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 <node> declaration
225 %type <node> declaration_statement
226 %type <node> jump_statement
227 %type <node> interface_block
228 %type <interface_block> basic_interface_block
229 %type <struct_specifier> struct_specifier
230 %type <declarator_list> struct_declaration_list
231 %type <declarator_list> struct_declaration
232 %type <declaration> struct_declarator
233 %type <declaration> struct_declarator_list
234 %type <declarator_list> member_list
235 %type <declarator_list> member_declaration
236 %type <node> selection_statement
237 %type <selection_rest_statement> selection_rest_statement
238 %type <node> switch_statement
239 %type <switch_body> switch_body
240 %type <case_label_list> case_label_list
241 %type <case_label> case_label
242 %type <case_statement> case_statement
243 %type <case_statement_list> case_statement_list
244 %type <node> iteration_statement
245 %type <node> condition
246 %type <node> conditionopt
247 %type <node> for_init_statement
248 %type <for_rest_statement> for_rest_statement
249 %type <n> integer_constant
253 version_statement extension_statement_list
255 _mesa_glsl_initialize_types(state);
257 external_declaration_list
259 delete state->symbols;
260 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
261 _mesa_glsl_initialize_types(state);
266 /* blank - no #version specified: defaults are already set */
267 | VERSION_TOK INTCONSTANT EOL
269 state->process_version_directive(&@2, $2, NULL);
271 | VERSION_TOK INTCONSTANT any_identifier EOL
273 state->process_version_directive(&@2, $2, $3);
279 | PRAGMA_DEBUG_OFF EOL
280 | PRAGMA_OPTIMIZE_ON EOL
281 | PRAGMA_OPTIMIZE_OFF EOL
282 | PRAGMA_INVARIANT_ALL EOL
284 if (!state->is_version(120, 100)) {
285 _mesa_glsl_warning(& @1, state,
286 "pragma `invariant(all)' not supported in %s "
287 "(GLSL ES 1.00 or GLSL 1.20 required).",
288 state->get_version_string());
290 state->all_invariant = true;
295 extension_statement_list:
297 | extension_statement_list extension_statement
307 EXTENSION any_identifier COLON any_identifier EOL
309 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
315 external_declaration_list:
318 /* FINISHME: The NULL test is required because pragmas are set to
319 * FINISHME: NULL. (See production rule for external_declaration.)
322 state->translation_unit.push_tail(& $1->link);
324 | external_declaration_list external_declaration
326 /* FINISHME: The NULL test is required because pragmas are set to
327 * FINISHME: NULL. (See production rule for external_declaration.)
330 state->translation_unit.push_tail(& $2->link);
343 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
344 $$->set_location(yylloc);
345 $$->primary_expression.identifier = $1;
350 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
351 $$->set_location(yylloc);
352 $$->primary_expression.int_constant = $1;
357 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
358 $$->set_location(yylloc);
359 $$->primary_expression.uint_constant = $1;
364 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
365 $$->set_location(yylloc);
366 $$->primary_expression.float_constant = $1;
371 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
372 $$->set_location(yylloc);
373 $$->primary_expression.bool_constant = $1;
383 | postfix_expression '[' integer_expression ']'
386 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
387 $$->set_location(yylloc);
393 | postfix_expression '.' any_identifier
396 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
397 $$->set_location(yylloc);
398 $$->primary_expression.identifier = $3;
400 | postfix_expression INC_OP
403 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
404 $$->set_location(yylloc);
406 | postfix_expression DEC_OP
409 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
410 $$->set_location(yylloc);
419 function_call_or_method
422 function_call_or_method:
423 function_call_generic
424 | postfix_expression '.' method_call_generic
427 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
428 $$->set_location(yylloc);
432 function_call_generic:
433 function_call_header_with_parameters ')'
434 | function_call_header_no_parameters ')'
437 function_call_header_no_parameters:
438 function_call_header VOID_TOK
439 | function_call_header
442 function_call_header_with_parameters:
443 function_call_header assignment_expression
446 $$->set_location(yylloc);
447 $$->expressions.push_tail(& $2->link);
449 | function_call_header_with_parameters ',' assignment_expression
452 $$->set_location(yylloc);
453 $$->expressions.push_tail(& $3->link);
457 // Grammar Note: Constructors look like functions, but lexical
458 // analysis recognized most of them as keywords. They are now
459 // recognized through "type_specifier".
460 function_call_header:
461 function_identifier '('
468 $$ = new(ctx) ast_function_expression($1);
469 $$->set_location(yylloc);
471 | variable_identifier
474 ast_expression *callee = new(ctx) ast_expression($1);
475 $$ = new(ctx) ast_function_expression(callee);
476 $$->set_location(yylloc);
481 ast_expression *callee = new(ctx) ast_expression($1);
482 $$ = new(ctx) ast_function_expression(callee);
483 $$->set_location(yylloc);
488 method_call_header_with_parameters ')'
489 | method_call_header_no_parameters ')'
492 method_call_header_no_parameters:
493 method_call_header VOID_TOK
497 method_call_header_with_parameters:
498 method_call_header assignment_expression
501 $$->set_location(yylloc);
502 $$->expressions.push_tail(& $2->link);
504 | method_call_header_with_parameters ',' assignment_expression
507 $$->set_location(yylloc);
508 $$->expressions.push_tail(& $3->link);
512 // Grammar Note: Constructors look like methods, but lexical
513 // analysis recognized most of them as keywords. They are now
514 // recognized through "type_specifier".
516 variable_identifier '('
519 ast_expression *callee = new(ctx) ast_expression($1);
520 $$ = new(ctx) ast_function_expression(callee);
521 $$->set_location(yylloc);
525 // Grammar Note: No traditional style type casts.
528 | INC_OP unary_expression
531 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
532 $$->set_location(yylloc);
534 | DEC_OP unary_expression
537 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
538 $$->set_location(yylloc);
540 | unary_operator unary_expression
543 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
544 $$->set_location(yylloc);
548 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
550 '+' { $$ = ast_plus; }
551 | '-' { $$ = ast_neg; }
552 | '!' { $$ = ast_logic_not; }
553 | '~' { $$ = ast_bit_not; }
556 multiplicative_expression:
558 | multiplicative_expression '*' unary_expression
561 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
562 $$->set_location(yylloc);
564 | multiplicative_expression '/' unary_expression
567 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
568 $$->set_location(yylloc);
570 | multiplicative_expression '%' unary_expression
573 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
574 $$->set_location(yylloc);
579 multiplicative_expression
580 | additive_expression '+' multiplicative_expression
583 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
584 $$->set_location(yylloc);
586 | additive_expression '-' multiplicative_expression
589 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
590 $$->set_location(yylloc);
596 | shift_expression LEFT_OP additive_expression
599 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
600 $$->set_location(yylloc);
602 | shift_expression RIGHT_OP additive_expression
605 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
606 $$->set_location(yylloc);
610 relational_expression:
612 | relational_expression '<' shift_expression
615 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
616 $$->set_location(yylloc);
618 | relational_expression '>' shift_expression
621 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
622 $$->set_location(yylloc);
624 | relational_expression LE_OP shift_expression
627 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
628 $$->set_location(yylloc);
630 | relational_expression GE_OP shift_expression
633 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
634 $$->set_location(yylloc);
639 relational_expression
640 | equality_expression EQ_OP relational_expression
643 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
644 $$->set_location(yylloc);
646 | equality_expression NE_OP relational_expression
649 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
650 $$->set_location(yylloc);
656 | and_expression '&' equality_expression
659 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
660 $$->set_location(yylloc);
664 exclusive_or_expression:
666 | exclusive_or_expression '^' and_expression
669 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
670 $$->set_location(yylloc);
674 inclusive_or_expression:
675 exclusive_or_expression
676 | inclusive_or_expression '|' exclusive_or_expression
679 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
680 $$->set_location(yylloc);
684 logical_and_expression:
685 inclusive_or_expression
686 | logical_and_expression AND_OP inclusive_or_expression
689 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
690 $$->set_location(yylloc);
694 logical_xor_expression:
695 logical_and_expression
696 | logical_xor_expression XOR_OP logical_and_expression
699 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
700 $$->set_location(yylloc);
704 logical_or_expression:
705 logical_xor_expression
706 | logical_or_expression OR_OP logical_xor_expression
709 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
710 $$->set_location(yylloc);
714 conditional_expression:
715 logical_or_expression
716 | logical_or_expression '?' expression ':' assignment_expression
719 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
720 $$->set_location(yylloc);
724 assignment_expression:
725 conditional_expression
726 | unary_expression assignment_operator assignment_expression
729 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
730 $$->set_location(yylloc);
735 '=' { $$ = ast_assign; }
736 | MUL_ASSIGN { $$ = ast_mul_assign; }
737 | DIV_ASSIGN { $$ = ast_div_assign; }
738 | MOD_ASSIGN { $$ = ast_mod_assign; }
739 | ADD_ASSIGN { $$ = ast_add_assign; }
740 | SUB_ASSIGN { $$ = ast_sub_assign; }
741 | LEFT_ASSIGN { $$ = ast_ls_assign; }
742 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
743 | AND_ASSIGN { $$ = ast_and_assign; }
744 | XOR_ASSIGN { $$ = ast_xor_assign; }
745 | OR_ASSIGN { $$ = ast_or_assign; }
749 assignment_expression
753 | expression ',' assignment_expression
756 if ($1->oper != ast_sequence) {
757 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
758 $$->set_location(yylloc);
759 $$->expressions.push_tail(& $1->link);
764 $$->expressions.push_tail(& $3->link);
769 conditional_expression
773 function_prototype ';'
775 state->symbols->pop_scope();
778 | init_declarator_list ';'
782 | PRECISION precision_qualifier type_specifier_no_prec ';'
785 $3->is_precision_statement = true;
795 function_declarator ')'
800 | function_header_with_parameters
803 function_header_with_parameters:
804 function_header parameter_declaration
807 $$->parameters.push_tail(& $2->link);
809 | function_header_with_parameters ',' parameter_declaration
812 $$->parameters.push_tail(& $3->link);
817 fully_specified_type variable_identifier '('
820 $$ = new(ctx) ast_function();
821 $$->set_location(yylloc);
822 $$->return_type = $1;
825 state->symbols->add_function(new(state) ir_function($2));
826 state->symbols->push_scope();
830 parameter_declarator:
831 type_specifier any_identifier
834 $$ = new(ctx) ast_parameter_declarator();
835 $$->set_location(yylloc);
836 $$->type = new(ctx) ast_fully_specified_type();
837 $$->type->set_location(yylloc);
838 $$->type->specifier = $1;
841 | type_specifier any_identifier '[' constant_expression ']'
844 $$ = new(ctx) ast_parameter_declarator();
845 $$->set_location(yylloc);
846 $$->type = new(ctx) ast_fully_specified_type();
847 $$->type->set_location(yylloc);
848 $$->type->specifier = $1;
855 parameter_declaration:
856 parameter_type_qualifier parameter_qualifier parameter_declarator
858 $1.flags.i |= $2.flags.i;
861 $$->type->qualifier = $1;
863 | parameter_qualifier parameter_declarator
866 $$->type->qualifier = $1;
868 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
871 $1.flags.i |= $2.flags.i;
873 $$ = new(ctx) ast_parameter_declarator();
874 $$->set_location(yylloc);
875 $$->type = new(ctx) ast_fully_specified_type();
876 $$->type->qualifier = $1;
877 $$->type->specifier = $3;
879 | parameter_qualifier parameter_type_specifier
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 = $2;
893 memset(& $$, 0, sizeof($$));
897 memset(& $$, 0, sizeof($$));
902 memset(& $$, 0, sizeof($$));
907 memset(& $$, 0, sizeof($$));
913 parameter_type_specifier:
917 init_declarator_list:
919 | init_declarator_list ',' any_identifier
922 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
923 decl->set_location(yylloc);
926 $$->declarations.push_tail(&decl->link);
927 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
929 | init_declarator_list ',' any_identifier '[' ']'
932 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
933 decl->set_location(yylloc);
936 $$->declarations.push_tail(&decl->link);
937 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
939 | init_declarator_list ',' any_identifier '[' constant_expression ']'
942 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
943 decl->set_location(yylloc);
946 $$->declarations.push_tail(&decl->link);
947 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
949 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
952 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
953 decl->set_location(yylloc);
956 $$->declarations.push_tail(&decl->link);
957 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
959 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
962 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
963 decl->set_location(yylloc);
966 $$->declarations.push_tail(&decl->link);
967 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
969 | init_declarator_list ',' any_identifier '=' initializer
972 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
973 decl->set_location(yylloc);
976 $$->declarations.push_tail(&decl->link);
977 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
981 // Grammar Note: No 'enum', or 'typedef'.
986 /* Empty declaration list is valid. */
987 $$ = new(ctx) ast_declarator_list($1);
988 $$->set_location(yylloc);
990 | fully_specified_type any_identifier
993 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
995 $$ = new(ctx) ast_declarator_list($1);
996 $$->set_location(yylloc);
997 $$->declarations.push_tail(&decl->link);
999 | fully_specified_type any_identifier '[' ']'
1002 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1004 $$ = new(ctx) ast_declarator_list($1);
1005 $$->set_location(yylloc);
1006 $$->declarations.push_tail(&decl->link);
1008 | fully_specified_type any_identifier '[' constant_expression ']'
1011 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1013 $$ = new(ctx) ast_declarator_list($1);
1014 $$->set_location(yylloc);
1015 $$->declarations.push_tail(&decl->link);
1017 | fully_specified_type any_identifier '[' ']' '=' initializer
1020 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1022 $$ = new(ctx) ast_declarator_list($1);
1023 $$->set_location(yylloc);
1024 $$->declarations.push_tail(&decl->link);
1026 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1029 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1031 $$ = new(ctx) ast_declarator_list($1);
1032 $$->set_location(yylloc);
1033 $$->declarations.push_tail(&decl->link);
1035 | fully_specified_type any_identifier '=' initializer
1038 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1040 $$ = new(ctx) ast_declarator_list($1);
1041 $$->set_location(yylloc);
1042 $$->declarations.push_tail(&decl->link);
1044 | INVARIANT variable_identifier // Vertex only.
1047 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1049 $$ = new(ctx) ast_declarator_list(NULL);
1050 $$->set_location(yylloc);
1051 $$->invariant = true;
1053 $$->declarations.push_tail(&decl->link);
1057 fully_specified_type:
1061 $$ = new(ctx) ast_fully_specified_type();
1062 $$->set_location(yylloc);
1065 | type_qualifier type_specifier
1068 $$ = new(ctx) ast_fully_specified_type();
1069 $$->set_location(yylloc);
1076 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1082 layout_qualifier_id_list:
1084 | layout_qualifier_id_list ',' layout_qualifier_id
1087 if (!$$.merge_qualifier(& @3, state, $3)) {
1094 INTCONSTANT { $$ = $1; }
1095 | UINTCONSTANT { $$ = $1; }
1098 layout_qualifier_id:
1101 memset(& $$, 0, sizeof($$));
1103 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1104 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1105 if (strcmp($1, "origin_upper_left") == 0) {
1106 $$.flags.q.origin_upper_left = 1;
1107 } else if (strcmp($1, "pixel_center_integer") == 0) {
1108 $$.flags.q.pixel_center_integer = 1;
1111 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1112 _mesa_glsl_warning(& @1, state,
1113 "GL_ARB_fragment_coord_conventions layout "
1114 "identifier `%s' used\n", $1);
1118 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1120 (state->AMD_conservative_depth_enable ||
1121 state->ARB_conservative_depth_enable)) {
1122 if (strcmp($1, "depth_any") == 0) {
1123 $$.flags.q.depth_any = 1;
1124 } else if (strcmp($1, "depth_greater") == 0) {
1125 $$.flags.q.depth_greater = 1;
1126 } else if (strcmp($1, "depth_less") == 0) {
1127 $$.flags.q.depth_less = 1;
1128 } else if (strcmp($1, "depth_unchanged") == 0) {
1129 $$.flags.q.depth_unchanged = 1;
1132 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1133 _mesa_glsl_warning(& @1, state,
1134 "GL_AMD_conservative_depth "
1135 "layout qualifier `%s' is used\n", $1);
1137 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1138 _mesa_glsl_warning(& @1, state,
1139 "GL_ARB_conservative_depth "
1140 "layout qualifier `%s' is used\n", $1);
1144 /* See also interface_block_layout_qualifier. */
1145 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1146 if (strcmp($1, "std140") == 0) {
1147 $$.flags.q.std140 = 1;
1148 } else if (strcmp($1, "shared") == 0) {
1149 $$.flags.q.shared = 1;
1150 } else if (strcmp($1, "column_major") == 0) {
1151 $$.flags.q.column_major = 1;
1152 } else if (strcmp($1, "row_major") == 0) {
1153 $$.flags.q.row_major = 1;
1156 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1157 _mesa_glsl_warning(& @1, state,
1158 "#version 140 / GL_ARB_uniform_buffer_object "
1159 "layout qualifier `%s' is used\n", $1);
1164 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1169 | any_identifier '=' integer_constant
1171 memset(& $$, 0, sizeof($$));
1173 if (state->ARB_explicit_attrib_location_enable) {
1174 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1175 * FINISHME: GLSL 1.30 (or later) are supported.
1177 if (strcmp("location", $1) == 0) {
1178 $$.flags.q.explicit_location = 1;
1183 _mesa_glsl_error(& @3, state,
1184 "invalid location %d specified\n", $3);
1189 if (strcmp("index", $1) == 0) {
1190 $$.flags.q.explicit_index = 1;
1195 _mesa_glsl_error(& @3, state,
1196 "invalid index %d specified\n", $3);
1202 /* If the identifier didn't match any known layout identifiers,
1206 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1209 } else if (state->ARB_explicit_attrib_location_warn) {
1210 _mesa_glsl_warning(& @1, state,
1211 "GL_ARB_explicit_attrib_location layout "
1212 "identifier `%s' used\n", $1);
1215 | interface_block_layout_qualifier
1218 /* Layout qualifiers for ARB_uniform_buffer_object. */
1219 if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
1220 _mesa_glsl_error(& @1, state,
1221 "#version 140 / GL_ARB_uniform_buffer_object "
1222 "layout qualifier `%s' is used\n", $1);
1223 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1224 _mesa_glsl_warning(& @1, state,
1225 "#version 140 / GL_ARB_uniform_buffer_object "
1226 "layout qualifier `%s' is used\n", $1);
1231 /* This is a separate language rule because we parse these as tokens
1232 * (due to them being reserved keywords) instead of identifiers like
1233 * most qualifiers. See the any_identifier path of
1234 * layout_qualifier_id for the others.
1236 interface_block_layout_qualifier:
1239 memset(& $$, 0, sizeof($$));
1240 $$.flags.q.row_major = 1;
1244 memset(& $$, 0, sizeof($$));
1245 $$.flags.q.packed = 1;
1249 interpolation_qualifier:
1252 memset(& $$, 0, sizeof($$));
1253 $$.flags.q.smooth = 1;
1257 memset(& $$, 0, sizeof($$));
1258 $$.flags.q.flat = 1;
1262 memset(& $$, 0, sizeof($$));
1263 $$.flags.q.noperspective = 1;
1267 parameter_type_qualifier:
1270 memset(& $$, 0, sizeof($$));
1271 $$.flags.q.constant = 1;
1278 | layout_qualifier storage_qualifier
1281 $$.flags.i |= $2.flags.i;
1283 | interpolation_qualifier
1284 | interpolation_qualifier storage_qualifier
1287 $$.flags.i |= $2.flags.i;
1289 | INVARIANT storage_qualifier
1292 $$.flags.q.invariant = 1;
1294 | INVARIANT interpolation_qualifier storage_qualifier
1297 $$.flags.i |= $3.flags.i;
1298 $$.flags.q.invariant = 1;
1302 memset(& $$, 0, sizeof($$));
1303 $$.flags.q.invariant = 1;
1310 memset(& $$, 0, sizeof($$));
1311 $$.flags.q.constant = 1;
1315 memset(& $$, 0, sizeof($$));
1316 $$.flags.q.attribute = 1;
1320 memset(& $$, 0, sizeof($$));
1321 $$.flags.q.varying = 1;
1325 memset(& $$, 0, sizeof($$));
1326 $$.flags.q.centroid = 1;
1327 $$.flags.q.varying = 1;
1331 memset(& $$, 0, sizeof($$));
1336 memset(& $$, 0, sizeof($$));
1341 memset(& $$, 0, sizeof($$));
1342 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1346 memset(& $$, 0, sizeof($$));
1347 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1351 memset(& $$, 0, sizeof($$));
1352 $$.flags.q.uniform = 1;
1357 type_specifier_no_prec
1361 | precision_qualifier type_specifier_no_prec
1368 type_specifier_no_prec:
1369 type_specifier_nonarray
1370 | type_specifier_nonarray '[' ']'
1373 $$->is_array = true;
1374 $$->array_size = NULL;
1376 | type_specifier_nonarray '[' constant_expression ']'
1379 $$->is_array = true;
1380 $$->array_size = $3;
1384 type_specifier_nonarray:
1385 basic_type_specifier_nonarray
1388 $$ = new(ctx) ast_type_specifier($1);
1389 $$->set_location(yylloc);
1394 $$ = new(ctx) ast_type_specifier($1);
1395 $$->set_location(yylloc);
1400 $$ = new(ctx) ast_type_specifier($1);
1401 $$->set_location(yylloc);
1405 basic_type_specifier_nonarray:
1406 VOID_TOK { $$ = "void"; }
1407 | FLOAT_TOK { $$ = "float"; }
1408 | INT_TOK { $$ = "int"; }
1409 | UINT_TOK { $$ = "uint"; }
1410 | BOOL_TOK { $$ = "bool"; }
1411 | VEC2 { $$ = "vec2"; }
1412 | VEC3 { $$ = "vec3"; }
1413 | VEC4 { $$ = "vec4"; }
1414 | BVEC2 { $$ = "bvec2"; }
1415 | BVEC3 { $$ = "bvec3"; }
1416 | BVEC4 { $$ = "bvec4"; }
1417 | IVEC2 { $$ = "ivec2"; }
1418 | IVEC3 { $$ = "ivec3"; }
1419 | IVEC4 { $$ = "ivec4"; }
1420 | UVEC2 { $$ = "uvec2"; }
1421 | UVEC3 { $$ = "uvec3"; }
1422 | UVEC4 { $$ = "uvec4"; }
1423 | MAT2X2 { $$ = "mat2"; }
1424 | MAT2X3 { $$ = "mat2x3"; }
1425 | MAT2X4 { $$ = "mat2x4"; }
1426 | MAT3X2 { $$ = "mat3x2"; }
1427 | MAT3X3 { $$ = "mat3"; }
1428 | MAT3X4 { $$ = "mat3x4"; }
1429 | MAT4X2 { $$ = "mat4x2"; }
1430 | MAT4X3 { $$ = "mat4x3"; }
1431 | MAT4X4 { $$ = "mat4"; }
1432 | SAMPLER1D { $$ = "sampler1D"; }
1433 | SAMPLER2D { $$ = "sampler2D"; }
1434 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1435 | SAMPLER3D { $$ = "sampler3D"; }
1436 | SAMPLERCUBE { $$ = "samplerCube"; }
1437 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1438 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1439 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1440 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1441 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1442 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1443 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1444 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1445 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1446 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1447 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1448 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1449 | ISAMPLER1D { $$ = "isampler1D"; }
1450 | ISAMPLER2D { $$ = "isampler2D"; }
1451 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1452 | ISAMPLER3D { $$ = "isampler3D"; }
1453 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1454 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1455 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1456 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1457 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1458 | USAMPLER1D { $$ = "usampler1D"; }
1459 | USAMPLER2D { $$ = "usampler2D"; }
1460 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1461 | USAMPLER3D { $$ = "usampler3D"; }
1462 | USAMPLERCUBE { $$ = "usamplerCube"; }
1463 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1464 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1465 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1466 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1467 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1468 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1469 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1470 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1471 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1472 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1475 precision_qualifier:
1477 state->check_precision_qualifiers_allowed(&@1);
1479 $$ = ast_precision_high;
1482 state->check_precision_qualifiers_allowed(&@1);
1484 $$ = ast_precision_medium;
1487 state->check_precision_qualifiers_allowed(&@1);
1489 $$ = ast_precision_low;
1494 STRUCT any_identifier '{' struct_declaration_list '}'
1497 $$ = new(ctx) ast_struct_specifier($2, $4);
1498 $$->set_location(yylloc);
1499 state->symbols->add_type($2, glsl_type::void_type);
1501 | STRUCT '{' struct_declaration_list '}'
1504 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1505 $$->set_location(yylloc);
1509 struct_declaration_list:
1513 $1->link.self_link();
1515 | struct_declaration_list struct_declaration
1518 $$->link.insert_before(& $2->link);
1523 type_specifier struct_declarator_list ';'
1526 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1527 type->set_location(yylloc);
1529 type->specifier = $1;
1530 $$ = new(ctx) ast_declarator_list(type);
1531 $$->set_location(yylloc);
1533 $$->declarations.push_degenerate_list_at_head(& $2->link);
1537 struct_declarator_list:
1541 $1->link.self_link();
1543 | struct_declarator_list ',' struct_declarator
1546 $$->link.insert_before(& $3->link);
1554 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1555 $$->set_location(yylloc);
1557 | any_identifier '[' constant_expression ']'
1560 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1561 $$->set_location(yylloc);
1566 assignment_expression
1569 declaration_statement:
1573 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1576 compound_statement { $$ = (ast_node *) $1; }
1581 declaration_statement
1582 | expression_statement
1583 | selection_statement
1585 | iteration_statement
1593 $$ = new(ctx) ast_compound_statement(true, NULL);
1594 $$->set_location(yylloc);
1598 state->symbols->push_scope();
1603 $$ = new(ctx) ast_compound_statement(true, $3);
1604 $$->set_location(yylloc);
1605 state->symbols->pop_scope();
1609 statement_no_new_scope:
1610 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1614 compound_statement_no_new_scope:
1618 $$ = new(ctx) ast_compound_statement(false, NULL);
1619 $$->set_location(yylloc);
1621 | '{' statement_list '}'
1624 $$ = new(ctx) ast_compound_statement(false, $2);
1625 $$->set_location(yylloc);
1633 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1638 $$->link.self_link();
1640 | statement_list statement
1643 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1647 $$->link.insert_before(& $2->link);
1651 expression_statement:
1655 $$ = new(ctx) ast_expression_statement(NULL);
1656 $$->set_location(yylloc);
1661 $$ = new(ctx) ast_expression_statement($1);
1662 $$->set_location(yylloc);
1666 selection_statement:
1667 IF '(' expression ')' selection_rest_statement
1669 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1671 $$->set_location(yylloc);
1675 selection_rest_statement:
1676 statement ELSE statement
1678 $$.then_statement = $1;
1679 $$.else_statement = $3;
1683 $$.then_statement = $1;
1684 $$.else_statement = NULL;
1691 $$ = (ast_node *) $1;
1693 | fully_specified_type any_identifier '=' initializer
1696 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1697 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1698 decl->set_location(yylloc);
1699 declarator->set_location(yylloc);
1701 declarator->declarations.push_tail(&decl->link);
1707 * siwtch_statement grammar is based on the syntax described in the body
1708 * of the GLSL spec, not in it's appendix!!!
1711 SWITCH '(' expression ')' switch_body
1713 $$ = new(state) ast_switch_statement($3, $5);
1714 $$->set_location(yylloc);
1721 $$ = new(state) ast_switch_body(NULL);
1722 $$->set_location(yylloc);
1724 | '{' case_statement_list '}'
1726 $$ = new(state) ast_switch_body($2);
1727 $$->set_location(yylloc);
1734 $$ = new(state) ast_case_label($2);
1735 $$->set_location(yylloc);
1739 $$ = new(state) ast_case_label(NULL);
1740 $$->set_location(yylloc);
1747 ast_case_label_list *labels = new(state) ast_case_label_list();
1749 labels->labels.push_tail(& $1->link);
1751 $$->set_location(yylloc);
1753 | case_label_list case_label
1756 $$->labels.push_tail(& $2->link);
1761 case_label_list statement
1763 ast_case_statement *stmts = new(state) ast_case_statement($1);
1764 stmts->set_location(yylloc);
1766 stmts->stmts.push_tail(& $2->link);
1769 | case_statement statement
1772 $$->stmts.push_tail(& $2->link);
1776 case_statement_list:
1779 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1780 cases->set_location(yylloc);
1782 cases->cases.push_tail(& $1->link);
1785 | case_statement_list case_statement
1788 $$->cases.push_tail(& $2->link);
1792 iteration_statement:
1793 WHILE '(' condition ')' statement_no_new_scope
1796 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1797 NULL, $3, NULL, $5);
1798 $$->set_location(yylloc);
1800 | DO statement WHILE '(' expression ')' ';'
1803 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1804 NULL, $5, NULL, $2);
1805 $$->set_location(yylloc);
1807 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1810 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1811 $3, $4.cond, $4.rest, $6);
1812 $$->set_location(yylloc);
1817 expression_statement
1818 | declaration_statement
1835 | conditionopt ';' expression
1842 // Grammar Note: No 'goto'. Gotos are not supported.
1847 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1848 $$->set_location(yylloc);
1853 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1854 $$->set_location(yylloc);
1859 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1860 $$->set_location(yylloc);
1862 | RETURN expression ';'
1865 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1866 $$->set_location(yylloc);
1868 | DISCARD ';' // Fragment shader only.
1871 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1872 $$->set_location(yylloc);
1876 external_declaration:
1877 function_definition { $$ = $1; }
1878 | declaration { $$ = $1; }
1879 | pragma_statement { $$ = NULL; }
1880 | layout_defaults { $$ = NULL; }
1883 function_definition:
1884 function_prototype compound_statement_no_new_scope
1887 $$ = new(ctx) ast_function_definition();
1888 $$->set_location(yylloc);
1892 state->symbols->pop_scope();
1896 /* layout_qualifieropt is packed into this rule */
1898 basic_interface_block
1902 | layout_qualifier basic_interface_block
1904 ast_interface_block *block = $2;
1905 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1912 basic_interface_block:
1913 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1915 ast_interface_block *const block = $6;
1917 block->block_name = $2;
1918 block->declarations.push_degenerate_list_at_head(& $4->link);
1920 if ($1.flags.q.uniform) {
1921 if (!state->ARB_uniform_buffer_object_enable) {
1922 _mesa_glsl_error(& @1, state,
1923 "#version 140 / GL_ARB_uniform_buffer_object "
1924 "required for defining uniform blocks\n");
1925 } else if (state->ARB_uniform_buffer_object_warn) {
1926 _mesa_glsl_warning(& @1, state,
1927 "#version 140 / GL_ARB_uniform_buffer_object "
1928 "required for defining uniform blocks\n");
1931 if (state->es_shader || state->language_version < 150) {
1932 _mesa_glsl_error(& @1, state,
1933 "#version 150 required for using "
1934 "interface blocks.\n");
1938 /* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
1939 * "It is illegal to have an input block in a vertex shader
1940 * or an output block in a fragment shader"
1942 if ((state->target == vertex_shader) && $1.flags.q.in) {
1943 _mesa_glsl_error(& @1, state,
1944 "`in' interface block is not allowed for "
1945 "a vertex shader\n");
1946 } else if ((state->target == fragment_shader) && $1.flags.q.out) {
1947 _mesa_glsl_error(& @1, state,
1948 "`out' interface block is not allowed for "
1949 "a fragment shader\n");
1952 /* Since block arrays require names, and both features are added in
1953 * the same language versions, we don't have to explicitly
1954 * version-check both things.
1956 if (block->instance_name != NULL) {
1957 state->check_version(150, 300, & @1, "interface blocks with "
1958 "an instance name are not allowed");
1961 unsigned interface_type_mask;
1962 struct ast_type_qualifier temp_type_qualifier;
1964 /* Get a bitmask containing only the in/out/uniform flags, allowing us
1965 * to ignore other irrelevant flags like interpolation qualifiers.
1967 temp_type_qualifier.flags.i = 0;
1968 temp_type_qualifier.flags.q.uniform = true;
1969 temp_type_qualifier.flags.q.in = true;
1970 temp_type_qualifier.flags.q.out = true;
1971 interface_type_mask = temp_type_qualifier.flags.i;
1973 /* Get the block's interface qualifier. The interface_qualifier
1974 * production rule guarantees that only one bit will be set (and
1975 * it will be in/out/uniform).
1977 unsigned block_interface_qualifier = $1.flags.i;
1979 block->layout.flags.i |= block_interface_qualifier;
1981 foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
1982 ast_type_qualifier& qualifier = member->type->qualifier;
1983 if ((qualifier.flags.i & interface_type_mask) == 0) {
1984 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
1985 * "If no optional qualifier is used in a member declaration, the
1986 * qualifier of the variable is just in, out, or uniform as declared
1987 * by interface-qualifier."
1989 qualifier.flags.i |= block_interface_qualifier;
1990 } else if ((qualifier.flags.i & interface_type_mask) !=
1991 block_interface_qualifier) {
1992 /* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
1993 * "If optional qualifiers are used, they can include interpolation
1994 * and storage qualifiers and they must declare an input, output,
1995 * or uniform variable consistent with the interface qualifier of
1998 _mesa_glsl_error(& @1, state,
1999 "uniform/in/out qualifier on "
2000 "interface block member does not match "
2001 "the interface block\n");
2009 interface_qualifier:
2012 memset(& $$, 0, sizeof($$));
2017 memset(& $$, 0, sizeof($$));
2022 memset(& $$, 0, sizeof($$));
2023 $$.flags.q.uniform = 1;
2030 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2036 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2040 | NEW_IDENTIFIER '[' constant_expression ']'
2042 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2046 | NEW_IDENTIFIER '[' ']'
2048 _mesa_glsl_error(& @1, state,
2049 "instance block arrays must be explicitly sized\n");
2051 $$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
2061 $1->link.self_link();
2063 | member_declaration member_list
2066 $2->link.insert_before(& $$->link);
2070 /* Specifying "uniform" inside of a uniform block is redundant. */
2077 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
2080 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2081 type->set_location(yylloc);
2083 type->qualifier = $1;
2084 type->qualifier.flags.q.uniform = true;
2085 type->specifier = $3;
2086 $$ = new(ctx) ast_declarator_list(type);
2087 $$->set_location(yylloc);
2088 $$->ubo_qualifiers_valid = true;
2090 $$->declarations.push_degenerate_list_at_head(& $4->link);
2092 | uniformopt type_specifier struct_declarator_list ';'
2095 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2096 type->set_location(yylloc);
2098 type->qualifier.flags.q.uniform = true;
2099 type->specifier = $2;
2100 $$ = new(ctx) ast_declarator_list(type);
2101 $$->set_location(yylloc);
2102 $$->ubo_qualifiers_valid = true;
2104 $$->declarations.push_degenerate_list_at_head(& $3->link);
2109 layout_qualifier UNIFORM ';'
2111 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,