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 "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 %type <interface_block> buffer_instance_name_opt
174 %token <real> FLOATCONSTANT
175 %token <dreal> DOUBLECONSTANT
176 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
177 %token <identifier> FIELD_SELECTION
178 %token LEFT_OP RIGHT_OP
179 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
180 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
181 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
183 %token INVARIANT PRECISE
184 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
186 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
187 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
188 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
189 %token PRAGMA_INVARIANT_ALL
192 /* Reserved words that are not actually used in the grammar.
194 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
195 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
196 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
197 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
199 %token SIZEOF CAST NAMESPACE USING
200 %token RESOURCE PATCH
205 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
207 %type <identifier> variable_identifier
208 %type <node> statement
209 %type <node> statement_list
210 %type <node> simple_statement
211 %type <n> precision_qualifier
212 %type <type_qualifier> type_qualifier
213 %type <type_qualifier> auxiliary_storage_qualifier
214 %type <type_qualifier> storage_qualifier
215 %type <type_qualifier> interpolation_qualifier
216 %type <type_qualifier> layout_qualifier
217 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
218 %type <type_qualifier> interface_block_layout_qualifier
219 %type <type_qualifier> memory_qualifier
220 %type <type_qualifier> subroutine_qualifier
221 %type <subroutine_list> subroutine_type_list
222 %type <type_qualifier> 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
307 version_statement extension_statement_list
309 _mesa_glsl_initialize_types(state);
311 external_declaration_list
313 delete state->symbols;
314 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
315 if (state->es_shader) {
316 if (state->stage == MESA_SHADER_FRAGMENT) {
317 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
319 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
320 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
322 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
323 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
324 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
325 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
327 _mesa_glsl_initialize_types(state);
332 /* blank - no #version specified: defaults are already set */
333 | VERSION_TOK INTCONSTANT EOL
335 state->process_version_directive(&@2, $2, NULL);
340 | VERSION_TOK INTCONSTANT any_identifier EOL
342 state->process_version_directive(&@2, $2, $3);
351 | PRAGMA_DEBUG_OFF EOL
352 | PRAGMA_OPTIMIZE_ON EOL
353 | PRAGMA_OPTIMIZE_OFF EOL
354 | PRAGMA_INVARIANT_ALL EOL
356 /* Pragma invariant(all) cannot be used in a fragment shader.
358 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
360 * "It is an error to use this pragma in a fragment shader."
362 if (state->is_version(120, 300) &&
363 state->stage == MESA_SHADER_FRAGMENT) {
364 _mesa_glsl_error(& @1, state,
365 "pragma `invariant(all)' cannot be used "
366 "in a fragment shader.");
367 } else if (!state->is_version(120, 100)) {
368 _mesa_glsl_warning(& @1, state,
369 "pragma `invariant(all)' not supported in %s "
370 "(GLSL ES 1.00 or GLSL 1.20 required)",
371 state->get_version_string());
373 state->all_invariant = true;
378 extension_statement_list:
380 | extension_statement_list extension_statement
390 EXTENSION any_identifier COLON any_identifier EOL
392 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
398 external_declaration_list:
401 /* FINISHME: The NULL test is required because pragmas are set to
402 * FINISHME: NULL. (See production rule for external_declaration.)
405 state->translation_unit.push_tail(& $1->link);
407 | external_declaration_list external_declaration
409 /* FINISHME: The NULL test is required because pragmas are set to
410 * FINISHME: NULL. (See production rule for external_declaration.)
413 state->translation_unit.push_tail(& $2->link);
415 | external_declaration_list extension_statement {
416 if (!state->allow_extension_directive_midshader) {
417 _mesa_glsl_error(& @2, state,
418 "#extension directive is not allowed "
419 "in the middle of a shader");
434 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
435 $$->set_location(@1);
436 $$->primary_expression.identifier = $1;
441 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
442 $$->set_location(@1);
443 $$->primary_expression.int_constant = $1;
448 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
449 $$->set_location(@1);
450 $$->primary_expression.uint_constant = $1;
455 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
456 $$->set_location(@1);
457 $$->primary_expression.float_constant = $1;
462 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
463 $$->set_location(@1);
464 $$->primary_expression.double_constant = $1;
469 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
470 $$->set_location(@1);
471 $$->primary_expression.bool_constant = $1;
481 | postfix_expression '[' integer_expression ']'
484 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
485 $$->set_location_range(@1, @4);
491 | postfix_expression DOT_TOK FIELD_SELECTION
494 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
495 $$->set_location_range(@1, @3);
496 $$->primary_expression.identifier = $3;
498 | postfix_expression INC_OP
501 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
502 $$->set_location_range(@1, @2);
504 | postfix_expression DEC_OP
507 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
508 $$->set_location_range(@1, @2);
517 function_call_or_method
520 function_call_or_method:
521 function_call_generic
524 function_call_generic:
525 function_call_header_with_parameters ')'
526 | function_call_header_no_parameters ')'
529 function_call_header_no_parameters:
530 function_call_header VOID_TOK
531 | function_call_header
534 function_call_header_with_parameters:
535 function_call_header assignment_expression
538 $$->set_location(@1);
539 $$->expressions.push_tail(& $2->link);
541 | function_call_header_with_parameters ',' assignment_expression
544 $$->set_location(@1);
545 $$->expressions.push_tail(& $3->link);
549 // Grammar Note: Constructors look like functions, but lexical
550 // analysis recognized most of them as keywords. They are now
551 // recognized through "type_specifier".
552 function_call_header:
553 function_identifier '('
560 $$ = new(ctx) ast_function_expression($1);
561 $$->set_location(@1);
566 $$ = new(ctx) ast_function_expression($1);
567 $$->set_location(@1);
571 // Grammar Note: Constructors look like methods, but lexical
572 // analysis recognized most of them as keywords. They are now
573 // recognized through "type_specifier".
575 // Grammar Note: No traditional style type casts.
578 | INC_OP unary_expression
581 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
582 $$->set_location(@1);
584 | DEC_OP unary_expression
587 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
588 $$->set_location(@1);
590 | unary_operator unary_expression
593 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
594 $$->set_location_range(@1, @2);
598 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
600 '+' { $$ = ast_plus; }
601 | '-' { $$ = ast_neg; }
602 | '!' { $$ = ast_logic_not; }
603 | '~' { $$ = ast_bit_not; }
606 multiplicative_expression:
608 | multiplicative_expression '*' unary_expression
611 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
612 $$->set_location_range(@1, @3);
614 | multiplicative_expression '/' unary_expression
617 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
618 $$->set_location_range(@1, @3);
620 | multiplicative_expression '%' unary_expression
623 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
624 $$->set_location_range(@1, @3);
629 multiplicative_expression
630 | additive_expression '+' multiplicative_expression
633 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
634 $$->set_location_range(@1, @3);
636 | additive_expression '-' multiplicative_expression
639 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
640 $$->set_location_range(@1, @3);
646 | shift_expression LEFT_OP additive_expression
649 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
650 $$->set_location_range(@1, @3);
652 | shift_expression RIGHT_OP additive_expression
655 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
656 $$->set_location_range(@1, @3);
660 relational_expression:
662 | relational_expression '<' shift_expression
665 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
666 $$->set_location_range(@1, @3);
668 | relational_expression '>' shift_expression
671 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
672 $$->set_location_range(@1, @3);
674 | relational_expression LE_OP shift_expression
677 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
678 $$->set_location_range(@1, @3);
680 | relational_expression GE_OP shift_expression
683 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
684 $$->set_location_range(@1, @3);
689 relational_expression
690 | equality_expression EQ_OP relational_expression
693 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
694 $$->set_location_range(@1, @3);
696 | equality_expression NE_OP relational_expression
699 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
700 $$->set_location_range(@1, @3);
706 | and_expression '&' equality_expression
709 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
710 $$->set_location_range(@1, @3);
714 exclusive_or_expression:
716 | exclusive_or_expression '^' and_expression
719 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
720 $$->set_location_range(@1, @3);
724 inclusive_or_expression:
725 exclusive_or_expression
726 | inclusive_or_expression '|' exclusive_or_expression
729 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
730 $$->set_location_range(@1, @3);
734 logical_and_expression:
735 inclusive_or_expression
736 | logical_and_expression AND_OP inclusive_or_expression
739 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
740 $$->set_location_range(@1, @3);
744 logical_xor_expression:
745 logical_and_expression
746 | logical_xor_expression XOR_OP logical_and_expression
749 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
750 $$->set_location_range(@1, @3);
754 logical_or_expression:
755 logical_xor_expression
756 | logical_or_expression OR_OP logical_xor_expression
759 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
760 $$->set_location_range(@1, @3);
764 conditional_expression:
765 logical_or_expression
766 | logical_or_expression '?' expression ':' assignment_expression
769 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
770 $$->set_location_range(@1, @5);
774 assignment_expression:
775 conditional_expression
776 | unary_expression assignment_operator assignment_expression
779 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
780 $$->set_location_range(@1, @3);
785 '=' { $$ = ast_assign; }
786 | MUL_ASSIGN { $$ = ast_mul_assign; }
787 | DIV_ASSIGN { $$ = ast_div_assign; }
788 | MOD_ASSIGN { $$ = ast_mod_assign; }
789 | ADD_ASSIGN { $$ = ast_add_assign; }
790 | SUB_ASSIGN { $$ = ast_sub_assign; }
791 | LEFT_ASSIGN { $$ = ast_ls_assign; }
792 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
793 | AND_ASSIGN { $$ = ast_and_assign; }
794 | XOR_ASSIGN { $$ = ast_xor_assign; }
795 | OR_ASSIGN { $$ = ast_or_assign; }
799 assignment_expression
803 | expression ',' assignment_expression
806 if ($1->oper != ast_sequence) {
807 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
808 $$->set_location_range(@1, @3);
809 $$->expressions.push_tail(& $1->link);
814 $$->expressions.push_tail(& $3->link);
819 conditional_expression
823 function_prototype ';'
825 state->symbols->pop_scope();
828 | init_declarator_list ';'
832 | PRECISION precision_qualifier type_specifier ';'
834 $3->default_precision = $2;
844 function_declarator ')'
849 | function_header_with_parameters
852 function_header_with_parameters:
853 function_header parameter_declaration
856 $$->parameters.push_tail(& $2->link);
858 | function_header_with_parameters ',' parameter_declaration
861 $$->parameters.push_tail(& $3->link);
866 fully_specified_type variable_identifier '('
869 $$ = new(ctx) ast_function();
870 $$->set_location(@2);
871 $$->return_type = $1;
874 if ($1->qualifier.flags.q.subroutine) {
875 /* add type for IDENTIFIER search */
876 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
878 state->symbols->add_function(new(state) ir_function($2));
879 state->symbols->push_scope();
883 parameter_declarator:
884 type_specifier any_identifier
887 $$ = new(ctx) ast_parameter_declarator();
888 $$->set_location_range(@1, @2);
889 $$->type = new(ctx) ast_fully_specified_type();
890 $$->type->set_location(@1);
891 $$->type->specifier = $1;
894 | type_specifier any_identifier array_specifier
897 $$ = new(ctx) ast_parameter_declarator();
898 $$->set_location_range(@1, @3);
899 $$->type = new(ctx) ast_fully_specified_type();
900 $$->type->set_location(@1);
901 $$->type->specifier = $1;
903 $$->array_specifier = $3;
907 parameter_declaration:
908 parameter_qualifier parameter_declarator
911 $$->type->qualifier = $1;
913 | parameter_qualifier parameter_type_specifier
916 $$ = new(ctx) ast_parameter_declarator();
917 $$->set_location(@2);
918 $$->type = new(ctx) ast_fully_specified_type();
919 $$->type->set_location_range(@1, @2);
920 $$->type->qualifier = $1;
921 $$->type->specifier = $2;
928 memset(& $$, 0, sizeof($$));
930 | CONST_TOK parameter_qualifier
932 if ($2.flags.q.constant)
933 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
936 $$.flags.q.constant = 1;
938 | PRECISE parameter_qualifier
940 if ($2.flags.q.precise)
941 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
944 $$.flags.q.precise = 1;
946 | parameter_direction_qualifier parameter_qualifier
948 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
949 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
951 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
952 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
956 $$.merge_qualifier(&@1, state, $2);
958 | precision_qualifier parameter_qualifier
960 if ($2.precision != ast_precision_none)
961 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
963 if (!state->has_420pack_or_es31() &&
965 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
970 | memory_qualifier parameter_qualifier
973 $$.merge_qualifier(&@1, state, $2);
976 parameter_direction_qualifier:
979 memset(& $$, 0, sizeof($$));
984 memset(& $$, 0, sizeof($$));
989 memset(& $$, 0, sizeof($$));
995 parameter_type_specifier:
999 init_declarator_list:
1001 | init_declarator_list ',' any_identifier
1004 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1005 decl->set_location(@3);
1008 $$->declarations.push_tail(&decl->link);
1009 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1011 | init_declarator_list ',' any_identifier array_specifier
1014 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1015 decl->set_location_range(@3, @4);
1018 $$->declarations.push_tail(&decl->link);
1019 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1021 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1024 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1025 decl->set_location_range(@3, @4);
1028 $$->declarations.push_tail(&decl->link);
1029 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1031 | init_declarator_list ',' any_identifier '=' initializer
1034 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1035 decl->set_location(@3);
1038 $$->declarations.push_tail(&decl->link);
1039 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1043 // Grammar Note: No 'enum', or 'typedef'.
1045 fully_specified_type
1048 /* Empty declaration list is valid. */
1049 $$ = new(ctx) ast_declarator_list($1);
1050 $$->set_location(@1);
1052 | fully_specified_type any_identifier
1055 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1056 decl->set_location(@2);
1058 $$ = new(ctx) ast_declarator_list($1);
1059 $$->set_location_range(@1, @2);
1060 $$->declarations.push_tail(&decl->link);
1062 | fully_specified_type any_identifier array_specifier
1065 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1066 decl->set_location_range(@2, @3);
1068 $$ = new(ctx) ast_declarator_list($1);
1069 $$->set_location_range(@1, @3);
1070 $$->declarations.push_tail(&decl->link);
1072 | fully_specified_type any_identifier array_specifier '=' initializer
1075 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1076 decl->set_location_range(@2, @3);
1078 $$ = new(ctx) ast_declarator_list($1);
1079 $$->set_location_range(@1, @3);
1080 $$->declarations.push_tail(&decl->link);
1082 | fully_specified_type any_identifier '=' initializer
1085 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1086 decl->set_location(@2);
1088 $$ = new(ctx) ast_declarator_list($1);
1089 $$->set_location_range(@1, @2);
1090 $$->declarations.push_tail(&decl->link);
1092 | INVARIANT variable_identifier
1095 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1096 decl->set_location(@2);
1098 $$ = new(ctx) ast_declarator_list(NULL);
1099 $$->set_location_range(@1, @2);
1100 $$->invariant = true;
1102 $$->declarations.push_tail(&decl->link);
1104 | PRECISE variable_identifier
1107 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1108 decl->set_location(@2);
1110 $$ = new(ctx) ast_declarator_list(NULL);
1111 $$->set_location_range(@1, @2);
1114 $$->declarations.push_tail(&decl->link);
1118 fully_specified_type:
1122 $$ = new(ctx) ast_fully_specified_type();
1123 $$->set_location(@1);
1126 | type_qualifier type_specifier
1129 $$ = new(ctx) ast_fully_specified_type();
1130 $$->set_location_range(@1, @2);
1133 if ($$->specifier->structure != NULL &&
1134 $$->specifier->structure->is_declaration) {
1135 $$->specifier->structure->layout = &$$->qualifier;
1141 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1147 layout_qualifier_id_list:
1149 | layout_qualifier_id_list ',' layout_qualifier_id
1152 if (!$$.merge_qualifier(& @3, state, $3)) {
1158 layout_qualifier_id:
1161 memset(& $$, 0, sizeof($$));
1163 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1164 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1165 state->is_version(150, 0))) {
1166 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1167 $$.flags.q.origin_upper_left = 1;
1168 } else if (match_layout_qualifier($1, "pixel_center_integer",
1170 $$.flags.q.pixel_center_integer = 1;
1173 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1174 _mesa_glsl_warning(& @1, state,
1175 "GL_ARB_fragment_coord_conventions layout "
1176 "identifier `%s' used", $1);
1180 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1182 (state->AMD_conservative_depth_enable ||
1183 state->ARB_conservative_depth_enable ||
1184 state->is_version(420, 0))) {
1185 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1186 $$.flags.q.depth_any = 1;
1187 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1188 $$.flags.q.depth_greater = 1;
1189 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1190 $$.flags.q.depth_less = 1;
1191 } else if (match_layout_qualifier($1, "depth_unchanged",
1193 $$.flags.q.depth_unchanged = 1;
1196 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1197 _mesa_glsl_warning(& @1, state,
1198 "GL_AMD_conservative_depth "
1199 "layout qualifier `%s' is used", $1);
1201 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1202 _mesa_glsl_warning(& @1, state,
1203 "GL_ARB_conservative_depth "
1204 "layout qualifier `%s' is used", $1);
1208 /* See also interface_block_layout_qualifier. */
1209 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1210 if (match_layout_qualifier($1, "std140", state) == 0) {
1211 $$.flags.q.std140 = 1;
1212 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1213 $$.flags.q.shared = 1;
1214 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1215 $$.flags.q.std430 = 1;
1216 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1217 $$.flags.q.column_major = 1;
1218 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1219 * below in the interface_block_layout_qualifier rule.
1221 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1224 * Also, this takes care of alternate capitalizations of
1225 * "row_major" (which is necessary because layout qualifiers
1226 * are case-insensitive in desktop GLSL).
1228 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1229 $$.flags.q.row_major = 1;
1230 /* "packed" is a reserved word in GLSL, and its token is
1231 * parsed below in the interface_block_layout_qualifier rule.
1232 * However, we must take care of alternate capitalizations of
1233 * "packed", because layout qualifiers are case-insensitive
1236 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1237 $$.flags.q.packed = 1;
1240 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1241 _mesa_glsl_warning(& @1, state,
1242 "#version 140 / GL_ARB_uniform_buffer_object "
1243 "layout qualifier `%s' is used", $1);
1247 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1249 static const struct {
1253 { "points", GL_POINTS },
1254 { "lines", GL_LINES },
1255 { "lines_adjacency", GL_LINES_ADJACENCY },
1256 { "line_strip", GL_LINE_STRIP },
1257 { "triangles", GL_TRIANGLES },
1258 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1259 { "triangle_strip", GL_TRIANGLE_STRIP },
1261 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1262 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1263 $$.flags.q.prim_type = 1;
1264 $$.prim_type = map[i].e;
1269 if ($$.flags.i && !state->is_version(150, 0)) {
1270 _mesa_glsl_error(& @1, state, "#version 150 layout "
1271 "qualifier `%s' used", $1);
1275 /* Layout qualifiers for ARB_shader_image_load_store. */
1276 if (state->ARB_shader_image_load_store_enable ||
1277 state->is_version(420, 310)) {
1279 static const struct {
1282 glsl_base_type base_type;
1283 /** Minimum desktop GLSL version required for the image
1284 * format. Use 130 if already present in the original
1287 unsigned required_glsl;
1288 /** Minimum GLSL ES version required for the image format. */
1289 unsigned required_essl;
1291 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1292 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1293 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1294 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1295 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1296 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1297 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1298 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1299 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1300 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1301 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1302 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1303 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1304 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1305 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1306 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1307 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1308 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1309 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1310 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1311 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1312 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1313 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1314 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1315 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1316 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1317 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1318 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1319 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1320 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1321 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1322 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1323 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1324 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1325 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1326 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1327 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1328 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1329 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1332 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1333 if (state->is_version(map[i].required_glsl,
1334 map[i].required_essl) &&
1335 match_layout_qualifier($1, map[i].name, state) == 0) {
1336 $$.flags.q.explicit_image_format = 1;
1337 $$.image_format = map[i].format;
1338 $$.image_base_type = map[i].base_type;
1345 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1346 /* From section 4.4.1.3 of the GLSL 4.50 specification
1347 * (Fragment Shader Inputs):
1349 * "Fragment shaders also allow the following layout
1350 * qualifier on in only (not with variable declarations)
1351 * layout-qualifier-id
1352 * early_fragment_tests
1355 if (state->stage != MESA_SHADER_FRAGMENT) {
1356 _mesa_glsl_error(& @1, state,
1357 "early_fragment_tests layout qualifier only "
1358 "valid in fragment shaders");
1361 $$.flags.q.early_fragment_tests = 1;
1365 /* Layout qualifiers for tessellation evaluation shaders. */
1371 /* triangles already parsed by gs-specific code */
1372 { "quads", GL_QUADS },
1373 { "isolines", GL_ISOLINES },
1375 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1376 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1377 $$.flags.q.prim_type = 1;
1378 $$.prim_type = map[i].e;
1384 !state->ARB_tessellation_shader_enable &&
1385 !state->is_version(400, 0)) {
1386 _mesa_glsl_error(& @1, state,
1387 "primitive mode qualifier `%s' requires "
1388 "GLSL 4.00 or ARB_tessellation_shader", $1);
1396 { "equal_spacing", GL_EQUAL },
1397 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1398 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1400 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1401 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1402 $$.flags.q.vertex_spacing = 1;
1403 $$.vertex_spacing = map[i].e;
1409 !state->ARB_tessellation_shader_enable &&
1410 !state->is_version(400, 0)) {
1411 _mesa_glsl_error(& @1, state,
1412 "vertex spacing qualifier `%s' requires "
1413 "GLSL 4.00 or ARB_tessellation_shader", $1);
1417 if (match_layout_qualifier($1, "cw", state) == 0) {
1418 $$.flags.q.ordering = 1;
1419 $$.ordering = GL_CW;
1420 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1421 $$.flags.q.ordering = 1;
1422 $$.ordering = GL_CCW;
1426 !state->ARB_tessellation_shader_enable &&
1427 !state->is_version(400, 0)) {
1428 _mesa_glsl_error(& @1, state,
1429 "ordering qualifier `%s' requires "
1430 "GLSL 4.00 or ARB_tessellation_shader", $1);
1434 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1435 $$.flags.q.point_mode = 1;
1436 $$.point_mode = true;
1440 !state->ARB_tessellation_shader_enable &&
1441 !state->is_version(400, 0)) {
1442 _mesa_glsl_error(& @1, state,
1443 "qualifier `point_mode' requires "
1444 "GLSL 4.00 or ARB_tessellation_shader");
1449 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1454 | any_identifier '=' constant_expression
1456 memset(& $$, 0, sizeof($$));
1459 if ($3->oper != ast_int_constant &&
1460 $3->oper != ast_uint_constant &&
1461 !state->has_enhanced_layouts()) {
1462 _mesa_glsl_error(& @1, state,
1463 "compile-time constant expressions require "
1464 "GLSL 4.40 or ARB_enhanced_layouts");
1467 if (match_layout_qualifier("location", $1, state) == 0) {
1468 $$.flags.q.explicit_location = 1;
1470 if ($$.flags.q.attribute == 1 &&
1471 state->ARB_explicit_attrib_location_warn) {
1472 _mesa_glsl_warning(& @1, state,
1473 "GL_ARB_explicit_attrib_location layout "
1474 "identifier `%s' used", $1);
1479 if (match_layout_qualifier("index", $1, state) == 0) {
1480 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1481 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1485 $$.flags.q.explicit_index = 1;
1489 if ((state->has_420pack_or_es31() ||
1490 state->has_atomic_counters() ||
1491 state->has_shader_storage_buffer_objects()) &&
1492 match_layout_qualifier("binding", $1, state) == 0) {
1493 $$.flags.q.explicit_binding = 1;
1497 if (state->has_atomic_counters() &&
1498 match_layout_qualifier("offset", $1, state) == 0) {
1499 $$.flags.q.explicit_offset = 1;
1503 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1504 $$.flags.q.max_vertices = 1;
1505 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1506 if (!state->is_version(150, 0)) {
1507 _mesa_glsl_error(& @3, state,
1508 "#version 150 max_vertices qualifier "
1513 if (state->stage == MESA_SHADER_GEOMETRY) {
1514 if (match_layout_qualifier("stream", $1, state) == 0 &&
1515 state->check_explicit_attrib_stream_allowed(& @3)) {
1516 $$.flags.q.stream = 1;
1517 $$.flags.q.explicit_stream = 1;
1522 static const char * const local_size_qualifiers[3] = {
1527 for (int i = 0; i < 3; i++) {
1528 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1530 if (!state->has_compute_shader()) {
1531 _mesa_glsl_error(& @3, state,
1532 "%s qualifier requires GLSL 4.30 or "
1533 "GLSL ES 3.10 or ARB_compute_shader",
1534 local_size_qualifiers[i]);
1537 $$.flags.q.local_size |= (1 << i);
1538 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1544 if (match_layout_qualifier("invocations", $1, state) == 0) {
1545 $$.flags.q.invocations = 1;
1546 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1547 if (!state->is_version(400, 0) &&
1548 !state->ARB_gpu_shader5_enable) {
1549 _mesa_glsl_error(& @3, state,
1550 "GL_ARB_gpu_shader5 invocations "
1551 "qualifier specified", $3);
1555 /* Layout qualifiers for tessellation control shaders. */
1556 if (match_layout_qualifier("vertices", $1, state) == 0) {
1557 $$.flags.q.vertices = 1;
1558 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1559 if (!state->ARB_tessellation_shader_enable &&
1560 !state->is_version(400, 0)) {
1561 _mesa_glsl_error(& @1, state,
1562 "vertices qualifier requires GLSL 4.00 or "
1563 "ARB_tessellation_shader");
1567 /* If the identifier didn't match any known layout identifiers,
1571 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1576 | interface_block_layout_qualifier
1579 /* Layout qualifiers for ARB_uniform_buffer_object. */
1580 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1581 _mesa_glsl_error(& @1, state,
1582 "#version 140 / GL_ARB_uniform_buffer_object "
1583 "layout qualifier `%s' is used", $1);
1584 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1585 _mesa_glsl_warning(& @1, state,
1586 "#version 140 / GL_ARB_uniform_buffer_object "
1587 "layout qualifier `%s' is used", $1);
1592 /* This is a separate language rule because we parse these as tokens
1593 * (due to them being reserved keywords) instead of identifiers like
1594 * most qualifiers. See the any_identifier path of
1595 * layout_qualifier_id for the others.
1597 * Note that since layout qualifiers are case-insensitive in desktop
1598 * GLSL, all of these qualifiers need to be handled as identifiers as
1599 * well (by the any_identifier path of layout_qualifier_id).
1601 interface_block_layout_qualifier:
1604 memset(& $$, 0, sizeof($$));
1605 $$.flags.q.row_major = 1;
1609 memset(& $$, 0, sizeof($$));
1610 $$.flags.q.packed = 1;
1614 memset(& $$, 0, sizeof($$));
1615 $$.flags.q.shared = 1;
1619 subroutine_qualifier:
1622 memset(& $$, 0, sizeof($$));
1623 $$.flags.q.subroutine = 1;
1625 | SUBROUTINE '(' subroutine_type_list ')'
1627 memset(& $$, 0, sizeof($$));
1628 $$.flags.q.subroutine_def = 1;
1629 $$.subroutine_list = $3;
1633 subroutine_type_list:
1637 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1638 decl->set_location(@1);
1640 $$ = new(ctx) ast_subroutine_list();
1641 $$->declarations.push_tail(&decl->link);
1643 | subroutine_type_list ',' any_identifier
1646 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1647 decl->set_location(@3);
1650 $$->declarations.push_tail(&decl->link);
1654 interpolation_qualifier:
1657 memset(& $$, 0, sizeof($$));
1658 $$.flags.q.smooth = 1;
1662 memset(& $$, 0, sizeof($$));
1663 $$.flags.q.flat = 1;
1667 memset(& $$, 0, sizeof($$));
1668 $$.flags.q.noperspective = 1;
1673 /* Single qualifiers */
1676 memset(& $$, 0, sizeof($$));
1677 $$.flags.q.invariant = 1;
1681 memset(& $$, 0, sizeof($$));
1682 $$.flags.q.precise = 1;
1684 | auxiliary_storage_qualifier
1686 | interpolation_qualifier
1689 | subroutine_qualifier
1690 | precision_qualifier
1692 memset(&$$, 0, sizeof($$));
1696 /* Multiple qualifiers:
1697 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1698 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1700 * invariant interpolation auxiliary storage precision ...or...
1701 * layout storage precision
1703 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1704 * side don't contain any that must appear on the left hand side.
1705 * For example, when processing a storage qualifier, we check that there are
1706 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1708 | PRECISE type_qualifier
1710 if ($2.flags.q.precise)
1711 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1714 $$.flags.q.precise = 1;
1716 | INVARIANT type_qualifier
1718 if ($2.flags.q.invariant)
1719 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1721 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1722 _mesa_glsl_error(&@1, state,
1723 "\"invariant\" must come after \"precise\"");
1726 $$.flags.q.invariant = 1;
1728 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1730 * "Only variables output from a shader can be candidates for invariance.
1731 * This includes user-defined output variables and the built-in output
1732 * variables. As only outputs can be declared as invariant, an invariant
1733 * output from one shader stage will still match an input of a subsequent
1734 * stage without the input being declared as invariant."
1736 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1737 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1739 | interpolation_qualifier type_qualifier
1741 /* Section 4.3 of the GLSL 1.40 specification states:
1742 * "...qualified with one of these interpolation qualifiers"
1744 * GLSL 1.30 claims to allow "one or more", but insists that:
1745 * "These interpolation qualifiers may only precede the qualifiers in,
1746 * centroid in, out, or centroid out in a declaration."
1748 * ...which means that e.g. smooth can't precede smooth, so there can be
1749 * only one after all, and the 1.40 text is a clarification, not a change.
1751 if ($2.has_interpolation())
1752 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1754 if (!state->has_420pack_or_es31() &&
1755 ($2.flags.q.precise || $2.flags.q.invariant)) {
1756 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1757 "after \"precise\" or \"invariant\"");
1761 $$.merge_qualifier(&@1, state, $2);
1763 | layout_qualifier type_qualifier
1765 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1766 * appear no later than auxiliary storage qualifiers. There is no
1767 * particularly clear spec language mandating this, but in all examples
1768 * the layout qualifier precedes the storage qualifier.
1770 * We allow combinations of layout with interpolation, invariant or
1771 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1772 * There is no clear spec guidance on this either.
1774 if (!state->has_420pack_or_es31() && $2.has_layout())
1775 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1778 $$.merge_qualifier(&@1, state, $2);
1780 | subroutine_qualifier type_qualifier
1783 $$.merge_qualifier(&@1, state, $2);
1785 | auxiliary_storage_qualifier type_qualifier
1787 if ($2.has_auxiliary_storage()) {
1788 _mesa_glsl_error(&@1, state,
1789 "duplicate auxiliary storage qualifier (centroid or sample)");
1792 if (!state->has_420pack_or_es31() &&
1793 ($2.flags.q.precise || $2.flags.q.invariant ||
1794 $2.has_interpolation() || $2.has_layout())) {
1795 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1796 "just before storage qualifiers");
1799 $$.merge_qualifier(&@1, state, $2);
1801 | storage_qualifier type_qualifier
1803 /* Section 4.3 of the GLSL 1.20 specification states:
1804 * "Variable declarations may have a storage qualifier specified..."
1805 * 1.30 clarifies this to "may have one storage qualifier".
1807 if ($2.has_storage())
1808 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1810 if (!state->has_420pack_or_es31() &&
1811 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1812 $2.has_layout() || $2.has_auxiliary_storage())) {
1813 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1814 "precise, invariant, interpolation, layout and auxiliary "
1815 "storage qualifiers");
1819 $$.merge_qualifier(&@1, state, $2);
1821 | precision_qualifier type_qualifier
1823 if ($2.precision != ast_precision_none)
1824 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1826 if (!(state->has_420pack_or_es31()) &&
1828 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1833 | memory_qualifier type_qualifier
1836 $$.merge_qualifier(&@1, state, $2);
1840 auxiliary_storage_qualifier:
1843 memset(& $$, 0, sizeof($$));
1844 $$.flags.q.centroid = 1;
1848 memset(& $$, 0, sizeof($$));
1849 $$.flags.q.sample = 1;
1853 memset(& $$, 0, sizeof($$));
1854 $$.flags.q.patch = 1;
1860 memset(& $$, 0, sizeof($$));
1861 $$.flags.q.constant = 1;
1865 memset(& $$, 0, sizeof($$));
1866 $$.flags.q.attribute = 1;
1870 memset(& $$, 0, sizeof($$));
1871 $$.flags.q.varying = 1;
1875 memset(& $$, 0, sizeof($$));
1880 memset(& $$, 0, sizeof($$));
1883 if (state->stage == MESA_SHADER_GEOMETRY &&
1884 state->has_explicit_attrib_stream()) {
1885 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1888 * "If the block or variable is declared with the stream
1889 * identifier, it is associated with the specified stream;
1890 * otherwise, it is associated with the current default stream."
1892 $$.flags.q.stream = 1;
1893 $$.flags.q.explicit_stream = 0;
1894 $$.stream = state->out_qualifier->stream;
1899 memset(& $$, 0, sizeof($$));
1900 $$.flags.q.uniform = 1;
1904 memset(& $$, 0, sizeof($$));
1905 $$.flags.q.buffer = 1;
1909 memset(& $$, 0, sizeof($$));
1910 $$.flags.q.shared_storage = 1;
1917 memset(& $$, 0, sizeof($$));
1918 $$.flags.q.coherent = 1;
1922 memset(& $$, 0, sizeof($$));
1923 $$.flags.q._volatile = 1;
1927 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1928 memset(& $$, 0, sizeof($$));
1929 $$.flags.q.restrict_flag = 1;
1933 memset(& $$, 0, sizeof($$));
1934 $$.flags.q.read_only = 1;
1938 memset(& $$, 0, sizeof($$));
1939 $$.flags.q.write_only = 1;
1947 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
1948 ast_unsized_array_dim, NULL,
1950 $$->set_location_range(@1, @2);
1952 | '[' constant_expression ']'
1955 $$ = new(ctx) ast_array_specifier(@1, $2);
1956 $$->set_location_range(@1, @3);
1958 | array_specifier '[' ']'
1963 if (state->check_arrays_of_arrays_allowed(& @1)) {
1964 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
1968 | array_specifier '[' constant_expression ']'
1972 if (state->check_arrays_of_arrays_allowed(& @1)) {
1973 $$->add_dimension($3);
1979 type_specifier_nonarray
1980 | type_specifier_nonarray array_specifier
1983 $$->array_specifier = $2;
1987 type_specifier_nonarray:
1988 basic_type_specifier_nonarray
1991 $$ = new(ctx) ast_type_specifier($1);
1992 $$->set_location(@1);
1997 $$ = new(ctx) ast_type_specifier($1);
1998 $$->set_location(@1);
2003 $$ = new(ctx) ast_type_specifier($1);
2004 $$->set_location(@1);
2008 basic_type_specifier_nonarray:
2009 VOID_TOK { $$ = "void"; }
2010 | FLOAT_TOK { $$ = "float"; }
2011 | DOUBLE_TOK { $$ = "double"; }
2012 | INT_TOK { $$ = "int"; }
2013 | UINT_TOK { $$ = "uint"; }
2014 | BOOL_TOK { $$ = "bool"; }
2015 | VEC2 { $$ = "vec2"; }
2016 | VEC3 { $$ = "vec3"; }
2017 | VEC4 { $$ = "vec4"; }
2018 | BVEC2 { $$ = "bvec2"; }
2019 | BVEC3 { $$ = "bvec3"; }
2020 | BVEC4 { $$ = "bvec4"; }
2021 | IVEC2 { $$ = "ivec2"; }
2022 | IVEC3 { $$ = "ivec3"; }
2023 | IVEC4 { $$ = "ivec4"; }
2024 | UVEC2 { $$ = "uvec2"; }
2025 | UVEC3 { $$ = "uvec3"; }
2026 | UVEC4 { $$ = "uvec4"; }
2027 | DVEC2 { $$ = "dvec2"; }
2028 | DVEC3 { $$ = "dvec3"; }
2029 | DVEC4 { $$ = "dvec4"; }
2030 | MAT2X2 { $$ = "mat2"; }
2031 | MAT2X3 { $$ = "mat2x3"; }
2032 | MAT2X4 { $$ = "mat2x4"; }
2033 | MAT3X2 { $$ = "mat3x2"; }
2034 | MAT3X3 { $$ = "mat3"; }
2035 | MAT3X4 { $$ = "mat3x4"; }
2036 | MAT4X2 { $$ = "mat4x2"; }
2037 | MAT4X3 { $$ = "mat4x3"; }
2038 | MAT4X4 { $$ = "mat4"; }
2039 | DMAT2X2 { $$ = "dmat2"; }
2040 | DMAT2X3 { $$ = "dmat2x3"; }
2041 | DMAT2X4 { $$ = "dmat2x4"; }
2042 | DMAT3X2 { $$ = "dmat3x2"; }
2043 | DMAT3X3 { $$ = "dmat3"; }
2044 | DMAT3X4 { $$ = "dmat3x4"; }
2045 | DMAT4X2 { $$ = "dmat4x2"; }
2046 | DMAT4X3 { $$ = "dmat4x3"; }
2047 | DMAT4X4 { $$ = "dmat4"; }
2048 | SAMPLER1D { $$ = "sampler1D"; }
2049 | SAMPLER2D { $$ = "sampler2D"; }
2050 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2051 | SAMPLER3D { $$ = "sampler3D"; }
2052 | SAMPLERCUBE { $$ = "samplerCube"; }
2053 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2054 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2055 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2056 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2057 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2058 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2059 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2060 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2061 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2062 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2063 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2064 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2065 | ISAMPLER1D { $$ = "isampler1D"; }
2066 | ISAMPLER2D { $$ = "isampler2D"; }
2067 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2068 | ISAMPLER3D { $$ = "isampler3D"; }
2069 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2070 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2071 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2072 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2073 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2074 | USAMPLER1D { $$ = "usampler1D"; }
2075 | USAMPLER2D { $$ = "usampler2D"; }
2076 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2077 | USAMPLER3D { $$ = "usampler3D"; }
2078 | USAMPLERCUBE { $$ = "usamplerCube"; }
2079 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2080 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2081 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2082 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2083 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2084 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2085 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2086 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2087 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2088 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2089 | IMAGE1D { $$ = "image1D"; }
2090 | IMAGE2D { $$ = "image2D"; }
2091 | IMAGE3D { $$ = "image3D"; }
2092 | IMAGE2DRECT { $$ = "image2DRect"; }
2093 | IMAGECUBE { $$ = "imageCube"; }
2094 | IMAGEBUFFER { $$ = "imageBuffer"; }
2095 | IMAGE1DARRAY { $$ = "image1DArray"; }
2096 | IMAGE2DARRAY { $$ = "image2DArray"; }
2097 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2098 | IMAGE2DMS { $$ = "image2DMS"; }
2099 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2100 | IIMAGE1D { $$ = "iimage1D"; }
2101 | IIMAGE2D { $$ = "iimage2D"; }
2102 | IIMAGE3D { $$ = "iimage3D"; }
2103 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2104 | IIMAGECUBE { $$ = "iimageCube"; }
2105 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2106 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2107 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2108 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2109 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2110 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2111 | UIMAGE1D { $$ = "uimage1D"; }
2112 | UIMAGE2D { $$ = "uimage2D"; }
2113 | UIMAGE3D { $$ = "uimage3D"; }
2114 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2115 | UIMAGECUBE { $$ = "uimageCube"; }
2116 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2117 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2118 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2119 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2120 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2121 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2122 | ATOMIC_UINT { $$ = "atomic_uint"; }
2125 precision_qualifier:
2128 state->check_precision_qualifiers_allowed(&@1);
2129 $$ = ast_precision_high;
2133 state->check_precision_qualifiers_allowed(&@1);
2134 $$ = ast_precision_medium;
2138 state->check_precision_qualifiers_allowed(&@1);
2139 $$ = ast_precision_low;
2144 STRUCT any_identifier '{' struct_declaration_list '}'
2147 $$ = new(ctx) ast_struct_specifier($2, $4);
2148 $$->set_location_range(@2, @5);
2149 state->symbols->add_type($2, glsl_type::void_type);
2151 | STRUCT '{' struct_declaration_list '}'
2154 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2155 $$->set_location_range(@2, @4);
2159 struct_declaration_list:
2163 $1->link.self_link();
2165 | struct_declaration_list struct_declaration
2168 $$->link.insert_before(& $2->link);
2173 fully_specified_type struct_declarator_list ';'
2176 ast_fully_specified_type *const type = $1;
2177 type->set_location(@1);
2179 if (type->qualifier.flags.i != 0)
2180 _mesa_glsl_error(&@1, state,
2181 "only precision qualifiers may be applied to "
2182 "structure members");
2184 $$ = new(ctx) ast_declarator_list(type);
2185 $$->set_location(@2);
2187 $$->declarations.push_degenerate_list_at_head(& $2->link);
2191 struct_declarator_list:
2195 $1->link.self_link();
2197 | struct_declarator_list ',' struct_declarator
2200 $$->link.insert_before(& $3->link);
2208 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2209 $$->set_location(@1);
2211 | any_identifier array_specifier
2214 $$ = new(ctx) ast_declaration($1, $2, NULL);
2215 $$->set_location_range(@1, @2);
2220 assignment_expression
2221 | '{' initializer_list '}'
2225 | '{' initializer_list ',' '}'
2235 $$ = new(ctx) ast_aggregate_initializer();
2236 $$->set_location(@1);
2237 $$->expressions.push_tail(& $1->link);
2239 | initializer_list ',' initializer
2241 $1->expressions.push_tail(& $3->link);
2245 declaration_statement:
2249 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2252 compound_statement { $$ = (ast_node *) $1; }
2257 declaration_statement
2258 | expression_statement
2259 | selection_statement
2261 | iteration_statement
2269 $$ = new(ctx) ast_compound_statement(true, NULL);
2270 $$->set_location_range(@1, @2);
2274 state->symbols->push_scope();
2279 $$ = new(ctx) ast_compound_statement(true, $3);
2280 $$->set_location_range(@1, @4);
2281 state->symbols->pop_scope();
2285 statement_no_new_scope:
2286 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2290 compound_statement_no_new_scope:
2294 $$ = new(ctx) ast_compound_statement(false, NULL);
2295 $$->set_location_range(@1, @2);
2297 | '{' statement_list '}'
2300 $$ = new(ctx) ast_compound_statement(false, $2);
2301 $$->set_location_range(@1, @3);
2309 _mesa_glsl_error(& @1, state, "<nil> statement");
2314 $$->link.self_link();
2316 | statement_list statement
2319 _mesa_glsl_error(& @2, state, "<nil> statement");
2323 $$->link.insert_before(& $2->link);
2327 expression_statement:
2331 $$ = new(ctx) ast_expression_statement(NULL);
2332 $$->set_location(@1);
2337 $$ = new(ctx) ast_expression_statement($1);
2338 $$->set_location(@1);
2342 selection_statement:
2343 IF '(' expression ')' selection_rest_statement
2345 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2347 $$->set_location_range(@1, @5);
2351 selection_rest_statement:
2352 statement ELSE statement
2354 $$.then_statement = $1;
2355 $$.else_statement = $3;
2357 | statement %prec THEN
2359 $$.then_statement = $1;
2360 $$.else_statement = NULL;
2367 $$ = (ast_node *) $1;
2369 | fully_specified_type any_identifier '=' initializer
2372 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2373 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2374 decl->set_location_range(@2, @4);
2375 declarator->set_location(@1);
2377 declarator->declarations.push_tail(&decl->link);
2383 * switch_statement grammar is based on the syntax described in the body
2384 * of the GLSL spec, not in it's appendix!!!
2387 SWITCH '(' expression ')' switch_body
2389 $$ = new(state) ast_switch_statement($3, $5);
2390 $$->set_location_range(@1, @5);
2397 $$ = new(state) ast_switch_body(NULL);
2398 $$->set_location_range(@1, @2);
2400 | '{' case_statement_list '}'
2402 $$ = new(state) ast_switch_body($2);
2403 $$->set_location_range(@1, @3);
2410 $$ = new(state) ast_case_label($2);
2411 $$->set_location(@2);
2415 $$ = new(state) ast_case_label(NULL);
2416 $$->set_location(@2);
2423 ast_case_label_list *labels = new(state) ast_case_label_list();
2425 labels->labels.push_tail(& $1->link);
2427 $$->set_location(@1);
2429 | case_label_list case_label
2432 $$->labels.push_tail(& $2->link);
2437 case_label_list statement
2439 ast_case_statement *stmts = new(state) ast_case_statement($1);
2440 stmts->set_location(@2);
2442 stmts->stmts.push_tail(& $2->link);
2445 | case_statement statement
2448 $$->stmts.push_tail(& $2->link);
2452 case_statement_list:
2455 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2456 cases->set_location(@1);
2458 cases->cases.push_tail(& $1->link);
2461 | case_statement_list case_statement
2464 $$->cases.push_tail(& $2->link);
2468 iteration_statement:
2469 WHILE '(' condition ')' statement_no_new_scope
2472 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2473 NULL, $3, NULL, $5);
2474 $$->set_location_range(@1, @4);
2476 | DO statement WHILE '(' expression ')' ';'
2479 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2480 NULL, $5, NULL, $2);
2481 $$->set_location_range(@1, @6);
2483 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2486 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2487 $3, $4.cond, $4.rest, $6);
2488 $$->set_location_range(@1, @6);
2493 expression_statement
2494 | declaration_statement
2511 | conditionopt ';' expression
2518 // Grammar Note: No 'goto'. Gotos are not supported.
2523 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2524 $$->set_location(@1);
2529 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2530 $$->set_location(@1);
2535 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2536 $$->set_location(@1);
2538 | RETURN expression ';'
2541 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2542 $$->set_location_range(@1, @2);
2544 | DISCARD ';' // Fragment shader only.
2547 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2548 $$->set_location(@1);
2552 external_declaration:
2553 function_definition { $$ = $1; }
2554 | declaration { $$ = $1; }
2555 | pragma_statement { $$ = NULL; }
2556 | layout_defaults { $$ = $1; }
2559 function_definition:
2560 function_prototype compound_statement_no_new_scope
2563 $$ = new(ctx) ast_function_definition();
2564 $$->set_location_range(@1, @2);
2568 state->symbols->pop_scope();
2572 /* layout_qualifieropt is packed into this rule */
2574 basic_interface_block
2578 | layout_qualifier interface_block
2580 ast_interface_block *block = (ast_interface_block *) $2;
2582 if (!state->has_420pack_or_es31() && block->layout.has_layout() &&
2583 !block->layout.is_default_qualifier) {
2584 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2588 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2592 block->layout.is_default_qualifier = false;
2596 | memory_qualifier interface_block
2598 ast_interface_block *block = (ast_interface_block *)$2;
2600 if (!block->layout.flags.q.buffer) {
2601 _mesa_glsl_error(& @1, state,
2602 "memory qualifiers can only be used in the "
2603 "declaration of shader storage blocks");
2605 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2612 basic_interface_block:
2613 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2615 ast_interface_block *const block = $6;
2617 block->block_name = $2;
2618 block->declarations.push_degenerate_list_at_head(& $4->link);
2620 _mesa_ast_process_interface_block(& @1, state, block, $1);
2624 | buffer_interface_qualifier NEW_IDENTIFIER '{' member_list '}' buffer_instance_name_opt ';'
2626 ast_interface_block *const block = $6;
2628 block->block_name = $2;
2629 block->declarations.push_degenerate_list_at_head(& $4->link);
2631 _mesa_ast_process_interface_block(& @1, state, block, $1);
2637 interface_qualifier:
2640 memset(& $$, 0, sizeof($$));
2645 memset(& $$, 0, sizeof($$));
2650 memset(& $$, 0, sizeof($$));
2651 $$.flags.q.uniform = 1;
2655 buffer_interface_qualifier:
2658 memset(& $$, 0, sizeof($$));
2659 $$.flags.q.buffer = 1;
2666 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2671 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2673 $$->set_location(@1);
2675 | NEW_IDENTIFIER array_specifier
2677 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2679 $$->set_location_range(@1, @2);
2683 buffer_instance_name_opt:
2686 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2691 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2693 $$->set_location(@1);
2695 | NEW_IDENTIFIER array_specifier
2697 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2699 $$->set_location_range(@1, @2);
2707 $1->link.self_link();
2709 | member_declaration member_list
2712 $2->link.insert_before(& $$->link);
2717 fully_specified_type struct_declarator_list ';'
2720 ast_fully_specified_type *type = $1;
2721 type->set_location(@1);
2723 if (type->qualifier.flags.q.attribute) {
2724 _mesa_glsl_error(& @1, state,
2725 "keyword 'attribute' cannot be used with "
2726 "interface block member");
2727 } else if (type->qualifier.flags.q.varying) {
2728 _mesa_glsl_error(& @1, state,
2729 "keyword 'varying' cannot be used with "
2730 "interface block member");
2733 $$ = new(ctx) ast_declarator_list(type);
2734 $$->set_location(@2);
2736 $$->declarations.push_degenerate_list_at_head(& $2->link);
2741 layout_qualifier UNIFORM ';'
2743 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2749 | layout_qualifier BUFFER ';'
2751 if (!state->default_shader_storage_qualifier->merge_qualifier(& @1, state, $1)) {
2755 /* From the GLSL 4.50 spec, section 4.4.5:
2757 * "It is a compile-time error to specify the binding identifier for
2758 * the global scope or for block member declarations."
2760 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2761 _mesa_glsl_error(& @1, state,
2762 "binding qualifier cannot be set for default layout");
2768 | layout_qualifier IN_TOK ';'
2771 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2776 | layout_qualifier OUT_TOK ';'
2779 if (state->stage == MESA_SHADER_GEOMETRY) {
2780 if ($1.flags.q.prim_type) {
2781 /* Make sure this is a valid output primitive type. */
2782 switch ($1.prim_type) {
2785 case GL_TRIANGLE_STRIP:
2788 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2793 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2796 /* Allow future assigments of global out's stream id value */
2797 state->out_qualifier->flags.q.explicit_stream = 0;
2798 } else if (state->stage == MESA_SHADER_TESS_CTRL) {
2799 if (!state->out_qualifier->merge_out_qualifier(& @1, state, $1, $$))
2802 _mesa_glsl_error(& @1, state,
2803 "out layout qualifiers only valid in "
2804 "tessellation control or geometry shaders");