Added enum sections to tree

This commit is contained in:
Sasha Koshka 2022-08-21 02:40:04 -04:00
parent ca80a5968d
commit 59126f60cc
2 changed files with 45 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}