Audacious $Id:Doxyfile42802007-03-2104:39:00Znenolod$
tuple_compiler.h
Go to the documentation of this file.
00001 /*
00002  * Audacious - Tuplez compiler
00003  * Copyright (c) 2007 Matti 'ccr' Hämäläinen
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; under version 3 of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses>.
00016  *
00017  * The Audacious team does not consider modular code linking to
00018  * Audacious or using our public API to be a derived work.
00019  */
00020 #ifndef AUDACIOUS_TUPLE_COMPILER_H
00021 #define AUDACIOUS_TUPLE_COMPILER_H
00022 
00023 #include <glib.h>
00024 #include <mowgli.h>
00025 #include "tuple.h"
00026 
00027 G_BEGIN_DECLS
00028 
00029 #define TUPLEZ_MAX_VARS (4)
00030 
00031 
00032 enum {
00033     OP_RAW = 0,         /* plain text */
00034     OP_FIELD,           /* a field/variable */
00035     OP_EXISTS,
00036     OP_DEF_STRING,
00037     OP_DEF_INT,
00038     OP_EQUALS,
00039     OP_NOT_EQUALS,
00040     OP_GT,
00041     OP_GTEQ,
00042     OP_LT,
00043     OP_LTEQ,
00044     OP_IS_EMPTY,
00045 
00046     OP_FUNCTION,        /* function */
00047     OP_EXPRESSION       /* additional registered expressions */
00048 };
00049 
00050 
00051 enum {
00052     TUPLE_VAR_FIELD = 0,
00053     TUPLE_VAR_CONST,
00054     TUPLE_VAR_DEF
00055 };
00056 
00057 
00058 /* Caching structure for deterministic functions
00059  */
00060 typedef struct {
00061     gchar *name;
00062     gboolean istemp;            /* Scope of variable - TRUE = temporary */
00063     gint type;                  /* Type of variable, see VAR_* */
00064     gchar *defvals;             /* Defined value ${=foo,bar} */
00065     gint defvali;
00066     TupleValueType ctype;       /* Type of constant/def value */
00067 
00068     gint fieldidx;              /* if >= 0: Index # of "pre-defined" Tuple fields */
00069     TupleValue *fieldref;       /* Cached tuple field ref */
00070 } TupleEvalVar;
00071 
00072 
00073 typedef struct {
00074     gchar *name;
00075     gboolean isdeterministic;
00076     gchar *(*func)(Tuple *tuple, TupleEvalVar **argument);
00077 } TupleEvalFunc;
00078 
00079 
00080 typedef struct _TupleEvalNode {
00081     gint opcode;                /* operator, see OP_ enums */
00082     gint var[TUPLEZ_MAX_VARS];  /* tuple / global variable references */
00083     gboolean global[TUPLEZ_MAX_VARS];
00084     gchar *text;                /* raw text, if any (OP_RAW) */
00085     gint function, expression;  /* for OP_FUNCTION and OP_EXPRESSION */
00086     struct _TupleEvalNode *children, *next, *prev; /* children of this struct, and pointer to next node. */
00087 } TupleEvalNode;
00088 
00089 
00090 typedef struct {
00091     gint nvariables, nfunctions, nexpressions;
00092     TupleEvalVar **variables;
00093     TupleEvalFunc **functions;
00094 
00095     /* Error context */
00096     gboolean iserror;
00097     gchar *errmsg;
00098 } TupleEvalContext;
00099 
00100 
00101 TupleEvalContext * tuple_evalctx_new(void);
00102 void tuple_evalctx_reset(TupleEvalContext *ctx);
00103 void tuple_evalctx_free(TupleEvalContext *ctx);
00104 gint tuple_evalctx_add_var(TupleEvalContext *ctx, const gchar *name, const gboolean istemp, const gint type, const TupleValueType ctype);
00105 
00106 void tuple_evalnode_free(TupleEvalNode *expr);
00107 
00108 gint tuple_formatter_print(FILE *f, gint *level, TupleEvalContext *ctx, TupleEvalNode *expr);
00109 TupleEvalNode *tuple_formatter_compile(TupleEvalContext *ctx, gchar *expr);
00110 gchar * tuple_formatter_eval (TupleEvalContext * ctx, TupleEvalNode * expr,
00111  const Tuple * tuple);
00112 
00113 
00114 G_END_DECLS
00115 
00116 #endif /* AUDACIOUS_TUPLE_COMPILER_H */