Renaming for clarity.
Renamed the class CppDeclarations => CppDeclarationGenerator to better reflect
its function and emphasize its statefulness.
Renamed Visit{Type,Method} => Include{Type,Method} to clarify that these methods
include the type or method into the generator state.
Renamed GenerateVisitedTypes => GenerateRemainingTypeDeclarations to clarify
that it outputs *remaining* declarations, i.e. declarations that haven't been
generated yet.
This commit is contained in:
40
Il2CppInspector.Common/CppUtils/CppDeclarations.cs → Il2CppInspector.Common/CppUtils/CppDeclarationGenerator.cs
Normal file → Executable file
40
Il2CppInspector.Common/CppUtils/CppDeclarations.cs → Il2CppInspector.Common/CppUtils/CppDeclarationGenerator.cs
Normal file → Executable file
@@ -16,7 +16,7 @@ using System.Text.RegularExpressions;
|
||||
namespace Il2CppInspector.CppUtils
|
||||
{
|
||||
// Class for generating C header declarations from Reflection objects (TypeInfo, etc.)
|
||||
public class CppDeclarations
|
||||
public class CppDeclarationGenerator
|
||||
{
|
||||
private readonly Il2CppModel model;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Il2CppInspector.CppUtils
|
||||
}
|
||||
public InheritanceStyleEnum InheritanceStyle;
|
||||
|
||||
public CppDeclarations(Il2CppModel model, UnityVersion version) {
|
||||
public CppDeclarationGenerator(Il2CppModel model, UnityVersion version) {
|
||||
this.model = model;
|
||||
if (version == null) {
|
||||
UnityHeader = UnityHeader.GuessHeadersForModel(model)[0];
|
||||
@@ -328,10 +328,11 @@ namespace Il2CppInspector.CppUtils
|
||||
private readonly List<TypeInfo> TodoTypeStructs = new List<TypeInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Visit a type and all types it depends on. Must call this before generating type structs.
|
||||
/// Include the given type into this generator. This will add the given type and all types it depends on.
|
||||
/// Call GenerateRemainingTypeDeclarations to produce the actual type declarations afterwards.
|
||||
/// </summary>
|
||||
/// <param name="ti"></param>
|
||||
public void VisitType(TypeInfo ti) {
|
||||
public void IncludeType(TypeInfo ti) {
|
||||
if (VisitedTypes.Contains(ti))
|
||||
return;
|
||||
if (ti.ContainsGenericParameters)
|
||||
@@ -340,15 +341,15 @@ namespace Il2CppInspector.CppUtils
|
||||
|
||||
if (ti.IsArray) {
|
||||
VisitFieldStructs(ti);
|
||||
VisitType(ti.ElementType);
|
||||
VisitType(ti.BaseType);
|
||||
IncludeType(ti.ElementType);
|
||||
IncludeType(ti.BaseType);
|
||||
return;
|
||||
} else if (ti.HasElementType) {
|
||||
VisitType(ti.ElementType);
|
||||
IncludeType(ti.ElementType);
|
||||
return;
|
||||
} else if (ti.IsEnum) {
|
||||
VisitFieldStructs(ti);
|
||||
VisitType(ti.GetEnumUnderlyingType());
|
||||
IncludeType(ti.GetEnumUnderlyingType());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -357,16 +358,16 @@ namespace Il2CppInspector.CppUtils
|
||||
VisitFieldStructs(ti);
|
||||
|
||||
if (ti.BaseType != null)
|
||||
VisitType(ti.BaseType);
|
||||
IncludeType(ti.BaseType);
|
||||
|
||||
TypeNamer.GetName(ti);
|
||||
|
||||
foreach (var fi in ti.DeclaredFields)
|
||||
VisitType(fi.FieldType);
|
||||
IncludeType(fi.FieldType);
|
||||
|
||||
foreach (var mi in GetFilledVTable(ti))
|
||||
if (mi != null && !mi.ContainsGenericParameters)
|
||||
VisitMethod(mi);
|
||||
IncludeMethod(mi);
|
||||
|
||||
TodoTypeStructs.Add(ti);
|
||||
}
|
||||
@@ -444,11 +445,11 @@ namespace Il2CppInspector.CppUtils
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate every type that has been visited so far. Types that have previously been generated
|
||||
/// by this instance will not be generated again.
|
||||
/// Output type declarations for every type that was included since the last call to GenerateRemainingTypeDeclarations
|
||||
/// Type declarations that have previously been generated by this instance of CppDeclarationGenerator will not be generated again.
|
||||
/// </summary>
|
||||
/// <returns>A string containing C type declarations</returns>
|
||||
public string GenerateVisitedTypes() {
|
||||
public string GenerateRemainingTypeDeclarations() {
|
||||
var csrc = new StringBuilder();
|
||||
GenerateVisitedFieldStructs(csrc);
|
||||
|
||||
@@ -463,18 +464,19 @@ namespace Il2CppInspector.CppUtils
|
||||
#region Method Generation
|
||||
|
||||
/// <summary>
|
||||
/// Visit a method and all types it takes/returns. Must call this before generating method declarations.
|
||||
/// Analyze a method and include all types that it takes and returns.
|
||||
/// Must call this before generating the method's declaration with GenerateMethodDeclaration or GenerateFunctionPointer.
|
||||
/// </summary>
|
||||
/// <param name="mi"></param>
|
||||
public void VisitMethod(MethodBase method, TypeInfo declaringType = null) {
|
||||
public void IncludeMethod(MethodBase method, TypeInfo declaringType = null) {
|
||||
if (!method.IsStatic)
|
||||
VisitType(declaringType ?? method.DeclaringType);
|
||||
IncludeType(declaringType ?? method.DeclaringType);
|
||||
|
||||
if (method is MethodInfo mi)
|
||||
VisitType(mi.ReturnType);
|
||||
IncludeType(mi.ReturnType);
|
||||
|
||||
foreach (var pi in method.DeclaredParameters) {
|
||||
VisitType(pi.ParameterType);
|
||||
IncludeType(pi.ParameterType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user