[vala/emit: 3/6] Replace CCodeDeclarationSpace by CCodeFile



commit 1de73dca3de2df0a28f0695484764caecb6b6f78
Author: Jürg Billeter <j bitron ch>
Date:   Fri Aug 13 14:25:19 2010 +0200

    Replace CCodeDeclarationSpace by CCodeFile

 ccode/Makefile.am                        |    1 +
 ccode/valaccodefile.vala                 |  173 ++++++++++++++
 codegen/Makefile.am                      |    1 -
 codegen/valaccodearraymodule.vala        |   42 ++--
 codegen/valaccodeassignmentmodule.vala   |    4 +-
 codegen/valaccodebasemodule.vala         |  371 +++++++++++-------------------
 codegen/valaccodecontrolflowmodule.vala  |    2 +-
 codegen/valaccodedeclarationspace.vala   |   66 ------
 codegen/valaccodedelegatemodule.vala     |   18 +-
 codegen/valaccodememberaccessmodule.vala |   12 +-
 codegen/valaccodemethodcallmodule.vala   |    6 +-
 codegen/valaccodemethodmodule.vala       |   38 ++--
 codegen/valaccodestructmodule.vala       |   20 +-
 codegen/valadbusclientmodule.vala        |  118 +++++-----
 codegen/valadbusmodule.vala              |   30 ++--
 codegen/valadbusservermodule.vala        |   50 ++--
 codegen/valadovaarraymodule.vala         |    2 +-
 codegen/valadovaassignmentmodule.vala    |    2 +-
 codegen/valadovabasemodule.vala          |  169 ++++----------
 codegen/valadovadelegatemodule.vala      |   24 +-
 codegen/valadovaerrormodule.vala         |    2 +-
 codegen/valadovamemberaccessmodule.vala  |   12 +-
 codegen/valadovamethodcallmodule.vala    |    2 +-
 codegen/valadovaobjectmodule.vala        |  174 +++++++-------
 codegen/valadovastructmodule.vala        |    6 +-
 codegen/valadovavaluemodule.vala         |   62 +++---
 codegen/valagasyncmodule.vala            |   34 ++--
 codegen/valagdbusclientmodule.vala       |   56 +++---
 codegen/valagdbusmodule.vala             |   10 +-
 codegen/valagdbusservermodule.vala       |   76 +++---
 codegen/valagerrormodule.vala            |   12 +-
 codegen/valagobjectmodule.vala           |   36 ++--
 codegen/valagsignalmodule.vala           |    6 +-
 codegen/valagtypemodule.vala             |  110 +++++-----
 codegen/valagvariantmodule.vala          |    8 +-
 35 files changed, 844 insertions(+), 911 deletions(-)
---
diff --git a/ccode/Makefile.am b/ccode/Makefile.am
index 1fd4a0d..9d54a09 100644
--- a/ccode/Makefile.am
+++ b/ccode/Makefile.am
@@ -32,6 +32,7 @@ libvalaccode_la_VALASOURCES = \
 	valaccodeenumvalue.vala \
 	valaccodeexpression.vala \
 	valaccodeexpressionstatement.vala \
+	valaccodefile.vala \
 	valaccodeformalparameter.vala \
 	valaccodeforstatement.vala \
 	valaccodefragment.vala \
diff --git a/ccode/valaccodefile.vala b/ccode/valaccodefile.vala
new file mode 100644
index 0000000..8bb8ecf
--- /dev/null
+++ b/ccode/valaccodefile.vala
@@ -0,0 +1,173 @@
+/* valaccodefile.vala
+ *
+ * Copyright (C) 2009-2010  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>
+ */
+
+
+public class Vala.CCodeFile {
+	public bool is_header { get; set; }
+
+	Set<string> declarations = new HashSet<string> (str_hash, str_equal);
+	Set<string> includes = new HashSet<string> (str_hash, str_equal);
+	CCodeFragment comments = new CCodeFragment ();
+	CCodeFragment include_directives = new CCodeFragment ();
+	CCodeFragment type_declaration = new CCodeFragment ();
+	CCodeFragment type_definition = new CCodeFragment ();
+	CCodeFragment type_member_declaration = new CCodeFragment ();
+	CCodeFragment constant_declaration = new CCodeFragment ();
+	CCodeFragment type_member_definition = new CCodeFragment ();
+
+	public bool add_declaration (string name) {
+		if (name in declarations) {
+			return true;
+		}
+		declarations.add (name);
+		return false;
+	}
+
+	public void add_comment (CCodeComment comment) {
+		comments.append (comment);
+	}
+
+	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_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);
+	}
+
+	public void add_type_member_definition (CCodeNode node) {
+		type_member_definition.append (node);
+	}
+
+	public void add_function (CCodeFunction func) {
+		type_member_definition.append (func);
+	}
+
+	public List<string> get_symbols () {
+		var symbols = new ArrayList<string> ();
+		foreach (CCodeNode node in type_member_declaration.get_children ()) {
+			var func = node as CCodeFunction;
+			if (func != null) {
+				symbols.add (func.name);
+			}
+		}
+		return symbols;
+	}
+
+	static string get_define_for_filename (string filename) {
+		var define = new StringBuilder ("__");
+
+		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 bool store (string filename, string? source_filename, bool write_version, bool line_directives, string? begin_decls = null, string? end_decls = null) {
+		var writer = new CCodeWriter (filename, source_filename);
+		if (!writer.open (write_version)) {
+			return false;
+		}
+
+		if (!is_header) {
+			writer.line_directives = line_directives;
+
+			comments.write (writer);
+			writer.write_newline ();
+			include_directives.write (writer);
+			writer.write_newline ();
+			type_declaration.write_combined (writer);
+			writer.write_newline ();
+			type_definition.write_combined (writer);
+			writer.write_newline ();
+			type_member_declaration.write_declaration (writer);
+			writer.write_newline ();
+			type_member_declaration.write (writer);
+			writer.write_newline ();
+			constant_declaration.write_combined (writer);
+			writer.write_newline ();
+			type_member_definition.write (writer);
+			writer.write_newline ();
+		} else {
+			writer.write_newline ();
+
+			var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
+			once.append (new CCodeNewline ());
+			once.append (include_directives);
+			once.append (new CCodeNewline ());
+
+			if (begin_decls != null) {
+				once.append (new CCodeIdentifier (begin_decls));
+				once.append (new CCodeNewline ());
+			}
+
+			once.append (new CCodeNewline ());
+			once.append (type_declaration);
+			once.append (new CCodeNewline ());
+			once.append (type_definition);
+			once.append (new CCodeNewline ());
+			once.append (type_member_declaration);
+			once.append (new CCodeNewline ());
+			once.append (constant_declaration);
+			once.append (new CCodeNewline ());
+
+			if (begin_decls != null) {
+				once.append (new CCodeIdentifier (end_decls));
+				once.append (new CCodeNewline ());
+			}
+
+			once.append (new CCodeNewline ());
+			once.write (writer);
+		}
+
+		writer.close ();
+
+		return true;
+	}
+}
+
diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index 3bb5b5b..7da6689 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -20,7 +20,6 @@ libvala_la_VALASOURCES = \
 	valaccodebasemodule.vala \
 	valaccodecompiler.vala \
 	valaccodecontrolflowmodule.vala \
-	valaccodedeclarationspace.vala \
 	valaccodedelegatemodule.vala \
 	valaccodememberaccessmodule.vala \
 	valaccodemethodcallmodule.vala \
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index d0966e6..2c7a345 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -61,7 +61,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		CCodeFunctionCall gnew;
 		if (context.profile == Profile.POSIX) {
-			source_declarations.add_include ("stdlib.h");
+			cfile.add_include ("stdlib.h");
 			gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
 		} else {
 			gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
@@ -493,7 +493,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 	public override string? append_struct_array_free (Struct st) {
 		string cname = "_vala_%s_array_free".printf (st.get_cname ());;
 
-		if (source_declarations.add_declaration (cname)) {
+		if (cfile.add_declaration (cname)) {
 			return cname;
 		}
 
@@ -501,7 +501,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		fun.modifiers = CCodeModifiers.STATIC;
 		fun.add_parameter (new CCodeFormalParameter ("array", "%s*".printf (st.get_cname ())));
 		fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
-		source_declarations.add_type_member_declaration (fun.copy ());
+		cfile.add_type_member_declaration (fun.copy ());
 
 		var cdofree = new CCodeBlock ();
 
@@ -520,7 +520,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		carrfree.add_argument (new CCodeIdentifier ("array"));
 		fun.block.add_statement (new CCodeExpressionStatement (carrfree));
 
-		source_type_member_definition.append (fun);
+		cfile.add_function (fun);
 
 		return cname;
 	}
@@ -554,7 +554,7 @@ public 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_declarations.add_type_member_declaration (fun.copy ());
+		cfile.add_type_member_declaration (fun.copy ());
 
 		var cdofree = new CCodeBlock ();
 
@@ -570,7 +570,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		fun.block = new CCodeBlock ();
 		fun.block.add_statement (cif);
 
-		source_type_member_definition.append (fun);
+		cfile.add_function (fun);
 
 		// _vala_array_free frees elements and array
 
@@ -579,7 +579,7 @@ public 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_declarations.add_type_member_declaration (fun.copy ());
+		cfile.add_type_member_declaration (fun.copy ());
 
 		// call _vala_array_destroy to free the array elements
 		var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy"));
@@ -594,11 +594,11 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		carrfree.add_argument (new CCodeIdentifier ("array"));
 		fun.block.add_statement (new CCodeExpressionStatement (carrfree));
 
-		source_type_member_definition.append (fun);
+		cfile.add_function (fun);
 	}
 
 	public override void append_vala_array_move () {
-		source_declarations.add_include ("string.h");
+		cfile.add_include ("string.h");
 
 		// assumes that overwritten array elements are null before invocation
 		// FIXME will leak memory if that's not the case
@@ -609,7 +609,7 @@ public 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_declarations.add_type_member_declaration (fun.copy ());
+		cfile.add_type_member_declaration (fun.copy ());
 
 		var array = new CCodeCastExpression (new CCodeIdentifier ("array"), "char*");
 		var element_size = new CCodeIdentifier ("element_size");
@@ -644,14 +644,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		fun.block.add_statement (new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, src, dest), czeroblock1, czeroblock2));
 
-		source_type_member_definition.append (fun);
+		cfile.add_function (fun);
 	}
 
 	public override void append_vala_array_length () {
 		var fun = new CCodeFunction ("_vala_array_length", "gint");
 		fun.modifiers = CCodeModifiers.STATIC;
 		fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
-		source_declarations.add_type_member_declaration (fun.copy ());
+		cfile.add_type_member_declaration (fun.copy ());
 
 		var block = new CCodeBlock ();
 
@@ -676,7 +676,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		fun.block = block;
 
-		source_type_member_definition.append (fun);
+		cfile.add_function (fun);
 	}
 
 	public override CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
@@ -819,10 +819,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return dup_func;
 	}
@@ -868,7 +868,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 			pop_context ();
 		} else {
-			source_declarations.add_include ("string.h");
+			cfile.add_include ("string.h");
 
 			var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
 			dup_call.add_argument (new CCodeIdentifier ("dest"));
@@ -883,10 +883,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return dup_func;
 	}
@@ -955,10 +955,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return add_func;
 	}
@@ -999,7 +999,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		assignment.ccodenode = ccall;
 	}
 
-	public override void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+	public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
 		if (!(param.variable_type is ArrayType)) {
 			base.generate_parameter (param, decl_space, cparam_map, carg_map);
 			return;
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index c1009b2..abfb3d8 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -34,7 +34,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 		var prop = (Property) assignment.left.symbol_reference;
 
 		if (!(prop is DynamicProperty)) {
-			generate_property_accessor_declaration (prop.set_accessor, source_declarations);
+			generate_property_accessor_declaration (prop.set_accessor, cfile);
 
 			if (!prop.external && prop.external_package) {
 				// internal VAPI properties
@@ -212,7 +212,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 		CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
 		CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
 
-		source_declarations.add_include ("string.h");
+		cfile.add_include ("string.h");
 
 		// it is necessary to use memcpy for fixed-length (stack-allocated) arrays
 		// simple assignments do not work in C
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 8c54c7e..37064cb 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -148,19 +148,16 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		return block;
 	}
 
-	public CCodeDeclarationSpace header_declarations;
-	public CCodeDeclarationSpace internal_header_declarations;
-	public CCodeDeclarationSpace source_declarations;
+	public CCodeFile header_file;
+	public CCodeFile internal_header_file;
+	public CCodeFile cfile;
 
-	public CCodeFragment source_signal_marshaller_declaration;
-	public CCodeFragment source_type_member_definition;
 	public CCodeFragment class_init_fragment;
 	public CCodeFragment base_init_fragment;
 	public CCodeFragment class_finalize_fragment;
 	public CCodeFragment base_finalize_fragment;
 	public CCodeFragment instance_init_fragment;
 	public CCodeFragment instance_finalize_fragment;
-	public CCodeFragment source_signal_marshaller_definition;
 	
 	public CCodeStruct param_spec_struct;
 	public CCodeStruct closure_struct;
@@ -412,10 +409,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			}
 		}
 
-		header_declarations = new CCodeDeclarationSpace ();
-		header_declarations.is_header = true;
-		internal_header_declarations = new CCodeDeclarationSpace ();
-		internal_header_declarations.is_header = true;
+		header_file = new CCodeFile ();
+		header_file.is_header = true;
+		internal_header_file = new CCodeFile ();
+		internal_header_file.is_header = true;
 
 		/* we're only interested in non-pkg source files */
 		var source_files = context.get_source_files ();
@@ -433,12 +430,9 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				return;
 			}
 
-			foreach (CCodeNode node in header_declarations.type_member_declaration.get_children ()) {
-				if (node is CCodeFunction) {
-					var func = (CCodeFunction) node;
-					stream.puts (func.name);
-					stream.putc ('\n');
-				}
+			foreach (string symbol in header_file.get_symbols ()) {
+				stream.puts (symbol);
+				stream.putc ('\n');
 			}
 
 			stream = null;
@@ -446,80 +440,28 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// generate C header file for public API
 		if (context.header_filename != null) {
-			var writer = new CCodeWriter (context.header_filename);
-			if (!writer.open (context.version_header)) {
-				Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
-				return;
-			}
-			writer.write_newline ();
-
-			var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.include_directives);
-			once.append (new CCodeNewline ());
-
+			bool ret;
 			if (context.profile == Profile.GOBJECT) {
-				once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
-				once.append (new CCodeNewline ());
+				ret = header_file.store (context.header_filename, null, context.version_header, false, "G_BEGIN_DECLS", "G_END_DECLS");
+			} else {
+				ret = header_file.store (context.header_filename, null, context.version_header, false);
 			}
-
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.type_declaration);
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.type_definition);
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.type_member_declaration);
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.constant_declaration);
-			once.append (new CCodeNewline ());
-
-			if (context.profile == Profile.GOBJECT) {
-				once.append (new CCodeIdentifier ("G_END_DECLS"));
-				once.append (new CCodeNewline ());
+			if (!ret) {
+				Report.error (null, "unable to open `%s' for writing".printf (context.header_filename));
 			}
-
-			once.append (new CCodeNewline ());
-			once.write (writer);
-			writer.close ();
 		}
 
 		// generate C header file for internal API
 		if (context.internal_header_filename != null) {
-			var writer = new CCodeWriter (context.internal_header_filename);
-			if (!writer.open (context.version_header)) {
-				Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
-				return;
-			}
-			writer.write_newline ();
-
-			var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
-			once.append (new CCodeNewline ());
-			once.append (internal_header_declarations.include_directives);
-			once.append (new CCodeNewline ());
-
+			bool ret;
 			if (context.profile == Profile.GOBJECT) {
-				once.append (new CCodeIdentifier ("G_BEGIN_DECLS"));
-				once.append (new CCodeNewline ());
+				ret = internal_header_file.store (context.internal_header_filename, null, context.version_header, false, "G_BEGIN_DECLS", "G_END_DECLS");
+			} else {
+				ret = internal_header_file.store (context.internal_header_filename, null, context.version_header, false);
 			}
-
-			once.append (new CCodeNewline ());
-			once.append (internal_header_declarations.type_declaration);
-			once.append (new CCodeNewline ());
-			once.append (internal_header_declarations.type_definition);
-			once.append (new CCodeNewline ());
-			once.append (internal_header_declarations.type_member_declaration);
-			once.append (new CCodeNewline ());
-			once.append (internal_header_declarations.constant_declaration);
-			once.append (new CCodeNewline ());
-
-			if (context.profile == Profile.GOBJECT) {
-				once.append (new CCodeIdentifier ("G_END_DECLS"));
-				once.append (new CCodeNewline ());
+			if (!ret) {
+				Report.error (null, "unable to open `%s' for writing".printf (context.internal_header_filename));
 			}
-
-			once.append (new CCodeNewline ());
-			once.write (writer);
-			writer.close ();
 		}
 	}
 
@@ -540,7 +482,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
-	public bool add_symbol_declaration (CCodeDeclarationSpace decl_space, Symbol sym, string name) {
+	public bool add_symbol_declaration (CCodeFile decl_space, Symbol sym, string name) {
 		if (decl_space.add_declaration (name)) {
 			return true;
 		}
@@ -603,13 +545,13 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	private void append_vala_strcmp0 () {
-		source_declarations.add_include ("string.h");;
+		cfile.add_include ("string.h");;
 
 		var fun = new CCodeFunction ("_vala_strcmp0", "int");
 		fun.modifiers = CCodeModifiers.STATIC;
 		fun.add_parameter (new CCodeFormalParameter ("str1", "const char *"));
 		fun.add_parameter (new CCodeFormalParameter ("str2", "const char *"));
-		source_declarations.add_type_member_declaration (fun.copy ());
+		cfile.add_type_member_declaration (fun.copy ());
 
 		// (str1 != str2)
 		var cineq = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("str1"), new CCodeIdentifier ("str2"));
@@ -637,14 +579,11 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		// return strcmp (str1, str2);
 		fun.block.add_statement (new CCodeReturnStatement (ccall));
 
-		source_type_member_definition.append (fun);
+		cfile.add_function (fun);
 	}
 
 	public override void visit_source_file (SourceFile source_file) {
-		source_declarations = new CCodeDeclarationSpace ();
-		source_type_member_definition = new CCodeFragment ();
-		source_signal_marshaller_definition = new CCodeFragment ();
-		source_signal_marshaller_declaration = new CCodeFragment ();
+		cfile = new CCodeFile ();
 		
 		user_marshal_set = new HashSet<string> (str_hash, str_equal);
 		
@@ -660,10 +599,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		generated_external_symbols = new HashSet<Symbol> ();
 
 		if (context.profile == Profile.GOBJECT) {
-			header_declarations.add_include ("glib.h");
-			internal_header_declarations.add_include ("glib.h");
-			source_declarations.add_include ("glib.h");
-			source_declarations.add_include ("glib-object.h");
+			header_file.add_include ("glib.h");
+			internal_header_file.add_include ("glib.h");
+			cfile.add_include ("glib.h");
+			cfile.add_include ("glib-object.h");
 		}
 
 		source_file.accept_children (this);
@@ -686,73 +625,25 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		}
 
 		if (gvaluecollector_h_needed) {
-			source_declarations.add_include ("gobject/gvaluecollector.h");
-		}
-
-		var writer = new CCodeWriter (source_file.get_csource_filename (), source_file.filename);
-		if (!writer.open (context.version_header)) {
-			Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
-			return;
+			cfile.add_include ("gobject/gvaluecollector.h");
 		}
-		writer.line_directives = context.debug;
 
 		var comments = source_file.get_comments();
 		if (comments != null) {
 			foreach (Comment comment in comments) {
 				var ccomment = new CCodeComment (comment.content);
-				ccomment.write (writer);
-			}
-		}
-
-		writer.write_newline ();
-		source_declarations.include_directives.write (writer);
-		writer.write_newline ();
-		source_declarations.type_declaration.write_combined (writer);
-		writer.write_newline ();
-		source_declarations.type_definition.write_combined (writer);
-		writer.write_newline ();
-		source_declarations.type_member_declaration.write_declaration (writer);
-		writer.write_newline ();
-		source_declarations.type_member_declaration.write (writer);
-		writer.write_newline ();
-		source_declarations.constant_declaration.write_combined (writer);
-		writer.write_newline ();
-		source_signal_marshaller_declaration.write_declaration (writer);
-		source_signal_marshaller_declaration.write (writer);
-		writer.write_newline ();
-		source_type_member_definition.write (writer);
-		writer.write_newline ();
-		source_signal_marshaller_definition.write (writer);
-		writer.write_newline ();
-		writer.close ();
-
-		source_declarations = null;
-		source_type_member_definition = null;
-		source_signal_marshaller_definition = null;
-		source_signal_marshaller_declaration = null;
-	}
-	
-	private static string get_define_for_filename (string filename) {
-		var define = new StringBuilder ("__");
-		
-		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 ('_');
+				cfile.add_comment (ccomment);
 			}
-		
-			i = i.next_char ();
 		}
-		
-		define.append ("__");
-		
-		return define.str;
+
+		if (!cfile.store (source_file.get_csource_filename (), source_file.filename, context.version_header, context.debug)) {
+			Report.error (null, "unable to open `%s' for writing".printf (source_file.get_csource_filename ()));
+		}
+
+		cfile = null;
 	}
 
-	public virtual bool generate_enum_declaration (Enum en, CCodeDeclarationSpace decl_space) {
+	public virtual bool generate_enum_declaration (Enum en, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, en, en.get_cname ())) {
 			return false;
 		}
@@ -809,16 +700,16 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		en.accept_children (this);
 
 		if (en.comment != null) {
-			source_type_member_definition.append (new CCodeComment (en.comment.content));
+			cfile.add_type_member_definition (new CCodeComment (en.comment.content));
 		}
 
-		generate_enum_declaration (en, source_declarations);
+		generate_enum_declaration (en, cfile);
 
 		if (!en.is_internal_symbol ()) {
-			generate_enum_declaration (en, header_declarations);
+			generate_enum_declaration (en, header_file);
 		}
 		if (!en.is_private_symbol ()) {
-			generate_enum_declaration (en, internal_header_declarations);
+			generate_enum_declaration (en, internal_header_file);
 		}
 	}
 
@@ -855,7 +746,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
-	public void generate_constant_declaration (Constant c, CCodeDeclarationSpace decl_space, bool definition = false) {
+	public void generate_constant_declaration (Constant c, CCodeFile decl_space, bool definition = false) {
 		if (add_symbol_declaration (decl_space, c, c.get_cname ())) {
 			return;
 		}
@@ -896,17 +787,17 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public override void visit_constant (Constant c) {
-		generate_constant_declaration (c, source_declarations, true);
+		generate_constant_declaration (c, cfile, true);
 
 		if (!c.is_internal_symbol ()) {
-			generate_constant_declaration (c, header_declarations);
+			generate_constant_declaration (c, header_file);
 		}
 		if (!c.is_private_symbol ()) {
-			generate_constant_declaration (c, internal_header_declarations);
+			generate_constant_declaration (c, internal_header_file);
 		}
 	}
 
-	public void generate_field_declaration (Field f, CCodeDeclarationSpace decl_space) {
+	public void generate_field_declaration (Field f, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, f, f.get_cname ())) {
 			return;
 		}
@@ -1105,13 +996,13 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				temp_ref_vars.clear ();
 			}
 		} else {
-			generate_field_declaration (f, source_declarations);
+			generate_field_declaration (f, cfile);
 
 			if (!f.is_internal_symbol ()) {
-				generate_field_declaration (f, header_declarations);
+				generate_field_declaration (f, header_file);
 			}
 			if (!f.is_private_symbol ()) {
-				generate_field_declaration (f, internal_header_declarations);
+				generate_field_declaration (f, internal_header_file);
 			}
 
 			lhs = new CCodeIdentifier (f.get_cname ());
@@ -1133,7 +1024,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			} else {
 				var_def.modifiers = CCodeModifiers.STATIC;
 			}
-			source_declarations.add_type_member_declaration (var_def);
+			cfile.add_type_member_declaration (var_def);
 
 			/* add array length fields where necessary */
 			if (f.variable_type is ArrayType && !f.no_array_length) {
@@ -1150,7 +1041,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 						} else {
 							len_def.modifiers = CCodeModifiers.STATIC;
 						}
-						source_declarations.add_type_member_declaration (len_def);
+						cfile.add_type_member_declaration (len_def);
 					}
 
 					if (array_type.rank == 1 && f.is_internal_symbol ()) {
@@ -1159,7 +1050,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 						var cdecl = new CCodeDeclaration (len_type.get_cname ());
 						cdecl.add_declarator (new CCodeVariableDeclarator (get_array_size_cname (f.get_cname ()), new CCodeConstant ("0")));
 						cdecl.modifiers = CCodeModifiers.STATIC;
-						source_declarations.add_type_member_declaration (cdecl);
+						cfile.add_type_member_declaration (cdecl);
 					}
 				}
 			} else if (f.variable_type is DelegateType) {
@@ -1174,7 +1065,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 					} else {
 						target_def.modifiers = CCodeModifiers.STATIC;
 					}
-					source_declarations.add_type_member_declaration (target_def);
+					cfile.add_type_member_declaration (target_def);
 
 					if (delegate_type.value_owned) {
 						var target_destroy_notify_def = new CCodeDeclaration ("GDestroyNotify");
@@ -1184,7 +1075,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 						} else {
 							target_destroy_notify_def.modifiers = CCodeModifiers.STATIC;
 						}
-						source_declarations.add_type_member_declaration (target_destroy_notify_def);
+						cfile.add_type_member_declaration (target_destroy_notify_def);
 
 					}
 				}
@@ -1307,7 +1198,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		prop.accept_children (this);
 	}
 
-	public void generate_type_declaration (DataType type, CCodeDeclarationSpace decl_space) {
+	public void generate_type_declaration (DataType type, CCodeFile decl_space) {
 		if (type is ObjectType) {
 			var object_type = (ObjectType) type;
 			if (object_type.type_symbol is Class) {
@@ -1343,19 +1234,19 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
-	public virtual void generate_class_struct_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_class_struct_declaration (Class cl, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_struct_declaration (Struct st, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_cparameters (Method m, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
+	public virtual void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
 	}
 
-	public void generate_property_accessor_declaration (PropertyAccessor acc, CCodeDeclarationSpace decl_space) {
+	public void generate_property_accessor_declaration (PropertyAccessor acc, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, acc, acc.get_cname ())) {
 			return;
 		}
@@ -1424,7 +1315,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		var prop = (Property) acc.prop;
 
 		if (acc.comment != null) {
-			source_type_member_definition.append (new CCodeComment (acc.comment.content));
+			cfile.add_type_member_definition (new CCodeComment (acc.comment.content));
 		}
 
 		bool returns_real_struct = acc.readable && prop.property_type.is_real_non_null_struct_type ();
@@ -1448,17 +1339,17 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		// do not declare overriding properties and interface implementations
 		if (prop.is_abstract || prop.is_virtual
 		    || (prop.base_property == null && prop.base_interface_property == null)) {
-			generate_property_accessor_declaration (acc, source_declarations);
+			generate_property_accessor_declaration (acc, cfile);
 
 			// do not declare construct-only properties in header files
 			if (acc.readable || acc.writable) {
 				if (!prop.is_internal_symbol ()
 				    && (acc.access == SymbolAccessibility.PUBLIC
 					|| acc.access == SymbolAccessibility.PROTECTED)) {
-					generate_property_accessor_declaration (acc, header_declarations);
+					generate_property_accessor_declaration (acc, header_file);
 				}
 				if (!prop.is_private_symbol () && acc.access != SymbolAccessibility.PRIVATE) {
-					generate_property_accessor_declaration (acc, internal_header_declarations);
+					generate_property_accessor_declaration (acc, internal_header_file);
 				}
 			}
 		}
@@ -1559,7 +1450,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				block.add_statement (new CCodeExpressionStatement (vcall));
 			}
 
-			source_type_member_definition.append (function);
+			cfile.add_function (function);
 		}
 
 		if (!prop.is_abstract) {
@@ -1673,7 +1564,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				function.block.add_statement (new CCodeExpressionStatement (notify_call));
 			}
 
-			source_type_member_definition.append (function);
+			cfile.add_function (function);
 		}
 
 		pop_context ();
@@ -1716,7 +1607,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	void capture_parameter (FormalParameter param, CCodeStruct data, CCodeBlock cblock, int block_id, CCodeBlock free_block) {
-		generate_type_declaration (param.variable_type, source_declarations);
+		generate_type_declaration (param.variable_type, cfile);
 
 		var param_type = param.variable_type.copy ();
 		param_type.value_owned = true;
@@ -1816,7 +1707,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			}
 			foreach (var local in local_vars) {
 				if (local.captured) {
-					generate_type_declaration (local.variable_type, source_declarations);
+					generate_type_declaration (local.variable_type, cfile);
 
 					data.add_field (local.variable_type.get_cname (), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
 
@@ -1925,8 +1816,8 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			}
 
 			var typedef = new CCodeTypeDefinition ("struct _" + struct_name, new CCodeVariableDeclarator (struct_name));
-			source_declarations.add_type_declaration (typedef);
-			source_declarations.add_type_definition (data);
+			cfile.add_type_declaration (typedef);
+			cfile.add_type_definition (data);
 
 			var data_free = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
 			data_free.add_argument (new CCodeIdentifier (struct_name));
@@ -1937,26 +1828,26 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			var ref_fun = new CCodeFunction ("block%d_data_ref".printf (block_id), struct_name + "*");
 			ref_fun.add_parameter (new CCodeFormalParameter ("_data%d_".printf (block_id), struct_name + "*"));
 			ref_fun.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (ref_fun.copy ());
+			cfile.add_type_member_declaration (ref_fun.copy ());
 			ref_fun.block = new CCodeBlock ();
 
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_atomic_int_inc"));
 			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")));
 			ref_fun.block.add_statement (new CCodeExpressionStatement (ccall));
 			ref_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_data%d_".printf (block_id))));
-			source_type_member_definition.append (ref_fun);
+			cfile.add_function (ref_fun);
 
 			var unref_fun = new CCodeFunction ("block%d_data_unref".printf (block_id), "void");
 			unref_fun.add_parameter (new CCodeFormalParameter ("_data%d_".printf (block_id), struct_name + "*"));
 			unref_fun.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (unref_fun.copy ());
+			cfile.add_type_member_declaration (unref_fun.copy ());
 			unref_fun.block = new CCodeBlock ();
 			
 			ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_atomic_int_dec_and_test"));
 			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")));
 			unref_fun.block.add_statement (new CCodeIfStatement (ccall, free_block));
 
-			source_type_member_definition.append (unref_fun);
+			cfile.add_function (unref_fun);
 		}
 
 		foreach (CodeNode stmt in b.get_statements ()) {
@@ -2081,7 +1972,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			visit_end_full_expression (local.initializer);
 		}
 
-		generate_type_declaration (local.variable_type, source_declarations);
+		generate_type_declaration (local.variable_type, cfile);
 
 		if (!local.captured) {
 			if (local.variable_type is ArrayType) {
@@ -2262,7 +2153,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			var array_type = (ArrayType) local.variable_type;
 
 			if (array_type.fixed_length) {
-				source_declarations.add_include ("string.h");
+				cfile.add_include ("string.h");
 
 				// it is necessary to use memcpy for fixed-length (stack-allocated) arrays
 				// simple assignments do not work in C
@@ -2399,7 +2290,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			if (type_id == null) {
 				type_id = "G_TYPE_INVALID";
 			} else {
-				generate_type_declaration (type, source_declarations);
+				generate_type_declaration (type, cfile);
 			}
 			return new CCodeIdentifier (type_id);
 		}
@@ -2605,10 +2496,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = cblock;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return equal_func;
 	}
@@ -2661,10 +2552,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = cblock;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return equal_func;
 	}
@@ -2715,7 +2606,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				copy_call.add_argument (new CCodeIdentifier ("dup"));
 				block.add_statement (new CCodeExpressionStatement (copy_call));
 			} else {
-				source_declarations.add_include ("string.h");
+				cfile.add_include ("string.h");
 
 				var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
 				sizeof_call.add_argument (new CCodeConstant (value_type.data_type.get_cname ()));
@@ -2732,10 +2623,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return dup_func;
 	}
@@ -2769,10 +2660,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return destroy_func;
 	}
@@ -2811,10 +2702,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return destroy_func;
 	}
@@ -2931,9 +2822,9 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			free_call.add_argument (new CCodeMemberAccess.pointer(new CCodeIdentifier("node"), "data"));
 			wrapper_block.add_statement (new CCodeExpressionStatement (free_call));
 			wrapper_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
-			source_declarations.add_type_member_declaration (function.copy ());
+			cfile.add_type_member_declaration (function.copy ());
 			wrapper.block = wrapper_block;
-			source_type_member_definition.append (wrapper);
+			cfile.add_function (wrapper);
 
 			/* Now the code to call g_traverse with the above */
 			element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_node_traverse"));
@@ -2963,10 +2854,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return destroy_func;
 	}
@@ -3033,7 +2924,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 			if (add_wrapper (free0_func)) {
 				var macro = get_unref_expression (new CCodeIdentifier ("var"), type, expr, true);
-				source_declarations.add_type_declaration (new CCodeMacroReplacement.with_expression ("%s(var)".printf (free0_func), macro));
+				cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("%s(var)".printf (free0_func), macro));
 			}
 
 			ccall = new CCodeFunctionCall (new CCodeIdentifier (free0_func));
@@ -3231,7 +3122,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 				if (vardecl.initializer  is CCodeInitializerList) {
 					// C does not support initializer lists in assignments, use memset instead
-					source_declarations.add_include ("string.h");
+					cfile.add_include ("string.h");
 					var memset_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
 					memset_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (local.name)));
 					memset_call.add_argument (new CCodeConstant ("0"));
@@ -3640,7 +3531,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		if (context.profile == Profile.GOBJECT) {
 			expr.ccodenode = new CCodeConstant (expr.value ? "TRUE" : "FALSE");
 		} else {
-			source_declarations.add_include ("stdbool.h");
+			cfile.add_include ("stdbool.h");
 			expr.ccodenode = new CCodeConstant (expr.value ? "true" : "false");
 		}
 	}
@@ -3731,7 +3622,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			fun.block.add_statement (if_stat);
 			fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("*re")));
 
-			source_type_member_definition.append (fun);
+			cfile.add_function (fun);
 		}
 		this.next_regex_id++;
 
@@ -3740,13 +3631,13 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		var regex_const = new CCodeConstant ("_thread_safe_regex_init (&%s, \"%s\", %s)".printf (cname, re, flags));
 
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 		expr.ccodenode = regex_const;
 	}
 
 	public override void visit_null_literal (NullLiteral expr) {
 		if (context.profile != Profile.GOBJECT) {
-			source_declarations.add_include ("stddef.h");
+			cfile.add_include ("stddef.h");
 		}
 		expr.ccodenode = new CCodeConstant ("NULL");
 	}
@@ -3978,7 +3869,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 				dup0_fun.block.add_statement (new CCodeReturnStatement (new CCodeConditionalExpression (new CCodeIdentifier ("self"), dup_call, new CCodeConstant ("NULL"))));
 
-				source_type_member_definition.append (dup0_fun);
+				cfile.add_function (dup0_fun);
 			}
 
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier (dup0_func));
@@ -4163,19 +4054,19 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
-	public virtual void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_class_declaration (Class cl, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
 	}
 
-	public virtual void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_method_declaration (Method m, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_error_domain_declaration (ErrorDomain edomain, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_error_domain_declaration (ErrorDomain edomain, CCodeFile decl_space) {
 	}
 
 	public void add_generic_type_arguments (Map<int,CCodeExpression> arg_map, List<DataType> type_args, CodeNode expr, bool is_chainup = false) {
@@ -4229,7 +4120,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			// no creation method
 			if (expr.type_reference.data_type is Struct) {
 				// memset needs string.h
-				source_declarations.add_include ("string.h");
+				cfile.add_include ("string.h");
 				var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
 				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
 				creation_call.add_argument (new CCodeConstant ("0"));
@@ -4247,7 +4138,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			var params = m.get_parameters ();
 			CCodeFunctionCall creation_call;
 
-			generate_method_declaration (m, source_declarations);
+			generate_method_declaration (m, cfile);
 
 			var cl = expr.type_reference.data_type as Class;
 
@@ -4275,7 +4166,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				}
 			}
 
-			generate_type_declaration (expr.type_reference, source_declarations);
+			generate_type_declaration (expr.type_reference, cfile);
 
 			var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
 
@@ -4410,7 +4301,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			var edomain = (ErrorDomain) ecode.parent_symbol;
 			CCodeFunctionCall creation_call;
 
-			generate_error_domain_declaration (edomain, source_declarations);
+			generate_error_domain_declaration (edomain, cfile);
 
 			if (expr.get_argument_list ().size == 1) {
 				// must not be a format argument
@@ -4480,7 +4371,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 					var cl = f.parent_symbol as Class;
 					if (cl != null) {
-						generate_class_struct_declaration (cl, source_declarations);
+						generate_class_struct_declaration (cl, cfile);
 					}
 				} else if (init.symbol_reference is Property) {
 					var inst_ma = new MemberAccess.simple ("new");
@@ -4529,7 +4420,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public override void visit_sizeof_expression (SizeofExpression expr) {
-		generate_type_declaration (expr.type_reference, source_declarations);
+		generate_type_declaration (expr.type_reference, cfile);
 
 		var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
 		csizeof.add_argument (new CCodeIdentifier (expr.type_reference.get_cname ()));
@@ -4651,10 +4542,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 		block.add_statement (fragment);
 		block.add_statement (new CCodeReturnStatement (result));
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		cfunc.block = block;
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 
 		return ccall;
 	}
@@ -4680,7 +4571,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			return;
 		}
 
-		generate_type_declaration (expr.type_reference, source_declarations);
+		generate_type_declaration (expr.type_reference, cfile);
 
 		var cl = expr.type_reference.data_type as Class;
 		var iface = expr.type_reference.data_type as Interface;
@@ -4797,14 +4688,14 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			op = CCodeBinaryOperator.DIV;
 		} else if (expr.operator == BinaryOperator.MOD) {
 			if (expr.value_type.equals (double_type)) {
-				source_declarations.add_include ("math.h");
+				cfile.add_include ("math.h");
 				var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmod"));
 				ccall.add_argument (cleft);
 				ccall.add_argument (cright);
 				expr.ccodenode = ccall;
 				return;
 			} else if (expr.value_type.equals (float_type)) {
-				source_declarations.add_include ("math.h");
+				cfile.add_include ("math.h");
 				var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmodf"));
 				ccall.add_argument (cleft);
 				ccall.add_argument (cright);
@@ -5048,15 +4939,15 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		block.add_statement (cloop);
 		block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return array_contains_func;
 	}
 
 	public override void visit_type_check (TypeCheck expr) {
-		generate_type_declaration (expr.type_reference, source_declarations);
+		generate_type_declaration (expr.type_reference, cfile);
 
 		expr.ccodenode = create_type_check (expr.expression.ccodenode, expr.type_reference);
 		if (expr.ccodenode is CCodeInvalidExpression) {
@@ -5270,10 +5161,10 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			block.add_statement (fragment);
 			block.add_statement (new CCodeReturnStatement (sink));
 
-			source_declarations.add_type_member_declaration (cfunc.copy ());
+			cfile.add_type_member_declaration (cfunc.copy ());
 
 			cfunc.block = block;
-			source_type_member_definition.append (cfunc);
+			cfile.add_function (cfunc);
 
 			return ccall;
 		} else if (boxing) {
@@ -5329,7 +5220,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			return cexpr;
 		}
 
-		generate_type_declaration (target_type, source_declarations);
+		generate_type_declaration (target_type, cfile);
 
 		var cl = target_type.data_type as Class;
 		var iface = target_type.data_type as Interface;
@@ -5384,7 +5275,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			if (prop is DynamicProperty) {
 				set_func = get_dynamic_property_setter_cname ((DynamicProperty) prop);
 			} else {
-				generate_property_accessor_declaration (base_property.set_accessor, source_declarations);
+				generate_property_accessor_declaration (base_property.set_accessor, cfile);
 				set_func = base_property.set_accessor.get_cname ();
 			}
 		}
@@ -5665,7 +5556,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	void generate_struct_destroy_function (Struct st) {
-		if (source_declarations.add_declaration (st.get_destroy_function ())) {
+		if (cfile.add_declaration (st.get_destroy_function ())) {
 			// only generate function once per source file
 			return;
 		}
@@ -5691,13 +5582,13 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 			}
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = cblock;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	void generate_struct_copy_function (Struct st) {
-		if (source_declarations.add_declaration (st.get_copy_function ())) {
+		if (cfile.add_declaration (st.get_copy_function ())) {
 			// only generate function once per source file
 			return;
 		}
@@ -5729,7 +5620,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 				var array_type = f.variable_type as ArrayType;
 				if (array_type != null && array_type.fixed_length) {
 					// fixed-length (stack-allocated) arrays
-					source_declarations.add_include ("string.h");
+					cfile.add_include ("string.h");
 
 					var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
 					sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
@@ -5759,9 +5650,9 @@ public class Vala.CCodeBaseModule : CodeGenerator {
 
 		pop_context ();
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = cblock;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	public virtual string? get_custom_creturn_type (Method m) {
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index dc66708..49d868b 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -235,7 +235,7 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
 		if (context.profile == Profile.GOBJECT) {
 			stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode);
 		} else {
-			source_declarations.add_include ("stdbool.h");
+			cfile.add_include ("stdbool.h");
 			stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode);
 		}
 	}
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 3f7b285..152ad5f 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -27,7 +27,7 @@
  * The link between an assignment and generated code.
  */
 public class Vala.CCodeDelegateModule : CCodeArrayModule {
-	public override void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
+	public override void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, d, d.get_cname ())) {
 			return;
 		}
@@ -114,13 +114,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 	public override void visit_delegate (Delegate d) {
 		d.accept_children (this);
 
-		generate_delegate_declaration (d, source_declarations);
+		generate_delegate_declaration (d, cfile);
 
 		if (!d.is_internal_symbol ()) {
-			generate_delegate_declaration (d, header_declarations);
+			generate_delegate_declaration (d, header_file);
 		}
 		if (!d.is_private_symbol ()) {
-			generate_delegate_declaration (d, internal_header_declarations);
+			generate_delegate_declaration (d, internal_header_file);
 		}
 	}
 
@@ -388,7 +388,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 		if (d.sender_type != null) {
 			var param = new FormalParameter ("_sender", d.sender_type);
-			generate_parameter (param, source_declarations, cparam_map, null);
+			generate_parameter (param, cfile, cparam_map, null);
 		}
 
 		var d_params = d.get_parameters ();
@@ -401,7 +401,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 				param.array_null_terminated = true;
 			}
 
-			generate_parameter (param, source_declarations, cparam_map, null);
+			generate_parameter (param, cfile, cparam_map, null);
 		}
 		if (!d.no_array_length && d.return_type is ArrayType) {
 			// return array length if appropriate
@@ -600,15 +600,15 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 		// append to file
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
 
-	public override void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+	public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
 		if (!(param.variable_type is DelegateType || param.variable_type is MethodType)) {
 			base.generate_parameter (param, decl_space, cparam_map, carg_map);
 			return;
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index d96a8a7..bbe085f 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -34,7 +34,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 			var m = (Method) expr.symbol_reference;
 
 			if (!(m is DynamicMethod || m is ArrayMoveMethod || m is ArrayResizeMethod)) {
-				generate_method_declaration (m, source_declarations);
+				generate_method_declaration (m, cfile);
 
 				if (!m.external && m.external_package) {
 					// internal VAPI methods
@@ -106,7 +106,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
 				} else {
 					if (cl != null) {
-						generate_class_struct_declaration (cl, source_declarations);
+						generate_class_struct_declaration (cl, cfile);
 					}
 					inst = pub_inst;
 				}
@@ -155,20 +155,20 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 				}
 
 			} else {
-				generate_field_declaration (f, source_declarations);
+				generate_field_declaration (f, cfile);
 
 				expr.ccodenode = new CCodeIdentifier (f.get_cname ());
 			}
 		} else if (expr.symbol_reference is EnumValue) {
 			var ev = (EnumValue) expr.symbol_reference;
 
-			generate_enum_declaration ((Enum) ev.parent_symbol, source_declarations);
+			generate_enum_declaration ((Enum) ev.parent_symbol, cfile);
 
 			expr.ccodenode = new CCodeConstant (ev.get_cname ());
 		} else if (expr.symbol_reference is Constant) {
 			var c = (Constant) expr.symbol_reference;
 
-			generate_constant_declaration (c, source_declarations,
+			generate_constant_declaration (c, cfile,
 				c.source_reference != null && expr.source_reference != null &&
 				c.source_reference.file == expr.source_reference.file);
 
@@ -192,7 +192,7 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 			var prop = (Property) expr.symbol_reference;
 
 			if (!(prop is DynamicProperty)) {
-				generate_property_accessor_declaration (prop.get_accessor, source_declarations);
+				generate_property_accessor_declaration (prop.get_accessor, cfile);
 
 				if (!prop.external && prop.external_package) {
 					// internal VAPI properties
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index c3a03e7..c21301e 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -54,13 +54,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			// constructor
 			var cl = (Class) ((ObjectType) itype).type_symbol;
 			m = cl.default_construction_method;
-			generate_method_declaration (m, source_declarations);
+			generate_method_declaration (m, cfile);
 			ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
 		} else if (itype is StructValueType) {
 			// constructor
 			var st = (Struct) ((StructValueType) itype).type_symbol;
 			m = st.default_construction_method;
-			generate_method_declaration (m, source_declarations);
+			generate_method_declaration (m, cfile);
 			ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
 		} else if (itype is DelegateType) {
 			deleg = ((DelegateType) itype).delegate_symbol;
@@ -766,7 +766,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			temp_vars.add (temp_decl);
 
 			/* memset needs string.h */
-			source_declarations.add_include ("string.h");
+			cfile.add_include ("string.h");
 
 			var clen = get_array_length_cexpression (ma.inner, 1);
 			var celems = (CCodeExpression) ma.inner.ccodenode;
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index d184a92..31cc3f8 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -61,7 +61,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 		return result;
 	}
 
-	public virtual void generate_method_result_declaration (Method m, CCodeDeclarationSpace decl_space, CCodeFunction cfunc, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+	public virtual void generate_method_result_declaration (Method m, CCodeFile decl_space, CCodeFunction cfunc, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
 		var creturn_type = m.return_type;
 		if (m is CreationMethod) {
 			var cl = m.parent_symbol as Class;
@@ -158,7 +158,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 		return complete_block;
 	}
 
-	public override void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
+	public override void generate_method_declaration (Method m, CCodeFile decl_space) {
 		if (m.is_async_callback) {
 			return;
 		}
@@ -318,18 +318,18 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 		// do not declare overriding methods and interface implementations
 		if (m.is_abstract || m.is_virtual
 		    || (m.base_method == null && m.base_interface_method == null)) {
-			generate_method_declaration (m, source_declarations);
+			generate_method_declaration (m, cfile);
 
 			if (!m.is_internal_symbol ()) {
-				generate_method_declaration (m, header_declarations);
+				generate_method_declaration (m, header_file);
 			}
 			if (!m.is_private_symbol ()) {
-				generate_method_declaration (m, internal_header_declarations);
+				generate_method_declaration (m, internal_header_file);
 			}
 		}
 
 		if (m.comment != null) {
-			source_type_member_definition.append (new CCodeComment (m.comment.content));
+			cfile.add_type_member_definition (new CCodeComment (m.comment.content));
 		}
 
 		CCodeFunction function;
@@ -342,7 +342,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (m, source_declarations, cparam_map, function);
+		generate_cparameters (m, cfile, cparam_map, function);
 
 		// generate *_real_* functions for virtual methods
 		// also generate them for abstract methods of classes to prevent faulty subclassing
@@ -351,7 +351,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 				if (m.base_method != null || m.base_interface_method != null) {
 					// declare *_real_* function
 					function.modifiers |= CCodeModifiers.STATIC;
-					source_declarations.add_type_member_declaration (function.copy ());
+					cfile.add_type_member_declaration (function.copy ());
 				} else if (m.is_private_symbol ()) {
 					function.modifiers |= CCodeModifiers.STATIC;
 				}
@@ -371,7 +371,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 					function.add_parameter (new CCodeFormalParameter ("data", Symbol.lower_case_to_camel_case (m.get_cname ()) + "Data*"));
 
 					function.modifiers |= CCodeModifiers.STATIC;
-					source_declarations.add_type_member_declaration (function.copy ());
+					cfile.add_type_member_declaration (function.copy ());
 				}
 			}
 		}
@@ -590,7 +590,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 						var st = (Struct) m.parent_symbol;
 
 						// memset needs string.h
-						source_declarations.add_include ("string.h");
+						cfile.add_include ("string.h");
 						var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
 						czero.add_argument (new CCodeIdentifier ("self"));
 						czero.add_argument (new CCodeConstant ("0"));
@@ -655,7 +655,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 					}
 				}
 
-				source_type_member_definition.append (function);
+				cfile.add_function (function);
 			} else if (m.is_abstract) {
 				// generate helpful error message if a sublcass does not implement an abstract method.
 				// This is only meaningful for subclasses implemented in C since the vala compiler would
@@ -688,7 +688,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 				cblock.add_statement (new CCodeReturnStatement (default_value_for_type (creturn_type, false)));
 
 				function.block = cblock;
-				source_type_member_definition.append (function);
+				cfile.add_function (function);
 			}
 		}
 
@@ -755,11 +755,11 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 				main_block.add_statement (main_stmt);
 			}
 			cmain.block = main_block;
-			source_type_member_definition.append (cmain);
+			cfile.add_function (cmain);
 		}
 	}
 
-	public virtual void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+	public virtual void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
 		if (!param.ellipsis) {
 			string ctypename = param.variable_type.get_cname ();
 
@@ -794,7 +794,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 		}
 	}
 
-	public override void generate_cparameters (Method m, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
+	public override void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
 		if (m.closure) {
 			var closure_block = current_closure_block;
 			int block_id = get_block_id (closure_block);
@@ -960,7 +960,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 		var vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, cname + suffix));
 		carg_map.set (get_param_pos (m.cinstance_parameter_position), new CCodeIdentifier ("self"));
 
-		generate_cparameters (m, source_declarations, cparam_map, vfunc, null, carg_map, vcall, direction);
+		generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall, direction);
 
 		CCodeStatement cstmt;
 		if (return_type is VoidType || return_type.is_real_non_null_struct_type ()) {
@@ -991,7 +991,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 
 		vfunc.block = vblock;
 
-		source_type_member_definition.append (vfunc);
+		cfile.add_function (vfunc);
 	}
 
 	private CCodeStatement? create_method_type_check_statement (Method m, DataType return_type, TypeSymbol t, bool non_null, string var_name) {
@@ -1088,7 +1088,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 			var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
 			vcall.add_argument (new CCodeIdentifier (current_class.get_type_id ()));
 
-			generate_cparameters (m, source_declarations, cparam_map, vfunc, null, carg_map, vcall);
+			generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall);
 			CCodeStatement cstmt = new CCodeReturnStatement (vcall);
 			cstmt.line = vfunc.line;
 			vblock.add_statement (cstmt);
@@ -1099,7 +1099,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 
 			vfunc.block = vblock;
 
-			source_type_member_definition.append (vfunc);
+			cfile.add_function (vfunc);
 		}
 
 		if (current_type_symbol is Class && gobject_type != null && current_class.is_subtype_of (gobject_type)
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 6c4b7e9..5ca9d92 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -25,7 +25,7 @@
 using GLib;
 
 public class Vala.CCodeStructModule : CCodeBaseModule {
-	public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
+	public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, st, st.get_cname ())) {
 			return;
 		}
@@ -145,13 +145,13 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 		var old_instance_finalize_fragment = instance_finalize_fragment;
 		instance_finalize_fragment = new CCodeFragment ();
 
-		generate_struct_declaration (st, source_declarations);
+		generate_struct_declaration (st, cfile);
 
 		if (!st.is_internal_symbol ()) {
-			generate_struct_declaration (st, header_declarations);
+			generate_struct_declaration (st, header_file);
 		}
 		if (!st.is_private_symbol ()) {
-			generate_struct_declaration (st, internal_header_declarations);
+			generate_struct_declaration (st, internal_header_file);
 		}
 
 		st.accept_children (this);
@@ -196,7 +196,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 			copy_call.add_argument (new CCodeIdentifier ("dup"));
 			cblock.add_statement (new CCodeExpressionStatement (copy_call));
 		} else {
-			source_declarations.add_include ("string.h");
+			cfile.add_include ("string.h");
 
 			var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
 			sizeof_call.add_argument (new CCodeConstant (st.get_cname ()));
@@ -212,7 +212,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	void add_struct_free_function (Struct st) {
@@ -237,7 +237,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	void add_struct_copy_function (Struct st) {
@@ -269,7 +269,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 				var array_type = f.variable_type as ArrayType;
 				if (array_type != null && array_type.fixed_length) {
 					// fixed-length (stack-allocated) arrays
-					source_declarations.add_include ("string.h");
+					cfile.add_include ("string.h");
 
 					var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
 					sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
@@ -299,7 +299,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	void add_struct_destroy_function (Struct st) {
@@ -316,7 +316,7 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 }
 
diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala
index 8194336..360d3c9 100644
--- a/codegen/valadbusclientmodule.vala
+++ b/codegen/valadbusclientmodule.vala
@@ -81,7 +81,7 @@ public class Vala.DBusClientModule : DBusModule {
 
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (method, source_declarations, cparam_map, func);
+		generate_cparameters (method, cfile, cparam_map, func);
 
 		var block = new CCodeBlock ();
 		if (dynamic_method.dynamic_type.data_type == dbus_object_type) {
@@ -91,10 +91,10 @@ public class Vala.DBusClientModule : DBusModule {
 		}
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 	}
 
 	void generate_dbus_method_wrapper (Method method, CCodeBlock block) {
@@ -225,9 +225,9 @@ public class Vala.DBusClientModule : DBusModule {
 				target = ref_call;
 			}
 
-			if (!source_declarations.add_declaration (cb_fun.name)) {
+			if (!cfile.add_declaration (cb_fun.name)) {
 				// avoid duplicate function definition
-				source_type_member_definition.append (cb_fun);
+				cfile.add_function (cb_fun);
 			}
 
 			ccall.add_argument (new CCodeIdentifier (cb_fun.name));
@@ -280,7 +280,7 @@ public class Vala.DBusClientModule : DBusModule {
 					block.add_statement (cdecl);
 
 					if (dbus_use_ptr_array (array_type)) {
-						source_declarations.add_include ("string.h");
+						cfile.add_include ("string.h");
 
 						var memcpy_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
 						memcpy_call.add_argument (new CCodeMemberAccess.pointer (new CCodeIdentifier ("dbus_%s".printf (param.name)), "pdata"));
@@ -648,10 +648,10 @@ public class Vala.DBusClientModule : DBusModule {
 		generate_dbus_property_getter_wrapper (prop, block);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return getter_cname;
 	}
@@ -678,10 +678,10 @@ public class Vala.DBusClientModule : DBusModule {
 		generate_dbus_property_setter_wrapper (prop, block);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return setter_cname;
 	}
@@ -819,10 +819,10 @@ public class Vala.DBusClientModule : DBusModule {
 		generate_dbus_connect_wrapper (sig, block);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return connect_wrapper_name;
 	}
@@ -842,10 +842,10 @@ public class Vala.DBusClientModule : DBusModule {
 		generate_dbus_disconnect_wrapper (sig, block);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return disconnect_wrapper_name;
 	}
@@ -975,9 +975,9 @@ public class Vala.DBusClientModule : DBusModule {
 		}
 
 		proxy_iface_init.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (proxy_iface_init.copy ());
+		cfile.add_type_member_declaration (proxy_iface_init.copy ());
 		proxy_iface_init.block = iface_block;
-		source_type_member_definition.append (proxy_iface_init);
+		cfile.add_function (proxy_iface_init);
 	}
 
 	string implement_interface (CCodeFunctionCall define_type, Interface main_iface, Interface iface) {
@@ -1029,7 +1029,7 @@ public class Vala.DBusClientModule : DBusModule {
 		}
 	}
 
-	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 		base.generate_interface_declaration (iface, decl_space);
 
 		string dbus_iface_name = get_dbus_name (iface);
@@ -1061,7 +1061,7 @@ public class Vala.DBusClientModule : DBusModule {
 		}
 
 		// strcmp
-		source_declarations.add_include ("string.h");
+		cfile.add_include ("string.h");
 
 		// create proxy class
 		string cname = iface.get_cname () + "DBusProxy";
@@ -1069,18 +1069,18 @@ public class Vala.DBusClientModule : DBusModule {
 
 		add_dbus_helpers ();
 
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cname), new CCodeVariableDeclarator (cname)));
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("DBusGProxyClass", new CCodeVariableDeclarator (cname + "Class")));
+		cfile.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cname), new CCodeVariableDeclarator (cname)));
+		cfile.add_type_declaration (new CCodeTypeDefinition ("DBusGProxyClass", new CCodeVariableDeclarator (cname + "Class")));
 
 		var instance_struct = new CCodeStruct ("_%s".printf (cname));
 		instance_struct.add_field ("DBusGProxy", "parent_instance");
 		instance_struct.add_field ("gboolean", "disposed");
 
-		source_declarations.add_type_definition (instance_struct);
+		cfile.add_type_definition (instance_struct);
 
 		var type_fun = new CCodeFunction(lower_cname + "_get_type", "GType");
 		type_fun.attributes = "G_GNUC_CONST";
-		source_declarations.add_type_member_declaration (type_fun);
+		cfile.add_type_member_declaration (type_fun);
 
 		var define_type = new CCodeFunctionCall (new CCodeIdentifier ("G_DEFINE_TYPE_EXTENDED"));
 		define_type.add_argument (new CCodeIdentifier (cname));
@@ -1089,7 +1089,7 @@ public class Vala.DBusClientModule : DBusModule {
 		define_type.add_argument (new CCodeConstant ("0"));
 		define_type.add_argument (new CCodeIdentifier (implement_interface (define_type, iface, iface)));
 
-		source_type_member_definition.append (new CCodeExpressionStatement (define_type));
+		cfile.add_type_member_definition (new CCodeExpressionStatement (define_type));
 
 		// generate proxy_new function
 		var proxy_new = new CCodeFunction (lower_cname + "_new", iface.get_cname () + "*");
@@ -1118,7 +1118,7 @@ public class Vala.DBusClientModule : DBusModule {
 		new_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("self")));
 
 		proxy_new.block = new_block;
-		source_type_member_definition.append (proxy_new);
+		cfile.add_function (proxy_new);
 
 		// dbus proxy construct
 		var proxy_construct = new CCodeFunction (lower_cname + "_construct", "GObject*");
@@ -1202,7 +1202,7 @@ public class Vala.DBusClientModule : DBusModule {
 
 		proxy_construct.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("self")));
 
-		source_type_member_definition.append (proxy_construct);
+		cfile.add_function (proxy_construct);
 
 		// dbus proxy filter function
 		generate_proxy_filter_function (iface);
@@ -1246,7 +1246,7 @@ public class Vala.DBusClientModule : DBusModule {
 		chainup.add_argument (new CCodeIdentifier ("self"));
 		proxy_dispose.block.add_statement (new CCodeExpressionStatement (chainup));
 
-		source_type_member_definition.append (proxy_dispose);
+		cfile.add_function (proxy_dispose);
 
 		var proxy_class_init = new CCodeFunction (lower_cname + "_class_init", "void");
 		proxy_class_init.add_parameter (new CCodeFormalParameter ("klass", cname + "Class*"));
@@ -1258,20 +1258,20 @@ public class Vala.DBusClientModule : DBusModule {
 		proxy_class_init.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (gobject_class, "dispose"), new CCodeIdentifier (lower_cname + "_dispose"))));
 		proxy_class_init.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (gobject_class, "get_property"), new CCodeIdentifier (lower_cname + "_get_property"))));
 		proxy_class_init.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (gobject_class, "set_property"), new CCodeIdentifier (lower_cname + "_set_property"))));
-		source_type_member_definition.append (proxy_class_init);
+		cfile.add_function (proxy_class_init);
 
 		prop_enum = new CCodeEnum ();
 		prop_enum.add_value (new CCodeEnumValue ("%s_DUMMY_PROPERTY".printf (lower_cname.up ())));
 
 		implement_property (proxy_class_init.block, iface, iface);
 
-		source_declarations.add_type_member_declaration (prop_enum);
+		cfile.add_type_member_declaration (prop_enum);
 
 		var proxy_instance_init = new CCodeFunction (lower_cname + "_init", "void");
 		proxy_instance_init.add_parameter (new CCodeFormalParameter ("self", cname + "*"));
 		proxy_instance_init.modifiers = CCodeModifiers.STATIC;
 		proxy_instance_init.block = new CCodeBlock ();
-		source_type_member_definition.append (proxy_instance_init);
+		cfile.add_function (proxy_instance_init);
 
 		generate_proxy_interface_init (iface, iface);
 
@@ -1283,9 +1283,9 @@ public class Vala.DBusClientModule : DBusModule {
 		get_prop.add_parameter (new CCodeFormalParameter ("property_id", "guint"));
 		get_prop.add_parameter (new CCodeFormalParameter ("value", "GValue *"));
 		get_prop.add_parameter (new CCodeFormalParameter ("pspec", "GParamSpec *"));
-		source_declarations.add_type_member_declaration (get_prop.copy ());
+		cfile.add_type_member_declaration (get_prop.copy ());
 		get_prop.block = new CCodeBlock ();
-		source_type_member_definition.append (get_prop);
+		cfile.add_function (get_prop);
 
 		var set_prop = new CCodeFunction ("%s_set_property".printf (lower_cname), "void");
 		set_prop.modifiers = CCodeModifiers.STATIC;
@@ -1293,9 +1293,9 @@ public class Vala.DBusClientModule : DBusModule {
 		set_prop.add_parameter (new CCodeFormalParameter ("property_id", "guint"));
 		set_prop.add_parameter (new CCodeFormalParameter ("value", "const GValue *"));
 		set_prop.add_parameter (new CCodeFormalParameter ("pspec", "GParamSpec *"));
-		source_declarations.add_type_member_declaration (set_prop.copy ());
+		cfile.add_type_member_declaration (set_prop.copy ());
 		set_prop.block = new CCodeBlock ();
-		source_type_member_definition.append (set_prop);
+		cfile.add_function (set_prop);
 	}
 
 	public override TypeRegisterFunction create_interface_register_function (Interface iface) {
@@ -1389,10 +1389,10 @@ public class Vala.DBusClientModule : DBusModule {
 
 		block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return get_all_func;
 	}
@@ -1486,9 +1486,9 @@ public class Vala.DBusClientModule : DBusModule {
 
 		filter_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("DBUS_HANDLER_RESULT_NOT_YET_HANDLED")));
 
-		source_declarations.add_type_member_declaration (proxy_filter.copy ());
+		cfile.add_type_member_declaration (proxy_filter.copy ());
 		proxy_filter.block = filter_block;
-		source_type_member_definition.append (proxy_filter);
+		cfile.add_function (proxy_filter);
 	}
 
 	string generate_dbus_signal_handler (Signal sig, ObjectTypeSymbol sym) {
@@ -1594,10 +1594,10 @@ public class Vala.DBusClientModule : DBusModule {
 		cdecl.add_declarator (new CCodeVariableDeclarator ("reply"));
 		block.add_statement (cdecl);
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -1822,7 +1822,7 @@ public class Vala.DBusClientModule : DBusModule {
 
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (m, source_declarations, cparam_map, function);
+		generate_cparameters (m, cfile, cparam_map, function);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -1911,9 +1911,9 @@ public class Vala.DBusClientModule : DBusModule {
 			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -1930,7 +1930,7 @@ public class Vala.DBusClientModule : DBusModule {
 
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (m, source_declarations, cparam_map, function);
+		generate_cparameters (m, cfile, cparam_map, function);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -2006,9 +2006,9 @@ public class Vala.DBusClientModule : DBusModule {
 
 		block.add_statement (postfragment);
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -2101,8 +2101,8 @@ public class Vala.DBusClientModule : DBusModule {
 		datastruct.add_field ("gpointer", "_user_data_");
 		datastruct.add_field ("DBusPendingCall*", "pending");
 
-		source_declarations.add_type_definition (datastruct);
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _" + dataname, new CCodeVariableDeclarator (dataname)));
+		cfile.add_type_definition (datastruct);
+		cfile.add_type_declaration (new CCodeTypeDefinition ("struct _" + dataname, new CCodeVariableDeclarator (dataname)));
 
 
 		// generate async function
@@ -2115,7 +2115,7 @@ public class Vala.DBusClientModule : DBusModule {
 		cparam_map.set (get_param_pos (-1), new CCodeFormalParameter ("_callback_", "GAsyncReadyCallback"));
 		cparam_map.set (get_param_pos (-0.9), new CCodeFormalParameter ("_user_data_", "gpointer"));
 
-		generate_cparameters (m, source_declarations, cparam_map, function, null, null, null, 1);
+		generate_cparameters (m, cfile, cparam_map, function, null, null, null, 1);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -2185,9 +2185,9 @@ public class Vala.DBusClientModule : DBusModule {
 		pending.add_argument (new CCodeConstant ("NULL"));
 		block.add_statement (new CCodeExpressionStatement (pending));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 
 		// generate ready function
@@ -2248,9 +2248,9 @@ public class Vala.DBusClientModule : DBusModule {
 		pendingfree.add_argument (new CCodeIdentifier ("pending"));
 		block.add_statement (new CCodeExpressionStatement (pendingfree));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 
 		return proxy_name;
@@ -2313,7 +2313,7 @@ public class Vala.DBusClientModule : DBusModule {
 
 		cparam_map.set (get_param_pos (0.1), new CCodeFormalParameter ("_res_", "GAsyncResult*"));
 
-		generate_cparameters (m, source_declarations, cparam_map, function, null, null, null, 2);
+		generate_cparameters (m, cfile, cparam_map, function, null, null, null, 2);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -2370,9 +2370,9 @@ public class Vala.DBusClientModule : DBusModule {
 			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -2656,9 +2656,9 @@ public class Vala.DBusClientModule : DBusModule {
 			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -2803,9 +2803,9 @@ public class Vala.DBusClientModule : DBusModule {
 		reply_unref.add_argument (new CCodeIdentifier ("_reply"));
 		block.add_statement (new CCodeExpressionStatement (reply_unref));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
diff --git a/codegen/valadbusmodule.vala b/codegen/valadbusmodule.vala
index e1a1072..190267a 100644
--- a/codegen/valadbusmodule.vala
+++ b/codegen/valadbusmodule.vala
@@ -159,15 +159,15 @@ public class Vala.DBusModule : GAsyncModule {
 
 		if (is_string_marshalled_enum (en)) {
 			// strcmp
-			source_declarations.add_include ("string.h");
-			source_declarations.add_include ("dbus/dbus-glib.h");
+			cfile.add_include ("string.h");
+			cfile.add_include ("dbus/dbus-glib.h");
 
-			source_type_member_definition.append (generate_enum_from_string_function (en));
-			source_type_member_definition.append (generate_enum_to_string_function (en));
+			cfile.add_function (generate_enum_from_string_function (en));
+			cfile.add_function (generate_enum_to_string_function (en));
 		}
 	}
 
-	public override bool generate_enum_declaration (Enum en, CCodeDeclarationSpace decl_space) {
+	public override bool generate_enum_declaration (Enum en, CCodeFile decl_space) {
 		if (base.generate_enum_declaration (en, decl_space)) {
 			if (is_string_marshalled_enum (en)) {
 				decl_space.add_type_member_declaration (generate_enum_from_string_function_declaration (en));
@@ -986,19 +986,19 @@ public class Vala.DBusModule : GAsyncModule {
 	}
 
 	public void add_dbus_helpers () {
-		if (source_declarations.add_declaration ("_vala_dbus_register_object")) {
+		if (cfile.add_declaration ("_vala_dbus_register_object")) {
 			return;
 		}
 
-		source_declarations.add_include ("dbus/dbus.h");
-		source_declarations.add_include ("dbus/dbus-glib.h");
-		source_declarations.add_include ("dbus/dbus-glib-lowlevel.h");
+		cfile.add_include ("dbus/dbus.h");
+		cfile.add_include ("dbus/dbus-glib.h");
+		cfile.add_include ("dbus/dbus-glib-lowlevel.h");
 
 		var dbusvtable = new CCodeStruct ("_DBusObjectVTable");
 		dbusvtable.add_field ("void", "(*register_object) (DBusConnection*, const char*, void*)");
-		source_declarations.add_type_definition (dbusvtable);
+		cfile.add_type_definition (dbusvtable);
 
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct _DBusObjectVTable", new CCodeVariableDeclarator ("_DBusObjectVTable")));
+		cfile.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*"));
@@ -1006,7 +1006,7 @@ public class Vala.DBusModule : GAsyncModule {
 		cfunc.add_parameter (new CCodeFormalParameter ("object", "void*"));
 
 		cfunc.modifiers |= CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -1041,7 +1041,7 @@ public class Vala.DBusModule : GAsyncModule {
 
 		block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("vtable"), ifblock, elseblock));
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 
 		// unregister function
 		cfunc = new CCodeFunction ("_vala_dbus_unregister_object", "void");
@@ -1049,7 +1049,7 @@ public class Vala.DBusModule : GAsyncModule {
 		cfunc.add_parameter (new CCodeFormalParameter ("object", "GObject*"));
 
 		cfunc.modifiers |= CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		block = new CCodeBlock ();
 		cfunc.block = block;
@@ -1072,6 +1072,6 @@ public class Vala.DBusModule : GAsyncModule {
 		path_free.add_argument (new CCodeIdentifier ("path"));
 		block.add_statement (new CCodeExpressionStatement (path_free));
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 }
diff --git a/codegen/valadbusservermodule.vala b/codegen/valadbusservermodule.vala
index 5a2ea3e..5f2c3e4 100644
--- a/codegen/valadbusservermodule.vala
+++ b/codegen/valadbusservermodule.vala
@@ -92,7 +92,7 @@ public class Vala.DBusServerModule : DBusClientModule {
 		CCodeBlock ready_block = null;
 		if (m.coroutine) {
 			// GAsyncResult
-			source_declarations.add_include ("gio/gio.h");
+			cfile.add_include ("gio/gio.h");
 
 			ready_function = new CCodeFunction (wrapper_name + "_ready", "void");
 			ready_function.modifiers = CCodeModifiers.STATIC;
@@ -406,16 +406,16 @@ public class Vala.DBusServerModule : DBusClientModule {
 			ready_block.add_statement (new CCodeExpressionStatement (free_call));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		if (m.coroutine) {
-			source_declarations.add_type_member_declaration (ready_function.copy ());
+			cfile.add_type_member_declaration (ready_function.copy ());
 
 			ready_function.block = ready_block;
-			source_type_member_definition.append (ready_function);
+			cfile.add_function (ready_function);
 		}
 
 		return wrapper_name;
@@ -489,7 +489,7 @@ public class Vala.DBusServerModule : DBusClientModule {
 
 		foreach (var param in sig.get_parameters ()) {
 			// ensure ccodenode of parameter is set
-			generate_parameter (param, source_declarations, new HashMap<int,CCodeFormalParameter> (), null);
+			generate_parameter (param, cfile, new HashMap<int,CCodeFormalParameter> (), null);
 
 			function.add_parameter ((CCodeFormalParameter) get_ccodenode (param));
 			if (param.variable_type is ArrayType) {
@@ -552,16 +552,16 @@ public class Vala.DBusServerModule : DBusClientModule {
 		message_unref.add_argument (new CCodeIdentifier ("_message"));
 		block.add_statement (new CCodeExpressionStatement (message_unref));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
 
 	void generate_register_function (ObjectType object_type) {
 		// strcmp
-		source_declarations.add_include ("string.h");
+		cfile.add_include ("string.h");
 
 		var sym = object_type.type_symbol;
 
@@ -576,7 +576,7 @@ public class Vala.DBusServerModule : DBusClientModule {
 			cfunc.modifiers |= CCodeModifiers.STATIC;
 		}
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -628,7 +628,7 @@ public class Vala.DBusServerModule : DBusClientModule {
 			}
 		}
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	void generate_unregister_function (ObjectType object_type) {
@@ -638,12 +638,12 @@ public class Vala.DBusServerModule : DBusClientModule {
 		cfunc.add_parameter (new CCodeFormalParameter ("connection", "DBusConnection*"));
 		cfunc.add_parameter (new CCodeFormalParameter ("_user_data_", "void*"));
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	void handle_method (string dbus_iface_name, string dbus_method_name, string handler_name, CCodeBlock block, ref CCodeIfStatement clastif) {
@@ -865,10 +865,10 @@ public class Vala.DBusServerModule : DBusClientModule {
 			handle_reply (block);
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -1079,10 +1079,10 @@ public class Vala.DBusServerModule : DBusClientModule {
 
 		handle_reply (block);
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -1253,10 +1253,10 @@ public class Vala.DBusServerModule : DBusClientModule {
 			handle_reply (block);
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -1464,10 +1464,10 @@ public class Vala.DBusServerModule : DBusClientModule {
 
 		handle_reply (block);
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -1509,7 +1509,7 @@ public class Vala.DBusServerModule : DBusClientModule {
 			cfunc.modifiers |= CCodeModifiers.STATIC;
 		}
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -1586,7 +1586,7 @@ public class Vala.DBusServerModule : DBusClientModule {
 		retblock.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("DBUS_HANDLER_RESULT_NOT_YET_HANDLED")));
 		clastif.false_statement = retblock;
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	CCodeExpression get_vtable (ObjectType object_type) {
@@ -1600,7 +1600,7 @@ public 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_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_vtable");
 	}
@@ -1618,7 +1618,7 @@ public 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_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_path_vtable");
 	}
diff --git a/codegen/valadovaarraymodule.vala b/codegen/valadovaarraymodule.vala
index 5e3478f..93978f1 100644
--- a/codegen/valadovaarraymodule.vala
+++ b/codegen/valadovaarraymodule.vala
@@ -49,7 +49,7 @@ public class Vala.DovaArrayModule : DovaMethodCallModule {
 			return;
 		}
 
-		generate_method_declaration (array_class.default_construction_method, source_declarations);
+		generate_method_declaration (array_class.default_construction_method, cfile);
 
 		var array_new = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_new"));
 		array_new.add_argument (get_type_id_expression (expr.element_type));
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index dd49e86..3d21f33 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -30,7 +30,7 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
 		var prop = (Property) assignment.left.symbol_reference;
 
 		if (!(prop is DynamicProperty)) {
-			generate_property_accessor_declaration (prop.set_accessor, source_declarations);
+			generate_property_accessor_declaration (prop.set_accessor, cfile);
 
 			if (!prop.external && prop.external_package) {
 				// internal VAPI properties
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index ebb52e9..3304f7f 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -145,12 +145,11 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		return block;
 	}
 
-	public CCodeDeclarationSpace header_declarations;
-	public CCodeDeclarationSpace source_declarations;
+	public CCodeFile header_file;
+	public CCodeFile cfile;
 
 	string? csource_filename;
 
-	public CCodeFragment source_type_member_definition;
 	public CCodeFragment module_init_fragment;
 	public CCodeFragment instance_init_fragment;
 	public CCodeFragment instance_finalize_fragment;
@@ -273,18 +272,17 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		delegate_class = (Class) dova_ns.scope.lookup ("Delegate");
 		error_class = (Class) dova_ns.scope.lookup ("Error");
 
-		header_declarations = new CCodeDeclarationSpace ();
+		header_file = new CCodeFile ();
 
-		source_declarations = new CCodeDeclarationSpace ();
+		cfile = new CCodeFile ();
 		module_init_fragment = new CCodeFragment ();
-		source_type_member_definition = new CCodeFragment ();
 
 		if (context.nostdpkg) {
-			header_declarations.add_include ("dova-types.h");
-			source_declarations.add_include ("dova-types.h");
+			header_file.add_include ("dova-types.h");
+			cfile.add_include ("dova-types.h");
 		} else {
-			header_declarations.add_include ("dova-base.h");
-			source_declarations.add_include ("dova-base.h");
+			header_file.add_include ("dova-base.h");
+			cfile.add_include ("dova-base.h");
 		}
 
 		generated_external_symbols = new HashSet<Symbol> ();
@@ -299,62 +297,19 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		}
 
 		if (csource_filename != null) {
-			var writer = new CCodeWriter (csource_filename);
-			if (!writer.open (context.version_header)) {
-				Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
-				return;
+			if (!cfile.store (csource_filename, null, context.version_header, context.debug)) {
+				Report.error (null, "unable to open `%s' for writing".printf (csource_filename));
 			}
-			writer.line_directives = context.debug;
-
-			writer.write_newline ();
-			source_declarations.include_directives.write (writer);
-			writer.write_newline ();
-			source_declarations.type_declaration.write_combined (writer);
-			writer.write_newline ();
-			source_declarations.type_definition.write_combined (writer);
-			writer.write_newline ();
-			source_declarations.type_member_declaration.write_declaration (writer);
-			writer.write_newline ();
-			source_declarations.type_member_declaration.write (writer);
-			writer.write_newline ();
-			source_declarations.constant_declaration.write_combined (writer);
-			writer.write_newline ();
-			source_type_member_definition.write (writer);
-			writer.write_newline ();
-			writer.close ();
 		}
 
-		source_declarations = null;
-		source_type_member_definition = null;
+		cfile = null;
 
 
 		// generate C header file for public API
 		if (context.header_filename != null) {
-			var writer = new CCodeWriter (context.header_filename);
-			if (!writer.open (context.version_header)) {
-				Report.error (null, "unable to open `%s' for writing".printf (writer.filename));
-				return;
+			if (!header_file.store (context.header_filename, null, context.version_header, false)) {
+				Report.error (null, "unable to open `%s' for writing".printf (context.header_filename));
 			}
-			writer.write_newline ();
-
-			var once = new CCodeOnceSection (get_define_for_filename (writer.filename));
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.include_directives);
-			once.append (new CCodeNewline ());
-
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.type_declaration);
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.type_definition);
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.type_member_declaration);
-			once.append (new CCodeNewline ());
-			once.append (header_declarations.constant_declaration);
-			once.append (new CCodeNewline ());
-
-			once.append (new CCodeNewline ());
-			once.write (writer);
-			writer.close ();
 		}
 	}
 
@@ -375,7 +330,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		}
 	}
 
-	public bool add_symbol_declaration (CCodeDeclarationSpace decl_space, Symbol sym, string name) {
+	public bool add_symbol_declaration (CCodeFile decl_space, Symbol sym, string name) {
 		if (decl_space.add_declaration (name)) {
 			return true;
 		}
@@ -411,27 +366,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		}
 	}
 
-	private static string get_define_for_filename (string filename) {
-		var define = new StringBuilder ("__");
-
-		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 void generate_enum_declaration (Enum en, CCodeDeclarationSpace decl_space) {
+	public void generate_enum_declaration (Enum en, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, en, en.get_cname ())) {
 			return;
 		}
@@ -454,14 +389,14 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	public override void visit_enum (Enum en) {
 		en.accept_children (this);
 
-		generate_enum_declaration (en, source_declarations);
+		generate_enum_declaration (en, cfile);
 
 		if (!en.is_internal_symbol ()) {
-			generate_enum_declaration (en, header_declarations);
+			generate_enum_declaration (en, header_file);
 		}
 	}
 
-	public void generate_constant_declaration (Constant c, CCodeDeclarationSpace decl_space) {
+	public void generate_constant_declaration (Constant c, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, c, c.get_cname ())) {
 			return;
 		}
@@ -487,14 +422,14 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public override void visit_constant (Constant c) {
-		generate_constant_declaration (c, source_declarations);
+		generate_constant_declaration (c, cfile);
 
 		if (!c.is_internal_symbol ()) {
-			generate_constant_declaration (c, header_declarations);
+			generate_constant_declaration (c, header_file);
 		}
 	}
 
-	public void generate_field_declaration (Field f, CCodeDeclarationSpace decl_space) {
+	public void generate_field_declaration (Field f, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, f, f.get_cname ())) {
 			return;
 		}
@@ -569,10 +504,10 @@ public class Vala.DovaBaseModule : CodeGenerator {
 				instance_finalize_fragment.append (new CCodeExpressionStatement (get_unref_expression (lhs, f.variable_type, ma)));
 			}
 		} else {
-			generate_field_declaration (f, source_declarations);
+			generate_field_declaration (f, cfile);
 
 			if (!f.is_internal_symbol ()) {
-				generate_field_declaration (f, header_declarations);
+				generate_field_declaration (f, header_file);
 			}
 
 			lhs = new CCodeIdentifier (f.get_cname ());
@@ -601,7 +536,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 				var_def.modifiers |= CCodeModifiers.THREAD_LOCAL;
 			}
 
-			source_declarations.add_type_member_declaration (var_def);
+			cfile.add_type_member_declaration (var_def);
 		}
 	}
 
@@ -665,7 +600,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		prop.accept_children (this);
 	}
 
-	public void generate_type_declaration (DataType type, CCodeDeclarationSpace decl_space) {
+	public void generate_type_declaration (DataType type, CCodeFile decl_space) {
 		if (type is ObjectType) {
 			var object_type = (ObjectType) type;
 			if (object_type.type_symbol is Class) {
@@ -696,16 +631,16 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		}
 	}
 
-	public virtual void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_struct_declaration (Struct st, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_cparameters (Method m, CCodeDeclarationSpace decl_space, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, CCodeFunctionCall? vcall = null) {
+	public virtual void generate_cparameters (Method m, CCodeFile decl_space, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, CCodeFunctionCall? vcall = null) {
 	}
 
-	public virtual void generate_property_accessor_declaration (PropertyAccessor acc, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_property_accessor_declaration (PropertyAccessor acc, CCodeFile decl_space) {
 	}
 
 	public override void visit_destructor (Destructor d) {
@@ -728,7 +663,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	void capture_parameter (FormalParameter param, CCodeStruct data, CCodeBlock cblock, int block_id, CCodeBlock free_block) {
-		generate_type_declaration (param.variable_type, source_declarations);
+		generate_type_declaration (param.variable_type, cfile);
 
 		var param_type = param.variable_type.copy ();
 		param_type.value_owned = true;
@@ -800,7 +735,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			}
 			foreach (var local in local_vars) {
 				if (local.captured) {
-					generate_type_declaration (local.variable_type, source_declarations);
+					generate_type_declaration (local.variable_type, cfile);
 
 					data.add_field (local.variable_type.get_cname (), get_variable_cname (local.name) + local.variable_type.get_cdeclarator_suffix ());
 				}
@@ -868,8 +803,8 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			}
 
 			var typedef = new CCodeTypeDefinition ("struct _" + struct_name, new CCodeVariableDeclarator (struct_name));
-			source_declarations.add_type_declaration (typedef);
-			source_declarations.add_type_definition (data);
+			cfile.add_type_declaration (typedef);
+			cfile.add_type_definition (data);
 
 			var data_free = new CCodeFunctionCall (new CCodeIdentifier ("free"));
 			data_free.add_argument (new CCodeIdentifier ("_data%d_".printf (block_id)));
@@ -878,23 +813,23 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			// create type_get/finalize functions
 			var type_get_fun = new CCodeFunction ("block%d_data_type_get".printf (block_id), "DovaType*");
 			type_get_fun.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (type_get_fun.copy ());
+			cfile.add_type_member_declaration (type_get_fun.copy ());
 			type_get_fun.block = new CCodeBlock ();
 
 			var cdecl = new CCodeDeclaration ("int");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_block%d_data_object_offset".printf (block_id), new CCodeConstant ("0")));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (cdecl);
+			cfile.add_type_member_declaration (cdecl);
 
 			cdecl = new CCodeDeclaration ("int");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_block%d_data_type_offset".printf (block_id), new CCodeConstant ("0")));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (cdecl);
+			cfile.add_type_member_declaration (cdecl);
 
 			cdecl = new CCodeDeclaration ("DovaType *");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("block%d_data_type".printf (block_id), new CCodeConstant ("NULL")));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (cdecl);
+			cfile.add_type_member_declaration (cdecl);
 
 			var type_init_block = new CCodeBlock ();
 			var alloc_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_alloc"));
@@ -911,15 +846,15 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			type_get_fun.block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("block%d_data_type".printf (block_id))), type_init_block));
 			type_get_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("block%d_data_type".printf (block_id))));
 
-			source_type_member_definition.append (type_get_fun);
+			cfile.add_function (type_get_fun);
 
 			var unref_fun = new CCodeFunction ("block%d_data_finalize".printf (block_id), "void");
 			unref_fun.add_parameter (new CCodeFormalParameter ("_data%d_".printf (block_id), struct_name + "*"));
 			unref_fun.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (unref_fun.copy ());
+			cfile.add_type_member_declaration (unref_fun.copy ());
 			unref_fun.block = free_block;
 
-			source_type_member_definition.append (unref_fun);
+			cfile.add_function (unref_fun);
 		}
 
 		foreach (CodeNode stmt in b.get_statements ()) {
@@ -1014,7 +949,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			visit_end_full_expression (local.initializer);
 		}
 
-		generate_type_declaration (local.variable_type, source_declarations);
+		generate_type_declaration (local.variable_type, cfile);
 
 		CCodeExpression rhs = null;
 		if (local.initializer != null && local.initializer.ccodenode != null) {
@@ -1605,7 +1540,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public override void visit_base_access (BaseAccess expr) {
-		generate_type_declaration (expr.value_type, source_declarations);
+		generate_type_declaration (expr.value_type, cfile);
 		expr.ccodenode = new CCodeCastExpression (new CCodeIdentifier ("this"), expr.value_type.get_cname ());
 	}
 
@@ -1784,16 +1719,16 @@ public class Vala.DovaBaseModule : CodeGenerator {
 		}
 	}
 
-	public virtual void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_class_declaration (Class cl, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
 	}
 
-	public virtual void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 	}
 
-	public virtual void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
+	public virtual void generate_method_declaration (Method m, CCodeFile decl_space) {
 	}
 
 	public void add_generic_type_arguments (CCodeFunctionCall ccall, List<DataType> type_args, CodeNode expr, bool is_chainup = false) {
@@ -1837,7 +1772,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			var params = m.get_parameters ();
 			CCodeFunctionCall creation_call;
 
-			generate_method_declaration (m, source_declarations);
+			generate_method_declaration (m, cfile);
 
 			var cl = expr.type_reference.data_type as Class;
 
@@ -1853,7 +1788,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
 			}
 
-			generate_type_declaration (expr.type_reference, source_declarations);
+			generate_type_declaration (expr.type_reference, cfile);
 
 			if (cl != null && !cl.is_compact) {
 				add_generic_type_arguments (creation_call, expr.type_reference.get_type_arguments (), expr);
@@ -2072,7 +2007,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			return;
 		}
 
-		generate_type_declaration (expr.type_reference, source_declarations);
+		generate_type_declaration (expr.type_reference, cfile);
 
 		if (expr.inner.value_type is GenericType && !(expr.type_reference is GenericType)) {
 			// generic types use an extra pointer, dereference that pointer
@@ -2207,7 +2142,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 	}
 
 	public override void visit_type_check (TypeCheck expr) {
-		generate_type_declaration (expr.type_reference, source_declarations);
+		generate_type_declaration (expr.type_reference, cfile);
 
 		expr.ccodenode = create_type_check (expr.expression.ccodenode, expr.type_reference);
 		if (expr.ccodenode is CCodeInvalidExpression) {
@@ -2282,7 +2217,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			return cexpr;
 		}
 
-		generate_type_declaration (target_type, source_declarations);
+		generate_type_declaration (target_type, cfile);
 
 		if (target_type is DelegateType && expression_type is MethodType) {
 			var deleg_type = (DelegateType) target_type;
@@ -2360,7 +2295,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 				}
 			}
 
-			source_type_member_definition.append (wrapper);
+			cfile.add_function (wrapper);
 
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_new".printf (deleg_type.delegate_symbol.get_lower_case_cname ())));
 			ccall.add_argument (delegate_target);
@@ -2396,7 +2331,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
 			base_property = prop.base_interface_property;
 		}
 
-		generate_property_accessor_declaration (base_property.set_accessor, source_declarations);
+		generate_property_accessor_declaration (base_property.set_accessor, cfile);
 		set_func = base_property.set_accessor.get_cname ();
 
 		var ccall = new CCodeFunctionCall (new CCodeIdentifier (set_func));
diff --git a/codegen/valadovadelegatemodule.vala b/codegen/valadovadelegatemodule.vala
index 0b41a2a..d8b066e 100644
--- a/codegen/valadovadelegatemodule.vala
+++ b/codegen/valadovadelegatemodule.vala
@@ -25,7 +25,7 @@
  * The link between a delegate and generated code.
  */
 public class Vala.DovaDelegateModule : DovaValueModule {
-	public override void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
+	public override void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, d, d.get_cname ())) {
 			return;
 		}
@@ -60,7 +60,7 @@ public class Vala.DovaDelegateModule : DovaValueModule {
 		decl_space.add_type_member_declaration (function);
 	}
 
-	CCodeFunction generate_new_function (Delegate d, CCodeDeclarationSpace decl_space) {
+	CCodeFunction generate_new_function (Delegate d, CCodeFile decl_space) {
 		var function = new CCodeFunction ("%s_new".printf (d.get_lower_case_cname ()), "%s*".printf (d.get_cname ()));
 		if (d.is_internal_symbol ()) {
 			function.modifiers |= CCodeModifiers.STATIC;
@@ -93,7 +93,7 @@ public class Vala.DovaDelegateModule : DovaValueModule {
 		return function;
 	}
 
-	CCodeFunction generate_invoke_function (Delegate d, CCodeDeclarationSpace decl_space) {
+	CCodeFunction generate_invoke_function (Delegate d, CCodeFile decl_space) {
 		var function = new CCodeFunction ("%s_invoke".printf (d.get_lower_case_cname ()));
 
 		if (d.is_internal_symbol ()) {
@@ -187,10 +187,10 @@ public class Vala.DovaDelegateModule : DovaValueModule {
 	public override void visit_delegate (Delegate d) {
 		d.accept_children (this);
 
-		generate_delegate_declaration (d, source_declarations);
+		generate_delegate_declaration (d, cfile);
 
 		if (!d.is_internal_symbol ()) {
-			generate_delegate_declaration (d, header_declarations);
+			generate_delegate_declaration (d, header_file);
 		}
 
 		generate_type_get_function (d, delegate_class);
@@ -199,23 +199,23 @@ public class Vala.DovaDelegateModule : DovaValueModule {
 
 		instance_priv_struct.add_field ("void", "(*method) (void)");
 
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (d.get_cname ()))));
-		source_declarations.add_type_definition (instance_priv_struct);
+		cfile.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (instance_priv_struct.name), new CCodeVariableDeclarator ("%sPrivate".printf (d.get_cname ()))));
+		cfile.add_type_definition (instance_priv_struct);
 
 		string macro = "((%sPrivate *) (((char *) o) + _%s_object_offset))".printf (d.get_cname (), d.get_lower_case_cname ());
-		source_declarations.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (d.get_upper_case_cname (null)), macro));
+		cfile.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (d.get_upper_case_cname (null)), macro));
 
 		var cdecl = new CCodeDeclaration ("int");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_%s_object_offset".printf (d.get_lower_case_cname ()), new CCodeConstant ("0")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cdecl);
+		cfile.add_type_member_declaration (cdecl);
 
 		cdecl = new CCodeDeclaration ("int");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_%s_type_offset".printf (d.get_lower_case_cname ()), new CCodeConstant ("0")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cdecl);
+		cfile.add_type_member_declaration (cdecl);
 
-		source_type_member_definition.append (generate_new_function (d, source_declarations));
-		source_type_member_definition.append (generate_invoke_function (d, source_declarations));
+		cfile.add_function (generate_new_function (d, cfile));
+		cfile.add_function (generate_invoke_function (d, cfile));
 	}
 }
diff --git a/codegen/valadovaerrormodule.vala b/codegen/valadovaerrormodule.vala
index 8813760..f38bafd 100644
--- a/codegen/valadovaerrormodule.vala
+++ b/codegen/valadovaerrormodule.vala
@@ -270,7 +270,7 @@ public class Vala.DovaErrorModule : DovaDelegateModule {
 	}
 
 	public override void visit_catch_clause (CatchClause clause) {
-		generate_type_declaration (clause.error_type, source_declarations);
+		generate_type_declaration (clause.error_type, cfile);
 
 		clause.body.emit (this);
 
diff --git a/codegen/valadovamemberaccessmodule.vala b/codegen/valadovamemberaccessmodule.vala
index 2b8c621..3e7b102 100644
--- a/codegen/valadovamemberaccessmodule.vala
+++ b/codegen/valadovamemberaccessmodule.vala
@@ -39,7 +39,7 @@ public class Vala.DovaMemberAccessModule : DovaControlFlowModule {
 			var m = (Method) expr.symbol_reference;
 
 			if (!(m is DynamicMethod)) {
-				generate_method_declaration (m, source_declarations);
+				generate_method_declaration (m, cfile);
 
 				if (!m.external && m.external_package) {
 					// internal VAPI methods
@@ -91,7 +91,7 @@ public class Vala.DovaMemberAccessModule : DovaControlFlowModule {
 				expr.ccodenode = new CCodeIdentifier (m.get_cname ());
 			}
 		} else if (expr.symbol_reference is ArrayLengthField) {
-			generate_property_accessor_declaration (((Property) array_class.scope.lookup ("length")).get_accessor, source_declarations);
+			generate_property_accessor_declaration (((Property) array_class.scope.lookup ("length")).get_accessor, cfile);
 
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_length"));
 			ccall.add_argument (pub_inst);
@@ -121,27 +121,27 @@ public class Vala.DovaMemberAccessModule : DovaControlFlowModule {
 					expr.ccodenode = new CCodeMemberAccess (inst, f.get_cname ());
 				}
 			} else {
-				generate_field_declaration (f, source_declarations);
+				generate_field_declaration (f, cfile);
 
 				expr.ccodenode = new CCodeIdentifier (f.get_cname ());
 			}
 		} else if (expr.symbol_reference is EnumValue) {
 			var ev = (EnumValue) expr.symbol_reference;
 
-			generate_enum_declaration ((Enum) ev.parent_symbol, source_declarations);
+			generate_enum_declaration ((Enum) ev.parent_symbol, cfile);
 
 			expr.ccodenode = new CCodeConstant (ev.get_cname ());
 		} else if (expr.symbol_reference is Constant) {
 			var c = (Constant) expr.symbol_reference;
 
-			generate_constant_declaration (c, source_declarations);
+			generate_constant_declaration (c, cfile);
 
 			expr.ccodenode = new CCodeIdentifier (c.get_cname ());
 		} else if (expr.symbol_reference is Property) {
 			var prop = (Property) expr.symbol_reference;
 
 			if (!(prop is DynamicProperty)) {
-				generate_property_accessor_declaration (prop.get_accessor, source_declarations);
+				generate_property_accessor_declaration (prop.get_accessor, cfile);
 
 				if (!prop.external && prop.external_package) {
 					// internal VAPI properties
diff --git a/codegen/valadovamethodcallmodule.vala b/codegen/valadovamethodcallmodule.vala
index 40f56b4..7a245b0 100644
--- a/codegen/valadovamethodcallmodule.vala
+++ b/codegen/valadovamethodcallmodule.vala
@@ -41,7 +41,7 @@ public class Vala.DovaMethodCallModule : DovaAssignmentModule {
 			// constructor
 			var cl = (Class) ((ObjectType) itype).type_symbol;
 			m = cl.default_construction_method;
-			generate_method_declaration (m, source_declarations);
+			generate_method_declaration (m, cfile);
 			ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
 		} else if (itype is DelegateType) {
 			deleg = ((DelegateType) itype).delegate_symbol;
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index a32529b..d578b76 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -21,7 +21,7 @@
  */
 
 public class Vala.DovaObjectModule : DovaArrayModule {
-	public override void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public override void generate_class_declaration (Class cl, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
@@ -49,7 +49,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			value_copy_function.add_parameter (new CCodeFormalParameter ("src", "void *"));
 			value_copy_function.add_parameter (new CCodeFormalParameter ("src_index", "int32_t"));
 
-			source_declarations.add_type_member_declaration (value_copy_function);
+			cfile.add_type_member_declaration (value_copy_function);
 
 			var value_equals_function = new CCodeFunction ("dova_type_value_equals", "bool");
 			value_equals_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
@@ -58,14 +58,14 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			value_equals_function.add_parameter (new CCodeFormalParameter ("other", "void *"));
 			value_equals_function.add_parameter (new CCodeFormalParameter ("other_index", "int32_t"));
 
-			source_declarations.add_type_member_declaration (value_equals_function);
+			cfile.add_type_member_declaration (value_equals_function);
 
 			var value_hash_function = new CCodeFunction ("dova_type_value_hash", "uint32_t");
 			value_hash_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
 			value_hash_function.add_parameter (new CCodeFormalParameter ("value", "void *"));
 			value_hash_function.add_parameter (new CCodeFormalParameter ("value_index", "int32_t"));
 
-			source_declarations.add_type_member_declaration (value_hash_function);
+			cfile.add_type_member_declaration (value_hash_function);
 		}
 
 		if (cl.base_class != null) {
@@ -95,7 +95,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		decl_space.add_type_member_declaration (type_init_fun);
 	}
 
-	void generate_virtual_method_declaration (Method m, CCodeDeclarationSpace decl_space, CCodeStruct type_struct) {
+	void generate_virtual_method_declaration (Method m, CCodeFile decl_space, CCodeStruct type_struct) {
 		if (!m.is_abstract && !m.is_virtual) {
 			return;
 		}
@@ -136,7 +136,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return false;
 	}
 
-	void generate_class_private_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	void generate_class_private_declaration (Class cl, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, cl, cl.get_cname () + "Private")) {
 			return;
 		}
@@ -305,7 +305,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return result;
 	}
 
-	public void declare_set_value_copy_function (CCodeDeclarationSpace decl_space) {
+	public void declare_set_value_copy_function (CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_copy")) {
 			return;
 		}
@@ -329,7 +329,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return result;
 	}
 
-	public void declare_set_value_equals_function (CCodeDeclarationSpace decl_space) {
+	public void declare_set_value_equals_function (CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_equals")) {
 			return;
 		}
@@ -353,7 +353,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return result;
 	}
 
-	public void declare_set_value_hash_function (CCodeDeclarationSpace decl_space) {
+	public void declare_set_value_hash_function (CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_hash")) {
 			return;
 		}
@@ -377,7 +377,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return result;
 	}
 
-	public void declare_set_value_to_any_function (CCodeDeclarationSpace decl_space) {
+	public void declare_set_value_to_any_function (CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_to_any")) {
 			return;
 		}
@@ -401,7 +401,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return result;
 	}
 
-	public void declare_set_value_from_any_function (CCodeDeclarationSpace decl_space) {
+	public void declare_set_value_from_any_function (CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, type_class, "dova_type_set_value_from_any")) {
 			return;
 		}
@@ -422,7 +422,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		var cdecl = new CCodeDeclaration ("DovaType *");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("%s_type".printf (cl.get_lower_case_cname ()), new CCodeConstant ("NULL")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cdecl);
+		cfile.add_type_member_declaration (cdecl);
 
 		var type_fun = new CCodeFunction ("%s_type_get".printf (cl.get_lower_case_cname ()), "DovaType *");
 		if (cl.is_internal_symbol ()) {
@@ -464,8 +464,8 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 			type_init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())), "type"), new CCodeFunctionCall (new CCodeIdentifier ("dova_type_type_get")))));
 		} else {
-			generate_method_declaration ((Method) object_class.scope.lookup ("alloc"), source_declarations);
-			generate_method_declaration ((Method) type_class.scope.lookup ("alloc"), source_declarations);
+			generate_method_declaration ((Method) object_class.scope.lookup ("alloc"), cfile);
+			generate_method_declaration ((Method) type_class.scope.lookup ("alloc"), cfile);
 
 			var base_type = new CCodeFunctionCall (new CCodeIdentifier ("%s_type_get".printf (base_class.get_lower_case_cname ())));
 			for (int i = 0; i < base_class.get_type_parameters ().size; i++) {
@@ -508,8 +508,8 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			// generics
 			var specialized_type_get_block = new CCodeBlock ();
 
-			generate_property_accessor_declaration (((Property) type_class.scope.lookup ("next_type")).get_accessor, source_declarations);
-			generate_method_declaration ((Method) type_class.scope.lookup ("insert_type"), source_declarations);
+			generate_property_accessor_declaration (((Property) type_class.scope.lookup ("next_type")).get_accessor, cfile);
+			generate_method_declaration ((Method) type_class.scope.lookup ("insert_type"), cfile);
 
 			var first = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_get_next_type"));
 			first.add_argument (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ())));
@@ -529,7 +529,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 			var specialized_type_init_block = new CCodeBlock ();
 
-			generate_method_declaration ((Method) type_class.scope.lookup ("alloc"), source_declarations);
+			generate_method_declaration ((Method) type_class.scope.lookup ("alloc"), cfile);
 
 			var base_type = new CCodeFunctionCall (new CCodeIdentifier ("%s_type_get".printf (base_class.get_lower_case_cname ())));
 			if (base_class_type != null) {
@@ -579,7 +579,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 		type_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("%s_type".printf (cl.get_lower_case_cname ()))));
 
-		source_type_member_definition.append (type_fun);
+		cfile.add_function (type_fun);
 
 		var type_init_fun = new CCodeFunction ("%s_type_init".printf (cl.get_lower_case_cname ()));
 		if (cl.is_internal_symbol ()) {
@@ -602,7 +602,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			set_size.add_argument (sizeof_call);
 			type_init_fun.block.add_statement (new CCodeExpressionStatement (set_size));
 
-			declare_set_value_copy_function (source_declarations);
+			declare_set_value_copy_function (cfile);
 
 			var value_copy_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_copy"));
 			value_copy_call.add_argument (new CCodeIdentifier ("type"));
@@ -636,7 +636,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ref_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, dest), ref_call)));
 			function.block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("src"), ref_block));
 
-			source_type_member_definition.append (function);
+			cfile.add_function (function);
 
 			{
 				var value_equals_fun = new CCodeFunction ("%s_value_equals".printf (cl.get_lower_case_cname ()), "bool");
@@ -652,9 +652,9 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
 				ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, other));
 				value_equals_fun.block.add_statement (new CCodeReturnStatement (ccall));
-				source_type_member_definition.append (value_equals_fun);
+				cfile.add_function (value_equals_fun);
 
-				declare_set_value_equals_function (source_declarations);
+				declare_set_value_equals_function (cfile);
 
 				var value_equals_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_equals"));
 				value_equals_call.add_argument (new CCodeIdentifier ("type"));
@@ -672,9 +672,9 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				var ccall = new CCodeFunctionCall (new CCodeIdentifier ("any_hash"));
 				ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
 				value_hash_fun.block.add_statement (new CCodeReturnStatement (ccall));
-				source_type_member_definition.append (value_hash_fun);
+				cfile.add_function (value_hash_fun);
 
-				declare_set_value_hash_function (source_declarations);
+				declare_set_value_hash_function (cfile);
 
 				var value_hash_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_hash"));
 				value_hash_call.add_argument (new CCodeIdentifier ("type"));
@@ -696,9 +696,9 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier (to_any_fun));
 			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
 			value_to_any_fun.block.add_statement (new CCodeReturnStatement (ccall));
-			source_type_member_definition.append (value_to_any_fun);
+			cfile.add_function (value_to_any_fun);
 
-			declare_set_value_to_any_function (source_declarations);
+			declare_set_value_to_any_function (cfile);
 
 			var value_to_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_to_any"));
 			value_to_any_call.add_argument (new CCodeIdentifier ("type"));
@@ -720,9 +720,9 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ccall.add_argument (new CCodeIdentifier ("any_"));
 			value_from_any_fun.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val), ccall)));
 			value_from_any_fun.block.add_statement (new CCodeReturnStatement (ccall));
-			source_type_member_definition.append (value_from_any_fun);
+			cfile.add_function (value_from_any_fun);
 
-			declare_set_value_from_any_function (source_declarations);
+			declare_set_value_from_any_function (cfile);
 
 			var value_from_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_from_any"));
 			value_from_any_call.add_argument (new CCodeIdentifier ("type"));
@@ -747,7 +747,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			}
 		}
 
-		source_type_member_definition.append (type_init_fun);
+		cfile.add_function (type_init_fun);
 
 		return type_init_fun.block;
 	}
@@ -758,7 +758,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 		function.add_parameter (new CCodeFormalParameter ("this", cl.get_cname () + "*"));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 
 		var cblock = new CCodeBlock ();
@@ -787,7 +787,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	public override void visit_class (Class cl) {
@@ -796,11 +796,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		var old_instance_finalize_fragment = instance_finalize_fragment;
 		instance_finalize_fragment = new CCodeFragment ();
 
-		generate_class_declaration (cl, source_declarations);
-		generate_class_private_declaration (cl, source_declarations);
+		generate_class_declaration (cl, cfile);
+		generate_class_private_declaration (cl, cfile);
 
 		if (!cl.is_internal_symbol ()) {
-			generate_class_declaration (cl, header_declarations);
+			generate_class_declaration (cl, header_file);
 		}
 
 		cl.accept_children (this);
@@ -810,7 +810,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		foreach (DataType base_type in cl.get_base_types ()) {
 			var object_type = (ObjectType) base_type;
 			if (object_type.type_symbol is Interface) {
-				generate_interface_declaration ((Interface) object_type.type_symbol, source_declarations);
+				generate_interface_declaration ((Interface) object_type.type_symbol, cfile);
 
 				var type_init_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_type_init".printf (object_type.type_symbol.get_lower_case_cname ())));
 				type_init_call.add_argument (new CCodeIdentifier ("type"));
@@ -825,7 +825,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		if (cl.base_class != null && !cl.is_fundamental () && (cl.get_fields ().size > 0 || cl.destructor != null)) {
 			add_finalize_function (cl);
 
-			generate_method_declaration ((Method) object_class.scope.lookup ("finalize"), source_declarations);
+			generate_method_declaration ((Method) object_class.scope.lookup ("finalize"), cfile);
 
 			var override_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_object_override_finalize"));
 			override_call.add_argument (new CCodeIdentifier ("type"));
@@ -884,11 +884,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ccall.add_argument (new CCodeIdentifier ("src_index"));
 			value_copy_function.block.add_statement (new CCodeExpressionStatement (ccall));
 
-			source_type_member_definition.append (value_copy_function);
+			cfile.add_function (value_copy_function);
 
-			declare_set_value_copy_function (source_declarations);
-			declare_set_value_copy_function (header_declarations);
-			source_type_member_definition.append (create_set_value_copy_function ());
+			declare_set_value_copy_function (cfile);
+			declare_set_value_copy_function (header_file);
+			cfile.add_function (create_set_value_copy_function ());
 
 			var value_equals_function = new CCodeFunction ("dova_type_value_equals", "bool");
 			value_equals_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
@@ -906,11 +906,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ccall.add_argument (new CCodeIdentifier ("other_index"));
 			value_equals_function.block.add_statement (new CCodeReturnStatement (ccall));
 
-			source_type_member_definition.append (value_equals_function);
+			cfile.add_function (value_equals_function);
 
-			declare_set_value_equals_function (source_declarations);
-			declare_set_value_equals_function (header_declarations);
-			source_type_member_definition.append (create_set_value_equals_function ());
+			declare_set_value_equals_function (cfile);
+			declare_set_value_equals_function (header_file);
+			cfile.add_function (create_set_value_equals_function ());
 
 			var value_hash_function = new CCodeFunction ("dova_type_value_hash", "uint32_t");
 			value_hash_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
@@ -924,11 +924,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ccall.add_argument (new CCodeIdentifier ("value_index"));
 			value_hash_function.block.add_statement (new CCodeReturnStatement (ccall));
 
-			source_type_member_definition.append (value_hash_function);
+			cfile.add_function (value_hash_function);
 
-			declare_set_value_hash_function (source_declarations);
-			declare_set_value_hash_function (header_declarations);
-			source_type_member_definition.append (create_set_value_hash_function ());
+			declare_set_value_hash_function (cfile);
+			declare_set_value_hash_function (header_file);
+			cfile.add_function (create_set_value_hash_function ());
 
 			var value_to_any_function = new CCodeFunction ("dova_type_value_to_any", "DovaObject *");
 			value_to_any_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
@@ -942,11 +942,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ccall.add_argument (new CCodeIdentifier ("value_index"));
 			value_to_any_function.block.add_statement (new CCodeReturnStatement (ccall));
 
-			source_type_member_definition.append (value_to_any_function);
+			cfile.add_function (value_to_any_function);
 
-			declare_set_value_to_any_function (source_declarations);
-			declare_set_value_to_any_function (header_declarations);
-			source_type_member_definition.append (create_set_value_to_any_function ());
+			declare_set_value_to_any_function (cfile);
+			declare_set_value_to_any_function (header_file);
+			cfile.add_function (create_set_value_to_any_function ());
 
 			var value_from_any_function = new CCodeFunction ("dova_type_value_from_any", "void");
 			value_from_any_function.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
@@ -962,11 +962,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			ccall.add_argument (new CCodeIdentifier ("value_index"));
 			value_from_any_function.block.add_statement (new CCodeReturnStatement (ccall));
 
-			source_type_member_definition.append (value_from_any_function);
+			cfile.add_function (value_from_any_function);
 
-			declare_set_value_from_any_function (source_declarations);
-			declare_set_value_from_any_function (header_declarations);
-			source_type_member_definition.append (create_set_value_from_any_function ());
+			declare_set_value_from_any_function (cfile);
+			declare_set_value_from_any_function (header_file);
+			cfile.add_function (create_set_value_from_any_function ());
 		}
 
 		instance_finalize_fragment = old_instance_finalize_fragment;
@@ -977,7 +977,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 	public override void visit_interface (Interface iface) {
 		push_context (new EmitContext (iface));
 
-		generate_interface_declaration (iface, source_declarations);
+		generate_interface_declaration (iface, cfile);
 
 		var type_priv_struct = new CCodeStruct ("_%sTypePrivate".printf (iface.get_cname ()));
 
@@ -988,16 +988,16 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		}
 
 		foreach (Method m in iface.get_methods ()) {
-			generate_virtual_method_declaration (m, source_declarations, type_priv_struct);
+			generate_virtual_method_declaration (m, cfile, type_priv_struct);
 		}
 
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_priv_struct.name), new CCodeVariableDeclarator ("%sTypePrivate".printf (iface.get_cname ()))));
-		source_declarations.add_type_definition (type_priv_struct);
+		cfile.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_priv_struct.name), new CCodeVariableDeclarator ("%sTypePrivate".printf (iface.get_cname ()))));
+		cfile.add_type_definition (type_priv_struct);
 
 		var cdecl = new CCodeDeclaration ("DovaType *");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("%s_type".printf (iface.get_lower_case_cname ()), new CCodeConstant ("NULL")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cdecl);
+		cfile.add_type_member_declaration (cdecl);
 
 		var type_fun = new CCodeFunction ("%s_type_get".printf (iface.get_lower_case_cname ()), "DovaType *");
 		if (iface.is_internal_symbol ()) {
@@ -1032,7 +1032,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 		type_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("%s_type".printf (iface.get_lower_case_cname ()))));
 
-		source_type_member_definition.append (type_fun);
+		cfile.add_function (type_fun);
 
 		var type_init_fun = new CCodeFunction ("%s_type_init".printf (iface.get_lower_case_cname ()));
 		if (iface.is_internal_symbol ()) {
@@ -1068,14 +1068,14 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		add_interface_call.add_argument (vtable_alloc);
 		type_init_fun.block.add_statement (new CCodeExpressionStatement (add_interface_call));
 
-		source_type_member_definition.append (type_init_fun);
+		cfile.add_function (type_init_fun);
 
 		iface.accept_children (this);
 
 		pop_context ();
 	}
 
-	public override void generate_property_accessor_declaration (PropertyAccessor acc, CCodeDeclarationSpace decl_space) {
+	public override void generate_property_accessor_declaration (PropertyAccessor acc, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, acc.prop, acc.get_cname ())) {
 			return;
 		}
@@ -1150,12 +1150,12 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		// do not declare overriding properties and interface implementations
 		if (prop.is_abstract || prop.is_virtual
 		    || (prop.base_property == null && prop.base_interface_property == null)) {
-			generate_property_accessor_declaration (acc, source_declarations);
+			generate_property_accessor_declaration (acc, cfile);
 
 			if (!prop.is_internal_symbol ()
 			    && (acc.access == SymbolAccessibility.PUBLIC
 				|| acc.access == SymbolAccessibility.PROTECTED)) {
-				generate_property_accessor_declaration (acc, header_declarations);
+				generate_property_accessor_declaration (acc, header_file);
 			}
 		}
 
@@ -1205,7 +1205,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				block.add_statement (new CCodeExpressionStatement (vcall));
 			}
 
-			source_type_member_definition.append (function);
+			cfile.add_function (function);
 
 
 			string param_list = "(%s *this".printf (((ObjectTypeSymbol) prop.parent_symbol).get_cname ());
@@ -1224,7 +1224,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 			override_func.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (vcast, "%s_%s".printf (acc.readable ? "get" : "set", prop.name)), new CCodeIdentifier ("function"))));
 
-			source_type_member_definition.append (override_func);
+			cfile.add_function (override_func);
 		}
 
 		if (!prop.is_abstract) {
@@ -1257,13 +1257,13 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				function.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
 			}
 
-			source_type_member_definition.append (function);
+			cfile.add_function (function);
 		}
 
 		pop_context ();
 	}
 
-	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, iface, iface.get_cname ())) {
 			return;
 		}
@@ -1310,7 +1310,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return null;
 	}
 
-	public override void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
+	public override void generate_method_declaration (Method m, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, m, m.get_cname ())) {
 			return;
 		}
@@ -1396,23 +1396,23 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 		pop_context ();
 
-		generate_method_declaration (m, source_declarations);
+		generate_method_declaration (m, cfile);
 
 		if (!m.is_internal_symbol ()) {
-			generate_method_declaration (m, header_declarations);
+			generate_method_declaration (m, header_file);
 		}
 
 		var function = new CCodeFunction (m.get_real_cname ());
 		m.ccodenode = function;
 
-		generate_cparameters (m, source_declarations, function);
+		generate_cparameters (m, cfile, function);
 
 		// generate *_real_* functions for virtual methods
 		if (!m.is_abstract) {
 			if (m.base_method != null || m.base_interface_method != null) {
 				// declare *_real_* function
 				function.modifiers |= CCodeModifiers.STATIC;
-				source_declarations.add_type_member_declaration (function.copy ());
+				cfile.add_type_member_declaration (function.copy ());
 			} else if (m.is_internal_symbol ()) {
 				function.modifiers |= CCodeModifiers.STATIC;
 			}
@@ -1497,12 +1497,12 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 					function.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("this")));
 				}
 
-				source_type_member_definition.append (function);
+				cfile.add_function (function);
 			}
 		}
 
 		if (m.is_abstract || m.is_virtual) {
-			generate_class_declaration ((Class) object_class, source_declarations);
+			generate_class_declaration ((Class) object_class, cfile);
 
 			var vfunc = new CCodeFunction (m.get_cname (), (m.return_type is GenericType) ? "void" : m.return_type.get_cname ());
 			vfunc.block = new CCodeBlock ();
@@ -1561,7 +1561,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				vfunc.block.add_statement (new CCodeReturnStatement (vcall));
 			}
 
-			source_type_member_definition.append (vfunc);
+			cfile.add_function (vfunc);
 
 
 			vfunc = new CCodeFunction ("%sbase_%s".printf (m.parent_symbol.get_lower_case_cprefix (), m.name), (m.return_type is GenericType) ? "void" : m.return_type.get_cname ());
@@ -1605,7 +1605,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				vfunc.block.add_statement (new CCodeReturnStatement (vcall));
 			}
 
-			source_type_member_definition.append (vfunc);
+			cfile.add_function (vfunc);
 
 
 			string param_list = "(%s *this".printf (((ObjectTypeSymbol) m.parent_symbol).get_cname ());
@@ -1627,11 +1627,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 
 			override_func.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (vcast, m.name), new CCodeIdentifier ("function"))));
 
-			source_type_member_definition.append (override_func);
+			cfile.add_function (override_func);
 		}
 
 		if (m.entry_point) {
-			generate_type_declaration (new ObjectType (array_class), source_declarations);
+			generate_type_declaration (new ObjectType (array_class), cfile);
 
 			// m is possible entry point, add appropriate startup code
 			var cmain = new CCodeFunction ("main", "int");
@@ -1712,7 +1712,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			main_block.add_statement (ret_stmt);
 
 			cmain.block = main_block;
-			source_type_member_definition.append (cmain);
+			cfile.add_function (cmain);
 		}
 	}
 
@@ -1772,7 +1772,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			vcall.add_argument (new CCodeIdentifier ("this"));
 			vblock.add_statement (new CCodeExpressionStatement (vcall));
 
-			generate_cparameters (m, source_declarations, vfunc, null, vcall);
+			generate_cparameters (m, cfile, vfunc, null, vcall);
 			CCodeStatement cstmt = new CCodeReturnStatement (new CCodeIdentifier ("this"));
 			cstmt.line = vfunc.line;
 			vblock.add_statement (cstmt);
@@ -1781,11 +1781,11 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 				vfunc.modifiers |= CCodeModifiers.STATIC;
 			}
 
-			source_declarations.add_type_member_declaration (vfunc.copy ());
+			cfile.add_type_member_declaration (vfunc.copy ());
 
 			vfunc.block = vblock;
 
-			source_type_member_definition.append (vfunc);
+			cfile.add_function (vfunc);
 		}
 	}
 
@@ -1799,7 +1799,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 		return null;
 	}
 
-	public override void generate_cparameters (Method m, CCodeDeclarationSpace decl_space, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, CCodeFunctionCall? vcall = null) {
+	public override void generate_cparameters (Method m, CCodeFile decl_space, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, CCodeFunctionCall? vcall = null) {
 		CCodeFormalParameter instance_param = null;
 		if (m.closure) {
 			var closure_block = current_closure_block;
@@ -1926,7 +1926,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
 			if (array_type.inline_allocated) {
 				expr.ccodenode = new CCodeElementAccess ((CCodeExpression) expr.container.ccodenode, cindex);
 			} else {
-				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, source_declarations);
+				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
 				var ccontainer = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_data"));
 				ccontainer.add_argument ((CCodeExpression) expr.container.ccodenode);
diff --git a/codegen/valadovastructmodule.vala b/codegen/valadovastructmodule.vala
index 4dee8f7..b7a99cd 100644
--- a/codegen/valadovastructmodule.vala
+++ b/codegen/valadovastructmodule.vala
@@ -23,7 +23,7 @@
 using GLib;
 
 public class Vala.DovaStructModule : DovaBaseModule {
-	public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
+	public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, st, st.get_cname ())) {
 			return;
 		}
@@ -75,10 +75,10 @@ public class Vala.DovaStructModule : DovaBaseModule {
 		var old_instance_finalize_fragment = instance_finalize_fragment;
 		instance_finalize_fragment = new CCodeFragment ();
 
-		generate_struct_declaration (st, source_declarations);
+		generate_struct_declaration (st, cfile);
 
 		if (!st.is_internal_symbol ()) {
-			generate_struct_declaration (st, header_declarations);
+			generate_struct_declaration (st, header_file);
 		}
 
 		st.accept_children (this);
diff --git a/codegen/valadovavaluemodule.vala b/codegen/valadovavaluemodule.vala
index 007025f..1f12d61 100644
--- a/codegen/valadovavaluemodule.vala
+++ b/codegen/valadovavaluemodule.vala
@@ -32,7 +32,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		visit_method (m);
 	}
 
-	public override void generate_struct_declaration (Struct st, CCodeDeclarationSpace decl_space) {
+	public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
 		base.generate_struct_declaration (st, decl_space);
 
 		if (add_symbol_declaration (decl_space, st, st.get_copy_function ())) {
@@ -73,32 +73,32 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		var cdecl = new CCodeDeclaration ("int");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_%s_object_offset".printf (st.get_lower_case_cname ()), new CCodeConstant ("0")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cdecl);
+		cfile.add_type_member_declaration (cdecl);
 
 		string macro = "((%s *) (((char *) o) + _%s_object_offset))".printf (st.get_cname (), st.get_lower_case_cname ());
-		source_declarations.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (st.get_upper_case_cname (null)), macro));
+		cfile.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_PRIVATE(o)".printf (st.get_upper_case_cname (null)), macro));
 
 
 		cdecl = new CCodeDeclaration ("DovaType *");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("%s_type".printf (st.get_lower_case_cname ()), new CCodeConstant ("NULL")));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cdecl);
+		cfile.add_type_member_declaration (cdecl);
 
 		var type_fun = new CCodeFunction ("%s_type_get".printf (st.get_lower_case_cname ()), "DovaType *");
 		type_fun.block = new CCodeBlock ();
 
 		var type_init_block = new CCodeBlock ();
 
-		generate_method_declaration ((Method) object_class.scope.lookup ("alloc"), source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("base_type")).get_accessor, source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("base_type")).set_accessor, source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("object_size")).get_accessor, source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("object_size")).set_accessor, source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("type_size")).get_accessor, source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("type_size")).set_accessor, source_declarations);
-		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("value_size")).set_accessor, source_declarations);
+		generate_method_declaration ((Method) object_class.scope.lookup ("alloc"), cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("base_type")).get_accessor, cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("base_type")).set_accessor, cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("object_size")).get_accessor, cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("object_size")).set_accessor, cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("type_size")).get_accessor, cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("type_size")).set_accessor, cfile);
+		generate_property_accessor_declaration (((Property) type_class.scope.lookup ("value_size")).set_accessor, cfile);
 
-		generate_class_declaration ((Class) context.root.scope.lookup ("Dova").scope.lookup ("Value"), source_declarations);
+		generate_class_declaration ((Class) context.root.scope.lookup ("Dova").scope.lookup ("Value"), cfile);
 
 		var base_type = new CCodeFunctionCall (new CCodeIdentifier ("dova_value_type_get"));
 
@@ -111,7 +111,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 
 		type_init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("%s_type".printf (st.get_lower_case_cname ())), calloc_call)));
 
-		generate_class_declaration ((Class) object_class, source_declarations);
+		generate_class_declaration ((Class) object_class, cfile);
 
 		type_init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeCastExpression (new CCodeIdentifier ("%s_type".printf (st.get_lower_case_cname ())), "DovaObject *"), "type"), new CCodeFunctionCall (new CCodeIdentifier ("dova_type_type_get")))));
 
@@ -156,7 +156,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 
 		type_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("%s_type".printf (st.get_lower_case_cname ()))));
 
-		source_type_member_definition.append (type_fun);
+		cfile.add_function (type_fun);
 
 		var type_init_fun = new CCodeFunction ("%s_type_init".printf (st.get_lower_case_cname ()));
 		type_init_fun.add_parameter (new CCodeFormalParameter ("type", "DovaType *"));
@@ -166,7 +166,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		type_init_call.add_argument (new CCodeIdentifier ("type"));
 		type_init_fun.block.add_statement (new CCodeExpressionStatement (type_init_call));
 
-		declare_set_value_copy_function (source_declarations);
+		declare_set_value_copy_function (cfile);
 
 		var value_copy_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_copy"));
 		value_copy_call.add_argument (new CCodeIdentifier ("type"));
@@ -187,9 +187,9 @@ public class Vala.DovaValueModule : DovaObjectModule {
 			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
 			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, other));
 			value_equals_fun.block.add_statement (new CCodeReturnStatement (ccall));
-			source_type_member_definition.append (value_equals_fun);
+			cfile.add_function (value_equals_fun);
 
-			declare_set_value_equals_function (source_declarations);
+			declare_set_value_equals_function (cfile);
 
 			var value_equals_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_equals"));
 			value_equals_call.add_argument (new CCodeIdentifier ("type"));
@@ -207,9 +207,9 @@ public class Vala.DovaValueModule : DovaObjectModule {
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_hash".printf (st.get_lower_case_cname ())));
 			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, val));
 			value_hash_fun.block.add_statement (new CCodeReturnStatement (ccall));
-			source_type_member_definition.append (value_hash_fun);
+			cfile.add_function (value_hash_fun);
 
-			declare_set_value_hash_function (source_declarations);
+			declare_set_value_hash_function (cfile);
 
 			var value_hash_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_hash"));
 			value_hash_call.add_argument (new CCodeIdentifier ("type"));
@@ -237,9 +237,9 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		copy_call.add_argument (new CCodeIdentifier ("value_index"));
 		value_to_any_fun.block.add_statement (new CCodeExpressionStatement (copy_call));
 		value_to_any_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
-		source_type_member_definition.append (value_to_any_fun);
+		cfile.add_function (value_to_any_fun);
 
-		declare_set_value_to_any_function (source_declarations);
+		declare_set_value_to_any_function (cfile);
 
 		var value_to_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_to_any"));
 		value_to_any_call.add_argument (new CCodeIdentifier ("type"));
@@ -261,16 +261,16 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		copy_call.add_argument (priv_call);
 		copy_call.add_argument (new CCodeConstant ("0"));
 		value_from_any_fun.block.add_statement (new CCodeExpressionStatement (copy_call));
-		source_type_member_definition.append (value_from_any_fun);
+		cfile.add_function (value_from_any_fun);
 
-		declare_set_value_from_any_function (source_declarations);
+		declare_set_value_from_any_function (cfile);
 
 		var value_from_any_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_set_value_from_any"));
 		value_from_any_call.add_argument (new CCodeIdentifier ("type"));
 		value_from_any_call.add_argument (new CCodeIdentifier ("%s_value_from_any".printf (st.get_lower_case_cname ())));
 		type_init_fun.block.add_statement (new CCodeExpressionStatement (value_from_any_call));
 
-		source_type_member_definition.append (type_init_fun);
+		cfile.add_function (type_init_fun);
 
 		add_struct_copy_function (st);
 	}
@@ -367,7 +367,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	public override void visit_assignment (Assignment assignment) {
@@ -398,7 +398,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 
 			var array_type = dest.value_type as ArrayType;
 			if (array_type != null && !array_type.inline_allocated) {
-				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, source_declarations);
+				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
 				var data_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_data"));
 				data_call.add_argument ((CCodeExpression) get_ccodenode (dest));
@@ -416,7 +416,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 
 			var array_type = src.value_type as ArrayType;
 			if (array_type != null && !array_type.inline_allocated) {
-				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, source_declarations);
+				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
 				var data_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_data"));
 				data_call.add_argument ((CCodeExpression) get_ccodenode (src));
@@ -460,7 +460,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		var right_ea = expr.right as ElementAccess;
 
 		if (left_ea != null) {
-			generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, source_declarations);
+			generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
 			var data_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_data"));
 			data_call.add_argument ((CCodeExpression) get_ccodenode (left_ea.container));
@@ -471,7 +471,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 		}
 
 		if (right_ea != null) {
-			generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, source_declarations);
+			generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
 			var data_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_data"));
 			data_call.add_argument ((CCodeExpression) get_ccodenode (right_ea.container));
@@ -515,7 +515,7 @@ public class Vala.DovaValueModule : DovaObjectModule {
 			if (val_ea != null) {
 				val = val_ea.container;
 
-				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, source_declarations);
+				generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
 				var data_call = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_get_data"));
 				data_call.add_argument ((CCodeExpression) get_ccodenode (val));
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 50b86fa..e8c93b9 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -270,12 +270,12 @@ public class Vala.GAsyncModule : GSignalModule {
 		cparam_map.set (get_param_pos (-1), new CCodeFormalParameter ("_callback_", "GAsyncReadyCallback"));
 		cparam_map.set (get_param_pos (-0.9), new CCodeFormalParameter ("_user_data_", "gpointer"));
 
-		generate_cparameters (m, source_declarations, cparam_map, asyncfunc, null, null, null, 1);
+		generate_cparameters (m, cfile, cparam_map, asyncfunc, null, null, null, 1);
 
 		if (m.base_method != null || m.base_interface_method != null) {
 			// declare *_real_* function
 			asyncfunc.modifiers |= CCodeModifiers.STATIC;
-			source_declarations.add_type_member_declaration (asyncfunc.copy ());
+			cfile.add_type_member_declaration (asyncfunc.copy ());
 		} else if (m.is_private_symbol ()) {
 			asyncfunc.modifiers |= CCodeModifiers.STATIC;
 		}
@@ -288,21 +288,21 @@ public 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_declarations.add_type_declaration (typedef);
-		source_declarations.add_type_definition (structure);
+		cfile.add_type_declaration (typedef);
+		cfile.add_type_definition (structure);
 	}
 
 	void append_function (CCodeFunction function) {
 		var block = function.block;
 		function.block = null;
  
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
-	public override void generate_method_declaration (Method m, CCodeDeclarationSpace decl_space) {
+	public override void generate_method_declaration (Method m, CCodeFile decl_space) {
 		if (m.coroutine) {
 			if (add_symbol_declaration (decl_space, m, m.get_cname ())) {
 				return;
@@ -339,17 +339,17 @@ public class Vala.GAsyncModule : GSignalModule {
 
 	public override void visit_method (Method m) {
 		if (m.coroutine) {
-			source_declarations.add_include ("gio/gio.h");
+			cfile.add_include ("gio/gio.h");
 			if (!m.is_internal_symbol ()) {
-				header_declarations.add_include ("gio/gio.h");
+				header_file.add_include ("gio/gio.h");
 			}
 
 			if (!m.is_abstract && m.body != null) {
 				var data = generate_data_struct (m);
 
 				append_function (generate_free_function (m));
-				source_type_member_definition.append (generate_async_function (m));
-				source_type_member_definition.append (generate_finish_function (m));
+				cfile.add_function (generate_async_function (m));
+				cfile.add_function (generate_finish_function (m));
 				append_function (generate_ready_function (m));
 
 				// append the _co function
@@ -361,13 +361,13 @@ public class Vala.GAsyncModule : GSignalModule {
 				// types are declared before the struct definition
 				append_struct (data);
 			} else {
-				generate_method_declaration (m, source_declarations);
+				generate_method_declaration (m, cfile);
 
 				if (!m.is_internal_symbol ()) {
-					generate_method_declaration (m, header_declarations);
+					generate_method_declaration (m, header_file);
 				}
 				if (!m.is_private_symbol ()) {
-					generate_method_declaration (m, internal_header_declarations);
+					generate_method_declaration (m, internal_header_file);
 				}
 			}
 
@@ -471,7 +471,7 @@ public class Vala.GAsyncModule : GSignalModule {
 
 		cparam_map.set (get_param_pos (0.1), new CCodeFormalParameter ("_res_", "GAsyncResult*"));
 
-		generate_cparameters (m, source_declarations, cparam_map, finishfunc, null, null, null, 2);
+		generate_cparameters (m, cfile, cparam_map, finishfunc, null, null, null, 2);
 
 		if (m.is_private_symbol () || m.base_method != null || m.base_interface_method != null) {
 			finishfunc.modifiers |= CCodeModifiers.STATIC;
@@ -511,7 +511,7 @@ public class Vala.GAsyncModule : GSignalModule {
 		return readyfunc;
 	}
 
-	public override void generate_virtual_method_declaration (Method m, CCodeDeclarationSpace decl_space, CCodeStruct type_struct) {
+	public override void generate_virtual_method_declaration (Method m, CCodeFile decl_space, CCodeStruct type_struct) {
 		if (!m.coroutine) {
 			base.generate_virtual_method_declaration (m, decl_space, type_struct);
 			return;
@@ -652,7 +652,7 @@ public class Vala.GAsyncModule : GSignalModule {
 		cfrag.append (complete_async ());
 	}
 
-	public override void generate_cparameters (Method m, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
+	public override void generate_cparameters (Method m, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
 		if (m.coroutine) {
 			decl_space.add_include ("gio/gio.h");
 
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index e4f46ae..6a5e0ce 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -43,7 +43,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (method, source_declarations, cparam_map, func);
+		generate_cparameters (method, cfile, cparam_map, func);
 
 		var block = new CCodeBlock ();
 		if (dynamic_method.dynamic_type.data_type == dbus_proxy_type) {
@@ -53,10 +53,10 @@ public class Vala.GDBusClientModule : GDBusModule {
 		}
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 	}
 
 	void generate_dbus_method_wrapper (Method m, CCodeBlock block) {
@@ -140,9 +140,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 		}
 
 		proxy_iface_init.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (proxy_iface_init.copy ());
+		cfile.add_type_member_declaration (proxy_iface_init.copy ());
 		proxy_iface_init.block = iface_block;
-		source_type_member_definition.append (proxy_iface_init);
+		cfile.add_function (proxy_iface_init);
 	}
 
 	string implement_interface (CCodeFunctionCall define_type, Interface main_iface, Interface iface) {
@@ -162,7 +162,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 		return result;
 	}
 
-	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 		base.generate_interface_declaration (iface, decl_space);
 
 		string dbus_iface_name = get_dbus_name (iface);
@@ -198,8 +198,8 @@ public class Vala.GDBusClientModule : GDBusModule {
 		string cname = iface.get_cname () + "Proxy";
 		string lower_cname = iface.get_lower_case_cprefix () + "proxy";
 
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("GDBusProxy", new CCodeVariableDeclarator (cname)));
-		source_declarations.add_type_declaration (new CCodeTypeDefinition ("GDBusProxyClass", new CCodeVariableDeclarator (cname + "Class")));
+		cfile.add_type_declaration (new CCodeTypeDefinition ("GDBusProxy", new CCodeVariableDeclarator (cname)));
+		cfile.add_type_declaration (new CCodeTypeDefinition ("GDBusProxyClass", new CCodeVariableDeclarator (cname + "Class")));
 
 		var define_type = new CCodeFunctionCall (new CCodeIdentifier ("G_DEFINE_TYPE_EXTENDED"));
 		define_type.add_argument (new CCodeIdentifier (cname));
@@ -208,7 +208,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 		define_type.add_argument (new CCodeConstant ("0"));
 		define_type.add_argument (new CCodeIdentifier (implement_interface (define_type, iface, iface)));
 
-		source_type_member_definition.append (new CCodeExpressionStatement (define_type));
+		cfile.add_type_member_definition (new CCodeExpressionStatement (define_type));
 
 		var proxy_class_init = new CCodeFunction (lower_cname + "_class_init", "void");
 		proxy_class_init.add_parameter (new CCodeFormalParameter ("klass", cname + "Class*"));
@@ -217,7 +217,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 		var proxy_class = new CCodeFunctionCall (new CCodeIdentifier ("G_DBUS_PROXY_CLASS"));
 		proxy_class.add_argument (new CCodeIdentifier ("klass"));
 		proxy_class_init.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (proxy_class, "g_signal"), new CCodeIdentifier (lower_cname + "_g_signal"))));
-		source_type_member_definition.append (proxy_class_init);
+		cfile.add_function (proxy_class_init);
 
 		generate_signal_handler_function (iface);
 
@@ -225,7 +225,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 		proxy_instance_init.add_parameter (new CCodeFormalParameter ("self", cname + "*"));
 		proxy_instance_init.modifiers = CCodeModifiers.STATIC;
 		proxy_instance_init.block = new CCodeBlock ();
-		source_type_member_definition.append (proxy_instance_init);
+		cfile.add_function (proxy_instance_init);
 
 		generate_proxy_interface_init (iface, iface);
 	}
@@ -354,10 +354,10 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		block.add_statement (postfragment);
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -371,7 +371,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		cfunc.modifiers |= CCodeModifiers.STATIC;
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -405,7 +405,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 			clastif = cif;
 		}
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	void generate_marshalling (Method m, CCodeFragment prefragment, CCodeFragment postfragment) {
@@ -514,7 +514,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (m, source_declarations, cparam_map, function);
+		generate_cparameters (m, cfile, cparam_map, function);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -558,9 +558,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -580,7 +580,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 		cparam_map.set (get_param_pos (-1), new CCodeFormalParameter ("_callback_", "GAsyncReadyCallback"));
 		cparam_map.set (get_param_pos (-0.9), new CCodeFormalParameter ("_user_data_", "gpointer"));
 
-		generate_cparameters (m, source_declarations, cparam_map, function, null, null, null, 1);
+		generate_cparameters (m, cfile, cparam_map, function, null, null, null, 1);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -605,9 +605,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 		ccall.add_argument (new CCodeIdentifier ("_user_data_"));
 		block.add_statement (new CCodeExpressionStatement (ccall));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -624,7 +624,7 @@ public class Vala.GDBusClientModule : GDBusModule {
 
 		cparam_map.set (get_param_pos (0.1), new CCodeFormalParameter ("_res_", "GAsyncResult*"));
 
-		generate_cparameters (m, source_declarations, cparam_map, function, null, null, null, 2);
+		generate_cparameters (m, cfile, cparam_map, function, null, null, null, 2);
 
 		var block = new CCodeBlock ();
 		var prefragment = new CCodeFragment ();
@@ -661,9 +661,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -802,9 +802,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_result")));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
@@ -902,9 +902,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 		unref_reply.add_argument (new CCodeIdentifier ("_reply"));
 		block.add_statement (new CCodeExpressionStatement (unref_reply));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return proxy_name;
 	}
diff --git a/codegen/valagdbusmodule.vala b/codegen/valagdbusmodule.vala
index b5014e4..0fff2c1 100644
--- a/codegen/valagdbusmodule.vala
+++ b/codegen/valagdbusmodule.vala
@@ -46,13 +46,13 @@ public class Vala.GDBusModule : GVariantModule {
 			return;
 		}
 
-		generate_error_domain_declaration (edomain, source_declarations);
+		generate_error_domain_declaration (edomain, cfile);
 
 		if (!edomain.is_internal_symbol ()) {
-			generate_error_domain_declaration (edomain, header_declarations);
+			generate_error_domain_declaration (edomain, header_file);
 		}
 		if (!edomain.is_private_symbol ()) {
-			generate_error_domain_declaration (edomain, internal_header_declarations);
+			generate_error_domain_declaration (edomain, internal_header_file);
 		}
 
 		var error_entries = new CCodeInitializerList ();
@@ -71,7 +71,7 @@ public class Vala.GDBusModule : GVariantModule {
 		var cdecl = new CCodeDeclaration ("const GDBusErrorEntry");
 		cdecl.add_declarator (new CCodeVariableDeclarator (edomain.get_lower_case_cname () + "_entries[]", error_entries));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
 
@@ -97,7 +97,7 @@ public class Vala.GDBusModule : GVariantModule {
 		cquark_block.add_statement (new CCodeReturnStatement (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark")));
 
 		cquark_fun.block = cquark_block;
-		source_type_member_definition.append (cquark_fun);
+		cfile.add_function (cquark_fun);
 	}
 
 	public override CCodeFragment register_dbus_info (ObjectTypeSymbol sym) {
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index e067c70..6fc6683 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -63,7 +63,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		CCodeBlock ready_block = null;
 		if (m.coroutine) {
 			// GAsyncResult
-			source_declarations.add_include ("gio/gio.h");
+			cfile.add_include ("gio/gio.h");
 
 			ready_function = new CCodeFunction (wrapper_name + "_ready", "void");
 			ready_function.modifiers = CCodeModifiers.STATIC;
@@ -334,16 +334,16 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			ready_block.add_statement (new CCodeExpressionStatement (unref_call));
 		}
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		if (m.coroutine) {
-			source_declarations.add_type_member_declaration (ready_function.copy ());
+			cfile.add_type_member_declaration (ready_function.copy ());
 
 			ready_function.block = ready_block;
-			source_type_member_definition.append (ready_function);
+			cfile.add_function (ready_function);
 		}
 
 		return wrapper_name;
@@ -363,7 +363,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		foreach (var param in sig.get_parameters ()) {
 			// ensure ccodenode of parameter is set
-			generate_parameter (param, source_declarations, new HashMap<int,CCodeFormalParameter> (), null);
+			generate_parameter (param, cfile, new HashMap<int,CCodeFormalParameter> (), null);
 
 			function.add_parameter ((CCodeFormalParameter) get_ccodenode (param));
 			if (param.variable_type is ArrayType) {
@@ -424,9 +424,9 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		ccall.add_argument (new CCodeConstant ("NULL"));
 		block.add_statement (new CCodeExpressionStatement (ccall));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -502,10 +502,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_reply")));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -573,10 +573,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		block.add_statement (postfragment);
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 		function.block = block;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 
 		return wrapper_name;
 	}
@@ -617,7 +617,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		cfunc.modifiers |= CCodeModifiers.STATIC;
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -664,7 +664,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			clastif = cif;
 		}
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	void generate_interface_get_property_function (ObjectTypeSymbol sym) {
@@ -679,7 +679,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		cfunc.modifiers |= CCodeModifiers.STATIC;
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -729,7 +729,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		block.add_statement (new CCodeReturnStatement (new CCodeConstant ("NULL")));
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	void generate_interface_set_property_function (ObjectTypeSymbol sym) {
@@ -745,7 +745,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		cfunc.modifiers |= CCodeModifiers.STATIC;
 
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		var block = new CCodeBlock ();
 		cfunc.block = block;
@@ -797,7 +797,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 
 	CCodeExpression get_method_info (ObjectTypeSymbol sym) {
@@ -824,7 +824,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 				var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
 				cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + m.name + "_" + param.name, info));
 				cdecl.modifiers = CCodeModifiers.STATIC;
-				source_declarations.add_constant_declaration (cdecl);
+				cfile.add_constant_declaration (cdecl);
 
 				if (param.direction == ParameterDirection.IN) {
 					in_args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + m.name + "_" + param.name)));
@@ -842,7 +842,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 				var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
 				cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + m.name + "_result", info));
 				cdecl.modifiers = CCodeModifiers.STATIC;
-				source_declarations.add_constant_declaration (cdecl);
+				cfile.add_constant_declaration (cdecl);
 
 				out_args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + m.name + "_result")));
 			}
@@ -853,12 +853,12 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			var cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + m.name + "_in[]", in_args_info));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_constant_declaration (cdecl);
+			cfile.add_constant_declaration (cdecl);
 
 			cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + m.name + "_out[]", out_args_info));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_constant_declaration (cdecl);
+			cfile.add_constant_declaration (cdecl);
 
 			var info = new CCodeInitializerList ();
 			info.append (new CCodeConstant ("-1"));
@@ -869,7 +869,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			cdecl = new CCodeDeclaration ("const GDBusMethodInfo");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_method_info_" + m.name, info));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_constant_declaration (cdecl);
+			cfile.add_constant_declaration (cdecl);
 
 			infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_method_info_" + m.name)));
 		}
@@ -879,7 +879,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		var cdecl = new CCodeDeclaration ("const GDBusMethodInfo * const");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_method_info[]", infos));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_method_info");
 	}
@@ -906,7 +906,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 				var cdecl = new CCodeDeclaration ("const GDBusArgInfo");
 				cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + sig.get_cname () + "_" + param.name, info));
 				cdecl.modifiers = CCodeModifiers.STATIC;
-				source_declarations.add_constant_declaration (cdecl);
+				cfile.add_constant_declaration (cdecl);
 
 				args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + sig.get_cname () + "_" + param.name)));
 			}
@@ -916,7 +916,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			var cdecl = new CCodeDeclaration ("const GDBusArgInfo * const");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_arg_info_" + sig.get_cname () + "[]", args_info));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_constant_declaration (cdecl);
+			cfile.add_constant_declaration (cdecl);
 
 			var info = new CCodeInitializerList ();
 			info.append (new CCodeConstant ("-1"));
@@ -926,7 +926,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			cdecl = new CCodeDeclaration ("const GDBusSignalInfo");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_signal_info_" + sig.get_cname (), info));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_constant_declaration (cdecl);
+			cfile.add_constant_declaration (cdecl);
 
 			infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_signal_info_" + sig.get_cname ())));
 		}
@@ -936,7 +936,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		var cdecl = new CCodeDeclaration ("const GDBusSignalInfo * const");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_signal_info[]", infos));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_signal_info");
 	}
@@ -970,7 +970,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			var cdecl = new CCodeDeclaration ("const GDBusPropertyInfo");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_property_info_" + prop.name, info));
 			cdecl.modifiers = CCodeModifiers.STATIC;
-			source_declarations.add_constant_declaration (cdecl);
+			cfile.add_constant_declaration (cdecl);
 
 			infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_property_info_" + prop.name)));
 		}
@@ -980,7 +980,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		var cdecl = new CCodeDeclaration ("const GDBusPropertyInfo * const");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_property_info[]", infos));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_property_info");
 	}
@@ -996,7 +996,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		var cdecl = new CCodeDeclaration ("const GDBusInterfaceInfo");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_interface_info", info));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_interface_info");
 	}
@@ -1014,7 +1014,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		var cdecl = new CCodeDeclaration ("const GDBusInterfaceVTable");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("_" + sym.get_lower_case_cprefix () + "dbus_interface_vtable", vtable));
 		cdecl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_constant_declaration (cdecl);
+		cfile.add_constant_declaration (cdecl);
 
 		return new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "dbus_interface_vtable");
 	}
@@ -1044,13 +1044,13 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		expr.ccodenode = cregister;
 	}
 
-	public override void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public override void generate_class_declaration (Class cl, CCodeFile decl_space) {
 		base.generate_class_declaration (cl, decl_space);
 
 		generate_object_type_symbol_declaration (cl, decl_space);
 	}
 
-	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 		base.generate_interface_declaration (iface, decl_space);
 
 		generate_object_type_symbol_declaration (iface, decl_space);
@@ -1068,7 +1068,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		visit_object_type_symbol (iface);
 	}
 
-	void generate_object_type_symbol_declaration (ObjectTypeSymbol sym, CCodeDeclarationSpace decl_space) {
+	void generate_object_type_symbol_declaration (ObjectTypeSymbol sym, CCodeFile decl_space) {
 		string dbus_iface_name = get_dbus_name (sym);
 		if (dbus_iface_name == null) {
 			return;
@@ -1161,13 +1161,13 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 
 
 		cfunc = new CCodeFunction ("_" + sym.get_lower_case_cprefix () + "unregister_object");
 		cfunc.add_parameter (new CCodeFormalParameter ("user_data", "gpointer"));
 		cfunc.modifiers |= CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (cfunc.copy ());
+		cfile.add_type_member_declaration (cfunc.copy ());
 
 		block = new CCodeBlock ();
 		cfunc.block = block;
@@ -1192,6 +1192,6 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 		free_data.add_argument (new CCodeIdentifier ("data"));
 		block.add_statement (new CCodeExpressionStatement (free_data));
 
-		source_type_member_definition.append (cfunc);
+		cfile.add_function (cfunc);
 	}
 }
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 90e99b1..7512247 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -28,7 +28,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 	private int next_try_id = 0;
 	private bool is_in_catch = false;
 
-	public override void generate_error_domain_declaration (ErrorDomain edomain, CCodeDeclarationSpace decl_space) {
+	public override void generate_error_domain_declaration (ErrorDomain edomain, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, edomain, edomain.get_cname ())) {
 			return;
 		}
@@ -57,13 +57,13 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 	}
 
 	public override void visit_error_domain (ErrorDomain edomain) {
-		generate_error_domain_declaration (edomain, source_declarations);
+		generate_error_domain_declaration (edomain, cfile);
 
 		if (!edomain.is_internal_symbol ()) {
-			generate_error_domain_declaration (edomain, header_declarations);
+			generate_error_domain_declaration (edomain, header_file);
 		}
 		if (!edomain.is_private_symbol ()) {
-			generate_error_domain_declaration (edomain, internal_header_declarations);
+			generate_error_domain_declaration (edomain, internal_header_file);
 		}
 
 		string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
@@ -77,7 +77,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 		cquark_block.add_statement (new CCodeReturnStatement (cquark_call));
 
 		cquark_fun.block = cquark_block;
-		source_type_member_definition.append (cquark_fun);
+		cfile.add_function (cquark_fun);
 	}
 
 	public override void visit_throw_statement (ThrowStatement stmt) {
@@ -367,7 +367,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 
 		var error_type = (ErrorType) clause.error_type;
 		if (error_type.error_domain != null) {
-			generate_error_domain_declaration (error_type.error_domain, source_declarations);
+			generate_error_domain_declaration (error_type.error_domain, cfile);
 		}
 
 		clause.body.emit (this);
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 59ef5ee..73fba74 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -209,13 +209,13 @@ public class Vala.GObjectModule : GTypeModule {
 				prefix = base_type.get_lower_case_cname (null);
 				cself = transform_expression (cself, new ObjectType (cl), new ObjectType (base_type));
 
-				generate_property_accessor_declaration (prop.base_property.get_accessor, source_declarations);
+				generate_property_accessor_declaration (prop.base_property.get_accessor, cfile);
 			} else if (prop.base_interface_property != null) {
 				var base_type = (Interface) prop.base_interface_property.parent_symbol;
 				prefix = base_type.get_lower_case_cname (null);
 				cself = transform_expression (cself, new ObjectType (cl), new ObjectType (base_type));
 
-				generate_property_accessor_declaration (prop.base_interface_property.get_accessor, source_declarations);
+				generate_property_accessor_declaration (prop.base_interface_property.get_accessor, cfile);
 			}
 
 			cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
@@ -274,11 +274,11 @@ public class Vala.GObjectModule : GTypeModule {
 
 		block.add_statement (cswitch);
 
-		source_declarations.add_type_member_declaration (get_prop.copy ());
+		cfile.add_type_member_declaration (get_prop.copy ());
 
 		get_prop.block = block;
 		
-		source_type_member_definition.append (get_prop);
+		cfile.add_function (get_prop);
 	}
 	
 	private void add_set_property_function (Class cl) {
@@ -315,13 +315,13 @@ public class Vala.GObjectModule : GTypeModule {
 				prefix = base_type.get_lower_case_cname (null);
 				cself = transform_expression (cself, new ObjectType (cl), new ObjectType (base_type));
 
-				generate_property_accessor_declaration (prop.base_property.set_accessor, source_declarations);
+				generate_property_accessor_declaration (prop.base_property.set_accessor, cfile);
 			} else if (prop.base_interface_property != null) {
 				var base_type = (Interface) prop.base_interface_property.parent_symbol;
 				prefix = base_type.get_lower_case_cname (null);
 				cself = transform_expression (cself, new ObjectType (cl), new ObjectType (base_type));
 
-				generate_property_accessor_declaration (prop.base_interface_property.set_accessor, source_declarations);
+				generate_property_accessor_declaration (prop.base_interface_property.set_accessor, cfile);
 			}
 
 			cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
@@ -395,11 +395,11 @@ public class Vala.GObjectModule : GTypeModule {
 			cswitch.add_statement (new CCodeBreakStatement ());
 		}
 
-		source_declarations.add_type_member_declaration (set_prop.copy ());
+		cfile.add_type_member_declaration (set_prop.copy ());
 
 		set_prop.block = block;
 		
-		source_type_member_definition.append (set_prop);
+		cfile.add_function (set_prop);
 	}
 
 	private CCodeStatement get_invalid_property_id_warn_statement () {
@@ -475,7 +475,7 @@ public class Vala.GObjectModule : GTypeModule {
 			function.add_parameter (new CCodeFormalParameter ("n_construct_properties", "guint"));
 			function.add_parameter (new CCodeFormalParameter ("construct_properties", "GObjectConstructParam *"));
 		
-			source_declarations.add_type_member_declaration (function.copy ());
+			cfile.add_type_member_declaration (function.copy ());
 
 
 			var cblock = new CCodeBlock ();
@@ -522,7 +522,7 @@ public class Vala.GObjectModule : GTypeModule {
 		
 			function.block = cblock;
 
-			source_type_member_definition.append (function);
+			cfile.add_function (function);
 		} else if (c.binding == MemberBinding.CLASS) {
 			// class constructor
 
@@ -586,10 +586,10 @@ public class Vala.GObjectModule : GTypeModule {
 		generate_gobject_property_getter_wrapper (prop, block);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return getter_cname;
 	}
@@ -612,10 +612,10 @@ public class Vala.GObjectModule : GTypeModule {
 		generate_gobject_property_setter_wrapper (prop, block);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return setter_cname;
 	}
@@ -666,10 +666,10 @@ public class Vala.GObjectModule : GTypeModule {
 		generate_gobject_connect_wrapper (sig, block, false);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return connect_wrapper_name;
 	}
@@ -690,10 +690,10 @@ public class Vala.GObjectModule : GTypeModule {
 		generate_gobject_connect_wrapper (sig, block, true);
 
 		// append to C source file
-		source_declarations.add_type_member_declaration (func.copy ());
+		cfile.add_type_member_declaration (func.copy ());
 
 		func.block = block;
-		source_type_member_definition.append (func);
+		cfile.add_function (func);
 
 		return connect_wrapper_name;
 	}
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index e36f5f2..0e0b94d 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -172,7 +172,7 @@ public class Vala.GSignalModule : GObjectModule {
 
 		// declare parameter type
 		foreach (FormalParameter p in sig.get_parameters ()) {
-			generate_parameter (p, source_declarations, new HashMap<int,CCodeFormalParameter> (), null);
+			generate_parameter (p, cfile, new HashMap<int,CCodeFormalParameter> (), null);
 		}
 
 		generate_marshaller (sig.get_parameters (), sig.return_type);
@@ -198,7 +198,7 @@ public class Vala.GSignalModule : GObjectModule {
 		signal_marshaller.add_parameter (new CCodeFormalParameter ("invocation_hint", "gpointer"));
 		signal_marshaller.add_parameter (new CCodeFormalParameter ("marshal_data", "gpointer"));
 		
-		source_signal_marshaller_declaration.append (signal_marshaller.copy ());
+		cfile.add_type_member_declaration (signal_marshaller.copy ());
 		
 		var marshaller_body = new CCodeBlock ();
 		
@@ -354,7 +354,7 @@ public class Vala.GSignalModule : GObjectModule {
 		
 		signal_marshaller.block = marshaller_body;
 		
-		source_signal_marshaller_definition.append (signal_marshaller);
+		cfile.add_function (signal_marshaller);
 		user_marshal_set.add (signature);
 	}
 
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 9c66056..07c02bb 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -24,7 +24,7 @@
 
 
 public class Vala.GTypeModule : GErrorModule {
-	public override void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
+	public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
 		if (!(param.variable_type is ObjectType)) {
 			base.generate_parameter (param, decl_space, cparam_map, carg_map);
 			return;
@@ -46,7 +46,7 @@ public class Vala.GTypeModule : GErrorModule {
 		}
 	}
 
-	public override void generate_class_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public override void generate_class_declaration (Class cl, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, cl, cl.get_cname ())) {
 			return;
 		}
@@ -176,7 +176,7 @@ public class Vala.GTypeModule : GErrorModule {
 		}
 	}
 
-	public override void generate_class_struct_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	public override void generate_class_struct_declaration (Class cl, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, cl, "struct _" + cl.get_cname ())) {
 			return;
 		}
@@ -349,7 +349,7 @@ public class Vala.GTypeModule : GErrorModule {
 		}
 	}
 
-	public virtual void generate_virtual_method_declaration (Method m, CCodeDeclarationSpace decl_space, CCodeStruct type_struct) {
+	public virtual void generate_virtual_method_declaration (Method m, CCodeFile decl_space, CCodeStruct type_struct) {
 		if (!m.is_abstract && !m.is_virtual) {
 			return;
 		}
@@ -371,7 +371,7 @@ public class Vala.GTypeModule : GErrorModule {
 		type_struct.add_declaration (vdecl);
 	}
 
-	void generate_class_private_declaration (Class cl, CCodeDeclarationSpace decl_space) {
+	void generate_class_private_declaration (Class cl, CCodeFile decl_space) {
 		if (decl_space.add_declaration (cl.get_cname () + "Private")) {
 			return;
 		}
@@ -522,14 +522,14 @@ public class Vala.GTypeModule : GErrorModule {
 		instance_finalize_fragment = new CCodeFragment ();
 
 
-		generate_class_struct_declaration (cl, source_declarations);
-		generate_class_private_declaration (cl, source_declarations);
+		generate_class_struct_declaration (cl, cfile);
+		generate_class_private_declaration (cl, cfile);
 
 		if (!cl.is_internal_symbol ()) {
-			generate_class_struct_declaration (cl, header_declarations);
+			generate_class_struct_declaration (cl, header_file);
 		}
 		if (!cl.is_private_symbol ()) {
-			generate_class_struct_declaration (cl, internal_header_declarations);
+			generate_class_struct_declaration (cl, internal_header_file);
 		}
 
 		cl.accept_children (this);
@@ -538,9 +538,9 @@ public class Vala.GTypeModule : GErrorModule {
 			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");
-				source_declarations.add_type_definition (param_spec_struct);
+				cfile.add_type_definition (param_spec_struct);
 
-				source_declarations.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (param_spec_struct.name), new CCodeVariableDeclarator ( "%sParamSpec%s".printf(cl.parent_symbol.get_cprefix (), cl.name))));
+				cfile.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;
@@ -587,13 +587,13 @@ public class Vala.GTypeModule : GErrorModule {
 			}
 
 			if (cl.comment != null) {
-				source_type_member_definition.append (new CCodeComment (cl.comment.content));
+				cfile.add_type_member_definition (new CCodeComment (cl.comment.content));
 			}
 
 			var type_fun = new ClassRegisterFunction (cl, context);
 			type_fun.init_from_type (in_plugin);
-			source_declarations.add_type_member_declaration (type_fun.get_source_declaration ());
-			source_type_member_definition.append (type_fun.get_definition ());
+			cfile.add_type_member_declaration (type_fun.get_source_declaration ());
+			cfile.add_type_member_definition (type_fun.get_definition ());
 
 			if (is_fundamental) {
 				var ref_fun = new CCodeFunction (cl.get_lower_case_cprefix () + "ref", "gpointer");
@@ -645,8 +645,8 @@ public class Vala.GTypeModule : GErrorModule {
 				ref_fun.block = ref_block;
 				unref_fun.block = unref_block;
 
-				source_type_member_definition.append (ref_fun);
-				source_type_member_definition.append (unref_fun);
+				cfile.add_function (ref_fun);
+				cfile.add_function (unref_fun);
 			}
 		} else {
 			if (cl.base_class == null) {
@@ -675,7 +675,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 				function.block = cblock;
 
-				source_type_member_definition.append (function);
+				cfile.add_function (function);
 			}
 		}
 
@@ -700,7 +700,7 @@ public class Vala.GTypeModule : GErrorModule {
 		function.block = init_block;
 
 		init_block.add_statement(new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess(new CCodeMemberAccess.pointer (new CCodeIdentifier ("value"), "data[0]"),"v_pointer"),new CCodeConstant ("NULL"), CCodeAssignmentOperator.SIMPLE)));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_type_value_table_free_function (Class cl) {
@@ -719,7 +719,7 @@ public class Vala.GTypeModule : GErrorModule {
 		ifbody.add_statement ( new CCodeExpressionStatement(ccall) );
 
 		init_block.add_statement(new CCodeIfStatement (vpointer, ifbody));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_type_value_table_copy_function (Class cl) {
@@ -746,7 +746,7 @@ public class Vala.GTypeModule : GErrorModule {
 		var if_statement = new CCodeIfStatement (src_vpointer, true_stmt, false_stmt);
 		init_block.add_statement (if_statement);
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_type_value_table_peek_pointer_function (Class cl) {
@@ -761,7 +761,7 @@ public class Vala.GTypeModule : GErrorModule {
 		var ret = new CCodeReturnStatement ( vpointer );
 		init_block.add_statement (ret);
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_type_value_table_lcopy_value_function ( Class cl ) {
@@ -813,7 +813,7 @@ public class Vala.GTypeModule : GErrorModule {
 		main_else_true.add_statement (new CCodeExpressionStatement (new CCodeAssignment (object_p_ptr, ref_fct, CCodeAssignmentOperator.SIMPLE)));
 
 		init_block.add_statement (new CCodeReturnStatement (null_));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_type_value_table_collect_value_function (Class cl) {
@@ -893,7 +893,7 @@ public class Vala.GTypeModule : GErrorModule {
 		false_stmt.add_statement (else_assigment);
 
 		init_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("NULL")));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_g_param_spec_type_function (Class cl) {
@@ -940,7 +940,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 		init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ccall, "value_type"), new CCodeIdentifier ("object_type"), CCodeAssignmentOperator.SIMPLE )));
 		init_block.add_statement (new CCodeReturnStatement (ccall));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_g_value_set_function (Class cl) {
@@ -1014,7 +1014,7 @@ public class Vala.GTypeModule : GErrorModule {
 		ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_unref_function ()));
 		ccall.add_argument (new CCodeIdentifier ("old"));
 		true_stmt.add_statement (new CCodeExpressionStatement (ccall));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_g_value_take_function (Class cl) {
@@ -1084,7 +1084,7 @@ public class Vala.GTypeModule : GErrorModule {
 		ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_unref_function ()));
 		ccall.add_argument (new CCodeIdentifier ("old"));
 		true_stmt.add_statement (new CCodeExpressionStatement (ccall));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_g_value_get_function (Class cl) {
@@ -1110,7 +1110,7 @@ public class Vala.GTypeModule : GErrorModule {
 		init_block.add_statement (new CCodeExpressionStatement (ccall));
 
 		init_block.add_statement (new CCodeReturnStatement ( vpointer ));
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_base_init_function (Class cl) {
@@ -1152,7 +1152,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 			block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("priv"), ccall)));
 
-			source_declarations.add_include ("string.h");
+			cfile.add_include ("string.h");
 
 			iftrue = new CCodeBlock ();
 			ccall = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
@@ -1191,7 +1191,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 		init_block.add_statement (base_init_fragment);
 
-		source_type_member_definition.append (base_init);
+		cfile.add_function (base_init);
 	}
 
 	public virtual void generate_class_init (Class cl, CCodeBlock init_block) {
@@ -1213,7 +1213,7 @@ public class Vala.GTypeModule : GErrorModule {
 		parent_var_decl.initializer = new CCodeConstant ("NULL");
 		parent_decl.add_declarator (parent_var_decl);
 		parent_decl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (parent_decl);
+		cfile.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);
@@ -1306,7 +1306,7 @@ public class Vala.GTypeModule : GErrorModule {
 		init_block.add_statement (register_dbus_info (cl));
 		init_block.add_statement (class_init_fragment);
 
-		source_type_member_definition.append (class_init);
+		cfile.add_function (class_init);
 	}
 	
 	private void add_interface_init_function (Class cl, Interface iface) {
@@ -1326,7 +1326,7 @@ public class Vala.GTypeModule : GErrorModule {
 		parent_var_decl.initializer = new CCodeConstant ("NULL");
 		parent_decl.add_declarator (parent_var_decl);
 		parent_decl.modifiers = CCodeModifiers.STATIC;
-		source_declarations.add_type_member_declaration (parent_decl);
+		cfile.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);
@@ -1381,7 +1381,7 @@ public class Vala.GTypeModule : GErrorModule {
 						base_method = cl_method.base_interface_method;
 					}
 
-					generate_method_declaration (base_method, source_declarations);
+					generate_method_declaration (base_method, cfile);
 
 					CCodeExpression cfunc = new CCodeIdentifier (base_method.get_cname ());
 					cfunc = cast_method_pointer (base_method, cfunc, iface);
@@ -1453,7 +1453,7 @@ public class Vala.GTypeModule : GErrorModule {
 				var ciface = new CCodeIdentifier ("iface");
 
 				if (base_property.get_accessor != null) {
-					generate_property_accessor_declaration (base_property.get_accessor, source_declarations);
+					generate_property_accessor_declaration (base_property.get_accessor, cfile);
 
 					string cname = base_property.get_accessor.get_cname ();
 					CCodeExpression cfunc = new CCodeIdentifier (cname);
@@ -1461,7 +1461,7 @@ public class Vala.GTypeModule : GErrorModule {
 					init_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (ciface, "get_%s".printf (prop.name)), cfunc)));
 				}
 				if (base_property.set_accessor != null) {
-					generate_property_accessor_declaration (base_property.set_accessor, source_declarations);
+					generate_property_accessor_declaration (base_property.set_accessor, cfile);
 
 					string cname = base_property.set_accessor.get_cname ();
 					CCodeExpression cfunc = new CCodeIdentifier (cname);
@@ -1471,7 +1471,7 @@ public class Vala.GTypeModule : GErrorModule {
 			}
 		}
 
-		source_type_member_definition.append (iface_init);
+		cfile.add_function (iface_init);
 	}
 
 	CCodeExpression cast_property_accessor_pointer (PropertyAccessor acc, CCodeExpression cfunc, ObjectTypeSymbol base_type) {
@@ -1496,7 +1496,7 @@ public class Vala.GTypeModule : GErrorModule {
 		var vdeclarator = new CCodeFunctionDeclarator (m.vfunc_name);
 		var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
 
-		generate_cparameters (m, source_declarations, cparam_map, new CCodeFunction ("fake"), vdeclarator);
+		generate_cparameters (m, cfile, cparam_map, new CCodeFunction ("fake"), vdeclarator);
 
 		// append C arguments in the right order
 		int last_pos = -1;
@@ -1528,7 +1528,7 @@ public class Vala.GTypeModule : GErrorModule {
 		if (cl.is_compact) {
 			// Add declaration, since the instance_init function is explicitly called
 			// by the creation methods
-			source_declarations.add_type_member_declaration (instance_init.copy ());
+			cfile.add_type_member_declaration (instance_init.copy ());
 		}
 
 		var init_block = new CCodeBlock ();
@@ -1542,7 +1542,7 @@ public class Vala.GTypeModule : GErrorModule {
 		
 		init_block.add_statement (instance_init_fragment);
 
-		source_type_member_definition.append (instance_init);
+		cfile.add_function (instance_init);
 	}
 
 	private void add_class_finalize_function (Class cl) {
@@ -1550,7 +1550,7 @@ public class Vala.GTypeModule : GErrorModule {
 		function.modifiers = CCodeModifiers.STATIC;
 
 		function.add_parameter (new CCodeFormalParameter ("klass", cl.get_cname () + "Class *"));
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		
 		var cblock = new CCodeBlock ();
 
@@ -1561,7 +1561,7 @@ public class Vala.GTypeModule : GErrorModule {
 		cblock.add_statement (class_finalize_fragment);
 
 		function.block = cblock;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_base_finalize_function (Class cl) {
@@ -1569,7 +1569,7 @@ public class Vala.GTypeModule : GErrorModule {
 		function.modifiers = CCodeModifiers.STATIC;
 
 		function.add_parameter (new CCodeFormalParameter ("klass", cl.get_cname () + "Class *"));
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 		
 		var cblock = new CCodeBlock ();
 
@@ -1580,7 +1580,7 @@ public class Vala.GTypeModule : GErrorModule {
 		cblock.add_statement (base_finalize_fragment);
 
 		function.block = cblock;
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	private void add_finalize_function (Class cl) {
@@ -1594,7 +1594,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 		function.add_parameter (new CCodeFormalParameter ("obj", fundamental_class.get_cname () + "*"));
 
-		source_declarations.add_type_member_declaration (function.copy ());
+		cfile.add_type_member_declaration (function.copy ());
 
 
 		var cblock = new CCodeBlock ();
@@ -1624,7 +1624,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 		function.block = cblock;
 
-		source_type_member_definition.append (function);
+		cfile.add_function (function);
 	}
 
 	public override CCodeFunctionCall get_param_spec (Property prop) {
@@ -1807,7 +1807,7 @@ public class Vala.GTypeModule : GErrorModule {
 		return cspec;
 	}
 
-	public override void generate_interface_declaration (Interface iface, CCodeDeclarationSpace decl_space) {
+	public override void generate_interface_declaration (Interface iface, CCodeFile decl_space) {
 		if (add_symbol_declaration (decl_space, iface, iface.get_cname ())) {
 			return;
 		}
@@ -1923,12 +1923,12 @@ public class Vala.GTypeModule : GErrorModule {
 			return;
 		}
 
-		generate_interface_declaration (iface, source_declarations);
+		generate_interface_declaration (iface, cfile);
 		if (!iface.is_internal_symbol ()) {
-			generate_interface_declaration (iface, header_declarations);
+			generate_interface_declaration (iface, header_file);
 		}
 		if (!iface.is_private_symbol ()) {
-			generate_interface_declaration (iface, internal_header_declarations);
+			generate_interface_declaration (iface, internal_header_file);
 		}
 
 		iface.accept_children (this);
@@ -1936,13 +1936,13 @@ public class Vala.GTypeModule : GErrorModule {
 		add_interface_base_init_function (iface);
 
 		if (iface.comment != null) {
-			source_type_member_definition.append (new CCodeComment (iface.comment.content));
+			cfile.add_type_member_definition (new CCodeComment (iface.comment.content));
 		}
 
 		var type_fun = create_interface_register_function (iface);
 		type_fun.init_from_type (in_plugin);
-		source_declarations.add_type_member_declaration (type_fun.get_source_declaration ());
-		source_type_member_definition.append (type_fun.get_definition ());
+		cfile.add_type_member_declaration (type_fun.get_source_declaration ());
+		cfile.add_type_member_definition (type_fun.get_definition ());
 
 		pop_context ();
 	}
@@ -2009,7 +2009,7 @@ public class Vala.GTypeModule : GErrorModule {
 
 		init_block.add_statement (register_dbus_info (iface));
 
-		source_type_member_definition.append (base_init);
+		cfile.add_function (base_init);
 	}
 
 	public override void visit_struct (Struct st) {
@@ -2018,7 +2018,7 @@ public class Vala.GTypeModule : GErrorModule {
 		if (st.has_type_id) {
 			var type_fun = new StructRegisterFunction (st, context);
 			type_fun.init_from_type (false);
-			source_type_member_definition.append (type_fun.get_definition ());
+			cfile.add_type_member_definition (type_fun.get_definition ());
 		}
 	}
 
@@ -2028,7 +2028,7 @@ public class Vala.GTypeModule : GErrorModule {
 		if (en.has_type_id) {
 			var type_fun = new EnumRegisterFunction (en, context);
 			type_fun.init_from_type (false);
-			source_type_member_definition.append (type_fun.get_definition ());
+			cfile.add_type_member_definition (type_fun.get_definition ());
 		}
 	}
 
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index f7ae8c1..8ca54ab 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -155,14 +155,14 @@ public class Vala.GVariantModule : GAsyncModule {
 
 		if (is_string_marshalled_enum (en)) {
 			// strcmp
-			source_declarations.add_include ("string.h");
+			cfile.add_include ("string.h");
 
-			source_type_member_definition.append (generate_enum_from_string_function (en));
-			source_type_member_definition.append (generate_enum_to_string_function (en));
+			cfile.add_function (generate_enum_from_string_function (en));
+			cfile.add_function (generate_enum_to_string_function (en));
 		}
 	}
 
-	public override bool generate_enum_declaration (Enum en, CCodeDeclarationSpace decl_space) {
+	public override bool generate_enum_declaration (Enum en, CCodeFile decl_space) {
 		if (base.generate_enum_declaration (en, decl_space)) {
 			if (is_string_marshalled_enum (en)) {
 				decl_space.add_type_member_declaration (generate_enum_from_string_function_declaration (en));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]