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

/* valatypeofexpression.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 <valagee.h>

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

struct _ValaTypeofExpressionPrivate {
	ValaDataType* _data_type;
};


static gpointer vala_typeof_expression_parent_class = NULL;

#define VALA_TYPEOF_EXPRESSION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_TYPEOF_EXPRESSION, ValaTypeofExpressionPrivate))
static void vala_typeof_expression_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static void vala_typeof_expression_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor);
static gboolean vala_typeof_expression_real_is_pure (ValaExpression* base);
static void vala_typeof_expression_real_replace_type (ValaCodeNode* base, ValaDataType* old_type, ValaDataType* new_type);
static gboolean vala_typeof_expression_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_typeof_expression_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_typeof_expression_finalize (ValaCodeNode * obj);


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


ValaTypeofExpression* vala_typeof_expression_new (ValaDataType* type, ValaSourceReference* source) {
	return vala_typeof_expression_construct (VALA_TYPE_TYPEOF_EXPRESSION, type, source);
}


static void vala_typeof_expression_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaTypeofExpression * self;
	ValaCodeVisitor* _tmp0_;
	ValaCodeVisitor* _tmp1_;
	self = (ValaTypeofExpression*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = visitor;
	vala_code_visitor_visit_typeof_expression (_tmp0_, self);
	_tmp1_ = visitor;
	vala_code_visitor_visit_expression (_tmp1_, (ValaExpression*) self);
}


static void vala_typeof_expression_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaTypeofExpression * self;
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	ValaCodeVisitor* _tmp2_;
	self = (ValaTypeofExpression*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = vala_typeof_expression_get_type_reference (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = visitor;
	vala_code_node_accept ((ValaCodeNode*) _tmp1_, _tmp2_);
}


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


static void vala_typeof_expression_real_replace_type (ValaCodeNode* base, ValaDataType* old_type, ValaDataType* new_type) {
	ValaTypeofExpression * self;
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	ValaDataType* _tmp2_;
	self = (ValaTypeofExpression*) base;
	g_return_if_fail (old_type != NULL);
	g_return_if_fail (new_type != NULL);
	_tmp0_ = vala_typeof_expression_get_type_reference (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = old_type;
	if (_tmp1_ == _tmp2_) {
		ValaDataType* _tmp3_;
		_tmp3_ = new_type;
		vala_typeof_expression_set_type_reference (self, _tmp3_);
	}
}


static gboolean vala_typeof_expression_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaTypeofExpression * self;
	gboolean result = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaDataType* _tmp4_;
	ValaDataType* _tmp5_;
	ValaCodeContext* _tmp6_;
	ValaCodeContext* _tmp7_;
	ValaSemanticAnalyzer* _tmp8_;
	ValaSemanticAnalyzer* _tmp9_;
	ValaDataType* _tmp10_;
	ValaDataType* _tmp11_;
	ValaDataType* _tmp12_;
	ValaList* _tmp13_;
	ValaList* _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	gboolean _tmp17_;
	gboolean _tmp21_;
	gboolean _tmp22_;
	self = (ValaTypeofExpression*) 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_typeof_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_->type_type;
	vala_expression_set_value_type ((ValaExpression*) self, _tmp10_);
	_tmp11_ = vala_typeof_expression_get_type_reference (self);
	_tmp12_ = _tmp11_;
	_tmp13_ = vala_data_type_get_type_arguments (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = vala_collection_get_size ((ValaCollection*) _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = _tmp16_ > 0;
	_vala_iterable_unref0 (_tmp14_);
	if (_tmp17_) {
		ValaDataType* _tmp18_;
		ValaSourceReference* _tmp19_;
		ValaSourceReference* _tmp20_;
		_tmp18_ = self->priv->_data_type;
		_tmp19_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp18_);
		_tmp20_ = _tmp19_;
		vala_report_warning (_tmp20_, "Type argument list without effect");
	}
	_tmp21_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp22_ = _tmp21_;
	result = !_tmp22_;
	return result;
}


static void vala_typeof_expression_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaTypeofExpression * self;
	ValaCodeGenerator* _tmp0_;
	ValaCodeGenerator* _tmp1_;
	self = (ValaTypeofExpression*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = codegen;
	vala_code_visitor_visit_typeof_expression ((ValaCodeVisitor*) _tmp0_, self);
	_tmp1_ = codegen;
	vala_code_visitor_visit_expression ((ValaCodeVisitor*) _tmp1_, (ValaExpression*) self);
}


ValaDataType* vala_typeof_expression_get_type_reference (ValaTypeofExpression* 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_typeof_expression_set_type_reference (ValaTypeofExpression* 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_typeof_expression_class_init (ValaTypeofExpressionClass * klass) {
	vala_typeof_expression_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_typeof_expression_finalize;
	g_type_class_add_private (klass, sizeof (ValaTypeofExpressionPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_typeof_expression_real_accept;
	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_typeof_expression_real_accept_children;
	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression *)) vala_typeof_expression_real_is_pure;
	((ValaCodeNodeClass *) klass)->replace_type = (void (*) (ValaCodeNode *, ValaDataType*, ValaDataType*)) vala_typeof_expression_real_replace_type;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_typeof_expression_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_typeof_expression_real_emit;
}


static void vala_typeof_expression_instance_init (ValaTypeofExpression * self) {
	self->priv = VALA_TYPEOF_EXPRESSION_GET_PRIVATE (self);
}


static void vala_typeof_expression_finalize (ValaCodeNode * obj) {
	ValaTypeofExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_TYPEOF_EXPRESSION, ValaTypeofExpression);
	_vala_code_node_unref0 (self->priv->_data_type);
	VALA_CODE_NODE_CLASS (vala_typeof_expression_parent_class)->finalize (obj);
}


/**
 * Represents a typeof expression in the source code.
 */
GType vala_typeof_expression_get_type (void) {
	static volatile gsize vala_typeof_expression_type_id__volatile = 0;
	if (g_once_init_enter (&vala_typeof_expression_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaTypeofExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_typeof_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaTypeofExpression), 0, (GInstanceInitFunc) vala_typeof_expression_instance_init, NULL };
		GType vala_typeof_expression_type_id;
		vala_typeof_expression_type_id = g_type_register_static (VALA_TYPE_EXPRESSION, "ValaTypeofExpression", &g_define_type_info, 0);
		g_once_init_leave (&vala_typeof_expression_type_id__volatile, vala_typeof_expression_type_id);
	}
	return vala_typeof_expression_type_id__volatile;
}



