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