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 "compiler/glsl_types.h"
35 #include "main/context.h"
36 #include "util/u_string.h"
39 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
44 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
46 _mesa_glsl_error(loc, st, "%s", msg);
50 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
52 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
55 static bool match_layout_qualifier(const char *s1, const char *s2,
56 _mesa_glsl_parse_state *state)
58 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
60 * "The tokens in any layout-qualifier-id-list ... are not case
61 * sensitive, unless explicitly noted otherwise."
63 * The text "unless explicitly noted otherwise" appears to be
64 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
67 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
70 * "As for other identifiers, they are case sensitive."
72 * So we need to do a case-sensitive or a case-insensitive match,
73 * depending on whether we are compiling for GLSL ES.
76 return strcmp(s1, s2);
78 return strcasecmp(s1, s2);
96 %lex-param {struct _mesa_glsl_parse_state *state}
97 %parse-param {struct _mesa_glsl_parse_state *state}
104 const char *identifier;
106 struct ast_type_qualifier type_qualifier;
109 ast_type_specifier *type_specifier;
110 ast_array_specifier *array_specifier;
111 ast_fully_specified_type *fully_specified_type;
112 ast_function *function;
113 ast_parameter_declarator *parameter_declarator;
114 ast_function_definition *function_definition;
115 ast_compound_statement *compound_statement;
116 ast_expression *expression;
117 ast_declarator_list *declarator_list;
118 ast_struct_specifier *struct_specifier;
119 ast_declaration *declaration;
120 ast_switch_body *switch_body;
121 ast_case_label *case_label;
122 ast_case_label_list *case_label_list;
123 ast_case_statement *case_statement;
124 ast_case_statement_list *case_statement_list;
125 ast_interface_block *interface_block;
126 ast_subroutine_list *subroutine_list;
129 ast_expression *rest;
130 } for_rest_statement;
133 ast_node *then_statement;
134 ast_node *else_statement;
135 } selection_rest_statement;
137 const glsl_type *type;
140 %token ATTRIBUTE CONST_TOK
141 %token <type> BASIC_TYPE_TOK
142 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
143 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
144 %token NOPERSPECTIVE FLAT SMOOTH
145 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
146 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
148 %token STRUCT VOID_TOK WHILE
149 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
150 %type <identifier> any_identifier
151 %type <interface_block> instance_name_opt
152 %token <real> FLOATCONSTANT
153 %token <dreal> DOUBLECONSTANT
154 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
155 %token <n64> INT64CONSTANT UINT64CONSTANT
156 %token <identifier> FIELD_SELECTION
157 %token LEFT_OP RIGHT_OP
158 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
159 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
160 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
162 %token INVARIANT PRECISE
163 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
165 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
166 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
167 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
168 %token PRAGMA_WARNING_ON PRAGMA_WARNING_OFF
169 %token PRAGMA_INVARIANT_ALL
172 /* Reserved words that are not actually used in the grammar.
174 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
175 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
176 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
177 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
179 %token SIZEOF CAST NAMESPACE USING
180 %token RESOURCE PATCH
185 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
187 %type <identifier> variable_identifier
188 %type <node> statement
189 %type <node> statement_list
190 %type <node> simple_statement
191 %type <n> precision_qualifier
192 %type <type_qualifier> type_qualifier
193 %type <type_qualifier> auxiliary_storage_qualifier
194 %type <type_qualifier> storage_qualifier
195 %type <type_qualifier> interpolation_qualifier
196 %type <type_qualifier> layout_qualifier
197 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
198 %type <type_qualifier> interface_block_layout_qualifier
199 %type <type_qualifier> memory_qualifier
200 %type <type_qualifier> subroutine_qualifier
201 %type <subroutine_list> subroutine_type_list
202 %type <type_qualifier> interface_qualifier
203 %type <type_specifier> type_specifier
204 %type <type_specifier> type_specifier_nonarray
205 %type <array_specifier> array_specifier
206 %type <type> basic_type_specifier_nonarray
207 %type <fully_specified_type> fully_specified_type
208 %type <function> function_prototype
209 %type <function> function_header
210 %type <function> function_header_with_parameters
211 %type <function> function_declarator
212 %type <parameter_declarator> parameter_declarator
213 %type <parameter_declarator> parameter_declaration
214 %type <type_qualifier> parameter_qualifier
215 %type <type_qualifier> parameter_direction_qualifier
216 %type <type_specifier> parameter_type_specifier
217 %type <function_definition> function_definition
218 %type <compound_statement> compound_statement_no_new_scope
219 %type <compound_statement> compound_statement
220 %type <node> statement_no_new_scope
221 %type <node> expression_statement
222 %type <expression> expression
223 %type <expression> primary_expression
224 %type <expression> assignment_expression
225 %type <expression> conditional_expression
226 %type <expression> logical_or_expression
227 %type <expression> logical_xor_expression
228 %type <expression> logical_and_expression
229 %type <expression> inclusive_or_expression
230 %type <expression> exclusive_or_expression
231 %type <expression> and_expression
232 %type <expression> equality_expression
233 %type <expression> relational_expression
234 %type <expression> shift_expression
235 %type <expression> additive_expression
236 %type <expression> multiplicative_expression
237 %type <expression> unary_expression
238 %type <expression> constant_expression
239 %type <expression> integer_expression
240 %type <expression> postfix_expression
241 %type <expression> function_call_header_with_parameters
242 %type <expression> function_call_header_no_parameters
243 %type <expression> function_call_header
244 %type <expression> function_call_generic
245 %type <expression> function_call_or_method
246 %type <expression> function_call
247 %type <n> assignment_operator
248 %type <n> unary_operator
249 %type <expression> function_identifier
250 %type <node> external_declaration
251 %type <node> pragma_statement
252 %type <declarator_list> init_declarator_list
253 %type <declarator_list> single_declaration
254 %type <expression> initializer
255 %type <expression> initializer_list
256 %type <node> declaration
257 %type <node> declaration_statement
258 %type <node> jump_statement
259 %type <node> interface_block
260 %type <interface_block> basic_interface_block
261 %type <struct_specifier> struct_specifier
262 %type <declarator_list> struct_declaration_list
263 %type <declarator_list> struct_declaration
264 %type <declaration> struct_declarator
265 %type <declaration> struct_declarator_list
266 %type <declarator_list> member_list
267 %type <declarator_list> member_declaration
268 %type <node> selection_statement
269 %type <selection_rest_statement> selection_rest_statement
270 %type <node> switch_statement
271 %type <switch_body> switch_body
272 %type <case_label_list> case_label_list
273 %type <case_label> case_label
274 %type <case_statement> case_statement
275 %type <case_statement_list> case_statement_list
276 %type <node> iteration_statement
277 %type <node> condition
278 %type <node> conditionopt
279 %type <node> for_init_statement
280 %type <for_rest_statement> for_rest_statement
281 %type <node> layout_defaults
282 %type <type_qualifier> layout_uniform_defaults
283 %type <type_qualifier> layout_buffer_defaults
284 %type <type_qualifier> layout_in_defaults
285 %type <type_qualifier> layout_out_defaults
291 version_statement extension_statement_list
293 _mesa_glsl_initialize_types(state);
295 external_declaration_list
297 delete state->symbols;
298 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
299 if (state->es_shader) {
300 if (state->stage == MESA_SHADER_FRAGMENT) {
301 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
303 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
304 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
306 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
307 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
308 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
309 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
311 _mesa_glsl_initialize_types(state);
316 /* blank - no #version specified: defaults are already set */
317 | VERSION_TOK INTCONSTANT EOL
319 state->process_version_directive(&@2, $2, NULL);
324 | VERSION_TOK INTCONSTANT any_identifier EOL
326 state->process_version_directive(&@2, $2, $3);
334 PRAGMA_DEBUG_ON EOL { $$ = NULL; }
335 | PRAGMA_DEBUG_OFF EOL { $$ = NULL; }
336 | PRAGMA_OPTIMIZE_ON EOL { $$ = NULL; }
337 | PRAGMA_OPTIMIZE_OFF EOL { $$ = NULL; }
338 | PRAGMA_INVARIANT_ALL EOL
340 /* Pragma invariant(all) cannot be used in a fragment shader.
342 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
344 * "It is an error to use this pragma in a fragment shader."
346 if (state->is_version(120, 300) &&
347 state->stage == MESA_SHADER_FRAGMENT) {
348 _mesa_glsl_error(& @1, state,
349 "pragma `invariant(all)' cannot be used "
350 "in a fragment shader.");
351 } else if (!state->is_version(120, 100)) {
352 _mesa_glsl_warning(& @1, state,
353 "pragma `invariant(all)' not supported in %s "
354 "(GLSL ES 1.00 or GLSL 1.20 required)",
355 state->get_version_string());
357 state->all_invariant = true;
362 | PRAGMA_WARNING_ON EOL
364 void *mem_ctx = state->linalloc;
365 $$ = new(mem_ctx) ast_warnings_toggle(true);
367 | PRAGMA_WARNING_OFF EOL
369 void *mem_ctx = state->linalloc;
370 $$ = new(mem_ctx) ast_warnings_toggle(false);
374 extension_statement_list:
376 | extension_statement_list extension_statement
386 EXTENSION any_identifier COLON any_identifier EOL
388 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
394 external_declaration_list:
397 /* FINISHME: The NULL test is required because pragmas are set to
398 * FINISHME: NULL. (See production rule for external_declaration.)
401 state->translation_unit.push_tail(& $1->link);
403 | external_declaration_list external_declaration
405 /* FINISHME: The NULL test is required because pragmas are set to
406 * FINISHME: NULL. (See production rule for external_declaration.)
409 state->translation_unit.push_tail(& $2->link);
411 | external_declaration_list extension_statement {
412 if (!state->allow_extension_directive_midshader) {
413 _mesa_glsl_error(& @2, state,
414 "#extension directive is not allowed "
415 "in the middle of a shader");
429 void *ctx = state->linalloc;
430 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
431 $$->set_location(@1);
432 $$->primary_expression.identifier = $1;
436 void *ctx = state->linalloc;
437 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
438 $$->set_location(@1);
439 $$->primary_expression.int_constant = $1;
443 void *ctx = state->linalloc;
444 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
445 $$->set_location(@1);
446 $$->primary_expression.uint_constant = $1;
450 void *ctx = state->linalloc;
451 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
452 $$->set_location(@1);
453 $$->primary_expression.int64_constant = $1;
457 void *ctx = state->linalloc;
458 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
459 $$->set_location(@1);
460 $$->primary_expression.uint64_constant = $1;
464 void *ctx = state->linalloc;
465 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
466 $$->set_location(@1);
467 $$->primary_expression.float_constant = $1;
471 void *ctx = state->linalloc;
472 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
473 $$->set_location(@1);
474 $$->primary_expression.double_constant = $1;
478 void *ctx = state->linalloc;
479 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
480 $$->set_location(@1);
481 $$->primary_expression.bool_constant = $1;
491 | postfix_expression '[' integer_expression ']'
493 void *ctx = state->linalloc;
494 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
495 $$->set_location_range(@1, @4);
501 | postfix_expression DOT_TOK FIELD_SELECTION
503 void *ctx = state->linalloc;
504 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
505 $$->set_location_range(@1, @3);
506 $$->primary_expression.identifier = $3;
508 | postfix_expression INC_OP
510 void *ctx = state->linalloc;
511 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
512 $$->set_location_range(@1, @2);
514 | postfix_expression DEC_OP
516 void *ctx = state->linalloc;
517 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
518 $$->set_location_range(@1, @2);
527 function_call_or_method
530 function_call_or_method:
531 function_call_generic
534 function_call_generic:
535 function_call_header_with_parameters ')'
536 | function_call_header_no_parameters ')'
539 function_call_header_no_parameters:
540 function_call_header VOID_TOK
541 | function_call_header
544 function_call_header_with_parameters:
545 function_call_header assignment_expression
548 $$->set_location(@1);
549 $$->expressions.push_tail(& $2->link);
551 | function_call_header_with_parameters ',' assignment_expression
554 $$->set_location(@1);
555 $$->expressions.push_tail(& $3->link);
559 // Grammar Note: Constructors look like functions, but lexical
560 // analysis recognized most of them as keywords. They are now
561 // recognized through "type_specifier".
562 function_call_header:
563 function_identifier '('
569 void *ctx = state->linalloc;
570 $$ = new(ctx) ast_function_expression($1);
571 $$->set_location(@1);
575 void *ctx = state->linalloc;
576 $$ = new(ctx) ast_function_expression($1);
577 $$->set_location(@1);
581 // Grammar Note: Constructors look like methods, but lexical
582 // analysis recognized most of them as keywords. They are now
583 // recognized through "type_specifier".
585 // Grammar Note: No traditional style type casts.
588 | INC_OP unary_expression
590 void *ctx = state->linalloc;
591 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
592 $$->set_location(@1);
594 | DEC_OP unary_expression
596 void *ctx = state->linalloc;
597 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
598 $$->set_location(@1);
600 | unary_operator unary_expression
602 void *ctx = state->linalloc;
603 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
604 $$->set_location_range(@1, @2);
608 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
610 '+' { $$ = ast_plus; }
611 | '-' { $$ = ast_neg; }
612 | '!' { $$ = ast_logic_not; }
613 | '~' { $$ = ast_bit_not; }
616 multiplicative_expression:
618 | multiplicative_expression '*' unary_expression
620 void *ctx = state->linalloc;
621 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
622 $$->set_location_range(@1, @3);
624 | multiplicative_expression '/' unary_expression
626 void *ctx = state->linalloc;
627 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
628 $$->set_location_range(@1, @3);
630 | multiplicative_expression '%' unary_expression
632 void *ctx = state->linalloc;
633 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
634 $$->set_location_range(@1, @3);
639 multiplicative_expression
640 | additive_expression '+' multiplicative_expression
642 void *ctx = state->linalloc;
643 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
644 $$->set_location_range(@1, @3);
646 | additive_expression '-' multiplicative_expression
648 void *ctx = state->linalloc;
649 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
650 $$->set_location_range(@1, @3);
656 | shift_expression LEFT_OP additive_expression
658 void *ctx = state->linalloc;
659 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
660 $$->set_location_range(@1, @3);
662 | shift_expression RIGHT_OP additive_expression
664 void *ctx = state->linalloc;
665 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
666 $$->set_location_range(@1, @3);
670 relational_expression:
672 | relational_expression '<' shift_expression
674 void *ctx = state->linalloc;
675 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
676 $$->set_location_range(@1, @3);
678 | relational_expression '>' shift_expression
680 void *ctx = state->linalloc;
681 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
682 $$->set_location_range(@1, @3);
684 | relational_expression LE_OP shift_expression
686 void *ctx = state->linalloc;
687 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
688 $$->set_location_range(@1, @3);
690 | relational_expression GE_OP shift_expression
692 void *ctx = state->linalloc;
693 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
694 $$->set_location_range(@1, @3);
699 relational_expression
700 | equality_expression EQ_OP relational_expression
702 void *ctx = state->linalloc;
703 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
704 $$->set_location_range(@1, @3);
706 | equality_expression NE_OP relational_expression
708 void *ctx = state->linalloc;
709 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
710 $$->set_location_range(@1, @3);
716 | and_expression '&' equality_expression
718 void *ctx = state->linalloc;
719 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
720 $$->set_location_range(@1, @3);
724 exclusive_or_expression:
726 | exclusive_or_expression '^' and_expression
728 void *ctx = state->linalloc;
729 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
730 $$->set_location_range(@1, @3);
734 inclusive_or_expression:
735 exclusive_or_expression
736 | inclusive_or_expression '|' exclusive_or_expression
738 void *ctx = state->linalloc;
739 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
740 $$->set_location_range(@1, @3);
744 logical_and_expression:
745 inclusive_or_expression
746 | logical_and_expression AND_OP inclusive_or_expression
748 void *ctx = state->linalloc;
749 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
750 $$->set_location_range(@1, @3);
754 logical_xor_expression:
755 logical_and_expression
756 | logical_xor_expression XOR_OP logical_and_expression
758 void *ctx = state->linalloc;
759 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
760 $$->set_location_range(@1, @3);
764 logical_or_expression:
765 logical_xor_expression
766 | logical_or_expression OR_OP logical_xor_expression
768 void *ctx = state->linalloc;
769 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
770 $$->set_location_range(@1, @3);
774 conditional_expression:
775 logical_or_expression
776 | logical_or_expression '?' expression ':' assignment_expression
778 void *ctx = state->linalloc;
779 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
780 $$->set_location_range(@1, @5);
784 assignment_expression:
785 conditional_expression
786 | unary_expression assignment_operator assignment_expression
788 void *ctx = state->linalloc;
789 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
790 $$->set_location_range(@1, @3);
795 '=' { $$ = ast_assign; }
796 | MUL_ASSIGN { $$ = ast_mul_assign; }
797 | DIV_ASSIGN { $$ = ast_div_assign; }
798 | MOD_ASSIGN { $$ = ast_mod_assign; }
799 | ADD_ASSIGN { $$ = ast_add_assign; }
800 | SUB_ASSIGN { $$ = ast_sub_assign; }
801 | LEFT_ASSIGN { $$ = ast_ls_assign; }
802 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
803 | AND_ASSIGN { $$ = ast_and_assign; }
804 | XOR_ASSIGN { $$ = ast_xor_assign; }
805 | OR_ASSIGN { $$ = ast_or_assign; }
809 assignment_expression
813 | expression ',' assignment_expression
815 void *ctx = state->linalloc;
816 if ($1->oper != ast_sequence) {
817 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
818 $$->set_location_range(@1, @3);
819 $$->expressions.push_tail(& $1->link);
824 $$->expressions.push_tail(& $3->link);
829 conditional_expression
833 function_prototype ';'
835 state->symbols->pop_scope();
838 | init_declarator_list ';'
842 | PRECISION precision_qualifier type_specifier ';'
844 $3->default_precision = $2;
849 ast_interface_block *block = (ast_interface_block *) $1;
850 if (block->layout.has_layout() || block->layout.has_memory()) {
851 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
855 block->layout = block->default_layout;
856 if (!block->layout.push_to_global(& @1, state)) {
864 function_declarator ')'
869 | function_header_with_parameters
872 function_header_with_parameters:
873 function_header parameter_declaration
876 $$->parameters.push_tail(& $2->link);
878 | function_header_with_parameters ',' parameter_declaration
881 $$->parameters.push_tail(& $3->link);
886 fully_specified_type variable_identifier '('
888 void *ctx = state->linalloc;
889 $$ = new(ctx) ast_function();
890 $$->set_location(@2);
891 $$->return_type = $1;
894 if ($1->qualifier.is_subroutine_decl()) {
895 /* add type for IDENTIFIER search */
896 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
898 state->symbols->add_function(new(state) ir_function($2));
899 state->symbols->push_scope();
903 parameter_declarator:
904 type_specifier any_identifier
906 void *ctx = state->linalloc;
907 $$ = new(ctx) ast_parameter_declarator();
908 $$->set_location_range(@1, @2);
909 $$->type = new(ctx) ast_fully_specified_type();
910 $$->type->set_location(@1);
911 $$->type->specifier = $1;
913 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
915 | layout_qualifier type_specifier any_identifier
917 if (state->allow_layout_qualifier_on_function_parameter) {
918 void *ctx = state->linalloc;
919 $$ = new(ctx) ast_parameter_declarator();
920 $$->set_location_range(@2, @3);
921 $$->type = new(ctx) ast_fully_specified_type();
922 $$->type->set_location(@2);
923 $$->type->specifier = $2;
925 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
927 _mesa_glsl_error(&@1, state,
928 "is is not allowed on function parameter");
932 | type_specifier any_identifier array_specifier
934 void *ctx = state->linalloc;
935 $$ = new(ctx) ast_parameter_declarator();
936 $$->set_location_range(@1, @3);
937 $$->type = new(ctx) ast_fully_specified_type();
938 $$->type->set_location(@1);
939 $$->type->specifier = $1;
941 $$->array_specifier = $3;
942 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
946 parameter_declaration:
947 parameter_qualifier parameter_declarator
950 $$->type->qualifier = $1;
951 if (!$$->type->qualifier.push_to_global(& @1, state)) {
955 | parameter_qualifier parameter_type_specifier
957 void *ctx = state->linalloc;
958 $$ = new(ctx) ast_parameter_declarator();
959 $$->set_location(@2);
960 $$->type = new(ctx) ast_fully_specified_type();
961 $$->type->set_location_range(@1, @2);
962 $$->type->qualifier = $1;
963 if (!$$->type->qualifier.push_to_global(& @1, state)) {
966 $$->type->specifier = $2;
973 memset(& $$, 0, sizeof($$));
975 | CONST_TOK parameter_qualifier
977 if ($2.flags.q.constant)
978 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
981 $$.flags.q.constant = 1;
983 | PRECISE parameter_qualifier
985 if ($2.flags.q.precise)
986 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
989 $$.flags.q.precise = 1;
991 | parameter_direction_qualifier parameter_qualifier
993 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
994 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
996 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
997 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
1001 $$.merge_qualifier(&@1, state, $2, false);
1003 | precision_qualifier parameter_qualifier
1005 if ($2.precision != ast_precision_none)
1006 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1008 if (!state->has_420pack_or_es31() &&
1010 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1015 | memory_qualifier parameter_qualifier
1018 $$.merge_qualifier(&@1, state, $2, false);
1021 parameter_direction_qualifier:
1024 memset(& $$, 0, sizeof($$));
1029 memset(& $$, 0, sizeof($$));
1034 memset(& $$, 0, sizeof($$));
1040 parameter_type_specifier:
1044 init_declarator_list:
1046 | init_declarator_list ',' any_identifier
1048 void *ctx = state->linalloc;
1049 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1050 decl->set_location(@3);
1053 $$->declarations.push_tail(&decl->link);
1054 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1056 | init_declarator_list ',' any_identifier array_specifier
1058 void *ctx = state->linalloc;
1059 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1060 decl->set_location_range(@3, @4);
1063 $$->declarations.push_tail(&decl->link);
1064 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1066 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1068 void *ctx = state->linalloc;
1069 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1070 decl->set_location_range(@3, @4);
1073 $$->declarations.push_tail(&decl->link);
1074 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1076 | init_declarator_list ',' any_identifier '=' initializer
1078 void *ctx = state->linalloc;
1079 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1080 decl->set_location(@3);
1083 $$->declarations.push_tail(&decl->link);
1084 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1088 // Grammar Note: No 'enum', or 'typedef'.
1090 fully_specified_type
1092 void *ctx = state->linalloc;
1093 /* Empty declaration list is valid. */
1094 $$ = new(ctx) ast_declarator_list($1);
1095 $$->set_location(@1);
1097 | fully_specified_type any_identifier
1099 void *ctx = state->linalloc;
1100 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1101 decl->set_location(@2);
1103 $$ = new(ctx) ast_declarator_list($1);
1104 $$->set_location_range(@1, @2);
1105 $$->declarations.push_tail(&decl->link);
1106 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1108 | fully_specified_type any_identifier array_specifier
1110 void *ctx = state->linalloc;
1111 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1112 decl->set_location_range(@2, @3);
1114 $$ = new(ctx) ast_declarator_list($1);
1115 $$->set_location_range(@1, @3);
1116 $$->declarations.push_tail(&decl->link);
1117 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1119 | fully_specified_type any_identifier array_specifier '=' initializer
1121 void *ctx = state->linalloc;
1122 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1123 decl->set_location_range(@2, @3);
1125 $$ = new(ctx) ast_declarator_list($1);
1126 $$->set_location_range(@1, @3);
1127 $$->declarations.push_tail(&decl->link);
1128 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1130 | fully_specified_type any_identifier '=' initializer
1132 void *ctx = state->linalloc;
1133 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1134 decl->set_location(@2);
1136 $$ = new(ctx) ast_declarator_list($1);
1137 $$->set_location_range(@1, @2);
1138 $$->declarations.push_tail(&decl->link);
1139 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1141 | INVARIANT variable_identifier
1143 void *ctx = state->linalloc;
1144 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1145 decl->set_location(@2);
1147 $$ = new(ctx) ast_declarator_list(NULL);
1148 $$->set_location_range(@1, @2);
1149 $$->invariant = true;
1151 $$->declarations.push_tail(&decl->link);
1153 | PRECISE variable_identifier
1155 void *ctx = state->linalloc;
1156 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1157 decl->set_location(@2);
1159 $$ = new(ctx) ast_declarator_list(NULL);
1160 $$->set_location_range(@1, @2);
1163 $$->declarations.push_tail(&decl->link);
1167 fully_specified_type:
1170 void *ctx = state->linalloc;
1171 $$ = new(ctx) ast_fully_specified_type();
1172 $$->set_location(@1);
1175 | type_qualifier type_specifier
1177 void *ctx = state->linalloc;
1178 $$ = new(ctx) ast_fully_specified_type();
1179 $$->set_location_range(@1, @2);
1181 if (!$$->qualifier.push_to_global(& @1, state)) {
1185 if ($$->specifier->structure != NULL &&
1186 $$->specifier->structure->is_declaration) {
1187 $$->specifier->structure->layout = &$$->qualifier;
1193 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1199 layout_qualifier_id_list:
1201 | layout_qualifier_id_list ',' layout_qualifier_id
1204 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1210 layout_qualifier_id:
1213 memset(& $$, 0, sizeof($$));
1215 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1216 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1217 state->is_version(150, 0))) {
1218 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1219 $$.flags.q.origin_upper_left = 1;
1220 } else if (match_layout_qualifier($1, "pixel_center_integer",
1222 $$.flags.q.pixel_center_integer = 1;
1225 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1226 _mesa_glsl_warning(& @1, state,
1227 "GL_ARB_fragment_coord_conventions layout "
1228 "identifier `%s' used", $1);
1232 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1234 (state->AMD_conservative_depth_enable ||
1235 state->ARB_conservative_depth_enable ||
1236 state->is_version(420, 0))) {
1237 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1238 $$.flags.q.depth_type = 1;
1239 $$.depth_type = ast_depth_any;
1240 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1241 $$.flags.q.depth_type = 1;
1242 $$.depth_type = ast_depth_greater;
1243 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1244 $$.flags.q.depth_type = 1;
1245 $$.depth_type = ast_depth_less;
1246 } else if (match_layout_qualifier($1, "depth_unchanged",
1248 $$.flags.q.depth_type = 1;
1249 $$.depth_type = ast_depth_unchanged;
1252 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1253 _mesa_glsl_warning(& @1, state,
1254 "GL_AMD_conservative_depth "
1255 "layout qualifier `%s' is used", $1);
1257 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1258 _mesa_glsl_warning(& @1, state,
1259 "GL_ARB_conservative_depth "
1260 "layout qualifier `%s' is used", $1);
1264 /* See also interface_block_layout_qualifier. */
1265 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1266 if (match_layout_qualifier($1, "std140", state) == 0) {
1267 $$.flags.q.std140 = 1;
1268 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1269 $$.flags.q.shared = 1;
1270 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1271 $$.flags.q.std430 = 1;
1272 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1273 $$.flags.q.column_major = 1;
1274 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1275 * below in the interface_block_layout_qualifier rule.
1277 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1280 * Also, this takes care of alternate capitalizations of
1281 * "row_major" (which is necessary because layout qualifiers
1282 * are case-insensitive in desktop GLSL).
1284 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1285 $$.flags.q.row_major = 1;
1286 /* "packed" is a reserved word in GLSL, and its token is
1287 * parsed below in the interface_block_layout_qualifier rule.
1288 * However, we must take care of alternate capitalizations of
1289 * "packed", because layout qualifiers are case-insensitive
1292 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1293 $$.flags.q.packed = 1;
1296 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1297 _mesa_glsl_warning(& @1, state,
1298 "#version 140 / GL_ARB_uniform_buffer_object "
1299 "layout qualifier `%s' is used", $1);
1303 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1305 static const struct {
1309 { "points", GL_POINTS },
1310 { "lines", GL_LINES },
1311 { "lines_adjacency", GL_LINES_ADJACENCY },
1312 { "line_strip", GL_LINE_STRIP },
1313 { "triangles", GL_TRIANGLES },
1314 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1315 { "triangle_strip", GL_TRIANGLE_STRIP },
1317 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1318 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1319 $$.flags.q.prim_type = 1;
1320 $$.prim_type = map[i].e;
1325 if ($$.flags.i && !state->has_geometry_shader() &&
1326 !state->has_tessellation_shader()) {
1327 _mesa_glsl_error(& @1, state, "#version 150 layout "
1328 "qualifier `%s' used", $1);
1332 /* Layout qualifiers for ARB_shader_image_load_store. */
1333 if (state->has_shader_image_load_store()) {
1335 static const struct {
1338 glsl_base_type base_type;
1339 /** Minimum desktop GLSL version required for the image
1340 * format. Use 130 if already present in the original
1343 unsigned required_glsl;
1344 /** Minimum GLSL ES version required for the image format. */
1345 unsigned required_essl;
1346 /* NV_image_formats */
1347 bool nv_image_formats;
1348 bool ext_qualifiers;
1350 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false, false },
1351 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false, false },
1352 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1353 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1354 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1355 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false, false },
1356 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1357 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false, false },
1358 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false, false },
1359 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true, false },
1360 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false, false },
1361 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true, false },
1362 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true, false },
1363 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true, false },
1364 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false, false },
1365 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true, false },
1366 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true, false },
1367 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false, false },
1368 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false, false },
1369 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false, false },
1370 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true, false },
1371 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true, false },
1372 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true, false },
1373 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false, false },
1374 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true, false },
1375 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true, false },
1376 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, true, false },
1377 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true, false },
1378 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false, false },
1379 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, true, false },
1380 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true, false },
1381 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, true, false },
1382 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true, false },
1383 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1384 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
1385 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1386 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1387 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1388 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1390 /* From GL_EXT_shader_image_load_store: */
1391 /* base_type is incorrect but it'll be patched later when we know
1392 * the variable type. See ast_to_hir.cpp */
1393 { "size1x8", GL_R8I, GLSL_TYPE_VOID, 130, 0, false, true },
1394 { "size1x16", GL_R16I, GLSL_TYPE_VOID, 130, 0, false, true },
1395 { "size1x32", GL_R32I, GLSL_TYPE_VOID, 130, 0, false, true },
1396 { "size2x32", GL_RG32I, GLSL_TYPE_VOID, 130, 0, false, true },
1397 { "size4x32", GL_RGBA32I, GLSL_TYPE_VOID, 130, 0, false, true },
1400 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1401 if ((state->is_version(map[i].required_glsl,
1402 map[i].required_essl) ||
1403 (state->NV_image_formats_enable &&
1404 map[i].nv_image_formats)) &&
1405 match_layout_qualifier($1, map[i].name, state) == 0) {
1406 /* Skip ARB_shader_image_load_store qualifiers if not enabled */
1407 if (!map[i].ext_qualifiers && !(state->ARB_shader_image_load_store_enable ||
1408 state->is_version(420, 310))) {
1411 /* Skip EXT_shader_image_load_store qualifiers if not enabled */
1412 if (map[i].ext_qualifiers && !state->EXT_shader_image_load_store_enable) {
1415 $$.flags.q.explicit_image_format = 1;
1416 $$.image_format = map[i].format;
1417 $$.image_base_type = map[i].base_type;
1425 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1426 /* From section 4.4.1.3 of the GLSL 4.50 specification
1427 * (Fragment Shader Inputs):
1429 * "Fragment shaders also allow the following layout
1430 * qualifier on in only (not with variable declarations)
1431 * layout-qualifier-id
1432 * early_fragment_tests
1435 if (state->stage != MESA_SHADER_FRAGMENT) {
1436 _mesa_glsl_error(& @1, state,
1437 "early_fragment_tests layout qualifier only "
1438 "valid in fragment shaders");
1441 $$.flags.q.early_fragment_tests = 1;
1444 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1445 if (state->stage != MESA_SHADER_FRAGMENT) {
1446 _mesa_glsl_error(& @1, state,
1447 "inner_coverage layout qualifier only "
1448 "valid in fragment shaders");
1451 if (state->INTEL_conservative_rasterization_enable) {
1452 $$.flags.q.inner_coverage = 1;
1454 _mesa_glsl_error(& @1, state,
1455 "inner_coverage layout qualifier present, "
1456 "but the INTEL_conservative_rasterization extension "
1461 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1462 if (state->stage != MESA_SHADER_FRAGMENT) {
1463 _mesa_glsl_error(& @1, state,
1464 "post_depth_coverage layout qualifier only "
1465 "valid in fragment shaders");
1468 if (state->ARB_post_depth_coverage_enable ||
1469 state->INTEL_conservative_rasterization_enable) {
1470 $$.flags.q.post_depth_coverage = 1;
1472 _mesa_glsl_error(& @1, state,
1473 "post_depth_coverage layout qualifier present, "
1474 "but the GL_ARB_post_depth_coverage extension "
1479 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1480 _mesa_glsl_error(& @1, state,
1481 "post_depth_coverage & inner_coverage layout qualifiers "
1482 "are mutually exclusive");
1486 const bool pixel_interlock_ordered = match_layout_qualifier($1,
1487 "pixel_interlock_ordered", state) == 0;
1488 const bool pixel_interlock_unordered = match_layout_qualifier($1,
1489 "pixel_interlock_unordered", state) == 0;
1490 const bool sample_interlock_ordered = match_layout_qualifier($1,
1491 "sample_interlock_ordered", state) == 0;
1492 const bool sample_interlock_unordered = match_layout_qualifier($1,
1493 "sample_interlock_unordered", state) == 0;
1495 if (pixel_interlock_ordered + pixel_interlock_unordered +
1496 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1497 state->stage != MESA_SHADER_FRAGMENT) {
1498 _mesa_glsl_error(& @1, state, "interlock layout qualifiers: "
1499 "pixel_interlock_ordered, pixel_interlock_unordered, "
1500 "sample_interlock_ordered and sample_interlock_unordered, "
1501 "only valid in fragment shader input layout declaration.");
1502 } else if (pixel_interlock_ordered + pixel_interlock_unordered +
1503 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1504 !state->ARB_fragment_shader_interlock_enable &&
1505 !state->NV_fragment_shader_interlock_enable) {
1506 _mesa_glsl_error(& @1, state,
1507 "interlock layout qualifier present, but the "
1508 "GL_ARB_fragment_shader_interlock or "
1509 "GL_NV_fragment_shader_interlock extension is not "
1512 $$.flags.q.pixel_interlock_ordered = pixel_interlock_ordered;
1513 $$.flags.q.pixel_interlock_unordered = pixel_interlock_unordered;
1514 $$.flags.q.sample_interlock_ordered = sample_interlock_ordered;
1515 $$.flags.q.sample_interlock_unordered = sample_interlock_unordered;
1518 /* Layout qualifiers for tessellation evaluation shaders. */
1520 static const struct {
1524 /* triangles already parsed by gs-specific code */
1525 { "quads", GL_QUADS },
1526 { "isolines", GL_ISOLINES },
1528 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1529 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1530 $$.flags.q.prim_type = 1;
1531 $$.prim_type = map[i].e;
1536 if ($$.flags.i && !state->has_tessellation_shader()) {
1537 _mesa_glsl_error(& @1, state,
1538 "primitive mode qualifier `%s' requires "
1539 "GLSL 4.00 or ARB_tessellation_shader", $1);
1543 static const struct {
1545 enum gl_tess_spacing e;
1547 { "equal_spacing", TESS_SPACING_EQUAL },
1548 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1549 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1551 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1552 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1553 $$.flags.q.vertex_spacing = 1;
1554 $$.vertex_spacing = map[i].e;
1559 if ($$.flags.i && !state->has_tessellation_shader()) {
1560 _mesa_glsl_error(& @1, state,
1561 "vertex spacing qualifier `%s' requires "
1562 "GLSL 4.00 or ARB_tessellation_shader", $1);
1566 if (match_layout_qualifier($1, "cw", state) == 0) {
1567 $$.flags.q.ordering = 1;
1568 $$.ordering = GL_CW;
1569 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1570 $$.flags.q.ordering = 1;
1571 $$.ordering = GL_CCW;
1574 if ($$.flags.i && !state->has_tessellation_shader()) {
1575 _mesa_glsl_error(& @1, state,
1576 "ordering qualifier `%s' requires "
1577 "GLSL 4.00 or ARB_tessellation_shader", $1);
1581 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1582 $$.flags.q.point_mode = 1;
1583 $$.point_mode = true;
1586 if ($$.flags.i && !state->has_tessellation_shader()) {
1587 _mesa_glsl_error(& @1, state,
1588 "qualifier `point_mode' requires "
1589 "GLSL 4.00 or ARB_tessellation_shader");
1594 static const struct {
1598 { "blend_support_multiply", BLEND_MULTIPLY },
1599 { "blend_support_screen", BLEND_SCREEN },
1600 { "blend_support_overlay", BLEND_OVERLAY },
1601 { "blend_support_darken", BLEND_DARKEN },
1602 { "blend_support_lighten", BLEND_LIGHTEN },
1603 { "blend_support_colordodge", BLEND_COLORDODGE },
1604 { "blend_support_colorburn", BLEND_COLORBURN },
1605 { "blend_support_hardlight", BLEND_HARDLIGHT },
1606 { "blend_support_softlight", BLEND_SOFTLIGHT },
1607 { "blend_support_difference", BLEND_DIFFERENCE },
1608 { "blend_support_exclusion", BLEND_EXCLUSION },
1609 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1610 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1611 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1612 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1613 { "blend_support_all_equations", BLEND_ALL },
1615 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1616 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1617 $$.flags.q.blend_support = 1;
1618 state->fs_blend_support |= map[i].mask;
1624 !state->KHR_blend_equation_advanced_enable &&
1625 !state->is_version(0, 320)) {
1626 _mesa_glsl_error(& @1, state,
1627 "advanced blending layout qualifiers require "
1628 "ESSL 3.20 or KHR_blend_equation_advanced");
1631 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1632 _mesa_glsl_error(& @1, state,
1633 "advanced blending layout qualifiers only "
1634 "valid in fragment shaders");
1638 /* Layout qualifiers for ARB_compute_variable_group_size. */
1640 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1641 $$.flags.q.local_size_variable = 1;
1644 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1645 _mesa_glsl_error(& @1, state,
1646 "qualifier `local_size_variable` requires "
1647 "ARB_compute_variable_group_size");
1651 /* Layout qualifiers for ARB_bindless_texture. */
1653 if (match_layout_qualifier($1, "bindless_sampler", state) == 0)
1654 $$.flags.q.bindless_sampler = 1;
1655 if (match_layout_qualifier($1, "bound_sampler", state) == 0)
1656 $$.flags.q.bound_sampler = 1;
1658 if (state->has_shader_image_load_store()) {
1659 if (match_layout_qualifier($1, "bindless_image", state) == 0)
1660 $$.flags.q.bindless_image = 1;
1661 if (match_layout_qualifier($1, "bound_image", state) == 0)
1662 $$.flags.q.bound_image = 1;
1665 if ($$.flags.i && !state->has_bindless()) {
1666 _mesa_glsl_error(& @1, state,
1667 "qualifier `%s` requires "
1668 "ARB_bindless_texture", $1);
1673 state->EXT_shader_framebuffer_fetch_non_coherent_enable) {
1674 if (match_layout_qualifier($1, "noncoherent", state) == 0)
1675 $$.flags.q.non_coherent = 1;
1678 // Layout qualifiers for NV_compute_shader_derivatives.
1680 if (match_layout_qualifier($1, "derivative_group_quadsNV", state) == 0) {
1681 $$.flags.q.derivative_group = 1;
1682 $$.derivative_group = DERIVATIVE_GROUP_QUADS;
1683 } else if (match_layout_qualifier($1, "derivative_group_linearNV", state) == 0) {
1684 $$.flags.q.derivative_group = 1;
1685 $$.derivative_group = DERIVATIVE_GROUP_LINEAR;
1689 if (!state->has_compute_shader()) {
1690 _mesa_glsl_error(& @1, state,
1691 "qualifier `%s' requires "
1692 "a compute shader", $1);
1695 if (!state->NV_compute_shader_derivatives_enable) {
1696 _mesa_glsl_error(& @1, state,
1697 "qualifier `%s' requires "
1698 "NV_compute_shader_derivatives", $1);
1701 if (state->NV_compute_shader_derivatives_warn) {
1702 _mesa_glsl_warning(& @1, state,
1703 "NV_compute_shader_derivatives layout "
1704 "qualifier `%s' used", $1);
1710 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1715 | any_identifier '=' constant_expression
1717 memset(& $$, 0, sizeof($$));
1718 void *ctx = state->linalloc;
1720 if ($3->oper != ast_int_constant &&
1721 $3->oper != ast_uint_constant &&
1722 !state->has_enhanced_layouts()) {
1723 _mesa_glsl_error(& @1, state,
1724 "compile-time constant expressions require "
1725 "GLSL 4.40 or ARB_enhanced_layouts");
1728 if (match_layout_qualifier("align", $1, state) == 0) {
1729 if (!state->has_enhanced_layouts()) {
1730 _mesa_glsl_error(& @1, state,
1731 "align qualifier requires "
1732 "GLSL 4.40 or ARB_enhanced_layouts");
1734 $$.flags.q.explicit_align = 1;
1739 if (match_layout_qualifier("location", $1, state) == 0) {
1740 $$.flags.q.explicit_location = 1;
1742 if ($$.flags.q.attribute == 1 &&
1743 state->ARB_explicit_attrib_location_warn) {
1744 _mesa_glsl_warning(& @1, state,
1745 "GL_ARB_explicit_attrib_location layout "
1746 "identifier `%s' used", $1);
1751 if (match_layout_qualifier("component", $1, state) == 0) {
1752 if (!state->has_enhanced_layouts()) {
1753 _mesa_glsl_error(& @1, state,
1754 "component qualifier requires "
1755 "GLSL 4.40 or ARB_enhanced_layouts");
1757 $$.flags.q.explicit_component = 1;
1762 if (match_layout_qualifier("index", $1, state) == 0) {
1763 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1764 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1768 $$.flags.q.explicit_index = 1;
1772 if ((state->has_420pack_or_es31() ||
1773 state->has_atomic_counters() ||
1774 state->has_shader_storage_buffer_objects()) &&
1775 match_layout_qualifier("binding", $1, state) == 0) {
1776 $$.flags.q.explicit_binding = 1;
1780 if ((state->has_atomic_counters() ||
1781 state->has_enhanced_layouts()) &&
1782 match_layout_qualifier("offset", $1, state) == 0) {
1783 $$.flags.q.explicit_offset = 1;
1787 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1788 $$.flags.q.max_vertices = 1;
1789 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1790 if (!state->has_geometry_shader()) {
1791 _mesa_glsl_error(& @3, state,
1792 "#version 150 max_vertices qualifier "
1797 if (state->stage == MESA_SHADER_GEOMETRY) {
1798 if (match_layout_qualifier("stream", $1, state) == 0 &&
1799 state->check_explicit_attrib_stream_allowed(& @3)) {
1800 $$.flags.q.stream = 1;
1801 $$.flags.q.explicit_stream = 1;
1806 if (state->has_enhanced_layouts()) {
1807 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1808 $$.flags.q.xfb_buffer = 1;
1809 $$.flags.q.explicit_xfb_buffer = 1;
1813 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1814 $$.flags.q.explicit_xfb_offset = 1;
1818 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1819 $$.flags.q.xfb_stride = 1;
1820 $$.flags.q.explicit_xfb_stride = 1;
1825 static const char * const local_size_qualifiers[3] = {
1830 for (int i = 0; i < 3; i++) {
1831 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1833 if (!state->has_compute_shader()) {
1834 _mesa_glsl_error(& @3, state,
1835 "%s qualifier requires GLSL 4.30 or "
1836 "GLSL ES 3.10 or ARB_compute_shader",
1837 local_size_qualifiers[i]);
1840 $$.flags.q.local_size |= (1 << i);
1841 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1847 if (match_layout_qualifier("invocations", $1, state) == 0) {
1848 $$.flags.q.invocations = 1;
1849 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1850 if (!state->is_version(400, 320) &&
1851 !state->ARB_gpu_shader5_enable &&
1852 !state->OES_geometry_shader_enable &&
1853 !state->EXT_geometry_shader_enable) {
1854 _mesa_glsl_error(& @3, state,
1855 "GL_ARB_gpu_shader5 invocations "
1856 "qualifier specified", $3);
1860 /* Layout qualifiers for tessellation control shaders. */
1861 if (match_layout_qualifier("vertices", $1, state) == 0) {
1862 $$.flags.q.vertices = 1;
1863 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1864 if (!state->has_tessellation_shader()) {
1865 _mesa_glsl_error(& @1, state,
1866 "vertices qualifier requires GLSL 4.00 or "
1867 "ARB_tessellation_shader");
1871 /* If the identifier didn't match any known layout identifiers,
1875 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1880 | interface_block_layout_qualifier
1883 /* Layout qualifiers for ARB_uniform_buffer_object. */
1884 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1885 _mesa_glsl_error(& @1, state,
1886 "#version 140 / GL_ARB_uniform_buffer_object "
1887 "layout qualifier `%s' is used", $1);
1888 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1889 _mesa_glsl_warning(& @1, state,
1890 "#version 140 / GL_ARB_uniform_buffer_object "
1891 "layout qualifier `%s' is used", $1);
1896 /* This is a separate language rule because we parse these as tokens
1897 * (due to them being reserved keywords) instead of identifiers like
1898 * most qualifiers. See the any_identifier path of
1899 * layout_qualifier_id for the others.
1901 * Note that since layout qualifiers are case-insensitive in desktop
1902 * GLSL, all of these qualifiers need to be handled as identifiers as
1903 * well (by the any_identifier path of layout_qualifier_id).
1905 interface_block_layout_qualifier:
1908 memset(& $$, 0, sizeof($$));
1909 $$.flags.q.row_major = 1;
1913 memset(& $$, 0, sizeof($$));
1914 $$.flags.q.packed = 1;
1918 memset(& $$, 0, sizeof($$));
1919 $$.flags.q.shared = 1;
1923 subroutine_qualifier:
1926 memset(& $$, 0, sizeof($$));
1927 $$.flags.q.subroutine = 1;
1929 | SUBROUTINE '(' subroutine_type_list ')'
1931 memset(& $$, 0, sizeof($$));
1932 $$.flags.q.subroutine = 1;
1933 $$.subroutine_list = $3;
1937 subroutine_type_list:
1940 void *ctx = state->linalloc;
1941 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1942 decl->set_location(@1);
1944 $$ = new(ctx) ast_subroutine_list();
1945 $$->declarations.push_tail(&decl->link);
1947 | subroutine_type_list ',' any_identifier
1949 void *ctx = state->linalloc;
1950 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1951 decl->set_location(@3);
1954 $$->declarations.push_tail(&decl->link);
1958 interpolation_qualifier:
1961 memset(& $$, 0, sizeof($$));
1962 $$.flags.q.smooth = 1;
1966 memset(& $$, 0, sizeof($$));
1967 $$.flags.q.flat = 1;
1971 memset(& $$, 0, sizeof($$));
1972 $$.flags.q.noperspective = 1;
1977 /* Single qualifiers */
1980 memset(& $$, 0, sizeof($$));
1981 $$.flags.q.invariant = 1;
1985 memset(& $$, 0, sizeof($$));
1986 $$.flags.q.precise = 1;
1988 | auxiliary_storage_qualifier
1990 | interpolation_qualifier
1993 | subroutine_qualifier
1994 | precision_qualifier
1996 memset(&$$, 0, sizeof($$));
2000 /* Multiple qualifiers:
2001 * In GLSL 4.20, these can be specified in any order. In earlier versions,
2002 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
2004 * invariant interpolation auxiliary storage precision ...or...
2005 * layout storage precision
2007 * Each qualifier's rule ensures that the accumulated qualifiers on the right
2008 * side don't contain any that must appear on the left hand side.
2009 * For example, when processing a storage qualifier, we check that there are
2010 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
2012 | PRECISE type_qualifier
2014 if ($2.flags.q.precise)
2015 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
2018 $$.flags.q.precise = 1;
2020 | INVARIANT type_qualifier
2022 if ($2.flags.q.invariant)
2023 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
2025 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
2026 _mesa_glsl_error(&@1, state,
2027 "\"invariant\" must come after \"precise\"");
2030 $$.flags.q.invariant = 1;
2032 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
2034 * "Only variables output from a shader can be candidates for invariance.
2035 * This includes user-defined output variables and the built-in output
2036 * variables. As only outputs can be declared as invariant, an invariant
2037 * output from one shader stage will still match an input of a subsequent
2038 * stage without the input being declared as invariant."
2040 * On the desktop side, this text first appears in GLSL 4.30.
2042 if (state->is_version(430, 300) && $$.flags.q.in)
2043 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
2045 | interpolation_qualifier type_qualifier
2047 /* Section 4.3 of the GLSL 1.40 specification states:
2048 * "...qualified with one of these interpolation qualifiers"
2050 * GLSL 1.30 claims to allow "one or more", but insists that:
2051 * "These interpolation qualifiers may only precede the qualifiers in,
2052 * centroid in, out, or centroid out in a declaration."
2054 * ...which means that e.g. smooth can't precede smooth, so there can be
2055 * only one after all, and the 1.40 text is a clarification, not a change.
2057 if ($2.has_interpolation())
2058 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
2060 if (!state->has_420pack_or_es31() &&
2061 ($2.flags.q.precise || $2.flags.q.invariant)) {
2062 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
2063 "after \"precise\" or \"invariant\"");
2067 $$.merge_qualifier(&@1, state, $2, false);
2069 | layout_qualifier type_qualifier
2071 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
2072 * appear no later than auxiliary storage qualifiers. There is no
2073 * particularly clear spec language mandating this, but in all examples
2074 * the layout qualifier precedes the storage qualifier.
2076 * We allow combinations of layout with interpolation, invariant or
2077 * precise qualifiers since these are useful in ARB_separate_shader_objects.
2078 * There is no clear spec guidance on this either.
2081 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
2083 | subroutine_qualifier type_qualifier
2086 $$.merge_qualifier(&@1, state, $2, false);
2088 | auxiliary_storage_qualifier type_qualifier
2090 if ($2.has_auxiliary_storage()) {
2091 _mesa_glsl_error(&@1, state,
2092 "duplicate auxiliary storage qualifier (centroid or sample)");
2095 if ((!state->has_420pack_or_es31() && !state->EXT_gpu_shader4_enable) &&
2096 ($2.flags.q.precise || $2.flags.q.invariant ||
2097 $2.has_interpolation() || $2.has_layout())) {
2098 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
2099 "just before storage qualifiers");
2102 $$.merge_qualifier(&@1, state, $2, false);
2104 | storage_qualifier type_qualifier
2106 /* Section 4.3 of the GLSL 1.20 specification states:
2107 * "Variable declarations may have a storage qualifier specified..."
2108 * 1.30 clarifies this to "may have one storage qualifier".
2110 * GL_EXT_gpu_shader4 allows "varying out" in fragment shaders.
2112 if ($2.has_storage() &&
2113 (!state->EXT_gpu_shader4_enable ||
2114 state->stage != MESA_SHADER_FRAGMENT ||
2115 !$1.flags.q.varying || !$2.flags.q.out))
2116 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
2118 if (!state->has_420pack_or_es31() &&
2119 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
2120 $2.has_layout() || $2.has_auxiliary_storage())) {
2121 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2122 "precise, invariant, interpolation, layout and auxiliary "
2123 "storage qualifiers");
2127 $$.merge_qualifier(&@1, state, $2, false);
2129 | precision_qualifier type_qualifier
2131 if ($2.precision != ast_precision_none)
2132 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2134 if (!(state->has_420pack_or_es31()) &&
2136 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2141 | memory_qualifier type_qualifier
2144 $$.merge_qualifier(&@1, state, $2, false);
2148 auxiliary_storage_qualifier:
2151 memset(& $$, 0, sizeof($$));
2152 $$.flags.q.centroid = 1;
2156 memset(& $$, 0, sizeof($$));
2157 $$.flags.q.sample = 1;
2161 memset(& $$, 0, sizeof($$));
2162 $$.flags.q.patch = 1;
2168 memset(& $$, 0, sizeof($$));
2169 $$.flags.q.constant = 1;
2173 memset(& $$, 0, sizeof($$));
2174 $$.flags.q.attribute = 1;
2178 memset(& $$, 0, sizeof($$));
2179 $$.flags.q.varying = 1;
2183 memset(& $$, 0, sizeof($$));
2188 memset(& $$, 0, sizeof($$));
2191 if (state->stage == MESA_SHADER_GEOMETRY &&
2192 state->has_explicit_attrib_stream()) {
2193 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2196 * "If the block or variable is declared with the stream
2197 * identifier, it is associated with the specified stream;
2198 * otherwise, it is associated with the current default stream."
2200 $$.flags.q.stream = 1;
2201 $$.flags.q.explicit_stream = 0;
2202 $$.stream = state->out_qualifier->stream;
2205 if (state->has_enhanced_layouts()) {
2206 $$.flags.q.xfb_buffer = 1;
2207 $$.flags.q.explicit_xfb_buffer = 0;
2208 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2213 memset(& $$, 0, sizeof($$));
2217 if (!state->has_framebuffer_fetch() ||
2218 !state->is_version(130, 300) ||
2219 state->stage != MESA_SHADER_FRAGMENT)
2220 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2221 "declared as both input and output");
2225 memset(& $$, 0, sizeof($$));
2226 $$.flags.q.uniform = 1;
2230 memset(& $$, 0, sizeof($$));
2231 $$.flags.q.buffer = 1;
2235 memset(& $$, 0, sizeof($$));
2236 $$.flags.q.shared_storage = 1;
2243 memset(& $$, 0, sizeof($$));
2244 $$.flags.q.coherent = 1;
2248 memset(& $$, 0, sizeof($$));
2249 $$.flags.q._volatile = 1;
2253 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2254 memset(& $$, 0, sizeof($$));
2255 $$.flags.q.restrict_flag = 1;
2259 memset(& $$, 0, sizeof($$));
2260 $$.flags.q.read_only = 1;
2264 memset(& $$, 0, sizeof($$));
2265 $$.flags.q.write_only = 1;
2272 void *ctx = state->linalloc;
2273 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2274 ast_unsized_array_dim, NULL,
2276 $$->set_location_range(@1, @2);
2278 | '[' constant_expression ']'
2280 void *ctx = state->linalloc;
2281 $$ = new(ctx) ast_array_specifier(@1, $2);
2282 $$->set_location_range(@1, @3);
2284 | array_specifier '[' ']'
2286 void *ctx = state->linalloc;
2289 if (state->check_arrays_of_arrays_allowed(& @1)) {
2290 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2294 | array_specifier '[' constant_expression ']'
2298 if (state->check_arrays_of_arrays_allowed(& @1)) {
2299 $$->add_dimension($3);
2305 type_specifier_nonarray
2306 | type_specifier_nonarray array_specifier
2309 $$->array_specifier = $2;
2313 type_specifier_nonarray:
2314 basic_type_specifier_nonarray
2316 void *ctx = state->linalloc;
2317 $$ = new(ctx) ast_type_specifier($1);
2318 $$->set_location(@1);
2322 void *ctx = state->linalloc;
2323 $$ = new(ctx) ast_type_specifier($1);
2324 $$->set_location(@1);
2328 void *ctx = state->linalloc;
2329 $$ = new(ctx) ast_type_specifier($1);
2330 $$->set_location(@1);
2334 basic_type_specifier_nonarray:
2335 VOID_TOK { $$ = glsl_type::void_type; }
2336 | BASIC_TYPE_TOK { $$ = $1; }
2337 | UNSIGNED BASIC_TYPE_TOK
2339 if ($2 == glsl_type::int_type) {
2340 $$ = glsl_type::uint_type;
2342 _mesa_glsl_error(&@1, state,
2343 "\"unsigned\" is only allowed before \"int\"");
2348 precision_qualifier:
2351 state->check_precision_qualifiers_allowed(&@1);
2352 $$ = ast_precision_high;
2356 state->check_precision_qualifiers_allowed(&@1);
2357 $$ = ast_precision_medium;
2361 state->check_precision_qualifiers_allowed(&@1);
2362 $$ = ast_precision_low;
2367 STRUCT any_identifier '{' struct_declaration_list '}'
2369 void *ctx = state->linalloc;
2370 $$ = new(ctx) ast_struct_specifier($2, $4);
2371 $$->set_location_range(@2, @5);
2372 state->symbols->add_type($2, glsl_type::void_type);
2374 | STRUCT '{' struct_declaration_list '}'
2376 void *ctx = state->linalloc;
2378 /* All anonymous structs have the same name. This simplifies matching of
2379 * globals whose type is an unnamed struct.
2381 * It also avoids a memory leak when the same shader is compiled over and
2384 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2386 $$->set_location_range(@2, @4);
2390 struct_declaration_list:
2394 $1->link.self_link();
2396 | struct_declaration_list struct_declaration
2399 $$->link.insert_before(& $2->link);
2404 fully_specified_type struct_declarator_list ';'
2406 void *ctx = state->linalloc;
2407 ast_fully_specified_type *const type = $1;
2408 type->set_location(@1);
2410 if (state->has_bindless()) {
2411 ast_type_qualifier input_layout_mask;
2413 /* Allow to declare qualifiers for images. */
2414 input_layout_mask.flags.i = 0;
2415 input_layout_mask.flags.q.coherent = 1;
2416 input_layout_mask.flags.q._volatile = 1;
2417 input_layout_mask.flags.q.restrict_flag = 1;
2418 input_layout_mask.flags.q.read_only = 1;
2419 input_layout_mask.flags.q.write_only = 1;
2420 input_layout_mask.flags.q.explicit_image_format = 1;
2422 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2423 _mesa_glsl_error(&@1, state,
2424 "only precision and image qualifiers may be "
2425 "applied to structure members");
2428 if (type->qualifier.flags.i != 0)
2429 _mesa_glsl_error(&@1, state,
2430 "only precision qualifiers may be applied to "
2431 "structure members");
2434 $$ = new(ctx) ast_declarator_list(type);
2435 $$->set_location(@2);
2437 $$->declarations.push_degenerate_list_at_head(& $2->link);
2441 struct_declarator_list:
2445 $1->link.self_link();
2447 | struct_declarator_list ',' struct_declarator
2450 $$->link.insert_before(& $3->link);
2457 void *ctx = state->linalloc;
2458 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2459 $$->set_location(@1);
2461 | any_identifier array_specifier
2463 void *ctx = state->linalloc;
2464 $$ = new(ctx) ast_declaration($1, $2, NULL);
2465 $$->set_location_range(@1, @2);
2470 assignment_expression
2471 | '{' initializer_list '}'
2475 | '{' initializer_list ',' '}'
2484 void *ctx = state->linalloc;
2485 $$ = new(ctx) ast_aggregate_initializer();
2486 $$->set_location(@1);
2487 $$->expressions.push_tail(& $1->link);
2489 | initializer_list ',' initializer
2491 $1->expressions.push_tail(& $3->link);
2495 declaration_statement:
2499 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2502 compound_statement { $$ = (ast_node *) $1; }
2507 declaration_statement
2508 | expression_statement
2509 | selection_statement
2511 | iteration_statement
2518 void *ctx = state->linalloc;
2519 $$ = new(ctx) ast_compound_statement(true, NULL);
2520 $$->set_location_range(@1, @2);
2524 state->symbols->push_scope();
2528 void *ctx = state->linalloc;
2529 $$ = new(ctx) ast_compound_statement(true, $3);
2530 $$->set_location_range(@1, @4);
2531 state->symbols->pop_scope();
2535 statement_no_new_scope:
2536 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2540 compound_statement_no_new_scope:
2543 void *ctx = state->linalloc;
2544 $$ = new(ctx) ast_compound_statement(false, NULL);
2545 $$->set_location_range(@1, @2);
2547 | '{' statement_list '}'
2549 void *ctx = state->linalloc;
2550 $$ = new(ctx) ast_compound_statement(false, $2);
2551 $$->set_location_range(@1, @3);
2559 _mesa_glsl_error(& @1, state, "<nil> statement");
2564 $$->link.self_link();
2566 | statement_list statement
2569 _mesa_glsl_error(& @2, state, "<nil> statement");
2573 $$->link.insert_before(& $2->link);
2575 | statement_list extension_statement
2577 if (!state->allow_extension_directive_midshader) {
2578 _mesa_glsl_error(& @1, state,
2579 "#extension directive is not allowed "
2580 "in the middle of a shader");
2586 expression_statement:
2589 void *ctx = state->linalloc;
2590 $$ = new(ctx) ast_expression_statement(NULL);
2591 $$->set_location(@1);
2595 void *ctx = state->linalloc;
2596 $$ = new(ctx) ast_expression_statement($1);
2597 $$->set_location(@1);
2601 selection_statement:
2602 IF '(' expression ')' selection_rest_statement
2604 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2606 $$->set_location_range(@1, @5);
2610 selection_rest_statement:
2611 statement ELSE statement
2613 $$.then_statement = $1;
2614 $$.else_statement = $3;
2616 | statement %prec THEN
2618 $$.then_statement = $1;
2619 $$.else_statement = NULL;
2626 $$ = (ast_node *) $1;
2628 | fully_specified_type any_identifier '=' initializer
2630 void *ctx = state->linalloc;
2631 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2632 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2633 decl->set_location_range(@2, @4);
2634 declarator->set_location(@1);
2636 declarator->declarations.push_tail(&decl->link);
2642 * switch_statement grammar is based on the syntax described in the body
2643 * of the GLSL spec, not in it's appendix!!!
2646 SWITCH '(' expression ')' switch_body
2648 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2649 $$->set_location_range(@1, @5);
2656 $$ = new(state->linalloc) ast_switch_body(NULL);
2657 $$->set_location_range(@1, @2);
2659 | '{' case_statement_list '}'
2661 $$ = new(state->linalloc) ast_switch_body($2);
2662 $$->set_location_range(@1, @3);
2669 $$ = new(state->linalloc) ast_case_label($2);
2670 $$->set_location(@2);
2674 $$ = new(state->linalloc) ast_case_label(NULL);
2675 $$->set_location(@2);
2682 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2684 labels->labels.push_tail(& $1->link);
2686 $$->set_location(@1);
2688 | case_label_list case_label
2691 $$->labels.push_tail(& $2->link);
2696 case_label_list statement
2698 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2699 stmts->set_location(@2);
2701 stmts->stmts.push_tail(& $2->link);
2704 | case_statement statement
2707 $$->stmts.push_tail(& $2->link);
2711 case_statement_list:
2714 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2715 cases->set_location(@1);
2717 cases->cases.push_tail(& $1->link);
2720 | case_statement_list case_statement
2723 $$->cases.push_tail(& $2->link);
2727 iteration_statement:
2728 WHILE '(' condition ')' statement_no_new_scope
2730 void *ctx = state->linalloc;
2731 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2732 NULL, $3, NULL, $5);
2733 $$->set_location_range(@1, @4);
2735 | DO statement WHILE '(' expression ')' ';'
2737 void *ctx = state->linalloc;
2738 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2739 NULL, $5, NULL, $2);
2740 $$->set_location_range(@1, @6);
2742 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2744 void *ctx = state->linalloc;
2745 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2746 $3, $4.cond, $4.rest, $6);
2747 $$->set_location_range(@1, @6);
2752 expression_statement
2753 | declaration_statement
2770 | conditionopt ';' expression
2777 // Grammar Note: No 'goto'. Gotos are not supported.
2781 void *ctx = state->linalloc;
2782 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2783 $$->set_location(@1);
2787 void *ctx = state->linalloc;
2788 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2789 $$->set_location(@1);
2793 void *ctx = state->linalloc;
2794 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2795 $$->set_location(@1);
2797 | RETURN expression ';'
2799 void *ctx = state->linalloc;
2800 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2801 $$->set_location_range(@1, @2);
2803 | DISCARD ';' // Fragment shader only.
2805 void *ctx = state->linalloc;
2806 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2807 $$->set_location(@1);
2811 external_declaration:
2812 function_definition { $$ = $1; }
2813 | declaration { $$ = $1; }
2814 | pragma_statement { $$ = $1; }
2815 | layout_defaults { $$ = $1; }
2816 | ';' { $$ = NULL; }
2819 function_definition:
2820 function_prototype compound_statement_no_new_scope
2822 void *ctx = state->linalloc;
2823 $$ = new(ctx) ast_function_definition();
2824 $$->set_location_range(@1, @2);
2828 state->symbols->pop_scope();
2832 /* layout_qualifieropt is packed into this rule */
2834 basic_interface_block
2838 | layout_qualifier interface_block
2840 ast_interface_block *block = (ast_interface_block *) $2;
2842 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2843 block->layout.has_layout())) {
2851 | memory_qualifier interface_block
2853 ast_interface_block *block = (ast_interface_block *)$2;
2855 if (!block->default_layout.flags.q.buffer) {
2856 _mesa_glsl_error(& @1, state,
2857 "memory qualifiers can only be used in the "
2858 "declaration of shader storage blocks");
2860 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2868 basic_interface_block:
2869 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2871 ast_interface_block *const block = $6;
2873 if ($1.flags.q.uniform) {
2874 block->default_layout = *state->default_uniform_qualifier;
2875 } else if ($1.flags.q.buffer) {
2876 block->default_layout = *state->default_shader_storage_qualifier;
2878 block->block_name = $2;
2879 block->declarations.push_degenerate_list_at_head(& $4->link);
2881 _mesa_ast_process_interface_block(& @1, state, block, $1);
2887 interface_qualifier:
2890 memset(& $$, 0, sizeof($$));
2895 memset(& $$, 0, sizeof($$));
2900 memset(& $$, 0, sizeof($$));
2901 $$.flags.q.uniform = 1;
2905 memset(& $$, 0, sizeof($$));
2906 $$.flags.q.buffer = 1;
2908 | auxiliary_storage_qualifier interface_qualifier
2910 if (!$1.flags.q.patch) {
2911 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2913 if ($2.has_auxiliary_storage()) {
2914 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2917 $$.flags.q.patch = 1;
2924 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2928 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2929 $$->set_location(@1);
2931 | NEW_IDENTIFIER array_specifier
2933 $$ = new(state->linalloc) ast_interface_block($1, $2);
2934 $$->set_location_range(@1, @2);
2942 $1->link.self_link();
2944 | member_declaration member_list
2947 $2->link.insert_before(& $$->link);
2952 fully_specified_type struct_declarator_list ';'
2954 void *ctx = state->linalloc;
2955 ast_fully_specified_type *type = $1;
2956 type->set_location(@1);
2958 if (type->qualifier.flags.q.attribute) {
2959 _mesa_glsl_error(& @1, state,
2960 "keyword 'attribute' cannot be used with "
2961 "interface block member");
2962 } else if (type->qualifier.flags.q.varying) {
2963 _mesa_glsl_error(& @1, state,
2964 "keyword 'varying' cannot be used with "
2965 "interface block member");
2968 $$ = new(ctx) ast_declarator_list(type);
2969 $$->set_location(@2);
2971 $$->declarations.push_degenerate_list_at_head(& $2->link);
2975 layout_uniform_defaults:
2976 layout_qualifier layout_uniform_defaults
2979 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2983 | layout_qualifier UNIFORM ';'
2986 layout_buffer_defaults:
2987 layout_qualifier layout_buffer_defaults
2990 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2994 | layout_qualifier BUFFER ';'
2998 layout_qualifier layout_in_defaults
3001 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3004 if (!$$.validate_in_qualifier(& @1, state)) {
3008 | layout_qualifier IN_TOK ';'
3010 if (!$1.validate_in_qualifier(& @1, state)) {
3016 layout_out_defaults:
3017 layout_qualifier layout_out_defaults
3020 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3023 if (!$$.validate_out_qualifier(& @1, state)) {
3027 | layout_qualifier OUT_TOK ';'
3029 if (!$1.validate_out_qualifier(& @1, state)) {
3036 layout_uniform_defaults
3039 if (!state->default_uniform_qualifier->
3040 merge_qualifier(& @1, state, $1, false)) {
3043 if (!state->default_uniform_qualifier->
3044 push_to_global(& @1, state)) {
3048 | layout_buffer_defaults
3051 if (!state->default_shader_storage_qualifier->
3052 merge_qualifier(& @1, state, $1, false)) {
3055 if (!state->default_shader_storage_qualifier->
3056 push_to_global(& @1, state)) {
3060 /* From the GLSL 4.50 spec, section 4.4.5:
3062 * "It is a compile-time error to specify the binding identifier for
3063 * the global scope or for block member declarations."
3065 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
3066 _mesa_glsl_error(& @1, state,
3067 "binding qualifier cannot be set for default layout");
3070 | layout_in_defaults
3073 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
3076 if (!state->in_qualifier->push_to_global(& @1, state)) {
3080 | layout_out_defaults
3083 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
3086 if (!state->out_qualifier->push_to_global(& @1, state)) {