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

/* valacallabletype.vala
 *
 * Copyright (C) 2017  Rico Tzschichholz
 *
 * 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:
 * 	Rico Tzschichholz <ricotz@ubuntu.com>
 */

#include <glib.h>
#include <glib-object.h>
#include "vala.h"
#include <stdlib.h>
#include <string.h>
#include <valagee.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)))
#define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))


static gpointer vala_callable_type_parent_class = NULL;

static gchar* vala_callable_type_real_to_prototype_string (ValaDataType* base, const gchar* override_name);


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


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


static gchar* vala_callable_type_real_to_prototype_string (ValaDataType* base, const gchar* override_name) {
	ValaCallableType * self;
	gchar* result = NULL;
	GString* builder = NULL;
	GString* _tmp0_;
	ValaDataType* return_type = NULL;
	ValaDataType* _tmp1_;
	ValaDataType* _tmp2_;
	gboolean _tmp3_;
	GString* _tmp5_;
	ValaDataType* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GString* _tmp9_;
	gchar* _tmp10_ = NULL;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	GString* _tmp14_;
	GString* _tmp15_;
	GString* _tmp16_;
	gint i = 0;
	ValaDelegateType* delegate_type = NULL;
	ValaDelegateType* _tmp17_;
	ValaDelegateType* _tmp18_;
	GString* _tmp97_;
	ValaList* error_types = NULL;
	ValaList* _tmp98_;
	ValaList* _tmp99_;
	gint _tmp100_;
	gint _tmp101_;
	GString* _tmp120_;
	const gchar* _tmp121_;
	gchar* _tmp122_;
	self = (ValaCallableType*) base;
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	_tmp1_ = vala_data_type_get_return_type ((ValaDataType*) self);
	return_type = _tmp1_;
	_tmp2_ = return_type;
	_tmp3_ = vala_data_type_is_weak (_tmp2_);
	if (_tmp3_) {
		GString* _tmp4_;
		_tmp4_ = builder;
		g_string_append (_tmp4_, "unowned ");
	}
	_tmp5_ = builder;
	_tmp6_ = return_type;
	_tmp7_ = vala_data_type_to_qualified_string (_tmp6_, NULL);
	_tmp8_ = _tmp7_;
	g_string_append (_tmp5_, _tmp8_);
	_g_free0 (_tmp8_);
	_tmp9_ = builder;
	g_string_append_c (_tmp9_, ' ');
	_tmp11_ = override_name;
	_tmp12_ = g_strdup (_tmp11_);
	_tmp10_ = _tmp12_;
	if (_tmp10_ == NULL) {
		gchar* _tmp13_;
		_tmp13_ = vala_code_node_to_string ((ValaCodeNode*) self);
		_g_free0 (_tmp10_);
		_tmp10_ = _tmp13_;
	}
	_tmp14_ = builder;
	g_string_append (_tmp14_, _tmp10_);
	_tmp15_ = builder;
	g_string_append_c (_tmp15_, ' ');
	_tmp16_ = builder;
	g_string_append_c (_tmp16_, '(');
	i = 1;
	_tmp17_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (self, VALA_TYPE_DELEGATE_TYPE) ? ((ValaDelegateType*) self) : NULL);
	delegate_type = _tmp17_;
	_tmp18_ = delegate_type;
	if (_tmp18_ != NULL) {
		ValaDelegate* delegate_symbol = NULL;
		ValaDelegateType* _tmp19_;
		ValaDelegate* _tmp20_;
		ValaDelegate* _tmp21_;
		ValaDelegate* _tmp22_;
		gboolean _tmp23_ = FALSE;
		ValaDelegate* _tmp24_;
		ValaSymbol* _tmp25_;
		ValaSymbol* _tmp26_;
		_tmp19_ = delegate_type;
		_tmp20_ = vala_delegate_type_get_delegate_symbol (_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp22_ = _vala_code_node_ref0 (_tmp21_);
		delegate_symbol = _tmp22_;
		_tmp24_ = delegate_symbol;
		_tmp25_ = vala_symbol_get_parent_symbol ((ValaSymbol*) _tmp24_);
		_tmp26_ = _tmp25_;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp26_, VALA_TYPE_SIGNAL)) {
			ValaDelegate* _tmp27_;
			ValaDataType* _tmp28_;
			ValaDataType* _tmp29_;
			_tmp27_ = delegate_symbol;
			_tmp28_ = vala_delegate_get_sender_type (_tmp27_);
			_tmp29_ = _tmp28_;
			_tmp23_ = _tmp29_ != NULL;
		} else {
			_tmp23_ = FALSE;
		}
		if (_tmp23_) {
			GString* _tmp30_;
			ValaDelegate* _tmp31_;
			ValaDataType* _tmp32_;
			ValaDataType* _tmp33_;
			gchar* _tmp34_;
			gchar* _tmp35_;
			gint _tmp36_;
			_tmp30_ = builder;
			_tmp31_ = delegate_symbol;
			_tmp32_ = vala_delegate_get_sender_type (_tmp31_);
			_tmp33_ = _tmp32_;
			_tmp34_ = vala_data_type_to_qualified_string (_tmp33_, NULL);
			_tmp35_ = _tmp34_;
			g_string_append (_tmp30_, _tmp35_);
			_g_free0 (_tmp35_);
			_tmp36_ = i;
			i = _tmp36_ + 1;
		}
		_vala_code_node_unref0 (delegate_symbol);
	}
	{
		ValaList* _param_list = NULL;
		ValaList* _tmp37_;
		gint _param_size = 0;
		ValaList* _tmp38_;
		gint _tmp39_;
		gint _tmp40_;
		gint _param_index = 0;
		_tmp37_ = vala_data_type_get_parameters ((ValaDataType*) self);
		_param_list = _tmp37_;
		_tmp38_ = _param_list;
		_tmp39_ = vala_collection_get_size ((ValaCollection*) _tmp38_);
		_tmp40_ = _tmp39_;
		_param_size = _tmp40_;
		_param_index = -1;
		while (TRUE) {
			gint _tmp41_;
			gint _tmp42_;
			gint _tmp43_;
			ValaParameter* param = NULL;
			ValaList* _tmp44_;
			gint _tmp45_;
			gpointer _tmp46_;
			gint _tmp47_;
			ValaParameter* _tmp49_;
			gboolean _tmp50_;
			gboolean _tmp51_;
			ValaParameter* _tmp53_;
			ValaParameterDirection _tmp54_;
			ValaParameterDirection _tmp55_;
			GString* _tmp80_;
			ValaParameter* _tmp81_;
			ValaDataType* _tmp82_;
			ValaDataType* _tmp83_;
			gchar* _tmp84_;
			gchar* _tmp85_;
			ValaParameter* _tmp86_;
			ValaExpression* _tmp87_;
			ValaExpression* _tmp88_;
			gint _tmp96_;
			_tmp41_ = _param_index;
			_param_index = _tmp41_ + 1;
			_tmp42_ = _param_index;
			_tmp43_ = _param_size;
			if (!(_tmp42_ < _tmp43_)) {
				break;
			}
			_tmp44_ = _param_list;
			_tmp45_ = _param_index;
			_tmp46_ = vala_list_get (_tmp44_, _tmp45_);
			param = (ValaParameter*) _tmp46_;
			_tmp47_ = i;
			if (_tmp47_ > 1) {
				GString* _tmp48_;
				_tmp48_ = builder;
				g_string_append (_tmp48_, ", ");
			}
			_tmp49_ = param;
			_tmp50_ = vala_parameter_get_ellipsis (_tmp49_);
			_tmp51_ = _tmp50_;
			if (_tmp51_) {
				GString* _tmp52_;
				_tmp52_ = builder;
				g_string_append (_tmp52_, "...");
				_vala_code_node_unref0 (param);
				continue;
			}
			_tmp53_ = param;
			_tmp54_ = vala_parameter_get_direction (_tmp53_);
			_tmp55_ = _tmp54_;
			if (_tmp55_ == VALA_PARAMETER_DIRECTION_IN) {
				ValaParameter* _tmp56_;
				ValaDataType* _tmp57_;
				ValaDataType* _tmp58_;
				gboolean _tmp59_;
				gboolean _tmp60_;
				_tmp56_ = param;
				_tmp57_ = vala_variable_get_variable_type ((ValaVariable*) _tmp56_);
				_tmp58_ = _tmp57_;
				_tmp59_ = vala_data_type_get_value_owned (_tmp58_);
				_tmp60_ = _tmp59_;
				if (_tmp60_) {
					GString* _tmp61_;
					_tmp61_ = builder;
					g_string_append (_tmp61_, "owned ");
				}
			} else {
				ValaParameter* _tmp62_;
				ValaParameterDirection _tmp63_;
				ValaParameterDirection _tmp64_;
				gboolean _tmp70_ = FALSE;
				ValaParameter* _tmp71_;
				ValaDataType* _tmp72_;
				ValaDataType* _tmp73_;
				gboolean _tmp74_;
				gboolean _tmp75_;
				_tmp62_ = param;
				_tmp63_ = vala_parameter_get_direction (_tmp62_);
				_tmp64_ = _tmp63_;
				if (_tmp64_ == VALA_PARAMETER_DIRECTION_REF) {
					GString* _tmp65_;
					_tmp65_ = builder;
					g_string_append (_tmp65_, "ref ");
				} else {
					ValaParameter* _tmp66_;
					ValaParameterDirection _tmp67_;
					ValaParameterDirection _tmp68_;
					_tmp66_ = param;
					_tmp67_ = vala_parameter_get_direction (_tmp66_);
					_tmp68_ = _tmp67_;
					if (_tmp68_ == VALA_PARAMETER_DIRECTION_OUT) {
						GString* _tmp69_;
						_tmp69_ = builder;
						g_string_append (_tmp69_, "out ");
					}
				}
				_tmp71_ = param;
				_tmp72_ = vala_variable_get_variable_type ((ValaVariable*) _tmp71_);
				_tmp73_ = _tmp72_;
				_tmp74_ = vala_data_type_get_value_owned (_tmp73_);
				_tmp75_ = _tmp74_;
				if (!_tmp75_) {
					ValaParameter* _tmp76_;
					ValaDataType* _tmp77_;
					ValaDataType* _tmp78_;
					_tmp76_ = param;
					_tmp77_ = vala_variable_get_variable_type ((ValaVariable*) _tmp76_);
					_tmp78_ = _tmp77_;
					_tmp70_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp78_, VALA_TYPE_REFERENCE_TYPE);
				} else {
					_tmp70_ = FALSE;
				}
				if (_tmp70_) {
					GString* _tmp79_;
					_tmp79_ = builder;
					g_string_append (_tmp79_, "weak ");
				}
			}
			_tmp80_ = builder;
			_tmp81_ = param;
			_tmp82_ = vala_variable_get_variable_type ((ValaVariable*) _tmp81_);
			_tmp83_ = _tmp82_;
			_tmp84_ = vala_data_type_to_qualified_string (_tmp83_, NULL);
			_tmp85_ = _tmp84_;
			g_string_append (_tmp80_, _tmp85_);
			_g_free0 (_tmp85_);
			_tmp86_ = param;
			_tmp87_ = vala_variable_get_initializer ((ValaVariable*) _tmp86_);
			_tmp88_ = _tmp87_;
			if (_tmp88_ != NULL) {
				GString* _tmp89_;
				GString* _tmp90_;
				ValaParameter* _tmp91_;
				ValaExpression* _tmp92_;
				ValaExpression* _tmp93_;
				gchar* _tmp94_;
				gchar* _tmp95_;
				_tmp89_ = builder;
				g_string_append (_tmp89_, " = ");
				_tmp90_ = builder;
				_tmp91_ = param;
				_tmp92_ = vala_variable_get_initializer ((ValaVariable*) _tmp91_);
				_tmp93_ = _tmp92_;
				_tmp94_ = vala_code_node_to_string ((ValaCodeNode*) _tmp93_);
				_tmp95_ = _tmp94_;
				g_string_append (_tmp90_, _tmp95_);
				_g_free0 (_tmp95_);
			}
			_tmp96_ = i;
			i = _tmp96_ + 1;
			_vala_code_node_unref0 (param);
		}
		_vala_iterable_unref0 (_param_list);
	}
	_tmp97_ = builder;
	g_string_append_c (_tmp97_, ')');
	_tmp98_ = vala_code_node_get_error_types ((ValaCodeNode*) self);
	error_types = _tmp98_;
	_tmp99_ = error_types;
	_tmp100_ = vala_collection_get_size ((ValaCollection*) _tmp99_);
	_tmp101_ = _tmp100_;
	if (_tmp101_ > 0) {
		GString* _tmp102_;
		gboolean first = FALSE;
		_tmp102_ = builder;
		g_string_append (_tmp102_, " throws ");
		first = TRUE;
		{
			ValaList* _type_list = NULL;
			ValaList* _tmp103_;
			ValaList* _tmp104_;
			gint _type_size = 0;
			ValaList* _tmp105_;
			gint _tmp106_;
			gint _tmp107_;
			gint _type_index = 0;
			_tmp103_ = error_types;
			_tmp104_ = _vala_iterable_ref0 (_tmp103_);
			_type_list = _tmp104_;
			_tmp105_ = _type_list;
			_tmp106_ = vala_collection_get_size ((ValaCollection*) _tmp105_);
			_tmp107_ = _tmp106_;
			_type_size = _tmp107_;
			_type_index = -1;
			while (TRUE) {
				gint _tmp108_;
				gint _tmp109_;
				gint _tmp110_;
				ValaDataType* type = NULL;
				ValaList* _tmp111_;
				gint _tmp112_;
				gpointer _tmp113_;
				gboolean _tmp114_;
				GString* _tmp116_;
				ValaDataType* _tmp117_;
				gchar* _tmp118_;
				gchar* _tmp119_;
				_tmp108_ = _type_index;
				_type_index = _tmp108_ + 1;
				_tmp109_ = _type_index;
				_tmp110_ = _type_size;
				if (!(_tmp109_ < _tmp110_)) {
					break;
				}
				_tmp111_ = _type_list;
				_tmp112_ = _type_index;
				_tmp113_ = vala_list_get (_tmp111_, _tmp112_);
				type = (ValaDataType*) _tmp113_;
				_tmp114_ = first;
				if (!_tmp114_) {
					GString* _tmp115_;
					_tmp115_ = builder;
					g_string_append (_tmp115_, ", ");
				} else {
					first = FALSE;
				}
				_tmp116_ = builder;
				_tmp117_ = type;
				_tmp118_ = vala_code_node_to_string ((ValaCodeNode*) _tmp117_);
				_tmp119_ = _tmp118_;
				g_string_append (_tmp116_, _tmp119_);
				_g_free0 (_tmp119_);
				_vala_code_node_unref0 (type);
			}
			_vala_iterable_unref0 (_type_list);
		}
	}
	_tmp120_ = builder;
	_tmp121_ = _tmp120_->str;
	_tmp122_ = g_strdup (_tmp121_);
	result = _tmp122_;
	_vala_iterable_unref0 (error_types);
	_vala_code_node_unref0 (delegate_type);
	_g_free0 (_tmp10_);
	_vala_code_node_unref0 (return_type);
	_g_string_free0 (builder);
	return result;
}


ValaCallableType* vala_callable_type_construct (GType object_type) {
	ValaCallableType* self = NULL;
	self = (ValaCallableType*) vala_data_type_construct (object_type);
	return self;
}


static void vala_callable_type_class_init (ValaCallableTypeClass * klass) {
	vala_callable_type_parent_class = g_type_class_peek_parent (klass);
	((ValaDataTypeClass *) klass)->to_prototype_string = (gchar* (*) (ValaDataType *, const gchar*)) vala_callable_type_real_to_prototype_string;
}


static void vala_callable_type_instance_init (ValaCallableType * self) {
}


/**
 * A callable type, i.e. a delegate, method, or signal type.
 */
GType vala_callable_type_get_type (void) {
	static volatile gsize vala_callable_type_type_id__volatile = 0;
	if (g_once_init_enter (&vala_callable_type_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaCallableTypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_callable_type_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCallableType), 0, (GInstanceInitFunc) vala_callable_type_instance_init, NULL };
		GType vala_callable_type_type_id;
		vala_callable_type_type_id = g_type_register_static (VALA_TYPE_DATA_TYPE, "ValaCallableType", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
		g_once_init_leave (&vala_callable_type_type_id__volatile, vala_callable_type_type_id);
	}
	return vala_callable_type_type_id__volatile;
}



