ast: add new node AEscapeExpr to generalizes ABreakExpr and AContinueExpr
authorJean Privat <jean@pryen.org>
Sat, 11 Oct 2014 02:32:26 +0000 (22:32 -0400)
committerJean Privat <jean@pryen.org>
Sat, 11 Oct 2014 02:32:26 +0000 (22:32 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/frontend/simple_misc_analysis.nit
src/parser/parser_nodes.nit
src/semantize/flow.nit
src/semantize/scope.nit

index a50b45b..9e3775d 100644 (file)
@@ -117,17 +117,7 @@ redef class AReturnExpr
        end
 end
 
-redef class AContinueExpr
-       redef fun after_simple_misc(v)
-       do
-               var e = n_expr
-               if e != null then
-                       e.warn_parentheses(v)
-               end
-       end
-end
-
-redef class ABreakExpr
+redef class AEscapeExpr
        redef fun after_simple_misc(v)
        do
                var e = n_expr
index 5aba49d..a031c12 100644 (file)
@@ -1344,14 +1344,19 @@ abstract class ALabelable
        var n_label: nullable ALabel = null is writable
 end
 
-# A `break` statement.
-class ABreakExpr
+# A `break` or a `continue`
+abstract class AEscapeExpr
        super AExpr
        super ALabelable
-       var n_kwbreak: TKwbreak is writable, noinit
        var n_expr: nullable AExpr = null is writable
 end
 
+# A `break` statement.
+class ABreakExpr
+       super AEscapeExpr
+       var n_kwbreak: TKwbreak is writable, noinit
+end
+
 # An `abort` statement
 class AAbortExpr
        super AExpr
@@ -1360,10 +1365,8 @@ end
 
 # A `continue` statement
 class AContinueExpr
-       super AExpr
-       super ALabelable
+       super AEscapeExpr
        var n_kwcontinue: nullable TKwcontinue = null is writable
-       var n_expr: nullable AExpr = null is writable
 end
 
 # A `do` statement
index ccc36b7..65f5c7b 100644 (file)
@@ -319,22 +319,7 @@ redef class AReturnExpr
        end
 end
 
-redef class AContinueExpr
-       # The flow just before it become unreachable
-       fun before_flow_context: nullable FlowContext
-       do
-               var after = self.after_flow_context
-               if after == null then return null
-               return after.previous.first
-       end
-       redef fun accept_flow_visitor(v)
-       do
-               super
-               v.make_unreachable_flow
-       end
-end
-
-redef class ABreakExpr
+redef class AEscapeExpr
        # The flow just before it become unreachable
        fun before_flow_context: nullable FlowContext
        do
index 3039745..30aade4 100644 (file)
@@ -292,9 +292,12 @@ redef class ASelfExpr
        end
 end
 
-redef class AContinueExpr
-       # The escape mark associated with the continue
+redef class AEscapeExpr
+       # The escape mark associated with the break/continue
        var escapemark: nullable EscapeMark
+end
+
+redef class AContinueExpr
        redef fun accept_scope_visitor(v)
        do
                super
@@ -309,8 +312,6 @@ redef class AContinueExpr
 end
 
 redef class ABreakExpr
-       # The escape mark associated with the break
-       var escapemark: nullable EscapeMark
        redef fun accept_scope_visitor(v)
        do
                super