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}
58 struct ast_type_qualifier q;
63 ast_type_specifier *type_specifier;
64 ast_fully_specified_type *fully_specified_type;
65 ast_function *function;
66 ast_parameter_declarator *parameter_declarator;
67 ast_function_definition *function_definition;
68 ast_compound_statement *compound_statement;
69 ast_expression *expression;
70 ast_declarator_list *declarator_list;
71 ast_struct_specifier *struct_specifier;
72 ast_declaration *declaration;
80 ast_node *then_statement;
81 ast_node *else_statement;
82 } selection_rest_statement;
85 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
86 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
87 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
88 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
89 %token NOPERSPECTIVE FLAT SMOOTH
90 %token MAT2X2 MAT2X3 MAT2X4
91 %token MAT3X2 MAT3X3 MAT3X4
92 %token MAT4X2 MAT4X3 MAT4X4
93 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
94 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
95 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
96 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
97 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
98 %token STRUCT VOID_TOK WHILE
99 %token <identifier> IDENTIFIER
100 %token <real> FLOATCONSTANT
101 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
102 %token <identifier> FIELD_SELECTION
103 %token LEFT_OP RIGHT_OP
104 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
105 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
106 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
109 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
111 %token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
112 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
113 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
116 /* Reserved words that are not actually used in the grammar.
118 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
119 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
120 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
121 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
122 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
123 %token SIZEOF CAST NAMESPACE USING
127 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
128 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
129 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
130 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
131 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
134 %type <identifier> variable_identifier
135 %type <node> statement
136 %type <node> statement_list
137 %type <node> simple_statement
138 %type <n> precision_qualifier
139 %type <type_qualifier> type_qualifier
140 %type <type_qualifier> storage_qualifier
141 %type <type_qualifier> interpolation_qualifier
142 %type <type_qualifier> layout_qualifier
143 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
144 %type <type_specifier> type_specifier
145 %type <type_specifier> type_specifier_no_prec
146 %type <type_specifier> type_specifier_nonarray
147 %type <n> basic_type_specifier_nonarray
148 %type <fully_specified_type> fully_specified_type
149 %type <function> function_prototype
150 %type <function> function_header
151 %type <function> function_header_with_parameters
152 %type <function> function_declarator
153 %type <parameter_declarator> parameter_declarator
154 %type <parameter_declarator> parameter_declaration
155 %type <type_qualifier> parameter_qualifier
156 %type <type_qualifier> parameter_type_qualifier
157 %type <type_specifier> parameter_type_specifier
158 %type <function_definition> function_definition
159 %type <compound_statement> compound_statement_no_new_scope
160 %type <compound_statement> compound_statement
161 %type <node> statement_no_new_scope
162 %type <node> expression_statement
163 %type <expression> expression
164 %type <expression> primary_expression
165 %type <expression> assignment_expression
166 %type <expression> conditional_expression
167 %type <expression> logical_or_expression
168 %type <expression> logical_xor_expression
169 %type <expression> logical_and_expression
170 %type <expression> inclusive_or_expression
171 %type <expression> exclusive_or_expression
172 %type <expression> and_expression
173 %type <expression> equality_expression
174 %type <expression> relational_expression
175 %type <expression> shift_expression
176 %type <expression> additive_expression
177 %type <expression> multiplicative_expression
178 %type <expression> unary_expression
179 %type <expression> constant_expression
180 %type <expression> integer_expression
181 %type <expression> postfix_expression
182 %type <expression> function_call_header_with_parameters
183 %type <expression> function_call_header_no_parameters
184 %type <expression> function_call_header
185 %type <expression> function_call_generic
186 %type <expression> function_call_or_method
187 %type <expression> function_call
188 %type <n> assignment_operator
189 %type <n> unary_operator
190 %type <expression> function_identifier
191 %type <node> external_declaration
192 %type <declarator_list> init_declarator_list
193 %type <declarator_list> single_declaration
194 %type <expression> initializer
195 %type <node> declaration
196 %type <node> declaration_statement
197 %type <node> jump_statement
198 %type <struct_specifier> struct_specifier
199 %type <node> struct_declaration_list
200 %type <declarator_list> struct_declaration
201 %type <declaration> struct_declarator
202 %type <declaration> struct_declarator_list
203 %type <node> selection_statement
204 %type <selection_rest_statement> selection_rest_statement
205 %type <node> iteration_statement
206 %type <node> condition
207 %type <node> conditionopt
208 %type <node> for_init_statement
209 %type <for_rest_statement> for_rest_statement
213 version_statement extension_statement_list
215 _mesa_glsl_initialize_types(state);
217 external_declaration_list
221 /* blank - no #version specified: defaults are already set */
222 | VERSION INTCONSTANT EOL
226 state->es_shader = true;
230 /* FINISHME: Check against implementation support versions. */
231 state->language_version = $2;
234 _mesa_glsl_error(& @2, state, "Shading language version"
235 "%u is not supported\n", $2);
243 | PRAGMA_DEBUG_OFF EOL
244 | PRAGMA_OPTIMIZE_ON EOL
245 | PRAGMA_OPTIMIZE_OFF EOL
248 extension_statement_list:
250 | extension_statement_list extension_statement
254 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
256 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
262 external_declaration_list:
265 /* FINISHME: The NULL test is only required because 'precision'
266 * FINISHME: statements are not yet supported.
269 state->translation_unit.push_tail(& $1->link);
271 | external_declaration_list external_declaration
273 /* FINISHME: The NULL test is only required because 'precision'
274 * FINISHME: statements are not yet supported.
277 state->translation_unit.push_tail(& $2->link);
289 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
290 $$->set_location(yylloc);
291 $$->primary_expression.identifier = $1;
296 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
297 $$->set_location(yylloc);
298 $$->primary_expression.int_constant = $1;
303 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
304 $$->set_location(yylloc);
305 $$->primary_expression.uint_constant = $1;
310 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
311 $$->set_location(yylloc);
312 $$->primary_expression.float_constant = $1;
317 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
318 $$->set_location(yylloc);
319 $$->primary_expression.bool_constant = $1;
329 | postfix_expression '[' integer_expression ']'
332 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
333 $$->set_location(yylloc);
339 | postfix_expression '.' IDENTIFIER
342 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
343 $$->set_location(yylloc);
344 $$->primary_expression.identifier = $3;
346 | postfix_expression INC_OP
349 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
350 $$->set_location(yylloc);
352 | postfix_expression DEC_OP
355 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
356 $$->set_location(yylloc);
365 function_call_or_method
368 function_call_or_method:
369 function_call_generic
370 | postfix_expression '.' function_call_generic
373 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
374 $$->set_location(yylloc);
378 function_call_generic:
379 function_call_header_with_parameters ')'
380 | function_call_header_no_parameters ')'
383 function_call_header_no_parameters:
384 function_call_header VOID_TOK
385 | function_call_header
388 function_call_header_with_parameters:
389 function_call_header assignment_expression
392 $$->set_location(yylloc);
393 $$->expressions.push_tail(& $2->link);
395 | function_call_header_with_parameters ',' assignment_expression
398 $$->set_location(yylloc);
399 $$->expressions.push_tail(& $3->link);
403 // Grammar Note: Constructors look like functions, but lexical
404 // analysis recognized most of them as keywords. They are now
405 // recognized through "type_specifier".
406 function_call_header:
407 function_identifier '('
414 $$ = new(ctx) ast_function_expression($1);
415 $$->set_location(yylloc);
420 ast_expression *callee = new(ctx) ast_expression($1);
421 $$ = new(ctx) ast_function_expression(callee);
422 $$->set_location(yylloc);
427 ast_expression *callee = new(ctx) ast_expression($1);
428 $$ = new(ctx) ast_function_expression(callee);
429 $$->set_location(yylloc);
433 // Grammar Note: No traditional style type casts.
436 | INC_OP unary_expression
439 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
440 $$->set_location(yylloc);
442 | DEC_OP unary_expression
445 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
446 $$->set_location(yylloc);
448 | unary_operator unary_expression
451 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
452 $$->set_location(yylloc);
456 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
458 '+' { $$ = ast_plus; }
459 | '-' { $$ = ast_neg; }
460 | '!' { $$ = ast_logic_not; }
461 | '~' { $$ = ast_bit_not; }
464 multiplicative_expression:
466 | multiplicative_expression '*' unary_expression
469 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
470 $$->set_location(yylloc);
472 | multiplicative_expression '/' unary_expression
475 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
476 $$->set_location(yylloc);
478 | multiplicative_expression '%' unary_expression
481 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
482 $$->set_location(yylloc);
487 multiplicative_expression
488 | additive_expression '+' multiplicative_expression
491 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
492 $$->set_location(yylloc);
494 | additive_expression '-' multiplicative_expression
497 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
498 $$->set_location(yylloc);
504 | shift_expression LEFT_OP additive_expression
507 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
508 $$->set_location(yylloc);
510 | shift_expression RIGHT_OP additive_expression
513 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
514 $$->set_location(yylloc);
518 relational_expression:
520 | relational_expression '<' shift_expression
523 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
524 $$->set_location(yylloc);
526 | relational_expression '>' shift_expression
529 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
530 $$->set_location(yylloc);
532 | relational_expression LE_OP shift_expression
535 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
536 $$->set_location(yylloc);
538 | relational_expression GE_OP shift_expression
541 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
542 $$->set_location(yylloc);
547 relational_expression
548 | equality_expression EQ_OP relational_expression
551 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
552 $$->set_location(yylloc);
554 | equality_expression NE_OP relational_expression
557 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
558 $$->set_location(yylloc);
564 | and_expression '&' equality_expression
567 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
568 $$->set_location(yylloc);
572 exclusive_or_expression:
574 | exclusive_or_expression '^' and_expression
577 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
578 $$->set_location(yylloc);
582 inclusive_or_expression:
583 exclusive_or_expression
584 | inclusive_or_expression '|' exclusive_or_expression
587 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
588 $$->set_location(yylloc);
592 logical_and_expression:
593 inclusive_or_expression
594 | logical_and_expression AND_OP inclusive_or_expression
597 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
598 $$->set_location(yylloc);
602 logical_xor_expression:
603 logical_and_expression
604 | logical_xor_expression XOR_OP logical_and_expression
607 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
608 $$->set_location(yylloc);
612 logical_or_expression:
613 logical_xor_expression
614 | logical_or_expression OR_OP logical_xor_expression
617 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
618 $$->set_location(yylloc);
622 conditional_expression:
623 logical_or_expression
624 | logical_or_expression '?' expression ':' assignment_expression
627 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
628 $$->set_location(yylloc);
632 assignment_expression:
633 conditional_expression
634 | unary_expression assignment_operator assignment_expression
637 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
638 $$->set_location(yylloc);
643 '=' { $$ = ast_assign; }
644 | MUL_ASSIGN { $$ = ast_mul_assign; }
645 | DIV_ASSIGN { $$ = ast_div_assign; }
646 | MOD_ASSIGN { $$ = ast_mod_assign; }
647 | ADD_ASSIGN { $$ = ast_add_assign; }
648 | SUB_ASSIGN { $$ = ast_sub_assign; }
649 | LEFT_ASSIGN { $$ = ast_ls_assign; }
650 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
651 | AND_ASSIGN { $$ = ast_and_assign; }
652 | XOR_ASSIGN { $$ = ast_xor_assign; }
653 | OR_ASSIGN { $$ = ast_or_assign; }
657 assignment_expression
661 | expression ',' assignment_expression
664 if ($1->oper != ast_sequence) {
665 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
666 $$->set_location(yylloc);
667 $$->expressions.push_tail(& $1->link);
672 $$->expressions.push_tail(& $3->link);
677 conditional_expression
681 function_prototype ';'
685 | init_declarator_list ';'
689 | PRECISION precision_qualifier type_specifier_no_prec ';'
691 if (($3->type_specifier != ast_float)
692 && ($3->type_specifier != ast_int)) {
693 _mesa_glsl_error(& @3, state, "global precision qualifier can "
694 "only be applied to `int' or `float'\n");
698 $$ = NULL; /* FINISHME */
703 function_declarator ')'
708 | function_header_with_parameters
711 function_header_with_parameters:
712 function_header parameter_declaration
715 $$->parameters.push_tail(& $2->link);
717 | function_header_with_parameters ',' parameter_declaration
720 $$->parameters.push_tail(& $3->link);
725 fully_specified_type IDENTIFIER '('
728 $$ = new(ctx) ast_function();
729 $$->set_location(yylloc);
730 $$->return_type = $1;
735 parameter_declarator:
736 type_specifier IDENTIFIER
739 $$ = new(ctx) ast_parameter_declarator();
740 $$->set_location(yylloc);
741 $$->type = new(ctx) ast_fully_specified_type();
742 $$->type->set_location(yylloc);
743 $$->type->specifier = $1;
746 | type_specifier IDENTIFIER '[' constant_expression ']'
749 $$ = new(ctx) ast_parameter_declarator();
750 $$->set_location(yylloc);
751 $$->type = new(ctx) ast_fully_specified_type();
752 $$->type->set_location(yylloc);
753 $$->type->specifier = $1;
760 parameter_declaration:
761 parameter_type_qualifier parameter_qualifier parameter_declarator
766 $$->type->qualifier = $1.q;
768 | parameter_qualifier parameter_declarator
771 $$->type->qualifier = $1.q;
773 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
778 $$ = new(ctx) ast_parameter_declarator();
779 $$->set_location(yylloc);
780 $$->type = new(ctx) ast_fully_specified_type();
781 $$->type->qualifier = $1.q;
782 $$->type->specifier = $3;
784 | parameter_qualifier parameter_type_specifier
787 $$ = new(ctx) ast_parameter_declarator();
788 $$->set_location(yylloc);
789 $$->type = new(ctx) ast_fully_specified_type();
790 $$->type->qualifier = $1.q;
791 $$->type->specifier = $2;
798 memset(& $$, 0, sizeof($$));
802 memset(& $$, 0, sizeof($$));
807 memset(& $$, 0, sizeof($$));
812 memset(& $$, 0, sizeof($$));
813 $$.q.in = 1; $$.q.out = 1;
817 parameter_type_specifier:
821 init_declarator_list:
823 | init_declarator_list ',' IDENTIFIER
826 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
827 decl->set_location(yylloc);
830 $$->declarations.push_tail(&decl->link);
832 | init_declarator_list ',' IDENTIFIER '[' ']'
835 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
836 decl->set_location(yylloc);
839 $$->declarations.push_tail(&decl->link);
841 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
844 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
845 decl->set_location(yylloc);
848 $$->declarations.push_tail(&decl->link);
850 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
853 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
854 decl->set_location(yylloc);
857 $$->declarations.push_tail(&decl->link);
859 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
862 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
863 decl->set_location(yylloc);
866 $$->declarations.push_tail(&decl->link);
868 | init_declarator_list ',' IDENTIFIER '=' initializer
871 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
872 decl->set_location(yylloc);
875 $$->declarations.push_tail(&decl->link);
879 // Grammar Note: No 'enum', or 'typedef'.
884 if ($1->specifier->type_specifier != ast_struct) {
885 _mesa_glsl_error(& @1, state, "empty declaration list\n");
888 $$ = new(ctx) ast_declarator_list($1);
889 $$->set_location(yylloc);
892 | fully_specified_type IDENTIFIER
895 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
897 $$ = new(ctx) ast_declarator_list($1);
898 $$->set_location(yylloc);
899 $$->declarations.push_tail(&decl->link);
901 | fully_specified_type IDENTIFIER '[' ']'
904 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
906 $$ = new(ctx) ast_declarator_list($1);
907 $$->set_location(yylloc);
908 $$->declarations.push_tail(&decl->link);
910 | fully_specified_type IDENTIFIER '[' constant_expression ']'
913 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
915 $$ = new(ctx) ast_declarator_list($1);
916 $$->set_location(yylloc);
917 $$->declarations.push_tail(&decl->link);
919 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
922 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
924 $$ = new(ctx) ast_declarator_list($1);
925 $$->set_location(yylloc);
926 $$->declarations.push_tail(&decl->link);
928 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
931 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
933 $$ = new(ctx) ast_declarator_list($1);
934 $$->set_location(yylloc);
935 $$->declarations.push_tail(&decl->link);
937 | fully_specified_type IDENTIFIER '=' initializer
940 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
942 $$ = new(ctx) ast_declarator_list($1);
943 $$->set_location(yylloc);
944 $$->declarations.push_tail(&decl->link);
946 | INVARIANT IDENTIFIER // Vertex only.
949 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
951 $$ = new(ctx) ast_declarator_list(NULL);
952 $$->set_location(yylloc);
953 $$->invariant = true;
955 $$->declarations.push_tail(&decl->link);
959 fully_specified_type:
963 $$ = new(ctx) ast_fully_specified_type();
964 $$->set_location(yylloc);
967 | type_qualifier type_specifier
970 $$ = new(ctx) ast_fully_specified_type();
971 $$->set_location(yylloc);
972 $$->qualifier = $1.q;
978 LAYOUT_TOK '(' layout_qualifier_id_list ')'
984 layout_qualifier_id_list:
986 | layout_qualifier_id_list ',' layout_qualifier_id
995 bool got_one = false;
997 memset(& $$, 0, sizeof($$));
999 if (state->ARB_fragment_coord_conventions_enable) {
1000 if (strcmp($1, "origin_upper_left") == 0) {
1002 $$.q.origin_upper_left = 1;
1003 } else if (strcmp($1, "pixel_center_integer") == 0) {
1005 $$.q.pixel_center_integer = 1;
1009 /* If the identifier didn't match any known layout identifiers,
1013 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1016 } else if (state->ARB_fragment_coord_conventions_warn) {
1017 _mesa_glsl_warning(& @1, state,
1018 "GL_ARB_fragment_coord_conventions layout "
1019 "identifier `%s' used\n", $1);
1024 interpolation_qualifier:
1027 memset(& $$, 0, sizeof($$));
1032 memset(& $$, 0, sizeof($$));
1037 memset(& $$, 0, sizeof($$));
1038 $$.q.noperspective = 1;
1042 parameter_type_qualifier:
1045 memset(& $$, 0, sizeof($$));
1053 | layout_qualifier storage_qualifier
1057 | interpolation_qualifier
1058 | interpolation_qualifier storage_qualifier
1062 | INVARIANT storage_qualifier
1067 | INVARIANT interpolation_qualifier storage_qualifier
1074 memset(& $$, 0, sizeof($$));
1082 memset(& $$, 0, sizeof($$));
1087 memset(& $$, 0, sizeof($$));
1092 memset(& $$, 0, sizeof($$));
1097 memset(& $$, 0, sizeof($$));
1098 $$.q.centroid = 1; $$.q.varying = 1;
1102 memset(& $$, 0, sizeof($$));
1107 memset(& $$, 0, sizeof($$));
1112 memset(& $$, 0, sizeof($$));
1113 $$.q.centroid = 1; $$.q.in = 1;
1117 memset(& $$, 0, sizeof($$));
1118 $$.q.centroid = 1; $$.q.out = 1;
1122 memset(& $$, 0, sizeof($$));
1128 type_specifier_no_prec
1129 | precision_qualifier type_specifier_no_prec
1136 type_specifier_no_prec:
1137 type_specifier_nonarray
1138 | type_specifier_nonarray '[' ']'
1141 $$->is_array = true;
1142 $$->array_size = NULL;
1144 | type_specifier_nonarray '[' constant_expression ']'
1147 $$->is_array = true;
1148 $$->array_size = $3;
1152 type_specifier_nonarray:
1153 basic_type_specifier_nonarray
1156 $$ = new(ctx) ast_type_specifier($1);
1157 $$->set_location(yylloc);
1162 $$ = new(ctx) ast_type_specifier($1);
1163 $$->set_location(yylloc);
1168 $$ = new(ctx) ast_type_specifier($1);
1169 $$->set_location(yylloc);
1173 basic_type_specifier_nonarray:
1174 VOID_TOK { $$ = ast_void; }
1175 | FLOAT_TOK { $$ = ast_float; }
1176 | INT_TOK { $$ = ast_int; }
1177 | UINT_TOK { $$ = ast_uint; }
1178 | BOOL_TOK { $$ = ast_bool; }
1179 | VEC2 { $$ = ast_vec2; }
1180 | VEC3 { $$ = ast_vec3; }
1181 | VEC4 { $$ = ast_vec4; }
1182 | BVEC2 { $$ = ast_bvec2; }
1183 | BVEC3 { $$ = ast_bvec3; }
1184 | BVEC4 { $$ = ast_bvec4; }
1185 | IVEC2 { $$ = ast_ivec2; }
1186 | IVEC3 { $$ = ast_ivec3; }
1187 | IVEC4 { $$ = ast_ivec4; }
1188 | UVEC2 { $$ = ast_uvec2; }
1189 | UVEC3 { $$ = ast_uvec3; }
1190 | UVEC4 { $$ = ast_uvec4; }
1191 | MAT2X2 { $$ = ast_mat2; }
1192 | MAT2X3 { $$ = ast_mat2x3; }
1193 | MAT2X4 { $$ = ast_mat2x4; }
1194 | MAT3X2 { $$ = ast_mat3x2; }
1195 | MAT3X3 { $$ = ast_mat3; }
1196 | MAT3X4 { $$ = ast_mat3x4; }
1197 | MAT4X2 { $$ = ast_mat4x2; }
1198 | MAT4X3 { $$ = ast_mat4x3; }
1199 | MAT4X4 { $$ = ast_mat4; }
1200 | SAMPLER1D { $$ = ast_sampler1d; }
1201 | SAMPLER2D { $$ = ast_sampler2d; }
1202 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1203 | SAMPLER3D { $$ = ast_sampler3d; }
1204 | SAMPLERCUBE { $$ = ast_samplercube; }
1205 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1206 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1207 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1208 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1209 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1210 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1211 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1212 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1213 | ISAMPLER1D { $$ = ast_isampler1d; }
1214 | ISAMPLER2D { $$ = ast_isampler2d; }
1215 | ISAMPLER3D { $$ = ast_isampler3d; }
1216 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1217 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1218 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1219 | USAMPLER1D { $$ = ast_usampler1d; }
1220 | USAMPLER2D { $$ = ast_usampler2d; }
1221 | USAMPLER3D { $$ = ast_usampler3d; }
1222 | USAMPLERCUBE { $$ = ast_usamplercube; }
1223 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1224 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1227 precision_qualifier:
1229 if (!state->es_shader && state->language_version < 130)
1230 _mesa_glsl_error(& @1, state,
1231 "precision qualifier forbidden "
1232 "in GLSL %d.%d (1.30 or later "
1234 state->language_version / 100,
1235 state->language_version % 100);
1237 $$ = ast_precision_high;
1240 if (!state->es_shader && state->language_version < 130)
1241 _mesa_glsl_error(& @1, state,
1242 "precision qualifier forbidden "
1243 "in GLSL %d.%d (1.30 or later "
1245 state->language_version / 100,
1246 state->language_version % 100);
1248 $$ = ast_precision_medium;
1251 if (!state->es_shader && state->language_version < 130)
1252 _mesa_glsl_error(& @1, state,
1253 "precision qualifier forbidden "
1254 "in GLSL %d.%d (1.30 or later "
1256 state->language_version / 100,
1257 state->language_version % 100);
1259 $$ = ast_precision_low;
1264 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1267 $$ = new(ctx) ast_struct_specifier($2, $4);
1268 $$->set_location(yylloc);
1270 | STRUCT '{' struct_declaration_list '}'
1273 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1274 $$->set_location(yylloc);
1278 struct_declaration_list:
1281 $$ = (ast_node *) $1;
1282 $1->link.self_link();
1284 | struct_declaration_list struct_declaration
1286 $$ = (ast_node *) $1;
1287 $$->link.insert_before(& $2->link);
1292 type_specifier struct_declarator_list ';'
1295 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1296 type->set_location(yylloc);
1298 type->specifier = $1;
1299 $$ = new(ctx) ast_declarator_list(type);
1300 $$->set_location(yylloc);
1302 $$->declarations.push_degenerate_list_at_head(& $2->link);
1306 struct_declarator_list:
1310 $1->link.self_link();
1312 | struct_declarator_list ',' struct_declarator
1315 $$->link.insert_before(& $3->link);
1323 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1324 $$->set_location(yylloc);
1326 | IDENTIFIER '[' constant_expression ']'
1329 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1330 $$->set_location(yylloc);
1335 assignment_expression
1338 declaration_statement:
1342 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1345 compound_statement { $$ = (ast_node *) $1; }
1350 declaration_statement
1351 | expression_statement
1352 | selection_statement
1353 | switch_statement { $$ = NULL; }
1354 | case_label { $$ = NULL; }
1355 | iteration_statement
1363 $$ = new(ctx) ast_compound_statement(true, NULL);
1364 $$->set_location(yylloc);
1366 | '{' statement_list '}'
1369 $$ = new(ctx) ast_compound_statement(true, $2);
1370 $$->set_location(yylloc);
1374 statement_no_new_scope:
1375 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1379 compound_statement_no_new_scope:
1383 $$ = new(ctx) ast_compound_statement(false, NULL);
1384 $$->set_location(yylloc);
1386 | '{' statement_list '}'
1389 $$ = new(ctx) ast_compound_statement(false, $2);
1390 $$->set_location(yylloc);
1398 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1403 $$->link.self_link();
1405 | statement_list statement
1408 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1412 $$->link.insert_before(& $2->link);
1416 expression_statement:
1420 $$ = new(ctx) ast_expression_statement(NULL);
1421 $$->set_location(yylloc);
1426 $$ = new(ctx) ast_expression_statement($1);
1427 $$->set_location(yylloc);
1431 selection_statement:
1432 IF '(' expression ')' selection_rest_statement
1434 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1436 $$->set_location(yylloc);
1440 selection_rest_statement:
1441 statement ELSE statement
1443 $$.then_statement = $1;
1444 $$.else_statement = $3;
1448 $$.then_statement = $1;
1449 $$.else_statement = NULL;
1456 $$ = (ast_node *) $1;
1458 | fully_specified_type IDENTIFIER '=' initializer
1461 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1462 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1463 decl->set_location(yylloc);
1464 declarator->set_location(yylloc);
1466 declarator->declarations.push_tail(&decl->link);
1472 SWITCH '(' expression ')' compound_statement
1480 iteration_statement:
1481 WHILE '(' condition ')' statement_no_new_scope
1484 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1485 NULL, $3, NULL, $5);
1486 $$->set_location(yylloc);
1488 | DO statement WHILE '(' expression ')' ';'
1491 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1492 NULL, $5, NULL, $2);
1493 $$->set_location(yylloc);
1495 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1498 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1499 $3, $4.cond, $4.rest, $6);
1500 $$->set_location(yylloc);
1505 expression_statement
1506 | declaration_statement
1523 | conditionopt ';' expression
1530 // Grammar Note: No 'goto'. Gotos are not supported.
1535 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1536 $$->set_location(yylloc);
1541 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1542 $$->set_location(yylloc);
1547 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1548 $$->set_location(yylloc);
1550 | RETURN expression ';'
1553 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1554 $$->set_location(yylloc);
1556 | DISCARD ';' // Fragment shader only.
1559 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1560 $$->set_location(yylloc);
1564 external_declaration:
1565 function_definition { $$ = $1; }
1566 | declaration { $$ = $1; }
1567 | pragma_statement { $$ = NULL; }
1570 function_definition:
1571 function_prototype compound_statement_no_new_scope
1574 $$ = new(ctx) ast_function_definition();
1575 $$->set_location(yylloc);