[vala/staging: 77/91] Cleanup generated empty blocks
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 77/91] Cleanup generated empty blocks
- Date: Mon, 3 Feb 2014 23:20:16 +0000 (UTC)
commit d21d0fd814cc24167f8236df7beb268427099b3c
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 e501716..0d5145b 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 3a27f94..551df45 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]