From 59126f60cc52f0a9bdb5ff2a21d266974e6b6211 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 21 Aug 2022 02:40:04 -0400 Subject: [PATCH] Added enum sections to tree --- parser/tree-tostring.go | 34 ++++++++++++++++++++++++++++++++++ parser/tree.go | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index d469ed3..a26c6c9 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -56,6 +56,11 @@ func (tree *SyntaxTree) ToString (indent int) (output string) { output += tree.objtSections[name].ToString(indent) } + enumSectionKeys := sortMapKeysAlphabetically(tree.enumSections) + for _, name := range enumSectionKeys { + output += tree.enumSections[name].ToString(indent) + } + dataSectionKeys := sortMapKeysAlphabetically(tree.dataSections) for _, name := range dataSectionKeys { output += tree.dataSections[name].ToString(indent) @@ -319,3 +324,32 @@ func (section *ObjtSection) ToString (indent int) (output string) { return } +func (section *EnumSection) ToString (indent int) (output string) { + output += doIndent ( + indent, + "enum ", + section.permission.ToString(), " ", + section.name, ":", + section.what.ToString(), "\n") + + for _, name := range sortMapKeysAlphabetically(section.members) { + output += doIndent(indent, name, " ") + + member := section.members[name] + + isComplexInitialization := + member.kind == ArgumentKindObjectInitializationValues || + member.kind == ArgumentKindArrayInitializationValues + + if member.value == nil { + output += "\n" + } else if isComplexInitialization { + output += "\n" + output += member.ToString(indent + 1, true) + } else { + output += " " + member.ToString(0, false) + output += "\n" + } + } + return +} diff --git a/parser/tree.go b/parser/tree.go index c1b5e74..f5cf332 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -13,6 +13,7 @@ type SyntaxTree struct { requires []string typeSections map[string] *TypeSection objtSections map[string] *ObjtSection + enumSections map[string] *EnumSection dataSections map[string] *DataSection } @@ -191,3 +192,13 @@ type ObjtSection struct { permission types.Permission members map[string] ObjtMember } + +// EnumSection represents an enumerated type section. +type EnumSection struct { + location file.Location + name string + + what Type + permission types.Permission + members map[string] Argument +}