91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
package analyzer
|
|
|
|
import "fmt"
|
|
import "git.tebibyte.media/sashakoshka/fspl/entity"
|
|
|
|
func (this *Tree) analyzeExpression (
|
|
into entity.Type,
|
|
mode strictness,
|
|
expression entity.Expression,
|
|
) (
|
|
entity.Expression,
|
|
error,
|
|
) {
|
|
switch expression := expression.(type) {
|
|
case *entity.Variable:
|
|
return this.analyzeVariable(into, mode, expression)
|
|
case *entity.Declaration:
|
|
return this.analyzeDeclaration(into, mode, expression)
|
|
case *entity.Call:
|
|
return this.analyzeCall(into, mode, expression)
|
|
case *entity.MethodCall:
|
|
return this.analyzeMethodCall(into, mode, expression)
|
|
case *entity.Subscript:
|
|
return this.analyzeSubscript(into, mode, expression)
|
|
case *entity.Slice:
|
|
return this.analyzeSlice(into, mode, expression)
|
|
case *entity.Length:
|
|
return this.analyzeLength(into, mode, expression)
|
|
case *entity.Dereference:
|
|
return this.analyzeDereference(into, mode, expression)
|
|
case *entity.Reference:
|
|
return this.analyzeReference(into, mode, expression)
|
|
case *entity.ValueCast:
|
|
return this.analyzeValueCast(into, mode, expression)
|
|
case *entity.BitCast:
|
|
return this.analyzeBitCast(into, mode, expression)
|
|
case *entity.Operation:
|
|
return this.analyzeOperation(into, mode, expression)
|
|
case *entity.Block:
|
|
return this.analyzeBlock(into, mode, expression)
|
|
case *entity.MemberAccess:
|
|
return this.analyzeMemberAccess(into, mode, expression)
|
|
case *entity.IfElse:
|
|
return this.analyzeIfElse(into, mode, expression)
|
|
case *entity.Loop:
|
|
return this.analyzeLoop(into, mode, expression)
|
|
case *entity.Break:
|
|
return this.analyzeBreak(into, mode, expression)
|
|
case *entity.Return:
|
|
return this.analyzeReturn(into, mode, expression)
|
|
|
|
case *entity.LiteralInt:
|
|
return this.analyzeLiteralInt(into, mode, expression)
|
|
case *entity.LiteralFloat:
|
|
return this.analyzeLiteralFloat(into, mode, expression)
|
|
case *entity.LiteralArray:
|
|
return this.analyzeLiteralArray(into, mode, expression)
|
|
case *entity.LiteralString:
|
|
return this.analyzeLiteralString(into, mode, expression)
|
|
case *entity.LiteralStruct:
|
|
return this.analyzeLiteralStruct(into, mode, expression)
|
|
case *entity.LiteralBoolean:
|
|
return this.analyzeLiteralBoolean(into, mode, expression)
|
|
case *entity.LiteralNil:
|
|
return this.analyzeLiteralNil(into, mode, expression)
|
|
default:
|
|
panic(fmt.Sprintf (
|
|
"BUG: analyzer doesnt know about expression %v, ty: %T",
|
|
expression, expression))
|
|
}
|
|
}
|
|
|
|
func (this *Tree) analyzeStatement (
|
|
statement entity.Statement,
|
|
) (
|
|
entity.Statement,
|
|
error,
|
|
) {
|
|
if assignment, ok := statement.(*entity.Assignment); ok {
|
|
return this.analyzeAssignment(assignment)
|
|
} else if expression, ok := statement.(entity.Expression); ok {
|
|
expression, err := this.analyzeExpression(nil, strict, expression)
|
|
if err != nil { return nil, err }
|
|
return expression.(entity.Statement), nil
|
|
} else {
|
|
panic(fmt.Sprintf (
|
|
"BUG: analyzer doesnt know about statement %v, ty: %T",
|
|
statement, statement))
|
|
}
|
|
}
|