2022-09-17 21:36:59 -06:00
|
|
|
package analyzer
|
|
|
|
|
2022-09-18 00:41:06 -06:00
|
|
|
import "git.tebibyte.media/arf/arf/types"
|
|
|
|
import "git.tebibyte.media/arf/arf/parser"
|
|
|
|
import "git.tebibyte.media/arf/arf/infoerr"
|
|
|
|
|
2022-09-17 21:36:59 -06:00
|
|
|
// TypeSection represents a type definition section.
|
|
|
|
type TypeSection struct {
|
|
|
|
sectionBase
|
2022-09-18 00:41:06 -06:00
|
|
|
what Type
|
2022-09-17 21:36:59 -06:00
|
|
|
complete bool
|
2022-09-29 22:04:28 -06:00
|
|
|
argument Argument
|
2022-09-29 15:34:51 -06:00
|
|
|
// TODO: do not add members from parent type. instead have a member
|
|
|
|
// function to discern whether this type contains a particular member,
|
|
|
|
// and have it recurse all the way up the family tree. it will be the
|
|
|
|
// translator's job to worry about what members are placed where.
|
|
|
|
members []ObjectMember
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectMember is a member of an object type.
|
|
|
|
type ObjectMember struct {
|
|
|
|
name string
|
|
|
|
|
|
|
|
// 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
|
2022-10-01 15:12:43 -06:00
|
|
|
// what members objects have.
|
2022-09-29 15:34:51 -06:00
|
|
|
permission types.Permission
|
|
|
|
|
|
|
|
what Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (member ObjectMember) ToString (indent int) (output string) {
|
|
|
|
output += doIndent (
|
|
|
|
indent,
|
|
|
|
member.name, " ",
|
|
|
|
member.permission.ToString(),
|
|
|
|
"\n")
|
|
|
|
output += member.what.ToString(indent + 1)
|
|
|
|
return
|
2022-09-17 21:36:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToString returns all data stored within the type section, in string form.
|
|
|
|
func (section TypeSection) ToString (indent int) (output string) {
|
2022-10-01 15:21:17 -06:00
|
|
|
output += doIndent(indent, "typeSection ")
|
|
|
|
output += section.permission.ToString() + " "
|
|
|
|
output += section.where.ToString()
|
|
|
|
output += "\n"
|
2022-09-18 00:41:06 -06:00
|
|
|
output += section.what.ToString(indent + 1)
|
2022-09-29 22:04:28 -06:00
|
|
|
if section.argument != nil {
|
|
|
|
output += section.argument.ToString(indent + 1)
|
|
|
|
}
|
2022-09-18 00:41:06 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// analyzeTypeSection analyzes a type section.
|
|
|
|
func (analyzer AnalysisOperation) analyzeTypeSection () (
|
|
|
|
section Section,
|
|
|
|
err error,
|
|
|
|
) {
|
2022-09-29 16:09:52 -06:00
|
|
|
outputSection := TypeSection { }
|
|
|
|
outputSection.where = analyzer.currentPosition
|
2022-09-29 20:54:32 -06:00
|
|
|
|
|
|
|
section = &outputSection
|
2022-09-29 16:09:52 -06:00
|
|
|
analyzer.addSection(section)
|
|
|
|
|
2022-09-18 00:41:06 -06:00
|
|
|
inputSection := analyzer.currentSection.(parser.TypeSection)
|
|
|
|
if inputSection.Permission() == types.PermissionReadWrite {
|
|
|
|
err = inputSection.NewError (
|
2022-09-29 15:34:51 -06:00
|
|
|
"read-write (rw) permission not understood in this " +
|
|
|
|
"context, try read-only (ro)",
|
2022-09-18 00:41:06 -06:00
|
|
|
infoerr.ErrorKindError)
|
|
|
|
}
|
|
|
|
|
2022-10-01 15:21:17 -06:00
|
|
|
outputSection.permission = inputSection.Permission()
|
|
|
|
|
2022-09-18 00:41:06 -06:00
|
|
|
outputSection.what, err = analyzer.analyzeType(inputSection.Type())
|
2022-09-20 09:01:56 -06:00
|
|
|
if err != nil { return }
|
2022-09-29 22:04:28 -06:00
|
|
|
|
|
|
|
if !inputSection.Argument().Nil() {
|
|
|
|
outputSection.argument,
|
|
|
|
err = analyzer.analyzeArgument(inputSection.Argument())
|
|
|
|
if err != nil { return }
|
2022-10-11 15:03:19 -06:00
|
|
|
|
|
|
|
// type check default value
|
2022-10-11 16:03:44 -06:00
|
|
|
err = analyzer.typeCheck (
|
|
|
|
inputSection.Argument().Location(),
|
|
|
|
outputSection.argument,
|
|
|
|
outputSection.what)
|
|
|
|
if err != nil { return }
|
2022-09-29 22:04:28 -06:00
|
|
|
}
|
2022-09-29 20:54:32 -06:00
|
|
|
|
|
|
|
// TODO: analyze members
|
2022-09-18 00:41:06 -06:00
|
|
|
|
|
|
|
outputSection.complete = true
|
2022-09-17 21:36:59 -06:00
|
|
|
return
|
|
|
|
}
|