Basic work for a possible RPN-based parser which is

        (slightly) faster and (hopefully) clearer than the
        existing one; uses GScanner for tokenising; works
        on all themes tested, but doesn't use GError etc
        properly yet.
	* src/Makefile.am:
	* src/ui/theme-parser.c:
	* src/ui/theme.c:
	* src/ui/theme.h:


svn path=/branches/rpnparser/; revision=4108
parent ad168043
2009-02-02 Thomas Thurman <tthurman@gnome.org>
Basic work for a possible RPN-based parser which is
(slightly) faster and (hopefully) clearer than the
existing one; uses GScanner for tokenising; works
on all themes tested, but doesn't use GError etc
properly yet.
* src/Makefile.am:
* src/ui/theme-parser.c:
* src/ui/theme.c:
* src/ui/theme.h:
2009-02-01 Thomas Thurman <tthurman@gnome.org>
* configure.in: Post-release bump to 2.25.233.
......
......@@ -96,6 +96,8 @@ metacity_SOURCES= \
ui/theme.h \
ui/themewidget.c \
ui/themewidget.h \
ui/rpn.c \
ui/rpn.h \
ui/ui.c \
include/all-keybindings.h
......@@ -114,6 +116,8 @@ libmetacity_private_la_SOURCES= \
ui/preview-widget.h \
ui/theme-parser.c \
ui/theme-parser.h \
ui/rpn.c \
ui/rpn.h \
ui/theme.c \
ui/theme.h
......
......@@ -24,6 +24,7 @@
#include <config.h>
#include "theme-parser.h"
#include "util.h"
#include "rpn.h"
#include <string.h>
#include <stdlib.h>
......@@ -1656,10 +1657,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op->data.line.color_spec = color_spec;
op->data.line.x1 = meta_draw_spec_new (info->theme, x1, NULL);
op->data.line.y1 = meta_draw_spec_new (info->theme, y1, NULL);
op->data.line.x2 = meta_draw_spec_new (info->theme, x2, NULL);
op->data.line.y2 = meta_draw_spec_new (info->theme, y2, NULL);
op->data.line.x1 = meta_rpn_parse (info->theme, x1, NULL);
op->data.line.y1 = meta_rpn_parse (info->theme, y1, NULL);
op->data.line.x2 = meta_rpn_parse (info->theme, x2, NULL);
op->data.line.y2 = meta_rpn_parse (info->theme, y2, NULL);
op->data.line.width = width_val;
op->data.line.dash_on_length = dash_on_val;
......@@ -1723,10 +1724,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op = meta_draw_op_new (META_DRAW_RECTANGLE);
op->data.rectangle.color_spec = color_spec;
op->data.rectangle.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.rectangle.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.rectangle.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.rectangle.height = meta_draw_spec_new (info->theme,
op->data.rectangle.x = meta_rpn_parse (info->theme, x, NULL);
op->data.rectangle.y = meta_rpn_parse (info->theme, y, NULL);
op->data.rectangle.width = meta_rpn_parse (info->theme, width, NULL);
op->data.rectangle.height = meta_rpn_parse (info->theme,
height, NULL);
op->data.rectangle.filled = filled_val;
......@@ -1859,10 +1860,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op->data.arc.color_spec = color_spec;
op->data.arc.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.arc.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.arc.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.arc.height = meta_draw_spec_new (info->theme, height, NULL);
op->data.arc.x = meta_rpn_parse (info->theme, x, NULL);
op->data.arc.y = meta_rpn_parse (info->theme, y, NULL);
op->data.arc.width = meta_rpn_parse (info->theme, width, NULL);
op->data.arc.height = meta_rpn_parse (info->theme, height, NULL);
op->data.arc.filled = filled_val;
op->data.arc.start_angle = start_angle_val;
......@@ -1904,10 +1905,10 @@ parse_draw_op_element (GMarkupParseContext *context,
#endif
op = meta_draw_op_new (META_DRAW_CLIP);
op->data.clip.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.clip.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.clip.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.clip.height = meta_draw_spec_new (info->theme, height, NULL);
op->data.clip.x = meta_rpn_parse (info->theme, x, NULL);
op->data.clip.y = meta_rpn_parse (info->theme, y, NULL);
op->data.clip.width = meta_rpn_parse (info->theme, width, NULL);
op->data.clip.height = meta_rpn_parse (info->theme, height, NULL);
g_assert (info->op_list);
......@@ -1971,10 +1972,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op->data.tint.color_spec = color_spec;
op->data.tint.alpha_spec = alpha_spec;
op->data.tint.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.tint.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.tint.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.tint.height = meta_draw_spec_new (info->theme, height, NULL);
op->data.tint.x = meta_rpn_parse (info->theme, x, NULL);
op->data.tint.y = meta_rpn_parse (info->theme, y, NULL);
op->data.tint.width = meta_rpn_parse (info->theme, width, NULL);
op->data.tint.height = meta_rpn_parse (info->theme, height, NULL);
g_assert (info->op_list);
......@@ -2032,11 +2033,11 @@ parse_draw_op_element (GMarkupParseContext *context,
g_assert (info->op == NULL);
info->op = meta_draw_op_new (META_DRAW_GRADIENT);
info->op->data.gradient.x = meta_draw_spec_new (info->theme, x, NULL);
info->op->data.gradient.y = meta_draw_spec_new (info->theme, y, NULL);
info->op->data.gradient.width = meta_draw_spec_new (info->theme,
info->op->data.gradient.x = meta_rpn_parse (info->theme, x, NULL);
info->op->data.gradient.y = meta_rpn_parse (info->theme, y, NULL);
info->op->data.gradient.width = meta_rpn_parse (info->theme,
width, NULL);
info->op->data.gradient.height = meta_draw_spec_new (info->theme,
info->op->data.gradient.height = meta_rpn_parse (info->theme,
height, NULL);
info->op->data.gradient.gradient_spec = meta_gradient_spec_new (type_val);
......@@ -2141,10 +2142,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op->data.image.pixbuf = pixbuf;
op->data.image.colorize_spec = colorize_spec;
op->data.image.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.image.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.image.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.image.height = meta_draw_spec_new (info->theme, height, NULL);
op->data.image.x = meta_rpn_parse (info->theme, x, NULL);
op->data.image.y = meta_rpn_parse (info->theme, y, NULL);
op->data.image.width = meta_rpn_parse (info->theme, width, NULL);
op->data.image.height = meta_rpn_parse (info->theme, height, NULL);
op->data.image.alpha_spec = alpha_spec;
op->data.image.fill_type = fill_type_val;
......@@ -2292,10 +2293,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op = meta_draw_op_new (META_DRAW_GTK_ARROW);
op->data.gtk_arrow.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.gtk_arrow.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.gtk_arrow.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.gtk_arrow.height = meta_draw_spec_new (info->theme,
op->data.gtk_arrow.x = meta_rpn_parse (info->theme, x, NULL);
op->data.gtk_arrow.y = meta_rpn_parse (info->theme, y, NULL);
op->data.gtk_arrow.width = meta_rpn_parse (info->theme, width, NULL);
op->data.gtk_arrow.height = meta_rpn_parse (info->theme,
height, NULL);
op->data.gtk_arrow.filled = filled_val;
......@@ -2365,10 +2366,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op = meta_draw_op_new (META_DRAW_GTK_BOX);
op->data.gtk_box.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.gtk_box.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.gtk_box.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.gtk_box.height = meta_draw_spec_new (info->theme, height, NULL);
op->data.gtk_box.x = meta_rpn_parse (info->theme, x, NULL);
op->data.gtk_box.y = meta_rpn_parse (info->theme, y, NULL);
op->data.gtk_box.width = meta_rpn_parse (info->theme, width, NULL);
op->data.gtk_box.height = meta_rpn_parse (info->theme, height, NULL);
op->data.gtk_box.state = state_val;
op->data.gtk_box.shadow = shadow_val;
......@@ -2418,9 +2419,9 @@ parse_draw_op_element (GMarkupParseContext *context,
op = meta_draw_op_new (META_DRAW_GTK_VLINE);
op->data.gtk_vline.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.gtk_vline.y1 = meta_draw_spec_new (info->theme, y1, NULL);
op->data.gtk_vline.y2 = meta_draw_spec_new (info->theme, y2, NULL);
op->data.gtk_vline.x = meta_rpn_parse (info->theme, x, NULL);
op->data.gtk_vline.y1 = meta_rpn_parse (info->theme, y1, NULL);
op->data.gtk_vline.y2 = meta_rpn_parse (info->theme, y2, NULL);
op->data.gtk_vline.state = state_val;
......@@ -2484,10 +2485,10 @@ parse_draw_op_element (GMarkupParseContext *context,
op = meta_draw_op_new (META_DRAW_ICON);
op->data.icon.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.icon.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.icon.width = meta_draw_spec_new (info->theme, width, NULL);
op->data.icon.height = meta_draw_spec_new (info->theme, height, NULL);
op->data.icon.x = meta_rpn_parse (info->theme, x, NULL);
op->data.icon.y = meta_rpn_parse (info->theme, y, NULL);
op->data.icon.width = meta_rpn_parse (info->theme, width, NULL);
op->data.icon.height = meta_rpn_parse (info->theme, height, NULL);
op->data.icon.alpha_spec = alpha_spec;
op->data.icon.fill_type = fill_type_val;
......@@ -2535,8 +2536,8 @@ parse_draw_op_element (GMarkupParseContext *context,
op->data.title.color_spec = color_spec;
op->data.title.x = meta_draw_spec_new (info->theme, x, NULL);
op->data.title.y = meta_draw_spec_new (info->theme, y, NULL);
op->data.title.x = meta_rpn_parse (info->theme, x, NULL);
op->data.title.y = meta_rpn_parse (info->theme, y, NULL);
g_assert (info->op_list);
......@@ -2607,12 +2608,12 @@ parse_draw_op_element (GMarkupParseContext *context,
meta_draw_op_list_ref (op_list);
op->data.op_list.op_list = op_list;
op->data.op_list.x = meta_draw_spec_new (info->theme, x ? x : "0", NULL);
op->data.op_list.y = meta_draw_spec_new (info->theme, y ? y : "0", NULL);
op->data.op_list.width = meta_draw_spec_new (info->theme,
op->data.op_list.x = meta_rpn_parse (info->theme, x ? x : "0", NULL);
op->data.op_list.y = meta_rpn_parse (info->theme, y ? y : "0", NULL);
op->data.op_list.width = meta_rpn_parse (info->theme,
width ? width : "width",
NULL);
op->data.op_list.height = meta_draw_spec_new (info->theme,
op->data.op_list.height = meta_rpn_parse (info->theme,
height ? height : "height",
NULL);
......@@ -2702,22 +2703,22 @@ parse_draw_op_element (GMarkupParseContext *context,
meta_draw_op_list_ref (op_list);
op->data.tile.x = meta_draw_spec_new (info->theme, x ? x : "0", NULL);
op->data.tile.y = meta_draw_spec_new (info->theme, y ? y : "0", NULL);
op->data.tile.width = meta_draw_spec_new (info->theme,
op->data.tile.x = meta_rpn_parse (info->theme, x ? x : "0", NULL);
op->data.tile.y = meta_rpn_parse (info->theme, y ? y : "0", NULL);
op->data.tile.width = meta_rpn_parse (info->theme,
width ? width : "width",
NULL);
op->data.tile.height = meta_draw_spec_new (info->theme,
op->data.tile.height = meta_rpn_parse (info->theme,
height ? height : "height",
NULL);
op->data.tile.tile_xoffset = meta_draw_spec_new (info->theme,
op->data.tile.tile_xoffset = meta_rpn_parse (info->theme,
tile_xoffset ? tile_xoffset : "0",
NULL);
op->data.tile.tile_yoffset = meta_draw_spec_new (info->theme,
op->data.tile.tile_yoffset = meta_rpn_parse (info->theme,
tile_yoffset ? tile_yoffset : "0",
NULL);
op->data.tile.tile_width = meta_draw_spec_new (info->theme, tile_width, NULL);
op->data.tile.tile_height = meta_draw_spec_new (info->theme, tile_height, NULL);
op->data.tile.tile_width = meta_rpn_parse (info->theme, tile_width, NULL);
op->data.tile.tile_height = meta_rpn_parse (info->theme, tile_height, NULL);
op->data.tile.op_list = op_list;
......
This diff is collapsed.
......@@ -42,6 +42,7 @@ typedef struct _MetaFrameGeometry MetaFrameGeometry;
typedef struct _MetaTheme MetaTheme;
typedef struct _MetaPositionExprEnv MetaPositionExprEnv;
typedef struct _MetaDrawInfo MetaDrawInfo;
typedef enum MetaToken MetaToken;
#define META_THEME_ERROR (g_quark_from_static_string ("meta-theme-error"))
......@@ -330,87 +331,6 @@ typedef enum
META_DRAW_TILE
} MetaDrawType;
typedef enum
{
POS_TOKEN_INT,
POS_TOKEN_DOUBLE,
POS_TOKEN_OPERATOR,
POS_TOKEN_VARIABLE,
POS_TOKEN_OPEN_PAREN,
POS_TOKEN_CLOSE_PAREN
} PosTokenType;
typedef enum
{
POS_OP_NONE,
POS_OP_ADD,
POS_OP_SUBTRACT,
POS_OP_MULTIPLY,
POS_OP_DIVIDE,
POS_OP_MOD,
POS_OP_MAX,
POS_OP_MIN
} PosOperatorType;
/**
* A token, as output by the tokeniser.
*
* \ingroup tokenizer
*/
typedef struct
{
PosTokenType type;
union
{
struct {
int val;
} i;
struct {
double val;
} d;
struct {
PosOperatorType op;
} o;
struct {
char *name;
GQuark name_quark;
} v;
} d;
} PosToken;
/**
* A computed expression in our simple vector drawing language.
* While it appears to take the form of a tree, this is actually
* merely a list; concerns such as precedence of operators are
* currently recomputed on every recalculation.
*
* Created by meta_draw_spec_new(), destroyed by meta_draw_spec_free().
* pos_eval() fills this with ...FIXME. Are tokens a tree or a list?
* \ingroup parser
*/
typedef struct _MetaDrawSpec
{
/**
* If this spec is constant, this is the value of the constant;
* otherwise it is zero.
*/
int value;
/** A list of tokens in the expression. */
PosToken *tokens;
/** How many tokens are in the tokens list. */
int n_tokens;
/** Does the expression contain any variables? */
gboolean constant : 1;
} MetaDrawSpec;
/**
* A single drawing operation in our simple vector drawing language.
*/
......@@ -426,65 +346,65 @@ struct _MetaDrawOp
int dash_on_length;
int dash_off_length;
int width;
MetaDrawSpec *x1;
MetaDrawSpec *y1;
MetaDrawSpec *x2;
MetaDrawSpec *y2;
MetaToken *x1;
MetaToken *y1;
MetaToken *x2;
MetaToken *y2;
} line;
struct {
MetaColorSpec *color_spec;
gboolean filled;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} rectangle;
struct {
MetaColorSpec *color_spec;
gboolean filled;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
double start_angle;
double extent_angle;
} arc;
struct {
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} clip;
struct {
MetaColorSpec *color_spec;
MetaAlphaGradientSpec *alpha_spec;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} tint;
struct {
MetaGradientSpec *gradient_spec;
MetaAlphaGradientSpec *alpha_spec;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} gradient;
struct {
MetaColorSpec *colorize_spec;
MetaAlphaGradientSpec *alpha_spec;
GdkPixbuf *pixbuf;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
guint32 colorize_cache_pixel;
GdkPixbuf *colorize_cache_pixbuf;
......@@ -499,61 +419,61 @@ struct _MetaDrawOp
GtkArrowType arrow;
gboolean filled;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} gtk_arrow;
struct {
GtkStateType state;
GtkShadowType shadow;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} gtk_box;
struct {
GtkStateType state;
MetaDrawSpec *x;
MetaDrawSpec *y1;
MetaDrawSpec *y2;
MetaToken *x;
MetaToken *y1;
MetaToken *y2;
} gtk_vline;
struct {
MetaAlphaGradientSpec *alpha_spec;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
MetaImageFillType fill_type;
} icon;
struct {
MetaColorSpec *color_spec;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaToken *x;
MetaToken *y;
} title;
struct {
MetaDrawOpList *op_list;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
} op_list;
struct {
MetaDrawOpList *op_list;
MetaDrawSpec *x;
MetaDrawSpec *y;
MetaDrawSpec *width;
MetaDrawSpec *height;
MetaDrawSpec *tile_xoffset;
MetaDrawSpec *tile_yoffset;
MetaDrawSpec *tile_width;
MetaDrawSpec *tile_height;
MetaToken *x;
MetaToken *y;
MetaToken *width;
MetaToken *height;
MetaToken *tile_xoffset;
MetaToken *tile_yoffset;
MetaToken *tile_width;
MetaToken *tile_height;
} tile;
} data;
......@@ -865,20 +785,19 @@ void meta_frame_layout_calc_geometry (const MetaFrameLayout *layout
gboolean meta_frame_layout_validate (const MetaFrameLayout *layout,
GError **error);
gboolean meta_parse_position_expression (MetaDrawSpec *spec,
gboolean meta_parse_position_expression (MetaToken *spec,
const MetaPositionExprEnv *env,
int *x_return,
int *y_return,
GError **err);
gboolean meta_parse_size_expression (MetaDrawSpec *spec,
gboolean meta_parse_size_expression (MetaToken *spec,
const MetaPositionExprEnv *env,
int *val_return,
GError **err);
MetaDrawSpec* meta_draw_spec_new (MetaTheme *theme,
MetaToken* meta_draw_spec_new (MetaTheme *theme,
const char *expr,
GError **error);
void meta_draw_spec_free (MetaDrawSpec *spec);
MetaColorSpec* meta_color_spec_new (MetaColorSpecType type);
MetaColorSpec* meta_color_spec_new_from_string (const char *str,
......@@ -1128,10 +1047,12 @@ gboolean meta_theme_lookup_color_constant (MetaTheme *theme,
const char *name,
char **value);
#if 0
gboolean meta_theme_replace_constants (MetaTheme *theme,
PosToken *tokens,
int n_tokens,
GError **err);
#endif
/* random stuff */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment