Skip to content

Commit

Permalink
Only load the subtags of the file we're currently writing
Browse files Browse the repository at this point in the history
  • Loading branch information
RA-Kooi committed Sep 13, 2022
1 parent 52862a2 commit a58377a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 7 additions & 7 deletions DwarfOne2C/CWriter/CWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public CWriter(string outputDirectory, string splitPath)
code = new();
}

public void GenerateCode(CompilationUnit unit)
public void GenerateCode(
CompilationUnit unit,
List<Tag> allTags,
Dictionary<int, int> IDToIndex)
{
if(splitPath.EndsWith('\\')
|| splitPath.EndsWith('/'))
Expand All @@ -32,23 +35,20 @@ public void GenerateCode(CompilationUnit unit)

outputPath = Path.Join(outputDirectory, outputPath);

List<Tag> allTags = unit.allTags;
Dictionary<int, int> IDToIndex = unit.IDToIndex;

Tag current = allTags[IDToIndex[unit.firstChild]];

List<Tag> memberFuncs = allTags
List<Tag> memberFuncs = unit.childTags
.Where(i => i.tagType == TagType.GlobalFunc && i.memberOfID >= 0)
.ToList();

Func<Tag, bool> 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<Tag> staticMembers = allTags
List<Tag> staticMembers = unit.childTags
.Where(i => i.tagType == TagType.GlobalVar)
.Where(predicate)
.ToList();
Expand Down
8 changes: 6 additions & 2 deletions DwarfOne2C/Parsing/CompilationUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public enum Language

public Language language;

public List<Tag> allTags;
public Dictionary<int /* ID */, int /* tagIndex */> IDToIndex;
public List<Tag> childTags = new();

private List<Tag> allTags;
private Dictionary<int /* ID */, int /* tagIndex */> IDToIndex;

public CompilationUnit(
List<Tag> allTags,
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
}
}
}
Expand Down

0 comments on commit a58377a

Please sign in to comment.