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
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 LOWP MEDIUMP HIGHP 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
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
189 version_statement extension_statement_list
191 _mesa_glsl_initialize_types(state);
193 external_declaration_list
197 /* blank - no #version specified */
199 state->language_version = 110;
201 | VERSION INTCONSTANT EOL
207 /* FINISHME: Check against implementation support versions. */
208 state->language_version = $2;
211 _mesa_glsl_error(& @2, state, "Shading language version"
212 "%u is not supported\n", $2);
218 extension_statement_list:
220 | extension_statement_list extension_statement
224 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
226 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
232 external_declaration_list:
235 /* FINISHME: The NULL test is only required because 'precision'
236 * FINISHME: statements are not yet supported.
239 state->translation_unit.push_tail(& $1->link);
241 | external_declaration_list external_declaration
243 /* FINISHME: The NULL test is only required because 'precision'
244 * FINISHME: statements are not yet supported.
247 state->translation_unit.push_tail(& $2->link);
258 $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
259 $$->set_location(yylloc);
260 $$->primary_expression.identifier = $1;
264 $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
265 $$->set_location(yylloc);
266 $$->primary_expression.int_constant = $1;
270 $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
271 $$->set_location(yylloc);
272 $$->primary_expression.uint_constant = $1;
276 $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
277 $$->set_location(yylloc);
278 $$->primary_expression.float_constant = $1;
282 $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
283 $$->set_location(yylloc);
284 $$->primary_expression.bool_constant = $1;
294 | postfix_expression '[' integer_expression ']'
296 $$ = new ast_expression(ast_array_index, $1, $3, NULL);
297 $$->set_location(yylloc);
301 /* Function call parameters used to be stored as a circular list in
302 * subexpressions[1]. They are now stored as a regular list in
303 * expressions. This assertion validates that the old code was
304 * correctly converted. It can eventually be removed.
306 assert($1->subexpressions[1] == NULL);
309 | postfix_expression '.' IDENTIFIER
311 $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
312 $$->set_location(yylloc);
313 $$->primary_expression.identifier = $3;
315 | postfix_expression INC_OP
317 $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
318 $$->set_location(yylloc);
320 | postfix_expression DEC_OP
322 $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
323 $$->set_location(yylloc);
332 function_call_or_method
335 function_call_or_method:
336 function_call_generic
337 | postfix_expression '.' function_call_generic
339 $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
340 $$->set_location(yylloc);
344 function_call_generic:
345 function_call_header_with_parameters ')'
346 | function_call_header_no_parameters ')'
349 function_call_header_no_parameters:
350 function_call_header VOID
351 | function_call_header
354 function_call_header_with_parameters:
355 function_call_header assignment_expression
358 $$->set_location(yylloc);
359 $$->expressions.push_tail(& $2->link);
361 | function_call_header_with_parameters ',' assignment_expression
364 $$->set_location(yylloc);
365 $$->expressions.push_tail(& $3->link);
369 // Grammar Note: Constructors look like functions, but lexical
370 // analysis recognized most of them as keywords. They are now
371 // recognized through "type_specifier".
372 function_call_header:
373 function_identifier '('
379 $$ = new ast_function_expression($1);
380 $$->set_location(yylloc);
384 ast_expression *callee = new ast_expression($1);
385 $$ = new ast_function_expression(callee);
386 $$->set_location(yylloc);
390 ast_expression *callee = new ast_expression($1);
391 $$ = new ast_function_expression(callee);
392 $$->set_location(yylloc);
396 // Grammar Note: No traditional style type casts.
399 | INC_OP unary_expression
401 $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
402 $$->set_location(yylloc);
404 | DEC_OP unary_expression
406 $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
407 $$->set_location(yylloc);
409 | unary_operator unary_expression
411 $$ = new ast_expression($1, $2, NULL, NULL);
412 $$->set_location(yylloc);
416 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
418 '+' { $$ = ast_plus; }
419 | '-' { $$ = ast_neg; }
420 | '!' { $$ = ast_logic_not; }
421 | '~' { $$ = ast_bit_not; }
424 multiplicative_expression:
426 | multiplicative_expression '*' unary_expression
428 $$ = new ast_expression_bin(ast_mul, $1, $3);
429 $$->set_location(yylloc);
431 | multiplicative_expression '/' unary_expression
433 $$ = new ast_expression_bin(ast_div, $1, $3);
434 $$->set_location(yylloc);
436 | multiplicative_expression '%' unary_expression
438 $$ = new ast_expression_bin(ast_mod, $1, $3);
439 $$->set_location(yylloc);
444 multiplicative_expression
445 | additive_expression '+' multiplicative_expression
447 $$ = new ast_expression_bin(ast_add, $1, $3);
448 $$->set_location(yylloc);
450 | additive_expression '-' multiplicative_expression
452 $$ = new ast_expression_bin(ast_sub, $1, $3);
453 $$->set_location(yylloc);
459 | shift_expression LEFT_OP additive_expression
461 $$ = new ast_expression_bin(ast_lshift, $1, $3);
462 $$->set_location(yylloc);
464 | shift_expression RIGHT_OP additive_expression
466 $$ = new ast_expression_bin(ast_rshift, $1, $3);
467 $$->set_location(yylloc);
471 relational_expression:
473 | relational_expression '<' shift_expression
475 $$ = new ast_expression_bin(ast_less, $1, $3);
476 $$->set_location(yylloc);
478 | relational_expression '>' shift_expression
480 $$ = new ast_expression_bin(ast_greater, $1, $3);
481 $$->set_location(yylloc);
483 | relational_expression LE_OP shift_expression
485 $$ = new ast_expression_bin(ast_lequal, $1, $3);
486 $$->set_location(yylloc);
488 | relational_expression GE_OP shift_expression
490 $$ = new ast_expression_bin(ast_gequal, $1, $3);
491 $$->set_location(yylloc);
496 relational_expression
497 | equality_expression EQ_OP relational_expression
499 $$ = new ast_expression_bin(ast_equal, $1, $3);
500 $$->set_location(yylloc);
502 | equality_expression NE_OP relational_expression
504 $$ = new ast_expression_bin(ast_nequal, $1, $3);
505 $$->set_location(yylloc);
511 | and_expression '&' equality_expression
513 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
514 $$->set_location(yylloc);
518 exclusive_or_expression:
520 | exclusive_or_expression '^' and_expression
522 $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
523 $$->set_location(yylloc);
527 inclusive_or_expression:
528 exclusive_or_expression
529 | inclusive_or_expression '|' exclusive_or_expression
531 $$ = new ast_expression_bin(ast_bit_or, $1, $3);
532 $$->set_location(yylloc);
536 logical_and_expression:
537 inclusive_or_expression
538 | logical_and_expression AND_OP inclusive_or_expression
540 $$ = new ast_expression_bin(ast_logic_and, $1, $3);
541 $$->set_location(yylloc);
545 logical_xor_expression:
546 logical_and_expression
547 | logical_xor_expression XOR_OP logical_and_expression
549 $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
550 $$->set_location(yylloc);
554 logical_or_expression:
555 logical_xor_expression
556 | logical_or_expression OR_OP logical_xor_expression
558 $$ = new ast_expression_bin(ast_logic_or, $1, $3);
559 $$->set_location(yylloc);
563 conditional_expression:
564 logical_or_expression
565 | logical_or_expression '?' expression ':' assignment_expression
567 $$ = new ast_expression(ast_conditional, $1, $3, $5);
568 $$->set_location(yylloc);
572 assignment_expression:
573 conditional_expression
574 | unary_expression assignment_operator assignment_expression
576 $$ = new ast_expression($2, $1, $3, NULL);
577 $$->set_location(yylloc);
582 '=' { $$ = ast_assign; }
583 | MUL_ASSIGN { $$ = ast_mul_assign; }
584 | DIV_ASSIGN { $$ = ast_div_assign; }
585 | MOD_ASSIGN { $$ = ast_mod_assign; }
586 | ADD_ASSIGN { $$ = ast_add_assign; }
587 | SUB_ASSIGN { $$ = ast_sub_assign; }
588 | LEFT_ASSIGN { $$ = ast_ls_assign; }
589 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
590 | AND_ASSIGN { $$ = ast_and_assign; }
591 | XOR_ASSIGN { $$ = ast_xor_assign; }
592 | OR_ASSIGN { $$ = ast_or_assign; }
596 assignment_expression
600 | expression ',' assignment_expression
602 if ($1->oper != ast_sequence) {
603 $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
604 $$->set_location(yylloc);
605 $$->expressions.push_tail(& $1->link);
610 $$->expressions.push_tail(& $3->link);
615 conditional_expression
619 function_prototype ';'
623 | init_declarator_list ';'
627 | PRECISION precision_qualifier type_specifier_no_prec ';'
629 if (($3->type_specifier != ast_float)
630 && ($3->type_specifier != ast_int)) {
631 _mesa_glsl_error(& @3, state, "global precision qualifier can "
632 "only be applied to `int' or `float'\n");
636 $$ = NULL; /* FINISHME */
641 function_declarator ')'
646 | function_header_with_parameters
649 function_header_with_parameters:
650 function_header parameter_declaration
653 $$->parameters.push_tail(& $2->link);
655 | function_header_with_parameters ',' parameter_declaration
658 $$->parameters.push_tail(& $3->link);
663 fully_specified_type IDENTIFIER '('
665 $$ = new ast_function();
666 $$->set_location(yylloc);
667 $$->return_type = $1;
672 parameter_declarator:
673 type_specifier IDENTIFIER
675 $$ = new ast_parameter_declarator();
676 $$->set_location(yylloc);
677 $$->type = new ast_fully_specified_type();
678 $$->type->set_location(yylloc);
679 $$->type->specifier = $1;
682 | type_specifier IDENTIFIER '[' constant_expression ']'
684 $$ = new ast_parameter_declarator();
685 $$->set_location(yylloc);
686 $$->type = new ast_fully_specified_type();
687 $$->type->set_location(yylloc);
688 $$->type->specifier = $1;
695 parameter_declaration:
696 parameter_type_qualifier parameter_qualifier parameter_declarator
701 $$->type->qualifier = $1.q;
703 | parameter_qualifier parameter_declarator
706 $$->type->qualifier = $1.q;
708 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
712 $$ = new ast_parameter_declarator();
713 $$->set_location(yylloc);
714 $$->type = new ast_fully_specified_type();
715 $$->type->qualifier = $1.q;
716 $$->type->specifier = $3;
718 | parameter_qualifier parameter_type_specifier
720 $$ = new ast_parameter_declarator();
721 $$->set_location(yylloc);
722 $$->type = new ast_fully_specified_type();
723 $$->type->qualifier = $1.q;
724 $$->type->specifier = $2;
729 /* empty */ { $$.i = 0; }
730 | IN { $$.i = 0; $$.q.in = 1; }
731 | OUT { $$.i = 0; $$.q.out = 1; }
732 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
735 parameter_type_specifier:
739 init_declarator_list:
741 | init_declarator_list ',' IDENTIFIER
743 ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
744 decl->set_location(yylloc);
747 $$->declarations.push_tail(&decl->link);
749 | init_declarator_list ',' IDENTIFIER '[' ']'
751 ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
752 decl->set_location(yylloc);
755 $$->declarations.push_tail(&decl->link);
757 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
759 ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
760 decl->set_location(yylloc);
763 $$->declarations.push_tail(&decl->link);
765 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
767 ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
768 decl->set_location(yylloc);
771 $$->declarations.push_tail(&decl->link);
773 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
775 ast_declaration *decl = new ast_declaration($3, true, $5, $8);
776 decl->set_location(yylloc);
779 $$->declarations.push_tail(&decl->link);
781 | init_declarator_list ',' IDENTIFIER '=' initializer
783 ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
784 decl->set_location(yylloc);
787 $$->declarations.push_tail(&decl->link);
791 // Grammar Note: No 'enum', or 'typedef'.
795 if ($1->specifier->type_specifier != ast_struct) {
796 _mesa_glsl_error(& @1, state, "empty declaration list\n");
799 $$ = new ast_declarator_list($1);
800 $$->set_location(yylloc);
803 | fully_specified_type IDENTIFIER
805 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
807 $$ = new ast_declarator_list($1);
808 $$->set_location(yylloc);
809 $$->declarations.push_tail(&decl->link);
811 | fully_specified_type IDENTIFIER '[' ']'
813 ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
815 $$ = new ast_declarator_list($1);
816 $$->set_location(yylloc);
817 $$->declarations.push_tail(&decl->link);
819 | fully_specified_type IDENTIFIER '[' constant_expression ']'
821 ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
823 $$ = new ast_declarator_list($1);
824 $$->set_location(yylloc);
825 $$->declarations.push_tail(&decl->link);
827 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
829 ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
831 $$ = new ast_declarator_list($1);
832 $$->set_location(yylloc);
833 $$->declarations.push_tail(&decl->link);
835 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
837 ast_declaration *decl = new ast_declaration($2, true, $4, $7);
839 $$ = new ast_declarator_list($1);
840 $$->set_location(yylloc);
841 $$->declarations.push_tail(&decl->link);
843 | fully_specified_type IDENTIFIER '=' initializer
845 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
847 $$ = new ast_declarator_list($1);
848 $$->set_location(yylloc);
849 $$->declarations.push_tail(&decl->link);
851 | INVARIANT IDENTIFIER // Vertex only.
853 ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
855 $$ = new ast_declarator_list(NULL);
856 $$->set_location(yylloc);
857 $$->invariant = true;
859 $$->declarations.push_tail(&decl->link);
863 fully_specified_type:
866 $$ = new ast_fully_specified_type();
867 $$->set_location(yylloc);
870 | type_qualifier type_specifier
872 $$ = new ast_fully_specified_type();
873 $$->set_location(yylloc);
874 $$->qualifier = $1.q;
879 interpolation_qualifier:
880 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
881 | FLAT { $$.i = 0; $$.q.flat = 1; }
882 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
885 parameter_type_qualifier:
886 CONST { $$.i = 0; $$.q.constant = 1; }
891 | interpolation_qualifier type_qualifier
895 | INVARIANT type_qualifier
903 CONST { $$.i = 0; $$.q.constant = 1; }
904 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
905 | VARYING { $$.i = 0; $$.q.varying = 1; }
906 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
907 | IN { $$.i = 0; $$.q.in = 1; }
908 | OUT { $$.i = 0; $$.q.out = 1; }
909 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
910 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
911 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
915 type_specifier_no_prec
916 | precision_qualifier type_specifier_no_prec
923 type_specifier_no_prec:
924 type_specifier_nonarray
925 | type_specifier_nonarray '[' ']'
929 $$->array_size = NULL;
931 | type_specifier_nonarray '[' constant_expression ']'
939 type_specifier_nonarray:
940 basic_type_specifier_nonarray
942 $$ = new ast_type_specifier($1);
943 $$->set_location(yylloc);
947 $$ = new ast_type_specifier($1);
948 $$->set_location(yylloc);
952 $$ = new ast_type_specifier($1);
953 $$->set_location(yylloc);
957 basic_type_specifier_nonarray:
958 VOID { $$ = ast_void; }
959 | FLOAT { $$ = ast_float; }
960 | INT { $$ = ast_int; }
961 | UINT { $$ = ast_uint; }
962 | BOOL { $$ = ast_bool; }
963 | VEC2 { $$ = ast_vec2; }
964 | VEC3 { $$ = ast_vec3; }
965 | VEC4 { $$ = ast_vec4; }
966 | BVEC2 { $$ = ast_bvec2; }
967 | BVEC3 { $$ = ast_bvec3; }
968 | BVEC4 { $$ = ast_bvec4; }
969 | IVEC2 { $$ = ast_ivec2; }
970 | IVEC3 { $$ = ast_ivec3; }
971 | IVEC4 { $$ = ast_ivec4; }
972 | UVEC2 { $$ = ast_uvec2; }
973 | UVEC3 { $$ = ast_uvec3; }
974 | UVEC4 { $$ = ast_uvec4; }
975 | MAT2 { $$ = ast_mat2; }
976 | MAT3 { $$ = ast_mat3; }
977 | MAT4 { $$ = ast_mat4; }
978 | MAT2X2 { $$ = ast_mat2; }
979 | MAT2X3 { $$ = ast_mat2x3; }
980 | MAT2X4 { $$ = ast_mat2x4; }
981 | MAT3X2 { $$ = ast_mat3x2; }
982 | MAT3X3 { $$ = ast_mat3; }
983 | MAT3X4 { $$ = ast_mat3x4; }
984 | MAT4X2 { $$ = ast_mat4x2; }
985 | MAT4X3 { $$ = ast_mat4x3; }
986 | MAT4X4 { $$ = ast_mat4; }
987 | SAMPLER1D { $$ = ast_sampler1d; }
988 | SAMPLER2D { $$ = ast_sampler2d; }
989 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
990 | SAMPLER3D { $$ = ast_sampler3d; }
991 | SAMPLERCUBE { $$ = ast_samplercube; }
992 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
993 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
994 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
995 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
996 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
997 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
998 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
999 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1000 | ISAMPLER1D { $$ = ast_isampler1d; }
1001 | ISAMPLER2D { $$ = ast_isampler2d; }
1002 | ISAMPLER3D { $$ = ast_isampler3d; }
1003 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1004 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1005 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1006 | USAMPLER1D { $$ = ast_usampler1d; }
1007 | USAMPLER2D { $$ = ast_usampler2d; }
1008 | USAMPLER3D { $$ = ast_usampler3d; }
1009 | USAMPLERCUBE { $$ = ast_usamplercube; }
1010 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1011 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1014 precision_qualifier:
1016 if (state->language_version < 130)
1017 _mesa_glsl_error(& @1, state,
1018 "precission qualifier forbidden "
1019 "in GLSL %d.%d (1.30 or later "
1021 state->language_version / 100,
1022 state->language_version % 100);
1024 $$ = ast_precision_high;
1027 if (state->language_version < 130)
1028 _mesa_glsl_error(& @1, state,
1029 "precission qualifier forbidden "
1030 "in GLSL %d.%d (1.30 or later "
1032 state->language_version / 100,
1033 state->language_version % 100);
1035 $$ = ast_precision_medium;
1038 if (state->language_version < 130)
1039 _mesa_glsl_error(& @1, state,
1040 "precission qualifier forbidden "
1041 "in GLSL %d.%d (1.30 or later "
1043 state->language_version / 100,
1044 state->language_version % 100);
1046 $$ = ast_precision_low;
1051 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1053 $$ = new ast_struct_specifier($2, $4);
1054 $$->set_location(yylloc);
1056 | STRUCT '{' struct_declaration_list '}'
1058 $$ = new ast_struct_specifier(NULL, $3);
1059 $$->set_location(yylloc);
1063 struct_declaration_list:
1066 $$ = (struct ast_node *) $1;
1067 $1->link.self_link();
1069 | struct_declaration_list struct_declaration
1071 $$ = (struct ast_node *) $1;
1072 $$->link.insert_before(& $2->link);
1077 type_specifier struct_declarator_list ';'
1079 ast_fully_specified_type *type = new ast_fully_specified_type();
1080 type->set_location(yylloc);
1082 type->specifier = $1;
1083 $$ = new ast_declarator_list(type);
1084 $$->set_location(yylloc);
1086 $$->declarations.push_degenerate_list_at_head(& $2->link);
1090 struct_declarator_list:
1094 $1->link.self_link();
1096 | struct_declarator_list ',' struct_declarator
1099 $$->link.insert_before(& $3->link);
1106 $$ = new ast_declaration($1, false, NULL, NULL);
1107 $$->set_location(yylloc);
1109 | IDENTIFIER '[' constant_expression ']'
1111 $$ = new ast_declaration($1, true, $3, NULL);
1112 $$->set_location(yylloc);
1117 assignment_expression
1120 declaration_statement:
1124 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1128 | statement_unmatched
1132 compound_statement { $$ = (struct ast_node *) $1; }
1136 statement_unmatched:
1137 selection_statement_unmatched
1141 declaration_statement
1142 | expression_statement
1143 | selection_statement_matched
1144 | switch_statement { $$ = NULL; }
1145 | case_label { $$ = NULL; }
1146 | iteration_statement
1153 $$ = new ast_compound_statement(true, NULL);
1154 $$->set_location(yylloc);
1156 | '{' statement_list '}'
1158 $$ = new ast_compound_statement(true, $2);
1159 $$->set_location(yylloc);
1163 statement_no_new_scope:
1164 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1168 compound_statement_no_new_scope:
1171 $$ = new ast_compound_statement(false, NULL);
1172 $$->set_location(yylloc);
1174 | '{' statement_list '}'
1176 $$ = new ast_compound_statement(false, $2);
1177 $$->set_location(yylloc);
1185 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1190 $$->link.self_link();
1192 | statement_list statement
1195 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1199 $$->link.insert_before(& $2->link);
1203 expression_statement:
1206 $$ = new ast_expression_statement(NULL);
1207 $$->set_location(yylloc);
1211 $$ = new ast_expression_statement($1);
1212 $$->set_location(yylloc);
1216 selection_statement_matched:
1217 IF '(' expression ')' statement_matched ELSE statement_matched
1219 $$ = new ast_selection_statement($3, $5, $7);
1220 $$->set_location(yylloc);
1224 selection_statement_unmatched:
1225 IF '(' expression ')' statement_matched
1227 $$ = new ast_selection_statement($3, $5, NULL);
1228 $$->set_location(yylloc);
1230 | IF '(' expression ')' statement_unmatched
1232 $$ = new ast_selection_statement($3, $5, NULL);
1233 $$->set_location(yylloc);
1235 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1237 $$ = new ast_selection_statement($3, $5, $7);
1238 $$->set_location(yylloc);
1245 $$ = (struct ast_node *) $1;
1247 | fully_specified_type IDENTIFIER '=' initializer
1249 ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
1250 ast_declarator_list *declarator = new ast_declarator_list($1);
1251 decl->set_location(yylloc);
1252 declarator->set_location(yylloc);
1254 declarator->declarations.push_tail(&decl->link);
1260 SWITCH '(' expression ')' compound_statement
1268 iteration_statement:
1269 WHILE '(' condition ')' statement_no_new_scope
1271 $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
1272 NULL, $3, NULL, $5);
1273 $$->set_location(yylloc);
1275 | DO statement WHILE '(' expression ')' ';'
1277 $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
1278 NULL, $5, NULL, $2);
1279 $$->set_location(yylloc);
1281 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1283 $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
1284 $3, $4.cond, $4.rest, $6);
1285 $$->set_location(yylloc);
1290 expression_statement
1291 | declaration_statement
1308 | conditionopt ';' expression
1315 // Grammar Note: No 'goto'. Gotos are not supported.
1319 $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1320 $$->set_location(yylloc);
1324 $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
1325 $$->set_location(yylloc);
1329 $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
1330 $$->set_location(yylloc);
1332 | RETURN expression ';'
1334 $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
1335 $$->set_location(yylloc);
1337 | DISCARD ';' // Fragment shader only.
1339 $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1340 $$->set_location(yylloc);
1344 external_declaration:
1345 function_definition { $$ = $1; }
1346 | declaration { $$ = $1; }
1349 function_definition:
1350 function_prototype compound_statement_no_new_scope
1352 $$ = new ast_function_definition();
1353 $$->set_location(yylloc);