switch block to external visitor
authorJuerg Billeter <j@bitron.ch>
Mon, 17 Sep 2007 18:22:42 +0000 (18:22 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 17 Sep 2007 18:22:42 +0000 (18:22 +0000)
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

ChangeLog
gobject/valacodegenerator.vala
vala/valablock.vala
vala/valacodevisitor.vala
vala/valaforeachstatement.vala
vala/valamemorymanager.vala
vala/valasemanticanalyzer.vala
vala/valaswitchsection.vala
vala/valasymbolresolver.vala

index eec4b2f..1923499 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 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>
+
        * vala/valaassignment.vala, vala/valacodevisitor.vala,
          vala/valamemorymanager.vala, vala/valasemanticanalyzer.vala,
          vala/valasymbolresolver.vala,
index 82b3f82..7bcc9d4 100644 (file)
@@ -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;
index 307990b..ace0921 100644 (file)
@@ -79,14 +79,14 @@ public class Vala.Block : Symbol, Statement {
        public Collection<VariableDeclarator> get_local_variables () {
                return new ReadOnlyCollection<VariableDeclarator> (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);
        }
 }
index 9864bec..5575285 100644 (file)
@@ -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) {
        }
 
        /**
index 7bddf44..5e2ba11 100644 (file)
@@ -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) {
index 9aea73c..58884d8 100644 (file)
@@ -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) {
index 1729dc5..004e5f9 100644 (file)
@@ -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;
index 530b2a4..08f1314 100644 (file)
@@ -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);
        }
 }
index bc8d4e1..24f059e 100644 (file)
@@ -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);
        }