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
254 version_statement extension_statement_list
256 _mesa_glsl_initialize_types(state);
258 external_declaration_list
260 delete state->symbols;
261 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
262 _mesa_glsl_initialize_types(state);
267 /* blank - no #version specified: defaults are already set */
268 | VERSION_TOK INTCONSTANT EOL
270 state->process_version_directive(&@2, $2, NULL);
275 | VERSION_TOK INTCONSTANT any_identifier EOL
277 state->process_version_directive(&@2, $2, $3);
286 | PRAGMA_DEBUG_OFF EOL
287 | PRAGMA_OPTIMIZE_ON EOL
288 | PRAGMA_OPTIMIZE_OFF EOL
289 | PRAGMA_INVARIANT_ALL EOL
291 if (!state->is_version(120, 100)) {
292 _mesa_glsl_warning(& @1, state,
293 "pragma `invariant(all)' not supported in %s "
294 "(GLSL ES 1.00 or GLSL 1.20 required).",
295 state->get_version_string());
297 state->all_invariant = true;
302 extension_statement_list:
304 | extension_statement_list extension_statement
314 EXTENSION any_identifier COLON any_identifier EOL
316 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
322 external_declaration_list:
325 /* FINISHME: The NULL test is required because pragmas are set to
326 * FINISHME: NULL. (See production rule for external_declaration.)
329 state->translation_unit.push_tail(& $1->link);
331 | external_declaration_list external_declaration
333 /* FINISHME: The NULL test is required because pragmas are set to
334 * FINISHME: NULL. (See production rule for external_declaration.)
337 state->translation_unit.push_tail(& $2->link);
350 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
351 $$->set_location(yylloc);
352 $$->primary_expression.identifier = $1;
357 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
358 $$->set_location(yylloc);
359 $$->primary_expression.int_constant = $1;
364 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
365 $$->set_location(yylloc);
366 $$->primary_expression.uint_constant = $1;
371 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
372 $$->set_location(yylloc);
373 $$->primary_expression.float_constant = $1;
378 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
379 $$->set_location(yylloc);
380 $$->primary_expression.bool_constant = $1;
390 | postfix_expression '[' integer_expression ']'
393 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
394 $$->set_location(yylloc);
400 | postfix_expression '.' any_identifier
403 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
404 $$->set_location(yylloc);
405 $$->primary_expression.identifier = $3;
407 | postfix_expression INC_OP
410 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
411 $$->set_location(yylloc);
413 | postfix_expression DEC_OP
416 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
417 $$->set_location(yylloc);
426 function_call_or_method
429 function_call_or_method:
430 function_call_generic
431 | postfix_expression '.' method_call_generic
434 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
435 $$->set_location(yylloc);
439 function_call_generic:
440 function_call_header_with_parameters ')'
441 | function_call_header_no_parameters ')'
444 function_call_header_no_parameters:
445 function_call_header VOID_TOK
446 | function_call_header
449 function_call_header_with_parameters:
450 function_call_header assignment_expression
453 $$->set_location(yylloc);
454 $$->expressions.push_tail(& $2->link);
456 | function_call_header_with_parameters ',' assignment_expression
459 $$->set_location(yylloc);
460 $$->expressions.push_tail(& $3->link);
464 // Grammar Note: Constructors look like functions, but lexical
465 // analysis recognized most of them as keywords. They are now
466 // recognized through "type_specifier".
467 function_call_header:
468 function_identifier '('
475 $$ = new(ctx) ast_function_expression($1);
476 $$->set_location(yylloc);
478 | variable_identifier
481 ast_expression *callee = new(ctx) ast_expression($1);
482 $$ = new(ctx) ast_function_expression(callee);
483 $$->set_location(yylloc);
488 ast_expression *callee = new(ctx) ast_expression($1);
489 $$ = new(ctx) ast_function_expression(callee);
490 $$->set_location(yylloc);
495 method_call_header_with_parameters ')'
496 | method_call_header_no_parameters ')'
499 method_call_header_no_parameters:
500 method_call_header VOID_TOK
504 method_call_header_with_parameters:
505 method_call_header assignment_expression
508 $$->set_location(yylloc);
509 $$->expressions.push_tail(& $2->link);
511 | method_call_header_with_parameters ',' assignment_expression
514 $$->set_location(yylloc);
515 $$->expressions.push_tail(& $3->link);
519 // Grammar Note: Constructors look like methods, but lexical
520 // analysis recognized most of them as keywords. They are now
521 // recognized through "type_specifier".
523 variable_identifier '('
526 ast_expression *callee = new(ctx) ast_expression($1);
527 $$ = new(ctx) ast_function_expression(callee);
528 $$->set_location(yylloc);
532 // Grammar Note: No traditional style type casts.
535 | INC_OP unary_expression
538 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
539 $$->set_location(yylloc);
541 | DEC_OP unary_expression
544 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
545 $$->set_location(yylloc);
547 | unary_operator unary_expression
550 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
551 $$->set_location(yylloc);
555 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
557 '+' { $$ = ast_plus; }
558 | '-' { $$ = ast_neg; }
559 | '!' { $$ = ast_logic_not; }
560 | '~' { $$ = ast_bit_not; }
563 multiplicative_expression:
565 | multiplicative_expression '*' unary_expression
568 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
569 $$->set_location(yylloc);
571 | multiplicative_expression '/' unary_expression
574 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
575 $$->set_location(yylloc);
577 | multiplicative_expression '%' unary_expression
580 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
581 $$->set_location(yylloc);
586 multiplicative_expression
587 | additive_expression '+' multiplicative_expression
590 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
591 $$->set_location(yylloc);
593 | additive_expression '-' multiplicative_expression
596 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
597 $$->set_location(yylloc);
603 | shift_expression LEFT_OP additive_expression
606 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
607 $$->set_location(yylloc);
609 | shift_expression RIGHT_OP additive_expression
612 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
613 $$->set_location(yylloc);
617 relational_expression:
619 | relational_expression '<' shift_expression
622 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
623 $$->set_location(yylloc);
625 | relational_expression '>' shift_expression
628 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
629 $$->set_location(yylloc);
631 | relational_expression LE_OP shift_expression
634 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
635 $$->set_location(yylloc);
637 | relational_expression GE_OP shift_expression
640 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
641 $$->set_location(yylloc);
646 relational_expression
647 | equality_expression EQ_OP relational_expression
650 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
651 $$->set_location(yylloc);
653 | equality_expression NE_OP relational_expression
656 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
657 $$->set_location(yylloc);
663 | and_expression '&' equality_expression
666 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
667 $$->set_location(yylloc);
671 exclusive_or_expression:
673 | exclusive_or_expression '^' and_expression
676 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
677 $$->set_location(yylloc);
681 inclusive_or_expression:
682 exclusive_or_expression
683 | inclusive_or_expression '|' exclusive_or_expression
686 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
687 $$->set_location(yylloc);
691 logical_and_expression:
692 inclusive_or_expression
693 | logical_and_expression AND_OP inclusive_or_expression
696 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
697 $$->set_location(yylloc);
701 logical_xor_expression:
702 logical_and_expression
703 | logical_xor_expression XOR_OP logical_and_expression
706 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
707 $$->set_location(yylloc);
711 logical_or_expression:
712 logical_xor_expression
713 | logical_or_expression OR_OP logical_xor_expression
716 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
717 $$->set_location(yylloc);
721 conditional_expression:
722 logical_or_expression
723 | logical_or_expression '?' expression ':' assignment_expression
726 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
727 $$->set_location(yylloc);
731 assignment_expression:
732 conditional_expression
733 | unary_expression assignment_operator assignment_expression
736 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
737 $$->set_location(yylloc);
742 '=' { $$ = ast_assign; }
743 | MUL_ASSIGN { $$ = ast_mul_assign; }
744 | DIV_ASSIGN { $$ = ast_div_assign; }
745 | MOD_ASSIGN { $$ = ast_mod_assign; }
746 | ADD_ASSIGN { $$ = ast_add_assign; }
747 | SUB_ASSIGN { $$ = ast_sub_assign; }
748 | LEFT_ASSIGN { $$ = ast_ls_assign; }
749 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
750 | AND_ASSIGN { $$ = ast_and_assign; }
751 | XOR_ASSIGN { $$ = ast_xor_assign; }
752 | OR_ASSIGN { $$ = ast_or_assign; }
756 assignment_expression
760 | expression ',' assignment_expression
763 if ($1->oper != ast_sequence) {
764 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
765 $$->set_location(yylloc);
766 $$->expressions.push_tail(& $1->link);
771 $$->expressions.push_tail(& $3->link);
776 conditional_expression
780 function_prototype ';'
782 state->symbols->pop_scope();
785 | init_declarator_list ';'
789 | PRECISION precision_qualifier type_specifier_no_prec ';'
792 $3->is_precision_statement = true;
802 function_declarator ')'
807 | function_header_with_parameters
810 function_header_with_parameters:
811 function_header parameter_declaration
814 $$->parameters.push_tail(& $2->link);
816 | function_header_with_parameters ',' parameter_declaration
819 $$->parameters.push_tail(& $3->link);
824 fully_specified_type variable_identifier '('
827 $$ = new(ctx) ast_function();
828 $$->set_location(yylloc);
829 $$->return_type = $1;
832 state->symbols->add_function(new(state) ir_function($2));
833 state->symbols->push_scope();
837 parameter_declarator:
838 type_specifier any_identifier
841 $$ = new(ctx) ast_parameter_declarator();
842 $$->set_location(yylloc);
843 $$->type = new(ctx) ast_fully_specified_type();
844 $$->type->set_location(yylloc);
845 $$->type->specifier = $1;
848 | type_specifier any_identifier '[' constant_expression ']'
851 $$ = new(ctx) ast_parameter_declarator();
852 $$->set_location(yylloc);
853 $$->type = new(ctx) ast_fully_specified_type();
854 $$->type->set_location(yylloc);
855 $$->type->specifier = $1;
862 parameter_declaration:
863 parameter_type_qualifier parameter_qualifier parameter_declarator
865 $1.flags.i |= $2.flags.i;
868 $$->type->qualifier = $1;
870 | parameter_qualifier parameter_declarator
873 $$->type->qualifier = $1;
875 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
878 $1.flags.i |= $2.flags.i;
880 $$ = new(ctx) ast_parameter_declarator();
881 $$->set_location(yylloc);
882 $$->type = new(ctx) ast_fully_specified_type();
883 $$->type->qualifier = $1;
884 $$->type->specifier = $3;
886 | parameter_qualifier parameter_type_specifier
889 $$ = new(ctx) ast_parameter_declarator();
890 $$->set_location(yylloc);
891 $$->type = new(ctx) ast_fully_specified_type();
892 $$->type->qualifier = $1;
893 $$->type->specifier = $2;
900 memset(& $$, 0, sizeof($$));
904 memset(& $$, 0, sizeof($$));
909 memset(& $$, 0, sizeof($$));
914 memset(& $$, 0, sizeof($$));
920 parameter_type_specifier:
924 init_declarator_list:
926 | init_declarator_list ',' any_identifier
929 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
930 decl->set_location(yylloc);
933 $$->declarations.push_tail(&decl->link);
934 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
936 | init_declarator_list ',' any_identifier '[' ']'
939 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
940 decl->set_location(yylloc);
943 $$->declarations.push_tail(&decl->link);
944 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
946 | init_declarator_list ',' any_identifier '[' constant_expression ']'
949 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
950 decl->set_location(yylloc);
953 $$->declarations.push_tail(&decl->link);
954 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
956 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
959 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
960 decl->set_location(yylloc);
963 $$->declarations.push_tail(&decl->link);
964 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
965 if ($7->oper == ast_aggregate) {
966 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
967 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
968 _mesa_ast_set_aggregate_type(type, ai, state);
971 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
974 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
975 decl->set_location(yylloc);
978 $$->declarations.push_tail(&decl->link);
979 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
980 if ($8->oper == ast_aggregate) {
981 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
982 ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
983 _mesa_ast_set_aggregate_type(type, ai, state);
986 | init_declarator_list ',' any_identifier '=' initializer
989 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
990 decl->set_location(yylloc);
993 $$->declarations.push_tail(&decl->link);
994 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
995 if ($5->oper == ast_aggregate) {
996 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
997 _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
1002 // Grammar Note: No 'enum', or 'typedef'.
1004 fully_specified_type
1007 /* Empty declaration list is valid. */
1008 $$ = new(ctx) ast_declarator_list($1);
1009 $$->set_location(yylloc);
1011 | fully_specified_type any_identifier
1014 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1016 $$ = new(ctx) ast_declarator_list($1);
1017 $$->set_location(yylloc);
1018 $$->declarations.push_tail(&decl->link);
1020 | fully_specified_type any_identifier '[' ']'
1023 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1025 $$ = new(ctx) ast_declarator_list($1);
1026 $$->set_location(yylloc);
1027 $$->declarations.push_tail(&decl->link);
1029 | fully_specified_type any_identifier '[' constant_expression ']'
1032 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1034 $$ = new(ctx) ast_declarator_list($1);
1035 $$->set_location(yylloc);
1036 $$->declarations.push_tail(&decl->link);
1038 | fully_specified_type any_identifier '[' ']' '=' initializer
1041 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1043 $$ = new(ctx) ast_declarator_list($1);
1044 $$->set_location(yylloc);
1045 $$->declarations.push_tail(&decl->link);
1046 if ($6->oper == ast_aggregate) {
1047 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
1048 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
1049 _mesa_ast_set_aggregate_type(type, ai, state);
1052 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1055 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1057 $$ = new(ctx) ast_declarator_list($1);
1058 $$->set_location(yylloc);
1059 $$->declarations.push_tail(&decl->link);
1060 if ($7->oper == ast_aggregate) {
1061 ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
1062 ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
1063 _mesa_ast_set_aggregate_type(type, ai, state);
1066 | fully_specified_type any_identifier '=' initializer
1069 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1071 $$ = new(ctx) ast_declarator_list($1);
1072 $$->set_location(yylloc);
1073 $$->declarations.push_tail(&decl->link);
1074 if ($4->oper == ast_aggregate) {
1075 _mesa_ast_set_aggregate_type($1->specifier, $4, state);
1078 | INVARIANT variable_identifier // Vertex only.
1081 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1083 $$ = new(ctx) ast_declarator_list(NULL);
1084 $$->set_location(yylloc);
1085 $$->invariant = true;
1087 $$->declarations.push_tail(&decl->link);
1091 fully_specified_type:
1095 $$ = new(ctx) ast_fully_specified_type();
1096 $$->set_location(yylloc);
1099 | type_qualifier type_specifier
1102 $$ = new(ctx) ast_fully_specified_type();
1103 $$->set_location(yylloc);
1110 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1116 layout_qualifier_id_list:
1118 | layout_qualifier_id_list ',' layout_qualifier_id
1121 if (!$$.merge_qualifier(& @3, state, $3)) {
1128 INTCONSTANT { $$ = $1; }
1129 | UINTCONSTANT { $$ = $1; }
1132 layout_qualifier_id:
1135 memset(& $$, 0, sizeof($$));
1137 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1138 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1139 if (strcmp($1, "origin_upper_left") == 0) {
1140 $$.flags.q.origin_upper_left = 1;
1141 } else if (strcmp($1, "pixel_center_integer") == 0) {
1142 $$.flags.q.pixel_center_integer = 1;
1145 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1146 _mesa_glsl_warning(& @1, state,
1147 "GL_ARB_fragment_coord_conventions layout "
1148 "identifier `%s' used\n", $1);
1152 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1154 (state->AMD_conservative_depth_enable ||
1155 state->ARB_conservative_depth_enable)) {
1156 if (strcmp($1, "depth_any") == 0) {
1157 $$.flags.q.depth_any = 1;
1158 } else if (strcmp($1, "depth_greater") == 0) {
1159 $$.flags.q.depth_greater = 1;
1160 } else if (strcmp($1, "depth_less") == 0) {
1161 $$.flags.q.depth_less = 1;
1162 } else if (strcmp($1, "depth_unchanged") == 0) {
1163 $$.flags.q.depth_unchanged = 1;
1166 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1167 _mesa_glsl_warning(& @1, state,
1168 "GL_AMD_conservative_depth "
1169 "layout qualifier `%s' is used\n", $1);
1171 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1172 _mesa_glsl_warning(& @1, state,
1173 "GL_ARB_conservative_depth "
1174 "layout qualifier `%s' is used\n", $1);
1178 /* See also interface_block_layout_qualifier. */
1179 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1180 if (strcmp($1, "std140") == 0) {
1181 $$.flags.q.std140 = 1;
1182 } else if (strcmp($1, "shared") == 0) {
1183 $$.flags.q.shared = 1;
1184 } else if (strcmp($1, "column_major") == 0) {
1185 $$.flags.q.column_major = 1;
1186 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1187 * below in the interface_block_layout_qualifier rule.
1189 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1192 } else if (strcmp($1, "row_major") == 0) {
1193 $$.flags.q.row_major = 1;
1196 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1197 _mesa_glsl_warning(& @1, state,
1198 "#version 140 / GL_ARB_uniform_buffer_object "
1199 "layout qualifier `%s' is used\n", $1);
1204 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1209 | any_identifier '=' integer_constant
1211 memset(& $$, 0, sizeof($$));
1213 if (state->ARB_explicit_attrib_location_enable) {
1214 if (strcmp("location", $1) == 0) {
1215 $$.flags.q.explicit_location = 1;
1220 _mesa_glsl_error(& @3, state,
1221 "invalid location %d specified\n", $3);
1226 if (strcmp("index", $1) == 0) {
1227 $$.flags.q.explicit_index = 1;
1232 _mesa_glsl_error(& @3, state,
1233 "invalid index %d specified\n", $3);
1239 /* If the identifier didn't match any known layout identifiers,
1243 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1246 } else if (state->ARB_explicit_attrib_location_warn) {
1247 _mesa_glsl_warning(& @1, state,
1248 "GL_ARB_explicit_attrib_location layout "
1249 "identifier `%s' used\n", $1);
1252 | interface_block_layout_qualifier
1255 /* Layout qualifiers for ARB_uniform_buffer_object. */
1256 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1257 _mesa_glsl_error(& @1, state,
1258 "#version 140 / GL_ARB_uniform_buffer_object "
1259 "layout qualifier `%s' is used\n", $1);
1260 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1261 _mesa_glsl_warning(& @1, state,
1262 "#version 140 / GL_ARB_uniform_buffer_object "
1263 "layout qualifier `%s' is used\n", $1);
1268 /* This is a separate language rule because we parse these as tokens
1269 * (due to them being reserved keywords) instead of identifiers like
1270 * most qualifiers. See the any_identifier path of
1271 * layout_qualifier_id for the others.
1273 interface_block_layout_qualifier:
1276 memset(& $$, 0, sizeof($$));
1277 $$.flags.q.row_major = 1;
1281 memset(& $$, 0, sizeof($$));
1282 $$.flags.q.packed = 1;
1286 interpolation_qualifier:
1289 memset(& $$, 0, sizeof($$));
1290 $$.flags.q.smooth = 1;
1294 memset(& $$, 0, sizeof($$));
1295 $$.flags.q.flat = 1;
1299 memset(& $$, 0, sizeof($$));
1300 $$.flags.q.noperspective = 1;
1304 parameter_type_qualifier:
1307 memset(& $$, 0, sizeof($$));
1308 $$.flags.q.constant = 1;
1315 | layout_qualifier storage_qualifier
1318 $$.flags.i |= $2.flags.i;
1320 | interpolation_qualifier
1321 | interpolation_qualifier storage_qualifier
1324 $$.flags.i |= $2.flags.i;
1326 | INVARIANT storage_qualifier
1329 $$.flags.q.invariant = 1;
1331 | INVARIANT interpolation_qualifier storage_qualifier
1334 $$.flags.i |= $3.flags.i;
1335 $$.flags.q.invariant = 1;
1339 memset(& $$, 0, sizeof($$));
1340 $$.flags.q.invariant = 1;
1347 memset(& $$, 0, sizeof($$));
1348 $$.flags.q.constant = 1;
1352 memset(& $$, 0, sizeof($$));
1353 $$.flags.q.attribute = 1;
1357 memset(& $$, 0, sizeof($$));
1358 $$.flags.q.varying = 1;
1362 memset(& $$, 0, sizeof($$));
1363 $$.flags.q.centroid = 1;
1364 $$.flags.q.varying = 1;
1368 memset(& $$, 0, sizeof($$));
1373 memset(& $$, 0, sizeof($$));
1378 memset(& $$, 0, sizeof($$));
1379 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1383 memset(& $$, 0, sizeof($$));
1384 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1388 memset(& $$, 0, sizeof($$));
1389 $$.flags.q.uniform = 1;
1394 type_specifier_no_prec
1398 | precision_qualifier type_specifier_no_prec
1405 type_specifier_no_prec:
1406 type_specifier_nonarray
1407 | type_specifier_nonarray '[' ']'
1410 $$->is_array = true;
1411 $$->array_size = NULL;
1413 | type_specifier_nonarray '[' constant_expression ']'
1416 $$->is_array = true;
1417 $$->array_size = $3;
1421 type_specifier_nonarray:
1422 basic_type_specifier_nonarray
1425 $$ = new(ctx) ast_type_specifier($1);
1426 $$->set_location(yylloc);
1431 $$ = new(ctx) ast_type_specifier($1);
1432 $$->set_location(yylloc);
1437 $$ = new(ctx) ast_type_specifier($1);
1438 $$->set_location(yylloc);
1442 basic_type_specifier_nonarray:
1443 VOID_TOK { $$ = "void"; }
1444 | FLOAT_TOK { $$ = "float"; }
1445 | INT_TOK { $$ = "int"; }
1446 | UINT_TOK { $$ = "uint"; }
1447 | BOOL_TOK { $$ = "bool"; }
1448 | VEC2 { $$ = "vec2"; }
1449 | VEC3 { $$ = "vec3"; }
1450 | VEC4 { $$ = "vec4"; }
1451 | BVEC2 { $$ = "bvec2"; }
1452 | BVEC3 { $$ = "bvec3"; }
1453 | BVEC4 { $$ = "bvec4"; }
1454 | IVEC2 { $$ = "ivec2"; }
1455 | IVEC3 { $$ = "ivec3"; }
1456 | IVEC4 { $$ = "ivec4"; }
1457 | UVEC2 { $$ = "uvec2"; }
1458 | UVEC3 { $$ = "uvec3"; }
1459 | UVEC4 { $$ = "uvec4"; }
1460 | MAT2X2 { $$ = "mat2"; }
1461 | MAT2X3 { $$ = "mat2x3"; }
1462 | MAT2X4 { $$ = "mat2x4"; }
1463 | MAT3X2 { $$ = "mat3x2"; }
1464 | MAT3X3 { $$ = "mat3"; }
1465 | MAT3X4 { $$ = "mat3x4"; }
1466 | MAT4X2 { $$ = "mat4x2"; }
1467 | MAT4X3 { $$ = "mat4x3"; }
1468 | MAT4X4 { $$ = "mat4"; }
1469 | SAMPLER1D { $$ = "sampler1D"; }
1470 | SAMPLER2D { $$ = "sampler2D"; }
1471 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1472 | SAMPLER3D { $$ = "sampler3D"; }
1473 | SAMPLERCUBE { $$ = "samplerCube"; }
1474 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1475 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1476 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1477 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1478 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1479 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1480 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1481 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1482 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1483 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1484 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1485 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1486 | ISAMPLER1D { $$ = "isampler1D"; }
1487 | ISAMPLER2D { $$ = "isampler2D"; }
1488 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1489 | ISAMPLER3D { $$ = "isampler3D"; }
1490 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1491 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1492 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1493 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1494 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1495 | USAMPLER1D { $$ = "usampler1D"; }
1496 | USAMPLER2D { $$ = "usampler2D"; }
1497 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1498 | USAMPLER3D { $$ = "usampler3D"; }
1499 | USAMPLERCUBE { $$ = "usamplerCube"; }
1500 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1501 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1502 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1503 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1504 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1505 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1506 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1507 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1508 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1509 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1512 precision_qualifier:
1514 state->check_precision_qualifiers_allowed(&@1);
1516 $$ = ast_precision_high;
1519 state->check_precision_qualifiers_allowed(&@1);
1521 $$ = ast_precision_medium;
1524 state->check_precision_qualifiers_allowed(&@1);
1526 $$ = ast_precision_low;
1531 STRUCT any_identifier '{' struct_declaration_list '}'
1534 $$ = new(ctx) ast_struct_specifier($2, $4);
1535 $$->set_location(yylloc);
1536 state->symbols->add_type($2, glsl_type::void_type);
1537 state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
1539 | STRUCT '{' struct_declaration_list '}'
1542 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1543 $$->set_location(yylloc);
1547 struct_declaration_list:
1551 $1->link.self_link();
1553 | struct_declaration_list struct_declaration
1556 $$->link.insert_before(& $2->link);
1561 type_specifier struct_declarator_list ';'
1564 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1565 type->set_location(yylloc);
1567 type->specifier = $1;
1568 $$ = new(ctx) ast_declarator_list(type);
1569 $$->set_location(yylloc);
1571 $$->declarations.push_degenerate_list_at_head(& $2->link);
1575 struct_declarator_list:
1579 $1->link.self_link();
1581 | struct_declarator_list ',' struct_declarator
1584 $$->link.insert_before(& $3->link);
1592 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1593 $$->set_location(yylloc);
1595 | any_identifier '[' constant_expression ']'
1598 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1599 $$->set_location(yylloc);
1604 assignment_expression
1605 | '{' initializer_list '}'
1609 | '{' initializer_list ',' '}'
1619 $$ = new(ctx) ast_aggregate_initializer();
1620 $$->set_location(yylloc);
1621 $$->expressions.push_tail(& $1->link);
1623 | initializer_list ',' initializer
1625 $1->expressions.push_tail(& $3->link);
1629 declaration_statement:
1633 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1636 compound_statement { $$ = (ast_node *) $1; }
1641 declaration_statement
1642 | expression_statement
1643 | selection_statement
1645 | iteration_statement
1653 $$ = new(ctx) ast_compound_statement(true, NULL);
1654 $$->set_location(yylloc);
1658 state->symbols->push_scope();
1663 $$ = new(ctx) ast_compound_statement(true, $3);
1664 $$->set_location(yylloc);
1665 state->symbols->pop_scope();
1669 statement_no_new_scope:
1670 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1674 compound_statement_no_new_scope:
1678 $$ = new(ctx) ast_compound_statement(false, NULL);
1679 $$->set_location(yylloc);
1681 | '{' statement_list '}'
1684 $$ = new(ctx) ast_compound_statement(false, $2);
1685 $$->set_location(yylloc);
1693 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1698 $$->link.self_link();
1700 | statement_list statement
1703 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1707 $$->link.insert_before(& $2->link);
1711 expression_statement:
1715 $$ = new(ctx) ast_expression_statement(NULL);
1716 $$->set_location(yylloc);
1721 $$ = new(ctx) ast_expression_statement($1);
1722 $$->set_location(yylloc);
1726 selection_statement:
1727 IF '(' expression ')' selection_rest_statement
1729 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1731 $$->set_location(yylloc);
1735 selection_rest_statement:
1736 statement ELSE statement
1738 $$.then_statement = $1;
1739 $$.else_statement = $3;
1743 $$.then_statement = $1;
1744 $$.else_statement = NULL;
1751 $$ = (ast_node *) $1;
1753 | fully_specified_type any_identifier '=' initializer
1756 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1757 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1758 decl->set_location(yylloc);
1759 declarator->set_location(yylloc);
1761 declarator->declarations.push_tail(&decl->link);
1767 * siwtch_statement grammar is based on the syntax described in the body
1768 * of the GLSL spec, not in it's appendix!!!
1771 SWITCH '(' expression ')' switch_body
1773 $$ = new(state) ast_switch_statement($3, $5);
1774 $$->set_location(yylloc);
1781 $$ = new(state) ast_switch_body(NULL);
1782 $$->set_location(yylloc);
1784 | '{' case_statement_list '}'
1786 $$ = new(state) ast_switch_body($2);
1787 $$->set_location(yylloc);
1794 $$ = new(state) ast_case_label($2);
1795 $$->set_location(yylloc);
1799 $$ = new(state) ast_case_label(NULL);
1800 $$->set_location(yylloc);
1807 ast_case_label_list *labels = new(state) ast_case_label_list();
1809 labels->labels.push_tail(& $1->link);
1811 $$->set_location(yylloc);
1813 | case_label_list case_label
1816 $$->labels.push_tail(& $2->link);
1821 case_label_list statement
1823 ast_case_statement *stmts = new(state) ast_case_statement($1);
1824 stmts->set_location(yylloc);
1826 stmts->stmts.push_tail(& $2->link);
1829 | case_statement statement
1832 $$->stmts.push_tail(& $2->link);
1836 case_statement_list:
1839 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1840 cases->set_location(yylloc);
1842 cases->cases.push_tail(& $1->link);
1845 | case_statement_list case_statement
1848 $$->cases.push_tail(& $2->link);
1852 iteration_statement:
1853 WHILE '(' condition ')' statement_no_new_scope
1856 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1857 NULL, $3, NULL, $5);
1858 $$->set_location(yylloc);
1860 | DO statement WHILE '(' expression ')' ';'
1863 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1864 NULL, $5, NULL, $2);
1865 $$->set_location(yylloc);
1867 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1870 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1871 $3, $4.cond, $4.rest, $6);
1872 $$->set_location(yylloc);
1877 expression_statement
1878 | declaration_statement
1895 | conditionopt ';' expression
1902 // Grammar Note: No 'goto'. Gotos are not supported.
1907 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1908 $$->set_location(yylloc);
1913 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1914 $$->set_location(yylloc);
1919 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1920 $$->set_location(yylloc);
1922 | RETURN expression ';'
1925 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1926 $$->set_location(yylloc);
1928 | DISCARD ';' // Fragment shader only.
1931 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1932 $$->set_location(yylloc);
1936 external_declaration:
1937 function_definition { $$ = $1; }
1938 | declaration { $$ = $1; }
1939 | pragma_statement { $$ = NULL; }
1940 | layout_defaults { $$ = NULL; }
1943 function_definition:
1944 function_prototype compound_statement_no_new_scope
1947 $$ = new(ctx) ast_function_definition();
1948 $$->set_location(yylloc);
1952 state->symbols->pop_scope();
1956 /* layout_qualifieropt is packed into this rule */
1958 basic_interface_block
1962 | layout_qualifier basic_interface_block
1964 ast_interface_block *block = $2;
1965 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1972 basic_interface_block:
1973 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1975 ast_interface_block *const block = $6;
1977 block->block_name = $2;
1978 block->declarations.push_degenerate_list_at_head(& $4->link);
1980 if ($1.flags.q.uniform) {
1981 if (!state->ARB_uniform_buffer_object_enable) {
1982 _mesa_glsl_error(& @1, state,
1983 "#version 140 / GL_ARB_uniform_buffer_object "
1984 "required for defining uniform blocks\n");
1985 } else if (state->ARB_uniform_buffer_object_warn) {
1986 _mesa_glsl_warning(& @1, state,
1987 "#version 140 / GL_ARB_uniform_buffer_object "
1988 "required for defining uniform blocks\n");
1991 if (state->es_shader || state->language_version < 150) {
1992 _mesa_glsl_error(& @1, state,
1993 "#version 150 required for using "
1994 "interface blocks.\n");
1998 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
1999 * "It is illegal to have an input block in a vertex shader
2000 * or an output block in a fragment shader"
2002 if ((state->target == vertex_shader) && $1.flags.q.in) {
2003 _mesa_glsl_error(& @1, state,
2004 "`in' interface block is not allowed for "
2005 "a vertex shader\n");
2006 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
2007 _mesa_glsl_error(& @1, state,
2008 "`out' interface block is not allowed for "
2009 "a fragment shader\n");
2012 /* Since block arrays require names, and both features are added in
2013 * the same language versions, we don't have to explicitly
2014 * version-check both things.
2016 if (block->instance_name != NULL) {
2017 state->check_version(150, 300, & @1, "interface blocks with "
2018 "an instance name are not allowed");
2021 unsigned interface_type_mask;
2022 struct ast_type_qualifier temp_type_qualifier;
2024 /* Get a bitmask containing only the in/out/uniform flags, allowing us
2025 * to ignore other irrelevant flags like interpolation qualifiers.
2027 temp_type_qualifier.flags.i = 0;
2028 temp_type_qualifier.flags.q.uniform = true;
2029 temp_type_qualifier.flags.q.in = true;
2030 temp_type_qualifier.flags.q.out = true;
2031 interface_type_mask = temp_type_qualifier.flags.i;
2033 /* Get the block's interface qualifier. The interface_qualifier
2034 * production rule guarantees that only one bit will be set (and
2035 * it will be in/out/uniform).
2037 unsigned block_interface_qualifier = $1.flags.i;
2039 block->layout.flags.i |= block_interface_qualifier;
2041 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
2042 ast_type_qualifier& qualifier = member->type->qualifier;
2043 if ((qualifier.flags.i & interface_type_mask) == 0) {
2044 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2045 * "If no optional qualifier is used in a member declaration, the
2046 * qualifier of the variable is just in, out, or uniform as declared
2047 * by interface-qualifier."
2049 qualifier.flags.i |= block_interface_qualifier;
2050 } else if ((qualifier.flags.i & interface_type_mask) !=
2051 block_interface_qualifier) {
2052 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
2053 * "If optional qualifiers are used, they can include interpolation
2054 * and storage qualifiers and they must declare an input, output,
2055 * or uniform variable consistent with the interface qualifier of
2058 _mesa_glsl_error(& @1, state,
2059 "uniform/in/out qualifier on "
2060 "interface block member does not match "
2061 "the interface block\n");
2069 interface_qualifier:
2072 memset(& $$, 0, sizeof($$));
2077 memset(& $$, 0, sizeof($$));
2082 memset(& $$, 0, sizeof($$));
2083 $$.flags.q.uniform = 1;
2090 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2096 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2100 | NEW_IDENTIFIER '[' constant_expression ']'
2102 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2106 | NEW_IDENTIFIER '[' ']'
2108 _mesa_glsl_error(& @1, state,
2109 "instance block arrays must be explicitly sized\n");
2111 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2121 $1->link.self_link();
2123 | member_declaration member_list
2126 $2->link.insert_before(& $$->link);
2131 fully_specified_type struct_declarator_list ';'
2134 ast_fully_specified_type *type = $1;
2135 type->set_location(yylloc);
2137 if (type->qualifier.flags.q.attribute) {
2138 _mesa_glsl_error(& @1, state,
2139 "keyword 'attribute' cannot be used with "
2140 "interface block member\n");
2141 } else if (type->qualifier.flags.q.varying) {
2142 _mesa_glsl_error(& @1, state,
2143 "keyword 'varying' cannot be used with "
2144 "interface block member\n");
2147 $$ = new(ctx) ast_declarator_list(type);
2148 $$->set_location(yylloc);
2149 $$->ubo_qualifiers_valid = true;
2151 $$->declarations.push_degenerate_list_at_head(& $2->link);
2156 layout_qualifier UNIFORM ';'
2158 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,