From: Jean Privat Date: Fri, 6 Feb 2009 15:26:27 +0000 (-0500) Subject: Finish syntax analysis for default closure. X-Git-Tag: mercurial_tip~3 X-Git-Url: http://nitlanguage.org Finish syntax analysis for default closure. --- diff --git a/src/syntax/control_flow.nit b/src/syntax/control_flow.nit index 11371ac..0903077 100644 --- a/src/syntax/control_flow.nit +++ b/src/syntax/control_flow.nit @@ -316,6 +316,30 @@ redef class AVarReassignExpr end end +redef class AClosureDecl + redef meth accept_control_flow(v) + do + if n_expr != null then + var old_control_flow_ctx = v.control_flow_ctx + v.control_flow_ctx = v.control_flow_ctx.sub + # Register the block + v.control_flow_ctx.base_block = n_expr + + super + + if v.control_flow_ctx.unreash == false then + if variable.closure.signature.return_type != null then + v.error(self, "Control error: Reached end of bloc (a 'continue' with a value was expected).") + else if variable.closure.is_break then + v.error(self, "Control error: Reached end of break bloc (an 'abort' was expected).") + end + end + + v.control_flow_ctx = old_control_flow_ctx + end + end +end + redef class AClosureDef special AControlableBlock redef meth accept_control_flow(v) diff --git a/src/syntax/typing.nit b/src/syntax/typing.nit index 5f49fba..04c1a62 100644 --- a/src/syntax/typing.nit +++ b/src/syntax/typing.nit @@ -298,9 +298,19 @@ redef class PParam end redef class AClosureDecl - redef meth after_typing(v) + redef meth accept_typing(v) do + # Register the closure for ClosureCallExpr v.variable_ctx.add(variable) + + var old_var_ctx = v.variable_ctx + v.variable_ctx = v.variable_ctx.sub + v.closure = variable.closure + + super + + v.variable_ctx = old_var_ctx + v.closure = null end end