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
226 state->es_shader = true;
230 /* FINISHME: Check against implementation support versions. */
231 state->language_version = $2;
234 _mesa_glsl_error(& @2, state, "Shading language version"
235 "%u is not supported\n", $2);
243 | PRAGMA_DEBUG_OFF EOL
244 | PRAGMA_OPTIMIZE_ON EOL
245 | PRAGMA_OPTIMIZE_OFF EOL
248 extension_statement_list:
250 | extension_statement_list extension_statement
254 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
256 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
262 external_declaration_list:
265 /* FINISHME: The NULL test is only required because 'precision'
266 * FINISHME: statements are not yet supported.
269 state->translation_unit.push_tail(& $1->link);
271 | external_declaration_list external_declaration
273 /* FINISHME: The NULL test is only required because 'precision'
274 * FINISHME: statements are not yet supported.
277 state->translation_unit.push_tail(& $2->link);
289 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
290 $$->set_location(yylloc);
291 $$->primary_expression.identifier = $1;
296 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
297 $$->set_location(yylloc);
298 $$->primary_expression.int_constant = $1;
303 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
304 $$->set_location(yylloc);
305 $$->primary_expression.uint_constant = $1;
310 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
311 $$->set_location(yylloc);
312 $$->primary_expression.float_constant = $1;
317 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
318 $$->set_location(yylloc);
319 $$->primary_expression.bool_constant = $1;
329 | postfix_expression '[' integer_expression ']'
332 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
333 $$->set_location(yylloc);
339 | postfix_expression '.' IDENTIFIER
342 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
343 $$->set_location(yylloc);
344 $$->primary_expression.identifier = $3;
346 | postfix_expression INC_OP
349 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
350 $$->set_location(yylloc);
352 | postfix_expression DEC_OP
355 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
356 $$->set_location(yylloc);
365 function_call_or_method
368 function_call_or_method:
369 function_call_generic
370 | postfix_expression '.' function_call_generic
373 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
374 $$->set_location(yylloc);
378 function_call_generic:
379 function_call_header_with_parameters ')'
380 | function_call_header_no_parameters ')'
383 function_call_header_no_parameters:
384 function_call_header VOID_TOK
385 | function_call_header
388 function_call_header_with_parameters:
389 function_call_header assignment_expression
392 $$->set_location(yylloc);
393 $$->expressions.push_tail(& $2->link);
395 | function_call_header_with_parameters ',' assignment_expression
398 $$->set_location(yylloc);
399 $$->expressions.push_tail(& $3->link);
403 // Grammar Note: Constructors look like functions, but lexical
404 // analysis recognized most of them as keywords. They are now
405 // recognized through "type_specifier".
406 function_call_header:
407 function_identifier '('
414 $$ = new(ctx) ast_function_expression($1);
415 $$->set_location(yylloc);
420 ast_expression *callee = new(ctx) ast_expression($1);
421 $$ = new(ctx) ast_function_expression(callee);
422 $$->set_location(yylloc);
427 ast_expression *callee = new(ctx) ast_expression($1);
428 $$ = new(ctx) ast_function_expression(callee);
429 $$->set_location(yylloc);
433 // Grammar Note: No traditional style type casts.
436 | INC_OP unary_expression
439 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
440 $$->set_location(yylloc);
442 | DEC_OP unary_expression
445 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
446 $$->set_location(yylloc);
448 | unary_operator unary_expression
451 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
452 $$->set_location(yylloc);
456 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
458 '+' { $$ = ast_plus; }
459 | '-' { $$ = ast_neg; }
460 | '!' { $$ = ast_logic_not; }
461 | '~' { $$ = ast_bit_not; }
464 multiplicative_expression:
466 | multiplicative_expression '*' unary_expression
469 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
470 $$->set_location(yylloc);
472 | multiplicative_expression '/' unary_expression
475 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
476 $$->set_location(yylloc);
478 | multiplicative_expression '%' unary_expression
481 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
482 $$->set_location(yylloc);
487 multiplicative_expression
488 | additive_expression '+' multiplicative_expression
491 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
492 $$->set_location(yylloc);
494 | additive_expression '-' multiplicative_expression
497 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
498 $$->set_location(yylloc);
504 | shift_expression LEFT_OP additive_expression
507 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
508 $$->set_location(yylloc);
510 | shift_expression RIGHT_OP additive_expression
513 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
514 $$->set_location(yylloc);
518 relational_expression:
520 | relational_expression '<' shift_expression
523 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
524 $$->set_location(yylloc);
526 | relational_expression '>' shift_expression
529 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
530 $$->set_location(yylloc);
532 | relational_expression LE_OP shift_expression
535 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
536 $$->set_location(yylloc);
538 | relational_expression GE_OP shift_expression
541 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
542 $$->set_location(yylloc);
547 relational_expression
548 | equality_expression EQ_OP relational_expression
551 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
552 $$->set_location(yylloc);
554 | equality_expression NE_OP relational_expression
557 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
558 $$->set_location(yylloc);
564 | and_expression '&' equality_expression
567 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
568 $$->set_location(yylloc);
572 exclusive_or_expression:
574 | exclusive_or_expression '^' and_expression
577 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
578 $$->set_location(yylloc);
582 inclusive_or_expression:
583 exclusive_or_expression
584 | inclusive_or_expression '|' exclusive_or_expression
587 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
588 $$->set_location(yylloc);
592 logical_and_expression:
593 inclusive_or_expression
594 | logical_and_expression AND_OP inclusive_or_expression
597 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
598 $$->set_location(yylloc);
602 logical_xor_expression:
603 logical_and_expression
604 | logical_xor_expression XOR_OP logical_and_expression
607 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
608 $$->set_location(yylloc);
612 logical_or_expression:
613 logical_xor_expression
614 | logical_or_expression OR_OP logical_xor_expression
617 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
618 $$->set_location(yylloc);
622 conditional_expression:
623 logical_or_expression
624 | logical_or_expression '?' expression ':' assignment_expression
627 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
628 $$->set_location(yylloc);
632 assignment_expression:
633 conditional_expression
634 | unary_expression assignment_operator assignment_expression
637 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
638 $$->set_location(yylloc);
643 '=' { $$ = ast_assign; }
644 | MUL_ASSIGN { $$ = ast_mul_assign; }
645 | DIV_ASSIGN { $$ = ast_div_assign; }
646 | MOD_ASSIGN { $$ = ast_mod_assign; }
647 | ADD_ASSIGN { $$ = ast_add_assign; }
648 | SUB_ASSIGN { $$ = ast_sub_assign; }
649 | LEFT_ASSIGN { $$ = ast_ls_assign; }
650 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
651 | AND_ASSIGN { $$ = ast_and_assign; }
652 | XOR_ASSIGN { $$ = ast_xor_assign; }
653 | OR_ASSIGN { $$ = ast_or_assign; }
657 assignment_expression
661 | expression ',' assignment_expression
664 if ($1->oper != ast_sequence) {
665 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
666 $$->set_location(yylloc);
667 $$->expressions.push_tail(& $1->link);
672 $$->expressions.push_tail(& $3->link);
677 conditional_expression
681 function_prototype ';'
685 | init_declarator_list ';'
689 | PRECISION precision_qualifier type_specifier_no_prec ';'
691 if (($3->type_specifier != ast_float)
692 && ($3->type_specifier != ast_int)) {
693 _mesa_glsl_error(& @3, state, "global precision qualifier can "
694 "only be applied to `int' or `float'\n");
698 $$ = NULL; /* FINISHME */
703 function_declarator ')'
708 | function_header_with_parameters
711 function_header_with_parameters:
712 function_header parameter_declaration
715 $$->parameters.push_tail(& $2->link);
717 | function_header_with_parameters ',' parameter_declaration
720 $$->parameters.push_tail(& $3->link);
725 fully_specified_type IDENTIFIER '('
728 $$ = new(ctx) ast_function();
729 $$->set_location(yylloc);
730 $$->return_type = $1;
735 parameter_declarator:
736 type_specifier IDENTIFIER
739 $$ = new(ctx) ast_parameter_declarator();
740 $$->set_location(yylloc);
741 $$->type = new(ctx) ast_fully_specified_type();
742 $$->type->set_location(yylloc);
743 $$->type->specifier = $1;
746 | type_specifier IDENTIFIER '[' constant_expression ']'
749 $$ = new(ctx) ast_parameter_declarator();
750 $$->set_location(yylloc);
751 $$->type = new(ctx) ast_fully_specified_type();
752 $$->type->set_location(yylloc);
753 $$->type->specifier = $1;
760 parameter_declaration:
761 parameter_type_qualifier parameter_qualifier parameter_declarator
766 $$->type->qualifier = $1.q;
768 | parameter_qualifier parameter_declarator
771 $$->type->qualifier = $1.q;
773 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
778 $$ = new(ctx) ast_parameter_declarator();
779 $$->set_location(yylloc);
780 $$->type = new(ctx) ast_fully_specified_type();
781 $$->type->qualifier = $1.q;
782 $$->type->specifier = $3;
784 | parameter_qualifier parameter_type_specifier
787 $$ = new(ctx) ast_parameter_declarator();
788 $$->set_location(yylloc);
789 $$->type = new(ctx) ast_fully_specified_type();
790 $$->type->qualifier = $1.q;
791 $$->type->specifier = $2;
796 /* empty */ { $$.i = 0; }
797 | IN_TOK { $$.i = 0; $$.q.in = 1; }
798 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
799 | INOUT_TOK { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
802 parameter_type_specifier:
806 init_declarator_list:
808 | init_declarator_list ',' IDENTIFIER
811 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
812 decl->set_location(yylloc);
815 $$->declarations.push_tail(&decl->link);
817 | init_declarator_list ',' IDENTIFIER '[' ']'
820 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
821 decl->set_location(yylloc);
824 $$->declarations.push_tail(&decl->link);
826 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
829 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
830 decl->set_location(yylloc);
833 $$->declarations.push_tail(&decl->link);
835 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
838 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
839 decl->set_location(yylloc);
842 $$->declarations.push_tail(&decl->link);
844 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
847 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
848 decl->set_location(yylloc);
851 $$->declarations.push_tail(&decl->link);
853 | init_declarator_list ',' IDENTIFIER '=' initializer
856 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
857 decl->set_location(yylloc);
860 $$->declarations.push_tail(&decl->link);
864 // Grammar Note: No 'enum', or 'typedef'.
869 if ($1->specifier->type_specifier != ast_struct) {
870 _mesa_glsl_error(& @1, state, "empty declaration list\n");
873 $$ = new(ctx) ast_declarator_list($1);
874 $$->set_location(yylloc);
877 | fully_specified_type IDENTIFIER
880 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
882 $$ = new(ctx) ast_declarator_list($1);
883 $$->set_location(yylloc);
884 $$->declarations.push_tail(&decl->link);
886 | fully_specified_type IDENTIFIER '[' ']'
889 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
891 $$ = new(ctx) ast_declarator_list($1);
892 $$->set_location(yylloc);
893 $$->declarations.push_tail(&decl->link);
895 | fully_specified_type IDENTIFIER '[' constant_expression ']'
898 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
900 $$ = new(ctx) ast_declarator_list($1);
901 $$->set_location(yylloc);
902 $$->declarations.push_tail(&decl->link);
904 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
907 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
909 $$ = new(ctx) ast_declarator_list($1);
910 $$->set_location(yylloc);
911 $$->declarations.push_tail(&decl->link);
913 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
916 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
918 $$ = new(ctx) ast_declarator_list($1);
919 $$->set_location(yylloc);
920 $$->declarations.push_tail(&decl->link);
922 | fully_specified_type IDENTIFIER '=' initializer
925 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
927 $$ = new(ctx) ast_declarator_list($1);
928 $$->set_location(yylloc);
929 $$->declarations.push_tail(&decl->link);
931 | INVARIANT IDENTIFIER // Vertex only.
934 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
936 $$ = new(ctx) ast_declarator_list(NULL);
937 $$->set_location(yylloc);
938 $$->invariant = true;
940 $$->declarations.push_tail(&decl->link);
944 fully_specified_type:
948 $$ = new(ctx) ast_fully_specified_type();
949 $$->set_location(yylloc);
952 | type_qualifier type_specifier
955 $$ = new(ctx) ast_fully_specified_type();
956 $$->set_location(yylloc);
957 $$->qualifier = $1.q;
962 opt_layout_qualifier:
968 LAYOUT_TOK '(' layout_qualifier_id_list ')'
974 layout_qualifier_id_list:
976 | layout_qualifier_id_list ',' layout_qualifier_id
987 if (state->ARB_fragment_coord_conventions_enable) {
988 bool got_one = false;
990 if (strcmp($1, "origin_upper_left") == 0) {
992 $$.q.origin_upper_left = 1;
993 } else if (strcmp($1, "pixel_center_integer") == 0) {
995 $$.q.pixel_center_integer = 1;
998 if (state->ARB_fragment_coord_conventions_warn && got_one) {
999 _mesa_glsl_warning(& @1, state,
1000 "GL_ARB_fragment_coord_conventions layout "
1001 "identifier `%s' used\n", $1);
1005 /* If the identifier didn't match any known layout identifiers,
1009 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1016 interpolation_qualifier:
1017 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1018 | FLAT { $$.i = 0; $$.q.flat = 1; }
1019 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1022 parameter_type_qualifier:
1023 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1028 | interpolation_qualifier type_qualifier
1032 | INVARIANT type_qualifier
1040 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1041 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1042 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1043 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1044 | opt_layout_qualifier IN_TOK { $$.i = 0; $$.q.in = 1; }
1045 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
1046 | CENTROID IN_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1047 | CENTROID OUT_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1048 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1052 type_specifier_no_prec
1053 | precision_qualifier type_specifier_no_prec
1060 type_specifier_no_prec:
1061 type_specifier_nonarray
1062 | type_specifier_nonarray '[' ']'
1065 $$->is_array = true;
1066 $$->array_size = NULL;
1068 | type_specifier_nonarray '[' constant_expression ']'
1071 $$->is_array = true;
1072 $$->array_size = $3;
1076 type_specifier_nonarray:
1077 basic_type_specifier_nonarray
1080 $$ = new(ctx) ast_type_specifier($1);
1081 $$->set_location(yylloc);
1086 $$ = new(ctx) ast_type_specifier($1);
1087 $$->set_location(yylloc);
1092 $$ = new(ctx) ast_type_specifier($1);
1093 $$->set_location(yylloc);
1097 basic_type_specifier_nonarray:
1098 VOID_TOK { $$ = ast_void; }
1099 | FLOAT_TOK { $$ = ast_float; }
1100 | INT_TOK { $$ = ast_int; }
1101 | UINT_TOK { $$ = ast_uint; }
1102 | BOOL_TOK { $$ = ast_bool; }
1103 | VEC2 { $$ = ast_vec2; }
1104 | VEC3 { $$ = ast_vec3; }
1105 | VEC4 { $$ = ast_vec4; }
1106 | BVEC2 { $$ = ast_bvec2; }
1107 | BVEC3 { $$ = ast_bvec3; }
1108 | BVEC4 { $$ = ast_bvec4; }
1109 | IVEC2 { $$ = ast_ivec2; }
1110 | IVEC3 { $$ = ast_ivec3; }
1111 | IVEC4 { $$ = ast_ivec4; }
1112 | UVEC2 { $$ = ast_uvec2; }
1113 | UVEC3 { $$ = ast_uvec3; }
1114 | UVEC4 { $$ = ast_uvec4; }
1115 | MAT2X2 { $$ = ast_mat2; }
1116 | MAT2X3 { $$ = ast_mat2x3; }
1117 | MAT2X4 { $$ = ast_mat2x4; }
1118 | MAT3X2 { $$ = ast_mat3x2; }
1119 | MAT3X3 { $$ = ast_mat3; }
1120 | MAT3X4 { $$ = ast_mat3x4; }
1121 | MAT4X2 { $$ = ast_mat4x2; }
1122 | MAT4X3 { $$ = ast_mat4x3; }
1123 | MAT4X4 { $$ = ast_mat4; }
1124 | SAMPLER1D { $$ = ast_sampler1d; }
1125 | SAMPLER2D { $$ = ast_sampler2d; }
1126 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1127 | SAMPLER3D { $$ = ast_sampler3d; }
1128 | SAMPLERCUBE { $$ = ast_samplercube; }
1129 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1130 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1131 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1132 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1133 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1134 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1135 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1136 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1137 | ISAMPLER1D { $$ = ast_isampler1d; }
1138 | ISAMPLER2D { $$ = ast_isampler2d; }
1139 | ISAMPLER3D { $$ = ast_isampler3d; }
1140 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1141 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1142 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1143 | USAMPLER1D { $$ = ast_usampler1d; }
1144 | USAMPLER2D { $$ = ast_usampler2d; }
1145 | USAMPLER3D { $$ = ast_usampler3d; }
1146 | USAMPLERCUBE { $$ = ast_usamplercube; }
1147 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1148 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1151 precision_qualifier:
1153 if (state->language_version < 130)
1154 _mesa_glsl_error(& @1, state,
1155 "precision qualifier forbidden "
1156 "in GLSL %d.%d (1.30 or later "
1158 state->language_version / 100,
1159 state->language_version % 100);
1161 $$ = ast_precision_high;
1164 if (state->language_version < 130)
1165 _mesa_glsl_error(& @1, state,
1166 "precision qualifier forbidden "
1167 "in GLSL %d.%d (1.30 or later "
1169 state->language_version / 100,
1170 state->language_version % 100);
1172 $$ = ast_precision_medium;
1175 if (state->language_version < 130)
1176 _mesa_glsl_error(& @1, state,
1177 "precision qualifier forbidden "
1178 "in GLSL %d.%d (1.30 or later "
1180 state->language_version / 100,
1181 state->language_version % 100);
1183 $$ = ast_precision_low;
1188 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1191 $$ = new(ctx) ast_struct_specifier($2, $4);
1192 $$->set_location(yylloc);
1194 | STRUCT '{' struct_declaration_list '}'
1197 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1198 $$->set_location(yylloc);
1202 struct_declaration_list:
1205 $$ = (ast_node *) $1;
1206 $1->link.self_link();
1208 | struct_declaration_list struct_declaration
1210 $$ = (ast_node *) $1;
1211 $$->link.insert_before(& $2->link);
1216 type_specifier struct_declarator_list ';'
1219 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1220 type->set_location(yylloc);
1222 type->specifier = $1;
1223 $$ = new(ctx) ast_declarator_list(type);
1224 $$->set_location(yylloc);
1226 $$->declarations.push_degenerate_list_at_head(& $2->link);
1230 struct_declarator_list:
1234 $1->link.self_link();
1236 | struct_declarator_list ',' struct_declarator
1239 $$->link.insert_before(& $3->link);
1247 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1248 $$->set_location(yylloc);
1250 | IDENTIFIER '[' constant_expression ']'
1253 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1254 $$->set_location(yylloc);
1259 assignment_expression
1262 declaration_statement:
1266 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1269 compound_statement { $$ = (ast_node *) $1; }
1274 declaration_statement
1275 | expression_statement
1276 | selection_statement
1277 | switch_statement { $$ = NULL; }
1278 | case_label { $$ = NULL; }
1279 | iteration_statement
1287 $$ = new(ctx) ast_compound_statement(true, NULL);
1288 $$->set_location(yylloc);
1290 | '{' statement_list '}'
1293 $$ = new(ctx) ast_compound_statement(true, $2);
1294 $$->set_location(yylloc);
1298 statement_no_new_scope:
1299 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1303 compound_statement_no_new_scope:
1307 $$ = new(ctx) ast_compound_statement(false, NULL);
1308 $$->set_location(yylloc);
1310 | '{' statement_list '}'
1313 $$ = new(ctx) ast_compound_statement(false, $2);
1314 $$->set_location(yylloc);
1322 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1327 $$->link.self_link();
1329 | statement_list statement
1332 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1336 $$->link.insert_before(& $2->link);
1340 expression_statement:
1344 $$ = new(ctx) ast_expression_statement(NULL);
1345 $$->set_location(yylloc);
1350 $$ = new(ctx) ast_expression_statement($1);
1351 $$->set_location(yylloc);
1355 selection_statement:
1356 IF '(' expression ')' selection_rest_statement
1358 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1360 $$->set_location(yylloc);
1364 selection_rest_statement:
1365 statement ELSE statement
1367 $$.then_statement = $1;
1368 $$.else_statement = $3;
1372 $$.then_statement = $1;
1373 $$.else_statement = NULL;
1380 $$ = (ast_node *) $1;
1382 | fully_specified_type IDENTIFIER '=' initializer
1385 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1386 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1387 decl->set_location(yylloc);
1388 declarator->set_location(yylloc);
1390 declarator->declarations.push_tail(&decl->link);
1396 SWITCH '(' expression ')' compound_statement
1404 iteration_statement:
1405 WHILE '(' condition ')' statement_no_new_scope
1408 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1409 NULL, $3, NULL, $5);
1410 $$->set_location(yylloc);
1412 | DO statement WHILE '(' expression ')' ';'
1415 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1416 NULL, $5, NULL, $2);
1417 $$->set_location(yylloc);
1419 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1422 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1423 $3, $4.cond, $4.rest, $6);
1424 $$->set_location(yylloc);
1429 expression_statement
1430 | declaration_statement
1447 | conditionopt ';' expression
1454 // Grammar Note: No 'goto'. Gotos are not supported.
1459 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1460 $$->set_location(yylloc);
1465 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1466 $$->set_location(yylloc);
1471 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1472 $$->set_location(yylloc);
1474 | RETURN expression ';'
1477 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1478 $$->set_location(yylloc);
1480 | DISCARD ';' // Fragment shader only.
1483 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1484 $$->set_location(yylloc);
1488 external_declaration:
1489 function_definition { $$ = $1; }
1490 | declaration { $$ = $1; }
1491 | pragma_statement { $$ = NULL; }
1494 function_definition:
1495 function_prototype compound_statement_no_new_scope
1498 $$ = new(ctx) ast_function_definition();
1499 $$->set_location(yylloc);