Commit 6b906cd7 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

switch block to external visitor

2007-09-17  Juerg Billeter  <j@bitron.ch>

	* vala/valablock.vala, vala/valacodevisitor.vala,
	  vala/valaforeachstatement.vala, vala/valamemorymanager.vala,
	  vala/valasemanticanalyzer.vala, vala/valaswitchsection.vala,
	  vala/valasymbolresolver.vala, gobject/valacodegenerator.vala: switch
	  block to external visitor

svn path=/trunk/; revision=612
parent 2d67e9ce
2007-09-17 Jürg Billeter <j@bitron.ch>
* vala/valablock.vala, vala/valacodevisitor.vala,
vala/valaforeachstatement.vala, vala/valamemorymanager.vala,
vala/valasemanticanalyzer.vala, vala/valaswitchsection.vala,
vala/valasymbolresolver.vala, gobject/valacodegenerator.vala: switch
block to external visitor
2007-09-17 Jürg Billeter <j@bitron.ch> 2007-09-17 Jürg Billeter <j@bitron.ch>
* vala/valaassignment.vala, vala/valacodevisitor.vala, * vala/valaassignment.vala, vala/valacodevisitor.vala,
......
...@@ -750,11 +750,11 @@ public class Vala.CodeGenerator : CodeVisitor { ...@@ -750,11 +750,11 @@ public class Vala.CodeGenerator : CodeVisitor {
d.accept_children (this); d.accept_children (this);
} }
public override void visit_begin_block (Block! b) { public override void visit_block (Block! b) {
current_symbol = b; current_symbol = b;
}
public override void visit_end_block (Block! b) { b.accept_children (this);
var local_vars = b.get_local_variables (); var local_vars = b.get_local_variables ();
foreach (VariableDeclarator decl in local_vars) { foreach (VariableDeclarator decl in local_vars) {
decl.active = false; decl.active = false;
...@@ -1428,6 +1428,10 @@ public class Vala.CodeGenerator : CodeVisitor { ...@@ -1428,6 +1428,10 @@ public class Vala.CodeGenerator : CodeVisitor {
cswitchblock.append (ctopstmt); cswitchblock.append (ctopstmt);
} }
public override void visit_switch_section (SwitchSection! section) {
visit_block (section);
}
public override void visit_while_statement (WhileStatement! stmt) { public override void visit_while_statement (WhileStatement! stmt) {
stmt.ccodenode = new CCodeWhileStatement ((CCodeExpression) stmt.condition.ccodenode, (CCodeStatement) stmt.body.ccodenode); stmt.ccodenode = new CCodeWhileStatement ((CCodeExpression) stmt.condition.ccodenode, (CCodeStatement) stmt.body.ccodenode);
...@@ -1457,15 +1461,15 @@ public class Vala.CodeGenerator : CodeVisitor { ...@@ -1457,15 +1461,15 @@ public class Vala.CodeGenerator : CodeVisitor {
create_temp_decl (stmt, stmt.condition.temp_vars); create_temp_decl (stmt, stmt.condition.temp_vars);
} }
public override void visit_begin_foreach_statement (ForeachStatement! stmt) { public override void visit_foreach_statement (ForeachStatement! stmt) {
stmt.variable_declarator.active = true; stmt.variable_declarator.active = true;
stmt.collection_variable_declarator.active = true; stmt.collection_variable_declarator.active = true;
if (stmt.iterator_variable_declarator != null) { if (stmt.iterator_variable_declarator != null) {
stmt.iterator_variable_declarator.active = true; stmt.iterator_variable_declarator.active = true;
} }
}
public override void visit_end_foreach_statement (ForeachStatement! stmt) { visit_block (stmt);
var cblock = new CCodeBlock (); var cblock = new CCodeBlock ();
// sets #line // sets #line
stmt.ccodenode = cblock; stmt.ccodenode = cblock;
......
...@@ -79,14 +79,14 @@ public class Vala.Block : Symbol, Statement { ...@@ -79,14 +79,14 @@ public class Vala.Block : Symbol, Statement {
public Collection<VariableDeclarator> get_local_variables () { public Collection<VariableDeclarator> get_local_variables () {
return new ReadOnlyCollection<VariableDeclarator> (local_variables); return new ReadOnlyCollection<VariableDeclarator> (local_variables);
} }
public override void accept (CodeVisitor! visitor) { public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_block (this); visitor.visit_block (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (Statement! stmt in statement_list) { foreach (Statement! stmt in statement_list) {
stmt.accept (visitor); stmt.accept (visitor);
} }
visitor.visit_end_block (this);
} }
} }
...@@ -212,19 +212,11 @@ public abstract class Vala.CodeVisitor : Object { ...@@ -212,19 +212,11 @@ public abstract class Vala.CodeVisitor : Object {
} }
/** /**
* Visit operation called at beginning of blocks. * Visit operation called for blocks.
* *
* @param b a block * @param b a block
*/ */
public virtual void visit_begin_block (Block! b) { public virtual void visit_block (Block! b) {
}
/**
* Visit operation called at end of blocks.
*
* @param b a block
*/
public virtual void visit_end_block (Block! b) {
} }
/** /**
...@@ -332,19 +324,11 @@ public abstract class Vala.CodeVisitor : Object { ...@@ -332,19 +324,11 @@ public abstract class Vala.CodeVisitor : Object {
} }
/** /**
* Visit operation called at beginning of foreach statements. * Visit operation called for foreach statements.
*
* @param stmt a foreach statement
*/
public virtual void visit_begin_foreach_statement (ForeachStatement! stmt) {
}
/**
* Visit operation called at end of foreach statements.
* *
* @param stmt a foreach statement * @param stmt a foreach statement
*/ */
public virtual void visit_end_foreach_statement (ForeachStatement! stmt) { public virtual void visit_foreach_statement (ForeachStatement! stmt) {
} }
/** /**
......
...@@ -94,20 +94,16 @@ public class Vala.ForeachStatement : Block { ...@@ -94,20 +94,16 @@ public class Vala.ForeachStatement : Block {
} }
public override void accept (CodeVisitor! visitor) { public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_foreach_statement (this); visitor.visit_foreach_statement (this);
}
visitor.visit_begin_block (this);
public override void accept_children (CodeVisitor! visitor) {
type_reference.accept (visitor); type_reference.accept (visitor);
collection.accept (visitor); collection.accept (visitor);
visitor.visit_end_full_expression (collection); visitor.visit_end_full_expression (collection);
body.accept (visitor); body.accept (visitor);
visitor.visit_end_block (this);
visitor.visit_end_foreach_statement (this);
} }
public override void replace (CodeNode! old_node, CodeNode! new_node) { public override void replace (CodeNode! old_node, CodeNode! new_node) {
......
...@@ -125,6 +125,10 @@ public class Vala.MemoryManager : CodeVisitor { ...@@ -125,6 +125,10 @@ public class Vala.MemoryManager : CodeVisitor {
visit_possibly_leaked_expression (n.argument); visit_possibly_leaked_expression (n.argument);
} }
public override void visit_block (Block! b) {
b.accept_children (this);
}
public override void visit_variable_declarator (VariableDeclarator! decl) { public override void visit_variable_declarator (VariableDeclarator! decl) {
decl.accept_children (this); decl.accept_children (this);
...@@ -145,6 +149,14 @@ public class Vala.MemoryManager : CodeVisitor { ...@@ -145,6 +149,14 @@ public class Vala.MemoryManager : CodeVisitor {
visit_possibly_leaked_expression (stmt.expression); visit_possibly_leaked_expression (stmt.expression);
} }
public override void visit_switch_section (SwitchSection! section) {
section.accept_children (this);
}
public override void visit_foreach_statement (ForeachStatement! stmt) {
stmt.accept_children (this);
}
public override void visit_end_return_statement (ReturnStatement! stmt) { public override void visit_end_return_statement (ReturnStatement! stmt) {
if (stmt.return_expression != null) { if (stmt.return_expression != null) {
if (current_symbol is Method) { if (current_symbol is Method) {
......
...@@ -634,12 +634,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor { ...@@ -634,12 +634,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
public override void visit_named_argument (NamedArgument! n) { public override void visit_named_argument (NamedArgument! n) {
} }
public override void visit_begin_block (Block! b) { public override void visit_block (Block! b) {
b.owner = current_symbol.scope; b.owner = current_symbol.scope;
current_symbol = b; current_symbol = b;
}
public override void visit_end_block (Block! b) { b.accept_children (this);
foreach (VariableDeclarator decl in b.get_local_variables ()) { foreach (VariableDeclarator decl in b.get_local_variables ()) {
decl.active = false; decl.active = false;
} }
...@@ -829,6 +829,25 @@ public class Vala.SemanticAnalyzer : CodeVisitor { ...@@ -829,6 +829,25 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
} }
} }
public override void visit_switch_section (SwitchSection! section) {
foreach (SwitchLabel label in section.get_labels ()) {
label.accept (this);
}
section.owner = current_symbol.scope;
current_symbol = section;
foreach (Statement st in section.get_statements ()) {
st.accept (this);
}
foreach (VariableDeclarator decl in section.get_local_variables ()) {
decl.active = false;
}
current_symbol = current_symbol.parent_symbol;
}
public override void visit_while_statement (WhileStatement! stmt) { public override void visit_while_statement (WhileStatement! stmt) {
if (stmt.condition.error) { if (stmt.condition.error) {
/* if there was an error in the condition, skip this check */ /* if there was an error in the condition, skip this check */
...@@ -857,7 +876,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { ...@@ -857,7 +876,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
} }
} }
public override void visit_begin_foreach_statement (ForeachStatement! stmt) { public override void visit_foreach_statement (ForeachStatement! stmt) {
if (stmt.type_reference.data_type != null) { if (stmt.type_reference.data_type != null) {
current_source_file.add_symbol_dependency (stmt.type_reference.data_type, SourceFileDependencyType.SOURCE); current_source_file.add_symbol_dependency (stmt.type_reference.data_type, SourceFileDependencyType.SOURCE);
} }
...@@ -869,9 +888,18 @@ public class Vala.SemanticAnalyzer : CodeVisitor { ...@@ -869,9 +888,18 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
stmt.body.add_local_variable (stmt.variable_declarator); stmt.body.add_local_variable (stmt.variable_declarator);
stmt.variable_declarator.active = true; stmt.variable_declarator.active = true;
}
public override void visit_end_foreach_statement (ForeachStatement! stmt) { stmt.owner = current_symbol.scope;
current_symbol = stmt;
stmt.accept_children (this);
foreach (VariableDeclarator decl in stmt.get_local_variables ()) {
decl.active = false;
}
current_symbol = current_symbol.parent_symbol;
if (stmt.collection.error) { if (stmt.collection.error) {
// ignore inner error // ignore inner error
stmt.error = true; stmt.error = true;
......
...@@ -86,17 +86,16 @@ public class Vala.SwitchSection : Block { ...@@ -86,17 +86,16 @@ public class Vala.SwitchSection : Block {
} }
public override void accept (CodeVisitor! visitor) { public override void accept (CodeVisitor! visitor) {
visitor.visit_switch_section (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (SwitchLabel label in labels) { foreach (SwitchLabel label in labels) {
label.accept (visitor); label.accept (visitor);
} }
visitor.visit_begin_block (this);
foreach (Statement st in statement_list) { foreach (Statement st in statement_list) {
st.accept (visitor); st.accept (visitor);
} }
visitor.visit_switch_section (this);
visitor.visit_end_block (this);
} }
} }
...@@ -167,6 +167,10 @@ public class Vala.SymbolResolver : CodeVisitor { ...@@ -167,6 +167,10 @@ public class Vala.SymbolResolver : CodeVisitor {
d.accept_children (this); d.accept_children (this);
} }
public override void visit_block (Block! b) {
b.accept_children (this);
}
public override void visit_namespace_reference (NamespaceReference! ns) { public override void visit_namespace_reference (NamespaceReference! ns) {
ns.namespace_symbol = current_scope.lookup (ns.name); ns.namespace_symbol = current_scope.lookup (ns.name);
if (ns.namespace_symbol == null) { if (ns.namespace_symbol == null) {
...@@ -303,6 +307,14 @@ public class Vala.SymbolResolver : CodeVisitor { ...@@ -303,6 +307,14 @@ public class Vala.SymbolResolver : CodeVisitor {
list.accept_children (this); list.accept_children (this);
} }
public override void visit_switch_section (SwitchSection! section) {
section.accept_children (this);
}
public override void visit_foreach_statement (ForeachStatement! stmt) {
stmt.accept_children (this);
}
public override void visit_throw_statement (ThrowStatement! stmt) { public override void visit_throw_statement (ThrowStatement! stmt) {
stmt.accept_children (this); stmt.accept_children (this);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment