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_uniform_block *uniform_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 SAMPLEREXTERNALOES
113 %token STRUCT VOID_TOK WHILE
114 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
115 %type <identifier> any_identifier
116 %type <uniform_block> instance_name_opt
117 %token <real> FLOATCONSTANT
118 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
119 %token <identifier> FIELD_SELECTION
120 %token LEFT_OP RIGHT_OP
121 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
122 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
123 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
126 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
128 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
129 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
130 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
131 %token PRAGMA_INVARIANT_ALL
134 /* Reserved words that are not actually used in the grammar.
136 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
137 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
138 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
139 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
141 %token SIZEOF CAST NAMESPACE USING
142 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
143 %token SUBROUTINE SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS SAMPLER2DMSARRAY
144 %token ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
148 %token COMMON PARTITION ACTIVE FILTER
149 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
150 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
151 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
152 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
153 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
156 %type <identifier> variable_identifier
157 %type <node> statement
158 %type <node> statement_list
159 %type <node> simple_statement
160 %type <n> precision_qualifier
161 %type <type_qualifier> type_qualifier
162 %type <type_qualifier> storage_qualifier
163 %type <type_qualifier> interpolation_qualifier
164 %type <type_qualifier> layout_qualifier
165 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
166 %type <type_qualifier> uniform_block_layout_qualifier
167 %type <type_specifier> type_specifier
168 %type <type_specifier> type_specifier_no_prec
169 %type <type_specifier> type_specifier_nonarray
170 %type <identifier> basic_type_specifier_nonarray
171 %type <fully_specified_type> fully_specified_type
172 %type <function> function_prototype
173 %type <function> function_header
174 %type <function> function_header_with_parameters
175 %type <function> function_declarator
176 %type <parameter_declarator> parameter_declarator
177 %type <parameter_declarator> parameter_declaration
178 %type <type_qualifier> parameter_qualifier
179 %type <type_qualifier> parameter_type_qualifier
180 %type <type_specifier> parameter_type_specifier
181 %type <function_definition> function_definition
182 %type <compound_statement> compound_statement_no_new_scope
183 %type <compound_statement> compound_statement
184 %type <node> statement_no_new_scope
185 %type <node> expression_statement
186 %type <expression> expression
187 %type <expression> primary_expression
188 %type <expression> assignment_expression
189 %type <expression> conditional_expression
190 %type <expression> logical_or_expression
191 %type <expression> logical_xor_expression
192 %type <expression> logical_and_expression
193 %type <expression> inclusive_or_expression
194 %type <expression> exclusive_or_expression
195 %type <expression> and_expression
196 %type <expression> equality_expression
197 %type <expression> relational_expression
198 %type <expression> shift_expression
199 %type <expression> additive_expression
200 %type <expression> multiplicative_expression
201 %type <expression> unary_expression
202 %type <expression> constant_expression
203 %type <expression> integer_expression
204 %type <expression> postfix_expression
205 %type <expression> function_call_header_with_parameters
206 %type <expression> function_call_header_no_parameters
207 %type <expression> function_call_header
208 %type <expression> function_call_generic
209 %type <expression> function_call_or_method
210 %type <expression> function_call
211 %type <expression> method_call_generic
212 %type <expression> method_call_header_with_parameters
213 %type <expression> method_call_header_no_parameters
214 %type <expression> method_call_header
215 %type <n> assignment_operator
216 %type <n> unary_operator
217 %type <expression> function_identifier
218 %type <node> external_declaration
219 %type <declarator_list> init_declarator_list
220 %type <declarator_list> single_declaration
221 %type <expression> initializer
222 %type <node> declaration
223 %type <node> declaration_statement
224 %type <node> jump_statement
225 %type <node> uniform_block
226 %type <uniform_block> basic_uniform_block
227 %type <struct_specifier> struct_specifier
228 %type <declarator_list> struct_declaration_list
229 %type <declarator_list> struct_declaration
230 %type <declaration> struct_declarator
231 %type <declaration> struct_declarator_list
232 %type <declarator_list> member_list
233 %type <declarator_list> member_declaration
234 %type <node> selection_statement
235 %type <selection_rest_statement> selection_rest_statement
236 %type <node> switch_statement
237 %type <switch_body> switch_body
238 %type <case_label_list> case_label_list
239 %type <case_label> case_label
240 %type <case_statement> case_statement
241 %type <case_statement_list> case_statement_list
242 %type <node> iteration_statement
243 %type <node> condition
244 %type <node> conditionopt
245 %type <node> for_init_statement
246 %type <for_rest_statement> for_rest_statement
247 %type <n> integer_constant
251 version_statement extension_statement_list
253 _mesa_glsl_initialize_types(state);
255 external_declaration_list
257 delete state->symbols;
258 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
259 _mesa_glsl_initialize_types(state);
264 /* blank - no #version specified: defaults are already set */
265 | VERSION_TOK INTCONSTANT EOL
267 state->process_version_directive(&@2, $2, NULL);
269 | VERSION_TOK INTCONSTANT any_identifier EOL
271 state->process_version_directive(&@2, $2, $3);
277 | PRAGMA_DEBUG_OFF EOL
278 | PRAGMA_OPTIMIZE_ON EOL
279 | PRAGMA_OPTIMIZE_OFF EOL
280 | PRAGMA_INVARIANT_ALL EOL
282 if (!state->is_version(120, 100)) {
283 _mesa_glsl_warning(& @1, state,
284 "pragma `invariant(all)' not supported in %s "
285 "(GLSL ES 1.00 or GLSL 1.20 required).",
286 state->get_version_string());
288 state->all_invariant = true;
293 extension_statement_list:
295 | extension_statement_list extension_statement
305 EXTENSION any_identifier COLON any_identifier EOL
307 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
313 external_declaration_list:
316 /* FINISHME: The NULL test is required because pragmas are set to
317 * FINISHME: NULL. (See production rule for external_declaration.)
320 state->translation_unit.push_tail(& $1->link);
322 | external_declaration_list external_declaration
324 /* FINISHME: The NULL test is required because pragmas are set to
325 * FINISHME: NULL. (See production rule for external_declaration.)
328 state->translation_unit.push_tail(& $2->link);
341 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
342 $$->set_location(yylloc);
343 $$->primary_expression.identifier = $1;
348 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
349 $$->set_location(yylloc);
350 $$->primary_expression.int_constant = $1;
355 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
356 $$->set_location(yylloc);
357 $$->primary_expression.uint_constant = $1;
362 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
363 $$->set_location(yylloc);
364 $$->primary_expression.float_constant = $1;
369 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
370 $$->set_location(yylloc);
371 $$->primary_expression.bool_constant = $1;
381 | postfix_expression '[' integer_expression ']'
384 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
385 $$->set_location(yylloc);
391 | postfix_expression '.' any_identifier
394 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
395 $$->set_location(yylloc);
396 $$->primary_expression.identifier = $3;
398 | postfix_expression INC_OP
401 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
402 $$->set_location(yylloc);
404 | postfix_expression DEC_OP
407 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
408 $$->set_location(yylloc);
417 function_call_or_method
420 function_call_or_method:
421 function_call_generic
422 | postfix_expression '.' method_call_generic
425 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
426 $$->set_location(yylloc);
430 function_call_generic:
431 function_call_header_with_parameters ')'
432 | function_call_header_no_parameters ')'
435 function_call_header_no_parameters:
436 function_call_header VOID_TOK
437 | function_call_header
440 function_call_header_with_parameters:
441 function_call_header assignment_expression
444 $$->set_location(yylloc);
445 $$->expressions.push_tail(& $2->link);
447 | function_call_header_with_parameters ',' assignment_expression
450 $$->set_location(yylloc);
451 $$->expressions.push_tail(& $3->link);
455 // Grammar Note: Constructors look like functions, but lexical
456 // analysis recognized most of them as keywords. They are now
457 // recognized through "type_specifier".
458 function_call_header:
459 function_identifier '('
466 $$ = new(ctx) ast_function_expression($1);
467 $$->set_location(yylloc);
469 | variable_identifier
472 ast_expression *callee = new(ctx) ast_expression($1);
473 $$ = new(ctx) ast_function_expression(callee);
474 $$->set_location(yylloc);
479 ast_expression *callee = new(ctx) ast_expression($1);
480 $$ = new(ctx) ast_function_expression(callee);
481 $$->set_location(yylloc);
486 method_call_header_with_parameters ')'
487 | method_call_header_no_parameters ')'
490 method_call_header_no_parameters:
491 method_call_header VOID_TOK
495 method_call_header_with_parameters:
496 method_call_header assignment_expression
499 $$->set_location(yylloc);
500 $$->expressions.push_tail(& $2->link);
502 | method_call_header_with_parameters ',' assignment_expression
505 $$->set_location(yylloc);
506 $$->expressions.push_tail(& $3->link);
510 // Grammar Note: Constructors look like methods, but lexical
511 // analysis recognized most of them as keywords. They are now
512 // recognized through "type_specifier".
514 variable_identifier '('
517 ast_expression *callee = new(ctx) ast_expression($1);
518 $$ = new(ctx) ast_function_expression(callee);
519 $$->set_location(yylloc);
523 // Grammar Note: No traditional style type casts.
526 | INC_OP unary_expression
529 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
530 $$->set_location(yylloc);
532 | DEC_OP unary_expression
535 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
536 $$->set_location(yylloc);
538 | unary_operator unary_expression
541 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
542 $$->set_location(yylloc);
546 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
548 '+' { $$ = ast_plus; }
549 | '-' { $$ = ast_neg; }
550 | '!' { $$ = ast_logic_not; }
551 | '~' { $$ = ast_bit_not; }
554 multiplicative_expression:
556 | multiplicative_expression '*' unary_expression
559 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
560 $$->set_location(yylloc);
562 | multiplicative_expression '/' unary_expression
565 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
566 $$->set_location(yylloc);
568 | multiplicative_expression '%' unary_expression
571 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
572 $$->set_location(yylloc);
577 multiplicative_expression
578 | additive_expression '+' multiplicative_expression
581 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
582 $$->set_location(yylloc);
584 | additive_expression '-' multiplicative_expression
587 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
588 $$->set_location(yylloc);
594 | shift_expression LEFT_OP additive_expression
597 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
598 $$->set_location(yylloc);
600 | shift_expression RIGHT_OP additive_expression
603 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
604 $$->set_location(yylloc);
608 relational_expression:
610 | relational_expression '<' shift_expression
613 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
614 $$->set_location(yylloc);
616 | relational_expression '>' shift_expression
619 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
620 $$->set_location(yylloc);
622 | relational_expression LE_OP shift_expression
625 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
626 $$->set_location(yylloc);
628 | relational_expression GE_OP shift_expression
631 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
632 $$->set_location(yylloc);
637 relational_expression
638 | equality_expression EQ_OP relational_expression
641 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
642 $$->set_location(yylloc);
644 | equality_expression NE_OP relational_expression
647 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
648 $$->set_location(yylloc);
654 | and_expression '&' equality_expression
657 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
658 $$->set_location(yylloc);
662 exclusive_or_expression:
664 | exclusive_or_expression '^' and_expression
667 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
668 $$->set_location(yylloc);
672 inclusive_or_expression:
673 exclusive_or_expression
674 | inclusive_or_expression '|' exclusive_or_expression
677 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
678 $$->set_location(yylloc);
682 logical_and_expression:
683 inclusive_or_expression
684 | logical_and_expression AND_OP inclusive_or_expression
687 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
688 $$->set_location(yylloc);
692 logical_xor_expression:
693 logical_and_expression
694 | logical_xor_expression XOR_OP logical_and_expression
697 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
698 $$->set_location(yylloc);
702 logical_or_expression:
703 logical_xor_expression
704 | logical_or_expression OR_OP logical_xor_expression
707 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
708 $$->set_location(yylloc);
712 conditional_expression:
713 logical_or_expression
714 | logical_or_expression '?' expression ':' assignment_expression
717 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
718 $$->set_location(yylloc);
722 assignment_expression:
723 conditional_expression
724 | unary_expression assignment_operator assignment_expression
727 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
728 $$->set_location(yylloc);
733 '=' { $$ = ast_assign; }
734 | MUL_ASSIGN { $$ = ast_mul_assign; }
735 | DIV_ASSIGN { $$ = ast_div_assign; }
736 | MOD_ASSIGN { $$ = ast_mod_assign; }
737 | ADD_ASSIGN { $$ = ast_add_assign; }
738 | SUB_ASSIGN { $$ = ast_sub_assign; }
739 | LEFT_ASSIGN { $$ = ast_ls_assign; }
740 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
741 | AND_ASSIGN { $$ = ast_and_assign; }
742 | XOR_ASSIGN { $$ = ast_xor_assign; }
743 | OR_ASSIGN { $$ = ast_or_assign; }
747 assignment_expression
751 | expression ',' assignment_expression
754 if ($1->oper != ast_sequence) {
755 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
756 $$->set_location(yylloc);
757 $$->expressions.push_tail(& $1->link);
762 $$->expressions.push_tail(& $3->link);
767 conditional_expression
771 function_prototype ';'
773 state->symbols->pop_scope();
776 | init_declarator_list ';'
780 | PRECISION precision_qualifier type_specifier_no_prec ';'
783 $3->is_precision_statement = true;
793 function_declarator ')'
798 | function_header_with_parameters
801 function_header_with_parameters:
802 function_header parameter_declaration
805 $$->parameters.push_tail(& $2->link);
807 | function_header_with_parameters ',' parameter_declaration
810 $$->parameters.push_tail(& $3->link);
815 fully_specified_type variable_identifier '('
818 $$ = new(ctx) ast_function();
819 $$->set_location(yylloc);
820 $$->return_type = $1;
823 state->symbols->add_function(new(state) ir_function($2));
824 state->symbols->push_scope();
828 parameter_declarator:
829 type_specifier any_identifier
832 $$ = new(ctx) ast_parameter_declarator();
833 $$->set_location(yylloc);
834 $$->type = new(ctx) ast_fully_specified_type();
835 $$->type->set_location(yylloc);
836 $$->type->specifier = $1;
839 | type_specifier any_identifier '[' constant_expression ']'
842 $$ = new(ctx) ast_parameter_declarator();
843 $$->set_location(yylloc);
844 $$->type = new(ctx) ast_fully_specified_type();
845 $$->type->set_location(yylloc);
846 $$->type->specifier = $1;
853 parameter_declaration:
854 parameter_type_qualifier parameter_qualifier parameter_declarator
856 $1.flags.i |= $2.flags.i;
859 $$->type->qualifier = $1;
861 | parameter_qualifier parameter_declarator
864 $$->type->qualifier = $1;
866 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
869 $1.flags.i |= $2.flags.i;
871 $$ = new(ctx) ast_parameter_declarator();
872 $$->set_location(yylloc);
873 $$->type = new(ctx) ast_fully_specified_type();
874 $$->type->qualifier = $1;
875 $$->type->specifier = $3;
877 | parameter_qualifier parameter_type_specifier
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 = $2;
891 memset(& $$, 0, sizeof($$));
895 memset(& $$, 0, sizeof($$));
900 memset(& $$, 0, sizeof($$));
905 memset(& $$, 0, sizeof($$));
911 parameter_type_specifier:
915 init_declarator_list:
917 | init_declarator_list ',' any_identifier
920 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
921 decl->set_location(yylloc);
924 $$->declarations.push_tail(&decl->link);
925 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
927 | init_declarator_list ',' any_identifier '[' ']'
930 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
931 decl->set_location(yylloc);
934 $$->declarations.push_tail(&decl->link);
935 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
937 | init_declarator_list ',' any_identifier '[' constant_expression ']'
940 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
941 decl->set_location(yylloc);
944 $$->declarations.push_tail(&decl->link);
945 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
947 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
950 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
951 decl->set_location(yylloc);
954 $$->declarations.push_tail(&decl->link);
955 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
957 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
960 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
961 decl->set_location(yylloc);
964 $$->declarations.push_tail(&decl->link);
965 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
967 | init_declarator_list ',' any_identifier '=' initializer
970 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
971 decl->set_location(yylloc);
974 $$->declarations.push_tail(&decl->link);
975 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
979 // Grammar Note: No 'enum', or 'typedef'.
984 /* Empty declaration list is valid. */
985 $$ = new(ctx) ast_declarator_list($1);
986 $$->set_location(yylloc);
988 | fully_specified_type any_identifier
991 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
993 $$ = new(ctx) ast_declarator_list($1);
994 $$->set_location(yylloc);
995 $$->declarations.push_tail(&decl->link);
997 | fully_specified_type any_identifier '[' ']'
1000 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1002 $$ = new(ctx) ast_declarator_list($1);
1003 $$->set_location(yylloc);
1004 $$->declarations.push_tail(&decl->link);
1006 | fully_specified_type any_identifier '[' constant_expression ']'
1009 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1011 $$ = new(ctx) ast_declarator_list($1);
1012 $$->set_location(yylloc);
1013 $$->declarations.push_tail(&decl->link);
1015 | fully_specified_type any_identifier '[' ']' '=' initializer
1018 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1020 $$ = new(ctx) ast_declarator_list($1);
1021 $$->set_location(yylloc);
1022 $$->declarations.push_tail(&decl->link);
1024 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1027 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1029 $$ = new(ctx) ast_declarator_list($1);
1030 $$->set_location(yylloc);
1031 $$->declarations.push_tail(&decl->link);
1033 | fully_specified_type any_identifier '=' initializer
1036 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1038 $$ = new(ctx) ast_declarator_list($1);
1039 $$->set_location(yylloc);
1040 $$->declarations.push_tail(&decl->link);
1042 | INVARIANT variable_identifier // Vertex only.
1045 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1047 $$ = new(ctx) ast_declarator_list(NULL);
1048 $$->set_location(yylloc);
1049 $$->invariant = true;
1051 $$->declarations.push_tail(&decl->link);
1055 fully_specified_type:
1059 $$ = new(ctx) ast_fully_specified_type();
1060 $$->set_location(yylloc);
1063 | type_qualifier type_specifier
1066 $$ = new(ctx) ast_fully_specified_type();
1067 $$->set_location(yylloc);
1074 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1080 layout_qualifier_id_list:
1082 | layout_qualifier_id_list ',' layout_qualifier_id
1085 if (!$$.merge_qualifier(& @3, state, $3)) {
1092 INTCONSTANT { $$ = $1; }
1093 | UINTCONSTANT { $$ = $1; }
1096 layout_qualifier_id:
1099 memset(& $$, 0, sizeof($$));
1101 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1102 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1103 if (strcmp($1, "origin_upper_left") == 0) {
1104 $$.flags.q.origin_upper_left = 1;
1105 } else if (strcmp($1, "pixel_center_integer") == 0) {
1106 $$.flags.q.pixel_center_integer = 1;
1109 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1110 _mesa_glsl_warning(& @1, state,
1111 "GL_ARB_fragment_coord_conventions layout "
1112 "identifier `%s' used\n", $1);
1116 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1118 (state->AMD_conservative_depth_enable ||
1119 state->ARB_conservative_depth_enable)) {
1120 if (strcmp($1, "depth_any") == 0) {
1121 $$.flags.q.depth_any = 1;
1122 } else if (strcmp($1, "depth_greater") == 0) {
1123 $$.flags.q.depth_greater = 1;
1124 } else if (strcmp($1, "depth_less") == 0) {
1125 $$.flags.q.depth_less = 1;
1126 } else if (strcmp($1, "depth_unchanged") == 0) {
1127 $$.flags.q.depth_unchanged = 1;
1130 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1131 _mesa_glsl_warning(& @1, state,
1132 "GL_AMD_conservative_depth "
1133 "layout qualifier `%s' is used\n", $1);
1135 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1136 _mesa_glsl_warning(& @1, state,
1137 "GL_ARB_conservative_depth "
1138 "layout qualifier `%s' is used\n", $1);
1142 /* See also uniform_block_layout_qualifier. */
1143 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1144 if (strcmp($1, "std140") == 0) {
1145 $$.flags.q.std140 = 1;
1146 } else if (strcmp($1, "shared") == 0) {
1147 $$.flags.q.shared = 1;
1148 } else if (strcmp($1, "column_major") == 0) {
1149 $$.flags.q.column_major = 1;
1150 } else if (strcmp($1, "row_major") == 0) {
1151 $$.flags.q.row_major = 1;
1154 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1155 _mesa_glsl_warning(& @1, state,
1156 "#version 140 / GL_ARB_uniform_buffer_object "
1157 "layout qualifier `%s' is used\n", $1);
1162 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1167 | any_identifier '=' integer_constant
1169 memset(& $$, 0, sizeof($$));
1171 if (state->ARB_explicit_attrib_location_enable) {
1172 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1173 * FINISHME: GLSL 1.30 (or later) are supported.
1175 if (strcmp("location", $1) == 0) {
1176 $$.flags.q.explicit_location = 1;
1181 _mesa_glsl_error(& @3, state,
1182 "invalid location %d specified\n", $3);
1187 if (strcmp("index", $1) == 0) {
1188 $$.flags.q.explicit_index = 1;
1193 _mesa_glsl_error(& @3, state,
1194 "invalid index %d specified\n", $3);
1200 /* If the identifier didn't match any known layout identifiers,
1204 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1207 } else if (state->ARB_explicit_attrib_location_warn) {
1208 _mesa_glsl_warning(& @1, state,
1209 "GL_ARB_explicit_attrib_location layout "
1210 "identifier `%s' used\n", $1);
1213 | uniform_block_layout_qualifier
1216 /* Layout qualifiers for ARB_uniform_buffer_object. */
1217 if (!state->ARB_uniform_buffer_object_enable) {
1218 _mesa_glsl_error(& @1, state,
1219 "#version 140 / GL_ARB_uniform_buffer_object "
1220 "layout qualifier `%s' is used\n", $1);
1221 } else if (state->ARB_uniform_buffer_object_warn) {
1222 _mesa_glsl_warning(& @1, state,
1223 "#version 140 / GL_ARB_uniform_buffer_object "
1224 "layout qualifier `%s' is used\n", $1);
1229 /* This is a separate language rule because we parse these as tokens
1230 * (due to them being reserved keywords) instead of identifiers like
1231 * most qualifiers. See the any_identifier path of
1232 * layout_qualifier_id for the others.
1234 uniform_block_layout_qualifier:
1237 memset(& $$, 0, sizeof($$));
1238 $$.flags.q.row_major = 1;
1242 memset(& $$, 0, sizeof($$));
1243 $$.flags.q.packed = 1;
1247 interpolation_qualifier:
1250 memset(& $$, 0, sizeof($$));
1251 $$.flags.q.smooth = 1;
1255 memset(& $$, 0, sizeof($$));
1256 $$.flags.q.flat = 1;
1260 memset(& $$, 0, sizeof($$));
1261 $$.flags.q.noperspective = 1;
1265 parameter_type_qualifier:
1268 memset(& $$, 0, sizeof($$));
1269 $$.flags.q.constant = 1;
1276 | layout_qualifier storage_qualifier
1279 $$.flags.i |= $2.flags.i;
1281 | interpolation_qualifier
1282 | interpolation_qualifier storage_qualifier
1285 $$.flags.i |= $2.flags.i;
1287 | INVARIANT storage_qualifier
1290 $$.flags.q.invariant = 1;
1292 | INVARIANT interpolation_qualifier storage_qualifier
1295 $$.flags.i |= $3.flags.i;
1296 $$.flags.q.invariant = 1;
1300 memset(& $$, 0, sizeof($$));
1301 $$.flags.q.invariant = 1;
1308 memset(& $$, 0, sizeof($$));
1309 $$.flags.q.constant = 1;
1313 memset(& $$, 0, sizeof($$));
1314 $$.flags.q.attribute = 1;
1318 memset(& $$, 0, sizeof($$));
1319 $$.flags.q.varying = 1;
1323 memset(& $$, 0, sizeof($$));
1324 $$.flags.q.centroid = 1;
1325 $$.flags.q.varying = 1;
1329 memset(& $$, 0, sizeof($$));
1334 memset(& $$, 0, sizeof($$));
1339 memset(& $$, 0, sizeof($$));
1340 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1344 memset(& $$, 0, sizeof($$));
1345 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1349 memset(& $$, 0, sizeof($$));
1350 $$.flags.q.uniform = 1;
1355 type_specifier_no_prec
1359 | precision_qualifier type_specifier_no_prec
1366 type_specifier_no_prec:
1367 type_specifier_nonarray
1368 | type_specifier_nonarray '[' ']'
1371 $$->is_array = true;
1372 $$->array_size = NULL;
1374 | type_specifier_nonarray '[' constant_expression ']'
1377 $$->is_array = true;
1378 $$->array_size = $3;
1382 type_specifier_nonarray:
1383 basic_type_specifier_nonarray
1386 $$ = new(ctx) ast_type_specifier($1);
1387 $$->set_location(yylloc);
1392 $$ = new(ctx) ast_type_specifier($1);
1393 $$->set_location(yylloc);
1398 $$ = new(ctx) ast_type_specifier($1);
1399 $$->set_location(yylloc);
1403 basic_type_specifier_nonarray:
1404 VOID_TOK { $$ = "void"; }
1405 | FLOAT_TOK { $$ = "float"; }
1406 | INT_TOK { $$ = "int"; }
1407 | UINT_TOK { $$ = "uint"; }
1408 | BOOL_TOK { $$ = "bool"; }
1409 | VEC2 { $$ = "vec2"; }
1410 | VEC3 { $$ = "vec3"; }
1411 | VEC4 { $$ = "vec4"; }
1412 | BVEC2 { $$ = "bvec2"; }
1413 | BVEC3 { $$ = "bvec3"; }
1414 | BVEC4 { $$ = "bvec4"; }
1415 | IVEC2 { $$ = "ivec2"; }
1416 | IVEC3 { $$ = "ivec3"; }
1417 | IVEC4 { $$ = "ivec4"; }
1418 | UVEC2 { $$ = "uvec2"; }
1419 | UVEC3 { $$ = "uvec3"; }
1420 | UVEC4 { $$ = "uvec4"; }
1421 | MAT2X2 { $$ = "mat2"; }
1422 | MAT2X3 { $$ = "mat2x3"; }
1423 | MAT2X4 { $$ = "mat2x4"; }
1424 | MAT3X2 { $$ = "mat3x2"; }
1425 | MAT3X3 { $$ = "mat3"; }
1426 | MAT3X4 { $$ = "mat3x4"; }
1427 | MAT4X2 { $$ = "mat4x2"; }
1428 | MAT4X3 { $$ = "mat4x3"; }
1429 | MAT4X4 { $$ = "mat4"; }
1430 | SAMPLER1D { $$ = "sampler1D"; }
1431 | SAMPLER2D { $$ = "sampler2D"; }
1432 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1433 | SAMPLER3D { $$ = "sampler3D"; }
1434 | SAMPLERCUBE { $$ = "samplerCube"; }
1435 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1436 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1437 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1438 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1439 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1440 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1441 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1442 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1443 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1444 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1445 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1446 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1447 | ISAMPLER1D { $$ = "isampler1D"; }
1448 | ISAMPLER2D { $$ = "isampler2D"; }
1449 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1450 | ISAMPLER3D { $$ = "isampler3D"; }
1451 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1452 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1453 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1454 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1455 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1456 | USAMPLER1D { $$ = "usampler1D"; }
1457 | USAMPLER2D { $$ = "usampler2D"; }
1458 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1459 | USAMPLER3D { $$ = "usampler3D"; }
1460 | USAMPLERCUBE { $$ = "usamplerCube"; }
1461 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1462 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1463 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1464 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1467 precision_qualifier:
1469 state->check_precision_qualifiers_allowed(&@1);
1471 $$ = ast_precision_high;
1474 state->check_precision_qualifiers_allowed(&@1);
1476 $$ = ast_precision_medium;
1479 state->check_precision_qualifiers_allowed(&@1);
1481 $$ = ast_precision_low;
1486 STRUCT any_identifier '{' struct_declaration_list '}'
1489 $$ = new(ctx) ast_struct_specifier($2, $4);
1490 $$->set_location(yylloc);
1491 state->symbols->add_type($2, glsl_type::void_type);
1493 | STRUCT '{' struct_declaration_list '}'
1496 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1497 $$->set_location(yylloc);
1501 struct_declaration_list:
1505 $1->link.self_link();
1507 | struct_declaration_list struct_declaration
1510 $$->link.insert_before(& $2->link);
1515 type_specifier struct_declarator_list ';'
1518 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1519 type->set_location(yylloc);
1521 type->specifier = $1;
1522 $$ = new(ctx) ast_declarator_list(type);
1523 $$->set_location(yylloc);
1525 $$->declarations.push_degenerate_list_at_head(& $2->link);
1529 struct_declarator_list:
1533 $1->link.self_link();
1535 | struct_declarator_list ',' struct_declarator
1538 $$->link.insert_before(& $3->link);
1546 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1547 $$->set_location(yylloc);
1549 | any_identifier '[' constant_expression ']'
1552 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1553 $$->set_location(yylloc);
1558 assignment_expression
1561 declaration_statement:
1565 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1568 compound_statement { $$ = (ast_node *) $1; }
1573 declaration_statement
1574 | expression_statement
1575 | selection_statement
1577 | iteration_statement
1585 $$ = new(ctx) ast_compound_statement(true, NULL);
1586 $$->set_location(yylloc);
1590 state->symbols->push_scope();
1595 $$ = new(ctx) ast_compound_statement(true, $3);
1596 $$->set_location(yylloc);
1597 state->symbols->pop_scope();
1601 statement_no_new_scope:
1602 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1606 compound_statement_no_new_scope:
1610 $$ = new(ctx) ast_compound_statement(false, NULL);
1611 $$->set_location(yylloc);
1613 | '{' statement_list '}'
1616 $$ = new(ctx) ast_compound_statement(false, $2);
1617 $$->set_location(yylloc);
1625 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1630 $$->link.self_link();
1632 | statement_list statement
1635 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1639 $$->link.insert_before(& $2->link);
1643 expression_statement:
1647 $$ = new(ctx) ast_expression_statement(NULL);
1648 $$->set_location(yylloc);
1653 $$ = new(ctx) ast_expression_statement($1);
1654 $$->set_location(yylloc);
1658 selection_statement:
1659 IF '(' expression ')' selection_rest_statement
1661 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1663 $$->set_location(yylloc);
1667 selection_rest_statement:
1668 statement ELSE statement
1670 $$.then_statement = $1;
1671 $$.else_statement = $3;
1675 $$.then_statement = $1;
1676 $$.else_statement = NULL;
1683 $$ = (ast_node *) $1;
1685 | fully_specified_type any_identifier '=' initializer
1688 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1689 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1690 decl->set_location(yylloc);
1691 declarator->set_location(yylloc);
1693 declarator->declarations.push_tail(&decl->link);
1699 * siwtch_statement grammar is based on the syntax described in the body
1700 * of the GLSL spec, not in it's appendix!!!
1703 SWITCH '(' expression ')' switch_body
1705 $$ = new(state) ast_switch_statement($3, $5);
1706 $$->set_location(yylloc);
1713 $$ = new(state) ast_switch_body(NULL);
1714 $$->set_location(yylloc);
1716 | '{' case_statement_list '}'
1718 $$ = new(state) ast_switch_body($2);
1719 $$->set_location(yylloc);
1726 $$ = new(state) ast_case_label($2);
1727 $$->set_location(yylloc);
1731 $$ = new(state) ast_case_label(NULL);
1732 $$->set_location(yylloc);
1739 ast_case_label_list *labels = new(state) ast_case_label_list();
1741 labels->labels.push_tail(& $1->link);
1743 $$->set_location(yylloc);
1745 | case_label_list case_label
1748 $$->labels.push_tail(& $2->link);
1753 case_label_list statement
1755 ast_case_statement *stmts = new(state) ast_case_statement($1);
1756 stmts->set_location(yylloc);
1758 stmts->stmts.push_tail(& $2->link);
1761 | case_statement statement
1764 $$->stmts.push_tail(& $2->link);
1768 case_statement_list:
1771 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1772 cases->set_location(yylloc);
1774 cases->cases.push_tail(& $1->link);
1777 | case_statement_list case_statement
1780 $$->cases.push_tail(& $2->link);
1784 iteration_statement:
1785 WHILE '(' condition ')' statement_no_new_scope
1788 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1789 NULL, $3, NULL, $5);
1790 $$->set_location(yylloc);
1792 | DO statement WHILE '(' expression ')' ';'
1795 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1796 NULL, $5, NULL, $2);
1797 $$->set_location(yylloc);
1799 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1802 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1803 $3, $4.cond, $4.rest, $6);
1804 $$->set_location(yylloc);
1809 expression_statement
1810 | declaration_statement
1827 | conditionopt ';' expression
1834 // Grammar Note: No 'goto'. Gotos are not supported.
1839 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1840 $$->set_location(yylloc);
1845 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1846 $$->set_location(yylloc);
1851 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1852 $$->set_location(yylloc);
1854 | RETURN expression ';'
1857 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1858 $$->set_location(yylloc);
1860 | DISCARD ';' // Fragment shader only.
1863 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1864 $$->set_location(yylloc);
1868 external_declaration:
1869 function_definition { $$ = $1; }
1870 | declaration { $$ = $1; }
1871 | pragma_statement { $$ = NULL; }
1872 | layout_defaults { $$ = NULL; }
1875 function_definition:
1876 function_prototype compound_statement_no_new_scope
1879 $$ = new(ctx) ast_function_definition();
1880 $$->set_location(yylloc);
1884 state->symbols->pop_scope();
1888 /* layout_qualifieropt is packed into this rule */
1894 | layout_qualifier basic_uniform_block
1896 ast_uniform_block *block = $2;
1897 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1904 basic_uniform_block:
1905 UNIFORM NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1907 ast_uniform_block *const block = $6;
1909 block->block_name = $2;
1910 block->declarations.push_degenerate_list_at_head(& $4->link);
1912 if (!state->ARB_uniform_buffer_object_enable) {
1913 _mesa_glsl_error(& @1, state,
1914 "#version 140 / GL_ARB_uniform_buffer_object "
1915 "required for defining uniform blocks\n");
1916 } else if (state->ARB_uniform_buffer_object_warn) {
1917 _mesa_glsl_warning(& @1, state,
1918 "#version 140 / GL_ARB_uniform_buffer_object "
1919 "required for defining uniform blocks\n");
1922 /* Since block arrays require names, and both features are added in
1923 * the same language versions, we don't have to explicitly
1924 * version-check both things.
1926 if (block->instance_name != NULL
1927 && !(state->language_version == 300 && state->es_shader)) {
1928 _mesa_glsl_error(& @1, state,
1929 "#version 300 es required for using uniform "
1930 "blocks with an instance name\n");
1940 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1946 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1950 | NEW_IDENTIFIER '[' constant_expression ']'
1952 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1956 | NEW_IDENTIFIER '[' ']'
1958 _mesa_glsl_error(& @1, state,
1959 "instance block arrays must be explicitly sized\n");
1961 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1971 $1->link.self_link();
1973 | member_declaration member_list
1976 $2->link.insert_before(& $$->link);
1980 /* Specifying "uniform" inside of a uniform block is redundant. */
1987 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
1990 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1991 type->set_location(yylloc);
1993 type->qualifier = $1;
1994 type->qualifier.flags.q.uniform = true;
1995 type->specifier = $3;
1996 $$ = new(ctx) ast_declarator_list(type);
1997 $$->set_location(yylloc);
1998 $$->ubo_qualifiers_valid = true;
2000 $$->declarations.push_degenerate_list_at_head(& $4->link);
2002 | uniformopt type_specifier struct_declarator_list ';'
2005 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2006 type->set_location(yylloc);
2008 type->qualifier.flags.q.uniform = true;
2009 type->specifier = $2;
2010 $$ = new(ctx) ast_declarator_list(type);
2011 $$->set_location(yylloc);
2012 $$->ubo_qualifiers_valid = true;
2014 $$->declarations.push_degenerate_list_at_head(& $3->link);
2019 layout_qualifier UNIFORM ';'
2021 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,