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.
30 #include "glsl_parser_extras.h"
31 #include "glsl_types.h"
32 #include "main/context.h"
36 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
38 _mesa_glsl_error(loc, st, "%s", msg);
42 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
44 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
47 static bool match_layout_qualifier(const char *s1, const char *s2,
48 _mesa_glsl_parse_state *state)
50 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
52 * "The tokens in any layout-qualifier-id-list ... are not case
53 * sensitive, unless explicitly noted otherwise."
55 * The text "unless explicitly noted otherwise" appears to be
56 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
59 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
62 * "As for other identifiers, they are case sensitive."
64 * So we need to do a case-sensitive or a case-insensitive match,
65 * depending on whether we are compiling for GLSL ES.
68 return strcmp(s1, s2);
70 return strcasecmp(s1, s2);
88 %lex-param {struct _mesa_glsl_parse_state *state}
89 %parse-param {struct _mesa_glsl_parse_state *state}
94 const char *identifier;
96 struct ast_type_qualifier type_qualifier;
99 ast_type_specifier *type_specifier;
100 ast_array_specifier *array_specifier;
101 ast_fully_specified_type *fully_specified_type;
102 ast_function *function;
103 ast_parameter_declarator *parameter_declarator;
104 ast_function_definition *function_definition;
105 ast_compound_statement *compound_statement;
106 ast_expression *expression;
107 ast_declarator_list *declarator_list;
108 ast_struct_specifier *struct_specifier;
109 ast_declaration *declaration;
110 ast_switch_body *switch_body;
111 ast_case_label *case_label;
112 ast_case_label_list *case_label_list;
113 ast_case_statement *case_statement;
114 ast_case_statement_list *case_statement_list;
115 ast_interface_block *interface_block;
119 ast_expression *rest;
120 } for_rest_statement;
123 ast_node *then_statement;
124 ast_node *else_statement;
125 } selection_rest_statement;
128 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
129 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
130 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
131 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
132 %token NOPERSPECTIVE FLAT SMOOTH
133 %token MAT2X2 MAT2X3 MAT2X4
134 %token MAT3X2 MAT3X3 MAT3X4
135 %token MAT4X2 MAT4X3 MAT4X4
136 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
137 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
138 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
139 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
140 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
141 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
142 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
143 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
144 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
145 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
146 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
147 %token SAMPLEREXTERNALOES
148 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
149 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
150 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
151 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
152 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
153 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
154 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
155 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
157 %token STRUCT VOID_TOK WHILE
158 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
159 %type <identifier> any_identifier
160 %type <interface_block> instance_name_opt
161 %token <real> FLOATCONSTANT
162 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
163 %token <identifier> FIELD_SELECTION
164 %token LEFT_OP RIGHT_OP
165 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
166 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
167 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
169 %token INVARIANT PRECISE
170 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
172 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
173 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
174 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
175 %token PRAGMA_INVARIANT_ALL
178 /* Reserved words that are not actually used in the grammar.
180 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
181 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
182 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
183 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
185 %token SIZEOF CAST NAMESPACE USING
186 %token RESOURCE PATCH
191 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
193 %type <identifier> variable_identifier
194 %type <node> statement
195 %type <node> statement_list
196 %type <node> simple_statement
197 %type <n> precision_qualifier
198 %type <type_qualifier> type_qualifier
199 %type <type_qualifier> auxiliary_storage_qualifier
200 %type <type_qualifier> storage_qualifier
201 %type <type_qualifier> interpolation_qualifier
202 %type <type_qualifier> layout_qualifier
203 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
204 %type <type_qualifier> interface_block_layout_qualifier
205 %type <type_qualifier> interface_qualifier
206 %type <type_specifier> type_specifier
207 %type <type_specifier> type_specifier_nonarray
208 %type <array_specifier> array_specifier
209 %type <identifier> basic_type_specifier_nonarray
210 %type <fully_specified_type> fully_specified_type
211 %type <function> function_prototype
212 %type <function> function_header
213 %type <function> function_header_with_parameters
214 %type <function> function_declarator
215 %type <parameter_declarator> parameter_declarator
216 %type <parameter_declarator> parameter_declaration
217 %type <type_qualifier> parameter_qualifier
218 %type <type_qualifier> parameter_direction_qualifier
219 %type <type_specifier> parameter_type_specifier
220 %type <function_definition> function_definition
221 %type <compound_statement> compound_statement_no_new_scope
222 %type <compound_statement> compound_statement
223 %type <node> statement_no_new_scope
224 %type <node> expression_statement
225 %type <expression> expression
226 %type <expression> primary_expression
227 %type <expression> assignment_expression
228 %type <expression> conditional_expression
229 %type <expression> logical_or_expression
230 %type <expression> logical_xor_expression
231 %type <expression> logical_and_expression
232 %type <expression> inclusive_or_expression
233 %type <expression> exclusive_or_expression
234 %type <expression> and_expression
235 %type <expression> equality_expression
236 %type <expression> relational_expression
237 %type <expression> shift_expression
238 %type <expression> additive_expression
239 %type <expression> multiplicative_expression
240 %type <expression> unary_expression
241 %type <expression> constant_expression
242 %type <expression> integer_expression
243 %type <expression> postfix_expression
244 %type <expression> function_call_header_with_parameters
245 %type <expression> function_call_header_no_parameters
246 %type <expression> function_call_header
247 %type <expression> function_call_generic
248 %type <expression> function_call_or_method
249 %type <expression> function_call
250 %type <expression> method_call_generic
251 %type <expression> method_call_header_with_parameters
252 %type <expression> method_call_header_no_parameters
253 %type <expression> method_call_header
254 %type <n> assignment_operator
255 %type <n> unary_operator
256 %type <expression> function_identifier
257 %type <node> external_declaration
258 %type <declarator_list> init_declarator_list
259 %type <declarator_list> single_declaration
260 %type <expression> initializer
261 %type <expression> initializer_list
262 %type <node> declaration
263 %type <node> declaration_statement
264 %type <node> jump_statement
265 %type <node> interface_block
266 %type <interface_block> basic_interface_block
267 %type <struct_specifier> struct_specifier
268 %type <declarator_list> struct_declaration_list
269 %type <declarator_list> struct_declaration
270 %type <declaration> struct_declarator
271 %type <declaration> struct_declarator_list
272 %type <declarator_list> member_list
273 %type <declarator_list> member_declaration
274 %type <node> selection_statement
275 %type <selection_rest_statement> selection_rest_statement
276 %type <node> switch_statement
277 %type <switch_body> switch_body
278 %type <case_label_list> case_label_list
279 %type <case_label> case_label
280 %type <case_statement> case_statement
281 %type <case_statement_list> case_statement_list
282 %type <node> iteration_statement
283 %type <node> condition
284 %type <node> conditionopt
285 %type <node> for_init_statement
286 %type <for_rest_statement> for_rest_statement
287 %type <n> integer_constant
288 %type <node> layout_defaults
294 version_statement extension_statement_list
296 _mesa_glsl_initialize_types(state);
298 external_declaration_list
300 delete state->symbols;
301 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
302 _mesa_glsl_initialize_types(state);
307 /* blank - no #version specified: defaults are already set */
308 | VERSION_TOK INTCONSTANT EOL
310 state->process_version_directive(&@2, $2, NULL);
315 | VERSION_TOK INTCONSTANT any_identifier EOL
317 state->process_version_directive(&@2, $2, $3);
326 | PRAGMA_DEBUG_OFF EOL
327 | PRAGMA_OPTIMIZE_ON EOL
328 | PRAGMA_OPTIMIZE_OFF EOL
329 | PRAGMA_INVARIANT_ALL EOL
331 if (!state->is_version(120, 100)) {
332 _mesa_glsl_warning(& @1, state,
333 "pragma `invariant(all)' not supported in %s "
334 "(GLSL ES 1.00 or GLSL 1.20 required)",
335 state->get_version_string());
337 state->all_invariant = true;
342 extension_statement_list:
344 | extension_statement_list extension_statement
354 EXTENSION any_identifier COLON any_identifier EOL
356 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
362 external_declaration_list:
365 /* FINISHME: The NULL test is required because pragmas are set to
366 * FINISHME: NULL. (See production rule for external_declaration.)
369 state->translation_unit.push_tail(& $1->link);
371 | external_declaration_list external_declaration
373 /* FINISHME: The NULL test is required because pragmas are set to
374 * FINISHME: NULL. (See production rule for external_declaration.)
377 state->translation_unit.push_tail(& $2->link);
379 | external_declaration_list extension_statement {
380 if (!state->allow_extension_directive_midshader) {
381 _mesa_glsl_error(& @2, state,
382 "#extension directive is not allowed "
383 "in the middle of a shader");
398 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
399 $$->set_location(@1);
400 $$->primary_expression.identifier = $1;
405 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
406 $$->set_location(@1);
407 $$->primary_expression.int_constant = $1;
412 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
413 $$->set_location(@1);
414 $$->primary_expression.uint_constant = $1;
419 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
420 $$->set_location(@1);
421 $$->primary_expression.float_constant = $1;
426 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
427 $$->set_location(@1);
428 $$->primary_expression.bool_constant = $1;
438 | postfix_expression '[' integer_expression ']'
441 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
442 $$->set_location_range(@1, @4);
448 | postfix_expression '.' any_identifier
451 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
452 $$->set_location_range(@1, @3);
453 $$->primary_expression.identifier = $3;
455 | postfix_expression INC_OP
458 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
459 $$->set_location_range(@1, @2);
461 | postfix_expression DEC_OP
464 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
465 $$->set_location_range(@1, @2);
474 function_call_or_method
477 function_call_or_method:
478 function_call_generic
479 | postfix_expression '.' method_call_generic
482 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
483 $$->set_location_range(@1, @3);
487 function_call_generic:
488 function_call_header_with_parameters ')'
489 | function_call_header_no_parameters ')'
492 function_call_header_no_parameters:
493 function_call_header VOID_TOK
494 | function_call_header
497 function_call_header_with_parameters:
498 function_call_header assignment_expression
501 $$->set_location(@1);
502 $$->expressions.push_tail(& $2->link);
504 | function_call_header_with_parameters ',' assignment_expression
507 $$->set_location(@1);
508 $$->expressions.push_tail(& $3->link);
512 // Grammar Note: Constructors look like functions, but lexical
513 // analysis recognized most of them as keywords. They are now
514 // recognized through "type_specifier".
515 function_call_header:
516 function_identifier '('
523 $$ = new(ctx) ast_function_expression($1);
524 $$->set_location(@1);
526 | variable_identifier
529 ast_expression *callee = new(ctx) ast_expression($1);
530 callee->set_location(@1);
531 $$ = new(ctx) ast_function_expression(callee);
532 $$->set_location(@1);
537 ast_expression *callee = new(ctx) ast_expression($1);
538 callee->set_location(@1);
539 $$ = new(ctx) ast_function_expression(callee);
540 $$->set_location(@1);
545 method_call_header_with_parameters ')'
546 | method_call_header_no_parameters ')'
549 method_call_header_no_parameters:
550 method_call_header VOID_TOK
554 method_call_header_with_parameters:
555 method_call_header assignment_expression
558 $$->set_location(@1);
559 $$->expressions.push_tail(& $2->link);
561 | method_call_header_with_parameters ',' assignment_expression
564 $$->set_location(@1);
565 $$->expressions.push_tail(& $3->link);
569 // Grammar Note: Constructors look like methods, but lexical
570 // analysis recognized most of them as keywords. They are now
571 // recognized through "type_specifier".
573 variable_identifier '('
576 ast_expression *callee = new(ctx) ast_expression($1);
577 callee->set_location(@1);
578 $$ = new(ctx) ast_function_expression(callee);
579 $$->set_location(@1);
583 // Grammar Note: No traditional style type casts.
586 | INC_OP unary_expression
589 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
590 $$->set_location(@1);
592 | DEC_OP unary_expression
595 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
596 $$->set_location(@1);
598 | unary_operator unary_expression
601 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
602 $$->set_location_range(@1, @2);
606 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
608 '+' { $$ = ast_plus; }
609 | '-' { $$ = ast_neg; }
610 | '!' { $$ = ast_logic_not; }
611 | '~' { $$ = ast_bit_not; }
614 multiplicative_expression:
616 | multiplicative_expression '*' unary_expression
619 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
620 $$->set_location_range(@1, @3);
622 | multiplicative_expression '/' unary_expression
625 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
626 $$->set_location_range(@1, @3);
628 | multiplicative_expression '%' unary_expression
631 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
632 $$->set_location_range(@1, @3);
637 multiplicative_expression
638 | additive_expression '+' multiplicative_expression
641 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
642 $$->set_location_range(@1, @3);
644 | additive_expression '-' multiplicative_expression
647 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
648 $$->set_location_range(@1, @3);
654 | shift_expression LEFT_OP additive_expression
657 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
658 $$->set_location_range(@1, @3);
660 | shift_expression RIGHT_OP additive_expression
663 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
664 $$->set_location_range(@1, @3);
668 relational_expression:
670 | relational_expression '<' shift_expression
673 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
674 $$->set_location_range(@1, @3);
676 | relational_expression '>' shift_expression
679 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
680 $$->set_location_range(@1, @3);
682 | relational_expression LE_OP shift_expression
685 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
686 $$->set_location_range(@1, @3);
688 | relational_expression GE_OP shift_expression
691 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
692 $$->set_location_range(@1, @3);
697 relational_expression
698 | equality_expression EQ_OP relational_expression
701 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
702 $$->set_location_range(@1, @3);
704 | equality_expression NE_OP relational_expression
707 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
708 $$->set_location_range(@1, @3);
714 | and_expression '&' equality_expression
717 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
718 $$->set_location_range(@1, @3);
722 exclusive_or_expression:
724 | exclusive_or_expression '^' and_expression
727 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
728 $$->set_location_range(@1, @3);
732 inclusive_or_expression:
733 exclusive_or_expression
734 | inclusive_or_expression '|' exclusive_or_expression
737 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
738 $$->set_location_range(@1, @3);
742 logical_and_expression:
743 inclusive_or_expression
744 | logical_and_expression AND_OP inclusive_or_expression
747 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
748 $$->set_location_range(@1, @3);
752 logical_xor_expression:
753 logical_and_expression
754 | logical_xor_expression XOR_OP logical_and_expression
757 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
758 $$->set_location_range(@1, @3);
762 logical_or_expression:
763 logical_xor_expression
764 | logical_or_expression OR_OP logical_xor_expression
767 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
768 $$->set_location_range(@1, @3);
772 conditional_expression:
773 logical_or_expression
774 | logical_or_expression '?' expression ':' assignment_expression
777 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
778 $$->set_location_range(@1, @5);
782 assignment_expression:
783 conditional_expression
784 | unary_expression assignment_operator assignment_expression
787 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
788 $$->set_location_range(@1, @3);
793 '=' { $$ = ast_assign; }
794 | MUL_ASSIGN { $$ = ast_mul_assign; }
795 | DIV_ASSIGN { $$ = ast_div_assign; }
796 | MOD_ASSIGN { $$ = ast_mod_assign; }
797 | ADD_ASSIGN { $$ = ast_add_assign; }
798 | SUB_ASSIGN { $$ = ast_sub_assign; }
799 | LEFT_ASSIGN { $$ = ast_ls_assign; }
800 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
801 | AND_ASSIGN { $$ = ast_and_assign; }
802 | XOR_ASSIGN { $$ = ast_xor_assign; }
803 | OR_ASSIGN { $$ = ast_or_assign; }
807 assignment_expression
811 | expression ',' assignment_expression
814 if ($1->oper != ast_sequence) {
815 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
816 $$->set_location_range(@1, @3);
817 $$->expressions.push_tail(& $1->link);
822 $$->expressions.push_tail(& $3->link);
827 conditional_expression
831 function_prototype ';'
833 state->symbols->pop_scope();
836 | init_declarator_list ';'
840 | PRECISION precision_qualifier type_specifier ';'
842 $3->default_precision = $2;
852 function_declarator ')'
857 | function_header_with_parameters
860 function_header_with_parameters:
861 function_header parameter_declaration
864 $$->parameters.push_tail(& $2->link);
866 | function_header_with_parameters ',' parameter_declaration
869 $$->parameters.push_tail(& $3->link);
874 fully_specified_type variable_identifier '('
877 $$ = new(ctx) ast_function();
878 $$->set_location(@2);
879 $$->return_type = $1;
882 state->symbols->add_function(new(state) ir_function($2));
883 state->symbols->push_scope();
887 parameter_declarator:
888 type_specifier any_identifier
891 $$ = new(ctx) ast_parameter_declarator();
892 $$->set_location_range(@1, @2);
893 $$->type = new(ctx) ast_fully_specified_type();
894 $$->type->set_location(@1);
895 $$->type->specifier = $1;
898 | type_specifier any_identifier array_specifier
901 $$ = new(ctx) ast_parameter_declarator();
902 $$->set_location_range(@1, @3);
903 $$->type = new(ctx) ast_fully_specified_type();
904 $$->type->set_location(@1);
905 $$->type->specifier = $1;
907 $$->array_specifier = $3;
911 parameter_declaration:
912 parameter_qualifier parameter_declarator
915 $$->type->qualifier = $1;
917 | parameter_qualifier parameter_type_specifier
920 $$ = new(ctx) ast_parameter_declarator();
921 $$->set_location(@2);
922 $$->type = new(ctx) ast_fully_specified_type();
923 $$->type->set_location_range(@1, @2);
924 $$->type->qualifier = $1;
925 $$->type->specifier = $2;
932 memset(& $$, 0, sizeof($$));
934 | CONST_TOK parameter_qualifier
936 if ($2.flags.q.constant)
937 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
940 $$.flags.q.constant = 1;
942 | PRECISE parameter_qualifier
944 if ($2.flags.q.precise)
945 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
948 $$.flags.q.precise = 1;
950 | parameter_direction_qualifier parameter_qualifier
952 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
953 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
955 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
956 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
960 $$.merge_qualifier(&@1, state, $2);
962 | precision_qualifier parameter_qualifier
964 if ($2.precision != ast_precision_none)
965 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
967 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
968 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
974 parameter_direction_qualifier:
977 memset(& $$, 0, sizeof($$));
982 memset(& $$, 0, sizeof($$));
987 memset(& $$, 0, sizeof($$));
993 parameter_type_specifier:
997 init_declarator_list:
999 | init_declarator_list ',' any_identifier
1002 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1003 decl->set_location(@3);
1006 $$->declarations.push_tail(&decl->link);
1007 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1009 | init_declarator_list ',' any_identifier array_specifier
1012 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1013 decl->set_location_range(@3, @4);
1016 $$->declarations.push_tail(&decl->link);
1017 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1019 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1022 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1023 decl->set_location_range(@3, @4);
1026 $$->declarations.push_tail(&decl->link);
1027 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1029 | init_declarator_list ',' any_identifier '=' initializer
1032 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1033 decl->set_location(@3);
1036 $$->declarations.push_tail(&decl->link);
1037 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1041 // Grammar Note: No 'enum', or 'typedef'.
1043 fully_specified_type
1046 /* Empty declaration list is valid. */
1047 $$ = new(ctx) ast_declarator_list($1);
1048 $$->set_location(@1);
1050 | fully_specified_type any_identifier
1053 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1054 decl->set_location(@2);
1056 $$ = new(ctx) ast_declarator_list($1);
1057 $$->set_location_range(@1, @2);
1058 $$->declarations.push_tail(&decl->link);
1060 | fully_specified_type any_identifier array_specifier
1063 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1064 decl->set_location_range(@2, @3);
1066 $$ = new(ctx) ast_declarator_list($1);
1067 $$->set_location_range(@1, @3);
1068 $$->declarations.push_tail(&decl->link);
1070 | fully_specified_type any_identifier array_specifier '=' initializer
1073 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1074 decl->set_location_range(@2, @3);
1076 $$ = new(ctx) ast_declarator_list($1);
1077 $$->set_location_range(@1, @3);
1078 $$->declarations.push_tail(&decl->link);
1080 | fully_specified_type any_identifier '=' initializer
1083 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1084 decl->set_location(@2);
1086 $$ = new(ctx) ast_declarator_list($1);
1087 $$->set_location_range(@1, @2);
1088 $$->declarations.push_tail(&decl->link);
1090 | INVARIANT variable_identifier
1093 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1094 decl->set_location(@2);
1096 $$ = new(ctx) ast_declarator_list(NULL);
1097 $$->set_location_range(@1, @2);
1098 $$->invariant = true;
1100 $$->declarations.push_tail(&decl->link);
1102 | PRECISE variable_identifier
1105 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1106 decl->set_location(@2);
1108 $$ = new(ctx) ast_declarator_list(NULL);
1109 $$->set_location_range(@1, @2);
1112 $$->declarations.push_tail(&decl->link);
1116 fully_specified_type:
1120 $$ = new(ctx) ast_fully_specified_type();
1121 $$->set_location(@1);
1124 | type_qualifier type_specifier
1127 $$ = new(ctx) ast_fully_specified_type();
1128 $$->set_location_range(@1, @2);
1135 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1141 layout_qualifier_id_list:
1143 | layout_qualifier_id_list ',' layout_qualifier_id
1146 if (!$$.merge_qualifier(& @3, state, $3)) {
1153 INTCONSTANT { $$ = $1; }
1154 | UINTCONSTANT { $$ = $1; }
1157 layout_qualifier_id:
1160 memset(& $$, 0, sizeof($$));
1162 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1163 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1164 state->is_version(150, 0))) {
1165 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1166 $$.flags.q.origin_upper_left = 1;
1167 } else if (match_layout_qualifier($1, "pixel_center_integer",
1169 $$.flags.q.pixel_center_integer = 1;
1172 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1173 _mesa_glsl_warning(& @1, state,
1174 "GL_ARB_fragment_coord_conventions layout "
1175 "identifier `%s' used", $1);
1179 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1181 (state->AMD_conservative_depth_enable ||
1182 state->ARB_conservative_depth_enable)) {
1183 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1184 $$.flags.q.depth_any = 1;
1185 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1186 $$.flags.q.depth_greater = 1;
1187 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1188 $$.flags.q.depth_less = 1;
1189 } else if (match_layout_qualifier($1, "depth_unchanged",
1191 $$.flags.q.depth_unchanged = 1;
1194 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1195 _mesa_glsl_warning(& @1, state,
1196 "GL_AMD_conservative_depth "
1197 "layout qualifier `%s' is used", $1);
1199 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1200 _mesa_glsl_warning(& @1, state,
1201 "GL_ARB_conservative_depth "
1202 "layout qualifier `%s' is used", $1);
1206 /* See also interface_block_layout_qualifier. */
1207 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1208 if (match_layout_qualifier($1, "std140", state) == 0) {
1209 $$.flags.q.std140 = 1;
1210 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1211 $$.flags.q.shared = 1;
1212 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1213 $$.flags.q.column_major = 1;
1214 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1215 * below in the interface_block_layout_qualifier rule.
1217 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1220 * Also, this takes care of alternate capitalizations of
1221 * "row_major" (which is necessary because layout qualifiers
1222 * are case-insensitive in desktop GLSL).
1224 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1225 $$.flags.q.row_major = 1;
1226 /* "packed" is a reserved word in GLSL, and its token is
1227 * parsed below in the interface_block_layout_qualifier rule.
1228 * However, we must take care of alternate capitalizations of
1229 * "packed", because layout qualifiers are case-insensitive
1232 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1233 $$.flags.q.packed = 1;
1236 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1237 _mesa_glsl_warning(& @1, state,
1238 "#version 140 / GL_ARB_uniform_buffer_object "
1239 "layout qualifier `%s' is used", $1);
1243 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1245 static const struct {
1249 { "points", GL_POINTS },
1250 { "lines", GL_LINES },
1251 { "lines_adjacency", GL_LINES_ADJACENCY },
1252 { "line_strip", GL_LINE_STRIP },
1253 { "triangles", GL_TRIANGLES },
1254 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1255 { "triangle_strip", GL_TRIANGLE_STRIP },
1257 for (unsigned i = 0; i < Elements(map); i++) {
1258 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1259 $$.flags.q.prim_type = 1;
1260 $$.prim_type = map[i].e;
1265 if ($$.flags.i && !state->is_version(150, 0)) {
1266 _mesa_glsl_error(& @1, state, "#version 150 layout "
1267 "qualifier `%s' used", $1);
1271 /* Layout qualifiers for ARB_shader_image_load_store. */
1272 if (state->ARB_shader_image_load_store_enable ||
1273 state->is_version(420, 0)) {
1275 static const struct {
1278 glsl_base_type base_type;
1280 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT },
1281 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT },
1282 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT },
1283 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT },
1284 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT },
1285 { "r32f", GL_R32F, GLSL_TYPE_FLOAT },
1286 { "r16f", GL_R16F, GLSL_TYPE_FLOAT },
1287 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT },
1288 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT },
1289 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT },
1290 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT },
1291 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT },
1292 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT },
1293 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT },
1294 { "r32ui", GL_R32UI, GLSL_TYPE_UINT },
1295 { "r16ui", GL_R16UI, GLSL_TYPE_UINT },
1296 { "r8ui", GL_R8UI, GLSL_TYPE_UINT },
1297 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT },
1298 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT },
1299 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT },
1300 { "rg32i", GL_RG32I, GLSL_TYPE_INT },
1301 { "rg16i", GL_RG16I, GLSL_TYPE_INT },
1302 { "rg8i", GL_RG8I, GLSL_TYPE_INT },
1303 { "r32i", GL_R32I, GLSL_TYPE_INT },
1304 { "r16i", GL_R16I, GLSL_TYPE_INT },
1305 { "r8i", GL_R8I, GLSL_TYPE_INT },
1306 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT },
1307 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT },
1308 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT },
1309 { "rg16", GL_RG16, GLSL_TYPE_FLOAT },
1310 { "rg8", GL_RG8, GLSL_TYPE_FLOAT },
1311 { "r16", GL_R16, GLSL_TYPE_FLOAT },
1312 { "r8", GL_R8, GLSL_TYPE_FLOAT },
1313 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT },
1314 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT },
1315 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT },
1316 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT },
1317 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT },
1318 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT }
1321 for (unsigned i = 0; i < Elements(map); i++) {
1322 if (match_layout_qualifier($1, map[i].name, state) == 0) {
1323 $$.flags.q.explicit_image_format = 1;
1324 $$.image_format = map[i].format;
1325 $$.image_base_type = map[i].base_type;
1332 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1333 $$.flags.q.early_fragment_tests = 1;
1338 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1343 | any_identifier '=' integer_constant
1345 memset(& $$, 0, sizeof($$));
1347 if (match_layout_qualifier("location", $1, state) == 0) {
1348 $$.flags.q.explicit_location = 1;
1350 if ($$.flags.q.attribute == 1 &&
1351 state->ARB_explicit_attrib_location_warn) {
1352 _mesa_glsl_warning(& @1, state,
1353 "GL_ARB_explicit_attrib_location layout "
1354 "identifier `%s' used", $1);
1360 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1365 if (match_layout_qualifier("index", $1, state) == 0) {
1366 $$.flags.q.explicit_index = 1;
1371 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1376 if ((state->ARB_shading_language_420pack_enable ||
1377 state->ARB_shader_atomic_counters_enable) &&
1378 match_layout_qualifier("binding", $1, state) == 0) {
1379 $$.flags.q.explicit_binding = 1;
1383 if (state->ARB_shader_atomic_counters_enable &&
1384 match_layout_qualifier("offset", $1, state) == 0) {
1385 $$.flags.q.explicit_offset = 1;
1389 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1390 $$.flags.q.max_vertices = 1;
1393 _mesa_glsl_error(& @3, state,
1394 "invalid max_vertices %d specified", $3);
1397 $$.max_vertices = $3;
1398 if (!state->is_version(150, 0)) {
1399 _mesa_glsl_error(& @3, state,
1400 "#version 150 max_vertices qualifier "
1406 if (state->stage == MESA_SHADER_GEOMETRY) {
1407 if (match_layout_qualifier("stream", $1, state) == 0 &&
1408 state->check_explicit_attrib_stream_allowed(& @3)) {
1409 $$.flags.q.stream = 1;
1412 _mesa_glsl_error(& @3, state,
1413 "invalid stream %d specified", $3);
1416 $$.flags.q.explicit_stream = 1;
1422 static const char * const local_size_qualifiers[3] = {
1427 for (int i = 0; i < 3; i++) {
1428 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1431 _mesa_glsl_error(& @3, state,
1432 "invalid %s of %d specified",
1433 local_size_qualifiers[i], $3);
1435 } else if (!state->is_version(430, 0) &&
1436 !state->ARB_compute_shader_enable) {
1437 _mesa_glsl_error(& @3, state,
1438 "%s qualifier requires GLSL 4.30 or "
1439 "ARB_compute_shader",
1440 local_size_qualifiers[i]);
1443 $$.flags.q.local_size |= (1 << i);
1444 $$.local_size[i] = $3;
1450 if (match_layout_qualifier("invocations", $1, state) == 0) {
1451 $$.flags.q.invocations = 1;
1454 _mesa_glsl_error(& @3, state,
1455 "invalid invocations %d specified", $3);
1457 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1458 _mesa_glsl_error(& @3, state,
1459 "invocations (%d) exceeds "
1460 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1463 $$.invocations = $3;
1464 if (!state->is_version(400, 0) &&
1465 !state->ARB_gpu_shader5_enable) {
1466 _mesa_glsl_error(& @3, state,
1467 "GL_ARB_gpu_shader5 invocations "
1468 "qualifier specified", $3);
1473 /* If the identifier didn't match any known layout identifiers,
1477 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1482 | interface_block_layout_qualifier
1485 /* Layout qualifiers for ARB_uniform_buffer_object. */
1486 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1487 _mesa_glsl_error(& @1, state,
1488 "#version 140 / GL_ARB_uniform_buffer_object "
1489 "layout qualifier `%s' is used", $1);
1490 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1491 _mesa_glsl_warning(& @1, state,
1492 "#version 140 / GL_ARB_uniform_buffer_object "
1493 "layout qualifier `%s' is used", $1);
1498 /* This is a separate language rule because we parse these as tokens
1499 * (due to them being reserved keywords) instead of identifiers like
1500 * most qualifiers. See the any_identifier path of
1501 * layout_qualifier_id for the others.
1503 * Note that since layout qualifiers are case-insensitive in desktop
1504 * GLSL, all of these qualifiers need to be handled as identifiers as
1505 * well (by the any_identifier path of layout_qualifier_id).
1507 interface_block_layout_qualifier:
1510 memset(& $$, 0, sizeof($$));
1511 $$.flags.q.row_major = 1;
1515 memset(& $$, 0, sizeof($$));
1516 $$.flags.q.packed = 1;
1520 interpolation_qualifier:
1523 memset(& $$, 0, sizeof($$));
1524 $$.flags.q.smooth = 1;
1528 memset(& $$, 0, sizeof($$));
1529 $$.flags.q.flat = 1;
1533 memset(& $$, 0, sizeof($$));
1534 $$.flags.q.noperspective = 1;
1539 /* Single qualifiers */
1542 memset(& $$, 0, sizeof($$));
1543 $$.flags.q.invariant = 1;
1547 memset(& $$, 0, sizeof($$));
1548 $$.flags.q.precise = 1;
1550 | auxiliary_storage_qualifier
1552 | interpolation_qualifier
1554 | precision_qualifier
1556 memset(&$$, 0, sizeof($$));
1560 /* Multiple qualifiers:
1561 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1562 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1564 * invariant interpolation auxiliary storage precision ...or...
1565 * layout storage precision
1567 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1568 * side don't contain any that must appear on the left hand side.
1569 * For example, when processing a storage qualifier, we check that there are
1570 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1572 | PRECISE type_qualifier
1574 if ($2.flags.q.precise)
1575 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1578 $$.flags.q.precise = 1;
1580 | INVARIANT type_qualifier
1582 if ($2.flags.q.invariant)
1583 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1585 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.precise)
1586 _mesa_glsl_error(&@1, state,
1587 "\"invariant\" must come after \"precise\"");
1590 $$.flags.q.invariant = 1;
1592 | interpolation_qualifier type_qualifier
1594 /* Section 4.3 of the GLSL 1.40 specification states:
1595 * "...qualified with one of these interpolation qualifiers"
1597 * GLSL 1.30 claims to allow "one or more", but insists that:
1598 * "These interpolation qualifiers may only precede the qualifiers in,
1599 * centroid in, out, or centroid out in a declaration."
1601 * ...which means that e.g. smooth can't precede smooth, so there can be
1602 * only one after all, and the 1.40 text is a clarification, not a change.
1604 if ($2.has_interpolation())
1605 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1607 if (!state->ARB_shading_language_420pack_enable &&
1608 ($2.flags.q.precise || $2.flags.q.invariant)) {
1609 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1610 "after \"precise\" or \"invariant\"");
1614 $$.merge_qualifier(&@1, state, $2);
1616 | layout_qualifier type_qualifier
1618 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1619 * appear no later than auxiliary storage qualifiers. There is no
1620 * particularly clear spec language mandating this, but in all examples
1621 * the layout qualifier precedes the storage qualifier.
1623 * We allow combinations of layout with interpolation, invariant or
1624 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1625 * There is no clear spec guidance on this either.
1627 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1628 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1631 $$.merge_qualifier(&@1, state, $2);
1633 | auxiliary_storage_qualifier type_qualifier
1635 if ($2.has_auxiliary_storage()) {
1636 _mesa_glsl_error(&@1, state,
1637 "duplicate auxiliary storage qualifier (centroid or sample)");
1640 if (!state->ARB_shading_language_420pack_enable &&
1641 ($2.flags.q.precise || $2.flags.q.invariant ||
1642 $2.has_interpolation() || $2.has_layout())) {
1643 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1644 "just before storage qualifiers");
1647 $$.merge_qualifier(&@1, state, $2);
1649 | storage_qualifier type_qualifier
1651 /* Section 4.3 of the GLSL 1.20 specification states:
1652 * "Variable declarations may have a storage qualifier specified..."
1653 * 1.30 clarifies this to "may have one storage qualifier".
1655 if ($2.has_storage())
1656 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1658 if (!state->ARB_shading_language_420pack_enable &&
1659 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1660 $2.has_layout() || $2.has_auxiliary_storage())) {
1661 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1662 "precise, invariant, interpolation, layout and auxiliary "
1663 "storage qualifiers");
1667 $$.merge_qualifier(&@1, state, $2);
1669 | precision_qualifier type_qualifier
1671 if ($2.precision != ast_precision_none)
1672 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1674 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1675 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1682 auxiliary_storage_qualifier:
1685 memset(& $$, 0, sizeof($$));
1686 $$.flags.q.centroid = 1;
1690 memset(& $$, 0, sizeof($$));
1691 $$.flags.q.sample = 1;
1693 /* TODO: "patch" also goes here someday. */
1698 memset(& $$, 0, sizeof($$));
1699 $$.flags.q.constant = 1;
1703 memset(& $$, 0, sizeof($$));
1704 $$.flags.q.attribute = 1;
1708 memset(& $$, 0, sizeof($$));
1709 $$.flags.q.varying = 1;
1713 memset(& $$, 0, sizeof($$));
1718 memset(& $$, 0, sizeof($$));
1721 if (state->stage == MESA_SHADER_GEOMETRY &&
1722 state->has_explicit_attrib_stream()) {
1723 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1726 * "If the block or variable is declared with the stream
1727 * identifier, it is associated with the specified stream;
1728 * otherwise, it is associated with the current default stream."
1730 $$.flags.q.stream = 1;
1731 $$.flags.q.explicit_stream = 0;
1732 $$.stream = state->out_qualifier->stream;
1737 memset(& $$, 0, sizeof($$));
1738 $$.flags.q.uniform = 1;
1742 memset(& $$, 0, sizeof($$));
1743 $$.flags.q.coherent = 1;
1747 memset(& $$, 0, sizeof($$));
1748 $$.flags.q._volatile = 1;
1752 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1753 memset(& $$, 0, sizeof($$));
1754 $$.flags.q.restrict_flag = 1;
1758 memset(& $$, 0, sizeof($$));
1759 $$.flags.q.read_only = 1;
1763 memset(& $$, 0, sizeof($$));
1764 $$.flags.q.write_only = 1;
1772 $$ = new(ctx) ast_array_specifier(@1);
1773 $$->set_location_range(@1, @2);
1775 | '[' constant_expression ']'
1778 $$ = new(ctx) ast_array_specifier(@1, $2);
1779 $$->set_location_range(@1, @3);
1781 | array_specifier '[' ']'
1785 if (!state->ARB_arrays_of_arrays_enable) {
1786 _mesa_glsl_error(& @1, state,
1787 "GL_ARB_arrays_of_arrays "
1788 "required for defining arrays of arrays");
1790 _mesa_glsl_error(& @1, state,
1791 "only the outermost array dimension can "
1795 | array_specifier '[' constant_expression ']'
1799 if (!state->ARB_arrays_of_arrays_enable) {
1800 _mesa_glsl_error(& @1, state,
1801 "GL_ARB_arrays_of_arrays "
1802 "required for defining arrays of arrays");
1805 $$->add_dimension($3);
1810 type_specifier_nonarray
1811 | type_specifier_nonarray array_specifier
1814 $$->array_specifier = $2;
1818 type_specifier_nonarray:
1819 basic_type_specifier_nonarray
1822 $$ = new(ctx) ast_type_specifier($1);
1823 $$->set_location(@1);
1828 $$ = new(ctx) ast_type_specifier($1);
1829 $$->set_location(@1);
1834 $$ = new(ctx) ast_type_specifier($1);
1835 $$->set_location(@1);
1839 basic_type_specifier_nonarray:
1840 VOID_TOK { $$ = "void"; }
1841 | FLOAT_TOK { $$ = "float"; }
1842 | INT_TOK { $$ = "int"; }
1843 | UINT_TOK { $$ = "uint"; }
1844 | BOOL_TOK { $$ = "bool"; }
1845 | VEC2 { $$ = "vec2"; }
1846 | VEC3 { $$ = "vec3"; }
1847 | VEC4 { $$ = "vec4"; }
1848 | BVEC2 { $$ = "bvec2"; }
1849 | BVEC3 { $$ = "bvec3"; }
1850 | BVEC4 { $$ = "bvec4"; }
1851 | IVEC2 { $$ = "ivec2"; }
1852 | IVEC3 { $$ = "ivec3"; }
1853 | IVEC4 { $$ = "ivec4"; }
1854 | UVEC2 { $$ = "uvec2"; }
1855 | UVEC3 { $$ = "uvec3"; }
1856 | UVEC4 { $$ = "uvec4"; }
1857 | MAT2X2 { $$ = "mat2"; }
1858 | MAT2X3 { $$ = "mat2x3"; }
1859 | MAT2X4 { $$ = "mat2x4"; }
1860 | MAT3X2 { $$ = "mat3x2"; }
1861 | MAT3X3 { $$ = "mat3"; }
1862 | MAT3X4 { $$ = "mat3x4"; }
1863 | MAT4X2 { $$ = "mat4x2"; }
1864 | MAT4X3 { $$ = "mat4x3"; }
1865 | MAT4X4 { $$ = "mat4"; }
1866 | SAMPLER1D { $$ = "sampler1D"; }
1867 | SAMPLER2D { $$ = "sampler2D"; }
1868 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1869 | SAMPLER3D { $$ = "sampler3D"; }
1870 | SAMPLERCUBE { $$ = "samplerCube"; }
1871 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1872 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1873 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1874 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1875 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1876 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1877 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1878 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1879 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1880 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1881 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1882 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1883 | ISAMPLER1D { $$ = "isampler1D"; }
1884 | ISAMPLER2D { $$ = "isampler2D"; }
1885 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1886 | ISAMPLER3D { $$ = "isampler3D"; }
1887 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1888 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1889 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1890 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1891 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1892 | USAMPLER1D { $$ = "usampler1D"; }
1893 | USAMPLER2D { $$ = "usampler2D"; }
1894 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1895 | USAMPLER3D { $$ = "usampler3D"; }
1896 | USAMPLERCUBE { $$ = "usamplerCube"; }
1897 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1898 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1899 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1900 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1901 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1902 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1903 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1904 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1905 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1906 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1907 | IMAGE1D { $$ = "image1D"; }
1908 | IMAGE2D { $$ = "image2D"; }
1909 | IMAGE3D { $$ = "image3D"; }
1910 | IMAGE2DRECT { $$ = "image2DRect"; }
1911 | IMAGECUBE { $$ = "imageCube"; }
1912 | IMAGEBUFFER { $$ = "imageBuffer"; }
1913 | IMAGE1DARRAY { $$ = "image1DArray"; }
1914 | IMAGE2DARRAY { $$ = "image2DArray"; }
1915 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
1916 | IMAGE2DMS { $$ = "image2DMS"; }
1917 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
1918 | IIMAGE1D { $$ = "iimage1D"; }
1919 | IIMAGE2D { $$ = "iimage2D"; }
1920 | IIMAGE3D { $$ = "iimage3D"; }
1921 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
1922 | IIMAGECUBE { $$ = "iimageCube"; }
1923 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
1924 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
1925 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
1926 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
1927 | IIMAGE2DMS { $$ = "iimage2DMS"; }
1928 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
1929 | UIMAGE1D { $$ = "uimage1D"; }
1930 | UIMAGE2D { $$ = "uimage2D"; }
1931 | UIMAGE3D { $$ = "uimage3D"; }
1932 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
1933 | UIMAGECUBE { $$ = "uimageCube"; }
1934 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
1935 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
1936 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
1937 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
1938 | UIMAGE2DMS { $$ = "uimage2DMS"; }
1939 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
1940 | ATOMIC_UINT { $$ = "atomic_uint"; }
1943 precision_qualifier:
1946 state->check_precision_qualifiers_allowed(&@1);
1947 $$ = ast_precision_high;
1951 state->check_precision_qualifiers_allowed(&@1);
1952 $$ = ast_precision_medium;
1956 state->check_precision_qualifiers_allowed(&@1);
1957 $$ = ast_precision_low;
1962 STRUCT any_identifier '{' struct_declaration_list '}'
1965 $$ = new(ctx) ast_struct_specifier($2, $4);
1966 $$->set_location_range(@2, @5);
1967 state->symbols->add_type($2, glsl_type::void_type);
1969 | STRUCT '{' struct_declaration_list '}'
1972 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1973 $$->set_location_range(@2, @4);
1977 struct_declaration_list:
1981 $1->link.self_link();
1983 | struct_declaration_list struct_declaration
1986 $$->link.insert_before(& $2->link);
1991 fully_specified_type struct_declarator_list ';'
1994 ast_fully_specified_type *const type = $1;
1995 type->set_location(@1);
1997 if (type->qualifier.flags.i != 0)
1998 _mesa_glsl_error(&@1, state,
1999 "only precision qualifiers may be applied to "
2000 "structure members");
2002 $$ = new(ctx) ast_declarator_list(type);
2003 $$->set_location(@2);
2005 $$->declarations.push_degenerate_list_at_head(& $2->link);
2009 struct_declarator_list:
2013 $1->link.self_link();
2015 | struct_declarator_list ',' struct_declarator
2018 $$->link.insert_before(& $3->link);
2026 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2027 $$->set_location(@1);
2029 | any_identifier array_specifier
2032 $$ = new(ctx) ast_declaration($1, $2, NULL);
2033 $$->set_location_range(@1, @2);
2038 assignment_expression
2039 | '{' initializer_list '}'
2043 | '{' initializer_list ',' '}'
2053 $$ = new(ctx) ast_aggregate_initializer();
2054 $$->set_location(@1);
2055 $$->expressions.push_tail(& $1->link);
2057 | initializer_list ',' initializer
2059 $1->expressions.push_tail(& $3->link);
2063 declaration_statement:
2067 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2070 compound_statement { $$ = (ast_node *) $1; }
2075 declaration_statement
2076 | expression_statement
2077 | selection_statement
2079 | iteration_statement
2087 $$ = new(ctx) ast_compound_statement(true, NULL);
2088 $$->set_location_range(@1, @2);
2092 state->symbols->push_scope();
2097 $$ = new(ctx) ast_compound_statement(true, $3);
2098 $$->set_location_range(@1, @4);
2099 state->symbols->pop_scope();
2103 statement_no_new_scope:
2104 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2108 compound_statement_no_new_scope:
2112 $$ = new(ctx) ast_compound_statement(false, NULL);
2113 $$->set_location_range(@1, @2);
2115 | '{' statement_list '}'
2118 $$ = new(ctx) ast_compound_statement(false, $2);
2119 $$->set_location_range(@1, @3);
2127 _mesa_glsl_error(& @1, state, "<nil> statement");
2132 $$->link.self_link();
2134 | statement_list statement
2137 _mesa_glsl_error(& @2, state, "<nil> statement");
2141 $$->link.insert_before(& $2->link);
2145 expression_statement:
2149 $$ = new(ctx) ast_expression_statement(NULL);
2150 $$->set_location(@1);
2155 $$ = new(ctx) ast_expression_statement($1);
2156 $$->set_location(@1);
2160 selection_statement:
2161 IF '(' expression ')' selection_rest_statement
2163 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2165 $$->set_location_range(@1, @5);
2169 selection_rest_statement:
2170 statement ELSE statement
2172 $$.then_statement = $1;
2173 $$.else_statement = $3;
2175 | statement %prec THEN
2177 $$.then_statement = $1;
2178 $$.else_statement = NULL;
2185 $$ = (ast_node *) $1;
2187 | fully_specified_type any_identifier '=' initializer
2190 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2191 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2192 decl->set_location_range(@2, @4);
2193 declarator->set_location(@1);
2195 declarator->declarations.push_tail(&decl->link);
2201 * switch_statement grammar is based on the syntax described in the body
2202 * of the GLSL spec, not in it's appendix!!!
2205 SWITCH '(' expression ')' switch_body
2207 $$ = new(state) ast_switch_statement($3, $5);
2208 $$->set_location_range(@1, @5);
2215 $$ = new(state) ast_switch_body(NULL);
2216 $$->set_location_range(@1, @2);
2218 | '{' case_statement_list '}'
2220 $$ = new(state) ast_switch_body($2);
2221 $$->set_location_range(@1, @3);
2228 $$ = new(state) ast_case_label($2);
2229 $$->set_location(@2);
2233 $$ = new(state) ast_case_label(NULL);
2234 $$->set_location(@2);
2241 ast_case_label_list *labels = new(state) ast_case_label_list();
2243 labels->labels.push_tail(& $1->link);
2245 $$->set_location(@1);
2247 | case_label_list case_label
2250 $$->labels.push_tail(& $2->link);
2255 case_label_list statement
2257 ast_case_statement *stmts = new(state) ast_case_statement($1);
2258 stmts->set_location(@2);
2260 stmts->stmts.push_tail(& $2->link);
2263 | case_statement statement
2266 $$->stmts.push_tail(& $2->link);
2270 case_statement_list:
2273 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2274 cases->set_location(@1);
2276 cases->cases.push_tail(& $1->link);
2279 | case_statement_list case_statement
2282 $$->cases.push_tail(& $2->link);
2286 iteration_statement:
2287 WHILE '(' condition ')' statement_no_new_scope
2290 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2291 NULL, $3, NULL, $5);
2292 $$->set_location_range(@1, @4);
2294 | DO statement WHILE '(' expression ')' ';'
2297 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2298 NULL, $5, NULL, $2);
2299 $$->set_location_range(@1, @6);
2301 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2304 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2305 $3, $4.cond, $4.rest, $6);
2306 $$->set_location_range(@1, @6);
2311 expression_statement
2312 | declaration_statement
2329 | conditionopt ';' expression
2336 // Grammar Note: No 'goto'. Gotos are not supported.
2341 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2342 $$->set_location(@1);
2347 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2348 $$->set_location(@1);
2353 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2354 $$->set_location(@1);
2356 | RETURN expression ';'
2359 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2360 $$->set_location_range(@1, @2);
2362 | DISCARD ';' // Fragment shader only.
2365 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2366 $$->set_location(@1);
2370 external_declaration:
2371 function_definition { $$ = $1; }
2372 | declaration { $$ = $1; }
2373 | pragma_statement { $$ = NULL; }
2374 | layout_defaults { $$ = $1; }
2377 function_definition:
2378 function_prototype compound_statement_no_new_scope
2381 $$ = new(ctx) ast_function_definition();
2382 $$->set_location_range(@1, @2);
2386 state->symbols->pop_scope();
2390 /* layout_qualifieropt is packed into this rule */
2392 basic_interface_block
2396 | layout_qualifier basic_interface_block
2398 ast_interface_block *block = $2;
2399 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2403 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2404 ast_type_qualifier& qualifier = member->type->qualifier;
2405 if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) {
2406 _mesa_glsl_error(& @1, state,
2407 "stream layout qualifier on "
2408 "interface block member does not match "
2409 "the interface block (%d vs %d)",
2410 qualifier.stream, block->layout.stream);
2418 basic_interface_block:
2419 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2421 ast_interface_block *const block = $6;
2423 block->block_name = $2;
2424 block->declarations.push_degenerate_list_at_head(& $4->link);
2426 if ($1.flags.q.uniform) {
2427 if (!state->has_uniform_buffer_objects()) {
2428 _mesa_glsl_error(& @1, state,
2429 "#version 140 / GL_ARB_uniform_buffer_object "
2430 "required for defining uniform blocks");
2431 } else if (state->ARB_uniform_buffer_object_warn) {
2432 _mesa_glsl_warning(& @1, state,
2433 "#version 140 / GL_ARB_uniform_buffer_object "
2434 "required for defining uniform blocks");
2437 if (state->es_shader || state->language_version < 150) {
2438 _mesa_glsl_error(& @1, state,
2439 "#version 150 required for using "
2440 "interface blocks");
2444 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2445 * "It is illegal to have an input block in a vertex shader
2446 * or an output block in a fragment shader"
2448 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2449 _mesa_glsl_error(& @1, state,
2450 "`in' interface block is not allowed for "
2452 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2453 _mesa_glsl_error(& @1, state,
2454 "`out' interface block is not allowed for "
2455 "a fragment shader");
2458 /* Since block arrays require names, and both features are added in
2459 * the same language versions, we don't have to explicitly
2460 * version-check both things.
2462 if (block->instance_name != NULL) {
2463 state->check_version(150, 300, & @1, "interface blocks with "
2464 "an instance name are not allowed");
2467 uint64_t interface_type_mask;
2468 struct ast_type_qualifier temp_type_qualifier;
2470 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2471 * to ignore other irrelevant flags like interpolation qualifiers.
2473 temp_type_qualifier.flags.i = 0;
2474 temp_type_qualifier.flags.q.uniform = true;
2475 temp_type_qualifier.flags.q.in = true;
2476 temp_type_qualifier.flags.q.out = true;
2477 interface_type_mask = temp_type_qualifier.flags.i;
2479 /* Get the block's interface qualifier. The interface_qualifier
2480 * production rule guarantees that only one bit will be set (and
2481 * it will be in/out/uniform).
2483 uint64_t block_interface_qualifier = $1.flags.i;
2485 block->layout.flags.i |= block_interface_qualifier;
2487 if (state->stage == MESA_SHADER_GEOMETRY &&
2488 state->has_explicit_attrib_stream()) {
2489 /* Assign global layout's stream value. */
2490 block->layout.flags.q.stream = 1;
2491 block->layout.flags.q.explicit_stream = 0;
2492 block->layout.stream = state->out_qualifier->stream;
2495 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2496 ast_type_qualifier& qualifier = member->type->qualifier;
2497 if ((qualifier.flags.i & interface_type_mask) == 0) {
2498 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2499 * "If no optional qualifier is used in a member declaration, the
2500 * qualifier of the variable is just in, out, or uniform as declared
2501 * by interface-qualifier."
2503 qualifier.flags.i |= block_interface_qualifier;
2504 } else if ((qualifier.flags.i & interface_type_mask) !=
2505 block_interface_qualifier) {
2506 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2507 * "If optional qualifiers are used, they can include interpolation
2508 * and storage qualifiers and they must declare an input, output,
2509 * or uniform variable consistent with the interface qualifier of
2512 _mesa_glsl_error(& @1, state,
2513 "uniform/in/out qualifier on "
2514 "interface block member does not match "
2515 "the interface block");
2523 interface_qualifier:
2526 memset(& $$, 0, sizeof($$));
2531 memset(& $$, 0, sizeof($$));
2536 memset(& $$, 0, sizeof($$));
2537 $$.flags.q.uniform = 1;
2544 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2549 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2551 $$->set_location(@1);
2553 | NEW_IDENTIFIER array_specifier
2555 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2557 $$->set_location_range(@1, @2);
2565 $1->link.self_link();
2567 | member_declaration member_list
2570 $2->link.insert_before(& $$->link);
2575 fully_specified_type struct_declarator_list ';'
2578 ast_fully_specified_type *type = $1;
2579 type->set_location(@1);
2581 if (type->qualifier.flags.q.attribute) {
2582 _mesa_glsl_error(& @1, state,
2583 "keyword 'attribute' cannot be used with "
2584 "interface block member");
2585 } else if (type->qualifier.flags.q.varying) {
2586 _mesa_glsl_error(& @1, state,
2587 "keyword 'varying' cannot be used with "
2588 "interface block member");
2591 $$ = new(ctx) ast_declarator_list(type);
2592 $$->set_location(@2);
2594 $$->declarations.push_degenerate_list_at_head(& $2->link);
2599 layout_qualifier UNIFORM ';'
2601 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2607 | layout_qualifier IN_TOK ';'
2610 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2615 | layout_qualifier OUT_TOK ';'
2617 if (state->stage != MESA_SHADER_GEOMETRY) {
2618 _mesa_glsl_error(& @1, state,
2619 "out layout qualifiers only valid in "
2620 "geometry shaders");
2622 if ($1.flags.q.prim_type) {
2623 /* Make sure this is a valid output primitive type. */
2624 switch ($1.prim_type) {
2627 case GL_TRIANGLE_STRIP:
2630 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2635 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))
2638 /* Allow future assigments of global out's stream id value */
2639 state->out_qualifier->flags.q.explicit_stream = 0;