3 * Copyright © 2008, 2009 Intel Corporation
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:
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
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.
33 #include "glsl_parser_extras.h"
34 #include "compiler/glsl_types.h"
35 #include "main/context.h"
38 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
43 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
45 _mesa_glsl_error(loc, st, "%s", msg);
49 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
51 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
54 static bool match_layout_qualifier(const char *s1, const char *s2,
55 _mesa_glsl_parse_state *state)
57 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
59 * "The tokens in any layout-qualifier-id-list ... are not case
60 * sensitive, unless explicitly noted otherwise."
62 * The text "unless explicitly noted otherwise" appears to be
63 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
66 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
69 * "As for other identifiers, they are case sensitive."
71 * So we need to do a case-sensitive or a case-insensitive match,
72 * depending on whether we are compiling for GLSL ES.
75 return strcmp(s1, s2);
77 return strcasecmp(s1, s2);
95 %lex-param {struct _mesa_glsl_parse_state *state}
96 %parse-param {struct _mesa_glsl_parse_state *state}
102 const char *identifier;
104 struct ast_type_qualifier type_qualifier;
107 ast_type_specifier *type_specifier;
108 ast_array_specifier *array_specifier;
109 ast_fully_specified_type *fully_specified_type;
110 ast_function *function;
111 ast_parameter_declarator *parameter_declarator;
112 ast_function_definition *function_definition;
113 ast_compound_statement *compound_statement;
114 ast_expression *expression;
115 ast_declarator_list *declarator_list;
116 ast_struct_specifier *struct_specifier;
117 ast_declaration *declaration;
118 ast_switch_body *switch_body;
119 ast_case_label *case_label;
120 ast_case_label_list *case_label_list;
121 ast_case_statement *case_statement;
122 ast_case_statement_list *case_statement_list;
123 ast_interface_block *interface_block;
124 ast_subroutine_list *subroutine_list;
127 ast_expression *rest;
128 } for_rest_statement;
131 ast_node *then_statement;
132 ast_node *else_statement;
133 } selection_rest_statement;
136 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
137 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
138 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
139 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
140 %token NOPERSPECTIVE FLAT SMOOTH
141 %token MAT2X2 MAT2X3 MAT2X4
142 %token MAT3X2 MAT3X3 MAT3X4
143 %token MAT4X2 MAT4X3 MAT4X4
144 %token DMAT2X2 DMAT2X3 DMAT2X4
145 %token DMAT3X2 DMAT3X3 DMAT3X4
146 %token DMAT4X2 DMAT4X3 DMAT4X4
147 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
148 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
149 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
150 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
151 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
152 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
153 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
154 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
155 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
156 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
157 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
158 %token SAMPLEREXTERNALOES
159 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
160 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
161 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
162 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
163 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
164 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
165 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
166 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
169 %token STRUCT VOID_TOK WHILE
170 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
171 %type <identifier> any_identifier
172 %type <interface_block> instance_name_opt
173 %token <real> FLOATCONSTANT
174 %token <dreal> DOUBLECONSTANT
175 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
176 %token <identifier> FIELD_SELECTION
177 %token LEFT_OP RIGHT_OP
178 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
179 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
180 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
182 %token INVARIANT PRECISE
183 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
185 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
186 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
187 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
188 %token PRAGMA_INVARIANT_ALL
191 /* Reserved words that are not actually used in the grammar.
193 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
194 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
195 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
196 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
198 %token SIZEOF CAST NAMESPACE USING
199 %token RESOURCE PATCH
204 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
206 %type <identifier> variable_identifier
207 %type <node> statement
208 %type <node> statement_list
209 %type <node> simple_statement
210 %type <n> precision_qualifier
211 %type <type_qualifier> type_qualifier
212 %type <type_qualifier> auxiliary_storage_qualifier
213 %type <type_qualifier> storage_qualifier
214 %type <type_qualifier> interpolation_qualifier
215 %type <type_qualifier> layout_qualifier
216 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
217 %type <type_qualifier> interface_block_layout_qualifier
218 %type <type_qualifier> memory_qualifier
219 %type <type_qualifier> subroutine_qualifier
220 %type <subroutine_list> subroutine_type_list
221 %type <type_qualifier> interface_qualifier
222 %type <type_qualifier> uniform_interface_qualifier
223 %type <type_qualifier> buffer_interface_qualifier
224 %type <type_specifier> type_specifier
225 %type <type_specifier> type_specifier_nonarray
226 %type <array_specifier> array_specifier
227 %type <identifier> basic_type_specifier_nonarray
228 %type <fully_specified_type> fully_specified_type
229 %type <function> function_prototype
230 %type <function> function_header
231 %type <function> function_header_with_parameters
232 %type <function> function_declarator
233 %type <parameter_declarator> parameter_declarator
234 %type <parameter_declarator> parameter_declaration
235 %type <type_qualifier> parameter_qualifier
236 %type <type_qualifier> parameter_direction_qualifier
237 %type <type_specifier> parameter_type_specifier
238 %type <function_definition> function_definition
239 %type <compound_statement> compound_statement_no_new_scope
240 %type <compound_statement> compound_statement
241 %type <node> statement_no_new_scope
242 %type <node> expression_statement
243 %type <expression> expression
244 %type <expression> primary_expression
245 %type <expression> assignment_expression
246 %type <expression> conditional_expression
247 %type <expression> logical_or_expression
248 %type <expression> logical_xor_expression
249 %type <expression> logical_and_expression
250 %type <expression> inclusive_or_expression
251 %type <expression> exclusive_or_expression
252 %type <expression> and_expression
253 %type <expression> equality_expression
254 %type <expression> relational_expression
255 %type <expression> shift_expression
256 %type <expression> additive_expression
257 %type <expression> multiplicative_expression
258 %type <expression> unary_expression
259 %type <expression> constant_expression
260 %type <expression> integer_expression
261 %type <expression> postfix_expression
262 %type <expression> function_call_header_with_parameters
263 %type <expression> function_call_header_no_parameters
264 %type <expression> function_call_header
265 %type <expression> function_call_generic
266 %type <expression> function_call_or_method
267 %type <expression> function_call
268 %type <n> assignment_operator
269 %type <n> unary_operator
270 %type <expression> function_identifier
271 %type <node> external_declaration
272 %type <declarator_list> init_declarator_list
273 %type <declarator_list> single_declaration
274 %type <expression> initializer
275 %type <expression> initializer_list
276 %type <node> declaration
277 %type <node> declaration_statement
278 %type <node> jump_statement
279 %type <node> interface_block
280 %type <interface_block> basic_interface_block
281 %type <struct_specifier> struct_specifier
282 %type <declarator_list> struct_declaration_list
283 %type <declarator_list> struct_declaration
284 %type <declaration> struct_declarator
285 %type <declaration> struct_declarator_list
286 %type <declarator_list> member_list
287 %type <declarator_list> member_declaration
288 %type <node> selection_statement
289 %type <selection_rest_statement> selection_rest_statement
290 %type <node> switch_statement
291 %type <switch_body> switch_body
292 %type <case_label_list> case_label_list
293 %type <case_label> case_label
294 %type <case_statement> case_statement
295 %type <case_statement_list> case_statement_list
296 %type <node> iteration_statement
297 %type <node> condition
298 %type <node> conditionopt
299 %type <node> for_init_statement
300 %type <for_rest_statement> for_rest_statement
301 %type <node> layout_defaults
302 %type <node> layout_uniform_defaults
303 %type <node> layout_buffer_defaults
304 %type <node> layout_in_defaults
305 %type <node> layout_out_defaults
311 version_statement extension_statement_list
313 _mesa_glsl_initialize_types(state);
315 external_declaration_list
317 delete state->symbols;
318 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
319 if (state->es_shader) {
320 if (state->stage == MESA_SHADER_FRAGMENT) {
321 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
323 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
324 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
326 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
327 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
328 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
329 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
331 _mesa_glsl_initialize_types(state);
336 /* blank - no #version specified: defaults are already set */
337 | VERSION_TOK INTCONSTANT EOL
339 state->process_version_directive(&@2, $2, NULL);
344 | VERSION_TOK INTCONSTANT any_identifier EOL
346 state->process_version_directive(&@2, $2, $3);
355 | PRAGMA_DEBUG_OFF EOL
356 | PRAGMA_OPTIMIZE_ON EOL
357 | PRAGMA_OPTIMIZE_OFF EOL
358 | PRAGMA_INVARIANT_ALL EOL
360 /* Pragma invariant(all) cannot be used in a fragment shader.
362 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
364 * "It is an error to use this pragma in a fragment shader."
366 if (state->is_version(120, 300) &&
367 state->stage == MESA_SHADER_FRAGMENT) {
368 _mesa_glsl_error(& @1, state,
369 "pragma `invariant(all)' cannot be used "
370 "in a fragment shader.");
371 } else if (!state->is_version(120, 100)) {
372 _mesa_glsl_warning(& @1, state,
373 "pragma `invariant(all)' not supported in %s "
374 "(GLSL ES 1.00 or GLSL 1.20 required)",
375 state->get_version_string());
377 state->all_invariant = true;
382 extension_statement_list:
384 | extension_statement_list extension_statement
394 EXTENSION any_identifier COLON any_identifier EOL
396 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
402 external_declaration_list:
405 /* FINISHME: The NULL test is required because pragmas are set to
406 * FINISHME: NULL. (See production rule for external_declaration.)
409 state->translation_unit.push_tail(& $1->link);
411 | external_declaration_list external_declaration
413 /* FINISHME: The NULL test is required because pragmas are set to
414 * FINISHME: NULL. (See production rule for external_declaration.)
417 state->translation_unit.push_tail(& $2->link);
419 | external_declaration_list extension_statement {
420 if (!state->allow_extension_directive_midshader) {
421 _mesa_glsl_error(& @2, state,
422 "#extension directive is not allowed "
423 "in the middle of a shader");
438 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
439 $$->set_location(@1);
440 $$->primary_expression.identifier = $1;
445 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
446 $$->set_location(@1);
447 $$->primary_expression.int_constant = $1;
452 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
453 $$->set_location(@1);
454 $$->primary_expression.uint_constant = $1;
459 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
460 $$->set_location(@1);
461 $$->primary_expression.float_constant = $1;
466 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
467 $$->set_location(@1);
468 $$->primary_expression.double_constant = $1;
473 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
474 $$->set_location(@1);
475 $$->primary_expression.bool_constant = $1;
485 | postfix_expression '[' integer_expression ']'
488 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
489 $$->set_location_range(@1, @4);
495 | postfix_expression DOT_TOK FIELD_SELECTION
498 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
499 $$->set_location_range(@1, @3);
500 $$->primary_expression.identifier = $3;
502 | postfix_expression INC_OP
505 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
506 $$->set_location_range(@1, @2);
508 | postfix_expression DEC_OP
511 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
512 $$->set_location_range(@1, @2);
521 function_call_or_method
524 function_call_or_method:
525 function_call_generic
528 function_call_generic:
529 function_call_header_with_parameters ')'
530 | function_call_header_no_parameters ')'
533 function_call_header_no_parameters:
534 function_call_header VOID_TOK
535 | function_call_header
538 function_call_header_with_parameters:
539 function_call_header assignment_expression
542 $$->set_location(@1);
543 $$->expressions.push_tail(& $2->link);
545 | function_call_header_with_parameters ',' assignment_expression
548 $$->set_location(@1);
549 $$->expressions.push_tail(& $3->link);
553 // Grammar Note: Constructors look like functions, but lexical
554 // analysis recognized most of them as keywords. They are now
555 // recognized through "type_specifier".
556 function_call_header:
557 function_identifier '('
564 $$ = new(ctx) ast_function_expression($1);
565 $$->set_location(@1);
570 $$ = new(ctx) ast_function_expression($1);
571 $$->set_location(@1);
575 // Grammar Note: Constructors look like methods, but lexical
576 // analysis recognized most of them as keywords. They are now
577 // recognized through "type_specifier".
579 // Grammar Note: No traditional style type casts.
582 | INC_OP unary_expression
585 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
586 $$->set_location(@1);
588 | DEC_OP unary_expression
591 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
592 $$->set_location(@1);
594 | unary_operator unary_expression
597 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
598 $$->set_location_range(@1, @2);
602 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
604 '+' { $$ = ast_plus; }
605 | '-' { $$ = ast_neg; }
606 | '!' { $$ = ast_logic_not; }
607 | '~' { $$ = ast_bit_not; }
610 multiplicative_expression:
612 | multiplicative_expression '*' unary_expression
615 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
616 $$->set_location_range(@1, @3);
618 | multiplicative_expression '/' unary_expression
621 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
622 $$->set_location_range(@1, @3);
624 | multiplicative_expression '%' unary_expression
627 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
628 $$->set_location_range(@1, @3);
633 multiplicative_expression
634 | additive_expression '+' multiplicative_expression
637 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
638 $$->set_location_range(@1, @3);
640 | additive_expression '-' multiplicative_expression
643 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
644 $$->set_location_range(@1, @3);
650 | shift_expression LEFT_OP additive_expression
653 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
654 $$->set_location_range(@1, @3);
656 | shift_expression RIGHT_OP additive_expression
659 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
660 $$->set_location_range(@1, @3);
664 relational_expression:
666 | relational_expression '<' shift_expression
669 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
670 $$->set_location_range(@1, @3);
672 | relational_expression '>' shift_expression
675 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
676 $$->set_location_range(@1, @3);
678 | relational_expression LE_OP shift_expression
681 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
682 $$->set_location_range(@1, @3);
684 | relational_expression GE_OP shift_expression
687 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
688 $$->set_location_range(@1, @3);
693 relational_expression
694 | equality_expression EQ_OP relational_expression
697 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
698 $$->set_location_range(@1, @3);
700 | equality_expression NE_OP relational_expression
703 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
704 $$->set_location_range(@1, @3);
710 | and_expression '&' equality_expression
713 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
714 $$->set_location_range(@1, @3);
718 exclusive_or_expression:
720 | exclusive_or_expression '^' and_expression
723 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
724 $$->set_location_range(@1, @3);
728 inclusive_or_expression:
729 exclusive_or_expression
730 | inclusive_or_expression '|' exclusive_or_expression
733 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
734 $$->set_location_range(@1, @3);
738 logical_and_expression:
739 inclusive_or_expression
740 | logical_and_expression AND_OP inclusive_or_expression
743 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
744 $$->set_location_range(@1, @3);
748 logical_xor_expression:
749 logical_and_expression
750 | logical_xor_expression XOR_OP logical_and_expression
753 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
754 $$->set_location_range(@1, @3);
758 logical_or_expression:
759 logical_xor_expression
760 | logical_or_expression OR_OP logical_xor_expression
763 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
764 $$->set_location_range(@1, @3);
768 conditional_expression:
769 logical_or_expression
770 | logical_or_expression '?' expression ':' assignment_expression
773 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
774 $$->set_location_range(@1, @5);
778 assignment_expression:
779 conditional_expression
780 | unary_expression assignment_operator assignment_expression
783 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
784 $$->set_location_range(@1, @3);
789 '=' { $$ = ast_assign; }
790 | MUL_ASSIGN { $$ = ast_mul_assign; }
791 | DIV_ASSIGN { $$ = ast_div_assign; }
792 | MOD_ASSIGN { $$ = ast_mod_assign; }
793 | ADD_ASSIGN { $$ = ast_add_assign; }
794 | SUB_ASSIGN { $$ = ast_sub_assign; }
795 | LEFT_ASSIGN { $$ = ast_ls_assign; }
796 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
797 | AND_ASSIGN { $$ = ast_and_assign; }
798 | XOR_ASSIGN { $$ = ast_xor_assign; }
799 | OR_ASSIGN { $$ = ast_or_assign; }
803 assignment_expression
807 | expression ',' assignment_expression
810 if ($1->oper != ast_sequence) {
811 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
812 $$->set_location_range(@1, @3);
813 $$->expressions.push_tail(& $1->link);
818 $$->expressions.push_tail(& $3->link);
823 conditional_expression
827 function_prototype ';'
829 state->symbols->pop_scope();
832 | init_declarator_list ';'
836 | PRECISION precision_qualifier type_specifier ';'
838 $3->default_precision = $2;
848 function_declarator ')'
853 | function_header_with_parameters
856 function_header_with_parameters:
857 function_header parameter_declaration
860 $$->parameters.push_tail(& $2->link);
862 | function_header_with_parameters ',' parameter_declaration
865 $$->parameters.push_tail(& $3->link);
870 fully_specified_type variable_identifier '('
873 $$ = new(ctx) ast_function();
874 $$->set_location(@2);
875 $$->return_type = $1;
878 if ($1->qualifier.flags.q.subroutine) {
879 /* add type for IDENTIFIER search */
880 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
882 state->symbols->add_function(new(state) ir_function($2));
883 state->symbols->push_scope();
887 parameter_declarator:
888 type_specifier any_identifier
891 $$ = new(ctx) ast_parameter_declarator();
892 $$->set_location_range(@1, @2);
893 $$->type = new(ctx) ast_fully_specified_type();
894 $$->type->set_location(@1);
895 $$->type->specifier = $1;
897 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
899 | type_specifier any_identifier array_specifier
902 $$ = new(ctx) ast_parameter_declarator();
903 $$->set_location_range(@1, @3);
904 $$->type = new(ctx) ast_fully_specified_type();
905 $$->type->set_location(@1);
906 $$->type->specifier = $1;
908 $$->array_specifier = $3;
909 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
913 parameter_declaration:
914 parameter_qualifier parameter_declarator
917 $$->type->qualifier = $1;
919 | parameter_qualifier parameter_type_specifier
922 $$ = new(ctx) ast_parameter_declarator();
923 $$->set_location(@2);
924 $$->type = new(ctx) ast_fully_specified_type();
925 $$->type->set_location_range(@1, @2);
926 $$->type->qualifier = $1;
927 $$->type->specifier = $2;
934 memset(& $$, 0, sizeof($$));
936 | CONST_TOK parameter_qualifier
938 if ($2.flags.q.constant)
939 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
942 $$.flags.q.constant = 1;
944 | PRECISE parameter_qualifier
946 if ($2.flags.q.precise)
947 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
950 $$.flags.q.precise = 1;
952 | parameter_direction_qualifier parameter_qualifier
954 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
955 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
957 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
958 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
962 $$.merge_qualifier(&@1, state, $2, false);
964 | precision_qualifier parameter_qualifier
966 if ($2.precision != ast_precision_none)
967 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
969 if (!state->has_420pack_or_es31() &&
971 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
976 | memory_qualifier parameter_qualifier
979 $$.merge_qualifier(&@1, state, $2, false);
982 parameter_direction_qualifier:
985 memset(& $$, 0, sizeof($$));
990 memset(& $$, 0, sizeof($$));
995 memset(& $$, 0, sizeof($$));
1001 parameter_type_specifier:
1005 init_declarator_list:
1007 | init_declarator_list ',' any_identifier
1010 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1011 decl->set_location(@3);
1014 $$->declarations.push_tail(&decl->link);
1015 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1017 | init_declarator_list ',' any_identifier array_specifier
1020 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1021 decl->set_location_range(@3, @4);
1024 $$->declarations.push_tail(&decl->link);
1025 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1027 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1030 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1031 decl->set_location_range(@3, @4);
1034 $$->declarations.push_tail(&decl->link);
1035 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1037 | init_declarator_list ',' any_identifier '=' initializer
1040 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1041 decl->set_location(@3);
1044 $$->declarations.push_tail(&decl->link);
1045 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1049 // Grammar Note: No 'enum', or 'typedef'.
1051 fully_specified_type
1054 /* Empty declaration list is valid. */
1055 $$ = new(ctx) ast_declarator_list($1);
1056 $$->set_location(@1);
1058 | fully_specified_type any_identifier
1061 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1062 decl->set_location(@2);
1064 $$ = new(ctx) ast_declarator_list($1);
1065 $$->set_location_range(@1, @2);
1066 $$->declarations.push_tail(&decl->link);
1067 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1069 | fully_specified_type any_identifier array_specifier
1072 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1073 decl->set_location_range(@2, @3);
1075 $$ = new(ctx) ast_declarator_list($1);
1076 $$->set_location_range(@1, @3);
1077 $$->declarations.push_tail(&decl->link);
1078 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1080 | fully_specified_type any_identifier array_specifier '=' initializer
1083 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1084 decl->set_location_range(@2, @3);
1086 $$ = new(ctx) ast_declarator_list($1);
1087 $$->set_location_range(@1, @3);
1088 $$->declarations.push_tail(&decl->link);
1089 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1091 | fully_specified_type any_identifier '=' initializer
1094 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1095 decl->set_location(@2);
1097 $$ = new(ctx) ast_declarator_list($1);
1098 $$->set_location_range(@1, @2);
1099 $$->declarations.push_tail(&decl->link);
1100 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1102 | INVARIANT variable_identifier
1105 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1106 decl->set_location(@2);
1108 $$ = new(ctx) ast_declarator_list(NULL);
1109 $$->set_location_range(@1, @2);
1110 $$->invariant = true;
1112 $$->declarations.push_tail(&decl->link);
1114 | PRECISE variable_identifier
1117 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1118 decl->set_location(@2);
1120 $$ = new(ctx) ast_declarator_list(NULL);
1121 $$->set_location_range(@1, @2);
1124 $$->declarations.push_tail(&decl->link);
1128 fully_specified_type:
1132 $$ = new(ctx) ast_fully_specified_type();
1133 $$->set_location(@1);
1136 | type_qualifier type_specifier
1139 $$ = new(ctx) ast_fully_specified_type();
1140 $$->set_location_range(@1, @2);
1143 if ($$->specifier->structure != NULL &&
1144 $$->specifier->structure->is_declaration) {
1145 $$->specifier->structure->layout = &$$->qualifier;
1151 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1157 layout_qualifier_id_list:
1159 | layout_qualifier_id_list ',' layout_qualifier_id
1162 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1168 layout_qualifier_id:
1171 memset(& $$, 0, sizeof($$));
1173 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1174 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1175 state->is_version(150, 0))) {
1176 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1177 $$.flags.q.origin_upper_left = 1;
1178 } else if (match_layout_qualifier($1, "pixel_center_integer",
1180 $$.flags.q.pixel_center_integer = 1;
1183 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1184 _mesa_glsl_warning(& @1, state,
1185 "GL_ARB_fragment_coord_conventions layout "
1186 "identifier `%s' used", $1);
1190 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1192 (state->AMD_conservative_depth_enable ||
1193 state->ARB_conservative_depth_enable ||
1194 state->is_version(420, 0))) {
1195 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1196 $$.flags.q.depth_any = 1;
1197 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1198 $$.flags.q.depth_greater = 1;
1199 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1200 $$.flags.q.depth_less = 1;
1201 } else if (match_layout_qualifier($1, "depth_unchanged",
1203 $$.flags.q.depth_unchanged = 1;
1206 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1207 _mesa_glsl_warning(& @1, state,
1208 "GL_AMD_conservative_depth "
1209 "layout qualifier `%s' is used", $1);
1211 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1212 _mesa_glsl_warning(& @1, state,
1213 "GL_ARB_conservative_depth "
1214 "layout qualifier `%s' is used", $1);
1218 /* See also interface_block_layout_qualifier. */
1219 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1220 if (match_layout_qualifier($1, "std140", state) == 0) {
1221 $$.flags.q.std140 = 1;
1222 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1223 $$.flags.q.shared = 1;
1224 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1225 $$.flags.q.std430 = 1;
1226 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1227 $$.flags.q.column_major = 1;
1228 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1229 * below in the interface_block_layout_qualifier rule.
1231 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1234 * Also, this takes care of alternate capitalizations of
1235 * "row_major" (which is necessary because layout qualifiers
1236 * are case-insensitive in desktop GLSL).
1238 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1239 $$.flags.q.row_major = 1;
1240 /* "packed" is a reserved word in GLSL, and its token is
1241 * parsed below in the interface_block_layout_qualifier rule.
1242 * However, we must take care of alternate capitalizations of
1243 * "packed", because layout qualifiers are case-insensitive
1246 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1247 $$.flags.q.packed = 1;
1250 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1251 _mesa_glsl_warning(& @1, state,
1252 "#version 140 / GL_ARB_uniform_buffer_object "
1253 "layout qualifier `%s' is used", $1);
1257 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1259 static const struct {
1263 { "points", GL_POINTS },
1264 { "lines", GL_LINES },
1265 { "lines_adjacency", GL_LINES_ADJACENCY },
1266 { "line_strip", GL_LINE_STRIP },
1267 { "triangles", GL_TRIANGLES },
1268 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1269 { "triangle_strip", GL_TRIANGLE_STRIP },
1271 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1272 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1273 $$.flags.q.prim_type = 1;
1274 $$.prim_type = map[i].e;
1279 if ($$.flags.i && !state->has_geometry_shader()) {
1280 _mesa_glsl_error(& @1, state, "#version 150 layout "
1281 "qualifier `%s' used", $1);
1285 /* Layout qualifiers for ARB_shader_image_load_store. */
1286 if (state->ARB_shader_image_load_store_enable ||
1287 state->is_version(420, 310)) {
1289 static const struct {
1292 glsl_base_type base_type;
1293 /** Minimum desktop GLSL version required for the image
1294 * format. Use 130 if already present in the original
1297 unsigned required_glsl;
1298 /** Minimum GLSL ES version required for the image format. */
1299 unsigned required_essl;
1301 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1302 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1303 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1304 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1305 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1306 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1307 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1308 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1309 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1310 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1311 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1312 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1313 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1314 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1315 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1316 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1317 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1318 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1319 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1320 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1321 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1322 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1323 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1324 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1325 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1326 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1327 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1328 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1329 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1330 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1331 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1332 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1333 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1334 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1335 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1336 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1337 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1338 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1339 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1342 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1343 if (state->is_version(map[i].required_glsl,
1344 map[i].required_essl) &&
1345 match_layout_qualifier($1, map[i].name, state) == 0) {
1346 $$.flags.q.explicit_image_format = 1;
1347 $$.image_format = map[i].format;
1348 $$.image_base_type = map[i].base_type;
1355 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1356 /* From section 4.4.1.3 of the GLSL 4.50 specification
1357 * (Fragment Shader Inputs):
1359 * "Fragment shaders also allow the following layout
1360 * qualifier on in only (not with variable declarations)
1361 * layout-qualifier-id
1362 * early_fragment_tests
1365 if (state->stage != MESA_SHADER_FRAGMENT) {
1366 _mesa_glsl_error(& @1, state,
1367 "early_fragment_tests layout qualifier only "
1368 "valid in fragment shaders");
1371 $$.flags.q.early_fragment_tests = 1;
1375 /* Layout qualifiers for tessellation evaluation shaders. */
1381 /* triangles already parsed by gs-specific code */
1382 { "quads", GL_QUADS },
1383 { "isolines", GL_ISOLINES },
1385 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1386 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1387 $$.flags.q.prim_type = 1;
1388 $$.prim_type = map[i].e;
1394 !state->ARB_tessellation_shader_enable &&
1395 !state->is_version(400, 0)) {
1396 _mesa_glsl_error(& @1, state,
1397 "primitive mode qualifier `%s' requires "
1398 "GLSL 4.00 or ARB_tessellation_shader", $1);
1406 { "equal_spacing", GL_EQUAL },
1407 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1408 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1410 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1411 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1412 $$.flags.q.vertex_spacing = 1;
1413 $$.vertex_spacing = map[i].e;
1419 !state->ARB_tessellation_shader_enable &&
1420 !state->is_version(400, 0)) {
1421 _mesa_glsl_error(& @1, state,
1422 "vertex spacing qualifier `%s' requires "
1423 "GLSL 4.00 or ARB_tessellation_shader", $1);
1427 if (match_layout_qualifier($1, "cw", state) == 0) {
1428 $$.flags.q.ordering = 1;
1429 $$.ordering = GL_CW;
1430 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1431 $$.flags.q.ordering = 1;
1432 $$.ordering = GL_CCW;
1436 !state->ARB_tessellation_shader_enable &&
1437 !state->is_version(400, 0)) {
1438 _mesa_glsl_error(& @1, state,
1439 "ordering qualifier `%s' requires "
1440 "GLSL 4.00 or ARB_tessellation_shader", $1);
1444 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1445 $$.flags.q.point_mode = 1;
1446 $$.point_mode = true;
1450 !state->ARB_tessellation_shader_enable &&
1451 !state->is_version(400, 0)) {
1452 _mesa_glsl_error(& @1, state,
1453 "qualifier `point_mode' requires "
1454 "GLSL 4.00 or ARB_tessellation_shader");
1459 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1464 | any_identifier '=' constant_expression
1466 memset(& $$, 0, sizeof($$));
1469 if ($3->oper != ast_int_constant &&
1470 $3->oper != ast_uint_constant &&
1471 !state->has_enhanced_layouts()) {
1472 _mesa_glsl_error(& @1, state,
1473 "compile-time constant expressions require "
1474 "GLSL 4.40 or ARB_enhanced_layouts");
1477 if (match_layout_qualifier("align", $1, state) == 0) {
1478 if (!state->has_enhanced_layouts()) {
1479 _mesa_glsl_error(& @1, state,
1480 "align qualifier requires "
1481 "GLSL 4.40 or ARB_enhanced_layouts");
1483 $$.flags.q.explicit_align = 1;
1488 if (match_layout_qualifier("location", $1, state) == 0) {
1489 $$.flags.q.explicit_location = 1;
1491 if ($$.flags.q.attribute == 1 &&
1492 state->ARB_explicit_attrib_location_warn) {
1493 _mesa_glsl_warning(& @1, state,
1494 "GL_ARB_explicit_attrib_location layout "
1495 "identifier `%s' used", $1);
1500 if (match_layout_qualifier("index", $1, state) == 0) {
1501 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1502 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1506 $$.flags.q.explicit_index = 1;
1510 if ((state->has_420pack_or_es31() ||
1511 state->has_atomic_counters() ||
1512 state->has_shader_storage_buffer_objects()) &&
1513 match_layout_qualifier("binding", $1, state) == 0) {
1514 $$.flags.q.explicit_binding = 1;
1518 if ((state->has_atomic_counters() ||
1519 state->has_enhanced_layouts()) &&
1520 match_layout_qualifier("offset", $1, state) == 0) {
1521 $$.flags.q.explicit_offset = 1;
1525 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1526 $$.flags.q.max_vertices = 1;
1527 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1528 if (!state->has_geometry_shader()) {
1529 _mesa_glsl_error(& @3, state,
1530 "#version 150 max_vertices qualifier "
1535 if (state->stage == MESA_SHADER_GEOMETRY) {
1536 if (match_layout_qualifier("stream", $1, state) == 0 &&
1537 state->check_explicit_attrib_stream_allowed(& @3)) {
1538 $$.flags.q.stream = 1;
1539 $$.flags.q.explicit_stream = 1;
1544 static const char * const local_size_qualifiers[3] = {
1549 for (int i = 0; i < 3; i++) {
1550 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1552 if (!state->has_compute_shader()) {
1553 _mesa_glsl_error(& @3, state,
1554 "%s qualifier requires GLSL 4.30 or "
1555 "GLSL ES 3.10 or ARB_compute_shader",
1556 local_size_qualifiers[i]);
1559 $$.flags.q.local_size |= (1 << i);
1560 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1566 if (match_layout_qualifier("invocations", $1, state) == 0) {
1567 $$.flags.q.invocations = 1;
1568 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1569 if (!state->is_version(400, 0) &&
1570 !state->ARB_gpu_shader5_enable) {
1571 _mesa_glsl_error(& @3, state,
1572 "GL_ARB_gpu_shader5 invocations "
1573 "qualifier specified", $3);
1577 /* Layout qualifiers for tessellation control shaders. */
1578 if (match_layout_qualifier("vertices", $1, state) == 0) {
1579 $$.flags.q.vertices = 1;
1580 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1581 if (!state->ARB_tessellation_shader_enable &&
1582 !state->is_version(400, 0)) {
1583 _mesa_glsl_error(& @1, state,
1584 "vertices qualifier requires GLSL 4.00 or "
1585 "ARB_tessellation_shader");
1589 /* If the identifier didn't match any known layout identifiers,
1593 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1598 | interface_block_layout_qualifier
1601 /* Layout qualifiers for ARB_uniform_buffer_object. */
1602 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1603 _mesa_glsl_error(& @1, state,
1604 "#version 140 / GL_ARB_uniform_buffer_object "
1605 "layout qualifier `%s' is used", $1);
1606 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1607 _mesa_glsl_warning(& @1, state,
1608 "#version 140 / GL_ARB_uniform_buffer_object "
1609 "layout qualifier `%s' is used", $1);
1614 /* This is a separate language rule because we parse these as tokens
1615 * (due to them being reserved keywords) instead of identifiers like
1616 * most qualifiers. See the any_identifier path of
1617 * layout_qualifier_id for the others.
1619 * Note that since layout qualifiers are case-insensitive in desktop
1620 * GLSL, all of these qualifiers need to be handled as identifiers as
1621 * well (by the any_identifier path of layout_qualifier_id).
1623 interface_block_layout_qualifier:
1626 memset(& $$, 0, sizeof($$));
1627 $$.flags.q.row_major = 1;
1631 memset(& $$, 0, sizeof($$));
1632 $$.flags.q.packed = 1;
1636 memset(& $$, 0, sizeof($$));
1637 $$.flags.q.shared = 1;
1641 subroutine_qualifier:
1644 memset(& $$, 0, sizeof($$));
1645 $$.flags.q.subroutine = 1;
1647 | SUBROUTINE '(' subroutine_type_list ')'
1649 memset(& $$, 0, sizeof($$));
1650 $$.flags.q.subroutine_def = 1;
1651 $$.subroutine_list = $3;
1655 subroutine_type_list:
1659 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1660 decl->set_location(@1);
1662 $$ = new(ctx) ast_subroutine_list();
1663 $$->declarations.push_tail(&decl->link);
1665 | subroutine_type_list ',' any_identifier
1668 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1669 decl->set_location(@3);
1672 $$->declarations.push_tail(&decl->link);
1676 interpolation_qualifier:
1679 memset(& $$, 0, sizeof($$));
1680 $$.flags.q.smooth = 1;
1684 memset(& $$, 0, sizeof($$));
1685 $$.flags.q.flat = 1;
1689 memset(& $$, 0, sizeof($$));
1690 $$.flags.q.noperspective = 1;
1695 /* Single qualifiers */
1698 memset(& $$, 0, sizeof($$));
1699 $$.flags.q.invariant = 1;
1703 memset(& $$, 0, sizeof($$));
1704 $$.flags.q.precise = 1;
1706 | auxiliary_storage_qualifier
1708 | interpolation_qualifier
1711 | subroutine_qualifier
1712 | precision_qualifier
1714 memset(&$$, 0, sizeof($$));
1718 /* Multiple qualifiers:
1719 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1720 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1722 * invariant interpolation auxiliary storage precision ...or...
1723 * layout storage precision
1725 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1726 * side don't contain any that must appear on the left hand side.
1727 * For example, when processing a storage qualifier, we check that there are
1728 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1730 | PRECISE type_qualifier
1732 if ($2.flags.q.precise)
1733 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1736 $$.flags.q.precise = 1;
1738 | INVARIANT type_qualifier
1740 if ($2.flags.q.invariant)
1741 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1743 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1744 _mesa_glsl_error(&@1, state,
1745 "\"invariant\" must come after \"precise\"");
1748 $$.flags.q.invariant = 1;
1750 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1752 * "Only variables output from a shader can be candidates for invariance.
1753 * This includes user-defined output variables and the built-in output
1754 * variables. As only outputs can be declared as invariant, an invariant
1755 * output from one shader stage will still match an input of a subsequent
1756 * stage without the input being declared as invariant."
1758 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1759 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1761 | interpolation_qualifier type_qualifier
1763 /* Section 4.3 of the GLSL 1.40 specification states:
1764 * "...qualified with one of these interpolation qualifiers"
1766 * GLSL 1.30 claims to allow "one or more", but insists that:
1767 * "These interpolation qualifiers may only precede the qualifiers in,
1768 * centroid in, out, or centroid out in a declaration."
1770 * ...which means that e.g. smooth can't precede smooth, so there can be
1771 * only one after all, and the 1.40 text is a clarification, not a change.
1773 if ($2.has_interpolation())
1774 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1776 if (!state->has_420pack_or_es31() &&
1777 ($2.flags.q.precise || $2.flags.q.invariant)) {
1778 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1779 "after \"precise\" or \"invariant\"");
1783 $$.merge_qualifier(&@1, state, $2, false);
1785 | layout_qualifier type_qualifier
1787 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1788 * appear no later than auxiliary storage qualifiers. There is no
1789 * particularly clear spec language mandating this, but in all examples
1790 * the layout qualifier precedes the storage qualifier.
1792 * We allow combinations of layout with interpolation, invariant or
1793 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1794 * There is no clear spec guidance on this either.
1796 if (!state->has_420pack_or_es31() && $2.has_layout())
1797 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1800 $$.merge_qualifier(&@1, state, $2, false);
1802 | subroutine_qualifier type_qualifier
1805 $$.merge_qualifier(&@1, state, $2, false);
1807 | auxiliary_storage_qualifier type_qualifier
1809 if ($2.has_auxiliary_storage()) {
1810 _mesa_glsl_error(&@1, state,
1811 "duplicate auxiliary storage qualifier (centroid or sample)");
1814 if (!state->has_420pack_or_es31() &&
1815 ($2.flags.q.precise || $2.flags.q.invariant ||
1816 $2.has_interpolation() || $2.has_layout())) {
1817 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1818 "just before storage qualifiers");
1821 $$.merge_qualifier(&@1, state, $2, false);
1823 | storage_qualifier type_qualifier
1825 /* Section 4.3 of the GLSL 1.20 specification states:
1826 * "Variable declarations may have a storage qualifier specified..."
1827 * 1.30 clarifies this to "may have one storage qualifier".
1829 if ($2.has_storage())
1830 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1832 if (!state->has_420pack_or_es31() &&
1833 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1834 $2.has_layout() || $2.has_auxiliary_storage())) {
1835 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1836 "precise, invariant, interpolation, layout and auxiliary "
1837 "storage qualifiers");
1841 $$.merge_qualifier(&@1, state, $2, false);
1843 | precision_qualifier type_qualifier
1845 if ($2.precision != ast_precision_none)
1846 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1848 if (!(state->has_420pack_or_es31()) &&
1850 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1855 | memory_qualifier type_qualifier
1858 $$.merge_qualifier(&@1, state, $2, false);
1862 auxiliary_storage_qualifier:
1865 memset(& $$, 0, sizeof($$));
1866 $$.flags.q.centroid = 1;
1870 memset(& $$, 0, sizeof($$));
1871 $$.flags.q.sample = 1;
1875 memset(& $$, 0, sizeof($$));
1876 $$.flags.q.patch = 1;
1882 memset(& $$, 0, sizeof($$));
1883 $$.flags.q.constant = 1;
1887 memset(& $$, 0, sizeof($$));
1888 $$.flags.q.attribute = 1;
1892 memset(& $$, 0, sizeof($$));
1893 $$.flags.q.varying = 1;
1897 memset(& $$, 0, sizeof($$));
1902 memset(& $$, 0, sizeof($$));
1905 if (state->stage == MESA_SHADER_GEOMETRY &&
1906 state->has_explicit_attrib_stream()) {
1907 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1910 * "If the block or variable is declared with the stream
1911 * identifier, it is associated with the specified stream;
1912 * otherwise, it is associated with the current default stream."
1914 $$.flags.q.stream = 1;
1915 $$.flags.q.explicit_stream = 0;
1916 $$.stream = state->out_qualifier->stream;
1921 memset(& $$, 0, sizeof($$));
1922 $$.flags.q.uniform = 1;
1926 memset(& $$, 0, sizeof($$));
1927 $$.flags.q.buffer = 1;
1931 memset(& $$, 0, sizeof($$));
1932 $$.flags.q.shared_storage = 1;
1939 memset(& $$, 0, sizeof($$));
1940 $$.flags.q.coherent = 1;
1944 memset(& $$, 0, sizeof($$));
1945 $$.flags.q._volatile = 1;
1949 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1950 memset(& $$, 0, sizeof($$));
1951 $$.flags.q.restrict_flag = 1;
1955 memset(& $$, 0, sizeof($$));
1956 $$.flags.q.read_only = 1;
1960 memset(& $$, 0, sizeof($$));
1961 $$.flags.q.write_only = 1;
1969 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
1970 ast_unsized_array_dim, NULL,
1972 $$->set_location_range(@1, @2);
1974 | '[' constant_expression ']'
1977 $$ = new(ctx) ast_array_specifier(@1, $2);
1978 $$->set_location_range(@1, @3);
1980 | array_specifier '[' ']'
1985 if (state->check_arrays_of_arrays_allowed(& @1)) {
1986 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
1990 | array_specifier '[' constant_expression ']'
1994 if (state->check_arrays_of_arrays_allowed(& @1)) {
1995 $$->add_dimension($3);
2001 type_specifier_nonarray
2002 | type_specifier_nonarray array_specifier
2005 $$->array_specifier = $2;
2009 type_specifier_nonarray:
2010 basic_type_specifier_nonarray
2013 $$ = new(ctx) ast_type_specifier($1);
2014 $$->set_location(@1);
2019 $$ = new(ctx) ast_type_specifier($1);
2020 $$->set_location(@1);
2025 $$ = new(ctx) ast_type_specifier($1);
2026 $$->set_location(@1);
2030 basic_type_specifier_nonarray:
2031 VOID_TOK { $$ = "void"; }
2032 | FLOAT_TOK { $$ = "float"; }
2033 | DOUBLE_TOK { $$ = "double"; }
2034 | INT_TOK { $$ = "int"; }
2035 | UINT_TOK { $$ = "uint"; }
2036 | BOOL_TOK { $$ = "bool"; }
2037 | VEC2 { $$ = "vec2"; }
2038 | VEC3 { $$ = "vec3"; }
2039 | VEC4 { $$ = "vec4"; }
2040 | BVEC2 { $$ = "bvec2"; }
2041 | BVEC3 { $$ = "bvec3"; }
2042 | BVEC4 { $$ = "bvec4"; }
2043 | IVEC2 { $$ = "ivec2"; }
2044 | IVEC3 { $$ = "ivec3"; }
2045 | IVEC4 { $$ = "ivec4"; }
2046 | UVEC2 { $$ = "uvec2"; }
2047 | UVEC3 { $$ = "uvec3"; }
2048 | UVEC4 { $$ = "uvec4"; }
2049 | DVEC2 { $$ = "dvec2"; }
2050 | DVEC3 { $$ = "dvec3"; }
2051 | DVEC4 { $$ = "dvec4"; }
2052 | MAT2X2 { $$ = "mat2"; }
2053 | MAT2X3 { $$ = "mat2x3"; }
2054 | MAT2X4 { $$ = "mat2x4"; }
2055 | MAT3X2 { $$ = "mat3x2"; }
2056 | MAT3X3 { $$ = "mat3"; }
2057 | MAT3X4 { $$ = "mat3x4"; }
2058 | MAT4X2 { $$ = "mat4x2"; }
2059 | MAT4X3 { $$ = "mat4x3"; }
2060 | MAT4X4 { $$ = "mat4"; }
2061 | DMAT2X2 { $$ = "dmat2"; }
2062 | DMAT2X3 { $$ = "dmat2x3"; }
2063 | DMAT2X4 { $$ = "dmat2x4"; }
2064 | DMAT3X2 { $$ = "dmat3x2"; }
2065 | DMAT3X3 { $$ = "dmat3"; }
2066 | DMAT3X4 { $$ = "dmat3x4"; }
2067 | DMAT4X2 { $$ = "dmat4x2"; }
2068 | DMAT4X3 { $$ = "dmat4x3"; }
2069 | DMAT4X4 { $$ = "dmat4"; }
2070 | SAMPLER1D { $$ = "sampler1D"; }
2071 | SAMPLER2D { $$ = "sampler2D"; }
2072 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2073 | SAMPLER3D { $$ = "sampler3D"; }
2074 | SAMPLERCUBE { $$ = "samplerCube"; }
2075 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2076 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2077 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2078 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2079 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2080 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2081 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2082 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2083 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2084 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2085 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2086 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2087 | ISAMPLER1D { $$ = "isampler1D"; }
2088 | ISAMPLER2D { $$ = "isampler2D"; }
2089 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2090 | ISAMPLER3D { $$ = "isampler3D"; }
2091 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2092 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2093 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2094 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2095 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2096 | USAMPLER1D { $$ = "usampler1D"; }
2097 | USAMPLER2D { $$ = "usampler2D"; }
2098 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2099 | USAMPLER3D { $$ = "usampler3D"; }
2100 | USAMPLERCUBE { $$ = "usamplerCube"; }
2101 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2102 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2103 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2104 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2105 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2106 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2107 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2108 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2109 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2110 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2111 | IMAGE1D { $$ = "image1D"; }
2112 | IMAGE2D { $$ = "image2D"; }
2113 | IMAGE3D { $$ = "image3D"; }
2114 | IMAGE2DRECT { $$ = "image2DRect"; }
2115 | IMAGECUBE { $$ = "imageCube"; }
2116 | IMAGEBUFFER { $$ = "imageBuffer"; }
2117 | IMAGE1DARRAY { $$ = "image1DArray"; }
2118 | IMAGE2DARRAY { $$ = "image2DArray"; }
2119 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2120 | IMAGE2DMS { $$ = "image2DMS"; }
2121 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2122 | IIMAGE1D { $$ = "iimage1D"; }
2123 | IIMAGE2D { $$ = "iimage2D"; }
2124 | IIMAGE3D { $$ = "iimage3D"; }
2125 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2126 | IIMAGECUBE { $$ = "iimageCube"; }
2127 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2128 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2129 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2130 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2131 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2132 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2133 | UIMAGE1D { $$ = "uimage1D"; }
2134 | UIMAGE2D { $$ = "uimage2D"; }
2135 | UIMAGE3D { $$ = "uimage3D"; }
2136 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2137 | UIMAGECUBE { $$ = "uimageCube"; }
2138 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2139 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2140 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2141 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2142 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2143 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2144 | ATOMIC_UINT { $$ = "atomic_uint"; }
2147 precision_qualifier:
2150 state->check_precision_qualifiers_allowed(&@1);
2151 $$ = ast_precision_high;
2155 state->check_precision_qualifiers_allowed(&@1);
2156 $$ = ast_precision_medium;
2160 state->check_precision_qualifiers_allowed(&@1);
2161 $$ = ast_precision_low;
2166 STRUCT any_identifier '{' struct_declaration_list '}'
2169 $$ = new(ctx) ast_struct_specifier($2, $4);
2170 $$->set_location_range(@2, @5);
2171 state->symbols->add_type($2, glsl_type::void_type);
2173 | STRUCT '{' struct_declaration_list '}'
2176 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2177 $$->set_location_range(@2, @4);
2181 struct_declaration_list:
2185 $1->link.self_link();
2187 | struct_declaration_list struct_declaration
2190 $$->link.insert_before(& $2->link);
2195 fully_specified_type struct_declarator_list ';'
2198 ast_fully_specified_type *const type = $1;
2199 type->set_location(@1);
2201 if (type->qualifier.flags.i != 0)
2202 _mesa_glsl_error(&@1, state,
2203 "only precision qualifiers may be applied to "
2204 "structure members");
2206 $$ = new(ctx) ast_declarator_list(type);
2207 $$->set_location(@2);
2209 $$->declarations.push_degenerate_list_at_head(& $2->link);
2213 struct_declarator_list:
2217 $1->link.self_link();
2219 | struct_declarator_list ',' struct_declarator
2222 $$->link.insert_before(& $3->link);
2230 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2231 $$->set_location(@1);
2233 | any_identifier array_specifier
2236 $$ = new(ctx) ast_declaration($1, $2, NULL);
2237 $$->set_location_range(@1, @2);
2242 assignment_expression
2243 | '{' initializer_list '}'
2247 | '{' initializer_list ',' '}'
2257 $$ = new(ctx) ast_aggregate_initializer();
2258 $$->set_location(@1);
2259 $$->expressions.push_tail(& $1->link);
2261 | initializer_list ',' initializer
2263 $1->expressions.push_tail(& $3->link);
2267 declaration_statement:
2271 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2274 compound_statement { $$ = (ast_node *) $1; }
2279 declaration_statement
2280 | expression_statement
2281 | selection_statement
2283 | iteration_statement
2291 $$ = new(ctx) ast_compound_statement(true, NULL);
2292 $$->set_location_range(@1, @2);
2296 state->symbols->push_scope();
2301 $$ = new(ctx) ast_compound_statement(true, $3);
2302 $$->set_location_range(@1, @4);
2303 state->symbols->pop_scope();
2307 statement_no_new_scope:
2308 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2312 compound_statement_no_new_scope:
2316 $$ = new(ctx) ast_compound_statement(false, NULL);
2317 $$->set_location_range(@1, @2);
2319 | '{' statement_list '}'
2322 $$ = new(ctx) ast_compound_statement(false, $2);
2323 $$->set_location_range(@1, @3);
2331 _mesa_glsl_error(& @1, state, "<nil> statement");
2336 $$->link.self_link();
2338 | statement_list statement
2341 _mesa_glsl_error(& @2, state, "<nil> statement");
2345 $$->link.insert_before(& $2->link);
2349 expression_statement:
2353 $$ = new(ctx) ast_expression_statement(NULL);
2354 $$->set_location(@1);
2359 $$ = new(ctx) ast_expression_statement($1);
2360 $$->set_location(@1);
2364 selection_statement:
2365 IF '(' expression ')' selection_rest_statement
2367 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2369 $$->set_location_range(@1, @5);
2373 selection_rest_statement:
2374 statement ELSE statement
2376 $$.then_statement = $1;
2377 $$.else_statement = $3;
2379 | statement %prec THEN
2381 $$.then_statement = $1;
2382 $$.else_statement = NULL;
2389 $$ = (ast_node *) $1;
2391 | fully_specified_type any_identifier '=' initializer
2394 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2395 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2396 decl->set_location_range(@2, @4);
2397 declarator->set_location(@1);
2399 declarator->declarations.push_tail(&decl->link);
2405 * switch_statement grammar is based on the syntax described in the body
2406 * of the GLSL spec, not in it's appendix!!!
2409 SWITCH '(' expression ')' switch_body
2411 $$ = new(state) ast_switch_statement($3, $5);
2412 $$->set_location_range(@1, @5);
2419 $$ = new(state) ast_switch_body(NULL);
2420 $$->set_location_range(@1, @2);
2422 | '{' case_statement_list '}'
2424 $$ = new(state) ast_switch_body($2);
2425 $$->set_location_range(@1, @3);
2432 $$ = new(state) ast_case_label($2);
2433 $$->set_location(@2);
2437 $$ = new(state) ast_case_label(NULL);
2438 $$->set_location(@2);
2445 ast_case_label_list *labels = new(state) ast_case_label_list();
2447 labels->labels.push_tail(& $1->link);
2449 $$->set_location(@1);
2451 | case_label_list case_label
2454 $$->labels.push_tail(& $2->link);
2459 case_label_list statement
2461 ast_case_statement *stmts = new(state) ast_case_statement($1);
2462 stmts->set_location(@2);
2464 stmts->stmts.push_tail(& $2->link);
2467 | case_statement statement
2470 $$->stmts.push_tail(& $2->link);
2474 case_statement_list:
2477 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2478 cases->set_location(@1);
2480 cases->cases.push_tail(& $1->link);
2483 | case_statement_list case_statement
2486 $$->cases.push_tail(& $2->link);
2490 iteration_statement:
2491 WHILE '(' condition ')' statement_no_new_scope
2494 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2495 NULL, $3, NULL, $5);
2496 $$->set_location_range(@1, @4);
2498 | DO statement WHILE '(' expression ')' ';'
2501 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2502 NULL, $5, NULL, $2);
2503 $$->set_location_range(@1, @6);
2505 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2508 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2509 $3, $4.cond, $4.rest, $6);
2510 $$->set_location_range(@1, @6);
2515 expression_statement
2516 | declaration_statement
2533 | conditionopt ';' expression
2540 // Grammar Note: No 'goto'. Gotos are not supported.
2545 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2546 $$->set_location(@1);
2551 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2552 $$->set_location(@1);
2557 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2558 $$->set_location(@1);
2560 | RETURN expression ';'
2563 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2564 $$->set_location_range(@1, @2);
2566 | DISCARD ';' // Fragment shader only.
2569 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2570 $$->set_location(@1);
2574 external_declaration:
2575 function_definition { $$ = $1; }
2576 | declaration { $$ = $1; }
2577 | pragma_statement { $$ = NULL; }
2578 | layout_defaults { $$ = $1; }
2581 function_definition:
2582 function_prototype compound_statement_no_new_scope
2585 $$ = new(ctx) ast_function_definition();
2586 $$->set_location_range(@1, @2);
2590 state->symbols->pop_scope();
2594 /* layout_qualifieropt is packed into this rule */
2596 basic_interface_block
2600 | layout_qualifier interface_block
2602 ast_interface_block *block = (ast_interface_block *) $2;
2604 if (!state->has_420pack_or_es31() && block->layout.has_layout() &&
2605 !block->layout.is_default_qualifier) {
2606 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2610 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2614 block->layout.is_default_qualifier = false;
2618 | memory_qualifier interface_block
2620 ast_interface_block *block = (ast_interface_block *)$2;
2622 if (!block->layout.flags.q.buffer) {
2623 _mesa_glsl_error(& @1, state,
2624 "memory qualifiers can only be used in the "
2625 "declaration of shader storage blocks");
2627 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2634 basic_interface_block:
2635 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2637 ast_interface_block *const block = $6;
2639 block->block_name = $2;
2640 block->declarations.push_degenerate_list_at_head(& $4->link);
2642 _mesa_ast_process_interface_block(& @1, state, block, $1);
2646 | uniform_interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2648 ast_interface_block *const block = $6;
2650 block->layout = *state->default_uniform_qualifier;
2651 block->block_name = $2;
2652 block->declarations.push_degenerate_list_at_head(& $4->link);
2654 _mesa_ast_process_interface_block(& @1, state, block, $1);
2658 | buffer_interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2660 ast_interface_block *const block = $6;
2662 block->layout = *state->default_shader_storage_qualifier;
2663 block->block_name = $2;
2664 block->declarations.push_degenerate_list_at_head(& $4->link);
2666 _mesa_ast_process_interface_block(& @1, state, block, $1);
2672 interface_qualifier:
2675 memset(& $$, 0, sizeof($$));
2680 memset(& $$, 0, sizeof($$));
2685 uniform_interface_qualifier:
2688 memset(& $$, 0, sizeof($$));
2689 $$.flags.q.uniform = 1;
2693 buffer_interface_qualifier:
2696 memset(& $$, 0, sizeof($$));
2697 $$.flags.q.buffer = 1;
2704 $$ = new(state) ast_interface_block(NULL, NULL);
2708 $$ = new(state) ast_interface_block($1, NULL);
2709 $$->set_location(@1);
2711 | NEW_IDENTIFIER array_specifier
2713 $$ = new(state) ast_interface_block($1, $2);
2714 $$->set_location_range(@1, @2);
2722 $1->link.self_link();
2724 | member_declaration member_list
2727 $2->link.insert_before(& $$->link);
2732 fully_specified_type struct_declarator_list ';'
2735 ast_fully_specified_type *type = $1;
2736 type->set_location(@1);
2738 if (type->qualifier.flags.q.attribute) {
2739 _mesa_glsl_error(& @1, state,
2740 "keyword 'attribute' cannot be used with "
2741 "interface block member");
2742 } else if (type->qualifier.flags.q.varying) {
2743 _mesa_glsl_error(& @1, state,
2744 "keyword 'varying' cannot be used with "
2745 "interface block member");
2748 $$ = new(ctx) ast_declarator_list(type);
2749 $$->set_location(@2);
2751 $$->declarations.push_degenerate_list_at_head(& $2->link);
2755 layout_uniform_defaults:
2756 layout_qualifier layout_uniform_defaults
2759 if (!state->has_420pack_or_es31()) {
2760 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2763 if (!state->default_uniform_qualifier->
2764 merge_qualifier(& @1, state, $1, false)) {
2769 | layout_qualifier UNIFORM ';'
2771 if (!state->default_uniform_qualifier->
2772 merge_qualifier(& @1, state, $1, false)) {
2779 layout_buffer_defaults:
2780 layout_qualifier layout_buffer_defaults
2783 if (!state->has_420pack_or_es31()) {
2784 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2787 if (!state->default_shader_storage_qualifier->
2788 merge_qualifier(& @1, state, $1, false)) {
2793 | layout_qualifier BUFFER ';'
2795 if (!state->default_shader_storage_qualifier->
2796 merge_qualifier(& @1, state, $1, false)) {
2800 /* From the GLSL 4.50 spec, section 4.4.5:
2802 * "It is a compile-time error to specify the binding identifier for
2803 * the global scope or for block member declarations."
2805 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2806 _mesa_glsl_error(& @1, state,
2807 "binding qualifier cannot be set for default layout");
2815 layout_qualifier layout_in_defaults
2818 if (!state->has_420pack_or_es31()) {
2819 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2822 if (!state->in_qualifier->
2823 merge_in_qualifier(& @1, state, $1, $$, false)) {
2828 | layout_qualifier IN_TOK ';'
2831 if (!state->in_qualifier->
2832 merge_in_qualifier(& @1, state, $1, $$, true)) {
2838 layout_out_defaults:
2839 layout_qualifier layout_out_defaults
2842 if (!state->has_420pack_or_es31()) {
2843 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2846 if (!state->out_qualifier->
2847 merge_out_qualifier(& @1, state, $1, $$, false)) {
2852 | layout_qualifier OUT_TOK ';'
2855 if (!state->out_qualifier->
2856 merge_out_qualifier(& @1, state, $1, $$, true))
2862 layout_uniform_defaults
2863 | layout_buffer_defaults
2864 | layout_in_defaults
2865 | layout_out_defaults