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 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 <uniform_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> uniform_block_layout_qualifier
168 %type <type_specifier> type_specifier
169 %type <type_specifier> type_specifier_no_prec
170 %type <type_specifier> type_specifier_nonarray
171 %type <identifier> basic_type_specifier_nonarray
172 %type <fully_specified_type> fully_specified_type
173 %type <function> function_prototype
174 %type <function> function_header
175 %type <function> function_header_with_parameters
176 %type <function> function_declarator
177 %type <parameter_declarator> parameter_declarator
178 %type <parameter_declarator> parameter_declaration
179 %type <type_qualifier> parameter_qualifier
180 %type <type_qualifier> parameter_type_qualifier
181 %type <type_specifier> parameter_type_specifier
182 %type <function_definition> function_definition
183 %type <compound_statement> compound_statement_no_new_scope
184 %type <compound_statement> compound_statement
185 %type <node> statement_no_new_scope
186 %type <node> expression_statement
187 %type <expression> expression
188 %type <expression> primary_expression
189 %type <expression> assignment_expression
190 %type <expression> conditional_expression
191 %type <expression> logical_or_expression
192 %type <expression> logical_xor_expression
193 %type <expression> logical_and_expression
194 %type <expression> inclusive_or_expression
195 %type <expression> exclusive_or_expression
196 %type <expression> and_expression
197 %type <expression> equality_expression
198 %type <expression> relational_expression
199 %type <expression> shift_expression
200 %type <expression> additive_expression
201 %type <expression> multiplicative_expression
202 %type <expression> unary_expression
203 %type <expression> constant_expression
204 %type <expression> integer_expression
205 %type <expression> postfix_expression
206 %type <expression> function_call_header_with_parameters
207 %type <expression> function_call_header_no_parameters
208 %type <expression> function_call_header
209 %type <expression> function_call_generic
210 %type <expression> function_call_or_method
211 %type <expression> function_call
212 %type <expression> method_call_generic
213 %type <expression> method_call_header_with_parameters
214 %type <expression> method_call_header_no_parameters
215 %type <expression> method_call_header
216 %type <n> assignment_operator
217 %type <n> unary_operator
218 %type <expression> function_identifier
219 %type <node> external_declaration
220 %type <declarator_list> init_declarator_list
221 %type <declarator_list> single_declaration
222 %type <expression> initializer
223 %type <node> declaration
224 %type <node> declaration_statement
225 %type <node> jump_statement
226 %type <node> uniform_block
227 %type <uniform_block> basic_uniform_block
228 %type <struct_specifier> struct_specifier
229 %type <declarator_list> struct_declaration_list
230 %type <declarator_list> struct_declaration
231 %type <declaration> struct_declarator
232 %type <declaration> struct_declarator_list
233 %type <declarator_list> member_list
234 %type <declarator_list> member_declaration
235 %type <node> selection_statement
236 %type <selection_rest_statement> selection_rest_statement
237 %type <node> switch_statement
238 %type <switch_body> switch_body
239 %type <case_label_list> case_label_list
240 %type <case_label> case_label
241 %type <case_statement> case_statement
242 %type <case_statement_list> case_statement_list
243 %type <node> iteration_statement
244 %type <node> condition
245 %type <node> conditionopt
246 %type <node> for_init_statement
247 %type <for_rest_statement> for_rest_statement
248 %type <n> integer_constant
252 version_statement extension_statement_list
254 _mesa_glsl_initialize_types(state);
256 external_declaration_list
258 delete state->symbols;
259 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
260 _mesa_glsl_initialize_types(state);
265 /* blank - no #version specified: defaults are already set */
266 | VERSION_TOK INTCONSTANT EOL
268 state->process_version_directive(&@2, $2, NULL);
270 | VERSION_TOK INTCONSTANT any_identifier EOL
272 state->process_version_directive(&@2, $2, $3);
278 | PRAGMA_DEBUG_OFF EOL
279 | PRAGMA_OPTIMIZE_ON EOL
280 | PRAGMA_OPTIMIZE_OFF EOL
281 | PRAGMA_INVARIANT_ALL EOL
283 if (!state->is_version(120, 100)) {
284 _mesa_glsl_warning(& @1, state,
285 "pragma `invariant(all)' not supported in %s "
286 "(GLSL ES 1.00 or GLSL 1.20 required).",
287 state->get_version_string());
289 state->all_invariant = true;
294 extension_statement_list:
296 | extension_statement_list extension_statement
306 EXTENSION any_identifier COLON any_identifier EOL
308 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
314 external_declaration_list:
317 /* FINISHME: The NULL test is required because pragmas are set to
318 * FINISHME: NULL. (See production rule for external_declaration.)
321 state->translation_unit.push_tail(& $1->link);
323 | external_declaration_list external_declaration
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(& $2->link);
342 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
343 $$->set_location(yylloc);
344 $$->primary_expression.identifier = $1;
349 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
350 $$->set_location(yylloc);
351 $$->primary_expression.int_constant = $1;
356 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
357 $$->set_location(yylloc);
358 $$->primary_expression.uint_constant = $1;
363 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
364 $$->set_location(yylloc);
365 $$->primary_expression.float_constant = $1;
370 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
371 $$->set_location(yylloc);
372 $$->primary_expression.bool_constant = $1;
382 | postfix_expression '[' integer_expression ']'
385 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
386 $$->set_location(yylloc);
392 | postfix_expression '.' any_identifier
395 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
396 $$->set_location(yylloc);
397 $$->primary_expression.identifier = $3;
399 | postfix_expression INC_OP
402 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
403 $$->set_location(yylloc);
405 | postfix_expression DEC_OP
408 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
409 $$->set_location(yylloc);
418 function_call_or_method
421 function_call_or_method:
422 function_call_generic
423 | postfix_expression '.' method_call_generic
426 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
427 $$->set_location(yylloc);
431 function_call_generic:
432 function_call_header_with_parameters ')'
433 | function_call_header_no_parameters ')'
436 function_call_header_no_parameters:
437 function_call_header VOID_TOK
438 | function_call_header
441 function_call_header_with_parameters:
442 function_call_header assignment_expression
445 $$->set_location(yylloc);
446 $$->expressions.push_tail(& $2->link);
448 | function_call_header_with_parameters ',' assignment_expression
451 $$->set_location(yylloc);
452 $$->expressions.push_tail(& $3->link);
456 // Grammar Note: Constructors look like functions, but lexical
457 // analysis recognized most of them as keywords. They are now
458 // recognized through "type_specifier".
459 function_call_header:
460 function_identifier '('
467 $$ = new(ctx) ast_function_expression($1);
468 $$->set_location(yylloc);
470 | variable_identifier
473 ast_expression *callee = new(ctx) ast_expression($1);
474 $$ = new(ctx) ast_function_expression(callee);
475 $$->set_location(yylloc);
480 ast_expression *callee = new(ctx) ast_expression($1);
481 $$ = new(ctx) ast_function_expression(callee);
482 $$->set_location(yylloc);
487 method_call_header_with_parameters ')'
488 | method_call_header_no_parameters ')'
491 method_call_header_no_parameters:
492 method_call_header VOID_TOK
496 method_call_header_with_parameters:
497 method_call_header assignment_expression
500 $$->set_location(yylloc);
501 $$->expressions.push_tail(& $2->link);
503 | method_call_header_with_parameters ',' assignment_expression
506 $$->set_location(yylloc);
507 $$->expressions.push_tail(& $3->link);
511 // Grammar Note: Constructors look like methods, but lexical
512 // analysis recognized most of them as keywords. They are now
513 // recognized through "type_specifier".
515 variable_identifier '('
518 ast_expression *callee = new(ctx) ast_expression($1);
519 $$ = new(ctx) ast_function_expression(callee);
520 $$->set_location(yylloc);
524 // Grammar Note: No traditional style type casts.
527 | INC_OP unary_expression
530 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
531 $$->set_location(yylloc);
533 | DEC_OP unary_expression
536 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
537 $$->set_location(yylloc);
539 | unary_operator unary_expression
542 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
543 $$->set_location(yylloc);
547 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
549 '+' { $$ = ast_plus; }
550 | '-' { $$ = ast_neg; }
551 | '!' { $$ = ast_logic_not; }
552 | '~' { $$ = ast_bit_not; }
555 multiplicative_expression:
557 | multiplicative_expression '*' unary_expression
560 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
561 $$->set_location(yylloc);
563 | multiplicative_expression '/' unary_expression
566 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
567 $$->set_location(yylloc);
569 | multiplicative_expression '%' unary_expression
572 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
573 $$->set_location(yylloc);
578 multiplicative_expression
579 | additive_expression '+' multiplicative_expression
582 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
583 $$->set_location(yylloc);
585 | additive_expression '-' multiplicative_expression
588 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
589 $$->set_location(yylloc);
595 | shift_expression LEFT_OP additive_expression
598 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
599 $$->set_location(yylloc);
601 | shift_expression RIGHT_OP additive_expression
604 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
605 $$->set_location(yylloc);
609 relational_expression:
611 | relational_expression '<' shift_expression
614 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
615 $$->set_location(yylloc);
617 | relational_expression '>' shift_expression
620 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
621 $$->set_location(yylloc);
623 | relational_expression LE_OP shift_expression
626 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
627 $$->set_location(yylloc);
629 | relational_expression GE_OP shift_expression
632 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
633 $$->set_location(yylloc);
638 relational_expression
639 | equality_expression EQ_OP relational_expression
642 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
643 $$->set_location(yylloc);
645 | equality_expression NE_OP relational_expression
648 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
649 $$->set_location(yylloc);
655 | and_expression '&' equality_expression
658 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
659 $$->set_location(yylloc);
663 exclusive_or_expression:
665 | exclusive_or_expression '^' and_expression
668 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
669 $$->set_location(yylloc);
673 inclusive_or_expression:
674 exclusive_or_expression
675 | inclusive_or_expression '|' exclusive_or_expression
678 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
679 $$->set_location(yylloc);
683 logical_and_expression:
684 inclusive_or_expression
685 | logical_and_expression AND_OP inclusive_or_expression
688 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
689 $$->set_location(yylloc);
693 logical_xor_expression:
694 logical_and_expression
695 | logical_xor_expression XOR_OP logical_and_expression
698 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
699 $$->set_location(yylloc);
703 logical_or_expression:
704 logical_xor_expression
705 | logical_or_expression OR_OP logical_xor_expression
708 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
709 $$->set_location(yylloc);
713 conditional_expression:
714 logical_or_expression
715 | logical_or_expression '?' expression ':' assignment_expression
718 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
719 $$->set_location(yylloc);
723 assignment_expression:
724 conditional_expression
725 | unary_expression assignment_operator assignment_expression
728 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
729 $$->set_location(yylloc);
734 '=' { $$ = ast_assign; }
735 | MUL_ASSIGN { $$ = ast_mul_assign; }
736 | DIV_ASSIGN { $$ = ast_div_assign; }
737 | MOD_ASSIGN { $$ = ast_mod_assign; }
738 | ADD_ASSIGN { $$ = ast_add_assign; }
739 | SUB_ASSIGN { $$ = ast_sub_assign; }
740 | LEFT_ASSIGN { $$ = ast_ls_assign; }
741 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
742 | AND_ASSIGN { $$ = ast_and_assign; }
743 | XOR_ASSIGN { $$ = ast_xor_assign; }
744 | OR_ASSIGN { $$ = ast_or_assign; }
748 assignment_expression
752 | expression ',' assignment_expression
755 if ($1->oper != ast_sequence) {
756 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
757 $$->set_location(yylloc);
758 $$->expressions.push_tail(& $1->link);
763 $$->expressions.push_tail(& $3->link);
768 conditional_expression
772 function_prototype ';'
774 state->symbols->pop_scope();
777 | init_declarator_list ';'
781 | PRECISION precision_qualifier type_specifier_no_prec ';'
784 $3->is_precision_statement = true;
794 function_declarator ')'
799 | function_header_with_parameters
802 function_header_with_parameters:
803 function_header parameter_declaration
806 $$->parameters.push_tail(& $2->link);
808 | function_header_with_parameters ',' parameter_declaration
811 $$->parameters.push_tail(& $3->link);
816 fully_specified_type variable_identifier '('
819 $$ = new(ctx) ast_function();
820 $$->set_location(yylloc);
821 $$->return_type = $1;
824 state->symbols->add_function(new(state) ir_function($2));
825 state->symbols->push_scope();
829 parameter_declarator:
830 type_specifier any_identifier
833 $$ = new(ctx) ast_parameter_declarator();
834 $$->set_location(yylloc);
835 $$->type = new(ctx) ast_fully_specified_type();
836 $$->type->set_location(yylloc);
837 $$->type->specifier = $1;
840 | type_specifier any_identifier '[' constant_expression ']'
843 $$ = new(ctx) ast_parameter_declarator();
844 $$->set_location(yylloc);
845 $$->type = new(ctx) ast_fully_specified_type();
846 $$->type->set_location(yylloc);
847 $$->type->specifier = $1;
854 parameter_declaration:
855 parameter_type_qualifier parameter_qualifier parameter_declarator
857 $1.flags.i |= $2.flags.i;
860 $$->type->qualifier = $1;
862 | parameter_qualifier parameter_declarator
865 $$->type->qualifier = $1;
867 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
870 $1.flags.i |= $2.flags.i;
872 $$ = new(ctx) ast_parameter_declarator();
873 $$->set_location(yylloc);
874 $$->type = new(ctx) ast_fully_specified_type();
875 $$->type->qualifier = $1;
876 $$->type->specifier = $3;
878 | parameter_qualifier parameter_type_specifier
881 $$ = new(ctx) ast_parameter_declarator();
882 $$->set_location(yylloc);
883 $$->type = new(ctx) ast_fully_specified_type();
884 $$->type->qualifier = $1;
885 $$->type->specifier = $2;
892 memset(& $$, 0, sizeof($$));
896 memset(& $$, 0, sizeof($$));
901 memset(& $$, 0, sizeof($$));
906 memset(& $$, 0, sizeof($$));
912 parameter_type_specifier:
916 init_declarator_list:
918 | init_declarator_list ',' any_identifier
921 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
922 decl->set_location(yylloc);
925 $$->declarations.push_tail(&decl->link);
926 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
928 | init_declarator_list ',' any_identifier '[' ']'
931 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
932 decl->set_location(yylloc);
935 $$->declarations.push_tail(&decl->link);
936 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
938 | init_declarator_list ',' any_identifier '[' constant_expression ']'
941 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
942 decl->set_location(yylloc);
945 $$->declarations.push_tail(&decl->link);
946 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
948 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
951 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
952 decl->set_location(yylloc);
955 $$->declarations.push_tail(&decl->link);
956 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
958 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
961 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
962 decl->set_location(yylloc);
965 $$->declarations.push_tail(&decl->link);
966 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
968 | init_declarator_list ',' any_identifier '=' initializer
971 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
972 decl->set_location(yylloc);
975 $$->declarations.push_tail(&decl->link);
976 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
980 // Grammar Note: No 'enum', or 'typedef'.
985 /* Empty declaration list is valid. */
986 $$ = new(ctx) ast_declarator_list($1);
987 $$->set_location(yylloc);
989 | fully_specified_type any_identifier
992 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
994 $$ = new(ctx) ast_declarator_list($1);
995 $$->set_location(yylloc);
996 $$->declarations.push_tail(&decl->link);
998 | fully_specified_type any_identifier '[' ']'
1001 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1003 $$ = new(ctx) ast_declarator_list($1);
1004 $$->set_location(yylloc);
1005 $$->declarations.push_tail(&decl->link);
1007 | fully_specified_type any_identifier '[' constant_expression ']'
1010 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1012 $$ = new(ctx) ast_declarator_list($1);
1013 $$->set_location(yylloc);
1014 $$->declarations.push_tail(&decl->link);
1016 | fully_specified_type any_identifier '[' ']' '=' initializer
1019 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1021 $$ = new(ctx) ast_declarator_list($1);
1022 $$->set_location(yylloc);
1023 $$->declarations.push_tail(&decl->link);
1025 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1028 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1030 $$ = new(ctx) ast_declarator_list($1);
1031 $$->set_location(yylloc);
1032 $$->declarations.push_tail(&decl->link);
1034 | fully_specified_type any_identifier '=' initializer
1037 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1039 $$ = new(ctx) ast_declarator_list($1);
1040 $$->set_location(yylloc);
1041 $$->declarations.push_tail(&decl->link);
1043 | INVARIANT variable_identifier // Vertex only.
1046 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1048 $$ = new(ctx) ast_declarator_list(NULL);
1049 $$->set_location(yylloc);
1050 $$->invariant = true;
1052 $$->declarations.push_tail(&decl->link);
1056 fully_specified_type:
1060 $$ = new(ctx) ast_fully_specified_type();
1061 $$->set_location(yylloc);
1064 | type_qualifier type_specifier
1067 $$ = new(ctx) ast_fully_specified_type();
1068 $$->set_location(yylloc);
1075 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1081 layout_qualifier_id_list:
1083 | layout_qualifier_id_list ',' layout_qualifier_id
1086 if (!$$.merge_qualifier(& @3, state, $3)) {
1093 INTCONSTANT { $$ = $1; }
1094 | UINTCONSTANT { $$ = $1; }
1097 layout_qualifier_id:
1100 memset(& $$, 0, sizeof($$));
1102 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1103 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1104 if (strcmp($1, "origin_upper_left") == 0) {
1105 $$.flags.q.origin_upper_left = 1;
1106 } else if (strcmp($1, "pixel_center_integer") == 0) {
1107 $$.flags.q.pixel_center_integer = 1;
1110 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1111 _mesa_glsl_warning(& @1, state,
1112 "GL_ARB_fragment_coord_conventions layout "
1113 "identifier `%s' used\n", $1);
1117 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1119 (state->AMD_conservative_depth_enable ||
1120 state->ARB_conservative_depth_enable)) {
1121 if (strcmp($1, "depth_any") == 0) {
1122 $$.flags.q.depth_any = 1;
1123 } else if (strcmp($1, "depth_greater") == 0) {
1124 $$.flags.q.depth_greater = 1;
1125 } else if (strcmp($1, "depth_less") == 0) {
1126 $$.flags.q.depth_less = 1;
1127 } else if (strcmp($1, "depth_unchanged") == 0) {
1128 $$.flags.q.depth_unchanged = 1;
1131 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1132 _mesa_glsl_warning(& @1, state,
1133 "GL_AMD_conservative_depth "
1134 "layout qualifier `%s' is used\n", $1);
1136 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1137 _mesa_glsl_warning(& @1, state,
1138 "GL_ARB_conservative_depth "
1139 "layout qualifier `%s' is used\n", $1);
1143 /* See also uniform_block_layout_qualifier. */
1144 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1145 if (strcmp($1, "std140") == 0) {
1146 $$.flags.q.std140 = 1;
1147 } else if (strcmp($1, "shared") == 0) {
1148 $$.flags.q.shared = 1;
1149 } else if (strcmp($1, "column_major") == 0) {
1150 $$.flags.q.column_major = 1;
1151 } else if (strcmp($1, "row_major") == 0) {
1152 $$.flags.q.row_major = 1;
1155 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1156 _mesa_glsl_warning(& @1, state,
1157 "#version 140 / GL_ARB_uniform_buffer_object "
1158 "layout qualifier `%s' is used\n", $1);
1163 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1168 | any_identifier '=' integer_constant
1170 memset(& $$, 0, sizeof($$));
1172 if (state->ARB_explicit_attrib_location_enable) {
1173 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1174 * FINISHME: GLSL 1.30 (or later) are supported.
1176 if (strcmp("location", $1) == 0) {
1177 $$.flags.q.explicit_location = 1;
1182 _mesa_glsl_error(& @3, state,
1183 "invalid location %d specified\n", $3);
1188 if (strcmp("index", $1) == 0) {
1189 $$.flags.q.explicit_index = 1;
1194 _mesa_glsl_error(& @3, state,
1195 "invalid index %d specified\n", $3);
1201 /* If the identifier didn't match any known layout identifiers,
1205 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1208 } else if (state->ARB_explicit_attrib_location_warn) {
1209 _mesa_glsl_warning(& @1, state,
1210 "GL_ARB_explicit_attrib_location layout "
1211 "identifier `%s' used\n", $1);
1214 | uniform_block_layout_qualifier
1217 /* Layout qualifiers for ARB_uniform_buffer_object. */
1218 if (!state->ARB_uniform_buffer_object_enable) {
1219 _mesa_glsl_error(& @1, state,
1220 "#version 140 / GL_ARB_uniform_buffer_object "
1221 "layout qualifier `%s' is used\n", $1);
1222 } else if (state->ARB_uniform_buffer_object_warn) {
1223 _mesa_glsl_warning(& @1, state,
1224 "#version 140 / GL_ARB_uniform_buffer_object "
1225 "layout qualifier `%s' is used\n", $1);
1230 /* This is a separate language rule because we parse these as tokens
1231 * (due to them being reserved keywords) instead of identifiers like
1232 * most qualifiers. See the any_identifier path of
1233 * layout_qualifier_id for the others.
1235 uniform_block_layout_qualifier:
1238 memset(& $$, 0, sizeof($$));
1239 $$.flags.q.row_major = 1;
1243 memset(& $$, 0, sizeof($$));
1244 $$.flags.q.packed = 1;
1248 interpolation_qualifier:
1251 memset(& $$, 0, sizeof($$));
1252 $$.flags.q.smooth = 1;
1256 memset(& $$, 0, sizeof($$));
1257 $$.flags.q.flat = 1;
1261 memset(& $$, 0, sizeof($$));
1262 $$.flags.q.noperspective = 1;
1266 parameter_type_qualifier:
1269 memset(& $$, 0, sizeof($$));
1270 $$.flags.q.constant = 1;
1277 | layout_qualifier storage_qualifier
1280 $$.flags.i |= $2.flags.i;
1282 | interpolation_qualifier
1283 | interpolation_qualifier storage_qualifier
1286 $$.flags.i |= $2.flags.i;
1288 | INVARIANT storage_qualifier
1291 $$.flags.q.invariant = 1;
1293 | INVARIANT interpolation_qualifier storage_qualifier
1296 $$.flags.i |= $3.flags.i;
1297 $$.flags.q.invariant = 1;
1301 memset(& $$, 0, sizeof($$));
1302 $$.flags.q.invariant = 1;
1309 memset(& $$, 0, sizeof($$));
1310 $$.flags.q.constant = 1;
1314 memset(& $$, 0, sizeof($$));
1315 $$.flags.q.attribute = 1;
1319 memset(& $$, 0, sizeof($$));
1320 $$.flags.q.varying = 1;
1324 memset(& $$, 0, sizeof($$));
1325 $$.flags.q.centroid = 1;
1326 $$.flags.q.varying = 1;
1330 memset(& $$, 0, sizeof($$));
1335 memset(& $$, 0, sizeof($$));
1340 memset(& $$, 0, sizeof($$));
1341 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1345 memset(& $$, 0, sizeof($$));
1346 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1350 memset(& $$, 0, sizeof($$));
1351 $$.flags.q.uniform = 1;
1356 type_specifier_no_prec
1360 | precision_qualifier type_specifier_no_prec
1367 type_specifier_no_prec:
1368 type_specifier_nonarray
1369 | type_specifier_nonarray '[' ']'
1372 $$->is_array = true;
1373 $$->array_size = NULL;
1375 | type_specifier_nonarray '[' constant_expression ']'
1378 $$->is_array = true;
1379 $$->array_size = $3;
1383 type_specifier_nonarray:
1384 basic_type_specifier_nonarray
1387 $$ = new(ctx) ast_type_specifier($1);
1388 $$->set_location(yylloc);
1393 $$ = new(ctx) ast_type_specifier($1);
1394 $$->set_location(yylloc);
1399 $$ = new(ctx) ast_type_specifier($1);
1400 $$->set_location(yylloc);
1404 basic_type_specifier_nonarray:
1405 VOID_TOK { $$ = "void"; }
1406 | FLOAT_TOK { $$ = "float"; }
1407 | INT_TOK { $$ = "int"; }
1408 | UINT_TOK { $$ = "uint"; }
1409 | BOOL_TOK { $$ = "bool"; }
1410 | VEC2 { $$ = "vec2"; }
1411 | VEC3 { $$ = "vec3"; }
1412 | VEC4 { $$ = "vec4"; }
1413 | BVEC2 { $$ = "bvec2"; }
1414 | BVEC3 { $$ = "bvec3"; }
1415 | BVEC4 { $$ = "bvec4"; }
1416 | IVEC2 { $$ = "ivec2"; }
1417 | IVEC3 { $$ = "ivec3"; }
1418 | IVEC4 { $$ = "ivec4"; }
1419 | UVEC2 { $$ = "uvec2"; }
1420 | UVEC3 { $$ = "uvec3"; }
1421 | UVEC4 { $$ = "uvec4"; }
1422 | MAT2X2 { $$ = "mat2"; }
1423 | MAT2X3 { $$ = "mat2x3"; }
1424 | MAT2X4 { $$ = "mat2x4"; }
1425 | MAT3X2 { $$ = "mat3x2"; }
1426 | MAT3X3 { $$ = "mat3"; }
1427 | MAT3X4 { $$ = "mat3x4"; }
1428 | MAT4X2 { $$ = "mat4x2"; }
1429 | MAT4X3 { $$ = "mat4x3"; }
1430 | MAT4X4 { $$ = "mat4"; }
1431 | SAMPLER1D { $$ = "sampler1D"; }
1432 | SAMPLER2D { $$ = "sampler2D"; }
1433 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1434 | SAMPLER3D { $$ = "sampler3D"; }
1435 | SAMPLERCUBE { $$ = "samplerCube"; }
1436 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1437 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1438 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1439 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1440 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1441 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1442 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1443 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1444 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1445 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1446 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1447 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1448 | ISAMPLER1D { $$ = "isampler1D"; }
1449 | ISAMPLER2D { $$ = "isampler2D"; }
1450 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1451 | ISAMPLER3D { $$ = "isampler3D"; }
1452 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1453 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1454 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1455 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1456 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1457 | USAMPLER1D { $$ = "usampler1D"; }
1458 | USAMPLER2D { $$ = "usampler2D"; }
1459 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1460 | USAMPLER3D { $$ = "usampler3D"; }
1461 | USAMPLERCUBE { $$ = "usamplerCube"; }
1462 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1463 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1464 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1465 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1466 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1467 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1468 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1469 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1470 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1471 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1474 precision_qualifier:
1476 state->check_precision_qualifiers_allowed(&@1);
1478 $$ = ast_precision_high;
1481 state->check_precision_qualifiers_allowed(&@1);
1483 $$ = ast_precision_medium;
1486 state->check_precision_qualifiers_allowed(&@1);
1488 $$ = ast_precision_low;
1493 STRUCT any_identifier '{' struct_declaration_list '}'
1496 $$ = new(ctx) ast_struct_specifier($2, $4);
1497 $$->set_location(yylloc);
1498 state->symbols->add_type($2, glsl_type::void_type);
1500 | STRUCT '{' struct_declaration_list '}'
1503 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1504 $$->set_location(yylloc);
1508 struct_declaration_list:
1512 $1->link.self_link();
1514 | struct_declaration_list struct_declaration
1517 $$->link.insert_before(& $2->link);
1522 type_specifier struct_declarator_list ';'
1525 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1526 type->set_location(yylloc);
1528 type->specifier = $1;
1529 $$ = new(ctx) ast_declarator_list(type);
1530 $$->set_location(yylloc);
1532 $$->declarations.push_degenerate_list_at_head(& $2->link);
1536 struct_declarator_list:
1540 $1->link.self_link();
1542 | struct_declarator_list ',' struct_declarator
1545 $$->link.insert_before(& $3->link);
1553 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1554 $$->set_location(yylloc);
1556 | any_identifier '[' constant_expression ']'
1559 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1560 $$->set_location(yylloc);
1565 assignment_expression
1568 declaration_statement:
1572 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1575 compound_statement { $$ = (ast_node *) $1; }
1580 declaration_statement
1581 | expression_statement
1582 | selection_statement
1584 | iteration_statement
1592 $$ = new(ctx) ast_compound_statement(true, NULL);
1593 $$->set_location(yylloc);
1597 state->symbols->push_scope();
1602 $$ = new(ctx) ast_compound_statement(true, $3);
1603 $$->set_location(yylloc);
1604 state->symbols->pop_scope();
1608 statement_no_new_scope:
1609 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1613 compound_statement_no_new_scope:
1617 $$ = new(ctx) ast_compound_statement(false, NULL);
1618 $$->set_location(yylloc);
1620 | '{' statement_list '}'
1623 $$ = new(ctx) ast_compound_statement(false, $2);
1624 $$->set_location(yylloc);
1632 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1637 $$->link.self_link();
1639 | statement_list statement
1642 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1646 $$->link.insert_before(& $2->link);
1650 expression_statement:
1654 $$ = new(ctx) ast_expression_statement(NULL);
1655 $$->set_location(yylloc);
1660 $$ = new(ctx) ast_expression_statement($1);
1661 $$->set_location(yylloc);
1665 selection_statement:
1666 IF '(' expression ')' selection_rest_statement
1668 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1670 $$->set_location(yylloc);
1674 selection_rest_statement:
1675 statement ELSE statement
1677 $$.then_statement = $1;
1678 $$.else_statement = $3;
1682 $$.then_statement = $1;
1683 $$.else_statement = NULL;
1690 $$ = (ast_node *) $1;
1692 | fully_specified_type any_identifier '=' initializer
1695 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1696 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1697 decl->set_location(yylloc);
1698 declarator->set_location(yylloc);
1700 declarator->declarations.push_tail(&decl->link);
1706 * siwtch_statement grammar is based on the syntax described in the body
1707 * of the GLSL spec, not in it's appendix!!!
1710 SWITCH '(' expression ')' switch_body
1712 $$ = new(state) ast_switch_statement($3, $5);
1713 $$->set_location(yylloc);
1720 $$ = new(state) ast_switch_body(NULL);
1721 $$->set_location(yylloc);
1723 | '{' case_statement_list '}'
1725 $$ = new(state) ast_switch_body($2);
1726 $$->set_location(yylloc);
1733 $$ = new(state) ast_case_label($2);
1734 $$->set_location(yylloc);
1738 $$ = new(state) ast_case_label(NULL);
1739 $$->set_location(yylloc);
1746 ast_case_label_list *labels = new(state) ast_case_label_list();
1748 labels->labels.push_tail(& $1->link);
1750 $$->set_location(yylloc);
1752 | case_label_list case_label
1755 $$->labels.push_tail(& $2->link);
1760 case_label_list statement
1762 ast_case_statement *stmts = new(state) ast_case_statement($1);
1763 stmts->set_location(yylloc);
1765 stmts->stmts.push_tail(& $2->link);
1768 | case_statement statement
1771 $$->stmts.push_tail(& $2->link);
1775 case_statement_list:
1778 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1779 cases->set_location(yylloc);
1781 cases->cases.push_tail(& $1->link);
1784 | case_statement_list case_statement
1787 $$->cases.push_tail(& $2->link);
1791 iteration_statement:
1792 WHILE '(' condition ')' statement_no_new_scope
1795 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1796 NULL, $3, NULL, $5);
1797 $$->set_location(yylloc);
1799 | DO statement WHILE '(' expression ')' ';'
1802 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1803 NULL, $5, NULL, $2);
1804 $$->set_location(yylloc);
1806 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1809 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1810 $3, $4.cond, $4.rest, $6);
1811 $$->set_location(yylloc);
1816 expression_statement
1817 | declaration_statement
1834 | conditionopt ';' expression
1841 // Grammar Note: No 'goto'. Gotos are not supported.
1846 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1847 $$->set_location(yylloc);
1852 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1853 $$->set_location(yylloc);
1858 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1859 $$->set_location(yylloc);
1861 | RETURN expression ';'
1864 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1865 $$->set_location(yylloc);
1867 | DISCARD ';' // Fragment shader only.
1870 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1871 $$->set_location(yylloc);
1875 external_declaration:
1876 function_definition { $$ = $1; }
1877 | declaration { $$ = $1; }
1878 | pragma_statement { $$ = NULL; }
1879 | layout_defaults { $$ = NULL; }
1882 function_definition:
1883 function_prototype compound_statement_no_new_scope
1886 $$ = new(ctx) ast_function_definition();
1887 $$->set_location(yylloc);
1891 state->symbols->pop_scope();
1895 /* layout_qualifieropt is packed into this rule */
1901 | layout_qualifier basic_uniform_block
1903 ast_uniform_block *block = $2;
1904 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1911 basic_uniform_block:
1912 UNIFORM NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1914 ast_uniform_block *const block = $6;
1916 block->block_name = $2;
1917 block->declarations.push_degenerate_list_at_head(& $4->link);
1919 if (!state->ARB_uniform_buffer_object_enable) {
1920 _mesa_glsl_error(& @1, state,
1921 "#version 140 / GL_ARB_uniform_buffer_object "
1922 "required for defining uniform blocks\n");
1923 } else if (state->ARB_uniform_buffer_object_warn) {
1924 _mesa_glsl_warning(& @1, state,
1925 "#version 140 / GL_ARB_uniform_buffer_object "
1926 "required for defining uniform blocks\n");
1929 /* Since block arrays require names, and both features are added in
1930 * the same language versions, we don't have to explicitly
1931 * version-check both things.
1933 if (block->instance_name != NULL
1934 && !(state->language_version == 300 && state->es_shader)) {
1935 _mesa_glsl_error(& @1, state,
1936 "#version 300 es required for using uniform "
1937 "blocks with an instance name\n");
1947 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1953 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1957 | NEW_IDENTIFIER '[' constant_expression ']'
1959 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1963 | NEW_IDENTIFIER '[' ']'
1965 _mesa_glsl_error(& @1, state,
1966 "instance block arrays must be explicitly sized\n");
1968 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1978 $1->link.self_link();
1980 | member_declaration member_list
1983 $2->link.insert_before(& $$->link);
1987 /* Specifying "uniform" inside of a uniform block is redundant. */
1994 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
1997 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1998 type->set_location(yylloc);
2000 type->qualifier = $1;
2001 type->qualifier.flags.q.uniform = true;
2002 type->specifier = $3;
2003 $$ = new(ctx) ast_declarator_list(type);
2004 $$->set_location(yylloc);
2005 $$->ubo_qualifiers_valid = true;
2007 $$->declarations.push_degenerate_list_at_head(& $4->link);
2009 | uniformopt type_specifier struct_declarator_list ';'
2012 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2013 type->set_location(yylloc);
2015 type->qualifier.flags.q.uniform = true;
2016 type->specifier = $2;
2017 $$ = new(ctx) ast_declarator_list(type);
2018 $$->set_location(yylloc);
2019 $$->ubo_qualifiers_valid = true;
2021 $$->declarations.push_degenerate_list_at_head(& $3->link);
2026 layout_qualifier UNIFORM ';'
2028 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,