/* parser.c generated by valac 0.12.1.1-323029-dirty, the Vala compiler
 * generated from parser.vala, do not modify */

/* parser.vala
 *
 * Copyright (C) 2009  Andrea Del Signore
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * Author:
 * 	Andrea Del Signore <sejerpz@tin.it>
 */

#include <glib.h>
#include <glib-object.h>
#include <vala.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>
#include <valagee.h>


#define AFRODITE_TYPE_PARSER (afrodite_parser_get_type ())
#define AFRODITE_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AFRODITE_TYPE_PARSER, AfroditeParser))
#define AFRODITE_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AFRODITE_TYPE_PARSER, AfroditeParserClass))
#define AFRODITE_IS_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AFRODITE_TYPE_PARSER))
#define AFRODITE_IS_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AFRODITE_TYPE_PARSER))
#define AFRODITE_PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AFRODITE_TYPE_PARSER, AfroditeParserClass))

typedef struct _AfroditeParser AfroditeParser;
typedef struct _AfroditeParserClass AfroditeParserClass;
typedef struct _AfroditeParserPrivate AfroditeParserPrivate;

#define AFRODITE_TYPE_SOURCE_ITEM (afrodite_source_item_get_type ())
#define AFRODITE_SOURCE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItem))
#define AFRODITE_SOURCE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItemClass))
#define AFRODITE_IS_SOURCE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AFRODITE_TYPE_SOURCE_ITEM))
#define AFRODITE_IS_SOURCE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AFRODITE_TYPE_SOURCE_ITEM))
#define AFRODITE_SOURCE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItemClass))

typedef struct _AfroditeSourceItem AfroditeSourceItem;
typedef struct _AfroditeSourceItemClass AfroditeSourceItemClass;
#define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))
typedef struct _AfroditeSourceItemPrivate AfroditeSourceItemPrivate;

#define AFRODITE_TYPE_SOURCE_TYPE (afrodite_source_type_get_type ())
#define _vala_source_file_unref0(var) ((var == NULL) ? NULL : (var = (vala_source_file_unref (var), NULL)))
#define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))

#define AFRODITE_TYPE_PARSE_RESULT (afrodite_parse_result_get_type ())
#define AFRODITE_PARSE_RESULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AFRODITE_TYPE_PARSE_RESULT, AfroditeParseResult))
#define AFRODITE_PARSE_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AFRODITE_TYPE_PARSE_RESULT, AfroditeParseResultClass))
#define AFRODITE_IS_PARSE_RESULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AFRODITE_TYPE_PARSE_RESULT))
#define AFRODITE_IS_PARSE_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AFRODITE_TYPE_PARSE_RESULT))
#define AFRODITE_PARSE_RESULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AFRODITE_TYPE_PARSE_RESULT, AfroditeParseResultClass))

typedef struct _AfroditeParseResult AfroditeParseResult;
typedef struct _AfroditeParseResultClass AfroditeParseResultClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_code_visitor_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_visitor_unref (var), NULL)))
typedef struct _AfroditeParseResultPrivate AfroditeParseResultPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _AfroditeParser {
	GObject parent_instance;
	AfroditeParserPrivate * priv;
};

struct _AfroditeParserClass {
	GObjectClass parent_class;
};

struct _AfroditeParserPrivate {
	ValaCodeContext* context;
	AfroditeSourceItem* _source;
};

typedef enum  {
	AFRODITE_SOURCE_TYPE_AUTO,
	AFRODITE_SOURCE_TYPE_VALA,
	AFRODITE_SOURCE_TYPE_GENIE,
	AFRODITE_SOURCE_TYPE_VAPI,
	AFRODITE_SOURCE_TYPE_UNKNOWN
} AfroditeSourceType;

struct _AfroditeSourceItem {
	GTypeInstance parent_instance;
	volatile int ref_count;
	AfroditeSourceItemPrivate * priv;
	gchar* content;
	AfroditeSourceType source_type;
	gboolean is_glib;
	ValaCodeContext* context;
};

struct _AfroditeSourceItemClass {
	GTypeClass parent_class;
	void (*finalize) (AfroditeSourceItem *self);
};

struct _AfroditeParseResult {
	ValaReport parent_instance;
	AfroditeParseResultPrivate * priv;
	ValaList* warnings;
	ValaList* errors;
	ValaList* notes;
	gchar* source_path;
	gboolean is_glib;
	ValaCodeContext* context;
	gboolean is_edited;
};

struct _AfroditeParseResultClass {
	ValaReportClass parent_class;
};


static gpointer afrodite_parser_parent_class = NULL;

GType afrodite_parser_get_type (void) G_GNUC_CONST;
gpointer afrodite_source_item_ref (gpointer instance);
void afrodite_source_item_unref (gpointer instance);
GParamSpec* afrodite_param_spec_source_item (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void afrodite_value_set_source_item (GValue* value, gpointer v_object);
void afrodite_value_take_source_item (GValue* value, gpointer v_object);
gpointer afrodite_value_get_source_item (const GValue* value);
GType afrodite_source_item_get_type (void) G_GNUC_CONST;
#define AFRODITE_PARSER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AFRODITE_TYPE_PARSER, AfroditeParserPrivate))
enum  {
	AFRODITE_PARSER_DUMMY_PROPERTY
};
AfroditeParser* afrodite_parser_new_with_source (AfroditeSourceItem* source_item);
AfroditeParser* afrodite_parser_construct_with_source (GType object_type, AfroditeSourceItem* source_item);
static void afrodite_parser_add_source_item (AfroditeParser* self, AfroditeSourceItem* source);
GType afrodite_source_type_get_type (void) G_GNUC_CONST;
const gchar* afrodite_source_item_get_path (AfroditeSourceItem* self);
GType afrodite_parse_result_get_type (void) G_GNUC_CONST;
AfroditeParseResult* afrodite_parser_parse (AfroditeParser* self);
AfroditeParseResult* afrodite_parse_result_new (void);
AfroditeParseResult* afrodite_parse_result_construct (GType object_type);
AfroditeParser* afrodite_parser_new (void);
AfroditeParser* afrodite_parser_construct (GType object_type);
static void afrodite_parser_finalize (GObject* obj);


AfroditeParser* afrodite_parser_construct_with_source (GType object_type, AfroditeSourceItem* source_item) {
	AfroditeParser * self = NULL;
	ValaCodeContext* _tmp0_ = NULL;
	g_return_val_if_fail (source_item != NULL, NULL);
	self = (AfroditeParser*) g_object_new (object_type, NULL);
	_tmp0_ = vala_code_context_new ();
	_vala_code_context_unref0 (self->priv->context);
	self->priv->context = _tmp0_;
	afrodite_parser_add_source_item (self, source_item);
	self->priv->_source = source_item;
	return self;
}


AfroditeParser* afrodite_parser_new_with_source (AfroditeSourceItem* source_item) {
	return afrodite_parser_construct_with_source (AFRODITE_TYPE_PARSER, source_item);
}


static void afrodite_parser_add_source_item (AfroditeParser* self, AfroditeSourceItem* source) {
	ValaSourceFile* source_file;
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	source_file = NULL;
	if (source->content == NULL) {
		const gchar* _tmp1_ = NULL;
		gboolean _tmp2_;
		_tmp1_ = afrodite_source_item_get_path (source);
		_tmp2_ = g_file_test (_tmp1_, G_FILE_TEST_EXISTS);
		_tmp0_ = !_tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		const gchar* _tmp3_ = NULL;
		_tmp3_ = afrodite_source_item_get_path (source);
		g_warning ("parser.vala:45: file %s not exists", _tmp3_);
		_vala_source_file_unref0 (source_file);
		return;
	}
	if (source->content == NULL) {
		ValaSourceFileType _tmp4_ = 0;
		const gchar* _tmp5_ = NULL;
		ValaSourceFile* _tmp6_ = NULL;
		if (source->source_type == AFRODITE_SOURCE_TYPE_VAPI) {
			_tmp4_ = VALA_SOURCE_FILE_TYPE_PACKAGE;
		} else {
			_tmp4_ = VALA_SOURCE_FILE_TYPE_SOURCE;
		}
		_tmp5_ = afrodite_source_item_get_path (source);
		_tmp6_ = vala_source_file_new (self->priv->context, _tmp4_, _tmp5_, NULL);
		_vala_source_file_unref0 (source_file);
		source_file = _tmp6_;
	} else {
		if (g_strcmp0 (source->content, "") != 0) {
			ValaSourceFileType _tmp7_ = 0;
			const gchar* _tmp8_ = NULL;
			ValaSourceFile* _tmp9_ = NULL;
			if (source->source_type == AFRODITE_SOURCE_TYPE_VAPI) {
				_tmp7_ = VALA_SOURCE_FILE_TYPE_PACKAGE;
			} else {
				_tmp7_ = VALA_SOURCE_FILE_TYPE_SOURCE;
			}
			_tmp8_ = afrodite_source_item_get_path (source);
			_tmp9_ = vala_source_file_new (self->priv->context, _tmp7_, _tmp8_, source->content);
			_vala_source_file_unref0 (source_file);
			source_file = _tmp9_;
		}
	}
	if (source_file != NULL) {
		ValaUnresolvedSymbol* _tmp10_ = NULL;
		ValaUnresolvedSymbol* _tmp11_;
		ValaUsingDirective* _tmp12_ = NULL;
		ValaUsingDirective* _tmp13_;
		ValaUsingDirective* ns_ref;
		_tmp10_ = vala_unresolved_symbol_new (NULL, "GLib", NULL);
		_tmp11_ = _tmp10_;
		_tmp12_ = vala_using_directive_new ((ValaSymbol*) _tmp11_, NULL);
		_tmp13_ = _tmp12_;
		_vala_code_node_unref0 (_tmp11_);
		ns_ref = _tmp13_;
		if (!source->is_glib) {
			ValaNamespace* _tmp14_ = NULL;
			_tmp14_ = vala_code_context_get_root (self->priv->context);
			vala_namespace_add_using_directive (_tmp14_, ns_ref);
		}
		vala_code_context_add_source_file (self->priv->context, source_file);
		if (!source->is_glib) {
			vala_source_file_add_using_directive (source_file, ns_ref);
		}
		_vala_code_node_unref0 (ns_ref);
	}
	_vala_source_file_unref0 (source_file);
}


static gpointer _vala_code_context_ref0 (gpointer self) {
	return self ? vala_code_context_ref (self) : NULL;
}


AfroditeParseResult* afrodite_parser_parse (AfroditeParser* self) {
	AfroditeParseResult* result = NULL;
	AfroditeParseResult* _tmp0_ = NULL;
	AfroditeParseResult* parse_result;
	gint glib_major;
	gint glib_minor;
	const gchar* _tmp9_ = NULL;
	gchar* _tmp10_;
	ValaCodeContext* _tmp11_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = afrodite_parse_result_new ();
	parse_result = _tmp0_;
	vala_code_context_push (self->priv->context);
	vala_code_context_set_assert (self->priv->context, FALSE);
	vala_code_context_set_checking (self->priv->context, FALSE);
	vala_code_context_set_experimental (self->priv->context, FALSE);
	vala_code_context_set_experimental_non_null (self->priv->context, FALSE);
	vala_code_context_set_compile_only (self->priv->context, TRUE);
	vala_code_context_set_report (self->priv->context, (ValaReport*) parse_result);
	vala_code_context_set_profile (self->priv->context, VALA_PROFILE_GOBJECT);
	vala_code_context_add_define (self->priv->context, "GOBJECT");
	glib_major = 2;
	glib_minor = 16;
	vala_code_context_set_target_glib_major (self->priv->context, glib_major);
	vala_code_context_set_target_glib_minor (self->priv->context, glib_minor);
	{
		gint i;
		i = 2;
		{
			gboolean _tmp1_;
			_tmp1_ = TRUE;
			while (TRUE) {
				gchar* _tmp2_ = NULL;
				gchar* _tmp3_;
				if (!_tmp1_) {
					i = i + 2;
				}
				_tmp1_ = FALSE;
				if (!(i <= 12)) {
					break;
				}
				_tmp2_ = g_strdup_printf ("VALA_0_%d", i);
				_tmp3_ = _tmp2_;
				vala_code_context_add_define (self->priv->context, _tmp3_);
				_g_free0 (_tmp3_);
			}
		}
	}
	{
		gint i;
		i = 16;
		{
			gboolean _tmp4_;
			_tmp4_ = TRUE;
			while (TRUE) {
				gchar* _tmp5_ = NULL;
				gchar* _tmp6_;
				if (!_tmp4_) {
					i = i + 2;
				}
				_tmp4_ = FALSE;
				if (!(i <= glib_minor)) {
					break;
				}
				_tmp5_ = g_strdup_printf ("GLIB_2_%d", i);
				_tmp6_ = _tmp5_;
				vala_code_context_add_define (self->priv->context, _tmp6_);
				_g_free0 (_tmp6_);
			}
		}
	}
	if (self->priv->_source->source_type == AFRODITE_SOURCE_TYPE_GENIE) {
		ValaGenieParser* _tmp7_ = NULL;
		ValaGenieParser* parser;
		_tmp7_ = vala_genie_parser_new ();
		parser = _tmp7_;
		vala_genie_parser_parse (parser, self->priv->context);
		_vala_code_visitor_unref0 (parser);
	} else {
		ValaParser* _tmp8_ = NULL;
		ValaParser* parser;
		_tmp8_ = vala_parser_new ();
		parser = _tmp8_;
		vala_parser_parse (parser, self->priv->context);
		_vala_code_visitor_unref0 (parser);
	}
	vala_code_context_pop ();
	_tmp9_ = afrodite_source_item_get_path (self->priv->_source);
	_tmp10_ = g_strdup (_tmp9_);
	_g_free0 (parse_result->source_path);
	parse_result->source_path = _tmp10_;
	parse_result->is_glib = self->priv->_source->is_glib;
	parse_result->is_edited = self->priv->_source->content != NULL;
	_tmp11_ = _vala_code_context_ref0 (self->priv->context);
	_vala_code_context_unref0 (parse_result->context);
	parse_result->context = _tmp11_;
	result = parse_result;
	return result;
}


AfroditeParser* afrodite_parser_construct (GType object_type) {
	AfroditeParser * self = NULL;
	self = (AfroditeParser*) g_object_new (object_type, NULL);
	return self;
}


AfroditeParser* afrodite_parser_new (void) {
	return afrodite_parser_construct (AFRODITE_TYPE_PARSER);
}


static void afrodite_parser_class_init (AfroditeParserClass * klass) {
	afrodite_parser_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (AfroditeParserPrivate));
	G_OBJECT_CLASS (klass)->finalize = afrodite_parser_finalize;
}


static void afrodite_parser_instance_init (AfroditeParser * self) {
	self->priv = AFRODITE_PARSER_GET_PRIVATE (self);
	self->priv->context = NULL;
}


static void afrodite_parser_finalize (GObject* obj) {
	AfroditeParser * self;
	self = AFRODITE_PARSER (obj);
	_vala_code_context_unref0 (self->priv->context);
	G_OBJECT_CLASS (afrodite_parser_parent_class)->finalize (obj);
}


GType afrodite_parser_get_type (void) {
	static volatile gsize afrodite_parser_type_id__volatile = 0;
	if (g_once_init_enter (&afrodite_parser_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (AfroditeParserClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) afrodite_parser_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AfroditeParser), 0, (GInstanceInitFunc) afrodite_parser_instance_init, NULL };
		GType afrodite_parser_type_id;
		afrodite_parser_type_id = g_type_register_static (G_TYPE_OBJECT, "AfroditeParser", &g_define_type_info, 0);
		g_once_init_leave (&afrodite_parser_type_id__volatile, afrodite_parser_type_id);
	}
	return afrodite_parser_type_id__volatile;
}



