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: defaults are already set */
222 | VERSION INTCONSTANT EOL
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_or, $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
764 $$->type->qualifier = $1.q;
766 | parameter_qualifier parameter_declarator
769 $$->type->qualifier = $1.q;
771 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
776 $$ = new(ctx) ast_parameter_declarator();
777 $$->set_location(yylloc);
778 $$->type = new(ctx) ast_fully_specified_type();
779 $$->type->qualifier = $1.q;
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.q;
789 $$->type->specifier = $2;
794 /* empty */ { $$.i = 0; }
795 | IN_TOK { $$.i = 0; $$.q.in = 1; }
796 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
797 | INOUT_TOK { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
800 parameter_type_specifier:
804 init_declarator_list:
806 | init_declarator_list ',' IDENTIFIER
809 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
810 decl->set_location(yylloc);
813 $$->declarations.push_tail(&decl->link);
815 | init_declarator_list ',' IDENTIFIER '[' ']'
818 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
819 decl->set_location(yylloc);
822 $$->declarations.push_tail(&decl->link);
824 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
827 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
828 decl->set_location(yylloc);
831 $$->declarations.push_tail(&decl->link);
833 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
836 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
837 decl->set_location(yylloc);
840 $$->declarations.push_tail(&decl->link);
842 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
845 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
846 decl->set_location(yylloc);
849 $$->declarations.push_tail(&decl->link);
851 | init_declarator_list ',' IDENTIFIER '=' initializer
854 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
855 decl->set_location(yylloc);
858 $$->declarations.push_tail(&decl->link);
862 // Grammar Note: No 'enum', or 'typedef'.
867 if ($1->specifier->type_specifier != ast_struct) {
868 _mesa_glsl_error(& @1, state, "empty declaration list\n");
871 $$ = new(ctx) ast_declarator_list($1);
872 $$->set_location(yylloc);
875 | fully_specified_type IDENTIFIER
878 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
880 $$ = new(ctx) ast_declarator_list($1);
881 $$->set_location(yylloc);
882 $$->declarations.push_tail(&decl->link);
884 | fully_specified_type IDENTIFIER '[' ']'
887 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
889 $$ = new(ctx) ast_declarator_list($1);
890 $$->set_location(yylloc);
891 $$->declarations.push_tail(&decl->link);
893 | fully_specified_type IDENTIFIER '[' constant_expression ']'
896 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
898 $$ = new(ctx) ast_declarator_list($1);
899 $$->set_location(yylloc);
900 $$->declarations.push_tail(&decl->link);
902 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
905 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
907 $$ = new(ctx) ast_declarator_list($1);
908 $$->set_location(yylloc);
909 $$->declarations.push_tail(&decl->link);
911 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
914 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
916 $$ = new(ctx) ast_declarator_list($1);
917 $$->set_location(yylloc);
918 $$->declarations.push_tail(&decl->link);
920 | fully_specified_type IDENTIFIER '=' initializer
923 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
925 $$ = new(ctx) ast_declarator_list($1);
926 $$->set_location(yylloc);
927 $$->declarations.push_tail(&decl->link);
929 | INVARIANT IDENTIFIER // Vertex only.
932 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
934 $$ = new(ctx) ast_declarator_list(NULL);
935 $$->set_location(yylloc);
936 $$->invariant = true;
938 $$->declarations.push_tail(&decl->link);
942 fully_specified_type:
946 $$ = new(ctx) ast_fully_specified_type();
947 $$->set_location(yylloc);
950 | type_qualifier type_specifier
953 $$ = new(ctx) ast_fully_specified_type();
954 $$->set_location(yylloc);
955 $$->qualifier = $1.q;
960 opt_layout_qualifier:
966 LAYOUT_TOK '(' layout_qualifier_id_list ')'
972 layout_qualifier_id_list:
974 | layout_qualifier_id_list ',' layout_qualifier_id
985 if (state->ARB_fragment_coord_conventions_enable) {
986 bool got_one = false;
988 if (strcmp($1, "origin_upper_left") == 0) {
990 $$.q.origin_upper_left = 1;
991 } else if (strcmp($1, "pixel_center_integer") == 0) {
993 $$.q.pixel_center_integer = 1;
996 if (state->ARB_fragment_coord_conventions_warn && got_one) {
997 _mesa_glsl_warning(& @1, state,
998 "GL_ARB_fragment_coord_conventions layout "
999 "identifier `%s' used\n", $1);
1003 /* If the identifier didn't match any known layout identifiers,
1007 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1014 interpolation_qualifier:
1015 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1016 | FLAT { $$.i = 0; $$.q.flat = 1; }
1017 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1020 parameter_type_qualifier:
1021 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1026 | interpolation_qualifier type_qualifier
1030 | INVARIANT type_qualifier
1038 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1039 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1040 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1041 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1042 | opt_layout_qualifier IN_TOK { $$.i = 0; $$.q.in = 1; }
1043 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
1044 | CENTROID IN_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1045 | CENTROID OUT_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1046 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1050 type_specifier_no_prec
1051 | precision_qualifier type_specifier_no_prec
1058 type_specifier_no_prec:
1059 type_specifier_nonarray
1060 | type_specifier_nonarray '[' ']'
1063 $$->is_array = true;
1064 $$->array_size = NULL;
1066 | type_specifier_nonarray '[' constant_expression ']'
1069 $$->is_array = true;
1070 $$->array_size = $3;
1074 type_specifier_nonarray:
1075 basic_type_specifier_nonarray
1078 $$ = new(ctx) ast_type_specifier($1);
1079 $$->set_location(yylloc);
1084 $$ = new(ctx) ast_type_specifier($1);
1085 $$->set_location(yylloc);
1090 $$ = new(ctx) ast_type_specifier($1);
1091 $$->set_location(yylloc);
1095 basic_type_specifier_nonarray:
1096 VOID_TOK { $$ = ast_void; }
1097 | FLOAT_TOK { $$ = ast_float; }
1098 | INT_TOK { $$ = ast_int; }
1099 | UINT_TOK { $$ = ast_uint; }
1100 | BOOL_TOK { $$ = ast_bool; }
1101 | VEC2 { $$ = ast_vec2; }
1102 | VEC3 { $$ = ast_vec3; }
1103 | VEC4 { $$ = ast_vec4; }
1104 | BVEC2 { $$ = ast_bvec2; }
1105 | BVEC3 { $$ = ast_bvec3; }
1106 | BVEC4 { $$ = ast_bvec4; }
1107 | IVEC2 { $$ = ast_ivec2; }
1108 | IVEC3 { $$ = ast_ivec3; }
1109 | IVEC4 { $$ = ast_ivec4; }
1110 | UVEC2 { $$ = ast_uvec2; }
1111 | UVEC3 { $$ = ast_uvec3; }
1112 | UVEC4 { $$ = ast_uvec4; }
1113 | MAT2X2 { $$ = ast_mat2; }
1114 | MAT2X3 { $$ = ast_mat2x3; }
1115 | MAT2X4 { $$ = ast_mat2x4; }
1116 | MAT3X2 { $$ = ast_mat3x2; }
1117 | MAT3X3 { $$ = ast_mat3; }
1118 | MAT3X4 { $$ = ast_mat3x4; }
1119 | MAT4X2 { $$ = ast_mat4x2; }
1120 | MAT4X3 { $$ = ast_mat4x3; }
1121 | MAT4X4 { $$ = ast_mat4; }
1122 | SAMPLER1D { $$ = ast_sampler1d; }
1123 | SAMPLER2D { $$ = ast_sampler2d; }
1124 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1125 | SAMPLER3D { $$ = ast_sampler3d; }
1126 | SAMPLERCUBE { $$ = ast_samplercube; }
1127 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1128 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1129 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1130 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1131 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1132 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1133 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1134 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1135 | ISAMPLER1D { $$ = ast_isampler1d; }
1136 | ISAMPLER2D { $$ = ast_isampler2d; }
1137 | ISAMPLER3D { $$ = ast_isampler3d; }
1138 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1139 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1140 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1141 | USAMPLER1D { $$ = ast_usampler1d; }
1142 | USAMPLER2D { $$ = ast_usampler2d; }
1143 | USAMPLER3D { $$ = ast_usampler3d; }
1144 | USAMPLERCUBE { $$ = ast_usamplercube; }
1145 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1146 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1149 precision_qualifier:
1151 if (state->language_version < 130)
1152 _mesa_glsl_error(& @1, state,
1153 "precision qualifier forbidden "
1154 "in GLSL %d.%d (1.30 or later "
1156 state->language_version / 100,
1157 state->language_version % 100);
1159 $$ = ast_precision_high;
1162 if (state->language_version < 130)
1163 _mesa_glsl_error(& @1, state,
1164 "precision qualifier forbidden "
1165 "in GLSL %d.%d (1.30 or later "
1167 state->language_version / 100,
1168 state->language_version % 100);
1170 $$ = ast_precision_medium;
1173 if (state->language_version < 130)
1174 _mesa_glsl_error(& @1, state,
1175 "precision qualifier forbidden "
1176 "in GLSL %d.%d (1.30 or later "
1178 state->language_version / 100,
1179 state->language_version % 100);
1181 $$ = ast_precision_low;
1186 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1189 $$ = new(ctx) ast_struct_specifier($2, $4);
1190 $$->set_location(yylloc);
1192 | STRUCT '{' struct_declaration_list '}'
1195 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1196 $$->set_location(yylloc);
1200 struct_declaration_list:
1203 $$ = (ast_node *) $1;
1204 $1->link.self_link();
1206 | struct_declaration_list struct_declaration
1208 $$ = (ast_node *) $1;
1209 $$->link.insert_before(& $2->link);
1214 type_specifier struct_declarator_list ';'
1217 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1218 type->set_location(yylloc);
1220 type->specifier = $1;
1221 $$ = new(ctx) ast_declarator_list(type);
1222 $$->set_location(yylloc);
1224 $$->declarations.push_degenerate_list_at_head(& $2->link);
1228 struct_declarator_list:
1232 $1->link.self_link();
1234 | struct_declarator_list ',' struct_declarator
1237 $$->link.insert_before(& $3->link);
1245 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1246 $$->set_location(yylloc);
1248 | IDENTIFIER '[' constant_expression ']'
1251 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1252 $$->set_location(yylloc);
1257 assignment_expression
1260 declaration_statement:
1264 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1267 compound_statement { $$ = (ast_node *) $1; }
1272 declaration_statement
1273 | expression_statement
1274 | selection_statement
1275 | switch_statement { $$ = NULL; }
1276 | case_label { $$ = NULL; }
1277 | iteration_statement
1285 $$ = new(ctx) ast_compound_statement(true, NULL);
1286 $$->set_location(yylloc);
1288 | '{' statement_list '}'
1291 $$ = new(ctx) ast_compound_statement(true, $2);
1292 $$->set_location(yylloc);
1296 statement_no_new_scope:
1297 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1301 compound_statement_no_new_scope:
1305 $$ = new(ctx) ast_compound_statement(false, NULL);
1306 $$->set_location(yylloc);
1308 | '{' statement_list '}'
1311 $$ = new(ctx) ast_compound_statement(false, $2);
1312 $$->set_location(yylloc);
1320 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1325 $$->link.self_link();
1327 | statement_list statement
1330 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1334 $$->link.insert_before(& $2->link);
1338 expression_statement:
1342 $$ = new(ctx) ast_expression_statement(NULL);
1343 $$->set_location(yylloc);
1348 $$ = new(ctx) ast_expression_statement($1);
1349 $$->set_location(yylloc);
1353 selection_statement:
1354 IF '(' expression ')' selection_rest_statement
1356 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1358 $$->set_location(yylloc);
1362 selection_rest_statement:
1363 statement ELSE statement
1365 $$.then_statement = $1;
1366 $$.else_statement = $3;
1370 $$.then_statement = $1;
1371 $$.else_statement = NULL;
1378 $$ = (ast_node *) $1;
1380 | fully_specified_type IDENTIFIER '=' initializer
1383 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1384 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1385 decl->set_location(yylloc);
1386 declarator->set_location(yylloc);
1388 declarator->declarations.push_tail(&decl->link);
1394 SWITCH '(' expression ')' compound_statement
1402 iteration_statement:
1403 WHILE '(' condition ')' statement_no_new_scope
1406 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1407 NULL, $3, NULL, $5);
1408 $$->set_location(yylloc);
1410 | DO statement WHILE '(' expression ')' ';'
1413 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1414 NULL, $5, NULL, $2);
1415 $$->set_location(yylloc);
1417 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1420 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1421 $3, $4.cond, $4.rest, $6);
1422 $$->set_location(yylloc);
1427 expression_statement
1428 | declaration_statement
1445 | conditionopt ';' expression
1452 // Grammar Note: No 'goto'. Gotos are not supported.
1457 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1458 $$->set_location(yylloc);
1463 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1464 $$->set_location(yylloc);
1469 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1470 $$->set_location(yylloc);
1472 | RETURN expression ';'
1475 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1476 $$->set_location(yylloc);
1478 | DISCARD ';' // Fragment shader only.
1481 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1482 $$->set_location(yylloc);
1486 external_declaration:
1487 function_definition { $$ = $1; }
1488 | declaration { $$ = $1; }
1489 | pragma_statement { $$ = NULL; }
1492 function_definition:
1493 function_prototype compound_statement_no_new_scope
1496 $$ = new(ctx) ast_function_definition();
1497 $$->set_location(yylloc);