Store enum default value as argument, error on empty enum
This commit is contained in:
parent
500184c4ab
commit
e885af997d
|
@ -8,7 +8,8 @@ import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
type EnumSection struct {
|
type EnumSection struct {
|
||||||
sectionBase
|
sectionBase
|
||||||
what Type
|
what Type
|
||||||
members []EnumMember
|
members []EnumMember
|
||||||
|
argument Argument
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumMember is a member of an enumerated type.
|
// EnumMember is a member of an enumerated type.
|
||||||
|
@ -34,6 +35,7 @@ func (section EnumSection) ToString (indent int) (output string) {
|
||||||
output += section.permission.ToString() + " "
|
output += section.permission.ToString() + " "
|
||||||
output += section.where.ToString()
|
output += section.where.ToString()
|
||||||
output += "\n"
|
output += "\n"
|
||||||
|
output += section.argument.ToString(indent + 1)
|
||||||
output += section.what.ToString(indent + 1)
|
output += section.what.ToString(indent + 1)
|
||||||
for _, member := range section.members {
|
for _, member := range section.members {
|
||||||
output += member.ToString(indent + 1)
|
output += member.ToString(indent + 1)
|
||||||
|
@ -194,6 +196,15 @@ func (analyzer analysisOperation) analyzeEnumSection () (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(outputSection.members) < 1 {
|
||||||
|
err = outputSection.NewError (
|
||||||
|
"cannot create an enum with no members",
|
||||||
|
infoerr.ErrorKindError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
outputSection.argument = outputSection.members[0].argument
|
||||||
|
|
||||||
outputSection.complete = true
|
outputSection.complete = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,44 @@ import "testing"
|
||||||
|
|
||||||
func TestEnumSection (test *testing.T) {
|
func TestEnumSection (test *testing.T) {
|
||||||
checkTree ("../tests/analyzer/enumSection", false,
|
checkTree ("../tests/analyzer/enumSection", false,
|
||||||
`
|
`enumSection ro ../tests/analyzer/enumSection.aWeekday
|
||||||
|
arg uint 1
|
||||||
|
type 1 basic Int
|
||||||
|
member sunday
|
||||||
|
arg uint 1
|
||||||
|
member monday
|
||||||
|
arg uint 2
|
||||||
|
member tuesday
|
||||||
|
arg uint 3
|
||||||
|
member wednesday
|
||||||
|
arg uint 4
|
||||||
|
member thursday
|
||||||
|
arg uint 5
|
||||||
|
member friday
|
||||||
|
arg uint 6
|
||||||
|
member saturday
|
||||||
|
arg uint 7
|
||||||
|
typeSection ro ../tests/analyzer/enumSection.bColor
|
||||||
|
type 1 basic U32
|
||||||
|
enumSection ro ../tests/analyzer/enumSection.cNamedColor
|
||||||
|
arg uint 16711680
|
||||||
|
type 1 basic bColor
|
||||||
|
member red
|
||||||
|
arg uint 16711680
|
||||||
|
member green
|
||||||
|
arg uint 65280
|
||||||
|
member blue
|
||||||
|
arg uint 255
|
||||||
|
enumSection ro ../tests/analyzer/enumSection.dFromFarAway
|
||||||
|
arg uint 5
|
||||||
|
type 1 basic dInheritFromOther
|
||||||
|
member bird
|
||||||
|
arg uint 5
|
||||||
|
member bread
|
||||||
|
arg uint 4
|
||||||
|
typeSection ro ../tests/analyzer/typeSection/required.aBasic
|
||||||
|
type 1 basic Int
|
||||||
|
typeSection ro ../tests/analyzer/typeSection.dInheritFromOther
|
||||||
|
type 1 basic aBasic
|
||||||
`, test)
|
`, test)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ require '../typeSection'
|
||||||
enum ro aWeekday:Int
|
enum ro aWeekday:Int
|
||||||
- sunday
|
- sunday
|
||||||
- monday
|
- monday
|
||||||
- tuesday 3
|
- tuesday
|
||||||
- wednesday
|
- wednesday
|
||||||
- thursday
|
- thursday
|
||||||
- friday
|
- friday
|
||||||
|
@ -17,3 +17,7 @@ enum ro cNamedColor:bColor
|
||||||
- red 0xFF0000
|
- red 0xFF0000
|
||||||
- green 0x00FF00
|
- green 0x00FF00
|
||||||
- blue 0x0000FF
|
- blue 0x0000FF
|
||||||
|
|
||||||
|
enum ro dFromFarAway:typeSection.dInheritFromOther
|
||||||
|
- bird
|
||||||
|
- bread 4
|
||||||
|
|
Reference in New Issue