From a58377ad15aab6cab8457f6a54e6a40b2adf2f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Kooi?= <48814281+RA-Kooi@users.noreply.github.com> Date: Tue, 13 Sep 2022 09:43:35 +0200 Subject: [PATCH] Only load the subtags of the file we're currently writing --- DwarfOne2C/CWriter/CWriter.cs | 14 +++++++------- DwarfOne2C/Parsing/CompilationUnit.cs | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) 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]); } } }