From: Juerg Billeter Date: Mon, 17 Sep 2007 18:22:42 +0000 (+0000) Subject: switch block to external visitor X-Git-Tag: VALA_0_1_4~36 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b906cd7c6d906854564cdb09035a46e687d0215;p=thirdparty%2Fvala.git switch block to external visitor 2007-09-17 Juerg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index eec4b2f36..192349910 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-09-17 Jürg Billeter + + * 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 * vala/valaassignment.vala, vala/valacodevisitor.vala, diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 82b3f823a..7bcc9d411 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -750,11 +750,11 @@ public class Vala.CodeGenerator : CodeVisitor { d.accept_children (this); } - public override void visit_begin_block (Block! b) { + public override void visit_block (Block! b) { current_symbol = b; - } - public override void visit_end_block (Block! b) { + b.accept_children (this); + var local_vars = b.get_local_variables (); foreach (VariableDeclarator decl in local_vars) { decl.active = false; @@ -1428,6 +1428,10 @@ public class Vala.CodeGenerator : CodeVisitor { cswitchblock.append (ctopstmt); } + public override void visit_switch_section (SwitchSection! section) { + visit_block (section); + } + public override void visit_while_statement (WhileStatement! stmt) { stmt.ccodenode = new CCodeWhileStatement ((CCodeExpression) stmt.condition.ccodenode, (CCodeStatement) stmt.body.ccodenode); @@ -1457,15 +1461,15 @@ public class Vala.CodeGenerator : CodeVisitor { 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.collection_variable_declarator.active = true; if (stmt.iterator_variable_declarator != null) { stmt.iterator_variable_declarator.active = true; } - } - public override void visit_end_foreach_statement (ForeachStatement! stmt) { + visit_block (stmt); + var cblock = new CCodeBlock (); // sets #line stmt.ccodenode = cblock; diff --git a/vala/valablock.vala b/vala/valablock.vala index 307990b54..ace09212b 100644 --- a/vala/valablock.vala +++ b/vala/valablock.vala @@ -79,14 +79,14 @@ public class Vala.Block : Symbol, Statement { public Collection get_local_variables () { return new ReadOnlyCollection (local_variables); } - + 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) { stmt.accept (visitor); } - - visitor.visit_end_block (this); } } diff --git a/vala/valacodevisitor.vala b/vala/valacodevisitor.vala index 9864bec1a..557528572 100644 --- a/vala/valacodevisitor.vala +++ b/vala/valacodevisitor.vala @@ -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 */ - public virtual void visit_begin_block (Block! b) { - } - - /** - * Visit operation called at end of blocks. - * - * @param b a block - */ - public virtual void visit_end_block (Block! b) { + public virtual void visit_block (Block! b) { } /** @@ -332,19 +324,11 @@ public abstract class Vala.CodeVisitor : Object { } /** - * Visit operation called at beginning of foreach statements. - * - * @param stmt a foreach statement - */ - public virtual void visit_begin_foreach_statement (ForeachStatement! stmt) { - } - - /** - * Visit operation called at end of foreach statements. + * Visit operation called for foreach statements. * * @param stmt a foreach statement */ - public virtual void visit_end_foreach_statement (ForeachStatement! stmt) { + public virtual void visit_foreach_statement (ForeachStatement! stmt) { } /** diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala index 7bddf440b..5e2ba1192 100644 --- a/vala/valaforeachstatement.vala +++ b/vala/valaforeachstatement.vala @@ -94,20 +94,16 @@ public class Vala.ForeachStatement : Block { } public override void accept (CodeVisitor! visitor) { - visitor.visit_begin_foreach_statement (this); - - visitor.visit_begin_block (this); + visitor.visit_foreach_statement (this); + } + public override void accept_children (CodeVisitor! visitor) { type_reference.accept (visitor); collection.accept (visitor); visitor.visit_end_full_expression (collection); body.accept (visitor); - - visitor.visit_end_block (this); - - visitor.visit_end_foreach_statement (this); } public override void replace (CodeNode! old_node, CodeNode! new_node) { diff --git a/vala/valamemorymanager.vala b/vala/valamemorymanager.vala index 9aea73ce4..58884d8ea 100644 --- a/vala/valamemorymanager.vala +++ b/vala/valamemorymanager.vala @@ -125,6 +125,10 @@ public class Vala.MemoryManager : CodeVisitor { 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) { decl.accept_children (this); @@ -145,6 +149,14 @@ public class Vala.MemoryManager : CodeVisitor { 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) { if (stmt.return_expression != null) { if (current_symbol is Method) { diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 1729dc579..004e5f90c 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -634,12 +634,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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; current_symbol = b; - } - public override void visit_end_block (Block! b) { + b.accept_children (this); + foreach (VariableDeclarator decl in b.get_local_variables ()) { decl.active = false; } @@ -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) { if (stmt.condition.error) { /* if there was an error in the condition, skip this check */ @@ -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) { current_source_file.add_symbol_dependency (stmt.type_reference.data_type, SourceFileDependencyType.SOURCE); } @@ -869,9 +888,18 @@ public class Vala.SemanticAnalyzer : CodeVisitor { stmt.body.add_local_variable (stmt.variable_declarator); 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) { // ignore inner error stmt.error = true; diff --git a/vala/valaswitchsection.vala b/vala/valaswitchsection.vala index 530b2a47c..08f1314f5 100644 --- a/vala/valaswitchsection.vala +++ b/vala/valaswitchsection.vala @@ -86,17 +86,16 @@ public class Vala.SwitchSection : Block { } public override void accept (CodeVisitor! visitor) { + visitor.visit_switch_section (this); + } + + public override void accept_children (CodeVisitor! visitor) { foreach (SwitchLabel label in labels) { label.accept (visitor); } - visitor.visit_begin_block (this); - foreach (Statement st in statement_list) { st.accept (visitor); } - - visitor.visit_switch_section (this); - visitor.visit_end_block (this); } } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index bc8d4e1a6..24f059e47 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -167,6 +167,10 @@ public class Vala.SymbolResolver : CodeVisitor { d.accept_children (this); } + public override void visit_block (Block! b) { + b.accept_children (this); + } + public override void visit_namespace_reference (NamespaceReference! ns) { ns.namespace_symbol = current_scope.lookup (ns.name); if (ns.namespace_symbol == null) { @@ -303,6 +307,14 @@ public class Vala.SymbolResolver : CodeVisitor { 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) { stmt.accept_children (this); }