/* valaccodefile.c generated by valac, the Vala compiler
 * generated from valaccodefile.vala, do not modify */

/* valaccodefile.vala
 *
 * Copyright (C) 2009-2011  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>
 */

#include <glib.h>
#include <glib-object.h>
#include "valaccode.h"
#include <valagee.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>

#define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
#define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _vala_ccode_writer_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_writer_unref (var), NULL)))
typedef struct _ValaParamSpecCCodeFile ValaParamSpecCCodeFile;

struct _ValaCCodeFilePrivate {
	gboolean _is_header;
	ValaSet* declarations;
	ValaSet* includes;
	ValaCCodeFragment* comments;
	ValaCCodeFragment* include_directives;
	ValaCCodeFragment* type_declaration;
	ValaCCodeFragment* type_definition;
	ValaCCodeFragment* type_member_declaration;
	ValaCCodeFragment* constant_declaration;
	ValaCCodeFragment* type_member_definition;
};

struct _ValaParamSpecCCodeFile {
	GParamSpec parent_instance;
};


static gpointer vala_ccode_file_parent_class = NULL;

#define VALA_CCODE_FILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_CCODE_FILE, ValaCCodeFilePrivate))
static void vala_ccode_file_get_symbols_from_fragment (ValaCCodeFile* self, ValaList* symbols, ValaCCodeFragment* fragment);
static gchar* vala_ccode_file_get_define_for_filename (const gchar* filename);
static void vala_ccode_file_finalize (ValaCCodeFile * obj);


gboolean vala_ccode_file_add_declaration (ValaCCodeFile* self, const gchar* name) {
	gboolean result = FALSE;
	ValaSet* _tmp0_;
	const gchar* _tmp1_;
	gboolean _tmp2_;
	ValaSet* _tmp3_;
	const gchar* _tmp4_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = self->priv->declarations;
	_tmp1_ = name;
	_tmp2_ = vala_collection_contains ((ValaCollection*) _tmp0_, _tmp1_);
	if (_tmp2_) {
		result = TRUE;
		return result;
	}
	_tmp3_ = self->priv->declarations;
	_tmp4_ = name;
	vala_collection_add ((ValaCollection*) _tmp3_, _tmp4_);
	result = FALSE;
	return result;
}


void vala_ccode_file_add_comment (ValaCCodeFile* self, ValaCCodeComment* comment) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeComment* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (comment != NULL);
	_tmp0_ = self->priv->comments;
	_tmp1_ = comment;
	vala_ccode_fragment_append (_tmp0_, (ValaCCodeNode*) _tmp1_);
}


void vala_ccode_file_add_include (ValaCCodeFile* self, const gchar* filename, gboolean local) {
	ValaSet* _tmp0_;
	const gchar* _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (filename != NULL);
	_tmp0_ = self->priv->includes;
	_tmp1_ = filename;
	_tmp2_ = vala_collection_contains ((ValaCollection*) _tmp0_, _tmp1_);
	if (!_tmp2_) {
		ValaCCodeFragment* _tmp3_;
		const gchar* _tmp4_;
		gboolean _tmp5_;
		ValaCCodeIncludeDirective* _tmp6_;
		ValaCCodeIncludeDirective* _tmp7_;
		ValaSet* _tmp8_;
		const gchar* _tmp9_;
		_tmp3_ = self->priv->include_directives;
		_tmp4_ = filename;
		_tmp5_ = local;
		_tmp6_ = vala_ccode_include_directive_new (_tmp4_, _tmp5_);
		_tmp7_ = _tmp6_;
		vala_ccode_fragment_append (_tmp3_, (ValaCCodeNode*) _tmp7_);
		_vala_ccode_node_unref0 (_tmp7_);
		_tmp8_ = self->priv->includes;
		_tmp9_ = filename;
		vala_collection_add ((ValaCollection*) _tmp8_, _tmp9_);
	}
}


void vala_ccode_file_add_type_declaration (ValaCCodeFile* self, ValaCCodeNode* node) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = self->priv->type_declaration;
	_tmp1_ = node;
	vala_ccode_fragment_append (_tmp0_, _tmp1_);
}


void vala_ccode_file_add_type_definition (ValaCCodeFile* self, ValaCCodeNode* node) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = self->priv->type_definition;
	_tmp1_ = node;
	vala_ccode_fragment_append (_tmp0_, _tmp1_);
}


void vala_ccode_file_add_type_member_declaration (ValaCCodeFile* self, ValaCCodeNode* node) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = self->priv->type_member_declaration;
	_tmp1_ = node;
	vala_ccode_fragment_append (_tmp0_, _tmp1_);
}


void vala_ccode_file_add_constant_declaration (ValaCCodeFile* self, ValaCCodeNode* node) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = self->priv->constant_declaration;
	_tmp1_ = node;
	vala_ccode_fragment_append (_tmp0_, _tmp1_);
}


void vala_ccode_file_add_type_member_definition (ValaCCodeFile* self, ValaCCodeNode* node) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (node != NULL);
	_tmp0_ = self->priv->type_member_definition;
	_tmp1_ = node;
	vala_ccode_fragment_append (_tmp0_, _tmp1_);
}


void vala_ccode_file_add_function_declaration (ValaCCodeFile* self, ValaCCodeFunction* func) {
	ValaCCodeFunction* decl = NULL;
	ValaCCodeFunction* _tmp0_;
	ValaCCodeFunction* _tmp1_;
	ValaCCodeFragment* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (func != NULL);
	_tmp0_ = func;
	_tmp1_ = vala_ccode_function_copy (_tmp0_);
	decl = _tmp1_;
	vala_ccode_function_set_is_declaration (decl, TRUE);
	_tmp2_ = self->priv->type_member_declaration;
	vala_ccode_fragment_append (_tmp2_, (ValaCCodeNode*) decl);
	_vala_ccode_node_unref0 (decl);
}


void vala_ccode_file_add_function (ValaCCodeFile* self, ValaCCodeFunction* func) {
	ValaCCodeFragment* _tmp0_;
	ValaCCodeFunction* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (func != NULL);
	_tmp0_ = self->priv->type_member_definition;
	_tmp1_ = func;
	vala_ccode_fragment_append (_tmp0_, (ValaCCodeNode*) _tmp1_);
}


ValaList* vala_ccode_file_get_symbols (ValaCCodeFile* self) {
	ValaList* result = NULL;
	ValaArrayList* symbols = NULL;
	GEqualFunc _tmp0_;
	ValaArrayList* _tmp1_;
	ValaCCodeFragment* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_direct_equal;
	_tmp1_ = vala_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp0_);
	symbols = _tmp1_;
	_tmp2_ = self->priv->type_member_declaration;
	vala_ccode_file_get_symbols_from_fragment (self, (ValaList*) symbols, _tmp2_);
	result = (ValaList*) symbols;
	return result;
}


static gpointer _vala_ccode_node_ref0 (gpointer self) {
	return self ? vala_ccode_node_ref (self) : NULL;
}


static void vala_ccode_file_get_symbols_from_fragment (ValaCCodeFile* self, ValaList* symbols, ValaCCodeFragment* fragment) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (symbols != NULL);
	g_return_if_fail (fragment != NULL);
	{
		ValaList* _node_list = NULL;
		ValaCCodeFragment* _tmp0_;
		ValaList* _tmp1_;
		gint _node_size = 0;
		ValaList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _node_index = 0;
		_tmp0_ = fragment;
		_tmp1_ = vala_ccode_fragment_get_children (_tmp0_);
		_node_list = _tmp1_;
		_tmp2_ = _node_list;
		_tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_node_size = _tmp4_;
		_node_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			gint _tmp7_;
			ValaCCodeNode* node = NULL;
			ValaList* _tmp8_;
			gint _tmp9_;
			gpointer _tmp10_;
			ValaCCodeNode* _tmp11_;
			_tmp5_ = _node_index;
			_node_index = _tmp5_ + 1;
			_tmp6_ = _node_index;
			_tmp7_ = _node_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _node_list;
			_tmp9_ = _node_index;
			_tmp10_ = vala_list_get (_tmp8_, _tmp9_);
			node = (ValaCCodeNode*) _tmp10_;
			_tmp11_ = node;
			if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp11_, VALA_TYPE_CCODE_FRAGMENT)) {
				ValaList* _tmp12_;
				ValaCCodeNode* _tmp13_;
				_tmp12_ = symbols;
				_tmp13_ = node;
				vala_ccode_file_get_symbols_from_fragment (self, _tmp12_, G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, VALA_TYPE_CCODE_FRAGMENT, ValaCCodeFragment));
			} else {
				ValaCCodeFunction* func = NULL;
				ValaCCodeNode* _tmp14_;
				ValaCCodeFunction* _tmp15_;
				ValaCCodeFunction* _tmp16_;
				_tmp14_ = node;
				_tmp15_ = _vala_ccode_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp14_, VALA_TYPE_CCODE_FUNCTION) ? ((ValaCCodeFunction*) _tmp14_) : NULL);
				func = _tmp15_;
				_tmp16_ = func;
				if (_tmp16_ != NULL) {
					ValaList* _tmp17_;
					ValaCCodeFunction* _tmp18_;
					const gchar* _tmp19_;
					const gchar* _tmp20_;
					_tmp17_ = symbols;
					_tmp18_ = func;
					_tmp19_ = vala_ccode_function_get_name (_tmp18_);
					_tmp20_ = _tmp19_;
					vala_collection_add ((ValaCollection*) _tmp17_, _tmp20_);
				}
				_vala_ccode_node_unref0 (func);
			}
			_vala_ccode_node_unref0 (node);
		}
		_vala_iterable_unref0 (_node_list);
	}
}


static gunichar string_get_char (const gchar* self, glong index) {
	gunichar result = 0U;
	glong _tmp0_;
	gunichar _tmp1_;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = index;
	_tmp1_ = g_utf8_get_char (((gchar*) self) + _tmp0_);
	result = _tmp1_;
	return result;
}


static gchar* vala_ccode_file_get_define_for_filename (const gchar* filename) {
	gchar* result = NULL;
	GString* define = NULL;
	GString* _tmp0_;
	gchar* i = NULL;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	GString* _tmp19_;
	GString* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	g_return_val_if_fail (filename != NULL, NULL);
	_tmp0_ = g_string_new ("__");
	define = _tmp0_;
	_tmp1_ = filename;
	_tmp2_ = g_strdup (_tmp1_);
	i = _tmp2_;
	while (TRUE) {
		const gchar* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gunichar c = 0U;
		const gchar* _tmp6_;
		gunichar _tmp7_;
		gboolean _tmp8_ = FALSE;
		gunichar _tmp9_;
		gboolean _tmp10_;
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_;
		_tmp3_ = i;
		_tmp4_ = strlen (_tmp3_);
		_tmp5_ = _tmp4_;
		if (!(_tmp5_ > 0)) {
			break;
		}
		_tmp6_ = i;
		_tmp7_ = string_get_char (_tmp6_, (glong) 0);
		c = _tmp7_;
		_tmp9_ = c;
		_tmp10_ = g_unichar_isalnum (_tmp9_);
		if (_tmp10_) {
			gunichar _tmp11_;
			_tmp11_ = c;
			_tmp8_ = _tmp11_ < ((gunichar) 0x80);
		} else {
			_tmp8_ = FALSE;
		}
		if (_tmp8_) {
			GString* _tmp12_;
			gunichar _tmp13_;
			gunichar _tmp14_;
			_tmp12_ = define;
			_tmp13_ = c;
			_tmp14_ = g_unichar_toupper (_tmp13_);
			g_string_append_unichar (_tmp12_, _tmp14_);
		} else {
			GString* _tmp15_;
			_tmp15_ = define;
			g_string_append_c (_tmp15_, '_');
		}
		_tmp16_ = i;
		_tmp17_ = g_utf8_next_char (_tmp16_);
		_tmp18_ = g_strdup (_tmp17_);
		_g_free0 (i);
		i = _tmp18_;
	}
	_tmp19_ = define;
	g_string_append (_tmp19_, "__");
	_tmp20_ = define;
	_tmp21_ = _tmp20_->str;
	_tmp22_ = g_strdup (_tmp21_);
	result = _tmp22_;
	_g_free0 (i);
	_g_string_free0 (define);
	return result;
}


gboolean vala_ccode_file_store (ValaCCodeFile* self, const gchar* filename, const gchar* source_filename, gboolean write_version, gboolean line_directives, const gchar* begin_decls, const gchar* end_decls) {
	gboolean result = FALSE;
	ValaCCodeWriter* writer = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	ValaCCodeWriter* _tmp2_;
	ValaCCodeWriter* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	ValaCCodeWriter* _tmp93_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (filename != NULL, FALSE);
	_tmp0_ = filename;
	_tmp1_ = source_filename;
	_tmp2_ = vala_ccode_writer_new (_tmp0_, _tmp1_);
	writer = _tmp2_;
	_tmp3_ = writer;
	_tmp4_ = write_version;
	_tmp5_ = vala_ccode_writer_open (_tmp3_, _tmp4_);
	if (!_tmp5_) {
		result = FALSE;
		_vala_ccode_writer_unref0 (writer);
		return result;
	}
	_tmp6_ = self->priv->_is_header;
	if (!_tmp6_) {
		ValaCCodeWriter* _tmp7_;
		gboolean _tmp8_;
		ValaCCodeFragment* _tmp9_;
		ValaCCodeWriter* _tmp10_;
		ValaCCodeWriter* _tmp11_;
		ValaCCodeFragment* _tmp12_;
		ValaCCodeWriter* _tmp13_;
		ValaCCodeWriter* _tmp14_;
		ValaCCodeFragment* _tmp15_;
		ValaCCodeWriter* _tmp16_;
		ValaCCodeWriter* _tmp17_;
		ValaCCodeFragment* _tmp18_;
		ValaCCodeWriter* _tmp19_;
		ValaCCodeWriter* _tmp20_;
		ValaCCodeFragment* _tmp21_;
		ValaCCodeWriter* _tmp22_;
		ValaCCodeWriter* _tmp23_;
		ValaCCodeFragment* _tmp24_;
		ValaCCodeWriter* _tmp25_;
		ValaCCodeWriter* _tmp26_;
		ValaCCodeFragment* _tmp27_;
		ValaCCodeWriter* _tmp28_;
		ValaCCodeWriter* _tmp29_;
		ValaCCodeFragment* _tmp30_;
		ValaCCodeWriter* _tmp31_;
		ValaCCodeWriter* _tmp32_;
		_tmp7_ = writer;
		_tmp8_ = line_directives;
		vala_ccode_writer_set_line_directives (_tmp7_, _tmp8_);
		_tmp9_ = self->priv->comments;
		_tmp10_ = writer;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp9_, _tmp10_);
		_tmp11_ = writer;
		vala_ccode_writer_write_newline (_tmp11_);
		_tmp12_ = self->priv->include_directives;
		_tmp13_ = writer;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp12_, _tmp13_);
		_tmp14_ = writer;
		vala_ccode_writer_write_newline (_tmp14_);
		_tmp15_ = self->priv->type_declaration;
		_tmp16_ = writer;
		vala_ccode_node_write_combined ((ValaCCodeNode*) _tmp15_, _tmp16_);
		_tmp17_ = writer;
		vala_ccode_writer_write_newline (_tmp17_);
		_tmp18_ = self->priv->type_definition;
		_tmp19_ = writer;
		vala_ccode_node_write_combined ((ValaCCodeNode*) _tmp18_, _tmp19_);
		_tmp20_ = writer;
		vala_ccode_writer_write_newline (_tmp20_);
		_tmp21_ = self->priv->type_member_declaration;
		_tmp22_ = writer;
		vala_ccode_node_write_declaration ((ValaCCodeNode*) _tmp21_, _tmp22_);
		_tmp23_ = writer;
		vala_ccode_writer_write_newline (_tmp23_);
		_tmp24_ = self->priv->type_member_declaration;
		_tmp25_ = writer;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp24_, _tmp25_);
		_tmp26_ = writer;
		vala_ccode_writer_write_newline (_tmp26_);
		_tmp27_ = self->priv->constant_declaration;
		_tmp28_ = writer;
		vala_ccode_node_write_combined ((ValaCCodeNode*) _tmp27_, _tmp28_);
		_tmp29_ = writer;
		vala_ccode_writer_write_newline (_tmp29_);
		_tmp30_ = self->priv->type_member_definition;
		_tmp31_ = writer;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp30_, _tmp31_);
		_tmp32_ = writer;
		vala_ccode_writer_write_newline (_tmp32_);
	} else {
		ValaCCodeWriter* _tmp33_;
		ValaCCodeOnceSection* once = NULL;
		ValaCCodeWriter* _tmp34_;
		const gchar* _tmp35_;
		const gchar* _tmp36_;
		gchar* _tmp37_;
		gchar* _tmp38_;
		ValaCCodeOnceSection* _tmp39_;
		ValaCCodeOnceSection* _tmp40_;
		ValaCCodeOnceSection* _tmp41_;
		ValaCCodeNewline* _tmp42_;
		ValaCCodeNewline* _tmp43_;
		ValaCCodeOnceSection* _tmp44_;
		ValaCCodeFragment* _tmp45_;
		ValaCCodeOnceSection* _tmp46_;
		ValaCCodeNewline* _tmp47_;
		ValaCCodeNewline* _tmp48_;
		const gchar* _tmp49_;
		ValaCCodeOnceSection* _tmp57_;
		ValaCCodeNewline* _tmp58_;
		ValaCCodeNewline* _tmp59_;
		ValaCCodeOnceSection* _tmp60_;
		ValaCCodeFragment* _tmp61_;
		ValaCCodeOnceSection* _tmp62_;
		ValaCCodeNewline* _tmp63_;
		ValaCCodeNewline* _tmp64_;
		ValaCCodeOnceSection* _tmp65_;
		ValaCCodeFragment* _tmp66_;
		ValaCCodeOnceSection* _tmp67_;
		ValaCCodeNewline* _tmp68_;
		ValaCCodeNewline* _tmp69_;
		ValaCCodeOnceSection* _tmp70_;
		ValaCCodeFragment* _tmp71_;
		ValaCCodeOnceSection* _tmp72_;
		ValaCCodeNewline* _tmp73_;
		ValaCCodeNewline* _tmp74_;
		ValaCCodeOnceSection* _tmp75_;
		ValaCCodeFragment* _tmp76_;
		ValaCCodeOnceSection* _tmp77_;
		ValaCCodeNewline* _tmp78_;
		ValaCCodeNewline* _tmp79_;
		const gchar* _tmp80_;
		ValaCCodeOnceSection* _tmp88_;
		ValaCCodeNewline* _tmp89_;
		ValaCCodeNewline* _tmp90_;
		ValaCCodeOnceSection* _tmp91_;
		ValaCCodeWriter* _tmp92_;
		_tmp33_ = writer;
		vala_ccode_writer_write_newline (_tmp33_);
		_tmp34_ = writer;
		_tmp35_ = vala_ccode_writer_get_filename (_tmp34_);
		_tmp36_ = _tmp35_;
		_tmp37_ = vala_ccode_file_get_define_for_filename (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = vala_ccode_once_section_new (_tmp38_);
		_tmp40_ = _tmp39_;
		_g_free0 (_tmp38_);
		once = _tmp40_;
		_tmp41_ = once;
		_tmp42_ = vala_ccode_newline_new ();
		_tmp43_ = _tmp42_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp41_, (ValaCCodeNode*) _tmp43_);
		_vala_ccode_node_unref0 (_tmp43_);
		_tmp44_ = once;
		_tmp45_ = self->priv->include_directives;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp44_, (ValaCCodeNode*) _tmp45_);
		_tmp46_ = once;
		_tmp47_ = vala_ccode_newline_new ();
		_tmp48_ = _tmp47_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp46_, (ValaCCodeNode*) _tmp48_);
		_vala_ccode_node_unref0 (_tmp48_);
		_tmp49_ = begin_decls;
		if (_tmp49_ != NULL) {
			ValaCCodeOnceSection* _tmp50_;
			const gchar* _tmp51_;
			ValaCCodeIdentifier* _tmp52_;
			ValaCCodeIdentifier* _tmp53_;
			ValaCCodeOnceSection* _tmp54_;
			ValaCCodeNewline* _tmp55_;
			ValaCCodeNewline* _tmp56_;
			_tmp50_ = once;
			_tmp51_ = begin_decls;
			_tmp52_ = vala_ccode_identifier_new (_tmp51_);
			_tmp53_ = _tmp52_;
			vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp50_, (ValaCCodeNode*) _tmp53_);
			_vala_ccode_node_unref0 (_tmp53_);
			_tmp54_ = once;
			_tmp55_ = vala_ccode_newline_new ();
			_tmp56_ = _tmp55_;
			vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp54_, (ValaCCodeNode*) _tmp56_);
			_vala_ccode_node_unref0 (_tmp56_);
		}
		_tmp57_ = once;
		_tmp58_ = vala_ccode_newline_new ();
		_tmp59_ = _tmp58_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp57_, (ValaCCodeNode*) _tmp59_);
		_vala_ccode_node_unref0 (_tmp59_);
		_tmp60_ = once;
		_tmp61_ = self->priv->type_declaration;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp60_, (ValaCCodeNode*) _tmp61_);
		_tmp62_ = once;
		_tmp63_ = vala_ccode_newline_new ();
		_tmp64_ = _tmp63_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp62_, (ValaCCodeNode*) _tmp64_);
		_vala_ccode_node_unref0 (_tmp64_);
		_tmp65_ = once;
		_tmp66_ = self->priv->type_definition;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp65_, (ValaCCodeNode*) _tmp66_);
		_tmp67_ = once;
		_tmp68_ = vala_ccode_newline_new ();
		_tmp69_ = _tmp68_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp67_, (ValaCCodeNode*) _tmp69_);
		_vala_ccode_node_unref0 (_tmp69_);
		_tmp70_ = once;
		_tmp71_ = self->priv->type_member_declaration;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp70_, (ValaCCodeNode*) _tmp71_);
		_tmp72_ = once;
		_tmp73_ = vala_ccode_newline_new ();
		_tmp74_ = _tmp73_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp72_, (ValaCCodeNode*) _tmp74_);
		_vala_ccode_node_unref0 (_tmp74_);
		_tmp75_ = once;
		_tmp76_ = self->priv->constant_declaration;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp75_, (ValaCCodeNode*) _tmp76_);
		_tmp77_ = once;
		_tmp78_ = vala_ccode_newline_new ();
		_tmp79_ = _tmp78_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp77_, (ValaCCodeNode*) _tmp79_);
		_vala_ccode_node_unref0 (_tmp79_);
		_tmp80_ = begin_decls;
		if (_tmp80_ != NULL) {
			ValaCCodeOnceSection* _tmp81_;
			const gchar* _tmp82_;
			ValaCCodeIdentifier* _tmp83_;
			ValaCCodeIdentifier* _tmp84_;
			ValaCCodeOnceSection* _tmp85_;
			ValaCCodeNewline* _tmp86_;
			ValaCCodeNewline* _tmp87_;
			_tmp81_ = once;
			_tmp82_ = end_decls;
			_tmp83_ = vala_ccode_identifier_new (_tmp82_);
			_tmp84_ = _tmp83_;
			vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp81_, (ValaCCodeNode*) _tmp84_);
			_vala_ccode_node_unref0 (_tmp84_);
			_tmp85_ = once;
			_tmp86_ = vala_ccode_newline_new ();
			_tmp87_ = _tmp86_;
			vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp85_, (ValaCCodeNode*) _tmp87_);
			_vala_ccode_node_unref0 (_tmp87_);
		}
		_tmp88_ = once;
		_tmp89_ = vala_ccode_newline_new ();
		_tmp90_ = _tmp89_;
		vala_ccode_fragment_append ((ValaCCodeFragment*) _tmp88_, (ValaCCodeNode*) _tmp90_);
		_vala_ccode_node_unref0 (_tmp90_);
		_tmp91_ = once;
		_tmp92_ = writer;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp91_, _tmp92_);
		_vala_ccode_node_unref0 (once);
	}
	_tmp93_ = writer;
	vala_ccode_writer_close (_tmp93_);
	result = TRUE;
	_vala_ccode_writer_unref0 (writer);
	return result;
}


ValaCCodeFile* vala_ccode_file_construct (GType object_type) {
	ValaCCodeFile* self = NULL;
	self = (ValaCCodeFile*) g_type_create_instance (object_type);
	return self;
}


ValaCCodeFile* vala_ccode_file_new (void) {
	return vala_ccode_file_construct (VALA_TYPE_CCODE_FILE);
}


gboolean vala_ccode_file_get_is_header (ValaCCodeFile* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_is_header;
	result = _tmp0_;
	return result;
}


void vala_ccode_file_set_is_header (ValaCCodeFile* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_is_header = _tmp0_;
}


static void vala_value_ccode_file_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void vala_value_ccode_file_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		vala_ccode_file_unref (value->data[0].v_pointer);
	}
}


static void vala_value_ccode_file_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = vala_ccode_file_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer vala_value_ccode_file_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* vala_value_ccode_file_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		ValaCCodeFile * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = vala_ccode_file_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* vala_value_ccode_file_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	ValaCCodeFile ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = vala_ccode_file_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* vala_param_spec_ccode_file (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ValaParamSpecCCodeFile* spec;
	g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_CCODE_FILE), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer vala_value_get_ccode_file (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_CCODE_FILE), NULL);
	return value->data[0].v_pointer;
}


void vala_value_set_ccode_file (GValue* value, gpointer v_object) {
	ValaCCodeFile * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_CCODE_FILE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_CCODE_FILE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		vala_ccode_file_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		vala_ccode_file_unref (old);
	}
}


void vala_value_take_ccode_file (GValue* value, gpointer v_object) {
	ValaCCodeFile * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_CCODE_FILE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_CCODE_FILE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		vala_ccode_file_unref (old);
	}
}


static void vala_ccode_file_class_init (ValaCCodeFileClass * klass) {
	vala_ccode_file_parent_class = g_type_class_peek_parent (klass);
	((ValaCCodeFileClass *) klass)->finalize = vala_ccode_file_finalize;
	g_type_class_add_private (klass, sizeof (ValaCCodeFilePrivate));
}


static void vala_ccode_file_instance_init (ValaCCodeFile * self) {
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	ValaHashSet* _tmp2_;
	GHashFunc _tmp3_;
	GEqualFunc _tmp4_;
	ValaHashSet* _tmp5_;
	ValaCCodeFragment* _tmp6_;
	ValaCCodeFragment* _tmp7_;
	ValaCCodeFragment* _tmp8_;
	ValaCCodeFragment* _tmp9_;
	ValaCCodeFragment* _tmp10_;
	ValaCCodeFragment* _tmp11_;
	ValaCCodeFragment* _tmp12_;
	self->priv = VALA_CCODE_FILE_GET_PRIVATE (self);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = vala_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp0_, _tmp1_);
	self->priv->declarations = (ValaSet*) _tmp2_;
	_tmp3_ = g_str_hash;
	_tmp4_ = g_str_equal;
	_tmp5_ = vala_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp3_, _tmp4_);
	self->priv->includes = (ValaSet*) _tmp5_;
	_tmp6_ = vala_ccode_fragment_new ();
	self->priv->comments = _tmp6_;
	_tmp7_ = vala_ccode_fragment_new ();
	self->priv->include_directives = _tmp7_;
	_tmp8_ = vala_ccode_fragment_new ();
	self->priv->type_declaration = _tmp8_;
	_tmp9_ = vala_ccode_fragment_new ();
	self->priv->type_definition = _tmp9_;
	_tmp10_ = vala_ccode_fragment_new ();
	self->priv->type_member_declaration = _tmp10_;
	_tmp11_ = vala_ccode_fragment_new ();
	self->priv->constant_declaration = _tmp11_;
	_tmp12_ = vala_ccode_fragment_new ();
	self->priv->type_member_definition = _tmp12_;
	self->ref_count = 1;
}


static void vala_ccode_file_finalize (ValaCCodeFile * obj) {
	ValaCCodeFile * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_FILE, ValaCCodeFile);
	g_signal_handlers_destroy (self);
	_vala_iterable_unref0 (self->priv->declarations);
	_vala_iterable_unref0 (self->priv->includes);
	_vala_ccode_node_unref0 (self->priv->comments);
	_vala_ccode_node_unref0 (self->priv->include_directives);
	_vala_ccode_node_unref0 (self->priv->type_declaration);
	_vala_ccode_node_unref0 (self->priv->type_definition);
	_vala_ccode_node_unref0 (self->priv->type_member_declaration);
	_vala_ccode_node_unref0 (self->priv->constant_declaration);
	_vala_ccode_node_unref0 (self->priv->type_member_definition);
}


GType vala_ccode_file_get_type (void) {
	static volatile gsize vala_ccode_file_type_id__volatile = 0;
	if (g_once_init_enter (&vala_ccode_file_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { vala_value_ccode_file_init, vala_value_ccode_file_free_value, vala_value_ccode_file_copy_value, vala_value_ccode_file_peek_pointer, "p", vala_value_ccode_file_collect_value, "p", vala_value_ccode_file_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeFileClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_file_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeFile), 0, (GInstanceInitFunc) vala_ccode_file_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType vala_ccode_file_type_id;
		vala_ccode_file_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaCCodeFile", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&vala_ccode_file_type_id__volatile, vala_ccode_file_type_id);
	}
	return vala_ccode_file_type_id__volatile;
}


gpointer vala_ccode_file_ref (gpointer instance) {
	ValaCCodeFile * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void vala_ccode_file_unref (gpointer instance) {
	ValaCCodeFile * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		VALA_CCODE_FILE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



