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

/* valaccodeblock.vala
 *
 * Copyright (C) 2006-2008  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>

#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)))

struct _ValaCCodeBlockPrivate {
	gboolean _suppress_newline;
	ValaList* statements;
};


static gpointer vala_ccode_block_parent_class = NULL;

#define VALA_CCODE_BLOCK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_CCODE_BLOCK, ValaCCodeBlockPrivate))
static void vala_ccode_block_real_write (ValaCCodeNode* base, ValaCCodeWriter* writer);
static void vala_ccode_block_finalize (ValaCCodeNode * obj);


/**
 * Prepend the specified statement to the list of statements.
 */
void vala_ccode_block_prepend_statement (ValaCCodeBlock* self, ValaCCodeNode* statement) {
	ValaList* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (statement != NULL);
	_tmp0_ = self->priv->statements;
	_tmp1_ = statement;
	vala_list_insert (_tmp0_, 0, _tmp1_);
}


/**
 * Append the specified statement to the list of statements.
 */
void vala_ccode_block_add_statement (ValaCCodeBlock* self, ValaCCodeNode* statement) {
	ValaList* _tmp0_;
	ValaCCodeNode* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (statement != NULL);
	_tmp0_ = self->priv->statements;
	_tmp1_ = statement;
	vala_collection_add ((ValaCollection*) _tmp0_, _tmp1_);
}


static gpointer _vala_iterable_ref0 (gpointer self) {
	return self ? vala_iterable_ref (self) : NULL;
}


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


static void vala_ccode_block_real_write (ValaCCodeNode* base, ValaCCodeWriter* writer) {
	ValaCCodeBlock * self;
	ValaCCodeNode* last_statement = NULL;
	ValaCCodeWriter* _tmp0_;
	ValaCCodeWriter* _tmp41_;
	gboolean _tmp42_;
	self = (ValaCCodeBlock*) base;
	g_return_if_fail (writer != NULL);
	last_statement = NULL;
	_tmp0_ = writer;
	vala_ccode_writer_write_begin_block (_tmp0_);
	{
		ValaList* _statement_list = NULL;
		ValaList* _tmp1_;
		ValaList* _tmp2_;
		gint _statement_size = 0;
		ValaList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _statement_index = 0;
		_tmp1_ = self->priv->statements;
		_tmp2_ = _vala_iterable_ref0 (_tmp1_);
		_statement_list = _tmp2_;
		_tmp3_ = _statement_list;
		_tmp4_ = vala_collection_get_size ((ValaCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_statement_size = _tmp5_;
		_statement_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			gint _tmp8_;
			ValaCCodeNode* statement = NULL;
			ValaList* _tmp9_;
			gint _tmp10_;
			gpointer _tmp11_;
			ValaCCodeNode* _tmp12_;
			ValaCCodeWriter* _tmp13_;
			gboolean _tmp14_ = FALSE;
			ValaCCodeNode* _tmp15_;
			_tmp6_ = _statement_index;
			_statement_index = _tmp6_ + 1;
			_tmp7_ = _statement_index;
			_tmp8_ = _statement_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _statement_list;
			_tmp10_ = _statement_index;
			_tmp11_ = vala_list_get (_tmp9_, _tmp10_);
			statement = (ValaCCodeNode*) _tmp11_;
			_tmp12_ = statement;
			_tmp13_ = writer;
			vala_ccode_node_write_declaration (_tmp12_, _tmp13_);
			_tmp15_ = statement;
			if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp15_, VALA_TYPE_CCODE_LABEL)) {
				_tmp14_ = TRUE;
			} else {
				ValaCCodeNode* _tmp16_;
				_tmp16_ = statement;
				_tmp14_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp16_, VALA_TYPE_CCODE_CASE_STATEMENT);
			}
			if (_tmp14_) {
				_vala_ccode_node_unref0 (last_statement);
				last_statement = NULL;
			} else {
				gboolean _tmp17_ = FALSE;
				gboolean _tmp18_ = FALSE;
				gboolean _tmp19_ = FALSE;
				ValaCCodeNode* _tmp20_;
				_tmp20_ = statement;
				if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp20_, VALA_TYPE_CCODE_RETURN_STATEMENT)) {
					_tmp19_ = TRUE;
				} else {
					ValaCCodeNode* _tmp21_;
					_tmp21_ = statement;
					_tmp19_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp21_, VALA_TYPE_CCODE_GOTO_STATEMENT);
				}
				if (_tmp19_) {
					_tmp18_ = TRUE;
				} else {
					ValaCCodeNode* _tmp22_;
					_tmp22_ = statement;
					_tmp18_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp22_, VALA_TYPE_CCODE_CONTINUE_STATEMENT);
				}
				if (_tmp18_) {
					_tmp17_ = TRUE;
				} else {
					ValaCCodeNode* _tmp23_;
					_tmp23_ = statement;
					_tmp17_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp23_, VALA_TYPE_CCODE_BREAK_STATEMENT);
				}
				if (_tmp17_) {
					ValaCCodeNode* _tmp24_;
					ValaCCodeNode* _tmp25_;
					_tmp24_ = statement;
					_tmp25_ = _vala_ccode_node_ref0 (_tmp24_);
					_vala_ccode_node_unref0 (last_statement);
					last_statement = _tmp25_;
				}
			}
			_vala_ccode_node_unref0 (statement);
		}
		_vala_iterable_unref0 (_statement_list);
	}
	{
		ValaList* _statement_list = NULL;
		ValaList* _tmp26_;
		ValaList* _tmp27_;
		gint _statement_size = 0;
		ValaList* _tmp28_;
		gint _tmp29_;
		gint _tmp30_;
		gint _statement_index = 0;
		_tmp26_ = self->priv->statements;
		_tmp27_ = _vala_iterable_ref0 (_tmp26_);
		_statement_list = _tmp27_;
		_tmp28_ = _statement_list;
		_tmp29_ = vala_collection_get_size ((ValaCollection*) _tmp28_);
		_tmp30_ = _tmp29_;
		_statement_size = _tmp30_;
		_statement_index = -1;
		while (TRUE) {
			gint _tmp31_;
			gint _tmp32_;
			gint _tmp33_;
			ValaCCodeNode* statement = NULL;
			ValaList* _tmp34_;
			gint _tmp35_;
			gpointer _tmp36_;
			ValaCCodeNode* _tmp37_;
			ValaCCodeWriter* _tmp38_;
			ValaCCodeNode* _tmp39_;
			ValaCCodeNode* _tmp40_;
			_tmp31_ = _statement_index;
			_statement_index = _tmp31_ + 1;
			_tmp32_ = _statement_index;
			_tmp33_ = _statement_size;
			if (!(_tmp32_ < _tmp33_)) {
				break;
			}
			_tmp34_ = _statement_list;
			_tmp35_ = _statement_index;
			_tmp36_ = vala_list_get (_tmp34_, _tmp35_);
			statement = (ValaCCodeNode*) _tmp36_;
			_tmp37_ = statement;
			_tmp38_ = writer;
			vala_ccode_node_write (_tmp37_, _tmp38_);
			_tmp39_ = statement;
			_tmp40_ = last_statement;
			if (_tmp39_ == _tmp40_) {
				_vala_ccode_node_unref0 (statement);
				break;
			}
			_vala_ccode_node_unref0 (statement);
		}
		_vala_iterable_unref0 (_statement_list);
	}
	_tmp41_ = writer;
	vala_ccode_writer_write_end_block (_tmp41_);
	_tmp42_ = self->priv->_suppress_newline;
	if (!_tmp42_) {
		ValaCCodeWriter* _tmp43_;
		_tmp43_ = writer;
		vala_ccode_writer_write_newline (_tmp43_);
	}
	_vala_ccode_node_unref0 (last_statement);
}


ValaCCodeBlock* vala_ccode_block_construct (GType object_type) {
	ValaCCodeBlock* self = NULL;
	self = (ValaCCodeBlock*) vala_ccode_statement_construct (object_type);
	return self;
}


ValaCCodeBlock* vala_ccode_block_new (void) {
	return vala_ccode_block_construct (VALA_TYPE_CCODE_BLOCK);
}


gboolean vala_ccode_block_get_suppress_newline (ValaCCodeBlock* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_suppress_newline;
	result = _tmp0_;
	return result;
}


void vala_ccode_block_set_suppress_newline (ValaCCodeBlock* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_suppress_newline = _tmp0_;
}


static void vala_ccode_block_class_init (ValaCCodeBlockClass * klass) {
	vala_ccode_block_parent_class = g_type_class_peek_parent (klass);
	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_block_finalize;
	g_type_class_add_private (klass, sizeof (ValaCCodeBlockPrivate));
	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode *, ValaCCodeWriter*)) vala_ccode_block_real_write;
}


static void vala_ccode_block_instance_init (ValaCCodeBlock * self) {
	GEqualFunc _tmp0_;
	ValaArrayList* _tmp1_;
	self->priv = VALA_CCODE_BLOCK_GET_PRIVATE (self);
	_tmp0_ = g_direct_equal;
	_tmp1_ = vala_array_list_new (VALA_TYPE_CCODE_NODE, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp0_);
	self->priv->statements = (ValaList*) _tmp1_;
}


static void vala_ccode_block_finalize (ValaCCodeNode * obj) {
	ValaCCodeBlock * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_BLOCK, ValaCCodeBlock);
	_vala_iterable_unref0 (self->priv->statements);
	VALA_CCODE_NODE_CLASS (vala_ccode_block_parent_class)->finalize (obj);
}


/**
 * Represents a C code block.
 */
GType vala_ccode_block_get_type (void) {
	static volatile gsize vala_ccode_block_type_id__volatile = 0;
	if (g_once_init_enter (&vala_ccode_block_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeBlockClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_block_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeBlock), 0, (GInstanceInitFunc) vala_ccode_block_instance_init, NULL };
		GType vala_ccode_block_type_id;
		vala_ccode_block_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeBlock", &g_define_type_info, 0);
		g_once_init_leave (&vala_ccode_block_type_id__volatile, vala_ccode_block_type_id);
	}
	return vala_ccode_block_type_id__volatile;
}



