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;
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 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> interface_qualifier
218 %type <type_specifier> type_specifier
219 %type <type_specifier> type_specifier_nonarray
220 %type <array_specifier> array_specifier
221 %type <identifier> basic_type_specifier_nonarray
222 %type <fully_specified_type> fully_specified_type
223 %type <function> function_prototype
224 %type <function> function_header
225 %type <function> function_header_with_parameters
226 %type <function> function_declarator
227 %type <parameter_declarator> parameter_declarator
228 %type <parameter_declarator> parameter_declaration
229 %type <type_qualifier> parameter_qualifier
230 %type <type_qualifier> parameter_direction_qualifier
231 %type <type_specifier> parameter_type_specifier
232 %type <function_definition> function_definition
233 %type <compound_statement> compound_statement_no_new_scope
234 %type <compound_statement> compound_statement
235 %type <node> statement_no_new_scope
236 %type <node> expression_statement
237 %type <expression> expression
238 %type <expression> primary_expression
239 %type <expression> assignment_expression
240 %type <expression> conditional_expression
241 %type <expression> logical_or_expression
242 %type <expression> logical_xor_expression
243 %type <expression> logical_and_expression
244 %type <expression> inclusive_or_expression
245 %type <expression> exclusive_or_expression
246 %type <expression> and_expression
247 %type <expression> equality_expression
248 %type <expression> relational_expression
249 %type <expression> shift_expression
250 %type <expression> additive_expression
251 %type <expression> multiplicative_expression
252 %type <expression> unary_expression
253 %type <expression> constant_expression
254 %type <expression> integer_expression
255 %type <expression> postfix_expression
256 %type <expression> function_call_header_with_parameters
257 %type <expression> function_call_header_no_parameters
258 %type <expression> function_call_header
259 %type <expression> function_call_generic
260 %type <expression> function_call_or_method
261 %type <expression> function_call
262 %type <expression> method_call_generic
263 %type <expression> method_call_header_with_parameters
264 %type <expression> method_call_header_no_parameters
265 %type <expression> method_call_header
266 %type <n> assignment_operator
267 %type <n> unary_operator
268 %type <expression> function_identifier
269 %type <node> external_declaration
270 %type <declarator_list> init_declarator_list
271 %type <declarator_list> single_declaration
272 %type <expression> initializer
273 %type <expression> initializer_list
274 %type <node> declaration
275 %type <node> declaration_statement
276 %type <node> jump_statement
277 %type <node> interface_block
278 %type <interface_block> basic_interface_block
279 %type <struct_specifier> struct_specifier
280 %type <declarator_list> struct_declaration_list
281 %type <declarator_list> struct_declaration
282 %type <declaration> struct_declarator
283 %type <declaration> struct_declarator_list
284 %type <declarator_list> member_list
285 %type <declarator_list> member_declaration
286 %type <node> selection_statement
287 %type <selection_rest_statement> selection_rest_statement
288 %type <node> switch_statement
289 %type <switch_body> switch_body
290 %type <case_label_list> case_label_list
291 %type <case_label> case_label
292 %type <case_statement> case_statement
293 %type <case_statement_list> case_statement_list
294 %type <node> iteration_statement
295 %type <node> condition
296 %type <node> conditionopt
297 %type <node> for_init_statement
298 %type <for_rest_statement> for_rest_statement
299 %type <n> integer_constant
300 %type <node> layout_defaults
306 version_statement extension_statement_list
308 _mesa_glsl_initialize_types(state);
310 external_declaration_list
312 delete state->symbols;
313 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
314 _mesa_glsl_initialize_types(state);
319 /* blank - no #version specified: defaults are already set */
320 | VERSION_TOK INTCONSTANT EOL
322 state->process_version_directive(&@2, $2, NULL);
327 | VERSION_TOK INTCONSTANT any_identifier EOL
329 state->process_version_directive(&@2, $2, $3);
338 | PRAGMA_DEBUG_OFF EOL
339 | PRAGMA_OPTIMIZE_ON EOL
340 | PRAGMA_OPTIMIZE_OFF EOL
341 | PRAGMA_INVARIANT_ALL EOL
343 /* Pragma invariant(all) cannot be used in a fragment shader.
345 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
347 * "It is an error to use this pragma in a fragment shader."
349 if (state->is_version(120, 300) &&
350 state->stage == MESA_SHADER_FRAGMENT) {
351 _mesa_glsl_error(& @1, state,
352 "pragma `invariant(all)' cannot be used "
353 "in a fragment shader.");
354 } else if (!state->is_version(120, 100)) {
355 _mesa_glsl_warning(& @1, state,
356 "pragma `invariant(all)' not supported in %s "
357 "(GLSL ES 1.00 or GLSL 1.20 required)",
358 state->get_version_string());
360 state->all_invariant = true;
365 extension_statement_list:
367 | extension_statement_list extension_statement
377 EXTENSION any_identifier COLON any_identifier EOL
379 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
385 external_declaration_list:
388 /* FINISHME: The NULL test is required because pragmas are set to
389 * FINISHME: NULL. (See production rule for external_declaration.)
392 state->translation_unit.push_tail(& $1->link);
394 | external_declaration_list external_declaration
396 /* FINISHME: The NULL test is required because pragmas are set to
397 * FINISHME: NULL. (See production rule for external_declaration.)
400 state->translation_unit.push_tail(& $2->link);
402 | external_declaration_list extension_statement {
403 if (!state->allow_extension_directive_midshader) {
404 _mesa_glsl_error(& @2, state,
405 "#extension directive is not allowed "
406 "in the middle of a shader");
421 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
422 $$->set_location(@1);
423 $$->primary_expression.identifier = $1;
428 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
429 $$->set_location(@1);
430 $$->primary_expression.int_constant = $1;
435 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
436 $$->set_location(@1);
437 $$->primary_expression.uint_constant = $1;
442 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
443 $$->set_location(@1);
444 $$->primary_expression.float_constant = $1;
449 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
450 $$->set_location(@1);
451 $$->primary_expression.double_constant = $1;
456 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
457 $$->set_location(@1);
458 $$->primary_expression.bool_constant = $1;
468 | postfix_expression '[' integer_expression ']'
471 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
472 $$->set_location_range(@1, @4);
478 | postfix_expression '.' any_identifier
481 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
482 $$->set_location_range(@1, @3);
483 $$->primary_expression.identifier = $3;
485 | postfix_expression INC_OP
488 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
489 $$->set_location_range(@1, @2);
491 | postfix_expression DEC_OP
494 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
495 $$->set_location_range(@1, @2);
504 function_call_or_method
507 function_call_or_method:
508 function_call_generic
509 | postfix_expression '.' method_call_generic
512 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
513 $$->set_location_range(@1, @3);
517 function_call_generic:
518 function_call_header_with_parameters ')'
519 | function_call_header_no_parameters ')'
522 function_call_header_no_parameters:
523 function_call_header VOID_TOK
524 | function_call_header
527 function_call_header_with_parameters:
528 function_call_header assignment_expression
531 $$->set_location(@1);
532 $$->expressions.push_tail(& $2->link);
534 | function_call_header_with_parameters ',' assignment_expression
537 $$->set_location(@1);
538 $$->expressions.push_tail(& $3->link);
542 // Grammar Note: Constructors look like functions, but lexical
543 // analysis recognized most of them as keywords. They are now
544 // recognized through "type_specifier".
545 function_call_header:
546 function_identifier '('
553 $$ = new(ctx) ast_function_expression($1);
554 $$->set_location(@1);
556 | variable_identifier
559 ast_expression *callee = new(ctx) ast_expression($1);
560 callee->set_location(@1);
561 $$ = new(ctx) ast_function_expression(callee);
562 $$->set_location(@1);
567 ast_expression *callee = new(ctx) ast_expression($1);
568 callee->set_location(@1);
569 $$ = new(ctx) ast_function_expression(callee);
570 $$->set_location(@1);
575 method_call_header_with_parameters ')'
576 | method_call_header_no_parameters ')'
579 method_call_header_no_parameters:
580 method_call_header VOID_TOK
584 method_call_header_with_parameters:
585 method_call_header assignment_expression
588 $$->set_location(@1);
589 $$->expressions.push_tail(& $2->link);
591 | method_call_header_with_parameters ',' assignment_expression
594 $$->set_location(@1);
595 $$->expressions.push_tail(& $3->link);
599 // Grammar Note: Constructors look like methods, but lexical
600 // analysis recognized most of them as keywords. They are now
601 // recognized through "type_specifier".
603 variable_identifier '('
606 ast_expression *callee = new(ctx) ast_expression($1);
607 callee->set_location(@1);
608 $$ = new(ctx) ast_function_expression(callee);
609 $$->set_location(@1);
613 // Grammar Note: No traditional style type casts.
616 | INC_OP unary_expression
619 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
620 $$->set_location(@1);
622 | DEC_OP unary_expression
625 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
626 $$->set_location(@1);
628 | unary_operator unary_expression
631 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
632 $$->set_location_range(@1, @2);
636 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
638 '+' { $$ = ast_plus; }
639 | '-' { $$ = ast_neg; }
640 | '!' { $$ = ast_logic_not; }
641 | '~' { $$ = ast_bit_not; }
644 multiplicative_expression:
646 | multiplicative_expression '*' unary_expression
649 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
650 $$->set_location_range(@1, @3);
652 | multiplicative_expression '/' unary_expression
655 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
656 $$->set_location_range(@1, @3);
658 | multiplicative_expression '%' unary_expression
661 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
662 $$->set_location_range(@1, @3);
667 multiplicative_expression
668 | additive_expression '+' multiplicative_expression
671 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
672 $$->set_location_range(@1, @3);
674 | additive_expression '-' multiplicative_expression
677 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
678 $$->set_location_range(@1, @3);
684 | shift_expression LEFT_OP additive_expression
687 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
688 $$->set_location_range(@1, @3);
690 | shift_expression RIGHT_OP additive_expression
693 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
694 $$->set_location_range(@1, @3);
698 relational_expression:
700 | relational_expression '<' shift_expression
703 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
704 $$->set_location_range(@1, @3);
706 | relational_expression '>' shift_expression
709 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
710 $$->set_location_range(@1, @3);
712 | relational_expression LE_OP shift_expression
715 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
716 $$->set_location_range(@1, @3);
718 | relational_expression GE_OP shift_expression
721 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
722 $$->set_location_range(@1, @3);
727 relational_expression
728 | equality_expression EQ_OP relational_expression
731 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
732 $$->set_location_range(@1, @3);
734 | equality_expression NE_OP relational_expression
737 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
738 $$->set_location_range(@1, @3);
744 | and_expression '&' equality_expression
747 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
748 $$->set_location_range(@1, @3);
752 exclusive_or_expression:
754 | exclusive_or_expression '^' and_expression
757 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
758 $$->set_location_range(@1, @3);
762 inclusive_or_expression:
763 exclusive_or_expression
764 | inclusive_or_expression '|' exclusive_or_expression
767 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
768 $$->set_location_range(@1, @3);
772 logical_and_expression:
773 inclusive_or_expression
774 | logical_and_expression AND_OP inclusive_or_expression
777 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
778 $$->set_location_range(@1, @3);
782 logical_xor_expression:
783 logical_and_expression
784 | logical_xor_expression XOR_OP logical_and_expression
787 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
788 $$->set_location_range(@1, @3);
792 logical_or_expression:
793 logical_xor_expression
794 | logical_or_expression OR_OP logical_xor_expression
797 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
798 $$->set_location_range(@1, @3);
802 conditional_expression:
803 logical_or_expression
804 | logical_or_expression '?' expression ':' assignment_expression
807 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
808 $$->set_location_range(@1, @5);
812 assignment_expression:
813 conditional_expression
814 | unary_expression assignment_operator assignment_expression
817 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
818 $$->set_location_range(@1, @3);
823 '=' { $$ = ast_assign; }
824 | MUL_ASSIGN { $$ = ast_mul_assign; }
825 | DIV_ASSIGN { $$ = ast_div_assign; }
826 | MOD_ASSIGN { $$ = ast_mod_assign; }
827 | ADD_ASSIGN { $$ = ast_add_assign; }
828 | SUB_ASSIGN { $$ = ast_sub_assign; }
829 | LEFT_ASSIGN { $$ = ast_ls_assign; }
830 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
831 | AND_ASSIGN { $$ = ast_and_assign; }
832 | XOR_ASSIGN { $$ = ast_xor_assign; }
833 | OR_ASSIGN { $$ = ast_or_assign; }
837 assignment_expression
841 | expression ',' assignment_expression
844 if ($1->oper != ast_sequence) {
845 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
846 $$->set_location_range(@1, @3);
847 $$->expressions.push_tail(& $1->link);
852 $$->expressions.push_tail(& $3->link);
857 conditional_expression
861 function_prototype ';'
863 state->symbols->pop_scope();
866 | init_declarator_list ';'
870 | PRECISION precision_qualifier type_specifier ';'
872 $3->default_precision = $2;
882 function_declarator ')'
887 | function_header_with_parameters
890 function_header_with_parameters:
891 function_header parameter_declaration
894 $$->parameters.push_tail(& $2->link);
896 | function_header_with_parameters ',' parameter_declaration
899 $$->parameters.push_tail(& $3->link);
904 fully_specified_type variable_identifier '('
907 $$ = new(ctx) ast_function();
908 $$->set_location(@2);
909 $$->return_type = $1;
912 state->symbols->add_function(new(state) ir_function($2));
913 state->symbols->push_scope();
917 parameter_declarator:
918 type_specifier any_identifier
921 $$ = new(ctx) ast_parameter_declarator();
922 $$->set_location_range(@1, @2);
923 $$->type = new(ctx) ast_fully_specified_type();
924 $$->type->set_location(@1);
925 $$->type->specifier = $1;
928 | type_specifier any_identifier array_specifier
931 $$ = new(ctx) ast_parameter_declarator();
932 $$->set_location_range(@1, @3);
933 $$->type = new(ctx) ast_fully_specified_type();
934 $$->type->set_location(@1);
935 $$->type->specifier = $1;
937 $$->array_specifier = $3;
941 parameter_declaration:
942 parameter_qualifier parameter_declarator
945 $$->type->qualifier = $1;
947 | parameter_qualifier parameter_type_specifier
950 $$ = new(ctx) ast_parameter_declarator();
951 $$->set_location(@2);
952 $$->type = new(ctx) ast_fully_specified_type();
953 $$->type->set_location_range(@1, @2);
954 $$->type->qualifier = $1;
955 $$->type->specifier = $2;
962 memset(& $$, 0, sizeof($$));
964 | CONST_TOK parameter_qualifier
966 if ($2.flags.q.constant)
967 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
970 $$.flags.q.constant = 1;
972 | PRECISE parameter_qualifier
974 if ($2.flags.q.precise)
975 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
978 $$.flags.q.precise = 1;
980 | parameter_direction_qualifier parameter_qualifier
982 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
983 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
985 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
986 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
990 $$.merge_qualifier(&@1, state, $2);
992 | precision_qualifier parameter_qualifier
994 if ($2.precision != ast_precision_none)
995 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
997 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
998 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1004 parameter_direction_qualifier:
1007 memset(& $$, 0, sizeof($$));
1012 memset(& $$, 0, sizeof($$));
1017 memset(& $$, 0, sizeof($$));
1023 parameter_type_specifier:
1027 init_declarator_list:
1029 | init_declarator_list ',' any_identifier
1032 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1033 decl->set_location(@3);
1036 $$->declarations.push_tail(&decl->link);
1037 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1039 | init_declarator_list ',' any_identifier array_specifier
1042 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1043 decl->set_location_range(@3, @4);
1046 $$->declarations.push_tail(&decl->link);
1047 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1049 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1052 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1053 decl->set_location_range(@3, @4);
1056 $$->declarations.push_tail(&decl->link);
1057 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1059 | init_declarator_list ',' any_identifier '=' initializer
1062 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1063 decl->set_location(@3);
1066 $$->declarations.push_tail(&decl->link);
1067 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1071 // Grammar Note: No 'enum', or 'typedef'.
1073 fully_specified_type
1076 /* Empty declaration list is valid. */
1077 $$ = new(ctx) ast_declarator_list($1);
1078 $$->set_location(@1);
1080 | fully_specified_type any_identifier
1083 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1084 decl->set_location(@2);
1086 $$ = new(ctx) ast_declarator_list($1);
1087 $$->set_location_range(@1, @2);
1088 $$->declarations.push_tail(&decl->link);
1090 | fully_specified_type any_identifier array_specifier
1093 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1094 decl->set_location_range(@2, @3);
1096 $$ = new(ctx) ast_declarator_list($1);
1097 $$->set_location_range(@1, @3);
1098 $$->declarations.push_tail(&decl->link);
1100 | fully_specified_type any_identifier array_specifier '=' initializer
1103 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1104 decl->set_location_range(@2, @3);
1106 $$ = new(ctx) ast_declarator_list($1);
1107 $$->set_location_range(@1, @3);
1108 $$->declarations.push_tail(&decl->link);
1110 | fully_specified_type any_identifier '=' initializer
1113 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1114 decl->set_location(@2);
1116 $$ = new(ctx) ast_declarator_list($1);
1117 $$->set_location_range(@1, @2);
1118 $$->declarations.push_tail(&decl->link);
1120 | INVARIANT variable_identifier
1123 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1124 decl->set_location(@2);
1126 $$ = new(ctx) ast_declarator_list(NULL);
1127 $$->set_location_range(@1, @2);
1128 $$->invariant = true;
1130 $$->declarations.push_tail(&decl->link);
1132 | PRECISE variable_identifier
1135 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1136 decl->set_location(@2);
1138 $$ = new(ctx) ast_declarator_list(NULL);
1139 $$->set_location_range(@1, @2);
1142 $$->declarations.push_tail(&decl->link);
1146 fully_specified_type:
1150 $$ = new(ctx) ast_fully_specified_type();
1151 $$->set_location(@1);
1154 | type_qualifier type_specifier
1157 $$ = new(ctx) ast_fully_specified_type();
1158 $$->set_location_range(@1, @2);
1165 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1171 layout_qualifier_id_list:
1173 | layout_qualifier_id_list ',' layout_qualifier_id
1176 if (!$$.merge_qualifier(& @3, state, $3)) {
1183 INTCONSTANT { $$ = $1; }
1184 | UINTCONSTANT { $$ = $1; }
1187 layout_qualifier_id:
1190 memset(& $$, 0, sizeof($$));
1192 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1193 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1194 state->is_version(150, 0))) {
1195 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1196 $$.flags.q.origin_upper_left = 1;
1197 } else if (match_layout_qualifier($1, "pixel_center_integer",
1199 $$.flags.q.pixel_center_integer = 1;
1202 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1203 _mesa_glsl_warning(& @1, state,
1204 "GL_ARB_fragment_coord_conventions layout "
1205 "identifier `%s' used", $1);
1209 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1211 (state->AMD_conservative_depth_enable ||
1212 state->ARB_conservative_depth_enable)) {
1213 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1214 $$.flags.q.depth_any = 1;
1215 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1216 $$.flags.q.depth_greater = 1;
1217 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1218 $$.flags.q.depth_less = 1;
1219 } else if (match_layout_qualifier($1, "depth_unchanged",
1221 $$.flags.q.depth_unchanged = 1;
1224 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1225 _mesa_glsl_warning(& @1, state,
1226 "GL_AMD_conservative_depth "
1227 "layout qualifier `%s' is used", $1);
1229 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1230 _mesa_glsl_warning(& @1, state,
1231 "GL_ARB_conservative_depth "
1232 "layout qualifier `%s' is used", $1);
1236 /* See also interface_block_layout_qualifier. */
1237 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1238 if (match_layout_qualifier($1, "std140", state) == 0) {
1239 $$.flags.q.std140 = 1;
1240 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1241 $$.flags.q.shared = 1;
1242 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1243 $$.flags.q.column_major = 1;
1244 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1245 * below in the interface_block_layout_qualifier rule.
1247 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1250 * Also, this takes care of alternate capitalizations of
1251 * "row_major" (which is necessary because layout qualifiers
1252 * are case-insensitive in desktop GLSL).
1254 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1255 $$.flags.q.row_major = 1;
1256 /* "packed" is a reserved word in GLSL, and its token is
1257 * parsed below in the interface_block_layout_qualifier rule.
1258 * However, we must take care of alternate capitalizations of
1259 * "packed", because layout qualifiers are case-insensitive
1262 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1263 $$.flags.q.packed = 1;
1266 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1267 _mesa_glsl_warning(& @1, state,
1268 "#version 140 / GL_ARB_uniform_buffer_object "
1269 "layout qualifier `%s' is used", $1);
1273 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1275 static const struct {
1279 { "points", GL_POINTS },
1280 { "lines", GL_LINES },
1281 { "lines_adjacency", GL_LINES_ADJACENCY },
1282 { "line_strip", GL_LINE_STRIP },
1283 { "triangles", GL_TRIANGLES },
1284 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1285 { "triangle_strip", GL_TRIANGLE_STRIP },
1287 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1288 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1289 $$.flags.q.prim_type = 1;
1290 $$.prim_type = map[i].e;
1295 if ($$.flags.i && !state->is_version(150, 0)) {
1296 _mesa_glsl_error(& @1, state, "#version 150 layout "
1297 "qualifier `%s' used", $1);
1301 /* Layout qualifiers for ARB_shader_image_load_store. */
1302 if (state->ARB_shader_image_load_store_enable ||
1303 state->is_version(420, 0)) {
1305 static const struct {
1308 glsl_base_type base_type;
1310 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT },
1311 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT },
1312 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT },
1313 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT },
1314 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT },
1315 { "r32f", GL_R32F, GLSL_TYPE_FLOAT },
1316 { "r16f", GL_R16F, GLSL_TYPE_FLOAT },
1317 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT },
1318 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT },
1319 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT },
1320 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT },
1321 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT },
1322 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT },
1323 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT },
1324 { "r32ui", GL_R32UI, GLSL_TYPE_UINT },
1325 { "r16ui", GL_R16UI, GLSL_TYPE_UINT },
1326 { "r8ui", GL_R8UI, GLSL_TYPE_UINT },
1327 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT },
1328 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT },
1329 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT },
1330 { "rg32i", GL_RG32I, GLSL_TYPE_INT },
1331 { "rg16i", GL_RG16I, GLSL_TYPE_INT },
1332 { "rg8i", GL_RG8I, GLSL_TYPE_INT },
1333 { "r32i", GL_R32I, GLSL_TYPE_INT },
1334 { "r16i", GL_R16I, GLSL_TYPE_INT },
1335 { "r8i", GL_R8I, GLSL_TYPE_INT },
1336 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT },
1337 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT },
1338 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT },
1339 { "rg16", GL_RG16, GLSL_TYPE_FLOAT },
1340 { "rg8", GL_RG8, GLSL_TYPE_FLOAT },
1341 { "r16", GL_R16, GLSL_TYPE_FLOAT },
1342 { "r8", GL_R8, GLSL_TYPE_FLOAT },
1343 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT },
1344 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT },
1345 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT },
1346 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT },
1347 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT },
1348 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT }
1351 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1352 if (match_layout_qualifier($1, map[i].name, state) == 0) {
1353 $$.flags.q.explicit_image_format = 1;
1354 $$.image_format = map[i].format;
1355 $$.image_base_type = map[i].base_type;
1362 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1363 $$.flags.q.early_fragment_tests = 1;
1368 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1373 | any_identifier '=' integer_constant
1375 memset(& $$, 0, sizeof($$));
1377 if (match_layout_qualifier("location", $1, state) == 0) {
1378 $$.flags.q.explicit_location = 1;
1380 if ($$.flags.q.attribute == 1 &&
1381 state->ARB_explicit_attrib_location_warn) {
1382 _mesa_glsl_warning(& @1, state,
1383 "GL_ARB_explicit_attrib_location layout "
1384 "identifier `%s' used", $1);
1390 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1395 if (match_layout_qualifier("index", $1, state) == 0) {
1396 $$.flags.q.explicit_index = 1;
1401 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1406 if ((state->ARB_shading_language_420pack_enable ||
1407 state->ARB_shader_atomic_counters_enable) &&
1408 match_layout_qualifier("binding", $1, state) == 0) {
1409 $$.flags.q.explicit_binding = 1;
1413 if (state->ARB_shader_atomic_counters_enable &&
1414 match_layout_qualifier("offset", $1, state) == 0) {
1415 $$.flags.q.explicit_offset = 1;
1419 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1420 $$.flags.q.max_vertices = 1;
1423 _mesa_glsl_error(& @3, state,
1424 "invalid max_vertices %d specified", $3);
1427 $$.max_vertices = $3;
1428 if (!state->is_version(150, 0)) {
1429 _mesa_glsl_error(& @3, state,
1430 "#version 150 max_vertices qualifier "
1436 if (state->stage == MESA_SHADER_GEOMETRY) {
1437 if (match_layout_qualifier("stream", $1, state) == 0 &&
1438 state->check_explicit_attrib_stream_allowed(& @3)) {
1439 $$.flags.q.stream = 1;
1442 _mesa_glsl_error(& @3, state,
1443 "invalid stream %d specified", $3);
1446 $$.flags.q.explicit_stream = 1;
1452 static const char * const local_size_qualifiers[3] = {
1457 for (int i = 0; i < 3; i++) {
1458 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1461 _mesa_glsl_error(& @3, state,
1462 "invalid %s of %d specified",
1463 local_size_qualifiers[i], $3);
1465 } else if (!state->is_version(430, 0) &&
1466 !state->ARB_compute_shader_enable) {
1467 _mesa_glsl_error(& @3, state,
1468 "%s qualifier requires GLSL 4.30 or "
1469 "ARB_compute_shader",
1470 local_size_qualifiers[i]);
1473 $$.flags.q.local_size |= (1 << i);
1474 $$.local_size[i] = $3;
1480 if (match_layout_qualifier("invocations", $1, state) == 0) {
1481 $$.flags.q.invocations = 1;
1484 _mesa_glsl_error(& @3, state,
1485 "invalid invocations %d specified", $3);
1487 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1488 _mesa_glsl_error(& @3, state,
1489 "invocations (%d) exceeds "
1490 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1493 $$.invocations = $3;
1494 if (!state->is_version(400, 0) &&
1495 !state->ARB_gpu_shader5_enable) {
1496 _mesa_glsl_error(& @3, state,
1497 "GL_ARB_gpu_shader5 invocations "
1498 "qualifier specified", $3);
1503 /* If the identifier didn't match any known layout identifiers,
1507 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1512 | interface_block_layout_qualifier
1515 /* Layout qualifiers for ARB_uniform_buffer_object. */
1516 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1517 _mesa_glsl_error(& @1, state,
1518 "#version 140 / GL_ARB_uniform_buffer_object "
1519 "layout qualifier `%s' is used", $1);
1520 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1521 _mesa_glsl_warning(& @1, state,
1522 "#version 140 / GL_ARB_uniform_buffer_object "
1523 "layout qualifier `%s' is used", $1);
1528 /* This is a separate language rule because we parse these as tokens
1529 * (due to them being reserved keywords) instead of identifiers like
1530 * most qualifiers. See the any_identifier path of
1531 * layout_qualifier_id for the others.
1533 * Note that since layout qualifiers are case-insensitive in desktop
1534 * GLSL, all of these qualifiers need to be handled as identifiers as
1535 * well (by the any_identifier path of layout_qualifier_id).
1537 interface_block_layout_qualifier:
1540 memset(& $$, 0, sizeof($$));
1541 $$.flags.q.row_major = 1;
1545 memset(& $$, 0, sizeof($$));
1546 $$.flags.q.packed = 1;
1550 interpolation_qualifier:
1553 memset(& $$, 0, sizeof($$));
1554 $$.flags.q.smooth = 1;
1558 memset(& $$, 0, sizeof($$));
1559 $$.flags.q.flat = 1;
1563 memset(& $$, 0, sizeof($$));
1564 $$.flags.q.noperspective = 1;
1569 /* Single qualifiers */
1572 memset(& $$, 0, sizeof($$));
1573 $$.flags.q.invariant = 1;
1577 memset(& $$, 0, sizeof($$));
1578 $$.flags.q.precise = 1;
1580 | auxiliary_storage_qualifier
1582 | interpolation_qualifier
1584 | precision_qualifier
1586 memset(&$$, 0, sizeof($$));
1590 /* Multiple qualifiers:
1591 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1592 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1594 * invariant interpolation auxiliary storage precision ...or...
1595 * layout storage precision
1597 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1598 * side don't contain any that must appear on the left hand side.
1599 * For example, when processing a storage qualifier, we check that there are
1600 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1602 | PRECISE type_qualifier
1604 if ($2.flags.q.precise)
1605 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1608 $$.flags.q.precise = 1;
1610 | INVARIANT type_qualifier
1612 if ($2.flags.q.invariant)
1613 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1615 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.precise)
1616 _mesa_glsl_error(&@1, state,
1617 "\"invariant\" must come after \"precise\"");
1620 $$.flags.q.invariant = 1;
1622 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1624 * "Only variables output from a shader can be candidates for invariance.
1625 * This includes user-defined output variables and the built-in output
1626 * variables. As only outputs can be declared as invariant, an invariant
1627 * output from one shader stage will still match an input of a subsequent
1628 * stage without the input being declared as invariant."
1630 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1631 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1633 | interpolation_qualifier type_qualifier
1635 /* Section 4.3 of the GLSL 1.40 specification states:
1636 * "...qualified with one of these interpolation qualifiers"
1638 * GLSL 1.30 claims to allow "one or more", but insists that:
1639 * "These interpolation qualifiers may only precede the qualifiers in,
1640 * centroid in, out, or centroid out in a declaration."
1642 * ...which means that e.g. smooth can't precede smooth, so there can be
1643 * only one after all, and the 1.40 text is a clarification, not a change.
1645 if ($2.has_interpolation())
1646 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1648 if (!state->ARB_shading_language_420pack_enable &&
1649 ($2.flags.q.precise || $2.flags.q.invariant)) {
1650 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1651 "after \"precise\" or \"invariant\"");
1655 $$.merge_qualifier(&@1, state, $2);
1657 | layout_qualifier type_qualifier
1659 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1660 * appear no later than auxiliary storage qualifiers. There is no
1661 * particularly clear spec language mandating this, but in all examples
1662 * the layout qualifier precedes the storage qualifier.
1664 * We allow combinations of layout with interpolation, invariant or
1665 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1666 * There is no clear spec guidance on this either.
1668 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1669 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1672 $$.merge_qualifier(&@1, state, $2);
1674 | auxiliary_storage_qualifier type_qualifier
1676 if ($2.has_auxiliary_storage()) {
1677 _mesa_glsl_error(&@1, state,
1678 "duplicate auxiliary storage qualifier (centroid or sample)");
1681 if (!state->ARB_shading_language_420pack_enable &&
1682 ($2.flags.q.precise || $2.flags.q.invariant ||
1683 $2.has_interpolation() || $2.has_layout())) {
1684 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1685 "just before storage qualifiers");
1688 $$.merge_qualifier(&@1, state, $2);
1690 | storage_qualifier type_qualifier
1692 /* Section 4.3 of the GLSL 1.20 specification states:
1693 * "Variable declarations may have a storage qualifier specified..."
1694 * 1.30 clarifies this to "may have one storage qualifier".
1696 if ($2.has_storage())
1697 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1699 if (!state->ARB_shading_language_420pack_enable &&
1700 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1701 $2.has_layout() || $2.has_auxiliary_storage())) {
1702 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1703 "precise, invariant, interpolation, layout and auxiliary "
1704 "storage qualifiers");
1708 $$.merge_qualifier(&@1, state, $2);
1710 | precision_qualifier type_qualifier
1712 if ($2.precision != ast_precision_none)
1713 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1715 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1716 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1723 auxiliary_storage_qualifier:
1726 memset(& $$, 0, sizeof($$));
1727 $$.flags.q.centroid = 1;
1731 memset(& $$, 0, sizeof($$));
1732 $$.flags.q.sample = 1;
1734 /* TODO: "patch" also goes here someday. */
1739 memset(& $$, 0, sizeof($$));
1740 $$.flags.q.constant = 1;
1744 memset(& $$, 0, sizeof($$));
1745 $$.flags.q.attribute = 1;
1749 memset(& $$, 0, sizeof($$));
1750 $$.flags.q.varying = 1;
1754 memset(& $$, 0, sizeof($$));
1759 memset(& $$, 0, sizeof($$));
1762 if (state->stage == MESA_SHADER_GEOMETRY &&
1763 state->has_explicit_attrib_stream()) {
1764 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1767 * "If the block or variable is declared with the stream
1768 * identifier, it is associated with the specified stream;
1769 * otherwise, it is associated with the current default stream."
1771 $$.flags.q.stream = 1;
1772 $$.flags.q.explicit_stream = 0;
1773 $$.stream = state->out_qualifier->stream;
1778 memset(& $$, 0, sizeof($$));
1779 $$.flags.q.uniform = 1;
1783 memset(& $$, 0, sizeof($$));
1784 $$.flags.q.coherent = 1;
1788 memset(& $$, 0, sizeof($$));
1789 $$.flags.q._volatile = 1;
1793 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1794 memset(& $$, 0, sizeof($$));
1795 $$.flags.q.restrict_flag = 1;
1799 memset(& $$, 0, sizeof($$));
1800 $$.flags.q.read_only = 1;
1804 memset(& $$, 0, sizeof($$));
1805 $$.flags.q.write_only = 1;
1813 $$ = new(ctx) ast_array_specifier(@1);
1814 $$->set_location_range(@1, @2);
1816 | '[' constant_expression ']'
1819 $$ = new(ctx) ast_array_specifier(@1, $2);
1820 $$->set_location_range(@1, @3);
1822 | array_specifier '[' ']'
1826 if (!state->ARB_arrays_of_arrays_enable) {
1827 _mesa_glsl_error(& @1, state,
1828 "GL_ARB_arrays_of_arrays "
1829 "required for defining arrays of arrays");
1831 _mesa_glsl_error(& @1, state,
1832 "only the outermost array dimension can "
1836 | array_specifier '[' constant_expression ']'
1840 if (!state->ARB_arrays_of_arrays_enable) {
1841 _mesa_glsl_error(& @1, state,
1842 "GL_ARB_arrays_of_arrays "
1843 "required for defining arrays of arrays");
1846 $$->add_dimension($3);
1851 type_specifier_nonarray
1852 | type_specifier_nonarray array_specifier
1855 $$->array_specifier = $2;
1859 type_specifier_nonarray:
1860 basic_type_specifier_nonarray
1863 $$ = new(ctx) ast_type_specifier($1);
1864 $$->set_location(@1);
1869 $$ = new(ctx) ast_type_specifier($1);
1870 $$->set_location(@1);
1875 $$ = new(ctx) ast_type_specifier($1);
1876 $$->set_location(@1);
1880 basic_type_specifier_nonarray:
1881 VOID_TOK { $$ = "void"; }
1882 | FLOAT_TOK { $$ = "float"; }
1883 | DOUBLE_TOK { $$ = "double"; }
1884 | INT_TOK { $$ = "int"; }
1885 | UINT_TOK { $$ = "uint"; }
1886 | BOOL_TOK { $$ = "bool"; }
1887 | VEC2 { $$ = "vec2"; }
1888 | VEC3 { $$ = "vec3"; }
1889 | VEC4 { $$ = "vec4"; }
1890 | BVEC2 { $$ = "bvec2"; }
1891 | BVEC3 { $$ = "bvec3"; }
1892 | BVEC4 { $$ = "bvec4"; }
1893 | IVEC2 { $$ = "ivec2"; }
1894 | IVEC3 { $$ = "ivec3"; }
1895 | IVEC4 { $$ = "ivec4"; }
1896 | UVEC2 { $$ = "uvec2"; }
1897 | UVEC3 { $$ = "uvec3"; }
1898 | UVEC4 { $$ = "uvec4"; }
1899 | DVEC2 { $$ = "dvec2"; }
1900 | DVEC3 { $$ = "dvec3"; }
1901 | DVEC4 { $$ = "dvec4"; }
1902 | MAT2X2 { $$ = "mat2"; }
1903 | MAT2X3 { $$ = "mat2x3"; }
1904 | MAT2X4 { $$ = "mat2x4"; }
1905 | MAT3X2 { $$ = "mat3x2"; }
1906 | MAT3X3 { $$ = "mat3"; }
1907 | MAT3X4 { $$ = "mat3x4"; }
1908 | MAT4X2 { $$ = "mat4x2"; }
1909 | MAT4X3 { $$ = "mat4x3"; }
1910 | MAT4X4 { $$ = "mat4"; }
1911 | DMAT2X2 { $$ = "dmat2"; }
1912 | DMAT2X3 { $$ = "dmat2x3"; }
1913 | DMAT2X4 { $$ = "dmat2x4"; }
1914 | DMAT3X2 { $$ = "dmat3x2"; }
1915 | DMAT3X3 { $$ = "dmat3"; }
1916 | DMAT3X4 { $$ = "dmat3x4"; }
1917 | DMAT4X2 { $$ = "dmat4x2"; }
1918 | DMAT4X3 { $$ = "dmat4x3"; }
1919 | DMAT4X4 { $$ = "dmat4"; }
1920 | SAMPLER1D { $$ = "sampler1D"; }
1921 | SAMPLER2D { $$ = "sampler2D"; }
1922 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1923 | SAMPLER3D { $$ = "sampler3D"; }
1924 | SAMPLERCUBE { $$ = "samplerCube"; }
1925 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1926 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1927 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1928 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1929 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1930 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1931 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1932 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1933 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1934 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1935 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1936 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1937 | ISAMPLER1D { $$ = "isampler1D"; }
1938 | ISAMPLER2D { $$ = "isampler2D"; }
1939 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1940 | ISAMPLER3D { $$ = "isampler3D"; }
1941 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1942 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1943 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1944 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1945 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1946 | USAMPLER1D { $$ = "usampler1D"; }
1947 | USAMPLER2D { $$ = "usampler2D"; }
1948 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1949 | USAMPLER3D { $$ = "usampler3D"; }
1950 | USAMPLERCUBE { $$ = "usamplerCube"; }
1951 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1952 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1953 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1954 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1955 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1956 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1957 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1958 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1959 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1960 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1961 | IMAGE1D { $$ = "image1D"; }
1962 | IMAGE2D { $$ = "image2D"; }
1963 | IMAGE3D { $$ = "image3D"; }
1964 | IMAGE2DRECT { $$ = "image2DRect"; }
1965 | IMAGECUBE { $$ = "imageCube"; }
1966 | IMAGEBUFFER { $$ = "imageBuffer"; }
1967 | IMAGE1DARRAY { $$ = "image1DArray"; }
1968 | IMAGE2DARRAY { $$ = "image2DArray"; }
1969 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
1970 | IMAGE2DMS { $$ = "image2DMS"; }
1971 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
1972 | IIMAGE1D { $$ = "iimage1D"; }
1973 | IIMAGE2D { $$ = "iimage2D"; }
1974 | IIMAGE3D { $$ = "iimage3D"; }
1975 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
1976 | IIMAGECUBE { $$ = "iimageCube"; }
1977 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
1978 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
1979 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
1980 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
1981 | IIMAGE2DMS { $$ = "iimage2DMS"; }
1982 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
1983 | UIMAGE1D { $$ = "uimage1D"; }
1984 | UIMAGE2D { $$ = "uimage2D"; }
1985 | UIMAGE3D { $$ = "uimage3D"; }
1986 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
1987 | UIMAGECUBE { $$ = "uimageCube"; }
1988 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
1989 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
1990 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
1991 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
1992 | UIMAGE2DMS { $$ = "uimage2DMS"; }
1993 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
1994 | ATOMIC_UINT { $$ = "atomic_uint"; }
1997 precision_qualifier:
2000 state->check_precision_qualifiers_allowed(&@1);
2001 $$ = ast_precision_high;
2005 state->check_precision_qualifiers_allowed(&@1);
2006 $$ = ast_precision_medium;
2010 state->check_precision_qualifiers_allowed(&@1);
2011 $$ = ast_precision_low;
2016 STRUCT any_identifier '{' struct_declaration_list '}'
2019 $$ = new(ctx) ast_struct_specifier($2, $4);
2020 $$->set_location_range(@2, @5);
2021 state->symbols->add_type($2, glsl_type::void_type);
2023 | STRUCT '{' struct_declaration_list '}'
2026 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2027 $$->set_location_range(@2, @4);
2031 struct_declaration_list:
2035 $1->link.self_link();
2037 | struct_declaration_list struct_declaration
2040 $$->link.insert_before(& $2->link);
2045 fully_specified_type struct_declarator_list ';'
2048 ast_fully_specified_type *const type = $1;
2049 type->set_location(@1);
2051 if (type->qualifier.flags.i != 0)
2052 _mesa_glsl_error(&@1, state,
2053 "only precision qualifiers may be applied to "
2054 "structure members");
2056 $$ = new(ctx) ast_declarator_list(type);
2057 $$->set_location(@2);
2059 $$->declarations.push_degenerate_list_at_head(& $2->link);
2063 struct_declarator_list:
2067 $1->link.self_link();
2069 | struct_declarator_list ',' struct_declarator
2072 $$->link.insert_before(& $3->link);
2080 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2081 $$->set_location(@1);
2083 | any_identifier array_specifier
2086 $$ = new(ctx) ast_declaration($1, $2, NULL);
2087 $$->set_location_range(@1, @2);
2092 assignment_expression
2093 | '{' initializer_list '}'
2097 | '{' initializer_list ',' '}'
2107 $$ = new(ctx) ast_aggregate_initializer();
2108 $$->set_location(@1);
2109 $$->expressions.push_tail(& $1->link);
2111 | initializer_list ',' initializer
2113 $1->expressions.push_tail(& $3->link);
2117 declaration_statement:
2121 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2124 compound_statement { $$ = (ast_node *) $1; }
2129 declaration_statement
2130 | expression_statement
2131 | selection_statement
2133 | iteration_statement
2141 $$ = new(ctx) ast_compound_statement(true, NULL);
2142 $$->set_location_range(@1, @2);
2146 state->symbols->push_scope();
2151 $$ = new(ctx) ast_compound_statement(true, $3);
2152 $$->set_location_range(@1, @4);
2153 state->symbols->pop_scope();
2157 statement_no_new_scope:
2158 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2162 compound_statement_no_new_scope:
2166 $$ = new(ctx) ast_compound_statement(false, NULL);
2167 $$->set_location_range(@1, @2);
2169 | '{' statement_list '}'
2172 $$ = new(ctx) ast_compound_statement(false, $2);
2173 $$->set_location_range(@1, @3);
2181 _mesa_glsl_error(& @1, state, "<nil> statement");
2186 $$->link.self_link();
2188 | statement_list statement
2191 _mesa_glsl_error(& @2, state, "<nil> statement");
2195 $$->link.insert_before(& $2->link);
2199 expression_statement:
2203 $$ = new(ctx) ast_expression_statement(NULL);
2204 $$->set_location(@1);
2209 $$ = new(ctx) ast_expression_statement($1);
2210 $$->set_location(@1);
2214 selection_statement:
2215 IF '(' expression ')' selection_rest_statement
2217 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2219 $$->set_location_range(@1, @5);
2223 selection_rest_statement:
2224 statement ELSE statement
2226 $$.then_statement = $1;
2227 $$.else_statement = $3;
2229 | statement %prec THEN
2231 $$.then_statement = $1;
2232 $$.else_statement = NULL;
2239 $$ = (ast_node *) $1;
2241 | fully_specified_type any_identifier '=' initializer
2244 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2245 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2246 decl->set_location_range(@2, @4);
2247 declarator->set_location(@1);
2249 declarator->declarations.push_tail(&decl->link);
2255 * switch_statement grammar is based on the syntax described in the body
2256 * of the GLSL spec, not in it's appendix!!!
2259 SWITCH '(' expression ')' switch_body
2261 $$ = new(state) ast_switch_statement($3, $5);
2262 $$->set_location_range(@1, @5);
2269 $$ = new(state) ast_switch_body(NULL);
2270 $$->set_location_range(@1, @2);
2272 | '{' case_statement_list '}'
2274 $$ = new(state) ast_switch_body($2);
2275 $$->set_location_range(@1, @3);
2282 $$ = new(state) ast_case_label($2);
2283 $$->set_location(@2);
2287 $$ = new(state) ast_case_label(NULL);
2288 $$->set_location(@2);
2295 ast_case_label_list *labels = new(state) ast_case_label_list();
2297 labels->labels.push_tail(& $1->link);
2299 $$->set_location(@1);
2301 | case_label_list case_label
2304 $$->labels.push_tail(& $2->link);
2309 case_label_list statement
2311 ast_case_statement *stmts = new(state) ast_case_statement($1);
2312 stmts->set_location(@2);
2314 stmts->stmts.push_tail(& $2->link);
2317 | case_statement statement
2320 $$->stmts.push_tail(& $2->link);
2324 case_statement_list:
2327 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2328 cases->set_location(@1);
2330 cases->cases.push_tail(& $1->link);
2333 | case_statement_list case_statement
2336 $$->cases.push_tail(& $2->link);
2340 iteration_statement:
2341 WHILE '(' condition ')' statement_no_new_scope
2344 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2345 NULL, $3, NULL, $5);
2346 $$->set_location_range(@1, @4);
2348 | DO statement WHILE '(' expression ')' ';'
2351 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2352 NULL, $5, NULL, $2);
2353 $$->set_location_range(@1, @6);
2355 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2358 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2359 $3, $4.cond, $4.rest, $6);
2360 $$->set_location_range(@1, @6);
2365 expression_statement
2366 | declaration_statement
2383 | conditionopt ';' expression
2390 // Grammar Note: No 'goto'. Gotos are not supported.
2395 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2396 $$->set_location(@1);
2401 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2402 $$->set_location(@1);
2407 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2408 $$->set_location(@1);
2410 | RETURN expression ';'
2413 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2414 $$->set_location_range(@1, @2);
2416 | DISCARD ';' // Fragment shader only.
2419 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2420 $$->set_location(@1);
2424 external_declaration:
2425 function_definition { $$ = $1; }
2426 | declaration { $$ = $1; }
2427 | pragma_statement { $$ = NULL; }
2428 | layout_defaults { $$ = $1; }
2431 function_definition:
2432 function_prototype compound_statement_no_new_scope
2435 $$ = new(ctx) ast_function_definition();
2436 $$->set_location_range(@1, @2);
2440 state->symbols->pop_scope();
2444 /* layout_qualifieropt is packed into this rule */
2446 basic_interface_block
2450 | layout_qualifier basic_interface_block
2452 ast_interface_block *block = $2;
2453 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2457 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2458 ast_type_qualifier& qualifier = member->type->qualifier;
2459 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2460 _mesa_glsl_error(& @1, state,
2461 "stream layout qualifier on "
2462 "interface block member does not match "
2463 "the interface block (%d vs %d)",
2464 qualifier.stream, block->layout.stream);
2472 basic_interface_block:
2473 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2475 ast_interface_block *const block = $6;
2477 block->block_name = $2;
2478 block->declarations.push_degenerate_list_at_head(& $4->link);
2480 if ($1.flags.q.uniform) {
2481 if (!state->has_uniform_buffer_objects()) {
2482 _mesa_glsl_error(& @1, state,
2483 "#version 140 / GL_ARB_uniform_buffer_object "
2484 "required for defining uniform blocks");
2485 } else if (state->ARB_uniform_buffer_object_warn) {
2486 _mesa_glsl_warning(& @1, state,
2487 "#version 140 / GL_ARB_uniform_buffer_object "
2488 "required for defining uniform blocks");
2491 if (state->es_shader || state->language_version < 150) {
2492 _mesa_glsl_error(& @1, state,
2493 "#version 150 required for using "
2494 "interface blocks");
2498 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2499 * "It is illegal to have an input block in a vertex shader
2500 * or an output block in a fragment shader"
2502 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2503 _mesa_glsl_error(& @1, state,
2504 "`in' interface block is not allowed for "
2506 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2507 _mesa_glsl_error(& @1, state,
2508 "`out' interface block is not allowed for "
2509 "a fragment shader");
2512 /* Since block arrays require names, and both features are added in
2513 * the same language versions, we don't have to explicitly
2514 * version-check both things.
2516 if (block->instance_name != NULL) {
2517 state->check_version(150, 300, & @1, "interface blocks with "
2518 "an instance name are not allowed");
2521 uint64_t interface_type_mask;
2522 struct ast_type_qualifier temp_type_qualifier;
2524 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2525 * to ignore other irrelevant flags like interpolation qualifiers.
2527 temp_type_qualifier.flags.i = 0;
2528 temp_type_qualifier.flags.q.uniform = true;
2529 temp_type_qualifier.flags.q.in = true;
2530 temp_type_qualifier.flags.q.out = true;
2531 interface_type_mask = temp_type_qualifier.flags.i;
2533 /* Get the block's interface qualifier. The interface_qualifier
2534 * production rule guarantees that only one bit will be set (and
2535 * it will be in/out/uniform).
2537 uint64_t block_interface_qualifier = $1.flags.i;
2539 block->layout.flags.i |= block_interface_qualifier;
2541 if (state->stage == MESA_SHADER_GEOMETRY &&
2542 state->has_explicit_attrib_stream()) {
2543 /* Assign global layout's stream value. */
2544 block->layout.flags.q.stream = 1;
2545 block->layout.flags.q.explicit_stream = 0;
2546 block->layout.stream = state->out_qualifier->stream;
2549 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2550 ast_type_qualifier& qualifier = member->type->qualifier;
2551 if ((qualifier.flags.i & interface_type_mask) == 0) {
2552 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2553 * "If no optional qualifier is used in a member declaration, the
2554 * qualifier of the variable is just in, out, or uniform as declared
2555 * by interface-qualifier."
2557 qualifier.flags.i |= block_interface_qualifier;
2558 } else if ((qualifier.flags.i & interface_type_mask) !=
2559 block_interface_qualifier) {
2560 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2561 * "If optional qualifiers are used, they can include interpolation
2562 * and storage qualifiers and they must declare an input, output,
2563 * or uniform variable consistent with the interface qualifier of
2566 _mesa_glsl_error(& @1, state,
2567 "uniform/in/out qualifier on "
2568 "interface block member does not match "
2569 "the interface block");
2572 /* From GLSL ES 3.0, chapter 4.3.7 "Interface Blocks":
2574 * "GLSL ES 3.0 does not support interface blocks for shader inputs or
2577 * And from GLSL ES 3.0, chapter 4.6.1 "The invariant qualifier":.
2579 * "Only variables output from a shader can be candidates for
2582 * From GLSL 4.40 and GLSL 1.50, section "Interface Blocks":
2584 * "If optional qualifiers are used, they can include interpolation
2585 * qualifiers, auxiliary storage qualifiers, and storage qualifiers
2586 * and they must declare an input, output, or uniform member
2587 * consistent with the interface qualifier of the block"
2589 if (qualifier.flags.q.invariant)
2590 _mesa_glsl_error(&@1, state,
2591 "invariant qualifiers cannot be used "
2592 "with interface blocks members");
2599 interface_qualifier:
2602 memset(& $$, 0, sizeof($$));
2607 memset(& $$, 0, sizeof($$));
2612 memset(& $$, 0, sizeof($$));
2613 $$.flags.q.uniform = 1;
2620 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2625 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2627 $$->set_location(@1);
2629 | NEW_IDENTIFIER array_specifier
2631 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2633 $$->set_location_range(@1, @2);
2641 $1->link.self_link();
2643 | member_declaration member_list
2646 $2->link.insert_before(& $$->link);
2651 fully_specified_type struct_declarator_list ';'
2654 ast_fully_specified_type *type = $1;
2655 type->set_location(@1);
2657 if (type->qualifier.flags.q.attribute) {
2658 _mesa_glsl_error(& @1, state,
2659 "keyword 'attribute' cannot be used with "
2660 "interface block member");
2661 } else if (type->qualifier.flags.q.varying) {
2662 _mesa_glsl_error(& @1, state,
2663 "keyword 'varying' cannot be used with "
2664 "interface block member");
2667 $$ = new(ctx) ast_declarator_list(type);
2668 $$->set_location(@2);
2670 $$->declarations.push_degenerate_list_at_head(& $2->link);
2675 layout_qualifier UNIFORM ';'
2677 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2683 | layout_qualifier IN_TOK ';'
2686 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2691 | layout_qualifier OUT_TOK ';'
2693 if (state->stage != MESA_SHADER_GEOMETRY) {
2694 _mesa_glsl_error(& @1, state,
2695 "out layout qualifiers only valid in "
2696 "geometry shaders");
2698 if ($1.flags.q.prim_type) {
2699 /* Make sure this is a valid output primitive type. */
2700 switch ($1.prim_type) {
2703 case GL_TRIANGLE_STRIP:
2706 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2711 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2714 /* Allow future assigments of global out's stream id value */
2715 state->out_qualifier->flags.q.explicit_stream = 0;