]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use builder for the while statements
authorLuca Bruno <lucabru@src.gnome.org>
Thu, 5 Jan 2012 19:41:10 +0000 (20:41 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 11 Mar 2019 12:52:38 +0000 (13:52 +0100)
codegen/valaccodetransformer.vala
codegen/valagdbusclienttransformer.vala
codegen/valagvariantmodule.vala
vala/valacodebuilder.vala

index ec811f230f75b8a47f532e3c0e15f424eb5d2525..b5dd01e0685e7df67b8bef28ff8c522df14a18c7 100644 (file)
@@ -156,28 +156,26 @@ public class Vala.CCodeTransformer : CodeTransformer {
 
        public override void visit_while_statement (WhileStatement stmt) {
                // convert to simple loop
+               push_builder (new CodeBuilder (context, stmt, stmt.source_reference));
 
-               if (always_true (stmt.condition)) {
-                       // do not generate if block if condition is always true
-               } else if (always_false (stmt.condition)) {
-                       // do not generate if block if condition is always false
-                       stmt.body.insert_statement (0, new BreakStatement (stmt.condition.source_reference));
-               } else {
-                       var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, stmt.condition.source_reference);
-                       var true_block = new Block (stmt.condition.source_reference);
-                       true_block.add_statement (new BreakStatement (stmt.condition.source_reference));
-                       var if_stmt = new IfStatement (if_condition, true_block, null, stmt.condition.source_reference);
-                       stmt.body.insert_statement (0, if_stmt);
+               if (!always_false (stmt.condition)) {
+                       b.open_loop ();
+                       if (!always_true (stmt.condition)) {
+                               b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, stmt.condition.source_reference));
+                               b.add_break ();
+                               b.close ();
+                               b.add_statement (stmt.body);
+                       }
+                       b.close ();
                }
 
-               var loop = new Loop (stmt.body, stmt.source_reference);
-
-               var parent_block = (Block) stmt.parent_node;
+               var parent_block = context.analyzer.get_current_block (stmt);
                context.analyzer.replaced_nodes.add (stmt);
-               parent_block.replace_statement (stmt, loop);
+               parent_block.replace_statement (stmt, new EmptyStatement (stmt.source_reference));
 
                stmt.body.checked = false;
-               check (loop);
+               b.check (this);
+               pop_builder ();
        }
 
        public override void visit_do_statement (DoStatement stmt) {
index 43fabc790ded06fb9e16080272e5020829a39355..5e887bc403a9f2e8136759cd7daff0e8a8314b95 100644 (file)
@@ -102,7 +102,6 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
                string fd_list = null;
                foreach (var param in m.get_parameters ()) {
                        if (param.direction == ParameterDirection.IN) {
-                               string? type_name = null;
                                if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
                                        cancellable = param.name;
                                }
index b3f1fa86d1bece101746fb194aec3bae463c2a1a..5ebc8e861216ecb92968c7afbc55121f5e7477a7 100644 (file)
  */
 
 public class Vala.GVariantModule : GAsyncModule {
-       struct BasicTypeInfo {
-               public unowned string signature;
-               public unowned string type_name;
-               public bool is_string;
-       }
-
-       const BasicTypeInfo[] basic_types = {
-               { "y", "byte", false },
-               { "b", "boolean", false },
-               { "n", "int16", false },
-               { "q", "uint16", false },
-               { "i", "int32", false },
-               { "u", "uint32", false },
-               { "x", "int64", false },
-               { "t", "uint64", false },
-               { "d", "double", false },
-               { "s", "string", true },
-               { "o", "object_path", true },
-               { "g", "signature", true }
-       };
-
        static bool is_string_marshalled_enum (TypeSymbol? symbol) {
                if (symbol != null && symbol is Enum) {
                        return symbol.get_attribute_bool ("DBus", "use_string_marshalling");
index 35282981c00e9cd02d5353d2cfad0f6a4c1a11c4..fc6c4e3230869535568bc99c4978fc7b23c83e7c 100644 (file)
@@ -97,6 +97,16 @@ public class Vala.CodeBuilder {
                statement_stack.add (stmt);
        }
 
+       public void open_loop () {
+               statement_stack.add (current_block);
+               var parent_block = current_block;
+
+               current_block = new Block (source_reference);
+
+               var stmt = new Loop (current_block, source_reference);
+               parent_block.add_statement (stmt);
+       }
+
        public void open_while (Expression condition) {
                statement_stack.add (current_block);
                var parent_block = current_block;