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

/* driver.vala
 *
 * Copyright (C) 2011  Florian Brosch
 *
 * 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:
 * 	Florian Brosch <flo.brosch@gmail.com>
 */

#include <glib.h>
#include <glib-object.h>
#include <valadoc.h>
#include <valacodegen.h>
#include <stdlib.h>
#include <string.h>
#include <vala.h>


#define VALADOC_DRIVERS_TYPE_DRIVER (valadoc_drivers_driver_get_type ())
#define VALADOC_DRIVERS_DRIVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALADOC_DRIVERS_TYPE_DRIVER, ValadocDriversDriver))
#define VALADOC_DRIVERS_DRIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALADOC_DRIVERS_TYPE_DRIVER, ValadocDriversDriverClass))
#define VALADOC_DRIVERS_IS_DRIVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALADOC_DRIVERS_TYPE_DRIVER))
#define VALADOC_DRIVERS_IS_DRIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALADOC_DRIVERS_TYPE_DRIVER))
#define VALADOC_DRIVERS_DRIVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALADOC_DRIVERS_TYPE_DRIVER, ValadocDriversDriverClass))

typedef struct _ValadocDriversDriver ValadocDriversDriver;
typedef struct _ValadocDriversDriverClass ValadocDriversDriverClass;
typedef struct _ValadocDriversDriverPrivate ValadocDriversDriverPrivate;

#define VALADOC_DRIVERS_TYPE_SYMBOL_RESOLVER (valadoc_drivers_symbol_resolver_get_type ())
#define VALADOC_DRIVERS_SYMBOL_RESOLVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALADOC_DRIVERS_TYPE_SYMBOL_RESOLVER, ValadocDriversSymbolResolver))
#define VALADOC_DRIVERS_SYMBOL_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALADOC_DRIVERS_TYPE_SYMBOL_RESOLVER, ValadocDriversSymbolResolverClass))
#define VALADOC_DRIVERS_IS_SYMBOL_RESOLVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALADOC_DRIVERS_TYPE_SYMBOL_RESOLVER))
#define VALADOC_DRIVERS_IS_SYMBOL_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALADOC_DRIVERS_TYPE_SYMBOL_RESOLVER))
#define VALADOC_DRIVERS_SYMBOL_RESOLVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALADOC_DRIVERS_TYPE_SYMBOL_RESOLVER, ValadocDriversSymbolResolverClass))

typedef struct _ValadocDriversSymbolResolver ValadocDriversSymbolResolver;
typedef struct _ValadocDriversSymbolResolverClass ValadocDriversSymbolResolverClass;
enum  {
	VALADOC_DRIVERS_DRIVER_0_PROPERTY,
	VALADOC_DRIVERS_DRIVER_NUM_PROPERTIES
};
static GParamSpec* valadoc_drivers_driver_properties[VALADOC_DRIVERS_DRIVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _valadoc_api_tree_unref0(var) ((var == NULL) ? NULL : (var = (valadoc_api_tree_unref (var), NULL)))

#define VALADOC_DRIVERS_TYPE_GIR_WRITER (valadoc_drivers_gir_writer_get_type ())
#define VALADOC_DRIVERS_GIR_WRITER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALADOC_DRIVERS_TYPE_GIR_WRITER, ValadocDriversGirWriter))
#define VALADOC_DRIVERS_GIR_WRITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALADOC_DRIVERS_TYPE_GIR_WRITER, ValadocDriversGirWriterClass))
#define VALADOC_DRIVERS_IS_GIR_WRITER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALADOC_DRIVERS_TYPE_GIR_WRITER))
#define VALADOC_DRIVERS_IS_GIR_WRITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALADOC_DRIVERS_TYPE_GIR_WRITER))
#define VALADOC_DRIVERS_GIR_WRITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALADOC_DRIVERS_TYPE_GIR_WRITER, ValadocDriversGirWriterClass))

typedef struct _ValadocDriversGirWriter ValadocDriversGirWriter;
typedef struct _ValadocDriversGirWriterClass ValadocDriversGirWriterClass;
#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)))

#define VALADOC_DRIVERS_TYPE_TREE_BUILDER (valadoc_drivers_tree_builder_get_type ())
#define VALADOC_DRIVERS_TREE_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALADOC_DRIVERS_TYPE_TREE_BUILDER, ValadocDriversTreeBuilder))
#define VALADOC_DRIVERS_TREE_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALADOC_DRIVERS_TYPE_TREE_BUILDER, ValadocDriversTreeBuilderClass))
#define VALADOC_DRIVERS_IS_TREE_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALADOC_DRIVERS_TYPE_TREE_BUILDER))
#define VALADOC_DRIVERS_IS_TREE_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALADOC_DRIVERS_TYPE_TREE_BUILDER))
#define VALADOC_DRIVERS_TREE_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALADOC_DRIVERS_TYPE_TREE_BUILDER, ValadocDriversTreeBuilderClass))

typedef struct _ValadocDriversTreeBuilder ValadocDriversTreeBuilder;
typedef struct _ValadocDriversTreeBuilderClass ValadocDriversTreeBuilderClass;

struct _ValadocDriversDriver {
	GObject parent_instance;
	ValadocDriversDriverPrivate * priv;
};

struct _ValadocDriversDriverClass {
	GObjectClass parent_class;
};

struct _ValadocDriversDriverPrivate {
	ValadocDriversSymbolResolver* resolver;
	ValadocApiTree* tree;
};


static gpointer valadoc_drivers_driver_parent_class = NULL;
static ValadocDriverIface * valadoc_drivers_driver_valadoc_driver_parent_iface = NULL;

GType valadoc_drivers_driver_get_type (void) G_GNUC_CONST;
GType valadoc_drivers_symbol_resolver_get_type (void) G_GNUC_CONST;
#define VALADOC_DRIVERS_DRIVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALADOC_DRIVERS_TYPE_DRIVER, ValadocDriversDriverPrivate))
static void valadoc_drivers_driver_real_write_gir (ValadocDriver* base, ValadocSettings* settings, ValadocErrorReporter* reporter);
GType valadoc_drivers_gir_writer_get_type (void) G_GNUC_CONST;
ValadocDriversGirWriter* valadoc_drivers_gir_writer_new (ValadocDriversSymbolResolver* resolver);
ValadocDriversGirWriter* valadoc_drivers_gir_writer_construct (GType object_type, ValadocDriversSymbolResolver* resolver);
static ValadocApiTree* valadoc_drivers_driver_real_build (ValadocDriver* base, ValadocSettings* settings, ValadocErrorReporter* reporter);
GType valadoc_drivers_tree_builder_get_type (void) G_GNUC_CONST;
ValadocDriversTreeBuilder* valadoc_drivers_tree_builder_new (void);
ValadocDriversTreeBuilder* valadoc_drivers_tree_builder_construct (GType object_type);
ValadocApiTree* valadoc_drivers_tree_builder_build (ValadocDriversTreeBuilder* self, ValadocSettings* settings, ValadocErrorReporter* reporter);
ValadocDriversSymbolResolver* valadoc_drivers_symbol_resolver_new (ValadocDriversTreeBuilder* builder);
ValadocDriversSymbolResolver* valadoc_drivers_symbol_resolver_construct (GType object_type, ValadocDriversTreeBuilder* builder);
ValadocDriversDriver* valadoc_drivers_driver_new (void);
ValadocDriversDriver* valadoc_drivers_driver_construct (GType object_type);
static void valadoc_drivers_driver_finalize (GObject * obj);
GType register_plugin (ValadocModuleLoader* module_loader);


static void valadoc_drivers_driver_real_write_gir (ValadocDriver* base, ValadocSettings* settings, ValadocErrorReporter* reporter) {
	ValadocDriversDriver * self;
	ValadocDriversGirWriter* gir_writer = NULL;
	ValadocDriversSymbolResolver* _tmp0_;
	ValadocDriversGirWriter* _tmp1_;
	gchar* gir_directory = NULL;
	gchar* _tmp2_;
	ValadocSettings* _tmp3_;
	const gchar* _tmp4_;
	ValadocDriversGirWriter* _tmp8_;
	ValadocApiTree* _tmp9_;
	void* _tmp10_;
	void* _tmp11_;
	const gchar* _tmp12_;
	ValadocSettings* _tmp13_;
	const gchar* _tmp14_;
	ValadocSettings* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	ValadocSettings* _tmp19_;
	const gchar* _tmp20_;
	ValadocSettings* _tmp21_;
	const gchar* _tmp22_;
	ValadocSettings* _tmp23_;
	const gchar* _tmp24_;
	self = (ValadocDriversDriver*) base;
	g_return_if_fail (settings != NULL);
	g_return_if_fail (reporter != NULL);
	_tmp0_ = self->priv->resolver;
	_tmp1_ = valadoc_drivers_gir_writer_new (_tmp0_);
	gir_writer = _tmp1_;
	_tmp2_ = g_strdup (".");
	gir_directory = _tmp2_;
	_tmp3_ = settings;
	_tmp4_ = _tmp3_->gir_directory;
	if (_tmp4_ != NULL) {
		ValadocSettings* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp5_ = settings;
		_tmp6_ = _tmp5_->gir_directory;
		_tmp7_ = g_strdup (_tmp6_);
		_g_free0 (gir_directory);
		gir_directory = _tmp7_;
	}
	_tmp8_ = gir_writer;
	_tmp9_ = self->priv->tree;
	_tmp10_ = valadoc_api_tree_get_data (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = gir_directory;
	_tmp13_ = settings;
	_tmp14_ = _tmp13_->gir_namespace;
	_tmp15_ = settings;
	_tmp16_ = _tmp15_->gir_version;
	_tmp17_ = g_strdup_printf ("%s-%s.gir", _tmp14_, _tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = settings;
	_tmp20_ = _tmp19_->gir_namespace;
	_tmp21_ = settings;
	_tmp22_ = _tmp21_->gir_version;
	_tmp23_ = settings;
	_tmp24_ = _tmp23_->pkg_name;
	vala_gir_writer_write_file ((ValaGIRWriter*) _tmp8_, G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, VALA_TYPE_CODE_CONTEXT, ValaCodeContext), _tmp12_, _tmp18_, _tmp20_, _tmp22_, _tmp24_, NULL);
	_g_free0 (_tmp18_);
	_g_free0 (gir_directory);
	_vala_code_visitor_unref0 (gir_writer);
}


static gpointer _valadoc_api_tree_ref0 (gpointer self) {
	return self ? valadoc_api_tree_ref (self) : NULL;
}


static ValadocApiTree* valadoc_drivers_driver_real_build (ValadocDriver* base, ValadocSettings* settings, ValadocErrorReporter* reporter) {
	ValadocDriversDriver * self;
	ValadocApiTree* result = NULL;
	ValadocDriversTreeBuilder* builder = NULL;
	ValadocDriversTreeBuilder* _tmp0_;
	ValadocDriversTreeBuilder* _tmp1_;
	ValadocSettings* _tmp2_;
	ValadocErrorReporter* _tmp3_;
	ValadocApiTree* _tmp4_;
	ValadocErrorReporter* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	ValadocDriversTreeBuilder* _tmp8_;
	ValadocDriversSymbolResolver* _tmp9_;
	ValadocApiTree* _tmp10_;
	ValadocDriversSymbolResolver* _tmp11_;
	ValadocApiTree* _tmp12_;
	ValadocApiTree* _tmp13_;
	self = (ValadocDriversDriver*) base;
	g_return_val_if_fail (settings != NULL, NULL);
	g_return_val_if_fail (reporter != NULL, NULL);
	_tmp0_ = valadoc_drivers_tree_builder_new ();
	builder = _tmp0_;
	_tmp1_ = builder;
	_tmp2_ = settings;
	_tmp3_ = reporter;
	_tmp4_ = valadoc_drivers_tree_builder_build (_tmp1_, _tmp2_, _tmp3_);
	_valadoc_api_tree_unref0 (self->priv->tree);
	self->priv->tree = _tmp4_;
	_tmp5_ = reporter;
	_tmp6_ = valadoc_error_reporter_get_errors (_tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp7_ > 0) {
		result = NULL;
		_vala_code_visitor_unref0 (builder);
		return result;
	}
	_tmp8_ = builder;
	_tmp9_ = valadoc_drivers_symbol_resolver_new (_tmp8_);
	_g_object_unref0 (self->priv->resolver);
	self->priv->resolver = _tmp9_;
	_tmp10_ = self->priv->tree;
	_tmp11_ = self->priv->resolver;
	valadoc_api_tree_accept (_tmp10_, (ValadocApiVisitor*) _tmp11_);
	_tmp12_ = self->priv->tree;
	_tmp13_ = _valadoc_api_tree_ref0 (_tmp12_);
	result = _tmp13_;
	_vala_code_visitor_unref0 (builder);
	return result;
}


ValadocDriversDriver* valadoc_drivers_driver_construct (GType object_type) {
	ValadocDriversDriver * self = NULL;
	self = (ValadocDriversDriver*) g_object_new (object_type, NULL);
	return self;
}


ValadocDriversDriver* valadoc_drivers_driver_new (void) {
	return valadoc_drivers_driver_construct (VALADOC_DRIVERS_TYPE_DRIVER);
}


static void valadoc_drivers_driver_class_init (ValadocDriversDriverClass * klass) {
	valadoc_drivers_driver_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ValadocDriversDriverPrivate));
	G_OBJECT_CLASS (klass)->finalize = valadoc_drivers_driver_finalize;
}


static void valadoc_drivers_driver_valadoc_driver_interface_init (ValadocDriverIface * iface) {
	valadoc_drivers_driver_valadoc_driver_parent_iface = g_type_interface_peek_parent (iface);
	iface->write_gir = (void (*) (ValadocDriver *, ValadocSettings*, ValadocErrorReporter*)) valadoc_drivers_driver_real_write_gir;
	iface->build = (ValadocApiTree* (*) (ValadocDriver *, ValadocSettings*, ValadocErrorReporter*)) valadoc_drivers_driver_real_build;
}


static void valadoc_drivers_driver_instance_init (ValadocDriversDriver * self) {
	self->priv = VALADOC_DRIVERS_DRIVER_GET_PRIVATE (self);
}


static void valadoc_drivers_driver_finalize (GObject * obj) {
	ValadocDriversDriver * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALADOC_DRIVERS_TYPE_DRIVER, ValadocDriversDriver);
	_g_object_unref0 (self->priv->resolver);
	_valadoc_api_tree_unref0 (self->priv->tree);
	G_OBJECT_CLASS (valadoc_drivers_driver_parent_class)->finalize (obj);
}


/**
 * Creates an simpler, minimized, more abstract AST for valacs AST.
 */
GType valadoc_drivers_driver_get_type (void) {
	static volatile gsize valadoc_drivers_driver_type_id__volatile = 0;
	if (g_once_init_enter (&valadoc_drivers_driver_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValadocDriversDriverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) valadoc_drivers_driver_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValadocDriversDriver), 0, (GInstanceInitFunc) valadoc_drivers_driver_instance_init, NULL };
		static const GInterfaceInfo valadoc_driver_info = { (GInterfaceInitFunc) valadoc_drivers_driver_valadoc_driver_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType valadoc_drivers_driver_type_id;
		valadoc_drivers_driver_type_id = g_type_register_static (G_TYPE_OBJECT, "ValadocDriversDriver", &g_define_type_info, 0);
		g_type_add_interface_static (valadoc_drivers_driver_type_id, VALADOC_TYPE_DRIVER, &valadoc_driver_info);
		g_once_init_leave (&valadoc_drivers_driver_type_id__volatile, valadoc_drivers_driver_type_id);
	}
	return valadoc_drivers_driver_type_id__volatile;
}


GType register_plugin (ValadocModuleLoader* module_loader) {
	GType result = 0UL;
	g_return_val_if_fail (module_loader != NULL, 0UL);
	result = VALADOC_DRIVERS_TYPE_DRIVER;
	return result;
}



