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 /* Empty declaration list is valid. */
975 $$ = new(ctx) ast_declarator_list($1);
976 $$->set_location(yylloc);
978 | fully_specified_type any_identifier
981 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
983 $$ = new(ctx) ast_declarator_list($1);
984 $$->set_location(yylloc);
985 $$->declarations.push_tail(&decl->link);
987 | fully_specified_type any_identifier '[' ']'
990 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
992 $$ = new(ctx) ast_declarator_list($1);
993 $$->set_location(yylloc);
994 $$->declarations.push_tail(&decl->link);
996 | fully_specified_type any_identifier '[' constant_expression ']'
999 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1001 $$ = new(ctx) ast_declarator_list($1);
1002 $$->set_location(yylloc);
1003 $$->declarations.push_tail(&decl->link);
1005 | fully_specified_type any_identifier '[' ']' '=' initializer
1008 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1010 $$ = new(ctx) ast_declarator_list($1);
1011 $$->set_location(yylloc);
1012 $$->declarations.push_tail(&decl->link);
1014 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1017 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1019 $$ = new(ctx) ast_declarator_list($1);
1020 $$->set_location(yylloc);
1021 $$->declarations.push_tail(&decl->link);
1023 | fully_specified_type any_identifier '=' initializer
1026 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1028 $$ = new(ctx) ast_declarator_list($1);
1029 $$->set_location(yylloc);
1030 $$->declarations.push_tail(&decl->link);
1032 | INVARIANT variable_identifier // Vertex only.
1035 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1037 $$ = new(ctx) ast_declarator_list(NULL);
1038 $$->set_location(yylloc);
1039 $$->invariant = true;
1041 $$->declarations.push_tail(&decl->link);
1045 fully_specified_type:
1049 $$ = new(ctx) ast_fully_specified_type();
1050 $$->set_location(yylloc);
1053 | type_qualifier type_specifier
1056 $$ = new(ctx) ast_fully_specified_type();
1057 $$->set_location(yylloc);
1064 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1070 layout_qualifier_id_list:
1072 | layout_qualifier_id_list ',' layout_qualifier_id
1074 if (($1.flags.i & $3.flags.i) != 0) {
1075 _mesa_glsl_error(& @3, state,
1076 "duplicate layout qualifiers used\n");
1080 $$.flags.i = $1.flags.i | $3.flags.i;
1082 if ($1.flags.q.explicit_location)
1083 $$.location = $1.location;
1085 if ($3.flags.q.explicit_location)
1086 $$.location = $3.location;
1090 layout_qualifier_id:
1093 bool got_one = false;
1095 memset(& $$, 0, sizeof($$));
1097 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1098 if (!got_one && state->ARB_fragment_coord_conventions_enable) {
1099 if (strcmp($1, "origin_upper_left") == 0) {
1101 $$.flags.q.origin_upper_left = 1;
1102 } else if (strcmp($1, "pixel_center_integer") == 0) {
1104 $$.flags.q.pixel_center_integer = 1;
1107 if (got_one && state->ARB_fragment_coord_conventions_warn) {
1108 _mesa_glsl_warning(& @1, state,
1109 "GL_ARB_fragment_coord_conventions layout "
1110 "identifier `%s' used\n", $1);
1114 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1115 if (!got_one && state->AMD_conservative_depth_enable) {
1116 if (strcmp($1, "depth_any") == 0) {
1118 $$.flags.q.depth_any = 1;
1119 } else if (strcmp($1, "depth_greater") == 0) {
1121 $$.flags.q.depth_greater = 1;
1122 } else if (strcmp($1, "depth_less") == 0) {
1124 $$.flags.q.depth_less = 1;
1125 } else if (strcmp($1, "depth_unchanged") == 0) {
1127 $$.flags.q.depth_unchanged = 1;
1130 if (got_one && state->AMD_conservative_depth_warn) {
1131 _mesa_glsl_warning(& @1, state,
1132 "GL_ARB_conservative_depth "
1133 "layout qualifier `%s' is used\n", $1);
1138 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1143 | any_identifier '=' INTCONSTANT
1145 bool got_one = false;
1147 memset(& $$, 0, sizeof($$));
1149 if (state->ARB_explicit_attrib_location_enable) {
1150 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1151 * FINISHME: GLSL 1.30 (or later) are supported.
1153 if (strcmp("location", $1) == 0) {
1156 $$.flags.q.explicit_location = 1;
1161 _mesa_glsl_error(& @3, state,
1162 "invalid location %d specified\n", $3);
1168 /* If the identifier didn't match any known layout identifiers,
1172 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1175 } else if (state->ARB_explicit_attrib_location_warn) {
1176 _mesa_glsl_warning(& @1, state,
1177 "GL_ARB_explicit_attrib_location layout "
1178 "identifier `%s' used\n", $1);
1183 interpolation_qualifier:
1186 memset(& $$, 0, sizeof($$));
1187 $$.flags.q.smooth = 1;
1191 memset(& $$, 0, sizeof($$));
1192 $$.flags.q.flat = 1;
1196 memset(& $$, 0, sizeof($$));
1197 $$.flags.q.noperspective = 1;
1201 parameter_type_qualifier:
1204 memset(& $$, 0, sizeof($$));
1205 $$.flags.q.constant = 1;
1212 | layout_qualifier storage_qualifier
1215 $$.flags.i |= $2.flags.i;
1217 | interpolation_qualifier
1218 | interpolation_qualifier storage_qualifier
1221 $$.flags.i |= $2.flags.i;
1223 | INVARIANT storage_qualifier
1226 $$.flags.q.invariant = 1;
1228 | INVARIANT interpolation_qualifier storage_qualifier
1231 $$.flags.i |= $3.flags.i;
1232 $$.flags.q.invariant = 1;
1236 memset(& $$, 0, sizeof($$));
1237 $$.flags.q.invariant = 1;
1244 memset(& $$, 0, sizeof($$));
1245 $$.flags.q.constant = 1;
1249 memset(& $$, 0, sizeof($$));
1250 $$.flags.q.attribute = 1;
1254 memset(& $$, 0, sizeof($$));
1255 $$.flags.q.varying = 1;
1259 memset(& $$, 0, sizeof($$));
1260 $$.flags.q.centroid = 1;
1261 $$.flags.q.varying = 1;
1265 memset(& $$, 0, sizeof($$));
1270 memset(& $$, 0, sizeof($$));
1275 memset(& $$, 0, sizeof($$));
1276 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1280 memset(& $$, 0, sizeof($$));
1281 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1285 memset(& $$, 0, sizeof($$));
1286 $$.flags.q.uniform = 1;
1291 type_specifier_no_prec
1295 | precision_qualifier type_specifier_no_prec
1302 type_specifier_no_prec:
1303 type_specifier_nonarray
1304 | type_specifier_nonarray '[' ']'
1307 $$->is_array = true;
1308 $$->array_size = NULL;
1310 | type_specifier_nonarray '[' constant_expression ']'
1313 $$->is_array = true;
1314 $$->array_size = $3;
1318 type_specifier_nonarray:
1319 basic_type_specifier_nonarray
1322 $$ = new(ctx) ast_type_specifier($1);
1323 $$->set_location(yylloc);
1328 $$ = new(ctx) ast_type_specifier($1);
1329 $$->set_location(yylloc);
1334 $$ = new(ctx) ast_type_specifier($1);
1335 $$->set_location(yylloc);
1339 basic_type_specifier_nonarray:
1340 VOID_TOK { $$ = ast_void; }
1341 | FLOAT_TOK { $$ = ast_float; }
1342 | INT_TOK { $$ = ast_int; }
1343 | UINT_TOK { $$ = ast_uint; }
1344 | BOOL_TOK { $$ = ast_bool; }
1345 | VEC2 { $$ = ast_vec2; }
1346 | VEC3 { $$ = ast_vec3; }
1347 | VEC4 { $$ = ast_vec4; }
1348 | BVEC2 { $$ = ast_bvec2; }
1349 | BVEC3 { $$ = ast_bvec3; }
1350 | BVEC4 { $$ = ast_bvec4; }
1351 | IVEC2 { $$ = ast_ivec2; }
1352 | IVEC3 { $$ = ast_ivec3; }
1353 | IVEC4 { $$ = ast_ivec4; }
1354 | UVEC2 { $$ = ast_uvec2; }
1355 | UVEC3 { $$ = ast_uvec3; }
1356 | UVEC4 { $$ = ast_uvec4; }
1357 | MAT2X2 { $$ = ast_mat2; }
1358 | MAT2X3 { $$ = ast_mat2x3; }
1359 | MAT2X4 { $$ = ast_mat2x4; }
1360 | MAT3X2 { $$ = ast_mat3x2; }
1361 | MAT3X3 { $$ = ast_mat3; }
1362 | MAT3X4 { $$ = ast_mat3x4; }
1363 | MAT4X2 { $$ = ast_mat4x2; }
1364 | MAT4X3 { $$ = ast_mat4x3; }
1365 | MAT4X4 { $$ = ast_mat4; }
1366 | SAMPLER1D { $$ = ast_sampler1d; }
1367 | SAMPLER2D { $$ = ast_sampler2d; }
1368 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1369 | SAMPLER3D { $$ = ast_sampler3d; }
1370 | SAMPLERCUBE { $$ = ast_samplercube; }
1371 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1372 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1373 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1374 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1375 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1376 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1377 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1378 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1379 | ISAMPLER1D { $$ = ast_isampler1d; }
1380 | ISAMPLER2D { $$ = ast_isampler2d; }
1381 | ISAMPLER3D { $$ = ast_isampler3d; }
1382 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1383 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1384 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1385 | USAMPLER1D { $$ = ast_usampler1d; }
1386 | USAMPLER2D { $$ = ast_usampler2d; }
1387 | USAMPLER3D { $$ = ast_usampler3d; }
1388 | USAMPLERCUBE { $$ = ast_usamplercube; }
1389 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1390 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1393 precision_qualifier:
1395 if (!state->es_shader && state->language_version < 130)
1396 _mesa_glsl_error(& @1, state,
1397 "precision qualifier forbidden "
1398 "in %s (1.30 or later "
1400 state->version_string);
1402 $$ = ast_precision_high;
1405 if (!state->es_shader && state->language_version < 130)
1406 _mesa_glsl_error(& @1, state,
1407 "precision qualifier forbidden "
1408 "in %s (1.30 or later "
1410 state->version_string);
1412 $$ = ast_precision_medium;
1415 if (!state->es_shader && state->language_version < 130)
1416 _mesa_glsl_error(& @1, state,
1417 "precision qualifier forbidden "
1418 "in %s (1.30 or later "
1420 state->version_string);
1422 $$ = ast_precision_low;
1427 STRUCT any_identifier '{' struct_declaration_list '}'
1430 $$ = new(ctx) ast_struct_specifier($2, $4);
1431 $$->set_location(yylloc);
1432 state->symbols->add_type($2, glsl_type::void_type);
1434 | STRUCT '{' struct_declaration_list '}'
1437 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1438 $$->set_location(yylloc);
1442 struct_declaration_list:
1445 $$ = (ast_node *) $1;
1446 $1->link.self_link();
1448 | struct_declaration_list struct_declaration
1450 $$ = (ast_node *) $1;
1451 $$->link.insert_before(& $2->link);
1456 type_specifier struct_declarator_list ';'
1459 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1460 type->set_location(yylloc);
1462 type->specifier = $1;
1463 $$ = new(ctx) ast_declarator_list(type);
1464 $$->set_location(yylloc);
1466 $$->declarations.push_degenerate_list_at_head(& $2->link);
1470 struct_declarator_list:
1474 $1->link.self_link();
1476 | struct_declarator_list ',' struct_declarator
1479 $$->link.insert_before(& $3->link);
1487 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1488 $$->set_location(yylloc);
1489 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1491 | any_identifier '[' constant_expression ']'
1494 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1495 $$->set_location(yylloc);
1500 assignment_expression
1503 declaration_statement:
1507 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1510 compound_statement { $$ = (ast_node *) $1; }
1515 declaration_statement
1516 | expression_statement
1517 | selection_statement
1518 | switch_statement { $$ = NULL; }
1519 | case_label { $$ = NULL; }
1520 | iteration_statement
1528 $$ = new(ctx) ast_compound_statement(true, NULL);
1529 $$->set_location(yylloc);
1533 state->symbols->push_scope();
1538 $$ = new(ctx) ast_compound_statement(true, $3);
1539 $$->set_location(yylloc);
1540 state->symbols->pop_scope();
1544 statement_no_new_scope:
1545 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1549 compound_statement_no_new_scope:
1553 $$ = new(ctx) ast_compound_statement(false, NULL);
1554 $$->set_location(yylloc);
1556 | '{' statement_list '}'
1559 $$ = new(ctx) ast_compound_statement(false, $2);
1560 $$->set_location(yylloc);
1568 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1573 $$->link.self_link();
1575 | statement_list statement
1578 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1582 $$->link.insert_before(& $2->link);
1586 expression_statement:
1590 $$ = new(ctx) ast_expression_statement(NULL);
1591 $$->set_location(yylloc);
1596 $$ = new(ctx) ast_expression_statement($1);
1597 $$->set_location(yylloc);
1601 selection_statement:
1602 IF '(' expression ')' selection_rest_statement
1604 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1606 $$->set_location(yylloc);
1610 selection_rest_statement:
1611 statement ELSE statement
1613 $$.then_statement = $1;
1614 $$.else_statement = $3;
1618 $$.then_statement = $1;
1619 $$.else_statement = NULL;
1626 $$ = (ast_node *) $1;
1628 | fully_specified_type any_identifier '=' initializer
1631 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1632 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1633 decl->set_location(yylloc);
1634 declarator->set_location(yylloc);
1636 declarator->declarations.push_tail(&decl->link);
1642 SWITCH '(' expression ')' compound_statement
1650 iteration_statement:
1651 WHILE '(' condition ')' statement_no_new_scope
1654 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1655 NULL, $3, NULL, $5);
1656 $$->set_location(yylloc);
1658 | DO statement WHILE '(' expression ')' ';'
1661 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1662 NULL, $5, NULL, $2);
1663 $$->set_location(yylloc);
1665 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1668 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1669 $3, $4.cond, $4.rest, $6);
1670 $$->set_location(yylloc);
1675 expression_statement
1676 | declaration_statement
1693 | conditionopt ';' expression
1700 // Grammar Note: No 'goto'. Gotos are not supported.
1705 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1706 $$->set_location(yylloc);
1711 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1712 $$->set_location(yylloc);
1717 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1718 $$->set_location(yylloc);
1720 | RETURN expression ';'
1723 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1724 $$->set_location(yylloc);
1726 | DISCARD ';' // Fragment shader only.
1729 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1730 $$->set_location(yylloc);
1734 external_declaration:
1735 function_definition { $$ = $1; }
1736 | declaration { $$ = $1; }
1737 | pragma_statement { $$ = NULL; }
1740 function_definition:
1741 function_prototype compound_statement_no_new_scope
1744 $$ = new(ctx) ast_function_definition();
1745 $$->set_location(yylloc);
1749 state->symbols->pop_scope();