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
49 %lex-param {void *scanner}
50 %parse-param {struct _mesa_glsl_parse_state *state}
57 struct ast_type_qualifier type_qualifier;
60 ast_type_specifier *type_specifier;
61 ast_fully_specified_type *fully_specified_type;
62 ast_function *function;
63 ast_parameter_declarator *parameter_declarator;
64 ast_function_definition *function_definition;
65 ast_compound_statement *compound_statement;
66 ast_expression *expression;
67 ast_declarator_list *declarator_list;
68 ast_struct_specifier *struct_specifier;
69 ast_declaration *declaration;
77 ast_node *then_statement;
78 ast_node *else_statement;
79 } selection_rest_statement;
82 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
83 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
84 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
85 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
86 %token NOPERSPECTIVE FLAT SMOOTH
87 %token MAT2X2 MAT2X3 MAT2X4
88 %token MAT3X2 MAT3X3 MAT3X4
89 %token MAT4X2 MAT4X3 MAT4X4
90 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
91 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
92 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
93 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
94 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
95 %token STRUCT VOID_TOK WHILE
96 %token <identifier> IDENTIFIER
97 %token <real> FLOATCONSTANT
98 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
99 %token <identifier> FIELD_SELECTION
100 %token LEFT_OP RIGHT_OP
101 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
102 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
103 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
106 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
108 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
109 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
110 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
111 %token PRAGMA_INVARIANT_ALL
114 /* Reserved words that are not actually used in the grammar.
116 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
117 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
118 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
119 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
120 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
121 %token SIZEOF CAST NAMESPACE USING
125 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
126 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
127 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
128 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
129 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
130 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
133 %type <identifier> variable_identifier
134 %type <node> statement
135 %type <node> statement_list
136 %type <node> simple_statement
137 %type <n> precision_qualifier
138 %type <type_qualifier> type_qualifier
139 %type <type_qualifier> storage_qualifier
140 %type <type_qualifier> interpolation_qualifier
141 %type <type_qualifier> layout_qualifier
142 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
143 %type <type_specifier> type_specifier
144 %type <type_specifier> type_specifier_no_prec
145 %type <type_specifier> type_specifier_nonarray
146 %type <n> basic_type_specifier_nonarray
147 %type <fully_specified_type> fully_specified_type
148 %type <function> function_prototype
149 %type <function> function_header
150 %type <function> function_header_with_parameters
151 %type <function> function_declarator
152 %type <parameter_declarator> parameter_declarator
153 %type <parameter_declarator> parameter_declaration
154 %type <type_qualifier> parameter_qualifier
155 %type <type_qualifier> parameter_type_qualifier
156 %type <type_specifier> parameter_type_specifier
157 %type <function_definition> function_definition
158 %type <compound_statement> compound_statement_no_new_scope
159 %type <compound_statement> compound_statement
160 %type <node> statement_no_new_scope
161 %type <node> expression_statement
162 %type <expression> expression
163 %type <expression> primary_expression
164 %type <expression> assignment_expression
165 %type <expression> conditional_expression
166 %type <expression> logical_or_expression
167 %type <expression> logical_xor_expression
168 %type <expression> logical_and_expression
169 %type <expression> inclusive_or_expression
170 %type <expression> exclusive_or_expression
171 %type <expression> and_expression
172 %type <expression> equality_expression
173 %type <expression> relational_expression
174 %type <expression> shift_expression
175 %type <expression> additive_expression
176 %type <expression> multiplicative_expression
177 %type <expression> unary_expression
178 %type <expression> constant_expression
179 %type <expression> integer_expression
180 %type <expression> postfix_expression
181 %type <expression> function_call_header_with_parameters
182 %type <expression> function_call_header_no_parameters
183 %type <expression> function_call_header
184 %type <expression> function_call_generic
185 %type <expression> function_call_or_method
186 %type <expression> function_call
187 %type <n> assignment_operator
188 %type <n> unary_operator
189 %type <expression> function_identifier
190 %type <node> external_declaration
191 %type <declarator_list> init_declarator_list
192 %type <declarator_list> single_declaration
193 %type <expression> initializer
194 %type <node> declaration
195 %type <node> declaration_statement
196 %type <node> jump_statement
197 %type <struct_specifier> struct_specifier
198 %type <node> struct_declaration_list
199 %type <declarator_list> struct_declaration
200 %type <declaration> struct_declarator
201 %type <declaration> struct_declarator_list
202 %type <node> selection_statement
203 %type <selection_rest_statement> selection_rest_statement
204 %type <node> iteration_statement
205 %type <node> condition
206 %type <node> conditionopt
207 %type <node> for_init_statement
208 %type <for_rest_statement> for_rest_statement
212 version_statement extension_statement_list
214 _mesa_glsl_initialize_types(state);
216 external_declaration_list
220 /* blank - no #version specified: defaults are already set */
221 | VERSION INTCONSTANT EOL
225 state->es_shader = true;
229 /* FINISHME: Check against implementation support versions. */
230 state->language_version = $2;
231 state->version_string =
232 talloc_asprintf(state, "GLSL%s %d.%02d",
233 state->es_shader ? " ES" : "",
234 state->language_version / 100,
235 state->language_version % 100);
238 _mesa_glsl_error(& @2, state, "Shading language version"
239 "%u is not supported\n", $2);
247 | PRAGMA_DEBUG_OFF EOL
248 | PRAGMA_OPTIMIZE_ON EOL
249 | PRAGMA_OPTIMIZE_OFF EOL
250 | PRAGMA_INVARIANT_ALL EOL
252 if (state->language_version < 120) {
253 _mesa_glsl_warning(& @1, state,
254 "pragma `invariant(all)' not supported in %s",
255 state->version_string);
257 state->all_invariant = true;
262 extension_statement_list:
264 | extension_statement_list extension_statement
268 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
270 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
276 external_declaration_list:
279 /* FINISHME: The NULL test is required because pragmas are set to
280 * FINISHME: NULL. (See production rule for external_declaration.)
283 state->translation_unit.push_tail(& $1->link);
285 | external_declaration_list external_declaration
287 /* FINISHME: The NULL test is required because pragmas are set to
288 * FINISHME: NULL. (See production rule for external_declaration.)
291 state->translation_unit.push_tail(& $2->link);
303 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
304 $$->set_location(yylloc);
305 $$->primary_expression.identifier = $1;
310 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
311 $$->set_location(yylloc);
312 $$->primary_expression.int_constant = $1;
317 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
318 $$->set_location(yylloc);
319 $$->primary_expression.uint_constant = $1;
324 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
325 $$->set_location(yylloc);
326 $$->primary_expression.float_constant = $1;
331 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
332 $$->set_location(yylloc);
333 $$->primary_expression.bool_constant = $1;
343 | postfix_expression '[' integer_expression ']'
346 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
347 $$->set_location(yylloc);
353 | postfix_expression '.' IDENTIFIER
356 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
357 $$->set_location(yylloc);
358 $$->primary_expression.identifier = $3;
360 | postfix_expression INC_OP
363 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
364 $$->set_location(yylloc);
366 | postfix_expression DEC_OP
369 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
370 $$->set_location(yylloc);
379 function_call_or_method
382 function_call_or_method:
383 function_call_generic
384 | postfix_expression '.' function_call_generic
387 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
388 $$->set_location(yylloc);
392 function_call_generic:
393 function_call_header_with_parameters ')'
394 | function_call_header_no_parameters ')'
397 function_call_header_no_parameters:
398 function_call_header VOID_TOK
399 | function_call_header
402 function_call_header_with_parameters:
403 function_call_header assignment_expression
406 $$->set_location(yylloc);
407 $$->expressions.push_tail(& $2->link);
409 | function_call_header_with_parameters ',' assignment_expression
412 $$->set_location(yylloc);
413 $$->expressions.push_tail(& $3->link);
417 // Grammar Note: Constructors look like functions, but lexical
418 // analysis recognized most of them as keywords. They are now
419 // recognized through "type_specifier".
420 function_call_header:
421 function_identifier '('
428 $$ = new(ctx) ast_function_expression($1);
429 $$->set_location(yylloc);
434 ast_expression *callee = new(ctx) ast_expression($1);
435 $$ = new(ctx) ast_function_expression(callee);
436 $$->set_location(yylloc);
441 ast_expression *callee = new(ctx) ast_expression($1);
442 $$ = new(ctx) ast_function_expression(callee);
443 $$->set_location(yylloc);
447 // Grammar Note: No traditional style type casts.
450 | INC_OP unary_expression
453 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
454 $$->set_location(yylloc);
456 | DEC_OP unary_expression
459 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
460 $$->set_location(yylloc);
462 | unary_operator unary_expression
465 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
466 $$->set_location(yylloc);
470 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
472 '+' { $$ = ast_plus; }
473 | '-' { $$ = ast_neg; }
474 | '!' { $$ = ast_logic_not; }
475 | '~' { $$ = ast_bit_not; }
478 multiplicative_expression:
480 | multiplicative_expression '*' unary_expression
483 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
484 $$->set_location(yylloc);
486 | multiplicative_expression '/' unary_expression
489 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
490 $$->set_location(yylloc);
492 | multiplicative_expression '%' unary_expression
495 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
496 $$->set_location(yylloc);
501 multiplicative_expression
502 | additive_expression '+' multiplicative_expression
505 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
506 $$->set_location(yylloc);
508 | additive_expression '-' multiplicative_expression
511 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
512 $$->set_location(yylloc);
518 | shift_expression LEFT_OP additive_expression
521 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
522 $$->set_location(yylloc);
524 | shift_expression RIGHT_OP additive_expression
527 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
528 $$->set_location(yylloc);
532 relational_expression:
534 | relational_expression '<' shift_expression
537 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
538 $$->set_location(yylloc);
540 | relational_expression '>' shift_expression
543 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
544 $$->set_location(yylloc);
546 | relational_expression LE_OP shift_expression
549 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
550 $$->set_location(yylloc);
552 | relational_expression GE_OP shift_expression
555 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
556 $$->set_location(yylloc);
561 relational_expression
562 | equality_expression EQ_OP relational_expression
565 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
566 $$->set_location(yylloc);
568 | equality_expression NE_OP relational_expression
571 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
572 $$->set_location(yylloc);
578 | and_expression '&' equality_expression
581 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
582 $$->set_location(yylloc);
586 exclusive_or_expression:
588 | exclusive_or_expression '^' and_expression
591 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
592 $$->set_location(yylloc);
596 inclusive_or_expression:
597 exclusive_or_expression
598 | inclusive_or_expression '|' exclusive_or_expression
601 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
602 $$->set_location(yylloc);
606 logical_and_expression:
607 inclusive_or_expression
608 | logical_and_expression AND_OP inclusive_or_expression
611 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
612 $$->set_location(yylloc);
616 logical_xor_expression:
617 logical_and_expression
618 | logical_xor_expression XOR_OP logical_and_expression
621 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
622 $$->set_location(yylloc);
626 logical_or_expression:
627 logical_xor_expression
628 | logical_or_expression OR_OP logical_xor_expression
631 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
632 $$->set_location(yylloc);
636 conditional_expression:
637 logical_or_expression
638 | logical_or_expression '?' expression ':' assignment_expression
641 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
642 $$->set_location(yylloc);
646 assignment_expression:
647 conditional_expression
648 | unary_expression assignment_operator assignment_expression
651 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
652 $$->set_location(yylloc);
657 '=' { $$ = ast_assign; }
658 | MUL_ASSIGN { $$ = ast_mul_assign; }
659 | DIV_ASSIGN { $$ = ast_div_assign; }
660 | MOD_ASSIGN { $$ = ast_mod_assign; }
661 | ADD_ASSIGN { $$ = ast_add_assign; }
662 | SUB_ASSIGN { $$ = ast_sub_assign; }
663 | LEFT_ASSIGN { $$ = ast_ls_assign; }
664 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
665 | AND_ASSIGN { $$ = ast_and_assign; }
666 | XOR_ASSIGN { $$ = ast_xor_assign; }
667 | OR_ASSIGN { $$ = ast_or_assign; }
671 assignment_expression
675 | expression ',' assignment_expression
678 if ($1->oper != ast_sequence) {
679 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
680 $$->set_location(yylloc);
681 $$->expressions.push_tail(& $1->link);
686 $$->expressions.push_tail(& $3->link);
691 conditional_expression
695 function_prototype ';'
699 | init_declarator_list ';'
703 | PRECISION precision_qualifier type_specifier_no_prec ';'
706 $3->is_precision_statement = true;
712 function_declarator ')'
717 | function_header_with_parameters
720 function_header_with_parameters:
721 function_header parameter_declaration
724 $$->parameters.push_tail(& $2->link);
726 | function_header_with_parameters ',' parameter_declaration
729 $$->parameters.push_tail(& $3->link);
734 fully_specified_type IDENTIFIER '('
737 $$ = new(ctx) ast_function();
738 $$->set_location(yylloc);
739 $$->return_type = $1;
744 parameter_declarator:
745 type_specifier IDENTIFIER
748 $$ = new(ctx) ast_parameter_declarator();
749 $$->set_location(yylloc);
750 $$->type = new(ctx) ast_fully_specified_type();
751 $$->type->set_location(yylloc);
752 $$->type->specifier = $1;
755 | type_specifier IDENTIFIER '[' constant_expression ']'
758 $$ = new(ctx) ast_parameter_declarator();
759 $$->set_location(yylloc);
760 $$->type = new(ctx) ast_fully_specified_type();
761 $$->type->set_location(yylloc);
762 $$->type->specifier = $1;
769 parameter_declaration:
770 parameter_type_qualifier parameter_qualifier parameter_declarator
772 $1.flags.i |= $2.flags.i;
775 $$->type->qualifier = $1;
777 | parameter_qualifier parameter_declarator
780 $$->type->qualifier = $1;
782 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
785 $1.flags.i |= $2.flags.i;
787 $$ = new(ctx) ast_parameter_declarator();
788 $$->set_location(yylloc);
789 $$->type = new(ctx) ast_fully_specified_type();
790 $$->type->qualifier = $1;
791 $$->type->specifier = $3;
793 | parameter_qualifier parameter_type_specifier
796 $$ = new(ctx) ast_parameter_declarator();
797 $$->set_location(yylloc);
798 $$->type = new(ctx) ast_fully_specified_type();
799 $$->type->qualifier = $1;
800 $$->type->specifier = $2;
807 memset(& $$, 0, sizeof($$));
811 memset(& $$, 0, sizeof($$));
816 memset(& $$, 0, sizeof($$));
821 memset(& $$, 0, sizeof($$));
827 parameter_type_specifier:
831 init_declarator_list:
833 | init_declarator_list ',' IDENTIFIER
836 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
837 decl->set_location(yylloc);
840 $$->declarations.push_tail(&decl->link);
842 | init_declarator_list ',' IDENTIFIER '[' ']'
845 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
846 decl->set_location(yylloc);
849 $$->declarations.push_tail(&decl->link);
851 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
854 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
855 decl->set_location(yylloc);
858 $$->declarations.push_tail(&decl->link);
860 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
863 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
864 decl->set_location(yylloc);
867 $$->declarations.push_tail(&decl->link);
869 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
872 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
873 decl->set_location(yylloc);
876 $$->declarations.push_tail(&decl->link);
878 | init_declarator_list ',' IDENTIFIER '=' initializer
881 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
882 decl->set_location(yylloc);
885 $$->declarations.push_tail(&decl->link);
889 // Grammar Note: No 'enum', or 'typedef'.
894 if ($1->specifier->type_specifier != ast_struct) {
895 _mesa_glsl_error(& @1, state, "empty declaration list\n");
898 $$ = new(ctx) ast_declarator_list($1);
899 $$->set_location(yylloc);
902 | fully_specified_type IDENTIFIER
905 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
907 $$ = new(ctx) ast_declarator_list($1);
908 $$->set_location(yylloc);
909 $$->declarations.push_tail(&decl->link);
911 | fully_specified_type IDENTIFIER '[' ']'
914 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
916 $$ = new(ctx) ast_declarator_list($1);
917 $$->set_location(yylloc);
918 $$->declarations.push_tail(&decl->link);
920 | fully_specified_type IDENTIFIER '[' constant_expression ']'
923 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
925 $$ = new(ctx) ast_declarator_list($1);
926 $$->set_location(yylloc);
927 $$->declarations.push_tail(&decl->link);
929 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
932 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
934 $$ = new(ctx) ast_declarator_list($1);
935 $$->set_location(yylloc);
936 $$->declarations.push_tail(&decl->link);
938 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
941 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
943 $$ = new(ctx) ast_declarator_list($1);
944 $$->set_location(yylloc);
945 $$->declarations.push_tail(&decl->link);
947 | fully_specified_type IDENTIFIER '=' initializer
950 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
952 $$ = new(ctx) ast_declarator_list($1);
953 $$->set_location(yylloc);
954 $$->declarations.push_tail(&decl->link);
956 | INVARIANT IDENTIFIER // Vertex only.
959 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
961 $$ = new(ctx) ast_declarator_list(NULL);
962 $$->set_location(yylloc);
963 $$->invariant = true;
965 $$->declarations.push_tail(&decl->link);
969 fully_specified_type:
973 $$ = new(ctx) ast_fully_specified_type();
974 $$->set_location(yylloc);
977 | type_qualifier type_specifier
980 $$ = new(ctx) ast_fully_specified_type();
981 $$->set_location(yylloc);
988 LAYOUT_TOK '(' layout_qualifier_id_list ')'
994 layout_qualifier_id_list:
996 | layout_qualifier_id_list ',' layout_qualifier_id
998 if (($1.flags.i & $3.flags.i) != 0) {
999 _mesa_glsl_error(& @3, state,
1000 "duplicate layout qualifiers used\n");
1004 $$.flags.i = $1.flags.i | $3.flags.i;
1006 if ($1.flags.q.explicit_location)
1007 $$.location = $1.location;
1009 if ($3.flags.q.explicit_location)
1010 $$.location = $3.location;
1014 layout_qualifier_id:
1017 bool got_one = false;
1019 memset(& $$, 0, sizeof($$));
1021 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1022 if (!got_one && state->ARB_fragment_coord_conventions_enable) {
1023 if (strcmp($1, "origin_upper_left") == 0) {
1025 $$.flags.q.origin_upper_left = 1;
1026 } else if (strcmp($1, "pixel_center_integer") == 0) {
1028 $$.flags.q.pixel_center_integer = 1;
1031 if (got_one && state->ARB_fragment_coord_conventions_warn) {
1032 _mesa_glsl_warning(& @1, state,
1033 "GL_ARB_fragment_coord_conventions layout "
1034 "identifier `%s' used\n", $1);
1038 /* Layout qualifiers for AMD_conservative_depth. */
1039 if (!got_one && state->AMD_conservative_depth_enable) {
1040 if (strcmp($1, "depth_any") == 0) {
1042 $$.flags.q.depth_any = 1;
1043 } else if (strcmp($1, "depth_greater") == 0) {
1045 $$.flags.q.depth_greater = 1;
1046 } else if (strcmp($1, "depth_less") == 0) {
1048 $$.flags.q.depth_less = 1;
1049 } else if (strcmp($1, "depth_unchanged") == 0) {
1051 $$.flags.q.depth_unchanged = 1;
1054 if (got_one && state->AMD_conservative_depth_warn) {
1055 _mesa_glsl_warning(& @1, state,
1056 "GL_AMD_conservative_depth "
1057 "layout qualifier `%s' is used\n", $1);
1062 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1067 | IDENTIFIER '=' INTCONSTANT
1069 bool got_one = false;
1071 memset(& $$, 0, sizeof($$));
1073 if (state->ARB_explicit_attrib_location_enable) {
1074 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1075 * FINISHME: GLSL 1.30 (or later) are supported.
1077 if (strcmp("location", $1) == 0) {
1080 $$.flags.q.explicit_location = 1;
1085 _mesa_glsl_error(& @3, state,
1086 "invalid location %d specified\n", $3);
1092 /* If the identifier didn't match any known layout identifiers,
1096 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1099 } else if (state->ARB_explicit_attrib_location_warn) {
1100 _mesa_glsl_warning(& @1, state,
1101 "GL_ARB_explicit_attrib_location layout "
1102 "identifier `%s' used\n", $1);
1107 interpolation_qualifier:
1110 memset(& $$, 0, sizeof($$));
1111 $$.flags.q.smooth = 1;
1115 memset(& $$, 0, sizeof($$));
1116 $$.flags.q.flat = 1;
1120 memset(& $$, 0, sizeof($$));
1121 $$.flags.q.noperspective = 1;
1125 parameter_type_qualifier:
1128 memset(& $$, 0, sizeof($$));
1129 $$.flags.q.constant = 1;
1136 | layout_qualifier storage_qualifier
1139 $$.flags.i |= $2.flags.i;
1141 | interpolation_qualifier
1142 | interpolation_qualifier storage_qualifier
1145 $$.flags.i |= $2.flags.i;
1147 | INVARIANT storage_qualifier
1150 $$.flags.q.invariant = 1;
1152 | INVARIANT interpolation_qualifier storage_qualifier
1155 $$.flags.i |= $3.flags.i;
1156 $$.flags.q.invariant = 1;
1160 memset(& $$, 0, sizeof($$));
1161 $$.flags.q.invariant = 1;
1168 memset(& $$, 0, sizeof($$));
1169 $$.flags.q.constant = 1;
1173 memset(& $$, 0, sizeof($$));
1174 $$.flags.q.attribute = 1;
1178 memset(& $$, 0, sizeof($$));
1179 $$.flags.q.varying = 1;
1183 memset(& $$, 0, sizeof($$));
1184 $$.flags.q.centroid = 1;
1185 $$.flags.q.varying = 1;
1189 memset(& $$, 0, sizeof($$));
1194 memset(& $$, 0, sizeof($$));
1199 memset(& $$, 0, sizeof($$));
1200 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1204 memset(& $$, 0, sizeof($$));
1205 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1209 memset(& $$, 0, sizeof($$));
1210 $$.flags.q.uniform = 1;
1215 type_specifier_no_prec
1219 | precision_qualifier type_specifier_no_prec
1226 type_specifier_no_prec:
1227 type_specifier_nonarray
1228 | type_specifier_nonarray '[' ']'
1231 $$->is_array = true;
1232 $$->array_size = NULL;
1234 | type_specifier_nonarray '[' constant_expression ']'
1237 $$->is_array = true;
1238 $$->array_size = $3;
1242 type_specifier_nonarray:
1243 basic_type_specifier_nonarray
1246 $$ = new(ctx) ast_type_specifier($1);
1247 $$->set_location(yylloc);
1252 $$ = new(ctx) ast_type_specifier($1);
1253 $$->set_location(yylloc);
1258 $$ = new(ctx) ast_type_specifier($1);
1259 $$->set_location(yylloc);
1263 basic_type_specifier_nonarray:
1264 VOID_TOK { $$ = ast_void; }
1265 | FLOAT_TOK { $$ = ast_float; }
1266 | INT_TOK { $$ = ast_int; }
1267 | UINT_TOK { $$ = ast_uint; }
1268 | BOOL_TOK { $$ = ast_bool; }
1269 | VEC2 { $$ = ast_vec2; }
1270 | VEC3 { $$ = ast_vec3; }
1271 | VEC4 { $$ = ast_vec4; }
1272 | BVEC2 { $$ = ast_bvec2; }
1273 | BVEC3 { $$ = ast_bvec3; }
1274 | BVEC4 { $$ = ast_bvec4; }
1275 | IVEC2 { $$ = ast_ivec2; }
1276 | IVEC3 { $$ = ast_ivec3; }
1277 | IVEC4 { $$ = ast_ivec4; }
1278 | UVEC2 { $$ = ast_uvec2; }
1279 | UVEC3 { $$ = ast_uvec3; }
1280 | UVEC4 { $$ = ast_uvec4; }
1281 | MAT2X2 { $$ = ast_mat2; }
1282 | MAT2X3 { $$ = ast_mat2x3; }
1283 | MAT2X4 { $$ = ast_mat2x4; }
1284 | MAT3X2 { $$ = ast_mat3x2; }
1285 | MAT3X3 { $$ = ast_mat3; }
1286 | MAT3X4 { $$ = ast_mat3x4; }
1287 | MAT4X2 { $$ = ast_mat4x2; }
1288 | MAT4X3 { $$ = ast_mat4x3; }
1289 | MAT4X4 { $$ = ast_mat4; }
1290 | SAMPLER1D { $$ = ast_sampler1d; }
1291 | SAMPLER2D { $$ = ast_sampler2d; }
1292 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1293 | SAMPLER3D { $$ = ast_sampler3d; }
1294 | SAMPLERCUBE { $$ = ast_samplercube; }
1295 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1296 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1297 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1298 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1299 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1300 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1301 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1302 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1303 | ISAMPLER1D { $$ = ast_isampler1d; }
1304 | ISAMPLER2D { $$ = ast_isampler2d; }
1305 | ISAMPLER3D { $$ = ast_isampler3d; }
1306 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1307 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1308 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1309 | USAMPLER1D { $$ = ast_usampler1d; }
1310 | USAMPLER2D { $$ = ast_usampler2d; }
1311 | USAMPLER3D { $$ = ast_usampler3d; }
1312 | USAMPLERCUBE { $$ = ast_usamplercube; }
1313 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1314 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1317 precision_qualifier:
1319 if (!state->es_shader && state->language_version < 130)
1320 _mesa_glsl_error(& @1, state,
1321 "precision qualifier forbidden "
1322 "in %s (1.30 or later "
1324 state->version_string);
1326 $$ = ast_precision_high;
1329 if (!state->es_shader && state->language_version < 130)
1330 _mesa_glsl_error(& @1, state,
1331 "precision qualifier forbidden "
1332 "in %s (1.30 or later "
1334 state->version_string);
1336 $$ = ast_precision_medium;
1339 if (!state->es_shader && state->language_version < 130)
1340 _mesa_glsl_error(& @1, state,
1341 "precision qualifier forbidden "
1342 "in %s (1.30 or later "
1344 state->version_string);
1346 $$ = ast_precision_low;
1351 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1354 $$ = new(ctx) ast_struct_specifier($2, $4);
1355 $$->set_location(yylloc);
1357 | STRUCT '{' struct_declaration_list '}'
1360 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1361 $$->set_location(yylloc);
1365 struct_declaration_list:
1368 $$ = (ast_node *) $1;
1369 $1->link.self_link();
1371 | struct_declaration_list struct_declaration
1373 $$ = (ast_node *) $1;
1374 $$->link.insert_before(& $2->link);
1379 type_specifier struct_declarator_list ';'
1382 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1383 type->set_location(yylloc);
1385 type->specifier = $1;
1386 $$ = new(ctx) ast_declarator_list(type);
1387 $$->set_location(yylloc);
1389 $$->declarations.push_degenerate_list_at_head(& $2->link);
1393 struct_declarator_list:
1397 $1->link.self_link();
1399 | struct_declarator_list ',' struct_declarator
1402 $$->link.insert_before(& $3->link);
1410 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1411 $$->set_location(yylloc);
1413 | IDENTIFIER '[' constant_expression ']'
1416 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1417 $$->set_location(yylloc);
1422 assignment_expression
1425 declaration_statement:
1429 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1432 compound_statement { $$ = (ast_node *) $1; }
1437 declaration_statement
1438 | expression_statement
1439 | selection_statement
1440 | switch_statement { $$ = NULL; }
1441 | case_label { $$ = NULL; }
1442 | iteration_statement
1450 $$ = new(ctx) ast_compound_statement(true, NULL);
1451 $$->set_location(yylloc);
1453 | '{' statement_list '}'
1456 $$ = new(ctx) ast_compound_statement(true, $2);
1457 $$->set_location(yylloc);
1461 statement_no_new_scope:
1462 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1466 compound_statement_no_new_scope:
1470 $$ = new(ctx) ast_compound_statement(false, NULL);
1471 $$->set_location(yylloc);
1473 | '{' statement_list '}'
1476 $$ = new(ctx) ast_compound_statement(false, $2);
1477 $$->set_location(yylloc);
1485 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1490 $$->link.self_link();
1492 | statement_list statement
1495 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1499 $$->link.insert_before(& $2->link);
1503 expression_statement:
1507 $$ = new(ctx) ast_expression_statement(NULL);
1508 $$->set_location(yylloc);
1513 $$ = new(ctx) ast_expression_statement($1);
1514 $$->set_location(yylloc);
1518 selection_statement:
1519 IF '(' expression ')' selection_rest_statement
1521 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1523 $$->set_location(yylloc);
1527 selection_rest_statement:
1528 statement ELSE statement
1530 $$.then_statement = $1;
1531 $$.else_statement = $3;
1535 $$.then_statement = $1;
1536 $$.else_statement = NULL;
1543 $$ = (ast_node *) $1;
1545 | fully_specified_type IDENTIFIER '=' initializer
1548 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1549 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1550 decl->set_location(yylloc);
1551 declarator->set_location(yylloc);
1553 declarator->declarations.push_tail(&decl->link);
1559 SWITCH '(' expression ')' compound_statement
1567 iteration_statement:
1568 WHILE '(' condition ')' statement_no_new_scope
1571 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1572 NULL, $3, NULL, $5);
1573 $$->set_location(yylloc);
1575 | DO statement WHILE '(' expression ')' ';'
1578 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1579 NULL, $5, NULL, $2);
1580 $$->set_location(yylloc);
1582 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1585 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1586 $3, $4.cond, $4.rest, $6);
1587 $$->set_location(yylloc);
1592 expression_statement
1593 | declaration_statement
1610 | conditionopt ';' expression
1617 // Grammar Note: No 'goto'. Gotos are not supported.
1622 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1623 $$->set_location(yylloc);
1628 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1629 $$->set_location(yylloc);
1634 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1635 $$->set_location(yylloc);
1637 | RETURN expression ';'
1640 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1641 $$->set_location(yylloc);
1643 | DISCARD ';' // Fragment shader only.
1646 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1647 $$->set_location(yylloc);
1651 external_declaration:
1652 function_definition { $$ = $1; }
1653 | declaration { $$ = $1; }
1654 | pragma_statement { $$ = NULL; }
1657 function_definition:
1658 function_prototype compound_statement_no_new_scope
1661 $$ = new(ctx) ast_function_definition();
1662 $$->set_location(yylloc);