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

/* valaccodeunaryexpression.vala
 *
 * Copyright (C) 2006-2009  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 "valaccode.h"

#define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))

struct _ValaCCodeUnaryExpressionPrivate {
	ValaCCodeUnaryOperator _operator;
	ValaCCodeExpression* _inner;
};


static gpointer vala_ccode_unary_expression_parent_class = NULL;

#define VALA_CCODE_UNARY_EXPRESSION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_CCODE_UNARY_EXPRESSION, ValaCCodeUnaryExpressionPrivate))
static void vala_ccode_unary_expression_real_write (ValaCCodeNode* base, ValaCCodeWriter* writer);
static void vala_ccode_unary_expression_real_write_inner (ValaCCodeExpression* base, ValaCCodeWriter* writer);
static void vala_ccode_unary_expression_finalize (ValaCCodeNode * obj);


ValaCCodeUnaryExpression* vala_ccode_unary_expression_construct (GType object_type, ValaCCodeUnaryOperator op, ValaCCodeExpression* expr) {
	ValaCCodeUnaryExpression* self = NULL;
	ValaCCodeUnaryOperator _tmp0_;
	ValaCCodeExpression* _tmp1_;
	g_return_val_if_fail (expr != NULL, NULL);
	self = (ValaCCodeUnaryExpression*) vala_ccode_expression_construct (object_type);
	_tmp0_ = op;
	vala_ccode_unary_expression_set_operator (self, _tmp0_);
	_tmp1_ = expr;
	vala_ccode_unary_expression_set_inner (self, _tmp1_);
	return self;
}


ValaCCodeUnaryExpression* vala_ccode_unary_expression_new (ValaCCodeUnaryOperator op, ValaCCodeExpression* expr) {
	return vala_ccode_unary_expression_construct (VALA_TYPE_CCODE_UNARY_EXPRESSION, op, expr);
}


static gpointer _vala_ccode_node_ref0 (gpointer self) {
	return self ? vala_ccode_node_ref (self) : NULL;
}


static void vala_ccode_unary_expression_real_write (ValaCCodeNode* base, ValaCCodeWriter* writer) {
	ValaCCodeUnaryExpression * self;
	ValaCCodeUnaryOperator _tmp0_;
	self = (ValaCCodeUnaryExpression*) base;
	g_return_if_fail (writer != NULL);
	_tmp0_ = self->priv->_operator;
	switch (_tmp0_) {
		case VALA_CCODE_UNARY_OPERATOR_PLUS:
		{
			ValaCCodeWriter* _tmp1_;
			ValaCCodeExpression* _tmp2_;
			ValaCCodeWriter* _tmp3_;
			_tmp1_ = writer;
			vala_ccode_writer_write_string (_tmp1_, "+");
			_tmp2_ = self->priv->_inner;
			_tmp3_ = writer;
			vala_ccode_expression_write_inner (_tmp2_, _tmp3_);
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_MINUS:
		{
			ValaCCodeWriter* _tmp4_;
			ValaCCodeExpression* _tmp5_;
			ValaCCodeWriter* _tmp6_;
			_tmp4_ = writer;
			vala_ccode_writer_write_string (_tmp4_, "-");
			_tmp5_ = self->priv->_inner;
			_tmp6_ = writer;
			vala_ccode_expression_write_inner (_tmp5_, _tmp6_);
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_LOGICAL_NEGATION:
		{
			ValaCCodeWriter* _tmp7_;
			ValaCCodeExpression* _tmp8_;
			ValaCCodeWriter* _tmp9_;
			_tmp7_ = writer;
			vala_ccode_writer_write_string (_tmp7_, "!");
			_tmp8_ = self->priv->_inner;
			_tmp9_ = writer;
			vala_ccode_expression_write_inner (_tmp8_, _tmp9_);
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_BITWISE_COMPLEMENT:
		{
			ValaCCodeWriter* _tmp10_;
			ValaCCodeExpression* _tmp11_;
			ValaCCodeWriter* _tmp12_;
			_tmp10_ = writer;
			vala_ccode_writer_write_string (_tmp10_, "~");
			_tmp11_ = self->priv->_inner;
			_tmp12_ = writer;
			vala_ccode_expression_write_inner (_tmp11_, _tmp12_);
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_POINTER_INDIRECTION:
		{
			ValaCCodeUnaryExpression* inner_unary = NULL;
			ValaCCodeExpression* _tmp13_;
			ValaCCodeUnaryExpression* _tmp14_;
			gboolean _tmp15_ = FALSE;
			ValaCCodeUnaryExpression* _tmp16_;
			ValaCCodeWriter* _tmp22_;
			ValaCCodeExpression* _tmp23_;
			ValaCCodeWriter* _tmp24_;
			_tmp13_ = self->priv->_inner;
			_tmp14_ = _vala_ccode_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp13_, VALA_TYPE_CCODE_UNARY_EXPRESSION) ? ((ValaCCodeUnaryExpression*) _tmp13_) : NULL);
			inner_unary = _tmp14_;
			_tmp16_ = inner_unary;
			if (_tmp16_ != NULL) {
				ValaCCodeUnaryExpression* _tmp17_;
				ValaCCodeUnaryOperator _tmp18_;
				_tmp17_ = inner_unary;
				_tmp18_ = _tmp17_->priv->_operator;
				_tmp15_ = _tmp18_ == VALA_CCODE_UNARY_OPERATOR_ADDRESS_OF;
			} else {
				_tmp15_ = FALSE;
			}
			if (_tmp15_) {
				ValaCCodeUnaryExpression* _tmp19_;
				ValaCCodeExpression* _tmp20_;
				ValaCCodeWriter* _tmp21_;
				_tmp19_ = inner_unary;
				_tmp20_ = _tmp19_->priv->_inner;
				_tmp21_ = writer;
				vala_ccode_node_write ((ValaCCodeNode*) _tmp20_, _tmp21_);
				_vala_ccode_node_unref0 (inner_unary);
				return;
			}
			_tmp22_ = writer;
			vala_ccode_writer_write_string (_tmp22_, "*");
			_tmp23_ = self->priv->_inner;
			_tmp24_ = writer;
			vala_ccode_expression_write_inner (_tmp23_, _tmp24_);
			_vala_ccode_node_unref0 (inner_unary);
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_ADDRESS_OF:
		{
			ValaCCodeUnaryExpression* inner_unary = NULL;
			ValaCCodeExpression* _tmp25_;
			ValaCCodeUnaryExpression* _tmp26_;
			gboolean _tmp27_ = FALSE;
			ValaCCodeUnaryExpression* _tmp28_;
			ValaCCodeWriter* _tmp34_;
			ValaCCodeExpression* _tmp35_;
			ValaCCodeWriter* _tmp36_;
			_tmp25_ = self->priv->_inner;
			_tmp26_ = _vala_ccode_node_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp25_, VALA_TYPE_CCODE_UNARY_EXPRESSION) ? ((ValaCCodeUnaryExpression*) _tmp25_) : NULL);
			inner_unary = _tmp26_;
			_tmp28_ = inner_unary;
			if (_tmp28_ != NULL) {
				ValaCCodeUnaryExpression* _tmp29_;
				ValaCCodeUnaryOperator _tmp30_;
				_tmp29_ = inner_unary;
				_tmp30_ = _tmp29_->priv->_operator;
				_tmp27_ = _tmp30_ == VALA_CCODE_UNARY_OPERATOR_POINTER_INDIRECTION;
			} else {
				_tmp27_ = FALSE;
			}
			if (_tmp27_) {
				ValaCCodeUnaryExpression* _tmp31_;
				ValaCCodeExpression* _tmp32_;
				ValaCCodeWriter* _tmp33_;
				_tmp31_ = inner_unary;
				_tmp32_ = _tmp31_->priv->_inner;
				_tmp33_ = writer;
				vala_ccode_node_write ((ValaCCodeNode*) _tmp32_, _tmp33_);
				_vala_ccode_node_unref0 (inner_unary);
				return;
			}
			_tmp34_ = writer;
			vala_ccode_writer_write_string (_tmp34_, "&");
			_tmp35_ = self->priv->_inner;
			_tmp36_ = writer;
			vala_ccode_expression_write_inner (_tmp35_, _tmp36_);
			_vala_ccode_node_unref0 (inner_unary);
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_PREFIX_INCREMENT:
		{
			ValaCCodeWriter* _tmp37_;
			_tmp37_ = writer;
			vala_ccode_writer_write_string (_tmp37_, "++");
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_PREFIX_DECREMENT:
		{
			ValaCCodeWriter* _tmp38_;
			_tmp38_ = writer;
			vala_ccode_writer_write_string (_tmp38_, "--");
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_POSTFIX_INCREMENT:
		{
			ValaCCodeExpression* _tmp39_;
			ValaCCodeWriter* _tmp40_;
			ValaCCodeWriter* _tmp41_;
			_tmp39_ = self->priv->_inner;
			_tmp40_ = writer;
			vala_ccode_expression_write_inner (_tmp39_, _tmp40_);
			_tmp41_ = writer;
			vala_ccode_writer_write_string (_tmp41_, "++");
			break;
		}
		case VALA_CCODE_UNARY_OPERATOR_POSTFIX_DECREMENT:
		{
			ValaCCodeExpression* _tmp42_;
			ValaCCodeWriter* _tmp43_;
			ValaCCodeWriter* _tmp44_;
			_tmp42_ = self->priv->_inner;
			_tmp43_ = writer;
			vala_ccode_expression_write_inner (_tmp42_, _tmp43_);
			_tmp44_ = writer;
			vala_ccode_writer_write_string (_tmp44_, "--");
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}


static void vala_ccode_unary_expression_real_write_inner (ValaCCodeExpression* base, ValaCCodeWriter* writer) {
	ValaCCodeUnaryExpression * self;
	ValaCCodeWriter* _tmp0_;
	ValaCCodeWriter* _tmp1_;
	ValaCCodeWriter* _tmp2_;
	self = (ValaCCodeUnaryExpression*) base;
	g_return_if_fail (writer != NULL);
	_tmp0_ = writer;
	vala_ccode_writer_write_string (_tmp0_, "(");
	_tmp1_ = writer;
	vala_ccode_node_write ((ValaCCodeNode*) self, _tmp1_);
	_tmp2_ = writer;
	vala_ccode_writer_write_string (_tmp2_, ")");
}


ValaCCodeUnaryOperator vala_ccode_unary_expression_get_operator (ValaCCodeUnaryExpression* self) {
	ValaCCodeUnaryOperator result;
	ValaCCodeUnaryOperator _tmp0_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_operator;
	result = _tmp0_;
	return result;
}


void vala_ccode_unary_expression_set_operator (ValaCCodeUnaryExpression* self, ValaCCodeUnaryOperator value) {
	ValaCCodeUnaryOperator _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_operator = _tmp0_;
}


ValaCCodeExpression* vala_ccode_unary_expression_get_inner (ValaCCodeUnaryExpression* self) {
	ValaCCodeExpression* result;
	ValaCCodeExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_inner;
	result = _tmp0_;
	return result;
}


void vala_ccode_unary_expression_set_inner (ValaCCodeUnaryExpression* self, ValaCCodeExpression* value) {
	ValaCCodeExpression* _tmp0_;
	ValaCCodeExpression* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _vala_ccode_node_ref0 (_tmp0_);
	_vala_ccode_node_unref0 (self->priv->_inner);
	self->priv->_inner = _tmp1_;
}


static void vala_ccode_unary_expression_class_init (ValaCCodeUnaryExpressionClass * klass) {
	vala_ccode_unary_expression_parent_class = g_type_class_peek_parent (klass);
	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_unary_expression_finalize;
	g_type_class_add_private (klass, sizeof (ValaCCodeUnaryExpressionPrivate));
	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode *, ValaCCodeWriter*)) vala_ccode_unary_expression_real_write;
	((ValaCCodeExpressionClass *) klass)->write_inner = (void (*) (ValaCCodeExpression *, ValaCCodeWriter*)) vala_ccode_unary_expression_real_write_inner;
}


static void vala_ccode_unary_expression_instance_init (ValaCCodeUnaryExpression * self) {
	self->priv = VALA_CCODE_UNARY_EXPRESSION_GET_PRIVATE (self);
}


static void vala_ccode_unary_expression_finalize (ValaCCodeNode * obj) {
	ValaCCodeUnaryExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_UNARY_EXPRESSION, ValaCCodeUnaryExpression);
	_vala_ccode_node_unref0 (self->priv->_inner);
	VALA_CCODE_NODE_CLASS (vala_ccode_unary_expression_parent_class)->finalize (obj);
}


/**
 * Represents an expression with one operand in the C code.
 */
GType vala_ccode_unary_expression_get_type (void) {
	static volatile gsize vala_ccode_unary_expression_type_id__volatile = 0;
	if (g_once_init_enter (&vala_ccode_unary_expression_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeUnaryExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_unary_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeUnaryExpression), 0, (GInstanceInitFunc) vala_ccode_unary_expression_instance_init, NULL };
		GType vala_ccode_unary_expression_type_id;
		vala_ccode_unary_expression_type_id = g_type_register_static (VALA_TYPE_CCODE_EXPRESSION, "ValaCCodeUnaryExpression", &g_define_type_info, 0);
		g_once_init_leave (&vala_ccode_unary_expression_type_id__volatile, vala_ccode_unary_expression_type_id);
	}
	return vala_ccode_unary_expression_type_id__volatile;
}


GType vala_ccode_unary_operator_get_type (void) {
	static volatile gsize vala_ccode_unary_operator_type_id__volatile = 0;
	if (g_once_init_enter (&vala_ccode_unary_operator_type_id__volatile)) {
		static const GEnumValue values[] = {{VALA_CCODE_UNARY_OPERATOR_PLUS, "VALA_CCODE_UNARY_OPERATOR_PLUS", "plus"}, {VALA_CCODE_UNARY_OPERATOR_MINUS, "VALA_CCODE_UNARY_OPERATOR_MINUS", "minus"}, {VALA_CCODE_UNARY_OPERATOR_LOGICAL_NEGATION, "VALA_CCODE_UNARY_OPERATOR_LOGICAL_NEGATION", "logical-negation"}, {VALA_CCODE_UNARY_OPERATOR_BITWISE_COMPLEMENT, "VALA_CCODE_UNARY_OPERATOR_BITWISE_COMPLEMENT", "bitwise-complement"}, {VALA_CCODE_UNARY_OPERATOR_POINTER_INDIRECTION, "VALA_CCODE_UNARY_OPERATOR_POINTER_INDIRECTION", "pointer-indirection"}, {VALA_CCODE_UNARY_OPERATOR_ADDRESS_OF, "VALA_CCODE_UNARY_OPERATOR_ADDRESS_OF", "address-of"}, {VALA_CCODE_UNARY_OPERATOR_PREFIX_INCREMENT, "VALA_CCODE_UNARY_OPERATOR_PREFIX_INCREMENT", "prefix-increment"}, {VALA_CCODE_UNARY_OPERATOR_PREFIX_DECREMENT, "VALA_CCODE_UNARY_OPERATOR_PREFIX_DECREMENT", "prefix-decrement"}, {VALA_CCODE_UNARY_OPERATOR_POSTFIX_INCREMENT, "VALA_CCODE_UNARY_OPERATOR_POSTFIX_INCREMENT", "postfix-increment"}, {VALA_CCODE_UNARY_OPERATOR_POSTFIX_DECREMENT, "VALA_CCODE_UNARY_OPERATOR_POSTFIX_DECREMENT", "postfix-decrement"}, {0, NULL, NULL}};
		GType vala_ccode_unary_operator_type_id;
		vala_ccode_unary_operator_type_id = g_enum_register_static ("ValaCCodeUnaryOperator", values);
		g_once_init_leave (&vala_ccode_unary_operator_type_id__volatile, vala_ccode_unary_operator_type_id);
	}
	return vala_ccode_unary_operator_type_id__volatile;
}



