glsl: Slight refactor of error / warning checking for ARB_fcc layout
[mesa.git] / src / glsl / glsl_parser.ypp
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
33 #define YYLEX_PARAM state->scanner
34
35 %}
36
37 %pure-parser
38 %error-verbose
39
40 %locations
41 %initial-action {
42 @$.first_line = 1;
43 @$.first_column = 1;
44 @$.last_line = 1;
45 @$.last_column = 1;
46 @$.source = 0;
47 }
48
49 %lex-param {void *scanner}
50 %parse-param {struct _mesa_glsl_parse_state *state}
51
52 %union {
53 int n;
54 float real;
55 char *identifier;
56
57 union {
58 struct ast_type_qualifier q;
59 unsigned i;
60 } type_qualifier;
61
62 ast_node *node;
63 ast_type_specifier *type_specifier;
64 ast_fully_specified_type *fully_specified_type;
65 ast_function *function;
66 ast_parameter_declarator *parameter_declarator;
67 ast_function_definition *function_definition;
68 ast_compound_statement *compound_statement;
69 ast_expression *expression;
70 ast_declarator_list *declarator_list;
71 ast_struct_specifier *struct_specifier;
72 ast_declaration *declaration;
73
74 struct {
75 ast_node *cond;
76 ast_expression *rest;
77 } for_rest_statement;
78
79 struct {
80 ast_node *then_statement;
81 ast_node *else_statement;
82 } selection_rest_statement;
83 }
84
85 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
86 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
87 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
88 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
89 %token NOPERSPECTIVE FLAT SMOOTH
90 %token MAT2X2 MAT2X3 MAT2X4
91 %token MAT3X2 MAT3X3 MAT3X4
92 %token MAT4X2 MAT4X3 MAT4X4
93 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
94 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
95 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
96 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
97 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
98 %token STRUCT VOID_TOK WHILE
99 %token <identifier> IDENTIFIER
100 %token <real> FLOATCONSTANT
101 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
102 %token <identifier> FIELD_SELECTION
103 %token LEFT_OP RIGHT_OP
104 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
105 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
106 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
107 %token SUB_ASSIGN
108 %token INVARIANT
109 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
110
111 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
112 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
113 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
114 %token LAYOUT_TOK
115
116 /* Reserved words that are not actually used in the grammar.
117 */
118 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
119 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
120 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
121 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
122 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
123 %token SIZEOF CAST NAMESPACE USING
124
125 %token ERROR_TOK
126
127 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
128 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
129 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
130 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
131 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
132 %token ROW_MAJOR
133
134 %type <identifier> variable_identifier
135 %type <node> statement
136 %type <node> statement_list
137 %type <node> simple_statement
138 %type <n> precision_qualifier
139 %type <type_qualifier> type_qualifier
140 %type <type_qualifier> storage_qualifier
141 %type <type_qualifier> interpolation_qualifier
142 %type <type_qualifier> layout_qualifier
143 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
144 %type <type_specifier> type_specifier
145 %type <type_specifier> type_specifier_no_prec
146 %type <type_specifier> type_specifier_nonarray
147 %type <n> basic_type_specifier_nonarray
148 %type <fully_specified_type> fully_specified_type
149 %type <function> function_prototype
150 %type <function> function_header
151 %type <function> function_header_with_parameters
152 %type <function> function_declarator
153 %type <parameter_declarator> parameter_declarator
154 %type <parameter_declarator> parameter_declaration
155 %type <type_qualifier> parameter_qualifier
156 %type <type_qualifier> parameter_type_qualifier
157 %type <type_specifier> parameter_type_specifier
158 %type <function_definition> function_definition
159 %type <compound_statement> compound_statement_no_new_scope
160 %type <compound_statement> compound_statement
161 %type <node> statement_no_new_scope
162 %type <node> expression_statement
163 %type <expression> expression
164 %type <expression> primary_expression
165 %type <expression> assignment_expression
166 %type <expression> conditional_expression
167 %type <expression> logical_or_expression
168 %type <expression> logical_xor_expression
169 %type <expression> logical_and_expression
170 %type <expression> inclusive_or_expression
171 %type <expression> exclusive_or_expression
172 %type <expression> and_expression
173 %type <expression> equality_expression
174 %type <expression> relational_expression
175 %type <expression> shift_expression
176 %type <expression> additive_expression
177 %type <expression> multiplicative_expression
178 %type <expression> unary_expression
179 %type <expression> constant_expression
180 %type <expression> integer_expression
181 %type <expression> postfix_expression
182 %type <expression> function_call_header_with_parameters
183 %type <expression> function_call_header_no_parameters
184 %type <expression> function_call_header
185 %type <expression> function_call_generic
186 %type <expression> function_call_or_method
187 %type <expression> function_call
188 %type <n> assignment_operator
189 %type <n> unary_operator
190 %type <expression> function_identifier
191 %type <node> external_declaration
192 %type <declarator_list> init_declarator_list
193 %type <declarator_list> single_declaration
194 %type <expression> initializer
195 %type <node> declaration
196 %type <node> declaration_statement
197 %type <node> jump_statement
198 %type <struct_specifier> struct_specifier
199 %type <node> struct_declaration_list
200 %type <declarator_list> struct_declaration
201 %type <declaration> struct_declarator
202 %type <declaration> struct_declarator_list
203 %type <node> selection_statement
204 %type <selection_rest_statement> selection_rest_statement
205 %type <node> iteration_statement
206 %type <node> condition
207 %type <node> conditionopt
208 %type <node> for_init_statement
209 %type <for_rest_statement> for_rest_statement
210 %%
211
212 translation_unit:
213 version_statement extension_statement_list
214 {
215 _mesa_glsl_initialize_types(state);
216 }
217 external_declaration_list
218 ;
219
220 version_statement:
221 /* blank - no #version specified: defaults are already set */
222 | VERSION INTCONSTANT EOL
223 {
224 switch ($2) {
225 case 100:
226 state->es_shader = true;
227 case 110:
228 case 120:
229 case 130:
230 /* FINISHME: Check against implementation support versions. */
231 state->language_version = $2;
232 break;
233 default:
234 _mesa_glsl_error(& @2, state, "Shading language version"
235 "%u is not supported\n", $2);
236 break;
237 }
238 }
239 ;
240
241 pragma_statement:
242 PRAGMA_DEBUG_ON EOL
243 | PRAGMA_DEBUG_OFF EOL
244 | PRAGMA_OPTIMIZE_ON EOL
245 | PRAGMA_OPTIMIZE_OFF EOL
246 ;
247
248 extension_statement_list:
249
250 | extension_statement_list extension_statement
251 ;
252
253 extension_statement:
254 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
255 {
256 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
257 YYERROR;
258 }
259 }
260 ;
261
262 external_declaration_list:
263 external_declaration
264 {
265 /* FINISHME: The NULL test is only required because 'precision'
266 * FINISHME: statements are not yet supported.
267 */
268 if ($1 != NULL)
269 state->translation_unit.push_tail(& $1->link);
270 }
271 | external_declaration_list external_declaration
272 {
273 /* FINISHME: The NULL test is only required because 'precision'
274 * FINISHME: statements are not yet supported.
275 */
276 if ($2 != NULL)
277 state->translation_unit.push_tail(& $2->link);
278 }
279 ;
280
281 variable_identifier:
282 IDENTIFIER
283 ;
284
285 primary_expression:
286 variable_identifier
287 {
288 void *ctx = state;
289 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
290 $$->set_location(yylloc);
291 $$->primary_expression.identifier = $1;
292 }
293 | INTCONSTANT
294 {
295 void *ctx = state;
296 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
297 $$->set_location(yylloc);
298 $$->primary_expression.int_constant = $1;
299 }
300 | UINTCONSTANT
301 {
302 void *ctx = state;
303 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
304 $$->set_location(yylloc);
305 $$->primary_expression.uint_constant = $1;
306 }
307 | FLOATCONSTANT
308 {
309 void *ctx = state;
310 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
311 $$->set_location(yylloc);
312 $$->primary_expression.float_constant = $1;
313 }
314 | BOOLCONSTANT
315 {
316 void *ctx = state;
317 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
318 $$->set_location(yylloc);
319 $$->primary_expression.bool_constant = $1;
320 }
321 | '(' expression ')'
322 {
323 $$ = $2;
324 }
325 ;
326
327 postfix_expression:
328 primary_expression
329 | postfix_expression '[' integer_expression ']'
330 {
331 void *ctx = state;
332 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
333 $$->set_location(yylloc);
334 }
335 | function_call
336 {
337 $$ = $1;
338 }
339 | postfix_expression '.' IDENTIFIER
340 {
341 void *ctx = state;
342 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
343 $$->set_location(yylloc);
344 $$->primary_expression.identifier = $3;
345 }
346 | postfix_expression INC_OP
347 {
348 void *ctx = state;
349 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
350 $$->set_location(yylloc);
351 }
352 | postfix_expression DEC_OP
353 {
354 void *ctx = state;
355 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
356 $$->set_location(yylloc);
357 }
358 ;
359
360 integer_expression:
361 expression
362 ;
363
364 function_call:
365 function_call_or_method
366 ;
367
368 function_call_or_method:
369 function_call_generic
370 | postfix_expression '.' function_call_generic
371 {
372 void *ctx = state;
373 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
374 $$->set_location(yylloc);
375 }
376 ;
377
378 function_call_generic:
379 function_call_header_with_parameters ')'
380 | function_call_header_no_parameters ')'
381 ;
382
383 function_call_header_no_parameters:
384 function_call_header VOID_TOK
385 | function_call_header
386 ;
387
388 function_call_header_with_parameters:
389 function_call_header assignment_expression
390 {
391 $$ = $1;
392 $$->set_location(yylloc);
393 $$->expressions.push_tail(& $2->link);
394 }
395 | function_call_header_with_parameters ',' assignment_expression
396 {
397 $$ = $1;
398 $$->set_location(yylloc);
399 $$->expressions.push_tail(& $3->link);
400 }
401 ;
402
403 // Grammar Note: Constructors look like functions, but lexical
404 // analysis recognized most of them as keywords. They are now
405 // recognized through "type_specifier".
406 function_call_header:
407 function_identifier '('
408 ;
409
410 function_identifier:
411 type_specifier
412 {
413 void *ctx = state;
414 $$ = new(ctx) ast_function_expression($1);
415 $$->set_location(yylloc);
416 }
417 | IDENTIFIER
418 {
419 void *ctx = state;
420 ast_expression *callee = new(ctx) ast_expression($1);
421 $$ = new(ctx) ast_function_expression(callee);
422 $$->set_location(yylloc);
423 }
424 | FIELD_SELECTION
425 {
426 void *ctx = state;
427 ast_expression *callee = new(ctx) ast_expression($1);
428 $$ = new(ctx) ast_function_expression(callee);
429 $$->set_location(yylloc);
430 }
431 ;
432
433 // Grammar Note: No traditional style type casts.
434 unary_expression:
435 postfix_expression
436 | INC_OP unary_expression
437 {
438 void *ctx = state;
439 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
440 $$->set_location(yylloc);
441 }
442 | DEC_OP unary_expression
443 {
444 void *ctx = state;
445 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
446 $$->set_location(yylloc);
447 }
448 | unary_operator unary_expression
449 {
450 void *ctx = state;
451 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
452 $$->set_location(yylloc);
453 }
454 ;
455
456 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
457 unary_operator:
458 '+' { $$ = ast_plus; }
459 | '-' { $$ = ast_neg; }
460 | '!' { $$ = ast_logic_not; }
461 | '~' { $$ = ast_bit_not; }
462 ;
463
464 multiplicative_expression:
465 unary_expression
466 | multiplicative_expression '*' unary_expression
467 {
468 void *ctx = state;
469 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
470 $$->set_location(yylloc);
471 }
472 | multiplicative_expression '/' unary_expression
473 {
474 void *ctx = state;
475 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
476 $$->set_location(yylloc);
477 }
478 | multiplicative_expression '%' unary_expression
479 {
480 void *ctx = state;
481 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
482 $$->set_location(yylloc);
483 }
484 ;
485
486 additive_expression:
487 multiplicative_expression
488 | additive_expression '+' multiplicative_expression
489 {
490 void *ctx = state;
491 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
492 $$->set_location(yylloc);
493 }
494 | additive_expression '-' multiplicative_expression
495 {
496 void *ctx = state;
497 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
498 $$->set_location(yylloc);
499 }
500 ;
501
502 shift_expression:
503 additive_expression
504 | shift_expression LEFT_OP additive_expression
505 {
506 void *ctx = state;
507 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
508 $$->set_location(yylloc);
509 }
510 | shift_expression RIGHT_OP additive_expression
511 {
512 void *ctx = state;
513 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
514 $$->set_location(yylloc);
515 }
516 ;
517
518 relational_expression:
519 shift_expression
520 | relational_expression '<' shift_expression
521 {
522 void *ctx = state;
523 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
524 $$->set_location(yylloc);
525 }
526 | relational_expression '>' shift_expression
527 {
528 void *ctx = state;
529 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
530 $$->set_location(yylloc);
531 }
532 | relational_expression LE_OP shift_expression
533 {
534 void *ctx = state;
535 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
536 $$->set_location(yylloc);
537 }
538 | relational_expression GE_OP shift_expression
539 {
540 void *ctx = state;
541 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
542 $$->set_location(yylloc);
543 }
544 ;
545
546 equality_expression:
547 relational_expression
548 | equality_expression EQ_OP relational_expression
549 {
550 void *ctx = state;
551 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
552 $$->set_location(yylloc);
553 }
554 | equality_expression NE_OP relational_expression
555 {
556 void *ctx = state;
557 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
558 $$->set_location(yylloc);
559 }
560 ;
561
562 and_expression:
563 equality_expression
564 | and_expression '&' equality_expression
565 {
566 void *ctx = state;
567 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
568 $$->set_location(yylloc);
569 }
570 ;
571
572 exclusive_or_expression:
573 and_expression
574 | exclusive_or_expression '^' and_expression
575 {
576 void *ctx = state;
577 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
578 $$->set_location(yylloc);
579 }
580 ;
581
582 inclusive_or_expression:
583 exclusive_or_expression
584 | inclusive_or_expression '|' exclusive_or_expression
585 {
586 void *ctx = state;
587 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
588 $$->set_location(yylloc);
589 }
590 ;
591
592 logical_and_expression:
593 inclusive_or_expression
594 | logical_and_expression AND_OP inclusive_or_expression
595 {
596 void *ctx = state;
597 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
598 $$->set_location(yylloc);
599 }
600 ;
601
602 logical_xor_expression:
603 logical_and_expression
604 | logical_xor_expression XOR_OP logical_and_expression
605 {
606 void *ctx = state;
607 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
608 $$->set_location(yylloc);
609 }
610 ;
611
612 logical_or_expression:
613 logical_xor_expression
614 | logical_or_expression OR_OP logical_xor_expression
615 {
616 void *ctx = state;
617 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
618 $$->set_location(yylloc);
619 }
620 ;
621
622 conditional_expression:
623 logical_or_expression
624 | logical_or_expression '?' expression ':' assignment_expression
625 {
626 void *ctx = state;
627 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
628 $$->set_location(yylloc);
629 }
630 ;
631
632 assignment_expression:
633 conditional_expression
634 | unary_expression assignment_operator assignment_expression
635 {
636 void *ctx = state;
637 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
638 $$->set_location(yylloc);
639 }
640 ;
641
642 assignment_operator:
643 '=' { $$ = ast_assign; }
644 | MUL_ASSIGN { $$ = ast_mul_assign; }
645 | DIV_ASSIGN { $$ = ast_div_assign; }
646 | MOD_ASSIGN { $$ = ast_mod_assign; }
647 | ADD_ASSIGN { $$ = ast_add_assign; }
648 | SUB_ASSIGN { $$ = ast_sub_assign; }
649 | LEFT_ASSIGN { $$ = ast_ls_assign; }
650 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
651 | AND_ASSIGN { $$ = ast_and_assign; }
652 | XOR_ASSIGN { $$ = ast_xor_assign; }
653 | OR_ASSIGN { $$ = ast_or_assign; }
654 ;
655
656 expression:
657 assignment_expression
658 {
659 $$ = $1;
660 }
661 | expression ',' assignment_expression
662 {
663 void *ctx = state;
664 if ($1->oper != ast_sequence) {
665 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
666 $$->set_location(yylloc);
667 $$->expressions.push_tail(& $1->link);
668 } else {
669 $$ = $1;
670 }
671
672 $$->expressions.push_tail(& $3->link);
673 }
674 ;
675
676 constant_expression:
677 conditional_expression
678 ;
679
680 declaration:
681 function_prototype ';'
682 {
683 $$ = $1;
684 }
685 | init_declarator_list ';'
686 {
687 $$ = $1;
688 }
689 | PRECISION precision_qualifier type_specifier_no_prec ';'
690 {
691 if (($3->type_specifier != ast_float)
692 && ($3->type_specifier != ast_int)) {
693 _mesa_glsl_error(& @3, state, "global precision qualifier can "
694 "only be applied to `int' or `float'\n");
695 YYERROR;
696 }
697
698 $$ = NULL; /* FINISHME */
699 }
700 ;
701
702 function_prototype:
703 function_declarator ')'
704 ;
705
706 function_declarator:
707 function_header
708 | function_header_with_parameters
709 ;
710
711 function_header_with_parameters:
712 function_header parameter_declaration
713 {
714 $$ = $1;
715 $$->parameters.push_tail(& $2->link);
716 }
717 | function_header_with_parameters ',' parameter_declaration
718 {
719 $$ = $1;
720 $$->parameters.push_tail(& $3->link);
721 }
722 ;
723
724 function_header:
725 fully_specified_type IDENTIFIER '('
726 {
727 void *ctx = state;
728 $$ = new(ctx) ast_function();
729 $$->set_location(yylloc);
730 $$->return_type = $1;
731 $$->identifier = $2;
732 }
733 ;
734
735 parameter_declarator:
736 type_specifier IDENTIFIER
737 {
738 void *ctx = state;
739 $$ = new(ctx) ast_parameter_declarator();
740 $$->set_location(yylloc);
741 $$->type = new(ctx) ast_fully_specified_type();
742 $$->type->set_location(yylloc);
743 $$->type->specifier = $1;
744 $$->identifier = $2;
745 }
746 | type_specifier IDENTIFIER '[' constant_expression ']'
747 {
748 void *ctx = state;
749 $$ = new(ctx) ast_parameter_declarator();
750 $$->set_location(yylloc);
751 $$->type = new(ctx) ast_fully_specified_type();
752 $$->type->set_location(yylloc);
753 $$->type->specifier = $1;
754 $$->identifier = $2;
755 $$->is_array = true;
756 $$->array_size = $4;
757 }
758 ;
759
760 parameter_declaration:
761 parameter_type_qualifier parameter_qualifier parameter_declarator
762 {
763 $1.i |= $2.i;
764
765 $$ = $3;
766 $$->type->qualifier = $1.q;
767 }
768 | parameter_qualifier parameter_declarator
769 {
770 $$ = $2;
771 $$->type->qualifier = $1.q;
772 }
773 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
774 {
775 void *ctx = state;
776 $1.i |= $2.i;
777
778 $$ = new(ctx) ast_parameter_declarator();
779 $$->set_location(yylloc);
780 $$->type = new(ctx) ast_fully_specified_type();
781 $$->type->qualifier = $1.q;
782 $$->type->specifier = $3;
783 }
784 | parameter_qualifier parameter_type_specifier
785 {
786 void *ctx = state;
787 $$ = new(ctx) ast_parameter_declarator();
788 $$->set_location(yylloc);
789 $$->type = new(ctx) ast_fully_specified_type();
790 $$->type->qualifier = $1.q;
791 $$->type->specifier = $2;
792 }
793 ;
794
795 parameter_qualifier:
796 /* empty */ { $$.i = 0; }
797 | IN_TOK { $$.i = 0; $$.q.in = 1; }
798 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
799 | INOUT_TOK { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
800 ;
801
802 parameter_type_specifier:
803 type_specifier
804 ;
805
806 init_declarator_list:
807 single_declaration
808 | init_declarator_list ',' IDENTIFIER
809 {
810 void *ctx = state;
811 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
812 decl->set_location(yylloc);
813
814 $$ = $1;
815 $$->declarations.push_tail(&decl->link);
816 }
817 | init_declarator_list ',' IDENTIFIER '[' ']'
818 {
819 void *ctx = state;
820 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
821 decl->set_location(yylloc);
822
823 $$ = $1;
824 $$->declarations.push_tail(&decl->link);
825 }
826 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
827 {
828 void *ctx = state;
829 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
830 decl->set_location(yylloc);
831
832 $$ = $1;
833 $$->declarations.push_tail(&decl->link);
834 }
835 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
836 {
837 void *ctx = state;
838 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
839 decl->set_location(yylloc);
840
841 $$ = $1;
842 $$->declarations.push_tail(&decl->link);
843 }
844 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
845 {
846 void *ctx = state;
847 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
848 decl->set_location(yylloc);
849
850 $$ = $1;
851 $$->declarations.push_tail(&decl->link);
852 }
853 | init_declarator_list ',' IDENTIFIER '=' initializer
854 {
855 void *ctx = state;
856 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
857 decl->set_location(yylloc);
858
859 $$ = $1;
860 $$->declarations.push_tail(&decl->link);
861 }
862 ;
863
864 // Grammar Note: No 'enum', or 'typedef'.
865 single_declaration:
866 fully_specified_type
867 {
868 void *ctx = state;
869 if ($1->specifier->type_specifier != ast_struct) {
870 _mesa_glsl_error(& @1, state, "empty declaration list\n");
871 YYERROR;
872 } else {
873 $$ = new(ctx) ast_declarator_list($1);
874 $$->set_location(yylloc);
875 }
876 }
877 | fully_specified_type IDENTIFIER
878 {
879 void *ctx = state;
880 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
881
882 $$ = new(ctx) ast_declarator_list($1);
883 $$->set_location(yylloc);
884 $$->declarations.push_tail(&decl->link);
885 }
886 | fully_specified_type IDENTIFIER '[' ']'
887 {
888 void *ctx = state;
889 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
890
891 $$ = new(ctx) ast_declarator_list($1);
892 $$->set_location(yylloc);
893 $$->declarations.push_tail(&decl->link);
894 }
895 | fully_specified_type IDENTIFIER '[' constant_expression ']'
896 {
897 void *ctx = state;
898 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
899
900 $$ = new(ctx) ast_declarator_list($1);
901 $$->set_location(yylloc);
902 $$->declarations.push_tail(&decl->link);
903 }
904 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
905 {
906 void *ctx = state;
907 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
908
909 $$ = new(ctx) ast_declarator_list($1);
910 $$->set_location(yylloc);
911 $$->declarations.push_tail(&decl->link);
912 }
913 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
914 {
915 void *ctx = state;
916 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
917
918 $$ = new(ctx) ast_declarator_list($1);
919 $$->set_location(yylloc);
920 $$->declarations.push_tail(&decl->link);
921 }
922 | fully_specified_type IDENTIFIER '=' initializer
923 {
924 void *ctx = state;
925 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
926
927 $$ = new(ctx) ast_declarator_list($1);
928 $$->set_location(yylloc);
929 $$->declarations.push_tail(&decl->link);
930 }
931 | INVARIANT IDENTIFIER // Vertex only.
932 {
933 void *ctx = state;
934 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
935
936 $$ = new(ctx) ast_declarator_list(NULL);
937 $$->set_location(yylloc);
938 $$->invariant = true;
939
940 $$->declarations.push_tail(&decl->link);
941 }
942 ;
943
944 fully_specified_type:
945 type_specifier
946 {
947 void *ctx = state;
948 $$ = new(ctx) ast_fully_specified_type();
949 $$->set_location(yylloc);
950 $$->specifier = $1;
951 }
952 | type_qualifier type_specifier
953 {
954 void *ctx = state;
955 $$ = new(ctx) ast_fully_specified_type();
956 $$->set_location(yylloc);
957 $$->qualifier = $1.q;
958 $$->specifier = $2;
959 }
960 ;
961
962 layout_qualifier:
963 LAYOUT_TOK '(' layout_qualifier_id_list ')'
964 {
965 $$ = $3;
966 }
967 ;
968
969 layout_qualifier_id_list:
970 layout_qualifier_id
971 | layout_qualifier_id_list ',' layout_qualifier_id
972 {
973 $$.i = $1.i | $3.i;
974 }
975 ;
976
977 layout_qualifier_id:
978 IDENTIFIER
979 {
980 bool got_one = false;
981
982 $$.i = 0;
983
984 if (state->ARB_fragment_coord_conventions_enable) {
985 if (strcmp($1, "origin_upper_left") == 0) {
986 got_one = true;
987 $$.q.origin_upper_left = 1;
988 } else if (strcmp($1, "pixel_center_integer") == 0) {
989 got_one = true;
990 $$.q.pixel_center_integer = 1;
991 }
992 }
993
994 /* If the identifier didn't match any known layout identifiers,
995 * emit an error.
996 */
997 if (!got_one) {
998 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
999 "`%s'\n", $1);
1000 YYERROR;
1001 } else if (state->ARB_fragment_coord_conventions_warn) {
1002 _mesa_glsl_warning(& @1, state,
1003 "GL_ARB_fragment_coord_conventions layout "
1004 "identifier `%s' used\n", $1);
1005 }
1006 }
1007 ;
1008
1009 interpolation_qualifier:
1010 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1011 | FLAT { $$.i = 0; $$.q.flat = 1; }
1012 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1013 ;
1014
1015 parameter_type_qualifier:
1016 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1017 ;
1018
1019 type_qualifier:
1020 storage_qualifier
1021 | layout_qualifier
1022 | layout_qualifier storage_qualifier
1023 {
1024 $$.i = $1.i | $2.i;
1025 }
1026 | interpolation_qualifier
1027 | interpolation_qualifier storage_qualifier
1028 {
1029 $$.i = $1.i | $2.i;
1030 }
1031 | INVARIANT storage_qualifier
1032 {
1033 $$ = $2;
1034 $$.q.invariant = 1;
1035 }
1036 | INVARIANT interpolation_qualifier storage_qualifier
1037 {
1038 $$.i = $2.i | $3.i;
1039 $$.q.invariant = 1;
1040 }
1041 | INVARIANT
1042 {
1043 $$.i = 0;
1044 $$.q.invariant = 1;
1045 }
1046 ;
1047
1048 storage_qualifier:
1049 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1050 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1051 | VARYING { $$.i = 0; $$.q.varying = 1; }
1052 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1053 | IN_TOK { $$.i = 0; $$.q.in = 1; }
1054 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
1055 | CENTROID IN_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1056 | CENTROID OUT_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1057 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1058 ;
1059
1060 type_specifier:
1061 type_specifier_no_prec
1062 | precision_qualifier type_specifier_no_prec
1063 {
1064 $$ = $2;
1065 $$->precision = $1;
1066 }
1067 ;
1068
1069 type_specifier_no_prec:
1070 type_specifier_nonarray
1071 | type_specifier_nonarray '[' ']'
1072 {
1073 $$ = $1;
1074 $$->is_array = true;
1075 $$->array_size = NULL;
1076 }
1077 | type_specifier_nonarray '[' constant_expression ']'
1078 {
1079 $$ = $1;
1080 $$->is_array = true;
1081 $$->array_size = $3;
1082 }
1083 ;
1084
1085 type_specifier_nonarray:
1086 basic_type_specifier_nonarray
1087 {
1088 void *ctx = state;
1089 $$ = new(ctx) ast_type_specifier($1);
1090 $$->set_location(yylloc);
1091 }
1092 | struct_specifier
1093 {
1094 void *ctx = state;
1095 $$ = new(ctx) ast_type_specifier($1);
1096 $$->set_location(yylloc);
1097 }
1098 | IDENTIFIER
1099 {
1100 void *ctx = state;
1101 $$ = new(ctx) ast_type_specifier($1);
1102 $$->set_location(yylloc);
1103 }
1104 ;
1105
1106 basic_type_specifier_nonarray:
1107 VOID_TOK { $$ = ast_void; }
1108 | FLOAT_TOK { $$ = ast_float; }
1109 | INT_TOK { $$ = ast_int; }
1110 | UINT_TOK { $$ = ast_uint; }
1111 | BOOL_TOK { $$ = ast_bool; }
1112 | VEC2 { $$ = ast_vec2; }
1113 | VEC3 { $$ = ast_vec3; }
1114 | VEC4 { $$ = ast_vec4; }
1115 | BVEC2 { $$ = ast_bvec2; }
1116 | BVEC3 { $$ = ast_bvec3; }
1117 | BVEC4 { $$ = ast_bvec4; }
1118 | IVEC2 { $$ = ast_ivec2; }
1119 | IVEC3 { $$ = ast_ivec3; }
1120 | IVEC4 { $$ = ast_ivec4; }
1121 | UVEC2 { $$ = ast_uvec2; }
1122 | UVEC3 { $$ = ast_uvec3; }
1123 | UVEC4 { $$ = ast_uvec4; }
1124 | MAT2X2 { $$ = ast_mat2; }
1125 | MAT2X3 { $$ = ast_mat2x3; }
1126 | MAT2X4 { $$ = ast_mat2x4; }
1127 | MAT3X2 { $$ = ast_mat3x2; }
1128 | MAT3X3 { $$ = ast_mat3; }
1129 | MAT3X4 { $$ = ast_mat3x4; }
1130 | MAT4X2 { $$ = ast_mat4x2; }
1131 | MAT4X3 { $$ = ast_mat4x3; }
1132 | MAT4X4 { $$ = ast_mat4; }
1133 | SAMPLER1D { $$ = ast_sampler1d; }
1134 | SAMPLER2D { $$ = ast_sampler2d; }
1135 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1136 | SAMPLER3D { $$ = ast_sampler3d; }
1137 | SAMPLERCUBE { $$ = ast_samplercube; }
1138 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1139 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1140 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1141 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1142 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1143 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1144 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1145 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1146 | ISAMPLER1D { $$ = ast_isampler1d; }
1147 | ISAMPLER2D { $$ = ast_isampler2d; }
1148 | ISAMPLER3D { $$ = ast_isampler3d; }
1149 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1150 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1151 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1152 | USAMPLER1D { $$ = ast_usampler1d; }
1153 | USAMPLER2D { $$ = ast_usampler2d; }
1154 | USAMPLER3D { $$ = ast_usampler3d; }
1155 | USAMPLERCUBE { $$ = ast_usamplercube; }
1156 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1157 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1158 ;
1159
1160 precision_qualifier:
1161 HIGHP {
1162 if (!state->es_shader && state->language_version < 130)
1163 _mesa_glsl_error(& @1, state,
1164 "precision qualifier forbidden "
1165 "in GLSL %d.%d (1.30 or later "
1166 "required)\n",
1167 state->language_version / 100,
1168 state->language_version % 100);
1169
1170 $$ = ast_precision_high;
1171 }
1172 | MEDIUMP {
1173 if (!state->es_shader && state->language_version < 130)
1174 _mesa_glsl_error(& @1, state,
1175 "precision qualifier forbidden "
1176 "in GLSL %d.%d (1.30 or later "
1177 "required)\n",
1178 state->language_version / 100,
1179 state->language_version % 100);
1180
1181 $$ = ast_precision_medium;
1182 }
1183 | LOWP {
1184 if (!state->es_shader && state->language_version < 130)
1185 _mesa_glsl_error(& @1, state,
1186 "precision qualifier forbidden "
1187 "in GLSL %d.%d (1.30 or later "
1188 "required)\n",
1189 state->language_version / 100,
1190 state->language_version % 100);
1191
1192 $$ = ast_precision_low;
1193 }
1194 ;
1195
1196 struct_specifier:
1197 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1198 {
1199 void *ctx = state;
1200 $$ = new(ctx) ast_struct_specifier($2, $4);
1201 $$->set_location(yylloc);
1202 }
1203 | STRUCT '{' struct_declaration_list '}'
1204 {
1205 void *ctx = state;
1206 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1207 $$->set_location(yylloc);
1208 }
1209 ;
1210
1211 struct_declaration_list:
1212 struct_declaration
1213 {
1214 $$ = (ast_node *) $1;
1215 $1->link.self_link();
1216 }
1217 | struct_declaration_list struct_declaration
1218 {
1219 $$ = (ast_node *) $1;
1220 $$->link.insert_before(& $2->link);
1221 }
1222 ;
1223
1224 struct_declaration:
1225 type_specifier struct_declarator_list ';'
1226 {
1227 void *ctx = state;
1228 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1229 type->set_location(yylloc);
1230
1231 type->specifier = $1;
1232 $$ = new(ctx) ast_declarator_list(type);
1233 $$->set_location(yylloc);
1234
1235 $$->declarations.push_degenerate_list_at_head(& $2->link);
1236 }
1237 ;
1238
1239 struct_declarator_list:
1240 struct_declarator
1241 {
1242 $$ = $1;
1243 $1->link.self_link();
1244 }
1245 | struct_declarator_list ',' struct_declarator
1246 {
1247 $$ = $1;
1248 $$->link.insert_before(& $3->link);
1249 }
1250 ;
1251
1252 struct_declarator:
1253 IDENTIFIER
1254 {
1255 void *ctx = state;
1256 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1257 $$->set_location(yylloc);
1258 }
1259 | IDENTIFIER '[' constant_expression ']'
1260 {
1261 void *ctx = state;
1262 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1263 $$->set_location(yylloc);
1264 }
1265 ;
1266
1267 initializer:
1268 assignment_expression
1269 ;
1270
1271 declaration_statement:
1272 declaration
1273 ;
1274
1275 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1276 // supported.
1277 statement:
1278 compound_statement { $$ = (ast_node *) $1; }
1279 | simple_statement
1280 ;
1281
1282 simple_statement:
1283 declaration_statement
1284 | expression_statement
1285 | selection_statement
1286 | switch_statement { $$ = NULL; }
1287 | case_label { $$ = NULL; }
1288 | iteration_statement
1289 | jump_statement
1290 ;
1291
1292 compound_statement:
1293 '{' '}'
1294 {
1295 void *ctx = state;
1296 $$ = new(ctx) ast_compound_statement(true, NULL);
1297 $$->set_location(yylloc);
1298 }
1299 | '{' statement_list '}'
1300 {
1301 void *ctx = state;
1302 $$ = new(ctx) ast_compound_statement(true, $2);
1303 $$->set_location(yylloc);
1304 }
1305 ;
1306
1307 statement_no_new_scope:
1308 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1309 | simple_statement
1310 ;
1311
1312 compound_statement_no_new_scope:
1313 '{' '}'
1314 {
1315 void *ctx = state;
1316 $$ = new(ctx) ast_compound_statement(false, NULL);
1317 $$->set_location(yylloc);
1318 }
1319 | '{' statement_list '}'
1320 {
1321 void *ctx = state;
1322 $$ = new(ctx) ast_compound_statement(false, $2);
1323 $$->set_location(yylloc);
1324 }
1325 ;
1326
1327 statement_list:
1328 statement
1329 {
1330 if ($1 == NULL) {
1331 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1332 assert($1 != NULL);
1333 }
1334
1335 $$ = $1;
1336 $$->link.self_link();
1337 }
1338 | statement_list statement
1339 {
1340 if ($2 == NULL) {
1341 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1342 assert($2 != NULL);
1343 }
1344 $$ = $1;
1345 $$->link.insert_before(& $2->link);
1346 }
1347 ;
1348
1349 expression_statement:
1350 ';'
1351 {
1352 void *ctx = state;
1353 $$ = new(ctx) ast_expression_statement(NULL);
1354 $$->set_location(yylloc);
1355 }
1356 | expression ';'
1357 {
1358 void *ctx = state;
1359 $$ = new(ctx) ast_expression_statement($1);
1360 $$->set_location(yylloc);
1361 }
1362 ;
1363
1364 selection_statement:
1365 IF '(' expression ')' selection_rest_statement
1366 {
1367 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1368 $5.else_statement);
1369 $$->set_location(yylloc);
1370 }
1371 ;
1372
1373 selection_rest_statement:
1374 statement ELSE statement
1375 {
1376 $$.then_statement = $1;
1377 $$.else_statement = $3;
1378 }
1379 | statement
1380 {
1381 $$.then_statement = $1;
1382 $$.else_statement = NULL;
1383 }
1384 ;
1385
1386 condition:
1387 expression
1388 {
1389 $$ = (ast_node *) $1;
1390 }
1391 | fully_specified_type IDENTIFIER '=' initializer
1392 {
1393 void *ctx = state;
1394 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1395 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1396 decl->set_location(yylloc);
1397 declarator->set_location(yylloc);
1398
1399 declarator->declarations.push_tail(&decl->link);
1400 $$ = declarator;
1401 }
1402 ;
1403
1404 switch_statement:
1405 SWITCH '(' expression ')' compound_statement
1406 ;
1407
1408 case_label:
1409 CASE expression ':'
1410 | DEFAULT ':'
1411 ;
1412
1413 iteration_statement:
1414 WHILE '(' condition ')' statement_no_new_scope
1415 {
1416 void *ctx = state;
1417 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1418 NULL, $3, NULL, $5);
1419 $$->set_location(yylloc);
1420 }
1421 | DO statement WHILE '(' expression ')' ';'
1422 {
1423 void *ctx = state;
1424 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1425 NULL, $5, NULL, $2);
1426 $$->set_location(yylloc);
1427 }
1428 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1429 {
1430 void *ctx = state;
1431 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1432 $3, $4.cond, $4.rest, $6);
1433 $$->set_location(yylloc);
1434 }
1435 ;
1436
1437 for_init_statement:
1438 expression_statement
1439 | declaration_statement
1440 ;
1441
1442 conditionopt:
1443 condition
1444 | /* empty */
1445 {
1446 $$ = NULL;
1447 }
1448 ;
1449
1450 for_rest_statement:
1451 conditionopt ';'
1452 {
1453 $$.cond = $1;
1454 $$.rest = NULL;
1455 }
1456 | conditionopt ';' expression
1457 {
1458 $$.cond = $1;
1459 $$.rest = $3;
1460 }
1461 ;
1462
1463 // Grammar Note: No 'goto'. Gotos are not supported.
1464 jump_statement:
1465 CONTINUE ';'
1466 {
1467 void *ctx = state;
1468 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1469 $$->set_location(yylloc);
1470 }
1471 | BREAK ';'
1472 {
1473 void *ctx = state;
1474 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1475 $$->set_location(yylloc);
1476 }
1477 | RETURN ';'
1478 {
1479 void *ctx = state;
1480 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1481 $$->set_location(yylloc);
1482 }
1483 | RETURN expression ';'
1484 {
1485 void *ctx = state;
1486 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1487 $$->set_location(yylloc);
1488 }
1489 | DISCARD ';' // Fragment shader only.
1490 {
1491 void *ctx = state;
1492 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1493 $$->set_location(yylloc);
1494 }
1495 ;
1496
1497 external_declaration:
1498 function_definition { $$ = $1; }
1499 | declaration { $$ = $1; }
1500 | pragma_statement { $$ = NULL; }
1501 ;
1502
1503 function_definition:
1504 function_prototype compound_statement_no_new_scope
1505 {
1506 void *ctx = state;
1507 $$ = new(ctx) ast_function_definition();
1508 $$->set_location(yylloc);
1509 $$->prototype = $1;
1510 $$->body = $2;
1511 }
1512 ;