Enum analysis works
This commit is contained in:
parent
a1faf68cce
commit
12755d3f85
|
@ -264,6 +264,10 @@ func (analyzer *analysisOperation) inCurrentModule (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make a method of analyzer that, given a name, searches through all
|
||||||
|
// accessible scopes and returns the thing the name references. when analyzing
|
||||||
|
// a function, the analyzer should remember a trail of scopes.
|
||||||
|
|
||||||
// doIndent perfroms a fmt.Sprint operation on input, indenting the string. This
|
// doIndent perfroms a fmt.Sprint operation on input, indenting the string. This
|
||||||
// does not add a trailing newline.
|
// does not add a trailing newline.
|
||||||
func doIndent (indent int, input ...any) (output string) {
|
func doIndent (indent int, input ...any) (output string) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (analyzer analysisOperation) analyzeEnumSection () (
|
||||||
if !inheritsFromTypeSection {
|
if !inheritsFromTypeSection {
|
||||||
err = inputSection.Type().NewError (
|
err = inputSection.Type().NewError (
|
||||||
"enum sections can only inherit from other type " +
|
"enum sections can only inherit from other type " +
|
||||||
"sections.",
|
"sections",
|
||||||
infoerr.ErrorKindError)
|
infoerr.ErrorKindError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,15 @@ func (analyzer analysisOperation) analyzeEnumSection () (
|
||||||
outputSection.what)
|
outputSection.what)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputSection.members = append (
|
||||||
|
outputSection.members,
|
||||||
|
outputMember)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fill in members that do not have values with incrementing
|
||||||
|
// values. take care to not duplicate them.
|
||||||
|
|
||||||
outputSection.complete = true
|
outputSection.complete = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ func (analyzer analysisOperation) analyzeTypeSection () (
|
||||||
if !inheritsFromTypeSection {
|
if !inheritsFromTypeSection {
|
||||||
err = inputSection.Type().NewError (
|
err = inputSection.Type().NewError (
|
||||||
"type sections can only inherit from other type " +
|
"type sections can only inherit from other type " +
|
||||||
"sections.",
|
"sections",
|
||||||
infoerr.ErrorKindError)
|
infoerr.ErrorKindError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,16 +119,15 @@ func (what Type) underlyingPrimitive () (underlying *TypeSection) {
|
||||||
underlying =
|
underlying =
|
||||||
actual.(*TypeSection).
|
actual.(*TypeSection).
|
||||||
what.underlyingPrimitive()
|
what.underlyingPrimitive()
|
||||||
// TODO
|
|
||||||
// case *FaceSection:
|
// case *FaceSection:
|
||||||
// TODO: depending on if this is an object interface or
|
// TODO: depending on if this is an object interface or
|
||||||
// a function interface, return either Face or Func.
|
// a function interface, return either Face or Func.
|
||||||
// we can assume this because of inheritence rules.
|
// we can assume this because of inheritence rules.
|
||||||
|
|
||||||
// // case *EnumSection:
|
case *EnumSection:
|
||||||
// underlying =
|
underlying =
|
||||||
// actual.(*EnumSection).
|
actual.(*EnumSection).
|
||||||
// what.underlyingPrimitive()
|
what.underlyingPrimitive()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic (
|
panic (
|
||||||
|
@ -164,13 +163,12 @@ func (what Type) isSingular () (singular bool) {
|
||||||
switch actual.(type) {
|
switch actual.(type) {
|
||||||
case *TypeSection:
|
case *TypeSection:
|
||||||
singular = actual.(*TypeSection).what.isSingular()
|
singular = actual.(*TypeSection).what.isSingular()
|
||||||
// TODO: uncomment this when these sections have been
|
// TODO: uncomment this when this section has been implemented
|
||||||
// implemented
|
|
||||||
// case *FaceSection:
|
// case *FaceSection:
|
||||||
// singular = true
|
// singular = true
|
||||||
|
|
||||||
// case *EnumSection:
|
case *EnumSection:
|
||||||
// singular = actual.(*EnumSection).what.isSingular()
|
singular = actual.(*EnumSection).what.isSingular()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic (
|
panic (
|
||||||
|
@ -207,13 +205,12 @@ func (what Type) reduce () (reduced Type, reducible bool) {
|
||||||
case *TypeSection:
|
case *TypeSection:
|
||||||
reduced, reducible = what.actual.(*TypeSection).what.reduce()
|
reduced, reducible = what.actual.(*TypeSection).what.reduce()
|
||||||
|
|
||||||
// TODO: uncomment this when these sections have been
|
// TODO: uncomment this when his section has been implemented
|
||||||
// implemented
|
|
||||||
// case *FaceSection:
|
// case *FaceSection:
|
||||||
// singular = true
|
// singular = true
|
||||||
|
|
||||||
// case *EnumSection:
|
case *EnumSection:
|
||||||
// reduced, reducible = what.actual.(*EnumSection).what.reduce()
|
reduced, reducible = what.actual.(*EnumSection).what.reduce()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic (
|
panic (
|
||||||
|
@ -268,7 +265,7 @@ func (analyzer analysisOperation) analyzeType (
|
||||||
|
|
||||||
switch actual.(type) {
|
switch actual.(type) {
|
||||||
// TODO: uncomment once these sections are implemented
|
// TODO: uncomment once these sections are implemented
|
||||||
case *TypeSection /* , *EnumSection, *FaceSection */:
|
case *TypeSection, *EnumSection /* , *FaceSection */:
|
||||||
outputType.actual = actual
|
outputType.actual = actual
|
||||||
default:
|
default:
|
||||||
err = inputType.NewError (
|
err = inputType.NewError (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
:arf
|
:arf
|
||||||
---
|
---
|
||||||
|
|
||||||
enum ro Weekday:Int
|
enum ro aWeekday:Int
|
||||||
- sunday
|
- sunday
|
||||||
- monday
|
- monday
|
||||||
- tuesday
|
- tuesday
|
||||||
|
@ -9,3 +9,12 @@ enum ro Weekday:Int
|
||||||
- thursday
|
- thursday
|
||||||
- friday
|
- friday
|
||||||
- saturday
|
- saturday
|
||||||
|
|
||||||
|
type ro bColor:U32
|
||||||
|
|
||||||
|
enum ro cNamedColor:bColor
|
||||||
|
- red 0xFF0000
|
||||||
|
- green 0x00FF00
|
||||||
|
- blue 0x0000FF
|
||||||
|
|
||||||
|
type ro X:cNamedColor
|
||||||
|
|
Reference in New Issue