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_array_specifier *array_specifier;
101 ast_fully_specified_type *fully_specified_type;
102 ast_function *function;
103 ast_parameter_declarator *parameter_declarator;
104 ast_function_definition *function_definition;
105 ast_compound_statement *compound_statement;
106 ast_expression *expression;
107 ast_declarator_list *declarator_list;
108 ast_struct_specifier *struct_specifier;
109 ast_declaration *declaration;
110 ast_switch_body *switch_body;
111 ast_case_label *case_label;
112 ast_case_label_list *case_label_list;
113 ast_case_statement *case_statement;
114 ast_case_statement_list *case_statement_list;
115 ast_interface_block *interface_block;
119 ast_expression *rest;
120 } for_rest_statement;
123 ast_node *then_statement;
124 ast_node *else_statement;
125 } selection_rest_statement;
128 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
129 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
130 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
131 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
132 %token NOPERSPECTIVE FLAT SMOOTH
133 %token MAT2X2 MAT2X3 MAT2X4
134 %token MAT3X2 MAT3X3 MAT3X4
135 %token MAT4X2 MAT4X3 MAT4X4
136 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
137 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
138 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
139 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
140 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
141 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
142 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
143 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
144 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
145 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
146 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
147 %token SAMPLEREXTERNALOES
148 %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
149 %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
150 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
151 %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
152 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
153 %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
154 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
155 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
157 %token STRUCT VOID_TOK WHILE
158 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
159 %type <identifier> any_identifier
160 %type <interface_block> instance_name_opt
161 %token <real> FLOATCONSTANT
162 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
163 %token <identifier> FIELD_SELECTION
164 %token LEFT_OP RIGHT_OP
165 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
166 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
167 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
170 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
172 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
173 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
174 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
175 %token PRAGMA_INVARIANT_ALL
178 /* Reserved words that are not actually used in the grammar.
180 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
181 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
182 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
183 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
185 %token SIZEOF CAST NAMESPACE USING
186 %token RESOURCE PATCH SAMPLE
191 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
193 %type <identifier> variable_identifier
194 %type <node> statement
195 %type <node> statement_list
196 %type <node> simple_statement
197 %type <n> precision_qualifier
198 %type <type_qualifier> type_qualifier
199 %type <type_qualifier> auxiliary_storage_qualifier
200 %type <type_qualifier> storage_qualifier
201 %type <type_qualifier> interpolation_qualifier
202 %type <type_qualifier> layout_qualifier
203 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
204 %type <type_qualifier> interface_block_layout_qualifier
205 %type <type_qualifier> interface_qualifier
206 %type <type_specifier> type_specifier
207 %type <type_specifier> type_specifier_nonarray
208 %type <array_specifier> array_specifier
209 %type <identifier> basic_type_specifier_nonarray
210 %type <fully_specified_type> fully_specified_type
211 %type <function> function_prototype
212 %type <function> function_header
213 %type <function> function_header_with_parameters
214 %type <function> function_declarator
215 %type <parameter_declarator> parameter_declarator
216 %type <parameter_declarator> parameter_declaration
217 %type <type_qualifier> parameter_qualifier
218 %type <type_qualifier> parameter_direction_qualifier
219 %type <type_specifier> parameter_type_specifier
220 %type <function_definition> function_definition
221 %type <compound_statement> compound_statement_no_new_scope
222 %type <compound_statement> compound_statement
223 %type <node> statement_no_new_scope
224 %type <node> expression_statement
225 %type <expression> expression
226 %type <expression> primary_expression
227 %type <expression> assignment_expression
228 %type <expression> conditional_expression
229 %type <expression> logical_or_expression
230 %type <expression> logical_xor_expression
231 %type <expression> logical_and_expression
232 %type <expression> inclusive_or_expression
233 %type <expression> exclusive_or_expression
234 %type <expression> and_expression
235 %type <expression> equality_expression
236 %type <expression> relational_expression
237 %type <expression> shift_expression
238 %type <expression> additive_expression
239 %type <expression> multiplicative_expression
240 %type <expression> unary_expression
241 %type <expression> constant_expression
242 %type <expression> integer_expression
243 %type <expression> postfix_expression
244 %type <expression> function_call_header_with_parameters
245 %type <expression> function_call_header_no_parameters
246 %type <expression> function_call_header
247 %type <expression> function_call_generic
248 %type <expression> function_call_or_method
249 %type <expression> function_call
250 %type <expression> method_call_generic
251 %type <expression> method_call_header_with_parameters
252 %type <expression> method_call_header_no_parameters
253 %type <expression> method_call_header
254 %type <n> assignment_operator
255 %type <n> unary_operator
256 %type <expression> function_identifier
257 %type <node> external_declaration
258 %type <declarator_list> init_declarator_list
259 %type <declarator_list> single_declaration
260 %type <expression> initializer
261 %type <expression> initializer_list
262 %type <node> declaration
263 %type <node> declaration_statement
264 %type <node> jump_statement
265 %type <node> interface_block
266 %type <interface_block> basic_interface_block
267 %type <struct_specifier> struct_specifier
268 %type <declarator_list> struct_declaration_list
269 %type <declarator_list> struct_declaration
270 %type <declaration> struct_declarator
271 %type <declaration> struct_declarator_list
272 %type <declarator_list> member_list
273 %type <declarator_list> member_declaration
274 %type <node> selection_statement
275 %type <selection_rest_statement> selection_rest_statement
276 %type <node> switch_statement
277 %type <switch_body> switch_body
278 %type <case_label_list> case_label_list
279 %type <case_label> case_label
280 %type <case_statement> case_statement
281 %type <case_statement_list> case_statement_list
282 %type <node> iteration_statement
283 %type <node> condition
284 %type <node> conditionopt
285 %type <node> for_init_statement
286 %type <for_rest_statement> for_rest_statement
287 %type <n> integer_constant
288 %type <node> layout_defaults
294 version_statement extension_statement_list
296 _mesa_glsl_initialize_types(state);
298 external_declaration_list
300 delete state->symbols;
301 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
302 _mesa_glsl_initialize_types(state);
307 /* blank - no #version specified: defaults are already set */
308 | VERSION_TOK INTCONSTANT EOL
310 state->process_version_directive(&@2, $2, NULL);
315 | VERSION_TOK INTCONSTANT any_identifier EOL
317 state->process_version_directive(&@2, $2, $3);
326 | PRAGMA_DEBUG_OFF EOL
327 | PRAGMA_OPTIMIZE_ON EOL
328 | PRAGMA_OPTIMIZE_OFF EOL
329 | PRAGMA_INVARIANT_ALL EOL
331 if (!state->is_version(120, 100)) {
332 _mesa_glsl_warning(& @1, state,
333 "pragma `invariant(all)' not supported in %s "
334 "(GLSL ES 1.00 or GLSL 1.20 required)",
335 state->get_version_string());
337 state->all_invariant = true;
342 extension_statement_list:
344 | extension_statement_list extension_statement
354 EXTENSION any_identifier COLON any_identifier EOL
356 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
362 external_declaration_list:
365 /* FINISHME: The NULL test is required because pragmas are set to
366 * FINISHME: NULL. (See production rule for external_declaration.)
369 state->translation_unit.push_tail(& $1->link);
371 | external_declaration_list external_declaration
373 /* FINISHME: The NULL test is required because pragmas are set to
374 * FINISHME: NULL. (See production rule for external_declaration.)
377 state->translation_unit.push_tail(& $2->link);
390 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
391 $$->set_location(yylloc);
392 $$->primary_expression.identifier = $1;
397 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
398 $$->set_location(yylloc);
399 $$->primary_expression.int_constant = $1;
404 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
405 $$->set_location(yylloc);
406 $$->primary_expression.uint_constant = $1;
411 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
412 $$->set_location(yylloc);
413 $$->primary_expression.float_constant = $1;
418 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
419 $$->set_location(yylloc);
420 $$->primary_expression.bool_constant = $1;
430 | postfix_expression '[' integer_expression ']'
433 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
434 $$->set_location(yylloc);
440 | postfix_expression '.' any_identifier
443 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
444 $$->set_location(yylloc);
445 $$->primary_expression.identifier = $3;
447 | postfix_expression INC_OP
450 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
451 $$->set_location(yylloc);
453 | postfix_expression DEC_OP
456 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
457 $$->set_location(yylloc);
466 function_call_or_method
469 function_call_or_method:
470 function_call_generic
471 | postfix_expression '.' method_call_generic
474 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
475 $$->set_location(yylloc);
479 function_call_generic:
480 function_call_header_with_parameters ')'
481 | function_call_header_no_parameters ')'
484 function_call_header_no_parameters:
485 function_call_header VOID_TOK
486 | function_call_header
489 function_call_header_with_parameters:
490 function_call_header assignment_expression
493 $$->set_location(yylloc);
494 $$->expressions.push_tail(& $2->link);
496 | function_call_header_with_parameters ',' assignment_expression
499 $$->set_location(yylloc);
500 $$->expressions.push_tail(& $3->link);
504 // Grammar Note: Constructors look like functions, but lexical
505 // analysis recognized most of them as keywords. They are now
506 // recognized through "type_specifier".
507 function_call_header:
508 function_identifier '('
515 $$ = new(ctx) ast_function_expression($1);
516 $$->set_location(yylloc);
518 | variable_identifier
521 ast_expression *callee = new(ctx) ast_expression($1);
522 $$ = new(ctx) ast_function_expression(callee);
523 $$->set_location(yylloc);
528 ast_expression *callee = new(ctx) ast_expression($1);
529 $$ = new(ctx) ast_function_expression(callee);
530 $$->set_location(yylloc);
535 method_call_header_with_parameters ')'
536 | method_call_header_no_parameters ')'
539 method_call_header_no_parameters:
540 method_call_header VOID_TOK
544 method_call_header_with_parameters:
545 method_call_header assignment_expression
548 $$->set_location(yylloc);
549 $$->expressions.push_tail(& $2->link);
551 | method_call_header_with_parameters ',' assignment_expression
554 $$->set_location(yylloc);
555 $$->expressions.push_tail(& $3->link);
559 // Grammar Note: Constructors look like methods, but lexical
560 // analysis recognized most of them as keywords. They are now
561 // recognized through "type_specifier".
563 variable_identifier '('
566 ast_expression *callee = new(ctx) ast_expression($1);
567 $$ = new(ctx) ast_function_expression(callee);
568 $$->set_location(yylloc);
572 // Grammar Note: No traditional style type casts.
575 | INC_OP unary_expression
578 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
579 $$->set_location(yylloc);
581 | DEC_OP unary_expression
584 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
585 $$->set_location(yylloc);
587 | unary_operator unary_expression
590 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
591 $$->set_location(yylloc);
595 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
597 '+' { $$ = ast_plus; }
598 | '-' { $$ = ast_neg; }
599 | '!' { $$ = ast_logic_not; }
600 | '~' { $$ = ast_bit_not; }
603 multiplicative_expression:
605 | multiplicative_expression '*' unary_expression
608 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
609 $$->set_location(yylloc);
611 | multiplicative_expression '/' unary_expression
614 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
615 $$->set_location(yylloc);
617 | multiplicative_expression '%' unary_expression
620 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
621 $$->set_location(yylloc);
626 multiplicative_expression
627 | additive_expression '+' multiplicative_expression
630 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
631 $$->set_location(yylloc);
633 | additive_expression '-' multiplicative_expression
636 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
637 $$->set_location(yylloc);
643 | shift_expression LEFT_OP additive_expression
646 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
647 $$->set_location(yylloc);
649 | shift_expression RIGHT_OP additive_expression
652 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
653 $$->set_location(yylloc);
657 relational_expression:
659 | relational_expression '<' shift_expression
662 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
663 $$->set_location(yylloc);
665 | relational_expression '>' shift_expression
668 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
669 $$->set_location(yylloc);
671 | relational_expression LE_OP shift_expression
674 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
675 $$->set_location(yylloc);
677 | relational_expression GE_OP shift_expression
680 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
681 $$->set_location(yylloc);
686 relational_expression
687 | equality_expression EQ_OP relational_expression
690 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
691 $$->set_location(yylloc);
693 | equality_expression NE_OP relational_expression
696 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
697 $$->set_location(yylloc);
703 | and_expression '&' equality_expression
706 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
707 $$->set_location(yylloc);
711 exclusive_or_expression:
713 | exclusive_or_expression '^' and_expression
716 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
717 $$->set_location(yylloc);
721 inclusive_or_expression:
722 exclusive_or_expression
723 | inclusive_or_expression '|' exclusive_or_expression
726 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
727 $$->set_location(yylloc);
731 logical_and_expression:
732 inclusive_or_expression
733 | logical_and_expression AND_OP inclusive_or_expression
736 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
737 $$->set_location(yylloc);
741 logical_xor_expression:
742 logical_and_expression
743 | logical_xor_expression XOR_OP logical_and_expression
746 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
747 $$->set_location(yylloc);
751 logical_or_expression:
752 logical_xor_expression
753 | logical_or_expression OR_OP logical_xor_expression
756 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
757 $$->set_location(yylloc);
761 conditional_expression:
762 logical_or_expression
763 | logical_or_expression '?' expression ':' assignment_expression
766 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
767 $$->set_location(yylloc);
771 assignment_expression:
772 conditional_expression
773 | unary_expression assignment_operator assignment_expression
776 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
777 $$->set_location(yylloc);
782 '=' { $$ = ast_assign; }
783 | MUL_ASSIGN { $$ = ast_mul_assign; }
784 | DIV_ASSIGN { $$ = ast_div_assign; }
785 | MOD_ASSIGN { $$ = ast_mod_assign; }
786 | ADD_ASSIGN { $$ = ast_add_assign; }
787 | SUB_ASSIGN { $$ = ast_sub_assign; }
788 | LEFT_ASSIGN { $$ = ast_ls_assign; }
789 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
790 | AND_ASSIGN { $$ = ast_and_assign; }
791 | XOR_ASSIGN { $$ = ast_xor_assign; }
792 | OR_ASSIGN { $$ = ast_or_assign; }
796 assignment_expression
800 | expression ',' assignment_expression
803 if ($1->oper != ast_sequence) {
804 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
805 $$->set_location(yylloc);
806 $$->expressions.push_tail(& $1->link);
811 $$->expressions.push_tail(& $3->link);
816 conditional_expression
820 function_prototype ';'
822 state->symbols->pop_scope();
825 | init_declarator_list ';'
829 | PRECISION precision_qualifier type_specifier ';'
831 $3->default_precision = $2;
841 function_declarator ')'
846 | function_header_with_parameters
849 function_header_with_parameters:
850 function_header parameter_declaration
853 $$->parameters.push_tail(& $2->link);
855 | function_header_with_parameters ',' parameter_declaration
858 $$->parameters.push_tail(& $3->link);
863 fully_specified_type variable_identifier '('
866 $$ = new(ctx) ast_function();
867 $$->set_location(yylloc);
868 $$->return_type = $1;
871 state->symbols->add_function(new(state) ir_function($2));
872 state->symbols->push_scope();
876 parameter_declarator:
877 type_specifier any_identifier
880 $$ = new(ctx) ast_parameter_declarator();
881 $$->set_location(yylloc);
882 $$->type = new(ctx) ast_fully_specified_type();
883 $$->type->set_location(yylloc);
884 $$->type->specifier = $1;
887 | type_specifier any_identifier array_specifier
890 $$ = new(ctx) ast_parameter_declarator();
891 $$->set_location(yylloc);
892 $$->type = new(ctx) ast_fully_specified_type();
893 $$->type->set_location(yylloc);
894 $$->type->specifier = $1;
896 $$->array_specifier = $3;
900 parameter_declaration:
901 parameter_qualifier parameter_declarator
904 $$->type->qualifier = $1;
906 | parameter_qualifier parameter_type_specifier
909 $$ = new(ctx) ast_parameter_declarator();
910 $$->set_location(yylloc);
911 $$->type = new(ctx) ast_fully_specified_type();
912 $$->type->qualifier = $1;
913 $$->type->specifier = $2;
920 memset(& $$, 0, sizeof($$));
922 | CONST_TOK parameter_qualifier
924 if ($2.flags.q.constant)
925 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
928 $$.flags.q.constant = 1;
930 | parameter_direction_qualifier parameter_qualifier
932 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
933 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
935 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
936 _mesa_glsl_error(&@1, state, "const must be specified before "
940 $$.merge_qualifier(&@1, state, $2);
942 | precision_qualifier parameter_qualifier
944 if ($2.precision != ast_precision_none)
945 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
947 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
948 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
954 parameter_direction_qualifier:
957 memset(& $$, 0, sizeof($$));
962 memset(& $$, 0, sizeof($$));
967 memset(& $$, 0, sizeof($$));
973 parameter_type_specifier:
977 init_declarator_list:
979 | init_declarator_list ',' any_identifier
982 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
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));
989 | init_declarator_list ',' any_identifier array_specifier
992 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
993 decl->set_location(yylloc);
996 $$->declarations.push_tail(&decl->link);
997 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
999 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1002 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1003 decl->set_location(yylloc);
1006 $$->declarations.push_tail(&decl->link);
1007 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1009 | init_declarator_list ',' any_identifier '=' initializer
1012 ast_declaration *decl = new(ctx) ast_declaration($3, 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));
1021 // Grammar Note: No 'enum', or 'typedef'.
1023 fully_specified_type
1026 /* Empty declaration list is valid. */
1027 $$ = new(ctx) ast_declarator_list($1);
1028 $$->set_location(yylloc);
1030 | fully_specified_type any_identifier
1033 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1035 $$ = new(ctx) ast_declarator_list($1);
1036 $$->set_location(yylloc);
1037 $$->declarations.push_tail(&decl->link);
1039 | fully_specified_type any_identifier array_specifier
1042 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1044 $$ = new(ctx) ast_declarator_list($1);
1045 $$->set_location(yylloc);
1046 $$->declarations.push_tail(&decl->link);
1048 | fully_specified_type any_identifier array_specifier '=' initializer
1051 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1053 $$ = new(ctx) ast_declarator_list($1);
1054 $$->set_location(yylloc);
1055 $$->declarations.push_tail(&decl->link);
1057 | fully_specified_type any_identifier '=' initializer
1060 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1062 $$ = new(ctx) ast_declarator_list($1);
1063 $$->set_location(yylloc);
1064 $$->declarations.push_tail(&decl->link);
1066 | INVARIANT variable_identifier // Vertex only.
1069 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1071 $$ = new(ctx) ast_declarator_list(NULL);
1072 $$->set_location(yylloc);
1073 $$->invariant = true;
1075 $$->declarations.push_tail(&decl->link);
1079 fully_specified_type:
1083 $$ = new(ctx) ast_fully_specified_type();
1084 $$->set_location(yylloc);
1087 | type_qualifier type_specifier
1090 $$ = new(ctx) ast_fully_specified_type();
1091 $$->set_location(yylloc);
1098 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1104 layout_qualifier_id_list:
1106 | layout_qualifier_id_list ',' layout_qualifier_id
1109 if (!$$.merge_qualifier(& @3, state, $3)) {
1116 INTCONSTANT { $$ = $1; }
1117 | UINTCONSTANT { $$ = $1; }
1120 layout_qualifier_id:
1123 memset(& $$, 0, sizeof($$));
1125 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1126 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1127 state->is_version(150, 0))) {
1128 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1129 $$.flags.q.origin_upper_left = 1;
1130 } else if (match_layout_qualifier($1, "pixel_center_integer",
1132 $$.flags.q.pixel_center_integer = 1;
1135 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1136 _mesa_glsl_warning(& @1, state,
1137 "GL_ARB_fragment_coord_conventions layout "
1138 "identifier `%s' used", $1);
1142 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1144 (state->AMD_conservative_depth_enable ||
1145 state->ARB_conservative_depth_enable)) {
1146 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1147 $$.flags.q.depth_any = 1;
1148 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1149 $$.flags.q.depth_greater = 1;
1150 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1151 $$.flags.q.depth_less = 1;
1152 } else if (match_layout_qualifier($1, "depth_unchanged",
1154 $$.flags.q.depth_unchanged = 1;
1157 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1158 _mesa_glsl_warning(& @1, state,
1159 "GL_AMD_conservative_depth "
1160 "layout qualifier `%s' is used", $1);
1162 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1163 _mesa_glsl_warning(& @1, state,
1164 "GL_ARB_conservative_depth "
1165 "layout qualifier `%s' is used", $1);
1169 /* See also interface_block_layout_qualifier. */
1170 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1171 if (match_layout_qualifier($1, "std140", state) == 0) {
1172 $$.flags.q.std140 = 1;
1173 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1174 $$.flags.q.shared = 1;
1175 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1176 $$.flags.q.column_major = 1;
1177 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1178 * below in the interface_block_layout_qualifier rule.
1180 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1183 * Also, this takes care of alternate capitalizations of
1184 * "row_major" (which is necessary because layout qualifiers
1185 * are case-insensitive in desktop GLSL).
1187 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1188 $$.flags.q.row_major = 1;
1189 /* "packed" is a reserved word in GLSL, and its token is
1190 * parsed below in the interface_block_layout_qualifier rule.
1191 * However, we must take care of alternate capitalizations of
1192 * "packed", because layout qualifiers are case-insensitive
1195 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1196 $$.flags.q.packed = 1;
1199 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1200 _mesa_glsl_warning(& @1, state,
1201 "#version 140 / GL_ARB_uniform_buffer_object "
1202 "layout qualifier `%s' is used", $1);
1206 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1212 { "points", GL_POINTS },
1213 { "lines", GL_LINES },
1214 { "lines_adjacency", GL_LINES_ADJACENCY },
1215 { "line_strip", GL_LINE_STRIP },
1216 { "triangles", GL_TRIANGLES },
1217 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1218 { "triangle_strip", GL_TRIANGLE_STRIP },
1220 for (unsigned i = 0; i < Elements(map); i++) {
1221 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1222 $$.flags.q.prim_type = 1;
1223 $$.prim_type = map[i].e;
1228 if ($$.flags.i && !state->is_version(150, 0)) {
1229 _mesa_glsl_error(& @1, state, "#version 150 layout "
1230 "qualifier `%s' used", $1);
1234 /* Layout qualifiers for ARB_shader_image_load_store. */
1235 if (state->ARB_shader_image_load_store_enable ||
1236 state->is_version(420, 0)) {
1238 static const struct {
1241 glsl_base_type base_type;
1243 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT },
1244 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT },
1245 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT },
1246 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT },
1247 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT },
1248 { "r32f", GL_R32F, GLSL_TYPE_FLOAT },
1249 { "r16f", GL_R16F, GLSL_TYPE_FLOAT },
1250 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT },
1251 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT },
1252 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT },
1253 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT },
1254 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT },
1255 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT },
1256 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT },
1257 { "r32ui", GL_R32UI, GLSL_TYPE_UINT },
1258 { "r16ui", GL_R16UI, GLSL_TYPE_UINT },
1259 { "r8ui", GL_R8UI, GLSL_TYPE_UINT },
1260 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT },
1261 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT },
1262 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT },
1263 { "rg32i", GL_RG32I, GLSL_TYPE_INT },
1264 { "rg16i", GL_RG16I, GLSL_TYPE_INT },
1265 { "rg8i", GL_RG8I, GLSL_TYPE_INT },
1266 { "r32i", GL_R32I, GLSL_TYPE_INT },
1267 { "r16i", GL_R16I, GLSL_TYPE_INT },
1268 { "r8i", GL_R8I, GLSL_TYPE_INT },
1269 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT },
1270 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT },
1271 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT },
1272 { "rg16", GL_RG16, GLSL_TYPE_FLOAT },
1273 { "rg8", GL_RG8, GLSL_TYPE_FLOAT },
1274 { "r16", GL_R16, GLSL_TYPE_FLOAT },
1275 { "r8", GL_R8, GLSL_TYPE_FLOAT },
1276 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT },
1277 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT },
1278 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT },
1279 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT },
1280 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT },
1281 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT }
1284 for (unsigned i = 0; i < Elements(map); i++) {
1285 if (match_layout_qualifier($1, map[i].name, state) == 0) {
1286 $$.flags.q.explicit_image_format = 1;
1287 $$.image_format = map[i].format;
1288 $$.image_base_type = map[i].base_type;
1295 match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1296 $$.flags.q.early_fragment_tests = 1;
1301 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1306 | any_identifier '=' integer_constant
1308 memset(& $$, 0, sizeof($$));
1310 if (match_layout_qualifier("location", $1, state) == 0) {
1311 $$.flags.q.explicit_location = 1;
1316 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1321 if (match_layout_qualifier("index", $1, state) == 0) {
1322 $$.flags.q.explicit_index = 1;
1327 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1332 if ((state->ARB_shading_language_420pack_enable ||
1333 state->ARB_shader_atomic_counters_enable) &&
1334 match_layout_qualifier("binding", $1, state) == 0) {
1335 $$.flags.q.explicit_binding = 1;
1339 if (state->ARB_shader_atomic_counters_enable &&
1340 match_layout_qualifier("offset", $1, state) == 0) {
1341 $$.flags.q.explicit_offset = 1;
1345 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1346 $$.flags.q.max_vertices = 1;
1349 _mesa_glsl_error(& @3, state,
1350 "invalid max_vertices %d specified", $3);
1353 $$.max_vertices = $3;
1354 if (!state->is_version(150, 0)) {
1355 _mesa_glsl_error(& @3, state,
1356 "#version 150 max_vertices qualifier "
1362 static const char *local_size_qualifiers[3] = {
1367 for (int i = 0; i < 3; i++) {
1368 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1371 _mesa_glsl_error(& @3, state,
1372 "invalid %s of %d specified",
1373 local_size_qualifiers[i], $3);
1375 } else if (!state->is_version(430, 0) &&
1376 !state->ARB_compute_shader_enable) {
1377 _mesa_glsl_error(& @3, state,
1378 "%s qualifier requires GLSL 4.30 or "
1379 "ARB_compute_shader",
1380 local_size_qualifiers[i]);
1383 $$.flags.q.local_size |= (1 << i);
1384 $$.local_size[i] = $3;
1390 if (match_layout_qualifier("invocations", $1, state) == 0) {
1391 $$.flags.q.invocations = 1;
1394 _mesa_glsl_error(& @3, state,
1395 "invalid invocations %d specified", $3);
1397 } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) {
1398 _mesa_glsl_error(& @3, state,
1399 "invocations (%d) exceeds "
1400 "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3);
1403 $$.invocations = $3;
1404 if (!state->is_version(400, 0) &&
1405 !state->ARB_gpu_shader5_enable) {
1406 _mesa_glsl_error(& @3, state,
1407 "GL_ARB_gpu_shader5 invocations "
1408 "qualifier specified", $3);
1413 /* If the identifier didn't match any known layout identifiers,
1417 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1420 } else if (state->ARB_explicit_attrib_location_warn) {
1421 _mesa_glsl_warning(& @1, state,
1422 "GL_ARB_explicit_attrib_location layout "
1423 "identifier `%s' used", $1);
1426 | interface_block_layout_qualifier
1429 /* Layout qualifiers for ARB_uniform_buffer_object. */
1430 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1431 _mesa_glsl_error(& @1, state,
1432 "#version 140 / GL_ARB_uniform_buffer_object "
1433 "layout qualifier `%s' is used", $1);
1434 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1435 _mesa_glsl_warning(& @1, state,
1436 "#version 140 / GL_ARB_uniform_buffer_object "
1437 "layout qualifier `%s' is used", $1);
1442 /* This is a separate language rule because we parse these as tokens
1443 * (due to them being reserved keywords) instead of identifiers like
1444 * most qualifiers. See the any_identifier path of
1445 * layout_qualifier_id for the others.
1447 * Note that since layout qualifiers are case-insensitive in desktop
1448 * GLSL, all of these qualifiers need to be handled as identifiers as
1449 * well (by the any_identifier path of layout_qualifier_id).
1451 interface_block_layout_qualifier:
1454 memset(& $$, 0, sizeof($$));
1455 $$.flags.q.row_major = 1;
1459 memset(& $$, 0, sizeof($$));
1460 $$.flags.q.packed = 1;
1464 interpolation_qualifier:
1467 memset(& $$, 0, sizeof($$));
1468 $$.flags.q.smooth = 1;
1472 memset(& $$, 0, sizeof($$));
1473 $$.flags.q.flat = 1;
1477 memset(& $$, 0, sizeof($$));
1478 $$.flags.q.noperspective = 1;
1483 /* Single qualifiers */
1486 memset(& $$, 0, sizeof($$));
1487 $$.flags.q.invariant = 1;
1489 | auxiliary_storage_qualifier
1491 | interpolation_qualifier
1493 | precision_qualifier
1495 memset(&$$, 0, sizeof($$));
1499 /* Multiple qualifiers:
1500 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1501 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1503 * invariant interpolation auxiliary storage precision ...or...
1504 * layout storage precision
1506 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1507 * side don't contain any that must appear on the left hand side.
1508 * For example, when processing a storage qualifier, we check that there are
1509 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1511 | INVARIANT type_qualifier
1513 if ($2.flags.q.invariant)
1514 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1516 if ($2.has_layout()) {
1517 _mesa_glsl_error(&@1, state,
1518 "\"invariant\" cannot be used with layout(...)");
1522 $$.flags.q.invariant = 1;
1524 | interpolation_qualifier type_qualifier
1526 /* Section 4.3 of the GLSL 1.40 specification states:
1527 * "...qualified with one of these interpolation qualifiers"
1529 * GLSL 1.30 claims to allow "one or more", but insists that:
1530 * "These interpolation qualifiers may only precede the qualifiers in,
1531 * centroid in, out, or centroid out in a declaration."
1533 * ...which means that e.g. smooth can't precede smooth, so there can be
1534 * only one after all, and the 1.40 text is a clarification, not a change.
1536 if ($2.has_interpolation())
1537 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1539 if ($2.has_layout()) {
1540 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1541 "with layout(...)");
1544 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1545 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1546 "after \"invariant\"");
1550 $$.merge_qualifier(&@1, state, $2);
1552 | layout_qualifier type_qualifier
1554 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1555 * used standalone or immediately before a storage qualifier. It cannot
1556 * be used with interpolation qualifiers or invariant. There does not
1557 * appear to be any text indicating that it must come before the storage
1558 * qualifier, but always seems to in examples.
1560 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1561 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1563 if ($2.flags.q.invariant)
1564 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1565 "the \"invariant\" qualifier");
1567 if ($2.has_interpolation()) {
1568 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1569 "interpolation qualifiers");
1573 $$.merge_qualifier(&@1, state, $2);
1575 | auxiliary_storage_qualifier type_qualifier
1577 if ($2.has_auxiliary_storage()) {
1578 _mesa_glsl_error(&@1, state,
1579 "duplicate auxiliary storage qualifier (centroid or sample)");
1582 if (!state->ARB_shading_language_420pack_enable &&
1583 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1584 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1585 "just before storage qualifiers");
1588 $$.merge_qualifier(&@1, state, $2);
1590 | storage_qualifier type_qualifier
1592 /* Section 4.3 of the GLSL 1.20 specification states:
1593 * "Variable declarations may have a storage qualifier specified..."
1594 * 1.30 clarifies this to "may have one storage qualifier".
1596 if ($2.has_storage())
1597 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1599 if (!state->ARB_shading_language_420pack_enable &&
1600 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1601 $2.has_auxiliary_storage())) {
1602 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1603 "invariant, interpolation, layout and auxiliary "
1604 "storage qualifiers");
1608 $$.merge_qualifier(&@1, state, $2);
1610 | precision_qualifier type_qualifier
1612 if ($2.precision != ast_precision_none)
1613 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1615 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1616 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1623 auxiliary_storage_qualifier:
1626 memset(& $$, 0, sizeof($$));
1627 $$.flags.q.centroid = 1;
1631 memset(& $$, 0, sizeof($$));
1632 $$.flags.q.sample = 1;
1634 /* TODO: "patch" also goes here someday. */
1639 memset(& $$, 0, sizeof($$));
1640 $$.flags.q.constant = 1;
1644 memset(& $$, 0, sizeof($$));
1645 $$.flags.q.attribute = 1;
1649 memset(& $$, 0, sizeof($$));
1650 $$.flags.q.varying = 1;
1654 memset(& $$, 0, sizeof($$));
1659 memset(& $$, 0, sizeof($$));
1664 memset(& $$, 0, sizeof($$));
1665 $$.flags.q.uniform = 1;
1669 memset(& $$, 0, sizeof($$));
1670 $$.flags.q.coherent = 1;
1674 memset(& $$, 0, sizeof($$));
1675 $$.flags.q._volatile = 1;
1679 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
1680 memset(& $$, 0, sizeof($$));
1681 $$.flags.q.restrict_flag = 1;
1685 memset(& $$, 0, sizeof($$));
1686 $$.flags.q.read_only = 1;
1690 memset(& $$, 0, sizeof($$));
1691 $$.flags.q.write_only = 1;
1699 $$ = new(ctx) ast_array_specifier(yylloc);
1701 | '[' constant_expression ']'
1704 $$ = new(ctx) ast_array_specifier(yylloc, $2);
1706 | array_specifier '[' ']'
1710 if (!state->ARB_arrays_of_arrays_enable) {
1711 _mesa_glsl_error(& @1, state,
1712 "GL_ARB_arrays_of_arrays "
1713 "required for defining arrays of arrays");
1715 _mesa_glsl_error(& @1, state,
1716 "only the outermost array dimension can "
1720 | array_specifier '[' constant_expression ']'
1724 if (!state->ARB_arrays_of_arrays_enable) {
1725 _mesa_glsl_error(& @1, state,
1726 "GL_ARB_arrays_of_arrays "
1727 "required for defining arrays of arrays");
1730 $$->add_dimension($3);
1735 type_specifier_nonarray
1736 | type_specifier_nonarray array_specifier
1739 $$->array_specifier = $2;
1743 type_specifier_nonarray:
1744 basic_type_specifier_nonarray
1747 $$ = new(ctx) ast_type_specifier($1);
1748 $$->set_location(yylloc);
1753 $$ = new(ctx) ast_type_specifier($1);
1754 $$->set_location(yylloc);
1759 $$ = new(ctx) ast_type_specifier($1);
1760 $$->set_location(yylloc);
1764 basic_type_specifier_nonarray:
1765 VOID_TOK { $$ = "void"; }
1766 | FLOAT_TOK { $$ = "float"; }
1767 | INT_TOK { $$ = "int"; }
1768 | UINT_TOK { $$ = "uint"; }
1769 | BOOL_TOK { $$ = "bool"; }
1770 | VEC2 { $$ = "vec2"; }
1771 | VEC3 { $$ = "vec3"; }
1772 | VEC4 { $$ = "vec4"; }
1773 | BVEC2 { $$ = "bvec2"; }
1774 | BVEC3 { $$ = "bvec3"; }
1775 | BVEC4 { $$ = "bvec4"; }
1776 | IVEC2 { $$ = "ivec2"; }
1777 | IVEC3 { $$ = "ivec3"; }
1778 | IVEC4 { $$ = "ivec4"; }
1779 | UVEC2 { $$ = "uvec2"; }
1780 | UVEC3 { $$ = "uvec3"; }
1781 | UVEC4 { $$ = "uvec4"; }
1782 | MAT2X2 { $$ = "mat2"; }
1783 | MAT2X3 { $$ = "mat2x3"; }
1784 | MAT2X4 { $$ = "mat2x4"; }
1785 | MAT3X2 { $$ = "mat3x2"; }
1786 | MAT3X3 { $$ = "mat3"; }
1787 | MAT3X4 { $$ = "mat3x4"; }
1788 | MAT4X2 { $$ = "mat4x2"; }
1789 | MAT4X3 { $$ = "mat4x3"; }
1790 | MAT4X4 { $$ = "mat4"; }
1791 | SAMPLER1D { $$ = "sampler1D"; }
1792 | SAMPLER2D { $$ = "sampler2D"; }
1793 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1794 | SAMPLER3D { $$ = "sampler3D"; }
1795 | SAMPLERCUBE { $$ = "samplerCube"; }
1796 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1797 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1798 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1799 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1800 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1801 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1802 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1803 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1804 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1805 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1806 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1807 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1808 | ISAMPLER1D { $$ = "isampler1D"; }
1809 | ISAMPLER2D { $$ = "isampler2D"; }
1810 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1811 | ISAMPLER3D { $$ = "isampler3D"; }
1812 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1813 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1814 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1815 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1816 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1817 | USAMPLER1D { $$ = "usampler1D"; }
1818 | USAMPLER2D { $$ = "usampler2D"; }
1819 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1820 | USAMPLER3D { $$ = "usampler3D"; }
1821 | USAMPLERCUBE { $$ = "usamplerCube"; }
1822 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1823 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1824 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1825 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1826 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1827 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1828 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1829 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1830 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1831 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1832 | IMAGE1D { $$ = "image1D"; }
1833 | IMAGE2D { $$ = "image2D"; }
1834 | IMAGE3D { $$ = "image3D"; }
1835 | IMAGE2DRECT { $$ = "image2DRect"; }
1836 | IMAGECUBE { $$ = "imageCube"; }
1837 | IMAGEBUFFER { $$ = "imageBuffer"; }
1838 | IMAGE1DARRAY { $$ = "image1DArray"; }
1839 | IMAGE2DARRAY { $$ = "image2DArray"; }
1840 | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
1841 | IMAGE2DMS { $$ = "image2DMS"; }
1842 | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
1843 | IIMAGE1D { $$ = "iimage1D"; }
1844 | IIMAGE2D { $$ = "iimage2D"; }
1845 | IIMAGE3D { $$ = "iimage3D"; }
1846 | IIMAGE2DRECT { $$ = "iimage2DRect"; }
1847 | IIMAGECUBE { $$ = "iimageCube"; }
1848 | IIMAGEBUFFER { $$ = "iimageBuffer"; }
1849 | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
1850 | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
1851 | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
1852 | IIMAGE2DMS { $$ = "iimage2DMS"; }
1853 | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
1854 | UIMAGE1D { $$ = "uimage1D"; }
1855 | UIMAGE2D { $$ = "uimage2D"; }
1856 | UIMAGE3D { $$ = "uimage3D"; }
1857 | UIMAGE2DRECT { $$ = "uimage2DRect"; }
1858 | UIMAGECUBE { $$ = "uimageCube"; }
1859 | UIMAGEBUFFER { $$ = "uimageBuffer"; }
1860 | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
1861 | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
1862 | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
1863 | UIMAGE2DMS { $$ = "uimage2DMS"; }
1864 | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
1865 | ATOMIC_UINT { $$ = "atomic_uint"; }
1868 precision_qualifier:
1871 state->check_precision_qualifiers_allowed(&@1);
1872 $$ = ast_precision_high;
1876 state->check_precision_qualifiers_allowed(&@1);
1877 $$ = ast_precision_medium;
1881 state->check_precision_qualifiers_allowed(&@1);
1882 $$ = ast_precision_low;
1887 STRUCT any_identifier '{' struct_declaration_list '}'
1890 $$ = new(ctx) ast_struct_specifier($2, $4);
1891 $$->set_location(yylloc);
1892 state->symbols->add_type($2, glsl_type::void_type);
1893 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1895 | STRUCT '{' struct_declaration_list '}'
1898 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1899 $$->set_location(yylloc);
1903 struct_declaration_list:
1907 $1->link.self_link();
1909 | struct_declaration_list struct_declaration
1912 $$->link.insert_before(& $2->link);
1917 fully_specified_type struct_declarator_list ';'
1920 ast_fully_specified_type *const type = $1;
1921 type->set_location(yylloc);
1923 if (type->qualifier.flags.i != 0)
1924 _mesa_glsl_error(&@1, state,
1925 "only precision qualifiers may be applied to "
1926 "structure members");
1928 $$ = new(ctx) ast_declarator_list(type);
1929 $$->set_location(yylloc);
1931 $$->declarations.push_degenerate_list_at_head(& $2->link);
1935 struct_declarator_list:
1939 $1->link.self_link();
1941 | struct_declarator_list ',' struct_declarator
1944 $$->link.insert_before(& $3->link);
1952 $$ = new(ctx) ast_declaration($1, NULL, NULL);
1953 $$->set_location(yylloc);
1955 | any_identifier array_specifier
1958 $$ = new(ctx) ast_declaration($1, $2, NULL);
1959 $$->set_location(yylloc);
1964 assignment_expression
1965 | '{' initializer_list '}'
1969 | '{' initializer_list ',' '}'
1979 $$ = new(ctx) ast_aggregate_initializer();
1980 $$->set_location(yylloc);
1981 $$->expressions.push_tail(& $1->link);
1983 | initializer_list ',' initializer
1985 $1->expressions.push_tail(& $3->link);
1989 declaration_statement:
1993 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1996 compound_statement { $$ = (ast_node *) $1; }
2001 declaration_statement
2002 | expression_statement
2003 | selection_statement
2005 | iteration_statement
2013 $$ = new(ctx) ast_compound_statement(true, NULL);
2014 $$->set_location(yylloc);
2018 state->symbols->push_scope();
2023 $$ = new(ctx) ast_compound_statement(true, $3);
2024 $$->set_location(yylloc);
2025 state->symbols->pop_scope();
2029 statement_no_new_scope:
2030 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2034 compound_statement_no_new_scope:
2038 $$ = new(ctx) ast_compound_statement(false, NULL);
2039 $$->set_location(yylloc);
2041 | '{' statement_list '}'
2044 $$ = new(ctx) ast_compound_statement(false, $2);
2045 $$->set_location(yylloc);
2053 _mesa_glsl_error(& @1, state, "<nil> statement");
2058 $$->link.self_link();
2060 | statement_list statement
2063 _mesa_glsl_error(& @2, state, "<nil> statement");
2067 $$->link.insert_before(& $2->link);
2071 expression_statement:
2075 $$ = new(ctx) ast_expression_statement(NULL);
2076 $$->set_location(yylloc);
2081 $$ = new(ctx) ast_expression_statement($1);
2082 $$->set_location(yylloc);
2086 selection_statement:
2087 IF '(' expression ')' selection_rest_statement
2089 $$ = new(state) ast_selection_statement($3, $5.then_statement,
2091 $$->set_location(yylloc);
2095 selection_rest_statement:
2096 statement ELSE statement
2098 $$.then_statement = $1;
2099 $$.else_statement = $3;
2101 | statement %prec THEN
2103 $$.then_statement = $1;
2104 $$.else_statement = NULL;
2111 $$ = (ast_node *) $1;
2113 | fully_specified_type any_identifier '=' initializer
2116 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2117 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2118 decl->set_location(yylloc);
2119 declarator->set_location(yylloc);
2121 declarator->declarations.push_tail(&decl->link);
2127 * siwtch_statement grammar is based on the syntax described in the body
2128 * of the GLSL spec, not in it's appendix!!!
2131 SWITCH '(' expression ')' switch_body
2133 $$ = new(state) ast_switch_statement($3, $5);
2134 $$->set_location(yylloc);
2141 $$ = new(state) ast_switch_body(NULL);
2142 $$->set_location(yylloc);
2144 | '{' case_statement_list '}'
2146 $$ = new(state) ast_switch_body($2);
2147 $$->set_location(yylloc);
2154 $$ = new(state) ast_case_label($2);
2155 $$->set_location(yylloc);
2159 $$ = new(state) ast_case_label(NULL);
2160 $$->set_location(yylloc);
2167 ast_case_label_list *labels = new(state) ast_case_label_list();
2169 labels->labels.push_tail(& $1->link);
2171 $$->set_location(yylloc);
2173 | case_label_list case_label
2176 $$->labels.push_tail(& $2->link);
2181 case_label_list statement
2183 ast_case_statement *stmts = new(state) ast_case_statement($1);
2184 stmts->set_location(yylloc);
2186 stmts->stmts.push_tail(& $2->link);
2189 | case_statement statement
2192 $$->stmts.push_tail(& $2->link);
2196 case_statement_list:
2199 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2200 cases->set_location(yylloc);
2202 cases->cases.push_tail(& $1->link);
2205 | case_statement_list case_statement
2208 $$->cases.push_tail(& $2->link);
2212 iteration_statement:
2213 WHILE '(' condition ')' statement_no_new_scope
2216 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2217 NULL, $3, NULL, $5);
2218 $$->set_location(yylloc);
2220 | DO statement WHILE '(' expression ')' ';'
2223 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2224 NULL, $5, NULL, $2);
2225 $$->set_location(yylloc);
2227 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2230 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2231 $3, $4.cond, $4.rest, $6);
2232 $$->set_location(yylloc);
2237 expression_statement
2238 | declaration_statement
2255 | conditionopt ';' expression
2262 // Grammar Note: No 'goto'. Gotos are not supported.
2267 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2268 $$->set_location(yylloc);
2273 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2274 $$->set_location(yylloc);
2279 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2280 $$->set_location(yylloc);
2282 | RETURN expression ';'
2285 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2286 $$->set_location(yylloc);
2288 | DISCARD ';' // Fragment shader only.
2291 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2292 $$->set_location(yylloc);
2296 external_declaration:
2297 function_definition { $$ = $1; }
2298 | declaration { $$ = $1; }
2299 | pragma_statement { $$ = NULL; }
2300 | layout_defaults { $$ = $1; }
2303 function_definition:
2304 function_prototype compound_statement_no_new_scope
2307 $$ = new(ctx) ast_function_definition();
2308 $$->set_location(yylloc);
2312 state->symbols->pop_scope();
2316 /* layout_qualifieropt is packed into this rule */
2318 basic_interface_block
2322 | layout_qualifier basic_interface_block
2324 ast_interface_block *block = $2;
2325 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2332 basic_interface_block:
2333 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2335 ast_interface_block *const block = $6;
2337 block->block_name = $2;
2338 block->declarations.push_degenerate_list_at_head(& $4->link);
2340 if ($1.flags.q.uniform) {
2341 if (!state->has_uniform_buffer_objects()) {
2342 _mesa_glsl_error(& @1, state,
2343 "#version 140 / GL_ARB_uniform_buffer_object "
2344 "required for defining uniform blocks");
2345 } else if (state->ARB_uniform_buffer_object_warn) {
2346 _mesa_glsl_warning(& @1, state,
2347 "#version 140 / GL_ARB_uniform_buffer_object "
2348 "required for defining uniform blocks");
2351 if (state->es_shader || state->language_version < 150) {
2352 _mesa_glsl_error(& @1, state,
2353 "#version 150 required for using "
2354 "interface blocks");
2358 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2359 * "It is illegal to have an input block in a vertex shader
2360 * or an output block in a fragment shader"
2362 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2363 _mesa_glsl_error(& @1, state,
2364 "`in' interface block is not allowed for "
2366 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2367 _mesa_glsl_error(& @1, state,
2368 "`out' interface block is not allowed for "
2369 "a fragment shader");
2372 /* Since block arrays require names, and both features are added in
2373 * the same language versions, we don't have to explicitly
2374 * version-check both things.
2376 if (block->instance_name != NULL) {
2377 state->check_version(150, 300, & @1, "interface blocks with "
2378 "an instance name are not allowed");
2381 uint64_t interface_type_mask;
2382 struct ast_type_qualifier temp_type_qualifier;
2384 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2385 * to ignore other irrelevant flags like interpolation qualifiers.
2387 temp_type_qualifier.flags.i = 0;
2388 temp_type_qualifier.flags.q.uniform = true;
2389 temp_type_qualifier.flags.q.in = true;
2390 temp_type_qualifier.flags.q.out = true;
2391 interface_type_mask = temp_type_qualifier.flags.i;
2393 /* Get the block's interface qualifier. The interface_qualifier
2394 * production rule guarantees that only one bit will be set (and
2395 * it will be in/out/uniform).
2397 uint64_t block_interface_qualifier = $1.flags.i;
2399 block->layout.flags.i |= block_interface_qualifier;
2401 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2402 ast_type_qualifier& qualifier = member->type->qualifier;
2403 if ((qualifier.flags.i & interface_type_mask) == 0) {
2404 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2405 * "If no optional qualifier is used in a member declaration, the
2406 * qualifier of the variable is just in, out, or uniform as declared
2407 * by interface-qualifier."
2409 qualifier.flags.i |= block_interface_qualifier;
2410 } else if ((qualifier.flags.i & interface_type_mask) !=
2411 block_interface_qualifier) {
2412 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2413 * "If optional qualifiers are used, they can include interpolation
2414 * and storage qualifiers and they must declare an input, output,
2415 * or uniform variable consistent with the interface qualifier of
2418 _mesa_glsl_error(& @1, state,
2419 "uniform/in/out qualifier on "
2420 "interface block member does not match "
2421 "the interface block");
2429 interface_qualifier:
2432 memset(& $$, 0, sizeof($$));
2437 memset(& $$, 0, sizeof($$));
2442 memset(& $$, 0, sizeof($$));
2443 $$.flags.q.uniform = 1;
2450 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2455 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2458 | NEW_IDENTIFIER array_specifier
2460 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2469 $1->link.self_link();
2471 | member_declaration member_list
2474 $2->link.insert_before(& $$->link);
2479 fully_specified_type struct_declarator_list ';'
2482 ast_fully_specified_type *type = $1;
2483 type->set_location(yylloc);
2485 if (type->qualifier.flags.q.attribute) {
2486 _mesa_glsl_error(& @1, state,
2487 "keyword 'attribute' cannot be used with "
2488 "interface block member");
2489 } else if (type->qualifier.flags.q.varying) {
2490 _mesa_glsl_error(& @1, state,
2491 "keyword 'varying' cannot be used with "
2492 "interface block member");
2495 $$ = new(ctx) ast_declarator_list(type);
2496 $$->set_location(yylloc);
2498 $$->declarations.push_degenerate_list_at_head(& $2->link);
2503 layout_qualifier UNIFORM ';'
2505 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2511 | layout_qualifier IN_TOK ';'
2514 if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) {
2519 | layout_qualifier OUT_TOK ';'
2521 if (state->stage != MESA_SHADER_GEOMETRY) {
2522 _mesa_glsl_error(& @1, state,
2523 "out layout qualifiers only valid in "
2524 "geometry shaders");
2526 if ($1.flags.q.prim_type) {
2527 /* Make sure this is a valid output primitive type. */
2528 switch ($1.prim_type) {
2531 case GL_TRIANGLE_STRIP:
2534 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2539 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))