Skip to content

Commit

Permalink
Move padding and member function fixups before the fixup loop
Browse files Browse the repository at this point in the history
  • Loading branch information
RA-Kooi committed Dec 31, 2021
1 parent f1f16dc commit 6630765
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions DwarfOne2C/Parsing/CompilationUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,59 @@ void FixChain(Tag parent, ref int i, int depth)

FixChain(this, ref idx, 0);

void Recurse(Tag parent, int depth)
{
if(parent.firstChild == -1)
return;

for(Tag child = allTags[IDToIndex[parent.firstChild]];
child.sibling != Tag.NoSibling;
child = allTags[IDToIndex[child.sibling]])
{
// Fixup TAG_padding being member variables, global variables,
// and global functions at the same time...
if(child.tagType == TagType.Padding)
{
if(depth == 0)
child.tagType = child.isFunction
? TagType.GlobalFunc
: TagType.GlobalVar;
else
child.tagType = child.isFunction
? TagType.GlobalFunc
: TagType.Member;

if(child.sibling == parent.sibling)
{
child.sibling = Tag.NoSibling;
break;
}
}
else if(child.tagType == TagType.GlobalFunc)
{
if(depth > 0)
{
// Remove staticness from functions that are
// not top level
child.isStatic = false;

// It is also a class/struct member function
// in this case
child.tagType = TagType.MemberFunc;
}
}

if((child.tagType == TagType.Class
|| child.tagType == TagType.Struct)
&& child.firstChild != -1)
{
Recurse(child, 1);
}
}
}

Recurse(allTags[0], 0);

foreach(Tag tag in allTags)
{
tag.modifiers.Reverse();
Expand Down Expand Up @@ -313,59 +366,6 @@ void FixChain(Tag parent, ref int i, int depth)
}
}

void Recurse(Tag parent, int depth)
{
if(parent.firstChild == -1)
return;

for(Tag child = allTags[IDToIndex[parent.firstChild]];
child.sibling != Tag.NoSibling;
child = allTags[IDToIndex[child.sibling]])
{
// Fixup TAG_padding being member variables, global variables,
// and global functions at the same time...
if(child.tagType == TagType.Padding)
{
if(depth == 0)
child.tagType = child.isFunction
? TagType.GlobalFunc
: TagType.GlobalVar;
else
child.tagType = child.isFunction
? TagType.GlobalFunc
: TagType.Member;

if(child.sibling == parent.sibling)
{
child.sibling = Tag.NoSibling;
break;
}
}
else if(child.tagType == TagType.GlobalFunc)
{
if(depth > 0)
{
// Remove staticness from functions that are
// not top level
child.isStatic = false;

// It is also a class/struct member function
// in this case
child.tagType = TagType.MemberFunc;
}
}

if((child.tagType == TagType.Class
|| child.tagType == TagType.Struct)
&& child.firstChild != -1)
{
Recurse(child, 1);
}
}
}

Recurse(allTags[0], 0);

// Discriminate global symbols with the same name
List<string> sameNames = new();

Expand Down

0 comments on commit 6630765

Please sign in to comment.