From: Jürg Billeter Date: Fri, 15 Jun 2007 10:25:33 +0000 (+0000) Subject: move iteration of source files and namespaces from accept to X-Git-Tag: VALA_0_1_0~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0233ba6904d0205e05a6e2e70fab1e3931eee857;p=thirdparty%2Fvala.git move iteration of source files and namespaces from accept to 2007-06-15 Jürg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index fe615ba19..202e9c129 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-06-15 Jürg Billeter + + * 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 * vala/valacodecontext.vala, gobject/valaccodecompiler.vala, diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 5b117219b..e1791a9e7 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -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 ()); diff --git a/gobject/valacodegeneratorsourcefile.vala b/gobject/valacodegeneratorsourcefile.vala index 7eb8b718a..f02a76d6d 100644 --- a/gobject/valacodegeneratorsourcefile.vala +++ b/gobject/valacodegeneratorsourcefile.vala @@ -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; + } } diff --git a/vala/valaattributeprocessor.vala b/vala/valaattributeprocessor.vala index 2c4901f8f..9300718fe 100644 --- a/vala/valaattributeprocessor.vala +++ b/vala/valaattributeprocessor.vala @@ -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) { diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 92df6fcb1..e5e187fca 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -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. * diff --git a/vala/valacodevisitor.vala b/vala/valacodevisitor.vala index aa1e9ff6c..eab68f1b6 100644 --- a/vala/valacodevisitor.vala +++ b/vala/valacodevisitor.vala @@ -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) { } /** diff --git a/vala/valainterfacewriter.vala b/vala/valainterfacewriter.vala index e518ffcab..e2bf4281b 100644 --- a/vala/valainterfacewriter.vala +++ b/vala/valainterfacewriter.vala @@ -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 (); } diff --git a/vala/valamemorymanager.vala b/vala/valamemorymanager.vala index 4d1cca382..fa8291c08 100644 --- a/vala/valamemorymanager.vala +++ b/vala/valamemorymanager.vala @@ -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) { diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala index 6dace35eb..5b6f7bdb6 100644 --- a/vala/valanamespace.vala +++ b/vala/valanamespace.vala @@ -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); } /** diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 16144680b..11b7f57b8 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -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. * diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 6e1b0f3d7..35c562d6c 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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; } diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala index 11972d536..9728dd2f5 100644 --- a/vala/valasourcefile.vala +++ b/vala/valasourcefile.vala @@ -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 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. * diff --git a/vala/valasymbolbuilder.vala b/vala/valasymbolbuilder.vala index 0bceb41b5..39018d156 100644 --- a/vala/valasymbolbuilder.vala +++ b/vala/valasymbolbuilder.vala @@ -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; } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index 483871bce..eb7bd33b3 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -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; diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index 0a7d31f33..b1e8cadff 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -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); }