[vala/wip/transform: 71/107] Convert get_used_variables to TraverseVisitor
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 71/107] Convert get_used_variables to TraverseVisitor
- Date: Mon, 15 May 2017 14:53:40 +0000 (UTC)
commit a225243121ac7f0db77dccaf8ee909afc6bb7c27
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Oct 27 18:22:49 2012 +0200
Convert get_used_variables to TraverseVisitor
vala/valaarraycreationexpression.vala | 10 -----
vala/valaassignment.vala | 11 -----
vala/valabinaryexpression.vala | 5 --
vala/valacastexpression.vala | 4 --
vala/valacodenode.vala | 59 +++++++++++++++++++++++++++--
vala/valaconditionalexpression.vala | 6 ---
vala/valadeclarationstatement.vala | 7 ---
vala/valaelementaccess.vala | 7 ---
vala/valaexpressionstatement.vala | 4 --
vala/valainitializerlist.vala | 6 ---
vala/valalambdaexpression.vala | 7 ---
vala/valamemberaccess.vala | 13 ------
vala/valamemberinitializer.vala | 4 --
vala/valamethodcall.vala | 8 ----
vala/valanamedargument.vala | 4 --
vala/valaobjectcreationexpression.vala | 10 -----
vala/valapointerindirection.vala | 4 --
vala/valapostfixexpression.vala | 4 --
vala/valareferencetransferexpression.vala | 11 -----
vala/valareturnstatement.vala | 6 ---
vala/valasliceexpression.vala | 6 ---
vala/valathrowstatement.vala | 4 --
vala/valaunaryexpression.vala | 6 ---
23 files changed, 55 insertions(+), 151 deletions(-)
---
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index f5d6062..066e5b9 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -290,14 +290,4 @@ public class Vala.ArrayCreationExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- foreach (Expression e in sizes) {
- e.get_used_variables (collection);
- }
-
- if (initializer_list != null) {
- initializer_list.get_used_variables (collection);
- }
- }
}
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 04c49cd..2e50cec 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -574,17 +574,6 @@ public class Vala.Assignment : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- var ma = left as MemberAccess;
- var ea = left as ElementAccess;
- if (ma != null && ma.inner != null) {
- ma.inner.get_used_variables (collection);
- } else if (ea != null) {
- ea.get_used_variables (collection);
- }
- right.get_used_variables (collection);
- }
}
public enum Vala.AssignmentOperator {
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 402fed8..f2789de 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -406,11 +406,6 @@ public class Vala.BinaryExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- left.get_used_variables (collection);
- right.get_used_variables (collection);
- }
}
public enum Vala.BinaryOperator {
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index ee9c728..785b142 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -192,10 +192,6 @@ public class Vala.CastExpression : Expression {
codegen.visit_expression (this);
}
- public override void get_used_variables (Collection<Variable> collection) {
- inner.get_used_variables (collection);
- }
-
public override bool is_constant () {
return inner.is_constant ();
}
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index efce32b..132a89e 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -347,14 +347,16 @@ public abstract class Vala.CodeNode {
public void get_defined_variables (Collection<Variable> collection) {
var traverse = new TraverseVisitor ((n) => {
if (n is Assignment) {
- var a = (Assignment) n;
- var local = a.left.symbol_reference as LocalVariable;
- var param = a.left.symbol_reference as Parameter;
+ var expr = (Assignment) n;
+ var local = expr.left.symbol_reference as LocalVariable;
+ var param = expr.left.symbol_reference as Parameter;
if (local != null) {
collection.add (local);
} else if (param != null && param.direction ==
ParameterDirection.OUT) {
collection.add (param);
}
+ } else if (n is Block) {
+ return TraverseStatus.STOP;
} else if (n is CatchClause) {
var clause = (CatchClause) n;
if (clause.error_variable != null) {
@@ -418,7 +420,56 @@ public abstract class Vala.CodeNode {
accept (traverse);
}
- public virtual void get_used_variables (Collection<Variable> collection) {
+ public void get_used_variables (Collection<Variable> collection) {
+ TraverseVisitor traverse = null;
+ traverse = new TraverseVisitor ((n) => {
+ if (n is Assignment) {
+ var expr = (Assignment) n;
+ var ma = expr.left as MemberAccess;
+ var ea = expr.left as ElementAccess;
+ if (ma != null && ma.inner != null) {
+ ma.inner.accept (traverse);
+ } else if (ea != null) {
+ ea.accept (traverse);
+ }
+ expr.right.accept (traverse);
+ return TraverseStatus.STOP;
+ } else if (n is Block) {
+ return TraverseStatus.STOP;
+ } else if (n is MemberAccess) {
+ var expr = (MemberAccess) n;
+ var local = expr.symbol_reference as LocalVariable;
+ var param = expr.symbol_reference as Parameter;
+ if (local != null) {
+ collection.add (local);
+ } else if (param != null && param.direction ==
ParameterDirection.OUT) {
+ collection.add (param);
+ }
+ } else if (n is LambdaExpression) {
+ var expr = (LambdaExpression) n;
+ // require captured variables to be initialized
+ if (expr.method.closure) {
+ expr.method.get_captured_variables
((Collection<LocalVariable>) collection);
+ }
+ return TraverseStatus.STOP;
+ } else if (n is ReferenceTransferExpression) {
+ var expr = (ReferenceTransferExpression) n;
+ var local = expr.inner.symbol_reference as LocalVariable;
+ var param = expr.inner.symbol_reference as Parameter;
+ if (local != null) {
+ collection.add (local);
+ } else if (param != null && param.direction ==
ParameterDirection.OUT) {
+ collection.add (param);
+ }
+ } else if (n is UnaryExpression) {
+ var expr = (UnaryExpression) n;
+ if (expr.operator == UnaryOperator.OUT) {
+ return TraverseStatus.STOP;
+ }
+ }
+ return TraverseStatus.CONTINUE;
+ });
+ accept (traverse);
}
public virtual void get_error_types (Collection<DataType> collection, SourceReference?
source_reference = null) {
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 04c006a..be34c72 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -110,12 +110,6 @@ public class Vala.ConditionalExpression : Expression {
false_expression.get_error_types (collection, source_reference);
}
- public override void get_used_variables (Collection<Variable> collection) {
- condition.get_used_variables (collection);
- true_expression.get_used_variables (collection);
- false_expression.get_used_variables (collection);
- }
-
public override string to_string () {
return "%s ? %s : %s".printf (condition.to_string (), true_expression.to_string (),
false_expression.to_string ());
}
diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala
index de58207..63acc78 100644
--- a/vala/valadeclarationstatement.vala
+++ b/vala/valadeclarationstatement.vala
@@ -87,11 +87,4 @@ public class Vala.DeclarationStatement : BaseStatement {
public override void emit (CodeGenerator codegen) {
codegen.visit_declaration_statement (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- var local = declaration as LocalVariable;
- if (local != null && local.initializer != null) {
- local.initializer.get_used_variables (collection);
- }
- }
}
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 7946c9d..947ee65 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -251,11 +251,4 @@ public class Vala.ElementAccess : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- container.get_used_variables (collection);
- foreach (Expression index in indices) {
- index.get_used_variables (collection);
- }
- }
}
diff --git a/vala/valaexpressionstatement.vala b/vala/valaexpressionstatement.vala
index 82d18f8..ba747f9 100644
--- a/vala/valaexpressionstatement.vala
+++ b/vala/valaexpressionstatement.vala
@@ -92,8 +92,4 @@ public class Vala.ExpressionStatement : BaseStatement {
codegen.visit_expression_statement (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- expression.get_used_variables (collection);
- }
}
diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala
index 8d05feb..f5ae294 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -248,10 +248,4 @@ public class Vala.InitializerList : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- foreach (Expression expr in initializers) {
- expr.get_used_variables (collection);
- }
- }
}
diff --git a/vala/valalambdaexpression.vala b/vala/valalambdaexpression.vala
index d7dc7b6..b1652c0 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -252,11 +252,4 @@ public class Vala.LambdaExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- // require captured variables to be initialized
- if (method.closure) {
- method.get_captured_variables ((Collection<LocalVariable>) collection);
- }
- }
}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 50a123d..01f451f 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -905,17 +905,4 @@ public class Vala.MemberAccess : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- if (inner != null) {
- inner.get_used_variables (collection);
- }
- var local = symbol_reference as LocalVariable;
- var param = symbol_reference as Parameter;
- if (local != null) {
- collection.add (local);
- } else if (param != null && param.direction == ParameterDirection.OUT) {
- collection.add (param);
- }
- }
}
diff --git a/vala/valamemberinitializer.vala b/vala/valamemberinitializer.vala
index 352b1ff..c5e5d82 100644
--- a/vala/valamemberinitializer.vala
+++ b/vala/valamemberinitializer.vala
@@ -76,10 +76,6 @@ public class Vala.MemberInitializer : CodeNode {
initializer.emit (codegen);
}
- public override void get_used_variables (Collection<Variable> collection) {
- initializer.get_used_variables (collection);
- }
-
public override void replace_expression (Expression old_node, Expression new_node) {
if (initializer == old_node) {
initializer = new_node;
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 1019f44..ec25487 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -623,14 +623,6 @@ public class Vala.MethodCall : Expression {
codegen.visit_expression (this);
}
- public override void get_used_variables (Collection<Variable> collection) {
- call.get_used_variables (collection);
-
- foreach (Expression arg in argument_list) {
- arg.get_used_variables (collection);
- }
- }
-
public StringLiteral? get_format_literal () {
var mtype = this.call.value_type as MethodType;
if (mtype != null) {
diff --git a/vala/valanamedargument.vala b/vala/valanamedargument.vala
index 5b57c13..3ee9156 100644
--- a/vala/valanamedargument.vala
+++ b/vala/valanamedargument.vala
@@ -88,8 +88,4 @@ public class Vala.NamedArgument : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- inner.get_used_variables (collection);
- }
}
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index e6a1e8a..405c287 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -502,14 +502,4 @@ public class Vala.ObjectCreationExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- foreach (Expression arg in argument_list) {
- arg.get_used_variables (collection);
- }
-
- foreach (MemberInitializer init in object_initializer) {
- init.get_used_variables (collection);
- }
- }
}
diff --git a/vala/valapointerindirection.vala b/vala/valapointerindirection.vala
index 3ff3524..d21f31a 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -114,8 +114,4 @@ public class Vala.PointerIndirection : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- inner.get_used_variables (collection);
- }
}
diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala
index 471d813..65303eb 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -76,10 +76,6 @@ public class Vala.PostfixExpression : Expression {
return inner.is_accessible (sym);
}
- public override void get_used_variables (Collection<Variable> collection) {
- inner.get_used_variables (collection);
- }
-
public override void replace_expression (Expression old_node, Expression new_node) {
if (inner == old_node) {
inner = new_node;
diff --git a/vala/valareferencetransferexpression.vala b/vala/valareferencetransferexpression.vala
index 524d139..f6838c3 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -120,15 +120,4 @@ public class Vala.ReferenceTransferExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- inner.get_used_variables (collection);
- var local = inner.symbol_reference as LocalVariable;
- var param = inner.symbol_reference as Parameter;
- if (local != null) {
- collection.add (local);
- } else if (param != null && param.direction == ParameterDirection.OUT) {
- collection.add (param);
- }
- }
}
diff --git a/vala/valareturnstatement.vala b/vala/valareturnstatement.vala
index 59236e7..452fd20 100644
--- a/vala/valareturnstatement.vala
+++ b/vala/valareturnstatement.vala
@@ -158,10 +158,4 @@ public class Vala.ReturnStatement : BaseStatement {
codegen.visit_return_statement (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- if (return_expression != null) {
- return_expression.get_used_variables (collection);
- }
- }
}
diff --git a/vala/valasliceexpression.vala b/vala/valasliceexpression.vala
index 591e2fa..25c17af 100644
--- a/vala/valasliceexpression.vala
+++ b/vala/valasliceexpression.vala
@@ -182,10 +182,4 @@ public class Vala.SliceExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- container.get_used_variables (collection);
- start.get_used_variables (collection);
- stop.get_used_variables (collection);
- }
}
diff --git a/vala/valathrowstatement.vala b/vala/valathrowstatement.vala
index ab0328c..cd838d2 100644
--- a/vala/valathrowstatement.vala
+++ b/vala/valathrowstatement.vala
@@ -122,8 +122,4 @@ public class Vala.ThrowStatement : BaseStatement {
codegen.visit_throw_statement (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- error_expression.get_used_variables (collection);
- }
}
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index e5a9eab..6402e50 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -253,12 +253,6 @@ public class Vala.UnaryExpression : Expression {
codegen.visit_expression (this);
}
-
- public override void get_used_variables (Collection<Variable> collection) {
- if (operator != UnaryOperator.OUT) {
- inner.get_used_variables (collection);
- }
- }
}
public enum Vala.UnaryOperator {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]