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