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

/* valaintegertype.vala
 *
 * Copyright (C) 2008-2009  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 <stdlib.h>
#include <string.h>

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

struct _ValaIntegerTypePrivate {
	gchar* literal_value;
	gchar* literal_type_name;
};


static gpointer vala_integer_type_parent_class = NULL;

#define VALA_INTEGER_TYPE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_INTEGER_TYPE, ValaIntegerTypePrivate))
static ValaDataType* vala_integer_type_real_copy (ValaDataType* base);
static gboolean vala_integer_type_real_compatible (ValaDataType* base, ValaDataType* target_type);
static void vala_integer_type_finalize (ValaCodeNode * obj);


ValaIntegerType* vala_integer_type_construct (GType object_type, ValaStruct* type_symbol, const gchar* literal_value, const gchar* literal_type_name) {
	ValaIntegerType* self = NULL;
	ValaStruct* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_val_if_fail (type_symbol != NULL, NULL);
	_tmp0_ = type_symbol;
	self = (ValaIntegerType*) vala_value_type_construct (object_type, (ValaTypeSymbol*) _tmp0_);
	_tmp1_ = literal_value;
	_tmp2_ = g_strdup (_tmp1_);
	_g_free0 (self->priv->literal_value);
	self->priv->literal_value = _tmp2_;
	_tmp3_ = literal_type_name;
	_tmp4_ = g_strdup (_tmp3_);
	_g_free0 (self->priv->literal_type_name);
	self->priv->literal_type_name = _tmp4_;
	return self;
}


ValaIntegerType* vala_integer_type_new (ValaStruct* type_symbol, const gchar* literal_value, const gchar* literal_type_name) {
	return vala_integer_type_construct (VALA_TYPE_INTEGER_TYPE, type_symbol, literal_value, literal_type_name);
}


static ValaDataType* vala_integer_type_real_copy (ValaDataType* base) {
	ValaIntegerType * self;
	ValaDataType* result = NULL;
	ValaIntegerType* _result_ = NULL;
	ValaTypeSymbol* _tmp0_;
	ValaTypeSymbol* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	ValaIntegerType* _tmp4_;
	ValaSourceReference* _tmp5_;
	ValaSourceReference* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	self = (ValaIntegerType*) base;
	_tmp0_ = vala_value_type_get_type_symbol ((ValaValueType*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->literal_value;
	_tmp3_ = self->priv->literal_type_name;
	_tmp4_ = vala_integer_type_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, VALA_TYPE_STRUCT, ValaStruct), _tmp2_, _tmp3_);
	_result_ = _tmp4_;
	_tmp5_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
	_tmp6_ = _tmp5_;
	vala_code_node_set_source_reference ((ValaCodeNode*) _result_, _tmp6_);
	_tmp7_ = vala_data_type_get_value_owned ((ValaDataType*) self);
	_tmp8_ = _tmp7_;
	vala_data_type_set_value_owned ((ValaDataType*) _result_, _tmp8_);
	_tmp9_ = vala_data_type_get_nullable ((ValaDataType*) self);
	_tmp10_ = _tmp9_;
	vala_data_type_set_nullable ((ValaDataType*) _result_, _tmp10_);
	result = (ValaDataType*) _result_;
	return result;
}


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


static gboolean vala_integer_type_real_compatible (ValaDataType* base, ValaDataType* target_type) {
	ValaIntegerType * self;
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	ValaDataType* _tmp1_;
	ValaTypeSymbol* _tmp2_;
	ValaTypeSymbol* _tmp3_;
	ValaDataType* _tmp36_;
	gboolean _tmp37_;
	self = (ValaIntegerType*) base;
	g_return_val_if_fail (target_type != NULL, FALSE);
	_tmp1_ = target_type;
	_tmp2_ = vala_data_type_get_data_type (_tmp1_);
	_tmp3_ = _tmp2_;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, VALA_TYPE_STRUCT)) {
		const gchar* _tmp4_;
		_tmp4_ = self->priv->literal_type_name;
		_tmp0_ = g_strcmp0 (_tmp4_, "int") == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ValaStruct* target_st = NULL;
		ValaDataType* _tmp5_;
		ValaTypeSymbol* _tmp6_;
		ValaTypeSymbol* _tmp7_;
		ValaStruct* _tmp8_;
		ValaStruct* _tmp9_;
		gboolean _tmp10_;
		_tmp5_ = target_type;
		_tmp6_ = vala_data_type_get_data_type (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, VALA_TYPE_STRUCT, ValaStruct));
		target_st = _tmp8_;
		_tmp9_ = target_st;
		_tmp10_ = vala_struct_is_integer_type (_tmp9_);
		if (_tmp10_) {
			ValaAttribute* int_attr = NULL;
			ValaStruct* _tmp11_;
			ValaAttribute* _tmp12_;
			gboolean _tmp13_ = FALSE;
			gboolean _tmp14_ = FALSE;
			ValaAttribute* _tmp15_;
			_tmp11_ = target_st;
			_tmp12_ = vala_code_node_get_attribute ((ValaCodeNode*) _tmp11_, "IntegerType");
			int_attr = _tmp12_;
			_tmp15_ = int_attr;
			if (_tmp15_ != NULL) {
				ValaAttribute* _tmp16_;
				gboolean _tmp17_;
				_tmp16_ = int_attr;
				_tmp17_ = vala_attribute_has_argument (_tmp16_, "min");
				_tmp14_ = _tmp17_;
			} else {
				_tmp14_ = FALSE;
			}
			if (_tmp14_) {
				ValaAttribute* _tmp18_;
				gboolean _tmp19_;
				_tmp18_ = int_attr;
				_tmp19_ = vala_attribute_has_argument (_tmp18_, "max");
				_tmp13_ = _tmp19_;
			} else {
				_tmp13_ = FALSE;
			}
			if (_tmp13_) {
				gint val = 0;
				const gchar* _tmp20_;
				gint _tmp21_;
				gboolean _tmp22_ = FALSE;
				gint _tmp23_;
				ValaAttribute* _tmp24_;
				gint _tmp25_;
				_tmp20_ = self->priv->literal_value;
				_tmp21_ = atoi (_tmp20_);
				val = _tmp21_;
				_tmp23_ = val;
				_tmp24_ = int_attr;
				_tmp25_ = vala_attribute_get_integer (_tmp24_, "min", 0);
				if (_tmp23_ >= _tmp25_) {
					gint _tmp26_;
					ValaAttribute* _tmp27_;
					gint _tmp28_;
					_tmp26_ = val;
					_tmp27_ = int_attr;
					_tmp28_ = vala_attribute_get_integer (_tmp27_, "max", 0);
					_tmp22_ = _tmp26_ <= _tmp28_;
				} else {
					_tmp22_ = FALSE;
				}
				result = _tmp22_;
				_vala_code_node_unref0 (int_attr);
				_vala_code_node_unref0 (target_st);
				return result;
			} else {
				result = TRUE;
				_vala_code_node_unref0 (int_attr);
				_vala_code_node_unref0 (target_st);
				return result;
			}
			_vala_code_node_unref0 (int_attr);
		}
		_vala_code_node_unref0 (target_st);
	} else {
		gboolean _tmp29_ = FALSE;
		ValaDataType* _tmp30_;
		ValaTypeSymbol* _tmp31_;
		ValaTypeSymbol* _tmp32_;
		_tmp30_ = target_type;
		_tmp31_ = vala_data_type_get_data_type (_tmp30_);
		_tmp32_ = _tmp31_;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp32_, VALA_TYPE_ENUM)) {
			const gchar* _tmp33_;
			_tmp33_ = self->priv->literal_type_name;
			_tmp29_ = g_strcmp0 (_tmp33_, "int") == 0;
		} else {
			_tmp29_ = FALSE;
		}
		if (_tmp29_) {
			const gchar* _tmp34_;
			gint _tmp35_;
			_tmp34_ = self->priv->literal_value;
			_tmp35_ = atoi (_tmp34_);
			if (_tmp35_ == 0) {
				result = TRUE;
				return result;
			}
		}
	}
	_tmp36_ = target_type;
	_tmp37_ = VALA_DATA_TYPE_CLASS (vala_integer_type_parent_class)->compatible ((ValaDataType*) G_TYPE_CHECK_INSTANCE_CAST (self, VALA_TYPE_VALUE_TYPE, ValaValueType), _tmp36_);
	result = _tmp37_;
	return result;
}


static void vala_integer_type_class_init (ValaIntegerTypeClass * klass) {
	vala_integer_type_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_integer_type_finalize;
	g_type_class_add_private (klass, sizeof (ValaIntegerTypePrivate));
	((ValaDataTypeClass *) klass)->copy = (ValaDataType* (*) (ValaDataType *)) vala_integer_type_real_copy;
	((ValaDataTypeClass *) klass)->compatible = (gboolean (*) (ValaDataType *, ValaDataType*)) vala_integer_type_real_compatible;
}


static void vala_integer_type_instance_init (ValaIntegerType * self) {
	self->priv = VALA_INTEGER_TYPE_GET_PRIVATE (self);
}


static void vala_integer_type_finalize (ValaCodeNode * obj) {
	ValaIntegerType * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_INTEGER_TYPE, ValaIntegerType);
	_g_free0 (self->priv->literal_value);
	_g_free0 (self->priv->literal_type_name);
	VALA_CODE_NODE_CLASS (vala_integer_type_parent_class)->finalize (obj);
}


/**
 * An integer type.
 */
GType vala_integer_type_get_type (void) {
	static volatile gsize vala_integer_type_type_id__volatile = 0;
	if (g_once_init_enter (&vala_integer_type_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaIntegerTypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_integer_type_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaIntegerType), 0, (GInstanceInitFunc) vala_integer_type_instance_init, NULL };
		GType vala_integer_type_type_id;
		vala_integer_type_type_id = g_type_register_static (VALA_TYPE_VALUE_TYPE, "ValaIntegerType", &g_define_type_info, 0);
		g_once_init_leave (&vala_integer_type_type_id__volatile, vala_integer_type_type_id);
	}
	return vala_integer_type_type_id__volatile;
}



