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

/* valamethodtype.vala
 *
 * Copyright (C) 2007-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 "vala.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>

static gpointer vala_method_type_parent_class = NULL;

static ValaDataType* vala_method_type_real_copy (ValaDataType* base);
static gboolean vala_method_type_real_compatible (ValaDataType* base,
                                           ValaDataType* target_type);
static gchar* vala_method_type_real_to_qualified_string (ValaDataType* base,
                                                  ValaScope* scope);
static ValaSymbol* vala_method_type_real_get_member (ValaDataType* base,
                                              const gchar* member_name);
static GType vala_method_type_get_type_once (void);

ValaMethod*
vala_method_type_get_method_symbol (ValaMethodType* self)
{
	ValaMethod* result;
	ValaSymbol* _tmp0_;
	ValaSymbol* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = vala_data_type_get_symbol ((ValaDataType*) self);
	_tmp1_ = _tmp0_;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, VALA_TYPE_METHOD, ValaMethod);
	return result;
}

ValaMethodType*
vala_method_type_construct (GType object_type,
                            ValaMethod* method_symbol,
                            ValaSourceReference* source_reference)
{
	ValaMethodType* self = NULL;
	g_return_val_if_fail (method_symbol != NULL, NULL);
	self = (ValaMethodType*) vala_callable_type_construct (object_type, (ValaSymbol*) method_symbol, source_reference);
	return self;
}

ValaMethodType*
vala_method_type_new (ValaMethod* method_symbol,
                      ValaSourceReference* source_reference)
{
	return vala_method_type_construct (VALA_TYPE_METHOD_TYPE, method_symbol, source_reference);
}

static ValaDataType*
vala_method_type_real_copy (ValaDataType* base)
{
	ValaMethodType * self;
	ValaMethod* _tmp0_;
	ValaMethod* _tmp1_;
	ValaSourceReference* _tmp2_;
	ValaSourceReference* _tmp3_;
	ValaMethodType* _tmp4_;
	ValaDataType* result;
	self = (ValaMethodType*) base;
	_tmp0_ = vala_method_type_get_method_symbol (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
	_tmp3_ = _tmp2_;
	_tmp4_ = vala_method_type_new (_tmp1_, _tmp3_);
	result = (ValaDataType*) _tmp4_;
	return result;
}

static gboolean
vala_method_type_real_compatible (ValaDataType* base,
                                  ValaDataType* target_type)
{
	ValaMethodType * self;
	ValaDelegateType* dt = NULL;
	ValaDelegateType* _tmp0_;
	ValaDelegateType* _tmp1_;
	ValaDelegate* _tmp2_;
	ValaDelegate* _tmp3_;
	ValaMethod* _tmp4_;
	ValaMethod* _tmp5_;
	ValaDelegateType* _tmp6_;
	gboolean result;
	self = (ValaMethodType*) base;
	g_return_val_if_fail (target_type != NULL, FALSE);
	dt = VALA_IS_DELEGATE_TYPE (target_type) ? ((ValaDelegateType*) target_type) : NULL;
	_tmp0_ = dt;
	if (_tmp0_ == NULL) {
		result = FALSE;
		return result;
	}
	_tmp1_ = dt;
	_tmp2_ = vala_delegate_type_get_delegate_symbol (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = vala_method_type_get_method_symbol (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = dt;
	result = vala_delegate_matches_method (_tmp3_, _tmp5_, (ValaDataType*) _tmp6_);
	return result;
}

static gchar*
vala_method_type_real_to_qualified_string (ValaDataType* base,
                                           ValaScope* scope)
{
	ValaMethodType * self;
	ValaMethod* _tmp0_;
	ValaMethod* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	self = (ValaMethodType*) base;
	_tmp0_ = vala_method_type_get_method_symbol (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = vala_symbol_get_full_name ((ValaSymbol*) _tmp1_);
	result = _tmp2_;
	return result;
}

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

static ValaSymbol*
vala_method_type_real_get_member (ValaDataType* base,
                                  const gchar* member_name)
{
	ValaMethodType * self;
	gboolean _tmp0_ = FALSE;
	ValaMethod* _tmp1_;
	ValaMethod* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	ValaSymbol* result;
	self = (ValaMethodType*) base;
	g_return_val_if_fail (member_name != NULL, NULL);
	_tmp1_ = vala_method_type_get_method_symbol (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = vala_method_get_coroutine (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_) {
		_tmp0_ = g_strcmp0 (member_name, "begin") == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ValaMethod* _tmp5_;
		ValaMethod* _tmp6_;
		ValaSymbol* _tmp7_;
		_tmp5_ = vala_method_type_get_method_symbol (self);
		_tmp6_ = _tmp5_;
		_tmp7_ = _vala_code_node_ref0 ((ValaSymbol*) _tmp6_);
		result = _tmp7_;
		return result;
	} else {
		gboolean _tmp8_ = FALSE;
		ValaMethod* _tmp9_;
		ValaMethod* _tmp10_;
		gboolean _tmp11_;
		gboolean _tmp12_;
		_tmp9_ = vala_method_type_get_method_symbol (self);
		_tmp10_ = _tmp9_;
		_tmp11_ = vala_method_get_coroutine (_tmp10_);
		_tmp12_ = _tmp11_;
		if (_tmp12_) {
			_tmp8_ = g_strcmp0 (member_name, "end") == 0;
		} else {
			_tmp8_ = FALSE;
		}
		if (_tmp8_) {
			ValaMethod* _tmp13_;
			ValaMethod* _tmp14_;
			ValaSymbol* _tmp15_;
			_tmp13_ = vala_method_type_get_method_symbol (self);
			_tmp14_ = _tmp13_;
			_tmp15_ = _vala_code_node_ref0 ((ValaSymbol*) _tmp14_);
			result = _tmp15_;
			return result;
		} else {
			gboolean _tmp16_ = FALSE;
			ValaMethod* _tmp17_;
			ValaMethod* _tmp18_;
			gboolean _tmp19_;
			gboolean _tmp20_;
			_tmp17_ = vala_method_type_get_method_symbol (self);
			_tmp18_ = _tmp17_;
			_tmp19_ = vala_method_get_coroutine (_tmp18_);
			_tmp20_ = _tmp19_;
			if (_tmp20_) {
				_tmp16_ = g_strcmp0 (member_name, "callback") == 0;
			} else {
				_tmp16_ = FALSE;
			}
			if (_tmp16_) {
				ValaMethod* _tmp21_;
				ValaMethod* _tmp22_;
				ValaMethod* _tmp23_;
				ValaSymbol* _tmp24_;
				_tmp21_ = vala_method_type_get_method_symbol (self);
				_tmp22_ = _tmp21_;
				_tmp23_ = vala_method_get_callback_method (_tmp22_);
				_tmp24_ = _vala_code_node_ref0 ((ValaSymbol*) _tmp23_);
				result = _tmp24_;
				return result;
			}
		}
	}
	result = NULL;
	return result;
}

static void
vala_method_type_class_init (ValaMethodTypeClass * klass,
                             gpointer klass_data)
{
	vala_method_type_parent_class = g_type_class_peek_parent (klass);
	((ValaDataTypeClass *) klass)->copy = (ValaDataType* (*) (ValaDataType*)) vala_method_type_real_copy;
	((ValaDataTypeClass *) klass)->compatible = (gboolean (*) (ValaDataType*, ValaDataType*)) vala_method_type_real_compatible;
	((ValaDataTypeClass *) klass)->to_qualified_string = (gchar* (*) (ValaDataType*, ValaScope*)) vala_method_type_real_to_qualified_string;
	((ValaDataTypeClass *) klass)->get_member = (ValaSymbol* (*) (ValaDataType*, const gchar*)) vala_method_type_real_get_member;
}

static void
vala_method_type_instance_init (ValaMethodType * self,
                                gpointer klass)
{
}

/**
 * The type of a method referencea.
 */
static GType
vala_method_type_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValaMethodTypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_method_type_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaMethodType), 0, (GInstanceInitFunc) vala_method_type_instance_init, NULL };
	GType vala_method_type_type_id;
	vala_method_type_type_id = g_type_register_static (VALA_TYPE_CALLABLE_TYPE, "ValaMethodType", &g_define_type_info, 0);
	return vala_method_type_type_id;
}

GType
vala_method_type_get_type (void)
{
	static volatile gsize vala_method_type_type_id__once = 0;
	if (g_once_init_enter (&vala_method_type_type_id__once)) {
		GType vala_method_type_type_id;
		vala_method_type_type_id = vala_method_type_get_type_once ();
		g_once_init_leave (&vala_method_type_type_id__once, vala_method_type_type_id);
	}
	return vala_method_type_type_id__once;
}

