diff options
author | Benjamin Otte <otte@redhat.com> | 2016-03-20 01:46:11 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-04-08 16:18:30 +0200 |
commit | 920a88512bc8809245b108ae6b75fcc72fcfeec9 (patch) | |
tree | b44948d06795de8c9c37982cbbd1110f3d92e367 | |
parent | fcf65bf8a4dc97297265cf9f3dfcc49ae7777f88 (diff) | |
download | gtk+-920a88512bc8809245b108ae6b75fcc72fcfeec9.tar.gz |
css: Move blocks handling to the token sources that need it
They need different ways of handling blocks, so they better do it
themselves instead of having a generic way that always gets it wrong.
-rw-r--r-- | gtk/gtkcssrule.c | 43 | ||||
-rw-r--r-- | gtk/gtkcsstokensource.c | 76 | ||||
-rw-r--r-- | gtk/gtkcsstokensourceprivate.h | 3 |
3 files changed, 59 insertions, 63 deletions
diff --git a/gtk/gtkcssrule.c b/gtk/gtkcssrule.c index 70ed6d8e0b..cffd975c3a 100644 --- a/gtk/gtkcssrule.c +++ b/gtk/gtkcssrule.c @@ -33,7 +33,7 @@ typedef struct _GtkCssTokenSourceAt GtkCssTokenSourceAt; struct _GtkCssTokenSourceAt { GtkCssTokenSource parent; GtkCssTokenSource *source; - guint inside_curly_block :1; + GSList *blocks; guint done :1; }; @@ -42,6 +42,8 @@ gtk_css_token_source_at_finalize (GtkCssTokenSource *source) { GtkCssTokenSourceAt *at = (GtkCssTokenSourceAt *) source; + g_slist_free (at->blocks); + gtk_css_token_source_unref (at->source); } @@ -55,20 +57,37 @@ gtk_css_token_source_at_consume_token (GtkCssTokenSource *source, if (at->done) return; - if (gtk_css_token_get_pending_block (source)) + token = gtk_css_token_source_peek_token (at->source); + switch (token->type) { - gtk_css_token_source_consume_token_as (at->source, consumer); - return; + case GTK_CSS_TOKEN_FUNCTION: + case GTK_CSS_TOKEN_OPEN_PARENS: + at->blocks = g_slist_prepend (at->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_PARENS)); + break; + case GTK_CSS_TOKEN_OPEN_SQUARE: + at->blocks = g_slist_prepend (at->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_SQUARE)); + break; + case GTK_CSS_TOKEN_OPEN_CURLY: + at->blocks = g_slist_prepend (at->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_CURLY)); + break; + case GTK_CSS_TOKEN_CLOSE_PARENS: + case GTK_CSS_TOKEN_CLOSE_SQUARE: + case GTK_CSS_TOKEN_CLOSE_CURLY: + if (at->blocks && GPOINTER_TO_UINT (at->blocks->data) == token->type) + { + at->blocks = g_slist_remove (at->blocks, at->blocks->data); + if (token->type == GTK_CSS_TOKEN_CLOSE_CURLY && at->blocks == NULL) + at->done = TRUE; + } + break; + case GTK_CSS_TOKEN_SEMICOLON: + if (at->blocks == NULL) + at->done = TRUE; + break; + default: + break; } - token = gtk_css_token_source_peek_token (at->source); - if (gtk_css_token_is (token, GTK_CSS_TOKEN_SEMICOLON)) - at->done = TRUE; - else if (at->inside_curly_block && gtk_css_token_is (token, GTK_CSS_TOKEN_CLOSE_CURLY)) - at->done = TRUE; - else if (gtk_css_token_is (token, GTK_CSS_TOKEN_OPEN_CURLY)) - at->inside_curly_block = TRUE; - gtk_css_token_source_consume_token_as (at->source, consumer); } diff --git a/gtk/gtkcsstokensource.c b/gtk/gtkcsstokensource.c index 9ed2675891..f1fadfe66d 100644 --- a/gtk/gtkcsstokensource.c +++ b/gtk/gtkcsstokensource.c @@ -126,6 +126,7 @@ struct _GtkCssTokenSourcePart { GtkCssTokenSource parent; GtkCssTokenSource *source; GtkCssTokenType end_type; + GSList *blocks; /* of GPOINTER_TO_UINT(GtkCssTokenType) */ }; static void @@ -134,6 +135,7 @@ gtk_css_token_source_part_finalize (GtkCssTokenSource *source) GtkCssTokenSourcePart *part = (GtkCssTokenSourcePart *) source; gtk_css_token_source_unref (part->source); + g_slist_free (part->blocks); } static void @@ -143,11 +145,32 @@ gtk_css_token_source_part_consume_token (GtkCssTokenSource *source, GtkCssTokenSourcePart *part = (GtkCssTokenSourcePart *) source; const GtkCssToken *token; - if (!gtk_css_token_get_pending_block (source)) + token = gtk_css_token_source_peek_token (part->source); + + if (part->blocks) + { + if (token->type == GPOINTER_TO_UINT (part->blocks->data)) + part->blocks = g_slist_remove (part->blocks, part->blocks->data); + } + else if (gtk_css_token_is (token, part->end_type)) { - token = gtk_css_token_source_peek_token (part->source); - if (gtk_css_token_is (token, part->end_type)) - return; + return; + } + + switch (token->type) + { + case GTK_CSS_TOKEN_FUNCTION: + case GTK_CSS_TOKEN_OPEN_PARENS: + part->blocks = g_slist_prepend (part->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_PARENS)); + break; + case GTK_CSS_TOKEN_OPEN_SQUARE: + part->blocks = g_slist_prepend (part->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_SQUARE)); + break; + case GTK_CSS_TOKEN_OPEN_CURLY: + part->blocks = g_slist_prepend (part->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_CURLY)); + break; + default: + break; } gtk_css_token_source_consume_token_as (part->source, consumer); @@ -161,7 +184,7 @@ gtk_css_token_source_part_peek_token (GtkCssTokenSource *source) const GtkCssToken *token; token = gtk_css_token_source_peek_token (part->source); - if (!gtk_css_token_get_pending_block (source) && + if (part->blocks == NULL && gtk_css_token_is (token, part->end_type)) return &eof_token; @@ -257,41 +280,7 @@ void gtk_css_token_source_consume_token_as (GtkCssTokenSource *source, GObject *consumer) { - const GtkCssToken *token; - - if (source->blocks) - { - token = gtk_css_token_source_peek_token (source); - if (gtk_css_token_is (token, GPOINTER_TO_UINT (source->blocks->data))) - source->blocks = g_slist_remove (source->blocks, source->blocks->data); - } - source->klass->consume_token (source, consumer); - - token = gtk_css_token_source_peek_token (source); - switch (token->type) - { - case GTK_CSS_TOKEN_FUNCTION: - case GTK_CSS_TOKEN_OPEN_PARENS: - source->blocks = g_slist_prepend (source->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_PARENS)); - break; - case GTK_CSS_TOKEN_OPEN_SQUARE: - source->blocks = g_slist_prepend (source->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_SQUARE)); - break; - case GTK_CSS_TOKEN_OPEN_CURLY: - source->blocks = g_slist_prepend (source->blocks, GUINT_TO_POINTER (GTK_CSS_TOKEN_CLOSE_CURLY)); - break; - default: - break; - } - - source->klass->consume_token (source, consumer); - - if (source->blocks) - { - if (token_type == GPOINTER_TO_UINT (source->blocks->data)) - source->blocks = g_slist_remove (source->blocks, source->blocks->data); - } } const GtkCssToken * @@ -521,15 +510,6 @@ gtk_css_token_source_consume_url (GtkCssTokenSource *source) } } -GtkCssTokenType -gtk_css_token_get_pending_block (GtkCssTokenSource *source) -{ - if (!source->blocks) - return GTK_CSS_TOKEN_EOF; - - return GPOINTER_TO_UINT(source->blocks->data); -} - void gtk_css_token_source_emit_error (GtkCssTokenSource *source, const GError *error) diff --git a/gtk/gtkcsstokensourceprivate.h b/gtk/gtkcsstokensourceprivate.h index 7b82762f4d..def15bcebd 100644 --- a/gtk/gtkcsstokensourceprivate.h +++ b/gtk/gtkcsstokensourceprivate.h @@ -33,7 +33,6 @@ struct _GtkCssTokenSource const GtkCssTokenSourceClass *klass; gint ref_count; GObject *consumer; - GSList *blocks; /* of GPOINTER_TO_UINT(GtkCssTokenType) */ }; struct _GtkCssTokenSourceClass @@ -65,8 +64,6 @@ void gtk_css_token_source_consume_token_as (GtkCssTokenSour const GtkCssToken * gtk_css_token_source_peek_token (GtkCssTokenSource *source); const GtkCssToken * gtk_css_token_source_get_token (GtkCssTokenSource *source); -GtkCssTokenType gtk_css_token_get_pending_block (GtkCssTokenSource *source); - void gtk_css_token_source_consume_all (GtkCssTokenSource *source); char * gtk_css_token_source_consume_to_string (GtkCssTokenSource *source); |