From b319c2c476ecca1efab8094d118413862605f9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Kooi?= <48814281+RA-Kooi@users.noreply.github.com> Date: Fri, 31 Dec 2021 11:59:33 +0100 Subject: [PATCH] Fix arrays generating with the wrong type/modifiers --- DwarfOne2C/CWriter/Types.cs | 3 +-- DwarfOne2C/Parsing/BlockParser.cs | 34 +++++++++++++++++++------------ DwarfOne2C/Parsing/Helpers.cs | 12 +++++++---- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/DwarfOne2C/CWriter/Types.cs b/DwarfOne2C/CWriter/Types.cs index 8b15db3..cc61889 100644 --- a/DwarfOne2C/CWriter/Types.cs +++ b/DwarfOne2C/CWriter/Types.cs @@ -80,7 +80,7 @@ private static (string part1, string part2) GetArray( if(current.typeID > 0) { Tag referenced = allTags[IDToIndex[current.typeID]]; - (type, part2) = GetType(allTags, IDToIndex, current); + (type, part2) = GetType(allTags, IDToIndex, referenced); type += GetModifiers(allTags, IDToIndex, current); } else @@ -108,7 +108,6 @@ private static (string part1, string part2) GetArray( ? "" : "" + (current.length + 1)); } - return (type, part2); } diff --git a/DwarfOne2C/Parsing/BlockParser.cs b/DwarfOne2C/Parsing/BlockParser.cs index 6535791..723f896 100644 --- a/DwarfOne2C/Parsing/BlockParser.cs +++ b/DwarfOne2C/Parsing/BlockParser.cs @@ -94,26 +94,28 @@ private Tag ParseArray( if(line.StartsWith("AT_subscr_data")) { Regex regex; - int count = 0; string searchFull = @"(?>AT_subscr_data\(<\d+>"; + + int dimensionCount = 0; + if(line.Contains("FT_long[")) { string searchStr = @"FT_long\[0:(\d+)\], "; - count = Regex.Matches(line, searchStr).Count; - for (int i = count; i > 0; --i) - { + dimensionCount = Regex.Matches(line, searchStr).Count; + + for (int i = dimensionCount; i > 0; --i) searchFull += searchStr; - } + regex = new(searchFull + @"FMT_ET: (.*)\))"); } else if(line.Contains("FT_integer[")) { string searchStr = @"FT_integer\[0:(\d+)\], "; - count = Regex.Matches(line, searchStr).Count; - for (int i = count; i > 0; --i) - { + dimensionCount = Regex.Matches(line, searchStr).Count; + + for (int i = dimensionCount; i > 0; --i) searchFull += searchStr; - } + regex = new(searchFull + @"FMT_ET: (.*)\))"); } else @@ -124,19 +126,24 @@ private Tag ParseArray( } Match match = regex.Match(line); + if (match.Success) { - GroupCollection groups = match.Groups; - tag.isMultidimArray = count > 1; string typeRef; + + GroupCollection groups = match.Groups; + + tag.isMultidimArray = dimensionCount > 1; + if (tag.isMultidimArray) { - for (int i = 0; i < count; ++i) + for (int i = 0; i < dimensionCount; ++i) { uint length = Convert.ToUInt32(groups[1 + i].Value); tag.arrayDimLengths.Add(unchecked((int)length)); } - typeRef = groups[1 + count].Value; + + typeRef = groups[1 + dimensionCount].Value; } else { @@ -144,6 +151,7 @@ private Tag ParseArray( tag.length = unchecked((int)length); typeRef = groups[2].Value; } + ParseTypes(typeRef, tag); } else diff --git a/DwarfOne2C/Parsing/Helpers.cs b/DwarfOne2C/Parsing/Helpers.cs index 16578cb..d8b5d53 100644 --- a/DwarfOne2C/Parsing/Helpers.cs +++ b/DwarfOne2C/Parsing/Helpers.cs @@ -73,22 +73,26 @@ private static void ParseModifiers(string line, int index, Tag tag) if(line[index] != 'M') break; - if(index + pointerLen <= line.Length && line.Substring(index, pointerLen) == "MOD_pointer_to") + if(index + pointerLen <= line.Length + && line.Substring(index, pointerLen) == "MOD_pointer_to") { tag.modifiers.Add(Type.Modifier.Pointer); index += pointerLen + 1; } - else if(index + refLen <= line.Length && line.Substring(index, refLen) == "MOD_reference_to") + else if(index + refLen <= line.Length + && line.Substring(index, refLen) == "MOD_reference_to") { tag.modifiers.Add(Type.Modifier.Reference); index += refLen + 1; } - else if(index + constLen <= line.Length && line.Substring(index, constLen) == "MOD_const") + else if(index + constLen <= line.Length + && line.Substring(index, constLen) == "MOD_const") { tag.modifiers.Add(Type.Modifier.Const); index += constLen + 1; } - else if(index + volatileLen <= line.Length && line.Substring(index, volatileLen) == "MOD_volatile") + else if(index + volatileLen <= line.Length + && line.Substring(index, volatileLen) == "MOD_volatile") { tag.modifiers.Add(Type.Modifier.Volatile); index += volatileLen + 1;