]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
move iteration of source files and namespaces from accept to
authorJürg Billeter <j@bitron.ch>
Fri, 15 Jun 2007 10:25:33 +0000 (10:25 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 15 Jun 2007 10:25:33 +0000 (10:25 +0000)
2007-06-15  Jürg Billeter  <j@bitron.ch>

* vala/valaattributeprocessor.vala, vala/valacodevisitor.vala,
  vala/valainterfacewriter.vala, vala/valamemorymanager.vala,
  vala/valaparser.vala, vala/valasemanticanalyzer.vala,
  vala/valasourcefile.vala, vala/valasymbolbuilder.vala,
  vala/valasymbolresolver.vala, vala/valacodenode.vala,
  vala/valanamespace.vala, gobject/valacodegenerator.vala,
  gobject/valacodegeneratorsourcefile.vala, vapigen/valagidlparser.vala:
  move iteration of source files and namespaces from accept to
  accept_children method

svn path=/trunk/; revision=322

15 files changed:
ChangeLog
gobject/valacodegenerator.vala
gobject/valacodegeneratorsourcefile.vala
vala/valaattributeprocessor.vala
vala/valacodenode.vala
vala/valacodevisitor.vala
vala/valainterfacewriter.vala
vala/valamemorymanager.vala
vala/valanamespace.vala
vala/valaparser.vala
vala/valasemanticanalyzer.vala
vala/valasourcefile.vala
vala/valasymbolbuilder.vala
vala/valasymbolresolver.vala
vapigen/valagidlparser.vala

index fe615ba193b0259eafdd67c420d5cd3bca938cb7..202e9c129ddc3cd99b095d2ce9db0ba1fb054ff6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-06-15  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaattributeprocessor.vala, vala/valacodevisitor.vala,
+         vala/valainterfacewriter.vala, vala/valamemorymanager.vala,
+         vala/valaparser.vala, vala/valasemanticanalyzer.vala,
+         vala/valasourcefile.vala, vala/valasymbolbuilder.vala,
+         vala/valasymbolresolver.vala, vala/valacodenode.vala,
+         vala/valanamespace.vala, gobject/valacodegenerator.vala,
+         gobject/valacodegeneratorsourcefile.vala, vapigen/valagidlparser.vala:
+         move iteration of source files and namespaces from accept to
+         accept_children method
+
 2007-06-15  Jürg Billeter  <j@bitron.ch>
 
        * vala/valacodecontext.vala, gobject/valaccodecompiler.vala,
index 5b117219ba900d89c219391d6655b7f8484f63e8..e1791a9e74c0a74f6881fc57db38ee0bbba78e24 100644 (file)
@@ -254,6 +254,10 @@ public class Vala.CodeGenerator : CodeVisitor {
                }
        }
 
+       public override void visit_namespace (Namespace! ns) {
+               ns.accept_children (this);
+       }
+
        public override void visit_begin_enum (Enum! en) {
                cenum = new CCodeEnum (en.get_cname ());
 
index 7eb8b718a758bb4a8a3ee11d1dbc2e8644ac7ce5..f02a76d6dd4c6d039625580269aabce2fcf75d23 100644 (file)
@@ -28,7 +28,7 @@ public class Vala.CodeGenerator {
                return new CCodeIncludeDirective (filename, context.library == null);
        }
 
-       public override void visit_begin_source_file (SourceFile! source_file) {
+       public override void visit_source_file (SourceFile! source_file) {
                header_begin = new CCodeFragment ();
                header_type_declaration = new CCodeFragment ();
                header_type_definition = new CCodeFragment ();
@@ -104,29 +104,9 @@ public class Vala.CodeGenerator {
                /* generate hardcoded "well-known" macros */
                source_begin.append (new CCodeMacroReplacement ("VALA_FREE_CHECKED(o,f)", "((o) == NULL ? NULL : ((o) = (f (o), NULL)))"));
                source_begin.append (new CCodeMacroReplacement ("VALA_FREE_UNCHECKED(o,f)", "((o) = (f (o), NULL))"));
-       }
-       
-       private static ref string get_define_for_filename (string! filename) {
-               var define = new String ("__");
-               
-               var i = filename;
-               while (i.len () > 0) {
-                       var c = i.get_char ();
-                       if (c.isalnum  () && c < 0x80) {
-                               define.append_unichar (c.toupper ());
-                       } else {
-                               define.append_c ('_');
-                       }
-               
-                       i = i.next_char ();
-               }
-               
-               define.append ("__");
-               
-               return define.str;
-       }
-       
-       public override void visit_end_source_file (SourceFile! source_file) {
+
+               source_file.accept_children (this);
+
                var header_define = get_define_for_filename (source_file.get_cheader_filename ());
                
                if (string_h_needed) {
@@ -194,4 +174,24 @@ public class Vala.CodeGenerator {
                source_signal_marshaller_definition = null;
                source_signal_marshaller_declaration = null;
        }
+       
+       private static ref string get_define_for_filename (string! filename) {
+               var define = new String ("__");
+               
+               var i = filename;
+               while (i.len () > 0) {
+                       var c = i.get_char ();
+                       if (c.isalnum  () && c < 0x80) {
+                               define.append_unichar (c.toupper ());
+                       } else {
+                               define.append_c ('_');
+                       }
+               
+                       i = i.next_char ();
+               }
+               
+               define.append ("__");
+               
+               return define.str;
+       }
 }
index 2c4901f8f8fc1fdc8a8f34a30824c63e0413332a..9300718fe01c4086c5d6d8fccd38a5b4a6b64c3c 100644 (file)
@@ -36,8 +36,14 @@ public class Vala.AttributeProcessor : CodeVisitor {
                context.accept (this);
        }
 
-       public override void visit_begin_namespace (Namespace! ns) {
+       public override void visit_source_file (SourceFile! source_file) {
+               source_file.accept_children (this);
+       }
+
+       public override void visit_namespace (Namespace! ns) {
                ns.process_attributes ();
+
+               ns.accept_children (this);
        }
 
        public override void visit_begin_class (Class! cl) {
index 92df6fcb1bfb3155b14cca2a9249d9fc55733e6d..e5e187fca9bb91055e4bf752d76eb9085b9e6345 100644 (file)
@@ -74,17 +74,24 @@ public abstract class Vala.CodeNode {
        public bool error { get; set; }
 
        /**
-        * Visits this code node and all children with the specified
-        * CodeVisitor.
+        * Visits this code node with the specified CodeVisitor.
         *
         * @param visitor the visitor to be called while traversing
         */
        public virtual void accept (CodeVisitor! visitor) {
        }
-       
+
+       /**
+        * Visits all children of this code node with the specified CodeVisitor.
+        *
+        * @param visitor the visitor to be called while traversing
+        */
+       public virtual void accept_children (CodeVisitor! visitor) {
+       }
+
        public virtual void replace (CodeNode! old_node, CodeNode! new_node) {
        }
-       
+
        /**
         * Returns the specified attribute.
         *
index aa1e9ff6c7665cc9794454974bc3ba09453345bb..eab68f1b638817ef372e282c21d8368be82dbb3b 100644 (file)
@@ -28,35 +28,19 @@ using GLib;
  */
 public abstract class Vala.CodeVisitor {
        /**
-        * Visit operation called at beginning of source files.
+        * Visit operation called for source files.
         *
         * @param source_file a source file
         */
-       public virtual void visit_begin_source_file (SourceFile! source_file) {
+       public virtual void visit_source_file (SourceFile! source_file) {
        }
 
        /**
-        * Visit operation called at end of source files.
-        *
-        * @param source_file a source file
-        */
-       public virtual void visit_end_source_file (SourceFile! source_file) {
-       }
-
-       /**
-        * Visit operation called at beginning of namespaces.
-        *
-        * @param ns a namespace
-        */
-       public virtual void visit_begin_namespace (Namespace! ns) {
-       }
-
-       /**
-        * Visit operation called at end of namespaces.
+        * Visit operation called for namespaces.
         *
         * @param ns a namespace
         */
-       public virtual void visit_end_namespace (Namespace! ns) {
+       public virtual void visit_namespace (Namespace! ns) {
        }
 
        /**
index e518ffcab87c00ddbb3f116b7cee4b7f86b90f61..e2bf4281bd7fadfc2fb83299fc7b9beb9695732f 100644 (file)
@@ -61,8 +61,13 @@ public class Vala.InterfaceWriter : CodeVisitor {
                stream = null;
        }
 
-       public override void visit_begin_namespace (Namespace! ns) {
+       public override void visit_source_file (SourceFile! source_file) {
+               source_file.accept_children (this);
+       }
+
+       public override void visit_namespace (Namespace! ns) {
                if (ns.name == null)  {
+                       ns.accept_children (this);
                        return;
                }
 
@@ -76,13 +81,9 @@ public class Vala.InterfaceWriter : CodeVisitor {
                write_string ("namespace ");
                write_identifier (ns.name);
                write_begin_block ();
-       }
 
-       public override void visit_end_namespace (Namespace! ns) {
-               if (ns.name == null)  {
-                       return;
-               }
-               
+               ns.accept_children (this);
+
                write_end_block ();
                write_newline ();
        }
index 4d1cca382d328eec04e96a8869525dbba5870f81..fa8291c08ebdc4526b6a44dba85fd717c4c58d1f 100644 (file)
@@ -61,6 +61,14 @@ public class Vala.MemoryManager : CodeVisitor {
                }
        }
 
+       public override void visit_source_file (SourceFile! source_file) {
+               source_file.accept_children (this);
+       }
+
+       public override void visit_namespace (Namespace! ns) {
+               ns.accept_children (this);
+       }
+
        public override void visit_field (Field! f) {
                if (f.initializer != null) {
                        if (f.type_reference.takes_ownership) {
index 6dace35eb6a1e637091da6f60517ebbf4b1a4e5d..5b6f7bdb6fa371418b7ba78d447ae50d51e4ce98 100644 (file)
@@ -181,10 +181,12 @@ public class Vala.Namespace : CodeNode {
        public void add_method (Method! m) {
                methods.append (m);
        }
-       
+
        public override void accept (CodeVisitor! visitor) {
-               visitor.visit_begin_namespace (this);
+               visitor.visit_namespace (this);
+       }
 
+       public override void accept_children (CodeVisitor! visitor) {
                /* process enums and flags first to avoid order problems in C code */
                foreach (Enum en in enums) {
                        en.accept (visitor);
@@ -221,8 +223,6 @@ public class Vala.Namespace : CodeNode {
                foreach (Method m in methods) {
                        m.accept (visitor);
                }
-
-               visitor.visit_end_namespace (this);
        }
 
        /**
index 16144680b35e89902c0ccb8bf44e7af26b4a606f..11b7f57b81bb50a2061fbd67fb13f907d6eefee5 100644 (file)
@@ -1,6 +1,6 @@
 /* valaparser.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -39,17 +39,17 @@ public class Vala.Parser : CodeVisitor {
                context.accept (this);
        }
 
-       public override void visit_begin_source_file (SourceFile! source_file) {
+       public override void visit_source_file (SourceFile! source_file) {
                if (source_file.filename.has_suffix (".vala")) {
                        parse_file (source_file);
                        source_file.comment = _file_comment;
                }
-       }
-       
-       public override void visit_end_source_file (SourceFile! source_file) {
+
+               source_file.accept_children (this);
+
                _file_comment = null;
        }
-       
+
        /**
         * Adds the specified comment to the comment stack.
         *
index 6e1b0f3d776cad4e04ad787531ba312eb820ef9a..35c562d6caead29c3f80f761afe599b0c2786cfd 100644 (file)
@@ -99,22 +99,22 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                context.accept (this);
        }
 
-       public override void visit_begin_source_file (SourceFile! file) {
+       public override void visit_source_file (SourceFile! file) {
                current_source_file = file;
                current_using_directives = file.get_using_directives ();
 
                next_lambda_id = 0;
-       }
 
-       public override void visit_end_source_file (SourceFile! file) {
+               file.accept_children (this);
+
                current_using_directives = null;
        }
 
-       public override void visit_begin_namespace (Namespace! ns) {
+       public override void visit_namespace (Namespace! ns) {
                current_symbol = ns.symbol;
-       }
 
-       public override void visit_end_namespace (Namespace! ns) {
+               ns.accept_children (this);
+
                current_symbol = current_symbol.parent_symbol;
        }
 
index 11972d536e4e67ee0a48466cbc37c7f1523f7f3e..9728dd2f5c302a7578cc7a91e48efdd9e7e56ea2 100644 (file)
@@ -1,6 +1,6 @@
 /* valasourcefile.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -146,16 +146,12 @@ public class Vala.SourceFile {
        public ref List<weak Namespace> get_namespaces () {
                return namespaces.copy ();
        }
-       
-       /**
-        * Visits this source file and all children with the specified
-        * CodeVisitor.
-        *
-        * @param visitor the visitor to be called while traversing
-        */
+
        public void accept (CodeVisitor! visitor) {
-               visitor.visit_begin_source_file (this);
+               visitor.visit_source_file (this);
+       }
 
+       public void accept_children (CodeVisitor! visitor) {
                foreach (NamespaceReference ns_ref in using_directives) {
                        ns_ref.accept (visitor);
                }
@@ -165,10 +161,8 @@ public class Vala.SourceFile {
                foreach (Namespace ns in namespaces) {
                        ns.accept (visitor);
                }
-
-               visitor.visit_end_source_file (this);
        }
-       
+
        /**
         * Returns the filename to use when generating C header files.
         *
index 0bceb41b55db989a91476106f1aa265bc38654c8..39018d156fdc2a97fcd2e67a683885d2f3deddb7 100644 (file)
@@ -42,11 +42,13 @@ public class Vala.SymbolBuilder : CodeVisitor {
                context.accept (this);
        }
        
-       public override void visit_begin_source_file (SourceFile! file) {
+       public override void visit_source_file (SourceFile! file) {
                current_source_file = file;
+
+               file.accept_children (this);
        }
        
-       public override void visit_begin_namespace (Namespace! ns) {
+       public override void visit_namespace (Namespace! ns) {
                if (ns.name == null) {
                        ns.symbol = root;
                }
@@ -60,9 +62,9 @@ public class Vala.SymbolBuilder : CodeVisitor {
                }
                
                current_symbol = ns.symbol;
-       }
-       
-       public override void visit_end_namespace (Namespace! ns) {
+
+               ns.accept_children (this);
+
                current_symbol = current_symbol.parent_symbol;
        }
        
index 483871bce7db0b24019a48a32321d6b912da9aec..eb7bd33b381e720672c8758203fd5f18fb8f0278 100644 (file)
@@ -50,19 +50,19 @@ public class Vala.SymbolResolver : CodeVisitor {
                context.accept (this);
        }
        
-       public override void visit_begin_source_file (SourceFile! file) {
+       public override void visit_source_file (SourceFile! file) {
                current_using_directives = file.get_using_directives ();
-       }
 
-       public override void visit_end_source_file (SourceFile! file) {
+               file.accept_children (this);
+
                current_using_directives = null;
        }
        
-       public override void visit_begin_namespace (Namespace! ns) {
+       public override void visit_namespace (Namespace! ns) {
                current_scope = ns.symbol;
-       }
 
-       public override void visit_end_namespace (Namespace! ns) {
+               ns.accept_children (this);
+
                // don't use current_scope.parent_symbol as that would be null
                // if the current namespace is SourceFile.global_namespace
                current_scope = root_symbol;
index 0a7d31f337fb129733179f6f8d46c4ca9dd420f1..b1e8cadff3f0a6d181704f27abde90ac828cb574 100644 (file)
@@ -43,7 +43,7 @@ public class Vala.GIdlParser : CodeVisitor {
                context.accept (this);
        }
 
-       public override void visit_begin_source_file (SourceFile! source_file) {
+       public override void visit_source_file (SourceFile! source_file) {
                if (source_file.filename.has_suffix (".gidl")) {
                        parse_file (source_file);
                }