Commit 6cbc5a68 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

move iteration of data types from accept to accept_children method

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/valasymbolbuilder.vala, vala/valasymbolresolver.vala,
	  vala/valacallback.vala, vala/valaclass.vala, vala/valaenum.vala,
	  vala/valaflags.vala, vala/valainterface.vala, vala/valastruct.vala,
	  gobject/valacodegenerator.class, gobject/valacodegeneratorclass.vala,
	  gobject/valacodegeneratorinterface.vala,
	  gobject/valacodegeneratorstruct.vala: move iteration of data types
	  from accept to accept_children method

svn path=/trunk/; revision=323
parent 0233ba69
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/valasymbolbuilder.vala, vala/valasymbolresolver.vala,
vala/valacallback.vala, vala/valaclass.vala, vala/valaenum.vala,
vala/valaflags.vala, vala/valainterface.vala, vala/valastruct.vala,
gobject/valacodegenerator.class, gobject/valacodegeneratorclass.vala,
gobject/valacodegeneratorinterface.vala,
gobject/valacodegeneratorstruct.vala: move iteration of data types
from accept to accept_children method
2007-06-15 Jürg Billeter <j@bitron.ch>
* vala/valaattributeprocessor.vala, vala/valacodevisitor.vala,
......
......@@ -258,13 +258,15 @@ public class Vala.CodeGenerator : CodeVisitor {
ns.accept_children (this);
}
public override void visit_begin_enum (Enum! en) {
public override void visit_enum (Enum! en) {
cenum = new CCodeEnum (en.get_cname ());
if (en.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (en.source_reference.comment));
}
header_type_definition.append (cenum);
en.accept_children (this);
}
public override void visit_enum_value (EnumValue! ev) {
......@@ -278,13 +280,15 @@ public class Vala.CodeGenerator : CodeVisitor {
cenum.add_value (ev.get_cname (), val);
}
public override void visit_begin_flags (Flags! fl) {
public override void visit_flags (Flags! fl) {
cenum = new CCodeEnum (fl.get_cname ());
if (fl.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (fl.source_reference.comment));
}
header_type_definition.append (cenum);
fl.accept_children (this);
}
public override void visit_flags_value (FlagsValue! fv) {
......@@ -298,7 +302,9 @@ public class Vala.CodeGenerator : CodeVisitor {
cenum.add_value (fv.get_cname (), val);
}
public override void visit_end_callback (Callback! cb) {
public override void visit_callback (Callback! cb) {
cb.accept_children (this);
var cfundecl = new CCodeFunctionDeclarator (cb.get_cname ());
foreach (FormalParameter param in cb.get_parameters ()) {
cfundecl.add_parameter ((CCodeFormalParameter) param.ccodenode);
......
......@@ -24,7 +24,7 @@
using GLib;
public class Vala.CodeGenerator {
public override void visit_begin_class (Class! cl) {
public override void visit_class (Class! cl) {
current_symbol = cl.symbol;
current_type_symbol = cl.symbol;
current_class = cl;
......@@ -85,9 +85,9 @@ public class Vala.CodeGenerator {
source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
}
source_type_member_declaration.append (prop_enum);
}
public override void visit_end_class (Class! cl) {
cl.accept_children (this);
if (!cl.is_static) {
if (class_has_readable_properties (cl)) {
add_get_property_function (cl);
......
......@@ -24,45 +24,43 @@
using GLib;
public class Vala.CodeGenerator {
public override void visit_begin_interface (Interface! iface) {
public override void visit_interface (Interface! iface) {
current_symbol = iface.symbol;
current_type_symbol = iface.symbol;
if (iface.is_static) {
return;
}
if (!iface.is_static) {
type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
header_type_declaration.append (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
header_type_declaration.append (new CCodeMacroReplacement (iface.get_upper_case_cname ("TYPE_"), macro));
type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
header_type_declaration.append (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
header_type_declaration.append (new CCodeMacroReplacement (iface.get_upper_case_cname ("TYPE_"), macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_upper_case_cname ("TYPE_"));
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname ("IS_")), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_upper_case_cname ("TYPE_"));
header_type_declaration.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname ("IS_")), macro));
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_type_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
header_type_declaration.append (new CCodeNewline ());
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_upper_case_cname ("TYPE_"), iface.get_type_cname ());
header_type_declaration.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
header_type_declaration.append (new CCodeNewline ());
if (iface.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
}
type_struct.add_field ("GTypeInterface", "parent");
if (iface.source_reference.file.cycle == null) {
header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
header_type_declaration.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
if (iface.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (iface.source_reference.comment));
}
header_type_definition.append (type_struct);
}
type_struct.add_field ("GTypeInterface", "parent");
if (iface.source_reference.comment != null) {
header_type_definition.append (new CCodeComment (iface.source_reference.comment));
}
header_type_definition.append (type_struct);
}
iface.accept_children (this);
public override void visit_end_interface (Interface! iface) {
if (!iface.is_static) {
add_interface_base_init_function (iface);
......
......@@ -24,7 +24,7 @@
using GLib;
public class Vala.CodeGenerator {
public override void visit_begin_struct (Struct! st) {
public override void visit_struct (Struct! st) {
current_type_symbol = st.symbol;
instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
......@@ -37,9 +37,9 @@ public class Vala.CodeGenerator {
header_type_definition.append (new CCodeComment (st.source_reference.comment));
}
header_type_definition.append (instance_struct);
}
public override void visit_end_struct (Struct! st) {
st.accept_children (this);
current_type_symbol = null;
}
}
......@@ -46,23 +46,29 @@ public class Vala.AttributeProcessor : CodeVisitor {
ns.accept_children (this);
}
public override void visit_begin_class (Class! cl) {
public override void visit_class (Class! cl) {
cl.process_attributes ();
cl.accept_children (this);
}
public override void visit_begin_struct (Struct! st) {
public override void visit_struct (Struct! st) {
st.process_attributes ();
st.accept_children (this);
}
public override void visit_begin_interface (Interface! iface) {
public override void visit_interface (Interface! iface) {
iface.process_attributes ();
iface.accept_children (this);
}
public override void visit_begin_enum (Enum! en) {
public override void visit_enum (Enum! en) {
en.process_attributes ();
}
public override void visit_begin_flags (Flags! fl) {
public override void visit_flags (Flags! fl) {
fl.process_attributes ();
}
......@@ -78,7 +84,7 @@ public class Vala.AttributeProcessor : CodeVisitor {
prop.process_attributes ();
}
public override void visit_begin_callback (Callback! cb) {
public override void visit_callback (Callback! cb) {
cb.process_attributes ();
}
......
......@@ -130,10 +130,12 @@ public class Vala.Callback : DataType {
return true;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_callback (this);
visitor.visit_callback (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (TypeParameter p in type_parameters) {
p.accept (visitor);
}
......@@ -143,8 +145,6 @@ public class Vala.Callback : DataType {
foreach (FormalParameter! param in parameters) {
param.accept (visitor);
}
visitor.visit_end_callback (this);
}
public override string get_cname (bool const_type = false) {
......
......@@ -229,10 +229,12 @@ public class Vala.Class : DataType {
public ref List<weak Signal> get_signals () {
return signals.copy ();
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_class (this);
visitor.visit_class (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (TypeReference type in base_types) {
type.accept (visitor);
}
......@@ -268,10 +270,8 @@ public class Vala.Class : DataType {
if (destructor != null) {
destructor.accept (visitor);
}
visitor.visit_end_class (this);
}
public override string get_cname (bool const_type = false) {
if (cname == null) {
cname = "%s%s".printf (@namespace.get_cprefix (), name);
......
......@@ -44,67 +44,35 @@ public abstract class Vala.CodeVisitor {
}
/**
* Visit operation called at beginning of classes.
* Visit operation called for classes.
*
* @param cl a class
*/
public virtual void visit_begin_class (Class! cl) {
public virtual void visit_class (Class! cl) {
}
/**
* Visit operation called at end of classes.
*
* @param cl a class
*/
public virtual void visit_end_class (Class! cl) {
}
/**
* Visit operation called at beginning of structs.
*
* @param st a struct
*/
public virtual void visit_begin_struct (Struct! st) {
}
/**
* Visit operation called at end of structs.
* Visit operation called for structs.
*
* @param st a struct
*/
public virtual void visit_end_struct (Struct! st) {
}
/**
* Visit operation called at beginning of interfaces.
*
* @param iface an interface
*/
public virtual void visit_begin_interface (Interface! iface) {
public virtual void visit_struct (Struct! st) {
}
/**
* Visit operation called at end of interfaces.
* Visit operation called for interfaces.
*
* @param iface an interface
*/
public virtual void visit_end_interface (Interface! iface) {
public virtual void visit_interface (Interface! iface) {
}
/**
* Visit operation called at beginning of enums.
* Visit operation called for enums.
*
* @param en an enum
*/
public virtual void visit_begin_enum (Enum! en) {
}
/**
* Visit operation called at end of enums.
*
* @param en an enum
*/
public virtual void visit_end_enum (Enum! en) {
public virtual void visit_enum (Enum! en) {
}
/**
......@@ -116,19 +84,11 @@ public abstract class Vala.CodeVisitor {
}
/**
* Visit operation called at beginning of flags.
*
* @param fl a flags
*/
public virtual void visit_begin_flags (Flags! fl) {
}
/**
* Visit operation called at end of flags.
* Visit operation called for flags.
*
* @param fl a flags
*/
public virtual void visit_end_flags (Flags! fl) {
public virtual void visit_flags (Flags! fl) {
}
/**
......@@ -140,19 +100,11 @@ public abstract class Vala.CodeVisitor {
}
/**
* Visit operation called at beginning of callbacks.
*
* @param cb a callback
*/
public virtual void visit_begin_callback (Callback! cb) {
}
/**
* Visit operation called at end of callbacks.
* Visit operation called for callbacks.
*
* @param cb a callback
*/
public virtual void visit_end_callback (Callback! cb) {
public virtual void visit_callback (Callback! cb) {
}
/**
......
/* valaenum.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
......@@ -50,15 +50,15 @@ public class Vala.Enum : DataType {
public void add_value (EnumValue! value) {
values.append (value);
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_enum (this);
visitor.visit_enum (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (EnumValue value in values) {
value.accept (visitor);
}
visitor.visit_end_enum (this);
}
public override string get_cname (bool const_type = false) {
......
......@@ -50,13 +50,13 @@ public class Vala.Flags : DataType {
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_flags (this);
visitor.visit_flags (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (FlagsValue value in values) {
value.accept (visitor);
}
visitor.visit_end_flags (this);
}
public override string get_cname (bool const_type = false) {
......
......@@ -184,10 +184,12 @@ public class Vala.Interface : DataType {
public override ref string get_upper_case_cname (string infix) {
return get_lower_case_cname (infix).up ();
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_interface (this);
visitor.visit_interface (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (TypeReference type in prerequisites) {
type.accept (visitor);
}
......@@ -207,8 +209,6 @@ public class Vala.Interface : DataType {
foreach (Signal sig in signals) {
sig.accept (visitor);
}
visitor.visit_end_interface (this);
}
public override bool is_reference_type () {
......
......@@ -34,9 +34,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
int indent;
/* at begin of line */
bool bol = true;
bool internal_scope = false;
string current_cheader_filename;
/**
......@@ -88,9 +86,8 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_newline ();
}
public override void visit_begin_class (Class! cl) {
public override void visit_class (Class! cl) {
if (cl.access == MemberAccessibility.PRIVATE) {
internal_scope = true;
return;
}
......@@ -132,21 +129,15 @@ public class Vala.InterfaceWriter : CodeVisitor {
}
}
write_begin_block ();
}
public override void visit_end_class (Class! cl) {
if (cl.access == MemberAccessibility.PRIVATE) {
internal_scope = false;
return;
}
cl.accept_children (this);
write_end_block ();
write_newline ();
}
public override void visit_begin_struct (Struct! st) {
public override void visit_struct (Struct! st) {
if (st.access == MemberAccessibility.PRIVATE) {
internal_scope = true;
return;
}
......@@ -159,21 +150,15 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string ("public struct ");
write_identifier (st.name);
write_begin_block ();
}
public override void visit_end_struct (Struct! st) {
if (st.access == MemberAccessibility.PRIVATE) {
internal_scope = false;
return;
}
st.accept_children (this);
write_end_block ();
write_newline ();
}
public override void visit_begin_interface (Interface! iface) {
public override void visit_interface (Interface! iface) {
if (iface.access == MemberAccessibility.PRIVATE) {
internal_scope = true;
return;
}
......@@ -183,21 +168,15 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_identifier (iface.name);
write_begin_block ();
}
public override void visit_end_interface (Interface! iface) {
if (iface.access == MemberAccessibility.PRIVATE) {
internal_scope = false;
return;
}
iface.accept_children (this);
write_end_block ();
write_newline ();
}
public override void visit_begin_enum (Enum! en) {
public override void visit_enum (Enum! en) {
if (en.access == MemberAccessibility.PRIVATE) {
internal_scope = true;
return;
}
......@@ -208,32 +187,22 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string ("public enum ");
write_identifier (en.name);
write_begin_block ();
}
public override void visit_end_enum (Enum! en) {
if (en.access == MemberAccessibility.PRIVATE) {
internal_scope = false;
return;
}
en.accept_children (this);
write_end_block ();
write_newline ();
}
public override void visit_enum_value (EnumValue! ev) {
if (internal_scope) {
return;
}
write_indent ();
write_identifier (ev.name);
write_string (",");
write_newline ();
}
public override void visit_begin_flags (Flags! fl) {
public override void visit_flags (Flags! fl) {
if (fl.access == MemberAccessibility.PRIVATE) {
internal_scope = true;
return;
}
......@@ -244,23 +213,14 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string ("public flags ");
write_identifier (fl.name);
write_begin_block ();
}
public override void visit_end_flags (Flags! fl) {
if (fl.access == MemberAccessibility.PRIVATE) {
internal_scope = false;
return;
}
fl.accept_children (this);
write_end_block ();
write_newline ();
}
public override void visit_flags_value (FlagsValue! fv) {
if (internal_scope) {
return;
}
write_indent ();
write_identifier (fv.name);
write_string (",");
......@@ -268,10 +228,6 @@ public class Vala.InterfaceWriter : CodeVisitor {
}
public override void visit_constant (Constant! c) {
if (internal_scope) {
return;
}
write_indent ();
write_string ("public const ");
write_string (c.type_reference.data_type.symbol.get_full_name ());
......@@ -283,7 +239,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
}
public override void visit_field (Field! f) {
if (internal_scope || f.access == MemberAccessibility.PRIVATE) {
if (f.access == MemberAccessibility.PRIVATE) {
return;
}
......@@ -366,8 +322,8 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string (")");
}
public override void visit_begin_callback (Callback! cb) {
if (internal_scope || cb.access == MemberAccessibility.PRIVATE) {
public override void visit_callback (Callback! cb) {
if (cb.access == MemberAccessibility.PRIVATE) {
return;
}
......@@ -397,7 +353,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
}
public override void visit_begin_method (Method! m) {
if (internal_scope || m.access == MemberAccessibility.PRIVATE || m.overrides) {
if (m.access == MemberAccessibility.PRIVATE || m.overrides) {
return;
}
......@@ -482,10 +438,6 @@ public class Vala.InterfaceWriter : CodeVisitor {
}
public override void visit_begin_property (Property! prop) {
if (internal_scope) {
return;
}
if (prop.no_accessor_method) {
write_indent ();
write_string ("[NoAccessorMethod]");
......@@ -530,7 +482,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
}
public override void visit_begin_signal (Signal! sig) {
if (internal_scope || sig.access == MemberAccessibility.PRIVATE) {
if (sig.access == MemberAccessibility.PRIVATE) {
return;
}
......
......@@ -69,6 +69,18 @@ public class Vala.MemoryManager : CodeVisitor {
ns.accept_children (this);
}
public override void visit_class (Class! cl) {
cl.accept_children (this);
}
public overrid