]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Cleanup generated empty blocks
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 1 Feb 2014 09:42:27 +0000 (10:42 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 1 Apr 2020 08:17:51 +0000 (10:17 +0200)
vala/valablock.vala
vala/valacodebuilder.vala
vala/valacodetransformer.vala

index 0a4c544d70fb4ad7264ba24f373b78494f952b40..4db87ca9a97fc3a6ce682c11c844446cab56afbd 100644 (file)
@@ -197,6 +197,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;
index 4a86650eaa961372ccfdc88fafeb1ed59f5b91c9..bbe8a5cc887b1500a9733a5e8ee4c3666ee5b6e9 100644 (file)
@@ -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);
index fb2a960cc4a2238b89e77abdee65976e9d09c33f..1a8bf359f36557db55d7da25875242f24419829f 100644 (file)
@@ -42,6 +42,7 @@ public class Vala.CodeTransformer : CodeVisitor {
        }
 
        public void pop_builder () {
+               b.cleanup ();
                b = builder_stack.remove_at (builder_stack.size - 1);
        }