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

/* attribute.vala
 *
 * Copyright (C) 2011 Florian Brosch
 *
 * 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:
 * 	Florian Brosch <flo.brosch@gmail.com>
 */

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

enum  {
	VALADOC_API_ATTRIBUTE_0_PROPERTY,
	VALADOC_API_ATTRIBUTE_NAME_PROPERTY,
	VALADOC_API_ATTRIBUTE_NUM_PROPERTIES
};
static GParamSpec* valadoc_api_attribute_properties[VALADOC_API_ATTRIBUTE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_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)))
#define _vala_iterator_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterator_unref (var), NULL)))
#define _g_sequence_free0(var) ((var == NULL) ? NULL : (var = (g_sequence_free (var), NULL)))
#define _valadoc_api_signature_builder_unref0(var) ((var == NULL) ? NULL : (var = (valadoc_api_signature_builder_unref (var), NULL)))

struct _ValadocApiAttributePrivate {
	ValadocApiSourceFile* file;
	gchar* _name;
};

static gint ValadocApiAttribute_private_offset;
static gpointer valadoc_api_attribute_parent_class = NULL;

static void valadoc_api_attribute_set_name (ValadocApiAttribute* self,
                                     const gchar* value);
static ValadocContentInline* valadoc_api_attribute_real_build_signature (ValadocApiItem* base);
static void _g_free0_ (gpointer var);
static void valadoc_api_attribute_finalize (GObject * obj);
static GType valadoc_api_attribute_get_type_once (void);
static void _vala_valadoc_api_attribute_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_valadoc_api_attribute_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);

static inline gpointer
valadoc_api_attribute_get_instance_private (ValadocApiAttribute* self)
{
	return G_STRUCT_MEMBER_P (self, ValadocApiAttribute_private_offset);
}

const gchar*
valadoc_api_attribute_get_name (ValadocApiAttribute* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

static void
valadoc_api_attribute_set_name (ValadocApiAttribute* self,
                                const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = valadoc_api_attribute_get_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_name);
		self->priv->_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, valadoc_api_attribute_properties[VALADOC_API_ATTRIBUTE_NAME_PROPERTY]);
	}
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

ValadocApiAttribute*
valadoc_api_attribute_construct (GType object_type,
                                 ValadocApiNode* parent,
                                 ValadocApiSourceFile* file,
                                 const gchar* name,
                                 ValaAttribute* data)
{
	ValadocApiAttribute * self = NULL;
	ValadocApiSourceFile* _tmp0_;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (file != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (data != NULL, NULL);
	self = (ValadocApiAttribute*) valadoc_api_item_construct (object_type, (ValaCodeNode*) data);
	valadoc_api_item_set_parent ((ValadocApiItem*) self, (ValadocApiItem*) parent);
	valadoc_api_attribute_set_name (self, name);
	_tmp0_ = _g_object_ref0 (file);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp0_;
	return self;
}

ValadocApiAttribute*
valadoc_api_attribute_new (ValadocApiNode* parent,
                           ValadocApiSourceFile* file,
                           const gchar* name,
                           ValaAttribute* data)
{
	return valadoc_api_attribute_construct (VALADOC_API_TYPE_ATTRIBUTE, parent, file, name, data);
}

ValadocApiSourceFile*
valadoc_api_attribute_get_source_file (ValadocApiAttribute* self)
{
	ValadocApiSourceFile* _tmp0_;
	ValadocApiSourceFile* _tmp1_;
	ValadocApiSourceFile* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->file;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static ValadocContentInline*
valadoc_api_attribute_real_build_signature (ValadocApiItem* base)
{
	ValadocApiAttribute * self;
	ValadocApiSignatureBuilder* builder = NULL;
	ValadocApiSignatureBuilder* _tmp0_;
	ValaAttribute* attr = NULL;
	ValaCodeNode* _tmp1_;
	ValaCodeNode* _tmp2_;
	GSequence* keys = NULL;
	GSequence* _tmp3_;
	gboolean _tmp20_ = FALSE;
	ValaAttribute* _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	ValadocApiSignatureBuilder* _tmp27_;
	ValadocApiSignatureBuilder* _tmp28_;
	ValaAttribute* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	GSequence* _tmp32_;
	ValadocApiSignatureBuilder* _tmp55_;
	ValadocApiSignatureBuilder* _tmp56_;
	ValadocContentRun* _tmp57_;
	ValadocContentInline* result;
	self = (ValadocApiAttribute*) base;
	_tmp0_ = valadoc_api_signature_builder_new ();
	builder = _tmp0_;
	_tmp1_ = valadoc_api_item_get_data ((ValadocApiItem*) self);
	_tmp2_ = _tmp1_;
	attr = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, VALA_TYPE_ATTRIBUTE, ValaAttribute);
	_tmp3_ = g_sequence_new (_g_free0_);
	keys = _tmp3_;
	{
		ValaIterator* _key_it = NULL;
		ValaAttribute* _tmp4_;
		ValaMap* _tmp5_;
		ValaMap* _tmp6_;
		ValaSet* _tmp7_;
		ValaSet* _tmp8_;
		ValaIterator* _tmp9_;
		ValaIterator* _tmp10_;
		_tmp4_ = attr;
		_tmp5_ = vala_attribute_get_args (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = vala_map_get_keys (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = vala_iterable_iterator ((ValaIterable*) _tmp8_);
		_tmp10_ = _tmp9_;
		_vala_iterable_unref0 (_tmp8_);
		_key_it = _tmp10_;
		while (TRUE) {
			ValaIterator* _tmp11_;
			gchar* key = NULL;
			ValaIterator* _tmp12_;
			gpointer _tmp13_;
			const gchar* _tmp14_;
			GSequence* _tmp15_;
			const gchar* _tmp16_;
			gchar* _tmp17_;
			GCompareFunc _tmp18_;
			GSequenceIter* _tmp19_;
			_tmp11_ = _key_it;
			if (!vala_iterator_next (_tmp11_)) {
				break;
			}
			_tmp12_ = _key_it;
			_tmp13_ = vala_iterator_get (_tmp12_);
			key = (gchar*) _tmp13_;
			_tmp14_ = key;
			if (g_strcmp0 (_tmp14_, "cheader_filename") == 0) {
				_g_free0 (key);
				continue;
			}
			_tmp15_ = keys;
			_tmp16_ = key;
			_tmp17_ = g_strdup (_tmp16_);
			_tmp18_ = ((GCompareFunc) g_strcmp0);
			_tmp19_ = g_sequence_insert_sorted (_tmp15_, _tmp17_, (GCompareDataFunc) _tmp18_, NULL);
			_g_free0 (key);
		}
		_vala_iterator_unref0 (_key_it);
	}
	_tmp21_ = attr;
	_tmp22_ = vala_attribute_get_name (_tmp21_);
	_tmp23_ = _tmp22_;
	if (g_strcmp0 (_tmp23_, "CCode") == 0) {
		GSequence* _tmp24_;
		_tmp24_ = keys;
		_tmp20_ = g_sequence_get_length (_tmp24_) == 0;
	} else {
		_tmp20_ = FALSE;
	}
	if (_tmp20_) {
		ValadocApiSignatureBuilder* _tmp25_;
		ValadocContentRun* _tmp26_;
		_tmp25_ = builder;
		_tmp26_ = valadoc_api_signature_builder_get (_tmp25_);
		result = (ValadocContentInline*) _tmp26_;
		_g_sequence_free0 (keys);
		_valadoc_api_signature_builder_unref0 (builder);
		return result;
	}
	_tmp27_ = builder;
	valadoc_api_signature_builder_append_attribute (_tmp27_, "[", TRUE);
	_tmp28_ = builder;
	_tmp29_ = attr;
	_tmp30_ = vala_attribute_get_name (_tmp29_);
	_tmp31_ = _tmp30_;
	valadoc_api_signature_builder_append_type_name (_tmp28_, _tmp31_, TRUE);
	_tmp32_ = keys;
	if (g_sequence_get_length (_tmp32_) > 0) {
		ValadocApiSignatureBuilder* _tmp33_;
		const gchar* separator = NULL;
		GSequenceIter* arg_iter = NULL;
		GSequence* _tmp34_;
		GSequenceIter* _tmp35_;
		ValadocApiSignatureBuilder* _tmp54_;
		_tmp33_ = builder;
		valadoc_api_signature_builder_append_attribute (_tmp33_, "(", TRUE);
		separator = "";
		_tmp34_ = keys;
		_tmp35_ = g_sequence_get_begin_iter (_tmp34_);
		arg_iter = _tmp35_;
		while (TRUE) {
			GSequenceIter* _tmp36_;
			const gchar* arg_name = NULL;
			GSequenceIter* _tmp37_;
			gconstpointer _tmp38_;
			GSequenceIter* _tmp39_;
			GSequenceIter* _tmp40_;
			const gchar* _tmp41_;
			const gchar* _tmp43_;
			_tmp36_ = arg_iter;
			if (!(!g_sequence_iter_is_end (_tmp36_))) {
				break;
			}
			_tmp37_ = arg_iter;
			_tmp38_ = g_sequence_get (_tmp37_);
			arg_name = (const gchar*) _tmp38_;
			_tmp39_ = arg_iter;
			_tmp40_ = g_sequence_iter_next (_tmp39_);
			arg_iter = _tmp40_;
			_tmp41_ = separator;
			if (g_strcmp0 (_tmp41_, "") != 0) {
				ValadocApiSignatureBuilder* _tmp42_;
				_tmp42_ = builder;
				valadoc_api_signature_builder_append_attribute (_tmp42_, ", ", TRUE);
			}
			_tmp43_ = arg_name;
			if (g_strcmp0 (_tmp43_, "cheader_filename") != 0) {
				ValadocApiSignatureBuilder* _tmp44_;
				const gchar* _tmp45_;
				ValadocApiSignatureBuilder* _tmp46_;
				ValadocApiSignatureBuilder* _tmp47_;
				ValaAttribute* _tmp48_;
				ValaMap* _tmp49_;
				ValaMap* _tmp50_;
				const gchar* _tmp51_;
				gpointer _tmp52_;
				gchar* _tmp53_;
				_tmp44_ = builder;
				_tmp45_ = arg_name;
				valadoc_api_signature_builder_append_attribute (_tmp44_, _tmp45_, TRUE);
				_tmp46_ = builder;
				valadoc_api_signature_builder_append_attribute (_tmp46_, "=", TRUE);
				_tmp47_ = builder;
				_tmp48_ = attr;
				_tmp49_ = vala_attribute_get_args (_tmp48_);
				_tmp50_ = _tmp49_;
				_tmp51_ = arg_name;
				_tmp52_ = vala_map_get (_tmp50_, _tmp51_);
				_tmp53_ = (gchar*) _tmp52_;
				valadoc_api_signature_builder_append_literal (_tmp47_, _tmp53_, TRUE);
				_g_free0 (_tmp53_);
			}
			separator = ", ";
		}
		_tmp54_ = builder;
		valadoc_api_signature_builder_append_attribute (_tmp54_, ")", TRUE);
	}
	_tmp55_ = builder;
	valadoc_api_signature_builder_append_attribute (_tmp55_, "]", TRUE);
	_tmp56_ = builder;
	_tmp57_ = valadoc_api_signature_builder_get (_tmp56_);
	result = (ValadocContentInline*) _tmp57_;
	_g_sequence_free0 (keys);
	_valadoc_api_signature_builder_unref0 (builder);
	return result;
}

static void
valadoc_api_attribute_class_init (ValadocApiAttributeClass * klass,
                                  gpointer klass_data)
{
	valadoc_api_attribute_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ValadocApiAttribute_private_offset);
	((ValadocApiItemClass *) klass)->build_signature = (ValadocContentInline* (*) (ValadocApiItem*)) valadoc_api_attribute_real_build_signature;
	G_OBJECT_CLASS (klass)->get_property = _vala_valadoc_api_attribute_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_valadoc_api_attribute_set_property;
	G_OBJECT_CLASS (klass)->finalize = valadoc_api_attribute_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_ATTRIBUTE_NAME_PROPERTY, valadoc_api_attribute_properties[VALADOC_API_ATTRIBUTE_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
valadoc_api_attribute_instance_init (ValadocApiAttribute * self,
                                     gpointer klass)
{
	self->priv = valadoc_api_attribute_get_instance_private (self);
}

static void
valadoc_api_attribute_finalize (GObject * obj)
{
	ValadocApiAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALADOC_API_TYPE_ATTRIBUTE, ValadocApiAttribute);
	_g_object_unref0 (self->priv->file);
	_g_free0 (self->priv->_name);
	G_OBJECT_CLASS (valadoc_api_attribute_parent_class)->finalize (obj);
}

static GType
valadoc_api_attribute_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValadocApiAttributeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) valadoc_api_attribute_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValadocApiAttribute), 0, (GInstanceInitFunc) valadoc_api_attribute_instance_init, NULL };
	GType valadoc_api_attribute_type_id;
	valadoc_api_attribute_type_id = g_type_register_static (VALADOC_API_TYPE_ITEM, "ValadocApiAttribute", &g_define_type_info, 0);
	ValadocApiAttribute_private_offset = g_type_add_instance_private (valadoc_api_attribute_type_id, sizeof (ValadocApiAttributePrivate));
	return valadoc_api_attribute_type_id;
}

GType
valadoc_api_attribute_get_type (void)
{
	static volatile gsize valadoc_api_attribute_type_id__once = 0;
	if (g_once_init_enter (&valadoc_api_attribute_type_id__once)) {
		GType valadoc_api_attribute_type_id;
		valadoc_api_attribute_type_id = valadoc_api_attribute_get_type_once ();
		g_once_init_leave (&valadoc_api_attribute_type_id__once, valadoc_api_attribute_type_id);
	}
	return valadoc_api_attribute_type_id__once;
}

static void
_vala_valadoc_api_attribute_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	ValadocApiAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_API_TYPE_ATTRIBUTE, ValadocApiAttribute);
	switch (property_id) {
		case VALADOC_API_ATTRIBUTE_NAME_PROPERTY:
		g_value_set_string (value, valadoc_api_attribute_get_name (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_valadoc_api_attribute_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	ValadocApiAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_API_TYPE_ATTRIBUTE, ValadocApiAttribute);
	switch (property_id) {
		case VALADOC_API_ATTRIBUTE_NAME_PROPERTY:
		valadoc_api_attribute_set_name (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

