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

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

#include <glib.h>
#include <glib-object.h>
#include "vala.h"
#include <valagee.h>

#define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
#define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))

struct _ValaDeclarationStatementPrivate {
	ValaSymbol* _declaration;
};


static gpointer vala_declaration_statement_parent_class = NULL;
static ValaStatementIface * vala_declaration_statement_vala_statement_parent_iface = NULL;

#define VALA_DECLARATION_STATEMENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_DECLARATION_STATEMENT, ValaDeclarationStatementPrivate))
static void vala_declaration_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static void vala_declaration_statement_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor);
static gboolean vala_declaration_statement_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_declaration_statement_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_declaration_statement_real_get_defined_variables (ValaCodeNode* base, ValaCollection* collection);
static void vala_declaration_statement_real_get_used_variables (ValaCodeNode* base, ValaCollection* collection);
static void vala_declaration_statement_finalize (ValaCodeNode * obj);


/**
 * Creates a new declaration statement.
 *
 * @param declaration       local variable declaration
 * @param source_reference  reference to source code
 * @return                  newly created declaration statement
 */
ValaDeclarationStatement* vala_declaration_statement_construct (GType object_type, ValaSymbol* declaration, ValaSourceReference* source_reference) {
	ValaDeclarationStatement* self = NULL;
	ValaSymbol* _tmp0_;
	ValaSourceReference* _tmp1_;
	g_return_val_if_fail (declaration != NULL, NULL);
	self = (ValaDeclarationStatement*) vala_code_node_construct (object_type);
	_tmp0_ = declaration;
	vala_declaration_statement_set_declaration (self, _tmp0_);
	_tmp1_ = source_reference;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp1_);
	return self;
}


ValaDeclarationStatement* vala_declaration_statement_new (ValaSymbol* declaration, ValaSourceReference* source_reference) {
	return vala_declaration_statement_construct (VALA_TYPE_DECLARATION_STATEMENT, declaration, source_reference);
}


static void vala_declaration_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaDeclarationStatement * self;
	ValaCodeVisitor* _tmp0_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = visitor;
	vala_code_visitor_visit_declaration_statement (_tmp0_, self);
}


static void vala_declaration_statement_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaDeclarationStatement * self;
	ValaSymbol* _tmp0_;
	ValaSymbol* _tmp1_;
	ValaCodeVisitor* _tmp2_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = vala_declaration_statement_get_declaration (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = visitor;
	vala_code_node_accept ((ValaCodeNode*) _tmp1_, _tmp2_);
}


static gpointer _vala_code_node_ref0 (gpointer self) {
	return self ? vala_code_node_ref (self) : NULL;
}


static gboolean vala_declaration_statement_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaDeclarationStatement * self;
	gboolean result = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaSymbol* _tmp4_;
	ValaSymbol* _tmp5_;
	ValaCodeContext* _tmp6_;
	ValaLocalVariable* local = NULL;
	ValaSymbol* _tmp7_;
	ValaSymbol* _tmp8_;
	ValaLocalVariable* _tmp9_;
	gboolean _tmp10_ = FALSE;
	ValaLocalVariable* _tmp11_;
	gboolean _tmp37_;
	gboolean _tmp38_;
	self = (ValaDeclarationStatement*) base;
	g_return_val_if_fail (context != NULL, FALSE);
	_tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
		_tmp3_ = _tmp2_;
		result = !_tmp3_;
		return result;
	}
	vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
	_tmp4_ = vala_declaration_statement_get_declaration (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = context;
	vala_code_node_check ((ValaCodeNode*) _tmp5_, _tmp6_);
	_tmp7_ = vala_declaration_statement_get_declaration (self);
	_tmp8_ = _tmp7_;
	_tmp9_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp8_, VALA_TYPE_LOCAL_VARIABLE) ? ((ValaLocalVariable*) _tmp8_) : NULL);
	local = _tmp9_;
	_tmp11_ = local;
	if (_tmp11_ != NULL) {
		ValaLocalVariable* _tmp12_;
		ValaExpression* _tmp13_;
		ValaExpression* _tmp14_;
		_tmp12_ = local;
		_tmp13_ = vala_variable_get_initializer ((ValaVariable*) _tmp12_);
		_tmp14_ = _tmp13_;
		_tmp10_ = _tmp14_ != NULL;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		{
			ValaList* _error_type_list = NULL;
			ValaLocalVariable* _tmp15_;
			ValaExpression* _tmp16_;
			ValaExpression* _tmp17_;
			ValaList* _tmp18_;
			gint _error_type_size = 0;
			ValaList* _tmp19_;
			gint _tmp20_;
			gint _tmp21_;
			gint _error_type_index = 0;
			_tmp15_ = local;
			_tmp16_ = vala_variable_get_initializer ((ValaVariable*) _tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = vala_code_node_get_error_types ((ValaCodeNode*) _tmp17_);
			_error_type_list = _tmp18_;
			_tmp19_ = _error_type_list;
			_tmp20_ = vala_collection_get_size ((ValaCollection*) _tmp19_);
			_tmp21_ = _tmp20_;
			_error_type_size = _tmp21_;
			_error_type_index = -1;
			while (TRUE) {
				gint _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				ValaDataType* error_type = NULL;
				ValaList* _tmp25_;
				gint _tmp26_;
				gpointer _tmp27_;
				ValaDataType* initializer_error_type = NULL;
				ValaDataType* _tmp28_;
				ValaDataType* _tmp29_;
				ValaDataType* _tmp30_;
				ValaLocalVariable* _tmp31_;
				ValaExpression* _tmp32_;
				ValaExpression* _tmp33_;
				ValaSourceReference* _tmp34_;
				ValaSourceReference* _tmp35_;
				ValaDataType* _tmp36_;
				_tmp22_ = _error_type_index;
				_error_type_index = _tmp22_ + 1;
				_tmp23_ = _error_type_index;
				_tmp24_ = _error_type_size;
				if (!(_tmp23_ < _tmp24_)) {
					break;
				}
				_tmp25_ = _error_type_list;
				_tmp26_ = _error_type_index;
				_tmp27_ = vala_list_get (_tmp25_, _tmp26_);
				error_type = (ValaDataType*) _tmp27_;
				_tmp28_ = error_type;
				_tmp29_ = vala_data_type_copy (_tmp28_);
				initializer_error_type = _tmp29_;
				_tmp30_ = initializer_error_type;
				_tmp31_ = local;
				_tmp32_ = vala_variable_get_initializer ((ValaVariable*) _tmp31_);
				_tmp33_ = _tmp32_;
				_tmp34_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp33_);
				_tmp35_ = _tmp34_;
				vala_code_node_set_source_reference ((ValaCodeNode*) _tmp30_, _tmp35_);
				_tmp36_ = initializer_error_type;
				vala_code_node_add_error_type ((ValaCodeNode*) self, _tmp36_);
				_vala_code_node_unref0 (initializer_error_type);
				_vala_code_node_unref0 (error_type);
			}
			_vala_iterable_unref0 (_error_type_list);
		}
	}
	_tmp37_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp38_ = _tmp37_;
	result = !_tmp38_;
	_vala_code_node_unref0 (local);
	return result;
}


static void vala_declaration_statement_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaDeclarationStatement * self;
	ValaCodeGenerator* _tmp0_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = codegen;
	vala_code_visitor_visit_declaration_statement ((ValaCodeVisitor*) _tmp0_, self);
}


static void vala_declaration_statement_real_get_defined_variables (ValaCodeNode* base, ValaCollection* collection) {
	ValaDeclarationStatement * self;
	ValaLocalVariable* local = NULL;
	ValaSymbol* _tmp0_;
	ValaSymbol* _tmp1_;
	ValaLocalVariable* _tmp2_;
	ValaLocalVariable* _tmp3_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (collection != NULL);
	_tmp0_ = vala_declaration_statement_get_declaration (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, VALA_TYPE_LOCAL_VARIABLE) ? ((ValaLocalVariable*) _tmp1_) : NULL);
	local = _tmp2_;
	_tmp3_ = local;
	if (_tmp3_ != NULL) {
		ValaArrayType* array_type = NULL;
		ValaLocalVariable* _tmp4_;
		ValaDataType* _tmp5_;
		ValaDataType* _tmp6_;
		ValaArrayType* _tmp7_;
		ValaLocalVariable* _tmp8_;
		ValaExpression* _tmp9_;
		ValaExpression* _tmp10_;
		_tmp4_ = local;
		_tmp5_ = vala_variable_get_variable_type ((ValaVariable*) _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, VALA_TYPE_ARRAY_TYPE) ? ((ValaArrayType*) _tmp6_) : NULL);
		array_type = _tmp7_;
		_tmp8_ = local;
		_tmp9_ = vala_variable_get_initializer ((ValaVariable*) _tmp8_);
		_tmp10_ = _tmp9_;
		if (_tmp10_ != NULL) {
			ValaLocalVariable* _tmp11_;
			ValaExpression* _tmp12_;
			ValaExpression* _tmp13_;
			ValaCollection* _tmp14_;
			ValaCollection* _tmp15_;
			ValaLocalVariable* _tmp16_;
			_tmp11_ = local;
			_tmp12_ = vala_variable_get_initializer ((ValaVariable*) _tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = collection;
			vala_code_node_get_defined_variables ((ValaCodeNode*) _tmp13_, _tmp14_);
			_tmp15_ = collection;
			_tmp16_ = local;
			vala_collection_add (_tmp15_, (ValaVariable*) _tmp16_);
		} else {
			gboolean _tmp17_ = FALSE;
			ValaArrayType* _tmp18_;
			_tmp18_ = array_type;
			if (_tmp18_ != NULL) {
				ValaArrayType* _tmp19_;
				gboolean _tmp20_;
				gboolean _tmp21_;
				_tmp19_ = array_type;
				_tmp20_ = vala_array_type_get_fixed_length (_tmp19_);
				_tmp21_ = _tmp20_;
				_tmp17_ = _tmp21_;
			} else {
				_tmp17_ = FALSE;
			}
			if (_tmp17_) {
				ValaCollection* _tmp22_;
				ValaLocalVariable* _tmp23_;
				_tmp22_ = collection;
				_tmp23_ = local;
				vala_collection_add (_tmp22_, (ValaVariable*) _tmp23_);
			}
		}
		_vala_code_node_unref0 (array_type);
	}
	_vala_code_node_unref0 (local);
}


static void vala_declaration_statement_real_get_used_variables (ValaCodeNode* base, ValaCollection* collection) {
	ValaDeclarationStatement * self;
	ValaLocalVariable* local = NULL;
	ValaSymbol* _tmp0_;
	ValaSymbol* _tmp1_;
	ValaLocalVariable* _tmp2_;
	gboolean _tmp3_ = FALSE;
	ValaLocalVariable* _tmp4_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (collection != NULL);
	_tmp0_ = vala_declaration_statement_get_declaration (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, VALA_TYPE_LOCAL_VARIABLE) ? ((ValaLocalVariable*) _tmp1_) : NULL);
	local = _tmp2_;
	_tmp4_ = local;
	if (_tmp4_ != NULL) {
		ValaLocalVariable* _tmp5_;
		ValaExpression* _tmp6_;
		ValaExpression* _tmp7_;
		_tmp5_ = local;
		_tmp6_ = vala_variable_get_initializer ((ValaVariable*) _tmp5_);
		_tmp7_ = _tmp6_;
		_tmp3_ = _tmp7_ != NULL;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		ValaLocalVariable* _tmp8_;
		ValaExpression* _tmp9_;
		ValaExpression* _tmp10_;
		ValaCollection* _tmp11_;
		_tmp8_ = local;
		_tmp9_ = vala_variable_get_initializer ((ValaVariable*) _tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = collection;
		vala_code_node_get_used_variables ((ValaCodeNode*) _tmp10_, _tmp11_);
	}
	_vala_code_node_unref0 (local);
}


ValaSymbol* vala_declaration_statement_get_declaration (ValaDeclarationStatement* self) {
	ValaSymbol* result;
	ValaSymbol* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_declaration;
	result = _tmp0_;
	return result;
}


void vala_declaration_statement_set_declaration (ValaDeclarationStatement* self, ValaSymbol* value) {
	ValaSymbol* _tmp0_;
	ValaSymbol* _tmp1_;
	ValaSymbol* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_code_node_ref0 (_tmp0_);
	_vala_code_node_unref0 (self->priv->_declaration);
	self->priv->_declaration = _tmp1_;
	_tmp2_ = self->priv->_declaration;
	if (_tmp2_ != NULL) {
		ValaSymbol* _tmp3_;
		_tmp3_ = self->priv->_declaration;
		vala_code_node_set_parent_node ((ValaCodeNode*) _tmp3_, (ValaCodeNode*) self);
	}
}


static void vala_declaration_statement_class_init (ValaDeclarationStatementClass * klass) {
	vala_declaration_statement_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_declaration_statement_finalize;
	g_type_class_add_private (klass, sizeof (ValaDeclarationStatementPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_declaration_statement_real_accept;
	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_declaration_statement_real_accept_children;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_declaration_statement_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_declaration_statement_real_emit;
	((ValaCodeNodeClass *) klass)->get_defined_variables = (void (*) (ValaCodeNode *, ValaCollection*)) vala_declaration_statement_real_get_defined_variables;
	((ValaCodeNodeClass *) klass)->get_used_variables = (void (*) (ValaCodeNode *, ValaCollection*)) vala_declaration_statement_real_get_used_variables;
}


static void vala_declaration_statement_vala_statement_interface_init (ValaStatementIface * iface) {
	vala_declaration_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
}


static void vala_declaration_statement_instance_init (ValaDeclarationStatement * self) {
	self->priv = VALA_DECLARATION_STATEMENT_GET_PRIVATE (self);
}


static void vala_declaration_statement_finalize (ValaCodeNode * obj) {
	ValaDeclarationStatement * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_DECLARATION_STATEMENT, ValaDeclarationStatement);
	_vala_code_node_unref0 (self->priv->_declaration);
	VALA_CODE_NODE_CLASS (vala_declaration_statement_parent_class)->finalize (obj);
}


/**
 * Represents a local variable or constant declaration statement in the source code.
 */
GType vala_declaration_statement_get_type (void) {
	static volatile gsize vala_declaration_statement_type_id__volatile = 0;
	if (g_once_init_enter (&vala_declaration_statement_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaDeclarationStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_declaration_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaDeclarationStatement), 0, (GInstanceInitFunc) vala_declaration_statement_instance_init, NULL };
		static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_declaration_statement_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType vala_declaration_statement_type_id;
		vala_declaration_statement_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaDeclarationStatement", &g_define_type_info, 0);
		g_type_add_interface_static (vala_declaration_statement_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
		g_once_init_leave (&vala_declaration_statement_type_id__volatile, vala_declaration_statement_type_id);
	}
	return vala_declaration_statement_type_id__volatile;
}



