glsl: Fix handling of function calls inside nested loops.
[mesa.git] / src / glsl / ast.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 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
25 #pragma once
26 #ifndef AST_H
27 #define AST_H
28
29 #include "list.h"
30 #include "glsl_parser_extras.h"
31
32 struct _mesa_glsl_parse_state;
33
34 struct YYLTYPE;
35
36 /**
37 * \defgroup AST Abstract syntax tree node definitions
38 *
39 * An abstract syntax tree is generated by the parser. This is a fairly
40 * direct representation of the gramma derivation for the source program.
41 * No symantic checking is done during the generation of the AST. Only
42 * syntactic checking is done. Symantic checking is performed by a later
43 * stage that converts the AST to a more generic intermediate representation.
44 *
45 *@{
46 */
47 /**
48 * Base class of all abstract syntax tree nodes
49 */
50 class ast_node {
51 public:
52 DECLARE_RALLOC_CXX_OPERATORS(ast_node);
53
54 /**
55 * Print an AST node in something approximating the original GLSL code
56 */
57 virtual void print(void) const;
58
59 /**
60 * Convert the AST node to the high-level intermediate representation
61 */
62 virtual ir_rvalue *hir(exec_list *instructions,
63 struct _mesa_glsl_parse_state *state);
64
65 /**
66 * Retrieve the source location of an AST node
67 *
68 * This function is primarily used to get the source position of an AST node
69 * into a form that can be passed to \c _mesa_glsl_error.
70 *
71 * \sa _mesa_glsl_error, ast_node::set_location
72 */
73 struct YYLTYPE get_location(void) const
74 {
75 struct YYLTYPE locp;
76
77 locp.source = this->location.source;
78 locp.first_line = this->location.line;
79 locp.first_column = this->location.column;
80 locp.last_line = locp.first_line;
81 locp.last_column = locp.first_column;
82
83 return locp;
84 }
85
86 /**
87 * Set the source location of an AST node from a parser location
88 *
89 * \sa ast_node::get_location
90 */
91 void set_location(const struct YYLTYPE &locp)
92 {
93 this->location.source = locp.source;
94 this->location.line = locp.first_line;
95 this->location.column = locp.first_column;
96 }
97
98 /**
99 * Source location of the AST node.
100 */
101 struct {
102 unsigned source; /**< GLSL source number. */
103 unsigned line; /**< Line number within the source string. */
104 unsigned column; /**< Column in the line. */
105 } location;
106
107 exec_node link;
108
109 protected:
110 /**
111 * The only constructor is protected so that only derived class objects can
112 * be created.
113 */
114 ast_node(void);
115 };
116
117
118 /**
119 * Operators for AST expression nodes.
120 */
121 enum ast_operators {
122 ast_assign,
123 ast_plus, /**< Unary + operator. */
124 ast_neg,
125 ast_add,
126 ast_sub,
127 ast_mul,
128 ast_div,
129 ast_mod,
130 ast_lshift,
131 ast_rshift,
132 ast_less,
133 ast_greater,
134 ast_lequal,
135 ast_gequal,
136 ast_equal,
137 ast_nequal,
138 ast_bit_and,
139 ast_bit_xor,
140 ast_bit_or,
141 ast_bit_not,
142 ast_logic_and,
143 ast_logic_xor,
144 ast_logic_or,
145 ast_logic_not,
146
147 ast_mul_assign,
148 ast_div_assign,
149 ast_mod_assign,
150 ast_add_assign,
151 ast_sub_assign,
152 ast_ls_assign,
153 ast_rs_assign,
154 ast_and_assign,
155 ast_xor_assign,
156 ast_or_assign,
157
158 ast_conditional,
159
160 ast_pre_inc,
161 ast_pre_dec,
162 ast_post_inc,
163 ast_post_dec,
164 ast_field_selection,
165 ast_array_index,
166
167 ast_function_call,
168
169 ast_identifier,
170 ast_int_constant,
171 ast_uint_constant,
172 ast_float_constant,
173 ast_bool_constant,
174
175 ast_sequence,
176 ast_aggregate
177 };
178
179 /**
180 * Representation of any sort of expression.
181 */
182 class ast_expression : public ast_node {
183 public:
184 ast_expression(int oper, ast_expression *,
185 ast_expression *, ast_expression *);
186
187 ast_expression(const char *identifier) :
188 oper(ast_identifier)
189 {
190 subexpressions[0] = NULL;
191 subexpressions[1] = NULL;
192 subexpressions[2] = NULL;
193 primary_expression.identifier = identifier;
194 this->non_lvalue_description = NULL;
195 }
196
197 static const char *operator_string(enum ast_operators op);
198
199 virtual ir_rvalue *hir(exec_list *instructions,
200 struct _mesa_glsl_parse_state *state);
201
202 virtual void print(void) const;
203
204 enum ast_operators oper;
205
206 ast_expression *subexpressions[3];
207
208 union {
209 const char *identifier;
210 int int_constant;
211 float float_constant;
212 unsigned uint_constant;
213 int bool_constant;
214 } primary_expression;
215
216
217 /**
218 * List of expressions for an \c ast_sequence or parameters for an
219 * \c ast_function_call
220 */
221 exec_list expressions;
222
223 /**
224 * For things that can't be l-values, this describes what it is.
225 *
226 * This text is used by the code that generates IR for assignments to
227 * detect and emit useful messages for assignments to some things that
228 * can't be l-values. For example, pre- or post-incerement expressions.
229 *
230 * \note
231 * This pointer may be \c NULL.
232 */
233 const char *non_lvalue_description;
234 };
235
236 class ast_expression_bin : public ast_expression {
237 public:
238 ast_expression_bin(int oper, ast_expression *, ast_expression *);
239
240 virtual void print(void) const;
241 };
242
243 /**
244 * Subclass of expressions for function calls
245 */
246 class ast_function_expression : public ast_expression {
247 public:
248 ast_function_expression(ast_expression *callee)
249 : ast_expression(ast_function_call, callee,
250 NULL, NULL),
251 cons(false)
252 {
253 /* empty */
254 }
255
256 ast_function_expression(class ast_type_specifier *type)
257 : ast_expression(ast_function_call, (ast_expression *) type,
258 NULL, NULL),
259 cons(true)
260 {
261 /* empty */
262 }
263
264 bool is_constructor() const
265 {
266 return cons;
267 }
268
269 virtual ir_rvalue *hir(exec_list *instructions,
270 struct _mesa_glsl_parse_state *state);
271
272 private:
273 /**
274 * Is this function call actually a constructor?
275 */
276 bool cons;
277 };
278
279 /**
280 * C-style aggregate initialization class
281 *
282 * Represents C-style initializers of vectors, matrices, arrays, and
283 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
284 * vec3 pos = vec3(1.0, 0.0, -1.0).
285 *
286 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
287 *
288 * \sa _mesa_ast_set_aggregate_type
289 */
290 class ast_aggregate_initializer : public ast_expression {
291 public:
292 ast_aggregate_initializer()
293 : ast_expression(ast_aggregate, NULL, NULL, NULL),
294 constructor_type(NULL)
295 {
296 /* empty */
297 }
298
299 ast_type_specifier *constructor_type;
300 virtual ir_rvalue *hir(exec_list *instructions,
301 struct _mesa_glsl_parse_state *state);
302 };
303
304 /**
305 * Number of possible operators for an ast_expression
306 *
307 * This is done as a define instead of as an additional value in the enum so
308 * that the compiler won't generate spurious messages like "warning:
309 * enumeration value ‘ast_num_operators’ not handled in switch"
310 */
311 #define AST_NUM_OPERATORS (ast_sequence + 1)
312
313
314 class ast_compound_statement : public ast_node {
315 public:
316 ast_compound_statement(int new_scope, ast_node *statements);
317 virtual void print(void) const;
318
319 virtual ir_rvalue *hir(exec_list *instructions,
320 struct _mesa_glsl_parse_state *state);
321
322 int new_scope;
323 exec_list statements;
324 };
325
326 class ast_declaration : public ast_node {
327 public:
328 ast_declaration(const char *identifier, bool is_array, ast_expression *array_size,
329 ast_expression *initializer);
330 virtual void print(void) const;
331
332 const char *identifier;
333
334 bool is_array;
335 ast_expression *array_size;
336
337 ast_expression *initializer;
338 };
339
340
341 enum {
342 ast_precision_none = 0, /**< Absence of precision qualifier. */
343 ast_precision_high,
344 ast_precision_medium,
345 ast_precision_low
346 };
347
348 struct ast_type_qualifier {
349 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier);
350
351 union {
352 struct {
353 unsigned invariant:1;
354 unsigned constant:1;
355 unsigned attribute:1;
356 unsigned varying:1;
357 unsigned in:1;
358 unsigned out:1;
359 unsigned centroid:1;
360 unsigned sample:1;
361 unsigned uniform:1;
362 unsigned smooth:1;
363 unsigned flat:1;
364 unsigned noperspective:1;
365
366 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
367 /*@{*/
368 unsigned origin_upper_left:1;
369 unsigned pixel_center_integer:1;
370 /*@}*/
371
372 /**
373 * Flag set if GL_ARB_explicit_attrib_location "location" layout
374 * qualifier is used.
375 */
376 unsigned explicit_location:1;
377 /**
378 * Flag set if GL_ARB_explicit_attrib_location "index" layout
379 * qualifier is used.
380 */
381 unsigned explicit_index:1;
382
383 /**
384 * Flag set if GL_ARB_shading_language_420pack "binding" layout
385 * qualifier is used.
386 */
387 unsigned explicit_binding:1;
388
389 /**
390 * Flag set if GL_ARB_shader_atomic counter "offset" layout
391 * qualifier is used.
392 */
393 unsigned explicit_offset:1;
394
395 /** \name Layout qualifiers for GL_AMD_conservative_depth */
396 /** \{ */
397 unsigned depth_any:1;
398 unsigned depth_greater:1;
399 unsigned depth_less:1;
400 unsigned depth_unchanged:1;
401 /** \} */
402
403 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
404 /** \{ */
405 unsigned std140:1;
406 unsigned shared:1;
407 unsigned packed:1;
408 unsigned column_major:1;
409 unsigned row_major:1;
410 /** \} */
411
412 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
413 /** \{ */
414 unsigned prim_type:1;
415 unsigned max_vertices:1;
416 /** \} */
417 }
418 /** \brief Set of flags, accessed by name. */
419 q;
420
421 /** \brief Set of flags, accessed as a bitmask. */
422 unsigned i;
423 } flags;
424
425 /** Precision of the type (highp/medium/lowp). */
426 unsigned precision:2;
427
428 /**
429 * Location specified via GL_ARB_explicit_attrib_location layout
430 *
431 * \note
432 * This field is only valid if \c explicit_location is set.
433 */
434 int location;
435 /**
436 * Index specified via GL_ARB_explicit_attrib_location layout
437 *
438 * \note
439 * This field is only valid if \c explicit_index is set.
440 */
441 int index;
442
443 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
444 int max_vertices;
445
446 /** Input or output primitive type in GLSL 1.50 geometry shaders */
447 GLenum prim_type;
448
449 /**
450 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
451 *
452 * \note
453 * This field is only valid if \c explicit_binding is set.
454 */
455 int binding;
456
457 /**
458 * Offset specified via GL_ARB_shader_atomic_counter's "offset"
459 * keyword.
460 *
461 * \note
462 * This field is only valid if \c explicit_offset is set.
463 */
464 int offset;
465
466 /**
467 * Return true if and only if an interpolation qualifier is present.
468 */
469 bool has_interpolation() const;
470
471 /**
472 * Return whether a layout qualifier is present.
473 */
474 bool has_layout() const;
475
476 /**
477 * Return whether a storage qualifier is present.
478 */
479 bool has_storage() const;
480
481 /**
482 * Return whether an auxiliary storage qualifier is present.
483 */
484 bool has_auxiliary_storage() const;
485
486 /**
487 * \brief Return string representation of interpolation qualifier.
488 *
489 * If an interpolation qualifier is present, then return that qualifier's
490 * string representation. Otherwise, return null. For example, if the
491 * noperspective bit is set, then this returns "noperspective".
492 *
493 * If multiple interpolation qualifiers are somehow present, then the
494 * returned string is undefined but not null.
495 */
496 const char *interpolation_string() const;
497
498 bool merge_qualifier(YYLTYPE *loc,
499 _mesa_glsl_parse_state *state,
500 ast_type_qualifier q);
501 };
502
503 class ast_declarator_list;
504
505 class ast_struct_specifier : public ast_node {
506 public:
507 /**
508 * \brief Make a shallow copy of an ast_struct_specifier.
509 *
510 * Use only if the objects are allocated from the same context and will not
511 * be modified. Zeros the inherited ast_node's fields.
512 */
513 ast_struct_specifier(const ast_struct_specifier& that):
514 ast_node(), name(that.name), declarations(that.declarations),
515 is_declaration(that.is_declaration)
516 {
517 /* empty */
518 }
519
520 ast_struct_specifier(const char *identifier,
521 ast_declarator_list *declarator_list);
522 virtual void print(void) const;
523
524 virtual ir_rvalue *hir(exec_list *instructions,
525 struct _mesa_glsl_parse_state *state);
526
527 const char *name;
528 /* List of ast_declarator_list * */
529 exec_list declarations;
530 bool is_declaration;
531 };
532
533
534
535 class ast_type_specifier : public ast_node {
536 public:
537 /**
538 * \brief Make a shallow copy of an ast_type_specifier, specifying array
539 * fields.
540 *
541 * Use only if the objects are allocated from the same context and will not
542 * be modified. Zeros the inherited ast_node's fields.
543 */
544 ast_type_specifier(const ast_type_specifier *that, bool is_array,
545 ast_expression *array_size)
546 : ast_node(), type_name(that->type_name), structure(that->structure),
547 is_array(is_array), array_size(array_size),
548 default_precision(that->default_precision)
549 {
550 /* empty */
551 }
552
553 /** Construct a type specifier from a type name */
554 ast_type_specifier(const char *name)
555 : type_name(name), structure(NULL),
556 is_array(false), array_size(NULL),
557 default_precision(ast_precision_none)
558 {
559 /* empty */
560 }
561
562 /** Construct a type specifier from a structure definition */
563 ast_type_specifier(ast_struct_specifier *s)
564 : type_name(s->name), structure(s),
565 is_array(false), array_size(NULL),
566 default_precision(ast_precision_none)
567 {
568 /* empty */
569 }
570
571 const struct glsl_type *glsl_type(const char **name,
572 struct _mesa_glsl_parse_state *state)
573 const;
574
575 virtual void print(void) const;
576
577 ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
578
579 const char *type_name;
580 ast_struct_specifier *structure;
581
582 bool is_array;
583 ast_expression *array_size;
584
585 /** For precision statements, this is the given precision; otherwise none. */
586 unsigned default_precision:2;
587 };
588
589
590 class ast_fully_specified_type : public ast_node {
591 public:
592 virtual void print(void) const;
593 bool has_qualifiers() const;
594
595 ast_fully_specified_type() : qualifier(), specifier(NULL)
596 {
597 }
598
599 const struct glsl_type *glsl_type(const char **name,
600 struct _mesa_glsl_parse_state *state)
601 const;
602
603 ast_type_qualifier qualifier;
604 ast_type_specifier *specifier;
605 };
606
607
608 class ast_declarator_list : public ast_node {
609 public:
610 ast_declarator_list(ast_fully_specified_type *);
611 virtual void print(void) const;
612
613 virtual ir_rvalue *hir(exec_list *instructions,
614 struct _mesa_glsl_parse_state *state);
615
616 ast_fully_specified_type *type;
617 /** List of 'ast_declaration *' */
618 exec_list declarations;
619
620 /**
621 * Special flag for vertex shader "invariant" declarations.
622 *
623 * Vertex shaders can contain "invariant" variable redeclarations that do
624 * not include a type. For example, "invariant gl_Position;". This flag
625 * is used to note these cases when no type is specified.
626 */
627 int invariant;
628 };
629
630
631 class ast_parameter_declarator : public ast_node {
632 public:
633 ast_parameter_declarator() :
634 type(NULL),
635 identifier(NULL),
636 is_array(false),
637 array_size(NULL),
638 formal_parameter(false),
639 is_void(false)
640 {
641 /* empty */
642 }
643
644 virtual void print(void) const;
645
646 virtual ir_rvalue *hir(exec_list *instructions,
647 struct _mesa_glsl_parse_state *state);
648
649 ast_fully_specified_type *type;
650 const char *identifier;
651 bool is_array;
652 ast_expression *array_size;
653
654 static void parameters_to_hir(exec_list *ast_parameters,
655 bool formal, exec_list *ir_parameters,
656 struct _mesa_glsl_parse_state *state);
657
658 private:
659 /** Is this parameter declaration part of a formal parameter list? */
660 bool formal_parameter;
661
662 /**
663 * Is this parameter 'void' type?
664 *
665 * This field is set by \c ::hir.
666 */
667 bool is_void;
668 };
669
670
671 class ast_function : public ast_node {
672 public:
673 ast_function(void);
674
675 virtual void print(void) const;
676
677 virtual ir_rvalue *hir(exec_list *instructions,
678 struct _mesa_glsl_parse_state *state);
679
680 ast_fully_specified_type *return_type;
681 const char *identifier;
682
683 exec_list parameters;
684
685 private:
686 /**
687 * Is this prototype part of the function definition?
688 *
689 * Used by ast_function_definition::hir to process the parameters, etc.
690 * of the function.
691 *
692 * \sa ::hir
693 */
694 bool is_definition;
695
696 /**
697 * Function signature corresponding to this function prototype instance
698 *
699 * Used by ast_function_definition::hir to process the parameters, etc.
700 * of the function.
701 *
702 * \sa ::hir
703 */
704 class ir_function_signature *signature;
705
706 friend class ast_function_definition;
707 };
708
709
710 class ast_expression_statement : public ast_node {
711 public:
712 ast_expression_statement(ast_expression *);
713 virtual void print(void) const;
714
715 virtual ir_rvalue *hir(exec_list *instructions,
716 struct _mesa_glsl_parse_state *state);
717
718 ast_expression *expression;
719 };
720
721
722 class ast_case_label : public ast_node {
723 public:
724 ast_case_label(ast_expression *test_value);
725 virtual void print(void) const;
726
727 virtual ir_rvalue *hir(exec_list *instructions,
728 struct _mesa_glsl_parse_state *state);
729
730 /**
731 * An test value of NULL means 'default'.
732 */
733 ast_expression *test_value;
734 };
735
736
737 class ast_case_label_list : public ast_node {
738 public:
739 ast_case_label_list(void);
740 virtual void print(void) const;
741
742 virtual ir_rvalue *hir(exec_list *instructions,
743 struct _mesa_glsl_parse_state *state);
744
745 /**
746 * A list of case labels.
747 */
748 exec_list labels;
749 };
750
751
752 class ast_case_statement : public ast_node {
753 public:
754 ast_case_statement(ast_case_label_list *labels);
755 virtual void print(void) const;
756
757 virtual ir_rvalue *hir(exec_list *instructions,
758 struct _mesa_glsl_parse_state *state);
759
760 ast_case_label_list *labels;
761
762 /**
763 * A list of statements.
764 */
765 exec_list stmts;
766 };
767
768
769 class ast_case_statement_list : public ast_node {
770 public:
771 ast_case_statement_list(void);
772 virtual void print(void) const;
773
774 virtual ir_rvalue *hir(exec_list *instructions,
775 struct _mesa_glsl_parse_state *state);
776
777 /**
778 * A list of cases.
779 */
780 exec_list cases;
781 };
782
783
784 class ast_switch_body : public ast_node {
785 public:
786 ast_switch_body(ast_case_statement_list *stmts);
787 virtual void print(void) const;
788
789 virtual ir_rvalue *hir(exec_list *instructions,
790 struct _mesa_glsl_parse_state *state);
791
792 ast_case_statement_list *stmts;
793 };
794
795
796 class ast_selection_statement : public ast_node {
797 public:
798 ast_selection_statement(ast_expression *condition,
799 ast_node *then_statement,
800 ast_node *else_statement);
801 virtual void print(void) const;
802
803 virtual ir_rvalue *hir(exec_list *instructions,
804 struct _mesa_glsl_parse_state *state);
805
806 ast_expression *condition;
807 ast_node *then_statement;
808 ast_node *else_statement;
809 };
810
811
812 class ast_switch_statement : public ast_node {
813 public:
814 ast_switch_statement(ast_expression *test_expression,
815 ast_node *body);
816 virtual void print(void) const;
817
818 virtual ir_rvalue *hir(exec_list *instructions,
819 struct _mesa_glsl_parse_state *state);
820
821 ast_expression *test_expression;
822 ast_node *body;
823
824 protected:
825 void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
826 };
827
828 class ast_iteration_statement : public ast_node {
829 public:
830 ast_iteration_statement(int mode, ast_node *init, ast_node *condition,
831 ast_expression *rest_expression, ast_node *body);
832
833 virtual void print(void) const;
834
835 virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
836
837 enum ast_iteration_modes {
838 ast_for,
839 ast_while,
840 ast_do_while
841 } mode;
842
843
844 ast_node *init_statement;
845 ast_node *condition;
846 ast_expression *rest_expression;
847
848 ast_node *body;
849
850 private:
851 /**
852 * Generate IR from the condition of a loop
853 *
854 * This is factored out of ::hir because some loops have the condition
855 * test at the top (for and while), and others have it at the end (do-while).
856 */
857 void condition_to_hir(class ir_loop *, struct _mesa_glsl_parse_state *);
858 };
859
860
861 class ast_jump_statement : public ast_node {
862 public:
863 ast_jump_statement(int mode, ast_expression *return_value);
864 virtual void print(void) const;
865
866 virtual ir_rvalue *hir(exec_list *instructions,
867 struct _mesa_glsl_parse_state *state);
868
869 enum ast_jump_modes {
870 ast_continue,
871 ast_break,
872 ast_return,
873 ast_discard
874 } mode;
875
876 ast_expression *opt_return_value;
877 };
878
879
880 class ast_function_definition : public ast_node {
881 public:
882 ast_function_definition() : prototype(NULL), body(NULL)
883 {
884 }
885
886 virtual void print(void) const;
887
888 virtual ir_rvalue *hir(exec_list *instructions,
889 struct _mesa_glsl_parse_state *state);
890
891 ast_function *prototype;
892 ast_compound_statement *body;
893 };
894
895 class ast_interface_block : public ast_node {
896 public:
897 ast_interface_block(ast_type_qualifier layout,
898 const char *instance_name,
899 bool is_array,
900 ast_expression *array_size)
901 : layout(layout), block_name(NULL), instance_name(instance_name),
902 is_array(is_array), array_size(array_size)
903 {
904 if (!is_array)
905 assert(array_size == NULL);
906 }
907
908 virtual ir_rvalue *hir(exec_list *instructions,
909 struct _mesa_glsl_parse_state *state);
910
911 ast_type_qualifier layout;
912 const char *block_name;
913
914 /**
915 * Declared name of the block instance, if specified.
916 *
917 * If the block does not have an instance name, this field will be
918 * \c NULL.
919 */
920 const char *instance_name;
921
922 /** List of ast_declarator_list * */
923 exec_list declarations;
924
925 /**
926 * True if the block is declared as an array
927 *
928 * \note
929 * A block can only be an array if it also has an instance name. If this
930 * field is true, ::instance_name must also not be \c NULL.
931 */
932 bool is_array;
933
934 /**
935 * Declared array size of the block instance
936 *
937 * If the block is not declared as an array or if the block instance array
938 * is unsized, this field will be \c NULL.
939 */
940 ast_expression *array_size;
941 };
942
943
944 /**
945 * AST node representing a declaration of the input layout for geometry
946 * shaders.
947 */
948 class ast_gs_input_layout : public ast_node
949 {
950 public:
951 ast_gs_input_layout(const struct YYLTYPE &locp, GLenum prim_type)
952 : prim_type(prim_type)
953 {
954 set_location(locp);
955 }
956
957 virtual ir_rvalue *hir(exec_list *instructions,
958 struct _mesa_glsl_parse_state *state);
959
960 private:
961 const GLenum prim_type;
962 };
963
964 /*@}*/
965
966 extern void
967 _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state);
968
969 extern ir_rvalue *
970 _mesa_ast_field_selection_to_hir(const ast_expression *expr,
971 exec_list *instructions,
972 struct _mesa_glsl_parse_state *state);
973
974 extern ir_rvalue *
975 _mesa_ast_array_index_to_hir(void *mem_ctx,
976 struct _mesa_glsl_parse_state *state,
977 ir_rvalue *array, ir_rvalue *idx,
978 YYLTYPE &loc, YYLTYPE &idx_loc);
979
980 extern void
981 _mesa_ast_set_aggregate_type(const ast_type_specifier *type,
982 ast_expression *expr,
983 _mesa_glsl_parse_state *state);
984
985 void
986 emit_function(_mesa_glsl_parse_state *state, ir_function *f);
987
988 extern void
989 check_builtin_array_max_size(const char *name, unsigned size,
990 YYLTYPE loc, struct _mesa_glsl_parse_state *state);
991
992 #endif /* AST_H */