From 12755d3f856976961b4bd0aa171cae93d36be834 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 13 Oct 2022 18:48:38 -0400 Subject: [PATCH] Enum analysis works --- analyzer/analyzer.go | 4 ++++ analyzer/enum-section.go | 9 ++++++++- analyzer/type-section.go | 2 +- analyzer/type.go | 25 +++++++++++-------------- tests/analyzer/enumSection/main.arf | 11 ++++++++++- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index a2bb773..dbcb11a 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -264,6 +264,10 @@ func (analyzer *analysisOperation) inCurrentModule ( 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 // does not add a trailing newline. func doIndent (indent int, input ...any) (output string) { diff --git a/analyzer/enum-section.go b/analyzer/enum-section.go index 35d558d..3100f42 100644 --- a/analyzer/enum-section.go +++ b/analyzer/enum-section.go @@ -74,7 +74,7 @@ func (analyzer analysisOperation) analyzeEnumSection () ( if !inheritsFromTypeSection { err = inputSection.Type().NewError ( "enum sections can only inherit from other type " + - "sections.", + "sections", infoerr.ErrorKindError) return } @@ -97,8 +97,15 @@ func (analyzer analysisOperation) analyzeEnumSection () ( outputSection.what) 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 return } diff --git a/analyzer/type-section.go b/analyzer/type-section.go index c24b61f..c242909 100644 --- a/analyzer/type-section.go +++ b/analyzer/type-section.go @@ -130,7 +130,7 @@ func (analyzer analysisOperation) analyzeTypeSection () ( if !inheritsFromTypeSection { err = inputSection.Type().NewError ( "type sections can only inherit from other type " + - "sections.", + "sections", infoerr.ErrorKindError) return } diff --git a/analyzer/type.go b/analyzer/type.go index cd31ea8..4c53342 100644 --- a/analyzer/type.go +++ b/analyzer/type.go @@ -119,16 +119,15 @@ func (what Type) underlyingPrimitive () (underlying *TypeSection) { underlying = actual.(*TypeSection). what.underlyingPrimitive() - // TODO // case *FaceSection: // TODO: depending on if this is an object interface or // a function interface, return either Face or Func. // we can assume this because of inheritence rules. - // // case *EnumSection: - // underlying = - // actual.(*EnumSection). - // what.underlyingPrimitive() + case *EnumSection: + underlying = + actual.(*EnumSection). + what.underlyingPrimitive() default: panic ( @@ -164,13 +163,12 @@ func (what Type) isSingular () (singular bool) { switch actual.(type) { case *TypeSection: singular = actual.(*TypeSection).what.isSingular() - // TODO: uncomment this when these sections have been - // implemented + // TODO: uncomment this when this section has been implemented // case *FaceSection: // singular = true - // case *EnumSection: - // singular = actual.(*EnumSection).what.isSingular() + case *EnumSection: + singular = actual.(*EnumSection).what.isSingular() default: panic ( @@ -207,13 +205,12 @@ func (what Type) reduce () (reduced Type, reducible bool) { case *TypeSection: reduced, reducible = what.actual.(*TypeSection).what.reduce() - // TODO: uncomment this when these sections have been - // implemented + // TODO: uncomment this when his section has been implemented // case *FaceSection: // singular = true - // case *EnumSection: - // reduced, reducible = what.actual.(*EnumSection).what.reduce() + case *EnumSection: + reduced, reducible = what.actual.(*EnumSection).what.reduce() default: panic ( @@ -268,7 +265,7 @@ func (analyzer analysisOperation) analyzeType ( switch actual.(type) { // TODO: uncomment once these sections are implemented - case *TypeSection /* , *EnumSection, *FaceSection */: + case *TypeSection, *EnumSection /* , *FaceSection */: outputType.actual = actual default: err = inputType.NewError ( diff --git a/tests/analyzer/enumSection/main.arf b/tests/analyzer/enumSection/main.arf index 6c2a43a..b5bd3a5 100644 --- a/tests/analyzer/enumSection/main.arf +++ b/tests/analyzer/enumSection/main.arf @@ -1,7 +1,7 @@ :arf --- -enum ro Weekday:Int +enum ro aWeekday:Int - sunday - monday - tuesday @@ -9,3 +9,12 @@ enum ro Weekday:Int - thursday - friday - saturday + +type ro bColor:U32 + +enum ro cNamedColor:bColor + - red 0xFF0000 + - green 0x00FF00 + - blue 0x0000FF + +type ro X:cNamedColor