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 <declarator_list> 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");
1104 $$.flags.i |= $3.flags.i;
1106 if ($3.flags.q.explicit_location)
1107 $$.location = $3.location;
1109 if ($3.flags.q.explicit_index)
1110 $$.index = $3.index;
1114 layout_qualifier_id:
1117 memset(& $$, 0, sizeof($$));
1119 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1120 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1121 if (strcmp($1, "origin_upper_left") == 0) {
1122 $$.flags.q.origin_upper_left = 1;
1123 } else if (strcmp($1, "pixel_center_integer") == 0) {
1124 $$.flags.q.pixel_center_integer = 1;
1127 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1128 _mesa_glsl_warning(& @1, state,
1129 "GL_ARB_fragment_coord_conventions layout "
1130 "identifier `%s' used\n", $1);
1134 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1136 (state->AMD_conservative_depth_enable ||
1137 state->ARB_conservative_depth_enable)) {
1138 if (strcmp($1, "depth_any") == 0) {
1139 $$.flags.q.depth_any = 1;
1140 } else if (strcmp($1, "depth_greater") == 0) {
1141 $$.flags.q.depth_greater = 1;
1142 } else if (strcmp($1, "depth_less") == 0) {
1143 $$.flags.q.depth_less = 1;
1144 } else if (strcmp($1, "depth_unchanged") == 0) {
1145 $$.flags.q.depth_unchanged = 1;
1148 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1149 _mesa_glsl_warning(& @1, state,
1150 "GL_AMD_conservative_depth "
1151 "layout qualifier `%s' is used\n", $1);
1153 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1154 _mesa_glsl_warning(& @1, state,
1155 "GL_ARB_conservative_depth "
1156 "layout qualifier `%s' is used\n", $1);
1161 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1166 | any_identifier '=' INTCONSTANT
1168 memset(& $$, 0, sizeof($$));
1170 if (state->ARB_explicit_attrib_location_enable) {
1171 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1172 * FINISHME: GLSL 1.30 (or later) are supported.
1174 if (strcmp("location", $1) == 0) {
1175 $$.flags.q.explicit_location = 1;
1180 _mesa_glsl_error(& @3, state,
1181 "invalid location %d specified\n", $3);
1186 if (strcmp("index", $1) == 0) {
1187 $$.flags.q.explicit_index = 1;
1192 _mesa_glsl_error(& @3, state,
1193 "invalid index %d specified\n", $3);
1199 /* If the identifier didn't match any known layout identifiers,
1203 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1206 } else if (state->ARB_explicit_attrib_location_warn) {
1207 _mesa_glsl_warning(& @1, state,
1208 "GL_ARB_explicit_attrib_location layout "
1209 "identifier `%s' used\n", $1);
1214 interpolation_qualifier:
1217 memset(& $$, 0, sizeof($$));
1218 $$.flags.q.smooth = 1;
1222 memset(& $$, 0, sizeof($$));
1223 $$.flags.q.flat = 1;
1227 memset(& $$, 0, sizeof($$));
1228 $$.flags.q.noperspective = 1;
1232 parameter_type_qualifier:
1235 memset(& $$, 0, sizeof($$));
1236 $$.flags.q.constant = 1;
1243 | layout_qualifier storage_qualifier
1246 $$.flags.i |= $2.flags.i;
1248 | interpolation_qualifier
1249 | interpolation_qualifier storage_qualifier
1252 $$.flags.i |= $2.flags.i;
1254 | INVARIANT storage_qualifier
1257 $$.flags.q.invariant = 1;
1259 | INVARIANT interpolation_qualifier storage_qualifier
1262 $$.flags.i |= $3.flags.i;
1263 $$.flags.q.invariant = 1;
1267 memset(& $$, 0, sizeof($$));
1268 $$.flags.q.invariant = 1;
1275 memset(& $$, 0, sizeof($$));
1276 $$.flags.q.constant = 1;
1280 memset(& $$, 0, sizeof($$));
1281 $$.flags.q.attribute = 1;
1285 memset(& $$, 0, sizeof($$));
1286 $$.flags.q.varying = 1;
1290 memset(& $$, 0, sizeof($$));
1291 $$.flags.q.centroid = 1;
1292 $$.flags.q.varying = 1;
1296 memset(& $$, 0, sizeof($$));
1301 memset(& $$, 0, sizeof($$));
1306 memset(& $$, 0, sizeof($$));
1307 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1311 memset(& $$, 0, sizeof($$));
1312 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1316 memset(& $$, 0, sizeof($$));
1317 $$.flags.q.uniform = 1;
1322 type_specifier_no_prec
1326 | precision_qualifier type_specifier_no_prec
1333 type_specifier_no_prec:
1334 type_specifier_nonarray
1335 | type_specifier_nonarray '[' ']'
1338 $$->is_array = true;
1339 $$->array_size = NULL;
1341 | type_specifier_nonarray '[' constant_expression ']'
1344 $$->is_array = true;
1345 $$->array_size = $3;
1349 type_specifier_nonarray:
1350 basic_type_specifier_nonarray
1353 $$ = new(ctx) ast_type_specifier($1);
1354 $$->set_location(yylloc);
1359 $$ = new(ctx) ast_type_specifier($1);
1360 $$->set_location(yylloc);
1365 $$ = new(ctx) ast_type_specifier($1);
1366 $$->set_location(yylloc);
1370 basic_type_specifier_nonarray:
1371 VOID_TOK { $$ = "void"; }
1372 | FLOAT_TOK { $$ = "float"; }
1373 | INT_TOK { $$ = "int"; }
1374 | UINT_TOK { $$ = "uint"; }
1375 | BOOL_TOK { $$ = "bool"; }
1376 | VEC2 { $$ = "vec2"; }
1377 | VEC3 { $$ = "vec3"; }
1378 | VEC4 { $$ = "vec4"; }
1379 | BVEC2 { $$ = "bvec2"; }
1380 | BVEC3 { $$ = "bvec3"; }
1381 | BVEC4 { $$ = "bvec4"; }
1382 | IVEC2 { $$ = "ivec2"; }
1383 | IVEC3 { $$ = "ivec3"; }
1384 | IVEC4 { $$ = "ivec4"; }
1385 | UVEC2 { $$ = "uvec2"; }
1386 | UVEC3 { $$ = "uvec3"; }
1387 | UVEC4 { $$ = "uvec4"; }
1388 | MAT2X2 { $$ = "mat2"; }
1389 | MAT2X3 { $$ = "mat2x3"; }
1390 | MAT2X4 { $$ = "mat2x4"; }
1391 | MAT3X2 { $$ = "mat3x2"; }
1392 | MAT3X3 { $$ = "mat3"; }
1393 | MAT3X4 { $$ = "mat3x4"; }
1394 | MAT4X2 { $$ = "mat4x2"; }
1395 | MAT4X3 { $$ = "mat4x3"; }
1396 | MAT4X4 { $$ = "mat4"; }
1397 | SAMPLER1D { $$ = "sampler1D"; }
1398 | SAMPLER2D { $$ = "sampler2D"; }
1399 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1400 | SAMPLER3D { $$ = "sampler3D"; }
1401 | SAMPLERCUBE { $$ = "samplerCube"; }
1402 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1403 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1404 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1405 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1406 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1407 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1408 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1409 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1410 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1411 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1412 | ISAMPLER1D { $$ = "isampler1D"; }
1413 | ISAMPLER2D { $$ = "isampler2D"; }
1414 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1415 | ISAMPLER3D { $$ = "isampler3D"; }
1416 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1417 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1418 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1419 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1420 | USAMPLER1D { $$ = "usampler1D"; }
1421 | USAMPLER2D { $$ = "usampler2D"; }
1422 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1423 | USAMPLER3D { $$ = "usampler3D"; }
1424 | USAMPLERCUBE { $$ = "usamplerCube"; }
1425 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1426 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1427 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1430 precision_qualifier:
1432 if (!state->es_shader && state->language_version < 130)
1433 _mesa_glsl_error(& @1, state,
1434 "precision qualifier forbidden "
1435 "in %s (1.30 or later "
1437 state->version_string);
1439 $$ = ast_precision_high;
1442 if (!state->es_shader && state->language_version < 130)
1443 _mesa_glsl_error(& @1, state,
1444 "precision qualifier forbidden "
1445 "in %s (1.30 or later "
1447 state->version_string);
1449 $$ = ast_precision_medium;
1452 if (!state->es_shader && state->language_version < 130)
1453 _mesa_glsl_error(& @1, state,
1454 "precision qualifier forbidden "
1455 "in %s (1.30 or later "
1457 state->version_string);
1459 $$ = ast_precision_low;
1464 STRUCT any_identifier '{' struct_declaration_list '}'
1467 $$ = new(ctx) ast_struct_specifier($2, $4);
1468 $$->set_location(yylloc);
1469 state->symbols->add_type($2, glsl_type::void_type);
1471 | STRUCT '{' struct_declaration_list '}'
1474 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1475 $$->set_location(yylloc);
1479 struct_declaration_list:
1483 $1->link.self_link();
1485 | struct_declaration_list struct_declaration
1488 $$->link.insert_before(& $2->link);
1493 type_specifier struct_declarator_list ';'
1496 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1497 type->set_location(yylloc);
1499 type->specifier = $1;
1500 $$ = new(ctx) ast_declarator_list(type);
1501 $$->set_location(yylloc);
1503 $$->declarations.push_degenerate_list_at_head(& $2->link);
1507 struct_declarator_list:
1511 $1->link.self_link();
1513 | struct_declarator_list ',' struct_declarator
1516 $$->link.insert_before(& $3->link);
1524 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1525 $$->set_location(yylloc);
1526 state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
1528 | any_identifier '[' constant_expression ']'
1531 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1532 $$->set_location(yylloc);
1537 assignment_expression
1540 declaration_statement:
1544 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1547 compound_statement { $$ = (ast_node *) $1; }
1552 declaration_statement
1553 | expression_statement
1554 | selection_statement
1556 | iteration_statement
1564 $$ = new(ctx) ast_compound_statement(true, NULL);
1565 $$->set_location(yylloc);
1569 state->symbols->push_scope();
1574 $$ = new(ctx) ast_compound_statement(true, $3);
1575 $$->set_location(yylloc);
1576 state->symbols->pop_scope();
1580 statement_no_new_scope:
1581 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1585 compound_statement_no_new_scope:
1589 $$ = new(ctx) ast_compound_statement(false, NULL);
1590 $$->set_location(yylloc);
1592 | '{' statement_list '}'
1595 $$ = new(ctx) ast_compound_statement(false, $2);
1596 $$->set_location(yylloc);
1604 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1609 $$->link.self_link();
1611 | statement_list statement
1614 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1618 $$->link.insert_before(& $2->link);
1622 expression_statement:
1626 $$ = new(ctx) ast_expression_statement(NULL);
1627 $$->set_location(yylloc);
1632 $$ = new(ctx) ast_expression_statement($1);
1633 $$->set_location(yylloc);
1637 selection_statement:
1638 IF '(' expression ')' selection_rest_statement
1640 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1642 $$->set_location(yylloc);
1646 selection_rest_statement:
1647 statement ELSE statement
1649 $$.then_statement = $1;
1650 $$.else_statement = $3;
1654 $$.then_statement = $1;
1655 $$.else_statement = NULL;
1662 $$ = (ast_node *) $1;
1664 | fully_specified_type any_identifier '=' initializer
1667 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1668 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1669 decl->set_location(yylloc);
1670 declarator->set_location(yylloc);
1672 declarator->declarations.push_tail(&decl->link);
1678 * siwtch_statement grammar is based on the syntax described in the body
1679 * of the GLSL spec, not in it's appendix!!!
1682 SWITCH '(' expression ')' switch_body
1684 $$ = new(state) ast_switch_statement($3, $5);
1685 $$->set_location(yylloc);
1692 $$ = new(state) ast_switch_body(NULL);
1693 $$->set_location(yylloc);
1695 | '{' case_statement_list '}'
1697 $$ = new(state) ast_switch_body($2);
1698 $$->set_location(yylloc);
1705 $$ = new(state) ast_case_label($2);
1706 $$->set_location(yylloc);
1710 $$ = new(state) ast_case_label(NULL);
1711 $$->set_location(yylloc);
1718 ast_case_label_list *labels = new(state) ast_case_label_list();
1720 labels->labels.push_tail(& $1->link);
1722 $$->set_location(yylloc);
1724 | case_label_list case_label
1727 $$->labels.push_tail(& $2->link);
1732 case_label_list statement
1734 ast_case_statement *stmts = new(state) ast_case_statement($1);
1735 stmts->set_location(yylloc);
1737 stmts->stmts.push_tail(& $2->link);
1740 | case_statement statement
1743 $$->stmts.push_tail(& $2->link);
1747 case_statement_list:
1750 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1751 cases->set_location(yylloc);
1753 cases->cases.push_tail(& $1->link);
1756 | case_statement_list case_statement
1759 $$->cases.push_tail(& $2->link);
1763 iteration_statement:
1764 WHILE '(' condition ')' statement_no_new_scope
1767 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1768 NULL, $3, NULL, $5);
1769 $$->set_location(yylloc);
1771 | DO statement WHILE '(' expression ')' ';'
1774 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1775 NULL, $5, NULL, $2);
1776 $$->set_location(yylloc);
1778 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1781 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1782 $3, $4.cond, $4.rest, $6);
1783 $$->set_location(yylloc);
1788 expression_statement
1789 | declaration_statement
1806 | conditionopt ';' expression
1813 // Grammar Note: No 'goto'. Gotos are not supported.
1818 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1819 $$->set_location(yylloc);
1824 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1825 $$->set_location(yylloc);
1830 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1831 $$->set_location(yylloc);
1833 | RETURN expression ';'
1836 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1837 $$->set_location(yylloc);
1839 | DISCARD ';' // Fragment shader only.
1842 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1843 $$->set_location(yylloc);
1847 external_declaration:
1848 function_definition { $$ = $1; }
1849 | declaration { $$ = $1; }
1850 | pragma_statement { $$ = NULL; }
1853 function_definition:
1854 function_prototype compound_statement_no_new_scope
1857 $$ = new(ctx) ast_function_definition();
1858 $$->set_location(yylloc);
1862 state->symbols->pop_scope();