[vala/wip/transform-ast: 24/25] Use more statements()



commit 7f1d1869e48b22c54cbfa322c39ba8e876503c64
Author: Luca Bruno <luca bruno immobiliare it>
Date:   Mon Feb 3 15:54:54 2014 +0100

    Use more statements()

 codegen/valaccodetransformer.vala | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 9f67943b6..ad348df1a 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -68,10 +68,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                if (!stmt.condition.is_always_false ()) {
                        b.open_loop ();
                        if (!stmt.condition.is_always_true ()) {
-                               var cond = expression ("!%?", {stmt.condition});
-                               b.open_if (cond);
-                               b.add_break ();
-                               b.close ();
+                               statements ("if (!%?) { break; }", {stmt.condition});
                        }
                        b.add_statement (stmt.body);
                        b.close ();
@@ -89,13 +86,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                // do not generate variable and if block if condition is always true
                if (!stmt.condition.is_always_true ()) {
                        var notfirst = b.add_temp_declaration (null, expression ("false"));
-                       b.open_if (expression (notfirst));
-                       b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, 
stmt.source_reference));
-                       b.add_break ();
-                       b.close ();
-                       b.add_else ();
-                       b.add_assignment (expression (notfirst), expression ("true"));
-                       b.close ();
+                       statements (@"if ($notfirst) { if (!%?) { break; } } else { $notfirst = true; }", 
{stmt.condition});
                }
                stmt.body.checked = false;
                b.add_statement (stmt.body);
@@ -262,19 +253,13 @@ public class Vala.CCodeTransformer : CodeTransformer {
                    && (expr.operator == BinaryOperator.AND || expr.operator == BinaryOperator.OR)) {
                        var is_and = expr.operator == BinaryOperator.AND;
                        var result = b.add_temp_declaration (data_type ("bool"));
-                       b.open_if (expr.left);
-                       if (is_and) {
-                               b.add_assignment (expression (result), expr.right);
-                       } else {
-                               statements (@"$result = true;");
-                       }
-                       b.add_else ();
+
                        if (is_and) {
-                               statements (@"$result = false;");
+                               statements (@"if (%?) { $result = %?; } else { $result = false; }", 
{expr.left, expr.right});
                        } else {
-                               b.add_assignment (expression (result), expr.right);
+                               statements (@"if (%?) { $result = true; } else { $result = %?; }", 
{expr.left, expr.right});
                        }
-                       b.close ();
+
                        replacement = expression (result);
                } else if (expr.operator == BinaryOperator.COALESCE) {
                        var result_type = copy_type (expr.value_type);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]