Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. %{
  2. /*
  3.  * Copyright © 2008, 2009 Intel Corporation
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the "Software"),
  7.  * to deal in the Software without restriction, including without limitation
  8.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9.  * and/or sell copies of the Software, and to permit persons to whom the
  10.  * Software is furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice (including the next
  13.  * paragraph) shall be included in all copies or substantial portions of the
  14.  * Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <assert.h>
  28.    
  29. #include "ast.h"
  30. #include "glsl_parser_extras.h"
  31. #include "glsl_types.h"
  32.  
  33. #define YYLEX_PARAM state->scanner
  34.  
  35. %}
  36.  
  37. %pure-parser
  38. %error-verbose
  39.  
  40. %locations
  41. %initial-action {
  42.    @$.first_line = 1;
  43.    @$.first_column = 1;
  44.    @$.last_line = 1;
  45.    @$.last_column = 1;
  46.    @$.source = 0;
  47. }
  48.  
  49. %lex-param   {void *scanner}
  50. %parse-param {struct _mesa_glsl_parse_state *state}
  51.  
  52. %union {
  53.    int n;
  54.    float real;
  55.    char *identifier;
  56.  
  57.    struct ast_type_qualifier type_qualifier;
  58.  
  59.    ast_node *node;
  60.    ast_type_specifier *type_specifier;
  61.    ast_fully_specified_type *fully_specified_type;
  62.    ast_function *function;
  63.    ast_parameter_declarator *parameter_declarator;
  64.    ast_function_definition *function_definition;
  65.    ast_compound_statement *compound_statement;
  66.    ast_expression *expression;
  67.    ast_declarator_list *declarator_list;
  68.    ast_struct_specifier *struct_specifier;
  69.    ast_declaration *declaration;
  70.  
  71.    struct {
  72.       ast_node *cond;
  73.       ast_expression *rest;
  74.    } for_rest_statement;
  75.  
  76.    struct {
  77.       ast_node *then_statement;
  78.       ast_node *else_statement;
  79.    } selection_rest_statement;
  80. }
  81.  
  82. %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
  83. %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
  84. %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
  85. %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
  86. %token NOPERSPECTIVE FLAT SMOOTH
  87. %token MAT2X2 MAT2X3 MAT2X4
  88. %token MAT3X2 MAT3X3 MAT3X4
  89. %token MAT4X2 MAT4X3 MAT4X4
  90. %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
  91. %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
  92. %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
  93. %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
  94. %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
  95. %token STRUCT VOID_TOK WHILE
  96. %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
  97. %type <identifier> any_identifier
  98. %token <real> FLOATCONSTANT
  99. %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
  100. %token <identifier> FIELD_SELECTION
  101. %token LEFT_OP RIGHT_OP
  102. %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
  103. %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
  104. %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
  105. %token SUB_ASSIGN
  106. %token INVARIANT
  107. %token LOWP MEDIUMP HIGHP SUPERP PRECISION
  108.  
  109. %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
  110. %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
  111. %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
  112. %token PRAGMA_INVARIANT_ALL
  113. %token LAYOUT_TOK
  114.  
  115.    /* Reserved words that are not actually used in the grammar.
  116.     */
  117. %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
  118. %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
  119. %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
  120. %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
  121. %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
  122. %token SIZEOF CAST NAMESPACE USING
  123.  
  124. %token ERROR_TOK
  125.  
  126. %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
  127. %token  IMAGE1D  IMAGE2D  IMAGE3D  IMAGECUBE  IMAGE1DARRAY  IMAGE2DARRAY
  128. %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
  129. %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
  130. %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
  131. %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
  132. %token ROW_MAJOR
  133.  
  134. %type <identifier> variable_identifier
  135. %type <node> statement
  136. %type <node> statement_list
  137. %type <node> simple_statement
  138. %type <n> precision_qualifier
  139. %type <type_qualifier> type_qualifier
  140. %type <type_qualifier> storage_qualifier
  141. %type <type_qualifier> interpolation_qualifier
  142. %type <type_qualifier> layout_qualifier
  143. %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
  144. %type <type_specifier> type_specifier
  145. %type <type_specifier> type_specifier_no_prec
  146. %type <type_specifier> type_specifier_nonarray
  147. %type <n> basic_type_specifier_nonarray
  148. %type <fully_specified_type> fully_specified_type
  149. %type <function> function_prototype
  150. %type <function> function_header
  151. %type <function> function_header_with_parameters
  152. %type <function> function_declarator
  153. %type <parameter_declarator> parameter_declarator
  154. %type <parameter_declarator> parameter_declaration
  155. %type <type_qualifier> parameter_qualifier
  156. %type <type_qualifier> parameter_type_qualifier
  157. %type <type_specifier> parameter_type_specifier
  158. %type <function_definition> function_definition
  159. %type <compound_statement> compound_statement_no_new_scope
  160. %type <compound_statement> compound_statement
  161. %type <node> statement_no_new_scope
  162. %type <node> expression_statement
  163. %type <expression> expression
  164. %type <expression> primary_expression
  165. %type <expression> assignment_expression
  166. %type <expression> conditional_expression
  167. %type <expression> logical_or_expression
  168. %type <expression> logical_xor_expression
  169. %type <expression> logical_and_expression
  170. %type <expression> inclusive_or_expression
  171. %type <expression> exclusive_or_expression
  172. %type <expression> and_expression
  173. %type <expression> equality_expression
  174. %type <expression> relational_expression
  175. %type <expression> shift_expression
  176. %type <expression> additive_expression
  177. %type <expression> multiplicative_expression
  178. %type <expression> unary_expression
  179. %type <expression> constant_expression
  180. %type <expression> integer_expression
  181. %type <expression> postfix_expression
  182. %type <expression> function_call_header_with_parameters
  183. %type <expression> function_call_header_no_parameters
  184. %type <expression> function_call_header
  185. %type <expression> function_call_generic
  186. %type <expression> function_call_or_method
  187. %type <expression> function_call
  188. %type <expression> method_call_generic
  189. %type <expression> method_call_header_with_parameters
  190. %type <expression> method_call_header_no_parameters
  191. %type <expression> method_call_header
  192. %type <n> assignment_operator
  193. %type <n> unary_operator
  194. %type <expression> function_identifier
  195. %type <node> external_declaration
  196. %type <declarator_list> init_declarator_list
  197. %type <declarator_list> single_declaration
  198. %type <expression> initializer
  199. %type <node> declaration
  200. %type <node> declaration_statement
  201. %type <node> jump_statement
  202. %type <struct_specifier> struct_specifier
  203. %type <node> struct_declaration_list
  204. %type <declarator_list> struct_declaration
  205. %type <declaration> struct_declarator
  206. %type <declaration> struct_declarator_list
  207. %type <node> selection_statement
  208. %type <selection_rest_statement> selection_rest_statement
  209. %type <node> iteration_statement
  210. %type <node> condition
  211. %type <node> conditionopt
  212. %type <node> for_init_statement
  213. %type <for_rest_statement> for_rest_statement
  214. %%
  215.  
  216. translation_unit:
  217.         version_statement extension_statement_list
  218.         {
  219.            _mesa_glsl_initialize_types(state);
  220.         }
  221.         external_declaration_list
  222.         {
  223.            delete state->symbols;
  224.            state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
  225.            _mesa_glsl_initialize_types(state);
  226.         }
  227.         ;
  228.  
  229. version_statement:
  230.         /* blank - no #version specified: defaults are already set */
  231.         | VERSION INTCONSTANT EOL
  232.         {
  233.            bool supported = false;
  234.  
  235.            switch ($2) {
  236.            case 100:
  237.               state->es_shader = true;
  238.               supported = state->Const.GLSL_100ES;
  239.               break;
  240.            case 110:
  241.               supported = state->Const.GLSL_110;
  242.               break;
  243.            case 120:
  244.               supported = state->Const.GLSL_120;
  245.               break;
  246.            case 130:
  247.               supported = state->Const.GLSL_130;
  248.               break;
  249.            default:
  250.               supported = false;
  251.               break;
  252.            }
  253.  
  254.            state->language_version = $2;
  255.            state->version_string =
  256.               ralloc_asprintf(state, "GLSL%s %d.%02d",
  257.                               state->es_shader ? " ES" : "",
  258.                               state->language_version / 100,
  259.                               state->language_version % 100);
  260.  
  261.            if (!supported) {
  262.               _mesa_glsl_error(& @2, state, "%s is not supported. "
  263.                                "Supported versions are: %s\n",
  264.                                state->version_string,
  265.                                state->supported_version_string);
  266.            }
  267.         }
  268.         ;
  269.  
  270. pragma_statement:
  271.         PRAGMA_DEBUG_ON EOL
  272.         | PRAGMA_DEBUG_OFF EOL
  273.         | PRAGMA_OPTIMIZE_ON EOL
  274.         | PRAGMA_OPTIMIZE_OFF EOL
  275.         | PRAGMA_INVARIANT_ALL EOL
  276.         {
  277.            if (state->language_version < 120) {
  278.               _mesa_glsl_warning(& @1, state,
  279.                                  "pragma `invariant(all)' not supported in %s",
  280.                                  state->version_string);
  281.            } else {
  282.               state->all_invariant = true;
  283.            }
  284.         }
  285.         ;
  286.  
  287. extension_statement_list:
  288.  
  289.         | extension_statement_list extension_statement
  290.         ;
  291.  
  292. any_identifier:
  293.         IDENTIFIER
  294.         | TYPE_IDENTIFIER
  295.         | NEW_IDENTIFIER
  296.         ;
  297.  
  298. extension_statement:
  299.         EXTENSION any_identifier COLON any_identifier EOL
  300.         {
  301.            if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
  302.               YYERROR;
  303.            }
  304.         }
  305.         ;
  306.  
  307. external_declaration_list:
  308.         external_declaration
  309.         {
  310.            /* FINISHME: The NULL test is required because pragmas are set to
  311.             * FINISHME: NULL. (See production rule for external_declaration.)
  312.             */
  313.            if ($1 != NULL)
  314.               state->translation_unit.push_tail(& $1->link);
  315.         }
  316.         | external_declaration_list external_declaration
  317.         {
  318.            /* FINISHME: The NULL test is required because pragmas are set to
  319.             * FINISHME: NULL. (See production rule for external_declaration.)
  320.             */
  321.            if ($2 != NULL)
  322.               state->translation_unit.push_tail(& $2->link);
  323.         }
  324.         ;
  325.  
  326. variable_identifier:
  327.         IDENTIFIER
  328.         | NEW_IDENTIFIER
  329.         ;
  330.  
  331. primary_expression:
  332.         variable_identifier
  333.         {
  334.            void *ctx = state;
  335.            $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
  336.            $$->set_location(yylloc);
  337.            $$->primary_expression.identifier = $1;
  338.         }
  339.         | INTCONSTANT
  340.         {
  341.            void *ctx = state;
  342.            $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
  343.            $$->set_location(yylloc);
  344.            $$->primary_expression.int_constant = $1;
  345.         }
  346.         | UINTCONSTANT
  347.         {
  348.            void *ctx = state;
  349.            $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
  350.            $$->set_location(yylloc);
  351.            $$->primary_expression.uint_constant = $1;
  352.         }
  353.         | FLOATCONSTANT
  354.         {
  355.            void *ctx = state;
  356.            $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
  357.            $$->set_location(yylloc);
  358.            $$->primary_expression.float_constant = $1;
  359.         }
  360.         | BOOLCONSTANT
  361.         {
  362.            void *ctx = state;
  363.            $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
  364.            $$->set_location(yylloc);
  365.            $$->primary_expression.bool_constant = $1;
  366.         }
  367.         | '(' expression ')'
  368.         {
  369.            $$ = $2;
  370.         }
  371.         ;
  372.  
  373. postfix_expression:
  374.         primary_expression
  375.         | postfix_expression '[' integer_expression ']'
  376.         {
  377.            void *ctx = state;
  378.            $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
  379.            $$->set_location(yylloc);
  380.         }
  381.         | function_call
  382.         {
  383.            $$ = $1;
  384.         }
  385.         | postfix_expression '.' any_identifier
  386.         {
  387.            void *ctx = state;
  388.            $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
  389.            $$->set_location(yylloc);
  390.            $$->primary_expression.identifier = $3;
  391.         }
  392.         | postfix_expression INC_OP
  393.         {
  394.            void *ctx = state;
  395.            $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
  396.            $$->set_location(yylloc);
  397.         }
  398.         | postfix_expression DEC_OP
  399.         {
  400.            void *ctx = state;
  401.            $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
  402.            $$->set_location(yylloc);
  403.         }
  404.         ;
  405.  
  406. integer_expression:
  407.         expression
  408.         ;
  409.  
  410. function_call:
  411.         function_call_or_method
  412.         ;
  413.  
  414. function_call_or_method:
  415.         function_call_generic
  416.         | postfix_expression '.' method_call_generic
  417.         {
  418.            void *ctx = state;
  419.            $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
  420.            $$->set_location(yylloc);
  421.         }
  422.         ;
  423.  
  424. function_call_generic:
  425.         function_call_header_with_parameters ')'
  426.         | function_call_header_no_parameters ')'
  427.         ;
  428.  
  429. function_call_header_no_parameters:
  430.         function_call_header VOID_TOK
  431.         | function_call_header
  432.         ;
  433.  
  434. function_call_header_with_parameters:
  435.         function_call_header assignment_expression
  436.         {
  437.            $$ = $1;
  438.            $$->set_location(yylloc);
  439.            $$->expressions.push_tail(& $2->link);
  440.         }
  441.         | function_call_header_with_parameters ',' assignment_expression
  442.         {
  443.            $$ = $1;
  444.            $$->set_location(yylloc);
  445.            $$->expressions.push_tail(& $3->link);
  446.         }
  447.         ;
  448.  
  449.         // Grammar Note: Constructors look like functions, but lexical
  450.         // analysis recognized most of them as keywords. They are now
  451.         // recognized through "type_specifier".
  452. function_call_header:
  453.         function_identifier '('
  454.         ;
  455.  
  456. function_identifier:
  457.         type_specifier
  458.         {
  459.            void *ctx = state;
  460.            $$ = new(ctx) ast_function_expression($1);
  461.            $$->set_location(yylloc);
  462.         }
  463.         | variable_identifier
  464.         {
  465.            void *ctx = state;
  466.            ast_expression *callee = new(ctx) ast_expression($1);
  467.            $$ = new(ctx) ast_function_expression(callee);
  468.            $$->set_location(yylloc);
  469.         }
  470.         | FIELD_SELECTION
  471.         {
  472.            void *ctx = state;
  473.            ast_expression *callee = new(ctx) ast_expression($1);
  474.            $$ = new(ctx) ast_function_expression(callee);
  475.            $$->set_location(yylloc);
  476.         }
  477.         ;
  478.  
  479. method_call_generic:
  480.         method_call_header_with_parameters ')'
  481.         | method_call_header_no_parameters ')'
  482.         ;
  483.  
  484. method_call_header_no_parameters:
  485.         method_call_header VOID_TOK
  486.         | method_call_header
  487.         ;
  488.  
  489. method_call_header_with_parameters:
  490.         method_call_header assignment_expression
  491.         {
  492.            $$ = $1;
  493.            $$->set_location(yylloc);
  494.            $$->expressions.push_tail(& $2->link);
  495.         }
  496.         | method_call_header_with_parameters ',' assignment_expression
  497.         {
  498.            $$ = $1;
  499.            $$->set_location(yylloc);
  500.            $$->expressions.push_tail(& $3->link);
  501.         }
  502.         ;
  503.  
  504.         // Grammar Note: Constructors look like methods, but lexical
  505.         // analysis recognized most of them as keywords. They are now
  506.         // recognized through "type_specifier".
  507. method_call_header:
  508.         variable_identifier '('
  509.         {
  510.            void *ctx = state;
  511.            ast_expression *callee = new(ctx) ast_expression($1);
  512.            $$ = new(ctx) ast_function_expression(callee);
  513.            $$->set_location(yylloc);
  514.         }
  515.         ;
  516.  
  517.         // Grammar Note: No traditional style type casts.
  518. unary_expression:
  519.         postfix_expression
  520.         | INC_OP unary_expression
  521.         {
  522.            void *ctx = state;
  523.            $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
  524.            $$->set_location(yylloc);
  525.         }
  526.         | DEC_OP unary_expression
  527.         {
  528.            void *ctx = state;
  529.            $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
  530.            $$->set_location(yylloc);
  531.         }
  532.         | unary_operator unary_expression
  533.         {
  534.            void *ctx = state;
  535.            $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
  536.            $$->set_location(yylloc);
  537.         }
  538.         ;
  539.  
  540.         // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
  541. unary_operator:
  542.         '+'     { $$ = ast_plus; }
  543.         | '-'   { $$ = ast_neg; }
  544.         | '!'   { $$ = ast_logic_not; }
  545.         | '~'   { $$ = ast_bit_not; }
  546.         ;
  547.  
  548. multiplicative_expression:
  549.         unary_expression
  550.         | multiplicative_expression '*' unary_expression
  551.         {
  552.            void *ctx = state;
  553.            $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
  554.            $$->set_location(yylloc);
  555.         }
  556.         | multiplicative_expression '/' unary_expression
  557.         {
  558.            void *ctx = state;
  559.            $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
  560.            $$->set_location(yylloc);
  561.         }
  562.         | multiplicative_expression '%' unary_expression
  563.         {
  564.            void *ctx = state;
  565.            $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
  566.            $$->set_location(yylloc);
  567.         }
  568.         ;
  569.  
  570. additive_expression:
  571.         multiplicative_expression
  572.         | additive_expression '+' multiplicative_expression
  573.         {
  574.            void *ctx = state;
  575.            $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
  576.            $$->set_location(yylloc);
  577.         }
  578.         | additive_expression '-' multiplicative_expression
  579.         {
  580.            void *ctx = state;
  581.            $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
  582.            $$->set_location(yylloc);
  583.         }
  584.         ;
  585.  
  586. shift_expression:
  587.         additive_expression
  588.         | shift_expression LEFT_OP additive_expression
  589.         {
  590.            void *ctx = state;
  591.            $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
  592.            $$->set_location(yylloc);
  593.         }
  594.         | shift_expression RIGHT_OP additive_expression
  595.         {
  596.            void *ctx = state;
  597.            $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
  598.            $$->set_location(yylloc);
  599.         }
  600.         ;
  601.  
  602. relational_expression:
  603.         shift_expression
  604.         | relational_expression '<' shift_expression
  605.         {
  606.            void *ctx = state;
  607.            $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
  608.            $$->set_location(yylloc);
  609.         }
  610.         | relational_expression '>' shift_expression
  611.         {
  612.            void *ctx = state;
  613.            $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
  614.            $$->set_location(yylloc);
  615.         }
  616.         | relational_expression LE_OP shift_expression
  617.         {
  618.            void *ctx = state;
  619.            $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
  620.            $$->set_location(yylloc);
  621.         }
  622.         | relational_expression GE_OP shift_expression
  623.         {
  624.            void *ctx = state;
  625.            $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
  626.            $$->set_location(yylloc);
  627.         }
  628.         ;
  629.  
  630. equality_expression:
  631.         relational_expression
  632.         | equality_expression EQ_OP relational_expression
  633.         {
  634.            void *ctx = state;
  635.            $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
  636.            $$->set_location(yylloc);
  637.         }
  638.         | equality_expression NE_OP relational_expression
  639.         {
  640.            void *ctx = state;
  641.            $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
  642.            $$->set_location(yylloc);
  643.         }
  644.         ;
  645.  
  646. and_expression:
  647.         equality_expression
  648.         | and_expression '&' equality_expression
  649.         {
  650.            void *ctx = state;
  651.            $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
  652.            $$->set_location(yylloc);
  653.         }
  654.         ;
  655.  
  656. exclusive_or_expression:
  657.         and_expression
  658.         | exclusive_or_expression '^' and_expression
  659.         {
  660.            void *ctx = state;
  661.            $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
  662.            $$->set_location(yylloc);
  663.         }
  664.         ;
  665.  
  666. inclusive_or_expression:
  667.         exclusive_or_expression
  668.         | inclusive_or_expression '|' exclusive_or_expression
  669.         {
  670.            void *ctx = state;
  671.            $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
  672.            $$->set_location(yylloc);
  673.         }
  674.         ;
  675.  
  676. logical_and_expression:
  677.         inclusive_or_expression
  678.         | logical_and_expression AND_OP inclusive_or_expression
  679.         {
  680.            void *ctx = state;
  681.            $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
  682.            $$->set_location(yylloc);
  683.         }
  684.         ;
  685.  
  686. logical_xor_expression:
  687.         logical_and_expression
  688.         | logical_xor_expression XOR_OP logical_and_expression
  689.         {
  690.            void *ctx = state;
  691.            $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
  692.            $$->set_location(yylloc);
  693.         }
  694.         ;
  695.  
  696. logical_or_expression:
  697.         logical_xor_expression
  698.         | logical_or_expression OR_OP logical_xor_expression
  699.         {
  700.            void *ctx = state;
  701.            $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
  702.            $$->set_location(yylloc);
  703.         }
  704.         ;
  705.  
  706. conditional_expression:
  707.         logical_or_expression
  708.         | logical_or_expression '?' expression ':' assignment_expression
  709.         {
  710.            void *ctx = state;
  711.            $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
  712.            $$->set_location(yylloc);
  713.         }
  714.         ;
  715.  
  716. assignment_expression:
  717.         conditional_expression
  718.         | unary_expression assignment_operator assignment_expression
  719.         {
  720.            void *ctx = state;
  721.            $$ = new(ctx) ast_expression($2, $1, $3, NULL);
  722.            $$->set_location(yylloc);
  723.         }
  724.         ;
  725.  
  726. assignment_operator:
  727.         '='             { $$ = ast_assign; }
  728.         | MUL_ASSIGN    { $$ = ast_mul_assign; }
  729.         | DIV_ASSIGN    { $$ = ast_div_assign; }
  730.         | MOD_ASSIGN    { $$ = ast_mod_assign; }
  731.         | ADD_ASSIGN    { $$ = ast_add_assign; }
  732.         | SUB_ASSIGN    { $$ = ast_sub_assign; }
  733.         | LEFT_ASSIGN   { $$ = ast_ls_assign; }
  734.         | RIGHT_ASSIGN  { $$ = ast_rs_assign; }
  735.         | AND_ASSIGN    { $$ = ast_and_assign; }
  736.         | XOR_ASSIGN    { $$ = ast_xor_assign; }
  737.         | OR_ASSIGN     { $$ = ast_or_assign; }
  738.         ;
  739.  
  740. expression:
  741.         assignment_expression
  742.         {
  743.            $$ = $1;
  744.         }
  745.         | expression ',' assignment_expression
  746.         {
  747.            void *ctx = state;
  748.            if ($1->oper != ast_sequence) {
  749.               $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
  750.               $$->set_location(yylloc);
  751.               $$->expressions.push_tail(& $1->link);
  752.            } else {
  753.               $$ = $1;
  754.            }
  755.  
  756.            $$->expressions.push_tail(& $3->link);
  757.         }
  758.         ;
  759.  
  760. constant_expression:
  761.         conditional_expression
  762.         ;
  763.  
  764. declaration:
  765.         function_prototype ';'
  766.         {
  767.            state->symbols->pop_scope();
  768.            $$ = $1;
  769.         }
  770.         | init_declarator_list ';'
  771.         {
  772.            $$ = $1;
  773.         }
  774.         | PRECISION precision_qualifier type_specifier_no_prec ';'
  775.         {
  776.            $3->precision = $2;
  777.            $3->is_precision_statement = true;
  778.            $$ = $3;
  779.         }
  780.         ;
  781.  
  782. function_prototype:
  783.         function_declarator ')'
  784.         ;
  785.  
  786. function_declarator:
  787.         function_header
  788.         | function_header_with_parameters
  789.         ;
  790.  
  791. function_header_with_parameters:
  792.         function_header parameter_declaration
  793.         {
  794.            $$ = $1;
  795.            $$->parameters.push_tail(& $2->link);
  796.         }
  797.         | function_header_with_parameters ',' parameter_declaration
  798.         {
  799.            $$ = $1;
  800.            $$->parameters.push_tail(& $3->link);
  801.         }
  802.         ;
  803.  
  804. function_header:
  805.         fully_specified_type variable_identifier '('
  806.         {
  807.            void *ctx = state;
  808.            $$ = new(ctx) ast_function();
  809.            $$->set_location(yylloc);
  810.            $$->return_type = $1;
  811.            $$->identifier = $2;
  812.  
  813.            state->symbols->add_function(new(state) ir_function($2));
  814.            state->symbols->push_scope();
  815.         }
  816.         ;
  817.  
  818. parameter_declarator:
  819.         type_specifier any_identifier
  820.         {
  821.            void *ctx = state;
  822.            $$ = new(ctx) ast_parameter_declarator();
  823.            $$->set_location(yylloc);
  824.            $$->type = new(ctx) ast_fully_specified_type();
  825.            $$->type->set_location(yylloc);
  826.            $$->type->specifier = $1;
  827.            $$->identifier = $2;
  828.         }
  829.         | type_specifier any_identifier '[' constant_expression ']'
  830.         {
  831.            void *ctx = state;
  832.            $$ = new(ctx) ast_parameter_declarator();
  833.            $$->set_location(yylloc);
  834.            $$->type = new(ctx) ast_fully_specified_type();
  835.            $$->type->set_location(yylloc);
  836.            $$->type->specifier = $1;
  837.            $$->identifier = $2;
  838.            $$->is_array = true;
  839.            $$->array_size = $4;
  840.         }
  841.         ;
  842.  
  843. parameter_declaration:
  844.         parameter_type_qualifier parameter_qualifier parameter_declarator
  845.         {
  846.            $1.flags.i |= $2.flags.i;
  847.  
  848.            $$ = $3;
  849.            $$->type->qualifier = $1;
  850.         }
  851.         | parameter_qualifier parameter_declarator
  852.         {
  853.            $$ = $2;
  854.            $$->type->qualifier = $1;
  855.         }
  856.         | parameter_type_qualifier parameter_qualifier parameter_type_specifier
  857.         {
  858.            void *ctx = state;
  859.            $1.flags.i |= $2.flags.i;
  860.  
  861.            $$ = new(ctx) ast_parameter_declarator();
  862.            $$->set_location(yylloc);
  863.            $$->type = new(ctx) ast_fully_specified_type();
  864.            $$->type->qualifier = $1;
  865.            $$->type->specifier = $3;
  866.         }
  867.         | parameter_qualifier parameter_type_specifier
  868.         {
  869.            void *ctx = state;
  870.            $$ = new(ctx) ast_parameter_declarator();
  871.            $$->set_location(yylloc);
  872.            $$->type = new(ctx) ast_fully_specified_type();
  873.            $$->type->qualifier = $1;
  874.            $$->type->specifier = $2;
  875.         }
  876.         ;
  877.  
  878. parameter_qualifier:
  879.         /* empty */
  880.         {
  881.            memset(& $$, 0, sizeof($$));
  882.         }
  883.         | IN_TOK
  884.         {
  885.            memset(& $$, 0, sizeof($$));
  886.            $$.flags.q.in = 1;
  887.         }
  888.         | OUT_TOK
  889.         {
  890.            memset(& $$, 0, sizeof($$));
  891.            $$.flags.q.out = 1;
  892.         }
  893.         | INOUT_TOK
  894.         {
  895.            memset(& $$, 0, sizeof($$));
  896.            $$.flags.q.in = 1;
  897.            $$.flags.q.out = 1;
  898.         }
  899.         ;
  900.  
  901. parameter_type_specifier:
  902.         type_specifier
  903.         ;
  904.  
  905. init_declarator_list:
  906.         single_declaration
  907.         | init_declarator_list ',' any_identifier
  908.         {
  909.            void *ctx = state;
  910.            ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
  911.            decl->set_location(yylloc);
  912.  
  913.            $$ = $1;
  914.            $$->declarations.push_tail(&decl->link);
  915.            state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  916.         }
  917.         | init_declarator_list ',' any_identifier '[' ']'
  918.         {
  919.            void *ctx = state;
  920.            ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
  921.            decl->set_location(yylloc);
  922.  
  923.            $$ = $1;
  924.            $$->declarations.push_tail(&decl->link);
  925.            state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  926.         }
  927.         | init_declarator_list ',' any_identifier '[' constant_expression ']'
  928.         {
  929.            void *ctx = state;
  930.            ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
  931.            decl->set_location(yylloc);
  932.  
  933.            $$ = $1;
  934.            $$->declarations.push_tail(&decl->link);
  935.            state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  936.         }
  937.         | init_declarator_list ',' any_identifier '[' ']' '=' initializer
  938.         {
  939.            void *ctx = state;
  940.            ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
  941.            decl->set_location(yylloc);
  942.  
  943.            $$ = $1;
  944.            $$->declarations.push_tail(&decl->link);
  945.            state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  946.         }
  947.         | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
  948.         {
  949.            void *ctx = state;
  950.            ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
  951.            decl->set_location(yylloc);
  952.  
  953.            $$ = $1;
  954.            $$->declarations.push_tail(&decl->link);
  955.            state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  956.         }
  957.         | init_declarator_list ',' any_identifier '=' initializer
  958.         {
  959.            void *ctx = state;
  960.            ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
  961.            decl->set_location(yylloc);
  962.  
  963.            $$ = $1;
  964.            $$->declarations.push_tail(&decl->link);
  965.            state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  966.         }
  967.         ;
  968.  
  969.         // Grammar Note: No 'enum', or 'typedef'.
  970. single_declaration:
  971.         fully_specified_type
  972.         {
  973.            void *ctx = state;
  974.            if ($1->specifier->type_specifier != ast_struct) {
  975.               _mesa_glsl_error(& @1, state, "empty declaration list\n");
  976.               YYERROR;
  977.            } else {
  978.               $$ = new(ctx) ast_declarator_list($1);
  979.               $$->set_location(yylloc);
  980.            }
  981.         }
  982.         | fully_specified_type any_identifier
  983.         {
  984.            void *ctx = state;
  985.            ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
  986.  
  987.            $$ = new(ctx) ast_declarator_list($1);
  988.            $$->set_location(yylloc);
  989.            $$->declarations.push_tail(&decl->link);
  990.         }
  991.         | fully_specified_type any_identifier '[' ']'
  992.         {
  993.            void *ctx = state;
  994.            ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
  995.  
  996.            $$ = new(ctx) ast_declarator_list($1);
  997.            $$->set_location(yylloc);
  998.            $$->declarations.push_tail(&decl->link);
  999.         }
  1000.         | fully_specified_type any_identifier '[' constant_expression ']'
  1001.         {
  1002.            void *ctx = state;
  1003.            ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
  1004.  
  1005.            $$ = new(ctx) ast_declarator_list($1);
  1006.            $$->set_location(yylloc);
  1007.            $$->declarations.push_tail(&decl->link);
  1008.         }
  1009.         | fully_specified_type any_identifier '[' ']' '=' initializer
  1010.         {
  1011.            void *ctx = state;
  1012.            ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
  1013.  
  1014.            $$ = new(ctx) ast_declarator_list($1);
  1015.            $$->set_location(yylloc);
  1016.            $$->declarations.push_tail(&decl->link);
  1017.         }
  1018.         | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
  1019.         {
  1020.            void *ctx = state;
  1021.            ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
  1022.  
  1023.            $$ = new(ctx) ast_declarator_list($1);
  1024.            $$->set_location(yylloc);
  1025.            $$->declarations.push_tail(&decl->link);
  1026.         }
  1027.         | fully_specified_type any_identifier '=' initializer
  1028.         {
  1029.            void *ctx = state;
  1030.            ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
  1031.  
  1032.            $$ = new(ctx) ast_declarator_list($1);
  1033.            $$->set_location(yylloc);
  1034.            $$->declarations.push_tail(&decl->link);
  1035.         }
  1036.         | INVARIANT variable_identifier // Vertex only.
  1037.         {
  1038.            void *ctx = state;
  1039.            ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
  1040.  
  1041.            $$ = new(ctx) ast_declarator_list(NULL);
  1042.            $$->set_location(yylloc);
  1043.            $$->invariant = true;
  1044.  
  1045.            $$->declarations.push_tail(&decl->link);
  1046.         }
  1047.         ;
  1048.  
  1049. fully_specified_type:
  1050.         type_specifier
  1051.         {
  1052.            void *ctx = state;
  1053.            $$ = new(ctx) ast_fully_specified_type();
  1054.            $$->set_location(yylloc);
  1055.            $$->specifier = $1;
  1056.         }
  1057.         | type_qualifier type_specifier
  1058.         {
  1059.            void *ctx = state;
  1060.            $$ = new(ctx) ast_fully_specified_type();
  1061.            $$->set_location(yylloc);
  1062.            $$->qualifier = $1;
  1063.            $$->specifier = $2;
  1064.         }
  1065.         ;
  1066.  
  1067. layout_qualifier:
  1068.         LAYOUT_TOK '(' layout_qualifier_id_list ')'
  1069.         {
  1070.           $$ = $3;
  1071.         }
  1072.         ;
  1073.  
  1074. layout_qualifier_id_list:
  1075.         layout_qualifier_id
  1076.         | layout_qualifier_id_list ',' layout_qualifier_id
  1077.         {
  1078.            if (($1.flags.i & $3.flags.i) != 0) {
  1079.               _mesa_glsl_error(& @3, state,
  1080.                                "duplicate layout qualifiers used\n");
  1081.               YYERROR;
  1082.            }
  1083.  
  1084.            $$.flags.i = $1.flags.i | $3.flags.i;
  1085.  
  1086.            if ($1.flags.q.explicit_location)
  1087.               $$.location = $1.location;
  1088.  
  1089.            if ($3.flags.q.explicit_location)
  1090.               $$.location = $3.location;
  1091.         }
  1092.         ;
  1093.  
  1094. layout_qualifier_id:
  1095.         any_identifier
  1096.         {
  1097.            bool got_one = false;
  1098.  
  1099.            memset(& $$, 0, sizeof($$));
  1100.  
  1101.            if (state->ARB_fragment_coord_conventions_enable) {
  1102.               if (strcmp($1, "origin_upper_left") == 0) {
  1103.                  got_one = true;
  1104.                  $$.flags.q.origin_upper_left = 1;
  1105.               } else if (strcmp($1, "pixel_center_integer") == 0) {
  1106.                  got_one = true;
  1107.                  $$.flags.q.pixel_center_integer = 1;
  1108.               }
  1109.            }
  1110.  
  1111.            /* If the identifier didn't match any known layout identifiers,
  1112.             * emit an error.
  1113.             */
  1114.            if (!got_one) {
  1115.               _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
  1116.                                "`%s'\n", $1);
  1117.               YYERROR;
  1118.            } else if (state->ARB_fragment_coord_conventions_warn) {
  1119.               _mesa_glsl_warning(& @1, state,
  1120.                                  "GL_ARB_fragment_coord_conventions layout "
  1121.                                  "identifier `%s' used\n", $1);
  1122.            }
  1123.         }
  1124.         | any_identifier '=' INTCONSTANT
  1125.         {
  1126.            bool got_one = false;
  1127.  
  1128.            memset(& $$, 0, sizeof($$));
  1129.  
  1130.            if (state->ARB_explicit_attrib_location_enable) {
  1131.               /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
  1132.                * FINISHME: GLSL 1.30 (or later) are supported.
  1133.                */
  1134.               if (strcmp("location", $1) == 0) {
  1135.                  got_one = true;
  1136.  
  1137.                  $$.flags.q.explicit_location = 1;
  1138.  
  1139.                  if ($3 >= 0) {
  1140.                     $$.location = $3;
  1141.                  } else {
  1142.                     _mesa_glsl_error(& @3, state,
  1143.                                      "invalid location %d specified\n", $3);
  1144.                     YYERROR;
  1145.                  }
  1146.               }
  1147.            }
  1148.  
  1149.            /* If the identifier didn't match any known layout identifiers,
  1150.             * emit an error.
  1151.             */
  1152.            if (!got_one) {
  1153.               _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
  1154.                                "`%s'\n", $1);
  1155.               YYERROR;
  1156.            } else if (state->ARB_explicit_attrib_location_warn) {
  1157.               _mesa_glsl_warning(& @1, state,
  1158.                                  "GL_ARB_explicit_attrib_location layout "
  1159.                                  "identifier `%s' used\n", $1);
  1160.            }
  1161.         }
  1162.         ;
  1163.  
  1164. interpolation_qualifier:
  1165.         SMOOTH
  1166.         {
  1167.            memset(& $$, 0, sizeof($$));
  1168.            $$.flags.q.smooth = 1;
  1169.         }
  1170.         | FLAT
  1171.         {
  1172.            memset(& $$, 0, sizeof($$));
  1173.            $$.flags.q.flat = 1;
  1174.         }
  1175.         | NOPERSPECTIVE
  1176.         {
  1177.            memset(& $$, 0, sizeof($$));
  1178.            $$.flags.q.noperspective = 1;
  1179.         }
  1180.         ;
  1181.  
  1182. parameter_type_qualifier:
  1183.         CONST_TOK
  1184.         {
  1185.            memset(& $$, 0, sizeof($$));
  1186.            $$.flags.q.constant = 1;
  1187.         }
  1188.         ;
  1189.  
  1190. type_qualifier:
  1191.         storage_qualifier
  1192.         | layout_qualifier
  1193.         | layout_qualifier storage_qualifier
  1194.         {
  1195.            $$ = $1;
  1196.            $$.flags.i |= $2.flags.i;
  1197.         }
  1198.         | interpolation_qualifier
  1199.         | interpolation_qualifier storage_qualifier
  1200.         {
  1201.            $$ = $1;
  1202.            $$.flags.i |= $2.flags.i;
  1203.         }
  1204.         | INVARIANT storage_qualifier
  1205.         {
  1206.            $$ = $2;
  1207.            $$.flags.q.invariant = 1;
  1208.         }
  1209.         | INVARIANT interpolation_qualifier storage_qualifier
  1210.         {
  1211.            $$ = $2;
  1212.            $$.flags.i |= $3.flags.i;
  1213.            $$.flags.q.invariant = 1;
  1214.         }
  1215.         | INVARIANT
  1216.         {
  1217.            memset(& $$, 0, sizeof($$));
  1218.            $$.flags.q.invariant = 1;
  1219.         }
  1220.         ;
  1221.  
  1222. storage_qualifier:
  1223.         CONST_TOK
  1224.         {
  1225.            memset(& $$, 0, sizeof($$));
  1226.            $$.flags.q.constant = 1;
  1227.         }
  1228.         | ATTRIBUTE
  1229.         {
  1230.            memset(& $$, 0, sizeof($$));
  1231.            $$.flags.q.attribute = 1;
  1232.         }
  1233.         | VARYING
  1234.         {
  1235.            memset(& $$, 0, sizeof($$));
  1236.            $$.flags.q.varying = 1;
  1237.         }
  1238.         | CENTROID VARYING
  1239.         {
  1240.            memset(& $$, 0, sizeof($$));
  1241.            $$.flags.q.centroid = 1;
  1242.            $$.flags.q.varying = 1;
  1243.         }
  1244.         | IN_TOK
  1245.         {
  1246.            memset(& $$, 0, sizeof($$));
  1247.            $$.flags.q.in = 1;
  1248.         }
  1249.         | OUT_TOK
  1250.         {
  1251.            memset(& $$, 0, sizeof($$));
  1252.            $$.flags.q.out = 1;
  1253.         }
  1254.         | CENTROID IN_TOK
  1255.         {
  1256.            memset(& $$, 0, sizeof($$));
  1257.            $$.flags.q.centroid = 1; $$.flags.q.in = 1;
  1258.         }
  1259.         | CENTROID OUT_TOK
  1260.         {
  1261.            memset(& $$, 0, sizeof($$));
  1262.            $$.flags.q.centroid = 1; $$.flags.q.out = 1;
  1263.         }
  1264.         | UNIFORM
  1265.         {
  1266.            memset(& $$, 0, sizeof($$));
  1267.            $$.flags.q.uniform = 1;
  1268.         }
  1269.         ;
  1270.  
  1271. type_specifier:
  1272.         type_specifier_no_prec
  1273.         {
  1274.            $$ = $1;
  1275.         }
  1276.         | precision_qualifier type_specifier_no_prec
  1277.         {
  1278.            $$ = $2;
  1279.            $$->precision = $1;
  1280.         }
  1281.         ;
  1282.  
  1283. type_specifier_no_prec:
  1284.         type_specifier_nonarray
  1285.         | type_specifier_nonarray '[' ']'
  1286.         {
  1287.            $$ = $1;
  1288.            $$->is_array = true;
  1289.            $$->array_size = NULL;
  1290.         }
  1291.         | type_specifier_nonarray '[' constant_expression ']'
  1292.         {
  1293.            $$ = $1;
  1294.            $$->is_array = true;
  1295.            $$->array_size = $3;
  1296.         }
  1297.         ;
  1298.  
  1299. type_specifier_nonarray:
  1300.         basic_type_specifier_nonarray
  1301.         {
  1302.            void *ctx = state;
  1303.            $$ = new(ctx) ast_type_specifier($1);
  1304.            $$->set_location(yylloc);
  1305.         }
  1306.         | struct_specifier
  1307.         {
  1308.            void *ctx = state;
  1309.            $$ = new(ctx) ast_type_specifier($1);
  1310.            $$->set_location(yylloc);
  1311.         }
  1312.         | TYPE_IDENTIFIER
  1313.         {
  1314.            void *ctx = state;
  1315.            $$ = new(ctx) ast_type_specifier($1);
  1316.            $$->set_location(yylloc);
  1317.         }
  1318.         ;
  1319.  
  1320. basic_type_specifier_nonarray:
  1321.         VOID_TOK                { $$ = ast_void; }
  1322.         | FLOAT_TOK             { $$ = ast_float; }
  1323.         | INT_TOK               { $$ = ast_int; }
  1324.         | UINT_TOK              { $$ = ast_uint; }
  1325.         | BOOL_TOK              { $$ = ast_bool; }
  1326.         | VEC2                  { $$ = ast_vec2; }
  1327.         | VEC3                  { $$ = ast_vec3; }
  1328.         | VEC4                  { $$ = ast_vec4; }
  1329.         | BVEC2                 { $$ = ast_bvec2; }
  1330.         | BVEC3                 { $$ = ast_bvec3; }
  1331.         | BVEC4                 { $$ = ast_bvec4; }
  1332.         | IVEC2                 { $$ = ast_ivec2; }
  1333.         | IVEC3                 { $$ = ast_ivec3; }
  1334.         | IVEC4                 { $$ = ast_ivec4; }
  1335.         | UVEC2                 { $$ = ast_uvec2; }
  1336.         | UVEC3                 { $$ = ast_uvec3; }
  1337.         | UVEC4                 { $$ = ast_uvec4; }
  1338.         | MAT2X2                { $$ = ast_mat2; }
  1339.         | MAT2X3                { $$ = ast_mat2x3; }
  1340.         | MAT2X4                { $$ = ast_mat2x4; }
  1341.         | MAT3X2                { $$ = ast_mat3x2; }
  1342.         | MAT3X3                { $$ = ast_mat3; }
  1343.         | MAT3X4                { $$ = ast_mat3x4; }
  1344.         | MAT4X2                { $$ = ast_mat4x2; }
  1345.         | MAT4X3                { $$ = ast_mat4x3; }
  1346.         | MAT4X4                { $$ = ast_mat4; }
  1347.         | SAMPLER1D             { $$ = ast_sampler1d; }
  1348.         | SAMPLER2D             { $$ = ast_sampler2d; }
  1349.         | SAMPLER2DRECT         { $$ = ast_sampler2drect; }
  1350.         | SAMPLER3D             { $$ = ast_sampler3d; }
  1351.         | SAMPLERCUBE           { $$ = ast_samplercube; }
  1352.         | SAMPLER1DSHADOW       { $$ = ast_sampler1dshadow; }
  1353.         | SAMPLER2DSHADOW       { $$ = ast_sampler2dshadow; }
  1354.         | SAMPLER2DRECTSHADOW   { $$ = ast_sampler2drectshadow; }
  1355.         | SAMPLERCUBESHADOW     { $$ = ast_samplercubeshadow; }
  1356.         | SAMPLER1DARRAY        { $$ = ast_sampler1darray; }
  1357.         | SAMPLER2DARRAY        { $$ = ast_sampler2darray; }
  1358.         | SAMPLER1DARRAYSHADOW  { $$ = ast_sampler1darrayshadow; }
  1359.         | SAMPLER2DARRAYSHADOW  { $$ = ast_sampler2darrayshadow; }
  1360.         | ISAMPLER1D            { $$ = ast_isampler1d; }
  1361.         | ISAMPLER2D            { $$ = ast_isampler2d; }
  1362.         | ISAMPLER3D            { $$ = ast_isampler3d; }
  1363.         | ISAMPLERCUBE          { $$ = ast_isamplercube; }
  1364.         | ISAMPLER1DARRAY       { $$ = ast_isampler1darray; }
  1365.         | ISAMPLER2DARRAY       { $$ = ast_isampler2darray; }
  1366.         | USAMPLER1D            { $$ = ast_usampler1d; }
  1367.         | USAMPLER2D            { $$ = ast_usampler2d; }
  1368.         | USAMPLER3D            { $$ = ast_usampler3d; }
  1369.         | USAMPLERCUBE          { $$ = ast_usamplercube; }
  1370.         | USAMPLER1DARRAY       { $$ = ast_usampler1darray; }
  1371.         | USAMPLER2DARRAY       { $$ = ast_usampler2darray; }
  1372.         ;
  1373.  
  1374. precision_qualifier:
  1375.         HIGHP     {
  1376.                      if (!state->es_shader && state->language_version < 130)
  1377.                         _mesa_glsl_error(& @1, state,
  1378.                                          "precision qualifier forbidden "
  1379.                                          "in %s (1.30 or later "
  1380.                                          "required)\n",
  1381.                                          state->version_string);
  1382.  
  1383.                      $$ = ast_precision_high;
  1384.                   }
  1385.         | MEDIUMP {
  1386.                      if (!state->es_shader && state->language_version < 130)
  1387.                         _mesa_glsl_error(& @1, state,
  1388.                                          "precision qualifier forbidden "
  1389.                                          "in %s (1.30 or later "
  1390.                                          "required)\n",
  1391.                                          state->version_string);
  1392.  
  1393.                      $$ = ast_precision_medium;
  1394.                   }
  1395.         | LOWP    {
  1396.                      if (!state->es_shader && state->language_version < 130)
  1397.                         _mesa_glsl_error(& @1, state,
  1398.                                          "precision qualifier forbidden "
  1399.                                          "in %s (1.30 or later "
  1400.                                          "required)\n",
  1401.                                          state->version_string);
  1402.  
  1403.                      $$ = ast_precision_low;
  1404.                   }
  1405.         ;
  1406.  
  1407. struct_specifier:
  1408.         STRUCT any_identifier '{' struct_declaration_list '}'
  1409.         {
  1410.            void *ctx = state;
  1411.            $$ = new(ctx) ast_struct_specifier($2, $4);
  1412.            $$->set_location(yylloc);
  1413.            state->symbols->add_type($2, glsl_type::void_type);
  1414.         }
  1415.         | STRUCT '{' struct_declaration_list '}'
  1416.         {
  1417.            void *ctx = state;
  1418.            $$ = new(ctx) ast_struct_specifier(NULL, $3);
  1419.            $$->set_location(yylloc);
  1420.         }
  1421.         ;
  1422.  
  1423. struct_declaration_list:
  1424.         struct_declaration
  1425.         {
  1426.            $$ = (ast_node *) $1;
  1427.            $1->link.self_link();
  1428.         }
  1429.         | struct_declaration_list struct_declaration
  1430.         {
  1431.            $$ = (ast_node *) $1;
  1432.            $$->link.insert_before(& $2->link);
  1433.         }
  1434.         ;
  1435.  
  1436. struct_declaration:
  1437.         type_specifier struct_declarator_list ';'
  1438.         {
  1439.            void *ctx = state;
  1440.            ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
  1441.            type->set_location(yylloc);
  1442.  
  1443.            type->specifier = $1;
  1444.            $$ = new(ctx) ast_declarator_list(type);
  1445.            $$->set_location(yylloc);
  1446.  
  1447.            $$->declarations.push_degenerate_list_at_head(& $2->link);
  1448.         }
  1449.         ;
  1450.  
  1451. struct_declarator_list:
  1452.         struct_declarator
  1453.         {
  1454.            $$ = $1;
  1455.            $1->link.self_link();
  1456.         }
  1457.         | struct_declarator_list ',' struct_declarator
  1458.         {
  1459.            $$ = $1;
  1460.            $$->link.insert_before(& $3->link);
  1461.         }
  1462.         ;
  1463.  
  1464. struct_declarator:
  1465.         any_identifier
  1466.         {
  1467.            void *ctx = state;
  1468.            $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
  1469.            $$->set_location(yylloc);
  1470.            state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
  1471.         }
  1472.         | any_identifier '[' constant_expression ']'
  1473.         {
  1474.            void *ctx = state;
  1475.            $$ = new(ctx) ast_declaration($1, true, $3, NULL);
  1476.            $$->set_location(yylloc);
  1477.         }
  1478.         ;
  1479.  
  1480. initializer:
  1481.         assignment_expression
  1482.         ;
  1483.  
  1484. declaration_statement:
  1485.         declaration
  1486.         ;
  1487.  
  1488.         // Grammar Note: labeled statements for SWITCH only; 'goto' is not
  1489.         // supported.
  1490. statement:
  1491.         compound_statement      { $$ = (ast_node *) $1; }
  1492.         | simple_statement
  1493.         ;
  1494.  
  1495. simple_statement:
  1496.         declaration_statement
  1497.         | expression_statement
  1498.         | selection_statement
  1499.         | switch_statement              { $$ = NULL; }
  1500.         | case_label                    { $$ = NULL; }
  1501.         | iteration_statement
  1502.         | jump_statement
  1503.         ;
  1504.  
  1505. compound_statement:
  1506.         '{' '}'
  1507.         {
  1508.            void *ctx = state;
  1509.            $$ = new(ctx) ast_compound_statement(true, NULL);
  1510.            $$->set_location(yylloc);
  1511.         }
  1512.         | '{'
  1513.         {
  1514.            state->symbols->push_scope();
  1515.         }
  1516.         statement_list '}'
  1517.         {
  1518.            void *ctx = state;
  1519.            $$ = new(ctx) ast_compound_statement(true, $3);
  1520.            $$->set_location(yylloc);
  1521.            state->symbols->pop_scope();
  1522.         }
  1523.         ;
  1524.  
  1525. statement_no_new_scope:
  1526.         compound_statement_no_new_scope { $$ = (ast_node *) $1; }
  1527.         | simple_statement
  1528.         ;
  1529.  
  1530. compound_statement_no_new_scope:
  1531.         '{' '}'
  1532.         {
  1533.            void *ctx = state;
  1534.            $$ = new(ctx) ast_compound_statement(false, NULL);
  1535.            $$->set_location(yylloc);
  1536.         }
  1537.         | '{' statement_list '}'
  1538.         {
  1539.            void *ctx = state;
  1540.            $$ = new(ctx) ast_compound_statement(false, $2);
  1541.            $$->set_location(yylloc);
  1542.         }
  1543.         ;
  1544.  
  1545. statement_list:
  1546.         statement
  1547.         {
  1548.            if ($1 == NULL) {
  1549.               _mesa_glsl_error(& @1, state, "<nil> statement\n");
  1550.               assert($1 != NULL);
  1551.            }
  1552.  
  1553.            $$ = $1;
  1554.            $$->link.self_link();
  1555.         }
  1556.         | statement_list statement
  1557.         {
  1558.            if ($2 == NULL) {
  1559.               _mesa_glsl_error(& @2, state, "<nil> statement\n");
  1560.               assert($2 != NULL);
  1561.            }
  1562.            $$ = $1;
  1563.            $$->link.insert_before(& $2->link);
  1564.         }
  1565.         ;
  1566.  
  1567. expression_statement:
  1568.         ';'
  1569.         {
  1570.            void *ctx = state;
  1571.            $$ = new(ctx) ast_expression_statement(NULL);
  1572.            $$->set_location(yylloc);
  1573.         }
  1574.         | expression ';'
  1575.         {
  1576.            void *ctx = state;
  1577.            $$ = new(ctx) ast_expression_statement($1);
  1578.            $$->set_location(yylloc);
  1579.         }
  1580.         ;
  1581.  
  1582. selection_statement:
  1583.         IF '(' expression ')' selection_rest_statement
  1584.         {
  1585.            $$ = new(state) ast_selection_statement($3, $5.then_statement,
  1586.                                                    $5.else_statement);
  1587.            $$->set_location(yylloc);
  1588.         }
  1589.         ;
  1590.  
  1591. selection_rest_statement:
  1592.         statement ELSE statement
  1593.         {
  1594.            $$.then_statement = $1;
  1595.            $$.else_statement = $3;
  1596.         }
  1597.         | statement
  1598.         {
  1599.            $$.then_statement = $1;
  1600.            $$.else_statement = NULL;
  1601.         }
  1602.         ;
  1603.  
  1604. condition:
  1605.         expression
  1606.         {
  1607.            $$ = (ast_node *) $1;
  1608.         }
  1609.         | fully_specified_type any_identifier '=' initializer
  1610.         {
  1611.            void *ctx = state;
  1612.            ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
  1613.            ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
  1614.            decl->set_location(yylloc);
  1615.            declarator->set_location(yylloc);
  1616.  
  1617.            declarator->declarations.push_tail(&decl->link);
  1618.            $$ = declarator;
  1619.         }
  1620.         ;
  1621.  
  1622. switch_statement:
  1623.         SWITCH '(' expression ')' compound_statement
  1624.         ;
  1625.  
  1626. case_label:
  1627.         CASE expression ':'
  1628.         | DEFAULT ':'
  1629.         ;
  1630.  
  1631. iteration_statement:
  1632.         WHILE '(' condition ')' statement_no_new_scope
  1633.         {
  1634.            void *ctx = state;
  1635.            $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
  1636.                                                     NULL, $3, NULL, $5);
  1637.            $$->set_location(yylloc);
  1638.         }
  1639.         | DO statement WHILE '(' expression ')' ';'
  1640.         {
  1641.            void *ctx = state;
  1642.            $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
  1643.                                                     NULL, $5, NULL, $2);
  1644.            $$->set_location(yylloc);
  1645.         }
  1646.         | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
  1647.         {
  1648.            void *ctx = state;
  1649.            $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
  1650.                                                     $3, $4.cond, $4.rest, $6);
  1651.            $$->set_location(yylloc);
  1652.         }
  1653.         ;
  1654.  
  1655. for_init_statement:
  1656.         expression_statement
  1657.         | declaration_statement
  1658.         ;
  1659.  
  1660. conditionopt:
  1661.         condition
  1662.         | /* empty */
  1663.         {
  1664.            $$ = NULL;
  1665.         }
  1666.         ;
  1667.  
  1668. for_rest_statement:
  1669.         conditionopt ';'
  1670.         {
  1671.            $$.cond = $1;
  1672.            $$.rest = NULL;
  1673.         }
  1674.         | conditionopt ';' expression
  1675.         {
  1676.            $$.cond = $1;
  1677.            $$.rest = $3;
  1678.         }
  1679.         ;
  1680.  
  1681.         // Grammar Note: No 'goto'. Gotos are not supported.
  1682. jump_statement:
  1683.         CONTINUE ';'
  1684.         {
  1685.            void *ctx = state;
  1686.            $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
  1687.            $$->set_location(yylloc);
  1688.         }
  1689.         | BREAK ';'
  1690.         {
  1691.            void *ctx = state;
  1692.            $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
  1693.            $$->set_location(yylloc);
  1694.         }
  1695.         | RETURN ';'
  1696.         {
  1697.            void *ctx = state;
  1698.            $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
  1699.            $$->set_location(yylloc);
  1700.         }
  1701.         | RETURN expression ';'
  1702.         {
  1703.            void *ctx = state;
  1704.            $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
  1705.            $$->set_location(yylloc);
  1706.         }
  1707.         | DISCARD ';' // Fragment shader only.
  1708.         {
  1709.            void *ctx = state;
  1710.            $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
  1711.            $$->set_location(yylloc);
  1712.         }
  1713.         ;
  1714.  
  1715. external_declaration:
  1716.         function_definition     { $$ = $1; }
  1717.         | declaration           { $$ = $1; }
  1718.         | pragma_statement      { $$ = NULL; }
  1719.         ;
  1720.  
  1721. function_definition:
  1722.         function_prototype compound_statement_no_new_scope
  1723.         {
  1724.            void *ctx = state;
  1725.            $$ = new(ctx) ast_function_definition();
  1726.            $$->set_location(yylloc);
  1727.            $$->prototype = $1;
  1728.            $$->body = $2;
  1729.  
  1730.            state->symbols->pop_scope();
  1731.         }
  1732.         ;
  1733.