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