Properly analyze member types

This commit is contained in:
Sasha Koshka 2022-10-13 00:01:49 -04:00
parent f817894b49
commit c290b3a3d7

View File

@ -1,5 +1,6 @@
package analyzer package analyzer
import "fmt"
import "git.tebibyte.media/arf/arf/types" import "git.tebibyte.media/arf/arf/types"
import "git.tebibyte.media/arf/arf/parser" import "git.tebibyte.media/arf/arf/parser"
import "git.tebibyte.media/arf/arf/infoerr" import "git.tebibyte.media/arf/arf/infoerr"
@ -21,6 +22,7 @@ type TypeSection struct {
type ObjectMember struct { type ObjectMember struct {
locatable locatable
name string name string
bitWidth uint64
// even if there is a private permission in another module, we still // even if there is a private permission in another module, we still
// need to include it in the semantic analysis because we need to know // need to include it in the semantic analysis because we need to know
@ -31,12 +33,18 @@ type ObjectMember struct {
argument Argument argument Argument
} }
// ToString returns all data stored within the member, in string form.
func (member ObjectMember) ToString (indent int) (output string) { func (member ObjectMember) ToString (indent int) (output string) {
output += doIndent ( output += doIndent (
indent, indent, "member ",
member.name, " ", member.permission.ToString(), " ",
member.permission.ToString(), member.name)
"\n")
if member.bitWidth > 0 {
output += fmt.Sprint(" width ", member.bitWidth)
}
output += "\n"
output += member.what.ToString(indent + 1) output += member.what.ToString(indent + 1)
return return
} }
@ -51,6 +59,9 @@ func (section TypeSection) ToString (indent int) (output string) {
if section.argument != nil { if section.argument != nil {
output += section.argument.ToString(indent + 1) output += section.argument.ToString(indent + 1)
} }
for _, member := range section.members {
output += member.ToString(indent + 1)
}
return return
} }
@ -162,6 +173,7 @@ func (analyzer *analysisOperation) analyzeObjectMembers (
outputMember.location = inputMember.Location() outputMember.location = inputMember.Location()
outputMember.name = inputMember.Name() outputMember.name = inputMember.Name()
outputMember.permission = inputMember.Permission() outputMember.permission = inputMember.Permission()
outputMember.bitWidth = inputMember.BitWidth()
inheritedMember, exists := inheritedMember, exists :=
inheritedSection.Member(inputMember.Name()) inheritedSection.Member(inputMember.Name())
@ -213,6 +225,10 @@ func (analyzer *analysisOperation) analyzeObjectMembers (
return return
} }
outputMember.what, err = analyzer.analyzeType (
inputMember.Type())
if err != nil { return }
// apply default value // apply default value
if !inputMember.Argument().Nil() { if !inputMember.Argument().Nil() {
outputMember.argument, outputMember.argument,