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 <node> layout_uniform_defaults
301 %type <node> layout_buffer_defaults
302 %type <node> layout_in_defaults
303 %type <node> 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");
436 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
437 $$->set_location(@1);
438 $$->primary_expression.identifier = $1;
443 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
444 $$->set_location(@1);
445 $$->primary_expression.int_constant = $1;
450 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
451 $$->set_location(@1);
452 $$->primary_expression.uint_constant = $1;
457 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
458 $$->set_location(@1);
459 $$->primary_expression.float_constant = $1;
464 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
465 $$->set_location(@1);
466 $$->primary_expression.double_constant = $1;
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 ']'
486 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
487 $$->set_location_range(@1, @4);
493 | postfix_expression DOT_TOK FIELD_SELECTION
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
503 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
504 $$->set_location_range(@1, @2);
506 | postfix_expression DEC_OP
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 '('
562 $$ = new(ctx) ast_function_expression($1);
563 $$->set_location(@1);
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
583 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
584 $$->set_location(@1);
586 | DEC_OP unary_expression
589 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
590 $$->set_location(@1);
592 | unary_operator unary_expression
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
613 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
614 $$->set_location_range(@1, @3);
616 | multiplicative_expression '/' unary_expression
619 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
620 $$->set_location_range(@1, @3);
622 | multiplicative_expression '%' unary_expression
625 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
626 $$->set_location_range(@1, @3);
631 multiplicative_expression
632 | additive_expression '+' multiplicative_expression
635 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
636 $$->set_location_range(@1, @3);
638 | additive_expression '-' multiplicative_expression
641 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
642 $$->set_location_range(@1, @3);
648 | shift_expression LEFT_OP additive_expression
651 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
652 $$->set_location_range(@1, @3);
654 | shift_expression RIGHT_OP additive_expression
657 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
658 $$->set_location_range(@1, @3);
662 relational_expression:
664 | relational_expression '<' shift_expression
667 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
668 $$->set_location_range(@1, @3);
670 | relational_expression '>' shift_expression
673 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
674 $$->set_location_range(@1, @3);
676 | relational_expression LE_OP shift_expression
679 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
680 $$->set_location_range(@1, @3);
682 | relational_expression GE_OP shift_expression
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
695 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
696 $$->set_location_range(@1, @3);
698 | equality_expression NE_OP relational_expression
701 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
702 $$->set_location_range(@1, @3);
708 | and_expression '&' equality_expression
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
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
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
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
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
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
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
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
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;
846 function_declarator ')'
851 | function_header_with_parameters
854 function_header_with_parameters:
855 function_header parameter_declaration
858 $$->parameters.push_tail(& $2->link);
860 | function_header_with_parameters ',' parameter_declaration
863 $$->parameters.push_tail(& $3->link);
868 fully_specified_type variable_identifier '('
871 $$ = new(ctx) ast_function();
872 $$->set_location(@2);
873 $$->return_type = $1;
876 if ($1->qualifier.flags.q.subroutine) {
877 /* add type for IDENTIFIER search */
878 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
880 state->symbols->add_function(new(state) ir_function($2));
881 state->symbols->push_scope();
885 parameter_declarator:
886 type_specifier any_identifier
889 $$ = new(ctx) ast_parameter_declarator();
890 $$->set_location_range(@1, @2);
891 $$->type = new(ctx) ast_fully_specified_type();
892 $$->type->set_location(@1);
893 $$->type->specifier = $1;
895 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
897 | type_specifier any_identifier array_specifier
900 $$ = new(ctx) ast_parameter_declarator();
901 $$->set_location_range(@1, @3);
902 $$->type = new(ctx) ast_fully_specified_type();
903 $$->type->set_location(@1);
904 $$->type->specifier = $1;
906 $$->array_specifier = $3;
907 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
911 parameter_declaration:
912 parameter_qualifier parameter_declarator
915 $$->type->qualifier = $1;
917 | parameter_qualifier parameter_type_specifier
920 $$ = new(ctx) ast_parameter_declarator();
921 $$->set_location(@2);
922 $$->type = new(ctx) ast_fully_specified_type();
923 $$->type->set_location_range(@1, @2);
924 $$->type->qualifier = $1;
925 $$->type->specifier = $2;
932 memset(& $$, 0, sizeof($$));
934 | CONST_TOK parameter_qualifier
936 if ($2.flags.q.constant)
937 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
940 $$.flags.q.constant = 1;
942 | PRECISE parameter_qualifier
944 if ($2.flags.q.precise)
945 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
948 $$.flags.q.precise = 1;
950 | parameter_direction_qualifier parameter_qualifier
952 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
953 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
955 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
956 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
960 $$.merge_qualifier(&@1, state, $2, false);
962 | precision_qualifier parameter_qualifier
964 if ($2.precision != ast_precision_none)
965 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
967 if (!state->has_420pack_or_es31() &&
969 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
974 | memory_qualifier parameter_qualifier
977 $$.merge_qualifier(&@1, state, $2, false);
980 parameter_direction_qualifier:
983 memset(& $$, 0, sizeof($$));
988 memset(& $$, 0, sizeof($$));
993 memset(& $$, 0, sizeof($$));
999 parameter_type_specifier:
1003 init_declarator_list:
1005 | init_declarator_list ',' any_identifier
1008 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1009 decl->set_location(@3);
1012 $$->declarations.push_tail(&decl->link);
1013 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1015 | init_declarator_list ',' any_identifier array_specifier
1018 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1019 decl->set_location_range(@3, @4);
1022 $$->declarations.push_tail(&decl->link);
1023 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1025 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1028 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1029 decl->set_location_range(@3, @4);
1032 $$->declarations.push_tail(&decl->link);
1033 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1035 | init_declarator_list ',' any_identifier '=' initializer
1038 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1039 decl->set_location(@3);
1042 $$->declarations.push_tail(&decl->link);
1043 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1047 // Grammar Note: No 'enum', or 'typedef'.
1049 fully_specified_type
1052 /* Empty declaration list is valid. */
1053 $$ = new(ctx) ast_declarator_list($1);
1054 $$->set_location(@1);
1056 | fully_specified_type any_identifier
1059 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1060 decl->set_location(@2);
1062 $$ = new(ctx) ast_declarator_list($1);
1063 $$->set_location_range(@1, @2);
1064 $$->declarations.push_tail(&decl->link);
1065 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1067 | fully_specified_type any_identifier array_specifier
1070 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1071 decl->set_location_range(@2, @3);
1073 $$ = new(ctx) ast_declarator_list($1);
1074 $$->set_location_range(@1, @3);
1075 $$->declarations.push_tail(&decl->link);
1076 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1078 | fully_specified_type any_identifier array_specifier '=' initializer
1081 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1082 decl->set_location_range(@2, @3);
1084 $$ = new(ctx) ast_declarator_list($1);
1085 $$->set_location_range(@1, @3);
1086 $$->declarations.push_tail(&decl->link);
1087 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1089 | fully_specified_type any_identifier '=' initializer
1092 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1093 decl->set_location(@2);
1095 $$ = new(ctx) ast_declarator_list($1);
1096 $$->set_location_range(@1, @2);
1097 $$->declarations.push_tail(&decl->link);
1098 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1100 | INVARIANT variable_identifier
1103 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1104 decl->set_location(@2);
1106 $$ = new(ctx) ast_declarator_list(NULL);
1107 $$->set_location_range(@1, @2);
1108 $$->invariant = true;
1110 $$->declarations.push_tail(&decl->link);
1112 | PRECISE variable_identifier
1115 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1116 decl->set_location(@2);
1118 $$ = new(ctx) ast_declarator_list(NULL);
1119 $$->set_location_range(@1, @2);
1122 $$->declarations.push_tail(&decl->link);
1126 fully_specified_type:
1130 $$ = new(ctx) ast_fully_specified_type();
1131 $$->set_location(@1);
1134 | type_qualifier type_specifier
1137 $$ = new(ctx) ast_fully_specified_type();
1138 $$->set_location_range(@1, @2);
1141 if ($$->specifier->structure != NULL &&
1142 $$->specifier->structure->is_declaration) {
1143 $$->specifier->structure->layout = &$$->qualifier;
1149 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1155 layout_qualifier_id_list:
1157 | layout_qualifier_id_list ',' layout_qualifier_id
1160 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1166 layout_qualifier_id:
1169 memset(& $$, 0, sizeof($$));
1171 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1172 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1173 state->is_version(150, 0))) {
1174 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1175 $$.flags.q.origin_upper_left = 1;
1176 } else if (match_layout_qualifier($1, "pixel_center_integer",
1178 $$.flags.q.pixel_center_integer = 1;
1181 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1182 _mesa_glsl_warning(& @1, state,
1183 "GL_ARB_fragment_coord_conventions layout "
1184 "identifier `%s' used", $1);
1188 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1190 (state->AMD_conservative_depth_enable ||
1191 state->ARB_conservative_depth_enable ||
1192 state->is_version(420, 0))) {
1193 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1194 $$.flags.q.depth_any = 1;
1195 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1196 $$.flags.q.depth_greater = 1;
1197 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1198 $$.flags.q.depth_less = 1;
1199 } else if (match_layout_qualifier($1, "depth_unchanged",
1201 $$.flags.q.depth_unchanged = 1;
1204 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1205 _mesa_glsl_warning(& @1, state,
1206 "GL_AMD_conservative_depth "
1207 "layout qualifier `%s' is used", $1);
1209 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1210 _mesa_glsl_warning(& @1, state,
1211 "GL_ARB_conservative_depth "
1212 "layout qualifier `%s' is used", $1);
1216 /* See also interface_block_layout_qualifier. */
1217 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1218 if (match_layout_qualifier($1, "std140", state) == 0) {
1219 $$.flags.q.std140 = 1;
1220 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1221 $$.flags.q.shared = 1;
1222 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1223 $$.flags.q.std430 = 1;
1224 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1225 $$.flags.q.column_major = 1;
1226 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1227 * below in the interface_block_layout_qualifier rule.
1229 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1232 * Also, this takes care of alternate capitalizations of
1233 * "row_major" (which is necessary because layout qualifiers
1234 * are case-insensitive in desktop GLSL).
1236 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1237 $$.flags.q.row_major = 1;
1238 /* "packed" is a reserved word in GLSL, and its token is
1239 * parsed below in the interface_block_layout_qualifier rule.
1240 * However, we must take care of alternate capitalizations of
1241 * "packed", because layout qualifiers are case-insensitive
1244 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1245 $$.flags.q.packed = 1;
1248 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1249 _mesa_glsl_warning(& @1, state,
1250 "#version 140 / GL_ARB_uniform_buffer_object "
1251 "layout qualifier `%s' is used", $1);
1255 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1257 static const struct {
1261 { "points", GL_POINTS },
1262 { "lines", GL_LINES },
1263 { "lines_adjacency", GL_LINES_ADJACENCY },
1264 { "line_strip", GL_LINE_STRIP },
1265 { "triangles", GL_TRIANGLES },
1266 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1267 { "triangle_strip", GL_TRIANGLE_STRIP },
1269 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1270 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1271 $$.flags.q.prim_type = 1;
1272 $$.prim_type = map[i].e;
1277 if ($$.flags.i && !state->has_geometry_shader() &&
1278 !state->has_tessellation_shader()) {
1279 _mesa_glsl_error(& @1, state, "#version 150 layout "
1280 "qualifier `%s' used", $1);
1284 /* Layout qualifiers for ARB_shader_image_load_store. */
1285 if (state->ARB_shader_image_load_store_enable ||
1286 state->is_version(420, 310)) {
1288 static const struct {
1291 glsl_base_type base_type;
1292 /** Minimum desktop GLSL version required for the image
1293 * format. Use 130 if already present in the original
1296 unsigned required_glsl;
1297 /** Minimum GLSL ES version required for the image format. */
1298 unsigned required_essl;
1300 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1301 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1302 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1303 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1304 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1305 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1306 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1307 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1308 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1309 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1310 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1311 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1312 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1313 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1314 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1315 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1316 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1317 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1318 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1319 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1320 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1321 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1322 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1323 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1324 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1325 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1326 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1327 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1328 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1329 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1330 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1331 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1332 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1333 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1334 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1335 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1336 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1337 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1338 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1341 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1342 if (state->is_version(map[i].required_glsl,
1343 map[i].required_essl) &&
1344 match_layout_qualifier($1, map[i].name, state) == 0) {
1345 $$.flags.q.explicit_image_format = 1;
1346 $$.image_format = map[i].format;
1347 $$.image_base_type = map[i].base_type;
1354 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1355 /* From section 4.4.1.3 of the GLSL 4.50 specification
1356 * (Fragment Shader Inputs):
1358 * "Fragment shaders also allow the following layout
1359 * qualifier on in only (not with variable declarations)
1360 * layout-qualifier-id
1361 * early_fragment_tests
1364 if (state->stage != MESA_SHADER_FRAGMENT) {
1365 _mesa_glsl_error(& @1, state,
1366 "early_fragment_tests layout qualifier only "
1367 "valid in fragment shaders");
1370 $$.flags.q.early_fragment_tests = 1;
1374 /* Layout qualifiers for tessellation evaluation shaders. */
1376 static const struct {
1380 /* triangles already parsed by gs-specific code */
1381 { "quads", GL_QUADS },
1382 { "isolines", GL_ISOLINES },
1384 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1385 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1386 $$.flags.q.prim_type = 1;
1387 $$.prim_type = map[i].e;
1392 if ($$.flags.i && !state->has_tessellation_shader()) {
1393 _mesa_glsl_error(& @1, state,
1394 "primitive mode qualifier `%s' requires "
1395 "GLSL 4.00 or ARB_tessellation_shader", $1);
1399 static const struct {
1403 { "equal_spacing", GL_EQUAL },
1404 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1405 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1407 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1408 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1409 $$.flags.q.vertex_spacing = 1;
1410 $$.vertex_spacing = map[i].e;
1415 if ($$.flags.i && !state->has_tessellation_shader()) {
1416 _mesa_glsl_error(& @1, state,
1417 "vertex spacing qualifier `%s' requires "
1418 "GLSL 4.00 or ARB_tessellation_shader", $1);
1422 if (match_layout_qualifier($1, "cw", state) == 0) {
1423 $$.flags.q.ordering = 1;
1424 $$.ordering = GL_CW;
1425 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1426 $$.flags.q.ordering = 1;
1427 $$.ordering = GL_CCW;
1430 if ($$.flags.i && !state->has_tessellation_shader()) {
1431 _mesa_glsl_error(& @1, state,
1432 "ordering qualifier `%s' requires "
1433 "GLSL 4.00 or ARB_tessellation_shader", $1);
1437 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1438 $$.flags.q.point_mode = 1;
1439 $$.point_mode = true;
1442 if ($$.flags.i && !state->has_tessellation_shader()) {
1443 _mesa_glsl_error(& @1, state,
1444 "qualifier `point_mode' requires "
1445 "GLSL 4.00 or ARB_tessellation_shader");
1450 static const struct {
1454 { "blend_support_multiply", BLEND_MULTIPLY },
1455 { "blend_support_screen", BLEND_SCREEN },
1456 { "blend_support_overlay", BLEND_OVERLAY },
1457 { "blend_support_darken", BLEND_DARKEN },
1458 { "blend_support_lighten", BLEND_LIGHTEN },
1459 { "blend_support_colordodge", BLEND_COLORDODGE },
1460 { "blend_support_colorburn", BLEND_COLORBURN },
1461 { "blend_support_hardlight", BLEND_HARDLIGHT },
1462 { "blend_support_softlight", BLEND_SOFTLIGHT },
1463 { "blend_support_difference", BLEND_DIFFERENCE },
1464 { "blend_support_exclusion", BLEND_EXCLUSION },
1465 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1466 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1467 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1468 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1469 { "blend_support_all_equations", BLEND_ALL },
1471 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1472 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1473 $$.flags.q.blend_support = 1;
1474 state->fs_blend_support |= map[i].mask;
1480 !state->KHR_blend_equation_advanced_enable &&
1481 !state->is_version(0, 320)) {
1482 _mesa_glsl_error(& @1, state,
1483 "advanced blending layout qualifiers require "
1484 "ESSL 3.20 or KHR_blend_equation_advanced");
1487 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1488 _mesa_glsl_error(& @1, state,
1489 "advanced blending layout qualifiers only "
1490 "valid in fragment shaders");
1495 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1500 | any_identifier '=' constant_expression
1502 memset(& $$, 0, sizeof($$));
1505 if ($3->oper != ast_int_constant &&
1506 $3->oper != ast_uint_constant &&
1507 !state->has_enhanced_layouts()) {
1508 _mesa_glsl_error(& @1, state,
1509 "compile-time constant expressions require "
1510 "GLSL 4.40 or ARB_enhanced_layouts");
1513 if (match_layout_qualifier("align", $1, state) == 0) {
1514 if (!state->has_enhanced_layouts()) {
1515 _mesa_glsl_error(& @1, state,
1516 "align qualifier requires "
1517 "GLSL 4.40 or ARB_enhanced_layouts");
1519 $$.flags.q.explicit_align = 1;
1524 if (match_layout_qualifier("location", $1, state) == 0) {
1525 $$.flags.q.explicit_location = 1;
1527 if ($$.flags.q.attribute == 1 &&
1528 state->ARB_explicit_attrib_location_warn) {
1529 _mesa_glsl_warning(& @1, state,
1530 "GL_ARB_explicit_attrib_location layout "
1531 "identifier `%s' used", $1);
1536 if (match_layout_qualifier("component", $1, state) == 0) {
1537 if (!state->has_enhanced_layouts()) {
1538 _mesa_glsl_error(& @1, state,
1539 "component qualifier requires "
1540 "GLSL 4.40 or ARB_enhanced_layouts");
1542 $$.flags.q.explicit_component = 1;
1547 if (match_layout_qualifier("index", $1, state) == 0) {
1548 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1549 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1553 $$.flags.q.explicit_index = 1;
1557 if ((state->has_420pack_or_es31() ||
1558 state->has_atomic_counters() ||
1559 state->has_shader_storage_buffer_objects()) &&
1560 match_layout_qualifier("binding", $1, state) == 0) {
1561 $$.flags.q.explicit_binding = 1;
1565 if ((state->has_atomic_counters() ||
1566 state->has_enhanced_layouts()) &&
1567 match_layout_qualifier("offset", $1, state) == 0) {
1568 $$.flags.q.explicit_offset = 1;
1572 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1573 $$.flags.q.max_vertices = 1;
1574 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1575 if (!state->has_geometry_shader()) {
1576 _mesa_glsl_error(& @3, state,
1577 "#version 150 max_vertices qualifier "
1582 if (state->stage == MESA_SHADER_GEOMETRY) {
1583 if (match_layout_qualifier("stream", $1, state) == 0 &&
1584 state->check_explicit_attrib_stream_allowed(& @3)) {
1585 $$.flags.q.stream = 1;
1586 $$.flags.q.explicit_stream = 1;
1591 if (state->has_enhanced_layouts()) {
1592 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1593 $$.flags.q.xfb_buffer = 1;
1594 $$.flags.q.explicit_xfb_buffer = 1;
1598 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1599 $$.flags.q.explicit_xfb_offset = 1;
1603 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1604 $$.flags.q.xfb_stride = 1;
1605 $$.flags.q.explicit_xfb_stride = 1;
1610 static const char * const local_size_qualifiers[3] = {
1615 for (int i = 0; i < 3; i++) {
1616 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1618 if (!state->has_compute_shader()) {
1619 _mesa_glsl_error(& @3, state,
1620 "%s qualifier requires GLSL 4.30 or "
1621 "GLSL ES 3.10 or ARB_compute_shader",
1622 local_size_qualifiers[i]);
1625 $$.flags.q.local_size |= (1 << i);
1626 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1632 if (match_layout_qualifier("invocations", $1, state) == 0) {
1633 $$.flags.q.invocations = 1;
1634 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1635 if (!state->is_version(400, 320) &&
1636 !state->ARB_gpu_shader5_enable &&
1637 !state->OES_geometry_shader_enable &&
1638 !state->EXT_geometry_shader_enable) {
1639 _mesa_glsl_error(& @3, state,
1640 "GL_ARB_gpu_shader5 invocations "
1641 "qualifier specified", $3);
1645 /* Layout qualifiers for tessellation control shaders. */
1646 if (match_layout_qualifier("vertices", $1, state) == 0) {
1647 $$.flags.q.vertices = 1;
1648 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1649 if (!state->has_tessellation_shader()) {
1650 _mesa_glsl_error(& @1, state,
1651 "vertices qualifier requires GLSL 4.00 or "
1652 "ARB_tessellation_shader");
1656 /* If the identifier didn't match any known layout identifiers,
1660 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1665 | interface_block_layout_qualifier
1668 /* Layout qualifiers for ARB_uniform_buffer_object. */
1669 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1670 _mesa_glsl_error(& @1, state,
1671 "#version 140 / GL_ARB_uniform_buffer_object "
1672 "layout qualifier `%s' is used", $1);
1673 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1674 _mesa_glsl_warning(& @1, state,
1675 "#version 140 / GL_ARB_uniform_buffer_object "
1676 "layout qualifier `%s' is used", $1);
1681 /* This is a separate language rule because we parse these as tokens
1682 * (due to them being reserved keywords) instead of identifiers like
1683 * most qualifiers. See the any_identifier path of
1684 * layout_qualifier_id for the others.
1686 * Note that since layout qualifiers are case-insensitive in desktop
1687 * GLSL, all of these qualifiers need to be handled as identifiers as
1688 * well (by the any_identifier path of layout_qualifier_id).
1690 interface_block_layout_qualifier:
1693 memset(& $$, 0, sizeof($$));
1694 $$.flags.q.row_major = 1;
1698 memset(& $$, 0, sizeof($$));
1699 $$.flags.q.packed = 1;
1703 memset(& $$, 0, sizeof($$));
1704 $$.flags.q.shared = 1;
1708 subroutine_qualifier:
1711 memset(& $$, 0, sizeof($$));
1712 $$.flags.q.subroutine = 1;
1714 | SUBROUTINE '(' subroutine_type_list ')'
1716 memset(& $$, 0, sizeof($$));
1717 $$.flags.q.subroutine_def = 1;
1718 $$.subroutine_list = $3;
1722 subroutine_type_list:
1726 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1727 decl->set_location(@1);
1729 $$ = new(ctx) ast_subroutine_list();
1730 $$->declarations.push_tail(&decl->link);
1732 | subroutine_type_list ',' any_identifier
1735 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1736 decl->set_location(@3);
1739 $$->declarations.push_tail(&decl->link);
1743 interpolation_qualifier:
1746 memset(& $$, 0, sizeof($$));
1747 $$.flags.q.smooth = 1;
1751 memset(& $$, 0, sizeof($$));
1752 $$.flags.q.flat = 1;
1756 memset(& $$, 0, sizeof($$));
1757 $$.flags.q.noperspective = 1;
1762 /* Single qualifiers */
1765 memset(& $$, 0, sizeof($$));
1766 $$.flags.q.invariant = 1;
1770 memset(& $$, 0, sizeof($$));
1771 $$.flags.q.precise = 1;
1773 | auxiliary_storage_qualifier
1775 | interpolation_qualifier
1778 | subroutine_qualifier
1779 | precision_qualifier
1781 memset(&$$, 0, sizeof($$));
1785 /* Multiple qualifiers:
1786 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1787 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1789 * invariant interpolation auxiliary storage precision ...or...
1790 * layout storage precision
1792 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1793 * side don't contain any that must appear on the left hand side.
1794 * For example, when processing a storage qualifier, we check that there are
1795 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1797 | PRECISE type_qualifier
1799 if ($2.flags.q.precise)
1800 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1803 $$.flags.q.precise = 1;
1805 | INVARIANT type_qualifier
1807 if ($2.flags.q.invariant)
1808 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1810 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1811 _mesa_glsl_error(&@1, state,
1812 "\"invariant\" must come after \"precise\"");
1815 $$.flags.q.invariant = 1;
1817 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1819 * "Only variables output from a shader can be candidates for invariance.
1820 * This includes user-defined output variables and the built-in output
1821 * variables. As only outputs can be declared as invariant, an invariant
1822 * output from one shader stage will still match an input of a subsequent
1823 * stage without the input being declared as invariant."
1825 * On the desktop side, this text first appears in GLSL 4.30.
1827 if (state->is_version(430, 300) && $$.flags.q.in)
1828 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1830 | interpolation_qualifier type_qualifier
1832 /* Section 4.3 of the GLSL 1.40 specification states:
1833 * "...qualified with one of these interpolation qualifiers"
1835 * GLSL 1.30 claims to allow "one or more", but insists that:
1836 * "These interpolation qualifiers may only precede the qualifiers in,
1837 * centroid in, out, or centroid out in a declaration."
1839 * ...which means that e.g. smooth can't precede smooth, so there can be
1840 * only one after all, and the 1.40 text is a clarification, not a change.
1842 if ($2.has_interpolation())
1843 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1845 if (!state->has_420pack_or_es31() &&
1846 ($2.flags.q.precise || $2.flags.q.invariant)) {
1847 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1848 "after \"precise\" or \"invariant\"");
1852 $$.merge_qualifier(&@1, state, $2, false);
1854 | layout_qualifier type_qualifier
1856 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1857 * appear no later than auxiliary storage qualifiers. There is no
1858 * particularly clear spec language mandating this, but in all examples
1859 * the layout qualifier precedes the storage qualifier.
1861 * We allow combinations of layout with interpolation, invariant or
1862 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1863 * There is no clear spec guidance on this either.
1865 if (!state->has_420pack_or_es31() && $2.has_layout())
1866 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1869 $$.merge_qualifier(&@1, state, $2, false);
1871 | subroutine_qualifier type_qualifier
1874 $$.merge_qualifier(&@1, state, $2, false);
1876 | auxiliary_storage_qualifier type_qualifier
1878 if ($2.has_auxiliary_storage()) {
1879 _mesa_glsl_error(&@1, state,
1880 "duplicate auxiliary storage qualifier (centroid or sample)");
1883 if (!state->has_420pack_or_es31() &&
1884 ($2.flags.q.precise || $2.flags.q.invariant ||
1885 $2.has_interpolation() || $2.has_layout())) {
1886 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1887 "just before storage qualifiers");
1890 $$.merge_qualifier(&@1, state, $2, false);
1892 | storage_qualifier type_qualifier
1894 /* Section 4.3 of the GLSL 1.20 specification states:
1895 * "Variable declarations may have a storage qualifier specified..."
1896 * 1.30 clarifies this to "may have one storage qualifier".
1898 if ($2.has_storage())
1899 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1901 if (!state->has_420pack_or_es31() &&
1902 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1903 $2.has_layout() || $2.has_auxiliary_storage())) {
1904 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1905 "precise, invariant, interpolation, layout and auxiliary "
1906 "storage qualifiers");
1910 $$.merge_qualifier(&@1, state, $2, false);
1912 | precision_qualifier type_qualifier
1914 if ($2.precision != ast_precision_none)
1915 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1917 if (!(state->has_420pack_or_es31()) &&
1919 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1924 | memory_qualifier type_qualifier
1927 $$.merge_qualifier(&@1, state, $2, false);
1931 auxiliary_storage_qualifier:
1934 memset(& $$, 0, sizeof($$));
1935 $$.flags.q.centroid = 1;
1939 memset(& $$, 0, sizeof($$));
1940 $$.flags.q.sample = 1;
1944 memset(& $$, 0, sizeof($$));
1945 $$.flags.q.patch = 1;
1951 memset(& $$, 0, sizeof($$));
1952 $$.flags.q.constant = 1;
1956 memset(& $$, 0, sizeof($$));
1957 $$.flags.q.attribute = 1;
1961 memset(& $$, 0, sizeof($$));
1962 $$.flags.q.varying = 1;
1966 memset(& $$, 0, sizeof($$));
1971 memset(& $$, 0, sizeof($$));
1974 if (state->stage == MESA_SHADER_GEOMETRY &&
1975 state->has_explicit_attrib_stream()) {
1976 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1979 * "If the block or variable is declared with the stream
1980 * identifier, it is associated with the specified stream;
1981 * otherwise, it is associated with the current default stream."
1983 $$.flags.q.stream = 1;
1984 $$.flags.q.explicit_stream = 0;
1985 $$.stream = state->out_qualifier->stream;
1988 if (state->has_enhanced_layouts()) {
1989 $$.flags.q.xfb_buffer = 1;
1990 $$.flags.q.explicit_xfb_buffer = 0;
1991 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
1996 memset(& $$, 0, sizeof($$));
2000 if (!state->has_framebuffer_fetch() ||
2001 !state->is_version(130, 300) ||
2002 state->stage != MESA_SHADER_FRAGMENT)
2003 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2004 "declared as both input and output");
2008 memset(& $$, 0, sizeof($$));
2009 $$.flags.q.uniform = 1;
2013 memset(& $$, 0, sizeof($$));
2014 $$.flags.q.buffer = 1;
2018 memset(& $$, 0, sizeof($$));
2019 $$.flags.q.shared_storage = 1;
2026 memset(& $$, 0, sizeof($$));
2027 $$.flags.q.coherent = 1;
2031 memset(& $$, 0, sizeof($$));
2032 $$.flags.q._volatile = 1;
2036 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2037 memset(& $$, 0, sizeof($$));
2038 $$.flags.q.restrict_flag = 1;
2042 memset(& $$, 0, sizeof($$));
2043 $$.flags.q.read_only = 1;
2047 memset(& $$, 0, sizeof($$));
2048 $$.flags.q.write_only = 1;
2056 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2057 ast_unsized_array_dim, NULL,
2059 $$->set_location_range(@1, @2);
2061 | '[' constant_expression ']'
2064 $$ = new(ctx) ast_array_specifier(@1, $2);
2065 $$->set_location_range(@1, @3);
2067 | array_specifier '[' ']'
2072 if (state->check_arrays_of_arrays_allowed(& @1)) {
2073 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2077 | array_specifier '[' constant_expression ']'
2081 if (state->check_arrays_of_arrays_allowed(& @1)) {
2082 $$->add_dimension($3);
2088 type_specifier_nonarray
2089 | type_specifier_nonarray array_specifier
2092 $$->array_specifier = $2;
2096 type_specifier_nonarray:
2097 basic_type_specifier_nonarray
2100 $$ = new(ctx) ast_type_specifier($1);
2101 $$->set_location(@1);
2106 $$ = new(ctx) ast_type_specifier($1);
2107 $$->set_location(@1);
2112 $$ = new(ctx) ast_type_specifier($1);
2113 $$->set_location(@1);
2117 basic_type_specifier_nonarray:
2118 VOID_TOK { $$ = "void"; }
2119 | FLOAT_TOK { $$ = "float"; }
2120 | DOUBLE_TOK { $$ = "double"; }
2121 | INT_TOK { $$ = "int"; }
2122 | UINT_TOK { $$ = "uint"; }
2123 | BOOL_TOK { $$ = "bool"; }
2124 | VEC2 { $$ = "vec2"; }
2125 | VEC3 { $$ = "vec3"; }
2126 | VEC4 { $$ = "vec4"; }
2127 | BVEC2 { $$ = "bvec2"; }
2128 | BVEC3 { $$ = "bvec3"; }
2129 | BVEC4 { $$ = "bvec4"; }
2130 | IVEC2 { $$ = "ivec2"; }
2131 | IVEC3 { $$ = "ivec3"; }
2132 | IVEC4 { $$ = "ivec4"; }
2133 | UVEC2 { $$ = "uvec2"; }
2134 | UVEC3 { $$ = "uvec3"; }
2135 | UVEC4 { $$ = "uvec4"; }
2136 | DVEC2 { $$ = "dvec2"; }
2137 | DVEC3 { $$ = "dvec3"; }
2138 | DVEC4 { $$ = "dvec4"; }
2139 | MAT2X2 { $$ = "mat2"; }
2140 | MAT2X3 { $$ = "mat2x3"; }
2141 | MAT2X4 { $$ = "mat2x4"; }
2142 | MAT3X2 { $$ = "mat3x2"; }
2143 | MAT3X3 { $$ = "mat3"; }
2144 | MAT3X4 { $$ = "mat3x4"; }
2145 | MAT4X2 { $$ = "mat4x2"; }
2146 | MAT4X3 { $$ = "mat4x3"; }
2147 | MAT4X4 { $$ = "mat4"; }
2148 | DMAT2X2 { $$ = "dmat2"; }
2149 | DMAT2X3 { $$ = "dmat2x3"; }
2150 | DMAT2X4 { $$ = "dmat2x4"; }
2151 | DMAT3X2 { $$ = "dmat3x2"; }
2152 | DMAT3X3 { $$ = "dmat3"; }
2153 | DMAT3X4 { $$ = "dmat3x4"; }
2154 | DMAT4X2 { $$ = "dmat4x2"; }
2155 | DMAT4X3 { $$ = "dmat4x3"; }
2156 | DMAT4X4 { $$ = "dmat4"; }
2157 | SAMPLER1D { $$ = "sampler1D"; }
2158 | SAMPLER2D { $$ = "sampler2D"; }
2159 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2160 | SAMPLER3D { $$ = "sampler3D"; }
2161 | SAMPLERCUBE { $$ = "samplerCube"; }
2162 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2163 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2164 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2165 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2166 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2167 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2168 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2169 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2170 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2171 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2172 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2173 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2174 | ISAMPLER1D { $$ = "isampler1D"; }
2175 | ISAMPLER2D { $$ = "isampler2D"; }
2176 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2177 | ISAMPLER3D { $$ = "isampler3D"; }
2178 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2179 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2180 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2181 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2182 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2183 | USAMPLER1D { $$ = "usampler1D"; }
2184 | USAMPLER2D { $$ = "usampler2D"; }
2185 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2186 | USAMPLER3D { $$ = "usampler3D"; }
2187 | USAMPLERCUBE { $$ = "usamplerCube"; }
2188 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2189 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2190 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2191 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2192 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2193 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2194 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2195 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2196 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2197 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2198 | IMAGE1D { $$ = "image1D"; }
2199 | IMAGE2D { $$ = "image2D"; }
2200 | IMAGE3D { $$ = "image3D"; }
2201 | IMAGE2DRECT { $$ = "image2DRect"; }
2202 | IMAGECUBE { $$ = "imageCube"; }
2203 | IMAGEBUFFER { $$ = "imageBuffer"; }
2204 | IMAGE1DARRAY { $$ = "image1DArray"; }
2205 | IMAGE2DARRAY { $$ = "image2DArray"; }
2206 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2207 | IMAGE2DMS { $$ = "image2DMS"; }
2208 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2209 | IIMAGE1D { $$ = "iimage1D"; }
2210 | IIMAGE2D { $$ = "iimage2D"; }
2211 | IIMAGE3D { $$ = "iimage3D"; }
2212 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2213 | IIMAGECUBE { $$ = "iimageCube"; }
2214 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2215 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2216 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2217 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2218 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2219 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2220 | UIMAGE1D { $$ = "uimage1D"; }
2221 | UIMAGE2D { $$ = "uimage2D"; }
2222 | UIMAGE3D { $$ = "uimage3D"; }
2223 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2224 | UIMAGECUBE { $$ = "uimageCube"; }
2225 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2226 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2227 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2228 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2229 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2230 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2231 | ATOMIC_UINT { $$ = "atomic_uint"; }
2234 precision_qualifier:
2237 state->check_precision_qualifiers_allowed(&@1);
2238 $$ = ast_precision_high;
2242 state->check_precision_qualifiers_allowed(&@1);
2243 $$ = ast_precision_medium;
2247 state->check_precision_qualifiers_allowed(&@1);
2248 $$ = ast_precision_low;
2253 STRUCT any_identifier '{' struct_declaration_list '}'
2256 $$ = new(ctx) ast_struct_specifier($2, $4);
2257 $$->set_location_range(@2, @5);
2258 state->symbols->add_type($2, glsl_type::void_type);
2260 | STRUCT '{' struct_declaration_list '}'
2263 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2264 $$->set_location_range(@2, @4);
2268 struct_declaration_list:
2272 $1->link.self_link();
2274 | struct_declaration_list struct_declaration
2277 $$->link.insert_before(& $2->link);
2282 fully_specified_type struct_declarator_list ';'
2285 ast_fully_specified_type *const type = $1;
2286 type->set_location(@1);
2288 if (type->qualifier.flags.i != 0)
2289 _mesa_glsl_error(&@1, state,
2290 "only precision qualifiers may be applied to "
2291 "structure members");
2293 $$ = new(ctx) ast_declarator_list(type);
2294 $$->set_location(@2);
2296 $$->declarations.push_degenerate_list_at_head(& $2->link);
2300 struct_declarator_list:
2304 $1->link.self_link();
2306 | struct_declarator_list ',' struct_declarator
2309 $$->link.insert_before(& $3->link);
2317 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2318 $$->set_location(@1);
2320 | any_identifier array_specifier
2323 $$ = new(ctx) ast_declaration($1, $2, NULL);
2324 $$->set_location_range(@1, @2);
2329 assignment_expression
2330 | '{' initializer_list '}'
2334 | '{' initializer_list ',' '}'
2344 $$ = new(ctx) ast_aggregate_initializer();
2345 $$->set_location(@1);
2346 $$->expressions.push_tail(& $1->link);
2348 | initializer_list ',' initializer
2350 $1->expressions.push_tail(& $3->link);
2354 declaration_statement:
2358 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2361 compound_statement { $$ = (ast_node *) $1; }
2366 declaration_statement
2367 | expression_statement
2368 | selection_statement
2370 | iteration_statement
2378 $$ = new(ctx) ast_compound_statement(true, NULL);
2379 $$->set_location_range(@1, @2);
2383 state->symbols->push_scope();
2388 $$ = new(ctx) ast_compound_statement(true, $3);
2389 $$->set_location_range(@1, @4);
2390 state->symbols->pop_scope();
2394 statement_no_new_scope:
2395 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2399 compound_statement_no_new_scope:
2403 $$ = new(ctx) ast_compound_statement(false, NULL);
2404 $$->set_location_range(@1, @2);
2406 | '{' statement_list '}'
2409 $$ = new(ctx) ast_compound_statement(false, $2);
2410 $$->set_location_range(@1, @3);
2418 _mesa_glsl_error(& @1, state, "<nil> statement");
2423 $$->link.self_link();
2425 | statement_list statement
2428 _mesa_glsl_error(& @2, state, "<nil> statement");
2432 $$->link.insert_before(& $2->link);
2436 expression_statement:
2440 $$ = new(ctx) ast_expression_statement(NULL);
2441 $$->set_location(@1);
2446 $$ = new(ctx) ast_expression_statement($1);
2447 $$->set_location(@1);
2451 selection_statement:
2452 IF '(' expression ')' selection_rest_statement
2454 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2456 $$->set_location_range(@1, @5);
2460 selection_rest_statement:
2461 statement ELSE statement
2463 $$.then_statement = $1;
2464 $$.else_statement = $3;
2466 | statement %prec THEN
2468 $$.then_statement = $1;
2469 $$.else_statement = NULL;
2476 $$ = (ast_node *) $1;
2478 | fully_specified_type any_identifier '=' initializer
2481 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2482 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2483 decl->set_location_range(@2, @4);
2484 declarator->set_location(@1);
2486 declarator->declarations.push_tail(&decl->link);
2492 * switch_statement grammar is based on the syntax described in the body
2493 * of the GLSL spec, not in it's appendix!!!
2496 SWITCH '(' expression ')' switch_body
2498 $$ = new(state) ast_switch_statement($3, $5);
2499 $$->set_location_range(@1, @5);
2506 $$ = new(state) ast_switch_body(NULL);
2507 $$->set_location_range(@1, @2);
2509 | '{' case_statement_list '}'
2511 $$ = new(state) ast_switch_body($2);
2512 $$->set_location_range(@1, @3);
2519 $$ = new(state) ast_case_label($2);
2520 $$->set_location(@2);
2524 $$ = new(state) ast_case_label(NULL);
2525 $$->set_location(@2);
2532 ast_case_label_list *labels = new(state) ast_case_label_list();
2534 labels->labels.push_tail(& $1->link);
2536 $$->set_location(@1);
2538 | case_label_list case_label
2541 $$->labels.push_tail(& $2->link);
2546 case_label_list statement
2548 ast_case_statement *stmts = new(state) ast_case_statement($1);
2549 stmts->set_location(@2);
2551 stmts->stmts.push_tail(& $2->link);
2554 | case_statement statement
2557 $$->stmts.push_tail(& $2->link);
2561 case_statement_list:
2564 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2565 cases->set_location(@1);
2567 cases->cases.push_tail(& $1->link);
2570 | case_statement_list case_statement
2573 $$->cases.push_tail(& $2->link);
2577 iteration_statement:
2578 WHILE '(' condition ')' statement_no_new_scope
2581 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2582 NULL, $3, NULL, $5);
2583 $$->set_location_range(@1, @4);
2585 | DO statement WHILE '(' expression ')' ';'
2588 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2589 NULL, $5, NULL, $2);
2590 $$->set_location_range(@1, @6);
2592 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2595 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2596 $3, $4.cond, $4.rest, $6);
2597 $$->set_location_range(@1, @6);
2602 expression_statement
2603 | declaration_statement
2620 | conditionopt ';' expression
2627 // Grammar Note: No 'goto'. Gotos are not supported.
2632 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2633 $$->set_location(@1);
2638 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2639 $$->set_location(@1);
2644 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2645 $$->set_location(@1);
2647 | RETURN expression ';'
2650 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2651 $$->set_location_range(@1, @2);
2653 | DISCARD ';' // Fragment shader only.
2656 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2657 $$->set_location(@1);
2661 external_declaration:
2662 function_definition { $$ = $1; }
2663 | declaration { $$ = $1; }
2664 | pragma_statement { $$ = NULL; }
2665 | layout_defaults { $$ = $1; }
2668 function_definition:
2669 function_prototype compound_statement_no_new_scope
2672 $$ = new(ctx) ast_function_definition();
2673 $$->set_location_range(@1, @2);
2677 state->symbols->pop_scope();
2681 /* layout_qualifieropt is packed into this rule */
2683 basic_interface_block
2687 | layout_qualifier interface_block
2689 ast_interface_block *block = (ast_interface_block *) $2;
2691 if (!state->has_420pack_or_es31() && block->layout.has_layout() &&
2692 !block->layout.is_default_qualifier) {
2693 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2697 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2701 block->layout.is_default_qualifier = false;
2705 | memory_qualifier interface_block
2707 ast_interface_block *block = (ast_interface_block *)$2;
2709 if (!block->layout.flags.q.buffer) {
2710 _mesa_glsl_error(& @1, state,
2711 "memory qualifiers can only be used in the "
2712 "declaration of shader storage blocks");
2714 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2721 basic_interface_block:
2722 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2724 ast_interface_block *const block = $6;
2726 if ($1.flags.q.uniform) {
2727 block->layout = *state->default_uniform_qualifier;
2728 } else if ($1.flags.q.buffer) {
2729 block->layout = *state->default_shader_storage_qualifier;
2731 block->block_name = $2;
2732 block->declarations.push_degenerate_list_at_head(& $4->link);
2734 _mesa_ast_process_interface_block(& @1, state, block, $1);
2740 interface_qualifier:
2743 memset(& $$, 0, sizeof($$));
2748 memset(& $$, 0, sizeof($$));
2753 memset(& $$, 0, sizeof($$));
2754 $$.flags.q.uniform = 1;
2758 memset(& $$, 0, sizeof($$));
2759 $$.flags.q.buffer = 1;
2761 | auxiliary_storage_qualifier interface_qualifier
2763 if (!$1.flags.q.patch) {
2764 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2766 if ($2.has_auxiliary_storage()) {
2767 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2770 $$.flags.q.patch = 1;
2777 $$ = new(state) ast_interface_block(NULL, NULL);
2781 $$ = new(state) ast_interface_block($1, NULL);
2782 $$->set_location(@1);
2784 | NEW_IDENTIFIER array_specifier
2786 $$ = new(state) ast_interface_block($1, $2);
2787 $$->set_location_range(@1, @2);
2795 $1->link.self_link();
2797 | member_declaration member_list
2800 $2->link.insert_before(& $$->link);
2805 fully_specified_type struct_declarator_list ';'
2808 ast_fully_specified_type *type = $1;
2809 type->set_location(@1);
2811 if (type->qualifier.flags.q.attribute) {
2812 _mesa_glsl_error(& @1, state,
2813 "keyword 'attribute' cannot be used with "
2814 "interface block member");
2815 } else if (type->qualifier.flags.q.varying) {
2816 _mesa_glsl_error(& @1, state,
2817 "keyword 'varying' cannot be used with "
2818 "interface block member");
2821 $$ = new(ctx) ast_declarator_list(type);
2822 $$->set_location(@2);
2824 $$->declarations.push_degenerate_list_at_head(& $2->link);
2828 layout_uniform_defaults:
2829 layout_qualifier layout_uniform_defaults
2832 if (!state->has_420pack_or_es31()) {
2833 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2836 if (!state->default_uniform_qualifier->
2837 merge_qualifier(& @1, state, $1, false)) {
2842 | layout_qualifier UNIFORM ';'
2844 if (!state->default_uniform_qualifier->
2845 merge_qualifier(& @1, state, $1, false)) {
2852 layout_buffer_defaults:
2853 layout_qualifier layout_buffer_defaults
2856 if (!state->has_420pack_or_es31()) {
2857 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2860 if (!state->default_shader_storage_qualifier->
2861 merge_qualifier(& @1, state, $1, false)) {
2866 | layout_qualifier BUFFER ';'
2868 if (!state->default_shader_storage_qualifier->
2869 merge_qualifier(& @1, state, $1, false)) {
2873 /* From the GLSL 4.50 spec, section 4.4.5:
2875 * "It is a compile-time error to specify the binding identifier for
2876 * the global scope or for block member declarations."
2878 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2879 _mesa_glsl_error(& @1, state,
2880 "binding qualifier cannot be set for default layout");
2888 layout_qualifier layout_in_defaults
2891 if (!state->has_420pack_or_es31()) {
2892 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2895 if (!state->in_qualifier->
2896 merge_in_qualifier(& @1, state, $1, $$, false)) {
2902 | layout_qualifier IN_TOK ';'
2905 if (!state->in_qualifier->
2906 merge_in_qualifier(& @1, state, $1, $$, true)) {
2912 layout_out_defaults:
2913 layout_qualifier layout_out_defaults
2916 if (!state->has_420pack_or_es31()) {
2917 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2920 if (!state->out_qualifier->
2921 merge_out_qualifier(& @1, state, $1, $$, false)) {
2927 | layout_qualifier OUT_TOK ';'
2930 if (!state->out_qualifier->
2931 merge_out_qualifier(& @1, state, $1, $$, true))
2937 layout_uniform_defaults
2938 | layout_buffer_defaults
2939 | layout_in_defaults
2940 | layout_out_defaults