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

/* valaobjecttype.vala
 *
 * Copyright (C) 2007-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 _ValaObjectTypePrivate {
	ValaObjectTypeSymbol* _type_symbol;
};


static gpointer vala_object_type_parent_class = NULL;

#define VALA_OBJECT_TYPE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_OBJECT_TYPE, ValaObjectTypePrivate))
static ValaDataType* vala_object_type_real_copy (ValaDataType* base);
static gboolean vala_object_type_real_stricter (ValaDataType* base, ValaDataType* target_type);
static gboolean vala_object_type_real_is_invokable (ValaDataType* base);
static ValaDataType* vala_object_type_real_get_return_type (ValaDataType* base);
static ValaList* vala_object_type_real_get_parameters (ValaDataType* base);
static gboolean vala_object_type_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_object_type_finalize (ValaCodeNode * obj);


ValaObjectType* vala_object_type_construct (GType object_type, ValaObjectTypeSymbol* type_symbol) {
	ValaObjectType* self = NULL;
	ValaObjectTypeSymbol* _tmp0_;
	ValaObjectTypeSymbol* _tmp1_;
	g_return_val_if_fail (type_symbol != NULL, NULL);
	self = (ValaObjectType*) vala_reference_type_construct (object_type);
	_tmp0_ = type_symbol;
	vala_object_type_set_type_symbol (self, _tmp0_);
	_tmp1_ = type_symbol;
	vala_data_type_set_data_type ((ValaDataType*) self, (ValaTypeSymbol*) _tmp1_);
	return self;
}


ValaObjectType* vala_object_type_new (ValaObjectTypeSymbol* type_symbol) {
	return vala_object_type_construct (VALA_TYPE_OBJECT_TYPE, type_symbol);
}


static ValaDataType* vala_object_type_real_copy (ValaDataType* base) {
	ValaObjectType * self;
	ValaDataType* result = NULL;
	ValaObjectType* _result_ = NULL;
	ValaObjectTypeSymbol* _tmp0_;
	ValaObjectType* _tmp1_;
	ValaObjectType* _tmp2_;
	ValaSourceReference* _tmp3_;
	ValaSourceReference* _tmp4_;
	ValaObjectType* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	ValaObjectType* _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	ValaObjectType* _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp13_;
	ValaObjectType* _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	self = (ValaObjectType*) base;
	_tmp0_ = self->priv->_type_symbol;
	_tmp1_ = vala_object_type_new (_tmp0_);
	_result_ = _tmp1_;
	_tmp2_ = _result_;
	_tmp3_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
	_tmp4_ = _tmp3_;
	vala_code_node_set_source_reference ((ValaCodeNode*) _tmp2_, _tmp4_);
	_tmp5_ = _result_;
	_tmp6_ = vala_data_type_get_value_owned ((ValaDataType*) self);
	_tmp7_ = _tmp6_;
	vala_data_type_set_value_owned ((ValaDataType*) _tmp5_, _tmp7_);
	_tmp8_ = _result_;
	_tmp9_ = vala_data_type_get_nullable ((ValaDataType*) self);
	_tmp10_ = _tmp9_;
	vala_data_type_set_nullable ((ValaDataType*) _tmp8_, _tmp10_);
	_tmp11_ = _result_;
	_tmp12_ = vala_data_type_get_is_dynamic ((ValaDataType*) self);
	_tmp13_ = _tmp12_;
	vala_data_type_set_is_dynamic ((ValaDataType*) _tmp11_, _tmp13_);
	_tmp14_ = _result_;
	_tmp15_ = vala_data_type_get_floating_reference ((ValaDataType*) self);
	_tmp16_ = _tmp15_;
	vala_data_type_set_floating_reference ((ValaDataType*) _tmp14_, _tmp16_);
	{
		ValaList* _arg_list = NULL;
		ValaList* _tmp17_;
		gint _arg_size = 0;
		ValaList* _tmp18_;
		gint _tmp19_;
		gint _tmp20_;
		gint _arg_index = 0;
		_tmp17_ = vala_data_type_get_type_arguments ((ValaDataType*) self);
		_arg_list = _tmp17_;
		_tmp18_ = _arg_list;
		_tmp19_ = vala_collection_get_size ((ValaCollection*) _tmp18_);
		_tmp20_ = _tmp19_;
		_arg_size = _tmp20_;
		_arg_index = -1;
		while (TRUE) {
			gint _tmp21_;
			gint _tmp22_;
			gint _tmp23_;
			ValaDataType* arg = NULL;
			ValaList* _tmp24_;
			gint _tmp25_;
			gpointer _tmp26_;
			ValaObjectType* _tmp27_;
			ValaDataType* _tmp28_;
			ValaDataType* _tmp29_;
			ValaDataType* _tmp30_;
			_tmp21_ = _arg_index;
			_arg_index = _tmp21_ + 1;
			_tmp22_ = _arg_index;
			_tmp23_ = _arg_size;
			if (!(_tmp22_ < _tmp23_)) {
				break;
			}
			_tmp24_ = _arg_list;
			_tmp25_ = _arg_index;
			_tmp26_ = vala_list_get (_tmp24_, _tmp25_);
			arg = (ValaDataType*) _tmp26_;
			_tmp27_ = _result_;
			_tmp28_ = arg;
			_tmp29_ = vala_data_type_copy (_tmp28_);
			_tmp30_ = _tmp29_;
			vala_data_type_add_type_argument ((ValaDataType*) _tmp27_, _tmp30_);
			_vala_code_node_unref0 (_tmp30_);
			_vala_code_node_unref0 (arg);
		}
		_vala_iterable_unref0 (_arg_list);
	}
	result = (ValaDataType*) _result_;
	return result;
}


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


static gboolean vala_object_type_real_stricter (ValaDataType* base, ValaDataType* target_type) {
	ValaObjectType * self;
	gboolean result = FALSE;
	ValaObjectType* obj_target_type = NULL;
	ValaDataType* _tmp0_;
	ValaObjectType* _tmp1_;
	ValaObjectType* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	ValaDataType* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_;
	gboolean _tmp10_;
	ValaObjectTypeSymbol* _tmp14_;
	ValaObjectType* _tmp15_;
	ValaObjectTypeSymbol* _tmp16_;
	gboolean _tmp17_;
	self = (ValaObjectType*) base;
	g_return_val_if_fail (target_type != NULL, FALSE);
	_tmp0_ = target_type;
	_tmp1_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, VALA_TYPE_OBJECT_TYPE) ? ((ValaObjectType*) _tmp0_) : NULL);
	obj_target_type = _tmp1_;
	_tmp2_ = obj_target_type;
	if (_tmp2_ == NULL) {
		result = FALSE;
		_vala_code_node_unref0 (obj_target_type);
		return result;
	}
	_tmp3_ = vala_data_type_get_value_owned ((ValaDataType*) self);
	_tmp4_ = _tmp3_;
	_tmp5_ = target_type;
	_tmp6_ = vala_data_type_get_value_owned (_tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp4_ != _tmp7_) {
		result = FALSE;
		_vala_code_node_unref0 (obj_target_type);
		return result;
	}
	_tmp9_ = vala_data_type_get_nullable ((ValaDataType*) self);
	_tmp10_ = _tmp9_;
	if (_tmp10_) {
		ValaDataType* _tmp11_;
		gboolean _tmp12_;
		gboolean _tmp13_;
		_tmp11_ = target_type;
		_tmp12_ = vala_data_type_get_nullable (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp8_ = !_tmp13_;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		result = FALSE;
		_vala_code_node_unref0 (obj_target_type);
		return result;
	}
	_tmp14_ = self->priv->_type_symbol;
	_tmp15_ = obj_target_type;
	_tmp16_ = _tmp15_->priv->_type_symbol;
	_tmp17_ = vala_typesymbol_is_subtype_of ((ValaTypeSymbol*) _tmp14_, (ValaTypeSymbol*) _tmp16_);
	result = _tmp17_;
	_vala_code_node_unref0 (obj_target_type);
	return result;
}


static gboolean vala_object_type_real_is_invokable (ValaDataType* base) {
	ValaObjectType * self;
	gboolean result = FALSE;
	ValaClass* cl = NULL;
	ValaObjectTypeSymbol* _tmp0_;
	ValaClass* _tmp1_;
	gboolean _tmp2_ = FALSE;
	ValaClass* _tmp3_;
	self = (ValaObjectType*) base;
	_tmp0_ = self->priv->_type_symbol;
	_tmp1_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, VALA_TYPE_CLASS) ? ((ValaClass*) _tmp0_) : NULL);
	cl = _tmp1_;
	_tmp3_ = cl;
	if (_tmp3_ != NULL) {
		ValaClass* _tmp4_;
		ValaCreationMethod* _tmp5_;
		ValaCreationMethod* _tmp6_;
		_tmp4_ = cl;
		_tmp5_ = vala_class_get_default_construction_method (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		result = TRUE;
		_vala_code_node_unref0 (cl);
		return result;
	} else {
		result = FALSE;
		_vala_code_node_unref0 (cl);
		return result;
	}
	_vala_code_node_unref0 (cl);
}


static ValaDataType* vala_object_type_real_get_return_type (ValaDataType* base) {
	ValaObjectType * self;
	ValaDataType* result = NULL;
	ValaClass* cl = NULL;
	ValaObjectTypeSymbol* _tmp0_;
	ValaClass* _tmp1_;
	gboolean _tmp2_ = FALSE;
	ValaClass* _tmp3_;
	self = (ValaObjectType*) base;
	_tmp0_ = self->priv->_type_symbol;
	_tmp1_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, VALA_TYPE_CLASS) ? ((ValaClass*) _tmp0_) : NULL);
	cl = _tmp1_;
	_tmp3_ = cl;
	if (_tmp3_ != NULL) {
		ValaClass* _tmp4_;
		ValaCreationMethod* _tmp5_;
		ValaCreationMethod* _tmp6_;
		_tmp4_ = cl;
		_tmp5_ = vala_class_get_default_construction_method (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ValaClass* _tmp7_;
		ValaCreationMethod* _tmp8_;
		ValaCreationMethod* _tmp9_;
		ValaDataType* _tmp10_;
		ValaDataType* _tmp11_;
		ValaDataType* _tmp12_;
		_tmp7_ = cl;
		_tmp8_ = vala_class_get_default_construction_method (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = vala_callable_get_return_type ((ValaCallable*) _tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = _vala_code_node_ref0 (_tmp11_);
		result = _tmp12_;
		_vala_code_node_unref0 (cl);
		return result;
	} else {
		result = NULL;
		_vala_code_node_unref0 (cl);
		return result;
	}
	_vala_code_node_unref0 (cl);
}


static ValaList* vala_object_type_real_get_parameters (ValaDataType* base) {
	ValaObjectType * self;
	ValaList* result = NULL;
	ValaClass* cl = NULL;
	ValaObjectTypeSymbol* _tmp0_;
	ValaClass* _tmp1_;
	gboolean _tmp2_ = FALSE;
	ValaClass* _tmp3_;
	self = (ValaObjectType*) base;
	_tmp0_ = self->priv->_type_symbol;
	_tmp1_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, VALA_TYPE_CLASS) ? ((ValaClass*) _tmp0_) : NULL);
	cl = _tmp1_;
	_tmp3_ = cl;
	if (_tmp3_ != NULL) {
		ValaClass* _tmp4_;
		ValaCreationMethod* _tmp5_;
		ValaCreationMethod* _tmp6_;
		_tmp4_ = cl;
		_tmp5_ = vala_class_get_default_construction_method (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ValaClass* _tmp7_;
		ValaCreationMethod* _tmp8_;
		ValaCreationMethod* _tmp9_;
		ValaList* _tmp10_;
		_tmp7_ = cl;
		_tmp8_ = vala_class_get_default_construction_method (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = vala_callable_get_parameters ((ValaCallable*) _tmp9_);
		result = _tmp10_;
		_vala_code_node_unref0 (cl);
		return result;
	} else {
		result = NULL;
		_vala_code_node_unref0 (cl);
		return result;
	}
	_vala_code_node_unref0 (cl);
}


static gboolean vala_object_type_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaObjectType * self;
	gboolean result = FALSE;
	ValaObjectTypeSymbol* _tmp0_;
	ValaCodeContext* _tmp1_;
	gboolean _tmp2_;
	gint n_type_args = 0;
	ValaList* _tmp3_;
	ValaList* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gboolean _tmp8_ = FALSE;
	gint _tmp9_;
	self = (ValaObjectType*) base;
	g_return_val_if_fail (context != NULL, FALSE);
	_tmp0_ = self->priv->_type_symbol;
	_tmp1_ = context;
	_tmp2_ = vala_code_node_check ((ValaCodeNode*) _tmp0_, _tmp1_);
	if (!_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp3_ = vala_data_type_get_type_arguments ((ValaDataType*) self);
	_tmp4_ = _tmp3_;
	_tmp5_ = vala_collection_get_size ((ValaCollection*) _tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_;
	_vala_iterable_unref0 (_tmp4_);
	n_type_args = _tmp7_;
	_tmp9_ = n_type_args;
	if (_tmp9_ > 0) {
		gint _tmp10_;
		ValaObjectTypeSymbol* _tmp11_;
		ValaList* _tmp12_;
		ValaList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		_tmp10_ = n_type_args;
		_tmp11_ = self->priv->_type_symbol;
		_tmp12_ = vala_object_type_symbol_get_type_parameters (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = vala_collection_get_size ((ValaCollection*) _tmp13_);
		_tmp15_ = _tmp14_;
		_tmp8_ = _tmp10_ < _tmp15_;
		_vala_iterable_unref0 (_tmp13_);
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		ValaSourceReference* _tmp16_;
		ValaSourceReference* _tmp17_;
		_tmp16_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
		_tmp17_ = _tmp16_;
		vala_report_error (_tmp17_, "too few type arguments");
		result = FALSE;
		return result;
	} else {
		gboolean _tmp18_ = FALSE;
		gint _tmp19_;
		_tmp19_ = n_type_args;
		if (_tmp19_ > 0) {
			gint _tmp20_;
			ValaObjectTypeSymbol* _tmp21_;
			ValaList* _tmp22_;
			ValaList* _tmp23_;
			gint _tmp24_;
			gint _tmp25_;
			_tmp20_ = n_type_args;
			_tmp21_ = self->priv->_type_symbol;
			_tmp22_ = vala_object_type_symbol_get_type_parameters (_tmp21_);
			_tmp23_ = _tmp22_;
			_tmp24_ = vala_collection_get_size ((ValaCollection*) _tmp23_);
			_tmp25_ = _tmp24_;
			_tmp18_ = _tmp20_ > _tmp25_;
			_vala_iterable_unref0 (_tmp23_);
		} else {
			_tmp18_ = FALSE;
		}
		if (_tmp18_) {
			ValaSourceReference* _tmp26_;
			ValaSourceReference* _tmp27_;
			_tmp26_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
			_tmp27_ = _tmp26_;
			vala_report_error (_tmp27_, "too many type arguments");
			result = FALSE;
			return result;
		}
	}
	{
		ValaList* _type_list = NULL;
		ValaList* _tmp28_;
		gint _type_size = 0;
		ValaList* _tmp29_;
		gint _tmp30_;
		gint _tmp31_;
		gint _type_index = 0;
		_tmp28_ = vala_data_type_get_type_arguments ((ValaDataType*) self);
		_type_list = _tmp28_;
		_tmp29_ = _type_list;
		_tmp30_ = vala_collection_get_size ((ValaCollection*) _tmp29_);
		_tmp31_ = _tmp30_;
		_type_size = _tmp31_;
		_type_index = -1;
		while (TRUE) {
			gint _tmp32_;
			gint _tmp33_;
			gint _tmp34_;
			ValaDataType* type = NULL;
			ValaList* _tmp35_;
			gint _tmp36_;
			gpointer _tmp37_;
			ValaDataType* _tmp38_;
			ValaCodeContext* _tmp39_;
			gboolean _tmp40_;
			_tmp32_ = _type_index;
			_type_index = _tmp32_ + 1;
			_tmp33_ = _type_index;
			_tmp34_ = _type_size;
			if (!(_tmp33_ < _tmp34_)) {
				break;
			}
			_tmp35_ = _type_list;
			_tmp36_ = _type_index;
			_tmp37_ = vala_list_get (_tmp35_, _tmp36_);
			type = (ValaDataType*) _tmp37_;
			_tmp38_ = type;
			_tmp39_ = context;
			_tmp40_ = vala_code_node_check ((ValaCodeNode*) _tmp38_, _tmp39_);
			if (!_tmp40_) {
				result = FALSE;
				_vala_code_node_unref0 (type);
				_vala_iterable_unref0 (_type_list);
				return result;
			}
			_vala_code_node_unref0 (type);
		}
		_vala_iterable_unref0 (_type_list);
	}
	result = TRUE;
	return result;
}


ValaObjectTypeSymbol* vala_object_type_get_type_symbol (ValaObjectType* self) {
	ValaObjectTypeSymbol* result;
	ValaObjectTypeSymbol* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_type_symbol;
	result = _tmp0_;
	return result;
}


void vala_object_type_set_type_symbol (ValaObjectType* self, ValaObjectTypeSymbol* value) {
	ValaObjectTypeSymbol* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_type_symbol = _tmp0_;
}


static void vala_object_type_class_init (ValaObjectTypeClass * klass) {
	vala_object_type_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_object_type_finalize;
	g_type_class_add_private (klass, sizeof (ValaObjectTypePrivate));
	((ValaDataTypeClass *) klass)->copy = (ValaDataType* (*) (ValaDataType *)) vala_object_type_real_copy;
	((ValaDataTypeClass *) klass)->stricter = (gboolean (*) (ValaDataType *, ValaDataType*)) vala_object_type_real_stricter;
	((ValaDataTypeClass *) klass)->is_invokable = (gboolean (*) (ValaDataType *)) vala_object_type_real_is_invokable;
	((ValaDataTypeClass *) klass)->get_return_type = (ValaDataType* (*) (ValaDataType *)) vala_object_type_real_get_return_type;
	((ValaDataTypeClass *) klass)->get_parameters = (ValaList* (*) (ValaDataType *)) vala_object_type_real_get_parameters;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_object_type_real_check;
}


static void vala_object_type_instance_init (ValaObjectType * self) {
	self->priv = VALA_OBJECT_TYPE_GET_PRIVATE (self);
}


static void vala_object_type_finalize (ValaCodeNode * obj) {
	ValaObjectType * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_OBJECT_TYPE, ValaObjectType);
	VALA_CODE_NODE_CLASS (vala_object_type_parent_class)->finalize (obj);
}


/**
 * A class type.
 */
GType vala_object_type_get_type (void) {
	static volatile gsize vala_object_type_type_id__volatile = 0;
	if (g_once_init_enter (&vala_object_type_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaObjectTypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_object_type_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaObjectType), 0, (GInstanceInitFunc) vala_object_type_instance_init, NULL };
		GType vala_object_type_type_id;
		vala_object_type_type_id = g_type_register_static (VALA_TYPE_REFERENCE_TYPE, "ValaObjectType", &g_define_type_info, 0);
		g_once_init_leave (&vala_object_type_type_id__volatile, vala_object_type_type_id);
	}
	return vala_object_type_type_id__volatile;
}



