Commit 0233ba69 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

move iteration of source files and namespaces from accept to

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
parent 49f7556c
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,
......
......@@ -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 ());
......
......@@ -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;
}
}
......@@ -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) {
......
......@@ -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.
*
......
......@@ -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) {
}
/**
......
......@@ -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 ();
}
......
......@@ -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) {
......
......@@ -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);
}
/**
......
/* 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.
*
......
......@@ -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;
}
......
/* 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.
*
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment