78a4e5df7cf689cafa3ea2803d84f89322b8257e
[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 %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
181 %token SUB_ASSIGN
182 %token INVARIANT PRECISE
183 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
184
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
189 %token LAYOUT_TOK
190 %token DOT_TOK
191 /* Reserved words that are not actually used in the grammar.
192 */
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
197 %token SAMPLER3DRECT
198 %token SIZEOF CAST NAMESPACE USING
199 %token RESOURCE PATCH
200 %token SUBROUTINE
201
202 %token ERROR_TOK
203
204 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
205
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_qualifier> uniform_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 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1066 }
1067 | fully_specified_type any_identifier array_specifier
1068 {
1069 void *ctx = state;
1070 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1071 decl->set_location_range(@2, @3);
1072
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));
1077 }
1078 | fully_specified_type any_identifier array_specifier '=' initializer
1079 {
1080 void *ctx = state;
1081 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1082 decl->set_location_range(@2, @3);
1083
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));
1088 }
1089 | fully_specified_type any_identifier '=' initializer
1090 {
1091 void *ctx = state;
1092 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1093 decl->set_location(@2);
1094
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));
1099 }
1100 | INVARIANT variable_identifier
1101 {
1102 void *ctx = state;
1103 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1104 decl->set_location(@2);
1105
1106 $$ = new(ctx) ast_declarator_list(NULL);
1107 $$->set_location_range(@1, @2);
1108 $$->invariant = true;
1109
1110 $$->declarations.push_tail(&decl->link);
1111 }
1112 | PRECISE variable_identifier
1113 {
1114 void *ctx = state;
1115 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1116 decl->set_location(@2);
1117
1118 $$ = new(ctx) ast_declarator_list(NULL);
1119 $$->set_location_range(@1, @2);
1120 $$->precise = true;
1121
1122 $$->declarations.push_tail(&decl->link);
1123 }
1124 ;
1125
1126 fully_specified_type:
1127 type_specifier
1128 {
1129 void *ctx = state;
1130 $$ = new(ctx) ast_fully_specified_type();
1131 $$->set_location(@1);
1132 $$->specifier = $1;
1133 }
1134 | type_qualifier type_specifier
1135 {
1136 void *ctx = state;
1137 $$ = new(ctx) ast_fully_specified_type();
1138 $$->set_location_range(@1, @2);
1139 $$->qualifier = $1;
1140 $$->specifier = $2;
1141 if ($$->specifier->structure != NULL &&
1142 $$->specifier->structure->is_declaration) {
1143 $$->specifier->structure->layout = &$$->qualifier;
1144 }
1145 }
1146 ;
1147
1148 layout_qualifier:
1149 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1150 {
1151 $$ = $3;
1152 }
1153 ;
1154
1155 layout_qualifier_id_list:
1156 layout_qualifier_id
1157 | layout_qualifier_id_list ',' layout_qualifier_id
1158 {
1159 $$ = $1;
1160 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1161 YYERROR;
1162 }
1163 }
1164 ;
1165
1166 layout_qualifier_id:
1167 any_identifier
1168 {
1169 memset(& $$, 0, sizeof($$));
1170
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",
1177 state) == 0) {
1178 $$.flags.q.pixel_center_integer = 1;
1179 }
1180
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);
1185 }
1186 }
1187
1188 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1189 if (!$$.flags.i &&
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",
1200 state) == 0) {
1201 $$.flags.q.depth_unchanged = 1;
1202 }
1203
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);
1208 }
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);
1213 }
1214 }
1215
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.
1228 *
1229 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1230 * an identifier.
1231 *
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).
1235 */
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
1242 * in desktop GLSL.
1243 */
1244 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1245 $$.flags.q.packed = 1;
1246 }
1247
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);
1252 }
1253 }
1254
1255 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1256 if (!$$.flags.i) {
1257 static const struct {
1258 const char *s;
1259 GLenum e;
1260 } map[] = {
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 },
1268 };
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;
1273 break;
1274 }
1275 }
1276
1277 if ($$.flags.i && !state->has_geometry_shader()) {
1278 _mesa_glsl_error(& @1, state, "#version 150 layout "
1279 "qualifier `%s' used", $1);
1280 }
1281 }
1282
1283 /* Layout qualifiers for ARB_shader_image_load_store. */
1284 if (state->ARB_shader_image_load_store_enable ||
1285 state->is_version(420, 310)) {
1286 if (!$$.flags.i) {
1287 static const struct {
1288 const char *name;
1289 GLenum format;
1290 glsl_base_type base_type;
1291 /** Minimum desktop GLSL version required for the image
1292 * format. Use 130 if already present in the original
1293 * ARB extension.
1294 */
1295 unsigned required_glsl;
1296 /** Minimum GLSL ES version required for the image format. */
1297 unsigned required_essl;
1298 } map[] = {
1299 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310 },
1300 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310 },
1301 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0 },
1302 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0 },
1303 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0 },
1304 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310 },
1305 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0 },
1306 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310 },
1307 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310 },
1308 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0 },
1309 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310 },
1310 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0 },
1311 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0 },
1312 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0 },
1313 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310 },
1314 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0 },
1315 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0 },
1316 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310 },
1317 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310 },
1318 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310 },
1319 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0 },
1320 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0 },
1321 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0 },
1322 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310 },
1323 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0 },
1324 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0 },
1325 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0 },
1326 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0 },
1327 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310 },
1328 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0 },
1329 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0 },
1330 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0 },
1331 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0 },
1332 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1333 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310 },
1334 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1335 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1336 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0 },
1337 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0 }
1338 };
1339
1340 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1341 if (state->is_version(map[i].required_glsl,
1342 map[i].required_essl) &&
1343 match_layout_qualifier($1, map[i].name, state) == 0) {
1344 $$.flags.q.explicit_image_format = 1;
1345 $$.image_format = map[i].format;
1346 $$.image_base_type = map[i].base_type;
1347 break;
1348 }
1349 }
1350 }
1351
1352 if (!$$.flags.i &&
1353 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1354 /* From section 4.4.1.3 of the GLSL 4.50 specification
1355 * (Fragment Shader Inputs):
1356 *
1357 * "Fragment shaders also allow the following layout
1358 * qualifier on in only (not with variable declarations)
1359 * layout-qualifier-id
1360 * early_fragment_tests
1361 * [...]"
1362 */
1363 if (state->stage != MESA_SHADER_FRAGMENT) {
1364 _mesa_glsl_error(& @1, state,
1365 "early_fragment_tests layout qualifier only "
1366 "valid in fragment shaders");
1367 }
1368
1369 $$.flags.q.early_fragment_tests = 1;
1370 }
1371 }
1372
1373 /* Layout qualifiers for tessellation evaluation shaders. */
1374 if (!$$.flags.i) {
1375 struct {
1376 const char *s;
1377 GLenum e;
1378 } map[] = {
1379 /* triangles already parsed by gs-specific code */
1380 { "quads", GL_QUADS },
1381 { "isolines", GL_ISOLINES },
1382 };
1383 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1384 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1385 $$.flags.q.prim_type = 1;
1386 $$.prim_type = map[i].e;
1387 break;
1388 }
1389 }
1390
1391 if ($$.flags.i &&
1392 !state->ARB_tessellation_shader_enable &&
1393 !state->is_version(400, 0)) {
1394 _mesa_glsl_error(& @1, state,
1395 "primitive mode qualifier `%s' requires "
1396 "GLSL 4.00 or ARB_tessellation_shader", $1);
1397 }
1398 }
1399 if (!$$.flags.i) {
1400 struct {
1401 const char *s;
1402 GLenum e;
1403 } map[] = {
1404 { "equal_spacing", GL_EQUAL },
1405 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
1406 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
1407 };
1408 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1409 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1410 $$.flags.q.vertex_spacing = 1;
1411 $$.vertex_spacing = map[i].e;
1412 break;
1413 }
1414 }
1415
1416 if ($$.flags.i &&
1417 !state->ARB_tessellation_shader_enable &&
1418 !state->is_version(400, 0)) {
1419 _mesa_glsl_error(& @1, state,
1420 "vertex spacing qualifier `%s' requires "
1421 "GLSL 4.00 or ARB_tessellation_shader", $1);
1422 }
1423 }
1424 if (!$$.flags.i) {
1425 if (match_layout_qualifier($1, "cw", state) == 0) {
1426 $$.flags.q.ordering = 1;
1427 $$.ordering = GL_CW;
1428 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1429 $$.flags.q.ordering = 1;
1430 $$.ordering = GL_CCW;
1431 }
1432
1433 if ($$.flags.i &&
1434 !state->ARB_tessellation_shader_enable &&
1435 !state->is_version(400, 0)) {
1436 _mesa_glsl_error(& @1, state,
1437 "ordering qualifier `%s' requires "
1438 "GLSL 4.00 or ARB_tessellation_shader", $1);
1439 }
1440 }
1441 if (!$$.flags.i) {
1442 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1443 $$.flags.q.point_mode = 1;
1444 $$.point_mode = true;
1445 }
1446
1447 if ($$.flags.i &&
1448 !state->ARB_tessellation_shader_enable &&
1449 !state->is_version(400, 0)) {
1450 _mesa_glsl_error(& @1, state,
1451 "qualifier `point_mode' requires "
1452 "GLSL 4.00 or ARB_tessellation_shader");
1453 }
1454 }
1455
1456 if (!$$.flags.i) {
1457 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1458 "`%s'", $1);
1459 YYERROR;
1460 }
1461 }
1462 | any_identifier '=' constant_expression
1463 {
1464 memset(& $$, 0, sizeof($$));
1465 void *ctx = state;
1466
1467 if ($3->oper != ast_int_constant &&
1468 $3->oper != ast_uint_constant &&
1469 !state->has_enhanced_layouts()) {
1470 _mesa_glsl_error(& @1, state,
1471 "compile-time constant expressions require "
1472 "GLSL 4.40 or ARB_enhanced_layouts");
1473 }
1474
1475 if (match_layout_qualifier("align", $1, state) == 0) {
1476 if (!state->has_enhanced_layouts()) {
1477 _mesa_glsl_error(& @1, state,
1478 "align qualifier requires "
1479 "GLSL 4.40 or ARB_enhanced_layouts");
1480 } else {
1481 $$.flags.q.explicit_align = 1;
1482 $$.align = $3;
1483 }
1484 }
1485
1486 if (match_layout_qualifier("location", $1, state) == 0) {
1487 $$.flags.q.explicit_location = 1;
1488
1489 if ($$.flags.q.attribute == 1 &&
1490 state->ARB_explicit_attrib_location_warn) {
1491 _mesa_glsl_warning(& @1, state,
1492 "GL_ARB_explicit_attrib_location layout "
1493 "identifier `%s' used", $1);
1494 }
1495 $$.location = $3;
1496 }
1497
1498 if (match_layout_qualifier("index", $1, state) == 0) {
1499 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1500 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1501 YYERROR;
1502 }
1503
1504 $$.flags.q.explicit_index = 1;
1505 $$.index = $3;
1506 }
1507
1508 if ((state->has_420pack_or_es31() ||
1509 state->has_atomic_counters() ||
1510 state->has_shader_storage_buffer_objects()) &&
1511 match_layout_qualifier("binding", $1, state) == 0) {
1512 $$.flags.q.explicit_binding = 1;
1513 $$.binding = $3;
1514 }
1515
1516 if ((state->has_atomic_counters() ||
1517 state->has_enhanced_layouts()) &&
1518 match_layout_qualifier("offset", $1, state) == 0) {
1519 $$.flags.q.explicit_offset = 1;
1520 $$.offset = $3;
1521 }
1522
1523 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1524 $$.flags.q.max_vertices = 1;
1525 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1526 if (!state->has_geometry_shader()) {
1527 _mesa_glsl_error(& @3, state,
1528 "#version 150 max_vertices qualifier "
1529 "specified", $3);
1530 }
1531 }
1532
1533 if (state->stage == MESA_SHADER_GEOMETRY) {
1534 if (match_layout_qualifier("stream", $1, state) == 0 &&
1535 state->check_explicit_attrib_stream_allowed(& @3)) {
1536 $$.flags.q.stream = 1;
1537 $$.flags.q.explicit_stream = 1;
1538 $$.stream = $3;
1539 }
1540 }
1541
1542 static const char * const local_size_qualifiers[3] = {
1543 "local_size_x",
1544 "local_size_y",
1545 "local_size_z",
1546 };
1547 for (int i = 0; i < 3; i++) {
1548 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1549 state) == 0) {
1550 if (!state->has_compute_shader()) {
1551 _mesa_glsl_error(& @3, state,
1552 "%s qualifier requires GLSL 4.30 or "
1553 "GLSL ES 3.10 or ARB_compute_shader",
1554 local_size_qualifiers[i]);
1555 YYERROR;
1556 } else {
1557 $$.flags.q.local_size |= (1 << i);
1558 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1559 }
1560 break;
1561 }
1562 }
1563
1564 if (match_layout_qualifier("invocations", $1, state) == 0) {
1565 $$.flags.q.invocations = 1;
1566 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1567 if (!state->is_version(400, 0) &&
1568 !state->ARB_gpu_shader5_enable) {
1569 _mesa_glsl_error(& @3, state,
1570 "GL_ARB_gpu_shader5 invocations "
1571 "qualifier specified", $3);
1572 }
1573 }
1574
1575 /* Layout qualifiers for tessellation control shaders. */
1576 if (match_layout_qualifier("vertices", $1, state) == 0) {
1577 $$.flags.q.vertices = 1;
1578 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1579 if (!state->ARB_tessellation_shader_enable &&
1580 !state->is_version(400, 0)) {
1581 _mesa_glsl_error(& @1, state,
1582 "vertices qualifier requires GLSL 4.00 or "
1583 "ARB_tessellation_shader");
1584 }
1585 }
1586
1587 /* If the identifier didn't match any known layout identifiers,
1588 * emit an error.
1589 */
1590 if (!$$.flags.i) {
1591 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1592 "`%s'", $1);
1593 YYERROR;
1594 }
1595 }
1596 | interface_block_layout_qualifier
1597 {
1598 $$ = $1;
1599 /* Layout qualifiers for ARB_uniform_buffer_object. */
1600 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1601 _mesa_glsl_error(& @1, state,
1602 "#version 140 / GL_ARB_uniform_buffer_object "
1603 "layout qualifier `%s' is used", $1);
1604 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1605 _mesa_glsl_warning(& @1, state,
1606 "#version 140 / GL_ARB_uniform_buffer_object "
1607 "layout qualifier `%s' is used", $1);
1608 }
1609 }
1610 ;
1611
1612 /* This is a separate language rule because we parse these as tokens
1613 * (due to them being reserved keywords) instead of identifiers like
1614 * most qualifiers. See the any_identifier path of
1615 * layout_qualifier_id for the others.
1616 *
1617 * Note that since layout qualifiers are case-insensitive in desktop
1618 * GLSL, all of these qualifiers need to be handled as identifiers as
1619 * well (by the any_identifier path of layout_qualifier_id).
1620 */
1621 interface_block_layout_qualifier:
1622 ROW_MAJOR
1623 {
1624 memset(& $$, 0, sizeof($$));
1625 $$.flags.q.row_major = 1;
1626 }
1627 | PACKED_TOK
1628 {
1629 memset(& $$, 0, sizeof($$));
1630 $$.flags.q.packed = 1;
1631 }
1632 | SHARED
1633 {
1634 memset(& $$, 0, sizeof($$));
1635 $$.flags.q.shared = 1;
1636 }
1637 ;
1638
1639 subroutine_qualifier:
1640 SUBROUTINE
1641 {
1642 memset(& $$, 0, sizeof($$));
1643 $$.flags.q.subroutine = 1;
1644 }
1645 | SUBROUTINE '(' subroutine_type_list ')'
1646 {
1647 memset(& $$, 0, sizeof($$));
1648 $$.flags.q.subroutine_def = 1;
1649 $$.subroutine_list = $3;
1650 }
1651 ;
1652
1653 subroutine_type_list:
1654 any_identifier
1655 {
1656 void *ctx = state;
1657 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1658 decl->set_location(@1);
1659
1660 $$ = new(ctx) ast_subroutine_list();
1661 $$->declarations.push_tail(&decl->link);
1662 }
1663 | subroutine_type_list ',' any_identifier
1664 {
1665 void *ctx = state;
1666 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1667 decl->set_location(@3);
1668
1669 $$ = $1;
1670 $$->declarations.push_tail(&decl->link);
1671 }
1672 ;
1673
1674 interpolation_qualifier:
1675 SMOOTH
1676 {
1677 memset(& $$, 0, sizeof($$));
1678 $$.flags.q.smooth = 1;
1679 }
1680 | FLAT
1681 {
1682 memset(& $$, 0, sizeof($$));
1683 $$.flags.q.flat = 1;
1684 }
1685 | NOPERSPECTIVE
1686 {
1687 memset(& $$, 0, sizeof($$));
1688 $$.flags.q.noperspective = 1;
1689 }
1690 ;
1691
1692 type_qualifier:
1693 /* Single qualifiers */
1694 INVARIANT
1695 {
1696 memset(& $$, 0, sizeof($$));
1697 $$.flags.q.invariant = 1;
1698 }
1699 | PRECISE
1700 {
1701 memset(& $$, 0, sizeof($$));
1702 $$.flags.q.precise = 1;
1703 }
1704 | auxiliary_storage_qualifier
1705 | storage_qualifier
1706 | interpolation_qualifier
1707 | layout_qualifier
1708 | memory_qualifier
1709 | subroutine_qualifier
1710 | precision_qualifier
1711 {
1712 memset(&$$, 0, sizeof($$));
1713 $$.precision = $1;
1714 }
1715
1716 /* Multiple qualifiers:
1717 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1718 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1719 *
1720 * invariant interpolation auxiliary storage precision ...or...
1721 * layout storage precision
1722 *
1723 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1724 * side don't contain any that must appear on the left hand side.
1725 * For example, when processing a storage qualifier, we check that there are
1726 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1727 */
1728 | PRECISE type_qualifier
1729 {
1730 if ($2.flags.q.precise)
1731 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1732
1733 $$ = $2;
1734 $$.flags.q.precise = 1;
1735 }
1736 | INVARIANT type_qualifier
1737 {
1738 if ($2.flags.q.invariant)
1739 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1740
1741 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1742 _mesa_glsl_error(&@1, state,
1743 "\"invariant\" must come after \"precise\"");
1744
1745 $$ = $2;
1746 $$.flags.q.invariant = 1;
1747
1748 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1749 *
1750 * "Only variables output from a shader can be candidates for invariance.
1751 * This includes user-defined output variables and the built-in output
1752 * variables. As only outputs can be declared as invariant, an invariant
1753 * output from one shader stage will still match an input of a subsequent
1754 * stage without the input being declared as invariant."
1755 */
1756 if (state->es_shader && state->language_version >= 300 && $$.flags.q.in)
1757 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1758 }
1759 | interpolation_qualifier type_qualifier
1760 {
1761 /* Section 4.3 of the GLSL 1.40 specification states:
1762 * "...qualified with one of these interpolation qualifiers"
1763 *
1764 * GLSL 1.30 claims to allow "one or more", but insists that:
1765 * "These interpolation qualifiers may only precede the qualifiers in,
1766 * centroid in, out, or centroid out in a declaration."
1767 *
1768 * ...which means that e.g. smooth can't precede smooth, so there can be
1769 * only one after all, and the 1.40 text is a clarification, not a change.
1770 */
1771 if ($2.has_interpolation())
1772 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1773
1774 if (!state->has_420pack_or_es31() &&
1775 ($2.flags.q.precise || $2.flags.q.invariant)) {
1776 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1777 "after \"precise\" or \"invariant\"");
1778 }
1779
1780 $$ = $1;
1781 $$.merge_qualifier(&@1, state, $2, false);
1782 }
1783 | layout_qualifier type_qualifier
1784 {
1785 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1786 * appear no later than auxiliary storage qualifiers. There is no
1787 * particularly clear spec language mandating this, but in all examples
1788 * the layout qualifier precedes the storage qualifier.
1789 *
1790 * We allow combinations of layout with interpolation, invariant or
1791 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1792 * There is no clear spec guidance on this either.
1793 */
1794 if (!state->has_420pack_or_es31() && $2.has_layout())
1795 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1796
1797 $$ = $1;
1798 $$.merge_qualifier(&@1, state, $2, false);
1799 }
1800 | subroutine_qualifier type_qualifier
1801 {
1802 $$ = $1;
1803 $$.merge_qualifier(&@1, state, $2, false);
1804 }
1805 | auxiliary_storage_qualifier type_qualifier
1806 {
1807 if ($2.has_auxiliary_storage()) {
1808 _mesa_glsl_error(&@1, state,
1809 "duplicate auxiliary storage qualifier (centroid or sample)");
1810 }
1811
1812 if (!state->has_420pack_or_es31() &&
1813 ($2.flags.q.precise || $2.flags.q.invariant ||
1814 $2.has_interpolation() || $2.has_layout())) {
1815 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1816 "just before storage qualifiers");
1817 }
1818 $$ = $1;
1819 $$.merge_qualifier(&@1, state, $2, false);
1820 }
1821 | storage_qualifier type_qualifier
1822 {
1823 /* Section 4.3 of the GLSL 1.20 specification states:
1824 * "Variable declarations may have a storage qualifier specified..."
1825 * 1.30 clarifies this to "may have one storage qualifier".
1826 */
1827 if ($2.has_storage())
1828 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1829
1830 if (!state->has_420pack_or_es31() &&
1831 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1832 $2.has_layout() || $2.has_auxiliary_storage())) {
1833 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1834 "precise, invariant, interpolation, layout and auxiliary "
1835 "storage qualifiers");
1836 }
1837
1838 $$ = $1;
1839 $$.merge_qualifier(&@1, state, $2, false);
1840 }
1841 | precision_qualifier type_qualifier
1842 {
1843 if ($2.precision != ast_precision_none)
1844 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1845
1846 if (!(state->has_420pack_or_es31()) &&
1847 $2.flags.i != 0)
1848 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1849
1850 $$ = $2;
1851 $$.precision = $1;
1852 }
1853 | memory_qualifier type_qualifier
1854 {
1855 $$ = $1;
1856 $$.merge_qualifier(&@1, state, $2, false);
1857 }
1858 ;
1859
1860 auxiliary_storage_qualifier:
1861 CENTROID
1862 {
1863 memset(& $$, 0, sizeof($$));
1864 $$.flags.q.centroid = 1;
1865 }
1866 | SAMPLE
1867 {
1868 memset(& $$, 0, sizeof($$));
1869 $$.flags.q.sample = 1;
1870 }
1871 | PATCH
1872 {
1873 memset(& $$, 0, sizeof($$));
1874 $$.flags.q.patch = 1;
1875 }
1876
1877 storage_qualifier:
1878 CONST_TOK
1879 {
1880 memset(& $$, 0, sizeof($$));
1881 $$.flags.q.constant = 1;
1882 }
1883 | ATTRIBUTE
1884 {
1885 memset(& $$, 0, sizeof($$));
1886 $$.flags.q.attribute = 1;
1887 }
1888 | VARYING
1889 {
1890 memset(& $$, 0, sizeof($$));
1891 $$.flags.q.varying = 1;
1892 }
1893 | IN_TOK
1894 {
1895 memset(& $$, 0, sizeof($$));
1896 $$.flags.q.in = 1;
1897 }
1898 | OUT_TOK
1899 {
1900 memset(& $$, 0, sizeof($$));
1901 $$.flags.q.out = 1;
1902
1903 if (state->stage == MESA_SHADER_GEOMETRY &&
1904 state->has_explicit_attrib_stream()) {
1905 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
1906 * spec says:
1907 *
1908 * "If the block or variable is declared with the stream
1909 * identifier, it is associated with the specified stream;
1910 * otherwise, it is associated with the current default stream."
1911 */
1912 $$.flags.q.stream = 1;
1913 $$.flags.q.explicit_stream = 0;
1914 $$.stream = state->out_qualifier->stream;
1915 }
1916 }
1917 | UNIFORM
1918 {
1919 memset(& $$, 0, sizeof($$));
1920 $$.flags.q.uniform = 1;
1921 }
1922 | BUFFER
1923 {
1924 memset(& $$, 0, sizeof($$));
1925 $$.flags.q.buffer = 1;
1926 }
1927 | SHARED
1928 {
1929 memset(& $$, 0, sizeof($$));
1930 $$.flags.q.shared_storage = 1;
1931 }
1932 ;
1933
1934 memory_qualifier:
1935 COHERENT
1936 {
1937 memset(& $$, 0, sizeof($$));
1938 $$.flags.q.coherent = 1;
1939 }
1940 | VOLATILE
1941 {
1942 memset(& $$, 0, sizeof($$));
1943 $$.flags.q._volatile = 1;
1944 }
1945 | RESTRICT
1946 {
1947 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1948 memset(& $$, 0, sizeof($$));
1949 $$.flags.q.restrict_flag = 1;
1950 }
1951 | READONLY
1952 {
1953 memset(& $$, 0, sizeof($$));
1954 $$.flags.q.read_only = 1;
1955 }
1956 | WRITEONLY
1957 {
1958 memset(& $$, 0, sizeof($$));
1959 $$.flags.q.write_only = 1;
1960 }
1961 ;
1962
1963 array_specifier:
1964 '[' ']'
1965 {
1966 void *ctx = state;
1967 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
1968 ast_unsized_array_dim, NULL,
1969 NULL, NULL));
1970 $$->set_location_range(@1, @2);
1971 }
1972 | '[' constant_expression ']'
1973 {
1974 void *ctx = state;
1975 $$ = new(ctx) ast_array_specifier(@1, $2);
1976 $$->set_location_range(@1, @3);
1977 }
1978 | array_specifier '[' ']'
1979 {
1980 void *ctx = state;
1981 $$ = $1;
1982
1983 if (state->check_arrays_of_arrays_allowed(& @1)) {
1984 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
1985 NULL, NULL));
1986 }
1987 }
1988 | array_specifier '[' constant_expression ']'
1989 {
1990 $$ = $1;
1991
1992 if (state->check_arrays_of_arrays_allowed(& @1)) {
1993 $$->add_dimension($3);
1994 }
1995 }
1996 ;
1997
1998 type_specifier:
1999 type_specifier_nonarray
2000 | type_specifier_nonarray array_specifier
2001 {
2002 $$ = $1;
2003 $$->array_specifier = $2;
2004 }
2005 ;
2006
2007 type_specifier_nonarray:
2008 basic_type_specifier_nonarray
2009 {
2010 void *ctx = state;
2011 $$ = new(ctx) ast_type_specifier($1);
2012 $$->set_location(@1);
2013 }
2014 | struct_specifier
2015 {
2016 void *ctx = state;
2017 $$ = new(ctx) ast_type_specifier($1);
2018 $$->set_location(@1);
2019 }
2020 | TYPE_IDENTIFIER
2021 {
2022 void *ctx = state;
2023 $$ = new(ctx) ast_type_specifier($1);
2024 $$->set_location(@1);
2025 }
2026 ;
2027
2028 basic_type_specifier_nonarray:
2029 VOID_TOK { $$ = "void"; }
2030 | FLOAT_TOK { $$ = "float"; }
2031 | DOUBLE_TOK { $$ = "double"; }
2032 | INT_TOK { $$ = "int"; }
2033 | UINT_TOK { $$ = "uint"; }
2034 | BOOL_TOK { $$ = "bool"; }
2035 | VEC2 { $$ = "vec2"; }
2036 | VEC3 { $$ = "vec3"; }
2037 | VEC4 { $$ = "vec4"; }
2038 | BVEC2 { $$ = "bvec2"; }
2039 | BVEC3 { $$ = "bvec3"; }
2040 | BVEC4 { $$ = "bvec4"; }
2041 | IVEC2 { $$ = "ivec2"; }
2042 | IVEC3 { $$ = "ivec3"; }
2043 | IVEC4 { $$ = "ivec4"; }
2044 | UVEC2 { $$ = "uvec2"; }
2045 | UVEC3 { $$ = "uvec3"; }
2046 | UVEC4 { $$ = "uvec4"; }
2047 | DVEC2 { $$ = "dvec2"; }
2048 | DVEC3 { $$ = "dvec3"; }
2049 | DVEC4 { $$ = "dvec4"; }
2050 | MAT2X2 { $$ = "mat2"; }
2051 | MAT2X3 { $$ = "mat2x3"; }
2052 | MAT2X4 { $$ = "mat2x4"; }
2053 | MAT3X2 { $$ = "mat3x2"; }
2054 | MAT3X3 { $$ = "mat3"; }
2055 | MAT3X4 { $$ = "mat3x4"; }
2056 | MAT4X2 { $$ = "mat4x2"; }
2057 | MAT4X3 { $$ = "mat4x3"; }
2058 | MAT4X4 { $$ = "mat4"; }
2059 | DMAT2X2 { $$ = "dmat2"; }
2060 | DMAT2X3 { $$ = "dmat2x3"; }
2061 | DMAT2X4 { $$ = "dmat2x4"; }
2062 | DMAT3X2 { $$ = "dmat3x2"; }
2063 | DMAT3X3 { $$ = "dmat3"; }
2064 | DMAT3X4 { $$ = "dmat3x4"; }
2065 | DMAT4X2 { $$ = "dmat4x2"; }
2066 | DMAT4X3 { $$ = "dmat4x3"; }
2067 | DMAT4X4 { $$ = "dmat4"; }
2068 | SAMPLER1D { $$ = "sampler1D"; }
2069 | SAMPLER2D { $$ = "sampler2D"; }
2070 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
2071 | SAMPLER3D { $$ = "sampler3D"; }
2072 | SAMPLERCUBE { $$ = "samplerCube"; }
2073 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
2074 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
2075 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
2076 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
2077 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
2078 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
2079 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
2080 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
2081 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
2082 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
2083 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
2084 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
2085 | ISAMPLER1D { $$ = "isampler1D"; }
2086 | ISAMPLER2D { $$ = "isampler2D"; }
2087 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
2088 | ISAMPLER3D { $$ = "isampler3D"; }
2089 | ISAMPLERCUBE { $$ = "isamplerCube"; }
2090 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
2091 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
2092 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
2093 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
2094 | USAMPLER1D { $$ = "usampler1D"; }
2095 | USAMPLER2D { $$ = "usampler2D"; }
2096 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
2097 | USAMPLER3D { $$ = "usampler3D"; }
2098 | USAMPLERCUBE { $$ = "usamplerCube"; }
2099 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
2100 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
2101 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
2102 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
2103 | SAMPLER2DMS { $$ = "sampler2DMS"; }
2104 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
2105 | USAMPLER2DMS { $$ = "usampler2DMS"; }
2106 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
2107 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
2108 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
2109 | IMAGE1D { $$ = "image1D"; }
2110 | IMAGE2D { $$ = "image2D"; }
2111 | IMAGE3D { $$ = "image3D"; }
2112 | IMAGE2DRECT { $$ = "image2DRect"; }
2113 | IMAGECUBE { $$ = "imageCube"; }
2114 | IMAGEBUFFER { $$ = "imageBuffer"; }
2115 | IMAGE1DARRAY { $$ = "image1DArray"; }
2116 | IMAGE2DARRAY { $$ = "image2DArray"; }
2117 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
2118 | IMAGE2DMS { $$ = "image2DMS"; }
2119 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
2120 | IIMAGE1D { $$ = "iimage1D"; }
2121 | IIMAGE2D { $$ = "iimage2D"; }
2122 | IIMAGE3D { $$ = "iimage3D"; }
2123 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
2124 | IIMAGECUBE { $$ = "iimageCube"; }
2125 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
2126 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
2127 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
2128 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
2129 | IIMAGE2DMS { $$ = "iimage2DMS"; }
2130 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
2131 | UIMAGE1D { $$ = "uimage1D"; }
2132 | UIMAGE2D { $$ = "uimage2D"; }
2133 | UIMAGE3D { $$ = "uimage3D"; }
2134 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
2135 | UIMAGECUBE { $$ = "uimageCube"; }
2136 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
2137 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
2138 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
2139 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
2140 | UIMAGE2DMS { $$ = "uimage2DMS"; }
2141 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
2142 | ATOMIC_UINT { $$ = "atomic_uint"; }
2143 ;
2144
2145 precision_qualifier:
2146 HIGHP
2147 {
2148 state->check_precision_qualifiers_allowed(&@1);
2149 $$ = ast_precision_high;
2150 }
2151 | MEDIUMP
2152 {
2153 state->check_precision_qualifiers_allowed(&@1);
2154 $$ = ast_precision_medium;
2155 }
2156 | LOWP
2157 {
2158 state->check_precision_qualifiers_allowed(&@1);
2159 $$ = ast_precision_low;
2160 }
2161 ;
2162
2163 struct_specifier:
2164 STRUCT any_identifier '{' struct_declaration_list '}'
2165 {
2166 void *ctx = state;
2167 $$ = new(ctx) ast_struct_specifier($2, $4);
2168 $$->set_location_range(@2, @5);
2169 state->symbols->add_type($2, glsl_type::void_type);
2170 }
2171 | STRUCT '{' struct_declaration_list '}'
2172 {
2173 void *ctx = state;
2174 $$ = new(ctx) ast_struct_specifier(NULL, $3);
2175 $$->set_location_range(@2, @4);
2176 }
2177 ;
2178
2179 struct_declaration_list:
2180 struct_declaration
2181 {
2182 $$ = $1;
2183 $1->link.self_link();
2184 }
2185 | struct_declaration_list struct_declaration
2186 {
2187 $$ = $1;
2188 $$->link.insert_before(& $2->link);
2189 }
2190 ;
2191
2192 struct_declaration:
2193 fully_specified_type struct_declarator_list ';'
2194 {
2195 void *ctx = state;
2196 ast_fully_specified_type *const type = $1;
2197 type->set_location(@1);
2198
2199 if (type->qualifier.flags.i != 0)
2200 _mesa_glsl_error(&@1, state,
2201 "only precision qualifiers may be applied to "
2202 "structure members");
2203
2204 $$ = new(ctx) ast_declarator_list(type);
2205 $$->set_location(@2);
2206
2207 $$->declarations.push_degenerate_list_at_head(& $2->link);
2208 }
2209 ;
2210
2211 struct_declarator_list:
2212 struct_declarator
2213 {
2214 $$ = $1;
2215 $1->link.self_link();
2216 }
2217 | struct_declarator_list ',' struct_declarator
2218 {
2219 $$ = $1;
2220 $$->link.insert_before(& $3->link);
2221 }
2222 ;
2223
2224 struct_declarator:
2225 any_identifier
2226 {
2227 void *ctx = state;
2228 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2229 $$->set_location(@1);
2230 }
2231 | any_identifier array_specifier
2232 {
2233 void *ctx = state;
2234 $$ = new(ctx) ast_declaration($1, $2, NULL);
2235 $$->set_location_range(@1, @2);
2236 }
2237 ;
2238
2239 initializer:
2240 assignment_expression
2241 | '{' initializer_list '}'
2242 {
2243 $$ = $2;
2244 }
2245 | '{' initializer_list ',' '}'
2246 {
2247 $$ = $2;
2248 }
2249 ;
2250
2251 initializer_list:
2252 initializer
2253 {
2254 void *ctx = state;
2255 $$ = new(ctx) ast_aggregate_initializer();
2256 $$->set_location(@1);
2257 $$->expressions.push_tail(& $1->link);
2258 }
2259 | initializer_list ',' initializer
2260 {
2261 $1->expressions.push_tail(& $3->link);
2262 }
2263 ;
2264
2265 declaration_statement:
2266 declaration
2267 ;
2268
2269 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2270 // supported.
2271 statement:
2272 compound_statement { $$ = (ast_node *) $1; }
2273 | simple_statement
2274 ;
2275
2276 simple_statement:
2277 declaration_statement
2278 | expression_statement
2279 | selection_statement
2280 | switch_statement
2281 | iteration_statement
2282 | jump_statement
2283 ;
2284
2285 compound_statement:
2286 '{' '}'
2287 {
2288 void *ctx = state;
2289 $$ = new(ctx) ast_compound_statement(true, NULL);
2290 $$->set_location_range(@1, @2);
2291 }
2292 | '{'
2293 {
2294 state->symbols->push_scope();
2295 }
2296 statement_list '}'
2297 {
2298 void *ctx = state;
2299 $$ = new(ctx) ast_compound_statement(true, $3);
2300 $$->set_location_range(@1, @4);
2301 state->symbols->pop_scope();
2302 }
2303 ;
2304
2305 statement_no_new_scope:
2306 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2307 | simple_statement
2308 ;
2309
2310 compound_statement_no_new_scope:
2311 '{' '}'
2312 {
2313 void *ctx = state;
2314 $$ = new(ctx) ast_compound_statement(false, NULL);
2315 $$->set_location_range(@1, @2);
2316 }
2317 | '{' statement_list '}'
2318 {
2319 void *ctx = state;
2320 $$ = new(ctx) ast_compound_statement(false, $2);
2321 $$->set_location_range(@1, @3);
2322 }
2323 ;
2324
2325 statement_list:
2326 statement
2327 {
2328 if ($1 == NULL) {
2329 _mesa_glsl_error(& @1, state, "<nil> statement");
2330 assert($1 != NULL);
2331 }
2332
2333 $$ = $1;
2334 $$->link.self_link();
2335 }
2336 | statement_list statement
2337 {
2338 if ($2 == NULL) {
2339 _mesa_glsl_error(& @2, state, "<nil> statement");
2340 assert($2 != NULL);
2341 }
2342 $$ = $1;
2343 $$->link.insert_before(& $2->link);
2344 }
2345 ;
2346
2347 expression_statement:
2348 ';'
2349 {
2350 void *ctx = state;
2351 $$ = new(ctx) ast_expression_statement(NULL);
2352 $$->set_location(@1);
2353 }
2354 | expression ';'
2355 {
2356 void *ctx = state;
2357 $$ = new(ctx) ast_expression_statement($1);
2358 $$->set_location(@1);
2359 }
2360 ;
2361
2362 selection_statement:
2363 IF '(' expression ')' selection_rest_statement
2364 {
2365 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2366 $5.else_statement);
2367 $$->set_location_range(@1, @5);
2368 }
2369 ;
2370
2371 selection_rest_statement:
2372 statement ELSE statement
2373 {
2374 $$.then_statement = $1;
2375 $$.else_statement = $3;
2376 }
2377 | statement %prec THEN
2378 {
2379 $$.then_statement = $1;
2380 $$.else_statement = NULL;
2381 }
2382 ;
2383
2384 condition:
2385 expression
2386 {
2387 $$ = (ast_node *) $1;
2388 }
2389 | fully_specified_type any_identifier '=' initializer
2390 {
2391 void *ctx = state;
2392 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2393 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2394 decl->set_location_range(@2, @4);
2395 declarator->set_location(@1);
2396
2397 declarator->declarations.push_tail(&decl->link);
2398 $$ = declarator;
2399 }
2400 ;
2401
2402 /*
2403 * switch_statement grammar is based on the syntax described in the body
2404 * of the GLSL spec, not in it's appendix!!!
2405 */
2406 switch_statement:
2407 SWITCH '(' expression ')' switch_body
2408 {
2409 $$ = new(state) ast_switch_statement($3, $5);
2410 $$->set_location_range(@1, @5);
2411 }
2412 ;
2413
2414 switch_body:
2415 '{' '}'
2416 {
2417 $$ = new(state) ast_switch_body(NULL);
2418 $$->set_location_range(@1, @2);
2419 }
2420 | '{' case_statement_list '}'
2421 {
2422 $$ = new(state) ast_switch_body($2);
2423 $$->set_location_range(@1, @3);
2424 }
2425 ;
2426
2427 case_label:
2428 CASE expression ':'
2429 {
2430 $$ = new(state) ast_case_label($2);
2431 $$->set_location(@2);
2432 }
2433 | DEFAULT ':'
2434 {
2435 $$ = new(state) ast_case_label(NULL);
2436 $$->set_location(@2);
2437 }
2438 ;
2439
2440 case_label_list:
2441 case_label
2442 {
2443 ast_case_label_list *labels = new(state) ast_case_label_list();
2444
2445 labels->labels.push_tail(& $1->link);
2446 $$ = labels;
2447 $$->set_location(@1);
2448 }
2449 | case_label_list case_label
2450 {
2451 $$ = $1;
2452 $$->labels.push_tail(& $2->link);
2453 }
2454 ;
2455
2456 case_statement:
2457 case_label_list statement
2458 {
2459 ast_case_statement *stmts = new(state) ast_case_statement($1);
2460 stmts->set_location(@2);
2461
2462 stmts->stmts.push_tail(& $2->link);
2463 $$ = stmts;
2464 }
2465 | case_statement statement
2466 {
2467 $$ = $1;
2468 $$->stmts.push_tail(& $2->link);
2469 }
2470 ;
2471
2472 case_statement_list:
2473 case_statement
2474 {
2475 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2476 cases->set_location(@1);
2477
2478 cases->cases.push_tail(& $1->link);
2479 $$ = cases;
2480 }
2481 | case_statement_list case_statement
2482 {
2483 $$ = $1;
2484 $$->cases.push_tail(& $2->link);
2485 }
2486 ;
2487
2488 iteration_statement:
2489 WHILE '(' condition ')' statement_no_new_scope
2490 {
2491 void *ctx = state;
2492 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2493 NULL, $3, NULL, $5);
2494 $$->set_location_range(@1, @4);
2495 }
2496 | DO statement WHILE '(' expression ')' ';'
2497 {
2498 void *ctx = state;
2499 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2500 NULL, $5, NULL, $2);
2501 $$->set_location_range(@1, @6);
2502 }
2503 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2504 {
2505 void *ctx = state;
2506 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2507 $3, $4.cond, $4.rest, $6);
2508 $$->set_location_range(@1, @6);
2509 }
2510 ;
2511
2512 for_init_statement:
2513 expression_statement
2514 | declaration_statement
2515 ;
2516
2517 conditionopt:
2518 condition
2519 | /* empty */
2520 {
2521 $$ = NULL;
2522 }
2523 ;
2524
2525 for_rest_statement:
2526 conditionopt ';'
2527 {
2528 $$.cond = $1;
2529 $$.rest = NULL;
2530 }
2531 | conditionopt ';' expression
2532 {
2533 $$.cond = $1;
2534 $$.rest = $3;
2535 }
2536 ;
2537
2538 // Grammar Note: No 'goto'. Gotos are not supported.
2539 jump_statement:
2540 CONTINUE ';'
2541 {
2542 void *ctx = state;
2543 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2544 $$->set_location(@1);
2545 }
2546 | BREAK ';'
2547 {
2548 void *ctx = state;
2549 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2550 $$->set_location(@1);
2551 }
2552 | RETURN ';'
2553 {
2554 void *ctx = state;
2555 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2556 $$->set_location(@1);
2557 }
2558 | RETURN expression ';'
2559 {
2560 void *ctx = state;
2561 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2562 $$->set_location_range(@1, @2);
2563 }
2564 | DISCARD ';' // Fragment shader only.
2565 {
2566 void *ctx = state;
2567 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2568 $$->set_location(@1);
2569 }
2570 ;
2571
2572 external_declaration:
2573 function_definition { $$ = $1; }
2574 | declaration { $$ = $1; }
2575 | pragma_statement { $$ = NULL; }
2576 | layout_defaults { $$ = $1; }
2577 ;
2578
2579 function_definition:
2580 function_prototype compound_statement_no_new_scope
2581 {
2582 void *ctx = state;
2583 $$ = new(ctx) ast_function_definition();
2584 $$->set_location_range(@1, @2);
2585 $$->prototype = $1;
2586 $$->body = $2;
2587
2588 state->symbols->pop_scope();
2589 }
2590 ;
2591
2592 /* layout_qualifieropt is packed into this rule */
2593 interface_block:
2594 basic_interface_block
2595 {
2596 $$ = $1;
2597 }
2598 | layout_qualifier interface_block
2599 {
2600 ast_interface_block *block = (ast_interface_block *) $2;
2601
2602 if (!state->has_420pack_or_es31() && block->layout.has_layout() &&
2603 !block->layout.is_default_qualifier) {
2604 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2605 YYERROR;
2606 }
2607
2608 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2609 YYERROR;
2610 }
2611
2612 block->layout.is_default_qualifier = false;
2613
2614 $$ = block;
2615 }
2616 | memory_qualifier interface_block
2617 {
2618 ast_interface_block *block = (ast_interface_block *)$2;
2619
2620 if (!block->layout.flags.q.buffer) {
2621 _mesa_glsl_error(& @1, state,
2622 "memory qualifiers can only be used in the "
2623 "declaration of shader storage blocks");
2624 }
2625 if (!block->layout.merge_qualifier(& @1, state, $1, false)) {
2626 YYERROR;
2627 }
2628 $$ = block;
2629 }
2630 ;
2631
2632 basic_interface_block:
2633 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2634 {
2635 ast_interface_block *const block = $6;
2636
2637 block->block_name = $2;
2638 block->declarations.push_degenerate_list_at_head(& $4->link);
2639
2640 _mesa_ast_process_interface_block(& @1, state, block, $1);
2641
2642 $$ = block;
2643 }
2644 | uniform_interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2645 {
2646 ast_interface_block *const block = $6;
2647
2648 block->layout = *state->default_uniform_qualifier;
2649 block->block_name = $2;
2650 block->declarations.push_degenerate_list_at_head(& $4->link);
2651
2652 _mesa_ast_process_interface_block(& @1, state, block, $1);
2653
2654 $$ = block;
2655 }
2656 | buffer_interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2657 {
2658 ast_interface_block *const block = $6;
2659
2660 block->layout = *state->default_shader_storage_qualifier;
2661 block->block_name = $2;
2662 block->declarations.push_degenerate_list_at_head(& $4->link);
2663
2664 _mesa_ast_process_interface_block(& @1, state, block, $1);
2665
2666 $$ = block;
2667 }
2668 ;
2669
2670 interface_qualifier:
2671 IN_TOK
2672 {
2673 memset(& $$, 0, sizeof($$));
2674 $$.flags.q.in = 1;
2675 }
2676 | OUT_TOK
2677 {
2678 memset(& $$, 0, sizeof($$));
2679 $$.flags.q.out = 1;
2680 }
2681 ;
2682
2683 uniform_interface_qualifier:
2684 UNIFORM
2685 {
2686 memset(& $$, 0, sizeof($$));
2687 $$.flags.q.uniform = 1;
2688 }
2689 ;
2690
2691 buffer_interface_qualifier:
2692 BUFFER
2693 {
2694 memset(& $$, 0, sizeof($$));
2695 $$.flags.q.buffer = 1;
2696 }
2697 ;
2698
2699 instance_name_opt:
2700 /* empty */
2701 {
2702 $$ = new(state) ast_interface_block(NULL, NULL);
2703 }
2704 | NEW_IDENTIFIER
2705 {
2706 $$ = new(state) ast_interface_block($1, NULL);
2707 $$->set_location(@1);
2708 }
2709 | NEW_IDENTIFIER array_specifier
2710 {
2711 $$ = new(state) ast_interface_block($1, $2);
2712 $$->set_location_range(@1, @2);
2713 }
2714 ;
2715
2716 member_list:
2717 member_declaration
2718 {
2719 $$ = $1;
2720 $1->link.self_link();
2721 }
2722 | member_declaration member_list
2723 {
2724 $$ = $1;
2725 $2->link.insert_before(& $$->link);
2726 }
2727 ;
2728
2729 member_declaration:
2730 fully_specified_type struct_declarator_list ';'
2731 {
2732 void *ctx = state;
2733 ast_fully_specified_type *type = $1;
2734 type->set_location(@1);
2735
2736 if (type->qualifier.flags.q.attribute) {
2737 _mesa_glsl_error(& @1, state,
2738 "keyword 'attribute' cannot be used with "
2739 "interface block member");
2740 } else if (type->qualifier.flags.q.varying) {
2741 _mesa_glsl_error(& @1, state,
2742 "keyword 'varying' cannot be used with "
2743 "interface block member");
2744 }
2745
2746 $$ = new(ctx) ast_declarator_list(type);
2747 $$->set_location(@2);
2748
2749 $$->declarations.push_degenerate_list_at_head(& $2->link);
2750 }
2751 ;
2752
2753 layout_uniform_defaults:
2754 layout_qualifier layout_uniform_defaults
2755 {
2756 $$ = NULL;
2757 if (!state->has_420pack_or_es31()) {
2758 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2759 YYERROR;
2760 } else {
2761 if (!state->default_uniform_qualifier->
2762 merge_qualifier(& @1, state, $1, false)) {
2763 YYERROR;
2764 }
2765 }
2766 }
2767 | layout_qualifier UNIFORM ';'
2768 {
2769 if (!state->default_uniform_qualifier->
2770 merge_qualifier(& @1, state, $1, false)) {
2771 YYERROR;
2772 }
2773 $$ = NULL;
2774 }
2775 ;
2776
2777 layout_buffer_defaults:
2778 layout_qualifier layout_buffer_defaults
2779 {
2780 $$ = NULL;
2781 if (!state->has_420pack_or_es31()) {
2782 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2783 YYERROR;
2784 } else {
2785 if (!state->default_shader_storage_qualifier->
2786 merge_qualifier(& @1, state, $1, false)) {
2787 YYERROR;
2788 }
2789 }
2790 }
2791 | layout_qualifier BUFFER ';'
2792 {
2793 if (!state->default_shader_storage_qualifier->
2794 merge_qualifier(& @1, state, $1, false)) {
2795 YYERROR;
2796 }
2797
2798 /* From the GLSL 4.50 spec, section 4.4.5:
2799 *
2800 * "It is a compile-time error to specify the binding identifier for
2801 * the global scope or for block member declarations."
2802 */
2803 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2804 _mesa_glsl_error(& @1, state,
2805 "binding qualifier cannot be set for default layout");
2806 }
2807
2808 $$ = NULL;
2809 }
2810 ;
2811
2812 layout_in_defaults:
2813 layout_qualifier layout_in_defaults
2814 {
2815 $$ = NULL;
2816 if (!state->has_420pack_or_es31()) {
2817 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2818 YYERROR;
2819 } else {
2820 if (!state->in_qualifier->
2821 merge_in_qualifier(& @1, state, $1, $$, false)) {
2822 YYERROR;
2823 }
2824 }
2825 }
2826 | layout_qualifier IN_TOK ';'
2827 {
2828 $$ = NULL;
2829 if (!state->in_qualifier->
2830 merge_in_qualifier(& @1, state, $1, $$, true)) {
2831 YYERROR;
2832 }
2833 }
2834 ;
2835
2836 layout_out_defaults:
2837 layout_qualifier layout_out_defaults
2838 {
2839 $$ = NULL;
2840 if (!state->has_420pack_or_es31()) {
2841 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
2842 YYERROR;
2843 } else {
2844 if (!state->out_qualifier->
2845 merge_out_qualifier(& @1, state, $1, $$, false)) {
2846 YYERROR;
2847 }
2848 }
2849 }
2850 | layout_qualifier OUT_TOK ';'
2851 {
2852 $$ = NULL;
2853 if (!state->out_qualifier->
2854 merge_out_qualifier(& @1, state, $1, $$, true))
2855 YYERROR;
2856 }
2857 ;
2858
2859 layout_defaults:
2860 layout_uniform_defaults
2861 | layout_buffer_defaults
2862 | layout_in_defaults
2863 | layout_out_defaults
2864 ;