From 308996f0590ba54ea441573f78443a2bddfdd6c4 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 18 Oct 2022 17:34:37 -0400 Subject: [PATCH] Pointers and dynamic arrays are accounted for --- analyzer/type-section.go | 10 ---------- analyzer/type-section_test.go | 8 ++++++-- analyzer/type.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/analyzer/type-section.go b/analyzer/type-section.go index 3c2e915..1722569 100644 --- a/analyzer/type-section.go +++ b/analyzer/type-section.go @@ -125,16 +125,6 @@ func (analyzer analysisOperation) analyzeTypeSection () ( outputSection.what, err = analyzer.analyzeType(inputSection.Type()) if err != nil { return } - // type sections are only allowed to inherit other type sections - _, inheritsFromTypeSection := outputSection.what.actual.(*TypeSection) - if !inheritsFromTypeSection { - err = inputSection.Type().NewError ( - "type sections can only inherit from other type " + - "sections", - infoerr.ErrorKindError) - return - } - if !inputSection.Argument().Nil() { outputSection.argument, err = analyzer.analyzeArgument(inputSection.Argument()) diff --git a/analyzer/type-section_test.go b/analyzer/type-section_test.go index eca78e8..c728b8a 100644 --- a/analyzer/type-section_test.go +++ b/analyzer/type-section_test.go @@ -38,8 +38,12 @@ typeSection ro ../tests/analyzer/typeSection.fInheritObjectFromOther type 1 basic Int arg uint 238 typeSection ro ../tests/analyzer/typeSection.gPointer - type 1 pointer {Int} + type 1 pointer { + type 1 basic Int + } typeSection ro ../tests/analyzer/typeSection.hDynamicArray - type 1 dynamicArray {Int} + type 1 dynamicArray { + type 1 basic Int + } `, test) } diff --git a/analyzer/type.go b/analyzer/type.go index e8846c7..4d7a3a1 100644 --- a/analyzer/type.go +++ b/analyzer/type.go @@ -284,11 +284,21 @@ func (analyzer analysisOperation) analyzeType ( return } + switch inputType.Kind() { + case parser.TypeKindBasic: + outputType.kind = TypeKindBasic + case parser.TypeKindPointer: + outputType.kind = TypeKindPointer + case parser.TypeKindVariableArray: + outputType.kind = TypeKindVariableArray + } + if inputType.Kind() != parser.TypeKindBasic { // analyze type this type points to, if it exists var points Type points, err = analyzer.analyzeType(inputType.Points()) outputType.points = &points + } else { // analyze the type section this type uses var node any