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;
848 if (!block->layout.push_to_global(& @1, state)) {
856 function_declarator ')'
861 | function_header_with_parameters
864 function_header_with_parameters:
865 function_header parameter_declaration
868 $$->parameters.push_tail(& $2->link);
870 | function_header_with_parameters ',' parameter_declaration
873 $$->parameters.push_tail(& $3->link);
878 fully_specified_type variable_identifier '('
880 void *ctx = state->linalloc;
881 $$ = new(ctx) ast_function();
882 $$->set_location(@2);
883 $$->return_type = $1;
886 if ($1->qualifier.flags.q.subroutine) {
887 /* add type for IDENTIFIER search */
888 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
890 state->symbols->add_function(new(state) ir_function($2));
891 state->symbols->push_scope();
895 parameter_declarator:
896 type_specifier any_identifier
898 void *ctx = state->linalloc;
899 $$ = new(ctx) ast_parameter_declarator();
900 $$->set_location_range(@1, @2);
901 $$->type = new(ctx) ast_fully_specified_type();
902 $$->type->set_location(@1);
903 $$->type->specifier = $1;
905 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
907 | type_specifier any_identifier array_specifier
909 void *ctx = state->linalloc;
910 $$ = new(ctx) ast_parameter_declarator();
911 $$->set_location_range(@1, @3);
912 $$->type = new(ctx) ast_fully_specified_type();
913 $$->type->set_location(@1);
914 $$->type->specifier = $1;
916 $$->array_specifier = $3;
917 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
921 parameter_declaration:
922 parameter_qualifier parameter_declarator
925 $$->type->qualifier = $1;
926 if (!$$->type->qualifier.push_to_global(& @1, state)) {
930 | parameter_qualifier parameter_type_specifier
932 void *ctx = state->linalloc;
933 $$ = new(ctx) ast_parameter_declarator();
934 $$->set_location(@2);
935 $$->type = new(ctx) ast_fully_specified_type();
936 $$->type->set_location_range(@1, @2);
937 $$->type->qualifier = $1;
938 if (!$$->type->qualifier.push_to_global(& @1, state)) {
941 $$->type->specifier = $2;
948 memset(& $$, 0, sizeof($$));
950 | CONST_TOK parameter_qualifier
952 if ($2.flags.q.constant)
953 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
956 $$.flags.q.constant = 1;
958 | PRECISE parameter_qualifier
960 if ($2.flags.q.precise)
961 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
964 $$.flags.q.precise = 1;
966 | parameter_direction_qualifier parameter_qualifier
968 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
969 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
971 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
972 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
976 $$.merge_qualifier(&@1, state, $2, false);
978 | precision_qualifier parameter_qualifier
980 if ($2.precision != ast_precision_none)
981 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
983 if (!state->has_420pack_or_es31() &&
985 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
990 | memory_qualifier parameter_qualifier
993 $$.merge_qualifier(&@1, state, $2, false);
996 parameter_direction_qualifier:
999 memset(& $$, 0, sizeof($$));
1004 memset(& $$, 0, sizeof($$));
1009 memset(& $$, 0, sizeof($$));
1015 parameter_type_specifier:
1019 init_declarator_list:
1021 | init_declarator_list ',' any_identifier
1023 void *ctx = state->linalloc;
1024 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1025 decl->set_location(@3);
1028 $$->declarations.push_tail(&decl->link);
1029 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1031 | init_declarator_list ',' any_identifier array_specifier
1033 void *ctx = state->linalloc;
1034 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1035 decl->set_location_range(@3, @4);
1038 $$->declarations.push_tail(&decl->link);
1039 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1041 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1043 void *ctx = state->linalloc;
1044 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1045 decl->set_location_range(@3, @4);
1048 $$->declarations.push_tail(&decl->link);
1049 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1051 | init_declarator_list ',' any_identifier '=' initializer
1053 void *ctx = state->linalloc;
1054 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1055 decl->set_location(@3);
1058 $$->declarations.push_tail(&decl->link);
1059 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1063 // Grammar Note: No 'enum', or 'typedef'.
1065 fully_specified_type
1067 void *ctx = state->linalloc;
1068 /* Empty declaration list is valid. */
1069 $$ = new(ctx) ast_declarator_list($1);
1070 $$->set_location(@1);
1072 | fully_specified_type any_identifier
1074 void *ctx = state->linalloc;
1075 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1076 decl->set_location(@2);
1078 $$ = new(ctx) ast_declarator_list($1);
1079 $$->set_location_range(@1, @2);
1080 $$->declarations.push_tail(&decl->link);
1081 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1083 | fully_specified_type any_identifier array_specifier
1085 void *ctx = state->linalloc;
1086 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1087 decl->set_location_range(@2, @3);
1089 $$ = new(ctx) ast_declarator_list($1);
1090 $$->set_location_range(@1, @3);
1091 $$->declarations.push_tail(&decl->link);
1092 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1094 | fully_specified_type any_identifier array_specifier '=' initializer
1096 void *ctx = state->linalloc;
1097 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1098 decl->set_location_range(@2, @3);
1100 $$ = new(ctx) ast_declarator_list($1);
1101 $$->set_location_range(@1, @3);
1102 $$->declarations.push_tail(&decl->link);
1103 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1105 | fully_specified_type any_identifier '=' initializer
1107 void *ctx = state->linalloc;
1108 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1109 decl->set_location(@2);
1111 $$ = new(ctx) ast_declarator_list($1);
1112 $$->set_location_range(@1, @2);
1113 $$->declarations.push_tail(&decl->link);
1114 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1116 | INVARIANT variable_identifier
1118 void *ctx = state->linalloc;
1119 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1120 decl->set_location(@2);
1122 $$ = new(ctx) ast_declarator_list(NULL);
1123 $$->set_location_range(@1, @2);
1124 $$->invariant = true;
1126 $$->declarations.push_tail(&decl->link);
1128 | PRECISE variable_identifier
1130 void *ctx = state->linalloc;
1131 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1132 decl->set_location(@2);
1134 $$ = new(ctx) ast_declarator_list(NULL);
1135 $$->set_location_range(@1, @2);
1138 $$->declarations.push_tail(&decl->link);
1142 fully_specified_type:
1145 void *ctx = state->linalloc;
1146 $$ = new(ctx) ast_fully_specified_type();
1147 $$->set_location(@1);
1150 | type_qualifier type_specifier
1152 void *ctx = state->linalloc;
1153 $$ = new(ctx) ast_fully_specified_type();
1154 $$->set_location_range(@1, @2);
1156 if (!$$->qualifier.push_to_global(& @1, state)) {
1160 if ($$->specifier->structure != NULL &&
1161 $$->specifier->structure->is_declaration) {
1162 $$->specifier->structure->layout = &$$->qualifier;
1168 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1174 layout_qualifier_id_list:
1176 | layout_qualifier_id_list ',' layout_qualifier_id
1179 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1185 layout_qualifier_id:
1188 memset(& $$, 0, sizeof($$));
1190 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1191 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1192 state->is_version(150, 0))) {
1193 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1194 $$.flags.q.origin_upper_left = 1;
1195 } else if (match_layout_qualifier($1, "pixel_center_integer",
1197 $$.flags.q.pixel_center_integer = 1;
1200 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1201 _mesa_glsl_warning(& @1, state,
1202 "GL_ARB_fragment_coord_conventions layout "
1203 "identifier `%s' used", $1);
1207 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1209 (state->AMD_conservative_depth_enable ||
1210 state->ARB_conservative_depth_enable ||
1211 state->is_version(420, 0))) {
1212 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1213 $$.flags.q.depth_any = 1;
1214 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1215 $$.flags.q.depth_greater = 1;
1216 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1217 $$.flags.q.depth_less = 1;
1218 } else if (match_layout_qualifier($1, "depth_unchanged",
1220 $$.flags.q.depth_unchanged = 1;
1223 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1224 _mesa_glsl_warning(& @1, state,
1225 "GL_AMD_conservative_depth "
1226 "layout qualifier `%s' is used", $1);
1228 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1229 _mesa_glsl_warning(& @1, state,
1230 "GL_ARB_conservative_depth "
1231 "layout qualifier `%s' is used", $1);
1235 /* See also interface_block_layout_qualifier. */
1236 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1237 if (match_layout_qualifier($1, "std140", state) == 0) {
1238 $$.flags.q.std140 = 1;
1239 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1240 $$.flags.q.shared = 1;
1241 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1242 $$.flags.q.std430 = 1;
1243 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1244 $$.flags.q.column_major = 1;
1245 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1246 * below in the interface_block_layout_qualifier rule.
1248 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1251 * Also, this takes care of alternate capitalizations of
1252 * "row_major" (which is necessary because layout qualifiers
1253 * are case-insensitive in desktop GLSL).
1255 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1256 $$.flags.q.row_major = 1;
1257 /* "packed" is a reserved word in GLSL, and its token is
1258 * parsed below in the interface_block_layout_qualifier rule.
1259 * However, we must take care of alternate capitalizations of
1260 * "packed", because layout qualifiers are case-insensitive
1263 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1264 $$.flags.q.packed = 1;
1267 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1268 _mesa_glsl_warning(& @1, state,
1269 "#version 140 / GL_ARB_uniform_buffer_object "
1270 "layout qualifier `%s' is used", $1);
1274 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1276 static const struct {
1280 { "points", GL_POINTS },
1281 { "lines", GL_LINES },
1282 { "lines_adjacency", GL_LINES_ADJACENCY },
1283 { "line_strip", GL_LINE_STRIP },
1284 { "triangles", GL_TRIANGLES },
1285 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1286 { "triangle_strip", GL_TRIANGLE_STRIP },
1288 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1289 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1290 $$.flags.q.prim_type = 1;
1291 $$.prim_type = map[i].e;
1296 if ($$.flags.i && !state->has_geometry_shader() &&
1297 !state->has_tessellation_shader()) {
1298 _mesa_glsl_error(& @1, state, "#version 150 layout "
1299 "qualifier `%s' used", $1);
1303 /* Layout qualifiers for ARB_shader_image_load_store. */
1304 if (state->ARB_shader_image_load_store_enable ||
1305 state->is_version(420, 310)) {
1307 static const struct {
1310 glsl_base_type base_type;
1311 /** Minimum desktop GLSL version required for the image
1312 * format. Use 130 if already present in the original
1315 unsigned required_glsl;
1316 /** Minimum GLSL ES version required for the image format. */
1317 unsigned required_essl;
1318 /* NV_image_formats */
1319 bool nv_image_formats;
1321 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1322 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1323 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1324 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1325 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1326 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1327 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1328 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1329 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1330 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1331 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1332 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1333 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1334 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1335 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1336 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1337 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1338 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1339 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1340 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1341 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1342 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1343 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1344 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1345 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1346 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1347 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
1348 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1349 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1350 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
1351 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1352 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
1353 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1354 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1355 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1356 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1357 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1358 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1359 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1362 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1363 if ((state->is_version(map[i].required_glsl,
1364 map[i].required_essl) ||
1365 (state->NV_image_formats_enable &&
1366 map[i].nv_image_formats)) &&
1367 match_layout_qualifier($1, map[i].name, state) == 0) {
1368 $$.flags.q.explicit_image_format = 1;
1369 $$.image_format = map[i].format;
1370 $$.image_base_type = map[i].base_type;
1377 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1378 /* From section 4.4.1.3 of the GLSL 4.50 specification
1379 * (Fragment Shader Inputs):
1381 * "Fragment shaders also allow the following layout
1382 * qualifier on in only (not with variable declarations)
1383 * layout-qualifier-id
1384 * early_fragment_tests
1387 if (state->stage != MESA_SHADER_FRAGMENT) {
1388 _mesa_glsl_error(& @1, state,
1389 "early_fragment_tests layout qualifier only "
1390 "valid in fragment shaders");
1393 $$.flags.q.early_fragment_tests = 1;
1397 match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1398 if (state->stage != MESA_SHADER_FRAGMENT) {
1399 _mesa_glsl_error(& @1, state,
1400 "post_depth_coverage layout qualifier only "
1401 "valid in fragment shaders");
1404 if (state->ARB_post_depth_coverage_enable) {
1405 $$.flags.q.post_depth_coverage = 1;
1407 _mesa_glsl_error(& @1, state,
1408 "post_depth_coverage layout qualifier present, "
1409 "but the GL_ARB_post_depth_coverage extension "
1415 /* Layout qualifiers for tessellation evaluation shaders. */
1417 static const struct {
1421 /* triangles already parsed by gs-specific code */
1422 { "quads", GL_QUADS },
1423 { "isolines", GL_ISOLINES },
1425 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1426 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1427 $$.flags.q.prim_type = 1;
1428 $$.prim_type = map[i].e;
1433 if ($$.flags.i && !state->has_tessellation_shader()) {
1434 _mesa_glsl_error(& @1, state,
1435 "primitive mode qualifier `%s' requires "
1436 "GLSL 4.00 or ARB_tessellation_shader", $1);
1440 static const struct {
1444 { "equal_spacing", GL_EQUAL },
1445 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1446 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1448 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1449 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1450 $$.flags.q.vertex_spacing = 1;
1451 $$.vertex_spacing = map[i].e;
1456 if ($$.flags.i && !state->has_tessellation_shader()) {
1457 _mesa_glsl_error(& @1, state,
1458 "vertex spacing qualifier `%s' requires "
1459 "GLSL 4.00 or ARB_tessellation_shader", $1);
1463 if (match_layout_qualifier($1, "cw", state) == 0) {
1464 $$.flags.q.ordering = 1;
1465 $$.ordering = GL_CW;
1466 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1467 $$.flags.q.ordering = 1;
1468 $$.ordering = GL_CCW;
1471 if ($$.flags.i && !state->has_tessellation_shader()) {
1472 _mesa_glsl_error(& @1, state,
1473 "ordering qualifier `%s' requires "
1474 "GLSL 4.00 or ARB_tessellation_shader", $1);
1478 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1479 $$.flags.q.point_mode = 1;
1480 $$.point_mode = true;
1483 if ($$.flags.i && !state->has_tessellation_shader()) {
1484 _mesa_glsl_error(& @1, state,
1485 "qualifier `point_mode' requires "
1486 "GLSL 4.00 or ARB_tessellation_shader");
1491 static const struct {
1495 { "blend_support_multiply", BLEND_MULTIPLY },
1496 { "blend_support_screen", BLEND_SCREEN },
1497 { "blend_support_overlay", BLEND_OVERLAY },
1498 { "blend_support_darken", BLEND_DARKEN },
1499 { "blend_support_lighten", BLEND_LIGHTEN },
1500 { "blend_support_colordodge", BLEND_COLORDODGE },
1501 { "blend_support_colorburn", BLEND_COLORBURN },
1502 { "blend_support_hardlight", BLEND_HARDLIGHT },
1503 { "blend_support_softlight", BLEND_SOFTLIGHT },
1504 { "blend_support_difference", BLEND_DIFFERENCE },
1505 { "blend_support_exclusion", BLEND_EXCLUSION },
1506 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1507 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1508 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1509 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1510 { "blend_support_all_equations", BLEND_ALL },
1512 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1513 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1514 $$.flags.q.blend_support = 1;
1515 state->fs_blend_support |= map[i].mask;
1521 !state->KHR_blend_equation_advanced_enable &&
1522 !state->is_version(0, 320)) {
1523 _mesa_glsl_error(& @1, state,
1524 "advanced blending layout qualifiers require "
1525 "ESSL 3.20 or KHR_blend_equation_advanced");
1528 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1529 _mesa_glsl_error(& @1, state,
1530 "advanced blending layout qualifiers only "
1531 "valid in fragment shaders");
1535 /* Layout qualifiers for ARB_compute_variable_group_size. */
1537 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1538 $$.flags.q.local_size_variable = 1;
1541 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1542 _mesa_glsl_error(& @1, state,
1543 "qualifier `local_size_variable` requires "
1544 "ARB_compute_variable_group_size");
1549 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1554 | any_identifier '=' constant_expression
1556 memset(& $$, 0, sizeof($$));
1557 void *ctx = state->linalloc;
1559 if ($3->oper != ast_int_constant &&
1560 $3->oper != ast_uint_constant &&
1561 !state->has_enhanced_layouts()) {
1562 _mesa_glsl_error(& @1, state,
1563 "compile-time constant expressions require "
1564 "GLSL 4.40 or ARB_enhanced_layouts");
1567 if (match_layout_qualifier("align", $1, state) == 0) {
1568 if (!state->has_enhanced_layouts()) {
1569 _mesa_glsl_error(& @1, state,
1570 "align qualifier requires "
1571 "GLSL 4.40 or ARB_enhanced_layouts");
1573 $$.flags.q.explicit_align = 1;
1578 if (match_layout_qualifier("location", $1, state) == 0) {
1579 $$.flags.q.explicit_location = 1;
1581 if ($$.flags.q.attribute == 1 &&
1582 state->ARB_explicit_attrib_location_warn) {
1583 _mesa_glsl_warning(& @1, state,
1584 "GL_ARB_explicit_attrib_location layout "
1585 "identifier `%s' used", $1);
1590 if (match_layout_qualifier("component", $1, state) == 0) {
1591 if (!state->has_enhanced_layouts()) {
1592 _mesa_glsl_error(& @1, state,
1593 "component qualifier requires "
1594 "GLSL 4.40 or ARB_enhanced_layouts");
1596 $$.flags.q.explicit_component = 1;
1601 if (match_layout_qualifier("index", $1, state) == 0) {
1602 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1603 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1607 $$.flags.q.explicit_index = 1;
1611 if ((state->has_420pack_or_es31() ||
1612 state->has_atomic_counters() ||
1613 state->has_shader_storage_buffer_objects()) &&
1614 match_layout_qualifier("binding", $1, state) == 0) {
1615 $$.flags.q.explicit_binding = 1;
1619 if ((state->has_atomic_counters() ||
1620 state->has_enhanced_layouts()) &&
1621 match_layout_qualifier("offset", $1, state) == 0) {
1622 $$.flags.q.explicit_offset = 1;
1626 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1627 $$.flags.q.max_vertices = 1;
1628 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1629 if (!state->has_geometry_shader()) {
1630 _mesa_glsl_error(& @3, state,
1631 "#version 150 max_vertices qualifier "
1636 if (state->stage == MESA_SHADER_GEOMETRY) {
1637 if (match_layout_qualifier("stream", $1, state) == 0 &&
1638 state->check_explicit_attrib_stream_allowed(& @3)) {
1639 $$.flags.q.stream = 1;
1640 $$.flags.q.explicit_stream = 1;
1645 if (state->has_enhanced_layouts()) {
1646 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1647 $$.flags.q.xfb_buffer = 1;
1648 $$.flags.q.explicit_xfb_buffer = 1;
1652 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1653 $$.flags.q.explicit_xfb_offset = 1;
1657 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1658 $$.flags.q.xfb_stride = 1;
1659 $$.flags.q.explicit_xfb_stride = 1;
1664 static const char * const local_size_qualifiers[3] = {
1669 for (int i = 0; i < 3; i++) {
1670 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1672 if (!state->has_compute_shader()) {
1673 _mesa_glsl_error(& @3, state,
1674 "%s qualifier requires GLSL 4.30 or "
1675 "GLSL ES 3.10 or ARB_compute_shader",
1676 local_size_qualifiers[i]);
1679 $$.flags.q.local_size |= (1 << i);
1680 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1686 if (match_layout_qualifier("invocations", $1, state) == 0) {
1687 $$.flags.q.invocations = 1;
1688 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1689 if (!state->is_version(400, 320) &&
1690 !state->ARB_gpu_shader5_enable &&
1691 !state->OES_geometry_shader_enable &&
1692 !state->EXT_geometry_shader_enable) {
1693 _mesa_glsl_error(& @3, state,
1694 "GL_ARB_gpu_shader5 invocations "
1695 "qualifier specified", $3);
1699 /* Layout qualifiers for tessellation control shaders. */
1700 if (match_layout_qualifier("vertices", $1, state) == 0) {
1701 $$.flags.q.vertices = 1;
1702 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1703 if (!state->has_tessellation_shader()) {
1704 _mesa_glsl_error(& @1, state,
1705 "vertices qualifier requires GLSL 4.00 or "
1706 "ARB_tessellation_shader");
1710 /* If the identifier didn't match any known layout identifiers,
1714 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1719 | interface_block_layout_qualifier
1722 /* Layout qualifiers for ARB_uniform_buffer_object. */
1723 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1724 _mesa_glsl_error(& @1, state,
1725 "#version 140 / GL_ARB_uniform_buffer_object "
1726 "layout qualifier `%s' is used", $1);
1727 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1728 _mesa_glsl_warning(& @1, state,
1729 "#version 140 / GL_ARB_uniform_buffer_object "
1730 "layout qualifier `%s' is used", $1);
1735 /* This is a separate language rule because we parse these as tokens
1736 * (due to them being reserved keywords) instead of identifiers like
1737 * most qualifiers. See the any_identifier path of
1738 * layout_qualifier_id for the others.
1740 * Note that since layout qualifiers are case-insensitive in desktop
1741 * GLSL, all of these qualifiers need to be handled as identifiers as
1742 * well (by the any_identifier path of layout_qualifier_id).
1744 interface_block_layout_qualifier:
1747 memset(& $$, 0, sizeof($$));
1748 $$.flags.q.row_major = 1;
1752 memset(& $$, 0, sizeof($$));
1753 $$.flags.q.packed = 1;
1757 memset(& $$, 0, sizeof($$));
1758 $$.flags.q.shared = 1;
1762 subroutine_qualifier:
1765 memset(& $$, 0, sizeof($$));
1766 $$.flags.q.subroutine = 1;
1768 | SUBROUTINE '(' subroutine_type_list ')'
1770 memset(& $$, 0, sizeof($$));
1771 $$.flags.q.subroutine_def = 1;
1772 $$.subroutine_list = $3;
1776 subroutine_type_list:
1779 void *ctx = state->linalloc;
1780 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1781 decl->set_location(@1);
1783 $$ = new(ctx) ast_subroutine_list();
1784 $$->declarations.push_tail(&decl->link);
1786 | subroutine_type_list ',' any_identifier
1788 void *ctx = state->linalloc;
1789 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1790 decl->set_location(@3);
1793 $$->declarations.push_tail(&decl->link);
1797 interpolation_qualifier:
1800 memset(& $$, 0, sizeof($$));
1801 $$.flags.q.smooth = 1;
1805 memset(& $$, 0, sizeof($$));
1806 $$.flags.q.flat = 1;
1810 memset(& $$, 0, sizeof($$));
1811 $$.flags.q.noperspective = 1;
1816 /* Single qualifiers */
1819 memset(& $$, 0, sizeof($$));
1820 $$.flags.q.invariant = 1;
1824 memset(& $$, 0, sizeof($$));
1825 $$.flags.q.precise = 1;
1827 | auxiliary_storage_qualifier
1829 | interpolation_qualifier
1832 | subroutine_qualifier
1833 | precision_qualifier
1835 memset(&$$, 0, sizeof($$));
1839 /* Multiple qualifiers:
1840 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1841 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1843 * invariant interpolation auxiliary storage precision ...or...
1844 * layout storage precision
1846 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1847 * side don't contain any that must appear on the left hand side.
1848 * For example, when processing a storage qualifier, we check that there are
1849 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1851 | PRECISE type_qualifier
1853 if ($2.flags.q.precise)
1854 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1857 $$.flags.q.precise = 1;
1859 | INVARIANT type_qualifier
1861 if ($2.flags.q.invariant)
1862 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1864 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1865 _mesa_glsl_error(&@1, state,
1866 "\"invariant\" must come after \"precise\"");
1869 $$.flags.q.invariant = 1;
1871 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1873 * "Only variables output from a shader can be candidates for invariance.
1874 * This includes user-defined output variables and the built-in output
1875 * variables. As only outputs can be declared as invariant, an invariant
1876 * output from one shader stage will still match an input of a subsequent
1877 * stage without the input being declared as invariant."
1879 * On the desktop side, this text first appears in GLSL 4.30.
1881 if (state->is_version(430, 300) && $$.flags.q.in)
1882 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1884 | interpolation_qualifier type_qualifier
1886 /* Section 4.3 of the GLSL 1.40 specification states:
1887 * "...qualified with one of these interpolation qualifiers"
1889 * GLSL 1.30 claims to allow "one or more", but insists that:
1890 * "These interpolation qualifiers may only precede the qualifiers in,
1891 * centroid in, out, or centroid out in a declaration."
1893 * ...which means that e.g. smooth can't precede smooth, so there can be
1894 * only one after all, and the 1.40 text is a clarification, not a change.
1896 if ($2.has_interpolation())
1897 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1899 if (!state->has_420pack_or_es31() &&
1900 ($2.flags.q.precise || $2.flags.q.invariant)) {
1901 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1902 "after \"precise\" or \"invariant\"");
1906 $$.merge_qualifier(&@1, state, $2, false);
1908 | layout_qualifier type_qualifier
1910 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1911 * appear no later than auxiliary storage qualifiers. There is no
1912 * particularly clear spec language mandating this, but in all examples
1913 * the layout qualifier precedes the storage qualifier.
1915 * We allow combinations of layout with interpolation, invariant or
1916 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1917 * There is no clear spec guidance on this either.
1920 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1922 | subroutine_qualifier type_qualifier
1925 $$.merge_qualifier(&@1, state, $2, false);
1927 | auxiliary_storage_qualifier type_qualifier
1929 if ($2.has_auxiliary_storage()) {
1930 _mesa_glsl_error(&@1, state,
1931 "duplicate auxiliary storage qualifier (centroid or sample)");
1934 if (!state->has_420pack_or_es31() &&
1935 ($2.flags.q.precise || $2.flags.q.invariant ||
1936 $2.has_interpolation() || $2.has_layout())) {
1937 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1938 "just before storage qualifiers");
1941 $$.merge_qualifier(&@1, state, $2, false);
1943 | storage_qualifier type_qualifier
1945 /* Section 4.3 of the GLSL 1.20 specification states:
1946 * "Variable declarations may have a storage qualifier specified..."
1947 * 1.30 clarifies this to "may have one storage qualifier".
1949 if ($2.has_storage())
1950 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1952 if (!state->has_420pack_or_es31() &&
1953 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1954 $2.has_layout() || $2.has_auxiliary_storage())) {
1955 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1956 "precise, invariant, interpolation, layout and auxiliary "
1957 "storage qualifiers");
1961 $$.merge_qualifier(&@1, state, $2, false);
1963 | precision_qualifier type_qualifier
1965 if ($2.precision != ast_precision_none)
1966 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1968 if (!(state->has_420pack_or_es31()) &&
1970 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1975 | memory_qualifier type_qualifier
1978 $$.merge_qualifier(&@1, state, $2, false);
1982 auxiliary_storage_qualifier:
1985 memset(& $$, 0, sizeof($$));
1986 $$.flags.q.centroid = 1;
1990 memset(& $$, 0, sizeof($$));
1991 $$.flags.q.sample = 1;
1995 memset(& $$, 0, sizeof($$));
1996 $$.flags.q.patch = 1;
2002 memset(& $$, 0, sizeof($$));
2003 $$.flags.q.constant = 1;
2007 memset(& $$, 0, sizeof($$));
2008 $$.flags.q.attribute = 1;
2012 memset(& $$, 0, sizeof($$));
2013 $$.flags.q.varying = 1;
2017 memset(& $$, 0, sizeof($$));
2022 memset(& $$, 0, sizeof($$));
2025 if (state->stage == MESA_SHADER_GEOMETRY &&
2026 state->has_explicit_attrib_stream()) {
2027 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2030 * "If the block or variable is declared with the stream
2031 * identifier, it is associated with the specified stream;
2032 * otherwise, it is associated with the current default stream."
2034 $$.flags.q.stream = 1;
2035 $$.flags.q.explicit_stream = 0;
2036 $$.stream = state->out_qualifier->stream;
2039 if (state->has_enhanced_layouts()) {
2040 $$.flags.q.xfb_buffer = 1;
2041 $$.flags.q.explicit_xfb_buffer = 0;
2042 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2047 memset(& $$, 0, sizeof($$));
2051 if (!state->has_framebuffer_fetch() ||
2052 !state->is_version(130, 300) ||
2053 state->stage != MESA_SHADER_FRAGMENT)
2054 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2055 "declared as both input and output");
2059 memset(& $$, 0, sizeof($$));
2060 $$.flags.q.uniform = 1;
2064 memset(& $$, 0, sizeof($$));
2065 $$.flags.q.buffer = 1;
2069 memset(& $$, 0, sizeof($$));
2070 $$.flags.q.shared_storage = 1;
2077 memset(& $$, 0, sizeof($$));
2078 $$.flags.q.coherent = 1;
2082 memset(& $$, 0, sizeof($$));
2083 $$.flags.q._volatile = 1;
2087 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2088 memset(& $$, 0, sizeof($$));
2089 $$.flags.q.restrict_flag = 1;
2093 memset(& $$, 0, sizeof($$));
2094 $$.flags.q.read_only = 1;
2098 memset(& $$, 0, sizeof($$));
2099 $$.flags.q.write_only = 1;
2106 void *ctx = state->linalloc;
2107 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2108 ast_unsized_array_dim, NULL,
2110 $$->set_location_range(@1, @2);
2112 | '[' constant_expression ']'
2114 void *ctx = state->linalloc;
2115 $$ = new(ctx) ast_array_specifier(@1, $2);
2116 $$->set_location_range(@1, @3);
2118 | array_specifier '[' ']'
2120 void *ctx = state->linalloc;
2123 if (state->check_arrays_of_arrays_allowed(& @1)) {
2124 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2128 | array_specifier '[' constant_expression ']'
2132 if (state->check_arrays_of_arrays_allowed(& @1)) {
2133 $$->add_dimension($3);
2139 type_specifier_nonarray
2140 | type_specifier_nonarray array_specifier
2143 $$->array_specifier = $2;
2147 type_specifier_nonarray:
2148 basic_type_specifier_nonarray
2150 void *ctx = state->linalloc;
2151 $$ = new(ctx) ast_type_specifier($1);
2152 $$->set_location(@1);
2156 void *ctx = state->linalloc;
2157 $$ = new(ctx) ast_type_specifier($1);
2158 $$->set_location(@1);
2162 void *ctx = state->linalloc;
2163 $$ = new(ctx) ast_type_specifier($1);
2164 $$->set_location(@1);
2168 basic_type_specifier_nonarray:
2169 VOID_TOK { $$ = "void"; }
2170 | FLOAT_TOK { $$ = "float"; }
2171 | DOUBLE_TOK { $$ = "double"; }
2172 | INT_TOK { $$ = "int"; }
2173 | UINT_TOK { $$ = "uint"; }
2174 | BOOL_TOK { $$ = "bool"; }
2175 | VEC2 { $$ = "vec2"; }
2176 | VEC3 { $$ = "vec3"; }
2177 | VEC4 { $$ = "vec4"; }
2178 | BVEC2 { $$ = "bvec2"; }
2179 | BVEC3 { $$ = "bvec3"; }
2180 | BVEC4 { $$ = "bvec4"; }
2181 | IVEC2 { $$ = "ivec2"; }
2182 | IVEC3 { $$ = "ivec3"; }
2183 | IVEC4 { $$ = "ivec4"; }
2184 | UVEC2 { $$ = "uvec2"; }
2185 | UVEC3 { $$ = "uvec3"; }
2186 | UVEC4 { $$ = "uvec4"; }
2187 | DVEC2 { $$ = "dvec2"; }
2188 | DVEC3 { $$ = "dvec3"; }
2189 | DVEC4 { $$ = "dvec4"; }
2190 | MAT2X2 { $$ = "mat2"; }
2191 | MAT2X3 { $$ = "mat2x3"; }
2192 | MAT2X4 { $$ = "mat2x4"; }
2193 | MAT3X2 { $$ = "mat3x2"; }
2194 | MAT3X3 { $$ = "mat3"; }
2195 | MAT3X4 { $$ = "mat3x4"; }
2196 | MAT4X2 { $$ = "mat4x2"; }
2197 | MAT4X3 { $$ = "mat4x3"; }
2198 | MAT4X4 { $$ = "mat4"; }
2199 | DMAT2X2 { $$ = "dmat2"; }
2200 | DMAT2X3 { $$ = "dmat2x3"; }
2201 | DMAT2X4 { $$ = "dmat2x4"; }
2202 | DMAT3X2 { $$ = "dmat3x2"; }
2203 | DMAT3X3 { $$ = "dmat3"; }
2204 | DMAT3X4 { $$ = "dmat3x4"; }
2205 | DMAT4X2 { $$ = "dmat4x2"; }
2206 | DMAT4X3 { $$ = "dmat4x3"; }
2207 | DMAT4X4 { $$ = "dmat4"; }
2208 | SAMPLER1D { $$ = "sampler1D"; }
2209 | SAMPLER2D { $$ = "sampler2D"; }
2210 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2211 | SAMPLER3D { $$ = "sampler3D"; }
2212 | SAMPLERCUBE { $$ = "samplerCube"; }
2213 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2214 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2215 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2216 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2217 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2218 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2219 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2220 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2221 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2222 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2223 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2224 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2225 | ISAMPLER1D { $$ = "isampler1D"; }
2226 | ISAMPLER2D { $$ = "isampler2D"; }
2227 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2228 | ISAMPLER3D { $$ = "isampler3D"; }
2229 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2230 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2231 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2232 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2233 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2234 | USAMPLER1D { $$ = "usampler1D"; }
2235 | USAMPLER2D { $$ = "usampler2D"; }
2236 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2237 | USAMPLER3D { $$ = "usampler3D"; }
2238 | USAMPLERCUBE { $$ = "usamplerCube"; }
2239 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2240 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2241 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2242 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2243 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2244 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2245 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2246 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2247 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2248 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2249 | IMAGE1D { $$ = "image1D"; }
2250 | IMAGE2D { $$ = "image2D"; }
2251 | IMAGE3D { $$ = "image3D"; }
2252 | IMAGE2DRECT { $$ = "image2DRect"; }
2253 | IMAGECUBE { $$ = "imageCube"; }
2254 | IMAGEBUFFER { $$ = "imageBuffer"; }
2255 | IMAGE1DARRAY { $$ = "image1DArray"; }
2256 | IMAGE2DARRAY { $$ = "image2DArray"; }
2257 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2258 | IMAGE2DMS { $$ = "image2DMS"; }
2259 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2260 | IIMAGE1D { $$ = "iimage1D"; }
2261 | IIMAGE2D { $$ = "iimage2D"; }
2262 | IIMAGE3D { $$ = "iimage3D"; }
2263 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2264 | IIMAGECUBE { $$ = "iimageCube"; }
2265 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2266 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2267 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2268 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2269 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2270 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2271 | UIMAGE1D { $$ = "uimage1D"; }
2272 | UIMAGE2D { $$ = "uimage2D"; }
2273 | UIMAGE3D { $$ = "uimage3D"; }
2274 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2275 | UIMAGECUBE { $$ = "uimageCube"; }
2276 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2277 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2278 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2279 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2280 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2281 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2282 | ATOMIC_UINT { $$ = "atomic_uint"; }
2285 precision_qualifier:
2288 state->check_precision_qualifiers_allowed(&@1);
2289 $$ = ast_precision_high;
2293 state->check_precision_qualifiers_allowed(&@1);
2294 $$ = ast_precision_medium;
2298 state->check_precision_qualifiers_allowed(&@1);
2299 $$ = ast_precision_low;
2304 STRUCT any_identifier '{' struct_declaration_list '}'
2306 void *ctx = state->linalloc;
2307 $$ = new(ctx) ast_struct_specifier(ctx, $2, $4);
2308 $$->set_location_range(@2, @5);
2309 state->symbols->add_type($2, glsl_type::void_type);
2311 | STRUCT '{' struct_declaration_list '}'
2313 void *ctx = state->linalloc;
2314 $$ = new(ctx) ast_struct_specifier(ctx, NULL, $3);
2315 $$->set_location_range(@2, @4);
2319 struct_declaration_list:
2323 $1->link.self_link();
2325 | struct_declaration_list struct_declaration
2328 $$->link.insert_before(& $2->link);
2333 fully_specified_type struct_declarator_list ';'
2335 void *ctx = state->linalloc;
2336 ast_fully_specified_type *const type = $1;
2337 type->set_location(@1);
2339 if (type->qualifier.flags.i != 0)
2340 _mesa_glsl_error(&@1, state,
2341 "only precision qualifiers may be applied to "
2342 "structure members");
2344 $$ = new(ctx) ast_declarator_list(type);
2345 $$->set_location(@2);
2347 $$->declarations.push_degenerate_list_at_head(& $2->link);
2351 struct_declarator_list:
2355 $1->link.self_link();
2357 | struct_declarator_list ',' struct_declarator
2360 $$->link.insert_before(& $3->link);
2367 void *ctx = state->linalloc;
2368 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2369 $$->set_location(@1);
2371 | any_identifier array_specifier
2373 void *ctx = state->linalloc;
2374 $$ = new(ctx) ast_declaration($1, $2, NULL);
2375 $$->set_location_range(@1, @2);
2380 assignment_expression
2381 | '{' initializer_list '}'
2385 | '{' initializer_list ',' '}'
2394 void *ctx = state->linalloc;
2395 $$ = new(ctx) ast_aggregate_initializer();
2396 $$->set_location(@1);
2397 $$->expressions.push_tail(& $1->link);
2399 | initializer_list ',' initializer
2401 $1->expressions.push_tail(& $3->link);
2405 declaration_statement:
2409 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2412 compound_statement { $$ = (ast_node *) $1; }
2417 declaration_statement
2418 | expression_statement
2419 | selection_statement
2421 | iteration_statement
2428 void *ctx = state->linalloc;
2429 $$ = new(ctx) ast_compound_statement(true, NULL);
2430 $$->set_location_range(@1, @2);
2434 state->symbols->push_scope();
2438 void *ctx = state->linalloc;
2439 $$ = new(ctx) ast_compound_statement(true, $3);
2440 $$->set_location_range(@1, @4);
2441 state->symbols->pop_scope();
2445 statement_no_new_scope:
2446 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2450 compound_statement_no_new_scope:
2453 void *ctx = state->linalloc;
2454 $$ = new(ctx) ast_compound_statement(false, NULL);
2455 $$->set_location_range(@1, @2);
2457 | '{' statement_list '}'
2459 void *ctx = state->linalloc;
2460 $$ = new(ctx) ast_compound_statement(false, $2);
2461 $$->set_location_range(@1, @3);
2469 _mesa_glsl_error(& @1, state, "<nil> statement");
2474 $$->link.self_link();
2476 | statement_list statement
2479 _mesa_glsl_error(& @2, state, "<nil> statement");
2483 $$->link.insert_before(& $2->link);
2487 expression_statement:
2490 void *ctx = state->linalloc;
2491 $$ = new(ctx) ast_expression_statement(NULL);
2492 $$->set_location(@1);
2496 void *ctx = state->linalloc;
2497 $$ = new(ctx) ast_expression_statement($1);
2498 $$->set_location(@1);
2502 selection_statement:
2503 IF '(' expression ')' selection_rest_statement
2505 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2507 $$->set_location_range(@1, @5);
2511 selection_rest_statement:
2512 statement ELSE statement
2514 $$.then_statement = $1;
2515 $$.else_statement = $3;
2517 | statement %prec THEN
2519 $$.then_statement = $1;
2520 $$.else_statement = NULL;
2527 $$ = (ast_node *) $1;
2529 | fully_specified_type any_identifier '=' initializer
2531 void *ctx = state->linalloc;
2532 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2533 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2534 decl->set_location_range(@2, @4);
2535 declarator->set_location(@1);
2537 declarator->declarations.push_tail(&decl->link);
2543 * switch_statement grammar is based on the syntax described in the body
2544 * of the GLSL spec, not in it's appendix!!!
2547 SWITCH '(' expression ')' switch_body
2549 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2550 $$->set_location_range(@1, @5);
2557 $$ = new(state->linalloc) ast_switch_body(NULL);
2558 $$->set_location_range(@1, @2);
2560 | '{' case_statement_list '}'
2562 $$ = new(state->linalloc) ast_switch_body($2);
2563 $$->set_location_range(@1, @3);
2570 $$ = new(state->linalloc) ast_case_label($2);
2571 $$->set_location(@2);
2575 $$ = new(state->linalloc) ast_case_label(NULL);
2576 $$->set_location(@2);
2583 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2585 labels->labels.push_tail(& $1->link);
2587 $$->set_location(@1);
2589 | case_label_list case_label
2592 $$->labels.push_tail(& $2->link);
2597 case_label_list statement
2599 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2600 stmts->set_location(@2);
2602 stmts->stmts.push_tail(& $2->link);
2605 | case_statement statement
2608 $$->stmts.push_tail(& $2->link);
2612 case_statement_list:
2615 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2616 cases->set_location(@1);
2618 cases->cases.push_tail(& $1->link);
2621 | case_statement_list case_statement
2624 $$->cases.push_tail(& $2->link);
2628 iteration_statement:
2629 WHILE '(' condition ')' statement_no_new_scope
2631 void *ctx = state->linalloc;
2632 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2633 NULL, $3, NULL, $5);
2634 $$->set_location_range(@1, @4);
2636 | DO statement WHILE '(' expression ')' ';'
2638 void *ctx = state->linalloc;
2639 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2640 NULL, $5, NULL, $2);
2641 $$->set_location_range(@1, @6);
2643 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2645 void *ctx = state->linalloc;
2646 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2647 $3, $4.cond, $4.rest, $6);
2648 $$->set_location_range(@1, @6);
2653 expression_statement
2654 | declaration_statement
2671 | conditionopt ';' expression
2678 // Grammar Note: No 'goto'. Gotos are not supported.
2682 void *ctx = state->linalloc;
2683 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2684 $$->set_location(@1);
2688 void *ctx = state->linalloc;
2689 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2690 $$->set_location(@1);
2694 void *ctx = state->linalloc;
2695 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2696 $$->set_location(@1);
2698 | RETURN expression ';'
2700 void *ctx = state->linalloc;
2701 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2702 $$->set_location_range(@1, @2);
2704 | DISCARD ';' // Fragment shader only.
2706 void *ctx = state->linalloc;
2707 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2708 $$->set_location(@1);
2712 external_declaration:
2713 function_definition { $$ = $1; }
2714 | declaration { $$ = $1; }
2715 | pragma_statement { $$ = NULL; }
2716 | layout_defaults { $$ = $1; }
2719 function_definition:
2720 function_prototype compound_statement_no_new_scope
2722 void *ctx = state->linalloc;
2723 $$ = new(ctx) ast_function_definition();
2724 $$->set_location_range(@1, @2);
2728 state->symbols->pop_scope();
2732 /* layout_qualifieropt is packed into this rule */
2734 basic_interface_block
2738 | layout_qualifier interface_block
2740 ast_interface_block *block = (ast_interface_block *) $2;
2742 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2743 block->layout.has_layout())) {
2751 | memory_qualifier interface_block
2753 ast_interface_block *block = (ast_interface_block *)$2;
2755 if (!block->default_layout.flags.q.buffer) {
2756 _mesa_glsl_error(& @1, state,
2757 "memory qualifiers can only be used in the "
2758 "declaration of shader storage blocks");
2760 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2768 basic_interface_block:
2769 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2771 ast_interface_block *const block = $6;
2773 if ($1.flags.q.uniform) {
2774 block->default_layout = *state->default_uniform_qualifier;
2775 } else if ($1.flags.q.buffer) {
2776 block->default_layout = *state->default_shader_storage_qualifier;
2778 block->block_name = $2;
2779 block->declarations.push_degenerate_list_at_head(& $4->link);
2781 _mesa_ast_process_interface_block(& @1, state, block, $1);
2787 interface_qualifier:
2790 memset(& $$, 0, sizeof($$));
2795 memset(& $$, 0, sizeof($$));
2800 memset(& $$, 0, sizeof($$));
2801 $$.flags.q.uniform = 1;
2805 memset(& $$, 0, sizeof($$));
2806 $$.flags.q.buffer = 1;
2808 | auxiliary_storage_qualifier interface_qualifier
2810 if (!$1.flags.q.patch) {
2811 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2813 if ($2.has_auxiliary_storage()) {
2814 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2817 $$.flags.q.patch = 1;
2824 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2828 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2829 $$->set_location(@1);
2831 | NEW_IDENTIFIER array_specifier
2833 $$ = new(state->linalloc) ast_interface_block($1, $2);
2834 $$->set_location_range(@1, @2);
2842 $1->link.self_link();
2844 | member_declaration member_list
2847 $2->link.insert_before(& $$->link);
2852 fully_specified_type struct_declarator_list ';'
2854 void *ctx = state->linalloc;
2855 ast_fully_specified_type *type = $1;
2856 type->set_location(@1);
2858 if (type->qualifier.flags.q.attribute) {
2859 _mesa_glsl_error(& @1, state,
2860 "keyword 'attribute' cannot be used with "
2861 "interface block member");
2862 } else if (type->qualifier.flags.q.varying) {
2863 _mesa_glsl_error(& @1, state,
2864 "keyword 'varying' cannot be used with "
2865 "interface block member");
2868 $$ = new(ctx) ast_declarator_list(type);
2869 $$->set_location(@2);
2871 $$->declarations.push_degenerate_list_at_head(& $2->link);
2875 layout_uniform_defaults:
2876 layout_qualifier layout_uniform_defaults
2879 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2883 | layout_qualifier UNIFORM ';'
2886 layout_buffer_defaults:
2887 layout_qualifier layout_buffer_defaults
2890 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2894 | layout_qualifier BUFFER ';'
2898 layout_qualifier layout_in_defaults
2901 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2904 if (!$$.validate_in_qualifier(& @1, state)) {
2908 | layout_qualifier IN_TOK ';'
2910 if (!$1.validate_in_qualifier(& @1, state)) {
2916 layout_out_defaults:
2917 layout_qualifier layout_out_defaults
2920 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2923 if (!$$.validate_out_qualifier(& @1, state)) {
2927 | layout_qualifier OUT_TOK ';'
2929 if (!$1.validate_out_qualifier(& @1, state)) {
2936 layout_uniform_defaults
2939 if (!state->default_uniform_qualifier->
2940 merge_qualifier(& @1, state, $1, false)) {
2943 if (!state->default_uniform_qualifier->
2944 push_to_global(& @1, state)) {
2948 | layout_buffer_defaults
2951 if (!state->default_shader_storage_qualifier->
2952 merge_qualifier(& @1, state, $1, false)) {
2955 if (!state->default_shader_storage_qualifier->
2956 push_to_global(& @1, state)) {
2960 /* From the GLSL 4.50 spec, section 4.4.5:
2962 * "It is a compile-time error to specify the binding identifier for
2963 * the global scope or for block member declarations."
2965 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2966 _mesa_glsl_error(& @1, state,
2967 "binding qualifier cannot be set for default layout");
2970 | layout_in_defaults
2973 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
2976 if (!state->in_qualifier->push_to_global(& @1, state)) {
2980 | layout_out_defaults
2983 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
2986 if (!state->out_qualifier->push_to_global(& @1, state)) {