3 * Copyright © 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
30 #include "glsl_parser_extras.h"
32 struct _mesa_glsl_parse_state
;
37 * \defgroup AST Abstract syntax tree node definitions
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.
48 * Base class of all abstract syntax tree nodes
52 DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node
);
55 * Print an AST node in something approximating the original GLSL code
57 virtual void print(void) const;
60 * Convert the AST node to the high-level intermediate representation
62 virtual ir_rvalue
*hir(exec_list
*instructions
,
63 struct _mesa_glsl_parse_state
*state
);
65 virtual bool has_sequence_subexpression() const;
68 * Retrieve the source location of an AST node
70 * This function is primarily used to get the source position of an AST node
71 * into a form that can be passed to \c _mesa_glsl_error.
73 * \sa _mesa_glsl_error, ast_node::set_location
75 struct YYLTYPE
get_location(void) const
79 locp
.source
= this->location
.source
;
80 locp
.first_line
= this->location
.first_line
;
81 locp
.first_column
= this->location
.first_column
;
82 locp
.last_line
= this->location
.last_line
;
83 locp
.last_column
= this->location
.last_column
;
89 * Set the source location of an AST node from a parser location
91 * \sa ast_node::get_location
93 void set_location(const struct YYLTYPE
&locp
)
95 this->location
.source
= locp
.source
;
96 this->location
.first_line
= locp
.first_line
;
97 this->location
.first_column
= locp
.first_column
;
98 this->location
.last_line
= locp
.last_line
;
99 this->location
.last_column
= locp
.last_column
;
103 * Set the source location range of an AST node using two location nodes
105 * \sa ast_node::set_location
107 void set_location_range(const struct YYLTYPE
&begin
, const struct YYLTYPE
&end
)
109 this->location
.source
= begin
.source
;
110 this->location
.first_line
= begin
.first_line
;
111 this->location
.last_line
= end
.last_line
;
112 this->location
.first_column
= begin
.first_column
;
113 this->location
.last_column
= end
.last_column
;
117 * Source location of the AST node.
120 unsigned source
; /**< GLSL source number. */
121 unsigned first_line
; /**< First line number within the source string. */
122 unsigned first_column
; /**< First column in the first line. */
123 unsigned last_line
; /**< Last line number within the source string. */
124 unsigned last_column
; /**< Last column in the last line. */
129 virtual void set_is_lhs(bool);
133 * The only constructor is protected so that only derived class objects can
141 * Operators for AST expression nodes.
145 ast_plus
, /**< Unary + operator. */
188 ast_unsized_array_dim
,
203 * Number of possible operators for an ast_expression
205 * This is done as a define instead of as an additional value in the enum so
206 * that the compiler won't generate spurious messages like "warning:
207 * enumeration value ‘ast_num_operators’ not handled in switch"
209 #define AST_NUM_OPERATORS (ast_aggregate + 1)
213 * Representation of any sort of expression.
215 class ast_expression
: public ast_node
{
217 ast_expression(int oper
, ast_expression
*,
218 ast_expression
*, ast_expression
*);
220 ast_expression(const char *identifier
) :
223 subexpressions
[0] = NULL
;
224 subexpressions
[1] = NULL
;
225 subexpressions
[2] = NULL
;
226 primary_expression
.identifier
= identifier
;
227 this->non_lvalue_description
= NULL
;
228 this->is_lhs
= false;
231 static const char *operator_string(enum ast_operators op
);
233 virtual ir_rvalue
*hir(exec_list
*instructions
,
234 struct _mesa_glsl_parse_state
*state
);
236 virtual void hir_no_rvalue(exec_list
*instructions
,
237 struct _mesa_glsl_parse_state
*state
);
239 virtual bool has_sequence_subexpression() const;
241 ir_rvalue
*do_hir(exec_list
*instructions
,
242 struct _mesa_glsl_parse_state
*state
,
245 virtual void print(void) const;
247 enum ast_operators oper
;
249 ast_expression
*subexpressions
[3];
252 const char *identifier
;
254 float float_constant
;
255 unsigned uint_constant
;
257 double double_constant
;
258 } primary_expression
;
262 * List of expressions for an \c ast_sequence or parameters for an
263 * \c ast_function_call
265 exec_list expressions
;
268 * For things that can't be l-values, this describes what it is.
270 * This text is used by the code that generates IR for assignments to
271 * detect and emit useful messages for assignments to some things that
272 * can't be l-values. For example, pre- or post-incerement expressions.
275 * This pointer may be \c NULL.
277 const char *non_lvalue_description
;
279 void set_is_lhs(bool new_value
);
285 class ast_expression_bin
: public ast_expression
{
287 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
289 virtual void print(void) const;
293 * Subclass of expressions for function calls
295 class ast_function_expression
: public ast_expression
{
297 ast_function_expression(ast_expression
*callee
)
298 : ast_expression(ast_function_call
, callee
,
305 ast_function_expression(class ast_type_specifier
*type
)
306 : ast_expression(ast_function_call
, (ast_expression
*) type
,
313 bool is_constructor() const
318 virtual ir_rvalue
*hir(exec_list
*instructions
,
319 struct _mesa_glsl_parse_state
*state
);
321 virtual void hir_no_rvalue(exec_list
*instructions
,
322 struct _mesa_glsl_parse_state
*state
);
324 virtual bool has_sequence_subexpression() const;
328 * Is this function call actually a constructor?
332 handle_method(exec_list
*instructions
,
333 struct _mesa_glsl_parse_state
*state
);
336 class ast_subroutine_list
: public ast_node
339 virtual void print(void) const;
340 exec_list declarations
;
343 class ast_array_specifier
: public ast_node
{
345 ast_array_specifier(const struct YYLTYPE
&locp
, ast_expression
*dim
)
348 array_dimensions
.push_tail(&dim
->link
);
351 void add_dimension(ast_expression
*dim
)
353 array_dimensions
.push_tail(&dim
->link
);
356 bool is_single_dimension() const
358 return this->array_dimensions
.get_tail_raw()->prev
!= NULL
&&
359 this->array_dimensions
.get_tail_raw()->prev
->is_head_sentinel();
362 virtual void print(void) const;
364 /* This list contains objects of type ast_node containing the
365 * array dimensions in outermost-to-innermost order.
367 exec_list array_dimensions
;
370 class ast_layout_expression
: public ast_node
{
372 ast_layout_expression(const struct YYLTYPE
&locp
, ast_expression
*expr
)
375 layout_const_expressions
.push_tail(&expr
->link
);
378 bool process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
379 const char *qual_indentifier
,
380 unsigned *value
, bool can_be_zero
,
381 bool must_match
= false);
383 void merge_qualifier(ast_layout_expression
*l_expr
)
385 layout_const_expressions
.append_list(&l_expr
->layout_const_expressions
);
388 exec_list layout_const_expressions
;
392 * C-style aggregate initialization class
394 * Represents C-style initializers of vectors, matrices, arrays, and
395 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
396 * vec3 pos = vec3(1.0, 0.0, -1.0).
398 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
400 * \sa _mesa_ast_set_aggregate_type
402 class ast_aggregate_initializer
: public ast_expression
{
404 ast_aggregate_initializer()
405 : ast_expression(ast_aggregate
, NULL
, NULL
, NULL
),
406 constructor_type(NULL
)
412 * glsl_type of the aggregate, which is inferred from the LHS of whatever
413 * the aggregate is being used to initialize. This can't be inferred at
414 * parse time (since the parser deals with ast_type_specifiers, not
415 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
416 * conversion code makes sure to fill it in with the appropriate type
417 * before hir() is called.
419 const glsl_type
*constructor_type
;
421 virtual ir_rvalue
*hir(exec_list
*instructions
,
422 struct _mesa_glsl_parse_state
*state
);
424 virtual void hir_no_rvalue(exec_list
*instructions
,
425 struct _mesa_glsl_parse_state
*state
);
429 class ast_compound_statement
: public ast_node
{
431 ast_compound_statement(int new_scope
, ast_node
*statements
);
432 virtual void print(void) const;
434 virtual ir_rvalue
*hir(exec_list
*instructions
,
435 struct _mesa_glsl_parse_state
*state
);
438 exec_list statements
;
441 class ast_declaration
: public ast_node
{
443 ast_declaration(const char *identifier
,
444 ast_array_specifier
*array_specifier
,
445 ast_expression
*initializer
);
446 virtual void print(void) const;
448 const char *identifier
;
450 ast_array_specifier
*array_specifier
;
452 ast_expression
*initializer
;
457 ast_precision_none
= 0, /**< Absence of precision qualifier. */
459 ast_precision_medium
,
463 struct ast_type_qualifier
{
464 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier
);
468 unsigned invariant
:1;
471 unsigned attribute
:1;
480 unsigned shared_storage
:1;
483 unsigned noperspective
:1;
485 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
487 unsigned origin_upper_left
:1;
488 unsigned pixel_center_integer
:1;
492 * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is
495 unsigned explicit_align
:1;
498 * Flag set if GL_ARB_explicit_attrib_location "location" layout
501 unsigned explicit_location
:1;
503 * Flag set if GL_ARB_explicit_attrib_location "index" layout
506 unsigned explicit_index
:1;
509 * Flag set if GL_ARB_enhanced_layouts "component" layout
512 unsigned explicit_component
:1;
515 * Flag set if GL_ARB_shading_language_420pack "binding" layout
518 unsigned explicit_binding
:1;
521 * Flag set if GL_ARB_shader_atomic counter "offset" layout
524 unsigned explicit_offset
:1;
526 /** \name Layout qualifiers for GL_AMD_conservative_depth */
528 unsigned depth_any
:1;
529 unsigned depth_greater
:1;
530 unsigned depth_less
:1;
531 unsigned depth_unchanged
:1;
534 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
540 unsigned column_major
:1;
541 unsigned row_major
:1;
544 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
546 unsigned prim_type
:1;
547 unsigned max_vertices
:1;
551 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
552 * local_size_x, and so on.
554 unsigned local_size
:3;
556 /** \name Layout qualifiers for ARB_compute_variable_group_size. */
558 unsigned local_size_variable
:1;
561 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
563 unsigned early_fragment_tests
:1;
564 unsigned explicit_image_format
:1;
566 unsigned _volatile
:1;
567 unsigned restrict_flag
:1;
568 unsigned read_only
:1; /**< "readonly" qualifier. */
569 unsigned write_only
:1; /**< "writeonly" qualifier. */
572 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
574 unsigned invocations
:1;
575 unsigned stream
:1; /**< Has stream value assigned */
576 unsigned explicit_stream
:1; /**< stream value assigned explicitly by shader code */
579 /** \name Layout qualifiers for GL_ARB_enhanced_layouts */
581 unsigned explicit_xfb_offset
:1; /**< xfb_offset value assigned explicitly by shader code */
582 unsigned xfb_buffer
:1; /**< Has xfb_buffer value assigned */
583 unsigned explicit_xfb_buffer
:1; /**< xfb_buffer value assigned explicitly by shader code */
584 unsigned xfb_stride
:1; /**< Is xfb_stride value yet to be merged with global values */
585 unsigned explicit_xfb_stride
:1; /**< xfb_stride value assigned explicitly by shader code */
588 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
590 /* tess eval input layout */
591 /* gs prim_type reused for primitive mode */
592 unsigned vertex_spacing
:1;
594 unsigned point_mode
:1;
595 /* tess control output layout */
599 /** \name Qualifiers for GL_ARB_shader_subroutine */
601 unsigned subroutine
:1; /**< Is this marked 'subroutine' */
602 unsigned subroutine_def
:1; /**< Is this marked 'subroutine' with a list of types */
605 /** \name Qualifiers for GL_KHR_blend_equation_advanced */
607 unsigned blend_support
:1; /**< Are there any blend_support_ qualifiers */
610 /** \brief Set of flags, accessed by name. */
613 /** \brief Set of flags, accessed as a bitmask. */
617 /** Precision of the type (highp/medium/lowp). */
618 unsigned precision
:2;
621 * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier
623 ast_expression
*align
;
625 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
626 ast_layout_expression
*invocations
;
629 * Location specified via GL_ARB_explicit_attrib_location layout
632 * This field is only valid if \c explicit_location is set.
634 ast_expression
*location
;
636 * Index specified via GL_ARB_explicit_attrib_location layout
639 * This field is only valid if \c explicit_index is set.
641 ast_expression
*index
;
644 * Component specified via GL_ARB_enhaced_layouts
647 * This field is only valid if \c explicit_component is set.
649 ast_expression
*component
;
651 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
652 ast_layout_expression
*max_vertices
;
654 /** Stream in GLSL 1.50 geometry shaders. */
655 ast_expression
*stream
;
657 /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */
658 ast_expression
*xfb_buffer
;
660 /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */
661 ast_expression
*xfb_stride
;
663 /** global xfb_stride values for each buffer */
664 ast_layout_expression
*out_xfb_stride
[MAX_FEEDBACK_BUFFERS
];
667 * Input or output primitive type in GLSL 1.50 geometry shaders
668 * and tessellation shaders.
673 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
676 * This field is only valid if \c explicit_binding is set.
678 ast_expression
*binding
;
681 * Offset specified via GL_ARB_shader_atomic_counter's or
682 * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts
683 * "xfb_offset" keyword.
686 * This field is only valid if \c explicit_offset is set.
688 ast_expression
*offset
;
691 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
692 * layout qualifier. Element i of this array is only valid if
693 * flags.q.local_size & (1 << i) is set.
695 ast_layout_expression
*local_size
[3];
697 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
698 GLenum vertex_spacing
;
700 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
703 /** Tessellation evaluation shader: point mode */
706 /** Tessellation control shader: number of output vertices */
707 ast_layout_expression
*vertices
;
710 * Image format specified with an ARB_shader_image_load_store
714 * This field is only valid if \c explicit_image_format is set.
719 * Base type of the data read from or written to this image. Only
720 * the following enumerants are allowed: GLSL_TYPE_UINT,
721 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
724 * This field is only valid if \c explicit_image_format is set.
726 glsl_base_type image_base_type
;
729 * Return true if and only if an interpolation qualifier is present.
731 bool has_interpolation() const;
734 * Return whether a layout qualifier is present.
736 bool has_layout() const;
739 * Return whether a storage qualifier is present.
741 bool has_storage() const;
744 * Return whether an auxiliary storage qualifier is present.
746 bool has_auxiliary_storage() const;
749 * Return true if and only if a memory qualifier is present.
751 bool has_memory() const;
753 bool merge_qualifier(YYLTYPE
*loc
,
754 _mesa_glsl_parse_state
*state
,
755 const ast_type_qualifier
&q
,
756 bool is_single_layout_merge
,
757 bool is_multiple_layouts_merge
= false);
760 * Validate current qualifier against the global out one.
762 bool validate_out_qualifier(YYLTYPE
*loc
,
763 _mesa_glsl_parse_state
*state
);
766 * Merge current qualifier into the global out one.
768 bool merge_into_out_qualifier(YYLTYPE
*loc
,
769 _mesa_glsl_parse_state
*state
,
770 ast_node
* &node
, bool create_node
);
773 * Validate current qualifier against the global in one.
775 bool validate_in_qualifier(YYLTYPE
*loc
,
776 _mesa_glsl_parse_state
*state
);
779 * Merge current qualifier into the global in one.
781 bool merge_into_in_qualifier(YYLTYPE
*loc
,
782 _mesa_glsl_parse_state
*state
,
783 ast_node
* &node
, bool create_node
);
785 bool validate_flags(YYLTYPE
*loc
,
786 _mesa_glsl_parse_state
*state
,
787 const ast_type_qualifier
&allowed_flags
,
788 const char *message
, const char *name
);
790 ast_subroutine_list
*subroutine_list
;
793 class ast_declarator_list
;
795 class ast_struct_specifier
: public ast_node
{
797 ast_struct_specifier(void *lin_ctx
, const char *identifier
,
798 ast_declarator_list
*declarator_list
);
799 virtual void print(void) const;
801 virtual ir_rvalue
*hir(exec_list
*instructions
,
802 struct _mesa_glsl_parse_state
*state
);
805 ast_type_qualifier
*layout
;
806 /* List of ast_declarator_list * */
807 exec_list declarations
;
813 class ast_type_specifier
: public ast_node
{
815 /** Construct a type specifier from a type name */
816 ast_type_specifier(const char *name
)
817 : type_name(name
), structure(NULL
), array_specifier(NULL
),
818 default_precision(ast_precision_none
)
823 /** Construct a type specifier from a structure definition */
824 ast_type_specifier(ast_struct_specifier
*s
)
825 : type_name(s
->name
), structure(s
), array_specifier(NULL
),
826 default_precision(ast_precision_none
)
831 const struct glsl_type
*glsl_type(const char **name
,
832 struct _mesa_glsl_parse_state
*state
)
835 virtual void print(void) const;
837 ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
839 const char *type_name
;
840 ast_struct_specifier
*structure
;
842 ast_array_specifier
*array_specifier
;
844 /** For precision statements, this is the given precision; otherwise none. */
845 unsigned default_precision
:2;
849 class ast_fully_specified_type
: public ast_node
{
851 virtual void print(void) const;
852 bool has_qualifiers(_mesa_glsl_parse_state
*state
) const;
854 ast_fully_specified_type() : qualifier(), specifier(NULL
)
858 const struct glsl_type
*glsl_type(const char **name
,
859 struct _mesa_glsl_parse_state
*state
)
862 ast_type_qualifier qualifier
;
863 ast_type_specifier
*specifier
;
867 class ast_declarator_list
: public ast_node
{
869 ast_declarator_list(ast_fully_specified_type
*);
870 virtual void print(void) const;
872 virtual ir_rvalue
*hir(exec_list
*instructions
,
873 struct _mesa_glsl_parse_state
*state
);
875 ast_fully_specified_type
*type
;
876 /** List of 'ast_declaration *' */
877 exec_list declarations
;
880 * Flags for redeclarations. In these cases, no type is specified, to
881 * `type` is allowed to be NULL. In all other cases, this would be an error.
883 int invariant
; /** < `invariant` redeclaration */
884 int precise
; /** < `precise` redeclaration */
888 class ast_parameter_declarator
: public ast_node
{
890 ast_parameter_declarator() :
893 array_specifier(NULL
),
894 formal_parameter(false),
900 virtual void print(void) const;
902 virtual ir_rvalue
*hir(exec_list
*instructions
,
903 struct _mesa_glsl_parse_state
*state
);
905 ast_fully_specified_type
*type
;
906 const char *identifier
;
907 ast_array_specifier
*array_specifier
;
909 static void parameters_to_hir(exec_list
*ast_parameters
,
910 bool formal
, exec_list
*ir_parameters
,
911 struct _mesa_glsl_parse_state
*state
);
914 /** Is this parameter declaration part of a formal parameter list? */
915 bool formal_parameter
;
918 * Is this parameter 'void' type?
920 * This field is set by \c ::hir.
926 class ast_function
: public ast_node
{
930 virtual void print(void) const;
932 virtual ir_rvalue
*hir(exec_list
*instructions
,
933 struct _mesa_glsl_parse_state
*state
);
935 ast_fully_specified_type
*return_type
;
936 const char *identifier
;
938 exec_list parameters
;
942 * Is this prototype part of the function definition?
944 * Used by ast_function_definition::hir to process the parameters, etc.
952 * Function signature corresponding to this function prototype instance
954 * Used by ast_function_definition::hir to process the parameters, etc.
959 class ir_function_signature
*signature
;
961 friend class ast_function_definition
;
965 class ast_expression_statement
: public ast_node
{
967 ast_expression_statement(ast_expression
*);
968 virtual void print(void) const;
970 virtual ir_rvalue
*hir(exec_list
*instructions
,
971 struct _mesa_glsl_parse_state
*state
);
973 ast_expression
*expression
;
977 class ast_case_label
: public ast_node
{
979 ast_case_label(ast_expression
*test_value
);
980 virtual void print(void) const;
982 virtual ir_rvalue
*hir(exec_list
*instructions
,
983 struct _mesa_glsl_parse_state
*state
);
986 * An test value of NULL means 'default'.
988 ast_expression
*test_value
;
992 class ast_case_label_list
: public ast_node
{
994 ast_case_label_list(void);
995 virtual void print(void) const;
997 virtual ir_rvalue
*hir(exec_list
*instructions
,
998 struct _mesa_glsl_parse_state
*state
);
1001 * A list of case labels.
1007 class ast_case_statement
: public ast_node
{
1009 ast_case_statement(ast_case_label_list
*labels
);
1010 virtual void print(void) const;
1012 virtual ir_rvalue
*hir(exec_list
*instructions
,
1013 struct _mesa_glsl_parse_state
*state
);
1015 ast_case_label_list
*labels
;
1018 * A list of statements.
1024 class ast_case_statement_list
: public ast_node
{
1026 ast_case_statement_list(void);
1027 virtual void print(void) const;
1029 virtual ir_rvalue
*hir(exec_list
*instructions
,
1030 struct _mesa_glsl_parse_state
*state
);
1039 class ast_switch_body
: public ast_node
{
1041 ast_switch_body(ast_case_statement_list
*stmts
);
1042 virtual void print(void) const;
1044 virtual ir_rvalue
*hir(exec_list
*instructions
,
1045 struct _mesa_glsl_parse_state
*state
);
1047 ast_case_statement_list
*stmts
;
1051 class ast_selection_statement
: public ast_node
{
1053 ast_selection_statement(ast_expression
*condition
,
1054 ast_node
*then_statement
,
1055 ast_node
*else_statement
);
1056 virtual void print(void) const;
1058 virtual ir_rvalue
*hir(exec_list
*instructions
,
1059 struct _mesa_glsl_parse_state
*state
);
1061 ast_expression
*condition
;
1062 ast_node
*then_statement
;
1063 ast_node
*else_statement
;
1067 class ast_switch_statement
: public ast_node
{
1069 ast_switch_statement(ast_expression
*test_expression
,
1071 virtual void print(void) const;
1073 virtual ir_rvalue
*hir(exec_list
*instructions
,
1074 struct _mesa_glsl_parse_state
*state
);
1076 ast_expression
*test_expression
;
1080 void test_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1083 class ast_iteration_statement
: public ast_node
{
1085 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
1086 ast_expression
*rest_expression
, ast_node
*body
);
1088 virtual void print(void) const;
1090 virtual ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1092 enum ast_iteration_modes
{
1099 ast_node
*init_statement
;
1100 ast_node
*condition
;
1101 ast_expression
*rest_expression
;
1106 * Generate IR from the condition of a loop
1108 * This is factored out of ::hir because some loops have the condition
1109 * test at the top (for and while), and others have it at the end (do-while).
1111 void condition_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1115 class ast_jump_statement
: public ast_node
{
1117 ast_jump_statement(int mode
, ast_expression
*return_value
);
1118 virtual void print(void) const;
1120 virtual ir_rvalue
*hir(exec_list
*instructions
,
1121 struct _mesa_glsl_parse_state
*state
);
1123 enum ast_jump_modes
{
1130 ast_expression
*opt_return_value
;
1134 class ast_function_definition
: public ast_node
{
1136 ast_function_definition() : prototype(NULL
), body(NULL
)
1140 virtual void print(void) const;
1142 virtual ir_rvalue
*hir(exec_list
*instructions
,
1143 struct _mesa_glsl_parse_state
*state
);
1145 ast_function
*prototype
;
1146 ast_compound_statement
*body
;
1149 class ast_interface_block
: public ast_node
{
1151 ast_interface_block(const char *instance_name
,
1152 ast_array_specifier
*array_specifier
)
1153 : block_name(NULL
), instance_name(instance_name
),
1154 array_specifier(array_specifier
)
1158 virtual ir_rvalue
*hir(exec_list
*instructions
,
1159 struct _mesa_glsl_parse_state
*state
);
1161 ast_type_qualifier default_layout
;
1162 ast_type_qualifier layout
;
1163 const char *block_name
;
1166 * Declared name of the block instance, if specified.
1168 * If the block does not have an instance name, this field will be
1171 const char *instance_name
;
1173 /** List of ast_declarator_list * */
1174 exec_list declarations
;
1177 * Declared array size of the block instance
1179 * If the block is not declared as an array or if the block instance array
1180 * is unsized, this field will be \c NULL.
1182 ast_array_specifier
*array_specifier
;
1187 * AST node representing a declaration of the output layout for tessellation
1190 class ast_tcs_output_layout
: public ast_node
1193 ast_tcs_output_layout(const struct YYLTYPE
&locp
)
1198 virtual ir_rvalue
*hir(exec_list
*instructions
,
1199 struct _mesa_glsl_parse_state
*state
);
1204 * AST node representing a declaration of the input layout for geometry
1207 class ast_gs_input_layout
: public ast_node
1210 ast_gs_input_layout(const struct YYLTYPE
&locp
, GLenum prim_type
)
1211 : prim_type(prim_type
)
1216 virtual ir_rvalue
*hir(exec_list
*instructions
,
1217 struct _mesa_glsl_parse_state
*state
);
1220 const GLenum prim_type
;
1225 * AST node representing a decalaration of the input layout for compute
1228 class ast_cs_input_layout
: public ast_node
1231 ast_cs_input_layout(const struct YYLTYPE
&locp
,
1232 ast_layout_expression
*const *local_size
)
1234 for (int i
= 0; i
< 3; i
++) {
1235 this->local_size
[i
] = local_size
[i
];
1240 virtual ir_rvalue
*hir(exec_list
*instructions
,
1241 struct _mesa_glsl_parse_state
*state
);
1244 ast_layout_expression
*local_size
[3];
1250 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
1253 _mesa_ast_field_selection_to_hir(const ast_expression
*expr
,
1254 exec_list
*instructions
,
1255 struct _mesa_glsl_parse_state
*state
);
1258 _mesa_ast_array_index_to_hir(void *mem_ctx
,
1259 struct _mesa_glsl_parse_state
*state
,
1260 ir_rvalue
*array
, ir_rvalue
*idx
,
1261 YYLTYPE
&loc
, YYLTYPE
&idx_loc
);
1264 _mesa_ast_set_aggregate_type(const glsl_type
*type
,
1265 ast_expression
*expr
);
1268 emit_function(_mesa_glsl_parse_state
*state
, ir_function
*f
);
1271 check_builtin_array_max_size(const char *name
, unsigned size
,
1272 YYLTYPE loc
, struct _mesa_glsl_parse_state
*state
);
1274 extern void _mesa_ast_process_interface_block(YYLTYPE
*locp
,
1275 _mesa_glsl_parse_state
*state
,
1276 ast_interface_block
*const block
,
1277 const struct ast_type_qualifier
&q
);
1280 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
1282 const char *qual_indentifier
,
1283 ast_expression
*const_expression
,