]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use more statements()
authorLuca Bruno <luca.bruno@immobiliare.it>
Mon, 3 Feb 2014 14:54:54 +0000 (15:54 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 1 Apr 2020 08:17:51 +0000 (10:17 +0200)
codegen/valaccodetransformer.vala

index 9f67943b6f30d5266eb9a999003324108399d2db..ad348df1a0959f5290769967353f797a585e1b46 100644 (file)
@@ -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);