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"
38 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
43 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
45 _mesa_glsl_error(loc, st, "%s", msg);
49 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
51 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
54 static bool match_layout_qualifier(const char *s1, const char *s2,
55 _mesa_glsl_parse_state *state)
57 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
59 * "The tokens in any layout-qualifier-id-list ... are not case
60 * sensitive, unless explicitly noted otherwise."
62 * The text "unless explicitly noted otherwise" appears to be
63 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
66 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
69 * "As for other identifiers, they are case sensitive."
71 * So we need to do a case-sensitive or a case-insensitive match,
72 * depending on whether we are compiling for GLSL ES.
75 return strcmp(s1, s2);
77 return strcasecmp(s1, s2);
95 %lex-param {struct _mesa_glsl_parse_state *state}
96 %parse-param {struct _mesa_glsl_parse_state *state}
103 const char *identifier;
105 struct ast_type_qualifier type_qualifier;
108 ast_type_specifier *type_specifier;
109 ast_array_specifier *array_specifier;
110 ast_fully_specified_type *fully_specified_type;
111 ast_function *function;
112 ast_parameter_declarator *parameter_declarator;
113 ast_function_definition *function_definition;
114 ast_compound_statement *compound_statement;
115 ast_expression *expression;
116 ast_declarator_list *declarator_list;
117 ast_struct_specifier *struct_specifier;
118 ast_declaration *declaration;
119 ast_switch_body *switch_body;
120 ast_case_label *case_label;
121 ast_case_label_list *case_label_list;
122 ast_case_statement *case_statement;
123 ast_case_statement_list *case_statement_list;
124 ast_interface_block *interface_block;
125 ast_subroutine_list *subroutine_list;
128 ast_expression *rest;
129 } for_rest_statement;
132 ast_node *then_statement;
133 ast_node *else_statement;
134 } selection_rest_statement;
136 const glsl_type *type;
139 %token ATTRIBUTE CONST_TOK
140 %token <type> BASIC_TYPE_TOK
141 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
142 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
143 %token NOPERSPECTIVE FLAT SMOOTH
144 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
145 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
147 %token STRUCT VOID_TOK WHILE
148 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
149 %type <identifier> any_identifier
150 %type <interface_block> instance_name_opt
151 %token <real> FLOATCONSTANT
152 %token <dreal> DOUBLECONSTANT
153 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
154 %token <n64> INT64CONSTANT UINT64CONSTANT
155 %token <identifier> FIELD_SELECTION
156 %token LEFT_OP RIGHT_OP
157 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
158 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
159 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
161 %token INVARIANT PRECISE
162 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
164 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
165 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
166 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
167 %token PRAGMA_WARNING_ON PRAGMA_WARNING_OFF
168 %token PRAGMA_INVARIANT_ALL
171 /* Reserved words that are not actually used in the grammar.
173 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
174 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
175 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
176 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
178 %token SIZEOF CAST NAMESPACE USING
179 %token RESOURCE PATCH
184 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
186 %type <identifier> variable_identifier
187 %type <node> statement
188 %type <node> statement_list
189 %type <node> simple_statement
190 %type <n> precision_qualifier
191 %type <type_qualifier> type_qualifier
192 %type <type_qualifier> auxiliary_storage_qualifier
193 %type <type_qualifier> storage_qualifier
194 %type <type_qualifier> interpolation_qualifier
195 %type <type_qualifier> layout_qualifier
196 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
197 %type <type_qualifier> interface_block_layout_qualifier
198 %type <type_qualifier> memory_qualifier
199 %type <type_qualifier> subroutine_qualifier
200 %type <subroutine_list> subroutine_type_list
201 %type <type_qualifier> interface_qualifier
202 %type <type_specifier> type_specifier
203 %type <type_specifier> type_specifier_nonarray
204 %type <array_specifier> array_specifier
205 %type <type> basic_type_specifier_nonarray
206 %type <fully_specified_type> fully_specified_type
207 %type <function> function_prototype
208 %type <function> function_header
209 %type <function> function_header_with_parameters
210 %type <function> function_declarator
211 %type <parameter_declarator> parameter_declarator
212 %type <parameter_declarator> parameter_declaration
213 %type <type_qualifier> parameter_qualifier
214 %type <type_qualifier> parameter_direction_qualifier
215 %type <type_specifier> parameter_type_specifier
216 %type <function_definition> function_definition
217 %type <compound_statement> compound_statement_no_new_scope
218 %type <compound_statement> compound_statement
219 %type <node> statement_no_new_scope
220 %type <node> expression_statement
221 %type <expression> expression
222 %type <expression> primary_expression
223 %type <expression> assignment_expression
224 %type <expression> conditional_expression
225 %type <expression> logical_or_expression
226 %type <expression> logical_xor_expression
227 %type <expression> logical_and_expression
228 %type <expression> inclusive_or_expression
229 %type <expression> exclusive_or_expression
230 %type <expression> and_expression
231 %type <expression> equality_expression
232 %type <expression> relational_expression
233 %type <expression> shift_expression
234 %type <expression> additive_expression
235 %type <expression> multiplicative_expression
236 %type <expression> unary_expression
237 %type <expression> constant_expression
238 %type <expression> integer_expression
239 %type <expression> postfix_expression
240 %type <expression> function_call_header_with_parameters
241 %type <expression> function_call_header_no_parameters
242 %type <expression> function_call_header
243 %type <expression> function_call_generic
244 %type <expression> function_call_or_method
245 %type <expression> function_call
246 %type <n> assignment_operator
247 %type <n> unary_operator
248 %type <expression> function_identifier
249 %type <node> external_declaration
250 %type <node> pragma_statement
251 %type <declarator_list> init_declarator_list
252 %type <declarator_list> single_declaration
253 %type <expression> initializer
254 %type <expression> initializer_list
255 %type <node> declaration
256 %type <node> declaration_statement
257 %type <node> jump_statement
258 %type <node> interface_block
259 %type <interface_block> basic_interface_block
260 %type <struct_specifier> struct_specifier
261 %type <declarator_list> struct_declaration_list
262 %type <declarator_list> struct_declaration
263 %type <declaration> struct_declarator
264 %type <declaration> struct_declarator_list
265 %type <declarator_list> member_list
266 %type <declarator_list> member_declaration
267 %type <node> selection_statement
268 %type <selection_rest_statement> selection_rest_statement
269 %type <node> switch_statement
270 %type <switch_body> switch_body
271 %type <case_label_list> case_label_list
272 %type <case_label> case_label
273 %type <case_statement> case_statement
274 %type <case_statement_list> case_statement_list
275 %type <node> iteration_statement
276 %type <node> condition
277 %type <node> conditionopt
278 %type <node> for_init_statement
279 %type <for_rest_statement> for_rest_statement
280 %type <node> layout_defaults
281 %type <type_qualifier> layout_uniform_defaults
282 %type <type_qualifier> layout_buffer_defaults
283 %type <type_qualifier> layout_in_defaults
284 %type <type_qualifier> layout_out_defaults
290 version_statement extension_statement_list
292 _mesa_glsl_initialize_types(state);
294 external_declaration_list
296 delete state->symbols;
297 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
298 if (state->es_shader) {
299 if (state->stage == MESA_SHADER_FRAGMENT) {
300 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
302 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
303 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
305 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
306 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
307 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
308 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
310 _mesa_glsl_initialize_types(state);
315 /* blank - no #version specified: defaults are already set */
316 | VERSION_TOK INTCONSTANT EOL
318 state->process_version_directive(&@2, $2, NULL);
323 | VERSION_TOK INTCONSTANT any_identifier EOL
325 state->process_version_directive(&@2, $2, $3);
333 PRAGMA_DEBUG_ON EOL { $$ = NULL; }
334 | PRAGMA_DEBUG_OFF EOL { $$ = NULL; }
335 | PRAGMA_OPTIMIZE_ON EOL { $$ = NULL; }
336 | PRAGMA_OPTIMIZE_OFF EOL { $$ = NULL; }
337 | PRAGMA_INVARIANT_ALL EOL
339 /* Pragma invariant(all) cannot be used in a fragment shader.
341 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
343 * "It is an error to use this pragma in a fragment shader."
345 if (state->is_version(120, 300) &&
346 state->stage == MESA_SHADER_FRAGMENT) {
347 _mesa_glsl_error(& @1, state,
348 "pragma `invariant(all)' cannot be used "
349 "in a fragment shader.");
350 } else if (!state->is_version(120, 100)) {
351 _mesa_glsl_warning(& @1, state,
352 "pragma `invariant(all)' not supported in %s "
353 "(GLSL ES 1.00 or GLSL 1.20 required)",
354 state->get_version_string());
356 state->all_invariant = true;
361 | PRAGMA_WARNING_ON EOL
363 void *mem_ctx = state->linalloc;
364 $$ = new(mem_ctx) ast_warnings_toggle(true);
366 | PRAGMA_WARNING_OFF EOL
368 void *mem_ctx = state->linalloc;
369 $$ = new(mem_ctx) ast_warnings_toggle(false);
373 extension_statement_list:
375 | extension_statement_list extension_statement
385 EXTENSION any_identifier COLON any_identifier EOL
387 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
393 external_declaration_list:
396 /* FINISHME: The NULL test is required because pragmas are set to
397 * FINISHME: NULL. (See production rule for external_declaration.)
400 state->translation_unit.push_tail(& $1->link);
402 | external_declaration_list external_declaration
404 /* FINISHME: The NULL test is required because pragmas are set to
405 * FINISHME: NULL. (See production rule for external_declaration.)
408 state->translation_unit.push_tail(& $2->link);
410 | external_declaration_list extension_statement {
411 if (!state->allow_extension_directive_midshader) {
412 _mesa_glsl_error(& @2, state,
413 "#extension directive is not allowed "
414 "in the middle of a shader");
428 void *ctx = state->linalloc;
429 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
430 $$->set_location(@1);
431 $$->primary_expression.identifier = $1;
435 void *ctx = state->linalloc;
436 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
437 $$->set_location(@1);
438 $$->primary_expression.int_constant = $1;
442 void *ctx = state->linalloc;
443 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
444 $$->set_location(@1);
445 $$->primary_expression.uint_constant = $1;
449 void *ctx = state->linalloc;
450 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
451 $$->set_location(@1);
452 $$->primary_expression.int64_constant = $1;
456 void *ctx = state->linalloc;
457 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
458 $$->set_location(@1);
459 $$->primary_expression.uint64_constant = $1;
463 void *ctx = state->linalloc;
464 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
465 $$->set_location(@1);
466 $$->primary_expression.float_constant = $1;
470 void *ctx = state->linalloc;
471 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
472 $$->set_location(@1);
473 $$->primary_expression.double_constant = $1;
477 void *ctx = state->linalloc;
478 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
479 $$->set_location(@1);
480 $$->primary_expression.bool_constant = $1;
490 | postfix_expression '[' integer_expression ']'
492 void *ctx = state->linalloc;
493 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
494 $$->set_location_range(@1, @4);
500 | postfix_expression DOT_TOK FIELD_SELECTION
502 void *ctx = state->linalloc;
503 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
504 $$->set_location_range(@1, @3);
505 $$->primary_expression.identifier = $3;
507 | postfix_expression INC_OP
509 void *ctx = state->linalloc;
510 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
511 $$->set_location_range(@1, @2);
513 | postfix_expression DEC_OP
515 void *ctx = state->linalloc;
516 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
517 $$->set_location_range(@1, @2);
526 function_call_or_method
529 function_call_or_method:
530 function_call_generic
533 function_call_generic:
534 function_call_header_with_parameters ')'
535 | function_call_header_no_parameters ')'
538 function_call_header_no_parameters:
539 function_call_header VOID_TOK
540 | function_call_header
543 function_call_header_with_parameters:
544 function_call_header assignment_expression
547 $$->set_location(@1);
548 $$->expressions.push_tail(& $2->link);
550 | function_call_header_with_parameters ',' assignment_expression
553 $$->set_location(@1);
554 $$->expressions.push_tail(& $3->link);
558 // Grammar Note: Constructors look like functions, but lexical
559 // analysis recognized most of them as keywords. They are now
560 // recognized through "type_specifier".
561 function_call_header:
562 function_identifier '('
568 void *ctx = state->linalloc;
569 $$ = new(ctx) ast_function_expression($1);
570 $$->set_location(@1);
574 void *ctx = state->linalloc;
575 $$ = new(ctx) ast_function_expression($1);
576 $$->set_location(@1);
580 // Grammar Note: Constructors look like methods, but lexical
581 // analysis recognized most of them as keywords. They are now
582 // recognized through "type_specifier".
584 // Grammar Note: No traditional style type casts.
587 | INC_OP unary_expression
589 void *ctx = state->linalloc;
590 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
591 $$->set_location(@1);
593 | DEC_OP unary_expression
595 void *ctx = state->linalloc;
596 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
597 $$->set_location(@1);
599 | unary_operator unary_expression
601 void *ctx = state->linalloc;
602 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
603 $$->set_location_range(@1, @2);
607 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
609 '+' { $$ = ast_plus; }
610 | '-' { $$ = ast_neg; }
611 | '!' { $$ = ast_logic_not; }
612 | '~' { $$ = ast_bit_not; }
615 multiplicative_expression:
617 | multiplicative_expression '*' unary_expression
619 void *ctx = state->linalloc;
620 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
621 $$->set_location_range(@1, @3);
623 | multiplicative_expression '/' unary_expression
625 void *ctx = state->linalloc;
626 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
627 $$->set_location_range(@1, @3);
629 | multiplicative_expression '%' unary_expression
631 void *ctx = state->linalloc;
632 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
633 $$->set_location_range(@1, @3);
638 multiplicative_expression
639 | additive_expression '+' multiplicative_expression
641 void *ctx = state->linalloc;
642 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
643 $$->set_location_range(@1, @3);
645 | additive_expression '-' multiplicative_expression
647 void *ctx = state->linalloc;
648 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
649 $$->set_location_range(@1, @3);
655 | shift_expression LEFT_OP additive_expression
657 void *ctx = state->linalloc;
658 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
659 $$->set_location_range(@1, @3);
661 | shift_expression RIGHT_OP additive_expression
663 void *ctx = state->linalloc;
664 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
665 $$->set_location_range(@1, @3);
669 relational_expression:
671 | relational_expression '<' shift_expression
673 void *ctx = state->linalloc;
674 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
675 $$->set_location_range(@1, @3);
677 | relational_expression '>' shift_expression
679 void *ctx = state->linalloc;
680 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
681 $$->set_location_range(@1, @3);
683 | relational_expression LE_OP shift_expression
685 void *ctx = state->linalloc;
686 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
687 $$->set_location_range(@1, @3);
689 | relational_expression GE_OP shift_expression
691 void *ctx = state->linalloc;
692 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
693 $$->set_location_range(@1, @3);
698 relational_expression
699 | equality_expression EQ_OP relational_expression
701 void *ctx = state->linalloc;
702 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
703 $$->set_location_range(@1, @3);
705 | equality_expression NE_OP relational_expression
707 void *ctx = state->linalloc;
708 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
709 $$->set_location_range(@1, @3);
715 | and_expression '&' equality_expression
717 void *ctx = state->linalloc;
718 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
719 $$->set_location_range(@1, @3);
723 exclusive_or_expression:
725 | exclusive_or_expression '^' and_expression
727 void *ctx = state->linalloc;
728 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
729 $$->set_location_range(@1, @3);
733 inclusive_or_expression:
734 exclusive_or_expression
735 | inclusive_or_expression '|' exclusive_or_expression
737 void *ctx = state->linalloc;
738 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
739 $$->set_location_range(@1, @3);
743 logical_and_expression:
744 inclusive_or_expression
745 | logical_and_expression AND_OP inclusive_or_expression
747 void *ctx = state->linalloc;
748 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
749 $$->set_location_range(@1, @3);
753 logical_xor_expression:
754 logical_and_expression
755 | logical_xor_expression XOR_OP logical_and_expression
757 void *ctx = state->linalloc;
758 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
759 $$->set_location_range(@1, @3);
763 logical_or_expression:
764 logical_xor_expression
765 | logical_or_expression OR_OP logical_xor_expression
767 void *ctx = state->linalloc;
768 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
769 $$->set_location_range(@1, @3);
773 conditional_expression:
774 logical_or_expression
775 | logical_or_expression '?' expression ':' assignment_expression
777 void *ctx = state->linalloc;
778 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
779 $$->set_location_range(@1, @5);
783 assignment_expression:
784 conditional_expression
785 | unary_expression assignment_operator assignment_expression
787 void *ctx = state->linalloc;
788 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
789 $$->set_location_range(@1, @3);
794 '=' { $$ = ast_assign; }
795 | MUL_ASSIGN { $$ = ast_mul_assign; }
796 | DIV_ASSIGN { $$ = ast_div_assign; }
797 | MOD_ASSIGN { $$ = ast_mod_assign; }
798 | ADD_ASSIGN { $$ = ast_add_assign; }
799 | SUB_ASSIGN { $$ = ast_sub_assign; }
800 | LEFT_ASSIGN { $$ = ast_ls_assign; }
801 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
802 | AND_ASSIGN { $$ = ast_and_assign; }
803 | XOR_ASSIGN { $$ = ast_xor_assign; }
804 | OR_ASSIGN { $$ = ast_or_assign; }
808 assignment_expression
812 | expression ',' assignment_expression
814 void *ctx = state->linalloc;
815 if ($1->oper != ast_sequence) {
816 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
817 $$->set_location_range(@1, @3);
818 $$->expressions.push_tail(& $1->link);
823 $$->expressions.push_tail(& $3->link);
828 conditional_expression
832 function_prototype ';'
834 state->symbols->pop_scope();
837 | init_declarator_list ';'
841 | PRECISION precision_qualifier type_specifier ';'
843 $3->default_precision = $2;
848 ast_interface_block *block = (ast_interface_block *) $1;
849 if (block->layout.has_layout() || block->layout.has_memory()) {
850 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
854 block->layout = block->default_layout;
855 if (!block->layout.push_to_global(& @1, state)) {
863 function_declarator ')'
868 | function_header_with_parameters
871 function_header_with_parameters:
872 function_header parameter_declaration
875 $$->parameters.push_tail(& $2->link);
877 | function_header_with_parameters ',' parameter_declaration
880 $$->parameters.push_tail(& $3->link);
885 fully_specified_type variable_identifier '('
887 void *ctx = state->linalloc;
888 $$ = new(ctx) ast_function();
889 $$->set_location(@2);
890 $$->return_type = $1;
893 if ($1->qualifier.is_subroutine_decl()) {
894 /* add type for IDENTIFIER search */
895 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
897 state->symbols->add_function(new(state) ir_function($2));
898 state->symbols->push_scope();
902 parameter_declarator:
903 type_specifier any_identifier
905 void *ctx = state->linalloc;
906 $$ = new(ctx) ast_parameter_declarator();
907 $$->set_location_range(@1, @2);
908 $$->type = new(ctx) ast_fully_specified_type();
909 $$->type->set_location(@1);
910 $$->type->specifier = $1;
912 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
914 | layout_qualifier type_specifier any_identifier
916 if (state->allow_layout_qualifier_on_function_parameter) {
917 void *ctx = state->linalloc;
918 $$ = new(ctx) ast_parameter_declarator();
919 $$->set_location_range(@2, @3);
920 $$->type = new(ctx) ast_fully_specified_type();
921 $$->type->set_location(@2);
922 $$->type->specifier = $2;
924 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
926 _mesa_glsl_error(&@1, state,
927 "is is not allowed on function parameter");
931 | type_specifier any_identifier array_specifier
933 void *ctx = state->linalloc;
934 $$ = new(ctx) ast_parameter_declarator();
935 $$->set_location_range(@1, @3);
936 $$->type = new(ctx) ast_fully_specified_type();
937 $$->type->set_location(@1);
938 $$->type->specifier = $1;
940 $$->array_specifier = $3;
941 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
945 parameter_declaration:
946 parameter_qualifier parameter_declarator
949 $$->type->qualifier = $1;
950 if (!$$->type->qualifier.push_to_global(& @1, state)) {
954 | parameter_qualifier parameter_type_specifier
956 void *ctx = state->linalloc;
957 $$ = new(ctx) ast_parameter_declarator();
958 $$->set_location(@2);
959 $$->type = new(ctx) ast_fully_specified_type();
960 $$->type->set_location_range(@1, @2);
961 $$->type->qualifier = $1;
962 if (!$$->type->qualifier.push_to_global(& @1, state)) {
965 $$->type->specifier = $2;
972 memset(& $$, 0, sizeof($$));
974 | CONST_TOK parameter_qualifier
976 if ($2.flags.q.constant)
977 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
980 $$.flags.q.constant = 1;
982 | PRECISE parameter_qualifier
984 if ($2.flags.q.precise)
985 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
988 $$.flags.q.precise = 1;
990 | parameter_direction_qualifier parameter_qualifier
992 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
993 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
995 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
996 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
1000 $$.merge_qualifier(&@1, state, $2, false);
1002 | precision_qualifier parameter_qualifier
1004 if ($2.precision != ast_precision_none)
1005 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1007 if (!state->has_420pack_or_es31() &&
1009 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1014 | memory_qualifier parameter_qualifier
1017 $$.merge_qualifier(&@1, state, $2, false);
1020 parameter_direction_qualifier:
1023 memset(& $$, 0, sizeof($$));
1028 memset(& $$, 0, sizeof($$));
1033 memset(& $$, 0, sizeof($$));
1039 parameter_type_specifier:
1043 init_declarator_list:
1045 | init_declarator_list ',' any_identifier
1047 void *ctx = state->linalloc;
1048 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1049 decl->set_location(@3);
1052 $$->declarations.push_tail(&decl->link);
1053 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1055 | init_declarator_list ',' any_identifier array_specifier
1057 void *ctx = state->linalloc;
1058 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1059 decl->set_location_range(@3, @4);
1062 $$->declarations.push_tail(&decl->link);
1063 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1065 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1067 void *ctx = state->linalloc;
1068 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1069 decl->set_location_range(@3, @4);
1072 $$->declarations.push_tail(&decl->link);
1073 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1075 | init_declarator_list ',' any_identifier '=' initializer
1077 void *ctx = state->linalloc;
1078 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1079 decl->set_location(@3);
1082 $$->declarations.push_tail(&decl->link);
1083 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1087 // Grammar Note: No 'enum', or 'typedef'.
1089 fully_specified_type
1091 void *ctx = state->linalloc;
1092 /* Empty declaration list is valid. */
1093 $$ = new(ctx) ast_declarator_list($1);
1094 $$->set_location(@1);
1096 | fully_specified_type any_identifier
1098 void *ctx = state->linalloc;
1099 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1100 decl->set_location(@2);
1102 $$ = new(ctx) ast_declarator_list($1);
1103 $$->set_location_range(@1, @2);
1104 $$->declarations.push_tail(&decl->link);
1105 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1107 | fully_specified_type any_identifier array_specifier
1109 void *ctx = state->linalloc;
1110 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1111 decl->set_location_range(@2, @3);
1113 $$ = new(ctx) ast_declarator_list($1);
1114 $$->set_location_range(@1, @3);
1115 $$->declarations.push_tail(&decl->link);
1116 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1118 | fully_specified_type any_identifier array_specifier '=' initializer
1120 void *ctx = state->linalloc;
1121 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1122 decl->set_location_range(@2, @3);
1124 $$ = new(ctx) ast_declarator_list($1);
1125 $$->set_location_range(@1, @3);
1126 $$->declarations.push_tail(&decl->link);
1127 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1129 | fully_specified_type any_identifier '=' initializer
1131 void *ctx = state->linalloc;
1132 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1133 decl->set_location(@2);
1135 $$ = new(ctx) ast_declarator_list($1);
1136 $$->set_location_range(@1, @2);
1137 $$->declarations.push_tail(&decl->link);
1138 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1140 | INVARIANT variable_identifier
1142 void *ctx = state->linalloc;
1143 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1144 decl->set_location(@2);
1146 $$ = new(ctx) ast_declarator_list(NULL);
1147 $$->set_location_range(@1, @2);
1148 $$->invariant = true;
1150 $$->declarations.push_tail(&decl->link);
1152 | PRECISE variable_identifier
1154 void *ctx = state->linalloc;
1155 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1156 decl->set_location(@2);
1158 $$ = new(ctx) ast_declarator_list(NULL);
1159 $$->set_location_range(@1, @2);
1162 $$->declarations.push_tail(&decl->link);
1166 fully_specified_type:
1169 void *ctx = state->linalloc;
1170 $$ = new(ctx) ast_fully_specified_type();
1171 $$->set_location(@1);
1174 | type_qualifier type_specifier
1176 void *ctx = state->linalloc;
1177 $$ = new(ctx) ast_fully_specified_type();
1178 $$->set_location_range(@1, @2);
1180 if (!$$->qualifier.push_to_global(& @1, state)) {
1184 if ($$->specifier->structure != NULL &&
1185 $$->specifier->structure->is_declaration) {
1186 $$->specifier->structure->layout = &$$->qualifier;
1192 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1198 layout_qualifier_id_list:
1200 | layout_qualifier_id_list ',' layout_qualifier_id
1203 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1209 layout_qualifier_id:
1212 memset(& $$, 0, sizeof($$));
1214 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1215 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1216 state->is_version(150, 0))) {
1217 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1218 $$.flags.q.origin_upper_left = 1;
1219 } else if (match_layout_qualifier($1, "pixel_center_integer",
1221 $$.flags.q.pixel_center_integer = 1;
1224 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1225 _mesa_glsl_warning(& @1, state,
1226 "GL_ARB_fragment_coord_conventions layout "
1227 "identifier `%s' used", $1);
1231 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1233 (state->AMD_conservative_depth_enable ||
1234 state->ARB_conservative_depth_enable ||
1235 state->is_version(420, 0))) {
1236 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1237 $$.flags.q.depth_type = 1;
1238 $$.depth_type = ast_depth_any;
1239 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1240 $$.flags.q.depth_type = 1;
1241 $$.depth_type = ast_depth_greater;
1242 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1243 $$.flags.q.depth_type = 1;
1244 $$.depth_type = ast_depth_less;
1245 } else if (match_layout_qualifier($1, "depth_unchanged",
1247 $$.flags.q.depth_type = 1;
1248 $$.depth_type = ast_depth_unchanged;
1251 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1252 _mesa_glsl_warning(& @1, state,
1253 "GL_AMD_conservative_depth "
1254 "layout qualifier `%s' is used", $1);
1256 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1257 _mesa_glsl_warning(& @1, state,
1258 "GL_ARB_conservative_depth "
1259 "layout qualifier `%s' is used", $1);
1263 /* See also interface_block_layout_qualifier. */
1264 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1265 if (match_layout_qualifier($1, "std140", state) == 0) {
1266 $$.flags.q.std140 = 1;
1267 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1268 $$.flags.q.shared = 1;
1269 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1270 $$.flags.q.std430 = 1;
1271 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1272 $$.flags.q.column_major = 1;
1273 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1274 * below in the interface_block_layout_qualifier rule.
1276 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1279 * Also, this takes care of alternate capitalizations of
1280 * "row_major" (which is necessary because layout qualifiers
1281 * are case-insensitive in desktop GLSL).
1283 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1284 $$.flags.q.row_major = 1;
1285 /* "packed" is a reserved word in GLSL, and its token is
1286 * parsed below in the interface_block_layout_qualifier rule.
1287 * However, we must take care of alternate capitalizations of
1288 * "packed", because layout qualifiers are case-insensitive
1291 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1292 $$.flags.q.packed = 1;
1295 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1296 _mesa_glsl_warning(& @1, state,
1297 "#version 140 / GL_ARB_uniform_buffer_object "
1298 "layout qualifier `%s' is used", $1);
1302 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1304 static const struct {
1308 { "points", GL_POINTS },
1309 { "lines", GL_LINES },
1310 { "lines_adjacency", GL_LINES_ADJACENCY },
1311 { "line_strip", GL_LINE_STRIP },
1312 { "triangles", GL_TRIANGLES },
1313 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1314 { "triangle_strip", GL_TRIANGLE_STRIP },
1316 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1317 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1318 $$.flags.q.prim_type = 1;
1319 $$.prim_type = map[i].e;
1324 if ($$.flags.i && !state->has_geometry_shader() &&
1325 !state->has_tessellation_shader()) {
1326 _mesa_glsl_error(& @1, state, "#version 150 layout "
1327 "qualifier `%s' used", $1);
1331 /* Layout qualifiers for ARB_shader_image_load_store. */
1332 if (state->has_shader_image_load_store()) {
1334 static const struct {
1337 glsl_base_type base_type;
1338 /** Minimum desktop GLSL version required for the image
1339 * format. Use 130 if already present in the original
1342 unsigned required_glsl;
1343 /** Minimum GLSL ES version required for the image format. */
1344 unsigned required_essl;
1345 /* NV_image_formats */
1346 bool nv_image_formats;
1348 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1349 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1350 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1351 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1352 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1353 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1354 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1355 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1356 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1357 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1358 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1359 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1360 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1361 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1362 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1363 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1364 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1365 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1366 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1367 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1368 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1369 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1370 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1371 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1372 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1373 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1374 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, true },
1375 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1376 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1377 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, true },
1378 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1379 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, true },
1380 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1381 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1382 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1383 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1384 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1385 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1386 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1389 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1390 if ((state->is_version(map[i].required_glsl,
1391 map[i].required_essl) ||
1392 (state->NV_image_formats_enable &&
1393 map[i].nv_image_formats)) &&
1394 match_layout_qualifier($1, map[i].name, state) == 0) {
1395 $$.flags.q.explicit_image_format = 1;
1396 $$.image_format = map[i].format;
1397 $$.image_base_type = map[i].base_type;
1405 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1406 /* From section 4.4.1.3 of the GLSL 4.50 specification
1407 * (Fragment Shader Inputs):
1409 * "Fragment shaders also allow the following layout
1410 * qualifier on in only (not with variable declarations)
1411 * layout-qualifier-id
1412 * early_fragment_tests
1415 if (state->stage != MESA_SHADER_FRAGMENT) {
1416 _mesa_glsl_error(& @1, state,
1417 "early_fragment_tests layout qualifier only "
1418 "valid in fragment shaders");
1421 $$.flags.q.early_fragment_tests = 1;
1424 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1425 if (state->stage != MESA_SHADER_FRAGMENT) {
1426 _mesa_glsl_error(& @1, state,
1427 "inner_coverage layout qualifier only "
1428 "valid in fragment shaders");
1431 if (state->INTEL_conservative_rasterization_enable) {
1432 $$.flags.q.inner_coverage = 1;
1434 _mesa_glsl_error(& @1, state,
1435 "inner_coverage layout qualifier present, "
1436 "but the INTEL_conservative_rasterization extension "
1441 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1442 if (state->stage != MESA_SHADER_FRAGMENT) {
1443 _mesa_glsl_error(& @1, state,
1444 "post_depth_coverage layout qualifier only "
1445 "valid in fragment shaders");
1448 if (state->ARB_post_depth_coverage_enable ||
1449 state->INTEL_conservative_rasterization_enable) {
1450 $$.flags.q.post_depth_coverage = 1;
1452 _mesa_glsl_error(& @1, state,
1453 "post_depth_coverage layout qualifier present, "
1454 "but the GL_ARB_post_depth_coverage extension "
1459 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1460 _mesa_glsl_error(& @1, state,
1461 "post_depth_coverage & inner_coverage layout qualifiers "
1462 "are mutually exclusive");
1466 const bool pixel_interlock_ordered = match_layout_qualifier($1,
1467 "pixel_interlock_ordered", state) == 0;
1468 const bool pixel_interlock_unordered = match_layout_qualifier($1,
1469 "pixel_interlock_unordered", state) == 0;
1470 const bool sample_interlock_ordered = match_layout_qualifier($1,
1471 "sample_interlock_ordered", state) == 0;
1472 const bool sample_interlock_unordered = match_layout_qualifier($1,
1473 "sample_interlock_unordered", state) == 0;
1475 if (pixel_interlock_ordered + pixel_interlock_unordered +
1476 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1477 state->stage != MESA_SHADER_FRAGMENT) {
1478 _mesa_glsl_error(& @1, state, "interlock layout qualifiers: "
1479 "pixel_interlock_ordered, pixel_interlock_unordered, "
1480 "sample_interlock_ordered and sample_interlock_unordered, "
1481 "only valid in fragment shader input layout declaration.");
1482 } else if (pixel_interlock_ordered + pixel_interlock_unordered +
1483 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1484 !state->ARB_fragment_shader_interlock_enable &&
1485 !state->NV_fragment_shader_interlock_enable) {
1486 _mesa_glsl_error(& @1, state,
1487 "interlock layout qualifier present, but the "
1488 "GL_ARB_fragment_shader_interlock or "
1489 "GL_NV_fragment_shader_interlock extension is not "
1492 $$.flags.q.pixel_interlock_ordered = pixel_interlock_ordered;
1493 $$.flags.q.pixel_interlock_unordered = pixel_interlock_unordered;
1494 $$.flags.q.sample_interlock_ordered = sample_interlock_ordered;
1495 $$.flags.q.sample_interlock_unordered = sample_interlock_unordered;
1498 /* Layout qualifiers for tessellation evaluation shaders. */
1500 static const struct {
1504 /* triangles already parsed by gs-specific code */
1505 { "quads", GL_QUADS },
1506 { "isolines", GL_ISOLINES },
1508 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1509 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1510 $$.flags.q.prim_type = 1;
1511 $$.prim_type = map[i].e;
1516 if ($$.flags.i && !state->has_tessellation_shader()) {
1517 _mesa_glsl_error(& @1, state,
1518 "primitive mode qualifier `%s' requires "
1519 "GLSL 4.00 or ARB_tessellation_shader", $1);
1523 static const struct {
1525 enum gl_tess_spacing e;
1527 { "equal_spacing", TESS_SPACING_EQUAL },
1528 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1529 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1531 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1532 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1533 $$.flags.q.vertex_spacing = 1;
1534 $$.vertex_spacing = map[i].e;
1539 if ($$.flags.i && !state->has_tessellation_shader()) {
1540 _mesa_glsl_error(& @1, state,
1541 "vertex spacing qualifier `%s' requires "
1542 "GLSL 4.00 or ARB_tessellation_shader", $1);
1546 if (match_layout_qualifier($1, "cw", state) == 0) {
1547 $$.flags.q.ordering = 1;
1548 $$.ordering = GL_CW;
1549 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1550 $$.flags.q.ordering = 1;
1551 $$.ordering = GL_CCW;
1554 if ($$.flags.i && !state->has_tessellation_shader()) {
1555 _mesa_glsl_error(& @1, state,
1556 "ordering qualifier `%s' requires "
1557 "GLSL 4.00 or ARB_tessellation_shader", $1);
1561 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1562 $$.flags.q.point_mode = 1;
1563 $$.point_mode = true;
1566 if ($$.flags.i && !state->has_tessellation_shader()) {
1567 _mesa_glsl_error(& @1, state,
1568 "qualifier `point_mode' requires "
1569 "GLSL 4.00 or ARB_tessellation_shader");
1574 static const struct {
1578 { "blend_support_multiply", BLEND_MULTIPLY },
1579 { "blend_support_screen", BLEND_SCREEN },
1580 { "blend_support_overlay", BLEND_OVERLAY },
1581 { "blend_support_darken", BLEND_DARKEN },
1582 { "blend_support_lighten", BLEND_LIGHTEN },
1583 { "blend_support_colordodge", BLEND_COLORDODGE },
1584 { "blend_support_colorburn", BLEND_COLORBURN },
1585 { "blend_support_hardlight", BLEND_HARDLIGHT },
1586 { "blend_support_softlight", BLEND_SOFTLIGHT },
1587 { "blend_support_difference", BLEND_DIFFERENCE },
1588 { "blend_support_exclusion", BLEND_EXCLUSION },
1589 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1590 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1591 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1592 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1593 { "blend_support_all_equations", BLEND_ALL },
1595 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1596 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1597 $$.flags.q.blend_support = 1;
1598 state->fs_blend_support |= map[i].mask;
1604 !state->KHR_blend_equation_advanced_enable &&
1605 !state->is_version(0, 320)) {
1606 _mesa_glsl_error(& @1, state,
1607 "advanced blending layout qualifiers require "
1608 "ESSL 3.20 or KHR_blend_equation_advanced");
1611 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1612 _mesa_glsl_error(& @1, state,
1613 "advanced blending layout qualifiers only "
1614 "valid in fragment shaders");
1618 /* Layout qualifiers for ARB_compute_variable_group_size. */
1620 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1621 $$.flags.q.local_size_variable = 1;
1624 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1625 _mesa_glsl_error(& @1, state,
1626 "qualifier `local_size_variable` requires "
1627 "ARB_compute_variable_group_size");
1631 /* Layout qualifiers for ARB_bindless_texture. */
1633 if (match_layout_qualifier($1, "bindless_sampler", state) == 0)
1634 $$.flags.q.bindless_sampler = 1;
1635 if (match_layout_qualifier($1, "bound_sampler", state) == 0)
1636 $$.flags.q.bound_sampler = 1;
1638 if (state->has_shader_image_load_store()) {
1639 if (match_layout_qualifier($1, "bindless_image", state) == 0)
1640 $$.flags.q.bindless_image = 1;
1641 if (match_layout_qualifier($1, "bound_image", state) == 0)
1642 $$.flags.q.bound_image = 1;
1645 if ($$.flags.i && !state->has_bindless()) {
1646 _mesa_glsl_error(& @1, state,
1647 "qualifier `%s` requires "
1648 "ARB_bindless_texture", $1);
1653 state->EXT_shader_framebuffer_fetch_non_coherent_enable) {
1654 if (match_layout_qualifier($1, "noncoherent", state) == 0)
1655 $$.flags.q.non_coherent = 1;
1658 // Layout qualifiers for NV_compute_shader_derivatives.
1660 if (match_layout_qualifier($1, "derivative_group_quadsNV", state) == 0) {
1661 $$.flags.q.derivative_group = 1;
1662 $$.derivative_group = DERIVATIVE_GROUP_QUADS;
1663 } else if (match_layout_qualifier($1, "derivative_group_linearNV", state) == 0) {
1664 $$.flags.q.derivative_group = 1;
1665 $$.derivative_group = DERIVATIVE_GROUP_LINEAR;
1669 if (!state->has_compute_shader()) {
1670 _mesa_glsl_error(& @1, state,
1671 "qualifier `%s' requires "
1672 "a compute shader", $1);
1675 if (!state->NV_compute_shader_derivatives_enable) {
1676 _mesa_glsl_error(& @1, state,
1677 "qualifier `%s' requires "
1678 "NV_compute_shader_derivatives", $1);
1681 if (state->NV_compute_shader_derivatives_warn) {
1682 _mesa_glsl_warning(& @1, state,
1683 "NV_compute_shader_derivatives layout "
1684 "qualifier `%s' used", $1);
1690 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1695 | any_identifier '=' constant_expression
1697 memset(& $$, 0, sizeof($$));
1698 void *ctx = state->linalloc;
1700 if ($3->oper != ast_int_constant &&
1701 $3->oper != ast_uint_constant &&
1702 !state->has_enhanced_layouts()) {
1703 _mesa_glsl_error(& @1, state,
1704 "compile-time constant expressions require "
1705 "GLSL 4.40 or ARB_enhanced_layouts");
1708 if (match_layout_qualifier("align", $1, state) == 0) {
1709 if (!state->has_enhanced_layouts()) {
1710 _mesa_glsl_error(& @1, state,
1711 "align qualifier requires "
1712 "GLSL 4.40 or ARB_enhanced_layouts");
1714 $$.flags.q.explicit_align = 1;
1719 if (match_layout_qualifier("location", $1, state) == 0) {
1720 $$.flags.q.explicit_location = 1;
1722 if ($$.flags.q.attribute == 1 &&
1723 state->ARB_explicit_attrib_location_warn) {
1724 _mesa_glsl_warning(& @1, state,
1725 "GL_ARB_explicit_attrib_location layout "
1726 "identifier `%s' used", $1);
1731 if (match_layout_qualifier("component", $1, state) == 0) {
1732 if (!state->has_enhanced_layouts()) {
1733 _mesa_glsl_error(& @1, state,
1734 "component qualifier requires "
1735 "GLSL 4.40 or ARB_enhanced_layouts");
1737 $$.flags.q.explicit_component = 1;
1742 if (match_layout_qualifier("index", $1, state) == 0) {
1743 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1744 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1748 $$.flags.q.explicit_index = 1;
1752 if ((state->has_420pack_or_es31() ||
1753 state->has_atomic_counters() ||
1754 state->has_shader_storage_buffer_objects()) &&
1755 match_layout_qualifier("binding", $1, state) == 0) {
1756 $$.flags.q.explicit_binding = 1;
1760 if ((state->has_atomic_counters() ||
1761 state->has_enhanced_layouts()) &&
1762 match_layout_qualifier("offset", $1, state) == 0) {
1763 $$.flags.q.explicit_offset = 1;
1767 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1768 $$.flags.q.max_vertices = 1;
1769 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1770 if (!state->has_geometry_shader()) {
1771 _mesa_glsl_error(& @3, state,
1772 "#version 150 max_vertices qualifier "
1777 if (state->stage == MESA_SHADER_GEOMETRY) {
1778 if (match_layout_qualifier("stream", $1, state) == 0 &&
1779 state->check_explicit_attrib_stream_allowed(& @3)) {
1780 $$.flags.q.stream = 1;
1781 $$.flags.q.explicit_stream = 1;
1786 if (state->has_enhanced_layouts()) {
1787 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1788 $$.flags.q.xfb_buffer = 1;
1789 $$.flags.q.explicit_xfb_buffer = 1;
1793 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1794 $$.flags.q.explicit_xfb_offset = 1;
1798 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1799 $$.flags.q.xfb_stride = 1;
1800 $$.flags.q.explicit_xfb_stride = 1;
1805 static const char * const local_size_qualifiers[3] = {
1810 for (int i = 0; i < 3; i++) {
1811 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1813 if (!state->has_compute_shader()) {
1814 _mesa_glsl_error(& @3, state,
1815 "%s qualifier requires GLSL 4.30 or "
1816 "GLSL ES 3.10 or ARB_compute_shader",
1817 local_size_qualifiers[i]);
1820 $$.flags.q.local_size |= (1 << i);
1821 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1827 if (match_layout_qualifier("invocations", $1, state) == 0) {
1828 $$.flags.q.invocations = 1;
1829 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1830 if (!state->is_version(400, 320) &&
1831 !state->ARB_gpu_shader5_enable &&
1832 !state->OES_geometry_shader_enable &&
1833 !state->EXT_geometry_shader_enable) {
1834 _mesa_glsl_error(& @3, state,
1835 "GL_ARB_gpu_shader5 invocations "
1836 "qualifier specified", $3);
1840 /* Layout qualifiers for tessellation control shaders. */
1841 if (match_layout_qualifier("vertices", $1, state) == 0) {
1842 $$.flags.q.vertices = 1;
1843 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1844 if (!state->has_tessellation_shader()) {
1845 _mesa_glsl_error(& @1, state,
1846 "vertices qualifier requires GLSL 4.00 or "
1847 "ARB_tessellation_shader");
1851 /* If the identifier didn't match any known layout identifiers,
1855 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1860 | interface_block_layout_qualifier
1863 /* Layout qualifiers for ARB_uniform_buffer_object. */
1864 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1865 _mesa_glsl_error(& @1, state,
1866 "#version 140 / GL_ARB_uniform_buffer_object "
1867 "layout qualifier `%s' is used", $1);
1868 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1869 _mesa_glsl_warning(& @1, state,
1870 "#version 140 / GL_ARB_uniform_buffer_object "
1871 "layout qualifier `%s' is used", $1);
1876 /* This is a separate language rule because we parse these as tokens
1877 * (due to them being reserved keywords) instead of identifiers like
1878 * most qualifiers. See the any_identifier path of
1879 * layout_qualifier_id for the others.
1881 * Note that since layout qualifiers are case-insensitive in desktop
1882 * GLSL, all of these qualifiers need to be handled as identifiers as
1883 * well (by the any_identifier path of layout_qualifier_id).
1885 interface_block_layout_qualifier:
1888 memset(& $$, 0, sizeof($$));
1889 $$.flags.q.row_major = 1;
1893 memset(& $$, 0, sizeof($$));
1894 $$.flags.q.packed = 1;
1898 memset(& $$, 0, sizeof($$));
1899 $$.flags.q.shared = 1;
1903 subroutine_qualifier:
1906 memset(& $$, 0, sizeof($$));
1907 $$.flags.q.subroutine = 1;
1909 | SUBROUTINE '(' subroutine_type_list ')'
1911 memset(& $$, 0, sizeof($$));
1912 $$.flags.q.subroutine = 1;
1913 $$.subroutine_list = $3;
1917 subroutine_type_list:
1920 void *ctx = state->linalloc;
1921 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1922 decl->set_location(@1);
1924 $$ = new(ctx) ast_subroutine_list();
1925 $$->declarations.push_tail(&decl->link);
1927 | subroutine_type_list ',' any_identifier
1929 void *ctx = state->linalloc;
1930 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1931 decl->set_location(@3);
1934 $$->declarations.push_tail(&decl->link);
1938 interpolation_qualifier:
1941 memset(& $$, 0, sizeof($$));
1942 $$.flags.q.smooth = 1;
1946 memset(& $$, 0, sizeof($$));
1947 $$.flags.q.flat = 1;
1951 memset(& $$, 0, sizeof($$));
1952 $$.flags.q.noperspective = 1;
1957 /* Single qualifiers */
1960 memset(& $$, 0, sizeof($$));
1961 $$.flags.q.invariant = 1;
1965 memset(& $$, 0, sizeof($$));
1966 $$.flags.q.precise = 1;
1968 | auxiliary_storage_qualifier
1970 | interpolation_qualifier
1973 | subroutine_qualifier
1974 | precision_qualifier
1976 memset(&$$, 0, sizeof($$));
1980 /* Multiple qualifiers:
1981 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1982 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1984 * invariant interpolation auxiliary storage precision ...or...
1985 * layout storage precision
1987 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1988 * side don't contain any that must appear on the left hand side.
1989 * For example, when processing a storage qualifier, we check that there are
1990 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1992 | PRECISE type_qualifier
1994 if ($2.flags.q.precise)
1995 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1998 $$.flags.q.precise = 1;
2000 | INVARIANT type_qualifier
2002 if ($2.flags.q.invariant)
2003 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
2005 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
2006 _mesa_glsl_error(&@1, state,
2007 "\"invariant\" must come after \"precise\"");
2010 $$.flags.q.invariant = 1;
2012 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
2014 * "Only variables output from a shader can be candidates for invariance.
2015 * This includes user-defined output variables and the built-in output
2016 * variables. As only outputs can be declared as invariant, an invariant
2017 * output from one shader stage will still match an input of a subsequent
2018 * stage without the input being declared as invariant."
2020 * On the desktop side, this text first appears in GLSL 4.30.
2022 if (state->is_version(430, 300) && $$.flags.q.in)
2023 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
2025 | interpolation_qualifier type_qualifier
2027 /* Section 4.3 of the GLSL 1.40 specification states:
2028 * "...qualified with one of these interpolation qualifiers"
2030 * GLSL 1.30 claims to allow "one or more", but insists that:
2031 * "These interpolation qualifiers may only precede the qualifiers in,
2032 * centroid in, out, or centroid out in a declaration."
2034 * ...which means that e.g. smooth can't precede smooth, so there can be
2035 * only one after all, and the 1.40 text is a clarification, not a change.
2037 if ($2.has_interpolation())
2038 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
2040 if (!state->has_420pack_or_es31() &&
2041 ($2.flags.q.precise || $2.flags.q.invariant)) {
2042 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
2043 "after \"precise\" or \"invariant\"");
2047 $$.merge_qualifier(&@1, state, $2, false);
2049 | layout_qualifier type_qualifier
2051 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
2052 * appear no later than auxiliary storage qualifiers. There is no
2053 * particularly clear spec language mandating this, but in all examples
2054 * the layout qualifier precedes the storage qualifier.
2056 * We allow combinations of layout with interpolation, invariant or
2057 * precise qualifiers since these are useful in ARB_separate_shader_objects.
2058 * There is no clear spec guidance on this either.
2061 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
2063 | subroutine_qualifier type_qualifier
2066 $$.merge_qualifier(&@1, state, $2, false);
2068 | auxiliary_storage_qualifier type_qualifier
2070 if ($2.has_auxiliary_storage()) {
2071 _mesa_glsl_error(&@1, state,
2072 "duplicate auxiliary storage qualifier (centroid or sample)");
2075 if ((!state->has_420pack_or_es31() && !state->EXT_gpu_shader4_enable) &&
2076 ($2.flags.q.precise || $2.flags.q.invariant ||
2077 $2.has_interpolation() || $2.has_layout())) {
2078 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
2079 "just before storage qualifiers");
2082 $$.merge_qualifier(&@1, state, $2, false);
2084 | storage_qualifier type_qualifier
2086 /* Section 4.3 of the GLSL 1.20 specification states:
2087 * "Variable declarations may have a storage qualifier specified..."
2088 * 1.30 clarifies this to "may have one storage qualifier".
2090 * GL_EXT_gpu_shader4 allows "varying out" in fragment shaders.
2092 if ($2.has_storage() &&
2093 (!state->EXT_gpu_shader4_enable ||
2094 state->stage != MESA_SHADER_FRAGMENT ||
2095 !$1.flags.q.varying || !$2.flags.q.out))
2096 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
2098 if (!state->has_420pack_or_es31() &&
2099 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
2100 $2.has_layout() || $2.has_auxiliary_storage())) {
2101 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2102 "precise, invariant, interpolation, layout and auxiliary "
2103 "storage qualifiers");
2107 $$.merge_qualifier(&@1, state, $2, false);
2109 | precision_qualifier type_qualifier
2111 if ($2.precision != ast_precision_none)
2112 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2114 if (!(state->has_420pack_or_es31()) &&
2116 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2121 | memory_qualifier type_qualifier
2124 $$.merge_qualifier(&@1, state, $2, false);
2128 auxiliary_storage_qualifier:
2131 memset(& $$, 0, sizeof($$));
2132 $$.flags.q.centroid = 1;
2136 memset(& $$, 0, sizeof($$));
2137 $$.flags.q.sample = 1;
2141 memset(& $$, 0, sizeof($$));
2142 $$.flags.q.patch = 1;
2148 memset(& $$, 0, sizeof($$));
2149 $$.flags.q.constant = 1;
2153 memset(& $$, 0, sizeof($$));
2154 $$.flags.q.attribute = 1;
2158 memset(& $$, 0, sizeof($$));
2159 $$.flags.q.varying = 1;
2163 memset(& $$, 0, sizeof($$));
2168 memset(& $$, 0, sizeof($$));
2171 if (state->stage == MESA_SHADER_GEOMETRY &&
2172 state->has_explicit_attrib_stream()) {
2173 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2176 * "If the block or variable is declared with the stream
2177 * identifier, it is associated with the specified stream;
2178 * otherwise, it is associated with the current default stream."
2180 $$.flags.q.stream = 1;
2181 $$.flags.q.explicit_stream = 0;
2182 $$.stream = state->out_qualifier->stream;
2185 if (state->has_enhanced_layouts()) {
2186 $$.flags.q.xfb_buffer = 1;
2187 $$.flags.q.explicit_xfb_buffer = 0;
2188 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2193 memset(& $$, 0, sizeof($$));
2197 if (!state->has_framebuffer_fetch() ||
2198 !state->is_version(130, 300) ||
2199 state->stage != MESA_SHADER_FRAGMENT)
2200 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2201 "declared as both input and output");
2205 memset(& $$, 0, sizeof($$));
2206 $$.flags.q.uniform = 1;
2210 memset(& $$, 0, sizeof($$));
2211 $$.flags.q.buffer = 1;
2215 memset(& $$, 0, sizeof($$));
2216 $$.flags.q.shared_storage = 1;
2223 memset(& $$, 0, sizeof($$));
2224 $$.flags.q.coherent = 1;
2228 memset(& $$, 0, sizeof($$));
2229 $$.flags.q._volatile = 1;
2233 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2234 memset(& $$, 0, sizeof($$));
2235 $$.flags.q.restrict_flag = 1;
2239 memset(& $$, 0, sizeof($$));
2240 $$.flags.q.read_only = 1;
2244 memset(& $$, 0, sizeof($$));
2245 $$.flags.q.write_only = 1;
2252 void *ctx = state->linalloc;
2253 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2254 ast_unsized_array_dim, NULL,
2256 $$->set_location_range(@1, @2);
2258 | '[' constant_expression ']'
2260 void *ctx = state->linalloc;
2261 $$ = new(ctx) ast_array_specifier(@1, $2);
2262 $$->set_location_range(@1, @3);
2264 | array_specifier '[' ']'
2266 void *ctx = state->linalloc;
2269 if (state->check_arrays_of_arrays_allowed(& @1)) {
2270 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2274 | array_specifier '[' constant_expression ']'
2278 if (state->check_arrays_of_arrays_allowed(& @1)) {
2279 $$->add_dimension($3);
2285 type_specifier_nonarray
2286 | type_specifier_nonarray array_specifier
2289 $$->array_specifier = $2;
2293 type_specifier_nonarray:
2294 basic_type_specifier_nonarray
2296 void *ctx = state->linalloc;
2297 $$ = new(ctx) ast_type_specifier($1);
2298 $$->set_location(@1);
2302 void *ctx = state->linalloc;
2303 $$ = new(ctx) ast_type_specifier($1);
2304 $$->set_location(@1);
2308 void *ctx = state->linalloc;
2309 $$ = new(ctx) ast_type_specifier($1);
2310 $$->set_location(@1);
2314 basic_type_specifier_nonarray:
2315 VOID_TOK { $$ = glsl_type::void_type; }
2316 | BASIC_TYPE_TOK { $$ = $1; }
2317 | UNSIGNED BASIC_TYPE_TOK
2319 if ($2 == glsl_type::int_type) {
2320 $$ = glsl_type::uint_type;
2322 _mesa_glsl_error(&@1, state,
2323 "\"unsigned\" is only allowed before \"int\"");
2328 precision_qualifier:
2331 state->check_precision_qualifiers_allowed(&@1);
2332 $$ = ast_precision_high;
2336 state->check_precision_qualifiers_allowed(&@1);
2337 $$ = ast_precision_medium;
2341 state->check_precision_qualifiers_allowed(&@1);
2342 $$ = ast_precision_low;
2347 STRUCT any_identifier '{' struct_declaration_list '}'
2349 void *ctx = state->linalloc;
2350 $$ = new(ctx) ast_struct_specifier($2, $4);
2351 $$->set_location_range(@2, @5);
2352 state->symbols->add_type($2, glsl_type::void_type);
2354 | STRUCT '{' struct_declaration_list '}'
2356 void *ctx = state->linalloc;
2358 /* All anonymous structs have the same name. This simplifies matching of
2359 * globals whose type is an unnamed struct.
2361 * It also avoids a memory leak when the same shader is compiled over and
2364 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2366 $$->set_location_range(@2, @4);
2370 struct_declaration_list:
2374 $1->link.self_link();
2376 | struct_declaration_list struct_declaration
2379 $$->link.insert_before(& $2->link);
2384 fully_specified_type struct_declarator_list ';'
2386 void *ctx = state->linalloc;
2387 ast_fully_specified_type *const type = $1;
2388 type->set_location(@1);
2390 if (state->has_bindless()) {
2391 ast_type_qualifier input_layout_mask;
2393 /* Allow to declare qualifiers for images. */
2394 input_layout_mask.flags.i = 0;
2395 input_layout_mask.flags.q.coherent = 1;
2396 input_layout_mask.flags.q._volatile = 1;
2397 input_layout_mask.flags.q.restrict_flag = 1;
2398 input_layout_mask.flags.q.read_only = 1;
2399 input_layout_mask.flags.q.write_only = 1;
2400 input_layout_mask.flags.q.explicit_image_format = 1;
2402 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2403 _mesa_glsl_error(&@1, state,
2404 "only precision and image qualifiers may be "
2405 "applied to structure members");
2408 if (type->qualifier.flags.i != 0)
2409 _mesa_glsl_error(&@1, state,
2410 "only precision qualifiers may be applied to "
2411 "structure members");
2414 $$ = new(ctx) ast_declarator_list(type);
2415 $$->set_location(@2);
2417 $$->declarations.push_degenerate_list_at_head(& $2->link);
2421 struct_declarator_list:
2425 $1->link.self_link();
2427 | struct_declarator_list ',' struct_declarator
2430 $$->link.insert_before(& $3->link);
2437 void *ctx = state->linalloc;
2438 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2439 $$->set_location(@1);
2441 | any_identifier array_specifier
2443 void *ctx = state->linalloc;
2444 $$ = new(ctx) ast_declaration($1, $2, NULL);
2445 $$->set_location_range(@1, @2);
2450 assignment_expression
2451 | '{' initializer_list '}'
2455 | '{' initializer_list ',' '}'
2464 void *ctx = state->linalloc;
2465 $$ = new(ctx) ast_aggregate_initializer();
2466 $$->set_location(@1);
2467 $$->expressions.push_tail(& $1->link);
2469 | initializer_list ',' initializer
2471 $1->expressions.push_tail(& $3->link);
2475 declaration_statement:
2479 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2482 compound_statement { $$ = (ast_node *) $1; }
2487 declaration_statement
2488 | expression_statement
2489 | selection_statement
2491 | iteration_statement
2498 void *ctx = state->linalloc;
2499 $$ = new(ctx) ast_compound_statement(true, NULL);
2500 $$->set_location_range(@1, @2);
2504 state->symbols->push_scope();
2508 void *ctx = state->linalloc;
2509 $$ = new(ctx) ast_compound_statement(true, $3);
2510 $$->set_location_range(@1, @4);
2511 state->symbols->pop_scope();
2515 statement_no_new_scope:
2516 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2520 compound_statement_no_new_scope:
2523 void *ctx = state->linalloc;
2524 $$ = new(ctx) ast_compound_statement(false, NULL);
2525 $$->set_location_range(@1, @2);
2527 | '{' statement_list '}'
2529 void *ctx = state->linalloc;
2530 $$ = new(ctx) ast_compound_statement(false, $2);
2531 $$->set_location_range(@1, @3);
2539 _mesa_glsl_error(& @1, state, "<nil> statement");
2544 $$->link.self_link();
2546 | statement_list statement
2549 _mesa_glsl_error(& @2, state, "<nil> statement");
2553 $$->link.insert_before(& $2->link);
2555 | statement_list extension_statement
2557 if (!state->allow_extension_directive_midshader) {
2558 _mesa_glsl_error(& @1, state,
2559 "#extension directive is not allowed "
2560 "in the middle of a shader");
2566 expression_statement:
2569 void *ctx = state->linalloc;
2570 $$ = new(ctx) ast_expression_statement(NULL);
2571 $$->set_location(@1);
2575 void *ctx = state->linalloc;
2576 $$ = new(ctx) ast_expression_statement($1);
2577 $$->set_location(@1);
2581 selection_statement:
2582 IF '(' expression ')' selection_rest_statement
2584 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2586 $$->set_location_range(@1, @5);
2590 selection_rest_statement:
2591 statement ELSE statement
2593 $$.then_statement = $1;
2594 $$.else_statement = $3;
2596 | statement %prec THEN
2598 $$.then_statement = $1;
2599 $$.else_statement = NULL;
2606 $$ = (ast_node *) $1;
2608 | fully_specified_type any_identifier '=' initializer
2610 void *ctx = state->linalloc;
2611 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2612 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2613 decl->set_location_range(@2, @4);
2614 declarator->set_location(@1);
2616 declarator->declarations.push_tail(&decl->link);
2622 * switch_statement grammar is based on the syntax described in the body
2623 * of the GLSL spec, not in it's appendix!!!
2626 SWITCH '(' expression ')' switch_body
2628 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2629 $$->set_location_range(@1, @5);
2636 $$ = new(state->linalloc) ast_switch_body(NULL);
2637 $$->set_location_range(@1, @2);
2639 | '{' case_statement_list '}'
2641 $$ = new(state->linalloc) ast_switch_body($2);
2642 $$->set_location_range(@1, @3);
2649 $$ = new(state->linalloc) ast_case_label($2);
2650 $$->set_location(@2);
2654 $$ = new(state->linalloc) ast_case_label(NULL);
2655 $$->set_location(@2);
2662 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2664 labels->labels.push_tail(& $1->link);
2666 $$->set_location(@1);
2668 | case_label_list case_label
2671 $$->labels.push_tail(& $2->link);
2676 case_label_list statement
2678 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2679 stmts->set_location(@2);
2681 stmts->stmts.push_tail(& $2->link);
2684 | case_statement statement
2687 $$->stmts.push_tail(& $2->link);
2691 case_statement_list:
2694 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2695 cases->set_location(@1);
2697 cases->cases.push_tail(& $1->link);
2700 | case_statement_list case_statement
2703 $$->cases.push_tail(& $2->link);
2707 iteration_statement:
2708 WHILE '(' condition ')' statement_no_new_scope
2710 void *ctx = state->linalloc;
2711 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2712 NULL, $3, NULL, $5);
2713 $$->set_location_range(@1, @4);
2715 | DO statement WHILE '(' expression ')' ';'
2717 void *ctx = state->linalloc;
2718 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2719 NULL, $5, NULL, $2);
2720 $$->set_location_range(@1, @6);
2722 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2724 void *ctx = state->linalloc;
2725 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2726 $3, $4.cond, $4.rest, $6);
2727 $$->set_location_range(@1, @6);
2732 expression_statement
2733 | declaration_statement
2750 | conditionopt ';' expression
2757 // Grammar Note: No 'goto'. Gotos are not supported.
2761 void *ctx = state->linalloc;
2762 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2763 $$->set_location(@1);
2767 void *ctx = state->linalloc;
2768 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2769 $$->set_location(@1);
2773 void *ctx = state->linalloc;
2774 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2775 $$->set_location(@1);
2777 | RETURN expression ';'
2779 void *ctx = state->linalloc;
2780 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2781 $$->set_location_range(@1, @2);
2783 | DISCARD ';' // Fragment shader only.
2785 void *ctx = state->linalloc;
2786 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2787 $$->set_location(@1);
2791 external_declaration:
2792 function_definition { $$ = $1; }
2793 | declaration { $$ = $1; }
2794 | pragma_statement { $$ = $1; }
2795 | layout_defaults { $$ = $1; }
2796 | ';' { $$ = NULL; }
2799 function_definition:
2800 function_prototype compound_statement_no_new_scope
2802 void *ctx = state->linalloc;
2803 $$ = new(ctx) ast_function_definition();
2804 $$->set_location_range(@1, @2);
2808 state->symbols->pop_scope();
2812 /* layout_qualifieropt is packed into this rule */
2814 basic_interface_block
2818 | layout_qualifier interface_block
2820 ast_interface_block *block = (ast_interface_block *) $2;
2822 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2823 block->layout.has_layout())) {
2831 | memory_qualifier interface_block
2833 ast_interface_block *block = (ast_interface_block *)$2;
2835 if (!block->default_layout.flags.q.buffer) {
2836 _mesa_glsl_error(& @1, state,
2837 "memory qualifiers can only be used in the "
2838 "declaration of shader storage blocks");
2840 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2848 basic_interface_block:
2849 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2851 ast_interface_block *const block = $6;
2853 if ($1.flags.q.uniform) {
2854 block->default_layout = *state->default_uniform_qualifier;
2855 } else if ($1.flags.q.buffer) {
2856 block->default_layout = *state->default_shader_storage_qualifier;
2858 block->block_name = $2;
2859 block->declarations.push_degenerate_list_at_head(& $4->link);
2861 _mesa_ast_process_interface_block(& @1, state, block, $1);
2867 interface_qualifier:
2870 memset(& $$, 0, sizeof($$));
2875 memset(& $$, 0, sizeof($$));
2880 memset(& $$, 0, sizeof($$));
2881 $$.flags.q.uniform = 1;
2885 memset(& $$, 0, sizeof($$));
2886 $$.flags.q.buffer = 1;
2888 | auxiliary_storage_qualifier interface_qualifier
2890 if (!$1.flags.q.patch) {
2891 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2893 if ($2.has_auxiliary_storage()) {
2894 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2897 $$.flags.q.patch = 1;
2904 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2908 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2909 $$->set_location(@1);
2911 | NEW_IDENTIFIER array_specifier
2913 $$ = new(state->linalloc) ast_interface_block($1, $2);
2914 $$->set_location_range(@1, @2);
2922 $1->link.self_link();
2924 | member_declaration member_list
2927 $2->link.insert_before(& $$->link);
2932 fully_specified_type struct_declarator_list ';'
2934 void *ctx = state->linalloc;
2935 ast_fully_specified_type *type = $1;
2936 type->set_location(@1);
2938 if (type->qualifier.flags.q.attribute) {
2939 _mesa_glsl_error(& @1, state,
2940 "keyword 'attribute' cannot be used with "
2941 "interface block member");
2942 } else if (type->qualifier.flags.q.varying) {
2943 _mesa_glsl_error(& @1, state,
2944 "keyword 'varying' cannot be used with "
2945 "interface block member");
2948 $$ = new(ctx) ast_declarator_list(type);
2949 $$->set_location(@2);
2951 $$->declarations.push_degenerate_list_at_head(& $2->link);
2955 layout_uniform_defaults:
2956 layout_qualifier layout_uniform_defaults
2959 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2963 | layout_qualifier UNIFORM ';'
2966 layout_buffer_defaults:
2967 layout_qualifier layout_buffer_defaults
2970 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2974 | layout_qualifier BUFFER ';'
2978 layout_qualifier layout_in_defaults
2981 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2984 if (!$$.validate_in_qualifier(& @1, state)) {
2988 | layout_qualifier IN_TOK ';'
2990 if (!$1.validate_in_qualifier(& @1, state)) {
2996 layout_out_defaults:
2997 layout_qualifier layout_out_defaults
3000 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3003 if (!$$.validate_out_qualifier(& @1, state)) {
3007 | layout_qualifier OUT_TOK ';'
3009 if (!$1.validate_out_qualifier(& @1, state)) {
3016 layout_uniform_defaults
3019 if (!state->default_uniform_qualifier->
3020 merge_qualifier(& @1, state, $1, false)) {
3023 if (!state->default_uniform_qualifier->
3024 push_to_global(& @1, state)) {
3028 | layout_buffer_defaults
3031 if (!state->default_shader_storage_qualifier->
3032 merge_qualifier(& @1, state, $1, false)) {
3035 if (!state->default_shader_storage_qualifier->
3036 push_to_global(& @1, state)) {
3040 /* From the GLSL 4.50 spec, section 4.4.5:
3042 * "It is a compile-time error to specify the binding identifier for
3043 * the global scope or for block member declarations."
3045 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
3046 _mesa_glsl_error(& @1, state,
3047 "binding qualifier cannot be set for default layout");
3050 | layout_in_defaults
3053 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
3056 if (!state->in_qualifier->push_to_global(& @1, state)) {
3060 | layout_out_defaults
3063 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
3066 if (!state->out_qualifier->push_to_global(& @1, state)) {