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