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}
102 const char *identifier;
104 struct ast_type_qualifier type_qualifier;
107 ast_type_specifier *type_specifier;
108 ast_array_specifier *array_specifier;
109 ast_fully_specified_type *fully_specified_type;
110 ast_function *function;
111 ast_parameter_declarator *parameter_declarator;
112 ast_function_definition *function_definition;
113 ast_compound_statement *compound_statement;
114 ast_expression *expression;
115 ast_declarator_list *declarator_list;
116 ast_struct_specifier *struct_specifier;
117 ast_declaration *declaration;
118 ast_switch_body *switch_body;
119 ast_case_label *case_label;
120 ast_case_label_list *case_label_list;
121 ast_case_statement *case_statement;
122 ast_case_statement_list *case_statement_list;
123 ast_interface_block *interface_block;
124 ast_subroutine_list *subroutine_list;
127 ast_expression *rest;
128 } for_rest_statement;
131 ast_node *then_statement;
132 ast_node *else_statement;
133 } selection_rest_statement;
136 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
137 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
138 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
139 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
140 %token NOPERSPECTIVE FLAT SMOOTH
141 %token MAT2X2 MAT2X3 MAT2X4
142 %token MAT3X2 MAT3X3 MAT3X4
143 %token MAT4X2 MAT4X3 MAT4X4
144 %token DMAT2X2 DMAT2X3 DMAT2X4
145 %token DMAT3X2 DMAT3X3 DMAT3X4
146 %token DMAT4X2 DMAT4X3 DMAT4X4
147 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
148 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
149 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
150 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
151 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
152 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
153 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
154 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
155 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
156 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
157 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
158 %token SAMPLEREXTERNALOES
159 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
160 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
161 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
162 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
163 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
164 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
165 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
166 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
169 %token STRUCT VOID_TOK WHILE
170 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
171 %type <identifier> any_identifier
172 %type <interface_block> instance_name_opt
173 %token <real> FLOATCONSTANT
174 %token <dreal> DOUBLECONSTANT
175 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
176 %token <identifier> FIELD_SELECTION
177 %token LEFT_OP RIGHT_OP
178 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
179 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
180 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
182 %token INVARIANT PRECISE
183 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
185 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
186 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
187 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
188 %token PRAGMA_INVARIANT_ALL
191 /* Reserved words that are not actually used in the grammar.
193 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
194 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
195 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
196 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
198 %token SIZEOF CAST NAMESPACE USING
199 %token RESOURCE PATCH
204 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
206 %type <identifier> variable_identifier
207 %type <node> statement
208 %type <node> statement_list
209 %type <node> simple_statement
210 %type <n> precision_qualifier
211 %type <type_qualifier> type_qualifier
212 %type <type_qualifier> auxiliary_storage_qualifier
213 %type <type_qualifier> storage_qualifier
214 %type <type_qualifier> interpolation_qualifier
215 %type <type_qualifier> layout_qualifier
216 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
217 %type <type_qualifier> interface_block_layout_qualifier
218 %type <type_qualifier> memory_qualifier
219 %type <type_qualifier> subroutine_qualifier
220 %type <subroutine_list> subroutine_type_list
221 %type <type_qualifier> interface_qualifier
222 %type <type_specifier> type_specifier
223 %type <type_specifier> type_specifier_nonarray
224 %type <array_specifier> array_specifier
225 %type <identifier> basic_type_specifier_nonarray
226 %type <fully_specified_type> fully_specified_type
227 %type <function> function_prototype
228 %type <function> function_header
229 %type <function> function_header_with_parameters
230 %type <function> function_declarator
231 %type <parameter_declarator> parameter_declarator
232 %type <parameter_declarator> parameter_declaration
233 %type <type_qualifier> parameter_qualifier
234 %type <type_qualifier> parameter_direction_qualifier
235 %type <type_specifier> parameter_type_specifier
236 %type <function_definition> function_definition
237 %type <compound_statement> compound_statement_no_new_scope
238 %type <compound_statement> compound_statement
239 %type <node> statement_no_new_scope
240 %type <node> expression_statement
241 %type <expression> expression
242 %type <expression> primary_expression
243 %type <expression> assignment_expression
244 %type <expression> conditional_expression
245 %type <expression> logical_or_expression
246 %type <expression> logical_xor_expression
247 %type <expression> logical_and_expression
248 %type <expression> inclusive_or_expression
249 %type <expression> exclusive_or_expression
250 %type <expression> and_expression
251 %type <expression> equality_expression
252 %type <expression> relational_expression
253 %type <expression> shift_expression
254 %type <expression> additive_expression
255 %type <expression> multiplicative_expression
256 %type <expression> unary_expression
257 %type <expression> constant_expression
258 %type <expression> integer_expression
259 %type <expression> postfix_expression
260 %type <expression> function_call_header_with_parameters
261 %type <expression> function_call_header_no_parameters
262 %type <expression> function_call_header
263 %type <expression> function_call_generic
264 %type <expression> function_call_or_method
265 %type <expression> function_call
266 %type <n> assignment_operator
267 %type <n> unary_operator
268 %type <expression> function_identifier
269 %type <node> external_declaration
270 %type <declarator_list> init_declarator_list
271 %type <declarator_list> single_declaration
272 %type <expression> initializer
273 %type <expression> initializer_list
274 %type <node> declaration
275 %type <node> declaration_statement
276 %type <node> jump_statement
277 %type <node> interface_block
278 %type <interface_block> basic_interface_block
279 %type <struct_specifier> struct_specifier
280 %type <declarator_list> struct_declaration_list
281 %type <declarator_list> struct_declaration
282 %type <declaration> struct_declarator
283 %type <declaration> struct_declarator_list
284 %type <declarator_list> member_list
285 %type <declarator_list> member_declaration
286 %type <node> selection_statement
287 %type <selection_rest_statement> selection_rest_statement
288 %type <node> switch_statement
289 %type <switch_body> switch_body
290 %type <case_label_list> case_label_list
291 %type <case_label> case_label
292 %type <case_statement> case_statement
293 %type <case_statement_list> case_statement_list
294 %type <node> iteration_statement
295 %type <node> condition
296 %type <node> conditionopt
297 %type <node> for_init_statement
298 %type <for_rest_statement> for_rest_statement
299 %type <node> layout_defaults
300 %type <type_qualifier> layout_uniform_defaults
301 %type <type_qualifier> layout_buffer_defaults
302 %type <type_qualifier> layout_in_defaults
303 %type <type_qualifier> layout_out_defaults
309 version_statement extension_statement_list
311 _mesa_glsl_initialize_types(state);
313 external_declaration_list
315 delete state->symbols;
316 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
317 if (state->es_shader) {
318 if (state->stage == MESA_SHADER_FRAGMENT) {
319 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
321 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
322 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
324 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
325 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
326 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
327 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
329 _mesa_glsl_initialize_types(state);
334 /* blank - no #version specified: defaults are already set */
335 | VERSION_TOK INTCONSTANT EOL
337 state->process_version_directive(&@2, $2, NULL);
342 | VERSION_TOK INTCONSTANT any_identifier EOL
344 state->process_version_directive(&@2, $2, $3);
353 | PRAGMA_DEBUG_OFF EOL
354 | PRAGMA_OPTIMIZE_ON EOL
355 | PRAGMA_OPTIMIZE_OFF EOL
356 | PRAGMA_INVARIANT_ALL EOL
358 /* Pragma invariant(all) cannot be used in a fragment shader.
360 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
362 * "It is an error to use this pragma in a fragment shader."
364 if (state->is_version(120, 300) &&
365 state->stage == MESA_SHADER_FRAGMENT) {
366 _mesa_glsl_error(& @1, state,
367 "pragma `invariant(all)' cannot be used "
368 "in a fragment shader.");
369 } else if (!state->is_version(120, 100)) {
370 _mesa_glsl_warning(& @1, state,
371 "pragma `invariant(all)' not supported in %s "
372 "(GLSL ES 1.00 or GLSL 1.20 required)",
373 state->get_version_string());
375 state->all_invariant = true;
380 extension_statement_list:
382 | extension_statement_list extension_statement
392 EXTENSION any_identifier COLON any_identifier EOL
394 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
400 external_declaration_list:
403 /* FINISHME: The NULL test is required because pragmas are set to
404 * FINISHME: NULL. (See production rule for external_declaration.)
407 state->translation_unit.push_tail(& $1->link);
409 | external_declaration_list external_declaration
411 /* FINISHME: The NULL test is required because pragmas are set to
412 * FINISHME: NULL. (See production rule for external_declaration.)
415 state->translation_unit.push_tail(& $2->link);
417 | external_declaration_list extension_statement {
418 if (!state->allow_extension_directive_midshader) {
419 _mesa_glsl_error(& @2, state,
420 "#extension directive is not allowed "
421 "in the middle of a shader");
435 void *ctx = state->linalloc;
436 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
437 $$->set_location(@1);
438 $$->primary_expression.identifier = $1;
442 void *ctx = state->linalloc;
443 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
444 $$->set_location(@1);
445 $$->primary_expression.int_constant = $1;
449 void *ctx = state->linalloc;
450 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
451 $$->set_location(@1);
452 $$->primary_expression.uint_constant = $1;
456 void *ctx = state->linalloc;
457 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
458 $$->set_location(@1);
459 $$->primary_expression.float_constant = $1;
463 void *ctx = state->linalloc;
464 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
465 $$->set_location(@1);
466 $$->primary_expression.double_constant = $1;
470 void *ctx = state->linalloc;
471 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
472 $$->set_location(@1);
473 $$->primary_expression.bool_constant = $1;
483 | postfix_expression '[' integer_expression ']'
485 void *ctx = state->linalloc;
486 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
487 $$->set_location_range(@1, @4);
493 | postfix_expression DOT_TOK FIELD_SELECTION
495 void *ctx = state->linalloc;
496 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
497 $$->set_location_range(@1, @3);
498 $$->primary_expression.identifier = $3;
500 | postfix_expression INC_OP
502 void *ctx = state->linalloc;
503 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
504 $$->set_location_range(@1, @2);
506 | postfix_expression DEC_OP
508 void *ctx = state->linalloc;
509 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
510 $$->set_location_range(@1, @2);
519 function_call_or_method
522 function_call_or_method:
523 function_call_generic
526 function_call_generic:
527 function_call_header_with_parameters ')'
528 | function_call_header_no_parameters ')'
531 function_call_header_no_parameters:
532 function_call_header VOID_TOK
533 | function_call_header
536 function_call_header_with_parameters:
537 function_call_header assignment_expression
540 $$->set_location(@1);
541 $$->expressions.push_tail(& $2->link);
543 | function_call_header_with_parameters ',' assignment_expression
546 $$->set_location(@1);
547 $$->expressions.push_tail(& $3->link);
551 // Grammar Note: Constructors look like functions, but lexical
552 // analysis recognized most of them as keywords. They are now
553 // recognized through "type_specifier".
554 function_call_header:
555 function_identifier '('
561 void *ctx = state->linalloc;
562 $$ = new(ctx) ast_function_expression($1);
563 $$->set_location(@1);
567 void *ctx = state->linalloc;
568 $$ = new(ctx) ast_function_expression($1);
569 $$->set_location(@1);
573 // Grammar Note: Constructors look like methods, but lexical
574 // analysis recognized most of them as keywords. They are now
575 // recognized through "type_specifier".
577 // Grammar Note: No traditional style type casts.
580 | INC_OP unary_expression
582 void *ctx = state->linalloc;
583 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
584 $$->set_location(@1);
586 | DEC_OP unary_expression
588 void *ctx = state->linalloc;
589 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
590 $$->set_location(@1);
592 | unary_operator unary_expression
594 void *ctx = state->linalloc;
595 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
596 $$->set_location_range(@1, @2);
600 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
602 '+' { $$ = ast_plus; }
603 | '-' { $$ = ast_neg; }
604 | '!' { $$ = ast_logic_not; }
605 | '~' { $$ = ast_bit_not; }
608 multiplicative_expression:
610 | multiplicative_expression '*' unary_expression
612 void *ctx = state->linalloc;
613 $$ = new(ctx) ast_expression_bin(ast_mul, $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_div, $1, $3);
620 $$->set_location_range(@1, @3);
622 | multiplicative_expression '%' unary_expression
624 void *ctx = state->linalloc;
625 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
626 $$->set_location_range(@1, @3);
631 multiplicative_expression
632 | additive_expression '+' multiplicative_expression
634 void *ctx = state->linalloc;
635 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
636 $$->set_location_range(@1, @3);
638 | additive_expression '-' multiplicative_expression
640 void *ctx = state->linalloc;
641 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
642 $$->set_location_range(@1, @3);
648 | shift_expression LEFT_OP additive_expression
650 void *ctx = state->linalloc;
651 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
652 $$->set_location_range(@1, @3);
654 | shift_expression RIGHT_OP additive_expression
656 void *ctx = state->linalloc;
657 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
658 $$->set_location_range(@1, @3);
662 relational_expression:
664 | relational_expression '<' shift_expression
666 void *ctx = state->linalloc;
667 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
668 $$->set_location_range(@1, @3);
670 | relational_expression '>' shift_expression
672 void *ctx = state->linalloc;
673 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
674 $$->set_location_range(@1, @3);
676 | relational_expression LE_OP shift_expression
678 void *ctx = state->linalloc;
679 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
680 $$->set_location_range(@1, @3);
682 | relational_expression GE_OP shift_expression
684 void *ctx = state->linalloc;
685 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
686 $$->set_location_range(@1, @3);
691 relational_expression
692 | equality_expression EQ_OP relational_expression
694 void *ctx = state->linalloc;
695 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
696 $$->set_location_range(@1, @3);
698 | equality_expression NE_OP relational_expression
700 void *ctx = state->linalloc;
701 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
702 $$->set_location_range(@1, @3);
708 | and_expression '&' equality_expression
710 void *ctx = state->linalloc;
711 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
712 $$->set_location_range(@1, @3);
716 exclusive_or_expression:
718 | exclusive_or_expression '^' and_expression
720 void *ctx = state->linalloc;
721 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
722 $$->set_location_range(@1, @3);
726 inclusive_or_expression:
727 exclusive_or_expression
728 | inclusive_or_expression '|' exclusive_or_expression
730 void *ctx = state->linalloc;
731 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
732 $$->set_location_range(@1, @3);
736 logical_and_expression:
737 inclusive_or_expression
738 | logical_and_expression AND_OP inclusive_or_expression
740 void *ctx = state->linalloc;
741 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
742 $$->set_location_range(@1, @3);
746 logical_xor_expression:
747 logical_and_expression
748 | logical_xor_expression XOR_OP logical_and_expression
750 void *ctx = state->linalloc;
751 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
752 $$->set_location_range(@1, @3);
756 logical_or_expression:
757 logical_xor_expression
758 | logical_or_expression OR_OP logical_xor_expression
760 void *ctx = state->linalloc;
761 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
762 $$->set_location_range(@1, @3);
766 conditional_expression:
767 logical_or_expression
768 | logical_or_expression '?' expression ':' assignment_expression
770 void *ctx = state->linalloc;
771 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
772 $$->set_location_range(@1, @5);
776 assignment_expression:
777 conditional_expression
778 | unary_expression assignment_operator assignment_expression
780 void *ctx = state->linalloc;
781 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
782 $$->set_location_range(@1, @3);
787 '=' { $$ = ast_assign; }
788 | MUL_ASSIGN { $$ = ast_mul_assign; }
789 | DIV_ASSIGN { $$ = ast_div_assign; }
790 | MOD_ASSIGN { $$ = ast_mod_assign; }
791 | ADD_ASSIGN { $$ = ast_add_assign; }
792 | SUB_ASSIGN { $$ = ast_sub_assign; }
793 | LEFT_ASSIGN { $$ = ast_ls_assign; }
794 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
795 | AND_ASSIGN { $$ = ast_and_assign; }
796 | XOR_ASSIGN { $$ = ast_xor_assign; }
797 | OR_ASSIGN { $$ = ast_or_assign; }
801 assignment_expression
805 | expression ',' assignment_expression
807 void *ctx = state->linalloc;
808 if ($1->oper != ast_sequence) {
809 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
810 $$->set_location_range(@1, @3);
811 $$->expressions.push_tail(& $1->link);
816 $$->expressions.push_tail(& $3->link);
821 conditional_expression
825 function_prototype ';'
827 state->symbols->pop_scope();
830 | init_declarator_list ';'
834 | PRECISION precision_qualifier type_specifier ';'
836 $3->default_precision = $2;
841 ast_interface_block *block = (ast_interface_block *) $1;
842 if (block->layout.has_layout() || block->layout.has_memory()) {
843 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
847 block->layout = block->default_layout;
854 function_declarator ')'
859 | function_header_with_parameters
862 function_header_with_parameters:
863 function_header parameter_declaration
866 $$->parameters.push_tail(& $2->link);
868 | function_header_with_parameters ',' parameter_declaration
871 $$->parameters.push_tail(& $3->link);
876 fully_specified_type variable_identifier '('
878 void *ctx = state->linalloc;
879 $$ = new(ctx) ast_function();
880 $$->set_location(@2);
881 $$->return_type = $1;
884 if ($1->qualifier.flags.q.subroutine) {
885 /* add type for IDENTIFIER search */
886 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
888 state->symbols->add_function(new(state) ir_function($2));
889 state->symbols->push_scope();
893 parameter_declarator:
894 type_specifier any_identifier
896 void *ctx = state->linalloc;
897 $$ = new(ctx) ast_parameter_declarator();
898 $$->set_location_range(@1, @2);
899 $$->type = new(ctx) ast_fully_specified_type();
900 $$->type->set_location(@1);
901 $$->type->specifier = $1;
903 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
905 | type_specifier any_identifier array_specifier
907 void *ctx = state->linalloc;
908 $$ = new(ctx) ast_parameter_declarator();
909 $$->set_location_range(@1, @3);
910 $$->type = new(ctx) ast_fully_specified_type();
911 $$->type->set_location(@1);
912 $$->type->specifier = $1;
914 $$->array_specifier = $3;
915 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
919 parameter_declaration:
920 parameter_qualifier parameter_declarator
923 $$->type->qualifier = $1;
925 | parameter_qualifier parameter_type_specifier
927 void *ctx = state->linalloc;
928 $$ = new(ctx) ast_parameter_declarator();
929 $$->set_location(@2);
930 $$->type = new(ctx) ast_fully_specified_type();
931 $$->type->set_location_range(@1, @2);
932 $$->type->qualifier = $1;
933 $$->type->specifier = $2;
940 memset(& $$, 0, sizeof($$));
942 | CONST_TOK parameter_qualifier
944 if ($2.flags.q.constant)
945 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
948 $$.flags.q.constant = 1;
950 | PRECISE parameter_qualifier
952 if ($2.flags.q.precise)
953 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
956 $$.flags.q.precise = 1;
958 | parameter_direction_qualifier parameter_qualifier
960 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
961 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
963 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
964 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
968 $$.merge_qualifier(&@1, state, $2, false);
970 | precision_qualifier parameter_qualifier
972 if ($2.precision != ast_precision_none)
973 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
975 if (!state->has_420pack_or_es31() &&
977 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
982 | memory_qualifier parameter_qualifier
985 $$.merge_qualifier(&@1, state, $2, false);
988 parameter_direction_qualifier:
991 memset(& $$, 0, sizeof($$));
996 memset(& $$, 0, sizeof($$));
1001 memset(& $$, 0, sizeof($$));
1007 parameter_type_specifier:
1011 init_declarator_list:
1013 | init_declarator_list ',' any_identifier
1015 void *ctx = state->linalloc;
1016 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1017 decl->set_location(@3);
1020 $$->declarations.push_tail(&decl->link);
1021 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1023 | init_declarator_list ',' any_identifier array_specifier
1025 void *ctx = state->linalloc;
1026 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1027 decl->set_location_range(@3, @4);
1030 $$->declarations.push_tail(&decl->link);
1031 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1033 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1035 void *ctx = state->linalloc;
1036 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1037 decl->set_location_range(@3, @4);
1040 $$->declarations.push_tail(&decl->link);
1041 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1043 | init_declarator_list ',' any_identifier '=' initializer
1045 void *ctx = state->linalloc;
1046 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1047 decl->set_location(@3);
1050 $$->declarations.push_tail(&decl->link);
1051 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1055 // Grammar Note: No 'enum', or 'typedef'.
1057 fully_specified_type
1059 void *ctx = state->linalloc;
1060 /* Empty declaration list is valid. */
1061 $$ = new(ctx) ast_declarator_list($1);
1062 $$->set_location(@1);
1064 | fully_specified_type any_identifier
1066 void *ctx = state->linalloc;
1067 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1068 decl->set_location(@2);
1070 $$ = new(ctx) ast_declarator_list($1);
1071 $$->set_location_range(@1, @2);
1072 $$->declarations.push_tail(&decl->link);
1073 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1075 | fully_specified_type any_identifier array_specifier
1077 void *ctx = state->linalloc;
1078 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1079 decl->set_location_range(@2, @3);
1081 $$ = new(ctx) ast_declarator_list($1);
1082 $$->set_location_range(@1, @3);
1083 $$->declarations.push_tail(&decl->link);
1084 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1086 | fully_specified_type any_identifier array_specifier '=' initializer
1088 void *ctx = state->linalloc;
1089 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1090 decl->set_location_range(@2, @3);
1092 $$ = new(ctx) ast_declarator_list($1);
1093 $$->set_location_range(@1, @3);
1094 $$->declarations.push_tail(&decl->link);
1095 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1097 | fully_specified_type any_identifier '=' initializer
1099 void *ctx = state->linalloc;
1100 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1101 decl->set_location(@2);
1103 $$ = new(ctx) ast_declarator_list($1);
1104 $$->set_location_range(@1, @2);
1105 $$->declarations.push_tail(&decl->link);
1106 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1108 | INVARIANT variable_identifier
1110 void *ctx = state->linalloc;
1111 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1112 decl->set_location(@2);
1114 $$ = new(ctx) ast_declarator_list(NULL);
1115 $$->set_location_range(@1, @2);
1116 $$->invariant = true;
1118 $$->declarations.push_tail(&decl->link);
1120 | PRECISE variable_identifier
1122 void *ctx = state->linalloc;
1123 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1124 decl->set_location(@2);
1126 $$ = new(ctx) ast_declarator_list(NULL);
1127 $$->set_location_range(@1, @2);
1130 $$->declarations.push_tail(&decl->link);
1134 fully_specified_type:
1137 void *ctx = state->linalloc;
1138 $$ = new(ctx) ast_fully_specified_type();
1139 $$->set_location(@1);
1142 | type_qualifier type_specifier
1144 void *ctx = state->linalloc;
1145 $$ = new(ctx) ast_fully_specified_type();
1146 $$->set_location_range(@1, @2);
1149 if ($$->specifier->structure != NULL &&
1150 $$->specifier->structure->is_declaration) {
1151 $$->specifier->structure->layout = &$$->qualifier;
1157 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1163 layout_qualifier_id_list:
1165 | layout_qualifier_id_list ',' layout_qualifier_id
1168 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1174 layout_qualifier_id:
1177 memset(& $$, 0, sizeof($$));
1179 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1180 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1181 state->is_version(150, 0))) {
1182 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1183 $$.flags.q.origin_upper_left = 1;
1184 } else if (match_layout_qualifier($1, "pixel_center_integer",
1186 $$.flags.q.pixel_center_integer = 1;
1189 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1190 _mesa_glsl_warning(& @1, state,
1191 "GL_ARB_fragment_coord_conventions layout "
1192 "identifier `%s' used", $1);
1196 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1198 (state->AMD_conservative_depth_enable ||
1199 state->ARB_conservative_depth_enable ||
1200 state->is_version(420, 0))) {
1201 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1202 $$.flags.q.depth_any = 1;
1203 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1204 $$.flags.q.depth_greater = 1;
1205 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1206 $$.flags.q.depth_less = 1;
1207 } else if (match_layout_qualifier($1, "depth_unchanged",
1209 $$.flags.q.depth_unchanged = 1;
1212 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1213 _mesa_glsl_warning(& @1, state,
1214 "GL_AMD_conservative_depth "
1215 "layout qualifier `%s' is used", $1);
1217 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1218 _mesa_glsl_warning(& @1, state,
1219 "GL_ARB_conservative_depth "
1220 "layout qualifier `%s' is used", $1);
1224 /* See also interface_block_layout_qualifier. */
1225 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1226 if (match_layout_qualifier($1, "std140", state) == 0) {
1227 $$.flags.q.std140 = 1;
1228 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1229 $$.flags.q.shared = 1;
1230 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1231 $$.flags.q.std430 = 1;
1232 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1233 $$.flags.q.column_major = 1;
1234 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1235 * below in the interface_block_layout_qualifier rule.
1237 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1240 * Also, this takes care of alternate capitalizations of
1241 * "row_major" (which is necessary because layout qualifiers
1242 * are case-insensitive in desktop GLSL).
1244 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1245 $$.flags.q.row_major = 1;
1246 /* "packed" is a reserved word in GLSL, and its token is
1247 * parsed below in the interface_block_layout_qualifier rule.
1248 * However, we must take care of alternate capitalizations of
1249 * "packed", because layout qualifiers are case-insensitive
1252 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1253 $$.flags.q.packed = 1;
1256 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1257 _mesa_glsl_warning(& @1, state,
1258 "#version 140 / GL_ARB_uniform_buffer_object "
1259 "layout qualifier `%s' is used", $1);
1263 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1265 static const struct {
1269 { "points", GL_POINTS },
1270 { "lines", GL_LINES },
1271 { "lines_adjacency", GL_LINES_ADJACENCY },
1272 { "line_strip", GL_LINE_STRIP },
1273 { "triangles", GL_TRIANGLES },
1274 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1275 { "triangle_strip", GL_TRIANGLE_STRIP },
1277 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1278 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1279 $$.flags.q.prim_type = 1;
1280 $$.prim_type = map[i].e;
1285 if ($$.flags.i && !state->has_geometry_shader() &&
1286 !state->has_tessellation_shader()) {
1287 _mesa_glsl_error(& @1, state, "#version 150 layout "
1288 "qualifier `%s' used", $1);
1292 /* Layout qualifiers for ARB_shader_image_load_store. */
1293 if (state->ARB_shader_image_load_store_enable ||
1294 state->is_version(420, 310)) {
1296 static const struct {
1299 glsl_base_type base_type;
1300 /** Minimum desktop GLSL version required for the image
1301 * format. Use 130 if already present in the original
1304 unsigned required_glsl;
1305 /** Minimum GLSL ES version required for the image format. */
1306 unsigned required_essl;
1307 /* NV_image_formats */
1308 bool nv_image_formats;
1310 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1311 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1312 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1313 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1314 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1315 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1316 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1317 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1318 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1319 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1320 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1321 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1322 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1323 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1324 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1325 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1326 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1327 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1328 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1329 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1330 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1331 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1332 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1333 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1334 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1335 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1336 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
1337 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1338 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1339 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
1340 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1341 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
1342 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1343 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1344 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1345 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1346 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1347 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1348 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1351 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1352 if ((state->is_version(map[i].required_glsl,
1353 map[i].required_essl) ||
1354 (state->NV_image_formats_enable &&
1355 map[i].nv_image_formats)) &&
1356 match_layout_qualifier($1, map[i].name, state) == 0) {
1357 $$.flags.q.explicit_image_format = 1;
1358 $$.image_format = map[i].format;
1359 $$.image_base_type = map[i].base_type;
1366 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1367 /* From section 4.4.1.3 of the GLSL 4.50 specification
1368 * (Fragment Shader Inputs):
1370 * "Fragment shaders also allow the following layout
1371 * qualifier on in only (not with variable declarations)
1372 * layout-qualifier-id
1373 * early_fragment_tests
1376 if (state->stage != MESA_SHADER_FRAGMENT) {
1377 _mesa_glsl_error(& @1, state,
1378 "early_fragment_tests layout qualifier only "
1379 "valid in fragment shaders");
1382 $$.flags.q.early_fragment_tests = 1;
1386 /* Layout qualifiers for tessellation evaluation shaders. */
1388 static const struct {
1392 /* triangles already parsed by gs-specific code */
1393 { "quads", GL_QUADS },
1394 { "isolines", GL_ISOLINES },
1396 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1397 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1398 $$.flags.q.prim_type = 1;
1399 $$.prim_type = map[i].e;
1404 if ($$.flags.i && !state->has_tessellation_shader()) {
1405 _mesa_glsl_error(& @1, state,
1406 "primitive mode qualifier `%s' requires "
1407 "GLSL 4.00 or ARB_tessellation_shader", $1);
1411 static const struct {
1415 { "equal_spacing", GL_EQUAL },
1416 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1417 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1419 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1420 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1421 $$.flags.q.vertex_spacing = 1;
1422 $$.vertex_spacing = map[i].e;
1427 if ($$.flags.i && !state->has_tessellation_shader()) {
1428 _mesa_glsl_error(& @1, state,
1429 "vertex spacing qualifier `%s' requires "
1430 "GLSL 4.00 or ARB_tessellation_shader", $1);
1434 if (match_layout_qualifier($1, "cw", state) == 0) {
1435 $$.flags.q.ordering = 1;
1436 $$.ordering = GL_CW;
1437 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1438 $$.flags.q.ordering = 1;
1439 $$.ordering = GL_CCW;
1442 if ($$.flags.i && !state->has_tessellation_shader()) {
1443 _mesa_glsl_error(& @1, state,
1444 "ordering qualifier `%s' requires "
1445 "GLSL 4.00 or ARB_tessellation_shader", $1);
1449 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1450 $$.flags.q.point_mode = 1;
1451 $$.point_mode = true;
1454 if ($$.flags.i && !state->has_tessellation_shader()) {
1455 _mesa_glsl_error(& @1, state,
1456 "qualifier `point_mode' requires "
1457 "GLSL 4.00 or ARB_tessellation_shader");
1462 static const struct {
1466 { "blend_support_multiply", BLEND_MULTIPLY },
1467 { "blend_support_screen", BLEND_SCREEN },
1468 { "blend_support_overlay", BLEND_OVERLAY },
1469 { "blend_support_darken", BLEND_DARKEN },
1470 { "blend_support_lighten", BLEND_LIGHTEN },
1471 { "blend_support_colordodge", BLEND_COLORDODGE },
1472 { "blend_support_colorburn", BLEND_COLORBURN },
1473 { "blend_support_hardlight", BLEND_HARDLIGHT },
1474 { "blend_support_softlight", BLEND_SOFTLIGHT },
1475 { "blend_support_difference", BLEND_DIFFERENCE },
1476 { "blend_support_exclusion", BLEND_EXCLUSION },
1477 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1478 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1479 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1480 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1481 { "blend_support_all_equations", BLEND_ALL },
1483 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1484 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1485 $$.flags.q.blend_support = 1;
1486 state->fs_blend_support |= map[i].mask;
1492 !state->KHR_blend_equation_advanced_enable &&
1493 !state->is_version(0, 320)) {
1494 _mesa_glsl_error(& @1, state,
1495 "advanced blending layout qualifiers require "
1496 "ESSL 3.20 or KHR_blend_equation_advanced");
1499 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1500 _mesa_glsl_error(& @1, state,
1501 "advanced blending layout qualifiers only "
1502 "valid in fragment shaders");
1506 /* Layout qualifiers for ARB_compute_variable_group_size. */
1508 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1509 $$.flags.q.local_size_variable = 1;
1512 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1513 _mesa_glsl_error(& @1, state,
1514 "qualifier `local_size_variable` requires "
1515 "ARB_compute_variable_group_size");
1520 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1525 | any_identifier '=' constant_expression
1527 memset(& $$, 0, sizeof($$));
1528 void *ctx = state->linalloc;
1530 if ($3->oper != ast_int_constant &&
1531 $3->oper != ast_uint_constant &&
1532 !state->has_enhanced_layouts()) {
1533 _mesa_glsl_error(& @1, state,
1534 "compile-time constant expressions require "
1535 "GLSL 4.40 or ARB_enhanced_layouts");
1538 if (match_layout_qualifier("align", $1, state) == 0) {
1539 if (!state->has_enhanced_layouts()) {
1540 _mesa_glsl_error(& @1, state,
1541 "align qualifier requires "
1542 "GLSL 4.40 or ARB_enhanced_layouts");
1544 $$.flags.q.explicit_align = 1;
1549 if (match_layout_qualifier("location", $1, state) == 0) {
1550 $$.flags.q.explicit_location = 1;
1552 if ($$.flags.q.attribute == 1 &&
1553 state->ARB_explicit_attrib_location_warn) {
1554 _mesa_glsl_warning(& @1, state,
1555 "GL_ARB_explicit_attrib_location layout "
1556 "identifier `%s' used", $1);
1561 if (match_layout_qualifier("component", $1, state) == 0) {
1562 if (!state->has_enhanced_layouts()) {
1563 _mesa_glsl_error(& @1, state,
1564 "component qualifier requires "
1565 "GLSL 4.40 or ARB_enhanced_layouts");
1567 $$.flags.q.explicit_component = 1;
1572 if (match_layout_qualifier("index", $1, state) == 0) {
1573 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1574 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1578 $$.flags.q.explicit_index = 1;
1582 if ((state->has_420pack_or_es31() ||
1583 state->has_atomic_counters() ||
1584 state->has_shader_storage_buffer_objects()) &&
1585 match_layout_qualifier("binding", $1, state) == 0) {
1586 $$.flags.q.explicit_binding = 1;
1590 if ((state->has_atomic_counters() ||
1591 state->has_enhanced_layouts()) &&
1592 match_layout_qualifier("offset", $1, state) == 0) {
1593 $$.flags.q.explicit_offset = 1;
1597 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1598 $$.flags.q.max_vertices = 1;
1599 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1600 if (!state->has_geometry_shader()) {
1601 _mesa_glsl_error(& @3, state,
1602 "#version 150 max_vertices qualifier "
1607 if (state->stage == MESA_SHADER_GEOMETRY) {
1608 if (match_layout_qualifier("stream", $1, state) == 0 &&
1609 state->check_explicit_attrib_stream_allowed(& @3)) {
1610 $$.flags.q.stream = 1;
1611 $$.flags.q.explicit_stream = 1;
1616 if (state->has_enhanced_layouts()) {
1617 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1618 $$.flags.q.xfb_buffer = 1;
1619 $$.flags.q.explicit_xfb_buffer = 1;
1623 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1624 $$.flags.q.explicit_xfb_offset = 1;
1628 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1629 $$.flags.q.xfb_stride = 1;
1630 $$.flags.q.explicit_xfb_stride = 1;
1635 static const char * const local_size_qualifiers[3] = {
1640 for (int i = 0; i < 3; i++) {
1641 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1643 if (!state->has_compute_shader()) {
1644 _mesa_glsl_error(& @3, state,
1645 "%s qualifier requires GLSL 4.30 or "
1646 "GLSL ES 3.10 or ARB_compute_shader",
1647 local_size_qualifiers[i]);
1650 $$.flags.q.local_size |= (1 << i);
1651 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1657 if (match_layout_qualifier("invocations", $1, state) == 0) {
1658 $$.flags.q.invocations = 1;
1659 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1660 if (!state->is_version(400, 320) &&
1661 !state->ARB_gpu_shader5_enable &&
1662 !state->OES_geometry_shader_enable &&
1663 !state->EXT_geometry_shader_enable) {
1664 _mesa_glsl_error(& @3, state,
1665 "GL_ARB_gpu_shader5 invocations "
1666 "qualifier specified", $3);
1670 /* Layout qualifiers for tessellation control shaders. */
1671 if (match_layout_qualifier("vertices", $1, state) == 0) {
1672 $$.flags.q.vertices = 1;
1673 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1674 if (!state->has_tessellation_shader()) {
1675 _mesa_glsl_error(& @1, state,
1676 "vertices qualifier requires GLSL 4.00 or "
1677 "ARB_tessellation_shader");
1681 /* If the identifier didn't match any known layout identifiers,
1685 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1690 | interface_block_layout_qualifier
1693 /* Layout qualifiers for ARB_uniform_buffer_object. */
1694 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1695 _mesa_glsl_error(& @1, state,
1696 "#version 140 / GL_ARB_uniform_buffer_object "
1697 "layout qualifier `%s' is used", $1);
1698 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1699 _mesa_glsl_warning(& @1, state,
1700 "#version 140 / GL_ARB_uniform_buffer_object "
1701 "layout qualifier `%s' is used", $1);
1706 /* This is a separate language rule because we parse these as tokens
1707 * (due to them being reserved keywords) instead of identifiers like
1708 * most qualifiers. See the any_identifier path of
1709 * layout_qualifier_id for the others.
1711 * Note that since layout qualifiers are case-insensitive in desktop
1712 * GLSL, all of these qualifiers need to be handled as identifiers as
1713 * well (by the any_identifier path of layout_qualifier_id).
1715 interface_block_layout_qualifier:
1718 memset(& $$, 0, sizeof($$));
1719 $$.flags.q.row_major = 1;
1723 memset(& $$, 0, sizeof($$));
1724 $$.flags.q.packed = 1;
1728 memset(& $$, 0, sizeof($$));
1729 $$.flags.q.shared = 1;
1733 subroutine_qualifier:
1736 memset(& $$, 0, sizeof($$));
1737 $$.flags.q.subroutine = 1;
1739 | SUBROUTINE '(' subroutine_type_list ')'
1741 memset(& $$, 0, sizeof($$));
1742 $$.flags.q.subroutine_def = 1;
1743 $$.subroutine_list = $3;
1747 subroutine_type_list:
1750 void *ctx = state->linalloc;
1751 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1752 decl->set_location(@1);
1754 $$ = new(ctx) ast_subroutine_list();
1755 $$->declarations.push_tail(&decl->link);
1757 | subroutine_type_list ',' any_identifier
1759 void *ctx = state->linalloc;
1760 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1761 decl->set_location(@3);
1764 $$->declarations.push_tail(&decl->link);
1768 interpolation_qualifier:
1771 memset(& $$, 0, sizeof($$));
1772 $$.flags.q.smooth = 1;
1776 memset(& $$, 0, sizeof($$));
1777 $$.flags.q.flat = 1;
1781 memset(& $$, 0, sizeof($$));
1782 $$.flags.q.noperspective = 1;
1787 /* Single qualifiers */
1790 memset(& $$, 0, sizeof($$));
1791 $$.flags.q.invariant = 1;
1795 memset(& $$, 0, sizeof($$));
1796 $$.flags.q.precise = 1;
1798 | auxiliary_storage_qualifier
1800 | interpolation_qualifier
1803 | subroutine_qualifier
1804 | precision_qualifier
1806 memset(&$$, 0, sizeof($$));
1810 /* Multiple qualifiers:
1811 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1812 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1814 * invariant interpolation auxiliary storage precision ...or...
1815 * layout storage precision
1817 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1818 * side don't contain any that must appear on the left hand side.
1819 * For example, when processing a storage qualifier, we check that there are
1820 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1822 | PRECISE type_qualifier
1824 if ($2.flags.q.precise)
1825 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1828 $$.flags.q.precise = 1;
1830 | INVARIANT type_qualifier
1832 if ($2.flags.q.invariant)
1833 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1835 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1836 _mesa_glsl_error(&@1, state,
1837 "\"invariant\" must come after \"precise\"");
1840 $$.flags.q.invariant = 1;
1842 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1844 * "Only variables output from a shader can be candidates for invariance.
1845 * This includes user-defined output variables and the built-in output
1846 * variables. As only outputs can be declared as invariant, an invariant
1847 * output from one shader stage will still match an input of a subsequent
1848 * stage without the input being declared as invariant."
1850 * On the desktop side, this text first appears in GLSL 4.30.
1852 if (state->is_version(430, 300) && $$.flags.q.in)
1853 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1855 | interpolation_qualifier type_qualifier
1857 /* Section 4.3 of the GLSL 1.40 specification states:
1858 * "...qualified with one of these interpolation qualifiers"
1860 * GLSL 1.30 claims to allow "one or more", but insists that:
1861 * "These interpolation qualifiers may only precede the qualifiers in,
1862 * centroid in, out, or centroid out in a declaration."
1864 * ...which means that e.g. smooth can't precede smooth, so there can be
1865 * only one after all, and the 1.40 text is a clarification, not a change.
1867 if ($2.has_interpolation())
1868 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1870 if (!state->has_420pack_or_es31() &&
1871 ($2.flags.q.precise || $2.flags.q.invariant)) {
1872 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1873 "after \"precise\" or \"invariant\"");
1877 $$.merge_qualifier(&@1, state, $2, false);
1879 | layout_qualifier type_qualifier
1881 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1882 * appear no later than auxiliary storage qualifiers. There is no
1883 * particularly clear spec language mandating this, but in all examples
1884 * the layout qualifier precedes the storage qualifier.
1886 * We allow combinations of layout with interpolation, invariant or
1887 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1888 * There is no clear spec guidance on this either.
1890 if (!state->has_420pack_or_es31() && $2.has_layout())
1891 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1894 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1896 | subroutine_qualifier type_qualifier
1899 $$.merge_qualifier(&@1, state, $2, false);
1901 | auxiliary_storage_qualifier type_qualifier
1903 if ($2.has_auxiliary_storage()) {
1904 _mesa_glsl_error(&@1, state,
1905 "duplicate auxiliary storage qualifier (centroid or sample)");
1908 if (!state->has_420pack_or_es31() &&
1909 ($2.flags.q.precise || $2.flags.q.invariant ||
1910 $2.has_interpolation() || $2.has_layout())) {
1911 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1912 "just before storage qualifiers");
1915 $$.merge_qualifier(&@1, state, $2, false);
1917 | storage_qualifier type_qualifier
1919 /* Section 4.3 of the GLSL 1.20 specification states:
1920 * "Variable declarations may have a storage qualifier specified..."
1921 * 1.30 clarifies this to "may have one storage qualifier".
1923 if ($2.has_storage())
1924 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1926 if (!state->has_420pack_or_es31() &&
1927 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1928 $2.has_layout() || $2.has_auxiliary_storage())) {
1929 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1930 "precise, invariant, interpolation, layout and auxiliary "
1931 "storage qualifiers");
1935 $$.merge_qualifier(&@1, state, $2, false);
1937 | precision_qualifier type_qualifier
1939 if ($2.precision != ast_precision_none)
1940 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1942 if (!(state->has_420pack_or_es31()) &&
1944 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1949 | memory_qualifier type_qualifier
1952 $$.merge_qualifier(&@1, state, $2, false);
1956 auxiliary_storage_qualifier:
1959 memset(& $$, 0, sizeof($$));
1960 $$.flags.q.centroid = 1;
1964 memset(& $$, 0, sizeof($$));
1965 $$.flags.q.sample = 1;
1969 memset(& $$, 0, sizeof($$));
1970 $$.flags.q.patch = 1;
1976 memset(& $$, 0, sizeof($$));
1977 $$.flags.q.constant = 1;
1981 memset(& $$, 0, sizeof($$));
1982 $$.flags.q.attribute = 1;
1986 memset(& $$, 0, sizeof($$));
1987 $$.flags.q.varying = 1;
1991 memset(& $$, 0, sizeof($$));
1996 memset(& $$, 0, sizeof($$));
1999 if (state->stage == MESA_SHADER_GEOMETRY &&
2000 state->has_explicit_attrib_stream()) {
2001 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2004 * "If the block or variable is declared with the stream
2005 * identifier, it is associated with the specified stream;
2006 * otherwise, it is associated with the current default stream."
2008 $$.flags.q.stream = 1;
2009 $$.flags.q.explicit_stream = 0;
2010 $$.stream = state->out_qualifier->stream;
2013 if (state->has_enhanced_layouts()) {
2014 $$.flags.q.xfb_buffer = 1;
2015 $$.flags.q.explicit_xfb_buffer = 0;
2016 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2021 memset(& $$, 0, sizeof($$));
2025 if (!state->has_framebuffer_fetch() ||
2026 !state->is_version(130, 300) ||
2027 state->stage != MESA_SHADER_FRAGMENT)
2028 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2029 "declared as both input and output");
2033 memset(& $$, 0, sizeof($$));
2034 $$.flags.q.uniform = 1;
2038 memset(& $$, 0, sizeof($$));
2039 $$.flags.q.buffer = 1;
2043 memset(& $$, 0, sizeof($$));
2044 $$.flags.q.shared_storage = 1;
2051 memset(& $$, 0, sizeof($$));
2052 $$.flags.q.coherent = 1;
2056 memset(& $$, 0, sizeof($$));
2057 $$.flags.q._volatile = 1;
2061 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2062 memset(& $$, 0, sizeof($$));
2063 $$.flags.q.restrict_flag = 1;
2067 memset(& $$, 0, sizeof($$));
2068 $$.flags.q.read_only = 1;
2072 memset(& $$, 0, sizeof($$));
2073 $$.flags.q.write_only = 1;
2080 void *ctx = state->linalloc;
2081 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2082 ast_unsized_array_dim, NULL,
2084 $$->set_location_range(@1, @2);
2086 | '[' constant_expression ']'
2088 void *ctx = state->linalloc;
2089 $$ = new(ctx) ast_array_specifier(@1, $2);
2090 $$->set_location_range(@1, @3);
2092 | array_specifier '[' ']'
2094 void *ctx = state->linalloc;
2097 if (state->check_arrays_of_arrays_allowed(& @1)) {
2098 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2102 | array_specifier '[' constant_expression ']'
2106 if (state->check_arrays_of_arrays_allowed(& @1)) {
2107 $$->add_dimension($3);
2113 type_specifier_nonarray
2114 | type_specifier_nonarray array_specifier
2117 $$->array_specifier = $2;
2121 type_specifier_nonarray:
2122 basic_type_specifier_nonarray
2124 void *ctx = state->linalloc;
2125 $$ = new(ctx) ast_type_specifier($1);
2126 $$->set_location(@1);
2130 void *ctx = state->linalloc;
2131 $$ = new(ctx) ast_type_specifier($1);
2132 $$->set_location(@1);
2136 void *ctx = state->linalloc;
2137 $$ = new(ctx) ast_type_specifier($1);
2138 $$->set_location(@1);
2142 basic_type_specifier_nonarray:
2143 VOID_TOK { $$ = "void"; }
2144 | FLOAT_TOK { $$ = "float"; }
2145 | DOUBLE_TOK { $$ = "double"; }
2146 | INT_TOK { $$ = "int"; }
2147 | UINT_TOK { $$ = "uint"; }
2148 | BOOL_TOK { $$ = "bool"; }
2149 | VEC2 { $$ = "vec2"; }
2150 | VEC3 { $$ = "vec3"; }
2151 | VEC4 { $$ = "vec4"; }
2152 | BVEC2 { $$ = "bvec2"; }
2153 | BVEC3 { $$ = "bvec3"; }
2154 | BVEC4 { $$ = "bvec4"; }
2155 | IVEC2 { $$ = "ivec2"; }
2156 | IVEC3 { $$ = "ivec3"; }
2157 | IVEC4 { $$ = "ivec4"; }
2158 | UVEC2 { $$ = "uvec2"; }
2159 | UVEC3 { $$ = "uvec3"; }
2160 | UVEC4 { $$ = "uvec4"; }
2161 | DVEC2 { $$ = "dvec2"; }
2162 | DVEC3 { $$ = "dvec3"; }
2163 | DVEC4 { $$ = "dvec4"; }
2164 | MAT2X2 { $$ = "mat2"; }
2165 | MAT2X3 { $$ = "mat2x3"; }
2166 | MAT2X4 { $$ = "mat2x4"; }
2167 | MAT3X2 { $$ = "mat3x2"; }
2168 | MAT3X3 { $$ = "mat3"; }
2169 | MAT3X4 { $$ = "mat3x4"; }
2170 | MAT4X2 { $$ = "mat4x2"; }
2171 | MAT4X3 { $$ = "mat4x3"; }
2172 | MAT4X4 { $$ = "mat4"; }
2173 | DMAT2X2 { $$ = "dmat2"; }
2174 | DMAT2X3 { $$ = "dmat2x3"; }
2175 | DMAT2X4 { $$ = "dmat2x4"; }
2176 | DMAT3X2 { $$ = "dmat3x2"; }
2177 | DMAT3X3 { $$ = "dmat3"; }
2178 | DMAT3X4 { $$ = "dmat3x4"; }
2179 | DMAT4X2 { $$ = "dmat4x2"; }
2180 | DMAT4X3 { $$ = "dmat4x3"; }
2181 | DMAT4X4 { $$ = "dmat4"; }
2182 | SAMPLER1D { $$ = "sampler1D"; }
2183 | SAMPLER2D { $$ = "sampler2D"; }
2184 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2185 | SAMPLER3D { $$ = "sampler3D"; }
2186 | SAMPLERCUBE { $$ = "samplerCube"; }
2187 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2188 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2189 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2190 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2191 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2192 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2193 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2194 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2195 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2196 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2197 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2198 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2199 | ISAMPLER1D { $$ = "isampler1D"; }
2200 | ISAMPLER2D { $$ = "isampler2D"; }
2201 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2202 | ISAMPLER3D { $$ = "isampler3D"; }
2203 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2204 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2205 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2206 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2207 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2208 | USAMPLER1D { $$ = "usampler1D"; }
2209 | USAMPLER2D { $$ = "usampler2D"; }
2210 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2211 | USAMPLER3D { $$ = "usampler3D"; }
2212 | USAMPLERCUBE { $$ = "usamplerCube"; }
2213 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2214 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2215 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2216 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2217 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2218 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2219 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2220 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2221 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2222 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2223 | IMAGE1D { $$ = "image1D"; }
2224 | IMAGE2D { $$ = "image2D"; }
2225 | IMAGE3D { $$ = "image3D"; }
2226 | IMAGE2DRECT { $$ = "image2DRect"; }
2227 | IMAGECUBE { $$ = "imageCube"; }
2228 | IMAGEBUFFER { $$ = "imageBuffer"; }
2229 | IMAGE1DARRAY { $$ = "image1DArray"; }
2230 | IMAGE2DARRAY { $$ = "image2DArray"; }
2231 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2232 | IMAGE2DMS { $$ = "image2DMS"; }
2233 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2234 | IIMAGE1D { $$ = "iimage1D"; }
2235 | IIMAGE2D { $$ = "iimage2D"; }
2236 | IIMAGE3D { $$ = "iimage3D"; }
2237 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2238 | IIMAGECUBE { $$ = "iimageCube"; }
2239 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2240 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2241 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2242 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2243 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2244 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2245 | UIMAGE1D { $$ = "uimage1D"; }
2246 | UIMAGE2D { $$ = "uimage2D"; }
2247 | UIMAGE3D { $$ = "uimage3D"; }
2248 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2249 | UIMAGECUBE { $$ = "uimageCube"; }
2250 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2251 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2252 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2253 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2254 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2255 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2256 | ATOMIC_UINT { $$ = "atomic_uint"; }
2259 precision_qualifier:
2262 state->check_precision_qualifiers_allowed(&@1);
2263 $$ = ast_precision_high;
2267 state->check_precision_qualifiers_allowed(&@1);
2268 $$ = ast_precision_medium;
2272 state->check_precision_qualifiers_allowed(&@1);
2273 $$ = ast_precision_low;
2278 STRUCT any_identifier '{' struct_declaration_list '}'
2280 void *ctx = state->linalloc;
2281 $$ = new(ctx) ast_struct_specifier(ctx, $2, $4);
2282 $$->set_location_range(@2, @5);
2283 state->symbols->add_type($2, glsl_type::void_type);
2285 | STRUCT '{' struct_declaration_list '}'
2287 void *ctx = state->linalloc;
2288 $$ = new(ctx) ast_struct_specifier(ctx, NULL, $3);
2289 $$->set_location_range(@2, @4);
2293 struct_declaration_list:
2297 $1->link.self_link();
2299 | struct_declaration_list struct_declaration
2302 $$->link.insert_before(& $2->link);
2307 fully_specified_type struct_declarator_list ';'
2309 void *ctx = state->linalloc;
2310 ast_fully_specified_type *const type = $1;
2311 type->set_location(@1);
2313 if (type->qualifier.flags.i != 0)
2314 _mesa_glsl_error(&@1, state,
2315 "only precision qualifiers may be applied to "
2316 "structure members");
2318 $$ = new(ctx) ast_declarator_list(type);
2319 $$->set_location(@2);
2321 $$->declarations.push_degenerate_list_at_head(& $2->link);
2325 struct_declarator_list:
2329 $1->link.self_link();
2331 | struct_declarator_list ',' struct_declarator
2334 $$->link.insert_before(& $3->link);
2341 void *ctx = state->linalloc;
2342 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2343 $$->set_location(@1);
2345 | any_identifier array_specifier
2347 void *ctx = state->linalloc;
2348 $$ = new(ctx) ast_declaration($1, $2, NULL);
2349 $$->set_location_range(@1, @2);
2354 assignment_expression
2355 | '{' initializer_list '}'
2359 | '{' initializer_list ',' '}'
2368 void *ctx = state->linalloc;
2369 $$ = new(ctx) ast_aggregate_initializer();
2370 $$->set_location(@1);
2371 $$->expressions.push_tail(& $1->link);
2373 | initializer_list ',' initializer
2375 $1->expressions.push_tail(& $3->link);
2379 declaration_statement:
2383 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2386 compound_statement { $$ = (ast_node *) $1; }
2391 declaration_statement
2392 | expression_statement
2393 | selection_statement
2395 | iteration_statement
2402 void *ctx = state->linalloc;
2403 $$ = new(ctx) ast_compound_statement(true, NULL);
2404 $$->set_location_range(@1, @2);
2408 state->symbols->push_scope();
2412 void *ctx = state->linalloc;
2413 $$ = new(ctx) ast_compound_statement(true, $3);
2414 $$->set_location_range(@1, @4);
2415 state->symbols->pop_scope();
2419 statement_no_new_scope:
2420 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2424 compound_statement_no_new_scope:
2427 void *ctx = state->linalloc;
2428 $$ = new(ctx) ast_compound_statement(false, NULL);
2429 $$->set_location_range(@1, @2);
2431 | '{' statement_list '}'
2433 void *ctx = state->linalloc;
2434 $$ = new(ctx) ast_compound_statement(false, $2);
2435 $$->set_location_range(@1, @3);
2443 _mesa_glsl_error(& @1, state, "<nil> statement");
2448 $$->link.self_link();
2450 | statement_list statement
2453 _mesa_glsl_error(& @2, state, "<nil> statement");
2457 $$->link.insert_before(& $2->link);
2461 expression_statement:
2464 void *ctx = state->linalloc;
2465 $$ = new(ctx) ast_expression_statement(NULL);
2466 $$->set_location(@1);
2470 void *ctx = state->linalloc;
2471 $$ = new(ctx) ast_expression_statement($1);
2472 $$->set_location(@1);
2476 selection_statement:
2477 IF '(' expression ')' selection_rest_statement
2479 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2481 $$->set_location_range(@1, @5);
2485 selection_rest_statement:
2486 statement ELSE statement
2488 $$.then_statement = $1;
2489 $$.else_statement = $3;
2491 | statement %prec THEN
2493 $$.then_statement = $1;
2494 $$.else_statement = NULL;
2501 $$ = (ast_node *) $1;
2503 | fully_specified_type any_identifier '=' initializer
2505 void *ctx = state->linalloc;
2506 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2507 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2508 decl->set_location_range(@2, @4);
2509 declarator->set_location(@1);
2511 declarator->declarations.push_tail(&decl->link);
2517 * switch_statement grammar is based on the syntax described in the body
2518 * of the GLSL spec, not in it's appendix!!!
2521 SWITCH '(' expression ')' switch_body
2523 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2524 $$->set_location_range(@1, @5);
2531 $$ = new(state->linalloc) ast_switch_body(NULL);
2532 $$->set_location_range(@1, @2);
2534 | '{' case_statement_list '}'
2536 $$ = new(state->linalloc) ast_switch_body($2);
2537 $$->set_location_range(@1, @3);
2544 $$ = new(state->linalloc) ast_case_label($2);
2545 $$->set_location(@2);
2549 $$ = new(state->linalloc) ast_case_label(NULL);
2550 $$->set_location(@2);
2557 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2559 labels->labels.push_tail(& $1->link);
2561 $$->set_location(@1);
2563 | case_label_list case_label
2566 $$->labels.push_tail(& $2->link);
2571 case_label_list statement
2573 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2574 stmts->set_location(@2);
2576 stmts->stmts.push_tail(& $2->link);
2579 | case_statement statement
2582 $$->stmts.push_tail(& $2->link);
2586 case_statement_list:
2589 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2590 cases->set_location(@1);
2592 cases->cases.push_tail(& $1->link);
2595 | case_statement_list case_statement
2598 $$->cases.push_tail(& $2->link);
2602 iteration_statement:
2603 WHILE '(' condition ')' statement_no_new_scope
2605 void *ctx = state->linalloc;
2606 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2607 NULL, $3, NULL, $5);
2608 $$->set_location_range(@1, @4);
2610 | DO statement WHILE '(' expression ')' ';'
2612 void *ctx = state->linalloc;
2613 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2614 NULL, $5, NULL, $2);
2615 $$->set_location_range(@1, @6);
2617 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2619 void *ctx = state->linalloc;
2620 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2621 $3, $4.cond, $4.rest, $6);
2622 $$->set_location_range(@1, @6);
2627 expression_statement
2628 | declaration_statement
2645 | conditionopt ';' expression
2652 // Grammar Note: No 'goto'. Gotos are not supported.
2656 void *ctx = state->linalloc;
2657 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2658 $$->set_location(@1);
2662 void *ctx = state->linalloc;
2663 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2664 $$->set_location(@1);
2668 void *ctx = state->linalloc;
2669 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2670 $$->set_location(@1);
2672 | RETURN expression ';'
2674 void *ctx = state->linalloc;
2675 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2676 $$->set_location_range(@1, @2);
2678 | DISCARD ';' // Fragment shader only.
2680 void *ctx = state->linalloc;
2681 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2682 $$->set_location(@1);
2686 external_declaration:
2687 function_definition { $$ = $1; }
2688 | declaration { $$ = $1; }
2689 | pragma_statement { $$ = NULL; }
2690 | layout_defaults { $$ = $1; }
2693 function_definition:
2694 function_prototype compound_statement_no_new_scope
2696 void *ctx = state->linalloc;
2697 $$ = new(ctx) ast_function_definition();
2698 $$->set_location_range(@1, @2);
2702 state->symbols->pop_scope();
2706 /* layout_qualifieropt is packed into this rule */
2708 basic_interface_block
2712 | layout_qualifier interface_block
2714 ast_interface_block *block = (ast_interface_block *) $2;
2716 if (!state->has_420pack_or_es31() && block->layout.has_layout()) {
2717 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2721 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2722 block->layout.has_layout())) {
2730 | memory_qualifier interface_block
2732 ast_interface_block *block = (ast_interface_block *)$2;
2734 if (!block->default_layout.flags.q.buffer) {
2735 _mesa_glsl_error(& @1, state,
2736 "memory qualifiers can only be used in the "
2737 "declaration of shader storage blocks");
2739 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2747 basic_interface_block:
2748 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2750 ast_interface_block *const block = $6;
2752 if ($1.flags.q.uniform) {
2753 block->default_layout = *state->default_uniform_qualifier;
2754 } else if ($1.flags.q.buffer) {
2755 block->default_layout = *state->default_shader_storage_qualifier;
2757 block->block_name = $2;
2758 block->declarations.push_degenerate_list_at_head(& $4->link);
2760 _mesa_ast_process_interface_block(& @1, state, block, $1);
2766 interface_qualifier:
2769 memset(& $$, 0, sizeof($$));
2774 memset(& $$, 0, sizeof($$));
2779 memset(& $$, 0, sizeof($$));
2780 $$.flags.q.uniform = 1;
2784 memset(& $$, 0, sizeof($$));
2785 $$.flags.q.buffer = 1;
2787 | auxiliary_storage_qualifier interface_qualifier
2789 if (!$1.flags.q.patch) {
2790 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2792 if ($2.has_auxiliary_storage()) {
2793 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2796 $$.flags.q.patch = 1;
2803 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2807 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2808 $$->set_location(@1);
2810 | NEW_IDENTIFIER array_specifier
2812 $$ = new(state->linalloc) ast_interface_block($1, $2);
2813 $$->set_location_range(@1, @2);
2821 $1->link.self_link();
2823 | member_declaration member_list
2826 $2->link.insert_before(& $$->link);
2831 fully_specified_type struct_declarator_list ';'
2833 void *ctx = state->linalloc;
2834 ast_fully_specified_type *type = $1;
2835 type->set_location(@1);
2837 if (type->qualifier.flags.q.attribute) {
2838 _mesa_glsl_error(& @1, state,
2839 "keyword 'attribute' cannot be used with "
2840 "interface block member");
2841 } else if (type->qualifier.flags.q.varying) {
2842 _mesa_glsl_error(& @1, state,
2843 "keyword 'varying' cannot be used with "
2844 "interface block member");
2847 $$ = new(ctx) ast_declarator_list(type);
2848 $$->set_location(@2);
2850 $$->declarations.push_degenerate_list_at_head(& $2->link);
2854 layout_uniform_defaults:
2855 layout_qualifier layout_uniform_defaults
2858 if (!state->has_420pack_or_es31()) {
2859 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2862 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2866 | layout_qualifier UNIFORM ';'
2869 layout_buffer_defaults:
2870 layout_qualifier layout_buffer_defaults
2873 if (!state->has_420pack_or_es31()) {
2874 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2877 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2881 | layout_qualifier BUFFER ';'
2885 layout_qualifier layout_in_defaults
2888 if (!state->has_420pack_or_es31()) {
2889 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2892 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2895 if (!$$.validate_in_qualifier(& @1, state)) {
2899 | layout_qualifier IN_TOK ';'
2901 if (!$1.validate_in_qualifier(& @1, state)) {
2907 layout_out_defaults:
2908 layout_qualifier layout_out_defaults
2911 if (!state->has_420pack_or_es31()) {
2912 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2915 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2918 if (!$$.validate_out_qualifier(& @1, state)) {
2922 | layout_qualifier OUT_TOK ';'
2924 if (!$1.validate_out_qualifier(& @1, state)) {
2931 layout_uniform_defaults
2934 if (!state->default_uniform_qualifier->
2935 merge_qualifier(& @1, state, $1, false)) {
2939 | layout_buffer_defaults
2942 if (!state->default_shader_storage_qualifier->
2943 merge_qualifier(& @1, state, $1, false)) {
2947 /* From the GLSL 4.50 spec, section 4.4.5:
2949 * "It is a compile-time error to specify the binding identifier for
2950 * the global scope or for block member declarations."
2952 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2953 _mesa_glsl_error(& @1, state,
2954 "binding qualifier cannot be set for default layout");
2957 | layout_in_defaults
2960 if (!$1.merge_into_in_qualifier(& @1, state, $$, true)) {
2964 | layout_out_defaults
2967 if (!$1.merge_into_out_qualifier(& @1, state, $$, true)) {