summaryrefslogtreecommitdiff
path: root/vala/valadostatement.vala
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2008-11-30 12:50:43 +0000
committerJürg Billeter <juergbi@src.gnome.org>2008-11-30 12:50:43 +0000
commit0697212ab726a72c826d27208181e026bf192cad (patch)
treef266a35833ce799ab33a2e3005031c69545fcf6b /vala/valadostatement.vala
parent457053b12382af6629ee5c64d0b2615b5ca6083b (diff)
downloadvala-0697212ab726a72c826d27208181e026bf192cad.tar.gz
Fix error handling in condition of while, do, and for statements
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
Diffstat (limited to 'vala/valadostatement.vala')
-rw-r--r--vala/valadostatement.vala83
1 files changed, 43 insertions, 40 deletions
diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala
index 443aca541..c994cb148 100644
--- a/vala/valadostatement.vala
+++ b/vala/valadostatement.vala
@@ -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;
+ }
}