summaryrefslogtreecommitdiffstats
path: root/src/glsl/glcpp/glcpp-parse.y
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2010-08-04 16:10:03 -0700
committerKenneth Graunke <[email protected]>2010-08-04 23:37:18 -0700
commit16b4eed59a07f5e07587f4f9b0cdc304a08a685c (patch)
treedc6ff6ffb5118b4b89e1b26c57d9a26726f96487 /src/glsl/glcpp/glcpp-parse.y
parent046bef235744e891e4a48076e1a3ff9a61a63092 (diff)
glcpp: Refactor HASH_IF and HASH_ELIF expansion to reuse code.
Diffstat (limited to 'src/glsl/glcpp/glcpp-parse.y')
-rw-r--r--src/glsl/glcpp/glcpp-parse.y39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 55a8d1761e6..e19da432eec 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -106,6 +106,9 @@ int
_active_list_contains (active_list_t *list, const char *identifier);
static void
+_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
+
+static void
_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
token_list_t *list);
@@ -212,16 +215,7 @@ control_line:
talloc_free ($2);
}
| HASH_IF conditional_tokens NEWLINE {
- token_list_t *expanded;
- token_t *token;
-
- expanded = _token_list_create (parser);
- token = _token_create_ival (parser, IF_EXPANDED, IF_EXPANDED);
- _token_list_append (expanded, token);
- talloc_unlink (parser, token);
- _glcpp_parser_expand_token_list (parser, $2);
- _token_list_append_list (expanded, $2);
- glcpp_parser_lex_from (parser, expanded);
+ _glcpp_parser_expand_if (parser, IF_EXPANDED, $2);
}
| HASH_IFDEF IDENTIFIER junk NEWLINE {
macro_t *macro = hash_table_find (parser->defines, $2);
@@ -234,16 +228,7 @@ control_line:
_glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL);
}
| HASH_ELIF conditional_tokens NEWLINE {
- token_list_t *expanded;
- token_t *token;
-
- expanded = _token_list_create (parser);
- token = _token_create_ival (parser, ELIF_EXPANDED, ELIF_EXPANDED);
- _token_list_append (expanded, token);
- talloc_unlink (parser, token);
- _glcpp_parser_expand_token_list (parser, $2);
- _token_list_append_list (expanded, $2);
- glcpp_parser_lex_from (parser, expanded);
+ _glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2);
}
| HASH_ELIF NEWLINE {
/* #elif without an expression results in a warning if the
@@ -1087,6 +1072,20 @@ _token_list_create_with_one_space (void *ctx)
return list;
}
+static void
+_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
+{
+ token_list_t *expanded;
+ token_t *token;
+
+ expanded = _token_list_create (parser);
+ token = _token_create_ival (parser, type, type);
+ _token_list_append (expanded, token);
+ _glcpp_parser_expand_token_list (parser, list);
+ _token_list_append_list (expanded, list);
+ glcpp_parser_lex_from (parser, expanded);
+}
+
/* This is a helper function that's essentially part of the
* implementation of _glcpp_parser_expand_node. It shouldn't be called
* except for by that function.