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"
33 #define YYLEX_PARAM state->scanner
49 %lex-param {void *scanner}
50 %parse-param {struct _mesa_glsl_parse_state *state}
57 struct ast_type_qualifier type_qualifier;
60 ast_type_specifier *type_specifier;
61 ast_fully_specified_type *fully_specified_type;
62 ast_function *function;
63 ast_parameter_declarator *parameter_declarator;
64 ast_function_definition *function_definition;
65 ast_compound_statement *compound_statement;
66 ast_expression *expression;
67 ast_declarator_list *declarator_list;
68 ast_struct_specifier *struct_specifier;
69 ast_declaration *declaration;
77 ast_node *then_statement;
78 ast_node *else_statement;
79 } selection_rest_statement;
82 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
83 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
84 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
85 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
86 %token NOPERSPECTIVE FLAT SMOOTH
87 %token MAT2X2 MAT2X3 MAT2X4
88 %token MAT3X2 MAT3X3 MAT3X4
89 %token MAT4X2 MAT4X3 MAT4X4
90 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
91 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
92 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
93 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
94 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
95 %token SAMPLEREXTERNALOES
96 %token STRUCT VOID_TOK WHILE
97 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
98 %type <identifier> any_identifier
99 %token <real> FLOATCONSTANT
100 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
101 %token <identifier> FIELD_SELECTION
102 %token LEFT_OP RIGHT_OP
103 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
104 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
105 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
108 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
110 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
111 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
112 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
113 %token PRAGMA_INVARIANT_ALL
116 /* Reserved words that are not actually used in the grammar.
118 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
119 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
120 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
121 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
122 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
123 %token SIZEOF CAST NAMESPACE USING
127 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
128 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
129 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
130 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
131 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
132 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
135 %type <identifier> variable_identifier
136 %type <node> statement
137 %type <node> statement_list
138 %type <node> simple_statement
139 %type <n> precision_qualifier
140 %type <type_qualifier> type_qualifier
141 %type <type_qualifier> storage_qualifier
142 %type <type_qualifier> interpolation_qualifier
143 %type <type_qualifier> layout_qualifier
144 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
145 %type <type_specifier> type_specifier
146 %type <type_specifier> type_specifier_no_prec
147 %type <type_specifier> type_specifier_nonarray
148 %type <n> basic_type_specifier_nonarray
149 %type <fully_specified_type> fully_specified_type
150 %type <function> function_prototype
151 %type <function> function_header
152 %type <function> function_header_with_parameters
153 %type <function> function_declarator
154 %type <parameter_declarator> parameter_declarator
155 %type <parameter_declarator> parameter_declaration
156 %type <type_qualifier> parameter_qualifier
157 %type <type_qualifier> parameter_type_qualifier
158 %type <type_specifier> parameter_type_specifier
159 %type <function_definition> function_definition
160 %type <compound_statement> compound_statement_no_new_scope
161 %type <compound_statement> compound_statement
162 %type <node> statement_no_new_scope
163 %type <node> expression_statement
164 %type <expression> expression
165 %type <expression> primary_expression
166 %type <expression> assignment_expression
167 %type <expression> conditional_expression
168 %type <expression> logical_or_expression
169 %type <expression> logical_xor_expression
170 %type <expression> logical_and_expression
171 %type <expression> inclusive_or_expression
172 %type <expression> exclusive_or_expression
173 %type <expression> and_expression
174 %type <expression> equality_expression
175 %type <expression> relational_expression
176 %type <expression> shift_expression
177 %type <expression> additive_expression
178 %type <expression> multiplicative_expression
179 %type <expression> unary_expression
180 %type <expression> constant_expression
181 %type <expression> integer_expression
182 %type <expression> postfix_expression
183 %type <expression> function_call_header_with_parameters
184 %type <expression> function_call_header_no_parameters
185 %type <expression> function_call_header
186 %type <expression> function_call_generic
187 %type <expression> function_call_or_method
188 %type <expression> function_call
189 %type <expression> method_call_generic
190 %type <expression> method_call_header_with_parameters
191 %type <expression> method_call_header_no_parameters
192 %type <expression> method_call_header
193 %type <n> assignment_operator
194 %type <n> unary_operator
195 %type <expression> function_identifier
196 %type <node> external_declaration
197 %type <declarator_list> init_declarator_list
198 %type <declarator_list> single_declaration
199 %type <expression> initializer
200 %type <node> declaration
201 %type <node> declaration_statement
202 %type <node> jump_statement
203 %type <struct_specifier> struct_specifier
204 %type <node> struct_declaration_list
205 %type <declarator_list> struct_declaration
206 %type <declaration> struct_declarator
207 %type <declaration> struct_declarator_list
208 %type <node> selection_statement
209 %type <selection_rest_statement> selection_rest_statement
210 %type <node> iteration_statement
211 %type <node> condition
212 %type <node> conditionopt
213 %type <node> for_init_statement
214 %type <for_rest_statement> for_rest_statement
218 version_statement extension_statement_list
220 _mesa_glsl_initialize_types(state);
222 external_declaration_list
224 delete state->symbols;
225 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
226 _mesa_glsl_initialize_types(state);
231 /* blank - no #version specified: defaults are already set */
232 | VERSION INTCONSTANT EOL
234 bool supported = false;
238 state->es_shader = true;
239 supported = state->Const.GLSL_100ES;
242 supported = state->Const.GLSL_110;
245 supported = state->Const.GLSL_120;
248 supported = state->Const.GLSL_130;
255 state->language_version = $2;
256 state->version_string =
257 ralloc_asprintf(state, "GLSL%s %d.%02d",
258 state->es_shader ? " ES" : "",
259 state->language_version / 100,
260 state->language_version % 100);
263 _mesa_glsl_error(& @2, state, "%s is not supported. "
264 "Supported versions are: %s\n",
265 state->version_string,
266 state->supported_version_string);
273 | PRAGMA_DEBUG_OFF EOL
274 | PRAGMA_OPTIMIZE_ON EOL
275 | PRAGMA_OPTIMIZE_OFF EOL
276 | PRAGMA_INVARIANT_ALL EOL
278 if (state->language_version < 120) {
279 _mesa_glsl_warning(& @1, state,
280 "pragma `invariant(all)' not supported in %s",
281 state->version_string);
283 state->all_invariant = true;
288 extension_statement_list:
290 | extension_statement_list extension_statement
300 EXTENSION any_identifier COLON any_identifier EOL
302 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
308 external_declaration_list:
311 /* FINISHME: The NULL test is required because pragmas are set to
312 * FINISHME: NULL. (See production rule for external_declaration.)
315 state->translation_unit.push_tail(& $1->link);
317 | external_declaration_list external_declaration
319 /* FINISHME: The NULL test is required because pragmas are set to
320 * FINISHME: NULL. (See production rule for external_declaration.)
323 state->translation_unit.push_tail(& $2->link);
336 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
337 $$->set_location(yylloc);
338 $$->primary_expression.identifier = $1;
343 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
344 $$->set_location(yylloc);
345 $$->primary_expression.int_constant = $1;
350 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
351 $$->set_location(yylloc);
352 $$->primary_expression.uint_constant = $1;
357 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
358 $$->set_location(yylloc);
359 $$->primary_expression.float_constant = $1;
364 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
365 $$->set_location(yylloc);
366 $$->primary_expression.bool_constant = $1;
376 | postfix_expression '[' integer_expression ']'
379 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
380 $$->set_location(yylloc);
386 | postfix_expression '.' any_identifier
389 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
390 $$->set_location(yylloc);
391 $$->primary_expression.identifier = $3;
393 | postfix_expression INC_OP
396 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
397 $$->set_location(yylloc);
399 | postfix_expression DEC_OP
402 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
403 $$->set_location(yylloc);
412 function_call_or_method
415 function_call_or_method:
416 function_call_generic
417 | postfix_expression '.' method_call_generic
420 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
421 $$->set_location(yylloc);
425 function_call_generic:
426 function_call_header_with_parameters ')'
427 | function_call_header_no_parameters ')'
430 function_call_header_no_parameters:
431 function_call_header VOID_TOK
432 | function_call_header
435 function_call_header_with_parameters:
436 function_call_header assignment_expression
439 $$->set_location(yylloc);
440 $$->expressions.push_tail(& $2->link);
442 | function_call_header_with_parameters ',' assignment_expression
445 $$->set_location(yylloc);
446 $$->expressions.push_tail(& $3->link);
450 // Grammar Note: Constructors look like functions, but lexical
451 // analysis recognized most of them as keywords. They are now
452 // recognized through "type_specifier".
453 function_call_header:
454 function_identifier '('
461 $$ = new(ctx) ast_function_expression($1);
462 $$->set_location(yylloc);
464 | variable_identifier
467 ast_expression *callee = new(ctx) ast_expression($1);
468 $$ = new(ctx) ast_function_expression(callee);
469 $$->set_location(yylloc);
474 ast_expression *callee = new(ctx) ast_expression($1);
475 $$ = new(ctx) ast_function_expression(callee);
476 $$->set_location(yylloc);
481 method_call_header_with_parameters ')'
482 | method_call_header_no_parameters ')'
485 method_call_header_no_parameters:
486 method_call_header VOID_TOK
490 method_call_header_with_parameters:
491 method_call_header assignment_expression
494 $$->set_location(yylloc);
495 $$->expressions.push_tail(& $2->link);
497 | method_call_header_with_parameters ',' assignment_expression
500 $$->set_location(yylloc);
501 $$->expressions.push_tail(& $3->link);
505 // Grammar Note: Constructors look like methods, but lexical
506 // analysis recognized most of them as keywords. They are now
507 // recognized through "type_specifier".
509 variable_identifier '('
512 ast_expression *callee = new(ctx) ast_expression($1);
513 $$ = new(ctx) ast_function_expression(callee);
514 $$->set_location(yylloc);
518 // Grammar Note: No traditional style type casts.
521 | INC_OP unary_expression
524 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
525 $$->set_location(yylloc);
527 | DEC_OP unary_expression
530 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
531 $$->set_location(yylloc);
533 | unary_operator unary_expression
536 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
537 $$->set_location(yylloc);
541 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
543 '+' { $$ = ast_plus; }
544 | '-' { $$ = ast_neg; }
545 | '!' { $$ = ast_logic_not; }
546 | '~' { $$ = ast_bit_not; }
549 multiplicative_expression:
551 | multiplicative_expression '*' unary_expression
554 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
555 $$->set_location(yylloc);
557 | multiplicative_expression '/' unary_expression
560 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
561 $$->set_location(yylloc);
563 | multiplicative_expression '%' unary_expression
566 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
567 $$->set_location(yylloc);
572 multiplicative_expression
573 | additive_expression '+' multiplicative_expression
576 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
577 $$->set_location(yylloc);
579 | additive_expression '-' multiplicative_expression
582 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
583 $$->set_location(yylloc);
589 | shift_expression LEFT_OP additive_expression
592 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
593 $$->set_location(yylloc);
595 | shift_expression RIGHT_OP additive_expression
598 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
599 $$->set_location(yylloc);
603 relational_expression:
605 | relational_expression '<' shift_expression
608 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
609 $$->set_location(yylloc);
611 | relational_expression '>' shift_expression
614 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
615 $$->set_location(yylloc);
617 | relational_expression LE_OP shift_expression
620 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
621 $$->set_location(yylloc);
623 | relational_expression GE_OP shift_expression
626 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
627 $$->set_location(yylloc);
632 relational_expression
633 | equality_expression EQ_OP relational_expression
636 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
637 $$->set_location(yylloc);
639 | equality_expression NE_OP relational_expression
642 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
643 $$->set_location(yylloc);
649 | and_expression '&' equality_expression
652 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
653 $$->set_location(yylloc);
657 exclusive_or_expression:
659 | exclusive_or_expression '^' and_expression
662 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
663 $$->set_location(yylloc);
667 inclusive_or_expression:
668 exclusive_or_expression
669 | inclusive_or_expression '|' exclusive_or_expression
672 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
673 $$->set_location(yylloc);
677 logical_and_expression:
678 inclusive_or_expression
679 | logical_and_expression AND_OP inclusive_or_expression
682 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
683 $$->set_location(yylloc);
687 logical_xor_expression:
688 logical_and_expression
689 | logical_xor_expression XOR_OP logical_and_expression
692 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
693 $$->set_location(yylloc);
697 logical_or_expression:
698 logical_xor_expression
699 | logical_or_expression OR_OP logical_xor_expression
702 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
703 $$->set_location(yylloc);
707 conditional_expression:
708 logical_or_expression
709 | logical_or_expression '?' expression ':' assignment_expression
712 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
713 $$->set_location(yylloc);
717 assignment_expression:
718 conditional_expression
719 | unary_expression assignment_operator assignment_expression
722 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
723 $$->set_location(yylloc);
728 '=' { $$ = ast_assign; }
729 | MUL_ASSIGN { $$ = ast_mul_assign; }
730 | DIV_ASSIGN { $$ = ast_div_assign; }
731 | MOD_ASSIGN { $$ = ast_mod_assign; }
732 | ADD_ASSIGN { $$ = ast_add_assign; }
733 | SUB_ASSIGN { $$ = ast_sub_assign; }
734 | LEFT_ASSIGN { $$ = ast_ls_assign; }
735 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
736 | AND_ASSIGN { $$ = ast_and_assign; }
737 | XOR_ASSIGN { $$ = ast_xor_assign; }
738 | OR_ASSIGN { $$ = ast_or_assign; }
742 assignment_expression
746 | expression ',' assignment_expression
749 if ($1->oper != ast_sequence) {
750 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
751 $$->set_location(yylloc);
752 $$->expressions.push_tail(& $1->link);
757 $$->expressions.push_tail(& $3->link);
762 conditional_expression
766 function_prototype ';'
768 state->symbols->pop_scope();
771 | init_declarator_list ';'
775 | PRECISION precision_qualifier type_specifier_no_prec ';'
778 $3->is_precision_statement = true;
784 function_declarator ')'
789 | function_header_with_parameters
792 function_header_with_parameters:
793 function_header parameter_declaration
796 $$->parameters.push_tail(& $2->link);
798 | function_header_with_parameters ',' parameter_declaration
801 $$->parameters.push_tail(& $3->link);
806 fully_specified_type variable_identifier '('
809 $$ = new(ctx) ast_function();
810 $$->set_location(yylloc);
811 $$->return_type = $1;
814 state->symbols->add_function(new(state) ir_function($2));
815 state->symbols->push_scope();
819 parameter_declarator:
820 type_specifier any_identifier
823 $$ = new(ctx) ast_parameter_declarator();
824 $$->set_location(yylloc);
825 $$->type = new(ctx) ast_fully_specified_type();
826 $$->type->set_location(yylloc);
827 $$->type->specifier = $1;
830 | type_specifier any_identifier '[' constant_expression ']'
833 $$ = new(ctx) ast_parameter_declarator();
834 $$->set_location(yylloc);
835 $$->type = new(ctx) ast_fully_specified_type();
836 $$->type->set_location(yylloc);
837 $$->type->specifier = $1;
844 parameter_declaration:
845 parameter_type_qualifier parameter_qualifier parameter_declarator
847 $1.flags.i |= $2.flags.i;
850 $$->type->qualifier = $1;
852 | parameter_qualifier parameter_declarator
855 $$->type->qualifier = $1;
857 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
860 $1.flags.i |= $2.flags.i;
862 $$ = new(ctx) ast_parameter_declarator();
863 $$->set_location(yylloc);
864 $$->type = new(ctx) ast_fully_specified_type();
865 $$->type->qualifier = $1;
866 $$->type->specifier = $3;
868 | parameter_qualifier parameter_type_specifier
871 $$ = new(ctx) ast_parameter_declarator();
872 $$->set_location(yylloc);
873 $$->type = new(ctx) ast_fully_specified_type();
874 $$->type->qualifier = $1;
875 $$->type->specifier = $2;
882 memset(& $$, 0, sizeof($$));
886 memset(& $$, 0, sizeof($$));
891 memset(& $$, 0, sizeof($$));
896 memset(& $$, 0, sizeof($$));
902 parameter_type_specifier:
906 init_declarator_list:
908 | init_declarator_list ',' any_identifier
911 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
912 decl->set_location(yylloc);
915 $$->declarations.push_tail(&decl->link);
916 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
918 | init_declarator_list ',' any_identifier '[' ']'
921 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
922 decl->set_location(yylloc);
925 $$->declarations.push_tail(&decl->link);
926 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
928 | init_declarator_list ',' any_identifier '[' constant_expression ']'
931 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
932 decl->set_location(yylloc);
935 $$->declarations.push_tail(&decl->link);
936 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
938 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
941 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
942 decl->set_location(yylloc);
945 $$->declarations.push_tail(&decl->link);
946 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
948 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
951 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
952 decl->set_location(yylloc);
955 $$->declarations.push_tail(&decl->link);
956 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
958 | init_declarator_list ',' any_identifier '=' initializer
961 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
962 decl->set_location(yylloc);
965 $$->declarations.push_tail(&decl->link);
966 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
970 // Grammar Note: No 'enum', or 'typedef'.
975 /* Empty declaration list is valid. */
976 $$ = new(ctx) ast_declarator_list($1);
977 $$->set_location(yylloc);
979 | fully_specified_type any_identifier
982 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
984 $$ = new(ctx) ast_declarator_list($1);
985 $$->set_location(yylloc);
986 $$->declarations.push_tail(&decl->link);
988 | fully_specified_type any_identifier '[' ']'
991 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
993 $$ = new(ctx) ast_declarator_list($1);
994 $$->set_location(yylloc);
995 $$->declarations.push_tail(&decl->link);
997 | fully_specified_type any_identifier '[' constant_expression ']'
1000 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1002 $$ = new(ctx) ast_declarator_list($1);
1003 $$->set_location(yylloc);
1004 $$->declarations.push_tail(&decl->link);
1006 | fully_specified_type any_identifier '[' ']' '=' initializer
1009 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1011 $$ = new(ctx) ast_declarator_list($1);
1012 $$->set_location(yylloc);
1013 $$->declarations.push_tail(&decl->link);
1015 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1018 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1020 $$ = new(ctx) ast_declarator_list($1);
1021 $$->set_location(yylloc);
1022 $$->declarations.push_tail(&decl->link);
1024 | fully_specified_type any_identifier '=' initializer
1027 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1029 $$ = new(ctx) ast_declarator_list($1);
1030 $$->set_location(yylloc);
1031 $$->declarations.push_tail(&decl->link);
1033 | INVARIANT variable_identifier // Vertex only.
1036 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1038 $$ = new(ctx) ast_declarator_list(NULL);
1039 $$->set_location(yylloc);
1040 $$->invariant = true;
1042 $$->declarations.push_tail(&decl->link);
1046 fully_specified_type:
1050 $$ = new(ctx) ast_fully_specified_type();
1051 $$->set_location(yylloc);
1054 | type_qualifier type_specifier
1057 $$ = new(ctx) ast_fully_specified_type();
1058 $$->set_location(yylloc);
1065 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1071 layout_qualifier_id_list:
1073 | layout_qualifier_id_list ',' layout_qualifier_id
1075 if (($1.flags.i & $3.flags.i) != 0) {
1076 _mesa_glsl_error(& @3, state,
1077 "duplicate layout qualifiers used\n");
1081 $$.flags.i = $1.flags.i | $3.flags.i;
1083 if ($1.flags.q.explicit_location)
1084 $$.location = $1.location;
1086 if ($3.flags.q.explicit_location)
1087 $$.location = $3.location;
1091 layout_qualifier_id:
1094 bool got_one = false;
1096 memset(& $$, 0, sizeof($$));
1098 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1099 if (!got_one && state->ARB_fragment_coord_conventions_enable) {
1100 if (strcmp($1, "origin_upper_left") == 0) {
1102 $$.flags.q.origin_upper_left = 1;
1103 } else if (strcmp($1, "pixel_center_integer") == 0) {
1105 $$.flags.q.pixel_center_integer = 1;
1108 if (got_one && state->ARB_fragment_coord_conventions_warn) {
1109 _mesa_glsl_warning(& @1, state,
1110 "GL_ARB_fragment_coord_conventions layout "
1111 "identifier `%s' used\n", $1);
1115 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1116 if (!got_one && state->AMD_conservative_depth_enable) {
1117 if (strcmp($1, "depth_any") == 0) {
1119 $$.flags.q.depth_any = 1;
1120 } else if (strcmp($1, "depth_greater") == 0) {
1122 $$.flags.q.depth_greater = 1;
1123 } else if (strcmp($1, "depth_less") == 0) {
1125 $$.flags.q.depth_less = 1;
1126 } else if (strcmp($1, "depth_unchanged") == 0) {
1128 $$.flags.q.depth_unchanged = 1;
1131 if (got_one && state->AMD_conservative_depth_warn) {
1132 _mesa_glsl_warning(& @1, state,
1133 "GL_ARB_conservative_depth "
1134 "layout qualifier `%s' is used\n", $1);
1139 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1144 | any_identifier '=' INTCONSTANT
1146 bool got_one = false;
1148 memset(& $$, 0, sizeof($$));
1150 if (state->ARB_explicit_attrib_location_enable) {
1151 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1152 * FINISHME: GLSL 1.30 (or later) are supported.
1154 if (strcmp("location", $1) == 0) {
1157 $$.flags.q.explicit_location = 1;
1162 _mesa_glsl_error(& @3, state,
1163 "invalid location %d specified\n", $3);
1169 /* If the identifier didn't match any known layout identifiers,
1173 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1176 } else if (state->ARB_explicit_attrib_location_warn) {
1177 _mesa_glsl_warning(& @1, state,
1178 "GL_ARB_explicit_attrib_location layout "
1179 "identifier `%s' used\n", $1);
1184 interpolation_qualifier:
1187 memset(& $$, 0, sizeof($$));
1188 $$.flags.q.smooth = 1;
1192 memset(& $$, 0, sizeof($$));
1193 $$.flags.q.flat = 1;
1197 memset(& $$, 0, sizeof($$));
1198 $$.flags.q.noperspective = 1;
1202 parameter_type_qualifier:
1205 memset(& $$, 0, sizeof($$));
1206 $$.flags.q.constant = 1;
1213 | layout_qualifier storage_qualifier
1216 $$.flags.i |= $2.flags.i;
1218 | interpolation_qualifier
1219 | interpolation_qualifier storage_qualifier
1222 $$.flags.i |= $2.flags.i;
1224 | INVARIANT storage_qualifier
1227 $$.flags.q.invariant = 1;
1229 | INVARIANT interpolation_qualifier storage_qualifier
1232 $$.flags.i |= $3.flags.i;
1233 $$.flags.q.invariant = 1;
1237 memset(& $$, 0, sizeof($$));
1238 $$.flags.q.invariant = 1;
1245 memset(& $$, 0, sizeof($$));
1246 $$.flags.q.constant = 1;
1250 memset(& $$, 0, sizeof($$));
1251 $$.flags.q.attribute = 1;
1255 memset(& $$, 0, sizeof($$));
1256 $$.flags.q.varying = 1;
1260 memset(& $$, 0, sizeof($$));
1261 $$.flags.q.centroid = 1;
1262 $$.flags.q.varying = 1;
1266 memset(& $$, 0, sizeof($$));
1271 memset(& $$, 0, sizeof($$));
1276 memset(& $$, 0, sizeof($$));
1277 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1281 memset(& $$, 0, sizeof($$));
1282 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1286 memset(& $$, 0, sizeof($$));
1287 $$.flags.q.uniform = 1;
1292 type_specifier_no_prec
1296 | precision_qualifier type_specifier_no_prec
1303 type_specifier_no_prec:
1304 type_specifier_nonarray
1305 | type_specifier_nonarray '[' ']'
1308 $$->is_array = true;
1309 $$->array_size = NULL;
1311 | type_specifier_nonarray '[' constant_expression ']'
1314 $$->is_array = true;
1315 $$->array_size = $3;
1319 type_specifier_nonarray:
1320 basic_type_specifier_nonarray
1323 $$ = new(ctx) ast_type_specifier($1);
1324 $$->set_location(yylloc);
1329 $$ = new(ctx) ast_type_specifier($1);
1330 $$->set_location(yylloc);
1335 $$ = new(ctx) ast_type_specifier($1);
1336 $$->set_location(yylloc);
1340 basic_type_specifier_nonarray:
1341 VOID_TOK { $$ = ast_void; }
1342 | FLOAT_TOK { $$ = ast_float; }
1343 | INT_TOK { $$ = ast_int; }
1344 | UINT_TOK { $$ = ast_uint; }
1345 | BOOL_TOK { $$ = ast_bool; }
1346 | VEC2 { $$ = ast_vec2; }
1347 | VEC3 { $$ = ast_vec3; }
1348 | VEC4 { $$ = ast_vec4; }
1349 | BVEC2 { $$ = ast_bvec2; }
1350 | BVEC3 { $$ = ast_bvec3; }
1351 | BVEC4 { $$ = ast_bvec4; }
1352 | IVEC2 { $$ = ast_ivec2; }
1353 | IVEC3 { $$ = ast_ivec3; }
1354 | IVEC4 { $$ = ast_ivec4; }
1355 | UVEC2 { $$ = ast_uvec2; }
1356 | UVEC3 { $$ = ast_uvec3; }
1357 | UVEC4 { $$ = ast_uvec4; }
1358 | MAT2X2 { $$ = ast_mat2; }
1359 | MAT2X3 { $$ = ast_mat2x3; }
1360 | MAT2X4 { $$ = ast_mat2x4; }
1361 | MAT3X2 { $$ = ast_mat3x2; }
1362 | MAT3X3 { $$ = ast_mat3; }
1363 | MAT3X4 { $$ = ast_mat3x4; }
1364 | MAT4X2 { $$ = ast_mat4x2; }
1365 | MAT4X3 { $$ = ast_mat4x3; }
1366 | MAT4X4 { $$ = ast_mat4; }
1367 | SAMPLER1D { $$ = ast_sampler1d; }
1368 | SAMPLER2D { $$ = ast_sampler2d; }
1369 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1370 | SAMPLER3D { $$ = ast_sampler3d; }
1371 | SAMPLERCUBE { $$ = ast_samplercube; }
1372 | SAMPLEREXTERNALOES { $$ = ast_samplerexternaloes; }
1373 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1374 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1375 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1376 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1377 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1378 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1379 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1380 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1381 | ISAMPLER1D { $$ = ast_isampler1d; }
1382 | ISAMPLER2D { $$ = ast_isampler2d; }
1383 | ISAMPLER3D { $$ = ast_isampler3d; }
1384 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1385 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1386 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1387 | USAMPLER1D { $$ = ast_usampler1d; }
1388 | USAMPLER2D { $$ = ast_usampler2d; }
1389 | USAMPLER3D { $$ = ast_usampler3d; }
1390 | USAMPLERCUBE { $$ = ast_usamplercube; }
1391 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1392 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1395 precision_qualifier:
1397 if (!state->es_shader && state->language_version < 130)
1398 _mesa_glsl_error(& @1, state,
1399 "precision qualifier forbidden "
1400 "in %s (1.30 or later "
1402 state->version_string);
1404 $$ = ast_precision_high;
1407 if (!state->es_shader && state->language_version < 130)
1408 _mesa_glsl_error(& @1, state,
1409 "precision qualifier forbidden "
1410 "in %s (1.30 or later "
1412 state->version_string);
1414 $$ = ast_precision_medium;
1417 if (!state->es_shader && state->language_version < 130)
1418 _mesa_glsl_error(& @1, state,
1419 "precision qualifier forbidden "
1420 "in %s (1.30 or later "
1422 state->version_string);
1424 $$ = ast_precision_low;
1429 STRUCT any_identifier '{' struct_declaration_list '}'
1432 $$ = new(ctx) ast_struct_specifier($2, $4);
1433 $$->set_location(yylloc);
1434 state->symbols->add_type($2, glsl_type::void_type);
1436 | STRUCT '{' struct_declaration_list '}'
1439 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1440 $$->set_location(yylloc);
1444 struct_declaration_list:
1447 $$ = (ast_node *) $1;
1448 $1->link.self_link();
1450 | struct_declaration_list struct_declaration
1452 $$ = (ast_node *) $1;
1453 $$->link.insert_before(& $2->link);
1458 type_specifier struct_declarator_list ';'
1461 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1462 type->set_location(yylloc);
1464 type->specifier = $1;
1465 $$ = new(ctx) ast_declarator_list(type);
1466 $$->set_location(yylloc);
1468 $$->declarations.push_degenerate_list_at_head(& $2->link);
1472 struct_declarator_list:
1476 $1->link.self_link();
1478 | struct_declarator_list ',' struct_declarator
1481 $$->link.insert_before(& $3->link);
1489 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1490 $$->set_location(yylloc);
1491 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1493 | any_identifier '[' constant_expression ']'
1496 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1497 $$->set_location(yylloc);
1502 assignment_expression
1505 declaration_statement:
1509 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1512 compound_statement { $$ = (ast_node *) $1; }
1517 declaration_statement
1518 | expression_statement
1519 | selection_statement
1520 | switch_statement { $$ = NULL; }
1521 | case_label { $$ = NULL; }
1522 | iteration_statement
1530 $$ = new(ctx) ast_compound_statement(true, NULL);
1531 $$->set_location(yylloc);
1535 state->symbols->push_scope();
1540 $$ = new(ctx) ast_compound_statement(true, $3);
1541 $$->set_location(yylloc);
1542 state->symbols->pop_scope();
1546 statement_no_new_scope:
1547 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1551 compound_statement_no_new_scope:
1555 $$ = new(ctx) ast_compound_statement(false, NULL);
1556 $$->set_location(yylloc);
1558 | '{' statement_list '}'
1561 $$ = new(ctx) ast_compound_statement(false, $2);
1562 $$->set_location(yylloc);
1570 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1575 $$->link.self_link();
1577 | statement_list statement
1580 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1584 $$->link.insert_before(& $2->link);
1588 expression_statement:
1592 $$ = new(ctx) ast_expression_statement(NULL);
1593 $$->set_location(yylloc);
1598 $$ = new(ctx) ast_expression_statement($1);
1599 $$->set_location(yylloc);
1603 selection_statement:
1604 IF '(' expression ')' selection_rest_statement
1606 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1608 $$->set_location(yylloc);
1612 selection_rest_statement:
1613 statement ELSE statement
1615 $$.then_statement = $1;
1616 $$.else_statement = $3;
1620 $$.then_statement = $1;
1621 $$.else_statement = NULL;
1628 $$ = (ast_node *) $1;
1630 | fully_specified_type any_identifier '=' initializer
1633 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1634 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1635 decl->set_location(yylloc);
1636 declarator->set_location(yylloc);
1638 declarator->declarations.push_tail(&decl->link);
1644 SWITCH '(' expression ')' compound_statement
1652 iteration_statement:
1653 WHILE '(' condition ')' statement_no_new_scope
1656 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1657 NULL, $3, NULL, $5);
1658 $$->set_location(yylloc);
1660 | DO statement WHILE '(' expression ')' ';'
1663 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1664 NULL, $5, NULL, $2);
1665 $$->set_location(yylloc);
1667 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1670 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1671 $3, $4.cond, $4.rest, $6);
1672 $$->set_location(yylloc);
1677 expression_statement
1678 | declaration_statement
1695 | conditionopt ';' expression
1702 // Grammar Note: No 'goto'. Gotos are not supported.
1707 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1708 $$->set_location(yylloc);
1713 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1714 $$->set_location(yylloc);
1719 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1720 $$->set_location(yylloc);
1722 | RETURN expression ';'
1725 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1726 $$->set_location(yylloc);
1728 | DISCARD ';' // Fragment shader only.
1731 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1732 $$->set_location(yylloc);
1736 external_declaration:
1737 function_definition { $$ = $1; }
1738 | declaration { $$ = $1; }
1739 | pragma_statement { $$ = NULL; }
1742 function_definition:
1743 function_prototype compound_statement_no_new_scope
1746 $$ = new(ctx) ast_function_definition();
1747 $$->set_location(yylloc);
1751 state->symbols->pop_scope();