[gtk+/wip/otte/shader: 13/33] gsksltokenizer: Always return idents
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 13/33] gsksltokenizer: Always return idents
- Date: Wed, 27 Sep 2017 01:45:06 +0000 (UTC)
commit 221abdd06bb0945529cf5d036de7802e7032ae5a
Author: Benjamin Otte <otte redhat com>
Date: Sat Sep 23 15:08:50 2017 +0200
gsksltokenizer: Always return idents
Turning idents into keywords is the job of the preprocessor and has to
be done after processing #defines.
gsk/gskslpreprocessor.c | 7 +++++++
gsk/gsksltokenizer.c | 28 +++++++++++++++-------------
gsk/gsksltokenizerprivate.h | 3 +++
3 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/gsk/gskslpreprocessor.c b/gsk/gskslpreprocessor.c
index 9ed8fe4..fa3cc57 100644
--- a/gsk/gskslpreprocessor.c
+++ b/gsk/gskslpreprocessor.c
@@ -213,6 +213,13 @@ gsk_sl_preprocessor_ensure (GskSlPreprocessor *preproc)
break;
}
}
+
+ if (gsk_sl_token_is (&preproc->token, GSK_SL_TOKEN_IDENTIFIER))
+ {
+ char *ident = preproc->token.str;
+ gsk_sl_token_init_from_identifier (&preproc->token, ident);
+ g_free (ident);
+ }
}
const GskSlToken *
diff --git a/gsk/gsksltokenizer.c b/gsk/gsksltokenizer.c
index f734d97..5e056ae 100644
--- a/gsk/gsksltokenizer.c
+++ b/gsk/gsksltokenizer.c
@@ -1459,14 +1459,11 @@ gsk_sl_token_reader_read_number (GskSlTokenReader *reader,
return gsk_sl_token_reader_read_float_number (reader, token, error);
}
-static gboolean
+static void
gsk_sl_token_reader_read_identifier (GskSlTokenReader *reader,
- GskSlToken *token,
- GError **error)
+ GskSlToken *token)
{
GString *string;
- guint i;
- char *ident;
char c;
string = g_string_new ("");
@@ -1479,19 +1476,26 @@ gsk_sl_token_reader_read_identifier (GskSlTokenReader *reader,
gsk_sl_token_reader_consume (reader, 1);
}
- ident = g_string_free (string, FALSE);
+ gsk_sl_token_init (token, GSK_SL_TOKEN_IDENTIFIER);
+ token->str = g_string_free (string, FALSE);
+}
+void
+gsk_sl_token_init_from_identifier (GskSlToken *token,
+ const char *ident)
+{
+ guint i;
if (g_str_equal (ident, "true"))
{
gsk_sl_token_init (token, GSK_SL_TOKEN_BOOLCONSTANT);
token->b = TRUE;
- return TRUE;
+ return;
}
else if (g_str_equal (ident, "false"))
{
gsk_sl_token_init (token, GSK_SL_TOKEN_BOOLCONSTANT);
token->b = FALSE;
- return TRUE;
+ return;
}
for (i = 0; i < G_N_ELEMENTS (keywords); i++)
@@ -1502,14 +1506,12 @@ gsk_sl_token_reader_read_identifier (GskSlTokenReader *reader,
if (g_str_equal (ident, keywords[i]))
{
gsk_sl_token_init (token, i);
- return TRUE;
+ return;
}
}
gsk_sl_token_init (token, GSK_SL_TOKEN_IDENTIFIER);
- token->str = ident;
-
- return TRUE;
+ token->str = g_strdup (ident);
}
void
@@ -1824,7 +1826,7 @@ gsk_sl_tokenizer_read_token (GskSlTokenizer *tokenizer,
}
else if (is_identifier_start (c))
{
- gsk_sl_token_reader_read_identifier (&reader, token, &error);
+ gsk_sl_token_reader_read_identifier (&reader, token);
}
else
{
diff --git a/gsk/gsksltokenizerprivate.h b/gsk/gsksltokenizerprivate.h
index ec2fc92..f39e64f 100644
--- a/gsk/gsksltokenizerprivate.h
+++ b/gsk/gsksltokenizerprivate.h
@@ -266,6 +266,9 @@ struct _GskSlToken {
void gsk_sl_token_clear (GskSlToken *token);
+void gsk_sl_token_init_from_identifier (GskSlToken *token,
+ const char *ident);
+
gboolean gsk_sl_token_is_finite (const GskSlToken *token);
#define gsk_sl_token_is(token, _type) ((token)->type == (_type))
gboolean gsk_sl_token_is_ident (const GskSlToken *token,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]