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

/* valasizeofexpression.vala
 *
 * Copyright (C) 2006-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 <glib-object.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

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

struct _ValaSizeofExpressionPrivate {
	ValaDataType* _data_type;
};

static gint ValaSizeofExpression_private_offset;
static gpointer vala_sizeof_expression_parent_class = NULL;

static void vala_sizeof_expression_set_type_reference (ValaSizeofExpression* self,
                                                ValaDataType* value);
static void vala_sizeof_expression_real_accept (ValaCodeNode* base,
                                         ValaCodeVisitor* visitor);
static void vala_sizeof_expression_real_accept_children (ValaCodeNode* base,
                                                  ValaCodeVisitor* visitor);
static gboolean vala_sizeof_expression_real_is_pure (ValaExpression* base);
static gboolean vala_sizeof_expression_real_is_constant (ValaExpression* base);
static void vala_sizeof_expression_real_replace_type (ValaCodeNode* base,
                                               ValaDataType* old_type,
                                               ValaDataType* new_type);
static gboolean vala_sizeof_expression_real_check (ValaCodeNode* base,
                                            ValaCodeContext* context);
static void vala_sizeof_expression_real_emit (ValaCodeNode* base,
                                       ValaCodeGenerator* codegen);
static void vala_sizeof_expression_finalize (ValaCodeNode * obj);
static GType vala_sizeof_expression_get_type_once (void);

static inline gpointer
vala_sizeof_expression_get_instance_private (ValaSizeofExpression* self)
{
	return G_STRUCT_MEMBER_P (self, ValaSizeofExpression_private_offset);
}

ValaDataType*
vala_sizeof_expression_get_type_reference (ValaSizeofExpression* self)
{
	ValaDataType* result;
	ValaDataType* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_data_type;
	result = _tmp0_;
	return result;
}

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

static void
vala_sizeof_expression_set_type_reference (ValaSizeofExpression* self,
                                           ValaDataType* value)
{
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_code_node_ref0 (value);
	_vala_code_node_unref0 (self->priv->_data_type);
	self->priv->_data_type = _tmp0_;
	_tmp1_ = self->priv->_data_type;
	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp1_, (ValaCodeNode*) self);
}

/**
 * Creates a new sizeof expression.
 *
 * @param type   a data type
 * @param source reference to source code
 * @return       newly created sizeof expression
 */
ValaSizeofExpression*
vala_sizeof_expression_construct (GType object_type,
                                  ValaDataType* type,
                                  ValaSourceReference* source)
{
	ValaSizeofExpression* self = NULL;
	g_return_val_if_fail (type != NULL, NULL);
	self = (ValaSizeofExpression*) vala_expression_construct (object_type);
	vala_sizeof_expression_set_type_reference (self, type);
	vala_code_node_set_source_reference ((ValaCodeNode*) self, source);
	return self;
}

ValaSizeofExpression*
vala_sizeof_expression_new (ValaDataType* type,
                            ValaSourceReference* source)
{
	return vala_sizeof_expression_construct (VALA_TYPE_SIZEOF_EXPRESSION, type, source);
}

static void
vala_sizeof_expression_real_accept (ValaCodeNode* base,
                                    ValaCodeVisitor* visitor)
{
	ValaSizeofExpression * self;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (visitor != NULL);
	vala_code_visitor_visit_sizeof_expression (visitor, self);
	vala_code_visitor_visit_expression (visitor, (ValaExpression*) self);
}

static void
vala_sizeof_expression_real_accept_children (ValaCodeNode* base,
                                             ValaCodeVisitor* visitor)
{
	ValaSizeofExpression * self;
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (visitor != NULL);
	_tmp0_ = vala_sizeof_expression_get_type_reference (self);
	_tmp1_ = _tmp0_;
	vala_code_node_accept ((ValaCodeNode*) _tmp1_, visitor);
}

static gboolean
vala_sizeof_expression_real_is_pure (ValaExpression* base)
{
	ValaSizeofExpression * self;
	gboolean result;
	self = (ValaSizeofExpression*) base;
	result = TRUE;
	return result;
}

static gboolean
vala_sizeof_expression_real_is_constant (ValaExpression* base)
{
	ValaSizeofExpression * self;
	gboolean result;
	self = (ValaSizeofExpression*) base;
	result = TRUE;
	return result;
}

static void
vala_sizeof_expression_real_replace_type (ValaCodeNode* base,
                                          ValaDataType* old_type,
                                          ValaDataType* new_type)
{
	ValaSizeofExpression * self;
	ValaDataType* _tmp0_;
	ValaDataType* _tmp1_;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (old_type != NULL);
	g_return_if_fail (new_type != NULL);
	_tmp0_ = vala_sizeof_expression_get_type_reference (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == old_type) {
		vala_sizeof_expression_set_type_reference (self, new_type);
	}
}

static gboolean
vala_sizeof_expression_real_check (ValaCodeNode* base,
                                   ValaCodeContext* context)
{
	ValaSizeofExpression * self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	ValaDataType* _tmp4_;
	ValaDataType* _tmp5_;
	ValaSemanticAnalyzer* _tmp6_;
	ValaSemanticAnalyzer* _tmp7_;
	ValaDataType* _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	gboolean result;
	self = (ValaSizeofExpression*) 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_sizeof_expression_get_type_reference (self);
	_tmp5_ = _tmp4_;
	vala_code_node_check ((ValaCodeNode*) _tmp5_, context);
	_tmp6_ = vala_code_context_get_analyzer (context);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->ulong_type;
	vala_expression_set_value_type ((ValaExpression*) self, _tmp8_);
	_tmp9_ = vala_code_node_get_error ((ValaCodeNode*) self);
	_tmp10_ = _tmp9_;
	result = !_tmp10_;
	return result;
}

static void
vala_sizeof_expression_real_emit (ValaCodeNode* base,
                                  ValaCodeGenerator* codegen)
{
	ValaSizeofExpression * self;
	self = (ValaSizeofExpression*) base;
	g_return_if_fail (codegen != NULL);
	vala_code_visitor_visit_sizeof_expression ((ValaCodeVisitor*) codegen, self);
	vala_code_visitor_visit_expression ((ValaCodeVisitor*) codegen, (ValaExpression*) self);
}

static void
vala_sizeof_expression_class_init (ValaSizeofExpressionClass * klass,
                                   gpointer klass_data)
{
	vala_sizeof_expression_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_sizeof_expression_finalize;
	g_type_class_adjust_private_offset (klass, &ValaSizeofExpression_private_offset);
	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_sizeof_expression_real_accept;
	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_sizeof_expression_real_accept_children;
	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression*)) vala_sizeof_expression_real_is_pure;
	((ValaExpressionClass *) klass)->is_constant = (gboolean (*) (ValaExpression*)) vala_sizeof_expression_real_is_constant;
	((ValaCodeNodeClass *) klass)->replace_type = (void (*) (ValaCodeNode*, ValaDataType*, ValaDataType*)) vala_sizeof_expression_real_replace_type;
	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_sizeof_expression_real_check;
	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_sizeof_expression_real_emit;
}

static void
vala_sizeof_expression_instance_init (ValaSizeofExpression * self,
                                      gpointer klass)
{
	self->priv = vala_sizeof_expression_get_instance_private (self);
}

static void
vala_sizeof_expression_finalize (ValaCodeNode * obj)
{
	ValaSizeofExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_SIZEOF_EXPRESSION, ValaSizeofExpression);
	_vala_code_node_unref0 (self->priv->_data_type);
	VALA_CODE_NODE_CLASS (vala_sizeof_expression_parent_class)->finalize (obj);
}

/**
 * Represents a sizeof expression in the source code.
 */
static GType
vala_sizeof_expression_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValaSizeofExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_sizeof_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaSizeofExpression), 0, (GInstanceInitFunc) vala_sizeof_expression_instance_init, NULL };
	GType vala_sizeof_expression_type_id;
	vala_sizeof_expression_type_id = g_type_register_static (VALA_TYPE_EXPRESSION, "ValaSizeofExpression", &g_define_type_info, 0);
	ValaSizeofExpression_private_offset = g_type_add_instance_private (vala_sizeof_expression_type_id, sizeof (ValaSizeofExpressionPrivate));
	return vala_sizeof_expression_type_id;
}

GType
vala_sizeof_expression_get_type (void)
{
	static volatile gsize vala_sizeof_expression_type_id__once = 0;
	if (g_once_init_enter (&vala_sizeof_expression_type_id__once)) {
		GType vala_sizeof_expression_type_id;
		vala_sizeof_expression_type_id = vala_sizeof_expression_get_type_once ();
		g_once_init_leave (&vala_sizeof_expression_type_id__once, vala_sizeof_expression_type_id);
	}
	return vala_sizeof_expression_type_id__once;
}

