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

/* valabooleanliteral.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 <glib.h>
#include <glib-object.h>
#include "vala.h"
#include <stdlib.h>
#include <string.h>


struct _ValaBooleanLiteralPrivate {
	gboolean _value;
};


static gpointer vala_boolean_literal_parent_class = NULL;

#define VALA_BOOLEAN_LITERAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_BOOLEAN_LITERAL, ValaBooleanLiteralPrivate))
static void vala_boolean_literal_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static gchar* vala_boolean_literal_real_to_string (ValaCodeNode* base);
static gboolean vala_boolean_literal_real_is_pure (ValaExpression* base);
static gboolean vala_boolean_literal_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_boolean_literal_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_boolean_literal_finalize (ValaCodeNode * obj);


/**
 * Creates a new boolean literal.
 *
 * @param b      boolean value
 * @param source reference to source code
 * @return       newly created boolean literal
 */
ValaBooleanLiteral* vala_boolean_literal_construct (GType object_type, gboolean b, ValaSourceReference* source) {
	ValaBooleanLiteral* self = NULL;
	gboolean _tmp0_;
	ValaSourceReference* _tmp1_;
	self = (ValaBooleanLiteral*) vala_literal_construct (object_type);
	_tmp0_ = b;
	vala_boolean_literal_set_value (self, _tmp0_);
	_tmp1_ = source;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp1_);
	return self;
}


ValaBooleanLiteral* vala_boolean_literal_new (gboolean b, ValaSourceReference* source) {
	return vala_boolean_literal_construct (VALA_TYPE_BOOLEAN_LITERAL, b, source);
}


static void vala_boolean_literal_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaBooleanLiteral * self;
	ValaCodeVisitor* _tmp0_;
	ValaCodeVisitor* _tmp1_;
	self = (ValaBooleanLiteral*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = visitor;
	vala_code_visitor_visit_boolean_literal (_tmp0_, self);
	_tmp1_ = visitor;
	vala_code_visitor_visit_expression (_tmp1_, (ValaExpression*) self);
}


static gchar* vala_boolean_literal_real_to_string (ValaCodeNode* base) {
	ValaBooleanLiteral * self;
	gchar* result = NULL;
	gboolean _tmp0_;
	self = (ValaBooleanLiteral*) base;
	_tmp0_ = self->priv->_value;
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("true");
		result = _tmp1_;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("false");
		result = _tmp2_;
		return result;
	}
}


static gboolean vala_boolean_literal_real_is_pure (ValaExpression* base) {
	ValaBooleanLiteral * self;
	gboolean result = FALSE;
	self = (ValaBooleanLiteral*) base;
	result = TRUE;
	return result;
}


static gboolean vala_boolean_literal_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaBooleanLiteral * self;
	gboolean result = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaCodeContext* _tmp4_;
	ValaSemanticAnalyzer* _tmp5_;
	ValaSemanticAnalyzer* _tmp6_;
	ValaDataType* _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	self = (ValaBooleanLiteral*) 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);
	_tmp4_ = context;
	_tmp5_ = vala_code_context_get_analyzer (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_->bool_type;
	vala_expression_set_value_type ((ValaExpression*) self, _tmp7_);
	_tmp8_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp9_ = _tmp8_;
	result = !_tmp9_;
	return result;
}


static void vala_boolean_literal_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaBooleanLiteral * self;
	ValaCodeGenerator* _tmp0_;
	ValaCodeGenerator* _tmp1_;
	self = (ValaBooleanLiteral*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = codegen;
	vala_code_visitor_visit_boolean_literal ((ValaCodeVisitor*) _tmp0_, self);
	_tmp1_ = codegen;
	vala_code_visitor_visit_expression ((ValaCodeVisitor*) _tmp1_, (ValaExpression*) self);
}


gboolean vala_boolean_literal_get_value (ValaBooleanLiteral* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_value;
	result = _tmp0_;
	return result;
}


void vala_boolean_literal_set_value (ValaBooleanLiteral* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_value = _tmp0_;
}


static void vala_boolean_literal_class_init (ValaBooleanLiteralClass * klass) {
	vala_boolean_literal_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_boolean_literal_finalize;
	g_type_class_add_private (klass, sizeof (ValaBooleanLiteralPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_boolean_literal_real_accept;
	((ValaCodeNodeClass *) klass)->to_string = (gchar* (*) (ValaCodeNode *)) vala_boolean_literal_real_to_string;
	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression *)) vala_boolean_literal_real_is_pure;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_boolean_literal_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_boolean_literal_real_emit;
}


static void vala_boolean_literal_instance_init (ValaBooleanLiteral * self) {
	self->priv = VALA_BOOLEAN_LITERAL_GET_PRIVATE (self);
}


static void vala_boolean_literal_finalize (ValaCodeNode * obj) {
	ValaBooleanLiteral * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_BOOLEAN_LITERAL, ValaBooleanLiteral);
	VALA_CODE_NODE_CLASS (vala_boolean_literal_parent_class)->finalize (obj);
}


/**
 * Represents a literal boolean, i.e. true or false.
 */
GType vala_boolean_literal_get_type (void) {
	static volatile gsize vala_boolean_literal_type_id__volatile = 0;
	if (g_once_init_enter (&vala_boolean_literal_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaBooleanLiteralClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_boolean_literal_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaBooleanLiteral), 0, (GInstanceInitFunc) vala_boolean_literal_instance_init, NULL };
		GType vala_boolean_literal_type_id;
		vala_boolean_literal_type_id = g_type_register_static (VALA_TYPE_LITERAL, "ValaBooleanLiteral", &g_define_type_info, 0);
		g_once_init_leave (&vala_boolean_literal_type_id__volatile, vala_boolean_literal_type_id);
	}
	return vala_boolean_literal_type_id__volatile;
}



