[gtk+/wip/otte/shader: 66/226] gsksltokenizer: Always return idents
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 66/226] gsksltokenizer: Always return idents
- Date: Mon, 30 Oct 2017 02:06:04 +0000 (UTC)
commit d3511003cff6960f21cf5d01f7c993bd7db52586
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 c633a7f..d20985e 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 ca609f3..f4cc865 100644
--- a/gsk/gsksltokenizer.c
+++ b/gsk/gsksltokenizer.c
@@ -1463,14 +1463,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 ("");
@@ -1483,19 +1480,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++)
@@ -1506,14 +1510,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
@@ -1828,7 +1830,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]