Minor re-organization

This commit is contained in:
Katy Coe
2020-06-30 00:13:18 +02:00
parent 18b94e08f3
commit 23db04c369
33 changed files with 27 additions and 27 deletions

View File

@@ -5,15 +5,15 @@
All rights reserved.
*/
using Il2CppInspector.CppUtils.UnityHeaders;
using Il2CppInspector.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Il2CppInspector.Cpp.UnityHeaders;
using Il2CppInspector.Reflection;
namespace Il2CppInspector.CppUtils
namespace Il2CppInspector.Cpp
{
// Class for generating C header declarations from Reflection objects (TypeInfo, etc.)
public class CppDeclarationGenerator
@@ -149,7 +149,7 @@ namespace Il2CppInspector.CppUtils
}
// Generate structure fields for each field of a given type
private void GenerateFieldList(StringBuilder csrc, Namespace ns, TypeInfo ti) {
private void GenerateFieldList(StringBuilder csrc, CppNamespace ns, TypeInfo ti) {
var namer = ns.MakeNamer<FieldInfo>((field) => field.Name.ToCIdentifier());
foreach (var field in ti.DeclaredFields) {
if (field.IsLiteral || field.IsStatic)
@@ -222,7 +222,7 @@ namespace Il2CppInspector.CppUtils
* This causes all classes to be aligned to the alignment of their base class. */
TypeInfo firstNonEmpty = null;
foreach (var bti in baseClasses) {
if (bti.DeclaredFields.Where((field) => !field.IsStatic && !field.IsLiteral).Any()) {
if (bti.DeclaredFields.Any(field => !field.IsStatic && !field.IsLiteral)) {
firstNonEmpty = bti;
break;
}
@@ -577,8 +577,8 @@ namespace Il2CppInspector.CppUtils
}
// Reserve C/C++ keywords and built-in names
private static Namespace CreateNamespace() {
var ns = new Namespace();
private static CppNamespace CreateNamespace() {
var ns = new CppNamespace();
/* Reserve C/C++ keywords */
foreach (var keyword in new string[] { "_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary", "_Noreturn", "_Static_assert", "_Thread_local", "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char16_t", "char32_t", "char8_t", "class", "co_await", "co_return", "co_yield", "compl", "concept", "const", "const_cast", "consteval", "constexpr", "constinit", "continue", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public", "reflexpr", "register", "reinterpret_cast", "requires", "restrict", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq" }) {
ns.ReserveName(keyword);
@@ -593,16 +593,16 @@ namespace Il2CppInspector.CppUtils
/// <summary>
/// Namespace for all types and typedefs
/// </summary>
public Namespace TypeNamespace { get; private set; }
public CppNamespace TypeNamespace { get; private set; }
public Namespace.Namer<TypeInfo> TypeNamer { get; private set; }
public CppNamespace.Namer<TypeInfo> TypeNamer { get; private set; }
/// <summary>
/// Namespace for global variables, enum values and methods
/// </summary>
public Namespace GlobalsNamespace { get; private set; }
public Namespace.Namer<MethodBase> GlobalNamer { get; private set; }
public Namespace.Namer<FieldInfo> EnumNamer { get; private set; }
public CppNamespace GlobalsNamespace { get; private set; }
public CppNamespace.Namer<MethodBase> GlobalNamer { get; private set; }
public CppNamespace.Namer<FieldInfo> EnumNamer { get; private set; }
#endregion
}
}

View File

@@ -9,12 +9,12 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace Il2CppInspector.CppUtils
namespace Il2CppInspector.Cpp
{
/// <summary>
/// A utility class for managing names in a common namespace.
/// </summary>
public class Namespace
public class CppNamespace
{
// The central data structure that keeps track of which names have been generated
// The value for any given key K is the number of unique objects originally named K, minus 1.
@@ -43,7 +43,7 @@ namespace Il2CppInspector.CppUtils
public class Namer<T>
{
// Parent namespace
private Namespace ns;
private CppNamespace ns;
// Names given out by this Namer.
private readonly Dictionary<T, string> names = new Dictionary<T, string>();
@@ -53,7 +53,7 @@ namespace Il2CppInspector.CppUtils
public delegate string KeyFunc(T t);
private readonly KeyFunc keyFunc;
public Namer(Namespace ns, KeyFunc keyFunc) {
public Namer(CppNamespace ns, KeyFunc keyFunc) {
this.ns = ns;
this.keyFunc = keyFunc;
}

View File

@@ -10,7 +10,7 @@ using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace Il2CppInspector.CppUtils.UnityHeaders
namespace Il2CppInspector.Cpp.UnityHeaders
{
// Each instance of UnityHeader represents one header file which potentially covers multiple versions of Unity.
public class UnityHeader

View File

@@ -8,7 +8,7 @@
using System;
using System.Text.RegularExpressions;
namespace Il2CppInspector.CppUtils.UnityHeaders
namespace Il2CppInspector.Cpp.UnityHeaders
{
// Parsed representation of a Unity version number, such as 5.3.0f1 or 2019.3.7.
public class UnityVersion : IComparable<UnityVersion>, IEquatable<UnityVersion>

View File

@@ -10,11 +10,11 @@
</PropertyGroup>
<ItemGroup>
<None Remove="CppUtils\UnityHeaders\**" />
<None Remove="Cpp\UnityHeaders\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="CppUtils\UnityHeaders\**" />
<EmbeddedResource Include="Cpp\UnityHeaders\**" />
</ItemGroup>
<ItemGroup>

View File

@@ -9,8 +9,8 @@ using System.Linq;
using System.IO;
using System.Text;
using Il2CppInspector.Reflection;
using Il2CppInspector.CppUtils;
using Il2CppInspector.CppUtils.UnityHeaders;
using Il2CppInspector.Cpp;
using Il2CppInspector.Cpp.UnityHeaders;
namespace Il2CppInspector.Outputs
{
@@ -113,7 +113,7 @@ typedef __int64 int64_t;
declGenerator.IncludeMethod(method);
writeDecls(declGenerator.GenerateRemainingTypeDeclarations());
var address = method.VirtualAddress.Value.Start;
writeTypedName(address, declGenerator.GenerateMethodDeclaration(method), declGenerator.MethodNamer.GetName(method));
writeTypedName(address, declGenerator.GenerateMethodDeclaration(method), declGenerator.GlobalNamer.GetName(method));
writeComment(address, method);
}
}
@@ -171,7 +171,7 @@ typedef __int64 int64_t;
declGenerator.IncludeMethod(method);
writeDecls(declGenerator.GenerateRemainingTypeDeclarations());
name = declGenerator.MethodNamer.GetName(method);
name = declGenerator.GlobalNamer.GetName(method);
writeTypedName(address, "struct MethodInfo *", $"{name}__MethodInfo");
writeComment(address, method);
break;