StringLiteral.canBePassedAs allows variable arrays
This commit is contained in:
parent
942a52f7c6
commit
b8c57d5a56
@ -7,10 +7,8 @@ import "git.tebibyte.media/arf/arf/parser"
|
||||
// allows things like phrases being arguments to other phrases.
|
||||
type Argument interface {
|
||||
// Phrase
|
||||
// List
|
||||
// Dereference
|
||||
// Subscript
|
||||
// Object
|
||||
// Array
|
||||
// Variable
|
||||
// IntLiteral
|
||||
// UIntLiteral
|
||||
@ -21,6 +19,35 @@ type Argument interface {
|
||||
canBePassedAs (what Type) (allowed bool)
|
||||
}
|
||||
|
||||
// phrase
|
||||
// is what
|
||||
// list
|
||||
// is what
|
||||
// dereference
|
||||
// if length is greater than 1
|
||||
// length is 1
|
||||
// is what (ignore length)
|
||||
// else
|
||||
// is points of reduced of what
|
||||
// variable
|
||||
// is what
|
||||
// int
|
||||
// primitive is basic signed | float
|
||||
// length is 1
|
||||
// uint
|
||||
// primitive is basic signed | unsigned | float
|
||||
// length is 1
|
||||
// float
|
||||
// primitive is basic float
|
||||
// length is 1
|
||||
// string
|
||||
// primitive is basic signed | unsigned | float
|
||||
// length is equal
|
||||
// or
|
||||
// reduced is variable array
|
||||
// reduced points to signed | unsigned | float
|
||||
// length is 1
|
||||
|
||||
// analyzeArgument analyzes an argument
|
||||
func (analyzer AnalysisOperation) analyzeArgument (
|
||||
inputArgument parser.Argument,
|
||||
@ -38,9 +65,6 @@ func (analyzer AnalysisOperation) analyzeArgument (
|
||||
case parser.ArgumentKindDereference:
|
||||
// TODO
|
||||
|
||||
case parser.ArgumentKindSubscript:
|
||||
// TODO
|
||||
|
||||
case parser.ArgumentKindList:
|
||||
// TODO
|
||||
|
||||
|
22
analyzer/list.go
Normal file
22
analyzer/list.go
Normal file
@ -0,0 +1,22 @@
|
||||
package analyzer
|
||||
|
||||
// import "git.tebibyte.media/arf/arf/parser"
|
||||
// import "git.tebibyte.media/arf/arf/infoerr"
|
||||
|
||||
type List struct {
|
||||
// TODO: length of what must be set to length of arguments
|
||||
what Type
|
||||
arguments []Argument
|
||||
}
|
||||
|
||||
func (list List) ToString (indent int) (output string) {
|
||||
// TODO
|
||||
panic("TODO")
|
||||
return
|
||||
}
|
||||
|
||||
func (list List) canBePassedAs (what Type) (allowed bool) {
|
||||
// TODO
|
||||
panic("TODO")
|
||||
return
|
||||
}
|
@ -104,7 +104,18 @@ func (literal StringLiteral) ToString (indent int) (output string) {
|
||||
// canBePassedAs returns true if this literal can be implicitly cast to the
|
||||
// specified type, and false if it can't.
|
||||
func (literal StringLiteral) canBePassedAs (what Type) (allowed bool) {
|
||||
// can be passed to types that are numbers at a primitive level.
|
||||
// can be passed to types that are numbers at a primitive level, or
|
||||
// types that can be reduced to a variable array pointing to numbers at
|
||||
// a primitive level.
|
||||
|
||||
what, worked := what.reduce()
|
||||
if worked {
|
||||
// TODO: make some method to check the total length of a type
|
||||
if what.length != 1 { return }
|
||||
|
||||
if what.kind != TypeKindVariableArray { return }
|
||||
}
|
||||
|
||||
primitive := what.underlyingPrimitive()
|
||||
switch primitive {
|
||||
case
|
||||
|
@ -80,6 +80,9 @@ func (analyzer AnalysisOperation) analyzeTypeSection () (
|
||||
outputSection.argument,
|
||||
err = analyzer.analyzeArgument(inputSection.Argument())
|
||||
if err != nil { return }
|
||||
if !outputSection.argument.canBePassedAs(outputSection.what) {
|
||||
|
||||
}
|
||||
// TODO: type check default value. possibly add a method to
|
||||
// Argument that takes in a type and determines whether the
|
||||
// argument can fit to it.
|
||||
|
@ -68,7 +68,7 @@ func (what Type) ToString (indent int) (output string) {
|
||||
}
|
||||
|
||||
// underlyingPrimitive returns the primitive that this type eventually inherits
|
||||
// from.
|
||||
// from. If the type ends up pointing to something, this returns nil.
|
||||
func (what Type) underlyingPrimitive () (underlying *TypeSection) {
|
||||
// if we have already done this operation, return the cahced result.
|
||||
if what.primitiveCache != nil {
|
||||
|
Reference in New Issue
Block a user