glcpp: Fix support for nested #ifdef and nested #ifndef
Previously, if the outer #ifdef/#ifndef evaluated to false, the inner directive would not be parsed correctly, (the identifier as the subject of the #ifdef/#ifndef would inadvertently be skipped along with the other content correctly being skipped). We fix this by setting the lexing_if state in each case here. We also add a new test to the test suite to ensure that this case is tested.
This commit is contained in:
@@ -90,16 +90,18 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
|
||||
}
|
||||
|
||||
{HASH}ifdef/.*\n {
|
||||
yyextra->lexing_if = 1;
|
||||
yyextra->space_tokens = 0;
|
||||
return HASH_IFDEF;
|
||||
}
|
||||
|
||||
{HASH}ifndef/.*\n {
|
||||
yyextra->lexing_if = 1;
|
||||
yyextra->space_tokens = 0;
|
||||
return HASH_IFNDEF;
|
||||
}
|
||||
|
||||
{HASH}if{HSPACE}*/[^_a-zA-Z0-9].*\n {
|
||||
{HASH}if/[^_a-zA-Z0-9].*\n {
|
||||
yyextra->lexing_if = 1;
|
||||
yyextra->space_tokens = 0;
|
||||
return HASH_IF;
|
||||
@@ -122,7 +124,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
|
||||
}
|
||||
|
||||
/* When skipping (due to an #if 0 or similar) consume anything
|
||||
* up to a newline. We do this less priroty than any
|
||||
* up to a newline. We do this with less priority than any
|
||||
* #if-related directive (#if, #elif, #else, #endif), but with
|
||||
* more priority than any other directive or token to avoid
|
||||
* any side-effects from skipped content.
|
||||
|
40
src/glsl/glcpp/tests/067-nested-ifdef-ifndef.c
Normal file
40
src/glsl/glcpp/tests/067-nested-ifdef-ifndef.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#define D1
|
||||
#define D2
|
||||
|
||||
#define result success
|
||||
|
||||
#ifdef U1
|
||||
#ifdef U2
|
||||
#undef result
|
||||
#define result failure
|
||||
#endif
|
||||
#endif
|
||||
result
|
||||
|
||||
#ifndef D1
|
||||
#ifndef D2
|
||||
#undef result
|
||||
#define result failure
|
||||
#endif
|
||||
#endif
|
||||
result
|
||||
|
||||
#undef result
|
||||
#define result failure
|
||||
#ifdef D1
|
||||
#ifdef D2
|
||||
#undef result
|
||||
#define result success
|
||||
#endif
|
||||
#endif
|
||||
result
|
||||
|
||||
#undef result
|
||||
#define result failure
|
||||
#ifndef U1
|
||||
#ifndef U2
|
||||
#undef result
|
||||
#define result success
|
||||
#endif
|
||||
#endif
|
||||
result
|
41
src/glsl/glcpp/tests/067-nested-ifdef-ifndef.c.expected
Normal file
41
src/glsl/glcpp/tests/067-nested-ifdef-ifndef.c.expected
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
success
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
success
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
success
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
success
|
||||
|
Reference in New Issue
Block a user