[vala/wip/code-transformer: 20/27] Cleanup generated empty blocks



commit 2379ba8a088b9dd81f2703119dc1e460803e4924
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Feb 1 10:42:27 2014 +0100

    Cleanup generated empty blocks

 vala/valablock.vala           | 17 +++++++++++++++++
 vala/valacodebuilder.vala     |  6 ++++++
 vala/valacodetransformer.vala |  1 +
 3 files changed, 24 insertions(+)
---
diff --git a/vala/valablock.vala b/vala/valablock.vala
index 44d8f8424..32cf83f2b 100644
--- a/vala/valablock.vala
+++ b/vala/valablock.vala
@@ -195,6 +195,23 @@ public class Vala.Block : Symbol, Statement {
                stmt.prev = new_stmt;
        }
 
+       public void remove_statement (Statement stmt) {
+               var prev = stmt.prev;
+               var next = stmt.next;
+
+               if (prev != null) {
+                       prev.next = next;
+               } else {
+                       first_statement = next;
+               }
+
+               if (next != null) {
+                       next.prev = prev;
+               } else {
+                       last_statement = prev;
+               }
+       }
+
        public void replace_statement (Statement old_stmt, Statement new_stmt) {
                new_stmt.parent_node = this;
                new_stmt.prev = old_stmt.prev;
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index 4a86650ea..bbe8a5cc8 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -47,6 +47,12 @@ public class Vala.CodeBuilder {
                m.body.add_statement (current_block);
        }
 
+       public void cleanup () {
+               if (current_block.first_statement == null) {
+                       insert_block.remove_statement (current_block);
+               }
+       }
+
        public void check (CodeTransformer transformer) {
                foreach (var node in decl_nodes) {
                        transformer.check (node);
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index 66ab12c41..6a50a576c 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -42,6 +42,7 @@ public class Vala.CodeTransformer : CodeVisitor {
        }
 
        public void pop_builder () {
+               b.cleanup ();
                b = builder_stack.remove_at (builder_stack.size - 1);
        }
 


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