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

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

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

struct _ValaSubroutinePrivate {
	ValaBlock* _body;
	ValaBasicBlock* _entry_block;
	ValaBasicBlock* _return_block;
	ValaBasicBlock* _exit_block;
	ValaLocalVariable* _result_var;
};

static gint ValaSubroutine_private_offset;
static gpointer vala_subroutine_parent_class = NULL;

static void vala_subroutine_finalize (ValaCodeNode * obj);
static GType vala_subroutine_get_type_once (void);

static inline gpointer
vala_subroutine_get_instance_private (ValaSubroutine* self)
{
	return G_STRUCT_MEMBER_P (self, ValaSubroutine_private_offset);
}

ValaBasicBlock*
vala_subroutine_get_entry_block (ValaSubroutine* self)
{
	ValaBasicBlock* result;
	ValaBasicBlock* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_entry_block;
	result = _tmp0_;
	return result;
}

static gpointer
_vala_basic_block_ref0 (gpointer self)
{
	return self ? vala_basic_block_ref (self) : NULL;
}

void
vala_subroutine_set_entry_block (ValaSubroutine* self,
                                 ValaBasicBlock* value)
{
	ValaBasicBlock* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_basic_block_ref0 (value);
	_vala_basic_block_unref0 (self->priv->_entry_block);
	self->priv->_entry_block = _tmp0_;
}

ValaBasicBlock*
vala_subroutine_get_return_block (ValaSubroutine* self)
{
	ValaBasicBlock* result;
	ValaBasicBlock* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_return_block;
	result = _tmp0_;
	return result;
}

void
vala_subroutine_set_return_block (ValaSubroutine* self,
                                  ValaBasicBlock* value)
{
	ValaBasicBlock* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_basic_block_ref0 (value);
	_vala_basic_block_unref0 (self->priv->_return_block);
	self->priv->_return_block = _tmp0_;
}

ValaBasicBlock*
vala_subroutine_get_exit_block (ValaSubroutine* self)
{
	ValaBasicBlock* result;
	ValaBasicBlock* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_exit_block;
	result = _tmp0_;
	return result;
}

void
vala_subroutine_set_exit_block (ValaSubroutine* self,
                                ValaBasicBlock* value)
{
	ValaBasicBlock* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_basic_block_ref0 (value);
	_vala_basic_block_unref0 (self->priv->_exit_block);
	self->priv->_exit_block = _tmp0_;
}

ValaLocalVariable*
vala_subroutine_get_result_var (ValaSubroutine* self)
{
	ValaLocalVariable* result;
	ValaLocalVariable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_result_var;
	result = _tmp0_;
	return result;
}

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

void
vala_subroutine_set_result_var (ValaSubroutine* self,
                                ValaLocalVariable* value)
{
	ValaLocalVariable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_code_node_ref0 (value);
	_vala_code_node_unref0 (self->priv->_result_var);
	self->priv->_result_var = _tmp0_;
}

gboolean
vala_subroutine_get_has_result (ValaSubroutine* self)
{
	ValaSubroutineClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = VALA_SUBROUTINE_GET_CLASS (self);
	if (_klass_->get_has_result) {
		return _klass_->get_has_result (self);
	}
	return FALSE;
}

ValaSubroutine*
vala_subroutine_construct (GType object_type,
                           const gchar* name,
                           ValaSourceReference* source_reference,
                           ValaComment* comment)
{
	ValaSubroutine* self = NULL;
	self = (ValaSubroutine*) vala_symbol_construct (object_type, name, source_reference, comment);
	return self;
}

ValaBlock*
vala_subroutine_get_body (ValaSubroutine* self)
{
	ValaBlock* result;
	ValaBlock* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_body;
	result = _tmp0_;
	return result;
}

void
vala_subroutine_set_body (ValaSubroutine* self,
                          ValaBlock* value)
{
	ValaBlock* _tmp0_;
	ValaBlock* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_code_node_ref0 (value);
	_vala_code_node_unref0 (self->priv->_body);
	self->priv->_body = _tmp0_;
	_tmp1_ = self->priv->_body;
	if (_tmp1_ != NULL) {
		ValaBlock* _tmp2_;
		ValaScope* _tmp3_;
		ValaScope* _tmp4_;
		ValaBlock* _tmp5_;
		_tmp2_ = self->priv->_body;
		_tmp3_ = vala_symbol_get_scope ((ValaSymbol*) self);
		_tmp4_ = _tmp3_;
		vala_symbol_set_owner ((ValaSymbol*) _tmp2_, _tmp4_);
		_tmp5_ = self->priv->_body;
		vala_code_node_set_parent_node ((ValaCodeNode*) _tmp5_, (ValaCodeNode*) self);
	}
}

static void
vala_subroutine_class_init (ValaSubroutineClass * klass,
                            gpointer klass_data)
{
	vala_subroutine_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_subroutine_finalize;
	g_type_class_adjust_private_offset (klass, &ValaSubroutine_private_offset);
}

static void
vala_subroutine_instance_init (ValaSubroutine * self,
                               gpointer klass)
{
	self->priv = vala_subroutine_get_instance_private (self);
}

static void
vala_subroutine_finalize (ValaCodeNode * obj)
{
	ValaSubroutine * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_SUBROUTINE, ValaSubroutine);
	_vala_code_node_unref0 (self->priv->_body);
	_vala_basic_block_unref0 (self->priv->_entry_block);
	_vala_basic_block_unref0 (self->priv->_return_block);
	_vala_basic_block_unref0 (self->priv->_exit_block);
	_vala_code_node_unref0 (self->priv->_result_var);
	VALA_CODE_NODE_CLASS (vala_subroutine_parent_class)->finalize (obj);
}

static GType
vala_subroutine_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValaSubroutineClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_subroutine_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaSubroutine), 0, (GInstanceInitFunc) vala_subroutine_instance_init, NULL };
	GType vala_subroutine_type_id;
	vala_subroutine_type_id = g_type_register_static (VALA_TYPE_SYMBOL, "ValaSubroutine", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	ValaSubroutine_private_offset = g_type_add_instance_private (vala_subroutine_type_id, sizeof (ValaSubroutinePrivate));
	return vala_subroutine_type_id;
}

GType
vala_subroutine_get_type (void)
{
	static volatile gsize vala_subroutine_type_id__once = 0;
	if (g_once_init_enter (&vala_subroutine_type_id__once)) {
		GType vala_subroutine_type_id;
		vala_subroutine_type_id = vala_subroutine_get_type_once ();
		g_once_init_leave (&vala_subroutine_type_id__once, vala_subroutine_type_id);
	}
	return vala_subroutine_type_id__once;
}

