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
113 /* Reserved words that are not actually used in the grammar.
115 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
116 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
117 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
118 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
119 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
120 %token SIZEOF CAST NAMESPACE USING
124 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
125 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
126 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
127 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
128 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
131 %type <identifier> variable_identifier
132 %type <node> statement
133 %type <node> statement_list
134 %type <node> simple_statement
135 %type <n> precision_qualifier
136 %type <type_qualifier> type_qualifier
137 %type <type_qualifier> storage_qualifier
138 %type <type_qualifier> interpolation_qualifier
139 %type <type_qualifier> layout_qualifier
140 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
141 %type <type_specifier> type_specifier
142 %type <type_specifier> type_specifier_no_prec
143 %type <type_specifier> type_specifier_nonarray
144 %type <n> basic_type_specifier_nonarray
145 %type <fully_specified_type> fully_specified_type
146 %type <function> function_prototype
147 %type <function> function_header
148 %type <function> function_header_with_parameters
149 %type <function> function_declarator
150 %type <parameter_declarator> parameter_declarator
151 %type <parameter_declarator> parameter_declaration
152 %type <type_qualifier> parameter_qualifier
153 %type <type_qualifier> parameter_type_qualifier
154 %type <type_specifier> parameter_type_specifier
155 %type <function_definition> function_definition
156 %type <compound_statement> compound_statement_no_new_scope
157 %type <compound_statement> compound_statement
158 %type <node> statement_no_new_scope
159 %type <node> expression_statement
160 %type <expression> expression
161 %type <expression> primary_expression
162 %type <expression> assignment_expression
163 %type <expression> conditional_expression
164 %type <expression> logical_or_expression
165 %type <expression> logical_xor_expression
166 %type <expression> logical_and_expression
167 %type <expression> inclusive_or_expression
168 %type <expression> exclusive_or_expression
169 %type <expression> and_expression
170 %type <expression> equality_expression
171 %type <expression> relational_expression
172 %type <expression> shift_expression
173 %type <expression> additive_expression
174 %type <expression> multiplicative_expression
175 %type <expression> unary_expression
176 %type <expression> constant_expression
177 %type <expression> integer_expression
178 %type <expression> postfix_expression
179 %type <expression> function_call_header_with_parameters
180 %type <expression> function_call_header_no_parameters
181 %type <expression> function_call_header
182 %type <expression> function_call_generic
183 %type <expression> function_call_or_method
184 %type <expression> function_call
185 %type <n> assignment_operator
186 %type <n> unary_operator
187 %type <expression> function_identifier
188 %type <node> external_declaration
189 %type <declarator_list> init_declarator_list
190 %type <declarator_list> single_declaration
191 %type <expression> initializer
192 %type <node> declaration
193 %type <node> declaration_statement
194 %type <node> jump_statement
195 %type <struct_specifier> struct_specifier
196 %type <node> struct_declaration_list
197 %type <declarator_list> struct_declaration
198 %type <declaration> struct_declarator
199 %type <declaration> struct_declarator_list
200 %type <node> selection_statement
201 %type <selection_rest_statement> selection_rest_statement
202 %type <node> iteration_statement
203 %type <node> condition
204 %type <node> conditionopt
205 %type <node> for_init_statement
206 %type <for_rest_statement> for_rest_statement
210 version_statement extension_statement_list
212 _mesa_glsl_initialize_types(state);
214 external_declaration_list
218 /* blank - no #version specified: defaults are already set */
219 | VERSION INTCONSTANT EOL
223 state->es_shader = true;
227 /* FINISHME: Check against implementation support versions. */
228 state->language_version = $2;
231 _mesa_glsl_error(& @2, state, "Shading language version"
232 "%u is not supported\n", $2);
240 | PRAGMA_DEBUG_OFF EOL
241 | PRAGMA_OPTIMIZE_ON EOL
242 | PRAGMA_OPTIMIZE_OFF EOL
245 extension_statement_list:
247 | extension_statement_list extension_statement
251 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
253 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
259 external_declaration_list:
262 /* FINISHME: The NULL test is only required because 'precision'
263 * FINISHME: statements are not yet supported.
266 state->translation_unit.push_tail(& $1->link);
268 | external_declaration_list external_declaration
270 /* FINISHME: The NULL test is only required because 'precision'
271 * FINISHME: statements are not yet supported.
274 state->translation_unit.push_tail(& $2->link);
286 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
287 $$->set_location(yylloc);
288 $$->primary_expression.identifier = $1;
293 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
294 $$->set_location(yylloc);
295 $$->primary_expression.int_constant = $1;
300 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
301 $$->set_location(yylloc);
302 $$->primary_expression.uint_constant = $1;
307 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
308 $$->set_location(yylloc);
309 $$->primary_expression.float_constant = $1;
314 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
315 $$->set_location(yylloc);
316 $$->primary_expression.bool_constant = $1;
326 | postfix_expression '[' integer_expression ']'
329 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
330 $$->set_location(yylloc);
336 | postfix_expression '.' IDENTIFIER
339 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
340 $$->set_location(yylloc);
341 $$->primary_expression.identifier = $3;
343 | postfix_expression INC_OP
346 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
347 $$->set_location(yylloc);
349 | postfix_expression DEC_OP
352 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
353 $$->set_location(yylloc);
362 function_call_or_method
365 function_call_or_method:
366 function_call_generic
367 | postfix_expression '.' function_call_generic
370 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
371 $$->set_location(yylloc);
375 function_call_generic:
376 function_call_header_with_parameters ')'
377 | function_call_header_no_parameters ')'
380 function_call_header_no_parameters:
381 function_call_header VOID_TOK
382 | function_call_header
385 function_call_header_with_parameters:
386 function_call_header assignment_expression
389 $$->set_location(yylloc);
390 $$->expressions.push_tail(& $2->link);
392 | function_call_header_with_parameters ',' assignment_expression
395 $$->set_location(yylloc);
396 $$->expressions.push_tail(& $3->link);
400 // Grammar Note: Constructors look like functions, but lexical
401 // analysis recognized most of them as keywords. They are now
402 // recognized through "type_specifier".
403 function_call_header:
404 function_identifier '('
411 $$ = new(ctx) ast_function_expression($1);
412 $$->set_location(yylloc);
417 ast_expression *callee = new(ctx) ast_expression($1);
418 $$ = new(ctx) ast_function_expression(callee);
419 $$->set_location(yylloc);
424 ast_expression *callee = new(ctx) ast_expression($1);
425 $$ = new(ctx) ast_function_expression(callee);
426 $$->set_location(yylloc);
430 // Grammar Note: No traditional style type casts.
433 | INC_OP unary_expression
436 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
437 $$->set_location(yylloc);
439 | DEC_OP unary_expression
442 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
443 $$->set_location(yylloc);
445 | unary_operator unary_expression
448 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
449 $$->set_location(yylloc);
453 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
455 '+' { $$ = ast_plus; }
456 | '-' { $$ = ast_neg; }
457 | '!' { $$ = ast_logic_not; }
458 | '~' { $$ = ast_bit_not; }
461 multiplicative_expression:
463 | multiplicative_expression '*' unary_expression
466 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
467 $$->set_location(yylloc);
469 | multiplicative_expression '/' unary_expression
472 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
473 $$->set_location(yylloc);
475 | multiplicative_expression '%' unary_expression
478 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
479 $$->set_location(yylloc);
484 multiplicative_expression
485 | additive_expression '+' multiplicative_expression
488 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
489 $$->set_location(yylloc);
491 | additive_expression '-' multiplicative_expression
494 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
495 $$->set_location(yylloc);
501 | shift_expression LEFT_OP additive_expression
504 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
505 $$->set_location(yylloc);
507 | shift_expression RIGHT_OP additive_expression
510 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
511 $$->set_location(yylloc);
515 relational_expression:
517 | relational_expression '<' shift_expression
520 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
521 $$->set_location(yylloc);
523 | relational_expression '>' shift_expression
526 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
527 $$->set_location(yylloc);
529 | relational_expression LE_OP shift_expression
532 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
533 $$->set_location(yylloc);
535 | relational_expression GE_OP shift_expression
538 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
539 $$->set_location(yylloc);
544 relational_expression
545 | equality_expression EQ_OP relational_expression
548 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
549 $$->set_location(yylloc);
551 | equality_expression NE_OP relational_expression
554 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
555 $$->set_location(yylloc);
561 | and_expression '&' equality_expression
564 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
565 $$->set_location(yylloc);
569 exclusive_or_expression:
571 | exclusive_or_expression '^' and_expression
574 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
575 $$->set_location(yylloc);
579 inclusive_or_expression:
580 exclusive_or_expression
581 | inclusive_or_expression '|' exclusive_or_expression
584 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
585 $$->set_location(yylloc);
589 logical_and_expression:
590 inclusive_or_expression
591 | logical_and_expression AND_OP inclusive_or_expression
594 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
595 $$->set_location(yylloc);
599 logical_xor_expression:
600 logical_and_expression
601 | logical_xor_expression XOR_OP logical_and_expression
604 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
605 $$->set_location(yylloc);
609 logical_or_expression:
610 logical_xor_expression
611 | logical_or_expression OR_OP logical_xor_expression
614 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
615 $$->set_location(yylloc);
619 conditional_expression:
620 logical_or_expression
621 | logical_or_expression '?' expression ':' assignment_expression
624 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
625 $$->set_location(yylloc);
629 assignment_expression:
630 conditional_expression
631 | unary_expression assignment_operator assignment_expression
634 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
635 $$->set_location(yylloc);
640 '=' { $$ = ast_assign; }
641 | MUL_ASSIGN { $$ = ast_mul_assign; }
642 | DIV_ASSIGN { $$ = ast_div_assign; }
643 | MOD_ASSIGN { $$ = ast_mod_assign; }
644 | ADD_ASSIGN { $$ = ast_add_assign; }
645 | SUB_ASSIGN { $$ = ast_sub_assign; }
646 | LEFT_ASSIGN { $$ = ast_ls_assign; }
647 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
648 | AND_ASSIGN { $$ = ast_and_assign; }
649 | XOR_ASSIGN { $$ = ast_xor_assign; }
650 | OR_ASSIGN { $$ = ast_or_assign; }
654 assignment_expression
658 | expression ',' assignment_expression
661 if ($1->oper != ast_sequence) {
662 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
663 $$->set_location(yylloc);
664 $$->expressions.push_tail(& $1->link);
669 $$->expressions.push_tail(& $3->link);
674 conditional_expression
678 function_prototype ';'
682 | init_declarator_list ';'
686 | PRECISION precision_qualifier type_specifier_no_prec ';'
688 if (($3->type_specifier != ast_float)
689 && ($3->type_specifier != ast_int)) {
690 _mesa_glsl_error(& @3, state, "global precision qualifier can "
691 "only be applied to `int' or `float'\n");
695 $$ = NULL; /* FINISHME */
700 function_declarator ')'
705 | function_header_with_parameters
708 function_header_with_parameters:
709 function_header parameter_declaration
712 $$->parameters.push_tail(& $2->link);
714 | function_header_with_parameters ',' parameter_declaration
717 $$->parameters.push_tail(& $3->link);
722 fully_specified_type IDENTIFIER '('
725 $$ = new(ctx) ast_function();
726 $$->set_location(yylloc);
727 $$->return_type = $1;
732 parameter_declarator:
733 type_specifier IDENTIFIER
736 $$ = new(ctx) ast_parameter_declarator();
737 $$->set_location(yylloc);
738 $$->type = new(ctx) ast_fully_specified_type();
739 $$->type->set_location(yylloc);
740 $$->type->specifier = $1;
743 | type_specifier IDENTIFIER '[' constant_expression ']'
746 $$ = new(ctx) ast_parameter_declarator();
747 $$->set_location(yylloc);
748 $$->type = new(ctx) ast_fully_specified_type();
749 $$->type->set_location(yylloc);
750 $$->type->specifier = $1;
757 parameter_declaration:
758 parameter_type_qualifier parameter_qualifier parameter_declarator
760 $1.flags.i |= $2.flags.i;
763 $$->type->qualifier = $1;
765 | parameter_qualifier parameter_declarator
768 $$->type->qualifier = $1;
770 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
773 $1.flags.i |= $2.flags.i;
775 $$ = new(ctx) ast_parameter_declarator();
776 $$->set_location(yylloc);
777 $$->type = new(ctx) ast_fully_specified_type();
778 $$->type->qualifier = $1;
779 $$->type->specifier = $3;
781 | parameter_qualifier parameter_type_specifier
784 $$ = new(ctx) ast_parameter_declarator();
785 $$->set_location(yylloc);
786 $$->type = new(ctx) ast_fully_specified_type();
787 $$->type->qualifier = $1;
788 $$->type->specifier = $2;
795 memset(& $$, 0, sizeof($$));
799 memset(& $$, 0, sizeof($$));
804 memset(& $$, 0, sizeof($$));
809 memset(& $$, 0, sizeof($$));
815 parameter_type_specifier:
819 init_declarator_list:
821 | init_declarator_list ',' IDENTIFIER
824 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
825 decl->set_location(yylloc);
828 $$->declarations.push_tail(&decl->link);
830 | init_declarator_list ',' IDENTIFIER '[' ']'
833 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
834 decl->set_location(yylloc);
837 $$->declarations.push_tail(&decl->link);
839 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
842 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
843 decl->set_location(yylloc);
846 $$->declarations.push_tail(&decl->link);
848 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
851 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
852 decl->set_location(yylloc);
855 $$->declarations.push_tail(&decl->link);
857 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
860 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
861 decl->set_location(yylloc);
864 $$->declarations.push_tail(&decl->link);
866 | init_declarator_list ',' IDENTIFIER '=' initializer
869 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
870 decl->set_location(yylloc);
873 $$->declarations.push_tail(&decl->link);
877 // Grammar Note: No 'enum', or 'typedef'.
882 if ($1->specifier->type_specifier != ast_struct) {
883 _mesa_glsl_error(& @1, state, "empty declaration list\n");
886 $$ = new(ctx) ast_declarator_list($1);
887 $$->set_location(yylloc);
890 | fully_specified_type IDENTIFIER
893 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
895 $$ = new(ctx) ast_declarator_list($1);
896 $$->set_location(yylloc);
897 $$->declarations.push_tail(&decl->link);
899 | fully_specified_type IDENTIFIER '[' ']'
902 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
904 $$ = new(ctx) ast_declarator_list($1);
905 $$->set_location(yylloc);
906 $$->declarations.push_tail(&decl->link);
908 | fully_specified_type IDENTIFIER '[' constant_expression ']'
911 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
913 $$ = new(ctx) ast_declarator_list($1);
914 $$->set_location(yylloc);
915 $$->declarations.push_tail(&decl->link);
917 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
920 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
922 $$ = new(ctx) ast_declarator_list($1);
923 $$->set_location(yylloc);
924 $$->declarations.push_tail(&decl->link);
926 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
929 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
931 $$ = new(ctx) ast_declarator_list($1);
932 $$->set_location(yylloc);
933 $$->declarations.push_tail(&decl->link);
935 | fully_specified_type IDENTIFIER '=' initializer
938 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
940 $$ = new(ctx) ast_declarator_list($1);
941 $$->set_location(yylloc);
942 $$->declarations.push_tail(&decl->link);
944 | INVARIANT IDENTIFIER // Vertex only.
947 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
949 $$ = new(ctx) ast_declarator_list(NULL);
950 $$->set_location(yylloc);
951 $$->invariant = true;
953 $$->declarations.push_tail(&decl->link);
957 fully_specified_type:
961 $$ = new(ctx) ast_fully_specified_type();
962 $$->set_location(yylloc);
965 | type_qualifier type_specifier
968 $$ = new(ctx) ast_fully_specified_type();
969 $$->set_location(yylloc);
976 LAYOUT_TOK '(' layout_qualifier_id_list ')'
982 layout_qualifier_id_list:
984 | layout_qualifier_id_list ',' layout_qualifier_id
986 if (($1.flags.i & $3.flags.i) != 0) {
987 _mesa_glsl_error(& @3, state,
988 "duplicate layout qualifiers used\n");
992 $$.flags.i = $1.flags.i | $3.flags.i;
994 if ($1.flags.q.explicit_location)
995 $$.location = $1.location;
997 if ($3.flags.q.explicit_location)
998 $$.location = $3.location;
1002 layout_qualifier_id:
1005 bool got_one = false;
1007 memset(& $$, 0, sizeof($$));
1009 if (state->ARB_fragment_coord_conventions_enable) {
1010 if (strcmp($1, "origin_upper_left") == 0) {
1012 $$.flags.q.origin_upper_left = 1;
1013 } else if (strcmp($1, "pixel_center_integer") == 0) {
1015 $$.flags.q.pixel_center_integer = 1;
1019 /* If the identifier didn't match any known layout identifiers,
1023 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1026 } else if (state->ARB_fragment_coord_conventions_warn) {
1027 _mesa_glsl_warning(& @1, state,
1028 "GL_ARB_fragment_coord_conventions layout "
1029 "identifier `%s' used\n", $1);
1032 | IDENTIFIER '=' INTCONSTANT
1034 bool got_one = false;
1036 memset(& $$, 0, sizeof($$));
1038 if (state->ARB_explicit_attrib_location_enable) {
1039 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1040 * FINISHME: GLSL 1.30 (or later) are supported.
1042 if (strcmp("location", $1) == 0) {
1045 $$.flags.q.explicit_location = 1;
1050 _mesa_glsl_error(& @3, state,
1051 "invalid location %d specified\n", $3);
1057 /* If the identifier didn't match any known layout identifiers,
1061 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1064 } else if (state->ARB_explicit_attrib_location_warn) {
1065 _mesa_glsl_warning(& @1, state,
1066 "GL_ARB_explicit_attrib_location layout "
1067 "identifier `%s' used\n", $1);
1072 interpolation_qualifier:
1075 memset(& $$, 0, sizeof($$));
1076 $$.flags.q.smooth = 1;
1080 memset(& $$, 0, sizeof($$));
1081 $$.flags.q.flat = 1;
1085 memset(& $$, 0, sizeof($$));
1086 $$.flags.q.noperspective = 1;
1090 parameter_type_qualifier:
1093 memset(& $$, 0, sizeof($$));
1094 $$.flags.q.constant = 1;
1101 | layout_qualifier storage_qualifier
1104 $$.flags.i |= $2.flags.i;
1106 | interpolation_qualifier
1107 | interpolation_qualifier storage_qualifier
1110 $$.flags.i |= $2.flags.i;
1112 | INVARIANT storage_qualifier
1115 $$.flags.q.invariant = 1;
1117 | INVARIANT interpolation_qualifier storage_qualifier
1120 $$.flags.i |= $3.flags.i;
1121 $$.flags.q.invariant = 1;
1125 memset(& $$, 0, sizeof($$));
1126 $$.flags.q.invariant = 1;
1133 memset(& $$, 0, sizeof($$));
1134 $$.flags.q.constant = 1;
1138 memset(& $$, 0, sizeof($$));
1139 $$.flags.q.attribute = 1;
1143 memset(& $$, 0, sizeof($$));
1144 $$.flags.q.varying = 1;
1148 memset(& $$, 0, sizeof($$));
1149 $$.flags.q.centroid = 1;
1150 $$.flags.q.varying = 1;
1154 memset(& $$, 0, sizeof($$));
1159 memset(& $$, 0, sizeof($$));
1164 memset(& $$, 0, sizeof($$));
1165 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1169 memset(& $$, 0, sizeof($$));
1170 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1174 memset(& $$, 0, sizeof($$));
1175 $$.flags.q.uniform = 1;
1180 type_specifier_no_prec
1181 | precision_qualifier type_specifier_no_prec
1188 type_specifier_no_prec:
1189 type_specifier_nonarray
1190 | type_specifier_nonarray '[' ']'
1193 $$->is_array = true;
1194 $$->array_size = NULL;
1196 | type_specifier_nonarray '[' constant_expression ']'
1199 $$->is_array = true;
1200 $$->array_size = $3;
1204 type_specifier_nonarray:
1205 basic_type_specifier_nonarray
1208 $$ = new(ctx) ast_type_specifier($1);
1209 $$->set_location(yylloc);
1214 $$ = new(ctx) ast_type_specifier($1);
1215 $$->set_location(yylloc);
1220 $$ = new(ctx) ast_type_specifier($1);
1221 $$->set_location(yylloc);
1225 basic_type_specifier_nonarray:
1226 VOID_TOK { $$ = ast_void; }
1227 | FLOAT_TOK { $$ = ast_float; }
1228 | INT_TOK { $$ = ast_int; }
1229 | UINT_TOK { $$ = ast_uint; }
1230 | BOOL_TOK { $$ = ast_bool; }
1231 | VEC2 { $$ = ast_vec2; }
1232 | VEC3 { $$ = ast_vec3; }
1233 | VEC4 { $$ = ast_vec4; }
1234 | BVEC2 { $$ = ast_bvec2; }
1235 | BVEC3 { $$ = ast_bvec3; }
1236 | BVEC4 { $$ = ast_bvec4; }
1237 | IVEC2 { $$ = ast_ivec2; }
1238 | IVEC3 { $$ = ast_ivec3; }
1239 | IVEC4 { $$ = ast_ivec4; }
1240 | UVEC2 { $$ = ast_uvec2; }
1241 | UVEC3 { $$ = ast_uvec3; }
1242 | UVEC4 { $$ = ast_uvec4; }
1243 | MAT2X2 { $$ = ast_mat2; }
1244 | MAT2X3 { $$ = ast_mat2x3; }
1245 | MAT2X4 { $$ = ast_mat2x4; }
1246 | MAT3X2 { $$ = ast_mat3x2; }
1247 | MAT3X3 { $$ = ast_mat3; }
1248 | MAT3X4 { $$ = ast_mat3x4; }
1249 | MAT4X2 { $$ = ast_mat4x2; }
1250 | MAT4X3 { $$ = ast_mat4x3; }
1251 | MAT4X4 { $$ = ast_mat4; }
1252 | SAMPLER1D { $$ = ast_sampler1d; }
1253 | SAMPLER2D { $$ = ast_sampler2d; }
1254 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1255 | SAMPLER3D { $$ = ast_sampler3d; }
1256 | SAMPLERCUBE { $$ = ast_samplercube; }
1257 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1258 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1259 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1260 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1261 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1262 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1263 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1264 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1265 | ISAMPLER1D { $$ = ast_isampler1d; }
1266 | ISAMPLER2D { $$ = ast_isampler2d; }
1267 | ISAMPLER3D { $$ = ast_isampler3d; }
1268 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1269 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1270 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1271 | USAMPLER1D { $$ = ast_usampler1d; }
1272 | USAMPLER2D { $$ = ast_usampler2d; }
1273 | USAMPLER3D { $$ = ast_usampler3d; }
1274 | USAMPLERCUBE { $$ = ast_usamplercube; }
1275 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1276 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1279 precision_qualifier:
1281 if (!state->es_shader && state->language_version < 130)
1282 _mesa_glsl_error(& @1, state,
1283 "precision qualifier forbidden "
1284 "in GLSL %d.%d (1.30 or later "
1286 state->language_version / 100,
1287 state->language_version % 100);
1289 $$ = ast_precision_high;
1292 if (!state->es_shader && state->language_version < 130)
1293 _mesa_glsl_error(& @1, state,
1294 "precision qualifier forbidden "
1295 "in GLSL %d.%d (1.30 or later "
1297 state->language_version / 100,
1298 state->language_version % 100);
1300 $$ = ast_precision_medium;
1303 if (!state->es_shader && state->language_version < 130)
1304 _mesa_glsl_error(& @1, state,
1305 "precision qualifier forbidden "
1306 "in GLSL %d.%d (1.30 or later "
1308 state->language_version / 100,
1309 state->language_version % 100);
1311 $$ = ast_precision_low;
1316 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1319 $$ = new(ctx) ast_struct_specifier($2, $4);
1320 $$->set_location(yylloc);
1322 | STRUCT '{' struct_declaration_list '}'
1325 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1326 $$->set_location(yylloc);
1330 struct_declaration_list:
1333 $$ = (ast_node *) $1;
1334 $1->link.self_link();
1336 | struct_declaration_list struct_declaration
1338 $$ = (ast_node *) $1;
1339 $$->link.insert_before(& $2->link);
1344 type_specifier struct_declarator_list ';'
1347 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1348 type->set_location(yylloc);
1350 type->specifier = $1;
1351 $$ = new(ctx) ast_declarator_list(type);
1352 $$->set_location(yylloc);
1354 $$->declarations.push_degenerate_list_at_head(& $2->link);
1358 struct_declarator_list:
1362 $1->link.self_link();
1364 | struct_declarator_list ',' struct_declarator
1367 $$->link.insert_before(& $3->link);
1375 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1376 $$->set_location(yylloc);
1378 | IDENTIFIER '[' constant_expression ']'
1381 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1382 $$->set_location(yylloc);
1387 assignment_expression
1390 declaration_statement:
1394 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1397 compound_statement { $$ = (ast_node *) $1; }
1402 declaration_statement
1403 | expression_statement
1404 | selection_statement
1405 | switch_statement { $$ = NULL; }
1406 | case_label { $$ = NULL; }
1407 | iteration_statement
1415 $$ = new(ctx) ast_compound_statement(true, NULL);
1416 $$->set_location(yylloc);
1418 | '{' statement_list '}'
1421 $$ = new(ctx) ast_compound_statement(true, $2);
1422 $$->set_location(yylloc);
1426 statement_no_new_scope:
1427 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1431 compound_statement_no_new_scope:
1435 $$ = new(ctx) ast_compound_statement(false, NULL);
1436 $$->set_location(yylloc);
1438 | '{' statement_list '}'
1441 $$ = new(ctx) ast_compound_statement(false, $2);
1442 $$->set_location(yylloc);
1450 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1455 $$->link.self_link();
1457 | statement_list statement
1460 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1464 $$->link.insert_before(& $2->link);
1468 expression_statement:
1472 $$ = new(ctx) ast_expression_statement(NULL);
1473 $$->set_location(yylloc);
1478 $$ = new(ctx) ast_expression_statement($1);
1479 $$->set_location(yylloc);
1483 selection_statement:
1484 IF '(' expression ')' selection_rest_statement
1486 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1488 $$->set_location(yylloc);
1492 selection_rest_statement:
1493 statement ELSE statement
1495 $$.then_statement = $1;
1496 $$.else_statement = $3;
1500 $$.then_statement = $1;
1501 $$.else_statement = NULL;
1508 $$ = (ast_node *) $1;
1510 | fully_specified_type IDENTIFIER '=' initializer
1513 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1514 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1515 decl->set_location(yylloc);
1516 declarator->set_location(yylloc);
1518 declarator->declarations.push_tail(&decl->link);
1524 SWITCH '(' expression ')' compound_statement
1532 iteration_statement:
1533 WHILE '(' condition ')' statement_no_new_scope
1536 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1537 NULL, $3, NULL, $5);
1538 $$->set_location(yylloc);
1540 | DO statement WHILE '(' expression ')' ';'
1543 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1544 NULL, $5, NULL, $2);
1545 $$->set_location(yylloc);
1547 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1550 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1551 $3, $4.cond, $4.rest, $6);
1552 $$->set_location(yylloc);
1557 expression_statement
1558 | declaration_statement
1575 | conditionopt ';' expression
1582 // Grammar Note: No 'goto'. Gotos are not supported.
1587 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1588 $$->set_location(yylloc);
1593 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1594 $$->set_location(yylloc);
1599 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1600 $$->set_location(yylloc);
1602 | RETURN expression ';'
1605 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1606 $$->set_location(yylloc);
1608 | DISCARD ';' // Fragment shader only.
1611 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1612 $$->set_location(yylloc);
1616 external_declaration:
1617 function_definition { $$ = $1; }
1618 | declaration { $$ = $1; }
1619 | pragma_statement { $$ = NULL; }
1622 function_definition:
1623 function_prototype compound_statement_no_new_scope
1626 $$ = new(ctx) ast_function_definition();
1627 $$->set_location(yylloc);