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}
97 const char *identifier;
99 struct ast_type_qualifier type_qualifier;
102 ast_type_specifier *type_specifier;
103 ast_array_specifier *array_specifier;
104 ast_fully_specified_type *fully_specified_type;
105 ast_function *function;
106 ast_parameter_declarator *parameter_declarator;
107 ast_function_definition *function_definition;
108 ast_compound_statement *compound_statement;
109 ast_expression *expression;
110 ast_declarator_list *declarator_list;
111 ast_struct_specifier *struct_specifier;
112 ast_declaration *declaration;
113 ast_switch_body *switch_body;
114 ast_case_label *case_label;
115 ast_case_label_list *case_label_list;
116 ast_case_statement *case_statement;
117 ast_case_statement_list *case_statement_list;
118 ast_interface_block *interface_block;
122 ast_expression *rest;
123 } for_rest_statement;
126 ast_node *then_statement;
127 ast_node *else_statement;
128 } selection_rest_statement;
131 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
132 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
133 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
134 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
135 %token NOPERSPECTIVE FLAT SMOOTH
136 %token MAT2X2 MAT2X3 MAT2X4
137 %token MAT3X2 MAT3X3 MAT3X4
138 %token MAT4X2 MAT4X3 MAT4X4
139 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
140 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
141 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
142 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
143 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
144 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
145 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
146 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
147 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
148 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
149 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
150 %token SAMPLEREXTERNALOES
151 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
152 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
153 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
154 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
155 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
156 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
157 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
158 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
160 %token STRUCT VOID_TOK WHILE
161 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
162 %type <identifier> any_identifier
163 %type <interface_block> instance_name_opt
164 %token <real> FLOATCONSTANT
165 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
166 %token <identifier> FIELD_SELECTION
167 %token LEFT_OP RIGHT_OP
168 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
169 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
170 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
172 %token INVARIANT PRECISE
173 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
175 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
176 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
177 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
178 %token PRAGMA_INVARIANT_ALL
181 /* Reserved words that are not actually used in the grammar.
183 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
184 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
185 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
186 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
188 %token SIZEOF CAST NAMESPACE USING
189 %token RESOURCE PATCH
194 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
196 %type <identifier> variable_identifier
197 %type <node> statement
198 %type <node> statement_list
199 %type <node> simple_statement
200 %type <n> precision_qualifier
201 %type <type_qualifier> type_qualifier
202 %type <type_qualifier> auxiliary_storage_qualifier
203 %type <type_qualifier> storage_qualifier
204 %type <type_qualifier> interpolation_qualifier
205 %type <type_qualifier> layout_qualifier
206 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
207 %type <type_qualifier> interface_block_layout_qualifier
208 %type <type_qualifier> interface_qualifier
209 %type <type_specifier> type_specifier
210 %type <type_specifier> type_specifier_nonarray
211 %type <array_specifier> array_specifier
212 %type <identifier> basic_type_specifier_nonarray
213 %type <fully_specified_type> fully_specified_type
214 %type <function> function_prototype
215 %type <function> function_header
216 %type <function> function_header_with_parameters
217 %type <function> function_declarator
218 %type <parameter_declarator> parameter_declarator
219 %type <parameter_declarator> parameter_declaration
220 %type <type_qualifier> parameter_qualifier
221 %type <type_qualifier> parameter_direction_qualifier
222 %type <type_specifier> parameter_type_specifier
223 %type <function_definition> function_definition
224 %type <compound_statement> compound_statement_no_new_scope
225 %type <compound_statement> compound_statement
226 %type <node> statement_no_new_scope
227 %type <node> expression_statement
228 %type <expression> expression
229 %type <expression> primary_expression
230 %type <expression> assignment_expression
231 %type <expression> conditional_expression
232 %type <expression> logical_or_expression
233 %type <expression> logical_xor_expression
234 %type <expression> logical_and_expression
235 %type <expression> inclusive_or_expression
236 %type <expression> exclusive_or_expression
237 %type <expression> and_expression
238 %type <expression> equality_expression
239 %type <expression> relational_expression
240 %type <expression> shift_expression
241 %type <expression> additive_expression
242 %type <expression> multiplicative_expression
243 %type <expression> unary_expression
244 %type <expression> constant_expression
245 %type <expression> integer_expression
246 %type <expression> postfix_expression
247 %type <expression> function_call_header_with_parameters
248 %type <expression> function_call_header_no_parameters
249 %type <expression> function_call_header
250 %type <expression> function_call_generic
251 %type <expression> function_call_or_method
252 %type <expression> function_call
253 %type <expression> method_call_generic
254 %type <expression> method_call_header_with_parameters
255 %type <expression> method_call_header_no_parameters
256 %type <expression> method_call_header
257 %type <n> assignment_operator
258 %type <n> unary_operator
259 %type <expression> function_identifier
260 %type <node> external_declaration
261 %type <declarator_list> init_declarator_list
262 %type <declarator_list> single_declaration
263 %type <expression> initializer
264 %type <expression> initializer_list
265 %type <node> declaration
266 %type <node> declaration_statement
267 %type <node> jump_statement
268 %type <node> interface_block
269 %type <interface_block> basic_interface_block
270 %type <struct_specifier> struct_specifier
271 %type <declarator_list> struct_declaration_list
272 %type <declarator_list> struct_declaration
273 %type <declaration> struct_declarator
274 %type <declaration> struct_declarator_list
275 %type <declarator_list> member_list
276 %type <declarator_list> member_declaration
277 %type <node> selection_statement
278 %type <selection_rest_statement> selection_rest_statement
279 %type <node> switch_statement
280 %type <switch_body> switch_body
281 %type <case_label_list> case_label_list
282 %type <case_label> case_label
283 %type <case_statement> case_statement
284 %type <case_statement_list> case_statement_list
285 %type <node> iteration_statement
286 %type <node> condition
287 %type <node> conditionopt
288 %type <node> for_init_statement
289 %type <for_rest_statement> for_rest_statement
290 %type <n> integer_constant
291 %type <node> layout_defaults
297 version_statement extension_statement_list
299 _mesa_glsl_initialize_types(state);
301 external_declaration_list
303 delete state->symbols;
304 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
305 _mesa_glsl_initialize_types(state);
310 /* blank - no #version specified: defaults are already set */
311 | VERSION_TOK INTCONSTANT EOL
313 state->process_version_directive(&@2, $2, NULL);
318 | VERSION_TOK INTCONSTANT any_identifier EOL
320 state->process_version_directive(&@2, $2, $3);
329 | PRAGMA_DEBUG_OFF EOL
330 | PRAGMA_OPTIMIZE_ON EOL
331 | PRAGMA_OPTIMIZE_OFF EOL
332 | PRAGMA_INVARIANT_ALL EOL
334 /* Pragma invariant(all) cannot be used in a fragment shader.
336 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
338 * "It is an error to use this pragma in a fragment shader."
340 if (state->is_version(120, 300) &&
341 state->stage == MESA_SHADER_FRAGMENT) {
342 _mesa_glsl_error(& @1, state,
343 "pragma `invariant(all)' cannot be used "
344 "in a fragment shader.");
345 } else if (!state->is_version(120, 100)) {
346 _mesa_glsl_warning(& @1, state,
347 "pragma `invariant(all)' not supported in %s "
348 "(GLSL ES 1.00 or GLSL 1.20 required)",
349 state->get_version_string());
351 state->all_invariant = true;
356 extension_statement_list:
358 | extension_statement_list extension_statement
368 EXTENSION any_identifier COLON any_identifier EOL
370 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
376 external_declaration_list:
379 /* FINISHME: The NULL test is required because pragmas are set to
380 * FINISHME: NULL. (See production rule for external_declaration.)
383 state->translation_unit.push_tail(& $1->link);
385 | external_declaration_list external_declaration
387 /* FINISHME: The NULL test is required because pragmas are set to
388 * FINISHME: NULL. (See production rule for external_declaration.)
391 state->translation_unit.push_tail(& $2->link);
393 | external_declaration_list extension_statement {
394 if (!state->allow_extension_directive_midshader) {
395 _mesa_glsl_error(& @2, state,
396 "#extension directive is not allowed "
397 "in the middle of a shader");
412 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
413 $$->set_location(@1);
414 $$->primary_expression.identifier = $1;
419 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
420 $$->set_location(@1);
421 $$->primary_expression.int_constant = $1;
426 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
427 $$->set_location(@1);
428 $$->primary_expression.uint_constant = $1;
433 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
434 $$->set_location(@1);
435 $$->primary_expression.float_constant = $1;
440 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
441 $$->set_location(@1);
442 $$->primary_expression.bool_constant = $1;
452 | postfix_expression '[' integer_expression ']'
455 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
456 $$->set_location_range(@1, @4);
462 | postfix_expression '.' any_identifier
465 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
466 $$->set_location_range(@1, @3);
467 $$->primary_expression.identifier = $3;
469 | postfix_expression INC_OP
472 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
473 $$->set_location_range(@1, @2);
475 | postfix_expression DEC_OP
478 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
479 $$->set_location_range(@1, @2);
488 function_call_or_method
491 function_call_or_method:
492 function_call_generic
493 | postfix_expression '.' method_call_generic
496 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
497 $$->set_location_range(@1, @3);
501 function_call_generic:
502 function_call_header_with_parameters ')'
503 | function_call_header_no_parameters ')'
506 function_call_header_no_parameters:
507 function_call_header VOID_TOK
508 | function_call_header
511 function_call_header_with_parameters:
512 function_call_header assignment_expression
515 $$->set_location(@1);
516 $$->expressions.push_tail(& $2->link);
518 | function_call_header_with_parameters ',' assignment_expression
521 $$->set_location(@1);
522 $$->expressions.push_tail(& $3->link);
526 // Grammar Note: Constructors look like functions, but lexical
527 // analysis recognized most of them as keywords. They are now
528 // recognized through "type_specifier".
529 function_call_header:
530 function_identifier '('
537 $$ = new(ctx) ast_function_expression($1);
538 $$->set_location(@1);
540 | variable_identifier
543 ast_expression *callee = new(ctx) ast_expression($1);
544 callee->set_location(@1);
545 $$ = new(ctx) ast_function_expression(callee);
546 $$->set_location(@1);
551 ast_expression *callee = new(ctx) ast_expression($1);
552 callee->set_location(@1);
553 $$ = new(ctx) ast_function_expression(callee);
554 $$->set_location(@1);
559 method_call_header_with_parameters ')'
560 | method_call_header_no_parameters ')'
563 method_call_header_no_parameters:
564 method_call_header VOID_TOK
568 method_call_header_with_parameters:
569 method_call_header assignment_expression
572 $$->set_location(@1);
573 $$->expressions.push_tail(& $2->link);
575 | method_call_header_with_parameters ',' assignment_expression
578 $$->set_location(@1);
579 $$->expressions.push_tail(& $3->link);
583 // Grammar Note: Constructors look like methods, but lexical
584 // analysis recognized most of them as keywords. They are now
585 // recognized through "type_specifier".
587 variable_identifier '('
590 ast_expression *callee = new(ctx) ast_expression($1);
591 callee->set_location(@1);
592 $$ = new(ctx) ast_function_expression(callee);
593 $$->set_location(@1);
597 // Grammar Note: No traditional style type casts.
600 | INC_OP unary_expression
603 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
604 $$->set_location(@1);
606 | DEC_OP unary_expression
609 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
610 $$->set_location(@1);
612 | unary_operator unary_expression
615 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
616 $$->set_location_range(@1, @2);
620 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
622 '+' { $$ = ast_plus; }
623 | '-' { $$ = ast_neg; }
624 | '!' { $$ = ast_logic_not; }
625 | '~' { $$ = ast_bit_not; }
628 multiplicative_expression:
630 | multiplicative_expression '*' unary_expression
633 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
634 $$->set_location_range(@1, @3);
636 | multiplicative_expression '/' unary_expression
639 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
640 $$->set_location_range(@1, @3);
642 | multiplicative_expression '%' unary_expression
645 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
646 $$->set_location_range(@1, @3);
651 multiplicative_expression
652 | additive_expression '+' multiplicative_expression
655 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
656 $$->set_location_range(@1, @3);
658 | additive_expression '-' multiplicative_expression
661 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
662 $$->set_location_range(@1, @3);
668 | shift_expression LEFT_OP additive_expression
671 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
672 $$->set_location_range(@1, @3);
674 | shift_expression RIGHT_OP additive_expression
677 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
678 $$->set_location_range(@1, @3);
682 relational_expression:
684 | relational_expression '<' shift_expression
687 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
688 $$->set_location_range(@1, @3);
690 | relational_expression '>' shift_expression
693 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
694 $$->set_location_range(@1, @3);
696 | relational_expression LE_OP shift_expression
699 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
700 $$->set_location_range(@1, @3);
702 | relational_expression GE_OP shift_expression
705 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
706 $$->set_location_range(@1, @3);
711 relational_expression
712 | equality_expression EQ_OP relational_expression
715 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
716 $$->set_location_range(@1, @3);
718 | equality_expression NE_OP relational_expression
721 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
722 $$->set_location_range(@1, @3);
728 | and_expression '&' equality_expression
731 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
732 $$->set_location_range(@1, @3);
736 exclusive_or_expression:
738 | exclusive_or_expression '^' and_expression
741 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
742 $$->set_location_range(@1, @3);
746 inclusive_or_expression:
747 exclusive_or_expression
748 | inclusive_or_expression '|' exclusive_or_expression
751 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
752 $$->set_location_range(@1, @3);
756 logical_and_expression:
757 inclusive_or_expression
758 | logical_and_expression AND_OP inclusive_or_expression
761 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
762 $$->set_location_range(@1, @3);
766 logical_xor_expression:
767 logical_and_expression
768 | logical_xor_expression XOR_OP logical_and_expression
771 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
772 $$->set_location_range(@1, @3);
776 logical_or_expression:
777 logical_xor_expression
778 | logical_or_expression OR_OP logical_xor_expression
781 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
782 $$->set_location_range(@1, @3);
786 conditional_expression:
787 logical_or_expression
788 | logical_or_expression '?' expression ':' assignment_expression
791 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
792 $$->set_location_range(@1, @5);
796 assignment_expression:
797 conditional_expression
798 | unary_expression assignment_operator assignment_expression
801 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
802 $$->set_location_range(@1, @3);
807 '=' { $$ = ast_assign; }
808 | MUL_ASSIGN { $$ = ast_mul_assign; }
809 | DIV_ASSIGN { $$ = ast_div_assign; }
810 | MOD_ASSIGN { $$ = ast_mod_assign; }
811 | ADD_ASSIGN { $$ = ast_add_assign; }
812 | SUB_ASSIGN { $$ = ast_sub_assign; }
813 | LEFT_ASSIGN { $$ = ast_ls_assign; }
814 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
815 | AND_ASSIGN { $$ = ast_and_assign; }
816 | XOR_ASSIGN { $$ = ast_xor_assign; }
817 | OR_ASSIGN { $$ = ast_or_assign; }
821 assignment_expression
825 | expression ',' assignment_expression
828 if ($1->oper != ast_sequence) {
829 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
830 $$->set_location_range(@1, @3);
831 $$->expressions.push_tail(& $1->link);
836 $$->expressions.push_tail(& $3->link);
841 conditional_expression
845 function_prototype ';'
847 state->symbols->pop_scope();
850 | init_declarator_list ';'
854 | PRECISION precision_qualifier type_specifier ';'
856 $3->default_precision = $2;
866 function_declarator ')'
871 | function_header_with_parameters
874 function_header_with_parameters:
875 function_header parameter_declaration
878 $$->parameters.push_tail(& $2->link);
880 | function_header_with_parameters ',' parameter_declaration
883 $$->parameters.push_tail(& $3->link);
888 fully_specified_type variable_identifier '('
891 $$ = new(ctx) ast_function();
892 $$->set_location(@2);
893 $$->return_type = $1;
896 state->symbols->add_function(new(state) ir_function($2));
897 state->symbols->push_scope();
901 parameter_declarator:
902 type_specifier any_identifier
905 $$ = new(ctx) ast_parameter_declarator();
906 $$->set_location_range(@1, @2);
907 $$->type = new(ctx) ast_fully_specified_type();
908 $$->type->set_location(@1);
909 $$->type->specifier = $1;
912 | type_specifier any_identifier array_specifier
915 $$ = new(ctx) ast_parameter_declarator();
916 $$->set_location_range(@1, @3);
917 $$->type = new(ctx) ast_fully_specified_type();
918 $$->type->set_location(@1);
919 $$->type->specifier = $1;
921 $$->array_specifier = $3;
925 parameter_declaration:
926 parameter_qualifier parameter_declarator
929 $$->type->qualifier = $1;
931 | parameter_qualifier parameter_type_specifier
934 $$ = new(ctx) ast_parameter_declarator();
935 $$->set_location(@2);
936 $$->type = new(ctx) ast_fully_specified_type();
937 $$->type->set_location_range(@1, @2);
938 $$->type->qualifier = $1;
939 $$->type->specifier = $2;
946 memset(& $$, 0, sizeof($$));
948 | CONST_TOK parameter_qualifier
950 if ($2.flags.q.constant)
951 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
954 $$.flags.q.constant = 1;
956 | PRECISE parameter_qualifier
958 if ($2.flags.q.precise)
959 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
962 $$.flags.q.precise = 1;
964 | parameter_direction_qualifier parameter_qualifier
966 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
967 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
969 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
970 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
974 $$.merge_qualifier(&@1, state, $2);
976 | precision_qualifier parameter_qualifier
978 if ($2.precision != ast_precision_none)
979 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
981 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
982 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
988 parameter_direction_qualifier:
991 memset(& $$, 0, sizeof($$));
996 memset(& $$, 0, sizeof($$));
1001 memset(& $$, 0, sizeof($$));
1007 parameter_type_specifier:
1011 init_declarator_list:
1013 | init_declarator_list ',' any_identifier
1016 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1017 decl->set_location(@3);
1020 $$->declarations.push_tail(&decl->link);
1021 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1023 | init_declarator_list ',' any_identifier array_specifier
1026 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1027 decl->set_location_range(@3, @4);
1030 $$->declarations.push_tail(&decl->link);
1031 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1033 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1036 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1037 decl->set_location_range(@3, @4);
1040 $$->declarations.push_tail(&decl->link);
1041 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1043 | init_declarator_list ',' any_identifier '=' initializer
1046 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1047 decl->set_location(@3);
1050 $$->declarations.push_tail(&decl->link);
1051 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1055 // Grammar Note: No 'enum', or 'typedef'.
1057 fully_specified_type
1060 /* Empty declaration list is valid. */
1061 $$ = new(ctx) ast_declarator_list($1);
1062 $$->set_location(@1);
1064 | fully_specified_type any_identifier
1067 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1068 decl->set_location(@2);
1070 $$ = new(ctx) ast_declarator_list($1);
1071 $$->set_location_range(@1, @2);
1072 $$->declarations.push_tail(&decl->link);
1074 | fully_specified_type any_identifier array_specifier
1077 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1078 decl->set_location_range(@2, @3);
1080 $$ = new(ctx) ast_declarator_list($1);
1081 $$->set_location_range(@1, @3);
1082 $$->declarations.push_tail(&decl->link);
1084 | fully_specified_type any_identifier array_specifier '=' initializer
1087 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1088 decl->set_location_range(@2, @3);
1090 $$ = new(ctx) ast_declarator_list($1);
1091 $$->set_location_range(@1, @3);
1092 $$->declarations.push_tail(&decl->link);
1094 | fully_specified_type any_identifier '=' initializer
1097 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1098 decl->set_location(@2);
1100 $$ = new(ctx) ast_declarator_list($1);
1101 $$->set_location_range(@1, @2);
1102 $$->declarations.push_tail(&decl->link);
1104 | INVARIANT variable_identifier
1107 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1108 decl->set_location(@2);
1110 $$ = new(ctx) ast_declarator_list(NULL);
1111 $$->set_location_range(@1, @2);
1112 $$->invariant = true;
1114 $$->declarations.push_tail(&decl->link);
1116 | PRECISE 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);
1126 $$->declarations.push_tail(&decl->link);
1130 fully_specified_type:
1134 $$ = new(ctx) ast_fully_specified_type();
1135 $$->set_location(@1);
1138 | type_qualifier type_specifier
1141 $$ = new(ctx) ast_fully_specified_type();
1142 $$->set_location_range(@1, @2);
1149 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1155 layout_qualifier_id_list:
1157 | layout_qualifier_id_list ',' layout_qualifier_id
1160 if (!$$.merge_qualifier(& @3, state, $3)) {
1167 INTCONSTANT { $$ = $1; }
1168 | UINTCONSTANT { $$ = $1; }
1171 layout_qualifier_id:
1174 memset(& $$, 0, sizeof($$));
1176 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1177 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1178 state->is_version(150, 0))) {
1179 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1180 $$.flags.q.origin_upper_left = 1;
1181 } else if (match_layout_qualifier($1, "pixel_center_integer",
1183 $$.flags.q.pixel_center_integer = 1;
1186 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1187 _mesa_glsl_warning(& @1, state,
1188 "GL_ARB_fragment_coord_conventions layout "
1189 "identifier `%s' used", $1);
1193 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1195 (state->AMD_conservative_depth_enable ||
1196 state->ARB_conservative_depth_enable)) {
1197 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1198 $$.flags.q.depth_any = 1;
1199 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1200 $$.flags.q.depth_greater = 1;
1201 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1202 $$.flags.q.depth_less = 1;
1203 } else if (match_layout_qualifier($1, "depth_unchanged",
1205 $$.flags.q.depth_unchanged = 1;
1208 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1209 _mesa_glsl_warning(& @1, state,
1210 "GL_AMD_conservative_depth "
1211 "layout qualifier `%s' is used", $1);
1213 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1214 _mesa_glsl_warning(& @1, state,
1215 "GL_ARB_conservative_depth "
1216 "layout qualifier `%s' is used", $1);
1220 /* See also interface_block_layout_qualifier. */
1221 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1222 if (match_layout_qualifier($1, "std140", state) == 0) {
1223 $$.flags.q.std140 = 1;
1224 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1225 $$.flags.q.shared = 1;
1226 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1227 $$.flags.q.column_major = 1;
1228 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1229 * below in the interface_block_layout_qualifier rule.
1231 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1234 * Also, this takes care of alternate capitalizations of
1235 * "row_major" (which is necessary because layout qualifiers
1236 * are case-insensitive in desktop GLSL).
1238 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1239 $$.flags.q.row_major = 1;
1240 /* "packed" is a reserved word in GLSL, and its token is
1241 * parsed below in the interface_block_layout_qualifier rule.
1242 * However, we must take care of alternate capitalizations of
1243 * "packed", because layout qualifiers are case-insensitive
1246 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1247 $$.flags.q.packed = 1;
1250 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1251 _mesa_glsl_warning(& @1, state,
1252 "#version 140 / GL_ARB_uniform_buffer_object "
1253 "layout qualifier `%s' is used", $1);
1257 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1259 static const struct {
1263 { "points", GL_POINTS },
1264 { "lines", GL_LINES },
1265 { "lines_adjacency", GL_LINES_ADJACENCY },
1266 { "line_strip", GL_LINE_STRIP },
1267 { "triangles", GL_TRIANGLES },
1268 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1269 { "triangle_strip", GL_TRIANGLE_STRIP },
1271 for (unsigned i = 0; i < Elements(map); i++) {
1272 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1273 $$.flags.q.prim_type = 1;
1274 $$.prim_type = map[i].e;
1279 if ($$.flags.i && !state->is_version(150, 0)) {
1280 _mesa_glsl_error(& @1, state, "#version 150 layout "
1281 "qualifier `%s' used", $1);
1285 /* Layout qualifiers for ARB_shader_image_load_store. */
1286 if (state->ARB_shader_image_load_store_enable ||
1287 state->is_version(420, 0)) {
1289 static const struct {
1292 glsl_base_type base_type;
1294 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT },
1295 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT },
1296 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT },
1297 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT },
1298 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT },
1299 { "r32f", GL_R32F, GLSL_TYPE_FLOAT },
1300 { "r16f", GL_R16F, GLSL_TYPE_FLOAT },
1301 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT },
1302 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT },
1303 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT },
1304 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT },
1305 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT },
1306 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT },
1307 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT },
1308 { "r32ui", GL_R32UI, GLSL_TYPE_UINT },
1309 { "r16ui", GL_R16UI, GLSL_TYPE_UINT },
1310 { "r8ui", GL_R8UI, GLSL_TYPE_UINT },
1311 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT },
1312 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT },
1313 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT },
1314 { "rg32i", GL_RG32I, GLSL_TYPE_INT },
1315 { "rg16i", GL_RG16I, GLSL_TYPE_INT },
1316 { "rg8i", GL_RG8I, GLSL_TYPE_INT },
1317 { "r32i", GL_R32I, GLSL_TYPE_INT },
1318 { "r16i", GL_R16I, GLSL_TYPE_INT },
1319 { "r8i", GL_R8I, GLSL_TYPE_INT },
1320 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT },
1321 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT },
1322 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT },
1323 { "rg16", GL_RG16, GLSL_TYPE_FLOAT },
1324 { "rg8", GL_RG8, GLSL_TYPE_FLOAT },
1325 { "r16", GL_R16, GLSL_TYPE_FLOAT },
1326 { "r8", GL_R8, GLSL_TYPE_FLOAT },
1327 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT },
1328 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT },
1329 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT },
1330 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT },
1331 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT },
1332 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT }
1335 for (unsigned i = 0; i < Elements(map); i++) {
1336 if (match_layout_qualifier($1, map[i].name, state) == 0) {
1337 $$.flags.q.explicit_image_format = 1;
1338 $$.image_format = map[i].format;
1339 $$.image_base_type = map[i].base_type;
1346 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1347 $$.flags.q.early_fragment_tests = 1;
1352 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1357 | any_identifier '=' integer_constant
1359 memset(& $$, 0, sizeof($$));
1361 if (match_layout_qualifier("location", $1, state) == 0) {
1362 $$.flags.q.explicit_location = 1;
1364 if ($$.flags.q.attribute == 1 &&
1365 state->ARB_explicit_attrib_location_warn) {
1366 _mesa_glsl_warning(& @1, state,
1367 "GL_ARB_explicit_attrib_location layout "
1368 "identifier `%s' used", $1);
1374 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1379 if (match_layout_qualifier("index", $1, state) == 0) {
1380 $$.flags.q.explicit_index = 1;
1385 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1390 if ((state->ARB_shading_language_420pack_enable ||
1391 state->ARB_shader_atomic_counters_enable) &&
1392 match_layout_qualifier("binding", $1, state) == 0) {
1393 $$.flags.q.explicit_binding = 1;
1397 if (state->ARB_shader_atomic_counters_enable &&
1398 match_layout_qualifier("offset", $1, state) == 0) {
1399 $$.flags.q.explicit_offset = 1;
1403 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1404 $$.flags.q.max_vertices = 1;
1407 _mesa_glsl_error(& @3, state,
1408 "invalid max_vertices %d specified", $3);
1411 $$.max_vertices = $3;
1412 if (!state->is_version(150, 0)) {
1413 _mesa_glsl_error(& @3, state,
1414 "#version 150 max_vertices qualifier "
1420 if (state->stage == MESA_SHADER_GEOMETRY) {
1421 if (match_layout_qualifier("stream", $1, state) == 0 &&
1422 state->check_explicit_attrib_stream_allowed(& @3)) {
1423 $$.flags.q.stream = 1;
1426 _mesa_glsl_error(& @3, state,
1427 "invalid stream %d specified", $3);
1430 $$.flags.q.explicit_stream = 1;
1436 static const char * const local_size_qualifiers[3] = {
1441 for (int i = 0; i < 3; i++) {
1442 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1445 _mesa_glsl_error(& @3, state,
1446 "invalid %s of %d specified",
1447 local_size_qualifiers[i], $3);
1449 } else if (!state->is_version(430, 0) &&
1450 !state->ARB_compute_shader_enable) {
1451 _mesa_glsl_error(& @3, state,
1452 "%s qualifier requires GLSL 4.30 or "
1453 "ARB_compute_shader",
1454 local_size_qualifiers[i]);
1457 $$.flags.q.local_size |= (1 << i);
1458 $$.local_size[i] = $3;
1464 if (match_layout_qualifier("invocations", $1, state) == 0) {
1465 $$.flags.q.invocations = 1;
1468 _mesa_glsl_error(& @3, state,
1469 "invalid invocations %d specified", $3);
1471 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1472 _mesa_glsl_error(& @3, state,
1473 "invocations (%d) exceeds "
1474 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1477 $$.invocations = $3;
1478 if (!state->is_version(400, 0) &&
1479 !state->ARB_gpu_shader5_enable) {
1480 _mesa_glsl_error(& @3, state,
1481 "GL_ARB_gpu_shader5 invocations "
1482 "qualifier specified", $3);
1487 /* If the identifier didn't match any known layout identifiers,
1491 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1496 | interface_block_layout_qualifier
1499 /* Layout qualifiers for ARB_uniform_buffer_object. */
1500 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1501 _mesa_glsl_error(& @1, state,
1502 "#version 140 / GL_ARB_uniform_buffer_object "
1503 "layout qualifier `%s' is used", $1);
1504 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1505 _mesa_glsl_warning(& @1, state,
1506 "#version 140 / GL_ARB_uniform_buffer_object "
1507 "layout qualifier `%s' is used", $1);
1512 /* This is a separate language rule because we parse these as tokens
1513 * (due to them being reserved keywords) instead of identifiers like
1514 * most qualifiers. See the any_identifier path of
1515 * layout_qualifier_id for the others.
1517 * Note that since layout qualifiers are case-insensitive in desktop
1518 * GLSL, all of these qualifiers need to be handled as identifiers as
1519 * well (by the any_identifier path of layout_qualifier_id).
1521 interface_block_layout_qualifier:
1524 memset(& $$, 0, sizeof($$));
1525 $$.flags.q.row_major = 1;
1529 memset(& $$, 0, sizeof($$));
1530 $$.flags.q.packed = 1;
1534 interpolation_qualifier:
1537 memset(& $$, 0, sizeof($$));
1538 $$.flags.q.smooth = 1;
1542 memset(& $$, 0, sizeof($$));
1543 $$.flags.q.flat = 1;
1547 memset(& $$, 0, sizeof($$));
1548 $$.flags.q.noperspective = 1;
1553 /* Single qualifiers */
1556 memset(& $$, 0, sizeof($$));
1557 $$.flags.q.invariant = 1;
1561 memset(& $$, 0, sizeof($$));
1562 $$.flags.q.precise = 1;
1564 | auxiliary_storage_qualifier
1566 | interpolation_qualifier
1568 | precision_qualifier
1570 memset(&$$, 0, sizeof($$));
1574 /* Multiple qualifiers:
1575 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1576 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1578 * invariant interpolation auxiliary storage precision ...or...
1579 * layout storage precision
1581 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1582 * side don't contain any that must appear on the left hand side.
1583 * For example, when processing a storage qualifier, we check that there are
1584 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1586 | PRECISE type_qualifier
1588 if ($2.flags.q.precise)
1589 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1592 $$.flags.q.precise = 1;
1594 | INVARIANT type_qualifier
1596 if ($2.flags.q.invariant)
1597 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1599 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.precise)
1600 _mesa_glsl_error(&@1, state,
1601 "\"invariant\" must come after \"precise\"");
1604 $$.flags.q.invariant = 1;
1606 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1608 * "Only variables output from a shader can be candidates for invariance.
1609 * This includes user-defined output variables and the built-in output
1610 * variables. As only outputs can be declared as invariant, an invariant
1611 * output from one shader stage will still match an input of a subsequent
1612 * stage without the input being declared as invariant."
1614 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1615 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1617 | interpolation_qualifier type_qualifier
1619 /* Section 4.3 of the GLSL 1.40 specification states:
1620 * "...qualified with one of these interpolation qualifiers"
1622 * GLSL 1.30 claims to allow "one or more", but insists that:
1623 * "These interpolation qualifiers may only precede the qualifiers in,
1624 * centroid in, out, or centroid out in a declaration."
1626 * ...which means that e.g. smooth can't precede smooth, so there can be
1627 * only one after all, and the 1.40 text is a clarification, not a change.
1629 if ($2.has_interpolation())
1630 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1632 if (!state->ARB_shading_language_420pack_enable &&
1633 ($2.flags.q.precise || $2.flags.q.invariant)) {
1634 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1635 "after \"precise\" or \"invariant\"");
1639 $$.merge_qualifier(&@1, state, $2);
1641 | layout_qualifier type_qualifier
1643 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1644 * appear no later than auxiliary storage qualifiers. There is no
1645 * particularly clear spec language mandating this, but in all examples
1646 * the layout qualifier precedes the storage qualifier.
1648 * We allow combinations of layout with interpolation, invariant or
1649 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1650 * There is no clear spec guidance on this either.
1652 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1653 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1656 $$.merge_qualifier(&@1, state, $2);
1658 | auxiliary_storage_qualifier type_qualifier
1660 if ($2.has_auxiliary_storage()) {
1661 _mesa_glsl_error(&@1, state,
1662 "duplicate auxiliary storage qualifier (centroid or sample)");
1665 if (!state->ARB_shading_language_420pack_enable &&
1666 ($2.flags.q.precise || $2.flags.q.invariant ||
1667 $2.has_interpolation() || $2.has_layout())) {
1668 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1669 "just before storage qualifiers");
1672 $$.merge_qualifier(&@1, state, $2);
1674 | storage_qualifier type_qualifier
1676 /* Section 4.3 of the GLSL 1.20 specification states:
1677 * "Variable declarations may have a storage qualifier specified..."
1678 * 1.30 clarifies this to "may have one storage qualifier".
1680 if ($2.has_storage())
1681 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1683 if (!state->ARB_shading_language_420pack_enable &&
1684 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1685 $2.has_layout() || $2.has_auxiliary_storage())) {
1686 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1687 "precise, invariant, interpolation, layout and auxiliary "
1688 "storage qualifiers");
1692 $$.merge_qualifier(&@1, state, $2);
1694 | precision_qualifier type_qualifier
1696 if ($2.precision != ast_precision_none)
1697 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1699 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1700 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1707 auxiliary_storage_qualifier:
1710 memset(& $$, 0, sizeof($$));
1711 $$.flags.q.centroid = 1;
1715 memset(& $$, 0, sizeof($$));
1716 $$.flags.q.sample = 1;
1718 /* TODO: "patch" also goes here someday. */
1723 memset(& $$, 0, sizeof($$));
1724 $$.flags.q.constant = 1;
1728 memset(& $$, 0, sizeof($$));
1729 $$.flags.q.attribute = 1;
1733 memset(& $$, 0, sizeof($$));
1734 $$.flags.q.varying = 1;
1738 memset(& $$, 0, sizeof($$));
1743 memset(& $$, 0, sizeof($$));
1746 if (state->stage == MESA_SHADER_GEOMETRY &&
1747 state->has_explicit_attrib_stream()) {
1748 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1751 * "If the block or variable is declared with the stream
1752 * identifier, it is associated with the specified stream;
1753 * otherwise, it is associated with the current default stream."
1755 $$.flags.q.stream = 1;
1756 $$.flags.q.explicit_stream = 0;
1757 $$.stream = state->out_qualifier->stream;
1762 memset(& $$, 0, sizeof($$));
1763 $$.flags.q.uniform = 1;
1767 memset(& $$, 0, sizeof($$));
1768 $$.flags.q.coherent = 1;
1772 memset(& $$, 0, sizeof($$));
1773 $$.flags.q._volatile = 1;
1777 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1778 memset(& $$, 0, sizeof($$));
1779 $$.flags.q.restrict_flag = 1;
1783 memset(& $$, 0, sizeof($$));
1784 $$.flags.q.read_only = 1;
1788 memset(& $$, 0, sizeof($$));
1789 $$.flags.q.write_only = 1;
1797 $$ = new(ctx) ast_array_specifier(@1);
1798 $$->set_location_range(@1, @2);
1800 | '[' constant_expression ']'
1803 $$ = new(ctx) ast_array_specifier(@1, $2);
1804 $$->set_location_range(@1, @3);
1806 | array_specifier '[' ']'
1810 if (!state->ARB_arrays_of_arrays_enable) {
1811 _mesa_glsl_error(& @1, state,
1812 "GL_ARB_arrays_of_arrays "
1813 "required for defining arrays of arrays");
1815 _mesa_glsl_error(& @1, state,
1816 "only the outermost array dimension can "
1820 | array_specifier '[' constant_expression ']'
1824 if (!state->ARB_arrays_of_arrays_enable) {
1825 _mesa_glsl_error(& @1, state,
1826 "GL_ARB_arrays_of_arrays "
1827 "required for defining arrays of arrays");
1830 $$->add_dimension($3);
1835 type_specifier_nonarray
1836 | type_specifier_nonarray array_specifier
1839 $$->array_specifier = $2;
1843 type_specifier_nonarray:
1844 basic_type_specifier_nonarray
1847 $$ = new(ctx) ast_type_specifier($1);
1848 $$->set_location(@1);
1853 $$ = new(ctx) ast_type_specifier($1);
1854 $$->set_location(@1);
1859 $$ = new(ctx) ast_type_specifier($1);
1860 $$->set_location(@1);
1864 basic_type_specifier_nonarray:
1865 VOID_TOK { $$ = "void"; }
1866 | FLOAT_TOK { $$ = "float"; }
1867 | INT_TOK { $$ = "int"; }
1868 | UINT_TOK { $$ = "uint"; }
1869 | BOOL_TOK { $$ = "bool"; }
1870 | VEC2 { $$ = "vec2"; }
1871 | VEC3 { $$ = "vec3"; }
1872 | VEC4 { $$ = "vec4"; }
1873 | BVEC2 { $$ = "bvec2"; }
1874 | BVEC3 { $$ = "bvec3"; }
1875 | BVEC4 { $$ = "bvec4"; }
1876 | IVEC2 { $$ = "ivec2"; }
1877 | IVEC3 { $$ = "ivec3"; }
1878 | IVEC4 { $$ = "ivec4"; }
1879 | UVEC2 { $$ = "uvec2"; }
1880 | UVEC3 { $$ = "uvec3"; }
1881 | UVEC4 { $$ = "uvec4"; }
1882 | MAT2X2 { $$ = "mat2"; }
1883 | MAT2X3 { $$ = "mat2x3"; }
1884 | MAT2X4 { $$ = "mat2x4"; }
1885 | MAT3X2 { $$ = "mat3x2"; }
1886 | MAT3X3 { $$ = "mat3"; }
1887 | MAT3X4 { $$ = "mat3x4"; }
1888 | MAT4X2 { $$ = "mat4x2"; }
1889 | MAT4X3 { $$ = "mat4x3"; }
1890 | MAT4X4 { $$ = "mat4"; }
1891 | SAMPLER1D { $$ = "sampler1D"; }
1892 | SAMPLER2D { $$ = "sampler2D"; }
1893 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1894 | SAMPLER3D { $$ = "sampler3D"; }
1895 | SAMPLERCUBE { $$ = "samplerCube"; }
1896 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1897 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1898 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1899 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1900 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1901 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1902 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1903 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1904 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1905 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1906 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1907 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1908 | ISAMPLER1D { $$ = "isampler1D"; }
1909 | ISAMPLER2D { $$ = "isampler2D"; }
1910 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1911 | ISAMPLER3D { $$ = "isampler3D"; }
1912 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1913 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1914 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1915 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1916 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1917 | USAMPLER1D { $$ = "usampler1D"; }
1918 | USAMPLER2D { $$ = "usampler2D"; }
1919 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1920 | USAMPLER3D { $$ = "usampler3D"; }
1921 | USAMPLERCUBE { $$ = "usamplerCube"; }
1922 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1923 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1924 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1925 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1926 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1927 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1928 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1929 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1930 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1931 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1932 | IMAGE1D { $$ = "image1D"; }
1933 | IMAGE2D { $$ = "image2D"; }
1934 | IMAGE3D { $$ = "image3D"; }
1935 | IMAGE2DRECT { $$ = "image2DRect"; }
1936 | IMAGECUBE { $$ = "imageCube"; }
1937 | IMAGEBUFFER { $$ = "imageBuffer"; }
1938 | IMAGE1DARRAY { $$ = "image1DArray"; }
1939 | IMAGE2DARRAY { $$ = "image2DArray"; }
1940 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
1941 | IMAGE2DMS { $$ = "image2DMS"; }
1942 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
1943 | IIMAGE1D { $$ = "iimage1D"; }
1944 | IIMAGE2D { $$ = "iimage2D"; }
1945 | IIMAGE3D { $$ = "iimage3D"; }
1946 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
1947 | IIMAGECUBE { $$ = "iimageCube"; }
1948 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
1949 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
1950 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
1951 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
1952 | IIMAGE2DMS { $$ = "iimage2DMS"; }
1953 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
1954 | UIMAGE1D { $$ = "uimage1D"; }
1955 | UIMAGE2D { $$ = "uimage2D"; }
1956 | UIMAGE3D { $$ = "uimage3D"; }
1957 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
1958 | UIMAGECUBE { $$ = "uimageCube"; }
1959 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
1960 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
1961 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
1962 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
1963 | UIMAGE2DMS { $$ = "uimage2DMS"; }
1964 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
1965 | ATOMIC_UINT { $$ = "atomic_uint"; }
1968 precision_qualifier:
1971 state->check_precision_qualifiers_allowed(&@1);
1972 $$ = ast_precision_high;
1976 state->check_precision_qualifiers_allowed(&@1);
1977 $$ = ast_precision_medium;
1981 state->check_precision_qualifiers_allowed(&@1);
1982 $$ = ast_precision_low;
1987 STRUCT any_identifier '{' struct_declaration_list '}'
1990 $$ = new(ctx) ast_struct_specifier($2, $4);
1991 $$->set_location_range(@2, @5);
1992 state->symbols->add_type($2, glsl_type::void_type);
1994 | STRUCT '{' struct_declaration_list '}'
1997 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1998 $$->set_location_range(@2, @4);
2002 struct_declaration_list:
2006 $1->link.self_link();
2008 | struct_declaration_list struct_declaration
2011 $$->link.insert_before(& $2->link);
2016 fully_specified_type struct_declarator_list ';'
2019 ast_fully_specified_type *const type = $1;
2020 type->set_location(@1);
2022 if (type->qualifier.flags.i != 0)
2023 _mesa_glsl_error(&@1, state,
2024 "only precision qualifiers may be applied to "
2025 "structure members");
2027 $$ = new(ctx) ast_declarator_list(type);
2028 $$->set_location(@2);
2030 $$->declarations.push_degenerate_list_at_head(& $2->link);
2034 struct_declarator_list:
2038 $1->link.self_link();
2040 | struct_declarator_list ',' struct_declarator
2043 $$->link.insert_before(& $3->link);
2051 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2052 $$->set_location(@1);
2054 | any_identifier array_specifier
2057 $$ = new(ctx) ast_declaration($1, $2, NULL);
2058 $$->set_location_range(@1, @2);
2063 assignment_expression
2064 | '{' initializer_list '}'
2068 | '{' initializer_list ',' '}'
2078 $$ = new(ctx) ast_aggregate_initializer();
2079 $$->set_location(@1);
2080 $$->expressions.push_tail(& $1->link);
2082 | initializer_list ',' initializer
2084 $1->expressions.push_tail(& $3->link);
2088 declaration_statement:
2092 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2095 compound_statement { $$ = (ast_node *) $1; }
2100 declaration_statement
2101 | expression_statement
2102 | selection_statement
2104 | iteration_statement
2112 $$ = new(ctx) ast_compound_statement(true, NULL);
2113 $$->set_location_range(@1, @2);
2117 state->symbols->push_scope();
2122 $$ = new(ctx) ast_compound_statement(true, $3);
2123 $$->set_location_range(@1, @4);
2124 state->symbols->pop_scope();
2128 statement_no_new_scope:
2129 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2133 compound_statement_no_new_scope:
2137 $$ = new(ctx) ast_compound_statement(false, NULL);
2138 $$->set_location_range(@1, @2);
2140 | '{' statement_list '}'
2143 $$ = new(ctx) ast_compound_statement(false, $2);
2144 $$->set_location_range(@1, @3);
2152 _mesa_glsl_error(& @1, state, "<nil> statement");
2157 $$->link.self_link();
2159 | statement_list statement
2162 _mesa_glsl_error(& @2, state, "<nil> statement");
2166 $$->link.insert_before(& $2->link);
2170 expression_statement:
2174 $$ = new(ctx) ast_expression_statement(NULL);
2175 $$->set_location(@1);
2180 $$ = new(ctx) ast_expression_statement($1);
2181 $$->set_location(@1);
2185 selection_statement:
2186 IF '(' expression ')' selection_rest_statement
2188 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2190 $$->set_location_range(@1, @5);
2194 selection_rest_statement:
2195 statement ELSE statement
2197 $$.then_statement = $1;
2198 $$.else_statement = $3;
2200 | statement %prec THEN
2202 $$.then_statement = $1;
2203 $$.else_statement = NULL;
2210 $$ = (ast_node *) $1;
2212 | fully_specified_type any_identifier '=' initializer
2215 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2216 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2217 decl->set_location_range(@2, @4);
2218 declarator->set_location(@1);
2220 declarator->declarations.push_tail(&decl->link);
2226 * switch_statement grammar is based on the syntax described in the body
2227 * of the GLSL spec, not in it's appendix!!!
2230 SWITCH '(' expression ')' switch_body
2232 $$ = new(state) ast_switch_statement($3, $5);
2233 $$->set_location_range(@1, @5);
2240 $$ = new(state) ast_switch_body(NULL);
2241 $$->set_location_range(@1, @2);
2243 | '{' case_statement_list '}'
2245 $$ = new(state) ast_switch_body($2);
2246 $$->set_location_range(@1, @3);
2253 $$ = new(state) ast_case_label($2);
2254 $$->set_location(@2);
2258 $$ = new(state) ast_case_label(NULL);
2259 $$->set_location(@2);
2266 ast_case_label_list *labels = new(state) ast_case_label_list();
2268 labels->labels.push_tail(& $1->link);
2270 $$->set_location(@1);
2272 | case_label_list case_label
2275 $$->labels.push_tail(& $2->link);
2280 case_label_list statement
2282 ast_case_statement *stmts = new(state) ast_case_statement($1);
2283 stmts->set_location(@2);
2285 stmts->stmts.push_tail(& $2->link);
2288 | case_statement statement
2291 $$->stmts.push_tail(& $2->link);
2295 case_statement_list:
2298 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2299 cases->set_location(@1);
2301 cases->cases.push_tail(& $1->link);
2304 | case_statement_list case_statement
2307 $$->cases.push_tail(& $2->link);
2311 iteration_statement:
2312 WHILE '(' condition ')' statement_no_new_scope
2315 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2316 NULL, $3, NULL, $5);
2317 $$->set_location_range(@1, @4);
2319 | DO statement WHILE '(' expression ')' ';'
2322 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2323 NULL, $5, NULL, $2);
2324 $$->set_location_range(@1, @6);
2326 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2329 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2330 $3, $4.cond, $4.rest, $6);
2331 $$->set_location_range(@1, @6);
2336 expression_statement
2337 | declaration_statement
2354 | conditionopt ';' expression
2361 // Grammar Note: No 'goto'. Gotos are not supported.
2366 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2367 $$->set_location(@1);
2372 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2373 $$->set_location(@1);
2378 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2379 $$->set_location(@1);
2381 | RETURN expression ';'
2384 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2385 $$->set_location_range(@1, @2);
2387 | DISCARD ';' // Fragment shader only.
2390 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2391 $$->set_location(@1);
2395 external_declaration:
2396 function_definition { $$ = $1; }
2397 | declaration { $$ = $1; }
2398 | pragma_statement { $$ = NULL; }
2399 | layout_defaults { $$ = $1; }
2402 function_definition:
2403 function_prototype compound_statement_no_new_scope
2406 $$ = new(ctx) ast_function_definition();
2407 $$->set_location_range(@1, @2);
2411 state->symbols->pop_scope();
2415 /* layout_qualifieropt is packed into this rule */
2417 basic_interface_block
2421 | layout_qualifier basic_interface_block
2423 ast_interface_block *block = $2;
2424 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2428 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2429 ast_type_qualifier& qualifier = member->type->qualifier;
2430 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2431 _mesa_glsl_error(& @1, state,
2432 "stream layout qualifier on "
2433 "interface block member does not match "
2434 "the interface block (%d vs %d)",
2435 qualifier.stream, block->layout.stream);
2443 basic_interface_block:
2444 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2446 ast_interface_block *const block = $6;
2448 block->block_name = $2;
2449 block->declarations.push_degenerate_list_at_head(& $4->link);
2451 if ($1.flags.q.uniform) {
2452 if (!state->has_uniform_buffer_objects()) {
2453 _mesa_glsl_error(& @1, state,
2454 "#version 140 / GL_ARB_uniform_buffer_object "
2455 "required for defining uniform blocks");
2456 } else if (state->ARB_uniform_buffer_object_warn) {
2457 _mesa_glsl_warning(& @1, state,
2458 "#version 140 / GL_ARB_uniform_buffer_object "
2459 "required for defining uniform blocks");
2462 if (state->es_shader || state->language_version < 150) {
2463 _mesa_glsl_error(& @1, state,
2464 "#version 150 required for using "
2465 "interface blocks");
2469 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2470 * "It is illegal to have an input block in a vertex shader
2471 * or an output block in a fragment shader"
2473 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2474 _mesa_glsl_error(& @1, state,
2475 "`in' interface block is not allowed for "
2477 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2478 _mesa_glsl_error(& @1, state,
2479 "`out' interface block is not allowed for "
2480 "a fragment shader");
2483 /* Since block arrays require names, and both features are added in
2484 * the same language versions, we don't have to explicitly
2485 * version-check both things.
2487 if (block->instance_name != NULL) {
2488 state->check_version(150, 300, & @1, "interface blocks with "
2489 "an instance name are not allowed");
2492 uint64_t interface_type_mask;
2493 struct ast_type_qualifier temp_type_qualifier;
2495 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2496 * to ignore other irrelevant flags like interpolation qualifiers.
2498 temp_type_qualifier.flags.i = 0;
2499 temp_type_qualifier.flags.q.uniform = true;
2500 temp_type_qualifier.flags.q.in = true;
2501 temp_type_qualifier.flags.q.out = true;
2502 interface_type_mask = temp_type_qualifier.flags.i;
2504 /* Get the block's interface qualifier. The interface_qualifier
2505 * production rule guarantees that only one bit will be set (and
2506 * it will be in/out/uniform).
2508 uint64_t block_interface_qualifier = $1.flags.i;
2510 block->layout.flags.i |= block_interface_qualifier;
2512 if (state->stage == MESA_SHADER_GEOMETRY &&
2513 state->has_explicit_attrib_stream()) {
2514 /* Assign global layout's stream value. */
2515 block->layout.flags.q.stream = 1;
2516 block->layout.flags.q.explicit_stream = 0;
2517 block->layout.stream = state->out_qualifier->stream;
2520 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2521 ast_type_qualifier& qualifier = member->type->qualifier;
2522 if ((qualifier.flags.i & interface_type_mask) == 0) {
2523 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2524 * "If no optional qualifier is used in a member declaration, the
2525 * qualifier of the variable is just in, out, or uniform as declared
2526 * by interface-qualifier."
2528 qualifier.flags.i |= block_interface_qualifier;
2529 } else if ((qualifier.flags.i & interface_type_mask) !=
2530 block_interface_qualifier) {
2531 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2532 * "If optional qualifiers are used, they can include interpolation
2533 * and storage qualifiers and they must declare an input, output,
2534 * or uniform variable consistent with the interface qualifier of
2537 _mesa_glsl_error(& @1, state,
2538 "uniform/in/out qualifier on "
2539 "interface block member does not match "
2540 "the interface block");
2548 interface_qualifier:
2551 memset(& $$, 0, sizeof($$));
2556 memset(& $$, 0, sizeof($$));
2561 memset(& $$, 0, sizeof($$));
2562 $$.flags.q.uniform = 1;
2569 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2574 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2576 $$->set_location(@1);
2578 | NEW_IDENTIFIER array_specifier
2580 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2582 $$->set_location_range(@1, @2);
2590 $1->link.self_link();
2592 | member_declaration member_list
2595 $2->link.insert_before(& $$->link);
2600 fully_specified_type struct_declarator_list ';'
2603 ast_fully_specified_type *type = $1;
2604 type->set_location(@1);
2606 if (type->qualifier.flags.q.attribute) {
2607 _mesa_glsl_error(& @1, state,
2608 "keyword 'attribute' cannot be used with "
2609 "interface block member");
2610 } else if (type->qualifier.flags.q.varying) {
2611 _mesa_glsl_error(& @1, state,
2612 "keyword 'varying' cannot be used with "
2613 "interface block member");
2616 $$ = new(ctx) ast_declarator_list(type);
2617 $$->set_location(@2);
2619 $$->declarations.push_degenerate_list_at_head(& $2->link);
2624 layout_qualifier UNIFORM ';'
2626 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2632 | layout_qualifier IN_TOK ';'
2635 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2640 | layout_qualifier OUT_TOK ';'
2642 if (state->stage != MESA_SHADER_GEOMETRY) {
2643 _mesa_glsl_error(& @1, state,
2644 "out layout qualifiers only valid in "
2645 "geometry shaders");
2647 if ($1.flags.q.prim_type) {
2648 /* Make sure this is a valid output primitive type. */
2649 switch ($1.prim_type) {
2652 case GL_TRIANGLE_STRIP:
2655 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2660 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2663 /* Allow future assigments of global out's stream id value */
2664 state->out_qualifier->flags.q.explicit_stream = 0;