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

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

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

struct _ValaEnumValueTypePrivate {
	ValaMethod* to_string_method;
};

static gint ValaEnumValueType_private_offset;
static gpointer vala_enum_value_type_parent_class = NULL;

static ValaDataType* vala_enum_value_type_real_copy (ValaDataType* base);
static ValaSymbol* vala_enum_value_type_real_get_member (ValaDataType* base,
                                                  const gchar* member_name);
static void vala_enum_value_type_finalize (ValaCodeNode * obj);
static GType vala_enum_value_type_get_type_once (void);

static inline gpointer
vala_enum_value_type_get_instance_private (ValaEnumValueType* self)
{
	return G_STRUCT_MEMBER_P (self, ValaEnumValueType_private_offset);
}

ValaEnumValueType*
vala_enum_value_type_construct (GType object_type,
                                ValaEnum* type_symbol,
                                ValaSourceReference* source_reference)
{
	ValaEnumValueType* self = NULL;
	g_return_val_if_fail (type_symbol != NULL, NULL);
	self = (ValaEnumValueType*) vala_value_type_construct (object_type, (ValaTypeSymbol*) type_symbol, source_reference);
	return self;
}

ValaEnumValueType*
vala_enum_value_type_new (ValaEnum* type_symbol,
                          ValaSourceReference* source_reference)
{
	return vala_enum_value_type_construct (VALA_TYPE_ENUM_VALUE_TYPE, type_symbol, source_reference);
}

static ValaDataType*
vala_enum_value_type_real_copy (ValaDataType* base)
{
	ValaEnumValueType * self;
	ValaEnumValueType* _result_ = NULL;
	ValaTypeSymbol* _tmp0_;
	ValaTypeSymbol* _tmp1_;
	ValaSourceReference* _tmp2_;
	ValaSourceReference* _tmp3_;
	ValaEnumValueType* _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	ValaDataType* result;
	self = (ValaEnumValueType*) base;
	_tmp0_ = vala_data_type_get_type_symbol ((ValaDataType*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
	_tmp3_ = _tmp2_;
	_tmp4_ = vala_enum_value_type_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, VALA_TYPE_ENUM, ValaEnum), _tmp3_);
	_result_ = _tmp4_;
	_tmp5_ = vala_data_type_get_value_owned ((ValaDataType*) self);
	_tmp6_ = _tmp5_;
	vala_data_type_set_value_owned ((ValaDataType*) _result_, _tmp6_);
	_tmp7_ = vala_data_type_get_nullable ((ValaDataType*) self);
	_tmp8_ = _tmp7_;
	vala_data_type_set_nullable ((ValaDataType*) _result_, _tmp8_);
	result = (ValaDataType*) _result_;
	return result;
}

ValaMethod*
vala_enum_value_type_get_to_string_method (ValaEnumValueType* self)
{
	ValaMethod* _tmp0_;
	ValaMethod* _tmp45_;
	ValaMethod* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->to_string_method;
	if (_tmp0_ == NULL) {
		ValaDataType* string_type = NULL;
		ValaCodeContext* _tmp1_;
		ValaCodeContext* _tmp2_;
		ValaSemanticAnalyzer* _tmp3_;
		ValaSemanticAnalyzer* _tmp4_;
		ValaDataType* _tmp5_;
		ValaDataType* _tmp6_;
		ValaDataType* _tmp7_;
		ValaDataType* _tmp8_;
		ValaDataType* _tmp9_;
		ValaSourceReference* _tmp10_;
		ValaSourceReference* _tmp11_;
		ValaMethod* _tmp12_;
		ValaMethod* _tmp13_;
		ValaMethod* _tmp14_;
		ValaCodeContext* _tmp15_;
		ValaCodeContext* _tmp16_;
		ValaProfile _tmp17_;
		ValaProfile _tmp18_;
		gboolean _tmp19_;
		ValaMethod* _tmp22_;
		ValaTypeSymbol* _tmp23_;
		ValaTypeSymbol* _tmp24_;
		ValaScope* _tmp25_;
		ValaScope* _tmp26_;
		ValaMethod* _tmp27_;
		ValaDataType* _tmp28_;
		ValaDataType* _tmp29_;
		ValaSourceReference* _tmp30_;
		ValaSourceReference* _tmp31_;
		ValaParameter* _tmp32_;
		ValaParameter* _tmp33_;
		ValaMethod* _tmp34_;
		ValaScope* _tmp35_;
		ValaScope* _tmp36_;
		ValaMethod* _tmp37_;
		ValaParameter* _tmp38_;
		ValaParameter* _tmp39_;
		const gchar* _tmp40_;
		const gchar* _tmp41_;
		ValaMethod* _tmp42_;
		ValaParameter* _tmp43_;
		ValaParameter* _tmp44_;
		_tmp1_ = vala_code_context_get ();
		_tmp2_ = _tmp1_;
		_tmp3_ = vala_code_context_get_analyzer (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = _tmp4_->string_type;
		_tmp6_ = vala_data_type_copy (_tmp5_);
		_tmp7_ = _tmp6_;
		_vala_code_context_unref0 (_tmp2_);
		string_type = _tmp7_;
		_tmp8_ = string_type;
		vala_data_type_set_value_owned (_tmp8_, FALSE);
		_tmp9_ = string_type;
		_tmp10_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
		_tmp11_ = _tmp10_;
		_tmp12_ = vala_method_new ("to_string", _tmp9_, _tmp11_, NULL);
		_vala_code_node_unref0 (self->priv->to_string_method);
		self->priv->to_string_method = _tmp12_;
		_tmp13_ = self->priv->to_string_method;
		vala_symbol_set_access ((ValaSymbol*) _tmp13_, VALA_SYMBOL_ACCESSIBILITY_PUBLIC);
		_tmp14_ = self->priv->to_string_method;
		vala_symbol_set_is_extern ((ValaSymbol*) _tmp14_, TRUE);
		_tmp15_ = vala_code_context_get ();
		_tmp16_ = _tmp15_;
		_tmp17_ = vala_code_context_get_profile (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = _tmp18_ == VALA_PROFILE_POSIX;
		_vala_code_context_unref0 (_tmp16_);
		if (_tmp19_) {
			ValaMethod* _tmp20_;
			_tmp20_ = self->priv->to_string_method;
			vala_code_node_set_attribute_string ((ValaCodeNode*) _tmp20_, "CCode", "cheader_filename", "stdlib.h", NULL);
		} else {
			ValaMethod* _tmp21_;
			_tmp21_ = self->priv->to_string_method;
			vala_code_node_set_attribute_string ((ValaCodeNode*) _tmp21_, "CCode", "cheader_filename", "glib-object.h", NULL);
		}
		_tmp22_ = self->priv->to_string_method;
		_tmp23_ = vala_data_type_get_type_symbol ((ValaDataType*) self);
		_tmp24_ = _tmp23_;
		_tmp25_ = vala_symbol_get_scope ((ValaSymbol*) _tmp24_);
		_tmp26_ = _tmp25_;
		vala_symbol_set_owner ((ValaSymbol*) _tmp22_, _tmp26_);
		_tmp27_ = self->priv->to_string_method;
		_tmp28_ = vala_data_type_copy ((ValaDataType*) self);
		_tmp29_ = _tmp28_;
		_tmp30_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
		_tmp31_ = _tmp30_;
		_tmp32_ = vala_parameter_new ("this", _tmp29_, _tmp31_);
		_tmp33_ = _tmp32_;
		vala_method_set_this_parameter (_tmp27_, _tmp33_);
		_vala_code_node_unref0 (_tmp33_);
		_vala_code_node_unref0 (_tmp29_);
		_tmp34_ = self->priv->to_string_method;
		_tmp35_ = vala_symbol_get_scope ((ValaSymbol*) _tmp34_);
		_tmp36_ = _tmp35_;
		_tmp37_ = self->priv->to_string_method;
		_tmp38_ = vala_method_get_this_parameter (_tmp37_);
		_tmp39_ = _tmp38_;
		_tmp40_ = vala_symbol_get_name ((ValaSymbol*) _tmp39_);
		_tmp41_ = _tmp40_;
		_tmp42_ = self->priv->to_string_method;
		_tmp43_ = vala_method_get_this_parameter (_tmp42_);
		_tmp44_ = _tmp43_;
		vala_scope_add (_tmp36_, _tmp41_, (ValaSymbol*) _tmp44_);
		_vala_code_node_unref0 (string_type);
	}
	_tmp45_ = self->priv->to_string_method;
	result = _tmp45_;
	return result;
}

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

static ValaSymbol*
vala_enum_value_type_real_get_member (ValaDataType* base,
                                      const gchar* member_name)
{
	ValaEnumValueType * self;
	ValaSymbol* _result_ = NULL;
	ValaSymbol* _tmp0_;
	gboolean _tmp1_ = FALSE;
	ValaSymbol* _tmp2_;
	ValaSymbol* result;
	self = (ValaEnumValueType*) base;
	g_return_val_if_fail (member_name != NULL, NULL);
	_tmp0_ = VALA_DATA_TYPE_CLASS (vala_enum_value_type_parent_class)->get_member ((ValaDataType*) G_TYPE_CHECK_INSTANCE_CAST (self, VALA_TYPE_VALUE_TYPE, ValaValueType), member_name);
	_result_ = _tmp0_;
	_tmp2_ = _result_;
	if (_tmp2_ == NULL) {
		_tmp1_ = g_strcmp0 (member_name, "to_string") == 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		ValaMethod* _tmp3_;
		ValaSymbol* _tmp4_;
		_tmp3_ = vala_enum_value_type_get_to_string_method (self);
		_tmp4_ = _vala_code_node_ref0 ((ValaSymbol*) _tmp3_);
		result = _tmp4_;
		_vala_code_node_unref0 (_result_);
		return result;
	}
	result = _result_;
	return result;
}

static void
vala_enum_value_type_class_init (ValaEnumValueTypeClass * klass,
                                 gpointer klass_data)
{
	vala_enum_value_type_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_enum_value_type_finalize;
	g_type_class_adjust_private_offset (klass, &ValaEnumValueType_private_offset);
	((ValaDataTypeClass *) klass)->copy = (ValaDataType* (*) (ValaDataType*)) vala_enum_value_type_real_copy;
	((ValaDataTypeClass *) klass)->get_member = (ValaSymbol* (*) (ValaDataType*, const gchar*)) vala_enum_value_type_real_get_member;
}

static void
vala_enum_value_type_instance_init (ValaEnumValueType * self,
                                    gpointer klass)
{
	self->priv = vala_enum_value_type_get_instance_private (self);
}

static void
vala_enum_value_type_finalize (ValaCodeNode * obj)
{
	ValaEnumValueType * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_ENUM_VALUE_TYPE, ValaEnumValueType);
	_vala_code_node_unref0 (self->priv->to_string_method);
	VALA_CODE_NODE_CLASS (vala_enum_value_type_parent_class)->finalize (obj);
}

/**
 * An enum value type.
 */
static GType
vala_enum_value_type_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValaEnumValueTypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_enum_value_type_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaEnumValueType), 0, (GInstanceInitFunc) vala_enum_value_type_instance_init, NULL };
	GType vala_enum_value_type_type_id;
	vala_enum_value_type_type_id = g_type_register_static (VALA_TYPE_VALUE_TYPE, "ValaEnumValueType", &g_define_type_info, 0);
	ValaEnumValueType_private_offset = g_type_add_instance_private (vala_enum_value_type_type_id, sizeof (ValaEnumValueTypePrivate));
	return vala_enum_value_type_type_id;
}

GType
vala_enum_value_type_get_type (void)
{
	static volatile gsize vala_enum_value_type_type_id__once = 0;
	if (g_once_init_enter (&vala_enum_value_type_type_id__once)) {
		GType vala_enum_value_type_type_id;
		vala_enum_value_type_type_id = vala_enum_value_type_get_type_once ();
		g_once_init_leave (&vala_enum_value_type_type_id__once, vala_enum_value_type_type_id);
	}
	return vala_enum_value_type_type_id__once;
}

