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 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1596 | any_identifier '=' constant_expression
1598 memset(& $$, 0, sizeof($$));
1599 void *ctx = state->linalloc;
1601 if ($3->oper != ast_int_constant &&
1602 $3->oper != ast_uint_constant &&
1603 !state->has_enhanced_layouts()) {
1604 _mesa_glsl_error(& @1, state,
1605 "compile-time constant expressions require "
1606 "GLSL 4.40 or ARB_enhanced_layouts");
1609 if (match_layout_qualifier("align", $1, state) == 0) {
1610 if (!state->has_enhanced_layouts()) {
1611 _mesa_glsl_error(& @1, state,
1612 "align qualifier requires "
1613 "GLSL 4.40 or ARB_enhanced_layouts");
1615 $$.flags.q.explicit_align = 1;
1620 if (match_layout_qualifier("location", $1, state) == 0) {
1621 $$.flags.q.explicit_location = 1;
1623 if ($$.flags.q.attribute == 1 &&
1624 state->ARB_explicit_attrib_location_warn) {
1625 _mesa_glsl_warning(& @1, state,
1626 "GL_ARB_explicit_attrib_location layout "
1627 "identifier `%s' used", $1);
1632 if (match_layout_qualifier("component", $1, state) == 0) {
1633 if (!state->has_enhanced_layouts()) {
1634 _mesa_glsl_error(& @1, state,
1635 "component qualifier requires "
1636 "GLSL 4.40 or ARB_enhanced_layouts");
1638 $$.flags.q.explicit_component = 1;
1643 if (match_layout_qualifier("index", $1, state) == 0) {
1644 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1645 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1649 $$.flags.q.explicit_index = 1;
1653 if ((state->has_420pack_or_es31() ||
1654 state->has_atomic_counters() ||
1655 state->has_shader_storage_buffer_objects()) &&
1656 match_layout_qualifier("binding", $1, state) == 0) {
1657 $$.flags.q.explicit_binding = 1;
1661 if ((state->has_atomic_counters() ||
1662 state->has_enhanced_layouts()) &&
1663 match_layout_qualifier("offset", $1, state) == 0) {
1664 $$.flags.q.explicit_offset = 1;
1668 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1669 $$.flags.q.max_vertices = 1;
1670 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1671 if (!state->has_geometry_shader()) {
1672 _mesa_glsl_error(& @3, state,
1673 "#version 150 max_vertices qualifier "
1678 if (state->stage == MESA_SHADER_GEOMETRY) {
1679 if (match_layout_qualifier("stream", $1, state) == 0 &&
1680 state->check_explicit_attrib_stream_allowed(& @3)) {
1681 $$.flags.q.stream = 1;
1682 $$.flags.q.explicit_stream = 1;
1687 if (state->has_enhanced_layouts()) {
1688 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1689 $$.flags.q.xfb_buffer = 1;
1690 $$.flags.q.explicit_xfb_buffer = 1;
1694 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1695 $$.flags.q.explicit_xfb_offset = 1;
1699 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1700 $$.flags.q.xfb_stride = 1;
1701 $$.flags.q.explicit_xfb_stride = 1;
1706 static const char * const local_size_qualifiers[3] = {
1711 for (int i = 0; i < 3; i++) {
1712 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1714 if (!state->has_compute_shader()) {
1715 _mesa_glsl_error(& @3, state,
1716 "%s qualifier requires GLSL 4.30 or "
1717 "GLSL ES 3.10 or ARB_compute_shader",
1718 local_size_qualifiers[i]);
1721 $$.flags.q.local_size |= (1 << i);
1722 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1728 if (match_layout_qualifier("invocations", $1, state) == 0) {
1729 $$.flags.q.invocations = 1;
1730 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1731 if (!state->is_version(400, 320) &&
1732 !state->ARB_gpu_shader5_enable &&
1733 !state->OES_geometry_shader_enable &&
1734 !state->EXT_geometry_shader_enable) {
1735 _mesa_glsl_error(& @3, state,
1736 "GL_ARB_gpu_shader5 invocations "
1737 "qualifier specified", $3);
1741 /* Layout qualifiers for tessellation control shaders. */
1742 if (match_layout_qualifier("vertices", $1, state) == 0) {
1743 $$.flags.q.vertices = 1;
1744 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1745 if (!state->has_tessellation_shader()) {
1746 _mesa_glsl_error(& @1, state,
1747 "vertices qualifier requires GLSL 4.00 or "
1748 "ARB_tessellation_shader");
1752 /* If the identifier didn't match any known layout identifiers,
1756 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1761 | interface_block_layout_qualifier
1764 /* Layout qualifiers for ARB_uniform_buffer_object. */
1765 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1766 _mesa_glsl_error(& @1, state,
1767 "#version 140 / GL_ARB_uniform_buffer_object "
1768 "layout qualifier `%s' is used", $1);
1769 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1770 _mesa_glsl_warning(& @1, state,
1771 "#version 140 / GL_ARB_uniform_buffer_object "
1772 "layout qualifier `%s' is used", $1);
1777 /* This is a separate language rule because we parse these as tokens
1778 * (due to them being reserved keywords) instead of identifiers like
1779 * most qualifiers. See the any_identifier path of
1780 * layout_qualifier_id for the others.
1782 * Note that since layout qualifiers are case-insensitive in desktop
1783 * GLSL, all of these qualifiers need to be handled as identifiers as
1784 * well (by the any_identifier path of layout_qualifier_id).
1786 interface_block_layout_qualifier:
1789 memset(& $$, 0, sizeof($$));
1790 $$.flags.q.row_major = 1;
1794 memset(& $$, 0, sizeof($$));
1795 $$.flags.q.packed = 1;
1799 memset(& $$, 0, sizeof($$));
1800 $$.flags.q.shared = 1;
1804 subroutine_qualifier:
1807 memset(& $$, 0, sizeof($$));
1808 $$.flags.q.subroutine = 1;
1810 | SUBROUTINE '(' subroutine_type_list ')'
1812 memset(& $$, 0, sizeof($$));
1813 $$.flags.q.subroutine = 1;
1814 $$.subroutine_list = $3;
1818 subroutine_type_list:
1821 void *ctx = state->linalloc;
1822 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1823 decl->set_location(@1);
1825 $$ = new(ctx) ast_subroutine_list();
1826 $$->declarations.push_tail(&decl->link);
1828 | subroutine_type_list ',' any_identifier
1830 void *ctx = state->linalloc;
1831 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1832 decl->set_location(@3);
1835 $$->declarations.push_tail(&decl->link);
1839 interpolation_qualifier:
1842 memset(& $$, 0, sizeof($$));
1843 $$.flags.q.smooth = 1;
1847 memset(& $$, 0, sizeof($$));
1848 $$.flags.q.flat = 1;
1852 memset(& $$, 0, sizeof($$));
1853 $$.flags.q.noperspective = 1;
1858 /* Single qualifiers */
1861 memset(& $$, 0, sizeof($$));
1862 $$.flags.q.invariant = 1;
1866 memset(& $$, 0, sizeof($$));
1867 $$.flags.q.precise = 1;
1869 | auxiliary_storage_qualifier
1871 | interpolation_qualifier
1874 | subroutine_qualifier
1875 | precision_qualifier
1877 memset(&$$, 0, sizeof($$));
1881 /* Multiple qualifiers:
1882 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1883 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1885 * invariant interpolation auxiliary storage precision ...or...
1886 * layout storage precision
1888 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1889 * side don't contain any that must appear on the left hand side.
1890 * For example, when processing a storage qualifier, we check that there are
1891 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1893 | PRECISE type_qualifier
1895 if ($2.flags.q.precise)
1896 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1899 $$.flags.q.precise = 1;
1901 | INVARIANT type_qualifier
1903 if ($2.flags.q.invariant)
1904 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1906 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1907 _mesa_glsl_error(&@1, state,
1908 "\"invariant\" must come after \"precise\"");
1911 $$.flags.q.invariant = 1;
1913 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1915 * "Only variables output from a shader can be candidates for invariance.
1916 * This includes user-defined output variables and the built-in output
1917 * variables. As only outputs can be declared as invariant, an invariant
1918 * output from one shader stage will still match an input of a subsequent
1919 * stage without the input being declared as invariant."
1921 * On the desktop side, this text first appears in GLSL 4.30.
1923 if (state->is_version(430, 300) && $$.flags.q.in)
1924 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1926 | interpolation_qualifier type_qualifier
1928 /* Section 4.3 of the GLSL 1.40 specification states:
1929 * "...qualified with one of these interpolation qualifiers"
1931 * GLSL 1.30 claims to allow "one or more", but insists that:
1932 * "These interpolation qualifiers may only precede the qualifiers in,
1933 * centroid in, out, or centroid out in a declaration."
1935 * ...which means that e.g. smooth can't precede smooth, so there can be
1936 * only one after all, and the 1.40 text is a clarification, not a change.
1938 if ($2.has_interpolation())
1939 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1941 if (!state->has_420pack_or_es31() &&
1942 ($2.flags.q.precise || $2.flags.q.invariant)) {
1943 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1944 "after \"precise\" or \"invariant\"");
1948 $$.merge_qualifier(&@1, state, $2, false);
1950 | layout_qualifier type_qualifier
1952 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1953 * appear no later than auxiliary storage qualifiers. There is no
1954 * particularly clear spec language mandating this, but in all examples
1955 * the layout qualifier precedes the storage qualifier.
1957 * We allow combinations of layout with interpolation, invariant or
1958 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1959 * There is no clear spec guidance on this either.
1962 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1964 | subroutine_qualifier type_qualifier
1967 $$.merge_qualifier(&@1, state, $2, false);
1969 | auxiliary_storage_qualifier type_qualifier
1971 if ($2.has_auxiliary_storage()) {
1972 _mesa_glsl_error(&@1, state,
1973 "duplicate auxiliary storage qualifier (centroid or sample)");
1976 if (!state->has_420pack_or_es31() &&
1977 ($2.flags.q.precise || $2.flags.q.invariant ||
1978 $2.has_interpolation() || $2.has_layout())) {
1979 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1980 "just before storage qualifiers");
1983 $$.merge_qualifier(&@1, state, $2, false);
1985 | storage_qualifier type_qualifier
1987 /* Section 4.3 of the GLSL 1.20 specification states:
1988 * "Variable declarations may have a storage qualifier specified..."
1989 * 1.30 clarifies this to "may have one storage qualifier".
1991 if ($2.has_storage())
1992 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1994 if (!state->has_420pack_or_es31() &&
1995 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1996 $2.has_layout() || $2.has_auxiliary_storage())) {
1997 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1998 "precise, invariant, interpolation, layout and auxiliary "
1999 "storage qualifiers");
2003 $$.merge_qualifier(&@1, state, $2, false);
2005 | precision_qualifier type_qualifier
2007 if ($2.precision != ast_precision_none)
2008 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2010 if (!(state->has_420pack_or_es31()) &&
2012 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2017 | memory_qualifier type_qualifier
2020 $$.merge_qualifier(&@1, state, $2, false);
2024 auxiliary_storage_qualifier:
2027 memset(& $$, 0, sizeof($$));
2028 $$.flags.q.centroid = 1;
2032 memset(& $$, 0, sizeof($$));
2033 $$.flags.q.sample = 1;
2037 memset(& $$, 0, sizeof($$));
2038 $$.flags.q.patch = 1;
2044 memset(& $$, 0, sizeof($$));
2045 $$.flags.q.constant = 1;
2049 memset(& $$, 0, sizeof($$));
2050 $$.flags.q.attribute = 1;
2054 memset(& $$, 0, sizeof($$));
2055 $$.flags.q.varying = 1;
2059 memset(& $$, 0, sizeof($$));
2064 memset(& $$, 0, sizeof($$));
2067 if (state->stage == MESA_SHADER_GEOMETRY &&
2068 state->has_explicit_attrib_stream()) {
2069 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2072 * "If the block or variable is declared with the stream
2073 * identifier, it is associated with the specified stream;
2074 * otherwise, it is associated with the current default stream."
2076 $$.flags.q.stream = 1;
2077 $$.flags.q.explicit_stream = 0;
2078 $$.stream = state->out_qualifier->stream;
2081 if (state->has_enhanced_layouts()) {
2082 $$.flags.q.xfb_buffer = 1;
2083 $$.flags.q.explicit_xfb_buffer = 0;
2084 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2089 memset(& $$, 0, sizeof($$));
2093 if (!state->has_framebuffer_fetch() ||
2094 !state->is_version(130, 300) ||
2095 state->stage != MESA_SHADER_FRAGMENT)
2096 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2097 "declared as both input and output");
2101 memset(& $$, 0, sizeof($$));
2102 $$.flags.q.uniform = 1;
2106 memset(& $$, 0, sizeof($$));
2107 $$.flags.q.buffer = 1;
2111 memset(& $$, 0, sizeof($$));
2112 $$.flags.q.shared_storage = 1;
2119 memset(& $$, 0, sizeof($$));
2120 $$.flags.q.coherent = 1;
2124 memset(& $$, 0, sizeof($$));
2125 $$.flags.q._volatile = 1;
2129 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2130 memset(& $$, 0, sizeof($$));
2131 $$.flags.q.restrict_flag = 1;
2135 memset(& $$, 0, sizeof($$));
2136 $$.flags.q.read_only = 1;
2140 memset(& $$, 0, sizeof($$));
2141 $$.flags.q.write_only = 1;
2148 void *ctx = state->linalloc;
2149 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2150 ast_unsized_array_dim, NULL,
2152 $$->set_location_range(@1, @2);
2154 | '[' constant_expression ']'
2156 void *ctx = state->linalloc;
2157 $$ = new(ctx) ast_array_specifier(@1, $2);
2158 $$->set_location_range(@1, @3);
2160 | array_specifier '[' ']'
2162 void *ctx = state->linalloc;
2165 if (state->check_arrays_of_arrays_allowed(& @1)) {
2166 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2170 | array_specifier '[' constant_expression ']'
2174 if (state->check_arrays_of_arrays_allowed(& @1)) {
2175 $$->add_dimension($3);
2181 type_specifier_nonarray
2182 | type_specifier_nonarray array_specifier
2185 $$->array_specifier = $2;
2189 type_specifier_nonarray:
2190 basic_type_specifier_nonarray
2192 void *ctx = state->linalloc;
2193 $$ = new(ctx) ast_type_specifier($1);
2194 $$->set_location(@1);
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 basic_type_specifier_nonarray:
2211 VOID_TOK { $$ = glsl_type::void_type; }
2212 | BASIC_TYPE_TOK { $$ = $1; };
2215 precision_qualifier:
2218 state->check_precision_qualifiers_allowed(&@1);
2219 $$ = ast_precision_high;
2223 state->check_precision_qualifiers_allowed(&@1);
2224 $$ = ast_precision_medium;
2228 state->check_precision_qualifiers_allowed(&@1);
2229 $$ = ast_precision_low;
2234 STRUCT any_identifier '{' struct_declaration_list '}'
2236 void *ctx = state->linalloc;
2237 $$ = new(ctx) ast_struct_specifier($2, $4);
2238 $$->set_location_range(@2, @5);
2239 state->symbols->add_type($2, glsl_type::void_type);
2241 | STRUCT '{' struct_declaration_list '}'
2243 void *ctx = state->linalloc;
2245 /* All anonymous structs have the same name. This simplifies matching of
2246 * globals whose type is an unnamed struct.
2248 * It also avoids a memory leak when the same shader is compiled over and
2251 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2253 $$->set_location_range(@2, @4);
2257 struct_declaration_list:
2261 $1->link.self_link();
2263 | struct_declaration_list struct_declaration
2266 $$->link.insert_before(& $2->link);
2271 fully_specified_type struct_declarator_list ';'
2273 void *ctx = state->linalloc;
2274 ast_fully_specified_type *const type = $1;
2275 type->set_location(@1);
2277 if (state->has_bindless()) {
2278 ast_type_qualifier input_layout_mask;
2280 /* Allow to declare qualifiers for images. */
2281 input_layout_mask.flags.i = 0;
2282 input_layout_mask.flags.q.coherent = 1;
2283 input_layout_mask.flags.q._volatile = 1;
2284 input_layout_mask.flags.q.restrict_flag = 1;
2285 input_layout_mask.flags.q.read_only = 1;
2286 input_layout_mask.flags.q.write_only = 1;
2287 input_layout_mask.flags.q.explicit_image_format = 1;
2289 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2290 _mesa_glsl_error(&@1, state,
2291 "only precision and image qualifiers may be "
2292 "applied to structure members");
2295 if (type->qualifier.flags.i != 0)
2296 _mesa_glsl_error(&@1, state,
2297 "only precision qualifiers may be applied to "
2298 "structure members");
2301 $$ = new(ctx) ast_declarator_list(type);
2302 $$->set_location(@2);
2304 $$->declarations.push_degenerate_list_at_head(& $2->link);
2308 struct_declarator_list:
2312 $1->link.self_link();
2314 | struct_declarator_list ',' struct_declarator
2317 $$->link.insert_before(& $3->link);
2324 void *ctx = state->linalloc;
2325 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2326 $$->set_location(@1);
2328 | any_identifier array_specifier
2330 void *ctx = state->linalloc;
2331 $$ = new(ctx) ast_declaration($1, $2, NULL);
2332 $$->set_location_range(@1, @2);
2337 assignment_expression
2338 | '{' initializer_list '}'
2342 | '{' initializer_list ',' '}'
2351 void *ctx = state->linalloc;
2352 $$ = new(ctx) ast_aggregate_initializer();
2353 $$->set_location(@1);
2354 $$->expressions.push_tail(& $1->link);
2356 | initializer_list ',' initializer
2358 $1->expressions.push_tail(& $3->link);
2362 declaration_statement:
2366 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2369 compound_statement { $$ = (ast_node *) $1; }
2374 declaration_statement
2375 | expression_statement
2376 | selection_statement
2378 | iteration_statement
2385 void *ctx = state->linalloc;
2386 $$ = new(ctx) ast_compound_statement(true, NULL);
2387 $$->set_location_range(@1, @2);
2391 state->symbols->push_scope();
2395 void *ctx = state->linalloc;
2396 $$ = new(ctx) ast_compound_statement(true, $3);
2397 $$->set_location_range(@1, @4);
2398 state->symbols->pop_scope();
2402 statement_no_new_scope:
2403 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2407 compound_statement_no_new_scope:
2410 void *ctx = state->linalloc;
2411 $$ = new(ctx) ast_compound_statement(false, NULL);
2412 $$->set_location_range(@1, @2);
2414 | '{' statement_list '}'
2416 void *ctx = state->linalloc;
2417 $$ = new(ctx) ast_compound_statement(false, $2);
2418 $$->set_location_range(@1, @3);
2426 _mesa_glsl_error(& @1, state, "<nil> statement");
2431 $$->link.self_link();
2433 | statement_list statement
2436 _mesa_glsl_error(& @2, state, "<nil> statement");
2440 $$->link.insert_before(& $2->link);
2444 expression_statement:
2447 void *ctx = state->linalloc;
2448 $$ = new(ctx) ast_expression_statement(NULL);
2449 $$->set_location(@1);
2453 void *ctx = state->linalloc;
2454 $$ = new(ctx) ast_expression_statement($1);
2455 $$->set_location(@1);
2459 selection_statement:
2460 IF '(' expression ')' selection_rest_statement
2462 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2464 $$->set_location_range(@1, @5);
2468 selection_rest_statement:
2469 statement ELSE statement
2471 $$.then_statement = $1;
2472 $$.else_statement = $3;
2474 | statement %prec THEN
2476 $$.then_statement = $1;
2477 $$.else_statement = NULL;
2484 $$ = (ast_node *) $1;
2486 | fully_specified_type any_identifier '=' initializer
2488 void *ctx = state->linalloc;
2489 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2490 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2491 decl->set_location_range(@2, @4);
2492 declarator->set_location(@1);
2494 declarator->declarations.push_tail(&decl->link);
2500 * switch_statement grammar is based on the syntax described in the body
2501 * of the GLSL spec, not in it's appendix!!!
2504 SWITCH '(' expression ')' switch_body
2506 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2507 $$->set_location_range(@1, @5);
2514 $$ = new(state->linalloc) ast_switch_body(NULL);
2515 $$->set_location_range(@1, @2);
2517 | '{' case_statement_list '}'
2519 $$ = new(state->linalloc) ast_switch_body($2);
2520 $$->set_location_range(@1, @3);
2527 $$ = new(state->linalloc) ast_case_label($2);
2528 $$->set_location(@2);
2532 $$ = new(state->linalloc) ast_case_label(NULL);
2533 $$->set_location(@2);
2540 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2542 labels->labels.push_tail(& $1->link);
2544 $$->set_location(@1);
2546 | case_label_list case_label
2549 $$->labels.push_tail(& $2->link);
2554 case_label_list statement
2556 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2557 stmts->set_location(@2);
2559 stmts->stmts.push_tail(& $2->link);
2562 | case_statement statement
2565 $$->stmts.push_tail(& $2->link);
2569 case_statement_list:
2572 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2573 cases->set_location(@1);
2575 cases->cases.push_tail(& $1->link);
2578 | case_statement_list case_statement
2581 $$->cases.push_tail(& $2->link);
2585 iteration_statement:
2586 WHILE '(' condition ')' statement_no_new_scope
2588 void *ctx = state->linalloc;
2589 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2590 NULL, $3, NULL, $5);
2591 $$->set_location_range(@1, @4);
2593 | DO statement WHILE '(' expression ')' ';'
2595 void *ctx = state->linalloc;
2596 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2597 NULL, $5, NULL, $2);
2598 $$->set_location_range(@1, @6);
2600 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2602 void *ctx = state->linalloc;
2603 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2604 $3, $4.cond, $4.rest, $6);
2605 $$->set_location_range(@1, @6);
2610 expression_statement
2611 | declaration_statement
2628 | conditionopt ';' expression
2635 // Grammar Note: No 'goto'. Gotos are not supported.
2639 void *ctx = state->linalloc;
2640 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2641 $$->set_location(@1);
2645 void *ctx = state->linalloc;
2646 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2647 $$->set_location(@1);
2651 void *ctx = state->linalloc;
2652 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2653 $$->set_location(@1);
2655 | RETURN expression ';'
2657 void *ctx = state->linalloc;
2658 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2659 $$->set_location_range(@1, @2);
2661 | DISCARD ';' // Fragment shader only.
2663 void *ctx = state->linalloc;
2664 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2665 $$->set_location(@1);
2669 external_declaration:
2670 function_definition { $$ = $1; }
2671 | declaration { $$ = $1; }
2672 | pragma_statement { $$ = NULL; }
2673 | layout_defaults { $$ = $1; }
2676 function_definition:
2677 function_prototype compound_statement_no_new_scope
2679 void *ctx = state->linalloc;
2680 $$ = new(ctx) ast_function_definition();
2681 $$->set_location_range(@1, @2);
2685 state->symbols->pop_scope();
2689 /* layout_qualifieropt is packed into this rule */
2691 basic_interface_block
2695 | layout_qualifier interface_block
2697 ast_interface_block *block = (ast_interface_block *) $2;
2699 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2700 block->layout.has_layout())) {
2708 | memory_qualifier interface_block
2710 ast_interface_block *block = (ast_interface_block *)$2;
2712 if (!block->default_layout.flags.q.buffer) {
2713 _mesa_glsl_error(& @1, state,
2714 "memory qualifiers can only be used in the "
2715 "declaration of shader storage blocks");
2717 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2725 basic_interface_block:
2726 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2728 ast_interface_block *const block = $6;
2730 if ($1.flags.q.uniform) {
2731 block->default_layout = *state->default_uniform_qualifier;
2732 } else if ($1.flags.q.buffer) {
2733 block->default_layout = *state->default_shader_storage_qualifier;
2735 block->block_name = $2;
2736 block->declarations.push_degenerate_list_at_head(& $4->link);
2738 _mesa_ast_process_interface_block(& @1, state, block, $1);
2744 interface_qualifier:
2747 memset(& $$, 0, sizeof($$));
2752 memset(& $$, 0, sizeof($$));
2757 memset(& $$, 0, sizeof($$));
2758 $$.flags.q.uniform = 1;
2762 memset(& $$, 0, sizeof($$));
2763 $$.flags.q.buffer = 1;
2765 | auxiliary_storage_qualifier interface_qualifier
2767 if (!$1.flags.q.patch) {
2768 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2770 if ($2.has_auxiliary_storage()) {
2771 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2774 $$.flags.q.patch = 1;
2781 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2785 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2786 $$->set_location(@1);
2788 | NEW_IDENTIFIER array_specifier
2790 $$ = new(state->linalloc) ast_interface_block($1, $2);
2791 $$->set_location_range(@1, @2);
2799 $1->link.self_link();
2801 | member_declaration member_list
2804 $2->link.insert_before(& $$->link);
2809 fully_specified_type struct_declarator_list ';'
2811 void *ctx = state->linalloc;
2812 ast_fully_specified_type *type = $1;
2813 type->set_location(@1);
2815 if (type->qualifier.flags.q.attribute) {
2816 _mesa_glsl_error(& @1, state,
2817 "keyword 'attribute' cannot be used with "
2818 "interface block member");
2819 } else if (type->qualifier.flags.q.varying) {
2820 _mesa_glsl_error(& @1, state,
2821 "keyword 'varying' cannot be used with "
2822 "interface block member");
2825 $$ = new(ctx) ast_declarator_list(type);
2826 $$->set_location(@2);
2828 $$->declarations.push_degenerate_list_at_head(& $2->link);
2832 layout_uniform_defaults:
2833 layout_qualifier layout_uniform_defaults
2836 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2840 | layout_qualifier UNIFORM ';'
2843 layout_buffer_defaults:
2844 layout_qualifier layout_buffer_defaults
2847 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2851 | layout_qualifier BUFFER ';'
2855 layout_qualifier layout_in_defaults
2858 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2861 if (!$$.validate_in_qualifier(& @1, state)) {
2865 | layout_qualifier IN_TOK ';'
2867 if (!$1.validate_in_qualifier(& @1, state)) {
2873 layout_out_defaults:
2874 layout_qualifier layout_out_defaults
2877 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2880 if (!$$.validate_out_qualifier(& @1, state)) {
2884 | layout_qualifier OUT_TOK ';'
2886 if (!$1.validate_out_qualifier(& @1, state)) {
2893 layout_uniform_defaults
2896 if (!state->default_uniform_qualifier->
2897 merge_qualifier(& @1, state, $1, false)) {
2900 if (!state->default_uniform_qualifier->
2901 push_to_global(& @1, state)) {
2905 | layout_buffer_defaults
2908 if (!state->default_shader_storage_qualifier->
2909 merge_qualifier(& @1, state, $1, false)) {
2912 if (!state->default_shader_storage_qualifier->
2913 push_to_global(& @1, state)) {
2917 /* From the GLSL 4.50 spec, section 4.4.5:
2919 * "It is a compile-time error to specify the binding identifier for
2920 * the global scope or for block member declarations."
2922 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2923 _mesa_glsl_error(& @1, state,
2924 "binding qualifier cannot be set for default layout");
2927 | layout_in_defaults
2930 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
2933 if (!state->in_qualifier->push_to_global(& @1, state)) {
2937 | layout_out_defaults
2940 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
2943 if (!state->out_qualifier->push_to_global(& @1, state)) {