From 66307654b726eebc51f77a3bd6dbb4b24d5a132c 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 12:03:23 +0100 Subject: [PATCH] Move padding and member function fixups before the fixup loop --- DwarfOne2C/Parsing/CompilationUnit.cs | 106 +++++++++++++------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/DwarfOne2C/Parsing/CompilationUnit.cs b/DwarfOne2C/Parsing/CompilationUnit.cs index 0c875b2..8cf3153 100644 --- a/DwarfOne2C/Parsing/CompilationUnit.cs +++ b/DwarfOne2C/Parsing/CompilationUnit.cs @@ -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(); @@ -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 sameNames = new();