C++: Handle comma-separated fields

This commit is contained in:
Katy Coe
2020-06-27 18:39:17 +02:00
parent b38a348709
commit 14b7d09e9d

View File

@@ -258,7 +258,7 @@ namespace Il2CppInspector.CppUtils
var rgxTypedefFnPtr = new Regex(@"typedef\s+(?:struct )?" + fnPtr + ";");
var rgxTypedef = new Regex(@"typedef (\S+?)\s*\**\s*(\S+);");
var rgxFieldFnPtr = new Regex(fnPtr + @";");
var rgxField = new Regex(@"^(?:struct |enum )?(\S+?)\s*\**\s*(\S+)(?:\s*:\s*([0-9]+))?;");
var rgxField = new Regex(@"^(?:struct |enum )?(\S+?)\s*\**\s*((?:\S|\s*,\s*)+)(?:\s*:\s*([0-9]+))?;");
var rgxStripKeywords = new Regex(@"\b(?:const|unsigned|volatile)\b");
var rgxCompressPtrs = new Regex(@"\*\s+\*");
@@ -271,7 +271,6 @@ namespace Il2CppInspector.CppUtils
bool inEnum = false;
string line;
// TODO: comma-separated fields
// TODO: #ifdef IS_32BIT
// TODO: function pointer signatures
@@ -471,9 +470,13 @@ namespace Il2CppInspector.CppUtils
var field = rgxField.Match(line);
if (field.Success) {
var name = field.Groups[2].Captures[0].ToString();
var names = field.Groups[2].Captures[0].ToString();
var typeName = field.Groups[1].Captures[0].ToString();
// Multiple fields can be separated by commas
foreach (var fieldName in names.Split(',')) {
string name = fieldName.Trim();
// Array
var array = rgxArrayField.Match(name);
int arraySize = 0;
@@ -501,9 +504,10 @@ namespace Il2CppInspector.CppUtils
ct.AddField(new CppField {Name = name, Type = type, BitfieldSize = bitfield}, alignment);
if (bitfield == 0)
Debug.WriteLine($"[FIELD {(pointers > 0? "PTR":"VAL")} ] {line} -- {name}");
Debug.WriteLine($"[FIELD {(pointers > 0 ? "PTR" : "VAL")} ] {line} -- {name}");
else
Debug.WriteLine($"[BITFIELD ] {line} -- {name} : {bitfield}");
}
continue;
}