Updated analyzer

This commit is contained in:
Sasha Koshka 2024-03-14 03:18:46 -04:00
parent d04e9d28ed
commit dce9e1d85d
8 changed files with 106 additions and 106 deletions

View File

@ -381,54 +381,54 @@ func (this *Tree) isLocationExpression (expression entity.Expression) error {
case *entity.Declaration: case *entity.Declaration:
return nil return nil
case *entity.Call: case *entity.Call:
return cannot(expression.Position, "function call") return cannot(expression.Position(), "function call")
case *entity.MethodCall: case *entity.MethodCall:
return cannot(expression.Position, "method call") return cannot(expression.Position(), "method call")
case *entity.Subscript: case *entity.Subscript:
return this.isLocationExpression(expression.Slice) return this.isLocationExpression(expression.Slice)
case *entity.Slice: case *entity.Slice:
return cannot(expression.Position, "slice operation") return cannot(expression.Position(), "slice operation")
case *entity.Dereference: case *entity.Dereference:
return this.isLocationExpression(expression.Pointer) return this.isLocationExpression(expression.Pointer)
case *entity.Reference: case *entity.Reference:
return cannot(expression.Position, "reference operation") return cannot(expression.Position(), "reference operation")
case *entity.ValueCast: case *entity.ValueCast:
return cannot(expression.Position, "value cast") return cannot(expression.Position(), "value cast")
case *entity.BitCast: case *entity.BitCast:
return cannot(expression.Position, "bit cast") return cannot(expression.Position(), "bit cast")
case *entity.Operation: case *entity.Operation:
return cannot(expression.Position, fmt.Sprintf ( return cannot(expression.Position(), fmt.Sprintf (
"cannot assign to %v operation", "cannot assign to %v operation",
expression.Operator)) expression.Operator))
case *entity.Block: case *entity.Block:
return cannot(expression.Position, "block") return cannot(expression.Position(), "block")
case *entity.MemberAccess: case *entity.MemberAccess:
return this.isLocationExpression ( return this.isLocationExpression (
expression.Source) expression.Source)
case *entity.IfElse: case *entity.IfElse:
return cannot(expression.Position, "if/else") return cannot(expression.Position(), "if/else")
case *entity.Match: case *entity.Match:
return cannot(expression.Position, "match") return cannot(expression.Position(), "match")
case *entity.Loop: case *entity.Loop:
return cannot(expression.Position, "loop") return cannot(expression.Position(), "loop")
case *entity.Break: case *entity.Break:
return cannot(expression.Position, "break statement") return cannot(expression.Position(), "break statement")
case *entity.Return: case *entity.Return:
return cannot(expression.Position, "return statement") return cannot(expression.Position(), "return statement")
case *entity.LiteralInt: case *entity.LiteralInt:
return cannot(expression.Position, "integer literal") return cannot(expression.Position(), "integer literal")
case *entity.LiteralFloat: case *entity.LiteralFloat:
return cannot(expression.Position, "float literal") return cannot(expression.Position(), "float literal")
case *entity.LiteralString: case *entity.LiteralString:
return cannot(expression.Position, "string literal") return cannot(expression.Position(), "string literal")
case *entity.LiteralArray: case *entity.LiteralArray:
return cannot(expression.Position, "array literal") return cannot(expression.Position(), "array literal")
case *entity.LiteralStruct: case *entity.LiteralStruct:
return cannot(expression.Position, "struct literal") return cannot(expression.Position(), "struct literal")
case *entity.LiteralBoolean: case *entity.LiteralBoolean:
return cannot(expression.Position, "boolean literal") return cannot(expression.Position(), "boolean literal")
case *entity.LiteralNil: case *entity.LiteralNil:
return cannot(expression.Position, "nil literal") return cannot(expression.Position(), "nil literal")
default: default:
panic(fmt.Sprint ( panic(fmt.Sprint (
"BUG: analyzer doesnt know about expression", "BUG: analyzer doesnt know about expression",

View File

@ -43,11 +43,11 @@ func (this *Tree) analyzeVariable (
declaration := this.variable(variable.Name) declaration := this.variable(variable.Name)
if declaration == nil { if declaration == nil {
return nil, errors.Errorf ( return nil, errors.Errorf (
variable.Position, "no variable named %s", variable.Position(), "no variable named %s",
variable.Name) variable.Name)
} }
err := this.canAssign(variable.Position, into, mode, declaration.Type()) err := this.canAssign(variable.Position(), into, mode, declaration.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
variable.Declaration = declaration variable.Declaration = declaration
@ -66,16 +66,16 @@ func (this *Tree) analyzeDeclaration (
existing := scope.Variable(declaration.Name) existing := scope.Variable(declaration.Name)
if existing != nil { if existing != nil {
return nil, errors.Errorf ( return nil, errors.Errorf (
declaration.Position, declaration.Position(),
"%s already declared in block at %v", "%s already declared in block at %v",
declaration.Name, existing.Position) declaration.Name, existing.Position())
} }
ty, err := this.analyzeType(declaration.Ty, false) ty, err := this.analyzeType(declaration.Ty, false)
declaration.Ty = ty declaration.Ty = ty
if err != nil { return nil, err } if err != nil { return nil, err }
err = this.canAssign(declaration.Position, into, mode, declaration.Type()) err = this.canAssign(declaration.Position(), into, mode, declaration.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
this.addVariable(declaration) this.addVariable(declaration)
@ -91,35 +91,35 @@ func (this *Tree) analyzeCall (
error, error,
) { ) {
// get function // get function
unit, err := this.resolveNickname(call.Position, call.UnitNickname) unit, err := this.resolveNickname(call.Position(), call.UnitNickname)
if err != nil { return nil, err } if err != nil { return nil, err }
function, err := this.analyzeFunction(call.Position, entity.Key { function, err := this.analyzeFunction(call.Position(), entity.Key {
Unit: unit, Unit: unit,
Name: call.Name, Name: call.Name,
}) })
if err != nil { return nil, err } if err != nil { return nil, err }
call.Function = function call.Function = function
call.Unit = function.Unit call.Unit = function.Unit()
// check access permissions // check access permissions
if function.Acc == entity.AccessPrivate && function.Unit != this.unit { if function.Acc == entity.AccessPrivate && function.Unit() != this.unit {
return nil, errors.Errorf ( return nil, errors.Errorf (
call.Position, "function %v::[%v] is private", call.Position(), "function %v::[%v] is private",
call.UnitNickname, call.Name) call.UnitNickname, call.Name)
} }
// check return result // check return result
err = this.canAssign(call.Position, into, mode, function.Signature.Return) err = this.canAssign(call.Position(), into, mode, function.Signature.Return)
if err != nil { return nil, err } if err != nil { return nil, err }
// check arg count // check arg count
if len(call.Arguments) > len(function.Signature.Arguments) { if len(call.Arguments) > len(function.Signature.Arguments) {
return nil, errors.Errorf ( return nil, errors.Errorf (
call.Position, "too many arguments in call to %s", call.Position(), "too many arguments in call to %s",
call.Name) call.Name)
} else if len(call.Arguments) < len(function.Signature.Arguments) { } else if len(call.Arguments) < len(function.Signature.Arguments) {
return nil, errors.Errorf ( return nil, errors.Errorf (
call.Position, "too few arguments in call to %s", call.Position(), "too few arguments in call to %s",
call.Name) call.Name)
} }
@ -147,7 +147,7 @@ func (this *Tree) analyzeMethodCall (
source, err := this.analyzeExpression(nil, strict, call.Source) source, err := this.analyzeExpression(nil, strict, call.Source)
if err != nil { return nil, err } if err != nil { return nil, err }
method, err := this.analyzeMethodOrBehavior ( method, err := this.analyzeMethodOrBehavior (
call.Position, source.Type(), call.Name) call.Position(), source.Type(), call.Name)
if err != nil { return nil, err } if err != nil { return nil, err }
// extract signature // extract signature
@ -159,7 +159,7 @@ func (this *Tree) analyzeMethodCall (
// since this is a behavior, check access permissions of the // since this is a behavior, check access permissions of the
// interface // interface
err = this.typeOpaque(call.Position, source.Type()) err = this.typeOpaque(call.Position(), source.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
case *entity.Method: case *entity.Method:
@ -168,9 +168,9 @@ func (this *Tree) analyzeMethodCall (
// since this is a method, check access permissions of the // since this is a method, check access permissions of the
// method // method
if method.Acc == entity.AccessPrivate && method.Unit != this.unit { if method.Acc == entity.AccessPrivate && method.Unit() != this.unit {
return nil, errors.Errorf ( return nil, errors.Errorf (
call.Position, "method %v.[%v] is private", call.Position(), "method %v.[%v] is private",
method.TypeName, method.Signature.Name) method.TypeName, method.Signature.Name)
} }
@ -181,17 +181,17 @@ func (this *Tree) analyzeMethodCall (
} }
// check return result // check return result
err = this.canAssign(call.Position, into, mode, signature.Return) err = this.canAssign(call.Position(), into, mode, signature.Return)
if err != nil { return nil, err } if err != nil { return nil, err }
// check arg count // check arg count
if len(call.Arguments) > len(signature.Arguments) { if len(call.Arguments) > len(signature.Arguments) {
return nil, errors.Errorf ( return nil, errors.Errorf (
call.Position, "too many arguments in call to %s", call.Position(), "too many arguments in call to %s",
call.Name) call.Name)
} else if len(call.Arguments) < len(signature.Arguments) { } else if len(call.Arguments) < len(signature.Arguments) {
return nil, errors.Errorf ( return nil, errors.Errorf (
call.Position, "too few arguments in call to %s", call.Position(), "too few arguments in call to %s",
call.Name) call.Name)
} }
@ -216,7 +216,7 @@ func (this *Tree) analyzeSubscript (
) { ) {
slice, err := this.analyzeExpression ( slice, err := this.analyzeExpression (
&entity.TypeSlice { &entity.TypeSlice {
Pos: subscript.Position, Pos: subscript.Position(),
Element: into, Element: into,
}, weak, }, weak,
subscript.Slice) subscript.Slice)
@ -225,7 +225,7 @@ func (this *Tree) analyzeSubscript (
subscript.Ty = into subscript.Ty = into
// check permissions // check permissions
err = this.typeOpaque(subscript.Position, slice.Type()) err = this.typeOpaque(subscript.Position(), slice.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
offset, err := this.analyzeExpression ( offset, err := this.analyzeExpression (
@ -264,7 +264,7 @@ func (this *Tree) analyzeSlice (
slice.Slice = value slice.Slice = value
// check permissions // check permissions
err = this.typeOpaque(slice.Position, value.Type()) err = this.typeOpaque(slice.Position(), value.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
if slice.Start != nil { if slice.Start != nil {
@ -312,7 +312,7 @@ func (this *Tree) analyzeDereference (
) { ) {
pointer, err := this.analyzeExpression ( pointer, err := this.analyzeExpression (
&entity.TypePointer { &entity.TypePointer {
Pos: dereference.Position, Pos: dereference.Position(),
Referenced: into, Referenced: into,
}, weak, }, weak,
dereference.Pointer) dereference.Pointer)
@ -346,7 +346,7 @@ func (this *Tree) analyzeReference (
) { ) {
referenced, ok := into.(*entity.TypePointer) referenced, ok := into.(*entity.TypePointer)
if !ok { if !ok {
return nil, errors.Errorf(reference.Position, "expected %v", into) return nil, errors.Errorf(reference.Position(), "expected %v", into)
} }
value, err := this.analyzeExpression ( value, err := this.analyzeExpression (
@ -373,7 +373,7 @@ func (this *Tree) analyzeValueCast (
if err != nil { return nil, err } if err != nil { return nil, err }
cast.Ty = ty cast.Ty = ty
err = this.canAssign(cast.Position, into, mode, cast.Type()) err = this.canAssign(cast.Position(), into, mode, cast.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
value, err := this.analyzeExpression(cast.Ty, coerce, cast.Value) value, err := this.analyzeExpression(cast.Ty, coerce, cast.Value)
@ -395,7 +395,7 @@ func (this *Tree) analyzeBitCast (
if err != nil { return nil, err } if err != nil { return nil, err }
cast.Ty = ty cast.Ty = ty
err = this.canAssign(cast.Position, into, mode, cast.Type()) err = this.canAssign(cast.Position(), into, mode, cast.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
value, err := this.analyzeExpression(cast.Ty, force, cast.Value) value, err := this.analyzeExpression(cast.Ty, force, cast.Value)
@ -414,26 +414,26 @@ func (this *Tree) analyzeOperation (
error, error,
) { ) {
// check permissions // check permissions
err := this.typeOpaque(operation.Position, into) err := this.typeOpaque(operation.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
intoUntrustworthy := into == nil || mode == force || mode == coerce intoUntrustworthy := into == nil || mode == force || mode == coerce
undefined := func (ty entity.Type) (entity.Expression, error) { undefined := func (ty entity.Type) (entity.Expression, error) {
return nil, errors.Errorf ( return nil, errors.Errorf (
operation.Position, "operator %v undefined for %v", operation.Position(), "operator %v undefined for %v",
operation.Operator, entity.FormatType(ty)) operation.Operator, entity.FormatType(ty))
} }
wrongInto := func () (entity.Expression, error) { wrongInto := func () (entity.Expression, error) {
return nil, errors.Errorf ( return nil, errors.Errorf (
operation.Position, "expected %v", operation.Position(), "expected %v",
entity.FormatType(into)) entity.FormatType(into))
} }
wrongArgCount := func () (entity.Expression, error) { wrongArgCount := func () (entity.Expression, error) {
return nil, errors.Errorf ( return nil, errors.Errorf (
operation.Position, "wrong argument count for %v", operation.Position(), "wrong argument count for %v",
operation.Operator) operation.Operator)
} }
@ -453,7 +453,7 @@ func (this *Tree) analyzeOperation (
} }
if argumentType == nil { if argumentType == nil {
return nil, -1, errors.Errorf ( return nil, -1, errors.Errorf (
operation.Position, operation.Position(),
"operation arguments have ambiguous type") "operation arguments have ambiguous type")
} }
return argumentType, boss, err return argumentType, boss, err
@ -594,7 +594,7 @@ func (this *Tree) analyzeBlock (
if len(block.Steps) == 0 && into != nil { if len(block.Steps) == 0 && into != nil {
return nil, errors.Errorf ( return nil, errors.Errorf (
block.Position, "block must have at least one statement") block.Position(), "block must have at least one statement")
} }
final := len(block.Steps) - 1 final := len(block.Steps) - 1
@ -603,7 +603,7 @@ func (this *Tree) analyzeBlock (
expression, ok := step.(entity.Expression) expression, ok := step.(entity.Expression)
if !ok { if !ok {
return nil, errors.Errorf ( return nil, errors.Errorf (
block.Position, "expected expression") block.Position(), "expected expression")
} }
step, err := this.analyzeExpression(into, strict, expression) step, err := this.analyzeExpression(into, strict, expression)
@ -642,30 +642,30 @@ func (this *Tree) analyzeMemberAccess (
referenced, ok := ReduceToBase(sourceTypeAny.Referenced).(*entity.TypeStruct) referenced, ok := ReduceToBase(sourceTypeAny.Referenced).(*entity.TypeStruct)
if !ok { if !ok {
return nil, errors.Errorf ( return nil, errors.Errorf (
access.Position, "cannot access members of %v", access.Position(), "cannot access members of %v",
source) source)
} }
sourceType = referenced sourceType = referenced
qualifiedSourceType = sourceTypeAny.Referenced qualifiedSourceType = sourceTypeAny.Referenced
default: default:
return nil, errors.Errorf ( return nil, errors.Errorf (
access.Position, "cannot access members of %v", access.Position(), "cannot access members of %v",
source) source)
} }
// check permissions // check permissions
err = this.typeOpaque(access.Position, qualifiedSourceType) err = this.typeOpaque(access.Position(), qualifiedSourceType)
if err != nil { return nil, err } if err != nil { return nil, err }
// get member // get member
member, ok := sourceType.MemberMap[access.Member] member, ok := sourceType.MemberMap[access.Member]
if !ok { if !ok {
return nil, errors.Errorf ( return nil, errors.Errorf (
access.Position, "no member %v", access.Position(), "no member %v",
access) access)
} }
err = this.canAssign(access.Position, into, mode, member.Type()) err = this.canAssign(access.Position(), into, mode, member.Type())
if err != nil { return nil, err } if err != nil { return nil, err }
access.Ty = member.Type() access.Ty = member.Type()
@ -696,7 +696,7 @@ func (this *Tree) analyzeIfElse (
if ifelse.False == nil { if ifelse.False == nil {
if into != nil { if into != nil {
return nil, errors.Errorf ( return nil, errors.Errorf (
ifelse.Position, ifelse.Position(),
"else case required when using value of if") "else case required when using value of if")
} }
} else { } else {
@ -726,7 +726,7 @@ func (this *Tree) analyzeMatch (
// FIXME: add Position() method to Expression, then change this // FIXME: add Position() method to Expression, then change this
// error message (and others) #53 // error message (and others) #53
return nil, errors.Errorf ( return nil, errors.Errorf (
match.Position, "type %v is not a union", match.Position(), "type %v is not a union",
value.Type()) value.Type())
} }
@ -761,7 +761,7 @@ func (this *Tree) analyzeMatch (
if into != nil && len(match.Cases) < len(rawUnion.Allowed) { if into != nil && len(match.Cases) < len(rawUnion.Allowed) {
return nil, errors.Errorf ( return nil, errors.Errorf (
match.Position, match.Position(),
"match does not cover all types within %v", "match does not cover all types within %v",
value.Type()) value.Type())
} }
@ -819,14 +819,14 @@ func (this *Tree) analyzeBreak (
loop, ok := this.topLoop() loop, ok := this.topLoop()
if !ok { if !ok {
return nil, errors.Errorf ( return nil, errors.Errorf (
brk.Position, brk.Position(),
"break statement must be within loop") "break statement must be within loop")
} }
brk.Loop = loop brk.Loop = loop
if loop.Type() != nil && brk.Value == nil { if loop.Type() != nil && brk.Value == nil {
return nil, errors.Errorf ( return nil, errors.Errorf (
brk.Position, brk.Position(),
"break statement must have value") "break statement must have value")
} }
@ -858,7 +858,7 @@ func (this *Tree) analyzeReturn (
if ty != nil && ret.Value == nil { if ty != nil && ret.Value == nil {
return nil, errors.Errorf ( return nil, errors.Errorf (
ret.Position, ret.Position(),
"break statement must have value") "break statement must have value")
} }

View File

@ -24,7 +24,7 @@ func (this *Tree) analyzeFunction (
} }
// set unit // set unit
function.Unit = key.Unit function.Unt = key.Unit
// functions cannot be marked as opaque // functions cannot be marked as opaque
if function.Acc == entity.AccessOpaque { if function.Acc == entity.AccessOpaque {

View File

@ -12,18 +12,18 @@ func (this *Tree) analyzeLiteralInt (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
if !isNumeric(into) { if !isNumeric(into) {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "cannot use integer literal as %v", literal.Position(), "cannot use integer literal as %v",
entity.FormatType(into)) entity.FormatType(into))
} }
if isInteger(into) && !inRange(into, int64(literal.Value)) { if isInteger(into) && !inRange(into, int64(literal.Value)) {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "integer literal out of range for type %v", literal.Position(), "integer literal out of range for type %v",
entity.FormatType(into)) entity.FormatType(into))
} }
@ -39,12 +39,12 @@ func (this *Tree) analyzeLiteralFloat (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
if !isFloat(into) { if !isFloat(into) {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "cannot use float literal as %v", literal.Position(), "cannot use float literal as %v",
entity.FormatType(into)) entity.FormatType(into))
} }
@ -60,14 +60,14 @@ func (this *Tree) analyzeLiteralString (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
base := ReduceToBase(into) base := ReduceToBase(into)
errCantUse := func () error { errCantUse := func () error {
return errors.Errorf ( return errors.Errorf (
literal.Position, "cannot use string literal as %v", literal.Position(), "cannot use string literal as %v",
entity.FormatType(into)) entity.FormatType(into))
} }
@ -92,13 +92,13 @@ func (this *Tree) analyzeLiteralString (
} }
if length > 1 { if length > 1 {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, literal.Position(),
"cannot fit string literal of length " + "cannot fit string literal of length " +
"%v into %v", "%v into %v",
length, entity.FormatType(into)) length, entity.FormatType(into))
} else if length < 1 { } else if length < 1 {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, literal.Position(),
"string literal must have data when " + "string literal must have data when " +
"assigning to %v", "assigning to %v",
entity.FormatType(into)) entity.FormatType(into))
@ -118,7 +118,7 @@ func (this *Tree) analyzeLiteralString (
} }
if length > base.Length { if length > base.Length {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, literal.Position(),
"cannot fit string literal of length " + "cannot fit string literal of length " +
"%v into array of length %v", "%v into array of length %v",
length, base.Length) length, base.Length)
@ -163,7 +163,7 @@ func (this *Tree) analyzeLiteralArray (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
base := ReduceToBase(into) base := ReduceToBase(into)
@ -173,7 +173,7 @@ func (this *Tree) analyzeLiteralArray (
base := base.(*entity.TypeArray) base := base.(*entity.TypeArray)
if base.Length < len(literal.Elements) { if base.Length < len(literal.Elements) {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "expected %v elements or less", literal.Position(), "expected %v elements or less",
base.Length) base.Length)
} }
elementType = base.Element elementType = base.Element
@ -187,7 +187,7 @@ func (this *Tree) analyzeLiteralArray (
elementType = base.Referenced elementType = base.Referenced
default: default:
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "cannot use array literal as %v", literal.Position(), "cannot use array literal as %v",
entity.FormatType(into)) entity.FormatType(into))
} }
@ -209,13 +209,13 @@ func (this *Tree) analyzeLiteralStruct (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
base, ok := ReduceToBase(into).(*entity.TypeStruct) base, ok := ReduceToBase(into).(*entity.TypeStruct)
if !ok { if !ok {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "cannot use struct literal as %v", literal.Position(), "cannot use struct literal as %v",
entity.FormatType(into)) entity.FormatType(into))
} }
@ -226,7 +226,7 @@ func (this *Tree) analyzeLiteralStruct (
correct, ok := base.MemberMap[name] correct, ok := base.MemberMap[name]
if !ok { if !ok {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "no member %v.%s", literal.Position(), "no member %v.%s",
into, name) into, name)
} }
@ -247,12 +247,12 @@ func (this *Tree) analyzeLiteralBoolean (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
if !isBoolean(into) { if !isBoolean(into) {
return nil, errors.Errorf ( return nil, errors.Errorf (
literal.Position, "cannot use boolean literal as %v", literal.Position(), "cannot use boolean literal as %v",
entity.FormatType(into)) entity.FormatType(into))
} }
@ -268,7 +268,7 @@ func (this *Tree) analyzeLiteralNil (
entity.Expression, entity.Expression,
error, error,
) { ) {
err := this.typeOpaque(literal.Position, into) err := this.typeOpaque(literal.Position(), into)
if err != nil { return nil, err } if err != nil { return nil, err }
literal.Ty = into literal.Ty = into
@ -286,8 +286,8 @@ func (this *Tree) assembleStructLiteralMap (
for index, member := range literal.Members { for index, member := range literal.Members {
if previous, exists := literal.MemberMap[member.Name]; exists { if previous, exists := literal.MemberMap[member.Name]; exists {
return literal, errors.Errorf ( return literal, errors.Errorf (
member.Position, "%s already listed in struct literal at %v", member.Position(), "%s already listed in struct literal at %v",
member.Name, previous.Position) member.Name, previous.Position())
} }
literal.MemberMap [member.Name] = member literal.MemberMap [member.Name] = member
literal.MemberOrder[index] = member.Name literal.MemberOrder[index] = member.Name

View File

@ -30,7 +30,7 @@ func (this *Tree) analyzeMethod (
} }
// set method's unit, very important information yes // set method's unit, very important information yes
method.Unit = owner.Unit method.Unt = owner.Unit()
// methods cannot be marked as opaque // methods cannot be marked as opaque
if method.Acc == entity.AccessOpaque { if method.Acc == entity.AccessOpaque {
@ -58,12 +58,12 @@ func (this *Tree) analyzeMethod (
// add owner to method // add owner to method
method.This = &entity.Declaration { method.This = &entity.Declaration {
Position: method.Position, Pos: method.Position(),
Name: "this", Name: "this",
Ty: &entity.TypePointer { Ty: &entity.TypePointer {
Pos: method.Position, Pos: method.Position(),
Referenced: &entity.TypeNamed { Referenced: &entity.TypeNamed {
Pos: method.Position, Pos: method.Position(),
Unt: key.Unit, Unt: key.Unit,
Name: key.Name, Name: key.Name,
Type: owner.Type, Type: owner.Type,

View File

@ -9,8 +9,8 @@ func (this *Tree) assembleSignatureMap (signature *entity.Signature) (*entity.Si
for index, member := range signature.Arguments { for index, member := range signature.Arguments {
if previous, exists := signature.ArgumentMap[member.Name]; exists { if previous, exists := signature.ArgumentMap[member.Name]; exists {
return signature, errors.Errorf ( return signature, errors.Errorf (
member.Position, "%s already listed as argument at %v", member.Position(), "%s already listed as argument at %v",
member.Name, previous.Position) member.Name, previous.Position())
} }
signature.ArgumentMap [member.Name] = member signature.ArgumentMap [member.Name] = member
signature.ArgumentOrder[index] = member.Name signature.ArgumentOrder[index] = member.Name

View File

@ -47,7 +47,7 @@ func (this *Tree) assembleRawMaps () error {
Unit: this.unit, Unit: this.unit,
Name: declaration.Name, Name: declaration.Name,
} }
err := this.topLevelNameAvailable(declaration.Position, key) err := this.topLevelNameAvailable(declaration.Position(), key)
if err != nil { return err } if err != nil { return err }
declaration.Methods = make(map[string] *entity.Method) declaration.Methods = make(map[string] *entity.Method)
this.rawTypes[key] = declaration this.rawTypes[key] = declaration
@ -57,7 +57,7 @@ func (this *Tree) assembleRawMaps () error {
Unit: this.unit, Unit: this.unit,
Name: declaration.Signature.Name, Name: declaration.Signature.Name,
} }
err := this.topLevelNameAvailable(declaration.Position, key) err := this.topLevelNameAvailable(declaration.Position(), key)
if err != nil { return err } if err != nil { return err }
this.rawFunctions[key] = declaration this.rawFunctions[key] = declaration
@ -67,7 +67,7 @@ func (this *Tree) assembleRawMaps () error {
Name: declaration.TypeName, Name: declaration.TypeName,
Method: declaration.Signature.Name, Method: declaration.Signature.Name,
} }
err := this.topLevelNameAvailable(declaration.Position, key) err := this.topLevelNameAvailable(declaration.Position(), key)
if err != nil { return err } if err != nil { return err }
this.rawMethods[key] = declaration this.rawMethods[key] = declaration
} }
@ -89,34 +89,34 @@ func (this *Tree) topLevelNameAvailable (currentPos errors.Position, key entity.
if ty, isType := this.rawTypes[key]; isType { if ty, isType := this.rawTypes[key]; isType {
return errors.Errorf ( return errors.Errorf (
currentPos, "%s already declared at %v", currentPos, "%s already declared at %v",
key.Name, ty.Position) key.Name, ty.Position())
} }
if function, isFunction := this.rawFunctions[key]; isFunction { if function, isFunction := this.rawFunctions[key]; isFunction {
return errors.Errorf ( return errors.Errorf (
currentPos, "%s already declared at %v", currentPos, "%s already declared at %v",
key.Name, function.Position) key.Name, function.Position())
} }
if method, isMethod := this.rawMethods[key]; isMethod { if method, isMethod := this.rawMethods[key]; isMethod {
return errors.Errorf ( return errors.Errorf (
currentPos, "%s.%s already declared at %v", currentPos, "%s.%s already declared at %v",
key.Name, key.Method, method.Position) key.Name, key.Method, method.Position())
} }
return nil return nil
} }
func (this *Tree) analyzeDeclarations () error { func (this *Tree) analyzeDeclarations () error {
for key, rawType := range this.rawTypes { for key, rawType := range this.rawTypes {
ty, err := this.analyzeTypedef(rawType.Position, key, false) ty, err := this.analyzeTypedef(rawType.Position(), key, false)
if err != nil { return err } if err != nil { return err }
this.Types[key] = ty this.Types[key] = ty
} }
for key, rawFunction := range this.rawFunctions { for key, rawFunction := range this.rawFunctions {
_, err := this.analyzeFunction(rawFunction.Position, key) _, err := this.analyzeFunction(rawFunction.Position(), key)
if err != nil { return err } if err != nil { return err }
} }
for _, rawMethod := range this.rawMethods { for _, rawMethod := range this.rawMethods {
_, err := this.analyzeMethod ( _, err := this.analyzeMethod (
rawMethod.Position, rawMethod.Position(),
entity.Key { entity.Key {
Unit: this.unit, Unit: this.unit,
Name: rawMethod.TypeName, Name: rawMethod.TypeName,

View File

@ -36,7 +36,7 @@ func (this *Tree) analyzeTypedef (
// analyze if it still needs to be analyzed // analyze if it still needs to be analyzed
if definition, exists := this.rawTypes[key]; exists { if definition, exists := this.rawTypes[key]; exists {
// update unit // update unit
definition.Unit = key.Unit definition.Unt = key.Unit
// analyze // analyze
var err error var err error
@ -246,8 +246,8 @@ func (this *Tree) assembleStructMap (ty *entity.TypeStruct) (*entity.TypeStruct,
for index, member := range ty.Members { for index, member := range ty.Members {
if previous, exists := ty.MemberMap[member.Name]; exists { if previous, exists := ty.MemberMap[member.Name]; exists {
return ty, errors.Errorf ( return ty, errors.Errorf (
member.Position, "%s already listed in struct at %v", member.Position(), "%s already listed in struct at %v",
member.Name, previous.Position) member.Name, previous.Position())
} }
ty.MemberMap [member.Name] = member ty.MemberMap [member.Name] = member
ty.MemberOrder[index] = member.Name ty.MemberOrder[index] = member.Name