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 %token <real> FLOATCONSTANT
173 %token <dreal> DOUBLECONSTANT
174 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
175 %token <identifier> FIELD_SELECTION
176 %token LEFT_OP RIGHT_OP
177 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
178 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
179 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
181 %token INVARIANT PRECISE
182 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
184 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
185 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
186 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
187 %token PRAGMA_INVARIANT_ALL
190 /* Reserved words that are not actually used in the grammar.
192 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
193 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
194 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
195 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
197 %token SIZEOF CAST NAMESPACE USING
198 %token RESOURCE PATCH
203 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
205 %type <identifier> variable_identifier
206 %type <node> statement
207 %type <node> statement_list
208 %type <node> simple_statement
209 %type <n> precision_qualifier
210 %type <type_qualifier> type_qualifier
211 %type <type_qualifier> auxiliary_storage_qualifier
212 %type <type_qualifier> storage_qualifier
213 %type <type_qualifier> interpolation_qualifier
214 %type <type_qualifier> layout_qualifier
215 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
216 %type <type_qualifier> interface_block_layout_qualifier
217 %type <type_qualifier> memory_qualifier
218 %type <type_qualifier> subroutine_qualifier
219 %type <subroutine_list> subroutine_type_list
220 %type <type_qualifier> interface_qualifier
221 %type <type_specifier> type_specifier
222 %type <type_specifier> type_specifier_nonarray
223 %type <array_specifier> array_specifier
224 %type <identifier> basic_type_specifier_nonarray
225 %type <fully_specified_type> fully_specified_type
226 %type <function> function_prototype
227 %type <function> function_header
228 %type <function> function_header_with_parameters
229 %type <function> function_declarator
230 %type <parameter_declarator> parameter_declarator
231 %type <parameter_declarator> parameter_declaration
232 %type <type_qualifier> parameter_qualifier
233 %type <type_qualifier> parameter_direction_qualifier
234 %type <type_specifier> parameter_type_specifier
235 %type <function_definition> function_definition
236 %type <compound_statement> compound_statement_no_new_scope
237 %type <compound_statement> compound_statement
238 %type <node> statement_no_new_scope
239 %type <node> expression_statement
240 %type <expression> expression
241 %type <expression> primary_expression
242 %type <expression> assignment_expression
243 %type <expression> conditional_expression
244 %type <expression> logical_or_expression
245 %type <expression> logical_xor_expression
246 %type <expression> logical_and_expression
247 %type <expression> inclusive_or_expression
248 %type <expression> exclusive_or_expression
249 %type <expression> and_expression
250 %type <expression> equality_expression
251 %type <expression> relational_expression
252 %type <expression> shift_expression
253 %type <expression> additive_expression
254 %type <expression> multiplicative_expression
255 %type <expression> unary_expression
256 %type <expression> constant_expression
257 %type <expression> integer_expression
258 %type <expression> postfix_expression
259 %type <expression> function_call_header_with_parameters
260 %type <expression> function_call_header_no_parameters
261 %type <expression> function_call_header
262 %type <expression> function_call_generic
263 %type <expression> function_call_or_method
264 %type <expression> function_call
265 %type <n> assignment_operator
266 %type <n> unary_operator
267 %type <expression> function_identifier
268 %type <node> external_declaration
269 %type <declarator_list> init_declarator_list
270 %type <declarator_list> single_declaration
271 %type <expression> initializer
272 %type <expression> initializer_list
273 %type <node> declaration
274 %type <node> declaration_statement
275 %type <node> jump_statement
276 %type <node> interface_block
277 %type <interface_block> basic_interface_block
278 %type <struct_specifier> struct_specifier
279 %type <declarator_list> struct_declaration_list
280 %type <declarator_list> struct_declaration
281 %type <declaration> struct_declarator
282 %type <declaration> struct_declarator_list
283 %type <declarator_list> member_list
284 %type <declarator_list> member_declaration
285 %type <node> selection_statement
286 %type <selection_rest_statement> selection_rest_statement
287 %type <node> switch_statement
288 %type <switch_body> switch_body
289 %type <case_label_list> case_label_list
290 %type <case_label> case_label
291 %type <case_statement> case_statement
292 %type <case_statement_list> case_statement_list
293 %type <node> iteration_statement
294 %type <node> condition
295 %type <node> conditionopt
296 %type <node> for_init_statement
297 %type <for_rest_statement> for_rest_statement
298 %type <n> integer_constant
299 %type <node> layout_defaults
305 version_statement extension_statement_list
307 _mesa_glsl_initialize_types(state);
309 external_declaration_list
311 delete state->symbols;
312 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
313 _mesa_glsl_initialize_types(state);
318 /* blank - no #version specified: defaults are already set */
319 | VERSION_TOK INTCONSTANT EOL
321 state->process_version_directive(&@2, $2, NULL);
326 | VERSION_TOK INTCONSTANT any_identifier EOL
328 state->process_version_directive(&@2, $2, $3);
337 | PRAGMA_DEBUG_OFF EOL
338 | PRAGMA_OPTIMIZE_ON EOL
339 | PRAGMA_OPTIMIZE_OFF EOL
340 | PRAGMA_INVARIANT_ALL EOL
342 /* Pragma invariant(all) cannot be used in a fragment shader.
344 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
346 * "It is an error to use this pragma in a fragment shader."
348 if (state->is_version(120, 300) &&
349 state->stage == MESA_SHADER_FRAGMENT) {
350 _mesa_glsl_error(& @1, state,
351 "pragma `invariant(all)' cannot be used "
352 "in a fragment shader.");
353 } else if (!state->is_version(120, 100)) {
354 _mesa_glsl_warning(& @1, state,
355 "pragma `invariant(all)' not supported in %s "
356 "(GLSL ES 1.00 or GLSL 1.20 required)",
357 state->get_version_string());
359 state->all_invariant = true;
364 extension_statement_list:
366 | extension_statement_list extension_statement
376 EXTENSION any_identifier COLON any_identifier EOL
378 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
384 external_declaration_list:
387 /* FINISHME: The NULL test is required because pragmas are set to
388 * FINISHME: NULL. (See production rule for external_declaration.)
391 state->translation_unit.push_tail(& $1->link);
393 | external_declaration_list external_declaration
395 /* FINISHME: The NULL test is required because pragmas are set to
396 * FINISHME: NULL. (See production rule for external_declaration.)
399 state->translation_unit.push_tail(& $2->link);
401 | external_declaration_list extension_statement {
402 if (!state->allow_extension_directive_midshader) {
403 _mesa_glsl_error(& @2, state,
404 "#extension directive is not allowed "
405 "in the middle of a shader");
420 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
421 $$->set_location(@1);
422 $$->primary_expression.identifier = $1;
427 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
428 $$->set_location(@1);
429 $$->primary_expression.int_constant = $1;
434 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
435 $$->set_location(@1);
436 $$->primary_expression.uint_constant = $1;
441 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
442 $$->set_location(@1);
443 $$->primary_expression.float_constant = $1;
448 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
449 $$->set_location(@1);
450 $$->primary_expression.double_constant = $1;
455 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
456 $$->set_location(@1);
457 $$->primary_expression.bool_constant = $1;
467 | postfix_expression '[' integer_expression ']'
470 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
471 $$->set_location_range(@1, @4);
477 | postfix_expression DOT_TOK FIELD_SELECTION
480 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
481 $$->set_location_range(@1, @3);
482 $$->primary_expression.identifier = $3;
484 | postfix_expression INC_OP
487 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
488 $$->set_location_range(@1, @2);
490 | postfix_expression DEC_OP
493 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
494 $$->set_location_range(@1, @2);
503 function_call_or_method
506 function_call_or_method:
507 function_call_generic
510 function_call_generic:
511 function_call_header_with_parameters ')'
512 | function_call_header_no_parameters ')'
515 function_call_header_no_parameters:
516 function_call_header VOID_TOK
517 | function_call_header
520 function_call_header_with_parameters:
521 function_call_header assignment_expression
524 $$->set_location(@1);
525 $$->expressions.push_tail(& $2->link);
527 | function_call_header_with_parameters ',' assignment_expression
530 $$->set_location(@1);
531 $$->expressions.push_tail(& $3->link);
535 // Grammar Note: Constructors look like functions, but lexical
536 // analysis recognized most of them as keywords. They are now
537 // recognized through "type_specifier".
538 function_call_header:
539 function_identifier '('
546 $$ = new(ctx) ast_function_expression($1);
547 $$->set_location(@1);
552 $$ = new(ctx) ast_function_expression($1);
553 $$->set_location(@1);
557 // Grammar Note: Constructors look like methods, but lexical
558 // analysis recognized most of them as keywords. They are now
559 // recognized through "type_specifier".
561 // Grammar Note: No traditional style type casts.
564 | INC_OP unary_expression
567 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
568 $$->set_location(@1);
570 | DEC_OP unary_expression
573 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
574 $$->set_location(@1);
576 | unary_operator unary_expression
579 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
580 $$->set_location_range(@1, @2);
584 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
586 '+' { $$ = ast_plus; }
587 | '-' { $$ = ast_neg; }
588 | '!' { $$ = ast_logic_not; }
589 | '~' { $$ = ast_bit_not; }
592 multiplicative_expression:
594 | multiplicative_expression '*' unary_expression
597 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
598 $$->set_location_range(@1, @3);
600 | multiplicative_expression '/' unary_expression
603 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
604 $$->set_location_range(@1, @3);
606 | multiplicative_expression '%' unary_expression
609 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
610 $$->set_location_range(@1, @3);
615 multiplicative_expression
616 | additive_expression '+' multiplicative_expression
619 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
620 $$->set_location_range(@1, @3);
622 | additive_expression '-' multiplicative_expression
625 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
626 $$->set_location_range(@1, @3);
632 | shift_expression LEFT_OP additive_expression
635 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
636 $$->set_location_range(@1, @3);
638 | shift_expression RIGHT_OP additive_expression
641 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
642 $$->set_location_range(@1, @3);
646 relational_expression:
648 | relational_expression '<' shift_expression
651 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
652 $$->set_location_range(@1, @3);
654 | relational_expression '>' shift_expression
657 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
658 $$->set_location_range(@1, @3);
660 | relational_expression LE_OP shift_expression
663 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
664 $$->set_location_range(@1, @3);
666 | relational_expression GE_OP shift_expression
669 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
670 $$->set_location_range(@1, @3);
675 relational_expression
676 | equality_expression EQ_OP relational_expression
679 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
680 $$->set_location_range(@1, @3);
682 | equality_expression NE_OP relational_expression
685 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
686 $$->set_location_range(@1, @3);
692 | and_expression '&' equality_expression
695 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
696 $$->set_location_range(@1, @3);
700 exclusive_or_expression:
702 | exclusive_or_expression '^' and_expression
705 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
706 $$->set_location_range(@1, @3);
710 inclusive_or_expression:
711 exclusive_or_expression
712 | inclusive_or_expression '|' exclusive_or_expression
715 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
716 $$->set_location_range(@1, @3);
720 logical_and_expression:
721 inclusive_or_expression
722 | logical_and_expression AND_OP inclusive_or_expression
725 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
726 $$->set_location_range(@1, @3);
730 logical_xor_expression:
731 logical_and_expression
732 | logical_xor_expression XOR_OP logical_and_expression
735 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
736 $$->set_location_range(@1, @3);
740 logical_or_expression:
741 logical_xor_expression
742 | logical_or_expression OR_OP logical_xor_expression
745 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
746 $$->set_location_range(@1, @3);
750 conditional_expression:
751 logical_or_expression
752 | logical_or_expression '?' expression ':' assignment_expression
755 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
756 $$->set_location_range(@1, @5);
760 assignment_expression:
761 conditional_expression
762 | unary_expression assignment_operator assignment_expression
765 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
766 $$->set_location_range(@1, @3);
771 '=' { $$ = ast_assign; }
772 | MUL_ASSIGN { $$ = ast_mul_assign; }
773 | DIV_ASSIGN { $$ = ast_div_assign; }
774 | MOD_ASSIGN { $$ = ast_mod_assign; }
775 | ADD_ASSIGN { $$ = ast_add_assign; }
776 | SUB_ASSIGN { $$ = ast_sub_assign; }
777 | LEFT_ASSIGN { $$ = ast_ls_assign; }
778 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
779 | AND_ASSIGN { $$ = ast_and_assign; }
780 | XOR_ASSIGN { $$ = ast_xor_assign; }
781 | OR_ASSIGN { $$ = ast_or_assign; }
785 assignment_expression
789 | expression ',' assignment_expression
792 if ($1->oper != ast_sequence) {
793 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
794 $$->set_location_range(@1, @3);
795 $$->expressions.push_tail(& $1->link);
800 $$->expressions.push_tail(& $3->link);
805 conditional_expression
809 function_prototype ';'
811 state->symbols->pop_scope();
814 | init_declarator_list ';'
818 | PRECISION precision_qualifier type_specifier ';'
820 $3->default_precision = $2;
830 function_declarator ')'
835 | function_header_with_parameters
838 function_header_with_parameters:
839 function_header parameter_declaration
842 $$->parameters.push_tail(& $2->link);
844 | function_header_with_parameters ',' parameter_declaration
847 $$->parameters.push_tail(& $3->link);
852 fully_specified_type variable_identifier '('
855 $$ = new(ctx) ast_function();
856 $$->set_location(@2);
857 $$->return_type = $1;
860 if ($1->qualifier.flags.q.subroutine) {
861 /* add type for IDENTIFIER search */
862 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
864 state->symbols->add_function(new(state) ir_function($2));
865 state->symbols->push_scope();
869 parameter_declarator:
870 type_specifier any_identifier
873 $$ = new(ctx) ast_parameter_declarator();
874 $$->set_location_range(@1, @2);
875 $$->type = new(ctx) ast_fully_specified_type();
876 $$->type->set_location(@1);
877 $$->type->specifier = $1;
880 | type_specifier any_identifier array_specifier
883 $$ = new(ctx) ast_parameter_declarator();
884 $$->set_location_range(@1, @3);
885 $$->type = new(ctx) ast_fully_specified_type();
886 $$->type->set_location(@1);
887 $$->type->specifier = $1;
889 $$->array_specifier = $3;
893 parameter_declaration:
894 parameter_qualifier parameter_declarator
897 $$->type->qualifier = $1;
899 | parameter_qualifier parameter_type_specifier
902 $$ = new(ctx) ast_parameter_declarator();
903 $$->set_location(@2);
904 $$->type = new(ctx) ast_fully_specified_type();
905 $$->type->set_location_range(@1, @2);
906 $$->type->qualifier = $1;
907 $$->type->specifier = $2;
914 memset(& $$, 0, sizeof($$));
916 | CONST_TOK parameter_qualifier
918 if ($2.flags.q.constant)
919 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
922 $$.flags.q.constant = 1;
924 | PRECISE parameter_qualifier
926 if ($2.flags.q.precise)
927 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
930 $$.flags.q.precise = 1;
932 | parameter_direction_qualifier parameter_qualifier
934 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
935 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
937 if (!state->has_420pack() && $2.flags.q.constant)
938 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
942 $$.merge_qualifier(&@1, state, $2);
944 | precision_qualifier parameter_qualifier
946 if ($2.precision != ast_precision_none)
947 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
949 if (!state->has_420pack() && $2.flags.i != 0)
950 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
955 | memory_qualifier parameter_qualifier
958 $$.merge_qualifier(&@1, state, $2);
961 parameter_direction_qualifier:
964 memset(& $$, 0, sizeof($$));
969 memset(& $$, 0, sizeof($$));
974 memset(& $$, 0, sizeof($$));
980 parameter_type_specifier:
984 init_declarator_list:
986 | init_declarator_list ',' any_identifier
989 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
990 decl->set_location(@3);
993 $$->declarations.push_tail(&decl->link);
994 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
996 | init_declarator_list ',' any_identifier array_specifier
999 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1000 decl->set_location_range(@3, @4);
1003 $$->declarations.push_tail(&decl->link);
1004 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1006 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1009 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1010 decl->set_location_range(@3, @4);
1013 $$->declarations.push_tail(&decl->link);
1014 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1016 | init_declarator_list ',' any_identifier '=' initializer
1019 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1020 decl->set_location(@3);
1023 $$->declarations.push_tail(&decl->link);
1024 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1028 // Grammar Note: No 'enum', or 'typedef'.
1030 fully_specified_type
1033 /* Empty declaration list is valid. */
1034 $$ = new(ctx) ast_declarator_list($1);
1035 $$->set_location(@1);
1037 | fully_specified_type any_identifier
1040 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1041 decl->set_location(@2);
1043 $$ = new(ctx) ast_declarator_list($1);
1044 $$->set_location_range(@1, @2);
1045 $$->declarations.push_tail(&decl->link);
1047 | fully_specified_type any_identifier array_specifier
1050 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1051 decl->set_location_range(@2, @3);
1053 $$ = new(ctx) ast_declarator_list($1);
1054 $$->set_location_range(@1, @3);
1055 $$->declarations.push_tail(&decl->link);
1057 | fully_specified_type any_identifier array_specifier '=' initializer
1060 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1061 decl->set_location_range(@2, @3);
1063 $$ = new(ctx) ast_declarator_list($1);
1064 $$->set_location_range(@1, @3);
1065 $$->declarations.push_tail(&decl->link);
1067 | fully_specified_type any_identifier '=' initializer
1070 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1071 decl->set_location(@2);
1073 $$ = new(ctx) ast_declarator_list($1);
1074 $$->set_location_range(@1, @2);
1075 $$->declarations.push_tail(&decl->link);
1077 | INVARIANT variable_identifier
1080 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1081 decl->set_location(@2);
1083 $$ = new(ctx) ast_declarator_list(NULL);
1084 $$->set_location_range(@1, @2);
1085 $$->invariant = true;
1087 $$->declarations.push_tail(&decl->link);
1089 | PRECISE variable_identifier
1092 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1093 decl->set_location(@2);
1095 $$ = new(ctx) ast_declarator_list(NULL);
1096 $$->set_location_range(@1, @2);
1099 $$->declarations.push_tail(&decl->link);
1103 fully_specified_type:
1107 $$ = new(ctx) ast_fully_specified_type();
1108 $$->set_location(@1);
1111 | type_qualifier type_specifier
1114 $$ = new(ctx) ast_fully_specified_type();
1115 $$->set_location_range(@1, @2);
1122 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1128 layout_qualifier_id_list:
1130 | layout_qualifier_id_list ',' layout_qualifier_id
1133 if (!$$.merge_qualifier(& @3, state, $3)) {
1140 INTCONSTANT { $$ = $1; }
1141 | UINTCONSTANT { $$ = $1; }
1144 layout_qualifier_id:
1147 memset(& $$, 0, sizeof($$));
1149 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1150 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1151 state->is_version(150, 0))) {
1152 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1153 $$.flags.q.origin_upper_left = 1;
1154 } else if (match_layout_qualifier($1, "pixel_center_integer",
1156 $$.flags.q.pixel_center_integer = 1;
1159 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1160 _mesa_glsl_warning(& @1, state,
1161 "GL_ARB_fragment_coord_conventions layout "
1162 "identifier `%s' used", $1);
1166 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1168 (state->AMD_conservative_depth_enable ||
1169 state->ARB_conservative_depth_enable ||
1170 state->is_version(420, 0))) {
1171 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1172 $$.flags.q.depth_any = 1;
1173 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1174 $$.flags.q.depth_greater = 1;
1175 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1176 $$.flags.q.depth_less = 1;
1177 } else if (match_layout_qualifier($1, "depth_unchanged",
1179 $$.flags.q.depth_unchanged = 1;
1182 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1183 _mesa_glsl_warning(& @1, state,
1184 "GL_AMD_conservative_depth "
1185 "layout qualifier `%s' is used", $1);
1187 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1188 _mesa_glsl_warning(& @1, state,
1189 "GL_ARB_conservative_depth "
1190 "layout qualifier `%s' is used", $1);
1194 /* See also interface_block_layout_qualifier. */
1195 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1196 if (match_layout_qualifier($1, "std140", state) == 0) {
1197 $$.flags.q.std140 = 1;
1198 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1199 $$.flags.q.shared = 1;
1200 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1201 $$.flags.q.column_major = 1;
1202 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1203 * below in the interface_block_layout_qualifier rule.
1205 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1208 * Also, this takes care of alternate capitalizations of
1209 * "row_major" (which is necessary because layout qualifiers
1210 * are case-insensitive in desktop GLSL).
1212 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1213 $$.flags.q.row_major = 1;
1214 /* "packed" is a reserved word in GLSL, and its token is
1215 * parsed below in the interface_block_layout_qualifier rule.
1216 * However, we must take care of alternate capitalizations of
1217 * "packed", because layout qualifiers are case-insensitive
1220 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1221 $$.flags.q.packed = 1;
1224 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1225 _mesa_glsl_warning(& @1, state,
1226 "#version 140 / GL_ARB_uniform_buffer_object "
1227 "layout qualifier `%s' is used", $1);
1231 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1233 static const struct {
1237 { "points", GL_POINTS },
1238 { "lines", GL_LINES },
1239 { "lines_adjacency", GL_LINES_ADJACENCY },
1240 { "line_strip", GL_LINE_STRIP },
1241 { "triangles", GL_TRIANGLES },
1242 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1243 { "triangle_strip", GL_TRIANGLE_STRIP },
1245 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1246 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1247 $$.flags.q.prim_type = 1;
1248 $$.prim_type = map[i].e;
1253 if ($$.flags.i && !state->is_version(150, 0)) {
1254 _mesa_glsl_error(& @1, state, "#version 150 layout "
1255 "qualifier `%s' used", $1);
1259 /* Layout qualifiers for ARB_shader_image_load_store. */
1260 if (state->ARB_shader_image_load_store_enable ||
1261 state->is_version(420, 310)) {
1263 static const struct {
1266 glsl_base_type base_type;
1267 /** Minimum desktop GLSL version required for the image
1268 * format. Use 130 if already present in the original
1271 unsigned required_glsl;
1272 /** Minimum GLSL ES version required for the image format. */
1273 unsigned required_essl;
1275 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1276 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1277 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1278 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1279 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1280 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1281 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1282 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1283 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1284 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1285 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1286 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1287 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1288 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1289 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1290 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1291 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1292 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1293 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1294 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1295 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1296 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1297 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1298 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1299 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1300 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1301 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1302 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1303 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1304 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1305 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1306 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1307 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1308 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1309 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1310 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1311 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1312 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1313 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1316 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1317 if (state->is_version(map[i].required_glsl,
1318 map[i].required_essl) &&
1319 match_layout_qualifier($1, map[i].name, state) == 0) {
1320 $$.flags.q.explicit_image_format = 1;
1321 $$.image_format = map[i].format;
1322 $$.image_base_type = map[i].base_type;
1329 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1330 /* From section 4.4.1.3 of the GLSL 4.50 specification
1331 * (Fragment Shader Inputs):
1333 * "Fragment shaders also allow the following layout
1334 * qualifier on in only (not with variable declarations)
1335 * layout-qualifier-id
1336 * early_fragment_tests
1339 if (state->stage != MESA_SHADER_FRAGMENT) {
1340 _mesa_glsl_error(& @1, state,
1341 "early_fragment_tests layout qualifier only "
1342 "valid in fragment shaders");
1345 $$.flags.q.early_fragment_tests = 1;
1349 /* Layout qualifiers for tessellation evaluation shaders. */
1355 /* triangles already parsed by gs-specific code */
1356 { "quads", GL_QUADS },
1357 { "isolines", GL_ISOLINES },
1359 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1360 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1361 $$.flags.q.prim_type = 1;
1362 $$.prim_type = map[i].e;
1368 !state->ARB_tessellation_shader_enable &&
1369 !state->is_version(400, 0)) {
1370 _mesa_glsl_error(& @1, state,
1371 "primitive mode qualifier `%s' requires "
1372 "GLSL 4.00 or ARB_tessellation_shader", $1);
1380 { "equal_spacing", GL_EQUAL },
1381 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1382 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1384 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1385 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1386 $$.flags.q.vertex_spacing = 1;
1387 $$.vertex_spacing = map[i].e;
1393 !state->ARB_tessellation_shader_enable &&
1394 !state->is_version(400, 0)) {
1395 _mesa_glsl_error(& @1, state,
1396 "vertex spacing qualifier `%s' requires "
1397 "GLSL 4.00 or ARB_tessellation_shader", $1);
1401 if (match_layout_qualifier($1, "cw", state) == 0) {
1402 $$.flags.q.ordering = 1;
1403 $$.ordering = GL_CW;
1404 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1405 $$.flags.q.ordering = 1;
1406 $$.ordering = GL_CCW;
1410 !state->ARB_tessellation_shader_enable &&
1411 !state->is_version(400, 0)) {
1412 _mesa_glsl_error(& @1, state,
1413 "ordering qualifier `%s' requires "
1414 "GLSL 4.00 or ARB_tessellation_shader", $1);
1418 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1419 $$.flags.q.point_mode = 1;
1420 $$.point_mode = true;
1424 !state->ARB_tessellation_shader_enable &&
1425 !state->is_version(400, 0)) {
1426 _mesa_glsl_error(& @1, state,
1427 "qualifier `point_mode' requires "
1428 "GLSL 4.00 or ARB_tessellation_shader");
1433 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1438 | any_identifier '=' integer_constant
1440 memset(& $$, 0, sizeof($$));
1442 if (match_layout_qualifier("location", $1, state) == 0) {
1443 $$.flags.q.explicit_location = 1;
1445 if ($$.flags.q.attribute == 1 &&
1446 state->ARB_explicit_attrib_location_warn) {
1447 _mesa_glsl_warning(& @1, state,
1448 "GL_ARB_explicit_attrib_location layout "
1449 "identifier `%s' used", $1);
1455 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1460 if (match_layout_qualifier("index", $1, state) == 0) {
1461 $$.flags.q.explicit_index = 1;
1466 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1471 if ((state->has_420pack() ||
1472 state->has_atomic_counters() ||
1473 state->has_shader_storage_buffer_objects()) &&
1474 match_layout_qualifier("binding", $1, state) == 0) {
1475 $$.flags.q.explicit_binding = 1;
1479 if (state->has_atomic_counters() &&
1480 match_layout_qualifier("offset", $1, state) == 0) {
1481 $$.flags.q.explicit_offset = 1;
1485 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1486 $$.flags.q.max_vertices = 1;
1489 _mesa_glsl_error(& @3, state,
1490 "invalid max_vertices %d specified", $3);
1493 $$.max_vertices = $3;
1494 if (!state->is_version(150, 0)) {
1495 _mesa_glsl_error(& @3, state,
1496 "#version 150 max_vertices qualifier "
1502 if (state->stage == MESA_SHADER_GEOMETRY) {
1503 if (match_layout_qualifier("stream", $1, state) == 0 &&
1504 state->check_explicit_attrib_stream_allowed(& @3)) {
1505 $$.flags.q.stream = 1;
1508 _mesa_glsl_error(& @3, state,
1509 "invalid stream %d specified", $3);
1512 $$.flags.q.explicit_stream = 1;
1518 static const char * const local_size_qualifiers[3] = {
1523 for (int i = 0; i < 3; i++) {
1524 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1527 _mesa_glsl_error(& @3, state,
1528 "invalid %s of %d specified",
1529 local_size_qualifiers[i], $3);
1531 } else if (!state->has_compute_shader()) {
1532 _mesa_glsl_error(& @3, state,
1533 "%s qualifier requires GLSL 4.30 or "
1534 "GLSL ES 3.10 or ARB_compute_shader",
1535 local_size_qualifiers[i]);
1538 $$.flags.q.local_size |= (1 << i);
1539 $$.local_size[i] = $3;
1545 if (match_layout_qualifier("invocations", $1, state) == 0) {
1546 $$.flags.q.invocations = 1;
1549 _mesa_glsl_error(& @3, state,
1550 "invalid invocations %d specified", $3);
1552 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1553 _mesa_glsl_error(& @3, state,
1554 "invocations (%d) exceeds "
1555 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1558 $$.invocations = $3;
1559 if (!state->is_version(400, 0) &&
1560 !state->ARB_gpu_shader5_enable) {
1561 _mesa_glsl_error(& @3, state,
1562 "GL_ARB_gpu_shader5 invocations "
1563 "qualifier specified", $3);
1568 /* Layout qualifiers for tessellation control shaders. */
1569 if (match_layout_qualifier("vertices", $1, state) == 0) {
1570 $$.flags.q.vertices = 1;
1573 _mesa_glsl_error(& @3, state,
1574 "invalid vertices (%d) specified", $3);
1576 } else if ($3 > (int)state->Const.MaxPatchVertices) {
1577 _mesa_glsl_error(& @3, state,
1578 "vertices (%d) exceeds "
1579 "GL_MAX_PATCH_VERTICES", $3);
1583 if (!state->ARB_tessellation_shader_enable &&
1584 !state->is_version(400, 0)) {
1585 _mesa_glsl_error(& @1, state,
1586 "vertices qualifier requires GLSL 4.00 or "
1587 "ARB_tessellation_shader");
1592 /* If the identifier didn't match any known layout identifiers,
1596 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1601 | interface_block_layout_qualifier
1604 /* Layout qualifiers for ARB_uniform_buffer_object. */
1605 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1606 _mesa_glsl_error(& @1, state,
1607 "#version 140 / GL_ARB_uniform_buffer_object "
1608 "layout qualifier `%s' is used", $1);
1609 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1610 _mesa_glsl_warning(& @1, state,
1611 "#version 140 / GL_ARB_uniform_buffer_object "
1612 "layout qualifier `%s' is used", $1);
1617 /* This is a separate language rule because we parse these as tokens
1618 * (due to them being reserved keywords) instead of identifiers like
1619 * most qualifiers. See the any_identifier path of
1620 * layout_qualifier_id for the others.
1622 * Note that since layout qualifiers are case-insensitive in desktop
1623 * GLSL, all of these qualifiers need to be handled as identifiers as
1624 * well (by the any_identifier path of layout_qualifier_id).
1626 interface_block_layout_qualifier:
1629 memset(& $$, 0, sizeof($$));
1630 $$.flags.q.row_major = 1;
1634 memset(& $$, 0, sizeof($$));
1635 $$.flags.q.packed = 1;
1639 subroutine_qualifier:
1642 memset(& $$, 0, sizeof($$));
1643 $$.flags.q.subroutine = 1;
1645 | SUBROUTINE '(' subroutine_type_list ')'
1647 memset(& $$, 0, sizeof($$));
1648 $$.flags.q.subroutine_def = 1;
1649 $$.subroutine_list = $3;
1653 subroutine_type_list:
1657 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1658 decl->set_location(@1);
1660 $$ = new(ctx) ast_subroutine_list();
1661 $$->declarations.push_tail(&decl->link);
1663 | subroutine_type_list ',' any_identifier
1666 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1667 decl->set_location(@3);
1670 $$->declarations.push_tail(&decl->link);
1674 interpolation_qualifier:
1677 memset(& $$, 0, sizeof($$));
1678 $$.flags.q.smooth = 1;
1682 memset(& $$, 0, sizeof($$));
1683 $$.flags.q.flat = 1;
1687 memset(& $$, 0, sizeof($$));
1688 $$.flags.q.noperspective = 1;
1693 /* Single qualifiers */
1696 memset(& $$, 0, sizeof($$));
1697 $$.flags.q.invariant = 1;
1701 memset(& $$, 0, sizeof($$));
1702 $$.flags.q.precise = 1;
1704 | auxiliary_storage_qualifier
1706 | interpolation_qualifier
1709 | subroutine_qualifier
1710 | precision_qualifier
1712 memset(&$$, 0, sizeof($$));
1716 /* Multiple qualifiers:
1717 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1718 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1720 * invariant interpolation auxiliary storage precision ...or...
1721 * layout storage precision
1723 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1724 * side don't contain any that must appear on the left hand side.
1725 * For example, when processing a storage qualifier, we check that there are
1726 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1728 | PRECISE type_qualifier
1730 if ($2.flags.q.precise)
1731 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1734 $$.flags.q.precise = 1;
1736 | INVARIANT type_qualifier
1738 if ($2.flags.q.invariant)
1739 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1741 if (!state->has_420pack() && $2.flags.q.precise)
1742 _mesa_glsl_error(&@1, state,
1743 "\"invariant\" must come after \"precise\"");
1746 $$.flags.q.invariant = 1;
1748 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1750 * "Only variables output from a shader can be candidates for invariance.
1751 * This includes user-defined output variables and the built-in output
1752 * variables. As only outputs can be declared as invariant, an invariant
1753 * output from one shader stage will still match an input of a subsequent
1754 * stage without the input being declared as invariant."
1756 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1757 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1759 | interpolation_qualifier type_qualifier
1761 /* Section 4.3 of the GLSL 1.40 specification states:
1762 * "...qualified with one of these interpolation qualifiers"
1764 * GLSL 1.30 claims to allow "one or more", but insists that:
1765 * "These interpolation qualifiers may only precede the qualifiers in,
1766 * centroid in, out, or centroid out in a declaration."
1768 * ...which means that e.g. smooth can't precede smooth, so there can be
1769 * only one after all, and the 1.40 text is a clarification, not a change.
1771 if ($2.has_interpolation())
1772 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1774 if (!state->has_420pack() &&
1775 ($2.flags.q.precise || $2.flags.q.invariant)) {
1776 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1777 "after \"precise\" or \"invariant\"");
1781 $$.merge_qualifier(&@1, state, $2);
1783 | layout_qualifier type_qualifier
1785 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1786 * appear no later than auxiliary storage qualifiers. There is no
1787 * particularly clear spec language mandating this, but in all examples
1788 * the layout qualifier precedes the storage qualifier.
1790 * We allow combinations of layout with interpolation, invariant or
1791 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1792 * There is no clear spec guidance on this either.
1794 if (!state->has_420pack() && $2.has_layout())
1795 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1798 $$.merge_qualifier(&@1, state, $2);
1800 | subroutine_qualifier type_qualifier
1803 $$.merge_qualifier(&@1, state, $2);
1805 | auxiliary_storage_qualifier type_qualifier
1807 if ($2.has_auxiliary_storage()) {
1808 _mesa_glsl_error(&@1, state,
1809 "duplicate auxiliary storage qualifier (centroid or sample)");
1812 if (!state->has_420pack() &&
1813 ($2.flags.q.precise || $2.flags.q.invariant ||
1814 $2.has_interpolation() || $2.has_layout())) {
1815 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1816 "just before storage qualifiers");
1819 $$.merge_qualifier(&@1, state, $2);
1821 | storage_qualifier type_qualifier
1823 /* Section 4.3 of the GLSL 1.20 specification states:
1824 * "Variable declarations may have a storage qualifier specified..."
1825 * 1.30 clarifies this to "may have one storage qualifier".
1827 if ($2.has_storage())
1828 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1830 if (!state->has_420pack() &&
1831 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1832 $2.has_layout() || $2.has_auxiliary_storage())) {
1833 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1834 "precise, invariant, interpolation, layout and auxiliary "
1835 "storage qualifiers");
1839 $$.merge_qualifier(&@1, state, $2);
1841 | precision_qualifier type_qualifier
1843 if ($2.precision != ast_precision_none)
1844 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1846 if (!state->has_420pack() && $2.flags.i != 0)
1847 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1852 | memory_qualifier type_qualifier
1855 $$.merge_qualifier(&@1, state, $2);
1859 auxiliary_storage_qualifier:
1862 memset(& $$, 0, sizeof($$));
1863 $$.flags.q.centroid = 1;
1867 memset(& $$, 0, sizeof($$));
1868 $$.flags.q.sample = 1;
1872 memset(& $$, 0, sizeof($$));
1873 $$.flags.q.patch = 1;
1879 memset(& $$, 0, sizeof($$));
1880 $$.flags.q.constant = 1;
1884 memset(& $$, 0, sizeof($$));
1885 $$.flags.q.attribute = 1;
1889 memset(& $$, 0, sizeof($$));
1890 $$.flags.q.varying = 1;
1894 memset(& $$, 0, sizeof($$));
1899 memset(& $$, 0, sizeof($$));
1902 if (state->stage == MESA_SHADER_GEOMETRY &&
1903 state->has_explicit_attrib_stream()) {
1904 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1907 * "If the block or variable is declared with the stream
1908 * identifier, it is associated with the specified stream;
1909 * otherwise, it is associated with the current default stream."
1911 $$.flags.q.stream = 1;
1912 $$.flags.q.explicit_stream = 0;
1913 $$.stream = state->out_qualifier->stream;
1918 memset(& $$, 0, sizeof($$));
1919 $$.flags.q.uniform = 1;
1923 memset(& $$, 0, sizeof($$));
1924 $$.flags.q.buffer = 1;
1931 memset(& $$, 0, sizeof($$));
1932 $$.flags.q.coherent = 1;
1936 memset(& $$, 0, sizeof($$));
1937 $$.flags.q._volatile = 1;
1941 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1942 memset(& $$, 0, sizeof($$));
1943 $$.flags.q.restrict_flag = 1;
1947 memset(& $$, 0, sizeof($$));
1948 $$.flags.q.read_only = 1;
1952 memset(& $$, 0, sizeof($$));
1953 $$.flags.q.write_only = 1;
1961 $$ = new(ctx) ast_array_specifier(@1);
1962 $$->set_location_range(@1, @2);
1964 | '[' constant_expression ']'
1967 $$ = new(ctx) ast_array_specifier(@1, $2);
1968 $$->set_location_range(@1, @3);
1970 | array_specifier '[' ']'
1974 if (!state->ARB_arrays_of_arrays_enable) {
1975 _mesa_glsl_error(& @1, state,
1976 "GL_ARB_arrays_of_arrays "
1977 "required for defining arrays of arrays");
1979 _mesa_glsl_error(& @1, state,
1980 "only the outermost array dimension can "
1984 | array_specifier '[' constant_expression ']'
1988 if (!state->ARB_arrays_of_arrays_enable) {
1989 _mesa_glsl_error(& @1, state,
1990 "GL_ARB_arrays_of_arrays "
1991 "required for defining arrays of arrays");
1994 $$->add_dimension($3);
1999 type_specifier_nonarray
2000 | type_specifier_nonarray array_specifier
2003 $$->array_specifier = $2;
2007 type_specifier_nonarray:
2008 basic_type_specifier_nonarray
2011 $$ = new(ctx) ast_type_specifier($1);
2012 $$->set_location(@1);
2017 $$ = new(ctx) ast_type_specifier($1);
2018 $$->set_location(@1);
2023 $$ = new(ctx) ast_type_specifier($1);
2024 $$->set_location(@1);
2028 basic_type_specifier_nonarray:
2029 VOID_TOK { $$ = "void"; }
2030 | FLOAT_TOK { $$ = "float"; }
2031 | DOUBLE_TOK { $$ = "double"; }
2032 | INT_TOK { $$ = "int"; }
2033 | UINT_TOK { $$ = "uint"; }
2034 | BOOL_TOK { $$ = "bool"; }
2035 | VEC2 { $$ = "vec2"; }
2036 | VEC3 { $$ = "vec3"; }
2037 | VEC4 { $$ = "vec4"; }
2038 | BVEC2 { $$ = "bvec2"; }
2039 | BVEC3 { $$ = "bvec3"; }
2040 | BVEC4 { $$ = "bvec4"; }
2041 | IVEC2 { $$ = "ivec2"; }
2042 | IVEC3 { $$ = "ivec3"; }
2043 | IVEC4 { $$ = "ivec4"; }
2044 | UVEC2 { $$ = "uvec2"; }
2045 | UVEC3 { $$ = "uvec3"; }
2046 | UVEC4 { $$ = "uvec4"; }
2047 | DVEC2 { $$ = "dvec2"; }
2048 | DVEC3 { $$ = "dvec3"; }
2049 | DVEC4 { $$ = "dvec4"; }
2050 | MAT2X2 { $$ = "mat2"; }
2051 | MAT2X3 { $$ = "mat2x3"; }
2052 | MAT2X4 { $$ = "mat2x4"; }
2053 | MAT3X2 { $$ = "mat3x2"; }
2054 | MAT3X3 { $$ = "mat3"; }
2055 | MAT3X4 { $$ = "mat3x4"; }
2056 | MAT4X2 { $$ = "mat4x2"; }
2057 | MAT4X3 { $$ = "mat4x3"; }
2058 | MAT4X4 { $$ = "mat4"; }
2059 | DMAT2X2 { $$ = "dmat2"; }
2060 | DMAT2X3 { $$ = "dmat2x3"; }
2061 | DMAT2X4 { $$ = "dmat2x4"; }
2062 | DMAT3X2 { $$ = "dmat3x2"; }
2063 | DMAT3X3 { $$ = "dmat3"; }
2064 | DMAT3X4 { $$ = "dmat3x4"; }
2065 | DMAT4X2 { $$ = "dmat4x2"; }
2066 | DMAT4X3 { $$ = "dmat4x3"; }
2067 | DMAT4X4 { $$ = "dmat4"; }
2068 | SAMPLER1D { $$ = "sampler1D"; }
2069 | SAMPLER2D { $$ = "sampler2D"; }
2070 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2071 | SAMPLER3D { $$ = "sampler3D"; }
2072 | SAMPLERCUBE { $$ = "samplerCube"; }
2073 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2074 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2075 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2076 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2077 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2078 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2079 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2080 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2081 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2082 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2083 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2084 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2085 | ISAMPLER1D { $$ = "isampler1D"; }
2086 | ISAMPLER2D { $$ = "isampler2D"; }
2087 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2088 | ISAMPLER3D { $$ = "isampler3D"; }
2089 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2090 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2091 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2092 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2093 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2094 | USAMPLER1D { $$ = "usampler1D"; }
2095 | USAMPLER2D { $$ = "usampler2D"; }
2096 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2097 | USAMPLER3D { $$ = "usampler3D"; }
2098 | USAMPLERCUBE { $$ = "usamplerCube"; }
2099 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2100 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2101 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2102 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2103 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2104 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2105 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2106 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2107 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2108 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2109 | IMAGE1D { $$ = "image1D"; }
2110 | IMAGE2D { $$ = "image2D"; }
2111 | IMAGE3D { $$ = "image3D"; }
2112 | IMAGE2DRECT { $$ = "image2DRect"; }
2113 | IMAGECUBE { $$ = "imageCube"; }
2114 | IMAGEBUFFER { $$ = "imageBuffer"; }
2115 | IMAGE1DARRAY { $$ = "image1DArray"; }
2116 | IMAGE2DARRAY { $$ = "image2DArray"; }
2117 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2118 | IMAGE2DMS { $$ = "image2DMS"; }
2119 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2120 | IIMAGE1D { $$ = "iimage1D"; }
2121 | IIMAGE2D { $$ = "iimage2D"; }
2122 | IIMAGE3D { $$ = "iimage3D"; }
2123 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2124 | IIMAGECUBE { $$ = "iimageCube"; }
2125 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2126 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2127 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2128 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2129 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2130 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2131 | UIMAGE1D { $$ = "uimage1D"; }
2132 | UIMAGE2D { $$ = "uimage2D"; }
2133 | UIMAGE3D { $$ = "uimage3D"; }
2134 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2135 | UIMAGECUBE { $$ = "uimageCube"; }
2136 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2137 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2138 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2139 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2140 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2141 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2142 | ATOMIC_UINT { $$ = "atomic_uint"; }
2145 precision_qualifier:
2148 state->check_precision_qualifiers_allowed(&@1);
2149 $$ = ast_precision_high;
2153 state->check_precision_qualifiers_allowed(&@1);
2154 $$ = ast_precision_medium;
2158 state->check_precision_qualifiers_allowed(&@1);
2159 $$ = ast_precision_low;
2164 STRUCT any_identifier '{' struct_declaration_list '}'
2167 $$ = new(ctx) ast_struct_specifier($2, $4);
2168 $$->set_location_range(@2, @5);
2169 state->symbols->add_type($2, glsl_type::void_type);
2171 | STRUCT '{' struct_declaration_list '}'
2174 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2175 $$->set_location_range(@2, @4);
2179 struct_declaration_list:
2183 $1->link.self_link();
2185 | struct_declaration_list struct_declaration
2188 $$->link.insert_before(& $2->link);
2193 fully_specified_type struct_declarator_list ';'
2196 ast_fully_specified_type *const type = $1;
2197 type->set_location(@1);
2199 if (type->qualifier.flags.i != 0)
2200 _mesa_glsl_error(&@1, state,
2201 "only precision qualifiers may be applied to "
2202 "structure members");
2204 $$ = new(ctx) ast_declarator_list(type);
2205 $$->set_location(@2);
2207 $$->declarations.push_degenerate_list_at_head(& $2->link);
2211 struct_declarator_list:
2215 $1->link.self_link();
2217 | struct_declarator_list ',' struct_declarator
2220 $$->link.insert_before(& $3->link);
2228 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2229 $$->set_location(@1);
2231 | any_identifier array_specifier
2234 $$ = new(ctx) ast_declaration($1, $2, NULL);
2235 $$->set_location_range(@1, @2);
2240 assignment_expression
2241 | '{' initializer_list '}'
2245 | '{' initializer_list ',' '}'
2255 $$ = new(ctx) ast_aggregate_initializer();
2256 $$->set_location(@1);
2257 $$->expressions.push_tail(& $1->link);
2259 | initializer_list ',' initializer
2261 $1->expressions.push_tail(& $3->link);
2265 declaration_statement:
2269 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2272 compound_statement { $$ = (ast_node *) $1; }
2277 declaration_statement
2278 | expression_statement
2279 | selection_statement
2281 | iteration_statement
2289 $$ = new(ctx) ast_compound_statement(true, NULL);
2290 $$->set_location_range(@1, @2);
2294 state->symbols->push_scope();
2299 $$ = new(ctx) ast_compound_statement(true, $3);
2300 $$->set_location_range(@1, @4);
2301 state->symbols->pop_scope();
2305 statement_no_new_scope:
2306 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2310 compound_statement_no_new_scope:
2314 $$ = new(ctx) ast_compound_statement(false, NULL);
2315 $$->set_location_range(@1, @2);
2317 | '{' statement_list '}'
2320 $$ = new(ctx) ast_compound_statement(false, $2);
2321 $$->set_location_range(@1, @3);
2329 _mesa_glsl_error(& @1, state, "<nil> statement");
2334 $$->link.self_link();
2336 | statement_list statement
2339 _mesa_glsl_error(& @2, state, "<nil> statement");
2343 $$->link.insert_before(& $2->link);
2347 expression_statement:
2351 $$ = new(ctx) ast_expression_statement(NULL);
2352 $$->set_location(@1);
2357 $$ = new(ctx) ast_expression_statement($1);
2358 $$->set_location(@1);
2362 selection_statement:
2363 IF '(' expression ')' selection_rest_statement
2365 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2367 $$->set_location_range(@1, @5);
2371 selection_rest_statement:
2372 statement ELSE statement
2374 $$.then_statement = $1;
2375 $$.else_statement = $3;
2377 | statement %prec THEN
2379 $$.then_statement = $1;
2380 $$.else_statement = NULL;
2387 $$ = (ast_node *) $1;
2389 | fully_specified_type any_identifier '=' initializer
2392 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2393 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2394 decl->set_location_range(@2, @4);
2395 declarator->set_location(@1);
2397 declarator->declarations.push_tail(&decl->link);
2403 * switch_statement grammar is based on the syntax described in the body
2404 * of the GLSL spec, not in it's appendix!!!
2407 SWITCH '(' expression ')' switch_body
2409 $$ = new(state) ast_switch_statement($3, $5);
2410 $$->set_location_range(@1, @5);
2417 $$ = new(state) ast_switch_body(NULL);
2418 $$->set_location_range(@1, @2);
2420 | '{' case_statement_list '}'
2422 $$ = new(state) ast_switch_body($2);
2423 $$->set_location_range(@1, @3);
2430 $$ = new(state) ast_case_label($2);
2431 $$->set_location(@2);
2435 $$ = new(state) ast_case_label(NULL);
2436 $$->set_location(@2);
2443 ast_case_label_list *labels = new(state) ast_case_label_list();
2445 labels->labels.push_tail(& $1->link);
2447 $$->set_location(@1);
2449 | case_label_list case_label
2452 $$->labels.push_tail(& $2->link);
2457 case_label_list statement
2459 ast_case_statement *stmts = new(state) ast_case_statement($1);
2460 stmts->set_location(@2);
2462 stmts->stmts.push_tail(& $2->link);
2465 | case_statement statement
2468 $$->stmts.push_tail(& $2->link);
2472 case_statement_list:
2475 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2476 cases->set_location(@1);
2478 cases->cases.push_tail(& $1->link);
2481 | case_statement_list case_statement
2484 $$->cases.push_tail(& $2->link);
2488 iteration_statement:
2489 WHILE '(' condition ')' statement_no_new_scope
2492 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2493 NULL, $3, NULL, $5);
2494 $$->set_location_range(@1, @4);
2496 | DO statement WHILE '(' expression ')' ';'
2499 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2500 NULL, $5, NULL, $2);
2501 $$->set_location_range(@1, @6);
2503 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2506 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2507 $3, $4.cond, $4.rest, $6);
2508 $$->set_location_range(@1, @6);
2513 expression_statement
2514 | declaration_statement
2531 | conditionopt ';' expression
2538 // Grammar Note: No 'goto'. Gotos are not supported.
2543 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2544 $$->set_location(@1);
2549 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2550 $$->set_location(@1);
2555 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2556 $$->set_location(@1);
2558 | RETURN expression ';'
2561 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2562 $$->set_location_range(@1, @2);
2564 | DISCARD ';' // Fragment shader only.
2567 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2568 $$->set_location(@1);
2572 external_declaration:
2573 function_definition { $$ = $1; }
2574 | declaration { $$ = $1; }
2575 | pragma_statement { $$ = NULL; }
2576 | layout_defaults { $$ = $1; }
2579 function_definition:
2580 function_prototype compound_statement_no_new_scope
2583 $$ = new(ctx) ast_function_definition();
2584 $$->set_location_range(@1, @2);
2588 state->symbols->pop_scope();
2592 /* layout_qualifieropt is packed into this rule */
2594 basic_interface_block
2598 | layout_qualifier interface_block
2600 ast_interface_block *block = (ast_interface_block *) $2;
2602 if (!state->has_420pack() && block->layout.has_layout()) {
2603 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2607 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2611 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2612 ast_type_qualifier& qualifier = member->type->qualifier;
2613 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2614 _mesa_glsl_error(& @1, state,
2615 "stream layout qualifier on "
2616 "interface block member does not match "
2617 "the interface block (%d vs %d)",
2618 qualifier.stream, block->layout.stream);
2626 basic_interface_block:
2627 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2629 ast_interface_block *const block = $6;
2631 block->block_name = $2;
2632 block->declarations.push_degenerate_list_at_head(& $4->link);
2634 if ($1.flags.q.buffer) {
2635 if (!state->has_shader_storage_buffer_objects()) {
2636 _mesa_glsl_error(& @1, state,
2637 "#version 430 / GL_ARB_shader_storage_buffer_object "
2638 "required for defining shader storage blocks");
2639 } else if (state->ARB_shader_storage_buffer_object_warn) {
2640 _mesa_glsl_warning(& @1, state,
2641 "#version 430 / GL_ARB_shader_storage_buffer_object "
2642 "required for defining shader storage blocks");
2644 } else if ($1.flags.q.uniform) {
2645 if (!state->has_uniform_buffer_objects()) {
2646 _mesa_glsl_error(& @1, state,
2647 "#version 140 / GL_ARB_uniform_buffer_object "
2648 "required for defining uniform blocks");
2649 } else if (state->ARB_uniform_buffer_object_warn) {
2650 _mesa_glsl_warning(& @1, state,
2651 "#version 140 / GL_ARB_uniform_buffer_object "
2652 "required for defining uniform blocks");
2655 if (state->es_shader || state->language_version < 150) {
2656 _mesa_glsl_error(& @1, state,
2657 "#version 150 required for using "
2658 "interface blocks");
2662 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2663 * "It is illegal to have an input block in a vertex shader
2664 * or an output block in a fragment shader"
2666 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2667 _mesa_glsl_error(& @1, state,
2668 "`in' interface block is not allowed for "
2670 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2671 _mesa_glsl_error(& @1, state,
2672 "`out' interface block is not allowed for "
2673 "a fragment shader");
2676 /* Since block arrays require names, and both features are added in
2677 * the same language versions, we don't have to explicitly
2678 * version-check both things.
2680 if (block->instance_name != NULL) {
2681 state->check_version(150, 300, & @1, "interface blocks with "
2682 "an instance name are not allowed");
2685 uint64_t interface_type_mask;
2686 struct ast_type_qualifier temp_type_qualifier;
2688 /* Get a bitmask containing only the in/out/uniform/buffer
2689 * flags, allowing us to ignore other irrelevant flags like
2690 * interpolation qualifiers.
2692 temp_type_qualifier.flags.i = 0;
2693 temp_type_qualifier.flags.q.uniform = true;
2694 temp_type_qualifier.flags.q.buffer = true;
2695 temp_type_qualifier.flags.q.in = true;
2696 temp_type_qualifier.flags.q.out = true;
2697 interface_type_mask = temp_type_qualifier.flags.i;
2699 /* Get the block's interface qualifier. The interface_qualifier
2700 * production rule guarantees that only one bit will be set (and
2701 * it will be in/out/uniform).
2703 uint64_t block_interface_qualifier = $1.flags.i;
2705 block->layout.flags.i |= block_interface_qualifier;
2707 if (state->stage == MESA_SHADER_GEOMETRY &&
2708 state->has_explicit_attrib_stream()) {
2709 /* Assign global layout's stream value. */
2710 block->layout.flags.q.stream = 1;
2711 block->layout.flags.q.explicit_stream = 0;
2712 block->layout.stream = state->out_qualifier->stream;
2715 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2716 ast_type_qualifier& qualifier = member->type->qualifier;
2717 if ((qualifier.flags.i & interface_type_mask) == 0) {
2718 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2719 * "If no optional qualifier is used in a member declaration, the
2720 * qualifier of the variable is just in, out, or uniform as declared
2721 * by interface-qualifier."
2723 qualifier.flags.i |= block_interface_qualifier;
2724 } else if ((qualifier.flags.i & interface_type_mask) !=
2725 block_interface_qualifier) {
2726 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2727 * "If optional qualifiers are used, they can include interpolation
2728 * and storage qualifiers and they must declare an input, output,
2729 * or uniform variable consistent with the interface qualifier of
2732 _mesa_glsl_error(& @1, state,
2733 "uniform/in/out qualifier on "
2734 "interface block member does not match "
2735 "the interface block");
2738 /* From GLSL ES 3.0, chapter 4.3.7 "Interface Blocks":
2740 * "GLSL ES 3.0 does not support interface blocks for shader inputs or
2743 * And from GLSL ES 3.0, chapter 4.6.1 "The invariant qualifier":.
2745 * "Only variables output from a shader can be candidates for
2748 * From GLSL 4.40 and GLSL 1.50, section "Interface Blocks":
2750 * "If optional qualifiers are used, they can include interpolation
2751 * qualifiers, auxiliary storage qualifiers, and storage qualifiers
2752 * and they must declare an input, output, or uniform member
2753 * consistent with the interface qualifier of the block"
2755 if (qualifier.flags.q.invariant)
2756 _mesa_glsl_error(&@1, state,
2757 "invariant qualifiers cannot be used "
2758 "with interface blocks members");
2765 interface_qualifier:
2768 memset(& $$, 0, sizeof($$));
2773 memset(& $$, 0, sizeof($$));
2778 memset(& $$, 0, sizeof($$));
2779 $$.flags.q.uniform = 1;
2783 memset(& $$, 0, sizeof($$));
2784 $$.flags.q.buffer = 1;
2791 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2796 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2798 $$->set_location(@1);
2800 | NEW_IDENTIFIER array_specifier
2802 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2804 $$->set_location_range(@1, @2);
2812 $1->link.self_link();
2814 | member_declaration member_list
2817 $2->link.insert_before(& $$->link);
2822 fully_specified_type struct_declarator_list ';'
2825 ast_fully_specified_type *type = $1;
2826 type->set_location(@1);
2828 if (type->qualifier.flags.q.attribute) {
2829 _mesa_glsl_error(& @1, state,
2830 "keyword 'attribute' cannot be used with "
2831 "interface block member");
2832 } else if (type->qualifier.flags.q.varying) {
2833 _mesa_glsl_error(& @1, state,
2834 "keyword 'varying' cannot be used with "
2835 "interface block member");
2838 $$ = new(ctx) ast_declarator_list(type);
2839 $$->set_location(@2);
2841 $$->declarations.push_degenerate_list_at_head(& $2->link);
2846 layout_qualifier UNIFORM ';'
2848 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2854 | layout_qualifier IN_TOK ';'
2857 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2862 | layout_qualifier OUT_TOK ';'
2865 if (state->stage == MESA_SHADER_GEOMETRY) {
2866 if ($1.flags.q.prim_type) {
2867 /* Make sure this is a valid output primitive type. */
2868 switch ($1.prim_type) {
2871 case GL_TRIANGLE_STRIP:
2874 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2879 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2882 /* Allow future assigments of global out's stream id value */
2883 state->out_qualifier->flags.q.explicit_stream = 0;
2884 } else if (state->stage == MESA_SHADER_TESS_CTRL) {
2885 if (!state->out_qualifier->merge_out_qualifier(& @1, state, $1, $$))
2888 _mesa_glsl_error(& @1, state,
2889 "out layout qualifiers only valid in "
2890 "tessellation control or geometry shaders");