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

/* valaphifunction.vala
 *
 * Copyright (C) 2008  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 <valagee.h>
#include <gobject/gvaluecollector.h>


#define VALA_TYPE_PHI_FUNCTION (vala_phi_function_get_type ())
#define VALA_PHI_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_PHI_FUNCTION, ValaPhiFunction))
#define VALA_PHI_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_PHI_FUNCTION, ValaPhiFunctionClass))
#define VALA_IS_PHI_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_PHI_FUNCTION))
#define VALA_IS_PHI_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_PHI_FUNCTION))
#define VALA_PHI_FUNCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_PHI_FUNCTION, ValaPhiFunctionClass))

typedef struct _ValaPhiFunction ValaPhiFunction;
typedef struct _ValaPhiFunctionClass ValaPhiFunctionClass;
typedef struct _ValaPhiFunctionPrivate ValaPhiFunctionPrivate;

#define VALA_TYPE_CODE_NODE (vala_code_node_get_type ())
#define VALA_CODE_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_CODE_NODE, ValaCodeNode))
#define VALA_CODE_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_CODE_NODE, ValaCodeNodeClass))
#define VALA_IS_CODE_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_CODE_NODE))
#define VALA_IS_CODE_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_CODE_NODE))
#define VALA_CODE_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_CODE_NODE, ValaCodeNodeClass))

typedef struct _ValaCodeNode ValaCodeNode;
typedef struct _ValaCodeNodeClass ValaCodeNodeClass;

#define VALA_TYPE_SYMBOL (vala_symbol_get_type ())
#define VALA_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_SYMBOL, ValaSymbol))
#define VALA_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_SYMBOL, ValaSymbolClass))
#define VALA_IS_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_SYMBOL))
#define VALA_IS_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_SYMBOL))
#define VALA_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_SYMBOL, ValaSymbolClass))

typedef struct _ValaSymbol ValaSymbol;
typedef struct _ValaSymbolClass ValaSymbolClass;

#define VALA_TYPE_VARIABLE (vala_variable_get_type ())
#define VALA_VARIABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_VARIABLE, ValaVariable))
#define VALA_VARIABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_VARIABLE, ValaVariableClass))
#define VALA_IS_VARIABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_VARIABLE))
#define VALA_IS_VARIABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_VARIABLE))
#define VALA_VARIABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_VARIABLE, ValaVariableClass))

typedef struct _ValaVariable ValaVariable;
typedef struct _ValaVariableClass ValaVariableClass;
#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)))
typedef struct _ValaParamSpecPhiFunction ValaParamSpecPhiFunction;

struct _ValaPhiFunction {
	GTypeInstance parent_instance;
	volatile int ref_count;
	ValaPhiFunctionPrivate * priv;
};

struct _ValaPhiFunctionClass {
	GTypeClass parent_class;
	void (*finalize) (ValaPhiFunction *self);
};

struct _ValaPhiFunctionPrivate {
	ValaVariable* _original_variable;
	ValaList* _operands;
};

struct _ValaParamSpecPhiFunction {
	GParamSpec parent_instance;
};


static gpointer vala_phi_function_parent_class = NULL;

gpointer vala_phi_function_ref (gpointer instance);
void vala_phi_function_unref (gpointer instance);
GParamSpec* vala_param_spec_phi_function (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void vala_value_set_phi_function (GValue* value, gpointer v_object);
void vala_value_take_phi_function (GValue* value, gpointer v_object);
gpointer vala_value_get_phi_function (const GValue* value);
GType vala_phi_function_get_type (void) G_GNUC_CONST;
gpointer vala_code_node_ref (gpointer instance);
void vala_code_node_unref (gpointer instance);
GParamSpec* vala_param_spec_code_node (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void vala_value_set_code_node (GValue* value, gpointer v_object);
void vala_value_take_code_node (GValue* value, gpointer v_object);
gpointer vala_value_get_code_node (const GValue* value);
GType vala_code_node_get_type (void) G_GNUC_CONST;
GType vala_symbol_get_type (void) G_GNUC_CONST;
GType vala_variable_get_type (void) G_GNUC_CONST;
#define VALA_PHI_FUNCTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_PHI_FUNCTION, ValaPhiFunctionPrivate))
enum  {
	VALA_PHI_FUNCTION_DUMMY_PROPERTY
};
ValaPhiFunction* vala_phi_function_new (ValaVariable* variable, gint num_of_ops);
ValaPhiFunction* vala_phi_function_construct (GType object_type, ValaVariable* variable, gint num_of_ops);
static void vala_phi_function_set_original_variable (ValaPhiFunction* self, ValaVariable* value);
static void vala_phi_function_set_operands (ValaPhiFunction* self, ValaList* value);
ValaList* vala_phi_function_get_operands (ValaPhiFunction* self);
ValaVariable* vala_phi_function_get_original_variable (ValaPhiFunction* self);
static void vala_phi_function_finalize (ValaPhiFunction * obj);


ValaPhiFunction* vala_phi_function_construct (GType object_type, ValaVariable* variable, gint num_of_ops) {
	ValaPhiFunction* self = NULL;
	ValaVariable* _tmp0_;
	GEqualFunc _tmp1_;
	ValaArrayList* _tmp2_;
	ValaArrayList* _tmp3_;
	g_return_val_if_fail (variable != NULL, NULL);
	self = (ValaPhiFunction*) g_type_create_instance (object_type);
	_tmp0_ = variable;
	vala_phi_function_set_original_variable (self, _tmp0_);
	_tmp1_ = g_direct_equal;
	_tmp2_ = vala_array_list_new (VALA_TYPE_VARIABLE, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp1_);
	_tmp3_ = _tmp2_;
	vala_phi_function_set_operands (self, (ValaList*) _tmp3_);
	_vala_iterable_unref0 (_tmp3_);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gint _tmp6_;
				gint _tmp7_;
				ValaList* _tmp8_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				_tmp6_ = i;
				_tmp7_ = num_of_ops;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = self->priv->_operands;
				vala_collection_add ((ValaCollection*) _tmp8_, G_TYPE_CHECK_INSTANCE_CAST (NULL, VALA_TYPE_VARIABLE, ValaVariable));
			}
		}
	}
	return self;
}


ValaPhiFunction* vala_phi_function_new (ValaVariable* variable, gint num_of_ops) {
	return vala_phi_function_construct (VALA_TYPE_PHI_FUNCTION, variable, num_of_ops);
}


ValaVariable* vala_phi_function_get_original_variable (ValaPhiFunction* self) {
	ValaVariable* result;
	ValaVariable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_original_variable;
	result = _tmp0_;
	return result;
}


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


static void vala_phi_function_set_original_variable (ValaPhiFunction* self, ValaVariable* value) {
	ValaVariable* _tmp0_;
	ValaVariable* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_code_node_ref0 (_tmp0_);
	_vala_code_node_unref0 (self->priv->_original_variable);
	self->priv->_original_variable = _tmp1_;
}


ValaList* vala_phi_function_get_operands (ValaPhiFunction* self) {
	ValaList* result;
	ValaList* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_operands;
	result = _tmp0_;
	return result;
}


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


static void vala_phi_function_set_operands (ValaPhiFunction* self, ValaList* value) {
	ValaList* _tmp0_;
	ValaList* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_iterable_ref0 (_tmp0_);
	_vala_iterable_unref0 (self->priv->_operands);
	self->priv->_operands = _tmp1_;
}


static void vala_value_phi_function_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void vala_value_phi_function_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		vala_phi_function_unref (value->data[0].v_pointer);
	}
}


static void vala_value_phi_function_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = vala_phi_function_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer vala_value_phi_function_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* vala_value_phi_function_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		ValaPhiFunction * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = vala_phi_function_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* vala_value_phi_function_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	ValaPhiFunction ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = vala_phi_function_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* vala_param_spec_phi_function (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ValaParamSpecPhiFunction* spec;
	g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_PHI_FUNCTION), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer vala_value_get_phi_function (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_PHI_FUNCTION), NULL);
	return value->data[0].v_pointer;
}


void vala_value_set_phi_function (GValue* value, gpointer v_object) {
	ValaPhiFunction * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_PHI_FUNCTION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_PHI_FUNCTION));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		vala_phi_function_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		vala_phi_function_unref (old);
	}
}


void vala_value_take_phi_function (GValue* value, gpointer v_object) {
	ValaPhiFunction * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_PHI_FUNCTION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_PHI_FUNCTION));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		vala_phi_function_unref (old);
	}
}


static void vala_phi_function_class_init (ValaPhiFunctionClass * klass) {
	vala_phi_function_parent_class = g_type_class_peek_parent (klass);
	((ValaPhiFunctionClass *) klass)->finalize = vala_phi_function_finalize;
	g_type_class_add_private (klass, sizeof (ValaPhiFunctionPrivate));
}


static void vala_phi_function_instance_init (ValaPhiFunction * self) {
	self->priv = VALA_PHI_FUNCTION_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void vala_phi_function_finalize (ValaPhiFunction * obj) {
	ValaPhiFunction * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_PHI_FUNCTION, ValaPhiFunction);
	g_signal_handlers_destroy (self);
	_vala_code_node_unref0 (self->priv->_original_variable);
	_vala_iterable_unref0 (self->priv->_operands);
}


GType vala_phi_function_get_type (void) {
	static volatile gsize vala_phi_function_type_id__volatile = 0;
	if (g_once_init_enter (&vala_phi_function_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { vala_value_phi_function_init, vala_value_phi_function_free_value, vala_value_phi_function_copy_value, vala_value_phi_function_peek_pointer, "p", vala_value_phi_function_collect_value, "p", vala_value_phi_function_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (ValaPhiFunctionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_phi_function_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaPhiFunction), 0, (GInstanceInitFunc) vala_phi_function_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType vala_phi_function_type_id;
		vala_phi_function_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaPhiFunction", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&vala_phi_function_type_id__volatile, vala_phi_function_type_id);
	}
	return vala_phi_function_type_id__volatile;
}


gpointer vala_phi_function_ref (gpointer instance) {
	ValaPhiFunction * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void vala_phi_function_unref (gpointer instance) {
	ValaPhiFunction * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		VALA_PHI_FUNCTION_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



