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_INVARIANT_ALL
170 /* Reserved words that are not actually used in the grammar.
172 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
173 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
174 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
175 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
177 %token SIZEOF CAST NAMESPACE USING
178 %token RESOURCE PATCH
183 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
185 %type <identifier> variable_identifier
186 %type <node> statement
187 %type <node> statement_list
188 %type <node> simple_statement
189 %type <n> precision_qualifier
190 %type <type_qualifier> type_qualifier
191 %type <type_qualifier> auxiliary_storage_qualifier
192 %type <type_qualifier> storage_qualifier
193 %type <type_qualifier> interpolation_qualifier
194 %type <type_qualifier> layout_qualifier
195 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
196 %type <type_qualifier> interface_block_layout_qualifier
197 %type <type_qualifier> memory_qualifier
198 %type <type_qualifier> subroutine_qualifier
199 %type <subroutine_list> subroutine_type_list
200 %type <type_qualifier> interface_qualifier
201 %type <type_specifier> type_specifier
202 %type <type_specifier> type_specifier_nonarray
203 %type <array_specifier> array_specifier
204 %type <type> basic_type_specifier_nonarray
205 %type <fully_specified_type> fully_specified_type
206 %type <function> function_prototype
207 %type <function> function_header
208 %type <function> function_header_with_parameters
209 %type <function> function_declarator
210 %type <parameter_declarator> parameter_declarator
211 %type <parameter_declarator> parameter_declaration
212 %type <type_qualifier> parameter_qualifier
213 %type <type_qualifier> parameter_direction_qualifier
214 %type <type_specifier> parameter_type_specifier
215 %type <function_definition> function_definition
216 %type <compound_statement> compound_statement_no_new_scope
217 %type <compound_statement> compound_statement
218 %type <node> statement_no_new_scope
219 %type <node> expression_statement
220 %type <expression> expression
221 %type <expression> primary_expression
222 %type <expression> assignment_expression
223 %type <expression> conditional_expression
224 %type <expression> logical_or_expression
225 %type <expression> logical_xor_expression
226 %type <expression> logical_and_expression
227 %type <expression> inclusive_or_expression
228 %type <expression> exclusive_or_expression
229 %type <expression> and_expression
230 %type <expression> equality_expression
231 %type <expression> relational_expression
232 %type <expression> shift_expression
233 %type <expression> additive_expression
234 %type <expression> multiplicative_expression
235 %type <expression> unary_expression
236 %type <expression> constant_expression
237 %type <expression> integer_expression
238 %type <expression> postfix_expression
239 %type <expression> function_call_header_with_parameters
240 %type <expression> function_call_header_no_parameters
241 %type <expression> function_call_header
242 %type <expression> function_call_generic
243 %type <expression> function_call_or_method
244 %type <expression> function_call
245 %type <n> assignment_operator
246 %type <n> unary_operator
247 %type <expression> function_identifier
248 %type <node> external_declaration
249 %type <declarator_list> init_declarator_list
250 %type <declarator_list> single_declaration
251 %type <expression> initializer
252 %type <expression> initializer_list
253 %type <node> declaration
254 %type <node> declaration_statement
255 %type <node> jump_statement
256 %type <node> interface_block
257 %type <interface_block> basic_interface_block
258 %type <struct_specifier> struct_specifier
259 %type <declarator_list> struct_declaration_list
260 %type <declarator_list> struct_declaration
261 %type <declaration> struct_declarator
262 %type <declaration> struct_declarator_list
263 %type <declarator_list> member_list
264 %type <declarator_list> member_declaration
265 %type <node> selection_statement
266 %type <selection_rest_statement> selection_rest_statement
267 %type <node> switch_statement
268 %type <switch_body> switch_body
269 %type <case_label_list> case_label_list
270 %type <case_label> case_label
271 %type <case_statement> case_statement
272 %type <case_statement_list> case_statement_list
273 %type <node> iteration_statement
274 %type <node> condition
275 %type <node> conditionopt
276 %type <node> for_init_statement
277 %type <for_rest_statement> for_rest_statement
278 %type <node> layout_defaults
279 %type <type_qualifier> layout_uniform_defaults
280 %type <type_qualifier> layout_buffer_defaults
281 %type <type_qualifier> layout_in_defaults
282 %type <type_qualifier> layout_out_defaults
288 version_statement extension_statement_list
290 _mesa_glsl_initialize_types(state);
292 external_declaration_list
294 delete state->symbols;
295 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
296 if (state->es_shader) {
297 if (state->stage == MESA_SHADER_FRAGMENT) {
298 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
300 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
301 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
303 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
304 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
305 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
306 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
308 _mesa_glsl_initialize_types(state);
313 /* blank - no #version specified: defaults are already set */
314 | VERSION_TOK INTCONSTANT EOL
316 state->process_version_directive(&@2, $2, NULL);
321 | VERSION_TOK INTCONSTANT any_identifier EOL
323 state->process_version_directive(&@2, $2, $3);
332 | PRAGMA_DEBUG_OFF EOL
333 | PRAGMA_OPTIMIZE_ON EOL
334 | PRAGMA_OPTIMIZE_OFF EOL
335 | PRAGMA_INVARIANT_ALL EOL
337 /* Pragma invariant(all) cannot be used in a fragment shader.
339 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
341 * "It is an error to use this pragma in a fragment shader."
343 if (state->is_version(120, 300) &&
344 state->stage == MESA_SHADER_FRAGMENT) {
345 _mesa_glsl_error(& @1, state,
346 "pragma `invariant(all)' cannot be used "
347 "in a fragment shader.");
348 } else if (!state->is_version(120, 100)) {
349 _mesa_glsl_warning(& @1, state,
350 "pragma `invariant(all)' not supported in %s "
351 "(GLSL ES 1.00 or GLSL 1.20 required)",
352 state->get_version_string());
354 state->all_invariant = true;
359 extension_statement_list:
361 | extension_statement_list extension_statement
371 EXTENSION any_identifier COLON any_identifier EOL
373 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
379 external_declaration_list:
382 /* FINISHME: The NULL test is required because pragmas are set to
383 * FINISHME: NULL. (See production rule for external_declaration.)
386 state->translation_unit.push_tail(& $1->link);
388 | external_declaration_list external_declaration
390 /* FINISHME: The NULL test is required because pragmas are set to
391 * FINISHME: NULL. (See production rule for external_declaration.)
394 state->translation_unit.push_tail(& $2->link);
396 | external_declaration_list extension_statement {
397 if (!state->allow_extension_directive_midshader) {
398 _mesa_glsl_error(& @2, state,
399 "#extension directive is not allowed "
400 "in the middle of a shader");
414 void *ctx = state->linalloc;
415 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
416 $$->set_location(@1);
417 $$->primary_expression.identifier = $1;
421 void *ctx = state->linalloc;
422 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
423 $$->set_location(@1);
424 $$->primary_expression.int_constant = $1;
428 void *ctx = state->linalloc;
429 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
430 $$->set_location(@1);
431 $$->primary_expression.uint_constant = $1;
435 void *ctx = state->linalloc;
436 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
437 $$->set_location(@1);
438 $$->primary_expression.int64_constant = $1;
442 void *ctx = state->linalloc;
443 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
444 $$->set_location(@1);
445 $$->primary_expression.uint64_constant = $1;
449 void *ctx = state->linalloc;
450 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
451 $$->set_location(@1);
452 $$->primary_expression.float_constant = $1;
456 void *ctx = state->linalloc;
457 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
458 $$->set_location(@1);
459 $$->primary_expression.double_constant = $1;
463 void *ctx = state->linalloc;
464 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
465 $$->set_location(@1);
466 $$->primary_expression.bool_constant = $1;
476 | postfix_expression '[' integer_expression ']'
478 void *ctx = state->linalloc;
479 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
480 $$->set_location_range(@1, @4);
486 | postfix_expression DOT_TOK FIELD_SELECTION
488 void *ctx = state->linalloc;
489 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
490 $$->set_location_range(@1, @3);
491 $$->primary_expression.identifier = $3;
493 | postfix_expression INC_OP
495 void *ctx = state->linalloc;
496 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
497 $$->set_location_range(@1, @2);
499 | postfix_expression DEC_OP
501 void *ctx = state->linalloc;
502 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
503 $$->set_location_range(@1, @2);
512 function_call_or_method
515 function_call_or_method:
516 function_call_generic
519 function_call_generic:
520 function_call_header_with_parameters ')'
521 | function_call_header_no_parameters ')'
524 function_call_header_no_parameters:
525 function_call_header VOID_TOK
526 | function_call_header
529 function_call_header_with_parameters:
530 function_call_header assignment_expression
533 $$->set_location(@1);
534 $$->expressions.push_tail(& $2->link);
536 | function_call_header_with_parameters ',' assignment_expression
539 $$->set_location(@1);
540 $$->expressions.push_tail(& $3->link);
544 // Grammar Note: Constructors look like functions, but lexical
545 // analysis recognized most of them as keywords. They are now
546 // recognized through "type_specifier".
547 function_call_header:
548 function_identifier '('
554 void *ctx = state->linalloc;
555 $$ = new(ctx) ast_function_expression($1);
556 $$->set_location(@1);
560 void *ctx = state->linalloc;
561 $$ = new(ctx) ast_function_expression($1);
562 $$->set_location(@1);
566 // Grammar Note: Constructors look like methods, but lexical
567 // analysis recognized most of them as keywords. They are now
568 // recognized through "type_specifier".
570 // Grammar Note: No traditional style type casts.
573 | INC_OP unary_expression
575 void *ctx = state->linalloc;
576 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
577 $$->set_location(@1);
579 | DEC_OP unary_expression
581 void *ctx = state->linalloc;
582 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
583 $$->set_location(@1);
585 | unary_operator unary_expression
587 void *ctx = state->linalloc;
588 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
589 $$->set_location_range(@1, @2);
593 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
595 '+' { $$ = ast_plus; }
596 | '-' { $$ = ast_neg; }
597 | '!' { $$ = ast_logic_not; }
598 | '~' { $$ = ast_bit_not; }
601 multiplicative_expression:
603 | multiplicative_expression '*' unary_expression
605 void *ctx = state->linalloc;
606 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
607 $$->set_location_range(@1, @3);
609 | multiplicative_expression '/' unary_expression
611 void *ctx = state->linalloc;
612 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
613 $$->set_location_range(@1, @3);
615 | multiplicative_expression '%' unary_expression
617 void *ctx = state->linalloc;
618 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
619 $$->set_location_range(@1, @3);
624 multiplicative_expression
625 | additive_expression '+' multiplicative_expression
627 void *ctx = state->linalloc;
628 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
629 $$->set_location_range(@1, @3);
631 | additive_expression '-' multiplicative_expression
633 void *ctx = state->linalloc;
634 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
635 $$->set_location_range(@1, @3);
641 | shift_expression LEFT_OP additive_expression
643 void *ctx = state->linalloc;
644 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
645 $$->set_location_range(@1, @3);
647 | shift_expression RIGHT_OP additive_expression
649 void *ctx = state->linalloc;
650 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
651 $$->set_location_range(@1, @3);
655 relational_expression:
657 | relational_expression '<' shift_expression
659 void *ctx = state->linalloc;
660 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
661 $$->set_location_range(@1, @3);
663 | relational_expression '>' shift_expression
665 void *ctx = state->linalloc;
666 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
667 $$->set_location_range(@1, @3);
669 | relational_expression LE_OP shift_expression
671 void *ctx = state->linalloc;
672 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
673 $$->set_location_range(@1, @3);
675 | relational_expression GE_OP shift_expression
677 void *ctx = state->linalloc;
678 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
679 $$->set_location_range(@1, @3);
684 relational_expression
685 | equality_expression EQ_OP relational_expression
687 void *ctx = state->linalloc;
688 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
689 $$->set_location_range(@1, @3);
691 | equality_expression NE_OP relational_expression
693 void *ctx = state->linalloc;
694 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
695 $$->set_location_range(@1, @3);
701 | and_expression '&' equality_expression
703 void *ctx = state->linalloc;
704 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
705 $$->set_location_range(@1, @3);
709 exclusive_or_expression:
711 | exclusive_or_expression '^' and_expression
713 void *ctx = state->linalloc;
714 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
715 $$->set_location_range(@1, @3);
719 inclusive_or_expression:
720 exclusive_or_expression
721 | inclusive_or_expression '|' exclusive_or_expression
723 void *ctx = state->linalloc;
724 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
725 $$->set_location_range(@1, @3);
729 logical_and_expression:
730 inclusive_or_expression
731 | logical_and_expression AND_OP inclusive_or_expression
733 void *ctx = state->linalloc;
734 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
735 $$->set_location_range(@1, @3);
739 logical_xor_expression:
740 logical_and_expression
741 | logical_xor_expression XOR_OP logical_and_expression
743 void *ctx = state->linalloc;
744 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
745 $$->set_location_range(@1, @3);
749 logical_or_expression:
750 logical_xor_expression
751 | logical_or_expression OR_OP logical_xor_expression
753 void *ctx = state->linalloc;
754 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
755 $$->set_location_range(@1, @3);
759 conditional_expression:
760 logical_or_expression
761 | logical_or_expression '?' expression ':' assignment_expression
763 void *ctx = state->linalloc;
764 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
765 $$->set_location_range(@1, @5);
769 assignment_expression:
770 conditional_expression
771 | unary_expression assignment_operator assignment_expression
773 void *ctx = state->linalloc;
774 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
775 $$->set_location_range(@1, @3);
780 '=' { $$ = ast_assign; }
781 | MUL_ASSIGN { $$ = ast_mul_assign; }
782 | DIV_ASSIGN { $$ = ast_div_assign; }
783 | MOD_ASSIGN { $$ = ast_mod_assign; }
784 | ADD_ASSIGN { $$ = ast_add_assign; }
785 | SUB_ASSIGN { $$ = ast_sub_assign; }
786 | LEFT_ASSIGN { $$ = ast_ls_assign; }
787 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
788 | AND_ASSIGN { $$ = ast_and_assign; }
789 | XOR_ASSIGN { $$ = ast_xor_assign; }
790 | OR_ASSIGN { $$ = ast_or_assign; }
794 assignment_expression
798 | expression ',' assignment_expression
800 void *ctx = state->linalloc;
801 if ($1->oper != ast_sequence) {
802 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
803 $$->set_location_range(@1, @3);
804 $$->expressions.push_tail(& $1->link);
809 $$->expressions.push_tail(& $3->link);
814 conditional_expression
818 function_prototype ';'
820 state->symbols->pop_scope();
823 | init_declarator_list ';'
827 | PRECISION precision_qualifier type_specifier ';'
829 $3->default_precision = $2;
834 ast_interface_block *block = (ast_interface_block *) $1;
835 if (block->layout.has_layout() || block->layout.has_memory()) {
836 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
840 block->layout = block->default_layout;
841 if (!block->layout.push_to_global(& @1, state)) {
849 function_declarator ')'
854 | function_header_with_parameters
857 function_header_with_parameters:
858 function_header parameter_declaration
861 $$->parameters.push_tail(& $2->link);
863 | function_header_with_parameters ',' parameter_declaration
866 $$->parameters.push_tail(& $3->link);
871 fully_specified_type variable_identifier '('
873 void *ctx = state->linalloc;
874 $$ = new(ctx) ast_function();
875 $$->set_location(@2);
876 $$->return_type = $1;
879 if ($1->qualifier.is_subroutine_decl()) {
880 /* add type for IDENTIFIER search */
881 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
883 state->symbols->add_function(new(state) ir_function($2));
884 state->symbols->push_scope();
888 parameter_declarator:
889 type_specifier any_identifier
891 void *ctx = state->linalloc;
892 $$ = new(ctx) ast_parameter_declarator();
893 $$->set_location_range(@1, @2);
894 $$->type = new(ctx) ast_fully_specified_type();
895 $$->type->set_location(@1);
896 $$->type->specifier = $1;
898 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
900 | type_specifier any_identifier array_specifier
902 void *ctx = state->linalloc;
903 $$ = new(ctx) ast_parameter_declarator();
904 $$->set_location_range(@1, @3);
905 $$->type = new(ctx) ast_fully_specified_type();
906 $$->type->set_location(@1);
907 $$->type->specifier = $1;
909 $$->array_specifier = $3;
910 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
914 parameter_declaration:
915 parameter_qualifier parameter_declarator
918 $$->type->qualifier = $1;
919 if (!$$->type->qualifier.push_to_global(& @1, state)) {
923 | parameter_qualifier parameter_type_specifier
925 void *ctx = state->linalloc;
926 $$ = new(ctx) ast_parameter_declarator();
927 $$->set_location(@2);
928 $$->type = new(ctx) ast_fully_specified_type();
929 $$->type->set_location_range(@1, @2);
930 $$->type->qualifier = $1;
931 if (!$$->type->qualifier.push_to_global(& @1, state)) {
934 $$->type->specifier = $2;
941 memset(& $$, 0, sizeof($$));
943 | CONST_TOK parameter_qualifier
945 if ($2.flags.q.constant)
946 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
949 $$.flags.q.constant = 1;
951 | PRECISE parameter_qualifier
953 if ($2.flags.q.precise)
954 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
957 $$.flags.q.precise = 1;
959 | parameter_direction_qualifier parameter_qualifier
961 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
962 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
964 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
965 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
969 $$.merge_qualifier(&@1, state, $2, false);
971 | precision_qualifier parameter_qualifier
973 if ($2.precision != ast_precision_none)
974 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
976 if (!state->has_420pack_or_es31() &&
978 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
983 | memory_qualifier parameter_qualifier
986 $$.merge_qualifier(&@1, state, $2, false);
989 parameter_direction_qualifier:
992 memset(& $$, 0, sizeof($$));
997 memset(& $$, 0, sizeof($$));
1002 memset(& $$, 0, sizeof($$));
1008 parameter_type_specifier:
1012 init_declarator_list:
1014 | init_declarator_list ',' any_identifier
1016 void *ctx = state->linalloc;
1017 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1018 decl->set_location(@3);
1021 $$->declarations.push_tail(&decl->link);
1022 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1024 | init_declarator_list ',' any_identifier array_specifier
1026 void *ctx = state->linalloc;
1027 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1028 decl->set_location_range(@3, @4);
1031 $$->declarations.push_tail(&decl->link);
1032 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1034 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1036 void *ctx = state->linalloc;
1037 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1038 decl->set_location_range(@3, @4);
1041 $$->declarations.push_tail(&decl->link);
1042 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1044 | init_declarator_list ',' any_identifier '=' initializer
1046 void *ctx = state->linalloc;
1047 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1048 decl->set_location(@3);
1051 $$->declarations.push_tail(&decl->link);
1052 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1056 // Grammar Note: No 'enum', or 'typedef'.
1058 fully_specified_type
1060 void *ctx = state->linalloc;
1061 /* Empty declaration list is valid. */
1062 $$ = new(ctx) ast_declarator_list($1);
1063 $$->set_location(@1);
1065 | fully_specified_type any_identifier
1067 void *ctx = state->linalloc;
1068 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1069 decl->set_location(@2);
1071 $$ = new(ctx) ast_declarator_list($1);
1072 $$->set_location_range(@1, @2);
1073 $$->declarations.push_tail(&decl->link);
1074 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1076 | fully_specified_type any_identifier array_specifier
1078 void *ctx = state->linalloc;
1079 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1080 decl->set_location_range(@2, @3);
1082 $$ = new(ctx) ast_declarator_list($1);
1083 $$->set_location_range(@1, @3);
1084 $$->declarations.push_tail(&decl->link);
1085 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1087 | fully_specified_type any_identifier array_specifier '=' initializer
1089 void *ctx = state->linalloc;
1090 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1091 decl->set_location_range(@2, @3);
1093 $$ = new(ctx) ast_declarator_list($1);
1094 $$->set_location_range(@1, @3);
1095 $$->declarations.push_tail(&decl->link);
1096 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1098 | fully_specified_type any_identifier '=' initializer
1100 void *ctx = state->linalloc;
1101 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1102 decl->set_location(@2);
1104 $$ = new(ctx) ast_declarator_list($1);
1105 $$->set_location_range(@1, @2);
1106 $$->declarations.push_tail(&decl->link);
1107 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1109 | INVARIANT variable_identifier
1111 void *ctx = state->linalloc;
1112 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1113 decl->set_location(@2);
1115 $$ = new(ctx) ast_declarator_list(NULL);
1116 $$->set_location_range(@1, @2);
1117 $$->invariant = true;
1119 $$->declarations.push_tail(&decl->link);
1121 | PRECISE variable_identifier
1123 void *ctx = state->linalloc;
1124 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1125 decl->set_location(@2);
1127 $$ = new(ctx) ast_declarator_list(NULL);
1128 $$->set_location_range(@1, @2);
1131 $$->declarations.push_tail(&decl->link);
1135 fully_specified_type:
1138 void *ctx = state->linalloc;
1139 $$ = new(ctx) ast_fully_specified_type();
1140 $$->set_location(@1);
1143 | type_qualifier type_specifier
1145 void *ctx = state->linalloc;
1146 $$ = new(ctx) ast_fully_specified_type();
1147 $$->set_location_range(@1, @2);
1149 if (!$$->qualifier.push_to_global(& @1, state)) {
1153 if ($$->specifier->structure != NULL &&
1154 $$->specifier->structure->is_declaration) {
1155 $$->specifier->structure->layout = &$$->qualifier;
1161 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1167 layout_qualifier_id_list:
1169 | layout_qualifier_id_list ',' layout_qualifier_id
1172 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1178 layout_qualifier_id:
1181 memset(& $$, 0, sizeof($$));
1183 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1184 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1185 state->is_version(150, 0))) {
1186 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1187 $$.flags.q.origin_upper_left = 1;
1188 } else if (match_layout_qualifier($1, "pixel_center_integer",
1190 $$.flags.q.pixel_center_integer = 1;
1193 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1194 _mesa_glsl_warning(& @1, state,
1195 "GL_ARB_fragment_coord_conventions layout "
1196 "identifier `%s' used", $1);
1200 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1202 (state->AMD_conservative_depth_enable ||
1203 state->ARB_conservative_depth_enable ||
1204 state->is_version(420, 0))) {
1205 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1206 $$.flags.q.depth_type = 1;
1207 $$.depth_type = ast_depth_any;
1208 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1209 $$.flags.q.depth_type = 1;
1210 $$.depth_type = ast_depth_greater;
1211 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1212 $$.flags.q.depth_type = 1;
1213 $$.depth_type = ast_depth_less;
1214 } else if (match_layout_qualifier($1, "depth_unchanged",
1216 $$.flags.q.depth_type = 1;
1217 $$.depth_type = ast_depth_unchanged;
1220 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1221 _mesa_glsl_warning(& @1, state,
1222 "GL_AMD_conservative_depth "
1223 "layout qualifier `%s' is used", $1);
1225 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1226 _mesa_glsl_warning(& @1, state,
1227 "GL_ARB_conservative_depth "
1228 "layout qualifier `%s' is used", $1);
1232 /* See also interface_block_layout_qualifier. */
1233 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1234 if (match_layout_qualifier($1, "std140", state) == 0) {
1235 $$.flags.q.std140 = 1;
1236 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1237 $$.flags.q.shared = 1;
1238 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1239 $$.flags.q.std430 = 1;
1240 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1241 $$.flags.q.column_major = 1;
1242 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1243 * below in the interface_block_layout_qualifier rule.
1245 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1248 * Also, this takes care of alternate capitalizations of
1249 * "row_major" (which is necessary because layout qualifiers
1250 * are case-insensitive in desktop GLSL).
1252 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1253 $$.flags.q.row_major = 1;
1254 /* "packed" is a reserved word in GLSL, and its token is
1255 * parsed below in the interface_block_layout_qualifier rule.
1256 * However, we must take care of alternate capitalizations of
1257 * "packed", because layout qualifiers are case-insensitive
1260 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1261 $$.flags.q.packed = 1;
1264 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1265 _mesa_glsl_warning(& @1, state,
1266 "#version 140 / GL_ARB_uniform_buffer_object "
1267 "layout qualifier `%s' is used", $1);
1271 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1273 static const struct {
1277 { "points", GL_POINTS },
1278 { "lines", GL_LINES },
1279 { "lines_adjacency", GL_LINES_ADJACENCY },
1280 { "line_strip", GL_LINE_STRIP },
1281 { "triangles", GL_TRIANGLES },
1282 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1283 { "triangle_strip", GL_TRIANGLE_STRIP },
1285 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1286 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1287 $$.flags.q.prim_type = 1;
1288 $$.prim_type = map[i].e;
1293 if ($$.flags.i && !state->has_geometry_shader() &&
1294 !state->has_tessellation_shader()) {
1295 _mesa_glsl_error(& @1, state, "#version 150 layout "
1296 "qualifier `%s' used", $1);
1300 /* Layout qualifiers for ARB_shader_image_load_store. */
1301 if (state->has_shader_image_load_store()) {
1303 static const struct {
1306 glsl_base_type base_type;
1307 /** Minimum desktop GLSL version required for the image
1308 * format. Use 130 if already present in the original
1311 unsigned required_glsl;
1312 /** Minimum GLSL ES version required for the image format. */
1313 unsigned required_essl;
1314 /* NV_image_formats */
1315 bool nv_image_formats;
1317 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1318 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1319 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1320 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1321 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1322 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1323 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1324 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1325 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1326 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1327 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1328 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1329 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1330 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1331 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1332 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1333 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1334 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1335 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1336 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1337 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1338 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1339 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1340 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1341 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1342 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1343 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
1344 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1345 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1346 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
1347 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1348 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
1349 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1350 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1351 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1352 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1353 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1354 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1355 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1358 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1359 if ((state->is_version(map[i].required_glsl,
1360 map[i].required_essl) ||
1361 (state->NV_image_formats_enable &&
1362 map[i].nv_image_formats)) &&
1363 match_layout_qualifier($1, map[i].name, state) == 0) {
1364 $$.flags.q.explicit_image_format = 1;
1365 $$.image_format = map[i].format;
1366 $$.image_base_type = map[i].base_type;
1374 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1375 /* From section 4.4.1.3 of the GLSL 4.50 specification
1376 * (Fragment Shader Inputs):
1378 * "Fragment shaders also allow the following layout
1379 * qualifier on in only (not with variable declarations)
1380 * layout-qualifier-id
1381 * early_fragment_tests
1384 if (state->stage != MESA_SHADER_FRAGMENT) {
1385 _mesa_glsl_error(& @1, state,
1386 "early_fragment_tests layout qualifier only "
1387 "valid in fragment shaders");
1390 $$.flags.q.early_fragment_tests = 1;
1393 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1394 if (state->stage != MESA_SHADER_FRAGMENT) {
1395 _mesa_glsl_error(& @1, state,
1396 "inner_coverage layout qualifier only "
1397 "valid in fragment shaders");
1400 if (state->INTEL_conservative_rasterization_enable) {
1401 $$.flags.q.inner_coverage = 1;
1403 _mesa_glsl_error(& @1, state,
1404 "inner_coverage layout qualifier present, "
1405 "but the INTEL_conservative_rasterization extension "
1410 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1411 if (state->stage != MESA_SHADER_FRAGMENT) {
1412 _mesa_glsl_error(& @1, state,
1413 "post_depth_coverage layout qualifier only "
1414 "valid in fragment shaders");
1417 if (state->ARB_post_depth_coverage_enable ||
1418 state->INTEL_conservative_rasterization_enable) {
1419 $$.flags.q.post_depth_coverage = 1;
1421 _mesa_glsl_error(& @1, state,
1422 "post_depth_coverage layout qualifier present, "
1423 "but the GL_ARB_post_depth_coverage extension "
1428 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1429 _mesa_glsl_error(& @1, state,
1430 "post_depth_coverage & inner_coverage layout qualifiers "
1431 "are mutually exclusive");
1435 /* Layout qualifiers for tessellation evaluation shaders. */
1437 static const struct {
1441 /* triangles already parsed by gs-specific code */
1442 { "quads", GL_QUADS },
1443 { "isolines", GL_ISOLINES },
1445 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1446 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1447 $$.flags.q.prim_type = 1;
1448 $$.prim_type = map[i].e;
1453 if ($$.flags.i && !state->has_tessellation_shader()) {
1454 _mesa_glsl_error(& @1, state,
1455 "primitive mode qualifier `%s' requires "
1456 "GLSL 4.00 or ARB_tessellation_shader", $1);
1460 static const struct {
1462 enum gl_tess_spacing e;
1464 { "equal_spacing", TESS_SPACING_EQUAL },
1465 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1466 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1468 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1469 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1470 $$.flags.q.vertex_spacing = 1;
1471 $$.vertex_spacing = map[i].e;
1476 if ($$.flags.i && !state->has_tessellation_shader()) {
1477 _mesa_glsl_error(& @1, state,
1478 "vertex spacing qualifier `%s' requires "
1479 "GLSL 4.00 or ARB_tessellation_shader", $1);
1483 if (match_layout_qualifier($1, "cw", state) == 0) {
1484 $$.flags.q.ordering = 1;
1485 $$.ordering = GL_CW;
1486 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1487 $$.flags.q.ordering = 1;
1488 $$.ordering = GL_CCW;
1491 if ($$.flags.i && !state->has_tessellation_shader()) {
1492 _mesa_glsl_error(& @1, state,
1493 "ordering qualifier `%s' requires "
1494 "GLSL 4.00 or ARB_tessellation_shader", $1);
1498 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1499 $$.flags.q.point_mode = 1;
1500 $$.point_mode = true;
1503 if ($$.flags.i && !state->has_tessellation_shader()) {
1504 _mesa_glsl_error(& @1, state,
1505 "qualifier `point_mode' requires "
1506 "GLSL 4.00 or ARB_tessellation_shader");
1511 static const struct {
1515 { "blend_support_multiply", BLEND_MULTIPLY },
1516 { "blend_support_screen", BLEND_SCREEN },
1517 { "blend_support_overlay", BLEND_OVERLAY },
1518 { "blend_support_darken", BLEND_DARKEN },
1519 { "blend_support_lighten", BLEND_LIGHTEN },
1520 { "blend_support_colordodge", BLEND_COLORDODGE },
1521 { "blend_support_colorburn", BLEND_COLORBURN },
1522 { "blend_support_hardlight", BLEND_HARDLIGHT },
1523 { "blend_support_softlight", BLEND_SOFTLIGHT },
1524 { "blend_support_difference", BLEND_DIFFERENCE },
1525 { "blend_support_exclusion", BLEND_EXCLUSION },
1526 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1527 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1528 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1529 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1530 { "blend_support_all_equations", BLEND_ALL },
1532 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1533 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1534 $$.flags.q.blend_support = 1;
1535 state->fs_blend_support |= map[i].mask;
1541 !state->KHR_blend_equation_advanced_enable &&
1542 !state->is_version(0, 320)) {
1543 _mesa_glsl_error(& @1, state,
1544 "advanced blending layout qualifiers require "
1545 "ESSL 3.20 or KHR_blend_equation_advanced");
1548 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1549 _mesa_glsl_error(& @1, state,
1550 "advanced blending layout qualifiers only "
1551 "valid in fragment shaders");
1555 /* Layout qualifiers for ARB_compute_variable_group_size. */
1557 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1558 $$.flags.q.local_size_variable = 1;
1561 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1562 _mesa_glsl_error(& @1, state,
1563 "qualifier `local_size_variable` requires "
1564 "ARB_compute_variable_group_size");
1568 /* Layout qualifiers for ARB_bindless_texture. */
1570 if (match_layout_qualifier($1, "bindless_sampler", state) == 0)
1571 $$.flags.q.bindless_sampler = 1;
1572 if (match_layout_qualifier($1, "bound_sampler", state) == 0)
1573 $$.flags.q.bound_sampler = 1;
1575 if (state->has_shader_image_load_store()) {
1576 if (match_layout_qualifier($1, "bindless_image", state) == 0)
1577 $$.flags.q.bindless_image = 1;
1578 if (match_layout_qualifier($1, "bound_image", state) == 0)
1579 $$.flags.q.bound_image = 1;
1582 if ($$.flags.i && !state->has_bindless()) {
1583 _mesa_glsl_error(& @1, state,
1584 "qualifier `%s` requires "
1585 "ARB_bindless_texture", $1);
1590 state->EXT_shader_framebuffer_fetch_non_coherent_enable) {
1591 if (match_layout_qualifier($1, "noncoherent", state) == 0)
1592 $$.flags.q.non_coherent = 1;
1596 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1601 | any_identifier '=' constant_expression
1603 memset(& $$, 0, sizeof($$));
1604 void *ctx = state->linalloc;
1606 if ($3->oper != ast_int_constant &&
1607 $3->oper != ast_uint_constant &&
1608 !state->has_enhanced_layouts()) {
1609 _mesa_glsl_error(& @1, state,
1610 "compile-time constant expressions require "
1611 "GLSL 4.40 or ARB_enhanced_layouts");
1614 if (match_layout_qualifier("align", $1, state) == 0) {
1615 if (!state->has_enhanced_layouts()) {
1616 _mesa_glsl_error(& @1, state,
1617 "align qualifier requires "
1618 "GLSL 4.40 or ARB_enhanced_layouts");
1620 $$.flags.q.explicit_align = 1;
1625 if (match_layout_qualifier("location", $1, state) == 0) {
1626 $$.flags.q.explicit_location = 1;
1628 if ($$.flags.q.attribute == 1 &&
1629 state->ARB_explicit_attrib_location_warn) {
1630 _mesa_glsl_warning(& @1, state,
1631 "GL_ARB_explicit_attrib_location layout "
1632 "identifier `%s' used", $1);
1637 if (match_layout_qualifier("component", $1, state) == 0) {
1638 if (!state->has_enhanced_layouts()) {
1639 _mesa_glsl_error(& @1, state,
1640 "component qualifier requires "
1641 "GLSL 4.40 or ARB_enhanced_layouts");
1643 $$.flags.q.explicit_component = 1;
1648 if (match_layout_qualifier("index", $1, state) == 0) {
1649 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1650 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1654 $$.flags.q.explicit_index = 1;
1658 if ((state->has_420pack_or_es31() ||
1659 state->has_atomic_counters() ||
1660 state->has_shader_storage_buffer_objects()) &&
1661 match_layout_qualifier("binding", $1, state) == 0) {
1662 $$.flags.q.explicit_binding = 1;
1666 if ((state->has_atomic_counters() ||
1667 state->has_enhanced_layouts()) &&
1668 match_layout_qualifier("offset", $1, state) == 0) {
1669 $$.flags.q.explicit_offset = 1;
1673 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1674 $$.flags.q.max_vertices = 1;
1675 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1676 if (!state->has_geometry_shader()) {
1677 _mesa_glsl_error(& @3, state,
1678 "#version 150 max_vertices qualifier "
1683 if (state->stage == MESA_SHADER_GEOMETRY) {
1684 if (match_layout_qualifier("stream", $1, state) == 0 &&
1685 state->check_explicit_attrib_stream_allowed(& @3)) {
1686 $$.flags.q.stream = 1;
1687 $$.flags.q.explicit_stream = 1;
1692 if (state->has_enhanced_layouts()) {
1693 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1694 $$.flags.q.xfb_buffer = 1;
1695 $$.flags.q.explicit_xfb_buffer = 1;
1699 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1700 $$.flags.q.explicit_xfb_offset = 1;
1704 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1705 $$.flags.q.xfb_stride = 1;
1706 $$.flags.q.explicit_xfb_stride = 1;
1711 static const char * const local_size_qualifiers[3] = {
1716 for (int i = 0; i < 3; i++) {
1717 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1719 if (!state->has_compute_shader()) {
1720 _mesa_glsl_error(& @3, state,
1721 "%s qualifier requires GLSL 4.30 or "
1722 "GLSL ES 3.10 or ARB_compute_shader",
1723 local_size_qualifiers[i]);
1726 $$.flags.q.local_size |= (1 << i);
1727 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1733 if (match_layout_qualifier("invocations", $1, state) == 0) {
1734 $$.flags.q.invocations = 1;
1735 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1736 if (!state->is_version(400, 320) &&
1737 !state->ARB_gpu_shader5_enable &&
1738 !state->OES_geometry_shader_enable &&
1739 !state->EXT_geometry_shader_enable) {
1740 _mesa_glsl_error(& @3, state,
1741 "GL_ARB_gpu_shader5 invocations "
1742 "qualifier specified", $3);
1746 /* Layout qualifiers for tessellation control shaders. */
1747 if (match_layout_qualifier("vertices", $1, state) == 0) {
1748 $$.flags.q.vertices = 1;
1749 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1750 if (!state->has_tessellation_shader()) {
1751 _mesa_glsl_error(& @1, state,
1752 "vertices qualifier requires GLSL 4.00 or "
1753 "ARB_tessellation_shader");
1757 /* If the identifier didn't match any known layout identifiers,
1761 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1766 | interface_block_layout_qualifier
1769 /* Layout qualifiers for ARB_uniform_buffer_object. */
1770 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1771 _mesa_glsl_error(& @1, state,
1772 "#version 140 / GL_ARB_uniform_buffer_object "
1773 "layout qualifier `%s' is used", $1);
1774 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1775 _mesa_glsl_warning(& @1, state,
1776 "#version 140 / GL_ARB_uniform_buffer_object "
1777 "layout qualifier `%s' is used", $1);
1782 /* This is a separate language rule because we parse these as tokens
1783 * (due to them being reserved keywords) instead of identifiers like
1784 * most qualifiers. See the any_identifier path of
1785 * layout_qualifier_id for the others.
1787 * Note that since layout qualifiers are case-insensitive in desktop
1788 * GLSL, all of these qualifiers need to be handled as identifiers as
1789 * well (by the any_identifier path of layout_qualifier_id).
1791 interface_block_layout_qualifier:
1794 memset(& $$, 0, sizeof($$));
1795 $$.flags.q.row_major = 1;
1799 memset(& $$, 0, sizeof($$));
1800 $$.flags.q.packed = 1;
1804 memset(& $$, 0, sizeof($$));
1805 $$.flags.q.shared = 1;
1809 subroutine_qualifier:
1812 memset(& $$, 0, sizeof($$));
1813 $$.flags.q.subroutine = 1;
1815 | SUBROUTINE '(' subroutine_type_list ')'
1817 memset(& $$, 0, sizeof($$));
1818 $$.flags.q.subroutine = 1;
1819 $$.subroutine_list = $3;
1823 subroutine_type_list:
1826 void *ctx = state->linalloc;
1827 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1828 decl->set_location(@1);
1830 $$ = new(ctx) ast_subroutine_list();
1831 $$->declarations.push_tail(&decl->link);
1833 | subroutine_type_list ',' any_identifier
1835 void *ctx = state->linalloc;
1836 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1837 decl->set_location(@3);
1840 $$->declarations.push_tail(&decl->link);
1844 interpolation_qualifier:
1847 memset(& $$, 0, sizeof($$));
1848 $$.flags.q.smooth = 1;
1852 memset(& $$, 0, sizeof($$));
1853 $$.flags.q.flat = 1;
1857 memset(& $$, 0, sizeof($$));
1858 $$.flags.q.noperspective = 1;
1863 /* Single qualifiers */
1866 memset(& $$, 0, sizeof($$));
1867 $$.flags.q.invariant = 1;
1871 memset(& $$, 0, sizeof($$));
1872 $$.flags.q.precise = 1;
1874 | auxiliary_storage_qualifier
1876 | interpolation_qualifier
1879 | subroutine_qualifier
1880 | precision_qualifier
1882 memset(&$$, 0, sizeof($$));
1886 /* Multiple qualifiers:
1887 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1888 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1890 * invariant interpolation auxiliary storage precision ...or...
1891 * layout storage precision
1893 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1894 * side don't contain any that must appear on the left hand side.
1895 * For example, when processing a storage qualifier, we check that there are
1896 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1898 | PRECISE type_qualifier
1900 if ($2.flags.q.precise)
1901 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1904 $$.flags.q.precise = 1;
1906 | INVARIANT type_qualifier
1908 if ($2.flags.q.invariant)
1909 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1911 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1912 _mesa_glsl_error(&@1, state,
1913 "\"invariant\" must come after \"precise\"");
1916 $$.flags.q.invariant = 1;
1918 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1920 * "Only variables output from a shader can be candidates for invariance.
1921 * This includes user-defined output variables and the built-in output
1922 * variables. As only outputs can be declared as invariant, an invariant
1923 * output from one shader stage will still match an input of a subsequent
1924 * stage without the input being declared as invariant."
1926 * On the desktop side, this text first appears in GLSL 4.30.
1928 if (state->is_version(430, 300) && $$.flags.q.in)
1929 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1931 | interpolation_qualifier type_qualifier
1933 /* Section 4.3 of the GLSL 1.40 specification states:
1934 * "...qualified with one of these interpolation qualifiers"
1936 * GLSL 1.30 claims to allow "one or more", but insists that:
1937 * "These interpolation qualifiers may only precede the qualifiers in,
1938 * centroid in, out, or centroid out in a declaration."
1940 * ...which means that e.g. smooth can't precede smooth, so there can be
1941 * only one after all, and the 1.40 text is a clarification, not a change.
1943 if ($2.has_interpolation())
1944 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1946 if (!state->has_420pack_or_es31() &&
1947 ($2.flags.q.precise || $2.flags.q.invariant)) {
1948 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1949 "after \"precise\" or \"invariant\"");
1953 $$.merge_qualifier(&@1, state, $2, false);
1955 | layout_qualifier type_qualifier
1957 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1958 * appear no later than auxiliary storage qualifiers. There is no
1959 * particularly clear spec language mandating this, but in all examples
1960 * the layout qualifier precedes the storage qualifier.
1962 * We allow combinations of layout with interpolation, invariant or
1963 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1964 * There is no clear spec guidance on this either.
1967 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1969 | subroutine_qualifier type_qualifier
1972 $$.merge_qualifier(&@1, state, $2, false);
1974 | auxiliary_storage_qualifier type_qualifier
1976 if ($2.has_auxiliary_storage()) {
1977 _mesa_glsl_error(&@1, state,
1978 "duplicate auxiliary storage qualifier (centroid or sample)");
1981 if (!state->has_420pack_or_es31() &&
1982 ($2.flags.q.precise || $2.flags.q.invariant ||
1983 $2.has_interpolation() || $2.has_layout())) {
1984 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1985 "just before storage qualifiers");
1988 $$.merge_qualifier(&@1, state, $2, false);
1990 | storage_qualifier type_qualifier
1992 /* Section 4.3 of the GLSL 1.20 specification states:
1993 * "Variable declarations may have a storage qualifier specified..."
1994 * 1.30 clarifies this to "may have one storage qualifier".
1996 if ($2.has_storage())
1997 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1999 if (!state->has_420pack_or_es31() &&
2000 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
2001 $2.has_layout() || $2.has_auxiliary_storage())) {
2002 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2003 "precise, invariant, interpolation, layout and auxiliary "
2004 "storage qualifiers");
2008 $$.merge_qualifier(&@1, state, $2, false);
2010 | precision_qualifier type_qualifier
2012 if ($2.precision != ast_precision_none)
2013 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2015 if (!(state->has_420pack_or_es31()) &&
2017 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2022 | memory_qualifier type_qualifier
2025 $$.merge_qualifier(&@1, state, $2, false);
2029 auxiliary_storage_qualifier:
2032 memset(& $$, 0, sizeof($$));
2033 $$.flags.q.centroid = 1;
2037 memset(& $$, 0, sizeof($$));
2038 $$.flags.q.sample = 1;
2042 memset(& $$, 0, sizeof($$));
2043 $$.flags.q.patch = 1;
2049 memset(& $$, 0, sizeof($$));
2050 $$.flags.q.constant = 1;
2054 memset(& $$, 0, sizeof($$));
2055 $$.flags.q.attribute = 1;
2059 memset(& $$, 0, sizeof($$));
2060 $$.flags.q.varying = 1;
2064 memset(& $$, 0, sizeof($$));
2069 memset(& $$, 0, sizeof($$));
2072 if (state->stage == MESA_SHADER_GEOMETRY &&
2073 state->has_explicit_attrib_stream()) {
2074 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2077 * "If the block or variable is declared with the stream
2078 * identifier, it is associated with the specified stream;
2079 * otherwise, it is associated with the current default stream."
2081 $$.flags.q.stream = 1;
2082 $$.flags.q.explicit_stream = 0;
2083 $$.stream = state->out_qualifier->stream;
2086 if (state->has_enhanced_layouts()) {
2087 $$.flags.q.xfb_buffer = 1;
2088 $$.flags.q.explicit_xfb_buffer = 0;
2089 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2094 memset(& $$, 0, sizeof($$));
2098 if (!state->has_framebuffer_fetch() ||
2099 !state->is_version(130, 300) ||
2100 state->stage != MESA_SHADER_FRAGMENT)
2101 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2102 "declared as both input and output");
2106 memset(& $$, 0, sizeof($$));
2107 $$.flags.q.uniform = 1;
2111 memset(& $$, 0, sizeof($$));
2112 $$.flags.q.buffer = 1;
2116 memset(& $$, 0, sizeof($$));
2117 $$.flags.q.shared_storage = 1;
2124 memset(& $$, 0, sizeof($$));
2125 $$.flags.q.coherent = 1;
2129 memset(& $$, 0, sizeof($$));
2130 $$.flags.q._volatile = 1;
2134 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2135 memset(& $$, 0, sizeof($$));
2136 $$.flags.q.restrict_flag = 1;
2140 memset(& $$, 0, sizeof($$));
2141 $$.flags.q.read_only = 1;
2145 memset(& $$, 0, sizeof($$));
2146 $$.flags.q.write_only = 1;
2153 void *ctx = state->linalloc;
2154 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2155 ast_unsized_array_dim, NULL,
2157 $$->set_location_range(@1, @2);
2159 | '[' constant_expression ']'
2161 void *ctx = state->linalloc;
2162 $$ = new(ctx) ast_array_specifier(@1, $2);
2163 $$->set_location_range(@1, @3);
2165 | array_specifier '[' ']'
2167 void *ctx = state->linalloc;
2170 if (state->check_arrays_of_arrays_allowed(& @1)) {
2171 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2175 | array_specifier '[' constant_expression ']'
2179 if (state->check_arrays_of_arrays_allowed(& @1)) {
2180 $$->add_dimension($3);
2186 type_specifier_nonarray
2187 | type_specifier_nonarray array_specifier
2190 $$->array_specifier = $2;
2194 type_specifier_nonarray:
2195 basic_type_specifier_nonarray
2197 void *ctx = state->linalloc;
2198 $$ = new(ctx) ast_type_specifier($1);
2199 $$->set_location(@1);
2203 void *ctx = state->linalloc;
2204 $$ = new(ctx) ast_type_specifier($1);
2205 $$->set_location(@1);
2209 void *ctx = state->linalloc;
2210 $$ = new(ctx) ast_type_specifier($1);
2211 $$->set_location(@1);
2215 basic_type_specifier_nonarray:
2216 VOID_TOK { $$ = glsl_type::void_type; }
2217 | BASIC_TYPE_TOK { $$ = $1; };
2220 precision_qualifier:
2223 state->check_precision_qualifiers_allowed(&@1);
2224 $$ = ast_precision_high;
2228 state->check_precision_qualifiers_allowed(&@1);
2229 $$ = ast_precision_medium;
2233 state->check_precision_qualifiers_allowed(&@1);
2234 $$ = ast_precision_low;
2239 STRUCT any_identifier '{' struct_declaration_list '}'
2241 void *ctx = state->linalloc;
2242 $$ = new(ctx) ast_struct_specifier($2, $4);
2243 $$->set_location_range(@2, @5);
2244 state->symbols->add_type($2, glsl_type::void_type);
2246 | STRUCT '{' struct_declaration_list '}'
2248 void *ctx = state->linalloc;
2250 /* All anonymous structs have the same name. This simplifies matching of
2251 * globals whose type is an unnamed struct.
2253 * It also avoids a memory leak when the same shader is compiled over and
2256 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2258 $$->set_location_range(@2, @4);
2262 struct_declaration_list:
2266 $1->link.self_link();
2268 | struct_declaration_list struct_declaration
2271 $$->link.insert_before(& $2->link);
2276 fully_specified_type struct_declarator_list ';'
2278 void *ctx = state->linalloc;
2279 ast_fully_specified_type *const type = $1;
2280 type->set_location(@1);
2282 if (state->has_bindless()) {
2283 ast_type_qualifier input_layout_mask;
2285 /* Allow to declare qualifiers for images. */
2286 input_layout_mask.flags.i = 0;
2287 input_layout_mask.flags.q.coherent = 1;
2288 input_layout_mask.flags.q._volatile = 1;
2289 input_layout_mask.flags.q.restrict_flag = 1;
2290 input_layout_mask.flags.q.read_only = 1;
2291 input_layout_mask.flags.q.write_only = 1;
2292 input_layout_mask.flags.q.explicit_image_format = 1;
2294 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2295 _mesa_glsl_error(&@1, state,
2296 "only precision and image qualifiers may be "
2297 "applied to structure members");
2300 if (type->qualifier.flags.i != 0)
2301 _mesa_glsl_error(&@1, state,
2302 "only precision qualifiers may be applied to "
2303 "structure members");
2306 $$ = new(ctx) ast_declarator_list(type);
2307 $$->set_location(@2);
2309 $$->declarations.push_degenerate_list_at_head(& $2->link);
2313 struct_declarator_list:
2317 $1->link.self_link();
2319 | struct_declarator_list ',' struct_declarator
2322 $$->link.insert_before(& $3->link);
2329 void *ctx = state->linalloc;
2330 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2331 $$->set_location(@1);
2333 | any_identifier array_specifier
2335 void *ctx = state->linalloc;
2336 $$ = new(ctx) ast_declaration($1, $2, NULL);
2337 $$->set_location_range(@1, @2);
2342 assignment_expression
2343 | '{' initializer_list '}'
2347 | '{' initializer_list ',' '}'
2356 void *ctx = state->linalloc;
2357 $$ = new(ctx) ast_aggregate_initializer();
2358 $$->set_location(@1);
2359 $$->expressions.push_tail(& $1->link);
2361 | initializer_list ',' initializer
2363 $1->expressions.push_tail(& $3->link);
2367 declaration_statement:
2371 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2374 compound_statement { $$ = (ast_node *) $1; }
2379 declaration_statement
2380 | expression_statement
2381 | selection_statement
2383 | iteration_statement
2390 void *ctx = state->linalloc;
2391 $$ = new(ctx) ast_compound_statement(true, NULL);
2392 $$->set_location_range(@1, @2);
2396 state->symbols->push_scope();
2400 void *ctx = state->linalloc;
2401 $$ = new(ctx) ast_compound_statement(true, $3);
2402 $$->set_location_range(@1, @4);
2403 state->symbols->pop_scope();
2407 statement_no_new_scope:
2408 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2412 compound_statement_no_new_scope:
2415 void *ctx = state->linalloc;
2416 $$ = new(ctx) ast_compound_statement(false, NULL);
2417 $$->set_location_range(@1, @2);
2419 | '{' statement_list '}'
2421 void *ctx = state->linalloc;
2422 $$ = new(ctx) ast_compound_statement(false, $2);
2423 $$->set_location_range(@1, @3);
2431 _mesa_glsl_error(& @1, state, "<nil> statement");
2436 $$->link.self_link();
2438 | statement_list statement
2441 _mesa_glsl_error(& @2, state, "<nil> statement");
2445 $$->link.insert_before(& $2->link);
2449 expression_statement:
2452 void *ctx = state->linalloc;
2453 $$ = new(ctx) ast_expression_statement(NULL);
2454 $$->set_location(@1);
2458 void *ctx = state->linalloc;
2459 $$ = new(ctx) ast_expression_statement($1);
2460 $$->set_location(@1);
2464 selection_statement:
2465 IF '(' expression ')' selection_rest_statement
2467 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2469 $$->set_location_range(@1, @5);
2473 selection_rest_statement:
2474 statement ELSE statement
2476 $$.then_statement = $1;
2477 $$.else_statement = $3;
2479 | statement %prec THEN
2481 $$.then_statement = $1;
2482 $$.else_statement = NULL;
2489 $$ = (ast_node *) $1;
2491 | fully_specified_type any_identifier '=' initializer
2493 void *ctx = state->linalloc;
2494 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2495 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2496 decl->set_location_range(@2, @4);
2497 declarator->set_location(@1);
2499 declarator->declarations.push_tail(&decl->link);
2505 * switch_statement grammar is based on the syntax described in the body
2506 * of the GLSL spec, not in it's appendix!!!
2509 SWITCH '(' expression ')' switch_body
2511 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2512 $$->set_location_range(@1, @5);
2519 $$ = new(state->linalloc) ast_switch_body(NULL);
2520 $$->set_location_range(@1, @2);
2522 | '{' case_statement_list '}'
2524 $$ = new(state->linalloc) ast_switch_body($2);
2525 $$->set_location_range(@1, @3);
2532 $$ = new(state->linalloc) ast_case_label($2);
2533 $$->set_location(@2);
2537 $$ = new(state->linalloc) ast_case_label(NULL);
2538 $$->set_location(@2);
2545 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2547 labels->labels.push_tail(& $1->link);
2549 $$->set_location(@1);
2551 | case_label_list case_label
2554 $$->labels.push_tail(& $2->link);
2559 case_label_list statement
2561 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2562 stmts->set_location(@2);
2564 stmts->stmts.push_tail(& $2->link);
2567 | case_statement statement
2570 $$->stmts.push_tail(& $2->link);
2574 case_statement_list:
2577 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2578 cases->set_location(@1);
2580 cases->cases.push_tail(& $1->link);
2583 | case_statement_list case_statement
2586 $$->cases.push_tail(& $2->link);
2590 iteration_statement:
2591 WHILE '(' condition ')' statement_no_new_scope
2593 void *ctx = state->linalloc;
2594 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2595 NULL, $3, NULL, $5);
2596 $$->set_location_range(@1, @4);
2598 | DO statement WHILE '(' expression ')' ';'
2600 void *ctx = state->linalloc;
2601 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2602 NULL, $5, NULL, $2);
2603 $$->set_location_range(@1, @6);
2605 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2607 void *ctx = state->linalloc;
2608 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2609 $3, $4.cond, $4.rest, $6);
2610 $$->set_location_range(@1, @6);
2615 expression_statement
2616 | declaration_statement
2633 | conditionopt ';' expression
2640 // Grammar Note: No 'goto'. Gotos are not supported.
2644 void *ctx = state->linalloc;
2645 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2646 $$->set_location(@1);
2650 void *ctx = state->linalloc;
2651 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2652 $$->set_location(@1);
2656 void *ctx = state->linalloc;
2657 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2658 $$->set_location(@1);
2660 | RETURN expression ';'
2662 void *ctx = state->linalloc;
2663 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2664 $$->set_location_range(@1, @2);
2666 | DISCARD ';' // Fragment shader only.
2668 void *ctx = state->linalloc;
2669 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2670 $$->set_location(@1);
2674 external_declaration:
2675 function_definition { $$ = $1; }
2676 | declaration { $$ = $1; }
2677 | pragma_statement { $$ = NULL; }
2678 | layout_defaults { $$ = $1; }
2681 function_definition:
2682 function_prototype compound_statement_no_new_scope
2684 void *ctx = state->linalloc;
2685 $$ = new(ctx) ast_function_definition();
2686 $$->set_location_range(@1, @2);
2690 state->symbols->pop_scope();
2694 /* layout_qualifieropt is packed into this rule */
2696 basic_interface_block
2700 | layout_qualifier interface_block
2702 ast_interface_block *block = (ast_interface_block *) $2;
2704 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2705 block->layout.has_layout())) {
2713 | memory_qualifier interface_block
2715 ast_interface_block *block = (ast_interface_block *)$2;
2717 if (!block->default_layout.flags.q.buffer) {
2718 _mesa_glsl_error(& @1, state,
2719 "memory qualifiers can only be used in the "
2720 "declaration of shader storage blocks");
2722 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2730 basic_interface_block:
2731 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2733 ast_interface_block *const block = $6;
2735 if ($1.flags.q.uniform) {
2736 block->default_layout = *state->default_uniform_qualifier;
2737 } else if ($1.flags.q.buffer) {
2738 block->default_layout = *state->default_shader_storage_qualifier;
2740 block->block_name = $2;
2741 block->declarations.push_degenerate_list_at_head(& $4->link);
2743 _mesa_ast_process_interface_block(& @1, state, block, $1);
2749 interface_qualifier:
2752 memset(& $$, 0, sizeof($$));
2757 memset(& $$, 0, sizeof($$));
2762 memset(& $$, 0, sizeof($$));
2763 $$.flags.q.uniform = 1;
2767 memset(& $$, 0, sizeof($$));
2768 $$.flags.q.buffer = 1;
2770 | auxiliary_storage_qualifier interface_qualifier
2772 if (!$1.flags.q.patch) {
2773 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2775 if ($2.has_auxiliary_storage()) {
2776 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2779 $$.flags.q.patch = 1;
2786 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2790 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2791 $$->set_location(@1);
2793 | NEW_IDENTIFIER array_specifier
2795 $$ = new(state->linalloc) ast_interface_block($1, $2);
2796 $$->set_location_range(@1, @2);
2804 $1->link.self_link();
2806 | member_declaration member_list
2809 $2->link.insert_before(& $$->link);
2814 fully_specified_type struct_declarator_list ';'
2816 void *ctx = state->linalloc;
2817 ast_fully_specified_type *type = $1;
2818 type->set_location(@1);
2820 if (type->qualifier.flags.q.attribute) {
2821 _mesa_glsl_error(& @1, state,
2822 "keyword 'attribute' cannot be used with "
2823 "interface block member");
2824 } else if (type->qualifier.flags.q.varying) {
2825 _mesa_glsl_error(& @1, state,
2826 "keyword 'varying' cannot be used with "
2827 "interface block member");
2830 $$ = new(ctx) ast_declarator_list(type);
2831 $$->set_location(@2);
2833 $$->declarations.push_degenerate_list_at_head(& $2->link);
2837 layout_uniform_defaults:
2838 layout_qualifier layout_uniform_defaults
2841 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2845 | layout_qualifier UNIFORM ';'
2848 layout_buffer_defaults:
2849 layout_qualifier layout_buffer_defaults
2852 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2856 | layout_qualifier BUFFER ';'
2860 layout_qualifier layout_in_defaults
2863 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2866 if (!$$.validate_in_qualifier(& @1, state)) {
2870 | layout_qualifier IN_TOK ';'
2872 if (!$1.validate_in_qualifier(& @1, state)) {
2878 layout_out_defaults:
2879 layout_qualifier layout_out_defaults
2882 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2885 if (!$$.validate_out_qualifier(& @1, state)) {
2889 | layout_qualifier OUT_TOK ';'
2891 if (!$1.validate_out_qualifier(& @1, state)) {
2898 layout_uniform_defaults
2901 if (!state->default_uniform_qualifier->
2902 merge_qualifier(& @1, state, $1, false)) {
2905 if (!state->default_uniform_qualifier->
2906 push_to_global(& @1, state)) {
2910 | layout_buffer_defaults
2913 if (!state->default_shader_storage_qualifier->
2914 merge_qualifier(& @1, state, $1, false)) {
2917 if (!state->default_shader_storage_qualifier->
2918 push_to_global(& @1, state)) {
2922 /* From the GLSL 4.50 spec, section 4.4.5:
2924 * "It is a compile-time error to specify the binding identifier for
2925 * the global scope or for block member declarations."
2927 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2928 _mesa_glsl_error(& @1, state,
2929 "binding qualifier cannot be set for default layout");
2932 | layout_in_defaults
2935 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
2938 if (!state->in_qualifier->push_to_global(& @1, state)) {
2942 | layout_out_defaults
2945 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
2948 if (!state->out_qualifier->push_to_global(& @1, state)) {