[vala/wip/transform: 40/98] Drop build_context from CodeBuilder
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 40/98] Drop build_context from CodeBuilder
- Date: Mon, 3 Feb 2014 23:52:28 +0000 (UTC)
commit f95b34471a2418ca92ff5e6bb16913d9f63a0af0
Author: Luca Bruno <lucabru src gnome org>
Date: Wed Jan 4 15:25:04 2012 +0100
Drop build_context from CodeBuilder
codegen/valagdbusclienttransformer.vala | 4 +-
codegen/valagdbusservertransformer.vala | 4 +-
codegen/valagvarianttransformer.vala | 24 +++---
vala/valacodebuilder.vala | 148 +++++++++++++-----------------
4 files changed, 80 insertions(+), 100 deletions(-)
---
diff --git a/codegen/valagdbusclienttransformer.vala b/codegen/valagdbusclienttransformer.vala
index 84456fc..6d585db 100644
--- a/codegen/valagdbusclienttransformer.vala
+++ b/codegen/valagdbusclienttransformer.vala
@@ -187,7 +187,7 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
m.access = SymbolAccessibility.PRIVATE;
m.add_parameter (new Parameter ("parameters", data_type ("GLib.Variant", false),
sig.source_reference));
proxy_class.add_method (m);
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
var iter = b.add_temp_declaration (null, expression ("parameters.iterator ()"));
var call = new MethodCall (expression (sig.name), sig.source_reference);
@@ -202,7 +202,7 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
}
b.add_expression (call);
- b.pop_method ();
+ pop_builder ();
return m.name;
}
diff --git a/codegen/valagdbusservertransformer.vala b/codegen/valagdbusservertransformer.vala
index 16570c7..618fa6f 100644
--- a/codegen/valagdbusservertransformer.vala
+++ b/codegen/valagdbusservertransformer.vala
@@ -43,7 +43,7 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
wrapper.add_parameter (new Parameter ("object", object_type));
wrapper.add_parameter (new Parameter ("arguments", data_type ("GLib.Variant", false)));
wrapper.add_parameter (new Parameter ("invocation", data_type ("GLib.DBusMethodInvocation",
false)));
- b.push_method (wrapper);
+ push_builder (new CodeBuilder.for_subroutine (wrapper));
var iter = b.add_temp_declaration (null, expression ("arguments.iterator ()"));
@@ -136,7 +136,7 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
check (ready);
}
- b.pop_method ();
+ pop_builder ();
check (wrapper);
return wrapper.name;
}
diff --git a/codegen/valagvarianttransformer.vala b/codegen/valagvarianttransformer.vala
index f1b9e51..694bfe0 100644
--- a/codegen/valagvarianttransformer.vala
+++ b/codegen/valagvarianttransformer.vala
@@ -147,7 +147,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
Method m;
if (!wrapper_method (data_type ("GLib.Variant"), "gvariant_serialize_array
"+array_type.to_string(), out m)) {
m.add_parameter (new Parameter ("array", copy_type (array_type, false),
b.source_reference));
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
string[] indices = new string[array_type.rank];
for (int dim=1; dim <= array_type.rank; dim++) {
@@ -155,7 +155,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
}
b.add_return (serialize_array_dim (array_type, 1, indices, "array"));
- b.pop_method ();
+ pop_builder ();
check (m);
}
var call = (MethodCall) expression (m.name+"()");
@@ -215,7 +215,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
var type = context.analyzer.get_data_type_for_symbol (st);
if (!wrapper_method (data_type ("GLib.Variant"), "gvariant_serialize_struct
"+type.to_string(), out m)) {
m.add_parameter (new Parameter ("st", type, b.source_reference));
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
var builderinit = expression ("new GLib.VariantBuilder (GLib.VariantType.TUPLE)");
var builder = b.add_temp_declaration (null, builderinit);
@@ -229,7 +229,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
}
b.add_return (expression (@"$builder.end ()"));
- b.pop_method ();
+ pop_builder ();
check (m);
}
@@ -242,7 +242,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
Method m;
if (!wrapper_method (data_type ("GLib.Variant"), "gvariant_serialize_hash_table
"+type.to_string(), out m)) {
m.add_parameter (new Parameter ("ht", copy_type (type, false), b.source_reference));
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
var builderinit = expression (@"new GLib.VariantBuilder (new GLib.VariantType
(\"$(get_type_signature (type))\"))");
var builder = b.add_temp_declaration (null, builderinit);
@@ -251,7 +251,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
b.add_expression (for_each);
b.add_return (expression (@"$builder.end ()"));
- b.pop_method ();
+ pop_builder ();
check (m);
}
var call = (MethodCall) expression (m.name+"()");
@@ -273,7 +273,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
Method m;
if (!wrapper_method (copy_type (array_type, true), "gvariant_deserialize_array
"+array_type.to_string(), out m)) {
m.add_parameter (new Parameter ("variant", data_type ("GLib.Variant", false),
b.source_reference));
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
var iterator = b.add_temp_declaration (data_type ("GLib.VariantIter"), expression
("variant.iterator ()"));
@@ -294,7 +294,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
deserialize_array_dim (array_type, "variant", indices, 1, array);
b.add_return (expression (array));
- b.pop_method ();
+ pop_builder ();
check (m);
}
var call = (MethodCall) expression (m.name+"()");
@@ -338,7 +338,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
type.value_owned = true;
if (!wrapper_method (type, "gvariant_deserialize_struct "+type.to_string(), out m)) {
m.add_parameter (new Parameter ("variant", data_type ("GLib.Variant", false),
b.source_reference));
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
var iterator = b.add_temp_declaration (data_type ("GLib.VariantIter"), expression
(@"variant.iterator ()"));
@@ -352,7 +352,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
b.add_assignment (expression (@"$result.$(f.name)"), expression
(@"($(f.variable_type)) ($iterator.next_value ())"));
}
b.add_return (expression (result));
- b.pop_method ();
+ pop_builder ();
check (m);
}
var call = (MethodCall) expression (m.name+"()");
@@ -364,7 +364,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
Method m;
if (!wrapper_method (copy_type (type, true), "gvariant_deserialize_hash_table
"+type.to_string(), out m)) {
m.add_parameter (new Parameter ("variant", data_type ("GLib.Variant", false),
b.source_reference));
- b.push_method (m);
+ push_builder (new CodeBuilder.for_subroutine (m));
var iterator = b.add_temp_declaration (data_type ("GLib.VariantIter"), expression
(@"variant.iterator ()"));
@@ -388,7 +388,7 @@ public class Vala.GVariantTransformer : CodeTransformer {
b.close ();
b.add_return (expression (hash_table));
- b.pop_method ();
+ pop_builder ();
check (m);
}
var call = (MethodCall) expression (m.name+"()");
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index f32cca3..19e3590 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -23,119 +23,99 @@
using GLib;
public class Vala.CodeBuilder {
- class BuildContext {
- public Block current_block;
- public Statement insert_statement;
- public Block insert_block;
- public ArrayList<Statement> statement_stack = new ArrayList<Statement> ();
- public ArrayList<CodeNode> check_nodes = new ArrayList<CodeNode> ();
- }
-
- BuildContext build_context;
- ArrayList<BuildContext> context_stack = new ArrayList<BuildContext> ();
+ public Block current_block;
+ public Statement insert_statement;
+ public Block insert_block;
+ public ArrayList<Statement> statement_stack = new ArrayList<Statement> ();
+ public ArrayList<CodeNode> check_nodes = new ArrayList<CodeNode> ();
public SourceReference source_reference;
public CodeBuilder (CodeContext context, Statement insert_statement, SourceReference
source_reference) {
- build_context = new BuildContext ();
- build_context.current_block = new Block (source_reference);
- build_context.insert_statement = insert_statement;
- build_context.insert_block = context.analyzer.get_insert_block (insert_statement);
+ current_block = new Block (source_reference);
+ insert_statement = insert_statement;
+ insert_block = context.analyzer.get_insert_block (insert_statement);
this.source_reference = source_reference;
var statement_block = context.analyzer.get_current_block (insert_statement);
- statement_block.insert_before (build_context.insert_statement, build_context.current_block);
- build_context.insert_statement = build_context.current_block;
- build_context.check_nodes.add (build_context.current_block);
+ statement_block.insert_before (insert_statement, current_block);
+ insert_statement = current_block;
+ check_nodes.add (current_block);
}
public CodeBuilder.for_subroutine (Subroutine m) {
source_reference = m.source_reference;
- build_context = new BuildContext ();
- build_context.insert_block = m.body = new Block (source_reference);
- build_context.insert_statement = build_context.current_block = new Block (source_reference);
- m.body.add_statement (build_context.current_block);
+ insert_block = m.body = new Block (source_reference);
+ insert_statement = current_block = new Block (source_reference);
+ m.body.add_statement (current_block);
}
public void check (CodeTransformer transformer) {
- foreach (var node in build_context.check_nodes) {
+ foreach (var node in check_nodes) {
transformer.check (node);
}
}
- public void push_method (Method m) {
- context_stack.add (build_context);
- build_context = new BuildContext ();
- build_context.insert_block = m.body = new Block (source_reference);
- build_context.insert_statement = build_context.current_block = new Block (source_reference);
- m.body.add_statement (build_context.current_block);
- }
-
- public void pop_method () {
- build_context = context_stack[context_stack.size - 1];
- context_stack.remove_at (context_stack.size - 1);
- }
-
public void open_block () {
- build_context.statement_stack.add (build_context.current_block);
- var parent_block = build_context.current_block;
+ statement_stack.add (current_block);
+ var parent_block = current_block;
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- parent_block.add_statement (build_context.current_block);
+ parent_block.add_statement (current_block);
}
public void open_if (Expression condition) {
- build_context.statement_stack.add (build_context.current_block);
- var parent_block = build_context.current_block;
+ statement_stack.add (current_block);
+ var parent_block = current_block;
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = new IfStatement (condition, build_context.current_block, null, source_reference);
- build_context.statement_stack.add (stmt);
+ var stmt = new IfStatement (condition, current_block, null, source_reference);
+ statement_stack.add (stmt);
parent_block.add_statement (stmt);
}
public void add_else () {
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = (IfStatement) build_context.statement_stack[build_context.statement_stack.size-1];
+ var stmt = (IfStatement) statement_stack[statement_stack.size-1];
assert (stmt.false_statement == null);
- stmt.false_statement = build_context.current_block;
+ stmt.false_statement = current_block;
}
public void else_if (Expression condition) {
- var parent_if = (IfStatement)
build_context.statement_stack[build_context.statement_stack.size - 1];
+ var parent_if = (IfStatement) statement_stack[statement_stack.size - 1];
assert (parent_if.false_statement == null);
- build_context.statement_stack.remove_at (build_context.statement_stack.size - 1);
+ statement_stack.remove_at (statement_stack.size - 1);
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = new IfStatement (condition, build_context.current_block, null, source_reference);
+ var stmt = new IfStatement (condition, current_block, null, source_reference);
var block = new Block (source_reference);
block.add_statement (stmt);
parent_if.false_statement = block;
- build_context.statement_stack.add (stmt);
+ statement_stack.add (stmt);
}
public void open_while (Expression condition) {
- build_context.statement_stack.add (build_context.current_block);
- var parent_block = build_context.current_block;
+ statement_stack.add (current_block);
+ var parent_block = current_block;
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = new WhileStatement (condition, build_context.current_block, source_reference);
+ var stmt = new WhileStatement (condition, current_block, source_reference);
parent_block.add_statement (stmt);
}
public void open_for (Expression? initializer, Expression condition, Expression? iterator) {
- build_context.statement_stack.add (build_context.current_block);
- var parent_block = build_context.current_block;
+ statement_stack.add (current_block);
+ var parent_block = current_block;
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = new ForStatement (condition, build_context.current_block, source_reference);
+ var stmt = new ForStatement (condition, current_block, source_reference);
if (initializer != null) {
stmt.add_initializer (initializer);
}
@@ -147,10 +127,10 @@ public class Vala.CodeBuilder {
}
public void open_switch (Expression expression, Expression? first_label) {
- var parent_block = build_context.current_block;
+ var parent_block = current_block;
var stmt = new SwitchStatement (expression, source_reference);
- build_context.statement_stack.add (stmt);
+ statement_stack.add (stmt);
var section = new SwitchSection (source_reference);
SwitchLabel label;
@@ -160,17 +140,17 @@ public class Vala.CodeBuilder {
label = new SwitchLabel (first_label);
}
section.add_label (label);
- build_context.current_block = section;
- build_context.statement_stack.add (section);
+ current_block = section;
+ statement_stack.add (section);
parent_block.add_statement (stmt);
stmt.add_section (section);
}
public void add_section (Expression? expression) {
- build_context.statement_stack.remove_at (build_context.statement_stack.size - 1);
+ statement_stack.remove_at (statement_stack.size - 1);
- var stmt = (SwitchStatement) build_context.statement_stack[build_context.statement_stack.size
- 1];
+ var stmt = (SwitchStatement) statement_stack[statement_stack.size - 1];
var section = new SwitchSection (source_reference);
SwitchLabel label;
if (expression == null) {
@@ -179,14 +159,14 @@ public class Vala.CodeBuilder {
label = new SwitchLabel (expression);
}
section.add_label (label);
- build_context.current_block = section;
- build_context.statement_stack.add (section);
+ current_block = section;
+ statement_stack.add (section);
stmt.add_section (section);
}
public void add_label (Expression? expression) {
- var section = (SwitchSection)
build_context.statement_stack[build_context.statement_stack.size - 1];
+ var section = (SwitchSection) statement_stack[statement_stack.size - 1];
SwitchLabel label;
if (expression == null) {
label = new SwitchLabel.with_default (source_reference);
@@ -197,26 +177,26 @@ public class Vala.CodeBuilder {
}
public void open_try () {
- build_context.statement_stack.add (build_context.current_block);
- var parent_block = build_context.current_block;
+ statement_stack.add (current_block);
+ var parent_block = current_block;
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = new TryStatement (build_context.current_block, null, source_reference);
- build_context.statement_stack.add (stmt);
+ var stmt = new TryStatement (current_block, null, source_reference);
+ statement_stack.add (stmt);
parent_block.add_statement (stmt);
}
public void add_catch (DataType? error_type, string? variable_name) {
- build_context.current_block = new Block (source_reference);
+ current_block = new Block (source_reference);
- var stmt = (TryStatement) build_context.statement_stack[build_context.statement_stack.size-1];
- stmt.add_catch_clause (new CatchClause (error_type, variable_name,
build_context.current_block, source_reference));
+ var stmt = (TryStatement) statement_stack[statement_stack.size-1];
+ stmt.add_catch_clause (new CatchClause (error_type, variable_name, current_block,
source_reference));
}
public void add_statement (Statement statement) {
- build_context.current_block.add_statement (statement);
+ current_block.add_statement (statement);
}
public void add_expression (Expression expression) {
@@ -246,16 +226,16 @@ public class Vala.CodeBuilder {
public string add_temp_declaration (DataType? type, Expression? initializer = null) {
var local = new LocalVariable (type, CodeNode.get_temp_name (), initializer,
source_reference);
var stmt = new DeclarationStatement (local, source_reference);
- build_context.insert_block.insert_before (build_context.insert_statement, stmt);
- build_context.check_nodes.insert (0, stmt);
+ insert_block.insert_before (insert_statement, stmt);
+ check_nodes.insert (0, stmt);
return local.name;
}
public void close () {
do {
- var top = build_context.statement_stack[build_context.statement_stack.size - 1];
- build_context.statement_stack.remove_at (build_context.statement_stack.size - 1);
- build_context.current_block = top as Block;
- } while (build_context.current_block == null);
+ var top = statement_stack[statement_stack.size - 1];
+ statement_stack.remove_at (statement_stack.size - 1);
+ current_block = top as Block;
+ } while (current_block == null);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]