glsl/glcpp: Fix glcpp to catch garbage after #if 1 ... #else
Previously, a line such as:
#else garbage
would flag an error if it followed "#if 0", but not if it followed "#if 1".
We fix this by setting a new bit of state (lexing_else) that allows the lexer
to defer switching to the <SKIP> start state until after the NEWLINE following
the #else directive.
A new test case is added for:
#if 1
#else garbage
#endif
which was untested before, (and did not generate the desired error).
This fixes the following Khronos GLES3 CTS tests:
tokens_after_else_vertex
tokens_after_else_fragment
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
This commit is contained in:
@@ -364,7 +364,7 @@ control_line:
|
||||
glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
|
||||
}
|
||||
}
|
||||
| HASH_ELSE {
|
||||
| HASH_ELSE { parser->lexing_directive = 1; } NEWLINE {
|
||||
if (parser->skip_stack &&
|
||||
parser->skip_stack->has_else)
|
||||
{
|
||||
@@ -376,7 +376,7 @@ control_line:
|
||||
if (parser->skip_stack)
|
||||
parser->skip_stack->has_else = true;
|
||||
}
|
||||
} NEWLINE
|
||||
}
|
||||
| HASH_ENDIF {
|
||||
_glcpp_parser_skip_stack_pop (parser, & @1);
|
||||
} NEWLINE
|
||||
@@ -1211,7 +1211,7 @@ glcpp_parser_create (const struct gl_extensions *extensions, gl_api api)
|
||||
parser->defines = hash_table_ctor (32, hash_table_string_hash,
|
||||
hash_table_string_compare);
|
||||
parser->active = NULL;
|
||||
parser->lexing_if = 0;
|
||||
parser->lexing_directive = 0;
|
||||
parser->space_tokens = 1;
|
||||
parser->newline_as_space = 0;
|
||||
parser->in_control_line = 0;
|
||||
|
||||
Reference in New Issue
Block a user