[vala] gobject: Add CCodeDeclarationSpace class
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] gobject: Add CCodeDeclarationSpace class
- Date: Wed, 11 Mar 2009 12:06:16 -0400 (EDT)
commit 32b0e29257ff044e7f46800c6882c098109e49ff
Author: Jürg Billeter <j bitron ch>
Date: Wed Mar 11 17:04:08 2009 +0100
gobject: Add CCodeDeclarationSpace class
The CCodeDeclarationSpace class abstracts access to the various
declaration fragments used to generate C header and source files.
---
gobject/Makefile.am | 1 +
gobject/valaccodearraymodule.vala | 10 +-
gobject/valaccodebasemodule.vala | 175 +++++++++++++-------------------
gobject/valaccodedeclarationspace.vala | 61 +++++++++++
gobject/valaccodedelegatemodule.vala | 10 +-
gobject/valaccodemethodmodule.vala | 14 ++--
gobject/valaccodestructmodule.vala | 31 +++---
gobject/valadbusclientmodule.vala | 46 ++++-----
gobject/valadbusservermodule.vala | 26 +++---
gobject/valagasyncmodule.vala | 10 +-
gobject/valagerrormodule.vala | 8 +-
gobject/valagobjectmodule.vala | 107 ++++++++++----------
gobject/valagtypemodule.vala | 47 ++++-----
13 files changed, 280 insertions(+), 266 deletions(-)
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index 4a15366..3e1b140 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -17,6 +17,7 @@ libvala_la_VALASOURCES = \
valaccodebasemodule.vala \
valaccodecompiler.vala \
valaccodecontrolflowmodule.vala \
+ valaccodedeclarationspace.vala \
valaccodedelegatemodule.vala \
valaccodegenerator.vala \
valaccodememberaccessmodule.vala \
diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala
index 0b6bf0e..06ad8b9 100644
--- a/gobject/valaccodearraymodule.vala
+++ b/gobject/valaccodearraymodule.vala
@@ -375,7 +375,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify"));
- source_type_member_declaration.append (fun.copy ());
+ source_declarations.add_type_member_declaration (fun.copy ());
var cdofree = new CCodeBlock ();
@@ -410,7 +410,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
fun.add_parameter (new CCodeFormalParameter ("src", "gint"));
fun.add_parameter (new CCodeFormalParameter ("dest", "gint"));
fun.add_parameter (new CCodeFormalParameter ("length", "gint"));
- source_type_member_declaration.append (fun.copy ());
+ source_declarations.add_type_member_declaration (fun.copy ());
var array = new CCodeCastExpression (new CCodeIdentifier ("array"), "char*");
var element_size = new CCodeIdentifier ("element_size");
@@ -452,7 +452,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
var fun = new CCodeFunction ("_vala_array_length", "gint");
fun.modifiers = CCodeModifiers.STATIC;
fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
- source_type_member_declaration.append (fun.copy ());
+ source_declarations.add_type_member_declaration (fun.copy ());
var block = new CCodeBlock ();
@@ -552,7 +552,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -624,7 +624,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
// append to file
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index d441397..822c841 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -39,17 +39,9 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public TryStatement current_try;
public PropertyAccessor current_property_accessor;
- public CCodeFragment header_begin;
- public CCodeFragment header_type_declaration;
- public CCodeFragment header_type_definition;
- public CCodeFragment header_type_member_declaration;
- public CCodeFragment header_constant_declaration;
- public CCodeFragment source_begin;
- public CCodeFragment source_include_directives;
- public CCodeFragment source_type_declaration;
- public CCodeFragment source_type_definition;
- public CCodeFragment source_type_member_declaration;
- public CCodeFragment source_constant_declaration;
+ public CCodeDeclarationSpace header_declarations;
+ public CCodeDeclarationSpace source_declarations;
+
public CCodeFragment source_signal_marshaller_declaration;
public CCodeFragment source_type_member_definition;
public CCodeFragment class_init_fragment;
@@ -222,10 +214,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
}
- private CCodeIncludeDirective get_internal_include (string filename) {
- return new CCodeIncludeDirective (filename, context.library == null);
- }
-
public virtual void append_vala_array_free () {
}
@@ -240,7 +228,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
fun.modifiers = CCodeModifiers.STATIC;
fun.add_parameter (new CCodeFormalParameter ("str1", "const char *"));
fun.add_parameter (new CCodeFormalParameter ("str2", "const char *"));
- source_type_member_declaration.append (fun.copy ());
+ source_declarations.add_type_member_declaration (fun.copy ());
// (str1 != str2)
var cineq = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("str1"), new CCodeIdentifier ("str2"));
@@ -272,17 +260,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
public override void visit_source_file (SourceFile source_file) {
- header_begin = new CCodeFragment ();
- header_type_declaration = new CCodeFragment ();
- header_type_definition = new CCodeFragment ();
- header_type_member_declaration = new CCodeFragment ();
- header_constant_declaration = new CCodeFragment ();
- source_begin = new CCodeFragment ();
- source_include_directives = new CCodeFragment ();
- source_type_declaration = new CCodeFragment ();
- source_type_definition = new CCodeFragment ();
- source_type_member_declaration = new CCodeFragment ();
- source_constant_declaration = new CCodeFragment ();
+ header_declarations = new CCodeDeclarationSpace ();
+ source_declarations = new CCodeDeclarationSpace ();
source_type_member_definition = new CCodeFragment ();
source_signal_marshaller_definition = new CCodeFragment ();
source_signal_marshaller_declaration = new CCodeFragment ();
@@ -305,14 +284,14 @@ internal class Vala.CCodeBaseModule : CCodeModule {
wrappers = new HashSet<string> (str_hash, str_equal);
- header_begin.append (new CCodeIncludeDirective ("glib.h"));
- header_begin.append (new CCodeIncludeDirective ("glib-object.h"));
+ header_declarations.add_include ("glib.h");
+ header_declarations.add_include ("glib-object.h");
if (context.legacy_headers) {
if (context.basedir != null || context.library != null) {
- source_include_directives.append (new CCodeIncludeDirective (source_file.get_cinclude_filename ()));
+ source_declarations.add_include (source_file.get_cinclude_filename ());
} else {
- source_include_directives.append (new CCodeIncludeDirective (source_file.get_cinclude_filename (), true));
+ source_declarations.add_include (source_file.get_cinclude_filename (), true);
}
}
@@ -325,25 +304,25 @@ internal class Vala.CCodeBaseModule : CCodeModule {
foreach (string filename in source_file.get_header_external_includes ()) {
if (!used_includes.contains (filename)) {
- header_begin.append (new CCodeIncludeDirective (filename));
+ header_declarations.add_include (filename);
used_includes.add (filename);
}
}
foreach (string filename in source_file.get_header_internal_includes ()) {
if (!used_includes.contains (filename)) {
- header_begin.append (get_internal_include (filename));
+ header_declarations.add_include (filename, (context.library == null));
used_includes.add (filename);
}
}
foreach (string filename in source_file.get_source_external_includes ()) {
if (!used_includes.contains (filename)) {
- source_include_directives.append (new CCodeIncludeDirective (filename));
+ source_declarations.add_include (filename);
used_includes.add (filename);
}
}
foreach (string filename in source_file.get_source_internal_includes ()) {
if (!used_includes.contains (filename)) {
- source_include_directives.append (get_internal_include (filename));
+ source_declarations.add_include (filename, (context.library == null));
used_includes.add (filename);
}
}
@@ -352,15 +331,15 @@ internal class Vala.CCodeBaseModule : CCodeModule {
foreach (CodeNode node in cycle_file.get_nodes ()) {
if (node is Struct) {
var st = (Struct) node;
- header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
+ header_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
} else if (node is Class) {
var cl = (Class) node;
- header_type_declaration.append (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
- header_type_declaration.append (new CCodeTypeDefinition ("struct _%sClass".printf (cl.get_cname ()), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
+ header_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
+ header_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%sClass".printf (cl.get_cname ()), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
} else if (node is Interface) {
var iface = (Interface) node;
- 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 (iface.get_type_cname ()), new CCodeVariableDeclarator (iface.get_type_cname ())));
+ header_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
+ header_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (iface.get_type_cname ()), new CCodeVariableDeclarator (iface.get_type_cname ())));
}
}
}
@@ -382,7 +361,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
/* generate hardcoded "well-known" macros */
if (requires_free_checked) {
- source_begin.append (new CCodeMacroReplacement ("VALA_FREE_CHECKED(o,f)", "((o) == NULL ? NULL : ((o) = (f (o), NULL)))"));
+ source_declarations.add_begin (new CCodeMacroReplacement ("VALA_FREE_CHECKED(o,f)", "((o) == NULL ? NULL : ((o) = (f (o), NULL)))"));
}
if (requires_array_free) {
append_vala_array_free ();
@@ -398,30 +377,30 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
if (string_h_needed) {
- source_include_directives.append (new CCodeIncludeDirective ("string.h"));
+ source_declarations.add_include ("string.h");
}
if (gvaluecollector_h_needed) {
- source_include_directives.append (new CCodeIncludeDirective ("gobject/gvaluecollector.h"));
+ source_declarations.add_include ("gobject/gvaluecollector.h");
}
if (gio_h_needed) {
- header_begin.append (new CCodeIncludeDirective ("gio/gio.h"));
+ header_declarations.add_include ("gio/gio.h");
}
if (dbus_glib_h_needed_in_header) {
- header_begin.append (new CCodeIncludeDirective ("dbus/dbus.h"));
- header_begin.append (new CCodeIncludeDirective ("dbus/dbus-glib.h"));
+ header_declarations.add_include ("dbus/dbus.h");
+ header_declarations.add_include ("dbus/dbus-glib.h");
} else if (dbus_glib_h_needed) {
- source_include_directives.append (new CCodeIncludeDirective ("dbus/dbus.h"));
- source_include_directives.append (new CCodeIncludeDirective ("dbus/dbus-glib.h"));
+ source_declarations.add_include ("dbus/dbus.h");
+ source_declarations.add_include ("dbus/dbus-glib.h");
}
if (dbus_glib_h_needed_in_header || dbus_glib_h_needed) {
var dbusvtable = new CCodeStruct ("_DBusObjectVTable");
dbusvtable.add_field ("void", "(*register_object) (DBusConnection*, const char*, void*)");
- source_type_definition.append (dbusvtable);
+ source_declarations.add_type_definition (dbusvtable);
- source_type_declaration.append (new CCodeTypeDefinition ("struct _DBusObjectVTable", new CCodeVariableDeclarator ("_DBusObjectVTable")));
+ source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _DBusObjectVTable", new CCodeVariableDeclarator ("_DBusObjectVTable")));
var cfunc = new CCodeFunction ("_vala_dbus_register_object", "void");
cfunc.add_parameter (new CCodeFormalParameter ("connection", "DBusConnection*"));
@@ -429,7 +408,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
cfunc.add_parameter (new CCodeFormalParameter ("object", "void*"));
cfunc.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (cfunc.copy ());
+ source_declarations.add_type_member_declaration (cfunc.copy ());
var block = new CCodeBlock ();
cfunc.block = block;
@@ -484,18 +463,18 @@ internal class Vala.CCodeBaseModule : CCodeModule {
writer.write_newline ();
var once = new CCodeOnceSection (header_define);
once.append (new CCodeNewline ());
- once.append (header_begin);
+ once.append (header_declarations.include_directives);
once.append (new CCodeNewline ());
once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
once.append (new CCodeNewline ());
once.append (new CCodeNewline ());
- once.append (header_type_declaration);
+ once.append (header_declarations.type_declaration);
once.append (new CCodeNewline ());
- once.append (header_type_definition);
+ once.append (header_declarations.type_definition);
once.append (new CCodeNewline ());
- once.append (header_type_member_declaration);
+ once.append (header_declarations.type_member_declaration);
once.append (new CCodeNewline ());
- once.append (header_constant_declaration);
+ once.append (header_declarations.constant_declaration);
once.append (new CCodeNewline ());
once.append (new CCodeIdentifier ("G_END_DECLS"));
once.append (new CCodeNewline ());
@@ -513,19 +492,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (comment != null) {
comment.write (writer);
}
- source_begin.write (writer);
+ source_declarations.begin.write (writer);
writer.write_newline ();
- source_include_directives.write (writer);
+ source_declarations.include_directives.write (writer);
writer.write_newline ();
- source_type_declaration.write_combined (writer);
+ source_declarations.type_declaration.write_combined (writer);
writer.write_newline ();
- source_type_definition.write_combined (writer);
+ source_declarations.type_definition.write_combined (writer);
writer.write_newline ();
- source_type_member_declaration.write_declaration (writer);
+ source_declarations.type_member_declaration.write_declaration (writer);
writer.write_newline ();
- source_type_member_declaration.write (writer);
+ source_declarations.type_member_declaration.write (writer);
writer.write_newline ();
- source_constant_declaration.write (writer);
+ source_declarations.constant_declaration.write (writer);
writer.write_newline ();
source_signal_marshaller_declaration.write_declaration (writer);
source_signal_marshaller_declaration.write (writer);
@@ -536,17 +515,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
writer.write_newline ();
writer.close ();
- header_begin = null;
- header_type_declaration = null;
- header_type_definition = null;
- header_type_member_declaration = null;
- header_constant_declaration = null;
- source_begin = null;
- source_include_directives = null;
- source_type_declaration = null;
- source_type_definition = null;
- source_type_member_declaration = null;
- source_constant_declaration = null;
+ header_declarations = null;
+ source_declarations = null;
source_type_member_definition = null;
source_signal_marshaller_definition = null;
source_signal_marshaller_declaration = null;
@@ -668,22 +638,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public override void visit_enum (Enum en) {
cenum = new CCodeEnum (en.get_cname ());
- CCodeFragment decl_frag;
- CCodeFragment def_frag;
+ CCodeDeclarationSpace decl_space;
if (en.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
+ decl_space = header_declarations;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
+ decl_space = source_declarations;
}
if (en.source_reference.comment != null) {
- def_frag.append (new CCodeComment (en.source_reference.comment));
+ decl_space.add_type_definition (new CCodeComment (en.source_reference.comment));
}
- def_frag.append (cenum);
- def_frag.append (new CCodeNewline ());
+ decl_space.add_type_definition (cenum);
+ decl_space.add_type_definition (new CCodeNewline ());
en.accept_children (codegen);
@@ -691,10 +658,10 @@ internal class Vala.CCodeBaseModule : CCodeModule {
return;
}
- decl_frag.append (new CCodeNewline ());
+ decl_space.add_type_declaration (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (en.get_lower_case_cname (null));
- decl_frag.append (new CCodeMacroReplacement (en.get_type_id (), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement (en.get_type_id (), macro));
var clist = new CCodeInitializerList (); /* or during visit time? */
CCodeInitializerList clist_ev = null;
@@ -758,9 +725,9 @@ internal class Vala.CCodeBaseModule : CCodeModule {
regblock.add_statement (new CCodeReturnStatement (new CCodeConstant (type_id_name)));
if (en.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (regfun.copy ());
+ header_declarations.add_type_member_declaration (regfun.copy ());
} else {
- source_type_member_declaration.append (regfun.copy ());
+ source_declarations.add_type_member_declaration (regfun.copy ());
}
regfun.block = regblock;
@@ -818,16 +785,16 @@ internal class Vala.CCodeBaseModule : CCodeModule {
cdecl.modifiers = CCodeModifiers.STATIC;
if (!c.is_internal_symbol ()) {
- header_constant_declaration.append (cdecl);
+ header_declarations.add_constant_declaration (cdecl);
} else {
- source_constant_declaration.append (cdecl);
+ source_declarations.add_constant_declaration (cdecl);
}
} else {
var cdefine = new CCodeMacroReplacement.with_expression (c.get_cname (), (CCodeExpression) c.initializer.ccodenode);
if (!c.is_internal_symbol ()) {
- header_type_member_declaration.append (cdefine);
+ header_declarations.add_type_member_declaration (cdefine);
} else {
- source_type_member_declaration.append (cdefine);
+ source_declarations.add_type_member_declaration (cdefine);
}
}
}
@@ -940,7 +907,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
var cdecl = new CCodeDeclaration (field_ctype);
cdecl.add_declarator (new CCodeVariableDeclarator (f.get_cname ()));
cdecl.modifiers = CCodeModifiers.EXTERN;
- header_type_member_declaration.append (cdecl);
+ header_declarations.add_type_member_declaration (cdecl);
}
var var_decl = new CCodeVariableDeclarator (f.get_cname ());
@@ -960,7 +927,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
} else {
var_def.modifiers = CCodeModifiers.STATIC;
}
- source_type_member_declaration.append (var_def);
+ source_declarations.add_type_member_declaration (var_def);
/* add array length fields where necessary */
if (f.field_type is ArrayType && !f.no_array_length) {
@@ -973,7 +940,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
var cdecl = new CCodeDeclaration (len_type.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_length_cname (f.get_cname (), dim)));
cdecl.modifiers = CCodeModifiers.EXTERN;
- header_type_member_declaration.append (cdecl);
+ header_declarations.add_type_member_declaration (cdecl);
}
var len_def = new CCodeDeclaration (len_type.get_cname ());
@@ -983,7 +950,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
} else {
len_def.modifiers = CCodeModifiers.STATIC;
}
- source_type_member_declaration.append (len_def);
+ source_declarations.add_type_member_declaration (len_def);
}
if (array_type.rank == 1 && f.is_internal_symbol ()) {
@@ -992,7 +959,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
var cdecl = new CCodeDeclaration (len_type.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (head.get_array_size_cname (f.get_cname ()), new CCodeConstant ("0")));
cdecl.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (cdecl);
+ source_declarations.add_type_member_declaration (cdecl);
}
} else if (f.field_type is DelegateType) {
var delegate_type = (DelegateType) f.field_type;
@@ -1003,7 +970,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
var cdecl = new CCodeDeclaration ("gpointer");
cdecl.add_declarator (new CCodeVariableDeclarator (get_delegate_target_cname (f.get_cname ())));
cdecl.modifiers = CCodeModifiers.EXTERN;
- header_type_member_declaration.append (cdecl);
+ header_declarations.add_type_member_declaration (cdecl);
}
var target_def = new CCodeDeclaration ("gpointer");
@@ -1013,7 +980,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
} else {
target_def.modifiers = CCodeModifiers.STATIC;
}
- source_type_member_declaration.append (target_def);
+ source_declarations.add_type_member_declaration (target_def);
}
}
@@ -1192,10 +1159,10 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (!prop.is_internal_symbol () && (acc.readable || acc.writable) && acc.access != SymbolAccessibility.PRIVATE) {
// accessor function should be public if the property is a public symbol and it's not a construct-only setter
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
function.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
var block = new CCodeBlock ();
@@ -1273,10 +1240,10 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (!is_virtual) {
if (!prop.is_internal_symbol () && (acc.readable || acc.writable) && acc.access != SymbolAccessibility.PRIVATE) {
// accessor function should be public if the property is a public symbol and it's not a construct-only setter
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
function.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
}
@@ -1746,7 +1713,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
// append to file
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1850,7 +1817,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
// append to file
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
diff --git a/gobject/valaccodedeclarationspace.vala b/gobject/valaccodedeclarationspace.vala
new file mode 100644
index 0000000..008321b
--- /dev/null
+++ b/gobject/valaccodedeclarationspace.vala
@@ -0,0 +1,61 @@
+/* valaccodedeclarationspace.vala
+ *
+ * Copyright (C) 2009 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Jürg Billeter <j bitron ch>
+ */
+
+using Gee;
+
+class Vala.CCodeDeclarationSpace {
+ Set<string> includes = new HashSet<string> (str_hash, str_equal);
+ internal CCodeFragment begin = new CCodeFragment ();
+ internal CCodeFragment include_directives = new CCodeFragment ();
+ internal CCodeFragment type_declaration = new CCodeFragment ();
+ internal CCodeFragment type_definition = new CCodeFragment ();
+ internal CCodeFragment type_member_declaration = new CCodeFragment ();
+ internal CCodeFragment constant_declaration = new CCodeFragment ();
+
+ public void add_include (string filename, bool local = false) {
+ if (!(filename in includes)) {
+ include_directives.append (new CCodeIncludeDirective (filename, local));
+ includes.add (filename);
+ }
+ }
+
+ public void add_begin (CCodeNode node) {
+ begin.append (node);
+ }
+
+ public void add_type_declaration (CCodeNode node) {
+ type_declaration.append (node);
+ }
+
+ public void add_type_definition (CCodeNode node) {
+ type_definition.append (node);
+ }
+
+ public void add_type_member_declaration (CCodeNode node) {
+ type_member_declaration.append (node);
+ }
+
+ public void add_constant_declaration (CCodeNode node) {
+ constant_declaration.append (node);
+ }
+}
+
diff --git a/gobject/valaccodedelegatemodule.vala b/gobject/valaccodedelegatemodule.vala
index 0864d61..a5a22b4 100644
--- a/gobject/valaccodedelegatemodule.vala
+++ b/gobject/valaccodedelegatemodule.vala
@@ -76,14 +76,14 @@ internal class Vala.CCodeDelegateModule : CCodeArrayModule {
if (!d.is_internal_symbol ()) {
if (d.source_reference != null && d.source_reference.comment != null) {
- header_type_declaration.append (new CCodeComment (d.source_reference.comment));
+ header_declarations.add_type_declaration (new CCodeComment (d.source_reference.comment));
}
- header_type_declaration.append (ctypedef);
+ header_declarations.add_type_declaration (ctypedef);
} else {
if (d.source_reference != null && d.source_reference.comment != null) {
- source_type_declaration.append (new CCodeComment (d.source_reference.comment));
+ source_declarations.add_type_declaration (new CCodeComment (d.source_reference.comment));
}
- source_type_declaration.append (ctypedef);
+ source_declarations.add_type_declaration (ctypedef);
}
}
@@ -379,7 +379,7 @@ internal class Vala.CCodeDelegateModule : CCodeArrayModule {
// append to file
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
diff --git a/gobject/valaccodemethodmodule.vala b/gobject/valaccodemethodmodule.vala
index 9bf47b2..5096111 100644
--- a/gobject/valaccodemethodmodule.vala
+++ b/gobject/valaccodemethodmodule.vala
@@ -276,12 +276,12 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
if (visible && m.base_method == null && m.base_interface_method == null) {
/* public methods need function declaration in
* header file except virtual/overridden methods */
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
/* declare all other functions in source file to
* avoid dependency on order within source file */
function.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
/* Methods imported from a plain C file don't
@@ -300,7 +300,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
co_function.add_parameter (new CCodeFormalParameter ("data", Symbol.lower_case_to_camel_case (m.get_cname ()) + "Data*"));
co_function.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (co_function.copy ());
+ source_declarations.add_type_member_declaration (co_function.copy ());
var cswitch = new CCodeSwitchStatement (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "state"));
@@ -754,10 +754,10 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
}
if (visible) {
- header_type_member_declaration.append (vfunc.copy ());
+ header_declarations.add_type_member_declaration (vfunc.copy ());
} else {
vfunc.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (vfunc.copy ());
+ source_declarations.add_type_member_declaration (vfunc.copy ());
}
vfunc.block = vblock;
@@ -904,10 +904,10 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
vblock.add_statement (cstmt);
if (visible) {
- header_type_member_declaration.append (vfunc.copy ());
+ header_declarations.add_type_member_declaration (vfunc.copy ());
} else {
vfunc.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (vfunc.copy ());
+ source_declarations.add_type_member_declaration (vfunc.copy ());
}
vfunc.block = vblock;
diff --git a/gobject/valaccodestructmodule.vala b/gobject/valaccodestructmodule.vala
index e38098c..5802608 100644
--- a/gobject/valaccodestructmodule.vala
+++ b/gobject/valaccodestructmodule.vala
@@ -36,26 +36,23 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
instance_finalize_fragment = new CCodeFragment ();
- CCodeFragment decl_frag;
- CCodeFragment def_frag;
+ CCodeDeclarationSpace decl_space;
if (st.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
+ decl_space = header_declarations;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
+ decl_space = source_declarations;
}
if (st.access == SymbolAccessibility.PRIVATE
|| st.source_reference.file.cycle == null) {
// no file dependency cycle for private symbols
- decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
}
if (st.source_reference.comment != null) {
- def_frag.append (new CCodeComment (st.source_reference.comment));
+ decl_space.add_type_definition (new CCodeComment (st.source_reference.comment));
}
- def_frag.append (instance_struct);
+ decl_space.add_type_definition (instance_struct);
st.accept_children (codegen);
@@ -81,9 +78,9 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
function.add_parameter (new CCodeFormalParameter ("self", "const " + st.get_cname () + "*"));
if (st.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
var cblock = new CCodeBlock ();
@@ -129,9 +126,9 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
function.add_parameter (new CCodeFormalParameter ("self", st.get_cname () + "*"));
if (st.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
var cblock = new CCodeBlock ();
@@ -161,9 +158,9 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
function.add_parameter (new CCodeFormalParameter ("dest", st.get_cname () + "*"));
if (st.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
var cblock = new CCodeBlock ();
@@ -212,9 +209,9 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
function.add_parameter (new CCodeFormalParameter ("self", st.get_cname () + "*"));
if (st.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
var cblock = new CCodeBlock ();
diff --git a/gobject/valadbusclientmodule.vala b/gobject/valadbusclientmodule.vala
index ddb45dd..77e986d 100644
--- a/gobject/valadbusclientmodule.vala
+++ b/gobject/valadbusclientmodule.vala
@@ -62,7 +62,7 @@ internal class Vala.DBusClientModule : DBusModule {
}
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -545,7 +545,7 @@ internal class Vala.DBusClientModule : DBusModule {
generate_dbus_property_getter_wrapper (prop, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -570,7 +570,7 @@ internal class Vala.DBusClientModule : DBusModule {
generate_dbus_property_setter_wrapper (prop, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -711,7 +711,7 @@ internal class Vala.DBusClientModule : DBusModule {
generate_dbus_connect_wrapper (sig, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -734,7 +734,7 @@ internal class Vala.DBusClientModule : DBusModule {
generate_dbus_disconnect_wrapper (sig, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -840,23 +840,17 @@ internal class Vala.DBusClientModule : DBusModule {
string cname = iface.get_cname () + "DBusProxy";
string lower_cname = iface.get_lower_case_cprefix () + "dbus_proxy";
- CCodeFragment decl_frag;
- CCodeFragment def_frag;
- CCodeFragment member_decl_frag;
+ CCodeDeclarationSpace decl_space;
if (iface.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
- member_decl_frag = header_type_member_declaration;
+ decl_space = header_declarations;
dbus_glib_h_needed_in_header = true;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
- member_decl_frag = source_type_member_declaration;
+ decl_space = source_declarations;
dbus_glib_h_needed = true;
}
- source_type_declaration.append (new CCodeTypeDefinition ("DBusGProxy", new CCodeVariableDeclarator (cname)));
- source_type_declaration.append (new CCodeTypeDefinition ("DBusGProxyClass", new CCodeVariableDeclarator (cname + "Class")));
+ source_declarations.add_type_declaration (new CCodeTypeDefinition ("DBusGProxy", new CCodeVariableDeclarator (cname)));
+ source_declarations.add_type_declaration (new CCodeTypeDefinition ("DBusGProxyClass", new CCodeVariableDeclarator (cname + "Class")));
var implement = new CCodeFunctionCall (new CCodeIdentifier ("G_IMPLEMENT_INTERFACE"));
implement.add_argument (new CCodeIdentifier (iface.get_upper_case_cname ("TYPE_")));
@@ -928,7 +922,7 @@ internal class Vala.DBusClientModule : DBusModule {
new_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("self")));
- member_decl_frag.append (proxy_new.copy ());
+ decl_space.add_type_member_declaration (proxy_new.copy ());
proxy_new.block = new_block;
source_type_member_definition.append (proxy_new);
@@ -999,7 +993,7 @@ internal class Vala.DBusClientModule : DBusModule {
}
proxy_iface_init.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (proxy_iface_init.copy ());
+ source_declarations.add_type_member_declaration (proxy_iface_init.copy ());
proxy_iface_init.block = iface_block;
source_type_member_definition.append (proxy_iface_init);
}
@@ -1029,7 +1023,7 @@ internal class Vala.DBusClientModule : DBusModule {
filter_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("DBUS_HANDLER_RESULT_NOT_YET_HANDLED")));
- source_type_member_declaration.append (proxy_filter.copy ());
+ source_declarations.add_type_member_declaration (proxy_filter.copy ());
proxy_filter.block = filter_block;
source_type_member_definition.append (proxy_filter);
}
@@ -1122,7 +1116,7 @@ internal class Vala.DBusClientModule : DBusModule {
cdecl.add_declarator (new CCodeVariableDeclarator ("reply"));
block.add_statement (cdecl);
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1336,7 +1330,7 @@ internal class Vala.DBusClientModule : DBusModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
}
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1360,8 +1354,8 @@ internal class Vala.DBusClientModule : DBusModule {
datastruct.add_field ("gpointer", "user_data");
datastruct.add_field ("DBusPendingCall*", "pending");
- source_type_definition.append (datastruct);
- source_type_declaration.append (new CCodeTypeDefinition ("struct _" + dataname, new CCodeVariableDeclarator (dataname)));
+ source_declarations.add_type_definition (datastruct);
+ source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _" + dataname, new CCodeVariableDeclarator (dataname)));
// generate async function
@@ -1444,7 +1438,7 @@ internal class Vala.DBusClientModule : DBusModule {
pending.add_argument (new CCodeConstant ("NULL"));
block.add_statement (new CCodeExpressionStatement (pending));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1480,7 +1474,7 @@ internal class Vala.DBusClientModule : DBusModule {
completecall.add_argument (async_result_creation);
block.add_statement (new CCodeExpressionStatement (completecall));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1541,7 +1535,7 @@ internal class Vala.DBusClientModule : DBusModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
}
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
diff --git a/gobject/valadbusservermodule.vala b/gobject/valadbusservermodule.vala
index 6580364..d13e8e1 100644
--- a/gobject/valadbusservermodule.vala
+++ b/gobject/valadbusservermodule.vala
@@ -225,7 +225,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("reply")));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -307,7 +307,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
message_unref.add_argument (new CCodeIdentifier ("_message"));
block.add_statement (new CCodeExpressionStatement (message_unref));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -325,12 +325,12 @@ internal class Vala.DBusServerModule : DBusClientModule {
if (!sym.is_internal_symbol ()) {
dbus_glib_h_needed_in_header = true;
- header_type_member_declaration.append (cfunc.copy ());
+ header_declarations.add_type_member_declaration (cfunc.copy ());
} else {
dbus_glib_h_needed = true;
cfunc.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (cfunc.copy ());
+ source_declarations.add_type_member_declaration (cfunc.copy ());
}
var block = new CCodeBlock ();
@@ -387,7 +387,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
cfunc.add_parameter (new CCodeFormalParameter ("connection", "DBusConnection*"));
cfunc.add_parameter (new CCodeFormalParameter ("user_data", "void*"));
- source_type_member_declaration.append (cfunc.copy ());
+ source_declarations.add_type_member_declaration (cfunc.copy ());
var block = new CCodeBlock ();
cfunc.block = block;
@@ -566,7 +566,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("reply")));
}
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -733,7 +733,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("reply")));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -867,7 +867,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("reply")));
}
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1078,7 +1078,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("reply")));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
function.block = block;
source_type_member_definition.append (function);
@@ -1124,10 +1124,10 @@ internal class Vala.DBusServerModule : DBusClientModule {
cfunc.add_parameter (new CCodeFormalParameter ("object", "void*"));
if (!sym.is_internal_symbol ()) {
- header_type_member_declaration.append (cfunc.copy ());
+ header_declarations.add_type_member_declaration (cfunc.copy ());
} else {
cfunc.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (cfunc.copy ());
+ source_declarations.add_type_member_declaration (cfunc.copy ());
}
var block = new CCodeBlock ();
@@ -1231,7 +1231,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
var cdecl = new CCodeDeclaration ("const _DBusObjectVTable");
cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_vtable", vtable));
cdecl.modifiers = CCodeModifiers.STATIC;
- source_constant_declaration.append (cdecl);
+ source_declarations.add_constant_declaration (cdecl);
return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_vtable");
}
@@ -1249,7 +1249,7 @@ internal class Vala.DBusServerModule : DBusClientModule {
var cdecl = new CCodeDeclaration ("const DBusObjectPathVTable");
cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_path_vtable", vtable));
cdecl.modifiers = CCodeModifiers.STATIC;
- source_constant_declaration.append (cdecl);
+ source_declarations.add_constant_declaration (cdecl);
return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_path_vtable");
}
diff --git a/gobject/valagasyncmodule.vala b/gobject/valagasyncmodule.vala
index 85e9884..c6d863a 100644
--- a/gobject/valagasyncmodule.vala
+++ b/gobject/valagasyncmodule.vala
@@ -173,8 +173,8 @@ internal class Vala.GAsyncModule : GSignalModule {
void append_struct (CCodeStruct structure) {
var typename = new CCodeVariableDeclarator (structure.name.substring (1));
var typedef = new CCodeTypeDefinition ("struct " + structure.name, typename);
- source_type_declaration.append (typedef);
- source_type_definition.append (structure);
+ source_declarations.add_type_declaration (typedef);
+ source_declarations.add_type_definition (structure);
}
void append_function (CCodeFunction function) {
@@ -182,9 +182,9 @@ internal class Vala.GAsyncModule : GSignalModule {
function.block = null;
if ((function.modifiers & CCodeModifiers.STATIC) != 0) {
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
} else {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
}
function.block = block;
@@ -264,7 +264,7 @@ internal class Vala.GAsyncModule : GSignalModule {
readyblock.add_statement (new CCodeExpressionStatement (ccall));
readyfunc.modifiers |= CCodeModifiers.STATIC;
- source_type_member_declaration.append (readyfunc.copy ());
+ source_declarations.add_type_member_declaration (readyfunc.copy ());
readyfunc.block = readyblock;
diff --git a/gobject/valagerrormodule.vala b/gobject/valagerrormodule.vala
index 38b4b95..d94feaa 100644
--- a/gobject/valagerrormodule.vala
+++ b/gobject/valagerrormodule.vala
@@ -35,16 +35,16 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
cenum = new CCodeEnum (edomain.get_cname ());
if (edomain.source_reference.comment != null) {
- header_type_definition.append (new CCodeComment (edomain.source_reference.comment));
+ header_declarations.add_type_definition (new CCodeComment (edomain.source_reference.comment));
}
- header_type_definition.append (cenum);
+ header_declarations.add_type_definition (cenum);
edomain.accept_children (codegen);
string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
var error_domain_define = new CCodeMacroReplacement (edomain.get_upper_case_cname (), quark_fun_name + " ()");
- header_type_definition.append (error_domain_define);
+ header_declarations.add_type_definition (error_domain_define);
var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
var cquark_block = new CCodeBlock ();
@@ -54,7 +54,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
cquark_block.add_statement (new CCodeReturnStatement (cquark_call));
- header_type_member_declaration.append (cquark_fun.copy ());
+ header_declarations.add_type_member_declaration (cquark_fun.copy ());
cquark_fun.block = cquark_block;
source_type_member_definition.append (cquark_fun);
diff --git a/gobject/valagobjectmodule.vala b/gobject/valagobjectmodule.vala
index 844a3bc..030c18b 100644
--- a/gobject/valagobjectmodule.vala
+++ b/gobject/valagobjectmodule.vala
@@ -89,43 +89,40 @@ internal class Vala.GObjectModule : GTypeModule {
instance_finalize_fragment = new CCodeFragment ();
- CCodeFragment decl_frag;
- CCodeFragment def_frag;
+ CCodeDeclarationSpace decl_space;
if (cl.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
+ decl_space = header_declarations;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
+ decl_space = source_declarations;
}
if (is_gtypeinstance) {
- decl_frag.append (new CCodeNewline ());
+ decl_space.add_type_declaration (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (cl.get_lower_case_cname (null));
- decl_frag.append (new CCodeMacroReplacement (cl.get_type_id (), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement (cl.get_type_id (), macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (cl.get_type_id (), cl.get_cname ());
- decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname (null)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (cl.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_CLASS_CAST ((klass), %s, %sClass))".printf (cl.get_type_id (), cl.get_cname ());
- decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (cl.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (cl.get_type_id ());
- decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (get_type_check_function (cl)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_type_check_function (cl)), macro));
macro = "(G_TYPE_CHECK_CLASS_TYPE ((klass), %s))".printf (cl.get_type_id ());
- decl_frag.append (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (get_type_check_function (cl)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_CLASS(klass)".printf (get_type_check_function (cl)), macro));
macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (cl.get_type_id (), cl.get_cname ());
- decl_frag.append (new CCodeMacroReplacement ("%s_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), macro));
- decl_frag.append (new CCodeNewline ());
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_GET_CLASS(obj)".printf (cl.get_upper_case_cname (null)), macro));
+ decl_space.add_type_declaration (new CCodeNewline ());
}
if (cl.access == SymbolAccessibility.PRIVATE
|| cl.source_reference.file.cycle == null) {
// no file dependency cycle for private symbols
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (instance_struct.name), new CCodeVariableDeclarator (cl.get_cname ())));
}
if (cl.base_class != null) {
@@ -144,15 +141,15 @@ internal class Vala.GObjectModule : GTypeModule {
if (cl.access == SymbolAccessibility.PRIVATE
|| cl.source_reference.file.cycle == null) {
// no file dependency cycle for private symbols
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator ("%sClass".printf (cl.get_cname ()))));
}
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (cl.get_cname ()))));
if (cl.has_class_private_fields) {
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_priv_struct.name), new CCodeVariableDeclarator ("%sClassPrivate".printf (cl.get_cname ()))));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_priv_struct.name), new CCodeVariableDeclarator ("%sClassPrivate".printf (cl.get_cname ()))));
var cdecl = new CCodeDeclaration ("GQuark");
cdecl.add_declarator (new CCodeVariableDeclarator ("_vala_%s_class_private_quark".printf (cl.get_lower_case_cname ()), new CCodeConstant ("0")));
cdecl.modifiers = CCodeModifiers.STATIC;
- decl_frag.append (cdecl);
+ decl_space.add_type_declaration (cdecl);
}
instance_struct.add_field ("%sPrivate *".printf (cl.get_cname ()), "priv");
@@ -168,26 +165,26 @@ internal class Vala.GObjectModule : GTypeModule {
}
if (cl.source_reference.comment != null) {
- def_frag.append (new CCodeComment (cl.source_reference.comment));
+ decl_space.add_type_definition (new CCodeComment (cl.source_reference.comment));
}
- def_frag.append (instance_struct);
+ decl_space.add_type_definition (instance_struct);
if (is_gtypeinstance) {
- def_frag.append (type_struct);
+ decl_space.add_type_definition (type_struct);
/* only add the *Private struct if it is not empty, i.e. we actually have private data */
if (cl.has_private_fields || cl.get_type_parameters ().size > 0) {
- source_type_member_declaration.append (instance_priv_struct);
+ source_declarations.add_type_member_declaration (instance_priv_struct);
var macro = "(G_TYPE_INSTANCE_GET_PRIVATE ((o), %s, %sPrivate))".printf (cl.get_type_id (), cl.get_cname ());
- source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
+ source_declarations.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (cl.get_upper_case_cname (null)), macro));
}
if (cl.has_class_private_fields) {
- source_type_member_declaration.append (type_priv_struct);
+ source_declarations.add_type_member_declaration (type_priv_struct);
var macro = "((%sClassPrivate *) g_type_get_qdata (type, _vala_%s_class_private_quark))".printf (cl.get_cname(), cl.get_lower_case_cname ());
- source_type_member_declaration.append (new CCodeMacroReplacement ("%s_GET_CLASS_PRIVATE(type)".printf (cl.get_upper_case_cname (null)), macro));
+ source_declarations.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_CLASS_PRIVATE(type)".printf (cl.get_upper_case_cname (null)), macro));
}
- source_type_member_declaration.append (prop_enum);
+ source_declarations.add_type_member_declaration (prop_enum);
}
cl.accept_children (codegen);
@@ -196,9 +193,9 @@ internal class Vala.GObjectModule : GTypeModule {
if (is_fundamental) {
param_spec_struct = new CCodeStruct ( "_%sParamSpec%s".printf(cl.parent_symbol.get_cprefix (), cl.name));
param_spec_struct.add_field ("GParamSpec", "parent_instance");
- def_frag.append (param_spec_struct);
+ decl_space.add_type_definition (param_spec_struct);
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (param_spec_struct.name), new CCodeVariableDeclarator ( "%sParamSpec%s".printf(cl.parent_symbol.get_cprefix (), cl.name))));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (param_spec_struct.name), new CCodeVariableDeclarator ( "%sParamSpec%s".printf(cl.parent_symbol.get_cprefix (), cl.name))));
gvaluecollector_h_needed = true;
@@ -253,9 +250,9 @@ internal class Vala.GObjectModule : GTypeModule {
var type_fun = new ClassRegisterFunction (cl, context);
type_fun.init_from_type (in_plugin);
if (cl.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (type_fun.get_declaration ());
+ header_declarations.add_type_member_declaration (type_fun.get_declaration ());
} else {
- source_type_member_declaration.append (type_fun.get_declaration ());
+ source_declarations.add_type_member_declaration (type_fun.get_declaration ());
}
source_type_member_definition.append (type_fun.get_definition ());
@@ -278,11 +275,11 @@ internal class Vala.GObjectModule : GTypeModule {
unref_fun.add_parameter (new CCodeFormalParameter ("instance", "gpointer"));
if (cl.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (ref_fun.copy ());
- header_type_member_declaration.append (unref_fun.copy ());
+ header_declarations.add_type_member_declaration (ref_fun.copy ());
+ header_declarations.add_type_member_declaration (unref_fun.copy ());
} else {
- source_type_member_declaration.append (ref_fun.copy ());
- source_type_member_declaration.append (unref_fun.copy ());
+ source_declarations.add_type_member_declaration (ref_fun.copy ());
+ source_declarations.add_type_member_declaration (unref_fun.copy ());
}
var ref_block = new CCodeBlock ();
@@ -338,9 +335,9 @@ internal class Vala.GObjectModule : GTypeModule {
function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
if (cl.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
} else {
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
}
var cblock = new CCodeBlock ();
@@ -597,9 +594,9 @@ internal class Vala.GObjectModule : GTypeModule {
if (cl.access == SymbolAccessibility.PRIVATE) {
function.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
} else {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
}
var init_block = new CCodeBlock ();
@@ -642,9 +639,9 @@ internal class Vala.GObjectModule : GTypeModule {
if (cl.access == SymbolAccessibility.PRIVATE) {
function.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
} else {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
}
var vpointer = new CCodeMemberAccess(new CCodeMemberAccess.pointer (new CCodeIdentifier ("value"), "data[0]"),"v_pointer");
@@ -654,7 +651,7 @@ internal class Vala.GObjectModule : GTypeModule {
var ctypedecl = new CCodeDeclaration (cl.get_cname()+"*");
ctypedecl.add_declarator ( new CCodeVariableDeclarator ("old"));
- init_block.add_statement (ctypedecl);
+ init_block.add_statement (ctypedecl);
var ccall_typecheck = new CCodeFunctionCall (new CCodeIdentifier ("G_TYPE_CHECK_VALUE_TYPE"));
ccall_typecheck.add_argument (new CCodeIdentifier ( "value" ));
@@ -718,9 +715,9 @@ internal class Vala.GObjectModule : GTypeModule {
if (cl.access == SymbolAccessibility.PRIVATE) {
function.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
} else {
- header_type_member_declaration.append (function.copy ());
+ header_declarations.add_type_member_declaration (function.copy ());
}
var vpointer = new CCodeMemberAccess(new CCodeMemberAccess.pointer (new CCodeIdentifier ("value"), "data[0]"),"v_pointer");
@@ -778,7 +775,7 @@ internal class Vala.GObjectModule : GTypeModule {
block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("priv"), ccall)));
- source_include_directives.append (new CCodeIncludeDirective ("string.h"));
+ source_declarations.add_include ("string.h");
iftrue = new CCodeBlock ();
ccall = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
@@ -838,7 +835,7 @@ internal class Vala.GObjectModule : GTypeModule {
parent_var_decl.initializer = new CCodeConstant ("NULL");
parent_decl.add_declarator (parent_var_decl);
parent_decl.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (parent_decl);
+ source_declarations.add_type_member_declaration (parent_decl);
ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_peek_parent"));
ccall.add_argument (new CCodeIdentifier ("klass"));
var parent_assignment = new CCodeAssignment (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))), ccall);
@@ -1084,7 +1081,7 @@ internal class Vala.GObjectModule : GTypeModule {
parent_var_decl.initializer = new CCodeConstant ("NULL");
parent_decl.add_declarator (parent_var_decl);
parent_decl.modifiers = CCodeModifiers.STATIC;
- source_type_member_declaration.append (parent_decl);
+ source_declarations.add_type_member_declaration (parent_decl);
ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_peek_parent"));
ccall.add_argument (new CCodeIdentifier ("iface"));
var parent_assignment = new CCodeAssignment (new CCodeIdentifier (parent_iface_var), ccall);
@@ -1207,7 +1204,7 @@ internal class Vala.GObjectModule : GTypeModule {
if (cl.is_compact) {
// Add declaration, since the instance_init function is explicitly called
// by the creation methods
- source_type_member_declaration.append (instance_init.copy ());
+ source_declarations.add_type_member_declaration (instance_init.copy ());
}
var init_block = new CCodeBlock ();
@@ -1229,7 +1226,7 @@ internal class Vala.GObjectModule : GTypeModule {
function.modifiers = CCodeModifiers.STATIC;
function.add_parameter (new CCodeFormalParameter ("klass", cl.get_cname () + "Class *"));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
var cblock = new CCodeBlock ();
@@ -1248,7 +1245,7 @@ internal class Vala.GObjectModule : GTypeModule {
function.modifiers = CCodeModifiers.STATIC;
function.add_parameter (new CCodeFormalParameter ("klass", cl.get_cname () + "Class *"));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
var cblock = new CCodeBlock ();
@@ -1273,7 +1270,7 @@ internal class Vala.GObjectModule : GTypeModule {
function.add_parameter (new CCodeFormalParameter ("obj", fundamental_class.get_cname () + "*"));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
var cblock = new CCodeBlock ();
@@ -1756,7 +1753,7 @@ internal class Vala.GObjectModule : GTypeModule {
function.add_parameter (new CCodeFormalParameter ("n_construct_properties", "guint"));
function.add_parameter (new CCodeFormalParameter ("construct_properties", "GObjectConstructParam *"));
- source_type_member_declaration.append (function.copy ());
+ source_declarations.add_type_member_declaration (function.copy ());
var cblock = new CCodeBlock ();
@@ -1880,7 +1877,7 @@ internal class Vala.GObjectModule : GTypeModule {
generate_gobject_property_getter_wrapper (prop, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -1906,7 +1903,7 @@ internal class Vala.GObjectModule : GTypeModule {
generate_gobject_property_setter_wrapper (prop, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
@@ -1960,7 +1957,7 @@ internal class Vala.GObjectModule : GTypeModule {
generate_gobject_connect_wrapper (sig, block);
// append to C source file
- source_type_member_declaration.append (func.copy ());
+ source_declarations.add_type_member_declaration (func.copy ());
func.block = block;
source_type_member_definition.append (func);
diff --git a/gobject/valagtypemodule.vala b/gobject/valagtypemodule.vala
index ad676e7..42afdbb 100644
--- a/gobject/valagtypemodule.vala
+++ b/gobject/valagtypemodule.vala
@@ -38,44 +38,41 @@ internal class Vala.GTypeModule : GErrorModule {
return;
}
- CCodeFragment decl_frag;
- CCodeFragment def_frag;
+ CCodeDeclarationSpace decl_space;
if (iface.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
- def_frag = header_type_definition;
+ decl_space = header_declarations;
} else {
- decl_frag = source_type_declaration;
- def_frag = source_type_definition;
+ decl_space = source_declarations;
}
type_struct = new CCodeStruct ("_%s".printf (iface.get_type_cname ()));
- decl_frag.append (new CCodeNewline ());
+ decl_space.add_type_declaration (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (iface.get_lower_case_cname (null));
- decl_frag.append (new CCodeMacroReplacement (iface.get_type_id (), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement (iface.get_type_id (), macro));
macro = "(G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, %s))".printf (iface.get_type_id (), iface.get_cname ());
- decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (iface.get_upper_case_cname (null)), macro));
macro = "(G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))".printf (iface.get_type_id ());
- decl_frag.append (new CCodeMacroReplacement ("%s(obj)".printf (get_type_check_function (iface)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_type_check_function (iface)), macro));
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (iface.get_type_id (), iface.get_type_cname ());
- decl_frag.append (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
- decl_frag.append (new CCodeNewline ());
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s_GET_INTERFACE(obj)".printf (iface.get_upper_case_cname (null)), macro));
+ decl_space.add_type_declaration (new CCodeNewline ());
if (iface.source_reference.file.cycle == null) {
- decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
- decl_frag.append (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (iface.get_cname ()), new CCodeVariableDeclarator (iface.get_cname ())));
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_struct.name), new CCodeVariableDeclarator (iface.get_type_cname ())));
}
type_struct.add_field ("GTypeInterface", "parent_iface");
if (iface.source_reference.comment != null) {
- def_frag.append (new CCodeComment (iface.source_reference.comment));
+ decl_space.add_type_definition (new CCodeComment (iface.source_reference.comment));
}
- def_frag.append (type_struct);
+ decl_space.add_type_definition (type_struct);
iface.accept_children (codegen);
@@ -84,9 +81,9 @@ internal class Vala.GTypeModule : GErrorModule {
var type_fun = new InterfaceRegisterFunction (iface, context);
type_fun.init_from_type ();
if (iface.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (type_fun.get_declaration ());
+ header_declarations.add_type_member_declaration (type_fun.get_declaration ());
} else {
- source_type_member_declaration.append (type_fun.get_declaration ());
+ source_declarations.add_type_member_declaration (type_fun.get_declaration ());
}
source_type_member_definition.append (type_fun.get_definition ());
@@ -146,23 +143,23 @@ internal class Vala.GTypeModule : GErrorModule {
public override void visit_struct (Struct st) {
base.visit_struct (st);
- CCodeFragment decl_frag;
+ CCodeDeclarationSpace decl_space;
if (st.access != SymbolAccessibility.PRIVATE) {
- decl_frag = header_type_declaration;
+ decl_space = header_declarations;
} else {
- decl_frag = source_type_declaration;
+ decl_space = source_declarations;
}
- decl_frag.append (new CCodeNewline ());
+ decl_space.add_type_declaration (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (st.get_lower_case_cname (null));
- decl_frag.append (new CCodeMacroReplacement (st.get_type_id (), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement (st.get_type_id (), macro));
var type_fun = new StructRegisterFunction (st, context);
type_fun.init_from_type (false);
if (st.access != SymbolAccessibility.PRIVATE) {
- header_type_member_declaration.append (type_fun.get_declaration ());
+ header_declarations.add_type_member_declaration (type_fun.get_declaration ());
} else {
- source_type_member_declaration.append (type_fun.get_declaration ());
+ source_declarations.add_type_member_declaration (type_fun.get_declaration ());
}
source_type_member_definition.append (type_fun.get_definition ());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]