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 STRUCT VOID_TOK WHILE
96 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
97 %type <identifier> any_identifier
98 %token <real> FLOATCONSTANT
99 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
100 %token <identifier> FIELD_SELECTION
101 %token LEFT_OP RIGHT_OP
102 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
103 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
104 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
107 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
109 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
110 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
111 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
112 %token PRAGMA_INVARIANT_ALL
115 /* Reserved words that are not actually used in the grammar.
117 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
118 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
119 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
120 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
121 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
122 %token SIZEOF CAST NAMESPACE USING
126 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
127 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
128 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
129 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
130 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
131 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
134 %type <identifier> variable_identifier
135 %type <node> statement
136 %type <node> statement_list
137 %type <node> simple_statement
138 %type <n> precision_qualifier
139 %type <type_qualifier> type_qualifier
140 %type <type_qualifier> storage_qualifier
141 %type <type_qualifier> interpolation_qualifier
142 %type <type_qualifier> layout_qualifier
143 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
144 %type <type_specifier> type_specifier
145 %type <type_specifier> type_specifier_no_prec
146 %type <type_specifier> type_specifier_nonarray
147 %type <n> basic_type_specifier_nonarray
148 %type <fully_specified_type> fully_specified_type
149 %type <function> function_prototype
150 %type <function> function_header
151 %type <function> function_header_with_parameters
152 %type <function> function_declarator
153 %type <parameter_declarator> parameter_declarator
154 %type <parameter_declarator> parameter_declaration
155 %type <type_qualifier> parameter_qualifier
156 %type <type_qualifier> parameter_type_qualifier
157 %type <type_specifier> parameter_type_specifier
158 %type <function_definition> function_definition
159 %type <compound_statement> compound_statement_no_new_scope
160 %type <compound_statement> compound_statement
161 %type <node> statement_no_new_scope
162 %type <node> expression_statement
163 %type <expression> expression
164 %type <expression> primary_expression
165 %type <expression> assignment_expression
166 %type <expression> conditional_expression
167 %type <expression> logical_or_expression
168 %type <expression> logical_xor_expression
169 %type <expression> logical_and_expression
170 %type <expression> inclusive_or_expression
171 %type <expression> exclusive_or_expression
172 %type <expression> and_expression
173 %type <expression> equality_expression
174 %type <expression> relational_expression
175 %type <expression> shift_expression
176 %type <expression> additive_expression
177 %type <expression> multiplicative_expression
178 %type <expression> unary_expression
179 %type <expression> constant_expression
180 %type <expression> integer_expression
181 %type <expression> postfix_expression
182 %type <expression> function_call_header_with_parameters
183 %type <expression> function_call_header_no_parameters
184 %type <expression> function_call_header
185 %type <expression> function_call_generic
186 %type <expression> function_call_or_method
187 %type <expression> function_call
188 %type <expression> method_call_generic
189 %type <expression> method_call_header_with_parameters
190 %type <expression> method_call_header_no_parameters
191 %type <expression> method_call_header
192 %type <n> assignment_operator
193 %type <n> unary_operator
194 %type <expression> function_identifier
195 %type <node> external_declaration
196 %type <declarator_list> init_declarator_list
197 %type <declarator_list> single_declaration
198 %type <expression> initializer
199 %type <node> declaration
200 %type <node> declaration_statement
201 %type <node> jump_statement
202 %type <struct_specifier> struct_specifier
203 %type <node> struct_declaration_list
204 %type <declarator_list> struct_declaration
205 %type <declaration> struct_declarator
206 %type <declaration> struct_declarator_list
207 %type <node> selection_statement
208 %type <selection_rest_statement> selection_rest_statement
209 %type <node> iteration_statement
210 %type <node> condition
211 %type <node> conditionopt
212 %type <node> for_init_statement
213 %type <for_rest_statement> for_rest_statement
217 version_statement extension_statement_list
219 _mesa_glsl_initialize_types(state);
221 external_declaration_list
223 delete state->symbols;
224 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
225 _mesa_glsl_initialize_types(state);
230 /* blank - no #version specified: defaults are already set */
231 | VERSION INTCONSTANT EOL
233 bool supported = false;
237 state->es_shader = true;
238 supported = state->Const.GLSL_100ES;
241 supported = state->Const.GLSL_110;
244 supported = state->Const.GLSL_120;
247 supported = state->Const.GLSL_130;
254 state->language_version = $2;
255 state->version_string =
256 ralloc_asprintf(state, "GLSL%s %d.%02d",
257 state->es_shader ? " ES" : "",
258 state->language_version / 100,
259 state->language_version % 100);
262 _mesa_glsl_error(& @2, state, "%s is not supported. "
263 "Supported versions are: %s\n",
264 state->version_string,
265 state->supported_version_string);
272 | PRAGMA_DEBUG_OFF EOL
273 | PRAGMA_OPTIMIZE_ON EOL
274 | PRAGMA_OPTIMIZE_OFF EOL
275 | PRAGMA_INVARIANT_ALL EOL
277 if (state->language_version < 120) {
278 _mesa_glsl_warning(& @1, state,
279 "pragma `invariant(all)' not supported in %s",
280 state->version_string);
282 state->all_invariant = true;
287 extension_statement_list:
289 | extension_statement_list extension_statement
299 EXTENSION any_identifier COLON any_identifier EOL
301 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
307 external_declaration_list:
310 /* FINISHME: The NULL test is required because pragmas are set to
311 * FINISHME: NULL. (See production rule for external_declaration.)
314 state->translation_unit.push_tail(& $1->link);
316 | external_declaration_list external_declaration
318 /* FINISHME: The NULL test is required because pragmas are set to
319 * FINISHME: NULL. (See production rule for external_declaration.)
322 state->translation_unit.push_tail(& $2->link);
335 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
336 $$->set_location(yylloc);
337 $$->primary_expression.identifier = $1;
342 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
343 $$->set_location(yylloc);
344 $$->primary_expression.int_constant = $1;
349 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
350 $$->set_location(yylloc);
351 $$->primary_expression.uint_constant = $1;
356 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
357 $$->set_location(yylloc);
358 $$->primary_expression.float_constant = $1;
363 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
364 $$->set_location(yylloc);
365 $$->primary_expression.bool_constant = $1;
375 | postfix_expression '[' integer_expression ']'
378 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
379 $$->set_location(yylloc);
385 | postfix_expression '.' any_identifier
388 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
389 $$->set_location(yylloc);
390 $$->primary_expression.identifier = $3;
392 | postfix_expression INC_OP
395 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
396 $$->set_location(yylloc);
398 | postfix_expression DEC_OP
401 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
402 $$->set_location(yylloc);
411 function_call_or_method
414 function_call_or_method:
415 function_call_generic
416 | postfix_expression '.' method_call_generic
419 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
420 $$->set_location(yylloc);
424 function_call_generic:
425 function_call_header_with_parameters ')'
426 | function_call_header_no_parameters ')'
429 function_call_header_no_parameters:
430 function_call_header VOID_TOK
431 | function_call_header
434 function_call_header_with_parameters:
435 function_call_header assignment_expression
438 $$->set_location(yylloc);
439 $$->expressions.push_tail(& $2->link);
441 | function_call_header_with_parameters ',' assignment_expression
444 $$->set_location(yylloc);
445 $$->expressions.push_tail(& $3->link);
449 // Grammar Note: Constructors look like functions, but lexical
450 // analysis recognized most of them as keywords. They are now
451 // recognized through "type_specifier".
452 function_call_header:
453 function_identifier '('
460 $$ = new(ctx) ast_function_expression($1);
461 $$->set_location(yylloc);
463 | variable_identifier
466 ast_expression *callee = new(ctx) ast_expression($1);
467 $$ = new(ctx) ast_function_expression(callee);
468 $$->set_location(yylloc);
473 ast_expression *callee = new(ctx) ast_expression($1);
474 $$ = new(ctx) ast_function_expression(callee);
475 $$->set_location(yylloc);
480 method_call_header_with_parameters ')'
481 | method_call_header_no_parameters ')'
484 method_call_header_no_parameters:
485 method_call_header VOID_TOK
489 method_call_header_with_parameters:
490 method_call_header assignment_expression
493 $$->set_location(yylloc);
494 $$->expressions.push_tail(& $2->link);
496 | method_call_header_with_parameters ',' assignment_expression
499 $$->set_location(yylloc);
500 $$->expressions.push_tail(& $3->link);
504 // Grammar Note: Constructors look like methods, but lexical
505 // analysis recognized most of them as keywords. They are now
506 // recognized through "type_specifier".
508 variable_identifier '('
511 ast_expression *callee = new(ctx) ast_expression($1);
512 $$ = new(ctx) ast_function_expression(callee);
513 $$->set_location(yylloc);
517 // Grammar Note: No traditional style type casts.
520 | INC_OP unary_expression
523 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
524 $$->set_location(yylloc);
526 | DEC_OP unary_expression
529 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
530 $$->set_location(yylloc);
532 | unary_operator unary_expression
535 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
536 $$->set_location(yylloc);
540 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
542 '+' { $$ = ast_plus; }
543 | '-' { $$ = ast_neg; }
544 | '!' { $$ = ast_logic_not; }
545 | '~' { $$ = ast_bit_not; }
548 multiplicative_expression:
550 | multiplicative_expression '*' unary_expression
553 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
554 $$->set_location(yylloc);
556 | multiplicative_expression '/' unary_expression
559 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
560 $$->set_location(yylloc);
562 | multiplicative_expression '%' unary_expression
565 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
566 $$->set_location(yylloc);
571 multiplicative_expression
572 | additive_expression '+' multiplicative_expression
575 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
576 $$->set_location(yylloc);
578 | additive_expression '-' multiplicative_expression
581 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
582 $$->set_location(yylloc);
588 | shift_expression LEFT_OP additive_expression
591 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
592 $$->set_location(yylloc);
594 | shift_expression RIGHT_OP additive_expression
597 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
598 $$->set_location(yylloc);
602 relational_expression:
604 | relational_expression '<' shift_expression
607 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
608 $$->set_location(yylloc);
610 | relational_expression '>' shift_expression
613 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
614 $$->set_location(yylloc);
616 | relational_expression LE_OP shift_expression
619 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
620 $$->set_location(yylloc);
622 | relational_expression GE_OP shift_expression
625 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
626 $$->set_location(yylloc);
631 relational_expression
632 | equality_expression EQ_OP relational_expression
635 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
636 $$->set_location(yylloc);
638 | equality_expression NE_OP relational_expression
641 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
642 $$->set_location(yylloc);
648 | and_expression '&' equality_expression
651 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
652 $$->set_location(yylloc);
656 exclusive_or_expression:
658 | exclusive_or_expression '^' and_expression
661 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
662 $$->set_location(yylloc);
666 inclusive_or_expression:
667 exclusive_or_expression
668 | inclusive_or_expression '|' exclusive_or_expression
671 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
672 $$->set_location(yylloc);
676 logical_and_expression:
677 inclusive_or_expression
678 | logical_and_expression AND_OP inclusive_or_expression
681 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
682 $$->set_location(yylloc);
686 logical_xor_expression:
687 logical_and_expression
688 | logical_xor_expression XOR_OP logical_and_expression
691 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
692 $$->set_location(yylloc);
696 logical_or_expression:
697 logical_xor_expression
698 | logical_or_expression OR_OP logical_xor_expression
701 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
702 $$->set_location(yylloc);
706 conditional_expression:
707 logical_or_expression
708 | logical_or_expression '?' expression ':' assignment_expression
711 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
712 $$->set_location(yylloc);
716 assignment_expression:
717 conditional_expression
718 | unary_expression assignment_operator assignment_expression
721 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
722 $$->set_location(yylloc);
727 '=' { $$ = ast_assign; }
728 | MUL_ASSIGN { $$ = ast_mul_assign; }
729 | DIV_ASSIGN { $$ = ast_div_assign; }
730 | MOD_ASSIGN { $$ = ast_mod_assign; }
731 | ADD_ASSIGN { $$ = ast_add_assign; }
732 | SUB_ASSIGN { $$ = ast_sub_assign; }
733 | LEFT_ASSIGN { $$ = ast_ls_assign; }
734 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
735 | AND_ASSIGN { $$ = ast_and_assign; }
736 | XOR_ASSIGN { $$ = ast_xor_assign; }
737 | OR_ASSIGN { $$ = ast_or_assign; }
741 assignment_expression
745 | expression ',' assignment_expression
748 if ($1->oper != ast_sequence) {
749 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
750 $$->set_location(yylloc);
751 $$->expressions.push_tail(& $1->link);
756 $$->expressions.push_tail(& $3->link);
761 conditional_expression
765 function_prototype ';'
767 state->symbols->pop_scope();
770 | init_declarator_list ';'
774 | PRECISION precision_qualifier type_specifier_no_prec ';'
777 $3->is_precision_statement = true;
783 function_declarator ')'
788 | function_header_with_parameters
791 function_header_with_parameters:
792 function_header parameter_declaration
795 $$->parameters.push_tail(& $2->link);
797 | function_header_with_parameters ',' parameter_declaration
800 $$->parameters.push_tail(& $3->link);
805 fully_specified_type variable_identifier '('
808 $$ = new(ctx) ast_function();
809 $$->set_location(yylloc);
810 $$->return_type = $1;
813 state->symbols->add_function(new(state) ir_function($2));
814 state->symbols->push_scope();
818 parameter_declarator:
819 type_specifier any_identifier
822 $$ = new(ctx) ast_parameter_declarator();
823 $$->set_location(yylloc);
824 $$->type = new(ctx) ast_fully_specified_type();
825 $$->type->set_location(yylloc);
826 $$->type->specifier = $1;
829 | type_specifier any_identifier '[' constant_expression ']'
832 $$ = new(ctx) ast_parameter_declarator();
833 $$->set_location(yylloc);
834 $$->type = new(ctx) ast_fully_specified_type();
835 $$->type->set_location(yylloc);
836 $$->type->specifier = $1;
843 parameter_declaration:
844 parameter_type_qualifier parameter_qualifier parameter_declarator
846 $1.flags.i |= $2.flags.i;
849 $$->type->qualifier = $1;
851 | parameter_qualifier parameter_declarator
854 $$->type->qualifier = $1;
856 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
859 $1.flags.i |= $2.flags.i;
861 $$ = new(ctx) ast_parameter_declarator();
862 $$->set_location(yylloc);
863 $$->type = new(ctx) ast_fully_specified_type();
864 $$->type->qualifier = $1;
865 $$->type->specifier = $3;
867 | parameter_qualifier parameter_type_specifier
870 $$ = new(ctx) ast_parameter_declarator();
871 $$->set_location(yylloc);
872 $$->type = new(ctx) ast_fully_specified_type();
873 $$->type->qualifier = $1;
874 $$->type->specifier = $2;
881 memset(& $$, 0, sizeof($$));
885 memset(& $$, 0, sizeof($$));
890 memset(& $$, 0, sizeof($$));
895 memset(& $$, 0, sizeof($$));
901 parameter_type_specifier:
905 init_declarator_list:
907 | init_declarator_list ',' any_identifier
910 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
911 decl->set_location(yylloc);
914 $$->declarations.push_tail(&decl->link);
915 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
917 | init_declarator_list ',' any_identifier '[' ']'
920 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
921 decl->set_location(yylloc);
924 $$->declarations.push_tail(&decl->link);
925 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
927 | init_declarator_list ',' any_identifier '[' constant_expression ']'
930 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
931 decl->set_location(yylloc);
934 $$->declarations.push_tail(&decl->link);
935 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
937 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
940 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
941 decl->set_location(yylloc);
944 $$->declarations.push_tail(&decl->link);
945 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
947 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
950 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
951 decl->set_location(yylloc);
954 $$->declarations.push_tail(&decl->link);
955 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
957 | init_declarator_list ',' any_identifier '=' initializer
960 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
961 decl->set_location(yylloc);
964 $$->declarations.push_tail(&decl->link);
965 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
969 // Grammar Note: No 'enum', or 'typedef'.
974 if ($1->specifier->type_specifier != ast_struct) {
975 _mesa_glsl_error(& @1, state, "empty declaration list\n");
978 $$ = new(ctx) ast_declarator_list($1);
979 $$->set_location(yylloc);
982 | fully_specified_type any_identifier
985 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
987 $$ = new(ctx) ast_declarator_list($1);
988 $$->set_location(yylloc);
989 $$->declarations.push_tail(&decl->link);
991 | fully_specified_type any_identifier '[' ']'
994 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
996 $$ = new(ctx) ast_declarator_list($1);
997 $$->set_location(yylloc);
998 $$->declarations.push_tail(&decl->link);
1000 | fully_specified_type any_identifier '[' constant_expression ']'
1003 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1005 $$ = new(ctx) ast_declarator_list($1);
1006 $$->set_location(yylloc);
1007 $$->declarations.push_tail(&decl->link);
1009 | fully_specified_type any_identifier '[' ']' '=' initializer
1012 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1014 $$ = new(ctx) ast_declarator_list($1);
1015 $$->set_location(yylloc);
1016 $$->declarations.push_tail(&decl->link);
1018 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1021 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1023 $$ = new(ctx) ast_declarator_list($1);
1024 $$->set_location(yylloc);
1025 $$->declarations.push_tail(&decl->link);
1027 | fully_specified_type any_identifier '=' initializer
1030 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1032 $$ = new(ctx) ast_declarator_list($1);
1033 $$->set_location(yylloc);
1034 $$->declarations.push_tail(&decl->link);
1036 | INVARIANT variable_identifier // Vertex only.
1039 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1041 $$ = new(ctx) ast_declarator_list(NULL);
1042 $$->set_location(yylloc);
1043 $$->invariant = true;
1045 $$->declarations.push_tail(&decl->link);
1049 fully_specified_type:
1053 $$ = new(ctx) ast_fully_specified_type();
1054 $$->set_location(yylloc);
1057 | type_qualifier type_specifier
1060 $$ = new(ctx) ast_fully_specified_type();
1061 $$->set_location(yylloc);
1068 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1074 layout_qualifier_id_list:
1076 | layout_qualifier_id_list ',' layout_qualifier_id
1078 if (($1.flags.i & $3.flags.i) != 0) {
1079 _mesa_glsl_error(& @3, state,
1080 "duplicate layout qualifiers used\n");
1084 $$.flags.i = $1.flags.i | $3.flags.i;
1086 if ($1.flags.q.explicit_location)
1087 $$.location = $1.location;
1089 if ($3.flags.q.explicit_location)
1090 $$.location = $3.location;
1094 layout_qualifier_id:
1097 bool got_one = false;
1099 memset(& $$, 0, sizeof($$));
1101 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1102 if (!got_one && state->ARB_fragment_coord_conventions_enable) {
1103 if (strcmp($1, "origin_upper_left") == 0) {
1105 $$.flags.q.origin_upper_left = 1;
1106 } else if (strcmp($1, "pixel_center_integer") == 0) {
1108 $$.flags.q.pixel_center_integer = 1;
1111 if (got_one && state->ARB_fragment_coord_conventions_warn) {
1112 _mesa_glsl_warning(& @1, state,
1113 "GL_ARB_fragment_coord_conventions layout "
1114 "identifier `%s' used\n", $1);
1118 /* Layout qualifiers for AMD_conservative_depth. */
1119 if (!got_one && state->AMD_conservative_depth_enable) {
1120 if (strcmp($1, "depth_any") == 0) {
1122 $$.flags.q.depth_any = 1;
1123 } else if (strcmp($1, "depth_greater") == 0) {
1125 $$.flags.q.depth_greater = 1;
1126 } else if (strcmp($1, "depth_less") == 0) {
1128 $$.flags.q.depth_less = 1;
1129 } else if (strcmp($1, "depth_unchanged") == 0) {
1131 $$.flags.q.depth_unchanged = 1;
1134 if (got_one && state->AMD_conservative_depth_warn) {
1135 _mesa_glsl_warning(& @1, state,
1136 "GL_AMD_conservative_depth "
1137 "layout qualifier `%s' is used\n", $1);
1142 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1147 | any_identifier '=' INTCONSTANT
1149 bool got_one = false;
1151 memset(& $$, 0, sizeof($$));
1153 if (state->ARB_explicit_attrib_location_enable) {
1154 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1155 * FINISHME: GLSL 1.30 (or later) are supported.
1157 if (strcmp("location", $1) == 0) {
1160 $$.flags.q.explicit_location = 1;
1165 _mesa_glsl_error(& @3, state,
1166 "invalid location %d specified\n", $3);
1172 /* If the identifier didn't match any known layout identifiers,
1176 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1179 } else if (state->ARB_explicit_attrib_location_warn) {
1180 _mesa_glsl_warning(& @1, state,
1181 "GL_ARB_explicit_attrib_location layout "
1182 "identifier `%s' used\n", $1);
1187 interpolation_qualifier:
1190 memset(& $$, 0, sizeof($$));
1191 $$.flags.q.smooth = 1;
1195 memset(& $$, 0, sizeof($$));
1196 $$.flags.q.flat = 1;
1200 memset(& $$, 0, sizeof($$));
1201 $$.flags.q.noperspective = 1;
1205 parameter_type_qualifier:
1208 memset(& $$, 0, sizeof($$));
1209 $$.flags.q.constant = 1;
1216 | layout_qualifier storage_qualifier
1219 $$.flags.i |= $2.flags.i;
1221 | interpolation_qualifier
1222 | interpolation_qualifier storage_qualifier
1225 $$.flags.i |= $2.flags.i;
1227 | INVARIANT storage_qualifier
1230 $$.flags.q.invariant = 1;
1232 | INVARIANT interpolation_qualifier storage_qualifier
1235 $$.flags.i |= $3.flags.i;
1236 $$.flags.q.invariant = 1;
1240 memset(& $$, 0, sizeof($$));
1241 $$.flags.q.invariant = 1;
1248 memset(& $$, 0, sizeof($$));
1249 $$.flags.q.constant = 1;
1253 memset(& $$, 0, sizeof($$));
1254 $$.flags.q.attribute = 1;
1258 memset(& $$, 0, sizeof($$));
1259 $$.flags.q.varying = 1;
1263 memset(& $$, 0, sizeof($$));
1264 $$.flags.q.centroid = 1;
1265 $$.flags.q.varying = 1;
1269 memset(& $$, 0, sizeof($$));
1274 memset(& $$, 0, sizeof($$));
1279 memset(& $$, 0, sizeof($$));
1280 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1284 memset(& $$, 0, sizeof($$));
1285 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1289 memset(& $$, 0, sizeof($$));
1290 $$.flags.q.uniform = 1;
1295 type_specifier_no_prec
1299 | precision_qualifier type_specifier_no_prec
1306 type_specifier_no_prec:
1307 type_specifier_nonarray
1308 | type_specifier_nonarray '[' ']'
1311 $$->is_array = true;
1312 $$->array_size = NULL;
1314 | type_specifier_nonarray '[' constant_expression ']'
1317 $$->is_array = true;
1318 $$->array_size = $3;
1322 type_specifier_nonarray:
1323 basic_type_specifier_nonarray
1326 $$ = new(ctx) ast_type_specifier($1);
1327 $$->set_location(yylloc);
1332 $$ = new(ctx) ast_type_specifier($1);
1333 $$->set_location(yylloc);
1338 $$ = new(ctx) ast_type_specifier($1);
1339 $$->set_location(yylloc);
1343 basic_type_specifier_nonarray:
1344 VOID_TOK { $$ = ast_void; }
1345 | FLOAT_TOK { $$ = ast_float; }
1346 | INT_TOK { $$ = ast_int; }
1347 | UINT_TOK { $$ = ast_uint; }
1348 | BOOL_TOK { $$ = ast_bool; }
1349 | VEC2 { $$ = ast_vec2; }
1350 | VEC3 { $$ = ast_vec3; }
1351 | VEC4 { $$ = ast_vec4; }
1352 | BVEC2 { $$ = ast_bvec2; }
1353 | BVEC3 { $$ = ast_bvec3; }
1354 | BVEC4 { $$ = ast_bvec4; }
1355 | IVEC2 { $$ = ast_ivec2; }
1356 | IVEC3 { $$ = ast_ivec3; }
1357 | IVEC4 { $$ = ast_ivec4; }
1358 | UVEC2 { $$ = ast_uvec2; }
1359 | UVEC3 { $$ = ast_uvec3; }
1360 | UVEC4 { $$ = ast_uvec4; }
1361 | MAT2X2 { $$ = ast_mat2; }
1362 | MAT2X3 { $$ = ast_mat2x3; }
1363 | MAT2X4 { $$ = ast_mat2x4; }
1364 | MAT3X2 { $$ = ast_mat3x2; }
1365 | MAT3X3 { $$ = ast_mat3; }
1366 | MAT3X4 { $$ = ast_mat3x4; }
1367 | MAT4X2 { $$ = ast_mat4x2; }
1368 | MAT4X3 { $$ = ast_mat4x3; }
1369 | MAT4X4 { $$ = ast_mat4; }
1370 | SAMPLER1D { $$ = ast_sampler1d; }
1371 | SAMPLER2D { $$ = ast_sampler2d; }
1372 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1373 | SAMPLER3D { $$ = ast_sampler3d; }
1374 | SAMPLERCUBE { $$ = ast_samplercube; }
1375 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1376 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1377 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1378 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1379 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1380 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1381 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1382 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1383 | ISAMPLER1D { $$ = ast_isampler1d; }
1384 | ISAMPLER2D { $$ = ast_isampler2d; }
1385 | ISAMPLER3D { $$ = ast_isampler3d; }
1386 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1387 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1388 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1389 | USAMPLER1D { $$ = ast_usampler1d; }
1390 | USAMPLER2D { $$ = ast_usampler2d; }
1391 | USAMPLER3D { $$ = ast_usampler3d; }
1392 | USAMPLERCUBE { $$ = ast_usamplercube; }
1393 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1394 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1397 precision_qualifier:
1399 if (!state->es_shader && state->language_version < 130)
1400 _mesa_glsl_error(& @1, state,
1401 "precision qualifier forbidden "
1402 "in %s (1.30 or later "
1404 state->version_string);
1406 $$ = ast_precision_high;
1409 if (!state->es_shader && state->language_version < 130)
1410 _mesa_glsl_error(& @1, state,
1411 "precision qualifier forbidden "
1412 "in %s (1.30 or later "
1414 state->version_string);
1416 $$ = ast_precision_medium;
1419 if (!state->es_shader && state->language_version < 130)
1420 _mesa_glsl_error(& @1, state,
1421 "precision qualifier forbidden "
1422 "in %s (1.30 or later "
1424 state->version_string);
1426 $$ = ast_precision_low;
1431 STRUCT any_identifier '{' struct_declaration_list '}'
1434 $$ = new(ctx) ast_struct_specifier($2, $4);
1435 $$->set_location(yylloc);
1436 state->symbols->add_type($2, glsl_type::void_type);
1438 | STRUCT '{' struct_declaration_list '}'
1441 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1442 $$->set_location(yylloc);
1446 struct_declaration_list:
1449 $$ = (ast_node *) $1;
1450 $1->link.self_link();
1452 | struct_declaration_list struct_declaration
1454 $$ = (ast_node *) $1;
1455 $$->link.insert_before(& $2->link);
1460 type_specifier struct_declarator_list ';'
1463 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1464 type->set_location(yylloc);
1466 type->specifier = $1;
1467 $$ = new(ctx) ast_declarator_list(type);
1468 $$->set_location(yylloc);
1470 $$->declarations.push_degenerate_list_at_head(& $2->link);
1474 struct_declarator_list:
1478 $1->link.self_link();
1480 | struct_declarator_list ',' struct_declarator
1483 $$->link.insert_before(& $3->link);
1491 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1492 $$->set_location(yylloc);
1493 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1495 | any_identifier '[' constant_expression ']'
1498 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1499 $$->set_location(yylloc);
1504 assignment_expression
1507 declaration_statement:
1511 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1514 compound_statement { $$ = (ast_node *) $1; }
1519 declaration_statement
1520 | expression_statement
1521 | selection_statement
1522 | switch_statement { $$ = NULL; }
1523 | case_label { $$ = NULL; }
1524 | iteration_statement
1532 $$ = new(ctx) ast_compound_statement(true, NULL);
1533 $$->set_location(yylloc);
1537 state->symbols->push_scope();
1542 $$ = new(ctx) ast_compound_statement(true, $3);
1543 $$->set_location(yylloc);
1544 state->symbols->pop_scope();
1548 statement_no_new_scope:
1549 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1553 compound_statement_no_new_scope:
1557 $$ = new(ctx) ast_compound_statement(false, NULL);
1558 $$->set_location(yylloc);
1560 | '{' statement_list '}'
1563 $$ = new(ctx) ast_compound_statement(false, $2);
1564 $$->set_location(yylloc);
1572 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1577 $$->link.self_link();
1579 | statement_list statement
1582 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1586 $$->link.insert_before(& $2->link);
1590 expression_statement:
1594 $$ = new(ctx) ast_expression_statement(NULL);
1595 $$->set_location(yylloc);
1600 $$ = new(ctx) ast_expression_statement($1);
1601 $$->set_location(yylloc);
1605 selection_statement:
1606 IF '(' expression ')' selection_rest_statement
1608 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1610 $$->set_location(yylloc);
1614 selection_rest_statement:
1615 statement ELSE statement
1617 $$.then_statement = $1;
1618 $$.else_statement = $3;
1622 $$.then_statement = $1;
1623 $$.else_statement = NULL;
1630 $$ = (ast_node *) $1;
1632 | fully_specified_type any_identifier '=' initializer
1635 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1636 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1637 decl->set_location(yylloc);
1638 declarator->set_location(yylloc);
1640 declarator->declarations.push_tail(&decl->link);
1646 SWITCH '(' expression ')' compound_statement
1654 iteration_statement:
1655 WHILE '(' condition ')' statement_no_new_scope
1658 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1659 NULL, $3, NULL, $5);
1660 $$->set_location(yylloc);
1662 | DO statement WHILE '(' expression ')' ';'
1665 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1666 NULL, $5, NULL, $2);
1667 $$->set_location(yylloc);
1669 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1672 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1673 $3, $4.cond, $4.rest, $6);
1674 $$->set_location(yylloc);
1679 expression_statement
1680 | declaration_statement
1697 | conditionopt ';' expression
1704 // Grammar Note: No 'goto'. Gotos are not supported.
1709 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1710 $$->set_location(yylloc);
1715 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1716 $$->set_location(yylloc);
1721 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1722 $$->set_location(yylloc);
1724 | RETURN expression ';'
1727 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1728 $$->set_location(yylloc);
1730 | DISCARD ';' // Fragment shader only.
1733 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1734 $$->set_location(yylloc);
1738 external_declaration:
1739 function_definition { $$ = $1; }
1740 | declaration { $$ = $1; }
1741 | pragma_statement { $$ = NULL; }
1744 function_definition:
1745 function_prototype compound_statement_no_new_scope
1748 $$ = new(ctx) ast_function_definition();
1749 $$->set_location(yylloc);
1753 state->symbols->pop_scope();