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 if (strcmp($1, "origin_upper_left") == 0) {
1163 $$.flags.q.origin_upper_left = 1;
1164 } else if (strcmp($1, "pixel_center_integer") == 0) {
1165 $$.flags.q.pixel_center_integer = 1;
1168 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1169 _mesa_glsl_warning(& @1, state,
1170 "GL_ARB_fragment_coord_conventions layout "
1171 "identifier `%s' used", $1);
1175 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1177 (state->AMD_conservative_depth_enable ||
1178 state->ARB_conservative_depth_enable)) {
1179 if (strcmp($1, "depth_any") == 0) {
1180 $$.flags.q.depth_any = 1;
1181 } else if (strcmp($1, "depth_greater") == 0) {
1182 $$.flags.q.depth_greater = 1;
1183 } else if (strcmp($1, "depth_less") == 0) {
1184 $$.flags.q.depth_less = 1;
1185 } else if (strcmp($1, "depth_unchanged") == 0) {
1186 $$.flags.q.depth_unchanged = 1;
1189 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1190 _mesa_glsl_warning(& @1, state,
1191 "GL_AMD_conservative_depth "
1192 "layout qualifier `%s' is used", $1);
1194 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1195 _mesa_glsl_warning(& @1, state,
1196 "GL_ARB_conservative_depth "
1197 "layout qualifier `%s' is used", $1);
1201 /* See also interface_block_layout_qualifier. */
1202 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1203 if (strcmp($1, "std140") == 0) {
1204 $$.flags.q.std140 = 1;
1205 } else if (strcmp($1, "shared") == 0) {
1206 $$.flags.q.shared = 1;
1207 } else if (strcmp($1, "column_major") == 0) {
1208 $$.flags.q.column_major = 1;
1209 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1210 * below in the interface_block_layout_qualifier rule.
1212 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1215 } else if (strcmp($1, "row_major") == 0) {
1216 $$.flags.q.row_major = 1;
1219 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1220 _mesa_glsl_warning(& @1, state,
1221 "#version 140 / GL_ARB_uniform_buffer_object "
1222 "layout qualifier `%s' is used", $1);
1226 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1232 { "points", GL_POINTS },
1233 { "lines", GL_LINES },
1234 { "lines_adjacency", GL_LINES_ADJACENCY },
1235 { "line_strip", GL_LINE_STRIP },
1236 { "triangles", GL_TRIANGLES },
1237 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1238 { "triangle_strip", GL_TRIANGLE_STRIP },
1240 for (unsigned i = 0; i < Elements(map); i++) {
1241 if (strcmp($1, map[i].s) == 0) {
1242 $$.flags.q.prim_type = 1;
1243 $$.prim_type = map[i].e;
1248 if ($$.flags.i && !state->is_version(150, 0)) {
1249 _mesa_glsl_error(& @1, state, "#version 150 layout "
1250 "qualifier `%s' used", $1);
1255 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1260 | any_identifier '=' integer_constant
1262 memset(& $$, 0, sizeof($$));
1264 if (state->ARB_explicit_attrib_location_enable) {
1265 if (strcmp("location", $1) == 0) {
1266 $$.flags.q.explicit_location = 1;
1271 _mesa_glsl_error(& @3, state,
1272 "invalid location %d specified", $3);
1277 if (strcmp("index", $1) == 0) {
1278 $$.flags.q.explicit_index = 1;
1283 _mesa_glsl_error(& @3, state,
1284 "invalid index %d specified", $3);
1290 if (state->ARB_shading_language_420pack_enable &&
1291 strcmp("binding", $1) == 0) {
1292 $$.flags.q.explicit_binding = 1;
1296 if (strcmp("max_vertices", $1) == 0) {
1297 $$.flags.q.max_vertices = 1;
1300 _mesa_glsl_error(& @3, state,
1301 "invalid max_vertices %d specified", $3);
1304 $$.max_vertices = $3;
1305 if (!state->is_version(150, 0)) {
1306 _mesa_glsl_error(& @3, state,
1307 "#version 150 max_vertices qualifier "
1313 /* If the identifier didn't match any known layout identifiers,
1317 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1320 } else if (state->ARB_explicit_attrib_location_warn) {
1321 _mesa_glsl_warning(& @1, state,
1322 "GL_ARB_explicit_attrib_location layout "
1323 "identifier `%s' used", $1);
1326 | interface_block_layout_qualifier
1329 /* Layout qualifiers for ARB_uniform_buffer_object. */
1330 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1331 _mesa_glsl_error(& @1, state,
1332 "#version 140 / GL_ARB_uniform_buffer_object "
1333 "layout qualifier `%s' is used", $1);
1334 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1335 _mesa_glsl_warning(& @1, state,
1336 "#version 140 / GL_ARB_uniform_buffer_object "
1337 "layout qualifier `%s' is used", $1);
1342 /* This is a separate language rule because we parse these as tokens
1343 * (due to them being reserved keywords) instead of identifiers like
1344 * most qualifiers. See the any_identifier path of
1345 * layout_qualifier_id for the others.
1347 interface_block_layout_qualifier:
1350 memset(& $$, 0, sizeof($$));
1351 $$.flags.q.row_major = 1;
1355 memset(& $$, 0, sizeof($$));
1356 $$.flags.q.packed = 1;
1360 interpolation_qualifier:
1363 memset(& $$, 0, sizeof($$));
1364 $$.flags.q.smooth = 1;
1368 memset(& $$, 0, sizeof($$));
1369 $$.flags.q.flat = 1;
1373 memset(& $$, 0, sizeof($$));
1374 $$.flags.q.noperspective = 1;
1379 /* Single qualifiers */
1382 memset(& $$, 0, sizeof($$));
1383 $$.flags.q.invariant = 1;
1385 | auxiliary_storage_qualifier
1387 | interpolation_qualifier
1389 | precision_qualifier
1391 memset(&$$, 0, sizeof($$));
1395 /* Multiple qualifiers:
1396 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1397 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1399 * invariant interpolation auxiliary storage precision ...or...
1400 * layout storage precision
1402 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1403 * side don't contain any that must appear on the left hand side.
1404 * For example, when processing a storage qualifier, we check that there are
1405 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1407 | INVARIANT type_qualifier
1409 if ($2.flags.q.invariant)
1410 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1412 if ($2.has_layout()) {
1413 _mesa_glsl_error(&@1, state,
1414 "\"invariant\" cannot be used with layout(...)");
1418 $$.flags.q.invariant = 1;
1420 | interpolation_qualifier type_qualifier
1422 /* Section 4.3 of the GLSL 1.40 specification states:
1423 * "...qualified with one of these interpolation qualifiers"
1425 * GLSL 1.30 claims to allow "one or more", but insists that:
1426 * "These interpolation qualifiers may only precede the qualifiers in,
1427 * centroid in, out, or centroid out in a declaration."
1429 * ...which means that e.g. smooth can't precede smooth, so there can be
1430 * only one after all, and the 1.40 text is a clarification, not a change.
1432 if ($2.has_interpolation())
1433 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1435 if ($2.has_layout()) {
1436 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1437 "with layout(...)");
1440 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1441 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1442 "after \"invariant\"");
1446 $$.merge_qualifier(&@1, state, $2);
1448 | layout_qualifier type_qualifier
1450 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1451 * used standalone or immediately before a storage qualifier. It cannot
1452 * be used with interpolation qualifiers or invariant. There does not
1453 * appear to be any text indicating that it must come before the storage
1454 * qualifier, but always seems to in examples.
1456 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1457 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1459 if ($2.flags.q.invariant)
1460 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1461 "the \"invariant\" qualifier");
1463 if ($2.has_interpolation()) {
1464 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1465 "interpolation qualifiers");
1469 $$.merge_qualifier(&@1, state, $2);
1471 | auxiliary_storage_qualifier type_qualifier
1473 if ($2.has_auxiliary_storage()) {
1474 _mesa_glsl_error(&@1, state,
1475 "duplicate auxiliary storage qualifier (centroid)");
1478 if (!state->ARB_shading_language_420pack_enable &&
1479 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1480 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1481 "just before storage qualifiers");
1484 $$.flags.i |= $2.flags.i;
1486 | storage_qualifier type_qualifier
1488 /* Section 4.3 of the GLSL 1.20 specification states:
1489 * "Variable declarations may have a storage qualifier specified..."
1490 * 1.30 clarifies this to "may have one storage qualifier".
1492 if ($2.has_storage())
1493 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1495 if (!state->ARB_shading_language_420pack_enable &&
1496 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1497 $2.has_auxiliary_storage())) {
1498 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1499 "invariant, interpolation, layout and auxiliary "
1500 "storage qualifiers");
1504 $$.merge_qualifier(&@1, state, $2);
1506 | precision_qualifier type_qualifier
1508 if ($2.precision != ast_precision_none)
1509 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1511 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1512 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1519 auxiliary_storage_qualifier:
1522 memset(& $$, 0, sizeof($$));
1523 $$.flags.q.centroid = 1;
1525 /* TODO: "sample" and "patch" also go here someday. */
1530 memset(& $$, 0, sizeof($$));
1531 $$.flags.q.constant = 1;
1535 memset(& $$, 0, sizeof($$));
1536 $$.flags.q.attribute = 1;
1540 memset(& $$, 0, sizeof($$));
1541 $$.flags.q.varying = 1;
1545 memset(& $$, 0, sizeof($$));
1550 memset(& $$, 0, sizeof($$));
1555 memset(& $$, 0, sizeof($$));
1556 $$.flags.q.uniform = 1;
1561 type_specifier_nonarray
1562 | type_specifier_nonarray '[' ']'
1565 $$->is_array = true;
1566 $$->array_size = NULL;
1568 | type_specifier_nonarray '[' constant_expression ']'
1571 $$->is_array = true;
1572 $$->array_size = $3;
1576 type_specifier_nonarray:
1577 basic_type_specifier_nonarray
1580 $$ = new(ctx) ast_type_specifier($1);
1581 $$->set_location(yylloc);
1586 $$ = new(ctx) ast_type_specifier($1);
1587 $$->set_location(yylloc);
1592 $$ = new(ctx) ast_type_specifier($1);
1593 $$->set_location(yylloc);
1597 basic_type_specifier_nonarray:
1598 VOID_TOK { $$ = "void"; }
1599 | FLOAT_TOK { $$ = "float"; }
1600 | INT_TOK { $$ = "int"; }
1601 | UINT_TOK { $$ = "uint"; }
1602 | BOOL_TOK { $$ = "bool"; }
1603 | VEC2 { $$ = "vec2"; }
1604 | VEC3 { $$ = "vec3"; }
1605 | VEC4 { $$ = "vec4"; }
1606 | BVEC2 { $$ = "bvec2"; }
1607 | BVEC3 { $$ = "bvec3"; }
1608 | BVEC4 { $$ = "bvec4"; }
1609 | IVEC2 { $$ = "ivec2"; }
1610 | IVEC3 { $$ = "ivec3"; }
1611 | IVEC4 { $$ = "ivec4"; }
1612 | UVEC2 { $$ = "uvec2"; }
1613 | UVEC3 { $$ = "uvec3"; }
1614 | UVEC4 { $$ = "uvec4"; }
1615 | MAT2X2 { $$ = "mat2"; }
1616 | MAT2X3 { $$ = "mat2x3"; }
1617 | MAT2X4 { $$ = "mat2x4"; }
1618 | MAT3X2 { $$ = "mat3x2"; }
1619 | MAT3X3 { $$ = "mat3"; }
1620 | MAT3X4 { $$ = "mat3x4"; }
1621 | MAT4X2 { $$ = "mat4x2"; }
1622 | MAT4X3 { $$ = "mat4x3"; }
1623 | MAT4X4 { $$ = "mat4"; }
1624 | SAMPLER1D { $$ = "sampler1D"; }
1625 | SAMPLER2D { $$ = "sampler2D"; }
1626 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1627 | SAMPLER3D { $$ = "sampler3D"; }
1628 | SAMPLERCUBE { $$ = "samplerCube"; }
1629 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1630 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1631 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1632 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1633 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1634 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1635 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1636 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1637 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1638 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1639 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1640 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1641 | ISAMPLER1D { $$ = "isampler1D"; }
1642 | ISAMPLER2D { $$ = "isampler2D"; }
1643 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1644 | ISAMPLER3D { $$ = "isampler3D"; }
1645 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1646 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1647 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1648 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1649 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1650 | USAMPLER1D { $$ = "usampler1D"; }
1651 | USAMPLER2D { $$ = "usampler2D"; }
1652 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1653 | USAMPLER3D { $$ = "usampler3D"; }
1654 | USAMPLERCUBE { $$ = "usamplerCube"; }
1655 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1656 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1657 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1658 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1659 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1660 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1661 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1662 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1663 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1664 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1667 precision_qualifier:
1670 state->check_precision_qualifiers_allowed(&@1);
1671 $$ = ast_precision_high;
1675 state->check_precision_qualifiers_allowed(&@1);
1676 $$ = ast_precision_medium;
1680 state->check_precision_qualifiers_allowed(&@1);
1681 $$ = ast_precision_low;
1686 STRUCT any_identifier '{' struct_declaration_list '}'
1689 $$ = new(ctx) ast_struct_specifier($2, $4);
1690 $$->set_location(yylloc);
1691 state->symbols->add_type($2, glsl_type::void_type);
1692 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1694 | STRUCT '{' struct_declaration_list '}'
1697 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1698 $$->set_location(yylloc);
1702 struct_declaration_list:
1706 $1->link.self_link();
1708 | struct_declaration_list struct_declaration
1711 $$->link.insert_before(& $2->link);
1716 type_specifier struct_declarator_list ';'
1719 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1720 type->set_location(yylloc);
1722 type->specifier = $1;
1723 $$ = new(ctx) ast_declarator_list(type);
1724 $$->set_location(yylloc);
1726 $$->declarations.push_degenerate_list_at_head(& $2->link);
1730 struct_declarator_list:
1734 $1->link.self_link();
1736 | struct_declarator_list ',' struct_declarator
1739 $$->link.insert_before(& $3->link);
1747 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1748 $$->set_location(yylloc);
1750 | any_identifier '[' constant_expression ']'
1753 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1754 $$->set_location(yylloc);
1759 assignment_expression
1760 | '{' initializer_list '}'
1764 | '{' initializer_list ',' '}'
1774 $$ = new(ctx) ast_aggregate_initializer();
1775 $$->set_location(yylloc);
1776 $$->expressions.push_tail(& $1->link);
1778 | initializer_list ',' initializer
1780 $1->expressions.push_tail(& $3->link);
1784 declaration_statement:
1788 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1791 compound_statement { $$ = (ast_node *) $1; }
1796 declaration_statement
1797 | expression_statement
1798 | selection_statement
1800 | iteration_statement
1808 $$ = new(ctx) ast_compound_statement(true, NULL);
1809 $$->set_location(yylloc);
1813 state->symbols->push_scope();
1818 $$ = new(ctx) ast_compound_statement(true, $3);
1819 $$->set_location(yylloc);
1820 state->symbols->pop_scope();
1824 statement_no_new_scope:
1825 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1829 compound_statement_no_new_scope:
1833 $$ = new(ctx) ast_compound_statement(false, NULL);
1834 $$->set_location(yylloc);
1836 | '{' statement_list '}'
1839 $$ = new(ctx) ast_compound_statement(false, $2);
1840 $$->set_location(yylloc);
1848 _mesa_glsl_error(& @1, state, "<nil> statement");
1853 $$->link.self_link();
1855 | statement_list statement
1858 _mesa_glsl_error(& @2, state, "<nil> statement");
1862 $$->link.insert_before(& $2->link);
1866 expression_statement:
1870 $$ = new(ctx) ast_expression_statement(NULL);
1871 $$->set_location(yylloc);
1876 $$ = new(ctx) ast_expression_statement($1);
1877 $$->set_location(yylloc);
1881 selection_statement:
1882 IF '(' expression ')' selection_rest_statement
1884 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1886 $$->set_location(yylloc);
1890 selection_rest_statement:
1891 statement ELSE statement
1893 $$.then_statement = $1;
1894 $$.else_statement = $3;
1896 | statement %prec THEN
1898 $$.then_statement = $1;
1899 $$.else_statement = NULL;
1906 $$ = (ast_node *) $1;
1908 | fully_specified_type any_identifier '=' initializer
1911 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1912 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1913 decl->set_location(yylloc);
1914 declarator->set_location(yylloc);
1916 declarator->declarations.push_tail(&decl->link);
1922 * siwtch_statement grammar is based on the syntax described in the body
1923 * of the GLSL spec, not in it's appendix!!!
1926 SWITCH '(' expression ')' switch_body
1928 $$ = new(state) ast_switch_statement($3, $5);
1929 $$->set_location(yylloc);
1936 $$ = new(state) ast_switch_body(NULL);
1937 $$->set_location(yylloc);
1939 | '{' case_statement_list '}'
1941 $$ = new(state) ast_switch_body($2);
1942 $$->set_location(yylloc);
1949 $$ = new(state) ast_case_label($2);
1950 $$->set_location(yylloc);
1954 $$ = new(state) ast_case_label(NULL);
1955 $$->set_location(yylloc);
1962 ast_case_label_list *labels = new(state) ast_case_label_list();
1964 labels->labels.push_tail(& $1->link);
1966 $$->set_location(yylloc);
1968 | case_label_list case_label
1971 $$->labels.push_tail(& $2->link);
1976 case_label_list statement
1978 ast_case_statement *stmts = new(state) ast_case_statement($1);
1979 stmts->set_location(yylloc);
1981 stmts->stmts.push_tail(& $2->link);
1984 | case_statement statement
1987 $$->stmts.push_tail(& $2->link);
1991 case_statement_list:
1994 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1995 cases->set_location(yylloc);
1997 cases->cases.push_tail(& $1->link);
2000 | case_statement_list case_statement
2003 $$->cases.push_tail(& $2->link);
2007 iteration_statement:
2008 WHILE '(' condition ')' statement_no_new_scope
2011 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2012 NULL, $3, NULL, $5);
2013 $$->set_location(yylloc);
2015 | DO statement WHILE '(' expression ')' ';'
2018 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2019 NULL, $5, NULL, $2);
2020 $$->set_location(yylloc);
2022 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2025 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2026 $3, $4.cond, $4.rest, $6);
2027 $$->set_location(yylloc);
2032 expression_statement
2033 | declaration_statement
2050 | conditionopt ';' expression
2057 // Grammar Note: No 'goto'. Gotos are not supported.
2062 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2063 $$->set_location(yylloc);
2068 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2069 $$->set_location(yylloc);
2074 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2075 $$->set_location(yylloc);
2077 | RETURN expression ';'
2080 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2081 $$->set_location(yylloc);
2083 | DISCARD ';' // Fragment shader only.
2086 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2087 $$->set_location(yylloc);
2091 external_declaration:
2092 function_definition { $$ = $1; }
2093 | declaration { $$ = $1; }
2094 | pragma_statement { $$ = NULL; }
2095 | layout_defaults { $$ = $1; }
2098 function_definition:
2099 function_prototype compound_statement_no_new_scope
2102 $$ = new(ctx) ast_function_definition();
2103 $$->set_location(yylloc);
2107 state->symbols->pop_scope();
2111 /* layout_qualifieropt is packed into this rule */
2113 basic_interface_block
2117 | layout_qualifier basic_interface_block
2119 ast_interface_block *block = $2;
2120 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2127 basic_interface_block:
2128 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2130 ast_interface_block *const block = $6;
2132 block->block_name = $2;
2133 block->declarations.push_degenerate_list_at_head(& $4->link);
2135 if ($1.flags.q.uniform) {
2136 if (!state->ARB_uniform_buffer_object_enable) {
2137 _mesa_glsl_error(& @1, state,
2138 "#version 140 / GL_ARB_uniform_buffer_object "
2139 "required for defining uniform blocks");
2140 } else if (state->ARB_uniform_buffer_object_warn) {
2141 _mesa_glsl_warning(& @1, state,
2142 "#version 140 / GL_ARB_uniform_buffer_object "
2143 "required for defining uniform blocks");
2146 if (state->es_shader || state->language_version < 150) {
2147 _mesa_glsl_error(& @1, state,
2148 "#version 150 required for using "
2149 "interface blocks");
2153 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2154 * "It is illegal to have an input block in a vertex shader
2155 * or an output block in a fragment shader"
2157 if ((state->target == vertex_shader) && $1.flags.q.in) {
2158 _mesa_glsl_error(& @1, state,
2159 "`in' interface block is not allowed for "
2161 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2162 _mesa_glsl_error(& @1, state,
2163 "`out' interface block is not allowed for "
2164 "a fragment shader");
2167 /* Since block arrays require names, and both features are added in
2168 * the same language versions, we don't have to explicitly
2169 * version-check both things.
2171 if (block->instance_name != NULL) {
2172 state->check_version(150, 300, & @1, "interface blocks with "
2173 "an instance name are not allowed");
2176 unsigned interface_type_mask;
2177 struct ast_type_qualifier temp_type_qualifier;
2179 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2180 * to ignore other irrelevant flags like interpolation qualifiers.
2182 temp_type_qualifier.flags.i = 0;
2183 temp_type_qualifier.flags.q.uniform = true;
2184 temp_type_qualifier.flags.q.in = true;
2185 temp_type_qualifier.flags.q.out = true;
2186 interface_type_mask = temp_type_qualifier.flags.i;
2188 /* Get the block's interface qualifier. The interface_qualifier
2189 * production rule guarantees that only one bit will be set (and
2190 * it will be in/out/uniform).
2192 unsigned block_interface_qualifier = $1.flags.i;
2194 block->layout.flags.i |= block_interface_qualifier;
2196 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2197 ast_type_qualifier& qualifier = member->type->qualifier;
2198 if ((qualifier.flags.i & interface_type_mask) == 0) {
2199 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2200 * "If no optional qualifier is used in a member declaration, the
2201 * qualifier of the variable is just in, out, or uniform as declared
2202 * by interface-qualifier."
2204 qualifier.flags.i |= block_interface_qualifier;
2205 } else if ((qualifier.flags.i & interface_type_mask) !=
2206 block_interface_qualifier) {
2207 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2208 * "If optional qualifiers are used, they can include interpolation
2209 * and storage qualifiers and they must declare an input, output,
2210 * or uniform variable consistent with the interface qualifier of
2213 _mesa_glsl_error(& @1, state,
2214 "uniform/in/out qualifier on "
2215 "interface block member does not match "
2216 "the interface block");
2224 interface_qualifier:
2227 memset(& $$, 0, sizeof($$));
2232 memset(& $$, 0, sizeof($$));
2237 memset(& $$, 0, sizeof($$));
2238 $$.flags.q.uniform = 1;
2245 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2250 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2253 | NEW_IDENTIFIER '[' constant_expression ']'
2255 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2258 | NEW_IDENTIFIER '[' ']'
2260 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2269 $1->link.self_link();
2271 | member_declaration member_list
2274 $2->link.insert_before(& $$->link);
2279 fully_specified_type struct_declarator_list ';'
2282 ast_fully_specified_type *type = $1;
2283 type->set_location(yylloc);
2285 if (type->qualifier.flags.q.attribute) {
2286 _mesa_glsl_error(& @1, state,
2287 "keyword 'attribute' cannot be used with "
2288 "interface block member");
2289 } else if (type->qualifier.flags.q.varying) {
2290 _mesa_glsl_error(& @1, state,
2291 "keyword 'varying' cannot be used with "
2292 "interface block member");
2295 $$ = new(ctx) ast_declarator_list(type);
2296 $$->set_location(yylloc);
2297 $$->ubo_qualifiers_valid = true;
2299 $$->declarations.push_degenerate_list_at_head(& $2->link);
2304 layout_qualifier UNIFORM ';'
2306 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2312 | layout_qualifier IN_TOK ';'
2315 if (state->target != geometry_shader) {
2316 _mesa_glsl_error(& @1, state,
2317 "input layout qualifiers only valid in "
2318 "geometry shaders");
2319 } else if (!$1.flags.q.prim_type) {
2320 _mesa_glsl_error(& @1, state,
2321 "input layout qualifiers must specify a primitive"
2324 $$ = new(ctx) ast_gs_input_layout(@1, $1.prim_type);
2327 | layout_qualifier OUT_TOK ';'
2329 if (state->target != geometry_shader) {
2330 _mesa_glsl_error(& @1, state,
2331 "out layout qualifiers only valid in "
2332 "geometry shaders");
2333 } else if (!state->out_qualifier->merge_qualifier(& @1, state, $1)) {