Added analyzeTypeSection method
This commit is contained in:
parent
55a1490c18
commit
7cf797af26
@ -85,6 +85,11 @@ func (analyzer *AnalysisOperation) fetchSection (
|
|||||||
analyzer.currentPosition = where
|
analyzer.currentPosition = where
|
||||||
analyzer.currentSection = parsedSection
|
analyzer.currentSection = parsedSection
|
||||||
|
|
||||||
|
defer func () {
|
||||||
|
analyzer.currentPosition = previousPosition
|
||||||
|
analyzer.currentSection = previousSection
|
||||||
|
} ()
|
||||||
|
|
||||||
// TODO: analyze section. have analysis methods work on currentPosition
|
// TODO: analyze section. have analysis methods work on currentPosition
|
||||||
// and currentSection.
|
// and currentSection.
|
||||||
//
|
//
|
||||||
@ -94,15 +99,14 @@ func (analyzer *AnalysisOperation) fetchSection (
|
|||||||
// scenarios.
|
// scenarios.
|
||||||
switch parsedSection.Kind() {
|
switch parsedSection.Kind() {
|
||||||
case parser.SectionKindType:
|
case parser.SectionKindType:
|
||||||
case parser.SectionKindObjt:
|
section, err = analyzer.analyzeTypeSection()
|
||||||
|
if err != nil { return}
|
||||||
case parser.SectionKindEnum:
|
case parser.SectionKindEnum:
|
||||||
case parser.SectionKindFace:
|
case parser.SectionKindFace:
|
||||||
case parser.SectionKindData:
|
case parser.SectionKindData:
|
||||||
case parser.SectionKindFunc:
|
case parser.SectionKindFunc:
|
||||||
}
|
}
|
||||||
|
|
||||||
analyzer.currentPosition = previousPosition
|
|
||||||
analyzer.currentSection = previousSection
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ var PrimitiveObjt = createPrimitive("Objt", Type {})
|
|||||||
var PrimitiveFace = createPrimitive("Face", Type {})
|
var PrimitiveFace = createPrimitive("Face", Type {})
|
||||||
|
|
||||||
var BuiltInString = createPrimitive("String", Type {
|
var BuiltInString = createPrimitive("String", Type {
|
||||||
actual: PrimitiveU8,
|
actual: PrimitiveU32,
|
||||||
kind: TypeKindVariableArray,
|
kind: TypeKindVariableArray,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package analyzer
|
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.
|
// TypeSection represents a type definition section.
|
||||||
type TypeSection struct {
|
type TypeSection struct {
|
||||||
sectionBase
|
sectionBase
|
||||||
inherits Type
|
what Type
|
||||||
complete bool
|
complete bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,6 +20,27 @@ func (section TypeSection) Kind () (kind SectionKind) {
|
|||||||
// ToString returns all data stored within the type section, in string form.
|
// ToString returns all data stored within the type section, in string form.
|
||||||
func (section TypeSection) ToString (indent int) (output string) {
|
func (section TypeSection) ToString (indent int) (output string) {
|
||||||
output += doIndent(indent, "typeSection ", section.where.ToString(), "\n")
|
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
|
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