diff --git a/DwarfOne2C/CWriter/CWriter.cs b/DwarfOne2C/CWriter/CWriter.cs index 26594c5..5c46a09 100644 --- a/DwarfOne2C/CWriter/CWriter.cs +++ b/DwarfOne2C/CWriter/CWriter.cs @@ -19,7 +19,10 @@ public CWriter(string outputDirectory, string splitPath) code = new(); } - public void GenerateCode(CompilationUnit unit) + public void GenerateCode( + CompilationUnit unit, + List allTags, + Dictionary IDToIndex) { if(splitPath.EndsWith('\\') || splitPath.EndsWith('/')) @@ -32,23 +35,20 @@ public void GenerateCode(CompilationUnit unit) outputPath = Path.Join(outputDirectory, outputPath); - List allTags = unit.allTags; - Dictionary IDToIndex = unit.IDToIndex; - Tag current = allTags[IDToIndex[unit.firstChild]]; - List memberFuncs = allTags + List memberFuncs = unit.childTags .Where(i => i.tagType == TagType.GlobalFunc && i.memberOfID >= 0) .ToList(); Func predicate = i => { - return allTags.Where(j => j.tagType == TagType.TypeDef) + return unit.childTags.Where(j => j.tagType == TagType.TypeDef) .Any(j => j.name == i.name); }; // Filled by classes and structs - List staticMembers = allTags + List staticMembers = unit.childTags .Where(i => i.tagType == TagType.GlobalVar) .Where(predicate) .ToList(); diff --git a/DwarfOne2C/Parsing/CompilationUnit.cs b/DwarfOne2C/Parsing/CompilationUnit.cs index 0191dc3..bbb0772 100644 --- a/DwarfOne2C/Parsing/CompilationUnit.cs +++ b/DwarfOne2C/Parsing/CompilationUnit.cs @@ -13,8 +13,10 @@ public enum Language public Language language; - public List allTags; - public Dictionary IDToIndex; + public List childTags = new(); + + private List allTags; + private Dictionary IDToIndex; public CompilationUnit( List allTags, @@ -234,6 +236,7 @@ public void Parse(string[] lines, int current) } IDToIndex.Add(ID, allTags.Count - 1); + childTags.Add(allTags[allTags.Count - 1]); // If prev->sibling != ID int prevSibling = allTags[allTags.Count - 2].sibling; @@ -257,6 +260,7 @@ public void Parse(string[] lines, int current) allTags.Add(endTag); IDToIndex.Add(ID, allTags.Count - 1); + childTags.Add(allTags[allTags.Count - 1]); } } }