diff options
author | Jürg Billeter <j@bitron.ch> | 2008-11-29 17:25:51 +0000 |
---|---|---|
committer | Jürg Billeter <juergbi@src.gnome.org> | 2008-11-29 17:25:51 +0000 |
commit | 9c112c985e1edafa2602416962702f185a5583a0 (patch) | |
tree | 00a87c40a46d3f07cf15797250d396d965d8006d /vala/valadostatement.vala | |
parent | 44a1c2f3196261abbc0930f84df21fc877afd266 (diff) | |
download | vala-9c112c985e1edafa2602416962702f185a5583a0.tar.gz |
Convert binary conditional expressions into if statements
2008-11-29 Jürg Billeter <j@bitron.ch>
* vala/valaaddressofexpression.vala:
* vala/valaarraycreationexpression.vala:
* vala/valaassignment.vala:
* vala/valabaseaccess.vala:
* vala/valabinaryexpression.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/valasizeofexpression.vala:
* vala/valatuple.vala:
* vala/valatypecheck.vala:
* vala/valatypeofexpression.vala:
* vala/valaunaryexpression.vala:
* vala/valawhilestatement.vala:
Convert binary conditional expressions into if statements
svn path=/trunk/; revision=2085
Diffstat (limited to 'vala/valadostatement.vala')
-rw-r--r-- | vala/valadostatement.vala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala index 8700c883c..443aca541 100644 --- a/vala/valadostatement.vala +++ b/vala/valadostatement.vala @@ -94,6 +94,43 @@ 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)) { |