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
41 %lex-param {void *scanner}
42 %parse-param {struct _mesa_glsl_parse_state *state}
43 %name-prefix "_mesa_glsl_"
51 struct ast_type_qualifier q;
55 struct ast_node *node;
56 struct ast_type_specifier *type_specifier;
57 struct ast_fully_specified_type *fully_specified_type;
58 struct ast_function *function;
59 struct ast_parameter_declarator *parameter_declarator;
60 struct ast_function_definition *function_definition;
61 struct ast_compound_statement *compound_statement;
62 struct ast_expression *expression;
63 struct ast_declarator_list *declarator_list;
64 struct ast_struct_specifier *struct_specifier;
65 struct ast_declaration *declaration;
68 struct ast_node *cond;
69 struct ast_expression *rest;
73 %token ATTRIBUTE CONST BOOL FLOAT INT UINT
74 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
75 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
76 %token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
77 %token NOPERSPECTIVE FLAT SMOOTH
78 %token MAT2X2 MAT2X3 MAT2X4
79 %token MAT3X2 MAT3X3 MAT3X4
80 %token MAT4X2 MAT4X3 MAT4X4
81 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
82 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
83 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
84 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
85 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
86 %token STRUCT VOID WHILE
87 %token <identifier> IDENTIFIER TYPE_NAME
88 %token <real> FLOATCONSTANT
89 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
90 %token <identifier> FIELD_SELECTION
91 %token LEFT_OP RIGHT_OP
92 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
93 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
94 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
97 %token HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
99 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
101 /* Reserved words that are not actually used in the grammar.
103 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
104 %token INLINE NOINLINE VOLATILE PUBLIC STATIC EXTERN EXTERNAL
105 %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
106 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
107 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
108 %token SIZEOF CAST NAMESPACE USING LOWP MEDIUMP HIGHP
110 %type <identifier> variable_identifier
111 %type <node> statement
112 %type <node> statement_list
113 %type <node> simple_statement
114 %type <node> statement_matched
115 %type <node> statement_unmatched
116 %type <n> precision_qualifier
117 %type <type_qualifier> type_qualifier
118 %type <type_qualifier> storage_qualifier
119 %type <type_qualifier> interpolation_qualifier
120 %type <type_specifier> type_specifier
121 %type <type_specifier> type_specifier_no_prec
122 %type <type_specifier> type_specifier_nonarray
123 %type <n> basic_type_specifier_nonarray
124 %type <fully_specified_type> fully_specified_type
125 %type <function> function_prototype
126 %type <function> function_header
127 %type <function> function_header_with_parameters
128 %type <function> function_declarator
129 %type <parameter_declarator> parameter_declarator
130 %type <parameter_declarator> parameter_declaration
131 %type <type_qualifier> parameter_qualifier
132 %type <type_qualifier> parameter_type_qualifier
133 %type <type_specifier> parameter_type_specifier
134 %type <function_definition> function_definition
135 %type <compound_statement> compound_statement_no_new_scope
136 %type <compound_statement> compound_statement
137 %type <node> statement_no_new_scope
138 %type <node> expression_statement
139 %type <expression> expression
140 %type <expression> primary_expression
141 %type <expression> assignment_expression
142 %type <expression> conditional_expression
143 %type <expression> logical_or_expression
144 %type <expression> logical_xor_expression
145 %type <expression> logical_and_expression
146 %type <expression> inclusive_or_expression
147 %type <expression> exclusive_or_expression
148 %type <expression> and_expression
149 %type <expression> equality_expression
150 %type <expression> relational_expression
151 %type <expression> shift_expression
152 %type <expression> additive_expression
153 %type <expression> multiplicative_expression
154 %type <expression> unary_expression
155 %type <expression> constant_expression
156 %type <expression> integer_expression
157 %type <expression> postfix_expression
158 %type <expression> function_call_header_with_parameters
159 %type <expression> function_call_header_no_parameters
160 %type <expression> function_call_header
161 %type <expression> function_call_generic
162 %type <expression> function_call_or_method
163 %type <expression> function_call
164 %type <n> assignment_operator
165 %type <n> unary_operator
166 %type <expression> function_identifier
167 %type <node> external_declaration
168 %type <declarator_list> init_declarator_list
169 %type <declarator_list> single_declaration
170 %type <expression> initializer
171 %type <node> declaration
172 %type <node> declaration_statement
173 %type <node> jump_statement
174 %type <struct_specifier> struct_specifier
175 %type <node> struct_declaration_list
176 %type <declarator_list> struct_declaration
177 %type <declaration> struct_declarator
178 %type <declaration> struct_declarator_list
179 %type <node> selection_statement_matched
180 %type <node> selection_statement_unmatched
181 %type <node> iteration_statement
182 %type <node> condition
183 %type <node> conditionopt
184 %type <node> for_init_statement
185 %type <for_rest_statement> for_rest_statement
191 _mesa_glsl_initialize_types(state);
193 external_declaration_list
196 state->language_version = 110;
197 _mesa_glsl_initialize_types(state);
199 external_declaration_list
203 VERSION INTCONSTANT EOL
209 /* FINISHME: Check against implementation support versions. */
210 state->language_version = $2;
213 _mesa_glsl_error(& @2, state, "Shading language version"
214 "%u is not supported\n", $2);
220 external_declaration_list:
223 insert_at_tail(& state->translation_unit,
224 (struct simple_node *) $1);
226 | external_declaration_list external_declaration
228 insert_at_tail(& state->translation_unit,
229 (struct simple_node *) $2);
240 $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
241 $$->set_location(yylloc);
242 $$->primary_expression.identifier = $1;
246 $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
247 $$->set_location(yylloc);
248 $$->primary_expression.int_constant = $1;
252 $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
253 $$->set_location(yylloc);
254 $$->primary_expression.uint_constant = $1;
258 $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
259 $$->set_location(yylloc);
260 $$->primary_expression.float_constant = $1;
264 $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
265 $$->set_location(yylloc);
266 $$->primary_expression.bool_constant = $1;
276 | postfix_expression '[' integer_expression ']'
278 $$ = new ast_expression(ast_array_index, $1, $3, NULL);
279 $$->set_location(yylloc);
285 | postfix_expression '.' IDENTIFIER
287 $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
288 $$->set_location(yylloc);
289 $$->primary_expression.identifier = $3;
291 | postfix_expression INC_OP
293 $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
294 $$->set_location(yylloc);
296 | postfix_expression DEC_OP
298 $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
299 $$->set_location(yylloc);
308 function_call_or_method
311 function_call_or_method:
312 function_call_generic
313 | postfix_expression '.' function_call_generic
315 $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
316 $$->set_location(yylloc);
320 function_call_generic:
321 function_call_header_with_parameters ')'
322 | function_call_header_no_parameters ')'
325 function_call_header_no_parameters:
326 function_call_header VOID
327 | function_call_header
330 function_call_header_with_parameters:
331 function_call_header assignment_expression
334 $$->set_location(yylloc);
335 $$->subexpressions[1] = $2;
337 | function_call_header_with_parameters ',' assignment_expression
340 $$->set_location(yylloc);
341 insert_at_tail((struct simple_node *) $$->subexpressions[1],
342 (struct simple_node *) $3);
346 // Grammar Note: Constructors look like functions, but lexical
347 // analysis recognized most of them as keywords. They are now
348 // recognized through "type_specifier".
349 function_call_header:
350 function_identifier '('
356 $$ = new ast_function_expression($1);
357 $$->set_location(yylloc);
361 ast_expression *callee = new ast_expression($1);
362 $$ = new ast_function_expression(callee);
363 $$->set_location(yylloc);
367 ast_expression *callee = new ast_expression($1);
368 $$ = new ast_function_expression(callee);
369 $$->set_location(yylloc);
373 // Grammar Note: No traditional style type casts.
376 | INC_OP unary_expression
378 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
379 $$->set_location(yylloc);
381 | DEC_OP unary_expression
383 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
384 $$->set_location(yylloc);
386 | unary_operator unary_expression
388 $$ = new ast_expression($1, $2, NULL, NULL);
389 $$->set_location(yylloc);
393 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
395 '+' { $$ = ast_plus; }
396 | '-' { $$ = ast_neg; }
397 | '!' { $$ = ast_logic_not; }
398 | '~' { $$ = ast_bit_not; }
401 multiplicative_expression:
403 | multiplicative_expression '*' unary_expression
405 $$ = new ast_expression_bin(ast_mul, $1, $3);
406 $$->set_location(yylloc);
408 | multiplicative_expression '/' unary_expression
410 $$ = new ast_expression_bin(ast_div, $1, $3);
411 $$->set_location(yylloc);
413 | multiplicative_expression '%' unary_expression
415 $$ = new ast_expression_bin(ast_mod, $1, $3);
416 $$->set_location(yylloc);
421 multiplicative_expression
422 | additive_expression '+' multiplicative_expression
424 $$ = new ast_expression_bin(ast_add, $1, $3);
425 $$->set_location(yylloc);
427 | additive_expression '-' multiplicative_expression
429 $$ = new ast_expression_bin(ast_sub, $1, $3);
430 $$->set_location(yylloc);
436 | shift_expression LEFT_OP additive_expression
438 $$ = new ast_expression_bin(ast_lshift, $1, $3);
439 $$->set_location(yylloc);
441 | shift_expression RIGHT_OP additive_expression
443 $$ = new ast_expression_bin(ast_rshift, $1, $3);
444 $$->set_location(yylloc);
448 relational_expression:
450 | relational_expression '<' shift_expression
452 $$ = new ast_expression_bin(ast_less, $1, $3);
453 $$->set_location(yylloc);
455 | relational_expression '>' shift_expression
457 $$ = new ast_expression_bin(ast_greater, $1, $3);
458 $$->set_location(yylloc);
460 | relational_expression LE_OP shift_expression
462 $$ = new ast_expression_bin(ast_lequal, $1, $3);
463 $$->set_location(yylloc);
465 | relational_expression GE_OP shift_expression
467 $$ = new ast_expression_bin(ast_gequal, $1, $3);
468 $$->set_location(yylloc);
473 relational_expression
474 | equality_expression EQ_OP relational_expression
476 $$ = new ast_expression_bin(ast_equal, $1, $3);
477 $$->set_location(yylloc);
479 | equality_expression NE_OP relational_expression
481 $$ = new ast_expression_bin(ast_nequal, $1, $3);
482 $$->set_location(yylloc);
488 | and_expression '&' equality_expression
490 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
491 $$->set_location(yylloc);
495 exclusive_or_expression:
497 | exclusive_or_expression '^' and_expression
499 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
500 $$->set_location(yylloc);
504 inclusive_or_expression:
505 exclusive_or_expression
506 | inclusive_or_expression '|' exclusive_or_expression
508 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
509 $$->set_location(yylloc);
513 logical_and_expression:
514 inclusive_or_expression
515 | logical_and_expression AND_OP inclusive_or_expression
517 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
518 $$->set_location(yylloc);
522 logical_xor_expression:
523 logical_and_expression
524 | logical_xor_expression XOR_OP logical_and_expression
526 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
527 $$->set_location(yylloc);
531 logical_or_expression:
532 logical_xor_expression
533 | logical_or_expression OR_OP logical_xor_expression
535 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
536 $$->set_location(yylloc);
540 conditional_expression:
541 logical_or_expression
542 | logical_or_expression '?' expression ':' assignment_expression
544 $$ = new ast_expression(ast_conditional, $1, $3, $5);
545 $$->set_location(yylloc);
549 assignment_expression:
550 conditional_expression
551 | unary_expression assignment_operator assignment_expression
553 $$ = new ast_expression($2, $1, $3, NULL);
554 $$->set_location(yylloc);
559 '=' { $$ = ast_assign; }
560 | MUL_ASSIGN { $$ = ast_mul_assign; }
561 | DIV_ASSIGN { $$ = ast_div_assign; }
562 | MOD_ASSIGN { $$ = ast_mod_assign; }
563 | ADD_ASSIGN { $$ = ast_add_assign; }
564 | SUB_ASSIGN { $$ = ast_sub_assign; }
565 | LEFT_ASSIGN { $$ = ast_ls_assign; }
566 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
567 | AND_ASSIGN { $$ = ast_and_assign; }
568 | XOR_ASSIGN { $$ = ast_xor_assign; }
569 | OR_ASSIGN { $$ = ast_or_assign; }
573 assignment_expression
577 | expression ',' assignment_expression
579 if ($1->oper != ast_sequence) {
580 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
581 $$->set_location(yylloc);
582 insert_at_tail(& $$->expressions, $1);
587 insert_at_tail(& $$->expressions, $3);
592 conditional_expression
596 function_prototype ';'
600 | init_declarator_list ';'
604 | PRECISION precision_qualifier type_specifier_no_prec ';'
606 $$ = NULL; /* FINISHME */
611 function_declarator ')'
616 | function_header_with_parameters
619 function_header_with_parameters:
620 function_header parameter_declaration
623 insert_at_tail(& $$->parameters,
624 (struct simple_node *) $2);
626 | function_header_with_parameters ',' parameter_declaration
629 insert_at_tail(& $$->parameters,
630 (struct simple_node *) $3);
635 fully_specified_type IDENTIFIER '('
637 $$ = new ast_function();
638 $$->set_location(yylloc);
639 $$->return_type = $1;
644 parameter_declarator:
645 type_specifier IDENTIFIER
647 $$ = new ast_parameter_declarator();
648 $$->set_location(yylloc);
649 $$->type = new ast_fully_specified_type();
650 $$->type->set_location(yylloc);
651 $$->type->specifier = $1;
654 | type_specifier IDENTIFIER '[' constant_expression ']'
656 $$ = new ast_parameter_declarator();
657 $$->set_location(yylloc);
658 $$->type = new ast_fully_specified_type();
659 $$->type->set_location(yylloc);
660 $$->type->specifier = $1;
667 parameter_declaration:
668 parameter_type_qualifier parameter_qualifier parameter_declarator
673 $$->type->qualifier = $1.q;
675 | parameter_qualifier parameter_declarator
678 $$->type->qualifier = $1.q;
680 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
684 $$ = new ast_parameter_declarator();
685 $$->set_location(yylloc);
686 $$->type = new ast_fully_specified_type();
687 $$->type->qualifier = $1.q;
688 $$->type->specifier = $3;
690 | parameter_qualifier parameter_type_specifier
692 $$ = new ast_parameter_declarator();
693 $$->set_location(yylloc);
694 $$->type = new ast_fully_specified_type();
695 $$->type->qualifier = $1.q;
696 $$->type->specifier = $2;
701 /* empty */ { $$.i = 0; }
702 | IN { $$.i = 0; $$.q.in = 1; }
703 | OUT { $$.i = 0; $$.q.out = 1; }
704 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
707 parameter_type_specifier:
711 init_declarator_list:
713 | init_declarator_list ',' IDENTIFIER
715 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
716 decl->set_location(yylloc);
719 insert_at_tail(& $$->declarations,
720 (struct simple_node *) decl);
722 | init_declarator_list ',' IDENTIFIER '[' ']'
724 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
725 decl->set_location(yylloc);
728 insert_at_tail(& $$->declarations,
729 (struct simple_node *) decl);
731 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
733 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
734 decl->set_location(yylloc);
737 insert_at_tail(& $$->declarations,
738 (struct simple_node *) decl);
740 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
742 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
743 decl->set_location(yylloc);
746 insert_at_tail(& $$->declarations,
747 (struct simple_node *) decl);
749 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
751 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
752 decl->set_location(yylloc);
755 insert_at_tail(& $$->declarations,
756 (struct simple_node *) decl);
758 | init_declarator_list ',' IDENTIFIER '=' initializer
760 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
761 decl->set_location(yylloc);
764 insert_at_tail(& $$->declarations,
765 (struct simple_node *) decl);
769 // Grammar Note: No 'enum', or 'typedef'.
773 $$ = new ast_declarator_list($1);
774 $$->set_location(yylloc);
776 | fully_specified_type IDENTIFIER
778 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
780 $$ = new ast_declarator_list($1);
781 $$->set_location(yylloc);
782 insert_at_tail(& $$->declarations,
783 (struct simple_node *) decl);
785 | fully_specified_type IDENTIFIER '[' ']'
787 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
789 $$ = new ast_declarator_list($1);
790 $$->set_location(yylloc);
791 insert_at_tail(& $$->declarations,
792 (struct simple_node *) decl);
794 | fully_specified_type IDENTIFIER '[' constant_expression ']'
796 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
798 $$ = new ast_declarator_list($1);
799 $$->set_location(yylloc);
800 insert_at_tail(& $$->declarations,
801 (struct simple_node *) decl);
803 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
805 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
807 $$ = new ast_declarator_list($1);
808 $$->set_location(yylloc);
809 insert_at_tail(& $$->declarations,
810 (struct simple_node *) decl);
812 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
814 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
816 $$ = new ast_declarator_list($1);
817 $$->set_location(yylloc);
818 insert_at_tail(& $$->declarations,
819 (struct simple_node *) decl);
821 | fully_specified_type IDENTIFIER '=' initializer
823 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
825 $$ = new ast_declarator_list($1);
826 $$->set_location(yylloc);
827 insert_at_tail(& $$->declarations,
828 (struct simple_node *) decl);
830 | INVARIANT IDENTIFIER // Vertex only.
832 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
834 $$ = new ast_declarator_list(NULL);
835 $$->set_location(yylloc);
836 $$->invariant = true;
838 insert_at_tail(& $$->declarations,
839 (struct simple_node *) decl);
843 fully_specified_type:
846 $$ = new ast_fully_specified_type();
847 $$->set_location(yylloc);
850 | type_qualifier type_specifier
852 $$ = new ast_fully_specified_type();
853 $$->set_location(yylloc);
854 $$->qualifier = $1.q;
859 interpolation_qualifier:
860 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
861 | FLAT { $$.i = 0; $$.q.flat = 1; }
862 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
865 parameter_type_qualifier:
866 CONST { $$.i = 0; $$.q.constant = 1; }
871 | interpolation_qualifier type_qualifier
875 | INVARIANT type_qualifier
883 CONST { $$.i = 0; $$.q.constant = 1; }
884 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
885 | VARYING { $$.i = 0; $$.q.varying = 1; }
886 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
887 | IN { $$.i = 0; $$.q.in = 1; }
888 | OUT { $$.i = 0; $$.q.out = 1; }
889 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
890 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
891 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
895 type_specifier_no_prec
896 | precision_qualifier type_specifier_no_prec
903 type_specifier_no_prec:
904 type_specifier_nonarray
905 | type_specifier_nonarray '[' ']'
909 $$->array_size = NULL;
911 | type_specifier_nonarray '[' constant_expression ']'
919 type_specifier_nonarray:
920 basic_type_specifier_nonarray
922 $$ = new ast_type_specifier($1);
923 $$->set_location(yylloc);
927 $$ = new ast_type_specifier($1);
928 $$->set_location(yylloc);
932 $$ = new ast_type_specifier($1);
933 $$->set_location(yylloc);
937 basic_type_specifier_nonarray:
938 VOID { $$ = ast_void; }
939 | FLOAT { $$ = ast_float; }
940 | INT { $$ = ast_int; }
941 | UINT { $$ = ast_uint; }
942 | BOOL { $$ = ast_bool; }
943 | VEC2 { $$ = ast_vec2; }
944 | VEC3 { $$ = ast_vec3; }
945 | VEC4 { $$ = ast_vec4; }
946 | BVEC2 { $$ = ast_bvec2; }
947 | BVEC3 { $$ = ast_bvec3; }
948 | BVEC4 { $$ = ast_bvec4; }
949 | IVEC2 { $$ = ast_ivec2; }
950 | IVEC3 { $$ = ast_ivec3; }
951 | IVEC4 { $$ = ast_ivec4; }
952 | UVEC2 { $$ = ast_uvec2; }
953 | UVEC3 { $$ = ast_uvec3; }
954 | UVEC4 { $$ = ast_uvec4; }
955 | MAT2 { $$ = ast_mat2; }
956 | MAT3 { $$ = ast_mat3; }
957 | MAT4 { $$ = ast_mat4; }
958 | MAT2X2 { $$ = ast_mat2; }
959 | MAT2X3 { $$ = ast_mat2x3; }
960 | MAT2X4 { $$ = ast_mat2x4; }
961 | MAT3X2 { $$ = ast_mat3x2; }
962 | MAT3X3 { $$ = ast_mat3; }
963 | MAT3X4 { $$ = ast_mat3x4; }
964 | MAT4X2 { $$ = ast_mat4x2; }
965 | MAT4X3 { $$ = ast_mat4x3; }
966 | MAT4X4 { $$ = ast_mat4; }
967 | SAMPLER1D { $$ = ast_sampler1d; }
968 | SAMPLER2D { $$ = ast_sampler2d; }
969 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
970 | SAMPLER3D { $$ = ast_sampler3d; }
971 | SAMPLERCUBE { $$ = ast_samplercube; }
972 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
973 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
974 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
975 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
976 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
977 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
978 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
979 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
980 | ISAMPLER1D { $$ = ast_isampler1d; }
981 | ISAMPLER2D { $$ = ast_isampler2d; }
982 | ISAMPLER3D { $$ = ast_isampler3d; }
983 | ISAMPLERCUBE { $$ = ast_isamplercube; }
984 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
985 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
986 | USAMPLER1D { $$ = ast_usampler1d; }
987 | USAMPLER2D { $$ = ast_usampler2d; }
988 | USAMPLER3D { $$ = ast_usampler3d; }
989 | USAMPLERCUBE { $$ = ast_usamplercube; }
990 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
991 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
995 HIGH_PRECISION { $$ = ast_precision_high; }
996 | MEDIUM_PRECISION { $$ = ast_precision_medium; }
997 | LOW_PRECISION { $$ = ast_precision_low; }
1001 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1003 $$ = new ast_struct_specifier($2, $4);
1004 $$->set_location(yylloc);
1006 | STRUCT '{' struct_declaration_list '}'
1008 $$ = new ast_struct_specifier(NULL, $3);
1009 $$->set_location(yylloc);
1013 struct_declaration_list:
1016 $$ = (struct ast_node *) $1;
1018 | struct_declaration_list struct_declaration
1020 $$ = (struct ast_node *) $1;
1021 insert_at_tail((struct simple_node *) $$,
1022 (struct simple_node *) $2);
1027 type_specifier struct_declarator_list ';'
1029 ast_fully_specified_type *type = new ast_fully_specified_type();
1030 type->set_location(yylloc);
1032 type->specifier = $1;
1033 $$ = new ast_declarator_list(type);
1034 $$->set_location(yylloc);
1036 insert_at_tail((struct simple_node *) $2,
1037 & $$->declarations);
1041 struct_declarator_list:
1043 | struct_declarator_list ',' struct_declarator
1046 insert_at_tail((struct simple_node *) $$,
1047 (struct simple_node *) $3);
1054 $$ = new ast_declaration($1, false, NULL, NULL);
1055 $$->set_location(yylloc);
1057 | IDENTIFIER '[' constant_expression ']'
1059 $$ = new ast_declaration($1, true, $3, NULL);
1060 $$->set_location(yylloc);
1065 assignment_expression
1068 declaration_statement:
1072 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1076 | statement_unmatched
1080 compound_statement { $$ = (struct ast_node *) $1; }
1084 statement_unmatched:
1085 selection_statement_unmatched
1089 declaration_statement
1090 | expression_statement
1091 | selection_statement_matched
1092 | switch_statement { $$ = NULL; }
1093 | case_label { $$ = NULL; }
1094 | iteration_statement
1101 $$ = new ast_compound_statement(true, NULL);
1102 $$->set_location(yylloc);
1104 | '{' statement_list '}'
1106 $$ = new ast_compound_statement(true, $2);
1107 $$->set_location(yylloc);
1111 statement_no_new_scope:
1112 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1116 compound_statement_no_new_scope:
1119 $$ = new ast_compound_statement(false, NULL);
1120 $$->set_location(yylloc);
1122 | '{' statement_list '}'
1124 $$ = new ast_compound_statement(false, $2);
1125 $$->set_location(yylloc);
1133 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1138 make_empty_list((struct simple_node *) $$);
1140 | statement_list statement
1143 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1147 insert_at_tail((struct simple_node *) $$,
1148 (struct simple_node *) $2);
1152 expression_statement:
1155 $$ = new ast_expression_statement(NULL);
1156 $$->set_location(yylloc);
1160 $$ = new ast_expression_statement($1);
1161 $$->set_location(yylloc);
1165 selection_statement_matched:
1166 IF '(' expression ')' statement_matched ELSE statement_matched
1168 $$ = new ast_selection_statement($3, $5, $7);
1169 $$->set_location(yylloc);
1173 selection_statement_unmatched:
1174 IF '(' expression ')' statement_matched
1176 $$ = new ast_selection_statement($3, $5, NULL);
1177 $$->set_location(yylloc);
1179 | IF '(' expression ')' statement_unmatched
1181 $$ = new ast_selection_statement($3, $5, NULL);
1182 $$->set_location(yylloc);
1184 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1186 $$ = new ast_selection_statement($3, $5, $7);
1187 $$->set_location(yylloc);
1194 $$ = (struct ast_node *) $1;
1196 | fully_specified_type IDENTIFIER '=' initializer
1198 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1199 ast_declarator_list *declarator = new ast_declarator_list($1);
1200 decl->set_location(yylloc);
1201 declarator->set_location(yylloc);
1203 insert_at_tail(& declarator->declarations,
1204 (struct simple_node *) decl);
1211 SWITCH '(' expression ')' compound_statement
1219 iteration_statement:
1220 WHILE '(' condition ')' statement_no_new_scope
1222 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1223 NULL, $3, NULL, $5);
1224 $$->set_location(yylloc);
1226 | DO statement WHILE '(' expression ')' ';'
1228 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1229 NULL, $5, NULL, $2);
1230 $$->set_location(yylloc);
1232 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1234 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1235 $3, $4.cond, $4.rest, $6);
1236 $$->set_location(yylloc);
1241 expression_statement
1242 | declaration_statement
1259 | conditionopt ';' expression
1266 // Grammar Note: No 'goto'. Gotos are not supported.
1270 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1271 $$->set_location(yylloc);
1275 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1276 $$->set_location(yylloc);
1280 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1281 $$->set_location(yylloc);
1283 | RETURN expression ';'
1285 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1286 $$->set_location(yylloc);
1288 | DISCARD ';' // Fragment shader only.
1290 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1291 $$->set_location(yylloc);
1295 external_declaration:
1296 function_definition { $$ = $1; }
1297 | declaration { $$ = $1; }
1300 function_definition:
1301 function_prototype compound_statement_no_new_scope
1303 $$ = new ast_function_definition();
1304 $$->set_location(yylloc);