3 * Copyright © 2008, 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
30 #include "glsl_parser_extras.h"
31 #include "glsl_types.h"
32 #include "main/context.h"
36 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
38 _mesa_glsl_error(loc, st, "%s", msg);
42 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
44 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
47 static bool match_layout_qualifier(const char *s1, const char *s2,
48 _mesa_glsl_parse_state *state)
50 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
52 * "The tokens in any layout-qualifier-id-list ... are not case
53 * sensitive, unless explicitly noted otherwise."
55 * The text "unless explicitly noted otherwise" appears to be
56 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
59 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
62 * "As for other identifiers, they are case sensitive."
64 * So we need to do a case-sensitive or a case-insensitive match,
65 * depending on whether we are compiling for GLSL ES.
68 return strcmp(s1, s2);
70 return strcasecmp(s1, s2);
88 %lex-param {struct _mesa_glsl_parse_state *state}
89 %parse-param {struct _mesa_glsl_parse_state *state}
94 const char *identifier;
96 struct ast_type_qualifier type_qualifier;
99 ast_type_specifier *type_specifier;
100 ast_fully_specified_type *fully_specified_type;
101 ast_function *function;
102 ast_parameter_declarator *parameter_declarator;
103 ast_function_definition *function_definition;
104 ast_compound_statement *compound_statement;
105 ast_expression *expression;
106 ast_declarator_list *declarator_list;
107 ast_struct_specifier *struct_specifier;
108 ast_declaration *declaration;
109 ast_switch_body *switch_body;
110 ast_case_label *case_label;
111 ast_case_label_list *case_label_list;
112 ast_case_statement *case_statement;
113 ast_case_statement_list *case_statement_list;
114 ast_interface_block *interface_block;
118 ast_expression *rest;
119 } for_rest_statement;
122 ast_node *then_statement;
123 ast_node *else_statement;
124 } selection_rest_statement;
127 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
128 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
129 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
130 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
131 %token NOPERSPECTIVE FLAT SMOOTH
132 %token MAT2X2 MAT2X3 MAT2X4
133 %token MAT3X2 MAT3X3 MAT3X4
134 %token MAT4X2 MAT4X3 MAT4X4
135 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
136 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
137 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
138 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
139 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
140 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
141 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
142 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
143 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
144 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
145 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
146 %token SAMPLEREXTERNALOES
148 %token STRUCT VOID_TOK WHILE
149 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
150 %type <identifier> any_identifier
151 %type <interface_block> instance_name_opt
152 %token <real> FLOATCONSTANT
153 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
154 %token <identifier> FIELD_SELECTION
155 %token LEFT_OP RIGHT_OP
156 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
157 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
158 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
161 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
163 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
164 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
165 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
166 %token PRAGMA_INVARIANT_ALL
169 /* Reserved words that are not actually used in the grammar.
171 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
172 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
173 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
174 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
176 %token SIZEOF CAST NAMESPACE USING
177 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE PATCH SAMPLE
182 %token COMMON PARTITION ACTIVE FILTER
183 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
184 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
185 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
186 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
187 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
190 %type <identifier> variable_identifier
191 %type <node> statement
192 %type <node> statement_list
193 %type <node> simple_statement
194 %type <n> precision_qualifier
195 %type <type_qualifier> type_qualifier
196 %type <type_qualifier> auxiliary_storage_qualifier
197 %type <type_qualifier> storage_qualifier
198 %type <type_qualifier> interpolation_qualifier
199 %type <type_qualifier> layout_qualifier
200 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
201 %type <type_qualifier> interface_block_layout_qualifier
202 %type <type_qualifier> interface_qualifier
203 %type <type_specifier> type_specifier
204 %type <type_specifier> type_specifier_nonarray
205 %type <identifier> basic_type_specifier_nonarray
206 %type <fully_specified_type> fully_specified_type
207 %type <function> function_prototype
208 %type <function> function_header
209 %type <function> function_header_with_parameters
210 %type <function> function_declarator
211 %type <parameter_declarator> parameter_declarator
212 %type <parameter_declarator> parameter_declaration
213 %type <type_qualifier> parameter_qualifier
214 %type <type_qualifier> parameter_direction_qualifier
215 %type <type_specifier> parameter_type_specifier
216 %type <function_definition> function_definition
217 %type <compound_statement> compound_statement_no_new_scope
218 %type <compound_statement> compound_statement
219 %type <node> statement_no_new_scope
220 %type <node> expression_statement
221 %type <expression> expression
222 %type <expression> primary_expression
223 %type <expression> assignment_expression
224 %type <expression> conditional_expression
225 %type <expression> logical_or_expression
226 %type <expression> logical_xor_expression
227 %type <expression> logical_and_expression
228 %type <expression> inclusive_or_expression
229 %type <expression> exclusive_or_expression
230 %type <expression> and_expression
231 %type <expression> equality_expression
232 %type <expression> relational_expression
233 %type <expression> shift_expression
234 %type <expression> additive_expression
235 %type <expression> multiplicative_expression
236 %type <expression> unary_expression
237 %type <expression> constant_expression
238 %type <expression> integer_expression
239 %type <expression> postfix_expression
240 %type <expression> function_call_header_with_parameters
241 %type <expression> function_call_header_no_parameters
242 %type <expression> function_call_header
243 %type <expression> function_call_generic
244 %type <expression> function_call_or_method
245 %type <expression> function_call
246 %type <expression> method_call_generic
247 %type <expression> method_call_header_with_parameters
248 %type <expression> method_call_header_no_parameters
249 %type <expression> method_call_header
250 %type <n> assignment_operator
251 %type <n> unary_operator
252 %type <expression> function_identifier
253 %type <node> external_declaration
254 %type <declarator_list> init_declarator_list
255 %type <declarator_list> single_declaration
256 %type <expression> initializer
257 %type <expression> initializer_list
258 %type <node> declaration
259 %type <node> declaration_statement
260 %type <node> jump_statement
261 %type <node> interface_block
262 %type <interface_block> basic_interface_block
263 %type <struct_specifier> struct_specifier
264 %type <declarator_list> struct_declaration_list
265 %type <declarator_list> struct_declaration
266 %type <declaration> struct_declarator
267 %type <declaration> struct_declarator_list
268 %type <declarator_list> member_list
269 %type <declarator_list> member_declaration
270 %type <node> selection_statement
271 %type <selection_rest_statement> selection_rest_statement
272 %type <node> switch_statement
273 %type <switch_body> switch_body
274 %type <case_label_list> case_label_list
275 %type <case_label> case_label
276 %type <case_statement> case_statement
277 %type <case_statement_list> case_statement_list
278 %type <node> iteration_statement
279 %type <node> condition
280 %type <node> conditionopt
281 %type <node> for_init_statement
282 %type <for_rest_statement> for_rest_statement
283 %type <n> integer_constant
284 %type <node> layout_defaults
290 version_statement extension_statement_list
292 _mesa_glsl_initialize_types(state);
294 external_declaration_list
296 delete state->symbols;
297 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
298 _mesa_glsl_initialize_types(state);
303 /* blank - no #version specified: defaults are already set */
304 | VERSION_TOK INTCONSTANT EOL
306 state->process_version_directive(&@2, $2, NULL);
311 | VERSION_TOK INTCONSTANT any_identifier EOL
313 state->process_version_directive(&@2, $2, $3);
322 | PRAGMA_DEBUG_OFF EOL
323 | PRAGMA_OPTIMIZE_ON EOL
324 | PRAGMA_OPTIMIZE_OFF EOL
325 | PRAGMA_INVARIANT_ALL EOL
327 if (!state->is_version(120, 100)) {
328 _mesa_glsl_warning(& @1, state,
329 "pragma `invariant(all)' not supported in %s "
330 "(GLSL ES 1.00 or GLSL 1.20 required)",
331 state->get_version_string());
333 state->all_invariant = true;
338 extension_statement_list:
340 | extension_statement_list extension_statement
350 EXTENSION any_identifier COLON any_identifier EOL
352 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
358 external_declaration_list:
361 /* FINISHME: The NULL test is required because pragmas are set to
362 * FINISHME: NULL. (See production rule for external_declaration.)
365 state->translation_unit.push_tail(& $1->link);
367 | external_declaration_list external_declaration
369 /* FINISHME: The NULL test is required because pragmas are set to
370 * FINISHME: NULL. (See production rule for external_declaration.)
373 state->translation_unit.push_tail(& $2->link);
386 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
387 $$->set_location(yylloc);
388 $$->primary_expression.identifier = $1;
393 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
394 $$->set_location(yylloc);
395 $$->primary_expression.int_constant = $1;
400 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
401 $$->set_location(yylloc);
402 $$->primary_expression.uint_constant = $1;
407 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
408 $$->set_location(yylloc);
409 $$->primary_expression.float_constant = $1;
414 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
415 $$->set_location(yylloc);
416 $$->primary_expression.bool_constant = $1;
426 | postfix_expression '[' integer_expression ']'
429 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
430 $$->set_location(yylloc);
436 | postfix_expression '.' any_identifier
439 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
440 $$->set_location(yylloc);
441 $$->primary_expression.identifier = $3;
443 | postfix_expression INC_OP
446 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
447 $$->set_location(yylloc);
449 | postfix_expression DEC_OP
452 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
453 $$->set_location(yylloc);
462 function_call_or_method
465 function_call_or_method:
466 function_call_generic
467 | postfix_expression '.' method_call_generic
470 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
471 $$->set_location(yylloc);
475 function_call_generic:
476 function_call_header_with_parameters ')'
477 | function_call_header_no_parameters ')'
480 function_call_header_no_parameters:
481 function_call_header VOID_TOK
482 | function_call_header
485 function_call_header_with_parameters:
486 function_call_header assignment_expression
489 $$->set_location(yylloc);
490 $$->expressions.push_tail(& $2->link);
492 | function_call_header_with_parameters ',' assignment_expression
495 $$->set_location(yylloc);
496 $$->expressions.push_tail(& $3->link);
500 // Grammar Note: Constructors look like functions, but lexical
501 // analysis recognized most of them as keywords. They are now
502 // recognized through "type_specifier".
503 function_call_header:
504 function_identifier '('
511 $$ = new(ctx) ast_function_expression($1);
512 $$->set_location(yylloc);
514 | variable_identifier
517 ast_expression *callee = new(ctx) ast_expression($1);
518 $$ = new(ctx) ast_function_expression(callee);
519 $$->set_location(yylloc);
524 ast_expression *callee = new(ctx) ast_expression($1);
525 $$ = new(ctx) ast_function_expression(callee);
526 $$->set_location(yylloc);
531 method_call_header_with_parameters ')'
532 | method_call_header_no_parameters ')'
535 method_call_header_no_parameters:
536 method_call_header VOID_TOK
540 method_call_header_with_parameters:
541 method_call_header assignment_expression
544 $$->set_location(yylloc);
545 $$->expressions.push_tail(& $2->link);
547 | method_call_header_with_parameters ',' assignment_expression
550 $$->set_location(yylloc);
551 $$->expressions.push_tail(& $3->link);
555 // Grammar Note: Constructors look like methods, but lexical
556 // analysis recognized most of them as keywords. They are now
557 // recognized through "type_specifier".
559 variable_identifier '('
562 ast_expression *callee = new(ctx) ast_expression($1);
563 $$ = new(ctx) ast_function_expression(callee);
564 $$->set_location(yylloc);
568 // Grammar Note: No traditional style type casts.
571 | INC_OP unary_expression
574 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
575 $$->set_location(yylloc);
577 | DEC_OP unary_expression
580 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
581 $$->set_location(yylloc);
583 | unary_operator unary_expression
586 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
587 $$->set_location(yylloc);
591 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
593 '+' { $$ = ast_plus; }
594 | '-' { $$ = ast_neg; }
595 | '!' { $$ = ast_logic_not; }
596 | '~' { $$ = ast_bit_not; }
599 multiplicative_expression:
601 | multiplicative_expression '*' unary_expression
604 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
605 $$->set_location(yylloc);
607 | multiplicative_expression '/' unary_expression
610 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
611 $$->set_location(yylloc);
613 | multiplicative_expression '%' unary_expression
616 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
617 $$->set_location(yylloc);
622 multiplicative_expression
623 | additive_expression '+' multiplicative_expression
626 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
627 $$->set_location(yylloc);
629 | additive_expression '-' multiplicative_expression
632 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
633 $$->set_location(yylloc);
639 | shift_expression LEFT_OP additive_expression
642 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
643 $$->set_location(yylloc);
645 | shift_expression RIGHT_OP additive_expression
648 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
649 $$->set_location(yylloc);
653 relational_expression:
655 | relational_expression '<' shift_expression
658 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
659 $$->set_location(yylloc);
661 | relational_expression '>' shift_expression
664 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
665 $$->set_location(yylloc);
667 | relational_expression LE_OP shift_expression
670 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
671 $$->set_location(yylloc);
673 | relational_expression GE_OP shift_expression
676 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
677 $$->set_location(yylloc);
682 relational_expression
683 | equality_expression EQ_OP relational_expression
686 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
687 $$->set_location(yylloc);
689 | equality_expression NE_OP relational_expression
692 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
693 $$->set_location(yylloc);
699 | and_expression '&' equality_expression
702 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
703 $$->set_location(yylloc);
707 exclusive_or_expression:
709 | exclusive_or_expression '^' and_expression
712 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
713 $$->set_location(yylloc);
717 inclusive_or_expression:
718 exclusive_or_expression
719 | inclusive_or_expression '|' exclusive_or_expression
722 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
723 $$->set_location(yylloc);
727 logical_and_expression:
728 inclusive_or_expression
729 | logical_and_expression AND_OP inclusive_or_expression
732 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
733 $$->set_location(yylloc);
737 logical_xor_expression:
738 logical_and_expression
739 | logical_xor_expression XOR_OP logical_and_expression
742 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
743 $$->set_location(yylloc);
747 logical_or_expression:
748 logical_xor_expression
749 | logical_or_expression OR_OP logical_xor_expression
752 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
753 $$->set_location(yylloc);
757 conditional_expression:
758 logical_or_expression
759 | logical_or_expression '?' expression ':' assignment_expression
762 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
763 $$->set_location(yylloc);
767 assignment_expression:
768 conditional_expression
769 | unary_expression assignment_operator assignment_expression
772 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
773 $$->set_location(yylloc);
778 '=' { $$ = ast_assign; }
779 | MUL_ASSIGN { $$ = ast_mul_assign; }
780 | DIV_ASSIGN { $$ = ast_div_assign; }
781 | MOD_ASSIGN { $$ = ast_mod_assign; }
782 | ADD_ASSIGN { $$ = ast_add_assign; }
783 | SUB_ASSIGN { $$ = ast_sub_assign; }
784 | LEFT_ASSIGN { $$ = ast_ls_assign; }
785 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
786 | AND_ASSIGN { $$ = ast_and_assign; }
787 | XOR_ASSIGN { $$ = ast_xor_assign; }
788 | OR_ASSIGN { $$ = ast_or_assign; }
792 assignment_expression
796 | expression ',' assignment_expression
799 if ($1->oper != ast_sequence) {
800 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
801 $$->set_location(yylloc);
802 $$->expressions.push_tail(& $1->link);
807 $$->expressions.push_tail(& $3->link);
812 conditional_expression
816 function_prototype ';'
818 state->symbols->pop_scope();
821 | init_declarator_list ';'
825 | PRECISION precision_qualifier type_specifier ';'
827 $3->default_precision = $2;
837 function_declarator ')'
842 | function_header_with_parameters
845 function_header_with_parameters:
846 function_header parameter_declaration
849 $$->parameters.push_tail(& $2->link);
851 | function_header_with_parameters ',' parameter_declaration
854 $$->parameters.push_tail(& $3->link);
859 fully_specified_type variable_identifier '('
862 $$ = new(ctx) ast_function();
863 $$->set_location(yylloc);
864 $$->return_type = $1;
867 state->symbols->add_function(new(state) ir_function($2));
868 state->symbols->push_scope();
872 parameter_declarator:
873 type_specifier any_identifier
876 $$ = new(ctx) ast_parameter_declarator();
877 $$->set_location(yylloc);
878 $$->type = new(ctx) ast_fully_specified_type();
879 $$->type->set_location(yylloc);
880 $$->type->specifier = $1;
883 | type_specifier any_identifier '[' constant_expression ']'
886 $$ = new(ctx) ast_parameter_declarator();
887 $$->set_location(yylloc);
888 $$->type = new(ctx) ast_fully_specified_type();
889 $$->type->set_location(yylloc);
890 $$->type->specifier = $1;
897 parameter_declaration:
898 parameter_qualifier parameter_declarator
901 $$->type->qualifier = $1;
903 | parameter_qualifier parameter_type_specifier
906 $$ = new(ctx) ast_parameter_declarator();
907 $$->set_location(yylloc);
908 $$->type = new(ctx) ast_fully_specified_type();
909 $$->type->qualifier = $1;
910 $$->type->specifier = $2;
917 memset(& $$, 0, sizeof($$));
919 | CONST_TOK parameter_qualifier
921 if ($2.flags.q.constant)
922 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
925 $$.flags.q.constant = 1;
927 | parameter_direction_qualifier parameter_qualifier
929 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
930 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
932 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
933 _mesa_glsl_error(&@1, state, "const must be specified before "
937 $$.merge_qualifier(&@1, state, $2);
939 | precision_qualifier parameter_qualifier
941 if ($2.precision != ast_precision_none)
942 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
944 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
945 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
951 parameter_direction_qualifier:
954 memset(& $$, 0, sizeof($$));
959 memset(& $$, 0, sizeof($$));
964 memset(& $$, 0, sizeof($$));
970 parameter_type_specifier:
974 init_declarator_list:
976 | init_declarator_list ',' any_identifier
979 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
980 decl->set_location(yylloc);
983 $$->declarations.push_tail(&decl->link);
984 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
986 | init_declarator_list ',' any_identifier '[' ']'
989 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
990 decl->set_location(yylloc);
993 $$->declarations.push_tail(&decl->link);
994 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
996 | init_declarator_list ',' any_identifier '[' constant_expression ']'
999 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
1000 decl->set_location(yylloc);
1003 $$->declarations.push_tail(&decl->link);
1004 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1006 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
1009 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
1010 decl->set_location(yylloc);
1013 $$->declarations.push_tail(&decl->link);
1014 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1015 if ($7->oper == ast_aggregate) {
1016 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1017 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
1018 _mesa_ast_set_aggregate_type(type, ai, state);
1021 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
1024 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
1025 decl->set_location(yylloc);
1028 $$->declarations.push_tail(&decl->link);
1029 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1030 if ($8->oper == ast_aggregate) {
1031 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
1032 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
1033 _mesa_ast_set_aggregate_type(type, ai, state);
1036 | init_declarator_list ',' any_identifier '=' initializer
1039 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1040 decl->set_location(yylloc);
1043 $$->declarations.push_tail(&decl->link);
1044 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1045 if ($5->oper == ast_aggregate) {
1046 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
1047 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1052 // Grammar Note: No 'enum', or 'typedef'.
1054 fully_specified_type
1057 /* Empty declaration list is valid. */
1058 $$ = new(ctx) ast_declarator_list($1);
1059 $$->set_location(yylloc);
1061 | fully_specified_type any_identifier
1064 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1066 $$ = new(ctx) ast_declarator_list($1);
1067 $$->set_location(yylloc);
1068 $$->declarations.push_tail(&decl->link);
1070 | fully_specified_type any_identifier '[' ']'
1073 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1075 $$ = new(ctx) ast_declarator_list($1);
1076 $$->set_location(yylloc);
1077 $$->declarations.push_tail(&decl->link);
1079 | fully_specified_type any_identifier '[' constant_expression ']'
1082 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1084 $$ = new(ctx) ast_declarator_list($1);
1085 $$->set_location(yylloc);
1086 $$->declarations.push_tail(&decl->link);
1088 | fully_specified_type any_identifier '[' ']' '=' initializer
1091 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1093 $$ = new(ctx) ast_declarator_list($1);
1094 $$->set_location(yylloc);
1095 $$->declarations.push_tail(&decl->link);
1096 if ($6->oper == ast_aggregate) {
1097 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1098 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1099 _mesa_ast_set_aggregate_type(type, ai, state);
1102 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1105 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1107 $$ = new(ctx) ast_declarator_list($1);
1108 $$->set_location(yylloc);
1109 $$->declarations.push_tail(&decl->link);
1110 if ($7->oper == ast_aggregate) {
1111 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1112 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1113 _mesa_ast_set_aggregate_type(type, ai, state);
1116 | fully_specified_type any_identifier '=' initializer
1119 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1121 $$ = new(ctx) ast_declarator_list($1);
1122 $$->set_location(yylloc);
1123 $$->declarations.push_tail(&decl->link);
1124 if ($4->oper == ast_aggregate) {
1125 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1128 | INVARIANT variable_identifier // Vertex only.
1131 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1133 $$ = new(ctx) ast_declarator_list(NULL);
1134 $$->set_location(yylloc);
1135 $$->invariant = true;
1137 $$->declarations.push_tail(&decl->link);
1141 fully_specified_type:
1145 $$ = new(ctx) ast_fully_specified_type();
1146 $$->set_location(yylloc);
1149 | type_qualifier type_specifier
1152 $$ = new(ctx) ast_fully_specified_type();
1153 $$->set_location(yylloc);
1160 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1166 layout_qualifier_id_list:
1168 | layout_qualifier_id_list ',' layout_qualifier_id
1171 if (!$$.merge_qualifier(& @3, state, $3)) {
1178 INTCONSTANT { $$ = $1; }
1179 | UINTCONSTANT { $$ = $1; }
1182 layout_qualifier_id:
1185 memset(& $$, 0, sizeof($$));
1187 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1188 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1189 state->is_version(150, 0))) {
1190 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1191 $$.flags.q.origin_upper_left = 1;
1192 } else if (match_layout_qualifier($1, "pixel_center_integer",
1194 $$.flags.q.pixel_center_integer = 1;
1197 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1198 _mesa_glsl_warning(& @1, state,
1199 "GL_ARB_fragment_coord_conventions layout "
1200 "identifier `%s' used", $1);
1204 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1206 (state->AMD_conservative_depth_enable ||
1207 state->ARB_conservative_depth_enable)) {
1208 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1209 $$.flags.q.depth_any = 1;
1210 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1211 $$.flags.q.depth_greater = 1;
1212 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1213 $$.flags.q.depth_less = 1;
1214 } else if (match_layout_qualifier($1, "depth_unchanged",
1216 $$.flags.q.depth_unchanged = 1;
1219 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1220 _mesa_glsl_warning(& @1, state,
1221 "GL_AMD_conservative_depth "
1222 "layout qualifier `%s' is used", $1);
1224 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1225 _mesa_glsl_warning(& @1, state,
1226 "GL_ARB_conservative_depth "
1227 "layout qualifier `%s' is used", $1);
1231 /* See also interface_block_layout_qualifier. */
1232 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1233 if (match_layout_qualifier($1, "std140", state) == 0) {
1234 $$.flags.q.std140 = 1;
1235 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1236 $$.flags.q.shared = 1;
1237 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1238 $$.flags.q.column_major = 1;
1239 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1240 * below in the interface_block_layout_qualifier rule.
1242 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1245 * Also, this takes care of alternate capitalizations of
1246 * "row_major" (which is necessary because layout qualifiers
1247 * are case-insensitive in desktop GLSL).
1249 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1250 $$.flags.q.row_major = 1;
1251 /* "packed" is a reserved word in GLSL, and its token is
1252 * parsed below in the interface_block_layout_qualifier rule.
1253 * However, we must take care of alternate capitalizations of
1254 * "packed", because layout qualifiers are case-insensitive
1257 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1258 $$.flags.q.packed = 1;
1261 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1262 _mesa_glsl_warning(& @1, state,
1263 "#version 140 / GL_ARB_uniform_buffer_object "
1264 "layout qualifier `%s' is used", $1);
1268 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1274 { "points", GL_POINTS },
1275 { "lines", GL_LINES },
1276 { "lines_adjacency", GL_LINES_ADJACENCY },
1277 { "line_strip", GL_LINE_STRIP },
1278 { "triangles", GL_TRIANGLES },
1279 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1280 { "triangle_strip", GL_TRIANGLE_STRIP },
1282 for (unsigned i = 0; i < Elements(map); i++) {
1283 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1284 $$.flags.q.prim_type = 1;
1285 $$.prim_type = map[i].e;
1290 if ($$.flags.i && !state->is_version(150, 0)) {
1291 _mesa_glsl_error(& @1, state, "#version 150 layout "
1292 "qualifier `%s' used", $1);
1297 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1302 | any_identifier '=' integer_constant
1304 memset(& $$, 0, sizeof($$));
1306 if (match_layout_qualifier("location", $1, state) == 0) {
1307 $$.flags.q.explicit_location = 1;
1312 _mesa_glsl_error(& @3, state, "invalid location %d specified", $3);
1317 if (match_layout_qualifier("index", $1, state) == 0) {
1318 $$.flags.q.explicit_index = 1;
1323 _mesa_glsl_error(& @3, state, "invalid index %d specified", $3);
1328 if ((state->ARB_shading_language_420pack_enable ||
1329 state->ARB_shader_atomic_counters_enable) &&
1330 match_layout_qualifier("binding", $1, state) == 0) {
1331 $$.flags.q.explicit_binding = 1;
1335 if (state->ARB_shader_atomic_counters_enable &&
1336 match_layout_qualifier("offset", $1, state) == 0) {
1337 $$.flags.q.explicit_offset = 1;
1341 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1342 $$.flags.q.max_vertices = 1;
1345 _mesa_glsl_error(& @3, state,
1346 "invalid max_vertices %d specified", $3);
1349 $$.max_vertices = $3;
1350 if (!state->is_version(150, 0)) {
1351 _mesa_glsl_error(& @3, state,
1352 "#version 150 max_vertices qualifier "
1358 /* If the identifier didn't match any known layout identifiers,
1362 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1365 } else if (state->ARB_explicit_attrib_location_warn) {
1366 _mesa_glsl_warning(& @1, state,
1367 "GL_ARB_explicit_attrib_location layout "
1368 "identifier `%s' used", $1);
1371 | interface_block_layout_qualifier
1374 /* Layout qualifiers for ARB_uniform_buffer_object. */
1375 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1376 _mesa_glsl_error(& @1, state,
1377 "#version 140 / GL_ARB_uniform_buffer_object "
1378 "layout qualifier `%s' is used", $1);
1379 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1380 _mesa_glsl_warning(& @1, state,
1381 "#version 140 / GL_ARB_uniform_buffer_object "
1382 "layout qualifier `%s' is used", $1);
1387 /* This is a separate language rule because we parse these as tokens
1388 * (due to them being reserved keywords) instead of identifiers like
1389 * most qualifiers. See the any_identifier path of
1390 * layout_qualifier_id for the others.
1392 * Note that since layout qualifiers are case-insensitive in desktop
1393 * GLSL, all of these qualifiers need to be handled as identifiers as
1394 * well (by the any_identifier path of layout_qualifier_id).
1396 interface_block_layout_qualifier:
1399 memset(& $$, 0, sizeof($$));
1400 $$.flags.q.row_major = 1;
1404 memset(& $$, 0, sizeof($$));
1405 $$.flags.q.packed = 1;
1409 interpolation_qualifier:
1412 memset(& $$, 0, sizeof($$));
1413 $$.flags.q.smooth = 1;
1417 memset(& $$, 0, sizeof($$));
1418 $$.flags.q.flat = 1;
1422 memset(& $$, 0, sizeof($$));
1423 $$.flags.q.noperspective = 1;
1428 /* Single qualifiers */
1431 memset(& $$, 0, sizeof($$));
1432 $$.flags.q.invariant = 1;
1434 | auxiliary_storage_qualifier
1436 | interpolation_qualifier
1438 | precision_qualifier
1440 memset(&$$, 0, sizeof($$));
1444 /* Multiple qualifiers:
1445 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1446 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1448 * invariant interpolation auxiliary storage precision ...or...
1449 * layout storage precision
1451 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1452 * side don't contain any that must appear on the left hand side.
1453 * For example, when processing a storage qualifier, we check that there are
1454 * no auxiliary, interpolation, layout, or invariant qualifiers to the right.
1456 | INVARIANT type_qualifier
1458 if ($2.flags.q.invariant)
1459 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1461 if ($2.has_layout()) {
1462 _mesa_glsl_error(&@1, state,
1463 "\"invariant\" cannot be used with layout(...)");
1467 $$.flags.q.invariant = 1;
1469 | interpolation_qualifier type_qualifier
1471 /* Section 4.3 of the GLSL 1.40 specification states:
1472 * "...qualified with one of these interpolation qualifiers"
1474 * GLSL 1.30 claims to allow "one or more", but insists that:
1475 * "These interpolation qualifiers may only precede the qualifiers in,
1476 * centroid in, out, or centroid out in a declaration."
1478 * ...which means that e.g. smooth can't precede smooth, so there can be
1479 * only one after all, and the 1.40 text is a clarification, not a change.
1481 if ($2.has_interpolation())
1482 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1484 if ($2.has_layout()) {
1485 _mesa_glsl_error(&@1, state, "interpolation qualifiers cannot be used "
1486 "with layout(...)");
1489 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1490 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1491 "after \"invariant\"");
1495 $$.merge_qualifier(&@1, state, $2);
1497 | layout_qualifier type_qualifier
1499 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1500 * used standalone or immediately before a storage qualifier. It cannot
1501 * be used with interpolation qualifiers or invariant. There does not
1502 * appear to be any text indicating that it must come before the storage
1503 * qualifier, but always seems to in examples.
1505 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1506 _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers");
1508 if ($2.flags.q.invariant)
1509 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1510 "the \"invariant\" qualifier");
1512 if ($2.has_interpolation()) {
1513 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1514 "interpolation qualifiers");
1518 $$.merge_qualifier(&@1, state, $2);
1520 | auxiliary_storage_qualifier type_qualifier
1522 if ($2.has_auxiliary_storage()) {
1523 _mesa_glsl_error(&@1, state,
1524 "duplicate auxiliary storage qualifier (centroid)");
1527 if (!state->ARB_shading_language_420pack_enable &&
1528 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1529 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1530 "just before storage qualifiers");
1533 $$.flags.i |= $2.flags.i;
1535 | storage_qualifier type_qualifier
1537 /* Section 4.3 of the GLSL 1.20 specification states:
1538 * "Variable declarations may have a storage qualifier specified..."
1539 * 1.30 clarifies this to "may have one storage qualifier".
1541 if ($2.has_storage())
1542 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1544 if (!state->ARB_shading_language_420pack_enable &&
1545 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout() ||
1546 $2.has_auxiliary_storage())) {
1547 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1548 "invariant, interpolation, layout and auxiliary "
1549 "storage qualifiers");
1553 $$.merge_qualifier(&@1, state, $2);
1555 | precision_qualifier type_qualifier
1557 if ($2.precision != ast_precision_none)
1558 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1560 if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0)
1561 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1568 auxiliary_storage_qualifier:
1571 memset(& $$, 0, sizeof($$));
1572 $$.flags.q.centroid = 1;
1574 /* TODO: "sample" and "patch" also go here someday. */
1579 memset(& $$, 0, sizeof($$));
1580 $$.flags.q.constant = 1;
1584 memset(& $$, 0, sizeof($$));
1585 $$.flags.q.attribute = 1;
1589 memset(& $$, 0, sizeof($$));
1590 $$.flags.q.varying = 1;
1594 memset(& $$, 0, sizeof($$));
1599 memset(& $$, 0, sizeof($$));
1604 memset(& $$, 0, sizeof($$));
1605 $$.flags.q.uniform = 1;
1610 type_specifier_nonarray
1611 | type_specifier_nonarray '[' ']'
1614 $$->is_array = true;
1615 $$->array_size = NULL;
1617 | type_specifier_nonarray '[' constant_expression ']'
1620 $$->is_array = true;
1621 $$->array_size = $3;
1625 type_specifier_nonarray:
1626 basic_type_specifier_nonarray
1629 $$ = new(ctx) ast_type_specifier($1);
1630 $$->set_location(yylloc);
1635 $$ = new(ctx) ast_type_specifier($1);
1636 $$->set_location(yylloc);
1641 $$ = new(ctx) ast_type_specifier($1);
1642 $$->set_location(yylloc);
1646 basic_type_specifier_nonarray:
1647 VOID_TOK { $$ = "void"; }
1648 | FLOAT_TOK { $$ = "float"; }
1649 | INT_TOK { $$ = "int"; }
1650 | UINT_TOK { $$ = "uint"; }
1651 | BOOL_TOK { $$ = "bool"; }
1652 | VEC2 { $$ = "vec2"; }
1653 | VEC3 { $$ = "vec3"; }
1654 | VEC4 { $$ = "vec4"; }
1655 | BVEC2 { $$ = "bvec2"; }
1656 | BVEC3 { $$ = "bvec3"; }
1657 | BVEC4 { $$ = "bvec4"; }
1658 | IVEC2 { $$ = "ivec2"; }
1659 | IVEC3 { $$ = "ivec3"; }
1660 | IVEC4 { $$ = "ivec4"; }
1661 | UVEC2 { $$ = "uvec2"; }
1662 | UVEC3 { $$ = "uvec3"; }
1663 | UVEC4 { $$ = "uvec4"; }
1664 | MAT2X2 { $$ = "mat2"; }
1665 | MAT2X3 { $$ = "mat2x3"; }
1666 | MAT2X4 { $$ = "mat2x4"; }
1667 | MAT3X2 { $$ = "mat3x2"; }
1668 | MAT3X3 { $$ = "mat3"; }
1669 | MAT3X4 { $$ = "mat3x4"; }
1670 | MAT4X2 { $$ = "mat4x2"; }
1671 | MAT4X3 { $$ = "mat4x3"; }
1672 | MAT4X4 { $$ = "mat4"; }
1673 | SAMPLER1D { $$ = "sampler1D"; }
1674 | SAMPLER2D { $$ = "sampler2D"; }
1675 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1676 | SAMPLER3D { $$ = "sampler3D"; }
1677 | SAMPLERCUBE { $$ = "samplerCube"; }
1678 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1679 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1680 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1681 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1682 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1683 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1684 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1685 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1686 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1687 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1688 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1689 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1690 | ISAMPLER1D { $$ = "isampler1D"; }
1691 | ISAMPLER2D { $$ = "isampler2D"; }
1692 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1693 | ISAMPLER3D { $$ = "isampler3D"; }
1694 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1695 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1696 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1697 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1698 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1699 | USAMPLER1D { $$ = "usampler1D"; }
1700 | USAMPLER2D { $$ = "usampler2D"; }
1701 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1702 | USAMPLER3D { $$ = "usampler3D"; }
1703 | USAMPLERCUBE { $$ = "usamplerCube"; }
1704 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1705 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1706 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1707 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1708 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1709 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1710 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1711 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1712 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1713 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1714 | ATOMIC_UINT { $$ = "atomic_uint"; }
1717 precision_qualifier:
1720 state->check_precision_qualifiers_allowed(&@1);
1721 $$ = ast_precision_high;
1725 state->check_precision_qualifiers_allowed(&@1);
1726 $$ = ast_precision_medium;
1730 state->check_precision_qualifiers_allowed(&@1);
1731 $$ = ast_precision_low;
1736 STRUCT any_identifier '{' struct_declaration_list '}'
1739 $$ = new(ctx) ast_struct_specifier($2, $4);
1740 $$->set_location(yylloc);
1741 state->symbols->add_type($2, glsl_type::void_type);
1742 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1744 | STRUCT '{' struct_declaration_list '}'
1747 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1748 $$->set_location(yylloc);
1752 struct_declaration_list:
1756 $1->link.self_link();
1758 | struct_declaration_list struct_declaration
1761 $$->link.insert_before(& $2->link);
1766 fully_specified_type struct_declarator_list ';'
1769 ast_fully_specified_type *const type = $1;
1770 type->set_location(yylloc);
1772 if (type->qualifier.flags.i != 0)
1773 _mesa_glsl_error(&@1, state,
1774 "only precision qualifiers may be applied to "
1775 "structure members");
1777 $$ = new(ctx) ast_declarator_list(type);
1778 $$->set_location(yylloc);
1780 $$->declarations.push_degenerate_list_at_head(& $2->link);
1784 struct_declarator_list:
1788 $1->link.self_link();
1790 | struct_declarator_list ',' struct_declarator
1793 $$->link.insert_before(& $3->link);
1801 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1802 $$->set_location(yylloc);
1804 | any_identifier '[' ']'
1807 $$ = new(ctx) ast_declaration($1, true, NULL, NULL);
1808 $$->set_location(yylloc);
1810 | any_identifier '[' constant_expression ']'
1813 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1814 $$->set_location(yylloc);
1819 assignment_expression
1820 | '{' initializer_list '}'
1824 | '{' initializer_list ',' '}'
1834 $$ = new(ctx) ast_aggregate_initializer();
1835 $$->set_location(yylloc);
1836 $$->expressions.push_tail(& $1->link);
1838 | initializer_list ',' initializer
1840 $1->expressions.push_tail(& $3->link);
1844 declaration_statement:
1848 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1851 compound_statement { $$ = (ast_node *) $1; }
1856 declaration_statement
1857 | expression_statement
1858 | selection_statement
1860 | iteration_statement
1868 $$ = new(ctx) ast_compound_statement(true, NULL);
1869 $$->set_location(yylloc);
1873 state->symbols->push_scope();
1878 $$ = new(ctx) ast_compound_statement(true, $3);
1879 $$->set_location(yylloc);
1880 state->symbols->pop_scope();
1884 statement_no_new_scope:
1885 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1889 compound_statement_no_new_scope:
1893 $$ = new(ctx) ast_compound_statement(false, NULL);
1894 $$->set_location(yylloc);
1896 | '{' statement_list '}'
1899 $$ = new(ctx) ast_compound_statement(false, $2);
1900 $$->set_location(yylloc);
1908 _mesa_glsl_error(& @1, state, "<nil> statement");
1913 $$->link.self_link();
1915 | statement_list statement
1918 _mesa_glsl_error(& @2, state, "<nil> statement");
1922 $$->link.insert_before(& $2->link);
1926 expression_statement:
1930 $$ = new(ctx) ast_expression_statement(NULL);
1931 $$->set_location(yylloc);
1936 $$ = new(ctx) ast_expression_statement($1);
1937 $$->set_location(yylloc);
1941 selection_statement:
1942 IF '(' expression ')' selection_rest_statement
1944 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1946 $$->set_location(yylloc);
1950 selection_rest_statement:
1951 statement ELSE statement
1953 $$.then_statement = $1;
1954 $$.else_statement = $3;
1956 | statement %prec THEN
1958 $$.then_statement = $1;
1959 $$.else_statement = NULL;
1966 $$ = (ast_node *) $1;
1968 | fully_specified_type any_identifier '=' initializer
1971 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1972 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1973 decl->set_location(yylloc);
1974 declarator->set_location(yylloc);
1976 declarator->declarations.push_tail(&decl->link);
1982 * siwtch_statement grammar is based on the syntax described in the body
1983 * of the GLSL spec, not in it's appendix!!!
1986 SWITCH '(' expression ')' switch_body
1988 $$ = new(state) ast_switch_statement($3, $5);
1989 $$->set_location(yylloc);
1996 $$ = new(state) ast_switch_body(NULL);
1997 $$->set_location(yylloc);
1999 | '{' case_statement_list '}'
2001 $$ = new(state) ast_switch_body($2);
2002 $$->set_location(yylloc);
2009 $$ = new(state) ast_case_label($2);
2010 $$->set_location(yylloc);
2014 $$ = new(state) ast_case_label(NULL);
2015 $$->set_location(yylloc);
2022 ast_case_label_list *labels = new(state) ast_case_label_list();
2024 labels->labels.push_tail(& $1->link);
2026 $$->set_location(yylloc);
2028 | case_label_list case_label
2031 $$->labels.push_tail(& $2->link);
2036 case_label_list statement
2038 ast_case_statement *stmts = new(state) ast_case_statement($1);
2039 stmts->set_location(yylloc);
2041 stmts->stmts.push_tail(& $2->link);
2044 | case_statement statement
2047 $$->stmts.push_tail(& $2->link);
2051 case_statement_list:
2054 ast_case_statement_list *cases= new(state) ast_case_statement_list();
2055 cases->set_location(yylloc);
2057 cases->cases.push_tail(& $1->link);
2060 | case_statement_list case_statement
2063 $$->cases.push_tail(& $2->link);
2067 iteration_statement:
2068 WHILE '(' condition ')' statement_no_new_scope
2071 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2072 NULL, $3, NULL, $5);
2073 $$->set_location(yylloc);
2075 | DO statement WHILE '(' expression ')' ';'
2078 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2079 NULL, $5, NULL, $2);
2080 $$->set_location(yylloc);
2082 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2085 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2086 $3, $4.cond, $4.rest, $6);
2087 $$->set_location(yylloc);
2092 expression_statement
2093 | declaration_statement
2110 | conditionopt ';' expression
2117 // Grammar Note: No 'goto'. Gotos are not supported.
2122 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2123 $$->set_location(yylloc);
2128 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2129 $$->set_location(yylloc);
2134 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2135 $$->set_location(yylloc);
2137 | RETURN expression ';'
2140 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2141 $$->set_location(yylloc);
2143 | DISCARD ';' // Fragment shader only.
2146 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2147 $$->set_location(yylloc);
2151 external_declaration:
2152 function_definition { $$ = $1; }
2153 | declaration { $$ = $1; }
2154 | pragma_statement { $$ = NULL; }
2155 | layout_defaults { $$ = $1; }
2158 function_definition:
2159 function_prototype compound_statement_no_new_scope
2162 $$ = new(ctx) ast_function_definition();
2163 $$->set_location(yylloc);
2167 state->symbols->pop_scope();
2171 /* layout_qualifieropt is packed into this rule */
2173 basic_interface_block
2177 | layout_qualifier basic_interface_block
2179 ast_interface_block *block = $2;
2180 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2187 basic_interface_block:
2188 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2190 ast_interface_block *const block = $6;
2192 block->block_name = $2;
2193 block->declarations.push_degenerate_list_at_head(& $4->link);
2195 if ($1.flags.q.uniform) {
2196 if (!state->has_uniform_buffer_objects()) {
2197 _mesa_glsl_error(& @1, state,
2198 "#version 140 / GL_ARB_uniform_buffer_object "
2199 "required for defining uniform blocks");
2200 } else if (state->ARB_uniform_buffer_object_warn) {
2201 _mesa_glsl_warning(& @1, state,
2202 "#version 140 / GL_ARB_uniform_buffer_object "
2203 "required for defining uniform blocks");
2206 if (state->es_shader || state->language_version < 150) {
2207 _mesa_glsl_error(& @1, state,
2208 "#version 150 required for using "
2209 "interface blocks");
2213 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2214 * "It is illegal to have an input block in a vertex shader
2215 * or an output block in a fragment shader"
2217 if ((state->target == vertex_shader) && $1.flags.q.in) {
2218 _mesa_glsl_error(& @1, state,
2219 "`in' interface block is not allowed for "
2221 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2222 _mesa_glsl_error(& @1, state,
2223 "`out' interface block is not allowed for "
2224 "a fragment shader");
2227 /* Since block arrays require names, and both features are added in
2228 * the same language versions, we don't have to explicitly
2229 * version-check both things.
2231 if (block->instance_name != NULL) {
2232 state->check_version(150, 300, & @1, "interface blocks with "
2233 "an instance name are not allowed");
2236 unsigned interface_type_mask;
2237 struct ast_type_qualifier temp_type_qualifier;
2239 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2240 * to ignore other irrelevant flags like interpolation qualifiers.
2242 temp_type_qualifier.flags.i = 0;
2243 temp_type_qualifier.flags.q.uniform = true;
2244 temp_type_qualifier.flags.q.in = true;
2245 temp_type_qualifier.flags.q.out = true;
2246 interface_type_mask = temp_type_qualifier.flags.i;
2248 /* Get the block's interface qualifier. The interface_qualifier
2249 * production rule guarantees that only one bit will be set (and
2250 * it will be in/out/uniform).
2252 unsigned block_interface_qualifier = $1.flags.i;
2254 block->layout.flags.i |= block_interface_qualifier;
2256 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2257 ast_type_qualifier& qualifier = member->type->qualifier;
2258 if ((qualifier.flags.i & interface_type_mask) == 0) {
2259 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2260 * "If no optional qualifier is used in a member declaration, the
2261 * qualifier of the variable is just in, out, or uniform as declared
2262 * by interface-qualifier."
2264 qualifier.flags.i |= block_interface_qualifier;
2265 } else if ((qualifier.flags.i & interface_type_mask) !=
2266 block_interface_qualifier) {
2267 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2268 * "If optional qualifiers are used, they can include interpolation
2269 * and storage qualifiers and they must declare an input, output,
2270 * or uniform variable consistent with the interface qualifier of
2273 _mesa_glsl_error(& @1, state,
2274 "uniform/in/out qualifier on "
2275 "interface block member does not match "
2276 "the interface block");
2284 interface_qualifier:
2287 memset(& $$, 0, sizeof($$));
2292 memset(& $$, 0, sizeof($$));
2297 memset(& $$, 0, sizeof($$));
2298 $$.flags.q.uniform = 1;
2305 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2310 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2313 | NEW_IDENTIFIER '[' constant_expression ']'
2315 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2318 | NEW_IDENTIFIER '[' ']'
2320 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2329 $1->link.self_link();
2331 | member_declaration member_list
2334 $2->link.insert_before(& $$->link);
2339 fully_specified_type struct_declarator_list ';'
2342 ast_fully_specified_type *type = $1;
2343 type->set_location(yylloc);
2345 if (type->qualifier.flags.q.attribute) {
2346 _mesa_glsl_error(& @1, state,
2347 "keyword 'attribute' cannot be used with "
2348 "interface block member");
2349 } else if (type->qualifier.flags.q.varying) {
2350 _mesa_glsl_error(& @1, state,
2351 "keyword 'varying' cannot be used with "
2352 "interface block member");
2355 $$ = new(ctx) ast_declarator_list(type);
2356 $$->set_location(yylloc);
2358 $$->declarations.push_degenerate_list_at_head(& $2->link);
2363 layout_qualifier UNIFORM ';'
2365 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {
2371 | layout_qualifier IN_TOK ';'
2375 if (state->target != geometry_shader) {
2376 _mesa_glsl_error(& @1, state,
2377 "input layout qualifiers only valid in "
2378 "geometry shaders");
2379 } else if (!$1.flags.q.prim_type) {
2380 _mesa_glsl_error(& @1, state,
2381 "input layout qualifiers must specify a primitive"
2384 /* Make sure this is a valid input primitive type. */
2385 switch ($1.prim_type) {
2388 case GL_LINES_ADJACENCY:
2390 case GL_TRIANGLES_ADJACENCY:
2391 $$ = new(ctx) ast_gs_input_layout(@1, $1.prim_type);
2394 _mesa_glsl_error(&@1, state,
2395 "invalid geometry shader input primitive type");
2401 | layout_qualifier OUT_TOK ';'
2403 if (state->target != geometry_shader) {
2404 _mesa_glsl_error(& @1, state,
2405 "out layout qualifiers only valid in "
2406 "geometry shaders");
2408 if ($1.flags.q.prim_type) {
2409 /* Make sure this is a valid output primitive type. */
2410 switch ($1.prim_type) {
2413 case GL_TRIANGLE_STRIP:
2416 _mesa_glsl_error(&@1, state, "invalid geometry shader output "
2421 if (!state->out_qualifier->merge_qualifier(& @1, state, $1))