Fix behavior of Tree.analyzeMethodOrBehavior()
This commit is contained in:
parent
6c7c7c9d99
commit
1fea25ba91
@ -98,9 +98,16 @@ func (this *Tree) analyzeCall (
|
|||||||
Name: call.Name,
|
Name: call.Name,
|
||||||
})
|
})
|
||||||
call.Function = function
|
call.Function = function
|
||||||
call.Unit = unit
|
call.Unit = function.Unit
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
|
// check access permissions
|
||||||
|
if function.Acc == entity.AccessPrivate && function.Unit != this.unit {
|
||||||
|
return nil, errors.Errorf (
|
||||||
|
call.Position, "function %v::[%v] is private",
|
||||||
|
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 }
|
||||||
@ -145,13 +152,20 @@ func (this *Tree) analyzeMethodCall (
|
|||||||
|
|
||||||
// extract signature
|
// extract signature
|
||||||
var signature *entity.Signature
|
var signature *entity.Signature
|
||||||
switch method.(type) {
|
switch method := method.(type) {
|
||||||
case *entity.Signature:
|
case *entity.Signature:
|
||||||
signature = method.(*entity.Signature)
|
signature = method
|
||||||
call.Behavior = signature
|
call.Behavior = signature
|
||||||
case *entity.Method:
|
case *entity.Method:
|
||||||
signature = method.(*entity.Method).Signature
|
signature = method.Signature
|
||||||
call.Method = method.(*entity.Method)
|
call.Method = method
|
||||||
|
|
||||||
|
// since this is a method, check access permissions
|
||||||
|
if method.Acc == entity.AccessPrivate && method.Unit != this.unit {
|
||||||
|
return nil, errors.Errorf (
|
||||||
|
method.Position, "method %v.[%v] is private",
|
||||||
|
method.TypeName, method.Signature.Name)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprint (
|
panic(fmt.Sprint (
|
||||||
"Tree.analyzeMethodOrBehavior returned ",
|
"Tree.analyzeMethodOrBehavior returned ",
|
||||||
|
@ -37,6 +37,9 @@ func (this *Tree) analyzeMethod (
|
|||||||
typeKey.Name, name)
|
typeKey.Name, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set method's unit, very important information yes
|
||||||
|
method.Unit = owner.Unit
|
||||||
|
|
||||||
// create a new scope context for this function
|
// create a new scope context for this function
|
||||||
this.pushScopeContext(method)
|
this.pushScopeContext(method)
|
||||||
this.pushScope(method)
|
this.pushScope(method)
|
||||||
@ -117,9 +120,10 @@ func (this *Tree) analyzeMethodOrBehaviorInternal (
|
|||||||
case *entity.TypeNamed:
|
case *entity.TypeNamed:
|
||||||
ty := ty.(*entity.TypeNamed)
|
ty := ty.(*entity.TypeNamed)
|
||||||
typeKey := Key {
|
typeKey := Key {
|
||||||
Unit: this.unit,
|
Unit: ty.Unit,
|
||||||
Name: ty.Name,
|
Name: ty.Name,
|
||||||
}
|
}
|
||||||
|
println(typeKey.String())
|
||||||
if this.methodExists(this.methodKey(typeKey, name)) {
|
if this.methodExists(this.methodKey(typeKey, name)) {
|
||||||
method, err := this.analyzeMethod(pos, typeKey, name)
|
method, err := this.analyzeMethod(pos, typeKey, name)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
|
@ -90,11 +90,16 @@ func (this *Tree) analyzeTypeInternal (
|
|||||||
case *entity.TypeNamed:
|
case *entity.TypeNamed:
|
||||||
ty := ty.(*entity.TypeNamed)
|
ty := ty.(*entity.TypeNamed)
|
||||||
updateIncompleteInfo()
|
updateIncompleteInfo()
|
||||||
|
|
||||||
|
// resolve nickname of the unit where the typedef is
|
||||||
if primitive, isPrimitive := primitiveTypes[ty.Name]; isPrimitive {
|
if primitive, isPrimitive := primitiveTypes[ty.Name]; isPrimitive {
|
||||||
return primitive, nil
|
return primitive, nil
|
||||||
}
|
}
|
||||||
unit, err := this.resolveNickname(ty.Position, ty.UnitNickname)
|
unit, err := this.resolveNickname(ty.Position, ty.UnitNickname)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
|
ty.Unit = unit
|
||||||
|
|
||||||
|
// analyze the typedef
|
||||||
def, err := this.analyzeTypedef(ty.Position, Key {
|
def, err := this.analyzeTypedef(ty.Position, Key {
|
||||||
Unit: unit,
|
Unit: unit,
|
||||||
Name: ty.Name,
|
Name: ty.Name,
|
||||||
|
@ -105,9 +105,10 @@ type Method struct {
|
|||||||
Body Expression
|
Body Expression
|
||||||
|
|
||||||
// Semantics
|
// Semantics
|
||||||
Scope
|
Unit uuid.UUID
|
||||||
Type Type
|
Type Type
|
||||||
This *Declaration
|
This *Declaration
|
||||||
|
Scope
|
||||||
}
|
}
|
||||||
func (*Method) topLevel(){}
|
func (*Method) topLevel(){}
|
||||||
func (this *Method) String () string {
|
func (this *Method) String () string {
|
||||||
|
Loading…
Reference in New Issue
Block a user