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"
39 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
41 _mesa_glsl_error(loc, st, "%s", msg);
45 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
47 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
50 static bool match_layout_qualifier(const char *s1, const char *s2,
51 _mesa_glsl_parse_state *state)
53 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
55 * "The tokens in any layout-qualifier-id-list ... are not case
56 * sensitive, unless explicitly noted otherwise."
58 * The text "unless explicitly noted otherwise" appears to be
59 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
62 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
65 * "As for other identifiers, they are case sensitive."
67 * So we need to do a case-sensitive or a case-insensitive match,
68 * depending on whether we are compiling for GLSL ES.
71 return strcmp(s1, s2);
73 return strcasecmp(s1, s2);
91 %lex-param {struct _mesa_glsl_parse_state *state}
92 %parse-param {struct _mesa_glsl_parse_state *state}
98 const char *identifier;
100 struct ast_type_qualifier type_qualifier;
103 ast_type_specifier *type_specifier;
104 ast_array_specifier *array_specifier;
105 ast_fully_specified_type *fully_specified_type;
106 ast_function *function;
107 ast_parameter_declarator *parameter_declarator;
108 ast_function_definition *function_definition;
109 ast_compound_statement *compound_statement;
110 ast_expression *expression;
111 ast_declarator_list *declarator_list;
112 ast_struct_specifier *struct_specifier;
113 ast_declaration *declaration;
114 ast_switch_body *switch_body;
115 ast_case_label *case_label;
116 ast_case_label_list *case_label_list;
117 ast_case_statement *case_statement;
118 ast_case_statement_list *case_statement_list;
119 ast_interface_block *interface_block;
123 ast_expression *rest;
124 } for_rest_statement;
127 ast_node *then_statement;
128 ast_node *else_statement;
129 } selection_rest_statement;
132 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
133 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
134 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
135 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
136 %token NOPERSPECTIVE FLAT SMOOTH
137 %token MAT2X2 MAT2X3 MAT2X4
138 %token MAT3X2 MAT3X3 MAT3X4
139 %token MAT4X2 MAT4X3 MAT4X4
140 %token DMAT2X2 DMAT2X3 DMAT2X4
141 %token DMAT3X2 DMAT3X3 DMAT3X4
142 %token DMAT4X2 DMAT4X3 DMAT4X4
143 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
144 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
145 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
146 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
147 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
148 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
149 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
150 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
151 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
152 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
153 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
154 %token SAMPLEREXTERNALOES
155 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
156 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
157 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
158 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
159 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
160 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
161 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
162 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
164 %token STRUCT VOID_TOK WHILE
165 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
166 %type <identifier> any_identifier
167 %type <interface_block> instance_name_opt
168 %token <real> FLOATCONSTANT
169 %token <dreal> DOUBLECONSTANT
170 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
171 %token <identifier> FIELD_SELECTION
172 %token LEFT_OP RIGHT_OP
173 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
174 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
175 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
177 %token INVARIANT PRECISE
178 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
180 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
181 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
182 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
183 %token PRAGMA_INVARIANT_ALL
186 /* Reserved words that are not actually used in the grammar.
188 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
189 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
190 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
191 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
193 %token SIZEOF CAST NAMESPACE USING
194 %token RESOURCE PATCH
199 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
201 %type <identifier> variable_identifier
202 %type <node> statement
203 %type <node> statement_list
204 %type <node> simple_statement
205 %type <n> precision_qualifier
206 %type <type_qualifier> type_qualifier
207 %type <type_qualifier> auxiliary_storage_qualifier
208 %type <type_qualifier> storage_qualifier
209 %type <type_qualifier> interpolation_qualifier
210 %type <type_qualifier> layout_qualifier
211 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
212 %type <type_qualifier> interface_block_layout_qualifier
213 %type <type_qualifier> interface_qualifier
214 %type <type_specifier> type_specifier
215 %type <type_specifier> type_specifier_nonarray
216 %type <array_specifier> array_specifier
217 %type <identifier> basic_type_specifier_nonarray
218 %type <fully_specified_type> fully_specified_type
219 %type <function> function_prototype
220 %type <function> function_header
221 %type <function> function_header_with_parameters
222 %type <function> function_declarator
223 %type <parameter_declarator> parameter_declarator
224 %type <parameter_declarator> parameter_declaration
225 %type <type_qualifier> parameter_qualifier
226 %type <type_qualifier> parameter_direction_qualifier
227 %type <type_specifier> parameter_type_specifier
228 %type <function_definition> function_definition
229 %type <compound_statement> compound_statement_no_new_scope
230 %type <compound_statement> compound_statement
231 %type <node> statement_no_new_scope
232 %type <node> expression_statement
233 %type <expression> expression
234 %type <expression> primary_expression
235 %type <expression> assignment_expression
236 %type <expression> conditional_expression
237 %type <expression> logical_or_expression
238 %type <expression> logical_xor_expression
239 %type <expression> logical_and_expression
240 %type <expression> inclusive_or_expression
241 %type <expression> exclusive_or_expression
242 %type <expression> and_expression
243 %type <expression> equality_expression
244 %type <expression> relational_expression
245 %type <expression> shift_expression
246 %type <expression> additive_expression
247 %type <expression> multiplicative_expression
248 %type <expression> unary_expression
249 %type <expression> constant_expression
250 %type <expression> integer_expression
251 %type <expression> postfix_expression
252 %type <expression> function_call_header_with_parameters
253 %type <expression> function_call_header_no_parameters
254 %type <expression> function_call_header
255 %type <expression> function_call_generic
256 %type <expression> function_call_or_method
257 %type <expression> function_call
258 %type <expression> method_call_generic
259 %type <expression> method_call_header_with_parameters
260 %type <expression> method_call_header_no_parameters
261 %type <expression> method_call_header
262 %type <n> assignment_operator
263 %type <n> unary_operator
264 %type <expression> function_identifier
265 %type <node> external_declaration
266 %type <declarator_list> init_declarator_list
267 %type <declarator_list> single_declaration
268 %type <expression> initializer
269 %type <expression> initializer_list
270 %type <node> declaration
271 %type <node> declaration_statement
272 %type <node> jump_statement
273 %type <node> interface_block
274 %type <interface_block> basic_interface_block
275 %type <struct_specifier> struct_specifier
276 %type <declarator_list> struct_declaration_list
277 %type <declarator_list> struct_declaration
278 %type <declaration> struct_declarator
279 %type <declaration> struct_declarator_list
280 %type <declarator_list> member_list
281 %type <declarator_list> member_declaration
282 %type <node> selection_statement
283 %type <selection_rest_statement> selection_rest_statement
284 %type <node> switch_statement
285 %type <switch_body> switch_body
286 %type <case_label_list> case_label_list
287 %type <case_label> case_label
288 %type <case_statement> case_statement
289 %type <case_statement_list> case_statement_list
290 %type <node> iteration_statement
291 %type <node> condition
292 %type <node> conditionopt
293 %type <node> for_init_statement
294 %type <for_rest_statement> for_rest_statement
295 %type <n> integer_constant
296 %type <node> layout_defaults
302 version_statement extension_statement_list
304 _mesa_glsl_initialize_types(state);
306 external_declaration_list
308 delete state->symbols;
309 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
310 _mesa_glsl_initialize_types(state);
315 /* blank - no #version specified: defaults are already set */
316 | VERSION_TOK INTCONSTANT EOL
318 state->process_version_directive(&@2, $2, NULL);
323 | VERSION_TOK INTCONSTANT any_identifier EOL
325 state->process_version_directive(&@2, $2, $3);
334 | PRAGMA_DEBUG_OFF EOL
335 | PRAGMA_OPTIMIZE_ON EOL
336 | PRAGMA_OPTIMIZE_OFF EOL
337 | PRAGMA_INVARIANT_ALL EOL
339 /* Pragma invariant(all) cannot be used in a fragment shader.
341 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
343 * "It is an error to use this pragma in a fragment shader."
345 if (state->is_version(120, 300) &&
346 state->stage == MESA_SHADER_FRAGMENT) {
347 _mesa_glsl_error(& @1, state,
348 "pragma `invariant(all)' cannot be used "
349 "in a fragment shader.");
350 } else if (!state->is_version(120, 100)) {
351 _mesa_glsl_warning(& @1, state,
352 "pragma `invariant(all)' not supported in %s "
353 "(GLSL ES 1.00 or GLSL 1.20 required)",
354 state->get_version_string());
356 state->all_invariant = true;
361 extension_statement_list:
363 | extension_statement_list extension_statement
373 EXTENSION any_identifier COLON any_identifier EOL
375 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
381 external_declaration_list:
384 /* FINISHME: The NULL test is required because pragmas are set to
385 * FINISHME: NULL. (See production rule for external_declaration.)
388 state->translation_unit.push_tail(& $1->link);
390 | external_declaration_list external_declaration
392 /* FINISHME: The NULL test is required because pragmas are set to
393 * FINISHME: NULL. (See production rule for external_declaration.)
396 state->translation_unit.push_tail(& $2->link);
398 | external_declaration_list extension_statement {
399 if (!state->allow_extension_directive_midshader) {
400 _mesa_glsl_error(& @2, state,
401 "#extension directive is not allowed "
402 "in the middle of a shader");
417 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
418 $$->set_location(@1);
419 $$->primary_expression.identifier = $1;
424 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
425 $$->set_location(@1);
426 $$->primary_expression.int_constant = $1;
431 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
432 $$->set_location(@1);
433 $$->primary_expression.uint_constant = $1;
438 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
439 $$->set_location(@1);
440 $$->primary_expression.float_constant = $1;
445 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
446 $$->set_location(@1);
447 $$->primary_expression.double_constant = $1;
452 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
453 $$->set_location(@1);
454 $$->primary_expression.bool_constant = $1;
464 | postfix_expression '[' integer_expression ']'
467 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
468 $$->set_location_range(@1, @4);
474 | postfix_expression '.' any_identifier
477 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
478 $$->set_location_range(@1, @3);
479 $$->primary_expression.identifier = $3;
481 | postfix_expression INC_OP
484 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
485 $$->set_location_range(@1, @2);
487 | postfix_expression DEC_OP
490 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
491 $$->set_location_range(@1, @2);
500 function_call_or_method
503 function_call_or_method:
504 function_call_generic
505 | postfix_expression '.' method_call_generic
508 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
509 $$->set_location_range(@1, @3);
513 function_call_generic:
514 function_call_header_with_parameters ')'
515 | function_call_header_no_parameters ')'
518 function_call_header_no_parameters:
519 function_call_header VOID_TOK
520 | function_call_header
523 function_call_header_with_parameters:
524 function_call_header assignment_expression
527 $$->set_location(@1);
528 $$->expressions.push_tail(& $2->link);
530 | function_call_header_with_parameters ',' assignment_expression
533 $$->set_location(@1);
534 $$->expressions.push_tail(& $3->link);
538 // Grammar Note: Constructors look like functions, but lexical
539 // analysis recognized most of them as keywords. They are now
540 // recognized through "type_specifier".
541 function_call_header:
542 function_identifier '('
549 $$ = new(ctx) ast_function_expression($1);
550 $$->set_location(@1);
552 | variable_identifier
555 ast_expression *callee = new(ctx) ast_expression($1);
556 callee->set_location(@1);
557 $$ = new(ctx) ast_function_expression(callee);
558 $$->set_location(@1);
563 ast_expression *callee = new(ctx) ast_expression($1);
564 callee->set_location(@1);
565 $$ = new(ctx) ast_function_expression(callee);
566 $$->set_location(@1);
571 method_call_header_with_parameters ')'
572 | method_call_header_no_parameters ')'
575 method_call_header_no_parameters:
576 method_call_header VOID_TOK
580 method_call_header_with_parameters:
581 method_call_header assignment_expression
584 $$->set_location(@1);
585 $$->expressions.push_tail(& $2->link);
587 | method_call_header_with_parameters ',' assignment_expression
590 $$->set_location(@1);
591 $$->expressions.push_tail(& $3->link);
595 // Grammar Note: Constructors look like methods, but lexical
596 // analysis recognized most of them as keywords. They are now
597 // recognized through "type_specifier".
599 variable_identifier '('
602 ast_expression *callee = new(ctx) ast_expression($1);
603 callee->set_location(@1);
604 $$ = new(ctx) ast_function_expression(callee);
605 $$->set_location(@1);
609 // Grammar Note: No traditional style type casts.
612 | INC_OP unary_expression
615 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
616 $$->set_location(@1);
618 | DEC_OP unary_expression
621 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
622 $$->set_location(@1);
624 | unary_operator unary_expression
627 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
628 $$->set_location_range(@1, @2);
632 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
634 '+' { $$ = ast_plus; }
635 | '-' { $$ = ast_neg; }
636 | '!' { $$ = ast_logic_not; }
637 | '~' { $$ = ast_bit_not; }
640 multiplicative_expression:
642 | multiplicative_expression '*' unary_expression
645 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
646 $$->set_location_range(@1, @3);
648 | multiplicative_expression '/' unary_expression
651 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
652 $$->set_location_range(@1, @3);
654 | multiplicative_expression '%' unary_expression
657 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
658 $$->set_location_range(@1, @3);
663 multiplicative_expression
664 | additive_expression '+' multiplicative_expression
667 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
668 $$->set_location_range(@1, @3);
670 | additive_expression '-' multiplicative_expression
673 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
674 $$->set_location_range(@1, @3);
680 | shift_expression LEFT_OP additive_expression
683 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
684 $$->set_location_range(@1, @3);
686 | shift_expression RIGHT_OP additive_expression
689 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
690 $$->set_location_range(@1, @3);
694 relational_expression:
696 | relational_expression '<' shift_expression
699 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
700 $$->set_location_range(@1, @3);
702 | relational_expression '>' shift_expression
705 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
706 $$->set_location_range(@1, @3);
708 | relational_expression LE_OP shift_expression
711 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
712 $$->set_location_range(@1, @3);
714 | relational_expression GE_OP shift_expression
717 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
718 $$->set_location_range(@1, @3);
723 relational_expression
724 | equality_expression EQ_OP relational_expression
727 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
728 $$->set_location_range(@1, @3);
730 | equality_expression NE_OP relational_expression
733 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
734 $$->set_location_range(@1, @3);
740 | and_expression '&' equality_expression
743 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
744 $$->set_location_range(@1, @3);
748 exclusive_or_expression:
750 | exclusive_or_expression '^' and_expression
753 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
754 $$->set_location_range(@1, @3);
758 inclusive_or_expression:
759 exclusive_or_expression
760 | inclusive_or_expression '|' exclusive_or_expression
763 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
764 $$->set_location_range(@1, @3);
768 logical_and_expression:
769 inclusive_or_expression
770 | logical_and_expression AND_OP inclusive_or_expression
773 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
774 $$->set_location_range(@1, @3);
778 logical_xor_expression:
779 logical_and_expression
780 | logical_xor_expression XOR_OP logical_and_expression
783 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
784 $$->set_location_range(@1, @3);
788 logical_or_expression:
789 logical_xor_expression
790 | logical_or_expression OR_OP logical_xor_expression
793 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
794 $$->set_location_range(@1, @3);
798 conditional_expression:
799 logical_or_expression
800 | logical_or_expression '?' expression ':' assignment_expression
803 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
804 $$->set_location_range(@1, @5);
808 assignment_expression:
809 conditional_expression
810 | unary_expression assignment_operator assignment_expression
813 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
814 $$->set_location_range(@1, @3);
819 '=' { $$ = ast_assign; }
820 | MUL_ASSIGN { $$ = ast_mul_assign; }
821 | DIV_ASSIGN { $$ = ast_div_assign; }
822 | MOD_ASSIGN { $$ = ast_mod_assign; }
823 | ADD_ASSIGN { $$ = ast_add_assign; }
824 | SUB_ASSIGN { $$ = ast_sub_assign; }
825 | LEFT_ASSIGN { $$ = ast_ls_assign; }
826 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
827 | AND_ASSIGN { $$ = ast_and_assign; }
828 | XOR_ASSIGN { $$ = ast_xor_assign; }
829 | OR_ASSIGN { $$ = ast_or_assign; }
833 assignment_expression
837 | expression ',' assignment_expression
840 if ($1->oper != ast_sequence) {
841 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
842 $$->set_location_range(@1, @3);
843 $$->expressions.push_tail(& $1->link);
848 $$->expressions.push_tail(& $3->link);
853 conditional_expression
857 function_prototype ';'
859 state->symbols->pop_scope();
862 | init_declarator_list ';'
866 | PRECISION precision_qualifier type_specifier ';'
868 $3->default_precision = $2;
878 function_declarator ')'
883 | function_header_with_parameters
886 function_header_with_parameters:
887 function_header parameter_declaration
890 $$->parameters.push_tail(& $2->link);
892 | function_header_with_parameters ',' parameter_declaration
895 $$->parameters.push_tail(& $3->link);
900 fully_specified_type variable_identifier '('
903 $$ = new(ctx) ast_function();
904 $$->set_location(@2);
905 $$->return_type = $1;
908 state->symbols->add_function(new(state) ir_function($2));
909 state->symbols->push_scope();
913 parameter_declarator:
914 type_specifier any_identifier
917 $$ = new(ctx) ast_parameter_declarator();
918 $$->set_location_range(@1, @2);
919 $$->type = new(ctx) ast_fully_specified_type();
920 $$->type->set_location(@1);
921 $$->type->specifier = $1;
924 | type_specifier any_identifier array_specifier
927 $$ = new(ctx) ast_parameter_declarator();
928 $$->set_location_range(@1, @3);
929 $$->type = new(ctx) ast_fully_specified_type();
930 $$->type->set_location(@1);
931 $$->type->specifier = $1;
933 $$->array_specifier = $3;
937 parameter_declaration:
938 parameter_qualifier parameter_declarator
941 $$->type->qualifier = $1;
943 | parameter_qualifier parameter_type_specifier
946 $$ = new(ctx) ast_parameter_declarator();
947 $$->set_location(@2);
948 $$->type = new(ctx) ast_fully_specified_type();
949 $$->type->set_location_range(@1, @2);
950 $$->type->qualifier = $1;
951 $$->type->specifier = $2;
958 memset(& $$, 0, sizeof($$));
960 | CONST_TOK parameter_qualifier
962 if ($2.flags.q.constant)
963 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
966 $$.flags.q.constant = 1;
968 | PRECISE parameter_qualifier
970 if ($2.flags.q.precise)
971 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
974 $$.flags.q.precise = 1;
976 | parameter_direction_qualifier parameter_qualifier
978 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
979 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
981 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
982 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
986 $$.merge_qualifier(&@1, state, $2);
988 | precision_qualifier parameter_qualifier
990 if ($2.precision != ast_precision_none)
991 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
993 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
994 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1000 parameter_direction_qualifier:
1003 memset(& $$, 0, sizeof($$));
1008 memset(& $$, 0, sizeof($$));
1013 memset(& $$, 0, sizeof($$));
1019 parameter_type_specifier:
1023 init_declarator_list:
1025 | init_declarator_list ',' any_identifier
1028 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1029 decl->set_location(@3);
1032 $$->declarations.push_tail(&decl->link);
1033 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1035 | init_declarator_list ',' any_identifier array_specifier
1038 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1039 decl->set_location_range(@3, @4);
1042 $$->declarations.push_tail(&decl->link);
1043 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1045 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1048 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1049 decl->set_location_range(@3, @4);
1052 $$->declarations.push_tail(&decl->link);
1053 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1055 | init_declarator_list ',' any_identifier '=' initializer
1058 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1059 decl->set_location(@3);
1062 $$->declarations.push_tail(&decl->link);
1063 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1067 // Grammar Note: No 'enum', or 'typedef'.
1069 fully_specified_type
1072 /* Empty declaration list is valid. */
1073 $$ = new(ctx) ast_declarator_list($1);
1074 $$->set_location(@1);
1076 | fully_specified_type any_identifier
1079 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1080 decl->set_location(@2);
1082 $$ = new(ctx) ast_declarator_list($1);
1083 $$->set_location_range(@1, @2);
1084 $$->declarations.push_tail(&decl->link);
1086 | fully_specified_type any_identifier array_specifier
1089 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1090 decl->set_location_range(@2, @3);
1092 $$ = new(ctx) ast_declarator_list($1);
1093 $$->set_location_range(@1, @3);
1094 $$->declarations.push_tail(&decl->link);
1096 | fully_specified_type any_identifier array_specifier '=' initializer
1099 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1100 decl->set_location_range(@2, @3);
1102 $$ = new(ctx) ast_declarator_list($1);
1103 $$->set_location_range(@1, @3);
1104 $$->declarations.push_tail(&decl->link);
1106 | fully_specified_type any_identifier '=' initializer
1109 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1110 decl->set_location(@2);
1112 $$ = new(ctx) ast_declarator_list($1);
1113 $$->set_location_range(@1, @2);
1114 $$->declarations.push_tail(&decl->link);
1116 | INVARIANT variable_identifier
1119 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1120 decl->set_location(@2);
1122 $$ = new(ctx) ast_declarator_list(NULL);
1123 $$->set_location_range(@1, @2);
1124 $$->invariant = true;
1126 $$->declarations.push_tail(&decl->link);
1128 | PRECISE variable_identifier
1131 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1132 decl->set_location(@2);
1134 $$ = new(ctx) ast_declarator_list(NULL);
1135 $$->set_location_range(@1, @2);
1138 $$->declarations.push_tail(&decl->link);
1142 fully_specified_type:
1146 $$ = new(ctx) ast_fully_specified_type();
1147 $$->set_location(@1);
1150 | type_qualifier type_specifier
1153 $$ = new(ctx) ast_fully_specified_type();
1154 $$->set_location_range(@1, @2);
1161 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1167 layout_qualifier_id_list:
1169 | layout_qualifier_id_list ',' layout_qualifier_id
1172 if (!$$.merge_qualifier(& @3, state, $3)) {
1179 INTCONSTANT { $$ = $1; }
1180 | UINTCONSTANT { $$ = $1; }
1183 layout_qualifier_id:
1186 memset(& $$, 0, sizeof($$));
1188 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1189 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1190 state->is_version(150, 0))) {
1191 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1192 $$.flags.q.origin_upper_left = 1;
1193 } else if (match_layout_qualifier($1, "pixel_center_integer",
1195 $$.flags.q.pixel_center_integer = 1;
1198 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1199 _mesa_glsl_warning(& @1, state,
1200 "GL_ARB_fragment_coord_conventions layout "
1201 "identifier `%s' used", $1);
1205 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1207 (state->AMD_conservative_depth_enable ||
1208 state->ARB_conservative_depth_enable)) {
1209 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1210 $$.flags.q.depth_any = 1;
1211 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1212 $$.flags.q.depth_greater = 1;
1213 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1214 $$.flags.q.depth_less = 1;
1215 } else if (match_layout_qualifier($1, "depth_unchanged",
1217 $$.flags.q.depth_unchanged = 1;
1220 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1221 _mesa_glsl_warning(& @1, state,
1222 "GL_AMD_conservative_depth "
1223 "layout qualifier `%s' is used", $1);
1225 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1226 _mesa_glsl_warning(& @1, state,
1227 "GL_ARB_conservative_depth "
1228 "layout qualifier `%s' is used", $1);
1232 /* See also interface_block_layout_qualifier. */
1233 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1234 if (match_layout_qualifier($1, "std140", state) == 0) {
1235 $$.flags.q.std140 = 1;
1236 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1237 $$.flags.q.shared = 1;
1238 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1239 $$.flags.q.column_major = 1;
1240 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1241 * below in the interface_block_layout_qualifier rule.
1243 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1246 * Also, this takes care of alternate capitalizations of
1247 * "row_major" (which is necessary because layout qualifiers
1248 * are case-insensitive in desktop GLSL).
1250 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1251 $$.flags.q.row_major = 1;
1252 /* "packed" is a reserved word in GLSL, and its token is
1253 * parsed below in the interface_block_layout_qualifier rule.
1254 * However, we must take care of alternate capitalizations of
1255 * "packed", because layout qualifiers are case-insensitive
1258 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1259 $$.flags.q.packed = 1;
1262 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1263 _mesa_glsl_warning(& @1, state,
1264 "#version 140 / GL_ARB_uniform_buffer_object "
1265 "layout qualifier `%s' is used", $1);
1269 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1271 static const struct {
1275 { "points", GL_POINTS },
1276 { "lines", GL_LINES },
1277 { "lines_adjacency", GL_LINES_ADJACENCY },
1278 { "line_strip", GL_LINE_STRIP },
1279 { "triangles", GL_TRIANGLES },
1280 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1281 { "triangle_strip", GL_TRIANGLE_STRIP },
1283 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1284 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1285 $$.flags.q.prim_type = 1;
1286 $$.prim_type = map[i].e;
1291 if ($$.flags.i && !state->is_version(150, 0)) {
1292 _mesa_glsl_error(& @1, state, "#version 150 layout "
1293 "qualifier `%s' used", $1);
1297 /* Layout qualifiers for ARB_shader_image_load_store. */
1298 if (state->ARB_shader_image_load_store_enable ||
1299 state->is_version(420, 0)) {
1301 static const struct {
1304 glsl_base_type base_type;
1306 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT },
1307 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT },
1308 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT },
1309 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT },
1310 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT },
1311 { "r32f", GL_R32F, GLSL_TYPE_FLOAT },
1312 { "r16f", GL_R16F, GLSL_TYPE_FLOAT },
1313 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT },
1314 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT },
1315 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT },
1316 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT },
1317 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT },
1318 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT },
1319 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT },
1320 { "r32ui", GL_R32UI, GLSL_TYPE_UINT },
1321 { "r16ui", GL_R16UI, GLSL_TYPE_UINT },
1322 { "r8ui", GL_R8UI, GLSL_TYPE_UINT },
1323 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT },
1324 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT },
1325 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT },
1326 { "rg32i", GL_RG32I, GLSL_TYPE_INT },
1327 { "rg16i", GL_RG16I, GLSL_TYPE_INT },
1328 { "rg8i", GL_RG8I, GLSL_TYPE_INT },
1329 { "r32i", GL_R32I, GLSL_TYPE_INT },
1330 { "r16i", GL_R16I, GLSL_TYPE_INT },
1331 { "r8i", GL_R8I, GLSL_TYPE_INT },
1332 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT },
1333 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT },
1334 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT },
1335 { "rg16", GL_RG16, GLSL_TYPE_FLOAT },
1336 { "rg8", GL_RG8, GLSL_TYPE_FLOAT },
1337 { "r16", GL_R16, GLSL_TYPE_FLOAT },
1338 { "r8", GL_R8, GLSL_TYPE_FLOAT },
1339 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT },
1340 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT },
1341 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT },
1342 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT },
1343 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT },
1344 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT }
1347 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1348 if (match_layout_qualifier($1, map[i].name, state) == 0) {
1349 $$.flags.q.explicit_image_format = 1;
1350 $$.image_format = map[i].format;
1351 $$.image_base_type = map[i].base_type;
1358 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1359 $$.flags.q.early_fragment_tests = 1;
1364 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1369 | any_identifier '=' integer_constant
1371 memset(& $$, 0, sizeof($$));
1373 if (match_layout_qualifier("location", $1, state) == 0) {
1374 $$.flags.q.explicit_location = 1;
1376 if ($$.flags.q.attribute == 1 &&
1377 state->ARB_explicit_attrib_location_warn) {
1378 _mesa_glsl_warning(& @1, state,
1379 "GL_ARB_explicit_attrib_location layout "
1380 "identifier `%s' used", $1);
1386 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1391 if (match_layout_qualifier("index", $1, state) == 0) {
1392 $$.flags.q.explicit_index = 1;
1397 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1402 if ((state->ARB_shading_language_420pack_enable ||
1403 state->ARB_shader_atomic_counters_enable) &&
1404 match_layout_qualifier("binding", $1, state) == 0) {
1405 $$.flags.q.explicit_binding = 1;
1409 if (state->ARB_shader_atomic_counters_enable &&
1410 match_layout_qualifier("offset", $1, state) == 0) {
1411 $$.flags.q.explicit_offset = 1;
1415 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1416 $$.flags.q.max_vertices = 1;
1419 _mesa_glsl_error(& @3, state,
1420 "invalid max_vertices %d specified", $3);
1423 $$.max_vertices = $3;
1424 if (!state->is_version(150, 0)) {
1425 _mesa_glsl_error(& @3, state,
1426 "#version 150 max_vertices qualifier "
1432 if (state->stage == MESA_SHADER_GEOMETRY) {
1433 if (match_layout_qualifier("stream", $1, state) == 0 &&
1434 state->check_explicit_attrib_stream_allowed(& @3)) {
1435 $$.flags.q.stream = 1;
1438 _mesa_glsl_error(& @3, state,
1439 "invalid stream %d specified", $3);
1442 $$.flags.q.explicit_stream = 1;
1448 static const char * const local_size_qualifiers[3] = {
1453 for (int i = 0; i < 3; i++) {
1454 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1457 _mesa_glsl_error(& @3, state,
1458 "invalid %s of %d specified",
1459 local_size_qualifiers[i], $3);
1461 } else if (!state->is_version(430, 0) &&
1462 !state->ARB_compute_shader_enable) {
1463 _mesa_glsl_error(& @3, state,
1464 "%s qualifier requires GLSL 4.30 or "
1465 "ARB_compute_shader",
1466 local_size_qualifiers[i]);
1469 $$.flags.q.local_size |= (1 << i);
1470 $$.local_size[i] = $3;
1476 if (match_layout_qualifier("invocations", $1, state) == 0) {
1477 $$.flags.q.invocations = 1;
1480 _mesa_glsl_error(& @3, state,
1481 "invalid invocations %d specified", $3);
1483 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1484 _mesa_glsl_error(& @3, state,
1485 "invocations (%d) exceeds "
1486 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1489 $$.invocations = $3;
1490 if (!state->is_version(400, 0) &&
1491 !state->ARB_gpu_shader5_enable) {
1492 _mesa_glsl_error(& @3, state,
1493 "GL_ARB_gpu_shader5 invocations "
1494 "qualifier specified", $3);
1499 /* If the identifier didn't match any known layout identifiers,
1503 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1508 | interface_block_layout_qualifier
1511 /* Layout qualifiers for ARB_uniform_buffer_object. */
1512 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1513 _mesa_glsl_error(& @1, state,
1514 "#version 140 / GL_ARB_uniform_buffer_object "
1515 "layout qualifier `%s' is used", $1);
1516 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1517 _mesa_glsl_warning(& @1, state,
1518 "#version 140 / GL_ARB_uniform_buffer_object "
1519 "layout qualifier `%s' is used", $1);
1524 /* This is a separate language rule because we parse these as tokens
1525 * (due to them being reserved keywords) instead of identifiers like
1526 * most qualifiers. See the any_identifier path of
1527 * layout_qualifier_id for the others.
1529 * Note that since layout qualifiers are case-insensitive in desktop
1530 * GLSL, all of these qualifiers need to be handled as identifiers as
1531 * well (by the any_identifier path of layout_qualifier_id).
1533 interface_block_layout_qualifier:
1536 memset(& $$, 0, sizeof($$));
1537 $$.flags.q.row_major = 1;
1541 memset(& $$, 0, sizeof($$));
1542 $$.flags.q.packed = 1;
1546 interpolation_qualifier:
1549 memset(& $$, 0, sizeof($$));
1550 $$.flags.q.smooth = 1;
1554 memset(& $$, 0, sizeof($$));
1555 $$.flags.q.flat = 1;
1559 memset(& $$, 0, sizeof($$));
1560 $$.flags.q.noperspective = 1;
1565 /* Single qualifiers */
1568 memset(& $$, 0, sizeof($$));
1569 $$.flags.q.invariant = 1;
1573 memset(& $$, 0, sizeof($$));
1574 $$.flags.q.precise = 1;
1576 | auxiliary_storage_qualifier
1578 | interpolation_qualifier
1580 | precision_qualifier
1582 memset(&$$, 0, sizeof($$));
1586 /* Multiple qualifiers:
1587 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1588 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1590 * invariant interpolation auxiliary storage precision ...or...
1591 * layout storage precision
1593 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1594 * side don't contain any that must appear on the left hand side.
1595 * For example, when processing a storage qualifier, we check that there are
1596 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1598 | PRECISE type_qualifier
1600 if ($2.flags.q.precise)
1601 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1604 $$.flags.q.precise = 1;
1606 | INVARIANT type_qualifier
1608 if ($2.flags.q.invariant)
1609 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1611 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.precise)
1612 _mesa_glsl_error(&@1, state,
1613 "\"invariant\" must come after \"precise\"");
1616 $$.flags.q.invariant = 1;
1618 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1620 * "Only variables output from a shader can be candidates for invariance.
1621 * This includes user-defined output variables and the built-in output
1622 * variables. As only outputs can be declared as invariant, an invariant
1623 * output from one shader stage will still match an input of a subsequent
1624 * stage without the input being declared as invariant."
1626 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1627 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1629 | interpolation_qualifier type_qualifier
1631 /* Section 4.3 of the GLSL 1.40 specification states:
1632 * "...qualified with one of these interpolation qualifiers"
1634 * GLSL 1.30 claims to allow "one or more", but insists that:
1635 * "These interpolation qualifiers may only precede the qualifiers in,
1636 * centroid in, out, or centroid out in a declaration."
1638 * ...which means that e.g. smooth can't precede smooth, so there can be
1639 * only one after all, and the 1.40 text is a clarification, not a change.
1641 if ($2.has_interpolation())
1642 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1644 if (!state->ARB_shading_language_420pack_enable &&
1645 ($2.flags.q.precise || $2.flags.q.invariant)) {
1646 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1647 "after \"precise\" or \"invariant\"");
1651 $$.merge_qualifier(&@1, state, $2);
1653 | layout_qualifier type_qualifier
1655 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1656 * appear no later than auxiliary storage qualifiers. There is no
1657 * particularly clear spec language mandating this, but in all examples
1658 * the layout qualifier precedes the storage qualifier.
1660 * We allow combinations of layout with interpolation, invariant or
1661 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1662 * There is no clear spec guidance on this either.
1664 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1665 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1668 $$.merge_qualifier(&@1, state, $2);
1670 | auxiliary_storage_qualifier type_qualifier
1672 if ($2.has_auxiliary_storage()) {
1673 _mesa_glsl_error(&@1, state,
1674 "duplicate auxiliary storage qualifier (centroid or sample)");
1677 if (!state->ARB_shading_language_420pack_enable &&
1678 ($2.flags.q.precise || $2.flags.q.invariant ||
1679 $2.has_interpolation() || $2.has_layout())) {
1680 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1681 "just before storage qualifiers");
1684 $$.merge_qualifier(&@1, state, $2);
1686 | storage_qualifier type_qualifier
1688 /* Section 4.3 of the GLSL 1.20 specification states:
1689 * "Variable declarations may have a storage qualifier specified..."
1690 * 1.30 clarifies this to "may have one storage qualifier".
1692 if ($2.has_storage())
1693 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1695 if (!state->ARB_shading_language_420pack_enable &&
1696 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1697 $2.has_layout() || $2.has_auxiliary_storage())) {
1698 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1699 "precise, invariant, interpolation, layout and auxiliary "
1700 "storage qualifiers");
1704 $$.merge_qualifier(&@1, state, $2);
1706 | precision_qualifier type_qualifier
1708 if ($2.precision != ast_precision_none)
1709 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1711 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1712 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1719 auxiliary_storage_qualifier:
1722 memset(& $$, 0, sizeof($$));
1723 $$.flags.q.centroid = 1;
1727 memset(& $$, 0, sizeof($$));
1728 $$.flags.q.sample = 1;
1730 /* TODO: "patch" also goes here someday. */
1735 memset(& $$, 0, sizeof($$));
1736 $$.flags.q.constant = 1;
1740 memset(& $$, 0, sizeof($$));
1741 $$.flags.q.attribute = 1;
1745 memset(& $$, 0, sizeof($$));
1746 $$.flags.q.varying = 1;
1750 memset(& $$, 0, sizeof($$));
1755 memset(& $$, 0, sizeof($$));
1758 if (state->stage == MESA_SHADER_GEOMETRY &&
1759 state->has_explicit_attrib_stream()) {
1760 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1763 * "If the block or variable is declared with the stream
1764 * identifier, it is associated with the specified stream;
1765 * otherwise, it is associated with the current default stream."
1767 $$.flags.q.stream = 1;
1768 $$.flags.q.explicit_stream = 0;
1769 $$.stream = state->out_qualifier->stream;
1774 memset(& $$, 0, sizeof($$));
1775 $$.flags.q.uniform = 1;
1779 memset(& $$, 0, sizeof($$));
1780 $$.flags.q.coherent = 1;
1784 memset(& $$, 0, sizeof($$));
1785 $$.flags.q._volatile = 1;
1789 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1790 memset(& $$, 0, sizeof($$));
1791 $$.flags.q.restrict_flag = 1;
1795 memset(& $$, 0, sizeof($$));
1796 $$.flags.q.read_only = 1;
1800 memset(& $$, 0, sizeof($$));
1801 $$.flags.q.write_only = 1;
1809 $$ = new(ctx) ast_array_specifier(@1);
1810 $$->set_location_range(@1, @2);
1812 | '[' constant_expression ']'
1815 $$ = new(ctx) ast_array_specifier(@1, $2);
1816 $$->set_location_range(@1, @3);
1818 | array_specifier '[' ']'
1822 if (!state->ARB_arrays_of_arrays_enable) {
1823 _mesa_glsl_error(& @1, state,
1824 "GL_ARB_arrays_of_arrays "
1825 "required for defining arrays of arrays");
1827 _mesa_glsl_error(& @1, state,
1828 "only the outermost array dimension can "
1832 | array_specifier '[' constant_expression ']'
1836 if (!state->ARB_arrays_of_arrays_enable) {
1837 _mesa_glsl_error(& @1, state,
1838 "GL_ARB_arrays_of_arrays "
1839 "required for defining arrays of arrays");
1842 $$->add_dimension($3);
1847 type_specifier_nonarray
1848 | type_specifier_nonarray array_specifier
1851 $$->array_specifier = $2;
1855 type_specifier_nonarray:
1856 basic_type_specifier_nonarray
1859 $$ = new(ctx) ast_type_specifier($1);
1860 $$->set_location(@1);
1865 $$ = new(ctx) ast_type_specifier($1);
1866 $$->set_location(@1);
1871 $$ = new(ctx) ast_type_specifier($1);
1872 $$->set_location(@1);
1876 basic_type_specifier_nonarray:
1877 VOID_TOK { $$ = "void"; }
1878 | FLOAT_TOK { $$ = "float"; }
1879 | DOUBLE_TOK { $$ = "double"; }
1880 | INT_TOK { $$ = "int"; }
1881 | UINT_TOK { $$ = "uint"; }
1882 | BOOL_TOK { $$ = "bool"; }
1883 | VEC2 { $$ = "vec2"; }
1884 | VEC3 { $$ = "vec3"; }
1885 | VEC4 { $$ = "vec4"; }
1886 | BVEC2 { $$ = "bvec2"; }
1887 | BVEC3 { $$ = "bvec3"; }
1888 | BVEC4 { $$ = "bvec4"; }
1889 | IVEC2 { $$ = "ivec2"; }
1890 | IVEC3 { $$ = "ivec3"; }
1891 | IVEC4 { $$ = "ivec4"; }
1892 | UVEC2 { $$ = "uvec2"; }
1893 | UVEC3 { $$ = "uvec3"; }
1894 | UVEC4 { $$ = "uvec4"; }
1895 | DVEC2 { $$ = "dvec2"; }
1896 | DVEC3 { $$ = "dvec3"; }
1897 | DVEC4 { $$ = "dvec4"; }
1898 | MAT2X2 { $$ = "mat2"; }
1899 | MAT2X3 { $$ = "mat2x3"; }
1900 | MAT2X4 { $$ = "mat2x4"; }
1901 | MAT3X2 { $$ = "mat3x2"; }
1902 | MAT3X3 { $$ = "mat3"; }
1903 | MAT3X4 { $$ = "mat3x4"; }
1904 | MAT4X2 { $$ = "mat4x2"; }
1905 | MAT4X3 { $$ = "mat4x3"; }
1906 | MAT4X4 { $$ = "mat4"; }
1907 | DMAT2X2 { $$ = "dmat2"; }
1908 | DMAT2X3 { $$ = "dmat2x3"; }
1909 | DMAT2X4 { $$ = "dmat2x4"; }
1910 | DMAT3X2 { $$ = "dmat3x2"; }
1911 | DMAT3X3 { $$ = "dmat3"; }
1912 | DMAT3X4 { $$ = "dmat3x4"; }
1913 | DMAT4X2 { $$ = "dmat4x2"; }
1914 | DMAT4X3 { $$ = "dmat4x3"; }
1915 | DMAT4X4 { $$ = "dmat4"; }
1916 | SAMPLER1D { $$ = "sampler1D"; }
1917 | SAMPLER2D { $$ = "sampler2D"; }
1918 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1919 | SAMPLER3D { $$ = "sampler3D"; }
1920 | SAMPLERCUBE { $$ = "samplerCube"; }
1921 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1922 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1923 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1924 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1925 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1926 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1927 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1928 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1929 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1930 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1931 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1932 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1933 | ISAMPLER1D { $$ = "isampler1D"; }
1934 | ISAMPLER2D { $$ = "isampler2D"; }
1935 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1936 | ISAMPLER3D { $$ = "isampler3D"; }
1937 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1938 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1939 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1940 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1941 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1942 | USAMPLER1D { $$ = "usampler1D"; }
1943 | USAMPLER2D { $$ = "usampler2D"; }
1944 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1945 | USAMPLER3D { $$ = "usampler3D"; }
1946 | USAMPLERCUBE { $$ = "usamplerCube"; }
1947 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1948 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1949 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1950 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1951 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1952 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1953 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1954 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1955 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1956 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1957 | IMAGE1D { $$ = "image1D"; }
1958 | IMAGE2D { $$ = "image2D"; }
1959 | IMAGE3D { $$ = "image3D"; }
1960 | IMAGE2DRECT { $$ = "image2DRect"; }
1961 | IMAGECUBE { $$ = "imageCube"; }
1962 | IMAGEBUFFER { $$ = "imageBuffer"; }
1963 | IMAGE1DARRAY { $$ = "image1DArray"; }
1964 | IMAGE2DARRAY { $$ = "image2DArray"; }
1965 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
1966 | IMAGE2DMS { $$ = "image2DMS"; }
1967 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
1968 | IIMAGE1D { $$ = "iimage1D"; }
1969 | IIMAGE2D { $$ = "iimage2D"; }
1970 | IIMAGE3D { $$ = "iimage3D"; }
1971 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
1972 | IIMAGECUBE { $$ = "iimageCube"; }
1973 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
1974 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
1975 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
1976 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
1977 | IIMAGE2DMS { $$ = "iimage2DMS"; }
1978 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
1979 | UIMAGE1D { $$ = "uimage1D"; }
1980 | UIMAGE2D { $$ = "uimage2D"; }
1981 | UIMAGE3D { $$ = "uimage3D"; }
1982 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
1983 | UIMAGECUBE { $$ = "uimageCube"; }
1984 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
1985 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
1986 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
1987 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
1988 | UIMAGE2DMS { $$ = "uimage2DMS"; }
1989 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
1990 | ATOMIC_UINT { $$ = "atomic_uint"; }
1993 precision_qualifier:
1996 state->check_precision_qualifiers_allowed(&@1);
1997 $$ = ast_precision_high;
2001 state->check_precision_qualifiers_allowed(&@1);
2002 $$ = ast_precision_medium;
2006 state->check_precision_qualifiers_allowed(&@1);
2007 $$ = ast_precision_low;
2012 STRUCT any_identifier '{' struct_declaration_list '}'
2015 $$ = new(ctx) ast_struct_specifier($2, $4);
2016 $$->set_location_range(@2, @5);
2017 state->symbols->add_type($2, glsl_type::void_type);
2019 | STRUCT '{' struct_declaration_list '}'
2022 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2023 $$->set_location_range(@2, @4);
2027 struct_declaration_list:
2031 $1->link.self_link();
2033 | struct_declaration_list struct_declaration
2036 $$->link.insert_before(& $2->link);
2041 fully_specified_type struct_declarator_list ';'
2044 ast_fully_specified_type *const type = $1;
2045 type->set_location(@1);
2047 if (type->qualifier.flags.i != 0)
2048 _mesa_glsl_error(&@1, state,
2049 "only precision qualifiers may be applied to "
2050 "structure members");
2052 $$ = new(ctx) ast_declarator_list(type);
2053 $$->set_location(@2);
2055 $$->declarations.push_degenerate_list_at_head(& $2->link);
2059 struct_declarator_list:
2063 $1->link.self_link();
2065 | struct_declarator_list ',' struct_declarator
2068 $$->link.insert_before(& $3->link);
2076 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2077 $$->set_location(@1);
2079 | any_identifier array_specifier
2082 $$ = new(ctx) ast_declaration($1, $2, NULL);
2083 $$->set_location_range(@1, @2);
2088 assignment_expression
2089 | '{' initializer_list '}'
2093 | '{' initializer_list ',' '}'
2103 $$ = new(ctx) ast_aggregate_initializer();
2104 $$->set_location(@1);
2105 $$->expressions.push_tail(& $1->link);
2107 | initializer_list ',' initializer
2109 $1->expressions.push_tail(& $3->link);
2113 declaration_statement:
2117 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2120 compound_statement { $$ = (ast_node *) $1; }
2125 declaration_statement
2126 | expression_statement
2127 | selection_statement
2129 | iteration_statement
2137 $$ = new(ctx) ast_compound_statement(true, NULL);
2138 $$->set_location_range(@1, @2);
2142 state->symbols->push_scope();
2147 $$ = new(ctx) ast_compound_statement(true, $3);
2148 $$->set_location_range(@1, @4);
2149 state->symbols->pop_scope();
2153 statement_no_new_scope:
2154 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2158 compound_statement_no_new_scope:
2162 $$ = new(ctx) ast_compound_statement(false, NULL);
2163 $$->set_location_range(@1, @2);
2165 | '{' statement_list '}'
2168 $$ = new(ctx) ast_compound_statement(false, $2);
2169 $$->set_location_range(@1, @3);
2177 _mesa_glsl_error(& @1, state, "<nil> statement");
2182 $$->link.self_link();
2184 | statement_list statement
2187 _mesa_glsl_error(& @2, state, "<nil> statement");
2191 $$->link.insert_before(& $2->link);
2195 expression_statement:
2199 $$ = new(ctx) ast_expression_statement(NULL);
2200 $$->set_location(@1);
2205 $$ = new(ctx) ast_expression_statement($1);
2206 $$->set_location(@1);
2210 selection_statement:
2211 IF '(' expression ')' selection_rest_statement
2213 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2215 $$->set_location_range(@1, @5);
2219 selection_rest_statement:
2220 statement ELSE statement
2222 $$.then_statement = $1;
2223 $$.else_statement = $3;
2225 | statement %prec THEN
2227 $$.then_statement = $1;
2228 $$.else_statement = NULL;
2235 $$ = (ast_node *) $1;
2237 | fully_specified_type any_identifier '=' initializer
2240 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2241 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2242 decl->set_location_range(@2, @4);
2243 declarator->set_location(@1);
2245 declarator->declarations.push_tail(&decl->link);
2251 * switch_statement grammar is based on the syntax described in the body
2252 * of the GLSL spec, not in it's appendix!!!
2255 SWITCH '(' expression ')' switch_body
2257 $$ = new(state) ast_switch_statement($3, $5);
2258 $$->set_location_range(@1, @5);
2265 $$ = new(state) ast_switch_body(NULL);
2266 $$->set_location_range(@1, @2);
2268 | '{' case_statement_list '}'
2270 $$ = new(state) ast_switch_body($2);
2271 $$->set_location_range(@1, @3);
2278 $$ = new(state) ast_case_label($2);
2279 $$->set_location(@2);
2283 $$ = new(state) ast_case_label(NULL);
2284 $$->set_location(@2);
2291 ast_case_label_list *labels = new(state) ast_case_label_list();
2293 labels->labels.push_tail(& $1->link);
2295 $$->set_location(@1);
2297 | case_label_list case_label
2300 $$->labels.push_tail(& $2->link);
2305 case_label_list statement
2307 ast_case_statement *stmts = new(state) ast_case_statement($1);
2308 stmts->set_location(@2);
2310 stmts->stmts.push_tail(& $2->link);
2313 | case_statement statement
2316 $$->stmts.push_tail(& $2->link);
2320 case_statement_list:
2323 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2324 cases->set_location(@1);
2326 cases->cases.push_tail(& $1->link);
2329 | case_statement_list case_statement
2332 $$->cases.push_tail(& $2->link);
2336 iteration_statement:
2337 WHILE '(' condition ')' statement_no_new_scope
2340 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2341 NULL, $3, NULL, $5);
2342 $$->set_location_range(@1, @4);
2344 | DO statement WHILE '(' expression ')' ';'
2347 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2348 NULL, $5, NULL, $2);
2349 $$->set_location_range(@1, @6);
2351 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2354 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2355 $3, $4.cond, $4.rest, $6);
2356 $$->set_location_range(@1, @6);
2361 expression_statement
2362 | declaration_statement
2379 | conditionopt ';' expression
2386 // Grammar Note: No 'goto'. Gotos are not supported.
2391 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2392 $$->set_location(@1);
2397 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2398 $$->set_location(@1);
2403 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2404 $$->set_location(@1);
2406 | RETURN expression ';'
2409 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2410 $$->set_location_range(@1, @2);
2412 | DISCARD ';' // Fragment shader only.
2415 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2416 $$->set_location(@1);
2420 external_declaration:
2421 function_definition { $$ = $1; }
2422 | declaration { $$ = $1; }
2423 | pragma_statement { $$ = NULL; }
2424 | layout_defaults { $$ = $1; }
2427 function_definition:
2428 function_prototype compound_statement_no_new_scope
2431 $$ = new(ctx) ast_function_definition();
2432 $$->set_location_range(@1, @2);
2436 state->symbols->pop_scope();
2440 /* layout_qualifieropt is packed into this rule */
2442 basic_interface_block
2446 | layout_qualifier basic_interface_block
2448 ast_interface_block *block = $2;
2449 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2453 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2454 ast_type_qualifier& qualifier = member->type->qualifier;
2455 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2456 _mesa_glsl_error(& @1, state,
2457 "stream layout qualifier on "
2458 "interface block member does not match "
2459 "the interface block (%d vs %d)",
2460 qualifier.stream, block->layout.stream);
2468 basic_interface_block:
2469 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2471 ast_interface_block *const block = $6;
2473 block->block_name = $2;
2474 block->declarations.push_degenerate_list_at_head(& $4->link);
2476 if ($1.flags.q.uniform) {
2477 if (!state->has_uniform_buffer_objects()) {
2478 _mesa_glsl_error(& @1, state,
2479 "#version 140 / GL_ARB_uniform_buffer_object "
2480 "required for defining uniform blocks");
2481 } else if (state->ARB_uniform_buffer_object_warn) {
2482 _mesa_glsl_warning(& @1, state,
2483 "#version 140 / GL_ARB_uniform_buffer_object "
2484 "required for defining uniform blocks");
2487 if (state->es_shader || state->language_version < 150) {
2488 _mesa_glsl_error(& @1, state,
2489 "#version 150 required for using "
2490 "interface blocks");
2494 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2495 * "It is illegal to have an input block in a vertex shader
2496 * or an output block in a fragment shader"
2498 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2499 _mesa_glsl_error(& @1, state,
2500 "`in' interface block is not allowed for "
2502 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2503 _mesa_glsl_error(& @1, state,
2504 "`out' interface block is not allowed for "
2505 "a fragment shader");
2508 /* Since block arrays require names, and both features are added in
2509 * the same language versions, we don't have to explicitly
2510 * version-check both things.
2512 if (block->instance_name != NULL) {
2513 state->check_version(150, 300, & @1, "interface blocks with "
2514 "an instance name are not allowed");
2517 uint64_t interface_type_mask;
2518 struct ast_type_qualifier temp_type_qualifier;
2520 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2521 * to ignore other irrelevant flags like interpolation qualifiers.
2523 temp_type_qualifier.flags.i = 0;
2524 temp_type_qualifier.flags.q.uniform = true;
2525 temp_type_qualifier.flags.q.in = true;
2526 temp_type_qualifier.flags.q.out = true;
2527 interface_type_mask = temp_type_qualifier.flags.i;
2529 /* Get the block's interface qualifier. The interface_qualifier
2530 * production rule guarantees that only one bit will be set (and
2531 * it will be in/out/uniform).
2533 uint64_t block_interface_qualifier = $1.flags.i;
2535 block->layout.flags.i |= block_interface_qualifier;
2537 if (state->stage == MESA_SHADER_GEOMETRY &&
2538 state->has_explicit_attrib_stream()) {
2539 /* Assign global layout's stream value. */
2540 block->layout.flags.q.stream = 1;
2541 block->layout.flags.q.explicit_stream = 0;
2542 block->layout.stream = state->out_qualifier->stream;
2545 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2546 ast_type_qualifier& qualifier = member->type->qualifier;
2547 if ((qualifier.flags.i & interface_type_mask) == 0) {
2548 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2549 * "If no optional qualifier is used in a member declaration, the
2550 * qualifier of the variable is just in, out, or uniform as declared
2551 * by interface-qualifier."
2553 qualifier.flags.i |= block_interface_qualifier;
2554 } else if ((qualifier.flags.i & interface_type_mask) !=
2555 block_interface_qualifier) {
2556 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2557 * "If optional qualifiers are used, they can include interpolation
2558 * and storage qualifiers and they must declare an input, output,
2559 * or uniform variable consistent with the interface qualifier of
2562 _mesa_glsl_error(& @1, state,
2563 "uniform/in/out qualifier on "
2564 "interface block member does not match "
2565 "the interface block");
2568 /* From GLSL ES 3.0, chapter 4.3.7 "Interface Blocks":
2570 * "GLSL ES 3.0 does not support interface blocks for shader inputs or
2573 * And from GLSL ES 3.0, chapter 4.6.1 "The invariant qualifier":.
2575 * "Only variables output from a shader can be candidates for
2578 * From GLSL 4.40 and GLSL 1.50, section "Interface Blocks":
2580 * "If optional qualifiers are used, they can include interpolation
2581 * qualifiers, auxiliary storage qualifiers, and storage qualifiers
2582 * and they must declare an input, output, or uniform member
2583 * consistent with the interface qualifier of the block"
2585 if (qualifier.flags.q.invariant)
2586 _mesa_glsl_error(&@1, state,
2587 "invariant qualifiers cannot be used "
2588 "with interface blocks members");
2595 interface_qualifier:
2598 memset(& $$, 0, sizeof($$));
2603 memset(& $$, 0, sizeof($$));
2608 memset(& $$, 0, sizeof($$));
2609 $$.flags.q.uniform = 1;
2616 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2621 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2623 $$->set_location(@1);
2625 | NEW_IDENTIFIER array_specifier
2627 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2629 $$->set_location_range(@1, @2);
2637 $1->link.self_link();
2639 | member_declaration member_list
2642 $2->link.insert_before(& $$->link);
2647 fully_specified_type struct_declarator_list ';'
2650 ast_fully_specified_type *type = $1;
2651 type->set_location(@1);
2653 if (type->qualifier.flags.q.attribute) {
2654 _mesa_glsl_error(& @1, state,
2655 "keyword 'attribute' cannot be used with "
2656 "interface block member");
2657 } else if (type->qualifier.flags.q.varying) {
2658 _mesa_glsl_error(& @1, state,
2659 "keyword 'varying' cannot be used with "
2660 "interface block member");
2663 $$ = new(ctx) ast_declarator_list(type);
2664 $$->set_location(@2);
2666 $$->declarations.push_degenerate_list_at_head(& $2->link);
2671 layout_qualifier UNIFORM ';'
2673 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2679 | layout_qualifier IN_TOK ';'
2682 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2687 | layout_qualifier OUT_TOK ';'
2689 if (state->stage != MESA_SHADER_GEOMETRY) {
2690 _mesa_glsl_error(& @1, state,
2691 "out layout qualifiers only valid in "
2692 "geometry shaders");
2694 if ($1.flags.q.prim_type) {
2695 /* Make sure this is a valid output primitive type. */
2696 switch ($1.prim_type) {
2699 case GL_TRIANGLE_STRIP:
2702 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2707 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2710 /* Allow future assigments of global out's stream id value */
2711 state->out_qualifier->flags.q.explicit_stream = 0;