/* ide-vala-source-file.c generated by valac 0.30.0, the Vala compiler
 * generated from ide-vala-source-file.vala, do not modify */

/* ide-vala-source-file.vala
 *
 * Copyright (C) 2015 Christian Hergert <christian@hergert.me>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*
 * Bits of the following file were inspired from Anjuta. It's original
 * copyright is in tact below.
 *
 * Copyright (C) 2008-2010 Abderrahim Kitouni
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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


#define IDE_TYPE_VALA_SOURCE_FILE (ide_vala_source_file_get_type ())
#define IDE_VALA_SOURCE_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDE_TYPE_VALA_SOURCE_FILE, IdeValaSourceFile))
#define IDE_VALA_SOURCE_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDE_TYPE_VALA_SOURCE_FILE, IdeValaSourceFileClass))
#define IDE_IS_VALA_SOURCE_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDE_TYPE_VALA_SOURCE_FILE))
#define IDE_IS_VALA_SOURCE_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDE_TYPE_VALA_SOURCE_FILE))
#define IDE_VALA_SOURCE_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDE_TYPE_VALA_SOURCE_FILE, IdeValaSourceFileClass))

typedef struct _IdeValaSourceFile IdeValaSourceFile;
typedef struct _IdeValaSourceFileClass IdeValaSourceFileClass;
typedef struct _IdeValaSourceFilePrivate IdeValaSourceFilePrivate;
#define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
typedef struct _Block8Data Block8Data;
#define _vala_source_file_unref0(var) ((var == NULL) ? NULL : (var = (vala_source_file_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _ide_diagnostic_unref0(var) ((var == NULL) ? NULL : (var = (ide_diagnostic_unref (var), NULL)))
#define _ide_source_location_unref0(var) ((var == NULL) ? NULL : (var = (ide_source_location_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))

struct _IdeValaSourceFile {
	ValaSourceFile parent_instance;
	IdeValaSourceFilePrivate * priv;
	IdeFile* file;
};

struct _IdeValaSourceFileClass {
	ValaSourceFileClass parent_class;
};

struct _IdeValaSourceFilePrivate {
	ValaArrayList* diagnostics;
	gboolean _dirty;
};

struct _Block8Data {
	int _ref_count_;
	IdeValaSourceFile* self;
	GFile* gfile;
};


static gpointer ide_vala_source_file_parent_class = NULL;
static GType ide_vala_source_file_type_id = 0;

GType ide_vala_source_file_get_type (void) G_GNUC_CONST;
GType ide_vala_source_file_register_type (GTypeModule * module);
#define IDE_VALA_SOURCE_FILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IDE_TYPE_VALA_SOURCE_FILE, IdeValaSourceFilePrivate))
enum  {
	IDE_VALA_SOURCE_FILE_DUMMY_PROPERTY
};
IdeValaSourceFile* ide_vala_source_file_new (ValaCodeContext* context, ValaSourceFileType type, const gchar* filename, const gchar* content, gboolean cmdline);
IdeValaSourceFile* ide_vala_source_file_construct (GType object_type, ValaCodeContext* context, ValaSourceFileType type, const gchar* filename, const gchar* content, gboolean cmdline);
static void ide_vala_source_file_add_default_namespace (IdeValaSourceFile* self);
void ide_vala_source_file_set_dirty (IdeValaSourceFile* self, gboolean value);
GFile* ide_vala_source_file_get_file (IdeValaSourceFile* self);
void ide_vala_source_file_reset (IdeValaSourceFile* self);
void ide_vala_source_file_sync (IdeValaSourceFile* self, GPtrArray* unsaved_files);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static void __lambda4_ (Block8Data* _data8_, IdeUnsavedFile* unsaved_file);
static void ___lambda4__gfunc (gconstpointer data, gpointer self);
void ide_vala_source_file_report (IdeValaSourceFile* self, ValaSourceReference* source_reference, const gchar* message, IdeDiagnosticSeverity severity);
IdeDiagnostics* ide_vala_source_file_diagnose (IdeValaSourceFile* self);
static void _ide_diagnostic_unref0_ (gpointer var);
gboolean ide_vala_source_file_get_dirty (IdeValaSourceFile* self);
static void ide_vala_source_file_finalize (ValaSourceFile* obj);


IdeValaSourceFile* ide_vala_source_file_construct (GType object_type, ValaCodeContext* context, ValaSourceFileType type, const gchar* filename, const gchar* content, gboolean cmdline) {
	IdeValaSourceFile* self = NULL;
	ValaCodeContext* _tmp0_ = NULL;
	ValaSourceFileType _tmp1_ = 0;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_ = NULL;
	GFile* _tmp6_ = NULL;
	GFile* _tmp7_ = NULL;
	IdeFile* _tmp8_ = NULL;
	GEqualFunc _tmp9_ = NULL;
	ValaArrayList* _tmp10_ = NULL;
	g_return_val_if_fail (context != NULL, NULL);
	g_return_val_if_fail (filename != NULL, NULL);
	_tmp0_ = context;
	_tmp1_ = type;
	_tmp2_ = filename;
	_tmp3_ = content;
	_tmp4_ = cmdline;
	self = (IdeValaSourceFile*) vala_source_file_construct (object_type, _tmp0_, _tmp1_, _tmp2_, _tmp3_, _tmp4_);
	_tmp5_ = filename;
	_tmp6_ = g_file_new_for_path (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = ide_file_new (NULL, _tmp7_);
	_g_object_unref0 (self->file);
	self->file = _tmp8_;
	_g_object_unref0 (_tmp7_);
	_tmp9_ = g_direct_equal;
	_tmp10_ = vala_array_list_new (ide_diagnostic_get_type (), (GBoxedCopyFunc) ide_diagnostic_ref, ide_diagnostic_unref, _tmp9_);
	_vala_iterable_unref0 (self->priv->diagnostics);
	self->priv->diagnostics = _tmp10_;
	ide_vala_source_file_add_default_namespace (self);
	ide_vala_source_file_set_dirty (self, TRUE);
	return self;
}


IdeValaSourceFile* ide_vala_source_file_new (ValaCodeContext* context, ValaSourceFileType type, const gchar* filename, const gchar* content, gboolean cmdline) {
	return ide_vala_source_file_construct (IDE_TYPE_VALA_SOURCE_FILE, context, type, filename, content, cmdline);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


GFile* ide_vala_source_file_get_file (IdeValaSourceFile* self) {
	GFile* result = NULL;
	IdeFile* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	GFile* _tmp2_ = NULL;
	GFile* _tmp3_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->file;
	_tmp1_ = ide_file_get_file (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


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


static gpointer _vala_iterable_ref0 (gpointer self) {
	return self ? vala_iterable_ref (self) : NULL;
}


void ide_vala_source_file_reset (IdeValaSourceFile* self) {
	ValaArrayList* _tmp0_ = NULL;
	ValaArrayList* copy = NULL;
	GEqualFunc _tmp1_ = NULL;
	ValaArrayList* _tmp2_ = NULL;
	ValaMethod* entry_point = NULL;
	ValaCodeContext* _tmp15_ = NULL;
	ValaCodeContext* _tmp16_ = NULL;
	ValaMethod* _tmp17_ = NULL;
	ValaMethod* _tmp18_ = NULL;
	ValaMethod* _tmp19_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->diagnostics;
	vala_collection_clear ((ValaCollection*) _tmp0_);
	_tmp1_ = g_direct_equal;
	_tmp2_ = vala_array_list_new (VALA_TYPE_CODE_NODE, (GBoxedCopyFunc) vala_code_node_ref, vala_code_node_unref, _tmp1_);
	copy = _tmp2_;
	{
		ValaList* _node_list = NULL;
		ValaList* _tmp3_ = NULL;
		gint _node_size = 0;
		ValaList* _tmp4_ = NULL;
		gint _tmp5_ = 0;
		gint _tmp6_ = 0;
		gint _node_index = 0;
		_tmp3_ = vala_source_file_get_nodes ((ValaSourceFile*) self);
		_node_list = _tmp3_;
		_tmp4_ = _node_list;
		_tmp5_ = vala_collection_get_size ((ValaCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_node_size = _tmp6_;
		_node_index = -1;
		while (TRUE) {
			gint _tmp7_ = 0;
			gint _tmp8_ = 0;
			gint _tmp9_ = 0;
			ValaCodeNode* node = NULL;
			ValaList* _tmp10_ = NULL;
			gint _tmp11_ = 0;
			gpointer _tmp12_ = NULL;
			ValaArrayList* _tmp13_ = NULL;
			ValaCodeNode* _tmp14_ = NULL;
			_tmp7_ = _node_index;
			_node_index = _tmp7_ + 1;
			_tmp8_ = _node_index;
			_tmp9_ = _node_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _node_list;
			_tmp11_ = _node_index;
			_tmp12_ = vala_list_get (_tmp10_, _tmp11_);
			node = (ValaCodeNode*) _tmp12_;
			_tmp13_ = copy;
			_tmp14_ = node;
			vala_collection_add ((ValaCollection*) _tmp13_, _tmp14_);
			_vala_code_node_unref0 (node);
		}
		_vala_iterable_unref0 (_node_list);
	}
	_tmp15_ = vala_source_file_get_context ((ValaSourceFile*) self);
	_tmp16_ = _tmp15_;
	_tmp17_ = vala_code_context_get_entry_point (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _vala_code_node_ref0 (_tmp18_);
	entry_point = _tmp19_;
	{
		ValaArrayList* _node_list = NULL;
		ValaArrayList* _tmp20_ = NULL;
		ValaArrayList* _tmp21_ = NULL;
		gint _node_size = 0;
		ValaArrayList* _tmp22_ = NULL;
		gint _tmp23_ = 0;
		gint _tmp24_ = 0;
		gint _node_index = 0;
		_tmp20_ = copy;
		_tmp21_ = _vala_iterable_ref0 (_tmp20_);
		_node_list = _tmp21_;
		_tmp22_ = _node_list;
		_tmp23_ = vala_collection_get_size ((ValaCollection*) _tmp22_);
		_tmp24_ = _tmp23_;
		_node_size = _tmp24_;
		_node_index = -1;
		while (TRUE) {
			gint _tmp25_ = 0;
			gint _tmp26_ = 0;
			gint _tmp27_ = 0;
			ValaCodeNode* node = NULL;
			ValaArrayList* _tmp28_ = NULL;
			gint _tmp29_ = 0;
			gpointer _tmp30_ = NULL;
			ValaCodeNode* _tmp31_ = NULL;
			ValaCodeNode* _tmp32_ = NULL;
			_tmp25_ = _node_index;
			_node_index = _tmp25_ + 1;
			_tmp26_ = _node_index;
			_tmp27_ = _node_size;
			if (!(_tmp26_ < _tmp27_)) {
				break;
			}
			_tmp28_ = _node_list;
			_tmp29_ = _node_index;
			_tmp30_ = vala_list_get ((ValaList*) _tmp28_, _tmp29_);
			node = (ValaCodeNode*) _tmp30_;
			_tmp31_ = node;
			vala_source_file_remove_node ((ValaSourceFile*) self, _tmp31_);
			_tmp32_ = node;
			if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp32_, VALA_TYPE_SYMBOL)) {
				ValaSymbol* symbol = NULL;
				ValaCodeNode* _tmp33_ = NULL;
				ValaSymbol* _tmp34_ = NULL;
				ValaSymbol* _tmp35_ = NULL;
				ValaScope* _tmp36_ = NULL;
				ValaScope* _tmp37_ = NULL;
				ValaSymbol* _tmp44_ = NULL;
				ValaMethod* _tmp45_ = NULL;
				_tmp33_ = node;
				_tmp34_ = _vala_code_node_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, VALA_TYPE_SYMBOL, ValaSymbol));
				symbol = _tmp34_;
				_tmp35_ = symbol;
				_tmp36_ = vala_symbol_get_owner (_tmp35_);
				_tmp37_ = _tmp36_;
				if (_tmp37_ != NULL) {
					ValaSymbol* _tmp38_ = NULL;
					ValaScope* _tmp39_ = NULL;
					ValaScope* _tmp40_ = NULL;
					ValaSymbol* _tmp41_ = NULL;
					const gchar* _tmp42_ = NULL;
					const gchar* _tmp43_ = NULL;
					_tmp38_ = symbol;
					_tmp39_ = vala_symbol_get_owner (_tmp38_);
					_tmp40_ = _tmp39_;
					_tmp41_ = symbol;
					_tmp42_ = vala_symbol_get_name (_tmp41_);
					_tmp43_ = _tmp42_;
					vala_scope_remove (_tmp40_, _tmp43_);
				}
				_tmp44_ = symbol;
				_tmp45_ = entry_point;
				if (_tmp44_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp45_, VALA_TYPE_SYMBOL, ValaSymbol)) {
					ValaCodeContext* _tmp46_ = NULL;
					ValaCodeContext* _tmp47_ = NULL;
					_tmp46_ = vala_source_file_get_context ((ValaSourceFile*) self);
					_tmp47_ = _tmp46_;
					vala_code_context_set_entry_point (_tmp47_, NULL);
				}
				_vala_code_node_unref0 (symbol);
			}
			_vala_code_node_unref0 (node);
		}
		_vala_iterable_unref0 (_node_list);
	}
	ide_vala_source_file_add_default_namespace (self);
	ide_vala_source_file_set_dirty (self, TRUE);
	_vala_code_node_unref0 (entry_point);
	_vala_iterable_unref0 (copy);
}


static Block8Data* block8_data_ref (Block8Data* _data8_) {
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}


static void block8_data_unref (void * _userdata_) {
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		IdeValaSourceFile* self;
		self = _data8_->self;
		_g_object_unref0 (_data8_->gfile);
		_vala_source_file_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}


static gpointer _g_bytes_ref0 (gpointer self) {
	return self ? g_bytes_ref (self) : NULL;
}


static void __lambda4_ (Block8Data* _data8_, IdeUnsavedFile* unsaved_file) {
	IdeValaSourceFile* self;
	IdeUnsavedFile* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	self = _data8_->self;
	g_return_if_fail (unsaved_file != NULL);
	_tmp0_ = unsaved_file;
	_tmp1_ = ide_unsaved_file_get_file (_tmp0_);
	_tmp2_ = g_file_equal (_tmp1_, _data8_->gfile);
	if (_tmp2_) {
		GBytes* bytes = NULL;
		IdeUnsavedFile* _tmp3_ = NULL;
		GBytes* _tmp4_ = NULL;
		GBytes* _tmp5_ = NULL;
		GBytes* _tmp6_ = NULL;
		gsize _tmp7_;
		guint8* _tmp8_ = NULL;
		const gchar* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		_tmp3_ = unsaved_file;
		_tmp4_ = ide_unsaved_file_get_content (_tmp3_);
		_tmp5_ = _g_bytes_ref0 (_tmp4_);
		bytes = _tmp5_;
		_tmp6_ = bytes;
		_tmp8_ = g_bytes_get_data (_tmp6_, &_tmp7_);
		_tmp9_ = vala_source_file_get_content ((ValaSourceFile*) self);
		_tmp10_ = _tmp9_;
		if (_tmp8_ != ((guint8*) _tmp10_)) {
			GBytes* _tmp11_ = NULL;
			gsize _tmp12_;
			guint8* _tmp13_ = NULL;
			_tmp11_ = bytes;
			_tmp13_ = g_bytes_get_data (_tmp11_, &_tmp12_);
			vala_source_file_set_content ((ValaSourceFile*) self, (const gchar*) _tmp13_);
			ide_vala_source_file_reset (self);
			_g_bytes_unref0 (bytes);
			return;
		}
		_g_bytes_unref0 (bytes);
	}
}


static void ___lambda4__gfunc (gconstpointer data, gpointer self) {
	__lambda4_ (self, (IdeUnsavedFile*) data);
}


void ide_vala_source_file_sync (IdeValaSourceFile* self, GPtrArray* unsaved_files) {
	Block8Data* _data8_;
	IdeFile* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	GFile* _tmp2_ = NULL;
	GFile* _tmp3_ = NULL;
	GPtrArray* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (unsaved_files != NULL);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = vala_source_file_ref (self);
	_tmp0_ = self->file;
	_tmp1_ = ide_file_get_file (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_data8_->gfile = _tmp3_;
	_tmp4_ = unsaved_files;
	g_ptr_array_foreach (_tmp4_, ___lambda4__gfunc, _data8_);
	block8_data_unref (_data8_);
	_data8_ = NULL;
}


void ide_vala_source_file_report (IdeValaSourceFile* self, ValaSourceReference* source_reference, const gchar* message, IdeDiagnosticSeverity severity) {
	IdeSourceLocation* begin = NULL;
	IdeFile* _tmp0_ = NULL;
	ValaSourceReference* _tmp1_ = NULL;
	ValaSourceLocation _tmp2_ = {0};
	ValaSourceLocation _tmp3_ = {0};
	gint _tmp4_ = 0;
	ValaSourceReference* _tmp5_ = NULL;
	ValaSourceLocation _tmp6_ = {0};
	ValaSourceLocation _tmp7_ = {0};
	gint _tmp8_ = 0;
	IdeSourceLocation* _tmp9_ = NULL;
	IdeSourceLocation* end = NULL;
	IdeFile* _tmp10_ = NULL;
	ValaSourceReference* _tmp11_ = NULL;
	ValaSourceLocation _tmp12_ = {0};
	ValaSourceLocation _tmp13_ = {0};
	gint _tmp14_ = 0;
	ValaSourceReference* _tmp15_ = NULL;
	ValaSourceLocation _tmp16_ = {0};
	ValaSourceLocation _tmp17_ = {0};
	gint _tmp18_ = 0;
	IdeSourceLocation* _tmp19_ = NULL;
	IdeDiagnostic* diag = NULL;
	IdeDiagnosticSeverity _tmp20_ = 0;
	const gchar* _tmp21_ = NULL;
	IdeDiagnostic* _tmp22_ = NULL;
	IdeSourceRange* _tmp23_ = NULL;
	ValaArrayList* _tmp24_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source_reference != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = self->file;
	_tmp1_ = source_reference;
	vala_source_reference_get_begin (_tmp1_, &_tmp2_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_.line;
	_tmp5_ = source_reference;
	vala_source_reference_get_begin (_tmp5_, &_tmp6_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_.column;
	_tmp9_ = ide_source_location_new (_tmp0_, (guint) (_tmp4_ - 1), (guint) (_tmp8_ - 1), (guint) 0);
	begin = _tmp9_;
	_tmp10_ = self->file;
	_tmp11_ = source_reference;
	vala_source_reference_get_end (_tmp11_, &_tmp12_);
	_tmp13_ = _tmp12_;
	_tmp14_ = _tmp13_.line;
	_tmp15_ = source_reference;
	vala_source_reference_get_end (_tmp15_, &_tmp16_);
	_tmp17_ = _tmp16_;
	_tmp18_ = _tmp17_.column;
	_tmp19_ = ide_source_location_new (_tmp10_, (guint) (_tmp14_ - 1), (guint) (_tmp18_ - 1), (guint) 0);
	end = _tmp19_;
	_tmp20_ = severity;
	_tmp21_ = message;
	_tmp22_ = ide_diagnostic_new (_tmp20_, _tmp21_, begin);
	diag = _tmp22_;
	_tmp23_ = ide_source_range_new (begin, end);
	ide_diagnostic_take_range (diag, _tmp23_);
	_tmp24_ = self->priv->diagnostics;
	vala_collection_add ((ValaCollection*) _tmp24_, diag);
	_ide_diagnostic_unref0 (diag);
	_ide_source_location_unref0 (end);
	_ide_source_location_unref0 (begin);
}


static void _ide_diagnostic_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (ide_diagnostic_unref (var), NULL));
}


static gpointer _ide_diagnostic_ref0 (gpointer self) {
	return self ? ide_diagnostic_ref (self) : NULL;
}


static gpointer _g_ptr_array_ref0 (gpointer self) {
	return self ? g_ptr_array_ref (self) : NULL;
}


IdeDiagnostics* ide_vala_source_file_diagnose (IdeValaSourceFile* self) {
	IdeDiagnostics* result = NULL;
	GPtrArray* ar = NULL;
	GPtrArray* _tmp0_ = NULL;
	GPtrArray* _tmp15_ = NULL;
	GPtrArray* _tmp16_ = NULL;
	IdeDiagnostics* _tmp17_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _ide_diagnostic_unref0_);
	ar = _tmp0_;
	{
		ValaArrayList* _diag_list = NULL;
		ValaArrayList* _tmp1_ = NULL;
		ValaArrayList* _tmp2_ = NULL;
		gint _diag_size = 0;
		ValaArrayList* _tmp3_ = NULL;
		gint _tmp4_ = 0;
		gint _tmp5_ = 0;
		gint _diag_index = 0;
		_tmp1_ = self->priv->diagnostics;
		_tmp2_ = _vala_iterable_ref0 (_tmp1_);
		_diag_list = _tmp2_;
		_tmp3_ = _diag_list;
		_tmp4_ = vala_collection_get_size ((ValaCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_diag_size = _tmp5_;
		_diag_index = -1;
		while (TRUE) {
			gint _tmp6_ = 0;
			gint _tmp7_ = 0;
			gint _tmp8_ = 0;
			IdeDiagnostic* diag = NULL;
			ValaArrayList* _tmp9_ = NULL;
			gint _tmp10_ = 0;
			gpointer _tmp11_ = NULL;
			GPtrArray* _tmp12_ = NULL;
			IdeDiagnostic* _tmp13_ = NULL;
			IdeDiagnostic* _tmp14_ = NULL;
			_tmp6_ = _diag_index;
			_diag_index = _tmp6_ + 1;
			_tmp7_ = _diag_index;
			_tmp8_ = _diag_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _diag_list;
			_tmp10_ = _diag_index;
			_tmp11_ = vala_list_get ((ValaList*) _tmp9_, _tmp10_);
			diag = (IdeDiagnostic*) _tmp11_;
			_tmp12_ = ar;
			_tmp13_ = diag;
			_tmp14_ = _ide_diagnostic_ref0 (_tmp13_);
			g_ptr_array_add (_tmp12_, _tmp14_);
			_ide_diagnostic_unref0 (diag);
		}
		_vala_iterable_unref0 (_diag_list);
	}
	_tmp15_ = ar;
	_tmp16_ = _g_ptr_array_ref0 (_tmp15_);
	_tmp17_ = ide_diagnostics_new (_tmp16_);
	result = _tmp17_;
	_g_ptr_array_unref0 (ar);
	return result;
}


static void ide_vala_source_file_add_default_namespace (IdeValaSourceFile* self) {
	GEqualFunc _tmp0_ = NULL;
	ValaArrayList* _tmp1_ = NULL;
	ValaArrayList* _tmp2_ = NULL;
	ValaUnresolvedSymbol* unres = NULL;
	ValaUnresolvedSymbol* _tmp3_ = NULL;
	ValaUsingDirective* udir = NULL;
	ValaUsingDirective* _tmp4_ = NULL;
	ValaCodeContext* _tmp5_ = NULL;
	ValaCodeContext* _tmp6_ = NULL;
	ValaNamespace* _tmp7_ = NULL;
	ValaNamespace* _tmp8_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_direct_equal;
	_tmp1_ = vala_array_list_new (VALA_TYPE_USING_DIRECTIVE, (GBoxedCopyFunc) vala_code_node_ref, vala_code_node_unref, _tmp0_);
	_tmp2_ = _tmp1_;
	vala_source_file_set_current_using_directives ((ValaSourceFile*) self, (ValaList*) _tmp2_);
	_vala_iterable_unref0 (_tmp2_);
	_tmp3_ = vala_unresolved_symbol_new (NULL, "GLib", NULL);
	unres = _tmp3_;
	_tmp4_ = vala_using_directive_new ((ValaSymbol*) unres, NULL);
	udir = _tmp4_;
	vala_source_file_add_using_directive ((ValaSourceFile*) self, udir);
	_tmp5_ = vala_source_file_get_context ((ValaSourceFile*) self);
	_tmp6_ = _tmp5_;
	_tmp7_ = vala_code_context_get_root (_tmp6_);
	_tmp8_ = _tmp7_;
	vala_namespace_add_using_directive (_tmp8_, udir);
	_vala_code_node_unref0 (udir);
	_vala_code_node_unref0 (unres);
}


gboolean ide_vala_source_file_get_dirty (IdeValaSourceFile* self) {
	gboolean result;
	gboolean _tmp0_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_dirty;
	result = _tmp0_;
	return result;
}


void ide_vala_source_file_set_dirty (IdeValaSourceFile* self, gboolean value) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_dirty = _tmp0_;
}


static void ide_vala_source_file_class_init (IdeValaSourceFileClass * klass) {
	ide_vala_source_file_parent_class = g_type_class_peek_parent (klass);
	((ValaSourceFileClass *) klass)->finalize = ide_vala_source_file_finalize;
	g_type_class_add_private (klass, sizeof (IdeValaSourceFilePrivate));
}


static void ide_vala_source_file_instance_init (IdeValaSourceFile * self) {
	self->priv = IDE_VALA_SOURCE_FILE_GET_PRIVATE (self);
}


static void ide_vala_source_file_finalize (ValaSourceFile* obj) {
	IdeValaSourceFile * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, IDE_TYPE_VALA_SOURCE_FILE, IdeValaSourceFile);
	_vala_iterable_unref0 (self->priv->diagnostics);
	_g_object_unref0 (self->file);
	VALA_SOURCE_FILE_CLASS (ide_vala_source_file_parent_class)->finalize (obj);
}


GType ide_vala_source_file_get_type (void) {
	return ide_vala_source_file_type_id;
}


GType ide_vala_source_file_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (IdeValaSourceFileClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ide_vala_source_file_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IdeValaSourceFile), 0, (GInstanceInitFunc) ide_vala_source_file_instance_init, NULL };
	ide_vala_source_file_type_id = g_type_module_register_type (module, VALA_TYPE_SOURCE_FILE, "IdeValaSourceFile", &g_define_type_info, 0);
	return ide_vala_source_file_type_id;
}



