]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use statements() parsing
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 2 Feb 2014 22:32:35 +0000 (23:32 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 11 Mar 2019 12:52:38 +0000 (13:52 +0100)
codegen/valaccodetransformer.vala
vala/valacodebuilder.vala
vala/valacodetransformer.vala

index cca3988267b0c531a28b7bbb4ef76f48d39358b5..a6e4f9b57ac3bb0c0c156e02824710107fcae3ee 100644 (file)
@@ -223,13 +223,11 @@ public class Vala.CCodeTransformer : CodeTransformer {
                                b.add_expression (it_expr);
                        }
                        b.add_else ();
-                       b.add_assignment (expression (notfirst), expression ("true"));
+                       statements (@"$notfirst = true;");
                        b.close ();
 
                        if (stmt.condition != null && !always_true (stmt.condition)) {
-                               b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, stmt.source_reference));
-                               b.add_break ();
-                               b.close ();
+                               statements (@"if (!$(stmt.condition)) break;");
                        }
                        b.add_statement (stmt.body);
 
@@ -373,11 +371,11 @@ public class Vala.CCodeTransformer : CodeTransformer {
                begin_replace_expression (expr);
 
                var result = b.add_temp_declaration (expr.value_type);
-               b.open_if (expr.condition);
-               b.add_assignment (expression (result), expr.true_expression);
-               b.add_else ();
-               b.add_assignment (expression (result), expr.false_expression);
-               b.close ();
+               statements (@"if ($(expr.condition)) {
+                                       $result = $(expr.true_expression);
+                                       } else {
+                                       $result = $(expr.false_expression);
+                                       }");
 
                replacement = return_temp_access (result, expr.value_type, target_type, formal_target_type);
                end_replace_expression (replacement);
index ab174ffb9719264bb512322f4c395b6a68304558..036303cb9a88502591970b59faa5a0e6389f6a47 100644 (file)
@@ -272,6 +272,10 @@ public class Vala.CodeBuilder {
                return new Parser().parse_expression_string (str, source_reference);
        }
 
+       public void statements (string str) {
+               new Parser().parse_statements_string (str, current_block, source_reference);
+       }
+
        // only qualified types, will slightly simplify the work of SymbolResolver
        public static Symbol? symbol_from_string (string symbol_string, Symbol? parent_symbol = null) {
                Symbol sym = parent_symbol != null ? parent_symbol : CodeContext.get().root;
index b7b829737d30b3be0ba8a9764ab4fc6d40ba220e..f6444b8e976d6ce5e9a947d09aa67b891ef100ad 100644 (file)
@@ -184,6 +184,10 @@ public class Vala.CodeTransformer : CodeVisitor {
                return b.expression (str);
        }
 
+       public void statements (string str) {
+               b.statements (str);
+       }
+
        public void check (CodeNode node) {
                var sym = context.analyzer.get_current_symbol (node);
                if (sym != null) {