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

/* valapointerindirection.vala
 *
 * Copyright (C) 2007-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)))

struct _ValaPointerIndirectionPrivate {
	ValaExpression* _inner;
};


static gpointer vala_pointer_indirection_parent_class = NULL;

#define VALA_POINTER_INDIRECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_POINTER_INDIRECTION, ValaPointerIndirectionPrivate))
static void vala_pointer_indirection_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor);
static void vala_pointer_indirection_real_replace_expression (ValaCodeNode* base, ValaExpression* old_node, ValaExpression* new_node);
static gboolean vala_pointer_indirection_real_is_pure (ValaExpression* base);
static gboolean vala_pointer_indirection_real_is_accessible (ValaExpression* base, ValaSymbol* sym);
static gboolean vala_pointer_indirection_real_check (ValaCodeNode* base, ValaCodeContext* context);
static void vala_pointer_indirection_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen);
static void vala_pointer_indirection_real_get_defined_variables (ValaCodeNode* base, ValaCollection* collection);
static void vala_pointer_indirection_real_get_used_variables (ValaCodeNode* base, ValaCollection* collection);
static void vala_pointer_indirection_finalize (ValaCodeNode * obj);


/**
 * Creates a new pointer indirection.
 *
 * @param inner pointer to be dereferenced
 * @return      newly created pointer indirection
 */
ValaPointerIndirection* vala_pointer_indirection_construct (GType object_type, ValaExpression* inner, ValaSourceReference* source_reference) {
	ValaPointerIndirection* self = NULL;
	ValaSourceReference* _tmp0_;
	ValaExpression* _tmp1_;
	g_return_val_if_fail (inner != NULL, NULL);
	self = (ValaPointerIndirection*) vala_expression_construct (object_type);
	_tmp0_ = source_reference;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp0_);
	_tmp1_ = inner;
	vala_pointer_indirection_set_inner (self, _tmp1_);
	return self;
}


ValaPointerIndirection* vala_pointer_indirection_new (ValaExpression* inner, ValaSourceReference* source_reference) {
	return vala_pointer_indirection_construct (VALA_TYPE_POINTER_INDIRECTION, inner, source_reference);
}


static void vala_pointer_indirection_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
	ValaPointerIndirection * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaCodeVisitor* _tmp2_;
	ValaCodeVisitor* _tmp3_;
	ValaCodeVisitor* _tmp4_;
	self = (ValaPointerIndirection*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = visitor;
	vala_code_node_accept ((ValaCodeNode*) _tmp1_, _tmp2_);
	_tmp3_ = visitor;
	vala_code_visitor_visit_pointer_indirection (_tmp3_, self);
	_tmp4_ = visitor;
	vala_code_visitor_visit_expression (_tmp4_, (ValaExpression*) self);
}


static void vala_pointer_indirection_real_replace_expression (ValaCodeNode* base, ValaExpression* old_node, ValaExpression* new_node) {
	ValaPointerIndirection * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaExpression* _tmp2_;
	self = (ValaPointerIndirection*) base;
	g_return_if_fail (old_node != NULL);
	g_return_if_fail (new_node != NULL);
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = old_node;
	if (_tmp1_ == _tmp2_) {
		ValaExpression* _tmp3_;
		_tmp3_ = new_node;
		vala_pointer_indirection_set_inner (self, _tmp3_);
	}
}


static gboolean vala_pointer_indirection_real_is_pure (ValaExpression* base) {
	ValaPointerIndirection * self;
	gboolean result = FALSE;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	gboolean _tmp2_;
	self = (ValaPointerIndirection*) base;
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = vala_expression_is_pure (_tmp1_);
	result = _tmp2_;
	return result;
}


static gboolean vala_pointer_indirection_real_is_accessible (ValaExpression* base, ValaSymbol* sym) {
	ValaPointerIndirection * self;
	gboolean result = FALSE;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaSymbol* _tmp2_;
	gboolean _tmp3_;
	self = (ValaPointerIndirection*) base;
	g_return_val_if_fail (sym != NULL, FALSE);
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = sym;
	_tmp3_ = vala_expression_is_accessible (_tmp1_, _tmp2_);
	result = _tmp3_;
	return result;
}


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


static gboolean vala_pointer_indirection_real_check (ValaCodeNode* base, ValaCodeContext* context) {
	ValaPointerIndirection * self;
	gboolean result = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaExpression* _tmp4_;
	ValaExpression* _tmp5_;
	ValaCodeContext* _tmp6_;
	gboolean _tmp7_;
	ValaExpression* _tmp8_;
	ValaExpression* _tmp9_;
	ValaDataType* _tmp10_;
	ValaDataType* _tmp11_;
	ValaExpression* _tmp14_;
	ValaExpression* _tmp15_;
	ValaDataType* _tmp16_;
	ValaDataType* _tmp17_;
	gboolean _tmp37_;
	gboolean _tmp38_;
	self = (ValaPointerIndirection*) 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_pointer_indirection_get_inner (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = context;
	_tmp7_ = vala_code_node_check ((ValaCodeNode*) _tmp5_, _tmp6_);
	if (!_tmp7_) {
		result = FALSE;
		return result;
	}
	_tmp8_ = vala_pointer_indirection_get_inner (self);
	_tmp9_ = _tmp8_;
	_tmp10_ = vala_expression_get_value_type (_tmp9_);
	_tmp11_ = _tmp10_;
	if (_tmp11_ == NULL) {
		ValaSourceReference* _tmp12_;
		ValaSourceReference* _tmp13_;
		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
		_tmp12_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
		_tmp13_ = _tmp12_;
		vala_report_error (_tmp13_, "internal error: unknown type of inner expression");
		result = FALSE;
		return result;
	}
	_tmp14_ = vala_pointer_indirection_get_inner (self);
	_tmp15_ = _tmp14_;
	_tmp16_ = vala_expression_get_value_type (_tmp15_);
	_tmp17_ = _tmp16_;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp17_, VALA_TYPE_POINTER_TYPE)) {
		ValaPointerType* pointer_type = NULL;
		ValaExpression* _tmp18_;
		ValaExpression* _tmp19_;
		ValaDataType* _tmp20_;
		ValaDataType* _tmp21_;
		ValaPointerType* _tmp22_;
		gboolean _tmp23_ = FALSE;
		ValaPointerType* _tmp24_;
		ValaDataType* _tmp25_;
		ValaDataType* _tmp26_;
		ValaPointerType* _tmp32_;
		ValaDataType* _tmp33_;
		ValaDataType* _tmp34_;
		_tmp18_ = vala_pointer_indirection_get_inner (self);
		_tmp19_ = _tmp18_;
		_tmp20_ = vala_expression_get_value_type (_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp22_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, VALA_TYPE_POINTER_TYPE, ValaPointerType));
		pointer_type = _tmp22_;
		_tmp24_ = pointer_type;
		_tmp25_ = vala_pointer_type_get_base_type (_tmp24_);
		_tmp26_ = _tmp25_;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp26_, VALA_TYPE_REFERENCE_TYPE)) {
			_tmp23_ = TRUE;
		} else {
			ValaPointerType* _tmp27_;
			ValaDataType* _tmp28_;
			ValaDataType* _tmp29_;
			_tmp27_ = pointer_type;
			_tmp28_ = vala_pointer_type_get_base_type (_tmp27_);
			_tmp29_ = _tmp28_;
			_tmp23_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp29_, VALA_TYPE_VOID_TYPE);
		}
		if (_tmp23_) {
			ValaSourceReference* _tmp30_;
			ValaSourceReference* _tmp31_;
			vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
			_tmp30_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
			_tmp31_ = _tmp30_;
			vala_report_error (_tmp31_, "Pointer indirection not supported for this expression");
			result = FALSE;
			_vala_code_node_unref0 (pointer_type);
			return result;
		}
		_tmp32_ = pointer_type;
		_tmp33_ = vala_pointer_type_get_base_type (_tmp32_);
		_tmp34_ = _tmp33_;
		vala_expression_set_value_type ((ValaExpression*) self, _tmp34_);
		_vala_code_node_unref0 (pointer_type);
	} else {
		ValaSourceReference* _tmp35_;
		ValaSourceReference* _tmp36_;
		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
		_tmp35_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
		_tmp36_ = _tmp35_;
		vala_report_error (_tmp36_, "Pointer indirection not supported for this expression");
		result = FALSE;
		return result;
	}
	_tmp37_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp38_ = _tmp37_;
	result = !_tmp38_;
	return result;
}


static void vala_pointer_indirection_real_emit (ValaCodeNode* base, ValaCodeGenerator* codegen) {
	ValaPointerIndirection * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaCodeGenerator* _tmp2_;
	ValaCodeGenerator* _tmp3_;
	ValaCodeGenerator* _tmp4_;
	self = (ValaPointerIndirection*) base;
	g_return_if_fail (codegen != NULL);
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = codegen;
	vala_code_node_emit ((ValaCodeNode*) _tmp1_, _tmp2_);
	_tmp3_ = codegen;
	vala_code_visitor_visit_pointer_indirection ((ValaCodeVisitor*) _tmp3_, self);
	_tmp4_ = codegen;
	vala_code_visitor_visit_expression ((ValaCodeVisitor*) _tmp4_, (ValaExpression*) self);
}


static void vala_pointer_indirection_real_get_defined_variables (ValaCodeNode* base, ValaCollection* collection) {
	ValaPointerIndirection * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaCollection* _tmp2_;
	self = (ValaPointerIndirection*) base;
	g_return_if_fail (collection != NULL);
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = collection;
	vala_code_node_get_defined_variables ((ValaCodeNode*) _tmp1_, _tmp2_);
}


static void vala_pointer_indirection_real_get_used_variables (ValaCodeNode* base, ValaCollection* collection) {
	ValaPointerIndirection * self;
	ValaExpression* _tmp0_;
	ValaExpression* _tmp1_;
	ValaCollection* _tmp2_;
	self = (ValaPointerIndirection*) base;
	g_return_if_fail (collection != NULL);
	_tmp0_ = vala_pointer_indirection_get_inner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = collection;
	vala_code_node_get_used_variables ((ValaCodeNode*) _tmp1_, _tmp2_);
}


ValaExpression* vala_pointer_indirection_get_inner (ValaPointerIndirection* self) {
	ValaExpression* result;
	ValaExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_inner;
	result = _tmp0_;
	return result;
}


void vala_pointer_indirection_set_inner (ValaPointerIndirection* 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->_inner);
	self->priv->_inner = _tmp1_;
	_tmp2_ = self->priv->_inner;
	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp2_, (ValaCodeNode*) self);
}


static void vala_pointer_indirection_class_init (ValaPointerIndirectionClass * klass) {
	vala_pointer_indirection_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_pointer_indirection_finalize;
	g_type_class_add_private (klass, sizeof (ValaPointerIndirectionPrivate));
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode *, ValaCodeVisitor*)) vala_pointer_indirection_real_accept;
	((ValaCodeNodeClass *) klass)->replace_expression = (void (*) (ValaCodeNode *, ValaExpression*, ValaExpression*)) vala_pointer_indirection_real_replace_expression;
	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression *)) vala_pointer_indirection_real_is_pure;
	((ValaExpressionClass *) klass)->is_accessible = (gboolean (*) (ValaExpression *, ValaSymbol*)) vala_pointer_indirection_real_is_accessible;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode *, ValaCodeContext*)) vala_pointer_indirection_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode *, ValaCodeGenerator*)) vala_pointer_indirection_real_emit;
	((ValaCodeNodeClass *) klass)->get_defined_variables = (void (*) (ValaCodeNode *, ValaCollection*)) vala_pointer_indirection_real_get_defined_variables;
	((ValaCodeNodeClass *) klass)->get_used_variables = (void (*) (ValaCodeNode *, ValaCollection*)) vala_pointer_indirection_real_get_used_variables;
}


static void vala_pointer_indirection_instance_init (ValaPointerIndirection * self) {
	self->priv = VALA_POINTER_INDIRECTION_GET_PRIVATE (self);
}


static void vala_pointer_indirection_finalize (ValaCodeNode * obj) {
	ValaPointerIndirection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_POINTER_INDIRECTION, ValaPointerIndirection);
	_vala_code_node_unref0 (self->priv->_inner);
	VALA_CODE_NODE_CLASS (vala_pointer_indirection_parent_class)->finalize (obj);
}


/**
 * Represents a pointer indirection in the source code, e.g. `*pointer`.
 */
GType vala_pointer_indirection_get_type (void) {
	static volatile gsize vala_pointer_indirection_type_id__volatile = 0;
	if (g_once_init_enter (&vala_pointer_indirection_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaPointerIndirectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_pointer_indirection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaPointerIndirection), 0, (GInstanceInitFunc) vala_pointer_indirection_instance_init, NULL };
		GType vala_pointer_indirection_type_id;
		vala_pointer_indirection_type_id = g_type_register_static (VALA_TYPE_EXPRESSION, "ValaPointerIndirection", &g_define_type_info, 0);
		g_once_init_leave (&vala_pointer_indirection_type_id__volatile, vala_pointer_indirection_type_id);
	}
	return vala_pointer_indirection_type_id__volatile;
}



