3 * Copyright © 2008, 2009 Intel Corporation
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:
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
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.
30 #include "glsl_parser_extras.h"
31 #include "glsl_types.h"
33 #define YYLEX_PARAM state->scanner
41 %lex-param {void *scanner}
42 %parse-param {struct _mesa_glsl_parse_state *state}
43 %name-prefix "_mesa_glsl_"
51 struct ast_type_qualifier q;
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;
68 struct ast_node *cond;
69 struct ast_expression *rest;
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
97 %token HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
99 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
101 /* Reserved words that are not actually used in the grammar.
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 LOWP MEDIUMP HIGHP
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
191 _mesa_glsl_initialize_types(state);
193 extension_statement_list external_declaration_list
196 state->language_version = 110;
197 _mesa_glsl_initialize_types(state);
199 extension_statement_list external_declaration_list
203 VERSION INTCONSTANT EOL
209 /* FINISHME: Check against implementation support versions. */
210 state->language_version = $2;
213 _mesa_glsl_error(& @2, state, "Shading language version"
214 "%u is not supported\n", $2);
220 extension_statement_list:
222 | extension_statement_list extension_statement
226 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
228 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
234 external_declaration_list:
237 insert_at_tail(& state->translation_unit,
238 (struct simple_node *) $1);
240 | external_declaration_list external_declaration
242 insert_at_tail(& state->translation_unit,
243 (struct simple_node *) $2);
254 $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
255 $$->set_location(yylloc);
256 $$->primary_expression.identifier = $1;
260 $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
261 $$->set_location(yylloc);
262 $$->primary_expression.int_constant = $1;
266 $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
267 $$->set_location(yylloc);
268 $$->primary_expression.uint_constant = $1;
272 $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
273 $$->set_location(yylloc);
274 $$->primary_expression.float_constant = $1;
278 $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
279 $$->set_location(yylloc);
280 $$->primary_expression.bool_constant = $1;
290 | postfix_expression '[' integer_expression ']'
292 $$ = new ast_expression(ast_array_index, $1, $3, NULL);
293 $$->set_location(yylloc);
299 | postfix_expression '.' IDENTIFIER
301 $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
302 $$->set_location(yylloc);
303 $$->primary_expression.identifier = $3;
305 | postfix_expression INC_OP
307 $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
308 $$->set_location(yylloc);
310 | postfix_expression DEC_OP
312 $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
313 $$->set_location(yylloc);
322 function_call_or_method
325 function_call_or_method:
326 function_call_generic
327 | postfix_expression '.' function_call_generic
329 $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
330 $$->set_location(yylloc);
334 function_call_generic:
335 function_call_header_with_parameters ')'
336 | function_call_header_no_parameters ')'
339 function_call_header_no_parameters:
340 function_call_header VOID
341 | function_call_header
344 function_call_header_with_parameters:
345 function_call_header assignment_expression
348 $$->set_location(yylloc);
349 $$->subexpressions[1] = $2;
351 | function_call_header_with_parameters ',' assignment_expression
354 $$->set_location(yylloc);
355 insert_at_tail((struct simple_node *) $$->subexpressions[1],
356 (struct simple_node *) $3);
360 // Grammar Note: Constructors look like functions, but lexical
361 // analysis recognized most of them as keywords. They are now
362 // recognized through "type_specifier".
363 function_call_header:
364 function_identifier '('
370 $$ = new ast_function_expression($1);
371 $$->set_location(yylloc);
375 ast_expression *callee = new ast_expression($1);
376 $$ = new ast_function_expression(callee);
377 $$->set_location(yylloc);
381 ast_expression *callee = new ast_expression($1);
382 $$ = new ast_function_expression(callee);
383 $$->set_location(yylloc);
387 // Grammar Note: No traditional style type casts.
390 | INC_OP unary_expression
392 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
393 $$->set_location(yylloc);
395 | DEC_OP unary_expression
397 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
398 $$->set_location(yylloc);
400 | unary_operator unary_expression
402 $$ = new ast_expression($1, $2, NULL, NULL);
403 $$->set_location(yylloc);
407 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
409 '+' { $$ = ast_plus; }
410 | '-' { $$ = ast_neg; }
411 | '!' { $$ = ast_logic_not; }
412 | '~' { $$ = ast_bit_not; }
415 multiplicative_expression:
417 | multiplicative_expression '*' unary_expression
419 $$ = new ast_expression_bin(ast_mul, $1, $3);
420 $$->set_location(yylloc);
422 | multiplicative_expression '/' unary_expression
424 $$ = new ast_expression_bin(ast_div, $1, $3);
425 $$->set_location(yylloc);
427 | multiplicative_expression '%' unary_expression
429 $$ = new ast_expression_bin(ast_mod, $1, $3);
430 $$->set_location(yylloc);
435 multiplicative_expression
436 | additive_expression '+' multiplicative_expression
438 $$ = new ast_expression_bin(ast_add, $1, $3);
439 $$->set_location(yylloc);
441 | additive_expression '-' multiplicative_expression
443 $$ = new ast_expression_bin(ast_sub, $1, $3);
444 $$->set_location(yylloc);
450 | shift_expression LEFT_OP additive_expression
452 $$ = new ast_expression_bin(ast_lshift, $1, $3);
453 $$->set_location(yylloc);
455 | shift_expression RIGHT_OP additive_expression
457 $$ = new ast_expression_bin(ast_rshift, $1, $3);
458 $$->set_location(yylloc);
462 relational_expression:
464 | relational_expression '<' shift_expression
466 $$ = new ast_expression_bin(ast_less, $1, $3);
467 $$->set_location(yylloc);
469 | relational_expression '>' shift_expression
471 $$ = new ast_expression_bin(ast_greater, $1, $3);
472 $$->set_location(yylloc);
474 | relational_expression LE_OP shift_expression
476 $$ = new ast_expression_bin(ast_lequal, $1, $3);
477 $$->set_location(yylloc);
479 | relational_expression GE_OP shift_expression
481 $$ = new ast_expression_bin(ast_gequal, $1, $3);
482 $$->set_location(yylloc);
487 relational_expression
488 | equality_expression EQ_OP relational_expression
490 $$ = new ast_expression_bin(ast_equal, $1, $3);
491 $$->set_location(yylloc);
493 | equality_expression NE_OP relational_expression
495 $$ = new ast_expression_bin(ast_nequal, $1, $3);
496 $$->set_location(yylloc);
502 | and_expression '&' equality_expression
504 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
505 $$->set_location(yylloc);
509 exclusive_or_expression:
511 | exclusive_or_expression '^' and_expression
513 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
514 $$->set_location(yylloc);
518 inclusive_or_expression:
519 exclusive_or_expression
520 | inclusive_or_expression '|' exclusive_or_expression
522 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
523 $$->set_location(yylloc);
527 logical_and_expression:
528 inclusive_or_expression
529 | logical_and_expression AND_OP inclusive_or_expression
531 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
532 $$->set_location(yylloc);
536 logical_xor_expression:
537 logical_and_expression
538 | logical_xor_expression XOR_OP logical_and_expression
540 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
541 $$->set_location(yylloc);
545 logical_or_expression:
546 logical_xor_expression
547 | logical_or_expression OR_OP logical_xor_expression
549 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
550 $$->set_location(yylloc);
554 conditional_expression:
555 logical_or_expression
556 | logical_or_expression '?' expression ':' assignment_expression
558 $$ = new ast_expression(ast_conditional, $1, $3, $5);
559 $$->set_location(yylloc);
563 assignment_expression:
564 conditional_expression
565 | unary_expression assignment_operator assignment_expression
567 $$ = new ast_expression($2, $1, $3, NULL);
568 $$->set_location(yylloc);
573 '=' { $$ = ast_assign; }
574 | MUL_ASSIGN { $$ = ast_mul_assign; }
575 | DIV_ASSIGN { $$ = ast_div_assign; }
576 | MOD_ASSIGN { $$ = ast_mod_assign; }
577 | ADD_ASSIGN { $$ = ast_add_assign; }
578 | SUB_ASSIGN { $$ = ast_sub_assign; }
579 | LEFT_ASSIGN { $$ = ast_ls_assign; }
580 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
581 | AND_ASSIGN { $$ = ast_and_assign; }
582 | XOR_ASSIGN { $$ = ast_xor_assign; }
583 | OR_ASSIGN { $$ = ast_or_assign; }
587 assignment_expression
591 | expression ',' assignment_expression
593 if ($1->oper != ast_sequence) {
594 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
595 $$->set_location(yylloc);
596 insert_at_tail(& $$->expressions, $1);
601 insert_at_tail(& $$->expressions, $3);
606 conditional_expression
610 function_prototype ';'
614 | init_declarator_list ';'
618 | PRECISION precision_qualifier type_specifier_no_prec ';'
620 $$ = NULL; /* FINISHME */
625 function_declarator ')'
630 | function_header_with_parameters
633 function_header_with_parameters:
634 function_header parameter_declaration
637 insert_at_tail(& $$->parameters,
638 (struct simple_node *) $2);
640 | function_header_with_parameters ',' parameter_declaration
643 insert_at_tail(& $$->parameters,
644 (struct simple_node *) $3);
649 fully_specified_type IDENTIFIER '('
651 $$ = new ast_function();
652 $$->set_location(yylloc);
653 $$->return_type = $1;
658 parameter_declarator:
659 type_specifier IDENTIFIER
661 $$ = new ast_parameter_declarator();
662 $$->set_location(yylloc);
663 $$->type = new ast_fully_specified_type();
664 $$->type->set_location(yylloc);
665 $$->type->specifier = $1;
668 | type_specifier IDENTIFIER '[' constant_expression ']'
670 $$ = new ast_parameter_declarator();
671 $$->set_location(yylloc);
672 $$->type = new ast_fully_specified_type();
673 $$->type->set_location(yylloc);
674 $$->type->specifier = $1;
681 parameter_declaration:
682 parameter_type_qualifier parameter_qualifier parameter_declarator
687 $$->type->qualifier = $1.q;
689 | parameter_qualifier parameter_declarator
692 $$->type->qualifier = $1.q;
694 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
698 $$ = new ast_parameter_declarator();
699 $$->set_location(yylloc);
700 $$->type = new ast_fully_specified_type();
701 $$->type->qualifier = $1.q;
702 $$->type->specifier = $3;
704 | parameter_qualifier parameter_type_specifier
706 $$ = new ast_parameter_declarator();
707 $$->set_location(yylloc);
708 $$->type = new ast_fully_specified_type();
709 $$->type->qualifier = $1.q;
710 $$->type->specifier = $2;
715 /* empty */ { $$.i = 0; }
716 | IN { $$.i = 0; $$.q.in = 1; }
717 | OUT { $$.i = 0; $$.q.out = 1; }
718 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
721 parameter_type_specifier:
725 init_declarator_list:
727 | init_declarator_list ',' IDENTIFIER
729 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
730 decl->set_location(yylloc);
733 insert_at_tail(& $$->declarations,
734 (struct simple_node *) decl);
736 | init_declarator_list ',' IDENTIFIER '[' ']'
738 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
739 decl->set_location(yylloc);
742 insert_at_tail(& $$->declarations,
743 (struct simple_node *) decl);
745 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
747 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
748 decl->set_location(yylloc);
751 insert_at_tail(& $$->declarations,
752 (struct simple_node *) decl);
754 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
756 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
757 decl->set_location(yylloc);
760 insert_at_tail(& $$->declarations,
761 (struct simple_node *) decl);
763 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
765 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
766 decl->set_location(yylloc);
769 insert_at_tail(& $$->declarations,
770 (struct simple_node *) decl);
772 | init_declarator_list ',' IDENTIFIER '=' initializer
774 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
775 decl->set_location(yylloc);
778 insert_at_tail(& $$->declarations,
779 (struct simple_node *) decl);
783 // Grammar Note: No 'enum', or 'typedef'.
787 $$ = new ast_declarator_list($1);
788 $$->set_location(yylloc);
790 | fully_specified_type IDENTIFIER
792 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
794 $$ = new ast_declarator_list($1);
795 $$->set_location(yylloc);
796 insert_at_tail(& $$->declarations,
797 (struct simple_node *) decl);
799 | fully_specified_type IDENTIFIER '[' ']'
801 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
803 $$ = new ast_declarator_list($1);
804 $$->set_location(yylloc);
805 insert_at_tail(& $$->declarations,
806 (struct simple_node *) decl);
808 | fully_specified_type IDENTIFIER '[' constant_expression ']'
810 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
812 $$ = new ast_declarator_list($1);
813 $$->set_location(yylloc);
814 insert_at_tail(& $$->declarations,
815 (struct simple_node *) decl);
817 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
819 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
821 $$ = new ast_declarator_list($1);
822 $$->set_location(yylloc);
823 insert_at_tail(& $$->declarations,
824 (struct simple_node *) decl);
826 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
828 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
830 $$ = new ast_declarator_list($1);
831 $$->set_location(yylloc);
832 insert_at_tail(& $$->declarations,
833 (struct simple_node *) decl);
835 | fully_specified_type IDENTIFIER '=' initializer
837 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
839 $$ = new ast_declarator_list($1);
840 $$->set_location(yylloc);
841 insert_at_tail(& $$->declarations,
842 (struct simple_node *) decl);
844 | INVARIANT IDENTIFIER // Vertex only.
846 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
848 $$ = new ast_declarator_list(NULL);
849 $$->set_location(yylloc);
850 $$->invariant = true;
852 insert_at_tail(& $$->declarations,
853 (struct simple_node *) decl);
857 fully_specified_type:
860 $$ = new ast_fully_specified_type();
861 $$->set_location(yylloc);
864 | type_qualifier type_specifier
866 $$ = new ast_fully_specified_type();
867 $$->set_location(yylloc);
868 $$->qualifier = $1.q;
873 interpolation_qualifier:
874 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
875 | FLAT { $$.i = 0; $$.q.flat = 1; }
876 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
879 parameter_type_qualifier:
880 CONST { $$.i = 0; $$.q.constant = 1; }
885 | interpolation_qualifier type_qualifier
889 | INVARIANT type_qualifier
897 CONST { $$.i = 0; $$.q.constant = 1; }
898 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
899 | VARYING { $$.i = 0; $$.q.varying = 1; }
900 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
901 | IN { $$.i = 0; $$.q.in = 1; }
902 | OUT { $$.i = 0; $$.q.out = 1; }
903 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
904 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
905 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
909 type_specifier_no_prec
910 | precision_qualifier type_specifier_no_prec
917 type_specifier_no_prec:
918 type_specifier_nonarray
919 | type_specifier_nonarray '[' ']'
923 $$->array_size = NULL;
925 | type_specifier_nonarray '[' constant_expression ']'
933 type_specifier_nonarray:
934 basic_type_specifier_nonarray
936 $$ = new ast_type_specifier($1);
937 $$->set_location(yylloc);
941 $$ = new ast_type_specifier($1);
942 $$->set_location(yylloc);
946 $$ = new ast_type_specifier($1);
947 $$->set_location(yylloc);
951 basic_type_specifier_nonarray:
952 VOID { $$ = ast_void; }
953 | FLOAT { $$ = ast_float; }
954 | INT { $$ = ast_int; }
955 | UINT { $$ = ast_uint; }
956 | BOOL { $$ = ast_bool; }
957 | VEC2 { $$ = ast_vec2; }
958 | VEC3 { $$ = ast_vec3; }
959 | VEC4 { $$ = ast_vec4; }
960 | BVEC2 { $$ = ast_bvec2; }
961 | BVEC3 { $$ = ast_bvec3; }
962 | BVEC4 { $$ = ast_bvec4; }
963 | IVEC2 { $$ = ast_ivec2; }
964 | IVEC3 { $$ = ast_ivec3; }
965 | IVEC4 { $$ = ast_ivec4; }
966 | UVEC2 { $$ = ast_uvec2; }
967 | UVEC3 { $$ = ast_uvec3; }
968 | UVEC4 { $$ = ast_uvec4; }
969 | MAT2 { $$ = ast_mat2; }
970 | MAT3 { $$ = ast_mat3; }
971 | MAT4 { $$ = ast_mat4; }
972 | MAT2X2 { $$ = ast_mat2; }
973 | MAT2X3 { $$ = ast_mat2x3; }
974 | MAT2X4 { $$ = ast_mat2x4; }
975 | MAT3X2 { $$ = ast_mat3x2; }
976 | MAT3X3 { $$ = ast_mat3; }
977 | MAT3X4 { $$ = ast_mat3x4; }
978 | MAT4X2 { $$ = ast_mat4x2; }
979 | MAT4X3 { $$ = ast_mat4x3; }
980 | MAT4X4 { $$ = ast_mat4; }
981 | SAMPLER1D { $$ = ast_sampler1d; }
982 | SAMPLER2D { $$ = ast_sampler2d; }
983 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
984 | SAMPLER3D { $$ = ast_sampler3d; }
985 | SAMPLERCUBE { $$ = ast_samplercube; }
986 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
987 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
988 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
989 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
990 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
991 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
992 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
993 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
994 | ISAMPLER1D { $$ = ast_isampler1d; }
995 | ISAMPLER2D { $$ = ast_isampler2d; }
996 | ISAMPLER3D { $$ = ast_isampler3d; }
997 | ISAMPLERCUBE { $$ = ast_isamplercube; }
998 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
999 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1000 | USAMPLER1D { $$ = ast_usampler1d; }
1001 | USAMPLER2D { $$ = ast_usampler2d; }
1002 | USAMPLER3D { $$ = ast_usampler3d; }
1003 | USAMPLERCUBE { $$ = ast_usamplercube; }
1004 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1005 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1008 precision_qualifier:
1009 HIGH_PRECISION { $$ = ast_precision_high; }
1010 | MEDIUM_PRECISION { $$ = ast_precision_medium; }
1011 | LOW_PRECISION { $$ = ast_precision_low; }
1015 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1017 $$ = new ast_struct_specifier($2, $4);
1018 $$->set_location(yylloc);
1020 | STRUCT '{' struct_declaration_list '}'
1022 $$ = new ast_struct_specifier(NULL, $3);
1023 $$->set_location(yylloc);
1027 struct_declaration_list:
1030 $$ = (struct ast_node *) $1;
1032 | struct_declaration_list struct_declaration
1034 $$ = (struct ast_node *) $1;
1035 insert_at_tail((struct simple_node *) $$,
1036 (struct simple_node *) $2);
1041 type_specifier struct_declarator_list ';'
1043 ast_fully_specified_type *type = new ast_fully_specified_type();
1044 type->set_location(yylloc);
1046 type->specifier = $1;
1047 $$ = new ast_declarator_list(type);
1048 $$->set_location(yylloc);
1050 insert_at_tail((struct simple_node *) $2,
1051 & $$->declarations);
1055 struct_declarator_list:
1057 | struct_declarator_list ',' struct_declarator
1060 insert_at_tail((struct simple_node *) $$,
1061 (struct simple_node *) $3);
1068 $$ = new ast_declaration($1, false, NULL, NULL);
1069 $$->set_location(yylloc);
1071 | IDENTIFIER '[' constant_expression ']'
1073 $$ = new ast_declaration($1, true, $3, NULL);
1074 $$->set_location(yylloc);
1079 assignment_expression
1082 declaration_statement:
1086 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1090 | statement_unmatched
1094 compound_statement { $$ = (struct ast_node *) $1; }
1098 statement_unmatched:
1099 selection_statement_unmatched
1103 declaration_statement
1104 | expression_statement
1105 | selection_statement_matched
1106 | switch_statement { $$ = NULL; }
1107 | case_label { $$ = NULL; }
1108 | iteration_statement
1115 $$ = new ast_compound_statement(true, NULL);
1116 $$->set_location(yylloc);
1118 | '{' statement_list '}'
1120 $$ = new ast_compound_statement(true, $2);
1121 $$->set_location(yylloc);
1125 statement_no_new_scope:
1126 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1130 compound_statement_no_new_scope:
1133 $$ = new ast_compound_statement(false, NULL);
1134 $$->set_location(yylloc);
1136 | '{' statement_list '}'
1138 $$ = new ast_compound_statement(false, $2);
1139 $$->set_location(yylloc);
1147 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1152 make_empty_list((struct simple_node *) $$);
1154 | statement_list statement
1157 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1161 insert_at_tail((struct simple_node *) $$,
1162 (struct simple_node *) $2);
1166 expression_statement:
1169 $$ = new ast_expression_statement(NULL);
1170 $$->set_location(yylloc);
1174 $$ = new ast_expression_statement($1);
1175 $$->set_location(yylloc);
1179 selection_statement_matched:
1180 IF '(' expression ')' statement_matched ELSE statement_matched
1182 $$ = new ast_selection_statement($3, $5, $7);
1183 $$->set_location(yylloc);
1187 selection_statement_unmatched:
1188 IF '(' expression ')' statement_matched
1190 $$ = new ast_selection_statement($3, $5, NULL);
1191 $$->set_location(yylloc);
1193 | IF '(' expression ')' statement_unmatched
1195 $$ = new ast_selection_statement($3, $5, NULL);
1196 $$->set_location(yylloc);
1198 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1200 $$ = new ast_selection_statement($3, $5, $7);
1201 $$->set_location(yylloc);
1208 $$ = (struct ast_node *) $1;
1210 | fully_specified_type IDENTIFIER '=' initializer
1212 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1213 ast_declarator_list *declarator = new ast_declarator_list($1);
1214 decl->set_location(yylloc);
1215 declarator->set_location(yylloc);
1217 insert_at_tail(& declarator->declarations,
1218 (struct simple_node *) decl);
1225 SWITCH '(' expression ')' compound_statement
1233 iteration_statement:
1234 WHILE '(' condition ')' statement_no_new_scope
1236 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1237 NULL, $3, NULL, $5);
1238 $$->set_location(yylloc);
1240 | DO statement WHILE '(' expression ')' ';'
1242 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1243 NULL, $5, NULL, $2);
1244 $$->set_location(yylloc);
1246 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1248 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1249 $3, $4.cond, $4.rest, $6);
1250 $$->set_location(yylloc);
1255 expression_statement
1256 | declaration_statement
1273 | conditionopt ';' expression
1280 // Grammar Note: No 'goto'. Gotos are not supported.
1284 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1285 $$->set_location(yylloc);
1289 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1290 $$->set_location(yylloc);
1294 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1295 $$->set_location(yylloc);
1297 | RETURN expression ';'
1299 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1300 $$->set_location(yylloc);
1302 | DISCARD ';' // Fragment shader only.
1304 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1305 $$->set_location(yylloc);
1309 external_declaration:
1310 function_definition { $$ = $1; }
1311 | declaration { $$ = $1; }
1314 function_definition:
1315 function_prototype compound_statement_no_new_scope
1317 $$ = new ast_function_definition();
1318 $$->set_location(yylloc);