/* function-manager.c generated by valac 0.40.6, the Vala compiler
 * generated from function-manager.vala, do not modify */

/*
 * Copyright (C) 2013 Garima Joshi
 *
 * 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. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>


#define TYPE_FUNCTION_MANAGER (function_manager_get_type ())
#define FUNCTION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FUNCTION_MANAGER, FunctionManager))
#define FUNCTION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FUNCTION_MANAGER, FunctionManagerClass))
#define IS_FUNCTION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FUNCTION_MANAGER))
#define IS_FUNCTION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FUNCTION_MANAGER))
#define FUNCTION_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FUNCTION_MANAGER, FunctionManagerClass))

typedef struct _FunctionManager FunctionManager;
typedef struct _FunctionManagerClass FunctionManagerClass;
typedef struct _FunctionManagerPrivate FunctionManagerPrivate;

#define TYPE_MATH_FUNCTION (math_function_get_type ())
#define MATH_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MATH_FUNCTION, MathFunction))
#define MATH_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MATH_FUNCTION, MathFunctionClass))
#define IS_MATH_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MATH_FUNCTION))
#define IS_MATH_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MATH_FUNCTION))
#define MATH_FUNCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MATH_FUNCTION, MathFunctionClass))

typedef struct _MathFunction MathFunction;
typedef struct _MathFunctionClass MathFunctionClass;

#define TYPE_SERIALIZER (serializer_get_type ())
#define SERIALIZER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SERIALIZER, Serializer))
#define SERIALIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SERIALIZER, SerializerClass))
#define IS_SERIALIZER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SERIALIZER))
#define IS_SERIALIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SERIALIZER))
#define SERIALIZER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SERIALIZER, SerializerClass))

typedef struct _Serializer Serializer;
typedef struct _SerializerClass SerializerClass;
enum  {
	FUNCTION_MANAGER_0_PROPERTY,
	FUNCTION_MANAGER_NUM_PROPERTIES
};
static GParamSpec* function_manager_properties[FUNCTION_MANAGER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_DISPLAY_FORMAT (display_format_get_type ())

#define TYPE_BUILT_IN_MATH_FUNCTION (built_in_math_function_get_type ())
#define BUILT_IN_MATH_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BUILT_IN_MATH_FUNCTION, BuiltInMathFunction))
#define BUILT_IN_MATH_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BUILT_IN_MATH_FUNCTION, BuiltInMathFunctionClass))
#define IS_BUILT_IN_MATH_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BUILT_IN_MATH_FUNCTION))
#define IS_BUILT_IN_MATH_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BUILT_IN_MATH_FUNCTION))
#define BUILT_IN_MATH_FUNCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BUILT_IN_MATH_FUNCTION, BuiltInMathFunctionClass))

typedef struct _BuiltInMathFunction BuiltInMathFunction;
typedef struct _BuiltInMathFunctionClass BuiltInMathFunctionClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

#define TYPE_PARSER (parser_get_type ())
#define PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PARSER, Parser))
#define PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PARSER, ParserClass))
#define IS_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PARSER))
#define IS_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PARSER))
#define PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PARSER, ParserClass))

typedef struct _Parser Parser;
typedef struct _ParserClass ParserClass;

#define TYPE_ERROR_CODE (error_code_get_type ())

#define TYPE_NUMBER (number_get_type ())
#define NUMBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NUMBER, Number))
#define NUMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NUMBER, NumberClass))
#define IS_NUMBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NUMBER))
#define IS_NUMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NUMBER))
#define NUMBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NUMBER, NumberClass))

typedef struct _Number Number;
typedef struct _NumberClass NumberClass;
enum  {
	FUNCTION_MANAGER_FUNCTION_ADDED_SIGNAL,
	FUNCTION_MANAGER_FUNCTION_EDITED_SIGNAL,
	FUNCTION_MANAGER_FUNCTION_DELETED_SIGNAL,
	FUNCTION_MANAGER_NUM_SIGNALS
};
static guint function_manager_signals[FUNCTION_MANAGER_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _FunctionManager {
	GObject parent_instance;
	FunctionManagerPrivate * priv;
};

struct _FunctionManagerClass {
	GObjectClass parent_class;
};

struct _FunctionManagerPrivate {
	gchar* file_name;
	GHashTable* functions;
	Serializer* serializer;
};

typedef enum  {
	DISPLAY_FORMAT_AUTOMATIC,
	DISPLAY_FORMAT_FIXED,
	DISPLAY_FORMAT_SCIENTIFIC,
	DISPLAY_FORMAT_ENGINEERING
} DisplayFormat;

typedef enum  {
	ERROR_CODE_NONE,
	ERROR_CODE_INVALID,
	ERROR_CODE_OVERFLOW,
	ERROR_CODE_UNKNOWN_VARIABLE,
	ERROR_CODE_UNKNOWN_FUNCTION,
	ERROR_CODE_UNKNOWN_CONVERSION,
	ERROR_CODE_MP
} ErrorCode;


extern FunctionManager* default_function_manager;
FunctionManager* default_function_manager = NULL;
static gpointer function_manager_parent_class = NULL;

GType function_manager_get_type (void) G_GNUC_CONST;
GType math_function_get_type (void) G_GNUC_CONST;
GType serializer_get_type (void) G_GNUC_CONST;
#define FUNCTION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_FUNCTION_MANAGER, FunctionManagerPrivate))
FunctionManager* function_manager_new (void);
FunctionManager* function_manager_construct (GType object_type);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
GType display_format_get_type (void) G_GNUC_CONST;
Serializer* serializer_new (DisplayFormat format,
                            gint number_base,
                            gint trailing_digits);
Serializer* serializer_construct (GType object_type,
                                  DisplayFormat format,
                                  gint number_base,
                                  gint trailing_digits);
void serializer_set_radix (Serializer* self,
                           gunichar radix);
static void function_manager_reload_functions (FunctionManager* self);
FunctionManager* function_manager_get_default_function_manager (void);
static void function_manager_reload_custom_functions (FunctionManager* self);
static void function_manager_reload_builtin_functions (FunctionManager* self);
static gboolean function_manager_add (FunctionManager* self,
                               MathFunction* new_function);
BuiltInMathFunction* built_in_math_function_new (const gchar* function_name,
                                                 const gchar* description);
BuiltInMathFunction* built_in_math_function_construct (GType object_type,
                                                       const gchar* function_name,
                                                       const gchar* description);
GType built_in_math_function_get_type (void) G_GNUC_CONST;
static MathFunction* function_manager_parse_function_from_string (FunctionManager* self,
                                                           const gchar* data);
const gchar* math_function_get_name (MathFunction* self);
MathFunction* math_function_new (const gchar* function_name,
                                 gchar** arguments,
                                 int arguments_length1,
                                 const gchar* expression,
                                 const gchar* description);
MathFunction* math_function_construct (GType object_type,
                                       const gchar* function_name,
                                       gchar** arguments,
                                       int arguments_length1,
                                       const gchar* expression,
                                       const gchar* description);
static void function_manager_save (FunctionManager* self);
gboolean math_function_is_custom_function (MathFunction* self);
gchar** math_function_get_arguments (MathFunction* self,
                                     int* result_length1);
const gchar* math_function_get_expression (MathFunction* self);
const gchar* math_function_get_description (MathFunction* self);
static gchar** function_manager_array_sort_string (FunctionManager* self,
                                            gchar** array,
                                            int array_length1,
                                            int* result_length1);
static gchar** _vala_array_dup1 (gchar** self,
                          int length);
gchar** function_manager_get_names (FunctionManager* self,
                                    int* result_length1);
MathFunction* function_manager_get (FunctionManager* self,
                                    const gchar* name);
gpointer parser_ref (gpointer instance);
void parser_unref (gpointer instance);
GParamSpec* param_spec_parser (const gchar* name,
                               const gchar* nick,
                               const gchar* blurb,
                               GType object_type,
                               GParamFlags flags);
void value_set_parser (GValue* value,
                       gpointer v_object);
void value_take_parser (GValue* value,
                        gpointer v_object);
gpointer value_get_parser (const GValue* value);
GType parser_get_type (void) G_GNUC_CONST;
gboolean function_manager_add_function_with_properties (FunctionManager* self,
                                                        const gchar* name,
                                                        const gchar* arguments,
                                                        const gchar* description,
                                                        Parser* root_parser);
gboolean math_function_validate (MathFunction* self,
                                 Parser* root_parser);
GType error_code_get_type (void) G_GNUC_CONST;
void parser_set_error (Parser* self,
                       ErrorCode errorno,
                       const gchar* token,
                       guint token_start,
                       guint token_end);
void function_manager_delete (FunctionManager* self,
                              const gchar* name);
gboolean function_manager_is_function_defined (FunctionManager* self,
                                               const gchar* name);
gint sub_atoi (const gchar* data);
GType number_get_type (void) G_GNUC_CONST;
Number* function_manager_evaluate_function (FunctionManager* self,
                                            const gchar* name,
                                            Number** arguments,
                                            int arguments_length1,
                                            Parser* parser);
static Number** _vala_array_dup2 (Number** self,
                           int length);
Number* number_new_integer (gint64 real,
                            gint64 imag);
Number* number_construct_integer (GType object_type,
                                  gint64 real,
                                  gint64 imag);
static void _vala_array_add3 (Number** * array,
                       int* length,
                       int* size,
                       Number* value);
Number* math_function_evaluate (MathFunction* self,
                                Number** args,
                                int args_length1,
                                Parser* root_parser);
static MathFunction** function_manager_array_sort_math_function (FunctionManager* self,
                                                          MathFunction** array,
                                                          int array_length1,
                                                          int* result_length1);
static MathFunction** _vala_array_dup3 (MathFunction** self,
                                 int length);
static MathFunction** _vala_array_dup4 (MathFunction** self,
                                 int length);
MathFunction** function_manager_functions_eligible_for_autocompletion_for_text (FunctionManager* self,
                                                                                const gchar* display_text,
                                                                                int* result_length1);
static void _vala_array_add4 (MathFunction** * array,
                       int* length,
                       int* size,
                       MathFunction* value);
static void function_manager_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 void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}


static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


FunctionManager*
function_manager_construct (GType object_type)
{
	FunctionManager * self = NULL;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	Serializer* _tmp5_;
	Serializer* _tmp6_;
	self = (FunctionManager*) g_object_new (object_type, NULL);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->functions);
	self->priv->functions = _tmp2_;
	_tmp3_ = g_get_user_data_dir ();
	_tmp4_ = g_build_filename (_tmp3_, "gnome-calculator", "custom-functions", NULL);
	_g_free0 (self->priv->file_name);
	self->priv->file_name = _tmp4_;
	_tmp5_ = serializer_new (DISPLAY_FORMAT_SCIENTIFIC, 10, 50);
	_g_object_unref0 (self->priv->serializer);
	self->priv->serializer = _tmp5_;
	_tmp6_ = self->priv->serializer;
	serializer_set_radix (_tmp6_, (gunichar) '.');
	function_manager_reload_functions (self);
	return self;
}


FunctionManager*
function_manager_new (void)
{
	return function_manager_construct (TYPE_FUNCTION_MANAGER);
}


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


FunctionManager*
function_manager_get_default_function_manager (void)
{
	FunctionManager* result = NULL;
	FunctionManager* _tmp0_;
	FunctionManager* _tmp2_;
	FunctionManager* _tmp3_;
	_tmp0_ = default_function_manager;
	if (_tmp0_ == NULL) {
		FunctionManager* _tmp1_;
		_tmp1_ = function_manager_new ();
		_g_object_unref0 (default_function_manager);
		default_function_manager = _tmp1_;
	}
	_tmp2_ = default_function_manager;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


static void
function_manager_reload_functions (FunctionManager* self)
{
	GHashTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->functions;
	g_hash_table_remove_all (_tmp0_);
	function_manager_reload_custom_functions (self);
	function_manager_reload_builtin_functions (self);
}


static void
function_manager_reload_builtin_functions (FunctionManager* self)
{
	BuiltInMathFunction* _tmp0_;
	BuiltInMathFunction* _tmp1_;
	BuiltInMathFunction* _tmp2_;
	BuiltInMathFunction* _tmp3_;
	BuiltInMathFunction* _tmp4_;
	BuiltInMathFunction* _tmp5_;
	BuiltInMathFunction* _tmp6_;
	BuiltInMathFunction* _tmp7_;
	BuiltInMathFunction* _tmp8_;
	BuiltInMathFunction* _tmp9_;
	BuiltInMathFunction* _tmp10_;
	BuiltInMathFunction* _tmp11_;
	BuiltInMathFunction* _tmp12_;
	BuiltInMathFunction* _tmp13_;
	BuiltInMathFunction* _tmp14_;
	BuiltInMathFunction* _tmp15_;
	BuiltInMathFunction* _tmp16_;
	BuiltInMathFunction* _tmp17_;
	BuiltInMathFunction* _tmp18_;
	BuiltInMathFunction* _tmp19_;
	BuiltInMathFunction* _tmp20_;
	BuiltInMathFunction* _tmp21_;
	BuiltInMathFunction* _tmp22_;
	BuiltInMathFunction* _tmp23_;
	BuiltInMathFunction* _tmp24_;
	BuiltInMathFunction* _tmp25_;
	BuiltInMathFunction* _tmp26_;
	BuiltInMathFunction* _tmp27_;
	BuiltInMathFunction* _tmp28_;
	BuiltInMathFunction* _tmp29_;
	BuiltInMathFunction* _tmp30_;
	BuiltInMathFunction* _tmp31_;
	BuiltInMathFunction* _tmp32_;
	BuiltInMathFunction* _tmp33_;
	BuiltInMathFunction* _tmp34_;
	BuiltInMathFunction* _tmp35_;
	BuiltInMathFunction* _tmp36_;
	BuiltInMathFunction* _tmp37_;
	BuiltInMathFunction* _tmp38_;
	BuiltInMathFunction* _tmp39_;
	BuiltInMathFunction* _tmp40_;
	BuiltInMathFunction* _tmp41_;
	BuiltInMathFunction* _tmp42_;
	BuiltInMathFunction* _tmp43_;
	BuiltInMathFunction* _tmp44_;
	BuiltInMathFunction* _tmp45_;
	BuiltInMathFunction* _tmp46_;
	BuiltInMathFunction* _tmp47_;
	BuiltInMathFunction* _tmp48_;
	BuiltInMathFunction* _tmp49_;
	BuiltInMathFunction* _tmp50_;
	BuiltInMathFunction* _tmp51_;
	BuiltInMathFunction* _tmp52_;
	BuiltInMathFunction* _tmp53_;
	BuiltInMathFunction* _tmp54_;
	BuiltInMathFunction* _tmp55_;
	BuiltInMathFunction* _tmp56_;
	BuiltInMathFunction* _tmp57_;
	BuiltInMathFunction* _tmp58_;
	BuiltInMathFunction* _tmp59_;
	BuiltInMathFunction* _tmp60_;
	BuiltInMathFunction* _tmp61_;
	BuiltInMathFunction* _tmp62_;
	BuiltInMathFunction* _tmp63_;
	BuiltInMathFunction* _tmp64_;
	BuiltInMathFunction* _tmp65_;
	BuiltInMathFunction* _tmp66_;
	BuiltInMathFunction* _tmp67_;
	g_return_if_fail (self != NULL);
	_tmp0_ = built_in_math_function_new ("log", "Logarithm");
	_tmp1_ = _tmp0_;
	function_manager_add (self, (MathFunction*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = built_in_math_function_new ("ln", "Natural logarithm");
	_tmp3_ = _tmp2_;
	function_manager_add (self, (MathFunction*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = built_in_math_function_new ("sqrt", "Square root");
	_tmp5_ = _tmp4_;
	function_manager_add (self, (MathFunction*) _tmp5_);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = built_in_math_function_new ("abs", "Absolute value");
	_tmp7_ = _tmp6_;
	function_manager_add (self, (MathFunction*) _tmp7_);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = built_in_math_function_new ("sgn", "Signum");
	_tmp9_ = _tmp8_;
	function_manager_add (self, (MathFunction*) _tmp9_);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = built_in_math_function_new ("arg", "Argument");
	_tmp11_ = _tmp10_;
	function_manager_add (self, (MathFunction*) _tmp11_);
	_g_object_unref0 (_tmp11_);
	_tmp12_ = built_in_math_function_new ("conj", "Conjugate");
	_tmp13_ = _tmp12_;
	function_manager_add (self, (MathFunction*) _tmp13_);
	_g_object_unref0 (_tmp13_);
	_tmp14_ = built_in_math_function_new ("int", "Integer");
	_tmp15_ = _tmp14_;
	function_manager_add (self, (MathFunction*) _tmp15_);
	_g_object_unref0 (_tmp15_);
	_tmp16_ = built_in_math_function_new ("frac", "Fraction");
	_tmp17_ = _tmp16_;
	function_manager_add (self, (MathFunction*) _tmp17_);
	_g_object_unref0 (_tmp17_);
	_tmp18_ = built_in_math_function_new ("floor", "Floor");
	_tmp19_ = _tmp18_;
	function_manager_add (self, (MathFunction*) _tmp19_);
	_g_object_unref0 (_tmp19_);
	_tmp20_ = built_in_math_function_new ("ceil", "Ceiling");
	_tmp21_ = _tmp20_;
	function_manager_add (self, (MathFunction*) _tmp21_);
	_g_object_unref0 (_tmp21_);
	_tmp22_ = built_in_math_function_new ("round", "Round");
	_tmp23_ = _tmp22_;
	function_manager_add (self, (MathFunction*) _tmp23_);
	_g_object_unref0 (_tmp23_);
	_tmp24_ = built_in_math_function_new ("re", "Real");
	_tmp25_ = _tmp24_;
	function_manager_add (self, (MathFunction*) _tmp25_);
	_g_object_unref0 (_tmp25_);
	_tmp26_ = built_in_math_function_new ("im", "Imaginary");
	_tmp27_ = _tmp26_;
	function_manager_add (self, (MathFunction*) _tmp27_);
	_g_object_unref0 (_tmp27_);
	_tmp28_ = built_in_math_function_new ("sin", "Sine");
	_tmp29_ = _tmp28_;
	function_manager_add (self, (MathFunction*) _tmp29_);
	_g_object_unref0 (_tmp29_);
	_tmp30_ = built_in_math_function_new ("cos", "Cosine");
	_tmp31_ = _tmp30_;
	function_manager_add (self, (MathFunction*) _tmp31_);
	_g_object_unref0 (_tmp31_);
	_tmp32_ = built_in_math_function_new ("tan", "Tangent");
	_tmp33_ = _tmp32_;
	function_manager_add (self, (MathFunction*) _tmp33_);
	_g_object_unref0 (_tmp33_);
	_tmp34_ = built_in_math_function_new ("asin", "Arc sine");
	_tmp35_ = _tmp34_;
	function_manager_add (self, (MathFunction*) _tmp35_);
	_g_object_unref0 (_tmp35_);
	_tmp36_ = built_in_math_function_new ("acos", "Arc cosine");
	_tmp37_ = _tmp36_;
	function_manager_add (self, (MathFunction*) _tmp37_);
	_g_object_unref0 (_tmp37_);
	_tmp38_ = built_in_math_function_new ("atan", "Arc tangent");
	_tmp39_ = _tmp38_;
	function_manager_add (self, (MathFunction*) _tmp39_);
	_g_object_unref0 (_tmp39_);
	_tmp40_ = built_in_math_function_new ("sin⁻¹", "Inverse sine");
	_tmp41_ = _tmp40_;
	function_manager_add (self, (MathFunction*) _tmp41_);
	_g_object_unref0 (_tmp41_);
	_tmp42_ = built_in_math_function_new ("cos⁻¹", "Inverse cosine");
	_tmp43_ = _tmp42_;
	function_manager_add (self, (MathFunction*) _tmp43_);
	_g_object_unref0 (_tmp43_);
	_tmp44_ = built_in_math_function_new ("tan⁻¹", "Inverse tangent");
	_tmp45_ = _tmp44_;
	function_manager_add (self, (MathFunction*) _tmp45_);
	_g_object_unref0 (_tmp45_);
	_tmp46_ = built_in_math_function_new ("sinh", "Hyperbolic sine");
	_tmp47_ = _tmp46_;
	function_manager_add (self, (MathFunction*) _tmp47_);
	_g_object_unref0 (_tmp47_);
	_tmp48_ = built_in_math_function_new ("cosh", "Hyperbolic cosine");
	_tmp49_ = _tmp48_;
	function_manager_add (self, (MathFunction*) _tmp49_);
	_g_object_unref0 (_tmp49_);
	_tmp50_ = built_in_math_function_new ("tanh", "Hyperbolic tangent");
	_tmp51_ = _tmp50_;
	function_manager_add (self, (MathFunction*) _tmp51_);
	_g_object_unref0 (_tmp51_);
	_tmp52_ = built_in_math_function_new ("sinh⁻¹", "Hyperbolic arcsine");
	_tmp53_ = _tmp52_;
	function_manager_add (self, (MathFunction*) _tmp53_);
	_g_object_unref0 (_tmp53_);
	_tmp54_ = built_in_math_function_new ("cosh⁻¹", "Hyperbolic arccosine");
	_tmp55_ = _tmp54_;
	function_manager_add (self, (MathFunction*) _tmp55_);
	_g_object_unref0 (_tmp55_);
	_tmp56_ = built_in_math_function_new ("tanh⁻¹", "Hyperbolic arctangent");
	_tmp57_ = _tmp56_;
	function_manager_add (self, (MathFunction*) _tmp57_);
	_g_object_unref0 (_tmp57_);
	_tmp58_ = built_in_math_function_new ("asinh", "Inverse hyperbolic sine");
	_tmp59_ = _tmp58_;
	function_manager_add (self, (MathFunction*) _tmp59_);
	_g_object_unref0 (_tmp59_);
	_tmp60_ = built_in_math_function_new ("acosh", "Inverse hyperbolic cosine");
	_tmp61_ = _tmp60_;
	function_manager_add (self, (MathFunction*) _tmp61_);
	_g_object_unref0 (_tmp61_);
	_tmp62_ = built_in_math_function_new ("atanh", "Inverse hyperbolic tangent");
	_tmp63_ = _tmp62_;
	function_manager_add (self, (MathFunction*) _tmp63_);
	_g_object_unref0 (_tmp63_);
	_tmp64_ = built_in_math_function_new ("ones", "One's complement");
	_tmp65_ = _tmp64_;
	function_manager_add (self, (MathFunction*) _tmp65_);
	_g_object_unref0 (_tmp65_);
	_tmp66_ = built_in_math_function_new ("twos", "Two's complement");
	_tmp67_ = _tmp66_;
	function_manager_add (self, (MathFunction*) _tmp67_);
	_g_object_unref0 (_tmp67_);
}


static void
function_manager_reload_custom_functions (FunctionManager* self)
{
	gchar* data = NULL;
	gchar** lines = NULL;
	const gchar* _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	gint lines_length1;
	gint _lines_size_;
	gchar** _tmp5_;
	gint _tmp5__length1;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		const gchar* _tmp0_;
		gchar* _tmp1_ = NULL;
		_tmp0_ = self->priv->file_name;
		g_file_get_contents (_tmp0_, &_tmp1_, NULL, &_inner_error_);
		_g_free0 (data);
		data = _tmp1_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch3_g_file_error;
			}
			_g_free0 (data);
			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;
		}
	}
	goto __finally3;
	__catch3_g_file_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
		_g_free0 (data);
		return;
	}
	__finally3:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_free0 (data);
		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;
	}
	_tmp2_ = data;
	_tmp4_ = _tmp3_ = g_strsplit (_tmp2_, "\n", 0);
	lines = _tmp4_;
	lines_length1 = _vala_array_length (_tmp3_);
	_lines_size_ = lines_length1;
	_tmp5_ = lines;
	_tmp5__length1 = lines_length1;
	{
		gchar** line_collection = NULL;
		gint line_collection_length1 = 0;
		gint _line_collection_size_ = 0;
		gint line_it = 0;
		line_collection = _tmp5_;
		line_collection_length1 = _tmp5__length1;
		for (line_it = 0; line_it < _tmp5__length1; line_it = line_it + 1) {
			gchar* _tmp6_;
			gchar* line = NULL;
			_tmp6_ = g_strdup (line_collection[line_it]);
			line = _tmp6_;
			{
				MathFunction* function = NULL;
				const gchar* _tmp7_;
				MathFunction* _tmp8_;
				MathFunction* _tmp9_;
				_tmp7_ = line;
				_tmp8_ = function_manager_parse_function_from_string (self, _tmp7_);
				function = _tmp8_;
				_tmp9_ = function;
				if (_tmp9_ != NULL) {
					GHashTable* _tmp10_;
					MathFunction* _tmp11_;
					const gchar* _tmp12_;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					MathFunction* _tmp15_;
					MathFunction* _tmp16_;
					_tmp10_ = self->priv->functions;
					_tmp11_ = function;
					_tmp12_ = math_function_get_name (_tmp11_);
					_tmp13_ = _tmp12_;
					_tmp14_ = g_strdup (_tmp13_);
					_tmp15_ = function;
					_tmp16_ = _g_object_ref0 (_tmp15_);
					g_hash_table_insert (_tmp10_, _tmp14_, _tmp16_);
				}
				_g_object_unref0 (function);
				_g_free0 (line);
			}
		}
	}
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (data);
}


static gint
string_index_of_char (const gchar* self,
                      gunichar c,
                      gint start_index)
{
	gint result = 0;
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = g_utf8_strchr (((gchar*) self) + start_index, (gssize) -1, c);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}


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


static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	glong _tmp6_;
	gchar* _tmp7_;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		glong _tmp3_;
		_tmp3_ = string_length;
		offset = _tmp3_ + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		glong _tmp4_;
		_tmp4_ = string_length;
		g_return_val_if_fail (offset <= _tmp4_, NULL);
	}
	if (len < ((glong) 0)) {
		glong _tmp5_;
		_tmp5_ = string_length;
		len = _tmp5_ - offset;
	}
	_tmp6_ = string_length;
	g_return_val_if_fail ((offset + len) <= _tmp6_, NULL);
	_tmp7_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp7_;
	return result;
}


static gchar*
string_strip (const gchar* self)
{
	gchar* result = NULL;
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	g_strstrip (_tmp1_);
	result = _result_;
	return result;
}


static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gchar* result = NULL;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			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 NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch4_g_regex_error;
			}
			_g_regex_unref0 (regex);
			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 NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally4;
	__catch4_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally4:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		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 NULL;
	}
}


static MathFunction*
function_manager_parse_function_from_string (FunctionManager* self,
                                             const gchar* data)
{
	MathFunction* result = NULL;
	gint i = 0;
	gint _tmp0_;
	gchar* left = NULL;
	gint _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* right = NULL;
	gint _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_ = FALSE;
	const gchar* _tmp12_;
	gchar* expression = NULL;
	gchar* _tmp14_;
	gchar* description = NULL;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	gint _tmp17_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gint _tmp32_;
	gchar* name = NULL;
	const gchar* _tmp33_;
	gint _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	gchar* argument_list = NULL;
	const gchar* _tmp39_;
	gint _tmp40_;
	gchar* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	gboolean _tmp45_ = FALSE;
	const gchar* _tmp46_;
	const gchar* _tmp48_;
	gchar* _tmp49_;
	gchar** arguments = NULL;
	const gchar* _tmp50_;
	gchar** _tmp51_;
	gchar** _tmp52_;
	gint arguments_length1;
	gint _arguments_size_;
	const gchar* _tmp53_;
	gchar** _tmp54_;
	gint _tmp54__length1;
	const gchar* _tmp55_;
	const gchar* _tmp56_;
	MathFunction* _tmp57_;
	g_return_val_if_fail (self != NULL, NULL);
	if (data == NULL) {
		result = NULL;
		return result;
	}
	i = string_index_of_char (data, (gunichar) '=', 0);
	_tmp0_ = i;
	if (_tmp0_ < 0) {
		result = NULL;
		return result;
	}
	_tmp1_ = i;
	_tmp2_ = string_substring (data, (glong) 0, (glong) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = string_strip (_tmp3_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	left = _tmp5_;
	_tmp6_ = i;
	_tmp7_ = string_substring (data, (glong) (_tmp6_ + 1), (glong) -1);
	_tmp8_ = _tmp7_;
	_tmp9_ = string_strip (_tmp8_);
	_tmp10_ = _tmp9_;
	_g_free0 (_tmp8_);
	right = _tmp10_;
	_tmp12_ = left;
	if (_tmp12_ == NULL) {
		_tmp11_ = TRUE;
	} else {
		const gchar* _tmp13_;
		_tmp13_ = right;
		_tmp11_ = _tmp13_ == NULL;
	}
	if (_tmp11_) {
		result = NULL;
		_g_free0 (right);
		_g_free0 (left);
		return result;
	}
	_tmp14_ = g_strdup ("");
	expression = _tmp14_;
	_tmp15_ = g_strdup ("");
	description = _tmp15_;
	_tmp16_ = right;
	i = string_index_of_char (_tmp16_, (gunichar) '@', 0);
	_tmp17_ = i;
	if (_tmp17_ < 0) {
		const gchar* _tmp18_;
		gchar* _tmp19_;
		_tmp18_ = right;
		_tmp19_ = g_strdup (_tmp18_);
		_g_free0 (expression);
		expression = _tmp19_;
	} else {
		const gchar* _tmp20_;
		gint _tmp21_;
		gchar* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		const gchar* _tmp25_;
		gint _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		gchar* _tmp29_;
		_tmp20_ = right;
		_tmp21_ = i;
		_tmp22_ = string_substring (_tmp20_, (glong) 0, (glong) _tmp21_);
		_tmp23_ = _tmp22_;
		_tmp24_ = string_strip (_tmp23_);
		_g_free0 (expression);
		expression = _tmp24_;
		_g_free0 (_tmp23_);
		_tmp25_ = right;
		_tmp26_ = i;
		_tmp27_ = string_substring (_tmp25_, (glong) (_tmp26_ + 1), (glong) -1);
		_tmp28_ = _tmp27_;
		_tmp29_ = string_strip (_tmp28_);
		_g_free0 (description);
		description = _tmp29_;
		_g_free0 (_tmp28_);
	}
	_tmp30_ = expression;
	if (_tmp30_ == NULL) {
		result = NULL;
		_g_free0 (description);
		_g_free0 (expression);
		_g_free0 (right);
		_g_free0 (left);
		return result;
	}
	_tmp31_ = left;
	i = string_index_of_char (_tmp31_, (gunichar) '(', 0);
	_tmp32_ = i;
	if (_tmp32_ < 0) {
		result = NULL;
		_g_free0 (description);
		_g_free0 (expression);
		_g_free0 (right);
		_g_free0 (left);
		return result;
	}
	_tmp33_ = left;
	_tmp34_ = i;
	_tmp35_ = string_substring (_tmp33_, (glong) 0, (glong) _tmp34_);
	_tmp36_ = _tmp35_;
	_tmp37_ = string_strip (_tmp36_);
	_tmp38_ = _tmp37_;
	_g_free0 (_tmp36_);
	name = _tmp38_;
	_tmp39_ = left;
	_tmp40_ = i;
	_tmp41_ = string_substring (_tmp39_, (glong) (_tmp40_ + 1), (glong) -1);
	_tmp42_ = _tmp41_;
	_tmp43_ = string_strip (_tmp42_);
	_tmp44_ = _tmp43_;
	_g_free0 (_tmp42_);
	argument_list = _tmp44_;
	_tmp46_ = name;
	if (_tmp46_ == NULL) {
		_tmp45_ = TRUE;
	} else {
		const gchar* _tmp47_;
		_tmp47_ = argument_list;
		_tmp45_ = _tmp47_ == NULL;
	}
	if (_tmp45_) {
		result = NULL;
		_g_free0 (argument_list);
		_g_free0 (name);
		_g_free0 (description);
		_g_free0 (expression);
		_g_free0 (right);
		_g_free0 (left);
		return result;
	}
	_tmp48_ = argument_list;
	_tmp49_ = string_replace (_tmp48_, ")", "");
	_g_free0 (argument_list);
	argument_list = _tmp49_;
	_tmp50_ = argument_list;
	_tmp52_ = _tmp51_ = g_strsplit_set (_tmp50_, ";", 0);
	arguments = _tmp52_;
	arguments_length1 = _vala_array_length (_tmp51_);
	_arguments_size_ = arguments_length1;
	_tmp53_ = name;
	_tmp54_ = arguments;
	_tmp54__length1 = arguments_length1;
	_tmp55_ = expression;
	_tmp56_ = description;
	_tmp57_ = math_function_new (_tmp53_, _tmp54_, _tmp54__length1, _tmp55_, _tmp56_);
	result = _tmp57_;
	arguments = (_vala_array_free (arguments, arguments_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (argument_list);
	_g_free0 (name);
	_g_free0 (description);
	_g_free0 (expression);
	_g_free0 (right);
	_g_free0 (left);
	return result;
}


static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  int str_array_length1)
{
	gchar* result = NULL;
	gboolean _tmp0_ = FALSE;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp20_;
		gint _tmp22_;
		gint _tmp23_;
		gsize _tmp24_;
		gint _tmp25_;
		gint _tmp26_;
		gint _tmp27_;
		const gchar* res = NULL;
		gsize _tmp28_;
		void* _tmp29_;
		void* ptr = NULL;
		const gchar* _tmp30_;
		const gchar* _tmp31_;
		void* _tmp32_;
		const gchar* _tmp45_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp12_ = 0;
				gint _tmp13_;
				const gchar* _tmp14_;
				gsize _tmp19_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					gint _tmp8_;
					_tmp8_ = i;
					_tmp7_ = _tmp8_ < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp9_ = FALSE;
					if (str_array_length1 == -1) {
						gint _tmp10_;
						const gchar* _tmp11_;
						_tmp10_ = i;
						_tmp11_ = str_array[_tmp10_];
						_tmp9_ = _tmp11_ != NULL;
					} else {
						_tmp9_ = FALSE;
					}
					_tmp6_ = _tmp9_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp13_ = i;
				_tmp14_ = str_array[_tmp13_];
				if (_tmp14_ != NULL) {
					gint _tmp15_;
					const gchar* _tmp16_;
					gint _tmp17_;
					gint _tmp18_;
					_tmp15_ = i;
					_tmp16_ = str_array[_tmp15_];
					_tmp17_ = strlen ((const gchar*) _tmp16_);
					_tmp18_ = _tmp17_;
					_tmp12_ = _tmp18_;
				} else {
					_tmp12_ = 0;
				}
				_tmp19_ = len;
				len = _tmp19_ + _tmp12_;
			}
		}
		_tmp20_ = i;
		if (_tmp20_ == 0) {
			gchar* _tmp21_;
			_tmp21_ = g_strdup ("");
			result = _tmp21_;
			return result;
		}
		_tmp22_ = i;
		str_array_length1 = _tmp22_;
		_tmp23_ = str_array_length1;
		_tmp24_ = len;
		_tmp25_ = strlen ((const gchar*) separator);
		_tmp26_ = _tmp25_;
		_tmp27_ = i;
		len = _tmp24_ + (_tmp26_ * (_tmp27_ - 1));
		_tmp28_ = len;
		_tmp29_ = g_malloc (_tmp28_);
		res = _tmp29_;
		_tmp30_ = res;
		_tmp31_ = str_array[0];
		_tmp32_ = g_stpcpy ((void*) _tmp30_, (const gchar*) _tmp31_);
		ptr = _tmp32_;
		{
			gboolean _tmp33_ = FALSE;
			i = 1;
			_tmp33_ = TRUE;
			while (TRUE) {
				gint _tmp35_;
				void* _tmp36_;
				void* _tmp37_;
				const gchar* _tmp38_ = NULL;
				gint _tmp39_;
				const gchar* _tmp40_;
				void* _tmp43_;
				void* _tmp44_;
				if (!_tmp33_) {
					gint _tmp34_;
					_tmp34_ = i;
					i = _tmp34_ + 1;
				}
				_tmp33_ = FALSE;
				_tmp35_ = i;
				if (!(_tmp35_ < str_array_length1)) {
					break;
				}
				_tmp36_ = ptr;
				_tmp37_ = g_stpcpy (_tmp36_, (const gchar*) separator);
				ptr = _tmp37_;
				_tmp39_ = i;
				_tmp40_ = str_array[_tmp39_];
				if (_tmp40_ != NULL) {
					gint _tmp41_;
					const gchar* _tmp42_;
					_tmp41_ = i;
					_tmp42_ = str_array[_tmp41_];
					_tmp38_ = (const gchar*) _tmp42_;
				} else {
					_tmp38_ = "";
				}
				_tmp43_ = ptr;
				_tmp44_ = g_stpcpy (_tmp43_, _tmp38_);
				ptr = _tmp44_;
			}
		}
		_tmp45_ = res;
		res = NULL;
		result = (gchar*) _tmp45_;
		return result;
	} else {
		gchar* _tmp46_;
		_tmp46_ = g_strdup ("");
		result = _tmp46_;
		return result;
	}
}


static void
function_manager_save (FunctionManager* self)
{
	gchar* data = NULL;
	gchar* _tmp0_;
	GHashTableIter iter = {0};
	GHashTable* _tmp1_;
	gchar* name = NULL;
	MathFunction* math_function = NULL;
	gchar* dir = NULL;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup ("");
	data = _tmp0_;
	_tmp1_ = self->priv->functions;
	g_hash_table_iter_init (&iter, _tmp1_);
	while (TRUE) {
		gconstpointer _tmp2_ = NULL;
		gconstpointer _tmp3_ = NULL;
		gboolean _tmp4_;
		gchar* _tmp5_;
		MathFunction* _tmp6_;
		MathFunction* _tmp7_;
		const gchar* _tmp8_;
		MathFunction* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		MathFunction* _tmp12_;
		gchar** _tmp13_;
		gint _tmp13__length1;
		gchar** _tmp14_;
		gint _tmp14__length1;
		gchar* _tmp15_;
		gchar* _tmp16_;
		MathFunction* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		MathFunction* _tmp20_;
		const gchar* _tmp21_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		gchar* _tmp25_;
		_tmp4_ = g_hash_table_iter_next (&iter, (gpointer*) (&_tmp2_), (gpointer*) (&_tmp3_));
		_g_free0 (name);
		_tmp5_ = g_strdup (_tmp2_);
		name = _tmp5_;
		_g_object_unref0 (math_function);
		_tmp6_ = _g_object_ref0 (_tmp3_);
		math_function = _tmp6_;
		if (!_tmp4_) {
			break;
		}
		_tmp7_ = math_function;
		if (!math_function_is_custom_function (_tmp7_)) {
			continue;
		}
		_tmp8_ = data;
		_tmp9_ = math_function;
		_tmp10_ = math_function_get_name (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = math_function;
		_tmp13_ = math_function_get_arguments (_tmp12_, &_tmp13__length1);
		_tmp14_ = _tmp13_;
		_tmp14__length1 = _tmp13__length1;
		_tmp15_ = _vala_g_strjoinv (";", _tmp14_, _tmp14__length1);
		_tmp16_ = _tmp15_;
		_tmp17_ = math_function;
		_tmp18_ = math_function_get_expression (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = math_function;
		_tmp21_ = math_function_get_description (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = g_strdup_printf ("%s(%s)=%s@%s\n", _tmp11_, _tmp16_, _tmp19_, _tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = g_strconcat (_tmp8_, _tmp24_, NULL);
		_g_free0 (data);
		data = _tmp25_;
		_g_free0 (_tmp24_);
		_g_free0 (_tmp16_);
	}
	_tmp26_ = self->priv->file_name;
	_tmp27_ = g_path_get_dirname (_tmp26_);
	dir = _tmp27_;
	g_mkdir_with_parents (dir, 0700);
	{
		const gchar* _tmp28_;
		const gchar* _tmp29_;
		_tmp28_ = self->priv->file_name;
		_tmp29_ = data;
		g_file_set_contents (_tmp28_, _tmp29_, (gssize) -1, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch5_g_file_error;
			}
			_g_free0 (dir);
			_g_object_unref0 (math_function);
			_g_free0 (name);
			_g_free0 (data);
			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;
		}
	}
	goto __finally5;
	__catch5_g_file_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
	}
	__finally5:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_free0 (dir);
		_g_object_unref0 (math_function);
		_g_free0 (name);
		_g_free0 (data);
		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;
	}
	_g_free0 (dir);
	_g_object_unref0 (math_function);
	_g_free0 (name);
	_g_free0 (data);
}


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**
function_manager_array_sort_string (FunctionManager* self,
                                    gchar** array,
                                    int array_length1,
                                    int* result_length1)
{
	gchar** result = NULL;
	gboolean swapped = FALSE;
	gint _tmp0_ = 0;
	const gchar* _tmp1_;
	gint j = 0;
	gchar* tmp = NULL;
	gchar** _tmp24_;
	gint _tmp24__length1;
	gchar** _tmp25_;
	gint _tmp25__length1;
	g_return_val_if_fail (self != NULL, NULL);
	swapped = TRUE;
	_tmp1_ = array[array_length1 - 1];
	if (_tmp1_ == NULL) {
		_tmp0_ = 1;
	} else {
		_tmp0_ = 0;
	}
	j = _tmp0_;
	while (TRUE) {
		gboolean _tmp2_;
		gint _tmp3_;
		_tmp2_ = swapped;
		if (!_tmp2_) {
			break;
		}
		swapped = FALSE;
		_tmp3_ = j;
		j = _tmp3_ + 1;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp4_ = FALSE;
				_tmp4_ = TRUE;
				while (TRUE) {
					gint _tmp6_;
					gint _tmp7_;
					gint _tmp8_;
					const gchar* _tmp9_;
					gint _tmp10_;
					const gchar* _tmp11_;
					if (!_tmp4_) {
						gint _tmp5_;
						_tmp5_ = i;
						i = _tmp5_ + 1;
					}
					_tmp4_ = FALSE;
					_tmp6_ = i;
					_tmp7_ = j;
					if (!(_tmp6_ < (array_length1 - _tmp7_))) {
						break;
					}
					_tmp8_ = i;
					_tmp9_ = array[_tmp8_];
					_tmp10_ = i;
					_tmp11_ = array[_tmp10_ + 1];
					if (g_strcmp0 (_tmp9_, _tmp11_) < 0) {
						gint _tmp12_;
						const gchar* _tmp13_;
						gchar* _tmp14_;
						gint _tmp15_;
						gint _tmp16_;
						const gchar* _tmp17_;
						gchar* _tmp18_;
						gchar* _tmp19_;
						gint _tmp20_;
						const gchar* _tmp21_;
						gchar* _tmp22_;
						gchar* _tmp23_;
						_tmp12_ = i;
						_tmp13_ = array[_tmp12_];
						_tmp14_ = g_strdup (_tmp13_);
						_g_free0 (tmp);
						tmp = _tmp14_;
						_tmp15_ = i;
						_tmp16_ = i;
						_tmp17_ = array[_tmp16_ + 1];
						_tmp18_ = g_strdup (_tmp17_);
						_g_free0 (array[_tmp15_]);
						array[_tmp15_] = _tmp18_;
						_tmp19_ = array[_tmp15_];
						_tmp20_ = i;
						_tmp21_ = tmp;
						_tmp22_ = g_strdup (_tmp21_);
						_g_free0 (array[_tmp20_ + 1]);
						array[_tmp20_ + 1] = _tmp22_;
						_tmp23_ = array[_tmp20_ + 1];
						swapped = TRUE;
					}
				}
			}
		}
	}
	_tmp24_ = (array != NULL) ? _vala_array_dup1 (array, array_length1) : ((gpointer) array);
	_tmp24__length1 = array_length1;
	_tmp25_ = _tmp24_;
	_tmp25__length1 = _tmp24__length1;
	if (result_length1) {
		*result_length1 = _tmp25__length1;
	}
	result = _tmp25_;
	_g_free0 (tmp);
	return result;
}


gchar**
function_manager_get_names (FunctionManager* self,
                            int* result_length1)
{
	gchar** result = NULL;
	gchar** names = NULL;
	GHashTable* _tmp0_;
	gchar** _tmp1_;
	gint names_length1;
	gint _names_size_;
	GHashTableIter iter = {0};
	GHashTable* _tmp2_;
	gint i = 0;
	gchar* name = NULL;
	MathFunction* definition = NULL;
	gchar** _tmp14_;
	gint _tmp14__length1;
	gint _tmp15_;
	gchar* _tmp16_;
	gchar** _tmp17_;
	gint _tmp17__length1;
	gint _tmp18_;
	gchar** _tmp19_;
	gchar** _tmp20_;
	gint _tmp20__length1;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->functions;
	_tmp1_ = g_new0 (gchar*, (g_hash_table_size (_tmp0_) + 1) + 1);
	names = _tmp1_;
	names_length1 = g_hash_table_size (_tmp0_) + 1;
	_names_size_ = names_length1;
	_tmp2_ = self->priv->functions;
	g_hash_table_iter_init (&iter, _tmp2_);
	i = 0;
	while (TRUE) {
		gconstpointer _tmp3_ = NULL;
		gconstpointer _tmp4_ = NULL;
		gboolean _tmp5_;
		gchar* _tmp6_;
		MathFunction* _tmp7_;
		gchar** _tmp8_;
		gint _tmp8__length1;
		gint _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		gint _tmp13_;
		_tmp5_ = g_hash_table_iter_next (&iter, (gpointer*) (&_tmp3_), (gpointer*) (&_tmp4_));
		_g_free0 (name);
		_tmp6_ = g_strdup (_tmp3_);
		name = _tmp6_;
		_g_object_unref0 (definition);
		_tmp7_ = _g_object_ref0 (_tmp4_);
		definition = _tmp7_;
		if (!_tmp5_) {
			break;
		}
		_tmp8_ = names;
		_tmp8__length1 = names_length1;
		_tmp9_ = i;
		_tmp10_ = name;
		_tmp11_ = g_strdup (_tmp10_);
		_g_free0 (_tmp8_[_tmp9_]);
		_tmp8_[_tmp9_] = _tmp11_;
		_tmp12_ = _tmp8_[_tmp9_];
		_tmp13_ = i;
		i = _tmp13_ + 1;
	}
	_tmp14_ = names;
	_tmp14__length1 = names_length1;
	_tmp15_ = i;
	_g_free0 (_tmp14_[_tmp15_]);
	_tmp14_[_tmp15_] = NULL;
	_tmp16_ = _tmp14_[_tmp15_];
	_tmp17_ = names;
	_tmp17__length1 = names_length1;
	_tmp19_ = function_manager_array_sort_string (self, _tmp17_, _tmp17__length1, &_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp20__length1 = _tmp18_;
	if (result_length1) {
		*result_length1 = _tmp20__length1;
	}
	result = _tmp20_;
	_g_object_unref0 (definition);
	_g_free0 (name);
	names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
	return result;
}


/**
      * Adds a function to the manager, unless the given name is already taken
      * by a predefined function.
      * @return If the function was successfully added.
      */
static gboolean
function_manager_add (FunctionManager* self,
                      MathFunction* new_function)
{
	gboolean result = FALSE;
	MathFunction* existing_function = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	MathFunction* _tmp2_;
	gboolean _tmp3_ = FALSE;
	MathFunction* _tmp4_;
	GHashTable* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	MathFunction* _tmp10_;
	MathFunction* _tmp11_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (new_function != NULL, FALSE);
	_tmp0_ = math_function_get_name (new_function);
	_tmp1_ = _tmp0_;
	_tmp2_ = function_manager_get (self, _tmp1_);
	existing_function = _tmp2_;
	_tmp4_ = existing_function;
	if (_tmp4_ != NULL) {
		MathFunction* _tmp5_;
		_tmp5_ = existing_function;
		_tmp3_ = !math_function_is_custom_function (_tmp5_);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		result = FALSE;
		_g_object_unref0 (existing_function);
		return result;
	}
	_tmp6_ = self->priv->functions;
	_tmp7_ = math_function_get_name (new_function);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_strdup (_tmp8_);
	_tmp10_ = _g_object_ref0 (new_function);
	g_hash_table_insert (_tmp6_, _tmp9_, _tmp10_);
	_tmp11_ = existing_function;
	if (_tmp11_ != NULL) {
		g_signal_emit (self, function_manager_signals[FUNCTION_MANAGER_FUNCTION_EDITED_SIGNAL], 0, new_function);
	} else {
		g_signal_emit (self, function_manager_signals[FUNCTION_MANAGER_FUNCTION_ADDED_SIGNAL], 0, new_function);
	}
	result = TRUE;
	_g_object_unref0 (existing_function);
	return result;
}


gboolean
function_manager_add_function_with_properties (FunctionManager* self,
                                               const gchar* name,
                                               const gchar* arguments,
                                               const gchar* description,
                                               Parser* root_parser)
{
	gboolean result = FALSE;
	gchar* function_string = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	MathFunction* new_function = NULL;
	const gchar* _tmp8_;
	MathFunction* _tmp9_;
	gboolean _tmp10_ = FALSE;
	MathFunction* _tmp11_;
	gboolean is_function_added = FALSE;
	MathFunction* _tmp13_;
	gboolean _tmp14_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	g_return_val_if_fail (arguments != NULL, FALSE);
	g_return_val_if_fail (description != NULL, FALSE);
	_tmp0_ = g_strconcat (name, "(", NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, arguments, NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, ")=", NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, description, NULL);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	function_string = _tmp7_;
	_tmp8_ = function_string;
	_tmp9_ = function_manager_parse_function_from_string (self, _tmp8_);
	new_function = _tmp9_;
	_tmp11_ = new_function;
	if (_tmp11_ == NULL) {
		_tmp10_ = TRUE;
	} else {
		MathFunction* _tmp12_;
		_tmp12_ = new_function;
		_tmp10_ = math_function_validate (_tmp12_, root_parser) == FALSE;
	}
	if (_tmp10_) {
		parser_set_error (root_parser, ERROR_CODE_INVALID, NULL, (guint) 0, (guint) 0);
		result = FALSE;
		_g_object_unref0 (new_function);
		_g_free0 (function_string);
		return result;
	}
	_tmp13_ = new_function;
	is_function_added = function_manager_add (self, _tmp13_);
	_tmp14_ = is_function_added;
	if (_tmp14_) {
		function_manager_save (self);
	}
	result = is_function_added;
	_g_object_unref0 (new_function);
	_g_free0 (function_string);
	return result;
}


MathFunction*
function_manager_get (FunctionManager* self,
                      const gchar* name)
{
	MathFunction* result = NULL;
	MathFunction* function = NULL;
	GHashTable* _tmp0_;
	gconstpointer _tmp1_;
	MathFunction* _tmp2_;
	MathFunction* _tmp3_;
	GHashTable* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gconstpointer _tmp7_;
	MathFunction* _tmp8_;
	MathFunction* _tmp9_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->priv->functions;
	_tmp1_ = g_hash_table_lookup (_tmp0_, name);
	_tmp2_ = _g_object_ref0 ((MathFunction*) _tmp1_);
	function = _tmp2_;
	_tmp3_ = function;
	if (_tmp3_ != NULL) {
		result = function;
		return result;
	}
	_tmp4_ = self->priv->functions;
	_tmp5_ = g_utf8_strdown (name, (gssize) -1);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_hash_table_lookup (_tmp4_, _tmp6_);
	_tmp8_ = _g_object_ref0 ((MathFunction*) _tmp7_);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp6_);
	result = _tmp9_;
	_g_object_unref0 (function);
	return result;
}


void
function_manager_delete (FunctionManager* self,
                         const gchar* name)
{
	MathFunction* function = NULL;
	MathFunction* _tmp0_;
	gboolean _tmp1_ = FALSE;
	MathFunction* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = function_manager_get (self, name);
	function = _tmp0_;
	_tmp2_ = function;
	if (_tmp2_ != NULL) {
		MathFunction* _tmp3_;
		_tmp3_ = function;
		_tmp1_ = math_function_is_custom_function (_tmp3_);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GHashTable* _tmp4_;
		MathFunction* _tmp5_;
		_tmp4_ = self->priv->functions;
		g_hash_table_remove (_tmp4_, name);
		function_manager_save (self);
		_tmp5_ = function;
		g_signal_emit (self, function_manager_signals[FUNCTION_MANAGER_FUNCTION_DELETED_SIGNAL], 0, _tmp5_);
	}
	_g_object_unref0 (function);
}


gboolean
function_manager_is_function_defined (FunctionManager* self,
                                      const gchar* name)
{
	gboolean result = FALSE;
	gchar* lower_name = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gboolean _tmp6_ = FALSE;
	GHashTable* _tmp7_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = g_utf8_strdown (name, (gssize) -1);
	lower_name = _tmp0_;
	_tmp2_ = lower_name;
	if (g_str_has_prefix (_tmp2_, "log")) {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = lower_name;
		_tmp4_ = string_substring (_tmp3_, (glong) 3, (glong) -1);
		_tmp5_ = _tmp4_;
		_tmp1_ = sub_atoi (_tmp5_) >= 0;
		_g_free0 (_tmp5_);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		result = TRUE;
		_g_free0 (lower_name);
		return result;
	}
	_tmp7_ = self->priv->functions;
	if (g_hash_table_contains (_tmp7_, name)) {
		_tmp6_ = TRUE;
	} else {
		GHashTable* _tmp8_;
		const gchar* _tmp9_;
		_tmp8_ = self->priv->functions;
		_tmp9_ = lower_name;
		_tmp6_ = g_hash_table_contains (_tmp8_, _tmp9_);
	}
	result = _tmp6_;
	_g_free0 (lower_name);
	return result;
}


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


static void
_vala_array_add3 (Number** * array,
                  int* length,
                  int* size,
                  Number* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (Number*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


Number*
function_manager_evaluate_function (FunctionManager* self,
                                    const gchar* name,
                                    Number** arguments,
                                    int arguments_length1,
                                    Parser* parser)
{
	Number* result = NULL;
	gchar* lower_name = NULL;
	gchar* _tmp0_;
	Number** args = NULL;
	Number** _tmp1_;
	gint _tmp1__length1;
	gint args_length1;
	gint _args_size_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	MathFunction* function = NULL;
	MathFunction* _tmp15_;
	MathFunction* _tmp16_;
	MathFunction* _tmp17_;
	Number** _tmp18_;
	gint _tmp18__length1;
	Number* _tmp19_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (parser != NULL, NULL);
	_tmp0_ = g_utf8_strdown (name, (gssize) -1);
	lower_name = _tmp0_;
	_tmp1_ = (arguments != NULL) ? _vala_array_dup2 (arguments, arguments_length1) : ((gpointer) arguments);
	_tmp1__length1 = arguments_length1;
	args = _tmp1_;
	args_length1 = _tmp1__length1;
	_args_size_ = args_length1;
	_tmp3_ = lower_name;
	if (g_str_has_prefix (_tmp3_, "log")) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = lower_name;
		_tmp5_ = string_substring (_tmp4_, (glong) 3, (glong) -1);
		_tmp6_ = _tmp5_;
		_tmp2_ = sub_atoi (_tmp6_) > 0;
		_g_free0 (_tmp6_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		Number* log_base = NULL;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		Number* _tmp10_;
		Number* _tmp11_;
		Number** _tmp12_;
		gint _tmp12__length1;
		Number* _tmp13_;
		Number* _tmp14_;
		_tmp7_ = lower_name;
		_tmp8_ = string_substring (_tmp7_, (glong) 3, (glong) -1);
		_tmp9_ = _tmp8_;
		_tmp10_ = number_new_integer ((gint64) sub_atoi (_tmp9_), (gint64) 0);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		log_base = _tmp11_;
		_tmp12_ = args;
		_tmp12__length1 = args_length1;
		_tmp13_ = log_base;
		_tmp14_ = _g_object_ref0 (_tmp13_);
		_vala_array_add3 (&args, &args_length1, &_args_size_, _tmp14_);
		name = "log";
		_g_object_unref0 (log_base);
	}
	_tmp15_ = function_manager_get (self, name);
	function = _tmp15_;
	_tmp16_ = function;
	if (_tmp16_ == NULL) {
		parser_set_error (parser, ERROR_CODE_UNKNOWN_FUNCTION, NULL, (guint) 0, (guint) 0);
		result = NULL;
		_g_object_unref0 (function);
		args = (_vala_array_free (args, args_length1, (GDestroyNotify) g_object_unref), NULL);
		_g_free0 (lower_name);
		return result;
	}
	_tmp17_ = function;
	_tmp18_ = args;
	_tmp18__length1 = args_length1;
	_tmp19_ = math_function_evaluate (_tmp17_, _tmp18_, _tmp18__length1, parser);
	result = _tmp19_;
	_g_object_unref0 (function);
	args = (_vala_array_free (args, args_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_free0 (lower_name);
	return result;
}


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


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


static MathFunction**
function_manager_array_sort_math_function (FunctionManager* self,
                                           MathFunction** array,
                                           int array_length1,
                                           int* result_length1)
{
	MathFunction** result = NULL;
	gboolean swapped = FALSE;
	gint _tmp2_ = 0;
	MathFunction* _tmp3_;
	gint j = 0;
	MathFunction* tmp = NULL;
	MathFunction** _tmp34_;
	gint _tmp34__length1;
	MathFunction** _tmp35_;
	gint _tmp35__length1;
	g_return_val_if_fail (self != NULL, NULL);
	if (array_length1 == 0) {
		MathFunction** _tmp0_;
		gint _tmp0__length1;
		MathFunction** _tmp1_;
		gint _tmp1__length1;
		_tmp0_ = (array != NULL) ? _vala_array_dup3 (array, array_length1) : ((gpointer) array);
		_tmp0__length1 = array_length1;
		_tmp1_ = _tmp0_;
		_tmp1__length1 = _tmp0__length1;
		if (result_length1) {
			*result_length1 = _tmp1__length1;
		}
		result = _tmp1_;
		return result;
	}
	swapped = TRUE;
	_tmp3_ = array[array_length1 - 1];
	if (_tmp3_ == NULL) {
		_tmp2_ = 1;
	} else {
		_tmp2_ = 0;
	}
	j = _tmp2_;
	while (TRUE) {
		gboolean _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		_tmp4_ = swapped;
		if (!_tmp4_) {
			break;
		}
		swapped = FALSE;
		_tmp5_ = j;
		j = _tmp5_ + 1;
		_tmp6_ = j;
		_tmp7_ = _tmp6_;
		_vala_assert ((0 <= _tmp7_) && (_tmp7_ <= array_length1), "0 <= j <= array.length");
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp8_ = FALSE;
				_tmp8_ = TRUE;
				while (TRUE) {
					gint _tmp10_;
					gint _tmp11_;
					gint _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					MathFunction* _tmp15_;
					const gchar* _tmp16_;
					const gchar* _tmp17_;
					gint _tmp18_;
					MathFunction* _tmp19_;
					const gchar* _tmp20_;
					const gchar* _tmp21_;
					if (!_tmp8_) {
						gint _tmp9_;
						_tmp9_ = i;
						i = _tmp9_ + 1;
					}
					_tmp8_ = FALSE;
					_tmp10_ = i;
					_tmp11_ = j;
					if (!(_tmp10_ < (array_length1 - _tmp11_))) {
						break;
					}
					_tmp12_ = i;
					_tmp13_ = _tmp12_ + 1;
					_vala_assert ((0 <= _tmp13_) && (_tmp13_ < array_length1), "0 <= (i+1) < array.length");
					_tmp14_ = i;
					_tmp15_ = array[_tmp14_];
					_tmp16_ = math_function_get_name (_tmp15_);
					_tmp17_ = _tmp16_;
					_tmp18_ = i;
					_tmp19_ = array[_tmp18_ + 1];
					_tmp20_ = math_function_get_name (_tmp19_);
					_tmp21_ = _tmp20_;
					if (g_strcmp0 (_tmp17_, _tmp21_) > 0) {
						gint _tmp22_;
						MathFunction* _tmp23_;
						MathFunction* _tmp24_;
						gint _tmp25_;
						gint _tmp26_;
						MathFunction* _tmp27_;
						MathFunction* _tmp28_;
						MathFunction* _tmp29_;
						gint _tmp30_;
						MathFunction* _tmp31_;
						MathFunction* _tmp32_;
						MathFunction* _tmp33_;
						_tmp22_ = i;
						_tmp23_ = array[_tmp22_];
						_tmp24_ = _g_object_ref0 (_tmp23_);
						_g_object_unref0 (tmp);
						tmp = _tmp24_;
						_tmp25_ = i;
						_tmp26_ = i;
						_tmp27_ = array[_tmp26_ + 1];
						_tmp28_ = _g_object_ref0 (_tmp27_);
						_g_object_unref0 (array[_tmp25_]);
						array[_tmp25_] = _tmp28_;
						_tmp29_ = array[_tmp25_];
						_tmp30_ = i;
						_tmp31_ = tmp;
						_tmp32_ = _g_object_ref0 (_tmp31_);
						_g_object_unref0 (array[_tmp30_ + 1]);
						array[_tmp30_ + 1] = _tmp32_;
						_tmp33_ = array[_tmp30_ + 1];
						swapped = TRUE;
					}
				}
			}
		}
	}
	_tmp34_ = (array != NULL) ? _vala_array_dup4 (array, array_length1) : ((gpointer) array);
	_tmp34__length1 = array_length1;
	_tmp35_ = _tmp34_;
	_tmp35__length1 = _tmp34__length1;
	if (result_length1) {
		*result_length1 = _tmp35__length1;
	}
	result = _tmp35_;
	_g_object_unref0 (tmp);
	return result;
}


static void
_vala_array_add4 (MathFunction** * array,
                  int* length,
                  int* size,
                  MathFunction* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (MathFunction*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


MathFunction**
function_manager_functions_eligible_for_autocompletion_for_text (FunctionManager* self,
                                                                 const gchar* display_text,
                                                                 int* result_length1)
{
	MathFunction** result = NULL;
	MathFunction** eligible_functions = NULL;
	MathFunction** _tmp0_;
	gint eligible_functions_length1;
	gint _eligible_functions_size_;
	gint _tmp1_;
	gint _tmp2_;
	gchar* display_text_case_insensitive = NULL;
	gchar* _tmp4_;
	GHashTableIter iter = {0};
	GHashTable* _tmp5_;
	gchar* function_name = NULL;
	MathFunction* function = NULL;
	MathFunction** _tmp18_;
	gint _tmp18__length1;
	gint _tmp19_;
	MathFunction** _tmp20_;
	MathFunction** _tmp21_;
	gint _tmp21__length1;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (display_text != NULL, NULL);
	_tmp0_ = g_new0 (MathFunction*, 0 + 1);
	eligible_functions = _tmp0_;
	eligible_functions_length1 = 0;
	_eligible_functions_size_ = eligible_functions_length1;
	_tmp1_ = strlen (display_text);
	_tmp2_ = _tmp1_;
	if (_tmp2_ <= 1) {
		MathFunction** _tmp3_;
		gint _tmp3__length1;
		_tmp3_ = eligible_functions;
		_tmp3__length1 = eligible_functions_length1;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		return result;
	}
	_tmp4_ = g_utf8_strdown (display_text, (gssize) -1);
	display_text_case_insensitive = _tmp4_;
	_tmp5_ = self->priv->functions;
	g_hash_table_iter_init (&iter, _tmp5_);
	while (TRUE) {
		gconstpointer _tmp6_ = NULL;
		gconstpointer _tmp7_ = NULL;
		gboolean _tmp8_;
		gchar* _tmp9_;
		MathFunction* _tmp10_;
		gchar* function_name_case_insensitive = NULL;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		_tmp8_ = g_hash_table_iter_next (&iter, (gpointer*) (&_tmp6_), (gpointer*) (&_tmp7_));
		_g_free0 (function_name);
		_tmp9_ = g_strdup (_tmp6_);
		function_name = _tmp9_;
		_g_object_unref0 (function);
		_tmp10_ = _g_object_ref0 (_tmp7_);
		function = _tmp10_;
		if (!_tmp8_) {
			break;
		}
		_tmp11_ = function_name;
		_tmp12_ = g_utf8_strdown (_tmp11_, (gssize) -1);
		function_name_case_insensitive = _tmp12_;
		_tmp13_ = function_name_case_insensitive;
		_tmp14_ = display_text_case_insensitive;
		if (g_str_has_prefix (_tmp13_, _tmp14_)) {
			MathFunction** _tmp15_;
			gint _tmp15__length1;
			MathFunction* _tmp16_;
			MathFunction* _tmp17_;
			_tmp15_ = eligible_functions;
			_tmp15__length1 = eligible_functions_length1;
			_tmp16_ = function;
			_tmp17_ = _g_object_ref0 (_tmp16_);
			_vala_array_add4 (&eligible_functions, &eligible_functions_length1, &_eligible_functions_size_, _tmp17_);
		}
		_g_free0 (function_name_case_insensitive);
	}
	_tmp18_ = eligible_functions;
	_tmp18__length1 = eligible_functions_length1;
	_tmp20_ = function_manager_array_sort_math_function (self, _tmp18_, _tmp18__length1, &_tmp19_);
	_tmp21_ = _tmp20_;
	_tmp21__length1 = _tmp19_;
	if (result_length1) {
		*result_length1 = _tmp21__length1;
	}
	result = _tmp21_;
	_g_object_unref0 (function);
	_g_free0 (function_name);
	_g_free0 (display_text_case_insensitive);
	eligible_functions = (_vala_array_free (eligible_functions, eligible_functions_length1, (GDestroyNotify) g_object_unref), NULL);
	return result;
}


static void
function_manager_class_init (FunctionManagerClass * klass)
{
	function_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FunctionManagerPrivate));
	G_OBJECT_CLASS (klass)->finalize = function_manager_finalize;
	function_manager_signals[FUNCTION_MANAGER_FUNCTION_ADDED_SIGNAL] = g_signal_new ("function-added", TYPE_FUNCTION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, TYPE_MATH_FUNCTION);
	function_manager_signals[FUNCTION_MANAGER_FUNCTION_EDITED_SIGNAL] = g_signal_new ("function-edited", TYPE_FUNCTION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, TYPE_MATH_FUNCTION);
	function_manager_signals[FUNCTION_MANAGER_FUNCTION_DELETED_SIGNAL] = g_signal_new ("function-deleted", TYPE_FUNCTION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, TYPE_MATH_FUNCTION);
}


static void
function_manager_instance_init (FunctionManager * self)
{
	self->priv = FUNCTION_MANAGER_GET_PRIVATE (self);
}


static void
function_manager_finalize (GObject * obj)
{
	FunctionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FUNCTION_MANAGER, FunctionManager);
	_g_free0 (self->priv->file_name);
	_g_hash_table_unref0 (self->priv->functions);
	_g_object_unref0 (self->priv->serializer);
	G_OBJECT_CLASS (function_manager_parent_class)->finalize (obj);
}


GType
function_manager_get_type (void)
{
	static volatile gsize function_manager_type_id__volatile = 0;
	if (g_once_init_enter (&function_manager_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FunctionManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) function_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FunctionManager), 0, (GInstanceInitFunc) function_manager_instance_init, NULL };
		GType function_manager_type_id;
		function_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "FunctionManager", &g_define_type_info, 0);
		g_once_init_leave (&function_manager_type_id__volatile, function_manager_type_id);
	}
	return function_manager_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;
}



