Skip to content

Commit

Permalink
Fix function signature generation
Browse files Browse the repository at this point in the history
Variable reuse gone wrong.
  • Loading branch information
RA-Kooi committed Dec 21, 2021
1 parent df6a27f commit a5b3f76
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions DwarfOne2C/CWriter/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ private static List<string> 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)
{
Expand All @@ -58,7 +64,7 @@ private static List<string> GenerateFunction(
if(hasParams)
line = line.Remove(line.Length - 2, 2);

line += ")" + part2;
line += ")" + pPart2;
code.Add(line);
code.Add(tabs + "{");
firstLocal = false;
Expand All @@ -67,9 +73,9 @@ private static List<string> GenerateFunction(
line = string.Format(
"{0}\t{1}{2}{3};",
tabs,
part1,
pPart1,
child.name,
part2);
pPart2);

code.Add(line);
}
Expand Down

0 comments on commit a5b3f76

Please sign in to comment.