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