From bb4a5472e12917a32191ed37c9b03ca1391dc4ce Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 29 Sep 2022 18:09:52 -0400 Subject: [PATCH] Less gooooo! --- analyzer/analyzer.go | 14 ++++++++++++++ analyzer/table.go | 6 ++++++ analyzer/type-section.go | 8 +++++--- analyzer/type.go | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index 400c39a..6691a83 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -157,6 +157,20 @@ func (analyzer *AnalysisOperation) fetchSectionFromIdentifier ( return } +// addSection adds a section to the analyzer's section table. If a section with +// that name already exists, it panics because the parser should not have given +// that to us. +func (analyzer *AnalysisOperation) addSection (section Section) { + _, exists := analyzer.sectionTable[section.locator()] + if exists { + panic ( + "invalid state: duplicate section " + + section.locator().ToString()) + } + analyzer.sectionTable[section.locator()] = section + return +} + func doIndent (indent int, input ...any) (output string) { for index := 0; index < indent; index ++ { output += "\t" diff --git a/analyzer/table.go b/analyzer/table.go index 0341a80..9691de4 100644 --- a/analyzer/table.go +++ b/analyzer/table.go @@ -33,6 +33,7 @@ type Section interface { Complete () (complete bool) ModulePath () (path string) ModuleName () (path string) + locator () (where locator) // Must be implemented by each individual section ToString (indent int) (output string) @@ -67,3 +68,8 @@ func (section sectionBase) Complete () (complete bool) { complete = section.complete return } + +func (section sectionBase) locator () (where locator) { + where = section.where + return +} diff --git a/analyzer/type-section.go b/analyzer/type-section.go index f1568d1..9857577 100644 --- a/analyzer/type-section.go +++ b/analyzer/type-section.go @@ -50,6 +50,11 @@ func (analyzer AnalysisOperation) analyzeTypeSection () ( section Section, err error, ) { + outputSection := TypeSection { } + outputSection.where = analyzer.currentPosition + section = outputSection + analyzer.addSection(section) + inputSection := analyzer.currentSection.(parser.TypeSection) if inputSection.Permission() == types.PermissionReadWrite { err = inputSection.NewError ( @@ -58,9 +63,6 @@ func (analyzer AnalysisOperation) analyzeTypeSection () ( infoerr.ErrorKindError) } - outputSection := TypeSection { } - outputSection.where = analyzer.currentPosition - outputSection.what, err = analyzer.analyzeType(inputSection.Type()) if err != nil { return } diff --git a/analyzer/type.go b/analyzer/type.go index f5df3e1..92757af 100644 --- a/analyzer/type.go +++ b/analyzer/type.go @@ -76,7 +76,7 @@ func (analyzer AnalysisOperation) analyzeType ( err error, ) { outputType.mutable = inputType.Mutable() - if outputType.length < 1 { + if inputType.Length() < 1 { err = inputType.NewError ( "cannot specify a length of zero", infoerr.ErrorKindError)