[vala/wip/transform: 83/131] Use builder for the while statements



commit eefa0b7b820bc9a81bcbf429e50abaa19aacf12e
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Jan 5 20:41:10 2012 +0100

    Use builder for the while statements

 codegen/valaccodetransformer.vala       | 30 ++++++++++++++----------------
 codegen/valagdbusclienttransformer.vala |  1 -
 codegen/valagvariantmodule.vala         | 21 ---------------------
 vala/valacodebuilder.vala               | 10 ++++++++++
 4 files changed, 24 insertions(+), 38 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index ec811f230..b5dd01e06 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -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) {
diff --git a/codegen/valagdbusclienttransformer.vala b/codegen/valagdbusclienttransformer.vala
index 43fabc790..5e887bc40 100644
--- a/codegen/valagdbusclienttransformer.vala
+++ b/codegen/valagdbusclienttransformer.vala
@@ -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;
                                }
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index b3f1fa86d..5ebc8e861 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -21,27 +21,6 @@
  */
 
 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");
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index 35282981c..fc6c4e323 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -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;


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