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);
47 static bool match_layout_qualifier(const char *s1, const char *s2,
48 _mesa_glsl_parse_state *state)
50 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
52 * "The tokens in any layout-qualifier-id-list ... are not case
53 * sensitive, unless explicitly noted otherwise."
55 * The text "unless explicitly noted otherwise" appears to be
56 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
59 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
62 * "As for other identifiers, they are case sensitive."
64 * So we need to do a case-sensitive or a case-insensitive match,
65 * depending on whether we are compiling for GLSL ES.
68 return strcmp(s1, s2);
70 return strcasecmp(s1, s2);
88 %lex-param {struct _mesa_glsl_parse_state *state}
89 %parse-param {struct _mesa_glsl_parse_state *state}
94 const char *identifier;
96 struct ast_type_qualifier type_qualifier;
99 ast_type_specifier *type_specifier;
100 ast_fully_specified_type *fully_specified_type;
101 ast_function *function;
102 ast_parameter_declarator *parameter_declarator;
103 ast_function_definition *function_definition;
104 ast_compound_statement *compound_statement;
105 ast_expression *expression;
106 ast_declarator_list *declarator_list;
107 ast_struct_specifier *struct_specifier;
108 ast_declaration *declaration;
109 ast_switch_body *switch_body;
110 ast_case_label *case_label;
111 ast_case_label_list *case_label_list;
112 ast_case_statement *case_statement;
113 ast_case_statement_list *case_statement_list;
114 ast_interface_block *interface_block;
118 ast_expression *rest;
119 } for_rest_statement;
122 ast_node *then_statement;
123 ast_node *else_statement;
124 } selection_rest_statement;
127 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
128 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
129 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
130 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
131 %token NOPERSPECTIVE FLAT SMOOTH
132 %token MAT2X2 MAT2X3 MAT2X4
133 %token MAT3X2 MAT3X3 MAT3X4
134 %token MAT4X2 MAT4X3 MAT4X4
135 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
136 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
137 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
138 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
139 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
140 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
141 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
142 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
143 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
144 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
145 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
146 %token SAMPLEREXTERNALOES
147 %token STRUCT VOID_TOK WHILE
148 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
149 %type <identifier> any_identifier
150 %type <interface_block> instance_name_opt
151 %token <real> FLOATCONSTANT
152 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
153 %token <identifier> FIELD_SELECTION
154 %token LEFT_OP RIGHT_OP
155 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
156 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
157 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
160 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
162 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
163 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
164 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
165 %token PRAGMA_INVARIANT_ALL
168 /* Reserved words that are not actually used in the grammar.
170 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
171 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
172 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
173 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
175 %token SIZEOF CAST NAMESPACE USING
176 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
181 %token COMMON PARTITION ACTIVE FILTER
182 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
183 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
184 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
185 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
186 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
189 %type <identifier> variable_identifier
190 %type <node> statement
191 %type <node> statement_list
192 %type <node> simple_statement
193 %type <n> precision_qualifier
194 %type <type_qualifier> type_qualifier
195 %type <type_qualifier> auxiliary_storage_qualifier
196 %type <type_qualifier> storage_qualifier
197 %type <type_qualifier> interpolation_qualifier
198 %type <type_qualifier> layout_qualifier
199 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
200 %type <type_qualifier> interface_block_layout_qualifier
201 %type <type_qualifier> interface_qualifier
202 %type <type_specifier> type_specifier
203 %type <type_specifier> type_specifier_nonarray
204 %type <identifier> basic_type_specifier_nonarray
205 %type <fully_specified_type> fully_specified_type
206 %type <function> function_prototype
207 %type <function> function_header
208 %type <function> function_header_with_parameters
209 %type <function> function_declarator
210 %type <parameter_declarator> parameter_declarator
211 %type <parameter_declarator> parameter_declaration
212 %type <type_qualifier> parameter_qualifier
213 %type <type_qualifier> parameter_direction_qualifier
214 %type <type_specifier> parameter_type_specifier
215 %type <function_definition> function_definition
216 %type <compound_statement> compound_statement_no_new_scope
217 %type <compound_statement> compound_statement
218 %type <node> statement_no_new_scope
219 %type <node> expression_statement
220 %type <expression> expression
221 %type <expression> primary_expression
222 %type <expression> assignment_expression
223 %type <expression> conditional_expression
224 %type <expression> logical_or_expression
225 %type <expression> logical_xor_expression
226 %type <expression> logical_and_expression
227 %type <expression> inclusive_or_expression
228 %type <expression> exclusive_or_expression
229 %type <expression> and_expression
230 %type <expression> equality_expression
231 %type <expression> relational_expression
232 %type <expression> shift_expression
233 %type <expression> additive_expression
234 %type <expression> multiplicative_expression
235 %type <expression> unary_expression
236 %type <expression> constant_expression
237 %type <expression> integer_expression
238 %type <expression> postfix_expression
239 %type <expression> function_call_header_with_parameters
240 %type <expression> function_call_header_no_parameters
241 %type <expression> function_call_header
242 %type <expression> function_call_generic
243 %type <expression> function_call_or_method
244 %type <expression> function_call
245 %type <expression> method_call_generic
246 %type <expression> method_call_header_with_parameters
247 %type <expression> method_call_header_no_parameters
248 %type <expression> method_call_header
249 %type <n> assignment_operator
250 %type <n> unary_operator
251 %type <expression> function_identifier
252 %type <node> external_declaration
253 %type <declarator_list> init_declarator_list
254 %type <declarator_list> single_declaration
255 %type <expression> initializer
256 %type <expression> initializer_list
257 %type <node> declaration
258 %type <node> declaration_statement
259 %type <node> jump_statement
260 %type <node> interface_block
261 %type <interface_block> basic_interface_block
262 %type <struct_specifier> struct_specifier
263 %type <declarator_list> struct_declaration_list
264 %type <declarator_list> struct_declaration
265 %type <declaration> struct_declarator
266 %type <declaration> struct_declarator_list
267 %type <declarator_list> member_list
268 %type <declarator_list> member_declaration
269 %type <node> selection_statement
270 %type <selection_rest_statement> selection_rest_statement
271 %type <node> switch_statement
272 %type <switch_body> switch_body
273 %type <case_label_list> case_label_list
274 %type <case_label> case_label
275 %type <case_statement> case_statement
276 %type <case_statement_list> case_statement_list
277 %type <node> iteration_statement
278 %type <node> condition
279 %type <node> conditionopt
280 %type <node> for_init_statement
281 %type <for_rest_statement> for_rest_statement
282 %type <n> integer_constant
283 %type <node> layout_defaults
289 version_statement extension_statement_list
291 _mesa_glsl_initialize_types(state);
293 external_declaration_list
295 delete state->symbols;
296 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
297 _mesa_glsl_initialize_types(state);
302 /* blank - no #version specified: defaults are already set */
303 | VERSION_TOK INTCONSTANT EOL
305 state->process_version_directive(&@2, $2, NULL);
310 | VERSION_TOK INTCONSTANT any_identifier EOL
312 state->process_version_directive(&@2, $2, $3);
321 | PRAGMA_DEBUG_OFF EOL
322 | PRAGMA_OPTIMIZE_ON EOL
323 | PRAGMA_OPTIMIZE_OFF EOL
324 | PRAGMA_INVARIANT_ALL EOL
326 if (!state->is_version(120, 100)) {
327 _mesa_glsl_warning(& @1, state,
328 "pragma `invariant(all)' not supported in %s "
329 "(GLSL ES 1.00 or GLSL 1.20 required)",
330 state->get_version_string());
332 state->all_invariant = true;
337 extension_statement_list:
339 | extension_statement_list extension_statement
349 EXTENSION any_identifier COLON any_identifier EOL
351 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
357 external_declaration_list:
360 /* FINISHME: The NULL test is required because pragmas are set to
361 * FINISHME: NULL. (See production rule for external_declaration.)
364 state->translation_unit.push_tail(& $1->link);
366 | external_declaration_list external_declaration
368 /* FINISHME: The NULL test is required because pragmas are set to
369 * FINISHME: NULL. (See production rule for external_declaration.)
372 state->translation_unit.push_tail(& $2->link);
385 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
386 $$->set_location(yylloc);
387 $$->primary_expression.identifier = $1;
392 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
393 $$->set_location(yylloc);
394 $$->primary_expression.int_constant = $1;
399 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
400 $$->set_location(yylloc);
401 $$->primary_expression.uint_constant = $1;
406 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
407 $$->set_location(yylloc);
408 $$->primary_expression.float_constant = $1;
413 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
414 $$->set_location(yylloc);
415 $$->primary_expression.bool_constant = $1;
425 | postfix_expression '[' integer_expression ']'
428 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
429 $$->set_location(yylloc);
435 | postfix_expression '.' any_identifier
438 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
439 $$->set_location(yylloc);
440 $$->primary_expression.identifier = $3;
442 | postfix_expression INC_OP
445 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
446 $$->set_location(yylloc);
448 | postfix_expression DEC_OP
451 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
452 $$->set_location(yylloc);
461 function_call_or_method
464 function_call_or_method:
465 function_call_generic
466 | postfix_expression '.' method_call_generic
469 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
470 $$->set_location(yylloc);
474 function_call_generic:
475 function_call_header_with_parameters ')'
476 | function_call_header_no_parameters ')'
479 function_call_header_no_parameters:
480 function_call_header VOID_TOK
481 | function_call_header
484 function_call_header_with_parameters:
485 function_call_header assignment_expression
488 $$->set_location(yylloc);
489 $$->expressions.push_tail(& $2->link);
491 | function_call_header_with_parameters ',' assignment_expression
494 $$->set_location(yylloc);
495 $$->expressions.push_tail(& $3->link);
499 // Grammar Note: Constructors look like functions, but lexical
500 // analysis recognized most of them as keywords. They are now
501 // recognized through "type_specifier".
502 function_call_header:
503 function_identifier '('
510 $$ = new(ctx) ast_function_expression($1);
511 $$->set_location(yylloc);
513 | variable_identifier
516 ast_expression *callee = new(ctx) ast_expression($1);
517 $$ = new(ctx) ast_function_expression(callee);
518 $$->set_location(yylloc);
523 ast_expression *callee = new(ctx) ast_expression($1);
524 $$ = new(ctx) ast_function_expression(callee);
525 $$->set_location(yylloc);
530 method_call_header_with_parameters ')'
531 | method_call_header_no_parameters ')'
534 method_call_header_no_parameters:
535 method_call_header VOID_TOK
539 method_call_header_with_parameters:
540 method_call_header assignment_expression
543 $$->set_location(yylloc);
544 $$->expressions.push_tail(& $2->link);
546 | method_call_header_with_parameters ',' assignment_expression
549 $$->set_location(yylloc);
550 $$->expressions.push_tail(& $3->link);
554 // Grammar Note: Constructors look like methods, but lexical
555 // analysis recognized most of them as keywords. They are now
556 // recognized through "type_specifier".
558 variable_identifier '('
561 ast_expression *callee = new(ctx) ast_expression($1);
562 $$ = new(ctx) ast_function_expression(callee);
563 $$->set_location(yylloc);
567 // Grammar Note: No traditional style type casts.
570 | INC_OP unary_expression
573 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
574 $$->set_location(yylloc);
576 | DEC_OP unary_expression
579 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
580 $$->set_location(yylloc);
582 | unary_operator unary_expression
585 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
586 $$->set_location(yylloc);
590 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
592 '+' { $$ = ast_plus; }
593 | '-' { $$ = ast_neg; }
594 | '!' { $$ = ast_logic_not; }
595 | '~' { $$ = ast_bit_not; }
598 multiplicative_expression:
600 | multiplicative_expression '*' unary_expression
603 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
604 $$->set_location(yylloc);
606 | multiplicative_expression '/' unary_expression
609 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
610 $$->set_location(yylloc);
612 | multiplicative_expression '%' unary_expression
615 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
616 $$->set_location(yylloc);
621 multiplicative_expression
622 | additive_expression '+' multiplicative_expression
625 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
626 $$->set_location(yylloc);
628 | additive_expression '-' multiplicative_expression
631 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
632 $$->set_location(yylloc);
638 | shift_expression LEFT_OP additive_expression
641 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
642 $$->set_location(yylloc);
644 | shift_expression RIGHT_OP additive_expression
647 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
648 $$->set_location(yylloc);
652 relational_expression:
654 | relational_expression '<' shift_expression
657 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
658 $$->set_location(yylloc);
660 | relational_expression '>' shift_expression
663 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
664 $$->set_location(yylloc);
666 | relational_expression LE_OP shift_expression
669 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
670 $$->set_location(yylloc);
672 | relational_expression GE_OP shift_expression
675 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
676 $$->set_location(yylloc);
681 relational_expression
682 | equality_expression EQ_OP relational_expression
685 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
686 $$->set_location(yylloc);
688 | equality_expression NE_OP relational_expression
691 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
692 $$->set_location(yylloc);
698 | and_expression '&' equality_expression
701 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
702 $$->set_location(yylloc);
706 exclusive_or_expression:
708 | exclusive_or_expression '^' and_expression
711 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
712 $$->set_location(yylloc);
716 inclusive_or_expression:
717 exclusive_or_expression
718 | inclusive_or_expression '|' exclusive_or_expression
721 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
722 $$->set_location(yylloc);
726 logical_and_expression:
727 inclusive_or_expression
728 | logical_and_expression AND_OP inclusive_or_expression
731 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
732 $$->set_location(yylloc);
736 logical_xor_expression:
737 logical_and_expression
738 | logical_xor_expression XOR_OP logical_and_expression
741 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
742 $$->set_location(yylloc);
746 logical_or_expression:
747 logical_xor_expression
748 | logical_or_expression OR_OP logical_xor_expression
751 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
752 $$->set_location(yylloc);
756 conditional_expression:
757 logical_or_expression
758 | logical_or_expression '?' expression ':' assignment_expression
761 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
762 $$->set_location(yylloc);
766 assignment_expression:
767 conditional_expression
768 | unary_expression assignment_operator assignment_expression
771 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
772 $$->set_location(yylloc);
777 '=' { $$ = ast_assign; }
778 | MUL_ASSIGN { $$ = ast_mul_assign; }
779 | DIV_ASSIGN { $$ = ast_div_assign; }
780 | MOD_ASSIGN { $$ = ast_mod_assign; }
781 | ADD_ASSIGN { $$ = ast_add_assign; }
782 | SUB_ASSIGN { $$ = ast_sub_assign; }
783 | LEFT_ASSIGN { $$ = ast_ls_assign; }
784 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
785 | AND_ASSIGN { $$ = ast_and_assign; }
786 | XOR_ASSIGN { $$ = ast_xor_assign; }
787 | OR_ASSIGN { $$ = ast_or_assign; }
791 assignment_expression
795 | expression ',' assignment_expression
798 if ($1->oper != ast_sequence) {
799 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
800 $$->set_location(yylloc);
801 $$->expressions.push_tail(& $1->link);
806 $$->expressions.push_tail(& $3->link);
811 conditional_expression
815 function_prototype ';'
817 state->symbols->pop_scope();
820 | init_declarator_list ';'
824 | PRECISION precision_qualifier type_specifier ';'
826 $3->default_precision = $2;
836 function_declarator ')'
841 | function_header_with_parameters
844 function_header_with_parameters:
845 function_header parameter_declaration
848 $$->parameters.push_tail(& $2->link);
850 | function_header_with_parameters ',' parameter_declaration
853 $$->parameters.push_tail(& $3->link);
858 fully_specified_type variable_identifier '('
861 $$ = new(ctx) ast_function();
862 $$->set_location(yylloc);
863 $$->return_type = $1;
866 state->symbols->add_function(new(state) ir_function($2));
867 state->symbols->push_scope();
871 parameter_declarator:
872 type_specifier any_identifier
875 $$ = new(ctx) ast_parameter_declarator();
876 $$->set_location(yylloc);
877 $$->type = new(ctx) ast_fully_specified_type();
878 $$->type->set_location(yylloc);
879 $$->type->specifier = $1;
882 | type_specifier any_identifier '[' constant_expression ']'
885 $$ = new(ctx) ast_parameter_declarator();
886 $$->set_location(yylloc);
887 $$->type = new(ctx) ast_fully_specified_type();
888 $$->type->set_location(yylloc);
889 $$->type->specifier = $1;
896 parameter_declaration:
897 parameter_qualifier parameter_declarator
900 $$->type->qualifier = $1;
902 | parameter_qualifier parameter_type_specifier
905 $$ = new(ctx) ast_parameter_declarator();
906 $$->set_location(yylloc);
907 $$->type = new(ctx) ast_fully_specified_type();
908 $$->type->qualifier = $1;
909 $$->type->specifier = $2;
916 memset(& $$, 0, sizeof($$));
918 | CONST_TOK parameter_qualifier
920 if ($2.flags.q.constant)
921 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
924 $$.flags.q.constant = 1;
926 | parameter_direction_qualifier parameter_qualifier
928 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
929 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
931 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
932 _mesa_glsl_error(&@1, state, "const must be specified before "
936 $$.merge_qualifier(&@1, state, $2);
938 | precision_qualifier parameter_qualifier
940 if ($2.precision != ast_precision_none)
941 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
943 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
944 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
950 parameter_direction_qualifier:
953 memset(& $$, 0, sizeof($$));
958 memset(& $$, 0, sizeof($$));
963 memset(& $$, 0, sizeof($$));
969 parameter_type_specifier:
973 init_declarator_list:
975 | init_declarator_list ',' any_identifier
978 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
979 decl->set_location(yylloc);
982 $$->declarations.push_tail(&decl->link);
983 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
985 | init_declarator_list ',' any_identifier '[' ']'
988 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
989 decl->set_location(yylloc);
992 $$->declarations.push_tail(&decl->link);
993 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
995 | init_declarator_list ',' any_identifier '[' constant_expression ']'
998 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
999 decl->set_location(yylloc);
1002 $$->declarations.push_tail(&decl->link);
1003 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1005 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
1008 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
1009 decl->set_location(yylloc);
1012 $$->declarations.push_tail(&decl->link);
1013 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1014 if ($7->oper == ast_aggregate) {
1015 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1016 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
1017 _mesa_ast_set_aggregate_type(type, ai, state);
1020 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
1023 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
1024 decl->set_location(yylloc);
1027 $$->declarations.push_tail(&decl->link);
1028 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1029 if ($8->oper == ast_aggregate) {
1030 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
1031 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
1032 _mesa_ast_set_aggregate_type(type, ai, state);
1035 | init_declarator_list ',' any_identifier '=' initializer
1038 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1039 decl->set_location(yylloc);
1042 $$->declarations.push_tail(&decl->link);
1043 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1044 if ($5->oper == ast_aggregate) {
1045 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
1046 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1051 // Grammar Note: No 'enum', or 'typedef'.
1053 fully_specified_type
1056 /* Empty declaration list is valid. */
1057 $$ = new(ctx) ast_declarator_list($1);
1058 $$->set_location(yylloc);
1060 | fully_specified_type any_identifier
1063 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1065 $$ = new(ctx) ast_declarator_list($1);
1066 $$->set_location(yylloc);
1067 $$->declarations.push_tail(&decl->link);
1069 | fully_specified_type any_identifier '[' ']'
1072 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1074 $$ = new(ctx) ast_declarator_list($1);
1075 $$->set_location(yylloc);
1076 $$->declarations.push_tail(&decl->link);
1078 | fully_specified_type any_identifier '[' constant_expression ']'
1081 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1083 $$ = new(ctx) ast_declarator_list($1);
1084 $$->set_location(yylloc);
1085 $$->declarations.push_tail(&decl->link);
1087 | fully_specified_type any_identifier '[' ']' '=' initializer
1090 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1092 $$ = new(ctx) ast_declarator_list($1);
1093 $$->set_location(yylloc);
1094 $$->declarations.push_tail(&decl->link);
1095 if ($6->oper == ast_aggregate) {
1096 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1097 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1098 _mesa_ast_set_aggregate_type(type, ai, state);
1101 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1104 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1106 $$ = new(ctx) ast_declarator_list($1);
1107 $$->set_location(yylloc);
1108 $$->declarations.push_tail(&decl->link);
1109 if ($7->oper == ast_aggregate) {
1110 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1111 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1112 _mesa_ast_set_aggregate_type(type, ai, state);
1115 | fully_specified_type any_identifier '=' initializer
1118 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1120 $$ = new(ctx) ast_declarator_list($1);
1121 $$->set_location(yylloc);
1122 $$->declarations.push_tail(&decl->link);
1123 if ($4->oper == ast_aggregate) {
1124 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1127 | INVARIANT variable_identifier // Vertex only.
1130 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1132 $$ = new(ctx) ast_declarator_list(NULL);
1133 $$->set_location(yylloc);
1134 $$->invariant = true;
1136 $$->declarations.push_tail(&decl->link);
1140 fully_specified_type:
1144 $$ = new(ctx) ast_fully_specified_type();
1145 $$->set_location(yylloc);
1148 | type_qualifier type_specifier
1151 $$ = new(ctx) ast_fully_specified_type();
1152 $$->set_location(yylloc);
1159 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1165 layout_qualifier_id_list:
1167 | layout_qualifier_id_list ',' layout_qualifier_id
1170 if (!$$.merge_qualifier(& @3, state, $3)) {
1177 INTCONSTANT { $$ = $1; }
1178 | UINTCONSTANT { $$ = $1; }
1181 layout_qualifier_id:
1184 memset(& $$, 0, sizeof($$));
1186 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1187 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1188 state->is_version(150, 0))) {
1189 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1190 $$.flags.q.origin_upper_left = 1;
1191 } else if (match_layout_qualifier($1, "pixel_center_integer",
1193 $$.flags.q.pixel_center_integer = 1;
1196 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1197 _mesa_glsl_warning(& @1, state,
1198 "GL_ARB_fragment_coord_conventions layout "
1199 "identifier `%s' used", $1);
1203 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1205 (state->AMD_conservative_depth_enable ||
1206 state->ARB_conservative_depth_enable)) {
1207 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1208 $$.flags.q.depth_any = 1;
1209 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1210 $$.flags.q.depth_greater = 1;
1211 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1212 $$.flags.q.depth_less = 1;
1213 } else if (match_layout_qualifier($1, "depth_unchanged",
1215 $$.flags.q.depth_unchanged = 1;
1218 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1219 _mesa_glsl_warning(& @1, state,
1220 "GL_AMD_conservative_depth "
1221 "layout qualifier `%s' is used", $1);
1223 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1224 _mesa_glsl_warning(& @1, state,
1225 "GL_ARB_conservative_depth "
1226 "layout qualifier `%s' is used", $1);
1230 /* See also interface_block_layout_qualifier. */
1231 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1232 if (match_layout_qualifier($1, "std140", state) == 0) {
1233 $$.flags.q.std140 = 1;
1234 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1235 $$.flags.q.shared = 1;
1236 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1237 $$.flags.q.column_major = 1;
1238 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1239 * below in the interface_block_layout_qualifier rule.
1241 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1244 * Also, this takes care of alternate capitalizations of
1245 * "row_major" (which is necessary because layout qualifiers
1246 * are case-insensitive in desktop GLSL).
1248 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1249 $$.flags.q.row_major = 1;
1250 /* "packed" is a reserved word in GLSL, and its token is
1251 * parsed below in the interface_block_layout_qualifier rule.
1252 * However, we must take care of alternate capitalizations of
1253 * "packed", because layout qualifiers are case-insensitive
1256 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1257 $$.flags.q.packed = 1;
1260 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1261 _mesa_glsl_warning(& @1, state,
1262 "#version 140 / GL_ARB_uniform_buffer_object "
1263 "layout qualifier `%s' is used", $1);
1267 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1273 { "points", GL_POINTS },
1274 { "lines", GL_LINES },
1275 { "lines_adjacency", GL_LINES_ADJACENCY },
1276 { "line_strip", GL_LINE_STRIP },
1277 { "triangles", GL_TRIANGLES },
1278 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1279 { "triangle_strip", GL_TRIANGLE_STRIP },
1281 for (unsigned i = 0; i < Elements(map); i++) {
1282 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1283 $$.flags.q.prim_type = 1;
1284 $$.prim_type = map[i].e;
1289 if ($$.flags.i && !state->is_version(150, 0)) {
1290 _mesa_glsl_error(& @1, state, "#version 150 layout "
1291 "qualifier `%s' used", $1);
1296 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1301 | any_identifier '=' integer_constant
1303 memset(& $$, 0, sizeof($$));
1305 if (state->has_explicit_attrib_location()) {
1306 if (match_layout_qualifier("location", $1, state) == 0) {
1307 $$.flags.q.explicit_location = 1;
1312 _mesa_glsl_error(& @3, state,
1313 "invalid location %d specified", $3);
1318 if (match_layout_qualifier("index", $1, state) == 0) {
1319 $$.flags.q.explicit_index = 1;
1324 _mesa_glsl_error(& @3, state,
1325 "invalid index %d specified", $3);
1331 if (state->ARB_shading_language_420pack_enable &&
1332 match_layout_qualifier("binding", $1, state) == 0) {
1333 $$.flags.q.explicit_binding = 1;
1337 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1338 $$.flags.q.max_vertices = 1;
1341 _mesa_glsl_error(& @3, state,
1342 "invalid max_vertices %d specified", $3);
1345 $$.max_vertices = $3;
1346 if (!state->is_version(150, 0)) {
1347 _mesa_glsl_error(& @3, state,
1348 "#version 150 max_vertices qualifier "
1354 /* If the identifier didn't match any known layout identifiers,
1358 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1361 } else if (state->ARB_explicit_attrib_location_warn) {
1362 _mesa_glsl_warning(& @1, state,
1363 "GL_ARB_explicit_attrib_location layout "
1364 "identifier `%s' used", $1);
1367 | interface_block_layout_qualifier
1370 /* Layout qualifiers for ARB_uniform_buffer_object. */
1371 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1372 _mesa_glsl_error(& @1, state,
1373 "#version 140 / GL_ARB_uniform_buffer_object "
1374 "layout qualifier `%s' is used", $1);
1375 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1376 _mesa_glsl_warning(& @1, state,
1377 "#version 140 / GL_ARB_uniform_buffer_object "
1378 "layout qualifier `%s' is used", $1);
1383 /* This is a separate language rule because we parse these as tokens
1384 * (due to them being reserved keywords) instead of identifiers like
1385 * most qualifiers. See the any_identifier path of
1386 * layout_qualifier_id for the others.
1388 * Note that since layout qualifiers are case-insensitive in desktop
1389 * GLSL, all of these qualifiers need to be handled as identifiers as
1390 * well (by the any_identifier path of layout_qualifier_id).
1392 interface_block_layout_qualifier:
1395 memset(& $$, 0, sizeof($$));
1396 $$.flags.q.row_major = 1;
1400 memset(& $$, 0, sizeof($$));
1401 $$.flags.q.packed = 1;
1405 interpolation_qualifier:
1408 memset(& $$, 0, sizeof($$));
1409 $$.flags.q.smooth = 1;
1413 memset(& $$, 0, sizeof($$));
1414 $$.flags.q.flat = 1;
1418 memset(& $$, 0, sizeof($$));
1419 $$.flags.q.noperspective = 1;
1424 /* Single qualifiers */
1427 memset(& $$, 0, sizeof($$));
1428 $$.flags.q.invariant = 1;
1430 | auxiliary_storage_qualifier
1432 | interpolation_qualifier
1434 | precision_qualifier
1436 memset(&$$, 0, sizeof($$));
1440 /* Multiple qualifiers:
1441 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1442 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1444 * invariant interpolation auxiliary storage precision ...or...
1445 * layout storage precision
1447 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1448 * side don't contain any that must appear on the left hand side.
1449 * For example, when processing a storage qualifier, we check that there are
1450 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1452 | INVARIANT type_qualifier
1454 if ($2.flags.q.invariant)
1455 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1457 if ($2.has_layout()) {
1458 _mesa_glsl_error(&@1, state,
1459 "\"invariant\" cannot be used with layout(...)");
1463 $$.flags.q.invariant = 1;
1465 | interpolation_qualifier type_qualifier
1467 /* Section 4.3 of the GLSL 1.40 specification states:
1468 * "...qualified with one of these interpolation qualifiers"
1470 * GLSL 1.30 claims to allow "one or more", but insists that:
1471 * "These interpolation qualifiers may only precede the qualifiers in,
1472 * centroid in, out, or centroid out in a declaration."
1474 * ...which means that e.g. smooth can't precede smooth, so there can be
1475 * only one after all, and the 1.40 text is a clarification, not a change.
1477 if ($2.has_interpolation())
1478 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1480 if ($2.has_layout()) {
1481 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1482 "with layout(...)");
1485 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1486 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1487 "after \"invariant\"");
1491 $$.merge_qualifier(&@1, state, $2);
1493 | layout_qualifier type_qualifier
1495 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1496 * used standalone or immediately before a storage qualifier. It cannot
1497 * be used with interpolation qualifiers or invariant. There does not
1498 * appear to be any text indicating that it must come before the storage
1499 * qualifier, but always seems to in examples.
1501 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1502 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1504 if ($2.flags.q.invariant)
1505 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1506 "the \"invariant\" qualifier");
1508 if ($2.has_interpolation()) {
1509 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1510 "interpolation qualifiers");
1514 $$.merge_qualifier(&@1, state, $2);
1516 | auxiliary_storage_qualifier type_qualifier
1518 if ($2.has_auxiliary_storage()) {
1519 _mesa_glsl_error(&@1, state,
1520 "duplicate auxiliary storage qualifier (centroid)");
1523 if (!state->ARB_shading_language_420pack_enable &&
1524 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1525 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1526 "just before storage qualifiers");
1529 $$.flags.i |= $2.flags.i;
1531 | storage_qualifier type_qualifier
1533 /* Section 4.3 of the GLSL 1.20 specification states:
1534 * "Variable declarations may have a storage qualifier specified..."
1535 * 1.30 clarifies this to "may have one storage qualifier".
1537 if ($2.has_storage())
1538 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1540 if (!state->ARB_shading_language_420pack_enable &&
1541 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1542 $2.has_auxiliary_storage())) {
1543 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1544 "invariant, interpolation, layout and auxiliary "
1545 "storage qualifiers");
1549 $$.merge_qualifier(&@1, state, $2);
1551 | precision_qualifier type_qualifier
1553 if ($2.precision != ast_precision_none)
1554 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1556 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1557 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1564 auxiliary_storage_qualifier:
1567 memset(& $$, 0, sizeof($$));
1568 $$.flags.q.centroid = 1;
1570 /* TODO: "sample" and "patch" also go here someday. */
1575 memset(& $$, 0, sizeof($$));
1576 $$.flags.q.constant = 1;
1580 memset(& $$, 0, sizeof($$));
1581 $$.flags.q.attribute = 1;
1585 memset(& $$, 0, sizeof($$));
1586 $$.flags.q.varying = 1;
1590 memset(& $$, 0, sizeof($$));
1595 memset(& $$, 0, sizeof($$));
1600 memset(& $$, 0, sizeof($$));
1601 $$.flags.q.uniform = 1;
1606 type_specifier_nonarray
1607 | type_specifier_nonarray '[' ']'
1610 $$->is_array = true;
1611 $$->array_size = NULL;
1613 | type_specifier_nonarray '[' constant_expression ']'
1616 $$->is_array = true;
1617 $$->array_size = $3;
1621 type_specifier_nonarray:
1622 basic_type_specifier_nonarray
1625 $$ = new(ctx) ast_type_specifier($1);
1626 $$->set_location(yylloc);
1631 $$ = new(ctx) ast_type_specifier($1);
1632 $$->set_location(yylloc);
1637 $$ = new(ctx) ast_type_specifier($1);
1638 $$->set_location(yylloc);
1642 basic_type_specifier_nonarray:
1643 VOID_TOK { $$ = "void"; }
1644 | FLOAT_TOK { $$ = "float"; }
1645 | INT_TOK { $$ = "int"; }
1646 | UINT_TOK { $$ = "uint"; }
1647 | BOOL_TOK { $$ = "bool"; }
1648 | VEC2 { $$ = "vec2"; }
1649 | VEC3 { $$ = "vec3"; }
1650 | VEC4 { $$ = "vec4"; }
1651 | BVEC2 { $$ = "bvec2"; }
1652 | BVEC3 { $$ = "bvec3"; }
1653 | BVEC4 { $$ = "bvec4"; }
1654 | IVEC2 { $$ = "ivec2"; }
1655 | IVEC3 { $$ = "ivec3"; }
1656 | IVEC4 { $$ = "ivec4"; }
1657 | UVEC2 { $$ = "uvec2"; }
1658 | UVEC3 { $$ = "uvec3"; }
1659 | UVEC4 { $$ = "uvec4"; }
1660 | MAT2X2 { $$ = "mat2"; }
1661 | MAT2X3 { $$ = "mat2x3"; }
1662 | MAT2X4 { $$ = "mat2x4"; }
1663 | MAT3X2 { $$ = "mat3x2"; }
1664 | MAT3X3 { $$ = "mat3"; }
1665 | MAT3X4 { $$ = "mat3x4"; }
1666 | MAT4X2 { $$ = "mat4x2"; }
1667 | MAT4X3 { $$ = "mat4x3"; }
1668 | MAT4X4 { $$ = "mat4"; }
1669 | SAMPLER1D { $$ = "sampler1D"; }
1670 | SAMPLER2D { $$ = "sampler2D"; }
1671 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1672 | SAMPLER3D { $$ = "sampler3D"; }
1673 | SAMPLERCUBE { $$ = "samplerCube"; }
1674 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1675 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1676 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1677 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1678 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1679 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1680 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1681 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1682 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1683 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1684 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1685 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1686 | ISAMPLER1D { $$ = "isampler1D"; }
1687 | ISAMPLER2D { $$ = "isampler2D"; }
1688 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1689 | ISAMPLER3D { $$ = "isampler3D"; }
1690 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1691 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1692 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1693 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1694 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1695 | USAMPLER1D { $$ = "usampler1D"; }
1696 | USAMPLER2D { $$ = "usampler2D"; }
1697 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1698 | USAMPLER3D { $$ = "usampler3D"; }
1699 | USAMPLERCUBE { $$ = "usamplerCube"; }
1700 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1701 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1702 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1703 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1704 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1705 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1706 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1707 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1708 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1709 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1712 precision_qualifier:
1715 state->check_precision_qualifiers_allowed(&@1);
1716 $$ = ast_precision_high;
1720 state->check_precision_qualifiers_allowed(&@1);
1721 $$ = ast_precision_medium;
1725 state->check_precision_qualifiers_allowed(&@1);
1726 $$ = ast_precision_low;
1731 STRUCT any_identifier '{' struct_declaration_list '}'
1734 $$ = new(ctx) ast_struct_specifier($2, $4);
1735 $$->set_location(yylloc);
1736 state->symbols->add_type($2, glsl_type::void_type);
1737 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1739 | STRUCT '{' struct_declaration_list '}'
1742 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1743 $$->set_location(yylloc);
1747 struct_declaration_list:
1751 $1->link.self_link();
1753 | struct_declaration_list struct_declaration
1756 $$->link.insert_before(& $2->link);
1761 fully_specified_type struct_declarator_list ';'
1764 ast_fully_specified_type *const type = $1;
1765 type->set_location(yylloc);
1767 if (type->qualifier.flags.i != 0)
1768 _mesa_glsl_error(&@1, state,
1769 "only precision qualifiers may be applied to "
1770 "structure members");
1772 $$ = new(ctx) ast_declarator_list(type);
1773 $$->set_location(yylloc);
1775 $$->declarations.push_degenerate_list_at_head(& $2->link);
1779 struct_declarator_list:
1783 $1->link.self_link();
1785 | struct_declarator_list ',' struct_declarator
1788 $$->link.insert_before(& $3->link);
1796 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1797 $$->set_location(yylloc);
1799 | any_identifier '[' ']'
1802 $$ = new(ctx) ast_declaration($1, true, NULL, NULL);
1803 $$->set_location(yylloc);
1805 | any_identifier '[' constant_expression ']'
1808 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1809 $$->set_location(yylloc);
1814 assignment_expression
1815 | '{' initializer_list '}'
1819 | '{' initializer_list ',' '}'
1829 $$ = new(ctx) ast_aggregate_initializer();
1830 $$->set_location(yylloc);
1831 $$->expressions.push_tail(& $1->link);
1833 | initializer_list ',' initializer
1835 $1->expressions.push_tail(& $3->link);
1839 declaration_statement:
1843 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1846 compound_statement { $$ = (ast_node *) $1; }
1851 declaration_statement
1852 | expression_statement
1853 | selection_statement
1855 | iteration_statement
1863 $$ = new(ctx) ast_compound_statement(true, NULL);
1864 $$->set_location(yylloc);
1868 state->symbols->push_scope();
1873 $$ = new(ctx) ast_compound_statement(true, $3);
1874 $$->set_location(yylloc);
1875 state->symbols->pop_scope();
1879 statement_no_new_scope:
1880 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1884 compound_statement_no_new_scope:
1888 $$ = new(ctx) ast_compound_statement(false, NULL);
1889 $$->set_location(yylloc);
1891 | '{' statement_list '}'
1894 $$ = new(ctx) ast_compound_statement(false, $2);
1895 $$->set_location(yylloc);
1903 _mesa_glsl_error(& @1, state, "<nil> statement");
1908 $$->link.self_link();
1910 | statement_list statement
1913 _mesa_glsl_error(& @2, state, "<nil> statement");
1917 $$->link.insert_before(& $2->link);
1921 expression_statement:
1925 $$ = new(ctx) ast_expression_statement(NULL);
1926 $$->set_location(yylloc);
1931 $$ = new(ctx) ast_expression_statement($1);
1932 $$->set_location(yylloc);
1936 selection_statement:
1937 IF '(' expression ')' selection_rest_statement
1939 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1941 $$->set_location(yylloc);
1945 selection_rest_statement:
1946 statement ELSE statement
1948 $$.then_statement = $1;
1949 $$.else_statement = $3;
1951 | statement %prec THEN
1953 $$.then_statement = $1;
1954 $$.else_statement = NULL;
1961 $$ = (ast_node *) $1;
1963 | fully_specified_type any_identifier '=' initializer
1966 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1967 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1968 decl->set_location(yylloc);
1969 declarator->set_location(yylloc);
1971 declarator->declarations.push_tail(&decl->link);
1977 * siwtch_statement grammar is based on the syntax described in the body
1978 * of the GLSL spec, not in it's appendix!!!
1981 SWITCH '(' expression ')' switch_body
1983 $$ = new(state) ast_switch_statement($3, $5);
1984 $$->set_location(yylloc);
1991 $$ = new(state) ast_switch_body(NULL);
1992 $$->set_location(yylloc);
1994 | '{' case_statement_list '}'
1996 $$ = new(state) ast_switch_body($2);
1997 $$->set_location(yylloc);
2004 $$ = new(state) ast_case_label($2);
2005 $$->set_location(yylloc);
2009 $$ = new(state) ast_case_label(NULL);
2010 $$->set_location(yylloc);
2017 ast_case_label_list *labels = new(state) ast_case_label_list();
2019 labels->labels.push_tail(& $1->link);
2021 $$->set_location(yylloc);
2023 | case_label_list case_label
2026 $$->labels.push_tail(& $2->link);
2031 case_label_list statement
2033 ast_case_statement *stmts = new(state) ast_case_statement($1);
2034 stmts->set_location(yylloc);
2036 stmts->stmts.push_tail(& $2->link);
2039 | case_statement statement
2042 $$->stmts.push_tail(& $2->link);
2046 case_statement_list:
2049 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2050 cases->set_location(yylloc);
2052 cases->cases.push_tail(& $1->link);
2055 | case_statement_list case_statement
2058 $$->cases.push_tail(& $2->link);
2062 iteration_statement:
2063 WHILE '(' condition ')' statement_no_new_scope
2066 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2067 NULL, $3, NULL, $5);
2068 $$->set_location(yylloc);
2070 | DO statement WHILE '(' expression ')' ';'
2073 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2074 NULL, $5, NULL, $2);
2075 $$->set_location(yylloc);
2077 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2080 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2081 $3, $4.cond, $4.rest, $6);
2082 $$->set_location(yylloc);
2087 expression_statement
2088 | declaration_statement
2105 | conditionopt ';' expression
2112 // Grammar Note: No 'goto'. Gotos are not supported.
2117 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2118 $$->set_location(yylloc);
2123 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2124 $$->set_location(yylloc);
2129 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2130 $$->set_location(yylloc);
2132 | RETURN expression ';'
2135 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2136 $$->set_location(yylloc);
2138 | DISCARD ';' // Fragment shader only.
2141 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2142 $$->set_location(yylloc);
2146 external_declaration:
2147 function_definition { $$ = $1; }
2148 | declaration { $$ = $1; }
2149 | pragma_statement { $$ = NULL; }
2150 | layout_defaults { $$ = $1; }
2153 function_definition:
2154 function_prototype compound_statement_no_new_scope
2157 $$ = new(ctx) ast_function_definition();
2158 $$->set_location(yylloc);
2162 state->symbols->pop_scope();
2166 /* layout_qualifieropt is packed into this rule */
2168 basic_interface_block
2172 | layout_qualifier basic_interface_block
2174 ast_interface_block *block = $2;
2175 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2182 basic_interface_block:
2183 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2185 ast_interface_block *const block = $6;
2187 block->block_name = $2;
2188 block->declarations.push_degenerate_list_at_head(& $4->link);
2190 if ($1.flags.q.uniform) {
2191 if (!state->has_uniform_buffer_objects()) {
2192 _mesa_glsl_error(& @1, state,
2193 "#version 140 / GL_ARB_uniform_buffer_object "
2194 "required for defining uniform blocks");
2195 } else if (state->ARB_uniform_buffer_object_warn) {
2196 _mesa_glsl_warning(& @1, state,
2197 "#version 140 / GL_ARB_uniform_buffer_object "
2198 "required for defining uniform blocks");
2201 if (state->es_shader || state->language_version < 150) {
2202 _mesa_glsl_error(& @1, state,
2203 "#version 150 required for using "
2204 "interface blocks");
2208 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2209 * "It is illegal to have an input block in a vertex shader
2210 * or an output block in a fragment shader"
2212 if ((state->target == vertex_shader) && $1.flags.q.in) {
2213 _mesa_glsl_error(& @1, state,
2214 "`in' interface block is not allowed for "
2216 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2217 _mesa_glsl_error(& @1, state,
2218 "`out' interface block is not allowed for "
2219 "a fragment shader");
2222 /* Since block arrays require names, and both features are added in
2223 * the same language versions, we don't have to explicitly
2224 * version-check both things.
2226 if (block->instance_name != NULL) {
2227 state->check_version(150, 300, & @1, "interface blocks with "
2228 "an instance name are not allowed");
2231 unsigned interface_type_mask;
2232 struct ast_type_qualifier temp_type_qualifier;
2234 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2235 * to ignore other irrelevant flags like interpolation qualifiers.
2237 temp_type_qualifier.flags.i = 0;
2238 temp_type_qualifier.flags.q.uniform = true;
2239 temp_type_qualifier.flags.q.in = true;
2240 temp_type_qualifier.flags.q.out = true;
2241 interface_type_mask = temp_type_qualifier.flags.i;
2243 /* Get the block's interface qualifier. The interface_qualifier
2244 * production rule guarantees that only one bit will be set (and
2245 * it will be in/out/uniform).
2247 unsigned block_interface_qualifier = $1.flags.i;
2249 block->layout.flags.i |= block_interface_qualifier;
2251 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2252 ast_type_qualifier& qualifier = member->type->qualifier;
2253 if ((qualifier.flags.i & interface_type_mask) == 0) {
2254 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2255 * "If no optional qualifier is used in a member declaration, the
2256 * qualifier of the variable is just in, out, or uniform as declared
2257 * by interface-qualifier."
2259 qualifier.flags.i |= block_interface_qualifier;
2260 } else if ((qualifier.flags.i & interface_type_mask) !=
2261 block_interface_qualifier) {
2262 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2263 * "If optional qualifiers are used, they can include interpolation
2264 * and storage qualifiers and they must declare an input, output,
2265 * or uniform variable consistent with the interface qualifier of
2268 _mesa_glsl_error(& @1, state,
2269 "uniform/in/out qualifier on "
2270 "interface block member does not match "
2271 "the interface block");
2279 interface_qualifier:
2282 memset(& $$, 0, sizeof($$));
2287 memset(& $$, 0, sizeof($$));
2292 memset(& $$, 0, sizeof($$));
2293 $$.flags.q.uniform = 1;
2300 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2305 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2308 | NEW_IDENTIFIER '[' constant_expression ']'
2310 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2313 | NEW_IDENTIFIER '[' ']'
2315 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2324 $1->link.self_link();
2326 | member_declaration member_list
2329 $2->link.insert_before(& $$->link);
2334 fully_specified_type struct_declarator_list ';'
2337 ast_fully_specified_type *type = $1;
2338 type->set_location(yylloc);
2340 if (type->qualifier.flags.q.attribute) {
2341 _mesa_glsl_error(& @1, state,
2342 "keyword 'attribute' cannot be used with "
2343 "interface block member");
2344 } else if (type->qualifier.flags.q.varying) {
2345 _mesa_glsl_error(& @1, state,
2346 "keyword 'varying' cannot be used with "
2347 "interface block member");
2350 $$ = new(ctx) ast_declarator_list(type);
2351 $$->set_location(yylloc);
2353 $$->declarations.push_degenerate_list_at_head(& $2->link);
2358 layout_qualifier UNIFORM ';'
2360 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2366 | layout_qualifier IN_TOK ';'
2369 if (state->target != geometry_shader) {
2370 _mesa_glsl_error(& @1, state,
2371 "input layout qualifiers only valid in "
2372 "geometry shaders");
2373 } else if (!$1.flags.q.prim_type) {
2374 _mesa_glsl_error(& @1, state,
2375 "input layout qualifiers must specify a primitive"
2378 $$ = new(ctx) ast_gs_input_layout(@1, $1.prim_type);
2381 | layout_qualifier OUT_TOK ';'
2383 if (state->target != geometry_shader) {
2384 _mesa_glsl_error(& @1, state,
2385 "out layout qualifiers only valid in "
2386 "geometry shaders");
2387 } else if (!state->out_qualifier->merge_qualifier(& @1, state, $1)) {