[vala/wip/transform: 66/102] Convert get_used_variables to TraverseVisitor
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 66/102] Convert get_used_variables to TraverseVisitor
- Date: Tue, 23 Oct 2018 20:47:34 +0000 (UTC)
commit efbb3af77070e82d59e1290ea8a1134dd2916f87
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 d3aebc9dc..8ee57db6f 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -301,14 +301,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 10e980250..898b099ca 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -513,17 +513,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 0a5b45873..1eef9514c 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -433,11 +433,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 70ea95ef5..e4cd825d8 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -202,10 +202,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 41e2042a8..b3dfac7fd 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -341,14 +341,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) {
@@ -412,7 +414,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 78608388f..fc139a48a 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -126,12 +126,6 @@ public class Vala.ConditionalExpression : Expression {
}
}
- 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 bool check (CodeContext context) {
if (checked) {
return !error;
diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala
index de58207e1..63acc78cc 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 cc9e53829..bf3b3cbb8 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -260,11 +260,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 82d18f828..ba747f99b 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 ec4315e0b..63fdeb1ab 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -258,10 +258,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 5e8fcee07..45eb6c330 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -246,11 +246,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 4dc6a3ec7..33327ee22 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -916,17 +916,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 436423aa5..cd58024f3 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 cacb5936e..22763e4a6 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -637,14 +637,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 5b57c1306..3ee9156fd 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 3340d009e..57a0611dd 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -508,14 +508,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 5989f8d66..f314711b3 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -115,10 +115,6 @@ public class Vala.PointerIndirection : Expression {
codegen.visit_expression (this);
}
- public override void get_used_variables (Collection<Variable> collection) {
- inner.get_used_variables (collection);
- }
-
public override string to_string () {
return "(*%s)".printf (inner.to_string ());
}
diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala
index 4f4efdf44..cce7cbf49 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 6db0a88d9..1e4f72078 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -121,17 +121,6 @@ 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);
- }
- }
-
public override string to_string () {
return "(owned) %s".printf (inner.to_string ());
}
diff --git a/vala/valareturnstatement.vala b/vala/valareturnstatement.vala
index eef419857..241603141 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 591e2fafb..25c17af30 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 b7bb08b24..eb0200d89 100644
--- a/vala/valathrowstatement.vala
+++ b/vala/valathrowstatement.vala
@@ -128,8 +128,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 4cc7ea1b7..7c51d03eb 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]