/* gcp-c-translator.c generated by valac 0.17.4.20-387e, the Vala compiler
 * generated from gcp-c-translator.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <clang-c/Index.h>
#include <gcp.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gobject/gvaluecollector.h>


#define GCP_C_TYPE_TRANSLATOR (gcp_c_translator_get_type ())
#define GCP_C_TRANSLATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCP_C_TYPE_TRANSLATOR, GcpCTranslator))
#define GCP_C_TRANSLATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCP_C_TYPE_TRANSLATOR, GcpCTranslatorClass))
#define GCP_C_IS_TRANSLATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCP_C_TYPE_TRANSLATOR))
#define GCP_C_IS_TRANSLATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCP_C_TYPE_TRANSLATOR))
#define GCP_C_TRANSLATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCP_C_TYPE_TRANSLATOR, GcpCTranslatorClass))

typedef struct _GcpCTranslator GcpCTranslator;
typedef struct _GcpCTranslatorClass GcpCTranslatorClass;
typedef struct _GcpCTranslatorPrivate GcpCTranslatorPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _GcpCParamSpecTranslator GcpCParamSpecTranslator;

struct _GcpCTranslator {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GcpCTranslatorPrivate * priv;
};

struct _GcpCTranslatorClass {
	GTypeClass parent_class;
	void (*finalize) (GcpCTranslator *self);
};

struct _GcpCParamSpecTranslator {
	GParamSpec parent_instance;
};


static gpointer gcp_c_translator_parent_class = NULL;
static GType gcp_c_translator_type_id = 0;

gpointer gcp_c_translator_ref (gpointer instance);
void gcp_c_translator_unref (gpointer instance);
GParamSpec* gcp_c_param_spec_translator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void gcp_c_value_set_translator (GValue* value, gpointer v_object);
void gcp_c_value_take_translator (GValue* value, gpointer v_object);
gpointer gcp_c_value_get_translator (const GValue* value);
GType gcp_c_translator_get_type (void) G_GNUC_CONST;
GType gcp_c_translator_register_type (GTypeModule * module);
enum  {
	GCP_C_TRANSLATOR_DUMMY_PROPERTY
};
GcpSourceLocation* gcp_c_translator_source_location (CXSourceLocation location);
GcpSourceRange* gcp_c_translator_source_range (CXSourceRange range);
GcpSemanticValueKind gcp_c_translator_semantic_kind (CXCursor cursor);
gboolean gcp_c_translator_is_reference (CXCursor cursor);
GcpSemanticValueReferenceType gcp_c_translator_semantic_reference_type (CXCursor cursor);
GcpDiagnosticSeverity gcp_c_translator_severity (enum CXDiagnosticSeverity severity);
GcpCTranslator* gcp_c_translator_new (void);
GcpCTranslator* gcp_c_translator_construct (GType object_type);
static void gcp_c_translator_finalize (GcpCTranslator* obj);


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


GcpSourceLocation* gcp_c_translator_source_location (CXSourceLocation location) {
	GcpSourceLocation* result = NULL;
	const void* file = NULL;
	guint line = 0U;
	guint column = 0U;
	guint offset = 0U;
	const void* _tmp0_ = NULL;
	guint _tmp1_ = 0U;
	guint _tmp2_ = 0U;
	guint _tmp3_ = 0U;
	const void* _tmp4_;
	CXString _tmp5_;
	CXString _tmp6_;
	const gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	gchar* filename;
	GFile* _tmp9_ = NULL;
	const gchar* _tmp10_;
	GFile* _tmp13_;
	GFile* _tmp14_;
	GFile* sfile;
	guint _tmp15_;
	guint _tmp16_;
	GcpSourceLocation* _tmp17_;
	clang_getInstantiationLocation (location, &_tmp0_, &_tmp1_, &_tmp2_, &_tmp3_);
	file = _tmp0_;
	line = _tmp1_;
	column = _tmp2_;
	offset = _tmp3_;
	_tmp4_ = file;
	_tmp5_ = clang_getFileName (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = clang_getCString (_tmp6_);
	_tmp8_ = g_strdup (_tmp7_);
	filename = _tmp8_;
	_tmp10_ = filename;
	if (_tmp10_ != NULL) {
		const gchar* _tmp11_;
		GFile* _tmp12_ = NULL;
		_tmp11_ = filename;
		_tmp12_ = g_file_new_for_path (_tmp11_);
		_g_object_unref0 (_tmp9_);
		_tmp9_ = _tmp12_;
	} else {
		_g_object_unref0 (_tmp9_);
		_tmp9_ = NULL;
	}
	_tmp13_ = _tmp9_;
	_tmp14_ = _g_object_ref0 (_tmp13_);
	sfile = _tmp14_;
	_tmp15_ = line;
	_tmp16_ = column;
	_tmp17_ = gcp_source_location_new (sfile, (gint) _tmp15_, (gint) _tmp16_);
	result = _tmp17_;
	_g_object_unref0 (sfile);
	_g_object_unref0 (_tmp9_);
	_g_free0 (filename);
	return result;
}


GcpSourceRange* gcp_c_translator_source_range (CXSourceRange range) {
	GcpSourceRange* result = NULL;
	CXSourceLocation _tmp0_ = {0};
	GcpSourceLocation* _tmp1_ = NULL;
	GcpSourceLocation* _tmp2_;
	CXSourceLocation _tmp3_ = {0};
	GcpSourceLocation* _tmp4_ = NULL;
	GcpSourceLocation* _tmp5_;
	GcpSourceRange* _tmp6_;
	GcpSourceRange* _tmp7_;
	_tmp0_ = clang_getRangeStart (range);
	_tmp1_ = gcp_c_translator_source_location (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = clang_getRangeEnd (range);
	_tmp4_ = gcp_c_translator_source_location (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = gcp_source_range_new (_tmp2_, _tmp5_);
	_tmp7_ = _tmp6_;
	_g_object_unref0 (_tmp5_);
	_g_object_unref0 (_tmp2_);
	result = _tmp7_;
	return result;
}


GcpSemanticValueKind gcp_c_translator_semantic_kind (CXCursor cursor) {
	GcpSemanticValueKind result = 0;
	CXCursor _tmp0_;
	gboolean _tmp1_ = FALSE;
	enum CXCursorKind _tmp4_ = 0;
	_tmp0_ = cursor;
	_tmp1_ = gcp_c_translator_is_reference (_tmp0_);
	if (_tmp1_) {
		CXCursor _tmp2_ = {0};
		GcpSemanticValueKind _tmp3_ = 0;
		_tmp2_ = clang_getCursorReferenced (cursor);
		_tmp3_ = gcp_c_translator_semantic_kind (_tmp2_);
		result = _tmp3_;
		return result;
	}
	_tmp4_ = clang_getCursorKind (cursor);
	switch (_tmp4_) {
		case CXCursor_StructDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_STRUCT;
			return result;
		}
		case CXCursor_UnionDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_UNION;
			return result;
		}
		case CXCursor_ClassDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_CLASS;
			return result;
		}
		case CXCursor_EnumDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_ENUM;
			return result;
		}
		case CXCursor_FieldDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_FIELD;
			return result;
		}
		case CXCursor_EnumConstantDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_ENUM_VALUE;
			return result;
		}
		case CXCursor_FunctionDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_FUNCTION;
			return result;
		}
		case CXCursor_CXXMethod:
		case CXCursor_ConversionFunction:
		{
			result = GCP_SEMANTIC_VALUE_KIND_MEMBER_FUNCTION;
			return result;
		}
		case CXCursor_Constructor:
		{
			result = GCP_SEMANTIC_VALUE_KIND_CONSTRUCTOR;
			return result;
		}
		case CXCursor_Destructor:
		{
			result = GCP_SEMANTIC_VALUE_KIND_DESTRUCTOR;
			return result;
		}
		case CXCursor_VarDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_VARIABLE;
			return result;
		}
		case CXCursor_ParmDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_PARAMETER;
			return result;
		}
		case CXCursor_TypedefDecl:
		{
			result = GCP_SEMANTIC_VALUE_KIND_TYPEDEF;
			return result;
		}
		case CXCursor_Namespace:
		case CXCursor_NamespaceRef:
		{
			result = GCP_SEMANTIC_VALUE_KIND_NAMESPACE;
			return result;
		}
		case CXCursor_BlockExpr:
		{
			result = GCP_SEMANTIC_VALUE_KIND_BLOCK;
			return result;
		}
		default:
		{
			result = GCP_SEMANTIC_VALUE_KIND_NONE;
			return result;
		}
	}
}


GcpSemanticValueReferenceType gcp_c_translator_semantic_reference_type (CXCursor cursor) {
	GcpSemanticValueReferenceType result = 0;
	GcpSemanticValueReferenceType rtype = 0;
	enum CXCursorKind _tmp0_ = 0;
	gboolean _tmp1_ = FALSE;
	enum CXCursorKind _tmp3_ = 0;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp6_ = FALSE;
	rtype = GCP_SEMANTIC_VALUE_REFERENCE_TYPE_NONE;
	_tmp0_ = clang_getCursorKind (cursor);
	_tmp1_ = clang_isReference (_tmp0_);
	if (_tmp1_) {
		GcpSemanticValueReferenceType _tmp2_;
		_tmp2_ = rtype;
		rtype = _tmp2_ | GCP_SEMANTIC_VALUE_REFERENCE_TYPE_REFERENCE;
	}
	_tmp3_ = clang_getCursorKind (cursor);
	_tmp4_ = clang_isDeclaration (_tmp3_);
	if (_tmp4_) {
		GcpSemanticValueReferenceType _tmp5_;
		_tmp5_ = rtype;
		rtype = _tmp5_ | GCP_SEMANTIC_VALUE_REFERENCE_TYPE_DECLARATION;
	}
	_tmp6_ = clang_isCursorDefinition (cursor);
	if (_tmp6_) {
		GcpSemanticValueReferenceType _tmp7_;
		_tmp7_ = rtype;
		rtype = _tmp7_ | GCP_SEMANTIC_VALUE_REFERENCE_TYPE_DEFINITION;
	}
	result = rtype;
	return result;
}


GcpDiagnosticSeverity gcp_c_translator_severity (enum CXDiagnosticSeverity severity) {
	GcpDiagnosticSeverity result = 0;
	enum CXDiagnosticSeverity _tmp0_;
	_tmp0_ = severity;
	switch (_tmp0_) {
		case CXDiagnostic_Note:
		{
			result = GCP_DIAGNOSTIC_SEVERITY_INFO;
			return result;
		}
		case CXDiagnostic_Warning:
		{
			result = GCP_DIAGNOSTIC_SEVERITY_WARNING;
			return result;
		}
		case CXDiagnostic_Error:
		{
			result = GCP_DIAGNOSTIC_SEVERITY_ERROR;
			return result;
		}
		case CXDiagnostic_Fatal:
		{
			result = GCP_DIAGNOSTIC_SEVERITY_FATAL;
			return result;
		}
		default:
		{
			result = GCP_DIAGNOSTIC_SEVERITY_NONE;
			return result;
		}
	}
}


gboolean gcp_c_translator_is_reference (CXCursor cursor) {
	gboolean result = FALSE;
	enum CXCursorKind _tmp0_ = 0;
	gboolean _tmp1_ = FALSE;
	enum CXCursorKind _tmp2_ = 0;
	_tmp0_ = clang_getCursorKind (cursor);
	_tmp1_ = clang_isReference (_tmp0_);
	if (_tmp1_) {
		result = TRUE;
		return result;
	}
	_tmp2_ = clang_getCursorKind (cursor);
	switch (_tmp2_) {
		case CXCursor_DeclRefExpr:
		case CXCursor_MemberRefExpr:
		{
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}


GcpCTranslator* gcp_c_translator_construct (GType object_type) {
	GcpCTranslator* self = NULL;
	self = (GcpCTranslator*) g_type_create_instance (object_type);
	return self;
}


GcpCTranslator* gcp_c_translator_new (void) {
	return gcp_c_translator_construct (GCP_C_TYPE_TRANSLATOR);
}


static void gcp_c_value_translator_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void gcp_c_value_translator_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		gcp_c_translator_unref (value->data[0].v_pointer);
	}
}


static void gcp_c_value_translator_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = gcp_c_translator_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer gcp_c_value_translator_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* gcp_c_value_translator_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		GcpCTranslator* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = gcp_c_translator_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* gcp_c_value_translator_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	GcpCTranslator** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = gcp_c_translator_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* gcp_c_param_spec_translator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	GcpCParamSpecTranslator* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GCP_C_TYPE_TRANSLATOR), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer gcp_c_value_get_translator (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GCP_C_TYPE_TRANSLATOR), NULL);
	return value->data[0].v_pointer;
}


void gcp_c_value_set_translator (GValue* value, gpointer v_object) {
	GcpCTranslator* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GCP_C_TYPE_TRANSLATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GCP_C_TYPE_TRANSLATOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		gcp_c_translator_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gcp_c_translator_unref (old);
	}
}


void gcp_c_value_take_translator (GValue* value, gpointer v_object) {
	GcpCTranslator* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GCP_C_TYPE_TRANSLATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GCP_C_TYPE_TRANSLATOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gcp_c_translator_unref (old);
	}
}


static void gcp_c_translator_class_init (GcpCTranslatorClass * klass) {
	gcp_c_translator_parent_class = g_type_class_peek_parent (klass);
	GCP_C_TRANSLATOR_CLASS (klass)->finalize = gcp_c_translator_finalize;
}


static void gcp_c_translator_instance_init (GcpCTranslator * self) {
	self->ref_count = 1;
}


static void gcp_c_translator_finalize (GcpCTranslator* obj) {
	GcpCTranslator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCP_C_TYPE_TRANSLATOR, GcpCTranslator);
}


GType gcp_c_translator_get_type (void) {
	return gcp_c_translator_type_id;
}


GType gcp_c_translator_register_type (GTypeModule * module) {
	static const GTypeValueTable g_define_type_value_table = { gcp_c_value_translator_init, gcp_c_value_translator_free_value, gcp_c_value_translator_copy_value, gcp_c_value_translator_peek_pointer, "p", gcp_c_value_translator_collect_value, "p", gcp_c_value_translator_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GcpCTranslatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcp_c_translator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GcpCTranslator), 0, (GInstanceInitFunc) gcp_c_translator_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	gcp_c_translator_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GcpCTranslator", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return gcp_c_translator_type_id;
}


gpointer gcp_c_translator_ref (gpointer instance) {
	GcpCTranslator* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void gcp_c_translator_unref (gpointer instance) {
	GcpCTranslator* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GCP_C_TRANSLATOR_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



