+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,
}
}
+ 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 ());
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 ();
/* 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) {
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;
+ }
}
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) {
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.
*
*/
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) {
}
/**
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;
}
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 ();
}
}
}
+ 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) {
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);
foreach (Method m in methods) {
m.accept (visitor);
}
-
- visitor.visit_end_namespace (this);
}
/**
/* 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
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.
*
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;
}
/* 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
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);
}
foreach (Namespace ns in namespaces) {
ns.accept (visitor);
}
-
- visitor.visit_end_source_file (this);
}
-
+
/**
* Returns the filename to use when generating C header files.
*
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;
}
}
current_symbol = ns.symbol;
- }
-
- public override void visit_end_namespace (Namespace! ns) {
+
+ ns.accept_children (this);
+
current_symbol = current_symbol.parent_symbol;
}
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;
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);
}