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 /* If the identifier didn't match any known layout identifiers,
1298 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1301 } else if (state->ARB_explicit_attrib_location_warn) {
1302 _mesa_glsl_warning(& @1, state,
1303 "GL_ARB_explicit_attrib_location layout "
1304 "identifier `%s' used", $1);
1307 | interface_block_layout_qualifier
1310 /* Layout qualifiers for ARB_uniform_buffer_object. */
1311 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1312 _mesa_glsl_error(& @1, state,
1313 "#version 140 / GL_ARB_uniform_buffer_object "
1314 "layout qualifier `%s' is used", $1);
1315 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1316 _mesa_glsl_warning(& @1, state,
1317 "#version 140 / GL_ARB_uniform_buffer_object "
1318 "layout qualifier `%s' is used", $1);
1323 /* This is a separate language rule because we parse these as tokens
1324 * (due to them being reserved keywords) instead of identifiers like
1325 * most qualifiers. See the any_identifier path of
1326 * layout_qualifier_id for the others.
1328 * Note that since layout qualifiers are case-insensitive in desktop
1329 * GLSL, all of these qualifiers need to be handled as identifiers as
1330 * well (by the any_identifier path of layout_qualifier_id).
1332 interface_block_layout_qualifier:
1335 memset(& $$, 0, sizeof($$));
1336 $$.flags.q.row_major = 1;
1340 memset(& $$, 0, sizeof($$));
1341 $$.flags.q.packed = 1;
1345 interpolation_qualifier:
1348 memset(& $$, 0, sizeof($$));
1349 $$.flags.q.smooth = 1;
1353 memset(& $$, 0, sizeof($$));
1354 $$.flags.q.flat = 1;
1358 memset(& $$, 0, sizeof($$));
1359 $$.flags.q.noperspective = 1;
1364 /* Single qualifiers */
1367 memset(& $$, 0, sizeof($$));
1368 $$.flags.q.invariant = 1;
1370 | auxiliary_storage_qualifier
1372 | interpolation_qualifier
1374 | precision_qualifier
1376 memset(&$$, 0, sizeof($$));
1380 /* Multiple qualifiers:
1381 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1382 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1384 * invariant interpolation auxiliary storage precision ...or...
1385 * layout storage precision
1387 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1388 * side don't contain any that must appear on the left hand side.
1389 * For example, when processing a storage qualifier, we check that there are
1390 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1392 | INVARIANT type_qualifier
1394 if ($2.flags.q.invariant)
1395 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1397 if ($2.has_layout()) {
1398 _mesa_glsl_error(&@1, state,
1399 "\"invariant\" cannot be used with layout(...)");
1403 $$.flags.q.invariant = 1;
1405 | interpolation_qualifier type_qualifier
1407 /* Section 4.3 of the GLSL 1.40 specification states:
1408 * "...qualified with one of these interpolation qualifiers"
1410 * GLSL 1.30 claims to allow "one or more", but insists that:
1411 * "These interpolation qualifiers may only precede the qualifiers in,
1412 * centroid in, out, or centroid out in a declaration."
1414 * ...which means that e.g. smooth can't precede smooth, so there can be
1415 * only one after all, and the 1.40 text is a clarification, not a change.
1417 if ($2.has_interpolation())
1418 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1420 if ($2.has_layout()) {
1421 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1422 "with layout(...)");
1425 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1426 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1427 "after \"invariant\"");
1431 $$.merge_qualifier(&@1, state, $2);
1433 | layout_qualifier type_qualifier
1435 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1436 * used standalone or immediately before a storage qualifier. It cannot
1437 * be used with interpolation qualifiers or invariant. There does not
1438 * appear to be any text indicating that it must come before the storage
1439 * qualifier, but always seems to in examples.
1441 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1442 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1444 if ($2.flags.q.invariant)
1445 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1446 "the \"invariant\" qualifier");
1448 if ($2.has_interpolation()) {
1449 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1450 "interpolation qualifiers");
1454 $$.merge_qualifier(&@1, state, $2);
1456 | auxiliary_storage_qualifier type_qualifier
1458 if ($2.has_auxiliary_storage()) {
1459 _mesa_glsl_error(&@1, state,
1460 "duplicate auxiliary storage qualifier (centroid or sample)");
1463 if (!state->ARB_shading_language_420pack_enable &&
1464 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1465 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1466 "just before storage qualifiers");
1469 $$.flags.i |= $2.flags.i;
1471 | storage_qualifier type_qualifier
1473 /* Section 4.3 of the GLSL 1.20 specification states:
1474 * "Variable declarations may have a storage qualifier specified..."
1475 * 1.30 clarifies this to "may have one storage qualifier".
1477 if ($2.has_storage())
1478 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1480 if (!state->ARB_shading_language_420pack_enable &&
1481 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1482 $2.has_auxiliary_storage())) {
1483 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1484 "invariant, interpolation, layout and auxiliary "
1485 "storage qualifiers");
1489 $$.merge_qualifier(&@1, state, $2);
1491 | precision_qualifier type_qualifier
1493 if ($2.precision != ast_precision_none)
1494 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1496 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1497 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1504 auxiliary_storage_qualifier:
1507 memset(& $$, 0, sizeof($$));
1508 $$.flags.q.centroid = 1;
1512 memset(& $$, 0, sizeof($$));
1513 $$.flags.q.sample = 1;
1515 /* TODO: "patch" also goes here someday. */
1520 memset(& $$, 0, sizeof($$));
1521 $$.flags.q.constant = 1;
1525 memset(& $$, 0, sizeof($$));
1526 $$.flags.q.attribute = 1;
1530 memset(& $$, 0, sizeof($$));
1531 $$.flags.q.varying = 1;
1535 memset(& $$, 0, sizeof($$));
1540 memset(& $$, 0, sizeof($$));
1545 memset(& $$, 0, sizeof($$));
1546 $$.flags.q.uniform = 1;
1554 $$ = new(ctx) ast_array_specifier(yylloc);
1556 | '[' constant_expression ']'
1559 $$ = new(ctx) ast_array_specifier(yylloc, $2);
1561 | array_specifier '[' ']'
1565 if (!state->ARB_arrays_of_arrays_enable) {
1566 _mesa_glsl_error(& @1, state,
1567 "GL_ARB_arrays_of_arrays "
1568 "required for defining arrays of arrays");
1570 _mesa_glsl_error(& @1, state,
1571 "only the outermost array dimension can "
1575 | array_specifier '[' constant_expression ']'
1579 if (!state->ARB_arrays_of_arrays_enable) {
1580 _mesa_glsl_error(& @1, state,
1581 "GL_ARB_arrays_of_arrays "
1582 "required for defining arrays of arrays");
1585 $$->add_dimension($3);
1590 type_specifier_nonarray
1591 | type_specifier_nonarray array_specifier
1594 $$->array_specifier = $2;
1598 type_specifier_nonarray:
1599 basic_type_specifier_nonarray
1602 $$ = new(ctx) ast_type_specifier($1);
1603 $$->set_location(yylloc);
1608 $$ = new(ctx) ast_type_specifier($1);
1609 $$->set_location(yylloc);
1614 $$ = new(ctx) ast_type_specifier($1);
1615 $$->set_location(yylloc);
1619 basic_type_specifier_nonarray:
1620 VOID_TOK { $$ = "void"; }
1621 | FLOAT_TOK { $$ = "float"; }
1622 | INT_TOK { $$ = "int"; }
1623 | UINT_TOK { $$ = "uint"; }
1624 | BOOL_TOK { $$ = "bool"; }
1625 | VEC2 { $$ = "vec2"; }
1626 | VEC3 { $$ = "vec3"; }
1627 | VEC4 { $$ = "vec4"; }
1628 | BVEC2 { $$ = "bvec2"; }
1629 | BVEC3 { $$ = "bvec3"; }
1630 | BVEC4 { $$ = "bvec4"; }
1631 | IVEC2 { $$ = "ivec2"; }
1632 | IVEC3 { $$ = "ivec3"; }
1633 | IVEC4 { $$ = "ivec4"; }
1634 | UVEC2 { $$ = "uvec2"; }
1635 | UVEC3 { $$ = "uvec3"; }
1636 | UVEC4 { $$ = "uvec4"; }
1637 | MAT2X2 { $$ = "mat2"; }
1638 | MAT2X3 { $$ = "mat2x3"; }
1639 | MAT2X4 { $$ = "mat2x4"; }
1640 | MAT3X2 { $$ = "mat3x2"; }
1641 | MAT3X3 { $$ = "mat3"; }
1642 | MAT3X4 { $$ = "mat3x4"; }
1643 | MAT4X2 { $$ = "mat4x2"; }
1644 | MAT4X3 { $$ = "mat4x3"; }
1645 | MAT4X4 { $$ = "mat4"; }
1646 | SAMPLER1D { $$ = "sampler1D"; }
1647 | SAMPLER2D { $$ = "sampler2D"; }
1648 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1649 | SAMPLER3D { $$ = "sampler3D"; }
1650 | SAMPLERCUBE { $$ = "samplerCube"; }
1651 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1652 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1653 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1654 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1655 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1656 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1657 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1658 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1659 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1660 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1661 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1662 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1663 | ISAMPLER1D { $$ = "isampler1D"; }
1664 | ISAMPLER2D { $$ = "isampler2D"; }
1665 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1666 | ISAMPLER3D { $$ = "isampler3D"; }
1667 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1668 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1669 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1670 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1671 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1672 | USAMPLER1D { $$ = "usampler1D"; }
1673 | USAMPLER2D { $$ = "usampler2D"; }
1674 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1675 | USAMPLER3D { $$ = "usampler3D"; }
1676 | USAMPLERCUBE { $$ = "usamplerCube"; }
1677 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1678 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1679 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1680 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1681 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1682 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1683 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1684 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1685 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1686 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1687 | ATOMIC_UINT { $$ = "atomic_uint"; }
1690 precision_qualifier:
1693 state->check_precision_qualifiers_allowed(&@1);
1694 $$ = ast_precision_high;
1698 state->check_precision_qualifiers_allowed(&@1);
1699 $$ = ast_precision_medium;
1703 state->check_precision_qualifiers_allowed(&@1);
1704 $$ = ast_precision_low;
1709 STRUCT any_identifier '{' struct_declaration_list '}'
1712 $$ = new(ctx) ast_struct_specifier($2, $4);
1713 $$->set_location(yylloc);
1714 state->symbols->add_type($2, glsl_type::void_type);
1715 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1717 | STRUCT '{' struct_declaration_list '}'
1720 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1721 $$->set_location(yylloc);
1725 struct_declaration_list:
1729 $1->link.self_link();
1731 | struct_declaration_list struct_declaration
1734 $$->link.insert_before(& $2->link);
1739 fully_specified_type struct_declarator_list ';'
1742 ast_fully_specified_type *const type = $1;
1743 type->set_location(yylloc);
1745 if (type->qualifier.flags.i != 0)
1746 _mesa_glsl_error(&@1, state,
1747 "only precision qualifiers may be applied to "
1748 "structure members");
1750 $$ = new(ctx) ast_declarator_list(type);
1751 $$->set_location(yylloc);
1753 $$->declarations.push_degenerate_list_at_head(& $2->link);
1757 struct_declarator_list:
1761 $1->link.self_link();
1763 | struct_declarator_list ',' struct_declarator
1766 $$->link.insert_before(& $3->link);
1774 $$ = new(ctx) ast_declaration($1, NULL, NULL);
1775 $$->set_location(yylloc);
1777 | any_identifier array_specifier
1780 $$ = new(ctx) ast_declaration($1, $2, NULL);
1781 $$->set_location(yylloc);
1786 assignment_expression
1787 | '{' initializer_list '}'
1791 | '{' initializer_list ',' '}'
1801 $$ = new(ctx) ast_aggregate_initializer();
1802 $$->set_location(yylloc);
1803 $$->expressions.push_tail(& $1->link);
1805 | initializer_list ',' initializer
1807 $1->expressions.push_tail(& $3->link);
1811 declaration_statement:
1815 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1818 compound_statement { $$ = (ast_node *) $1; }
1823 declaration_statement
1824 | expression_statement
1825 | selection_statement
1827 | iteration_statement
1835 $$ = new(ctx) ast_compound_statement(true, NULL);
1836 $$->set_location(yylloc);
1840 state->symbols->push_scope();
1845 $$ = new(ctx) ast_compound_statement(true, $3);
1846 $$->set_location(yylloc);
1847 state->symbols->pop_scope();
1851 statement_no_new_scope:
1852 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1856 compound_statement_no_new_scope:
1860 $$ = new(ctx) ast_compound_statement(false, NULL);
1861 $$->set_location(yylloc);
1863 | '{' statement_list '}'
1866 $$ = new(ctx) ast_compound_statement(false, $2);
1867 $$->set_location(yylloc);
1875 _mesa_glsl_error(& @1, state, "<nil> statement");
1880 $$->link.self_link();
1882 | statement_list statement
1885 _mesa_glsl_error(& @2, state, "<nil> statement");
1889 $$->link.insert_before(& $2->link);
1893 expression_statement:
1897 $$ = new(ctx) ast_expression_statement(NULL);
1898 $$->set_location(yylloc);
1903 $$ = new(ctx) ast_expression_statement($1);
1904 $$->set_location(yylloc);
1908 selection_statement:
1909 IF '(' expression ')' selection_rest_statement
1911 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1913 $$->set_location(yylloc);
1917 selection_rest_statement:
1918 statement ELSE statement
1920 $$.then_statement = $1;
1921 $$.else_statement = $3;
1923 | statement %prec THEN
1925 $$.then_statement = $1;
1926 $$.else_statement = NULL;
1933 $$ = (ast_node *) $1;
1935 | fully_specified_type any_identifier '=' initializer
1938 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1939 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1940 decl->set_location(yylloc);
1941 declarator->set_location(yylloc);
1943 declarator->declarations.push_tail(&decl->link);
1949 * siwtch_statement grammar is based on the syntax described in the body
1950 * of the GLSL spec, not in it's appendix!!!
1953 SWITCH '(' expression ')' switch_body
1955 $$ = new(state) ast_switch_statement($3, $5);
1956 $$->set_location(yylloc);
1963 $$ = new(state) ast_switch_body(NULL);
1964 $$->set_location(yylloc);
1966 | '{' case_statement_list '}'
1968 $$ = new(state) ast_switch_body($2);
1969 $$->set_location(yylloc);
1976 $$ = new(state) ast_case_label($2);
1977 $$->set_location(yylloc);
1981 $$ = new(state) ast_case_label(NULL);
1982 $$->set_location(yylloc);
1989 ast_case_label_list *labels = new(state) ast_case_label_list();
1991 labels->labels.push_tail(& $1->link);
1993 $$->set_location(yylloc);
1995 | case_label_list case_label
1998 $$->labels.push_tail(& $2->link);
2003 case_label_list statement
2005 ast_case_statement *stmts = new(state) ast_case_statement($1);
2006 stmts->set_location(yylloc);
2008 stmts->stmts.push_tail(& $2->link);
2011 | case_statement statement
2014 $$->stmts.push_tail(& $2->link);
2018 case_statement_list:
2021 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2022 cases->set_location(yylloc);
2024 cases->cases.push_tail(& $1->link);
2027 | case_statement_list case_statement
2030 $$->cases.push_tail(& $2->link);
2034 iteration_statement:
2035 WHILE '(' condition ')' statement_no_new_scope
2038 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2039 NULL, $3, NULL, $5);
2040 $$->set_location(yylloc);
2042 | DO statement WHILE '(' expression ')' ';'
2045 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2046 NULL, $5, NULL, $2);
2047 $$->set_location(yylloc);
2049 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2052 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2053 $3, $4.cond, $4.rest, $6);
2054 $$->set_location(yylloc);
2059 expression_statement
2060 | declaration_statement
2077 | conditionopt ';' expression
2084 // Grammar Note: No 'goto'. Gotos are not supported.
2089 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2090 $$->set_location(yylloc);
2095 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2096 $$->set_location(yylloc);
2101 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2102 $$->set_location(yylloc);
2104 | RETURN expression ';'
2107 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2108 $$->set_location(yylloc);
2110 | DISCARD ';' // Fragment shader only.
2113 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2114 $$->set_location(yylloc);
2118 external_declaration:
2119 function_definition { $$ = $1; }
2120 | declaration { $$ = $1; }
2121 | pragma_statement { $$ = NULL; }
2122 | layout_defaults { $$ = $1; }
2125 function_definition:
2126 function_prototype compound_statement_no_new_scope
2129 $$ = new(ctx) ast_function_definition();
2130 $$->set_location(yylloc);
2134 state->symbols->pop_scope();
2138 /* layout_qualifieropt is packed into this rule */
2140 basic_interface_block
2144 | layout_qualifier basic_interface_block
2146 ast_interface_block *block = $2;
2147 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2154 basic_interface_block:
2155 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2157 ast_interface_block *const block = $6;
2159 block->block_name = $2;
2160 block->declarations.push_degenerate_list_at_head(& $4->link);
2162 if ($1.flags.q.uniform) {
2163 if (!state->has_uniform_buffer_objects()) {
2164 _mesa_glsl_error(& @1, state,
2165 "#version 140 / GL_ARB_uniform_buffer_object "
2166 "required for defining uniform blocks");
2167 } else if (state->ARB_uniform_buffer_object_warn) {
2168 _mesa_glsl_warning(& @1, state,
2169 "#version 140 / GL_ARB_uniform_buffer_object "
2170 "required for defining uniform blocks");
2173 if (state->es_shader || state->language_version < 150) {
2174 _mesa_glsl_error(& @1, state,
2175 "#version 150 required for using "
2176 "interface blocks");
2180 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2181 * "It is illegal to have an input block in a vertex shader
2182 * or an output block in a fragment shader"
2184 if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) {
2185 _mesa_glsl_error(& @1, state,
2186 "`in' interface block is not allowed for "
2188 } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) {
2189 _mesa_glsl_error(& @1, state,
2190 "`out' interface block is not allowed for "
2191 "a fragment shader");
2194 /* Since block arrays require names, and both features are added in
2195 * the same language versions, we don't have to explicitly
2196 * version-check both things.
2198 if (block->instance_name != NULL) {
2199 state->check_version(150, 300, & @1, "interface blocks with "
2200 "an instance name are not allowed");
2203 unsigned interface_type_mask;
2204 struct ast_type_qualifier temp_type_qualifier;
2206 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2207 * to ignore other irrelevant flags like interpolation qualifiers.
2209 temp_type_qualifier.flags.i = 0;
2210 temp_type_qualifier.flags.q.uniform = true;
2211 temp_type_qualifier.flags.q.in = true;
2212 temp_type_qualifier.flags.q.out = true;
2213 interface_type_mask = temp_type_qualifier.flags.i;
2215 /* Get the block's interface qualifier. The interface_qualifier
2216 * production rule guarantees that only one bit will be set (and
2217 * it will be in/out/uniform).
2219 unsigned block_interface_qualifier = $1.flags.i;
2221 block->layout.flags.i |= block_interface_qualifier;
2223 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2224 ast_type_qualifier& qualifier = member->type->qualifier;
2225 if ((qualifier.flags.i & interface_type_mask) == 0) {
2226 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2227 * "If no optional qualifier is used in a member declaration, the
2228 * qualifier of the variable is just in, out, or uniform as declared
2229 * by interface-qualifier."
2231 qualifier.flags.i |= block_interface_qualifier;
2232 } else if ((qualifier.flags.i & interface_type_mask) !=
2233 block_interface_qualifier) {
2234 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2235 * "If optional qualifiers are used, they can include interpolation
2236 * and storage qualifiers and they must declare an input, output,
2237 * or uniform variable consistent with the interface qualifier of
2240 _mesa_glsl_error(& @1, state,
2241 "uniform/in/out qualifier on "
2242 "interface block member does not match "
2243 "the interface block");
2251 interface_qualifier:
2254 memset(& $$, 0, sizeof($$));
2259 memset(& $$, 0, sizeof($$));
2264 memset(& $$, 0, sizeof($$));
2265 $$.flags.q.uniform = 1;
2272 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2277 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2280 | NEW_IDENTIFIER array_specifier
2282 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2291 $1->link.self_link();
2293 | member_declaration member_list
2296 $2->link.insert_before(& $$->link);
2301 fully_specified_type struct_declarator_list ';'
2304 ast_fully_specified_type *type = $1;
2305 type->set_location(yylloc);
2307 if (type->qualifier.flags.q.attribute) {
2308 _mesa_glsl_error(& @1, state,
2309 "keyword 'attribute' cannot be used with "
2310 "interface block member");
2311 } else if (type->qualifier.flags.q.varying) {
2312 _mesa_glsl_error(& @1, state,
2313 "keyword 'varying' cannot be used with "
2314 "interface block member");
2317 $$ = new(ctx) ast_declarator_list(type);
2318 $$->set_location(yylloc);
2320 $$->declarations.push_degenerate_list_at_head(& $2->link);
2325 layout_qualifier UNIFORM ';'
2327 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2333 | layout_qualifier IN_TOK ';'
2337 if (state->stage != MESA_SHADER_GEOMETRY) {
2338 _mesa_glsl_error(& @1, state,
2339 "input layout qualifiers only valid in "
2340 "geometry shaders");
2341 } else if (!$1.flags.q.prim_type) {
2342 _mesa_glsl_error(& @1, state,
2343 "input layout qualifiers must specify a primitive"
2346 /* Make sure this is a valid input primitive type. */
2347 switch ($1.prim_type) {
2350 case GL_LINES_ADJACENCY:
2352 case GL_TRIANGLES_ADJACENCY:
2353 $$ = new(ctx) ast_gs_input_layout(@1, $1.prim_type);
2356 _mesa_glsl_error(&@1, state,
2357 "invalid geometry shader input primitive type");
2363 | layout_qualifier OUT_TOK ';'
2365 if (state->stage != MESA_SHADER_GEOMETRY) {
2366 _mesa_glsl_error(& @1, state,
2367 "out layout qualifiers only valid in "
2368 "geometry shaders");
2370 if ($1.flags.q.prim_type) {
2371 /* Make sure this is a valid output primitive type. */
2372 switch ($1.prim_type) {
2375 case GL_TRIANGLE_STRIP:
2378 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2383 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))