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}
51 %name-prefix "_mesa_glsl_"
59 struct ast_type_qualifier q;
63 struct ast_node *node;
64 struct ast_type_specifier *type_specifier;
65 struct ast_fully_specified_type *fully_specified_type;
66 struct ast_function *function;
67 struct ast_parameter_declarator *parameter_declarator;
68 struct ast_function_definition *function_definition;
69 struct ast_compound_statement *compound_statement;
70 struct ast_expression *expression;
71 struct ast_declarator_list *declarator_list;
72 struct ast_struct_specifier *struct_specifier;
73 struct ast_declaration *declaration;
76 struct ast_node *cond;
77 struct ast_expression *rest;
81 %token ATTRIBUTE CONST_TOK BOOL FLOAT INT UINT
82 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
83 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
84 %token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
85 %token NOPERSPECTIVE FLAT SMOOTH
86 %token MAT2X2 MAT2X3 MAT2X4
87 %token MAT3X2 MAT3X3 MAT3X4
88 %token MAT4X2 MAT4X3 MAT4X4
89 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
90 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
91 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
92 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
93 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
94 %token STRUCT VOID WHILE
95 %token <identifier> IDENTIFIER
96 %token <real> FLOATCONSTANT
97 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
98 %token <identifier> FIELD_SELECTION
99 %token LEFT_OP RIGHT_OP
100 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
101 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
102 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
105 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
107 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
110 /* Reserved words that are not actually used in the grammar.
112 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
113 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
114 %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
115 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
116 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
117 %token SIZEOF CAST NAMESPACE USING
121 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
122 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
123 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
124 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
125 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
128 %type <identifier> variable_identifier
129 %type <node> statement
130 %type <node> statement_list
131 %type <node> simple_statement
132 %type <node> statement_matched
133 %type <node> statement_unmatched
134 %type <n> precision_qualifier
135 %type <type_qualifier> type_qualifier
136 %type <type_qualifier> storage_qualifier
137 %type <type_qualifier> interpolation_qualifier
138 %type <type_qualifier> opt_layout_qualifier layout_qualifier
139 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
140 %type <type_specifier> type_specifier
141 %type <type_specifier> type_specifier_no_prec
142 %type <type_specifier> type_specifier_nonarray
143 %type <n> basic_type_specifier_nonarray
144 %type <fully_specified_type> fully_specified_type
145 %type <function> function_prototype
146 %type <function> function_header
147 %type <function> function_header_with_parameters
148 %type <function> function_declarator
149 %type <parameter_declarator> parameter_declarator
150 %type <parameter_declarator> parameter_declaration
151 %type <type_qualifier> parameter_qualifier
152 %type <type_qualifier> parameter_type_qualifier
153 %type <type_specifier> parameter_type_specifier
154 %type <function_definition> function_definition
155 %type <compound_statement> compound_statement_no_new_scope
156 %type <compound_statement> compound_statement
157 %type <node> statement_no_new_scope
158 %type <node> expression_statement
159 %type <expression> expression
160 %type <expression> primary_expression
161 %type <expression> assignment_expression
162 %type <expression> conditional_expression
163 %type <expression> logical_or_expression
164 %type <expression> logical_xor_expression
165 %type <expression> logical_and_expression
166 %type <expression> inclusive_or_expression
167 %type <expression> exclusive_or_expression
168 %type <expression> and_expression
169 %type <expression> equality_expression
170 %type <expression> relational_expression
171 %type <expression> shift_expression
172 %type <expression> additive_expression
173 %type <expression> multiplicative_expression
174 %type <expression> unary_expression
175 %type <expression> constant_expression
176 %type <expression> integer_expression
177 %type <expression> postfix_expression
178 %type <expression> function_call_header_with_parameters
179 %type <expression> function_call_header_no_parameters
180 %type <expression> function_call_header
181 %type <expression> function_call_generic
182 %type <expression> function_call_or_method
183 %type <expression> function_call
184 %type <n> assignment_operator
185 %type <n> unary_operator
186 %type <expression> function_identifier
187 %type <node> external_declaration
188 %type <declarator_list> init_declarator_list
189 %type <declarator_list> single_declaration
190 %type <expression> initializer
191 %type <node> declaration
192 %type <node> declaration_statement
193 %type <node> jump_statement
194 %type <struct_specifier> struct_specifier
195 %type <node> struct_declaration_list
196 %type <declarator_list> struct_declaration
197 %type <declaration> struct_declarator
198 %type <declaration> struct_declarator_list
199 %type <node> selection_statement_matched
200 %type <node> selection_statement_unmatched
201 %type <node> iteration_statement
202 %type <node> condition
203 %type <node> conditionopt
204 %type <node> for_init_statement
205 %type <for_rest_statement> for_rest_statement
209 version_statement extension_statement_list
211 _mesa_glsl_initialize_types(state);
213 external_declaration_list
217 /* blank - no #version specified */
219 state->language_version = 110;
221 | VERSION INTCONSTANT EOL
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);
238 extension_statement_list:
240 | extension_statement_list extension_statement
244 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
246 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
252 external_declaration_list:
255 /* FINISHME: The NULL test is only required because 'precision'
256 * FINISHME: statements are not yet supported.
259 state->translation_unit.push_tail(& $1->link);
261 | external_declaration_list external_declaration
263 /* FINISHME: The NULL test is only required because 'precision'
264 * FINISHME: statements are not yet supported.
267 state->translation_unit.push_tail(& $2->link);
279 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
280 $$->set_location(yylloc);
281 $$->primary_expression.identifier = $1;
286 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
287 $$->set_location(yylloc);
288 $$->primary_expression.int_constant = $1;
293 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
294 $$->set_location(yylloc);
295 $$->primary_expression.uint_constant = $1;
300 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
301 $$->set_location(yylloc);
302 $$->primary_expression.float_constant = $1;
307 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
308 $$->set_location(yylloc);
309 $$->primary_expression.bool_constant = $1;
319 | postfix_expression '[' integer_expression ']'
322 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
323 $$->set_location(yylloc);
329 | postfix_expression '.' IDENTIFIER
332 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
333 $$->set_location(yylloc);
334 $$->primary_expression.identifier = $3;
336 | postfix_expression INC_OP
339 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
340 $$->set_location(yylloc);
342 | postfix_expression DEC_OP
345 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
346 $$->set_location(yylloc);
355 function_call_or_method
358 function_call_or_method:
359 function_call_generic
360 | postfix_expression '.' function_call_generic
363 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
364 $$->set_location(yylloc);
368 function_call_generic:
369 function_call_header_with_parameters ')'
370 | function_call_header_no_parameters ')'
373 function_call_header_no_parameters:
374 function_call_header VOID
375 | function_call_header
378 function_call_header_with_parameters:
379 function_call_header assignment_expression
382 $$->set_location(yylloc);
383 $$->expressions.push_tail(& $2->link);
385 | function_call_header_with_parameters ',' assignment_expression
388 $$->set_location(yylloc);
389 $$->expressions.push_tail(& $3->link);
393 // Grammar Note: Constructors look like functions, but lexical
394 // analysis recognized most of them as keywords. They are now
395 // recognized through "type_specifier".
396 function_call_header:
397 function_identifier '('
404 $$ = new(ctx) ast_function_expression($1);
405 $$->set_location(yylloc);
410 ast_expression *callee = new(ctx) ast_expression($1);
411 $$ = new(ctx) ast_function_expression(callee);
412 $$->set_location(yylloc);
417 ast_expression *callee = new(ctx) ast_expression($1);
418 $$ = new(ctx) ast_function_expression(callee);
419 $$->set_location(yylloc);
423 // Grammar Note: No traditional style type casts.
426 | INC_OP unary_expression
429 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
430 $$->set_location(yylloc);
432 | DEC_OP unary_expression
435 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
436 $$->set_location(yylloc);
438 | unary_operator unary_expression
441 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
442 $$->set_location(yylloc);
446 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
448 '+' { $$ = ast_plus; }
449 | '-' { $$ = ast_neg; }
450 | '!' { $$ = ast_logic_not; }
451 | '~' { $$ = ast_bit_not; }
454 multiplicative_expression:
456 | multiplicative_expression '*' unary_expression
459 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
460 $$->set_location(yylloc);
462 | multiplicative_expression '/' unary_expression
465 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
466 $$->set_location(yylloc);
468 | multiplicative_expression '%' unary_expression
471 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
472 $$->set_location(yylloc);
477 multiplicative_expression
478 | additive_expression '+' multiplicative_expression
481 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
482 $$->set_location(yylloc);
484 | additive_expression '-' multiplicative_expression
487 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
488 $$->set_location(yylloc);
494 | shift_expression LEFT_OP additive_expression
497 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
498 $$->set_location(yylloc);
500 | shift_expression RIGHT_OP additive_expression
503 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
504 $$->set_location(yylloc);
508 relational_expression:
510 | relational_expression '<' shift_expression
513 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
514 $$->set_location(yylloc);
516 | relational_expression '>' shift_expression
519 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
520 $$->set_location(yylloc);
522 | relational_expression LE_OP shift_expression
525 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
526 $$->set_location(yylloc);
528 | relational_expression GE_OP shift_expression
531 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
532 $$->set_location(yylloc);
537 relational_expression
538 | equality_expression EQ_OP relational_expression
541 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
542 $$->set_location(yylloc);
544 | equality_expression NE_OP relational_expression
547 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
548 $$->set_location(yylloc);
554 | and_expression '&' equality_expression
557 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
558 $$->set_location(yylloc);
562 exclusive_or_expression:
564 | exclusive_or_expression '^' and_expression
567 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
568 $$->set_location(yylloc);
572 inclusive_or_expression:
573 exclusive_or_expression
574 | inclusive_or_expression '|' exclusive_or_expression
577 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
578 $$->set_location(yylloc);
582 logical_and_expression:
583 inclusive_or_expression
584 | logical_and_expression AND_OP inclusive_or_expression
587 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
588 $$->set_location(yylloc);
592 logical_xor_expression:
593 logical_and_expression
594 | logical_xor_expression XOR_OP logical_and_expression
597 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
598 $$->set_location(yylloc);
602 logical_or_expression:
603 logical_xor_expression
604 | logical_or_expression OR_OP logical_xor_expression
607 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
608 $$->set_location(yylloc);
612 conditional_expression:
613 logical_or_expression
614 | logical_or_expression '?' expression ':' assignment_expression
617 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
618 $$->set_location(yylloc);
622 assignment_expression:
623 conditional_expression
624 | unary_expression assignment_operator assignment_expression
627 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
628 $$->set_location(yylloc);
633 '=' { $$ = ast_assign; }
634 | MUL_ASSIGN { $$ = ast_mul_assign; }
635 | DIV_ASSIGN { $$ = ast_div_assign; }
636 | MOD_ASSIGN { $$ = ast_mod_assign; }
637 | ADD_ASSIGN { $$ = ast_add_assign; }
638 | SUB_ASSIGN { $$ = ast_sub_assign; }
639 | LEFT_ASSIGN { $$ = ast_ls_assign; }
640 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
641 | AND_ASSIGN { $$ = ast_and_assign; }
642 | XOR_ASSIGN { $$ = ast_xor_assign; }
643 | OR_ASSIGN { $$ = ast_or_assign; }
647 assignment_expression
651 | expression ',' assignment_expression
654 if ($1->oper != ast_sequence) {
655 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
656 $$->set_location(yylloc);
657 $$->expressions.push_tail(& $1->link);
662 $$->expressions.push_tail(& $3->link);
667 conditional_expression
671 function_prototype ';'
675 | init_declarator_list ';'
679 | PRECISION precision_qualifier type_specifier_no_prec ';'
681 if (($3->type_specifier != ast_float)
682 && ($3->type_specifier != ast_int)) {
683 _mesa_glsl_error(& @3, state, "global precision qualifier can "
684 "only be applied to `int' or `float'\n");
688 $$ = NULL; /* FINISHME */
693 function_declarator ')'
698 | function_header_with_parameters
701 function_header_with_parameters:
702 function_header parameter_declaration
705 $$->parameters.push_tail(& $2->link);
707 | function_header_with_parameters ',' parameter_declaration
710 $$->parameters.push_tail(& $3->link);
715 fully_specified_type IDENTIFIER '('
718 $$ = new(ctx) ast_function();
719 $$->set_location(yylloc);
720 $$->return_type = $1;
725 parameter_declarator:
726 type_specifier IDENTIFIER
729 $$ = new(ctx) ast_parameter_declarator();
730 $$->set_location(yylloc);
731 $$->type = new(ctx) ast_fully_specified_type();
732 $$->type->set_location(yylloc);
733 $$->type->specifier = $1;
736 | type_specifier IDENTIFIER '[' constant_expression ']'
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;
750 parameter_declaration:
751 parameter_type_qualifier parameter_qualifier parameter_declarator
756 $$->type->qualifier = $1.q;
758 | parameter_qualifier parameter_declarator
761 $$->type->qualifier = $1.q;
763 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
768 $$ = new(ctx) ast_parameter_declarator();
769 $$->set_location(yylloc);
770 $$->type = new(ctx) ast_fully_specified_type();
771 $$->type->qualifier = $1.q;
772 $$->type->specifier = $3;
774 | parameter_qualifier parameter_type_specifier
777 $$ = new(ctx) ast_parameter_declarator();
778 $$->set_location(yylloc);
779 $$->type = new(ctx) ast_fully_specified_type();
780 $$->type->qualifier = $1.q;
781 $$->type->specifier = $2;
786 /* empty */ { $$.i = 0; }
787 | IN { $$.i = 0; $$.q.in = 1; }
788 | OUT { $$.i = 0; $$.q.out = 1; }
789 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
792 parameter_type_specifier:
796 init_declarator_list:
798 | init_declarator_list ',' IDENTIFIER
801 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
802 decl->set_location(yylloc);
805 $$->declarations.push_tail(&decl->link);
807 | init_declarator_list ',' IDENTIFIER '[' ']'
810 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
811 decl->set_location(yylloc);
814 $$->declarations.push_tail(&decl->link);
816 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
819 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
820 decl->set_location(yylloc);
823 $$->declarations.push_tail(&decl->link);
825 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
828 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
829 decl->set_location(yylloc);
832 $$->declarations.push_tail(&decl->link);
834 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
837 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
838 decl->set_location(yylloc);
841 $$->declarations.push_tail(&decl->link);
843 | init_declarator_list ',' IDENTIFIER '=' initializer
846 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
847 decl->set_location(yylloc);
850 $$->declarations.push_tail(&decl->link);
854 // Grammar Note: No 'enum', or 'typedef'.
859 if ($1->specifier->type_specifier != ast_struct) {
860 _mesa_glsl_error(& @1, state, "empty declaration list\n");
863 $$ = new(ctx) ast_declarator_list($1);
864 $$->set_location(yylloc);
867 | fully_specified_type IDENTIFIER
870 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
872 $$ = new(ctx) ast_declarator_list($1);
873 $$->set_location(yylloc);
874 $$->declarations.push_tail(&decl->link);
876 | fully_specified_type IDENTIFIER '[' ']'
879 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
881 $$ = new(ctx) ast_declarator_list($1);
882 $$->set_location(yylloc);
883 $$->declarations.push_tail(&decl->link);
885 | fully_specified_type IDENTIFIER '[' constant_expression ']'
888 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
890 $$ = new(ctx) ast_declarator_list($1);
891 $$->set_location(yylloc);
892 $$->declarations.push_tail(&decl->link);
894 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
897 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
899 $$ = new(ctx) ast_declarator_list($1);
900 $$->set_location(yylloc);
901 $$->declarations.push_tail(&decl->link);
903 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
906 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
908 $$ = new(ctx) ast_declarator_list($1);
909 $$->set_location(yylloc);
910 $$->declarations.push_tail(&decl->link);
912 | fully_specified_type IDENTIFIER '=' initializer
915 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
917 $$ = new(ctx) ast_declarator_list($1);
918 $$->set_location(yylloc);
919 $$->declarations.push_tail(&decl->link);
921 | INVARIANT IDENTIFIER // Vertex only.
924 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
926 $$ = new(ctx) ast_declarator_list(NULL);
927 $$->set_location(yylloc);
928 $$->invariant = true;
930 $$->declarations.push_tail(&decl->link);
934 fully_specified_type:
938 $$ = new(ctx) ast_fully_specified_type();
939 $$->set_location(yylloc);
942 | type_qualifier type_specifier
945 $$ = new(ctx) ast_fully_specified_type();
946 $$->set_location(yylloc);
947 $$->qualifier = $1.q;
952 opt_layout_qualifier:
958 LAYOUT_TOK '(' layout_qualifier_id_list ')'
964 layout_qualifier_id_list:
966 | layout_qualifier_id_list ',' layout_qualifier_id
977 if (state->ARB_fragment_coord_conventions_enable) {
978 bool got_one = false;
980 if (strcmp($1, "origin_upper_left") == 0) {
982 $$.q.origin_upper_left = 1;
983 } else if (strcmp($1, "pixel_center_integer") == 0) {
985 $$.q.pixel_center_integer = 1;
988 if (state->ARB_fragment_coord_conventions_warn && got_one) {
989 _mesa_glsl_warning(& @1, state,
990 "GL_ARB_fragment_coord_conventions layout "
991 "identifier `%s' used\n", $1);
995 /* If the identifier didn't match any known layout identifiers,
999 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1006 interpolation_qualifier:
1007 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1008 | FLAT { $$.i = 0; $$.q.flat = 1; }
1009 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1012 parameter_type_qualifier:
1013 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1018 | interpolation_qualifier type_qualifier
1022 | INVARIANT type_qualifier
1030 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1031 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1032 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1033 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1034 | opt_layout_qualifier IN { $$.i = 0; $$.q.in = 1; }
1035 | OUT { $$.i = 0; $$.q.out = 1; }
1036 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1037 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1038 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1042 type_specifier_no_prec
1043 | precision_qualifier type_specifier_no_prec
1050 type_specifier_no_prec:
1051 type_specifier_nonarray
1052 | type_specifier_nonarray '[' ']'
1055 $$->is_array = true;
1056 $$->array_size = NULL;
1058 | type_specifier_nonarray '[' constant_expression ']'
1061 $$->is_array = true;
1062 $$->array_size = $3;
1066 type_specifier_nonarray:
1067 basic_type_specifier_nonarray
1070 $$ = new(ctx) ast_type_specifier($1);
1071 $$->set_location(yylloc);
1076 $$ = new(ctx) ast_type_specifier($1);
1077 $$->set_location(yylloc);
1082 $$ = new(ctx) ast_type_specifier($1);
1083 $$->set_location(yylloc);
1087 basic_type_specifier_nonarray:
1088 VOID { $$ = ast_void; }
1089 | FLOAT { $$ = ast_float; }
1090 | INT { $$ = ast_int; }
1091 | UINT { $$ = ast_uint; }
1092 | BOOL { $$ = ast_bool; }
1093 | VEC2 { $$ = ast_vec2; }
1094 | VEC3 { $$ = ast_vec3; }
1095 | VEC4 { $$ = ast_vec4; }
1096 | BVEC2 { $$ = ast_bvec2; }
1097 | BVEC3 { $$ = ast_bvec3; }
1098 | BVEC4 { $$ = ast_bvec4; }
1099 | IVEC2 { $$ = ast_ivec2; }
1100 | IVEC3 { $$ = ast_ivec3; }
1101 | IVEC4 { $$ = ast_ivec4; }
1102 | UVEC2 { $$ = ast_uvec2; }
1103 | UVEC3 { $$ = ast_uvec3; }
1104 | UVEC4 { $$ = ast_uvec4; }
1105 | MAT2 { $$ = ast_mat2; }
1106 | MAT3 { $$ = ast_mat3; }
1107 | MAT4 { $$ = ast_mat4; }
1108 | MAT2X2 { $$ = ast_mat2; }
1109 | MAT2X3 { $$ = ast_mat2x3; }
1110 | MAT2X4 { $$ = ast_mat2x4; }
1111 | MAT3X2 { $$ = ast_mat3x2; }
1112 | MAT3X3 { $$ = ast_mat3; }
1113 | MAT3X4 { $$ = ast_mat3x4; }
1114 | MAT4X2 { $$ = ast_mat4x2; }
1115 | MAT4X3 { $$ = ast_mat4x3; }
1116 | MAT4X4 { $$ = ast_mat4; }
1117 | SAMPLER1D { $$ = ast_sampler1d; }
1118 | SAMPLER2D { $$ = ast_sampler2d; }
1119 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1120 | SAMPLER3D { $$ = ast_sampler3d; }
1121 | SAMPLERCUBE { $$ = ast_samplercube; }
1122 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1123 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1124 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1125 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1126 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1127 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1128 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1129 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1130 | ISAMPLER1D { $$ = ast_isampler1d; }
1131 | ISAMPLER2D { $$ = ast_isampler2d; }
1132 | ISAMPLER3D { $$ = ast_isampler3d; }
1133 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1134 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1135 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1136 | USAMPLER1D { $$ = ast_usampler1d; }
1137 | USAMPLER2D { $$ = ast_usampler2d; }
1138 | USAMPLER3D { $$ = ast_usampler3d; }
1139 | USAMPLERCUBE { $$ = ast_usamplercube; }
1140 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1141 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1144 precision_qualifier:
1146 if (state->language_version < 130)
1147 _mesa_glsl_error(& @1, state,
1148 "precision qualifier forbidden "
1149 "in GLSL %d.%d (1.30 or later "
1151 state->language_version / 100,
1152 state->language_version % 100);
1154 $$ = ast_precision_high;
1157 if (state->language_version < 130)
1158 _mesa_glsl_error(& @1, state,
1159 "precision qualifier forbidden "
1160 "in GLSL %d.%d (1.30 or later "
1162 state->language_version / 100,
1163 state->language_version % 100);
1165 $$ = ast_precision_medium;
1168 if (state->language_version < 130)
1169 _mesa_glsl_error(& @1, state,
1170 "precision qualifier forbidden "
1171 "in GLSL %d.%d (1.30 or later "
1173 state->language_version / 100,
1174 state->language_version % 100);
1176 $$ = ast_precision_low;
1181 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1184 $$ = new(ctx) ast_struct_specifier($2, $4);
1185 $$->set_location(yylloc);
1187 | STRUCT '{' struct_declaration_list '}'
1190 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1191 $$->set_location(yylloc);
1195 struct_declaration_list:
1198 $$ = (struct ast_node *) $1;
1199 $1->link.self_link();
1201 | struct_declaration_list struct_declaration
1203 $$ = (struct ast_node *) $1;
1204 $$->link.insert_before(& $2->link);
1209 type_specifier struct_declarator_list ';'
1212 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1213 type->set_location(yylloc);
1215 type->specifier = $1;
1216 $$ = new(ctx) ast_declarator_list(type);
1217 $$->set_location(yylloc);
1219 $$->declarations.push_degenerate_list_at_head(& $2->link);
1223 struct_declarator_list:
1227 $1->link.self_link();
1229 | struct_declarator_list ',' struct_declarator
1232 $$->link.insert_before(& $3->link);
1240 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1241 $$->set_location(yylloc);
1243 | IDENTIFIER '[' constant_expression ']'
1246 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1247 $$->set_location(yylloc);
1252 assignment_expression
1255 declaration_statement:
1259 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1263 | statement_unmatched
1267 compound_statement { $$ = (struct ast_node *) $1; }
1271 statement_unmatched:
1272 selection_statement_unmatched
1276 declaration_statement
1277 | expression_statement
1278 | selection_statement_matched
1279 | switch_statement { $$ = NULL; }
1280 | case_label { $$ = NULL; }
1281 | iteration_statement
1289 $$ = new(ctx) ast_compound_statement(true, NULL);
1290 $$->set_location(yylloc);
1292 | '{' statement_list '}'
1295 $$ = new(ctx) ast_compound_statement(true, $2);
1296 $$->set_location(yylloc);
1300 statement_no_new_scope:
1301 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1305 compound_statement_no_new_scope:
1309 $$ = new(ctx) ast_compound_statement(false, NULL);
1310 $$->set_location(yylloc);
1312 | '{' statement_list '}'
1315 $$ = new(ctx) ast_compound_statement(false, $2);
1316 $$->set_location(yylloc);
1324 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1329 $$->link.self_link();
1331 | statement_list statement
1334 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1338 $$->link.insert_before(& $2->link);
1342 expression_statement:
1346 $$ = new(ctx) ast_expression_statement(NULL);
1347 $$->set_location(yylloc);
1352 $$ = new(ctx) ast_expression_statement($1);
1353 $$->set_location(yylloc);
1357 selection_statement_matched:
1358 IF '(' expression ')' statement_matched ELSE statement_matched
1361 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1362 $$->set_location(yylloc);
1366 selection_statement_unmatched:
1367 IF '(' expression ')' statement_matched
1370 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1371 $$->set_location(yylloc);
1373 | IF '(' expression ')' statement_unmatched
1376 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1377 $$->set_location(yylloc);
1379 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1382 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1383 $$->set_location(yylloc);
1390 $$ = (struct ast_node *) $1;
1392 | fully_specified_type IDENTIFIER '=' initializer
1395 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1396 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1397 decl->set_location(yylloc);
1398 declarator->set_location(yylloc);
1400 declarator->declarations.push_tail(&decl->link);
1406 SWITCH '(' expression ')' compound_statement
1414 iteration_statement:
1415 WHILE '(' condition ')' statement_no_new_scope
1418 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1419 NULL, $3, NULL, $5);
1420 $$->set_location(yylloc);
1422 | DO statement WHILE '(' expression ')' ';'
1425 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1426 NULL, $5, NULL, $2);
1427 $$->set_location(yylloc);
1429 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1432 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1433 $3, $4.cond, $4.rest, $6);
1434 $$->set_location(yylloc);
1439 expression_statement
1440 | declaration_statement
1457 | conditionopt ';' expression
1464 // Grammar Note: No 'goto'. Gotos are not supported.
1469 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1470 $$->set_location(yylloc);
1475 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1476 $$->set_location(yylloc);
1481 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1482 $$->set_location(yylloc);
1484 | RETURN expression ';'
1487 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1488 $$->set_location(yylloc);
1490 | DISCARD ';' // Fragment shader only.
1493 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1494 $$->set_location(yylloc);
1498 external_declaration:
1499 function_definition { $$ = $1; }
1500 | declaration { $$ = $1; }
1503 function_definition:
1504 function_prototype compound_statement_no_new_scope
1507 $$ = new(ctx) ast_function_definition();
1508 $$->set_location(yylloc);