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_TOK 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_TOK NOINLINE VOLATILE PUBLIC_TOK 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);
259 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
260 $$->set_location(yylloc);
261 $$->primary_expression.identifier = $1;
266 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
267 $$->set_location(yylloc);
268 $$->primary_expression.int_constant = $1;
273 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
274 $$->set_location(yylloc);
275 $$->primary_expression.uint_constant = $1;
280 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
281 $$->set_location(yylloc);
282 $$->primary_expression.float_constant = $1;
287 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
288 $$->set_location(yylloc);
289 $$->primary_expression.bool_constant = $1;
299 | postfix_expression '[' integer_expression ']'
302 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
303 $$->set_location(yylloc);
309 | postfix_expression '.' IDENTIFIER
312 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
313 $$->set_location(yylloc);
314 $$->primary_expression.identifier = $3;
316 | postfix_expression INC_OP
319 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
320 $$->set_location(yylloc);
322 | postfix_expression DEC_OP
325 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
326 $$->set_location(yylloc);
335 function_call_or_method
338 function_call_or_method:
339 function_call_generic
340 | postfix_expression '.' function_call_generic
343 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
344 $$->set_location(yylloc);
348 function_call_generic:
349 function_call_header_with_parameters ')'
350 | function_call_header_no_parameters ')'
353 function_call_header_no_parameters:
354 function_call_header VOID
355 | function_call_header
358 function_call_header_with_parameters:
359 function_call_header assignment_expression
362 $$->set_location(yylloc);
363 $$->expressions.push_tail(& $2->link);
365 | function_call_header_with_parameters ',' assignment_expression
368 $$->set_location(yylloc);
369 $$->expressions.push_tail(& $3->link);
373 // Grammar Note: Constructors look like functions, but lexical
374 // analysis recognized most of them as keywords. They are now
375 // recognized through "type_specifier".
376 function_call_header:
377 function_identifier '('
384 $$ = new(ctx) ast_function_expression($1);
385 $$->set_location(yylloc);
390 ast_expression *callee = new(ctx) ast_expression($1);
391 $$ = new(ctx) ast_function_expression(callee);
392 $$->set_location(yylloc);
397 ast_expression *callee = new(ctx) ast_expression($1);
398 $$ = new(ctx) ast_function_expression(callee);
399 $$->set_location(yylloc);
403 // Grammar Note: No traditional style type casts.
406 | INC_OP unary_expression
409 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
410 $$->set_location(yylloc);
412 | DEC_OP unary_expression
415 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
416 $$->set_location(yylloc);
418 | unary_operator unary_expression
421 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
422 $$->set_location(yylloc);
426 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
428 '+' { $$ = ast_plus; }
429 | '-' { $$ = ast_neg; }
430 | '!' { $$ = ast_logic_not; }
431 | '~' { $$ = ast_bit_not; }
434 multiplicative_expression:
436 | multiplicative_expression '*' unary_expression
439 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
440 $$->set_location(yylloc);
442 | multiplicative_expression '/' unary_expression
445 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
446 $$->set_location(yylloc);
448 | multiplicative_expression '%' unary_expression
451 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
452 $$->set_location(yylloc);
457 multiplicative_expression
458 | additive_expression '+' multiplicative_expression
461 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
462 $$->set_location(yylloc);
464 | additive_expression '-' multiplicative_expression
467 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
468 $$->set_location(yylloc);
474 | shift_expression LEFT_OP additive_expression
477 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
478 $$->set_location(yylloc);
480 | shift_expression RIGHT_OP additive_expression
483 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
484 $$->set_location(yylloc);
488 relational_expression:
490 | relational_expression '<' shift_expression
493 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
494 $$->set_location(yylloc);
496 | relational_expression '>' shift_expression
499 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
500 $$->set_location(yylloc);
502 | relational_expression LE_OP shift_expression
505 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
506 $$->set_location(yylloc);
508 | relational_expression GE_OP shift_expression
511 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
512 $$->set_location(yylloc);
517 relational_expression
518 | equality_expression EQ_OP relational_expression
521 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
522 $$->set_location(yylloc);
524 | equality_expression NE_OP relational_expression
527 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
528 $$->set_location(yylloc);
534 | and_expression '&' equality_expression
537 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
538 $$->set_location(yylloc);
542 exclusive_or_expression:
544 | exclusive_or_expression '^' and_expression
547 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
548 $$->set_location(yylloc);
552 inclusive_or_expression:
553 exclusive_or_expression
554 | inclusive_or_expression '|' exclusive_or_expression
557 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
558 $$->set_location(yylloc);
562 logical_and_expression:
563 inclusive_or_expression
564 | logical_and_expression AND_OP inclusive_or_expression
567 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
568 $$->set_location(yylloc);
572 logical_xor_expression:
573 logical_and_expression
574 | logical_xor_expression XOR_OP logical_and_expression
577 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
578 $$->set_location(yylloc);
582 logical_or_expression:
583 logical_xor_expression
584 | logical_or_expression OR_OP logical_xor_expression
587 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
588 $$->set_location(yylloc);
592 conditional_expression:
593 logical_or_expression
594 | logical_or_expression '?' expression ':' assignment_expression
597 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
598 $$->set_location(yylloc);
602 assignment_expression:
603 conditional_expression
604 | unary_expression assignment_operator assignment_expression
607 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
608 $$->set_location(yylloc);
613 '=' { $$ = ast_assign; }
614 | MUL_ASSIGN { $$ = ast_mul_assign; }
615 | DIV_ASSIGN { $$ = ast_div_assign; }
616 | MOD_ASSIGN { $$ = ast_mod_assign; }
617 | ADD_ASSIGN { $$ = ast_add_assign; }
618 | SUB_ASSIGN { $$ = ast_sub_assign; }
619 | LEFT_ASSIGN { $$ = ast_ls_assign; }
620 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
621 | AND_ASSIGN { $$ = ast_and_assign; }
622 | XOR_ASSIGN { $$ = ast_xor_assign; }
623 | OR_ASSIGN { $$ = ast_or_assign; }
627 assignment_expression
631 | expression ',' assignment_expression
634 if ($1->oper != ast_sequence) {
635 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
636 $$->set_location(yylloc);
637 $$->expressions.push_tail(& $1->link);
642 $$->expressions.push_tail(& $3->link);
647 conditional_expression
651 function_prototype ';'
655 | init_declarator_list ';'
659 | PRECISION precision_qualifier type_specifier_no_prec ';'
661 if (($3->type_specifier != ast_float)
662 && ($3->type_specifier != ast_int)) {
663 _mesa_glsl_error(& @3, state, "global precision qualifier can "
664 "only be applied to `int' or `float'\n");
668 $$ = NULL; /* FINISHME */
673 function_declarator ')'
678 | function_header_with_parameters
681 function_header_with_parameters:
682 function_header parameter_declaration
685 $$->parameters.push_tail(& $2->link);
687 | function_header_with_parameters ',' parameter_declaration
690 $$->parameters.push_tail(& $3->link);
695 fully_specified_type IDENTIFIER '('
698 $$ = new(ctx) ast_function();
699 $$->set_location(yylloc);
700 $$->return_type = $1;
705 parameter_declarator:
706 type_specifier IDENTIFIER
709 $$ = new(ctx) ast_parameter_declarator();
710 $$->set_location(yylloc);
711 $$->type = new(ctx) ast_fully_specified_type();
712 $$->type->set_location(yylloc);
713 $$->type->specifier = $1;
716 | type_specifier IDENTIFIER '[' constant_expression ']'
719 $$ = new(ctx) ast_parameter_declarator();
720 $$->set_location(yylloc);
721 $$->type = new(ctx) ast_fully_specified_type();
722 $$->type->set_location(yylloc);
723 $$->type->specifier = $1;
730 parameter_declaration:
731 parameter_type_qualifier parameter_qualifier parameter_declarator
736 $$->type->qualifier = $1.q;
738 | parameter_qualifier parameter_declarator
741 $$->type->qualifier = $1.q;
743 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
748 $$ = new(ctx) ast_parameter_declarator();
749 $$->set_location(yylloc);
750 $$->type = new(ctx) ast_fully_specified_type();
751 $$->type->qualifier = $1.q;
752 $$->type->specifier = $3;
754 | parameter_qualifier parameter_type_specifier
757 $$ = new(ctx) ast_parameter_declarator();
758 $$->set_location(yylloc);
759 $$->type = new(ctx) ast_fully_specified_type();
760 $$->type->qualifier = $1.q;
761 $$->type->specifier = $2;
766 /* empty */ { $$.i = 0; }
767 | IN { $$.i = 0; $$.q.in = 1; }
768 | OUT { $$.i = 0; $$.q.out = 1; }
769 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
772 parameter_type_specifier:
776 init_declarator_list:
778 | init_declarator_list ',' IDENTIFIER
781 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
782 decl->set_location(yylloc);
785 $$->declarations.push_tail(&decl->link);
787 | init_declarator_list ',' IDENTIFIER '[' ']'
790 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
791 decl->set_location(yylloc);
794 $$->declarations.push_tail(&decl->link);
796 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
799 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
800 decl->set_location(yylloc);
803 $$->declarations.push_tail(&decl->link);
805 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
808 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
809 decl->set_location(yylloc);
812 $$->declarations.push_tail(&decl->link);
814 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
817 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
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, false, NULL, $5);
827 decl->set_location(yylloc);
830 $$->declarations.push_tail(&decl->link);
834 // Grammar Note: No 'enum', or 'typedef'.
839 if ($1->specifier->type_specifier != ast_struct) {
840 _mesa_glsl_error(& @1, state, "empty declaration list\n");
843 $$ = new(ctx) ast_declarator_list($1);
844 $$->set_location(yylloc);
847 | fully_specified_type IDENTIFIER
850 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
852 $$ = new(ctx) ast_declarator_list($1);
853 $$->set_location(yylloc);
854 $$->declarations.push_tail(&decl->link);
856 | fully_specified_type IDENTIFIER '[' ']'
859 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
861 $$ = new(ctx) ast_declarator_list($1);
862 $$->set_location(yylloc);
863 $$->declarations.push_tail(&decl->link);
865 | fully_specified_type IDENTIFIER '[' constant_expression ']'
868 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
870 $$ = new(ctx) ast_declarator_list($1);
871 $$->set_location(yylloc);
872 $$->declarations.push_tail(&decl->link);
874 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
877 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
879 $$ = new(ctx) ast_declarator_list($1);
880 $$->set_location(yylloc);
881 $$->declarations.push_tail(&decl->link);
883 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
886 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
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, false, NULL, $4);
897 $$ = new(ctx) ast_declarator_list($1);
898 $$->set_location(yylloc);
899 $$->declarations.push_tail(&decl->link);
901 | INVARIANT IDENTIFIER // Vertex only.
904 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
906 $$ = new(ctx) ast_declarator_list(NULL);
907 $$->set_location(yylloc);
908 $$->invariant = true;
910 $$->declarations.push_tail(&decl->link);
914 fully_specified_type:
918 $$ = new(ctx) ast_fully_specified_type();
919 $$->set_location(yylloc);
922 | type_qualifier type_specifier
925 $$ = new(ctx) ast_fully_specified_type();
926 $$->set_location(yylloc);
927 $$->qualifier = $1.q;
932 interpolation_qualifier:
933 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
934 | FLAT { $$.i = 0; $$.q.flat = 1; }
935 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
938 parameter_type_qualifier:
939 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
944 | interpolation_qualifier type_qualifier
948 | INVARIANT type_qualifier
956 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
957 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
958 | VARYING { $$.i = 0; $$.q.varying = 1; }
959 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
960 | IN { $$.i = 0; $$.q.in = 1; }
961 | OUT { $$.i = 0; $$.q.out = 1; }
962 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
963 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
964 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
968 type_specifier_no_prec
969 | precision_qualifier type_specifier_no_prec
976 type_specifier_no_prec:
977 type_specifier_nonarray
978 | type_specifier_nonarray '[' ']'
982 $$->array_size = NULL;
984 | type_specifier_nonarray '[' constant_expression ']'
992 type_specifier_nonarray:
993 basic_type_specifier_nonarray
996 $$ = new(ctx) ast_type_specifier($1);
997 $$->set_location(yylloc);
1002 $$ = new(ctx) ast_type_specifier($1);
1003 $$->set_location(yylloc);
1008 $$ = new(ctx) ast_type_specifier($1);
1009 $$->set_location(yylloc);
1013 basic_type_specifier_nonarray:
1014 VOID { $$ = ast_void; }
1015 | FLOAT { $$ = ast_float; }
1016 | INT { $$ = ast_int; }
1017 | UINT { $$ = ast_uint; }
1018 | BOOL { $$ = ast_bool; }
1019 | VEC2 { $$ = ast_vec2; }
1020 | VEC3 { $$ = ast_vec3; }
1021 | VEC4 { $$ = ast_vec4; }
1022 | BVEC2 { $$ = ast_bvec2; }
1023 | BVEC3 { $$ = ast_bvec3; }
1024 | BVEC4 { $$ = ast_bvec4; }
1025 | IVEC2 { $$ = ast_ivec2; }
1026 | IVEC3 { $$ = ast_ivec3; }
1027 | IVEC4 { $$ = ast_ivec4; }
1028 | UVEC2 { $$ = ast_uvec2; }
1029 | UVEC3 { $$ = ast_uvec3; }
1030 | UVEC4 { $$ = ast_uvec4; }
1031 | MAT2 { $$ = ast_mat2; }
1032 | MAT3 { $$ = ast_mat3; }
1033 | MAT4 { $$ = ast_mat4; }
1034 | MAT2X2 { $$ = ast_mat2; }
1035 | MAT2X3 { $$ = ast_mat2x3; }
1036 | MAT2X4 { $$ = ast_mat2x4; }
1037 | MAT3X2 { $$ = ast_mat3x2; }
1038 | MAT3X3 { $$ = ast_mat3; }
1039 | MAT3X4 { $$ = ast_mat3x4; }
1040 | MAT4X2 { $$ = ast_mat4x2; }
1041 | MAT4X3 { $$ = ast_mat4x3; }
1042 | MAT4X4 { $$ = ast_mat4; }
1043 | SAMPLER1D { $$ = ast_sampler1d; }
1044 | SAMPLER2D { $$ = ast_sampler2d; }
1045 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1046 | SAMPLER3D { $$ = ast_sampler3d; }
1047 | SAMPLERCUBE { $$ = ast_samplercube; }
1048 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1049 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1050 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1051 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1052 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1053 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1054 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1055 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1056 | ISAMPLER1D { $$ = ast_isampler1d; }
1057 | ISAMPLER2D { $$ = ast_isampler2d; }
1058 | ISAMPLER3D { $$ = ast_isampler3d; }
1059 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1060 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1061 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1062 | USAMPLER1D { $$ = ast_usampler1d; }
1063 | USAMPLER2D { $$ = ast_usampler2d; }
1064 | USAMPLER3D { $$ = ast_usampler3d; }
1065 | USAMPLERCUBE { $$ = ast_usamplercube; }
1066 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1067 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1070 precision_qualifier:
1072 if (state->language_version < 130)
1073 _mesa_glsl_error(& @1, state,
1074 "precission qualifier forbidden "
1075 "in GLSL %d.%d (1.30 or later "
1077 state->language_version / 100,
1078 state->language_version % 100);
1080 $$ = ast_precision_high;
1083 if (state->language_version < 130)
1084 _mesa_glsl_error(& @1, state,
1085 "precission qualifier forbidden "
1086 "in GLSL %d.%d (1.30 or later "
1088 state->language_version / 100,
1089 state->language_version % 100);
1091 $$ = ast_precision_medium;
1094 if (state->language_version < 130)
1095 _mesa_glsl_error(& @1, state,
1096 "precission qualifier forbidden "
1097 "in GLSL %d.%d (1.30 or later "
1099 state->language_version / 100,
1100 state->language_version % 100);
1102 $$ = ast_precision_low;
1107 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1110 $$ = new(ctx) ast_struct_specifier($2, $4);
1111 $$->set_location(yylloc);
1113 | STRUCT '{' struct_declaration_list '}'
1116 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1117 $$->set_location(yylloc);
1121 struct_declaration_list:
1124 $$ = (struct ast_node *) $1;
1125 $1->link.self_link();
1127 | struct_declaration_list struct_declaration
1129 $$ = (struct ast_node *) $1;
1130 $$->link.insert_before(& $2->link);
1135 type_specifier struct_declarator_list ';'
1138 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1139 type->set_location(yylloc);
1141 type->specifier = $1;
1142 $$ = new(ctx) ast_declarator_list(type);
1143 $$->set_location(yylloc);
1145 $$->declarations.push_degenerate_list_at_head(& $2->link);
1149 struct_declarator_list:
1153 $1->link.self_link();
1155 | struct_declarator_list ',' struct_declarator
1158 $$->link.insert_before(& $3->link);
1166 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1167 $$->set_location(yylloc);
1169 | IDENTIFIER '[' constant_expression ']'
1172 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1173 $$->set_location(yylloc);
1178 assignment_expression
1181 declaration_statement:
1185 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1189 | statement_unmatched
1193 compound_statement { $$ = (struct ast_node *) $1; }
1197 statement_unmatched:
1198 selection_statement_unmatched
1202 declaration_statement
1203 | expression_statement
1204 | selection_statement_matched
1205 | switch_statement { $$ = NULL; }
1206 | case_label { $$ = NULL; }
1207 | iteration_statement
1215 $$ = new(ctx) ast_compound_statement(true, NULL);
1216 $$->set_location(yylloc);
1218 | '{' statement_list '}'
1221 $$ = new(ctx) ast_compound_statement(true, $2);
1222 $$->set_location(yylloc);
1226 statement_no_new_scope:
1227 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1231 compound_statement_no_new_scope:
1235 $$ = new(ctx) ast_compound_statement(false, NULL);
1236 $$->set_location(yylloc);
1238 | '{' statement_list '}'
1241 $$ = new(ctx) ast_compound_statement(false, $2);
1242 $$->set_location(yylloc);
1250 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1255 $$->link.self_link();
1257 | statement_list statement
1260 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1264 $$->link.insert_before(& $2->link);
1268 expression_statement:
1272 $$ = new(ctx) ast_expression_statement(NULL);
1273 $$->set_location(yylloc);
1278 $$ = new(ctx) ast_expression_statement($1);
1279 $$->set_location(yylloc);
1283 selection_statement_matched:
1284 IF '(' expression ')' statement_matched ELSE statement_matched
1287 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1288 $$->set_location(yylloc);
1292 selection_statement_unmatched:
1293 IF '(' expression ')' statement_matched
1296 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1297 $$->set_location(yylloc);
1299 | IF '(' expression ')' statement_unmatched
1302 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1303 $$->set_location(yylloc);
1305 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1308 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1309 $$->set_location(yylloc);
1316 $$ = (struct ast_node *) $1;
1318 | fully_specified_type IDENTIFIER '=' initializer
1321 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1322 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1323 decl->set_location(yylloc);
1324 declarator->set_location(yylloc);
1326 declarator->declarations.push_tail(&decl->link);
1332 SWITCH '(' expression ')' compound_statement
1340 iteration_statement:
1341 WHILE '(' condition ')' statement_no_new_scope
1344 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1345 NULL, $3, NULL, $5);
1346 $$->set_location(yylloc);
1348 | DO statement WHILE '(' expression ')' ';'
1351 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1352 NULL, $5, NULL, $2);
1353 $$->set_location(yylloc);
1355 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1358 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1359 $3, $4.cond, $4.rest, $6);
1360 $$->set_location(yylloc);
1365 expression_statement
1366 | declaration_statement
1383 | conditionopt ';' expression
1390 // Grammar Note: No 'goto'. Gotos are not supported.
1395 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1396 $$->set_location(yylloc);
1401 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1402 $$->set_location(yylloc);
1407 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1408 $$->set_location(yylloc);
1410 | RETURN expression ';'
1413 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1414 $$->set_location(yylloc);
1416 | DISCARD ';' // Fragment shader only.
1419 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1420 $$->set_location(yylloc);
1424 external_declaration:
1425 function_definition { $$ = $1; }
1426 | declaration { $$ = $1; }
1429 function_definition:
1430 function_prototype compound_statement_no_new_scope
1433 $$ = new(ctx) ast_function_definition();
1434 $$->set_location(yylloc);