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"
34 #define YYLEX_PARAM state->scanner
38 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
40 _mesa_glsl_error(loc, st, "%s", msg);
58 %lex-param {void *scanner}
59 %parse-param {struct _mesa_glsl_parse_state *state}
64 const char *identifier;
66 struct ast_type_qualifier type_qualifier;
69 ast_type_specifier *type_specifier;
70 ast_fully_specified_type *fully_specified_type;
71 ast_function *function;
72 ast_parameter_declarator *parameter_declarator;
73 ast_function_definition *function_definition;
74 ast_compound_statement *compound_statement;
75 ast_expression *expression;
76 ast_declarator_list *declarator_list;
77 ast_struct_specifier *struct_specifier;
78 ast_declaration *declaration;
79 ast_switch_body *switch_body;
80 ast_case_label *case_label;
81 ast_case_label_list *case_label_list;
82 ast_case_statement *case_statement;
83 ast_case_statement_list *case_statement_list;
84 ast_interface_block *interface_block;
92 ast_node *then_statement;
93 ast_node *else_statement;
94 } selection_rest_statement;
97 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
98 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
99 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
100 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
101 %token NOPERSPECTIVE FLAT SMOOTH
102 %token MAT2X2 MAT2X3 MAT2X4
103 %token MAT3X2 MAT3X3 MAT3X4
104 %token MAT4X2 MAT4X3 MAT4X4
105 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
106 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
107 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
108 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
109 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
110 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
111 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
112 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
113 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
114 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
115 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
116 %token SAMPLEREXTERNALOES
117 %token STRUCT VOID_TOK WHILE
118 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
119 %type <identifier> any_identifier
120 %type <interface_block> instance_name_opt
121 %token <real> FLOATCONSTANT
122 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
123 %token <identifier> FIELD_SELECTION
124 %token LEFT_OP RIGHT_OP
125 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
126 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
127 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
130 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
132 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
133 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
134 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
135 %token PRAGMA_INVARIANT_ALL
138 /* Reserved words that are not actually used in the grammar.
140 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
141 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
142 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
143 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
145 %token SIZEOF CAST NAMESPACE USING
146 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
151 %token COMMON PARTITION ACTIVE FILTER
152 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
153 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
154 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
155 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
156 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
159 %type <identifier> variable_identifier
160 %type <node> statement
161 %type <node> statement_list
162 %type <node> simple_statement
163 %type <n> precision_qualifier
164 %type <type_qualifier> type_qualifier
165 %type <type_qualifier> storage_qualifier
166 %type <type_qualifier> interpolation_qualifier
167 %type <type_qualifier> layout_qualifier
168 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
169 %type <type_qualifier> interface_block_layout_qualifier
170 %type <type_qualifier> interface_qualifier
171 %type <type_specifier> type_specifier
172 %type <type_specifier> type_specifier_no_prec
173 %type <type_specifier> type_specifier_nonarray
174 %type <identifier> basic_type_specifier_nonarray
175 %type <fully_specified_type> fully_specified_type
176 %type <function> function_prototype
177 %type <function> function_header
178 %type <function> function_header_with_parameters
179 %type <function> function_declarator
180 %type <parameter_declarator> parameter_declarator
181 %type <parameter_declarator> parameter_declaration
182 %type <type_qualifier> parameter_qualifier
183 %type <type_qualifier> parameter_direction_qualifier
184 %type <type_specifier> parameter_type_specifier
185 %type <function_definition> function_definition
186 %type <compound_statement> compound_statement_no_new_scope
187 %type <compound_statement> compound_statement
188 %type <node> statement_no_new_scope
189 %type <node> expression_statement
190 %type <expression> expression
191 %type <expression> primary_expression
192 %type <expression> assignment_expression
193 %type <expression> conditional_expression
194 %type <expression> logical_or_expression
195 %type <expression> logical_xor_expression
196 %type <expression> logical_and_expression
197 %type <expression> inclusive_or_expression
198 %type <expression> exclusive_or_expression
199 %type <expression> and_expression
200 %type <expression> equality_expression
201 %type <expression> relational_expression
202 %type <expression> shift_expression
203 %type <expression> additive_expression
204 %type <expression> multiplicative_expression
205 %type <expression> unary_expression
206 %type <expression> constant_expression
207 %type <expression> integer_expression
208 %type <expression> postfix_expression
209 %type <expression> function_call_header_with_parameters
210 %type <expression> function_call_header_no_parameters
211 %type <expression> function_call_header
212 %type <expression> function_call_generic
213 %type <expression> function_call_or_method
214 %type <expression> function_call
215 %type <expression> method_call_generic
216 %type <expression> method_call_header_with_parameters
217 %type <expression> method_call_header_no_parameters
218 %type <expression> method_call_header
219 %type <n> assignment_operator
220 %type <n> unary_operator
221 %type <expression> function_identifier
222 %type <node> external_declaration
223 %type <declarator_list> init_declarator_list
224 %type <declarator_list> single_declaration
225 %type <expression> initializer
226 %type <expression> initializer_list
227 %type <node> declaration
228 %type <node> declaration_statement
229 %type <node> jump_statement
230 %type <node> interface_block
231 %type <interface_block> basic_interface_block
232 %type <struct_specifier> struct_specifier
233 %type <declarator_list> struct_declaration_list
234 %type <declarator_list> struct_declaration
235 %type <declaration> struct_declarator
236 %type <declaration> struct_declarator_list
237 %type <declarator_list> member_list
238 %type <declarator_list> member_declaration
239 %type <node> selection_statement
240 %type <selection_rest_statement> selection_rest_statement
241 %type <node> switch_statement
242 %type <switch_body> switch_body
243 %type <case_label_list> case_label_list
244 %type <case_label> case_label
245 %type <case_statement> case_statement
246 %type <case_statement_list> case_statement_list
247 %type <node> iteration_statement
248 %type <node> condition
249 %type <node> conditionopt
250 %type <node> for_init_statement
251 %type <for_rest_statement> for_rest_statement
252 %type <n> integer_constant
258 version_statement extension_statement_list
260 _mesa_glsl_initialize_types(state);
262 external_declaration_list
264 delete state->symbols;
265 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
266 _mesa_glsl_initialize_types(state);
271 /* blank - no #version specified: defaults are already set */
272 | VERSION_TOK INTCONSTANT EOL
274 state->process_version_directive(&@2, $2, NULL);
279 | VERSION_TOK INTCONSTANT any_identifier EOL
281 state->process_version_directive(&@2, $2, $3);
290 | PRAGMA_DEBUG_OFF EOL
291 | PRAGMA_OPTIMIZE_ON EOL
292 | PRAGMA_OPTIMIZE_OFF EOL
293 | PRAGMA_INVARIANT_ALL EOL
295 if (!state->is_version(120, 100)) {
296 _mesa_glsl_warning(& @1, state,
297 "pragma `invariant(all)' not supported in %s "
298 "(GLSL ES 1.00 or GLSL 1.20 required).",
299 state->get_version_string());
301 state->all_invariant = true;
306 extension_statement_list:
308 | extension_statement_list extension_statement
318 EXTENSION any_identifier COLON any_identifier EOL
320 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
326 external_declaration_list:
329 /* FINISHME: The NULL test is required because pragmas are set to
330 * FINISHME: NULL. (See production rule for external_declaration.)
333 state->translation_unit.push_tail(& $1->link);
335 | external_declaration_list external_declaration
337 /* FINISHME: The NULL test is required because pragmas are set to
338 * FINISHME: NULL. (See production rule for external_declaration.)
341 state->translation_unit.push_tail(& $2->link);
354 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
355 $$->set_location(yylloc);
356 $$->primary_expression.identifier = $1;
361 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
362 $$->set_location(yylloc);
363 $$->primary_expression.int_constant = $1;
368 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
369 $$->set_location(yylloc);
370 $$->primary_expression.uint_constant = $1;
375 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
376 $$->set_location(yylloc);
377 $$->primary_expression.float_constant = $1;
382 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
383 $$->set_location(yylloc);
384 $$->primary_expression.bool_constant = $1;
394 | postfix_expression '[' integer_expression ']'
397 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
398 $$->set_location(yylloc);
404 | postfix_expression '.' any_identifier
407 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
408 $$->set_location(yylloc);
409 $$->primary_expression.identifier = $3;
411 | postfix_expression INC_OP
414 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
415 $$->set_location(yylloc);
417 | postfix_expression DEC_OP
420 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
421 $$->set_location(yylloc);
430 function_call_or_method
433 function_call_or_method:
434 function_call_generic
435 | postfix_expression '.' method_call_generic
438 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
439 $$->set_location(yylloc);
443 function_call_generic:
444 function_call_header_with_parameters ')'
445 | function_call_header_no_parameters ')'
448 function_call_header_no_parameters:
449 function_call_header VOID_TOK
450 | function_call_header
453 function_call_header_with_parameters:
454 function_call_header assignment_expression
457 $$->set_location(yylloc);
458 $$->expressions.push_tail(& $2->link);
460 | function_call_header_with_parameters ',' assignment_expression
463 $$->set_location(yylloc);
464 $$->expressions.push_tail(& $3->link);
468 // Grammar Note: Constructors look like functions, but lexical
469 // analysis recognized most of them as keywords. They are now
470 // recognized through "type_specifier".
471 function_call_header:
472 function_identifier '('
479 $$ = new(ctx) ast_function_expression($1);
480 $$->set_location(yylloc);
482 | variable_identifier
485 ast_expression *callee = new(ctx) ast_expression($1);
486 $$ = new(ctx) ast_function_expression(callee);
487 $$->set_location(yylloc);
492 ast_expression *callee = new(ctx) ast_expression($1);
493 $$ = new(ctx) ast_function_expression(callee);
494 $$->set_location(yylloc);
499 method_call_header_with_parameters ')'
500 | method_call_header_no_parameters ')'
503 method_call_header_no_parameters:
504 method_call_header VOID_TOK
508 method_call_header_with_parameters:
509 method_call_header assignment_expression
512 $$->set_location(yylloc);
513 $$->expressions.push_tail(& $2->link);
515 | method_call_header_with_parameters ',' assignment_expression
518 $$->set_location(yylloc);
519 $$->expressions.push_tail(& $3->link);
523 // Grammar Note: Constructors look like methods, but lexical
524 // analysis recognized most of them as keywords. They are now
525 // recognized through "type_specifier".
527 variable_identifier '('
530 ast_expression *callee = new(ctx) ast_expression($1);
531 $$ = new(ctx) ast_function_expression(callee);
532 $$->set_location(yylloc);
536 // Grammar Note: No traditional style type casts.
539 | INC_OP unary_expression
542 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
543 $$->set_location(yylloc);
545 | DEC_OP unary_expression
548 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
549 $$->set_location(yylloc);
551 | unary_operator unary_expression
554 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
555 $$->set_location(yylloc);
559 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
561 '+' { $$ = ast_plus; }
562 | '-' { $$ = ast_neg; }
563 | '!' { $$ = ast_logic_not; }
564 | '~' { $$ = ast_bit_not; }
567 multiplicative_expression:
569 | multiplicative_expression '*' unary_expression
572 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
573 $$->set_location(yylloc);
575 | multiplicative_expression '/' unary_expression
578 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
579 $$->set_location(yylloc);
581 | multiplicative_expression '%' unary_expression
584 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
585 $$->set_location(yylloc);
590 multiplicative_expression
591 | additive_expression '+' multiplicative_expression
594 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
595 $$->set_location(yylloc);
597 | additive_expression '-' multiplicative_expression
600 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
601 $$->set_location(yylloc);
607 | shift_expression LEFT_OP additive_expression
610 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
611 $$->set_location(yylloc);
613 | shift_expression RIGHT_OP additive_expression
616 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
617 $$->set_location(yylloc);
621 relational_expression:
623 | relational_expression '<' shift_expression
626 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
627 $$->set_location(yylloc);
629 | relational_expression '>' shift_expression
632 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
633 $$->set_location(yylloc);
635 | relational_expression LE_OP shift_expression
638 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
639 $$->set_location(yylloc);
641 | relational_expression GE_OP shift_expression
644 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
645 $$->set_location(yylloc);
650 relational_expression
651 | equality_expression EQ_OP relational_expression
654 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
655 $$->set_location(yylloc);
657 | equality_expression NE_OP relational_expression
660 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
661 $$->set_location(yylloc);
667 | and_expression '&' equality_expression
670 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
671 $$->set_location(yylloc);
675 exclusive_or_expression:
677 | exclusive_or_expression '^' and_expression
680 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
681 $$->set_location(yylloc);
685 inclusive_or_expression:
686 exclusive_or_expression
687 | inclusive_or_expression '|' exclusive_or_expression
690 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
691 $$->set_location(yylloc);
695 logical_and_expression:
696 inclusive_or_expression
697 | logical_and_expression AND_OP inclusive_or_expression
700 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
701 $$->set_location(yylloc);
705 logical_xor_expression:
706 logical_and_expression
707 | logical_xor_expression XOR_OP logical_and_expression
710 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
711 $$->set_location(yylloc);
715 logical_or_expression:
716 logical_xor_expression
717 | logical_or_expression OR_OP logical_xor_expression
720 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
721 $$->set_location(yylloc);
725 conditional_expression:
726 logical_or_expression
727 | logical_or_expression '?' expression ':' assignment_expression
730 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
731 $$->set_location(yylloc);
735 assignment_expression:
736 conditional_expression
737 | unary_expression assignment_operator assignment_expression
740 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
741 $$->set_location(yylloc);
746 '=' { $$ = ast_assign; }
747 | MUL_ASSIGN { $$ = ast_mul_assign; }
748 | DIV_ASSIGN { $$ = ast_div_assign; }
749 | MOD_ASSIGN { $$ = ast_mod_assign; }
750 | ADD_ASSIGN { $$ = ast_add_assign; }
751 | SUB_ASSIGN { $$ = ast_sub_assign; }
752 | LEFT_ASSIGN { $$ = ast_ls_assign; }
753 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
754 | AND_ASSIGN { $$ = ast_and_assign; }
755 | XOR_ASSIGN { $$ = ast_xor_assign; }
756 | OR_ASSIGN { $$ = ast_or_assign; }
760 assignment_expression
764 | expression ',' assignment_expression
767 if ($1->oper != ast_sequence) {
768 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
769 $$->set_location(yylloc);
770 $$->expressions.push_tail(& $1->link);
775 $$->expressions.push_tail(& $3->link);
780 conditional_expression
784 function_prototype ';'
786 state->symbols->pop_scope();
789 | init_declarator_list ';'
793 | PRECISION precision_qualifier type_specifier_no_prec ';'
796 $3->is_precision_statement = true;
806 function_declarator ')'
811 | function_header_with_parameters
814 function_header_with_parameters:
815 function_header parameter_declaration
818 $$->parameters.push_tail(& $2->link);
820 | function_header_with_parameters ',' parameter_declaration
823 $$->parameters.push_tail(& $3->link);
828 fully_specified_type variable_identifier '('
831 $$ = new(ctx) ast_function();
832 $$->set_location(yylloc);
833 $$->return_type = $1;
836 state->symbols->add_function(new(state) ir_function($2));
837 state->symbols->push_scope();
841 parameter_declarator:
842 type_specifier any_identifier
845 $$ = new(ctx) ast_parameter_declarator();
846 $$->set_location(yylloc);
847 $$->type = new(ctx) ast_fully_specified_type();
848 $$->type->set_location(yylloc);
849 $$->type->specifier = $1;
852 | type_specifier any_identifier '[' constant_expression ']'
855 $$ = new(ctx) ast_parameter_declarator();
856 $$->set_location(yylloc);
857 $$->type = new(ctx) ast_fully_specified_type();
858 $$->type->set_location(yylloc);
859 $$->type->specifier = $1;
866 parameter_declaration:
867 parameter_qualifier parameter_declarator
870 $$->type->qualifier = $1;
872 | parameter_qualifier parameter_type_specifier
875 $$ = new(ctx) ast_parameter_declarator();
876 $$->set_location(yylloc);
877 $$->type = new(ctx) ast_fully_specified_type();
878 $$->type->qualifier = $1;
879 $$->type->specifier = $2;
886 memset(& $$, 0, sizeof($$));
888 | CONST_TOK parameter_qualifier
890 if ($2.flags.q.constant)
891 _mesa_glsl_error(&@1, state, "duplicate const qualifier.\n");
894 $$.flags.q.constant = 1;
896 | parameter_direction_qualifier parameter_qualifier
898 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
899 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier\n");
901 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant)
902 _mesa_glsl_error(&@1, state, "const must be specified before "
906 $$.merge_qualifier(&@1, state, $2);
909 parameter_direction_qualifier:
912 memset(& $$, 0, sizeof($$));
917 memset(& $$, 0, sizeof($$));
922 memset(& $$, 0, sizeof($$));
928 parameter_type_specifier:
932 init_declarator_list:
934 | init_declarator_list ',' any_identifier
937 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
938 decl->set_location(yylloc);
941 $$->declarations.push_tail(&decl->link);
942 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
944 | init_declarator_list ',' any_identifier '[' ']'
947 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
948 decl->set_location(yylloc);
951 $$->declarations.push_tail(&decl->link);
952 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
954 | init_declarator_list ',' any_identifier '[' constant_expression ']'
957 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
958 decl->set_location(yylloc);
961 $$->declarations.push_tail(&decl->link);
962 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
964 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
967 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
968 decl->set_location(yylloc);
971 $$->declarations.push_tail(&decl->link);
972 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
973 if ($7->oper == ast_aggregate) {
974 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
975 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
976 _mesa_ast_set_aggregate_type(type, ai, state);
979 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
982 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
983 decl->set_location(yylloc);
986 $$->declarations.push_tail(&decl->link);
987 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
988 if ($8->oper == ast_aggregate) {
989 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
990 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
991 _mesa_ast_set_aggregate_type(type, ai, state);
994 | init_declarator_list ',' any_identifier '=' initializer
997 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
998 decl->set_location(yylloc);
1001 $$->declarations.push_tail(&decl->link);
1002 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1003 if ($5->oper == ast_aggregate) {
1004 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
1005 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1010 // Grammar Note: No 'enum', or 'typedef'.
1012 fully_specified_type
1015 /* Empty declaration list is valid. */
1016 $$ = new(ctx) ast_declarator_list($1);
1017 $$->set_location(yylloc);
1019 | fully_specified_type any_identifier
1022 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1024 $$ = new(ctx) ast_declarator_list($1);
1025 $$->set_location(yylloc);
1026 $$->declarations.push_tail(&decl->link);
1028 | fully_specified_type any_identifier '[' ']'
1031 ast_declaration *decl = new(ctx) ast_declaration($2, true, 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 '[' constant_expression ']'
1040 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1042 $$ = new(ctx) ast_declarator_list($1);
1043 $$->set_location(yylloc);
1044 $$->declarations.push_tail(&decl->link);
1046 | fully_specified_type any_identifier '[' ']' '=' initializer
1049 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1051 $$ = new(ctx) ast_declarator_list($1);
1052 $$->set_location(yylloc);
1053 $$->declarations.push_tail(&decl->link);
1054 if ($6->oper == ast_aggregate) {
1055 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1056 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1057 _mesa_ast_set_aggregate_type(type, ai, state);
1060 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1063 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1065 $$ = new(ctx) ast_declarator_list($1);
1066 $$->set_location(yylloc);
1067 $$->declarations.push_tail(&decl->link);
1068 if ($7->oper == ast_aggregate) {
1069 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1070 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1071 _mesa_ast_set_aggregate_type(type, ai, state);
1074 | fully_specified_type any_identifier '=' initializer
1077 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1079 $$ = new(ctx) ast_declarator_list($1);
1080 $$->set_location(yylloc);
1081 $$->declarations.push_tail(&decl->link);
1082 if ($4->oper == ast_aggregate) {
1083 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1086 | INVARIANT variable_identifier // Vertex only.
1089 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1091 $$ = new(ctx) ast_declarator_list(NULL);
1092 $$->set_location(yylloc);
1093 $$->invariant = true;
1095 $$->declarations.push_tail(&decl->link);
1099 fully_specified_type:
1103 $$ = new(ctx) ast_fully_specified_type();
1104 $$->set_location(yylloc);
1107 | type_qualifier type_specifier
1110 $$ = new(ctx) ast_fully_specified_type();
1111 $$->set_location(yylloc);
1118 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1124 layout_qualifier_id_list:
1126 | layout_qualifier_id_list ',' layout_qualifier_id
1129 if (!$$.merge_qualifier(& @3, state, $3)) {
1136 INTCONSTANT { $$ = $1; }
1137 | UINTCONSTANT { $$ = $1; }
1140 layout_qualifier_id:
1143 memset(& $$, 0, sizeof($$));
1145 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1146 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1147 if (strcmp($1, "origin_upper_left") == 0) {
1148 $$.flags.q.origin_upper_left = 1;
1149 } else if (strcmp($1, "pixel_center_integer") == 0) {
1150 $$.flags.q.pixel_center_integer = 1;
1153 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1154 _mesa_glsl_warning(& @1, state,
1155 "GL_ARB_fragment_coord_conventions layout "
1156 "identifier `%s' used\n", $1);
1160 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1162 (state->AMD_conservative_depth_enable ||
1163 state->ARB_conservative_depth_enable)) {
1164 if (strcmp($1, "depth_any") == 0) {
1165 $$.flags.q.depth_any = 1;
1166 } else if (strcmp($1, "depth_greater") == 0) {
1167 $$.flags.q.depth_greater = 1;
1168 } else if (strcmp($1, "depth_less") == 0) {
1169 $$.flags.q.depth_less = 1;
1170 } else if (strcmp($1, "depth_unchanged") == 0) {
1171 $$.flags.q.depth_unchanged = 1;
1174 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1175 _mesa_glsl_warning(& @1, state,
1176 "GL_AMD_conservative_depth "
1177 "layout qualifier `%s' is used\n", $1);
1179 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1180 _mesa_glsl_warning(& @1, state,
1181 "GL_ARB_conservative_depth "
1182 "layout qualifier `%s' is used\n", $1);
1186 /* See also interface_block_layout_qualifier. */
1187 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1188 if (strcmp($1, "std140") == 0) {
1189 $$.flags.q.std140 = 1;
1190 } else if (strcmp($1, "shared") == 0) {
1191 $$.flags.q.shared = 1;
1192 } else if (strcmp($1, "column_major") == 0) {
1193 $$.flags.q.column_major = 1;
1194 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1195 * below in the interface_block_layout_qualifier rule.
1197 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1200 } else if (strcmp($1, "row_major") == 0) {
1201 $$.flags.q.row_major = 1;
1204 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1205 _mesa_glsl_warning(& @1, state,
1206 "#version 140 / GL_ARB_uniform_buffer_object "
1207 "layout qualifier `%s' is used\n", $1);
1212 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1217 | any_identifier '=' integer_constant
1219 memset(& $$, 0, sizeof($$));
1221 if (state->ARB_explicit_attrib_location_enable) {
1222 if (strcmp("location", $1) == 0) {
1223 $$.flags.q.explicit_location = 1;
1228 _mesa_glsl_error(& @3, state,
1229 "invalid location %d specified\n", $3);
1234 if (strcmp("index", $1) == 0) {
1235 $$.flags.q.explicit_index = 1;
1240 _mesa_glsl_error(& @3, state,
1241 "invalid index %d specified\n", $3);
1247 /* If the identifier didn't match any known layout identifiers,
1251 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1254 } else if (state->ARB_explicit_attrib_location_warn) {
1255 _mesa_glsl_warning(& @1, state,
1256 "GL_ARB_explicit_attrib_location layout "
1257 "identifier `%s' used\n", $1);
1260 | interface_block_layout_qualifier
1263 /* Layout qualifiers for ARB_uniform_buffer_object. */
1264 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1265 _mesa_glsl_error(& @1, state,
1266 "#version 140 / GL_ARB_uniform_buffer_object "
1267 "layout qualifier `%s' is used\n", $1);
1268 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1269 _mesa_glsl_warning(& @1, state,
1270 "#version 140 / GL_ARB_uniform_buffer_object "
1271 "layout qualifier `%s' is used\n", $1);
1276 /* This is a separate language rule because we parse these as tokens
1277 * (due to them being reserved keywords) instead of identifiers like
1278 * most qualifiers. See the any_identifier path of
1279 * layout_qualifier_id for the others.
1281 interface_block_layout_qualifier:
1284 memset(& $$, 0, sizeof($$));
1285 $$.flags.q.row_major = 1;
1289 memset(& $$, 0, sizeof($$));
1290 $$.flags.q.packed = 1;
1294 interpolation_qualifier:
1297 memset(& $$, 0, sizeof($$));
1298 $$.flags.q.smooth = 1;
1302 memset(& $$, 0, sizeof($$));
1303 $$.flags.q.flat = 1;
1307 memset(& $$, 0, sizeof($$));
1308 $$.flags.q.noperspective = 1;
1313 /* Single qualifiers */
1316 memset(& $$, 0, sizeof($$));
1317 $$.flags.q.invariant = 1;
1320 | interpolation_qualifier
1323 /* Multiple qualifiers:
1324 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1325 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1327 * invariant interpolation storage precision ...or...
1328 * layout storage precision
1330 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1331 * side don't contain any that must appear on the left hand side.
1332 * For example, when processing a storage qualifier, we check that there are
1333 * no interpolation, layout, or invariant qualifiers to the right.
1335 | INVARIANT type_qualifier
1337 if ($2.flags.q.invariant)
1338 _mesa_glsl_error(&@1, state, "Duplicate \"invariant\" qualifier.\n");
1340 if ($2.has_layout()) {
1341 _mesa_glsl_error(&@1, state,
1342 "\"invariant\" cannot be used with layout(...).\n");
1346 $$.flags.q.invariant = 1;
1348 | interpolation_qualifier type_qualifier
1350 /* Section 4.3 of the GLSL 1.40 specification states:
1351 * "...qualified with one of these interpolation qualifiers"
1353 * GLSL 1.30 claims to allow "one or more", but insists that:
1354 * "These interpolation qualifiers may only precede the qualifiers in,
1355 * centroid in, out, or centroid out in a declaration."
1357 * ...which means that e.g. smooth can't precede smooth, so there can be
1358 * only one after all, and the 1.40 text is a clarification, not a change.
1360 if ($2.has_interpolation())
1361 _mesa_glsl_error(&@1, state, "Duplicate interpolation qualifier.\n");
1363 if ($2.has_layout()) {
1364 _mesa_glsl_error(&@1, state, "Interpolation qualifiers cannot be used "
1365 "with layout(...).\n");
1368 if (!state->ARB_shading_language_420pack_enable && $2.flags.q.invariant) {
1369 _mesa_glsl_error(&@1, state, "Interpolation qualifiers must come "
1370 "after \"invariant\".\n");
1374 $$.merge_qualifier(&@1, state, $2);
1376 | layout_qualifier type_qualifier
1378 /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be
1379 * used standalone or immediately before a storage qualifier. It cannot
1380 * be used with interpolation qualifiers or invariant. There does not
1381 * appear to be any text indicating that it must come before the storage
1382 * qualifier, but always seems to in examples.
1384 if (!state->ARB_shading_language_420pack_enable && $2.has_layout())
1385 _mesa_glsl_error(&@1, state, "Duplicate layout(...) qualifiers.\n");
1387 if ($2.flags.q.invariant)
1388 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1389 "the \"invariant\" qualifier\n");
1391 if ($2.has_interpolation()) {
1392 _mesa_glsl_error(&@1, state, "layout(...) cannot be used with "
1393 "interpolation qualifiers.\n");
1397 $$.merge_qualifier(&@1, state, $2);
1399 | storage_qualifier type_qualifier
1401 /* Section 4.3 of the GLSL 1.20 specification states:
1402 * "Variable declarations may have a storage qualifier specified..."
1403 * 1.30 clarifies this to "may have one storage qualifier".
1405 if ($2.has_storage())
1406 _mesa_glsl_error(&@1, state, "Duplicate storage qualifier.\n");
1408 if (!state->ARB_shading_language_420pack_enable &&
1409 ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout())) {
1410 _mesa_glsl_error(&@1, state, "Storage qualifiers must come after "
1411 "invariant, interpolation, and layout qualifiers.\n");
1415 $$.merge_qualifier(&@1, state, $2);
1422 memset(& $$, 0, sizeof($$));
1423 $$.flags.q.constant = 1;
1427 memset(& $$, 0, sizeof($$));
1428 $$.flags.q.attribute = 1;
1432 memset(& $$, 0, sizeof($$));
1433 $$.flags.q.varying = 1;
1437 memset(& $$, 0, sizeof($$));
1438 $$.flags.q.centroid = 1;
1439 $$.flags.q.varying = 1;
1443 memset(& $$, 0, sizeof($$));
1448 memset(& $$, 0, sizeof($$));
1453 memset(& $$, 0, sizeof($$));
1454 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1458 memset(& $$, 0, sizeof($$));
1459 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1463 memset(& $$, 0, sizeof($$));
1464 $$.flags.q.uniform = 1;
1469 type_specifier_no_prec
1473 | precision_qualifier type_specifier_no_prec
1480 type_specifier_no_prec:
1481 type_specifier_nonarray
1482 | type_specifier_nonarray '[' ']'
1485 $$->is_array = true;
1486 $$->array_size = NULL;
1488 | type_specifier_nonarray '[' constant_expression ']'
1491 $$->is_array = true;
1492 $$->array_size = $3;
1496 type_specifier_nonarray:
1497 basic_type_specifier_nonarray
1500 $$ = new(ctx) ast_type_specifier($1);
1501 $$->set_location(yylloc);
1506 $$ = new(ctx) ast_type_specifier($1);
1507 $$->set_location(yylloc);
1512 $$ = new(ctx) ast_type_specifier($1);
1513 $$->set_location(yylloc);
1517 basic_type_specifier_nonarray:
1518 VOID_TOK { $$ = "void"; }
1519 | FLOAT_TOK { $$ = "float"; }
1520 | INT_TOK { $$ = "int"; }
1521 | UINT_TOK { $$ = "uint"; }
1522 | BOOL_TOK { $$ = "bool"; }
1523 | VEC2 { $$ = "vec2"; }
1524 | VEC3 { $$ = "vec3"; }
1525 | VEC4 { $$ = "vec4"; }
1526 | BVEC2 { $$ = "bvec2"; }
1527 | BVEC3 { $$ = "bvec3"; }
1528 | BVEC4 { $$ = "bvec4"; }
1529 | IVEC2 { $$ = "ivec2"; }
1530 | IVEC3 { $$ = "ivec3"; }
1531 | IVEC4 { $$ = "ivec4"; }
1532 | UVEC2 { $$ = "uvec2"; }
1533 | UVEC3 { $$ = "uvec3"; }
1534 | UVEC4 { $$ = "uvec4"; }
1535 | MAT2X2 { $$ = "mat2"; }
1536 | MAT2X3 { $$ = "mat2x3"; }
1537 | MAT2X4 { $$ = "mat2x4"; }
1538 | MAT3X2 { $$ = "mat3x2"; }
1539 | MAT3X3 { $$ = "mat3"; }
1540 | MAT3X4 { $$ = "mat3x4"; }
1541 | MAT4X2 { $$ = "mat4x2"; }
1542 | MAT4X3 { $$ = "mat4x3"; }
1543 | MAT4X4 { $$ = "mat4"; }
1544 | SAMPLER1D { $$ = "sampler1D"; }
1545 | SAMPLER2D { $$ = "sampler2D"; }
1546 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1547 | SAMPLER3D { $$ = "sampler3D"; }
1548 | SAMPLERCUBE { $$ = "samplerCube"; }
1549 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1550 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1551 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1552 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1553 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1554 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1555 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1556 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1557 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1558 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1559 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1560 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1561 | ISAMPLER1D { $$ = "isampler1D"; }
1562 | ISAMPLER2D { $$ = "isampler2D"; }
1563 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1564 | ISAMPLER3D { $$ = "isampler3D"; }
1565 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1566 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1567 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1568 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1569 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1570 | USAMPLER1D { $$ = "usampler1D"; }
1571 | USAMPLER2D { $$ = "usampler2D"; }
1572 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1573 | USAMPLER3D { $$ = "usampler3D"; }
1574 | USAMPLERCUBE { $$ = "usamplerCube"; }
1575 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1576 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1577 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1578 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1579 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1580 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1581 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1582 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1583 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1584 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1587 precision_qualifier:
1590 state->check_precision_qualifiers_allowed(&@1);
1591 $$ = ast_precision_high;
1595 state->check_precision_qualifiers_allowed(&@1);
1596 $$ = ast_precision_medium;
1600 state->check_precision_qualifiers_allowed(&@1);
1601 $$ = ast_precision_low;
1606 STRUCT any_identifier '{' struct_declaration_list '}'
1609 $$ = new(ctx) ast_struct_specifier($2, $4);
1610 $$->set_location(yylloc);
1611 state->symbols->add_type($2, glsl_type::void_type);
1612 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1614 | STRUCT '{' struct_declaration_list '}'
1617 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1618 $$->set_location(yylloc);
1622 struct_declaration_list:
1626 $1->link.self_link();
1628 | struct_declaration_list struct_declaration
1631 $$->link.insert_before(& $2->link);
1636 type_specifier struct_declarator_list ';'
1639 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1640 type->set_location(yylloc);
1642 type->specifier = $1;
1643 $$ = new(ctx) ast_declarator_list(type);
1644 $$->set_location(yylloc);
1646 $$->declarations.push_degenerate_list_at_head(& $2->link);
1650 struct_declarator_list:
1654 $1->link.self_link();
1656 | struct_declarator_list ',' struct_declarator
1659 $$->link.insert_before(& $3->link);
1667 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1668 $$->set_location(yylloc);
1670 | any_identifier '[' constant_expression ']'
1673 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1674 $$->set_location(yylloc);
1679 assignment_expression
1680 | '{' initializer_list '}'
1684 | '{' initializer_list ',' '}'
1694 $$ = new(ctx) ast_aggregate_initializer();
1695 $$->set_location(yylloc);
1696 $$->expressions.push_tail(& $1->link);
1698 | initializer_list ',' initializer
1700 $1->expressions.push_tail(& $3->link);
1704 declaration_statement:
1708 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1711 compound_statement { $$ = (ast_node *) $1; }
1716 declaration_statement
1717 | expression_statement
1718 | selection_statement
1720 | iteration_statement
1728 $$ = new(ctx) ast_compound_statement(true, NULL);
1729 $$->set_location(yylloc);
1733 state->symbols->push_scope();
1738 $$ = new(ctx) ast_compound_statement(true, $3);
1739 $$->set_location(yylloc);
1740 state->symbols->pop_scope();
1744 statement_no_new_scope:
1745 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1749 compound_statement_no_new_scope:
1753 $$ = new(ctx) ast_compound_statement(false, NULL);
1754 $$->set_location(yylloc);
1756 | '{' statement_list '}'
1759 $$ = new(ctx) ast_compound_statement(false, $2);
1760 $$->set_location(yylloc);
1768 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1773 $$->link.self_link();
1775 | statement_list statement
1778 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1782 $$->link.insert_before(& $2->link);
1786 expression_statement:
1790 $$ = new(ctx) ast_expression_statement(NULL);
1791 $$->set_location(yylloc);
1796 $$ = new(ctx) ast_expression_statement($1);
1797 $$->set_location(yylloc);
1801 selection_statement:
1802 IF '(' expression ')' selection_rest_statement
1804 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1806 $$->set_location(yylloc);
1810 selection_rest_statement:
1811 statement ELSE statement
1813 $$.then_statement = $1;
1814 $$.else_statement = $3;
1816 | statement %prec THEN
1818 $$.then_statement = $1;
1819 $$.else_statement = NULL;
1826 $$ = (ast_node *) $1;
1828 | fully_specified_type any_identifier '=' initializer
1831 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1832 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1833 decl->set_location(yylloc);
1834 declarator->set_location(yylloc);
1836 declarator->declarations.push_tail(&decl->link);
1842 * siwtch_statement grammar is based on the syntax described in the body
1843 * of the GLSL spec, not in it's appendix!!!
1846 SWITCH '(' expression ')' switch_body
1848 $$ = new(state) ast_switch_statement($3, $5);
1849 $$->set_location(yylloc);
1856 $$ = new(state) ast_switch_body(NULL);
1857 $$->set_location(yylloc);
1859 | '{' case_statement_list '}'
1861 $$ = new(state) ast_switch_body($2);
1862 $$->set_location(yylloc);
1869 $$ = new(state) ast_case_label($2);
1870 $$->set_location(yylloc);
1874 $$ = new(state) ast_case_label(NULL);
1875 $$->set_location(yylloc);
1882 ast_case_label_list *labels = new(state) ast_case_label_list();
1884 labels->labels.push_tail(& $1->link);
1886 $$->set_location(yylloc);
1888 | case_label_list case_label
1891 $$->labels.push_tail(& $2->link);
1896 case_label_list statement
1898 ast_case_statement *stmts = new(state) ast_case_statement($1);
1899 stmts->set_location(yylloc);
1901 stmts->stmts.push_tail(& $2->link);
1904 | case_statement statement
1907 $$->stmts.push_tail(& $2->link);
1911 case_statement_list:
1914 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1915 cases->set_location(yylloc);
1917 cases->cases.push_tail(& $1->link);
1920 | case_statement_list case_statement
1923 $$->cases.push_tail(& $2->link);
1927 iteration_statement:
1928 WHILE '(' condition ')' statement_no_new_scope
1931 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1932 NULL, $3, NULL, $5);
1933 $$->set_location(yylloc);
1935 | DO statement WHILE '(' expression ')' ';'
1938 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1939 NULL, $5, NULL, $2);
1940 $$->set_location(yylloc);
1942 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1945 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1946 $3, $4.cond, $4.rest, $6);
1947 $$->set_location(yylloc);
1952 expression_statement
1953 | declaration_statement
1970 | conditionopt ';' expression
1977 // Grammar Note: No 'goto'. Gotos are not supported.
1982 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1983 $$->set_location(yylloc);
1988 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1989 $$->set_location(yylloc);
1994 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1995 $$->set_location(yylloc);
1997 | RETURN expression ';'
2000 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2001 $$->set_location(yylloc);
2003 | DISCARD ';' // Fragment shader only.
2006 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2007 $$->set_location(yylloc);
2011 external_declaration:
2012 function_definition { $$ = $1; }
2013 | declaration { $$ = $1; }
2014 | pragma_statement { $$ = NULL; }
2015 | layout_defaults { $$ = NULL; }
2018 function_definition:
2019 function_prototype compound_statement_no_new_scope
2022 $$ = new(ctx) ast_function_definition();
2023 $$->set_location(yylloc);
2027 state->symbols->pop_scope();
2031 /* layout_qualifieropt is packed into this rule */
2033 basic_interface_block
2037 | layout_qualifier basic_interface_block
2039 ast_interface_block *block = $2;
2040 if (!block->layout.merge_qualifier(& @1, state, $1)) {
2047 basic_interface_block:
2048 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2050 ast_interface_block *const block = $6;
2052 block->block_name = $2;
2053 block->declarations.push_degenerate_list_at_head(& $4->link);
2055 if ($1.flags.q.uniform) {
2056 if (!state->ARB_uniform_buffer_object_enable) {
2057 _mesa_glsl_error(& @1, state,
2058 "#version 140 / GL_ARB_uniform_buffer_object "
2059 "required for defining uniform blocks\n");
2060 } else if (state->ARB_uniform_buffer_object_warn) {
2061 _mesa_glsl_warning(& @1, state,
2062 "#version 140 / GL_ARB_uniform_buffer_object "
2063 "required for defining uniform blocks\n");
2066 if (state->es_shader || state->language_version < 150) {
2067 _mesa_glsl_error(& @1, state,
2068 "#version 150 required for using "
2069 "interface blocks.\n");
2073 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2074 * "It is illegal to have an input block in a vertex shader
2075 * or an output block in a fragment shader"
2077 if ((state->target == vertex_shader) && $1.flags.q.in) {
2078 _mesa_glsl_error(& @1, state,
2079 "`in' interface block is not allowed for "
2080 "a vertex shader\n");
2081 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2082 _mesa_glsl_error(& @1, state,
2083 "`out' interface block is not allowed for "
2084 "a fragment shader\n");
2087 /* Since block arrays require names, and both features are added in
2088 * the same language versions, we don't have to explicitly
2089 * version-check both things.
2091 if (block->instance_name != NULL) {
2092 state->check_version(150, 300, & @1, "interface blocks with "
2093 "an instance name are not allowed");
2096 unsigned interface_type_mask;
2097 struct ast_type_qualifier temp_type_qualifier;
2099 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2100 * to ignore other irrelevant flags like interpolation qualifiers.
2102 temp_type_qualifier.flags.i = 0;
2103 temp_type_qualifier.flags.q.uniform = true;
2104 temp_type_qualifier.flags.q.in = true;
2105 temp_type_qualifier.flags.q.out = true;
2106 interface_type_mask = temp_type_qualifier.flags.i;
2108 /* Get the block's interface qualifier. The interface_qualifier
2109 * production rule guarantees that only one bit will be set (and
2110 * it will be in/out/uniform).
2112 unsigned block_interface_qualifier = $1.flags.i;
2114 block->layout.flags.i |= block_interface_qualifier;
2116 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2117 ast_type_qualifier& qualifier = member->type->qualifier;
2118 if ((qualifier.flags.i & interface_type_mask) == 0) {
2119 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2120 * "If no optional qualifier is used in a member declaration, the
2121 * qualifier of the variable is just in, out, or uniform as declared
2122 * by interface-qualifier."
2124 qualifier.flags.i |= block_interface_qualifier;
2125 } else if ((qualifier.flags.i & interface_type_mask) !=
2126 block_interface_qualifier) {
2127 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2128 * "If optional qualifiers are used, they can include interpolation
2129 * and storage qualifiers and they must declare an input, output,
2130 * or uniform variable consistent with the interface qualifier of
2133 _mesa_glsl_error(& @1, state,
2134 "uniform/in/out qualifier on "
2135 "interface block member does not match "
2136 "the interface block\n");
2144 interface_qualifier:
2147 memset(& $$, 0, sizeof($$));
2152 memset(& $$, 0, sizeof($$));
2157 memset(& $$, 0, sizeof($$));
2158 $$.flags.q.uniform = 1;
2165 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2170 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2173 | NEW_IDENTIFIER '[' constant_expression ']'
2175 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2178 | NEW_IDENTIFIER '[' ']'
2180 _mesa_glsl_error(& @1, state,
2181 "instance block arrays must be explicitly sized\n");
2183 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2192 $1->link.self_link();
2194 | member_declaration member_list
2197 $2->link.insert_before(& $$->link);
2202 fully_specified_type struct_declarator_list ';'
2205 ast_fully_specified_type *type = $1;
2206 type->set_location(yylloc);
2208 if (type->qualifier.flags.q.attribute) {
2209 _mesa_glsl_error(& @1, state,
2210 "keyword 'attribute' cannot be used with "
2211 "interface block member\n");
2212 } else if (type->qualifier.flags.q.varying) {
2213 _mesa_glsl_error(& @1, state,
2214 "keyword 'varying' cannot be used with "
2215 "interface block member\n");
2218 $$ = new(ctx) ast_declarator_list(type);
2219 $$->set_location(yylloc);
2220 $$->ubo_qualifiers_valid = true;
2222 $$->declarations.push_degenerate_list_at_head(& $2->link);
2227 layout_qualifier UNIFORM ';'
2229 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) {