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;
89 ast_node *then_statement;
90 ast_node *else_statement;
91 } selection_rest_statement;
94 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
95 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
96 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
97 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
98 %token NOPERSPECTIVE FLAT SMOOTH
99 %token MAT2X2 MAT2X3 MAT2X4
100 %token MAT3X2 MAT3X3 MAT3X4
101 %token MAT4X2 MAT4X3 MAT4X4
102 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
103 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
104 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
105 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
106 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
107 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
108 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
109 %token SAMPLEREXTERNALOES
110 %token STRUCT VOID_TOK WHILE
111 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
112 %type <identifier> any_identifier
113 %token <real> FLOATCONSTANT
114 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
115 %token <identifier> FIELD_SELECTION
116 %token LEFT_OP RIGHT_OP
117 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
118 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
119 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
122 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
124 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
125 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
126 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
127 %token PRAGMA_INVARIANT_ALL
130 /* Reserved words that are not actually used in the grammar.
132 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
133 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
134 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
135 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
137 %token SIZEOF CAST NAMESPACE USING
141 %token COMMON PARTITION ACTIVE FILTER
142 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
143 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
144 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
145 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
146 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
149 %type <identifier> variable_identifier
150 %type <node> statement
151 %type <node> statement_list
152 %type <node> simple_statement
153 %type <n> precision_qualifier
154 %type <type_qualifier> type_qualifier
155 %type <type_qualifier> storage_qualifier
156 %type <type_qualifier> interpolation_qualifier
157 %type <type_qualifier> layout_qualifier
158 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
159 %type <type_qualifier> uniform_block_layout_qualifier
160 %type <type_specifier> type_specifier
161 %type <type_specifier> type_specifier_no_prec
162 %type <type_specifier> type_specifier_nonarray
163 %type <identifier> basic_type_specifier_nonarray
164 %type <fully_specified_type> fully_specified_type
165 %type <function> function_prototype
166 %type <function> function_header
167 %type <function> function_header_with_parameters
168 %type <function> function_declarator
169 %type <parameter_declarator> parameter_declarator
170 %type <parameter_declarator> parameter_declaration
171 %type <type_qualifier> parameter_qualifier
172 %type <type_qualifier> parameter_type_qualifier
173 %type <type_specifier> parameter_type_specifier
174 %type <function_definition> function_definition
175 %type <compound_statement> compound_statement_no_new_scope
176 %type <compound_statement> compound_statement
177 %type <node> statement_no_new_scope
178 %type <node> expression_statement
179 %type <expression> expression
180 %type <expression> primary_expression
181 %type <expression> assignment_expression
182 %type <expression> conditional_expression
183 %type <expression> logical_or_expression
184 %type <expression> logical_xor_expression
185 %type <expression> logical_and_expression
186 %type <expression> inclusive_or_expression
187 %type <expression> exclusive_or_expression
188 %type <expression> and_expression
189 %type <expression> equality_expression
190 %type <expression> relational_expression
191 %type <expression> shift_expression
192 %type <expression> additive_expression
193 %type <expression> multiplicative_expression
194 %type <expression> unary_expression
195 %type <expression> constant_expression
196 %type <expression> integer_expression
197 %type <expression> postfix_expression
198 %type <expression> function_call_header_with_parameters
199 %type <expression> function_call_header_no_parameters
200 %type <expression> function_call_header
201 %type <expression> function_call_generic
202 %type <expression> function_call_or_method
203 %type <expression> function_call
204 %type <expression> method_call_generic
205 %type <expression> method_call_header_with_parameters
206 %type <expression> method_call_header_no_parameters
207 %type <expression> method_call_header
208 %type <n> assignment_operator
209 %type <n> unary_operator
210 %type <expression> function_identifier
211 %type <node> external_declaration
212 %type <declarator_list> init_declarator_list
213 %type <declarator_list> single_declaration
214 %type <expression> initializer
215 %type <node> declaration
216 %type <node> declaration_statement
217 %type <node> jump_statement
218 %type <node> uniform_block
219 %type <struct_specifier> struct_specifier
220 %type <declarator_list> struct_declaration_list
221 %type <declarator_list> struct_declaration
222 %type <declaration> struct_declarator
223 %type <declaration> struct_declarator_list
224 %type <declarator_list> member_list
225 %type <declarator_list> member_declaration
226 %type <node> selection_statement
227 %type <selection_rest_statement> selection_rest_statement
228 %type <node> switch_statement
229 %type <switch_body> switch_body
230 %type <case_label_list> case_label_list
231 %type <case_label> case_label
232 %type <case_statement> case_statement
233 %type <case_statement_list> case_statement_list
234 %type <node> iteration_statement
235 %type <node> condition
236 %type <node> conditionopt
237 %type <node> for_init_statement
238 %type <for_rest_statement> for_rest_statement
242 version_statement extension_statement_list
244 _mesa_glsl_initialize_types(state);
246 external_declaration_list
248 delete state->symbols;
249 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
250 _mesa_glsl_initialize_types(state);
255 /* blank - no #version specified: defaults are already set */
256 | VERSION_TOK INTCONSTANT EOL
258 bool supported = false;
262 state->es_shader = true;
263 supported = state->ctx->API == API_OPENGLES2 ||
264 state->ctx->Extensions.ARB_ES2_compatibility;
268 /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
269 * the OpenGL 3.2 Core context is supported, this logic will need
270 * change. Older versions of GLSL are no longer supported
271 * outside the compatibility contexts of 3.x.
280 supported = _mesa_is_desktop_gl(state->ctx) &&
281 ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
288 state->language_version = $2;
289 state->version_string =
290 ralloc_asprintf(state, "GLSL%s %d.%02d",
291 state->es_shader ? " ES" : "",
292 state->language_version / 100,
293 state->language_version % 100);
296 _mesa_glsl_error(& @2, state, "%s is not supported. "
297 "Supported versions are: %s\n",
298 state->version_string,
299 state->supported_version_string);
302 if (state->language_version >= 140) {
303 state->ARB_uniform_buffer_object_enable = true;
310 | PRAGMA_DEBUG_OFF EOL
311 | PRAGMA_OPTIMIZE_ON EOL
312 | PRAGMA_OPTIMIZE_OFF EOL
313 | PRAGMA_INVARIANT_ALL EOL
315 if (state->language_version == 110) {
316 _mesa_glsl_warning(& @1, state,
317 "pragma `invariant(all)' not supported in %s",
318 state->version_string);
320 state->all_invariant = true;
325 extension_statement_list:
327 | extension_statement_list extension_statement
337 EXTENSION any_identifier COLON any_identifier EOL
339 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
345 external_declaration_list:
348 /* FINISHME: The NULL test is required because pragmas are set to
349 * FINISHME: NULL. (See production rule for external_declaration.)
352 state->translation_unit.push_tail(& $1->link);
354 | external_declaration_list external_declaration
356 /* FINISHME: The NULL test is required because pragmas are set to
357 * FINISHME: NULL. (See production rule for external_declaration.)
360 state->translation_unit.push_tail(& $2->link);
373 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
374 $$->set_location(yylloc);
375 $$->primary_expression.identifier = $1;
380 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
381 $$->set_location(yylloc);
382 $$->primary_expression.int_constant = $1;
387 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
388 $$->set_location(yylloc);
389 $$->primary_expression.uint_constant = $1;
394 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
395 $$->set_location(yylloc);
396 $$->primary_expression.float_constant = $1;
401 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
402 $$->set_location(yylloc);
403 $$->primary_expression.bool_constant = $1;
413 | postfix_expression '[' integer_expression ']'
416 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
417 $$->set_location(yylloc);
423 | postfix_expression '.' any_identifier
426 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
427 $$->set_location(yylloc);
428 $$->primary_expression.identifier = $3;
430 | postfix_expression INC_OP
433 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
434 $$->set_location(yylloc);
436 | postfix_expression DEC_OP
439 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
440 $$->set_location(yylloc);
449 function_call_or_method
452 function_call_or_method:
453 function_call_generic
454 | postfix_expression '.' method_call_generic
457 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
458 $$->set_location(yylloc);
462 function_call_generic:
463 function_call_header_with_parameters ')'
464 | function_call_header_no_parameters ')'
467 function_call_header_no_parameters:
468 function_call_header VOID_TOK
469 | function_call_header
472 function_call_header_with_parameters:
473 function_call_header assignment_expression
476 $$->set_location(yylloc);
477 $$->expressions.push_tail(& $2->link);
479 | function_call_header_with_parameters ',' assignment_expression
482 $$->set_location(yylloc);
483 $$->expressions.push_tail(& $3->link);
487 // Grammar Note: Constructors look like functions, but lexical
488 // analysis recognized most of them as keywords. They are now
489 // recognized through "type_specifier".
490 function_call_header:
491 function_identifier '('
498 $$ = new(ctx) ast_function_expression($1);
499 $$->set_location(yylloc);
501 | variable_identifier
504 ast_expression *callee = new(ctx) ast_expression($1);
505 $$ = new(ctx) ast_function_expression(callee);
506 $$->set_location(yylloc);
511 ast_expression *callee = new(ctx) ast_expression($1);
512 $$ = new(ctx) ast_function_expression(callee);
513 $$->set_location(yylloc);
518 method_call_header_with_parameters ')'
519 | method_call_header_no_parameters ')'
522 method_call_header_no_parameters:
523 method_call_header VOID_TOK
527 method_call_header_with_parameters:
528 method_call_header assignment_expression
531 $$->set_location(yylloc);
532 $$->expressions.push_tail(& $2->link);
534 | method_call_header_with_parameters ',' assignment_expression
537 $$->set_location(yylloc);
538 $$->expressions.push_tail(& $3->link);
542 // Grammar Note: Constructors look like methods, but lexical
543 // analysis recognized most of them as keywords. They are now
544 // recognized through "type_specifier".
546 variable_identifier '('
549 ast_expression *callee = new(ctx) ast_expression($1);
550 $$ = new(ctx) ast_function_expression(callee);
551 $$->set_location(yylloc);
555 // Grammar Note: No traditional style type casts.
558 | INC_OP unary_expression
561 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
562 $$->set_location(yylloc);
564 | DEC_OP unary_expression
567 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
568 $$->set_location(yylloc);
570 | unary_operator unary_expression
573 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
574 $$->set_location(yylloc);
578 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
580 '+' { $$ = ast_plus; }
581 | '-' { $$ = ast_neg; }
582 | '!' { $$ = ast_logic_not; }
583 | '~' { $$ = ast_bit_not; }
586 multiplicative_expression:
588 | multiplicative_expression '*' unary_expression
591 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
592 $$->set_location(yylloc);
594 | multiplicative_expression '/' unary_expression
597 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
598 $$->set_location(yylloc);
600 | multiplicative_expression '%' unary_expression
603 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
604 $$->set_location(yylloc);
609 multiplicative_expression
610 | additive_expression '+' multiplicative_expression
613 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
614 $$->set_location(yylloc);
616 | additive_expression '-' multiplicative_expression
619 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
620 $$->set_location(yylloc);
626 | shift_expression LEFT_OP additive_expression
629 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
630 $$->set_location(yylloc);
632 | shift_expression RIGHT_OP additive_expression
635 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
636 $$->set_location(yylloc);
640 relational_expression:
642 | relational_expression '<' shift_expression
645 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
646 $$->set_location(yylloc);
648 | relational_expression '>' shift_expression
651 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
652 $$->set_location(yylloc);
654 | relational_expression LE_OP shift_expression
657 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
658 $$->set_location(yylloc);
660 | relational_expression GE_OP shift_expression
663 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
664 $$->set_location(yylloc);
669 relational_expression
670 | equality_expression EQ_OP relational_expression
673 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
674 $$->set_location(yylloc);
676 | equality_expression NE_OP relational_expression
679 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
680 $$->set_location(yylloc);
686 | and_expression '&' equality_expression
689 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
690 $$->set_location(yylloc);
694 exclusive_or_expression:
696 | exclusive_or_expression '^' and_expression
699 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
700 $$->set_location(yylloc);
704 inclusive_or_expression:
705 exclusive_or_expression
706 | inclusive_or_expression '|' exclusive_or_expression
709 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
710 $$->set_location(yylloc);
714 logical_and_expression:
715 inclusive_or_expression
716 | logical_and_expression AND_OP inclusive_or_expression
719 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
720 $$->set_location(yylloc);
724 logical_xor_expression:
725 logical_and_expression
726 | logical_xor_expression XOR_OP logical_and_expression
729 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
730 $$->set_location(yylloc);
734 logical_or_expression:
735 logical_xor_expression
736 | logical_or_expression OR_OP logical_xor_expression
739 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
740 $$->set_location(yylloc);
744 conditional_expression:
745 logical_or_expression
746 | logical_or_expression '?' expression ':' assignment_expression
749 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
750 $$->set_location(yylloc);
754 assignment_expression:
755 conditional_expression
756 | unary_expression assignment_operator assignment_expression
759 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
760 $$->set_location(yylloc);
765 '=' { $$ = ast_assign; }
766 | MUL_ASSIGN { $$ = ast_mul_assign; }
767 | DIV_ASSIGN { $$ = ast_div_assign; }
768 | MOD_ASSIGN { $$ = ast_mod_assign; }
769 | ADD_ASSIGN { $$ = ast_add_assign; }
770 | SUB_ASSIGN { $$ = ast_sub_assign; }
771 | LEFT_ASSIGN { $$ = ast_ls_assign; }
772 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
773 | AND_ASSIGN { $$ = ast_and_assign; }
774 | XOR_ASSIGN { $$ = ast_xor_assign; }
775 | OR_ASSIGN { $$ = ast_or_assign; }
779 assignment_expression
783 | expression ',' assignment_expression
786 if ($1->oper != ast_sequence) {
787 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
788 $$->set_location(yylloc);
789 $$->expressions.push_tail(& $1->link);
794 $$->expressions.push_tail(& $3->link);
799 conditional_expression
803 function_prototype ';'
805 state->symbols->pop_scope();
808 | init_declarator_list ';'
812 | PRECISION precision_qualifier type_specifier_no_prec ';'
815 $3->is_precision_statement = true;
825 function_declarator ')'
830 | function_header_with_parameters
833 function_header_with_parameters:
834 function_header parameter_declaration
837 $$->parameters.push_tail(& $2->link);
839 | function_header_with_parameters ',' parameter_declaration
842 $$->parameters.push_tail(& $3->link);
847 fully_specified_type variable_identifier '('
850 $$ = new(ctx) ast_function();
851 $$->set_location(yylloc);
852 $$->return_type = $1;
855 state->symbols->add_function(new(state) ir_function($2));
856 state->symbols->push_scope();
860 parameter_declarator:
861 type_specifier any_identifier
864 $$ = new(ctx) ast_parameter_declarator();
865 $$->set_location(yylloc);
866 $$->type = new(ctx) ast_fully_specified_type();
867 $$->type->set_location(yylloc);
868 $$->type->specifier = $1;
871 | type_specifier any_identifier '[' constant_expression ']'
874 $$ = new(ctx) ast_parameter_declarator();
875 $$->set_location(yylloc);
876 $$->type = new(ctx) ast_fully_specified_type();
877 $$->type->set_location(yylloc);
878 $$->type->specifier = $1;
885 parameter_declaration:
886 parameter_type_qualifier parameter_qualifier parameter_declarator
888 $1.flags.i |= $2.flags.i;
891 $$->type->qualifier = $1;
893 | parameter_qualifier parameter_declarator
896 $$->type->qualifier = $1;
898 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
901 $1.flags.i |= $2.flags.i;
903 $$ = new(ctx) ast_parameter_declarator();
904 $$->set_location(yylloc);
905 $$->type = new(ctx) ast_fully_specified_type();
906 $$->type->qualifier = $1;
907 $$->type->specifier = $3;
909 | parameter_qualifier parameter_type_specifier
912 $$ = new(ctx) ast_parameter_declarator();
913 $$->set_location(yylloc);
914 $$->type = new(ctx) ast_fully_specified_type();
915 $$->type->qualifier = $1;
916 $$->type->specifier = $2;
923 memset(& $$, 0, sizeof($$));
927 memset(& $$, 0, sizeof($$));
932 memset(& $$, 0, sizeof($$));
937 memset(& $$, 0, sizeof($$));
943 parameter_type_specifier:
947 init_declarator_list:
949 | init_declarator_list ',' any_identifier
952 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
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 '[' ']'
962 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
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 '[' constant_expression ']'
972 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
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));
979 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
982 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
983 decl->set_location(yylloc);
986 $$->declarations.push_tail(&decl->link);
987 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
989 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
992 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
993 decl->set_location(yylloc);
996 $$->declarations.push_tail(&decl->link);
997 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
999 | init_declarator_list ',' any_identifier '=' initializer
1002 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1003 decl->set_location(yylloc);
1006 $$->declarations.push_tail(&decl->link);
1007 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1011 // Grammar Note: No 'enum', or 'typedef'.
1013 fully_specified_type
1016 /* Empty declaration list is valid. */
1017 $$ = new(ctx) ast_declarator_list($1);
1018 $$->set_location(yylloc);
1020 | fully_specified_type any_identifier
1023 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1025 $$ = new(ctx) ast_declarator_list($1);
1026 $$->set_location(yylloc);
1027 $$->declarations.push_tail(&decl->link);
1029 | fully_specified_type any_identifier '[' ']'
1032 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1034 $$ = new(ctx) ast_declarator_list($1);
1035 $$->set_location(yylloc);
1036 $$->declarations.push_tail(&decl->link);
1038 | fully_specified_type any_identifier '[' constant_expression ']'
1041 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1043 $$ = new(ctx) ast_declarator_list($1);
1044 $$->set_location(yylloc);
1045 $$->declarations.push_tail(&decl->link);
1047 | fully_specified_type any_identifier '[' ']' '=' initializer
1050 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1052 $$ = new(ctx) ast_declarator_list($1);
1053 $$->set_location(yylloc);
1054 $$->declarations.push_tail(&decl->link);
1056 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1059 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1061 $$ = new(ctx) ast_declarator_list($1);
1062 $$->set_location(yylloc);
1063 $$->declarations.push_tail(&decl->link);
1065 | fully_specified_type any_identifier '=' initializer
1068 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1070 $$ = new(ctx) ast_declarator_list($1);
1071 $$->set_location(yylloc);
1072 $$->declarations.push_tail(&decl->link);
1074 | INVARIANT variable_identifier // Vertex only.
1077 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1079 $$ = new(ctx) ast_declarator_list(NULL);
1080 $$->set_location(yylloc);
1081 $$->invariant = true;
1083 $$->declarations.push_tail(&decl->link);
1087 fully_specified_type:
1091 $$ = new(ctx) ast_fully_specified_type();
1092 $$->set_location(yylloc);
1095 | type_qualifier type_specifier
1098 $$ = new(ctx) ast_fully_specified_type();
1099 $$->set_location(yylloc);
1106 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1112 layout_qualifier_id_list:
1114 | layout_qualifier_id_list ',' layout_qualifier_id
1116 if (($1.flags.i & $3.flags.i) != 0) {
1117 _mesa_glsl_error(& @3, state,
1118 "duplicate layout qualifiers used\n");
1123 $$.flags.i |= $3.flags.i;
1125 if ($3.flags.q.explicit_location)
1126 $$.location = $3.location;
1128 if ($3.flags.q.explicit_index)
1129 $$.index = $3.index;
1133 layout_qualifier_id:
1136 memset(& $$, 0, sizeof($$));
1138 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1139 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1140 if (strcmp($1, "origin_upper_left") == 0) {
1141 $$.flags.q.origin_upper_left = 1;
1142 } else if (strcmp($1, "pixel_center_integer") == 0) {
1143 $$.flags.q.pixel_center_integer = 1;
1146 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1147 _mesa_glsl_warning(& @1, state,
1148 "GL_ARB_fragment_coord_conventions layout "
1149 "identifier `%s' used\n", $1);
1153 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1155 (state->AMD_conservative_depth_enable ||
1156 state->ARB_conservative_depth_enable)) {
1157 if (strcmp($1, "depth_any") == 0) {
1158 $$.flags.q.depth_any = 1;
1159 } else if (strcmp($1, "depth_greater") == 0) {
1160 $$.flags.q.depth_greater = 1;
1161 } else if (strcmp($1, "depth_less") == 0) {
1162 $$.flags.q.depth_less = 1;
1163 } else if (strcmp($1, "depth_unchanged") == 0) {
1164 $$.flags.q.depth_unchanged = 1;
1167 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1168 _mesa_glsl_warning(& @1, state,
1169 "GL_AMD_conservative_depth "
1170 "layout qualifier `%s' is used\n", $1);
1172 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1173 _mesa_glsl_warning(& @1, state,
1174 "GL_ARB_conservative_depth "
1175 "layout qualifier `%s' is used\n", $1);
1179 /* See also uniform_block_layout_qualifier. */
1180 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1181 if (strcmp($1, "std140") == 0) {
1182 $$.flags.q.std140 = 1;
1183 } else if (strcmp($1, "shared") == 0) {
1184 $$.flags.q.shared = 1;
1185 } else if (strcmp($1, "column_major") == 0) {
1186 $$.flags.q.column_major = 1;
1189 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1190 _mesa_glsl_warning(& @1, state,
1191 "#version 140 / GL_ARB_uniform_buffer_object "
1192 "layout qualifier `%s' is used\n", $1);
1197 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1202 | any_identifier '=' INTCONSTANT
1204 memset(& $$, 0, sizeof($$));
1206 if (state->ARB_explicit_attrib_location_enable) {
1207 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1208 * FINISHME: GLSL 1.30 (or later) are supported.
1210 if (strcmp("location", $1) == 0) {
1211 $$.flags.q.explicit_location = 1;
1216 _mesa_glsl_error(& @3, state,
1217 "invalid location %d specified\n", $3);
1222 if (strcmp("index", $1) == 0) {
1223 $$.flags.q.explicit_index = 1;
1228 _mesa_glsl_error(& @3, state,
1229 "invalid index %d specified\n", $3);
1235 /* If the identifier didn't match any known layout identifiers,
1239 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1242 } else if (state->ARB_explicit_attrib_location_warn) {
1243 _mesa_glsl_warning(& @1, state,
1244 "GL_ARB_explicit_attrib_location layout "
1245 "identifier `%s' used\n", $1);
1248 | uniform_block_layout_qualifier
1251 /* Layout qualifiers for ARB_uniform_buffer_object. */
1252 if (!state->ARB_uniform_buffer_object_enable) {
1253 _mesa_glsl_error(& @1, state,
1254 "#version 140 / GL_ARB_uniform_buffer_object "
1255 "layout qualifier `%s' is used\n", $1);
1256 } else if (state->ARB_uniform_buffer_object_warn) {
1257 _mesa_glsl_warning(& @1, state,
1258 "#version 140 / GL_ARB_uniform_buffer_object "
1259 "layout qualifier `%s' is used\n", $1);
1264 /* This is a separate language rule because we parse these as tokens
1265 * (due to them being reserved keywords) instead of identifiers like
1266 * most qualifiers. See the any_identifier path of
1267 * layout_qualifier_id for the others.
1269 uniform_block_layout_qualifier:
1272 memset(& $$, 0, sizeof($$));
1273 $$.flags.q.row_major = 1;
1277 memset(& $$, 0, sizeof($$));
1278 $$.flags.q.packed = 1;
1282 interpolation_qualifier:
1285 memset(& $$, 0, sizeof($$));
1286 $$.flags.q.smooth = 1;
1290 memset(& $$, 0, sizeof($$));
1291 $$.flags.q.flat = 1;
1295 memset(& $$, 0, sizeof($$));
1296 $$.flags.q.noperspective = 1;
1300 parameter_type_qualifier:
1303 memset(& $$, 0, sizeof($$));
1304 $$.flags.q.constant = 1;
1311 | layout_qualifier storage_qualifier
1314 $$.flags.i |= $2.flags.i;
1316 | interpolation_qualifier
1317 | interpolation_qualifier storage_qualifier
1320 $$.flags.i |= $2.flags.i;
1322 | INVARIANT storage_qualifier
1325 $$.flags.q.invariant = 1;
1327 | INVARIANT interpolation_qualifier storage_qualifier
1330 $$.flags.i |= $3.flags.i;
1331 $$.flags.q.invariant = 1;
1335 memset(& $$, 0, sizeof($$));
1336 $$.flags.q.invariant = 1;
1343 memset(& $$, 0, sizeof($$));
1344 $$.flags.q.constant = 1;
1348 memset(& $$, 0, sizeof($$));
1349 $$.flags.q.attribute = 1;
1353 memset(& $$, 0, sizeof($$));
1354 $$.flags.q.varying = 1;
1358 memset(& $$, 0, sizeof($$));
1359 $$.flags.q.centroid = 1;
1360 $$.flags.q.varying = 1;
1364 memset(& $$, 0, sizeof($$));
1369 memset(& $$, 0, sizeof($$));
1374 memset(& $$, 0, sizeof($$));
1375 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1379 memset(& $$, 0, sizeof($$));
1380 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1384 memset(& $$, 0, sizeof($$));
1385 $$.flags.q.uniform = 1;
1390 type_specifier_no_prec
1394 | precision_qualifier type_specifier_no_prec
1401 type_specifier_no_prec:
1402 type_specifier_nonarray
1403 | type_specifier_nonarray '[' ']'
1406 $$->is_array = true;
1407 $$->array_size = NULL;
1409 | type_specifier_nonarray '[' constant_expression ']'
1412 $$->is_array = true;
1413 $$->array_size = $3;
1417 type_specifier_nonarray:
1418 basic_type_specifier_nonarray
1421 $$ = new(ctx) ast_type_specifier($1);
1422 $$->set_location(yylloc);
1427 $$ = new(ctx) ast_type_specifier($1);
1428 $$->set_location(yylloc);
1433 $$ = new(ctx) ast_type_specifier($1);
1434 $$->set_location(yylloc);
1438 basic_type_specifier_nonarray:
1439 VOID_TOK { $$ = "void"; }
1440 | FLOAT_TOK { $$ = "float"; }
1441 | INT_TOK { $$ = "int"; }
1442 | UINT_TOK { $$ = "uint"; }
1443 | BOOL_TOK { $$ = "bool"; }
1444 | VEC2 { $$ = "vec2"; }
1445 | VEC3 { $$ = "vec3"; }
1446 | VEC4 { $$ = "vec4"; }
1447 | BVEC2 { $$ = "bvec2"; }
1448 | BVEC3 { $$ = "bvec3"; }
1449 | BVEC4 { $$ = "bvec4"; }
1450 | IVEC2 { $$ = "ivec2"; }
1451 | IVEC3 { $$ = "ivec3"; }
1452 | IVEC4 { $$ = "ivec4"; }
1453 | UVEC2 { $$ = "uvec2"; }
1454 | UVEC3 { $$ = "uvec3"; }
1455 | UVEC4 { $$ = "uvec4"; }
1456 | MAT2X2 { $$ = "mat2"; }
1457 | MAT2X3 { $$ = "mat2x3"; }
1458 | MAT2X4 { $$ = "mat2x4"; }
1459 | MAT3X2 { $$ = "mat3x2"; }
1460 | MAT3X3 { $$ = "mat3"; }
1461 | MAT3X4 { $$ = "mat3x4"; }
1462 | MAT4X2 { $$ = "mat4x2"; }
1463 | MAT4X3 { $$ = "mat4x3"; }
1464 | MAT4X4 { $$ = "mat4"; }
1465 | SAMPLER1D { $$ = "sampler1D"; }
1466 | SAMPLER2D { $$ = "sampler2D"; }
1467 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1468 | SAMPLER3D { $$ = "sampler3D"; }
1469 | SAMPLERCUBE { $$ = "samplerCube"; }
1470 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1471 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1472 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1473 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1474 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1475 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1476 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1477 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1478 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1479 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1480 | ISAMPLER1D { $$ = "isampler1D"; }
1481 | ISAMPLER2D { $$ = "isampler2D"; }
1482 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1483 | ISAMPLER3D { $$ = "isampler3D"; }
1484 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1485 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1486 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1487 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1488 | USAMPLER1D { $$ = "usampler1D"; }
1489 | USAMPLER2D { $$ = "usampler2D"; }
1490 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1491 | USAMPLER3D { $$ = "usampler3D"; }
1492 | USAMPLERCUBE { $$ = "usamplerCube"; }
1493 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1494 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1495 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1498 precision_qualifier:
1500 if (!state->es_shader && state->language_version < 130)
1501 _mesa_glsl_error(& @1, state,
1502 "precision qualifier forbidden "
1503 "in %s (1.30 or later "
1505 state->version_string);
1507 $$ = ast_precision_high;
1510 if (!state->es_shader && state->language_version < 130)
1511 _mesa_glsl_error(& @1, state,
1512 "precision qualifier forbidden "
1513 "in %s (1.30 or later "
1515 state->version_string);
1517 $$ = ast_precision_medium;
1520 if (!state->es_shader && state->language_version < 130)
1521 _mesa_glsl_error(& @1, state,
1522 "precision qualifier forbidden "
1523 "in %s (1.30 or later "
1525 state->version_string);
1527 $$ = ast_precision_low;
1532 STRUCT any_identifier '{' struct_declaration_list '}'
1535 $$ = new(ctx) ast_struct_specifier($2, $4);
1536 $$->set_location(yylloc);
1537 state->symbols->add_type($2, glsl_type::void_type);
1539 | STRUCT '{' struct_declaration_list '}'
1542 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1543 $$->set_location(yylloc);
1547 struct_declaration_list:
1551 $1->link.self_link();
1553 | struct_declaration_list struct_declaration
1556 $$->link.insert_before(& $2->link);
1561 type_specifier struct_declarator_list ';'
1564 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1565 type->set_location(yylloc);
1567 type->specifier = $1;
1568 $$ = new(ctx) ast_declarator_list(type);
1569 $$->set_location(yylloc);
1571 $$->declarations.push_degenerate_list_at_head(& $2->link);
1575 struct_declarator_list:
1579 $1->link.self_link();
1581 | struct_declarator_list ',' struct_declarator
1584 $$->link.insert_before(& $3->link);
1592 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1593 $$->set_location(yylloc);
1594 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1596 | any_identifier '[' constant_expression ']'
1599 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1600 $$->set_location(yylloc);
1605 assignment_expression
1608 declaration_statement:
1612 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1615 compound_statement { $$ = (ast_node *) $1; }
1620 declaration_statement
1621 | expression_statement
1622 | selection_statement
1624 | iteration_statement
1632 $$ = new(ctx) ast_compound_statement(true, NULL);
1633 $$->set_location(yylloc);
1637 state->symbols->push_scope();
1642 $$ = new(ctx) ast_compound_statement(true, $3);
1643 $$->set_location(yylloc);
1644 state->symbols->pop_scope();
1648 statement_no_new_scope:
1649 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1653 compound_statement_no_new_scope:
1657 $$ = new(ctx) ast_compound_statement(false, NULL);
1658 $$->set_location(yylloc);
1660 | '{' statement_list '}'
1663 $$ = new(ctx) ast_compound_statement(false, $2);
1664 $$->set_location(yylloc);
1672 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1677 $$->link.self_link();
1679 | statement_list statement
1682 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1686 $$->link.insert_before(& $2->link);
1690 expression_statement:
1694 $$ = new(ctx) ast_expression_statement(NULL);
1695 $$->set_location(yylloc);
1700 $$ = new(ctx) ast_expression_statement($1);
1701 $$->set_location(yylloc);
1705 selection_statement:
1706 IF '(' expression ')' selection_rest_statement
1708 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1710 $$->set_location(yylloc);
1714 selection_rest_statement:
1715 statement ELSE statement
1717 $$.then_statement = $1;
1718 $$.else_statement = $3;
1722 $$.then_statement = $1;
1723 $$.else_statement = NULL;
1730 $$ = (ast_node *) $1;
1732 | fully_specified_type any_identifier '=' initializer
1735 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1736 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1737 decl->set_location(yylloc);
1738 declarator->set_location(yylloc);
1740 declarator->declarations.push_tail(&decl->link);
1746 * siwtch_statement grammar is based on the syntax described in the body
1747 * of the GLSL spec, not in it's appendix!!!
1750 SWITCH '(' expression ')' switch_body
1752 $$ = new(state) ast_switch_statement($3, $5);
1753 $$->set_location(yylloc);
1760 $$ = new(state) ast_switch_body(NULL);
1761 $$->set_location(yylloc);
1763 | '{' case_statement_list '}'
1765 $$ = new(state) ast_switch_body($2);
1766 $$->set_location(yylloc);
1773 $$ = new(state) ast_case_label($2);
1774 $$->set_location(yylloc);
1778 $$ = new(state) ast_case_label(NULL);
1779 $$->set_location(yylloc);
1786 ast_case_label_list *labels = new(state) ast_case_label_list();
1788 labels->labels.push_tail(& $1->link);
1790 $$->set_location(yylloc);
1792 | case_label_list case_label
1795 $$->labels.push_tail(& $2->link);
1800 case_label_list statement
1802 ast_case_statement *stmts = new(state) ast_case_statement($1);
1803 stmts->set_location(yylloc);
1805 stmts->stmts.push_tail(& $2->link);
1808 | case_statement statement
1811 $$->stmts.push_tail(& $2->link);
1815 case_statement_list:
1818 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1819 cases->set_location(yylloc);
1821 cases->cases.push_tail(& $1->link);
1824 | case_statement_list case_statement
1827 $$->cases.push_tail(& $2->link);
1831 iteration_statement:
1832 WHILE '(' condition ')' statement_no_new_scope
1835 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1836 NULL, $3, NULL, $5);
1837 $$->set_location(yylloc);
1839 | DO statement WHILE '(' expression ')' ';'
1842 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1843 NULL, $5, NULL, $2);
1844 $$->set_location(yylloc);
1846 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1849 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1850 $3, $4.cond, $4.rest, $6);
1851 $$->set_location(yylloc);
1856 expression_statement
1857 | declaration_statement
1874 | conditionopt ';' expression
1881 // Grammar Note: No 'goto'. Gotos are not supported.
1886 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1887 $$->set_location(yylloc);
1892 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1893 $$->set_location(yylloc);
1898 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1899 $$->set_location(yylloc);
1901 | RETURN expression ';'
1904 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1905 $$->set_location(yylloc);
1907 | DISCARD ';' // Fragment shader only.
1910 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1911 $$->set_location(yylloc);
1915 external_declaration:
1916 function_definition { $$ = $1; }
1917 | declaration { $$ = $1; }
1918 | pragma_statement { $$ = NULL; }
1921 function_definition:
1922 function_prototype compound_statement_no_new_scope
1925 $$ = new(ctx) ast_function_definition();
1926 $$->set_location(yylloc);
1930 state->symbols->pop_scope();
1934 /* layout_qualifieropt is packed into this rule */
1936 UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1939 ast_type_qualifier no_qual;
1940 memset(&no_qual, 0, sizeof(no_qual));
1941 $$ = new(ctx) ast_uniform_block(no_qual, $2, $4);
1943 | layout_qualifier UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1946 $$ = new(ctx) ast_uniform_block($1, $3, $5);
1954 $1->link.self_link();
1956 | member_declaration member_list
1959 $2->link.insert_before(& $$->link);
1963 /* Specifying "uniform" inside of a uniform block is redundant. */
1970 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
1973 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1974 type->set_location(yylloc);
1976 type->qualifier = $1;
1977 type->qualifier.flags.q.uniform = true;
1978 type->specifier = $3;
1979 $$ = new(ctx) ast_declarator_list(type);
1980 $$->set_location(yylloc);
1981 $$->ubo_qualifiers_valid = true;
1983 $$->declarations.push_degenerate_list_at_head(& $4->link);
1985 | uniformopt type_specifier struct_declarator_list ';'
1988 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1989 type->set_location(yylloc);
1991 type->qualifier.flags.q.uniform = true;
1992 type->specifier = $2;
1993 $$ = new(ctx) ast_declarator_list(type);
1994 $$->set_location(yylloc);
1995 $$->ubo_qualifiers_valid = true;
1997 $$->declarations.push_degenerate_list_at_head(& $3->link);