From 578e614344d99f990f2c00c4b734b746f16b6eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Kooi?= <48814281+RA-Kooi@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:20:14 +0200 Subject: [PATCH] Add function to find a Node by tag ID For CWriter, which needs it to find tag types and cross compilation unit references. --- DwarfOne2C/Parsing/CompilationUnit.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/DwarfOne2C/Parsing/CompilationUnit.cs b/DwarfOne2C/Parsing/CompilationUnit.cs index 63280dd..b0efc26 100644 --- a/DwarfOne2C/Parsing/CompilationUnit.cs +++ b/DwarfOne2C/Parsing/CompilationUnit.cs @@ -12,6 +12,24 @@ public Node(Tag tag) this.tag = tag; children = new(); } + + public Node Find(int tagID) + { + Node result = children.Find(n => n.tag.ID == tagID); + + if(result != null) + return result; + + foreach(Node child in children) + { + result = child.Find(tagID); + + if(result != null) + return result; + } + + return null; + } } public class CompilationUnit