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 ralloc_asprintf(state, "GLSL%s %d.%02d",
294 state->es_shader ? " ES" : "",
295 state->language_version / 100,
296 state->language_version % 100);
299 _mesa_glsl_error(& @2, state, "%s is not supported. "
300 "Supported versions are: %s\n",
301 state->version_string,
302 state->supported_version_string);
305 if (state->language_version >= 140) {
306 state->ARB_uniform_buffer_object_enable = true;
313 | PRAGMA_DEBUG_OFF EOL
314 | PRAGMA_OPTIMIZE_ON EOL
315 | PRAGMA_OPTIMIZE_OFF EOL
316 | PRAGMA_INVARIANT_ALL EOL
318 if (state->language_version == 110) {
319 _mesa_glsl_warning(& @1, state,
320 "pragma `invariant(all)' not supported in %s",
321 state->version_string);
323 state->all_invariant = true;
328 extension_statement_list:
330 | extension_statement_list extension_statement
340 EXTENSION any_identifier COLON any_identifier EOL
342 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
348 external_declaration_list:
351 /* FINISHME: The NULL test is required because pragmas are set to
352 * FINISHME: NULL. (See production rule for external_declaration.)
355 state->translation_unit.push_tail(& $1->link);
357 | external_declaration_list external_declaration
359 /* FINISHME: The NULL test is required because pragmas are set to
360 * FINISHME: NULL. (See production rule for external_declaration.)
363 state->translation_unit.push_tail(& $2->link);
376 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
377 $$->set_location(yylloc);
378 $$->primary_expression.identifier = $1;
383 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
384 $$->set_location(yylloc);
385 $$->primary_expression.int_constant = $1;
390 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
391 $$->set_location(yylloc);
392 $$->primary_expression.uint_constant = $1;
397 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
398 $$->set_location(yylloc);
399 $$->primary_expression.float_constant = $1;
404 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
405 $$->set_location(yylloc);
406 $$->primary_expression.bool_constant = $1;
416 | postfix_expression '[' integer_expression ']'
419 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
420 $$->set_location(yylloc);
426 | postfix_expression '.' any_identifier
429 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
430 $$->set_location(yylloc);
431 $$->primary_expression.identifier = $3;
433 | postfix_expression INC_OP
436 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
437 $$->set_location(yylloc);
439 | postfix_expression DEC_OP
442 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
443 $$->set_location(yylloc);
452 function_call_or_method
455 function_call_or_method:
456 function_call_generic
457 | postfix_expression '.' method_call_generic
460 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
461 $$->set_location(yylloc);
465 function_call_generic:
466 function_call_header_with_parameters ')'
467 | function_call_header_no_parameters ')'
470 function_call_header_no_parameters:
471 function_call_header VOID_TOK
472 | function_call_header
475 function_call_header_with_parameters:
476 function_call_header assignment_expression
479 $$->set_location(yylloc);
480 $$->expressions.push_tail(& $2->link);
482 | function_call_header_with_parameters ',' assignment_expression
485 $$->set_location(yylloc);
486 $$->expressions.push_tail(& $3->link);
490 // Grammar Note: Constructors look like functions, but lexical
491 // analysis recognized most of them as keywords. They are now
492 // recognized through "type_specifier".
493 function_call_header:
494 function_identifier '('
501 $$ = new(ctx) ast_function_expression($1);
502 $$->set_location(yylloc);
504 | variable_identifier
507 ast_expression *callee = new(ctx) ast_expression($1);
508 $$ = new(ctx) ast_function_expression(callee);
509 $$->set_location(yylloc);
514 ast_expression *callee = new(ctx) ast_expression($1);
515 $$ = new(ctx) ast_function_expression(callee);
516 $$->set_location(yylloc);
521 method_call_header_with_parameters ')'
522 | method_call_header_no_parameters ')'
525 method_call_header_no_parameters:
526 method_call_header VOID_TOK
530 method_call_header_with_parameters:
531 method_call_header assignment_expression
534 $$->set_location(yylloc);
535 $$->expressions.push_tail(& $2->link);
537 | method_call_header_with_parameters ',' assignment_expression
540 $$->set_location(yylloc);
541 $$->expressions.push_tail(& $3->link);
545 // Grammar Note: Constructors look like methods, but lexical
546 // analysis recognized most of them as keywords. They are now
547 // recognized through "type_specifier".
549 variable_identifier '('
552 ast_expression *callee = new(ctx) ast_expression($1);
553 $$ = new(ctx) ast_function_expression(callee);
554 $$->set_location(yylloc);
558 // Grammar Note: No traditional style type casts.
561 | INC_OP unary_expression
564 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
565 $$->set_location(yylloc);
567 | DEC_OP unary_expression
570 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
571 $$->set_location(yylloc);
573 | unary_operator unary_expression
576 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
577 $$->set_location(yylloc);
581 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
583 '+' { $$ = ast_plus; }
584 | '-' { $$ = ast_neg; }
585 | '!' { $$ = ast_logic_not; }
586 | '~' { $$ = ast_bit_not; }
589 multiplicative_expression:
591 | multiplicative_expression '*' unary_expression
594 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
595 $$->set_location(yylloc);
597 | multiplicative_expression '/' unary_expression
600 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
601 $$->set_location(yylloc);
603 | multiplicative_expression '%' unary_expression
606 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
607 $$->set_location(yylloc);
612 multiplicative_expression
613 | additive_expression '+' multiplicative_expression
616 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
617 $$->set_location(yylloc);
619 | additive_expression '-' multiplicative_expression
622 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
623 $$->set_location(yylloc);
629 | shift_expression LEFT_OP additive_expression
632 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
633 $$->set_location(yylloc);
635 | shift_expression RIGHT_OP additive_expression
638 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
639 $$->set_location(yylloc);
643 relational_expression:
645 | relational_expression '<' shift_expression
648 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
649 $$->set_location(yylloc);
651 | relational_expression '>' shift_expression
654 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
655 $$->set_location(yylloc);
657 | relational_expression LE_OP shift_expression
660 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
661 $$->set_location(yylloc);
663 | relational_expression GE_OP shift_expression
666 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
667 $$->set_location(yylloc);
672 relational_expression
673 | equality_expression EQ_OP relational_expression
676 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
677 $$->set_location(yylloc);
679 | equality_expression NE_OP relational_expression
682 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
683 $$->set_location(yylloc);
689 | and_expression '&' equality_expression
692 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
693 $$->set_location(yylloc);
697 exclusive_or_expression:
699 | exclusive_or_expression '^' and_expression
702 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
703 $$->set_location(yylloc);
707 inclusive_or_expression:
708 exclusive_or_expression
709 | inclusive_or_expression '|' exclusive_or_expression
712 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
713 $$->set_location(yylloc);
717 logical_and_expression:
718 inclusive_or_expression
719 | logical_and_expression AND_OP inclusive_or_expression
722 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
723 $$->set_location(yylloc);
727 logical_xor_expression:
728 logical_and_expression
729 | logical_xor_expression XOR_OP logical_and_expression
732 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
733 $$->set_location(yylloc);
737 logical_or_expression:
738 logical_xor_expression
739 | logical_or_expression OR_OP logical_xor_expression
742 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
743 $$->set_location(yylloc);
747 conditional_expression:
748 logical_or_expression
749 | logical_or_expression '?' expression ':' assignment_expression
752 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
753 $$->set_location(yylloc);
757 assignment_expression:
758 conditional_expression
759 | unary_expression assignment_operator assignment_expression
762 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
763 $$->set_location(yylloc);
768 '=' { $$ = ast_assign; }
769 | MUL_ASSIGN { $$ = ast_mul_assign; }
770 | DIV_ASSIGN { $$ = ast_div_assign; }
771 | MOD_ASSIGN { $$ = ast_mod_assign; }
772 | ADD_ASSIGN { $$ = ast_add_assign; }
773 | SUB_ASSIGN { $$ = ast_sub_assign; }
774 | LEFT_ASSIGN { $$ = ast_ls_assign; }
775 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
776 | AND_ASSIGN { $$ = ast_and_assign; }
777 | XOR_ASSIGN { $$ = ast_xor_assign; }
778 | OR_ASSIGN { $$ = ast_or_assign; }
782 assignment_expression
786 | expression ',' assignment_expression
789 if ($1->oper != ast_sequence) {
790 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
791 $$->set_location(yylloc);
792 $$->expressions.push_tail(& $1->link);
797 $$->expressions.push_tail(& $3->link);
802 conditional_expression
806 function_prototype ';'
808 state->symbols->pop_scope();
811 | init_declarator_list ';'
815 | PRECISION precision_qualifier type_specifier_no_prec ';'
818 $3->is_precision_statement = true;
828 function_declarator ')'
833 | function_header_with_parameters
836 function_header_with_parameters:
837 function_header parameter_declaration
840 $$->parameters.push_tail(& $2->link);
842 | function_header_with_parameters ',' parameter_declaration
845 $$->parameters.push_tail(& $3->link);
850 fully_specified_type variable_identifier '('
853 $$ = new(ctx) ast_function();
854 $$->set_location(yylloc);
855 $$->return_type = $1;
858 state->symbols->add_function(new(state) ir_function($2));
859 state->symbols->push_scope();
863 parameter_declarator:
864 type_specifier any_identifier
867 $$ = new(ctx) ast_parameter_declarator();
868 $$->set_location(yylloc);
869 $$->type = new(ctx) ast_fully_specified_type();
870 $$->type->set_location(yylloc);
871 $$->type->specifier = $1;
874 | type_specifier any_identifier '[' constant_expression ']'
877 $$ = new(ctx) ast_parameter_declarator();
878 $$->set_location(yylloc);
879 $$->type = new(ctx) ast_fully_specified_type();
880 $$->type->set_location(yylloc);
881 $$->type->specifier = $1;
888 parameter_declaration:
889 parameter_type_qualifier parameter_qualifier parameter_declarator
891 $1.flags.i |= $2.flags.i;
894 $$->type->qualifier = $1;
896 | parameter_qualifier parameter_declarator
899 $$->type->qualifier = $1;
901 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
904 $1.flags.i |= $2.flags.i;
906 $$ = new(ctx) ast_parameter_declarator();
907 $$->set_location(yylloc);
908 $$->type = new(ctx) ast_fully_specified_type();
909 $$->type->qualifier = $1;
910 $$->type->specifier = $3;
912 | parameter_qualifier parameter_type_specifier
915 $$ = new(ctx) ast_parameter_declarator();
916 $$->set_location(yylloc);
917 $$->type = new(ctx) ast_fully_specified_type();
918 $$->type->qualifier = $1;
919 $$->type->specifier = $2;
926 memset(& $$, 0, sizeof($$));
930 memset(& $$, 0, sizeof($$));
935 memset(& $$, 0, sizeof($$));
940 memset(& $$, 0, sizeof($$));
946 parameter_type_specifier:
950 init_declarator_list:
952 | init_declarator_list ',' any_identifier
955 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
956 decl->set_location(yylloc);
959 $$->declarations.push_tail(&decl->link);
960 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
962 | init_declarator_list ',' any_identifier '[' ']'
965 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
966 decl->set_location(yylloc);
969 $$->declarations.push_tail(&decl->link);
970 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
972 | init_declarator_list ',' any_identifier '[' constant_expression ']'
975 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
976 decl->set_location(yylloc);
979 $$->declarations.push_tail(&decl->link);
980 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
982 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
985 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
986 decl->set_location(yylloc);
989 $$->declarations.push_tail(&decl->link);
990 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
992 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
995 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
996 decl->set_location(yylloc);
999 $$->declarations.push_tail(&decl->link);
1000 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1002 | init_declarator_list ',' any_identifier '=' initializer
1005 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
1006 decl->set_location(yylloc);
1009 $$->declarations.push_tail(&decl->link);
1010 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1014 // Grammar Note: No 'enum', or 'typedef'.
1016 fully_specified_type
1019 /* Empty declaration list is valid. */
1020 $$ = new(ctx) ast_declarator_list($1);
1021 $$->set_location(yylloc);
1023 | fully_specified_type any_identifier
1026 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1028 $$ = new(ctx) ast_declarator_list($1);
1029 $$->set_location(yylloc);
1030 $$->declarations.push_tail(&decl->link);
1032 | fully_specified_type any_identifier '[' ']'
1035 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1037 $$ = new(ctx) ast_declarator_list($1);
1038 $$->set_location(yylloc);
1039 $$->declarations.push_tail(&decl->link);
1041 | fully_specified_type any_identifier '[' constant_expression ']'
1044 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1046 $$ = new(ctx) ast_declarator_list($1);
1047 $$->set_location(yylloc);
1048 $$->declarations.push_tail(&decl->link);
1050 | fully_specified_type any_identifier '[' ']' '=' initializer
1053 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1055 $$ = new(ctx) ast_declarator_list($1);
1056 $$->set_location(yylloc);
1057 $$->declarations.push_tail(&decl->link);
1059 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1062 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1064 $$ = new(ctx) ast_declarator_list($1);
1065 $$->set_location(yylloc);
1066 $$->declarations.push_tail(&decl->link);
1068 | fully_specified_type any_identifier '=' initializer
1071 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1073 $$ = new(ctx) ast_declarator_list($1);
1074 $$->set_location(yylloc);
1075 $$->declarations.push_tail(&decl->link);
1077 | INVARIANT variable_identifier // Vertex only.
1080 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1082 $$ = new(ctx) ast_declarator_list(NULL);
1083 $$->set_location(yylloc);
1084 $$->invariant = true;
1086 $$->declarations.push_tail(&decl->link);
1090 fully_specified_type:
1094 $$ = new(ctx) ast_fully_specified_type();
1095 $$->set_location(yylloc);
1098 | type_qualifier type_specifier
1101 $$ = new(ctx) ast_fully_specified_type();
1102 $$->set_location(yylloc);
1109 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1115 layout_qualifier_id_list:
1117 | layout_qualifier_id_list ',' layout_qualifier_id
1120 if (!$$.merge_qualifier(& @3, state, $3)) {
1127 INTCONSTANT { $$ = $1; }
1128 | UINTCONSTANT { $$ = $1; }
1130 layout_qualifier_id:
1133 memset(& $$, 0, sizeof($$));
1135 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1136 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1137 if (strcmp($1, "origin_upper_left") == 0) {
1138 $$.flags.q.origin_upper_left = 1;
1139 } else if (strcmp($1, "pixel_center_integer") == 0) {
1140 $$.flags.q.pixel_center_integer = 1;
1143 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1144 _mesa_glsl_warning(& @1, state,
1145 "GL_ARB_fragment_coord_conventions layout "
1146 "identifier `%s' used\n", $1);
1150 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1152 (state->AMD_conservative_depth_enable ||
1153 state->ARB_conservative_depth_enable)) {
1154 if (strcmp($1, "depth_any") == 0) {
1155 $$.flags.q.depth_any = 1;
1156 } else if (strcmp($1, "depth_greater") == 0) {
1157 $$.flags.q.depth_greater = 1;
1158 } else if (strcmp($1, "depth_less") == 0) {
1159 $$.flags.q.depth_less = 1;
1160 } else if (strcmp($1, "depth_unchanged") == 0) {
1161 $$.flags.q.depth_unchanged = 1;
1164 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1165 _mesa_glsl_warning(& @1, state,
1166 "GL_AMD_conservative_depth "
1167 "layout qualifier `%s' is used\n", $1);
1169 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1170 _mesa_glsl_warning(& @1, state,
1171 "GL_ARB_conservative_depth "
1172 "layout qualifier `%s' is used\n", $1);
1176 /* See also uniform_block_layout_qualifier. */
1177 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1178 if (strcmp($1, "std140") == 0) {
1179 $$.flags.q.std140 = 1;
1180 } else if (strcmp($1, "shared") == 0) {
1181 $$.flags.q.shared = 1;
1182 } else if (strcmp($1, "column_major") == 0) {
1183 $$.flags.q.column_major = 1;
1186 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1187 _mesa_glsl_warning(& @1, state,
1188 "#version 140 / GL_ARB_uniform_buffer_object "
1189 "layout qualifier `%s' is used\n", $1);
1194 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1199 | any_identifier '=' integer_constant
1201 memset(& $$, 0, sizeof($$));
1203 if (state->ARB_explicit_attrib_location_enable) {
1204 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1205 * FINISHME: GLSL 1.30 (or later) are supported.
1207 if (strcmp("location", $1) == 0) {
1208 $$.flags.q.explicit_location = 1;
1213 _mesa_glsl_error(& @3, state,
1214 "invalid location %d specified\n", $3);
1219 if (strcmp("index", $1) == 0) {
1220 $$.flags.q.explicit_index = 1;
1225 _mesa_glsl_error(& @3, state,
1226 "invalid index %d specified\n", $3);
1232 /* If the identifier didn't match any known layout identifiers,
1236 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1239 } else if (state->ARB_explicit_attrib_location_warn) {
1240 _mesa_glsl_warning(& @1, state,
1241 "GL_ARB_explicit_attrib_location layout "
1242 "identifier `%s' used\n", $1);
1245 | uniform_block_layout_qualifier
1248 /* Layout qualifiers for ARB_uniform_buffer_object. */
1249 if (!state->ARB_uniform_buffer_object_enable) {
1250 _mesa_glsl_error(& @1, state,
1251 "#version 140 / GL_ARB_uniform_buffer_object "
1252 "layout qualifier `%s' is used\n", $1);
1253 } else if (state->ARB_uniform_buffer_object_warn) {
1254 _mesa_glsl_warning(& @1, state,
1255 "#version 140 / GL_ARB_uniform_buffer_object "
1256 "layout qualifier `%s' is used\n", $1);
1261 /* This is a separate language rule because we parse these as tokens
1262 * (due to them being reserved keywords) instead of identifiers like
1263 * most qualifiers. See the any_identifier path of
1264 * layout_qualifier_id for the others.
1266 uniform_block_layout_qualifier:
1269 memset(& $$, 0, sizeof($$));
1270 $$.flags.q.row_major = 1;
1274 memset(& $$, 0, sizeof($$));
1275 $$.flags.q.packed = 1;
1279 interpolation_qualifier:
1282 memset(& $$, 0, sizeof($$));
1283 $$.flags.q.smooth = 1;
1287 memset(& $$, 0, sizeof($$));
1288 $$.flags.q.flat = 1;
1292 memset(& $$, 0, sizeof($$));
1293 $$.flags.q.noperspective = 1;
1297 parameter_type_qualifier:
1300 memset(& $$, 0, sizeof($$));
1301 $$.flags.q.constant = 1;
1308 | layout_qualifier storage_qualifier
1311 $$.flags.i |= $2.flags.i;
1313 | interpolation_qualifier
1314 | interpolation_qualifier storage_qualifier
1317 $$.flags.i |= $2.flags.i;
1319 | INVARIANT storage_qualifier
1322 $$.flags.q.invariant = 1;
1324 | INVARIANT interpolation_qualifier storage_qualifier
1327 $$.flags.i |= $3.flags.i;
1328 $$.flags.q.invariant = 1;
1332 memset(& $$, 0, sizeof($$));
1333 $$.flags.q.invariant = 1;
1340 memset(& $$, 0, sizeof($$));
1341 $$.flags.q.constant = 1;
1345 memset(& $$, 0, sizeof($$));
1346 $$.flags.q.attribute = 1;
1350 memset(& $$, 0, sizeof($$));
1351 $$.flags.q.varying = 1;
1355 memset(& $$, 0, sizeof($$));
1356 $$.flags.q.centroid = 1;
1357 $$.flags.q.varying = 1;
1361 memset(& $$, 0, sizeof($$));
1366 memset(& $$, 0, sizeof($$));
1371 memset(& $$, 0, sizeof($$));
1372 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1376 memset(& $$, 0, sizeof($$));
1377 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1381 memset(& $$, 0, sizeof($$));
1382 $$.flags.q.uniform = 1;
1387 type_specifier_no_prec
1391 | precision_qualifier type_specifier_no_prec
1398 type_specifier_no_prec:
1399 type_specifier_nonarray
1400 | type_specifier_nonarray '[' ']'
1403 $$->is_array = true;
1404 $$->array_size = NULL;
1406 | type_specifier_nonarray '[' constant_expression ']'
1409 $$->is_array = true;
1410 $$->array_size = $3;
1414 type_specifier_nonarray:
1415 basic_type_specifier_nonarray
1418 $$ = new(ctx) ast_type_specifier($1);
1419 $$->set_location(yylloc);
1424 $$ = new(ctx) ast_type_specifier($1);
1425 $$->set_location(yylloc);
1430 $$ = new(ctx) ast_type_specifier($1);
1431 $$->set_location(yylloc);
1435 basic_type_specifier_nonarray:
1436 VOID_TOK { $$ = "void"; }
1437 | FLOAT_TOK { $$ = "float"; }
1438 | INT_TOK { $$ = "int"; }
1439 | UINT_TOK { $$ = "uint"; }
1440 | BOOL_TOK { $$ = "bool"; }
1441 | VEC2 { $$ = "vec2"; }
1442 | VEC3 { $$ = "vec3"; }
1443 | VEC4 { $$ = "vec4"; }
1444 | BVEC2 { $$ = "bvec2"; }
1445 | BVEC3 { $$ = "bvec3"; }
1446 | BVEC4 { $$ = "bvec4"; }
1447 | IVEC2 { $$ = "ivec2"; }
1448 | IVEC3 { $$ = "ivec3"; }
1449 | IVEC4 { $$ = "ivec4"; }
1450 | UVEC2 { $$ = "uvec2"; }
1451 | UVEC3 { $$ = "uvec3"; }
1452 | UVEC4 { $$ = "uvec4"; }
1453 | MAT2X2 { $$ = "mat2"; }
1454 | MAT2X3 { $$ = "mat2x3"; }
1455 | MAT2X4 { $$ = "mat2x4"; }
1456 | MAT3X2 { $$ = "mat3x2"; }
1457 | MAT3X3 { $$ = "mat3"; }
1458 | MAT3X4 { $$ = "mat3x4"; }
1459 | MAT4X2 { $$ = "mat4x2"; }
1460 | MAT4X3 { $$ = "mat4x3"; }
1461 | MAT4X4 { $$ = "mat4"; }
1462 | SAMPLER1D { $$ = "sampler1D"; }
1463 | SAMPLER2D { $$ = "sampler2D"; }
1464 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1465 | SAMPLER3D { $$ = "sampler3D"; }
1466 | SAMPLERCUBE { $$ = "samplerCube"; }
1467 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1468 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1469 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1470 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1471 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1472 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1473 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1474 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1475 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1476 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1477 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1478 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1479 | ISAMPLER1D { $$ = "isampler1D"; }
1480 | ISAMPLER2D { $$ = "isampler2D"; }
1481 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1482 | ISAMPLER3D { $$ = "isampler3D"; }
1483 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1484 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1485 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1486 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1487 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1488 | USAMPLER1D { $$ = "usampler1D"; }
1489 | USAMPLER2D { $$ = "usampler2D"; }
1490 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1491 | USAMPLER3D { $$ = "usampler3D"; }
1492 | USAMPLERCUBE { $$ = "usamplerCube"; }
1493 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1494 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1495 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1496 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1499 precision_qualifier:
1501 if (!state->es_shader && state->language_version < 130)
1502 _mesa_glsl_error(& @1, state,
1503 "precision qualifier forbidden "
1504 "in %s (1.30 or later "
1506 state->version_string);
1508 $$ = ast_precision_high;
1511 if (!state->es_shader && state->language_version < 130)
1512 _mesa_glsl_error(& @1, state,
1513 "precision qualifier forbidden "
1514 "in %s (1.30 or later "
1516 state->version_string);
1518 $$ = ast_precision_medium;
1521 if (!state->es_shader && state->language_version < 130)
1522 _mesa_glsl_error(& @1, state,
1523 "precision qualifier forbidden "
1524 "in %s (1.30 or later "
1526 state->version_string);
1528 $$ = ast_precision_low;
1533 STRUCT any_identifier '{' struct_declaration_list '}'
1536 $$ = new(ctx) ast_struct_specifier($2, $4);
1537 $$->set_location(yylloc);
1538 state->symbols->add_type($2, glsl_type::void_type);
1540 | STRUCT '{' struct_declaration_list '}'
1543 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1544 $$->set_location(yylloc);
1548 struct_declaration_list:
1552 $1->link.self_link();
1554 | struct_declaration_list struct_declaration
1557 $$->link.insert_before(& $2->link);
1562 type_specifier struct_declarator_list ';'
1565 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1566 type->set_location(yylloc);
1568 type->specifier = $1;
1569 $$ = new(ctx) ast_declarator_list(type);
1570 $$->set_location(yylloc);
1572 $$->declarations.push_degenerate_list_at_head(& $2->link);
1576 struct_declarator_list:
1580 $1->link.self_link();
1582 | struct_declarator_list ',' struct_declarator
1585 $$->link.insert_before(& $3->link);
1593 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1594 $$->set_location(yylloc);
1595 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1597 | any_identifier '[' constant_expression ']'
1600 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1601 $$->set_location(yylloc);
1606 assignment_expression
1609 declaration_statement:
1613 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1616 compound_statement { $$ = (ast_node *) $1; }
1621 declaration_statement
1622 | expression_statement
1623 | selection_statement
1625 | iteration_statement
1633 $$ = new(ctx) ast_compound_statement(true, NULL);
1634 $$->set_location(yylloc);
1638 state->symbols->push_scope();
1643 $$ = new(ctx) ast_compound_statement(true, $3);
1644 $$->set_location(yylloc);
1645 state->symbols->pop_scope();
1649 statement_no_new_scope:
1650 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1654 compound_statement_no_new_scope:
1658 $$ = new(ctx) ast_compound_statement(false, NULL);
1659 $$->set_location(yylloc);
1661 | '{' statement_list '}'
1664 $$ = new(ctx) ast_compound_statement(false, $2);
1665 $$->set_location(yylloc);
1673 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1678 $$->link.self_link();
1680 | statement_list statement
1683 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1687 $$->link.insert_before(& $2->link);
1691 expression_statement:
1695 $$ = new(ctx) ast_expression_statement(NULL);
1696 $$->set_location(yylloc);
1701 $$ = new(ctx) ast_expression_statement($1);
1702 $$->set_location(yylloc);
1706 selection_statement:
1707 IF '(' expression ')' selection_rest_statement
1709 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1711 $$->set_location(yylloc);
1715 selection_rest_statement:
1716 statement ELSE statement
1718 $$.then_statement = $1;
1719 $$.else_statement = $3;
1723 $$.then_statement = $1;
1724 $$.else_statement = NULL;
1731 $$ = (ast_node *) $1;
1733 | fully_specified_type any_identifier '=' initializer
1736 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1737 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1738 decl->set_location(yylloc);
1739 declarator->set_location(yylloc);
1741 declarator->declarations.push_tail(&decl->link);
1747 * siwtch_statement grammar is based on the syntax described in the body
1748 * of the GLSL spec, not in it's appendix!!!
1751 SWITCH '(' expression ')' switch_body
1753 $$ = new(state) ast_switch_statement($3, $5);
1754 $$->set_location(yylloc);
1761 $$ = new(state) ast_switch_body(NULL);
1762 $$->set_location(yylloc);
1764 | '{' case_statement_list '}'
1766 $$ = new(state) ast_switch_body($2);
1767 $$->set_location(yylloc);
1774 $$ = new(state) ast_case_label($2);
1775 $$->set_location(yylloc);
1779 $$ = new(state) ast_case_label(NULL);
1780 $$->set_location(yylloc);
1787 ast_case_label_list *labels = new(state) ast_case_label_list();
1789 labels->labels.push_tail(& $1->link);
1791 $$->set_location(yylloc);
1793 | case_label_list case_label
1796 $$->labels.push_tail(& $2->link);
1801 case_label_list statement
1803 ast_case_statement *stmts = new(state) ast_case_statement($1);
1804 stmts->set_location(yylloc);
1806 stmts->stmts.push_tail(& $2->link);
1809 | case_statement statement
1812 $$->stmts.push_tail(& $2->link);
1816 case_statement_list:
1819 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1820 cases->set_location(yylloc);
1822 cases->cases.push_tail(& $1->link);
1825 | case_statement_list case_statement
1828 $$->cases.push_tail(& $2->link);
1832 iteration_statement:
1833 WHILE '(' condition ')' statement_no_new_scope
1836 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1837 NULL, $3, NULL, $5);
1838 $$->set_location(yylloc);
1840 | DO statement WHILE '(' expression ')' ';'
1843 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1844 NULL, $5, NULL, $2);
1845 $$->set_location(yylloc);
1847 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1850 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1851 $3, $4.cond, $4.rest, $6);
1852 $$->set_location(yylloc);
1857 expression_statement
1858 | declaration_statement
1875 | conditionopt ';' expression
1882 // Grammar Note: No 'goto'. Gotos are not supported.
1887 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1888 $$->set_location(yylloc);
1893 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1894 $$->set_location(yylloc);
1899 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1900 $$->set_location(yylloc);
1902 | RETURN expression ';'
1905 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1906 $$->set_location(yylloc);
1908 | DISCARD ';' // Fragment shader only.
1911 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1912 $$->set_location(yylloc);
1916 external_declaration:
1917 function_definition { $$ = $1; }
1918 | declaration { $$ = $1; }
1919 | pragma_statement { $$ = NULL; }
1920 | layout_defaults { $$ = NULL; }
1923 function_definition:
1924 function_prototype compound_statement_no_new_scope
1927 $$ = new(ctx) ast_function_definition();
1928 $$->set_location(yylloc);
1932 state->symbols->pop_scope();
1936 /* layout_qualifieropt is packed into this rule */
1938 UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1941 $$ = new(ctx) ast_uniform_block(*state->default_uniform_qualifier,
1944 if (!state->ARB_uniform_buffer_object_enable) {
1945 _mesa_glsl_error(& @1, state,
1946 "#version 140 / GL_ARB_uniform_buffer_object "
1947 "required for defining uniform blocks\n");
1948 } else if (state->ARB_uniform_buffer_object_warn) {
1949 _mesa_glsl_warning(& @1, state,
1950 "#version 140 / GL_ARB_uniform_buffer_object "
1951 "required for defining uniform blocks\n");
1954 | layout_qualifier UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
1958 ast_type_qualifier qual = *state->default_uniform_qualifier;
1959 if (!qual.merge_qualifier(& @1, state, $1)) {
1962 $$ = new(ctx) ast_uniform_block(qual, $3, $5);
1964 if (!state->ARB_uniform_buffer_object_enable) {
1965 _mesa_glsl_error(& @1, state,
1966 "#version 140 / GL_ARB_uniform_buffer_object "
1967 "required for defining uniform blocks\n");
1968 } else if (state->ARB_uniform_buffer_object_warn) {
1969 _mesa_glsl_warning(& @1, state,
1970 "#version 140 / GL_ARB_uniform_buffer_object "
1971 "required for defining uniform blocks\n");
1980 $1->link.self_link();
1982 | member_declaration member_list
1985 $2->link.insert_before(& $$->link);
1989 /* Specifying "uniform" inside of a uniform block is redundant. */
1996 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
1999 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2000 type->set_location(yylloc);
2002 type->qualifier = $1;
2003 type->qualifier.flags.q.uniform = true;
2004 type->specifier = $3;
2005 $$ = new(ctx) ast_declarator_list(type);
2006 $$->set_location(yylloc);
2007 $$->ubo_qualifiers_valid = true;
2009 $$->declarations.push_degenerate_list_at_head(& $4->link);
2011 | uniformopt type_specifier struct_declarator_list ';'
2014 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2015 type->set_location(yylloc);
2017 type->qualifier.flags.q.uniform = true;
2018 type->specifier = $2;
2019 $$ = new(ctx) ast_declarator_list(type);
2020 $$->set_location(yylloc);
2021 $$->ubo_qualifiers_valid = true;
2023 $$->declarations.push_degenerate_list_at_head(& $3->link);
2028 layout_qualifier UNIFORM ';'
2030 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,