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

/* valaunresolvedtype.vala
 *
 * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
 *
 * 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>
 *	Raffaele Sandrini <raffaele@sandrini.ch>
 */

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

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

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

struct _ValaUnresolvedTypePrivate {
	ValaUnresolvedSymbol* _unresolved_symbol;
};

static gint ValaUnresolvedType_private_offset;
static gpointer vala_unresolved_type_parent_class = NULL;

static ValaDataType* vala_unresolved_type_real_copy (ValaDataType* base);
static gchar* vala_unresolved_type_real_to_qualified_string (ValaDataType* base,
                                                      ValaScope* scope);
static gboolean vala_unresolved_type_real_is_disposable (ValaDataType* base);
static void vala_unresolved_type_finalize (ValaCodeNode * obj);
static GType vala_unresolved_type_get_type_once (void);

static inline gpointer
vala_unresolved_type_get_instance_private (ValaUnresolvedType* self)
{
	return G_STRUCT_MEMBER_P (self, ValaUnresolvedType_private_offset);
}

ValaUnresolvedSymbol*
vala_unresolved_type_get_unresolved_symbol (ValaUnresolvedType* self)
{
	ValaUnresolvedSymbol* result;
	ValaUnresolvedSymbol* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_unresolved_symbol;
	result = _tmp0_;
	return result;
}

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

void
vala_unresolved_type_set_unresolved_symbol (ValaUnresolvedType* self,
                                            ValaUnresolvedSymbol* value)
{
	ValaUnresolvedSymbol* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_code_node_ref0 (value);
	_vala_code_node_unref0 (self->priv->_unresolved_symbol);
	self->priv->_unresolved_symbol = _tmp0_;
}

ValaUnresolvedType*
vala_unresolved_type_construct (GType object_type,
                                ValaSourceReference* source_reference)
{
	ValaUnresolvedType* self = NULL;
	self = (ValaUnresolvedType*) vala_data_type_construct (object_type);
	vala_code_node_set_source_reference ((ValaCodeNode*) self, source_reference);
	return self;
}

ValaUnresolvedType*
vala_unresolved_type_new (ValaSourceReference* source_reference)
{
	return vala_unresolved_type_construct (VALA_TYPE_UNRESOLVED_TYPE, source_reference);
}

/**
 * Creates a new type reference.
 *
 * @param symbol    unresolved type symbol
 * @param source    reference to source code
 * @return          newly created type reference
 */
ValaUnresolvedType*
vala_unresolved_type_construct_from_symbol (GType object_type,
                                            ValaUnresolvedSymbol* symbol,
                                            ValaSourceReference* source_reference)
{
	ValaUnresolvedType* self = NULL;
	g_return_val_if_fail (symbol != NULL, NULL);
	self = (ValaUnresolvedType*) vala_data_type_construct (object_type);
	vala_unresolved_type_set_unresolved_symbol (self, symbol);
	vala_code_node_set_source_reference ((ValaCodeNode*) self, source_reference);
	return self;
}

ValaUnresolvedType*
vala_unresolved_type_new_from_symbol (ValaUnresolvedSymbol* symbol,
                                      ValaSourceReference* source_reference)
{
	return vala_unresolved_type_construct_from_symbol (VALA_TYPE_UNRESOLVED_TYPE, symbol, source_reference);
}

/**
 * Creates a new type reference from a code expression.
 *
 * @param expr   member access expression
 * @return       newly created type reference
 */
ValaUnresolvedType*
vala_unresolved_type_construct_from_expression (GType object_type,
                                                ValaMemberAccess* expr)
{
	ValaUnresolvedType* self = NULL;
	ValaUnresolvedSymbol* _tmp0_;
	ValaUnresolvedSymbol* _tmp1_;
	ValaSourceReference* _tmp2_;
	ValaSourceReference* _tmp3_;
	g_return_val_if_fail (expr != NULL, NULL);
	self = (ValaUnresolvedType*) vala_data_type_construct (object_type);
	_tmp0_ = vala_unresolved_symbol_new_from_expression (expr);
	_tmp1_ = _tmp0_;
	vala_unresolved_type_set_unresolved_symbol (self, _tmp1_);
	_vala_code_node_unref0 (_tmp1_);
	_tmp2_ = vala_code_node_get_source_reference ((ValaCodeNode*) expr);
	_tmp3_ = _tmp2_;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp3_);
	vala_data_type_set_value_owned ((ValaDataType*) self, TRUE);
	{
		ValaList* _arg_list = NULL;
		ValaList* _tmp4_;
		gint _arg_size = 0;
		ValaList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _arg_index = 0;
		_tmp4_ = vala_member_access_get_type_arguments (expr);
		_arg_list = _tmp4_;
		_tmp5_ = _arg_list;
		_tmp6_ = vala_collection_get_size ((ValaCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_arg_size = _tmp7_;
		_arg_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			ValaDataType* arg = NULL;
			ValaList* _tmp10_;
			gpointer _tmp11_;
			ValaDataType* _tmp12_;
			_arg_index = _arg_index + 1;
			_tmp8_ = _arg_index;
			_tmp9_ = _arg_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _arg_list;
			_tmp11_ = vala_list_get (_tmp10_, _arg_index);
			arg = (ValaDataType*) _tmp11_;
			_tmp12_ = arg;
			vala_data_type_add_type_argument ((ValaDataType*) self, _tmp12_);
			_vala_code_node_unref0 (arg);
		}
	}
	return self;
}

ValaUnresolvedType*
vala_unresolved_type_new_from_expression (ValaMemberAccess* expr)
{
	return vala_unresolved_type_construct_from_expression (VALA_TYPE_UNRESOLVED_TYPE, expr);
}

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

static gpointer
_vala_iterable_ref0 (gpointer self)
{
	return self ? vala_iterable_ref (self) : NULL;
}

static gchar*
vala_unresolved_type_real_to_qualified_string (ValaDataType* base,
                                               ValaScope* scope)
{
	ValaUnresolvedType * self;
	gchar* s = NULL;
	ValaUnresolvedSymbol* _tmp0_;
	gchar* _tmp1_;
	ValaList* type_args = NULL;
	ValaList* _tmp2_;
	ValaList* _tmp3_;
	ValaList* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gboolean _tmp29_;
	gboolean _tmp30_;
	gchar* result;
	self = (ValaUnresolvedType*) base;
	_tmp0_ = self->priv->_unresolved_symbol;
	_tmp1_ = vala_code_node_to_string ((ValaCodeNode*) _tmp0_);
	s = _tmp1_;
	_tmp2_ = vala_data_type_get_type_arguments ((ValaDataType*) self);
	_tmp3_ = _vala_iterable_ref0 (_tmp2_);
	type_args = _tmp3_;
	_tmp4_ = type_args;
	_tmp5_ = vala_collection_get_size ((ValaCollection*) _tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_ > 0) {
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gboolean first = FALSE;
		const gchar* _tmp27_;
		gchar* _tmp28_;
		_tmp7_ = s;
		_tmp8_ = g_strconcat (_tmp7_, "<", NULL);
		_g_free0 (s);
		s = _tmp8_;
		first = TRUE;
		{
			ValaList* _type_arg_list = NULL;
			ValaList* _tmp9_;
			gint _type_arg_size = 0;
			ValaList* _tmp10_;
			gint _tmp11_;
			gint _tmp12_;
			gint _type_arg_index = 0;
			_tmp9_ = type_args;
			_type_arg_list = _tmp9_;
			_tmp10_ = _type_arg_list;
			_tmp11_ = vala_collection_get_size ((ValaCollection*) _tmp10_);
			_tmp12_ = _tmp11_;
			_type_arg_size = _tmp12_;
			_type_arg_index = -1;
			while (TRUE) {
				gint _tmp13_;
				gint _tmp14_;
				ValaDataType* type_arg = NULL;
				ValaList* _tmp15_;
				gpointer _tmp16_;
				ValaDataType* _tmp19_;
				const gchar* _tmp22_;
				ValaDataType* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				gchar* _tmp26_;
				_type_arg_index = _type_arg_index + 1;
				_tmp13_ = _type_arg_index;
				_tmp14_ = _type_arg_size;
				if (!(_tmp13_ < _tmp14_)) {
					break;
				}
				_tmp15_ = _type_arg_list;
				_tmp16_ = vala_list_get (_tmp15_, _type_arg_index);
				type_arg = (ValaDataType*) _tmp16_;
				if (!first) {
					const gchar* _tmp17_;
					gchar* _tmp18_;
					_tmp17_ = s;
					_tmp18_ = g_strconcat (_tmp17_, ",", NULL);
					_g_free0 (s);
					s = _tmp18_;
				} else {
					first = FALSE;
				}
				_tmp19_ = type_arg;
				if (vala_data_type_is_weak (_tmp19_)) {
					const gchar* _tmp20_;
					gchar* _tmp21_;
					_tmp20_ = s;
					_tmp21_ = g_strconcat (_tmp20_, "weak ", NULL);
					_g_free0 (s);
					s = _tmp21_;
				}
				_tmp22_ = s;
				_tmp23_ = type_arg;
				_tmp24_ = vala_data_type_to_qualified_string (_tmp23_, scope);
				_tmp25_ = _tmp24_;
				_tmp26_ = g_strconcat (_tmp22_, _tmp25_, NULL);
				_g_free0 (s);
				s = _tmp26_;
				_g_free0 (_tmp25_);
				_vala_code_node_unref0 (type_arg);
			}
		}
		_tmp27_ = s;
		_tmp28_ = g_strconcat (_tmp27_, ">", NULL);
		_g_free0 (s);
		s = _tmp28_;
	}
	_tmp29_ = vala_data_type_get_nullable ((ValaDataType*) self);
	_tmp30_ = _tmp29_;
	if (_tmp30_) {
		const gchar* _tmp31_;
		gchar* _tmp32_;
		_tmp31_ = s;
		_tmp32_ = g_strconcat (_tmp31_, "?", NULL);
		_g_free0 (s);
		s = _tmp32_;
	}
	result = s;
	_vala_iterable_unref0 (type_args);
	return result;
}

static gboolean
vala_unresolved_type_real_is_disposable (ValaDataType* base)
{
	ValaUnresolvedType * self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean result;
	self = (ValaUnresolvedType*) base;
	_tmp0_ = vala_data_type_get_value_owned ((ValaDataType*) self);
	_tmp1_ = _tmp0_;
	result = _tmp1_;
	return result;
}

static void
vala_unresolved_type_class_init (ValaUnresolvedTypeClass * klass,
                                 gpointer klass_data)
{
	vala_unresolved_type_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_unresolved_type_finalize;
	g_type_class_adjust_private_offset (klass, &ValaUnresolvedType_private_offset);
	((ValaDataTypeClass *) klass)->copy = (ValaDataType* (*) (ValaDataType*)) vala_unresolved_type_real_copy;
	((ValaDataTypeClass *) klass)->to_qualified_string = (gchar* (*) (ValaDataType*, ValaScope*)) vala_unresolved_type_real_to_qualified_string;
	((ValaDataTypeClass *) klass)->is_disposable = (gboolean (*) (ValaDataType*)) vala_unresolved_type_real_is_disposable;
}

static void
vala_unresolved_type_instance_init (ValaUnresolvedType * self,
                                    gpointer klass)
{
	self->priv = vala_unresolved_type_get_instance_private (self);
}

static void
vala_unresolved_type_finalize (ValaCodeNode * obj)
{
	ValaUnresolvedType * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_UNRESOLVED_TYPE, ValaUnresolvedType);
	_vala_code_node_unref0 (self->priv->_unresolved_symbol);
	VALA_CODE_NODE_CLASS (vala_unresolved_type_parent_class)->finalize (obj);
}

/**
 * An unresolved reference to a data type.
 */
static GType
vala_unresolved_type_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValaUnresolvedTypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_unresolved_type_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaUnresolvedType), 0, (GInstanceInitFunc) vala_unresolved_type_instance_init, NULL };
	GType vala_unresolved_type_type_id;
	vala_unresolved_type_type_id = g_type_register_static (VALA_TYPE_DATA_TYPE, "ValaUnresolvedType", &g_define_type_info, 0);
	ValaUnresolvedType_private_offset = g_type_add_instance_private (vala_unresolved_type_type_id, sizeof (ValaUnresolvedTypePrivate));
	return vala_unresolved_type_type_id;
}

GType
vala_unresolved_type_get_type (void)
{
	static volatile gsize vala_unresolved_type_type_id__once = 0;
	if (g_once_init_enter (&vala_unresolved_type_type_id__once)) {
		GType vala_unresolved_type_type_id;
		vala_unresolved_type_type_id = vala_unresolved_type_get_type_once ();
		g_once_init_leave (&vala_unresolved_type_type_id__once, vala_unresolved_type_type_id);
	}
	return vala_unresolved_type_type_id__once;
}

