C++: Improve parsing of #defines, #ifdefs, #ifs, function pointers
This commit is contained in:
@@ -113,7 +113,7 @@ namespace Il2CppInspector.Cpp
|
|||||||
public List<(string Name, CppType Type)> Arguments { get; }
|
public List<(string Name, CppType Type)> Arguments { get; }
|
||||||
|
|
||||||
// Regex which matches a function pointer
|
// Regex which matches a function pointer
|
||||||
public const string Regex = @"(\S+)\s*\(\s*\*(\S+)\s*\)\s*\(\s*(.*?)\s*\)";
|
public const string Regex = @"(\S+)\s*\(\s*\*\s*(\S+?)\s*?\)\s*\(\s*(.*?)\s*\)";
|
||||||
|
|
||||||
public CppFnPtrType(int WordSize, CppType returnType, List<(string Name, CppType Type)> arguments) : base(null, WordSize) {
|
public CppFnPtrType(int WordSize, CppType returnType, List<(string Name, CppType Type)> arguments) : base(null, WordSize) {
|
||||||
ReturnType = returnType;
|
ReturnType = returnType;
|
||||||
@@ -121,6 +121,7 @@ namespace Il2CppInspector.Cpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a CppFnPtrType from a text signature (typedef or field)
|
// Generate a CppFnPtrType from a text signature (typedef or field)
|
||||||
|
// TODO: Fails to select correct arguments if one or more arguments are a function pointer; needs recursive parsing
|
||||||
public static CppFnPtrType FromSignature(CppTypeCollection types, string text) {
|
public static CppFnPtrType FromSignature(CppTypeCollection types, string text) {
|
||||||
if (text.StartsWith("typedef "))
|
if (text.StartsWith("typedef "))
|
||||||
text = text.Substring(8);
|
text = text.Substring(8);
|
||||||
|
|||||||
@@ -182,7 +182,11 @@ namespace Il2CppInspector.Cpp
|
|||||||
if (line.Length == 0)
|
if (line.Length == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Process #ifs before anything else
|
// Ignore defines
|
||||||
|
if (line.StartsWith("#define"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Process #ifdefs before anything else
|
||||||
// Doesn't handle nesting but we probably don't need to (use a Stack if we do)
|
// Doesn't handle nesting but we probably don't need to (use a Stack if we do)
|
||||||
var ifdef = rgxIsBitDirective.Match(line);
|
var ifdef = rgxIsBitDirective.Match(line);
|
||||||
if (ifdef.Success) {
|
if (ifdef.Success) {
|
||||||
@@ -193,6 +197,19 @@ namespace Il2CppInspector.Cpp
|
|||||||
Debug.WriteLine($"[IF ] {line}");
|
Debug.WriteLine($"[IF ] {line}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Other #ifdef
|
||||||
|
if (line.StartsWith("#ifdef") || line.StartsWith("#if ")) {
|
||||||
|
falseIfBlock = true;
|
||||||
|
|
||||||
|
Debug.WriteLine($"[IF ] {line}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.StartsWith("#ifndef")) {
|
||||||
|
falseIfBlock = false;
|
||||||
|
|
||||||
|
Debug.WriteLine($"[IF ] {line}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (line == "#else") {
|
if (line == "#else") {
|
||||||
falseIfBlock = !falseIfBlock;
|
falseIfBlock = !falseIfBlock;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user