[vala/wip/transform: 77/98] Cleanup generated empty blocks
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 77/98] Cleanup generated empty blocks
- Date: Sun, 25 Sep 2016 19:40:40 +0000 (UTC)
commit 0a5b54cec41e80ca3b1607ffe285812c0d5d4019
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 | 2 ++
3 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/vala/valablock.vala b/vala/valablock.vala
index 6d9cf74..3f2de5f 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 ea7262b..2d5e364 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -46,6 +46,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 23b10fd..ffb55ec 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -40,6 +40,8 @@ public class Vala.CodeTransformer : CodeVisitor {
}
public void pop_builder () {
+ b.cleanup ();
+
b = builder_stack[builder_stack.size - 1];
builder_stack.remove_at (builder_stack.size - 1);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]