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

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

#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "graphs.h"
#include <gobject/gvaluecollector.h>

#define GRAPHS_MATH_PARSER_PREPROCESSOR_PI_THRESH 0.00010000314159265359
#define GRAPHS_MATH_PARSER_PREPROCESSOR_E_THRESH 0.00010000271828182846
#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_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;
typedef struct _GraphsMathParserPreprocessorPrivate GraphsMathParserPreprocessorPrivate;

#define GRAPHS_MATH_PARSER_TYPE_LEXER (graphs_math_parser_lexer_get_type ())
#define GRAPHS_MATH_PARSER_LEXER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRAPHS_MATH_PARSER_TYPE_LEXER, GraphsMathParserLexer))
#define GRAPHS_MATH_PARSER_LEXER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRAPHS_MATH_PARSER_TYPE_LEXER, GraphsMathParserLexerClass))
#define GRAPHS_MATH_PARSER_IS_LEXER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRAPHS_MATH_PARSER_TYPE_LEXER))
#define GRAPHS_MATH_PARSER_IS_LEXER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRAPHS_MATH_PARSER_TYPE_LEXER))
#define GRAPHS_MATH_PARSER_LEXER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRAPHS_MATH_PARSER_TYPE_LEXER, GraphsMathParserLexerClass))

typedef struct _GraphsMathParserLexer GraphsMathParserLexer;
typedef struct _GraphsMathParserLexerClass GraphsMathParserLexerClass;
#define _graphs_math_parser_lexer_unref0(var) ((var == NULL) ? NULL : (var = (graphs_math_parser_lexer_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), 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 struct _GraphsMathParserLexerPrivate GraphsMathParserLexerPrivate;
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 ())
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
typedef struct _GraphsMathParserParamSpecPreprocessor GraphsMathParserParamSpecPreprocessor;

struct _GraphsMathParserPreprocessor {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GraphsMathParserPreprocessorPrivate * priv;
};

struct _GraphsMathParserPreprocessorClass {
	GTypeClass parent_class;
	void (*finalize) (GraphsMathParserPreprocessor *self);
};

struct _GraphsMathParserPreprocessorPrivate {
	GraphsMathParserLexer* lexer;
	GString* builder;
	gboolean prettify;
};

struct _GraphsMathParserLexer {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GraphsMathParserLexerPrivate * priv;
	GraphsMathParserTokenType current_type;
	GraphsMathParserIdent current_ident;
	gdouble current_val;
};

struct _GraphsMathParserLexerClass {
	GTypeClass parent_class;
	void (*finalize) (GraphsMathParserLexer *self);
};

struct _GraphsMathParserParamSpecPreprocessor {
	GParamSpec parent_instance;
};

static gint GraphsMathParserPreprocessor_private_offset;
static gpointer graphs_math_parser_preprocessor_parent_class = NULL;
static GOnce graphs_math_parser_preprocessor__instance;
static GOnce graphs_math_parser_preprocessor__instance = G_ONCE_INIT;

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 gpointer graphs_math_parser_lexer_ref (gpointer instance);
VALA_EXTERN void graphs_math_parser_lexer_unref (gpointer instance);
VALA_EXTERN GParamSpec* graphs_math_parser_param_spec_lexer (const gchar* name,
                                                 const gchar* nick,
                                                 const gchar* blurb,
                                                 GType object_type,
                                                 GParamFlags flags);
VALA_EXTERN void graphs_math_parser_value_set_lexer (GValue* value,
                                         gpointer v_object);
VALA_EXTERN void graphs_math_parser_value_take_lexer (GValue* value,
                                          gpointer v_object);
VALA_EXTERN gpointer graphs_math_parser_value_get_lexer (const GValue* value);
VALA_EXTERN GType graphs_math_parser_lexer_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GraphsMathParserLexer* graphs_math_parser_lexer_new (gboolean allow_custom_ident);
VALA_EXTERN GraphsMathParserLexer* graphs_math_parser_lexer_construct (GType object_type,
                                                           gboolean allow_custom_ident);
VALA_EXTERN GraphsMathParserPreprocessor* graphs_math_parser_preprocessor_instance (void);
static GraphsMathParserPreprocessor* __lambda11_ (void);
VALA_EXTERN GraphsMathParserPreprocessor* graphs_math_parser_preprocessor_new (void);
VALA_EXTERN GraphsMathParserPreprocessor* graphs_math_parser_preprocessor_construct (GType object_type);
static gpointer ___lambda11__gthread_func (gpointer self);
VALA_EXTERN gchar* graphs_math_parser_preprocessor_preprocess (GraphsMathParserPreprocessor* self,
                                                   const gchar* src,
                                                   gboolean prettify,
                                                   GError** error);
VALA_EXTERN void graphs_math_parser_lexer_start_lexing (GraphsMathParserLexer* self,
                                            const gchar* src,
                                            gunichar decimal_separator,
                                            GError** error);
static void graphs_math_parser_preprocessor_expr (GraphsMathParserPreprocessor* self,
                                           GError** error);
VALA_EXTERN void graphs_math_parser_lexer_expect_end (GraphsMathParserLexer* self,
                                          GError** error);
static void graphs_math_parser_preprocessor_term (GraphsMathParserPreprocessor* self,
                                           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 void graphs_math_parser_lexer_next (GraphsMathParserLexer* self,
                                    GError** error);
static void graphs_math_parser_preprocessor_power (GraphsMathParserPreprocessor* self,
                                            GError** error);
static void graphs_math_parser_preprocessor_unary (GraphsMathParserPreprocessor* self,
                                            GError** error);
static void graphs_math_parser_preprocessor_postfix (GraphsMathParserPreprocessor* self,
                                              GError** error);
static gdouble* graphs_math_parser_preprocessor_primary (GraphsMathParserPreprocessor* self,
                                                  GError** error);
static gboolean _double_equal (const gdouble * s1,
                        const gdouble * s2);
VALA_EXTERN glong graphs_math_parser_factorial (gint n);
static gdouble* _double_dup (gdouble* self);
VALA_EXTERN gdouble graphs_math_parser_ipow (gdouble bas,
                                 gint exp);
VALA_EXTERN gchar* graphs_math_parser_lexer_get_current_token_as_string (GraphsMathParserLexer* self);
VALA_EXTERN void graphs_math_parser_lexer_expect (GraphsMathParserLexer* self,
                                      GraphsMathParserTokenType t,
                                      GError** error);
static void graphs_math_parser_preprocessor_function_pre (GraphsMathParserPreprocessor* self,
                                                   GraphsMathParserIdent id);
static void graphs_math_parser_preprocessor_function_post (GraphsMathParserPreprocessor* self,
                                                    GraphsMathParserIdent id);
static void graphs_math_parser_preprocessor_finalize (GraphsMathParserPreprocessor * obj);
static GType graphs_math_parser_preprocessor_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
graphs_math_parser_preprocessor_get_instance_private (GraphsMathParserPreprocessor* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsMathParserPreprocessor_private_offset);
}

static GraphsMathParserPreprocessor*
__lambda11_ (void)
{
	GraphsMathParserPreprocessor* _tmp0_;
	GraphsMathParserPreprocessor* result;
	_tmp0_ = graphs_math_parser_preprocessor_new ();
	result = _tmp0_;
	return result;
}

static gpointer
___lambda11__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda11_ ();
	return result;
}

GraphsMathParserPreprocessor*
graphs_math_parser_preprocessor_instance (void)
{
	gconstpointer _tmp0_;
	GraphsMathParserPreprocessor* result;
	_tmp0_ = g_once (&graphs_math_parser_preprocessor__instance, ___lambda11__gthread_func, NULL);
	result = (GraphsMathParserPreprocessor*) _tmp0_;
	return result;
}

gchar*
graphs_math_parser_preprocessor_preprocess (GraphsMathParserPreprocessor* self,
                                            const gchar* src,
                                            gboolean prettify,
                                            GError** error)
{
	GString* _tmp0_;
	GraphsMathParserLexer* _tmp1_;
	GraphsMathParserLexer* _tmp2_;
	GString* _tmp3_;
	gchar* _tmp4_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (src != NULL, NULL);
	_tmp0_ = g_string_new ("");
	_g_string_free0 (self->priv->builder);
	self->priv->builder = _tmp0_;
	self->priv->prettify = prettify;
	_tmp1_ = self->priv->lexer;
	graphs_math_parser_lexer_start_lexing (_tmp1_, src, (gunichar) '.', &_inner_error0_);
	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;
		}
	}
	graphs_math_parser_preprocessor_expr (self, &_inner_error0_);
	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_ = self->priv->lexer;
	graphs_math_parser_lexer_expect_end (_tmp2_, &_inner_error0_);
	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_ = self->priv->builder;
	self->priv->builder = NULL;
	_tmp4_ = g_string_free_and_steal (_tmp3_);
	result = _tmp4_;
	return result;
}

static void
graphs_math_parser_preprocessor_expr (GraphsMathParserPreprocessor* self,
                                      GError** error)
{
	GraphsMathParserTokenType t = 0;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	graphs_math_parser_preprocessor_term (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} 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;
		}
	}
	while (TRUE) {
		GraphsMathParserLexer* _tmp0_;
		gboolean _tmp1_ = FALSE;
		gchar _tmp3_ = '\0';
		GString* _tmp4_;
		GraphsMathParserLexer* _tmp6_;
		_tmp0_ = self->priv->lexer;
		t = _tmp0_->current_type;
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS) {
			_tmp1_ = TRUE;
		} else {
			_tmp1_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS;
		}
		if (!_tmp1_) {
			break;
		}
		if (self->priv->prettify) {
			GString* _tmp2_;
			_tmp2_ = self->priv->builder;
			g_string_append_c (_tmp2_, ' ');
		}
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS) {
			_tmp3_ = '+';
		} else {
			_tmp3_ = '-';
		}
		_tmp4_ = self->priv->builder;
		g_string_append_c (_tmp4_, _tmp3_);
		if (self->priv->prettify) {
			GString* _tmp5_;
			_tmp5_ = self->priv->builder;
			g_string_append_c (_tmp5_, ' ');
		}
		_tmp6_ = self->priv->lexer;
		graphs_math_parser_lexer_next (_tmp6_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
		graphs_math_parser_preprocessor_term (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
	}
}

static void
graphs_math_parser_preprocessor_term (GraphsMathParserPreprocessor* self,
                                      GError** error)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	graphs_math_parser_preprocessor_power (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} 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;
		}
	}
	while (TRUE) {
		GraphsMathParserTokenType t = 0;
		GraphsMathParserLexer* _tmp0_;
		gboolean _tmp1_ = FALSE;
		gboolean _tmp7_ = FALSE;
		gboolean _tmp8_ = FALSE;
		_tmp0_ = self->priv->lexer;
		t = _tmp0_->current_type;
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR) {
			_tmp1_ = TRUE;
		} else {
			_tmp1_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_SLASH;
		}
		if (_tmp1_) {
			gchar _tmp3_ = '\0';
			GString* _tmp4_;
			GraphsMathParserLexer* _tmp6_;
			if (self->priv->prettify) {
				GString* _tmp2_;
				_tmp2_ = self->priv->builder;
				g_string_append_c (_tmp2_, ' ');
			}
			if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_STAR) {
				_tmp3_ = '*';
			} else {
				_tmp3_ = '/';
			}
			_tmp4_ = self->priv->builder;
			g_string_append_c (_tmp4_, _tmp3_);
			if (self->priv->prettify) {
				GString* _tmp5_;
				_tmp5_ = self->priv->builder;
				g_string_append_c (_tmp5_, ' ');
			}
			_tmp6_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp6_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					g_propagate_error (error, _inner_error0_);
					return;
				} 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;
				}
			}
			graphs_math_parser_preprocessor_power (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					g_propagate_error (error, _inner_error0_);
					return;
				} 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;
				}
			}
			continue;
		}
		if (t == GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER) {
			_tmp8_ = TRUE;
		} else {
			_tmp8_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT;
		}
		if (_tmp8_) {
			_tmp7_ = TRUE;
		} else {
			_tmp7_ = t == GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN;
		}
		if (_tmp7_) {
			if (!self->priv->prettify) {
				GString* _tmp9_;
				_tmp9_ = self->priv->builder;
				g_string_append_c (_tmp9_, '*');
			}
			graphs_math_parser_preprocessor_power (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					g_propagate_error (error, _inner_error0_);
					return;
				} 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;
				}
			}
			continue;
		}
		break;
	}
}

static void
graphs_math_parser_preprocessor_power (GraphsMathParserPreprocessor* self,
                                       GError** error)
{
	GraphsMathParserLexer* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	graphs_math_parser_preprocessor_unary (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} 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;
		}
	}
	_tmp0_ = self->priv->lexer;
	if (_tmp0_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_CARET) {
		const gchar* _tmp1_ = NULL;
		GString* _tmp2_;
		GraphsMathParserLexer* _tmp3_;
		if (self->priv->prettify) {
			_tmp1_ = "^";
		} else {
			_tmp1_ = "**";
		}
		_tmp2_ = self->priv->builder;
		g_string_append (_tmp2_, _tmp1_);
		_tmp3_ = self->priv->lexer;
		graphs_math_parser_lexer_next (_tmp3_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
		graphs_math_parser_preprocessor_power (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
	}
}

static void
graphs_math_parser_preprocessor_unary (GraphsMathParserPreprocessor* self,
                                       GError** error)
{
	GraphsMathParserLexer* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->lexer;
	if (_tmp0_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_MINUS) {
		GString* _tmp1_;
		GraphsMathParserLexer* _tmp2_;
		_tmp1_ = self->priv->builder;
		g_string_append_c (_tmp1_, '-');
		_tmp2_ = self->priv->lexer;
		graphs_math_parser_lexer_next (_tmp2_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
		graphs_math_parser_preprocessor_postfix (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				g_propagate_error (error, _inner_error0_);
				return;
			} 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;
			}
		}
		return;
	} else {
		GraphsMathParserLexer* _tmp3_;
		_tmp3_ = self->priv->lexer;
		if (_tmp3_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_PLUS) {
			GraphsMathParserLexer* _tmp4_;
			_tmp4_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp4_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					g_propagate_error (error, _inner_error0_);
					return;
				} 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;
				}
			}
		}
	}
	graphs_math_parser_preprocessor_postfix (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} 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;
		}
	}
}

static gboolean
_double_equal (const gdouble * s1,
               const gdouble * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	return (*s1) == (*s2);
}

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;
}

static void
graphs_math_parser_preprocessor_postfix (GraphsMathParserPreprocessor* self,
                                         GError** error)
{
	gdouble* v = NULL;
	gdouble* _tmp0_;
	gboolean output = FALSE;
	gboolean _tmp35_ = FALSE;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = graphs_math_parser_preprocessor_primary (self, &_inner_error0_);
	v = _tmp0_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} 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;
		}
	}
	output = FALSE;
	while (TRUE) {
		GraphsMathParserLexer* _tmp1_;
		GraphsMathParserLexer* _tmp18_;
		_tmp1_ = self->priv->lexer;
		if (_tmp1_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_FACT) {
			gdouble* _tmp2_;
			GraphsMathParserLexer* _tmp17_;
			_tmp2_ = v;
			if (_tmp2_ != NULL) {
				gboolean _tmp3_ = FALSE;
				gdouble* _tmp4_;
				gdouble* _tmp9_;
				gdouble _tmp10_;
				gdouble* _tmp11_;
				GString* _tmp12_;
				gdouble* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				_tmp4_ = v;
				if ((*_tmp4_) < ((gdouble) 0)) {
					_tmp3_ = TRUE;
				} else {
					gdouble* _tmp5_;
					gdouble* _tmp6_;
					gdouble _tmp7_;
					_tmp5_ = v;
					_tmp6_ = v;
					_tmp7_ = floor (*_tmp6_);
					_tmp3_ = _double_equal (_tmp5_, &_tmp7_) != TRUE;
				}
				if (_tmp3_) {
					GError* _tmp8_;
					_tmp8_ = g_error_new_literal (GRAPHS_MATH_ERROR, GRAPHS_MATH_ERROR_DOMAIN, "invalid factorial");
					_inner_error0_ = _tmp8_;
					if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
						g_propagate_error (error, _inner_error0_);
						_g_free0 (v);
						return;
					} else {
						_g_free0 (v);
						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;
					}
				}
				_tmp9_ = v;
				_tmp10_ = (gdouble) graphs_math_parser_factorial ((gint) (*_tmp9_));
				_tmp11_ = __double_dup0 (&_tmp10_);
				_g_free0 (v);
				v = _tmp11_;
				_tmp12_ = self->priv->builder;
				_tmp13_ = v;
				_tmp14_ = g_strdup_printf ("%.15g", *_tmp13_);
				_tmp15_ = _tmp14_;
				g_string_append (_tmp12_, _tmp15_);
				_g_free0 (_tmp15_);
			} else {
				GString* _tmp16_;
				_tmp16_ = self->priv->builder;
				g_string_append_c (_tmp16_, '!');
			}
			output = TRUE;
			_tmp17_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp17_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
					g_propagate_error (error, _inner_error0_);
					_g_free0 (v);
					return;
				} else {
					_g_free0 (v);
					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;
				}
			}
			continue;
		}
		_tmp18_ = self->priv->lexer;
		if (_tmp18_->current_type == GRAPHS_MATH_PARSER_TOKEN_TYPE_SUPERSCRIPT) {
			gint exp = 0;
			GraphsMathParserLexer* _tmp19_;
			gdouble* _tmp20_;
			_tmp19_ = self->priv->lexer;
			exp = (gint) _tmp19_->current_val;
			_tmp20_ = v;
			if (_tmp20_ != NULL) {
				GraphsMathParserLexer* _tmp21_;
				gdouble* _tmp22_;
				gdouble _tmp23_;
				gdouble* _tmp24_;
				GString* _tmp25_;
				gdouble* _tmp26_;
				gchar* _tmp27_;
				gchar* _tmp28_;
				_tmp21_ = self->priv->lexer;
				graphs_math_parser_lexer_next (_tmp21_, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
						g_propagate_error (error, _inner_error0_);
						_g_free0 (v);
						return;
					} else {
						_g_free0 (v);
						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;
					}
				}
				_tmp22_ = v;
				_tmp23_ = graphs_math_parser_ipow (*_tmp22_, exp);
				_tmp24_ = __double_dup0 (&_tmp23_);
				_g_free0 (v);
				v = _tmp24_;
				_tmp25_ = self->priv->builder;
				_tmp26_ = v;
				_tmp27_ = g_strdup_printf ("%.15g", *_tmp26_);
				_tmp28_ = _tmp27_;
				g_string_append (_tmp25_, _tmp28_);
				_g_free0 (_tmp28_);
			} else {
				const gchar* _tmp29_ = NULL;
				GString* _tmp30_;
				GString* _tmp31_;
				gchar* _tmp32_;
				gchar* _tmp33_;
				GraphsMathParserLexer* _tmp34_;
				if (self->priv->prettify) {
					_tmp29_ = "^";
				} else {
					_tmp29_ = "**";
				}
				_tmp30_ = self->priv->builder;
				g_string_append (_tmp30_, _tmp29_);
				_tmp31_ = self->priv->builder;
				_tmp32_ = g_strdup_printf ("%i", exp);
				_tmp33_ = _tmp32_;
				g_string_append (_tmp31_, _tmp33_);
				_g_free0 (_tmp33_);
				_tmp34_ = self->priv->lexer;
				graphs_math_parser_lexer_next (_tmp34_, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
						g_propagate_error (error, _inner_error0_);
						_g_free0 (v);
						return;
					} else {
						_g_free0 (v);
						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;
					}
				}
			}
			output = TRUE;
			continue;
		}
		break;
	}
	if (!output) {
		gdouble* _tmp36_;
		_tmp36_ = v;
		_tmp35_ = _tmp36_ != NULL;
	} else {
		_tmp35_ = FALSE;
	}
	if (_tmp35_) {
		GString* _tmp37_;
		gdouble* _tmp38_;
		gchar* _tmp39_;
		gchar* _tmp40_;
		_tmp37_ = self->priv->builder;
		_tmp38_ = v;
		_tmp39_ = g_strdup_printf ("%.15g", *_tmp38_);
		_tmp40_ = _tmp39_;
		g_string_append (_tmp37_, _tmp40_);
		_g_free0 (_tmp40_);
	}
	_g_free0 (v);
}

static gdouble*
graphs_math_parser_preprocessor_primary (GraphsMathParserPreprocessor* self,
                                         GError** error)
{
	GraphsMathParserLexer* _tmp0_;
	GError* _inner_error0_ = NULL;
	gdouble* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->lexer;
	switch (_tmp0_->current_type) {
		case GRAPHS_MATH_PARSER_TOKEN_TYPE_NUMBER:
		{
			gdouble v = 0.0;
			GraphsMathParserLexer* _tmp1_;
			GraphsMathParserLexer* _tmp14_;
			gdouble* _tmp15_;
			_tmp1_ = self->priv->lexer;
			v = _tmp1_->current_val;
			if (self->priv->prettify) {
				gdouble remainder = 0.0;
				gboolean _tmp2_ = FALSE;
				gboolean _tmp8_ = FALSE;
				remainder = fmod (v, G_PI);
				if (remainder <= GRAPHS_MATH_PARSER_PREPROCESSOR_PI_THRESH) {
					_tmp2_ = TRUE;
				} else {
					_tmp2_ = remainder >= (G_PI - GRAPHS_MATH_PARSER_PREPROCESSOR_PI_THRESH);
				}
				if (_tmp2_) {
					gdouble factor = 0.0;
					factor = floor ((v / G_PI) + 0.5);
					if (factor != ((gdouble) 0)) {
						GString* _tmp6_;
						GraphsMathParserLexer* _tmp7_;
						if (factor != ((gdouble) 1)) {
							GString* _tmp3_;
							gchar* _tmp4_;
							gchar* _tmp5_;
							_tmp3_ = self->priv->builder;
							_tmp4_ = g_strdup_printf ("%.15g", factor);
							_tmp5_ = _tmp4_;
							g_string_append (_tmp3_, _tmp5_);
							_g_free0 (_tmp5_);
						}
						_tmp6_ = self->priv->builder;
						g_string_append (_tmp6_, "pi");
						_tmp7_ = self->priv->lexer;
						graphs_math_parser_lexer_next (_tmp7_, &_inner_error0_);
						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;
							}
						}
						result = NULL;
						return result;
					}
				}
				remainder = fmod (v, G_E);
				if (remainder <= GRAPHS_MATH_PARSER_PREPROCESSOR_E_THRESH) {
					_tmp8_ = TRUE;
				} else {
					_tmp8_ = remainder >= (G_E - GRAPHS_MATH_PARSER_PREPROCESSOR_E_THRESH);
				}
				if (_tmp8_) {
					gdouble factor = 0.0;
					factor = floor ((v / G_E) + 0.5);
					if (factor != ((gdouble) 0)) {
						GString* _tmp12_;
						GraphsMathParserLexer* _tmp13_;
						if (factor != ((gdouble) 1)) {
							GString* _tmp9_;
							gchar* _tmp10_;
							gchar* _tmp11_;
							_tmp9_ = self->priv->builder;
							_tmp10_ = g_strdup_printf ("%.15g", factor);
							_tmp11_ = _tmp10_;
							g_string_append (_tmp9_, _tmp11_);
							_g_free0 (_tmp11_);
						}
						_tmp12_ = self->priv->builder;
						g_string_append_c (_tmp12_, 'e');
						_tmp13_ = self->priv->lexer;
						graphs_math_parser_lexer_next (_tmp13_, &_inner_error0_);
						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;
							}
						}
						result = NULL;
						return result;
					}
				}
			}
			_tmp14_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp14_, &_inner_error0_);
			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;
				}
			}
			_tmp15_ = __double_dup0 (&v);
			result = _tmp15_;
			return result;
		}
		case GRAPHS_MATH_PARSER_TOKEN_TYPE_IDENT:
		{
			GraphsMathParserIdent id = 0;
			GraphsMathParserLexer* _tmp16_;
			GraphsMathParserLexer* _tmp24_;
			GraphsMathParserLexer* _tmp31_;
			GraphsMathParserLexer* _tmp32_;
			_tmp16_ = self->priv->lexer;
			id = _tmp16_->current_ident;
			if (id == GRAPHS_MATH_PARSER_IDENT_CUSTOM) {
				GString* _tmp17_;
				GraphsMathParserLexer* _tmp18_;
				gchar* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				GraphsMathParserLexer* _tmp23_;
				_tmp17_ = self->priv->builder;
				_tmp18_ = self->priv->lexer;
				_tmp19_ = graphs_math_parser_lexer_get_current_token_as_string (_tmp18_);
				_tmp20_ = _tmp19_;
				_tmp21_ = g_utf8_strdown (_tmp20_, (gssize) -1);
				_tmp22_ = _tmp21_;
				g_string_append (_tmp17_, _tmp22_);
				_g_free0 (_tmp22_);
				_g_free0 (_tmp20_);
				_tmp23_ = self->priv->lexer;
				graphs_math_parser_lexer_next (_tmp23_, &_inner_error0_);
				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;
					}
				}
				result = NULL;
				return result;
			}
			_tmp24_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp24_, &_inner_error0_);
			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;
				}
			}
			switch (id) {
				case GRAPHS_MATH_PARSER_IDENT_PI:
				{
					gdouble _tmp25_;
					gdouble* _tmp26_;
					_tmp25_ = G_PI;
					_tmp26_ = __double_dup0 (&_tmp25_);
					result = _tmp26_;
					return result;
				}
				case GRAPHS_MATH_PARSER_IDENT_E:
				{
					gdouble _tmp27_;
					gdouble* _tmp28_;
					_tmp27_ = G_E;
					_tmp28_ = __double_dup0 (&_tmp27_);
					result = _tmp28_;
					return result;
				}
				case GRAPHS_MATH_PARSER_IDENT_INF:
				{
					gdouble _tmp29_;
					gdouble* _tmp30_;
					_tmp29_ = ((double) INFINITY);
					_tmp30_ = __double_dup0 (&_tmp29_);
					result = _tmp30_;
					return result;
				}
				default:
				{
					break;
				}
			}
			_tmp31_ = self->priv->lexer;
			graphs_math_parser_lexer_expect (_tmp31_, GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN, &_inner_error0_);
			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;
				}
			}
			graphs_math_parser_preprocessor_function_pre (self, id);
			graphs_math_parser_preprocessor_expr (self, &_inner_error0_);
			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;
				}
			}
			_tmp32_ = self->priv->lexer;
			graphs_math_parser_lexer_expect (_tmp32_, GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN, &_inner_error0_);
			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;
				}
			}
			graphs_math_parser_preprocessor_function_post (self, id);
			result = NULL;
			return result;
		}
		case GRAPHS_MATH_PARSER_TOKEN_TYPE_LPAREN:
		{
			GString* _tmp33_;
			GraphsMathParserLexer* _tmp34_;
			GraphsMathParserLexer* _tmp35_;
			GString* _tmp36_;
			_tmp33_ = self->priv->builder;
			g_string_append_c (_tmp33_, '(');
			_tmp34_ = self->priv->lexer;
			graphs_math_parser_lexer_next (_tmp34_, &_inner_error0_);
			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;
				}
			}
			graphs_math_parser_preprocessor_expr (self, &_inner_error0_);
			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;
				}
			}
			_tmp35_ = self->priv->lexer;
			graphs_math_parser_lexer_expect (_tmp35_, GRAPHS_MATH_PARSER_TOKEN_TYPE_RPAREN, &_inner_error0_);
			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;
				}
			}
			_tmp36_ = self->priv->builder;
			g_string_append_c (_tmp36_, ')');
			result = NULL;
			return result;
		}
		default:
		{
			GError* _tmp37_;
			_tmp37_ = g_error_new_literal (GRAPHS_MATH_ERROR, GRAPHS_MATH_ERROR_SYNTAX, "unexpected token");
			_inner_error0_ = _tmp37_;
			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;
			}
		}
	}
}

static void
graphs_math_parser_preprocessor_function_pre (GraphsMathParserPreprocessor* self,
                                              GraphsMathParserIdent id)
{
	g_return_if_fail (self != NULL);
	switch (id) {
		case GRAPHS_MATH_PARSER_IDENT_SIN:
		{
			GString* _tmp0_;
			_tmp0_ = self->priv->builder;
			g_string_append (_tmp0_, "sin(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_COS:
		{
			GString* _tmp1_;
			_tmp1_ = self->priv->builder;
			g_string_append (_tmp1_, "cos(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_TAN:
		{
			GString* _tmp2_;
			_tmp2_ = self->priv->builder;
			g_string_append (_tmp2_, "tan(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_COT:
		{
			GString* _tmp3_;
			_tmp3_ = self->priv->builder;
			g_string_append (_tmp3_, "1/tan(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_SEC:
		{
			GString* _tmp4_;
			_tmp4_ = self->priv->builder;
			g_string_append (_tmp4_, "1/cos(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_CSC:
		{
			GString* _tmp5_;
			_tmp5_ = self->priv->builder;
			g_string_append (_tmp5_, "1/sin(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_SIND:
		{
			GString* _tmp6_;
			_tmp6_ = self->priv->builder;
			g_string_append (_tmp6_, "sin(0.017453292519943295*(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_COSD:
		{
			GString* _tmp7_;
			_tmp7_ = self->priv->builder;
			g_string_append (_tmp7_, "cos(0.017453292519943295*(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_TAND:
		{
			GString* _tmp8_;
			_tmp8_ = self->priv->builder;
			g_string_append (_tmp8_, "tan(0.017453292519943295*(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_COTD:
		{
			GString* _tmp9_;
			_tmp9_ = self->priv->builder;
			g_string_append (_tmp9_, "1/tan(0.017453292519943295*(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_SECD:
		{
			GString* _tmp10_;
			_tmp10_ = self->priv->builder;
			g_string_append (_tmp10_, "1/cos(0.017453292519943295*(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_CSCD:
		{
			GString* _tmp11_;
			_tmp11_ = self->priv->builder;
			g_string_append (_tmp11_, "1/sin(0.017453292519943295*(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASIN:
		{
			GString* _tmp12_;
			_tmp12_ = self->priv->builder;
			g_string_append (_tmp12_, "arcsin(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOS:
		{
			GString* _tmp13_;
			_tmp13_ = self->priv->builder;
			g_string_append (_tmp13_, "arccos(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ATAN:
		{
			GString* _tmp14_;
			_tmp14_ = self->priv->builder;
			g_string_append (_tmp14_, "arctan(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOT:
		{
			GString* _tmp15_;
			_tmp15_ = self->priv->builder;
			g_string_append (_tmp15_, "arcsin(1/sqrt(1+");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASEC:
		{
			GString* _tmp16_;
			_tmp16_ = self->priv->builder;
			g_string_append (_tmp16_, "arccos(1/(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACSC:
		{
			GString* _tmp17_;
			_tmp17_ = self->priv->builder;
			g_string_append (_tmp17_, "arcsin(1/(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASIND:
		{
			GString* _tmp18_;
			_tmp18_ = self->priv->builder;
			g_string_append (_tmp18_, "57.29577951308232*arcsin(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOSD:
		{
			GString* _tmp19_;
			_tmp19_ = self->priv->builder;
			g_string_append (_tmp19_, "57.29577951308232*arccos(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ATAND:
		{
			GString* _tmp20_;
			_tmp20_ = self->priv->builder;
			g_string_append (_tmp20_, "57.29577951308232*arctan(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACOTD:
		{
			GString* _tmp21_;
			_tmp21_ = self->priv->builder;
			g_string_append (_tmp21_, "57.29577951308232*arcsin(1/sqrt(1+");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ASECD:
		{
			GString* _tmp22_;
			_tmp22_ = self->priv->builder;
			g_string_append (_tmp22_, "57.29577951308232*arccos(1/(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ACSCD:
		{
			GString* _tmp23_;
			_tmp23_ = self->priv->builder;
			g_string_append (_tmp23_, "57.29577951308232*arcsin(1/(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_LOG:
		{
			GString* _tmp24_;
			_tmp24_ = self->priv->builder;
			g_string_append (_tmp24_, "log(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_LOG2:
		{
			GString* _tmp25_;
			_tmp25_ = self->priv->builder;
			g_string_append (_tmp25_, "log2(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_LOG10:
		{
			GString* _tmp26_;
			_tmp26_ = self->priv->builder;
			g_string_append (_tmp26_, "log10(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_SQRT:
		{
			GString* _tmp27_;
			_tmp27_ = self->priv->builder;
			g_string_append (_tmp27_, "sqrt(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_EXP:
		{
			GString* _tmp28_;
			_tmp28_ = self->priv->builder;
			g_string_append (_tmp28_, "exp(");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_ABS:
		{
			GString* _tmp29_;
			_tmp29_ = self->priv->builder;
			g_string_append (_tmp29_, "abs(");
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static void
graphs_math_parser_preprocessor_function_post (GraphsMathParserPreprocessor* self,
                                               GraphsMathParserIdent id)
{
	g_return_if_fail (self != NULL);
	switch (id) {
		case GRAPHS_MATH_PARSER_IDENT_ACOT:
		case GRAPHS_MATH_PARSER_IDENT_ACOTD:
		{
			GString* _tmp0_;
			_tmp0_ = self->priv->builder;
			g_string_append (_tmp0_, "**2))");
			break;
		}
		case GRAPHS_MATH_PARSER_IDENT_SIND:
		case GRAPHS_MATH_PARSER_IDENT_COSD:
		case GRAPHS_MATH_PARSER_IDENT_TAND:
		case GRAPHS_MATH_PARSER_IDENT_COTD:
		case GRAPHS_MATH_PARSER_IDENT_SECD:
		case GRAPHS_MATH_PARSER_IDENT_CSCD:
		case GRAPHS_MATH_PARSER_IDENT_ASEC:
		case GRAPHS_MATH_PARSER_IDENT_ACSC:
		case GRAPHS_MATH_PARSER_IDENT_ASECD:
		case GRAPHS_MATH_PARSER_IDENT_ACSCD:
		{
			GString* _tmp1_;
			_tmp1_ = self->priv->builder;
			g_string_append (_tmp1_, "))");
			break;
		}
		default:
		{
			GString* _tmp2_;
			_tmp2_ = self->priv->builder;
			g_string_append_c (_tmp2_, ')');
			break;
		}
	}
}

GraphsMathParserPreprocessor*
graphs_math_parser_preprocessor_construct (GType object_type)
{
	GraphsMathParserPreprocessor* self = NULL;
	self = (GraphsMathParserPreprocessor*) g_type_create_instance (object_type);
	return self;
}

GraphsMathParserPreprocessor*
graphs_math_parser_preprocessor_new (void)
{
	return graphs_math_parser_preprocessor_construct (GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR);
}

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

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

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

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

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

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

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

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

void
graphs_math_parser_value_set_preprocessor (GValue* value,
                                           gpointer v_object)
{
	GraphsMathParserPreprocessor * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		graphs_math_parser_preprocessor_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		graphs_math_parser_preprocessor_unref (old);
	}
}

void
graphs_math_parser_value_take_preprocessor (GValue* value,
                                            gpointer v_object)
{
	GraphsMathParserPreprocessor * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		graphs_math_parser_preprocessor_unref (old);
	}
}

static void
graphs_math_parser_preprocessor_class_init (GraphsMathParserPreprocessorClass * klass,
                                            gpointer klass_data)
{
	graphs_math_parser_preprocessor_parent_class = g_type_class_peek_parent (klass);
	((GraphsMathParserPreprocessorClass *) klass)->finalize = graphs_math_parser_preprocessor_finalize;
	g_type_class_adjust_private_offset (klass, &GraphsMathParserPreprocessor_private_offset);
}

static void
graphs_math_parser_preprocessor_instance_init (GraphsMathParserPreprocessor * self,
                                               gpointer klass)
{
	GraphsMathParserLexer* _tmp0_;
	self->priv = graphs_math_parser_preprocessor_get_instance_private (self);
	_tmp0_ = graphs_math_parser_lexer_new (TRUE);
	self->priv->lexer = _tmp0_;
	self->ref_count = 1;
}

static void
graphs_math_parser_preprocessor_finalize (GraphsMathParserPreprocessor * obj)
{
	GraphsMathParserPreprocessor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_MATH_PARSER_TYPE_PREPROCESSOR, GraphsMathParserPreprocessor);
	g_signal_handlers_destroy (self);
	_graphs_math_parser_lexer_unref0 (self->priv->lexer);
	_g_string_free0 (self->priv->builder);
}

static GType
graphs_math_parser_preprocessor_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { graphs_math_parser_value_preprocessor_init, graphs_math_parser_value_preprocessor_free_value, graphs_math_parser_value_preprocessor_copy_value, graphs_math_parser_value_preprocessor_peek_pointer, "p", graphs_math_parser_value_preprocessor_collect_value, "p", graphs_math_parser_value_preprocessor_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GraphsMathParserPreprocessorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_math_parser_preprocessor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsMathParserPreprocessor), 0, (GInstanceInitFunc) graphs_math_parser_preprocessor_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType graphs_math_parser_preprocessor_type_id;
	graphs_math_parser_preprocessor_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GraphsMathParserPreprocessor", &g_define_type_info, &g_define_type_fundamental_info, 0);
	GraphsMathParserPreprocessor_private_offset = g_type_add_instance_private (graphs_math_parser_preprocessor_type_id, sizeof (GraphsMathParserPreprocessorPrivate));
	return graphs_math_parser_preprocessor_type_id;
}

GType
graphs_math_parser_preprocessor_get_type (void)
{
	static volatile gsize graphs_math_parser_preprocessor_type_id__once = 0;
	if (g_once_init_enter (&graphs_math_parser_preprocessor_type_id__once)) {
		GType graphs_math_parser_preprocessor_type_id;
		graphs_math_parser_preprocessor_type_id = graphs_math_parser_preprocessor_get_type_once ();
		g_once_init_leave (&graphs_math_parser_preprocessor_type_id__once, graphs_math_parser_preprocessor_type_id);
	}
	return graphs_math_parser_preprocessor_type_id__once;
}

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

void
graphs_math_parser_preprocessor_unref (gpointer instance)
{
	GraphsMathParserPreprocessor * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GRAPHS_MATH_PARSER_PREPROCESSOR_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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;
}

