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