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