From f4239872c9cb56d1e5735b62ea53bedf3f39dfb0 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 4 Aug 2010 16:24:39 -0700 Subject: glcpp: Ignore #if and #elif expressions when skipping. Fixes glcpp test cases 073 and 074, as well as piglit test xonotic-vs-generic-diffuse.vert. --- src/glsl/glcpp/glcpp-parse.y | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/glsl/glcpp/glcpp-parse.y') diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index e19da432ee..df1a649d9b 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -215,7 +215,15 @@ control_line: talloc_free ($2); } | HASH_IF conditional_tokens NEWLINE { - _glcpp_parser_expand_if (parser, IF_EXPANDED, $2); + /* If we're skipping to the next #elif/#else case or to #endif, + * don't bother expanding or parsing the expression. + */ + if (parser->skip_stack != NULL && parser->skip_stack->type != SKIP_NO_SKIP) { + _glcpp_parser_skip_stack_push_if (parser, & @1, 0); + parser->skip_stack->type = SKIP_TO_ENDIF; + } else { + _glcpp_parser_expand_if (parser, IF_EXPANDED, $2); + } } | HASH_IFDEF IDENTIFIER junk NEWLINE { macro_t *macro = hash_table_find (parser->defines, $2); @@ -228,7 +236,13 @@ control_line: _glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL); } | HASH_ELIF conditional_tokens NEWLINE { - _glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2); + /* If we just finished a non-skipped #if/#ifdef/#ifndef block, + * don't bother expanding or parsing the expression. + */ + if (parser->skip_stack != NULL && parser->skip_stack->type == SKIP_NO_SKIP) + parser->skip_stack->type = SKIP_TO_ENDIF; + else + _glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2); } | HASH_ELIF NEWLINE { /* #elif without an expression results in a warning if the -- cgit v1.2.3