/* 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 "vala.h"
#include <valagee.h>
#include <glib-object.h>
#include <glib.h>

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

struct _ValaDeclarationStatementPrivate {
	ValaSymbol* _declaration;
};

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

static void vala_declaration_statement_set_declaration (ValaDeclarationStatement* self,
                                                 ValaSymbol* value);
static void vala_declaration_statement_real_accept (ValaCodeNode* base,
                                             ValaCodeVisitor* visitor);
static void vala_declaration_statement_real_accept_children (ValaCodeNode* base,
                                                      ValaCodeVisitor* visitor);
static void vala_declaration_statement_real_get_error_types (ValaCodeNode* base,
                                                      ValaCollection* collection,
                                                      ValaSourceReference* source_reference);
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);
static GType vala_declaration_statement_get_type_once (void);

static inline gpointer
vala_declaration_statement_get_instance_private (ValaDeclarationStatement* self)
{
	return G_STRUCT_MEMBER_P (self, ValaDeclarationStatement_private_offset);
}

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;
}

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

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

/**
 * 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;
	g_return_val_if_fail (declaration != NULL, NULL);
	self = (ValaDeclarationStatement*) vala_code_node_construct (object_type);
	vala_declaration_statement_set_declaration (self, declaration);
	vala_code_node_set_source_reference ((ValaCodeNode*) self, source_reference);
	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;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (visitor != NULL);
	vala_code_visitor_visit_declaration_statement (visitor, self);
}

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

static void
vala_declaration_statement_real_get_error_types (ValaCodeNode* base,
                                                 ValaCollection* collection,
                                                 ValaSourceReference* source_reference)
{
	ValaDeclarationStatement * self;
	ValaLocalVariable* local = NULL;
	ValaSymbol* _tmp2_;
	ValaSymbol* _tmp3_;
	gboolean _tmp4_ = FALSE;
	ValaLocalVariable* _tmp5_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (collection != NULL);
	if (source_reference == NULL) {
		ValaSourceReference* _tmp0_;
		ValaSourceReference* _tmp1_;
		_tmp0_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
		_tmp1_ = _tmp0_;
		source_reference = _tmp1_;
	}
	_tmp2_ = vala_declaration_statement_get_declaration (self);
	_tmp3_ = _tmp2_;
	local = VALA_IS_LOCAL_VARIABLE (_tmp3_) ? ((ValaLocalVariable*) _tmp3_) : NULL;
	_tmp5_ = local;
	if (_tmp5_ != NULL) {
		ValaLocalVariable* _tmp6_;
		ValaExpression* _tmp7_;
		ValaExpression* _tmp8_;
		_tmp6_ = local;
		_tmp7_ = vala_variable_get_initializer ((ValaVariable*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_ != NULL;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		ValaLocalVariable* _tmp9_;
		ValaExpression* _tmp10_;
		ValaExpression* _tmp11_;
		_tmp9_ = local;
		_tmp10_ = vala_variable_get_initializer ((ValaVariable*) _tmp9_);
		_tmp11_ = _tmp10_;
		vala_code_node_get_error_types ((ValaCodeNode*) _tmp11_, collection, source_reference);
	}
}

static gboolean
vala_declaration_statement_real_check (ValaCodeNode* base,
                                       ValaCodeContext* context)
{
	ValaDeclarationStatement * self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaSymbol* _tmp4_;
	ValaSymbol* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean result;
	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_;
	if (!vala_code_node_check ((ValaCodeNode*) _tmp5_, context)) {
		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
		result = FALSE;
		return result;
	}
	_tmp6_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp7_ = _tmp6_;
	result = !_tmp7_;
	return result;
}

static void
vala_declaration_statement_real_emit (ValaCodeNode* base,
                                      ValaCodeGenerator* codegen)
{
	ValaDeclarationStatement * self;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (codegen != NULL);
	vala_code_visitor_visit_declaration_statement ((ValaCodeVisitor*) codegen, 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_;
	self = (ValaDeclarationStatement*) base;
	g_return_if_fail (collection != NULL);
	_tmp0_ = vala_declaration_statement_get_declaration (self);
	_tmp1_ = _tmp0_;
	local = VALA_IS_LOCAL_VARIABLE (_tmp1_) ? ((ValaLocalVariable*) _tmp1_) : NULL;
	_tmp2_ = local;
	if (_tmp2_ != NULL) {
		ValaArrayType* array_type = NULL;
		ValaLocalVariable* _tmp3_;
		ValaDataType* _tmp4_;
		ValaDataType* _tmp5_;
		ValaLocalVariable* _tmp6_;
		ValaExpression* _tmp7_;
		ValaExpression* _tmp8_;
		_tmp3_ = local;
		_tmp4_ = vala_variable_get_variable_type ((ValaVariable*) _tmp3_);
		_tmp5_ = _tmp4_;
		array_type = VALA_IS_ARRAY_TYPE (_tmp5_) ? ((ValaArrayType*) _tmp5_) : NULL;
		_tmp6_ = local;
		_tmp7_ = vala_variable_get_initializer ((ValaVariable*) _tmp6_);
		_tmp8_ = _tmp7_;
		if (_tmp8_ != NULL) {
			ValaLocalVariable* _tmp9_;
			ValaExpression* _tmp10_;
			ValaExpression* _tmp11_;
			ValaLocalVariable* _tmp12_;
			_tmp9_ = local;
			_tmp10_ = vala_variable_get_initializer ((ValaVariable*) _tmp9_);
			_tmp11_ = _tmp10_;
			vala_code_node_get_defined_variables ((ValaCodeNode*) _tmp11_, collection);
			_tmp12_ = local;
			vala_collection_add (collection, (ValaVariable*) _tmp12_);
		} else {
			gboolean _tmp13_ = FALSE;
			ValaArrayType* _tmp14_;
			_tmp14_ = array_type;
			if (_tmp14_ != NULL) {
				ValaArrayType* _tmp15_;
				gboolean _tmp16_;
				gboolean _tmp17_;
				_tmp15_ = array_type;
				_tmp16_ = vala_array_type_get_fixed_length (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp13_ = _tmp17_;
			} else {
				_tmp13_ = FALSE;
			}
			if (_tmp13_) {
				ValaLocalVariable* _tmp18_;
				_tmp18_ = local;
				vala_collection_add (collection, (ValaVariable*) _tmp18_);
			}
		}
	}
}

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

static void
vala_declaration_statement_class_init (ValaDeclarationStatementClass * klass,
                                       gpointer klass_data)
{
	vala_declaration_statement_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_declaration_statement_finalize;
	g_type_class_adjust_private_offset (klass, &ValaDeclarationStatement_private_offset);
	((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)->get_error_types = (void (*) (ValaCodeNode*, ValaCollection*, ValaSourceReference*)) vala_declaration_statement_real_get_error_types;
	((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,
                                                          gpointer iface_data)
{
	vala_declaration_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
}

static void
vala_declaration_statement_instance_init (ValaDeclarationStatement * self,
                                          gpointer klass)
{
	self->priv = vala_declaration_statement_get_instance_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.
 */
static GType
vala_declaration_statement_get_type_once (void)
{
	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);
	ValaDeclarationStatement_private_offset = g_type_add_instance_private (vala_declaration_statement_type_id, sizeof (ValaDeclarationStatementPrivate));
	return vala_declaration_statement_type_id;
}

GType
vala_declaration_statement_get_type (void)
{
	static volatile gsize vala_declaration_statement_type_id__once = 0;
	if (g_once_init_enter (&vala_declaration_statement_type_id__once)) {
		GType vala_declaration_statement_type_id;
		vala_declaration_statement_type_id = vala_declaration_statement_get_type_once ();
		g_once_init_leave (&vala_declaration_statement_type_id__once, vala_declaration_statement_type_id);
	}
	return vala_declaration_statement_type_id__once;
}

