[vala/wip/transform: 60/63] Convert get_used_variables to TraverseVisitor
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 60/63] Convert get_used_variables to TraverseVisitor
- Date: Sat, 27 Oct 2012 18:11:37 +0000 (UTC)
commit d1eaff5ddcb8f63ba03460b1653b1df3725dea84
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Oct 27 18:22:49 2012 +0200
Convert get_used_variables to TraverseVisitor
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/valalambdaexpression.vala | 7 ---
vala/valamemberaccess.vala | 13 ------
vala/valamethodcall.vala | 8 ----
vala/valanamedargument.vala | 4 --
vala/valaobjectcreationexpression.vala | 6 ---
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 ---
20 files changed, 55 insertions(+), 127 deletions(-)
---
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 16b56d7..5af5b12 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -562,17 +562,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 e8ba1f6..a64c074 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -397,11 +397,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 4a3b173..99d6743 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -184,10 +184,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 4432b5b..3c155ca 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 6c7533e..e9c809a 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -100,12 +100,6 @@ public class Vala.ConditionalExpression : Expression {
return condition.is_pure () && true_expression.is_pure () && false_expression.is_pure ();
}
- 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 6a1b01e..d75f11e 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 0db3c20..e045352 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -234,11 +234,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 a0c703c..89d74fe 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/valalambdaexpression.vala b/vala/valalambdaexpression.vala
index cb5ba65..a18c5ec 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -243,11 +243,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 7d9ed32..1161b4a 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -907,17 +907,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/valamethodcall.vala b/vala/valamethodcall.vala
index a6f344a..32e346f 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -743,12 +743,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 78d68b2..fbe870b 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -427,10 +427,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);
- }
- }
}
diff --git a/vala/valapointerindirection.vala b/vala/valapointerindirection.vala
index 1b5eca7..4cefaf1 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -106,8 +106,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 9ec2284..947044d 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -72,10 +72,6 @@ public class Vala.PostfixExpression : Expression {
return false;
}
- 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 15195bb..b796253 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -114,15 +114,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 4f50904..c96a50e 100644
--- a/vala/valasliceexpression.vala
+++ b/vala/valasliceexpression.vala
@@ -173,10 +173,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 ef83972..6033964 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -245,12 +245,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]