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
97 %token <real> FLOATCONSTANT
98 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
99 %token <identifier> FIELD_SELECTION
100 %token LEFT_OP RIGHT_OP
101 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
102 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
103 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
106 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
108 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
109 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
110 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
111 %token PRAGMA_INVARIANT_ALL
114 /* Reserved words that are not actually used in the grammar.
116 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
117 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
118 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
119 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
120 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
121 %token SIZEOF CAST NAMESPACE USING
125 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
126 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
127 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
128 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
129 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
130 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
133 %type <identifier> variable_identifier
134 %type <node> statement
135 %type <node> statement_list
136 %type <node> simple_statement
137 %type <n> precision_qualifier
138 %type <type_qualifier> type_qualifier
139 %type <type_qualifier> storage_qualifier
140 %type <type_qualifier> interpolation_qualifier
141 %type <type_qualifier> layout_qualifier
142 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
143 %type <type_specifier> type_specifier
144 %type <type_specifier> type_specifier_no_prec
145 %type <type_specifier> type_specifier_nonarray
146 %type <n> basic_type_specifier_nonarray
147 %type <fully_specified_type> fully_specified_type
148 %type <function> function_prototype
149 %type <function> function_header
150 %type <function> function_header_with_parameters
151 %type <function> function_declarator
152 %type <parameter_declarator> parameter_declarator
153 %type <parameter_declarator> parameter_declaration
154 %type <type_qualifier> parameter_qualifier
155 %type <type_qualifier> parameter_type_qualifier
156 %type <type_specifier> parameter_type_specifier
157 %type <function_definition> function_definition
158 %type <compound_statement> compound_statement_no_new_scope
159 %type <compound_statement> compound_statement
160 %type <node> statement_no_new_scope
161 %type <node> expression_statement
162 %type <expression> expression
163 %type <expression> primary_expression
164 %type <expression> assignment_expression
165 %type <expression> conditional_expression
166 %type <expression> logical_or_expression
167 %type <expression> logical_xor_expression
168 %type <expression> logical_and_expression
169 %type <expression> inclusive_or_expression
170 %type <expression> exclusive_or_expression
171 %type <expression> and_expression
172 %type <expression> equality_expression
173 %type <expression> relational_expression
174 %type <expression> shift_expression
175 %type <expression> additive_expression
176 %type <expression> multiplicative_expression
177 %type <expression> unary_expression
178 %type <expression> constant_expression
179 %type <expression> integer_expression
180 %type <expression> postfix_expression
181 %type <expression> function_call_header_with_parameters
182 %type <expression> function_call_header_no_parameters
183 %type <expression> function_call_header
184 %type <expression> function_call_generic
185 %type <expression> function_call_or_method
186 %type <expression> function_call
187 %type <n> assignment_operator
188 %type <n> unary_operator
189 %type <expression> function_identifier
190 %type <node> external_declaration
191 %type <declarator_list> init_declarator_list
192 %type <declarator_list> single_declaration
193 %type <expression> initializer
194 %type <node> declaration
195 %type <node> declaration_statement
196 %type <node> jump_statement
197 %type <struct_specifier> struct_specifier
198 %type <node> struct_declaration_list
199 %type <declarator_list> struct_declaration
200 %type <declaration> struct_declarator
201 %type <declaration> struct_declarator_list
202 %type <node> selection_statement
203 %type <selection_rest_statement> selection_rest_statement
204 %type <node> iteration_statement
205 %type <node> condition
206 %type <node> conditionopt
207 %type <node> for_init_statement
208 %type <for_rest_statement> for_rest_statement
212 version_statement extension_statement_list
214 _mesa_glsl_initialize_types(state);
216 external_declaration_list
220 /* blank - no #version specified: defaults are already set */
221 | VERSION INTCONSTANT EOL
223 bool supported = false;
227 state->es_shader = true;
228 supported = state->Const.GLSL_100ES;
231 supported = state->Const.GLSL_110;
234 supported = state->Const.GLSL_120;
237 supported = state->Const.GLSL_130;
244 state->language_version = $2;
245 state->version_string =
246 ralloc_asprintf(state, "GLSL%s %d.%02d",
247 state->es_shader ? " ES" : "",
248 state->language_version / 100,
249 state->language_version % 100);
252 _mesa_glsl_error(& @2, state, "%s is not supported. "
253 "Supported versions are: %s\n",
254 state->version_string,
255 state->supported_version_string);
262 | PRAGMA_DEBUG_OFF EOL
263 | PRAGMA_OPTIMIZE_ON EOL
264 | PRAGMA_OPTIMIZE_OFF EOL
265 | PRAGMA_INVARIANT_ALL EOL
267 if (state->language_version < 120) {
268 _mesa_glsl_warning(& @1, state,
269 "pragma `invariant(all)' not supported in %s",
270 state->version_string);
272 state->all_invariant = true;
277 extension_statement_list:
279 | extension_statement_list extension_statement
283 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
285 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
291 external_declaration_list:
294 /* FINISHME: The NULL test is required because pragmas are set to
295 * FINISHME: NULL. (See production rule for external_declaration.)
298 state->translation_unit.push_tail(& $1->link);
300 | external_declaration_list external_declaration
302 /* FINISHME: The NULL test is required because pragmas are set to
303 * FINISHME: NULL. (See production rule for external_declaration.)
306 state->translation_unit.push_tail(& $2->link);
318 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
319 $$->set_location(yylloc);
320 $$->primary_expression.identifier = $1;
325 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
326 $$->set_location(yylloc);
327 $$->primary_expression.int_constant = $1;
332 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
333 $$->set_location(yylloc);
334 $$->primary_expression.uint_constant = $1;
339 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
340 $$->set_location(yylloc);
341 $$->primary_expression.float_constant = $1;
346 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
347 $$->set_location(yylloc);
348 $$->primary_expression.bool_constant = $1;
358 | postfix_expression '[' integer_expression ']'
361 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
362 $$->set_location(yylloc);
368 | postfix_expression '.' IDENTIFIER
371 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
372 $$->set_location(yylloc);
373 $$->primary_expression.identifier = $3;
375 | postfix_expression INC_OP
378 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
379 $$->set_location(yylloc);
381 | postfix_expression DEC_OP
384 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
385 $$->set_location(yylloc);
394 function_call_or_method
397 function_call_or_method:
398 function_call_generic
399 | postfix_expression '.' function_call_generic
402 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
403 $$->set_location(yylloc);
407 function_call_generic:
408 function_call_header_with_parameters ')'
409 | function_call_header_no_parameters ')'
412 function_call_header_no_parameters:
413 function_call_header VOID_TOK
414 | function_call_header
417 function_call_header_with_parameters:
418 function_call_header assignment_expression
421 $$->set_location(yylloc);
422 $$->expressions.push_tail(& $2->link);
424 | function_call_header_with_parameters ',' assignment_expression
427 $$->set_location(yylloc);
428 $$->expressions.push_tail(& $3->link);
432 // Grammar Note: Constructors look like functions, but lexical
433 // analysis recognized most of them as keywords. They are now
434 // recognized through "type_specifier".
435 function_call_header:
436 function_identifier '('
443 $$ = new(ctx) ast_function_expression($1);
444 $$->set_location(yylloc);
449 ast_expression *callee = new(ctx) ast_expression($1);
450 $$ = new(ctx) ast_function_expression(callee);
451 $$->set_location(yylloc);
456 ast_expression *callee = new(ctx) ast_expression($1);
457 $$ = new(ctx) ast_function_expression(callee);
458 $$->set_location(yylloc);
462 // Grammar Note: No traditional style type casts.
465 | INC_OP unary_expression
468 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
469 $$->set_location(yylloc);
471 | DEC_OP unary_expression
474 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
475 $$->set_location(yylloc);
477 | unary_operator unary_expression
480 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
481 $$->set_location(yylloc);
485 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
487 '+' { $$ = ast_plus; }
488 | '-' { $$ = ast_neg; }
489 | '!' { $$ = ast_logic_not; }
490 | '~' { $$ = ast_bit_not; }
493 multiplicative_expression:
495 | multiplicative_expression '*' unary_expression
498 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
499 $$->set_location(yylloc);
501 | multiplicative_expression '/' unary_expression
504 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
505 $$->set_location(yylloc);
507 | multiplicative_expression '%' unary_expression
510 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
511 $$->set_location(yylloc);
516 multiplicative_expression
517 | additive_expression '+' multiplicative_expression
520 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
521 $$->set_location(yylloc);
523 | additive_expression '-' multiplicative_expression
526 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
527 $$->set_location(yylloc);
533 | shift_expression LEFT_OP additive_expression
536 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
537 $$->set_location(yylloc);
539 | shift_expression RIGHT_OP additive_expression
542 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
543 $$->set_location(yylloc);
547 relational_expression:
549 | relational_expression '<' shift_expression
552 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
553 $$->set_location(yylloc);
555 | relational_expression '>' shift_expression
558 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
559 $$->set_location(yylloc);
561 | relational_expression LE_OP shift_expression
564 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
565 $$->set_location(yylloc);
567 | relational_expression GE_OP shift_expression
570 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
571 $$->set_location(yylloc);
576 relational_expression
577 | equality_expression EQ_OP relational_expression
580 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
581 $$->set_location(yylloc);
583 | equality_expression NE_OP relational_expression
586 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
587 $$->set_location(yylloc);
593 | and_expression '&' equality_expression
596 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
597 $$->set_location(yylloc);
601 exclusive_or_expression:
603 | exclusive_or_expression '^' and_expression
606 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
607 $$->set_location(yylloc);
611 inclusive_or_expression:
612 exclusive_or_expression
613 | inclusive_or_expression '|' exclusive_or_expression
616 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
617 $$->set_location(yylloc);
621 logical_and_expression:
622 inclusive_or_expression
623 | logical_and_expression AND_OP inclusive_or_expression
626 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
627 $$->set_location(yylloc);
631 logical_xor_expression:
632 logical_and_expression
633 | logical_xor_expression XOR_OP logical_and_expression
636 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
637 $$->set_location(yylloc);
641 logical_or_expression:
642 logical_xor_expression
643 | logical_or_expression OR_OP logical_xor_expression
646 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
647 $$->set_location(yylloc);
651 conditional_expression:
652 logical_or_expression
653 | logical_or_expression '?' expression ':' assignment_expression
656 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
657 $$->set_location(yylloc);
661 assignment_expression:
662 conditional_expression
663 | unary_expression assignment_operator assignment_expression
666 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
667 $$->set_location(yylloc);
672 '=' { $$ = ast_assign; }
673 | MUL_ASSIGN { $$ = ast_mul_assign; }
674 | DIV_ASSIGN { $$ = ast_div_assign; }
675 | MOD_ASSIGN { $$ = ast_mod_assign; }
676 | ADD_ASSIGN { $$ = ast_add_assign; }
677 | SUB_ASSIGN { $$ = ast_sub_assign; }
678 | LEFT_ASSIGN { $$ = ast_ls_assign; }
679 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
680 | AND_ASSIGN { $$ = ast_and_assign; }
681 | XOR_ASSIGN { $$ = ast_xor_assign; }
682 | OR_ASSIGN { $$ = ast_or_assign; }
686 assignment_expression
690 | expression ',' assignment_expression
693 if ($1->oper != ast_sequence) {
694 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
695 $$->set_location(yylloc);
696 $$->expressions.push_tail(& $1->link);
701 $$->expressions.push_tail(& $3->link);
706 conditional_expression
710 function_prototype ';'
714 | init_declarator_list ';'
718 | PRECISION precision_qualifier type_specifier_no_prec ';'
721 $3->is_precision_statement = true;
727 function_declarator ')'
732 | function_header_with_parameters
735 function_header_with_parameters:
736 function_header parameter_declaration
739 $$->parameters.push_tail(& $2->link);
741 | function_header_with_parameters ',' parameter_declaration
744 $$->parameters.push_tail(& $3->link);
749 fully_specified_type IDENTIFIER '('
752 $$ = new(ctx) ast_function();
753 $$->set_location(yylloc);
754 $$->return_type = $1;
759 parameter_declarator:
760 type_specifier IDENTIFIER
763 $$ = new(ctx) ast_parameter_declarator();
764 $$->set_location(yylloc);
765 $$->type = new(ctx) ast_fully_specified_type();
766 $$->type->set_location(yylloc);
767 $$->type->specifier = $1;
770 | type_specifier IDENTIFIER '[' constant_expression ']'
773 $$ = new(ctx) ast_parameter_declarator();
774 $$->set_location(yylloc);
775 $$->type = new(ctx) ast_fully_specified_type();
776 $$->type->set_location(yylloc);
777 $$->type->specifier = $1;
784 parameter_declaration:
785 parameter_type_qualifier parameter_qualifier parameter_declarator
787 $1.flags.i |= $2.flags.i;
790 $$->type->qualifier = $1;
792 | parameter_qualifier parameter_declarator
795 $$->type->qualifier = $1;
797 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
800 $1.flags.i |= $2.flags.i;
802 $$ = new(ctx) ast_parameter_declarator();
803 $$->set_location(yylloc);
804 $$->type = new(ctx) ast_fully_specified_type();
805 $$->type->qualifier = $1;
806 $$->type->specifier = $3;
808 | parameter_qualifier parameter_type_specifier
811 $$ = new(ctx) ast_parameter_declarator();
812 $$->set_location(yylloc);
813 $$->type = new(ctx) ast_fully_specified_type();
814 $$->type->qualifier = $1;
815 $$->type->specifier = $2;
822 memset(& $$, 0, sizeof($$));
826 memset(& $$, 0, sizeof($$));
831 memset(& $$, 0, sizeof($$));
836 memset(& $$, 0, sizeof($$));
842 parameter_type_specifier:
846 init_declarator_list:
848 | init_declarator_list ',' IDENTIFIER
851 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
852 decl->set_location(yylloc);
855 $$->declarations.push_tail(&decl->link);
857 | init_declarator_list ',' IDENTIFIER '[' ']'
860 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
861 decl->set_location(yylloc);
864 $$->declarations.push_tail(&decl->link);
866 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
869 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
870 decl->set_location(yylloc);
873 $$->declarations.push_tail(&decl->link);
875 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
878 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
879 decl->set_location(yylloc);
882 $$->declarations.push_tail(&decl->link);
884 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
887 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
888 decl->set_location(yylloc);
891 $$->declarations.push_tail(&decl->link);
893 | init_declarator_list ',' IDENTIFIER '=' initializer
896 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
897 decl->set_location(yylloc);
900 $$->declarations.push_tail(&decl->link);
904 // Grammar Note: No 'enum', or 'typedef'.
909 if ($1->specifier->type_specifier != ast_struct) {
910 _mesa_glsl_error(& @1, state, "empty declaration list\n");
913 $$ = new(ctx) ast_declarator_list($1);
914 $$->set_location(yylloc);
917 | fully_specified_type IDENTIFIER
920 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
922 $$ = new(ctx) ast_declarator_list($1);
923 $$->set_location(yylloc);
924 $$->declarations.push_tail(&decl->link);
926 | fully_specified_type IDENTIFIER '[' ']'
929 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
931 $$ = new(ctx) ast_declarator_list($1);
932 $$->set_location(yylloc);
933 $$->declarations.push_tail(&decl->link);
935 | fully_specified_type IDENTIFIER '[' constant_expression ']'
938 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
940 $$ = new(ctx) ast_declarator_list($1);
941 $$->set_location(yylloc);
942 $$->declarations.push_tail(&decl->link);
944 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
947 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
949 $$ = new(ctx) ast_declarator_list($1);
950 $$->set_location(yylloc);
951 $$->declarations.push_tail(&decl->link);
953 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
956 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
958 $$ = new(ctx) ast_declarator_list($1);
959 $$->set_location(yylloc);
960 $$->declarations.push_tail(&decl->link);
962 | fully_specified_type IDENTIFIER '=' initializer
965 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
967 $$ = new(ctx) ast_declarator_list($1);
968 $$->set_location(yylloc);
969 $$->declarations.push_tail(&decl->link);
971 | INVARIANT IDENTIFIER // Vertex only.
974 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
976 $$ = new(ctx) ast_declarator_list(NULL);
977 $$->set_location(yylloc);
978 $$->invariant = true;
980 $$->declarations.push_tail(&decl->link);
984 fully_specified_type:
988 $$ = new(ctx) ast_fully_specified_type();
989 $$->set_location(yylloc);
992 | type_qualifier type_specifier
995 $$ = new(ctx) ast_fully_specified_type();
996 $$->set_location(yylloc);
1003 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1009 layout_qualifier_id_list:
1011 | layout_qualifier_id_list ',' layout_qualifier_id
1013 if (($1.flags.i & $3.flags.i) != 0) {
1014 _mesa_glsl_error(& @3, state,
1015 "duplicate layout qualifiers used\n");
1019 $$.flags.i = $1.flags.i | $3.flags.i;
1021 if ($1.flags.q.explicit_location)
1022 $$.location = $1.location;
1024 if ($3.flags.q.explicit_location)
1025 $$.location = $3.location;
1029 layout_qualifier_id:
1032 bool got_one = false;
1034 memset(& $$, 0, sizeof($$));
1036 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1037 if (!got_one && state->ARB_fragment_coord_conventions_enable) {
1038 if (strcmp($1, "origin_upper_left") == 0) {
1040 $$.flags.q.origin_upper_left = 1;
1041 } else if (strcmp($1, "pixel_center_integer") == 0) {
1043 $$.flags.q.pixel_center_integer = 1;
1046 if (got_one && state->ARB_fragment_coord_conventions_warn) {
1047 _mesa_glsl_warning(& @1, state,
1048 "GL_ARB_fragment_coord_conventions layout "
1049 "identifier `%s' used\n", $1);
1053 /* Layout qualifiers for AMD_conservative_depth. */
1054 if (!got_one && state->AMD_conservative_depth_enable) {
1055 if (strcmp($1, "depth_any") == 0) {
1057 $$.flags.q.depth_any = 1;
1058 } else if (strcmp($1, "depth_greater") == 0) {
1060 $$.flags.q.depth_greater = 1;
1061 } else if (strcmp($1, "depth_less") == 0) {
1063 $$.flags.q.depth_less = 1;
1064 } else if (strcmp($1, "depth_unchanged") == 0) {
1066 $$.flags.q.depth_unchanged = 1;
1069 if (got_one && state->AMD_conservative_depth_warn) {
1070 _mesa_glsl_warning(& @1, state,
1071 "GL_AMD_conservative_depth "
1072 "layout qualifier `%s' is used\n", $1);
1077 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1082 | IDENTIFIER '=' INTCONSTANT
1084 bool got_one = false;
1086 memset(& $$, 0, sizeof($$));
1088 if (state->ARB_explicit_attrib_location_enable) {
1089 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1090 * FINISHME: GLSL 1.30 (or later) are supported.
1092 if (strcmp("location", $1) == 0) {
1095 $$.flags.q.explicit_location = 1;
1100 _mesa_glsl_error(& @3, state,
1101 "invalid location %d specified\n", $3);
1107 /* If the identifier didn't match any known layout identifiers,
1111 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1114 } else if (state->ARB_explicit_attrib_location_warn) {
1115 _mesa_glsl_warning(& @1, state,
1116 "GL_ARB_explicit_attrib_location layout "
1117 "identifier `%s' used\n", $1);
1122 interpolation_qualifier:
1125 memset(& $$, 0, sizeof($$));
1126 $$.flags.q.smooth = 1;
1130 memset(& $$, 0, sizeof($$));
1131 $$.flags.q.flat = 1;
1135 memset(& $$, 0, sizeof($$));
1136 $$.flags.q.noperspective = 1;
1140 parameter_type_qualifier:
1143 memset(& $$, 0, sizeof($$));
1144 $$.flags.q.constant = 1;
1151 | layout_qualifier storage_qualifier
1154 $$.flags.i |= $2.flags.i;
1156 | interpolation_qualifier
1157 | interpolation_qualifier storage_qualifier
1160 $$.flags.i |= $2.flags.i;
1162 | INVARIANT storage_qualifier
1165 $$.flags.q.invariant = 1;
1167 | INVARIANT interpolation_qualifier storage_qualifier
1170 $$.flags.i |= $3.flags.i;
1171 $$.flags.q.invariant = 1;
1175 memset(& $$, 0, sizeof($$));
1176 $$.flags.q.invariant = 1;
1183 memset(& $$, 0, sizeof($$));
1184 $$.flags.q.constant = 1;
1188 memset(& $$, 0, sizeof($$));
1189 $$.flags.q.attribute = 1;
1193 memset(& $$, 0, sizeof($$));
1194 $$.flags.q.varying = 1;
1198 memset(& $$, 0, sizeof($$));
1199 $$.flags.q.centroid = 1;
1200 $$.flags.q.varying = 1;
1204 memset(& $$, 0, sizeof($$));
1209 memset(& $$, 0, sizeof($$));
1214 memset(& $$, 0, sizeof($$));
1215 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1219 memset(& $$, 0, sizeof($$));
1220 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1224 memset(& $$, 0, sizeof($$));
1225 $$.flags.q.uniform = 1;
1230 type_specifier_no_prec
1234 | precision_qualifier type_specifier_no_prec
1241 type_specifier_no_prec:
1242 type_specifier_nonarray
1243 | type_specifier_nonarray '[' ']'
1246 $$->is_array = true;
1247 $$->array_size = NULL;
1249 | type_specifier_nonarray '[' constant_expression ']'
1252 $$->is_array = true;
1253 $$->array_size = $3;
1257 type_specifier_nonarray:
1258 basic_type_specifier_nonarray
1261 $$ = new(ctx) ast_type_specifier($1);
1262 $$->set_location(yylloc);
1267 $$ = new(ctx) ast_type_specifier($1);
1268 $$->set_location(yylloc);
1273 $$ = new(ctx) ast_type_specifier($1);
1274 $$->set_location(yylloc);
1278 basic_type_specifier_nonarray:
1279 VOID_TOK { $$ = ast_void; }
1280 | FLOAT_TOK { $$ = ast_float; }
1281 | INT_TOK { $$ = ast_int; }
1282 | UINT_TOK { $$ = ast_uint; }
1283 | BOOL_TOK { $$ = ast_bool; }
1284 | VEC2 { $$ = ast_vec2; }
1285 | VEC3 { $$ = ast_vec3; }
1286 | VEC4 { $$ = ast_vec4; }
1287 | BVEC2 { $$ = ast_bvec2; }
1288 | BVEC3 { $$ = ast_bvec3; }
1289 | BVEC4 { $$ = ast_bvec4; }
1290 | IVEC2 { $$ = ast_ivec2; }
1291 | IVEC3 { $$ = ast_ivec3; }
1292 | IVEC4 { $$ = ast_ivec4; }
1293 | UVEC2 { $$ = ast_uvec2; }
1294 | UVEC3 { $$ = ast_uvec3; }
1295 | UVEC4 { $$ = ast_uvec4; }
1296 | MAT2X2 { $$ = ast_mat2; }
1297 | MAT2X3 { $$ = ast_mat2x3; }
1298 | MAT2X4 { $$ = ast_mat2x4; }
1299 | MAT3X2 { $$ = ast_mat3x2; }
1300 | MAT3X3 { $$ = ast_mat3; }
1301 | MAT3X4 { $$ = ast_mat3x4; }
1302 | MAT4X2 { $$ = ast_mat4x2; }
1303 | MAT4X3 { $$ = ast_mat4x3; }
1304 | MAT4X4 { $$ = ast_mat4; }
1305 | SAMPLER1D { $$ = ast_sampler1d; }
1306 | SAMPLER2D { $$ = ast_sampler2d; }
1307 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1308 | SAMPLER3D { $$ = ast_sampler3d; }
1309 | SAMPLERCUBE { $$ = ast_samplercube; }
1310 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1311 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1312 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1313 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1314 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1315 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1316 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1317 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1318 | ISAMPLER1D { $$ = ast_isampler1d; }
1319 | ISAMPLER2D { $$ = ast_isampler2d; }
1320 | ISAMPLER3D { $$ = ast_isampler3d; }
1321 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1322 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1323 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1324 | USAMPLER1D { $$ = ast_usampler1d; }
1325 | USAMPLER2D { $$ = ast_usampler2d; }
1326 | USAMPLER3D { $$ = ast_usampler3d; }
1327 | USAMPLERCUBE { $$ = ast_usamplercube; }
1328 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1329 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1332 precision_qualifier:
1334 if (!state->es_shader && state->language_version < 130)
1335 _mesa_glsl_error(& @1, state,
1336 "precision qualifier forbidden "
1337 "in %s (1.30 or later "
1339 state->version_string);
1341 $$ = ast_precision_high;
1344 if (!state->es_shader && state->language_version < 130)
1345 _mesa_glsl_error(& @1, state,
1346 "precision qualifier forbidden "
1347 "in %s (1.30 or later "
1349 state->version_string);
1351 $$ = ast_precision_medium;
1354 if (!state->es_shader && state->language_version < 130)
1355 _mesa_glsl_error(& @1, state,
1356 "precision qualifier forbidden "
1357 "in %s (1.30 or later "
1359 state->version_string);
1361 $$ = ast_precision_low;
1366 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1369 $$ = new(ctx) ast_struct_specifier($2, $4);
1370 $$->set_location(yylloc);
1372 | STRUCT '{' struct_declaration_list '}'
1375 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1376 $$->set_location(yylloc);
1380 struct_declaration_list:
1383 $$ = (ast_node *) $1;
1384 $1->link.self_link();
1386 | struct_declaration_list struct_declaration
1388 $$ = (ast_node *) $1;
1389 $$->link.insert_before(& $2->link);
1394 type_specifier struct_declarator_list ';'
1397 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1398 type->set_location(yylloc);
1400 type->specifier = $1;
1401 $$ = new(ctx) ast_declarator_list(type);
1402 $$->set_location(yylloc);
1404 $$->declarations.push_degenerate_list_at_head(& $2->link);
1408 struct_declarator_list:
1412 $1->link.self_link();
1414 | struct_declarator_list ',' struct_declarator
1417 $$->link.insert_before(& $3->link);
1425 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1426 $$->set_location(yylloc);
1428 | IDENTIFIER '[' constant_expression ']'
1431 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1432 $$->set_location(yylloc);
1437 assignment_expression
1440 declaration_statement:
1444 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1447 compound_statement { $$ = (ast_node *) $1; }
1452 declaration_statement
1453 | expression_statement
1454 | selection_statement
1455 | switch_statement { $$ = NULL; }
1456 | case_label { $$ = NULL; }
1457 | iteration_statement
1465 $$ = new(ctx) ast_compound_statement(true, NULL);
1466 $$->set_location(yylloc);
1468 | '{' statement_list '}'
1471 $$ = new(ctx) ast_compound_statement(true, $2);
1472 $$->set_location(yylloc);
1476 statement_no_new_scope:
1477 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1481 compound_statement_no_new_scope:
1485 $$ = new(ctx) ast_compound_statement(false, NULL);
1486 $$->set_location(yylloc);
1488 | '{' statement_list '}'
1491 $$ = new(ctx) ast_compound_statement(false, $2);
1492 $$->set_location(yylloc);
1500 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1505 $$->link.self_link();
1507 | statement_list statement
1510 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1514 $$->link.insert_before(& $2->link);
1518 expression_statement:
1522 $$ = new(ctx) ast_expression_statement(NULL);
1523 $$->set_location(yylloc);
1528 $$ = new(ctx) ast_expression_statement($1);
1529 $$->set_location(yylloc);
1533 selection_statement:
1534 IF '(' expression ')' selection_rest_statement
1536 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1538 $$->set_location(yylloc);
1542 selection_rest_statement:
1543 statement ELSE statement
1545 $$.then_statement = $1;
1546 $$.else_statement = $3;
1550 $$.then_statement = $1;
1551 $$.else_statement = NULL;
1558 $$ = (ast_node *) $1;
1560 | fully_specified_type IDENTIFIER '=' initializer
1563 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1564 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1565 decl->set_location(yylloc);
1566 declarator->set_location(yylloc);
1568 declarator->declarations.push_tail(&decl->link);
1574 SWITCH '(' expression ')' compound_statement
1582 iteration_statement:
1583 WHILE '(' condition ')' statement_no_new_scope
1586 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1587 NULL, $3, NULL, $5);
1588 $$->set_location(yylloc);
1590 | DO statement WHILE '(' expression ')' ';'
1593 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1594 NULL, $5, NULL, $2);
1595 $$->set_location(yylloc);
1597 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1600 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1601 $3, $4.cond, $4.rest, $6);
1602 $$->set_location(yylloc);
1607 expression_statement
1608 | declaration_statement
1625 | conditionopt ';' expression
1632 // Grammar Note: No 'goto'. Gotos are not supported.
1637 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1638 $$->set_location(yylloc);
1643 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1644 $$->set_location(yylloc);
1649 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1650 $$->set_location(yylloc);
1652 | RETURN expression ';'
1655 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1656 $$->set_location(yylloc);
1658 | DISCARD ';' // Fragment shader only.
1661 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1662 $$->set_location(yylloc);
1666 external_declaration:
1667 function_definition { $$ = $1; }
1668 | declaration { $$ = $1; }
1669 | pragma_statement { $$ = NULL; }
1672 function_definition:
1673 function_prototype compound_statement_no_new_scope
1676 $$ = new(ctx) ast_function_definition();
1677 $$->set_location(yylloc);