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}
104 const char *identifier;
106 struct ast_type_qualifier type_qualifier;
109 ast_type_specifier *type_specifier;
110 ast_array_specifier *array_specifier;
111 ast_fully_specified_type *fully_specified_type;
112 ast_function *function;
113 ast_parameter_declarator *parameter_declarator;
114 ast_function_definition *function_definition;
115 ast_compound_statement *compound_statement;
116 ast_expression *expression;
117 ast_declarator_list *declarator_list;
118 ast_struct_specifier *struct_specifier;
119 ast_declaration *declaration;
120 ast_switch_body *switch_body;
121 ast_case_label *case_label;
122 ast_case_label_list *case_label_list;
123 ast_case_statement *case_statement;
124 ast_case_statement_list *case_statement_list;
125 ast_interface_block *interface_block;
126 ast_subroutine_list *subroutine_list;
129 ast_expression *rest;
130 } for_rest_statement;
133 ast_node *then_statement;
134 ast_node *else_statement;
135 } selection_rest_statement;
137 const glsl_type *type;
140 %token ATTRIBUTE CONST_TOK
141 %token <type> BASIC_TYPE_TOK
142 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
143 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
144 %token NOPERSPECTIVE FLAT SMOOTH
145 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
146 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
148 %token STRUCT VOID_TOK WHILE
149 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
150 %type <identifier> any_identifier
151 %type <interface_block> instance_name_opt
152 %token <real> FLOATCONSTANT
153 %token <dreal> DOUBLECONSTANT
154 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
155 %token <n64> INT64CONSTANT UINT64CONSTANT
156 %token <identifier> FIELD_SELECTION
157 %token LEFT_OP RIGHT_OP
158 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
159 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
160 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
162 %token INVARIANT PRECISE
163 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
165 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
166 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
167 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
168 %token PRAGMA_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 <declarator_list> init_declarator_list
251 %type <declarator_list> single_declaration
252 %type <expression> initializer
253 %type <expression> initializer_list
254 %type <node> declaration
255 %type <node> declaration_statement
256 %type <node> jump_statement
257 %type <node> interface_block
258 %type <interface_block> basic_interface_block
259 %type <struct_specifier> struct_specifier
260 %type <declarator_list> struct_declaration_list
261 %type <declarator_list> struct_declaration
262 %type <declaration> struct_declarator
263 %type <declaration> struct_declarator_list
264 %type <declarator_list> member_list
265 %type <declarator_list> member_declaration
266 %type <node> selection_statement
267 %type <selection_rest_statement> selection_rest_statement
268 %type <node> switch_statement
269 %type <switch_body> switch_body
270 %type <case_label_list> case_label_list
271 %type <case_label> case_label
272 %type <case_statement> case_statement
273 %type <case_statement_list> case_statement_list
274 %type <node> iteration_statement
275 %type <node> condition
276 %type <node> conditionopt
277 %type <node> for_init_statement
278 %type <for_rest_statement> for_rest_statement
279 %type <node> layout_defaults
280 %type <type_qualifier> layout_uniform_defaults
281 %type <type_qualifier> layout_buffer_defaults
282 %type <type_qualifier> layout_in_defaults
283 %type <type_qualifier> layout_out_defaults
289 version_statement extension_statement_list
291 _mesa_glsl_initialize_types(state);
293 external_declaration_list
295 delete state->symbols;
296 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
297 if (state->es_shader) {
298 if (state->stage == MESA_SHADER_FRAGMENT) {
299 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
301 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
302 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
304 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
305 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
306 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
307 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
309 _mesa_glsl_initialize_types(state);
314 /* blank - no #version specified: defaults are already set */
315 | VERSION_TOK INTCONSTANT EOL
317 state->process_version_directive(&@2, $2, NULL);
322 | VERSION_TOK INTCONSTANT any_identifier EOL
324 state->process_version_directive(&@2, $2, $3);
333 | PRAGMA_DEBUG_OFF EOL
334 | PRAGMA_OPTIMIZE_ON EOL
335 | PRAGMA_OPTIMIZE_OFF EOL
336 | PRAGMA_INVARIANT_ALL EOL
338 /* Pragma invariant(all) cannot be used in a fragment shader.
340 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
342 * "It is an error to use this pragma in a fragment shader."
344 if (state->is_version(120, 300) &&
345 state->stage == MESA_SHADER_FRAGMENT) {
346 _mesa_glsl_error(& @1, state,
347 "pragma `invariant(all)' cannot be used "
348 "in a fragment shader.");
349 } else if (!state->is_version(120, 100)) {
350 _mesa_glsl_warning(& @1, state,
351 "pragma `invariant(all)' not supported in %s "
352 "(GLSL ES 1.00 or GLSL 1.20 required)",
353 state->get_version_string());
355 state->all_invariant = true;
360 extension_statement_list:
362 | extension_statement_list extension_statement
372 EXTENSION any_identifier COLON any_identifier EOL
374 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
380 external_declaration_list:
383 /* FINISHME: The NULL test is required because pragmas are set to
384 * FINISHME: NULL. (See production rule for external_declaration.)
387 state->translation_unit.push_tail(& $1->link);
389 | external_declaration_list external_declaration
391 /* FINISHME: The NULL test is required because pragmas are set to
392 * FINISHME: NULL. (See production rule for external_declaration.)
395 state->translation_unit.push_tail(& $2->link);
397 | external_declaration_list extension_statement {
398 if (!state->allow_extension_directive_midshader) {
399 _mesa_glsl_error(& @2, state,
400 "#extension directive is not allowed "
401 "in the middle of a shader");
415 void *ctx = state->linalloc;
416 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
417 $$->set_location(@1);
418 $$->primary_expression.identifier = $1;
422 void *ctx = state->linalloc;
423 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
424 $$->set_location(@1);
425 $$->primary_expression.int_constant = $1;
429 void *ctx = state->linalloc;
430 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
431 $$->set_location(@1);
432 $$->primary_expression.uint_constant = $1;
436 void *ctx = state->linalloc;
437 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
438 $$->set_location(@1);
439 $$->primary_expression.int64_constant = $1;
443 void *ctx = state->linalloc;
444 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
445 $$->set_location(@1);
446 $$->primary_expression.uint64_constant = $1;
450 void *ctx = state->linalloc;
451 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
452 $$->set_location(@1);
453 $$->primary_expression.float_constant = $1;
457 void *ctx = state->linalloc;
458 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
459 $$->set_location(@1);
460 $$->primary_expression.double_constant = $1;
464 void *ctx = state->linalloc;
465 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
466 $$->set_location(@1);
467 $$->primary_expression.bool_constant = $1;
477 | postfix_expression '[' integer_expression ']'
479 void *ctx = state->linalloc;
480 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
481 $$->set_location_range(@1, @4);
487 | postfix_expression DOT_TOK FIELD_SELECTION
489 void *ctx = state->linalloc;
490 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
491 $$->set_location_range(@1, @3);
492 $$->primary_expression.identifier = $3;
494 | postfix_expression INC_OP
496 void *ctx = state->linalloc;
497 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
498 $$->set_location_range(@1, @2);
500 | postfix_expression DEC_OP
502 void *ctx = state->linalloc;
503 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
504 $$->set_location_range(@1, @2);
513 function_call_or_method
516 function_call_or_method:
517 function_call_generic
520 function_call_generic:
521 function_call_header_with_parameters ')'
522 | function_call_header_no_parameters ')'
525 function_call_header_no_parameters:
526 function_call_header VOID_TOK
527 | function_call_header
530 function_call_header_with_parameters:
531 function_call_header assignment_expression
534 $$->set_location(@1);
535 $$->expressions.push_tail(& $2->link);
537 | function_call_header_with_parameters ',' assignment_expression
540 $$->set_location(@1);
541 $$->expressions.push_tail(& $3->link);
545 // Grammar Note: Constructors look like functions, but lexical
546 // analysis recognized most of them as keywords. They are now
547 // recognized through "type_specifier".
548 function_call_header:
549 function_identifier '('
555 void *ctx = state->linalloc;
556 $$ = new(ctx) ast_function_expression($1);
557 $$->set_location(@1);
561 void *ctx = state->linalloc;
562 $$ = new(ctx) ast_function_expression($1);
563 $$->set_location(@1);
567 // Grammar Note: Constructors look like methods, but lexical
568 // analysis recognized most of them as keywords. They are now
569 // recognized through "type_specifier".
571 // Grammar Note: No traditional style type casts.
574 | INC_OP unary_expression
576 void *ctx = state->linalloc;
577 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
578 $$->set_location(@1);
580 | DEC_OP unary_expression
582 void *ctx = state->linalloc;
583 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
584 $$->set_location(@1);
586 | unary_operator unary_expression
588 void *ctx = state->linalloc;
589 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
590 $$->set_location_range(@1, @2);
594 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
596 '+' { $$ = ast_plus; }
597 | '-' { $$ = ast_neg; }
598 | '!' { $$ = ast_logic_not; }
599 | '~' { $$ = ast_bit_not; }
602 multiplicative_expression:
604 | multiplicative_expression '*' unary_expression
606 void *ctx = state->linalloc;
607 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
608 $$->set_location_range(@1, @3);
610 | multiplicative_expression '/' unary_expression
612 void *ctx = state->linalloc;
613 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
614 $$->set_location_range(@1, @3);
616 | multiplicative_expression '%' unary_expression
618 void *ctx = state->linalloc;
619 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
620 $$->set_location_range(@1, @3);
625 multiplicative_expression
626 | additive_expression '+' multiplicative_expression
628 void *ctx = state->linalloc;
629 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
630 $$->set_location_range(@1, @3);
632 | additive_expression '-' multiplicative_expression
634 void *ctx = state->linalloc;
635 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
636 $$->set_location_range(@1, @3);
642 | shift_expression LEFT_OP additive_expression
644 void *ctx = state->linalloc;
645 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
646 $$->set_location_range(@1, @3);
648 | shift_expression RIGHT_OP additive_expression
650 void *ctx = state->linalloc;
651 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
652 $$->set_location_range(@1, @3);
656 relational_expression:
658 | relational_expression '<' shift_expression
660 void *ctx = state->linalloc;
661 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
662 $$->set_location_range(@1, @3);
664 | relational_expression '>' shift_expression
666 void *ctx = state->linalloc;
667 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
668 $$->set_location_range(@1, @3);
670 | relational_expression LE_OP shift_expression
672 void *ctx = state->linalloc;
673 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
674 $$->set_location_range(@1, @3);
676 | relational_expression GE_OP shift_expression
678 void *ctx = state->linalloc;
679 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
680 $$->set_location_range(@1, @3);
685 relational_expression
686 | equality_expression EQ_OP relational_expression
688 void *ctx = state->linalloc;
689 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
690 $$->set_location_range(@1, @3);
692 | equality_expression NE_OP relational_expression
694 void *ctx = state->linalloc;
695 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
696 $$->set_location_range(@1, @3);
702 | and_expression '&' equality_expression
704 void *ctx = state->linalloc;
705 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
706 $$->set_location_range(@1, @3);
710 exclusive_or_expression:
712 | exclusive_or_expression '^' and_expression
714 void *ctx = state->linalloc;
715 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
716 $$->set_location_range(@1, @3);
720 inclusive_or_expression:
721 exclusive_or_expression
722 | inclusive_or_expression '|' exclusive_or_expression
724 void *ctx = state->linalloc;
725 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
726 $$->set_location_range(@1, @3);
730 logical_and_expression:
731 inclusive_or_expression
732 | logical_and_expression AND_OP inclusive_or_expression
734 void *ctx = state->linalloc;
735 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
736 $$->set_location_range(@1, @3);
740 logical_xor_expression:
741 logical_and_expression
742 | logical_xor_expression XOR_OP logical_and_expression
744 void *ctx = state->linalloc;
745 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
746 $$->set_location_range(@1, @3);
750 logical_or_expression:
751 logical_xor_expression
752 | logical_or_expression OR_OP logical_xor_expression
754 void *ctx = state->linalloc;
755 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
756 $$->set_location_range(@1, @3);
760 conditional_expression:
761 logical_or_expression
762 | logical_or_expression '?' expression ':' assignment_expression
764 void *ctx = state->linalloc;
765 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
766 $$->set_location_range(@1, @5);
770 assignment_expression:
771 conditional_expression
772 | unary_expression assignment_operator assignment_expression
774 void *ctx = state->linalloc;
775 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
776 $$->set_location_range(@1, @3);
781 '=' { $$ = ast_assign; }
782 | MUL_ASSIGN { $$ = ast_mul_assign; }
783 | DIV_ASSIGN { $$ = ast_div_assign; }
784 | MOD_ASSIGN { $$ = ast_mod_assign; }
785 | ADD_ASSIGN { $$ = ast_add_assign; }
786 | SUB_ASSIGN { $$ = ast_sub_assign; }
787 | LEFT_ASSIGN { $$ = ast_ls_assign; }
788 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
789 | AND_ASSIGN { $$ = ast_and_assign; }
790 | XOR_ASSIGN { $$ = ast_xor_assign; }
791 | OR_ASSIGN { $$ = ast_or_assign; }
795 assignment_expression
799 | expression ',' assignment_expression
801 void *ctx = state->linalloc;
802 if ($1->oper != ast_sequence) {
803 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
804 $$->set_location_range(@1, @3);
805 $$->expressions.push_tail(& $1->link);
810 $$->expressions.push_tail(& $3->link);
815 conditional_expression
819 function_prototype ';'
821 state->symbols->pop_scope();
824 | init_declarator_list ';'
828 | PRECISION precision_qualifier type_specifier ';'
830 $3->default_precision = $2;
835 ast_interface_block *block = (ast_interface_block *) $1;
836 if (block->layout.has_layout() || block->layout.has_memory()) {
837 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
841 block->layout = block->default_layout;
842 if (!block->layout.push_to_global(& @1, state)) {
850 function_declarator ')'
855 | function_header_with_parameters
858 function_header_with_parameters:
859 function_header parameter_declaration
862 $$->parameters.push_tail(& $2->link);
864 | function_header_with_parameters ',' parameter_declaration
867 $$->parameters.push_tail(& $3->link);
872 fully_specified_type variable_identifier '('
874 void *ctx = state->linalloc;
875 $$ = new(ctx) ast_function();
876 $$->set_location(@2);
877 $$->return_type = $1;
880 if ($1->qualifier.is_subroutine_decl()) {
881 /* add type for IDENTIFIER search */
882 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
884 state->symbols->add_function(new(state) ir_function($2));
885 state->symbols->push_scope();
889 parameter_declarator:
890 type_specifier any_identifier
892 void *ctx = state->linalloc;
893 $$ = new(ctx) ast_parameter_declarator();
894 $$->set_location_range(@1, @2);
895 $$->type = new(ctx) ast_fully_specified_type();
896 $$->type->set_location(@1);
897 $$->type->specifier = $1;
899 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
901 | type_specifier any_identifier array_specifier
903 void *ctx = state->linalloc;
904 $$ = new(ctx) ast_parameter_declarator();
905 $$->set_location_range(@1, @3);
906 $$->type = new(ctx) ast_fully_specified_type();
907 $$->type->set_location(@1);
908 $$->type->specifier = $1;
910 $$->array_specifier = $3;
911 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
915 parameter_declaration:
916 parameter_qualifier parameter_declarator
919 $$->type->qualifier = $1;
920 if (!$$->type->qualifier.push_to_global(& @1, state)) {
924 | parameter_qualifier parameter_type_specifier
926 void *ctx = state->linalloc;
927 $$ = new(ctx) ast_parameter_declarator();
928 $$->set_location(@2);
929 $$->type = new(ctx) ast_fully_specified_type();
930 $$->type->set_location_range(@1, @2);
931 $$->type->qualifier = $1;
932 if (!$$->type->qualifier.push_to_global(& @1, state)) {
935 $$->type->specifier = $2;
942 memset(& $$, 0, sizeof($$));
944 | CONST_TOK parameter_qualifier
946 if ($2.flags.q.constant)
947 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
950 $$.flags.q.constant = 1;
952 | PRECISE parameter_qualifier
954 if ($2.flags.q.precise)
955 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
958 $$.flags.q.precise = 1;
960 | parameter_direction_qualifier parameter_qualifier
962 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
963 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
965 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
966 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
970 $$.merge_qualifier(&@1, state, $2, false);
972 | precision_qualifier parameter_qualifier
974 if ($2.precision != ast_precision_none)
975 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
977 if (!state->has_420pack_or_es31() &&
979 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
984 | memory_qualifier parameter_qualifier
987 $$.merge_qualifier(&@1, state, $2, false);
990 parameter_direction_qualifier:
993 memset(& $$, 0, sizeof($$));
998 memset(& $$, 0, sizeof($$));
1003 memset(& $$, 0, sizeof($$));
1009 parameter_type_specifier:
1013 init_declarator_list:
1015 | init_declarator_list ',' any_identifier
1017 void *ctx = state->linalloc;
1018 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1019 decl->set_location(@3);
1022 $$->declarations.push_tail(&decl->link);
1023 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1025 | init_declarator_list ',' any_identifier array_specifier
1027 void *ctx = state->linalloc;
1028 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1029 decl->set_location_range(@3, @4);
1032 $$->declarations.push_tail(&decl->link);
1033 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1035 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1037 void *ctx = state->linalloc;
1038 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1039 decl->set_location_range(@3, @4);
1042 $$->declarations.push_tail(&decl->link);
1043 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1045 | init_declarator_list ',' any_identifier '=' initializer
1047 void *ctx = state->linalloc;
1048 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
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));
1057 // Grammar Note: No 'enum', or 'typedef'.
1059 fully_specified_type
1061 void *ctx = state->linalloc;
1062 /* Empty declaration list is valid. */
1063 $$ = new(ctx) ast_declarator_list($1);
1064 $$->set_location(@1);
1066 | fully_specified_type any_identifier
1068 void *ctx = state->linalloc;
1069 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1070 decl->set_location(@2);
1072 $$ = new(ctx) ast_declarator_list($1);
1073 $$->set_location_range(@1, @2);
1074 $$->declarations.push_tail(&decl->link);
1075 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1077 | fully_specified_type any_identifier array_specifier
1079 void *ctx = state->linalloc;
1080 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1081 decl->set_location_range(@2, @3);
1083 $$ = new(ctx) ast_declarator_list($1);
1084 $$->set_location_range(@1, @3);
1085 $$->declarations.push_tail(&decl->link);
1086 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1088 | fully_specified_type any_identifier array_specifier '=' initializer
1090 void *ctx = state->linalloc;
1091 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1092 decl->set_location_range(@2, @3);
1094 $$ = new(ctx) ast_declarator_list($1);
1095 $$->set_location_range(@1, @3);
1096 $$->declarations.push_tail(&decl->link);
1097 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1099 | fully_specified_type any_identifier '=' initializer
1101 void *ctx = state->linalloc;
1102 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1103 decl->set_location(@2);
1105 $$ = new(ctx) ast_declarator_list($1);
1106 $$->set_location_range(@1, @2);
1107 $$->declarations.push_tail(&decl->link);
1108 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1110 | INVARIANT variable_identifier
1112 void *ctx = state->linalloc;
1113 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1114 decl->set_location(@2);
1116 $$ = new(ctx) ast_declarator_list(NULL);
1117 $$->set_location_range(@1, @2);
1118 $$->invariant = true;
1120 $$->declarations.push_tail(&decl->link);
1122 | PRECISE variable_identifier
1124 void *ctx = state->linalloc;
1125 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1126 decl->set_location(@2);
1128 $$ = new(ctx) ast_declarator_list(NULL);
1129 $$->set_location_range(@1, @2);
1132 $$->declarations.push_tail(&decl->link);
1136 fully_specified_type:
1139 void *ctx = state->linalloc;
1140 $$ = new(ctx) ast_fully_specified_type();
1141 $$->set_location(@1);
1144 | type_qualifier type_specifier
1146 void *ctx = state->linalloc;
1147 $$ = new(ctx) ast_fully_specified_type();
1148 $$->set_location_range(@1, @2);
1150 if (!$$->qualifier.push_to_global(& @1, state)) {
1154 if ($$->specifier->structure != NULL &&
1155 $$->specifier->structure->is_declaration) {
1156 $$->specifier->structure->layout = &$$->qualifier;
1162 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1168 layout_qualifier_id_list:
1170 | layout_qualifier_id_list ',' layout_qualifier_id
1173 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1179 layout_qualifier_id:
1182 memset(& $$, 0, sizeof($$));
1184 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1185 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1186 state->is_version(150, 0))) {
1187 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1188 $$.flags.q.origin_upper_left = 1;
1189 } else if (match_layout_qualifier($1, "pixel_center_integer",
1191 $$.flags.q.pixel_center_integer = 1;
1194 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1195 _mesa_glsl_warning(& @1, state,
1196 "GL_ARB_fragment_coord_conventions layout "
1197 "identifier `%s' used", $1);
1201 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1203 (state->AMD_conservative_depth_enable ||
1204 state->ARB_conservative_depth_enable ||
1205 state->is_version(420, 0))) {
1206 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1207 $$.flags.q.depth_type = 1;
1208 $$.depth_type = ast_depth_any;
1209 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1210 $$.flags.q.depth_type = 1;
1211 $$.depth_type = ast_depth_greater;
1212 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1213 $$.flags.q.depth_type = 1;
1214 $$.depth_type = ast_depth_less;
1215 } else if (match_layout_qualifier($1, "depth_unchanged",
1217 $$.flags.q.depth_type = 1;
1218 $$.depth_type = ast_depth_unchanged;
1221 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1222 _mesa_glsl_warning(& @1, state,
1223 "GL_AMD_conservative_depth "
1224 "layout qualifier `%s' is used", $1);
1226 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1227 _mesa_glsl_warning(& @1, state,
1228 "GL_ARB_conservative_depth "
1229 "layout qualifier `%s' is used", $1);
1233 /* See also interface_block_layout_qualifier. */
1234 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1235 if (match_layout_qualifier($1, "std140", state) == 0) {
1236 $$.flags.q.std140 = 1;
1237 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1238 $$.flags.q.shared = 1;
1239 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1240 $$.flags.q.std430 = 1;
1241 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1242 $$.flags.q.column_major = 1;
1243 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1244 * below in the interface_block_layout_qualifier rule.
1246 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1249 * Also, this takes care of alternate capitalizations of
1250 * "row_major" (which is necessary because layout qualifiers
1251 * are case-insensitive in desktop GLSL).
1253 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1254 $$.flags.q.row_major = 1;
1255 /* "packed" is a reserved word in GLSL, and its token is
1256 * parsed below in the interface_block_layout_qualifier rule.
1257 * However, we must take care of alternate capitalizations of
1258 * "packed", because layout qualifiers are case-insensitive
1261 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1262 $$.flags.q.packed = 1;
1265 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1266 _mesa_glsl_warning(& @1, state,
1267 "#version 140 / GL_ARB_uniform_buffer_object "
1268 "layout qualifier `%s' is used", $1);
1272 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1274 static const struct {
1278 { "points", GL_POINTS },
1279 { "lines", GL_LINES },
1280 { "lines_adjacency", GL_LINES_ADJACENCY },
1281 { "line_strip", GL_LINE_STRIP },
1282 { "triangles", GL_TRIANGLES },
1283 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1284 { "triangle_strip", GL_TRIANGLE_STRIP },
1286 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1287 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1288 $$.flags.q.prim_type = 1;
1289 $$.prim_type = map[i].e;
1294 if ($$.flags.i && !state->has_geometry_shader() &&
1295 !state->has_tessellation_shader()) {
1296 _mesa_glsl_error(& @1, state, "#version 150 layout "
1297 "qualifier `%s' used", $1);
1301 /* Layout qualifiers for ARB_shader_image_load_store. */
1302 if (state->has_shader_image_load_store()) {
1304 static const struct {
1307 glsl_base_type base_type;
1308 /** Minimum desktop GLSL version required for the image
1309 * format. Use 130 if already present in the original
1312 unsigned required_glsl;
1313 /** Minimum GLSL ES version required for the image format. */
1314 unsigned required_essl;
1315 /* NV_image_formats */
1316 bool nv_image_formats;
1318 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1319 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1320 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1321 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1322 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1323 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1324 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1325 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1326 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1327 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1328 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1329 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1330 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1331 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1332 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1333 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1334 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1335 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1336 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1337 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1338 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1339 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1340 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1341 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1342 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1343 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1344 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
1345 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1346 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1347 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
1348 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1349 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
1350 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1351 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1352 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1353 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1354 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1355 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1356 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1359 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1360 if ((state->is_version(map[i].required_glsl,
1361 map[i].required_essl) ||
1362 (state->NV_image_formats_enable &&
1363 map[i].nv_image_formats)) &&
1364 match_layout_qualifier($1, map[i].name, state) == 0) {
1365 $$.flags.q.explicit_image_format = 1;
1366 $$.image_format = map[i].format;
1367 $$.image_base_type = map[i].base_type;
1375 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1376 /* From section 4.4.1.3 of the GLSL 4.50 specification
1377 * (Fragment Shader Inputs):
1379 * "Fragment shaders also allow the following layout
1380 * qualifier on in only (not with variable declarations)
1381 * layout-qualifier-id
1382 * early_fragment_tests
1385 if (state->stage != MESA_SHADER_FRAGMENT) {
1386 _mesa_glsl_error(& @1, state,
1387 "early_fragment_tests layout qualifier only "
1388 "valid in fragment shaders");
1391 $$.flags.q.early_fragment_tests = 1;
1394 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1395 if (state->stage != MESA_SHADER_FRAGMENT) {
1396 _mesa_glsl_error(& @1, state,
1397 "inner_coverage layout qualifier only "
1398 "valid in fragment shaders");
1401 if (state->INTEL_conservative_rasterization_enable) {
1402 $$.flags.q.inner_coverage = 1;
1404 _mesa_glsl_error(& @1, state,
1405 "inner_coverage layout qualifier present, "
1406 "but the INTEL_conservative_rasterization extension "
1411 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1412 if (state->stage != MESA_SHADER_FRAGMENT) {
1413 _mesa_glsl_error(& @1, state,
1414 "post_depth_coverage layout qualifier only "
1415 "valid in fragment shaders");
1418 if (state->ARB_post_depth_coverage_enable ||
1419 state->INTEL_conservative_rasterization_enable) {
1420 $$.flags.q.post_depth_coverage = 1;
1422 _mesa_glsl_error(& @1, state,
1423 "post_depth_coverage layout qualifier present, "
1424 "but the GL_ARB_post_depth_coverage extension "
1429 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1430 _mesa_glsl_error(& @1, state,
1431 "post_depth_coverage & inner_coverage layout qualifiers "
1432 "are mutually exclusive");
1436 /* Layout qualifiers for tessellation evaluation shaders. */
1438 static const struct {
1442 /* triangles already parsed by gs-specific code */
1443 { "quads", GL_QUADS },
1444 { "isolines", GL_ISOLINES },
1446 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1447 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1448 $$.flags.q.prim_type = 1;
1449 $$.prim_type = map[i].e;
1454 if ($$.flags.i && !state->has_tessellation_shader()) {
1455 _mesa_glsl_error(& @1, state,
1456 "primitive mode qualifier `%s' requires "
1457 "GLSL 4.00 or ARB_tessellation_shader", $1);
1461 static const struct {
1463 enum gl_tess_spacing e;
1465 { "equal_spacing", TESS_SPACING_EQUAL },
1466 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1467 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1469 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1470 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1471 $$.flags.q.vertex_spacing = 1;
1472 $$.vertex_spacing = map[i].e;
1477 if ($$.flags.i && !state->has_tessellation_shader()) {
1478 _mesa_glsl_error(& @1, state,
1479 "vertex spacing qualifier `%s' requires "
1480 "GLSL 4.00 or ARB_tessellation_shader", $1);
1484 if (match_layout_qualifier($1, "cw", state) == 0) {
1485 $$.flags.q.ordering = 1;
1486 $$.ordering = GL_CW;
1487 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1488 $$.flags.q.ordering = 1;
1489 $$.ordering = GL_CCW;
1492 if ($$.flags.i && !state->has_tessellation_shader()) {
1493 _mesa_glsl_error(& @1, state,
1494 "ordering qualifier `%s' requires "
1495 "GLSL 4.00 or ARB_tessellation_shader", $1);
1499 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1500 $$.flags.q.point_mode = 1;
1501 $$.point_mode = true;
1504 if ($$.flags.i && !state->has_tessellation_shader()) {
1505 _mesa_glsl_error(& @1, state,
1506 "qualifier `point_mode' requires "
1507 "GLSL 4.00 or ARB_tessellation_shader");
1512 static const struct {
1516 { "blend_support_multiply", BLEND_MULTIPLY },
1517 { "blend_support_screen", BLEND_SCREEN },
1518 { "blend_support_overlay", BLEND_OVERLAY },
1519 { "blend_support_darken", BLEND_DARKEN },
1520 { "blend_support_lighten", BLEND_LIGHTEN },
1521 { "blend_support_colordodge", BLEND_COLORDODGE },
1522 { "blend_support_colorburn", BLEND_COLORBURN },
1523 { "blend_support_hardlight", BLEND_HARDLIGHT },
1524 { "blend_support_softlight", BLEND_SOFTLIGHT },
1525 { "blend_support_difference", BLEND_DIFFERENCE },
1526 { "blend_support_exclusion", BLEND_EXCLUSION },
1527 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1528 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1529 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1530 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1531 { "blend_support_all_equations", BLEND_ALL },
1533 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1534 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1535 $$.flags.q.blend_support = 1;
1536 state->fs_blend_support |= map[i].mask;
1542 !state->KHR_blend_equation_advanced_enable &&
1543 !state->is_version(0, 320)) {
1544 _mesa_glsl_error(& @1, state,
1545 "advanced blending layout qualifiers require "
1546 "ESSL 3.20 or KHR_blend_equation_advanced");
1549 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1550 _mesa_glsl_error(& @1, state,
1551 "advanced blending layout qualifiers only "
1552 "valid in fragment shaders");
1556 /* Layout qualifiers for ARB_compute_variable_group_size. */
1558 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1559 $$.flags.q.local_size_variable = 1;
1562 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1563 _mesa_glsl_error(& @1, state,
1564 "qualifier `local_size_variable` requires "
1565 "ARB_compute_variable_group_size");
1569 /* Layout qualifiers for ARB_bindless_texture. */
1571 if (match_layout_qualifier($1, "bindless_sampler", state) == 0)
1572 $$.flags.q.bindless_sampler = 1;
1573 if (match_layout_qualifier($1, "bound_sampler", state) == 0)
1574 $$.flags.q.bound_sampler = 1;
1576 if (state->has_shader_image_load_store()) {
1577 if (match_layout_qualifier($1, "bindless_image", state) == 0)
1578 $$.flags.q.bindless_image = 1;
1579 if (match_layout_qualifier($1, "bound_image", state) == 0)
1580 $$.flags.q.bound_image = 1;
1583 if ($$.flags.i && !state->has_bindless()) {
1584 _mesa_glsl_error(& @1, state,
1585 "qualifier `%s` requires "
1586 "ARB_bindless_texture", $1);
1591 state->EXT_shader_framebuffer_fetch_non_coherent_enable) {
1592 if (match_layout_qualifier($1, "noncoherent", state) == 0)
1593 $$.flags.q.non_coherent = 1;
1597 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1602 | any_identifier '=' constant_expression
1604 memset(& $$, 0, sizeof($$));
1605 void *ctx = state->linalloc;
1607 if ($3->oper != ast_int_constant &&
1608 $3->oper != ast_uint_constant &&
1609 !state->has_enhanced_layouts()) {
1610 _mesa_glsl_error(& @1, state,
1611 "compile-time constant expressions require "
1612 "GLSL 4.40 or ARB_enhanced_layouts");
1615 if (match_layout_qualifier("align", $1, state) == 0) {
1616 if (!state->has_enhanced_layouts()) {
1617 _mesa_glsl_error(& @1, state,
1618 "align qualifier requires "
1619 "GLSL 4.40 or ARB_enhanced_layouts");
1621 $$.flags.q.explicit_align = 1;
1626 if (match_layout_qualifier("location", $1, state) == 0) {
1627 $$.flags.q.explicit_location = 1;
1629 if ($$.flags.q.attribute == 1 &&
1630 state->ARB_explicit_attrib_location_warn) {
1631 _mesa_glsl_warning(& @1, state,
1632 "GL_ARB_explicit_attrib_location layout "
1633 "identifier `%s' used", $1);
1638 if (match_layout_qualifier("component", $1, state) == 0) {
1639 if (!state->has_enhanced_layouts()) {
1640 _mesa_glsl_error(& @1, state,
1641 "component qualifier requires "
1642 "GLSL 4.40 or ARB_enhanced_layouts");
1644 $$.flags.q.explicit_component = 1;
1649 if (match_layout_qualifier("index", $1, state) == 0) {
1650 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1651 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1655 $$.flags.q.explicit_index = 1;
1659 if ((state->has_420pack_or_es31() ||
1660 state->has_atomic_counters() ||
1661 state->has_shader_storage_buffer_objects()) &&
1662 match_layout_qualifier("binding", $1, state) == 0) {
1663 $$.flags.q.explicit_binding = 1;
1667 if ((state->has_atomic_counters() ||
1668 state->has_enhanced_layouts()) &&
1669 match_layout_qualifier("offset", $1, state) == 0) {
1670 $$.flags.q.explicit_offset = 1;
1674 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1675 $$.flags.q.max_vertices = 1;
1676 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1677 if (!state->has_geometry_shader()) {
1678 _mesa_glsl_error(& @3, state,
1679 "#version 150 max_vertices qualifier "
1684 if (state->stage == MESA_SHADER_GEOMETRY) {
1685 if (match_layout_qualifier("stream", $1, state) == 0 &&
1686 state->check_explicit_attrib_stream_allowed(& @3)) {
1687 $$.flags.q.stream = 1;
1688 $$.flags.q.explicit_stream = 1;
1693 if (state->has_enhanced_layouts()) {
1694 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1695 $$.flags.q.xfb_buffer = 1;
1696 $$.flags.q.explicit_xfb_buffer = 1;
1700 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1701 $$.flags.q.explicit_xfb_offset = 1;
1705 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1706 $$.flags.q.xfb_stride = 1;
1707 $$.flags.q.explicit_xfb_stride = 1;
1712 static const char * const local_size_qualifiers[3] = {
1717 for (int i = 0; i < 3; i++) {
1718 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1720 if (!state->has_compute_shader()) {
1721 _mesa_glsl_error(& @3, state,
1722 "%s qualifier requires GLSL 4.30 or "
1723 "GLSL ES 3.10 or ARB_compute_shader",
1724 local_size_qualifiers[i]);
1727 $$.flags.q.local_size |= (1 << i);
1728 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1734 if (match_layout_qualifier("invocations", $1, state) == 0) {
1735 $$.flags.q.invocations = 1;
1736 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1737 if (!state->is_version(400, 320) &&
1738 !state->ARB_gpu_shader5_enable &&
1739 !state->OES_geometry_shader_enable &&
1740 !state->EXT_geometry_shader_enable) {
1741 _mesa_glsl_error(& @3, state,
1742 "GL_ARB_gpu_shader5 invocations "
1743 "qualifier specified", $3);
1747 /* Layout qualifiers for tessellation control shaders. */
1748 if (match_layout_qualifier("vertices", $1, state) == 0) {
1749 $$.flags.q.vertices = 1;
1750 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1751 if (!state->has_tessellation_shader()) {
1752 _mesa_glsl_error(& @1, state,
1753 "vertices qualifier requires GLSL 4.00 or "
1754 "ARB_tessellation_shader");
1758 /* If the identifier didn't match any known layout identifiers,
1762 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1767 | interface_block_layout_qualifier
1770 /* Layout qualifiers for ARB_uniform_buffer_object. */
1771 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1772 _mesa_glsl_error(& @1, state,
1773 "#version 140 / GL_ARB_uniform_buffer_object "
1774 "layout qualifier `%s' is used", $1);
1775 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1776 _mesa_glsl_warning(& @1, state,
1777 "#version 140 / GL_ARB_uniform_buffer_object "
1778 "layout qualifier `%s' is used", $1);
1783 /* This is a separate language rule because we parse these as tokens
1784 * (due to them being reserved keywords) instead of identifiers like
1785 * most qualifiers. See the any_identifier path of
1786 * layout_qualifier_id for the others.
1788 * Note that since layout qualifiers are case-insensitive in desktop
1789 * GLSL, all of these qualifiers need to be handled as identifiers as
1790 * well (by the any_identifier path of layout_qualifier_id).
1792 interface_block_layout_qualifier:
1795 memset(& $$, 0, sizeof($$));
1796 $$.flags.q.row_major = 1;
1800 memset(& $$, 0, sizeof($$));
1801 $$.flags.q.packed = 1;
1805 memset(& $$, 0, sizeof($$));
1806 $$.flags.q.shared = 1;
1810 subroutine_qualifier:
1813 memset(& $$, 0, sizeof($$));
1814 $$.flags.q.subroutine = 1;
1816 | SUBROUTINE '(' subroutine_type_list ')'
1818 memset(& $$, 0, sizeof($$));
1819 $$.flags.q.subroutine = 1;
1820 $$.subroutine_list = $3;
1824 subroutine_type_list:
1827 void *ctx = state->linalloc;
1828 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1829 decl->set_location(@1);
1831 $$ = new(ctx) ast_subroutine_list();
1832 $$->declarations.push_tail(&decl->link);
1834 | subroutine_type_list ',' any_identifier
1836 void *ctx = state->linalloc;
1837 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1838 decl->set_location(@3);
1841 $$->declarations.push_tail(&decl->link);
1845 interpolation_qualifier:
1848 memset(& $$, 0, sizeof($$));
1849 $$.flags.q.smooth = 1;
1853 memset(& $$, 0, sizeof($$));
1854 $$.flags.q.flat = 1;
1858 memset(& $$, 0, sizeof($$));
1859 $$.flags.q.noperspective = 1;
1864 /* Single qualifiers */
1867 memset(& $$, 0, sizeof($$));
1868 $$.flags.q.invariant = 1;
1872 memset(& $$, 0, sizeof($$));
1873 $$.flags.q.precise = 1;
1875 | auxiliary_storage_qualifier
1877 | interpolation_qualifier
1880 | subroutine_qualifier
1881 | precision_qualifier
1883 memset(&$$, 0, sizeof($$));
1887 /* Multiple qualifiers:
1888 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1889 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1891 * invariant interpolation auxiliary storage precision ...or...
1892 * layout storage precision
1894 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1895 * side don't contain any that must appear on the left hand side.
1896 * For example, when processing a storage qualifier, we check that there are
1897 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1899 | PRECISE type_qualifier
1901 if ($2.flags.q.precise)
1902 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1905 $$.flags.q.precise = 1;
1907 | INVARIANT type_qualifier
1909 if ($2.flags.q.invariant)
1910 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1912 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1913 _mesa_glsl_error(&@1, state,
1914 "\"invariant\" must come after \"precise\"");
1917 $$.flags.q.invariant = 1;
1919 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1921 * "Only variables output from a shader can be candidates for invariance.
1922 * This includes user-defined output variables and the built-in output
1923 * variables. As only outputs can be declared as invariant, an invariant
1924 * output from one shader stage will still match an input of a subsequent
1925 * stage without the input being declared as invariant."
1927 * On the desktop side, this text first appears in GLSL 4.30.
1929 if (state->is_version(430, 300) && $$.flags.q.in)
1930 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1932 | interpolation_qualifier type_qualifier
1934 /* Section 4.3 of the GLSL 1.40 specification states:
1935 * "...qualified with one of these interpolation qualifiers"
1937 * GLSL 1.30 claims to allow "one or more", but insists that:
1938 * "These interpolation qualifiers may only precede the qualifiers in,
1939 * centroid in, out, or centroid out in a declaration."
1941 * ...which means that e.g. smooth can't precede smooth, so there can be
1942 * only one after all, and the 1.40 text is a clarification, not a change.
1944 if ($2.has_interpolation())
1945 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1947 if (!state->has_420pack_or_es31() &&
1948 ($2.flags.q.precise || $2.flags.q.invariant)) {
1949 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1950 "after \"precise\" or \"invariant\"");
1954 $$.merge_qualifier(&@1, state, $2, false);
1956 | layout_qualifier type_qualifier
1958 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1959 * appear no later than auxiliary storage qualifiers. There is no
1960 * particularly clear spec language mandating this, but in all examples
1961 * the layout qualifier precedes the storage qualifier.
1963 * We allow combinations of layout with interpolation, invariant or
1964 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1965 * There is no clear spec guidance on this either.
1968 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1970 | subroutine_qualifier type_qualifier
1973 $$.merge_qualifier(&@1, state, $2, false);
1975 | auxiliary_storage_qualifier type_qualifier
1977 if ($2.has_auxiliary_storage()) {
1978 _mesa_glsl_error(&@1, state,
1979 "duplicate auxiliary storage qualifier (centroid or sample)");
1982 if (!state->has_420pack_or_es31() &&
1983 ($2.flags.q.precise || $2.flags.q.invariant ||
1984 $2.has_interpolation() || $2.has_layout())) {
1985 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1986 "just before storage qualifiers");
1989 $$.merge_qualifier(&@1, state, $2, false);
1991 | storage_qualifier type_qualifier
1993 /* Section 4.3 of the GLSL 1.20 specification states:
1994 * "Variable declarations may have a storage qualifier specified..."
1995 * 1.30 clarifies this to "may have one storage qualifier".
1997 if ($2.has_storage())
1998 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
2000 if (!state->has_420pack_or_es31() &&
2001 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
2002 $2.has_layout() || $2.has_auxiliary_storage())) {
2003 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2004 "precise, invariant, interpolation, layout and auxiliary "
2005 "storage qualifiers");
2009 $$.merge_qualifier(&@1, state, $2, false);
2011 | precision_qualifier type_qualifier
2013 if ($2.precision != ast_precision_none)
2014 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2016 if (!(state->has_420pack_or_es31()) &&
2018 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2023 | memory_qualifier type_qualifier
2026 $$.merge_qualifier(&@1, state, $2, false);
2030 auxiliary_storage_qualifier:
2033 memset(& $$, 0, sizeof($$));
2034 $$.flags.q.centroid = 1;
2038 memset(& $$, 0, sizeof($$));
2039 $$.flags.q.sample = 1;
2043 memset(& $$, 0, sizeof($$));
2044 $$.flags.q.patch = 1;
2050 memset(& $$, 0, sizeof($$));
2051 $$.flags.q.constant = 1;
2055 memset(& $$, 0, sizeof($$));
2056 $$.flags.q.attribute = 1;
2060 memset(& $$, 0, sizeof($$));
2061 $$.flags.q.varying = 1;
2065 memset(& $$, 0, sizeof($$));
2070 memset(& $$, 0, sizeof($$));
2073 if (state->stage == MESA_SHADER_GEOMETRY &&
2074 state->has_explicit_attrib_stream()) {
2075 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2078 * "If the block or variable is declared with the stream
2079 * identifier, it is associated with the specified stream;
2080 * otherwise, it is associated with the current default stream."
2082 $$.flags.q.stream = 1;
2083 $$.flags.q.explicit_stream = 0;
2084 $$.stream = state->out_qualifier->stream;
2087 if (state->has_enhanced_layouts()) {
2088 $$.flags.q.xfb_buffer = 1;
2089 $$.flags.q.explicit_xfb_buffer = 0;
2090 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2095 memset(& $$, 0, sizeof($$));
2099 if (!state->has_framebuffer_fetch() ||
2100 !state->is_version(130, 300) ||
2101 state->stage != MESA_SHADER_FRAGMENT)
2102 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2103 "declared as both input and output");
2107 memset(& $$, 0, sizeof($$));
2108 $$.flags.q.uniform = 1;
2112 memset(& $$, 0, sizeof($$));
2113 $$.flags.q.buffer = 1;
2117 memset(& $$, 0, sizeof($$));
2118 $$.flags.q.shared_storage = 1;
2125 memset(& $$, 0, sizeof($$));
2126 $$.flags.q.coherent = 1;
2130 memset(& $$, 0, sizeof($$));
2131 $$.flags.q._volatile = 1;
2135 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2136 memset(& $$, 0, sizeof($$));
2137 $$.flags.q.restrict_flag = 1;
2141 memset(& $$, 0, sizeof($$));
2142 $$.flags.q.read_only = 1;
2146 memset(& $$, 0, sizeof($$));
2147 $$.flags.q.write_only = 1;
2154 void *ctx = state->linalloc;
2155 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2156 ast_unsized_array_dim, NULL,
2158 $$->set_location_range(@1, @2);
2160 | '[' constant_expression ']'
2162 void *ctx = state->linalloc;
2163 $$ = new(ctx) ast_array_specifier(@1, $2);
2164 $$->set_location_range(@1, @3);
2166 | array_specifier '[' ']'
2168 void *ctx = state->linalloc;
2171 if (state->check_arrays_of_arrays_allowed(& @1)) {
2172 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2176 | array_specifier '[' constant_expression ']'
2180 if (state->check_arrays_of_arrays_allowed(& @1)) {
2181 $$->add_dimension($3);
2187 type_specifier_nonarray
2188 | type_specifier_nonarray array_specifier
2191 $$->array_specifier = $2;
2195 type_specifier_nonarray:
2196 basic_type_specifier_nonarray
2198 void *ctx = state->linalloc;
2199 $$ = new(ctx) ast_type_specifier($1);
2200 $$->set_location(@1);
2204 void *ctx = state->linalloc;
2205 $$ = new(ctx) ast_type_specifier($1);
2206 $$->set_location(@1);
2210 void *ctx = state->linalloc;
2211 $$ = new(ctx) ast_type_specifier($1);
2212 $$->set_location(@1);
2216 basic_type_specifier_nonarray:
2217 VOID_TOK { $$ = glsl_type::void_type; }
2218 | BASIC_TYPE_TOK { $$ = $1; };
2221 precision_qualifier:
2224 state->check_precision_qualifiers_allowed(&@1);
2225 $$ = ast_precision_high;
2229 state->check_precision_qualifiers_allowed(&@1);
2230 $$ = ast_precision_medium;
2234 state->check_precision_qualifiers_allowed(&@1);
2235 $$ = ast_precision_low;
2240 STRUCT any_identifier '{' struct_declaration_list '}'
2242 void *ctx = state->linalloc;
2243 $$ = new(ctx) ast_struct_specifier($2, $4);
2244 $$->set_location_range(@2, @5);
2245 state->symbols->add_type($2, glsl_type::void_type);
2247 | STRUCT '{' struct_declaration_list '}'
2249 void *ctx = state->linalloc;
2251 /* All anonymous structs have the same name. This simplifies matching of
2252 * globals whose type is an unnamed struct.
2254 * It also avoids a memory leak when the same shader is compiled over and
2257 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2259 $$->set_location_range(@2, @4);
2263 struct_declaration_list:
2267 $1->link.self_link();
2269 | struct_declaration_list struct_declaration
2272 $$->link.insert_before(& $2->link);
2277 fully_specified_type struct_declarator_list ';'
2279 void *ctx = state->linalloc;
2280 ast_fully_specified_type *const type = $1;
2281 type->set_location(@1);
2283 if (state->has_bindless()) {
2284 ast_type_qualifier input_layout_mask;
2286 /* Allow to declare qualifiers for images. */
2287 input_layout_mask.flags.i = 0;
2288 input_layout_mask.flags.q.coherent = 1;
2289 input_layout_mask.flags.q._volatile = 1;
2290 input_layout_mask.flags.q.restrict_flag = 1;
2291 input_layout_mask.flags.q.read_only = 1;
2292 input_layout_mask.flags.q.write_only = 1;
2293 input_layout_mask.flags.q.explicit_image_format = 1;
2295 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2296 _mesa_glsl_error(&@1, state,
2297 "only precision and image qualifiers may be "
2298 "applied to structure members");
2301 if (type->qualifier.flags.i != 0)
2302 _mesa_glsl_error(&@1, state,
2303 "only precision qualifiers may be applied to "
2304 "structure members");
2307 $$ = new(ctx) ast_declarator_list(type);
2308 $$->set_location(@2);
2310 $$->declarations.push_degenerate_list_at_head(& $2->link);
2314 struct_declarator_list:
2318 $1->link.self_link();
2320 | struct_declarator_list ',' struct_declarator
2323 $$->link.insert_before(& $3->link);
2330 void *ctx = state->linalloc;
2331 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2332 $$->set_location(@1);
2334 | any_identifier array_specifier
2336 void *ctx = state->linalloc;
2337 $$ = new(ctx) ast_declaration($1, $2, NULL);
2338 $$->set_location_range(@1, @2);
2343 assignment_expression
2344 | '{' initializer_list '}'
2348 | '{' initializer_list ',' '}'
2357 void *ctx = state->linalloc;
2358 $$ = new(ctx) ast_aggregate_initializer();
2359 $$->set_location(@1);
2360 $$->expressions.push_tail(& $1->link);
2362 | initializer_list ',' initializer
2364 $1->expressions.push_tail(& $3->link);
2368 declaration_statement:
2372 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2375 compound_statement { $$ = (ast_node *) $1; }
2380 declaration_statement
2381 | expression_statement
2382 | selection_statement
2384 | iteration_statement
2391 void *ctx = state->linalloc;
2392 $$ = new(ctx) ast_compound_statement(true, NULL);
2393 $$->set_location_range(@1, @2);
2397 state->symbols->push_scope();
2401 void *ctx = state->linalloc;
2402 $$ = new(ctx) ast_compound_statement(true, $3);
2403 $$->set_location_range(@1, @4);
2404 state->symbols->pop_scope();
2408 statement_no_new_scope:
2409 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2413 compound_statement_no_new_scope:
2416 void *ctx = state->linalloc;
2417 $$ = new(ctx) ast_compound_statement(false, NULL);
2418 $$->set_location_range(@1, @2);
2420 | '{' statement_list '}'
2422 void *ctx = state->linalloc;
2423 $$ = new(ctx) ast_compound_statement(false, $2);
2424 $$->set_location_range(@1, @3);
2432 _mesa_glsl_error(& @1, state, "<nil> statement");
2437 $$->link.self_link();
2439 | statement_list statement
2442 _mesa_glsl_error(& @2, state, "<nil> statement");
2446 $$->link.insert_before(& $2->link);
2450 expression_statement:
2453 void *ctx = state->linalloc;
2454 $$ = new(ctx) ast_expression_statement(NULL);
2455 $$->set_location(@1);
2459 void *ctx = state->linalloc;
2460 $$ = new(ctx) ast_expression_statement($1);
2461 $$->set_location(@1);
2465 selection_statement:
2466 IF '(' expression ')' selection_rest_statement
2468 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2470 $$->set_location_range(@1, @5);
2474 selection_rest_statement:
2475 statement ELSE statement
2477 $$.then_statement = $1;
2478 $$.else_statement = $3;
2480 | statement %prec THEN
2482 $$.then_statement = $1;
2483 $$.else_statement = NULL;
2490 $$ = (ast_node *) $1;
2492 | fully_specified_type any_identifier '=' initializer
2494 void *ctx = state->linalloc;
2495 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2496 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2497 decl->set_location_range(@2, @4);
2498 declarator->set_location(@1);
2500 declarator->declarations.push_tail(&decl->link);
2506 * switch_statement grammar is based on the syntax described in the body
2507 * of the GLSL spec, not in it's appendix!!!
2510 SWITCH '(' expression ')' switch_body
2512 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2513 $$->set_location_range(@1, @5);
2520 $$ = new(state->linalloc) ast_switch_body(NULL);
2521 $$->set_location_range(@1, @2);
2523 | '{' case_statement_list '}'
2525 $$ = new(state->linalloc) ast_switch_body($2);
2526 $$->set_location_range(@1, @3);
2533 $$ = new(state->linalloc) ast_case_label($2);
2534 $$->set_location(@2);
2538 $$ = new(state->linalloc) ast_case_label(NULL);
2539 $$->set_location(@2);
2546 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2548 labels->labels.push_tail(& $1->link);
2550 $$->set_location(@1);
2552 | case_label_list case_label
2555 $$->labels.push_tail(& $2->link);
2560 case_label_list statement
2562 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2563 stmts->set_location(@2);
2565 stmts->stmts.push_tail(& $2->link);
2568 | case_statement statement
2571 $$->stmts.push_tail(& $2->link);
2575 case_statement_list:
2578 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2579 cases->set_location(@1);
2581 cases->cases.push_tail(& $1->link);
2584 | case_statement_list case_statement
2587 $$->cases.push_tail(& $2->link);
2591 iteration_statement:
2592 WHILE '(' condition ')' statement_no_new_scope
2594 void *ctx = state->linalloc;
2595 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2596 NULL, $3, NULL, $5);
2597 $$->set_location_range(@1, @4);
2599 | DO statement WHILE '(' expression ')' ';'
2601 void *ctx = state->linalloc;
2602 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2603 NULL, $5, NULL, $2);
2604 $$->set_location_range(@1, @6);
2606 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2608 void *ctx = state->linalloc;
2609 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2610 $3, $4.cond, $4.rest, $6);
2611 $$->set_location_range(@1, @6);
2616 expression_statement
2617 | declaration_statement
2634 | conditionopt ';' expression
2641 // Grammar Note: No 'goto'. Gotos are not supported.
2645 void *ctx = state->linalloc;
2646 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2647 $$->set_location(@1);
2651 void *ctx = state->linalloc;
2652 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2653 $$->set_location(@1);
2657 void *ctx = state->linalloc;
2658 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2659 $$->set_location(@1);
2661 | RETURN expression ';'
2663 void *ctx = state->linalloc;
2664 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2665 $$->set_location_range(@1, @2);
2667 | DISCARD ';' // Fragment shader only.
2669 void *ctx = state->linalloc;
2670 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2671 $$->set_location(@1);
2675 external_declaration:
2676 function_definition { $$ = $1; }
2677 | declaration { $$ = $1; }
2678 | pragma_statement { $$ = NULL; }
2679 | layout_defaults { $$ = $1; }
2682 function_definition:
2683 function_prototype compound_statement_no_new_scope
2685 void *ctx = state->linalloc;
2686 $$ = new(ctx) ast_function_definition();
2687 $$->set_location_range(@1, @2);
2691 state->symbols->pop_scope();
2695 /* layout_qualifieropt is packed into this rule */
2697 basic_interface_block
2701 | layout_qualifier interface_block
2703 ast_interface_block *block = (ast_interface_block *) $2;
2705 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2706 block->layout.has_layout())) {
2714 | memory_qualifier interface_block
2716 ast_interface_block *block = (ast_interface_block *)$2;
2718 if (!block->default_layout.flags.q.buffer) {
2719 _mesa_glsl_error(& @1, state,
2720 "memory qualifiers can only be used in the "
2721 "declaration of shader storage blocks");
2723 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2731 basic_interface_block:
2732 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2734 ast_interface_block *const block = $6;
2736 if ($1.flags.q.uniform) {
2737 block->default_layout = *state->default_uniform_qualifier;
2738 } else if ($1.flags.q.buffer) {
2739 block->default_layout = *state->default_shader_storage_qualifier;
2741 block->block_name = $2;
2742 block->declarations.push_degenerate_list_at_head(& $4->link);
2744 _mesa_ast_process_interface_block(& @1, state, block, $1);
2750 interface_qualifier:
2753 memset(& $$, 0, sizeof($$));
2758 memset(& $$, 0, sizeof($$));
2763 memset(& $$, 0, sizeof($$));
2764 $$.flags.q.uniform = 1;
2768 memset(& $$, 0, sizeof($$));
2769 $$.flags.q.buffer = 1;
2771 | auxiliary_storage_qualifier interface_qualifier
2773 if (!$1.flags.q.patch) {
2774 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2776 if ($2.has_auxiliary_storage()) {
2777 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2780 $$.flags.q.patch = 1;
2787 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2791 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2792 $$->set_location(@1);
2794 | NEW_IDENTIFIER array_specifier
2796 $$ = new(state->linalloc) ast_interface_block($1, $2);
2797 $$->set_location_range(@1, @2);
2805 $1->link.self_link();
2807 | member_declaration member_list
2810 $2->link.insert_before(& $$->link);
2815 fully_specified_type struct_declarator_list ';'
2817 void *ctx = state->linalloc;
2818 ast_fully_specified_type *type = $1;
2819 type->set_location(@1);
2821 if (type->qualifier.flags.q.attribute) {
2822 _mesa_glsl_error(& @1, state,
2823 "keyword 'attribute' cannot be used with "
2824 "interface block member");
2825 } else if (type->qualifier.flags.q.varying) {
2826 _mesa_glsl_error(& @1, state,
2827 "keyword 'varying' cannot be used with "
2828 "interface block member");
2831 $$ = new(ctx) ast_declarator_list(type);
2832 $$->set_location(@2);
2834 $$->declarations.push_degenerate_list_at_head(& $2->link);
2838 layout_uniform_defaults:
2839 layout_qualifier layout_uniform_defaults
2842 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2846 | layout_qualifier UNIFORM ';'
2849 layout_buffer_defaults:
2850 layout_qualifier layout_buffer_defaults
2853 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2857 | layout_qualifier BUFFER ';'
2861 layout_qualifier layout_in_defaults
2864 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2867 if (!$$.validate_in_qualifier(& @1, state)) {
2871 | layout_qualifier IN_TOK ';'
2873 if (!$1.validate_in_qualifier(& @1, state)) {
2879 layout_out_defaults:
2880 layout_qualifier layout_out_defaults
2883 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2886 if (!$$.validate_out_qualifier(& @1, state)) {
2890 | layout_qualifier OUT_TOK ';'
2892 if (!$1.validate_out_qualifier(& @1, state)) {
2899 layout_uniform_defaults
2902 if (!state->default_uniform_qualifier->
2903 merge_qualifier(& @1, state, $1, false)) {
2906 if (!state->default_uniform_qualifier->
2907 push_to_global(& @1, state)) {
2911 | layout_buffer_defaults
2914 if (!state->default_shader_storage_qualifier->
2915 merge_qualifier(& @1, state, $1, false)) {
2918 if (!state->default_shader_storage_qualifier->
2919 push_to_global(& @1, state)) {
2923 /* From the GLSL 4.50 spec, section 4.4.5:
2925 * "It is a compile-time error to specify the binding identifier for
2926 * the global scope or for block member declarations."
2928 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2929 _mesa_glsl_error(& @1, state,
2930 "binding qualifier cannot be set for default layout");
2933 | layout_in_defaults
2936 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
2939 if (!state->in_qualifier->push_to_global(& @1, state)) {
2943 | layout_out_defaults
2946 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
2949 if (!state->out_qualifier->push_to_global(& @1, state)) {