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

/* valaunlockstatement.vala
 *
 * Copyright (C) 2009-2010  Jürg Billeter
 * Copyright (C) 2009  Jiří Zárevúcky
 *
 * 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:
 * 	Jiří Zárevúcky <zarevucky.jiri@gmail.com>
 */

#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 _ValaUnlockStatementPrivate {
	ValaExpression* _resource;
};


static gpointer vala_unlock_statement_parent_class = NULL;
static ValaStatementIface * vala_unlock_statement_vala_statement_parent_iface = NULL;

#define VALA_UNLOCK_STATEMENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_UNLOCK_STATEMENT, ValaUnlockStatementPrivate))
static void vala_unlock_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static gboolean vala_unlock_statement_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_unlock_statement_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_unlock_statement_finalize (ValaCodeNode * obj);


ValaUnlockStatement* vala_unlock_statement_construct (GType object_type, ValaExpression* resource, ValaSourceReference* source_reference) {
	ValaUnlockStatement* self = NULL;
	ValaSourceReference* _tmp0_;
	ValaExpression* _tmp1_;
	g_return_val_if_fail (resource != NULL, NULL);
	self = (ValaUnlockStatement*) vala_code_node_construct (object_type);
	_tmp0_ = source_reference;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp0_);
	_tmp1_ = resource;
	vala_unlock_statement_set_resource (self, _tmp1_);
	return self;
}


ValaUnlockStatement* vala_unlock_statement_new (ValaExpression* resource, ValaSourceReference* source_reference) {
	return vala_unlock_statement_construct (VALA_TYPE_UNLOCK_STATEMENT, resource, source_reference);
}


static void vala_unlock_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaUnlockStatement * self;
	ValaExpression* _tmp0_;
	ValaCodeVisitor* _tmp1_;
	ValaCodeVisitor* _tmp2_;
	self = (ValaUnlockStatement*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = self->priv->_resource;
	_tmp1_ = visitor;
	vala_code_node_accept ((ValaCodeNode*) _tmp0_, _tmp1_);
	_tmp2_ = visitor;
	vala_code_visitor_visit_unlock_statement (_tmp2_, self);
}


static gboolean vala_unlock_statement_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaUnlockStatement * self;
	gboolean result = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaExpression* _tmp4_;
	ValaCodeContext* _tmp5_;
	gboolean _tmp6_ = FALSE;
	ValaExpression* _tmp7_;
	ValaExpression* _tmp15_;
	ValaSymbol* _tmp16_;
	ValaSymbol* _tmp17_;
	ValaSymbol* _tmp18_;
	ValaSymbol* _tmp19_;
	ValaCodeContext* _tmp20_;
	ValaSemanticAnalyzer* _tmp21_;
	ValaSemanticAnalyzer* _tmp22_;
	ValaClass* _tmp23_;
	ValaClass* _tmp24_;
	ValaExpression* _tmp29_;
	ValaSymbol* _tmp30_;
	ValaSymbol* _tmp31_;
	gboolean _tmp32_;
	gboolean _tmp33_;
	self = (ValaUnlockStatement*) 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_ = self->priv->_resource;
	_tmp5_ = context;
	vala_code_node_check ((ValaCodeNode*) _tmp4_, _tmp5_);
	_tmp7_ = self->priv->_resource;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, VALA_TYPE_MEMBER_ACCESS)) {
		ValaExpression* _tmp8_;
		ValaSymbol* _tmp9_;
		ValaSymbol* _tmp10_;
		_tmp8_ = self->priv->_resource;
		_tmp9_ = vala_expression_get_symbol_reference (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp6_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp10_, VALA_TYPE_LOCKABLE);
	} else {
		_tmp6_ = FALSE;
	}
	if (!_tmp6_) {
		ValaExpression* _tmp11_;
		ValaExpression* _tmp12_;
		ValaSourceReference* _tmp13_;
		ValaSourceReference* _tmp14_;
		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
		_tmp11_ = self->priv->_resource;
		vala_code_node_set_error ((ValaCodeNode*) _tmp11_, TRUE);
		_tmp12_ = self->priv->_resource;
		_tmp13_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp12_);
		_tmp14_ = _tmp13_;
		vala_report_error (_tmp14_, "Expression is either not a member access or does not denote a lockable" \
" member");
		result = FALSE;
		return result;
	}
	_tmp15_ = self->priv->_resource;
	_tmp16_ = vala_expression_get_symbol_reference (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = vala_symbol_get_parent_symbol (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = context;
	_tmp21_ = vala_code_context_get_analyzer (_tmp20_);
	_tmp22_ = _tmp21_;
	_tmp23_ = vala_semantic_analyzer_get_current_class (_tmp22_);
	_tmp24_ = _tmp23_;
	if (_tmp19_ != G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, VALA_TYPE_SYMBOL, ValaSymbol)) {
		ValaExpression* _tmp25_;
		ValaExpression* _tmp26_;
		ValaSourceReference* _tmp27_;
		ValaSourceReference* _tmp28_;
		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
		_tmp25_ = self->priv->_resource;
		vala_code_node_set_error ((ValaCodeNode*) _tmp25_, TRUE);
		_tmp26_ = self->priv->_resource;
		_tmp27_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp26_);
		_tmp28_ = _tmp27_;
		vala_report_error (_tmp28_, "Only members of the current class are lockable");
	}
	_tmp29_ = self->priv->_resource;
	_tmp30_ = vala_expression_get_symbol_reference (_tmp29_);
	_tmp31_ = _tmp30_;
	vala_lockable_set_lock_used (G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, VALA_TYPE_LOCKABLE, ValaLockable), TRUE);
	_tmp32_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp33_ = _tmp32_;
	result = !_tmp33_;
	return result;
}


static void vala_unlock_statement_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaUnlockStatement * self;
	ValaExpression* _tmp0_;
	ValaCodeGenerator* _tmp1_;
	ValaCodeGenerator* _tmp2_;
	self = (ValaUnlockStatement*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = self->priv->_resource;
	_tmp1_ = codegen;
	vala_code_node_emit ((ValaCodeNode*) _tmp0_, _tmp1_);
	_tmp2_ = codegen;
	vala_code_visitor_visit_unlock_statement ((ValaCodeVisitor*) _tmp2_, self);
}


ValaExpression* vala_unlock_statement_get_resource (ValaUnlockStatement* self) {
	ValaExpression* result;
	ValaExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_resource;
	result = _tmp0_;
	return result;
}


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


void vala_unlock_statement_set_resource (ValaUnlockStatement* self, ValaExpression* value) {
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_code_node_ref0 (_tmp0_);
	_vala_code_node_unref0 (self->priv->_resource);
	self->priv->_resource = _tmp1_;
}


static void vala_unlock_statement_class_init (ValaUnlockStatementClass * klass) {
	vala_unlock_statement_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_unlock_statement_finalize;
	g_type_class_add_private (klass, sizeof (ValaUnlockStatementPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_unlock_statement_real_accept;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_unlock_statement_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_unlock_statement_real_emit;
}


static void vala_unlock_statement_vala_statement_interface_init (ValaStatementIface * iface) {
	vala_unlock_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
}


static void vala_unlock_statement_instance_init (ValaUnlockStatement * self) {
	self->priv = VALA_UNLOCK_STATEMENT_GET_PRIVATE (self);
}


static void vala_unlock_statement_finalize (ValaCodeNode * obj) {
	ValaUnlockStatement * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_UNLOCK_STATEMENT, ValaUnlockStatement);
	_vala_code_node_unref0 (self->priv->_resource);
	VALA_CODE_NODE_CLASS (vala_unlock_statement_parent_class)->finalize (obj);
}


/**
 * Represents an unlock statement e.g. {{{ unlock (a); }}}.
 */
GType vala_unlock_statement_get_type (void) {
	static volatile gsize vala_unlock_statement_type_id__volatile = 0;
	if (g_once_init_enter (&vala_unlock_statement_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaUnlockStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_unlock_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaUnlockStatement), 0, (GInstanceInitFunc) vala_unlock_statement_instance_init, NULL };
		static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_unlock_statement_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType vala_unlock_statement_type_id;
		vala_unlock_statement_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaUnlockStatement", &g_define_type_info, 0);
		g_type_add_interface_static (vala_unlock_statement_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
		g_once_init_leave (&vala_unlock_statement_type_id__volatile, vala_unlock_statement_type_id);
	}
	return vala_unlock_statement_type_id__volatile;
}



