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"
32 #include "main/context.h"
36 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
38 _mesa_glsl_error(loc, st, "%s", msg);
42 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
44 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
62 %lex-param {struct _mesa_glsl_parse_state *state}
63 %parse-param {struct _mesa_glsl_parse_state *state}
68 const char *identifier;
70 struct ast_type_qualifier type_qualifier;
73 ast_type_specifier *type_specifier;
74 ast_fully_specified_type *fully_specified_type;
75 ast_function *function;
76 ast_parameter_declarator *parameter_declarator;
77 ast_function_definition *function_definition;
78 ast_compound_statement *compound_statement;
79 ast_expression *expression;
80 ast_declarator_list *declarator_list;
81 ast_struct_specifier *struct_specifier;
82 ast_declaration *declaration;
83 ast_switch_body *switch_body;
84 ast_case_label *case_label;
85 ast_case_label_list *case_label_list;
86 ast_case_statement *case_statement;
87 ast_case_statement_list *case_statement_list;
88 ast_interface_block *interface_block;
96 ast_node *then_statement;
97 ast_node *else_statement;
98 } selection_rest_statement;
101 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
102 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
103 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
104 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
105 %token NOPERSPECTIVE FLAT SMOOTH
106 %token MAT2X2 MAT2X3 MAT2X4
107 %token MAT3X2 MAT3X3 MAT3X4
108 %token MAT4X2 MAT4X3 MAT4X4
109 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
110 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
111 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
112 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
113 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
114 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
115 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
116 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
117 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
118 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
119 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
120 %token SAMPLEREXTERNALOES
121 %token STRUCT VOID_TOK WHILE
122 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
123 %type <identifier> any_identifier
124 %type <interface_block> instance_name_opt
125 %token <real> FLOATCONSTANT
126 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
127 %token <identifier> FIELD_SELECTION
128 %token LEFT_OP RIGHT_OP
129 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
130 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
131 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
134 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
136 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
137 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
138 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
139 %token PRAGMA_INVARIANT_ALL
142 /* Reserved words that are not actually used in the grammar.
144 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
145 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
146 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
147 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
149 %token SIZEOF CAST NAMESPACE USING
150 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
155 %token COMMON PARTITION ACTIVE FILTER
156 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
157 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
158 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
159 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
160 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
163 %type <identifier> variable_identifier
164 %type <node> statement
165 %type <node> statement_list
166 %type <node> simple_statement
167 %type <n> precision_qualifier
168 %type <type_qualifier> type_qualifier
169 %type <type_qualifier> auxiliary_storage_qualifier
170 %type <type_qualifier> storage_qualifier
171 %type <type_qualifier> interpolation_qualifier
172 %type <type_qualifier> layout_qualifier
173 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
174 %type <type_qualifier> interface_block_layout_qualifier
175 %type <type_qualifier> interface_qualifier
176 %type <type_specifier> type_specifier
177 %type <type_specifier> type_specifier_nonarray
178 %type <identifier> basic_type_specifier_nonarray
179 %type <fully_specified_type> fully_specified_type
180 %type <function> function_prototype
181 %type <function> function_header
182 %type <function> function_header_with_parameters
183 %type <function> function_declarator
184 %type <parameter_declarator> parameter_declarator
185 %type <parameter_declarator> parameter_declaration
186 %type <type_qualifier> parameter_qualifier
187 %type <type_qualifier> parameter_direction_qualifier
188 %type <type_specifier> parameter_type_specifier
189 %type <function_definition> function_definition
190 %type <compound_statement> compound_statement_no_new_scope
191 %type <compound_statement> compound_statement
192 %type <node> statement_no_new_scope
193 %type <node> expression_statement
194 %type <expression> expression
195 %type <expression> primary_expression
196 %type <expression> assignment_expression
197 %type <expression> conditional_expression
198 %type <expression> logical_or_expression
199 %type <expression> logical_xor_expression
200 %type <expression> logical_and_expression
201 %type <expression> inclusive_or_expression
202 %type <expression> exclusive_or_expression
203 %type <expression> and_expression
204 %type <expression> equality_expression
205 %type <expression> relational_expression
206 %type <expression> shift_expression
207 %type <expression> additive_expression
208 %type <expression> multiplicative_expression
209 %type <expression> unary_expression
210 %type <expression> constant_expression
211 %type <expression> integer_expression
212 %type <expression> postfix_expression
213 %type <expression> function_call_header_with_parameters
214 %type <expression> function_call_header_no_parameters
215 %type <expression> function_call_header
216 %type <expression> function_call_generic
217 %type <expression> function_call_or_method
218 %type <expression> function_call
219 %type <expression> method_call_generic
220 %type <expression> method_call_header_with_parameters
221 %type <expression> method_call_header_no_parameters
222 %type <expression> method_call_header
223 %type <n> assignment_operator
224 %type <n> unary_operator
225 %type <expression> function_identifier
226 %type <node> external_declaration
227 %type <declarator_list> init_declarator_list
228 %type <declarator_list> single_declaration
229 %type <expression> initializer
230 %type <expression> initializer_list
231 %type <node> declaration
232 %type <node> declaration_statement
233 %type <node> jump_statement
234 %type <node> interface_block
235 %type <interface_block> basic_interface_block
236 %type <struct_specifier> struct_specifier
237 %type <declarator_list> struct_declaration_list
238 %type <declarator_list> struct_declaration
239 %type <declaration> struct_declarator
240 %type <declaration> struct_declarator_list
241 %type <declarator_list> member_list
242 %type <declarator_list> member_declaration
243 %type <node> selection_statement
244 %type <selection_rest_statement> selection_rest_statement
245 %type <node> switch_statement
246 %type <switch_body> switch_body
247 %type <case_label_list> case_label_list
248 %type <case_label> case_label
249 %type <case_statement> case_statement
250 %type <case_statement_list> case_statement_list
251 %type <node> iteration_statement
252 %type <node> condition
253 %type <node> conditionopt
254 %type <node> for_init_statement
255 %type <for_rest_statement> for_rest_statement
256 %type <n> integer_constant
257 %type <node> layout_defaults
263 version_statement extension_statement_list
265 _mesa_glsl_initialize_types(state);
267 external_declaration_list
269 delete state->symbols;
270 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
271 _mesa_glsl_initialize_types(state);
276 /* blank - no #version specified: defaults are already set */
277 | VERSION_TOK INTCONSTANT EOL
279 state->process_version_directive(&@2, $2, NULL);
284 | VERSION_TOK INTCONSTANT any_identifier EOL
286 state->process_version_directive(&@2, $2, $3);
295 | PRAGMA_DEBUG_OFF EOL
296 | PRAGMA_OPTIMIZE_ON EOL
297 | PRAGMA_OPTIMIZE_OFF EOL
298 | PRAGMA_INVARIANT_ALL EOL
300 if (!state->is_version(120, 100)) {
301 _mesa_glsl_warning(& @1, state,
302 "pragma `invariant(all)' not supported in %s "
303 "(GLSL ES 1.00 or GLSL 1.20 required)",
304 state->get_version_string());
306 state->all_invariant = true;
311 extension_statement_list:
313 | extension_statement_list extension_statement
323 EXTENSION any_identifier COLON any_identifier EOL
325 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
331 external_declaration_list:
334 /* FINISHME: The NULL test is required because pragmas are set to
335 * FINISHME: NULL. (See production rule for external_declaration.)
338 state->translation_unit.push_tail(& $1->link);
340 | external_declaration_list external_declaration
342 /* FINISHME: The NULL test is required because pragmas are set to
343 * FINISHME: NULL. (See production rule for external_declaration.)
346 state->translation_unit.push_tail(& $2->link);
359 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
360 $$->set_location(yylloc);
361 $$->primary_expression.identifier = $1;
366 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
367 $$->set_location(yylloc);
368 $$->primary_expression.int_constant = $1;
373 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
374 $$->set_location(yylloc);
375 $$->primary_expression.uint_constant = $1;
380 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
381 $$->set_location(yylloc);
382 $$->primary_expression.float_constant = $1;
387 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
388 $$->set_location(yylloc);
389 $$->primary_expression.bool_constant = $1;
399 | postfix_expression '[' integer_expression ']'
402 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
403 $$->set_location(yylloc);
409 | postfix_expression '.' any_identifier
412 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
413 $$->set_location(yylloc);
414 $$->primary_expression.identifier = $3;
416 | postfix_expression INC_OP
419 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
420 $$->set_location(yylloc);
422 | postfix_expression DEC_OP
425 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
426 $$->set_location(yylloc);
435 function_call_or_method
438 function_call_or_method:
439 function_call_generic
440 | postfix_expression '.' method_call_generic
443 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
444 $$->set_location(yylloc);
448 function_call_generic:
449 function_call_header_with_parameters ')'
450 | function_call_header_no_parameters ')'
453 function_call_header_no_parameters:
454 function_call_header VOID_TOK
455 | function_call_header
458 function_call_header_with_parameters:
459 function_call_header assignment_expression
462 $$->set_location(yylloc);
463 $$->expressions.push_tail(& $2->link);
465 | function_call_header_with_parameters ',' assignment_expression
468 $$->set_location(yylloc);
469 $$->expressions.push_tail(& $3->link);
473 // Grammar Note: Constructors look like functions, but lexical
474 // analysis recognized most of them as keywords. They are now
475 // recognized through "type_specifier".
476 function_call_header:
477 function_identifier '('
484 $$ = new(ctx) ast_function_expression($1);
485 $$->set_location(yylloc);
487 | variable_identifier
490 ast_expression *callee = new(ctx) ast_expression($1);
491 $$ = new(ctx) ast_function_expression(callee);
492 $$->set_location(yylloc);
497 ast_expression *callee = new(ctx) ast_expression($1);
498 $$ = new(ctx) ast_function_expression(callee);
499 $$->set_location(yylloc);
504 method_call_header_with_parameters ')'
505 | method_call_header_no_parameters ')'
508 method_call_header_no_parameters:
509 method_call_header VOID_TOK
513 method_call_header_with_parameters:
514 method_call_header assignment_expression
517 $$->set_location(yylloc);
518 $$->expressions.push_tail(& $2->link);
520 | method_call_header_with_parameters ',' assignment_expression
523 $$->set_location(yylloc);
524 $$->expressions.push_tail(& $3->link);
528 // Grammar Note: Constructors look like methods, but lexical
529 // analysis recognized most of them as keywords. They are now
530 // recognized through "type_specifier".
532 variable_identifier '('
535 ast_expression *callee = new(ctx) ast_expression($1);
536 $$ = new(ctx) ast_function_expression(callee);
537 $$->set_location(yylloc);
541 // Grammar Note: No traditional style type casts.
544 | INC_OP unary_expression
547 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
548 $$->set_location(yylloc);
550 | DEC_OP unary_expression
553 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
554 $$->set_location(yylloc);
556 | unary_operator unary_expression
559 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
560 $$->set_location(yylloc);
564 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
566 '+' { $$ = ast_plus; }
567 | '-' { $$ = ast_neg; }
568 | '!' { $$ = ast_logic_not; }
569 | '~' { $$ = ast_bit_not; }
572 multiplicative_expression:
574 | multiplicative_expression '*' unary_expression
577 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
578 $$->set_location(yylloc);
580 | multiplicative_expression '/' unary_expression
583 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
584 $$->set_location(yylloc);
586 | multiplicative_expression '%' unary_expression
589 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
590 $$->set_location(yylloc);
595 multiplicative_expression
596 | additive_expression '+' multiplicative_expression
599 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
600 $$->set_location(yylloc);
602 | additive_expression '-' multiplicative_expression
605 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
606 $$->set_location(yylloc);
612 | shift_expression LEFT_OP additive_expression
615 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
616 $$->set_location(yylloc);
618 | shift_expression RIGHT_OP additive_expression
621 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
622 $$->set_location(yylloc);
626 relational_expression:
628 | relational_expression '<' shift_expression
631 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
632 $$->set_location(yylloc);
634 | relational_expression '>' shift_expression
637 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
638 $$->set_location(yylloc);
640 | relational_expression LE_OP shift_expression
643 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
644 $$->set_location(yylloc);
646 | relational_expression GE_OP shift_expression
649 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
650 $$->set_location(yylloc);
655 relational_expression
656 | equality_expression EQ_OP relational_expression
659 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
660 $$->set_location(yylloc);
662 | equality_expression NE_OP relational_expression
665 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
666 $$->set_location(yylloc);
672 | and_expression '&' equality_expression
675 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
676 $$->set_location(yylloc);
680 exclusive_or_expression:
682 | exclusive_or_expression '^' and_expression
685 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
686 $$->set_location(yylloc);
690 inclusive_or_expression:
691 exclusive_or_expression
692 | inclusive_or_expression '|' exclusive_or_expression
695 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
696 $$->set_location(yylloc);
700 logical_and_expression:
701 inclusive_or_expression
702 | logical_and_expression AND_OP inclusive_or_expression
705 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
706 $$->set_location(yylloc);
710 logical_xor_expression:
711 logical_and_expression
712 | logical_xor_expression XOR_OP logical_and_expression
715 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
716 $$->set_location(yylloc);
720 logical_or_expression:
721 logical_xor_expression
722 | logical_or_expression OR_OP logical_xor_expression
725 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
726 $$->set_location(yylloc);
730 conditional_expression:
731 logical_or_expression
732 | logical_or_expression '?' expression ':' assignment_expression
735 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
736 $$->set_location(yylloc);
740 assignment_expression:
741 conditional_expression
742 | unary_expression assignment_operator assignment_expression
745 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
746 $$->set_location(yylloc);
751 '=' { $$ = ast_assign; }
752 | MUL_ASSIGN { $$ = ast_mul_assign; }
753 | DIV_ASSIGN { $$ = ast_div_assign; }
754 | MOD_ASSIGN { $$ = ast_mod_assign; }
755 | ADD_ASSIGN { $$ = ast_add_assign; }
756 | SUB_ASSIGN { $$ = ast_sub_assign; }
757 | LEFT_ASSIGN { $$ = ast_ls_assign; }
758 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
759 | AND_ASSIGN { $$ = ast_and_assign; }
760 | XOR_ASSIGN { $$ = ast_xor_assign; }
761 | OR_ASSIGN { $$ = ast_or_assign; }
765 assignment_expression
769 | expression ',' assignment_expression
772 if ($1->oper != ast_sequence) {
773 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
774 $$->set_location(yylloc);
775 $$->expressions.push_tail(& $1->link);
780 $$->expressions.push_tail(& $3->link);
785 conditional_expression
789 function_prototype ';'
791 state->symbols->pop_scope();
794 | init_declarator_list ';'
798 | PRECISION precision_qualifier type_specifier ';'
800 $3->default_precision = $2;
810 function_declarator ')'
815 | function_header_with_parameters
818 function_header_with_parameters:
819 function_header parameter_declaration
822 $$->parameters.push_tail(& $2->link);
824 | function_header_with_parameters ',' parameter_declaration
827 $$->parameters.push_tail(& $3->link);
832 fully_specified_type variable_identifier '('
835 $$ = new(ctx) ast_function();
836 $$->set_location(yylloc);
837 $$->return_type = $1;
840 state->symbols->add_function(new(state) ir_function($2));
841 state->symbols->push_scope();
845 parameter_declarator:
846 type_specifier any_identifier
849 $$ = new(ctx) ast_parameter_declarator();
850 $$->set_location(yylloc);
851 $$->type = new(ctx) ast_fully_specified_type();
852 $$->type->set_location(yylloc);
853 $$->type->specifier = $1;
856 | type_specifier any_identifier '[' constant_expression ']'
859 $$ = new(ctx) ast_parameter_declarator();
860 $$->set_location(yylloc);
861 $$->type = new(ctx) ast_fully_specified_type();
862 $$->type->set_location(yylloc);
863 $$->type->specifier = $1;
870 parameter_declaration:
871 parameter_qualifier parameter_declarator
874 $$->type->qualifier = $1;
876 | parameter_qualifier parameter_type_specifier
879 $$ = new(ctx) ast_parameter_declarator();
880 $$->set_location(yylloc);
881 $$->type = new(ctx) ast_fully_specified_type();
882 $$->type->qualifier = $1;
883 $$->type->specifier = $2;
890 memset(& $$, 0, sizeof($$));
892 | CONST_TOK parameter_qualifier
894 if ($2.flags.q.constant)
895 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
898 $$.flags.q.constant = 1;
900 | parameter_direction_qualifier parameter_qualifier
902 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
903 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
905 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
906 _mesa_glsl_error(&@1, state, "const must be specified before "
910 $$.merge_qualifier(&@1, state, $2);
912 | precision_qualifier parameter_qualifier
914 if ($2.precision != ast_precision_none)
915 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
917 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
918 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
924 parameter_direction_qualifier:
927 memset(& $$, 0, sizeof($$));
932 memset(& $$, 0, sizeof($$));
937 memset(& $$, 0, sizeof($$));
943 parameter_type_specifier:
947 init_declarator_list:
949 | init_declarator_list ',' any_identifier
952 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
953 decl->set_location(yylloc);
956 $$->declarations.push_tail(&decl->link);
957 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
959 | init_declarator_list ',' any_identifier '[' ']'
962 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
963 decl->set_location(yylloc);
966 $$->declarations.push_tail(&decl->link);
967 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
969 | init_declarator_list ',' any_identifier '[' constant_expression ']'
972 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
973 decl->set_location(yylloc);
976 $$->declarations.push_tail(&decl->link);
977 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
979 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
982 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
983 decl->set_location(yylloc);
986 $$->declarations.push_tail(&decl->link);
987 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
988 if ($7->oper == ast_aggregate) {
989 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
990 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
991 _mesa_ast_set_aggregate_type(type, ai, state);
994 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
997 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
998 decl->set_location(yylloc);
1001 $$->declarations.push_tail(&decl->link);
1002 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1003 if ($8->oper == ast_aggregate) {
1004 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
1005 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
1006 _mesa_ast_set_aggregate_type(type, ai, state);
1009 | init_declarator_list ',' any_identifier '=' initializer
1012 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1013 decl->set_location(yylloc);
1016 $$->declarations.push_tail(&decl->link);
1017 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1018 if ($5->oper == ast_aggregate) {
1019 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
1020 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1025 // Grammar Note: No 'enum', or 'typedef'.
1027 fully_specified_type
1030 /* Empty declaration list is valid. */
1031 $$ = new(ctx) ast_declarator_list($1);
1032 $$->set_location(yylloc);
1034 | fully_specified_type any_identifier
1037 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1039 $$ = new(ctx) ast_declarator_list($1);
1040 $$->set_location(yylloc);
1041 $$->declarations.push_tail(&decl->link);
1043 | fully_specified_type any_identifier '[' ']'
1046 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1048 $$ = new(ctx) ast_declarator_list($1);
1049 $$->set_location(yylloc);
1050 $$->declarations.push_tail(&decl->link);
1052 | fully_specified_type any_identifier '[' constant_expression ']'
1055 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1057 $$ = new(ctx) ast_declarator_list($1);
1058 $$->set_location(yylloc);
1059 $$->declarations.push_tail(&decl->link);
1061 | fully_specified_type any_identifier '[' ']' '=' initializer
1064 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1066 $$ = new(ctx) ast_declarator_list($1);
1067 $$->set_location(yylloc);
1068 $$->declarations.push_tail(&decl->link);
1069 if ($6->oper == ast_aggregate) {
1070 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1071 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1072 _mesa_ast_set_aggregate_type(type, ai, state);
1075 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1078 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1080 $$ = new(ctx) ast_declarator_list($1);
1081 $$->set_location(yylloc);
1082 $$->declarations.push_tail(&decl->link);
1083 if ($7->oper == ast_aggregate) {
1084 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1085 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1086 _mesa_ast_set_aggregate_type(type, ai, state);
1089 | fully_specified_type any_identifier '=' initializer
1092 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1094 $$ = new(ctx) ast_declarator_list($1);
1095 $$->set_location(yylloc);
1096 $$->declarations.push_tail(&decl->link);
1097 if ($4->oper == ast_aggregate) {
1098 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1101 | INVARIANT variable_identifier // Vertex only.
1104 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1106 $$ = new(ctx) ast_declarator_list(NULL);
1107 $$->set_location(yylloc);
1108 $$->invariant = true;
1110 $$->declarations.push_tail(&decl->link);
1114 fully_specified_type:
1118 $$ = new(ctx) ast_fully_specified_type();
1119 $$->set_location(yylloc);
1122 | type_qualifier type_specifier
1125 $$ = new(ctx) ast_fully_specified_type();
1126 $$->set_location(yylloc);
1133 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1139 layout_qualifier_id_list:
1141 | layout_qualifier_id_list ',' layout_qualifier_id
1144 if (!$$.merge_qualifier(& @3, state, $3)) {
1151 INTCONSTANT { $$ = $1; }
1152 | UINTCONSTANT { $$ = $1; }
1155 layout_qualifier_id:
1158 memset(& $$, 0, sizeof($$));
1160 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1161 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1162 state->is_version(150, 0))) {
1163 if (strcmp($1, "origin_upper_left") == 0) {
1164 $$.flags.q.origin_upper_left = 1;
1165 } else if (strcmp($1, "pixel_center_integer") == 0) {
1166 $$.flags.q.pixel_center_integer = 1;
1169 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1170 _mesa_glsl_warning(& @1, state,
1171 "GL_ARB_fragment_coord_conventions layout "
1172 "identifier `%s' used", $1);
1176 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1178 (state->AMD_conservative_depth_enable ||
1179 state->ARB_conservative_depth_enable)) {
1180 if (strcmp($1, "depth_any") == 0) {
1181 $$.flags.q.depth_any = 1;
1182 } else if (strcmp($1, "depth_greater") == 0) {
1183 $$.flags.q.depth_greater = 1;
1184 } else if (strcmp($1, "depth_less") == 0) {
1185 $$.flags.q.depth_less = 1;
1186 } else if (strcmp($1, "depth_unchanged") == 0) {
1187 $$.flags.q.depth_unchanged = 1;
1190 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1191 _mesa_glsl_warning(& @1, state,
1192 "GL_AMD_conservative_depth "
1193 "layout qualifier `%s' is used", $1);
1195 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1196 _mesa_glsl_warning(& @1, state,
1197 "GL_ARB_conservative_depth "
1198 "layout qualifier `%s' is used", $1);
1202 /* See also interface_block_layout_qualifier. */
1203 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1204 if (strcmp($1, "std140") == 0) {
1205 $$.flags.q.std140 = 1;
1206 } else if (strcmp($1, "shared") == 0) {
1207 $$.flags.q.shared = 1;
1208 } else if (strcmp($1, "column_major") == 0) {
1209 $$.flags.q.column_major = 1;
1210 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1211 * below in the interface_block_layout_qualifier rule.
1213 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1216 } else if (strcmp($1, "row_major") == 0) {
1217 $$.flags.q.row_major = 1;
1220 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1221 _mesa_glsl_warning(& @1, state,
1222 "#version 140 / GL_ARB_uniform_buffer_object "
1223 "layout qualifier `%s' is used", $1);
1227 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1233 { "points", GL_POINTS },
1234 { "lines", GL_LINES },
1235 { "lines_adjacency", GL_LINES_ADJACENCY },
1236 { "line_strip", GL_LINE_STRIP },
1237 { "triangles", GL_TRIANGLES },
1238 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1239 { "triangle_strip", GL_TRIANGLE_STRIP },
1241 for (unsigned i = 0; i < Elements(map); i++) {
1242 if (strcmp($1, map[i].s) == 0) {
1243 $$.flags.q.prim_type = 1;
1244 $$.prim_type = map[i].e;
1249 if ($$.flags.i && !state->is_version(150, 0)) {
1250 _mesa_glsl_error(& @1, state, "#version 150 layout "
1251 "qualifier `%s' used", $1);
1256 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1261 | any_identifier '=' integer_constant
1263 memset(& $$, 0, sizeof($$));
1265 if (state->has_explicit_attrib_location()) {
1266 if (strcmp("location", $1) == 0) {
1267 $$.flags.q.explicit_location = 1;
1272 _mesa_glsl_error(& @3, state,
1273 "invalid location %d specified", $3);
1278 if (strcmp("index", $1) == 0) {
1279 $$.flags.q.explicit_index = 1;
1284 _mesa_glsl_error(& @3, state,
1285 "invalid index %d specified", $3);
1291 if (state->ARB_shading_language_420pack_enable &&
1292 strcmp("binding", $1) == 0) {
1293 $$.flags.q.explicit_binding = 1;
1297 if (strcmp("max_vertices", $1) == 0) {
1298 $$.flags.q.max_vertices = 1;
1301 _mesa_glsl_error(& @3, state,
1302 "invalid max_vertices %d specified", $3);
1305 $$.max_vertices = $3;
1306 if (!state->is_version(150, 0)) {
1307 _mesa_glsl_error(& @3, state,
1308 "#version 150 max_vertices qualifier "
1314 /* If the identifier didn't match any known layout identifiers,
1318 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1321 } else if (state->ARB_explicit_attrib_location_warn) {
1322 _mesa_glsl_warning(& @1, state,
1323 "GL_ARB_explicit_attrib_location layout "
1324 "identifier `%s' used", $1);
1327 | interface_block_layout_qualifier
1330 /* Layout qualifiers for ARB_uniform_buffer_object. */
1331 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1332 _mesa_glsl_error(& @1, state,
1333 "#version 140 / GL_ARB_uniform_buffer_object "
1334 "layout qualifier `%s' is used", $1);
1335 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1336 _mesa_glsl_warning(& @1, state,
1337 "#version 140 / GL_ARB_uniform_buffer_object "
1338 "layout qualifier `%s' is used", $1);
1343 /* This is a separate language rule because we parse these as tokens
1344 * (due to them being reserved keywords) instead of identifiers like
1345 * most qualifiers. See the any_identifier path of
1346 * layout_qualifier_id for the others.
1348 interface_block_layout_qualifier:
1351 memset(& $$, 0, sizeof($$));
1352 $$.flags.q.row_major = 1;
1356 memset(& $$, 0, sizeof($$));
1357 $$.flags.q.packed = 1;
1361 interpolation_qualifier:
1364 memset(& $$, 0, sizeof($$));
1365 $$.flags.q.smooth = 1;
1369 memset(& $$, 0, sizeof($$));
1370 $$.flags.q.flat = 1;
1374 memset(& $$, 0, sizeof($$));
1375 $$.flags.q.noperspective = 1;
1380 /* Single qualifiers */
1383 memset(& $$, 0, sizeof($$));
1384 $$.flags.q.invariant = 1;
1386 | auxiliary_storage_qualifier
1388 | interpolation_qualifier
1390 | precision_qualifier
1392 memset(&$$, 0, sizeof($$));
1396 /* Multiple qualifiers:
1397 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1398 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1400 * invariant interpolation auxiliary storage precision ...or...
1401 * layout storage precision
1403 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1404 * side don't contain any that must appear on the left hand side.
1405 * For example, when processing a storage qualifier, we check that there are
1406 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1408 | INVARIANT type_qualifier
1410 if ($2.flags.q.invariant)
1411 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1413 if ($2.has_layout()) {
1414 _mesa_glsl_error(&@1, state,
1415 "\"invariant\" cannot be used with layout(...)");
1419 $$.flags.q.invariant = 1;
1421 | interpolation_qualifier type_qualifier
1423 /* Section 4.3 of the GLSL 1.40 specification states:
1424 * "...qualified with one of these interpolation qualifiers"
1426 * GLSL 1.30 claims to allow "one or more", but insists that:
1427 * "These interpolation qualifiers may only precede the qualifiers in,
1428 * centroid in, out, or centroid out in a declaration."
1430 * ...which means that e.g. smooth can't precede smooth, so there can be
1431 * only one after all, and the 1.40 text is a clarification, not a change.
1433 if ($2.has_interpolation())
1434 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1436 if ($2.has_layout()) {
1437 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1438 "with layout(...)");
1441 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1442 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1443 "after \"invariant\"");
1447 $$.merge_qualifier(&@1, state, $2);
1449 | layout_qualifier type_qualifier
1451 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1452 * used standalone or immediately before a storage qualifier. It cannot
1453 * be used with interpolation qualifiers or invariant. There does not
1454 * appear to be any text indicating that it must come before the storage
1455 * qualifier, but always seems to in examples.
1457 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1458 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1460 if ($2.flags.q.invariant)
1461 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1462 "the \"invariant\" qualifier");
1464 if ($2.has_interpolation()) {
1465 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1466 "interpolation qualifiers");
1470 $$.merge_qualifier(&@1, state, $2);
1472 | auxiliary_storage_qualifier type_qualifier
1474 if ($2.has_auxiliary_storage()) {
1475 _mesa_glsl_error(&@1, state,
1476 "duplicate auxiliary storage qualifier (centroid)");
1479 if (!state->ARB_shading_language_420pack_enable &&
1480 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1481 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1482 "just before storage qualifiers");
1485 $$.flags.i |= $2.flags.i;
1487 | storage_qualifier type_qualifier
1489 /* Section 4.3 of the GLSL 1.20 specification states:
1490 * "Variable declarations may have a storage qualifier specified..."
1491 * 1.30 clarifies this to "may have one storage qualifier".
1493 if ($2.has_storage())
1494 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1496 if (!state->ARB_shading_language_420pack_enable &&
1497 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1498 $2.has_auxiliary_storage())) {
1499 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1500 "invariant, interpolation, layout and auxiliary "
1501 "storage qualifiers");
1505 $$.merge_qualifier(&@1, state, $2);
1507 | precision_qualifier type_qualifier
1509 if ($2.precision != ast_precision_none)
1510 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1512 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1513 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1520 auxiliary_storage_qualifier:
1523 memset(& $$, 0, sizeof($$));
1524 $$.flags.q.centroid = 1;
1526 /* TODO: "sample" and "patch" also go here someday. */
1531 memset(& $$, 0, sizeof($$));
1532 $$.flags.q.constant = 1;
1536 memset(& $$, 0, sizeof($$));
1537 $$.flags.q.attribute = 1;
1541 memset(& $$, 0, sizeof($$));
1542 $$.flags.q.varying = 1;
1546 memset(& $$, 0, sizeof($$));
1551 memset(& $$, 0, sizeof($$));
1556 memset(& $$, 0, sizeof($$));
1557 $$.flags.q.uniform = 1;
1562 type_specifier_nonarray
1563 | type_specifier_nonarray '[' ']'
1566 $$->is_array = true;
1567 $$->array_size = NULL;
1569 | type_specifier_nonarray '[' constant_expression ']'
1572 $$->is_array = true;
1573 $$->array_size = $3;
1577 type_specifier_nonarray:
1578 basic_type_specifier_nonarray
1581 $$ = new(ctx) ast_type_specifier($1);
1582 $$->set_location(yylloc);
1587 $$ = new(ctx) ast_type_specifier($1);
1588 $$->set_location(yylloc);
1593 $$ = new(ctx) ast_type_specifier($1);
1594 $$->set_location(yylloc);
1598 basic_type_specifier_nonarray:
1599 VOID_TOK { $$ = "void"; }
1600 | FLOAT_TOK { $$ = "float"; }
1601 | INT_TOK { $$ = "int"; }
1602 | UINT_TOK { $$ = "uint"; }
1603 | BOOL_TOK { $$ = "bool"; }
1604 | VEC2 { $$ = "vec2"; }
1605 | VEC3 { $$ = "vec3"; }
1606 | VEC4 { $$ = "vec4"; }
1607 | BVEC2 { $$ = "bvec2"; }
1608 | BVEC3 { $$ = "bvec3"; }
1609 | BVEC4 { $$ = "bvec4"; }
1610 | IVEC2 { $$ = "ivec2"; }
1611 | IVEC3 { $$ = "ivec3"; }
1612 | IVEC4 { $$ = "ivec4"; }
1613 | UVEC2 { $$ = "uvec2"; }
1614 | UVEC3 { $$ = "uvec3"; }
1615 | UVEC4 { $$ = "uvec4"; }
1616 | MAT2X2 { $$ = "mat2"; }
1617 | MAT2X3 { $$ = "mat2x3"; }
1618 | MAT2X4 { $$ = "mat2x4"; }
1619 | MAT3X2 { $$ = "mat3x2"; }
1620 | MAT3X3 { $$ = "mat3"; }
1621 | MAT3X4 { $$ = "mat3x4"; }
1622 | MAT4X2 { $$ = "mat4x2"; }
1623 | MAT4X3 { $$ = "mat4x3"; }
1624 | MAT4X4 { $$ = "mat4"; }
1625 | SAMPLER1D { $$ = "sampler1D"; }
1626 | SAMPLER2D { $$ = "sampler2D"; }
1627 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1628 | SAMPLER3D { $$ = "sampler3D"; }
1629 | SAMPLERCUBE { $$ = "samplerCube"; }
1630 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1631 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1632 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1633 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1634 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1635 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1636 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1637 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1638 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1639 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1640 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1641 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1642 | ISAMPLER1D { $$ = "isampler1D"; }
1643 | ISAMPLER2D { $$ = "isampler2D"; }
1644 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1645 | ISAMPLER3D { $$ = "isampler3D"; }
1646 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1647 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1648 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1649 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1650 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1651 | USAMPLER1D { $$ = "usampler1D"; }
1652 | USAMPLER2D { $$ = "usampler2D"; }
1653 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1654 | USAMPLER3D { $$ = "usampler3D"; }
1655 | USAMPLERCUBE { $$ = "usamplerCube"; }
1656 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1657 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1658 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1659 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1660 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1661 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1662 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1663 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1664 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1665 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1668 precision_qualifier:
1671 state->check_precision_qualifiers_allowed(&@1);
1672 $$ = ast_precision_high;
1676 state->check_precision_qualifiers_allowed(&@1);
1677 $$ = ast_precision_medium;
1681 state->check_precision_qualifiers_allowed(&@1);
1682 $$ = ast_precision_low;
1687 STRUCT any_identifier '{' struct_declaration_list '}'
1690 $$ = new(ctx) ast_struct_specifier($2, $4);
1691 $$->set_location(yylloc);
1692 state->symbols->add_type($2, glsl_type::void_type);
1693 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1695 | STRUCT '{' struct_declaration_list '}'
1698 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1699 $$->set_location(yylloc);
1703 struct_declaration_list:
1707 $1->link.self_link();
1709 | struct_declaration_list struct_declaration
1712 $$->link.insert_before(& $2->link);
1717 fully_specified_type struct_declarator_list ';'
1720 ast_fully_specified_type *const type = $1;
1721 type->set_location(yylloc);
1723 if (type->qualifier.flags.i != 0)
1724 _mesa_glsl_error(&@1, state,
1725 "only precision qualifiers may be applied to "
1726 "structure members");
1728 $$ = new(ctx) ast_declarator_list(type);
1729 $$->set_location(yylloc);
1731 $$->declarations.push_degenerate_list_at_head(& $2->link);
1735 struct_declarator_list:
1739 $1->link.self_link();
1741 | struct_declarator_list ',' struct_declarator
1744 $$->link.insert_before(& $3->link);
1752 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1753 $$->set_location(yylloc);
1755 | any_identifier '[' constant_expression ']'
1758 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1759 $$->set_location(yylloc);
1764 assignment_expression
1765 | '{' initializer_list '}'
1769 | '{' initializer_list ',' '}'
1779 $$ = new(ctx) ast_aggregate_initializer();
1780 $$->set_location(yylloc);
1781 $$->expressions.push_tail(& $1->link);
1783 | initializer_list ',' initializer
1785 $1->expressions.push_tail(& $3->link);
1789 declaration_statement:
1793 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1796 compound_statement { $$ = (ast_node *) $1; }
1801 declaration_statement
1802 | expression_statement
1803 | selection_statement
1805 | iteration_statement
1813 $$ = new(ctx) ast_compound_statement(true, NULL);
1814 $$->set_location(yylloc);
1818 state->symbols->push_scope();
1823 $$ = new(ctx) ast_compound_statement(true, $3);
1824 $$->set_location(yylloc);
1825 state->symbols->pop_scope();
1829 statement_no_new_scope:
1830 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1834 compound_statement_no_new_scope:
1838 $$ = new(ctx) ast_compound_statement(false, NULL);
1839 $$->set_location(yylloc);
1841 | '{' statement_list '}'
1844 $$ = new(ctx) ast_compound_statement(false, $2);
1845 $$->set_location(yylloc);
1853 _mesa_glsl_error(& @1, state, "<nil> statement");
1858 $$->link.self_link();
1860 | statement_list statement
1863 _mesa_glsl_error(& @2, state, "<nil> statement");
1867 $$->link.insert_before(& $2->link);
1871 expression_statement:
1875 $$ = new(ctx) ast_expression_statement(NULL);
1876 $$->set_location(yylloc);
1881 $$ = new(ctx) ast_expression_statement($1);
1882 $$->set_location(yylloc);
1886 selection_statement:
1887 IF '(' expression ')' selection_rest_statement
1889 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1891 $$->set_location(yylloc);
1895 selection_rest_statement:
1896 statement ELSE statement
1898 $$.then_statement = $1;
1899 $$.else_statement = $3;
1901 | statement %prec THEN
1903 $$.then_statement = $1;
1904 $$.else_statement = NULL;
1911 $$ = (ast_node *) $1;
1913 | fully_specified_type any_identifier '=' initializer
1916 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1917 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1918 decl->set_location(yylloc);
1919 declarator->set_location(yylloc);
1921 declarator->declarations.push_tail(&decl->link);
1927 * siwtch_statement grammar is based on the syntax described in the body
1928 * of the GLSL spec, not in it's appendix!!!
1931 SWITCH '(' expression ')' switch_body
1933 $$ = new(state) ast_switch_statement($3, $5);
1934 $$->set_location(yylloc);
1941 $$ = new(state) ast_switch_body(NULL);
1942 $$->set_location(yylloc);
1944 | '{' case_statement_list '}'
1946 $$ = new(state) ast_switch_body($2);
1947 $$->set_location(yylloc);
1954 $$ = new(state) ast_case_label($2);
1955 $$->set_location(yylloc);
1959 $$ = new(state) ast_case_label(NULL);
1960 $$->set_location(yylloc);
1967 ast_case_label_list *labels = new(state) ast_case_label_list();
1969 labels->labels.push_tail(& $1->link);
1971 $$->set_location(yylloc);
1973 | case_label_list case_label
1976 $$->labels.push_tail(& $2->link);
1981 case_label_list statement
1983 ast_case_statement *stmts = new(state) ast_case_statement($1);
1984 stmts->set_location(yylloc);
1986 stmts->stmts.push_tail(& $2->link);
1989 | case_statement statement
1992 $$->stmts.push_tail(& $2->link);
1996 case_statement_list:
1999 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2000 cases->set_location(yylloc);
2002 cases->cases.push_tail(& $1->link);
2005 | case_statement_list case_statement
2008 $$->cases.push_tail(& $2->link);
2012 iteration_statement:
2013 WHILE '(' condition ')' statement_no_new_scope
2016 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2017 NULL, $3, NULL, $5);
2018 $$->set_location(yylloc);
2020 | DO statement WHILE '(' expression ')' ';'
2023 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2024 NULL, $5, NULL, $2);
2025 $$->set_location(yylloc);
2027 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2030 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2031 $3, $4.cond, $4.rest, $6);
2032 $$->set_location(yylloc);
2037 expression_statement
2038 | declaration_statement
2055 | conditionopt ';' expression
2062 // Grammar Note: No 'goto'. Gotos are not supported.
2067 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2068 $$->set_location(yylloc);
2073 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2074 $$->set_location(yylloc);
2079 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2080 $$->set_location(yylloc);
2082 | RETURN expression ';'
2085 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2086 $$->set_location(yylloc);
2088 | DISCARD ';' // Fragment shader only.
2091 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2092 $$->set_location(yylloc);
2096 external_declaration:
2097 function_definition { $$ = $1; }
2098 | declaration { $$ = $1; }
2099 | pragma_statement { $$ = NULL; }
2100 | layout_defaults { $$ = $1; }
2103 function_definition:
2104 function_prototype compound_statement_no_new_scope
2107 $$ = new(ctx) ast_function_definition();
2108 $$->set_location(yylloc);
2112 state->symbols->pop_scope();
2116 /* layout_qualifieropt is packed into this rule */
2118 basic_interface_block
2122 | layout_qualifier basic_interface_block
2124 ast_interface_block *block = $2;
2125 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2132 basic_interface_block:
2133 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2135 ast_interface_block *const block = $6;
2137 block->block_name = $2;
2138 block->declarations.push_degenerate_list_at_head(& $4->link);
2140 if ($1.flags.q.uniform) {
2141 if (!state->ARB_uniform_buffer_object_enable) {
2142 _mesa_glsl_error(& @1, state,
2143 "#version 140 / GL_ARB_uniform_buffer_object "
2144 "required for defining uniform blocks");
2145 } else if (state->ARB_uniform_buffer_object_warn) {
2146 _mesa_glsl_warning(& @1, state,
2147 "#version 140 / GL_ARB_uniform_buffer_object "
2148 "required for defining uniform blocks");
2151 if (state->es_shader || state->language_version < 150) {
2152 _mesa_glsl_error(& @1, state,
2153 "#version 150 required for using "
2154 "interface blocks");
2158 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2159 * "It is illegal to have an input block in a vertex shader
2160 * or an output block in a fragment shader"
2162 if ((state->target == vertex_shader) && $1.flags.q.in) {
2163 _mesa_glsl_error(& @1, state,
2164 "`in' interface block is not allowed for "
2166 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2167 _mesa_glsl_error(& @1, state,
2168 "`out' interface block is not allowed for "
2169 "a fragment shader");
2172 /* Since block arrays require names, and both features are added in
2173 * the same language versions, we don't have to explicitly
2174 * version-check both things.
2176 if (block->instance_name != NULL) {
2177 state->check_version(150, 300, & @1, "interface blocks with "
2178 "an instance name are not allowed");
2181 unsigned interface_type_mask;
2182 struct ast_type_qualifier temp_type_qualifier;
2184 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2185 * to ignore other irrelevant flags like interpolation qualifiers.
2187 temp_type_qualifier.flags.i = 0;
2188 temp_type_qualifier.flags.q.uniform = true;
2189 temp_type_qualifier.flags.q.in = true;
2190 temp_type_qualifier.flags.q.out = true;
2191 interface_type_mask = temp_type_qualifier.flags.i;
2193 /* Get the block's interface qualifier. The interface_qualifier
2194 * production rule guarantees that only one bit will be set (and
2195 * it will be in/out/uniform).
2197 unsigned block_interface_qualifier = $1.flags.i;
2199 block->layout.flags.i |= block_interface_qualifier;
2201 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2202 ast_type_qualifier& qualifier = member->type->qualifier;
2203 if ((qualifier.flags.i & interface_type_mask) == 0) {
2204 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2205 * "If no optional qualifier is used in a member declaration, the
2206 * qualifier of the variable is just in, out, or uniform as declared
2207 * by interface-qualifier."
2209 qualifier.flags.i |= block_interface_qualifier;
2210 } else if ((qualifier.flags.i & interface_type_mask) !=
2211 block_interface_qualifier) {
2212 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2213 * "If optional qualifiers are used, they can include interpolation
2214 * and storage qualifiers and they must declare an input, output,
2215 * or uniform variable consistent with the interface qualifier of
2218 _mesa_glsl_error(& @1, state,
2219 "uniform/in/out qualifier on "
2220 "interface block member does not match "
2221 "the interface block");
2229 interface_qualifier:
2232 memset(& $$, 0, sizeof($$));
2237 memset(& $$, 0, sizeof($$));
2242 memset(& $$, 0, sizeof($$));
2243 $$.flags.q.uniform = 1;
2250 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2255 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2258 | NEW_IDENTIFIER '[' constant_expression ']'
2260 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2263 | NEW_IDENTIFIER '[' ']'
2265 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2274 $1->link.self_link();
2276 | member_declaration member_list
2279 $2->link.insert_before(& $$->link);
2284 fully_specified_type struct_declarator_list ';'
2287 ast_fully_specified_type *type = $1;
2288 type->set_location(yylloc);
2290 if (type->qualifier.flags.q.attribute) {
2291 _mesa_glsl_error(& @1, state,
2292 "keyword 'attribute' cannot be used with "
2293 "interface block member");
2294 } else if (type->qualifier.flags.q.varying) {
2295 _mesa_glsl_error(& @1, state,
2296 "keyword 'varying' cannot be used with "
2297 "interface block member");
2300 $$ = new(ctx) ast_declarator_list(type);
2301 $$->set_location(yylloc);
2303 $$->declarations.push_degenerate_list_at_head(& $2->link);
2308 layout_qualifier UNIFORM ';'
2310 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2316 | layout_qualifier IN_TOK ';'
2319 if (state->target != geometry_shader) {
2320 _mesa_glsl_error(& @1, state,
2321 "input layout qualifiers only valid in "
2322 "geometry shaders");
2323 } else if (!$1.flags.q.prim_type) {
2324 _mesa_glsl_error(& @1, state,
2325 "input layout qualifiers must specify a primitive"
2328 $$ = new(ctx) ast_gs_input_layout(@1, $1.prim_type);
2331 | layout_qualifier OUT_TOK ';'
2333 if (state->target != geometry_shader) {
2334 _mesa_glsl_error(& @1, state,
2335 "out layout qualifiers only valid in "
2336 "geometry shaders");
2337 } else if (!state->out_qualifier->merge_qualifier(& @1, state, $1)) {