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
143 %token COMMON PARTITION ACTIVE FILTER
144 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
145 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
146 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
147 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
148 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
151 %type <identifier> variable_identifier
152 %type <node> statement
153 %type <node> statement_list
154 %type <node> simple_statement
155 %type <n> precision_qualifier
156 %type <type_qualifier> type_qualifier
157 %type <type_qualifier> storage_qualifier
158 %type <type_qualifier> interpolation_qualifier
159 %type <type_qualifier> layout_qualifier
160 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
161 %type <type_qualifier> uniform_block_layout_qualifier
162 %type <type_specifier> type_specifier
163 %type <type_specifier> type_specifier_no_prec
164 %type <type_specifier> type_specifier_nonarray
165 %type <identifier> basic_type_specifier_nonarray
166 %type <fully_specified_type> fully_specified_type
167 %type <function> function_prototype
168 %type <function> function_header
169 %type <function> function_header_with_parameters
170 %type <function> function_declarator
171 %type <parameter_declarator> parameter_declarator
172 %type <parameter_declarator> parameter_declaration
173 %type <type_qualifier> parameter_qualifier
174 %type <type_qualifier> parameter_type_qualifier
175 %type <type_specifier> parameter_type_specifier
176 %type <function_definition> function_definition
177 %type <compound_statement> compound_statement_no_new_scope
178 %type <compound_statement> compound_statement
179 %type <node> statement_no_new_scope
180 %type <node> expression_statement
181 %type <expression> expression
182 %type <expression> primary_expression
183 %type <expression> assignment_expression
184 %type <expression> conditional_expression
185 %type <expression> logical_or_expression
186 %type <expression> logical_xor_expression
187 %type <expression> logical_and_expression
188 %type <expression> inclusive_or_expression
189 %type <expression> exclusive_or_expression
190 %type <expression> and_expression
191 %type <expression> equality_expression
192 %type <expression> relational_expression
193 %type <expression> shift_expression
194 %type <expression> additive_expression
195 %type <expression> multiplicative_expression
196 %type <expression> unary_expression
197 %type <expression> constant_expression
198 %type <expression> integer_expression
199 %type <expression> postfix_expression
200 %type <expression> function_call_header_with_parameters
201 %type <expression> function_call_header_no_parameters
202 %type <expression> function_call_header
203 %type <expression> function_call_generic
204 %type <expression> function_call_or_method
205 %type <expression> function_call
206 %type <expression> method_call_generic
207 %type <expression> method_call_header_with_parameters
208 %type <expression> method_call_header_no_parameters
209 %type <expression> method_call_header
210 %type <n> assignment_operator
211 %type <n> unary_operator
212 %type <expression> function_identifier
213 %type <node> external_declaration
214 %type <declarator_list> init_declarator_list
215 %type <declarator_list> single_declaration
216 %type <expression> initializer
217 %type <node> declaration
218 %type <node> declaration_statement
219 %type <node> jump_statement
220 %type <node> uniform_block
221 %type <struct_specifier> struct_specifier
222 %type <declarator_list> struct_declaration_list
223 %type <declarator_list> struct_declaration
224 %type <declaration> struct_declarator
225 %type <declaration> struct_declarator_list
226 %type <declarator_list> member_list
227 %type <declarator_list> member_declaration
228 %type <node> selection_statement
229 %type <selection_rest_statement> selection_rest_statement
230 %type <node> switch_statement
231 %type <switch_body> switch_body
232 %type <case_label_list> case_label_list
233 %type <case_label> case_label
234 %type <case_statement> case_statement
235 %type <case_statement_list> case_statement_list
236 %type <node> iteration_statement
237 %type <node> condition
238 %type <node> conditionopt
239 %type <node> for_init_statement
240 %type <for_rest_statement> for_rest_statement
241 %type <n> integer_constant
245 version_statement extension_statement_list
247 _mesa_glsl_initialize_types(state);
249 external_declaration_list
251 delete state->symbols;
252 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
253 _mesa_glsl_initialize_types(state);
258 /* blank - no #version specified: defaults are already set */
259 | VERSION_TOK INTCONSTANT EOL
261 bool supported = false;
265 state->es_shader = true;
266 supported = state->ctx->API == API_OPENGLES2 ||
267 state->ctx->Extensions.ARB_ES2_compatibility;
271 /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
272 * the OpenGL 3.2 Core context is supported, this logic will need
273 * change. Older versions of GLSL are no longer supported
274 * outside the compatibility contexts of 3.x.
283 supported = _mesa_is_desktop_gl(state->ctx) &&
284 ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
291 state->language_version = $2;
292 state->version_string =
293 glsl_compute_version_string(state, state->es_shader,
294 state->language_version);
297 _mesa_glsl_error(& @2, state, "%s is not supported. "
298 "Supported versions are: %s\n",
299 state->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->language_version == 110) {
317 _mesa_glsl_warning(& @1, state,
318 "pragma `invariant(all)' not supported in %s",
319 state->version_string);
321 state->all_invariant = true;
326 extension_statement_list:
328 | extension_statement_list extension_statement
338 EXTENSION any_identifier COLON any_identifier EOL
340 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
346 external_declaration_list:
349 /* FINISHME: The NULL test is required because pragmas are set to
350 * FINISHME: NULL. (See production rule for external_declaration.)
353 state->translation_unit.push_tail(& $1->link);
355 | external_declaration_list external_declaration
357 /* FINISHME: The NULL test is required because pragmas are set to
358 * FINISHME: NULL. (See production rule for external_declaration.)
361 state->translation_unit.push_tail(& $2->link);
374 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
375 $$->set_location(yylloc);
376 $$->primary_expression.identifier = $1;
381 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
382 $$->set_location(yylloc);
383 $$->primary_expression.int_constant = $1;
388 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
389 $$->set_location(yylloc);
390 $$->primary_expression.uint_constant = $1;
395 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
396 $$->set_location(yylloc);
397 $$->primary_expression.float_constant = $1;
402 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
403 $$->set_location(yylloc);
404 $$->primary_expression.bool_constant = $1;
414 | postfix_expression '[' integer_expression ']'
417 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
418 $$->set_location(yylloc);
424 | postfix_expression '.' any_identifier
427 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
428 $$->set_location(yylloc);
429 $$->primary_expression.identifier = $3;
431 | postfix_expression INC_OP
434 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
435 $$->set_location(yylloc);
437 | postfix_expression DEC_OP
440 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
441 $$->set_location(yylloc);
450 function_call_or_method
453 function_call_or_method:
454 function_call_generic
455 | postfix_expression '.' method_call_generic
458 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
459 $$->set_location(yylloc);
463 function_call_generic:
464 function_call_header_with_parameters ')'
465 | function_call_header_no_parameters ')'
468 function_call_header_no_parameters:
469 function_call_header VOID_TOK
470 | function_call_header
473 function_call_header_with_parameters:
474 function_call_header assignment_expression
477 $$->set_location(yylloc);
478 $$->expressions.push_tail(& $2->link);
480 | function_call_header_with_parameters ',' assignment_expression
483 $$->set_location(yylloc);
484 $$->expressions.push_tail(& $3->link);
488 // Grammar Note: Constructors look like functions, but lexical
489 // analysis recognized most of them as keywords. They are now
490 // recognized through "type_specifier".
491 function_call_header:
492 function_identifier '('
499 $$ = new(ctx) ast_function_expression($1);
500 $$->set_location(yylloc);
502 | variable_identifier
505 ast_expression *callee = new(ctx) ast_expression($1);
506 $$ = new(ctx) ast_function_expression(callee);
507 $$->set_location(yylloc);
512 ast_expression *callee = new(ctx) ast_expression($1);
513 $$ = new(ctx) ast_function_expression(callee);
514 $$->set_location(yylloc);
519 method_call_header_with_parameters ')'
520 | method_call_header_no_parameters ')'
523 method_call_header_no_parameters:
524 method_call_header VOID_TOK
528 method_call_header_with_parameters:
529 method_call_header assignment_expression
532 $$->set_location(yylloc);
533 $$->expressions.push_tail(& $2->link);
535 | method_call_header_with_parameters ',' assignment_expression
538 $$->set_location(yylloc);
539 $$->expressions.push_tail(& $3->link);
543 // Grammar Note: Constructors look like methods, but lexical
544 // analysis recognized most of them as keywords. They are now
545 // recognized through "type_specifier".
547 variable_identifier '('
550 ast_expression *callee = new(ctx) ast_expression($1);
551 $$ = new(ctx) ast_function_expression(callee);
552 $$->set_location(yylloc);
556 // Grammar Note: No traditional style type casts.
559 | INC_OP unary_expression
562 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
563 $$->set_location(yylloc);
565 | DEC_OP unary_expression
568 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
569 $$->set_location(yylloc);
571 | unary_operator unary_expression
574 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
575 $$->set_location(yylloc);
579 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
581 '+' { $$ = ast_plus; }
582 | '-' { $$ = ast_neg; }
583 | '!' { $$ = ast_logic_not; }
584 | '~' { $$ = ast_bit_not; }
587 multiplicative_expression:
589 | multiplicative_expression '*' unary_expression
592 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
593 $$->set_location(yylloc);
595 | multiplicative_expression '/' unary_expression
598 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
599 $$->set_location(yylloc);
601 | multiplicative_expression '%' unary_expression
604 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
605 $$->set_location(yylloc);
610 multiplicative_expression
611 | additive_expression '+' multiplicative_expression
614 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
615 $$->set_location(yylloc);
617 | additive_expression '-' multiplicative_expression
620 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
621 $$->set_location(yylloc);
627 | shift_expression LEFT_OP additive_expression
630 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
631 $$->set_location(yylloc);
633 | shift_expression RIGHT_OP additive_expression
636 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
637 $$->set_location(yylloc);
641 relational_expression:
643 | relational_expression '<' shift_expression
646 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
647 $$->set_location(yylloc);
649 | relational_expression '>' shift_expression
652 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
653 $$->set_location(yylloc);
655 | relational_expression LE_OP shift_expression
658 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
659 $$->set_location(yylloc);
661 | relational_expression GE_OP shift_expression
664 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
665 $$->set_location(yylloc);
670 relational_expression
671 | equality_expression EQ_OP relational_expression
674 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
675 $$->set_location(yylloc);
677 | equality_expression NE_OP relational_expression
680 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
681 $$->set_location(yylloc);
687 | and_expression '&' equality_expression
690 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
691 $$->set_location(yylloc);
695 exclusive_or_expression:
697 | exclusive_or_expression '^' and_expression
700 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
701 $$->set_location(yylloc);
705 inclusive_or_expression:
706 exclusive_or_expression
707 | inclusive_or_expression '|' exclusive_or_expression
710 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
711 $$->set_location(yylloc);
715 logical_and_expression:
716 inclusive_or_expression
717 | logical_and_expression AND_OP inclusive_or_expression
720 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
721 $$->set_location(yylloc);
725 logical_xor_expression:
726 logical_and_expression
727 | logical_xor_expression XOR_OP logical_and_expression
730 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
731 $$->set_location(yylloc);
735 logical_or_expression:
736 logical_xor_expression
737 | logical_or_expression OR_OP logical_xor_expression
740 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
741 $$->set_location(yylloc);
745 conditional_expression:
746 logical_or_expression
747 | logical_or_expression '?' expression ':' assignment_expression
750 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
751 $$->set_location(yylloc);
755 assignment_expression:
756 conditional_expression
757 | unary_expression assignment_operator assignment_expression
760 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
761 $$->set_location(yylloc);
766 '=' { $$ = ast_assign; }
767 | MUL_ASSIGN { $$ = ast_mul_assign; }
768 | DIV_ASSIGN { $$ = ast_div_assign; }
769 | MOD_ASSIGN { $$ = ast_mod_assign; }
770 | ADD_ASSIGN { $$ = ast_add_assign; }
771 | SUB_ASSIGN { $$ = ast_sub_assign; }
772 | LEFT_ASSIGN { $$ = ast_ls_assign; }
773 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
774 | AND_ASSIGN { $$ = ast_and_assign; }
775 | XOR_ASSIGN { $$ = ast_xor_assign; }
776 | OR_ASSIGN { $$ = ast_or_assign; }
780 assignment_expression
784 | expression ',' assignment_expression
787 if ($1->oper != ast_sequence) {
788 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
789 $$->set_location(yylloc);
790 $$->expressions.push_tail(& $1->link);
795 $$->expressions.push_tail(& $3->link);
800 conditional_expression
804 function_prototype ';'
806 state->symbols->pop_scope();
809 | init_declarator_list ';'
813 | PRECISION precision_qualifier type_specifier_no_prec ';'
816 $3->is_precision_statement = true;
826 function_declarator ')'
831 | function_header_with_parameters
834 function_header_with_parameters:
835 function_header parameter_declaration
838 $$->parameters.push_tail(& $2->link);
840 | function_header_with_parameters ',' parameter_declaration
843 $$->parameters.push_tail(& $3->link);
848 fully_specified_type variable_identifier '('
851 $$ = new(ctx) ast_function();
852 $$->set_location(yylloc);
853 $$->return_type = $1;
856 state->symbols->add_function(new(state) ir_function($2));
857 state->symbols->push_scope();
861 parameter_declarator:
862 type_specifier any_identifier
865 $$ = new(ctx) ast_parameter_declarator();
866 $$->set_location(yylloc);
867 $$->type = new(ctx) ast_fully_specified_type();
868 $$->type->set_location(yylloc);
869 $$->type->specifier = $1;
872 | type_specifier any_identifier '[' constant_expression ']'
875 $$ = new(ctx) ast_parameter_declarator();
876 $$->set_location(yylloc);
877 $$->type = new(ctx) ast_fully_specified_type();
878 $$->type->set_location(yylloc);
879 $$->type->specifier = $1;
886 parameter_declaration:
887 parameter_type_qualifier parameter_qualifier parameter_declarator
889 $1.flags.i |= $2.flags.i;
892 $$->type->qualifier = $1;
894 | parameter_qualifier parameter_declarator
897 $$->type->qualifier = $1;
899 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
902 $1.flags.i |= $2.flags.i;
904 $$ = new(ctx) ast_parameter_declarator();
905 $$->set_location(yylloc);
906 $$->type = new(ctx) ast_fully_specified_type();
907 $$->type->qualifier = $1;
908 $$->type->specifier = $3;
910 | parameter_qualifier parameter_type_specifier
913 $$ = new(ctx) ast_parameter_declarator();
914 $$->set_location(yylloc);
915 $$->type = new(ctx) ast_fully_specified_type();
916 $$->type->qualifier = $1;
917 $$->type->specifier = $2;
924 memset(& $$, 0, sizeof($$));
928 memset(& $$, 0, sizeof($$));
933 memset(& $$, 0, sizeof($$));
938 memset(& $$, 0, sizeof($$));
944 parameter_type_specifier:
948 init_declarator_list:
950 | init_declarator_list ',' any_identifier
953 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
954 decl->set_location(yylloc);
957 $$->declarations.push_tail(&decl->link);
958 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
960 | init_declarator_list ',' any_identifier '[' ']'
963 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
964 decl->set_location(yylloc);
967 $$->declarations.push_tail(&decl->link);
968 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
970 | init_declarator_list ',' any_identifier '[' constant_expression ']'
973 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
974 decl->set_location(yylloc);
977 $$->declarations.push_tail(&decl->link);
978 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
980 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
983 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
984 decl->set_location(yylloc);
987 $$->declarations.push_tail(&decl->link);
988 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
990 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
993 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
994 decl->set_location(yylloc);
997 $$->declarations.push_tail(&decl->link);
998 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1000 | init_declarator_list ',' any_identifier '=' initializer
1003 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1004 decl->set_location(yylloc);
1007 $$->declarations.push_tail(&decl->link);
1008 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1012 // Grammar Note: No 'enum', or 'typedef'.
1014 fully_specified_type
1017 /* Empty declaration list is valid. */
1018 $$ = new(ctx) ast_declarator_list($1);
1019 $$->set_location(yylloc);
1021 | fully_specified_type any_identifier
1024 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1026 $$ = new(ctx) ast_declarator_list($1);
1027 $$->set_location(yylloc);
1028 $$->declarations.push_tail(&decl->link);
1030 | fully_specified_type any_identifier '[' ']'
1033 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1035 $$ = new(ctx) ast_declarator_list($1);
1036 $$->set_location(yylloc);
1037 $$->declarations.push_tail(&decl->link);
1039 | fully_specified_type any_identifier '[' constant_expression ']'
1042 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1044 $$ = new(ctx) ast_declarator_list($1);
1045 $$->set_location(yylloc);
1046 $$->declarations.push_tail(&decl->link);
1048 | fully_specified_type any_identifier '[' ']' '=' initializer
1051 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1053 $$ = new(ctx) ast_declarator_list($1);
1054 $$->set_location(yylloc);
1055 $$->declarations.push_tail(&decl->link);
1057 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1060 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1062 $$ = new(ctx) ast_declarator_list($1);
1063 $$->set_location(yylloc);
1064 $$->declarations.push_tail(&decl->link);
1066 | fully_specified_type any_identifier '=' initializer
1069 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1071 $$ = new(ctx) ast_declarator_list($1);
1072 $$->set_location(yylloc);
1073 $$->declarations.push_tail(&decl->link);
1075 | INVARIANT variable_identifier // Vertex only.
1078 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1080 $$ = new(ctx) ast_declarator_list(NULL);
1081 $$->set_location(yylloc);
1082 $$->invariant = true;
1084 $$->declarations.push_tail(&decl->link);
1088 fully_specified_type:
1092 $$ = new(ctx) ast_fully_specified_type();
1093 $$->set_location(yylloc);
1096 | type_qualifier type_specifier
1099 $$ = new(ctx) ast_fully_specified_type();
1100 $$->set_location(yylloc);
1107 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1113 layout_qualifier_id_list:
1115 | layout_qualifier_id_list ',' layout_qualifier_id
1118 if (!$$.merge_qualifier(& @3, state, $3)) {
1125 INTCONSTANT { $$ = $1; }
1126 | UINTCONSTANT { $$ = $1; }
1128 layout_qualifier_id:
1131 memset(& $$, 0, sizeof($$));
1133 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1134 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1135 if (strcmp($1, "origin_upper_left") == 0) {
1136 $$.flags.q.origin_upper_left = 1;
1137 } else if (strcmp($1, "pixel_center_integer") == 0) {
1138 $$.flags.q.pixel_center_integer = 1;
1141 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1142 _mesa_glsl_warning(& @1, state,
1143 "GL_ARB_fragment_coord_conventions layout "
1144 "identifier `%s' used\n", $1);
1148 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1150 (state->AMD_conservative_depth_enable ||
1151 state->ARB_conservative_depth_enable)) {
1152 if (strcmp($1, "depth_any") == 0) {
1153 $$.flags.q.depth_any = 1;
1154 } else if (strcmp($1, "depth_greater") == 0) {
1155 $$.flags.q.depth_greater = 1;
1156 } else if (strcmp($1, "depth_less") == 0) {
1157 $$.flags.q.depth_less = 1;
1158 } else if (strcmp($1, "depth_unchanged") == 0) {
1159 $$.flags.q.depth_unchanged = 1;
1162 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1163 _mesa_glsl_warning(& @1, state,
1164 "GL_AMD_conservative_depth "
1165 "layout qualifier `%s' is used\n", $1);
1167 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1168 _mesa_glsl_warning(& @1, state,
1169 "GL_ARB_conservative_depth "
1170 "layout qualifier `%s' is used\n", $1);
1174 /* See also uniform_block_layout_qualifier. */
1175 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1176 if (strcmp($1, "std140") == 0) {
1177 $$.flags.q.std140 = 1;
1178 } else if (strcmp($1, "shared") == 0) {
1179 $$.flags.q.shared = 1;
1180 } else if (strcmp($1, "column_major") == 0) {
1181 $$.flags.q.column_major = 1;
1184 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1185 _mesa_glsl_warning(& @1, state,
1186 "#version 140 / GL_ARB_uniform_buffer_object "
1187 "layout qualifier `%s' is used\n", $1);
1192 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1197 | any_identifier '=' integer_constant
1199 memset(& $$, 0, sizeof($$));
1201 if (state->ARB_explicit_attrib_location_enable) {
1202 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1203 * FINISHME: GLSL 1.30 (or later) are supported.
1205 if (strcmp("location", $1) == 0) {
1206 $$.flags.q.explicit_location = 1;
1211 _mesa_glsl_error(& @3, state,
1212 "invalid location %d specified\n", $3);
1217 if (strcmp("index", $1) == 0) {
1218 $$.flags.q.explicit_index = 1;
1223 _mesa_glsl_error(& @3, state,
1224 "invalid index %d specified\n", $3);
1230 /* If the identifier didn't match any known layout identifiers,
1234 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1237 } else if (state->ARB_explicit_attrib_location_warn) {
1238 _mesa_glsl_warning(& @1, state,
1239 "GL_ARB_explicit_attrib_location layout "
1240 "identifier `%s' used\n", $1);
1243 | uniform_block_layout_qualifier
1246 /* Layout qualifiers for ARB_uniform_buffer_object. */
1247 if (!state->ARB_uniform_buffer_object_enable) {
1248 _mesa_glsl_error(& @1, state,
1249 "#version 140 / GL_ARB_uniform_buffer_object "
1250 "layout qualifier `%s' is used\n", $1);
1251 } else if (state->ARB_uniform_buffer_object_warn) {
1252 _mesa_glsl_warning(& @1, state,
1253 "#version 140 / GL_ARB_uniform_buffer_object "
1254 "layout qualifier `%s' is used\n", $1);
1259 /* This is a separate language rule because we parse these as tokens
1260 * (due to them being reserved keywords) instead of identifiers like
1261 * most qualifiers. See the any_identifier path of
1262 * layout_qualifier_id for the others.
1264 uniform_block_layout_qualifier:
1267 memset(& $$, 0, sizeof($$));
1268 $$.flags.q.row_major = 1;
1272 memset(& $$, 0, sizeof($$));
1273 $$.flags.q.packed = 1;
1277 interpolation_qualifier:
1280 memset(& $$, 0, sizeof($$));
1281 $$.flags.q.smooth = 1;
1285 memset(& $$, 0, sizeof($$));
1286 $$.flags.q.flat = 1;
1290 memset(& $$, 0, sizeof($$));
1291 $$.flags.q.noperspective = 1;
1295 parameter_type_qualifier:
1298 memset(& $$, 0, sizeof($$));
1299 $$.flags.q.constant = 1;
1306 | layout_qualifier storage_qualifier
1309 $$.flags.i |= $2.flags.i;
1311 | interpolation_qualifier
1312 | interpolation_qualifier storage_qualifier
1315 $$.flags.i |= $2.flags.i;
1317 | INVARIANT storage_qualifier
1320 $$.flags.q.invariant = 1;
1322 | INVARIANT interpolation_qualifier storage_qualifier
1325 $$.flags.i |= $3.flags.i;
1326 $$.flags.q.invariant = 1;
1330 memset(& $$, 0, sizeof($$));
1331 $$.flags.q.invariant = 1;
1338 memset(& $$, 0, sizeof($$));
1339 $$.flags.q.constant = 1;
1343 memset(& $$, 0, sizeof($$));
1344 $$.flags.q.attribute = 1;
1348 memset(& $$, 0, sizeof($$));
1349 $$.flags.q.varying = 1;
1353 memset(& $$, 0, sizeof($$));
1354 $$.flags.q.centroid = 1;
1355 $$.flags.q.varying = 1;
1359 memset(& $$, 0, sizeof($$));
1364 memset(& $$, 0, sizeof($$));
1369 memset(& $$, 0, sizeof($$));
1370 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1374 memset(& $$, 0, sizeof($$));
1375 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1379 memset(& $$, 0, sizeof($$));
1380 $$.flags.q.uniform = 1;
1385 type_specifier_no_prec
1389 | precision_qualifier type_specifier_no_prec
1396 type_specifier_no_prec:
1397 type_specifier_nonarray
1398 | type_specifier_nonarray '[' ']'
1401 $$->is_array = true;
1402 $$->array_size = NULL;
1404 | type_specifier_nonarray '[' constant_expression ']'
1407 $$->is_array = true;
1408 $$->array_size = $3;
1412 type_specifier_nonarray:
1413 basic_type_specifier_nonarray
1416 $$ = new(ctx) ast_type_specifier($1);
1417 $$->set_location(yylloc);
1422 $$ = new(ctx) ast_type_specifier($1);
1423 $$->set_location(yylloc);
1428 $$ = new(ctx) ast_type_specifier($1);
1429 $$->set_location(yylloc);
1433 basic_type_specifier_nonarray:
1434 VOID_TOK { $$ = "void"; }
1435 | FLOAT_TOK { $$ = "float"; }
1436 | INT_TOK { $$ = "int"; }
1437 | UINT_TOK { $$ = "uint"; }
1438 | BOOL_TOK { $$ = "bool"; }
1439 | VEC2 { $$ = "vec2"; }
1440 | VEC3 { $$ = "vec3"; }
1441 | VEC4 { $$ = "vec4"; }
1442 | BVEC2 { $$ = "bvec2"; }
1443 | BVEC3 { $$ = "bvec3"; }
1444 | BVEC4 { $$ = "bvec4"; }
1445 | IVEC2 { $$ = "ivec2"; }
1446 | IVEC3 { $$ = "ivec3"; }
1447 | IVEC4 { $$ = "ivec4"; }
1448 | UVEC2 { $$ = "uvec2"; }
1449 | UVEC3 { $$ = "uvec3"; }
1450 | UVEC4 { $$ = "uvec4"; }
1451 | MAT2X2 { $$ = "mat2"; }
1452 | MAT2X3 { $$ = "mat2x3"; }
1453 | MAT2X4 { $$ = "mat2x4"; }
1454 | MAT3X2 { $$ = "mat3x2"; }
1455 | MAT3X3 { $$ = "mat3"; }
1456 | MAT3X4 { $$ = "mat3x4"; }
1457 | MAT4X2 { $$ = "mat4x2"; }
1458 | MAT4X3 { $$ = "mat4x3"; }
1459 | MAT4X4 { $$ = "mat4"; }
1460 | SAMPLER1D { $$ = "sampler1D"; }
1461 | SAMPLER2D { $$ = "sampler2D"; }
1462 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1463 | SAMPLER3D { $$ = "sampler3D"; }
1464 | SAMPLERCUBE { $$ = "samplerCube"; }
1465 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1466 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1467 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1468 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1469 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1470 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1471 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1472 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1473 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1474 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1475 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1476 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1477 | ISAMPLER1D { $$ = "isampler1D"; }
1478 | ISAMPLER2D { $$ = "isampler2D"; }
1479 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1480 | ISAMPLER3D { $$ = "isampler3D"; }
1481 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1482 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1483 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1484 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1485 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1486 | USAMPLER1D { $$ = "usampler1D"; }
1487 | USAMPLER2D { $$ = "usampler2D"; }
1488 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1489 | USAMPLER3D { $$ = "usampler3D"; }
1490 | USAMPLERCUBE { $$ = "usamplerCube"; }
1491 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1492 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1493 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1494 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1497 precision_qualifier:
1499 if (!state->es_shader && state->language_version < 130)
1500 _mesa_glsl_error(& @1, state,
1501 "precision qualifier forbidden "
1502 "in %s (1.30 or later "
1504 state->version_string);
1506 $$ = ast_precision_high;
1509 if (!state->es_shader && state->language_version < 130)
1510 _mesa_glsl_error(& @1, state,
1511 "precision qualifier forbidden "
1512 "in %s (1.30 or later "
1514 state->version_string);
1516 $$ = ast_precision_medium;
1519 if (!state->es_shader && state->language_version < 130)
1520 _mesa_glsl_error(& @1, state,
1521 "precision qualifier forbidden "
1522 "in %s (1.30 or later "
1524 state->version_string);
1526 $$ = ast_precision_low;
1531 STRUCT any_identifier '{' struct_declaration_list '}'
1534 $$ = new(ctx) ast_struct_specifier($2, $4);
1535 $$->set_location(yylloc);
1536 state->symbols->add_type($2, glsl_type::void_type);
1538 | STRUCT '{' struct_declaration_list '}'
1541 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1542 $$->set_location(yylloc);
1546 struct_declaration_list:
1550 $1->link.self_link();
1552 | struct_declaration_list struct_declaration
1555 $$->link.insert_before(& $2->link);
1560 type_specifier struct_declarator_list ';'
1563 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1564 type->set_location(yylloc);
1566 type->specifier = $1;
1567 $$ = new(ctx) ast_declarator_list(type);
1568 $$->set_location(yylloc);
1570 $$->declarations.push_degenerate_list_at_head(& $2->link);
1574 struct_declarator_list:
1578 $1->link.self_link();
1580 | struct_declarator_list ',' struct_declarator
1583 $$->link.insert_before(& $3->link);
1591 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1592 $$->set_location(yylloc);
1593 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1595 | any_identifier '[' constant_expression ']'
1598 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1599 $$->set_location(yylloc);
1604 assignment_expression
1607 declaration_statement:
1611 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1614 compound_statement { $$ = (ast_node *) $1; }
1619 declaration_statement
1620 | expression_statement
1621 | selection_statement
1623 | iteration_statement
1631 $$ = new(ctx) ast_compound_statement(true, NULL);
1632 $$->set_location(yylloc);
1636 state->symbols->push_scope();
1641 $$ = new(ctx) ast_compound_statement(true, $3);
1642 $$->set_location(yylloc);
1643 state->symbols->pop_scope();
1647 statement_no_new_scope:
1648 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1652 compound_statement_no_new_scope:
1656 $$ = new(ctx) ast_compound_statement(false, NULL);
1657 $$->set_location(yylloc);
1659 | '{' statement_list '}'
1662 $$ = new(ctx) ast_compound_statement(false, $2);
1663 $$->set_location(yylloc);
1671 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1676 $$->link.self_link();
1678 | statement_list statement
1681 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1685 $$->link.insert_before(& $2->link);
1689 expression_statement:
1693 $$ = new(ctx) ast_expression_statement(NULL);
1694 $$->set_location(yylloc);
1699 $$ = new(ctx) ast_expression_statement($1);
1700 $$->set_location(yylloc);
1704 selection_statement:
1705 IF '(' expression ')' selection_rest_statement
1707 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1709 $$->set_location(yylloc);
1713 selection_rest_statement:
1714 statement ELSE statement
1716 $$.then_statement = $1;
1717 $$.else_statement = $3;
1721 $$.then_statement = $1;
1722 $$.else_statement = NULL;
1729 $$ = (ast_node *) $1;
1731 | fully_specified_type any_identifier '=' initializer
1734 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1735 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1736 decl->set_location(yylloc);
1737 declarator->set_location(yylloc);
1739 declarator->declarations.push_tail(&decl->link);
1745 * siwtch_statement grammar is based on the syntax described in the body
1746 * of the GLSL spec, not in it's appendix!!!
1749 SWITCH '(' expression ')' switch_body
1751 $$ = new(state) ast_switch_statement($3, $5);
1752 $$->set_location(yylloc);
1759 $$ = new(state) ast_switch_body(NULL);
1760 $$->set_location(yylloc);
1762 | '{' case_statement_list '}'
1764 $$ = new(state) ast_switch_body($2);
1765 $$->set_location(yylloc);
1772 $$ = new(state) ast_case_label($2);
1773 $$->set_location(yylloc);
1777 $$ = new(state) ast_case_label(NULL);
1778 $$->set_location(yylloc);
1785 ast_case_label_list *labels = new(state) ast_case_label_list();
1787 labels->labels.push_tail(& $1->link);
1789 $$->set_location(yylloc);
1791 | case_label_list case_label
1794 $$->labels.push_tail(& $2->link);
1799 case_label_list statement
1801 ast_case_statement *stmts = new(state) ast_case_statement($1);
1802 stmts->set_location(yylloc);
1804 stmts->stmts.push_tail(& $2->link);
1807 | case_statement statement
1810 $$->stmts.push_tail(& $2->link);
1814 case_statement_list:
1817 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1818 cases->set_location(yylloc);
1820 cases->cases.push_tail(& $1->link);
1823 | case_statement_list case_statement
1826 $$->cases.push_tail(& $2->link);
1830 iteration_statement:
1831 WHILE '(' condition ')' statement_no_new_scope
1834 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1835 NULL, $3, NULL, $5);
1836 $$->set_location(yylloc);
1838 | DO statement WHILE '(' expression ')' ';'
1841 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1842 NULL, $5, NULL, $2);
1843 $$->set_location(yylloc);
1845 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1848 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1849 $3, $4.cond, $4.rest, $6);
1850 $$->set_location(yylloc);
1855 expression_statement
1856 | declaration_statement
1873 | conditionopt ';' expression
1880 // Grammar Note: No 'goto'. Gotos are not supported.
1885 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1886 $$->set_location(yylloc);
1891 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1892 $$->set_location(yylloc);
1897 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1898 $$->set_location(yylloc);
1900 | RETURN expression ';'
1903 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1904 $$->set_location(yylloc);
1906 | DISCARD ';' // Fragment shader only.
1909 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1910 $$->set_location(yylloc);
1914 external_declaration:
1915 function_definition { $$ = $1; }
1916 | declaration { $$ = $1; }
1917 | pragma_statement { $$ = NULL; }
1918 | layout_defaults { $$ = 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 $$ = new(ctx) ast_uniform_block(*state->default_uniform_qualifier,
1942 if (!state->ARB_uniform_buffer_object_enable) {
1943 _mesa_glsl_error(& @1, state,
1944 "#version 140 / GL_ARB_uniform_buffer_object "
1945 "required for defining uniform blocks\n");
1946 } else if (state->ARB_uniform_buffer_object_warn) {
1947 _mesa_glsl_warning(& @1, state,
1948 "#version 140 / GL_ARB_uniform_buffer_object "
1949 "required for defining uniform blocks\n");
1952 | layout_qualifier UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1956 ast_type_qualifier qual = *state->default_uniform_qualifier;
1957 if (!qual.merge_qualifier(& @1, state, $1)) {
1960 $$ = new(ctx) ast_uniform_block(qual, $3, $5);
1962 if (!state->ARB_uniform_buffer_object_enable) {
1963 _mesa_glsl_error(& @1, state,
1964 "#version 140 / GL_ARB_uniform_buffer_object "
1965 "required for defining uniform blocks\n");
1966 } else if (state->ARB_uniform_buffer_object_warn) {
1967 _mesa_glsl_warning(& @1, state,
1968 "#version 140 / GL_ARB_uniform_buffer_object "
1969 "required for defining uniform blocks\n");
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,