redef fun after_typing(v)
do
- var va = new VarVariable(n_id.to_symbol, self)
+ var va = new VarVariable(n_id.to_symbol, n_id)
_variable = va
v.variable_ctx.add(va)
if n_expr != null then v.variable_ctx.mark_is_set(va)
end
end
+redef class ALoopExpr
+ # The corresponding escapable block
+ readable var _escapable: nullable EscapableBlock
+
+ redef fun accept_typing(v)
+ do
+ var escapable = new EscapableBlock(self)
+ _escapable = escapable
+ v.escapable_ctx.push(escapable, n_label)
+ var old_var_ctx = v.variable_ctx
+ var old_base_var_ctx = v.base_variable_ctx
+ v.base_variable_ctx = v.variable_ctx
+ v.variable_ctx = v.variable_ctx.sub(self)
+
+ # Process inside
+ if n_block != null then
+ v.variable_ctx = v.variable_ctx.sub(n_block.as(not null))
+ v.enter_visit(n_block)
+ end
+
+ v.variable_ctx = old_var_ctx
+ v.base_variable_ctx = old_base_var_ctx
+ v.escapable_ctx.pop
+ _is_typed = true
+ end
+end
+
redef class AForExpr
var _variable: nullable AutoVariable
redef fun variable do return _variable.as(not null)
var old_base_var_ctx = v.base_variable_ctx
v.base_variable_ctx = v.variable_ctx
v.variable_ctx = v.variable_ctx.sub(self)
- var va = new AutoVariable(n_id.to_symbol, self)
+ var va = new AutoVariable(n_id.to_symbol, n_id)
_variable = va
v.variable_ctx.add(va)
end
redef class AAssertExpr
- redef fun after_typing(v)
+ redef fun accept_typing(v)
do
+ # Process condition
+ v.enter_visit(n_expr)
v.check_conform_expr(n_expr, v.type_bool)
+
+ # Process optional 'else' part
+ if n_else != null then
+ var old_var_ctx = v.variable_ctx
+ v.use_if_false_variable_ctx(n_expr)
+ v.enter_visit(n_else)
+ v.variable_ctx = old_var_ctx
+ end
+
+ # Prepare outside
v.use_if_true_variable_ctx(n_expr)
_is_typed = true
end
redef fun after_typing(v)
do
v.variable_ctx.mark_is_set(variable)
- var t = v.variable_ctx.stype(variable)
# Check the base type
var btype = v.base_variable_ctx.stype(variable)
- if not v.check_conform_expr(n_value, btype) then return
+ if not v.check_expr(n_value) then return
+ if btype != null and not v.check_conform_expr(n_value, btype) then return
# Always cast
v.variable_ctx.stype(variable) = n_value.stype
# Check the base type
var btype = v.base_variable_ctx.stype(variable)
- if not v.check_conform(n_value, t2, btype) then return
+ if not v.check_expr(n_value) then return
+ if btype != null and not v.check_conform(n_value, t2, btype) then return
# Always cast
v.variable_ctx.stype(variable) = t2
print "{location} no compute_raw_arguments"
return null
end
- # The real arguments used (after star transformation) (once computed)
- redef fun arguments do return _arguments.as(not null)
- var _arguments: nullable Array[AExpr]
# Check the conformity of a set of arguments `raw_args' to a signature.
- private fun process_signature(v: TypingVisitor, psig: MMSignature, name: Symbol, raw_args: nullable Array[AExpr]): nullable Array[AExpr]
+ private fun process_signature(v: TypingVisitor, psig: MMSignature, name: Symbol, raw_args: nullable Array[AExpr]): Bool
do
var par_vararg = psig.vararg_rank
var par_arity = psig.arity
var raw_arity: Int
if raw_args == null then raw_arity = 0 else raw_arity = raw_args.length
if par_arity > raw_arity or (par_arity != raw_arity and par_vararg == -1) then
- v.error(self, "Error: '{name}' arity missmatch.")
- return null
+ v.error(self, "Error: arity missmatch; prototype is '{name}{psig}'.")
+ return false
end
var arg_idx = 0
- var args = new Array[AExpr]
for par_idx in [0..par_arity[ do
var a: AExpr
var par_type = psig[par_idx]
if par_idx == par_vararg then
- var star = new Array[AExpr]
for i in [0..(raw_arity-par_arity)] do
a = raw_args[arg_idx]
v.check_conform_expr(a, par_type)
- star.add(a)
arg_idx = arg_idx + 1
end
- var aa = new AArrayExpr.init_aarrayexpr(star)
- aa.do_typing(v, par_type)
- a = aa
else
a = raw_args[arg_idx]
v.check_conform_expr(a, par_type)
arg_idx = arg_idx + 1
end
- args.add(a)
end
- return args
+ return true
end
# Check the conformity of a set of defined closures
# Process each closure definition
for i in [0..arity[ do
- var csi = cs[i]
var cdi = cd[i]
- var esc = new EscapableClosure(cdi, csi, break_list)
- v.escapable_ctx.push(esc, n_label)
- cdi.accept_typing2(v, esc)
- v.escapable_ctx.pop
+ var cni = cdi.n_id.to_symbol
+ var csi = psig.closure_named(cni)
+ if csi != null then
+ var esc = new EscapableClosure(cdi, csi, break_list)
+ v.escapable_ctx.push(esc, n_label)
+ cdi.accept_typing2(v, esc)
+ v.escapable_ctx.pop
+ else if cs.length == 1 then
+ v.error(cdi.n_id, "Error: no closure named '!{cni}' in {name}; only closure is !{cs.first.name}.")
+ else
+ var a = new Array[String]
+ for c in cs do
+ a.add("!{c.name}")
+ end
+ v.error(cdi.n_id, "Error: no closure named '!{cni}' in {name}; only closures are {a.join(",")}.")
+ end
end
# Check break type conformity
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)
- var args = process_signature(v, sig, prop.name, raw_args)
- if args == null then return
+ if not process_signature(v, sig, prop.name, raw_args) then return
var rtype = process_closures(v, sig, prop.name, closure_defs)
if rtype == null and sig.return_type != null then return
_prop = prop
_prop_signature = sig
- _arguments = args
_return_type = rtype
end
_read_prop = prop
raw_args = raw_args.to_a
- var old_args = arguments
raw_args.add(n_value)
do_typing(v, n_expr.stype, n_expr.is_implicit_self, n_expr.is_self, "{name}=".to_symbol, raw_args, null)
end
end
- _arguments = old_args # FIXME: What if star parameters do not match betwen the two methods?
_is_typed = true
end
end
redef class ABraExpr
redef fun name do return once "[]".to_symbol
redef fun compute_raw_arguments do return n_args.to_a
+ redef fun closure_defs
+ do
+ if n_closure_defs.is_empty then
+ return null
+ else
+ return n_closure_defs.to_a
+ end
+ end
end
redef class ABraAssignExpr
var va = variable
if va.closure.is_break then v.variable_ctx.unreash = true
var sig = va.closure.signature
- var args = process_signature(v, sig, n_id.to_symbol, n_args.to_a)
+ var s = process_signature(v, sig, n_id.to_symbol, compute_raw_arguments)
if not n_closure_defs.is_empty then
process_closures(v, sig, n_id.to_symbol, n_closure_defs.to_a)
end
- if args == null then return
+ if not s then return
_prop_signature = sig
- _arguments = args
_stype = sig.return_type
_is_typed = true
end
end
+redef class AClosureId
+ fun to_symbol: Symbol is abstract
+end
+redef class ASimpleClosureId
+ redef fun to_symbol: Symbol do return n_id.to_symbol
+end
+redef class ABreakClosureId
+ redef fun to_symbol: Symbol do return n_kwbreak.to_symbol
+end
+
redef class AClosureDef
var _closure: nullable MMClosure
redef fun closure do return _closure.as(not null)
_escapable = esc
var sig = esc.closure.signature
- if sig.arity != n_id.length then
- v.error(self, "Error: {sig.arity} automatic variable names expected, {n_id.length} found.")
+ if sig.arity != n_ids.length then
+ v.error(self, "Error: {sig.arity} automatic variable names expected, {n_ids.length} found.")
return
end
v.base_variable_ctx = v.variable_ctx
v.variable_ctx = v.variable_ctx.sub(self)
variables = new Array[AutoVariable]
- for i in [0..n_id.length[ do
- var va = new AutoVariable(n_id[i].to_symbol, self)
+ for i in [0..n_ids.length[ do
+ var va = new AutoVariable(n_ids[i].to_symbol, n_ids[i])
variables.add(va)
va.stype = sig[i]
v.variable_ctx.add(va)