mesa: remove unused DD_LINE_SMOOTH flag
[mesa.git] / src / glsl / glsl_parser.yy
1 %{
2 /*
3 * Copyright © 2008, 2009 Intel Corporation
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <assert.h>
28
29 #include "ast.h"
30 #include "glsl_parser_extras.h"
31 #include "glsl_types.h"
32 #include "main/context.h"
33
34 #define YYLEX_PARAM state->scanner
35
36 #undef yyerror
37
38 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
39 {
40 _mesa_glsl_error(loc, st, "%s", msg);
41 }
42 %}
43
44 %pure-parser
45 %error-verbose
46
47 %locations
48 %initial-action {
49 @$.first_line = 1;
50 @$.first_column = 1;
51 @$.last_line = 1;
52 @$.last_column = 1;
53 @$.source = 0;
54 }
55
56 %lex-param {void *scanner}
57 %parse-param {struct _mesa_glsl_parse_state *state}
58
59 %union {
60 int n;
61 float real;
62 const char *identifier;
63
64 struct ast_type_qualifier type_qualifier;
65
66 ast_node *node;
67 ast_type_specifier *type_specifier;
68 ast_fully_specified_type *fully_specified_type;
69 ast_function *function;
70 ast_parameter_declarator *parameter_declarator;
71 ast_function_definition *function_definition;
72 ast_compound_statement *compound_statement;
73 ast_expression *expression;
74 ast_declarator_list *declarator_list;
75 ast_struct_specifier *struct_specifier;
76 ast_declaration *declaration;
77 ast_switch_body *switch_body;
78 ast_case_label *case_label;
79 ast_case_label_list *case_label_list;
80 ast_case_statement *case_statement;
81 ast_case_statement_list *case_statement_list;
82 ast_uniform_block *uniform_block;
83
84 struct {
85 ast_node *cond;
86 ast_expression *rest;
87 } for_rest_statement;
88
89 struct {
90 ast_node *then_statement;
91 ast_node *else_statement;
92 } selection_rest_statement;
93 }
94
95 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
96 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
97 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
98 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
99 %token NOPERSPECTIVE FLAT SMOOTH
100 %token MAT2X2 MAT2X3 MAT2X4
101 %token MAT3X2 MAT3X3 MAT3X4
102 %token MAT4X2 MAT4X3 MAT4X4
103 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
104 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
105 %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
106 %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
107 %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
108 %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
109 %token USAMPLER2DARRAY USAMPLERCUBEARRAY
110 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
111 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
112 %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
113 %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
114 %token SAMPLEREXTERNALOES
115 %token STRUCT VOID_TOK WHILE
116 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
117 %type <identifier> any_identifier
118 %type <uniform_block> instance_name_opt
119 %token <real> FLOATCONSTANT
120 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
121 %token <identifier> FIELD_SELECTION
122 %token LEFT_OP RIGHT_OP
123 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
124 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
125 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
126 %token SUB_ASSIGN
127 %token INVARIANT
128 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
129
130 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
131 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
132 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
133 %token PRAGMA_INVARIANT_ALL
134 %token LAYOUT_TOK
135
136 /* Reserved words that are not actually used in the grammar.
137 */
138 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
139 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
140 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
141 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
142 %token SAMPLER3DRECT
143 %token SIZEOF CAST NAMESPACE USING
144 %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
145 %token SUBROUTINE
146
147 %token ERROR_TOK
148
149 %token COMMON PARTITION ACTIVE FILTER
150 %token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY
151 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
152 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
153 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
154 %token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
155 %token ROW_MAJOR
156
157 %type <identifier> variable_identifier
158 %type <node> statement
159 %type <node> statement_list
160 %type <node> simple_statement
161 %type <n> precision_qualifier
162 %type <type_qualifier> type_qualifier
163 %type <type_qualifier> storage_qualifier
164 %type <type_qualifier> interpolation_qualifier
165 %type <type_qualifier> layout_qualifier
166 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
167 %type <type_qualifier> uniform_block_layout_qualifier
168 %type <type_specifier> type_specifier
169 %type <type_specifier> type_specifier_no_prec
170 %type <type_specifier> type_specifier_nonarray
171 %type <identifier> basic_type_specifier_nonarray
172 %type <fully_specified_type> fully_specified_type
173 %type <function> function_prototype
174 %type <function> function_header
175 %type <function> function_header_with_parameters
176 %type <function> function_declarator
177 %type <parameter_declarator> parameter_declarator
178 %type <parameter_declarator> parameter_declaration
179 %type <type_qualifier> parameter_qualifier
180 %type <type_qualifier> parameter_type_qualifier
181 %type <type_specifier> parameter_type_specifier
182 %type <function_definition> function_definition
183 %type <compound_statement> compound_statement_no_new_scope
184 %type <compound_statement> compound_statement
185 %type <node> statement_no_new_scope
186 %type <node> expression_statement
187 %type <expression> expression
188 %type <expression> primary_expression
189 %type <expression> assignment_expression
190 %type <expression> conditional_expression
191 %type <expression> logical_or_expression
192 %type <expression> logical_xor_expression
193 %type <expression> logical_and_expression
194 %type <expression> inclusive_or_expression
195 %type <expression> exclusive_or_expression
196 %type <expression> and_expression
197 %type <expression> equality_expression
198 %type <expression> relational_expression
199 %type <expression> shift_expression
200 %type <expression> additive_expression
201 %type <expression> multiplicative_expression
202 %type <expression> unary_expression
203 %type <expression> constant_expression
204 %type <expression> integer_expression
205 %type <expression> postfix_expression
206 %type <expression> function_call_header_with_parameters
207 %type <expression> function_call_header_no_parameters
208 %type <expression> function_call_header
209 %type <expression> function_call_generic
210 %type <expression> function_call_or_method
211 %type <expression> function_call
212 %type <expression> method_call_generic
213 %type <expression> method_call_header_with_parameters
214 %type <expression> method_call_header_no_parameters
215 %type <expression> method_call_header
216 %type <n> assignment_operator
217 %type <n> unary_operator
218 %type <expression> function_identifier
219 %type <node> external_declaration
220 %type <declarator_list> init_declarator_list
221 %type <declarator_list> single_declaration
222 %type <expression> initializer
223 %type <node> declaration
224 %type <node> declaration_statement
225 %type <node> jump_statement
226 %type <node> uniform_block
227 %type <uniform_block> basic_uniform_block
228 %type <struct_specifier> struct_specifier
229 %type <declarator_list> struct_declaration_list
230 %type <declarator_list> struct_declaration
231 %type <declaration> struct_declarator
232 %type <declaration> struct_declarator_list
233 %type <declarator_list> member_list
234 %type <declarator_list> member_declaration
235 %type <node> selection_statement
236 %type <selection_rest_statement> selection_rest_statement
237 %type <node> switch_statement
238 %type <switch_body> switch_body
239 %type <case_label_list> case_label_list
240 %type <case_label> case_label
241 %type <case_statement> case_statement
242 %type <case_statement_list> case_statement_list
243 %type <node> iteration_statement
244 %type <node> condition
245 %type <node> conditionopt
246 %type <node> for_init_statement
247 %type <for_rest_statement> for_rest_statement
248 %type <n> integer_constant
249 %%
250
251 translation_unit:
252 version_statement extension_statement_list
253 {
254 _mesa_glsl_initialize_types(state);
255 }
256 external_declaration_list
257 {
258 delete state->symbols;
259 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
260 _mesa_glsl_initialize_types(state);
261 }
262 ;
263
264 version_statement:
265 /* blank - no #version specified: defaults are already set */
266 | VERSION_TOK INTCONSTANT EOL
267 {
268 state->process_version_directive(&@2, $2, NULL);
269 }
270 | VERSION_TOK INTCONSTANT any_identifier EOL
271 {
272 state->process_version_directive(&@2, $2, $3);
273 }
274 ;
275
276 pragma_statement:
277 PRAGMA_DEBUG_ON EOL
278 | PRAGMA_DEBUG_OFF EOL
279 | PRAGMA_OPTIMIZE_ON EOL
280 | PRAGMA_OPTIMIZE_OFF EOL
281 | PRAGMA_INVARIANT_ALL EOL
282 {
283 if (!state->is_version(120, 100)) {
284 _mesa_glsl_warning(& @1, state,
285 "pragma `invariant(all)' not supported in %s "
286 "(GLSL ES 1.00 or GLSL 1.20 required).",
287 state->get_version_string());
288 } else {
289 state->all_invariant = true;
290 }
291 }
292 ;
293
294 extension_statement_list:
295
296 | extension_statement_list extension_statement
297 ;
298
299 any_identifier:
300 IDENTIFIER
301 | TYPE_IDENTIFIER
302 | NEW_IDENTIFIER
303 ;
304
305 extension_statement:
306 EXTENSION any_identifier COLON any_identifier EOL
307 {
308 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
309 YYERROR;
310 }
311 }
312 ;
313
314 external_declaration_list:
315 external_declaration
316 {
317 /* FINISHME: The NULL test is required because pragmas are set to
318 * FINISHME: NULL. (See production rule for external_declaration.)
319 */
320 if ($1 != NULL)
321 state->translation_unit.push_tail(& $1->link);
322 }
323 | external_declaration_list external_declaration
324 {
325 /* FINISHME: The NULL test is required because pragmas are set to
326 * FINISHME: NULL. (See production rule for external_declaration.)
327 */
328 if ($2 != NULL)
329 state->translation_unit.push_tail(& $2->link);
330 }
331 ;
332
333 variable_identifier:
334 IDENTIFIER
335 | NEW_IDENTIFIER
336 ;
337
338 primary_expression:
339 variable_identifier
340 {
341 void *ctx = state;
342 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
343 $$->set_location(yylloc);
344 $$->primary_expression.identifier = $1;
345 }
346 | INTCONSTANT
347 {
348 void *ctx = state;
349 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
350 $$->set_location(yylloc);
351 $$->primary_expression.int_constant = $1;
352 }
353 | UINTCONSTANT
354 {
355 void *ctx = state;
356 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
357 $$->set_location(yylloc);
358 $$->primary_expression.uint_constant = $1;
359 }
360 | FLOATCONSTANT
361 {
362 void *ctx = state;
363 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
364 $$->set_location(yylloc);
365 $$->primary_expression.float_constant = $1;
366 }
367 | BOOLCONSTANT
368 {
369 void *ctx = state;
370 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
371 $$->set_location(yylloc);
372 $$->primary_expression.bool_constant = $1;
373 }
374 | '(' expression ')'
375 {
376 $$ = $2;
377 }
378 ;
379
380 postfix_expression:
381 primary_expression
382 | postfix_expression '[' integer_expression ']'
383 {
384 void *ctx = state;
385 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
386 $$->set_location(yylloc);
387 }
388 | function_call
389 {
390 $$ = $1;
391 }
392 | postfix_expression '.' any_identifier
393 {
394 void *ctx = state;
395 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
396 $$->set_location(yylloc);
397 $$->primary_expression.identifier = $3;
398 }
399 | postfix_expression INC_OP
400 {
401 void *ctx = state;
402 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
403 $$->set_location(yylloc);
404 }
405 | postfix_expression DEC_OP
406 {
407 void *ctx = state;
408 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
409 $$->set_location(yylloc);
410 }
411 ;
412
413 integer_expression:
414 expression
415 ;
416
417 function_call:
418 function_call_or_method
419 ;
420
421 function_call_or_method:
422 function_call_generic
423 | postfix_expression '.' method_call_generic
424 {
425 void *ctx = state;
426 $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
427 $$->set_location(yylloc);
428 }
429 ;
430
431 function_call_generic:
432 function_call_header_with_parameters ')'
433 | function_call_header_no_parameters ')'
434 ;
435
436 function_call_header_no_parameters:
437 function_call_header VOID_TOK
438 | function_call_header
439 ;
440
441 function_call_header_with_parameters:
442 function_call_header assignment_expression
443 {
444 $$ = $1;
445 $$->set_location(yylloc);
446 $$->expressions.push_tail(& $2->link);
447 }
448 | function_call_header_with_parameters ',' assignment_expression
449 {
450 $$ = $1;
451 $$->set_location(yylloc);
452 $$->expressions.push_tail(& $3->link);
453 }
454 ;
455
456 // Grammar Note: Constructors look like functions, but lexical
457 // analysis recognized most of them as keywords. They are now
458 // recognized through "type_specifier".
459 function_call_header:
460 function_identifier '('
461 ;
462
463 function_identifier:
464 type_specifier
465 {
466 void *ctx = state;
467 $$ = new(ctx) ast_function_expression($1);
468 $$->set_location(yylloc);
469 }
470 | variable_identifier
471 {
472 void *ctx = state;
473 ast_expression *callee = new(ctx) ast_expression($1);
474 $$ = new(ctx) ast_function_expression(callee);
475 $$->set_location(yylloc);
476 }
477 | FIELD_SELECTION
478 {
479 void *ctx = state;
480 ast_expression *callee = new(ctx) ast_expression($1);
481 $$ = new(ctx) ast_function_expression(callee);
482 $$->set_location(yylloc);
483 }
484 ;
485
486 method_call_generic:
487 method_call_header_with_parameters ')'
488 | method_call_header_no_parameters ')'
489 ;
490
491 method_call_header_no_parameters:
492 method_call_header VOID_TOK
493 | method_call_header
494 ;
495
496 method_call_header_with_parameters:
497 method_call_header assignment_expression
498 {
499 $$ = $1;
500 $$->set_location(yylloc);
501 $$->expressions.push_tail(& $2->link);
502 }
503 | method_call_header_with_parameters ',' assignment_expression
504 {
505 $$ = $1;
506 $$->set_location(yylloc);
507 $$->expressions.push_tail(& $3->link);
508 }
509 ;
510
511 // Grammar Note: Constructors look like methods, but lexical
512 // analysis recognized most of them as keywords. They are now
513 // recognized through "type_specifier".
514 method_call_header:
515 variable_identifier '('
516 {
517 void *ctx = state;
518 ast_expression *callee = new(ctx) ast_expression($1);
519 $$ = new(ctx) ast_function_expression(callee);
520 $$->set_location(yylloc);
521 }
522 ;
523
524 // Grammar Note: No traditional style type casts.
525 unary_expression:
526 postfix_expression
527 | INC_OP unary_expression
528 {
529 void *ctx = state;
530 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
531 $$->set_location(yylloc);
532 }
533 | DEC_OP unary_expression
534 {
535 void *ctx = state;
536 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
537 $$->set_location(yylloc);
538 }
539 | unary_operator unary_expression
540 {
541 void *ctx = state;
542 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
543 $$->set_location(yylloc);
544 }
545 ;
546
547 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
548 unary_operator:
549 '+' { $$ = ast_plus; }
550 | '-' { $$ = ast_neg; }
551 | '!' { $$ = ast_logic_not; }
552 | '~' { $$ = ast_bit_not; }
553 ;
554
555 multiplicative_expression:
556 unary_expression
557 | multiplicative_expression '*' unary_expression
558 {
559 void *ctx = state;
560 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
561 $$->set_location(yylloc);
562 }
563 | multiplicative_expression '/' unary_expression
564 {
565 void *ctx = state;
566 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
567 $$->set_location(yylloc);
568 }
569 | multiplicative_expression '%' unary_expression
570 {
571 void *ctx = state;
572 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
573 $$->set_location(yylloc);
574 }
575 ;
576
577 additive_expression:
578 multiplicative_expression
579 | additive_expression '+' multiplicative_expression
580 {
581 void *ctx = state;
582 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
583 $$->set_location(yylloc);
584 }
585 | additive_expression '-' multiplicative_expression
586 {
587 void *ctx = state;
588 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
589 $$->set_location(yylloc);
590 }
591 ;
592
593 shift_expression:
594 additive_expression
595 | shift_expression LEFT_OP additive_expression
596 {
597 void *ctx = state;
598 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
599 $$->set_location(yylloc);
600 }
601 | shift_expression RIGHT_OP additive_expression
602 {
603 void *ctx = state;
604 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
605 $$->set_location(yylloc);
606 }
607 ;
608
609 relational_expression:
610 shift_expression
611 | relational_expression '<' shift_expression
612 {
613 void *ctx = state;
614 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
615 $$->set_location(yylloc);
616 }
617 | relational_expression '>' shift_expression
618 {
619 void *ctx = state;
620 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
621 $$->set_location(yylloc);
622 }
623 | relational_expression LE_OP shift_expression
624 {
625 void *ctx = state;
626 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
627 $$->set_location(yylloc);
628 }
629 | relational_expression GE_OP shift_expression
630 {
631 void *ctx = state;
632 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
633 $$->set_location(yylloc);
634 }
635 ;
636
637 equality_expression:
638 relational_expression
639 | equality_expression EQ_OP relational_expression
640 {
641 void *ctx = state;
642 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
643 $$->set_location(yylloc);
644 }
645 | equality_expression NE_OP relational_expression
646 {
647 void *ctx = state;
648 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
649 $$->set_location(yylloc);
650 }
651 ;
652
653 and_expression:
654 equality_expression
655 | and_expression '&' equality_expression
656 {
657 void *ctx = state;
658 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
659 $$->set_location(yylloc);
660 }
661 ;
662
663 exclusive_or_expression:
664 and_expression
665 | exclusive_or_expression '^' and_expression
666 {
667 void *ctx = state;
668 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
669 $$->set_location(yylloc);
670 }
671 ;
672
673 inclusive_or_expression:
674 exclusive_or_expression
675 | inclusive_or_expression '|' exclusive_or_expression
676 {
677 void *ctx = state;
678 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
679 $$->set_location(yylloc);
680 }
681 ;
682
683 logical_and_expression:
684 inclusive_or_expression
685 | logical_and_expression AND_OP inclusive_or_expression
686 {
687 void *ctx = state;
688 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
689 $$->set_location(yylloc);
690 }
691 ;
692
693 logical_xor_expression:
694 logical_and_expression
695 | logical_xor_expression XOR_OP logical_and_expression
696 {
697 void *ctx = state;
698 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
699 $$->set_location(yylloc);
700 }
701 ;
702
703 logical_or_expression:
704 logical_xor_expression
705 | logical_or_expression OR_OP logical_xor_expression
706 {
707 void *ctx = state;
708 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
709 $$->set_location(yylloc);
710 }
711 ;
712
713 conditional_expression:
714 logical_or_expression
715 | logical_or_expression '?' expression ':' assignment_expression
716 {
717 void *ctx = state;
718 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
719 $$->set_location(yylloc);
720 }
721 ;
722
723 assignment_expression:
724 conditional_expression
725 | unary_expression assignment_operator assignment_expression
726 {
727 void *ctx = state;
728 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
729 $$->set_location(yylloc);
730 }
731 ;
732
733 assignment_operator:
734 '=' { $$ = ast_assign; }
735 | MUL_ASSIGN { $$ = ast_mul_assign; }
736 | DIV_ASSIGN { $$ = ast_div_assign; }
737 | MOD_ASSIGN { $$ = ast_mod_assign; }
738 | ADD_ASSIGN { $$ = ast_add_assign; }
739 | SUB_ASSIGN { $$ = ast_sub_assign; }
740 | LEFT_ASSIGN { $$ = ast_ls_assign; }
741 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
742 | AND_ASSIGN { $$ = ast_and_assign; }
743 | XOR_ASSIGN { $$ = ast_xor_assign; }
744 | OR_ASSIGN { $$ = ast_or_assign; }
745 ;
746
747 expression:
748 assignment_expression
749 {
750 $$ = $1;
751 }
752 | expression ',' assignment_expression
753 {
754 void *ctx = state;
755 if ($1->oper != ast_sequence) {
756 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
757 $$->set_location(yylloc);
758 $$->expressions.push_tail(& $1->link);
759 } else {
760 $$ = $1;
761 }
762
763 $$->expressions.push_tail(& $3->link);
764 }
765 ;
766
767 constant_expression:
768 conditional_expression
769 ;
770
771 declaration:
772 function_prototype ';'
773 {
774 state->symbols->pop_scope();
775 $$ = $1;
776 }
777 | init_declarator_list ';'
778 {
779 $$ = $1;
780 }
781 | PRECISION precision_qualifier type_specifier_no_prec ';'
782 {
783 $3->precision = $2;
784 $3->is_precision_statement = true;
785 $$ = $3;
786 }
787 | uniform_block
788 {
789 $$ = $1;
790 }
791 ;
792
793 function_prototype:
794 function_declarator ')'
795 ;
796
797 function_declarator:
798 function_header
799 | function_header_with_parameters
800 ;
801
802 function_header_with_parameters:
803 function_header parameter_declaration
804 {
805 $$ = $1;
806 $$->parameters.push_tail(& $2->link);
807 }
808 | function_header_with_parameters ',' parameter_declaration
809 {
810 $$ = $1;
811 $$->parameters.push_tail(& $3->link);
812 }
813 ;
814
815 function_header:
816 fully_specified_type variable_identifier '('
817 {
818 void *ctx = state;
819 $$ = new(ctx) ast_function();
820 $$->set_location(yylloc);
821 $$->return_type = $1;
822 $$->identifier = $2;
823
824 state->symbols->add_function(new(state) ir_function($2));
825 state->symbols->push_scope();
826 }
827 ;
828
829 parameter_declarator:
830 type_specifier any_identifier
831 {
832 void *ctx = state;
833 $$ = new(ctx) ast_parameter_declarator();
834 $$->set_location(yylloc);
835 $$->type = new(ctx) ast_fully_specified_type();
836 $$->type->set_location(yylloc);
837 $$->type->specifier = $1;
838 $$->identifier = $2;
839 }
840 | type_specifier any_identifier '[' constant_expression ']'
841 {
842 void *ctx = state;
843 $$ = new(ctx) ast_parameter_declarator();
844 $$->set_location(yylloc);
845 $$->type = new(ctx) ast_fully_specified_type();
846 $$->type->set_location(yylloc);
847 $$->type->specifier = $1;
848 $$->identifier = $2;
849 $$->is_array = true;
850 $$->array_size = $4;
851 }
852 ;
853
854 parameter_declaration:
855 parameter_type_qualifier parameter_qualifier parameter_declarator
856 {
857 $1.flags.i |= $2.flags.i;
858
859 $$ = $3;
860 $$->type->qualifier = $1;
861 }
862 | parameter_qualifier parameter_declarator
863 {
864 $$ = $2;
865 $$->type->qualifier = $1;
866 }
867 | parameter_type_qualifier parameter_qualifier parameter_type_specifier
868 {
869 void *ctx = state;
870 $1.flags.i |= $2.flags.i;
871
872 $$ = new(ctx) ast_parameter_declarator();
873 $$->set_location(yylloc);
874 $$->type = new(ctx) ast_fully_specified_type();
875 $$->type->qualifier = $1;
876 $$->type->specifier = $3;
877 }
878 | parameter_qualifier parameter_type_specifier
879 {
880 void *ctx = state;
881 $$ = new(ctx) ast_parameter_declarator();
882 $$->set_location(yylloc);
883 $$->type = new(ctx) ast_fully_specified_type();
884 $$->type->qualifier = $1;
885 $$->type->specifier = $2;
886 }
887 ;
888
889 parameter_qualifier:
890 /* empty */
891 {
892 memset(& $$, 0, sizeof($$));
893 }
894 | IN_TOK
895 {
896 memset(& $$, 0, sizeof($$));
897 $$.flags.q.in = 1;
898 }
899 | OUT_TOK
900 {
901 memset(& $$, 0, sizeof($$));
902 $$.flags.q.out = 1;
903 }
904 | INOUT_TOK
905 {
906 memset(& $$, 0, sizeof($$));
907 $$.flags.q.in = 1;
908 $$.flags.q.out = 1;
909 }
910 ;
911
912 parameter_type_specifier:
913 type_specifier
914 ;
915
916 init_declarator_list:
917 single_declaration
918 | init_declarator_list ',' any_identifier
919 {
920 void *ctx = state;
921 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
922 decl->set_location(yylloc);
923
924 $$ = $1;
925 $$->declarations.push_tail(&decl->link);
926 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
927 }
928 | init_declarator_list ',' any_identifier '[' ']'
929 {
930 void *ctx = state;
931 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
932 decl->set_location(yylloc);
933
934 $$ = $1;
935 $$->declarations.push_tail(&decl->link);
936 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
937 }
938 | init_declarator_list ',' any_identifier '[' constant_expression ']'
939 {
940 void *ctx = state;
941 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
942 decl->set_location(yylloc);
943
944 $$ = $1;
945 $$->declarations.push_tail(&decl->link);
946 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
947 }
948 | init_declarator_list ',' any_identifier '[' ']' '=' initializer
949 {
950 void *ctx = state;
951 ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
952 decl->set_location(yylloc);
953
954 $$ = $1;
955 $$->declarations.push_tail(&decl->link);
956 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
957 }
958 | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
959 {
960 void *ctx = state;
961 ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
962 decl->set_location(yylloc);
963
964 $$ = $1;
965 $$->declarations.push_tail(&decl->link);
966 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
967 }
968 | init_declarator_list ',' any_identifier '=' initializer
969 {
970 void *ctx = state;
971 ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
972 decl->set_location(yylloc);
973
974 $$ = $1;
975 $$->declarations.push_tail(&decl->link);
976 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
977 }
978 ;
979
980 // Grammar Note: No 'enum', or 'typedef'.
981 single_declaration:
982 fully_specified_type
983 {
984 void *ctx = state;
985 /* Empty declaration list is valid. */
986 $$ = new(ctx) ast_declarator_list($1);
987 $$->set_location(yylloc);
988 }
989 | fully_specified_type any_identifier
990 {
991 void *ctx = state;
992 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
993
994 $$ = new(ctx) ast_declarator_list($1);
995 $$->set_location(yylloc);
996 $$->declarations.push_tail(&decl->link);
997 }
998 | fully_specified_type any_identifier '[' ']'
999 {
1000 void *ctx = state;
1001 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
1002
1003 $$ = new(ctx) ast_declarator_list($1);
1004 $$->set_location(yylloc);
1005 $$->declarations.push_tail(&decl->link);
1006 }
1007 | fully_specified_type any_identifier '[' constant_expression ']'
1008 {
1009 void *ctx = state;
1010 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
1011
1012 $$ = new(ctx) ast_declarator_list($1);
1013 $$->set_location(yylloc);
1014 $$->declarations.push_tail(&decl->link);
1015 }
1016 | fully_specified_type any_identifier '[' ']' '=' initializer
1017 {
1018 void *ctx = state;
1019 ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
1020
1021 $$ = new(ctx) ast_declarator_list($1);
1022 $$->set_location(yylloc);
1023 $$->declarations.push_tail(&decl->link);
1024 }
1025 | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
1026 {
1027 void *ctx = state;
1028 ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
1029
1030 $$ = new(ctx) ast_declarator_list($1);
1031 $$->set_location(yylloc);
1032 $$->declarations.push_tail(&decl->link);
1033 }
1034 | fully_specified_type any_identifier '=' initializer
1035 {
1036 void *ctx = state;
1037 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1038
1039 $$ = new(ctx) ast_declarator_list($1);
1040 $$->set_location(yylloc);
1041 $$->declarations.push_tail(&decl->link);
1042 }
1043 | INVARIANT variable_identifier // Vertex only.
1044 {
1045 void *ctx = state;
1046 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
1047
1048 $$ = new(ctx) ast_declarator_list(NULL);
1049 $$->set_location(yylloc);
1050 $$->invariant = true;
1051
1052 $$->declarations.push_tail(&decl->link);
1053 }
1054 ;
1055
1056 fully_specified_type:
1057 type_specifier
1058 {
1059 void *ctx = state;
1060 $$ = new(ctx) ast_fully_specified_type();
1061 $$->set_location(yylloc);
1062 $$->specifier = $1;
1063 }
1064 | type_qualifier type_specifier
1065 {
1066 void *ctx = state;
1067 $$ = new(ctx) ast_fully_specified_type();
1068 $$->set_location(yylloc);
1069 $$->qualifier = $1;
1070 $$->specifier = $2;
1071 }
1072 ;
1073
1074 layout_qualifier:
1075 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1076 {
1077 $$ = $3;
1078 }
1079 ;
1080
1081 layout_qualifier_id_list:
1082 layout_qualifier_id
1083 | layout_qualifier_id_list ',' layout_qualifier_id
1084 {
1085 $$ = $1;
1086 if (!$$.merge_qualifier(& @3, state, $3)) {
1087 YYERROR;
1088 }
1089 }
1090 ;
1091
1092 integer_constant:
1093 INTCONSTANT { $$ = $1; }
1094 | UINTCONSTANT { $$ = $1; }
1095 ;
1096
1097 layout_qualifier_id:
1098 any_identifier
1099 {
1100 memset(& $$, 0, sizeof($$));
1101
1102 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1103 if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
1104 if (strcmp($1, "origin_upper_left") == 0) {
1105 $$.flags.q.origin_upper_left = 1;
1106 } else if (strcmp($1, "pixel_center_integer") == 0) {
1107 $$.flags.q.pixel_center_integer = 1;
1108 }
1109
1110 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1111 _mesa_glsl_warning(& @1, state,
1112 "GL_ARB_fragment_coord_conventions layout "
1113 "identifier `%s' used\n", $1);
1114 }
1115 }
1116
1117 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1118 if (!$$.flags.i &&
1119 (state->AMD_conservative_depth_enable ||
1120 state->ARB_conservative_depth_enable)) {
1121 if (strcmp($1, "depth_any") == 0) {
1122 $$.flags.q.depth_any = 1;
1123 } else if (strcmp($1, "depth_greater") == 0) {
1124 $$.flags.q.depth_greater = 1;
1125 } else if (strcmp($1, "depth_less") == 0) {
1126 $$.flags.q.depth_less = 1;
1127 } else if (strcmp($1, "depth_unchanged") == 0) {
1128 $$.flags.q.depth_unchanged = 1;
1129 }
1130
1131 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1132 _mesa_glsl_warning(& @1, state,
1133 "GL_AMD_conservative_depth "
1134 "layout qualifier `%s' is used\n", $1);
1135 }
1136 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1137 _mesa_glsl_warning(& @1, state,
1138 "GL_ARB_conservative_depth "
1139 "layout qualifier `%s' is used\n", $1);
1140 }
1141 }
1142
1143 /* See also uniform_block_layout_qualifier. */
1144 if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
1145 if (strcmp($1, "std140") == 0) {
1146 $$.flags.q.std140 = 1;
1147 } else if (strcmp($1, "shared") == 0) {
1148 $$.flags.q.shared = 1;
1149 } else if (strcmp($1, "column_major") == 0) {
1150 $$.flags.q.column_major = 1;
1151 } else if (strcmp($1, "row_major") == 0) {
1152 $$.flags.q.row_major = 1;
1153 }
1154
1155 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1156 _mesa_glsl_warning(& @1, state,
1157 "#version 140 / GL_ARB_uniform_buffer_object "
1158 "layout qualifier `%s' is used\n", $1);
1159 }
1160 }
1161
1162 if (!$$.flags.i) {
1163 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1164 "`%s'\n", $1);
1165 YYERROR;
1166 }
1167 }
1168 | any_identifier '=' integer_constant
1169 {
1170 memset(& $$, 0, sizeof($$));
1171
1172 if (state->ARB_explicit_attrib_location_enable) {
1173 /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and
1174 * FINISHME: GLSL 1.30 (or later) are supported.
1175 */
1176 if (strcmp("location", $1) == 0) {
1177 $$.flags.q.explicit_location = 1;
1178
1179 if ($3 >= 0) {
1180 $$.location = $3;
1181 } else {
1182 _mesa_glsl_error(& @3, state,
1183 "invalid location %d specified\n", $3);
1184 YYERROR;
1185 }
1186 }
1187
1188 if (strcmp("index", $1) == 0) {
1189 $$.flags.q.explicit_index = 1;
1190
1191 if ($3 >= 0) {
1192 $$.index = $3;
1193 } else {
1194 _mesa_glsl_error(& @3, state,
1195 "invalid index %d specified\n", $3);
1196 YYERROR;
1197 }
1198 }
1199 }
1200
1201 /* If the identifier didn't match any known layout identifiers,
1202 * emit an error.
1203 */
1204 if (!$$.flags.i) {
1205 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1206 "`%s'\n", $1);
1207 YYERROR;
1208 } else if (state->ARB_explicit_attrib_location_warn) {
1209 _mesa_glsl_warning(& @1, state,
1210 "GL_ARB_explicit_attrib_location layout "
1211 "identifier `%s' used\n", $1);
1212 }
1213 }
1214 | uniform_block_layout_qualifier
1215 {
1216 $$ = $1;
1217 /* Layout qualifiers for ARB_uniform_buffer_object. */
1218 if (!state->ARB_uniform_buffer_object_enable) {
1219 _mesa_glsl_error(& @1, state,
1220 "#version 140 / GL_ARB_uniform_buffer_object "
1221 "layout qualifier `%s' is used\n", $1);
1222 } else if (state->ARB_uniform_buffer_object_warn) {
1223 _mesa_glsl_warning(& @1, state,
1224 "#version 140 / GL_ARB_uniform_buffer_object "
1225 "layout qualifier `%s' is used\n", $1);
1226 }
1227 }
1228 ;
1229
1230 /* This is a separate language rule because we parse these as tokens
1231 * (due to them being reserved keywords) instead of identifiers like
1232 * most qualifiers. See the any_identifier path of
1233 * layout_qualifier_id for the others.
1234 */
1235 uniform_block_layout_qualifier:
1236 ROW_MAJOR
1237 {
1238 memset(& $$, 0, sizeof($$));
1239 $$.flags.q.row_major = 1;
1240 }
1241 | PACKED_TOK
1242 {
1243 memset(& $$, 0, sizeof($$));
1244 $$.flags.q.packed = 1;
1245 }
1246 ;
1247
1248 interpolation_qualifier:
1249 SMOOTH
1250 {
1251 memset(& $$, 0, sizeof($$));
1252 $$.flags.q.smooth = 1;
1253 }
1254 | FLAT
1255 {
1256 memset(& $$, 0, sizeof($$));
1257 $$.flags.q.flat = 1;
1258 }
1259 | NOPERSPECTIVE
1260 {
1261 memset(& $$, 0, sizeof($$));
1262 $$.flags.q.noperspective = 1;
1263 }
1264 ;
1265
1266 parameter_type_qualifier:
1267 CONST_TOK
1268 {
1269 memset(& $$, 0, sizeof($$));
1270 $$.flags.q.constant = 1;
1271 }
1272 ;
1273
1274 type_qualifier:
1275 storage_qualifier
1276 | layout_qualifier
1277 | layout_qualifier storage_qualifier
1278 {
1279 $$ = $1;
1280 $$.flags.i |= $2.flags.i;
1281 }
1282 | interpolation_qualifier
1283 | interpolation_qualifier storage_qualifier
1284 {
1285 $$ = $1;
1286 $$.flags.i |= $2.flags.i;
1287 }
1288 | INVARIANT storage_qualifier
1289 {
1290 $$ = $2;
1291 $$.flags.q.invariant = 1;
1292 }
1293 | INVARIANT interpolation_qualifier storage_qualifier
1294 {
1295 $$ = $2;
1296 $$.flags.i |= $3.flags.i;
1297 $$.flags.q.invariant = 1;
1298 }
1299 | INVARIANT
1300 {
1301 memset(& $$, 0, sizeof($$));
1302 $$.flags.q.invariant = 1;
1303 }
1304 ;
1305
1306 storage_qualifier:
1307 CONST_TOK
1308 {
1309 memset(& $$, 0, sizeof($$));
1310 $$.flags.q.constant = 1;
1311 }
1312 | ATTRIBUTE
1313 {
1314 memset(& $$, 0, sizeof($$));
1315 $$.flags.q.attribute = 1;
1316 }
1317 | VARYING
1318 {
1319 memset(& $$, 0, sizeof($$));
1320 $$.flags.q.varying = 1;
1321 }
1322 | CENTROID VARYING
1323 {
1324 memset(& $$, 0, sizeof($$));
1325 $$.flags.q.centroid = 1;
1326 $$.flags.q.varying = 1;
1327 }
1328 | IN_TOK
1329 {
1330 memset(& $$, 0, sizeof($$));
1331 $$.flags.q.in = 1;
1332 }
1333 | OUT_TOK
1334 {
1335 memset(& $$, 0, sizeof($$));
1336 $$.flags.q.out = 1;
1337 }
1338 | CENTROID IN_TOK
1339 {
1340 memset(& $$, 0, sizeof($$));
1341 $$.flags.q.centroid = 1; $$.flags.q.in = 1;
1342 }
1343 | CENTROID OUT_TOK
1344 {
1345 memset(& $$, 0, sizeof($$));
1346 $$.flags.q.centroid = 1; $$.flags.q.out = 1;
1347 }
1348 | UNIFORM
1349 {
1350 memset(& $$, 0, sizeof($$));
1351 $$.flags.q.uniform = 1;
1352 }
1353 ;
1354
1355 type_specifier:
1356 type_specifier_no_prec
1357 {
1358 $$ = $1;
1359 }
1360 | precision_qualifier type_specifier_no_prec
1361 {
1362 $$ = $2;
1363 $$->precision = $1;
1364 }
1365 ;
1366
1367 type_specifier_no_prec:
1368 type_specifier_nonarray
1369 | type_specifier_nonarray '[' ']'
1370 {
1371 $$ = $1;
1372 $$->is_array = true;
1373 $$->array_size = NULL;
1374 }
1375 | type_specifier_nonarray '[' constant_expression ']'
1376 {
1377 $$ = $1;
1378 $$->is_array = true;
1379 $$->array_size = $3;
1380 }
1381 ;
1382
1383 type_specifier_nonarray:
1384 basic_type_specifier_nonarray
1385 {
1386 void *ctx = state;
1387 $$ = new(ctx) ast_type_specifier($1);
1388 $$->set_location(yylloc);
1389 }
1390 | struct_specifier
1391 {
1392 void *ctx = state;
1393 $$ = new(ctx) ast_type_specifier($1);
1394 $$->set_location(yylloc);
1395 }
1396 | TYPE_IDENTIFIER
1397 {
1398 void *ctx = state;
1399 $$ = new(ctx) ast_type_specifier($1);
1400 $$->set_location(yylloc);
1401 }
1402 ;
1403
1404 basic_type_specifier_nonarray:
1405 VOID_TOK { $$ = "void"; }
1406 | FLOAT_TOK { $$ = "float"; }
1407 | INT_TOK { $$ = "int"; }
1408 | UINT_TOK { $$ = "uint"; }
1409 | BOOL_TOK { $$ = "bool"; }
1410 | VEC2 { $$ = "vec2"; }
1411 | VEC3 { $$ = "vec3"; }
1412 | VEC4 { $$ = "vec4"; }
1413 | BVEC2 { $$ = "bvec2"; }
1414 | BVEC3 { $$ = "bvec3"; }
1415 | BVEC4 { $$ = "bvec4"; }
1416 | IVEC2 { $$ = "ivec2"; }
1417 | IVEC3 { $$ = "ivec3"; }
1418 | IVEC4 { $$ = "ivec4"; }
1419 | UVEC2 { $$ = "uvec2"; }
1420 | UVEC3 { $$ = "uvec3"; }
1421 | UVEC4 { $$ = "uvec4"; }
1422 | MAT2X2 { $$ = "mat2"; }
1423 | MAT2X3 { $$ = "mat2x3"; }
1424 | MAT2X4 { $$ = "mat2x4"; }
1425 | MAT3X2 { $$ = "mat3x2"; }
1426 | MAT3X3 { $$ = "mat3"; }
1427 | MAT3X4 { $$ = "mat3x4"; }
1428 | MAT4X2 { $$ = "mat4x2"; }
1429 | MAT4X3 { $$ = "mat4x3"; }
1430 | MAT4X4 { $$ = "mat4"; }
1431 | SAMPLER1D { $$ = "sampler1D"; }
1432 | SAMPLER2D { $$ = "sampler2D"; }
1433 | SAMPLER2DRECT { $$ = "sampler2DRect"; }
1434 | SAMPLER3D { $$ = "sampler3D"; }
1435 | SAMPLERCUBE { $$ = "samplerCube"; }
1436 | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
1437 | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
1438 | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
1439 | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
1440 | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
1441 | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
1442 | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
1443 | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
1444 | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
1445 | SAMPLERBUFFER { $$ = "samplerBuffer"; }
1446 | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
1447 | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
1448 | ISAMPLER1D { $$ = "isampler1D"; }
1449 | ISAMPLER2D { $$ = "isampler2D"; }
1450 | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
1451 | ISAMPLER3D { $$ = "isampler3D"; }
1452 | ISAMPLERCUBE { $$ = "isamplerCube"; }
1453 | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
1454 | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
1455 | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
1456 | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
1457 | USAMPLER1D { $$ = "usampler1D"; }
1458 | USAMPLER2D { $$ = "usampler2D"; }
1459 | USAMPLER2DRECT { $$ = "usampler2DRect"; }
1460 | USAMPLER3D { $$ = "usampler3D"; }
1461 | USAMPLERCUBE { $$ = "usamplerCube"; }
1462 | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
1463 | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
1464 | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
1465 | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
1466 | SAMPLER2DMS { $$ = "sampler2DMS"; }
1467 | ISAMPLER2DMS { $$ = "isampler2DMS"; }
1468 | USAMPLER2DMS { $$ = "usampler2DMS"; }
1469 | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
1470 | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
1471 | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
1472 ;
1473
1474 precision_qualifier:
1475 HIGHP {
1476 state->check_precision_qualifiers_allowed(&@1);
1477
1478 $$ = ast_precision_high;
1479 }
1480 | MEDIUMP {
1481 state->check_precision_qualifiers_allowed(&@1);
1482
1483 $$ = ast_precision_medium;
1484 }
1485 | LOWP {
1486 state->check_precision_qualifiers_allowed(&@1);
1487
1488 $$ = ast_precision_low;
1489 }
1490 ;
1491
1492 struct_specifier:
1493 STRUCT any_identifier '{' struct_declaration_list '}'
1494 {
1495 void *ctx = state;
1496 $$ = new(ctx) ast_struct_specifier($2, $4);
1497 $$->set_location(yylloc);
1498 state->symbols->add_type($2, glsl_type::void_type);
1499 }
1500 | STRUCT '{' struct_declaration_list '}'
1501 {
1502 void *ctx = state;
1503 $$ = new(ctx) ast_struct_specifier(NULL, $3);
1504 $$->set_location(yylloc);
1505 }
1506 ;
1507
1508 struct_declaration_list:
1509 struct_declaration
1510 {
1511 $$ = $1;
1512 $1->link.self_link();
1513 }
1514 | struct_declaration_list struct_declaration
1515 {
1516 $$ = $1;
1517 $$->link.insert_before(& $2->link);
1518 }
1519 ;
1520
1521 struct_declaration:
1522 type_specifier struct_declarator_list ';'
1523 {
1524 void *ctx = state;
1525 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1526 type->set_location(yylloc);
1527
1528 type->specifier = $1;
1529 $$ = new(ctx) ast_declarator_list(type);
1530 $$->set_location(yylloc);
1531
1532 $$->declarations.push_degenerate_list_at_head(& $2->link);
1533 }
1534 ;
1535
1536 struct_declarator_list:
1537 struct_declarator
1538 {
1539 $$ = $1;
1540 $1->link.self_link();
1541 }
1542 | struct_declarator_list ',' struct_declarator
1543 {
1544 $$ = $1;
1545 $$->link.insert_before(& $3->link);
1546 }
1547 ;
1548
1549 struct_declarator:
1550 any_identifier
1551 {
1552 void *ctx = state;
1553 $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
1554 $$->set_location(yylloc);
1555 }
1556 | any_identifier '[' constant_expression ']'
1557 {
1558 void *ctx = state;
1559 $$ = new(ctx) ast_declaration($1, true, $3, NULL);
1560 $$->set_location(yylloc);
1561 }
1562 ;
1563
1564 initializer:
1565 assignment_expression
1566 ;
1567
1568 declaration_statement:
1569 declaration
1570 ;
1571
1572 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
1573 // supported.
1574 statement:
1575 compound_statement { $$ = (ast_node *) $1; }
1576 | simple_statement
1577 ;
1578
1579 simple_statement:
1580 declaration_statement
1581 | expression_statement
1582 | selection_statement
1583 | switch_statement
1584 | iteration_statement
1585 | jump_statement
1586 ;
1587
1588 compound_statement:
1589 '{' '}'
1590 {
1591 void *ctx = state;
1592 $$ = new(ctx) ast_compound_statement(true, NULL);
1593 $$->set_location(yylloc);
1594 }
1595 | '{'
1596 {
1597 state->symbols->push_scope();
1598 }
1599 statement_list '}'
1600 {
1601 void *ctx = state;
1602 $$ = new(ctx) ast_compound_statement(true, $3);
1603 $$->set_location(yylloc);
1604 state->symbols->pop_scope();
1605 }
1606 ;
1607
1608 statement_no_new_scope:
1609 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
1610 | simple_statement
1611 ;
1612
1613 compound_statement_no_new_scope:
1614 '{' '}'
1615 {
1616 void *ctx = state;
1617 $$ = new(ctx) ast_compound_statement(false, NULL);
1618 $$->set_location(yylloc);
1619 }
1620 | '{' statement_list '}'
1621 {
1622 void *ctx = state;
1623 $$ = new(ctx) ast_compound_statement(false, $2);
1624 $$->set_location(yylloc);
1625 }
1626 ;
1627
1628 statement_list:
1629 statement
1630 {
1631 if ($1 == NULL) {
1632 _mesa_glsl_error(& @1, state, "<nil> statement\n");
1633 assert($1 != NULL);
1634 }
1635
1636 $$ = $1;
1637 $$->link.self_link();
1638 }
1639 | statement_list statement
1640 {
1641 if ($2 == NULL) {
1642 _mesa_glsl_error(& @2, state, "<nil> statement\n");
1643 assert($2 != NULL);
1644 }
1645 $$ = $1;
1646 $$->link.insert_before(& $2->link);
1647 }
1648 ;
1649
1650 expression_statement:
1651 ';'
1652 {
1653 void *ctx = state;
1654 $$ = new(ctx) ast_expression_statement(NULL);
1655 $$->set_location(yylloc);
1656 }
1657 | expression ';'
1658 {
1659 void *ctx = state;
1660 $$ = new(ctx) ast_expression_statement($1);
1661 $$->set_location(yylloc);
1662 }
1663 ;
1664
1665 selection_statement:
1666 IF '(' expression ')' selection_rest_statement
1667 {
1668 $$ = new(state) ast_selection_statement($3, $5.then_statement,
1669 $5.else_statement);
1670 $$->set_location(yylloc);
1671 }
1672 ;
1673
1674 selection_rest_statement:
1675 statement ELSE statement
1676 {
1677 $$.then_statement = $1;
1678 $$.else_statement = $3;
1679 }
1680 | statement
1681 {
1682 $$.then_statement = $1;
1683 $$.else_statement = NULL;
1684 }
1685 ;
1686
1687 condition:
1688 expression
1689 {
1690 $$ = (ast_node *) $1;
1691 }
1692 | fully_specified_type any_identifier '=' initializer
1693 {
1694 void *ctx = state;
1695 ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
1696 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
1697 decl->set_location(yylloc);
1698 declarator->set_location(yylloc);
1699
1700 declarator->declarations.push_tail(&decl->link);
1701 $$ = declarator;
1702 }
1703 ;
1704
1705 /*
1706 * siwtch_statement grammar is based on the syntax described in the body
1707 * of the GLSL spec, not in it's appendix!!!
1708 */
1709 switch_statement:
1710 SWITCH '(' expression ')' switch_body
1711 {
1712 $$ = new(state) ast_switch_statement($3, $5);
1713 $$->set_location(yylloc);
1714 }
1715 ;
1716
1717 switch_body:
1718 '{' '}'
1719 {
1720 $$ = new(state) ast_switch_body(NULL);
1721 $$->set_location(yylloc);
1722 }
1723 | '{' case_statement_list '}'
1724 {
1725 $$ = new(state) ast_switch_body($2);
1726 $$->set_location(yylloc);
1727 }
1728 ;
1729
1730 case_label:
1731 CASE expression ':'
1732 {
1733 $$ = new(state) ast_case_label($2);
1734 $$->set_location(yylloc);
1735 }
1736 | DEFAULT ':'
1737 {
1738 $$ = new(state) ast_case_label(NULL);
1739 $$->set_location(yylloc);
1740 }
1741 ;
1742
1743 case_label_list:
1744 case_label
1745 {
1746 ast_case_label_list *labels = new(state) ast_case_label_list();
1747
1748 labels->labels.push_tail(& $1->link);
1749 $$ = labels;
1750 $$->set_location(yylloc);
1751 }
1752 | case_label_list case_label
1753 {
1754 $$ = $1;
1755 $$->labels.push_tail(& $2->link);
1756 }
1757 ;
1758
1759 case_statement:
1760 case_label_list statement
1761 {
1762 ast_case_statement *stmts = new(state) ast_case_statement($1);
1763 stmts->set_location(yylloc);
1764
1765 stmts->stmts.push_tail(& $2->link);
1766 $$ = stmts;
1767 }
1768 | case_statement statement
1769 {
1770 $$ = $1;
1771 $$->stmts.push_tail(& $2->link);
1772 }
1773 ;
1774
1775 case_statement_list:
1776 case_statement
1777 {
1778 ast_case_statement_list *cases= new(state) ast_case_statement_list();
1779 cases->set_location(yylloc);
1780
1781 cases->cases.push_tail(& $1->link);
1782 $$ = cases;
1783 }
1784 | case_statement_list case_statement
1785 {
1786 $$ = $1;
1787 $$->cases.push_tail(& $2->link);
1788 }
1789 ;
1790
1791 iteration_statement:
1792 WHILE '(' condition ')' statement_no_new_scope
1793 {
1794 void *ctx = state;
1795 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
1796 NULL, $3, NULL, $5);
1797 $$->set_location(yylloc);
1798 }
1799 | DO statement WHILE '(' expression ')' ';'
1800 {
1801 void *ctx = state;
1802 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
1803 NULL, $5, NULL, $2);
1804 $$->set_location(yylloc);
1805 }
1806 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
1807 {
1808 void *ctx = state;
1809 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
1810 $3, $4.cond, $4.rest, $6);
1811 $$->set_location(yylloc);
1812 }
1813 ;
1814
1815 for_init_statement:
1816 expression_statement
1817 | declaration_statement
1818 ;
1819
1820 conditionopt:
1821 condition
1822 | /* empty */
1823 {
1824 $$ = NULL;
1825 }
1826 ;
1827
1828 for_rest_statement:
1829 conditionopt ';'
1830 {
1831 $$.cond = $1;
1832 $$.rest = NULL;
1833 }
1834 | conditionopt ';' expression
1835 {
1836 $$.cond = $1;
1837 $$.rest = $3;
1838 }
1839 ;
1840
1841 // Grammar Note: No 'goto'. Gotos are not supported.
1842 jump_statement:
1843 CONTINUE ';'
1844 {
1845 void *ctx = state;
1846 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
1847 $$->set_location(yylloc);
1848 }
1849 | BREAK ';'
1850 {
1851 void *ctx = state;
1852 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
1853 $$->set_location(yylloc);
1854 }
1855 | RETURN ';'
1856 {
1857 void *ctx = state;
1858 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
1859 $$->set_location(yylloc);
1860 }
1861 | RETURN expression ';'
1862 {
1863 void *ctx = state;
1864 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
1865 $$->set_location(yylloc);
1866 }
1867 | DISCARD ';' // Fragment shader only.
1868 {
1869 void *ctx = state;
1870 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
1871 $$->set_location(yylloc);
1872 }
1873 ;
1874
1875 external_declaration:
1876 function_definition { $$ = $1; }
1877 | declaration { $$ = $1; }
1878 | pragma_statement { $$ = NULL; }
1879 | layout_defaults { $$ = NULL; }
1880 ;
1881
1882 function_definition:
1883 function_prototype compound_statement_no_new_scope
1884 {
1885 void *ctx = state;
1886 $$ = new(ctx) ast_function_definition();
1887 $$->set_location(yylloc);
1888 $$->prototype = $1;
1889 $$->body = $2;
1890
1891 state->symbols->pop_scope();
1892 }
1893 ;
1894
1895 /* layout_qualifieropt is packed into this rule */
1896 uniform_block:
1897 basic_uniform_block
1898 {
1899 $$ = $1;
1900 }
1901 | layout_qualifier basic_uniform_block
1902 {
1903 ast_uniform_block *block = $2;
1904 if (!block->layout.merge_qualifier(& @1, state, $1)) {
1905 YYERROR;
1906 }
1907 $$ = block;
1908 }
1909 ;
1910
1911 basic_uniform_block:
1912 UNIFORM NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
1913 {
1914 ast_uniform_block *const block = $6;
1915
1916 block->block_name = $2;
1917 block->declarations.push_degenerate_list_at_head(& $4->link);
1918
1919 if (!state->ARB_uniform_buffer_object_enable) {
1920 _mesa_glsl_error(& @1, state,
1921 "#version 140 / GL_ARB_uniform_buffer_object "
1922 "required for defining uniform blocks\n");
1923 } else if (state->ARB_uniform_buffer_object_warn) {
1924 _mesa_glsl_warning(& @1, state,
1925 "#version 140 / GL_ARB_uniform_buffer_object "
1926 "required for defining uniform blocks\n");
1927 }
1928
1929 /* Since block arrays require names, and both features are added in
1930 * the same language versions, we don't have to explicitly
1931 * version-check both things.
1932 */
1933 if (block->instance_name != NULL
1934 && !(state->language_version == 300 && state->es_shader)) {
1935 _mesa_glsl_error(& @1, state,
1936 "#version 300 es required for using uniform "
1937 "blocks with an instance name\n");
1938 }
1939
1940 $$ = block;
1941 }
1942 ;
1943
1944 instance_name_opt:
1945 /* empty */
1946 {
1947 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1948 NULL,
1949 NULL);
1950 }
1951 | NEW_IDENTIFIER
1952 {
1953 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1954 $1,
1955 NULL);
1956 }
1957 | NEW_IDENTIFIER '[' constant_expression ']'
1958 {
1959 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1960 $1,
1961 $3);
1962 }
1963 | NEW_IDENTIFIER '[' ']'
1964 {
1965 _mesa_glsl_error(& @1, state,
1966 "instance block arrays must be explicitly sized\n");
1967
1968 $$ = new(state) ast_uniform_block(*state->default_uniform_qualifier,
1969 $1,
1970 NULL);
1971 }
1972 ;
1973
1974 member_list:
1975 member_declaration
1976 {
1977 $$ = $1;
1978 $1->link.self_link();
1979 }
1980 | member_declaration member_list
1981 {
1982 $$ = $1;
1983 $2->link.insert_before(& $$->link);
1984 }
1985 ;
1986
1987 /* Specifying "uniform" inside of a uniform block is redundant. */
1988 uniformopt:
1989 /* nothing */
1990 | UNIFORM
1991 ;
1992
1993 member_declaration:
1994 layout_qualifier uniformopt type_specifier struct_declarator_list ';'
1995 {
1996 void *ctx = state;
1997 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
1998 type->set_location(yylloc);
1999
2000 type->qualifier = $1;
2001 type->qualifier.flags.q.uniform = true;
2002 type->specifier = $3;
2003 $$ = new(ctx) ast_declarator_list(type);
2004 $$->set_location(yylloc);
2005 $$->ubo_qualifiers_valid = true;
2006
2007 $$->declarations.push_degenerate_list_at_head(& $4->link);
2008 }
2009 | uniformopt type_specifier struct_declarator_list ';'
2010 {
2011 void *ctx = state;
2012 ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
2013 type->set_location(yylloc);
2014
2015 type->qualifier.flags.q.uniform = true;
2016 type->specifier = $2;
2017 $$ = new(ctx) ast_declarator_list(type);
2018 $$->set_location(yylloc);
2019 $$->ubo_qualifiers_valid = true;
2020
2021 $$->declarations.push_degenerate_list_at_head(& $3->link);
2022 }
2023 ;
2024
2025 layout_defaults:
2026 layout_qualifier UNIFORM ';'
2027 {
2028 if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,
2029 $1)) {
2030 YYERROR;
2031 }
2032 }