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;
62 struct ast_node *node;
63 struct ast_type_specifier *type_specifier;
64 struct ast_fully_specified_type *fully_specified_type;
65 struct ast_function *function;
66 struct ast_parameter_declarator *parameter_declarator;
67 struct ast_function_definition *function_definition;
68 struct ast_compound_statement *compound_statement;
69 struct ast_expression *expression;
70 struct ast_declarator_list *declarator_list;
71 struct ast_struct_specifier *struct_specifier;
72 struct ast_declaration *declaration;
75 struct ast_node *cond;
76 struct ast_expression *rest;
80 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
81 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
82 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
83 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
84 %token NOPERSPECTIVE FLAT SMOOTH
85 %token MAT2X2 MAT2X3 MAT2X4
86 %token MAT3X2 MAT3X3 MAT3X4
87 %token MAT4X2 MAT4X3 MAT4X4
88 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
89 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
90 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
91 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
92 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
93 %token STRUCT VOID_TOK WHILE
94 %token <identifier> IDENTIFIER
95 %token <real> FLOATCONSTANT
96 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
97 %token <identifier> FIELD_SELECTION
98 %token LEFT_OP RIGHT_OP
99 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
100 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
101 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
104 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
106 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
109 /* Reserved words that are not actually used in the grammar.
111 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
112 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
113 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
114 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
115 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
116 %token SIZEOF CAST NAMESPACE USING
120 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
121 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
122 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
123 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
124 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
127 %type <identifier> variable_identifier
128 %type <node> statement
129 %type <node> statement_list
130 %type <node> simple_statement
131 %type <node> statement_matched
132 %type <node> statement_unmatched
133 %type <n> precision_qualifier
134 %type <type_qualifier> type_qualifier
135 %type <type_qualifier> storage_qualifier
136 %type <type_qualifier> interpolation_qualifier
137 %type <type_qualifier> opt_layout_qualifier layout_qualifier
138 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
139 %type <type_specifier> type_specifier
140 %type <type_specifier> type_specifier_no_prec
141 %type <type_specifier> type_specifier_nonarray
142 %type <n> basic_type_specifier_nonarray
143 %type <fully_specified_type> fully_specified_type
144 %type <function> function_prototype
145 %type <function> function_header
146 %type <function> function_header_with_parameters
147 %type <function> function_declarator
148 %type <parameter_declarator> parameter_declarator
149 %type <parameter_declarator> parameter_declaration
150 %type <type_qualifier> parameter_qualifier
151 %type <type_qualifier> parameter_type_qualifier
152 %type <type_specifier> parameter_type_specifier
153 %type <function_definition> function_definition
154 %type <compound_statement> compound_statement_no_new_scope
155 %type <compound_statement> compound_statement
156 %type <node> statement_no_new_scope
157 %type <node> expression_statement
158 %type <expression> expression
159 %type <expression> primary_expression
160 %type <expression> assignment_expression
161 %type <expression> conditional_expression
162 %type <expression> logical_or_expression
163 %type <expression> logical_xor_expression
164 %type <expression> logical_and_expression
165 %type <expression> inclusive_or_expression
166 %type <expression> exclusive_or_expression
167 %type <expression> and_expression
168 %type <expression> equality_expression
169 %type <expression> relational_expression
170 %type <expression> shift_expression
171 %type <expression> additive_expression
172 %type <expression> multiplicative_expression
173 %type <expression> unary_expression
174 %type <expression> constant_expression
175 %type <expression> integer_expression
176 %type <expression> postfix_expression
177 %type <expression> function_call_header_with_parameters
178 %type <expression> function_call_header_no_parameters
179 %type <expression> function_call_header
180 %type <expression> function_call_generic
181 %type <expression> function_call_or_method
182 %type <expression> function_call
183 %type <n> assignment_operator
184 %type <n> unary_operator
185 %type <expression> function_identifier
186 %type <node> external_declaration
187 %type <declarator_list> init_declarator_list
188 %type <declarator_list> single_declaration
189 %type <expression> initializer
190 %type <node> declaration
191 %type <node> declaration_statement
192 %type <node> jump_statement
193 %type <struct_specifier> struct_specifier
194 %type <node> struct_declaration_list
195 %type <declarator_list> struct_declaration
196 %type <declaration> struct_declarator
197 %type <declaration> struct_declarator_list
198 %type <node> selection_statement_matched
199 %type <node> selection_statement_unmatched
200 %type <node> iteration_statement
201 %type <node> condition
202 %type <node> conditionopt
203 %type <node> for_init_statement
204 %type <for_rest_statement> for_rest_statement
208 version_statement extension_statement_list
210 _mesa_glsl_initialize_types(state);
212 external_declaration_list
216 /* blank - no #version specified */
218 state->language_version = 110;
220 | VERSION INTCONSTANT EOL
226 /* FINISHME: Check against implementation support versions. */
227 state->language_version = $2;
230 _mesa_glsl_error(& @2, state, "Shading language version"
231 "%u is not supported\n", $2);
237 extension_statement_list:
239 | extension_statement_list extension_statement
243 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
245 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
251 external_declaration_list:
254 /* FINISHME: The NULL test is only required because 'precision'
255 * FINISHME: statements are not yet supported.
258 state->translation_unit.push_tail(& $1->link);
260 | external_declaration_list external_declaration
262 /* FINISHME: The NULL test is only required because 'precision'
263 * FINISHME: statements are not yet supported.
266 state->translation_unit.push_tail(& $2->link);
278 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
279 $$->set_location(yylloc);
280 $$->primary_expression.identifier = $1;
285 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
286 $$->set_location(yylloc);
287 $$->primary_expression.int_constant = $1;
292 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
293 $$->set_location(yylloc);
294 $$->primary_expression.uint_constant = $1;
299 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
300 $$->set_location(yylloc);
301 $$->primary_expression.float_constant = $1;
306 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
307 $$->set_location(yylloc);
308 $$->primary_expression.bool_constant = $1;
318 | postfix_expression '[' integer_expression ']'
321 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
322 $$->set_location(yylloc);
328 | postfix_expression '.' IDENTIFIER
331 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
332 $$->set_location(yylloc);
333 $$->primary_expression.identifier = $3;
335 | postfix_expression INC_OP
338 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
339 $$->set_location(yylloc);
341 | postfix_expression DEC_OP
344 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
345 $$->set_location(yylloc);
354 function_call_or_method
357 function_call_or_method:
358 function_call_generic
359 | postfix_expression '.' function_call_generic
362 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
363 $$->set_location(yylloc);
367 function_call_generic:
368 function_call_header_with_parameters ')'
369 | function_call_header_no_parameters ')'
372 function_call_header_no_parameters:
373 function_call_header VOID_TOK
374 | function_call_header
377 function_call_header_with_parameters:
378 function_call_header assignment_expression
381 $$->set_location(yylloc);
382 $$->expressions.push_tail(& $2->link);
384 | function_call_header_with_parameters ',' assignment_expression
387 $$->set_location(yylloc);
388 $$->expressions.push_tail(& $3->link);
392 // Grammar Note: Constructors look like functions, but lexical
393 // analysis recognized most of them as keywords. They are now
394 // recognized through "type_specifier".
395 function_call_header:
396 function_identifier '('
403 $$ = new(ctx) ast_function_expression($1);
404 $$->set_location(yylloc);
409 ast_expression *callee = new(ctx) ast_expression($1);
410 $$ = new(ctx) ast_function_expression(callee);
411 $$->set_location(yylloc);
416 ast_expression *callee = new(ctx) ast_expression($1);
417 $$ = new(ctx) ast_function_expression(callee);
418 $$->set_location(yylloc);
422 // Grammar Note: No traditional style type casts.
425 | INC_OP unary_expression
428 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
429 $$->set_location(yylloc);
431 | DEC_OP unary_expression
434 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
435 $$->set_location(yylloc);
437 | unary_operator unary_expression
440 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
441 $$->set_location(yylloc);
445 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
447 '+' { $$ = ast_plus; }
448 | '-' { $$ = ast_neg; }
449 | '!' { $$ = ast_logic_not; }
450 | '~' { $$ = ast_bit_not; }
453 multiplicative_expression:
455 | multiplicative_expression '*' unary_expression
458 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
459 $$->set_location(yylloc);
461 | multiplicative_expression '/' unary_expression
464 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
465 $$->set_location(yylloc);
467 | multiplicative_expression '%' unary_expression
470 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
471 $$->set_location(yylloc);
476 multiplicative_expression
477 | additive_expression '+' multiplicative_expression
480 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
481 $$->set_location(yylloc);
483 | additive_expression '-' multiplicative_expression
486 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
487 $$->set_location(yylloc);
493 | shift_expression LEFT_OP additive_expression
496 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
497 $$->set_location(yylloc);
499 | shift_expression RIGHT_OP additive_expression
502 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
503 $$->set_location(yylloc);
507 relational_expression:
509 | relational_expression '<' shift_expression
512 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
513 $$->set_location(yylloc);
515 | relational_expression '>' shift_expression
518 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
519 $$->set_location(yylloc);
521 | relational_expression LE_OP shift_expression
524 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
525 $$->set_location(yylloc);
527 | relational_expression GE_OP shift_expression
530 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
531 $$->set_location(yylloc);
536 relational_expression
537 | equality_expression EQ_OP relational_expression
540 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
541 $$->set_location(yylloc);
543 | equality_expression NE_OP relational_expression
546 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
547 $$->set_location(yylloc);
553 | and_expression '&' equality_expression
556 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
557 $$->set_location(yylloc);
561 exclusive_or_expression:
563 | exclusive_or_expression '^' and_expression
566 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
567 $$->set_location(yylloc);
571 inclusive_or_expression:
572 exclusive_or_expression
573 | inclusive_or_expression '|' exclusive_or_expression
576 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
577 $$->set_location(yylloc);
581 logical_and_expression:
582 inclusive_or_expression
583 | logical_and_expression AND_OP inclusive_or_expression
586 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
587 $$->set_location(yylloc);
591 logical_xor_expression:
592 logical_and_expression
593 | logical_xor_expression XOR_OP logical_and_expression
596 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
597 $$->set_location(yylloc);
601 logical_or_expression:
602 logical_xor_expression
603 | logical_or_expression OR_OP logical_xor_expression
606 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
607 $$->set_location(yylloc);
611 conditional_expression:
612 logical_or_expression
613 | logical_or_expression '?' expression ':' assignment_expression
616 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
617 $$->set_location(yylloc);
621 assignment_expression:
622 conditional_expression
623 | unary_expression assignment_operator assignment_expression
626 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
627 $$->set_location(yylloc);
632 '=' { $$ = ast_assign; }
633 | MUL_ASSIGN { $$ = ast_mul_assign; }
634 | DIV_ASSIGN { $$ = ast_div_assign; }
635 | MOD_ASSIGN { $$ = ast_mod_assign; }
636 | ADD_ASSIGN { $$ = ast_add_assign; }
637 | SUB_ASSIGN { $$ = ast_sub_assign; }
638 | LEFT_ASSIGN { $$ = ast_ls_assign; }
639 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
640 | AND_ASSIGN { $$ = ast_and_assign; }
641 | XOR_ASSIGN { $$ = ast_xor_assign; }
642 | OR_ASSIGN { $$ = ast_or_assign; }
646 assignment_expression
650 | expression ',' assignment_expression
653 if ($1->oper != ast_sequence) {
654 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
655 $$->set_location(yylloc);
656 $$->expressions.push_tail(& $1->link);
661 $$->expressions.push_tail(& $3->link);
666 conditional_expression
670 function_prototype ';'
674 | init_declarator_list ';'
678 | PRECISION precision_qualifier type_specifier_no_prec ';'
680 if (($3->type_specifier != ast_float)
681 && ($3->type_specifier != ast_int)) {
682 _mesa_glsl_error(& @3, state, "global precision qualifier can "
683 "only be applied to `int' or `float'\n");
687 $$ = NULL; /* FINISHME */
692 function_declarator ')'
697 | function_header_with_parameters
700 function_header_with_parameters:
701 function_header parameter_declaration
704 $$->parameters.push_tail(& $2->link);
706 | function_header_with_parameters ',' parameter_declaration
709 $$->parameters.push_tail(& $3->link);
714 fully_specified_type IDENTIFIER '('
717 $$ = new(ctx) ast_function();
718 $$->set_location(yylloc);
719 $$->return_type = $1;
724 parameter_declarator:
725 type_specifier IDENTIFIER
728 $$ = new(ctx) ast_parameter_declarator();
729 $$->set_location(yylloc);
730 $$->type = new(ctx) ast_fully_specified_type();
731 $$->type->set_location(yylloc);
732 $$->type->specifier = $1;
735 | type_specifier IDENTIFIER '[' constant_expression ']'
738 $$ = new(ctx) ast_parameter_declarator();
739 $$->set_location(yylloc);
740 $$->type = new(ctx) ast_fully_specified_type();
741 $$->type->set_location(yylloc);
742 $$->type->specifier = $1;
749 parameter_declaration:
750 parameter_type_qualifier parameter_qualifier parameter_declarator
755 $$->type->qualifier = $1.q;
757 | parameter_qualifier parameter_declarator
760 $$->type->qualifier = $1.q;
762 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
767 $$ = new(ctx) ast_parameter_declarator();
768 $$->set_location(yylloc);
769 $$->type = new(ctx) ast_fully_specified_type();
770 $$->type->qualifier = $1.q;
771 $$->type->specifier = $3;
773 | parameter_qualifier parameter_type_specifier
776 $$ = new(ctx) ast_parameter_declarator();
777 $$->set_location(yylloc);
778 $$->type = new(ctx) ast_fully_specified_type();
779 $$->type->qualifier = $1.q;
780 $$->type->specifier = $2;
785 /* empty */ { $$.i = 0; }
786 | IN_TOK { $$.i = 0; $$.q.in = 1; }
787 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
788 | INOUT_TOK { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
791 parameter_type_specifier:
795 init_declarator_list:
797 | init_declarator_list ',' IDENTIFIER
800 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
801 decl->set_location(yylloc);
804 $$->declarations.push_tail(&decl->link);
806 | init_declarator_list ',' IDENTIFIER '[' ']'
809 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
810 decl->set_location(yylloc);
813 $$->declarations.push_tail(&decl->link);
815 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
818 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
819 decl->set_location(yylloc);
822 $$->declarations.push_tail(&decl->link);
824 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
827 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
828 decl->set_location(yylloc);
831 $$->declarations.push_tail(&decl->link);
833 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
836 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
837 decl->set_location(yylloc);
840 $$->declarations.push_tail(&decl->link);
842 | init_declarator_list ',' IDENTIFIER '=' initializer
845 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
846 decl->set_location(yylloc);
849 $$->declarations.push_tail(&decl->link);
853 // Grammar Note: No 'enum', or 'typedef'.
858 if ($1->specifier->type_specifier != ast_struct) {
859 _mesa_glsl_error(& @1, state, "empty declaration list\n");
862 $$ = new(ctx) ast_declarator_list($1);
863 $$->set_location(yylloc);
866 | fully_specified_type IDENTIFIER
869 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
871 $$ = new(ctx) ast_declarator_list($1);
872 $$->set_location(yylloc);
873 $$->declarations.push_tail(&decl->link);
875 | fully_specified_type IDENTIFIER '[' ']'
878 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
880 $$ = new(ctx) ast_declarator_list($1);
881 $$->set_location(yylloc);
882 $$->declarations.push_tail(&decl->link);
884 | fully_specified_type IDENTIFIER '[' constant_expression ']'
887 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
889 $$ = new(ctx) ast_declarator_list($1);
890 $$->set_location(yylloc);
891 $$->declarations.push_tail(&decl->link);
893 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
896 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
898 $$ = new(ctx) ast_declarator_list($1);
899 $$->set_location(yylloc);
900 $$->declarations.push_tail(&decl->link);
902 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
905 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
907 $$ = new(ctx) ast_declarator_list($1);
908 $$->set_location(yylloc);
909 $$->declarations.push_tail(&decl->link);
911 | fully_specified_type IDENTIFIER '=' initializer
914 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
916 $$ = new(ctx) ast_declarator_list($1);
917 $$->set_location(yylloc);
918 $$->declarations.push_tail(&decl->link);
920 | INVARIANT IDENTIFIER // Vertex only.
923 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
925 $$ = new(ctx) ast_declarator_list(NULL);
926 $$->set_location(yylloc);
927 $$->invariant = true;
929 $$->declarations.push_tail(&decl->link);
933 fully_specified_type:
937 $$ = new(ctx) ast_fully_specified_type();
938 $$->set_location(yylloc);
941 | type_qualifier type_specifier
944 $$ = new(ctx) ast_fully_specified_type();
945 $$->set_location(yylloc);
946 $$->qualifier = $1.q;
951 opt_layout_qualifier:
957 LAYOUT_TOK '(' layout_qualifier_id_list ')'
963 layout_qualifier_id_list:
965 | layout_qualifier_id_list ',' layout_qualifier_id
976 if (state->ARB_fragment_coord_conventions_enable) {
977 bool got_one = false;
979 if (strcmp($1, "origin_upper_left") == 0) {
981 $$.q.origin_upper_left = 1;
982 } else if (strcmp($1, "pixel_center_integer") == 0) {
984 $$.q.pixel_center_integer = 1;
987 if (state->ARB_fragment_coord_conventions_warn && got_one) {
988 _mesa_glsl_warning(& @1, state,
989 "GL_ARB_fragment_coord_conventions layout "
990 "identifier `%s' used\n", $1);
994 /* If the identifier didn't match any known layout identifiers,
998 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1005 interpolation_qualifier:
1006 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1007 | FLAT { $$.i = 0; $$.q.flat = 1; }
1008 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1011 parameter_type_qualifier:
1012 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1017 | interpolation_qualifier type_qualifier
1021 | INVARIANT type_qualifier
1029 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1030 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1031 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1032 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1033 | opt_layout_qualifier IN_TOK { $$.i = 0; $$.q.in = 1; }
1034 | OUT_TOK { $$.i = 0; $$.q.out = 1; }
1035 | CENTROID IN_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1036 | CENTROID OUT_TOK { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1037 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1041 type_specifier_no_prec
1042 | precision_qualifier type_specifier_no_prec
1049 type_specifier_no_prec:
1050 type_specifier_nonarray
1051 | type_specifier_nonarray '[' ']'
1054 $$->is_array = true;
1055 $$->array_size = NULL;
1057 | type_specifier_nonarray '[' constant_expression ']'
1060 $$->is_array = true;
1061 $$->array_size = $3;
1065 type_specifier_nonarray:
1066 basic_type_specifier_nonarray
1069 $$ = new(ctx) ast_type_specifier($1);
1070 $$->set_location(yylloc);
1075 $$ = new(ctx) ast_type_specifier($1);
1076 $$->set_location(yylloc);
1081 $$ = new(ctx) ast_type_specifier($1);
1082 $$->set_location(yylloc);
1086 basic_type_specifier_nonarray:
1087 VOID_TOK { $$ = ast_void; }
1088 | FLOAT_TOK { $$ = ast_float; }
1089 | INT_TOK { $$ = ast_int; }
1090 | UINT_TOK { $$ = ast_uint; }
1091 | BOOL_TOK { $$ = ast_bool; }
1092 | VEC2 { $$ = ast_vec2; }
1093 | VEC3 { $$ = ast_vec3; }
1094 | VEC4 { $$ = ast_vec4; }
1095 | BVEC2 { $$ = ast_bvec2; }
1096 | BVEC3 { $$ = ast_bvec3; }
1097 | BVEC4 { $$ = ast_bvec4; }
1098 | IVEC2 { $$ = ast_ivec2; }
1099 | IVEC3 { $$ = ast_ivec3; }
1100 | IVEC4 { $$ = ast_ivec4; }
1101 | UVEC2 { $$ = ast_uvec2; }
1102 | UVEC3 { $$ = ast_uvec3; }
1103 | UVEC4 { $$ = ast_uvec4; }
1104 | MAT2X2 { $$ = ast_mat2; }
1105 | MAT2X3 { $$ = ast_mat2x3; }
1106 | MAT2X4 { $$ = ast_mat2x4; }
1107 | MAT3X2 { $$ = ast_mat3x2; }
1108 | MAT3X3 { $$ = ast_mat3; }
1109 | MAT3X4 { $$ = ast_mat3x4; }
1110 | MAT4X2 { $$ = ast_mat4x2; }
1111 | MAT4X3 { $$ = ast_mat4x3; }
1112 | MAT4X4 { $$ = ast_mat4; }
1113 | SAMPLER1D { $$ = ast_sampler1d; }
1114 | SAMPLER2D { $$ = ast_sampler2d; }
1115 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1116 | SAMPLER3D { $$ = ast_sampler3d; }
1117 | SAMPLERCUBE { $$ = ast_samplercube; }
1118 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1119 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1120 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1121 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1122 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1123 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1124 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1125 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1126 | ISAMPLER1D { $$ = ast_isampler1d; }
1127 | ISAMPLER2D { $$ = ast_isampler2d; }
1128 | ISAMPLER3D { $$ = ast_isampler3d; }
1129 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1130 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1131 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1132 | USAMPLER1D { $$ = ast_usampler1d; }
1133 | USAMPLER2D { $$ = ast_usampler2d; }
1134 | USAMPLER3D { $$ = ast_usampler3d; }
1135 | USAMPLERCUBE { $$ = ast_usamplercube; }
1136 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1137 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1140 precision_qualifier:
1142 if (state->language_version < 130)
1143 _mesa_glsl_error(& @1, state,
1144 "precision qualifier forbidden "
1145 "in GLSL %d.%d (1.30 or later "
1147 state->language_version / 100,
1148 state->language_version % 100);
1150 $$ = ast_precision_high;
1153 if (state->language_version < 130)
1154 _mesa_glsl_error(& @1, state,
1155 "precision qualifier forbidden "
1156 "in GLSL %d.%d (1.30 or later "
1158 state->language_version / 100,
1159 state->language_version % 100);
1161 $$ = ast_precision_medium;
1164 if (state->language_version < 130)
1165 _mesa_glsl_error(& @1, state,
1166 "precision qualifier forbidden "
1167 "in GLSL %d.%d (1.30 or later "
1169 state->language_version / 100,
1170 state->language_version % 100);
1172 $$ = ast_precision_low;
1177 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1180 $$ = new(ctx) ast_struct_specifier($2, $4);
1181 $$->set_location(yylloc);
1183 | STRUCT '{' struct_declaration_list '}'
1186 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1187 $$->set_location(yylloc);
1191 struct_declaration_list:
1194 $$ = (struct ast_node *) $1;
1195 $1->link.self_link();
1197 | struct_declaration_list struct_declaration
1199 $$ = (struct ast_node *) $1;
1200 $$->link.insert_before(& $2->link);
1205 type_specifier struct_declarator_list ';'
1208 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1209 type->set_location(yylloc);
1211 type->specifier = $1;
1212 $$ = new(ctx) ast_declarator_list(type);
1213 $$->set_location(yylloc);
1215 $$->declarations.push_degenerate_list_at_head(& $2->link);
1219 struct_declarator_list:
1223 $1->link.self_link();
1225 | struct_declarator_list ',' struct_declarator
1228 $$->link.insert_before(& $3->link);
1236 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1237 $$->set_location(yylloc);
1239 | IDENTIFIER '[' constant_expression ']'
1242 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1243 $$->set_location(yylloc);
1248 assignment_expression
1251 declaration_statement:
1255 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1259 | statement_unmatched
1263 compound_statement { $$ = (struct ast_node *) $1; }
1267 statement_unmatched:
1268 selection_statement_unmatched
1272 declaration_statement
1273 | expression_statement
1274 | selection_statement_matched
1275 | switch_statement { $$ = NULL; }
1276 | case_label { $$ = NULL; }
1277 | iteration_statement
1285 $$ = new(ctx) ast_compound_statement(true, NULL);
1286 $$->set_location(yylloc);
1288 | '{' statement_list '}'
1291 $$ = new(ctx) ast_compound_statement(true, $2);
1292 $$->set_location(yylloc);
1296 statement_no_new_scope:
1297 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1301 compound_statement_no_new_scope:
1305 $$ = new(ctx) ast_compound_statement(false, NULL);
1306 $$->set_location(yylloc);
1308 | '{' statement_list '}'
1311 $$ = new(ctx) ast_compound_statement(false, $2);
1312 $$->set_location(yylloc);
1320 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1325 $$->link.self_link();
1327 | statement_list statement
1330 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1334 $$->link.insert_before(& $2->link);
1338 expression_statement:
1342 $$ = new(ctx) ast_expression_statement(NULL);
1343 $$->set_location(yylloc);
1348 $$ = new(ctx) ast_expression_statement($1);
1349 $$->set_location(yylloc);
1353 selection_statement_matched:
1354 IF '(' expression ')' statement_matched ELSE statement_matched
1357 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1358 $$->set_location(yylloc);
1362 selection_statement_unmatched:
1363 IF '(' expression ')' statement_matched
1366 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1367 $$->set_location(yylloc);
1369 | IF '(' expression ')' statement_unmatched
1372 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1373 $$->set_location(yylloc);
1375 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1378 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1379 $$->set_location(yylloc);
1386 $$ = (struct ast_node *) $1;
1388 | fully_specified_type IDENTIFIER '=' initializer
1391 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1392 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1393 decl->set_location(yylloc);
1394 declarator->set_location(yylloc);
1396 declarator->declarations.push_tail(&decl->link);
1402 SWITCH '(' expression ')' compound_statement
1410 iteration_statement:
1411 WHILE '(' condition ')' statement_no_new_scope
1414 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1415 NULL, $3, NULL, $5);
1416 $$->set_location(yylloc);
1418 | DO statement WHILE '(' expression ')' ';'
1421 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1422 NULL, $5, NULL, $2);
1423 $$->set_location(yylloc);
1425 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1428 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1429 $3, $4.cond, $4.rest, $6);
1430 $$->set_location(yylloc);
1435 expression_statement
1436 | declaration_statement
1453 | conditionopt ';' expression
1460 // Grammar Note: No 'goto'. Gotos are not supported.
1465 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1466 $$->set_location(yylloc);
1471 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1472 $$->set_location(yylloc);
1477 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1478 $$->set_location(yylloc);
1480 | RETURN expression ';'
1483 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1484 $$->set_location(yylloc);
1486 | DISCARD ';' // Fragment shader only.
1489 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1490 $$->set_location(yylloc);
1494 external_declaration:
1495 function_definition { $$ = $1; }
1496 | declaration { $$ = $1; }
1499 function_definition:
1500 function_prototype compound_statement_no_new_scope
1503 $$ = new(ctx) ast_function_definition();
1504 $$->set_location(yylloc);