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 if (!state->is_version(120, 100)) {
335 _mesa_glsl_warning(& @1, state,
336 "pragma `invariant(all)' not supported in %s "
337 "(GLSL ES 1.00 or GLSL 1.20 required)",
338 state->get_version_string());
340 state->all_invariant = true;
345 extension_statement_list:
347 | extension_statement_list extension_statement
357 EXTENSION any_identifier COLON any_identifier EOL
359 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
365 external_declaration_list:
368 /* FINISHME: The NULL test is required because pragmas are set to
369 * FINISHME: NULL. (See production rule for external_declaration.)
372 state->translation_unit.push_tail(& $1->link);
374 | external_declaration_list external_declaration
376 /* FINISHME: The NULL test is required because pragmas are set to
377 * FINISHME: NULL. (See production rule for external_declaration.)
380 state->translation_unit.push_tail(& $2->link);
382 | external_declaration_list extension_statement {
383 if (!state->allow_extension_directive_midshader) {
384 _mesa_glsl_error(& @2, state,
385 "#extension directive is not allowed "
386 "in the middle of a shader");
401 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
402 $$->set_location(@1);
403 $$->primary_expression.identifier = $1;
408 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
409 $$->set_location(@1);
410 $$->primary_expression.int_constant = $1;
415 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
416 $$->set_location(@1);
417 $$->primary_expression.uint_constant = $1;
422 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
423 $$->set_location(@1);
424 $$->primary_expression.float_constant = $1;
429 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
430 $$->set_location(@1);
431 $$->primary_expression.bool_constant = $1;
441 | postfix_expression '[' integer_expression ']'
444 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
445 $$->set_location_range(@1, @4);
451 | postfix_expression '.' any_identifier
454 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
455 $$->set_location_range(@1, @3);
456 $$->primary_expression.identifier = $3;
458 | postfix_expression INC_OP
461 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
462 $$->set_location_range(@1, @2);
464 | postfix_expression DEC_OP
467 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
468 $$->set_location_range(@1, @2);
477 function_call_or_method
480 function_call_or_method:
481 function_call_generic
482 | postfix_expression '.' method_call_generic
485 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
486 $$->set_location_range(@1, @3);
490 function_call_generic:
491 function_call_header_with_parameters ')'
492 | function_call_header_no_parameters ')'
495 function_call_header_no_parameters:
496 function_call_header VOID_TOK
497 | function_call_header
500 function_call_header_with_parameters:
501 function_call_header assignment_expression
504 $$->set_location(@1);
505 $$->expressions.push_tail(& $2->link);
507 | function_call_header_with_parameters ',' assignment_expression
510 $$->set_location(@1);
511 $$->expressions.push_tail(& $3->link);
515 // Grammar Note: Constructors look like functions, but lexical
516 // analysis recognized most of them as keywords. They are now
517 // recognized through "type_specifier".
518 function_call_header:
519 function_identifier '('
526 $$ = new(ctx) ast_function_expression($1);
527 $$->set_location(@1);
529 | variable_identifier
532 ast_expression *callee = new(ctx) ast_expression($1);
533 callee->set_location(@1);
534 $$ = new(ctx) ast_function_expression(callee);
535 $$->set_location(@1);
540 ast_expression *callee = new(ctx) ast_expression($1);
541 callee->set_location(@1);
542 $$ = new(ctx) ast_function_expression(callee);
543 $$->set_location(@1);
548 method_call_header_with_parameters ')'
549 | method_call_header_no_parameters ')'
552 method_call_header_no_parameters:
553 method_call_header VOID_TOK
557 method_call_header_with_parameters:
558 method_call_header assignment_expression
561 $$->set_location(@1);
562 $$->expressions.push_tail(& $2->link);
564 | method_call_header_with_parameters ',' assignment_expression
567 $$->set_location(@1);
568 $$->expressions.push_tail(& $3->link);
572 // Grammar Note: Constructors look like methods, but lexical
573 // analysis recognized most of them as keywords. They are now
574 // recognized through "type_specifier".
576 variable_identifier '('
579 ast_expression *callee = new(ctx) ast_expression($1);
580 callee->set_location(@1);
581 $$ = new(ctx) ast_function_expression(callee);
582 $$->set_location(@1);
586 // Grammar Note: No traditional style type casts.
589 | INC_OP unary_expression
592 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
593 $$->set_location(@1);
595 | DEC_OP unary_expression
598 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
599 $$->set_location(@1);
601 | unary_operator unary_expression
604 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
605 $$->set_location_range(@1, @2);
609 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
611 '+' { $$ = ast_plus; }
612 | '-' { $$ = ast_neg; }
613 | '!' { $$ = ast_logic_not; }
614 | '~' { $$ = ast_bit_not; }
617 multiplicative_expression:
619 | multiplicative_expression '*' unary_expression
622 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
623 $$->set_location_range(@1, @3);
625 | multiplicative_expression '/' unary_expression
628 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
629 $$->set_location_range(@1, @3);
631 | multiplicative_expression '%' unary_expression
634 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
635 $$->set_location_range(@1, @3);
640 multiplicative_expression
641 | additive_expression '+' multiplicative_expression
644 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
645 $$->set_location_range(@1, @3);
647 | additive_expression '-' multiplicative_expression
650 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
651 $$->set_location_range(@1, @3);
657 | shift_expression LEFT_OP additive_expression
660 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
661 $$->set_location_range(@1, @3);
663 | shift_expression RIGHT_OP additive_expression
666 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
667 $$->set_location_range(@1, @3);
671 relational_expression:
673 | relational_expression '<' shift_expression
676 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
677 $$->set_location_range(@1, @3);
679 | relational_expression '>' shift_expression
682 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
683 $$->set_location_range(@1, @3);
685 | relational_expression LE_OP shift_expression
688 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
689 $$->set_location_range(@1, @3);
691 | relational_expression GE_OP shift_expression
694 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
695 $$->set_location_range(@1, @3);
700 relational_expression
701 | equality_expression EQ_OP relational_expression
704 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
705 $$->set_location_range(@1, @3);
707 | equality_expression NE_OP relational_expression
710 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
711 $$->set_location_range(@1, @3);
717 | and_expression '&' equality_expression
720 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
721 $$->set_location_range(@1, @3);
725 exclusive_or_expression:
727 | exclusive_or_expression '^' and_expression
730 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
731 $$->set_location_range(@1, @3);
735 inclusive_or_expression:
736 exclusive_or_expression
737 | inclusive_or_expression '|' exclusive_or_expression
740 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
741 $$->set_location_range(@1, @3);
745 logical_and_expression:
746 inclusive_or_expression
747 | logical_and_expression AND_OP inclusive_or_expression
750 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
751 $$->set_location_range(@1, @3);
755 logical_xor_expression:
756 logical_and_expression
757 | logical_xor_expression XOR_OP logical_and_expression
760 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
761 $$->set_location_range(@1, @3);
765 logical_or_expression:
766 logical_xor_expression
767 | logical_or_expression OR_OP logical_xor_expression
770 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
771 $$->set_location_range(@1, @3);
775 conditional_expression:
776 logical_or_expression
777 | logical_or_expression '?' expression ':' assignment_expression
780 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
781 $$->set_location_range(@1, @5);
785 assignment_expression:
786 conditional_expression
787 | unary_expression assignment_operator assignment_expression
790 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
791 $$->set_location_range(@1, @3);
796 '=' { $$ = ast_assign; }
797 | MUL_ASSIGN { $$ = ast_mul_assign; }
798 | DIV_ASSIGN { $$ = ast_div_assign; }
799 | MOD_ASSIGN { $$ = ast_mod_assign; }
800 | ADD_ASSIGN { $$ = ast_add_assign; }
801 | SUB_ASSIGN { $$ = ast_sub_assign; }
802 | LEFT_ASSIGN { $$ = ast_ls_assign; }
803 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
804 | AND_ASSIGN { $$ = ast_and_assign; }
805 | XOR_ASSIGN { $$ = ast_xor_assign; }
806 | OR_ASSIGN { $$ = ast_or_assign; }
810 assignment_expression
814 | expression ',' assignment_expression
817 if ($1->oper != ast_sequence) {
818 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
819 $$->set_location_range(@1, @3);
820 $$->expressions.push_tail(& $1->link);
825 $$->expressions.push_tail(& $3->link);
830 conditional_expression
834 function_prototype ';'
836 state->symbols->pop_scope();
839 | init_declarator_list ';'
843 | PRECISION precision_qualifier type_specifier ';'
845 $3->default_precision = $2;
855 function_declarator ')'
860 | function_header_with_parameters
863 function_header_with_parameters:
864 function_header parameter_declaration
867 $$->parameters.push_tail(& $2->link);
869 | function_header_with_parameters ',' parameter_declaration
872 $$->parameters.push_tail(& $3->link);
877 fully_specified_type variable_identifier '('
880 $$ = new(ctx) ast_function();
881 $$->set_location(@2);
882 $$->return_type = $1;
885 state->symbols->add_function(new(state) ir_function($2));
886 state->symbols->push_scope();
890 parameter_declarator:
891 type_specifier any_identifier
894 $$ = new(ctx) ast_parameter_declarator();
895 $$->set_location_range(@1, @2);
896 $$->type = new(ctx) ast_fully_specified_type();
897 $$->type->set_location(@1);
898 $$->type->specifier = $1;
901 | type_specifier any_identifier array_specifier
904 $$ = new(ctx) ast_parameter_declarator();
905 $$->set_location_range(@1, @3);
906 $$->type = new(ctx) ast_fully_specified_type();
907 $$->type->set_location(@1);
908 $$->type->specifier = $1;
910 $$->array_specifier = $3;
914 parameter_declaration:
915 parameter_qualifier parameter_declarator
918 $$->type->qualifier = $1;
920 | parameter_qualifier parameter_type_specifier
923 $$ = new(ctx) ast_parameter_declarator();
924 $$->set_location(@2);
925 $$->type = new(ctx) ast_fully_specified_type();
926 $$->type->set_location_range(@1, @2);
927 $$->type->qualifier = $1;
928 $$->type->specifier = $2;
935 memset(& $$, 0, sizeof($$));
937 | CONST_TOK parameter_qualifier
939 if ($2.flags.q.constant)
940 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
943 $$.flags.q.constant = 1;
945 | PRECISE parameter_qualifier
947 if ($2.flags.q.precise)
948 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
951 $$.flags.q.precise = 1;
953 | parameter_direction_qualifier parameter_qualifier
955 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
956 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
958 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
959 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
963 $$.merge_qualifier(&@1, state, $2);
965 | precision_qualifier parameter_qualifier
967 if ($2.precision != ast_precision_none)
968 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
970 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
971 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
977 parameter_direction_qualifier:
980 memset(& $$, 0, sizeof($$));
985 memset(& $$, 0, sizeof($$));
990 memset(& $$, 0, sizeof($$));
996 parameter_type_specifier:
1000 init_declarator_list:
1002 | init_declarator_list ',' any_identifier
1005 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1006 decl->set_location(@3);
1009 $$->declarations.push_tail(&decl->link);
1010 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1012 | init_declarator_list ',' any_identifier array_specifier
1015 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1016 decl->set_location_range(@3, @4);
1019 $$->declarations.push_tail(&decl->link);
1020 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1022 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1025 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1026 decl->set_location_range(@3, @4);
1029 $$->declarations.push_tail(&decl->link);
1030 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1032 | init_declarator_list ',' any_identifier '=' initializer
1035 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1036 decl->set_location(@3);
1039 $$->declarations.push_tail(&decl->link);
1040 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1044 // Grammar Note: No 'enum', or 'typedef'.
1046 fully_specified_type
1049 /* Empty declaration list is valid. */
1050 $$ = new(ctx) ast_declarator_list($1);
1051 $$->set_location(@1);
1053 | fully_specified_type any_identifier
1056 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1057 decl->set_location(@2);
1059 $$ = new(ctx) ast_declarator_list($1);
1060 $$->set_location_range(@1, @2);
1061 $$->declarations.push_tail(&decl->link);
1063 | fully_specified_type any_identifier array_specifier
1066 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1067 decl->set_location_range(@2, @3);
1069 $$ = new(ctx) ast_declarator_list($1);
1070 $$->set_location_range(@1, @3);
1071 $$->declarations.push_tail(&decl->link);
1073 | fully_specified_type any_identifier array_specifier '=' initializer
1076 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1077 decl->set_location_range(@2, @3);
1079 $$ = new(ctx) ast_declarator_list($1);
1080 $$->set_location_range(@1, @3);
1081 $$->declarations.push_tail(&decl->link);
1083 | fully_specified_type any_identifier '=' initializer
1086 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1087 decl->set_location(@2);
1089 $$ = new(ctx) ast_declarator_list($1);
1090 $$->set_location_range(@1, @2);
1091 $$->declarations.push_tail(&decl->link);
1093 | INVARIANT variable_identifier
1096 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1097 decl->set_location(@2);
1099 $$ = new(ctx) ast_declarator_list(NULL);
1100 $$->set_location_range(@1, @2);
1101 $$->invariant = true;
1103 $$->declarations.push_tail(&decl->link);
1105 | PRECISE variable_identifier
1108 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1109 decl->set_location(@2);
1111 $$ = new(ctx) ast_declarator_list(NULL);
1112 $$->set_location_range(@1, @2);
1115 $$->declarations.push_tail(&decl->link);
1119 fully_specified_type:
1123 $$ = new(ctx) ast_fully_specified_type();
1124 $$->set_location(@1);
1127 | type_qualifier type_specifier
1130 $$ = new(ctx) ast_fully_specified_type();
1131 $$->set_location_range(@1, @2);
1138 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1144 layout_qualifier_id_list:
1146 | layout_qualifier_id_list ',' layout_qualifier_id
1149 if (!$$.merge_qualifier(& @3, state, $3)) {
1156 INTCONSTANT { $$ = $1; }
1157 | UINTCONSTANT { $$ = $1; }
1160 layout_qualifier_id:
1163 memset(& $$, 0, sizeof($$));
1165 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1166 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1167 state->is_version(150, 0))) {
1168 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1169 $$.flags.q.origin_upper_left = 1;
1170 } else if (match_layout_qualifier($1, "pixel_center_integer",
1172 $$.flags.q.pixel_center_integer = 1;
1175 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1176 _mesa_glsl_warning(& @1, state,
1177 "GL_ARB_fragment_coord_conventions layout "
1178 "identifier `%s' used", $1);
1182 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1184 (state->AMD_conservative_depth_enable ||
1185 state->ARB_conservative_depth_enable)) {
1186 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1187 $$.flags.q.depth_any = 1;
1188 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1189 $$.flags.q.depth_greater = 1;
1190 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1191 $$.flags.q.depth_less = 1;
1192 } else if (match_layout_qualifier($1, "depth_unchanged",
1194 $$.flags.q.depth_unchanged = 1;
1197 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1198 _mesa_glsl_warning(& @1, state,
1199 "GL_AMD_conservative_depth "
1200 "layout qualifier `%s' is used", $1);
1202 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1203 _mesa_glsl_warning(& @1, state,
1204 "GL_ARB_conservative_depth "
1205 "layout qualifier `%s' is used", $1);
1209 /* See also interface_block_layout_qualifier. */
1210 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1211 if (match_layout_qualifier($1, "std140", state) == 0) {
1212 $$.flags.q.std140 = 1;
1213 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1214 $$.flags.q.shared = 1;
1215 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1216 $$.flags.q.column_major = 1;
1217 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1218 * below in the interface_block_layout_qualifier rule.
1220 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1223 * Also, this takes care of alternate capitalizations of
1224 * "row_major" (which is necessary because layout qualifiers
1225 * are case-insensitive in desktop GLSL).
1227 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1228 $$.flags.q.row_major = 1;
1229 /* "packed" is a reserved word in GLSL, and its token is
1230 * parsed below in the interface_block_layout_qualifier rule.
1231 * However, we must take care of alternate capitalizations of
1232 * "packed", because layout qualifiers are case-insensitive
1235 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1236 $$.flags.q.packed = 1;
1239 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1240 _mesa_glsl_warning(& @1, state,
1241 "#version 140 / GL_ARB_uniform_buffer_object "
1242 "layout qualifier `%s' is used", $1);
1246 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1248 static const struct {
1252 { "points", GL_POINTS },
1253 { "lines", GL_LINES },
1254 { "lines_adjacency", GL_LINES_ADJACENCY },
1255 { "line_strip", GL_LINE_STRIP },
1256 { "triangles", GL_TRIANGLES },
1257 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1258 { "triangle_strip", GL_TRIANGLE_STRIP },
1260 for (unsigned i = 0; i < Elements(map); i++) {
1261 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1262 $$.flags.q.prim_type = 1;
1263 $$.prim_type = map[i].e;
1268 if ($$.flags.i && !state->is_version(150, 0)) {
1269 _mesa_glsl_error(& @1, state, "#version 150 layout "
1270 "qualifier `%s' used", $1);
1274 /* Layout qualifiers for ARB_shader_image_load_store. */
1275 if (state->ARB_shader_image_load_store_enable ||
1276 state->is_version(420, 0)) {
1278 static const struct {
1281 glsl_base_type base_type;
1283 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT },
1284 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT },
1285 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT },
1286 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT },
1287 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT },
1288 { "r32f", GL_R32F, GLSL_TYPE_FLOAT },
1289 { "r16f", GL_R16F, GLSL_TYPE_FLOAT },
1290 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT },
1291 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT },
1292 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT },
1293 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT },
1294 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT },
1295 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT },
1296 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT },
1297 { "r32ui", GL_R32UI, GLSL_TYPE_UINT },
1298 { "r16ui", GL_R16UI, GLSL_TYPE_UINT },
1299 { "r8ui", GL_R8UI, GLSL_TYPE_UINT },
1300 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT },
1301 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT },
1302 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT },
1303 { "rg32i", GL_RG32I, GLSL_TYPE_INT },
1304 { "rg16i", GL_RG16I, GLSL_TYPE_INT },
1305 { "rg8i", GL_RG8I, GLSL_TYPE_INT },
1306 { "r32i", GL_R32I, GLSL_TYPE_INT },
1307 { "r16i", GL_R16I, GLSL_TYPE_INT },
1308 { "r8i", GL_R8I, GLSL_TYPE_INT },
1309 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT },
1310 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT },
1311 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT },
1312 { "rg16", GL_RG16, GLSL_TYPE_FLOAT },
1313 { "rg8", GL_RG8, GLSL_TYPE_FLOAT },
1314 { "r16", GL_R16, GLSL_TYPE_FLOAT },
1315 { "r8", GL_R8, GLSL_TYPE_FLOAT },
1316 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT },
1317 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT },
1318 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT },
1319 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT },
1320 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT },
1321 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT }
1324 for (unsigned i = 0; i < Elements(map); i++) {
1325 if (match_layout_qualifier($1, map[i].name, state) == 0) {
1326 $$.flags.q.explicit_image_format = 1;
1327 $$.image_format = map[i].format;
1328 $$.image_base_type = map[i].base_type;
1335 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1336 $$.flags.q.early_fragment_tests = 1;
1341 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1346 | any_identifier '=' integer_constant
1348 memset(& $$, 0, sizeof($$));
1350 if (match_layout_qualifier("location", $1, state) == 0) {
1351 $$.flags.q.explicit_location = 1;
1353 if ($$.flags.q.attribute == 1 &&
1354 state->ARB_explicit_attrib_location_warn) {
1355 _mesa_glsl_warning(& @1, state,
1356 "GL_ARB_explicit_attrib_location layout "
1357 "identifier `%s' used", $1);
1363 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1368 if (match_layout_qualifier("index", $1, state) == 0) {
1369 $$.flags.q.explicit_index = 1;
1374 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1379 if ((state->ARB_shading_language_420pack_enable ||
1380 state->ARB_shader_atomic_counters_enable) &&
1381 match_layout_qualifier("binding", $1, state) == 0) {
1382 $$.flags.q.explicit_binding = 1;
1386 if (state->ARB_shader_atomic_counters_enable &&
1387 match_layout_qualifier("offset", $1, state) == 0) {
1388 $$.flags.q.explicit_offset = 1;
1392 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1393 $$.flags.q.max_vertices = 1;
1396 _mesa_glsl_error(& @3, state,
1397 "invalid max_vertices %d specified", $3);
1400 $$.max_vertices = $3;
1401 if (!state->is_version(150, 0)) {
1402 _mesa_glsl_error(& @3, state,
1403 "#version 150 max_vertices qualifier "
1409 if (state->stage == MESA_SHADER_GEOMETRY) {
1410 if (match_layout_qualifier("stream", $1, state) == 0 &&
1411 state->check_explicit_attrib_stream_allowed(& @3)) {
1412 $$.flags.q.stream = 1;
1415 _mesa_glsl_error(& @3, state,
1416 "invalid stream %d specified", $3);
1419 $$.flags.q.explicit_stream = 1;
1425 static const char * const local_size_qualifiers[3] = {
1430 for (int i = 0; i < 3; i++) {
1431 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1434 _mesa_glsl_error(& @3, state,
1435 "invalid %s of %d specified",
1436 local_size_qualifiers[i], $3);
1438 } else if (!state->is_version(430, 0) &&
1439 !state->ARB_compute_shader_enable) {
1440 _mesa_glsl_error(& @3, state,
1441 "%s qualifier requires GLSL 4.30 or "
1442 "ARB_compute_shader",
1443 local_size_qualifiers[i]);
1446 $$.flags.q.local_size |= (1 << i);
1447 $$.local_size[i] = $3;
1453 if (match_layout_qualifier("invocations", $1, state) == 0) {
1454 $$.flags.q.invocations = 1;
1457 _mesa_glsl_error(& @3, state,
1458 "invalid invocations %d specified", $3);
1460 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1461 _mesa_glsl_error(& @3, state,
1462 "invocations (%d) exceeds "
1463 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1466 $$.invocations = $3;
1467 if (!state->is_version(400, 0) &&
1468 !state->ARB_gpu_shader5_enable) {
1469 _mesa_glsl_error(& @3, state,
1470 "GL_ARB_gpu_shader5 invocations "
1471 "qualifier specified", $3);
1476 /* If the identifier didn't match any known layout identifiers,
1480 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1485 | interface_block_layout_qualifier
1488 /* Layout qualifiers for ARB_uniform_buffer_object. */
1489 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1490 _mesa_glsl_error(& @1, state,
1491 "#version 140 / GL_ARB_uniform_buffer_object "
1492 "layout qualifier `%s' is used", $1);
1493 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1494 _mesa_glsl_warning(& @1, state,
1495 "#version 140 / GL_ARB_uniform_buffer_object "
1496 "layout qualifier `%s' is used", $1);
1501 /* This is a separate language rule because we parse these as tokens
1502 * (due to them being reserved keywords) instead of identifiers like
1503 * most qualifiers. See the any_identifier path of
1504 * layout_qualifier_id for the others.
1506 * Note that since layout qualifiers are case-insensitive in desktop
1507 * GLSL, all of these qualifiers need to be handled as identifiers as
1508 * well (by the any_identifier path of layout_qualifier_id).
1510 interface_block_layout_qualifier:
1513 memset(& $$, 0, sizeof($$));
1514 $$.flags.q.row_major = 1;
1518 memset(& $$, 0, sizeof($$));
1519 $$.flags.q.packed = 1;
1523 interpolation_qualifier:
1526 memset(& $$, 0, sizeof($$));
1527 $$.flags.q.smooth = 1;
1531 memset(& $$, 0, sizeof($$));
1532 $$.flags.q.flat = 1;
1536 memset(& $$, 0, sizeof($$));
1537 $$.flags.q.noperspective = 1;
1542 /* Single qualifiers */
1545 memset(& $$, 0, sizeof($$));
1546 $$.flags.q.invariant = 1;
1550 memset(& $$, 0, sizeof($$));
1551 $$.flags.q.precise = 1;
1553 | auxiliary_storage_qualifier
1555 | interpolation_qualifier
1557 | precision_qualifier
1559 memset(&$$, 0, sizeof($$));
1563 /* Multiple qualifiers:
1564 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1565 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1567 * invariant interpolation auxiliary storage precision ...or...
1568 * layout storage precision
1570 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1571 * side don't contain any that must appear on the left hand side.
1572 * For example, when processing a storage qualifier, we check that there are
1573 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1575 | PRECISE type_qualifier
1577 if ($2.flags.q.precise)
1578 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1581 $$.flags.q.precise = 1;
1583 | INVARIANT type_qualifier
1585 if ($2.flags.q.invariant)
1586 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1588 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.precise)
1589 _mesa_glsl_error(&@1, state,
1590 "\"invariant\" must come after \"precise\"");
1593 $$.flags.q.invariant = 1;
1595 | interpolation_qualifier type_qualifier
1597 /* Section 4.3 of the GLSL 1.40 specification states:
1598 * "...qualified with one of these interpolation qualifiers"
1600 * GLSL 1.30 claims to allow "one or more", but insists that:
1601 * "These interpolation qualifiers may only precede the qualifiers in,
1602 * centroid in, out, or centroid out in a declaration."
1604 * ...which means that e.g. smooth can't precede smooth, so there can be
1605 * only one after all, and the 1.40 text is a clarification, not a change.
1607 if ($2.has_interpolation())
1608 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1610 if (!state->ARB_shading_language_420pack_enable &&
1611 ($2.flags.q.precise || $2.flags.q.invariant)) {
1612 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1613 "after \"precise\" or \"invariant\"");
1617 $$.merge_qualifier(&@1, state, $2);
1619 | layout_qualifier type_qualifier
1621 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1622 * appear no later than auxiliary storage qualifiers. There is no
1623 * particularly clear spec language mandating this, but in all examples
1624 * the layout qualifier precedes the storage qualifier.
1626 * We allow combinations of layout with interpolation, invariant or
1627 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1628 * There is no clear spec guidance on this either.
1630 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1631 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1634 $$.merge_qualifier(&@1, state, $2);
1636 | auxiliary_storage_qualifier type_qualifier
1638 if ($2.has_auxiliary_storage()) {
1639 _mesa_glsl_error(&@1, state,
1640 "duplicate auxiliary storage qualifier (centroid or sample)");
1643 if (!state->ARB_shading_language_420pack_enable &&
1644 ($2.flags.q.precise || $2.flags.q.invariant ||
1645 $2.has_interpolation() || $2.has_layout())) {
1646 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1647 "just before storage qualifiers");
1650 $$.merge_qualifier(&@1, state, $2);
1652 | storage_qualifier type_qualifier
1654 /* Section 4.3 of the GLSL 1.20 specification states:
1655 * "Variable declarations may have a storage qualifier specified..."
1656 * 1.30 clarifies this to "may have one storage qualifier".
1658 if ($2.has_storage())
1659 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1661 if (!state->ARB_shading_language_420pack_enable &&
1662 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1663 $2.has_layout() || $2.has_auxiliary_storage())) {
1664 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1665 "precise, invariant, interpolation, layout and auxiliary "
1666 "storage qualifiers");
1670 $$.merge_qualifier(&@1, state, $2);
1672 | precision_qualifier type_qualifier
1674 if ($2.precision != ast_precision_none)
1675 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1677 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1678 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1685 auxiliary_storage_qualifier:
1688 memset(& $$, 0, sizeof($$));
1689 $$.flags.q.centroid = 1;
1693 memset(& $$, 0, sizeof($$));
1694 $$.flags.q.sample = 1;
1696 /* TODO: "patch" also goes here someday. */
1701 memset(& $$, 0, sizeof($$));
1702 $$.flags.q.constant = 1;
1706 memset(& $$, 0, sizeof($$));
1707 $$.flags.q.attribute = 1;
1711 memset(& $$, 0, sizeof($$));
1712 $$.flags.q.varying = 1;
1716 memset(& $$, 0, sizeof($$));
1721 memset(& $$, 0, sizeof($$));
1724 if (state->stage == MESA_SHADER_GEOMETRY &&
1725 state->has_explicit_attrib_stream()) {
1726 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1729 * "If the block or variable is declared with the stream
1730 * identifier, it is associated with the specified stream;
1731 * otherwise, it is associated with the current default stream."
1733 $$.flags.q.stream = 1;
1734 $$.flags.q.explicit_stream = 0;
1735 $$.stream = state->out_qualifier->stream;
1740 memset(& $$, 0, sizeof($$));
1741 $$.flags.q.uniform = 1;
1745 memset(& $$, 0, sizeof($$));
1746 $$.flags.q.coherent = 1;
1750 memset(& $$, 0, sizeof($$));
1751 $$.flags.q._volatile = 1;
1755 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1756 memset(& $$, 0, sizeof($$));
1757 $$.flags.q.restrict_flag = 1;
1761 memset(& $$, 0, sizeof($$));
1762 $$.flags.q.read_only = 1;
1766 memset(& $$, 0, sizeof($$));
1767 $$.flags.q.write_only = 1;
1775 $$ = new(ctx) ast_array_specifier(@1);
1776 $$->set_location_range(@1, @2);
1778 | '[' constant_expression ']'
1781 $$ = new(ctx) ast_array_specifier(@1, $2);
1782 $$->set_location_range(@1, @3);
1784 | array_specifier '[' ']'
1788 if (!state->ARB_arrays_of_arrays_enable) {
1789 _mesa_glsl_error(& @1, state,
1790 "GL_ARB_arrays_of_arrays "
1791 "required for defining arrays of arrays");
1793 _mesa_glsl_error(& @1, state,
1794 "only the outermost array dimension can "
1798 | array_specifier '[' constant_expression ']'
1802 if (!state->ARB_arrays_of_arrays_enable) {
1803 _mesa_glsl_error(& @1, state,
1804 "GL_ARB_arrays_of_arrays "
1805 "required for defining arrays of arrays");
1808 $$->add_dimension($3);
1813 type_specifier_nonarray
1814 | type_specifier_nonarray array_specifier
1817 $$->array_specifier = $2;
1821 type_specifier_nonarray:
1822 basic_type_specifier_nonarray
1825 $$ = new(ctx) ast_type_specifier($1);
1826 $$->set_location(@1);
1831 $$ = new(ctx) ast_type_specifier($1);
1832 $$->set_location(@1);
1837 $$ = new(ctx) ast_type_specifier($1);
1838 $$->set_location(@1);
1842 basic_type_specifier_nonarray:
1843 VOID_TOK { $$ = "void"; }
1844 | FLOAT_TOK { $$ = "float"; }
1845 | INT_TOK { $$ = "int"; }
1846 | UINT_TOK { $$ = "uint"; }
1847 | BOOL_TOK { $$ = "bool"; }
1848 | VEC2 { $$ = "vec2"; }
1849 | VEC3 { $$ = "vec3"; }
1850 | VEC4 { $$ = "vec4"; }
1851 | BVEC2 { $$ = "bvec2"; }
1852 | BVEC3 { $$ = "bvec3"; }
1853 | BVEC4 { $$ = "bvec4"; }
1854 | IVEC2 { $$ = "ivec2"; }
1855 | IVEC3 { $$ = "ivec3"; }
1856 | IVEC4 { $$ = "ivec4"; }
1857 | UVEC2 { $$ = "uvec2"; }
1858 | UVEC3 { $$ = "uvec3"; }
1859 | UVEC4 { $$ = "uvec4"; }
1860 | MAT2X2 { $$ = "mat2"; }
1861 | MAT2X3 { $$ = "mat2x3"; }
1862 | MAT2X4 { $$ = "mat2x4"; }
1863 | MAT3X2 { $$ = "mat3x2"; }
1864 | MAT3X3 { $$ = "mat3"; }
1865 | MAT3X4 { $$ = "mat3x4"; }
1866 | MAT4X2 { $$ = "mat4x2"; }
1867 | MAT4X3 { $$ = "mat4x3"; }
1868 | MAT4X4 { $$ = "mat4"; }
1869 | SAMPLER1D { $$ = "sampler1D"; }
1870 | SAMPLER2D { $$ = "sampler2D"; }
1871 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1872 | SAMPLER3D { $$ = "sampler3D"; }
1873 | SAMPLERCUBE { $$ = "samplerCube"; }
1874 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1875 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1876 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1877 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1878 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1879 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1880 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1881 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1882 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1883 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1884 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1885 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1886 | ISAMPLER1D { $$ = "isampler1D"; }
1887 | ISAMPLER2D { $$ = "isampler2D"; }
1888 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1889 | ISAMPLER3D { $$ = "isampler3D"; }
1890 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1891 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1892 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1893 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1894 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1895 | USAMPLER1D { $$ = "usampler1D"; }
1896 | USAMPLER2D { $$ = "usampler2D"; }
1897 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1898 | USAMPLER3D { $$ = "usampler3D"; }
1899 | USAMPLERCUBE { $$ = "usamplerCube"; }
1900 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1901 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1902 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1903 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1904 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1905 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1906 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1907 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1908 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1909 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1910 | IMAGE1D { $$ = "image1D"; }
1911 | IMAGE2D { $$ = "image2D"; }
1912 | IMAGE3D { $$ = "image3D"; }
1913 | IMAGE2DRECT { $$ = "image2DRect"; }
1914 | IMAGECUBE { $$ = "imageCube"; }
1915 | IMAGEBUFFER { $$ = "imageBuffer"; }
1916 | IMAGE1DARRAY { $$ = "image1DArray"; }
1917 | IMAGE2DARRAY { $$ = "image2DArray"; }
1918 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
1919 | IMAGE2DMS { $$ = "image2DMS"; }
1920 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
1921 | IIMAGE1D { $$ = "iimage1D"; }
1922 | IIMAGE2D { $$ = "iimage2D"; }
1923 | IIMAGE3D { $$ = "iimage3D"; }
1924 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
1925 | IIMAGECUBE { $$ = "iimageCube"; }
1926 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
1927 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
1928 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
1929 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
1930 | IIMAGE2DMS { $$ = "iimage2DMS"; }
1931 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
1932 | UIMAGE1D { $$ = "uimage1D"; }
1933 | UIMAGE2D { $$ = "uimage2D"; }
1934 | UIMAGE3D { $$ = "uimage3D"; }
1935 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
1936 | UIMAGECUBE { $$ = "uimageCube"; }
1937 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
1938 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
1939 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
1940 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
1941 | UIMAGE2DMS { $$ = "uimage2DMS"; }
1942 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
1943 | ATOMIC_UINT { $$ = "atomic_uint"; }
1946 precision_qualifier:
1949 state->check_precision_qualifiers_allowed(&@1);
1950 $$ = ast_precision_high;
1954 state->check_precision_qualifiers_allowed(&@1);
1955 $$ = ast_precision_medium;
1959 state->check_precision_qualifiers_allowed(&@1);
1960 $$ = ast_precision_low;
1965 STRUCT any_identifier '{' struct_declaration_list '}'
1968 $$ = new(ctx) ast_struct_specifier($2, $4);
1969 $$->set_location_range(@2, @5);
1970 state->symbols->add_type($2, glsl_type::void_type);
1972 | STRUCT '{' struct_declaration_list '}'
1975 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1976 $$->set_location_range(@2, @4);
1980 struct_declaration_list:
1984 $1->link.self_link();
1986 | struct_declaration_list struct_declaration
1989 $$->link.insert_before(& $2->link);
1994 fully_specified_type struct_declarator_list ';'
1997 ast_fully_specified_type *const type = $1;
1998 type->set_location(@1);
2000 if (type->qualifier.flags.i != 0)
2001 _mesa_glsl_error(&@1, state,
2002 "only precision qualifiers may be applied to "
2003 "structure members");
2005 $$ = new(ctx) ast_declarator_list(type);
2006 $$->set_location(@2);
2008 $$->declarations.push_degenerate_list_at_head(& $2->link);
2012 struct_declarator_list:
2016 $1->link.self_link();
2018 | struct_declarator_list ',' struct_declarator
2021 $$->link.insert_before(& $3->link);
2029 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2030 $$->set_location(@1);
2032 | any_identifier array_specifier
2035 $$ = new(ctx) ast_declaration($1, $2, NULL);
2036 $$->set_location_range(@1, @2);
2041 assignment_expression
2042 | '{' initializer_list '}'
2046 | '{' initializer_list ',' '}'
2056 $$ = new(ctx) ast_aggregate_initializer();
2057 $$->set_location(@1);
2058 $$->expressions.push_tail(& $1->link);
2060 | initializer_list ',' initializer
2062 $1->expressions.push_tail(& $3->link);
2066 declaration_statement:
2070 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2073 compound_statement { $$ = (ast_node *) $1; }
2078 declaration_statement
2079 | expression_statement
2080 | selection_statement
2082 | iteration_statement
2090 $$ = new(ctx) ast_compound_statement(true, NULL);
2091 $$->set_location_range(@1, @2);
2095 state->symbols->push_scope();
2100 $$ = new(ctx) ast_compound_statement(true, $3);
2101 $$->set_location_range(@1, @4);
2102 state->symbols->pop_scope();
2106 statement_no_new_scope:
2107 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2111 compound_statement_no_new_scope:
2115 $$ = new(ctx) ast_compound_statement(false, NULL);
2116 $$->set_location_range(@1, @2);
2118 | '{' statement_list '}'
2121 $$ = new(ctx) ast_compound_statement(false, $2);
2122 $$->set_location_range(@1, @3);
2130 _mesa_glsl_error(& @1, state, "<nil> statement");
2135 $$->link.self_link();
2137 | statement_list statement
2140 _mesa_glsl_error(& @2, state, "<nil> statement");
2144 $$->link.insert_before(& $2->link);
2148 expression_statement:
2152 $$ = new(ctx) ast_expression_statement(NULL);
2153 $$->set_location(@1);
2158 $$ = new(ctx) ast_expression_statement($1);
2159 $$->set_location(@1);
2163 selection_statement:
2164 IF '(' expression ')' selection_rest_statement
2166 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2168 $$->set_location_range(@1, @5);
2172 selection_rest_statement:
2173 statement ELSE statement
2175 $$.then_statement = $1;
2176 $$.else_statement = $3;
2178 | statement %prec THEN
2180 $$.then_statement = $1;
2181 $$.else_statement = NULL;
2188 $$ = (ast_node *) $1;
2190 | fully_specified_type any_identifier '=' initializer
2193 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2194 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2195 decl->set_location_range(@2, @4);
2196 declarator->set_location(@1);
2198 declarator->declarations.push_tail(&decl->link);
2204 * switch_statement grammar is based on the syntax described in the body
2205 * of the GLSL spec, not in it's appendix!!!
2208 SWITCH '(' expression ')' switch_body
2210 $$ = new(state) ast_switch_statement($3, $5);
2211 $$->set_location_range(@1, @5);
2218 $$ = new(state) ast_switch_body(NULL);
2219 $$->set_location_range(@1, @2);
2221 | '{' case_statement_list '}'
2223 $$ = new(state) ast_switch_body($2);
2224 $$->set_location_range(@1, @3);
2231 $$ = new(state) ast_case_label($2);
2232 $$->set_location(@2);
2236 $$ = new(state) ast_case_label(NULL);
2237 $$->set_location(@2);
2244 ast_case_label_list *labels = new(state) ast_case_label_list();
2246 labels->labels.push_tail(& $1->link);
2248 $$->set_location(@1);
2250 | case_label_list case_label
2253 $$->labels.push_tail(& $2->link);
2258 case_label_list statement
2260 ast_case_statement *stmts = new(state) ast_case_statement($1);
2261 stmts->set_location(@2);
2263 stmts->stmts.push_tail(& $2->link);
2266 | case_statement statement
2269 $$->stmts.push_tail(& $2->link);
2273 case_statement_list:
2276 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2277 cases->set_location(@1);
2279 cases->cases.push_tail(& $1->link);
2282 | case_statement_list case_statement
2285 $$->cases.push_tail(& $2->link);
2289 iteration_statement:
2290 WHILE '(' condition ')' statement_no_new_scope
2293 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2294 NULL, $3, NULL, $5);
2295 $$->set_location_range(@1, @4);
2297 | DO statement WHILE '(' expression ')' ';'
2300 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2301 NULL, $5, NULL, $2);
2302 $$->set_location_range(@1, @6);
2304 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2307 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2308 $3, $4.cond, $4.rest, $6);
2309 $$->set_location_range(@1, @6);
2314 expression_statement
2315 | declaration_statement
2332 | conditionopt ';' expression
2339 // Grammar Note: No 'goto'. Gotos are not supported.
2344 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2345 $$->set_location(@1);
2350 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2351 $$->set_location(@1);
2356 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2357 $$->set_location(@1);
2359 | RETURN expression ';'
2362 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2363 $$->set_location_range(@1, @2);
2365 | DISCARD ';' // Fragment shader only.
2368 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2369 $$->set_location(@1);
2373 external_declaration:
2374 function_definition { $$ = $1; }
2375 | declaration { $$ = $1; }
2376 | pragma_statement { $$ = NULL; }
2377 | layout_defaults { $$ = $1; }
2380 function_definition:
2381 function_prototype compound_statement_no_new_scope
2384 $$ = new(ctx) ast_function_definition();
2385 $$->set_location_range(@1, @2);
2389 state->symbols->pop_scope();
2393 /* layout_qualifieropt is packed into this rule */
2395 basic_interface_block
2399 | layout_qualifier basic_interface_block
2401 ast_interface_block *block = $2;
2402 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2406 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2407 ast_type_qualifier& qualifier = member->type->qualifier;
2408 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2409 _mesa_glsl_error(& @1, state,
2410 "stream layout qualifier on "
2411 "interface block member does not match "
2412 "the interface block (%d vs %d)",
2413 qualifier.stream, block->layout.stream);
2421 basic_interface_block:
2422 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2424 ast_interface_block *const block = $6;
2426 block->block_name = $2;
2427 block->declarations.push_degenerate_list_at_head(& $4->link);
2429 if ($1.flags.q.uniform) {
2430 if (!state->has_uniform_buffer_objects()) {
2431 _mesa_glsl_error(& @1, state,
2432 "#version 140 / GL_ARB_uniform_buffer_object "
2433 "required for defining uniform blocks");
2434 } else if (state->ARB_uniform_buffer_object_warn) {
2435 _mesa_glsl_warning(& @1, state,
2436 "#version 140 / GL_ARB_uniform_buffer_object "
2437 "required for defining uniform blocks");
2440 if (state->es_shader || state->language_version < 150) {
2441 _mesa_glsl_error(& @1, state,
2442 "#version 150 required for using "
2443 "interface blocks");
2447 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2448 * "It is illegal to have an input block in a vertex shader
2449 * or an output block in a fragment shader"
2451 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2452 _mesa_glsl_error(& @1, state,
2453 "`in' interface block is not allowed for "
2455 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2456 _mesa_glsl_error(& @1, state,
2457 "`out' interface block is not allowed for "
2458 "a fragment shader");
2461 /* Since block arrays require names, and both features are added in
2462 * the same language versions, we don't have to explicitly
2463 * version-check both things.
2465 if (block->instance_name != NULL) {
2466 state->check_version(150, 300, & @1, "interface blocks with "
2467 "an instance name are not allowed");
2470 uint64_t interface_type_mask;
2471 struct ast_type_qualifier temp_type_qualifier;
2473 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2474 * to ignore other irrelevant flags like interpolation qualifiers.
2476 temp_type_qualifier.flags.i = 0;
2477 temp_type_qualifier.flags.q.uniform = true;
2478 temp_type_qualifier.flags.q.in = true;
2479 temp_type_qualifier.flags.q.out = true;
2480 interface_type_mask = temp_type_qualifier.flags.i;
2482 /* Get the block's interface qualifier. The interface_qualifier
2483 * production rule guarantees that only one bit will be set (and
2484 * it will be in/out/uniform).
2486 uint64_t block_interface_qualifier = $1.flags.i;
2488 block->layout.flags.i |= block_interface_qualifier;
2490 if (state->stage == MESA_SHADER_GEOMETRY &&
2491 state->has_explicit_attrib_stream()) {
2492 /* Assign global layout's stream value. */
2493 block->layout.flags.q.stream = 1;
2494 block->layout.flags.q.explicit_stream = 0;
2495 block->layout.stream = state->out_qualifier->stream;
2498 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2499 ast_type_qualifier& qualifier = member->type->qualifier;
2500 if ((qualifier.flags.i & interface_type_mask) == 0) {
2501 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2502 * "If no optional qualifier is used in a member declaration, the
2503 * qualifier of the variable is just in, out, or uniform as declared
2504 * by interface-qualifier."
2506 qualifier.flags.i |= block_interface_qualifier;
2507 } else if ((qualifier.flags.i & interface_type_mask) !=
2508 block_interface_qualifier) {
2509 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2510 * "If optional qualifiers are used, they can include interpolation
2511 * and storage qualifiers and they must declare an input, output,
2512 * or uniform variable consistent with the interface qualifier of
2515 _mesa_glsl_error(& @1, state,
2516 "uniform/in/out qualifier on "
2517 "interface block member does not match "
2518 "the interface block");
2526 interface_qualifier:
2529 memset(& $$, 0, sizeof($$));
2534 memset(& $$, 0, sizeof($$));
2539 memset(& $$, 0, sizeof($$));
2540 $$.flags.q.uniform = 1;
2547 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2552 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2554 $$->set_location(@1);
2556 | NEW_IDENTIFIER array_specifier
2558 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2560 $$->set_location_range(@1, @2);
2568 $1->link.self_link();
2570 | member_declaration member_list
2573 $2->link.insert_before(& $$->link);
2578 fully_specified_type struct_declarator_list ';'
2581 ast_fully_specified_type *type = $1;
2582 type->set_location(@1);
2584 if (type->qualifier.flags.q.attribute) {
2585 _mesa_glsl_error(& @1, state,
2586 "keyword 'attribute' cannot be used with "
2587 "interface block member");
2588 } else if (type->qualifier.flags.q.varying) {
2589 _mesa_glsl_error(& @1, state,
2590 "keyword 'varying' cannot be used with "
2591 "interface block member");
2594 $$ = new(ctx) ast_declarator_list(type);
2595 $$->set_location(@2);
2597 $$->declarations.push_degenerate_list_at_head(& $2->link);
2602 layout_qualifier UNIFORM ';'
2604 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2610 | layout_qualifier IN_TOK ';'
2613 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2618 | layout_qualifier OUT_TOK ';'
2620 if (state->stage != MESA_SHADER_GEOMETRY) {
2621 _mesa_glsl_error(& @1, state,
2622 "out layout qualifiers only valid in "
2623 "geometry shaders");
2625 if ($1.flags.q.prim_type) {
2626 /* Make sure this is a valid output primitive type. */
2627 switch ($1.prim_type) {
2630 case GL_TRIANGLE_STRIP:
2633 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2638 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2641 /* Allow future assigments of global out's stream id value */
2642 state->out_qualifier->flags.q.explicit_stream = 0;