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
119 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
120 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
121 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
122 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
123 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
126 %type <identifier> variable_identifier
127 %type <node> statement
128 %type <node> statement_list
129 %type <node> simple_statement
130 %type <node> statement_matched
131 %type <node> statement_unmatched
132 %type <n> precision_qualifier
133 %type <type_qualifier> type_qualifier
134 %type <type_qualifier> storage_qualifier
135 %type <type_qualifier> interpolation_qualifier
136 %type <type_qualifier> opt_layout_qualifier layout_qualifier
137 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
138 %type <type_specifier> type_specifier
139 %type <type_specifier> type_specifier_no_prec
140 %type <type_specifier> type_specifier_nonarray
141 %type <n> basic_type_specifier_nonarray
142 %type <fully_specified_type> fully_specified_type
143 %type <function> function_prototype
144 %type <function> function_header
145 %type <function> function_header_with_parameters
146 %type <function> function_declarator
147 %type <parameter_declarator> parameter_declarator
148 %type <parameter_declarator> parameter_declaration
149 %type <type_qualifier> parameter_qualifier
150 %type <type_qualifier> parameter_type_qualifier
151 %type <type_specifier> parameter_type_specifier
152 %type <function_definition> function_definition
153 %type <compound_statement> compound_statement_no_new_scope
154 %type <compound_statement> compound_statement
155 %type <node> statement_no_new_scope
156 %type <node> expression_statement
157 %type <expression> expression
158 %type <expression> primary_expression
159 %type <expression> assignment_expression
160 %type <expression> conditional_expression
161 %type <expression> logical_or_expression
162 %type <expression> logical_xor_expression
163 %type <expression> logical_and_expression
164 %type <expression> inclusive_or_expression
165 %type <expression> exclusive_or_expression
166 %type <expression> and_expression
167 %type <expression> equality_expression
168 %type <expression> relational_expression
169 %type <expression> shift_expression
170 %type <expression> additive_expression
171 %type <expression> multiplicative_expression
172 %type <expression> unary_expression
173 %type <expression> constant_expression
174 %type <expression> integer_expression
175 %type <expression> postfix_expression
176 %type <expression> function_call_header_with_parameters
177 %type <expression> function_call_header_no_parameters
178 %type <expression> function_call_header
179 %type <expression> function_call_generic
180 %type <expression> function_call_or_method
181 %type <expression> function_call
182 %type <n> assignment_operator
183 %type <n> unary_operator
184 %type <expression> function_identifier
185 %type <node> external_declaration
186 %type <declarator_list> init_declarator_list
187 %type <declarator_list> single_declaration
188 %type <expression> initializer
189 %type <node> declaration
190 %type <node> declaration_statement
191 %type <node> jump_statement
192 %type <struct_specifier> struct_specifier
193 %type <node> struct_declaration_list
194 %type <declarator_list> struct_declaration
195 %type <declaration> struct_declarator
196 %type <declaration> struct_declarator_list
197 %type <node> selection_statement_matched
198 %type <node> selection_statement_unmatched
199 %type <node> iteration_statement
200 %type <node> condition
201 %type <node> conditionopt
202 %type <node> for_init_statement
203 %type <for_rest_statement> for_rest_statement
207 version_statement extension_statement_list
209 _mesa_glsl_initialize_types(state);
211 external_declaration_list
215 /* blank - no #version specified */
217 state->language_version = 110;
219 | VERSION INTCONSTANT EOL
225 /* FINISHME: Check against implementation support versions. */
226 state->language_version = $2;
229 _mesa_glsl_error(& @2, state, "Shading language version"
230 "%u is not supported\n", $2);
236 extension_statement_list:
238 | extension_statement_list extension_statement
242 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
244 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
250 external_declaration_list:
253 /* FINISHME: The NULL test is only required because 'precision'
254 * FINISHME: statements are not yet supported.
257 state->translation_unit.push_tail(& $1->link);
259 | external_declaration_list external_declaration
261 /* FINISHME: The NULL test is only required because 'precision'
262 * FINISHME: statements are not yet supported.
265 state->translation_unit.push_tail(& $2->link);
277 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
278 $$->set_location(yylloc);
279 $$->primary_expression.identifier = $1;
284 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
285 $$->set_location(yylloc);
286 $$->primary_expression.int_constant = $1;
291 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
292 $$->set_location(yylloc);
293 $$->primary_expression.uint_constant = $1;
298 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
299 $$->set_location(yylloc);
300 $$->primary_expression.float_constant = $1;
305 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
306 $$->set_location(yylloc);
307 $$->primary_expression.bool_constant = $1;
317 | postfix_expression '[' integer_expression ']'
320 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
321 $$->set_location(yylloc);
327 | postfix_expression '.' IDENTIFIER
330 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
331 $$->set_location(yylloc);
332 $$->primary_expression.identifier = $3;
334 | postfix_expression INC_OP
337 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
338 $$->set_location(yylloc);
340 | postfix_expression DEC_OP
343 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
344 $$->set_location(yylloc);
353 function_call_or_method
356 function_call_or_method:
357 function_call_generic
358 | postfix_expression '.' function_call_generic
361 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
362 $$->set_location(yylloc);
366 function_call_generic:
367 function_call_header_with_parameters ')'
368 | function_call_header_no_parameters ')'
371 function_call_header_no_parameters:
372 function_call_header VOID
373 | function_call_header
376 function_call_header_with_parameters:
377 function_call_header assignment_expression
380 $$->set_location(yylloc);
381 $$->expressions.push_tail(& $2->link);
383 | function_call_header_with_parameters ',' assignment_expression
386 $$->set_location(yylloc);
387 $$->expressions.push_tail(& $3->link);
391 // Grammar Note: Constructors look like functions, but lexical
392 // analysis recognized most of them as keywords. They are now
393 // recognized through "type_specifier".
394 function_call_header:
395 function_identifier '('
402 $$ = new(ctx) ast_function_expression($1);
403 $$->set_location(yylloc);
408 ast_expression *callee = new(ctx) ast_expression($1);
409 $$ = new(ctx) ast_function_expression(callee);
410 $$->set_location(yylloc);
415 ast_expression *callee = new(ctx) ast_expression($1);
416 $$ = new(ctx) ast_function_expression(callee);
417 $$->set_location(yylloc);
421 // Grammar Note: No traditional style type casts.
424 | INC_OP unary_expression
427 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
428 $$->set_location(yylloc);
430 | DEC_OP unary_expression
433 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
434 $$->set_location(yylloc);
436 | unary_operator unary_expression
439 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
440 $$->set_location(yylloc);
444 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
446 '+' { $$ = ast_plus; }
447 | '-' { $$ = ast_neg; }
448 | '!' { $$ = ast_logic_not; }
449 | '~' { $$ = ast_bit_not; }
452 multiplicative_expression:
454 | multiplicative_expression '*' unary_expression
457 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
458 $$->set_location(yylloc);
460 | multiplicative_expression '/' unary_expression
463 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
464 $$->set_location(yylloc);
466 | multiplicative_expression '%' unary_expression
469 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
470 $$->set_location(yylloc);
475 multiplicative_expression
476 | additive_expression '+' multiplicative_expression
479 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
480 $$->set_location(yylloc);
482 | additive_expression '-' multiplicative_expression
485 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
486 $$->set_location(yylloc);
492 | shift_expression LEFT_OP additive_expression
495 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
496 $$->set_location(yylloc);
498 | shift_expression RIGHT_OP additive_expression
501 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
502 $$->set_location(yylloc);
506 relational_expression:
508 | relational_expression '<' shift_expression
511 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
512 $$->set_location(yylloc);
514 | relational_expression '>' shift_expression
517 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
518 $$->set_location(yylloc);
520 | relational_expression LE_OP shift_expression
523 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
524 $$->set_location(yylloc);
526 | relational_expression GE_OP shift_expression
529 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
530 $$->set_location(yylloc);
535 relational_expression
536 | equality_expression EQ_OP relational_expression
539 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
540 $$->set_location(yylloc);
542 | equality_expression NE_OP relational_expression
545 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
546 $$->set_location(yylloc);
552 | and_expression '&' equality_expression
555 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
556 $$->set_location(yylloc);
560 exclusive_or_expression:
562 | exclusive_or_expression '^' and_expression
565 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
566 $$->set_location(yylloc);
570 inclusive_or_expression:
571 exclusive_or_expression
572 | inclusive_or_expression '|' exclusive_or_expression
575 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
576 $$->set_location(yylloc);
580 logical_and_expression:
581 inclusive_or_expression
582 | logical_and_expression AND_OP inclusive_or_expression
585 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
586 $$->set_location(yylloc);
590 logical_xor_expression:
591 logical_and_expression
592 | logical_xor_expression XOR_OP logical_and_expression
595 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
596 $$->set_location(yylloc);
600 logical_or_expression:
601 logical_xor_expression
602 | logical_or_expression OR_OP logical_xor_expression
605 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
606 $$->set_location(yylloc);
610 conditional_expression:
611 logical_or_expression
612 | logical_or_expression '?' expression ':' assignment_expression
615 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
616 $$->set_location(yylloc);
620 assignment_expression:
621 conditional_expression
622 | unary_expression assignment_operator assignment_expression
625 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
626 $$->set_location(yylloc);
631 '=' { $$ = ast_assign; }
632 | MUL_ASSIGN { $$ = ast_mul_assign; }
633 | DIV_ASSIGN { $$ = ast_div_assign; }
634 | MOD_ASSIGN { $$ = ast_mod_assign; }
635 | ADD_ASSIGN { $$ = ast_add_assign; }
636 | SUB_ASSIGN { $$ = ast_sub_assign; }
637 | LEFT_ASSIGN { $$ = ast_ls_assign; }
638 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
639 | AND_ASSIGN { $$ = ast_and_assign; }
640 | XOR_ASSIGN { $$ = ast_xor_assign; }
641 | OR_ASSIGN { $$ = ast_or_assign; }
645 assignment_expression
649 | expression ',' assignment_expression
652 if ($1->oper != ast_sequence) {
653 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
654 $$->set_location(yylloc);
655 $$->expressions.push_tail(& $1->link);
660 $$->expressions.push_tail(& $3->link);
665 conditional_expression
669 function_prototype ';'
673 | init_declarator_list ';'
677 | PRECISION precision_qualifier type_specifier_no_prec ';'
679 if (($3->type_specifier != ast_float)
680 && ($3->type_specifier != ast_int)) {
681 _mesa_glsl_error(& @3, state, "global precision qualifier can "
682 "only be applied to `int' or `float'\n");
686 $$ = NULL; /* FINISHME */
691 function_declarator ')'
696 | function_header_with_parameters
699 function_header_with_parameters:
700 function_header parameter_declaration
703 $$->parameters.push_tail(& $2->link);
705 | function_header_with_parameters ',' parameter_declaration
708 $$->parameters.push_tail(& $3->link);
713 fully_specified_type IDENTIFIER '('
716 $$ = new(ctx) ast_function();
717 $$->set_location(yylloc);
718 $$->return_type = $1;
723 parameter_declarator:
724 type_specifier IDENTIFIER
727 $$ = new(ctx) ast_parameter_declarator();
728 $$->set_location(yylloc);
729 $$->type = new(ctx) ast_fully_specified_type();
730 $$->type->set_location(yylloc);
731 $$->type->specifier = $1;
734 | type_specifier IDENTIFIER '[' constant_expression ']'
737 $$ = new(ctx) ast_parameter_declarator();
738 $$->set_location(yylloc);
739 $$->type = new(ctx) ast_fully_specified_type();
740 $$->type->set_location(yylloc);
741 $$->type->specifier = $1;
748 parameter_declaration:
749 parameter_type_qualifier parameter_qualifier parameter_declarator
754 $$->type->qualifier = $1.q;
756 | parameter_qualifier parameter_declarator
759 $$->type->qualifier = $1.q;
761 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
766 $$ = new(ctx) ast_parameter_declarator();
767 $$->set_location(yylloc);
768 $$->type = new(ctx) ast_fully_specified_type();
769 $$->type->qualifier = $1.q;
770 $$->type->specifier = $3;
772 | parameter_qualifier parameter_type_specifier
775 $$ = new(ctx) ast_parameter_declarator();
776 $$->set_location(yylloc);
777 $$->type = new(ctx) ast_fully_specified_type();
778 $$->type->qualifier = $1.q;
779 $$->type->specifier = $2;
784 /* empty */ { $$.i = 0; }
785 | IN { $$.i = 0; $$.q.in = 1; }
786 | OUT { $$.i = 0; $$.q.out = 1; }
787 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
790 parameter_type_specifier:
794 init_declarator_list:
796 | init_declarator_list ',' IDENTIFIER
799 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
800 decl->set_location(yylloc);
803 $$->declarations.push_tail(&decl->link);
805 | init_declarator_list ',' IDENTIFIER '[' ']'
808 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
809 decl->set_location(yylloc);
812 $$->declarations.push_tail(&decl->link);
814 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
817 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
818 decl->set_location(yylloc);
821 $$->declarations.push_tail(&decl->link);
823 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
826 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
827 decl->set_location(yylloc);
830 $$->declarations.push_tail(&decl->link);
832 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
835 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
836 decl->set_location(yylloc);
839 $$->declarations.push_tail(&decl->link);
841 | init_declarator_list ',' IDENTIFIER '=' initializer
844 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
845 decl->set_location(yylloc);
848 $$->declarations.push_tail(&decl->link);
852 // Grammar Note: No 'enum', or 'typedef'.
857 if ($1->specifier->type_specifier != ast_struct) {
858 _mesa_glsl_error(& @1, state, "empty declaration list\n");
861 $$ = new(ctx) ast_declarator_list($1);
862 $$->set_location(yylloc);
865 | fully_specified_type IDENTIFIER
868 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
870 $$ = new(ctx) ast_declarator_list($1);
871 $$->set_location(yylloc);
872 $$->declarations.push_tail(&decl->link);
874 | fully_specified_type IDENTIFIER '[' ']'
877 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
879 $$ = new(ctx) ast_declarator_list($1);
880 $$->set_location(yylloc);
881 $$->declarations.push_tail(&decl->link);
883 | fully_specified_type IDENTIFIER '[' constant_expression ']'
886 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
888 $$ = new(ctx) ast_declarator_list($1);
889 $$->set_location(yylloc);
890 $$->declarations.push_tail(&decl->link);
892 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
895 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
897 $$ = new(ctx) ast_declarator_list($1);
898 $$->set_location(yylloc);
899 $$->declarations.push_tail(&decl->link);
901 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
904 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
906 $$ = new(ctx) ast_declarator_list($1);
907 $$->set_location(yylloc);
908 $$->declarations.push_tail(&decl->link);
910 | fully_specified_type IDENTIFIER '=' initializer
913 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
915 $$ = new(ctx) ast_declarator_list($1);
916 $$->set_location(yylloc);
917 $$->declarations.push_tail(&decl->link);
919 | INVARIANT IDENTIFIER // Vertex only.
922 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
924 $$ = new(ctx) ast_declarator_list(NULL);
925 $$->set_location(yylloc);
926 $$->invariant = true;
928 $$->declarations.push_tail(&decl->link);
932 fully_specified_type:
936 $$ = new(ctx) ast_fully_specified_type();
937 $$->set_location(yylloc);
940 | type_qualifier type_specifier
943 $$ = new(ctx) ast_fully_specified_type();
944 $$->set_location(yylloc);
945 $$->qualifier = $1.q;
950 opt_layout_qualifier:
956 LAYOUT_TOK '(' layout_qualifier_id_list ')'
962 layout_qualifier_id_list:
964 | layout_qualifier_id_list ',' layout_qualifier_id
975 if (state->ARB_fragment_coord_conventions_enable) {
976 bool got_one = false;
978 if (strcmp($1, "origin_upper_left") == 0) {
980 $$.q.origin_upper_left = 1;
981 } else if (strcmp($1, "pixel_center_integer") == 0) {
983 $$.q.pixel_center_integer = 1;
986 if (state->ARB_fragment_coord_conventions_warn && got_one) {
987 _mesa_glsl_warning(& @1, state,
988 "GL_ARB_fragment_coord_conventions layout "
989 "identifier `%s' used\n", $1);
993 /* If the identifier didn't match any known layout identifiers,
997 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1004 interpolation_qualifier:
1005 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
1006 | FLAT { $$.i = 0; $$.q.flat = 1; }
1007 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1010 parameter_type_qualifier:
1011 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1016 | interpolation_qualifier type_qualifier
1020 | INVARIANT type_qualifier
1028 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1029 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1030 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1031 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1032 | opt_layout_qualifier IN { $$.i = 0; $$.q.in = 1; }
1033 | OUT { $$.i = 0; $$.q.out = 1; }
1034 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1035 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1036 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1040 type_specifier_no_prec
1041 | precision_qualifier type_specifier_no_prec
1048 type_specifier_no_prec:
1049 type_specifier_nonarray
1050 | type_specifier_nonarray '[' ']'
1053 $$->is_array = true;
1054 $$->array_size = NULL;
1056 | type_specifier_nonarray '[' constant_expression ']'
1059 $$->is_array = true;
1060 $$->array_size = $3;
1064 type_specifier_nonarray:
1065 basic_type_specifier_nonarray
1068 $$ = new(ctx) ast_type_specifier($1);
1069 $$->set_location(yylloc);
1074 $$ = new(ctx) ast_type_specifier($1);
1075 $$->set_location(yylloc);
1080 $$ = new(ctx) ast_type_specifier($1);
1081 $$->set_location(yylloc);
1085 basic_type_specifier_nonarray:
1086 VOID { $$ = ast_void; }
1087 | FLOAT { $$ = ast_float; }
1088 | INT { $$ = ast_int; }
1089 | UINT { $$ = ast_uint; }
1090 | BOOL { $$ = ast_bool; }
1091 | VEC2 { $$ = ast_vec2; }
1092 | VEC3 { $$ = ast_vec3; }
1093 | VEC4 { $$ = ast_vec4; }
1094 | BVEC2 { $$ = ast_bvec2; }
1095 | BVEC3 { $$ = ast_bvec3; }
1096 | BVEC4 { $$ = ast_bvec4; }
1097 | IVEC2 { $$ = ast_ivec2; }
1098 | IVEC3 { $$ = ast_ivec3; }
1099 | IVEC4 { $$ = ast_ivec4; }
1100 | UVEC2 { $$ = ast_uvec2; }
1101 | UVEC3 { $$ = ast_uvec3; }
1102 | UVEC4 { $$ = ast_uvec4; }
1103 | MAT2 { $$ = ast_mat2; }
1104 | MAT3 { $$ = ast_mat3; }
1105 | MAT4 { $$ = ast_mat4; }
1106 | MAT2X2 { $$ = ast_mat2; }
1107 | MAT2X3 { $$ = ast_mat2x3; }
1108 | MAT2X4 { $$ = ast_mat2x4; }
1109 | MAT3X2 { $$ = ast_mat3x2; }
1110 | MAT3X3 { $$ = ast_mat3; }
1111 | MAT3X4 { $$ = ast_mat3x4; }
1112 | MAT4X2 { $$ = ast_mat4x2; }
1113 | MAT4X3 { $$ = ast_mat4x3; }
1114 | MAT4X4 { $$ = ast_mat4; }
1115 | SAMPLER1D { $$ = ast_sampler1d; }
1116 | SAMPLER2D { $$ = ast_sampler2d; }
1117 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1118 | SAMPLER3D { $$ = ast_sampler3d; }
1119 | SAMPLERCUBE { $$ = ast_samplercube; }
1120 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1121 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1122 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1123 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1124 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1125 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1126 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1127 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1128 | ISAMPLER1D { $$ = ast_isampler1d; }
1129 | ISAMPLER2D { $$ = ast_isampler2d; }
1130 | ISAMPLER3D { $$ = ast_isampler3d; }
1131 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1132 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1133 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1134 | USAMPLER1D { $$ = ast_usampler1d; }
1135 | USAMPLER2D { $$ = ast_usampler2d; }
1136 | USAMPLER3D { $$ = ast_usampler3d; }
1137 | USAMPLERCUBE { $$ = ast_usamplercube; }
1138 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1139 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1142 precision_qualifier:
1144 if (state->language_version < 130)
1145 _mesa_glsl_error(& @1, state,
1146 "precision qualifier forbidden "
1147 "in GLSL %d.%d (1.30 or later "
1149 state->language_version / 100,
1150 state->language_version % 100);
1152 $$ = ast_precision_high;
1155 if (state->language_version < 130)
1156 _mesa_glsl_error(& @1, state,
1157 "precision qualifier forbidden "
1158 "in GLSL %d.%d (1.30 or later "
1160 state->language_version / 100,
1161 state->language_version % 100);
1163 $$ = ast_precision_medium;
1166 if (state->language_version < 130)
1167 _mesa_glsl_error(& @1, state,
1168 "precision qualifier forbidden "
1169 "in GLSL %d.%d (1.30 or later "
1171 state->language_version / 100,
1172 state->language_version % 100);
1174 $$ = ast_precision_low;
1179 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1182 $$ = new(ctx) ast_struct_specifier($2, $4);
1183 $$->set_location(yylloc);
1185 | STRUCT '{' struct_declaration_list '}'
1188 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1189 $$->set_location(yylloc);
1193 struct_declaration_list:
1196 $$ = (struct ast_node *) $1;
1197 $1->link.self_link();
1199 | struct_declaration_list struct_declaration
1201 $$ = (struct ast_node *) $1;
1202 $$->link.insert_before(& $2->link);
1207 type_specifier struct_declarator_list ';'
1210 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1211 type->set_location(yylloc);
1213 type->specifier = $1;
1214 $$ = new(ctx) ast_declarator_list(type);
1215 $$->set_location(yylloc);
1217 $$->declarations.push_degenerate_list_at_head(& $2->link);
1221 struct_declarator_list:
1225 $1->link.self_link();
1227 | struct_declarator_list ',' struct_declarator
1230 $$->link.insert_before(& $3->link);
1238 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1239 $$->set_location(yylloc);
1241 | IDENTIFIER '[' constant_expression ']'
1244 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1245 $$->set_location(yylloc);
1250 assignment_expression
1253 declaration_statement:
1257 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1261 | statement_unmatched
1265 compound_statement { $$ = (struct ast_node *) $1; }
1269 statement_unmatched:
1270 selection_statement_unmatched
1274 declaration_statement
1275 | expression_statement
1276 | selection_statement_matched
1277 | switch_statement { $$ = NULL; }
1278 | case_label { $$ = NULL; }
1279 | iteration_statement
1287 $$ = new(ctx) ast_compound_statement(true, NULL);
1288 $$->set_location(yylloc);
1290 | '{' statement_list '}'
1293 $$ = new(ctx) ast_compound_statement(true, $2);
1294 $$->set_location(yylloc);
1298 statement_no_new_scope:
1299 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1303 compound_statement_no_new_scope:
1307 $$ = new(ctx) ast_compound_statement(false, NULL);
1308 $$->set_location(yylloc);
1310 | '{' statement_list '}'
1313 $$ = new(ctx) ast_compound_statement(false, $2);
1314 $$->set_location(yylloc);
1322 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1327 $$->link.self_link();
1329 | statement_list statement
1332 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1336 $$->link.insert_before(& $2->link);
1340 expression_statement:
1344 $$ = new(ctx) ast_expression_statement(NULL);
1345 $$->set_location(yylloc);
1350 $$ = new(ctx) ast_expression_statement($1);
1351 $$->set_location(yylloc);
1355 selection_statement_matched:
1356 IF '(' expression ')' statement_matched ELSE statement_matched
1359 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1360 $$->set_location(yylloc);
1364 selection_statement_unmatched:
1365 IF '(' expression ')' statement_matched
1368 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1369 $$->set_location(yylloc);
1371 | IF '(' expression ')' statement_unmatched
1374 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1375 $$->set_location(yylloc);
1377 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1380 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1381 $$->set_location(yylloc);
1388 $$ = (struct ast_node *) $1;
1390 | fully_specified_type IDENTIFIER '=' initializer
1393 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1394 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1395 decl->set_location(yylloc);
1396 declarator->set_location(yylloc);
1398 declarator->declarations.push_tail(&decl->link);
1404 SWITCH '(' expression ')' compound_statement
1412 iteration_statement:
1413 WHILE '(' condition ')' statement_no_new_scope
1416 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1417 NULL, $3, NULL, $5);
1418 $$->set_location(yylloc);
1420 | DO statement WHILE '(' expression ')' ';'
1423 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1424 NULL, $5, NULL, $2);
1425 $$->set_location(yylloc);
1427 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1430 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1431 $3, $4.cond, $4.rest, $6);
1432 $$->set_location(yylloc);
1437 expression_statement
1438 | declaration_statement
1455 | conditionopt ';' expression
1462 // Grammar Note: No 'goto'. Gotos are not supported.
1467 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1468 $$->set_location(yylloc);
1473 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1474 $$->set_location(yylloc);
1479 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1480 $$->set_location(yylloc);
1482 | RETURN expression ';'
1485 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1486 $$->set_location(yylloc);
1488 | DISCARD ';' // Fragment shader only.
1491 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1492 $$->set_location(yylloc);
1496 external_declaration:
1497 function_definition { $$ = $1; }
1498 | declaration { $$ = $1; }
1501 function_definition:
1502 function_prototype compound_statement_no_new_scope
1505 $$ = new(ctx) ast_function_definition();
1506 $$->set_location(yylloc);