3 * Copyright © 2008, 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
33 #include "glsl_parser_extras.h"
34 #include "compiler/glsl_types.h"
35 #include "main/context.h"
38 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
43 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
45 _mesa_glsl_error(loc, st, "%s", msg);
49 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
51 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
54 static bool match_layout_qualifier(const char *s1, const char *s2,
55 _mesa_glsl_parse_state *state)
57 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
59 * "The tokens in any layout-qualifier-id-list ... are not case
60 * sensitive, unless explicitly noted otherwise."
62 * The text "unless explicitly noted otherwise" appears to be
63 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
66 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
69 * "As for other identifiers, they are case sensitive."
71 * So we need to do a case-sensitive or a case-insensitive match,
72 * depending on whether we are compiling for GLSL ES.
75 return strcmp(s1, s2);
77 return strcasecmp(s1, s2);
95 %lex-param {struct _mesa_glsl_parse_state *state}
96 %parse-param {struct _mesa_glsl_parse_state *state}
103 const char *identifier;
105 struct ast_type_qualifier type_qualifier;
108 ast_type_specifier *type_specifier;
109 ast_array_specifier *array_specifier;
110 ast_fully_specified_type *fully_specified_type;
111 ast_function *function;
112 ast_parameter_declarator *parameter_declarator;
113 ast_function_definition *function_definition;
114 ast_compound_statement *compound_statement;
115 ast_expression *expression;
116 ast_declarator_list *declarator_list;
117 ast_struct_specifier *struct_specifier;
118 ast_declaration *declaration;
119 ast_switch_body *switch_body;
120 ast_case_label *case_label;
121 ast_case_label_list *case_label_list;
122 ast_case_statement *case_statement;
123 ast_case_statement_list *case_statement_list;
124 ast_interface_block *interface_block;
125 ast_subroutine_list *subroutine_list;
128 ast_expression *rest;
129 } for_rest_statement;
132 ast_node *then_statement;
133 ast_node *else_statement;
134 } selection_rest_statement;
137 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
138 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
139 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
140 %token INT64_TOK UINT64_TOK I64VEC2 I64VEC3 I64VEC4 U64VEC2 U64VEC3 U64VEC4
141 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
142 %token NOPERSPECTIVE FLAT SMOOTH
143 %token MAT2X2 MAT2X3 MAT2X4
144 %token MAT3X2 MAT3X3 MAT3X4
145 %token MAT4X2 MAT4X3 MAT4X4
146 %token DMAT2X2 DMAT2X3 DMAT2X4
147 %token DMAT3X2 DMAT3X3 DMAT3X4
148 %token DMAT4X2 DMAT4X3 DMAT4X4
149 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
150 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
151 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
152 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
153 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
154 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
155 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
156 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
157 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
158 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
159 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
160 %token SAMPLEREXTERNALOES
161 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
162 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
163 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
164 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
165 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
166 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
167 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
168 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
171 %token STRUCT VOID_TOK WHILE
172 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
173 %type <identifier> any_identifier
174 %type <interface_block> instance_name_opt
175 %token <real> FLOATCONSTANT
176 %token <dreal> DOUBLECONSTANT
177 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
178 %token <n64> INT64CONSTANT UINT64CONSTANT
179 %token <identifier> FIELD_SELECTION
180 %token LEFT_OP RIGHT_OP
181 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
182 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
183 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
185 %token INVARIANT PRECISE
186 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
188 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
189 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
190 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
191 %token PRAGMA_INVARIANT_ALL
194 /* Reserved words that are not actually used in the grammar.
196 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
197 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
198 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
199 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
201 %token SIZEOF CAST NAMESPACE USING
202 %token RESOURCE PATCH
207 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
209 %type <identifier> variable_identifier
210 %type <node> statement
211 %type <node> statement_list
212 %type <node> simple_statement
213 %type <n> precision_qualifier
214 %type <type_qualifier> type_qualifier
215 %type <type_qualifier> auxiliary_storage_qualifier
216 %type <type_qualifier> storage_qualifier
217 %type <type_qualifier> interpolation_qualifier
218 %type <type_qualifier> layout_qualifier
219 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
220 %type <type_qualifier> interface_block_layout_qualifier
221 %type <type_qualifier> memory_qualifier
222 %type <type_qualifier> subroutine_qualifier
223 %type <subroutine_list> subroutine_type_list
224 %type <type_qualifier> interface_qualifier
225 %type <type_specifier> type_specifier
226 %type <type_specifier> type_specifier_nonarray
227 %type <array_specifier> array_specifier
228 %type <identifier> basic_type_specifier_nonarray
229 %type <fully_specified_type> fully_specified_type
230 %type <function> function_prototype
231 %type <function> function_header
232 %type <function> function_header_with_parameters
233 %type <function> function_declarator
234 %type <parameter_declarator> parameter_declarator
235 %type <parameter_declarator> parameter_declaration
236 %type <type_qualifier> parameter_qualifier
237 %type <type_qualifier> parameter_direction_qualifier
238 %type <type_specifier> parameter_type_specifier
239 %type <function_definition> function_definition
240 %type <compound_statement> compound_statement_no_new_scope
241 %type <compound_statement> compound_statement
242 %type <node> statement_no_new_scope
243 %type <node> expression_statement
244 %type <expression> expression
245 %type <expression> primary_expression
246 %type <expression> assignment_expression
247 %type <expression> conditional_expression
248 %type <expression> logical_or_expression
249 %type <expression> logical_xor_expression
250 %type <expression> logical_and_expression
251 %type <expression> inclusive_or_expression
252 %type <expression> exclusive_or_expression
253 %type <expression> and_expression
254 %type <expression> equality_expression
255 %type <expression> relational_expression
256 %type <expression> shift_expression
257 %type <expression> additive_expression
258 %type <expression> multiplicative_expression
259 %type <expression> unary_expression
260 %type <expression> constant_expression
261 %type <expression> integer_expression
262 %type <expression> postfix_expression
263 %type <expression> function_call_header_with_parameters
264 %type <expression> function_call_header_no_parameters
265 %type <expression> function_call_header
266 %type <expression> function_call_generic
267 %type <expression> function_call_or_method
268 %type <expression> function_call
269 %type <n> assignment_operator
270 %type <n> unary_operator
271 %type <expression> function_identifier
272 %type <node> external_declaration
273 %type <declarator_list> init_declarator_list
274 %type <declarator_list> single_declaration
275 %type <expression> initializer
276 %type <expression> initializer_list
277 %type <node> declaration
278 %type <node> declaration_statement
279 %type <node> jump_statement
280 %type <node> interface_block
281 %type <interface_block> basic_interface_block
282 %type <struct_specifier> struct_specifier
283 %type <declarator_list> struct_declaration_list
284 %type <declarator_list> struct_declaration
285 %type <declaration> struct_declarator
286 %type <declaration> struct_declarator_list
287 %type <declarator_list> member_list
288 %type <declarator_list> member_declaration
289 %type <node> selection_statement
290 %type <selection_rest_statement> selection_rest_statement
291 %type <node> switch_statement
292 %type <switch_body> switch_body
293 %type <case_label_list> case_label_list
294 %type <case_label> case_label
295 %type <case_statement> case_statement
296 %type <case_statement_list> case_statement_list
297 %type <node> iteration_statement
298 %type <node> condition
299 %type <node> conditionopt
300 %type <node> for_init_statement
301 %type <for_rest_statement> for_rest_statement
302 %type <node> layout_defaults
303 %type <type_qualifier> layout_uniform_defaults
304 %type <type_qualifier> layout_buffer_defaults
305 %type <type_qualifier> layout_in_defaults
306 %type <type_qualifier> layout_out_defaults
312 version_statement extension_statement_list
314 _mesa_glsl_initialize_types(state);
316 external_declaration_list
318 delete state->symbols;
319 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
320 if (state->es_shader) {
321 if (state->stage == MESA_SHADER_FRAGMENT) {
322 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
324 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
325 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
327 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
328 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
329 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
330 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
332 _mesa_glsl_initialize_types(state);
337 /* blank - no #version specified: defaults are already set */
338 | VERSION_TOK INTCONSTANT EOL
340 state->process_version_directive(&@2, $2, NULL);
345 | VERSION_TOK INTCONSTANT any_identifier EOL
347 state->process_version_directive(&@2, $2, $3);
356 | PRAGMA_DEBUG_OFF EOL
357 | PRAGMA_OPTIMIZE_ON EOL
358 | PRAGMA_OPTIMIZE_OFF EOL
359 | PRAGMA_INVARIANT_ALL EOL
361 /* Pragma invariant(all) cannot be used in a fragment shader.
363 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
365 * "It is an error to use this pragma in a fragment shader."
367 if (state->is_version(120, 300) &&
368 state->stage == MESA_SHADER_FRAGMENT) {
369 _mesa_glsl_error(& @1, state,
370 "pragma `invariant(all)' cannot be used "
371 "in a fragment shader.");
372 } else if (!state->is_version(120, 100)) {
373 _mesa_glsl_warning(& @1, state,
374 "pragma `invariant(all)' not supported in %s "
375 "(GLSL ES 1.00 or GLSL 1.20 required)",
376 state->get_version_string());
378 state->all_invariant = true;
383 extension_statement_list:
385 | extension_statement_list extension_statement
395 EXTENSION any_identifier COLON any_identifier EOL
397 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
403 external_declaration_list:
406 /* FINISHME: The NULL test is required because pragmas are set to
407 * FINISHME: NULL. (See production rule for external_declaration.)
410 state->translation_unit.push_tail(& $1->link);
412 | external_declaration_list external_declaration
414 /* FINISHME: The NULL test is required because pragmas are set to
415 * FINISHME: NULL. (See production rule for external_declaration.)
418 state->translation_unit.push_tail(& $2->link);
420 | external_declaration_list extension_statement {
421 if (!state->allow_extension_directive_midshader) {
422 _mesa_glsl_error(& @2, state,
423 "#extension directive is not allowed "
424 "in the middle of a shader");
438 void *ctx = state->linalloc;
439 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
440 $$->set_location(@1);
441 $$->primary_expression.identifier = $1;
445 void *ctx = state->linalloc;
446 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
447 $$->set_location(@1);
448 $$->primary_expression.int_constant = $1;
452 void *ctx = state->linalloc;
453 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
454 $$->set_location(@1);
455 $$->primary_expression.uint_constant = $1;
459 void *ctx = state->linalloc;
460 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
461 $$->set_location(@1);
462 $$->primary_expression.int64_constant = $1;
466 void *ctx = state->linalloc;
467 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
468 $$->set_location(@1);
469 $$->primary_expression.uint64_constant = $1;
473 void *ctx = state->linalloc;
474 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
475 $$->set_location(@1);
476 $$->primary_expression.float_constant = $1;
480 void *ctx = state->linalloc;
481 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
482 $$->set_location(@1);
483 $$->primary_expression.double_constant = $1;
487 void *ctx = state->linalloc;
488 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
489 $$->set_location(@1);
490 $$->primary_expression.bool_constant = $1;
500 | postfix_expression '[' integer_expression ']'
502 void *ctx = state->linalloc;
503 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
504 $$->set_location_range(@1, @4);
510 | postfix_expression DOT_TOK FIELD_SELECTION
512 void *ctx = state->linalloc;
513 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
514 $$->set_location_range(@1, @3);
515 $$->primary_expression.identifier = $3;
517 | postfix_expression INC_OP
519 void *ctx = state->linalloc;
520 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
521 $$->set_location_range(@1, @2);
523 | postfix_expression DEC_OP
525 void *ctx = state->linalloc;
526 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
527 $$->set_location_range(@1, @2);
536 function_call_or_method
539 function_call_or_method:
540 function_call_generic
543 function_call_generic:
544 function_call_header_with_parameters ')'
545 | function_call_header_no_parameters ')'
548 function_call_header_no_parameters:
549 function_call_header VOID_TOK
550 | function_call_header
553 function_call_header_with_parameters:
554 function_call_header assignment_expression
557 $$->set_location(@1);
558 $$->expressions.push_tail(& $2->link);
560 | function_call_header_with_parameters ',' assignment_expression
563 $$->set_location(@1);
564 $$->expressions.push_tail(& $3->link);
568 // Grammar Note: Constructors look like functions, but lexical
569 // analysis recognized most of them as keywords. They are now
570 // recognized through "type_specifier".
571 function_call_header:
572 function_identifier '('
578 void *ctx = state->linalloc;
579 $$ = new(ctx) ast_function_expression($1);
580 $$->set_location(@1);
584 void *ctx = state->linalloc;
585 $$ = new(ctx) ast_function_expression($1);
586 $$->set_location(@1);
590 // Grammar Note: Constructors look like methods, but lexical
591 // analysis recognized most of them as keywords. They are now
592 // recognized through "type_specifier".
594 // Grammar Note: No traditional style type casts.
597 | INC_OP unary_expression
599 void *ctx = state->linalloc;
600 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
601 $$->set_location(@1);
603 | DEC_OP unary_expression
605 void *ctx = state->linalloc;
606 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
607 $$->set_location(@1);
609 | unary_operator unary_expression
611 void *ctx = state->linalloc;
612 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
613 $$->set_location_range(@1, @2);
617 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
619 '+' { $$ = ast_plus; }
620 | '-' { $$ = ast_neg; }
621 | '!' { $$ = ast_logic_not; }
622 | '~' { $$ = ast_bit_not; }
625 multiplicative_expression:
627 | multiplicative_expression '*' unary_expression
629 void *ctx = state->linalloc;
630 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
631 $$->set_location_range(@1, @3);
633 | multiplicative_expression '/' unary_expression
635 void *ctx = state->linalloc;
636 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
637 $$->set_location_range(@1, @3);
639 | multiplicative_expression '%' unary_expression
641 void *ctx = state->linalloc;
642 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
643 $$->set_location_range(@1, @3);
648 multiplicative_expression
649 | additive_expression '+' multiplicative_expression
651 void *ctx = state->linalloc;
652 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
653 $$->set_location_range(@1, @3);
655 | additive_expression '-' multiplicative_expression
657 void *ctx = state->linalloc;
658 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
659 $$->set_location_range(@1, @3);
665 | shift_expression LEFT_OP additive_expression
667 void *ctx = state->linalloc;
668 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
669 $$->set_location_range(@1, @3);
671 | shift_expression RIGHT_OP additive_expression
673 void *ctx = state->linalloc;
674 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
675 $$->set_location_range(@1, @3);
679 relational_expression:
681 | relational_expression '<' shift_expression
683 void *ctx = state->linalloc;
684 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
685 $$->set_location_range(@1, @3);
687 | relational_expression '>' shift_expression
689 void *ctx = state->linalloc;
690 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
691 $$->set_location_range(@1, @3);
693 | relational_expression LE_OP shift_expression
695 void *ctx = state->linalloc;
696 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
697 $$->set_location_range(@1, @3);
699 | relational_expression GE_OP shift_expression
701 void *ctx = state->linalloc;
702 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
703 $$->set_location_range(@1, @3);
708 relational_expression
709 | equality_expression EQ_OP relational_expression
711 void *ctx = state->linalloc;
712 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
713 $$->set_location_range(@1, @3);
715 | equality_expression NE_OP relational_expression
717 void *ctx = state->linalloc;
718 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
719 $$->set_location_range(@1, @3);
725 | and_expression '&' equality_expression
727 void *ctx = state->linalloc;
728 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
729 $$->set_location_range(@1, @3);
733 exclusive_or_expression:
735 | exclusive_or_expression '^' and_expression
737 void *ctx = state->linalloc;
738 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
739 $$->set_location_range(@1, @3);
743 inclusive_or_expression:
744 exclusive_or_expression
745 | inclusive_or_expression '|' exclusive_or_expression
747 void *ctx = state->linalloc;
748 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
749 $$->set_location_range(@1, @3);
753 logical_and_expression:
754 inclusive_or_expression
755 | logical_and_expression AND_OP inclusive_or_expression
757 void *ctx = state->linalloc;
758 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
759 $$->set_location_range(@1, @3);
763 logical_xor_expression:
764 logical_and_expression
765 | logical_xor_expression XOR_OP logical_and_expression
767 void *ctx = state->linalloc;
768 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
769 $$->set_location_range(@1, @3);
773 logical_or_expression:
774 logical_xor_expression
775 | logical_or_expression OR_OP logical_xor_expression
777 void *ctx = state->linalloc;
778 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
779 $$->set_location_range(@1, @3);
783 conditional_expression:
784 logical_or_expression
785 | logical_or_expression '?' expression ':' assignment_expression
787 void *ctx = state->linalloc;
788 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
789 $$->set_location_range(@1, @5);
793 assignment_expression:
794 conditional_expression
795 | unary_expression assignment_operator assignment_expression
797 void *ctx = state->linalloc;
798 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
799 $$->set_location_range(@1, @3);
804 '=' { $$ = ast_assign; }
805 | MUL_ASSIGN { $$ = ast_mul_assign; }
806 | DIV_ASSIGN { $$ = ast_div_assign; }
807 | MOD_ASSIGN { $$ = ast_mod_assign; }
808 | ADD_ASSIGN { $$ = ast_add_assign; }
809 | SUB_ASSIGN { $$ = ast_sub_assign; }
810 | LEFT_ASSIGN { $$ = ast_ls_assign; }
811 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
812 | AND_ASSIGN { $$ = ast_and_assign; }
813 | XOR_ASSIGN { $$ = ast_xor_assign; }
814 | OR_ASSIGN { $$ = ast_or_assign; }
818 assignment_expression
822 | expression ',' assignment_expression
824 void *ctx = state->linalloc;
825 if ($1->oper != ast_sequence) {
826 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
827 $$->set_location_range(@1, @3);
828 $$->expressions.push_tail(& $1->link);
833 $$->expressions.push_tail(& $3->link);
838 conditional_expression
842 function_prototype ';'
844 state->symbols->pop_scope();
847 | init_declarator_list ';'
851 | PRECISION precision_qualifier type_specifier ';'
853 $3->default_precision = $2;
858 ast_interface_block *block = (ast_interface_block *) $1;
859 if (block->layout.has_layout() || block->layout.has_memory()) {
860 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
864 block->layout = block->default_layout;
865 if (!block->layout.push_to_global(& @1, state)) {
873 function_declarator ')'
878 | function_header_with_parameters
881 function_header_with_parameters:
882 function_header parameter_declaration
885 $$->parameters.push_tail(& $2->link);
887 | function_header_with_parameters ',' parameter_declaration
890 $$->parameters.push_tail(& $3->link);
895 fully_specified_type variable_identifier '('
897 void *ctx = state->linalloc;
898 $$ = new(ctx) ast_function();
899 $$->set_location(@2);
900 $$->return_type = $1;
903 if ($1->qualifier.flags.q.subroutine) {
904 /* add type for IDENTIFIER search */
905 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
907 state->symbols->add_function(new(state) ir_function($2));
908 state->symbols->push_scope();
912 parameter_declarator:
913 type_specifier any_identifier
915 void *ctx = state->linalloc;
916 $$ = new(ctx) ast_parameter_declarator();
917 $$->set_location_range(@1, @2);
918 $$->type = new(ctx) ast_fully_specified_type();
919 $$->type->set_location(@1);
920 $$->type->specifier = $1;
922 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
924 | type_specifier any_identifier array_specifier
926 void *ctx = state->linalloc;
927 $$ = new(ctx) ast_parameter_declarator();
928 $$->set_location_range(@1, @3);
929 $$->type = new(ctx) ast_fully_specified_type();
930 $$->type->set_location(@1);
931 $$->type->specifier = $1;
933 $$->array_specifier = $3;
934 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
938 parameter_declaration:
939 parameter_qualifier parameter_declarator
942 $$->type->qualifier = $1;
943 if (!$$->type->qualifier.push_to_global(& @1, state)) {
947 | parameter_qualifier parameter_type_specifier
949 void *ctx = state->linalloc;
950 $$ = new(ctx) ast_parameter_declarator();
951 $$->set_location(@2);
952 $$->type = new(ctx) ast_fully_specified_type();
953 $$->type->set_location_range(@1, @2);
954 $$->type->qualifier = $1;
955 if (!$$->type->qualifier.push_to_global(& @1, state)) {
958 $$->type->specifier = $2;
965 memset(& $$, 0, sizeof($$));
967 | CONST_TOK parameter_qualifier
969 if ($2.flags.q.constant)
970 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
973 $$.flags.q.constant = 1;
975 | PRECISE parameter_qualifier
977 if ($2.flags.q.precise)
978 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
981 $$.flags.q.precise = 1;
983 | parameter_direction_qualifier parameter_qualifier
985 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
986 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
988 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
989 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
993 $$.merge_qualifier(&@1, state, $2, false);
995 | precision_qualifier parameter_qualifier
997 if ($2.precision != ast_precision_none)
998 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1000 if (!state->has_420pack_or_es31() &&
1002 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1007 | memory_qualifier parameter_qualifier
1010 $$.merge_qualifier(&@1, state, $2, false);
1013 parameter_direction_qualifier:
1016 memset(& $$, 0, sizeof($$));
1021 memset(& $$, 0, sizeof($$));
1026 memset(& $$, 0, sizeof($$));
1032 parameter_type_specifier:
1036 init_declarator_list:
1038 | init_declarator_list ',' any_identifier
1040 void *ctx = state->linalloc;
1041 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1042 decl->set_location(@3);
1045 $$->declarations.push_tail(&decl->link);
1046 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1048 | init_declarator_list ',' any_identifier array_specifier
1050 void *ctx = state->linalloc;
1051 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1052 decl->set_location_range(@3, @4);
1055 $$->declarations.push_tail(&decl->link);
1056 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1058 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1060 void *ctx = state->linalloc;
1061 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1062 decl->set_location_range(@3, @4);
1065 $$->declarations.push_tail(&decl->link);
1066 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1068 | init_declarator_list ',' any_identifier '=' initializer
1070 void *ctx = state->linalloc;
1071 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1072 decl->set_location(@3);
1075 $$->declarations.push_tail(&decl->link);
1076 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1080 // Grammar Note: No 'enum', or 'typedef'.
1082 fully_specified_type
1084 void *ctx = state->linalloc;
1085 /* Empty declaration list is valid. */
1086 $$ = new(ctx) ast_declarator_list($1);
1087 $$->set_location(@1);
1089 | fully_specified_type any_identifier
1091 void *ctx = state->linalloc;
1092 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1093 decl->set_location(@2);
1095 $$ = new(ctx) ast_declarator_list($1);
1096 $$->set_location_range(@1, @2);
1097 $$->declarations.push_tail(&decl->link);
1098 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1100 | fully_specified_type any_identifier array_specifier
1102 void *ctx = state->linalloc;
1103 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1104 decl->set_location_range(@2, @3);
1106 $$ = new(ctx) ast_declarator_list($1);
1107 $$->set_location_range(@1, @3);
1108 $$->declarations.push_tail(&decl->link);
1109 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1111 | fully_specified_type any_identifier array_specifier '=' initializer
1113 void *ctx = state->linalloc;
1114 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1115 decl->set_location_range(@2, @3);
1117 $$ = new(ctx) ast_declarator_list($1);
1118 $$->set_location_range(@1, @3);
1119 $$->declarations.push_tail(&decl->link);
1120 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1122 | fully_specified_type any_identifier '=' initializer
1124 void *ctx = state->linalloc;
1125 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1126 decl->set_location(@2);
1128 $$ = new(ctx) ast_declarator_list($1);
1129 $$->set_location_range(@1, @2);
1130 $$->declarations.push_tail(&decl->link);
1131 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1133 | INVARIANT variable_identifier
1135 void *ctx = state->linalloc;
1136 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1137 decl->set_location(@2);
1139 $$ = new(ctx) ast_declarator_list(NULL);
1140 $$->set_location_range(@1, @2);
1141 $$->invariant = true;
1143 $$->declarations.push_tail(&decl->link);
1145 | PRECISE variable_identifier
1147 void *ctx = state->linalloc;
1148 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1149 decl->set_location(@2);
1151 $$ = new(ctx) ast_declarator_list(NULL);
1152 $$->set_location_range(@1, @2);
1155 $$->declarations.push_tail(&decl->link);
1159 fully_specified_type:
1162 void *ctx = state->linalloc;
1163 $$ = new(ctx) ast_fully_specified_type();
1164 $$->set_location(@1);
1167 | type_qualifier type_specifier
1169 void *ctx = state->linalloc;
1170 $$ = new(ctx) ast_fully_specified_type();
1171 $$->set_location_range(@1, @2);
1173 if (!$$->qualifier.push_to_global(& @1, state)) {
1177 if ($$->specifier->structure != NULL &&
1178 $$->specifier->structure->is_declaration) {
1179 $$->specifier->structure->layout = &$$->qualifier;
1185 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1191 layout_qualifier_id_list:
1193 | layout_qualifier_id_list ',' layout_qualifier_id
1196 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1202 layout_qualifier_id:
1205 memset(& $$, 0, sizeof($$));
1207 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1208 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1209 state->is_version(150, 0))) {
1210 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1211 $$.flags.q.origin_upper_left = 1;
1212 } else if (match_layout_qualifier($1, "pixel_center_integer",
1214 $$.flags.q.pixel_center_integer = 1;
1217 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1218 _mesa_glsl_warning(& @1, state,
1219 "GL_ARB_fragment_coord_conventions layout "
1220 "identifier `%s' used", $1);
1224 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1226 (state->AMD_conservative_depth_enable ||
1227 state->ARB_conservative_depth_enable ||
1228 state->is_version(420, 0))) {
1229 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1230 $$.flags.q.depth_type = 1;
1231 $$.depth_type = ast_depth_any;
1232 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1233 $$.flags.q.depth_type = 1;
1234 $$.depth_type = ast_depth_greater;
1235 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1236 $$.flags.q.depth_type = 1;
1237 $$.depth_type = ast_depth_less;
1238 } else if (match_layout_qualifier($1, "depth_unchanged",
1240 $$.flags.q.depth_type = 1;
1241 $$.depth_type = ast_depth_unchanged;
1244 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1245 _mesa_glsl_warning(& @1, state,
1246 "GL_AMD_conservative_depth "
1247 "layout qualifier `%s' is used", $1);
1249 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1250 _mesa_glsl_warning(& @1, state,
1251 "GL_ARB_conservative_depth "
1252 "layout qualifier `%s' is used", $1);
1256 /* See also interface_block_layout_qualifier. */
1257 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1258 if (match_layout_qualifier($1, "std140", state) == 0) {
1259 $$.flags.q.std140 = 1;
1260 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1261 $$.flags.q.shared = 1;
1262 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1263 $$.flags.q.std430 = 1;
1264 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1265 $$.flags.q.column_major = 1;
1266 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1267 * below in the interface_block_layout_qualifier rule.
1269 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1272 * Also, this takes care of alternate capitalizations of
1273 * "row_major" (which is necessary because layout qualifiers
1274 * are case-insensitive in desktop GLSL).
1276 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1277 $$.flags.q.row_major = 1;
1278 /* "packed" is a reserved word in GLSL, and its token is
1279 * parsed below in the interface_block_layout_qualifier rule.
1280 * However, we must take care of alternate capitalizations of
1281 * "packed", because layout qualifiers are case-insensitive
1284 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1285 $$.flags.q.packed = 1;
1288 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1289 _mesa_glsl_warning(& @1, state,
1290 "#version 140 / GL_ARB_uniform_buffer_object "
1291 "layout qualifier `%s' is used", $1);
1295 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1297 static const struct {
1301 { "points", GL_POINTS },
1302 { "lines", GL_LINES },
1303 { "lines_adjacency", GL_LINES_ADJACENCY },
1304 { "line_strip", GL_LINE_STRIP },
1305 { "triangles", GL_TRIANGLES },
1306 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1307 { "triangle_strip", GL_TRIANGLE_STRIP },
1309 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1310 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1311 $$.flags.q.prim_type = 1;
1312 $$.prim_type = map[i].e;
1317 if ($$.flags.i && !state->has_geometry_shader() &&
1318 !state->has_tessellation_shader()) {
1319 _mesa_glsl_error(& @1, state, "#version 150 layout "
1320 "qualifier `%s' used", $1);
1324 /* Layout qualifiers for ARB_shader_image_load_store. */
1325 if (state->has_shader_image_load_store()) {
1327 static const struct {
1330 glsl_base_type base_type;
1331 /** Minimum desktop GLSL version required for the image
1332 * format. Use 130 if already present in the original
1335 unsigned required_glsl;
1336 /** Minimum GLSL ES version required for the image format. */
1337 unsigned required_essl;
1338 /* NV_image_formats */
1339 bool nv_image_formats;
1341 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1342 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1343 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1344 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1345 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1346 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1347 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1348 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1349 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1350 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1351 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1352 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1353 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1354 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1355 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1356 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1357 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1358 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1359 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1360 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1361 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1362 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1363 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1364 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1365 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1366 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1367 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
1368 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1369 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1370 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
1371 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1372 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
1373 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1374 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1375 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1376 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1377 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1378 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1379 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1382 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1383 if ((state->is_version(map[i].required_glsl,
1384 map[i].required_essl) ||
1385 (state->NV_image_formats_enable &&
1386 map[i].nv_image_formats)) &&
1387 match_layout_qualifier($1, map[i].name, state) == 0) {
1388 $$.flags.q.explicit_image_format = 1;
1389 $$.image_format = map[i].format;
1390 $$.image_base_type = map[i].base_type;
1398 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1399 /* From section 4.4.1.3 of the GLSL 4.50 specification
1400 * (Fragment Shader Inputs):
1402 * "Fragment shaders also allow the following layout
1403 * qualifier on in only (not with variable declarations)
1404 * layout-qualifier-id
1405 * early_fragment_tests
1408 if (state->stage != MESA_SHADER_FRAGMENT) {
1409 _mesa_glsl_error(& @1, state,
1410 "early_fragment_tests layout qualifier only "
1411 "valid in fragment shaders");
1414 $$.flags.q.early_fragment_tests = 1;
1417 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1418 if (state->stage != MESA_SHADER_FRAGMENT) {
1419 _mesa_glsl_error(& @1, state,
1420 "inner_coverage layout qualifier only "
1421 "valid in fragment shaders");
1424 if (state->INTEL_conservative_rasterization_enable) {
1425 $$.flags.q.inner_coverage = 1;
1427 _mesa_glsl_error(& @1, state,
1428 "inner_coverage layout qualifier present, "
1429 "but the INTEL_conservative_rasterization extension "
1434 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1435 if (state->stage != MESA_SHADER_FRAGMENT) {
1436 _mesa_glsl_error(& @1, state,
1437 "post_depth_coverage layout qualifier only "
1438 "valid in fragment shaders");
1441 if (state->ARB_post_depth_coverage_enable ||
1442 state->INTEL_conservative_rasterization_enable) {
1443 $$.flags.q.post_depth_coverage = 1;
1445 _mesa_glsl_error(& @1, state,
1446 "post_depth_coverage layout qualifier present, "
1447 "but the GL_ARB_post_depth_coverage extension "
1452 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1453 _mesa_glsl_error(& @1, state,
1454 "post_depth_coverage & inner_coverage layout qualifiers "
1455 "are mutually exclusive");
1459 /* Layout qualifiers for tessellation evaluation shaders. */
1461 static const struct {
1465 /* triangles already parsed by gs-specific code */
1466 { "quads", GL_QUADS },
1467 { "isolines", GL_ISOLINES },
1469 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1470 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1471 $$.flags.q.prim_type = 1;
1472 $$.prim_type = map[i].e;
1477 if ($$.flags.i && !state->has_tessellation_shader()) {
1478 _mesa_glsl_error(& @1, state,
1479 "primitive mode qualifier `%s' requires "
1480 "GLSL 4.00 or ARB_tessellation_shader", $1);
1484 static const struct {
1486 enum gl_tess_spacing e;
1488 { "equal_spacing", TESS_SPACING_EQUAL },
1489 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1490 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1492 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1493 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1494 $$.flags.q.vertex_spacing = 1;
1495 $$.vertex_spacing = map[i].e;
1500 if ($$.flags.i && !state->has_tessellation_shader()) {
1501 _mesa_glsl_error(& @1, state,
1502 "vertex spacing qualifier `%s' requires "
1503 "GLSL 4.00 or ARB_tessellation_shader", $1);
1507 if (match_layout_qualifier($1, "cw", state) == 0) {
1508 $$.flags.q.ordering = 1;
1509 $$.ordering = GL_CW;
1510 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1511 $$.flags.q.ordering = 1;
1512 $$.ordering = GL_CCW;
1515 if ($$.flags.i && !state->has_tessellation_shader()) {
1516 _mesa_glsl_error(& @1, state,
1517 "ordering qualifier `%s' requires "
1518 "GLSL 4.00 or ARB_tessellation_shader", $1);
1522 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1523 $$.flags.q.point_mode = 1;
1524 $$.point_mode = true;
1527 if ($$.flags.i && !state->has_tessellation_shader()) {
1528 _mesa_glsl_error(& @1, state,
1529 "qualifier `point_mode' requires "
1530 "GLSL 4.00 or ARB_tessellation_shader");
1535 static const struct {
1539 { "blend_support_multiply", BLEND_MULTIPLY },
1540 { "blend_support_screen", BLEND_SCREEN },
1541 { "blend_support_overlay", BLEND_OVERLAY },
1542 { "blend_support_darken", BLEND_DARKEN },
1543 { "blend_support_lighten", BLEND_LIGHTEN },
1544 { "blend_support_colordodge", BLEND_COLORDODGE },
1545 { "blend_support_colorburn", BLEND_COLORBURN },
1546 { "blend_support_hardlight", BLEND_HARDLIGHT },
1547 { "blend_support_softlight", BLEND_SOFTLIGHT },
1548 { "blend_support_difference", BLEND_DIFFERENCE },
1549 { "blend_support_exclusion", BLEND_EXCLUSION },
1550 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1551 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1552 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1553 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1554 { "blend_support_all_equations", BLEND_ALL },
1556 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1557 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1558 $$.flags.q.blend_support = 1;
1559 state->fs_blend_support |= map[i].mask;
1565 !state->KHR_blend_equation_advanced_enable &&
1566 !state->is_version(0, 320)) {
1567 _mesa_glsl_error(& @1, state,
1568 "advanced blending layout qualifiers require "
1569 "ESSL 3.20 or KHR_blend_equation_advanced");
1572 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1573 _mesa_glsl_error(& @1, state,
1574 "advanced blending layout qualifiers only "
1575 "valid in fragment shaders");
1579 /* Layout qualifiers for ARB_compute_variable_group_size. */
1581 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1582 $$.flags.q.local_size_variable = 1;
1585 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1586 _mesa_glsl_error(& @1, state,
1587 "qualifier `local_size_variable` requires "
1588 "ARB_compute_variable_group_size");
1593 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1598 | any_identifier '=' constant_expression
1600 memset(& $$, 0, sizeof($$));
1601 void *ctx = state->linalloc;
1603 if ($3->oper != ast_int_constant &&
1604 $3->oper != ast_uint_constant &&
1605 !state->has_enhanced_layouts()) {
1606 _mesa_glsl_error(& @1, state,
1607 "compile-time constant expressions require "
1608 "GLSL 4.40 or ARB_enhanced_layouts");
1611 if (match_layout_qualifier("align", $1, state) == 0) {
1612 if (!state->has_enhanced_layouts()) {
1613 _mesa_glsl_error(& @1, state,
1614 "align qualifier requires "
1615 "GLSL 4.40 or ARB_enhanced_layouts");
1617 $$.flags.q.explicit_align = 1;
1622 if (match_layout_qualifier("location", $1, state) == 0) {
1623 $$.flags.q.explicit_location = 1;
1625 if ($$.flags.q.attribute == 1 &&
1626 state->ARB_explicit_attrib_location_warn) {
1627 _mesa_glsl_warning(& @1, state,
1628 "GL_ARB_explicit_attrib_location layout "
1629 "identifier `%s' used", $1);
1634 if (match_layout_qualifier("component", $1, state) == 0) {
1635 if (!state->has_enhanced_layouts()) {
1636 _mesa_glsl_error(& @1, state,
1637 "component qualifier requires "
1638 "GLSL 4.40 or ARB_enhanced_layouts");
1640 $$.flags.q.explicit_component = 1;
1645 if (match_layout_qualifier("index", $1, state) == 0) {
1646 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1647 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1651 $$.flags.q.explicit_index = 1;
1655 if ((state->has_420pack_or_es31() ||
1656 state->has_atomic_counters() ||
1657 state->has_shader_storage_buffer_objects()) &&
1658 match_layout_qualifier("binding", $1, state) == 0) {
1659 $$.flags.q.explicit_binding = 1;
1663 if ((state->has_atomic_counters() ||
1664 state->has_enhanced_layouts()) &&
1665 match_layout_qualifier("offset", $1, state) == 0) {
1666 $$.flags.q.explicit_offset = 1;
1670 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1671 $$.flags.q.max_vertices = 1;
1672 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1673 if (!state->has_geometry_shader()) {
1674 _mesa_glsl_error(& @3, state,
1675 "#version 150 max_vertices qualifier "
1680 if (state->stage == MESA_SHADER_GEOMETRY) {
1681 if (match_layout_qualifier("stream", $1, state) == 0 &&
1682 state->check_explicit_attrib_stream_allowed(& @3)) {
1683 $$.flags.q.stream = 1;
1684 $$.flags.q.explicit_stream = 1;
1689 if (state->has_enhanced_layouts()) {
1690 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1691 $$.flags.q.xfb_buffer = 1;
1692 $$.flags.q.explicit_xfb_buffer = 1;
1696 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1697 $$.flags.q.explicit_xfb_offset = 1;
1701 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1702 $$.flags.q.xfb_stride = 1;
1703 $$.flags.q.explicit_xfb_stride = 1;
1708 static const char * const local_size_qualifiers[3] = {
1713 for (int i = 0; i < 3; i++) {
1714 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1716 if (!state->has_compute_shader()) {
1717 _mesa_glsl_error(& @3, state,
1718 "%s qualifier requires GLSL 4.30 or "
1719 "GLSL ES 3.10 or ARB_compute_shader",
1720 local_size_qualifiers[i]);
1723 $$.flags.q.local_size |= (1 << i);
1724 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1730 if (match_layout_qualifier("invocations", $1, state) == 0) {
1731 $$.flags.q.invocations = 1;
1732 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1733 if (!state->is_version(400, 320) &&
1734 !state->ARB_gpu_shader5_enable &&
1735 !state->OES_geometry_shader_enable &&
1736 !state->EXT_geometry_shader_enable) {
1737 _mesa_glsl_error(& @3, state,
1738 "GL_ARB_gpu_shader5 invocations "
1739 "qualifier specified", $3);
1743 /* Layout qualifiers for tessellation control shaders. */
1744 if (match_layout_qualifier("vertices", $1, state) == 0) {
1745 $$.flags.q.vertices = 1;
1746 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1747 if (!state->has_tessellation_shader()) {
1748 _mesa_glsl_error(& @1, state,
1749 "vertices qualifier requires GLSL 4.00 or "
1750 "ARB_tessellation_shader");
1754 /* If the identifier didn't match any known layout identifiers,
1758 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1763 | interface_block_layout_qualifier
1766 /* Layout qualifiers for ARB_uniform_buffer_object. */
1767 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1768 _mesa_glsl_error(& @1, state,
1769 "#version 140 / GL_ARB_uniform_buffer_object "
1770 "layout qualifier `%s' is used", $1);
1771 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1772 _mesa_glsl_warning(& @1, state,
1773 "#version 140 / GL_ARB_uniform_buffer_object "
1774 "layout qualifier `%s' is used", $1);
1779 /* This is a separate language rule because we parse these as tokens
1780 * (due to them being reserved keywords) instead of identifiers like
1781 * most qualifiers. See the any_identifier path of
1782 * layout_qualifier_id for the others.
1784 * Note that since layout qualifiers are case-insensitive in desktop
1785 * GLSL, all of these qualifiers need to be handled as identifiers as
1786 * well (by the any_identifier path of layout_qualifier_id).
1788 interface_block_layout_qualifier:
1791 memset(& $$, 0, sizeof($$));
1792 $$.flags.q.row_major = 1;
1796 memset(& $$, 0, sizeof($$));
1797 $$.flags.q.packed = 1;
1801 memset(& $$, 0, sizeof($$));
1802 $$.flags.q.shared = 1;
1806 subroutine_qualifier:
1809 memset(& $$, 0, sizeof($$));
1810 $$.flags.q.subroutine = 1;
1812 | SUBROUTINE '(' subroutine_type_list ')'
1814 memset(& $$, 0, sizeof($$));
1815 $$.flags.q.subroutine_def = 1;
1816 $$.subroutine_list = $3;
1820 subroutine_type_list:
1823 void *ctx = state->linalloc;
1824 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1825 decl->set_location(@1);
1827 $$ = new(ctx) ast_subroutine_list();
1828 $$->declarations.push_tail(&decl->link);
1830 | subroutine_type_list ',' any_identifier
1832 void *ctx = state->linalloc;
1833 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1834 decl->set_location(@3);
1837 $$->declarations.push_tail(&decl->link);
1841 interpolation_qualifier:
1844 memset(& $$, 0, sizeof($$));
1845 $$.flags.q.smooth = 1;
1849 memset(& $$, 0, sizeof($$));
1850 $$.flags.q.flat = 1;
1854 memset(& $$, 0, sizeof($$));
1855 $$.flags.q.noperspective = 1;
1860 /* Single qualifiers */
1863 memset(& $$, 0, sizeof($$));
1864 $$.flags.q.invariant = 1;
1868 memset(& $$, 0, sizeof($$));
1869 $$.flags.q.precise = 1;
1871 | auxiliary_storage_qualifier
1873 | interpolation_qualifier
1876 | subroutine_qualifier
1877 | precision_qualifier
1879 memset(&$$, 0, sizeof($$));
1883 /* Multiple qualifiers:
1884 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1885 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1887 * invariant interpolation auxiliary storage precision ...or...
1888 * layout storage precision
1890 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1891 * side don't contain any that must appear on the left hand side.
1892 * For example, when processing a storage qualifier, we check that there are
1893 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1895 | PRECISE type_qualifier
1897 if ($2.flags.q.precise)
1898 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1901 $$.flags.q.precise = 1;
1903 | INVARIANT type_qualifier
1905 if ($2.flags.q.invariant)
1906 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1908 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1909 _mesa_glsl_error(&@1, state,
1910 "\"invariant\" must come after \"precise\"");
1913 $$.flags.q.invariant = 1;
1915 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1917 * "Only variables output from a shader can be candidates for invariance.
1918 * This includes user-defined output variables and the built-in output
1919 * variables. As only outputs can be declared as invariant, an invariant
1920 * output from one shader stage will still match an input of a subsequent
1921 * stage without the input being declared as invariant."
1923 * On the desktop side, this text first appears in GLSL 4.30.
1925 if (state->is_version(430, 300) && $$.flags.q.in)
1926 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1928 | interpolation_qualifier type_qualifier
1930 /* Section 4.3 of the GLSL 1.40 specification states:
1931 * "...qualified with one of these interpolation qualifiers"
1933 * GLSL 1.30 claims to allow "one or more", but insists that:
1934 * "These interpolation qualifiers may only precede the qualifiers in,
1935 * centroid in, out, or centroid out in a declaration."
1937 * ...which means that e.g. smooth can't precede smooth, so there can be
1938 * only one after all, and the 1.40 text is a clarification, not a change.
1940 if ($2.has_interpolation())
1941 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1943 if (!state->has_420pack_or_es31() &&
1944 ($2.flags.q.precise || $2.flags.q.invariant)) {
1945 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1946 "after \"precise\" or \"invariant\"");
1950 $$.merge_qualifier(&@1, state, $2, false);
1952 | layout_qualifier type_qualifier
1954 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1955 * appear no later than auxiliary storage qualifiers. There is no
1956 * particularly clear spec language mandating this, but in all examples
1957 * the layout qualifier precedes the storage qualifier.
1959 * We allow combinations of layout with interpolation, invariant or
1960 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1961 * There is no clear spec guidance on this either.
1964 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1966 | subroutine_qualifier type_qualifier
1969 $$.merge_qualifier(&@1, state, $2, false);
1971 | auxiliary_storage_qualifier type_qualifier
1973 if ($2.has_auxiliary_storage()) {
1974 _mesa_glsl_error(&@1, state,
1975 "duplicate auxiliary storage qualifier (centroid or sample)");
1978 if (!state->has_420pack_or_es31() &&
1979 ($2.flags.q.precise || $2.flags.q.invariant ||
1980 $2.has_interpolation() || $2.has_layout())) {
1981 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1982 "just before storage qualifiers");
1985 $$.merge_qualifier(&@1, state, $2, false);
1987 | storage_qualifier type_qualifier
1989 /* Section 4.3 of the GLSL 1.20 specification states:
1990 * "Variable declarations may have a storage qualifier specified..."
1991 * 1.30 clarifies this to "may have one storage qualifier".
1993 if ($2.has_storage())
1994 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1996 if (!state->has_420pack_or_es31() &&
1997 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1998 $2.has_layout() || $2.has_auxiliary_storage())) {
1999 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2000 "precise, invariant, interpolation, layout and auxiliary "
2001 "storage qualifiers");
2005 $$.merge_qualifier(&@1, state, $2, false);
2007 | precision_qualifier type_qualifier
2009 if ($2.precision != ast_precision_none)
2010 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2012 if (!(state->has_420pack_or_es31()) &&
2014 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2019 | memory_qualifier type_qualifier
2022 $$.merge_qualifier(&@1, state, $2, false);
2026 auxiliary_storage_qualifier:
2029 memset(& $$, 0, sizeof($$));
2030 $$.flags.q.centroid = 1;
2034 memset(& $$, 0, sizeof($$));
2035 $$.flags.q.sample = 1;
2039 memset(& $$, 0, sizeof($$));
2040 $$.flags.q.patch = 1;
2046 memset(& $$, 0, sizeof($$));
2047 $$.flags.q.constant = 1;
2051 memset(& $$, 0, sizeof($$));
2052 $$.flags.q.attribute = 1;
2056 memset(& $$, 0, sizeof($$));
2057 $$.flags.q.varying = 1;
2061 memset(& $$, 0, sizeof($$));
2066 memset(& $$, 0, sizeof($$));
2069 if (state->stage == MESA_SHADER_GEOMETRY &&
2070 state->has_explicit_attrib_stream()) {
2071 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2074 * "If the block or variable is declared with the stream
2075 * identifier, it is associated with the specified stream;
2076 * otherwise, it is associated with the current default stream."
2078 $$.flags.q.stream = 1;
2079 $$.flags.q.explicit_stream = 0;
2080 $$.stream = state->out_qualifier->stream;
2083 if (state->has_enhanced_layouts()) {
2084 $$.flags.q.xfb_buffer = 1;
2085 $$.flags.q.explicit_xfb_buffer = 0;
2086 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2091 memset(& $$, 0, sizeof($$));
2095 if (!state->has_framebuffer_fetch() ||
2096 !state->is_version(130, 300) ||
2097 state->stage != MESA_SHADER_FRAGMENT)
2098 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2099 "declared as both input and output");
2103 memset(& $$, 0, sizeof($$));
2104 $$.flags.q.uniform = 1;
2108 memset(& $$, 0, sizeof($$));
2109 $$.flags.q.buffer = 1;
2113 memset(& $$, 0, sizeof($$));
2114 $$.flags.q.shared_storage = 1;
2121 memset(& $$, 0, sizeof($$));
2122 $$.flags.q.coherent = 1;
2126 memset(& $$, 0, sizeof($$));
2127 $$.flags.q._volatile = 1;
2131 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2132 memset(& $$, 0, sizeof($$));
2133 $$.flags.q.restrict_flag = 1;
2137 memset(& $$, 0, sizeof($$));
2138 $$.flags.q.read_only = 1;
2142 memset(& $$, 0, sizeof($$));
2143 $$.flags.q.write_only = 1;
2150 void *ctx = state->linalloc;
2151 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2152 ast_unsized_array_dim, NULL,
2154 $$->set_location_range(@1, @2);
2156 | '[' constant_expression ']'
2158 void *ctx = state->linalloc;
2159 $$ = new(ctx) ast_array_specifier(@1, $2);
2160 $$->set_location_range(@1, @3);
2162 | array_specifier '[' ']'
2164 void *ctx = state->linalloc;
2167 if (state->check_arrays_of_arrays_allowed(& @1)) {
2168 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2172 | array_specifier '[' constant_expression ']'
2176 if (state->check_arrays_of_arrays_allowed(& @1)) {
2177 $$->add_dimension($3);
2183 type_specifier_nonarray
2184 | type_specifier_nonarray array_specifier
2187 $$->array_specifier = $2;
2191 type_specifier_nonarray:
2192 basic_type_specifier_nonarray
2194 void *ctx = state->linalloc;
2195 $$ = new(ctx) ast_type_specifier($1);
2196 $$->set_location(@1);
2200 void *ctx = state->linalloc;
2201 $$ = new(ctx) ast_type_specifier($1);
2202 $$->set_location(@1);
2206 void *ctx = state->linalloc;
2207 $$ = new(ctx) ast_type_specifier($1);
2208 $$->set_location(@1);
2212 basic_type_specifier_nonarray:
2213 VOID_TOK { $$ = "void"; }
2214 | FLOAT_TOK { $$ = "float"; }
2215 | DOUBLE_TOK { $$ = "double"; }
2216 | INT_TOK { $$ = "int"; }
2217 | UINT_TOK { $$ = "uint"; }
2218 | BOOL_TOK { $$ = "bool"; }
2219 | VEC2 { $$ = "vec2"; }
2220 | VEC3 { $$ = "vec3"; }
2221 | VEC4 { $$ = "vec4"; }
2222 | BVEC2 { $$ = "bvec2"; }
2223 | BVEC3 { $$ = "bvec3"; }
2224 | BVEC4 { $$ = "bvec4"; }
2225 | IVEC2 { $$ = "ivec2"; }
2226 | IVEC3 { $$ = "ivec3"; }
2227 | IVEC4 { $$ = "ivec4"; }
2228 | UVEC2 { $$ = "uvec2"; }
2229 | UVEC3 { $$ = "uvec3"; }
2230 | UVEC4 { $$ = "uvec4"; }
2231 | DVEC2 { $$ = "dvec2"; }
2232 | DVEC3 { $$ = "dvec3"; }
2233 | DVEC4 { $$ = "dvec4"; }
2234 | MAT2X2 { $$ = "mat2"; }
2235 | MAT2X3 { $$ = "mat2x3"; }
2236 | MAT2X4 { $$ = "mat2x4"; }
2237 | MAT3X2 { $$ = "mat3x2"; }
2238 | MAT3X3 { $$ = "mat3"; }
2239 | MAT3X4 { $$ = "mat3x4"; }
2240 | MAT4X2 { $$ = "mat4x2"; }
2241 | MAT4X3 { $$ = "mat4x3"; }
2242 | MAT4X4 { $$ = "mat4"; }
2243 | DMAT2X2 { $$ = "dmat2"; }
2244 | DMAT2X3 { $$ = "dmat2x3"; }
2245 | DMAT2X4 { $$ = "dmat2x4"; }
2246 | DMAT3X2 { $$ = "dmat3x2"; }
2247 | DMAT3X3 { $$ = "dmat3"; }
2248 | DMAT3X4 { $$ = "dmat3x4"; }
2249 | DMAT4X2 { $$ = "dmat4x2"; }
2250 | DMAT4X3 { $$ = "dmat4x3"; }
2251 | DMAT4X4 { $$ = "dmat4"; }
2252 | SAMPLER1D { $$ = "sampler1D"; }
2253 | SAMPLER2D { $$ = "sampler2D"; }
2254 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2255 | SAMPLER3D { $$ = "sampler3D"; }
2256 | SAMPLERCUBE { $$ = "samplerCube"; }
2257 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2258 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2259 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2260 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2261 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2262 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2263 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2264 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2265 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2266 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2267 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2268 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2269 | ISAMPLER1D { $$ = "isampler1D"; }
2270 | ISAMPLER2D { $$ = "isampler2D"; }
2271 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2272 | ISAMPLER3D { $$ = "isampler3D"; }
2273 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2274 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2275 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2276 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2277 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2278 | USAMPLER1D { $$ = "usampler1D"; }
2279 | USAMPLER2D { $$ = "usampler2D"; }
2280 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2281 | USAMPLER3D { $$ = "usampler3D"; }
2282 | USAMPLERCUBE { $$ = "usamplerCube"; }
2283 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2284 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2285 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2286 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2287 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2288 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2289 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2290 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2291 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2292 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2293 | IMAGE1D { $$ = "image1D"; }
2294 | IMAGE2D { $$ = "image2D"; }
2295 | IMAGE3D { $$ = "image3D"; }
2296 | IMAGE2DRECT { $$ = "image2DRect"; }
2297 | IMAGECUBE { $$ = "imageCube"; }
2298 | IMAGEBUFFER { $$ = "imageBuffer"; }
2299 | IMAGE1DARRAY { $$ = "image1DArray"; }
2300 | IMAGE2DARRAY { $$ = "image2DArray"; }
2301 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2302 | IMAGE2DMS { $$ = "image2DMS"; }
2303 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2304 | IIMAGE1D { $$ = "iimage1D"; }
2305 | IIMAGE2D { $$ = "iimage2D"; }
2306 | IIMAGE3D { $$ = "iimage3D"; }
2307 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2308 | IIMAGECUBE { $$ = "iimageCube"; }
2309 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2310 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2311 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2312 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2313 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2314 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2315 | UIMAGE1D { $$ = "uimage1D"; }
2316 | UIMAGE2D { $$ = "uimage2D"; }
2317 | UIMAGE3D { $$ = "uimage3D"; }
2318 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2319 | UIMAGECUBE { $$ = "uimageCube"; }
2320 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2321 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2322 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2323 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2324 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2325 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2326 | ATOMIC_UINT { $$ = "atomic_uint"; }
2327 | INT64_TOK { $$ = "int64_t"; }
2328 | I64VEC2 { $$ = "i64vec2"; }
2329 | I64VEC3 { $$ = "i64vec3"; }
2330 | I64VEC4 { $$ = "i64vec4"; }
2331 | UINT64_TOK { $$ = "uint64_t"; }
2332 | U64VEC2 { $$ = "u64vec2"; }
2333 | U64VEC3 { $$ = "u64vec3"; }
2334 | U64VEC4 { $$ = "u64vec4"; }
2337 precision_qualifier:
2340 state->check_precision_qualifiers_allowed(&@1);
2341 $$ = ast_precision_high;
2345 state->check_precision_qualifiers_allowed(&@1);
2346 $$ = ast_precision_medium;
2350 state->check_precision_qualifiers_allowed(&@1);
2351 $$ = ast_precision_low;
2356 STRUCT any_identifier '{' struct_declaration_list '}'
2358 void *ctx = state->linalloc;
2359 $$ = new(ctx) ast_struct_specifier(ctx, $2, $4);
2360 $$->set_location_range(@2, @5);
2361 state->symbols->add_type($2, glsl_type::void_type);
2363 | STRUCT '{' struct_declaration_list '}'
2365 void *ctx = state->linalloc;
2366 $$ = new(ctx) ast_struct_specifier(ctx, NULL, $3);
2367 $$->set_location_range(@2, @4);
2371 struct_declaration_list:
2375 $1->link.self_link();
2377 | struct_declaration_list struct_declaration
2380 $$->link.insert_before(& $2->link);
2385 fully_specified_type struct_declarator_list ';'
2387 void *ctx = state->linalloc;
2388 ast_fully_specified_type *const type = $1;
2389 type->set_location(@1);
2391 if (type->qualifier.flags.i != 0)
2392 _mesa_glsl_error(&@1, state,
2393 "only precision qualifiers may be applied to "
2394 "structure members");
2396 $$ = new(ctx) ast_declarator_list(type);
2397 $$->set_location(@2);
2399 $$->declarations.push_degenerate_list_at_head(& $2->link);
2403 struct_declarator_list:
2407 $1->link.self_link();
2409 | struct_declarator_list ',' struct_declarator
2412 $$->link.insert_before(& $3->link);
2419 void *ctx = state->linalloc;
2420 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2421 $$->set_location(@1);
2423 | any_identifier array_specifier
2425 void *ctx = state->linalloc;
2426 $$ = new(ctx) ast_declaration($1, $2, NULL);
2427 $$->set_location_range(@1, @2);
2432 assignment_expression
2433 | '{' initializer_list '}'
2437 | '{' initializer_list ',' '}'
2446 void *ctx = state->linalloc;
2447 $$ = new(ctx) ast_aggregate_initializer();
2448 $$->set_location(@1);
2449 $$->expressions.push_tail(& $1->link);
2451 | initializer_list ',' initializer
2453 $1->expressions.push_tail(& $3->link);
2457 declaration_statement:
2461 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2464 compound_statement { $$ = (ast_node *) $1; }
2469 declaration_statement
2470 | expression_statement
2471 | selection_statement
2473 | iteration_statement
2480 void *ctx = state->linalloc;
2481 $$ = new(ctx) ast_compound_statement(true, NULL);
2482 $$->set_location_range(@1, @2);
2486 state->symbols->push_scope();
2490 void *ctx = state->linalloc;
2491 $$ = new(ctx) ast_compound_statement(true, $3);
2492 $$->set_location_range(@1, @4);
2493 state->symbols->pop_scope();
2497 statement_no_new_scope:
2498 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2502 compound_statement_no_new_scope:
2505 void *ctx = state->linalloc;
2506 $$ = new(ctx) ast_compound_statement(false, NULL);
2507 $$->set_location_range(@1, @2);
2509 | '{' statement_list '}'
2511 void *ctx = state->linalloc;
2512 $$ = new(ctx) ast_compound_statement(false, $2);
2513 $$->set_location_range(@1, @3);
2521 _mesa_glsl_error(& @1, state, "<nil> statement");
2526 $$->link.self_link();
2528 | statement_list statement
2531 _mesa_glsl_error(& @2, state, "<nil> statement");
2535 $$->link.insert_before(& $2->link);
2539 expression_statement:
2542 void *ctx = state->linalloc;
2543 $$ = new(ctx) ast_expression_statement(NULL);
2544 $$->set_location(@1);
2548 void *ctx = state->linalloc;
2549 $$ = new(ctx) ast_expression_statement($1);
2550 $$->set_location(@1);
2554 selection_statement:
2555 IF '(' expression ')' selection_rest_statement
2557 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2559 $$->set_location_range(@1, @5);
2563 selection_rest_statement:
2564 statement ELSE statement
2566 $$.then_statement = $1;
2567 $$.else_statement = $3;
2569 | statement %prec THEN
2571 $$.then_statement = $1;
2572 $$.else_statement = NULL;
2579 $$ = (ast_node *) $1;
2581 | fully_specified_type any_identifier '=' initializer
2583 void *ctx = state->linalloc;
2584 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2585 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2586 decl->set_location_range(@2, @4);
2587 declarator->set_location(@1);
2589 declarator->declarations.push_tail(&decl->link);
2595 * switch_statement grammar is based on the syntax described in the body
2596 * of the GLSL spec, not in it's appendix!!!
2599 SWITCH '(' expression ')' switch_body
2601 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2602 $$->set_location_range(@1, @5);
2609 $$ = new(state->linalloc) ast_switch_body(NULL);
2610 $$->set_location_range(@1, @2);
2612 | '{' case_statement_list '}'
2614 $$ = new(state->linalloc) ast_switch_body($2);
2615 $$->set_location_range(@1, @3);
2622 $$ = new(state->linalloc) ast_case_label($2);
2623 $$->set_location(@2);
2627 $$ = new(state->linalloc) ast_case_label(NULL);
2628 $$->set_location(@2);
2635 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2637 labels->labels.push_tail(& $1->link);
2639 $$->set_location(@1);
2641 | case_label_list case_label
2644 $$->labels.push_tail(& $2->link);
2649 case_label_list statement
2651 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2652 stmts->set_location(@2);
2654 stmts->stmts.push_tail(& $2->link);
2657 | case_statement statement
2660 $$->stmts.push_tail(& $2->link);
2664 case_statement_list:
2667 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2668 cases->set_location(@1);
2670 cases->cases.push_tail(& $1->link);
2673 | case_statement_list case_statement
2676 $$->cases.push_tail(& $2->link);
2680 iteration_statement:
2681 WHILE '(' condition ')' statement_no_new_scope
2683 void *ctx = state->linalloc;
2684 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2685 NULL, $3, NULL, $5);
2686 $$->set_location_range(@1, @4);
2688 | DO statement WHILE '(' expression ')' ';'
2690 void *ctx = state->linalloc;
2691 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2692 NULL, $5, NULL, $2);
2693 $$->set_location_range(@1, @6);
2695 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2697 void *ctx = state->linalloc;
2698 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2699 $3, $4.cond, $4.rest, $6);
2700 $$->set_location_range(@1, @6);
2705 expression_statement
2706 | declaration_statement
2723 | conditionopt ';' expression
2730 // Grammar Note: No 'goto'. Gotos are not supported.
2734 void *ctx = state->linalloc;
2735 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2736 $$->set_location(@1);
2740 void *ctx = state->linalloc;
2741 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2742 $$->set_location(@1);
2746 void *ctx = state->linalloc;
2747 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2748 $$->set_location(@1);
2750 | RETURN expression ';'
2752 void *ctx = state->linalloc;
2753 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2754 $$->set_location_range(@1, @2);
2756 | DISCARD ';' // Fragment shader only.
2758 void *ctx = state->linalloc;
2759 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2760 $$->set_location(@1);
2764 external_declaration:
2765 function_definition { $$ = $1; }
2766 | declaration { $$ = $1; }
2767 | pragma_statement { $$ = NULL; }
2768 | layout_defaults { $$ = $1; }
2771 function_definition:
2772 function_prototype compound_statement_no_new_scope
2774 void *ctx = state->linalloc;
2775 $$ = new(ctx) ast_function_definition();
2776 $$->set_location_range(@1, @2);
2780 state->symbols->pop_scope();
2784 /* layout_qualifieropt is packed into this rule */
2786 basic_interface_block
2790 | layout_qualifier interface_block
2792 ast_interface_block *block = (ast_interface_block *) $2;
2794 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2795 block->layout.has_layout())) {
2803 | memory_qualifier interface_block
2805 ast_interface_block *block = (ast_interface_block *)$2;
2807 if (!block->default_layout.flags.q.buffer) {
2808 _mesa_glsl_error(& @1, state,
2809 "memory qualifiers can only be used in the "
2810 "declaration of shader storage blocks");
2812 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2820 basic_interface_block:
2821 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2823 ast_interface_block *const block = $6;
2825 if ($1.flags.q.uniform) {
2826 block->default_layout = *state->default_uniform_qualifier;
2827 } else if ($1.flags.q.buffer) {
2828 block->default_layout = *state->default_shader_storage_qualifier;
2830 block->block_name = $2;
2831 block->declarations.push_degenerate_list_at_head(& $4->link);
2833 _mesa_ast_process_interface_block(& @1, state, block, $1);
2839 interface_qualifier:
2842 memset(& $$, 0, sizeof($$));
2847 memset(& $$, 0, sizeof($$));
2852 memset(& $$, 0, sizeof($$));
2853 $$.flags.q.uniform = 1;
2857 memset(& $$, 0, sizeof($$));
2858 $$.flags.q.buffer = 1;
2860 | auxiliary_storage_qualifier interface_qualifier
2862 if (!$1.flags.q.patch) {
2863 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2865 if ($2.has_auxiliary_storage()) {
2866 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2869 $$.flags.q.patch = 1;
2876 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2880 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2881 $$->set_location(@1);
2883 | NEW_IDENTIFIER array_specifier
2885 $$ = new(state->linalloc) ast_interface_block($1, $2);
2886 $$->set_location_range(@1, @2);
2894 $1->link.self_link();
2896 | member_declaration member_list
2899 $2->link.insert_before(& $$->link);
2904 fully_specified_type struct_declarator_list ';'
2906 void *ctx = state->linalloc;
2907 ast_fully_specified_type *type = $1;
2908 type->set_location(@1);
2910 if (type->qualifier.flags.q.attribute) {
2911 _mesa_glsl_error(& @1, state,
2912 "keyword 'attribute' cannot be used with "
2913 "interface block member");
2914 } else if (type->qualifier.flags.q.varying) {
2915 _mesa_glsl_error(& @1, state,
2916 "keyword 'varying' cannot be used with "
2917 "interface block member");
2920 $$ = new(ctx) ast_declarator_list(type);
2921 $$->set_location(@2);
2923 $$->declarations.push_degenerate_list_at_head(& $2->link);
2927 layout_uniform_defaults:
2928 layout_qualifier layout_uniform_defaults
2931 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2935 | layout_qualifier UNIFORM ';'
2938 layout_buffer_defaults:
2939 layout_qualifier layout_buffer_defaults
2942 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2946 | layout_qualifier BUFFER ';'
2950 layout_qualifier layout_in_defaults
2953 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2956 if (!$$.validate_in_qualifier(& @1, state)) {
2960 | layout_qualifier IN_TOK ';'
2962 if (!$1.validate_in_qualifier(& @1, state)) {
2968 layout_out_defaults:
2969 layout_qualifier layout_out_defaults
2972 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2975 if (!$$.validate_out_qualifier(& @1, state)) {
2979 | layout_qualifier OUT_TOK ';'
2981 if (!$1.validate_out_qualifier(& @1, state)) {
2988 layout_uniform_defaults
2991 if (!state->default_uniform_qualifier->
2992 merge_qualifier(& @1, state, $1, false)) {
2995 if (!state->default_uniform_qualifier->
2996 push_to_global(& @1, state)) {
3000 | layout_buffer_defaults
3003 if (!state->default_shader_storage_qualifier->
3004 merge_qualifier(& @1, state, $1, false)) {
3007 if (!state->default_shader_storage_qualifier->
3008 push_to_global(& @1, state)) {
3012 /* From the GLSL 4.50 spec, section 4.4.5:
3014 * "It is a compile-time error to specify the binding identifier for
3015 * the global scope or for block member declarations."
3017 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
3018 _mesa_glsl_error(& @1, state,
3019 "binding qualifier cannot be set for default layout");
3022 | layout_in_defaults
3025 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
3028 if (!state->in_qualifier->push_to_global(& @1, state)) {
3032 | layout_out_defaults
3035 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
3038 if (!state->out_qualifier->push_to_global(& @1, state)) {