[vala/wip/transform: 102/139] Convert get_used_variables to TraverseVisitor
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 102/139] Convert get_used_variables to TraverseVisitor
- Date: Mon, 17 Oct 2016 20:14:05 +0000 (UTC)
commit 37f1f0cd7bab59dd27c5c2182d86bc082e13a7a9
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 d974919..855c074 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -401,11 +401,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 2d5509a..4fc4d38 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -188,10 +188,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 0e0918a..f5ea62e 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -104,12 +104,6 @@ public class Vala.ConditionalExpression : Expression {
return condition.is_accessible (sym) && true_expression.is_accessible (sym) &&
false_expression.is_accessible (sym);
}
- 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 2e5ee1b..d7e9b45 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -244,11 +244,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 7e5761b..d104e44 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -248,11 +248,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 c892d6c..69878db 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -918,17 +918,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 10c41b8..9fa8570 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -653,12 +653,4 @@ 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);
- }
- }
}
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 98357eb..955a7fa 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -467,14 +467,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 077c451..617fae8 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -110,8 +110,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 9f7055d..4586d41 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -249,12 +249,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]