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

/* valarealliteral.vala
 *
 * Copyright (C) 2006-2010  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 <stdlib.h>
#include <string.h>
#include <glib.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)))

struct _ValaRealLiteralPrivate {
	gchar* _value;
};

static gint ValaRealLiteral_private_offset;
static gpointer vala_real_literal_parent_class = NULL;

static void vala_real_literal_set_value (ValaRealLiteral* self,
                                  const gchar* value);
static void vala_real_literal_real_accept (ValaCodeNode* base,
                                    ValaCodeVisitor* visitor);
static gboolean vala_real_literal_real_is_pure (ValaExpression* base);
static gchar* vala_real_literal_real_to_string (ValaCodeNode* base);
static gboolean vala_real_literal_real_check (ValaCodeNode* base,
                                       ValaCodeContext* context);
static void vala_real_literal_real_emit (ValaCodeNode* base,
                                  ValaCodeGenerator* codegen);
static void vala_real_literal_finalize (ValaCodeNode * obj);
static GType vala_real_literal_get_type_once (void);

static inline gpointer
vala_real_literal_get_instance_private (ValaRealLiteral* self)
{
	return G_STRUCT_MEMBER_P (self, ValaRealLiteral_private_offset);
}

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

static void
vala_real_literal_set_value (ValaRealLiteral* self,
                             const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_value);
	self->priv->_value = _tmp0_;
}

/**
 * Creates a new real literal.
 *
 * @param r      literal value
 * @param source reference to source code
 * @return       newly created real literal
 */
ValaRealLiteral*
vala_real_literal_construct (GType object_type,
                             const gchar* r,
                             ValaSourceReference* source)
{
	ValaRealLiteral* self = NULL;
	g_return_val_if_fail (r != NULL, NULL);
	self = (ValaRealLiteral*) vala_literal_construct (object_type);
	vala_real_literal_set_value (self, r);
	vala_code_node_set_source_reference ((ValaCodeNode*) self, source);
	return self;
}

ValaRealLiteral*
vala_real_literal_new (const gchar* r,
                       ValaSourceReference* source)
{
	return vala_real_literal_construct (VALA_TYPE_REAL_LITERAL, r, source);
}

static void
vala_real_literal_real_accept (ValaCodeNode* base,
                               ValaCodeVisitor* visitor)
{
	ValaRealLiteral * self;
	self = (ValaRealLiteral*) base;
	g_return_if_fail (visitor != NULL);
	vala_code_visitor_visit_real_literal (visitor, self);
	vala_code_visitor_visit_expression (visitor, (ValaExpression*) self);
}

static gboolean
vala_real_literal_real_is_pure (ValaExpression* base)
{
	ValaRealLiteral * self;
	gboolean result;
	self = (ValaRealLiteral*) base;
	result = TRUE;
	return result;
}

static gchar*
vala_real_literal_real_to_string (ValaCodeNode* base)
{
	ValaRealLiteral * self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	self = (ValaRealLiteral*) base;
	_tmp0_ = self->priv->_value;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

static gboolean
vala_real_literal_real_check (ValaCodeNode* base,
                              ValaCodeContext* context)
{
	ValaRealLiteral * self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gchar* type_name = NULL;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	ValaStruct* st = NULL;
	ValaNamespace* _tmp9_;
	ValaNamespace* _tmp10_;
	ValaScope* _tmp11_;
	ValaScope* _tmp12_;
	const gchar* _tmp13_;
	ValaSymbol* _tmp14_;
	ValaStruct* _tmp15_;
	ValaStruct* _tmp16_;
	ValaFloatingType* _tmp17_;
	ValaFloatingType* _tmp18_;
	gboolean _tmp19_;
	gboolean _tmp20_;
	gboolean result;
	self = (ValaRealLiteral*) base;
	g_return_val_if_fail (context != NULL, FALSE);
	_tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
		_tmp3_ = _tmp2_;
		result = !_tmp3_;
		return result;
	}
	vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
	_tmp5_ = self->priv->_value;
	if (g_str_has_suffix (_tmp5_, "f")) {
		_tmp4_ = TRUE;
	} else {
		const gchar* _tmp6_;
		_tmp6_ = self->priv->_value;
		_tmp4_ = g_str_has_suffix (_tmp6_, "F");
	}
	if (_tmp4_) {
		gchar* _tmp7_;
		_tmp7_ = g_strdup ("float");
		_g_free0 (type_name);
		type_name = _tmp7_;
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_strdup ("double");
		_g_free0 (type_name);
		type_name = _tmp8_;
	}
	_tmp9_ = vala_code_context_get_root (context);
	_tmp10_ = _tmp9_;
	_tmp11_ = vala_symbol_get_scope ((ValaSymbol*) _tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = type_name;
	_tmp14_ = vala_scope_lookup (_tmp12_, _tmp13_);
	st = G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, VALA_TYPE_STRUCT, ValaStruct);
	_tmp15_ = st;
	vala_code_node_check ((ValaCodeNode*) _tmp15_, context);
	_tmp16_ = st;
	_tmp17_ = vala_floating_type_new (_tmp16_, NULL);
	_tmp18_ = _tmp17_;
	vala_expression_set_value_type ((ValaExpression*) self, (ValaDataType*) _tmp18_);
	_vala_code_node_unref0 (_tmp18_);
	_tmp19_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp20_ = _tmp19_;
	result = !_tmp20_;
	_vala_code_node_unref0 (st);
	_g_free0 (type_name);
	return result;
}

static void
vala_real_literal_real_emit (ValaCodeNode* base,
                             ValaCodeGenerator* codegen)
{
	ValaRealLiteral * self;
	self = (ValaRealLiteral*) base;
	g_return_if_fail (codegen != NULL);
	vala_code_visitor_visit_real_literal ((ValaCodeVisitor*) codegen, self);
	vala_code_visitor_visit_expression ((ValaCodeVisitor*) codegen, (ValaExpression*) self);
}

static void
vala_real_literal_class_init (ValaRealLiteralClass * klass,
                              gpointer klass_data)
{
	vala_real_literal_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_real_literal_finalize;
	g_type_class_adjust_private_offset (klass, &ValaRealLiteral_private_offset);
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_real_literal_real_accept;
	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression*)) vala_real_literal_real_is_pure;
	((ValaCodeNodeClass *) klass)->to_string = (gchar* (*) (ValaCodeNode*)) vala_real_literal_real_to_string;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_real_literal_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_real_literal_real_emit;
}

static void
vala_real_literal_instance_init (ValaRealLiteral * self,
                                 gpointer klass)
{
	self->priv = vala_real_literal_get_instance_private (self);
}

static void
vala_real_literal_finalize (ValaCodeNode * obj)
{
	ValaRealLiteral * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_REAL_LITERAL, ValaRealLiteral);
	_g_free0 (self->priv->_value);
	VALA_CODE_NODE_CLASS (vala_real_literal_parent_class)->finalize (obj);
}

/**
 * Represents a real literal in the source code.
 */
static GType
vala_real_literal_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValaRealLiteralClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_real_literal_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaRealLiteral), 0, (GInstanceInitFunc) vala_real_literal_instance_init, NULL };
	GType vala_real_literal_type_id;
	vala_real_literal_type_id = g_type_register_static (VALA_TYPE_LITERAL, "ValaRealLiteral", &g_define_type_info, 0);
	ValaRealLiteral_private_offset = g_type_add_instance_private (vala_real_literal_type_id, sizeof (ValaRealLiteralPrivate));
	return vala_real_literal_type_id;
}

GType
vala_real_literal_get_type (void)
{
	static volatile gsize vala_real_literal_type_id__once = 0;
	if (g_once_init_enter (&vala_real_literal_type_id__once)) {
		GType vala_real_literal_type_id;
		vala_real_literal_type_id = vala_real_literal_get_type_once ();
		g_once_init_leave (&vala_real_literal_type_id__once, vala_real_literal_type_id);
	}
	return vala_real_literal_type_id__once;
}

