glsl: move to compiler/
[mesa.git] / src / compiler / glsl / glsl_parser.yy
1 %{
2 /*
3 * Copyright © 2008, 2009 Intel Corporation
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #ifndef _MSC_VER
28 #include <strings.h>
29 #endif
30 #include <assert.h>
31
32 #include "ast.h"
33 #include "glsl_parser_extras.h"
34 #include "compiler/glsl_types.h"
35 #include "main/context.h"
36
37 #ifdef _MSC_VER
38 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
39 #endif
40
41 #undef yyerror
42
43 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
44 {
45 _mesa_glsl_error(loc, st, "%s", msg);
46 }
47
48 static int
49 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
50 {
51 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
52 }
53
54 static bool match_layout_qualifier(const char *s1, const char *s2,
55 _mesa_glsl_parse_state *state)
56 {
57 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
58 *
59 * "The tokens in any layout-qualifier-id-list ... are not case
60 * sensitive, unless explicitly noted otherwise."
61 *
62 * The text "unless explicitly noted otherwise" appears to be
63 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
64 * otherwise.
65 *
66 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
67 * Qualifiers):
68 *
69 * "As for other identifiers, they are case sensitive."
70 *
71 * So we need to do a case-sensitive or a case-insensitive match,
72 * depending on whether we are compiling for GLSL ES.
73 */
74 if (state->es_shader)
75 return strcmp(s1, s2);
76 else
77 return strcasecmp(s1, s2);
78 }
79 %}
80
81 %expect 0
82
83 %pure-parser
84 %error-verbose
85
86 %locations
87 %initial-action {
88 @$.first_line = 1;
89 @$.first_column = 1;
90 @$.last_line = 1;
91 @$.last_column = 1;
92 @$.source = 0;
93 }
94
95 %lex-param {struct _mesa_glsl_parse_state *state}
96 %parse-param {struct _mesa_glsl_parse_state *state}
97
98 %union {
99 int n;
100 float real;
101 double dreal;
102 const char *identifier;
103
104 struct ast_type_qualifier type_qualifier;
105
106 ast_node *node;
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;
125 struct {
126 ast_node *cond;
127 ast_expression *rest;
128 } for_rest_statement;
129
130 struct {
131 ast_node *then_statement;
132 ast_node *else_statement;
133 } selection_rest_statement;
134 }
135
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
167 %token ATOMIC_UINT
168 %token SHARED
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 %type <interface_block> buffer_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
182 %token SUB_ASSIGN
183 %token INVARIANT PRECISE
184 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
185
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
190 %token LAYOUT_TOK
191 %token DOT_TOK
192 /* Reserved words that are not actually used in the grammar.
193 */
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
198 %token SAMPLER3DRECT
199 %token SIZEOF CAST NAMESPACE USING
200 %token RESOURCE PATCH
201 %token SUBROUTINE
202
203 %token ERROR_TOK
204
205 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
206
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_qualifier> buffer_interface_qualifier
224 %type <type_specifier> type_specifier
225 %type <type_specifier> type_specifier_nonarray
226 %type <array_specifier> array_specifier
227 %type <identifier> basic_type_specifier_nonarray
228 %type <fully_specified_type> fully_specified_type
229 %type <function> function_prototype
230 %type <function> function_header
231 %type <function> function_header_with_parameters
232 %type <function> function_declarator
233 %type <parameter_declarator> parameter_declarator
234 %type <parameter_declarator> parameter_declaration
235 %type <type_qualifier> parameter_qualifier
236 %type <type_qualifier> parameter_direction_qualifier
237 %type <type_specifier> parameter_type_specifier
238 %type <function_definition> function_definition
239 %type <compound_statement> compound_statement_no_new_scope
240 %type <compound_statement> compound_statement
241 %type <node> statement_no_new_scope
242 %type <node> expression_statement
243 %type <expression> expression
244 %type <expression> primary_expression
245 %type <expression> assignment_expression
246 %type <expression> conditional_expression
247 %type <expression> logical_or_expression
248 %type <expression> logical_xor_expression
249 %type <expression> logical_and_expression
250 %type <expression> inclusive_or_expression
251 %type <expression> exclusive_or_expression
252 %type <expression> and_expression
253 %type <expression> equality_expression
254 %type <expression> relational_expression
255 %type <expression> shift_expression
256 %type <expression> additive_expression
257 %type <expression> multiplicative_expression
258 %type <expression> unary_expression
259 %type <expression> constant_expression
260 %type <expression> integer_expression
261 %type <expression> postfix_expression
262 %type <expression> function_call_header_with_parameters
263 %type <expression> function_call_header_no_parameters
264 %type <expression> function_call_header
265 %type <expression> function_call_generic
266 %type <expression> function_call_or_method
267 %type <expression> function_call
268 %type <n> assignment_operator
269 %type <n> unary_operator
270 %type <expression> function_identifier
271 %type <node> external_declaration
272 %type <declarator_list> init_declarator_list
273 %type <declarator_list> single_declaration
274 %type <expression> initializer
275 %type <expression> initializer_list
276 %type <node> declaration
277 %type <node> declaration_statement
278 %type <node> jump_statement
279 %type <node> interface_block
280 %type <interface_block> basic_interface_block
281 %type <struct_specifier> struct_specifier
282 %type <declarator_list> struct_declaration_list
283 %type <declarator_list> struct_declaration
284 %type <declaration> struct_declarator
285 %type <declaration> struct_declarator_list
286 %type <declarator_list> member_list
287 %type <declarator_list> member_declaration
288 %type <node> selection_statement
289 %type <selection_rest_statement> selection_rest_statement
290 %type <node> switch_statement
291 %type <switch_body> switch_body
292 %type <case_label_list> case_label_list
293 %type <case_label> case_label
294 %type <case_statement> case_statement
295 %type <case_statement_list> case_statement_list
296 %type <node> iteration_statement
297 %type <node> condition
298 %type <node> conditionopt
299 %type <node> for_init_statement
300 %type <for_rest_statement> for_rest_statement
301 %type <node> layout_defaults
302 %type <node> layout_uniform_defaults
303 %type <node> layout_buffer_defaults
304 %type <node> layout_in_defaults
305 %type <node> layout_out_defaults
306
307 %right THEN ELSE
308 %%
309
310 translation_unit:
311 version_statement extension_statement_list
312 {
313 _mesa_glsl_initialize_types(state);
314 }
315 external_declaration_list
316 {
317 delete state->symbols;
318 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
319 if (state->es_shader) {
320 if (state->stage == MESA_SHADER_FRAGMENT) {
321 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
322 } else {
323 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
324 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
325 }
326 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
327 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
328 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
329 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
330 }
331 _mesa_glsl_initialize_types(state);
332 }
333 ;
334
335 version_statement:
336 /* blank - no #version specified: defaults are already set */
337 | VERSION_TOK INTCONSTANT EOL
338 {
339 state->process_version_directive(&@2, $2, NULL);
340 if (state->error) {
341 YYERROR;
342 }
343 }
344 | VERSION_TOK INTCONSTANT any_identifier EOL
345 {
346 state->process_version_directive(&@2, $2, $3);
347 if (state->error) {
348 YYERROR;
349 }
350 }
351 ;
352
353 pragma_statement:
354 PRAGMA_DEBUG_ON EOL
355 | PRAGMA_DEBUG_OFF EOL
356 | PRAGMA_OPTIMIZE_ON EOL
357 | PRAGMA_OPTIMIZE_OFF EOL
358 | PRAGMA_INVARIANT_ALL EOL
359 {
360 /* Pragma invariant(all) cannot be used in a fragment shader.
361 *
362 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
363 *
364 * "It is an error to use this pragma in a fragment shader."
365 */
366 if (state->is_version(120, 300) &&
367 state->stage == MESA_SHADER_FRAGMENT) {
368 _mesa_glsl_error(& @1, state,
369 "pragma `invariant(all)' cannot be used "
370 "in a fragment shader.");
371 } else if (!state->is_version(120, 100)) {
372 _mesa_glsl_warning(& @1, state,
373 "pragma `invariant(all)' not supported in %s "
374 "(GLSL ES 1.00 or GLSL 1.20 required)",
375 state->get_version_string());
376 } else {
377 state->all_invariant = true;
378 }
379 }
380 ;
381
382 extension_statement_list:
383
384 | extension_statement_list extension_statement
385 ;
386
387 any_identifier:
388 IDENTIFIER
389 | TYPE_IDENTIFIER
390 | NEW_IDENTIFIER
391 ;
392
393 extension_statement:
394 EXTENSION any_identifier COLON any_identifier EOL
395 {
396 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
397 YYERROR;
398 }
399 }
400 ;
401
402 external_declaration_list:
403 external_declaration
404 {
405 /* FINISHME: The NULL test is required because pragmas are set to
406 * FINISHME: NULL. (See production rule for external_declaration.)
407 */
408 if ($1 != NULL)
409 state->translation_unit.push_tail(& $1->link);
410 }
411 | external_declaration_list external_declaration
412 {
413 /* FINISHME: The NULL test is required because pragmas are set to
414 * FINISHME: NULL. (See production rule for external_declaration.)
415 */
416 if ($2 != NULL)
417 state->translation_unit.push_tail(& $2->link);
418 }
419 | external_declaration_list extension_statement {
420 if (!state->allow_extension_directive_midshader) {
421 _mesa_glsl_error(& @2, state,
422 "#extension directive is not allowed "
423 "in the middle of a shader");
424 YYERROR;
425 }
426 }
427 ;
428
429 variable_identifier:
430 IDENTIFIER
431 | NEW_IDENTIFIER
432 ;
433
434 primary_expression:
435 variable_identifier
436 {
437 void *ctx = state;
438 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
439 $$->set_location(@1);
440 $$->primary_expression.identifier = $1;
441 }
442 | INTCONSTANT
443 {
444 void *ctx = state;
445 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
446 $$->set_location(@1);
447 $$->primary_expression.int_constant = $1;
448 }
449 | UINTCONSTANT
450 {
451 void *ctx = state;
452 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
453 $$->set_location(@1);
454 $$->primary_expression.uint_constant = $1;
455 }
456 | FLOATCONSTANT
457 {
458 void *ctx = state;
459 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
460 $$->set_location(@1);
461 $$->primary_expression.float_constant = $1;
462 }
463 | DOUBLECONSTANT
464 {
465 void *ctx = state;
466 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
467 $$->set_location(@1);
468 $$->primary_expression.double_constant = $1;
469 }
470 | BOOLCONSTANT
471 {
472 void *ctx = state;
473 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
474 $$->set_location(@1);
475 $$->primary_expression.bool_constant = $1;
476 }
477 | '(' expression ')'
478 {
479 $$ = $2;
480 }
481 ;
482
483 postfix_expression:
484 primary_expression
485 | postfix_expression '[' integer_expression ']'
486 {
487 void *ctx = state;
488 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
489 $$->set_location_range(@1, @4);
490 }
491 | function_call
492 {
493 $$ = $1;
494 }
495 | postfix_expression DOT_TOK FIELD_SELECTION
496 {
497 void *ctx = state;
498 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
499 $$->set_location_range(@1, @3);
500 $$->primary_expression.identifier = $3;
501 }
502 | postfix_expression INC_OP
503 {
504 void *ctx = state;
505 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
506 $$->set_location_range(@1, @2);
507 }
508 | postfix_expression DEC_OP
509 {
510 void *ctx = state;
511 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
512 $$->set_location_range(@1, @2);
513 }
514 ;
515
516 integer_expression:
517 expression
518 ;
519
520 function_call:
521 function_call_or_method
522 ;
523
524 function_call_or_method:
525 function_call_generic
526 ;
527
528 function_call_generic:
529 function_call_header_with_parameters ')'
530 | function_call_header_no_parameters ')'
531 ;
532
533 function_call_header_no_parameters:
534 function_call_header VOID_TOK
535 | function_call_header
536 ;
537
538 function_call_header_with_parameters:
539 function_call_header assignment_expression
540 {
541 $$ = $1;
542 $$->set_location(@1);
543 $$->expressions.push_tail(& $2->link);
544 }
545 | function_call_header_with_parameters ',' assignment_expression
546 {
547 $$ = $1;
548 $$->set_location(@1);
549 $$->expressions.push_tail(& $3->link);
550 }
551 ;
552
553 // Grammar Note: Constructors look like functions, but lexical
554 // analysis recognized most of them as keywords. They are now
555 // recognized through "type_specifier".
556 function_call_header:
557 function_identifier '('
558 ;
559
560 function_identifier:
561 type_specifier
562 {
563 void *ctx = state;
564 $$ = new(ctx) ast_function_expression($1);
565 $$->set_location(@1);
566 }
567 | postfix_expression
568 {
569 void *ctx = state;
570 $$ = new(ctx) ast_function_expression($1);
571 $$->set_location(@1);
572 }
573 ;
574
575 // Grammar Note: Constructors look like methods, but lexical
576 // analysis recognized most of them as keywords. They are now
577 // recognized through "type_specifier".
578
579 // Grammar Note: No traditional style type casts.
580 unary_expression:
581 postfix_expression
582 | INC_OP unary_expression
583 {
584 void *ctx = state;
585 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
586 $$->set_location(@1);
587 }
588 | DEC_OP unary_expression
589 {
590 void *ctx = state;
591 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
592 $$->set_location(@1);
593 }
594 | unary_operator unary_expression
595 {
596 void *ctx = state;
597 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
598 $$->set_location_range(@1, @2);
599 }
600 ;
601
602 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
603 unary_operator:
604 '+' { $$ = ast_plus; }
605 | '-' { $$ = ast_neg; }
606 | '!' { $$ = ast_logic_not; }
607 | '~' { $$ = ast_bit_not; }
608 ;
609
610 multiplicative_expression:
611 unary_expression
612 | multiplicative_expression '*' unary_expression
613 {
614 void *ctx = state;
615 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
616 $$->set_location_range(@1, @3);
617 }
618 | multiplicative_expression '/' unary_expression
619 {
620 void *ctx = state;
621 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
622 $$->set_location_range(@1, @3);
623 }
624 | multiplicative_expression '%' unary_expression
625 {
626 void *ctx = state;
627 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
628 $$->set_location_range(@1, @3);
629 }
630 ;
631
632 additive_expression:
633 multiplicative_expression
634 | additive_expression '+' multiplicative_expression
635 {
636 void *ctx = state;
637 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
638 $$->set_location_range(@1, @3);
639 }
640 | additive_expression '-' multiplicative_expression
641 {
642 void *ctx = state;
643 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
644 $$->set_location_range(@1, @3);
645 }
646 ;
647
648 shift_expression:
649 additive_expression
650 | shift_expression LEFT_OP additive_expression
651 {
652 void *ctx = state;
653 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
654 $$->set_location_range(@1, @3);
655 }
656 | shift_expression RIGHT_OP additive_expression
657 {
658 void *ctx = state;
659 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
660 $$->set_location_range(@1, @3);
661 }
662 ;
663
664 relational_expression:
665 shift_expression
666 | relational_expression '<' shift_expression
667 {
668 void *ctx = state;
669 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
670 $$->set_location_range(@1, @3);
671 }
672 | relational_expression '>' shift_expression
673 {
674 void *ctx = state;
675 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
676 $$->set_location_range(@1, @3);
677 }
678 | relational_expression LE_OP shift_expression
679 {
680 void *ctx = state;
681 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
682 $$->set_location_range(@1, @3);
683 }
684 | relational_expression GE_OP shift_expression
685 {
686 void *ctx = state;
687 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
688 $$->set_location_range(@1, @3);
689 }
690 ;
691
692 equality_expression:
693 relational_expression
694 | equality_expression EQ_OP relational_expression
695 {
696 void *ctx = state;
697 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
698 $$->set_location_range(@1, @3);
699 }
700 | equality_expression NE_OP relational_expression
701 {
702 void *ctx = state;
703 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
704 $$->set_location_range(@1, @3);
705 }
706 ;
707
708 and_expression:
709 equality_expression
710 | and_expression '&' equality_expression
711 {
712 void *ctx = state;
713 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
714 $$->set_location_range(@1, @3);
715 }
716 ;
717
718 exclusive_or_expression:
719 and_expression
720 | exclusive_or_expression '^' and_expression
721 {
722 void *ctx = state;
723 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
724 $$->set_location_range(@1, @3);
725 }
726 ;
727
728 inclusive_or_expression:
729 exclusive_or_expression
730 | inclusive_or_expression '|' exclusive_or_expression
731 {
732 void *ctx = state;
733 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
734 $$->set_location_range(@1, @3);
735 }
736 ;
737
738 logical_and_expression:
739 inclusive_or_expression
740 | logical_and_expression AND_OP inclusive_or_expression
741 {
742 void *ctx = state;
743 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
744 $$->set_location_range(@1, @3);
745 }
746 ;
747
748 logical_xor_expression:
749 logical_and_expression
750 | logical_xor_expression XOR_OP logical_and_expression
751 {
752 void *ctx = state;
753 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
754 $$->set_location_range(@1, @3);
755 }
756 ;
757
758 logical_or_expression:
759 logical_xor_expression
760 | logical_or_expression OR_OP logical_xor_expression
761 {
762 void *ctx = state;
763 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
764 $$->set_location_range(@1, @3);
765 }
766 ;
767
768 conditional_expression:
769 logical_or_expression
770 | logical_or_expression '?' expression ':' assignment_expression
771 {
772 void *ctx = state;
773 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
774 $$->set_location_range(@1, @5);
775 }
776 ;
777
778 assignment_expression:
779 conditional_expression
780 | unary_expression assignment_operator assignment_expression
781 {
782 void *ctx = state;
783 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
784 $$->set_location_range(@1, @3);
785 }
786 ;
787
788 assignment_operator:
789 '=' { $$ = ast_assign; }
790 | MUL_ASSIGN { $$ = ast_mul_assign; }
791 | DIV_ASSIGN { $$ = ast_div_assign; }
792 | MOD_ASSIGN { $$ = ast_mod_assign; }
793 | ADD_ASSIGN { $$ = ast_add_assign; }
794 | SUB_ASSIGN { $$ = ast_sub_assign; }
795 | LEFT_ASSIGN { $$ = ast_ls_assign; }
796 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
797 | AND_ASSIGN { $$ = ast_and_assign; }
798 | XOR_ASSIGN { $$ = ast_xor_assign; }
799 | OR_ASSIGN { $$ = ast_or_assign; }
800 ;
801
802 expression:
803 assignment_expression
804 {
805 $$ = $1;
806 }
807 | expression ',' assignment_expression
808 {
809 void *ctx = state;
810 if ($1->oper != ast_sequence) {
811 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
812 $$->set_location_range(@1, @3);
813 $$->expressions.push_tail(& $1->link);
814 } else {
815 $$ = $1;
816 }
817
818 $$->expressions.push_tail(& $3->link);
819 }
820 ;
821
822 constant_expression:
823 conditional_expression
824 ;
825
826 declaration:
827 function_prototype ';'
828 {
829 state->symbols->pop_scope();
830 $$ = $1;
831 }
832 | init_declarator_list ';'
833 {
834 $$ = $1;
835 }
836 | PRECISION precision_qualifier type_specifier ';'
837 {
838 $3->default_precision = $2;
839 $$ = $3;
840 }
841 | interface_block
842 {
843 $$ = $1;
844 }
845 ;
846
847 function_prototype:
848 function_declarator ')'
849 ;
850
851 function_declarator:
852 function_header
853 | function_header_with_parameters
854 ;
855
856 function_header_with_parameters:
857 function_header parameter_declaration
858 {
859 $$ = $1;
860 $$->parameters.push_tail(& $2->link);
861 }
862 | function_header_with_parameters ',' parameter_declaration
863 {
864 $$ = $1;
865 $$->parameters.push_tail(& $3->link);
866 }
867 ;
868
869 function_header:
870 fully_specified_type variable_identifier '('
871 {
872 void *ctx = state;
873 $$ = new(ctx) ast_function();
874 $$->set_location(@2);
875 $$->return_type = $1;
876 $$->identifier = $2;
877
878 if ($1->qualifier.flags.q.subroutine) {
879 /* add type for IDENTIFIER search */
880 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
881 } else
882 state->symbols->add_function(new(state) ir_function($2));
883 state->symbols->push_scope();
884 }
885 ;
886
887 parameter_declarator:
888 type_specifier any_identifier
889 {
890 void *ctx = state;
891 $$ = new(ctx) ast_parameter_declarator();
892 $$->set_location_range(@1, @2);
893 $$->type = new(ctx) ast_fully_specified_type();
894 $$->type->set_location(@1);
895 $$->type->specifier = $1;
896 $$->identifier = $2;
897 }
898 | type_specifier any_identifier array_specifier
899 {
900 void *ctx = state;
901 $$ = new(ctx) ast_parameter_declarator();
902 $$->set_location_range(@1, @3);
903 $$->type = new(ctx) ast_fully_specified_type();
904 $$->type->set_location(@1);
905 $$->type->specifier = $1;
906 $$->identifier = $2;
907 $$->array_specifier = $3;
908 }
909 ;
910
911 parameter_declaration:
912 parameter_qualifier parameter_declarator
913 {
914 $$ = $2;
915 $$->type->qualifier = $1;
916 }
917 | parameter_qualifier parameter_type_specifier
918 {
919 void *ctx = state;
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;
926 }
927 ;
928
929 parameter_qualifier:
930 /* empty */
931 {
932 memset(& $$, 0, sizeof($$));
933 }
934 | CONST_TOK parameter_qualifier
935 {
936 if ($2.flags.q.constant)
937 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
938
939 $$ = $2;
940 $$.flags.q.constant = 1;
941 }
942 | PRECISE parameter_qualifier
943 {
944 if ($2.flags.q.precise)
945 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
946
947 $$ = $2;
948 $$.flags.q.precise = 1;
949 }
950 | parameter_direction_qualifier parameter_qualifier
951 {
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");
954
955 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
956 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
957 "or precise");
958
959 $$ = $1;
960 $$.merge_qualifier(&@1, state, $2, false);
961 }
962 | precision_qualifier parameter_qualifier
963 {
964 if ($2.precision != ast_precision_none)
965 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
966
967 if (!state->has_420pack_or_es31() &&
968 $2.flags.i != 0)
969 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
970
971 $$ = $2;
972 $$.precision = $1;
973 }
974 | memory_qualifier parameter_qualifier
975 {
976 $$ = $1;
977 $$.merge_qualifier(&@1, state, $2, false);
978 }
979
980 parameter_direction_qualifier:
981 IN_TOK
982 {
983 memset(& $$, 0, sizeof($$));
984 $$.flags.q.in = 1;
985 }
986 | OUT_TOK
987 {
988 memset(& $$, 0, sizeof($$));
989 $$.flags.q.out = 1;
990 }
991 | INOUT_TOK
992 {
993 memset(& $$, 0, sizeof($$));
994 $$.flags.q.in = 1;
995 $$.flags.q.out = 1;
996 }
997 ;
998
999 parameter_type_specifier:
1000 type_specifier
1001 ;
1002
1003 init_declarator_list:
1004 single_declaration
1005 | init_declarator_list ',' any_identifier
1006 {
1007 void *ctx = state;
1008 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1009 decl->set_location(@3);
1010
1011 $$ = $1;
1012 $$->declarations.push_tail(&decl->link);
1013 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1014 }
1015 | init_declarator_list ',' any_identifier array_specifier
1016 {
1017 void *ctx = state;
1018 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1019 decl->set_location_range(@3, @4);
1020
1021 $$ = $1;
1022 $$->declarations.push_tail(&decl->link);
1023 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1024 }
1025 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1026 {
1027 void *ctx = state;
1028 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1029 decl->set_location_range(@3, @4);
1030
1031 $$ = $1;
1032 $$->declarations.push_tail(&decl->link);
1033 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1034 }
1035 | init_declarator_list ',' any_identifier '=' initializer
1036 {
1037 void *ctx = state;
1038 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1039 decl->set_location(@3);
1040
1041 $$ = $1;
1042 $$->declarations.push_tail(&decl->link);
1043 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1044 }
1045 ;
1046
1047 // Grammar Note: No 'enum', or 'typedef'.
1048 single_declaration:
1049 fully_specified_type
1050 {
1051 void *ctx = state;
1052 /* Empty declaration list is valid. */
1053 $$ = new(ctx) ast_declarator_list($1);
1054 $$->set_location(@1);
1055 }
1056 | fully_specified_type any_identifier
1057 {
1058 void *ctx = state;
1059 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1060 decl->set_location(@2);
1061
1062 $$ = new(ctx) ast_declarator_list($1);
1063 $$->set_location_range(@1, @2);
1064 $$->declarations.push_tail(&decl->link);
1065 }
1066 | fully_specified_type any_identifier array_specifier
1067 {
1068 void *ctx = state;
1069 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1070 decl->set_location_range(@2, @3);
1071
1072 $$ = new(ctx) ast_declarator_list($1);
1073 $$->set_location_range(@1, @3);
1074 $$->declarations.push_tail(&decl->link);
1075 }
1076 | fully_specified_type any_identifier array_specifier '=' initializer
1077 {
1078 void *ctx = state;
1079 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1080 decl->set_location_range(@2, @3);
1081
1082 $$ = new(ctx) ast_declarator_list($1);
1083 $$->set_location_range(@1, @3);
1084 $$->declarations.push_tail(&decl->link);
1085 }
1086 | fully_specified_type any_identifier '=' initializer
1087 {
1088 void *ctx = state;
1089 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1090 decl->set_location(@2);
1091
1092 $$ = new(ctx) ast_declarator_list($1);
1093 $$->set_location_range(@1, @2);
1094 $$->declarations.push_tail(&decl->link);
1095 }
1096 | INVARIANT variable_identifier
1097 {
1098 void *ctx = state;
1099 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1100 decl->set_location(@2);
1101
1102 $$ = new(ctx) ast_declarator_list(NULL);
1103 $$->set_location_range(@1, @2);
1104 $$->invariant = true;
1105
1106 $$->declarations.push_tail(&decl->link);
1107 }
1108 | PRECISE variable_identifier
1109 {
1110 void *ctx = state;
1111 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1112 decl->set_location(@2);
1113
1114 $$ = new(ctx) ast_declarator_list(NULL);
1115 $$->set_location_range(@1, @2);
1116 $$->precise = true;
1117
1118 $$->declarations.push_tail(&decl->link);
1119 }
1120 ;
1121
1122 fully_specified_type:
1123 type_specifier
1124 {
1125 void *ctx = state;
1126 $$ = new(ctx) ast_fully_specified_type();
1127 $$->set_location(@1);
1128 $$->specifier = $1;
1129 }
1130 | type_qualifier type_specifier
1131 {
1132 void *ctx = state;
1133 $$ = new(ctx) ast_fully_specified_type();
1134 $$->set_location_range(@1, @2);
1135 $$->qualifier = $1;
1136 $$->specifier = $2;
1137 if ($$->specifier->structure != NULL &&
1138 $$->specifier->structure->is_declaration) {
1139 $$->specifier->structure->layout = &$$->qualifier;
1140 }
1141 }
1142 ;
1143
1144 layout_qualifier:
1145 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1146 {
1147 $$ = $3;
1148 }
1149 ;
1150
1151 layout_qualifier_id_list:
1152 layout_qualifier_id
1153 | layout_qualifier_id_list ',' layout_qualifier_id
1154 {
1155 $$ = $1;
1156 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1157 YYERROR;
1158 }
1159 }
1160 ;
1161
1162 layout_qualifier_id:
1163 any_identifier
1164 {
1165 memset(& $$, 0, sizeof($$));
1166
1167 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1168 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1169 state->is_version(150, 0))) {
1170 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1171 $$.flags.q.origin_upper_left = 1;
1172 } else if (match_layout_qualifier($1, "pixel_center_integer",
1173 state) == 0) {
1174 $$.flags.q.pixel_center_integer = 1;
1175 }
1176
1177 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1178 _mesa_glsl_warning(& @1, state,
1179 "GL_ARB_fragment_coord_conventions layout "
1180 "identifier `%s' used", $1);
1181 }
1182 }
1183
1184 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1185 if (!$$.flags.i &&
1186 (state->AMD_conservative_depth_enable ||
1187 state->ARB_conservative_depth_enable ||
1188 state->is_version(420, 0))) {
1189 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1190 $$.flags.q.depth_any = 1;
1191 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1192 $$.flags.q.depth_greater = 1;
1193 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1194 $$.flags.q.depth_less = 1;
1195 } else if (match_layout_qualifier($1, "depth_unchanged",
1196 state) == 0) {
1197 $$.flags.q.depth_unchanged = 1;
1198 }
1199
1200 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1201 _mesa_glsl_warning(& @1, state,
1202 "GL_AMD_conservative_depth "
1203 "layout qualifier `%s' is used", $1);
1204 }
1205 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1206 _mesa_glsl_warning(& @1, state,
1207 "GL_ARB_conservative_depth "
1208 "layout qualifier `%s' is used", $1);
1209 }
1210 }
1211
1212 /* See also interface_block_layout_qualifier. */
1213 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1214 if (match_layout_qualifier($1, "std140", state) == 0) {
1215 $$.flags.q.std140 = 1;
1216 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1217 $$.flags.q.shared = 1;
1218 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1219 $$.flags.q.std430 = 1;
1220 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1221 $$.flags.q.column_major = 1;
1222 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1223 * below in the interface_block_layout_qualifier rule.
1224 *
1225 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1226 * an identifier.
1227 *
1228 * Also, this takes care of alternate capitalizations of
1229 * "row_major" (which is necessary because layout qualifiers
1230 * are case-insensitive in desktop GLSL).
1231 */
1232 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1233 $$.flags.q.row_major = 1;
1234 /* "packed" is a reserved word in GLSL, and its token is
1235 * parsed below in the interface_block_layout_qualifier rule.
1236 * However, we must take care of alternate capitalizations of
1237 * "packed", because layout qualifiers are case-insensitive
1238 * in desktop GLSL.
1239 */
1240 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1241 $$.flags.q.packed = 1;
1242 }
1243
1244 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1245 _mesa_glsl_warning(& @1, state,
1246 "#version 140 / GL_ARB_uniform_buffer_object "
1247 "layout qualifier `%s' is used", $1);
1248 }
1249 }
1250
1251 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1252 if (!$$.flags.i) {
1253 static const struct {
1254 const char *s;
1255 GLenum e;
1256 } map[] = {
1257 { "points", GL_POINTS },
1258 { "lines", GL_LINES },
1259 { "lines_adjacency", GL_LINES_ADJACENCY },
1260 { "line_strip", GL_LINE_STRIP },
1261 { "triangles", GL_TRIANGLES },
1262 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1263 { "triangle_strip", GL_TRIANGLE_STRIP },
1264 };
1265 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1266 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1267 $$.flags.q.prim_type = 1;
1268 $$.prim_type = map[i].e;
1269 break;
1270 }
1271 }
1272
1273 if ($$.flags.i && !state->has_geometry_shader()) {
1274 _mesa_glsl_error(& @1, state, "#version 150 layout "
1275 "qualifier `%s' used", $1);
1276 }
1277 }
1278
1279 /* Layout qualifiers for ARB_shader_image_load_store. */
1280 if (state->ARB_shader_image_load_store_enable ||
1281 state->is_version(420, 310)) {
1282 if (!$$.flags.i) {
1283 static const struct {
1284 const char *name;
1285 GLenum format;
1286 glsl_base_type base_type;
1287 /** Minimum desktop GLSL version required for the image
1288 * format. Use 130 if already present in the original
1289 * ARB extension.
1290 */
1291 unsigned required_glsl;
1292 /** Minimum GLSL ES version required for the image format. */
1293 unsigned required_essl;
1294 } map[] = {
1295 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1296 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1297 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1298 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1299 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1300 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1301 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1302 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1303 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1304 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1305 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1306 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1307 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1308 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1309 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1310 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1311 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1312 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1313 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1314 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1315 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1316 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1317 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1318 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1319 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1320 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1321 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1322 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1323 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1324 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1325 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1326 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1327 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1328 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1329 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1330 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1331 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1332 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1333 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1334 };
1335
1336 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1337 if (state->is_version(map[i].required_glsl,
1338 map[i].required_essl) &&
1339 match_layout_qualifier($1, map[i].name, state) == 0) {
1340 $$.flags.q.explicit_image_format = 1;
1341 $$.image_format = map[i].format;
1342 $$.image_base_type = map[i].base_type;
1343 break;
1344 }
1345 }
1346 }
1347
1348 if (!$$.flags.i &&
1349 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1350 /* From section 4.4.1.3 of the GLSL 4.50 specification
1351 * (Fragment Shader Inputs):
1352 *
1353 * "Fragment shaders also allow the following layout
1354 * qualifier on in only (not with variable declarations)
1355 * layout-qualifier-id
1356 * early_fragment_tests
1357 * [...]"
1358 */
1359 if (state->stage != MESA_SHADER_FRAGMENT) {
1360 _mesa_glsl_error(& @1, state,
1361 "early_fragment_tests layout qualifier only "
1362 "valid in fragment shaders");
1363 }
1364
1365 $$.flags.q.early_fragment_tests = 1;
1366 }
1367 }
1368
1369 /* Layout qualifiers for tessellation evaluation shaders. */
1370 if (!$$.flags.i) {
1371 struct {
1372 const char *s;
1373 GLenum e;
1374 } map[] = {
1375 /* triangles already parsed by gs-specific code */
1376 { "quads", GL_QUADS },
1377 { "isolines", GL_ISOLINES },
1378 };
1379 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1380 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1381 $$.flags.q.prim_type = 1;
1382 $$.prim_type = map[i].e;
1383 break;
1384 }
1385 }
1386
1387 if ($$.flags.i &&
1388 !state->ARB_tessellation_shader_enable &&
1389 !state->is_version(400, 0)) {
1390 _mesa_glsl_error(& @1, state,
1391 "primitive mode qualifier `%s' requires "
1392 "GLSL 4.00 or ARB_tessellation_shader", $1);
1393 }
1394 }
1395 if (!$$.flags.i) {
1396 struct {
1397 const char *s;
1398 GLenum e;
1399 } map[] = {
1400 { "equal_spacing", GL_EQUAL },
1401 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1402 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1403 };
1404 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1405 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1406 $$.flags.q.vertex_spacing = 1;
1407 $$.vertex_spacing = map[i].e;
1408 break;
1409 }
1410 }
1411
1412 if ($$.flags.i &&
1413 !state->ARB_tessellation_shader_enable &&
1414 !state->is_version(400, 0)) {
1415 _mesa_glsl_error(& @1, state,
1416 "vertex spacing qualifier `%s' requires "
1417 "GLSL 4.00 or ARB_tessellation_shader", $1);
1418 }
1419 }
1420 if (!$$.flags.i) {
1421 if (match_layout_qualifier($1, "cw", state) == 0) {
1422 $$.flags.q.ordering = 1;
1423 $$.ordering = GL_CW;
1424 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1425 $$.flags.q.ordering = 1;
1426 $$.ordering = GL_CCW;
1427 }
1428
1429 if ($$.flags.i &&
1430 !state->ARB_tessellation_shader_enable &&
1431 !state->is_version(400, 0)) {
1432 _mesa_glsl_error(& @1, state,
1433 "ordering qualifier `%s' requires "
1434 "GLSL 4.00 or ARB_tessellation_shader", $1);
1435 }
1436 }
1437 if (!$$.flags.i) {
1438 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1439 $$.flags.q.point_mode = 1;
1440 $$.point_mode = true;
1441 }
1442
1443 if ($$.flags.i &&
1444 !state->ARB_tessellation_shader_enable &&
1445 !state->is_version(400, 0)) {
1446 _mesa_glsl_error(& @1, state,
1447 "qualifier `point_mode' requires "
1448 "GLSL 4.00 or ARB_tessellation_shader");
1449 }
1450 }
1451
1452 if (!$$.flags.i) {
1453 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1454 "`%s'", $1);
1455 YYERROR;
1456 }
1457 }
1458 | any_identifier '=' constant_expression
1459 {
1460 memset(& $$, 0, sizeof($$));
1461 void *ctx = state;
1462
1463 if ($3->oper != ast_int_constant &&
1464 $3->oper != ast_uint_constant &&
1465 !state->has_enhanced_layouts()) {
1466 _mesa_glsl_error(& @1, state,
1467 "compile-time constant expressions require "
1468 "GLSL 4.40 or ARB_enhanced_layouts");
1469 }
1470
1471 if (match_layout_qualifier("location", $1, state) == 0) {
1472 $$.flags.q.explicit_location = 1;
1473
1474 if ($$.flags.q.attribute == 1 &&
1475 state->ARB_explicit_attrib_location_warn) {
1476 _mesa_glsl_warning(& @1, state,
1477 "GL_ARB_explicit_attrib_location layout "
1478 "identifier `%s' used", $1);
1479 }
1480 $$.location = $3;
1481 }
1482
1483 if (match_layout_qualifier("index", $1, state) == 0) {
1484 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1485 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1486 YYERROR;
1487 }
1488
1489 $$.flags.q.explicit_index = 1;
1490 $$.index = $3;
1491 }
1492
1493 if ((state->has_420pack_or_es31() ||
1494 state->has_atomic_counters() ||
1495 state->has_shader_storage_buffer_objects()) &&
1496 match_layout_qualifier("binding", $1, state) == 0) {
1497 $$.flags.q.explicit_binding = 1;
1498 $$.binding = $3;
1499 }
1500
1501 if (state->has_atomic_counters() &&
1502 match_layout_qualifier("offset", $1, state) == 0) {
1503 $$.flags.q.explicit_offset = 1;
1504 $$.offset = $3;
1505 }
1506
1507 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1508 $$.flags.q.max_vertices = 1;
1509 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1510 if (!state->has_geometry_shader()) {
1511 _mesa_glsl_error(& @3, state,
1512 "#version 150 max_vertices qualifier "
1513 "specified", $3);
1514 }
1515 }
1516
1517 if (state->stage == MESA_SHADER_GEOMETRY) {
1518 if (match_layout_qualifier("stream", $1, state) == 0 &&
1519 state->check_explicit_attrib_stream_allowed(& @3)) {
1520 $$.flags.q.stream = 1;
1521 $$.flags.q.explicit_stream = 1;
1522 $$.stream = $3;
1523 }
1524 }
1525
1526 static const char * const local_size_qualifiers[3] = {
1527 "local_size_x",
1528 "local_size_y",
1529 "local_size_z",
1530 };
1531 for (int i = 0; i < 3; i++) {
1532 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1533 state) == 0) {
1534 if (!state->has_compute_shader()) {
1535 _mesa_glsl_error(& @3, state,
1536 "%s qualifier requires GLSL 4.30 or "
1537 "GLSL ES 3.10 or ARB_compute_shader",
1538 local_size_qualifiers[i]);
1539 YYERROR;
1540 } else {
1541 $$.flags.q.local_size |= (1 << i);
1542 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1543 }
1544 break;
1545 }
1546 }
1547
1548 if (match_layout_qualifier("invocations", $1, state) == 0) {
1549 $$.flags.q.invocations = 1;
1550 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1551 if (!state->is_version(400, 0) &&
1552 !state->ARB_gpu_shader5_enable) {
1553 _mesa_glsl_error(& @3, state,
1554 "GL_ARB_gpu_shader5 invocations "
1555 "qualifier specified", $3);
1556 }
1557 }
1558
1559 /* Layout qualifiers for tessellation control shaders. */
1560 if (match_layout_qualifier("vertices", $1, state) == 0) {
1561 $$.flags.q.vertices = 1;
1562 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1563 if (!state->ARB_tessellation_shader_enable &&
1564 !state->is_version(400, 0)) {
1565 _mesa_glsl_error(& @1, state,
1566 "vertices qualifier requires GLSL 4.00 or "
1567 "ARB_tessellation_shader");
1568 }
1569 }
1570
1571 /* If the identifier didn't match any known layout identifiers,
1572 * emit an error.
1573 */
1574 if (!$$.flags.i) {
1575 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1576 "`%s'", $1);
1577 YYERROR;
1578 }
1579 }
1580 | interface_block_layout_qualifier
1581 {
1582 $$ = $1;
1583 /* Layout qualifiers for ARB_uniform_buffer_object. */
1584 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1585 _mesa_glsl_error(& @1, state,
1586 "#version 140 / GL_ARB_uniform_buffer_object "
1587 "layout qualifier `%s' is used", $1);
1588 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1589 _mesa_glsl_warning(& @1, state,
1590 "#version 140 / GL_ARB_uniform_buffer_object "
1591 "layout qualifier `%s' is used", $1);
1592 }
1593 }
1594 ;
1595
1596 /* This is a separate language rule because we parse these as tokens
1597 * (due to them being reserved keywords) instead of identifiers like
1598 * most qualifiers. See the any_identifier path of
1599 * layout_qualifier_id for the others.
1600 *
1601 * Note that since layout qualifiers are case-insensitive in desktop
1602 * GLSL, all of these qualifiers need to be handled as identifiers as
1603 * well (by the any_identifier path of layout_qualifier_id).
1604 */
1605 interface_block_layout_qualifier:
1606 ROW_MAJOR
1607 {
1608 memset(& $$, 0, sizeof($$));
1609 $$.flags.q.row_major = 1;
1610 }
1611 | PACKED_TOK
1612 {
1613 memset(& $$, 0, sizeof($$));
1614 $$.flags.q.packed = 1;
1615 }
1616 | SHARED
1617 {
1618 memset(& $$, 0, sizeof($$));
1619 $$.flags.q.shared = 1;
1620 }
1621 ;
1622
1623 subroutine_qualifier:
1624 SUBROUTINE
1625 {
1626 memset(& $$, 0, sizeof($$));
1627 $$.flags.q.subroutine = 1;
1628 }
1629 | SUBROUTINE '(' subroutine_type_list ')'
1630 {
1631 memset(& $$, 0, sizeof($$));
1632 $$.flags.q.subroutine_def = 1;
1633 $$.subroutine_list = $3;
1634 }
1635 ;
1636
1637 subroutine_type_list:
1638 any_identifier
1639 {
1640 void *ctx = state;
1641 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1642 decl->set_location(@1);
1643
1644 $$ = new(ctx) ast_subroutine_list();
1645 $$->declarations.push_tail(&decl->link);
1646 }
1647 | subroutine_type_list ',' any_identifier
1648 {
1649 void *ctx = state;
1650 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1651 decl->set_location(@3);
1652
1653 $$ = $1;
1654 $$->declarations.push_tail(&decl->link);
1655 }
1656 ;
1657
1658 interpolation_qualifier:
1659 SMOOTH
1660 {
1661 memset(& $$, 0, sizeof($$));
1662 $$.flags.q.smooth = 1;
1663 }
1664 | FLAT
1665 {
1666 memset(& $$, 0, sizeof($$));
1667 $$.flags.q.flat = 1;
1668 }
1669 | NOPERSPECTIVE
1670 {
1671 memset(& $$, 0, sizeof($$));
1672 $$.flags.q.noperspective = 1;
1673 }
1674 ;
1675
1676 type_qualifier:
1677 /* Single qualifiers */
1678 INVARIANT
1679 {
1680 memset(& $$, 0, sizeof($$));
1681 $$.flags.q.invariant = 1;
1682 }
1683 | PRECISE
1684 {
1685 memset(& $$, 0, sizeof($$));
1686 $$.flags.q.precise = 1;
1687 }
1688 | auxiliary_storage_qualifier
1689 | storage_qualifier
1690 | interpolation_qualifier
1691 | layout_qualifier
1692 | memory_qualifier
1693 | subroutine_qualifier
1694 | precision_qualifier
1695 {
1696 memset(&$$, 0, sizeof($$));
1697 $$.precision = $1;
1698 }
1699
1700 /* Multiple qualifiers:
1701 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1702 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1703 *
1704 * invariant interpolation auxiliary storage precision ...or...
1705 * layout storage precision
1706 *
1707 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1708 * side don't contain any that must appear on the left hand side.
1709 * For example, when processing a storage qualifier, we check that there are
1710 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1711 */
1712 | PRECISE type_qualifier
1713 {
1714 if ($2.flags.q.precise)
1715 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1716
1717 $$ = $2;
1718 $$.flags.q.precise = 1;
1719 }
1720 | INVARIANT type_qualifier
1721 {
1722 if ($2.flags.q.invariant)
1723 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1724
1725 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1726 _mesa_glsl_error(&@1, state,
1727 "\"invariant\" must come after \"precise\"");
1728
1729 $$ = $2;
1730 $$.flags.q.invariant = 1;
1731
1732 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1733 *
1734 * "Only variables output from a shader can be candidates for invariance.
1735 * This includes user-defined output variables and the built-in output
1736 * variables. As only outputs can be declared as invariant, an invariant
1737 * output from one shader stage will still match an input of a subsequent
1738 * stage without the input being declared as invariant."
1739 */
1740 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1741 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1742 }
1743 | interpolation_qualifier type_qualifier
1744 {
1745 /* Section 4.3 of the GLSL 1.40 specification states:
1746 * "...qualified with one of these interpolation qualifiers"
1747 *
1748 * GLSL 1.30 claims to allow "one or more", but insists that:
1749 * "These interpolation qualifiers may only precede the qualifiers in,
1750 * centroid in, out, or centroid out in a declaration."
1751 *
1752 * ...which means that e.g. smooth can't precede smooth, so there can be
1753 * only one after all, and the 1.40 text is a clarification, not a change.
1754 */
1755 if ($2.has_interpolation())
1756 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1757
1758 if (!state->has_420pack_or_es31() &&
1759 ($2.flags.q.precise || $2.flags.q.invariant)) {
1760 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1761 "after \"precise\" or \"invariant\"");
1762 }
1763
1764 $$ = $1;
1765 $$.merge_qualifier(&@1, state, $2, false);
1766 }
1767 | layout_qualifier type_qualifier
1768 {
1769 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1770 * appear no later than auxiliary storage qualifiers. There is no
1771 * particularly clear spec language mandating this, but in all examples
1772 * the layout qualifier precedes the storage qualifier.
1773 *
1774 * We allow combinations of layout with interpolation, invariant or
1775 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1776 * There is no clear spec guidance on this either.
1777 */
1778 if (!state->has_420pack_or_es31() && $2.has_layout())
1779 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1780
1781 $$ = $1;
1782 $$.merge_qualifier(&@1, state, $2, false);
1783 }
1784 | subroutine_qualifier type_qualifier
1785 {
1786 $$ = $1;
1787 $$.merge_qualifier(&@1, state, $2, false);
1788 }
1789 | auxiliary_storage_qualifier type_qualifier
1790 {
1791 if ($2.has_auxiliary_storage()) {
1792 _mesa_glsl_error(&@1, state,
1793 "duplicate auxiliary storage qualifier (centroid or sample)");
1794 }
1795
1796 if (!state->has_420pack_or_es31() &&
1797 ($2.flags.q.precise || $2.flags.q.invariant ||
1798 $2.has_interpolation() || $2.has_layout())) {
1799 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1800 "just before storage qualifiers");
1801 }
1802 $$ = $1;
1803 $$.merge_qualifier(&@1, state, $2, false);
1804 }
1805 | storage_qualifier type_qualifier
1806 {
1807 /* Section 4.3 of the GLSL 1.20 specification states:
1808 * "Variable declarations may have a storage qualifier specified..."
1809 * 1.30 clarifies this to "may have one storage qualifier".
1810 */
1811 if ($2.has_storage())
1812 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1813
1814 if (!state->has_420pack_or_es31() &&
1815 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1816 $2.has_layout() || $2.has_auxiliary_storage())) {
1817 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1818 "precise, invariant, interpolation, layout and auxiliary "
1819 "storage qualifiers");
1820 }
1821
1822 $$ = $1;
1823 $$.merge_qualifier(&@1, state, $2, false);
1824 }
1825 | precision_qualifier type_qualifier
1826 {
1827 if ($2.precision != ast_precision_none)
1828 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1829
1830 if (!(state->has_420pack_or_es31()) &&
1831 $2.flags.i != 0)
1832 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1833
1834 $$ = $2;
1835 $$.precision = $1;
1836 }
1837 | memory_qualifier type_qualifier
1838 {
1839 $$ = $1;
1840 $$.merge_qualifier(&@1, state, $2, false);
1841 }
1842 ;
1843
1844 auxiliary_storage_qualifier:
1845 CENTROID
1846 {
1847 memset(& $$, 0, sizeof($$));
1848 $$.flags.q.centroid = 1;
1849 }
1850 | SAMPLE
1851 {
1852 memset(& $$, 0, sizeof($$));
1853 $$.flags.q.sample = 1;
1854 }
1855 | PATCH
1856 {
1857 memset(& $$, 0, sizeof($$));
1858 $$.flags.q.patch = 1;
1859 }
1860
1861 storage_qualifier:
1862 CONST_TOK
1863 {
1864 memset(& $$, 0, sizeof($$));
1865 $$.flags.q.constant = 1;
1866 }
1867 | ATTRIBUTE
1868 {
1869 memset(& $$, 0, sizeof($$));
1870 $$.flags.q.attribute = 1;
1871 }
1872 | VARYING
1873 {
1874 memset(& $$, 0, sizeof($$));
1875 $$.flags.q.varying = 1;
1876 }
1877 | IN_TOK
1878 {
1879 memset(& $$, 0, sizeof($$));
1880 $$.flags.q.in = 1;
1881 }
1882 | OUT_TOK
1883 {
1884 memset(& $$, 0, sizeof($$));
1885 $$.flags.q.out = 1;
1886
1887 if (state->stage == MESA_SHADER_GEOMETRY &&
1888 state->has_explicit_attrib_stream()) {
1889 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1890 * spec says:
1891 *
1892 * "If the block or variable is declared with the stream
1893 * identifier, it is associated with the specified stream;
1894 * otherwise, it is associated with the current default stream."
1895 */
1896 $$.flags.q.stream = 1;
1897 $$.flags.q.explicit_stream = 0;
1898 $$.stream = state->out_qualifier->stream;
1899 }
1900 }
1901 | UNIFORM
1902 {
1903 memset(& $$, 0, sizeof($$));
1904 $$.flags.q.uniform = 1;
1905 }
1906 | BUFFER
1907 {
1908 memset(& $$, 0, sizeof($$));
1909 $$.flags.q.buffer = 1;
1910 }
1911 | SHARED
1912 {
1913 memset(& $$, 0, sizeof($$));
1914 $$.flags.q.shared_storage = 1;
1915 }
1916 ;
1917
1918 memory_qualifier:
1919 COHERENT
1920 {
1921 memset(& $$, 0, sizeof($$));
1922 $$.flags.q.coherent = 1;
1923 }
1924 | VOLATILE
1925 {
1926 memset(& $$, 0, sizeof($$));
1927 $$.flags.q._volatile = 1;
1928 }
1929 | RESTRICT
1930 {
1931 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1932 memset(& $$, 0, sizeof($$));
1933 $$.flags.q.restrict_flag = 1;
1934 }
1935 | READONLY
1936 {
1937 memset(& $$, 0, sizeof($$));
1938 $$.flags.q.read_only = 1;
1939 }
1940 | WRITEONLY
1941 {
1942 memset(& $$, 0, sizeof($$));
1943 $$.flags.q.write_only = 1;
1944 }
1945 ;
1946
1947 array_specifier:
1948 '[' ']'
1949 {
1950 void *ctx = state;
1951 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
1952 ast_unsized_array_dim, NULL,
1953 NULL, NULL));
1954 $$->set_location_range(@1, @2);
1955 }
1956 | '[' constant_expression ']'
1957 {
1958 void *ctx = state;
1959 $$ = new(ctx) ast_array_specifier(@1, $2);
1960 $$->set_location_range(@1, @3);
1961 }
1962 | array_specifier '[' ']'
1963 {
1964 void *ctx = state;
1965 $$ = $1;
1966
1967 if (state->check_arrays_of_arrays_allowed(& @1)) {
1968 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
1969 NULL, NULL));
1970 }
1971 }
1972 | array_specifier '[' constant_expression ']'
1973 {
1974 $$ = $1;
1975
1976 if (state->check_arrays_of_arrays_allowed(& @1)) {
1977 $$->add_dimension($3);
1978 }
1979 }
1980 ;
1981
1982 type_specifier:
1983 type_specifier_nonarray
1984 | type_specifier_nonarray array_specifier
1985 {
1986 $$ = $1;
1987 $$->array_specifier = $2;
1988 }
1989 ;
1990
1991 type_specifier_nonarray:
1992 basic_type_specifier_nonarray
1993 {
1994 void *ctx = state;
1995 $$ = new(ctx) ast_type_specifier($1);
1996 $$->set_location(@1);
1997 }
1998 | struct_specifier
1999 {
2000 void *ctx = state;
2001 $$ = new(ctx) ast_type_specifier($1);
2002 $$->set_location(@1);
2003 }
2004 | TYPE_IDENTIFIER
2005 {
2006 void *ctx = state;
2007 $$ = new(ctx) ast_type_specifier($1);
2008 $$->set_location(@1);
2009 }
2010 ;
2011
2012 basic_type_specifier_nonarray:
2013 VOID_TOK { $$ = "void"; }
2014 | FLOAT_TOK { $$ = "float"; }
2015 | DOUBLE_TOK { $$ = "double"; }
2016 | INT_TOK { $$ = "int"; }
2017 | UINT_TOK { $$ = "uint"; }
2018 | BOOL_TOK { $$ = "bool"; }
2019 | VEC2 { $$ = "vec2"; }
2020 | VEC3 { $$ = "vec3"; }
2021 | VEC4 { $$ = "vec4"; }
2022 | BVEC2 { $$ = "bvec2"; }
2023 | BVEC3 { $$ = "bvec3"; }
2024 | BVEC4 { $$ = "bvec4"; }
2025 | IVEC2 { $$ = "ivec2"; }
2026 | IVEC3 { $$ = "ivec3"; }
2027 | IVEC4 { $$ = "ivec4"; }
2028 | UVEC2 { $$ = "uvec2"; }
2029 | UVEC3 { $$ = "uvec3"; }
2030 | UVEC4 { $$ = "uvec4"; }
2031 | DVEC2 { $$ = "dvec2"; }
2032 | DVEC3 { $$ = "dvec3"; }
2033 | DVEC4 { $$ = "dvec4"; }
2034 | MAT2X2 { $$ = "mat2"; }
2035 | MAT2X3 { $$ = "mat2x3"; }
2036 | MAT2X4 { $$ = "mat2x4"; }
2037 | MAT3X2 { $$ = "mat3x2"; }
2038 | MAT3X3 { $$ = "mat3"; }
2039 | MAT3X4 { $$ = "mat3x4"; }
2040 | MAT4X2 { $$ = "mat4x2"; }
2041 | MAT4X3 { $$ = "mat4x3"; }
2042 | MAT4X4 { $$ = "mat4"; }
2043 | DMAT2X2 { $$ = "dmat2"; }
2044 | DMAT2X3 { $$ = "dmat2x3"; }
2045 | DMAT2X4 { $$ = "dmat2x4"; }
2046 | DMAT3X2 { $$ = "dmat3x2"; }
2047 | DMAT3X3 { $$ = "dmat3"; }
2048 | DMAT3X4 { $$ = "dmat3x4"; }
2049 | DMAT4X2 { $$ = "dmat4x2"; }
2050 | DMAT4X3 { $$ = "dmat4x3"; }
2051 | DMAT4X4 { $$ = "dmat4"; }
2052 | SAMPLER1D { $$ = "sampler1D"; }
2053 | SAMPLER2D { $$ = "sampler2D"; }
2054 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2055 | SAMPLER3D { $$ = "sampler3D"; }
2056 | SAMPLERCUBE { $$ = "samplerCube"; }
2057 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2058 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2059 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2060 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2061 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2062 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2063 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2064 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2065 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2066 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2067 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2068 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2069 | ISAMPLER1D { $$ = "isampler1D"; }
2070 | ISAMPLER2D { $$ = "isampler2D"; }
2071 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2072 | ISAMPLER3D { $$ = "isampler3D"; }
2073 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2074 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2075 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2076 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2077 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2078 | USAMPLER1D { $$ = "usampler1D"; }
2079 | USAMPLER2D { $$ = "usampler2D"; }
2080 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2081 | USAMPLER3D { $$ = "usampler3D"; }
2082 | USAMPLERCUBE { $$ = "usamplerCube"; }
2083 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2084 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2085 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2086 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2087 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2088 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2089 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2090 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2091 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2092 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2093 | IMAGE1D { $$ = "image1D"; }
2094 | IMAGE2D { $$ = "image2D"; }
2095 | IMAGE3D { $$ = "image3D"; }
2096 | IMAGE2DRECT { $$ = "image2DRect"; }
2097 | IMAGECUBE { $$ = "imageCube"; }
2098 | IMAGEBUFFER { $$ = "imageBuffer"; }
2099 | IMAGE1DARRAY { $$ = "image1DArray"; }
2100 | IMAGE2DARRAY { $$ = "image2DArray"; }
2101 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2102 | IMAGE2DMS { $$ = "image2DMS"; }
2103 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2104 | IIMAGE1D { $$ = "iimage1D"; }
2105 | IIMAGE2D { $$ = "iimage2D"; }
2106 | IIMAGE3D { $$ = "iimage3D"; }
2107 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2108 | IIMAGECUBE { $$ = "iimageCube"; }
2109 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2110 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2111 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2112 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2113 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2114 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2115 | UIMAGE1D { $$ = "uimage1D"; }
2116 | UIMAGE2D { $$ = "uimage2D"; }
2117 | UIMAGE3D { $$ = "uimage3D"; }
2118 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2119 | UIMAGECUBE { $$ = "uimageCube"; }
2120 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2121 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2122 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2123 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2124 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2125 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2126 | ATOMIC_UINT { $$ = "atomic_uint"; }
2127 ;
2128
2129 precision_qualifier:
2130 HIGHP
2131 {
2132 state->check_precision_qualifiers_allowed(&@1);
2133 $$ = ast_precision_high;
2134 }
2135 | MEDIUMP
2136 {
2137 state->check_precision_qualifiers_allowed(&@1);
2138 $$ = ast_precision_medium;
2139 }
2140 | LOWP
2141 {
2142 state->check_precision_qualifiers_allowed(&@1);
2143 $$ = ast_precision_low;
2144 }
2145 ;
2146
2147 struct_specifier:
2148 STRUCT any_identifier '{' struct_declaration_list '}'
2149 {
2150 void *ctx = state;
2151 $$ = new(ctx) ast_struct_specifier($2, $4);
2152 $$->set_location_range(@2, @5);
2153 state->symbols->add_type($2, glsl_type::void_type);
2154 }
2155 | STRUCT '{' struct_declaration_list '}'
2156 {
2157 void *ctx = state;
2158 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2159 $$->set_location_range(@2, @4);
2160 }
2161 ;
2162
2163 struct_declaration_list:
2164 struct_declaration
2165 {
2166 $$ = $1;
2167 $1->link.self_link();
2168 }
2169 | struct_declaration_list struct_declaration
2170 {
2171 $$ = $1;
2172 $$->link.insert_before(& $2->link);
2173 }
2174 ;
2175
2176 struct_declaration:
2177 fully_specified_type struct_declarator_list ';'
2178 {
2179 void *ctx = state;
2180 ast_fully_specified_type *const type = $1;
2181 type->set_location(@1);
2182
2183 if (type->qualifier.flags.i != 0)
2184 _mesa_glsl_error(&@1, state,
2185 "only precision qualifiers may be applied to "
2186 "structure members");
2187
2188 $$ = new(ctx) ast_declarator_list(type);
2189 $$->set_location(@2);
2190
2191 $$->declarations.push_degenerate_list_at_head(& $2->link);
2192 }
2193 ;
2194
2195 struct_declarator_list:
2196 struct_declarator
2197 {
2198 $$ = $1;
2199 $1->link.self_link();
2200 }
2201 | struct_declarator_list ',' struct_declarator
2202 {
2203 $$ = $1;
2204 $$->link.insert_before(& $3->link);
2205 }
2206 ;
2207
2208 struct_declarator:
2209 any_identifier
2210 {
2211 void *ctx = state;
2212 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2213 $$->set_location(@1);
2214 }
2215 | any_identifier array_specifier
2216 {
2217 void *ctx = state;
2218 $$ = new(ctx) ast_declaration($1, $2, NULL);
2219 $$->set_location_range(@1, @2);
2220 }
2221 ;
2222
2223 initializer:
2224 assignment_expression
2225 | '{' initializer_list '}'
2226 {
2227 $$ = $2;
2228 }
2229 | '{' initializer_list ',' '}'
2230 {
2231 $$ = $2;
2232 }
2233 ;
2234
2235 initializer_list:
2236 initializer
2237 {
2238 void *ctx = state;
2239 $$ = new(ctx) ast_aggregate_initializer();
2240 $$->set_location(@1);
2241 $$->expressions.push_tail(& $1->link);
2242 }
2243 | initializer_list ',' initializer
2244 {
2245 $1->expressions.push_tail(& $3->link);
2246 }
2247 ;
2248
2249 declaration_statement:
2250 declaration
2251 ;
2252
2253 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2254 // supported.
2255 statement:
2256 compound_statement { $$ = (ast_node *) $1; }
2257 | simple_statement
2258 ;
2259
2260 simple_statement:
2261 declaration_statement
2262 | expression_statement
2263 | selection_statement
2264 | switch_statement
2265 | iteration_statement
2266 | jump_statement
2267 ;
2268
2269 compound_statement:
2270 '{' '}'
2271 {
2272 void *ctx = state;
2273 $$ = new(ctx) ast_compound_statement(true, NULL);
2274 $$->set_location_range(@1, @2);
2275 }
2276 | '{'
2277 {
2278 state->symbols->push_scope();
2279 }
2280 statement_list '}'
2281 {
2282 void *ctx = state;
2283 $$ = new(ctx) ast_compound_statement(true, $3);
2284 $$->set_location_range(@1, @4);
2285 state->symbols->pop_scope();
2286 }
2287 ;
2288
2289 statement_no_new_scope:
2290 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2291 | simple_statement
2292 ;
2293
2294 compound_statement_no_new_scope:
2295 '{' '}'
2296 {
2297 void *ctx = state;
2298 $$ = new(ctx) ast_compound_statement(false, NULL);
2299 $$->set_location_range(@1, @2);
2300 }
2301 | '{' statement_list '}'
2302 {
2303 void *ctx = state;
2304 $$ = new(ctx) ast_compound_statement(false, $2);
2305 $$->set_location_range(@1, @3);
2306 }
2307 ;
2308
2309 statement_list:
2310 statement
2311 {
2312 if ($1 == NULL) {
2313 _mesa_glsl_error(& @1, state, "<nil> statement");
2314 assert($1 != NULL);
2315 }
2316
2317 $$ = $1;
2318 $$->link.self_link();
2319 }
2320 | statement_list statement
2321 {
2322 if ($2 == NULL) {
2323 _mesa_glsl_error(& @2, state, "<nil> statement");
2324 assert($2 != NULL);
2325 }
2326 $$ = $1;
2327 $$->link.insert_before(& $2->link);
2328 }
2329 ;
2330
2331 expression_statement:
2332 ';'
2333 {
2334 void *ctx = state;
2335 $$ = new(ctx) ast_expression_statement(NULL);
2336 $$->set_location(@1);
2337 }
2338 | expression ';'
2339 {
2340 void *ctx = state;
2341 $$ = new(ctx) ast_expression_statement($1);
2342 $$->set_location(@1);
2343 }
2344 ;
2345
2346 selection_statement:
2347 IF '(' expression ')' selection_rest_statement
2348 {
2349 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2350 $5.else_statement);
2351 $$->set_location_range(@1, @5);
2352 }
2353 ;
2354
2355 selection_rest_statement:
2356 statement ELSE statement
2357 {
2358 $$.then_statement = $1;
2359 $$.else_statement = $3;
2360 }
2361 | statement %prec THEN
2362 {
2363 $$.then_statement = $1;
2364 $$.else_statement = NULL;
2365 }
2366 ;
2367
2368 condition:
2369 expression
2370 {
2371 $$ = (ast_node *) $1;
2372 }
2373 | fully_specified_type any_identifier '=' initializer
2374 {
2375 void *ctx = state;
2376 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2377 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2378 decl->set_location_range(@2, @4);
2379 declarator->set_location(@1);
2380
2381 declarator->declarations.push_tail(&decl->link);
2382 $$ = declarator;
2383 }
2384 ;
2385
2386 /*
2387 * switch_statement grammar is based on the syntax described in the body
2388 * of the GLSL spec, not in it's appendix!!!
2389 */
2390 switch_statement:
2391 SWITCH '(' expression ')' switch_body
2392 {
2393 $$ = new(state) ast_switch_statement($3, $5);
2394 $$->set_location_range(@1, @5);
2395 }
2396 ;
2397
2398 switch_body:
2399 '{' '}'
2400 {
2401 $$ = new(state) ast_switch_body(NULL);
2402 $$->set_location_range(@1, @2);
2403 }
2404 | '{' case_statement_list '}'
2405 {
2406 $$ = new(state) ast_switch_body($2);
2407 $$->set_location_range(@1, @3);
2408 }
2409 ;
2410
2411 case_label:
2412 CASE expression ':'
2413 {
2414 $$ = new(state) ast_case_label($2);
2415 $$->set_location(@2);
2416 }
2417 | DEFAULT ':'
2418 {
2419 $$ = new(state) ast_case_label(NULL);
2420 $$->set_location(@2);
2421 }
2422 ;
2423
2424 case_label_list:
2425 case_label
2426 {
2427 ast_case_label_list *labels = new(state) ast_case_label_list();
2428
2429 labels->labels.push_tail(& $1->link);
2430 $$ = labels;
2431 $$->set_location(@1);
2432 }
2433 | case_label_list case_label
2434 {
2435 $$ = $1;
2436 $$->labels.push_tail(& $2->link);
2437 }
2438 ;
2439
2440 case_statement:
2441 case_label_list statement
2442 {
2443 ast_case_statement *stmts = new(state) ast_case_statement($1);
2444 stmts->set_location(@2);
2445
2446 stmts->stmts.push_tail(& $2->link);
2447 $$ = stmts;
2448 }
2449 | case_statement statement
2450 {
2451 $$ = $1;
2452 $$->stmts.push_tail(& $2->link);
2453 }
2454 ;
2455
2456 case_statement_list:
2457 case_statement
2458 {
2459 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2460 cases->set_location(@1);
2461
2462 cases->cases.push_tail(& $1->link);
2463 $$ = cases;
2464 }
2465 | case_statement_list case_statement
2466 {
2467 $$ = $1;
2468 $$->cases.push_tail(& $2->link);
2469 }
2470 ;
2471
2472 iteration_statement:
2473 WHILE '(' condition ')' statement_no_new_scope
2474 {
2475 void *ctx = state;
2476 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2477 NULL, $3, NULL, $5);
2478 $$->set_location_range(@1, @4);
2479 }
2480 | DO statement WHILE '(' expression ')' ';'
2481 {
2482 void *ctx = state;
2483 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2484 NULL, $5, NULL, $2);
2485 $$->set_location_range(@1, @6);
2486 }
2487 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2488 {
2489 void *ctx = state;
2490 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2491 $3, $4.cond, $4.rest, $6);
2492 $$->set_location_range(@1, @6);
2493 }
2494 ;
2495
2496 for_init_statement:
2497 expression_statement
2498 | declaration_statement
2499 ;
2500
2501 conditionopt:
2502 condition
2503 | /* empty */
2504 {
2505 $$ = NULL;
2506 }
2507 ;
2508
2509 for_rest_statement:
2510 conditionopt ';'
2511 {
2512 $$.cond = $1;
2513 $$.rest = NULL;
2514 }
2515 | conditionopt ';' expression
2516 {
2517 $$.cond = $1;
2518 $$.rest = $3;
2519 }
2520 ;
2521
2522 // Grammar Note: No 'goto'. Gotos are not supported.
2523 jump_statement:
2524 CONTINUE ';'
2525 {
2526 void *ctx = state;
2527 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2528 $$->set_location(@1);
2529 }
2530 | BREAK ';'
2531 {
2532 void *ctx = state;
2533 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2534 $$->set_location(@1);
2535 }
2536 | RETURN ';'
2537 {
2538 void *ctx = state;
2539 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2540 $$->set_location(@1);
2541 }
2542 | RETURN expression ';'
2543 {
2544 void *ctx = state;
2545 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2546 $$->set_location_range(@1, @2);
2547 }
2548 | DISCARD ';' // Fragment shader only.
2549 {
2550 void *ctx = state;
2551 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2552 $$->set_location(@1);
2553 }
2554 ;
2555
2556 external_declaration:
2557 function_definition { $$ = $1; }
2558 | declaration { $$ = $1; }
2559 | pragma_statement { $$ = NULL; }
2560 | layout_defaults { $$ = $1; }
2561 ;
2562
2563 function_definition:
2564 function_prototype compound_statement_no_new_scope
2565 {
2566 void *ctx = state;
2567 $$ = new(ctx) ast_function_definition();
2568 $$->set_location_range(@1, @2);
2569 $$->prototype = $1;
2570 $$->body = $2;
2571
2572 state->symbols->pop_scope();
2573 }
2574 ;
2575
2576 /* layout_qualifieropt is packed into this rule */
2577 interface_block:
2578 basic_interface_block
2579 {
2580 $$ = $1;
2581 }
2582 | layout_qualifier interface_block
2583 {
2584 ast_interface_block *block = (ast_interface_block *) $2;
2585
2586 if (!state->has_420pack_or_es31() && block->layout.has_layout() &&
2587 !block->layout.is_default_qualifier) {
2588 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2589 YYERROR;
2590 }
2591
2592 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2593 YYERROR;
2594 }
2595
2596 block->layout.is_default_qualifier = false;
2597
2598 $$ = block;
2599 }
2600 | memory_qualifier interface_block
2601 {
2602 ast_interface_block *block = (ast_interface_block *)$2;
2603
2604 if (!block->layout.flags.q.buffer) {
2605 _mesa_glsl_error(& @1, state,
2606 "memory qualifiers can only be used in the "
2607 "declaration of shader storage blocks");
2608 }
2609 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2610 YYERROR;
2611 }
2612 $$ = block;
2613 }
2614 ;
2615
2616 basic_interface_block:
2617 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2618 {
2619 ast_interface_block *const block = $6;
2620
2621 block->block_name = $2;
2622 block->declarations.push_degenerate_list_at_head(& $4->link);
2623
2624 _mesa_ast_process_interface_block(& @1, state, block, $1);
2625
2626 $$ = block;
2627 }
2628 | buffer_interface_qualifier NEW_IDENTIFIER '{' member_list '}' buffer_instance_name_opt ';'
2629 {
2630 ast_interface_block *const block = $6;
2631
2632 block->block_name = $2;
2633 block->declarations.push_degenerate_list_at_head(& $4->link);
2634
2635 _mesa_ast_process_interface_block(& @1, state, block, $1);
2636
2637 $$ = block;
2638 }
2639 ;
2640
2641 interface_qualifier:
2642 IN_TOK
2643 {
2644 memset(& $$, 0, sizeof($$));
2645 $$.flags.q.in = 1;
2646 }
2647 | OUT_TOK
2648 {
2649 memset(& $$, 0, sizeof($$));
2650 $$.flags.q.out = 1;
2651 }
2652 | UNIFORM
2653 {
2654 memset(& $$, 0, sizeof($$));
2655 $$.flags.q.uniform = 1;
2656 }
2657 ;
2658
2659 buffer_interface_qualifier:
2660 BUFFER
2661 {
2662 memset(& $$, 0, sizeof($$));
2663 $$.flags.q.buffer = 1;
2664 }
2665 ;
2666
2667 instance_name_opt:
2668 /* empty */
2669 {
2670 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2671 NULL, NULL);
2672 }
2673 | NEW_IDENTIFIER
2674 {
2675 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2676 $1, NULL);
2677 $$->set_location(@1);
2678 }
2679 | NEW_IDENTIFIER array_specifier
2680 {
2681 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2682 $1, $2);
2683 $$->set_location_range(@1, @2);
2684 }
2685 ;
2686
2687 buffer_instance_name_opt:
2688 /* empty */
2689 {
2690 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2691 NULL, NULL);
2692 }
2693 | NEW_IDENTIFIER
2694 {
2695 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2696 $1, NULL);
2697 $$->set_location(@1);
2698 }
2699 | NEW_IDENTIFIER array_specifier
2700 {
2701 $$ = new(state) ast_interface_block(*state->default_shader_storage_qualifier,
2702 $1, $2);
2703 $$->set_location_range(@1, @2);
2704 }
2705 ;
2706
2707 member_list:
2708 member_declaration
2709 {
2710 $$ = $1;
2711 $1->link.self_link();
2712 }
2713 | member_declaration member_list
2714 {
2715 $$ = $1;
2716 $2->link.insert_before(& $$->link);
2717 }
2718 ;
2719
2720 member_declaration:
2721 fully_specified_type struct_declarator_list ';'
2722 {
2723 void *ctx = state;
2724 ast_fully_specified_type *type = $1;
2725 type->set_location(@1);
2726
2727 if (type->qualifier.flags.q.attribute) {
2728 _mesa_glsl_error(& @1, state,
2729 "keyword 'attribute' cannot be used with "
2730 "interface block member");
2731 } else if (type->qualifier.flags.q.varying) {
2732 _mesa_glsl_error(& @1, state,
2733 "keyword 'varying' cannot be used with "
2734 "interface block member");
2735 }
2736
2737 $$ = new(ctx) ast_declarator_list(type);
2738 $$->set_location(@2);
2739
2740 $$->declarations.push_degenerate_list_at_head(& $2->link);
2741 }
2742 ;
2743
2744 layout_uniform_defaults:
2745 layout_qualifier layout_uniform_defaults
2746 {
2747 $$ = NULL;
2748 if (!state->has_420pack_or_es31()) {
2749 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2750 YYERROR;
2751 } else {
2752 if (!state->default_uniform_qualifier->
2753 merge_qualifier(& @1, state, $1, false)) {
2754 YYERROR;
2755 }
2756 }
2757 }
2758 | layout_qualifier UNIFORM ';'
2759 {
2760 if (!state->default_uniform_qualifier->
2761 merge_qualifier(& @1, state, $1, false)) {
2762 YYERROR;
2763 }
2764 $$ = NULL;
2765 }
2766 ;
2767
2768 layout_buffer_defaults:
2769 layout_qualifier layout_buffer_defaults
2770 {
2771 $$ = NULL;
2772 if (!state->has_420pack_or_es31()) {
2773 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2774 YYERROR;
2775 } else {
2776 if (!state->default_shader_storage_qualifier->
2777 merge_qualifier(& @1, state, $1, false)) {
2778 YYERROR;
2779 }
2780 }
2781 }
2782 | layout_qualifier BUFFER ';'
2783 {
2784 if (!state->default_shader_storage_qualifier->
2785 merge_qualifier(& @1, state, $1, false)) {
2786 YYERROR;
2787 }
2788
2789 /* From the GLSL 4.50 spec, section 4.4.5:
2790 *
2791 * "It is a compile-time error to specify the binding identifier for
2792 * the global scope or for block member declarations."
2793 */
2794 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2795 _mesa_glsl_error(& @1, state,
2796 "binding qualifier cannot be set for default layout");
2797 }
2798
2799 $$ = NULL;
2800 }
2801 ;
2802
2803 layout_in_defaults:
2804 layout_qualifier layout_in_defaults
2805 {
2806 $$ = NULL;
2807 if (!state->has_420pack_or_es31()) {
2808 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2809 YYERROR;
2810 } else {
2811 if (!state->in_qualifier->
2812 merge_in_qualifier(& @1, state, $1, $$, false)) {
2813 YYERROR;
2814 }
2815 }
2816 }
2817 | layout_qualifier IN_TOK ';'
2818 {
2819 $$ = NULL;
2820 if (!state->in_qualifier->
2821 merge_in_qualifier(& @1, state, $1, $$, true)) {
2822 YYERROR;
2823 }
2824 }
2825 ;
2826
2827 layout_out_defaults:
2828 layout_qualifier layout_out_defaults
2829 {
2830 $$ = NULL;
2831 if (!state->has_420pack_or_es31()) {
2832 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2833 YYERROR;
2834 } else {
2835 if (!state->out_qualifier->
2836 merge_out_qualifier(& @1, state, $1, $$, false)) {
2837 YYERROR;
2838 }
2839 }
2840 }
2841 | layout_qualifier OUT_TOK ';'
2842 {
2843 $$ = NULL;
2844 if (!state->out_qualifier->
2845 merge_out_qualifier(& @1, state, $1, $$, true))
2846 YYERROR;
2847 }
2848 ;
2849
2850 layout_defaults:
2851 layout_uniform_defaults
2852 | layout_buffer_defaults
2853 | layout_in_defaults
2854 | layout_out_defaults
2855 ;