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
37 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
39 _mesa_glsl_error(loc, st, "%s", msg);
55 %lex-param {void *scanner}
56 %parse-param {struct _mesa_glsl_parse_state *state}
61 const char *identifier;
63 struct ast_type_qualifier type_qualifier;
66 ast_type_specifier *type_specifier;
67 ast_fully_specified_type *fully_specified_type;
68 ast_function *function;
69 ast_parameter_declarator *parameter_declarator;
70 ast_function_definition *function_definition;
71 ast_compound_statement *compound_statement;
72 ast_expression *expression;
73 ast_declarator_list *declarator_list;
74 ast_struct_specifier *struct_specifier;
75 ast_declaration *declaration;
76 ast_switch_body *switch_body;
77 ast_case_label *case_label;
78 ast_case_label_list *case_label_list;
79 ast_case_statement *case_statement;
80 ast_case_statement_list *case_statement_list;
88 ast_node *then_statement;
89 ast_node *else_statement;
90 } selection_rest_statement;
93 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
94 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
95 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
96 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
97 %token NOPERSPECTIVE FLAT SMOOTH
98 %token MAT2X2 MAT2X3 MAT2X4
99 %token MAT3X2 MAT3X3 MAT3X4
100 %token MAT4X2 MAT4X3 MAT4X4
101 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
102 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
103 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
104 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
105 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
106 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
107 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
108 %token SAMPLEREXTERNALOES
109 %token STRUCT VOID_TOK WHILE
110 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
111 %type <identifier> any_identifier
112 %token <real> FLOATCONSTANT
113 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
114 %token <identifier> FIELD_SELECTION
115 %token LEFT_OP RIGHT_OP
116 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
117 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
118 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
121 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
123 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
124 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
125 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
126 %token PRAGMA_INVARIANT_ALL
129 /* Reserved words that are not actually used in the grammar.
131 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
132 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
133 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
134 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
136 %token SIZEOF CAST NAMESPACE USING
140 %token COMMON PARTITION ACTIVE FILTER
141 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
142 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
143 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
144 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
145 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
148 %type <identifier> variable_identifier
149 %type <node> statement
150 %type <node> statement_list
151 %type <node> simple_statement
152 %type <n> precision_qualifier
153 %type <type_qualifier> type_qualifier
154 %type <type_qualifier> storage_qualifier
155 %type <type_qualifier> interpolation_qualifier
156 %type <type_qualifier> layout_qualifier
157 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
158 %type <type_specifier> type_specifier
159 %type <type_specifier> type_specifier_no_prec
160 %type <type_specifier> type_specifier_nonarray
161 %type <identifier> basic_type_specifier_nonarray
162 %type <fully_specified_type> fully_specified_type
163 %type <function> function_prototype
164 %type <function> function_header
165 %type <function> function_header_with_parameters
166 %type <function> function_declarator
167 %type <parameter_declarator> parameter_declarator
168 %type <parameter_declarator> parameter_declaration
169 %type <type_qualifier> parameter_qualifier
170 %type <type_qualifier> parameter_type_qualifier
171 %type <type_specifier> parameter_type_specifier
172 %type <function_definition> function_definition
173 %type <compound_statement> compound_statement_no_new_scope
174 %type <compound_statement> compound_statement
175 %type <node> statement_no_new_scope
176 %type <node> expression_statement
177 %type <expression> expression
178 %type <expression> primary_expression
179 %type <expression> assignment_expression
180 %type <expression> conditional_expression
181 %type <expression> logical_or_expression
182 %type <expression> logical_xor_expression
183 %type <expression> logical_and_expression
184 %type <expression> inclusive_or_expression
185 %type <expression> exclusive_or_expression
186 %type <expression> and_expression
187 %type <expression> equality_expression
188 %type <expression> relational_expression
189 %type <expression> shift_expression
190 %type <expression> additive_expression
191 %type <expression> multiplicative_expression
192 %type <expression> unary_expression
193 %type <expression> constant_expression
194 %type <expression> integer_expression
195 %type <expression> postfix_expression
196 %type <expression> function_call_header_with_parameters
197 %type <expression> function_call_header_no_parameters
198 %type <expression> function_call_header
199 %type <expression> function_call_generic
200 %type <expression> function_call_or_method
201 %type <expression> function_call
202 %type <expression> method_call_generic
203 %type <expression> method_call_header_with_parameters
204 %type <expression> method_call_header_no_parameters
205 %type <expression> method_call_header
206 %type <n> assignment_operator
207 %type <n> unary_operator
208 %type <expression> function_identifier
209 %type <node> external_declaration
210 %type <declarator_list> init_declarator_list
211 %type <declarator_list> single_declaration
212 %type <expression> initializer
213 %type <node> declaration
214 %type <node> declaration_statement
215 %type <node> jump_statement
216 %type <struct_specifier> struct_specifier
217 %type <node> struct_declaration_list
218 %type <declarator_list> struct_declaration
219 %type <declaration> struct_declarator
220 %type <declaration> struct_declarator_list
221 %type <node> selection_statement
222 %type <selection_rest_statement> selection_rest_statement
223 %type <node> switch_statement
224 %type <switch_body> switch_body
225 %type <case_label_list> case_label_list
226 %type <case_label> case_label
227 %type <case_statement> case_statement
228 %type <case_statement_list> case_statement_list
229 %type <node> iteration_statement
230 %type <node> condition
231 %type <node> conditionopt
232 %type <node> for_init_statement
233 %type <for_rest_statement> for_rest_statement
237 version_statement extension_statement_list
239 _mesa_glsl_initialize_types(state);
241 external_declaration_list
243 delete state->symbols;
244 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
245 _mesa_glsl_initialize_types(state);
250 /* blank - no #version specified: defaults are already set */
251 | VERSION_TOK INTCONSTANT EOL
253 bool supported = false;
257 state->es_shader = true;
258 supported = state->Const.GLSL_100ES;
261 supported = state->Const.GLSL_110;
264 supported = state->Const.GLSL_120;
267 supported = state->Const.GLSL_130;
270 supported = state->Const.GLSL_140;
277 state->language_version = $2;
278 state->version_string =
279 ralloc_asprintf(state, "GLSL%s %d.%02d",
280 state->es_shader ? " ES" : "",
281 state->language_version / 100,
282 state->language_version % 100);
285 _mesa_glsl_error(& @2, state, "%s is not supported. "
286 "Supported versions are: %s\n",
287 state->version_string,
288 state->supported_version_string);
295 | PRAGMA_DEBUG_OFF EOL
296 | PRAGMA_OPTIMIZE_ON EOL
297 | PRAGMA_OPTIMIZE_OFF EOL
298 | PRAGMA_INVARIANT_ALL EOL
300 if (state->language_version < 120) {
301 _mesa_glsl_warning(& @1, state,
302 "pragma `invariant(all)' not supported in %s",
303 state->version_string);
305 state->all_invariant = true;
310 extension_statement_list:
312 | extension_statement_list extension_statement
322 EXTENSION any_identifier COLON any_identifier EOL
324 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
330 external_declaration_list:
333 /* FINISHME: The NULL test is required because pragmas are set to
334 * FINISHME: NULL. (See production rule for external_declaration.)
337 state->translation_unit.push_tail(& $1->link);
339 | external_declaration_list external_declaration
341 /* FINISHME: The NULL test is required because pragmas are set to
342 * FINISHME: NULL. (See production rule for external_declaration.)
345 state->translation_unit.push_tail(& $2->link);
358 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
359 $$->set_location(yylloc);
360 $$->primary_expression.identifier = $1;
365 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
366 $$->set_location(yylloc);
367 $$->primary_expression.int_constant = $1;
372 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
373 $$->set_location(yylloc);
374 $$->primary_expression.uint_constant = $1;
379 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
380 $$->set_location(yylloc);
381 $$->primary_expression.float_constant = $1;
386 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
387 $$->set_location(yylloc);
388 $$->primary_expression.bool_constant = $1;
398 | postfix_expression '[' integer_expression ']'
401 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
402 $$->set_location(yylloc);
408 | postfix_expression '.' any_identifier
411 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
412 $$->set_location(yylloc);
413 $$->primary_expression.identifier = $3;
415 | postfix_expression INC_OP
418 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
419 $$->set_location(yylloc);
421 | postfix_expression DEC_OP
424 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
425 $$->set_location(yylloc);
434 function_call_or_method
437 function_call_or_method:
438 function_call_generic
439 | postfix_expression '.' method_call_generic
442 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
443 $$->set_location(yylloc);
447 function_call_generic:
448 function_call_header_with_parameters ')'
449 | function_call_header_no_parameters ')'
452 function_call_header_no_parameters:
453 function_call_header VOID_TOK
454 | function_call_header
457 function_call_header_with_parameters:
458 function_call_header assignment_expression
461 $$->set_location(yylloc);
462 $$->expressions.push_tail(& $2->link);
464 | function_call_header_with_parameters ',' assignment_expression
467 $$->set_location(yylloc);
468 $$->expressions.push_tail(& $3->link);
472 // Grammar Note: Constructors look like functions, but lexical
473 // analysis recognized most of them as keywords. They are now
474 // recognized through "type_specifier".
475 function_call_header:
476 function_identifier '('
483 $$ = new(ctx) ast_function_expression($1);
484 $$->set_location(yylloc);
486 | variable_identifier
489 ast_expression *callee = new(ctx) ast_expression($1);
490 $$ = new(ctx) ast_function_expression(callee);
491 $$->set_location(yylloc);
496 ast_expression *callee = new(ctx) ast_expression($1);
497 $$ = new(ctx) ast_function_expression(callee);
498 $$->set_location(yylloc);
503 method_call_header_with_parameters ')'
504 | method_call_header_no_parameters ')'
507 method_call_header_no_parameters:
508 method_call_header VOID_TOK
512 method_call_header_with_parameters:
513 method_call_header assignment_expression
516 $$->set_location(yylloc);
517 $$->expressions.push_tail(& $2->link);
519 | method_call_header_with_parameters ',' assignment_expression
522 $$->set_location(yylloc);
523 $$->expressions.push_tail(& $3->link);
527 // Grammar Note: Constructors look like methods, but lexical
528 // analysis recognized most of them as keywords. They are now
529 // recognized through "type_specifier".
531 variable_identifier '('
534 ast_expression *callee = new(ctx) ast_expression($1);
535 $$ = new(ctx) ast_function_expression(callee);
536 $$->set_location(yylloc);
540 // Grammar Note: No traditional style type casts.
543 | INC_OP unary_expression
546 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
547 $$->set_location(yylloc);
549 | DEC_OP unary_expression
552 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
553 $$->set_location(yylloc);
555 | unary_operator unary_expression
558 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
559 $$->set_location(yylloc);
563 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
565 '+' { $$ = ast_plus; }
566 | '-' { $$ = ast_neg; }
567 | '!' { $$ = ast_logic_not; }
568 | '~' { $$ = ast_bit_not; }
571 multiplicative_expression:
573 | multiplicative_expression '*' unary_expression
576 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
577 $$->set_location(yylloc);
579 | multiplicative_expression '/' unary_expression
582 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
583 $$->set_location(yylloc);
585 | multiplicative_expression '%' unary_expression
588 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
589 $$->set_location(yylloc);
594 multiplicative_expression
595 | additive_expression '+' multiplicative_expression
598 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
599 $$->set_location(yylloc);
601 | additive_expression '-' multiplicative_expression
604 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
605 $$->set_location(yylloc);
611 | shift_expression LEFT_OP additive_expression
614 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
615 $$->set_location(yylloc);
617 | shift_expression RIGHT_OP additive_expression
620 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
621 $$->set_location(yylloc);
625 relational_expression:
627 | relational_expression '<' shift_expression
630 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
631 $$->set_location(yylloc);
633 | relational_expression '>' shift_expression
636 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
637 $$->set_location(yylloc);
639 | relational_expression LE_OP shift_expression
642 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
643 $$->set_location(yylloc);
645 | relational_expression GE_OP shift_expression
648 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
649 $$->set_location(yylloc);
654 relational_expression
655 | equality_expression EQ_OP relational_expression
658 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
659 $$->set_location(yylloc);
661 | equality_expression NE_OP relational_expression
664 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
665 $$->set_location(yylloc);
671 | and_expression '&' equality_expression
674 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
675 $$->set_location(yylloc);
679 exclusive_or_expression:
681 | exclusive_or_expression '^' and_expression
684 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
685 $$->set_location(yylloc);
689 inclusive_or_expression:
690 exclusive_or_expression
691 | inclusive_or_expression '|' exclusive_or_expression
694 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
695 $$->set_location(yylloc);
699 logical_and_expression:
700 inclusive_or_expression
701 | logical_and_expression AND_OP inclusive_or_expression
704 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
705 $$->set_location(yylloc);
709 logical_xor_expression:
710 logical_and_expression
711 | logical_xor_expression XOR_OP logical_and_expression
714 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
715 $$->set_location(yylloc);
719 logical_or_expression:
720 logical_xor_expression
721 | logical_or_expression OR_OP logical_xor_expression
724 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
725 $$->set_location(yylloc);
729 conditional_expression:
730 logical_or_expression
731 | logical_or_expression '?' expression ':' assignment_expression
734 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
735 $$->set_location(yylloc);
739 assignment_expression:
740 conditional_expression
741 | unary_expression assignment_operator assignment_expression
744 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
745 $$->set_location(yylloc);
750 '=' { $$ = ast_assign; }
751 | MUL_ASSIGN { $$ = ast_mul_assign; }
752 | DIV_ASSIGN { $$ = ast_div_assign; }
753 | MOD_ASSIGN { $$ = ast_mod_assign; }
754 | ADD_ASSIGN { $$ = ast_add_assign; }
755 | SUB_ASSIGN { $$ = ast_sub_assign; }
756 | LEFT_ASSIGN { $$ = ast_ls_assign; }
757 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
758 | AND_ASSIGN { $$ = ast_and_assign; }
759 | XOR_ASSIGN { $$ = ast_xor_assign; }
760 | OR_ASSIGN { $$ = ast_or_assign; }
764 assignment_expression
768 | expression ',' assignment_expression
771 if ($1->oper != ast_sequence) {
772 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
773 $$->set_location(yylloc);
774 $$->expressions.push_tail(& $1->link);
779 $$->expressions.push_tail(& $3->link);
784 conditional_expression
788 function_prototype ';'
790 state->symbols->pop_scope();
793 | init_declarator_list ';'
797 | PRECISION precision_qualifier type_specifier_no_prec ';'
800 $3->is_precision_statement = true;
806 function_declarator ')'
811 | function_header_with_parameters
814 function_header_with_parameters:
815 function_header parameter_declaration
818 $$->parameters.push_tail(& $2->link);
820 | function_header_with_parameters ',' parameter_declaration
823 $$->parameters.push_tail(& $3->link);
828 fully_specified_type variable_identifier '('
831 $$ = new(ctx) ast_function();
832 $$->set_location(yylloc);
833 $$->return_type = $1;
836 state->symbols->add_function(new(state) ir_function($2));
837 state->symbols->push_scope();
841 parameter_declarator:
842 type_specifier any_identifier
845 $$ = new(ctx) ast_parameter_declarator();
846 $$->set_location(yylloc);
847 $$->type = new(ctx) ast_fully_specified_type();
848 $$->type->set_location(yylloc);
849 $$->type->specifier = $1;
852 | type_specifier any_identifier '[' constant_expression ']'
855 $$ = new(ctx) ast_parameter_declarator();
856 $$->set_location(yylloc);
857 $$->type = new(ctx) ast_fully_specified_type();
858 $$->type->set_location(yylloc);
859 $$->type->specifier = $1;
866 parameter_declaration:
867 parameter_type_qualifier parameter_qualifier parameter_declarator
869 $1.flags.i |= $2.flags.i;
872 $$->type->qualifier = $1;
874 | parameter_qualifier parameter_declarator
877 $$->type->qualifier = $1;
879 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
882 $1.flags.i |= $2.flags.i;
884 $$ = new(ctx) ast_parameter_declarator();
885 $$->set_location(yylloc);
886 $$->type = new(ctx) ast_fully_specified_type();
887 $$->type->qualifier = $1;
888 $$->type->specifier = $3;
890 | parameter_qualifier parameter_type_specifier
893 $$ = new(ctx) ast_parameter_declarator();
894 $$->set_location(yylloc);
895 $$->type = new(ctx) ast_fully_specified_type();
896 $$->type->qualifier = $1;
897 $$->type->specifier = $2;
904 memset(& $$, 0, sizeof($$));
908 memset(& $$, 0, sizeof($$));
913 memset(& $$, 0, sizeof($$));
918 memset(& $$, 0, sizeof($$));
924 parameter_type_specifier:
928 init_declarator_list:
930 | init_declarator_list ',' any_identifier
933 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
934 decl->set_location(yylloc);
937 $$->declarations.push_tail(&decl->link);
938 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
940 | init_declarator_list ',' any_identifier '[' ']'
943 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
944 decl->set_location(yylloc);
947 $$->declarations.push_tail(&decl->link);
948 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
950 | init_declarator_list ',' any_identifier '[' constant_expression ']'
953 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
954 decl->set_location(yylloc);
957 $$->declarations.push_tail(&decl->link);
958 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
960 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
963 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
964 decl->set_location(yylloc);
967 $$->declarations.push_tail(&decl->link);
968 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
970 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
973 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
974 decl->set_location(yylloc);
977 $$->declarations.push_tail(&decl->link);
978 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
980 | init_declarator_list ',' any_identifier '=' initializer
983 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
984 decl->set_location(yylloc);
987 $$->declarations.push_tail(&decl->link);
988 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
992 // Grammar Note: No 'enum', or 'typedef'.
997 /* Empty declaration list is valid. */
998 $$ = new(ctx) ast_declarator_list($1);
999 $$->set_location(yylloc);
1001 | fully_specified_type any_identifier
1004 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1006 $$ = new(ctx) ast_declarator_list($1);
1007 $$->set_location(yylloc);
1008 $$->declarations.push_tail(&decl->link);
1010 | fully_specified_type any_identifier '[' ']'
1013 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1015 $$ = new(ctx) ast_declarator_list($1);
1016 $$->set_location(yylloc);
1017 $$->declarations.push_tail(&decl->link);
1019 | fully_specified_type any_identifier '[' constant_expression ']'
1022 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1024 $$ = new(ctx) ast_declarator_list($1);
1025 $$->set_location(yylloc);
1026 $$->declarations.push_tail(&decl->link);
1028 | fully_specified_type any_identifier '[' ']' '=' initializer
1031 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1033 $$ = new(ctx) ast_declarator_list($1);
1034 $$->set_location(yylloc);
1035 $$->declarations.push_tail(&decl->link);
1037 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1040 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1042 $$ = new(ctx) ast_declarator_list($1);
1043 $$->set_location(yylloc);
1044 $$->declarations.push_tail(&decl->link);
1046 | fully_specified_type any_identifier '=' initializer
1049 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1051 $$ = new(ctx) ast_declarator_list($1);
1052 $$->set_location(yylloc);
1053 $$->declarations.push_tail(&decl->link);
1055 | INVARIANT variable_identifier // Vertex only.
1058 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1060 $$ = new(ctx) ast_declarator_list(NULL);
1061 $$->set_location(yylloc);
1062 $$->invariant = true;
1064 $$->declarations.push_tail(&decl->link);
1068 fully_specified_type:
1072 $$ = new(ctx) ast_fully_specified_type();
1073 $$->set_location(yylloc);
1076 | type_qualifier type_specifier
1079 $$ = new(ctx) ast_fully_specified_type();
1080 $$->set_location(yylloc);
1087 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1093 layout_qualifier_id_list:
1095 | layout_qualifier_id_list ',' layout_qualifier_id
1097 if (($1.flags.i & $3.flags.i) != 0) {
1098 _mesa_glsl_error(& @3, state,
1099 "duplicate layout qualifiers used\n");
1103 $$.flags.i = $1.flags.i | $3.flags.i;
1105 if ($1.flags.q.explicit_location)
1106 $$.location = $1.location;
1108 if ($1.flags.q.explicit_index)
1109 $$.index = $1.index;
1111 if ($3.flags.q.explicit_location)
1112 $$.location = $3.location;
1114 if ($3.flags.q.explicit_index)
1115 $$.index = $3.index;
1119 layout_qualifier_id:
1122 bool got_one = false;
1124 memset(& $$, 0, sizeof($$));
1126 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1127 if (!got_one && state->ARB_fragment_coord_conventions_enable) {
1128 if (strcmp($1, "origin_upper_left") == 0) {
1130 $$.flags.q.origin_upper_left = 1;
1131 } else if (strcmp($1, "pixel_center_integer") == 0) {
1133 $$.flags.q.pixel_center_integer = 1;
1136 if (got_one && state->ARB_fragment_coord_conventions_warn) {
1137 _mesa_glsl_warning(& @1, state,
1138 "GL_ARB_fragment_coord_conventions layout "
1139 "identifier `%s' used\n", $1);
1143 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1145 (state->AMD_conservative_depth_enable ||
1146 state->ARB_conservative_depth_enable)) {
1147 if (strcmp($1, "depth_any") == 0) {
1149 $$.flags.q.depth_any = 1;
1150 } else if (strcmp($1, "depth_greater") == 0) {
1152 $$.flags.q.depth_greater = 1;
1153 } else if (strcmp($1, "depth_less") == 0) {
1155 $$.flags.q.depth_less = 1;
1156 } else if (strcmp($1, "depth_unchanged") == 0) {
1158 $$.flags.q.depth_unchanged = 1;
1161 if (got_one && state->AMD_conservative_depth_warn) {
1162 _mesa_glsl_warning(& @1, state,
1163 "GL_AMD_conservative_depth "
1164 "layout qualifier `%s' is used\n", $1);
1166 if (got_one && state->ARB_conservative_depth_warn) {
1167 _mesa_glsl_warning(& @1, state,
1168 "GL_ARB_conservative_depth "
1169 "layout qualifier `%s' is used\n", $1);
1174 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1179 | any_identifier '=' INTCONSTANT
1181 bool got_one = false;
1183 memset(& $$, 0, sizeof($$));
1185 if (state->ARB_explicit_attrib_location_enable) {
1186 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1187 * FINISHME: GLSL 1.30 (or later) are supported.
1189 if (strcmp("location", $1) == 0) {
1192 $$.flags.q.explicit_location = 1;
1197 _mesa_glsl_error(& @3, state,
1198 "invalid location %d specified\n", $3);
1203 if (strcmp("index", $1) == 0) {
1206 $$.flags.q.explicit_index = 1;
1211 _mesa_glsl_error(& @3, state,
1212 "invalid index %d specified\n", $3);
1218 /* If the identifier didn't match any known layout identifiers,
1222 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1225 } else if (state->ARB_explicit_attrib_location_warn) {
1226 _mesa_glsl_warning(& @1, state,
1227 "GL_ARB_explicit_attrib_location layout "
1228 "identifier `%s' used\n", $1);
1233 interpolation_qualifier:
1236 memset(& $$, 0, sizeof($$));
1237 $$.flags.q.smooth = 1;
1241 memset(& $$, 0, sizeof($$));
1242 $$.flags.q.flat = 1;
1246 memset(& $$, 0, sizeof($$));
1247 $$.flags.q.noperspective = 1;
1251 parameter_type_qualifier:
1254 memset(& $$, 0, sizeof($$));
1255 $$.flags.q.constant = 1;
1262 | layout_qualifier storage_qualifier
1265 $$.flags.i |= $2.flags.i;
1267 | interpolation_qualifier
1268 | interpolation_qualifier storage_qualifier
1271 $$.flags.i |= $2.flags.i;
1273 | INVARIANT storage_qualifier
1276 $$.flags.q.invariant = 1;
1278 | INVARIANT interpolation_qualifier storage_qualifier
1281 $$.flags.i |= $3.flags.i;
1282 $$.flags.q.invariant = 1;
1286 memset(& $$, 0, sizeof($$));
1287 $$.flags.q.invariant = 1;
1294 memset(& $$, 0, sizeof($$));
1295 $$.flags.q.constant = 1;
1299 memset(& $$, 0, sizeof($$));
1300 $$.flags.q.attribute = 1;
1304 memset(& $$, 0, sizeof($$));
1305 $$.flags.q.varying = 1;
1309 memset(& $$, 0, sizeof($$));
1310 $$.flags.q.centroid = 1;
1311 $$.flags.q.varying = 1;
1315 memset(& $$, 0, sizeof($$));
1320 memset(& $$, 0, sizeof($$));
1325 memset(& $$, 0, sizeof($$));
1326 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1330 memset(& $$, 0, sizeof($$));
1331 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1335 memset(& $$, 0, sizeof($$));
1336 $$.flags.q.uniform = 1;
1341 type_specifier_no_prec
1345 | precision_qualifier type_specifier_no_prec
1352 type_specifier_no_prec:
1353 type_specifier_nonarray
1354 | type_specifier_nonarray '[' ']'
1357 $$->is_array = true;
1358 $$->array_size = NULL;
1360 | type_specifier_nonarray '[' constant_expression ']'
1363 $$->is_array = true;
1364 $$->array_size = $3;
1368 type_specifier_nonarray:
1369 basic_type_specifier_nonarray
1372 $$ = new(ctx) ast_type_specifier($1);
1373 $$->set_location(yylloc);
1378 $$ = new(ctx) ast_type_specifier($1);
1379 $$->set_location(yylloc);
1384 $$ = new(ctx) ast_type_specifier($1);
1385 $$->set_location(yylloc);
1389 basic_type_specifier_nonarray:
1390 VOID_TOK { $$ = "void"; }
1391 | FLOAT_TOK { $$ = "float"; }
1392 | INT_TOK { $$ = "int"; }
1393 | UINT_TOK { $$ = "uint"; }
1394 | BOOL_TOK { $$ = "bool"; }
1395 | VEC2 { $$ = "vec2"; }
1396 | VEC3 { $$ = "vec3"; }
1397 | VEC4 { $$ = "vec4"; }
1398 | BVEC2 { $$ = "bvec2"; }
1399 | BVEC3 { $$ = "bvec3"; }
1400 | BVEC4 { $$ = "bvec4"; }
1401 | IVEC2 { $$ = "ivec2"; }
1402 | IVEC3 { $$ = "ivec3"; }
1403 | IVEC4 { $$ = "ivec4"; }
1404 | UVEC2 { $$ = "uvec2"; }
1405 | UVEC3 { $$ = "uvec3"; }
1406 | UVEC4 { $$ = "uvec4"; }
1407 | MAT2X2 { $$ = "mat2"; }
1408 | MAT2X3 { $$ = "mat2x3"; }
1409 | MAT2X4 { $$ = "mat2x4"; }
1410 | MAT3X2 { $$ = "mat3x2"; }
1411 | MAT3X3 { $$ = "mat3"; }
1412 | MAT3X4 { $$ = "mat3x4"; }
1413 | MAT4X2 { $$ = "mat4x2"; }
1414 | MAT4X3 { $$ = "mat4x3"; }
1415 | MAT4X4 { $$ = "mat4"; }
1416 | SAMPLER1D { $$ = "sampler1D"; }
1417 | SAMPLER2D { $$ = "sampler2D"; }
1418 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1419 | SAMPLER3D { $$ = "sampler3D"; }
1420 | SAMPLERCUBE { $$ = "samplerCube"; }
1421 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1422 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1423 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1424 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1425 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1426 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1427 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1428 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1429 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1430 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1431 | ISAMPLER1D { $$ = "isampler1D"; }
1432 | ISAMPLER2D { $$ = "isampler2D"; }
1433 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1434 | ISAMPLER3D { $$ = "isampler3D"; }
1435 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1436 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1437 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1438 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1439 | USAMPLER1D { $$ = "usampler1D"; }
1440 | USAMPLER2D { $$ = "usampler2D"; }
1441 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1442 | USAMPLER3D { $$ = "usampler3D"; }
1443 | USAMPLERCUBE { $$ = "usamplerCube"; }
1444 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1445 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1446 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1449 precision_qualifier:
1451 if (!state->es_shader && state->language_version < 130)
1452 _mesa_glsl_error(& @1, state,
1453 "precision qualifier forbidden "
1454 "in %s (1.30 or later "
1456 state->version_string);
1458 $$ = ast_precision_high;
1461 if (!state->es_shader && state->language_version < 130)
1462 _mesa_glsl_error(& @1, state,
1463 "precision qualifier forbidden "
1464 "in %s (1.30 or later "
1466 state->version_string);
1468 $$ = ast_precision_medium;
1471 if (!state->es_shader && state->language_version < 130)
1472 _mesa_glsl_error(& @1, state,
1473 "precision qualifier forbidden "
1474 "in %s (1.30 or later "
1476 state->version_string);
1478 $$ = ast_precision_low;
1483 STRUCT any_identifier '{' struct_declaration_list '}'
1486 $$ = new(ctx) ast_struct_specifier($2, $4);
1487 $$->set_location(yylloc);
1488 state->symbols->add_type($2, glsl_type::void_type);
1490 | STRUCT '{' struct_declaration_list '}'
1493 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1494 $$->set_location(yylloc);
1498 struct_declaration_list:
1501 $$ = (ast_node *) $1;
1502 $1->link.self_link();
1504 | struct_declaration_list struct_declaration
1506 $$ = (ast_node *) $1;
1507 $$->link.insert_before(& $2->link);
1512 type_specifier struct_declarator_list ';'
1515 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1516 type->set_location(yylloc);
1518 type->specifier = $1;
1519 $$ = new(ctx) ast_declarator_list(type);
1520 $$->set_location(yylloc);
1522 $$->declarations.push_degenerate_list_at_head(& $2->link);
1526 struct_declarator_list:
1530 $1->link.self_link();
1532 | struct_declarator_list ',' struct_declarator
1535 $$->link.insert_before(& $3->link);
1543 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1544 $$->set_location(yylloc);
1545 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1547 | any_identifier '[' constant_expression ']'
1550 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1551 $$->set_location(yylloc);
1556 assignment_expression
1559 declaration_statement:
1563 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1566 compound_statement { $$ = (ast_node *) $1; }
1571 declaration_statement
1572 | expression_statement
1573 | selection_statement
1575 | iteration_statement
1583 $$ = new(ctx) ast_compound_statement(true, NULL);
1584 $$->set_location(yylloc);
1588 state->symbols->push_scope();
1593 $$ = new(ctx) ast_compound_statement(true, $3);
1594 $$->set_location(yylloc);
1595 state->symbols->pop_scope();
1599 statement_no_new_scope:
1600 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1604 compound_statement_no_new_scope:
1608 $$ = new(ctx) ast_compound_statement(false, NULL);
1609 $$->set_location(yylloc);
1611 | '{' statement_list '}'
1614 $$ = new(ctx) ast_compound_statement(false, $2);
1615 $$->set_location(yylloc);
1623 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1628 $$->link.self_link();
1630 | statement_list statement
1633 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1637 $$->link.insert_before(& $2->link);
1641 expression_statement:
1645 $$ = new(ctx) ast_expression_statement(NULL);
1646 $$->set_location(yylloc);
1651 $$ = new(ctx) ast_expression_statement($1);
1652 $$->set_location(yylloc);
1656 selection_statement:
1657 IF '(' expression ')' selection_rest_statement
1659 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1661 $$->set_location(yylloc);
1665 selection_rest_statement:
1666 statement ELSE statement
1668 $$.then_statement = $1;
1669 $$.else_statement = $3;
1673 $$.then_statement = $1;
1674 $$.else_statement = NULL;
1681 $$ = (ast_node *) $1;
1683 | fully_specified_type any_identifier '=' initializer
1686 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1687 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1688 decl->set_location(yylloc);
1689 declarator->set_location(yylloc);
1691 declarator->declarations.push_tail(&decl->link);
1697 * siwtch_statement grammar is based on the syntax described in the body
1698 * of the GLSL spec, not in it's appendix!!!
1701 SWITCH '(' expression ')' switch_body
1703 $$ = new(state) ast_switch_statement($3, $5);
1704 $$->set_location(yylloc);
1711 $$ = new(state) ast_switch_body(NULL);
1712 $$->set_location(yylloc);
1714 | '{' case_statement_list '}'
1716 $$ = new(state) ast_switch_body($2);
1717 $$->set_location(yylloc);
1724 $$ = new(state) ast_case_label($2);
1725 $$->set_location(yylloc);
1729 $$ = new(state) ast_case_label(NULL);
1730 $$->set_location(yylloc);
1737 ast_case_label_list *labels = new(state) ast_case_label_list();
1739 labels->labels.push_tail(& $1->link);
1741 $$->set_location(yylloc);
1743 | case_label_list case_label
1746 $$->labels.push_tail(& $2->link);
1751 case_label_list statement
1753 ast_case_statement *stmts = new(state) ast_case_statement($1);
1754 stmts->set_location(yylloc);
1756 stmts->stmts.push_tail(& $2->link);
1759 | case_statement statement
1762 $$->stmts.push_tail(& $2->link);
1766 case_statement_list:
1769 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1770 cases->set_location(yylloc);
1772 cases->cases.push_tail(& $1->link);
1775 | case_statement_list case_statement
1778 $$->cases.push_tail(& $2->link);
1782 iteration_statement:
1783 WHILE '(' condition ')' statement_no_new_scope
1786 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1787 NULL, $3, NULL, $5);
1788 $$->set_location(yylloc);
1790 | DO statement WHILE '(' expression ')' ';'
1793 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1794 NULL, $5, NULL, $2);
1795 $$->set_location(yylloc);
1797 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1800 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1801 $3, $4.cond, $4.rest, $6);
1802 $$->set_location(yylloc);
1807 expression_statement
1808 | declaration_statement
1825 | conditionopt ';' expression
1832 // Grammar Note: No 'goto'. Gotos are not supported.
1837 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1838 $$->set_location(yylloc);
1843 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1844 $$->set_location(yylloc);
1849 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1850 $$->set_location(yylloc);
1852 | RETURN expression ';'
1855 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1856 $$->set_location(yylloc);
1858 | DISCARD ';' // Fragment shader only.
1861 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1862 $$->set_location(yylloc);
1866 external_declaration:
1867 function_definition { $$ = $1; }
1868 | declaration { $$ = $1; }
1869 | pragma_statement { $$ = NULL; }
1872 function_definition:
1873 function_prototype compound_statement_no_new_scope
1876 $$ = new(ctx) ast_function_definition();
1877 $$->set_location(yylloc);
1881 state->symbols->pop_scope();