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 INT64 UINT64 I64VEC2 I64VEC3 I64VEC4 U64VEC2 U64VEC3 U64VEC4
140 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
141 %token NOPERSPECTIVE FLAT SMOOTH
142 %token MAT2X2 MAT2X3 MAT2X4
143 %token MAT3X2 MAT3X3 MAT3X4
144 %token MAT4X2 MAT4X3 MAT4X4
145 %token DMAT2X2 DMAT2X3 DMAT2X4
146 %token DMAT3X2 DMAT3X3 DMAT3X4
147 %token DMAT4X2 DMAT4X3 DMAT4X4
148 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
149 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
150 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
151 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
152 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
153 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
154 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
155 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
156 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
157 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
158 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
159 %token SAMPLEREXTERNALOES
160 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
161 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
162 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
163 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
164 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
165 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
166 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
167 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
170 %token STRUCT VOID_TOK WHILE
171 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
172 %type <identifier> any_identifier
173 %type <interface_block> instance_name_opt
174 %token <real> FLOATCONSTANT
175 %token <dreal> DOUBLECONSTANT
176 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
177 %token <identifier> FIELD_SELECTION
178 %token LEFT_OP RIGHT_OP
179 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
180 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
181 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
183 %token INVARIANT PRECISE
184 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
186 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
187 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
188 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
189 %token PRAGMA_INVARIANT_ALL
192 /* Reserved words that are not actually used in the grammar.
194 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
195 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
196 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
197 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
199 %token SIZEOF CAST NAMESPACE USING
200 %token RESOURCE PATCH
205 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
207 %type <identifier> variable_identifier
208 %type <node> statement
209 %type <node> statement_list
210 %type <node> simple_statement
211 %type <n> precision_qualifier
212 %type <type_qualifier> type_qualifier
213 %type <type_qualifier> auxiliary_storage_qualifier
214 %type <type_qualifier> storage_qualifier
215 %type <type_qualifier> interpolation_qualifier
216 %type <type_qualifier> layout_qualifier
217 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
218 %type <type_qualifier> interface_block_layout_qualifier
219 %type <type_qualifier> memory_qualifier
220 %type <type_qualifier> subroutine_qualifier
221 %type <subroutine_list> subroutine_type_list
222 %type <type_qualifier> interface_qualifier
223 %type <type_specifier> type_specifier
224 %type <type_specifier> type_specifier_nonarray
225 %type <array_specifier> array_specifier
226 %type <identifier> basic_type_specifier_nonarray
227 %type <fully_specified_type> fully_specified_type
228 %type <function> function_prototype
229 %type <function> function_header
230 %type <function> function_header_with_parameters
231 %type <function> function_declarator
232 %type <parameter_declarator> parameter_declarator
233 %type <parameter_declarator> parameter_declaration
234 %type <type_qualifier> parameter_qualifier
235 %type <type_qualifier> parameter_direction_qualifier
236 %type <type_specifier> parameter_type_specifier
237 %type <function_definition> function_definition
238 %type <compound_statement> compound_statement_no_new_scope
239 %type <compound_statement> compound_statement
240 %type <node> statement_no_new_scope
241 %type <node> expression_statement
242 %type <expression> expression
243 %type <expression> primary_expression
244 %type <expression> assignment_expression
245 %type <expression> conditional_expression
246 %type <expression> logical_or_expression
247 %type <expression> logical_xor_expression
248 %type <expression> logical_and_expression
249 %type <expression> inclusive_or_expression
250 %type <expression> exclusive_or_expression
251 %type <expression> and_expression
252 %type <expression> equality_expression
253 %type <expression> relational_expression
254 %type <expression> shift_expression
255 %type <expression> additive_expression
256 %type <expression> multiplicative_expression
257 %type <expression> unary_expression
258 %type <expression> constant_expression
259 %type <expression> integer_expression
260 %type <expression> postfix_expression
261 %type <expression> function_call_header_with_parameters
262 %type <expression> function_call_header_no_parameters
263 %type <expression> function_call_header
264 %type <expression> function_call_generic
265 %type <expression> function_call_or_method
266 %type <expression> function_call
267 %type <n> assignment_operator
268 %type <n> unary_operator
269 %type <expression> function_identifier
270 %type <node> external_declaration
271 %type <declarator_list> init_declarator_list
272 %type <declarator_list> single_declaration
273 %type <expression> initializer
274 %type <expression> initializer_list
275 %type <node> declaration
276 %type <node> declaration_statement
277 %type <node> jump_statement
278 %type <node> interface_block
279 %type <interface_block> basic_interface_block
280 %type <struct_specifier> struct_specifier
281 %type <declarator_list> struct_declaration_list
282 %type <declarator_list> struct_declaration
283 %type <declaration> struct_declarator
284 %type <declaration> struct_declarator_list
285 %type <declarator_list> member_list
286 %type <declarator_list> member_declaration
287 %type <node> selection_statement
288 %type <selection_rest_statement> selection_rest_statement
289 %type <node> switch_statement
290 %type <switch_body> switch_body
291 %type <case_label_list> case_label_list
292 %type <case_label> case_label
293 %type <case_statement> case_statement
294 %type <case_statement_list> case_statement_list
295 %type <node> iteration_statement
296 %type <node> condition
297 %type <node> conditionopt
298 %type <node> for_init_statement
299 %type <for_rest_statement> for_rest_statement
300 %type <node> layout_defaults
301 %type <type_qualifier> layout_uniform_defaults
302 %type <type_qualifier> layout_buffer_defaults
303 %type <type_qualifier> layout_in_defaults
304 %type <type_qualifier> layout_out_defaults
310 version_statement extension_statement_list
312 _mesa_glsl_initialize_types(state);
314 external_declaration_list
316 delete state->symbols;
317 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
318 if (state->es_shader) {
319 if (state->stage == MESA_SHADER_FRAGMENT) {
320 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
322 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
323 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
325 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
326 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
327 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
328 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
330 _mesa_glsl_initialize_types(state);
335 /* blank - no #version specified: defaults are already set */
336 | VERSION_TOK INTCONSTANT EOL
338 state->process_version_directive(&@2, $2, NULL);
343 | VERSION_TOK INTCONSTANT any_identifier EOL
345 state->process_version_directive(&@2, $2, $3);
354 | PRAGMA_DEBUG_OFF EOL
355 | PRAGMA_OPTIMIZE_ON EOL
356 | PRAGMA_OPTIMIZE_OFF EOL
357 | PRAGMA_INVARIANT_ALL EOL
359 /* Pragma invariant(all) cannot be used in a fragment shader.
361 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
363 * "It is an error to use this pragma in a fragment shader."
365 if (state->is_version(120, 300) &&
366 state->stage == MESA_SHADER_FRAGMENT) {
367 _mesa_glsl_error(& @1, state,
368 "pragma `invariant(all)' cannot be used "
369 "in a fragment shader.");
370 } else if (!state->is_version(120, 100)) {
371 _mesa_glsl_warning(& @1, state,
372 "pragma `invariant(all)' not supported in %s "
373 "(GLSL ES 1.00 or GLSL 1.20 required)",
374 state->get_version_string());
376 state->all_invariant = true;
381 extension_statement_list:
383 | extension_statement_list extension_statement
393 EXTENSION any_identifier COLON any_identifier EOL
395 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
401 external_declaration_list:
404 /* FINISHME: The NULL test is required because pragmas are set to
405 * FINISHME: NULL. (See production rule for external_declaration.)
408 state->translation_unit.push_tail(& $1->link);
410 | external_declaration_list external_declaration
412 /* FINISHME: The NULL test is required because pragmas are set to
413 * FINISHME: NULL. (See production rule for external_declaration.)
416 state->translation_unit.push_tail(& $2->link);
418 | external_declaration_list extension_statement {
419 if (!state->allow_extension_directive_midshader) {
420 _mesa_glsl_error(& @2, state,
421 "#extension directive is not allowed "
422 "in the middle of a shader");
436 void *ctx = state->linalloc;
437 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
438 $$->set_location(@1);
439 $$->primary_expression.identifier = $1;
443 void *ctx = state->linalloc;
444 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
445 $$->set_location(@1);
446 $$->primary_expression.int_constant = $1;
450 void *ctx = state->linalloc;
451 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
452 $$->set_location(@1);
453 $$->primary_expression.uint_constant = $1;
457 void *ctx = state->linalloc;
458 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
459 $$->set_location(@1);
460 $$->primary_expression.float_constant = $1;
464 void *ctx = state->linalloc;
465 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
466 $$->set_location(@1);
467 $$->primary_expression.double_constant = $1;
471 void *ctx = state->linalloc;
472 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
473 $$->set_location(@1);
474 $$->primary_expression.bool_constant = $1;
484 | postfix_expression '[' integer_expression ']'
486 void *ctx = state->linalloc;
487 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
488 $$->set_location_range(@1, @4);
494 | postfix_expression DOT_TOK FIELD_SELECTION
496 void *ctx = state->linalloc;
497 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
498 $$->set_location_range(@1, @3);
499 $$->primary_expression.identifier = $3;
501 | postfix_expression INC_OP
503 void *ctx = state->linalloc;
504 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
505 $$->set_location_range(@1, @2);
507 | postfix_expression DEC_OP
509 void *ctx = state->linalloc;
510 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
511 $$->set_location_range(@1, @2);
520 function_call_or_method
523 function_call_or_method:
524 function_call_generic
527 function_call_generic:
528 function_call_header_with_parameters ')'
529 | function_call_header_no_parameters ')'
532 function_call_header_no_parameters:
533 function_call_header VOID_TOK
534 | function_call_header
537 function_call_header_with_parameters:
538 function_call_header assignment_expression
541 $$->set_location(@1);
542 $$->expressions.push_tail(& $2->link);
544 | function_call_header_with_parameters ',' assignment_expression
547 $$->set_location(@1);
548 $$->expressions.push_tail(& $3->link);
552 // Grammar Note: Constructors look like functions, but lexical
553 // analysis recognized most of them as keywords. They are now
554 // recognized through "type_specifier".
555 function_call_header:
556 function_identifier '('
562 void *ctx = state->linalloc;
563 $$ = new(ctx) ast_function_expression($1);
564 $$->set_location(@1);
568 void *ctx = state->linalloc;
569 $$ = new(ctx) ast_function_expression($1);
570 $$->set_location(@1);
574 // Grammar Note: Constructors look like methods, but lexical
575 // analysis recognized most of them as keywords. They are now
576 // recognized through "type_specifier".
578 // Grammar Note: No traditional style type casts.
581 | INC_OP unary_expression
583 void *ctx = state->linalloc;
584 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
585 $$->set_location(@1);
587 | DEC_OP unary_expression
589 void *ctx = state->linalloc;
590 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
591 $$->set_location(@1);
593 | unary_operator unary_expression
595 void *ctx = state->linalloc;
596 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
597 $$->set_location_range(@1, @2);
601 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
603 '+' { $$ = ast_plus; }
604 | '-' { $$ = ast_neg; }
605 | '!' { $$ = ast_logic_not; }
606 | '~' { $$ = ast_bit_not; }
609 multiplicative_expression:
611 | multiplicative_expression '*' unary_expression
613 void *ctx = state->linalloc;
614 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
615 $$->set_location_range(@1, @3);
617 | multiplicative_expression '/' unary_expression
619 void *ctx = state->linalloc;
620 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
621 $$->set_location_range(@1, @3);
623 | multiplicative_expression '%' unary_expression
625 void *ctx = state->linalloc;
626 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
627 $$->set_location_range(@1, @3);
632 multiplicative_expression
633 | additive_expression '+' multiplicative_expression
635 void *ctx = state->linalloc;
636 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
637 $$->set_location_range(@1, @3);
639 | additive_expression '-' multiplicative_expression
641 void *ctx = state->linalloc;
642 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
643 $$->set_location_range(@1, @3);
649 | shift_expression LEFT_OP additive_expression
651 void *ctx = state->linalloc;
652 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
653 $$->set_location_range(@1, @3);
655 | shift_expression RIGHT_OP additive_expression
657 void *ctx = state->linalloc;
658 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
659 $$->set_location_range(@1, @3);
663 relational_expression:
665 | relational_expression '<' shift_expression
667 void *ctx = state->linalloc;
668 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
669 $$->set_location_range(@1, @3);
671 | relational_expression '>' shift_expression
673 void *ctx = state->linalloc;
674 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
675 $$->set_location_range(@1, @3);
677 | relational_expression LE_OP shift_expression
679 void *ctx = state->linalloc;
680 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
681 $$->set_location_range(@1, @3);
683 | relational_expression GE_OP shift_expression
685 void *ctx = state->linalloc;
686 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
687 $$->set_location_range(@1, @3);
692 relational_expression
693 | equality_expression EQ_OP relational_expression
695 void *ctx = state->linalloc;
696 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
697 $$->set_location_range(@1, @3);
699 | equality_expression NE_OP relational_expression
701 void *ctx = state->linalloc;
702 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
703 $$->set_location_range(@1, @3);
709 | and_expression '&' equality_expression
711 void *ctx = state->linalloc;
712 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
713 $$->set_location_range(@1, @3);
717 exclusive_or_expression:
719 | exclusive_or_expression '^' and_expression
721 void *ctx = state->linalloc;
722 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
723 $$->set_location_range(@1, @3);
727 inclusive_or_expression:
728 exclusive_or_expression
729 | inclusive_or_expression '|' exclusive_or_expression
731 void *ctx = state->linalloc;
732 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
733 $$->set_location_range(@1, @3);
737 logical_and_expression:
738 inclusive_or_expression
739 | logical_and_expression AND_OP inclusive_or_expression
741 void *ctx = state->linalloc;
742 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
743 $$->set_location_range(@1, @3);
747 logical_xor_expression:
748 logical_and_expression
749 | logical_xor_expression XOR_OP logical_and_expression
751 void *ctx = state->linalloc;
752 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
753 $$->set_location_range(@1, @3);
757 logical_or_expression:
758 logical_xor_expression
759 | logical_or_expression OR_OP logical_xor_expression
761 void *ctx = state->linalloc;
762 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
763 $$->set_location_range(@1, @3);
767 conditional_expression:
768 logical_or_expression
769 | logical_or_expression '?' expression ':' assignment_expression
771 void *ctx = state->linalloc;
772 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
773 $$->set_location_range(@1, @5);
777 assignment_expression:
778 conditional_expression
779 | unary_expression assignment_operator assignment_expression
781 void *ctx = state->linalloc;
782 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
783 $$->set_location_range(@1, @3);
788 '=' { $$ = ast_assign; }
789 | MUL_ASSIGN { $$ = ast_mul_assign; }
790 | DIV_ASSIGN { $$ = ast_div_assign; }
791 | MOD_ASSIGN { $$ = ast_mod_assign; }
792 | ADD_ASSIGN { $$ = ast_add_assign; }
793 | SUB_ASSIGN { $$ = ast_sub_assign; }
794 | LEFT_ASSIGN { $$ = ast_ls_assign; }
795 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
796 | AND_ASSIGN { $$ = ast_and_assign; }
797 | XOR_ASSIGN { $$ = ast_xor_assign; }
798 | OR_ASSIGN { $$ = ast_or_assign; }
802 assignment_expression
806 | expression ',' assignment_expression
808 void *ctx = state->linalloc;
809 if ($1->oper != ast_sequence) {
810 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
811 $$->set_location_range(@1, @3);
812 $$->expressions.push_tail(& $1->link);
817 $$->expressions.push_tail(& $3->link);
822 conditional_expression
826 function_prototype ';'
828 state->symbols->pop_scope();
831 | init_declarator_list ';'
835 | PRECISION precision_qualifier type_specifier ';'
837 $3->default_precision = $2;
842 ast_interface_block *block = (ast_interface_block *) $1;
843 if (block->layout.has_layout() || block->layout.has_memory()) {
844 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
848 block->layout = block->default_layout;
849 if (!block->layout.push_to_global(& @1, state)) {
857 function_declarator ')'
862 | function_header_with_parameters
865 function_header_with_parameters:
866 function_header parameter_declaration
869 $$->parameters.push_tail(& $2->link);
871 | function_header_with_parameters ',' parameter_declaration
874 $$->parameters.push_tail(& $3->link);
879 fully_specified_type variable_identifier '('
881 void *ctx = state->linalloc;
882 $$ = new(ctx) ast_function();
883 $$->set_location(@2);
884 $$->return_type = $1;
887 if ($1->qualifier.flags.q.subroutine) {
888 /* add type for IDENTIFIER search */
889 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
891 state->symbols->add_function(new(state) ir_function($2));
892 state->symbols->push_scope();
896 parameter_declarator:
897 type_specifier any_identifier
899 void *ctx = state->linalloc;
900 $$ = new(ctx) ast_parameter_declarator();
901 $$->set_location_range(@1, @2);
902 $$->type = new(ctx) ast_fully_specified_type();
903 $$->type->set_location(@1);
904 $$->type->specifier = $1;
906 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
908 | type_specifier any_identifier array_specifier
910 void *ctx = state->linalloc;
911 $$ = new(ctx) ast_parameter_declarator();
912 $$->set_location_range(@1, @3);
913 $$->type = new(ctx) ast_fully_specified_type();
914 $$->type->set_location(@1);
915 $$->type->specifier = $1;
917 $$->array_specifier = $3;
918 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
922 parameter_declaration:
923 parameter_qualifier parameter_declarator
926 $$->type->qualifier = $1;
927 if (!$$->type->qualifier.push_to_global(& @1, state)) {
931 | parameter_qualifier parameter_type_specifier
933 void *ctx = state->linalloc;
934 $$ = new(ctx) ast_parameter_declarator();
935 $$->set_location(@2);
936 $$->type = new(ctx) ast_fully_specified_type();
937 $$->type->set_location_range(@1, @2);
938 $$->type->qualifier = $1;
939 if (!$$->type->qualifier.push_to_global(& @1, state)) {
942 $$->type->specifier = $2;
949 memset(& $$, 0, sizeof($$));
951 | CONST_TOK parameter_qualifier
953 if ($2.flags.q.constant)
954 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
957 $$.flags.q.constant = 1;
959 | PRECISE parameter_qualifier
961 if ($2.flags.q.precise)
962 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
965 $$.flags.q.precise = 1;
967 | parameter_direction_qualifier parameter_qualifier
969 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
970 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
972 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
973 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
977 $$.merge_qualifier(&@1, state, $2, false);
979 | precision_qualifier parameter_qualifier
981 if ($2.precision != ast_precision_none)
982 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
984 if (!state->has_420pack_or_es31() &&
986 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
991 | memory_qualifier parameter_qualifier
994 $$.merge_qualifier(&@1, state, $2, false);
997 parameter_direction_qualifier:
1000 memset(& $$, 0, sizeof($$));
1005 memset(& $$, 0, sizeof($$));
1010 memset(& $$, 0, sizeof($$));
1016 parameter_type_specifier:
1020 init_declarator_list:
1022 | init_declarator_list ',' any_identifier
1024 void *ctx = state->linalloc;
1025 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1026 decl->set_location(@3);
1029 $$->declarations.push_tail(&decl->link);
1030 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1032 | init_declarator_list ',' any_identifier array_specifier
1034 void *ctx = state->linalloc;
1035 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1036 decl->set_location_range(@3, @4);
1039 $$->declarations.push_tail(&decl->link);
1040 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1042 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1044 void *ctx = state->linalloc;
1045 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1046 decl->set_location_range(@3, @4);
1049 $$->declarations.push_tail(&decl->link);
1050 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1052 | init_declarator_list ',' any_identifier '=' initializer
1054 void *ctx = state->linalloc;
1055 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1056 decl->set_location(@3);
1059 $$->declarations.push_tail(&decl->link);
1060 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1064 // Grammar Note: No 'enum', or 'typedef'.
1066 fully_specified_type
1068 void *ctx = state->linalloc;
1069 /* Empty declaration list is valid. */
1070 $$ = new(ctx) ast_declarator_list($1);
1071 $$->set_location(@1);
1073 | fully_specified_type any_identifier
1075 void *ctx = state->linalloc;
1076 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1077 decl->set_location(@2);
1079 $$ = new(ctx) ast_declarator_list($1);
1080 $$->set_location_range(@1, @2);
1081 $$->declarations.push_tail(&decl->link);
1082 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1084 | fully_specified_type any_identifier array_specifier
1086 void *ctx = state->linalloc;
1087 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1088 decl->set_location_range(@2, @3);
1090 $$ = new(ctx) ast_declarator_list($1);
1091 $$->set_location_range(@1, @3);
1092 $$->declarations.push_tail(&decl->link);
1093 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1095 | fully_specified_type any_identifier array_specifier '=' initializer
1097 void *ctx = state->linalloc;
1098 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1099 decl->set_location_range(@2, @3);
1101 $$ = new(ctx) ast_declarator_list($1);
1102 $$->set_location_range(@1, @3);
1103 $$->declarations.push_tail(&decl->link);
1104 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1106 | fully_specified_type any_identifier '=' initializer
1108 void *ctx = state->linalloc;
1109 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1110 decl->set_location(@2);
1112 $$ = new(ctx) ast_declarator_list($1);
1113 $$->set_location_range(@1, @2);
1114 $$->declarations.push_tail(&decl->link);
1115 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1117 | INVARIANT variable_identifier
1119 void *ctx = state->linalloc;
1120 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1121 decl->set_location(@2);
1123 $$ = new(ctx) ast_declarator_list(NULL);
1124 $$->set_location_range(@1, @2);
1125 $$->invariant = true;
1127 $$->declarations.push_tail(&decl->link);
1129 | PRECISE variable_identifier
1131 void *ctx = state->linalloc;
1132 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1133 decl->set_location(@2);
1135 $$ = new(ctx) ast_declarator_list(NULL);
1136 $$->set_location_range(@1, @2);
1139 $$->declarations.push_tail(&decl->link);
1143 fully_specified_type:
1146 void *ctx = state->linalloc;
1147 $$ = new(ctx) ast_fully_specified_type();
1148 $$->set_location(@1);
1151 | type_qualifier type_specifier
1153 void *ctx = state->linalloc;
1154 $$ = new(ctx) ast_fully_specified_type();
1155 $$->set_location_range(@1, @2);
1157 if (!$$->qualifier.push_to_global(& @1, state)) {
1161 if ($$->specifier->structure != NULL &&
1162 $$->specifier->structure->is_declaration) {
1163 $$->specifier->structure->layout = &$$->qualifier;
1169 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1175 layout_qualifier_id_list:
1177 | layout_qualifier_id_list ',' layout_qualifier_id
1180 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1186 layout_qualifier_id:
1189 memset(& $$, 0, sizeof($$));
1191 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1192 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1193 state->is_version(150, 0))) {
1194 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1195 $$.flags.q.origin_upper_left = 1;
1196 } else if (match_layout_qualifier($1, "pixel_center_integer",
1198 $$.flags.q.pixel_center_integer = 1;
1201 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1202 _mesa_glsl_warning(& @1, state,
1203 "GL_ARB_fragment_coord_conventions layout "
1204 "identifier `%s' used", $1);
1208 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1210 (state->AMD_conservative_depth_enable ||
1211 state->ARB_conservative_depth_enable ||
1212 state->is_version(420, 0))) {
1213 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1214 $$.flags.q.depth_any = 1;
1215 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1216 $$.flags.q.depth_greater = 1;
1217 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1218 $$.flags.q.depth_less = 1;
1219 } else if (match_layout_qualifier($1, "depth_unchanged",
1221 $$.flags.q.depth_unchanged = 1;
1224 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1225 _mesa_glsl_warning(& @1, state,
1226 "GL_AMD_conservative_depth "
1227 "layout qualifier `%s' is used", $1);
1229 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1230 _mesa_glsl_warning(& @1, state,
1231 "GL_ARB_conservative_depth "
1232 "layout qualifier `%s' is used", $1);
1236 /* See also interface_block_layout_qualifier. */
1237 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1238 if (match_layout_qualifier($1, "std140", state) == 0) {
1239 $$.flags.q.std140 = 1;
1240 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1241 $$.flags.q.shared = 1;
1242 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1243 $$.flags.q.std430 = 1;
1244 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1245 $$.flags.q.column_major = 1;
1246 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1247 * below in the interface_block_layout_qualifier rule.
1249 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1252 * Also, this takes care of alternate capitalizations of
1253 * "row_major" (which is necessary because layout qualifiers
1254 * are case-insensitive in desktop GLSL).
1256 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1257 $$.flags.q.row_major = 1;
1258 /* "packed" is a reserved word in GLSL, and its token is
1259 * parsed below in the interface_block_layout_qualifier rule.
1260 * However, we must take care of alternate capitalizations of
1261 * "packed", because layout qualifiers are case-insensitive
1264 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1265 $$.flags.q.packed = 1;
1268 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1269 _mesa_glsl_warning(& @1, state,
1270 "#version 140 / GL_ARB_uniform_buffer_object "
1271 "layout qualifier `%s' is used", $1);
1275 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1277 static const struct {
1281 { "points", GL_POINTS },
1282 { "lines", GL_LINES },
1283 { "lines_adjacency", GL_LINES_ADJACENCY },
1284 { "line_strip", GL_LINE_STRIP },
1285 { "triangles", GL_TRIANGLES },
1286 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1287 { "triangle_strip", GL_TRIANGLE_STRIP },
1289 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1290 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1291 $$.flags.q.prim_type = 1;
1292 $$.prim_type = map[i].e;
1297 if ($$.flags.i && !state->has_geometry_shader() &&
1298 !state->has_tessellation_shader()) {
1299 _mesa_glsl_error(& @1, state, "#version 150 layout "
1300 "qualifier `%s' used", $1);
1304 /* Layout qualifiers for ARB_shader_image_load_store. */
1305 if (state->ARB_shader_image_load_store_enable ||
1306 state->is_version(420, 310)) {
1308 static const struct {
1311 glsl_base_type base_type;
1312 /** Minimum desktop GLSL version required for the image
1313 * format. Use 130 if already present in the original
1316 unsigned required_glsl;
1317 /** Minimum GLSL ES version required for the image format. */
1318 unsigned required_essl;
1319 /* NV_image_formats */
1320 bool nv_image_formats;
1322 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
1323 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
1324 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
1325 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
1326 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
1327 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
1328 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
1329 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
1330 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
1331 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
1332 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
1333 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
1334 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
1335 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
1336 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
1337 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
1338 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
1339 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
1340 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
1341 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
1342 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
1343 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
1344 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
1345 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
1346 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
1347 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
1348 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
1349 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
1350 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
1351 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
1352 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
1353 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
1354 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
1355 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1356 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
1357 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1358 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
1359 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
1360 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
1363 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1364 if ((state->is_version(map[i].required_glsl,
1365 map[i].required_essl) ||
1366 (state->NV_image_formats_enable &&
1367 map[i].nv_image_formats)) &&
1368 match_layout_qualifier($1, map[i].name, state) == 0) {
1369 $$.flags.q.explicit_image_format = 1;
1370 $$.image_format = map[i].format;
1371 $$.image_base_type = map[i].base_type;
1379 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1380 /* From section 4.4.1.3 of the GLSL 4.50 specification
1381 * (Fragment Shader Inputs):
1383 * "Fragment shaders also allow the following layout
1384 * qualifier on in only (not with variable declarations)
1385 * layout-qualifier-id
1386 * early_fragment_tests
1389 if (state->stage != MESA_SHADER_FRAGMENT) {
1390 _mesa_glsl_error(& @1, state,
1391 "early_fragment_tests layout qualifier only "
1392 "valid in fragment shaders");
1395 $$.flags.q.early_fragment_tests = 1;
1398 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1399 if (state->stage != MESA_SHADER_FRAGMENT) {
1400 _mesa_glsl_error(& @1, state,
1401 "inner_coverage layout qualifier only "
1402 "valid in fragment shaders");
1405 if (state->INTEL_conservative_rasterization_enable) {
1406 $$.flags.q.inner_coverage = 1;
1408 _mesa_glsl_error(& @1, state,
1409 "inner_coverage layout qualifier present, "
1410 "but the INTEL_conservative_rasterization extension "
1415 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1416 if (state->stage != MESA_SHADER_FRAGMENT) {
1417 _mesa_glsl_error(& @1, state,
1418 "post_depth_coverage layout qualifier only "
1419 "valid in fragment shaders");
1422 if (state->ARB_post_depth_coverage_enable ||
1423 state->INTEL_conservative_rasterization_enable) {
1424 $$.flags.q.post_depth_coverage = 1;
1426 _mesa_glsl_error(& @1, state,
1427 "post_depth_coverage layout qualifier present, "
1428 "but the GL_ARB_post_depth_coverage extension "
1433 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1434 _mesa_glsl_error(& @1, state,
1435 "post_depth_coverage & inner_coverage layout qualifiers "
1436 "are mutually exclusive");
1440 /* Layout qualifiers for tessellation evaluation shaders. */
1442 static const struct {
1446 /* triangles already parsed by gs-specific code */
1447 { "quads", GL_QUADS },
1448 { "isolines", GL_ISOLINES },
1450 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1451 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1452 $$.flags.q.prim_type = 1;
1453 $$.prim_type = map[i].e;
1458 if ($$.flags.i && !state->has_tessellation_shader()) {
1459 _mesa_glsl_error(& @1, state,
1460 "primitive mode qualifier `%s' requires "
1461 "GLSL 4.00 or ARB_tessellation_shader", $1);
1465 static const struct {
1467 enum gl_tess_spacing e;
1469 { "equal_spacing", TESS_SPACING_EQUAL },
1470 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1471 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1473 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1474 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1475 $$.flags.q.vertex_spacing = 1;
1476 $$.vertex_spacing = map[i].e;
1481 if ($$.flags.i && !state->has_tessellation_shader()) {
1482 _mesa_glsl_error(& @1, state,
1483 "vertex spacing qualifier `%s' requires "
1484 "GLSL 4.00 or ARB_tessellation_shader", $1);
1488 if (match_layout_qualifier($1, "cw", state) == 0) {
1489 $$.flags.q.ordering = 1;
1490 $$.ordering = GL_CW;
1491 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1492 $$.flags.q.ordering = 1;
1493 $$.ordering = GL_CCW;
1496 if ($$.flags.i && !state->has_tessellation_shader()) {
1497 _mesa_glsl_error(& @1, state,
1498 "ordering qualifier `%s' requires "
1499 "GLSL 4.00 or ARB_tessellation_shader", $1);
1503 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1504 $$.flags.q.point_mode = 1;
1505 $$.point_mode = true;
1508 if ($$.flags.i && !state->has_tessellation_shader()) {
1509 _mesa_glsl_error(& @1, state,
1510 "qualifier `point_mode' requires "
1511 "GLSL 4.00 or ARB_tessellation_shader");
1516 static const struct {
1520 { "blend_support_multiply", BLEND_MULTIPLY },
1521 { "blend_support_screen", BLEND_SCREEN },
1522 { "blend_support_overlay", BLEND_OVERLAY },
1523 { "blend_support_darken", BLEND_DARKEN },
1524 { "blend_support_lighten", BLEND_LIGHTEN },
1525 { "blend_support_colordodge", BLEND_COLORDODGE },
1526 { "blend_support_colorburn", BLEND_COLORBURN },
1527 { "blend_support_hardlight", BLEND_HARDLIGHT },
1528 { "blend_support_softlight", BLEND_SOFTLIGHT },
1529 { "blend_support_difference", BLEND_DIFFERENCE },
1530 { "blend_support_exclusion", BLEND_EXCLUSION },
1531 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1532 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1533 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1534 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1535 { "blend_support_all_equations", BLEND_ALL },
1537 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1538 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1539 $$.flags.q.blend_support = 1;
1540 state->fs_blend_support |= map[i].mask;
1546 !state->KHR_blend_equation_advanced_enable &&
1547 !state->is_version(0, 320)) {
1548 _mesa_glsl_error(& @1, state,
1549 "advanced blending layout qualifiers require "
1550 "ESSL 3.20 or KHR_blend_equation_advanced");
1553 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1554 _mesa_glsl_error(& @1, state,
1555 "advanced blending layout qualifiers only "
1556 "valid in fragment shaders");
1560 /* Layout qualifiers for ARB_compute_variable_group_size. */
1562 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1563 $$.flags.q.local_size_variable = 1;
1566 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1567 _mesa_glsl_error(& @1, state,
1568 "qualifier `local_size_variable` requires "
1569 "ARB_compute_variable_group_size");
1574 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1579 | any_identifier '=' constant_expression
1581 memset(& $$, 0, sizeof($$));
1582 void *ctx = state->linalloc;
1584 if ($3->oper != ast_int_constant &&
1585 $3->oper != ast_uint_constant &&
1586 !state->has_enhanced_layouts()) {
1587 _mesa_glsl_error(& @1, state,
1588 "compile-time constant expressions require "
1589 "GLSL 4.40 or ARB_enhanced_layouts");
1592 if (match_layout_qualifier("align", $1, state) == 0) {
1593 if (!state->has_enhanced_layouts()) {
1594 _mesa_glsl_error(& @1, state,
1595 "align qualifier requires "
1596 "GLSL 4.40 or ARB_enhanced_layouts");
1598 $$.flags.q.explicit_align = 1;
1603 if (match_layout_qualifier("location", $1, state) == 0) {
1604 $$.flags.q.explicit_location = 1;
1606 if ($$.flags.q.attribute == 1 &&
1607 state->ARB_explicit_attrib_location_warn) {
1608 _mesa_glsl_warning(& @1, state,
1609 "GL_ARB_explicit_attrib_location layout "
1610 "identifier `%s' used", $1);
1615 if (match_layout_qualifier("component", $1, state) == 0) {
1616 if (!state->has_enhanced_layouts()) {
1617 _mesa_glsl_error(& @1, state,
1618 "component qualifier requires "
1619 "GLSL 4.40 or ARB_enhanced_layouts");
1621 $$.flags.q.explicit_component = 1;
1626 if (match_layout_qualifier("index", $1, state) == 0) {
1627 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1628 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1632 $$.flags.q.explicit_index = 1;
1636 if ((state->has_420pack_or_es31() ||
1637 state->has_atomic_counters() ||
1638 state->has_shader_storage_buffer_objects()) &&
1639 match_layout_qualifier("binding", $1, state) == 0) {
1640 $$.flags.q.explicit_binding = 1;
1644 if ((state->has_atomic_counters() ||
1645 state->has_enhanced_layouts()) &&
1646 match_layout_qualifier("offset", $1, state) == 0) {
1647 $$.flags.q.explicit_offset = 1;
1651 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1652 $$.flags.q.max_vertices = 1;
1653 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1654 if (!state->has_geometry_shader()) {
1655 _mesa_glsl_error(& @3, state,
1656 "#version 150 max_vertices qualifier "
1661 if (state->stage == MESA_SHADER_GEOMETRY) {
1662 if (match_layout_qualifier("stream", $1, state) == 0 &&
1663 state->check_explicit_attrib_stream_allowed(& @3)) {
1664 $$.flags.q.stream = 1;
1665 $$.flags.q.explicit_stream = 1;
1670 if (state->has_enhanced_layouts()) {
1671 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1672 $$.flags.q.xfb_buffer = 1;
1673 $$.flags.q.explicit_xfb_buffer = 1;
1677 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1678 $$.flags.q.explicit_xfb_offset = 1;
1682 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1683 $$.flags.q.xfb_stride = 1;
1684 $$.flags.q.explicit_xfb_stride = 1;
1689 static const char * const local_size_qualifiers[3] = {
1694 for (int i = 0; i < 3; i++) {
1695 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1697 if (!state->has_compute_shader()) {
1698 _mesa_glsl_error(& @3, state,
1699 "%s qualifier requires GLSL 4.30 or "
1700 "GLSL ES 3.10 or ARB_compute_shader",
1701 local_size_qualifiers[i]);
1704 $$.flags.q.local_size |= (1 << i);
1705 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1711 if (match_layout_qualifier("invocations", $1, state) == 0) {
1712 $$.flags.q.invocations = 1;
1713 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1714 if (!state->is_version(400, 320) &&
1715 !state->ARB_gpu_shader5_enable &&
1716 !state->OES_geometry_shader_enable &&
1717 !state->EXT_geometry_shader_enable) {
1718 _mesa_glsl_error(& @3, state,
1719 "GL_ARB_gpu_shader5 invocations "
1720 "qualifier specified", $3);
1724 /* Layout qualifiers for tessellation control shaders. */
1725 if (match_layout_qualifier("vertices", $1, state) == 0) {
1726 $$.flags.q.vertices = 1;
1727 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1728 if (!state->has_tessellation_shader()) {
1729 _mesa_glsl_error(& @1, state,
1730 "vertices qualifier requires GLSL 4.00 or "
1731 "ARB_tessellation_shader");
1735 /* If the identifier didn't match any known layout identifiers,
1739 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1744 | interface_block_layout_qualifier
1747 /* Layout qualifiers for ARB_uniform_buffer_object. */
1748 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1749 _mesa_glsl_error(& @1, state,
1750 "#version 140 / GL_ARB_uniform_buffer_object "
1751 "layout qualifier `%s' is used", $1);
1752 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1753 _mesa_glsl_warning(& @1, state,
1754 "#version 140 / GL_ARB_uniform_buffer_object "
1755 "layout qualifier `%s' is used", $1);
1760 /* This is a separate language rule because we parse these as tokens
1761 * (due to them being reserved keywords) instead of identifiers like
1762 * most qualifiers. See the any_identifier path of
1763 * layout_qualifier_id for the others.
1765 * Note that since layout qualifiers are case-insensitive in desktop
1766 * GLSL, all of these qualifiers need to be handled as identifiers as
1767 * well (by the any_identifier path of layout_qualifier_id).
1769 interface_block_layout_qualifier:
1772 memset(& $$, 0, sizeof($$));
1773 $$.flags.q.row_major = 1;
1777 memset(& $$, 0, sizeof($$));
1778 $$.flags.q.packed = 1;
1782 memset(& $$, 0, sizeof($$));
1783 $$.flags.q.shared = 1;
1787 subroutine_qualifier:
1790 memset(& $$, 0, sizeof($$));
1791 $$.flags.q.subroutine = 1;
1793 | SUBROUTINE '(' subroutine_type_list ')'
1795 memset(& $$, 0, sizeof($$));
1796 $$.flags.q.subroutine_def = 1;
1797 $$.subroutine_list = $3;
1801 subroutine_type_list:
1804 void *ctx = state->linalloc;
1805 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1806 decl->set_location(@1);
1808 $$ = new(ctx) ast_subroutine_list();
1809 $$->declarations.push_tail(&decl->link);
1811 | subroutine_type_list ',' any_identifier
1813 void *ctx = state->linalloc;
1814 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1815 decl->set_location(@3);
1818 $$->declarations.push_tail(&decl->link);
1822 interpolation_qualifier:
1825 memset(& $$, 0, sizeof($$));
1826 $$.flags.q.smooth = 1;
1830 memset(& $$, 0, sizeof($$));
1831 $$.flags.q.flat = 1;
1835 memset(& $$, 0, sizeof($$));
1836 $$.flags.q.noperspective = 1;
1841 /* Single qualifiers */
1844 memset(& $$, 0, sizeof($$));
1845 $$.flags.q.invariant = 1;
1849 memset(& $$, 0, sizeof($$));
1850 $$.flags.q.precise = 1;
1852 | auxiliary_storage_qualifier
1854 | interpolation_qualifier
1857 | subroutine_qualifier
1858 | precision_qualifier
1860 memset(&$$, 0, sizeof($$));
1864 /* Multiple qualifiers:
1865 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1866 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1868 * invariant interpolation auxiliary storage precision ...or...
1869 * layout storage precision
1871 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1872 * side don't contain any that must appear on the left hand side.
1873 * For example, when processing a storage qualifier, we check that there are
1874 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1876 | PRECISE type_qualifier
1878 if ($2.flags.q.precise)
1879 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1882 $$.flags.q.precise = 1;
1884 | INVARIANT type_qualifier
1886 if ($2.flags.q.invariant)
1887 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1889 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1890 _mesa_glsl_error(&@1, state,
1891 "\"invariant\" must come after \"precise\"");
1894 $$.flags.q.invariant = 1;
1896 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1898 * "Only variables output from a shader can be candidates for invariance.
1899 * This includes user-defined output variables and the built-in output
1900 * variables. As only outputs can be declared as invariant, an invariant
1901 * output from one shader stage will still match an input of a subsequent
1902 * stage without the input being declared as invariant."
1904 * On the desktop side, this text first appears in GLSL 4.30.
1906 if (state->is_version(430, 300) && $$.flags.q.in)
1907 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1909 | interpolation_qualifier type_qualifier
1911 /* Section 4.3 of the GLSL 1.40 specification states:
1912 * "...qualified with one of these interpolation qualifiers"
1914 * GLSL 1.30 claims to allow "one or more", but insists that:
1915 * "These interpolation qualifiers may only precede the qualifiers in,
1916 * centroid in, out, or centroid out in a declaration."
1918 * ...which means that e.g. smooth can't precede smooth, so there can be
1919 * only one after all, and the 1.40 text is a clarification, not a change.
1921 if ($2.has_interpolation())
1922 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1924 if (!state->has_420pack_or_es31() &&
1925 ($2.flags.q.precise || $2.flags.q.invariant)) {
1926 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1927 "after \"precise\" or \"invariant\"");
1931 $$.merge_qualifier(&@1, state, $2, false);
1933 | layout_qualifier type_qualifier
1935 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1936 * appear no later than auxiliary storage qualifiers. There is no
1937 * particularly clear spec language mandating this, but in all examples
1938 * the layout qualifier precedes the storage qualifier.
1940 * We allow combinations of layout with interpolation, invariant or
1941 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1942 * There is no clear spec guidance on this either.
1945 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1947 | subroutine_qualifier type_qualifier
1950 $$.merge_qualifier(&@1, state, $2, false);
1952 | auxiliary_storage_qualifier type_qualifier
1954 if ($2.has_auxiliary_storage()) {
1955 _mesa_glsl_error(&@1, state,
1956 "duplicate auxiliary storage qualifier (centroid or sample)");
1959 if (!state->has_420pack_or_es31() &&
1960 ($2.flags.q.precise || $2.flags.q.invariant ||
1961 $2.has_interpolation() || $2.has_layout())) {
1962 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1963 "just before storage qualifiers");
1966 $$.merge_qualifier(&@1, state, $2, false);
1968 | storage_qualifier type_qualifier
1970 /* Section 4.3 of the GLSL 1.20 specification states:
1971 * "Variable declarations may have a storage qualifier specified..."
1972 * 1.30 clarifies this to "may have one storage qualifier".
1974 if ($2.has_storage())
1975 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1977 if (!state->has_420pack_or_es31() &&
1978 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1979 $2.has_layout() || $2.has_auxiliary_storage())) {
1980 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1981 "precise, invariant, interpolation, layout and auxiliary "
1982 "storage qualifiers");
1986 $$.merge_qualifier(&@1, state, $2, false);
1988 | precision_qualifier type_qualifier
1990 if ($2.precision != ast_precision_none)
1991 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1993 if (!(state->has_420pack_or_es31()) &&
1995 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2000 | memory_qualifier type_qualifier
2003 $$.merge_qualifier(&@1, state, $2, false);
2007 auxiliary_storage_qualifier:
2010 memset(& $$, 0, sizeof($$));
2011 $$.flags.q.centroid = 1;
2015 memset(& $$, 0, sizeof($$));
2016 $$.flags.q.sample = 1;
2020 memset(& $$, 0, sizeof($$));
2021 $$.flags.q.patch = 1;
2027 memset(& $$, 0, sizeof($$));
2028 $$.flags.q.constant = 1;
2032 memset(& $$, 0, sizeof($$));
2033 $$.flags.q.attribute = 1;
2037 memset(& $$, 0, sizeof($$));
2038 $$.flags.q.varying = 1;
2042 memset(& $$, 0, sizeof($$));
2047 memset(& $$, 0, sizeof($$));
2050 if (state->stage == MESA_SHADER_GEOMETRY &&
2051 state->has_explicit_attrib_stream()) {
2052 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2055 * "If the block or variable is declared with the stream
2056 * identifier, it is associated with the specified stream;
2057 * otherwise, it is associated with the current default stream."
2059 $$.flags.q.stream = 1;
2060 $$.flags.q.explicit_stream = 0;
2061 $$.stream = state->out_qualifier->stream;
2064 if (state->has_enhanced_layouts()) {
2065 $$.flags.q.xfb_buffer = 1;
2066 $$.flags.q.explicit_xfb_buffer = 0;
2067 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2072 memset(& $$, 0, sizeof($$));
2076 if (!state->has_framebuffer_fetch() ||
2077 !state->is_version(130, 300) ||
2078 state->stage != MESA_SHADER_FRAGMENT)
2079 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2080 "declared as both input and output");
2084 memset(& $$, 0, sizeof($$));
2085 $$.flags.q.uniform = 1;
2089 memset(& $$, 0, sizeof($$));
2090 $$.flags.q.buffer = 1;
2094 memset(& $$, 0, sizeof($$));
2095 $$.flags.q.shared_storage = 1;
2102 memset(& $$, 0, sizeof($$));
2103 $$.flags.q.coherent = 1;
2107 memset(& $$, 0, sizeof($$));
2108 $$.flags.q._volatile = 1;
2112 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2113 memset(& $$, 0, sizeof($$));
2114 $$.flags.q.restrict_flag = 1;
2118 memset(& $$, 0, sizeof($$));
2119 $$.flags.q.read_only = 1;
2123 memset(& $$, 0, sizeof($$));
2124 $$.flags.q.write_only = 1;
2131 void *ctx = state->linalloc;
2132 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2133 ast_unsized_array_dim, NULL,
2135 $$->set_location_range(@1, @2);
2137 | '[' constant_expression ']'
2139 void *ctx = state->linalloc;
2140 $$ = new(ctx) ast_array_specifier(@1, $2);
2141 $$->set_location_range(@1, @3);
2143 | array_specifier '[' ']'
2145 void *ctx = state->linalloc;
2148 if (state->check_arrays_of_arrays_allowed(& @1)) {
2149 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2153 | array_specifier '[' constant_expression ']'
2157 if (state->check_arrays_of_arrays_allowed(& @1)) {
2158 $$->add_dimension($3);
2164 type_specifier_nonarray
2165 | type_specifier_nonarray array_specifier
2168 $$->array_specifier = $2;
2172 type_specifier_nonarray:
2173 basic_type_specifier_nonarray
2175 void *ctx = state->linalloc;
2176 $$ = new(ctx) ast_type_specifier($1);
2177 $$->set_location(@1);
2181 void *ctx = state->linalloc;
2182 $$ = new(ctx) ast_type_specifier($1);
2183 $$->set_location(@1);
2187 void *ctx = state->linalloc;
2188 $$ = new(ctx) ast_type_specifier($1);
2189 $$->set_location(@1);
2193 basic_type_specifier_nonarray:
2194 VOID_TOK { $$ = "void"; }
2195 | FLOAT_TOK { $$ = "float"; }
2196 | DOUBLE_TOK { $$ = "double"; }
2197 | INT_TOK { $$ = "int"; }
2198 | UINT_TOK { $$ = "uint"; }
2199 | BOOL_TOK { $$ = "bool"; }
2200 | VEC2 { $$ = "vec2"; }
2201 | VEC3 { $$ = "vec3"; }
2202 | VEC4 { $$ = "vec4"; }
2203 | BVEC2 { $$ = "bvec2"; }
2204 | BVEC3 { $$ = "bvec3"; }
2205 | BVEC4 { $$ = "bvec4"; }
2206 | IVEC2 { $$ = "ivec2"; }
2207 | IVEC3 { $$ = "ivec3"; }
2208 | IVEC4 { $$ = "ivec4"; }
2209 | UVEC2 { $$ = "uvec2"; }
2210 | UVEC3 { $$ = "uvec3"; }
2211 | UVEC4 { $$ = "uvec4"; }
2212 | DVEC2 { $$ = "dvec2"; }
2213 | DVEC3 { $$ = "dvec3"; }
2214 | DVEC4 { $$ = "dvec4"; }
2215 | MAT2X2 { $$ = "mat2"; }
2216 | MAT2X3 { $$ = "mat2x3"; }
2217 | MAT2X4 { $$ = "mat2x4"; }
2218 | MAT3X2 { $$ = "mat3x2"; }
2219 | MAT3X3 { $$ = "mat3"; }
2220 | MAT3X4 { $$ = "mat3x4"; }
2221 | MAT4X2 { $$ = "mat4x2"; }
2222 | MAT4X3 { $$ = "mat4x3"; }
2223 | MAT4X4 { $$ = "mat4"; }
2224 | DMAT2X2 { $$ = "dmat2"; }
2225 | DMAT2X3 { $$ = "dmat2x3"; }
2226 | DMAT2X4 { $$ = "dmat2x4"; }
2227 | DMAT3X2 { $$ = "dmat3x2"; }
2228 | DMAT3X3 { $$ = "dmat3"; }
2229 | DMAT3X4 { $$ = "dmat3x4"; }
2230 | DMAT4X2 { $$ = "dmat4x2"; }
2231 | DMAT4X3 { $$ = "dmat4x3"; }
2232 | DMAT4X4 { $$ = "dmat4"; }
2233 | SAMPLER1D { $$ = "sampler1D"; }
2234 | SAMPLER2D { $$ = "sampler2D"; }
2235 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2236 | SAMPLER3D { $$ = "sampler3D"; }
2237 | SAMPLERCUBE { $$ = "samplerCube"; }
2238 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2239 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2240 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2241 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2242 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2243 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2244 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2245 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2246 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2247 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2248 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2249 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2250 | ISAMPLER1D { $$ = "isampler1D"; }
2251 | ISAMPLER2D { $$ = "isampler2D"; }
2252 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2253 | ISAMPLER3D { $$ = "isampler3D"; }
2254 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2255 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2256 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2257 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2258 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2259 | USAMPLER1D { $$ = "usampler1D"; }
2260 | USAMPLER2D { $$ = "usampler2D"; }
2261 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2262 | USAMPLER3D { $$ = "usampler3D"; }
2263 | USAMPLERCUBE { $$ = "usamplerCube"; }
2264 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2265 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2266 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2267 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2268 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2269 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2270 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2271 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2272 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2273 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2274 | IMAGE1D { $$ = "image1D"; }
2275 | IMAGE2D { $$ = "image2D"; }
2276 | IMAGE3D { $$ = "image3D"; }
2277 | IMAGE2DRECT { $$ = "image2DRect"; }
2278 | IMAGECUBE { $$ = "imageCube"; }
2279 | IMAGEBUFFER { $$ = "imageBuffer"; }
2280 | IMAGE1DARRAY { $$ = "image1DArray"; }
2281 | IMAGE2DARRAY { $$ = "image2DArray"; }
2282 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2283 | IMAGE2DMS { $$ = "image2DMS"; }
2284 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2285 | IIMAGE1D { $$ = "iimage1D"; }
2286 | IIMAGE2D { $$ = "iimage2D"; }
2287 | IIMAGE3D { $$ = "iimage3D"; }
2288 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2289 | IIMAGECUBE { $$ = "iimageCube"; }
2290 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2291 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2292 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2293 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2294 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2295 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2296 | UIMAGE1D { $$ = "uimage1D"; }
2297 | UIMAGE2D { $$ = "uimage2D"; }
2298 | UIMAGE3D { $$ = "uimage3D"; }
2299 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2300 | UIMAGECUBE { $$ = "uimageCube"; }
2301 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2302 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2303 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2304 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2305 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2306 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2307 | ATOMIC_UINT { $$ = "atomic_uint"; }
2308 | INT64 { $$ = "int64_t"; }
2309 | I64VEC2 { $$ = "i64vec2"; }
2310 | I64VEC3 { $$ = "i64vec3"; }
2311 | I64VEC4 { $$ = "i64vec4"; }
2312 | UINT64 { $$ = "uint64_t"; }
2313 | U64VEC2 { $$ = "u64vec2"; }
2314 | U64VEC3 { $$ = "u64vec3"; }
2315 | U64VEC4 { $$ = "u64vec4"; }
2318 precision_qualifier:
2321 state->check_precision_qualifiers_allowed(&@1);
2322 $$ = ast_precision_high;
2326 state->check_precision_qualifiers_allowed(&@1);
2327 $$ = ast_precision_medium;
2331 state->check_precision_qualifiers_allowed(&@1);
2332 $$ = ast_precision_low;
2337 STRUCT any_identifier '{' struct_declaration_list '}'
2339 void *ctx = state->linalloc;
2340 $$ = new(ctx) ast_struct_specifier(ctx, $2, $4);
2341 $$->set_location_range(@2, @5);
2342 state->symbols->add_type($2, glsl_type::void_type);
2344 | STRUCT '{' struct_declaration_list '}'
2346 void *ctx = state->linalloc;
2347 $$ = new(ctx) ast_struct_specifier(ctx, NULL, $3);
2348 $$->set_location_range(@2, @4);
2352 struct_declaration_list:
2356 $1->link.self_link();
2358 | struct_declaration_list struct_declaration
2361 $$->link.insert_before(& $2->link);
2366 fully_specified_type struct_declarator_list ';'
2368 void *ctx = state->linalloc;
2369 ast_fully_specified_type *const type = $1;
2370 type->set_location(@1);
2372 if (type->qualifier.flags.i != 0)
2373 _mesa_glsl_error(&@1, state,
2374 "only precision qualifiers may be applied to "
2375 "structure members");
2377 $$ = new(ctx) ast_declarator_list(type);
2378 $$->set_location(@2);
2380 $$->declarations.push_degenerate_list_at_head(& $2->link);
2384 struct_declarator_list:
2388 $1->link.self_link();
2390 | struct_declarator_list ',' struct_declarator
2393 $$->link.insert_before(& $3->link);
2400 void *ctx = state->linalloc;
2401 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2402 $$->set_location(@1);
2404 | any_identifier array_specifier
2406 void *ctx = state->linalloc;
2407 $$ = new(ctx) ast_declaration($1, $2, NULL);
2408 $$->set_location_range(@1, @2);
2413 assignment_expression
2414 | '{' initializer_list '}'
2418 | '{' initializer_list ',' '}'
2427 void *ctx = state->linalloc;
2428 $$ = new(ctx) ast_aggregate_initializer();
2429 $$->set_location(@1);
2430 $$->expressions.push_tail(& $1->link);
2432 | initializer_list ',' initializer
2434 $1->expressions.push_tail(& $3->link);
2438 declaration_statement:
2442 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2445 compound_statement { $$ = (ast_node *) $1; }
2450 declaration_statement
2451 | expression_statement
2452 | selection_statement
2454 | iteration_statement
2461 void *ctx = state->linalloc;
2462 $$ = new(ctx) ast_compound_statement(true, NULL);
2463 $$->set_location_range(@1, @2);
2467 state->symbols->push_scope();
2471 void *ctx = state->linalloc;
2472 $$ = new(ctx) ast_compound_statement(true, $3);
2473 $$->set_location_range(@1, @4);
2474 state->symbols->pop_scope();
2478 statement_no_new_scope:
2479 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2483 compound_statement_no_new_scope:
2486 void *ctx = state->linalloc;
2487 $$ = new(ctx) ast_compound_statement(false, NULL);
2488 $$->set_location_range(@1, @2);
2490 | '{' statement_list '}'
2492 void *ctx = state->linalloc;
2493 $$ = new(ctx) ast_compound_statement(false, $2);
2494 $$->set_location_range(@1, @3);
2502 _mesa_glsl_error(& @1, state, "<nil> statement");
2507 $$->link.self_link();
2509 | statement_list statement
2512 _mesa_glsl_error(& @2, state, "<nil> statement");
2516 $$->link.insert_before(& $2->link);
2520 expression_statement:
2523 void *ctx = state->linalloc;
2524 $$ = new(ctx) ast_expression_statement(NULL);
2525 $$->set_location(@1);
2529 void *ctx = state->linalloc;
2530 $$ = new(ctx) ast_expression_statement($1);
2531 $$->set_location(@1);
2535 selection_statement:
2536 IF '(' expression ')' selection_rest_statement
2538 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2540 $$->set_location_range(@1, @5);
2544 selection_rest_statement:
2545 statement ELSE statement
2547 $$.then_statement = $1;
2548 $$.else_statement = $3;
2550 | statement %prec THEN
2552 $$.then_statement = $1;
2553 $$.else_statement = NULL;
2560 $$ = (ast_node *) $1;
2562 | fully_specified_type any_identifier '=' initializer
2564 void *ctx = state->linalloc;
2565 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2566 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2567 decl->set_location_range(@2, @4);
2568 declarator->set_location(@1);
2570 declarator->declarations.push_tail(&decl->link);
2576 * switch_statement grammar is based on the syntax described in the body
2577 * of the GLSL spec, not in it's appendix!!!
2580 SWITCH '(' expression ')' switch_body
2582 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2583 $$->set_location_range(@1, @5);
2590 $$ = new(state->linalloc) ast_switch_body(NULL);
2591 $$->set_location_range(@1, @2);
2593 | '{' case_statement_list '}'
2595 $$ = new(state->linalloc) ast_switch_body($2);
2596 $$->set_location_range(@1, @3);
2603 $$ = new(state->linalloc) ast_case_label($2);
2604 $$->set_location(@2);
2608 $$ = new(state->linalloc) ast_case_label(NULL);
2609 $$->set_location(@2);
2616 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2618 labels->labels.push_tail(& $1->link);
2620 $$->set_location(@1);
2622 | case_label_list case_label
2625 $$->labels.push_tail(& $2->link);
2630 case_label_list statement
2632 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2633 stmts->set_location(@2);
2635 stmts->stmts.push_tail(& $2->link);
2638 | case_statement statement
2641 $$->stmts.push_tail(& $2->link);
2645 case_statement_list:
2648 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2649 cases->set_location(@1);
2651 cases->cases.push_tail(& $1->link);
2654 | case_statement_list case_statement
2657 $$->cases.push_tail(& $2->link);
2661 iteration_statement:
2662 WHILE '(' condition ')' statement_no_new_scope
2664 void *ctx = state->linalloc;
2665 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2666 NULL, $3, NULL, $5);
2667 $$->set_location_range(@1, @4);
2669 | DO statement WHILE '(' expression ')' ';'
2671 void *ctx = state->linalloc;
2672 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2673 NULL, $5, NULL, $2);
2674 $$->set_location_range(@1, @6);
2676 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2678 void *ctx = state->linalloc;
2679 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2680 $3, $4.cond, $4.rest, $6);
2681 $$->set_location_range(@1, @6);
2686 expression_statement
2687 | declaration_statement
2704 | conditionopt ';' expression
2711 // Grammar Note: No 'goto'. Gotos are not supported.
2715 void *ctx = state->linalloc;
2716 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2717 $$->set_location(@1);
2721 void *ctx = state->linalloc;
2722 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2723 $$->set_location(@1);
2727 void *ctx = state->linalloc;
2728 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2729 $$->set_location(@1);
2731 | RETURN expression ';'
2733 void *ctx = state->linalloc;
2734 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2735 $$->set_location_range(@1, @2);
2737 | DISCARD ';' // Fragment shader only.
2739 void *ctx = state->linalloc;
2740 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2741 $$->set_location(@1);
2745 external_declaration:
2746 function_definition { $$ = $1; }
2747 | declaration { $$ = $1; }
2748 | pragma_statement { $$ = NULL; }
2749 | layout_defaults { $$ = $1; }
2752 function_definition:
2753 function_prototype compound_statement_no_new_scope
2755 void *ctx = state->linalloc;
2756 $$ = new(ctx) ast_function_definition();
2757 $$->set_location_range(@1, @2);
2761 state->symbols->pop_scope();
2765 /* layout_qualifieropt is packed into this rule */
2767 basic_interface_block
2771 | layout_qualifier interface_block
2773 ast_interface_block *block = (ast_interface_block *) $2;
2775 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2776 block->layout.has_layout())) {
2784 | memory_qualifier interface_block
2786 ast_interface_block *block = (ast_interface_block *)$2;
2788 if (!block->default_layout.flags.q.buffer) {
2789 _mesa_glsl_error(& @1, state,
2790 "memory qualifiers can only be used in the "
2791 "declaration of shader storage blocks");
2793 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2801 basic_interface_block:
2802 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2804 ast_interface_block *const block = $6;
2806 if ($1.flags.q.uniform) {
2807 block->default_layout = *state->default_uniform_qualifier;
2808 } else if ($1.flags.q.buffer) {
2809 block->default_layout = *state->default_shader_storage_qualifier;
2811 block->block_name = $2;
2812 block->declarations.push_degenerate_list_at_head(& $4->link);
2814 _mesa_ast_process_interface_block(& @1, state, block, $1);
2820 interface_qualifier:
2823 memset(& $$, 0, sizeof($$));
2828 memset(& $$, 0, sizeof($$));
2833 memset(& $$, 0, sizeof($$));
2834 $$.flags.q.uniform = 1;
2838 memset(& $$, 0, sizeof($$));
2839 $$.flags.q.buffer = 1;
2841 | auxiliary_storage_qualifier interface_qualifier
2843 if (!$1.flags.q.patch) {
2844 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2846 if ($2.has_auxiliary_storage()) {
2847 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2850 $$.flags.q.patch = 1;
2857 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2861 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2862 $$->set_location(@1);
2864 | NEW_IDENTIFIER array_specifier
2866 $$ = new(state->linalloc) ast_interface_block($1, $2);
2867 $$->set_location_range(@1, @2);
2875 $1->link.self_link();
2877 | member_declaration member_list
2880 $2->link.insert_before(& $$->link);
2885 fully_specified_type struct_declarator_list ';'
2887 void *ctx = state->linalloc;
2888 ast_fully_specified_type *type = $1;
2889 type->set_location(@1);
2891 if (type->qualifier.flags.q.attribute) {
2892 _mesa_glsl_error(& @1, state,
2893 "keyword 'attribute' cannot be used with "
2894 "interface block member");
2895 } else if (type->qualifier.flags.q.varying) {
2896 _mesa_glsl_error(& @1, state,
2897 "keyword 'varying' cannot be used with "
2898 "interface block member");
2901 $$ = new(ctx) ast_declarator_list(type);
2902 $$->set_location(@2);
2904 $$->declarations.push_degenerate_list_at_head(& $2->link);
2908 layout_uniform_defaults:
2909 layout_qualifier layout_uniform_defaults
2912 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2916 | layout_qualifier UNIFORM ';'
2919 layout_buffer_defaults:
2920 layout_qualifier layout_buffer_defaults
2923 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2927 | layout_qualifier BUFFER ';'
2931 layout_qualifier layout_in_defaults
2934 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2937 if (!$$.validate_in_qualifier(& @1, state)) {
2941 | layout_qualifier IN_TOK ';'
2943 if (!$1.validate_in_qualifier(& @1, state)) {
2949 layout_out_defaults:
2950 layout_qualifier layout_out_defaults
2953 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2956 if (!$$.validate_out_qualifier(& @1, state)) {
2960 | layout_qualifier OUT_TOK ';'
2962 if (!$1.validate_out_qualifier(& @1, state)) {
2969 layout_uniform_defaults
2972 if (!state->default_uniform_qualifier->
2973 merge_qualifier(& @1, state, $1, false)) {
2976 if (!state->default_uniform_qualifier->
2977 push_to_global(& @1, state)) {
2981 | layout_buffer_defaults
2984 if (!state->default_shader_storage_qualifier->
2985 merge_qualifier(& @1, state, $1, false)) {
2988 if (!state->default_shader_storage_qualifier->
2989 push_to_global(& @1, state)) {
2993 /* From the GLSL 4.50 spec, section 4.4.5:
2995 * "It is a compile-time error to specify the binding identifier for
2996 * the global scope or for block member declarations."
2998 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2999 _mesa_glsl_error(& @1, state,
3000 "binding qualifier cannot be set for default layout");
3003 | layout_in_defaults
3006 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
3009 if (!state->in_qualifier->push_to_global(& @1, state)) {
3013 | layout_out_defaults
3016 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
3019 if (!state->out_qualifier->push_to_global(& @1, state)) {