From 2d5fa2be078a32b2abefefbf26306ff0a881d50f Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 6 Oct 2015 21:33:10 -0400 Subject: [PATCH] frontend: handle multi-iterators Signed-off-by: Jean Privat --- src/frontend/simple_misc_analysis.nit | 8 +++++++- src/rapid_type_analysis.nit | 2 +- src/semantize/flow.nit | 4 +++- src/semantize/scope.nit | 28 +++++++++++++++++----------- src/semantize/typing.nit | 32 ++++++++++++++++++-------------- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/frontend/simple_misc_analysis.nit b/src/frontend/simple_misc_analysis.nit index f61b10a..4934e1a 100644 --- a/src/frontend/simple_misc_analysis.nit +++ b/src/frontend/simple_misc_analysis.nit @@ -172,11 +172,17 @@ end redef class AForExpr redef fun after_simple_misc(v) do - n_expr.warn_parentheses(v) v.check_do_expr(n_block) end end +redef class AForGroup + redef fun after_simple_misc(v) + do + n_expr.warn_parentheses(v) + end +end + redef class AWithExpr redef fun after_simple_misc(v) do diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index bcdb6db..a87a48f 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -699,7 +699,7 @@ redef class ASuperExpr end end -redef class AForExpr +redef class AForGroup redef fun accept_rapid_type_visitor(v) do v.add_callsite(self.method_iterator) diff --git a/src/semantize/flow.nit b/src/semantize/flow.nit index b0e833a..adcb8ee 100644 --- a/src/semantize/flow.nit +++ b/src/semantize/flow.nit @@ -423,7 +423,9 @@ end redef class AForExpr redef fun accept_flow_visitor(v) do - v.enter_visit(self.n_expr) + for g in n_groups do + v.enter_visit(g.n_expr) + end var before_loop = v.make_sub_flow diff --git a/src/semantize/scope.nit b/src/semantize/scope.nit index fa10118..e595b1c 100644 --- a/src/semantize/scope.nit +++ b/src/semantize/scope.nit @@ -377,9 +377,6 @@ redef class ALoopExpr end redef class AForExpr - # The automatic variables in order - var variables: nullable Array[Variable] - # The break escape mark associated with the 'for' var break_mark: nullable EscapeMark @@ -388,18 +385,22 @@ redef class AForExpr redef fun accept_scope_visitor(v) do - v.enter_visit(n_expr) + for g in n_groups do + v.enter_visit(g.n_expr) + end # Protect automatic variables v.scopes.unshift(new Scope) - # Create the automatic variables - var variables = new Array[Variable] - self.variables = variables - for nid in n_ids do - var va = new Variable(nid.text) - v.register_variable(nid, va) - variables.add(va) + for g in n_groups do + # Create the automatic variables + var variables = new Array[Variable] + g.variables = variables + for nid in g.n_ids do + var va = new Variable(nid.text) + v.register_variable(nid, va) + variables.add(va) + end end var escapemark = v.make_escape_mark(n_label, true) @@ -411,6 +412,11 @@ redef class AForExpr end end +redef class AForGroup + # The automatic variables in order + var variables: nullable Array[Variable] +end + redef class AWithExpr # The break escape mark associated with the 'with' var break_mark: nullable EscapeMark diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 935e1fc..11b7078 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1120,6 +1120,24 @@ redef class ALoopExpr end redef class AForExpr + redef fun accept_typing(v) + do + v.has_loop = true + + for g in n_groups do + var mtype = v.visit_expr(g.n_expr) + if mtype == null then return + g.do_type_iterator(v, mtype) + end + + v.visit_stmt(n_block) + + self.mtype = n_block.mtype + self.is_typed = true + end +end + +redef class AForGroup var coltype: nullable MClassType var method_iterator: nullable CallSite @@ -1246,20 +1264,6 @@ redef class AForExpr self.method_successor = v.get_method(self, vtype, "successor", false) end end - - redef fun accept_typing(v) - do - v.has_loop = true - var mtype = v.visit_expr(n_expr) - if mtype == null then return - - self.do_type_iterator(v, mtype) - - v.visit_stmt(n_block) - - self.mtype = n_block.mtype - self.is_typed = true - end end redef class AWithExpr -- 1.7.9.5