# Is a other constructor of the same class invoked
readable writable attr _explicit_other_init_call: Bool
+ # Make the if_true_variable_ctx of the expression effective
+ private meth use_if_true_variable_ctx(e: PExpr)
+ do
+ var ctx = e.if_true_variable_ctx
+ if ctx != null then
+ variable_ctx = ctx
+ end
+ end
+
init(tc, module) do super
private meth get_default_constructor_for(n: PNode, c: MMLocalClass, prop: MMSrcMethod): MMMethod
# Build a new VariableContext
meth sub: SubVariableContext
do
- return new SubVariableContext.with_prev(self, null, null)
+ return new SubVariableContext.with_prev(self)
end
# Build a nested VariableContext with new variable information
meth sub_with(v: Variable, t: MMType): SubVariableContext
do
- return new SubVariableContext.with_prev(self, v, t)
+ return new CastVariableContext.with_prev(self, v, t)
end
init
private class SubVariableContext
special VariableContext
readable attr _prev: VariableContext
- attr _variable: Variable
- attr _var_type: MMType
redef meth [](s)
do
redef meth stype(v)
do
+ return prev.stype(v)
+ end
+
+ init with_prev(p: VariableContext)
+ do
+ init
+ _prev = p
+ end
+end
+
+private class CastVariableContext
+special SubVariableContext
+ attr _variable: Variable
+ attr _var_type: MMType
+
+ redef meth stype(v)
+ do
if _variable == v then
return _var_type
end
init with_prev(p: VariableContext, v: Variable, t: MMType)
do
- init
- _prev = p
+ super(p)
_variable = v
_var_type =t
end
v.visit(n_expr)
v.check_conform_expr(n_expr, v.type_bool)
- if n_expr.if_true_variable_ctx != null then
- v.variable_ctx = n_expr.if_true_variable_ctx
- end
+ v.use_if_true_variable_ctx(n_expr)
v.visit(n_then)
# Restore variable ctx
redef meth after_typing(v)
do
v.check_conform_expr(n_expr, v.type_bool)
- if n_expr.if_true_variable_ctx != null then v.variable_ctx = n_expr.if_true_variable_ctx
+ v.use_if_true_variable_ctx(n_expr)
end
end
return
end
var name = n_assign_op.method_name
- var prop = type_lvalue.local_class.select_method(name)
- if prop == null then
+ var lc = type_lvalue.local_class
+ if not lc.has_global_property_by_name(name) then
v.error(self, "Error: Method '{name}' doesn't exists in {type_lvalue}.")
return
end
+ var prop = lc.select_method(name)
prop.global.check_visibility(v, self, v.module, false)
var psig = prop.signature_for(type_lvalue)
_assign_method = prop
var old_var_ctx = v.variable_ctx
v.visit(n_expr)
- if n_expr.if_true_variable_ctx != null then v.variable_ctx = n_expr.if_true_variable_ctx
+ v.use_if_true_variable_ctx(n_expr)
v.visit(n_then)
v.variable_ctx = old_var_ctx
v.visit(n_else)
v.check_conform_expr(n_expr, v.type_bool)
- if not v.check_expr(n_then) or not v.check_expr(n_else) then return
-
- var t = n_then.stype
- var te = n_else.stype
- if t < te then
- t = te
- else if not te < t then
- v.error(self, "Type error: {te} is not a subtype of {t}.")
- return
- end
-
- _stype = t
+ _stype = v.check_conform_multiexpr(null, [n_then, n_else])
end
end
var old_var_ctx = v.variable_ctx
v.visit(n_expr)
- if n_expr.if_true_variable_ctx != null then v.variable_ctx = n_expr.if_true_variable_ctx
+ v.use_if_true_variable_ctx(n_expr)
v.visit(n_expr2)
if n_expr2.if_true_variable_ctx != null then
redef meth after_typing(v)
do
- var stype: MMType = null
- for n in n_exprs do
- var ntype = n.stype
- if stype == null or (ntype != null and stype < ntype) then
- stype = ntype
- end
- end
- for n in n_exprs do
- v.check_conform_expr(n, stype)
- end
+ var stype = v.check_conform_multiexpr(null, n_exprs)
+ if stype == null then return
do_typing(v, stype)
end
if not v.check_expr(n_expr) then return
var type_recv = n_expr.stype
var name = n_id.to_symbol
- var prop = type_recv.local_class.select_attribute(name)
- if prop == null then
+ var lc = type_recv.local_class
+ if not lc.has_global_property_by_name(name) then
v.error(self, "Error: Attribute {name} doesn't exists in {type_recv}.")
return
- else if v.module.visibility_for(prop.global.local_class.module) < 3 then
+ end
+ var prop = lc.select_attribute(name)
+ if v.module.visibility_for(prop.global.local_class.module) < 3 then
v.error(self, "Error: Attribute {name} from {prop.global.local_class.module} is invisible in {v.module}")
end
_prop = prop
end
end
-class AAbsSendExpr
+class AAbsAbsSendExpr
special PExpr
# The signature of the called property
readable attr _prop_signature: MMSignature
- # Compute the called global property
- private meth do_typing(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, recv_is_self: Bool, name: Symbol, raw_args: Array[PExpr], closure_defs: Array[PClosureDef])
- do
- var prop = get_property(v, type_recv, is_implicit_self, name)
- if prop == null then return
- var sig = get_signature(v, type_recv, prop, recv_is_self)
- if sig == null then return
- var args = process_signature(v, sig, prop.name, raw_args)
- if args == null then return
- var rtype = process_closures(v, sig, prop.name, closure_defs)
- _prop = prop
- _prop_signature = sig
- _arguments = args
- _return_type = rtype
- end
-
- private meth get_property(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, name: Symbol): MMMethod
- do
- if type_recv == null then return null
- var prop = type_recv.local_class.select_method(name)
- if prop == null and v.local_property.global.is_init then
- var props = type_recv.local_class.super_methods_named(name)
- if props.length > 1 then
- v.error(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
- return null
- else if props.length == 1 then
- var p = type_recv.local_class[props.first.global]
- assert p isa MMMethod
- prop = p
- end
-
- end
- if prop == null then
- if is_implicit_self then
- v.error(self, "Error: Method or variable '{name}' unknown in {type_recv}.")
- else
- v.error(self, "Error: Method '{name}' doesn't exists in {type_recv}.")
- end
- return null
- end
- return prop
- end
-
- # Get the signature for a local property and a receiver
- private meth get_signature(v: TypingVisitor, type_recv: MMType, prop: MMMethod, recv_is_self: Bool): MMSignature
- do
- prop.global.check_visibility(v, self, v.module, recv_is_self)
- var psig = prop.signature_for(type_recv)
- if not recv_is_self then psig = psig.not_for_self
- return psig
- end
+ # The real arguments used (after star transformation) (once computed)
+ readable attr _arguments: Array[PExpr]
# Check the conformity of a set of arguments `raw_args' to a signature.
private meth process_signature(v: TypingVisitor, psig: MMSignature, name: Symbol, raw_args: Array[PExpr]): Array[PExpr]
# Check break type conformity
if break_list != null then
- for n in break_list do
- var ntype = n.stype
- if t == null or (t != null and t < ntype) then
- t = ntype
- end
- end
- for n in break_list do
- v.check_conform_expr(n, t)
- end
+ t = v.check_conform_multiexpr(t, break_list)
end
end
else if min_arity != 0 then
end
return t
end
+end
+
+class AAbsSendExpr
+special AAbsAbsSendExpr
+ # Compute the called global property
+ private meth do_typing(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, recv_is_self: Bool, name: Symbol, raw_args: Array[PExpr], closure_defs: Array[PClosureDef])
+ do
+ var prop = get_property(v, type_recv, is_implicit_self, name)
+ if prop == null then return
+ var sig = get_signature(v, type_recv, prop, recv_is_self)
+ if sig == null then return
+ var args = process_signature(v, sig, prop.name, raw_args)
+ if args == null then return
+ var rtype = process_closures(v, sig, prop.name, closure_defs)
+ _prop = prop
+ _prop_signature = sig
+ _arguments = args
+ _return_type = rtype
+ end
+
+ private meth get_property(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, name: Symbol): MMMethod
+ do
+ if type_recv == null then return null
+ var lc = type_recv.local_class
+ var prop: MMMethod = null
+ if lc.has_global_property_by_name(name) then prop = lc.select_method(name)
+ if prop == null and v.local_property.global.is_init then
+ var props = type_recv.local_class.super_methods_named(name)
+ if props.length > 1 then
+ v.error(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
+ return null
+ else if props.length == 1 then
+ var p = type_recv.local_class[props.first.global]
+ assert p isa MMMethod
+ prop = p
+ end
+
+ end
+ if prop == null then
+ if is_implicit_self then
+ v.error(self, "Error: Method or variable '{name}' unknown in {type_recv}.")
+ else
+ v.error(self, "Error: Method '{name}' doesn't exists in {type_recv}.")
+ end
+ return null
+ end
+ return prop
+ end
+
+ # Get the signature for a local property and a receiver
+ private meth get_signature(v: TypingVisitor, type_recv: MMType, prop: MMMethod, recv_is_self: Bool): MMSignature
+ do
+ prop.global.check_visibility(v, self, v.module, recv_is_self)
+ var psig = prop.signature_for(type_recv)
+ if not recv_is_self then psig = psig.not_for_self
+ return psig
+ end
# The invoked method (once computed)
readable attr _prop: MMMethod
- # The real arguments used (after star transformation) (once computed)
- readable attr _arguments: Array[PExpr]
-
# The return type (if any) (once computed)
readable attr _return_type: MMType
end