vala r2085 - in trunk: . vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2085 - in trunk: . vala
- Date: Sat, 29 Nov 2008 17:25:52 +0000 (UTC)
Author: juergbi
Date: Sat Nov 29 17:25:51 2008
New Revision: 2085
URL: http://svn.gnome.org/viewvc/vala?rev=2085&view=rev
Log:
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
Modified:
trunk/ChangeLog
trunk/vala/valaaddressofexpression.vala
trunk/vala/valaarraycreationexpression.vala
trunk/vala/valaassignment.vala
trunk/vala/valabaseaccess.vala
trunk/vala/valabinaryexpression.vala
trunk/vala/valacastexpression.vala
trunk/vala/valaconditionalexpression.vala
trunk/vala/valadostatement.vala
trunk/vala/valaelementaccess.vala
trunk/vala/valaexpression.vala
trunk/vala/valaforstatement.vala
trunk/vala/valainitializerlist.vala
trunk/vala/valalambdaexpression.vala
trunk/vala/valaliteral.vala
trunk/vala/valamemberaccess.vala
trunk/vala/valamethodcall.vala
trunk/vala/valaobjectcreationexpression.vala
trunk/vala/valaparenthesizedexpression.vala
trunk/vala/valapointerindirection.vala
trunk/vala/valapostfixexpression.vala
trunk/vala/valareferencetransferexpression.vala
trunk/vala/valasizeofexpression.vala
trunk/vala/valatuple.vala
trunk/vala/valatypecheck.vala
trunk/vala/valatypeofexpression.vala
trunk/vala/valaunaryexpression.vala
trunk/vala/valawhilestatement.vala
Modified: trunk/vala/valaaddressofexpression.vala
==============================================================================
--- trunk/vala/valaaddressofexpression.vala (original)
+++ trunk/vala/valaaddressofexpression.vala Sat Nov 29 17:25:51 2008
@@ -97,4 +97,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return inner.in_single_basic_block ();
+ }
}
Modified: trunk/vala/valaarraycreationexpression.vala
==============================================================================
--- trunk/vala/valaarraycreationexpression.vala (original)
+++ trunk/vala/valaarraycreationexpression.vala Sat Nov 29 17:25:51 2008
@@ -220,4 +220,13 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ foreach (Expression size in sizes) {
+ if (!size.in_single_basic_block ()) {
+ return false;
+ }
+ }
+ return true;
+ }
}
Modified: trunk/vala/valaassignment.vala
==============================================================================
--- trunk/vala/valaassignment.vala (original)
+++ trunk/vala/valaassignment.vala Sat Nov 29 17:25:51 2008
@@ -400,6 +400,10 @@
}
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 {
Modified: trunk/vala/valabaseaccess.vala
==============================================================================
--- trunk/vala/valabaseaccess.vala (original)
+++ trunk/vala/valabaseaccess.vala Sat Nov 29 17:25:51 2008
@@ -88,4 +88,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return true;
+ }
}
Modified: trunk/vala/valabinaryexpression.vala
==============================================================================
--- trunk/vala/valabinaryexpression.vala (original)
+++ trunk/vala/valabinaryexpression.vala Sat Nov 29 17:25:51 2008
@@ -145,6 +145,47 @@
checked = true;
+ if (operator == BinaryOperator.AND || operator == BinaryOperator.OR) {
+ // convert conditional expression into if statement
+ // required for flow analysis and exception handling
+
+ var local = new LocalVariable (new ValueType (analyzer.bool_type.data_type), get_temp_name (), null, source_reference);
+ var decl = new DeclarationStatement (local, source_reference);
+ decl.check (analyzer);
+
+ var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference), right.source_reference);
+
+ var stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, left.source_reference), new BooleanLiteral ((operator == BinaryOperator.OR), left.source_reference), AssignmentOperator.SIMPLE, left.source_reference), left.source_reference);
+
+ var true_block = new Block (source_reference);
+ var false_block = new Block (source_reference);
+
+ if (operator == BinaryOperator.AND) {
+ true_block.add_statement (right_stmt);
+ false_block.add_statement (stmt);
+ } else {
+ true_block.add_statement (stmt);
+ false_block.add_statement (right_stmt);
+ }
+
+ 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);
+
+ if (!if_stmt.check (analyzer)) {
+ return false;
+ }
+
+ var ma = new MemberAccess.simple (local.name, source_reference);
+ ma.target_type = target_type;
+ ma.check (analyzer);
+
+ parent_node.replace_expression (this, ma);
+
+ return true;
+ }
+
if (!left.check (analyzer) || !right.check (analyzer)) {
/* if there were any errors in inner expressions, skip type check */
error = true;
@@ -260,14 +301,6 @@
// integer type or flags type
value_type = left.value_type;
- } else if (operator == BinaryOperator.AND
- || operator == BinaryOperator.OR) {
- if (!left.value_type.compatible (analyzer.bool_type) || !right.value_type.compatible (analyzer.bool_type)) {
- error = true;
- Report.error (source_reference, "Operands must be boolean");
- }
-
- value_type = analyzer.bool_type;
} else if (operator == BinaryOperator.IN) {
if (left.value_type.compatible (analyzer.int_type)
&& right.value_type.compatible (analyzer.int_type)) {
@@ -315,6 +348,14 @@
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 {
Modified: trunk/vala/valacastexpression.vala
==============================================================================
--- trunk/vala/valacastexpression.vala (original)
+++ trunk/vala/valacastexpression.vala Sat Nov 29 17:25:51 2008
@@ -131,4 +131,8 @@
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 ();
+ }
}
Modified: trunk/vala/valaconditionalexpression.vala
==============================================================================
--- trunk/vala/valaconditionalexpression.vala (original)
+++ trunk/vala/valaconditionalexpression.vala Sat Nov 29 17:25:51 2008
@@ -113,6 +113,9 @@
true_expression.target_type = target_type;
false_expression.target_type = target_type;
+ var local = new LocalVariable (null, temp_name, null, source_reference);
+ var decl = new DeclarationStatement (local, source_reference);
+
var true_local = new LocalVariable (null, temp_name, true_expression, true_expression.source_reference);
var true_block = new Block (true_expression.source_reference);
var true_decl = new DeclarationStatement (true_local, true_expression.source_reference);
@@ -124,6 +127,10 @@
false_block.add_statement (false_decl);
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);
+
if (!if_stmt.check (analyzer)) {
return false;
}
@@ -146,8 +153,7 @@
value_type.value_owned = (true_expression.value_type.value_owned || false_expression.value_type.value_owned);
- var local = new LocalVariable (value_type, temp_name, null, source_reference);
- var decl = new DeclarationStatement (local, source_reference);
+ local.variable_type = value_type;
decl.check (analyzer);
true_expression.target_type = value_type;
@@ -162,9 +168,6 @@
true_block.replace_statement (true_decl, true_stmt);
false_block.replace_statement (false_decl, false_stmt);
- insert_statement ((Block) analyzer.current_symbol, decl);
- insert_statement ((Block) analyzer.current_symbol, if_stmt);
-
var ma = new MemberAccess.simple (local.name, source_reference);
ma.target_type = target_type;
ma.check (analyzer);
@@ -173,4 +176,8 @@
return true;
}
+
+ public override bool in_single_basic_block () {
+ return false;
+ }
}
Modified: trunk/vala/valadostatement.vala
==============================================================================
--- trunk/vala/valadostatement.vala (original)
+++ trunk/vala/valadostatement.vala Sat Nov 29 17:25:51 2008
@@ -94,6 +94,43 @@
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)) {
Modified: trunk/vala/valaelementaccess.vala
==============================================================================
--- trunk/vala/valaelementaccess.vala (original)
+++ trunk/vala/valaelementaccess.vala Sat Nov 29 17:25:51 2008
@@ -222,4 +222,13 @@
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 ();
+ }
}
Modified: trunk/vala/valaexpression.vala
==============================================================================
--- trunk/vala/valaexpression.vala (original)
+++ trunk/vala/valaexpression.vala Sat Nov 29 17:25:51 2008
@@ -105,4 +105,10 @@
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 ();
}
Modified: trunk/vala/valaforstatement.vala
==============================================================================
--- trunk/vala/valaforstatement.vala (original)
+++ trunk/vala/valaforstatement.vala Sat Nov 29 17:25:51 2008
@@ -164,6 +164,20 @@
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);
}
Modified: trunk/vala/valainitializerlist.vala
==============================================================================
--- trunk/vala/valainitializerlist.vala (original)
+++ trunk/vala/valainitializerlist.vala Sat Nov 29 17:25:51 2008
@@ -170,4 +170,13 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ foreach (Expression initializer in initializers) {
+ if (!initializer.in_single_basic_block ()) {
+ return false;
+ }
+ }
+ return true;
+ }
}
Modified: trunk/vala/valalambdaexpression.vala
==============================================================================
--- trunk/vala/valalambdaexpression.vala (original)
+++ trunk/vala/valalambdaexpression.vala Sat Nov 29 17:25:51 2008
@@ -203,4 +203,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return true;
+ }
}
Modified: trunk/vala/valaliteral.vala
==============================================================================
--- trunk/vala/valaliteral.vala (original)
+++ trunk/vala/valaliteral.vala Sat Nov 29 17:25:51 2008
@@ -33,4 +33,8 @@
public override bool is_pure () {
return true;
}
+
+ public override bool in_single_basic_block () {
+ return true;
+ }
}
Modified: trunk/vala/valamemberaccess.vala
==============================================================================
--- trunk/vala/valamemberaccess.vala (original)
+++ trunk/vala/valamemberaccess.vala Sat Nov 29 17:25:51 2008
@@ -551,4 +551,8 @@
collection.add (local);
}
}
+
+ public override bool in_single_basic_block () {
+ return inner == null || inner.in_single_basic_block ();
+ }
}
Modified: trunk/vala/valamethodcall.vala
==============================================================================
--- trunk/vala/valamethodcall.vala (original)
+++ trunk/vala/valamethodcall.vala Sat Nov 29 17:25:51 2008
@@ -422,4 +422,13 @@
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 ();
+ }
}
Modified: trunk/vala/valaobjectcreationexpression.vala
==============================================================================
--- trunk/vala/valaobjectcreationexpression.vala (original)
+++ trunk/vala/valaobjectcreationexpression.vala Sat Nov 29 17:25:51 2008
@@ -372,4 +372,13 @@
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;
+ }
}
Modified: trunk/vala/valaparenthesizedexpression.vala
==============================================================================
--- trunk/vala/valaparenthesizedexpression.vala (original)
+++ trunk/vala/valaparenthesizedexpression.vala Sat Nov 29 17:25:51 2008
@@ -112,4 +112,8 @@
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 ();
+ }
}
Modified: trunk/vala/valapointerindirection.vala
==============================================================================
--- trunk/vala/valapointerindirection.vala (original)
+++ trunk/vala/valapointerindirection.vala Sat Nov 29 17:25:51 2008
@@ -109,4 +109,8 @@
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 ();
+ }
}
Modified: trunk/vala/valapostfixexpression.vala
==============================================================================
--- trunk/vala/valapostfixexpression.vala (original)
+++ trunk/vala/valapostfixexpression.vala Sat Nov 29 17:25:51 2008
@@ -75,4 +75,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return true;
+ }
}
Modified: trunk/vala/valareferencetransferexpression.vala
==============================================================================
--- trunk/vala/valareferencetransferexpression.vala (original)
+++ trunk/vala/valareferencetransferexpression.vala Sat Nov 29 17:25:51 2008
@@ -115,4 +115,8 @@
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 ();
+ }
}
Modified: trunk/vala/valasizeofexpression.vala
==============================================================================
--- trunk/vala/valasizeofexpression.vala (original)
+++ trunk/vala/valasizeofexpression.vala Sat Nov 29 17:25:51 2008
@@ -82,4 +82,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return true;
+ }
}
Modified: trunk/vala/valatuple.vala
==============================================================================
--- trunk/vala/valatuple.vala (original)
+++ trunk/vala/valatuple.vala Sat Nov 29 17:25:51 2008
@@ -43,5 +43,14 @@
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;
+ }
}
Modified: trunk/vala/valatypecheck.vala
==============================================================================
--- trunk/vala/valatypecheck.vala (original)
+++ trunk/vala/valatypecheck.vala Sat Nov 29 17:25:51 2008
@@ -101,4 +101,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return expression.in_single_basic_block ();
+ }
}
Modified: trunk/vala/valatypeofexpression.vala
==============================================================================
--- trunk/vala/valatypeofexpression.vala (original)
+++ trunk/vala/valatypeofexpression.vala Sat Nov 29 17:25:51 2008
@@ -84,4 +84,8 @@
return !error;
}
+
+ public override bool in_single_basic_block () {
+ return true;
+ }
}
Modified: trunk/vala/valaunaryexpression.vala
==============================================================================
--- trunk/vala/valaunaryexpression.vala (original)
+++ trunk/vala/valaunaryexpression.vala Sat Nov 29 17:25:51 2008
@@ -241,6 +241,10 @@
inner.get_used_variables (collection);
}
}
+
+ public override bool in_single_basic_block () {
+ return inner.in_single_basic_block ();
+ }
}
public enum Vala.UnaryOperator {
Modified: trunk/vala/valawhilestatement.vala
==============================================================================
--- trunk/vala/valawhilestatement.vala (original)
+++ trunk/vala/valawhilestatement.vala Sat Nov 29 17:25:51 2008
@@ -94,6 +94,19 @@
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]