[vala/wip/transform: 59/63] Added TraverseVisitor for traversing the tree with a callback



commit 14c540db50d58e052e517b558f8e5733c8b88300
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Oct 27 17:11:40 2012 +0200

    Added TraverseVisitor for traversing the tree with a callback
    
    This will allow cleaning up virtual methods of code nodes
    and more stateful to stateless code conversion.

 vala/Makefile.am                          |    1 +
 vala/valaassignment.vala                  |   12 -
 vala/valabinaryexpression.vala            |    5 -
 vala/valacastexpression.vala              |    4 -
 vala/valacatchclause.vala                 |    6 -
 vala/valacodenode.vala                    |   73 ++++++-
 vala/valaconditionalexpression.vala       |    6 -
 vala/valadeclarationstatement.vala        |   13 --
 vala/valaelementaccess.vala               |    7 -
 vala/valaexpressionstatement.vala         |    4 -
 vala/valaforeachstatement.vala            |    4 -
 vala/valamemberaccess.vala                |    6 -
 vala/valamethod.vala                      |    8 -
 vala/valamethodcall.vala                  |    8 -
 vala/valanamedargument.vala               |    4 -
 vala/valaobjectcreationexpression.vala    |    6 -
 vala/valapointerindirection.vala          |    4 -
 vala/valapostfixexpression.vala           |   11 -
 vala/valareferencetransferexpression.vala |   11 -
 vala/valareturnstatement.vala             |    6 -
 vala/valasliceexpression.vala             |    6 -
 vala/valathrowstatement.vala              |    4 -
 vala/valatraversevisitor.vala             |  333 +++++++++++++++++++++++++++++
 vala/valaunaryexpression.vala             |   14 --
 24 files changed, 406 insertions(+), 150 deletions(-)
---
diff --git a/vala/Makefile.am b/vala/Makefile.am
index 61a45d8..c917a2f 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -145,6 +145,7 @@ libvalacore_la_VALASOURCES = \
 	valatemplate.vala \
 	valathrowstatement.vala \
 	valatokentype.vala \
+	valatraversevisitor.vala \
 	valatrystatement.vala \
 	valatuple.vala \
 	valatypecheck.vala \
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index f5ba935..16b56d7 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -563,18 +563,6 @@ public class Vala.Assignment : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		right.get_defined_variables (collection);
-		left.get_defined_variables (collection);
-		var local = left.symbol_reference as LocalVariable;
-		var param = left.symbol_reference as Parameter;
-		if (local != null) {
-			collection.add (local);
-		} else if (param != null && param.direction == ParameterDirection.OUT) {
-			collection.add (param);
-		}
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		var ma = left as MemberAccess;
 		var ea = left as ElementAccess;
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 8a81e6c..e8ba1f6 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -398,11 +398,6 @@ public class Vala.BinaryExpression : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		left.get_defined_variables (collection);
-		right.get_defined_variables (collection);
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		left.get_used_variables (collection);
 		right.get_used_variables (collection);
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index 8bca197..4a3b173 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_defined_variables (Collection<Variable> collection) {
-		inner.get_defined_variables (collection);
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		inner.get_used_variables (collection);
 	}
diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala
index cda2747..f15e1f5 100644
--- a/vala/valacatchclause.vala
+++ b/vala/valacatchclause.vala
@@ -143,10 +143,4 @@ public class Vala.CatchClause : CodeNode {
 
 		codegen.visit_catch_clause (this);
 	}
-
-	public override void get_defined_variables (Collection<Variable> collection) {
-		if (error_variable != null) {
-			collection.add (error_variable);
-		}
-	}
 }
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 2452e3f..4432b5b 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -344,7 +344,78 @@ public abstract class Vala.CodeNode {
 		return str.append (" */").str;
 	}
 
-	public virtual void get_defined_variables (Collection<Variable> collection) {
+	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;
+					if (local != null) {
+						collection.add (local);
+					} else if (param != null && param.direction == ParameterDirection.OUT) {
+						collection.add (param);
+					}
+				} else if (n is CatchClause) {
+					var clause = (CatchClause) n;
+					if (clause.error_variable != null) {
+						collection.add (clause.error_variable);
+					}
+					return TraverseStatus.STOP;
+				} else if (n is DeclarationStatement) {
+					var stmt = (DeclarationStatement) n;
+					var local = stmt.declaration as LocalVariable;
+					if (local != null) {
+						var array_type = local.variable_type as ArrayType;
+						if (local.initializer != null || (array_type != null && array_type.fixed_length)) {
+							collection.add (local);
+						}
+					}
+				} else if (n is ForeachStatement) {
+					var stmt = (ForeachStatement) n;
+					collection.add (stmt.element_variable);
+					return TraverseStatus.STOP;
+				} else if (n is Method) {
+					var m = (Method) n;
+					// capturing variables is only supported if they are initialized
+					// therefore assume that captured variables are initialized
+					if (m.closure) {
+						m.get_captured_variables ((Collection<LocalVariable>) collection);
+					}
+					return TraverseStatus.STOP;
+				} else if (n is PostfixExpression) {
+					var expr = (PostfixExpression) 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 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 || expr.operator == UnaryOperator.REF) {
+						var local = expr.inner.symbol_reference as LocalVariable;
+						var param = expr.inner.symbol_reference as Parameter;
+						if (local != null) {
+							collection.add (local);
+						}
+						if (param != null && param.direction == ParameterDirection.OUT) {
+							collection.add (param);
+						}
+					}
+				}
+				return TraverseStatus.CONTINUE;
+			});
+		accept (traverse);
 	}
 
 	public virtual void get_used_variables (Collection<Variable> collection) {
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 9512b06..6c7533e 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_defined_variables (Collection<Variable> collection) {
-		condition.get_defined_variables (collection);
-		true_expression.get_defined_variables (collection);
-		false_expression.get_defined_variables (collection);
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		condition.get_used_variables (collection);
 		true_expression.get_used_variables (collection);
diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala
index 8b3ce75..6a1b01e 100644
--- a/vala/valadeclarationstatement.vala
+++ b/vala/valadeclarationstatement.vala
@@ -88,19 +88,6 @@ public class Vala.DeclarationStatement : BaseStatement {
 		codegen.visit_declaration_statement (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		var local = declaration as LocalVariable;
-		if (local != null) {
-			var array_type = local.variable_type as ArrayType;
-			if (local.initializer != null) {
-				local.initializer.get_defined_variables (collection);
-				collection.add (local);
-			} else if (array_type != null && array_type.fixed_length) {
-				collection.add (local);
-			}
-		}
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		var local = declaration as LocalVariable;
 		if (local != null && local.initializer != null) {
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 1cfaf81..0db3c20 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -235,13 +235,6 @@ public class Vala.ElementAccess : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		container.get_defined_variables (collection);
-		foreach (Expression index in indices) {
-			index.get_defined_variables (collection);
-		}
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		container.get_used_variables (collection);
 		foreach (Expression index in indices) {
diff --git a/vala/valaexpressionstatement.vala b/vala/valaexpressionstatement.vala
index 7dc1534..a0c703c 100644
--- a/vala/valaexpressionstatement.vala
+++ b/vala/valaexpressionstatement.vala
@@ -93,10 +93,6 @@ public class Vala.ExpressionStatement : BaseStatement {
 		codegen.visit_expression_statement (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		expression.get_defined_variables (collection);
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		expression.get_used_variables (collection);
 	}
diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala
index 10f4568..20024c6 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -328,10 +328,6 @@ public class Vala.ForeachStatement : BaseStatement {
 
 		codegen.visit_foreach_statement (this);
 	}
-
-	public override void get_defined_variables (Collection<Variable> collection) {
-		collection.add (element_variable);
-	}
 }
 
 public enum Vala.ForeachIteration {
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 704115e..7d9ed32 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -908,12 +908,6 @@ public class Vala.MemberAccess : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		if (inner != null) {
-			inner.get_defined_variables (collection);
-		}
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		if (inner != null) {
 			inner.get_used_variables (collection);
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 895f508..8713b9c 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -962,14 +962,6 @@ public class Vala.Method : Subroutine {
 			}
 		}
 	}
-
-	public override void get_defined_variables (Collection<Variable> collection) {
-		// capturing variables is only supported if they are initialized
-		// therefore assume that captured variables are initialized
-		if (closure) {
-			get_captured_variables ((Collection<LocalVariable>) collection);
-		}
-	}
 }
 
 // vim:sw=8 noet
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 4d8a11d..a6f344a 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -744,14 +744,6 @@ public class Vala.MethodCall : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		call.get_defined_variables (collection);
-
-		foreach (Expression arg in argument_list) {
-			arg.get_defined_variables (collection);
-		}
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		call.get_used_variables (collection);
 
diff --git a/vala/valanamedargument.vala b/vala/valanamedargument.vala
index 4c3e23b..5b57c13 100644
--- a/vala/valanamedargument.vala
+++ b/vala/valanamedargument.vala
@@ -89,10 +89,6 @@ public class Vala.NamedArgument : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		inner.get_defined_variables (collection);
-	}
-
 	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 94549b0..78d68b2 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -428,12 +428,6 @@ public class Vala.ObjectCreationExpression : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		foreach (Expression arg in argument_list) {
-			arg.get_defined_variables (collection);
-		}
-	}
-
 	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 61f7f99..1b5eca7 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -107,10 +107,6 @@ public class Vala.PointerIndirection : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		inner.get_defined_variables (collection);
-	}
-
 	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 2ccc0e6..9ec2284 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -72,17 +72,6 @@ public class Vala.PostfixExpression : Expression {
 		return false;
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		inner.get_defined_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 void get_used_variables (Collection<Variable> collection) {
 		inner.get_used_variables (collection);
 	}
diff --git a/vala/valareferencetransferexpression.vala b/vala/valareferencetransferexpression.vala
index cd2f154..15195bb 100644
--- a/vala/valareferencetransferexpression.vala
+++ b/vala/valareferencetransferexpression.vala
@@ -115,17 +115,6 @@ public class Vala.ReferenceTransferExpression : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		inner.get_defined_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 void get_used_variables (Collection<Variable> collection) {
 		inner.get_used_variables (collection);
 		var local = inner.symbol_reference as LocalVariable;
diff --git a/vala/valareturnstatement.vala b/vala/valareturnstatement.vala
index 219f6d9..59236e7 100644
--- a/vala/valareturnstatement.vala
+++ b/vala/valareturnstatement.vala
@@ -159,12 +159,6 @@ public class Vala.ReturnStatement : BaseStatement {
 		codegen.visit_return_statement (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		if (return_expression != null) {
-			return_expression.get_defined_variables (collection);
-		}
-	}
-
 	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 7b741a3..4f50904 100644
--- a/vala/valasliceexpression.vala
+++ b/vala/valasliceexpression.vala
@@ -174,12 +174,6 @@ public class Vala.SliceExpression : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		container.get_defined_variables (collection);
-		start.get_defined_variables (collection);
-		stop.get_defined_variables (collection);
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		container.get_used_variables (collection);
 		start.get_used_variables (collection);
diff --git a/vala/valathrowstatement.vala b/vala/valathrowstatement.vala
index 32275f3..ab0328c 100644
--- a/vala/valathrowstatement.vala
+++ b/vala/valathrowstatement.vala
@@ -123,10 +123,6 @@ public class Vala.ThrowStatement : BaseStatement {
 		codegen.visit_throw_statement (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		error_expression.get_defined_variables (collection);
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		error_expression.get_used_variables (collection);
 	}
diff --git a/vala/valatraversevisitor.vala b/vala/valatraversevisitor.vala
new file mode 100644
index 0000000..37c85ec
--- /dev/null
+++ b/vala/valatraversevisitor.vala
@@ -0,0 +1,333 @@
+/* valatraversevisitor.vala
+ *
+ * Copyright (C) 2012  Luca Bruno
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ * 	Luca Bruno <lucabru src gnome org>
+ */
+
+/**
+ * Code visitor for traversing the tree with a simple callback
+ */
+public class Vala.TraverseVisitor : CodeVisitor {
+	private TraverseFunc func;
+
+	public TraverseVisitor (owned TraverseFunc func) {
+		this.func = (owned) func;
+	}
+
+	public override void visit_namespace (Namespace ns) {
+		if (func (ns) == TraverseStatus.CONTINUE) {
+			ns.accept_children (this);
+		}
+	}
+
+	public override void visit_class (Class cl) {
+		if (func (cl) == TraverseStatus.CONTINUE) {
+			cl.accept_children (this);
+		}
+	}
+
+	public override void visit_struct (Struct st) {
+		if (func (st) == TraverseStatus.CONTINUE) {
+			st.accept_children (this);
+		}
+	}
+
+	public override void visit_interface (Interface iface) {
+		if (func (iface) == TraverseStatus.CONTINUE) {
+			iface.accept_children (this);
+		}
+	}
+
+	public override void visit_enum (Enum en) {
+		if (func (en) == TraverseStatus.CONTINUE) {
+			en.accept_children (this);
+		}
+	}
+
+	public override void visit_enum_value (EnumValue ev) {
+		if (func (ev) == TraverseStatus.CONTINUE) {
+			ev.accept_children (this);
+		}
+	}
+
+	public override void visit_error_domain (ErrorDomain edomain) {
+		if (func (edomain) == TraverseStatus.CONTINUE) {
+			edomain.accept_children (this);
+		}
+	}
+
+	public override void visit_error_code (ErrorCode ecode) {
+		if (func (ecode) == TraverseStatus.CONTINUE) {
+			ecode.accept_children (this);
+		}
+	}
+
+	public override void visit_delegate (Delegate d) {
+		if (func (d) == TraverseStatus.CONTINUE) {
+			d.accept_children (this);
+		}
+	}
+
+	public override void visit_constant (Constant c) {
+		if (func (c) == TraverseStatus.CONTINUE) {
+			c.accept_children (this);
+		}
+	}
+
+	public override void visit_field (Field f) {
+		if (func (f) == TraverseStatus.CONTINUE) {
+			f.accept_children (this);
+		}
+	}
+
+	public override void visit_method (Method m) {
+		if (func (m) == TraverseStatus.CONTINUE) {
+			m.accept_children (this);
+		}
+	}
+
+	public override void visit_creation_method (CreationMethod m) {
+		if (func (m) == TraverseStatus.CONTINUE) {
+			m.accept_children (this);
+		}
+	}
+
+	public override void visit_formal_parameter (Parameter p) {
+		if (func (p) == TraverseStatus.CONTINUE) {
+			p.accept_children (this);
+		}
+	}
+
+	public override void visit_property (Property prop) {
+		if (func (prop) == TraverseStatus.CONTINUE) {
+			prop.accept_children (this);
+		}
+	}
+
+	public override void visit_property_accessor (PropertyAccessor acc) {
+		if (func (acc) == TraverseStatus.CONTINUE) {
+			acc.accept_children (this);
+		}
+	}
+
+	public override void visit_signal (Signal sig) {
+		if (func (sig) == TraverseStatus.CONTINUE) {
+			sig.accept_children (this);
+		}
+	}
+
+	public override void visit_constructor (Constructor c) {
+		if (func (c) == TraverseStatus.CONTINUE) {
+			c.accept_children (this);
+		}
+	}
+
+	public override void visit_destructor (Destructor d) {
+		if (func (d) == TraverseStatus.CONTINUE) {
+			d.accept_children (this);
+		}
+	}
+
+	public override void visit_block (Block b) {
+		if (func (b) == TraverseStatus.CONTINUE) {
+			b.accept_children (this);
+		}
+	}
+
+	public override void visit_declaration_statement (DeclarationStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_local_variable (LocalVariable local) {
+		if (func (local) == TraverseStatus.CONTINUE) {
+			local.accept_children (this);
+		}
+	}
+
+	public override void visit_initializer_list (InitializerList list) {
+		if (func (list) == TraverseStatus.CONTINUE) {
+			list.accept_children (this);
+		}
+	}
+
+	public override void visit_expression_statement (ExpressionStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_if_statement (IfStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_switch_statement (SwitchStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_switch_section (SwitchSection section) {
+		if (func (section) == TraverseStatus.CONTINUE) {
+			section.accept_children (this);
+		}
+	}
+
+	public override void visit_switch_label (SwitchLabel label) {
+		if (func (label) == TraverseStatus.CONTINUE) {
+			label.accept_children (this);
+		}
+	}
+
+	public override void visit_loop (Loop loop) {
+		if (func (loop) == TraverseStatus.CONTINUE) {
+			loop.accept_children (this);
+		}
+	}
+
+	public override void visit_while_statement (WhileStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_do_statement (DoStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_for_statement (ForStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_foreach_statement (ForeachStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_break_statement (BreakStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_continue_statement (ContinueStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_return_statement (ReturnStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_yield_statement (YieldStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_throw_statement (ThrowStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_try_statement (TryStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_catch_clause (CatchClause clause) {
+		if (func (clause) == TraverseStatus.CONTINUE) {
+			clause.accept_children (this);
+		}
+	}
+
+	public override void visit_lock_statement (LockStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_unlock_statement (UnlockStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_delete_statement (DeleteStatement stmt) {
+		if (func (stmt) == TraverseStatus.CONTINUE) {
+			stmt.accept_children (this);
+		}
+	}
+
+	public override void visit_expression (Expression expr) {
+		if (func (expr) == TraverseStatus.CONTINUE) {
+			expr.accept_children (this);
+		}
+	}
+
+	public override void visit_method_call (MethodCall expr) {
+		if (func (expr) == TraverseStatus.CONTINUE) {
+			expr.accept_children (this);
+		}
+	}
+
+	public override void visit_conditional_expression (ConditionalExpression expr) {
+		if (func (expr) == TraverseStatus.CONTINUE) {
+			expr.accept_children (this);
+		}
+	}
+
+	public override void visit_binary_expression (BinaryExpression expr) {
+		if (func (expr) == TraverseStatus.CONTINUE) {
+			expr.accept_children (this);
+		}
+	}
+
+	public override void visit_unary_expression (UnaryExpression expr) {
+		if (func (expr) == TraverseStatus.CONTINUE) {
+			expr.accept_children (this);
+		}
+	}
+
+	public override void visit_object_creation_expression (ObjectCreationExpression expr) {
+		if (func (expr) == TraverseStatus.CONTINUE) {
+			expr.accept_children (this);
+		}
+	}
+}
+
+public enum Vala.TraverseStatus {
+	STOP,
+	CONTINUE
+}
+
+public delegate Vala.TraverseStatus Vala.TraverseFunc (CodeNode node);
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index f090b97..ef83972 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -246,20 +246,6 @@ public class Vala.UnaryExpression : Expression {
 		codegen.visit_expression (this);
 	}
 
-	public override void get_defined_variables (Collection<Variable> collection) {
-		inner.get_defined_variables (collection);
-		if (operator == UnaryOperator.OUT || operator == UnaryOperator.REF) {
-			var local = inner.symbol_reference as LocalVariable;
-			var param = inner.symbol_reference as Parameter;
-			if (local != null) {
-				collection.add (local);
-			}
-			if (param != null && param.direction == ParameterDirection.OUT) {
-				collection.add (param);
-			}
-		}
-	}
-
 	public override void get_used_variables (Collection<Variable> collection) {
 		if (operator != UnaryOperator.OUT) {
 			inner.get_used_variables (collection);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]