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; }
|
||||
|
||||
// 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) {
|
||||
ReturnType = returnType;
|
||||
@@ -121,6 +121,7 @@ namespace Il2CppInspector.Cpp
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (text.StartsWith("typedef "))
|
||||
text = text.Substring(8);
|
||||
|
||||
@@ -182,7 +182,11 @@ namespace Il2CppInspector.Cpp
|
||||
if (line.Length == 0)
|
||||
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)
|
||||
var ifdef = rgxIsBitDirective.Match(line);
|
||||
if (ifdef.Success) {
|
||||
@@ -193,6 +197,19 @@ namespace Il2CppInspector.Cpp
|
||||
Debug.WriteLine($"[IF ] {line}");
|
||||
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") {
|
||||
falseIfBlock = !falseIfBlock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user