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
168 %token STRUCT VOID_TOK WHILE
169 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
170 %type <identifier> any_identifier
171 %type <interface_block> instance_name_opt
172 %type <interface_block> buffer_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> buffer_interface_qualifier
223 %type <type_specifier> type_specifier
224 %type <type_specifier> type_specifier_nonarray
225 %type <array_specifier> array_specifier
226 %type <identifier> basic_type_specifier_nonarray
227 %type <fully_specified_type> fully_specified_type
228 %type <function> function_prototype
229 %type <function> function_header
230 %type <function> function_header_with_parameters
231 %type <function> function_declarator
232 %type <parameter_declarator> parameter_declarator
233 %type <parameter_declarator> parameter_declaration
234 %type <type_qualifier> parameter_qualifier
235 %type <type_qualifier> parameter_direction_qualifier
236 %type <type_specifier> parameter_type_specifier
237 %type <function_definition> function_definition
238 %type <compound_statement> compound_statement_no_new_scope
239 %type <compound_statement> compound_statement
240 %type <node> statement_no_new_scope
241 %type <node> expression_statement
242 %type <expression> expression
243 %type <expression> primary_expression
244 %type <expression> assignment_expression
245 %type <expression> conditional_expression
246 %type <expression> logical_or_expression
247 %type <expression> logical_xor_expression
248 %type <expression> logical_and_expression
249 %type <expression> inclusive_or_expression
250 %type <expression> exclusive_or_expression
251 %type <expression> and_expression
252 %type <expression> equality_expression
253 %type <expression> relational_expression
254 %type <expression> shift_expression
255 %type <expression> additive_expression
256 %type <expression> multiplicative_expression
257 %type <expression> unary_expression
258 %type <expression> constant_expression
259 %type <expression> integer_expression
260 %type <expression> postfix_expression
261 %type <expression> function_call_header_with_parameters
262 %type <expression> function_call_header_no_parameters
263 %type <expression> function_call_header
264 %type <expression> function_call_generic
265 %type <expression> function_call_or_method
266 %type <expression> function_call
267 %type <n> assignment_operator
268 %type <n> unary_operator
269 %type <expression> function_identifier
270 %type <node> external_declaration
271 %type <declarator_list> init_declarator_list
272 %type <declarator_list> single_declaration
273 %type <expression> initializer
274 %type <expression> initializer_list
275 %type <node> declaration
276 %type <node> declaration_statement
277 %type <node> jump_statement
278 %type <node> interface_block
279 %type <interface_block> basic_interface_block
280 %type <struct_specifier> struct_specifier
281 %type <declarator_list> struct_declaration_list
282 %type <declarator_list> struct_declaration
283 %type <declaration> struct_declarator
284 %type <declaration> struct_declarator_list
285 %type <declarator_list> member_list
286 %type <declarator_list> member_declaration
287 %type <node> selection_statement
288 %type <selection_rest_statement> selection_rest_statement
289 %type <node> switch_statement
290 %type <switch_body> switch_body
291 %type <case_label_list> case_label_list
292 %type <case_label> case_label
293 %type <case_statement> case_statement
294 %type <case_statement_list> case_statement_list
295 %type <node> iteration_statement
296 %type <node> condition
297 %type <node> conditionopt
298 %type <node> for_init_statement
299 %type <for_rest_statement> for_rest_statement
300 %type <n> integer_constant
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 _mesa_glsl_initialize_types(state);
320 /* blank - no #version specified: defaults are already set */
321 | VERSION_TOK INTCONSTANT EOL
323 state->process_version_directive(&@2, $2, NULL);
328 | VERSION_TOK INTCONSTANT any_identifier EOL
330 state->process_version_directive(&@2, $2, $3);
339 | PRAGMA_DEBUG_OFF EOL
340 | PRAGMA_OPTIMIZE_ON EOL
341 | PRAGMA_OPTIMIZE_OFF EOL
342 | PRAGMA_INVARIANT_ALL EOL
344 /* Pragma invariant(all) cannot be used in a fragment shader.
346 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
348 * "It is an error to use this pragma in a fragment shader."
350 if (state->is_version(120, 300) &&
351 state->stage == MESA_SHADER_FRAGMENT) {
352 _mesa_glsl_error(& @1, state,
353 "pragma `invariant(all)' cannot be used "
354 "in a fragment shader.");
355 } else if (!state->is_version(120, 100)) {
356 _mesa_glsl_warning(& @1, state,
357 "pragma `invariant(all)' not supported in %s "
358 "(GLSL ES 1.00 or GLSL 1.20 required)",
359 state->get_version_string());
361 state->all_invariant = true;
366 extension_statement_list:
368 | extension_statement_list extension_statement
378 EXTENSION any_identifier COLON any_identifier EOL
380 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
386 external_declaration_list:
389 /* FINISHME: The NULL test is required because pragmas are set to
390 * FINISHME: NULL. (See production rule for external_declaration.)
393 state->translation_unit.push_tail(& $1->link);
395 | external_declaration_list external_declaration
397 /* FINISHME: The NULL test is required because pragmas are set to
398 * FINISHME: NULL. (See production rule for external_declaration.)
401 state->translation_unit.push_tail(& $2->link);
403 | external_declaration_list extension_statement {
404 if (!state->allow_extension_directive_midshader) {
405 _mesa_glsl_error(& @2, state,
406 "#extension directive is not allowed "
407 "in the middle of a shader");
422 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
423 $$->set_location(@1);
424 $$->primary_expression.identifier = $1;
429 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
430 $$->set_location(@1);
431 $$->primary_expression.int_constant = $1;
436 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
437 $$->set_location(@1);
438 $$->primary_expression.uint_constant = $1;
443 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
444 $$->set_location(@1);
445 $$->primary_expression.float_constant = $1;
450 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
451 $$->set_location(@1);
452 $$->primary_expression.double_constant = $1;
457 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
458 $$->set_location(@1);
459 $$->primary_expression.bool_constant = $1;
469 | postfix_expression '[' integer_expression ']'
472 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
473 $$->set_location_range(@1, @4);
479 | postfix_expression DOT_TOK FIELD_SELECTION
482 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
483 $$->set_location_range(@1, @3);
484 $$->primary_expression.identifier = $3;
486 | postfix_expression INC_OP
489 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
490 $$->set_location_range(@1, @2);
492 | postfix_expression DEC_OP
495 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
496 $$->set_location_range(@1, @2);
505 function_call_or_method
508 function_call_or_method:
509 function_call_generic
512 function_call_generic:
513 function_call_header_with_parameters ')'
514 | function_call_header_no_parameters ')'
517 function_call_header_no_parameters:
518 function_call_header VOID_TOK
519 | function_call_header
522 function_call_header_with_parameters:
523 function_call_header assignment_expression
526 $$->set_location(@1);
527 $$->expressions.push_tail(& $2->link);
529 | function_call_header_with_parameters ',' assignment_expression
532 $$->set_location(@1);
533 $$->expressions.push_tail(& $3->link);
537 // Grammar Note: Constructors look like functions, but lexical
538 // analysis recognized most of them as keywords. They are now
539 // recognized through "type_specifier".
540 function_call_header:
541 function_identifier '('
548 $$ = new(ctx) ast_function_expression($1);
549 $$->set_location(@1);
554 $$ = new(ctx) ast_function_expression($1);
555 $$->set_location(@1);
559 // Grammar Note: Constructors look like methods, but lexical
560 // analysis recognized most of them as keywords. They are now
561 // recognized through "type_specifier".
563 // Grammar Note: No traditional style type casts.
566 | INC_OP unary_expression
569 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
570 $$->set_location(@1);
572 | DEC_OP unary_expression
575 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
576 $$->set_location(@1);
578 | unary_operator unary_expression
581 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
582 $$->set_location_range(@1, @2);
586 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
588 '+' { $$ = ast_plus; }
589 | '-' { $$ = ast_neg; }
590 | '!' { $$ = ast_logic_not; }
591 | '~' { $$ = ast_bit_not; }
594 multiplicative_expression:
596 | multiplicative_expression '*' unary_expression
599 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
600 $$->set_location_range(@1, @3);
602 | multiplicative_expression '/' unary_expression
605 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
606 $$->set_location_range(@1, @3);
608 | multiplicative_expression '%' unary_expression
611 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
612 $$->set_location_range(@1, @3);
617 multiplicative_expression
618 | additive_expression '+' multiplicative_expression
621 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
622 $$->set_location_range(@1, @3);
624 | additive_expression '-' multiplicative_expression
627 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
628 $$->set_location_range(@1, @3);
634 | shift_expression LEFT_OP additive_expression
637 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
638 $$->set_location_range(@1, @3);
640 | shift_expression RIGHT_OP additive_expression
643 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
644 $$->set_location_range(@1, @3);
648 relational_expression:
650 | relational_expression '<' shift_expression
653 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
654 $$->set_location_range(@1, @3);
656 | relational_expression '>' shift_expression
659 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
660 $$->set_location_range(@1, @3);
662 | relational_expression LE_OP shift_expression
665 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
666 $$->set_location_range(@1, @3);
668 | relational_expression GE_OP shift_expression
671 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
672 $$->set_location_range(@1, @3);
677 relational_expression
678 | equality_expression EQ_OP relational_expression
681 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
682 $$->set_location_range(@1, @3);
684 | equality_expression NE_OP relational_expression
687 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
688 $$->set_location_range(@1, @3);
694 | and_expression '&' equality_expression
697 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
698 $$->set_location_range(@1, @3);
702 exclusive_or_expression:
704 | exclusive_or_expression '^' and_expression
707 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
708 $$->set_location_range(@1, @3);
712 inclusive_or_expression:
713 exclusive_or_expression
714 | inclusive_or_expression '|' exclusive_or_expression
717 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
718 $$->set_location_range(@1, @3);
722 logical_and_expression:
723 inclusive_or_expression
724 | logical_and_expression AND_OP inclusive_or_expression
727 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
728 $$->set_location_range(@1, @3);
732 logical_xor_expression:
733 logical_and_expression
734 | logical_xor_expression XOR_OP logical_and_expression
737 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
738 $$->set_location_range(@1, @3);
742 logical_or_expression:
743 logical_xor_expression
744 | logical_or_expression OR_OP logical_xor_expression
747 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
748 $$->set_location_range(@1, @3);
752 conditional_expression:
753 logical_or_expression
754 | logical_or_expression '?' expression ':' assignment_expression
757 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
758 $$->set_location_range(@1, @5);
762 assignment_expression:
763 conditional_expression
764 | unary_expression assignment_operator assignment_expression
767 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
768 $$->set_location_range(@1, @3);
773 '=' { $$ = ast_assign; }
774 | MUL_ASSIGN { $$ = ast_mul_assign; }
775 | DIV_ASSIGN { $$ = ast_div_assign; }
776 | MOD_ASSIGN { $$ = ast_mod_assign; }
777 | ADD_ASSIGN { $$ = ast_add_assign; }
778 | SUB_ASSIGN { $$ = ast_sub_assign; }
779 | LEFT_ASSIGN { $$ = ast_ls_assign; }
780 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
781 | AND_ASSIGN { $$ = ast_and_assign; }
782 | XOR_ASSIGN { $$ = ast_xor_assign; }
783 | OR_ASSIGN { $$ = ast_or_assign; }
787 assignment_expression
791 | expression ',' assignment_expression
794 if ($1->oper != ast_sequence) {
795 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
796 $$->set_location_range(@1, @3);
797 $$->expressions.push_tail(& $1->link);
802 $$->expressions.push_tail(& $3->link);
807 conditional_expression
811 function_prototype ';'
813 state->symbols->pop_scope();
816 | init_declarator_list ';'
820 | PRECISION precision_qualifier type_specifier ';'
822 $3->default_precision = $2;
832 function_declarator ')'
837 | function_header_with_parameters
840 function_header_with_parameters:
841 function_header parameter_declaration
844 $$->parameters.push_tail(& $2->link);
846 | function_header_with_parameters ',' parameter_declaration
849 $$->parameters.push_tail(& $3->link);
854 fully_specified_type variable_identifier '('
857 $$ = new(ctx) ast_function();
858 $$->set_location(@2);
859 $$->return_type = $1;
862 if ($1->qualifier.flags.q.subroutine) {
863 /* add type for IDENTIFIER search */
864 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
866 state->symbols->add_function(new(state) ir_function($2));
867 state->symbols->push_scope();
871 parameter_declarator:
872 type_specifier any_identifier
875 $$ = new(ctx) ast_parameter_declarator();
876 $$->set_location_range(@1, @2);
877 $$->type = new(ctx) ast_fully_specified_type();
878 $$->type->set_location(@1);
879 $$->type->specifier = $1;
882 | type_specifier any_identifier array_specifier
885 $$ = new(ctx) ast_parameter_declarator();
886 $$->set_location_range(@1, @3);
887 $$->type = new(ctx) ast_fully_specified_type();
888 $$->type->set_location(@1);
889 $$->type->specifier = $1;
891 $$->array_specifier = $3;
895 parameter_declaration:
896 parameter_qualifier parameter_declarator
899 $$->type->qualifier = $1;
901 | parameter_qualifier parameter_type_specifier
904 $$ = new(ctx) ast_parameter_declarator();
905 $$->set_location(@2);
906 $$->type = new(ctx) ast_fully_specified_type();
907 $$->type->set_location_range(@1, @2);
908 $$->type->qualifier = $1;
909 $$->type->specifier = $2;
916 memset(& $$, 0, sizeof($$));
918 | CONST_TOK parameter_qualifier
920 if ($2.flags.q.constant)
921 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
924 $$.flags.q.constant = 1;
926 | PRECISE parameter_qualifier
928 if ($2.flags.q.precise)
929 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
932 $$.flags.q.precise = 1;
934 | parameter_direction_qualifier parameter_qualifier
936 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
937 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
939 if (!state->has_420pack() && $2.flags.q.constant)
940 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
944 $$.merge_qualifier(&@1, state, $2);
946 | precision_qualifier parameter_qualifier
948 if ($2.precision != ast_precision_none)
949 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
951 if (!state->has_420pack() && $2.flags.i != 0)
952 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
957 | memory_qualifier parameter_qualifier
960 $$.merge_qualifier(&@1, state, $2);
963 parameter_direction_qualifier:
966 memset(& $$, 0, sizeof($$));
971 memset(& $$, 0, sizeof($$));
976 memset(& $$, 0, sizeof($$));
982 parameter_type_specifier:
986 init_declarator_list:
988 | init_declarator_list ',' any_identifier
991 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
992 decl->set_location(@3);
995 $$->declarations.push_tail(&decl->link);
996 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
998 | init_declarator_list ',' any_identifier array_specifier
1001 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1002 decl->set_location_range(@3, @4);
1005 $$->declarations.push_tail(&decl->link);
1006 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1008 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1011 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1012 decl->set_location_range(@3, @4);
1015 $$->declarations.push_tail(&decl->link);
1016 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1018 | init_declarator_list ',' any_identifier '=' initializer
1021 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1022 decl->set_location(@3);
1025 $$->declarations.push_tail(&decl->link);
1026 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1030 // Grammar Note: No 'enum', or 'typedef'.
1032 fully_specified_type
1035 /* Empty declaration list is valid. */
1036 $$ = new(ctx) ast_declarator_list($1);
1037 $$->set_location(@1);
1039 | fully_specified_type any_identifier
1042 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1043 decl->set_location(@2);
1045 $$ = new(ctx) ast_declarator_list($1);
1046 $$->set_location_range(@1, @2);
1047 $$->declarations.push_tail(&decl->link);
1049 | fully_specified_type any_identifier array_specifier
1052 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1053 decl->set_location_range(@2, @3);
1055 $$ = new(ctx) ast_declarator_list($1);
1056 $$->set_location_range(@1, @3);
1057 $$->declarations.push_tail(&decl->link);
1059 | fully_specified_type any_identifier array_specifier '=' initializer
1062 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1063 decl->set_location_range(@2, @3);
1065 $$ = new(ctx) ast_declarator_list($1);
1066 $$->set_location_range(@1, @3);
1067 $$->declarations.push_tail(&decl->link);
1069 | fully_specified_type any_identifier '=' initializer
1072 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1073 decl->set_location(@2);
1075 $$ = new(ctx) ast_declarator_list($1);
1076 $$->set_location_range(@1, @2);
1077 $$->declarations.push_tail(&decl->link);
1079 | INVARIANT variable_identifier
1082 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1083 decl->set_location(@2);
1085 $$ = new(ctx) ast_declarator_list(NULL);
1086 $$->set_location_range(@1, @2);
1087 $$->invariant = true;
1089 $$->declarations.push_tail(&decl->link);
1091 | PRECISE variable_identifier
1094 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1095 decl->set_location(@2);
1097 $$ = new(ctx) ast_declarator_list(NULL);
1098 $$->set_location_range(@1, @2);
1101 $$->declarations.push_tail(&decl->link);
1105 fully_specified_type:
1109 $$ = new(ctx) ast_fully_specified_type();
1110 $$->set_location(@1);
1113 | type_qualifier type_specifier
1116 $$ = new(ctx) ast_fully_specified_type();
1117 $$->set_location_range(@1, @2);
1124 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1130 layout_qualifier_id_list:
1132 | layout_qualifier_id_list ',' layout_qualifier_id
1135 if (!$$.merge_qualifier(& @3, state, $3)) {
1142 INTCONSTANT { $$ = $1; }
1143 | UINTCONSTANT { $$ = $1; }
1146 layout_qualifier_id:
1149 memset(& $$, 0, sizeof($$));
1151 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1152 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1153 state->is_version(150, 0))) {
1154 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1155 $$.flags.q.origin_upper_left = 1;
1156 } else if (match_layout_qualifier($1, "pixel_center_integer",
1158 $$.flags.q.pixel_center_integer = 1;
1161 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1162 _mesa_glsl_warning(& @1, state,
1163 "GL_ARB_fragment_coord_conventions layout "
1164 "identifier `%s' used", $1);
1168 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1170 (state->AMD_conservative_depth_enable ||
1171 state->ARB_conservative_depth_enable ||
1172 state->is_version(420, 0))) {
1173 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1174 $$.flags.q.depth_any = 1;
1175 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1176 $$.flags.q.depth_greater = 1;
1177 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1178 $$.flags.q.depth_less = 1;
1179 } else if (match_layout_qualifier($1, "depth_unchanged",
1181 $$.flags.q.depth_unchanged = 1;
1184 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1185 _mesa_glsl_warning(& @1, state,
1186 "GL_AMD_conservative_depth "
1187 "layout qualifier `%s' is used", $1);
1189 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1190 _mesa_glsl_warning(& @1, state,
1191 "GL_ARB_conservative_depth "
1192 "layout qualifier `%s' is used", $1);
1196 /* See also interface_block_layout_qualifier. */
1197 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1198 if (match_layout_qualifier($1, "std140", state) == 0) {
1199 $$.flags.q.std140 = 1;
1200 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1201 $$.flags.q.shared = 1;
1202 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1203 $$.flags.q.std430 = 1;
1204 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1205 $$.flags.q.column_major = 1;
1206 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1207 * below in the interface_block_layout_qualifier rule.
1209 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1212 * Also, this takes care of alternate capitalizations of
1213 * "row_major" (which is necessary because layout qualifiers
1214 * are case-insensitive in desktop GLSL).
1216 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1217 $$.flags.q.row_major = 1;
1218 /* "packed" is a reserved word in GLSL, and its token is
1219 * parsed below in the interface_block_layout_qualifier rule.
1220 * However, we must take care of alternate capitalizations of
1221 * "packed", because layout qualifiers are case-insensitive
1224 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1225 $$.flags.q.packed = 1;
1228 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1229 _mesa_glsl_warning(& @1, state,
1230 "#version 140 / GL_ARB_uniform_buffer_object "
1231 "layout qualifier `%s' is used", $1);
1235 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1237 static const struct {
1241 { "points", GL_POINTS },
1242 { "lines", GL_LINES },
1243 { "lines_adjacency", GL_LINES_ADJACENCY },
1244 { "line_strip", GL_LINE_STRIP },
1245 { "triangles", GL_TRIANGLES },
1246 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1247 { "triangle_strip", GL_TRIANGLE_STRIP },
1249 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1250 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1251 $$.flags.q.prim_type = 1;
1252 $$.prim_type = map[i].e;
1257 if ($$.flags.i && !state->is_version(150, 0)) {
1258 _mesa_glsl_error(& @1, state, "#version 150 layout "
1259 "qualifier `%s' used", $1);
1263 /* Layout qualifiers for ARB_shader_image_load_store. */
1264 if (state->ARB_shader_image_load_store_enable ||
1265 state->is_version(420, 310)) {
1267 static const struct {
1270 glsl_base_type base_type;
1271 /** Minimum desktop GLSL version required for the image
1272 * format. Use 130 if already present in the original
1275 unsigned required_glsl;
1276 /** Minimum GLSL ES version required for the image format. */
1277 unsigned required_essl;
1279 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1280 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1281 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1282 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1283 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1284 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1285 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1286 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1287 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1288 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1289 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1290 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1291 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1292 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1293 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1294 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1295 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1296 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1297 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1298 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1299 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1300 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1301 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1302 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1303 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1304 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1305 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1306 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1307 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1308 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1309 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1310 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1311 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1312 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1313 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1314 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1315 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1316 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1317 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1320 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1321 if (state->is_version(map[i].required_glsl,
1322 map[i].required_essl) &&
1323 match_layout_qualifier($1, map[i].name, state) == 0) {
1324 $$.flags.q.explicit_image_format = 1;
1325 $$.image_format = map[i].format;
1326 $$.image_base_type = map[i].base_type;
1333 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1334 /* From section 4.4.1.3 of the GLSL 4.50 specification
1335 * (Fragment Shader Inputs):
1337 * "Fragment shaders also allow the following layout
1338 * qualifier on in only (not with variable declarations)
1339 * layout-qualifier-id
1340 * early_fragment_tests
1343 if (state->stage != MESA_SHADER_FRAGMENT) {
1344 _mesa_glsl_error(& @1, state,
1345 "early_fragment_tests layout qualifier only "
1346 "valid in fragment shaders");
1349 $$.flags.q.early_fragment_tests = 1;
1353 /* Layout qualifiers for tessellation evaluation shaders. */
1359 /* triangles already parsed by gs-specific code */
1360 { "quads", GL_QUADS },
1361 { "isolines", GL_ISOLINES },
1363 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1364 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1365 $$.flags.q.prim_type = 1;
1366 $$.prim_type = map[i].e;
1372 !state->ARB_tessellation_shader_enable &&
1373 !state->is_version(400, 0)) {
1374 _mesa_glsl_error(& @1, state,
1375 "primitive mode qualifier `%s' requires "
1376 "GLSL 4.00 or ARB_tessellation_shader", $1);
1384 { "equal_spacing", GL_EQUAL },
1385 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1386 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1388 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1389 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1390 $$.flags.q.vertex_spacing = 1;
1391 $$.vertex_spacing = map[i].e;
1397 !state->ARB_tessellation_shader_enable &&
1398 !state->is_version(400, 0)) {
1399 _mesa_glsl_error(& @1, state,
1400 "vertex spacing qualifier `%s' requires "
1401 "GLSL 4.00 or ARB_tessellation_shader", $1);
1405 if (match_layout_qualifier($1, "cw", state) == 0) {
1406 $$.flags.q.ordering = 1;
1407 $$.ordering = GL_CW;
1408 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1409 $$.flags.q.ordering = 1;
1410 $$.ordering = GL_CCW;
1414 !state->ARB_tessellation_shader_enable &&
1415 !state->is_version(400, 0)) {
1416 _mesa_glsl_error(& @1, state,
1417 "ordering qualifier `%s' requires "
1418 "GLSL 4.00 or ARB_tessellation_shader", $1);
1422 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1423 $$.flags.q.point_mode = 1;
1424 $$.point_mode = true;
1428 !state->ARB_tessellation_shader_enable &&
1429 !state->is_version(400, 0)) {
1430 _mesa_glsl_error(& @1, state,
1431 "qualifier `point_mode' requires "
1432 "GLSL 4.00 or ARB_tessellation_shader");
1437 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1442 | any_identifier '=' integer_constant
1444 memset(& $$, 0, sizeof($$));
1446 if (match_layout_qualifier("location", $1, state) == 0) {
1447 $$.flags.q.explicit_location = 1;
1449 if ($$.flags.q.attribute == 1 &&
1450 state->ARB_explicit_attrib_location_warn) {
1451 _mesa_glsl_warning(& @1, state,
1452 "GL_ARB_explicit_attrib_location layout "
1453 "identifier `%s' used", $1);
1459 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1464 if (match_layout_qualifier("index", $1, state) == 0) {
1465 $$.flags.q.explicit_index = 1;
1470 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1475 if ((state->has_420pack() ||
1476 state->has_atomic_counters() ||
1477 state->has_shader_storage_buffer_objects()) &&
1478 match_layout_qualifier("binding", $1, state) == 0) {
1479 $$.flags.q.explicit_binding = 1;
1483 if (state->has_atomic_counters() &&
1484 match_layout_qualifier("offset", $1, state) == 0) {
1485 $$.flags.q.explicit_offset = 1;
1489 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1490 $$.flags.q.max_vertices = 1;
1493 _mesa_glsl_error(& @3, state,
1494 "invalid max_vertices %d specified", $3);
1497 $$.max_vertices = $3;
1498 if (!state->is_version(150, 0)) {
1499 _mesa_glsl_error(& @3, state,
1500 "#version 150 max_vertices qualifier "
1506 if (state->stage == MESA_SHADER_GEOMETRY) {
1507 if (match_layout_qualifier("stream", $1, state) == 0 &&
1508 state->check_explicit_attrib_stream_allowed(& @3)) {
1509 $$.flags.q.stream = 1;
1512 _mesa_glsl_error(& @3, state,
1513 "invalid stream %d specified", $3);
1516 $$.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,
1531 _mesa_glsl_error(& @3, state,
1532 "invalid %s of %d specified",
1533 local_size_qualifiers[i], $3);
1535 } else if (!state->has_compute_shader()) {
1536 _mesa_glsl_error(& @3, state,
1537 "%s qualifier requires GLSL 4.30 or "
1538 "GLSL ES 3.10 or ARB_compute_shader",
1539 local_size_qualifiers[i]);
1542 $$.flags.q.local_size |= (1 << i);
1543 $$.local_size[i] = $3;
1549 if (match_layout_qualifier("invocations", $1, state) == 0) {
1550 $$.flags.q.invocations = 1;
1553 _mesa_glsl_error(& @3, state,
1554 "invalid invocations %d specified", $3);
1556 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1557 _mesa_glsl_error(& @3, state,
1558 "invocations (%d) exceeds "
1559 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1562 $$.invocations = $3;
1563 if (!state->is_version(400, 0) &&
1564 !state->ARB_gpu_shader5_enable) {
1565 _mesa_glsl_error(& @3, state,
1566 "GL_ARB_gpu_shader5 invocations "
1567 "qualifier specified", $3);
1572 /* Layout qualifiers for tessellation control shaders. */
1573 if (match_layout_qualifier("vertices", $1, state) == 0) {
1574 $$.flags.q.vertices = 1;
1577 _mesa_glsl_error(& @3, state,
1578 "invalid vertices (%d) specified", $3);
1580 } else if ($3 > (int)state->Const.MaxPatchVertices) {
1581 _mesa_glsl_error(& @3, state,
1582 "vertices (%d) exceeds "
1583 "GL_MAX_PATCH_VERTICES", $3);
1587 if (!state->ARB_tessellation_shader_enable &&
1588 !state->is_version(400, 0)) {
1589 _mesa_glsl_error(& @1, state,
1590 "vertices qualifier requires GLSL 4.00 or "
1591 "ARB_tessellation_shader");
1596 /* If the identifier didn't match any known layout identifiers,
1600 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1605 | interface_block_layout_qualifier
1608 /* Layout qualifiers for ARB_uniform_buffer_object. */
1609 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1610 _mesa_glsl_error(& @1, state,
1611 "#version 140 / GL_ARB_uniform_buffer_object "
1612 "layout qualifier `%s' is used", $1);
1613 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1614 _mesa_glsl_warning(& @1, state,
1615 "#version 140 / GL_ARB_uniform_buffer_object "
1616 "layout qualifier `%s' is used", $1);
1621 /* This is a separate language rule because we parse these as tokens
1622 * (due to them being reserved keywords) instead of identifiers like
1623 * most qualifiers. See the any_identifier path of
1624 * layout_qualifier_id for the others.
1626 * Note that since layout qualifiers are case-insensitive in desktop
1627 * GLSL, all of these qualifiers need to be handled as identifiers as
1628 * well (by the any_identifier path of layout_qualifier_id).
1630 interface_block_layout_qualifier:
1633 memset(& $$, 0, sizeof($$));
1634 $$.flags.q.row_major = 1;
1638 memset(& $$, 0, sizeof($$));
1639 $$.flags.q.packed = 1;
1643 subroutine_qualifier:
1646 memset(& $$, 0, sizeof($$));
1647 $$.flags.q.subroutine = 1;
1649 | SUBROUTINE '(' subroutine_type_list ')'
1651 memset(& $$, 0, sizeof($$));
1652 $$.flags.q.subroutine_def = 1;
1653 $$.subroutine_list = $3;
1657 subroutine_type_list:
1661 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1662 decl->set_location(@1);
1664 $$ = new(ctx) ast_subroutine_list();
1665 $$->declarations.push_tail(&decl->link);
1667 | subroutine_type_list ',' any_identifier
1670 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1671 decl->set_location(@3);
1674 $$->declarations.push_tail(&decl->link);
1678 interpolation_qualifier:
1681 memset(& $$, 0, sizeof($$));
1682 $$.flags.q.smooth = 1;
1686 memset(& $$, 0, sizeof($$));
1687 $$.flags.q.flat = 1;
1691 memset(& $$, 0, sizeof($$));
1692 $$.flags.q.noperspective = 1;
1697 /* Single qualifiers */
1700 memset(& $$, 0, sizeof($$));
1701 $$.flags.q.invariant = 1;
1705 memset(& $$, 0, sizeof($$));
1706 $$.flags.q.precise = 1;
1708 | auxiliary_storage_qualifier
1710 | interpolation_qualifier
1713 | subroutine_qualifier
1714 | precision_qualifier
1716 memset(&$$, 0, sizeof($$));
1720 /* Multiple qualifiers:
1721 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1722 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1724 * invariant interpolation auxiliary storage precision ...or...
1725 * layout storage precision
1727 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1728 * side don't contain any that must appear on the left hand side.
1729 * For example, when processing a storage qualifier, we check that there are
1730 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1732 | PRECISE type_qualifier
1734 if ($2.flags.q.precise)
1735 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1738 $$.flags.q.precise = 1;
1740 | INVARIANT type_qualifier
1742 if ($2.flags.q.invariant)
1743 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1745 if (!state->has_420pack() && $2.flags.q.precise)
1746 _mesa_glsl_error(&@1, state,
1747 "\"invariant\" must come after \"precise\"");
1750 $$.flags.q.invariant = 1;
1752 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1754 * "Only variables output from a shader can be candidates for invariance.
1755 * This includes user-defined output variables and the built-in output
1756 * variables. As only outputs can be declared as invariant, an invariant
1757 * output from one shader stage will still match an input of a subsequent
1758 * stage without the input being declared as invariant."
1760 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1761 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1763 | interpolation_qualifier type_qualifier
1765 /* Section 4.3 of the GLSL 1.40 specification states:
1766 * "...qualified with one of these interpolation qualifiers"
1768 * GLSL 1.30 claims to allow "one or more", but insists that:
1769 * "These interpolation qualifiers may only precede the qualifiers in,
1770 * centroid in, out, or centroid out in a declaration."
1772 * ...which means that e.g. smooth can't precede smooth, so there can be
1773 * only one after all, and the 1.40 text is a clarification, not a change.
1775 if ($2.has_interpolation())
1776 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1778 if (!state->has_420pack() &&
1779 ($2.flags.q.precise || $2.flags.q.invariant)) {
1780 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1781 "after \"precise\" or \"invariant\"");
1785 $$.merge_qualifier(&@1, state, $2);
1787 | layout_qualifier type_qualifier
1789 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1790 * appear no later than auxiliary storage qualifiers. There is no
1791 * particularly clear spec language mandating this, but in all examples
1792 * the layout qualifier precedes the storage qualifier.
1794 * We allow combinations of layout with interpolation, invariant or
1795 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1796 * There is no clear spec guidance on this either.
1798 if (!state->has_420pack() && $2.has_layout())
1799 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1802 $$.merge_qualifier(&@1, state, $2);
1804 | subroutine_qualifier type_qualifier
1807 $$.merge_qualifier(&@1, state, $2);
1809 | auxiliary_storage_qualifier type_qualifier
1811 if ($2.has_auxiliary_storage()) {
1812 _mesa_glsl_error(&@1, state,
1813 "duplicate auxiliary storage qualifier (centroid or sample)");
1816 if (!state->has_420pack() &&
1817 ($2.flags.q.precise || $2.flags.q.invariant ||
1818 $2.has_interpolation() || $2.has_layout())) {
1819 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1820 "just before storage qualifiers");
1823 $$.merge_qualifier(&@1, state, $2);
1825 | storage_qualifier type_qualifier
1827 /* Section 4.3 of the GLSL 1.20 specification states:
1828 * "Variable declarations may have a storage qualifier specified..."
1829 * 1.30 clarifies this to "may have one storage qualifier".
1831 if ($2.has_storage())
1832 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1834 if (!state->has_420pack() &&
1835 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1836 $2.has_layout() || $2.has_auxiliary_storage())) {
1837 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1838 "precise, invariant, interpolation, layout and auxiliary "
1839 "storage qualifiers");
1843 $$.merge_qualifier(&@1, state, $2);
1845 | precision_qualifier type_qualifier
1847 if ($2.precision != ast_precision_none)
1848 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1850 if (!state->has_420pack() && $2.flags.i != 0)
1851 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1856 | memory_qualifier type_qualifier
1859 $$.merge_qualifier(&@1, state, $2);
1863 auxiliary_storage_qualifier:
1866 memset(& $$, 0, sizeof($$));
1867 $$.flags.q.centroid = 1;
1871 memset(& $$, 0, sizeof($$));
1872 $$.flags.q.sample = 1;
1876 memset(& $$, 0, sizeof($$));
1877 $$.flags.q.patch = 1;
1883 memset(& $$, 0, sizeof($$));
1884 $$.flags.q.constant = 1;
1888 memset(& $$, 0, sizeof($$));
1889 $$.flags.q.attribute = 1;
1893 memset(& $$, 0, sizeof($$));
1894 $$.flags.q.varying = 1;
1898 memset(& $$, 0, sizeof($$));
1903 memset(& $$, 0, sizeof($$));
1906 if (state->stage == MESA_SHADER_GEOMETRY &&
1907 state->has_explicit_attrib_stream()) {
1908 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1911 * "If the block or variable is declared with the stream
1912 * identifier, it is associated with the specified stream;
1913 * otherwise, it is associated with the current default stream."
1915 $$.flags.q.stream = 1;
1916 $$.flags.q.explicit_stream = 0;
1917 $$.stream = state->out_qualifier->stream;
1922 memset(& $$, 0, sizeof($$));
1923 $$.flags.q.uniform = 1;
1927 memset(& $$, 0, sizeof($$));
1928 $$.flags.q.buffer = 1;
1935 memset(& $$, 0, sizeof($$));
1936 $$.flags.q.coherent = 1;
1940 memset(& $$, 0, sizeof($$));
1941 $$.flags.q._volatile = 1;
1945 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1946 memset(& $$, 0, sizeof($$));
1947 $$.flags.q.restrict_flag = 1;
1951 memset(& $$, 0, sizeof($$));
1952 $$.flags.q.read_only = 1;
1956 memset(& $$, 0, sizeof($$));
1957 $$.flags.q.write_only = 1;
1965 $$ = new(ctx) ast_array_specifier(@1);
1966 $$->set_location_range(@1, @2);
1968 | '[' constant_expression ']'
1971 $$ = new(ctx) ast_array_specifier(@1, $2);
1972 $$->set_location_range(@1, @3);
1974 | array_specifier '[' ']'
1978 if (!state->ARB_arrays_of_arrays_enable) {
1979 _mesa_glsl_error(& @1, state,
1980 "GL_ARB_arrays_of_arrays "
1981 "required for defining arrays of arrays");
1983 _mesa_glsl_error(& @1, state,
1984 "only the outermost array dimension can "
1988 | array_specifier '[' constant_expression ']'
1992 if (!state->ARB_arrays_of_arrays_enable) {
1993 _mesa_glsl_error(& @1, state,
1994 "GL_ARB_arrays_of_arrays "
1995 "required for defining arrays of arrays");
1998 $$->add_dimension($3);
2003 type_specifier_nonarray
2004 | type_specifier_nonarray array_specifier
2007 $$->array_specifier = $2;
2011 type_specifier_nonarray:
2012 basic_type_specifier_nonarray
2015 $$ = new(ctx) ast_type_specifier($1);
2016 $$->set_location(@1);
2021 $$ = new(ctx) ast_type_specifier($1);
2022 $$->set_location(@1);
2027 $$ = new(ctx) ast_type_specifier($1);
2028 $$->set_location(@1);
2032 basic_type_specifier_nonarray:
2033 VOID_TOK { $$ = "void"; }
2034 | FLOAT_TOK { $$ = "float"; }
2035 | DOUBLE_TOK { $$ = "double"; }
2036 | INT_TOK { $$ = "int"; }
2037 | UINT_TOK { $$ = "uint"; }
2038 | BOOL_TOK { $$ = "bool"; }
2039 | VEC2 { $$ = "vec2"; }
2040 | VEC3 { $$ = "vec3"; }
2041 | VEC4 { $$ = "vec4"; }
2042 | BVEC2 { $$ = "bvec2"; }
2043 | BVEC3 { $$ = "bvec3"; }
2044 | BVEC4 { $$ = "bvec4"; }
2045 | IVEC2 { $$ = "ivec2"; }
2046 | IVEC3 { $$ = "ivec3"; }
2047 | IVEC4 { $$ = "ivec4"; }
2048 | UVEC2 { $$ = "uvec2"; }
2049 | UVEC3 { $$ = "uvec3"; }
2050 | UVEC4 { $$ = "uvec4"; }
2051 | DVEC2 { $$ = "dvec2"; }
2052 | DVEC3 { $$ = "dvec3"; }
2053 | DVEC4 { $$ = "dvec4"; }
2054 | MAT2X2 { $$ = "mat2"; }
2055 | MAT2X3 { $$ = "mat2x3"; }
2056 | MAT2X4 { $$ = "mat2x4"; }
2057 | MAT3X2 { $$ = "mat3x2"; }
2058 | MAT3X3 { $$ = "mat3"; }
2059 | MAT3X4 { $$ = "mat3x4"; }
2060 | MAT4X2 { $$ = "mat4x2"; }
2061 | MAT4X3 { $$ = "mat4x3"; }
2062 | MAT4X4 { $$ = "mat4"; }
2063 | DMAT2X2 { $$ = "dmat2"; }
2064 | DMAT2X3 { $$ = "dmat2x3"; }
2065 | DMAT2X4 { $$ = "dmat2x4"; }
2066 | DMAT3X2 { $$ = "dmat3x2"; }
2067 | DMAT3X3 { $$ = "dmat3"; }
2068 | DMAT3X4 { $$ = "dmat3x4"; }
2069 | DMAT4X2 { $$ = "dmat4x2"; }
2070 | DMAT4X3 { $$ = "dmat4x3"; }
2071 | DMAT4X4 { $$ = "dmat4"; }
2072 | SAMPLER1D { $$ = "sampler1D"; }
2073 | SAMPLER2D { $$ = "sampler2D"; }
2074 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2075 | SAMPLER3D { $$ = "sampler3D"; }
2076 | SAMPLERCUBE { $$ = "samplerCube"; }
2077 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2078 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2079 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2080 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2081 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2082 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2083 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2084 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2085 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2086 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2087 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2088 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2089 | ISAMPLER1D { $$ = "isampler1D"; }
2090 | ISAMPLER2D { $$ = "isampler2D"; }
2091 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2092 | ISAMPLER3D { $$ = "isampler3D"; }
2093 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2094 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2095 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2096 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2097 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2098 | USAMPLER1D { $$ = "usampler1D"; }
2099 | USAMPLER2D { $$ = "usampler2D"; }
2100 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2101 | USAMPLER3D { $$ = "usampler3D"; }
2102 | USAMPLERCUBE { $$ = "usamplerCube"; }
2103 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2104 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2105 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2106 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2107 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2108 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2109 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2110 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2111 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2112 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2113 | IMAGE1D { $$ = "image1D"; }
2114 | IMAGE2D { $$ = "image2D"; }
2115 | IMAGE3D { $$ = "image3D"; }
2116 | IMAGE2DRECT { $$ = "image2DRect"; }
2117 | IMAGECUBE { $$ = "imageCube"; }
2118 | IMAGEBUFFER { $$ = "imageBuffer"; }
2119 | IMAGE1DARRAY { $$ = "image1DArray"; }
2120 | IMAGE2DARRAY { $$ = "image2DArray"; }
2121 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2122 | IMAGE2DMS { $$ = "image2DMS"; }
2123 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2124 | IIMAGE1D { $$ = "iimage1D"; }
2125 | IIMAGE2D { $$ = "iimage2D"; }
2126 | IIMAGE3D { $$ = "iimage3D"; }
2127 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2128 | IIMAGECUBE { $$ = "iimageCube"; }
2129 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2130 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2131 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2132 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2133 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2134 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2135 | UIMAGE1D { $$ = "uimage1D"; }
2136 | UIMAGE2D { $$ = "uimage2D"; }
2137 | UIMAGE3D { $$ = "uimage3D"; }
2138 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2139 | UIMAGECUBE { $$ = "uimageCube"; }
2140 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2141 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2142 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2143 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2144 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2145 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2146 | ATOMIC_UINT { $$ = "atomic_uint"; }
2149 precision_qualifier:
2152 state->check_precision_qualifiers_allowed(&@1);
2153 $$ = ast_precision_high;
2157 state->check_precision_qualifiers_allowed(&@1);
2158 $$ = ast_precision_medium;
2162 state->check_precision_qualifiers_allowed(&@1);
2163 $$ = ast_precision_low;
2168 STRUCT any_identifier '{' struct_declaration_list '}'
2171 $$ = new(ctx) ast_struct_specifier($2, $4);
2172 $$->set_location_range(@2, @5);
2173 state->symbols->add_type($2, glsl_type::void_type);
2175 | STRUCT '{' struct_declaration_list '}'
2178 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2179 $$->set_location_range(@2, @4);
2183 struct_declaration_list:
2187 $1->link.self_link();
2189 | struct_declaration_list struct_declaration
2192 $$->link.insert_before(& $2->link);
2197 fully_specified_type struct_declarator_list ';'
2200 ast_fully_specified_type *const type = $1;
2201 type->set_location(@1);
2203 if (type->qualifier.flags.i != 0)
2204 _mesa_glsl_error(&@1, state,
2205 "only precision qualifiers may be applied to "
2206 "structure members");
2208 $$ = new(ctx) ast_declarator_list(type);
2209 $$->set_location(@2);
2211 $$->declarations.push_degenerate_list_at_head(& $2->link);
2215 struct_declarator_list:
2219 $1->link.self_link();
2221 | struct_declarator_list ',' struct_declarator
2224 $$->link.insert_before(& $3->link);
2232 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2233 $$->set_location(@1);
2235 | any_identifier array_specifier
2238 $$ = new(ctx) ast_declaration($1, $2, NULL);
2239 $$->set_location_range(@1, @2);
2244 assignment_expression
2245 | '{' initializer_list '}'
2249 | '{' initializer_list ',' '}'
2259 $$ = new(ctx) ast_aggregate_initializer();
2260 $$->set_location(@1);
2261 $$->expressions.push_tail(& $1->link);
2263 | initializer_list ',' initializer
2265 $1->expressions.push_tail(& $3->link);
2269 declaration_statement:
2273 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2276 compound_statement { $$ = (ast_node *) $1; }
2281 declaration_statement
2282 | expression_statement
2283 | selection_statement
2285 | iteration_statement
2293 $$ = new(ctx) ast_compound_statement(true, NULL);
2294 $$->set_location_range(@1, @2);
2298 state->symbols->push_scope();
2303 $$ = new(ctx) ast_compound_statement(true, $3);
2304 $$->set_location_range(@1, @4);
2305 state->symbols->pop_scope();
2309 statement_no_new_scope:
2310 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2314 compound_statement_no_new_scope:
2318 $$ = new(ctx) ast_compound_statement(false, NULL);
2319 $$->set_location_range(@1, @2);
2321 | '{' statement_list '}'
2324 $$ = new(ctx) ast_compound_statement(false, $2);
2325 $$->set_location_range(@1, @3);
2333 _mesa_glsl_error(& @1, state, "<nil> statement");
2338 $$->link.self_link();
2340 | statement_list statement
2343 _mesa_glsl_error(& @2, state, "<nil> statement");
2347 $$->link.insert_before(& $2->link);
2351 expression_statement:
2355 $$ = new(ctx) ast_expression_statement(NULL);
2356 $$->set_location(@1);
2361 $$ = new(ctx) ast_expression_statement($1);
2362 $$->set_location(@1);
2366 selection_statement:
2367 IF '(' expression ')' selection_rest_statement
2369 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2371 $$->set_location_range(@1, @5);
2375 selection_rest_statement:
2376 statement ELSE statement
2378 $$.then_statement = $1;
2379 $$.else_statement = $3;
2381 | statement %prec THEN
2383 $$.then_statement = $1;
2384 $$.else_statement = NULL;
2391 $$ = (ast_node *) $1;
2393 | fully_specified_type any_identifier '=' initializer
2396 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2397 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2398 decl->set_location_range(@2, @4);
2399 declarator->set_location(@1);
2401 declarator->declarations.push_tail(&decl->link);
2407 * switch_statement grammar is based on the syntax described in the body
2408 * of the GLSL spec, not in it's appendix!!!
2411 SWITCH '(' expression ')' switch_body
2413 $$ = new(state) ast_switch_statement($3, $5);
2414 $$->set_location_range(@1, @5);
2421 $$ = new(state) ast_switch_body(NULL);
2422 $$->set_location_range(@1, @2);
2424 | '{' case_statement_list '}'
2426 $$ = new(state) ast_switch_body($2);
2427 $$->set_location_range(@1, @3);
2434 $$ = new(state) ast_case_label($2);
2435 $$->set_location(@2);
2439 $$ = new(state) ast_case_label(NULL);
2440 $$->set_location(@2);
2447 ast_case_label_list *labels = new(state) ast_case_label_list();
2449 labels->labels.push_tail(& $1->link);
2451 $$->set_location(@1);
2453 | case_label_list case_label
2456 $$->labels.push_tail(& $2->link);
2461 case_label_list statement
2463 ast_case_statement *stmts = new(state) ast_case_statement($1);
2464 stmts->set_location(@2);
2466 stmts->stmts.push_tail(& $2->link);
2469 | case_statement statement
2472 $$->stmts.push_tail(& $2->link);
2476 case_statement_list:
2479 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2480 cases->set_location(@1);
2482 cases->cases.push_tail(& $1->link);
2485 | case_statement_list case_statement
2488 $$->cases.push_tail(& $2->link);
2492 iteration_statement:
2493 WHILE '(' condition ')' statement_no_new_scope
2496 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2497 NULL, $3, NULL, $5);
2498 $$->set_location_range(@1, @4);
2500 | DO statement WHILE '(' expression ')' ';'
2503 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2504 NULL, $5, NULL, $2);
2505 $$->set_location_range(@1, @6);
2507 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2510 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2511 $3, $4.cond, $4.rest, $6);
2512 $$->set_location_range(@1, @6);
2517 expression_statement
2518 | declaration_statement
2535 | conditionopt ';' expression
2542 // Grammar Note: No 'goto'. Gotos are not supported.
2547 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2548 $$->set_location(@1);
2553 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2554 $$->set_location(@1);
2559 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2560 $$->set_location(@1);
2562 | RETURN expression ';'
2565 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2566 $$->set_location_range(@1, @2);
2568 | DISCARD ';' // Fragment shader only.
2571 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2572 $$->set_location(@1);
2576 external_declaration:
2577 function_definition { $$ = $1; }
2578 | declaration { $$ = $1; }
2579 | pragma_statement { $$ = NULL; }
2580 | layout_defaults { $$ = $1; }
2583 function_definition:
2584 function_prototype compound_statement_no_new_scope
2587 $$ = new(ctx) ast_function_definition();
2588 $$->set_location_range(@1, @2);
2592 state->symbols->pop_scope();
2596 /* layout_qualifieropt is packed into this rule */
2598 basic_interface_block
2602 | layout_qualifier interface_block
2604 ast_interface_block *block = (ast_interface_block *) $2;
2606 if (!state->has_420pack() && block->layout.has_layout() &&
2607 !block->layout.is_default_qualifier) {
2608 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2612 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2616 block->layout.is_default_qualifier = false;
2618 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2619 ast_type_qualifier& qualifier = member->type->qualifier;
2620 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2621 _mesa_glsl_error(& @1, state,
2622 "stream layout qualifier on "
2623 "interface block member does not match "
2624 "the interface block (%d vs %d)",
2625 qualifier.stream, block->layout.stream);
2631 | memory_qualifier interface_block
2633 ast_interface_block *block = (ast_interface_block *)$2;
2635 if (!block->layout.flags.q.buffer) {
2636 _mesa_glsl_error(& @1, state,
2637 "memory qualifiers can only be used in the "
2638 "declaration of shader storage blocks");
2640 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2647 basic_interface_block:
2648 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2650 ast_interface_block *const block = $6;
2652 block->block_name = $2;
2653 block->declarations.push_degenerate_list_at_head(& $4->link);
2655 _mesa_ast_process_interface_block(& @1, state, block, $1);
2659 | buffer_interface_qualifier NEW_IDENTIFIER '{' member_list '}' buffer_instance_name_opt ';'
2661 ast_interface_block *const block = $6;
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 memset(& $$, 0, sizeof($$));
2686 $$.flags.q.uniform = 1;
2690 buffer_interface_qualifier:
2693 memset(& $$, 0, sizeof($$));
2694 $$.flags.q.buffer = 1;
2701 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2706 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2708 $$->set_location(@1);
2710 | NEW_IDENTIFIER array_specifier
2712 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2714 $$->set_location_range(@1, @2);
2718 buffer_instance_name_opt:
2721 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2726 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2728 $$->set_location(@1);
2730 | NEW_IDENTIFIER array_specifier
2732 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2734 $$->set_location_range(@1, @2);
2742 $1->link.self_link();
2744 | member_declaration member_list
2747 $2->link.insert_before(& $$->link);
2752 fully_specified_type struct_declarator_list ';'
2755 ast_fully_specified_type *type = $1;
2756 type->set_location(@1);
2758 if (type->qualifier.flags.q.attribute) {
2759 _mesa_glsl_error(& @1, state,
2760 "keyword 'attribute' cannot be used with "
2761 "interface block member");
2762 } else if (type->qualifier.flags.q.varying) {
2763 _mesa_glsl_error(& @1, state,
2764 "keyword 'varying' cannot be used with "
2765 "interface block member");
2768 $$ = new(ctx) ast_declarator_list(type);
2769 $$->set_location(@2);
2771 $$->declarations.push_degenerate_list_at_head(& $2->link);
2776 layout_qualifier UNIFORM ';'
2778 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2784 | layout_qualifier BUFFER ';'
2786 if (!state->default_shader_storage_qualifier->merge_qualifier(& @1, state, $1)) {
2792 | layout_qualifier IN_TOK ';'
2795 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2800 | layout_qualifier OUT_TOK ';'
2803 if (state->stage == MESA_SHADER_GEOMETRY) {
2804 if ($1.flags.q.prim_type) {
2805 /* Make sure this is a valid output primitive type. */
2806 switch ($1.prim_type) {
2809 case GL_TRIANGLE_STRIP:
2812 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2817 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2820 /* Allow future assigments of global out's stream id value */
2821 state->out_qualifier->flags.q.explicit_stream = 0;
2822 } else if (state->stage == MESA_SHADER_TESS_CTRL) {
2823 if (!state->out_qualifier->merge_out_qualifier(& @1, state, $1, $$))
2826 _mesa_glsl_error(& @1, state,
2827 "out layout qualifiers only valid in "
2828 "tessellation control or geometry shaders");