Hi Ian, The current GLSL preprocessor fails to parse expressions such as
#if 1 == 0 || defined UNDEFINED which is used by CINEBENCH r11. The problem is the parser->space_tokens = 1; statement conditional_tokens stanza -- it causes space tokens to be emitted halfway before reaching the DEFINED token. The attached patch is a quick bandaid to this problem, but I suspect that other space-related issues may subsist. I don't quite understand space_tokens' role here, or how it is supposed to work. I confess I'm not very familiar with bison/flex inner-workings: I though that the tokenizer was producing tokens quite ahead of the parser, so the parser couldn't change the behavior of the tokenizer in flight -- but perhaps I'm mixing up with other lexel/grammar generation tools. Also attached is an extended version of the defined-01.vert piglit glslparsertest test which covers more variations. Jose
// [config] // expect_result: pass // glsl_version: 110 // [end config] #define DEF 1 #undef UNDEF #if defined DEF #else #error Wrong #endif #if defined UNDEF #error Wrong #else #endif #if 1 == 0 || defined DEF #else #error Wrong #endif #if 1 == 0 || defined UNDEF #error Wrong #else #endif #if defined(DEF) #else #error Wrong #endif #if defined(UNDEF) #error Wrong #else #endif #if 1 == 0 || defined(DEF) #else #error Wrong #endif #if 1 == 0 || defined(UNDEF) #error Wrong #else #endif void main() { gl_Position = gl_Vertex; }
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index 8475e08..3b84c06 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -462,6 +462,10 @@ conditional_token: int v = hash_table_find (parser->defines, $2) ? 1 : 0; $$ = _token_create_ival (parser, INTEGER, v); } +| DEFINED SPACE IDENTIFIER { + int v = hash_table_find (parser->defines, $3) ? 1 : 0; + $$ = _token_create_ival (parser, INTEGER, v); + } | DEFINED '(' IDENTIFIER ')' { int v = hash_table_find (parser->defines, $3) ? 1 : 0; $$ = _token_create_ival (parser, INTEGER, v);
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev