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 SUPERP PRECISION
99 %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
102 /* Reserved words that are not actually used in the grammar.
104 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
105 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
106 %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
107 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
108 %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
109 %token SIZEOF CAST NAMESPACE USING
111 %token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
112 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
113 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
114 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
115 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
118 %type <identifier> variable_identifier
119 %type <node> statement
120 %type <node> statement_list
121 %type <node> simple_statement
122 %type <node> statement_matched
123 %type <node> statement_unmatched
124 %type <n> precision_qualifier
125 %type <type_qualifier> type_qualifier
126 %type <type_qualifier> storage_qualifier
127 %type <type_qualifier> interpolation_qualifier
128 %type <type_qualifier> opt_layout_qualifier layout_qualifier
129 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
130 %type <type_specifier> type_specifier
131 %type <type_specifier> type_specifier_no_prec
132 %type <type_specifier> type_specifier_nonarray
133 %type <n> basic_type_specifier_nonarray
134 %type <fully_specified_type> fully_specified_type
135 %type <function> function_prototype
136 %type <function> function_header
137 %type <function> function_header_with_parameters
138 %type <function> function_declarator
139 %type <parameter_declarator> parameter_declarator
140 %type <parameter_declarator> parameter_declaration
141 %type <type_qualifier> parameter_qualifier
142 %type <type_qualifier> parameter_type_qualifier
143 %type <type_specifier> parameter_type_specifier
144 %type <function_definition> function_definition
145 %type <compound_statement> compound_statement_no_new_scope
146 %type <compound_statement> compound_statement
147 %type <node> statement_no_new_scope
148 %type <node> expression_statement
149 %type <expression> expression
150 %type <expression> primary_expression
151 %type <expression> assignment_expression
152 %type <expression> conditional_expression
153 %type <expression> logical_or_expression
154 %type <expression> logical_xor_expression
155 %type <expression> logical_and_expression
156 %type <expression> inclusive_or_expression
157 %type <expression> exclusive_or_expression
158 %type <expression> and_expression
159 %type <expression> equality_expression
160 %type <expression> relational_expression
161 %type <expression> shift_expression
162 %type <expression> additive_expression
163 %type <expression> multiplicative_expression
164 %type <expression> unary_expression
165 %type <expression> constant_expression
166 %type <expression> integer_expression
167 %type <expression> postfix_expression
168 %type <expression> function_call_header_with_parameters
169 %type <expression> function_call_header_no_parameters
170 %type <expression> function_call_header
171 %type <expression> function_call_generic
172 %type <expression> function_call_or_method
173 %type <expression> function_call
174 %type <n> assignment_operator
175 %type <n> unary_operator
176 %type <expression> function_identifier
177 %type <node> external_declaration
178 %type <declarator_list> init_declarator_list
179 %type <declarator_list> single_declaration
180 %type <expression> initializer
181 %type <node> declaration
182 %type <node> declaration_statement
183 %type <node> jump_statement
184 %type <struct_specifier> struct_specifier
185 %type <node> struct_declaration_list
186 %type <declarator_list> struct_declaration
187 %type <declaration> struct_declarator
188 %type <declaration> struct_declarator_list
189 %type <node> selection_statement_matched
190 %type <node> selection_statement_unmatched
191 %type <node> iteration_statement
192 %type <node> condition
193 %type <node> conditionopt
194 %type <node> for_init_statement
195 %type <for_rest_statement> for_rest_statement
199 version_statement extension_statement_list
201 _mesa_glsl_initialize_types(state);
203 external_declaration_list
207 /* blank - no #version specified */
209 state->language_version = 110;
211 | VERSION INTCONSTANT EOL
217 /* FINISHME: Check against implementation support versions. */
218 state->language_version = $2;
221 _mesa_glsl_error(& @2, state, "Shading language version"
222 "%u is not supported\n", $2);
228 extension_statement_list:
230 | extension_statement_list extension_statement
234 EXTENSION IDENTIFIER COLON IDENTIFIER EOL
236 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
242 external_declaration_list:
245 /* FINISHME: The NULL test is only required because 'precision'
246 * FINISHME: statements are not yet supported.
249 state->translation_unit.push_tail(& $1->link);
251 | external_declaration_list external_declaration
253 /* FINISHME: The NULL test is only required because 'precision'
254 * FINISHME: statements are not yet supported.
257 state->translation_unit.push_tail(& $2->link);
269 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
270 $$->set_location(yylloc);
271 $$->primary_expression.identifier = $1;
276 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
277 $$->set_location(yylloc);
278 $$->primary_expression.int_constant = $1;
283 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
284 $$->set_location(yylloc);
285 $$->primary_expression.uint_constant = $1;
290 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
291 $$->set_location(yylloc);
292 $$->primary_expression.float_constant = $1;
297 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
298 $$->set_location(yylloc);
299 $$->primary_expression.bool_constant = $1;
309 | postfix_expression '[' integer_expression ']'
312 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
313 $$->set_location(yylloc);
319 | postfix_expression '.' IDENTIFIER
322 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
323 $$->set_location(yylloc);
324 $$->primary_expression.identifier = $3;
326 | postfix_expression INC_OP
329 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
330 $$->set_location(yylloc);
332 | postfix_expression DEC_OP
335 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
336 $$->set_location(yylloc);
345 function_call_or_method
348 function_call_or_method:
349 function_call_generic
350 | postfix_expression '.' function_call_generic
353 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
354 $$->set_location(yylloc);
358 function_call_generic:
359 function_call_header_with_parameters ')'
360 | function_call_header_no_parameters ')'
363 function_call_header_no_parameters:
364 function_call_header VOID
365 | function_call_header
368 function_call_header_with_parameters:
369 function_call_header assignment_expression
372 $$->set_location(yylloc);
373 $$->expressions.push_tail(& $2->link);
375 | function_call_header_with_parameters ',' assignment_expression
378 $$->set_location(yylloc);
379 $$->expressions.push_tail(& $3->link);
383 // Grammar Note: Constructors look like functions, but lexical
384 // analysis recognized most of them as keywords. They are now
385 // recognized through "type_specifier".
386 function_call_header:
387 function_identifier '('
394 $$ = new(ctx) ast_function_expression($1);
395 $$->set_location(yylloc);
400 ast_expression *callee = new(ctx) ast_expression($1);
401 $$ = new(ctx) ast_function_expression(callee);
402 $$->set_location(yylloc);
407 ast_expression *callee = new(ctx) ast_expression($1);
408 $$ = new(ctx) ast_function_expression(callee);
409 $$->set_location(yylloc);
413 // Grammar Note: No traditional style type casts.
416 | INC_OP unary_expression
419 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
420 $$->set_location(yylloc);
422 | DEC_OP unary_expression
425 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
426 $$->set_location(yylloc);
428 | unary_operator unary_expression
431 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
432 $$->set_location(yylloc);
436 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
438 '+' { $$ = ast_plus; }
439 | '-' { $$ = ast_neg; }
440 | '!' { $$ = ast_logic_not; }
441 | '~' { $$ = ast_bit_not; }
444 multiplicative_expression:
446 | multiplicative_expression '*' unary_expression
449 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
450 $$->set_location(yylloc);
452 | multiplicative_expression '/' unary_expression
455 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
456 $$->set_location(yylloc);
458 | multiplicative_expression '%' unary_expression
461 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
462 $$->set_location(yylloc);
467 multiplicative_expression
468 | additive_expression '+' multiplicative_expression
471 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
472 $$->set_location(yylloc);
474 | additive_expression '-' multiplicative_expression
477 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
478 $$->set_location(yylloc);
484 | shift_expression LEFT_OP additive_expression
487 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
488 $$->set_location(yylloc);
490 | shift_expression RIGHT_OP additive_expression
493 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
494 $$->set_location(yylloc);
498 relational_expression:
500 | relational_expression '<' shift_expression
503 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
504 $$->set_location(yylloc);
506 | relational_expression '>' shift_expression
509 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
510 $$->set_location(yylloc);
512 | relational_expression LE_OP shift_expression
515 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
516 $$->set_location(yylloc);
518 | relational_expression GE_OP shift_expression
521 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
522 $$->set_location(yylloc);
527 relational_expression
528 | equality_expression EQ_OP relational_expression
531 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
532 $$->set_location(yylloc);
534 | equality_expression NE_OP relational_expression
537 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
538 $$->set_location(yylloc);
544 | and_expression '&' equality_expression
547 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
548 $$->set_location(yylloc);
552 exclusive_or_expression:
554 | exclusive_or_expression '^' and_expression
557 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
558 $$->set_location(yylloc);
562 inclusive_or_expression:
563 exclusive_or_expression
564 | inclusive_or_expression '|' exclusive_or_expression
567 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
568 $$->set_location(yylloc);
572 logical_and_expression:
573 inclusive_or_expression
574 | logical_and_expression AND_OP inclusive_or_expression
577 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
578 $$->set_location(yylloc);
582 logical_xor_expression:
583 logical_and_expression
584 | logical_xor_expression XOR_OP logical_and_expression
587 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
588 $$->set_location(yylloc);
592 logical_or_expression:
593 logical_xor_expression
594 | logical_or_expression OR_OP logical_xor_expression
597 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
598 $$->set_location(yylloc);
602 conditional_expression:
603 logical_or_expression
604 | logical_or_expression '?' expression ':' assignment_expression
607 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
608 $$->set_location(yylloc);
612 assignment_expression:
613 conditional_expression
614 | unary_expression assignment_operator assignment_expression
617 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
618 $$->set_location(yylloc);
623 '=' { $$ = ast_assign; }
624 | MUL_ASSIGN { $$ = ast_mul_assign; }
625 | DIV_ASSIGN { $$ = ast_div_assign; }
626 | MOD_ASSIGN { $$ = ast_mod_assign; }
627 | ADD_ASSIGN { $$ = ast_add_assign; }
628 | SUB_ASSIGN { $$ = ast_sub_assign; }
629 | LEFT_ASSIGN { $$ = ast_ls_assign; }
630 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
631 | AND_ASSIGN { $$ = ast_and_assign; }
632 | XOR_ASSIGN { $$ = ast_xor_assign; }
633 | OR_ASSIGN { $$ = ast_or_assign; }
637 assignment_expression
641 | expression ',' assignment_expression
644 if ($1->oper != ast_sequence) {
645 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
646 $$->set_location(yylloc);
647 $$->expressions.push_tail(& $1->link);
652 $$->expressions.push_tail(& $3->link);
657 conditional_expression
661 function_prototype ';'
665 | init_declarator_list ';'
669 | PRECISION precision_qualifier type_specifier_no_prec ';'
671 if (($3->type_specifier != ast_float)
672 && ($3->type_specifier != ast_int)) {
673 _mesa_glsl_error(& @3, state, "global precision qualifier can "
674 "only be applied to `int' or `float'\n");
678 $$ = NULL; /* FINISHME */
683 function_declarator ')'
688 | function_header_with_parameters
691 function_header_with_parameters:
692 function_header parameter_declaration
695 $$->parameters.push_tail(& $2->link);
697 | function_header_with_parameters ',' parameter_declaration
700 $$->parameters.push_tail(& $3->link);
705 fully_specified_type IDENTIFIER '('
708 $$ = new(ctx) ast_function();
709 $$->set_location(yylloc);
710 $$->return_type = $1;
715 parameter_declarator:
716 type_specifier IDENTIFIER
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;
726 | type_specifier IDENTIFIER '[' constant_expression ']'
729 $$ = new(ctx) ast_parameter_declarator();
730 $$->set_location(yylloc);
731 $$->type = new(ctx) ast_fully_specified_type();
732 $$->type->set_location(yylloc);
733 $$->type->specifier = $1;
740 parameter_declaration:
741 parameter_type_qualifier parameter_qualifier parameter_declarator
746 $$->type->qualifier = $1.q;
748 | parameter_qualifier parameter_declarator
751 $$->type->qualifier = $1.q;
753 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
758 $$ = new(ctx) ast_parameter_declarator();
759 $$->set_location(yylloc);
760 $$->type = new(ctx) ast_fully_specified_type();
761 $$->type->qualifier = $1.q;
762 $$->type->specifier = $3;
764 | parameter_qualifier parameter_type_specifier
767 $$ = new(ctx) ast_parameter_declarator();
768 $$->set_location(yylloc);
769 $$->type = new(ctx) ast_fully_specified_type();
770 $$->type->qualifier = $1.q;
771 $$->type->specifier = $2;
776 /* empty */ { $$.i = 0; }
777 | IN { $$.i = 0; $$.q.in = 1; }
778 | OUT { $$.i = 0; $$.q.out = 1; }
779 | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
782 parameter_type_specifier:
786 init_declarator_list:
788 | init_declarator_list ',' IDENTIFIER
791 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
792 decl->set_location(yylloc);
795 $$->declarations.push_tail(&decl->link);
797 | init_declarator_list ',' IDENTIFIER '[' ']'
800 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
801 decl->set_location(yylloc);
804 $$->declarations.push_tail(&decl->link);
806 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
809 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
810 decl->set_location(yylloc);
813 $$->declarations.push_tail(&decl->link);
815 | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
818 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
819 decl->set_location(yylloc);
822 $$->declarations.push_tail(&decl->link);
824 | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
827 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
828 decl->set_location(yylloc);
831 $$->declarations.push_tail(&decl->link);
833 | init_declarator_list ',' IDENTIFIER '=' initializer
836 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
837 decl->set_location(yylloc);
840 $$->declarations.push_tail(&decl->link);
844 // Grammar Note: No 'enum', or 'typedef'.
849 if ($1->specifier->type_specifier != ast_struct) {
850 _mesa_glsl_error(& @1, state, "empty declaration list\n");
853 $$ = new(ctx) ast_declarator_list($1);
854 $$->set_location(yylloc);
857 | fully_specified_type IDENTIFIER
860 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
862 $$ = new(ctx) ast_declarator_list($1);
863 $$->set_location(yylloc);
864 $$->declarations.push_tail(&decl->link);
866 | fully_specified_type IDENTIFIER '[' ']'
869 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
871 $$ = new(ctx) ast_declarator_list($1);
872 $$->set_location(yylloc);
873 $$->declarations.push_tail(&decl->link);
875 | fully_specified_type IDENTIFIER '[' constant_expression ']'
878 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
880 $$ = new(ctx) ast_declarator_list($1);
881 $$->set_location(yylloc);
882 $$->declarations.push_tail(&decl->link);
884 | fully_specified_type IDENTIFIER '[' ']' '=' initializer
887 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
889 $$ = new(ctx) ast_declarator_list($1);
890 $$->set_location(yylloc);
891 $$->declarations.push_tail(&decl->link);
893 | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
896 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
898 $$ = new(ctx) ast_declarator_list($1);
899 $$->set_location(yylloc);
900 $$->declarations.push_tail(&decl->link);
902 | fully_specified_type IDENTIFIER '=' initializer
905 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
907 $$ = new(ctx) ast_declarator_list($1);
908 $$->set_location(yylloc);
909 $$->declarations.push_tail(&decl->link);
911 | INVARIANT IDENTIFIER // Vertex only.
914 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
916 $$ = new(ctx) ast_declarator_list(NULL);
917 $$->set_location(yylloc);
918 $$->invariant = true;
920 $$->declarations.push_tail(&decl->link);
924 fully_specified_type:
928 $$ = new(ctx) ast_fully_specified_type();
929 $$->set_location(yylloc);
932 | type_qualifier type_specifier
935 $$ = new(ctx) ast_fully_specified_type();
936 $$->set_location(yylloc);
937 $$->qualifier = $1.q;
942 opt_layout_qualifier:
948 LAYOUT_TOK '(' layout_qualifier_id_list ')'
954 layout_qualifier_id_list:
956 | layout_qualifier_id_list ',' layout_qualifier_id
967 if (state->ARB_fragment_coord_conventions_enable) {
968 bool got_one = false;
970 if (strcmp($1, "origin_upper_left") == 0) {
972 $$.q.origin_upper_left = 1;
973 } else if (strcmp($1, "pixel_center_integer") == 0) {
975 $$.q.pixel_center_integer = 1;
978 if (state->ARB_fragment_coord_conventions_warn && got_one) {
979 _mesa_glsl_warning(& @1, state,
980 "GL_ARB_fragment_coord_conventions layout "
981 "identifier `%s' used\n", $1);
985 /* If the identifier didn't match any known layout identifiers,
989 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
996 interpolation_qualifier:
997 SMOOTH { $$.i = 0; $$.q.smooth = 1; }
998 | FLAT { $$.i = 0; $$.q.flat = 1; }
999 | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
1002 parameter_type_qualifier:
1003 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1008 | interpolation_qualifier type_qualifier
1012 | INVARIANT type_qualifier
1020 CONST_TOK { $$.i = 0; $$.q.constant = 1; }
1021 | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
1022 | opt_layout_qualifier VARYING { $$.i = $1.i; $$.q.varying = 1; }
1023 | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
1024 | opt_layout_qualifier IN { $$.i = 0; $$.q.in = 1; }
1025 | OUT { $$.i = 0; $$.q.out = 1; }
1026 | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
1027 | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
1028 | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
1032 type_specifier_no_prec
1033 | precision_qualifier type_specifier_no_prec
1040 type_specifier_no_prec:
1041 type_specifier_nonarray
1042 | type_specifier_nonarray '[' ']'
1045 $$->is_array = true;
1046 $$->array_size = NULL;
1048 | type_specifier_nonarray '[' constant_expression ']'
1051 $$->is_array = true;
1052 $$->array_size = $3;
1056 type_specifier_nonarray:
1057 basic_type_specifier_nonarray
1060 $$ = new(ctx) ast_type_specifier($1);
1061 $$->set_location(yylloc);
1066 $$ = new(ctx) ast_type_specifier($1);
1067 $$->set_location(yylloc);
1072 $$ = new(ctx) ast_type_specifier($1);
1073 $$->set_location(yylloc);
1077 basic_type_specifier_nonarray:
1078 VOID { $$ = ast_void; }
1079 | FLOAT { $$ = ast_float; }
1080 | INT { $$ = ast_int; }
1081 | UINT { $$ = ast_uint; }
1082 | BOOL { $$ = ast_bool; }
1083 | VEC2 { $$ = ast_vec2; }
1084 | VEC3 { $$ = ast_vec3; }
1085 | VEC4 { $$ = ast_vec4; }
1086 | BVEC2 { $$ = ast_bvec2; }
1087 | BVEC3 { $$ = ast_bvec3; }
1088 | BVEC4 { $$ = ast_bvec4; }
1089 | IVEC2 { $$ = ast_ivec2; }
1090 | IVEC3 { $$ = ast_ivec3; }
1091 | IVEC4 { $$ = ast_ivec4; }
1092 | UVEC2 { $$ = ast_uvec2; }
1093 | UVEC3 { $$ = ast_uvec3; }
1094 | UVEC4 { $$ = ast_uvec4; }
1095 | MAT2 { $$ = ast_mat2; }
1096 | MAT3 { $$ = ast_mat3; }
1097 | MAT4 { $$ = ast_mat4; }
1098 | MAT2X2 { $$ = ast_mat2; }
1099 | MAT2X3 { $$ = ast_mat2x3; }
1100 | MAT2X4 { $$ = ast_mat2x4; }
1101 | MAT3X2 { $$ = ast_mat3x2; }
1102 | MAT3X3 { $$ = ast_mat3; }
1103 | MAT3X4 { $$ = ast_mat3x4; }
1104 | MAT4X2 { $$ = ast_mat4x2; }
1105 | MAT4X3 { $$ = ast_mat4x3; }
1106 | MAT4X4 { $$ = ast_mat4; }
1107 | SAMPLER1D { $$ = ast_sampler1d; }
1108 | SAMPLER2D { $$ = ast_sampler2d; }
1109 | SAMPLER2DRECT { $$ = ast_sampler2drect; }
1110 | SAMPLER3D { $$ = ast_sampler3d; }
1111 | SAMPLERCUBE { $$ = ast_samplercube; }
1112 | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
1113 | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
1114 | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
1115 | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
1116 | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
1117 | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
1118 | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
1119 | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
1120 | ISAMPLER1D { $$ = ast_isampler1d; }
1121 | ISAMPLER2D { $$ = ast_isampler2d; }
1122 | ISAMPLER3D { $$ = ast_isampler3d; }
1123 | ISAMPLERCUBE { $$ = ast_isamplercube; }
1124 | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
1125 | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
1126 | USAMPLER1D { $$ = ast_usampler1d; }
1127 | USAMPLER2D { $$ = ast_usampler2d; }
1128 | USAMPLER3D { $$ = ast_usampler3d; }
1129 | USAMPLERCUBE { $$ = ast_usamplercube; }
1130 | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
1131 | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
1134 precision_qualifier:
1136 if (state->language_version < 130)
1137 _mesa_glsl_error(& @1, state,
1138 "precision qualifier forbidden "
1139 "in GLSL %d.%d (1.30 or later "
1141 state->language_version / 100,
1142 state->language_version % 100);
1144 $$ = ast_precision_high;
1147 if (state->language_version < 130)
1148 _mesa_glsl_error(& @1, state,
1149 "precision qualifier forbidden "
1150 "in GLSL %d.%d (1.30 or later "
1152 state->language_version / 100,
1153 state->language_version % 100);
1155 $$ = ast_precision_medium;
1158 if (state->language_version < 130)
1159 _mesa_glsl_error(& @1, state,
1160 "precision qualifier forbidden "
1161 "in GLSL %d.%d (1.30 or later "
1163 state->language_version / 100,
1164 state->language_version % 100);
1166 $$ = ast_precision_low;
1171 STRUCT IDENTIFIER '{' struct_declaration_list '}'
1174 $$ = new(ctx) ast_struct_specifier($2, $4);
1175 $$->set_location(yylloc);
1177 | STRUCT '{' struct_declaration_list '}'
1180 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1181 $$->set_location(yylloc);
1185 struct_declaration_list:
1188 $$ = (struct ast_node *) $1;
1189 $1->link.self_link();
1191 | struct_declaration_list struct_declaration
1193 $$ = (struct ast_node *) $1;
1194 $$->link.insert_before(& $2->link);
1199 type_specifier struct_declarator_list ';'
1202 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1203 type->set_location(yylloc);
1205 type->specifier = $1;
1206 $$ = new(ctx) ast_declarator_list(type);
1207 $$->set_location(yylloc);
1209 $$->declarations.push_degenerate_list_at_head(& $2->link);
1213 struct_declarator_list:
1217 $1->link.self_link();
1219 | struct_declarator_list ',' struct_declarator
1222 $$->link.insert_before(& $3->link);
1230 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1231 $$->set_location(yylloc);
1233 | IDENTIFIER '[' constant_expression ']'
1236 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1237 $$->set_location(yylloc);
1242 assignment_expression
1245 declaration_statement:
1249 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1253 | statement_unmatched
1257 compound_statement { $$ = (struct ast_node *) $1; }
1261 statement_unmatched:
1262 selection_statement_unmatched
1266 declaration_statement
1267 | expression_statement
1268 | selection_statement_matched
1269 | switch_statement { $$ = NULL; }
1270 | case_label { $$ = NULL; }
1271 | iteration_statement
1279 $$ = new(ctx) ast_compound_statement(true, NULL);
1280 $$->set_location(yylloc);
1282 | '{' statement_list '}'
1285 $$ = new(ctx) ast_compound_statement(true, $2);
1286 $$->set_location(yylloc);
1290 statement_no_new_scope:
1291 compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
1295 compound_statement_no_new_scope:
1299 $$ = new(ctx) ast_compound_statement(false, NULL);
1300 $$->set_location(yylloc);
1302 | '{' statement_list '}'
1305 $$ = new(ctx) ast_compound_statement(false, $2);
1306 $$->set_location(yylloc);
1314 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1319 $$->link.self_link();
1321 | statement_list statement
1324 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1328 $$->link.insert_before(& $2->link);
1332 expression_statement:
1336 $$ = new(ctx) ast_expression_statement(NULL);
1337 $$->set_location(yylloc);
1342 $$ = new(ctx) ast_expression_statement($1);
1343 $$->set_location(yylloc);
1347 selection_statement_matched:
1348 IF '(' expression ')' statement_matched ELSE statement_matched
1351 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1352 $$->set_location(yylloc);
1356 selection_statement_unmatched:
1357 IF '(' expression ')' statement_matched
1360 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1361 $$->set_location(yylloc);
1363 | IF '(' expression ')' statement_unmatched
1366 $$ = new(ctx) ast_selection_statement($3, $5, NULL);
1367 $$->set_location(yylloc);
1369 | IF '(' expression ')' statement_matched ELSE statement_unmatched
1372 $$ = new(ctx) ast_selection_statement($3, $5, $7);
1373 $$->set_location(yylloc);
1380 $$ = (struct ast_node *) $1;
1382 | fully_specified_type IDENTIFIER '=' initializer
1385 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1386 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1387 decl->set_location(yylloc);
1388 declarator->set_location(yylloc);
1390 declarator->declarations.push_tail(&decl->link);
1396 SWITCH '(' expression ')' compound_statement
1404 iteration_statement:
1405 WHILE '(' condition ')' statement_no_new_scope
1408 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1409 NULL, $3, NULL, $5);
1410 $$->set_location(yylloc);
1412 | DO statement WHILE '(' expression ')' ';'
1415 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1416 NULL, $5, NULL, $2);
1417 $$->set_location(yylloc);
1419 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1422 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1423 $3, $4.cond, $4.rest, $6);
1424 $$->set_location(yylloc);
1429 expression_statement
1430 | declaration_statement
1447 | conditionopt ';' expression
1454 // Grammar Note: No 'goto'. Gotos are not supported.
1459 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1460 $$->set_location(yylloc);
1465 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1466 $$->set_location(yylloc);
1471 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1472 $$->set_location(yylloc);
1474 | RETURN expression ';'
1477 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1478 $$->set_location(yylloc);
1480 | DISCARD ';' // Fragment shader only.
1483 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1484 $$->set_location(yylloc);
1488 external_declaration:
1489 function_definition { $$ = $1; }
1490 | declaration { $$ = $1; }
1493 function_definition:
1494 function_prototype compound_statement_no_new_scope
1497 $$ = new(ctx) ast_function_definition();
1498 $$->set_location(yylloc);