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);
56 %lex-param {void *scanner}
57 %parse-param {struct _mesa_glsl_parse_state *state}
62 const char *identifier;
64 struct ast_type_qualifier type_qualifier;
67 ast_type_specifier *type_specifier;
68 ast_fully_specified_type *fully_specified_type;
69 ast_function *function;
70 ast_parameter_declarator *parameter_declarator;
71 ast_function_definition *function_definition;
72 ast_compound_statement *compound_statement;
73 ast_expression *expression;
74 ast_declarator_list *declarator_list;
75 ast_struct_specifier *struct_specifier;
76 ast_declaration *declaration;
77 ast_switch_body *switch_body;
78 ast_case_label *case_label;
79 ast_case_label_list *case_label_list;
80 ast_case_statement *case_statement;
81 ast_case_statement_list *case_statement_list;
82 ast_interface_block *interface_block;
90 ast_node *then_statement;
91 ast_node *else_statement;
92 } selection_rest_statement;
95 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
96 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
97 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
98 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
99 %token NOPERSPECTIVE FLAT SMOOTH
100 %token MAT2X2 MAT2X3 MAT2X4
101 %token MAT3X2 MAT3X3 MAT3X4
102 %token MAT4X2 MAT4X3 MAT4X4
103 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
104 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
105 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
106 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
107 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
108 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
109 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
110 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
111 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
112 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
113 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
114 %token SAMPLEREXTERNALOES
115 %token STRUCT VOID_TOK WHILE
116 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
117 %type <identifier> any_identifier
118 %type <interface_block> instance_name_opt
119 %token <real> FLOATCONSTANT
120 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
121 %token <identifier> FIELD_SELECTION
122 %token LEFT_OP RIGHT_OP
123 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
124 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
125 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
128 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
130 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
131 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
132 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
133 %token PRAGMA_INVARIANT_ALL
136 /* Reserved words that are not actually used in the grammar.
138 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
139 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
140 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
141 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
143 %token SIZEOF CAST NAMESPACE USING
144 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
149 %token COMMON PARTITION ACTIVE FILTER
150 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
151 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
152 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
153 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
154 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
157 %type <identifier> variable_identifier
158 %type <node> statement
159 %type <node> statement_list
160 %type <node> simple_statement
161 %type <n> precision_qualifier
162 %type <type_qualifier> type_qualifier
163 %type <type_qualifier> storage_qualifier
164 %type <type_qualifier> interpolation_qualifier
165 %type <type_qualifier> layout_qualifier
166 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
167 %type <type_qualifier> interface_block_layout_qualifier
168 %type <type_qualifier> interface_qualifier
169 %type <type_specifier> type_specifier
170 %type <type_specifier> type_specifier_no_prec
171 %type <type_specifier> type_specifier_nonarray
172 %type <identifier> basic_type_specifier_nonarray
173 %type <fully_specified_type> fully_specified_type
174 %type <function> function_prototype
175 %type <function> function_header
176 %type <function> function_header_with_parameters
177 %type <function> function_declarator
178 %type <parameter_declarator> parameter_declarator
179 %type <parameter_declarator> parameter_declaration
180 %type <type_qualifier> parameter_qualifier
181 %type <type_qualifier> parameter_type_qualifier
182 %type <type_specifier> parameter_type_specifier
183 %type <function_definition> function_definition
184 %type <compound_statement> compound_statement_no_new_scope
185 %type <compound_statement> compound_statement
186 %type <node> statement_no_new_scope
187 %type <node> expression_statement
188 %type <expression> expression
189 %type <expression> primary_expression
190 %type <expression> assignment_expression
191 %type <expression> conditional_expression
192 %type <expression> logical_or_expression
193 %type <expression> logical_xor_expression
194 %type <expression> logical_and_expression
195 %type <expression> inclusive_or_expression
196 %type <expression> exclusive_or_expression
197 %type <expression> and_expression
198 %type <expression> equality_expression
199 %type <expression> relational_expression
200 %type <expression> shift_expression
201 %type <expression> additive_expression
202 %type <expression> multiplicative_expression
203 %type <expression> unary_expression
204 %type <expression> constant_expression
205 %type <expression> integer_expression
206 %type <expression> postfix_expression
207 %type <expression> function_call_header_with_parameters
208 %type <expression> function_call_header_no_parameters
209 %type <expression> function_call_header
210 %type <expression> function_call_generic
211 %type <expression> function_call_or_method
212 %type <expression> function_call
213 %type <expression> method_call_generic
214 %type <expression> method_call_header_with_parameters
215 %type <expression> method_call_header_no_parameters
216 %type <expression> method_call_header
217 %type <n> assignment_operator
218 %type <n> unary_operator
219 %type <expression> function_identifier
220 %type <node> external_declaration
221 %type <declarator_list> init_declarator_list
222 %type <declarator_list> single_declaration
223 %type <expression> initializer
224 %type <expression> initializer_list
225 %type <node> declaration
226 %type <node> declaration_statement
227 %type <node> jump_statement
228 %type <node> interface_block
229 %type <interface_block> basic_interface_block
230 %type <struct_specifier> struct_specifier
231 %type <declarator_list> struct_declaration_list
232 %type <declarator_list> struct_declaration
233 %type <declaration> struct_declarator
234 %type <declaration> struct_declarator_list
235 %type <declarator_list> member_list
236 %type <declarator_list> member_declaration
237 %type <node> selection_statement
238 %type <selection_rest_statement> selection_rest_statement
239 %type <node> switch_statement
240 %type <switch_body> switch_body
241 %type <case_label_list> case_label_list
242 %type <case_label> case_label
243 %type <case_statement> case_statement
244 %type <case_statement_list> case_statement_list
245 %type <node> iteration_statement
246 %type <node> condition
247 %type <node> conditionopt
248 %type <node> for_init_statement
249 %type <for_rest_statement> for_rest_statement
250 %type <n> integer_constant
256 version_statement extension_statement_list
258 _mesa_glsl_initialize_types(state);
260 external_declaration_list
262 delete state->symbols;
263 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
264 _mesa_glsl_initialize_types(state);
269 /* blank - no #version specified: defaults are already set */
270 | VERSION_TOK INTCONSTANT EOL
272 state->process_version_directive(&@2, $2, NULL);
277 | VERSION_TOK INTCONSTANT any_identifier EOL
279 state->process_version_directive(&@2, $2, $3);
288 | PRAGMA_DEBUG_OFF EOL
289 | PRAGMA_OPTIMIZE_ON EOL
290 | PRAGMA_OPTIMIZE_OFF EOL
291 | PRAGMA_INVARIANT_ALL EOL
293 if (!state->is_version(120, 100)) {
294 _mesa_glsl_warning(& @1, state,
295 "pragma `invariant(all)' not supported in %s "
296 "(GLSL ES 1.00 or GLSL 1.20 required).",
297 state->get_version_string());
299 state->all_invariant = true;
304 extension_statement_list:
306 | extension_statement_list extension_statement
316 EXTENSION any_identifier COLON any_identifier EOL
318 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
324 external_declaration_list:
327 /* FINISHME: The NULL test is required because pragmas are set to
328 * FINISHME: NULL. (See production rule for external_declaration.)
331 state->translation_unit.push_tail(& $1->link);
333 | external_declaration_list external_declaration
335 /* FINISHME: The NULL test is required because pragmas are set to
336 * FINISHME: NULL. (See production rule for external_declaration.)
339 state->translation_unit.push_tail(& $2->link);
352 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
353 $$->set_location(yylloc);
354 $$->primary_expression.identifier = $1;
359 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
360 $$->set_location(yylloc);
361 $$->primary_expression.int_constant = $1;
366 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
367 $$->set_location(yylloc);
368 $$->primary_expression.uint_constant = $1;
373 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
374 $$->set_location(yylloc);
375 $$->primary_expression.float_constant = $1;
380 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
381 $$->set_location(yylloc);
382 $$->primary_expression.bool_constant = $1;
392 | postfix_expression '[' integer_expression ']'
395 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
396 $$->set_location(yylloc);
402 | postfix_expression '.' any_identifier
405 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
406 $$->set_location(yylloc);
407 $$->primary_expression.identifier = $3;
409 | postfix_expression INC_OP
412 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
413 $$->set_location(yylloc);
415 | postfix_expression DEC_OP
418 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
419 $$->set_location(yylloc);
428 function_call_or_method
431 function_call_or_method:
432 function_call_generic
433 | postfix_expression '.' method_call_generic
436 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
437 $$->set_location(yylloc);
441 function_call_generic:
442 function_call_header_with_parameters ')'
443 | function_call_header_no_parameters ')'
446 function_call_header_no_parameters:
447 function_call_header VOID_TOK
448 | function_call_header
451 function_call_header_with_parameters:
452 function_call_header assignment_expression
455 $$->set_location(yylloc);
456 $$->expressions.push_tail(& $2->link);
458 | function_call_header_with_parameters ',' assignment_expression
461 $$->set_location(yylloc);
462 $$->expressions.push_tail(& $3->link);
466 // Grammar Note: Constructors look like functions, but lexical
467 // analysis recognized most of them as keywords. They are now
468 // recognized through "type_specifier".
469 function_call_header:
470 function_identifier '('
477 $$ = new(ctx) ast_function_expression($1);
478 $$->set_location(yylloc);
480 | variable_identifier
483 ast_expression *callee = new(ctx) ast_expression($1);
484 $$ = new(ctx) ast_function_expression(callee);
485 $$->set_location(yylloc);
490 ast_expression *callee = new(ctx) ast_expression($1);
491 $$ = new(ctx) ast_function_expression(callee);
492 $$->set_location(yylloc);
497 method_call_header_with_parameters ')'
498 | method_call_header_no_parameters ')'
501 method_call_header_no_parameters:
502 method_call_header VOID_TOK
506 method_call_header_with_parameters:
507 method_call_header assignment_expression
510 $$->set_location(yylloc);
511 $$->expressions.push_tail(& $2->link);
513 | method_call_header_with_parameters ',' assignment_expression
516 $$->set_location(yylloc);
517 $$->expressions.push_tail(& $3->link);
521 // Grammar Note: Constructors look like methods, but lexical
522 // analysis recognized most of them as keywords. They are now
523 // recognized through "type_specifier".
525 variable_identifier '('
528 ast_expression *callee = new(ctx) ast_expression($1);
529 $$ = new(ctx) ast_function_expression(callee);
530 $$->set_location(yylloc);
534 // Grammar Note: No traditional style type casts.
537 | INC_OP unary_expression
540 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
541 $$->set_location(yylloc);
543 | DEC_OP unary_expression
546 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
547 $$->set_location(yylloc);
549 | unary_operator unary_expression
552 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
553 $$->set_location(yylloc);
557 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
559 '+' { $$ = ast_plus; }
560 | '-' { $$ = ast_neg; }
561 | '!' { $$ = ast_logic_not; }
562 | '~' { $$ = ast_bit_not; }
565 multiplicative_expression:
567 | multiplicative_expression '*' unary_expression
570 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
571 $$->set_location(yylloc);
573 | multiplicative_expression '/' unary_expression
576 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
577 $$->set_location(yylloc);
579 | multiplicative_expression '%' unary_expression
582 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
583 $$->set_location(yylloc);
588 multiplicative_expression
589 | additive_expression '+' multiplicative_expression
592 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
593 $$->set_location(yylloc);
595 | additive_expression '-' multiplicative_expression
598 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
599 $$->set_location(yylloc);
605 | shift_expression LEFT_OP additive_expression
608 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
609 $$->set_location(yylloc);
611 | shift_expression RIGHT_OP additive_expression
614 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
615 $$->set_location(yylloc);
619 relational_expression:
621 | relational_expression '<' shift_expression
624 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
625 $$->set_location(yylloc);
627 | relational_expression '>' shift_expression
630 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
631 $$->set_location(yylloc);
633 | relational_expression LE_OP shift_expression
636 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
637 $$->set_location(yylloc);
639 | relational_expression GE_OP shift_expression
642 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
643 $$->set_location(yylloc);
648 relational_expression
649 | equality_expression EQ_OP relational_expression
652 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
653 $$->set_location(yylloc);
655 | equality_expression NE_OP relational_expression
658 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
659 $$->set_location(yylloc);
665 | and_expression '&' equality_expression
668 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
669 $$->set_location(yylloc);
673 exclusive_or_expression:
675 | exclusive_or_expression '^' and_expression
678 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
679 $$->set_location(yylloc);
683 inclusive_or_expression:
684 exclusive_or_expression
685 | inclusive_or_expression '|' exclusive_or_expression
688 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
689 $$->set_location(yylloc);
693 logical_and_expression:
694 inclusive_or_expression
695 | logical_and_expression AND_OP inclusive_or_expression
698 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
699 $$->set_location(yylloc);
703 logical_xor_expression:
704 logical_and_expression
705 | logical_xor_expression XOR_OP logical_and_expression
708 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
709 $$->set_location(yylloc);
713 logical_or_expression:
714 logical_xor_expression
715 | logical_or_expression OR_OP logical_xor_expression
718 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
719 $$->set_location(yylloc);
723 conditional_expression:
724 logical_or_expression
725 | logical_or_expression '?' expression ':' assignment_expression
728 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
729 $$->set_location(yylloc);
733 assignment_expression:
734 conditional_expression
735 | unary_expression assignment_operator assignment_expression
738 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
739 $$->set_location(yylloc);
744 '=' { $$ = ast_assign; }
745 | MUL_ASSIGN { $$ = ast_mul_assign; }
746 | DIV_ASSIGN { $$ = ast_div_assign; }
747 | MOD_ASSIGN { $$ = ast_mod_assign; }
748 | ADD_ASSIGN { $$ = ast_add_assign; }
749 | SUB_ASSIGN { $$ = ast_sub_assign; }
750 | LEFT_ASSIGN { $$ = ast_ls_assign; }
751 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
752 | AND_ASSIGN { $$ = ast_and_assign; }
753 | XOR_ASSIGN { $$ = ast_xor_assign; }
754 | OR_ASSIGN { $$ = ast_or_assign; }
758 assignment_expression
762 | expression ',' assignment_expression
765 if ($1->oper != ast_sequence) {
766 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
767 $$->set_location(yylloc);
768 $$->expressions.push_tail(& $1->link);
773 $$->expressions.push_tail(& $3->link);
778 conditional_expression
782 function_prototype ';'
784 state->symbols->pop_scope();
787 | init_declarator_list ';'
791 | PRECISION precision_qualifier type_specifier_no_prec ';'
794 $3->is_precision_statement = true;
804 function_declarator ')'
809 | function_header_with_parameters
812 function_header_with_parameters:
813 function_header parameter_declaration
816 $$->parameters.push_tail(& $2->link);
818 | function_header_with_parameters ',' parameter_declaration
821 $$->parameters.push_tail(& $3->link);
826 fully_specified_type variable_identifier '('
829 $$ = new(ctx) ast_function();
830 $$->set_location(yylloc);
831 $$->return_type = $1;
834 state->symbols->add_function(new(state) ir_function($2));
835 state->symbols->push_scope();
839 parameter_declarator:
840 type_specifier any_identifier
843 $$ = new(ctx) ast_parameter_declarator();
844 $$->set_location(yylloc);
845 $$->type = new(ctx) ast_fully_specified_type();
846 $$->type->set_location(yylloc);
847 $$->type->specifier = $1;
850 | type_specifier any_identifier '[' constant_expression ']'
853 $$ = new(ctx) ast_parameter_declarator();
854 $$->set_location(yylloc);
855 $$->type = new(ctx) ast_fully_specified_type();
856 $$->type->set_location(yylloc);
857 $$->type->specifier = $1;
864 parameter_declaration:
865 parameter_type_qualifier parameter_qualifier parameter_declarator
867 $1.flags.i |= $2.flags.i;
870 $$->type->qualifier = $1;
872 | parameter_qualifier parameter_declarator
875 $$->type->qualifier = $1;
877 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
880 $1.flags.i |= $2.flags.i;
882 $$ = new(ctx) ast_parameter_declarator();
883 $$->set_location(yylloc);
884 $$->type = new(ctx) ast_fully_specified_type();
885 $$->type->qualifier = $1;
886 $$->type->specifier = $3;
888 | parameter_qualifier parameter_type_specifier
891 $$ = new(ctx) ast_parameter_declarator();
892 $$->set_location(yylloc);
893 $$->type = new(ctx) ast_fully_specified_type();
894 $$->type->qualifier = $1;
895 $$->type->specifier = $2;
902 memset(& $$, 0, sizeof($$));
906 memset(& $$, 0, sizeof($$));
911 memset(& $$, 0, sizeof($$));
916 memset(& $$, 0, sizeof($$));
922 parameter_type_specifier:
926 init_declarator_list:
928 | init_declarator_list ',' any_identifier
931 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
932 decl->set_location(yylloc);
935 $$->declarations.push_tail(&decl->link);
936 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
938 | init_declarator_list ',' any_identifier '[' ']'
941 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
942 decl->set_location(yylloc);
945 $$->declarations.push_tail(&decl->link);
946 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
948 | init_declarator_list ',' any_identifier '[' constant_expression ']'
951 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
952 decl->set_location(yylloc);
955 $$->declarations.push_tail(&decl->link);
956 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
958 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
961 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
962 decl->set_location(yylloc);
965 $$->declarations.push_tail(&decl->link);
966 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
967 if ($7->oper == ast_aggregate) {
968 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
969 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
970 _mesa_ast_set_aggregate_type(type, ai, state);
973 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
976 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
977 decl->set_location(yylloc);
980 $$->declarations.push_tail(&decl->link);
981 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
982 if ($8->oper == ast_aggregate) {
983 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
984 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
985 _mesa_ast_set_aggregate_type(type, ai, state);
988 | init_declarator_list ',' any_identifier '=' initializer
991 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
992 decl->set_location(yylloc);
995 $$->declarations.push_tail(&decl->link);
996 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
997 if ($5->oper == ast_aggregate) {
998 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
999 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1004 // Grammar Note: No 'enum', or 'typedef'.
1006 fully_specified_type
1009 /* Empty declaration list is valid. */
1010 $$ = new(ctx) ast_declarator_list($1);
1011 $$->set_location(yylloc);
1013 | fully_specified_type any_identifier
1016 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1018 $$ = new(ctx) ast_declarator_list($1);
1019 $$->set_location(yylloc);
1020 $$->declarations.push_tail(&decl->link);
1022 | fully_specified_type any_identifier '[' ']'
1025 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1027 $$ = new(ctx) ast_declarator_list($1);
1028 $$->set_location(yylloc);
1029 $$->declarations.push_tail(&decl->link);
1031 | fully_specified_type any_identifier '[' constant_expression ']'
1034 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1036 $$ = new(ctx) ast_declarator_list($1);
1037 $$->set_location(yylloc);
1038 $$->declarations.push_tail(&decl->link);
1040 | fully_specified_type any_identifier '[' ']' '=' initializer
1043 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1045 $$ = new(ctx) ast_declarator_list($1);
1046 $$->set_location(yylloc);
1047 $$->declarations.push_tail(&decl->link);
1048 if ($6->oper == ast_aggregate) {
1049 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1050 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1051 _mesa_ast_set_aggregate_type(type, ai, state);
1054 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1057 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1059 $$ = new(ctx) ast_declarator_list($1);
1060 $$->set_location(yylloc);
1061 $$->declarations.push_tail(&decl->link);
1062 if ($7->oper == ast_aggregate) {
1063 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1064 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1065 _mesa_ast_set_aggregate_type(type, ai, state);
1068 | fully_specified_type any_identifier '=' initializer
1071 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1073 $$ = new(ctx) ast_declarator_list($1);
1074 $$->set_location(yylloc);
1075 $$->declarations.push_tail(&decl->link);
1076 if ($4->oper == ast_aggregate) {
1077 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1080 | INVARIANT variable_identifier // Vertex only.
1083 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1085 $$ = new(ctx) ast_declarator_list(NULL);
1086 $$->set_location(yylloc);
1087 $$->invariant = true;
1089 $$->declarations.push_tail(&decl->link);
1093 fully_specified_type:
1097 $$ = new(ctx) ast_fully_specified_type();
1098 $$->set_location(yylloc);
1101 | type_qualifier type_specifier
1104 $$ = new(ctx) ast_fully_specified_type();
1105 $$->set_location(yylloc);
1112 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1118 layout_qualifier_id_list:
1120 | layout_qualifier_id_list ',' layout_qualifier_id
1123 if (!$$.merge_qualifier(& @3, state, $3)) {
1130 INTCONSTANT { $$ = $1; }
1131 | UINTCONSTANT { $$ = $1; }
1134 layout_qualifier_id:
1137 memset(& $$, 0, sizeof($$));
1139 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1140 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1141 if (strcmp($1, "origin_upper_left") == 0) {
1142 $$.flags.q.origin_upper_left = 1;
1143 } else if (strcmp($1, "pixel_center_integer") == 0) {
1144 $$.flags.q.pixel_center_integer = 1;
1147 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1148 _mesa_glsl_warning(& @1, state,
1149 "GL_ARB_fragment_coord_conventions layout "
1150 "identifier `%s' used\n", $1);
1154 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1156 (state->AMD_conservative_depth_enable ||
1157 state->ARB_conservative_depth_enable)) {
1158 if (strcmp($1, "depth_any") == 0) {
1159 $$.flags.q.depth_any = 1;
1160 } else if (strcmp($1, "depth_greater") == 0) {
1161 $$.flags.q.depth_greater = 1;
1162 } else if (strcmp($1, "depth_less") == 0) {
1163 $$.flags.q.depth_less = 1;
1164 } else if (strcmp($1, "depth_unchanged") == 0) {
1165 $$.flags.q.depth_unchanged = 1;
1168 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1169 _mesa_glsl_warning(& @1, state,
1170 "GL_AMD_conservative_depth "
1171 "layout qualifier `%s' is used\n", $1);
1173 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1174 _mesa_glsl_warning(& @1, state,
1175 "GL_ARB_conservative_depth "
1176 "layout qualifier `%s' is used\n", $1);
1180 /* See also interface_block_layout_qualifier. */
1181 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1182 if (strcmp($1, "std140") == 0) {
1183 $$.flags.q.std140 = 1;
1184 } else if (strcmp($1, "shared") == 0) {
1185 $$.flags.q.shared = 1;
1186 } else if (strcmp($1, "column_major") == 0) {
1187 $$.flags.q.column_major = 1;
1188 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1189 * below in the interface_block_layout_qualifier rule.
1191 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1194 } else if (strcmp($1, "row_major") == 0) {
1195 $$.flags.q.row_major = 1;
1198 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1199 _mesa_glsl_warning(& @1, state,
1200 "#version 140 / GL_ARB_uniform_buffer_object "
1201 "layout qualifier `%s' is used\n", $1);
1206 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1211 | any_identifier '=' integer_constant
1213 memset(& $$, 0, sizeof($$));
1215 if (state->ARB_explicit_attrib_location_enable) {
1216 if (strcmp("location", $1) == 0) {
1217 $$.flags.q.explicit_location = 1;
1222 _mesa_glsl_error(& @3, state,
1223 "invalid location %d specified\n", $3);
1228 if (strcmp("index", $1) == 0) {
1229 $$.flags.q.explicit_index = 1;
1234 _mesa_glsl_error(& @3, state,
1235 "invalid index %d specified\n", $3);
1241 /* If the identifier didn't match any known layout identifiers,
1245 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1248 } else if (state->ARB_explicit_attrib_location_warn) {
1249 _mesa_glsl_warning(& @1, state,
1250 "GL_ARB_explicit_attrib_location layout "
1251 "identifier `%s' used\n", $1);
1254 | interface_block_layout_qualifier
1257 /* Layout qualifiers for ARB_uniform_buffer_object. */
1258 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1259 _mesa_glsl_error(& @1, state,
1260 "#version 140 / GL_ARB_uniform_buffer_object "
1261 "layout qualifier `%s' is used\n", $1);
1262 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1263 _mesa_glsl_warning(& @1, state,
1264 "#version 140 / GL_ARB_uniform_buffer_object "
1265 "layout qualifier `%s' is used\n", $1);
1270 /* This is a separate language rule because we parse these as tokens
1271 * (due to them being reserved keywords) instead of identifiers like
1272 * most qualifiers. See the any_identifier path of
1273 * layout_qualifier_id for the others.
1275 interface_block_layout_qualifier:
1278 memset(& $$, 0, sizeof($$));
1279 $$.flags.q.row_major = 1;
1283 memset(& $$, 0, sizeof($$));
1284 $$.flags.q.packed = 1;
1288 interpolation_qualifier:
1291 memset(& $$, 0, sizeof($$));
1292 $$.flags.q.smooth = 1;
1296 memset(& $$, 0, sizeof($$));
1297 $$.flags.q.flat = 1;
1301 memset(& $$, 0, sizeof($$));
1302 $$.flags.q.noperspective = 1;
1306 parameter_type_qualifier:
1309 memset(& $$, 0, sizeof($$));
1310 $$.flags.q.constant = 1;
1317 | layout_qualifier storage_qualifier
1320 $$.flags.i |= $2.flags.i;
1322 | interpolation_qualifier
1323 | interpolation_qualifier storage_qualifier
1326 $$.flags.i |= $2.flags.i;
1328 | INVARIANT storage_qualifier
1331 $$.flags.q.invariant = 1;
1333 | INVARIANT interpolation_qualifier storage_qualifier
1336 $$.flags.i |= $3.flags.i;
1337 $$.flags.q.invariant = 1;
1341 memset(& $$, 0, sizeof($$));
1342 $$.flags.q.invariant = 1;
1349 memset(& $$, 0, sizeof($$));
1350 $$.flags.q.constant = 1;
1354 memset(& $$, 0, sizeof($$));
1355 $$.flags.q.attribute = 1;
1359 memset(& $$, 0, sizeof($$));
1360 $$.flags.q.varying = 1;
1364 memset(& $$, 0, sizeof($$));
1365 $$.flags.q.centroid = 1;
1366 $$.flags.q.varying = 1;
1370 memset(& $$, 0, sizeof($$));
1375 memset(& $$, 0, sizeof($$));
1380 memset(& $$, 0, sizeof($$));
1381 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1385 memset(& $$, 0, sizeof($$));
1386 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1390 memset(& $$, 0, sizeof($$));
1391 $$.flags.q.uniform = 1;
1396 type_specifier_no_prec
1400 | precision_qualifier type_specifier_no_prec
1407 type_specifier_no_prec:
1408 type_specifier_nonarray
1409 | type_specifier_nonarray '[' ']'
1412 $$->is_array = true;
1413 $$->array_size = NULL;
1415 | type_specifier_nonarray '[' constant_expression ']'
1418 $$->is_array = true;
1419 $$->array_size = $3;
1423 type_specifier_nonarray:
1424 basic_type_specifier_nonarray
1427 $$ = new(ctx) ast_type_specifier($1);
1428 $$->set_location(yylloc);
1433 $$ = new(ctx) ast_type_specifier($1);
1434 $$->set_location(yylloc);
1439 $$ = new(ctx) ast_type_specifier($1);
1440 $$->set_location(yylloc);
1444 basic_type_specifier_nonarray:
1445 VOID_TOK { $$ = "void"; }
1446 | FLOAT_TOK { $$ = "float"; }
1447 | INT_TOK { $$ = "int"; }
1448 | UINT_TOK { $$ = "uint"; }
1449 | BOOL_TOK { $$ = "bool"; }
1450 | VEC2 { $$ = "vec2"; }
1451 | VEC3 { $$ = "vec3"; }
1452 | VEC4 { $$ = "vec4"; }
1453 | BVEC2 { $$ = "bvec2"; }
1454 | BVEC3 { $$ = "bvec3"; }
1455 | BVEC4 { $$ = "bvec4"; }
1456 | IVEC2 { $$ = "ivec2"; }
1457 | IVEC3 { $$ = "ivec3"; }
1458 | IVEC4 { $$ = "ivec4"; }
1459 | UVEC2 { $$ = "uvec2"; }
1460 | UVEC3 { $$ = "uvec3"; }
1461 | UVEC4 { $$ = "uvec4"; }
1462 | MAT2X2 { $$ = "mat2"; }
1463 | MAT2X3 { $$ = "mat2x3"; }
1464 | MAT2X4 { $$ = "mat2x4"; }
1465 | MAT3X2 { $$ = "mat3x2"; }
1466 | MAT3X3 { $$ = "mat3"; }
1467 | MAT3X4 { $$ = "mat3x4"; }
1468 | MAT4X2 { $$ = "mat4x2"; }
1469 | MAT4X3 { $$ = "mat4x3"; }
1470 | MAT4X4 { $$ = "mat4"; }
1471 | SAMPLER1D { $$ = "sampler1D"; }
1472 | SAMPLER2D { $$ = "sampler2D"; }
1473 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1474 | SAMPLER3D { $$ = "sampler3D"; }
1475 | SAMPLERCUBE { $$ = "samplerCube"; }
1476 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1477 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1478 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1479 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1480 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1481 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1482 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1483 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1484 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1485 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1486 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1487 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1488 | ISAMPLER1D { $$ = "isampler1D"; }
1489 | ISAMPLER2D { $$ = "isampler2D"; }
1490 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1491 | ISAMPLER3D { $$ = "isampler3D"; }
1492 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1493 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1494 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1495 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1496 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1497 | USAMPLER1D { $$ = "usampler1D"; }
1498 | USAMPLER2D { $$ = "usampler2D"; }
1499 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1500 | USAMPLER3D { $$ = "usampler3D"; }
1501 | USAMPLERCUBE { $$ = "usamplerCube"; }
1502 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1503 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1504 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1505 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1506 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1507 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1508 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1509 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1510 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1511 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1514 precision_qualifier:
1516 state->check_precision_qualifiers_allowed(&@1);
1518 $$ = ast_precision_high;
1521 state->check_precision_qualifiers_allowed(&@1);
1523 $$ = ast_precision_medium;
1526 state->check_precision_qualifiers_allowed(&@1);
1528 $$ = ast_precision_low;
1533 STRUCT any_identifier '{' struct_declaration_list '}'
1536 $$ = new(ctx) ast_struct_specifier($2, $4);
1537 $$->set_location(yylloc);
1538 state->symbols->add_type($2, glsl_type::void_type);
1539 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1541 | STRUCT '{' struct_declaration_list '}'
1544 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1545 $$->set_location(yylloc);
1549 struct_declaration_list:
1553 $1->link.self_link();
1555 | struct_declaration_list struct_declaration
1558 $$->link.insert_before(& $2->link);
1563 type_specifier struct_declarator_list ';'
1566 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1567 type->set_location(yylloc);
1569 type->specifier = $1;
1570 $$ = new(ctx) ast_declarator_list(type);
1571 $$->set_location(yylloc);
1573 $$->declarations.push_degenerate_list_at_head(& $2->link);
1577 struct_declarator_list:
1581 $1->link.self_link();
1583 | struct_declarator_list ',' struct_declarator
1586 $$->link.insert_before(& $3->link);
1594 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1595 $$->set_location(yylloc);
1597 | any_identifier '[' constant_expression ']'
1600 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1601 $$->set_location(yylloc);
1606 assignment_expression
1607 | '{' initializer_list '}'
1611 | '{' initializer_list ',' '}'
1621 $$ = new(ctx) ast_aggregate_initializer();
1622 $$->set_location(yylloc);
1623 $$->expressions.push_tail(& $1->link);
1625 | initializer_list ',' initializer
1627 $1->expressions.push_tail(& $3->link);
1631 declaration_statement:
1635 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1638 compound_statement { $$ = (ast_node *) $1; }
1643 declaration_statement
1644 | expression_statement
1645 | selection_statement
1647 | iteration_statement
1655 $$ = new(ctx) ast_compound_statement(true, NULL);
1656 $$->set_location(yylloc);
1660 state->symbols->push_scope();
1665 $$ = new(ctx) ast_compound_statement(true, $3);
1666 $$->set_location(yylloc);
1667 state->symbols->pop_scope();
1671 statement_no_new_scope:
1672 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1676 compound_statement_no_new_scope:
1680 $$ = new(ctx) ast_compound_statement(false, NULL);
1681 $$->set_location(yylloc);
1683 | '{' statement_list '}'
1686 $$ = new(ctx) ast_compound_statement(false, $2);
1687 $$->set_location(yylloc);
1695 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1700 $$->link.self_link();
1702 | statement_list statement
1705 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1709 $$->link.insert_before(& $2->link);
1713 expression_statement:
1717 $$ = new(ctx) ast_expression_statement(NULL);
1718 $$->set_location(yylloc);
1723 $$ = new(ctx) ast_expression_statement($1);
1724 $$->set_location(yylloc);
1728 selection_statement:
1729 IF '(' expression ')' selection_rest_statement
1731 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1733 $$->set_location(yylloc);
1737 selection_rest_statement:
1738 statement ELSE statement
1740 $$.then_statement = $1;
1741 $$.else_statement = $3;
1743 | statement %prec THEN
1745 $$.then_statement = $1;
1746 $$.else_statement = NULL;
1753 $$ = (ast_node *) $1;
1755 | fully_specified_type any_identifier '=' initializer
1758 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1759 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1760 decl->set_location(yylloc);
1761 declarator->set_location(yylloc);
1763 declarator->declarations.push_tail(&decl->link);
1769 * siwtch_statement grammar is based on the syntax described in the body
1770 * of the GLSL spec, not in it's appendix!!!
1773 SWITCH '(' expression ')' switch_body
1775 $$ = new(state) ast_switch_statement($3, $5);
1776 $$->set_location(yylloc);
1783 $$ = new(state) ast_switch_body(NULL);
1784 $$->set_location(yylloc);
1786 | '{' case_statement_list '}'
1788 $$ = new(state) ast_switch_body($2);
1789 $$->set_location(yylloc);
1796 $$ = new(state) ast_case_label($2);
1797 $$->set_location(yylloc);
1801 $$ = new(state) ast_case_label(NULL);
1802 $$->set_location(yylloc);
1809 ast_case_label_list *labels = new(state) ast_case_label_list();
1811 labels->labels.push_tail(& $1->link);
1813 $$->set_location(yylloc);
1815 | case_label_list case_label
1818 $$->labels.push_tail(& $2->link);
1823 case_label_list statement
1825 ast_case_statement *stmts = new(state) ast_case_statement($1);
1826 stmts->set_location(yylloc);
1828 stmts->stmts.push_tail(& $2->link);
1831 | case_statement statement
1834 $$->stmts.push_tail(& $2->link);
1838 case_statement_list:
1841 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1842 cases->set_location(yylloc);
1844 cases->cases.push_tail(& $1->link);
1847 | case_statement_list case_statement
1850 $$->cases.push_tail(& $2->link);
1854 iteration_statement:
1855 WHILE '(' condition ')' statement_no_new_scope
1858 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1859 NULL, $3, NULL, $5);
1860 $$->set_location(yylloc);
1862 | DO statement WHILE '(' expression ')' ';'
1865 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1866 NULL, $5, NULL, $2);
1867 $$->set_location(yylloc);
1869 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1872 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1873 $3, $4.cond, $4.rest, $6);
1874 $$->set_location(yylloc);
1879 expression_statement
1880 | declaration_statement
1897 | conditionopt ';' expression
1904 // Grammar Note: No 'goto'. Gotos are not supported.
1909 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1910 $$->set_location(yylloc);
1915 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1916 $$->set_location(yylloc);
1921 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1922 $$->set_location(yylloc);
1924 | RETURN expression ';'
1927 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1928 $$->set_location(yylloc);
1930 | DISCARD ';' // Fragment shader only.
1933 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1934 $$->set_location(yylloc);
1938 external_declaration:
1939 function_definition { $$ = $1; }
1940 | declaration { $$ = $1; }
1941 | pragma_statement { $$ = NULL; }
1942 | layout_defaults { $$ = NULL; }
1945 function_definition:
1946 function_prototype compound_statement_no_new_scope
1949 $$ = new(ctx) ast_function_definition();
1950 $$->set_location(yylloc);
1954 state->symbols->pop_scope();
1958 /* layout_qualifieropt is packed into this rule */
1960 basic_interface_block
1964 | layout_qualifier basic_interface_block
1966 ast_interface_block *block = $2;
1967 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1974 basic_interface_block:
1975 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1977 ast_interface_block *const block = $6;
1979 block->block_name = $2;
1980 block->declarations.push_degenerate_list_at_head(& $4->link);
1982 if ($1.flags.q.uniform) {
1983 if (!state->ARB_uniform_buffer_object_enable) {
1984 _mesa_glsl_error(& @1, state,
1985 "#version 140 / GL_ARB_uniform_buffer_object "
1986 "required for defining uniform blocks\n");
1987 } else if (state->ARB_uniform_buffer_object_warn) {
1988 _mesa_glsl_warning(& @1, state,
1989 "#version 140 / GL_ARB_uniform_buffer_object "
1990 "required for defining uniform blocks\n");
1993 if (state->es_shader || state->language_version < 150) {
1994 _mesa_glsl_error(& @1, state,
1995 "#version 150 required for using "
1996 "interface blocks.\n");
2000 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
2001 * "It is illegal to have an input block in a vertex shader
2002 * or an output block in a fragment shader"
2004 if ((state->target == vertex_shader) && $1.flags.q.in) {
2005 _mesa_glsl_error(& @1, state,
2006 "`in' interface block is not allowed for "
2007 "a vertex shader\n");
2008 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2009 _mesa_glsl_error(& @1, state,
2010 "`out' interface block is not allowed for "
2011 "a fragment shader\n");
2014 /* Since block arrays require names, and both features are added in
2015 * the same language versions, we don't have to explicitly
2016 * version-check both things.
2018 if (block->instance_name != NULL) {
2019 state->check_version(150, 300, & @1, "interface blocks with "
2020 "an instance name are not allowed");
2023 unsigned interface_type_mask;
2024 struct ast_type_qualifier temp_type_qualifier;
2026 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2027 * to ignore other irrelevant flags like interpolation qualifiers.
2029 temp_type_qualifier.flags.i = 0;
2030 temp_type_qualifier.flags.q.uniform = true;
2031 temp_type_qualifier.flags.q.in = true;
2032 temp_type_qualifier.flags.q.out = true;
2033 interface_type_mask = temp_type_qualifier.flags.i;
2035 /* Get the block's interface qualifier. The interface_qualifier
2036 * production rule guarantees that only one bit will be set (and
2037 * it will be in/out/uniform).
2039 unsigned block_interface_qualifier = $1.flags.i;
2041 block->layout.flags.i |= block_interface_qualifier;
2043 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2044 ast_type_qualifier& qualifier = member->type->qualifier;
2045 if ((qualifier.flags.i & interface_type_mask) == 0) {
2046 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2047 * "If no optional qualifier is used in a member declaration, the
2048 * qualifier of the variable is just in, out, or uniform as declared
2049 * by interface-qualifier."
2051 qualifier.flags.i |= block_interface_qualifier;
2052 } else if ((qualifier.flags.i & interface_type_mask) !=
2053 block_interface_qualifier) {
2054 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2055 * "If optional qualifiers are used, they can include interpolation
2056 * and storage qualifiers and they must declare an input, output,
2057 * or uniform variable consistent with the interface qualifier of
2060 _mesa_glsl_error(& @1, state,
2061 "uniform/in/out qualifier on "
2062 "interface block member does not match "
2063 "the interface block\n");
2071 interface_qualifier:
2074 memset(& $$, 0, sizeof($$));
2079 memset(& $$, 0, sizeof($$));
2084 memset(& $$, 0, sizeof($$));
2085 $$.flags.q.uniform = 1;
2092 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2098 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2102 | NEW_IDENTIFIER '[' constant_expression ']'
2104 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2108 | NEW_IDENTIFIER '[' ']'
2110 _mesa_glsl_error(& @1, state,
2111 "instance block arrays must be explicitly sized\n");
2113 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2123 $1->link.self_link();
2125 | member_declaration member_list
2128 $2->link.insert_before(& $$->link);
2133 fully_specified_type struct_declarator_list ';'
2136 ast_fully_specified_type *type = $1;
2137 type->set_location(yylloc);
2139 if (type->qualifier.flags.q.attribute) {
2140 _mesa_glsl_error(& @1, state,
2141 "keyword 'attribute' cannot be used with "
2142 "interface block member\n");
2143 } else if (type->qualifier.flags.q.varying) {
2144 _mesa_glsl_error(& @1, state,
2145 "keyword 'varying' cannot be used with "
2146 "interface block member\n");
2149 $$ = new(ctx) ast_declarator_list(type);
2150 $$->set_location(yylloc);
2151 $$->ubo_qualifiers_valid = true;
2153 $$->declarations.push_degenerate_list_at_head(& $2->link);
2158 layout_qualifier UNIFORM ';'
2160 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,