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

/* valayieldstatement.vala
 *
 * Copyright (C) 2008-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 _ValaYieldStatementPrivate {
	ValaExpression* _yield_expression;
};


static gpointer vala_yield_statement_parent_class = NULL;
static ValaStatementIface * vala_yield_statement_vala_statement_parent_iface = NULL;

#define VALA_YIELD_STATEMENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_YIELD_STATEMENT, ValaYieldStatementPrivate))
static void vala_yield_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static void vala_yield_statement_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor);
static void vala_yield_statement_real_replace_expression (ValaCodeNode* base, ValaExpression* old_node, ValaExpression* new_node);
static gboolean vala_yield_statement_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_yield_statement_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_yield_statement_finalize (ValaCodeNode * obj);


/**
 * Creates a new yield statement.
 *
 * @param yield_expression the yield expression
 * @param source_reference reference to source code
 * @return                 newly created yield statement
 */
ValaYieldStatement* vala_yield_statement_construct (GType object_type, ValaExpression* yield_expression, ValaSourceReference* source_reference) {
	ValaYieldStatement* self = NULL;
	ValaExpression* _tmp0_;
	ValaSourceReference* _tmp1_;
	self = (ValaYieldStatement*) vala_code_node_construct (object_type);
	_tmp0_ = yield_expression;
	vala_yield_statement_set_yield_expression (self, _tmp0_);
	_tmp1_ = source_reference;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp1_);
	return self;
}


ValaYieldStatement* vala_yield_statement_new (ValaExpression* yield_expression, ValaSourceReference* source_reference) {
	return vala_yield_statement_construct (VALA_TYPE_YIELD_STATEMENT, yield_expression, source_reference);
}


static void vala_yield_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaYieldStatement * self;
	ValaCodeVisitor* _tmp0_;
	self = (ValaYieldStatement*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = visitor;
	vala_code_visitor_visit_yield_statement (_tmp0_, self);
}


static void vala_yield_statement_real_accept_children (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaYieldStatement * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	self = (ValaYieldStatement*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = vala_yield_statement_get_yield_expression (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		ValaExpression* _tmp2_;
		ValaExpression* _tmp3_;
		ValaCodeVisitor* _tmp4_;
		ValaCodeVisitor* _tmp5_;
		ValaExpression* _tmp6_;
		ValaExpression* _tmp7_;
		_tmp2_ = vala_yield_statement_get_yield_expression (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = visitor;
		vala_code_node_accept ((ValaCodeNode*) _tmp3_, _tmp4_);
		_tmp5_ = visitor;
		_tmp6_ = vala_yield_statement_get_yield_expression (self);
		_tmp7_ = _tmp6_;
		vala_code_visitor_visit_end_full_expression (_tmp5_, _tmp7_);
	}
}


static void vala_yield_statement_real_replace_expression (ValaCodeNode* base, ValaExpression* old_node, ValaExpression* new_node) {
	ValaYieldStatement * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaExpression* _tmp2_;
	self = (ValaYieldStatement*) base;
	g_return_if_fail (old_node != NULL);
	g_return_if_fail (new_node != NULL);
	_tmp0_ = vala_yield_statement_get_yield_expression (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = old_node;
	if (_tmp1_ == _tmp2_) {
		ValaExpression* _tmp3_;
		_tmp3_ = new_node;
		vala_yield_statement_set_yield_expression (self, _tmp3_);
	}
}


static gboolean vala_yield_statement_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaYieldStatement * self;
	gboolean result = FALSE;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	self = (ValaYieldStatement*) base;
	g_return_val_if_fail (context != NULL, FALSE);
	_tmp0_ = vala_yield_statement_get_yield_expression (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		ValaExpression* _tmp2_;
		ValaExpression* _tmp3_;
		ValaCodeContext* _tmp4_;
		ValaExpression* _tmp5_;
		ValaExpression* _tmp6_;
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp2_ = vala_yield_statement_get_yield_expression (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = context;
		vala_code_node_check ((ValaCodeNode*) _tmp3_, _tmp4_);
		_tmp5_ = vala_yield_statement_get_yield_expression (self);
		_tmp6_ = _tmp5_;
		_tmp7_ = vala_code_node_get_error ((ValaCodeNode*) _tmp6_);
		_tmp8_ = _tmp7_;
		vala_code_node_set_error ((ValaCodeNode*) self, _tmp8_);
	}
	_tmp9_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp10_ = _tmp9_;
	result = !_tmp10_;
	return result;
}


static void vala_yield_statement_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaYieldStatement * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaCodeGenerator* _tmp8_;
	self = (ValaYieldStatement*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = vala_yield_statement_get_yield_expression (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		ValaExpression* _tmp2_;
		ValaExpression* _tmp3_;
		ValaCodeGenerator* _tmp4_;
		ValaCodeGenerator* _tmp5_;
		ValaExpression* _tmp6_;
		ValaExpression* _tmp7_;
		_tmp2_ = vala_yield_statement_get_yield_expression (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = codegen;
		vala_code_node_emit ((ValaCodeNode*) _tmp3_, _tmp4_);
		_tmp5_ = codegen;
		_tmp6_ = vala_yield_statement_get_yield_expression (self);
		_tmp7_ = _tmp6_;
		vala_code_visitor_visit_end_full_expression ((ValaCodeVisitor*) _tmp5_, _tmp7_);
	}
	_tmp8_ = codegen;
	vala_code_visitor_visit_yield_statement ((ValaCodeVisitor*) _tmp8_, self);
}


ValaExpression* vala_yield_statement_get_yield_expression (ValaYieldStatement* self) {
	ValaExpression* result;
	ValaExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_yield_expression;
	result = _tmp0_;
	return result;
}


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


void vala_yield_statement_set_yield_expression (ValaYieldStatement* self, ValaExpression* value) {
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaExpression* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_code_node_ref0 (_tmp0_);
	_vala_code_node_unref0 (self->priv->_yield_expression);
	self->priv->_yield_expression = _tmp1_;
	_tmp2_ = self->priv->_yield_expression;
	if (_tmp2_ != NULL) {
		ValaExpression* _tmp3_;
		_tmp3_ = self->priv->_yield_expression;
		vala_code_node_set_parent_node ((ValaCodeNode*) _tmp3_, (ValaCodeNode*) self);
	}
}


static void vala_yield_statement_class_init (ValaYieldStatementClass * klass) {
	vala_yield_statement_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_yield_statement_finalize;
	g_type_class_add_private (klass, sizeof (ValaYieldStatementPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_yield_statement_real_accept;
	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_yield_statement_real_accept_children;
	((ValaCodeNodeClass *) klass)->replace_expression = (void (*) (ValaCodeNode *, ValaExpression*, ValaExpression*)) vala_yield_statement_real_replace_expression;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_yield_statement_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_yield_statement_real_emit;
}


static void vala_yield_statement_vala_statement_interface_init (ValaStatementIface * iface) {
	vala_yield_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
}


static void vala_yield_statement_instance_init (ValaYieldStatement * self) {
	self->priv = VALA_YIELD_STATEMENT_GET_PRIVATE (self);
}


static void vala_yield_statement_finalize (ValaCodeNode * obj) {
	ValaYieldStatement * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_YIELD_STATEMENT, ValaYieldStatement);
	_vala_code_node_unref0 (self->priv->_yield_expression);
	VALA_CODE_NODE_CLASS (vala_yield_statement_parent_class)->finalize (obj);
}


/**
 * Represents a yield statement in the source code.
 */
GType vala_yield_statement_get_type (void) {
	static volatile gsize vala_yield_statement_type_id__volatile = 0;
	if (g_once_init_enter (&vala_yield_statement_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaYieldStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_yield_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaYieldStatement), 0, (GInstanceInitFunc) vala_yield_statement_instance_init, NULL };
		static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_yield_statement_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType vala_yield_statement_type_id;
		vala_yield_statement_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaYieldStatement", &g_define_type_info, 0);
		g_type_add_interface_static (vala_yield_statement_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
		g_once_init_leave (&vala_yield_statement_type_id__volatile, vala_yield_statement_type_id);
	}
	return vala_yield_statement_type_id__volatile;
}



