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

/* valavapigen.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 <glib.h>
#include <glib-object.h>
#include <vala.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <glib/gstdio.h>
#include <valagee.h>
#include <locale.h>
#include <version.h>


#define VALA_TYPE_VAPI_GEN (vala_vapi_gen_get_type ())
#define VALA_VAPI_GEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_VAPI_GEN, ValaVAPIGen))
#define VALA_VAPI_GEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_VAPI_GEN, ValaVAPIGenClass))
#define VALA_IS_VAPI_GEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_VAPI_GEN))
#define VALA_IS_VAPI_GEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_VAPI_GEN))
#define VALA_VAPI_GEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_VAPI_GEN, ValaVAPIGenClass))

typedef struct _ValaVAPIGen ValaVAPIGen;
typedef struct _ValaVAPIGenClass ValaVAPIGenClass;
typedef struct _ValaVAPIGenPrivate ValaVAPIGenPrivate;
#define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_source_file_unref0(var) ((var == NULL) ? NULL : (var = (vala_source_file_unref (var), NULL)))
#define _vala_code_visitor_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_visitor_unref (var), NULL)))

#define VALA_TYPE_GIDL_PARSER (vala_gidl_parser_get_type ())
#define VALA_GIDL_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_GIDL_PARSER, ValaGIdlParser))
#define VALA_GIDL_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_GIDL_PARSER, ValaGIdlParserClass))
#define VALA_IS_GIDL_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_GIDL_PARSER))
#define VALA_IS_GIDL_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_GIDL_PARSER))
#define VALA_GIDL_PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_GIDL_PARSER, ValaGIdlParserClass))

typedef struct _ValaGIdlParser ValaGIdlParser;
typedef struct _ValaGIdlParserClass ValaGIdlParserClass;
#define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _ValaVAPIGen {
	GObject parent_instance;
	ValaVAPIGenPrivate * priv;
};

struct _ValaVAPIGenClass {
	GObjectClass parent_class;
};

struct _ValaVAPIGenPrivate {
	ValaCodeContext* context;
};


static gpointer vala_vapi_gen_parent_class = NULL;
static gchar* vala_vapi_gen_directory;
static gchar* vala_vapi_gen_directory = NULL;
static gboolean vala_vapi_gen_version;
static gboolean vala_vapi_gen_version = FALSE;
static gboolean vala_vapi_gen_quiet_mode;
static gboolean vala_vapi_gen_quiet_mode = FALSE;
static gboolean vala_vapi_gen_disable_warnings;
static gboolean vala_vapi_gen_disable_warnings = FALSE;
static gchar** vala_vapi_gen_sources;
static gchar** vala_vapi_gen_sources = NULL;
static gchar** vala_vapi_gen_vapi_directories;
static gchar** vala_vapi_gen_vapi_directories = NULL;
static gchar** vala_vapi_gen_gir_directories;
static gchar** vala_vapi_gen_gir_directories = NULL;
static gchar** vala_vapi_gen_metadata_directories;
static gchar** vala_vapi_gen_metadata_directories = NULL;
static gchar* vala_vapi_gen_library;
static gchar* vala_vapi_gen_library = NULL;
static gchar** vala_vapi_gen_packages;
static gchar** vala_vapi_gen_packages = NULL;
static gboolean vala_vapi_gen_nostdpkg;
static gboolean vala_vapi_gen_nostdpkg = FALSE;

G_GNUC_INTERNAL GType vala_vapi_gen_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
#define VALA_VAPI_GEN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_VAPI_GEN, ValaVAPIGenPrivate))
enum  {
	VALA_VAPI_GEN_DUMMY_PROPERTY
};
static gint vala_vapi_gen_quit (ValaVAPIGen* self);
static gint vala_vapi_gen_run (ValaVAPIGen* self);
static gchar** _vala_array_dup1 (gchar** self, int length);
static gchar** _vala_array_dup2 (gchar** self, int length);
static gchar** _vala_array_dup3 (gchar** self, int length);
GType vala_gidl_parser_get_type (void) G_GNUC_CONST;
ValaGIdlParser* vala_gidl_parser_new (void);
ValaGIdlParser* vala_gidl_parser_construct (GType object_type);
void vala_gidl_parser_parse (ValaGIdlParser* self, ValaCodeContext* context);
static gboolean _vala_string_array_contains (gchar* * stack, int stack_length, gchar* needle);
static gint vala_vapi_gen_main (gchar** args, int args_length1);
G_GNUC_INTERNAL ValaVAPIGen* vala_vapi_gen_new (void);
G_GNUC_INTERNAL ValaVAPIGen* vala_vapi_gen_construct (GType object_type);
static void vala_vapi_gen_finalize (GObject * obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);

static const GOptionEntry VALA_VAPI_GEN_options[12] = {{"vapidir", (gchar) 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &vala_vapi_gen_vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..."}, {"girdir", (gchar) 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &vala_vapi_gen_gir_directories, "Look for GIR bindings in DIRECTORY", "DIRECTORY..."}, {"metadatadir", (gchar) 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &vala_vapi_gen_metadata_directories, "Look for GIR .metadata files in DIRECTORY", "DIRECTORY..."}, {"nostdpkg", (gchar) 0, 0, G_OPTION_ARG_NONE, &vala_vapi_gen_nostdpkg, "Do not include standard packages", NULL}, {"pkg", (gchar) 0, 0, G_OPTION_ARG_STRING_ARRAY, &vala_vapi_gen_packages, "Include binding for PACKAGE", "PACKAGE..."}, {"library", (gchar) 0, 0, G_OPTION_ARG_STRING, &vala_vapi_gen_library, "Library name", "NAME"}, {"directory", 'd', 0, G_OPTION_ARG_FILENAME, &vala_vapi_gen_directory, "Output directory", "DIRECTORY"}, {"disable-warnings", (gchar) 0, 0, G_OPTION_ARG_NONE, &vala_vapi_gen_disable_warnings, "Disable warnings", NULL}, {"version", (gchar) 0, 0, G_OPTION_ARG_NONE, &vala_vapi_gen_version, "Display version number", NULL}, {"quiet", 'q', 0, G_OPTION_ARG_NONE, &vala_vapi_gen_quiet_mode, "Do not print messages to the console", NULL}, {"", (gchar) 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &vala_vapi_gen_sources, NULL, "FILE..."}, {NULL}};

static gint vala_vapi_gen_quit (ValaVAPIGen* self) {
	gint result = 0;
	ValaCodeContext* _tmp0_;
	ValaReport* _tmp1_;
	ValaReport* _tmp2_;
	gint _tmp3_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->context;
	_tmp1_ = vala_code_context_get_report (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = vala_report_get_errors (_tmp2_);
	if (_tmp3_ == 0) {
		gboolean _tmp4_;
		_tmp4_ = vala_vapi_gen_quiet_mode;
		if (!_tmp4_) {
			FILE* _tmp5_;
			ValaCodeContext* _tmp6_;
			ValaReport* _tmp7_;
			ValaReport* _tmp8_;
			gint _tmp9_;
			_tmp5_ = stdout;
			_tmp6_ = self->priv->context;
			_tmp7_ = vala_code_context_get_report (_tmp6_);
			_tmp8_ = _tmp7_;
			_tmp9_ = vala_report_get_warnings (_tmp8_);
			fprintf (_tmp5_, "Generation succeeded - %d warning(s)\n", _tmp9_);
		}
		result = 0;
		return result;
	} else {
		gboolean _tmp10_;
		_tmp10_ = vala_vapi_gen_quiet_mode;
		if (!_tmp10_) {
			FILE* _tmp11_;
			ValaCodeContext* _tmp12_;
			ValaReport* _tmp13_;
			ValaReport* _tmp14_;
			gint _tmp15_;
			ValaCodeContext* _tmp16_;
			ValaReport* _tmp17_;
			ValaReport* _tmp18_;
			gint _tmp19_;
			_tmp11_ = stdout;
			_tmp12_ = self->priv->context;
			_tmp13_ = vala_code_context_get_report (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = vala_report_get_errors (_tmp14_);
			_tmp16_ = self->priv->context;
			_tmp17_ = vala_code_context_get_report (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = vala_report_get_warnings (_tmp18_);
			fprintf (_tmp11_, "Generation failed: %d error(s), %d warning(s)\n", _tmp15_, _tmp19_);
		}
		result = 1;
		return result;
	}
}


static gchar** _vala_array_dup1 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static gchar** _vala_array_dup2 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static gchar** _vala_array_dup3 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static glong string_strnlen (gchar* str, glong maxlen) {
	glong result = 0L;
	gchar* end = NULL;
	gchar* _tmp0_;
	glong _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = str;
	_tmp1_ = maxlen;
	_tmp2_ = memchr (_tmp0_, 0, (gsize) _tmp1_);
	end = _tmp2_;
	_tmp3_ = end;
	if (_tmp3_ == NULL) {
		glong _tmp4_;
		_tmp4_ = maxlen;
		result = _tmp4_;
		return result;
	} else {
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = end;
		_tmp6_ = str;
		result = (glong) (_tmp5_ - _tmp6_);
		return result;
	}
}


static gchar* string_substring (const gchar* self, glong offset, glong len) {
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	glong _tmp1_;
	glong _tmp8_;
	glong _tmp14_;
	glong _tmp17_;
	glong _tmp18_;
	glong _tmp19_;
	glong _tmp20_;
	glong _tmp21_;
	gchar* _tmp22_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = offset;
	if (_tmp1_ >= ((glong) 0)) {
		glong _tmp2_;
		_tmp2_ = len;
		_tmp0_ = _tmp2_ >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		glong _tmp3_;
		glong _tmp4_;
		glong _tmp5_;
		_tmp3_ = offset;
		_tmp4_ = len;
		_tmp5_ = string_strnlen ((gchar*) self, _tmp3_ + _tmp4_);
		string_length = _tmp5_;
	} else {
		gint _tmp6_;
		gint _tmp7_;
		_tmp6_ = strlen (self);
		_tmp7_ = _tmp6_;
		string_length = (glong) _tmp7_;
	}
	_tmp8_ = offset;
	if (_tmp8_ < ((glong) 0)) {
		glong _tmp9_;
		glong _tmp10_;
		glong _tmp11_;
		_tmp9_ = string_length;
		_tmp10_ = offset;
		offset = _tmp9_ + _tmp10_;
		_tmp11_ = offset;
		g_return_val_if_fail (_tmp11_ >= ((glong) 0), NULL);
	} else {
		glong _tmp12_;
		glong _tmp13_;
		_tmp12_ = offset;
		_tmp13_ = string_length;
		g_return_val_if_fail (_tmp12_ <= _tmp13_, NULL);
	}
	_tmp14_ = len;
	if (_tmp14_ < ((glong) 0)) {
		glong _tmp15_;
		glong _tmp16_;
		_tmp15_ = string_length;
		_tmp16_ = offset;
		len = _tmp15_ - _tmp16_;
	}
	_tmp17_ = offset;
	_tmp18_ = len;
	_tmp19_ = string_length;
	g_return_val_if_fail ((_tmp17_ + _tmp18_) <= _tmp19_, NULL);
	_tmp20_ = offset;
	_tmp21_ = len;
	_tmp22_ = g_strndup (((gchar*) self) + _tmp20_, (gsize) _tmp21_);
	result = _tmp22_;
	return result;
}


static gboolean _vala_string_array_contains (gchar* * stack, int stack_length, gchar* needle) {
	int i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


static gint vala_vapi_gen_run (ValaVAPIGen* self) {
	gint result = 0;
	ValaCodeContext* _tmp0_;
	ValaCodeContext* _tmp1_;
	ValaCodeContext* _tmp2_;
	gchar** _tmp3_;
	gint _tmp3__length1;
	gchar** _tmp4_;
	gint _tmp4__length1;
	ValaCodeContext* _tmp5_;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar** _tmp7_;
	gint _tmp7__length1;
	ValaCodeContext* _tmp8_;
	gchar** _tmp9_;
	gint _tmp9__length1;
	gchar** _tmp10_;
	gint _tmp10__length1;
	ValaCodeContext* _tmp11_;
	ValaReport* _tmp12_;
	ValaReport* _tmp13_;
	gboolean _tmp14_;
	ValaCodeContext* _tmp15_;
	ValaReport* _tmp16_;
	ValaReport* _tmp17_;
	gboolean _tmp18_;
	ValaCodeContext* _tmp19_;
	ValaCodeContext* _tmp20_;
	gboolean _tmp21_;
	gboolean _tmp22_;
	ValaCodeContext* _tmp25_;
	ValaReport* _tmp26_;
	ValaReport* _tmp27_;
	gint _tmp28_;
	gchar** _tmp30_;
	gint _tmp30__length1;
	ValaCodeContext* _tmp46_;
	ValaReport* _tmp47_;
	ValaReport* _tmp48_;
	gint _tmp49_;
	const gchar* _tmp51_;
	ValaCodeContext* _tmp56_;
	ValaReport* _tmp57_;
	ValaReport* _tmp58_;
	gint _tmp59_;
	gchar** _tmp61_;
	gint _tmp61__length1;
	ValaCodeContext* _tmp66_;
	ValaReport* _tmp67_;
	ValaReport* _tmp68_;
	gint _tmp69_;
	gchar** _tmp71_;
	gint _tmp71__length1;
	ValaCodeContext* _tmp83_;
	ValaReport* _tmp84_;
	ValaReport* _tmp85_;
	gint _tmp86_;
	ValaParser* parser = NULL;
	ValaParser* _tmp88_;
	ValaParser* _tmp89_;
	ValaCodeContext* _tmp90_;
	ValaCodeContext* _tmp91_;
	ValaReport* _tmp92_;
	ValaReport* _tmp93_;
	gint _tmp94_;
	ValaGirParser* girparser = NULL;
	ValaGirParser* _tmp96_;
	ValaGirParser* _tmp97_;
	ValaCodeContext* _tmp98_;
	ValaCodeContext* _tmp99_;
	ValaReport* _tmp100_;
	ValaReport* _tmp101_;
	gint _tmp102_;
	ValaGIdlParser* gidlparser = NULL;
	ValaGIdlParser* _tmp104_;
	ValaGIdlParser* _tmp105_;
	ValaCodeContext* _tmp106_;
	ValaCodeContext* _tmp107_;
	ValaReport* _tmp108_;
	ValaReport* _tmp109_;
	gint _tmp110_;
	ValaCodeContext* _tmp112_;
	ValaCodeContext* _tmp113_;
	ValaReport* _tmp114_;
	ValaReport* _tmp115_;
	gint _tmp116_;
	ValaCodeWriter* interface_writer = NULL;
	ValaCodeWriter* _tmp164_;
	gchar* vapi_filename = NULL;
	const gchar* _tmp165_;
	gchar* _tmp166_;
	const gchar* _tmp167_;
	ValaCodeWriter* _tmp171_;
	ValaCodeContext* _tmp172_;
	const gchar* _tmp173_;
	gint _tmp174_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = vala_code_context_new ();
	_vala_code_context_unref0 (self->priv->context);
	self->priv->context = _tmp0_;
	_tmp1_ = self->priv->context;
	vala_code_context_set_profile (_tmp1_, VALA_PROFILE_GOBJECT);
	_tmp2_ = self->priv->context;
	_tmp3_ = vala_vapi_gen_vapi_directories;
	_tmp3__length1 = _vala_array_length (vala_vapi_gen_vapi_directories);
	_tmp4_ = (_tmp3_ != NULL) ? _vala_array_dup1 (_tmp3_, _tmp3__length1) : ((gpointer) _tmp3_);
	_tmp4__length1 = _tmp3__length1;
	_tmp2_->vapi_directories = (_vala_array_free (_tmp2_->vapi_directories, _tmp2_->vapi_directories_length1, (GDestroyNotify) g_free), NULL);
	_tmp2_->vapi_directories = _tmp4_;
	_tmp2_->vapi_directories_length1 = _tmp4__length1;
	_tmp5_ = self->priv->context;
	_tmp6_ = vala_vapi_gen_gir_directories;
	_tmp6__length1 = _vala_array_length (vala_vapi_gen_gir_directories);
	_tmp7_ = (_tmp6_ != NULL) ? _vala_array_dup2 (_tmp6_, _tmp6__length1) : ((gpointer) _tmp6_);
	_tmp7__length1 = _tmp6__length1;
	_tmp5_->gir_directories = (_vala_array_free (_tmp5_->gir_directories, _tmp5_->gir_directories_length1, (GDestroyNotify) g_free), NULL);
	_tmp5_->gir_directories = _tmp7_;
	_tmp5_->gir_directories_length1 = _tmp7__length1;
	_tmp8_ = self->priv->context;
	_tmp9_ = vala_vapi_gen_metadata_directories;
	_tmp9__length1 = _vala_array_length (vala_vapi_gen_metadata_directories);
	_tmp10_ = (_tmp9_ != NULL) ? _vala_array_dup3 (_tmp9_, _tmp9__length1) : ((gpointer) _tmp9_);
	_tmp10__length1 = _tmp9__length1;
	_tmp8_->metadata_directories = (_vala_array_free (_tmp8_->metadata_directories, _tmp8_->metadata_directories_length1, (GDestroyNotify) g_free), NULL);
	_tmp8_->metadata_directories = _tmp10_;
	_tmp8_->metadata_directories_length1 = _tmp10__length1;
	_tmp11_ = self->priv->context;
	_tmp12_ = vala_code_context_get_report (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = vala_vapi_gen_disable_warnings;
	vala_report_set_enable_warnings (_tmp13_, !_tmp14_);
	_tmp15_ = self->priv->context;
	_tmp16_ = vala_code_context_get_report (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = vala_vapi_gen_quiet_mode;
	vala_report_set_verbose_errors (_tmp17_, !_tmp18_);
	_tmp19_ = self->priv->context;
	vala_code_context_push (_tmp19_);
	_tmp20_ = self->priv->context;
	_tmp21_ = vala_vapi_gen_nostdpkg;
	vala_code_context_set_nostdpkg (_tmp20_, _tmp21_);
	_tmp22_ = vala_vapi_gen_nostdpkg;
	if (!_tmp22_) {
		ValaCodeContext* _tmp23_;
		ValaCodeContext* _tmp24_;
		_tmp23_ = self->priv->context;
		vala_code_context_add_external_package (_tmp23_, "glib-2.0");
		_tmp24_ = self->priv->context;
		vala_code_context_add_external_package (_tmp24_, "gobject-2.0");
	}
	_tmp25_ = self->priv->context;
	_tmp26_ = vala_code_context_get_report (_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp28_ = vala_report_get_errors (_tmp27_);
	if (_tmp28_ > 0) {
		gint _tmp29_;
		_tmp29_ = vala_vapi_gen_quit (self);
		result = _tmp29_;
		return result;
	}
	_tmp30_ = vala_vapi_gen_sources;
	_tmp30__length1 = _vala_array_length (vala_vapi_gen_sources);
	{
		gchar** source_collection = NULL;
		gint source_collection_length1 = 0;
		gint _source_collection_size_ = 0;
		gint source_it = 0;
		source_collection = _tmp30_;
		source_collection_length1 = _tmp30__length1;
		for (source_it = 0; source_it < _tmp30__length1; source_it = source_it + 1) {
			gchar* _tmp31_;
			gchar* source = NULL;
			_tmp31_ = g_strdup (source_collection[source_it]);
			source = _tmp31_;
			{
				const gchar* _tmp32_;
				gboolean _tmp33_;
				gchar* depsfile = NULL;
				const gchar* _tmp34_;
				const gchar* _tmp35_;
				gint _tmp36_;
				gint _tmp37_;
				gint _tmp38_;
				gint _tmp39_;
				gchar* _tmp40_;
				gchar* _tmp41_;
				gchar* _tmp42_;
				gchar* _tmp43_;
				ValaCodeContext* _tmp44_;
				const gchar* _tmp45_;
				_tmp32_ = source;
				_tmp33_ = g_str_has_suffix (_tmp32_, ".gi");
				if (!_tmp33_) {
					_g_free0 (source);
					continue;
				}
				_tmp34_ = source;
				_tmp35_ = source;
				_tmp36_ = strlen (_tmp35_);
				_tmp37_ = _tmp36_;
				_tmp38_ = strlen ("gi");
				_tmp39_ = _tmp38_;
				_tmp40_ = string_substring (_tmp34_, (glong) 0, (glong) (_tmp37_ - _tmp39_));
				_tmp41_ = _tmp40_;
				_tmp42_ = g_strconcat (_tmp41_, "deps", NULL);
				_tmp43_ = _tmp42_;
				_g_free0 (_tmp41_);
				depsfile = _tmp43_;
				_tmp44_ = self->priv->context;
				_tmp45_ = depsfile;
				vala_code_context_add_packages_from_file (_tmp44_, _tmp45_);
				_g_free0 (depsfile);
				_g_free0 (source);
			}
		}
	}
	_tmp46_ = self->priv->context;
	_tmp47_ = vala_code_context_get_report (_tmp46_);
	_tmp48_ = _tmp47_;
	_tmp49_ = vala_report_get_errors (_tmp48_);
	if (_tmp49_ > 0) {
		gint _tmp50_;
		_tmp50_ = vala_vapi_gen_quit (self);
		result = _tmp50_;
		return result;
	}
	_tmp51_ = vala_vapi_gen_library;
	if (_tmp51_ != NULL) {
		gchar* depsfile = NULL;
		const gchar* _tmp52_;
		gchar* _tmp53_;
		ValaCodeContext* _tmp54_;
		const gchar* _tmp55_;
		_tmp52_ = vala_vapi_gen_library;
		_tmp53_ = g_strconcat (_tmp52_, ".deps", NULL);
		depsfile = _tmp53_;
		_tmp54_ = self->priv->context;
		_tmp55_ = depsfile;
		vala_code_context_add_packages_from_file (_tmp54_, _tmp55_);
		_g_free0 (depsfile);
	} else {
		vala_report_error (NULL, "--library option must be specified");
	}
	_tmp56_ = self->priv->context;
	_tmp57_ = vala_code_context_get_report (_tmp56_);
	_tmp58_ = _tmp57_;
	_tmp59_ = vala_report_get_errors (_tmp58_);
	if (_tmp59_ > 0) {
		gint _tmp60_;
		_tmp60_ = vala_vapi_gen_quit (self);
		result = _tmp60_;
		return result;
	}
	_tmp61_ = vala_vapi_gen_packages;
	_tmp61__length1 = _vala_array_length (vala_vapi_gen_packages);
	if (_tmp61_ != NULL) {
		gchar** _tmp62_;
		gint _tmp62__length1;
		_tmp62_ = vala_vapi_gen_packages;
		_tmp62__length1 = _vala_array_length (vala_vapi_gen_packages);
		{
			gchar** package_collection = NULL;
			gint package_collection_length1 = 0;
			gint _package_collection_size_ = 0;
			gint package_it = 0;
			package_collection = _tmp62_;
			package_collection_length1 = _tmp62__length1;
			for (package_it = 0; package_it < _tmp62__length1; package_it = package_it + 1) {
				gchar* _tmp63_;
				gchar* package = NULL;
				_tmp63_ = g_strdup (package_collection[package_it]);
				package = _tmp63_;
				{
					ValaCodeContext* _tmp64_;
					const gchar* _tmp65_;
					_tmp64_ = self->priv->context;
					_tmp65_ = package;
					vala_code_context_add_external_package (_tmp64_, _tmp65_);
					_g_free0 (package);
				}
			}
		}
		vala_vapi_gen_packages = (_vala_array_free (vala_vapi_gen_packages, _vala_array_length (vala_vapi_gen_packages), (GDestroyNotify) g_free), NULL);
		vala_vapi_gen_packages = NULL;
	}
	_tmp66_ = self->priv->context;
	_tmp67_ = vala_code_context_get_report (_tmp66_);
	_tmp68_ = _tmp67_;
	_tmp69_ = vala_report_get_errors (_tmp68_);
	if (_tmp69_ > 0) {
		gint _tmp70_;
		_tmp70_ = vala_vapi_gen_quit (self);
		result = _tmp70_;
		return result;
	}
	_tmp71_ = vala_vapi_gen_sources;
	_tmp71__length1 = _vala_array_length (vala_vapi_gen_sources);
	{
		gchar** source_collection = NULL;
		gint source_collection_length1 = 0;
		gint _source_collection_size_ = 0;
		gint source_it = 0;
		source_collection = _tmp71_;
		source_collection_length1 = _tmp71__length1;
		for (source_it = 0; source_it < _tmp71__length1; source_it = source_it + 1) {
			gchar* _tmp72_;
			gchar* source = NULL;
			_tmp72_ = g_strdup (source_collection[source_it]);
			source = _tmp72_;
			{
				const gchar* _tmp73_;
				gboolean _tmp74_;
				_tmp73_ = source;
				_tmp74_ = g_file_test (_tmp73_, G_FILE_TEST_EXISTS);
				if (_tmp74_) {
					ValaCodeContext* _tmp75_;
					ValaCodeContext* _tmp76_;
					const gchar* _tmp77_;
					ValaSourceFile* _tmp78_;
					ValaSourceFile* _tmp79_;
					_tmp75_ = self->priv->context;
					_tmp76_ = self->priv->context;
					_tmp77_ = source;
					_tmp78_ = vala_source_file_new (_tmp76_, VALA_SOURCE_FILE_TYPE_PACKAGE, _tmp77_, NULL, FALSE);
					_tmp79_ = _tmp78_;
					vala_code_context_add_source_file (_tmp75_, _tmp79_);
					_vala_source_file_unref0 (_tmp79_);
				} else {
					const gchar* _tmp80_;
					gchar* _tmp81_;
					gchar* _tmp82_;
					_tmp80_ = source;
					_tmp81_ = g_strdup_printf ("%s not found", _tmp80_);
					_tmp82_ = _tmp81_;
					vala_report_error (NULL, _tmp82_);
					_g_free0 (_tmp82_);
				}
				_g_free0 (source);
			}
		}
	}
	_tmp83_ = self->priv->context;
	_tmp84_ = vala_code_context_get_report (_tmp83_);
	_tmp85_ = _tmp84_;
	_tmp86_ = vala_report_get_errors (_tmp85_);
	if (_tmp86_ > 0) {
		gint _tmp87_;
		_tmp87_ = vala_vapi_gen_quit (self);
		result = _tmp87_;
		return result;
	}
	_tmp88_ = vala_parser_new ();
	parser = _tmp88_;
	_tmp89_ = parser;
	_tmp90_ = self->priv->context;
	vala_parser_parse (_tmp89_, _tmp90_);
	_tmp91_ = self->priv->context;
	_tmp92_ = vala_code_context_get_report (_tmp91_);
	_tmp93_ = _tmp92_;
	_tmp94_ = vala_report_get_errors (_tmp93_);
	if (_tmp94_ > 0) {
		gint _tmp95_;
		_tmp95_ = vala_vapi_gen_quit (self);
		result = _tmp95_;
		_vala_code_visitor_unref0 (parser);
		return result;
	}
	_tmp96_ = vala_gir_parser_new ();
	girparser = _tmp96_;
	_tmp97_ = girparser;
	_tmp98_ = self->priv->context;
	vala_gir_parser_parse (_tmp97_, _tmp98_);
	_tmp99_ = self->priv->context;
	_tmp100_ = vala_code_context_get_report (_tmp99_);
	_tmp101_ = _tmp100_;
	_tmp102_ = vala_report_get_errors (_tmp101_);
	if (_tmp102_ > 0) {
		gint _tmp103_;
		_tmp103_ = vala_vapi_gen_quit (self);
		result = _tmp103_;
		_vala_code_visitor_unref0 (girparser);
		_vala_code_visitor_unref0 (parser);
		return result;
	}
	_tmp104_ = vala_gidl_parser_new ();
	gidlparser = _tmp104_;
	_tmp105_ = gidlparser;
	_tmp106_ = self->priv->context;
	vala_gidl_parser_parse (_tmp105_, _tmp106_);
	_tmp107_ = self->priv->context;
	_tmp108_ = vala_code_context_get_report (_tmp107_);
	_tmp109_ = _tmp108_;
	_tmp110_ = vala_report_get_errors (_tmp109_);
	if (_tmp110_ > 0) {
		gint _tmp111_;
		_tmp111_ = vala_vapi_gen_quit (self);
		result = _tmp111_;
		_vala_code_visitor_unref0 (gidlparser);
		_vala_code_visitor_unref0 (girparser);
		_vala_code_visitor_unref0 (parser);
		return result;
	}
	_tmp112_ = self->priv->context;
	vala_code_context_check (_tmp112_);
	_tmp113_ = self->priv->context;
	_tmp114_ = vala_code_context_get_report (_tmp113_);
	_tmp115_ = _tmp114_;
	_tmp116_ = vala_report_get_errors (_tmp115_);
	if (_tmp116_ > 0) {
		gint _tmp117_;
		_tmp117_ = vala_vapi_gen_quit (self);
		result = _tmp117_;
		_vala_code_visitor_unref0 (gidlparser);
		_vala_code_visitor_unref0 (girparser);
		_vala_code_visitor_unref0 (parser);
		return result;
	}
	{
		ValaList* _file_list = NULL;
		ValaCodeContext* _tmp118_;
		ValaList* _tmp119_;
		gint _file_size = 0;
		ValaList* _tmp120_;
		gint _tmp121_;
		gint _tmp122_;
		gint _file_index = 0;
		_tmp118_ = self->priv->context;
		_tmp119_ = vala_code_context_get_source_files (_tmp118_);
		_file_list = _tmp119_;
		_tmp120_ = _file_list;
		_tmp121_ = vala_collection_get_size ((ValaCollection*) _tmp120_);
		_tmp122_ = _tmp121_;
		_file_size = _tmp122_;
		_file_index = -1;
		while (TRUE) {
			gint _tmp123_;
			gint _tmp124_;
			gint _tmp125_;
			ValaSourceFile* file = NULL;
			ValaList* _tmp126_;
			gint _tmp127_;
			gpointer _tmp128_;
			ValaSourceFile* _tmp129_;
			const gchar* _tmp130_;
			const gchar* _tmp131_;
			gboolean _tmp132_;
			ValaSourceFile* _tmp133_;
			const gchar* _tmp134_;
			const gchar* _tmp135_;
			gchar** _tmp136_;
			gint _tmp136__length1;
			_tmp123_ = _file_index;
			_file_index = _tmp123_ + 1;
			_tmp124_ = _file_index;
			_tmp125_ = _file_size;
			if (!(_tmp124_ < _tmp125_)) {
				break;
			}
			_tmp126_ = _file_list;
			_tmp127_ = _file_index;
			_tmp128_ = vala_list_get (_tmp126_, _tmp127_);
			file = (ValaSourceFile*) _tmp128_;
			_tmp129_ = file;
			_tmp130_ = vala_source_file_get_filename (_tmp129_);
			_tmp131_ = _tmp130_;
			_tmp132_ = g_str_has_suffix (_tmp131_, ".vapi");
			if (_tmp132_) {
				_vala_source_file_unref0 (file);
				continue;
			}
			_tmp133_ = file;
			_tmp134_ = vala_source_file_get_filename (_tmp133_);
			_tmp135_ = _tmp134_;
			_tmp136_ = vala_vapi_gen_sources;
			_tmp136__length1 = _vala_array_length (vala_vapi_gen_sources);
			if (_vala_string_array_contains (_tmp136_, _tmp136__length1, _tmp135_)) {
				ValaSourceFile* _tmp137_;
				ValaSourceFile* _tmp138_;
				const gchar* _tmp139_;
				const gchar* _tmp140_;
				gboolean _tmp141_;
				_tmp137_ = file;
				vala_source_file_set_file_type (_tmp137_, VALA_SOURCE_FILE_TYPE_SOURCE);
				_tmp138_ = file;
				_tmp139_ = vala_source_file_get_filename (_tmp138_);
				_tmp140_ = _tmp139_;
				_tmp141_ = g_str_has_suffix (_tmp140_, ".gir");
				if (_tmp141_) {
					gchar* metadata_filename = NULL;
					ValaCodeContext* _tmp142_;
					ValaSourceFile* _tmp143_;
					const gchar* _tmp144_;
					const gchar* _tmp145_;
					gchar* _tmp146_;
					const gchar* _tmp147_;
					_tmp142_ = self->priv->context;
					_tmp143_ = file;
					_tmp144_ = vala_source_file_get_filename (_tmp143_);
					_tmp145_ = _tmp144_;
					_tmp146_ = vala_code_context_get_metadata_path (_tmp142_, _tmp145_);
					metadata_filename = _tmp146_;
					_tmp147_ = metadata_filename;
					if (_tmp147_ != NULL) {
						{
							ValaList* _metadata_file_list = NULL;
							ValaCodeContext* _tmp148_;
							ValaList* _tmp149_;
							gint _metadata_file_size = 0;
							ValaList* _tmp150_;
							gint _tmp151_;
							gint _tmp152_;
							gint _metadata_file_index = 0;
							_tmp148_ = self->priv->context;
							_tmp149_ = vala_code_context_get_source_files (_tmp148_);
							_metadata_file_list = _tmp149_;
							_tmp150_ = _metadata_file_list;
							_tmp151_ = vala_collection_get_size ((ValaCollection*) _tmp150_);
							_tmp152_ = _tmp151_;
							_metadata_file_size = _tmp152_;
							_metadata_file_index = -1;
							while (TRUE) {
								gint _tmp153_;
								gint _tmp154_;
								gint _tmp155_;
								ValaSourceFile* metadata_file = NULL;
								ValaList* _tmp156_;
								gint _tmp157_;
								gpointer _tmp158_;
								ValaSourceFile* _tmp159_;
								const gchar* _tmp160_;
								const gchar* _tmp161_;
								const gchar* _tmp162_;
								_tmp153_ = _metadata_file_index;
								_metadata_file_index = _tmp153_ + 1;
								_tmp154_ = _metadata_file_index;
								_tmp155_ = _metadata_file_size;
								if (!(_tmp154_ < _tmp155_)) {
									break;
								}
								_tmp156_ = _metadata_file_list;
								_tmp157_ = _metadata_file_index;
								_tmp158_ = vala_list_get (_tmp156_, _tmp157_);
								metadata_file = (ValaSourceFile*) _tmp158_;
								_tmp159_ = metadata_file;
								_tmp160_ = vala_source_file_get_filename (_tmp159_);
								_tmp161_ = _tmp160_;
								_tmp162_ = metadata_filename;
								if (g_strcmp0 (_tmp161_, _tmp162_) == 0) {
									ValaSourceFile* _tmp163_;
									_tmp163_ = metadata_file;
									vala_source_file_set_file_type (_tmp163_, VALA_SOURCE_FILE_TYPE_SOURCE);
								}
								_vala_source_file_unref0 (metadata_file);
							}
							_vala_iterable_unref0 (_metadata_file_list);
						}
					}
					_g_free0 (metadata_filename);
				}
			}
			_vala_source_file_unref0 (file);
		}
		_vala_iterable_unref0 (_file_list);
	}
	_tmp164_ = vala_code_writer_new (VALA_CODE_WRITER_TYPE_EXTERNAL);
	interface_writer = _tmp164_;
	_tmp165_ = vala_vapi_gen_library;
	_tmp166_ = g_strdup_printf ("%s.vapi", _tmp165_);
	vapi_filename = _tmp166_;
	_tmp167_ = vala_vapi_gen_directory;
	if (_tmp167_ != NULL) {
		const gchar* _tmp168_;
		const gchar* _tmp169_;
		gchar* _tmp170_;
		_tmp168_ = vala_vapi_gen_directory;
		_tmp169_ = vapi_filename;
		_tmp170_ = g_build_path ("/", _tmp168_, _tmp169_, NULL);
		_g_free0 (vapi_filename);
		vapi_filename = _tmp170_;
	}
	_tmp171_ = interface_writer;
	_tmp172_ = self->priv->context;
	_tmp173_ = vapi_filename;
	vala_code_writer_write_file (_tmp171_, _tmp172_, _tmp173_);
	_g_free0 (vala_vapi_gen_library);
	vala_vapi_gen_library = NULL;
	_tmp174_ = vala_vapi_gen_quit (self);
	result = _tmp174_;
	_g_free0 (vapi_filename);
	_vala_code_visitor_unref0 (interface_writer);
	_vala_code_visitor_unref0 (gidlparser);
	_vala_code_visitor_unref0 (girparser);
	_vala_code_visitor_unref0 (parser);
	return result;
}


static gint vala_vapi_gen_main (gchar** args, int args_length1) {
	gint result = 0;
	gboolean _tmp12_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	ValaVAPIGen* vapigen = NULL;
	ValaVAPIGen* _tmp16_;
	ValaVAPIGen* _tmp17_;
	gint _tmp18_;
	GError * _inner_error_ = NULL;
	setlocale (LC_ALL, "");
	{
		GOptionContext* opt_context = NULL;
		GOptionContext* _tmp0_;
		GOptionContext* _tmp1_;
		GOptionContext* _tmp2_;
		GOptionContext* _tmp3_;
		_tmp0_ = g_option_context_new ("- Vala API Generator");
		opt_context = _tmp0_;
		_tmp1_ = opt_context;
		g_option_context_set_help_enabled (_tmp1_, TRUE);
		_tmp2_ = opt_context;
		g_option_context_add_main_entries (_tmp2_, VALA_VAPI_GEN_options, NULL);
		_tmp3_ = opt_context;
		g_option_context_parse (_tmp3_, &args_length1, &args, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			gint _tmp4_ = 0;
			_g_option_context_free0 (opt_context);
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch3_g_option_error;
			}
			_g_option_context_free0 (opt_context);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return _tmp4_;
		}
		_g_option_context_free0 (opt_context);
	}
	goto __finally3;
	__catch3_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp5_;
		GError* _tmp6_;
		const gchar* _tmp7_;
		FILE* _tmp8_;
		gchar** _tmp9_;
		gint _tmp9__length1;
		const gchar* _tmp10_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = stdout;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		fprintf (_tmp5_, "%s\n", _tmp7_);
		_tmp8_ = stdout;
		_tmp9_ = args;
		_tmp9__length1 = args_length1;
		_tmp10_ = _tmp9_[0];
		fprintf (_tmp8_, "Run '%s --help' to see a full list of available command line options.\n", _tmp10_);
		result = 1;
		_g_error_free0 (e);
		return result;
	}
	__finally3:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gint _tmp11_ = 0;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return _tmp11_;
	}
	_tmp12_ = vala_vapi_gen_version;
	if (_tmp12_) {
		FILE* _tmp13_;
		_tmp13_ = stdout;
		fprintf (_tmp13_, "Vala API Generator %s\n", BUILD_VERSION);
		result = 0;
		return result;
	}
	_tmp14_ = vala_vapi_gen_sources;
	_tmp14__length1 = _vala_array_length (vala_vapi_gen_sources);
	if (_tmp14_ == NULL) {
		FILE* _tmp15_;
		_tmp15_ = stderr;
		fprintf (_tmp15_, "No source file specified.\n");
		result = 1;
		return result;
	}
	_tmp16_ = vala_vapi_gen_new ();
	vapigen = _tmp16_;
	_tmp17_ = vapigen;
	_tmp18_ = vala_vapi_gen_run (_tmp17_);
	result = _tmp18_;
	_g_object_unref0 (vapigen);
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	return vala_vapi_gen_main (argv, argc);
}


G_GNUC_INTERNAL ValaVAPIGen* vala_vapi_gen_construct (GType object_type) {
	ValaVAPIGen * self = NULL;
	self = (ValaVAPIGen*) g_object_new (object_type, NULL);
	return self;
}


G_GNUC_INTERNAL ValaVAPIGen* vala_vapi_gen_new (void) {
	return vala_vapi_gen_construct (VALA_TYPE_VAPI_GEN);
}


static void vala_vapi_gen_class_init (ValaVAPIGenClass * klass) {
	vala_vapi_gen_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ValaVAPIGenPrivate));
	G_OBJECT_CLASS (klass)->finalize = vala_vapi_gen_finalize;
}


static void vala_vapi_gen_instance_init (ValaVAPIGen * self) {
	self->priv = VALA_VAPI_GEN_GET_PRIVATE (self);
}


static void vala_vapi_gen_finalize (GObject * obj) {
	ValaVAPIGen * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_VAPI_GEN, ValaVAPIGen);
	_vala_code_context_unref0 (self->priv->context);
	G_OBJECT_CLASS (vala_vapi_gen_parent_class)->finalize (obj);
}


G_GNUC_INTERNAL GType vala_vapi_gen_get_type (void) {
	static volatile gsize vala_vapi_gen_type_id__volatile = 0;
	if (g_once_init_enter (&vala_vapi_gen_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaVAPIGenClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_vapi_gen_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaVAPIGen), 0, (GInstanceInitFunc) vala_vapi_gen_instance_init, NULL };
		GType vala_vapi_gen_type_id;
		vala_vapi_gen_type_id = g_type_register_static (G_TYPE_OBJECT, "ValaVAPIGen", &g_define_type_info, 0);
		g_once_init_leave (&vala_vapi_gen_type_id__volatile, vala_vapi_gen_type_id);
	}
	return vala_vapi_gen_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



