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

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <glib-object.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 GRAPHS_MATH_PARSER_TYPE_EVALUATOR (graphs_math_parser_evaluator_get_type ())
#define GRAPHS_MATH_PARSER_EVALUATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluator))
#define GRAPHS_MATH_PARSER_EVALUATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluatorClass))
#define GRAPHS_MATH_PARSER_IS_EVALUATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRAPHS_MATH_PARSER_TYPE_EVALUATOR))
#define GRAPHS_MATH_PARSER_IS_EVALUATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRAPHS_MATH_PARSER_TYPE_EVALUATOR))
#define GRAPHS_MATH_PARSER_EVALUATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRAPHS_MATH_PARSER_TYPE_EVALUATOR, GraphsMathParserEvaluatorClass))

typedef struct _GraphsMathParserEvaluator GraphsMathParserEvaluator;
typedef struct _GraphsMathParserEvaluatorClass GraphsMathParserEvaluatorClass;
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))

#define GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR (graphs_math_parser_preprocessor_get_type ())
#define GRAPHS_MATH_PARSER_PREPROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR, GraphsMathParserPreprocessor))
#define GRAPHS_MATH_PARSER_PREPROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR, GraphsMathParserPreprocessorClass))
#define GRAPHS_MATH_PARSER_IS_PREPROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR))
#define GRAPHS_MATH_PARSER_IS_PREPROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR))
#define GRAPHS_MATH_PARSER_PREPROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR, GraphsMathParserPreprocessorClass))

typedef struct _GraphsMathParserPreprocessor GraphsMathParserPreprocessor;
typedef struct _GraphsMathParserPreprocessorClass GraphsMathParserPreprocessorClass;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef enum  {
	GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_CARET,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_FACT,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_SUPERSCRIPT,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN,
	GRAPHS_MATH_PARSER_TOKEN_TYPE_END
} GraphsMathParserTokenType;

#define GRAPHS_MATH_PARSER_TYPE_TOKEN_TYPE (graphs_math_parser_token_type_get_type ())
typedef enum  {
	GRAPHS_MATH_PARSER_IDENT_PI,
	GRAPHS_MATH_PARSER_IDENT_E,
	GRAPHS_MATH_PARSER_IDENT_INF,
	GRAPHS_MATH_PARSER_IDENT_SIN,
	GRAPHS_MATH_PARSER_IDENT_COS,
	GRAPHS_MATH_PARSER_IDENT_TAN,
	GRAPHS_MATH_PARSER_IDENT_COT,
	GRAPHS_MATH_PARSER_IDENT_SEC,
	GRAPHS_MATH_PARSER_IDENT_CSC,
	GRAPHS_MATH_PARSER_IDENT_SIND,
	GRAPHS_MATH_PARSER_IDENT_COSD,
	GRAPHS_MATH_PARSER_IDENT_TAND,
	GRAPHS_MATH_PARSER_IDENT_COTD,
	GRAPHS_MATH_PARSER_IDENT_SECD,
	GRAPHS_MATH_PARSER_IDENT_CSCD,
	GRAPHS_MATH_PARSER_IDENT_ASIN,
	GRAPHS_MATH_PARSER_IDENT_ACOS,
	GRAPHS_MATH_PARSER_IDENT_ATAN,
	GRAPHS_MATH_PARSER_IDENT_ACOT,
	GRAPHS_MATH_PARSER_IDENT_ASEC,
	GRAPHS_MATH_PARSER_IDENT_ACSC,
	GRAPHS_MATH_PARSER_IDENT_ASIND,
	GRAPHS_MATH_PARSER_IDENT_ACOSD,
	GRAPHS_MATH_PARSER_IDENT_ATAND,
	GRAPHS_MATH_PARSER_IDENT_ACOTD,
	GRAPHS_MATH_PARSER_IDENT_ASECD,
	GRAPHS_MATH_PARSER_IDENT_ACSCD,
	GRAPHS_MATH_PARSER_IDENT_LOG,
	GRAPHS_MATH_PARSER_IDENT_LOG2,
	GRAPHS_MATH_PARSER_IDENT_LOG10,
	GRAPHS_MATH_PARSER_IDENT_SQRT,
	GRAPHS_MATH_PARSER_IDENT_EXP,
	GRAPHS_MATH_PARSER_IDENT_ABS,
	GRAPHS_MATH_PARSER_IDENT_CUSTOM
} GraphsMathParserIdent;

#define GRAPHS_MATH_PARSER_TYPE_IDENT (graphs_math_parser_ident_get_type ())

VALA_EXTERN gpointer graphs_math_parser_evaluator_ref (gpointer instance);
VALA_EXTERN void graphs_math_parser_evaluator_unref (gpointer instance);
VALA_EXTERN GParamSpec* graphs_math_parser_param_spec_evaluator (const gchar* name,
                                                     const gchar* nick,
                                                     const gchar* blurb,
                                                     GType object_type,
                                                     GParamFlags flags);
VALA_EXTERN void graphs_math_parser_value_set_evaluator (GValue* value,
                                             gpointer v_object);
VALA_EXTERN void graphs_math_parser_value_take_evaluator (GValue* value,
                                              gpointer v_object);
VALA_EXTERN gpointer graphs_math_parser_value_get_evaluator (const GValue* value);
VALA_EXTERN GType graphs_math_parser_evaluator_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GraphsMathParserEvaluator* graphs_math_parser_evaluator_instance (void);
VALA_EXTERN gdouble graphs_math_parser_evaluator_parse (GraphsMathParserEvaluator* self,
                                            const gchar* src,
                                            gunichar decimal_separator,
                                            GError** error);
static gdouble* _double_dup (gdouble* self);
VALA_EXTERN gpointer graphs_math_parser_preprocessor_ref (gpointer instance);
VALA_EXTERN void graphs_math_parser_preprocessor_unref (gpointer instance);
VALA_EXTERN GParamSpec* graphs_math_parser_param_spec_preprocessor (const gchar* name,
                                                        const gchar* nick,
                                                        const gchar* blurb,
                                                        GType object_type,
                                                        GParamFlags flags);
VALA_EXTERN void graphs_math_parser_value_set_preprocessor (GValue* value,
                                                gpointer v_object);
VALA_EXTERN void graphs_math_parser_value_take_preprocessor (GValue* value,
                                                 gpointer v_object);
VALA_EXTERN gpointer graphs_math_parser_value_get_preprocessor (const GValue* value);
VALA_EXTERN GType graphs_math_parser_preprocessor_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GraphsMathParserPreprocessor* graphs_math_parser_preprocessor_instance (void);
VALA_EXTERN gchar* graphs_math_parser_preprocessor_preprocess (GraphsMathParserPreprocessor* self,
                                                   const gchar* src,
                                                   gboolean prettify,
                                                   GError** error);
VALA_EXTERN GType graphs_math_parser_token_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType graphs_math_parser_ident_get_type (void) G_GNUC_CONST ;
VALA_EXTERN glong graphs_math_parser_factorial (gint n);
VALA_EXTERN gdouble graphs_math_parser_ipow (gdouble bas,
                                 gint exp);
VALA_EXTERN gboolean graphs_math_parser_is_superscript (gunichar c);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
     * Try evaluating a string to a double.
     * returns true if successfully parsed.
     */
static gdouble*
_double_dup (gdouble* self)
{
	gdouble* dup;
	dup = g_new0 (gdouble, 1);
	memcpy (dup, self, sizeof (gdouble));
	return dup;
}

static gpointer
__double_dup0 (gpointer self)
{
	return self ? _double_dup (self) : NULL;
}

gboolean
graphs_try_evaluate_string (const gchar* expression,
                            gdouble** _result_,
                            gunichar decimal_separator)
{
	gdouble* _vala__result_ = NULL;
	gboolean _tmp5_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (expression != NULL, FALSE);
	{
		gdouble _tmp0_ = 0.0;
		GraphsMathParserEvaluator* _tmp1_;
		gdouble* _tmp2_;
		_tmp1_ = graphs_math_parser_evaluator_instance ();
		_tmp0_ = graphs_math_parser_evaluator_parse (_tmp1_, expression, decimal_separator, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = __double_dup0 (&_tmp0_);
		_g_free0 (_vala__result_);
		_vala__result_ = _tmp2_;
		result = TRUE;
		if (_result_) {
			*_result_ = _vala__result_;
		} else {
			_g_free0 (_vala__result_);
		}
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		gdouble _tmp3_;
		gdouble* _tmp4_;
		g_clear_error (&_inner_error0_);
		_tmp3_ = (gdouble) 0;
		_tmp4_ = __double_dup0 (&_tmp3_);
		_g_free0 (_vala__result_);
		_vala__result_ = _tmp4_;
		result = FALSE;
		if (_result_) {
			*_result_ = _vala__result_;
		} else {
			_g_free0 (_vala__result_);
		}
		return result;
	}
	__finally0:
	_g_free0 (_vala__result_);
	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 _tmp5_;
}

/**
     * Evaluate a string to a double.
     */
gdouble
graphs_evaluate_string (const gchar* expression,
                        GError** error)
{
	gdouble _tmp0_ = 0.0;
	GraphsMathParserEvaluator* _tmp1_;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (expression != NULL, -1.0);
	_tmp1_ = graphs_math_parser_evaluator_instance ();
	_tmp0_ = graphs_math_parser_evaluator_parse (_tmp1_, expression, (gunichar) '.', &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp2_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp2_;
		} else {
			gdouble _tmp3_ = -1.0;
			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 _tmp3_;
		}
	}
	result = _tmp0_;
	return result;
}

/**
     * Evaluate a string to a double with given decimal separator.
     */
gdouble
graphs_evaluate_string_with_separator (const gchar* expression,
                                       gunichar separator,
                                       GError** error)
{
	gdouble _tmp0_ = 0.0;
	GraphsMathParserEvaluator* _tmp1_;
	GError* _inner_error0_ = NULL;
	gdouble result;
	g_return_val_if_fail (expression != NULL, -1.0);
	_tmp1_ = graphs_math_parser_evaluator_instance ();
	_tmp0_ = graphs_math_parser_evaluator_parse (_tmp1_, expression, separator, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			gdouble _tmp2_ = -1.0;
			g_propagate_error (error, _inner_error0_);
			return _tmp2_;
		} else {
			gdouble _tmp3_ = -1.0;
			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 _tmp3_;
		}
	}
	result = _tmp0_;
	return result;
}

/**
     * Preprocess an equation to be compatible with numexpr syntax.
     */
gchar*
graphs_preprocess_equation (const gchar* equation,
                            GError** error)
{
	gchar* _tmp0_ = NULL;
	GraphsMathParserPreprocessor* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (equation != NULL, NULL);
	_tmp1_ = graphs_math_parser_preprocessor_instance ();
	_tmp2_ = graphs_math_parser_preprocessor_preprocess (_tmp1_, equation, FALSE, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return NULL;
		} else {
			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;
		}
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_free0 (_tmp0_);
	return result;
}

/**
     * Return an equation in a prettier, more humanly readable, format.
     */
static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	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_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	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;
}

gchar*
graphs_prettify_equation (const gchar* equation,
                          GError** error)
{
	gchar* _result_ = NULL;
	GraphsMathParserPreprocessor* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (equation != NULL, NULL);
	_tmp0_ = graphs_math_parser_preprocessor_instance ();
	_tmp1_ = graphs_math_parser_preprocessor_preprocess (_tmp0_, equation, TRUE, &_inner_error0_);
	_result_ = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return NULL;
		} else {
			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;
		}
	}
	_tmp2_ = _result_;
	_tmp3_ = string_replace (_tmp2_, ")*(", "()");
	_g_free0 (_result_);
	_result_ = _tmp3_;
	result = _result_;
	return result;
}

GQuark
graphs_math_error_quark (void)
{
	return g_quark_from_static_string ("graphs-math-error-quark");
}

static GType
graphs_math_error_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_MATH_ERROR_SYNTAX, "GRAPHS_MATH_ERROR_SYNTAX", "syntax"}, {GRAPHS_MATH_ERROR_UNKNOWN_FUNCTION, "GRAPHS_MATH_ERROR_UNKNOWN_FUNCTION", "unknown-function"}, {GRAPHS_MATH_ERROR_DOMAIN, "GRAPHS_MATH_ERROR_DOMAIN", "domain"}, {GRAPHS_MATH_ERROR_DIV_ZERO, "GRAPHS_MATH_ERROR_DIV_ZERO", "div-zero"}, {0, NULL, NULL}};
	GType graphs_math_error_type_id;
	graphs_math_error_type_id = g_enum_register_static ("GraphsMathError", values);
	return graphs_math_error_type_id;
}

GType
graphs_math_error_get_type (void)
{
	static volatile gsize graphs_math_error_type_id__once = 0;
	if (g_once_init_enter (&graphs_math_error_type_id__once)) {
		GType graphs_math_error_type_id;
		graphs_math_error_type_id = graphs_math_error_get_type_once ();
		g_once_init_leave (&graphs_math_error_type_id__once, graphs_math_error_type_id);
	}
	return graphs_math_error_type_id__once;
}

static GType
graphs_math_parser_token_type_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER, "GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER", "number"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT, "GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT", "ident"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS, "GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS", "plus"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS, "GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS", "minus"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR, "GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR", "star"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH, "GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH", "slash"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_CARET, "GRAPHS_MATH_PARSER_TOKEN_TYPE_CARET", "caret"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_FACT, "GRAPHS_MATH_PARSER_TOKEN_TYPE_FACT", "fact"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_SUPERSCRIPT, "GRAPHS_MATH_PARSER_TOKEN_TYPE_SUPERSCRIPT", "superscript"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN, "GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN", "lparen"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN, "GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN", "rparen"}, {GRAPHS_MATH_PARSER_TOKEN_TYPE_END, "GRAPHS_MATH_PARSER_TOKEN_TYPE_END", "end"}, {0, NULL, NULL}};
	GType graphs_math_parser_token_type_type_id;
	graphs_math_parser_token_type_type_id = g_enum_register_static ("GraphsMathParserTokenType", values);
	return graphs_math_parser_token_type_type_id;
}

GType
graphs_math_parser_token_type_get_type (void)
{
	static volatile gsize graphs_math_parser_token_type_type_id__once = 0;
	if (g_once_init_enter (&graphs_math_parser_token_type_type_id__once)) {
		GType graphs_math_parser_token_type_type_id;
		graphs_math_parser_token_type_type_id = graphs_math_parser_token_type_get_type_once ();
		g_once_init_leave (&graphs_math_parser_token_type_type_id__once, graphs_math_parser_token_type_type_id);
	}
	return graphs_math_parser_token_type_type_id__once;
}

static GType
graphs_math_parser_ident_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_MATH_PARSER_IDENT_PI, "GRAPHS_MATH_PARSER_IDENT_PI", "pi"}, {GRAPHS_MATH_PARSER_IDENT_E, "GRAPHS_MATH_PARSER_IDENT_E", "e"}, {GRAPHS_MATH_PARSER_IDENT_INF, "GRAPHS_MATH_PARSER_IDENT_INF", "inf"}, {GRAPHS_MATH_PARSER_IDENT_SIN, "GRAPHS_MATH_PARSER_IDENT_SIN", "sin"}, {GRAPHS_MATH_PARSER_IDENT_COS, "GRAPHS_MATH_PARSER_IDENT_COS", "cos"}, {GRAPHS_MATH_PARSER_IDENT_TAN, "GRAPHS_MATH_PARSER_IDENT_TAN", "tan"}, {GRAPHS_MATH_PARSER_IDENT_COT, "GRAPHS_MATH_PARSER_IDENT_COT", "cot"}, {GRAPHS_MATH_PARSER_IDENT_SEC, "GRAPHS_MATH_PARSER_IDENT_SEC", "sec"}, {GRAPHS_MATH_PARSER_IDENT_CSC, "GRAPHS_MATH_PARSER_IDENT_CSC", "csc"}, {GRAPHS_MATH_PARSER_IDENT_SIND, "GRAPHS_MATH_PARSER_IDENT_SIND", "sind"}, {GRAPHS_MATH_PARSER_IDENT_COSD, "GRAPHS_MATH_PARSER_IDENT_COSD", "cosd"}, {GRAPHS_MATH_PARSER_IDENT_TAND, "GRAPHS_MATH_PARSER_IDENT_TAND", "tand"}, {GRAPHS_MATH_PARSER_IDENT_COTD, "GRAPHS_MATH_PARSER_IDENT_COTD", "cotd"}, {GRAPHS_MATH_PARSER_IDENT_SECD, "GRAPHS_MATH_PARSER_IDENT_SECD", "secd"}, {GRAPHS_MATH_PARSER_IDENT_CSCD, "GRAPHS_MATH_PARSER_IDENT_CSCD", "cscd"}, {GRAPHS_MATH_PARSER_IDENT_ASIN, "GRAPHS_MATH_PARSER_IDENT_ASIN", "asin"}, {GRAPHS_MATH_PARSER_IDENT_ACOS, "GRAPHS_MATH_PARSER_IDENT_ACOS", "acos"}, {GRAPHS_MATH_PARSER_IDENT_ATAN, "GRAPHS_MATH_PARSER_IDENT_ATAN", "atan"}, {GRAPHS_MATH_PARSER_IDENT_ACOT, "GRAPHS_MATH_PARSER_IDENT_ACOT", "acot"}, {GRAPHS_MATH_PARSER_IDENT_ASEC, "GRAPHS_MATH_PARSER_IDENT_ASEC", "asec"}, {GRAPHS_MATH_PARSER_IDENT_ACSC, "GRAPHS_MATH_PARSER_IDENT_ACSC", "acsc"}, {GRAPHS_MATH_PARSER_IDENT_ASIND, "GRAPHS_MATH_PARSER_IDENT_ASIND", "asind"}, {GRAPHS_MATH_PARSER_IDENT_ACOSD, "GRAPHS_MATH_PARSER_IDENT_ACOSD", "acosd"}, {GRAPHS_MATH_PARSER_IDENT_ATAND, "GRAPHS_MATH_PARSER_IDENT_ATAND", "atand"}, {GRAPHS_MATH_PARSER_IDENT_ACOTD, "GRAPHS_MATH_PARSER_IDENT_ACOTD", "acotd"}, {GRAPHS_MATH_PARSER_IDENT_ASECD, "GRAPHS_MATH_PARSER_IDENT_ASECD", "asecd"}, {GRAPHS_MATH_PARSER_IDENT_ACSCD, "GRAPHS_MATH_PARSER_IDENT_ACSCD", "acscd"}, {GRAPHS_MATH_PARSER_IDENT_LOG, "GRAPHS_MATH_PARSER_IDENT_LOG", "log"}, {GRAPHS_MATH_PARSER_IDENT_LOG2, "GRAPHS_MATH_PARSER_IDENT_LOG2", "log2"}, {GRAPHS_MATH_PARSER_IDENT_LOG10, "GRAPHS_MATH_PARSER_IDENT_LOG10", "log10"}, {GRAPHS_MATH_PARSER_IDENT_SQRT, "GRAPHS_MATH_PARSER_IDENT_SQRT", "sqrt"}, {GRAPHS_MATH_PARSER_IDENT_EXP, "GRAPHS_MATH_PARSER_IDENT_EXP", "exp"}, {GRAPHS_MATH_PARSER_IDENT_ABS, "GRAPHS_MATH_PARSER_IDENT_ABS", "abs"}, {GRAPHS_MATH_PARSER_IDENT_CUSTOM, "GRAPHS_MATH_PARSER_IDENT_CUSTOM", "custom"}, {0, NULL, NULL}};
	GType graphs_math_parser_ident_type_id;
	graphs_math_parser_ident_type_id = g_enum_register_static ("GraphsMathParserIdent", values);
	return graphs_math_parser_ident_type_id;
}

GType
graphs_math_parser_ident_get_type (void)
{
	static volatile gsize graphs_math_parser_ident_type_id__once = 0;
	if (g_once_init_enter (&graphs_math_parser_ident_type_id__once)) {
		GType graphs_math_parser_ident_type_id;
		graphs_math_parser_ident_type_id = graphs_math_parser_ident_get_type_once ();
		g_once_init_leave (&graphs_math_parser_ident_type_id__once, graphs_math_parser_ident_type_id);
	}
	return graphs_math_parser_ident_type_id__once;
}

inline glong
graphs_math_parser_factorial (gint n)
{
	glong r = 0L;
	glong result;
	r = (glong) 1;
	{
		gint i = 0;
		i = 2;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i <= n)) {
					break;
				}
				r *= (glong) i;
			}
		}
	}
	result = r;
	return result;
}

inline gdouble
graphs_math_parser_ipow (gdouble bas,
                         gint exp)
{
	gdouble _result_ = 0.0;
	gdouble b = 0.0;
	gint e = 0;
	gdouble result;
	_result_ = (gdouble) 1;
	b = bas;
	e = exp;
	while (TRUE) {
		if (!(e > 0)) {
			break;
		}
		if ((e & 1) == 1) {
			_result_ *= b;
		}
		b = b * b;
		e >>= 1;
	}
	result = _result_;
	return result;
}

inline gboolean
graphs_math_parser_is_superscript (gunichar c)
{
	gboolean result;
	switch (c) {
		case 8304U:
		case 185U:
		case 178U:
		case 179U:
		case 8308U:
		case 8309U:
		case 8310U:
		case 8311U:
		case 8312U:
		case 8313U:
		{
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

