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