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

/* token.vala
 *
 * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
 *
 * 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:
 * 	Didier 'Ptitjes Villevalois <ptitjes@free.fr>
 */

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

enum  {
	VALADOC_TOKEN_0_PROPERTY,
	VALADOC_TOKEN_IS_WORD_PROPERTY,
	VALADOC_TOKEN_IS_NUMBER_PROPERTY,
	VALADOC_TOKEN_WORD_PROPERTY,
	VALADOC_TOKEN_VALUE_PROPERTY,
	VALADOC_TOKEN_TOKEN_TYPE_PROPERTY,
	VALADOC_TOKEN_BEGIN_PROPERTY,
	VALADOC_TOKEN_END_PROPERTY,
	VALADOC_TOKEN_NUM_PROPERTIES
};
static GParamSpec* valadoc_token_properties[VALADOC_TOKEN_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_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _ValadocTokenPrivate {
	ValadocTokenType* _type;
	gchar* _word;
	ValadocSourceLocation _begin;
	ValadocSourceLocation _end;
	gchar* _value;
};


static gpointer valadoc_token_parent_class = NULL;

#define VALADOC_TOKEN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALADOC_TYPE_TOKEN, ValadocTokenPrivate))
static void valadoc_token_finalize (GObject * obj);
static void _vala_valadoc_token_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);


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


ValadocToken* valadoc_token_construct_from_type (GType object_type, ValadocTokenType* type, ValadocSourceLocation* begin, ValadocSourceLocation* end, const gchar* val) {
	ValadocToken * self = NULL;
	ValadocTokenType* _tmp0_;
	ValadocTokenType* _tmp1_;
	ValadocSourceLocation _tmp2_;
	ValadocSourceLocation _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	g_return_val_if_fail (type != NULL, NULL);
	g_return_val_if_fail (begin != NULL, NULL);
	g_return_val_if_fail (end != NULL, NULL);
	self = (ValadocToken*) g_object_new (object_type, NULL);
	_tmp0_ = type;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_type);
	self->priv->_type = _tmp1_;
	_tmp2_ = *begin;
	self->priv->_begin = _tmp2_;
	_tmp3_ = *end;
	self->priv->_end = _tmp3_;
	_tmp4_ = val;
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 (self->priv->_value);
	self->priv->_value = _tmp5_;
	return self;
}


ValadocToken* valadoc_token_new_from_type (ValadocTokenType* type, ValadocSourceLocation* begin, ValadocSourceLocation* end, const gchar* val) {
	return valadoc_token_construct_from_type (VALADOC_TYPE_TOKEN, type, begin, end, val);
}


ValadocToken* valadoc_token_construct_from_word (GType object_type, const gchar* word, ValadocSourceLocation* begin, ValadocSourceLocation* end) {
	ValadocToken * self = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	ValadocSourceLocation _tmp2_;
	ValadocSourceLocation _tmp3_;
	g_return_val_if_fail (word != NULL, NULL);
	g_return_val_if_fail (begin != NULL, NULL);
	g_return_val_if_fail (end != NULL, NULL);
	self = (ValadocToken*) g_object_new (object_type, NULL);
	_tmp0_ = word;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_word);
	self->priv->_word = _tmp1_;
	_tmp2_ = *begin;
	self->priv->_begin = _tmp2_;
	_tmp3_ = *end;
	self->priv->_end = _tmp3_;
	return self;
}


ValadocToken* valadoc_token_new_from_word (const gchar* word, ValadocSourceLocation* begin, ValadocSourceLocation* end) {
	return valadoc_token_construct_from_word (VALADOC_TYPE_TOKEN, word, begin, end);
}


gchar* valadoc_token_to_string (ValadocToken* self) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->_word;
	if (_tmp1_ == NULL) {
		ValadocTokenType* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->_type;
		_tmp3_ = valadoc_token_type_to_string (_tmp2_);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = self->priv->_word;
		_tmp5_ = g_strdup (_tmp4_);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp5_;
	}
	result = _tmp0_;
	return result;
}


gchar* valadoc_token_to_pretty_string (ValadocToken* self) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->_word;
	if (_tmp1_ == NULL) {
		ValadocTokenType* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->_type;
		_tmp3_ = valadoc_token_type_to_pretty_string (_tmp2_);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = self->priv->_word;
		_tmp5_ = g_strdup (_tmp4_);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp5_;
	}
	result = _tmp0_;
	return result;
}


gint valadoc_token_to_int (ValadocToken* self) {
	gint result = 0;
	gboolean _tmp0_;
	gboolean _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = valadoc_token_get_is_number (self);
	_tmp1_ = _tmp0_;
	_vala_assert (_tmp1_, "is_number");
	_tmp2_ = self->priv->_word;
	_tmp3_ = atoi (_tmp2_);
	result = _tmp3_;
	return result;
}


ValadocToken* valadoc_token_construct (GType object_type) {
	ValadocToken * self = NULL;
	self = (ValadocToken*) g_object_new (object_type, NULL);
	return self;
}


ValadocToken* valadoc_token_new (void) {
	return valadoc_token_construct (VALADOC_TYPE_TOKEN);
}


gboolean valadoc_token_get_is_word (ValadocToken* self) {
	gboolean result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_word;
	result = _tmp0_ != NULL;
	return result;
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	glong _tmp0_;
	gchar _tmp1_;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = index;
	_tmp1_ = ((gchar*) self)[_tmp0_];
	result = _tmp1_;
	return result;
}


gboolean valadoc_token_get_is_number (ValadocToken* self) {
	gboolean result;
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->_word;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		_tmp2_ = self->priv->_word;
		_tmp3_ = strlen (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ == 0;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	} else {
		gboolean _tmp5_ = FALSE;
		const gchar* _tmp6_;
		gchar _tmp7_;
		_tmp6_ = self->priv->_word;
		_tmp7_ = string_get (_tmp6_, (glong) 0);
		if (_tmp7_ == '0') {
			const gchar* _tmp8_;
			gint _tmp9_;
			gint _tmp10_;
			_tmp8_ = self->priv->_word;
			_tmp9_ = strlen (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp5_ = _tmp10_ > 1;
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			result = FALSE;
			return result;
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp11_ = FALSE;
			_tmp11_ = TRUE;
			while (TRUE) {
				gint _tmp13_;
				const gchar* _tmp14_;
				gint _tmp15_;
				gint _tmp16_;
				gboolean _tmp17_ = FALSE;
				const gchar* _tmp18_;
				gint _tmp19_;
				gchar _tmp20_;
				if (!_tmp11_) {
					gint _tmp12_;
					_tmp12_ = i;
					i = _tmp12_ + 1;
				}
				_tmp11_ = FALSE;
				_tmp13_ = i;
				_tmp14_ = self->priv->_word;
				_tmp15_ = strlen (_tmp14_);
				_tmp16_ = _tmp15_;
				if (!(_tmp13_ < _tmp16_)) {
					break;
				}
				_tmp18_ = self->priv->_word;
				_tmp19_ = i;
				_tmp20_ = string_get (_tmp18_, (glong) _tmp19_);
				if (_tmp20_ < '0') {
					_tmp17_ = TRUE;
				} else {
					const gchar* _tmp21_;
					gint _tmp22_;
					gchar _tmp23_;
					_tmp21_ = self->priv->_word;
					_tmp22_ = i;
					_tmp23_ = string_get (_tmp21_, (glong) _tmp22_);
					_tmp17_ = _tmp23_ > '9';
				}
				if (_tmp17_) {
					result = FALSE;
					return result;
				}
			}
		}
	}
	result = TRUE;
	return result;
}


const gchar* valadoc_token_get_word (ValadocToken* self) {
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_word;
	result = _tmp0_;
	return result;
}


const gchar* valadoc_token_get_value (ValadocToken* self) {
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_value;
	result = _tmp0_;
	return result;
}


ValadocTokenType* valadoc_token_get_token_type (ValadocToken* self) {
	ValadocTokenType* result;
	ValadocTokenType* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_type;
	result = _tmp0_;
	return result;
}


void valadoc_token_get_begin (ValadocToken* self, ValadocSourceLocation * result) {
	ValadocSourceLocation _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_begin;
	*result = _tmp0_;
	return;
}


void valadoc_token_get_end (ValadocToken* self, ValadocSourceLocation * result) {
	ValadocSourceLocation _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_end;
	*result = _tmp0_;
	return;
}


static void valadoc_token_class_init (ValadocTokenClass * klass) {
	valadoc_token_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ValadocTokenPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_valadoc_token_get_property;
	G_OBJECT_CLASS (klass)->finalize = valadoc_token_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_IS_WORD_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_IS_WORD_PROPERTY] = g_param_spec_boolean ("is-word", "is-word", "is-word", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_IS_NUMBER_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_IS_NUMBER_PROPERTY] = g_param_spec_boolean ("is-number", "is-number", "is-number", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_WORD_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_WORD_PROPERTY] = g_param_spec_string ("word", "word", "word", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_VALUE_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_VALUE_PROPERTY] = g_param_spec_string ("value", "value", "value", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_TOKEN_TYPE_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_TOKEN_TYPE_PROPERTY] = g_param_spec_object ("token-type", "token-type", "token-type", VALADOC_TYPE_TOKEN_TYPE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_BEGIN_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_BEGIN_PROPERTY] = g_param_spec_boxed ("begin", "begin", "begin", VALADOC_TYPE_SOURCE_LOCATION, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_TOKEN_END_PROPERTY, valadoc_token_properties[VALADOC_TOKEN_END_PROPERTY] = g_param_spec_boxed ("end", "end", "end", VALADOC_TYPE_SOURCE_LOCATION, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static void valadoc_token_instance_init (ValadocToken * self) {
	self->priv = VALADOC_TOKEN_GET_PRIVATE (self);
	self->priv->_type = NULL;
	self->priv->_word = NULL;
}


static void valadoc_token_finalize (GObject * obj) {
	ValadocToken * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALADOC_TYPE_TOKEN, ValadocToken);
	_g_object_unref0 (self->priv->_type);
	_g_free0 (self->priv->_word);
	_g_free0 (self->priv->_value);
	G_OBJECT_CLASS (valadoc_token_parent_class)->finalize (obj);
}


GType valadoc_token_get_type (void) {
	static volatile gsize valadoc_token_type_id__volatile = 0;
	if (g_once_init_enter (&valadoc_token_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValadocTokenClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) valadoc_token_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValadocToken), 0, (GInstanceInitFunc) valadoc_token_instance_init, NULL };
		GType valadoc_token_type_id;
		valadoc_token_type_id = g_type_register_static (G_TYPE_OBJECT, "ValadocToken", &g_define_type_info, 0);
		g_once_init_leave (&valadoc_token_type_id__volatile, valadoc_token_type_id);
	}
	return valadoc_token_type_id__volatile;
}


static void _vala_valadoc_token_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	ValadocToken * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_TYPE_TOKEN, ValadocToken);
	switch (property_id) {
		case VALADOC_TOKEN_IS_WORD_PROPERTY:
		g_value_set_boolean (value, valadoc_token_get_is_word (self));
		break;
		case VALADOC_TOKEN_IS_NUMBER_PROPERTY:
		g_value_set_boolean (value, valadoc_token_get_is_number (self));
		break;
		case VALADOC_TOKEN_WORD_PROPERTY:
		g_value_set_string (value, valadoc_token_get_word (self));
		break;
		case VALADOC_TOKEN_VALUE_PROPERTY:
		g_value_set_string (value, valadoc_token_get_value (self));
		break;
		case VALADOC_TOKEN_TOKEN_TYPE_PROPERTY:
		g_value_set_object (value, valadoc_token_get_token_type (self));
		break;
		case VALADOC_TOKEN_BEGIN_PROPERTY:
		{
			ValadocSourceLocation boxed;
			valadoc_token_get_begin (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case VALADOC_TOKEN_END_PROPERTY:
		{
			ValadocSourceLocation boxed;
			valadoc_token_get_end (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



