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}
58 struct ast_type_qualifier q;
63 ast_type_specifier *type_specifier;
64 ast_fully_specified_type *fully_specified_type;
65 ast_function *function;
66 ast_parameter_declarator *parameter_declarator;
67 ast_function_definition *function_definition;
68 ast_compound_statement *compound_statement;
69 ast_expression *expression;
70 ast_declarator_list *declarator_list;
71 ast_struct_specifier *struct_specifier;
72 ast_declaration *declaration;
80 ast_node *then_statement;
81 ast_node *else_statement;
82 } selection_rest_statement;
85 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
86 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
87 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
88 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
89 %token NOPERSPECTIVE FLAT SMOOTH
90 %token MAT2X2 MAT2X3 MAT2X4
91 %token MAT3X2 MAT3X3 MAT3X4
92 %token MAT4X2 MAT4X3 MAT4X4
93 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
94 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
95 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
96 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
97 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
98 %token STRUCT VOID_TOK WHILE
99 %token <identifier> IDENTIFIER
100 %token <real> FLOATCONSTANT
101 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
102 %token <identifier> FIELD_SELECTION
103 %token LEFT_OP RIGHT_OP
104 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
105 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
106 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
109 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
111 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
112 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
113 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
116 /* Reserved words that are not actually used in the grammar.
118 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
119 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
120 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
121 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
122 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
123 %token SIZEOF CAST NAMESPACE USING
127 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
128 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
129 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
130 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
131 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
134 %type <identifier> variable_identifier
135 %type <node> statement
136 %type <node> statement_list
137 %type <node> simple_statement
138 %type <n> precision_qualifier
139 %type <type_qualifier> type_qualifier
140 %type <type_qualifier> storage_qualifier
141 %type <type_qualifier> interpolation_qualifier
142 %type <type_qualifier> opt_layout_qualifier layout_qualifier
143 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
144 %type <type_specifier> type_specifier
145 %type <type_specifier> type_specifier_no_prec
146 %type <type_specifier> type_specifier_nonarray
147 %type <n> basic_type_specifier_nonarray
148 %type <fully_specified_type> fully_specified_type
149 %type <function> function_prototype
150 %type <function> function_header
151 %type <function> function_header_with_parameters
152 %type <function> function_declarator
153 %type <parameter_declarator> parameter_declarator
154 %type <parameter_declarator> parameter_declaration
155 %type <type_qualifier> parameter_qualifier
156 %type <type_qualifier> parameter_type_qualifier
157 %type <type_specifier> parameter_type_specifier
158 %type <function_definition> function_definition
159 %type <compound_statement> compound_statement_no_new_scope
160 %type <compound_statement> compound_statement
161 %type <node> statement_no_new_scope
162 %type <node> expression_statement
163 %type <expression> expression
164 %type <expression> primary_expression
165 %type <expression> assignment_expression
166 %type <expression> conditional_expression
167 %type <expression> logical_or_expression
168 %type <expression> logical_xor_expression
169 %type <expression> logical_and_expression
170 %type <expression> inclusive_or_expression
171 %type <expression> exclusive_or_expression
172 %type <expression> and_expression
173 %type <expression> equality_expression
174 %type <expression> relational_expression
175 %type <expression> shift_expression
176 %type <expression> additive_expression
177 %type <expression> multiplicative_expression
178 %type <expression> unary_expression
179 %type <expression> constant_expression
180 %type <expression> integer_expression
181 %type <expression> postfix_expression
182 %type <expression> function_call_header_with_parameters
183 %type <expression> function_call_header_no_parameters
184 %type <expression> function_call_header
185 %type <expression> function_call_generic
186 %type <expression> function_call_or_method
187 %type <expression> function_call
188 %type <n> assignment_operator
189 %type <n> unary_operator
190 %type <expression> function_identifier
191 %type <node> external_declaration
192 %type <declarator_list> init_declarator_list
193 %type <declarator_list> single_declaration
194 %type <expression> initializer
195 %type <node> declaration
196 %type <node> declaration_statement
197 %type <node> jump_statement
198 %type <struct_specifier> struct_specifier
199 %type <node> struct_declaration_list
200 %type <declarator_list> struct_declaration
201 %type <declaration> struct_declarator
202 %type <declaration> struct_declarator_list
203 %type <node> selection_statement
204 %type <selection_rest_statement> selection_rest_statement
205 %type <node> iteration_statement
206 %type <node> condition
207 %type <node> conditionopt
208 %type <node> for_init_statement
209 %type <for_rest_statement> for_rest_statement
213 version_statement extension_statement_list
215 _mesa_glsl_initialize_types(state);
217 external_declaration_list
221 /* blank - no #version specified */
223 state->language_version = 110;
224 state->symbols->language_version = 110;
226 | VERSION INTCONSTANT EOL
232 /* FINISHME: Check against implementation support versions. */
233 state->language_version = $2;
234 state->symbols->language_version = $2;
237 _mesa_glsl_error(& @2, state, "Shading language version"
238 "%u is not supported\n", $2);
246 | PRAGMA_DEBUG_OFF EOL
247 | PRAGMA_OPTIMIZE_ON EOL
248 | PRAGMA_OPTIMIZE_OFF EOL
251 extension_statement_list:
253 | extension_statement_list extension_statement
257 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
259 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
265 external_declaration_list:
268 /* FINISHME: The NULL test is only required because 'precision'
269 * FINISHME: statements are not yet supported.
272 state->translation_unit.push_tail(& $1->link);
274 | external_declaration_list external_declaration
276 /* FINISHME: The NULL test is only required because 'precision'
277 * FINISHME: statements are not yet supported.
280 state->translation_unit.push_tail(& $2->link);
292 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
293 $$->set_location(yylloc);
294 $$->primary_expression.identifier = $1;
299 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
300 $$->set_location(yylloc);
301 $$->primary_expression.int_constant = $1;
306 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
307 $$->set_location(yylloc);
308 $$->primary_expression.uint_constant = $1;
313 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
314 $$->set_location(yylloc);
315 $$->primary_expression.float_constant = $1;
320 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
321 $$->set_location(yylloc);
322 $$->primary_expression.bool_constant = $1;
332 | postfix_expression '[' integer_expression ']'
335 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
336 $$->set_location(yylloc);
342 | postfix_expression '.' IDENTIFIER
345 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
346 $$->set_location(yylloc);
347 $$->primary_expression.identifier = $3;
349 | postfix_expression INC_OP
352 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
353 $$->set_location(yylloc);
355 | postfix_expression DEC_OP
358 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
359 $$->set_location(yylloc);
368 function_call_or_method
371 function_call_or_method:
372 function_call_generic
373 | postfix_expression '.' function_call_generic
376 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
377 $$->set_location(yylloc);
381 function_call_generic:
382 function_call_header_with_parameters ')'
383 | function_call_header_no_parameters ')'
386 function_call_header_no_parameters:
387 function_call_header VOID_TOK
388 | function_call_header
391 function_call_header_with_parameters:
392 function_call_header assignment_expression
395 $$->set_location(yylloc);
396 $$->expressions.push_tail(& $2->link);
398 | function_call_header_with_parameters ',' assignment_expression
401 $$->set_location(yylloc);
402 $$->expressions.push_tail(& $3->link);
406 // Grammar Note: Constructors look like functions, but lexical
407 // analysis recognized most of them as keywords. They are now
408 // recognized through "type_specifier".
409 function_call_header:
410 function_identifier '('
417 $$ = new(ctx) ast_function_expression($1);
418 $$->set_location(yylloc);
423 ast_expression *callee = new(ctx) ast_expression($1);
424 $$ = new(ctx) ast_function_expression(callee);
425 $$->set_location(yylloc);
430 ast_expression *callee = new(ctx) ast_expression($1);
431 $$ = new(ctx) ast_function_expression(callee);
432 $$->set_location(yylloc);
436 // Grammar Note: No traditional style type casts.
439 | INC_OP unary_expression
442 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
443 $$->set_location(yylloc);
445 | DEC_OP unary_expression
448 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
449 $$->set_location(yylloc);
451 | unary_operator unary_expression
454 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
455 $$->set_location(yylloc);
459 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
461 '+' { $$ = ast_plus; }
462 | '-' { $$ = ast_neg; }
463 | '!' { $$ = ast_logic_not; }
464 | '~' { $$ = ast_bit_not; }
467 multiplicative_expression:
469 | multiplicative_expression '*' unary_expression
472 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
473 $$->set_location(yylloc);
475 | multiplicative_expression '/' unary_expression
478 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
479 $$->set_location(yylloc);
481 | multiplicative_expression '%' unary_expression
484 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
485 $$->set_location(yylloc);
490 multiplicative_expression
491 | additive_expression '+' multiplicative_expression
494 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
495 $$->set_location(yylloc);
497 | additive_expression '-' multiplicative_expression
500 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
501 $$->set_location(yylloc);
507 | shift_expression LEFT_OP additive_expression
510 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
511 $$->set_location(yylloc);
513 | shift_expression RIGHT_OP additive_expression
516 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
517 $$->set_location(yylloc);
521 relational_expression:
523 | relational_expression '<' shift_expression
526 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
527 $$->set_location(yylloc);
529 | relational_expression '>' shift_expression
532 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
533 $$->set_location(yylloc);
535 | relational_expression LE_OP shift_expression
538 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
539 $$->set_location(yylloc);
541 | relational_expression GE_OP shift_expression
544 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
545 $$->set_location(yylloc);
550 relational_expression
551 | equality_expression EQ_OP relational_expression
554 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
555 $$->set_location(yylloc);
557 | equality_expression NE_OP relational_expression
560 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
561 $$->set_location(yylloc);
567 | and_expression '&' equality_expression
570 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
571 $$->set_location(yylloc);
575 exclusive_or_expression:
577 | exclusive_or_expression '^' and_expression
580 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
581 $$->set_location(yylloc);
585 inclusive_or_expression:
586 exclusive_or_expression
587 | inclusive_or_expression '|' exclusive_or_expression
590 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
591 $$->set_location(yylloc);
595 logical_and_expression:
596 inclusive_or_expression
597 | logical_and_expression AND_OP inclusive_or_expression
600 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
601 $$->set_location(yylloc);
605 logical_xor_expression:
606 logical_and_expression
607 | logical_xor_expression XOR_OP logical_and_expression
610 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
611 $$->set_location(yylloc);
615 logical_or_expression:
616 logical_xor_expression
617 | logical_or_expression OR_OP logical_xor_expression
620 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
621 $$->set_location(yylloc);
625 conditional_expression:
626 logical_or_expression
627 | logical_or_expression '?' expression ':' assignment_expression
630 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
631 $$->set_location(yylloc);
635 assignment_expression:
636 conditional_expression
637 | unary_expression assignment_operator assignment_expression
640 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
641 $$->set_location(yylloc);
646 '=' { $$ = ast_assign; }
647 | MUL_ASSIGN { $$ = ast_mul_assign; }
648 | DIV_ASSIGN { $$ = ast_div_assign; }
649 | MOD_ASSIGN { $$ = ast_mod_assign; }
650 | ADD_ASSIGN { $$ = ast_add_assign; }
651 | SUB_ASSIGN { $$ = ast_sub_assign; }
652 | LEFT_ASSIGN { $$ = ast_ls_assign; }
653 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
654 | AND_ASSIGN { $$ = ast_and_assign; }
655 | XOR_ASSIGN { $$ = ast_xor_assign; }
656 | OR_ASSIGN { $$ = ast_or_assign; }
660 assignment_expression
664 | expression ',' assignment_expression
667 if ($1->oper != ast_sequence) {
668 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
669 $$->set_location(yylloc);
670 $$->expressions.push_tail(& $1->link);
675 $$->expressions.push_tail(& $3->link);
680 conditional_expression
684 function_prototype ';'
688 | init_declarator_list ';'
692 | PRECISION precision_qualifier type_specifier_no_prec ';'
694 if (($3->type_specifier != ast_float)
695 && ($3->type_specifier != ast_int)) {
696 _mesa_glsl_error(& @3, state, "global precision qualifier can "
697 "only be applied to `int' or `float'\n");
701 $$ = NULL; /* FINISHME */
706 function_declarator ')'
711 | function_header_with_parameters
714 function_header_with_parameters:
715 function_header parameter_declaration
718 $$->parameters.push_tail(& $2->link);
720 | function_header_with_parameters ',' parameter_declaration
723 $$->parameters.push_tail(& $3->link);
728 fully_specified_type IDENTIFIER '('
731 $$ = new(ctx) ast_function();
732 $$->set_location(yylloc);
733 $$->return_type = $1;
738 parameter_declarator:
739 type_specifier IDENTIFIER
742 $$ = new(ctx) ast_parameter_declarator();
743 $$->set_location(yylloc);
744 $$->type = new(ctx) ast_fully_specified_type();
745 $$->type->set_location(yylloc);
746 $$->type->specifier = $1;
749 | type_specifier IDENTIFIER '[' constant_expression ']'
752 $$ = new(ctx) ast_parameter_declarator();
753 $$->set_location(yylloc);
754 $$->type = new(ctx) ast_fully_specified_type();
755 $$->type->set_location(yylloc);
756 $$->type->specifier = $1;
763 parameter_declaration:
764 parameter_type_qualifier parameter_qualifier parameter_declarator
769 $$->type->qualifier = $1.q;
771 | parameter_qualifier parameter_declarator
774 $$->type->qualifier = $1.q;
776 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
781 $$ = new(ctx) ast_parameter_declarator();
782 $$->set_location(yylloc);
783 $$->type = new(ctx) ast_fully_specified_type();
784 $$->type->qualifier = $1.q;
785 $$->type->specifier = $3;
787 | parameter_qualifier parameter_type_specifier
790 $$ = new(ctx) ast_parameter_declarator();
791 $$->set_location(yylloc);
792 $$->type = new(ctx) ast_fully_specified_type();
793 $$->type->qualifier = $1.q;
794 $$->type->specifier = $2;
799 /* empty */ { $$.i = 0; }
800 | IN_TOK { $$.i = 0; $$.q.in = 1; }
801 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
802 | INOUT_TOK { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
805 parameter_type_specifier:
809 init_declarator_list:
811 | init_declarator_list ',' IDENTIFIER
814 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
815 decl->set_location(yylloc);
818 $$->declarations.push_tail(&decl->link);
820 | init_declarator_list ',' IDENTIFIER '[' ']'
823 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
824 decl->set_location(yylloc);
827 $$->declarations.push_tail(&decl->link);
829 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
832 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
833 decl->set_location(yylloc);
836 $$->declarations.push_tail(&decl->link);
838 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
841 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
842 decl->set_location(yylloc);
845 $$->declarations.push_tail(&decl->link);
847 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
850 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
851 decl->set_location(yylloc);
854 $$->declarations.push_tail(&decl->link);
856 | init_declarator_list ',' IDENTIFIER '=' initializer
859 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
860 decl->set_location(yylloc);
863 $$->declarations.push_tail(&decl->link);
867 // Grammar Note: No 'enum', or 'typedef'.
872 if ($1->specifier->type_specifier != ast_struct) {
873 _mesa_glsl_error(& @1, state, "empty declaration list\n");
876 $$ = new(ctx) ast_declarator_list($1);
877 $$->set_location(yylloc);
880 | fully_specified_type IDENTIFIER
883 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
885 $$ = new(ctx) ast_declarator_list($1);
886 $$->set_location(yylloc);
887 $$->declarations.push_tail(&decl->link);
889 | fully_specified_type IDENTIFIER '[' ']'
892 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
894 $$ = new(ctx) ast_declarator_list($1);
895 $$->set_location(yylloc);
896 $$->declarations.push_tail(&decl->link);
898 | fully_specified_type IDENTIFIER '[' constant_expression ']'
901 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
903 $$ = new(ctx) ast_declarator_list($1);
904 $$->set_location(yylloc);
905 $$->declarations.push_tail(&decl->link);
907 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
910 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
912 $$ = new(ctx) ast_declarator_list($1);
913 $$->set_location(yylloc);
914 $$->declarations.push_tail(&decl->link);
916 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
919 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
921 $$ = new(ctx) ast_declarator_list($1);
922 $$->set_location(yylloc);
923 $$->declarations.push_tail(&decl->link);
925 | fully_specified_type IDENTIFIER '=' initializer
928 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
930 $$ = new(ctx) ast_declarator_list($1);
931 $$->set_location(yylloc);
932 $$->declarations.push_tail(&decl->link);
934 | INVARIANT IDENTIFIER // Vertex only.
937 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
939 $$ = new(ctx) ast_declarator_list(NULL);
940 $$->set_location(yylloc);
941 $$->invariant = true;
943 $$->declarations.push_tail(&decl->link);
947 fully_specified_type:
951 $$ = new(ctx) ast_fully_specified_type();
952 $$->set_location(yylloc);
955 | type_qualifier type_specifier
958 $$ = new(ctx) ast_fully_specified_type();
959 $$->set_location(yylloc);
960 $$->qualifier = $1.q;
965 opt_layout_qualifier:
971 LAYOUT_TOK '(' layout_qualifier_id_list ')'
977 layout_qualifier_id_list:
979 | layout_qualifier_id_list ',' layout_qualifier_id
990 if (state->ARB_fragment_coord_conventions_enable) {
991 bool got_one = false;
993 if (strcmp($1, "origin_upper_left") == 0) {
995 $$.q.origin_upper_left = 1;
996 } else if (strcmp($1, "pixel_center_integer") == 0) {
998 $$.q.pixel_center_integer = 1;
1001 if (state->ARB_fragment_coord_conventions_warn && got_one) {
1002 _mesa_glsl_warning(& @1, state,
1003 "GL_ARB_fragment_coord_conventions layout "
1004 "identifier `%s' used\n", $1);
1008 /* If the identifier didn't match any known layout identifiers,
1012 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1019 interpolation_qualifier:
1020 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1021 | FLAT { $$.i = 0; $$.q.flat = 1; }
1022 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1025 parameter_type_qualifier:
1026 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1031 | interpolation_qualifier type_qualifier
1035 | INVARIANT type_qualifier
1043 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1044 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1045 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1046 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1047 | opt_layout_qualifier IN_TOK { $$.i = 0; $$.q.in = 1; }
1048 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
1049 | CENTROID IN_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1050 | CENTROID OUT_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1051 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1055 type_specifier_no_prec
1056 | precision_qualifier type_specifier_no_prec
1063 type_specifier_no_prec:
1064 type_specifier_nonarray
1065 | type_specifier_nonarray '[' ']'
1068 $$->is_array = true;
1069 $$->array_size = NULL;
1071 | type_specifier_nonarray '[' constant_expression ']'
1074 $$->is_array = true;
1075 $$->array_size = $3;
1079 type_specifier_nonarray:
1080 basic_type_specifier_nonarray
1083 $$ = new(ctx) ast_type_specifier($1);
1084 $$->set_location(yylloc);
1089 $$ = new(ctx) ast_type_specifier($1);
1090 $$->set_location(yylloc);
1095 $$ = new(ctx) ast_type_specifier($1);
1096 $$->set_location(yylloc);
1100 basic_type_specifier_nonarray:
1101 VOID_TOK { $$ = ast_void; }
1102 | FLOAT_TOK { $$ = ast_float; }
1103 | INT_TOK { $$ = ast_int; }
1104 | UINT_TOK { $$ = ast_uint; }
1105 | BOOL_TOK { $$ = ast_bool; }
1106 | VEC2 { $$ = ast_vec2; }
1107 | VEC3 { $$ = ast_vec3; }
1108 | VEC4 { $$ = ast_vec4; }
1109 | BVEC2 { $$ = ast_bvec2; }
1110 | BVEC3 { $$ = ast_bvec3; }
1111 | BVEC4 { $$ = ast_bvec4; }
1112 | IVEC2 { $$ = ast_ivec2; }
1113 | IVEC3 { $$ = ast_ivec3; }
1114 | IVEC4 { $$ = ast_ivec4; }
1115 | UVEC2 { $$ = ast_uvec2; }
1116 | UVEC3 { $$ = ast_uvec3; }
1117 | UVEC4 { $$ = ast_uvec4; }
1118 | MAT2X2 { $$ = ast_mat2; }
1119 | MAT2X3 { $$ = ast_mat2x3; }
1120 | MAT2X4 { $$ = ast_mat2x4; }
1121 | MAT3X2 { $$ = ast_mat3x2; }
1122 | MAT3X3 { $$ = ast_mat3; }
1123 | MAT3X4 { $$ = ast_mat3x4; }
1124 | MAT4X2 { $$ = ast_mat4x2; }
1125 | MAT4X3 { $$ = ast_mat4x3; }
1126 | MAT4X4 { $$ = ast_mat4; }
1127 | SAMPLER1D { $$ = ast_sampler1d; }
1128 | SAMPLER2D { $$ = ast_sampler2d; }
1129 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1130 | SAMPLER3D { $$ = ast_sampler3d; }
1131 | SAMPLERCUBE { $$ = ast_samplercube; }
1132 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1133 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1134 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1135 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1136 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1137 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1138 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1139 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1140 | ISAMPLER1D { $$ = ast_isampler1d; }
1141 | ISAMPLER2D { $$ = ast_isampler2d; }
1142 | ISAMPLER3D { $$ = ast_isampler3d; }
1143 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1144 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1145 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1146 | USAMPLER1D { $$ = ast_usampler1d; }
1147 | USAMPLER2D { $$ = ast_usampler2d; }
1148 | USAMPLER3D { $$ = ast_usampler3d; }
1149 | USAMPLERCUBE { $$ = ast_usamplercube; }
1150 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1151 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1154 precision_qualifier:
1156 if (state->language_version < 130)
1157 _mesa_glsl_error(& @1, state,
1158 "precision qualifier forbidden "
1159 "in GLSL %d.%d (1.30 or later "
1161 state->language_version / 100,
1162 state->language_version % 100);
1164 $$ = ast_precision_high;
1167 if (state->language_version < 130)
1168 _mesa_glsl_error(& @1, state,
1169 "precision qualifier forbidden "
1170 "in GLSL %d.%d (1.30 or later "
1172 state->language_version / 100,
1173 state->language_version % 100);
1175 $$ = ast_precision_medium;
1178 if (state->language_version < 130)
1179 _mesa_glsl_error(& @1, state,
1180 "precision qualifier forbidden "
1181 "in GLSL %d.%d (1.30 or later "
1183 state->language_version / 100,
1184 state->language_version % 100);
1186 $$ = ast_precision_low;
1191 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1194 $$ = new(ctx) ast_struct_specifier($2, $4);
1195 $$->set_location(yylloc);
1197 | STRUCT '{' struct_declaration_list '}'
1200 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1201 $$->set_location(yylloc);
1205 struct_declaration_list:
1208 $$ = (ast_node *) $1;
1209 $1->link.self_link();
1211 | struct_declaration_list struct_declaration
1213 $$ = (ast_node *) $1;
1214 $$->link.insert_before(& $2->link);
1219 type_specifier struct_declarator_list ';'
1222 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1223 type->set_location(yylloc);
1225 type->specifier = $1;
1226 $$ = new(ctx) ast_declarator_list(type);
1227 $$->set_location(yylloc);
1229 $$->declarations.push_degenerate_list_at_head(& $2->link);
1233 struct_declarator_list:
1237 $1->link.self_link();
1239 | struct_declarator_list ',' struct_declarator
1242 $$->link.insert_before(& $3->link);
1250 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1251 $$->set_location(yylloc);
1253 | IDENTIFIER '[' constant_expression ']'
1256 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1257 $$->set_location(yylloc);
1262 assignment_expression
1265 declaration_statement:
1269 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1272 compound_statement { $$ = (ast_node *) $1; }
1277 declaration_statement
1278 | expression_statement
1279 | selection_statement
1280 | switch_statement { $$ = NULL; }
1281 | case_label { $$ = NULL; }
1282 | iteration_statement
1290 $$ = new(ctx) ast_compound_statement(true, NULL);
1291 $$->set_location(yylloc);
1293 | '{' statement_list '}'
1296 $$ = new(ctx) ast_compound_statement(true, $2);
1297 $$->set_location(yylloc);
1301 statement_no_new_scope:
1302 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1306 compound_statement_no_new_scope:
1310 $$ = new(ctx) ast_compound_statement(false, NULL);
1311 $$->set_location(yylloc);
1313 | '{' statement_list '}'
1316 $$ = new(ctx) ast_compound_statement(false, $2);
1317 $$->set_location(yylloc);
1325 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1330 $$->link.self_link();
1332 | statement_list statement
1335 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1339 $$->link.insert_before(& $2->link);
1343 expression_statement:
1347 $$ = new(ctx) ast_expression_statement(NULL);
1348 $$->set_location(yylloc);
1353 $$ = new(ctx) ast_expression_statement($1);
1354 $$->set_location(yylloc);
1358 selection_statement:
1359 IF '(' expression ')' selection_rest_statement
1361 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1363 $$->set_location(yylloc);
1367 selection_rest_statement:
1368 statement ELSE statement
1370 $$.then_statement = $1;
1371 $$.else_statement = $3;
1375 $$.then_statement = $1;
1376 $$.else_statement = NULL;
1383 $$ = (ast_node *) $1;
1385 | fully_specified_type IDENTIFIER '=' initializer
1388 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1389 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1390 decl->set_location(yylloc);
1391 declarator->set_location(yylloc);
1393 declarator->declarations.push_tail(&decl->link);
1399 SWITCH '(' expression ')' compound_statement
1407 iteration_statement:
1408 WHILE '(' condition ')' statement_no_new_scope
1411 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1412 NULL, $3, NULL, $5);
1413 $$->set_location(yylloc);
1415 | DO statement WHILE '(' expression ')' ';'
1418 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1419 NULL, $5, NULL, $2);
1420 $$->set_location(yylloc);
1422 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1425 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1426 $3, $4.cond, $4.rest, $6);
1427 $$->set_location(yylloc);
1432 expression_statement
1433 | declaration_statement
1450 | conditionopt ';' expression
1457 // Grammar Note: No 'goto'. Gotos are not supported.
1462 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1463 $$->set_location(yylloc);
1468 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1469 $$->set_location(yylloc);
1474 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1475 $$->set_location(yylloc);
1477 | RETURN expression ';'
1480 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1481 $$->set_location(yylloc);
1483 | DISCARD ';' // Fragment shader only.
1486 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1487 $$->set_location(yylloc);
1491 external_declaration:
1492 function_definition { $$ = $1; }
1493 | declaration { $$ = $1; }
1494 | pragma_statement { $$ = NULL; }
1497 function_definition:
1498 function_prototype compound_statement_no_new_scope
1501 $$ = new(ctx) ast_function_definition();
1502 $$->set_location(yylloc);