]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix error handling in condition of while, do, and for statements
authorJürg Billeter <j@bitron.ch>
Sun, 30 Nov 2008 12:50:43 +0000 (12:50 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 30 Nov 2008 12:50:43 +0000 (12:50 +0000)
2008-11-30  Jürg Billeter  <j@bitron.ch>

* vala/valaaddressofexpression.vala:
* vala/valaarraycreationexpression.vala:
* vala/valaassignment.vala:
* vala/valabaseaccess.vala:
* vala/valabinaryexpression.vala:
* vala/valablock.vala:
* vala/valacastexpression.vala:
* vala/valaconditionalexpression.vala:
* vala/valadostatement.vala:
* vala/valaelementaccess.vala:
* vala/valaexpression.vala:
* vala/valaforstatement.vala:
* vala/valainitializerlist.vala:
* vala/valalambdaexpression.vala:
* vala/valaliteral.vala:
* vala/valamemberaccess.vala:
* vala/valamethodcall.vala:
* vala/valaobjectcreationexpression.vala:
* vala/valaparenthesizedexpression.vala:
* vala/valapointerindirection.vala:
* vala/valapostfixexpression.vala:
* vala/valareferencetransferexpression.vala:
* vala/valasemanticanalyzer.vala:
* vala/valasizeofexpression.vala:
* vala/valaswitchsection.vala:
* vala/valatuple.vala:
* vala/valatypecheck.vala:
* vala/valatypeofexpression.vala:
* vala/valaunaryexpression.vala:
* vala/valawhilestatement.vala:
* gobject/valaccodebasemodule.vala:

Fix error handling in condition of while, do, and for statements

svn path=/trunk/; revision=2096

32 files changed:
ChangeLog
gobject/valaccodebasemodule.vala
vala/valaaddressofexpression.vala
vala/valaarraycreationexpression.vala
vala/valaassignment.vala
vala/valabaseaccess.vala
vala/valabinaryexpression.vala
vala/valablock.vala
vala/valacastexpression.vala
vala/valaconditionalexpression.vala
vala/valadostatement.vala
vala/valaelementaccess.vala
vala/valaexpression.vala
vala/valaforstatement.vala
vala/valainitializerlist.vala
vala/valalambdaexpression.vala
vala/valaliteral.vala
vala/valamemberaccess.vala
vala/valamethodcall.vala
vala/valaobjectcreationexpression.vala
vala/valaparenthesizedexpression.vala
vala/valapointerindirection.vala
vala/valapostfixexpression.vala
vala/valareferencetransferexpression.vala
vala/valasemanticanalyzer.vala
vala/valasizeofexpression.vala
vala/valaswitchsection.vala
vala/valatuple.vala
vala/valatypecheck.vala
vala/valatypeofexpression.vala
vala/valaunaryexpression.vala
vala/valawhilestatement.vala

index c42bac415649d990561494c13f57ad7d8908119e..41e191b1bcd8f0494ab4f87800661ffd217cc2be 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2008-11-30  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaaddressofexpression.vala:
+       * vala/valaarraycreationexpression.vala:
+       * vala/valaassignment.vala:
+       * vala/valabaseaccess.vala:
+       * vala/valabinaryexpression.vala:
+       * vala/valablock.vala:
+       * vala/valacastexpression.vala:
+       * vala/valaconditionalexpression.vala:
+       * vala/valadostatement.vala:
+       * vala/valaelementaccess.vala:
+       * vala/valaexpression.vala:
+       * vala/valaforstatement.vala:
+       * vala/valainitializerlist.vala:
+       * vala/valalambdaexpression.vala:
+       * vala/valaliteral.vala:
+       * vala/valamemberaccess.vala:
+       * vala/valamethodcall.vala:
+       * vala/valaobjectcreationexpression.vala:
+       * vala/valaparenthesizedexpression.vala:
+       * vala/valapointerindirection.vala:
+       * vala/valapostfixexpression.vala:
+       * vala/valareferencetransferexpression.vala:
+       * vala/valasemanticanalyzer.vala:
+       * vala/valasizeofexpression.vala:
+       * vala/valaswitchsection.vala:
+       * vala/valatuple.vala:
+       * vala/valatypecheck.vala:
+       * vala/valatypeofexpression.vala:
+       * vala/valaunaryexpression.vala:
+       * vala/valawhilestatement.vala:
+       * gobject/valaccodebasemodule.vala:
+
+       Fix error handling in condition of while, do, and for statements
+
 2008-11-30  Jürg Billeter  <j@bitron.ch>
 
        * vala/valaexpressionstatement.vala:
index 9157028e3404ab1c45ea4d9cdb7bce30e87cf68b..d8295c4e9eb7a21756bf4ec11e9cb5a5ce812424 100644 (file)
@@ -1207,6 +1207,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
        }
 
        public override void visit_block (Block b) {
+               var old_symbol = current_symbol;
                current_symbol = b;
 
                b.accept_children (codegen);
@@ -1258,7 +1259,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
 
                b.ccodenode = cblock;
 
-               current_symbol = current_symbol.parent_symbol;
+               current_symbol = old_symbol;
        }
 
        public override void visit_empty_statement (EmptyStatement stmt) {
index be21b9572011b9b7454da58e3d18e89713b3fc6f..4874a2b0a89dcb3c58fff0de2e8d4a494ee45493 100644 (file)
@@ -97,8 +97,4 @@ public class Vala.AddressofExpression : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return inner.in_single_basic_block ();
-       }
 }
index 8e2f891d7d57bc9df14b105bcf41e79a4f22e181..9ef841c549c37623d47f8d1c9a26a564d47bbf58 100644 (file)
@@ -220,13 +220,4 @@ public class Vala.ArrayCreationExpression : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               foreach (Expression size in sizes) {
-                       if (!size.in_single_basic_block ()) {
-                               return false;
-                       }
-               }
-               return true;
-       }
 }
index 026040b30b0a9363dd35437da0f20c5a1bb5dca9..d3ad077f70412b4c7ab6037f633349ef94a12373 100644 (file)
@@ -400,10 +400,6 @@ public class Vala.Assignment : Expression {
                }
                right.get_used_variables (collection);
        }
-
-       public override bool in_single_basic_block () {
-               return left.in_single_basic_block () && right.in_single_basic_block ();
-       }
 }
        
 public enum Vala.AssignmentOperator {
index 7db98c878b930bbee82eaeecaff49406ba24942e..1de0c7a7849928383edc627f8717d9e6644bdfda 100644 (file)
@@ -88,8 +88,4 @@ public class Vala.BaseAccess : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return true;
-       }
 }
index 3eb02fd41eb529dee526797789aeb4e4d1a67e45..64ff3c796600546cae9ba6ee9759150b13cf2b42 100644 (file)
@@ -148,6 +148,9 @@ public class Vala.BinaryExpression : Expression {
                checked = true;
 
                if (operator == BinaryOperator.AND || operator == BinaryOperator.OR) {
+                       var old_insert_block = analyzer.insert_block;
+                       analyzer.insert_block = prepare_condition_split (analyzer);
+
                        // convert conditional expression into if statement
                        // required for flow analysis and exception handling
 
@@ -172,12 +175,13 @@ public class Vala.BinaryExpression : Expression {
 
                        var if_stmt = new IfStatement (left, true_block, false_block, source_reference);
 
-                       insert_statement ((Block) analyzer.current_symbol, decl);
-                       insert_statement ((Block) analyzer.current_symbol, if_stmt);
+                       insert_statement (analyzer.insert_block, decl);
+                       insert_statement (analyzer.insert_block, if_stmt);
 
                        if (!if_stmt.check (analyzer)) {
                                return false;
                        }
+                       analyzer.insert_block = old_insert_block;
 
                        var ma = new MemberAccess.simple (local.name, source_reference);
                        ma.target_type = target_type;
@@ -350,14 +354,6 @@ public class Vala.BinaryExpression : Expression {
                left.get_used_variables (collection);
                right.get_used_variables (collection);
        }
-
-       public override bool in_single_basic_block () {
-               if (operator == BinaryOperator.AND
-                   || operator == BinaryOperator.OR) {
-                       return false;
-               }
-               return left.in_single_basic_block () && right.in_single_basic_block ();
-       }
 }
 
 public enum Vala.BinaryOperator {
index 8eb3516c0be7f41186a267ceb6db03d591ed48a4..70fbc73034183502b11231de7b542a5bea7844d6 100644 (file)
@@ -120,7 +120,9 @@ public class Vala.Block : Symbol, Statement {
                owner = analyzer.current_symbol.scope;
 
                var old_symbol = analyzer.current_symbol;
+               var old_insert_block = analyzer.insert_block;
                analyzer.current_symbol = this;
+               analyzer.insert_block = this;
 
                for (int i = 0; i < statement_list.size; i++) {
                        statement_list[i].check (analyzer);
@@ -135,6 +137,7 @@ public class Vala.Block : Symbol, Statement {
                }
 
                analyzer.current_symbol = old_symbol;
+               analyzer.insert_block = old_insert_block;
 
                return !error;
        }
index 598b5a28db344ac49bc283f4a4bb47fdf01e9c4b..4f94832ce54ef6dd59f3e0e7dda7e78e2bf8bc47 100644 (file)
@@ -131,8 +131,4 @@ public class Vala.CastExpression : Expression {
        public override void get_used_variables (Collection<LocalVariable> collection) {
                inner.get_used_variables (collection);
        }
-
-       public override bool in_single_basic_block () {
-               return inner.in_single_basic_block ();
-       }
 }
index ff798a6a03fe8fbbee9fb6b8a3b58da85b87db57..2d002b68b5d4c332bf49482c112e7d7c742f3f32 100644 (file)
@@ -105,6 +105,9 @@ public class Vala.ConditionalExpression : Expression {
 
                checked = true;
 
+               var old_insert_block = analyzer.insert_block;
+               analyzer.insert_block = prepare_condition_split (analyzer);
+
                // convert ternary expression into if statement
                // required for flow analysis and exception handling
 
@@ -128,12 +131,13 @@ public class Vala.ConditionalExpression : Expression {
 
                var if_stmt = new IfStatement (condition, true_block, false_block, source_reference);
 
-               insert_statement ((Block) analyzer.current_symbol, decl);
-               insert_statement ((Block) analyzer.current_symbol, if_stmt);
+               insert_statement (analyzer.insert_block, decl);
+               insert_statement (analyzer.insert_block, if_stmt);
 
                if (!if_stmt.check (analyzer)) {
                        return false;
                }
+               analyzer.insert_block = old_insert_block;
 
                true_expression = true_local.initializer;
                false_expression = false_local.initializer;
@@ -176,8 +180,4 @@ public class Vala.ConditionalExpression : Expression {
 
                return true;
        }
-
-       public override bool in_single_basic_block () {
-               return false;
-       }
 }
index 443aca541624094836b92cee83f83e8219014a74..c994cb148e083be419b78588a8a29ec0cbff512d 100644 (file)
@@ -54,7 +54,7 @@ public class Vala.DoStatement : CodeNode, Statement {
 
        private Expression _condition;
        private Block _body;
-       
+
        /**
         * Creates a new do statement.
         *
@@ -94,45 +94,6 @@ public class Vala.DoStatement : CodeNode, Statement {
 
                checked = true;
 
-               if (!condition.in_single_basic_block ()) {
-                       /* move condition into the loop body to allow split
-                        * in multiple statements
-                        *
-                        * first = false;
-                        * do {
-                        *     if (first) {
-                        *         if (!condition) {
-                        *             break;
-                        *         }
-                        *     }
-                        *     first = true;
-                        *     ...
-                        * } while (true);
-                        */
-
-                       var first_local = new LocalVariable (new ValueType (analyzer.bool_type.data_type), get_temp_name (), new BooleanLiteral (false, source_reference), source_reference);
-                       var first_decl = new DeclarationStatement (first_local, source_reference);
-                       first_decl.check (analyzer);
-                       var block = (Block) analyzer.current_symbol;
-                       block.insert_before (this, first_decl);
-
-                       var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
-                       var true_block = new Block (condition.source_reference);
-                       true_block.add_statement (new BreakStatement (condition.source_reference));
-                       var if_stmt = new IfStatement (if_condition, true_block, null, condition.source_reference);
-
-                       var condition_block = new Block (condition.source_reference);
-                       condition_block.add_statement (if_stmt);
-
-                       var first_if = new IfStatement (new MemberAccess.simple (first_local.name, source_reference), condition_block, null, source_reference);
-                       body.insert_statement (0, first_if);
-                       body.insert_statement (1, new ExpressionStatement (new Assignment (new MemberAccess.simple (first_local.name, source_reference), new BooleanLiteral (true, source_reference), AssignmentOperator.SIMPLE, source_reference), source_reference));
-
-                       condition = new BooleanLiteral (true, source_reference);
-               }
-
-               body.check (analyzer);
-
                if (!condition.check (analyzer)) {
                        /* if there was an error in the condition, skip this check */
                        error = true;
@@ -145,9 +106,51 @@ public class Vala.DoStatement : CodeNode, Statement {
                        return false;
                }
 
+               body.check (analyzer);
+
                add_error_types (condition.get_error_types ());
                add_error_types (body.get_error_types ());
 
                return !error;
        }
+
+       public Block prepare_condition_split (SemanticAnalyzer analyzer) {
+               /* move condition into the loop body to allow split
+                * in multiple statements
+                *
+                * first = false;
+                * do {
+                *     if (first) {
+                *         if (!condition) {
+                *             break;
+                *         }
+                *     }
+                *     first = true;
+                *     ...
+                * } while (true);
+                */
+
+               var first_local = new LocalVariable (new ValueType (analyzer.bool_type.data_type), get_temp_name (), new BooleanLiteral (false, source_reference), source_reference);
+               var first_decl = new DeclarationStatement (first_local, source_reference);
+               first_decl.check (analyzer);
+               var block = (Block) analyzer.current_symbol;
+               block.insert_before (this, first_decl);
+
+               var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
+               var true_block = new Block (condition.source_reference);
+               true_block.add_statement (new BreakStatement (condition.source_reference));
+               var if_stmt = new IfStatement (if_condition, true_block, null, condition.source_reference);
+
+               var condition_block = new Block (condition.source_reference);
+               condition_block.add_statement (if_stmt);
+
+               var first_if = new IfStatement (new MemberAccess.simple (first_local.name, source_reference), condition_block, null, source_reference);
+               body.insert_statement (0, first_if);
+               body.insert_statement (1, new ExpressionStatement (new Assignment (new MemberAccess.simple (first_local.name, source_reference), new BooleanLiteral (true, source_reference), AssignmentOperator.SIMPLE, source_reference), source_reference));
+
+               condition = new BooleanLiteral (true, source_reference);
+               condition.check (analyzer);
+
+               return condition_block;
+       }
 }
index e6b4dc8b2119c14ef4b4928d1babe69755d29f59..8475187637f8769b865a1d2e8173159855190c25 100644 (file)
@@ -222,13 +222,4 @@ public class Vala.ElementAccess : Expression {
                        index.get_used_variables (collection);
                }
        }
-
-       public override bool in_single_basic_block () {
-               foreach (Expression index in indices) {
-                       if (!index.in_single_basic_block ()) {
-                               return false;
-                       }
-               }
-               return container.in_single_basic_block ();
-       }
 }
index 47fb7cdac145aa2226362f53446f4df7e2c95c6b..95fd844a31411a38e8dea1df4c455069dd6f8a75 100644 (file)
@@ -102,13 +102,23 @@ public abstract class Vala.Expression : CodeNode {
                }
        }
 
+       public Block prepare_condition_split (SemanticAnalyzer analyzer) {
+               var while_stmt = parent_statement as WhileStatement;
+               var do_stmt = parent_statement as DoStatement;
+               var for_stmt = parent_statement as ForStatement;
+
+               if (while_stmt != null) {
+                       return while_stmt.prepare_condition_split (analyzer);
+               } else if (do_stmt != null) {
+                       return do_stmt.prepare_condition_split (analyzer);
+               } else if (for_stmt != null) {
+                       return for_stmt.prepare_condition_split (analyzer);
+               }
+
+               return analyzer.insert_block;
+       }
+
        public void insert_statement (Block block, Statement stmt) {
                block.insert_before (parent_statement, stmt);
        }
-
-       /**
-        * Returns whether this expression is guaranteed to be part of a
-        * single basic block in the control flow graph.
-        */
-       public abstract bool in_single_basic_block ();
 }
index ebd8de526747296ab09521d534e83e1e121f2f0e..bdc048a52791b84690e2b28ec27f17fc9aef3199 100644 (file)
@@ -164,20 +164,6 @@ public class Vala.ForStatement : CodeNode, Statement {
 
                checked = true;
 
-
-               if (condition != null && !condition.in_single_basic_block ()) {
-                       // move condition into the loop body to allow split
-                       // in multiple statements
-
-                       var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
-                       var true_block = new Block (condition.source_reference);
-                       true_block.add_statement (new BreakStatement (condition.source_reference));
-                       var if_stmt = new IfStatement (if_condition, true_block, null, condition.source_reference);
-                       body.insert_statement (0, if_stmt);
-
-                       condition = new BooleanLiteral (true, source_reference);
-               }
-
                foreach (Expression init_expr in initializer) {
                        init_expr.check (analyzer);
                }
@@ -218,4 +204,20 @@ public class Vala.ForStatement : CodeNode, Statement {
 
                return !error;
        }
+
+       public Block prepare_condition_split (SemanticAnalyzer analyzer) {
+               // move condition into the loop body to allow split
+               // in multiple statements
+
+               var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
+               var true_block = new Block (condition.source_reference);
+               true_block.add_statement (new BreakStatement (condition.source_reference));
+               var if_stmt = new IfStatement (if_condition, true_block, null, condition.source_reference);
+               body.insert_statement (0, if_stmt);
+
+               condition = new BooleanLiteral (true, source_reference);
+               condition.check (analyzer);
+
+               return body;
+       }
 }
index 5284d08bcc6d8aa4f1d00c6c15e2541b0629518a..4b10f160734e58fc111003bb6727cd4e086396a0 100644 (file)
@@ -170,13 +170,4 @@ public class Vala.InitializerList : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               foreach (Expression initializer in initializers) {
-                       if (!initializer.in_single_basic_block ()) {
-                               return false;
-                       }
-               }
-               return true;
-       }
 }
index 20a7fbef9706df1bd0071a7d0953e05aa4fe901e..52415a91591d209e88fb3408d4106b821d405f19 100644 (file)
@@ -203,8 +203,4 @@ public class Vala.LambdaExpression : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return true;
-       }
 }
index 932f0f58c0453f2479d23ce4e4b7787c668f718f..62f17a3af5aee0c9080b70afe21fbec6f57f677f 100644 (file)
@@ -33,8 +33,4 @@ public abstract class Vala.Literal : Expression {
        public override bool is_pure () {
                return true;
        }
-
-       public override bool in_single_basic_block () {
-               return true;
-       }
 }
index 2c59a6eb749454fa1923ac27b02928c2f80c1219..031d66f6f383fafc3ddb77a2726b6b73cafd342a 100644 (file)
@@ -551,8 +551,4 @@ public class Vala.MemberAccess : Expression {
                        collection.add (local);
                }
        }
-
-       public override bool in_single_basic_block () {
-               return inner == null || inner.in_single_basic_block ();
-       }
 }
index 3f8b773bef8a98f898402dc9bf8959d271a4f668..d7a3685d070587160f3cecdd0d35184d59fa2a59 100644 (file)
@@ -412,13 +412,16 @@ public class Vala.MethodCall : Expression {
                        if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
                                // simple statements, no side effects after method call
                        } else {
+                               var old_insert_block = analyzer.insert_block;
+                               analyzer.insert_block = prepare_condition_split (analyzer);
+
                                // store parent_node as we need to replace the expression in the old parent node later on
                                var old_parent_node = parent_node;
 
                                var local = new LocalVariable (value_type, get_temp_name (), null, source_reference);
                                var decl = new DeclarationStatement (local, source_reference);
 
-                               insert_statement ((Block) analyzer.current_symbol, decl);
+                               insert_statement (analyzer.insert_block, decl);
 
                                var temp_access = new MemberAccess.simple (local.name, source_reference);
                                temp_access.target_type = target_type;
@@ -428,6 +431,8 @@ public class Vala.MethodCall : Expression {
                                decl.check (analyzer);
                                temp_access.check (analyzer);
 
+                               analyzer.insert_block = old_insert_block;
+
                                old_parent_node.replace_expression (this, temp_access);
                        }
                }
@@ -450,13 +455,4 @@ public class Vala.MethodCall : Expression {
                        arg.get_used_variables (collection);
                }
        }
-
-       public override bool in_single_basic_block () {
-               foreach (Expression arg in argument_list) {
-                       if (!arg.in_single_basic_block ()) {
-                               return false;
-                       }
-               }
-               return call.in_single_basic_block ();
-       }
 }
index 5d64b05f81c4cf02926b9fea94472acc543ecce1..9fc43fd10ab4556f113eb40786fdafd85b70b3f8 100644 (file)
@@ -372,13 +372,4 @@ public class Vala.ObjectCreationExpression : Expression {
                        arg.get_used_variables (collection);
                }
        }
-
-       public override bool in_single_basic_block () {
-               foreach (Expression arg in argument_list) {
-                       if (!arg.in_single_basic_block ()) {
-                               return false;
-                       }
-               }
-               return true;
-       }
 }
index e1c97d487039fc2039c7f8c1cb932c391324fde6..2a29d933273a481037c73699f0a0437f4be234a2 100644 (file)
@@ -112,8 +112,4 @@ public class Vala.ParenthesizedExpression : Expression {
        public override void get_used_variables (Collection<LocalVariable> collection) {
                inner.get_used_variables (collection);
        }
-
-       public override bool in_single_basic_block () {
-               return inner.in_single_basic_block ();
-       }
 }
index f926c7a53773ff7ab12273ab9e594ca0cfae5467..84f1b6e6f81915fa0fc7b78022895684a0f8cab7 100644 (file)
@@ -109,8 +109,4 @@ public class Vala.PointerIndirection : Expression {
        public override void get_used_variables (Collection<LocalVariable> collection) {
                inner.get_used_variables (collection);
        }
-
-       public override bool in_single_basic_block () {
-               return inner.in_single_basic_block ();
-       }
 }
index e34365472348f0f8943665768aea49da05161818..3ff4d6d69d59e9adaa79e209108d141ff4278780 100644 (file)
@@ -75,8 +75,4 @@ public class Vala.PostfixExpression : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return true;
-       }
 }
index fc83f1a0d71839b5465a579873629013647d58a5..dcf2e5369e7306f1aff9836de788bf72ca551573 100644 (file)
@@ -115,8 +115,4 @@ public class Vala.ReferenceTransferExpression : Expression {
        public override void get_used_variables (Collection<LocalVariable> collection) {
                inner.get_used_variables (collection);
        }
-
-       public override bool in_single_basic_block () {
-               return inner.in_single_basic_block ();
-       }
 }
index 259b7d712959cdf300463cde5fb6a0ff9ddddf74..fcd82367005fd4c1b98fe949540a2bfea1bafd5a 100644 (file)
@@ -37,6 +37,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public Class current_class;
        public Struct current_struct;
 
+       public Block insert_block;
+
        public DataType bool_type;
        public DataType string_type;
        public DataType uchar_type;
index 0000d2ced7fd5d7644c2614b730a4d2d7a4902bc..673b16e9cef3943bfc97590829afd3997136c472 100644 (file)
@@ -82,8 +82,4 @@ public class Vala.SizeofExpression : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return true;
-       }
 }
index 89137a09f9f243b7a955884536e75fd8f71d4052..27c02c2f61ffdea53ee60efc34d7da9b0bdb4959 100644 (file)
@@ -93,7 +93,11 @@ public class Vala.SwitchSection : Block {
                }
 
                owner = analyzer.current_symbol.scope;
+
+               var old_symbol = analyzer.current_symbol;
+               var old_insert_block = analyzer.insert_block;
                analyzer.current_symbol = this;
+               analyzer.insert_block = this;
 
                foreach (Statement st in get_statements ()) {
                        st.check (analyzer);
@@ -103,7 +107,8 @@ public class Vala.SwitchSection : Block {
                        local.active = false;
                }
 
-               analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+               analyzer.current_symbol = old_symbol;
+               analyzer.insert_block = old_insert_block;
 
                return !error;
        }
index 16354f6075d02d5972670d134f822619d745ca67..fc05984e8e0ef7645f9de3f436633755d791d184 100644 (file)
@@ -43,14 +43,5 @@ public class Vala.Tuple : Expression {
        public override bool is_pure () {
                return false;
        }
-
-       public override bool in_single_basic_block () {
-               foreach (Expression expr in expression_list) {
-                       if (!expr.in_single_basic_block ()) {
-                               return false;
-                       }
-               }
-               return true;
-       }
 }
 
index dea9708b468f23b130233fd974795c2ad069dbbe..2dee142f174a086a9c4134d6beb2270864b8c2a5 100644 (file)
@@ -101,8 +101,4 @@ public class Vala.TypeCheck : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return expression.in_single_basic_block ();
-       }
 }
index e18be52ae905e681d141f20a53097e0b8f7fa305..9331a8f399597cb51efff4b519abb8d5e3b12964 100644 (file)
@@ -84,8 +84,4 @@ public class Vala.TypeofExpression : Expression {
 
                return !error;
        }
-
-       public override bool in_single_basic_block () {
-               return true;
-       }
 }
index 16260859ec8209586646eb0719f0b403cb9fe369..9f478d8e94113d3856145b35816b08c9bf9d84cd 100644 (file)
@@ -241,10 +241,6 @@ public class Vala.UnaryExpression : Expression {
                        inner.get_used_variables (collection);
                }
        }
-
-       public override bool in_single_basic_block () {
-               return inner.in_single_basic_block ();
-       }
 }
 
 public enum Vala.UnaryOperator {
index 3a595256ab308a18c6af3fbe61732f693ac0a2be..64c8e1ce251bdb685c95b5fd6ef427ca3a484095 100644 (file)
@@ -94,19 +94,6 @@ public class Vala.WhileStatement : CodeNode, Statement {
 
                checked = true;
 
-               if (!condition.in_single_basic_block ()) {
-                       // move condition into the loop body to allow split
-                       // in multiple statements
-
-                       var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
-                       var true_block = new Block (condition.source_reference);
-                       true_block.add_statement (new BreakStatement (condition.source_reference));
-                       var if_stmt = new IfStatement (if_condition, true_block, null, condition.source_reference);
-                       body.insert_statement (0, if_stmt);
-
-                       condition = new BooleanLiteral (true, source_reference);
-               }
-
                condition.check (analyzer);
                
                body.check (analyzer);
@@ -128,4 +115,21 @@ public class Vala.WhileStatement : CodeNode, Statement {
 
                return !error;
        }
+
+       public Block prepare_condition_split (SemanticAnalyzer analyzer) {
+               // move condition into the loop body to allow split
+               // in multiple statements
+
+               var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
+               var true_block = new Block (condition.source_reference);
+               true_block.add_statement (new BreakStatement (condition.source_reference));
+               var if_stmt = new IfStatement (if_condition, true_block, null, condition.source_reference);
+               body.insert_statement (0, if_stmt);
+
+               condition = new BooleanLiteral (true, source_reference);
+               condition.check (analyzer);
+
+               return body;
+       }
 }
+