From a5b3f76931d2c015e6575af77380bd0233aa8954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Kooi?= <48814281+RA-Kooi@users.noreply.github.com> Date: Tue, 21 Dec 2021 07:17:13 +0100 Subject: [PATCH] Fix function signature generation Variable reuse gone wrong. --- DwarfOne2C/CWriter/Function.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/DwarfOne2C/CWriter/Function.cs b/DwarfOne2C/CWriter/Function.cs index 360deb9..df8e45f 100644 --- a/DwarfOne2C/CWriter/Function.cs +++ b/DwarfOne2C/CWriter/Function.cs @@ -37,19 +37,25 @@ private static List GenerateFunction( bool firstLocal = true; bool hasParams = false; + int i = 0; + for(Tag child = allTags[IDToIndex[current.firstChild]]; child.sibling != Tag.NoSibling; - child = allTags[IDToIndex[child.sibling]]) + child = allTags[IDToIndex[child.sibling]], ++i) { if(child.name == "this") continue; - (part1, part2) = GetType(allTags, IDToIndex, child); + string name = child.name != null + ? child.name + : $"unknown{i}"; + + (string pPart1, string pPart2) = GetType(allTags, IDToIndex, child); if(child.tagType == TagType.Param) { hasParams = true; - line += part1 + child.name + part2 + ", "; + line += pPart1 + name + pPart2 + ", "; } else if(child.tagType == TagType.LocalVar) { @@ -58,7 +64,7 @@ private static List GenerateFunction( if(hasParams) line = line.Remove(line.Length - 2, 2); - line += ")" + part2; + line += ")" + pPart2; code.Add(line); code.Add(tabs + "{"); firstLocal = false; @@ -67,9 +73,9 @@ private static List GenerateFunction( line = string.Format( "{0}\t{1}{2}{3};", tabs, - part1, + pPart1, child.name, - part2); + pPart2); code.Add(line); }