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 SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
105 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
106 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
107 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
108 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
109 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
110 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
111 %token SAMPLEREXTERNALOES
112 %token STRUCT VOID_TOK WHILE
113 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
114 %type <identifier> any_identifier
115 %token <real> FLOATCONSTANT
116 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
117 %token <identifier> FIELD_SELECTION
118 %token LEFT_OP RIGHT_OP
119 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
120 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
121 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
124 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
126 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
127 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
128 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
129 %token PRAGMA_INVARIANT_ALL
132 /* Reserved words that are not actually used in the grammar.
134 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
135 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
136 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
137 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
139 %token SIZEOF CAST NAMESPACE USING
140 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
141 %token SUBROUTINE SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS SAMPLER2DMSARRAY
142 %token ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
146 %token COMMON PARTITION ACTIVE FILTER
147 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
148 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
149 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
150 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
151 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
154 %type <identifier> variable_identifier
155 %type <node> statement
156 %type <node> statement_list
157 %type <node> simple_statement
158 %type <n> precision_qualifier
159 %type <type_qualifier> type_qualifier
160 %type <type_qualifier> storage_qualifier
161 %type <type_qualifier> interpolation_qualifier
162 %type <type_qualifier> layout_qualifier
163 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
164 %type <type_qualifier> uniform_block_layout_qualifier
165 %type <type_specifier> type_specifier
166 %type <type_specifier> type_specifier_no_prec
167 %type <type_specifier> type_specifier_nonarray
168 %type <identifier> basic_type_specifier_nonarray
169 %type <fully_specified_type> fully_specified_type
170 %type <function> function_prototype
171 %type <function> function_header
172 %type <function> function_header_with_parameters
173 %type <function> function_declarator
174 %type <parameter_declarator> parameter_declarator
175 %type <parameter_declarator> parameter_declaration
176 %type <type_qualifier> parameter_qualifier
177 %type <type_qualifier> parameter_type_qualifier
178 %type <type_specifier> parameter_type_specifier
179 %type <function_definition> function_definition
180 %type <compound_statement> compound_statement_no_new_scope
181 %type <compound_statement> compound_statement
182 %type <node> statement_no_new_scope
183 %type <node> expression_statement
184 %type <expression> expression
185 %type <expression> primary_expression
186 %type <expression> assignment_expression
187 %type <expression> conditional_expression
188 %type <expression> logical_or_expression
189 %type <expression> logical_xor_expression
190 %type <expression> logical_and_expression
191 %type <expression> inclusive_or_expression
192 %type <expression> exclusive_or_expression
193 %type <expression> and_expression
194 %type <expression> equality_expression
195 %type <expression> relational_expression
196 %type <expression> shift_expression
197 %type <expression> additive_expression
198 %type <expression> multiplicative_expression
199 %type <expression> unary_expression
200 %type <expression> constant_expression
201 %type <expression> integer_expression
202 %type <expression> postfix_expression
203 %type <expression> function_call_header_with_parameters
204 %type <expression> function_call_header_no_parameters
205 %type <expression> function_call_header
206 %type <expression> function_call_generic
207 %type <expression> function_call_or_method
208 %type <expression> function_call
209 %type <expression> method_call_generic
210 %type <expression> method_call_header_with_parameters
211 %type <expression> method_call_header_no_parameters
212 %type <expression> method_call_header
213 %type <n> assignment_operator
214 %type <n> unary_operator
215 %type <expression> function_identifier
216 %type <node> external_declaration
217 %type <declarator_list> init_declarator_list
218 %type <declarator_list> single_declaration
219 %type <expression> initializer
220 %type <node> declaration
221 %type <node> declaration_statement
222 %type <node> jump_statement
223 %type <node> uniform_block
224 %type <struct_specifier> struct_specifier
225 %type <declarator_list> struct_declaration_list
226 %type <declarator_list> struct_declaration
227 %type <declaration> struct_declarator
228 %type <declaration> struct_declarator_list
229 %type <declarator_list> member_list
230 %type <declarator_list> member_declaration
231 %type <node> selection_statement
232 %type <selection_rest_statement> selection_rest_statement
233 %type <node> switch_statement
234 %type <switch_body> switch_body
235 %type <case_label_list> case_label_list
236 %type <case_label> case_label
237 %type <case_statement> case_statement
238 %type <case_statement_list> case_statement_list
239 %type <node> iteration_statement
240 %type <node> condition
241 %type <node> conditionopt
242 %type <node> for_init_statement
243 %type <for_rest_statement> for_rest_statement
244 %type <n> integer_constant
248 version_statement extension_statement_list
250 _mesa_glsl_initialize_types(state);
252 external_declaration_list
254 delete state->symbols;
255 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
256 _mesa_glsl_initialize_types(state);
261 /* blank - no #version specified: defaults are already set */
262 | VERSION_TOK INTCONSTANT EOL
264 bool supported = false;
268 state->es_shader = true;
269 supported = state->ctx->API == API_OPENGLES2 ||
270 state->ctx->Extensions.ARB_ES2_compatibility;
274 /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
275 * the OpenGL 3.2 Core context is supported, this logic will need
276 * change. Older versions of GLSL are no longer supported
277 * outside the compatibility contexts of 3.x.
286 supported = _mesa_is_desktop_gl(state->ctx) &&
287 ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
294 state->language_version = $2;
297 _mesa_glsl_error(& @2, state, "%s is not supported. "
298 "Supported versions are: %s\n",
299 state->get_version_string(),
300 state->supported_version_string);
303 if (state->language_version >= 140) {
304 state->ARB_uniform_buffer_object_enable = true;
311 | PRAGMA_DEBUG_OFF EOL
312 | PRAGMA_OPTIMIZE_ON EOL
313 | PRAGMA_OPTIMIZE_OFF EOL
314 | PRAGMA_INVARIANT_ALL EOL
316 if (!state->is_version(120, 100)) {
317 _mesa_glsl_warning(& @1, state,
318 "pragma `invariant(all)' not supported in %s "
319 "(GLSL ES 1.00 or GLSL 1.20 required).",
320 state->get_version_string());
322 state->all_invariant = true;
327 extension_statement_list:
329 | extension_statement_list extension_statement
339 EXTENSION any_identifier COLON any_identifier EOL
341 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
347 external_declaration_list:
350 /* FINISHME: The NULL test is required because pragmas are set to
351 * FINISHME: NULL. (See production rule for external_declaration.)
354 state->translation_unit.push_tail(& $1->link);
356 | external_declaration_list external_declaration
358 /* FINISHME: The NULL test is required because pragmas are set to
359 * FINISHME: NULL. (See production rule for external_declaration.)
362 state->translation_unit.push_tail(& $2->link);
375 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
376 $$->set_location(yylloc);
377 $$->primary_expression.identifier = $1;
382 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
383 $$->set_location(yylloc);
384 $$->primary_expression.int_constant = $1;
389 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
390 $$->set_location(yylloc);
391 $$->primary_expression.uint_constant = $1;
396 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
397 $$->set_location(yylloc);
398 $$->primary_expression.float_constant = $1;
403 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
404 $$->set_location(yylloc);
405 $$->primary_expression.bool_constant = $1;
415 | postfix_expression '[' integer_expression ']'
418 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
419 $$->set_location(yylloc);
425 | postfix_expression '.' any_identifier
428 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
429 $$->set_location(yylloc);
430 $$->primary_expression.identifier = $3;
432 | postfix_expression INC_OP
435 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
436 $$->set_location(yylloc);
438 | postfix_expression DEC_OP
441 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
442 $$->set_location(yylloc);
451 function_call_or_method
454 function_call_or_method:
455 function_call_generic
456 | postfix_expression '.' method_call_generic
459 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
460 $$->set_location(yylloc);
464 function_call_generic:
465 function_call_header_with_parameters ')'
466 | function_call_header_no_parameters ')'
469 function_call_header_no_parameters:
470 function_call_header VOID_TOK
471 | function_call_header
474 function_call_header_with_parameters:
475 function_call_header assignment_expression
478 $$->set_location(yylloc);
479 $$->expressions.push_tail(& $2->link);
481 | function_call_header_with_parameters ',' assignment_expression
484 $$->set_location(yylloc);
485 $$->expressions.push_tail(& $3->link);
489 // Grammar Note: Constructors look like functions, but lexical
490 // analysis recognized most of them as keywords. They are now
491 // recognized through "type_specifier".
492 function_call_header:
493 function_identifier '('
500 $$ = new(ctx) ast_function_expression($1);
501 $$->set_location(yylloc);
503 | variable_identifier
506 ast_expression *callee = new(ctx) ast_expression($1);
507 $$ = new(ctx) ast_function_expression(callee);
508 $$->set_location(yylloc);
513 ast_expression *callee = new(ctx) ast_expression($1);
514 $$ = new(ctx) ast_function_expression(callee);
515 $$->set_location(yylloc);
520 method_call_header_with_parameters ')'
521 | method_call_header_no_parameters ')'
524 method_call_header_no_parameters:
525 method_call_header VOID_TOK
529 method_call_header_with_parameters:
530 method_call_header assignment_expression
533 $$->set_location(yylloc);
534 $$->expressions.push_tail(& $2->link);
536 | method_call_header_with_parameters ',' assignment_expression
539 $$->set_location(yylloc);
540 $$->expressions.push_tail(& $3->link);
544 // Grammar Note: Constructors look like methods, but lexical
545 // analysis recognized most of them as keywords. They are now
546 // recognized through "type_specifier".
548 variable_identifier '('
551 ast_expression *callee = new(ctx) ast_expression($1);
552 $$ = new(ctx) ast_function_expression(callee);
553 $$->set_location(yylloc);
557 // Grammar Note: No traditional style type casts.
560 | INC_OP unary_expression
563 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
564 $$->set_location(yylloc);
566 | DEC_OP unary_expression
569 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
570 $$->set_location(yylloc);
572 | unary_operator unary_expression
575 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
576 $$->set_location(yylloc);
580 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
582 '+' { $$ = ast_plus; }
583 | '-' { $$ = ast_neg; }
584 | '!' { $$ = ast_logic_not; }
585 | '~' { $$ = ast_bit_not; }
588 multiplicative_expression:
590 | multiplicative_expression '*' unary_expression
593 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
594 $$->set_location(yylloc);
596 | multiplicative_expression '/' unary_expression
599 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
600 $$->set_location(yylloc);
602 | multiplicative_expression '%' unary_expression
605 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
606 $$->set_location(yylloc);
611 multiplicative_expression
612 | additive_expression '+' multiplicative_expression
615 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
616 $$->set_location(yylloc);
618 | additive_expression '-' multiplicative_expression
621 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
622 $$->set_location(yylloc);
628 | shift_expression LEFT_OP additive_expression
631 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
632 $$->set_location(yylloc);
634 | shift_expression RIGHT_OP additive_expression
637 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
638 $$->set_location(yylloc);
642 relational_expression:
644 | relational_expression '<' shift_expression
647 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
648 $$->set_location(yylloc);
650 | relational_expression '>' shift_expression
653 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
654 $$->set_location(yylloc);
656 | relational_expression LE_OP shift_expression
659 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
660 $$->set_location(yylloc);
662 | relational_expression GE_OP shift_expression
665 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
666 $$->set_location(yylloc);
671 relational_expression
672 | equality_expression EQ_OP relational_expression
675 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
676 $$->set_location(yylloc);
678 | equality_expression NE_OP relational_expression
681 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
682 $$->set_location(yylloc);
688 | and_expression '&' equality_expression
691 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
692 $$->set_location(yylloc);
696 exclusive_or_expression:
698 | exclusive_or_expression '^' and_expression
701 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
702 $$->set_location(yylloc);
706 inclusive_or_expression:
707 exclusive_or_expression
708 | inclusive_or_expression '|' exclusive_or_expression
711 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
712 $$->set_location(yylloc);
716 logical_and_expression:
717 inclusive_or_expression
718 | logical_and_expression AND_OP inclusive_or_expression
721 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
722 $$->set_location(yylloc);
726 logical_xor_expression:
727 logical_and_expression
728 | logical_xor_expression XOR_OP logical_and_expression
731 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
732 $$->set_location(yylloc);
736 logical_or_expression:
737 logical_xor_expression
738 | logical_or_expression OR_OP logical_xor_expression
741 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
742 $$->set_location(yylloc);
746 conditional_expression:
747 logical_or_expression
748 | logical_or_expression '?' expression ':' assignment_expression
751 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
752 $$->set_location(yylloc);
756 assignment_expression:
757 conditional_expression
758 | unary_expression assignment_operator assignment_expression
761 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
762 $$->set_location(yylloc);
767 '=' { $$ = ast_assign; }
768 | MUL_ASSIGN { $$ = ast_mul_assign; }
769 | DIV_ASSIGN { $$ = ast_div_assign; }
770 | MOD_ASSIGN { $$ = ast_mod_assign; }
771 | ADD_ASSIGN { $$ = ast_add_assign; }
772 | SUB_ASSIGN { $$ = ast_sub_assign; }
773 | LEFT_ASSIGN { $$ = ast_ls_assign; }
774 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
775 | AND_ASSIGN { $$ = ast_and_assign; }
776 | XOR_ASSIGN { $$ = ast_xor_assign; }
777 | OR_ASSIGN { $$ = ast_or_assign; }
781 assignment_expression
785 | expression ',' assignment_expression
788 if ($1->oper != ast_sequence) {
789 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
790 $$->set_location(yylloc);
791 $$->expressions.push_tail(& $1->link);
796 $$->expressions.push_tail(& $3->link);
801 conditional_expression
805 function_prototype ';'
807 state->symbols->pop_scope();
810 | init_declarator_list ';'
814 | PRECISION precision_qualifier type_specifier_no_prec ';'
817 $3->is_precision_statement = true;
827 function_declarator ')'
832 | function_header_with_parameters
835 function_header_with_parameters:
836 function_header parameter_declaration
839 $$->parameters.push_tail(& $2->link);
841 | function_header_with_parameters ',' parameter_declaration
844 $$->parameters.push_tail(& $3->link);
849 fully_specified_type variable_identifier '('
852 $$ = new(ctx) ast_function();
853 $$->set_location(yylloc);
854 $$->return_type = $1;
857 state->symbols->add_function(new(state) ir_function($2));
858 state->symbols->push_scope();
862 parameter_declarator:
863 type_specifier any_identifier
866 $$ = new(ctx) ast_parameter_declarator();
867 $$->set_location(yylloc);
868 $$->type = new(ctx) ast_fully_specified_type();
869 $$->type->set_location(yylloc);
870 $$->type->specifier = $1;
873 | type_specifier any_identifier '[' constant_expression ']'
876 $$ = new(ctx) ast_parameter_declarator();
877 $$->set_location(yylloc);
878 $$->type = new(ctx) ast_fully_specified_type();
879 $$->type->set_location(yylloc);
880 $$->type->specifier = $1;
887 parameter_declaration:
888 parameter_type_qualifier parameter_qualifier parameter_declarator
890 $1.flags.i |= $2.flags.i;
893 $$->type->qualifier = $1;
895 | parameter_qualifier parameter_declarator
898 $$->type->qualifier = $1;
900 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
903 $1.flags.i |= $2.flags.i;
905 $$ = new(ctx) ast_parameter_declarator();
906 $$->set_location(yylloc);
907 $$->type = new(ctx) ast_fully_specified_type();
908 $$->type->qualifier = $1;
909 $$->type->specifier = $3;
911 | parameter_qualifier parameter_type_specifier
914 $$ = new(ctx) ast_parameter_declarator();
915 $$->set_location(yylloc);
916 $$->type = new(ctx) ast_fully_specified_type();
917 $$->type->qualifier = $1;
918 $$->type->specifier = $2;
925 memset(& $$, 0, sizeof($$));
929 memset(& $$, 0, sizeof($$));
934 memset(& $$, 0, sizeof($$));
939 memset(& $$, 0, sizeof($$));
945 parameter_type_specifier:
949 init_declarator_list:
951 | init_declarator_list ',' any_identifier
954 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
955 decl->set_location(yylloc);
958 $$->declarations.push_tail(&decl->link);
959 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
961 | init_declarator_list ',' any_identifier '[' ']'
964 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
965 decl->set_location(yylloc);
968 $$->declarations.push_tail(&decl->link);
969 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
971 | init_declarator_list ',' any_identifier '[' constant_expression ']'
974 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
975 decl->set_location(yylloc);
978 $$->declarations.push_tail(&decl->link);
979 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
981 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
984 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
985 decl->set_location(yylloc);
988 $$->declarations.push_tail(&decl->link);
989 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
991 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
994 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
995 decl->set_location(yylloc);
998 $$->declarations.push_tail(&decl->link);
999 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1001 | init_declarator_list ',' any_identifier '=' initializer
1004 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1005 decl->set_location(yylloc);
1008 $$->declarations.push_tail(&decl->link);
1009 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1013 // Grammar Note: No 'enum', or 'typedef'.
1015 fully_specified_type
1018 /* Empty declaration list is valid. */
1019 $$ = new(ctx) ast_declarator_list($1);
1020 $$->set_location(yylloc);
1022 | fully_specified_type any_identifier
1025 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1027 $$ = new(ctx) ast_declarator_list($1);
1028 $$->set_location(yylloc);
1029 $$->declarations.push_tail(&decl->link);
1031 | fully_specified_type any_identifier '[' ']'
1034 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1036 $$ = new(ctx) ast_declarator_list($1);
1037 $$->set_location(yylloc);
1038 $$->declarations.push_tail(&decl->link);
1040 | fully_specified_type any_identifier '[' constant_expression ']'
1043 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1045 $$ = new(ctx) ast_declarator_list($1);
1046 $$->set_location(yylloc);
1047 $$->declarations.push_tail(&decl->link);
1049 | fully_specified_type any_identifier '[' ']' '=' initializer
1052 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1054 $$ = new(ctx) ast_declarator_list($1);
1055 $$->set_location(yylloc);
1056 $$->declarations.push_tail(&decl->link);
1058 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1061 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1063 $$ = new(ctx) ast_declarator_list($1);
1064 $$->set_location(yylloc);
1065 $$->declarations.push_tail(&decl->link);
1067 | fully_specified_type any_identifier '=' initializer
1070 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1072 $$ = new(ctx) ast_declarator_list($1);
1073 $$->set_location(yylloc);
1074 $$->declarations.push_tail(&decl->link);
1076 | INVARIANT variable_identifier // Vertex only.
1079 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1081 $$ = new(ctx) ast_declarator_list(NULL);
1082 $$->set_location(yylloc);
1083 $$->invariant = true;
1085 $$->declarations.push_tail(&decl->link);
1089 fully_specified_type:
1093 $$ = new(ctx) ast_fully_specified_type();
1094 $$->set_location(yylloc);
1097 | type_qualifier type_specifier
1100 $$ = new(ctx) ast_fully_specified_type();
1101 $$->set_location(yylloc);
1108 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1114 layout_qualifier_id_list:
1116 | layout_qualifier_id_list ',' layout_qualifier_id
1119 if (!$$.merge_qualifier(& @3, state, $3)) {
1126 INTCONSTANT { $$ = $1; }
1127 | UINTCONSTANT { $$ = $1; }
1129 layout_qualifier_id:
1132 memset(& $$, 0, sizeof($$));
1134 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1135 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1136 if (strcmp($1, "origin_upper_left") == 0) {
1137 $$.flags.q.origin_upper_left = 1;
1138 } else if (strcmp($1, "pixel_center_integer") == 0) {
1139 $$.flags.q.pixel_center_integer = 1;
1142 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1143 _mesa_glsl_warning(& @1, state,
1144 "GL_ARB_fragment_coord_conventions layout "
1145 "identifier `%s' used\n", $1);
1149 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1151 (state->AMD_conservative_depth_enable ||
1152 state->ARB_conservative_depth_enable)) {
1153 if (strcmp($1, "depth_any") == 0) {
1154 $$.flags.q.depth_any = 1;
1155 } else if (strcmp($1, "depth_greater") == 0) {
1156 $$.flags.q.depth_greater = 1;
1157 } else if (strcmp($1, "depth_less") == 0) {
1158 $$.flags.q.depth_less = 1;
1159 } else if (strcmp($1, "depth_unchanged") == 0) {
1160 $$.flags.q.depth_unchanged = 1;
1163 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1164 _mesa_glsl_warning(& @1, state,
1165 "GL_AMD_conservative_depth "
1166 "layout qualifier `%s' is used\n", $1);
1168 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1169 _mesa_glsl_warning(& @1, state,
1170 "GL_ARB_conservative_depth "
1171 "layout qualifier `%s' is used\n", $1);
1175 /* See also uniform_block_layout_qualifier. */
1176 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1177 if (strcmp($1, "std140") == 0) {
1178 $$.flags.q.std140 = 1;
1179 } else if (strcmp($1, "shared") == 0) {
1180 $$.flags.q.shared = 1;
1181 } else if (strcmp($1, "column_major") == 0) {
1182 $$.flags.q.column_major = 1;
1185 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1186 _mesa_glsl_warning(& @1, state,
1187 "#version 140 / GL_ARB_uniform_buffer_object "
1188 "layout qualifier `%s' is used\n", $1);
1193 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1198 | any_identifier '=' integer_constant
1200 memset(& $$, 0, sizeof($$));
1202 if (state->ARB_explicit_attrib_location_enable) {
1203 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1204 * FINISHME: GLSL 1.30 (or later) are supported.
1206 if (strcmp("location", $1) == 0) {
1207 $$.flags.q.explicit_location = 1;
1212 _mesa_glsl_error(& @3, state,
1213 "invalid location %d specified\n", $3);
1218 if (strcmp("index", $1) == 0) {
1219 $$.flags.q.explicit_index = 1;
1224 _mesa_glsl_error(& @3, state,
1225 "invalid index %d specified\n", $3);
1231 /* If the identifier didn't match any known layout identifiers,
1235 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1238 } else if (state->ARB_explicit_attrib_location_warn) {
1239 _mesa_glsl_warning(& @1, state,
1240 "GL_ARB_explicit_attrib_location layout "
1241 "identifier `%s' used\n", $1);
1244 | uniform_block_layout_qualifier
1247 /* Layout qualifiers for ARB_uniform_buffer_object. */
1248 if (!state->ARB_uniform_buffer_object_enable) {
1249 _mesa_glsl_error(& @1, state,
1250 "#version 140 / GL_ARB_uniform_buffer_object "
1251 "layout qualifier `%s' is used\n", $1);
1252 } else if (state->ARB_uniform_buffer_object_warn) {
1253 _mesa_glsl_warning(& @1, state,
1254 "#version 140 / GL_ARB_uniform_buffer_object "
1255 "layout qualifier `%s' is used\n", $1);
1260 /* This is a separate language rule because we parse these as tokens
1261 * (due to them being reserved keywords) instead of identifiers like
1262 * most qualifiers. See the any_identifier path of
1263 * layout_qualifier_id for the others.
1265 uniform_block_layout_qualifier:
1268 memset(& $$, 0, sizeof($$));
1269 $$.flags.q.row_major = 1;
1273 memset(& $$, 0, sizeof($$));
1274 $$.flags.q.packed = 1;
1278 interpolation_qualifier:
1281 memset(& $$, 0, sizeof($$));
1282 $$.flags.q.smooth = 1;
1286 memset(& $$, 0, sizeof($$));
1287 $$.flags.q.flat = 1;
1291 memset(& $$, 0, sizeof($$));
1292 $$.flags.q.noperspective = 1;
1296 parameter_type_qualifier:
1299 memset(& $$, 0, sizeof($$));
1300 $$.flags.q.constant = 1;
1307 | layout_qualifier storage_qualifier
1310 $$.flags.i |= $2.flags.i;
1312 | interpolation_qualifier
1313 | interpolation_qualifier storage_qualifier
1316 $$.flags.i |= $2.flags.i;
1318 | INVARIANT storage_qualifier
1321 $$.flags.q.invariant = 1;
1323 | INVARIANT interpolation_qualifier storage_qualifier
1326 $$.flags.i |= $3.flags.i;
1327 $$.flags.q.invariant = 1;
1331 memset(& $$, 0, sizeof($$));
1332 $$.flags.q.invariant = 1;
1339 memset(& $$, 0, sizeof($$));
1340 $$.flags.q.constant = 1;
1344 memset(& $$, 0, sizeof($$));
1345 $$.flags.q.attribute = 1;
1349 memset(& $$, 0, sizeof($$));
1350 $$.flags.q.varying = 1;
1354 memset(& $$, 0, sizeof($$));
1355 $$.flags.q.centroid = 1;
1356 $$.flags.q.varying = 1;
1360 memset(& $$, 0, sizeof($$));
1365 memset(& $$, 0, sizeof($$));
1370 memset(& $$, 0, sizeof($$));
1371 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1375 memset(& $$, 0, sizeof($$));
1376 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1380 memset(& $$, 0, sizeof($$));
1381 $$.flags.q.uniform = 1;
1386 type_specifier_no_prec
1390 | precision_qualifier type_specifier_no_prec
1397 type_specifier_no_prec:
1398 type_specifier_nonarray
1399 | type_specifier_nonarray '[' ']'
1402 $$->is_array = true;
1403 $$->array_size = NULL;
1405 | type_specifier_nonarray '[' constant_expression ']'
1408 $$->is_array = true;
1409 $$->array_size = $3;
1413 type_specifier_nonarray:
1414 basic_type_specifier_nonarray
1417 $$ = new(ctx) ast_type_specifier($1);
1418 $$->set_location(yylloc);
1423 $$ = new(ctx) ast_type_specifier($1);
1424 $$->set_location(yylloc);
1429 $$ = new(ctx) ast_type_specifier($1);
1430 $$->set_location(yylloc);
1434 basic_type_specifier_nonarray:
1435 VOID_TOK { $$ = "void"; }
1436 | FLOAT_TOK { $$ = "float"; }
1437 | INT_TOK { $$ = "int"; }
1438 | UINT_TOK { $$ = "uint"; }
1439 | BOOL_TOK { $$ = "bool"; }
1440 | VEC2 { $$ = "vec2"; }
1441 | VEC3 { $$ = "vec3"; }
1442 | VEC4 { $$ = "vec4"; }
1443 | BVEC2 { $$ = "bvec2"; }
1444 | BVEC3 { $$ = "bvec3"; }
1445 | BVEC4 { $$ = "bvec4"; }
1446 | IVEC2 { $$ = "ivec2"; }
1447 | IVEC3 { $$ = "ivec3"; }
1448 | IVEC4 { $$ = "ivec4"; }
1449 | UVEC2 { $$ = "uvec2"; }
1450 | UVEC3 { $$ = "uvec3"; }
1451 | UVEC4 { $$ = "uvec4"; }
1452 | MAT2X2 { $$ = "mat2"; }
1453 | MAT2X3 { $$ = "mat2x3"; }
1454 | MAT2X4 { $$ = "mat2x4"; }
1455 | MAT3X2 { $$ = "mat3x2"; }
1456 | MAT3X3 { $$ = "mat3"; }
1457 | MAT3X4 { $$ = "mat3x4"; }
1458 | MAT4X2 { $$ = "mat4x2"; }
1459 | MAT4X3 { $$ = "mat4x3"; }
1460 | MAT4X4 { $$ = "mat4"; }
1461 | SAMPLER1D { $$ = "sampler1D"; }
1462 | SAMPLER2D { $$ = "sampler2D"; }
1463 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1464 | SAMPLER3D { $$ = "sampler3D"; }
1465 | SAMPLERCUBE { $$ = "samplerCube"; }
1466 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1467 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1468 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1469 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1470 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1471 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1472 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1473 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1474 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1475 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1476 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1477 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1478 | ISAMPLER1D { $$ = "isampler1D"; }
1479 | ISAMPLER2D { $$ = "isampler2D"; }
1480 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1481 | ISAMPLER3D { $$ = "isampler3D"; }
1482 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1483 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1484 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1485 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1486 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1487 | USAMPLER1D { $$ = "usampler1D"; }
1488 | USAMPLER2D { $$ = "usampler2D"; }
1489 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1490 | USAMPLER3D { $$ = "usampler3D"; }
1491 | USAMPLERCUBE { $$ = "usamplerCube"; }
1492 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1493 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1494 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1495 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1498 precision_qualifier:
1500 state->check_precision_qualifiers_allowed(&@1);
1502 $$ = ast_precision_high;
1505 state->check_precision_qualifiers_allowed(&@1);
1507 $$ = ast_precision_medium;
1510 state->check_precision_qualifiers_allowed(&@1);
1512 $$ = ast_precision_low;
1517 STRUCT any_identifier '{' struct_declaration_list '}'
1520 $$ = new(ctx) ast_struct_specifier($2, $4);
1521 $$->set_location(yylloc);
1522 state->symbols->add_type($2, glsl_type::void_type);
1524 | STRUCT '{' struct_declaration_list '}'
1527 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1528 $$->set_location(yylloc);
1532 struct_declaration_list:
1536 $1->link.self_link();
1538 | struct_declaration_list struct_declaration
1541 $$->link.insert_before(& $2->link);
1546 type_specifier struct_declarator_list ';'
1549 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1550 type->set_location(yylloc);
1552 type->specifier = $1;
1553 $$ = new(ctx) ast_declarator_list(type);
1554 $$->set_location(yylloc);
1556 $$->declarations.push_degenerate_list_at_head(& $2->link);
1560 struct_declarator_list:
1564 $1->link.self_link();
1566 | struct_declarator_list ',' struct_declarator
1569 $$->link.insert_before(& $3->link);
1577 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1578 $$->set_location(yylloc);
1579 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1581 | any_identifier '[' constant_expression ']'
1584 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1585 $$->set_location(yylloc);
1590 assignment_expression
1593 declaration_statement:
1597 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1600 compound_statement { $$ = (ast_node *) $1; }
1605 declaration_statement
1606 | expression_statement
1607 | selection_statement
1609 | iteration_statement
1617 $$ = new(ctx) ast_compound_statement(true, NULL);
1618 $$->set_location(yylloc);
1622 state->symbols->push_scope();
1627 $$ = new(ctx) ast_compound_statement(true, $3);
1628 $$->set_location(yylloc);
1629 state->symbols->pop_scope();
1633 statement_no_new_scope:
1634 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1638 compound_statement_no_new_scope:
1642 $$ = new(ctx) ast_compound_statement(false, NULL);
1643 $$->set_location(yylloc);
1645 | '{' statement_list '}'
1648 $$ = new(ctx) ast_compound_statement(false, $2);
1649 $$->set_location(yylloc);
1657 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1662 $$->link.self_link();
1664 | statement_list statement
1667 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1671 $$->link.insert_before(& $2->link);
1675 expression_statement:
1679 $$ = new(ctx) ast_expression_statement(NULL);
1680 $$->set_location(yylloc);
1685 $$ = new(ctx) ast_expression_statement($1);
1686 $$->set_location(yylloc);
1690 selection_statement:
1691 IF '(' expression ')' selection_rest_statement
1693 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1695 $$->set_location(yylloc);
1699 selection_rest_statement:
1700 statement ELSE statement
1702 $$.then_statement = $1;
1703 $$.else_statement = $3;
1707 $$.then_statement = $1;
1708 $$.else_statement = NULL;
1715 $$ = (ast_node *) $1;
1717 | fully_specified_type any_identifier '=' initializer
1720 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1721 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1722 decl->set_location(yylloc);
1723 declarator->set_location(yylloc);
1725 declarator->declarations.push_tail(&decl->link);
1731 * siwtch_statement grammar is based on the syntax described in the body
1732 * of the GLSL spec, not in it's appendix!!!
1735 SWITCH '(' expression ')' switch_body
1737 $$ = new(state) ast_switch_statement($3, $5);
1738 $$->set_location(yylloc);
1745 $$ = new(state) ast_switch_body(NULL);
1746 $$->set_location(yylloc);
1748 | '{' case_statement_list '}'
1750 $$ = new(state) ast_switch_body($2);
1751 $$->set_location(yylloc);
1758 $$ = new(state) ast_case_label($2);
1759 $$->set_location(yylloc);
1763 $$ = new(state) ast_case_label(NULL);
1764 $$->set_location(yylloc);
1771 ast_case_label_list *labels = new(state) ast_case_label_list();
1773 labels->labels.push_tail(& $1->link);
1775 $$->set_location(yylloc);
1777 | case_label_list case_label
1780 $$->labels.push_tail(& $2->link);
1785 case_label_list statement
1787 ast_case_statement *stmts = new(state) ast_case_statement($1);
1788 stmts->set_location(yylloc);
1790 stmts->stmts.push_tail(& $2->link);
1793 | case_statement statement
1796 $$->stmts.push_tail(& $2->link);
1800 case_statement_list:
1803 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1804 cases->set_location(yylloc);
1806 cases->cases.push_tail(& $1->link);
1809 | case_statement_list case_statement
1812 $$->cases.push_tail(& $2->link);
1816 iteration_statement:
1817 WHILE '(' condition ')' statement_no_new_scope
1820 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1821 NULL, $3, NULL, $5);
1822 $$->set_location(yylloc);
1824 | DO statement WHILE '(' expression ')' ';'
1827 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1828 NULL, $5, NULL, $2);
1829 $$->set_location(yylloc);
1831 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1834 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1835 $3, $4.cond, $4.rest, $6);
1836 $$->set_location(yylloc);
1841 expression_statement
1842 | declaration_statement
1859 | conditionopt ';' expression
1866 // Grammar Note: No 'goto'. Gotos are not supported.
1871 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1872 $$->set_location(yylloc);
1877 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1878 $$->set_location(yylloc);
1883 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1884 $$->set_location(yylloc);
1886 | RETURN expression ';'
1889 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1890 $$->set_location(yylloc);
1892 | DISCARD ';' // Fragment shader only.
1895 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1896 $$->set_location(yylloc);
1900 external_declaration:
1901 function_definition { $$ = $1; }
1902 | declaration { $$ = $1; }
1903 | pragma_statement { $$ = NULL; }
1904 | layout_defaults { $$ = NULL; }
1907 function_definition:
1908 function_prototype compound_statement_no_new_scope
1911 $$ = new(ctx) ast_function_definition();
1912 $$->set_location(yylloc);
1916 state->symbols->pop_scope();
1920 /* layout_qualifieropt is packed into this rule */
1922 UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1925 $$ = new(ctx) ast_uniform_block(*state->default_uniform_qualifier,
1928 if (!state->ARB_uniform_buffer_object_enable) {
1929 _mesa_glsl_error(& @1, state,
1930 "#version 140 / GL_ARB_uniform_buffer_object "
1931 "required for defining uniform blocks\n");
1932 } else if (state->ARB_uniform_buffer_object_warn) {
1933 _mesa_glsl_warning(& @1, state,
1934 "#version 140 / GL_ARB_uniform_buffer_object "
1935 "required for defining uniform blocks\n");
1938 | layout_qualifier UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1942 ast_type_qualifier qual = *state->default_uniform_qualifier;
1943 if (!qual.merge_qualifier(& @1, state, $1)) {
1946 $$ = new(ctx) ast_uniform_block(qual, $3, $5);
1948 if (!state->ARB_uniform_buffer_object_enable) {
1949 _mesa_glsl_error(& @1, state,
1950 "#version 140 / GL_ARB_uniform_buffer_object "
1951 "required for defining uniform blocks\n");
1952 } else if (state->ARB_uniform_buffer_object_warn) {
1953 _mesa_glsl_warning(& @1, state,
1954 "#version 140 / GL_ARB_uniform_buffer_object "
1955 "required for defining uniform blocks\n");
1964 $1->link.self_link();
1966 | member_declaration member_list
1969 $2->link.insert_before(& $$->link);
1973 /* Specifying "uniform" inside of a uniform block is redundant. */
1980 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
1983 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1984 type->set_location(yylloc);
1986 type->qualifier = $1;
1987 type->qualifier.flags.q.uniform = true;
1988 type->specifier = $3;
1989 $$ = new(ctx) ast_declarator_list(type);
1990 $$->set_location(yylloc);
1991 $$->ubo_qualifiers_valid = true;
1993 $$->declarations.push_degenerate_list_at_head(& $4->link);
1995 | uniformopt type_specifier struct_declarator_list ';'
1998 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1999 type->set_location(yylloc);
2001 type->qualifier.flags.q.uniform = true;
2002 type->specifier = $2;
2003 $$ = new(ctx) ast_declarator_list(type);
2004 $$->set_location(yylloc);
2005 $$->ubo_qualifiers_valid = true;
2007 $$->declarations.push_degenerate_list_at_head(& $3->link);
2012 layout_qualifier UNIFORM ';'
2014 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,