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

/* valasizeofexpression.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"

#define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))

struct _ValaSizeofExpressionPrivate {
	ValaDataType* _data_type;
};


static gpointer vala_sizeof_expression_parent_class = NULL;

#define VALA_SIZEOF_EXPRESSION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_SIZEOF_EXPRESSION, ValaSizeofExpressionPrivate))
static void vala_sizeof_expression_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static void vala_sizeof_expression_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor);
static gboolean vala_sizeof_expression_real_is_pure (ValaExpression* base);
static gboolean vala_sizeof_expression_real_is_constant (ValaExpression* base);
static void vala_sizeof_expression_real_replace_type (ValaCodeNode* base, ValaDataType* old_type, ValaDataType* new_type);
static gboolean vala_sizeof_expression_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_sizeof_expression_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_sizeof_expression_finalize (ValaCodeNode * obj);


/**
 * Creates a new sizeof expression.
 *
 * @param type   a data type
 * @param source reference to source code
 * @return       newly created sizeof expression
 */
ValaSizeofExpression* vala_sizeof_expression_construct (GType object_type, ValaDataType* type, ValaSourceReference* source) {
	ValaSizeofExpression* self = NULL;
	ValaDataType* _tmp0_;
	ValaSourceReference* _tmp1_;
	g_return_val_if_fail (type != NULL, NULL);
	g_return_val_if_fail (source != NULL, NULL);
	self = (ValaSizeofExpression*) vala_expression_construct (object_type);
	_tmp0_ = type;
	vala_sizeof_expression_set_type_reference (self, _tmp0_);
	_tmp1_ = source;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp1_);
	return self;
}


ValaSizeofExpression* vala_sizeof_expression_new (ValaDataType* type, ValaSourceReference* source) {
	return vala_sizeof_expression_construct (VALA_TYPE_SIZEOF_EXPRESSION, type, source);
}


static void vala_sizeof_expression_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaSizeofExpression * self;
	ValaCodeVisitor* _tmp0_;
	ValaCodeVisitor* _tmp1_;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = visitor;
	vala_code_visitor_visit_sizeof_expression (_tmp0_, self);
	_tmp1_ = visitor;
	vala_code_visitor_visit_expression (_tmp1_, (ValaExpression*) self);
}


static void vala_sizeof_expression_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaSizeofExpression * self;
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	ValaCodeVisitor* _tmp2_;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = vala_sizeof_expression_get_type_reference (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = visitor;
	vala_code_node_accept ((ValaCodeNode*) _tmp1_, _tmp2_);
}


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


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


static void vala_sizeof_expression_real_replace_type (ValaCodeNode* base, ValaDataType* old_type, ValaDataType* new_type) {
	ValaSizeofExpression * self;
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	ValaDataType* _tmp2_;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (old_type != NULL);
	g_return_if_fail (new_type != NULL);
	_tmp0_ = vala_sizeof_expression_get_type_reference (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = old_type;
	if (_tmp1_ == _tmp2_) {
		ValaDataType* _tmp3_;
		_tmp3_ = new_type;
		vala_sizeof_expression_set_type_reference (self, _tmp3_);
	}
}


static gboolean vala_sizeof_expression_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaSizeofExpression * self;
	gboolean result = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaDataType* _tmp4_;
	ValaDataType* _tmp5_;
	ValaCodeContext* _tmp6_;
	ValaCodeContext* _tmp7_;
	ValaSemanticAnalyzer* _tmp8_;
	ValaSemanticAnalyzer* _tmp9_;
	ValaDataType* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	self = (ValaSizeofExpression*) 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_ = vala_sizeof_expression_get_type_reference (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = context;
	vala_code_node_check ((ValaCodeNode*) _tmp5_, _tmp6_);
	_tmp7_ = context;
	_tmp8_ = vala_code_context_get_analyzer (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_->ulong_type;
	vala_expression_set_value_type ((ValaExpression*) self, _tmp10_);
	_tmp11_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp12_ = _tmp11_;
	result = !_tmp12_;
	return result;
}


static void vala_sizeof_expression_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaSizeofExpression * self;
	ValaCodeGenerator* _tmp0_;
	ValaCodeGenerator* _tmp1_;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = codegen;
	vala_code_visitor_visit_sizeof_expression ((ValaCodeVisitor*) _tmp0_, self);
	_tmp1_ = codegen;
	vala_code_visitor_visit_expression ((ValaCodeVisitor*) _tmp1_, (ValaExpression*) self);
}


ValaDataType* vala_sizeof_expression_get_type_reference (ValaSizeofExpression* self) {
	ValaDataType* result;
	ValaDataType* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_data_type;
	result = _tmp0_;
	return result;
}


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


void vala_sizeof_expression_set_type_reference (ValaSizeofExpression* self, ValaDataType* value) {
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	ValaDataType* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_code_node_ref0 (_tmp0_);
	_vala_code_node_unref0 (self->priv->_data_type);
	self->priv->_data_type = _tmp1_;
	_tmp2_ = self->priv->_data_type;
	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp2_, (ValaCodeNode*) self);
}


static void vala_sizeof_expression_class_init (ValaSizeofExpressionClass * klass) {
	vala_sizeof_expression_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_sizeof_expression_finalize;
	g_type_class_add_private (klass, sizeof (ValaSizeofExpressionPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_sizeof_expression_real_accept;
	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_sizeof_expression_real_accept_children;
	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression *)) vala_sizeof_expression_real_is_pure;
	((ValaExpressionClass *) klass)->is_constant = (gboolean (*) (ValaExpression *)) vala_sizeof_expression_real_is_constant;
	((ValaCodeNodeClass *) klass)->replace_type = (void (*) (ValaCodeNode *, ValaDataType*, ValaDataType*)) vala_sizeof_expression_real_replace_type;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_sizeof_expression_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_sizeof_expression_real_emit;
}


static void vala_sizeof_expression_instance_init (ValaSizeofExpression * self) {
	self->priv = VALA_SIZEOF_EXPRESSION_GET_PRIVATE (self);
}


static void vala_sizeof_expression_finalize (ValaCodeNode * obj) {
	ValaSizeofExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_SIZEOF_EXPRESSION, ValaSizeofExpression);
	_vala_code_node_unref0 (self->priv->_data_type);
	VALA_CODE_NODE_CLASS (vala_sizeof_expression_parent_class)->finalize (obj);
}


/**
 * Represents a sizeof expression in the source code.
 */
GType vala_sizeof_expression_get_type (void) {
	static volatile gsize vala_sizeof_expression_type_id__volatile = 0;
	if (g_once_init_enter (&vala_sizeof_expression_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaSizeofExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_sizeof_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaSizeofExpression), 0, (GInstanceInitFunc) vala_sizeof_expression_instance_init, NULL };
		GType vala_sizeof_expression_type_id;
		vala_sizeof_expression_type_id = g_type_register_static (VALA_TYPE_EXPRESSION, "ValaSizeofExpression", &g_define_type_info, 0);
		g_once_init_leave (&vala_sizeof_expression_type_id__volatile, vala_sizeof_expression_type_id);
	}
	return vala_sizeof_expression_type_id__volatile;
}



