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
113 /* Reserved words that are not actually used in the grammar.
115 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
116 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
117 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
118 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
119 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
120 %token SIZEOF CAST NAMESPACE USING
124 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
125 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
126 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
127 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
128 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
129 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
132 %type <identifier> variable_identifier
133 %type <node> statement
134 %type <node> statement_list
135 %type <node> simple_statement
136 %type <n> precision_qualifier
137 %type <type_qualifier> type_qualifier
138 %type <type_qualifier> storage_qualifier
139 %type <type_qualifier> interpolation_qualifier
140 %type <type_qualifier> layout_qualifier
141 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
142 %type <type_specifier> type_specifier
143 %type <type_specifier> type_specifier_no_prec
144 %type <type_specifier> type_specifier_nonarray
145 %type <n> basic_type_specifier_nonarray
146 %type <fully_specified_type> fully_specified_type
147 %type <function> function_prototype
148 %type <function> function_header
149 %type <function> function_header_with_parameters
150 %type <function> function_declarator
151 %type <parameter_declarator> parameter_declarator
152 %type <parameter_declarator> parameter_declaration
153 %type <type_qualifier> parameter_qualifier
154 %type <type_qualifier> parameter_type_qualifier
155 %type <type_specifier> parameter_type_specifier
156 %type <function_definition> function_definition
157 %type <compound_statement> compound_statement_no_new_scope
158 %type <compound_statement> compound_statement
159 %type <node> statement_no_new_scope
160 %type <node> expression_statement
161 %type <expression> expression
162 %type <expression> primary_expression
163 %type <expression> assignment_expression
164 %type <expression> conditional_expression
165 %type <expression> logical_or_expression
166 %type <expression> logical_xor_expression
167 %type <expression> logical_and_expression
168 %type <expression> inclusive_or_expression
169 %type <expression> exclusive_or_expression
170 %type <expression> and_expression
171 %type <expression> equality_expression
172 %type <expression> relational_expression
173 %type <expression> shift_expression
174 %type <expression> additive_expression
175 %type <expression> multiplicative_expression
176 %type <expression> unary_expression
177 %type <expression> constant_expression
178 %type <expression> integer_expression
179 %type <expression> postfix_expression
180 %type <expression> function_call_header_with_parameters
181 %type <expression> function_call_header_no_parameters
182 %type <expression> function_call_header
183 %type <expression> function_call_generic
184 %type <expression> function_call_or_method
185 %type <expression> function_call
186 %type <n> assignment_operator
187 %type <n> unary_operator
188 %type <expression> function_identifier
189 %type <node> external_declaration
190 %type <declarator_list> init_declarator_list
191 %type <declarator_list> single_declaration
192 %type <expression> initializer
193 %type <node> declaration
194 %type <node> declaration_statement
195 %type <node> jump_statement
196 %type <struct_specifier> struct_specifier
197 %type <node> struct_declaration_list
198 %type <declarator_list> struct_declaration
199 %type <declaration> struct_declarator
200 %type <declaration> struct_declarator_list
201 %type <node> selection_statement
202 %type <selection_rest_statement> selection_rest_statement
203 %type <node> iteration_statement
204 %type <node> condition
205 %type <node> conditionopt
206 %type <node> for_init_statement
207 %type <for_rest_statement> for_rest_statement
211 version_statement extension_statement_list
213 _mesa_glsl_initialize_types(state);
215 external_declaration_list
219 /* blank - no #version specified: defaults are already set */
220 | VERSION INTCONSTANT EOL
224 state->es_shader = true;
228 /* FINISHME: Check against implementation support versions. */
229 state->language_version = $2;
232 _mesa_glsl_error(& @2, state, "Shading language version"
233 "%u is not supported\n", $2);
241 | PRAGMA_DEBUG_OFF EOL
242 | PRAGMA_OPTIMIZE_ON EOL
243 | PRAGMA_OPTIMIZE_OFF EOL
246 extension_statement_list:
248 | extension_statement_list extension_statement
252 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
254 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
260 external_declaration_list:
263 /* FINISHME: The NULL test is only required because 'precision'
264 * FINISHME: statements are not yet supported.
267 state->translation_unit.push_tail(& $1->link);
269 | external_declaration_list external_declaration
271 /* FINISHME: The NULL test is only required because 'precision'
272 * FINISHME: statements are not yet supported.
275 state->translation_unit.push_tail(& $2->link);
287 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
288 $$->set_location(yylloc);
289 $$->primary_expression.identifier = $1;
294 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
295 $$->set_location(yylloc);
296 $$->primary_expression.int_constant = $1;
301 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
302 $$->set_location(yylloc);
303 $$->primary_expression.uint_constant = $1;
308 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
309 $$->set_location(yylloc);
310 $$->primary_expression.float_constant = $1;
315 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
316 $$->set_location(yylloc);
317 $$->primary_expression.bool_constant = $1;
327 | postfix_expression '[' integer_expression ']'
330 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
331 $$->set_location(yylloc);
337 | postfix_expression '.' IDENTIFIER
340 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
341 $$->set_location(yylloc);
342 $$->primary_expression.identifier = $3;
344 | postfix_expression INC_OP
347 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
348 $$->set_location(yylloc);
350 | postfix_expression DEC_OP
353 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
354 $$->set_location(yylloc);
363 function_call_or_method
366 function_call_or_method:
367 function_call_generic
368 | postfix_expression '.' function_call_generic
371 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
372 $$->set_location(yylloc);
376 function_call_generic:
377 function_call_header_with_parameters ')'
378 | function_call_header_no_parameters ')'
381 function_call_header_no_parameters:
382 function_call_header VOID_TOK
383 | function_call_header
386 function_call_header_with_parameters:
387 function_call_header assignment_expression
390 $$->set_location(yylloc);
391 $$->expressions.push_tail(& $2->link);
393 | function_call_header_with_parameters ',' assignment_expression
396 $$->set_location(yylloc);
397 $$->expressions.push_tail(& $3->link);
401 // Grammar Note: Constructors look like functions, but lexical
402 // analysis recognized most of them as keywords. They are now
403 // recognized through "type_specifier".
404 function_call_header:
405 function_identifier '('
412 $$ = new(ctx) ast_function_expression($1);
413 $$->set_location(yylloc);
418 ast_expression *callee = new(ctx) ast_expression($1);
419 $$ = new(ctx) ast_function_expression(callee);
420 $$->set_location(yylloc);
425 ast_expression *callee = new(ctx) ast_expression($1);
426 $$ = new(ctx) ast_function_expression(callee);
427 $$->set_location(yylloc);
431 // Grammar Note: No traditional style type casts.
434 | INC_OP unary_expression
437 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
438 $$->set_location(yylloc);
440 | DEC_OP unary_expression
443 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
444 $$->set_location(yylloc);
446 | unary_operator unary_expression
449 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
450 $$->set_location(yylloc);
454 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
456 '+' { $$ = ast_plus; }
457 | '-' { $$ = ast_neg; }
458 | '!' { $$ = ast_logic_not; }
459 | '~' { $$ = ast_bit_not; }
462 multiplicative_expression:
464 | multiplicative_expression '*' unary_expression
467 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
468 $$->set_location(yylloc);
470 | multiplicative_expression '/' unary_expression
473 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
474 $$->set_location(yylloc);
476 | multiplicative_expression '%' unary_expression
479 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
480 $$->set_location(yylloc);
485 multiplicative_expression
486 | additive_expression '+' multiplicative_expression
489 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
490 $$->set_location(yylloc);
492 | additive_expression '-' multiplicative_expression
495 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
496 $$->set_location(yylloc);
502 | shift_expression LEFT_OP additive_expression
505 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
506 $$->set_location(yylloc);
508 | shift_expression RIGHT_OP additive_expression
511 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
512 $$->set_location(yylloc);
516 relational_expression:
518 | relational_expression '<' shift_expression
521 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
522 $$->set_location(yylloc);
524 | relational_expression '>' shift_expression
527 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
528 $$->set_location(yylloc);
530 | relational_expression LE_OP shift_expression
533 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
534 $$->set_location(yylloc);
536 | relational_expression GE_OP shift_expression
539 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
540 $$->set_location(yylloc);
545 relational_expression
546 | equality_expression EQ_OP relational_expression
549 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
550 $$->set_location(yylloc);
552 | equality_expression NE_OP relational_expression
555 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
556 $$->set_location(yylloc);
562 | and_expression '&' equality_expression
565 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
566 $$->set_location(yylloc);
570 exclusive_or_expression:
572 | exclusive_or_expression '^' and_expression
575 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
576 $$->set_location(yylloc);
580 inclusive_or_expression:
581 exclusive_or_expression
582 | inclusive_or_expression '|' exclusive_or_expression
585 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
586 $$->set_location(yylloc);
590 logical_and_expression:
591 inclusive_or_expression
592 | logical_and_expression AND_OP inclusive_or_expression
595 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
596 $$->set_location(yylloc);
600 logical_xor_expression:
601 logical_and_expression
602 | logical_xor_expression XOR_OP logical_and_expression
605 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
606 $$->set_location(yylloc);
610 logical_or_expression:
611 logical_xor_expression
612 | logical_or_expression OR_OP logical_xor_expression
615 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
616 $$->set_location(yylloc);
620 conditional_expression:
621 logical_or_expression
622 | logical_or_expression '?' expression ':' assignment_expression
625 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
626 $$->set_location(yylloc);
630 assignment_expression:
631 conditional_expression
632 | unary_expression assignment_operator assignment_expression
635 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
636 $$->set_location(yylloc);
641 '=' { $$ = ast_assign; }
642 | MUL_ASSIGN { $$ = ast_mul_assign; }
643 | DIV_ASSIGN { $$ = ast_div_assign; }
644 | MOD_ASSIGN { $$ = ast_mod_assign; }
645 | ADD_ASSIGN { $$ = ast_add_assign; }
646 | SUB_ASSIGN { $$ = ast_sub_assign; }
647 | LEFT_ASSIGN { $$ = ast_ls_assign; }
648 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
649 | AND_ASSIGN { $$ = ast_and_assign; }
650 | XOR_ASSIGN { $$ = ast_xor_assign; }
651 | OR_ASSIGN { $$ = ast_or_assign; }
655 assignment_expression
659 | expression ',' assignment_expression
662 if ($1->oper != ast_sequence) {
663 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
664 $$->set_location(yylloc);
665 $$->expressions.push_tail(& $1->link);
670 $$->expressions.push_tail(& $3->link);
675 conditional_expression
679 function_prototype ';'
683 | init_declarator_list ';'
687 | PRECISION precision_qualifier type_specifier_no_prec ';'
689 if (($3->type_specifier != ast_float)
690 && ($3->type_specifier != ast_int)) {
691 _mesa_glsl_error(& @3, state, "global precision qualifier can "
692 "only be applied to `int' or `float'\n");
696 $$ = NULL; /* FINISHME */
701 function_declarator ')'
706 | function_header_with_parameters
709 function_header_with_parameters:
710 function_header parameter_declaration
713 $$->parameters.push_tail(& $2->link);
715 | function_header_with_parameters ',' parameter_declaration
718 $$->parameters.push_tail(& $3->link);
723 fully_specified_type IDENTIFIER '('
726 $$ = new(ctx) ast_function();
727 $$->set_location(yylloc);
728 $$->return_type = $1;
733 parameter_declarator:
734 type_specifier IDENTIFIER
737 $$ = new(ctx) ast_parameter_declarator();
738 $$->set_location(yylloc);
739 $$->type = new(ctx) ast_fully_specified_type();
740 $$->type->set_location(yylloc);
741 $$->type->specifier = $1;
744 | type_specifier IDENTIFIER '[' constant_expression ']'
747 $$ = new(ctx) ast_parameter_declarator();
748 $$->set_location(yylloc);
749 $$->type = new(ctx) ast_fully_specified_type();
750 $$->type->set_location(yylloc);
751 $$->type->specifier = $1;
758 parameter_declaration:
759 parameter_type_qualifier parameter_qualifier parameter_declarator
761 $1.flags.i |= $2.flags.i;
764 $$->type->qualifier = $1;
766 | parameter_qualifier parameter_declarator
769 $$->type->qualifier = $1;
771 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
774 $1.flags.i |= $2.flags.i;
776 $$ = new(ctx) ast_parameter_declarator();
777 $$->set_location(yylloc);
778 $$->type = new(ctx) ast_fully_specified_type();
779 $$->type->qualifier = $1;
780 $$->type->specifier = $3;
782 | parameter_qualifier parameter_type_specifier
785 $$ = new(ctx) ast_parameter_declarator();
786 $$->set_location(yylloc);
787 $$->type = new(ctx) ast_fully_specified_type();
788 $$->type->qualifier = $1;
789 $$->type->specifier = $2;
796 memset(& $$, 0, sizeof($$));
800 memset(& $$, 0, sizeof($$));
805 memset(& $$, 0, sizeof($$));
810 memset(& $$, 0, sizeof($$));
816 parameter_type_specifier:
820 init_declarator_list:
822 | init_declarator_list ',' IDENTIFIER
825 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
826 decl->set_location(yylloc);
829 $$->declarations.push_tail(&decl->link);
831 | init_declarator_list ',' IDENTIFIER '[' ']'
834 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
835 decl->set_location(yylloc);
838 $$->declarations.push_tail(&decl->link);
840 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
843 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
844 decl->set_location(yylloc);
847 $$->declarations.push_tail(&decl->link);
849 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
852 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
853 decl->set_location(yylloc);
856 $$->declarations.push_tail(&decl->link);
858 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
861 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
862 decl->set_location(yylloc);
865 $$->declarations.push_tail(&decl->link);
867 | init_declarator_list ',' IDENTIFIER '=' initializer
870 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
871 decl->set_location(yylloc);
874 $$->declarations.push_tail(&decl->link);
878 // Grammar Note: No 'enum', or 'typedef'.
883 if ($1->specifier->type_specifier != ast_struct) {
884 _mesa_glsl_error(& @1, state, "empty declaration list\n");
887 $$ = new(ctx) ast_declarator_list($1);
888 $$->set_location(yylloc);
891 | fully_specified_type IDENTIFIER
894 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
896 $$ = new(ctx) ast_declarator_list($1);
897 $$->set_location(yylloc);
898 $$->declarations.push_tail(&decl->link);
900 | fully_specified_type IDENTIFIER '[' ']'
903 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
905 $$ = new(ctx) ast_declarator_list($1);
906 $$->set_location(yylloc);
907 $$->declarations.push_tail(&decl->link);
909 | fully_specified_type IDENTIFIER '[' constant_expression ']'
912 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
914 $$ = new(ctx) ast_declarator_list($1);
915 $$->set_location(yylloc);
916 $$->declarations.push_tail(&decl->link);
918 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
921 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
923 $$ = new(ctx) ast_declarator_list($1);
924 $$->set_location(yylloc);
925 $$->declarations.push_tail(&decl->link);
927 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
930 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
932 $$ = new(ctx) ast_declarator_list($1);
933 $$->set_location(yylloc);
934 $$->declarations.push_tail(&decl->link);
936 | fully_specified_type IDENTIFIER '=' initializer
939 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
941 $$ = new(ctx) ast_declarator_list($1);
942 $$->set_location(yylloc);
943 $$->declarations.push_tail(&decl->link);
945 | INVARIANT IDENTIFIER // Vertex only.
948 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
950 $$ = new(ctx) ast_declarator_list(NULL);
951 $$->set_location(yylloc);
952 $$->invariant = true;
954 $$->declarations.push_tail(&decl->link);
958 fully_specified_type:
962 $$ = new(ctx) ast_fully_specified_type();
963 $$->set_location(yylloc);
966 | type_qualifier type_specifier
969 $$ = new(ctx) ast_fully_specified_type();
970 $$->set_location(yylloc);
977 LAYOUT_TOK '(' layout_qualifier_id_list ')'
983 layout_qualifier_id_list:
985 | layout_qualifier_id_list ',' layout_qualifier_id
987 if (($1.flags.i & $3.flags.i) != 0) {
988 _mesa_glsl_error(& @3, state,
989 "duplicate layout qualifiers used\n");
993 $$.flags.i = $1.flags.i | $3.flags.i;
995 if ($1.flags.q.explicit_location)
996 $$.location = $1.location;
998 if ($3.flags.q.explicit_location)
999 $$.location = $3.location;
1003 layout_qualifier_id:
1006 bool got_one = false;
1008 memset(& $$, 0, sizeof($$));
1010 if (state->ARB_fragment_coord_conventions_enable) {
1011 if (strcmp($1, "origin_upper_left") == 0) {
1013 $$.flags.q.origin_upper_left = 1;
1014 } else if (strcmp($1, "pixel_center_integer") == 0) {
1016 $$.flags.q.pixel_center_integer = 1;
1020 /* If the identifier didn't match any known layout identifiers,
1024 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1027 } else if (state->ARB_fragment_coord_conventions_warn) {
1028 _mesa_glsl_warning(& @1, state,
1029 "GL_ARB_fragment_coord_conventions layout "
1030 "identifier `%s' used\n", $1);
1033 | IDENTIFIER '=' INTCONSTANT
1035 bool got_one = false;
1037 memset(& $$, 0, sizeof($$));
1039 if (state->ARB_explicit_attrib_location_enable) {
1040 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1041 * FINISHME: GLSL 1.30 (or later) are supported.
1043 if (strcmp("location", $1) == 0) {
1046 $$.flags.q.explicit_location = 1;
1051 _mesa_glsl_error(& @3, state,
1052 "invalid location %d specified\n", $3);
1058 /* If the identifier didn't match any known layout identifiers,
1062 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1065 } else if (state->ARB_explicit_attrib_location_warn) {
1066 _mesa_glsl_warning(& @1, state,
1067 "GL_ARB_explicit_attrib_location layout "
1068 "identifier `%s' used\n", $1);
1073 interpolation_qualifier:
1076 memset(& $$, 0, sizeof($$));
1077 $$.flags.q.smooth = 1;
1081 memset(& $$, 0, sizeof($$));
1082 $$.flags.q.flat = 1;
1086 memset(& $$, 0, sizeof($$));
1087 $$.flags.q.noperspective = 1;
1091 parameter_type_qualifier:
1094 memset(& $$, 0, sizeof($$));
1095 $$.flags.q.constant = 1;
1102 | layout_qualifier storage_qualifier
1105 $$.flags.i |= $2.flags.i;
1107 | interpolation_qualifier
1108 | interpolation_qualifier storage_qualifier
1111 $$.flags.i |= $2.flags.i;
1113 | INVARIANT storage_qualifier
1116 $$.flags.q.invariant = 1;
1118 | INVARIANT interpolation_qualifier storage_qualifier
1121 $$.flags.i |= $3.flags.i;
1122 $$.flags.q.invariant = 1;
1126 memset(& $$, 0, sizeof($$));
1127 $$.flags.q.invariant = 1;
1134 memset(& $$, 0, sizeof($$));
1135 $$.flags.q.constant = 1;
1139 memset(& $$, 0, sizeof($$));
1140 $$.flags.q.attribute = 1;
1144 memset(& $$, 0, sizeof($$));
1145 $$.flags.q.varying = 1;
1149 memset(& $$, 0, sizeof($$));
1150 $$.flags.q.centroid = 1;
1151 $$.flags.q.varying = 1;
1155 memset(& $$, 0, sizeof($$));
1160 memset(& $$, 0, sizeof($$));
1165 memset(& $$, 0, sizeof($$));
1166 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1170 memset(& $$, 0, sizeof($$));
1171 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1175 memset(& $$, 0, sizeof($$));
1176 $$.flags.q.uniform = 1;
1181 type_specifier_no_prec
1182 | precision_qualifier type_specifier_no_prec
1189 type_specifier_no_prec:
1190 type_specifier_nonarray
1191 | type_specifier_nonarray '[' ']'
1194 $$->is_array = true;
1195 $$->array_size = NULL;
1197 | type_specifier_nonarray '[' constant_expression ']'
1200 $$->is_array = true;
1201 $$->array_size = $3;
1205 type_specifier_nonarray:
1206 basic_type_specifier_nonarray
1209 $$ = new(ctx) ast_type_specifier($1);
1210 $$->set_location(yylloc);
1215 $$ = new(ctx) ast_type_specifier($1);
1216 $$->set_location(yylloc);
1221 $$ = new(ctx) ast_type_specifier($1);
1222 $$->set_location(yylloc);
1226 basic_type_specifier_nonarray:
1227 VOID_TOK { $$ = ast_void; }
1228 | FLOAT_TOK { $$ = ast_float; }
1229 | INT_TOK { $$ = ast_int; }
1230 | UINT_TOK { $$ = ast_uint; }
1231 | BOOL_TOK { $$ = ast_bool; }
1232 | VEC2 { $$ = ast_vec2; }
1233 | VEC3 { $$ = ast_vec3; }
1234 | VEC4 { $$ = ast_vec4; }
1235 | BVEC2 { $$ = ast_bvec2; }
1236 | BVEC3 { $$ = ast_bvec3; }
1237 | BVEC4 { $$ = ast_bvec4; }
1238 | IVEC2 { $$ = ast_ivec2; }
1239 | IVEC3 { $$ = ast_ivec3; }
1240 | IVEC4 { $$ = ast_ivec4; }
1241 | UVEC2 { $$ = ast_uvec2; }
1242 | UVEC3 { $$ = ast_uvec3; }
1243 | UVEC4 { $$ = ast_uvec4; }
1244 | MAT2X2 { $$ = ast_mat2; }
1245 | MAT2X3 { $$ = ast_mat2x3; }
1246 | MAT2X4 { $$ = ast_mat2x4; }
1247 | MAT3X2 { $$ = ast_mat3x2; }
1248 | MAT3X3 { $$ = ast_mat3; }
1249 | MAT3X4 { $$ = ast_mat3x4; }
1250 | MAT4X2 { $$ = ast_mat4x2; }
1251 | MAT4X3 { $$ = ast_mat4x3; }
1252 | MAT4X4 { $$ = ast_mat4; }
1253 | SAMPLER1D { $$ = ast_sampler1d; }
1254 | SAMPLER2D { $$ = ast_sampler2d; }
1255 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1256 | SAMPLER3D { $$ = ast_sampler3d; }
1257 | SAMPLERCUBE { $$ = ast_samplercube; }
1258 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1259 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1260 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1261 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1262 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1263 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1264 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1265 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1266 | ISAMPLER1D { $$ = ast_isampler1d; }
1267 | ISAMPLER2D { $$ = ast_isampler2d; }
1268 | ISAMPLER3D { $$ = ast_isampler3d; }
1269 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1270 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1271 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1272 | USAMPLER1D { $$ = ast_usampler1d; }
1273 | USAMPLER2D { $$ = ast_usampler2d; }
1274 | USAMPLER3D { $$ = ast_usampler3d; }
1275 | USAMPLERCUBE { $$ = ast_usamplercube; }
1276 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1277 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1280 precision_qualifier:
1282 if (!state->es_shader && state->language_version < 130)
1283 _mesa_glsl_error(& @1, state,
1284 "precision qualifier forbidden "
1285 "in GLSL %d.%d (1.30 or later "
1287 state->language_version / 100,
1288 state->language_version % 100);
1290 $$ = ast_precision_high;
1293 if (!state->es_shader && state->language_version < 130)
1294 _mesa_glsl_error(& @1, state,
1295 "precision qualifier forbidden "
1296 "in GLSL %d.%d (1.30 or later "
1298 state->language_version / 100,
1299 state->language_version % 100);
1301 $$ = ast_precision_medium;
1304 if (!state->es_shader && state->language_version < 130)
1305 _mesa_glsl_error(& @1, state,
1306 "precision qualifier forbidden "
1307 "in GLSL %d.%d (1.30 or later "
1309 state->language_version / 100,
1310 state->language_version % 100);
1312 $$ = ast_precision_low;
1317 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1320 $$ = new(ctx) ast_struct_specifier($2, $4);
1321 $$->set_location(yylloc);
1323 | STRUCT '{' struct_declaration_list '}'
1326 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1327 $$->set_location(yylloc);
1331 struct_declaration_list:
1334 $$ = (ast_node *) $1;
1335 $1->link.self_link();
1337 | struct_declaration_list struct_declaration
1339 $$ = (ast_node *) $1;
1340 $$->link.insert_before(& $2->link);
1345 type_specifier struct_declarator_list ';'
1348 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1349 type->set_location(yylloc);
1351 type->specifier = $1;
1352 $$ = new(ctx) ast_declarator_list(type);
1353 $$->set_location(yylloc);
1355 $$->declarations.push_degenerate_list_at_head(& $2->link);
1359 struct_declarator_list:
1363 $1->link.self_link();
1365 | struct_declarator_list ',' struct_declarator
1368 $$->link.insert_before(& $3->link);
1376 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1377 $$->set_location(yylloc);
1379 | IDENTIFIER '[' constant_expression ']'
1382 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1383 $$->set_location(yylloc);
1388 assignment_expression
1391 declaration_statement:
1395 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1398 compound_statement { $$ = (ast_node *) $1; }
1403 declaration_statement
1404 | expression_statement
1405 | selection_statement
1406 | switch_statement { $$ = NULL; }
1407 | case_label { $$ = NULL; }
1408 | iteration_statement
1416 $$ = new(ctx) ast_compound_statement(true, NULL);
1417 $$->set_location(yylloc);
1419 | '{' statement_list '}'
1422 $$ = new(ctx) ast_compound_statement(true, $2);
1423 $$->set_location(yylloc);
1427 statement_no_new_scope:
1428 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1432 compound_statement_no_new_scope:
1436 $$ = new(ctx) ast_compound_statement(false, NULL);
1437 $$->set_location(yylloc);
1439 | '{' statement_list '}'
1442 $$ = new(ctx) ast_compound_statement(false, $2);
1443 $$->set_location(yylloc);
1451 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1456 $$->link.self_link();
1458 | statement_list statement
1461 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1465 $$->link.insert_before(& $2->link);
1469 expression_statement:
1473 $$ = new(ctx) ast_expression_statement(NULL);
1474 $$->set_location(yylloc);
1479 $$ = new(ctx) ast_expression_statement($1);
1480 $$->set_location(yylloc);
1484 selection_statement:
1485 IF '(' expression ')' selection_rest_statement
1487 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1489 $$->set_location(yylloc);
1493 selection_rest_statement:
1494 statement ELSE statement
1496 $$.then_statement = $1;
1497 $$.else_statement = $3;
1501 $$.then_statement = $1;
1502 $$.else_statement = NULL;
1509 $$ = (ast_node *) $1;
1511 | fully_specified_type IDENTIFIER '=' initializer
1514 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1515 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1516 decl->set_location(yylloc);
1517 declarator->set_location(yylloc);
1519 declarator->declarations.push_tail(&decl->link);
1525 SWITCH '(' expression ')' compound_statement
1533 iteration_statement:
1534 WHILE '(' condition ')' statement_no_new_scope
1537 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1538 NULL, $3, NULL, $5);
1539 $$->set_location(yylloc);
1541 | DO statement WHILE '(' expression ')' ';'
1544 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1545 NULL, $5, NULL, $2);
1546 $$->set_location(yylloc);
1548 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1551 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1552 $3, $4.cond, $4.rest, $6);
1553 $$->set_location(yylloc);
1558 expression_statement
1559 | declaration_statement
1576 | conditionopt ';' expression
1583 // Grammar Note: No 'goto'. Gotos are not supported.
1588 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1589 $$->set_location(yylloc);
1594 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1595 $$->set_location(yylloc);
1600 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1601 $$->set_location(yylloc);
1603 | RETURN expression ';'
1606 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1607 $$->set_location(yylloc);
1609 | DISCARD ';' // Fragment shader only.
1612 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1613 $$->set_location(yylloc);
1617 external_declaration:
1618 function_definition { $$ = $1; }
1619 | declaration { $$ = $1; }
1620 | pragma_statement { $$ = NULL; }
1623 function_definition:
1624 function_prototype compound_statement_no_new_scope
1627 $$ = new(ctx) ast_function_definition();
1628 $$->set_location(yylloc);