/* map-file.c generated by valac 0.56.19, the Vala compiler
 * generated from map-file.vala, do not modify */

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * 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/>.
 */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <json-glib/json-glib.h>
#include "libkkc/libkkc.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 KKC_TYPE_MAP_FILE (kkc_map_file_get_type ())
#define KKC_MAP_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_MAP_FILE, KkcMapFile))
#define KKC_MAP_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_MAP_FILE, KkcMapFileClass))
#define KKC_IS_MAP_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_MAP_FILE))
#define KKC_IS_MAP_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_MAP_FILE))
#define KKC_MAP_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_MAP_FILE, KkcMapFileClass))

typedef struct _KkcMapFile KkcMapFile;
typedef struct _KkcMapFileClass KkcMapFileClass;
typedef struct _KkcMapFilePrivate KkcMapFilePrivate;
enum  {
	KKC_MAP_FILE_0_PROPERTY,
	KKC_MAP_FILE_NUM_PROPERTIES
};
static GParamSpec* kkc_map_file_properties[KKC_MAP_FILE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))

struct _KkcMapFile {
	GObject parent_instance;
	KkcMapFilePrivate * priv;
};

struct _KkcMapFileClass {
	GObjectClass parent_class;
	gchar* (*uniquify) (KkcMapFile* self, const gchar* key);
};

struct _KkcMapFilePrivate {
	GeeMap* maps;
	GeeMap* parent_maps;
};

static gint KkcMapFile_private_offset;
static gpointer kkc_map_file_parent_class = NULL;

VALA_EXTERN GType kkc_map_file_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* kkc_map_file_uniquify (KkcMapFile* self,
                              const gchar* key);
static void kkc_map_file_load_map (KkcMapFile* self,
                            GeeMap* map,
                            JsonObject* object);
static JsonNode* _vala_JsonNode_copy (JsonNode* self);
static void _vala_JsonNode_free (JsonNode* self);
static gchar* kkc_map_file_real_uniquify (KkcMapFile* self,
                                   const gchar* key);
static void kkc_map_file_load (KkcMapFile* self,
                        KkcRuleMetadata* metadata,
                        const gchar* type,
                        const gchar* name,
                        GeeSet* parents,
                        GeeMap* maps,
                        GeeMap* parent_maps,
                        GError** error);
VALA_EXTERN KkcMapFile* kkc_map_file_construct (GType object_type,
                                    KkcRuleMetadata* metadata,
                                    const gchar* type,
                                    const gchar* name,
                                    GError** error);
VALA_EXTERN GeeMap* kkc_map_file_get (KkcMapFile* self,
                          const gchar* name);
VALA_EXTERN GeeMap* kkc_map_file_get_parent (KkcMapFile* self,
                                 const gchar* name);
static void kkc_map_file_finalize (GObject * obj);
static GType kkc_map_file_get_type_once (void);

static inline gpointer
kkc_map_file_get_instance_private (KkcMapFile* self)
{
	return G_STRUCT_MEMBER_P (self, KkcMapFile_private_offset);
}

static JsonNode*
_vala_JsonNode_copy (JsonNode* self)
{
	return g_boxed_copy (json_node_get_type (), self);
}

static gpointer
__vala_JsonNode_copy0 (gpointer self)
{
	return self ? _vala_JsonNode_copy (self) : NULL;
}

static void
_vala_JsonNode_free (JsonNode* self)
{
	g_boxed_free (json_node_get_type (), self);
}

static void
kkc_map_file_load_map (KkcMapFile* self,
                       GeeMap* map,
                       JsonObject* object)
{
	GList* keys = NULL;
	GList* _tmp0_;
	GList* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (map != NULL);
	g_return_if_fail (object != NULL);
	_tmp0_ = json_object_get_members (object);
	keys = _tmp0_;
	_tmp1_ = keys;
	{
		GList* key_collection = NULL;
		GList* key_it = NULL;
		key_collection = _tmp1_;
		for (key_it = key_collection; key_it != NULL; key_it = key_it->next) {
			const gchar* key = NULL;
			key = (const gchar*) key_it->data;
			{
				JsonNode* value = NULL;
				const gchar* _tmp2_;
				JsonNode* _tmp3_;
				JsonNode* _tmp4_;
				gchar* _key = NULL;
				const gchar* _tmp5_;
				gchar* _tmp6_;
				const gchar* _tmp7_;
				JsonNode* _tmp8_;
				_tmp2_ = key;
				_tmp3_ = json_object_get_member (object, _tmp2_);
				_tmp4_ = __vala_JsonNode_copy0 (_tmp3_);
				value = _tmp4_;
				_tmp5_ = key;
				_tmp6_ = kkc_map_file_uniquify (self, _tmp5_);
				_key = _tmp6_;
				_tmp7_ = _key;
				_tmp8_ = value;
				gee_map_set (map, _tmp7_, _tmp8_);
				_g_free0 (_key);
				__vala_JsonNode_free0 (value);
			}
		}
	}
	(keys == NULL) ? NULL : (keys = (g_list_free (keys), NULL));
}

static gchar*
kkc_map_file_real_uniquify (KkcMapFile* self,
                            const gchar* key)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = g_strdup (key);
	result = _tmp0_;
	return result;
}

gchar*
kkc_map_file_uniquify (KkcMapFile* self,
                       const gchar* key)
{
	KkcMapFileClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_MAP_FILE_GET_CLASS (self);
	if (_klass_->uniquify) {
		return _klass_->uniquify (self, key);
	}
	return NULL;
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static gpointer
_json_array_ref0 (gpointer self)
{
	return self ? json_array_ref (self) : NULL;
}

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

static void
kkc_map_file_load (KkcMapFile* self,
                   KkcRuleMetadata* metadata,
                   const gchar* type,
                   const gchar* name,
                   GeeSet* parents,
                   GeeMap* maps,
                   GeeMap* parent_maps,
                   GError** error)
{
	gchar* filename = NULL;
	gchar* _tmp0_;
	JsonParser* parser = NULL;
	JsonParser* _tmp2_;
	JsonNode* root = NULL;
	JsonParser* _tmp12_;
	JsonNode* _tmp13_;
	JsonNode* _tmp14_;
	JsonNode* _tmp15_;
	JsonObject* object = NULL;
	JsonNode* _tmp17_;
	JsonObject* _tmp18_;
	JsonObject* _tmp19_;
	JsonNode* member = NULL;
	JsonObject* _tmp20_;
	JsonObject* _tmp59_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (metadata != NULL);
	g_return_if_fail (type != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (parents != NULL);
	g_return_if_fail (maps != NULL);
	g_return_if_fail (parent_maps != NULL);
	_tmp0_ = kkc_rule_metadata_locate_map_file (metadata, type, name);
	filename = _tmp0_;
	if (filename == NULL) {
		GError* _tmp1_;
		_tmp1_ = g_error_new (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "can't locate map file for %s/%s", type, name);
		_inner_error0_ = _tmp1_;
		if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (filename);
			return;
		} else {
			_g_free0 (filename);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_tmp2_ = json_parser_new ();
	parser = _tmp2_;
	{
		gboolean _tmp3_ = FALSE;
		JsonParser* _tmp4_;
		_tmp4_ = parser;
		_tmp3_ = json_parser_load_from_file (_tmp4_, filename, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (!_tmp3_) {
			GError* _tmp5_;
			_tmp5_ = g_error_new_literal (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "");
			_inner_error0_ = _tmp5_;
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		GError* _tmp10_;
		GError* _tmp11_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		_tmp8_ = g_strdup_printf ("can't load %s: %s", filename, _tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_error_new_literal (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, _tmp9_);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		_inner_error0_ = _tmp11_;
		_g_error_free0 (e);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			return;
		} else {
			_g_object_unref0 (parser);
			_g_free0 (filename);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_tmp12_ = parser;
	_tmp13_ = json_parser_get_root (_tmp12_);
	_tmp14_ = __vala_JsonNode_copy0 (_tmp13_);
	root = _tmp14_;
	_tmp15_ = root;
	if (json_node_get_node_type (_tmp15_) != JSON_NODE_OBJECT) {
		GError* _tmp16_;
		_tmp16_ = g_error_new_literal (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "root element must be an object");
		_inner_error0_ = _tmp16_;
		if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error0_);
			__vala_JsonNode_free0 (root);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			return;
		} else {
			__vala_JsonNode_free0 (root);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_tmp17_ = root;
	_tmp18_ = json_node_get_object (_tmp17_);
	_tmp19_ = _json_object_ref0 (_tmp18_);
	object = _tmp19_;
	_tmp20_ = object;
	if (json_object_has_member (_tmp20_, "include")) {
		JsonObject* _tmp21_;
		JsonNode* _tmp22_;
		JsonNode* _tmp23_;
		JsonNode* _tmp24_;
		JsonArray* include = NULL;
		JsonNode* _tmp26_;
		JsonArray* _tmp27_;
		JsonArray* _tmp28_;
		GList* elements = NULL;
		JsonArray* _tmp29_;
		GList* _tmp30_;
		GList* _tmp31_;
		_tmp21_ = object;
		_tmp22_ = json_object_get_member (_tmp21_, "include");
		_tmp23_ = __vala_JsonNode_copy0 (_tmp22_);
		__vala_JsonNode_free0 (member);
		member = _tmp23_;
		_tmp24_ = member;
		if (json_node_get_node_type (_tmp24_) != JSON_NODE_ARRAY) {
			GError* _tmp25_;
			_tmp25_ = g_error_new_literal (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "\"include\" element must be an array");
			_inner_error0_ = _tmp25_;
			if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
				g_propagate_error (error, _inner_error0_);
				__vala_JsonNode_free0 (member);
				_json_object_unref0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				return;
			} else {
				__vala_JsonNode_free0 (member);
				_json_object_unref0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		_tmp26_ = member;
		_tmp27_ = json_node_get_array (_tmp26_);
		_tmp28_ = _json_array_ref0 (_tmp27_);
		include = _tmp28_;
		_tmp29_ = include;
		_tmp30_ = json_array_get_elements (_tmp29_);
		elements = _tmp30_;
		_tmp31_ = elements;
		{
			GList* element_collection = NULL;
			GList* element_it = NULL;
			element_collection = _tmp31_;
			for (element_it = element_collection; element_it != NULL; element_it = element_it->next) {
				JsonNode* element = NULL;
				element = (JsonNode*) element_it->data;
				{
					gchar* parent = NULL;
					JsonNode* _tmp32_;
					const gchar* _tmp33_;
					gchar* _tmp34_;
					const gchar* _tmp35_;
					gchar* parent_rule = NULL;
					gchar* parent_name = NULL;
					gint index = 0;
					const gchar* _tmp38_;
					KkcRuleMetadata* parent_metadata = NULL;
					const gchar* _tmp51_;
					KkcRuleMetadata* _tmp52_;
					KkcRuleMetadata* _tmp53_;
					const gchar* _tmp56_;
					KkcRuleMetadata* _tmp57_;
					const gchar* _tmp58_;
					_tmp32_ = element;
					_tmp33_ = json_node_get_string (_tmp32_);
					_tmp34_ = g_strdup (_tmp33_);
					parent = _tmp34_;
					_tmp35_ = parent;
					if (gee_collection_contains ((GeeCollection*) parents, _tmp35_)) {
						const gchar* _tmp36_;
						GError* _tmp37_;
						_tmp36_ = parent;
						_tmp37_ = g_error_new (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "found circular include of %s", _tmp36_);
						_inner_error0_ = _tmp37_;
						if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error0_);
							_g_free0 (parent);
							(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
							_json_array_unref0 (include);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							return;
						} else {
							_g_free0 (parent);
							(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
							_json_array_unref0 (include);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
					}
					_tmp38_ = parent;
					index = string_index_of (_tmp38_, "/", 0);
					if (index < 0) {
						const gchar* _tmp39_;
						const gchar* _tmp40_;
						gchar* _tmp41_;
						const gchar* _tmp42_;
						gchar* _tmp43_;
						_tmp39_ = kkc_metadata_file_get_name ((KkcMetadataFile*) metadata);
						_tmp40_ = _tmp39_;
						_tmp41_ = g_strdup (_tmp40_);
						_g_free0 (parent_rule);
						parent_rule = _tmp41_;
						_tmp42_ = parent;
						_tmp43_ = g_strdup (_tmp42_);
						_g_free0 (parent_name);
						parent_name = _tmp43_;
					} else {
						const gchar* _tmp44_;
						gchar* _tmp45_;
						const gchar* _tmp46_;
						const gchar* _tmp47_;
						gint _tmp48_;
						gint _tmp49_;
						gchar* _tmp50_;
						_tmp44_ = parent;
						_tmp45_ = string_slice (_tmp44_, (glong) 0, (glong) index);
						_g_free0 (parent_rule);
						parent_rule = _tmp45_;
						_tmp46_ = parent;
						_tmp47_ = parent;
						_tmp48_ = strlen (_tmp47_);
						_tmp49_ = _tmp48_;
						_tmp50_ = string_slice (_tmp46_, (glong) (index + 1), (glong) _tmp49_);
						_g_free0 (parent_name);
						parent_name = _tmp50_;
					}
					_tmp51_ = parent_rule;
					_tmp52_ = kkc_rule_metadata_find (_tmp51_);
					parent_metadata = _tmp52_;
					_tmp53_ = parent_metadata;
					if (_tmp53_ == NULL) {
						const gchar* _tmp54_;
						GError* _tmp55_;
						_tmp54_ = parent_rule;
						_tmp55_ = g_error_new (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "can't find rule %s", _tmp54_);
						_inner_error0_ = _tmp55_;
						if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (parent_metadata);
							_g_free0 (parent_name);
							_g_free0 (parent_rule);
							_g_free0 (parent);
							(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
							_json_array_unref0 (include);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							return;
						} else {
							_g_object_unref0 (parent_metadata);
							_g_free0 (parent_name);
							_g_free0 (parent_rule);
							_g_free0 (parent);
							(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
							_json_array_unref0 (include);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
					}
					_tmp56_ = parent;
					gee_collection_add ((GeeCollection*) parents, _tmp56_);
					_tmp57_ = parent_metadata;
					_tmp58_ = parent_name;
					kkc_map_file_load (self, _tmp57_, type, _tmp58_, parents, parent_maps, parent_maps, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error0_);
							_g_object_unref0 (parent_metadata);
							_g_free0 (parent_name);
							_g_free0 (parent_rule);
							_g_free0 (parent);
							(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
							_json_array_unref0 (include);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							return;
						} else {
							_g_object_unref0 (parent_metadata);
							_g_free0 (parent_name);
							_g_free0 (parent_rule);
							_g_free0 (parent);
							(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
							_json_array_unref0 (include);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
					}
					_g_object_unref0 (parent_metadata);
					_g_free0 (parent_name);
					_g_free0 (parent_rule);
					_g_free0 (parent);
				}
			}
		}
		(elements == NULL) ? NULL : (elements = (g_list_free (elements), NULL));
		_json_array_unref0 (include);
	}
	_tmp59_ = object;
	if (json_object_has_member (_tmp59_, "define")) {
		JsonObject* _tmp60_;
		JsonNode* _tmp61_;
		JsonNode* _tmp62_;
		JsonNode* _tmp63_;
		JsonObject* define = NULL;
		JsonNode* _tmp65_;
		JsonObject* _tmp66_;
		JsonObject* _tmp67_;
		GList* keys = NULL;
		JsonObject* _tmp68_;
		GList* _tmp69_;
		GList* _tmp70_;
		_tmp60_ = object;
		_tmp61_ = json_object_get_member (_tmp60_, "define");
		_tmp62_ = __vala_JsonNode_copy0 (_tmp61_);
		__vala_JsonNode_free0 (member);
		member = _tmp62_;
		_tmp63_ = member;
		if (json_node_get_node_type (_tmp63_) != JSON_NODE_OBJECT) {
			GError* _tmp64_;
			_tmp64_ = g_error_new_literal (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "\"define\" element must be an object");
			_inner_error0_ = _tmp64_;
			if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
				g_propagate_error (error, _inner_error0_);
				__vala_JsonNode_free0 (member);
				_json_object_unref0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				return;
			} else {
				__vala_JsonNode_free0 (member);
				_json_object_unref0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		_tmp65_ = member;
		_tmp66_ = json_node_get_object (_tmp65_);
		_tmp67_ = _json_object_ref0 (_tmp66_);
		define = _tmp67_;
		_tmp68_ = define;
		_tmp69_ = json_object_get_members (_tmp68_);
		keys = _tmp69_;
		_tmp70_ = keys;
		{
			GList* key_collection = NULL;
			GList* key_it = NULL;
			key_collection = _tmp70_;
			for (key_it = key_collection; key_it != NULL; key_it = key_it->next) {
				const gchar* key = NULL;
				key = (const gchar*) key_it->data;
				{
					const gchar* _tmp71_;
					JsonObject* _tmp75_;
					const gchar* _tmp76_;
					JsonNode* _tmp77_;
					JsonNode* _tmp78_;
					JsonNode* _tmp79_;
					const gchar* _tmp81_;
					gpointer _tmp82_;
					GeeMap* _tmp83_;
					JsonNode* _tmp84_;
					JsonObject* _tmp85_;
					_tmp71_ = key;
					if (!gee_map_has_key (maps, _tmp71_)) {
						GeeHashMap* map = NULL;
						GeeHashMap* _tmp72_;
						const gchar* _tmp73_;
						GeeHashMap* _tmp74_;
						_tmp72_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, json_node_get_type (), (GBoxedCopyFunc) _vala_JsonNode_copy, (GDestroyNotify) _vala_JsonNode_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
						map = _tmp72_;
						_tmp73_ = key;
						_tmp74_ = map;
						gee_map_set (maps, _tmp73_, (GeeMap*) _tmp74_);
						_g_object_unref0 (map);
					}
					_tmp75_ = define;
					_tmp76_ = key;
					_tmp77_ = json_object_get_member (_tmp75_, _tmp76_);
					_tmp78_ = __vala_JsonNode_copy0 (_tmp77_);
					__vala_JsonNode_free0 (member);
					member = _tmp78_;
					_tmp79_ = member;
					if (json_node_get_node_type (_tmp79_) != JSON_NODE_OBJECT) {
						GError* _tmp80_;
						_tmp80_ = g_error_new_literal (KKC_RULE_PARSE_ERROR, KKC_RULE_PARSE_ERROR_FAILED, "map element must be an object");
						_inner_error0_ = _tmp80_;
						if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error0_);
							(keys == NULL) ? NULL : (keys = (g_list_free (keys), NULL));
							_json_object_unref0 (define);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							return;
						} else {
							(keys == NULL) ? NULL : (keys = (g_list_free (keys), NULL));
							_json_object_unref0 (define);
							__vala_JsonNode_free0 (member);
							_json_object_unref0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
					}
					_tmp81_ = key;
					_tmp82_ = gee_map_get (maps, _tmp81_);
					_tmp83_ = (GeeMap*) _tmp82_;
					_tmp84_ = member;
					_tmp85_ = json_node_get_object (_tmp84_);
					kkc_map_file_load_map (self, _tmp83_, _tmp85_);
					_g_object_unref0 (_tmp83_);
				}
			}
		}
		(keys == NULL) ? NULL : (keys = (g_list_free (keys), NULL));
		_json_object_unref0 (define);
	}
	__vala_JsonNode_free0 (member);
	_json_object_unref0 (object);
	__vala_JsonNode_free0 (root);
	_g_object_unref0 (parser);
	_g_free0 (filename);
}

KkcMapFile*
kkc_map_file_construct (GType object_type,
                        KkcRuleMetadata* metadata,
                        const gchar* type,
                        const gchar* name,
                        GError** error)
{
	KkcMapFile * self = NULL;
	GeeSet* parents = NULL;
	GeeHashSet* _tmp0_;
	GeeMap* _tmp1_;
	GeeMap* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (metadata != NULL, NULL);
	g_return_val_if_fail (type != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	self = (KkcMapFile*) g_object_new (object_type, NULL);
	_tmp0_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
	parents = (GeeSet*) _tmp0_;
	_tmp1_ = self->priv->maps;
	_tmp2_ = self->priv->parent_maps;
	kkc_map_file_load (self, metadata, type, name, parents, _tmp1_, _tmp2_, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == KKC_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (parents);
			_g_object_unref0 (self);
			return NULL;
		} else {
			_g_object_unref0 (parents);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_g_object_unref0 (parents);
	return self;
}

GeeMap*
kkc_map_file_get (KkcMapFile* self,
                  const gchar* name)
{
	GeeMap* _tmp0_;
	GeeHashMap* _tmp3_;
	GeeMap* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->priv->maps;
	if (gee_map_has_key (_tmp0_, name)) {
		GeeMap* _tmp1_;
		gpointer _tmp2_;
		_tmp1_ = self->priv->maps;
		_tmp2_ = gee_map_get (_tmp1_, name);
		result = (GeeMap*) _tmp2_;
		return result;
	}
	_tmp3_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, json_node_get_type (), (GBoxedCopyFunc) _vala_JsonNode_copy, (GDestroyNotify) _vala_JsonNode_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	result = (GeeMap*) _tmp3_;
	return result;
}

GeeMap*
kkc_map_file_get_parent (KkcMapFile* self,
                         const gchar* name)
{
	GeeMap* _tmp0_;
	GeeHashMap* _tmp3_;
	GeeMap* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->priv->parent_maps;
	if (gee_map_has_key (_tmp0_, name)) {
		GeeMap* _tmp1_;
		gpointer _tmp2_;
		_tmp1_ = self->priv->parent_maps;
		_tmp2_ = gee_map_get (_tmp1_, name);
		result = (GeeMap*) _tmp2_;
		return result;
	}
	_tmp3_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, json_node_get_type (), (GBoxedCopyFunc) _vala_JsonNode_copy, (GDestroyNotify) _vala_JsonNode_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	result = (GeeMap*) _tmp3_;
	return result;
}

static void
kkc_map_file_class_init (KkcMapFileClass * klass,
                         gpointer klass_data)
{
	kkc_map_file_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcMapFile_private_offset);
	((KkcMapFileClass *) klass)->uniquify = (gchar* (*) (KkcMapFile*, const gchar*)) kkc_map_file_real_uniquify;
	G_OBJECT_CLASS (klass)->finalize = kkc_map_file_finalize;
}

static void
kkc_map_file_instance_init (KkcMapFile * self,
                            gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	self->priv = kkc_map_file_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->maps = (GeeMap*) _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->parent_maps = (GeeMap*) _tmp1_;
}

static void
kkc_map_file_finalize (GObject * obj)
{
	KkcMapFile * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_MAP_FILE, KkcMapFile);
	_g_object_unref0 (self->priv->maps);
	_g_object_unref0 (self->priv->parent_maps);
	G_OBJECT_CLASS (kkc_map_file_parent_class)->finalize (obj);
}

static GType
kkc_map_file_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcMapFileClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_map_file_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcMapFile), 0, (GInstanceInitFunc) kkc_map_file_instance_init, NULL };
	GType kkc_map_file_type_id;
	kkc_map_file_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcMapFile", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	KkcMapFile_private_offset = g_type_add_instance_private (kkc_map_file_type_id, sizeof (KkcMapFilePrivate));
	return kkc_map_file_type_id;
}

GType
kkc_map_file_get_type (void)
{
	static volatile gsize kkc_map_file_type_id__once = 0;
	if (g_once_init_enter (&kkc_map_file_type_id__once)) {
		GType kkc_map_file_type_id;
		kkc_map_file_type_id = kkc_map_file_get_type_once ();
		g_once_init_leave (&kkc_map_file_type_id__once, kkc_map_file_type_id);
	}
	return kkc_map_file_type_id__once;
}

