glsl2: Parse #pragma lines
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 30 Aug 2010 18:58:04 +0000 (11:58 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 30 Aug 2010 19:52:42 +0000 (12:52 -0700)
All pragmas are currently ignored.  Also, the error messages when a
pragma is used incorrectly (i.e., '#pragma debug(on)' inside a
function) are crap, but I think this is sufficient for now.

Fixes piglit test cases pragma-0[1-8].(vert|frag).

src/glsl/glsl_lexer.lpp
src/glsl/glsl_parser.ypp

index 3128cdd3a78459283ca3f12ce01ccbd53bc9a782..1de1fb4cf7cbcfe53dc3c5ef459354cd20f5b22e 100644 (file)
@@ -64,7 +64,7 @@
 %option prefix="_mesa_glsl_"
 %option extra-type="struct _mesa_glsl_parse_state *"
 
-%x PP
+%x PP PRAGMA
 
 DEC_INT                [1-9][0-9]*
 HEX_INT                0[xX][0-9a-fA-F]+
@@ -110,7 +110,27 @@ HASH               ^{SPC}#{SPC}
                                    */
                                   yylineno = strtol(ptr, &ptr, 0) - 1;
                                }
-^[ \t]*#[ \t]*pragma           { BEGIN PP; return PRAGMA; }
+^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
+                                 BEGIN PP;
+                                 return PRAGMA_DEBUG_ON;
+                               }
+^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) {
+                                 BEGIN PP;
+                                 return PRAGMA_DEBUG_OFF;
+                               }
+^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) {
+                                 BEGIN PP;
+                                 return PRAGMA_OPTIMIZE_ON;
+                               }
+^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) {
+                                 BEGIN PP;
+                                 return PRAGMA_OPTIMIZE_OFF;
+                               }
+^{SPC}#{SPC}pragma{SPCP}       { BEGIN PRAGMA; }
+
+<PRAGMA>\n                     { BEGIN 0; yylineno++; yycolumn = 0; }
+<PRAGMA>.                      { }
+
 <PP>\/\/[^\n]*                 { }
 <PP>[ \t\r]*                   { }
 <PP>:                          return COLON;
index 4b6d9fe7eaa785112f0a623517fa54a37707fcab..6d99c52503e66cdd2ce299b2ce8e5591d003daa5 100644 (file)
 %token INVARIANT
 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
 
-%token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
+%token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
+%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
+%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
 %token LAYOUT_TOK
 
    /* Reserved words that are not actually used in the grammar.
@@ -236,6 +238,13 @@ version_statement:
        }
        ;
 
+pragma_statement:
+       PRAGMA_DEBUG_ON EOL
+       | PRAGMA_DEBUG_OFF EOL
+       | PRAGMA_OPTIMIZE_ON EOL
+       | PRAGMA_OPTIMIZE_OFF EOL
+       ;
+
 extension_statement_list:
 
        | extension_statement_list extension_statement
@@ -1496,6 +1505,7 @@ jump_statement:
 external_declaration:
        function_definition     { $$ = $1; }
        | declaration           { $$ = $1; }
+       | pragma_statement      { $$ = NULL; }
        ;
 
 function_definition: