Added analyzeTypeSection method
This commit is contained in:
parent
55a1490c18
commit
7cf797af26
@ -85,6 +85,11 @@ func (analyzer *AnalysisOperation) fetchSection (
|
||||
analyzer.currentPosition = where
|
||||
analyzer.currentSection = parsedSection
|
||||
|
||||
defer func () {
|
||||
analyzer.currentPosition = previousPosition
|
||||
analyzer.currentSection = previousSection
|
||||
} ()
|
||||
|
||||
// TODO: analyze section. have analysis methods work on currentPosition
|
||||
// and currentSection.
|
||||
//
|
||||
@ -94,15 +99,14 @@ func (analyzer *AnalysisOperation) fetchSection (
|
||||
// scenarios.
|
||||
switch parsedSection.Kind() {
|
||||
case parser.SectionKindType:
|
||||
case parser.SectionKindObjt:
|
||||
section, err = analyzer.analyzeTypeSection()
|
||||
if err != nil { return}
|
||||
case parser.SectionKindEnum:
|
||||
case parser.SectionKindFace:
|
||||
case parser.SectionKindData:
|
||||
case parser.SectionKindFunc:
|
||||
}
|
||||
|
||||
analyzer.currentPosition = previousPosition
|
||||
analyzer.currentSection = previousSection
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ var PrimitiveObjt = createPrimitive("Objt", Type {})
|
||||
var PrimitiveFace = createPrimitive("Face", Type {})
|
||||
|
||||
var BuiltInString = createPrimitive("String", Type {
|
||||
actual: PrimitiveU8,
|
||||
actual: PrimitiveU32,
|
||||
kind: TypeKindVariableArray,
|
||||
})
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
package analyzer
|
||||
|
||||
import "git.tebibyte.media/arf/arf/types"
|
||||
import "git.tebibyte.media/arf/arf/parser"
|
||||
import "git.tebibyte.media/arf/arf/infoerr"
|
||||
|
||||
// TypeSection represents a type definition section.
|
||||
type TypeSection struct {
|
||||
sectionBase
|
||||
inherits Type
|
||||
what Type
|
||||
complete bool
|
||||
}
|
||||
|
||||
@ -16,6 +20,27 @@ func (section TypeSection) Kind () (kind SectionKind) {
|
||||
// ToString returns all data stored within the type section, in string form.
|
||||
func (section TypeSection) ToString (indent int) (output string) {
|
||||
output += doIndent(indent, "typeSection ", section.where.ToString(), "\n")
|
||||
output += section.inherits.ToString(indent + 1)
|
||||
output += section.what.ToString(indent + 1)
|
||||
return
|
||||
}
|
||||
|
||||
// analyzeTypeSection analyzes a type section.
|
||||
func (analyzer AnalysisOperation) analyzeTypeSection () (
|
||||
section Section,
|
||||
err error,
|
||||
) {
|
||||
inputSection := analyzer.currentSection.(parser.TypeSection)
|
||||
if inputSection.Permission() == types.PermissionReadWrite {
|
||||
err = inputSection.NewError (
|
||||
"rw permission not understood in this context, try ro",
|
||||
infoerr.ErrorKindError)
|
||||
}
|
||||
|
||||
outputSection := TypeSection { }
|
||||
outputSection.where = analyzer.currentPosition
|
||||
|
||||
outputSection.what, err = analyzer.analyzeType(inputSection.Type())
|
||||
|
||||
outputSection.complete = true
|
||||
return
|
||||
}
|
||||
|
11
analyzer/type-section_test.go
Normal file
11
analyzer/type-section_test.go
Normal file
@ -0,0 +1,11 @@
|
||||
package analyzer
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTypeSection (test *testing.T) {
|
||||
checkTree ("../tests/analyzer/typeSection", false,
|
||||
`
|
||||
typeSection ../tests/analyzer/typeSection.basicInt
|
||||
type basic Int
|
||||
`, test)
|
||||
}
|
Reference in New Issue
Block a user