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
149 %token STRUCT VOID_TOK WHILE
150 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
151 %type <identifier> any_identifier
152 %type <interface_block> instance_name_opt
153 %token <real> FLOATCONSTANT
154 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
155 %token <identifier> FIELD_SELECTION
156 %token LEFT_OP RIGHT_OP
157 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
158 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
159 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
162 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
164 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
165 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
166 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
167 %token PRAGMA_INVARIANT_ALL
170 /* Reserved words that are not actually used in the grammar.
172 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
173 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
174 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
175 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
177 %token SIZEOF CAST NAMESPACE USING
178 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE PATCH SAMPLE
183 %token COMMON PARTITION ACTIVE FILTER
184 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
185 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
186 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
187 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
188 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
191 %type <identifier> variable_identifier
192 %type <node> statement
193 %type <node> statement_list
194 %type <node> simple_statement
195 %type <n> precision_qualifier
196 %type <type_qualifier> type_qualifier
197 %type <type_qualifier> auxiliary_storage_qualifier
198 %type <type_qualifier> storage_qualifier
199 %type <type_qualifier> interpolation_qualifier
200 %type <type_qualifier> layout_qualifier
201 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
202 %type <type_qualifier> interface_block_layout_qualifier
203 %type <type_qualifier> interface_qualifier
204 %type <type_specifier> type_specifier
205 %type <type_specifier> type_specifier_nonarray
206 %type <array_specifier> array_specifier
207 %type <identifier> basic_type_specifier_nonarray
208 %type <fully_specified_type> fully_specified_type
209 %type <function> function_prototype
210 %type <function> function_header
211 %type <function> function_header_with_parameters
212 %type <function> function_declarator
213 %type <parameter_declarator> parameter_declarator
214 %type <parameter_declarator> parameter_declaration
215 %type <type_qualifier> parameter_qualifier
216 %type <type_qualifier> parameter_direction_qualifier
217 %type <type_specifier> parameter_type_specifier
218 %type <function_definition> function_definition
219 %type <compound_statement> compound_statement_no_new_scope
220 %type <compound_statement> compound_statement
221 %type <node> statement_no_new_scope
222 %type <node> expression_statement
223 %type <expression> expression
224 %type <expression> primary_expression
225 %type <expression> assignment_expression
226 %type <expression> conditional_expression
227 %type <expression> logical_or_expression
228 %type <expression> logical_xor_expression
229 %type <expression> logical_and_expression
230 %type <expression> inclusive_or_expression
231 %type <expression> exclusive_or_expression
232 %type <expression> and_expression
233 %type <expression> equality_expression
234 %type <expression> relational_expression
235 %type <expression> shift_expression
236 %type <expression> additive_expression
237 %type <expression> multiplicative_expression
238 %type <expression> unary_expression
239 %type <expression> constant_expression
240 %type <expression> integer_expression
241 %type <expression> postfix_expression
242 %type <expression> function_call_header_with_parameters
243 %type <expression> function_call_header_no_parameters
244 %type <expression> function_call_header
245 %type <expression> function_call_generic
246 %type <expression> function_call_or_method
247 %type <expression> function_call
248 %type <expression> method_call_generic
249 %type <expression> method_call_header_with_parameters
250 %type <expression> method_call_header_no_parameters
251 %type <expression> method_call_header
252 %type <n> assignment_operator
253 %type <n> unary_operator
254 %type <expression> function_identifier
255 %type <node> external_declaration
256 %type <declarator_list> init_declarator_list
257 %type <declarator_list> single_declaration
258 %type <expression> initializer
259 %type <expression> initializer_list
260 %type <node> declaration
261 %type <node> declaration_statement
262 %type <node> jump_statement
263 %type <node> interface_block
264 %type <interface_block> basic_interface_block
265 %type <struct_specifier> struct_specifier
266 %type <declarator_list> struct_declaration_list
267 %type <declarator_list> struct_declaration
268 %type <declaration> struct_declarator
269 %type <declaration> struct_declarator_list
270 %type <declarator_list> member_list
271 %type <declarator_list> member_declaration
272 %type <node> selection_statement
273 %type <selection_rest_statement> selection_rest_statement
274 %type <node> switch_statement
275 %type <switch_body> switch_body
276 %type <case_label_list> case_label_list
277 %type <case_label> case_label
278 %type <case_statement> case_statement
279 %type <case_statement_list> case_statement_list
280 %type <node> iteration_statement
281 %type <node> condition
282 %type <node> conditionopt
283 %type <node> for_init_statement
284 %type <for_rest_statement> for_rest_statement
285 %type <n> integer_constant
286 %type <node> layout_defaults
292 version_statement extension_statement_list
294 _mesa_glsl_initialize_types(state);
296 external_declaration_list
298 delete state->symbols;
299 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
300 _mesa_glsl_initialize_types(state);
305 /* blank - no #version specified: defaults are already set */
306 | VERSION_TOK INTCONSTANT EOL
308 state->process_version_directive(&@2, $2, NULL);
313 | VERSION_TOK INTCONSTANT any_identifier EOL
315 state->process_version_directive(&@2, $2, $3);
324 | PRAGMA_DEBUG_OFF EOL
325 | PRAGMA_OPTIMIZE_ON EOL
326 | PRAGMA_OPTIMIZE_OFF EOL
327 | PRAGMA_INVARIANT_ALL EOL
329 if (!state->is_version(120, 100)) {
330 _mesa_glsl_warning(& @1, state,
331 "pragma `invariant(all)' not supported in %s "
332 "(GLSL ES 1.00 or GLSL 1.20 required)",
333 state->get_version_string());
335 state->all_invariant = true;
340 extension_statement_list:
342 | extension_statement_list extension_statement
352 EXTENSION any_identifier COLON any_identifier EOL
354 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
360 external_declaration_list:
363 /* FINISHME: The NULL test is required because pragmas are set to
364 * FINISHME: NULL. (See production rule for external_declaration.)
367 state->translation_unit.push_tail(& $1->link);
369 | external_declaration_list external_declaration
371 /* FINISHME: The NULL test is required because pragmas are set to
372 * FINISHME: NULL. (See production rule for external_declaration.)
375 state->translation_unit.push_tail(& $2->link);
388 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
389 $$->set_location(yylloc);
390 $$->primary_expression.identifier = $1;
395 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
396 $$->set_location(yylloc);
397 $$->primary_expression.int_constant = $1;
402 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
403 $$->set_location(yylloc);
404 $$->primary_expression.uint_constant = $1;
409 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
410 $$->set_location(yylloc);
411 $$->primary_expression.float_constant = $1;
416 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
417 $$->set_location(yylloc);
418 $$->primary_expression.bool_constant = $1;
428 | postfix_expression '[' integer_expression ']'
431 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
432 $$->set_location(yylloc);
438 | postfix_expression '.' any_identifier
441 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
442 $$->set_location(yylloc);
443 $$->primary_expression.identifier = $3;
445 | postfix_expression INC_OP
448 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
449 $$->set_location(yylloc);
451 | postfix_expression DEC_OP
454 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
455 $$->set_location(yylloc);
464 function_call_or_method
467 function_call_or_method:
468 function_call_generic
469 | postfix_expression '.' method_call_generic
472 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
473 $$->set_location(yylloc);
477 function_call_generic:
478 function_call_header_with_parameters ')'
479 | function_call_header_no_parameters ')'
482 function_call_header_no_parameters:
483 function_call_header VOID_TOK
484 | function_call_header
487 function_call_header_with_parameters:
488 function_call_header assignment_expression
491 $$->set_location(yylloc);
492 $$->expressions.push_tail(& $2->link);
494 | function_call_header_with_parameters ',' assignment_expression
497 $$->set_location(yylloc);
498 $$->expressions.push_tail(& $3->link);
502 // Grammar Note: Constructors look like functions, but lexical
503 // analysis recognized most of them as keywords. They are now
504 // recognized through "type_specifier".
505 function_call_header:
506 function_identifier '('
513 $$ = new(ctx) ast_function_expression($1);
514 $$->set_location(yylloc);
516 | variable_identifier
519 ast_expression *callee = new(ctx) ast_expression($1);
520 $$ = new(ctx) ast_function_expression(callee);
521 $$->set_location(yylloc);
526 ast_expression *callee = new(ctx) ast_expression($1);
527 $$ = new(ctx) ast_function_expression(callee);
528 $$->set_location(yylloc);
533 method_call_header_with_parameters ')'
534 | method_call_header_no_parameters ')'
537 method_call_header_no_parameters:
538 method_call_header VOID_TOK
542 method_call_header_with_parameters:
543 method_call_header assignment_expression
546 $$->set_location(yylloc);
547 $$->expressions.push_tail(& $2->link);
549 | method_call_header_with_parameters ',' assignment_expression
552 $$->set_location(yylloc);
553 $$->expressions.push_tail(& $3->link);
557 // Grammar Note: Constructors look like methods, but lexical
558 // analysis recognized most of them as keywords. They are now
559 // recognized through "type_specifier".
561 variable_identifier '('
564 ast_expression *callee = new(ctx) ast_expression($1);
565 $$ = new(ctx) ast_function_expression(callee);
566 $$->set_location(yylloc);
570 // Grammar Note: No traditional style type casts.
573 | INC_OP unary_expression
576 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
577 $$->set_location(yylloc);
579 | DEC_OP unary_expression
582 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
583 $$->set_location(yylloc);
585 | unary_operator unary_expression
588 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
589 $$->set_location(yylloc);
593 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
595 '+' { $$ = ast_plus; }
596 | '-' { $$ = ast_neg; }
597 | '!' { $$ = ast_logic_not; }
598 | '~' { $$ = ast_bit_not; }
601 multiplicative_expression:
603 | multiplicative_expression '*' unary_expression
606 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
607 $$->set_location(yylloc);
609 | multiplicative_expression '/' unary_expression
612 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
613 $$->set_location(yylloc);
615 | multiplicative_expression '%' unary_expression
618 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
619 $$->set_location(yylloc);
624 multiplicative_expression
625 | additive_expression '+' multiplicative_expression
628 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
629 $$->set_location(yylloc);
631 | additive_expression '-' multiplicative_expression
634 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
635 $$->set_location(yylloc);
641 | shift_expression LEFT_OP additive_expression
644 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
645 $$->set_location(yylloc);
647 | shift_expression RIGHT_OP additive_expression
650 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
651 $$->set_location(yylloc);
655 relational_expression:
657 | relational_expression '<' shift_expression
660 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
661 $$->set_location(yylloc);
663 | relational_expression '>' shift_expression
666 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
667 $$->set_location(yylloc);
669 | relational_expression LE_OP shift_expression
672 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
673 $$->set_location(yylloc);
675 | relational_expression GE_OP shift_expression
678 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
679 $$->set_location(yylloc);
684 relational_expression
685 | equality_expression EQ_OP relational_expression
688 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
689 $$->set_location(yylloc);
691 | equality_expression NE_OP relational_expression
694 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
695 $$->set_location(yylloc);
701 | and_expression '&' equality_expression
704 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
705 $$->set_location(yylloc);
709 exclusive_or_expression:
711 | exclusive_or_expression '^' and_expression
714 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
715 $$->set_location(yylloc);
719 inclusive_or_expression:
720 exclusive_or_expression
721 | inclusive_or_expression '|' exclusive_or_expression
724 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
725 $$->set_location(yylloc);
729 logical_and_expression:
730 inclusive_or_expression
731 | logical_and_expression AND_OP inclusive_or_expression
734 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
735 $$->set_location(yylloc);
739 logical_xor_expression:
740 logical_and_expression
741 | logical_xor_expression XOR_OP logical_and_expression
744 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
745 $$->set_location(yylloc);
749 logical_or_expression:
750 logical_xor_expression
751 | logical_or_expression OR_OP logical_xor_expression
754 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
755 $$->set_location(yylloc);
759 conditional_expression:
760 logical_or_expression
761 | logical_or_expression '?' expression ':' assignment_expression
764 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
765 $$->set_location(yylloc);
769 assignment_expression:
770 conditional_expression
771 | unary_expression assignment_operator assignment_expression
774 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
775 $$->set_location(yylloc);
780 '=' { $$ = ast_assign; }
781 | MUL_ASSIGN { $$ = ast_mul_assign; }
782 | DIV_ASSIGN { $$ = ast_div_assign; }
783 | MOD_ASSIGN { $$ = ast_mod_assign; }
784 | ADD_ASSIGN { $$ = ast_add_assign; }
785 | SUB_ASSIGN { $$ = ast_sub_assign; }
786 | LEFT_ASSIGN { $$ = ast_ls_assign; }
787 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
788 | AND_ASSIGN { $$ = ast_and_assign; }
789 | XOR_ASSIGN { $$ = ast_xor_assign; }
790 | OR_ASSIGN { $$ = ast_or_assign; }
794 assignment_expression
798 | expression ',' assignment_expression
801 if ($1->oper != ast_sequence) {
802 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
803 $$->set_location(yylloc);
804 $$->expressions.push_tail(& $1->link);
809 $$->expressions.push_tail(& $3->link);
814 conditional_expression
818 function_prototype ';'
820 state->symbols->pop_scope();
823 | init_declarator_list ';'
827 | PRECISION precision_qualifier type_specifier ';'
829 $3->default_precision = $2;
839 function_declarator ')'
844 | function_header_with_parameters
847 function_header_with_parameters:
848 function_header parameter_declaration
851 $$->parameters.push_tail(& $2->link);
853 | function_header_with_parameters ',' parameter_declaration
856 $$->parameters.push_tail(& $3->link);
861 fully_specified_type variable_identifier '('
864 $$ = new(ctx) ast_function();
865 $$->set_location(yylloc);
866 $$->return_type = $1;
869 state->symbols->add_function(new(state) ir_function($2));
870 state->symbols->push_scope();
874 parameter_declarator:
875 type_specifier any_identifier
878 $$ = new(ctx) ast_parameter_declarator();
879 $$->set_location(yylloc);
880 $$->type = new(ctx) ast_fully_specified_type();
881 $$->type->set_location(yylloc);
882 $$->type->specifier = $1;
885 | type_specifier any_identifier array_specifier
888 $$ = new(ctx) ast_parameter_declarator();
889 $$->set_location(yylloc);
890 $$->type = new(ctx) ast_fully_specified_type();
891 $$->type->set_location(yylloc);
892 $$->type->specifier = $1;
894 $$->array_specifier = $3;
898 parameter_declaration:
899 parameter_qualifier parameter_declarator
902 $$->type->qualifier = $1;
904 | parameter_qualifier parameter_type_specifier
907 $$ = new(ctx) ast_parameter_declarator();
908 $$->set_location(yylloc);
909 $$->type = new(ctx) ast_fully_specified_type();
910 $$->type->qualifier = $1;
911 $$->type->specifier = $2;
918 memset(& $$, 0, sizeof($$));
920 | CONST_TOK parameter_qualifier
922 if ($2.flags.q.constant)
923 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
926 $$.flags.q.constant = 1;
928 | parameter_direction_qualifier parameter_qualifier
930 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
931 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
933 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
934 _mesa_glsl_error(&@1, state, "const must be specified before "
938 $$.merge_qualifier(&@1, state, $2);
940 | precision_qualifier parameter_qualifier
942 if ($2.precision != ast_precision_none)
943 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
945 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
946 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
952 parameter_direction_qualifier:
955 memset(& $$, 0, sizeof($$));
960 memset(& $$, 0, sizeof($$));
965 memset(& $$, 0, sizeof($$));
971 parameter_type_specifier:
975 init_declarator_list:
977 | init_declarator_list ',' any_identifier
980 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
981 decl->set_location(yylloc);
984 $$->declarations.push_tail(&decl->link);
985 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
987 | init_declarator_list ',' any_identifier array_specifier
990 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
991 decl->set_location(yylloc);
994 $$->declarations.push_tail(&decl->link);
995 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
997 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1000 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1001 decl->set_location(yylloc);
1004 $$->declarations.push_tail(&decl->link);
1005 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1007 | init_declarator_list ',' any_identifier '=' initializer
1010 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1011 decl->set_location(yylloc);
1014 $$->declarations.push_tail(&decl->link);
1015 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1019 // Grammar Note: No 'enum', or 'typedef'.
1021 fully_specified_type
1024 /* Empty declaration list is valid. */
1025 $$ = new(ctx) ast_declarator_list($1);
1026 $$->set_location(yylloc);
1028 | fully_specified_type any_identifier
1031 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1033 $$ = new(ctx) ast_declarator_list($1);
1034 $$->set_location(yylloc);
1035 $$->declarations.push_tail(&decl->link);
1037 | fully_specified_type any_identifier array_specifier
1040 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1042 $$ = new(ctx) ast_declarator_list($1);
1043 $$->set_location(yylloc);
1044 $$->declarations.push_tail(&decl->link);
1046 | fully_specified_type any_identifier array_specifier '=' initializer
1049 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1051 $$ = new(ctx) ast_declarator_list($1);
1052 $$->set_location(yylloc);
1053 $$->declarations.push_tail(&decl->link);
1055 | fully_specified_type any_identifier '=' initializer
1058 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1060 $$ = new(ctx) ast_declarator_list($1);
1061 $$->set_location(yylloc);
1062 $$->declarations.push_tail(&decl->link);
1064 | INVARIANT variable_identifier // Vertex only.
1067 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1069 $$ = new(ctx) ast_declarator_list(NULL);
1070 $$->set_location(yylloc);
1071 $$->invariant = true;
1073 $$->declarations.push_tail(&decl->link);
1077 fully_specified_type:
1081 $$ = new(ctx) ast_fully_specified_type();
1082 $$->set_location(yylloc);
1085 | type_qualifier type_specifier
1088 $$ = new(ctx) ast_fully_specified_type();
1089 $$->set_location(yylloc);
1096 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1102 layout_qualifier_id_list:
1104 | layout_qualifier_id_list ',' layout_qualifier_id
1107 if (!$$.merge_qualifier(& @3, state, $3)) {
1114 INTCONSTANT { $$ = $1; }
1115 | UINTCONSTANT { $$ = $1; }
1118 layout_qualifier_id:
1121 memset(& $$, 0, sizeof($$));
1123 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1124 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1125 state->is_version(150, 0))) {
1126 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1127 $$.flags.q.origin_upper_left = 1;
1128 } else if (match_layout_qualifier($1, "pixel_center_integer",
1130 $$.flags.q.pixel_center_integer = 1;
1133 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1134 _mesa_glsl_warning(& @1, state,
1135 "GL_ARB_fragment_coord_conventions layout "
1136 "identifier `%s' used", $1);
1140 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1142 (state->AMD_conservative_depth_enable ||
1143 state->ARB_conservative_depth_enable)) {
1144 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1145 $$.flags.q.depth_any = 1;
1146 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1147 $$.flags.q.depth_greater = 1;
1148 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1149 $$.flags.q.depth_less = 1;
1150 } else if (match_layout_qualifier($1, "depth_unchanged",
1152 $$.flags.q.depth_unchanged = 1;
1155 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1156 _mesa_glsl_warning(& @1, state,
1157 "GL_AMD_conservative_depth "
1158 "layout qualifier `%s' is used", $1);
1160 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1161 _mesa_glsl_warning(& @1, state,
1162 "GL_ARB_conservative_depth "
1163 "layout qualifier `%s' is used", $1);
1167 /* See also interface_block_layout_qualifier. */
1168 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1169 if (match_layout_qualifier($1, "std140", state) == 0) {
1170 $$.flags.q.std140 = 1;
1171 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1172 $$.flags.q.shared = 1;
1173 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1174 $$.flags.q.column_major = 1;
1175 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1176 * below in the interface_block_layout_qualifier rule.
1178 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1181 * Also, this takes care of alternate capitalizations of
1182 * "row_major" (which is necessary because layout qualifiers
1183 * are case-insensitive in desktop GLSL).
1185 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1186 $$.flags.q.row_major = 1;
1187 /* "packed" is a reserved word in GLSL, and its token is
1188 * parsed below in the interface_block_layout_qualifier rule.
1189 * However, we must take care of alternate capitalizations of
1190 * "packed", because layout qualifiers are case-insensitive
1193 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1194 $$.flags.q.packed = 1;
1197 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1198 _mesa_glsl_warning(& @1, state,
1199 "#version 140 / GL_ARB_uniform_buffer_object "
1200 "layout qualifier `%s' is used", $1);
1204 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1210 { "points", GL_POINTS },
1211 { "lines", GL_LINES },
1212 { "lines_adjacency", GL_LINES_ADJACENCY },
1213 { "line_strip", GL_LINE_STRIP },
1214 { "triangles", GL_TRIANGLES },
1215 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1216 { "triangle_strip", GL_TRIANGLE_STRIP },
1218 for (unsigned i = 0; i < Elements(map); i++) {
1219 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1220 $$.flags.q.prim_type = 1;
1221 $$.prim_type = map[i].e;
1226 if ($$.flags.i && !state->is_version(150, 0)) {
1227 _mesa_glsl_error(& @1, state, "#version 150 layout "
1228 "qualifier `%s' used", $1);
1233 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1238 | any_identifier '=' integer_constant
1240 memset(& $$, 0, sizeof($$));
1242 if (match_layout_qualifier("location", $1, state) == 0) {
1243 $$.flags.q.explicit_location = 1;
1248 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1253 if (match_layout_qualifier("index", $1, state) == 0) {
1254 $$.flags.q.explicit_index = 1;
1259 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1264 if ((state->ARB_shading_language_420pack_enable ||
1265 state->ARB_shader_atomic_counters_enable) &&
1266 match_layout_qualifier("binding", $1, state) == 0) {
1267 $$.flags.q.explicit_binding = 1;
1271 if (state->ARB_shader_atomic_counters_enable &&
1272 match_layout_qualifier("offset", $1, state) == 0) {
1273 $$.flags.q.explicit_offset = 1;
1277 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1278 $$.flags.q.max_vertices = 1;
1281 _mesa_glsl_error(& @3, state,
1282 "invalid max_vertices %d specified", $3);
1285 $$.max_vertices = $3;
1286 if (!state->is_version(150, 0)) {
1287 _mesa_glsl_error(& @3, state,
1288 "#version 150 max_vertices qualifier "
1294 static const char *local_size_qualifiers[3] = {
1299 for (int i = 0; i < 3; i++) {
1300 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1303 _mesa_glsl_error(& @3, state,
1304 "invalid %s of %d specified",
1305 local_size_qualifiers[i], $3);
1307 } else if (!state->is_version(430, 0) &&
1308 !state->ARB_compute_shader_enable) {
1309 _mesa_glsl_error(& @3, state,
1310 "%s qualifier requires GLSL 4.30 or "
1311 "ARB_compute_shader",
1312 local_size_qualifiers[i]);
1315 $$.flags.q.local_size |= (1 << i);
1316 $$.local_size[i] = $3;
1322 /* If the identifier didn't match any known layout identifiers,
1326 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1329 } else if (state->ARB_explicit_attrib_location_warn) {
1330 _mesa_glsl_warning(& @1, state,
1331 "GL_ARB_explicit_attrib_location layout "
1332 "identifier `%s' used", $1);
1335 | interface_block_layout_qualifier
1338 /* Layout qualifiers for ARB_uniform_buffer_object. */
1339 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1340 _mesa_glsl_error(& @1, state,
1341 "#version 140 / GL_ARB_uniform_buffer_object "
1342 "layout qualifier `%s' is used", $1);
1343 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1344 _mesa_glsl_warning(& @1, state,
1345 "#version 140 / GL_ARB_uniform_buffer_object "
1346 "layout qualifier `%s' is used", $1);
1351 /* This is a separate language rule because we parse these as tokens
1352 * (due to them being reserved keywords) instead of identifiers like
1353 * most qualifiers. See the any_identifier path of
1354 * layout_qualifier_id for the others.
1356 * Note that since layout qualifiers are case-insensitive in desktop
1357 * GLSL, all of these qualifiers need to be handled as identifiers as
1358 * well (by the any_identifier path of layout_qualifier_id).
1360 interface_block_layout_qualifier:
1363 memset(& $$, 0, sizeof($$));
1364 $$.flags.q.row_major = 1;
1368 memset(& $$, 0, sizeof($$));
1369 $$.flags.q.packed = 1;
1373 interpolation_qualifier:
1376 memset(& $$, 0, sizeof($$));
1377 $$.flags.q.smooth = 1;
1381 memset(& $$, 0, sizeof($$));
1382 $$.flags.q.flat = 1;
1386 memset(& $$, 0, sizeof($$));
1387 $$.flags.q.noperspective = 1;
1392 /* Single qualifiers */
1395 memset(& $$, 0, sizeof($$));
1396 $$.flags.q.invariant = 1;
1398 | auxiliary_storage_qualifier
1400 | interpolation_qualifier
1402 | precision_qualifier
1404 memset(&$$, 0, sizeof($$));
1408 /* Multiple qualifiers:
1409 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1410 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1412 * invariant interpolation auxiliary storage precision ...or...
1413 * layout storage precision
1415 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1416 * side don't contain any that must appear on the left hand side.
1417 * For example, when processing a storage qualifier, we check that there are
1418 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1420 | INVARIANT type_qualifier
1422 if ($2.flags.q.invariant)
1423 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1425 if ($2.has_layout()) {
1426 _mesa_glsl_error(&@1, state,
1427 "\"invariant\" cannot be used with layout(...)");
1431 $$.flags.q.invariant = 1;
1433 | interpolation_qualifier type_qualifier
1435 /* Section 4.3 of the GLSL 1.40 specification states:
1436 * "...qualified with one of these interpolation qualifiers"
1438 * GLSL 1.30 claims to allow "one or more", but insists that:
1439 * "These interpolation qualifiers may only precede the qualifiers in,
1440 * centroid in, out, or centroid out in a declaration."
1442 * ...which means that e.g. smooth can't precede smooth, so there can be
1443 * only one after all, and the 1.40 text is a clarification, not a change.
1445 if ($2.has_interpolation())
1446 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1448 if ($2.has_layout()) {
1449 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1450 "with layout(...)");
1453 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1454 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1455 "after \"invariant\"");
1459 $$.merge_qualifier(&@1, state, $2);
1461 | layout_qualifier type_qualifier
1463 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1464 * used standalone or immediately before a storage qualifier. It cannot
1465 * be used with interpolation qualifiers or invariant. There does not
1466 * appear to be any text indicating that it must come before the storage
1467 * qualifier, but always seems to in examples.
1469 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1470 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1472 if ($2.flags.q.invariant)
1473 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1474 "the \"invariant\" qualifier");
1476 if ($2.has_interpolation()) {
1477 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1478 "interpolation qualifiers");
1482 $$.merge_qualifier(&@1, state, $2);
1484 | auxiliary_storage_qualifier type_qualifier
1486 if ($2.has_auxiliary_storage()) {
1487 _mesa_glsl_error(&@1, state,
1488 "duplicate auxiliary storage qualifier (centroid or sample)");
1491 if (!state->ARB_shading_language_420pack_enable &&
1492 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1493 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1494 "just before storage qualifiers");
1497 $$.merge_qualifier(&@1, state, $2);
1499 | storage_qualifier type_qualifier
1501 /* Section 4.3 of the GLSL 1.20 specification states:
1502 * "Variable declarations may have a storage qualifier specified..."
1503 * 1.30 clarifies this to "may have one storage qualifier".
1505 if ($2.has_storage())
1506 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1508 if (!state->ARB_shading_language_420pack_enable &&
1509 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1510 $2.has_auxiliary_storage())) {
1511 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1512 "invariant, interpolation, layout and auxiliary "
1513 "storage qualifiers");
1517 $$.merge_qualifier(&@1, state, $2);
1519 | precision_qualifier type_qualifier
1521 if ($2.precision != ast_precision_none)
1522 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1524 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1525 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1532 auxiliary_storage_qualifier:
1535 memset(& $$, 0, sizeof($$));
1536 $$.flags.q.centroid = 1;
1540 memset(& $$, 0, sizeof($$));
1541 $$.flags.q.sample = 1;
1543 /* TODO: "patch" also goes here someday. */
1548 memset(& $$, 0, sizeof($$));
1549 $$.flags.q.constant = 1;
1553 memset(& $$, 0, sizeof($$));
1554 $$.flags.q.attribute = 1;
1558 memset(& $$, 0, sizeof($$));
1559 $$.flags.q.varying = 1;
1563 memset(& $$, 0, sizeof($$));
1568 memset(& $$, 0, sizeof($$));
1573 memset(& $$, 0, sizeof($$));
1574 $$.flags.q.uniform = 1;
1582 $$ = new(ctx) ast_array_specifier(yylloc);
1584 | '[' constant_expression ']'
1587 $$ = new(ctx) ast_array_specifier(yylloc, $2);
1589 | array_specifier '[' ']'
1593 if (!state->ARB_arrays_of_arrays_enable) {
1594 _mesa_glsl_error(& @1, state,
1595 "GL_ARB_arrays_of_arrays "
1596 "required for defining arrays of arrays");
1598 _mesa_glsl_error(& @1, state,
1599 "only the outermost array dimension can "
1603 | array_specifier '[' constant_expression ']'
1607 if (!state->ARB_arrays_of_arrays_enable) {
1608 _mesa_glsl_error(& @1, state,
1609 "GL_ARB_arrays_of_arrays "
1610 "required for defining arrays of arrays");
1613 $$->add_dimension($3);
1618 type_specifier_nonarray
1619 | type_specifier_nonarray array_specifier
1622 $$->array_specifier = $2;
1626 type_specifier_nonarray:
1627 basic_type_specifier_nonarray
1630 $$ = new(ctx) ast_type_specifier($1);
1631 $$->set_location(yylloc);
1636 $$ = new(ctx) ast_type_specifier($1);
1637 $$->set_location(yylloc);
1642 $$ = new(ctx) ast_type_specifier($1);
1643 $$->set_location(yylloc);
1647 basic_type_specifier_nonarray:
1648 VOID_TOK { $$ = "void"; }
1649 | FLOAT_TOK { $$ = "float"; }
1650 | INT_TOK { $$ = "int"; }
1651 | UINT_TOK { $$ = "uint"; }
1652 | BOOL_TOK { $$ = "bool"; }
1653 | VEC2 { $$ = "vec2"; }
1654 | VEC3 { $$ = "vec3"; }
1655 | VEC4 { $$ = "vec4"; }
1656 | BVEC2 { $$ = "bvec2"; }
1657 | BVEC3 { $$ = "bvec3"; }
1658 | BVEC4 { $$ = "bvec4"; }
1659 | IVEC2 { $$ = "ivec2"; }
1660 | IVEC3 { $$ = "ivec3"; }
1661 | IVEC4 { $$ = "ivec4"; }
1662 | UVEC2 { $$ = "uvec2"; }
1663 | UVEC3 { $$ = "uvec3"; }
1664 | UVEC4 { $$ = "uvec4"; }
1665 | MAT2X2 { $$ = "mat2"; }
1666 | MAT2X3 { $$ = "mat2x3"; }
1667 | MAT2X4 { $$ = "mat2x4"; }
1668 | MAT3X2 { $$ = "mat3x2"; }
1669 | MAT3X3 { $$ = "mat3"; }
1670 | MAT3X4 { $$ = "mat3x4"; }
1671 | MAT4X2 { $$ = "mat4x2"; }
1672 | MAT4X3 { $$ = "mat4x3"; }
1673 | MAT4X4 { $$ = "mat4"; }
1674 | SAMPLER1D { $$ = "sampler1D"; }
1675 | SAMPLER2D { $$ = "sampler2D"; }
1676 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1677 | SAMPLER3D { $$ = "sampler3D"; }
1678 | SAMPLERCUBE { $$ = "samplerCube"; }
1679 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1680 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1681 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1682 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1683 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1684 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1685 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1686 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1687 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1688 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1689 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1690 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1691 | ISAMPLER1D { $$ = "isampler1D"; }
1692 | ISAMPLER2D { $$ = "isampler2D"; }
1693 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1694 | ISAMPLER3D { $$ = "isampler3D"; }
1695 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1696 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1697 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1698 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1699 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1700 | USAMPLER1D { $$ = "usampler1D"; }
1701 | USAMPLER2D { $$ = "usampler2D"; }
1702 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1703 | USAMPLER3D { $$ = "usampler3D"; }
1704 | USAMPLERCUBE { $$ = "usamplerCube"; }
1705 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1706 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1707 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1708 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1709 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1710 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1711 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1712 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1713 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1714 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1715 | ATOMIC_UINT { $$ = "atomic_uint"; }
1718 precision_qualifier:
1721 state->check_precision_qualifiers_allowed(&@1);
1722 $$ = ast_precision_high;
1726 state->check_precision_qualifiers_allowed(&@1);
1727 $$ = ast_precision_medium;
1731 state->check_precision_qualifiers_allowed(&@1);
1732 $$ = ast_precision_low;
1737 STRUCT any_identifier '{' struct_declaration_list '}'
1740 $$ = new(ctx) ast_struct_specifier($2, $4);
1741 $$->set_location(yylloc);
1742 state->symbols->add_type($2, glsl_type::void_type);
1743 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1745 | STRUCT '{' struct_declaration_list '}'
1748 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1749 $$->set_location(yylloc);
1753 struct_declaration_list:
1757 $1->link.self_link();
1759 | struct_declaration_list struct_declaration
1762 $$->link.insert_before(& $2->link);
1767 fully_specified_type struct_declarator_list ';'
1770 ast_fully_specified_type *const type = $1;
1771 type->set_location(yylloc);
1773 if (type->qualifier.flags.i != 0)
1774 _mesa_glsl_error(&@1, state,
1775 "only precision qualifiers may be applied to "
1776 "structure members");
1778 $$ = new(ctx) ast_declarator_list(type);
1779 $$->set_location(yylloc);
1781 $$->declarations.push_degenerate_list_at_head(& $2->link);
1785 struct_declarator_list:
1789 $1->link.self_link();
1791 | struct_declarator_list ',' struct_declarator
1794 $$->link.insert_before(& $3->link);
1802 $$ = new(ctx) ast_declaration($1, NULL, NULL);
1803 $$->set_location(yylloc);
1805 | any_identifier array_specifier
1808 $$ = new(ctx) ast_declaration($1, $2, 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, 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->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2213 _mesa_glsl_error(& @1, state,
2214 "`in' interface block is not allowed for "
2216 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $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 array_specifier
2310 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2319 $1->link.self_link();
2321 | member_declaration member_list
2324 $2->link.insert_before(& $$->link);
2329 fully_specified_type struct_declarator_list ';'
2332 ast_fully_specified_type *type = $1;
2333 type->set_location(yylloc);
2335 if (type->qualifier.flags.q.attribute) {
2336 _mesa_glsl_error(& @1, state,
2337 "keyword 'attribute' cannot be used with "
2338 "interface block member");
2339 } else if (type->qualifier.flags.q.varying) {
2340 _mesa_glsl_error(& @1, state,
2341 "keyword 'varying' cannot be used with "
2342 "interface block member");
2345 $$ = new(ctx) ast_declarator_list(type);
2346 $$->set_location(yylloc);
2348 $$->declarations.push_degenerate_list_at_head(& $2->link);
2353 layout_qualifier UNIFORM ';'
2355 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2361 | layout_qualifier IN_TOK ';'
2365 switch (state->stage) {
2366 case MESA_SHADER_GEOMETRY: {
2367 if (!$1.flags.q.prim_type) {
2368 _mesa_glsl_error(& @1, state,
2369 "input layout qualifiers must specify a primitive"
2372 /* Make sure this is a valid input primitive type. */
2373 switch ($1.prim_type) {
2376 case GL_LINES_ADJACENCY:
2378 case GL_TRIANGLES_ADJACENCY:
2379 $$ = new(ctx) ast_gs_input_layout(@1, $1.prim_type);
2382 _mesa_glsl_error(&@1, state,
2383 "invalid geometry shader input primitive type");
2389 case MESA_SHADER_COMPUTE: {
2390 if ($1.flags.q.local_size == 0) {
2391 _mesa_glsl_error(& @1, state,
2392 "input layout qualifiers must specify a local "
2395 /* Infer a local_size of 1 for every unspecified dimension */
2396 unsigned local_size[3];
2397 for (int i = 0; i < 3; i++) {
2398 if ($1.flags.q.local_size & (1 << i))
2399 local_size[i] = $1.local_size[i];
2403 $$ = new(ctx) ast_cs_input_layout(@1, local_size);
2408 _mesa_glsl_error(& @1, state,
2409 "input layout qualifiers only valid in "
2410 "geometry and compute shaders");
2415 | layout_qualifier OUT_TOK ';'
2417 if (state->stage != MESA_SHADER_GEOMETRY) {
2418 _mesa_glsl_error(& @1, state,
2419 "out layout qualifiers only valid in "
2420 "geometry shaders");
2422 if ($1.flags.q.prim_type) {
2423 /* Make sure this is a valid output primitive type. */
2424 switch ($1.prim_type) {
2427 case GL_TRIANGLE_STRIP:
2430 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2435 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))