[vala/wip/transform: 78/102] Cleanup generated empty blocks
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 78/102] Cleanup generated empty blocks
- Date: Tue, 23 Oct 2018 20:48:34 +0000 (UTC)
commit 9707ab31cb454be2806359b2690d6dd85d01b499
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(+)
---
diff --git a/vala/valablock.vala b/vala/valablock.vala
index 3e82d8014..028cfc76c 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 e2087c7fc..51433956b 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 3e9f6ffae..4b78a9470 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]