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