Various ToString fixes

This commit is contained in:
Sasha Koshka 2022-09-16 22:35:55 -04:00
parent e123e97357
commit aff5b1749c
2 changed files with 75 additions and 63 deletions

View File

@ -28,23 +28,24 @@ data ro gIntegerArrayInitialized:Int:16:
> >
data ro jObject:Obj: data ro jObject:Obj:
( (
.this:<324>
.that:<324> .that:<324>
.this:<324>
) )
data ro kNestedObject:Obj: data ro kNestedObject:Obj:
( (
.ro newMember:Int:<9023> .ro newMember:Int:<9023>
) ):
.this: (
(
.bird0:<324>
.bird1:<"hello world">
)
.that: .that:
( (
.bird2:<123.8439> .bird2:<123.8439>
.bird3:<9328.21348239> .bird3:<9328.21348239>
) )
.this:
(
.bird0:<324>
.bird1:<"hello world">
)
) )
data ro lMutIntegerArray16:Int:16:mut data ro lMutIntegerArray16:Int:16:mut
data ro mExternalData:Int:8 data ro mExternalData:Int:8

View File

@ -72,12 +72,28 @@ func (values ObjectDefaultValues) ToString (
) ( ) (
output string, output string,
) { ) {
output += doIndent(indent, "(\n") if !breakLine { indent = 0 }
for name, value := range values { output += doIndent(indent, "(")
output += doIndent ( if breakLine { output += "\n" }
indent,
name + ":" + value.ToString(indent, false)) for _, name := range sortMapKeysAlphabetically(values) {
output += "\n" value := values[name]
output += doIndent(indent, "." + name + ":")
isComplexDefaultValue :=
value.kind == ArgumentKindObjectDefaultValues ||
value.kind == ArgumentKindArrayDefaultValues
if isComplexDefaultValue {
if breakLine { output += "\n" }
output += value.ToString(indent + 1, breakLine)
} else {
output += "<"
output += value.ToString(indent + 1, false)
output += ">"
}
if breakLine { output += "\n" }
} }
output += doIndent(indent, ")") output += doIndent(indent, ")")
return return
@ -89,14 +105,36 @@ func (values ArrayDefaultValues) ToString (
) ( ) (
output string, output string,
) { ) {
output += doIndent(indent, "<\n") if !breakLine { indent = 0 }
output += doIndent(indent, "<")
if breakLine { output += "\n" }
for _, value := range values { for _, value := range values {
output += value.ToString(indent, breakLine) output += value.ToString(indent, breakLine)
} }
output += doIndent(indent, ">") output += doIndent(indent, ">")
return return
} }
func (member TypeMember) ToString (indent int, breakLine bool) (output string) {
output += doIndent(indent, ".")
output += member.permission.ToString() + " "
output += member.name + ":"
output += member.what.ToString(indent, breakLine)
if member.bitWidth > 0 {
output += fmt.Sprint(" & ", member.bitWidth)
}
if breakLine {
output += "\n"
}
return
}
func (what Type) ToString (indent int, breakLine bool) (output string) { func (what Type) ToString (indent int, breakLine bool) (output string) {
if what.kind == TypeKindBasic { if what.kind == TypeKindBasic {
output += what.name.ToString() output += what.name.ToString()
@ -120,12 +158,20 @@ func (what Type) ToString (indent int, breakLine bool) (output string) {
} }
if what.members != nil { if what.members != nil {
output += ":\n" + doIndent(indent, "(\n") if breakLine {
for _, member := range what.members { output += ":\n" + doIndent(indent, "(\n")
output += doIndent ( for _, member := range what.members {
indent, member.ToString(indent + 1), "\n") output += member.ToString(indent, breakLine)
}
output += doIndent(indent, ")")
} else {
output += ":("
for index, member := range what.members {
if index > 0 { output += " " }
output += member.ToString(indent, breakLine)
}
output += ")"
} }
output += doIndent(indent, ")")
} }
defaultValueKind := what.defaultValue.kind defaultValueKind := what.defaultValue.kind
@ -134,9 +180,10 @@ func (what Type) ToString (indent int, breakLine bool) (output string) {
defaultValueKind == ArgumentKindObjectDefaultValues || defaultValueKind == ArgumentKindObjectDefaultValues ||
defaultValueKind == ArgumentKindArrayDefaultValues defaultValueKind == ArgumentKindArrayDefaultValues
if isComplexDefaultValue && breakLine{ if isComplexDefaultValue {
output += ":\n" output += ":"
output += what.defaultValue.ToString(indent + 1, breakLine) if breakLine { output += "\n" }
output += what.defaultValue.ToString(indent, breakLine)
} else { } else {
output += ":<" output += ":<"
output += what.defaultValue.ToString(indent, false) output += what.defaultValue.ToString(indent, false)
@ -281,23 +328,7 @@ func (section DataSection) ToString (indent int) (output string) {
"data ", "data ",
section.permission.ToString(), " ", section.permission.ToString(), " ",
section.name, ":", section.name, ":",
section.what.ToString(indent, true), "\n") section.what.ToString(indent + 1, true), "\n")
return
}
func (member TypeMember) ToString (indent int) (output string) {
output += doIndent(indent)
output += member.permission.ToString() + " "
output += member.name + ":"
output += member.what.ToString(indent, true)
if member.bitWidth > 0 {
output += fmt.Sprint(" & ", member.bitWidth)
}
output += "\n"
return return
} }
@ -307,7 +338,7 @@ func (section TypeSection) ToString (indent int) (output string) {
"type ", "type ",
section.permission.ToString(), " ", section.permission.ToString(), " ",
section.name, ":", section.name, ":",
section.what.ToString(indent, true), "\n") section.what.ToString(indent + 1, true), "\n")
return return
} }
@ -374,21 +405,9 @@ func (phrase Phrase) ToString (indent int, ownLine bool) (output string) {
output += doIndent(indent) output += doIndent(indent)
} }
var initializationValues Argument
var declaration Argument
output += "[" + phrase.command.ToString(0, false) output += "[" + phrase.command.ToString(0, false)
for _, argument := range phrase.arguments { for _, argument := range phrase.arguments {
isInitializationValue := output += " " + argument.ToString(0, false)
argument.kind == ArgumentKindObjectDefaultValues ||
argument.kind == ArgumentKindArrayDefaultValues
if isInitializationValue {
initializationValues = argument
} else if argument.kind == ArgumentKindDeclaration {
declaration = argument
} else {
output += " " + argument.ToString(0, false)
}
} }
output += "]" output += "]"
@ -401,17 +420,9 @@ func (phrase Phrase) ToString (indent int, ownLine bool) (output string) {
if ownLine { if ownLine {
output += "\n" output += "\n"
// TODO: make = phrases special, have them carry a declaration
// and argument and nothing else. somehow.
for _, member := range declaration.value.(Declaration).what.members {
output += member.ToString(indent + 1)
}
if initializationValues.kind != ArgumentKindNil {
output += initializationValues.ToString(indent + 1, true)
}
output += phrase.block.ToString(indent + 1) output += phrase.block.ToString(indent + 1)
} else if len(phrase.block) > 0 {
output += "NON BLOCKLEVEL PHRASE HAS BLOCK"
} }
return return
} }