aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/glcpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-12-03 09:09:06 +0100
committermarha <marha@users.sourceforge.net>2012-12-03 09:09:06 +0100
commitb8da71ffb17d3d16706db04115e9ba1dd8bc49b9 (patch)
tree52bf0a78e9db0a4eff7b3dbb7c3a036c01504f6a /mesalib/src/glsl/glcpp
parentd2d73da59e64acdc4718e4e6790a69d967bee875 (diff)
downloadvcxsrv-b8da71ffb17d3d16706db04115e9ba1dd8bc49b9.tar.gz
vcxsrv-b8da71ffb17d3d16706db04115e9ba1dd8bc49b9.tar.bz2
vcxsrv-b8da71ffb17d3d16706db04115e9ba1dd8bc49b9.zip
fontconfig mesa xserver pixman xkeyboard-config git update 3 dec 2012
fontconfig: 2442d611579bccb84f0c29e3f9ceb0a7436df812 mesa: 54ff536823bf5a431efe1f2becdb21174c146948 xserver: b51a1bd2766e7dc975ca8f1cacc3f8bd0e1a68a3 pixman: 978bab253d1d061b00b5e80aa45ab6986aac466f xkeyboard-config: 05dcc6db64cd7425aea6d22efd6a3ecf34dbddd2
Diffstat (limited to 'mesalib/src/glsl/glcpp')
-rw-r--r--mesalib/src/glsl/glcpp/README4
-rw-r--r--mesalib/src/glsl/glcpp/glcpp-parse.y99
-rw-r--r--mesalib/src/glsl/glcpp/glcpp.c2
3 files changed, 82 insertions, 23 deletions
diff --git a/mesalib/src/glsl/glcpp/README b/mesalib/src/glsl/glcpp/README
index 0b5ef508c..0637935e2 100644
--- a/mesalib/src/glsl/glcpp/README
+++ b/mesalib/src/glsl/glcpp/README
@@ -20,13 +20,11 @@ to encounter and deal with the following preprocessor macros:
#pragma
#extension
-All other macros will be handles according to the GLSL specification
+All other macros will be handled according to the GLSL specification
and will not appear in the output.
Known limitations
-----------------
-The __LINE__ and __FILE__ macros are not yet supported.
-
A file that ends with a function-like macro name as the last
non-whitespace token will result in a parse error, (where it should be
passed through as is). \ No newline at end of file
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y
index b0537c3b0..e7daf7fea 100644
--- a/mesalib/src/glsl/glcpp/glcpp-parse.y
+++ b/mesalib/src/glsl/glcpp/glcpp-parse.y
@@ -1054,26 +1054,67 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
return combined;
}
- /* Two string-valued tokens can usually just be mashed
- * together.
+ /* Two string-valued (or integer) tokens can usually just be
+ * mashed together. (We also handle a string followed by an
+ * integer here as well.)
*
- * XXX: This isn't actually legitimate. Several things here
- * should result in a diagnostic since the result cannot be a
- * valid, single pre-processing token. For example, pasting
- * "123" and "abc" is not legal, but we don't catch that
- * here. */
- if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
- (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
+ * There are some exceptions here. Notably, if the first token
+ * is an integer (or a string representing an integer), then
+ * the second token must also be an integer or must be a
+ * string representing an integer that begins with a digit.
+ */
+ if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING || token->type == INTEGER) &&
+ (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING || other->type == INTEGER))
{
char *str;
+ int combined_type;
+
+ /* Check that pasting onto an integer doesn't create a
+ * non-integer, (that is, only digits can be
+ * pasted. */
+ if (token->type == INTEGER_STRING || token->type == INTEGER)
+ {
+ switch (other->type) {
+ case INTEGER_STRING:
+ if (other->value.str[0] < '0' ||
+ other->value.str[0] > '9')
+ goto FAIL;
+ break;
+ case INTEGER:
+ if (other->value.ival < 0)
+ goto FAIL;
+ break;
+ default:
+ goto FAIL;
+ }
+ }
- str = ralloc_asprintf (token, "%s%s", token->value.str,
- other->value.str);
- combined = _token_create_str (token, token->type, str);
+ if (token->type == INTEGER)
+ str = ralloc_asprintf (token, "%" PRIiMAX,
+ token->value.ival);
+ else
+ str = ralloc_strdup (token, token->value.str);
+
+
+ if (other->type == INTEGER)
+ ralloc_asprintf_append (&str, "%" PRIiMAX,
+ other->value.ival);
+ else
+ ralloc_strcat (&str, other->value.str);
+
+ /* New token is same type as original token, unless we
+ * started with an integer, in which case we will be
+ * creating an integer-string. */
+ combined_type = token->type;
+ if (combined_type == INTEGER)
+ combined_type = INTEGER_STRING;
+
+ combined = _token_create_str (token, combined_type, str);
combined->location = token->location;
return combined;
}
+ FAIL:
glcpp_error (&token->location, parser, "");
ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \"");
_token_print (&parser->info_log, &parser->info_log_length, token);
@@ -1300,18 +1341,30 @@ _arguments_parse (argument_list_t *arguments,
}
static token_list_t *
-_token_list_create_with_one_space (void *ctx)
+_token_list_create_with_one_ival (void *ctx, int type, int ival)
{
token_list_t *list;
- token_t *space;
+ token_t *node;
list = _token_list_create (ctx);
- space = _token_create_ival (list, SPACE, SPACE);
- _token_list_append (list, space);
+ node = _token_create_ival (list, type, ival);
+ _token_list_append (list, node);
return list;
}
+static token_list_t *
+_token_list_create_with_one_space (void *ctx)
+{
+ return _token_list_create_with_one_ival (ctx, SPACE, SPACE);
+}
+
+static token_list_t *
+_token_list_create_with_one_integer (void *ctx, int ival)
+{
+ return _token_list_create_with_one_ival (ctx, INTEGER, ival);
+}
+
/* Perform macro expansion on 'list', placing the resulting tokens
* into a new list which is initialized with a first token of type
* 'head_token_type'. Then begin lexing from the resulting list,
@@ -1528,8 +1581,18 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
return NULL;
}
- /* Look up this identifier in the hash table. */
+ *last = node;
identifier = token->value.str;
+
+ /* Special handling for __LINE__ and __FILE__, (not through
+ * the hash table). */
+ if (strcmp(identifier, "__LINE__") == 0)
+ return _token_list_create_with_one_integer (parser, node->token->location.first_line);
+
+ if (strcmp(identifier, "__FILE__") == 0)
+ return _token_list_create_with_one_integer (parser, node->token->location.source);
+
+ /* Look up this identifier in the hash table. */
macro = hash_table_find (parser->defines, identifier);
/* Not a macro, so no expansion needed. */
@@ -1550,14 +1613,12 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser,
final = _token_create_str (parser, OTHER, str);
expansion = _token_list_create (parser);
_token_list_append (expansion, final);
- *last = node;
return expansion;
}
if (! macro->is_function)
{
token_list_t *replacement;
- *last = node;
/* Replace a macro defined as empty with a SPACE token. */
if (macro->replacements == NULL)
diff --git a/mesalib/src/glsl/glcpp/glcpp.c b/mesalib/src/glsl/glcpp/glcpp.c
index 35db47087..7c2ded850 100644
--- a/mesalib/src/glsl/glcpp/glcpp.c
+++ b/mesalib/src/glsl/glcpp/glcpp.c
@@ -111,7 +111,7 @@ main (int argc, char *argv[])
if (shader == NULL)
return 1;
- ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, API_OPENGL);
+ ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, API_OPENGL_COMPAT);
printf("%s", shader);
fprintf(stderr, "%s", info_log);