glsl: Silence the last shift/reduce conflict warning in the grammar.
[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 #include <assert.h>
28
29 #include "ast.h"
30 #include "glsl_parser_extras.h"
31 #include "glsl_types.h"
32 #include "main/context.h"
33
34 #define YYLEX_PARAM state->scanner
35
36 #undef yyerror
37
38 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
39 {
40 _mesa_glsl_error(loc, st, "%s", msg);
41 }
42 %}
43
44 %pure-parser
45 %error-verbose
46
47 %locations
48 %initial-action {
49 @$.first_line = 1;
50 @$.first_column = 1;
51 @$.last_line = 1;
52 @$.last_column = 1;
53 @$.source = 0;
54 }
55
56 %lex-param {void *scanner}
57 %parse-param {struct _mesa_glsl_parse_state *state}
58
59 %union {
60 int n;
61 float real;
62 const char *identifier;
63
64 struct ast_type_qualifier type_qualifier;
65
66 ast_node *node;
67 ast_type_specifier *type_specifier;
68 ast_fully_specified_type *fully_specified_type;
69 ast_function *function;
70 ast_parameter_declarator *parameter_declarator;
71 ast_function_definition *function_definition;
72 ast_compound_statement *compound_statement;
73 ast_expression *expression;
74 ast_declarator_list *declarator_list;
75 ast_struct_specifier *struct_specifier;
76 ast_declaration *declaration;
77 ast_switch_body *switch_body;
78 ast_case_label *case_label;
79 ast_case_label_list *case_label_list;
80 ast_case_statement *case_statement;
81 ast_case_statement_list *case_statement_list;
82 ast_interface_block *interface_block;
83
84 struct {
85 ast_node *cond;
86 ast_expression *rest;
87 } for_rest_statement;
88
89 struct {
90 ast_node *then_statement;
91 ast_node *else_statement;
92 } selection_rest_statement;
93 }
94
95 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
96 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
97 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
98 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
99 %token NOPERSPECTIVE FLAT SMOOTH
100 %token MAT2X2 MAT2X3 MAT2X4
101 %token MAT3X2 MAT3X3 MAT3X4
102 %token MAT4X2 MAT4X3 MAT4X4
103 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
104 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
105 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
106 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
107 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
108 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
109 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
110 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
111 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
112 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
113 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
114 %token SAMPLEREXTERNALOES
115 %token STRUCT VOID_TOK WHILE
116 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
117 %type <identifier> any_identifier
118 %type <interface_block> instance_name_opt
119 %token <real> FLOATCONSTANT
120 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
121 %token <identifier> FIELD_SELECTION
122 %token LEFT_OP RIGHT_OP
123 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
124 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
125 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
126 %token SUB_ASSIGN
127 %token INVARIANT
128 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
129
130 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
131 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
132 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
133 %token PRAGMA_INVARIANT_ALL
134 %token LAYOUT_TOK
135
136 /* Reserved words that are not actually used in the grammar.
137 */
138 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
139 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
140 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
141 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
142 %token SAMPLER3DRECT
143 %token SIZEOF CAST NAMESPACE USING
144 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
145 %token SUBROUTINE
146
147 %token ERROR_TOK
148
149 %token COMMON PARTITION ACTIVE FILTER
150 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
151 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
152 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
153 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
154 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
155 %token ROW_MAJOR
156
157 %type <identifier> variable_identifier
158 %type <node> statement
159 %type <node> statement_list
160 %type <node> simple_statement
161 %type <n> precision_qualifier
162 %type <type_qualifier> type_qualifier
163 %type <type_qualifier> storage_qualifier
164 %type <type_qualifier> interpolation_qualifier
165 %type <type_qualifier> layout_qualifier
166 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
167 %type <type_qualifier> interface_block_layout_qualifier
168 %type <type_qualifier> interface_qualifier
169 %type <type_specifier> type_specifier
170 %type <type_specifier> type_specifier_no_prec
171 %type <type_specifier> type_specifier_nonarray
172 %type <identifier> basic_type_specifier_nonarray
173 %type <fully_specified_type> fully_specified_type
174 %type <function> function_prototype
175 %type <function> function_header
176 %type <function> function_header_with_parameters
177 %type <function> function_declarator
178 %type <parameter_declarator> parameter_declarator
179 %type <parameter_declarator> parameter_declaration
180 %type <type_qualifier> parameter_qualifier
181 %type <type_qualifier> parameter_type_qualifier
182 %type <type_specifier> parameter_type_specifier
183 %type <function_definition> function_definition
184 %type <compound_statement> compound_statement_no_new_scope
185 %type <compound_statement> compound_statement
186 %type <node> statement_no_new_scope
187 %type <node> expression_statement
188 %type <expression> expression
189 %type <expression> primary_expression
190 %type <expression> assignment_expression
191 %type <expression> conditional_expression
192 %type <expression> logical_or_expression
193 %type <expression> logical_xor_expression
194 %type <expression> logical_and_expression
195 %type <expression> inclusive_or_expression
196 %type <expression> exclusive_or_expression
197 %type <expression> and_expression
198 %type <expression> equality_expression
199 %type <expression> relational_expression
200 %type <expression> shift_expression
201 %type <expression> additive_expression
202 %type <expression> multiplicative_expression
203 %type <expression> unary_expression
204 %type <expression> constant_expression
205 %type <expression> integer_expression
206 %type <expression> postfix_expression
207 %type <expression> function_call_header_with_parameters
208 %type <expression> function_call_header_no_parameters
209 %type <expression> function_call_header
210 %type <expression> function_call_generic
211 %type <expression> function_call_or_method
212 %type <expression> function_call
213 %type <expression> method_call_generic
214 %type <expression> method_call_header_with_parameters
215 %type <expression> method_call_header_no_parameters
216 %type <expression> method_call_header
217 %type <n> assignment_operator
218 %type <n> unary_operator
219 %type <expression> function_identifier
220 %type <node> external_declaration
221 %type <declarator_list> init_declarator_list
222 %type <declarator_list> single_declaration
223 %type <expression> initializer
224 %type <expression> initializer_list
225 %type <node> declaration
226 %type <node> declaration_statement
227 %type <node> jump_statement
228 %type <node> interface_block
229 %type <interface_block> basic_interface_block
230 %type <struct_specifier> struct_specifier
231 %type <declarator_list> struct_declaration_list
232 %type <declarator_list> struct_declaration
233 %type <declaration> struct_declarator
234 %type <declaration> struct_declarator_list
235 %type <declarator_list> member_list
236 %type <declarator_list> member_declaration
237 %type <node> selection_statement
238 %type <selection_rest_statement> selection_rest_statement
239 %type <node> switch_statement
240 %type <switch_body> switch_body
241 %type <case_label_list> case_label_list
242 %type <case_label> case_label
243 %type <case_statement> case_statement
244 %type <case_statement_list> case_statement_list
245 %type <node> iteration_statement
246 %type <node> condition
247 %type <node> conditionopt
248 %type <node> for_init_statement
249 %type <for_rest_statement> for_rest_statement
250 %type <n> integer_constant
251
252 %right THEN ELSE
253 %%
254
255 translation_unit:
256 version_statement extension_statement_list
257 {
258 _mesa_glsl_initialize_types(state);
259 }
260 external_declaration_list
261 {
262 delete state->symbols;
263 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
264 _mesa_glsl_initialize_types(state);
265 }
266 ;
267
268 version_statement:
269 /* blank - no #version specified: defaults are already set */
270 | VERSION_TOK INTCONSTANT EOL
271 {
272 state->process_version_directive(&@2, $2, NULL);
273 if (state->error) {
274 YYERROR;
275 }
276 }
277 | VERSION_TOK INTCONSTANT any_identifier EOL
278 {
279 state->process_version_directive(&@2, $2, $3);
280 if (state->error) {
281 YYERROR;
282 }
283 }
284 ;
285
286 pragma_statement:
287 PRAGMA_DEBUG_ON EOL
288 | PRAGMA_DEBUG_OFF EOL
289 | PRAGMA_OPTIMIZE_ON EOL
290 | PRAGMA_OPTIMIZE_OFF EOL
291 | PRAGMA_INVARIANT_ALL EOL
292 {
293 if (!state->is_version(120, 100)) {
294 _mesa_glsl_warning(& @1, state,
295 "pragma `invariant(all)' not supported in %s "
296 "(GLSL ES 1.00 or GLSL 1.20 required).",
297 state->get_version_string());
298 } else {
299 state->all_invariant = true;
300 }
301 }
302 ;
303
304 extension_statement_list:
305
306 | extension_statement_list extension_statement
307 ;
308
309 any_identifier:
310 IDENTIFIER
311 | TYPE_IDENTIFIER
312 | NEW_IDENTIFIER
313 ;
314
315 extension_statement:
316 EXTENSION any_identifier COLON any_identifier EOL
317 {
318 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
319 YYERROR;
320 }
321 }
322 ;
323
324 external_declaration_list:
325 external_declaration
326 {
327 /* FINISHME: The NULL test is required because pragmas are set to
328 * FINISHME: NULL. (See production rule for external_declaration.)
329 */
330 if ($1 != NULL)
331 state->translation_unit.push_tail(& $1->link);
332 }
333 | external_declaration_list external_declaration
334 {
335 /* FINISHME: The NULL test is required because pragmas are set to
336 * FINISHME: NULL. (See production rule for external_declaration.)
337 */
338 if ($2 != NULL)
339 state->translation_unit.push_tail(& $2->link);
340 }
341 ;
342
343 variable_identifier:
344 IDENTIFIER
345 | NEW_IDENTIFIER
346 ;
347
348 primary_expression:
349 variable_identifier
350 {
351 void *ctx = state;
352 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
353 $$->set_location(yylloc);
354 $$->primary_expression.identifier = $1;
355 }
356 | INTCONSTANT
357 {
358 void *ctx = state;
359 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
360 $$->set_location(yylloc);
361 $$->primary_expression.int_constant = $1;
362 }
363 | UINTCONSTANT
364 {
365 void *ctx = state;
366 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
367 $$->set_location(yylloc);
368 $$->primary_expression.uint_constant = $1;
369 }
370 | FLOATCONSTANT
371 {
372 void *ctx = state;
373 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
374 $$->set_location(yylloc);
375 $$->primary_expression.float_constant = $1;
376 }
377 | BOOLCONSTANT
378 {
379 void *ctx = state;
380 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
381 $$->set_location(yylloc);
382 $$->primary_expression.bool_constant = $1;
383 }
384 | '(' expression ')'
385 {
386 $$ = $2;
387 }
388 ;
389
390 postfix_expression:
391 primary_expression
392 | postfix_expression '[' integer_expression ']'
393 {
394 void *ctx = state;
395 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
396 $$->set_location(yylloc);
397 }
398 | function_call
399 {
400 $$ = $1;
401 }
402 | postfix_expression '.' any_identifier
403 {
404 void *ctx = state;
405 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
406 $$->set_location(yylloc);
407 $$->primary_expression.identifier = $3;
408 }
409 | postfix_expression INC_OP
410 {
411 void *ctx = state;
412 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
413 $$->set_location(yylloc);
414 }
415 | postfix_expression DEC_OP
416 {
417 void *ctx = state;
418 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
419 $$->set_location(yylloc);
420 }
421 ;
422
423 integer_expression:
424 expression
425 ;
426
427 function_call:
428 function_call_or_method
429 ;
430
431 function_call_or_method:
432 function_call_generic
433 | postfix_expression '.' method_call_generic
434 {
435 void *ctx = state;
436 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
437 $$->set_location(yylloc);
438 }
439 ;
440
441 function_call_generic:
442 function_call_header_with_parameters ')'
443 | function_call_header_no_parameters ')'
444 ;
445
446 function_call_header_no_parameters:
447 function_call_header VOID_TOK
448 | function_call_header
449 ;
450
451 function_call_header_with_parameters:
452 function_call_header assignment_expression
453 {
454 $$ = $1;
455 $$->set_location(yylloc);
456 $$->expressions.push_tail(& $2->link);
457 }
458 | function_call_header_with_parameters ',' assignment_expression
459 {
460 $$ = $1;
461 $$->set_location(yylloc);
462 $$->expressions.push_tail(& $3->link);
463 }
464 ;
465
466 // Grammar Note: Constructors look like functions, but lexical
467 // analysis recognized most of them as keywords. They are now
468 // recognized through "type_specifier".
469 function_call_header:
470 function_identifier '('
471 ;
472
473 function_identifier:
474 type_specifier
475 {
476 void *ctx = state;
477 $$ = new(ctx) ast_function_expression($1);
478 $$->set_location(yylloc);
479 }
480 | variable_identifier
481 {
482 void *ctx = state;
483 ast_expression *callee = new(ctx) ast_expression($1);
484 $$ = new(ctx) ast_function_expression(callee);
485 $$->set_location(yylloc);
486 }
487 | FIELD_SELECTION
488 {
489 void *ctx = state;
490 ast_expression *callee = new(ctx) ast_expression($1);
491 $$ = new(ctx) ast_function_expression(callee);
492 $$->set_location(yylloc);
493 }
494 ;
495
496 method_call_generic:
497 method_call_header_with_parameters ')'
498 | method_call_header_no_parameters ')'
499 ;
500
501 method_call_header_no_parameters:
502 method_call_header VOID_TOK
503 | method_call_header
504 ;
505
506 method_call_header_with_parameters:
507 method_call_header assignment_expression
508 {
509 $$ = $1;
510 $$->set_location(yylloc);
511 $$->expressions.push_tail(& $2->link);
512 }
513 | method_call_header_with_parameters ',' assignment_expression
514 {
515 $$ = $1;
516 $$->set_location(yylloc);
517 $$->expressions.push_tail(& $3->link);
518 }
519 ;
520
521 // Grammar Note: Constructors look like methods, but lexical
522 // analysis recognized most of them as keywords. They are now
523 // recognized through "type_specifier".
524 method_call_header:
525 variable_identifier '('
526 {
527 void *ctx = state;
528 ast_expression *callee = new(ctx) ast_expression($1);
529 $$ = new(ctx) ast_function_expression(callee);
530 $$->set_location(yylloc);
531 }
532 ;
533
534 // Grammar Note: No traditional style type casts.
535 unary_expression:
536 postfix_expression
537 | INC_OP unary_expression
538 {
539 void *ctx = state;
540 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
541 $$->set_location(yylloc);
542 }
543 | DEC_OP unary_expression
544 {
545 void *ctx = state;
546 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
547 $$->set_location(yylloc);
548 }
549 | unary_operator unary_expression
550 {
551 void *ctx = state;
552 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
553 $$->set_location(yylloc);
554 }
555 ;
556
557 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
558 unary_operator:
559 '+' { $$ = ast_plus; }
560 | '-' { $$ = ast_neg; }
561 | '!' { $$ = ast_logic_not; }
562 | '~' { $$ = ast_bit_not; }
563 ;
564
565 multiplicative_expression:
566 unary_expression
567 | multiplicative_expression '*' unary_expression
568 {
569 void *ctx = state;
570 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
571 $$->set_location(yylloc);
572 }
573 | multiplicative_expression '/' unary_expression
574 {
575 void *ctx = state;
576 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
577 $$->set_location(yylloc);
578 }
579 | multiplicative_expression '%' unary_expression
580 {
581 void *ctx = state;
582 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
583 $$->set_location(yylloc);
584 }
585 ;
586
587 additive_expression:
588 multiplicative_expression
589 | additive_expression '+' multiplicative_expression
590 {
591 void *ctx = state;
592 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
593 $$->set_location(yylloc);
594 }
595 | additive_expression '-' multiplicative_expression
596 {
597 void *ctx = state;
598 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
599 $$->set_location(yylloc);
600 }
601 ;
602
603 shift_expression:
604 additive_expression
605 | shift_expression LEFT_OP additive_expression
606 {
607 void *ctx = state;
608 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
609 $$->set_location(yylloc);
610 }
611 | shift_expression RIGHT_OP additive_expression
612 {
613 void *ctx = state;
614 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
615 $$->set_location(yylloc);
616 }
617 ;
618
619 relational_expression:
620 shift_expression
621 | relational_expression '<' shift_expression
622 {
623 void *ctx = state;
624 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
625 $$->set_location(yylloc);
626 }
627 | relational_expression '>' shift_expression
628 {
629 void *ctx = state;
630 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
631 $$->set_location(yylloc);
632 }
633 | relational_expression LE_OP shift_expression
634 {
635 void *ctx = state;
636 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
637 $$->set_location(yylloc);
638 }
639 | relational_expression GE_OP shift_expression
640 {
641 void *ctx = state;
642 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
643 $$->set_location(yylloc);
644 }
645 ;
646
647 equality_expression:
648 relational_expression
649 | equality_expression EQ_OP relational_expression
650 {
651 void *ctx = state;
652 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
653 $$->set_location(yylloc);
654 }
655 | equality_expression NE_OP relational_expression
656 {
657 void *ctx = state;
658 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
659 $$->set_location(yylloc);
660 }
661 ;
662
663 and_expression:
664 equality_expression
665 | and_expression '&' equality_expression
666 {
667 void *ctx = state;
668 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
669 $$->set_location(yylloc);
670 }
671 ;
672
673 exclusive_or_expression:
674 and_expression
675 | exclusive_or_expression '^' and_expression
676 {
677 void *ctx = state;
678 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
679 $$->set_location(yylloc);
680 }
681 ;
682
683 inclusive_or_expression:
684 exclusive_or_expression
685 | inclusive_or_expression '|' exclusive_or_expression
686 {
687 void *ctx = state;
688 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
689 $$->set_location(yylloc);
690 }
691 ;
692
693 logical_and_expression:
694 inclusive_or_expression
695 | logical_and_expression AND_OP inclusive_or_expression
696 {
697 void *ctx = state;
698 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
699 $$->set_location(yylloc);
700 }
701 ;
702
703 logical_xor_expression:
704 logical_and_expression
705 | logical_xor_expression XOR_OP logical_and_expression
706 {
707 void *ctx = state;
708 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
709 $$->set_location(yylloc);
710 }
711 ;
712
713 logical_or_expression:
714 logical_xor_expression
715 | logical_or_expression OR_OP logical_xor_expression
716 {
717 void *ctx = state;
718 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
719 $$->set_location(yylloc);
720 }
721 ;
722
723 conditional_expression:
724 logical_or_expression
725 | logical_or_expression '?' expression ':' assignment_expression
726 {
727 void *ctx = state;
728 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
729 $$->set_location(yylloc);
730 }
731 ;
732
733 assignment_expression:
734 conditional_expression
735 | unary_expression assignment_operator assignment_expression
736 {
737 void *ctx = state;
738 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
739 $$->set_location(yylloc);
740 }
741 ;
742
743 assignment_operator:
744 '=' { $$ = ast_assign; }
745 | MUL_ASSIGN { $$ = ast_mul_assign; }
746 | DIV_ASSIGN { $$ = ast_div_assign; }
747 | MOD_ASSIGN { $$ = ast_mod_assign; }
748 | ADD_ASSIGN { $$ = ast_add_assign; }
749 | SUB_ASSIGN { $$ = ast_sub_assign; }
750 | LEFT_ASSIGN { $$ = ast_ls_assign; }
751 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
752 | AND_ASSIGN { $$ = ast_and_assign; }
753 | XOR_ASSIGN { $$ = ast_xor_assign; }
754 | OR_ASSIGN { $$ = ast_or_assign; }
755 ;
756
757 expression:
758 assignment_expression
759 {
760 $$ = $1;
761 }
762 | expression ',' assignment_expression
763 {
764 void *ctx = state;
765 if ($1->oper != ast_sequence) {
766 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
767 $$->set_location(yylloc);
768 $$->expressions.push_tail(& $1->link);
769 } else {
770 $$ = $1;
771 }
772
773 $$->expressions.push_tail(& $3->link);
774 }
775 ;
776
777 constant_expression:
778 conditional_expression
779 ;
780
781 declaration:
782 function_prototype ';'
783 {
784 state->symbols->pop_scope();
785 $$ = $1;
786 }
787 | init_declarator_list ';'
788 {
789 $$ = $1;
790 }
791 | PRECISION precision_qualifier type_specifier_no_prec ';'
792 {
793 $3->precision = $2;
794 $3->is_precision_statement = true;
795 $$ = $3;
796 }
797 | interface_block
798 {
799 $$ = $1;
800 }
801 ;
802
803 function_prototype:
804 function_declarator ')'
805 ;
806
807 function_declarator:
808 function_header
809 | function_header_with_parameters
810 ;
811
812 function_header_with_parameters:
813 function_header parameter_declaration
814 {
815 $$ = $1;
816 $$->parameters.push_tail(& $2->link);
817 }
818 | function_header_with_parameters ',' parameter_declaration
819 {
820 $$ = $1;
821 $$->parameters.push_tail(& $3->link);
822 }
823 ;
824
825 function_header:
826 fully_specified_type variable_identifier '('
827 {
828 void *ctx = state;
829 $$ = new(ctx) ast_function();
830 $$->set_location(yylloc);
831 $$->return_type = $1;
832 $$->identifier = $2;
833
834 state->symbols->add_function(new(state) ir_function($2));
835 state->symbols->push_scope();
836 }
837 ;
838
839 parameter_declarator:
840 type_specifier any_identifier
841 {
842 void *ctx = state;
843 $$ = new(ctx) ast_parameter_declarator();
844 $$->set_location(yylloc);
845 $$->type = new(ctx) ast_fully_specified_type();
846 $$->type->set_location(yylloc);
847 $$->type->specifier = $1;
848 $$->identifier = $2;
849 }
850 | type_specifier any_identifier '[' constant_expression ']'
851 {
852 void *ctx = state;
853 $$ = new(ctx) ast_parameter_declarator();
854 $$->set_location(yylloc);
855 $$->type = new(ctx) ast_fully_specified_type();
856 $$->type->set_location(yylloc);
857 $$->type->specifier = $1;
858 $$->identifier = $2;
859 $$->is_array = true;
860 $$->array_size = $4;
861 }
862 ;
863
864 parameter_declaration:
865 parameter_type_qualifier parameter_qualifier parameter_declarator
866 {
867 $1.flags.i |= $2.flags.i;
868
869 $$ = $3;
870 $$->type->qualifier = $1;
871 }
872 | parameter_qualifier parameter_declarator
873 {
874 $$ = $2;
875 $$->type->qualifier = $1;
876 }
877 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
878 {
879 void *ctx = state;
880 $1.flags.i |= $2.flags.i;
881
882 $$ = new(ctx) ast_parameter_declarator();
883 $$->set_location(yylloc);
884 $$->type = new(ctx) ast_fully_specified_type();
885 $$->type->qualifier = $1;
886 $$->type->specifier = $3;
887 }
888 | parameter_qualifier parameter_type_specifier
889 {
890 void *ctx = state;
891 $$ = new(ctx) ast_parameter_declarator();
892 $$->set_location(yylloc);
893 $$->type = new(ctx) ast_fully_specified_type();
894 $$->type->qualifier = $1;
895 $$->type->specifier = $2;
896 }
897 ;
898
899 parameter_qualifier:
900 /* empty */
901 {
902 memset(& $$, 0, sizeof($$));
903 }
904 | IN_TOK
905 {
906 memset(& $$, 0, sizeof($$));
907 $$.flags.q.in = 1;
908 }
909 | OUT_TOK
910 {
911 memset(& $$, 0, sizeof($$));
912 $$.flags.q.out = 1;
913 }
914 | INOUT_TOK
915 {
916 memset(& $$, 0, sizeof($$));
917 $$.flags.q.in = 1;
918 $$.flags.q.out = 1;
919 }
920 ;
921
922 parameter_type_specifier:
923 type_specifier
924 ;
925
926 init_declarator_list:
927 single_declaration
928 | init_declarator_list ',' any_identifier
929 {
930 void *ctx = state;
931 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
932 decl->set_location(yylloc);
933
934 $$ = $1;
935 $$->declarations.push_tail(&decl->link);
936 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
937 }
938 | init_declarator_list ',' any_identifier '[' ']'
939 {
940 void *ctx = state;
941 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
942 decl->set_location(yylloc);
943
944 $$ = $1;
945 $$->declarations.push_tail(&decl->link);
946 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
947 }
948 | init_declarator_list ',' any_identifier '[' constant_expression ']'
949 {
950 void *ctx = state;
951 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
952 decl->set_location(yylloc);
953
954 $$ = $1;
955 $$->declarations.push_tail(&decl->link);
956 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
957 }
958 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
959 {
960 void *ctx = state;
961 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
962 decl->set_location(yylloc);
963
964 $$ = $1;
965 $$->declarations.push_tail(&decl->link);
966 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
967 if ($7->oper == ast_aggregate) {
968 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
969 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
970 _mesa_ast_set_aggregate_type(type, ai, state);
971 }
972 }
973 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
974 {
975 void *ctx = state;
976 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
977 decl->set_location(yylloc);
978
979 $$ = $1;
980 $$->declarations.push_tail(&decl->link);
981 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
982 if ($8->oper == ast_aggregate) {
983 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
984 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
985 _mesa_ast_set_aggregate_type(type, ai, state);
986 }
987 }
988 | init_declarator_list ',' any_identifier '=' initializer
989 {
990 void *ctx = state;
991 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
992 decl->set_location(yylloc);
993
994 $$ = $1;
995 $$->declarations.push_tail(&decl->link);
996 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
997 if ($5->oper == ast_aggregate) {
998 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
999 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1000 }
1001 }
1002 ;
1003
1004 // Grammar Note: No 'enum', or 'typedef'.
1005 single_declaration:
1006 fully_specified_type
1007 {
1008 void *ctx = state;
1009 /* Empty declaration list is valid. */
1010 $$ = new(ctx) ast_declarator_list($1);
1011 $$->set_location(yylloc);
1012 }
1013 | fully_specified_type any_identifier
1014 {
1015 void *ctx = state;
1016 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1017
1018 $$ = new(ctx) ast_declarator_list($1);
1019 $$->set_location(yylloc);
1020 $$->declarations.push_tail(&decl->link);
1021 }
1022 | fully_specified_type any_identifier '[' ']'
1023 {
1024 void *ctx = state;
1025 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1026
1027 $$ = new(ctx) ast_declarator_list($1);
1028 $$->set_location(yylloc);
1029 $$->declarations.push_tail(&decl->link);
1030 }
1031 | fully_specified_type any_identifier '[' constant_expression ']'
1032 {
1033 void *ctx = state;
1034 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1035
1036 $$ = new(ctx) ast_declarator_list($1);
1037 $$->set_location(yylloc);
1038 $$->declarations.push_tail(&decl->link);
1039 }
1040 | fully_specified_type any_identifier '[' ']' '=' initializer
1041 {
1042 void *ctx = state;
1043 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1044
1045 $$ = new(ctx) ast_declarator_list($1);
1046 $$->set_location(yylloc);
1047 $$->declarations.push_tail(&decl->link);
1048 if ($6->oper == ast_aggregate) {
1049 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1050 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1051 _mesa_ast_set_aggregate_type(type, ai, state);
1052 }
1053 }
1054 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1055 {
1056 void *ctx = state;
1057 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1058
1059 $$ = new(ctx) ast_declarator_list($1);
1060 $$->set_location(yylloc);
1061 $$->declarations.push_tail(&decl->link);
1062 if ($7->oper == ast_aggregate) {
1063 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1064 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1065 _mesa_ast_set_aggregate_type(type, ai, state);
1066 }
1067 }
1068 | fully_specified_type any_identifier '=' initializer
1069 {
1070 void *ctx = state;
1071 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1072
1073 $$ = new(ctx) ast_declarator_list($1);
1074 $$->set_location(yylloc);
1075 $$->declarations.push_tail(&decl->link);
1076 if ($4->oper == ast_aggregate) {
1077 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1078 }
1079 }
1080 | INVARIANT variable_identifier // Vertex only.
1081 {
1082 void *ctx = state;
1083 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1084
1085 $$ = new(ctx) ast_declarator_list(NULL);
1086 $$->set_location(yylloc);
1087 $$->invariant = true;
1088
1089 $$->declarations.push_tail(&decl->link);
1090 }
1091 ;
1092
1093 fully_specified_type:
1094 type_specifier
1095 {
1096 void *ctx = state;
1097 $$ = new(ctx) ast_fully_specified_type();
1098 $$->set_location(yylloc);
1099 $$->specifier = $1;
1100 }
1101 | type_qualifier type_specifier
1102 {
1103 void *ctx = state;
1104 $$ = new(ctx) ast_fully_specified_type();
1105 $$->set_location(yylloc);
1106 $$->qualifier = $1;
1107 $$->specifier = $2;
1108 }
1109 ;
1110
1111 layout_qualifier:
1112 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1113 {
1114 $$ = $3;
1115 }
1116 ;
1117
1118 layout_qualifier_id_list:
1119 layout_qualifier_id
1120 | layout_qualifier_id_list ',' layout_qualifier_id
1121 {
1122 $$ = $1;
1123 if (!$$.merge_qualifier(& @3, state, $3)) {
1124 YYERROR;
1125 }
1126 }
1127 ;
1128
1129 integer_constant:
1130 INTCONSTANT { $$ = $1; }
1131 | UINTCONSTANT { $$ = $1; }
1132 ;
1133
1134 layout_qualifier_id:
1135 any_identifier
1136 {
1137 memset(& $$, 0, sizeof($$));
1138
1139 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1140 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1141 if (strcmp($1, "origin_upper_left") == 0) {
1142 $$.flags.q.origin_upper_left = 1;
1143 } else if (strcmp($1, "pixel_center_integer") == 0) {
1144 $$.flags.q.pixel_center_integer = 1;
1145 }
1146
1147 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1148 _mesa_glsl_warning(& @1, state,
1149 "GL_ARB_fragment_coord_conventions layout "
1150 "identifier `%s' used\n", $1);
1151 }
1152 }
1153
1154 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1155 if (!$$.flags.i &&
1156 (state->AMD_conservative_depth_enable ||
1157 state->ARB_conservative_depth_enable)) {
1158 if (strcmp($1, "depth_any") == 0) {
1159 $$.flags.q.depth_any = 1;
1160 } else if (strcmp($1, "depth_greater") == 0) {
1161 $$.flags.q.depth_greater = 1;
1162 } else if (strcmp($1, "depth_less") == 0) {
1163 $$.flags.q.depth_less = 1;
1164 } else if (strcmp($1, "depth_unchanged") == 0) {
1165 $$.flags.q.depth_unchanged = 1;
1166 }
1167
1168 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1169 _mesa_glsl_warning(& @1, state,
1170 "GL_AMD_conservative_depth "
1171 "layout qualifier `%s' is used\n", $1);
1172 }
1173 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1174 _mesa_glsl_warning(& @1, state,
1175 "GL_ARB_conservative_depth "
1176 "layout qualifier `%s' is used\n", $1);
1177 }
1178 }
1179
1180 /* See also interface_block_layout_qualifier. */
1181 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1182 if (strcmp($1, "std140") == 0) {
1183 $$.flags.q.std140 = 1;
1184 } else if (strcmp($1, "shared") == 0) {
1185 $$.flags.q.shared = 1;
1186 } else if (strcmp($1, "column_major") == 0) {
1187 $$.flags.q.column_major = 1;
1188 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1189 * below in the interface_block_layout_qualifier rule.
1190 *
1191 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1192 * an identifier.
1193 */
1194 } else if (strcmp($1, "row_major") == 0) {
1195 $$.flags.q.row_major = 1;
1196 }
1197
1198 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1199 _mesa_glsl_warning(& @1, state,
1200 "#version 140 / GL_ARB_uniform_buffer_object "
1201 "layout qualifier `%s' is used\n", $1);
1202 }
1203 }
1204
1205 if (!$$.flags.i) {
1206 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1207 "`%s'\n", $1);
1208 YYERROR;
1209 }
1210 }
1211 | any_identifier '=' integer_constant
1212 {
1213 memset(& $$, 0, sizeof($$));
1214
1215 if (state->ARB_explicit_attrib_location_enable) {
1216 if (strcmp("location", $1) == 0) {
1217 $$.flags.q.explicit_location = 1;
1218
1219 if ($3 >= 0) {
1220 $$.location = $3;
1221 } else {
1222 _mesa_glsl_error(& @3, state,
1223 "invalid location %d specified\n", $3);
1224 YYERROR;
1225 }
1226 }
1227
1228 if (strcmp("index", $1) == 0) {
1229 $$.flags.q.explicit_index = 1;
1230
1231 if ($3 >= 0) {
1232 $$.index = $3;
1233 } else {
1234 _mesa_glsl_error(& @3, state,
1235 "invalid index %d specified\n", $3);
1236 YYERROR;
1237 }
1238 }
1239 }
1240
1241 /* If the identifier didn't match any known layout identifiers,
1242 * emit an error.
1243 */
1244 if (!$$.flags.i) {
1245 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1246 "`%s'\n", $1);
1247 YYERROR;
1248 } else if (state->ARB_explicit_attrib_location_warn) {
1249 _mesa_glsl_warning(& @1, state,
1250 "GL_ARB_explicit_attrib_location layout "
1251 "identifier `%s' used\n", $1);
1252 }
1253 }
1254 | interface_block_layout_qualifier
1255 {
1256 $$ = $1;
1257 /* Layout qualifiers for ARB_uniform_buffer_object. */
1258 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1259 _mesa_glsl_error(& @1, state,
1260 "#version 140 / GL_ARB_uniform_buffer_object "
1261 "layout qualifier `%s' is used\n", $1);
1262 } else if ($$.flags.q.uniform && 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\n", $1);
1266 }
1267 }
1268 ;
1269
1270 /* This is a separate language rule because we parse these as tokens
1271 * (due to them being reserved keywords) instead of identifiers like
1272 * most qualifiers. See the any_identifier path of
1273 * layout_qualifier_id for the others.
1274 */
1275 interface_block_layout_qualifier:
1276 ROW_MAJOR
1277 {
1278 memset(& $$, 0, sizeof($$));
1279 $$.flags.q.row_major = 1;
1280 }
1281 | PACKED_TOK
1282 {
1283 memset(& $$, 0, sizeof($$));
1284 $$.flags.q.packed = 1;
1285 }
1286 ;
1287
1288 interpolation_qualifier:
1289 SMOOTH
1290 {
1291 memset(& $$, 0, sizeof($$));
1292 $$.flags.q.smooth = 1;
1293 }
1294 | FLAT
1295 {
1296 memset(& $$, 0, sizeof($$));
1297 $$.flags.q.flat = 1;
1298 }
1299 | NOPERSPECTIVE
1300 {
1301 memset(& $$, 0, sizeof($$));
1302 $$.flags.q.noperspective = 1;
1303 }
1304 ;
1305
1306 parameter_type_qualifier:
1307 CONST_TOK
1308 {
1309 memset(& $$, 0, sizeof($$));
1310 $$.flags.q.constant = 1;
1311 }
1312 ;
1313
1314 type_qualifier:
1315 storage_qualifier
1316 | layout_qualifier
1317 | layout_qualifier storage_qualifier
1318 {
1319 $$ = $1;
1320 $$.flags.i |= $2.flags.i;
1321 }
1322 | interpolation_qualifier
1323 | interpolation_qualifier storage_qualifier
1324 {
1325 $$ = $1;
1326 $$.flags.i |= $2.flags.i;
1327 }
1328 | INVARIANT storage_qualifier
1329 {
1330 $$ = $2;
1331 $$.flags.q.invariant = 1;
1332 }
1333 | INVARIANT interpolation_qualifier storage_qualifier
1334 {
1335 $$ = $2;
1336 $$.flags.i |= $3.flags.i;
1337 $$.flags.q.invariant = 1;
1338 }
1339 | INVARIANT
1340 {
1341 memset(& $$, 0, sizeof($$));
1342 $$.flags.q.invariant = 1;
1343 }
1344 ;
1345
1346 storage_qualifier:
1347 CONST_TOK
1348 {
1349 memset(& $$, 0, sizeof($$));
1350 $$.flags.q.constant = 1;
1351 }
1352 | ATTRIBUTE
1353 {
1354 memset(& $$, 0, sizeof($$));
1355 $$.flags.q.attribute = 1;
1356 }
1357 | VARYING
1358 {
1359 memset(& $$, 0, sizeof($$));
1360 $$.flags.q.varying = 1;
1361 }
1362 | CENTROID VARYING
1363 {
1364 memset(& $$, 0, sizeof($$));
1365 $$.flags.q.centroid = 1;
1366 $$.flags.q.varying = 1;
1367 }
1368 | IN_TOK
1369 {
1370 memset(& $$, 0, sizeof($$));
1371 $$.flags.q.in = 1;
1372 }
1373 | OUT_TOK
1374 {
1375 memset(& $$, 0, sizeof($$));
1376 $$.flags.q.out = 1;
1377 }
1378 | CENTROID IN_TOK
1379 {
1380 memset(& $$, 0, sizeof($$));
1381 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1382 }
1383 | CENTROID OUT_TOK
1384 {
1385 memset(& $$, 0, sizeof($$));
1386 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1387 }
1388 | UNIFORM
1389 {
1390 memset(& $$, 0, sizeof($$));
1391 $$.flags.q.uniform = 1;
1392 }
1393 ;
1394
1395 type_specifier:
1396 type_specifier_no_prec
1397 {
1398 $$ = $1;
1399 }
1400 | precision_qualifier type_specifier_no_prec
1401 {
1402 $$ = $2;
1403 $$->precision = $1;
1404 }
1405 ;
1406
1407 type_specifier_no_prec:
1408 type_specifier_nonarray
1409 | type_specifier_nonarray '[' ']'
1410 {
1411 $$ = $1;
1412 $$->is_array = true;
1413 $$->array_size = NULL;
1414 }
1415 | type_specifier_nonarray '[' constant_expression ']'
1416 {
1417 $$ = $1;
1418 $$->is_array = true;
1419 $$->array_size = $3;
1420 }
1421 ;
1422
1423 type_specifier_nonarray:
1424 basic_type_specifier_nonarray
1425 {
1426 void *ctx = state;
1427 $$ = new(ctx) ast_type_specifier($1);
1428 $$->set_location(yylloc);
1429 }
1430 | struct_specifier
1431 {
1432 void *ctx = state;
1433 $$ = new(ctx) ast_type_specifier($1);
1434 $$->set_location(yylloc);
1435 }
1436 | TYPE_IDENTIFIER
1437 {
1438 void *ctx = state;
1439 $$ = new(ctx) ast_type_specifier($1);
1440 $$->set_location(yylloc);
1441 }
1442 ;
1443
1444 basic_type_specifier_nonarray:
1445 VOID_TOK { $$ = "void"; }
1446 | FLOAT_TOK { $$ = "float"; }
1447 | INT_TOK { $$ = "int"; }
1448 | UINT_TOK { $$ = "uint"; }
1449 | BOOL_TOK { $$ = "bool"; }
1450 | VEC2 { $$ = "vec2"; }
1451 | VEC3 { $$ = "vec3"; }
1452 | VEC4 { $$ = "vec4"; }
1453 | BVEC2 { $$ = "bvec2"; }
1454 | BVEC3 { $$ = "bvec3"; }
1455 | BVEC4 { $$ = "bvec4"; }
1456 | IVEC2 { $$ = "ivec2"; }
1457 | IVEC3 { $$ = "ivec3"; }
1458 | IVEC4 { $$ = "ivec4"; }
1459 | UVEC2 { $$ = "uvec2"; }
1460 | UVEC3 { $$ = "uvec3"; }
1461 | UVEC4 { $$ = "uvec4"; }
1462 | MAT2X2 { $$ = "mat2"; }
1463 | MAT2X3 { $$ = "mat2x3"; }
1464 | MAT2X4 { $$ = "mat2x4"; }
1465 | MAT3X2 { $$ = "mat3x2"; }
1466 | MAT3X3 { $$ = "mat3"; }
1467 | MAT3X4 { $$ = "mat3x4"; }
1468 | MAT4X2 { $$ = "mat4x2"; }
1469 | MAT4X3 { $$ = "mat4x3"; }
1470 | MAT4X4 { $$ = "mat4"; }
1471 | SAMPLER1D { $$ = "sampler1D"; }
1472 | SAMPLER2D { $$ = "sampler2D"; }
1473 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1474 | SAMPLER3D { $$ = "sampler3D"; }
1475 | SAMPLERCUBE { $$ = "samplerCube"; }
1476 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1477 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1478 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1479 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1480 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1481 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1482 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1483 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1484 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1485 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1486 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1487 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1488 | ISAMPLER1D { $$ = "isampler1D"; }
1489 | ISAMPLER2D { $$ = "isampler2D"; }
1490 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1491 | ISAMPLER3D { $$ = "isampler3D"; }
1492 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1493 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1494 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1495 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1496 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1497 | USAMPLER1D { $$ = "usampler1D"; }
1498 | USAMPLER2D { $$ = "usampler2D"; }
1499 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1500 | USAMPLER3D { $$ = "usampler3D"; }
1501 | USAMPLERCUBE { $$ = "usamplerCube"; }
1502 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1503 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1504 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1505 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1506 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1507 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1508 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1509 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1510 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1511 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1512 ;
1513
1514 precision_qualifier:
1515 HIGHP {
1516 state->check_precision_qualifiers_allowed(&@1);
1517
1518 $$ = ast_precision_high;
1519 }
1520 | MEDIUMP {
1521 state->check_precision_qualifiers_allowed(&@1);
1522
1523 $$ = ast_precision_medium;
1524 }
1525 | LOWP {
1526 state->check_precision_qualifiers_allowed(&@1);
1527
1528 $$ = ast_precision_low;
1529 }
1530 ;
1531
1532 struct_specifier:
1533 STRUCT any_identifier '{' struct_declaration_list '}'
1534 {
1535 void *ctx = state;
1536 $$ = new(ctx) ast_struct_specifier($2, $4);
1537 $$->set_location(yylloc);
1538 state->symbols->add_type($2, glsl_type::void_type);
1539 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1540 }
1541 | STRUCT '{' struct_declaration_list '}'
1542 {
1543 void *ctx = state;
1544 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1545 $$->set_location(yylloc);
1546 }
1547 ;
1548
1549 struct_declaration_list:
1550 struct_declaration
1551 {
1552 $$ = $1;
1553 $1->link.self_link();
1554 }
1555 | struct_declaration_list struct_declaration
1556 {
1557 $$ = $1;
1558 $$->link.insert_before(& $2->link);
1559 }
1560 ;
1561
1562 struct_declaration:
1563 type_specifier struct_declarator_list ';'
1564 {
1565 void *ctx = state;
1566 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1567 type->set_location(yylloc);
1568
1569 type->specifier = $1;
1570 $$ = new(ctx) ast_declarator_list(type);
1571 $$->set_location(yylloc);
1572
1573 $$->declarations.push_degenerate_list_at_head(& $2->link);
1574 }
1575 ;
1576
1577 struct_declarator_list:
1578 struct_declarator
1579 {
1580 $$ = $1;
1581 $1->link.self_link();
1582 }
1583 | struct_declarator_list ',' struct_declarator
1584 {
1585 $$ = $1;
1586 $$->link.insert_before(& $3->link);
1587 }
1588 ;
1589
1590 struct_declarator:
1591 any_identifier
1592 {
1593 void *ctx = state;
1594 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1595 $$->set_location(yylloc);
1596 }
1597 | any_identifier '[' constant_expression ']'
1598 {
1599 void *ctx = state;
1600 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1601 $$->set_location(yylloc);
1602 }
1603 ;
1604
1605 initializer:
1606 assignment_expression
1607 | '{' initializer_list '}'
1608 {
1609 $$ = $2;
1610 }
1611 | '{' initializer_list ',' '}'
1612 {
1613 $$ = $2;
1614 }
1615 ;
1616
1617 initializer_list:
1618 initializer
1619 {
1620 void *ctx = state;
1621 $$ = new(ctx) ast_aggregate_initializer();
1622 $$->set_location(yylloc);
1623 $$->expressions.push_tail(& $1->link);
1624 }
1625 | initializer_list ',' initializer
1626 {
1627 $1->expressions.push_tail(& $3->link);
1628 }
1629 ;
1630
1631 declaration_statement:
1632 declaration
1633 ;
1634
1635 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1636 // supported.
1637 statement:
1638 compound_statement { $$ = (ast_node *) $1; }
1639 | simple_statement
1640 ;
1641
1642 simple_statement:
1643 declaration_statement
1644 | expression_statement
1645 | selection_statement
1646 | switch_statement
1647 | iteration_statement
1648 | jump_statement
1649 ;
1650
1651 compound_statement:
1652 '{' '}'
1653 {
1654 void *ctx = state;
1655 $$ = new(ctx) ast_compound_statement(true, NULL);
1656 $$->set_location(yylloc);
1657 }
1658 | '{'
1659 {
1660 state->symbols->push_scope();
1661 }
1662 statement_list '}'
1663 {
1664 void *ctx = state;
1665 $$ = new(ctx) ast_compound_statement(true, $3);
1666 $$->set_location(yylloc);
1667 state->symbols->pop_scope();
1668 }
1669 ;
1670
1671 statement_no_new_scope:
1672 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1673 | simple_statement
1674 ;
1675
1676 compound_statement_no_new_scope:
1677 '{' '}'
1678 {
1679 void *ctx = state;
1680 $$ = new(ctx) ast_compound_statement(false, NULL);
1681 $$->set_location(yylloc);
1682 }
1683 | '{' statement_list '}'
1684 {
1685 void *ctx = state;
1686 $$ = new(ctx) ast_compound_statement(false, $2);
1687 $$->set_location(yylloc);
1688 }
1689 ;
1690
1691 statement_list:
1692 statement
1693 {
1694 if ($1 == NULL) {
1695 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1696 assert($1 != NULL);
1697 }
1698
1699 $$ = $1;
1700 $$->link.self_link();
1701 }
1702 | statement_list statement
1703 {
1704 if ($2 == NULL) {
1705 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1706 assert($2 != NULL);
1707 }
1708 $$ = $1;
1709 $$->link.insert_before(& $2->link);
1710 }
1711 ;
1712
1713 expression_statement:
1714 ';'
1715 {
1716 void *ctx = state;
1717 $$ = new(ctx) ast_expression_statement(NULL);
1718 $$->set_location(yylloc);
1719 }
1720 | expression ';'
1721 {
1722 void *ctx = state;
1723 $$ = new(ctx) ast_expression_statement($1);
1724 $$->set_location(yylloc);
1725 }
1726 ;
1727
1728 selection_statement:
1729 IF '(' expression ')' selection_rest_statement
1730 {
1731 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1732 $5.else_statement);
1733 $$->set_location(yylloc);
1734 }
1735 ;
1736
1737 selection_rest_statement:
1738 statement ELSE statement
1739 {
1740 $$.then_statement = $1;
1741 $$.else_statement = $3;
1742 }
1743 | statement %prec THEN
1744 {
1745 $$.then_statement = $1;
1746 $$.else_statement = NULL;
1747 }
1748 ;
1749
1750 condition:
1751 expression
1752 {
1753 $$ = (ast_node *) $1;
1754 }
1755 | fully_specified_type any_identifier '=' initializer
1756 {
1757 void *ctx = state;
1758 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1759 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1760 decl->set_location(yylloc);
1761 declarator->set_location(yylloc);
1762
1763 declarator->declarations.push_tail(&decl->link);
1764 $$ = declarator;
1765 }
1766 ;
1767
1768 /*
1769 * siwtch_statement grammar is based on the syntax described in the body
1770 * of the GLSL spec, not in it's appendix!!!
1771 */
1772 switch_statement:
1773 SWITCH '(' expression ')' switch_body
1774 {
1775 $$ = new(state) ast_switch_statement($3, $5);
1776 $$->set_location(yylloc);
1777 }
1778 ;
1779
1780 switch_body:
1781 '{' '}'
1782 {
1783 $$ = new(state) ast_switch_body(NULL);
1784 $$->set_location(yylloc);
1785 }
1786 | '{' case_statement_list '}'
1787 {
1788 $$ = new(state) ast_switch_body($2);
1789 $$->set_location(yylloc);
1790 }
1791 ;
1792
1793 case_label:
1794 CASE expression ':'
1795 {
1796 $$ = new(state) ast_case_label($2);
1797 $$->set_location(yylloc);
1798 }
1799 | DEFAULT ':'
1800 {
1801 $$ = new(state) ast_case_label(NULL);
1802 $$->set_location(yylloc);
1803 }
1804 ;
1805
1806 case_label_list:
1807 case_label
1808 {
1809 ast_case_label_list *labels = new(state) ast_case_label_list();
1810
1811 labels->labels.push_tail(& $1->link);
1812 $$ = labels;
1813 $$->set_location(yylloc);
1814 }
1815 | case_label_list case_label
1816 {
1817 $$ = $1;
1818 $$->labels.push_tail(& $2->link);
1819 }
1820 ;
1821
1822 case_statement:
1823 case_label_list statement
1824 {
1825 ast_case_statement *stmts = new(state) ast_case_statement($1);
1826 stmts->set_location(yylloc);
1827
1828 stmts->stmts.push_tail(& $2->link);
1829 $$ = stmts;
1830 }
1831 | case_statement statement
1832 {
1833 $$ = $1;
1834 $$->stmts.push_tail(& $2->link);
1835 }
1836 ;
1837
1838 case_statement_list:
1839 case_statement
1840 {
1841 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1842 cases->set_location(yylloc);
1843
1844 cases->cases.push_tail(& $1->link);
1845 $$ = cases;
1846 }
1847 | case_statement_list case_statement
1848 {
1849 $$ = $1;
1850 $$->cases.push_tail(& $2->link);
1851 }
1852 ;
1853
1854 iteration_statement:
1855 WHILE '(' condition ')' statement_no_new_scope
1856 {
1857 void *ctx = state;
1858 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1859 NULL, $3, NULL, $5);
1860 $$->set_location(yylloc);
1861 }
1862 | DO statement WHILE '(' expression ')' ';'
1863 {
1864 void *ctx = state;
1865 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1866 NULL, $5, NULL, $2);
1867 $$->set_location(yylloc);
1868 }
1869 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1870 {
1871 void *ctx = state;
1872 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1873 $3, $4.cond, $4.rest, $6);
1874 $$->set_location(yylloc);
1875 }
1876 ;
1877
1878 for_init_statement:
1879 expression_statement
1880 | declaration_statement
1881 ;
1882
1883 conditionopt:
1884 condition
1885 | /* empty */
1886 {
1887 $$ = NULL;
1888 }
1889 ;
1890
1891 for_rest_statement:
1892 conditionopt ';'
1893 {
1894 $$.cond = $1;
1895 $$.rest = NULL;
1896 }
1897 | conditionopt ';' expression
1898 {
1899 $$.cond = $1;
1900 $$.rest = $3;
1901 }
1902 ;
1903
1904 // Grammar Note: No 'goto'. Gotos are not supported.
1905 jump_statement:
1906 CONTINUE ';'
1907 {
1908 void *ctx = state;
1909 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1910 $$->set_location(yylloc);
1911 }
1912 | BREAK ';'
1913 {
1914 void *ctx = state;
1915 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1916 $$->set_location(yylloc);
1917 }
1918 | RETURN ';'
1919 {
1920 void *ctx = state;
1921 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1922 $$->set_location(yylloc);
1923 }
1924 | RETURN expression ';'
1925 {
1926 void *ctx = state;
1927 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1928 $$->set_location(yylloc);
1929 }
1930 | DISCARD ';' // Fragment shader only.
1931 {
1932 void *ctx = state;
1933 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1934 $$->set_location(yylloc);
1935 }
1936 ;
1937
1938 external_declaration:
1939 function_definition { $$ = $1; }
1940 | declaration { $$ = $1; }
1941 | pragma_statement { $$ = NULL; }
1942 | layout_defaults { $$ = NULL; }
1943 ;
1944
1945 function_definition:
1946 function_prototype compound_statement_no_new_scope
1947 {
1948 void *ctx = state;
1949 $$ = new(ctx) ast_function_definition();
1950 $$->set_location(yylloc);
1951 $$->prototype = $1;
1952 $$->body = $2;
1953
1954 state->symbols->pop_scope();
1955 }
1956 ;
1957
1958 /* layout_qualifieropt is packed into this rule */
1959 interface_block:
1960 basic_interface_block
1961 {
1962 $$ = $1;
1963 }
1964 | layout_qualifier basic_interface_block
1965 {
1966 ast_interface_block *block = $2;
1967 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1968 YYERROR;
1969 }
1970 $$ = block;
1971 }
1972 ;
1973
1974 basic_interface_block:
1975 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1976 {
1977 ast_interface_block *const block = $6;
1978
1979 block->block_name = $2;
1980 block->declarations.push_degenerate_list_at_head(& $4->link);
1981
1982 if ($1.flags.q.uniform) {
1983 if (!state->ARB_uniform_buffer_object_enable) {
1984 _mesa_glsl_error(& @1, state,
1985 "#version 140 / GL_ARB_uniform_buffer_object "
1986 "required for defining uniform blocks\n");
1987 } else if (state->ARB_uniform_buffer_object_warn) {
1988 _mesa_glsl_warning(& @1, state,
1989 "#version 140 / GL_ARB_uniform_buffer_object "
1990 "required for defining uniform blocks\n");
1991 }
1992 } else {
1993 if (state->es_shader || state->language_version < 150) {
1994 _mesa_glsl_error(& @1, state,
1995 "#version 150 required for using "
1996 "interface blocks.\n");
1997 }
1998 }
1999
2000 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2001 * "It is illegal to have an input block in a vertex shader
2002 * or an output block in a fragment shader"
2003 */
2004 if ((state->target == vertex_shader) && $1.flags.q.in) {
2005 _mesa_glsl_error(& @1, state,
2006 "`in' interface block is not allowed for "
2007 "a vertex shader\n");
2008 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2009 _mesa_glsl_error(& @1, state,
2010 "`out' interface block is not allowed for "
2011 "a fragment shader\n");
2012 }
2013
2014 /* Since block arrays require names, and both features are added in
2015 * the same language versions, we don't have to explicitly
2016 * version-check both things.
2017 */
2018 if (block->instance_name != NULL) {
2019 state->check_version(150, 300, & @1, "interface blocks with "
2020 "an instance name are not allowed");
2021 }
2022
2023 unsigned interface_type_mask;
2024 struct ast_type_qualifier temp_type_qualifier;
2025
2026 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2027 * to ignore other irrelevant flags like interpolation qualifiers.
2028 */
2029 temp_type_qualifier.flags.i = 0;
2030 temp_type_qualifier.flags.q.uniform = true;
2031 temp_type_qualifier.flags.q.in = true;
2032 temp_type_qualifier.flags.q.out = true;
2033 interface_type_mask = temp_type_qualifier.flags.i;
2034
2035 /* Get the block's interface qualifier. The interface_qualifier
2036 * production rule guarantees that only one bit will be set (and
2037 * it will be in/out/uniform).
2038 */
2039 unsigned block_interface_qualifier = $1.flags.i;
2040
2041 block->layout.flags.i |= block_interface_qualifier;
2042
2043 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2044 ast_type_qualifier& qualifier = member->type->qualifier;
2045 if ((qualifier.flags.i & interface_type_mask) == 0) {
2046 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2047 * "If no optional qualifier is used in a member declaration, the
2048 * qualifier of the variable is just in, out, or uniform as declared
2049 * by interface-qualifier."
2050 */
2051 qualifier.flags.i |= block_interface_qualifier;
2052 } else if ((qualifier.flags.i & interface_type_mask) !=
2053 block_interface_qualifier) {
2054 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2055 * "If optional qualifiers are used, they can include interpolation
2056 * and storage qualifiers and they must declare an input, output,
2057 * or uniform variable consistent with the interface qualifier of
2058 * the block."
2059 */
2060 _mesa_glsl_error(& @1, state,
2061 "uniform/in/out qualifier on "
2062 "interface block member does not match "
2063 "the interface block\n");
2064 }
2065 }
2066
2067 $$ = block;
2068 }
2069 ;
2070
2071 interface_qualifier:
2072 IN_TOK
2073 {
2074 memset(& $$, 0, sizeof($$));
2075 $$.flags.q.in = 1;
2076 }
2077 | OUT_TOK
2078 {
2079 memset(& $$, 0, sizeof($$));
2080 $$.flags.q.out = 1;
2081 }
2082 | UNIFORM
2083 {
2084 memset(& $$, 0, sizeof($$));
2085 $$.flags.q.uniform = 1;
2086 }
2087 ;
2088
2089 instance_name_opt:
2090 /* empty */
2091 {
2092 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2093 NULL,
2094 NULL);
2095 }
2096 | NEW_IDENTIFIER
2097 {
2098 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2099 $1,
2100 NULL);
2101 }
2102 | NEW_IDENTIFIER '[' constant_expression ']'
2103 {
2104 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2105 $1,
2106 $3);
2107 }
2108 | NEW_IDENTIFIER '[' ']'
2109 {
2110 _mesa_glsl_error(& @1, state,
2111 "instance block arrays must be explicitly sized\n");
2112
2113 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2114 $1,
2115 NULL);
2116 }
2117 ;
2118
2119 member_list:
2120 member_declaration
2121 {
2122 $$ = $1;
2123 $1->link.self_link();
2124 }
2125 | member_declaration member_list
2126 {
2127 $$ = $1;
2128 $2->link.insert_before(& $$->link);
2129 }
2130 ;
2131
2132 member_declaration:
2133 fully_specified_type struct_declarator_list ';'
2134 {
2135 void *ctx = state;
2136 ast_fully_specified_type *type = $1;
2137 type->set_location(yylloc);
2138
2139 if (type->qualifier.flags.q.attribute) {
2140 _mesa_glsl_error(& @1, state,
2141 "keyword 'attribute' cannot be used with "
2142 "interface block member\n");
2143 } else if (type->qualifier.flags.q.varying) {
2144 _mesa_glsl_error(& @1, state,
2145 "keyword 'varying' cannot be used with "
2146 "interface block member\n");
2147 }
2148
2149 $$ = new(ctx) ast_declarator_list(type);
2150 $$->set_location(yylloc);
2151 $$->ubo_qualifiers_valid = true;
2152
2153 $$->declarations.push_degenerate_list_at_head(& $2->link);
2154 }
2155 ;
2156
2157 layout_defaults:
2158 layout_qualifier UNIFORM ';'
2159 {
2160 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,
2161 $1)) {
2162 YYERROR;
2163 }
2164 }