Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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.       /** \brief Set of flags, accessed by name. */
  440.       q;
  441.  
  442.       /** \brief Set of flags, accessed as a bitmask. */
  443.       unsigned i;
  444.    } flags;
  445.  
  446.    /** Precision of the type (highp/medium/lowp). */
  447.    unsigned precision:2;
  448.  
  449.    /**
  450.     * Location specified via GL_ARB_explicit_attrib_location layout
  451.     *
  452.     * \note
  453.     * This field is only valid if \c explicit_location is set.
  454.     */
  455.    int location;
  456.    /**
  457.     * Index specified via GL_ARB_explicit_attrib_location layout
  458.     *
  459.     * \note
  460.     * This field is only valid if \c explicit_index is set.
  461.     */
  462.    int index;
  463.  
  464.    /**
  465.     * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
  466.     *
  467.     * \note
  468.     * This field is only valid if \c explicit_binding is set.
  469.     */
  470.    int binding;
  471.  
  472.    /**
  473.     * Return true if and only if an interpolation qualifier is present.
  474.     */
  475.    bool has_interpolation() const;
  476.  
  477.    /**
  478.     * Return whether a layout qualifier is present.
  479.     */
  480.    bool has_layout() const;
  481.  
  482.    /**
  483.     * Return whether a storage qualifier is present.
  484.     */
  485.    bool has_storage() const;
  486.  
  487.    /**
  488.     * Return whether an auxiliary storage qualifier is present.
  489.     */
  490.    bool has_auxiliary_storage() const;
  491.  
  492.    /**
  493.     * \brief Return string representation of interpolation qualifier.
  494.     *
  495.     * If an interpolation qualifier is present, then return that qualifier's
  496.     * string representation. Otherwise, return null. For example, if the
  497.     * noperspective bit is set, then this returns "noperspective".
  498.     *
  499.     * If multiple interpolation qualifiers are somehow present, then the
  500.     * returned string is undefined but not null.
  501.     */
  502.    const char *interpolation_string() const;
  503.  
  504.    bool merge_qualifier(YYLTYPE *loc,
  505.                         _mesa_glsl_parse_state *state,
  506.                         ast_type_qualifier q);
  507. };
  508.  
  509. class ast_declarator_list;
  510.  
  511. class ast_struct_specifier : public ast_node {
  512. public:
  513.    /**
  514.     * \brief Make a shallow copy of an ast_struct_specifier.
  515.     *
  516.     * Use only if the objects are allocated from the same context and will not
  517.     * be modified. Zeros the inherited ast_node's fields.
  518.     */
  519.    ast_struct_specifier(const ast_struct_specifier& that):
  520.       ast_node(), name(that.name), declarations(that.declarations),
  521.       is_declaration(that.is_declaration)
  522.    {
  523.       /* empty */
  524.    }
  525.  
  526.    ast_struct_specifier(const char *identifier,
  527.                         ast_declarator_list *declarator_list);
  528.    virtual void print(void) const;
  529.  
  530.    virtual ir_rvalue *hir(exec_list *instructions,
  531.                           struct _mesa_glsl_parse_state *state);
  532.  
  533.    const char *name;
  534.    /* List of ast_declarator_list * */
  535.    exec_list declarations;
  536.    bool is_declaration;
  537. };
  538.  
  539.  
  540.  
  541. class ast_type_specifier : public ast_node {
  542. public:
  543.    /**
  544.     * \brief Make a shallow copy of an ast_type_specifier, specifying array
  545.     *        fields.
  546.     *
  547.     * Use only if the objects are allocated from the same context and will not
  548.     * be modified. Zeros the inherited ast_node's fields.
  549.     */
  550.    ast_type_specifier(const ast_type_specifier *that, bool is_array,
  551.                       ast_expression *array_size)
  552.       : ast_node(), type_name(that->type_name), structure(that->structure),
  553.         is_array(is_array), array_size(array_size),
  554.         default_precision(that->default_precision)
  555.    {
  556.       /* empty */
  557.    }
  558.  
  559.    /** Construct a type specifier from a type name */
  560.    ast_type_specifier(const char *name)
  561.       : type_name(name), structure(NULL),
  562.         is_array(false), array_size(NULL),
  563.         default_precision(ast_precision_none)
  564.    {
  565.       /* empty */
  566.    }
  567.  
  568.    /** Construct a type specifier from a structure definition */
  569.    ast_type_specifier(ast_struct_specifier *s)
  570.       : type_name(s->name), structure(s),
  571.         is_array(false), array_size(NULL),
  572.         default_precision(ast_precision_none)
  573.    {
  574.       /* empty */
  575.    }
  576.  
  577.    const struct glsl_type *glsl_type(const char **name,
  578.                                      struct _mesa_glsl_parse_state *state)
  579.       const;
  580.  
  581.    virtual void print(void) const;
  582.  
  583.    ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
  584.  
  585.    const char *type_name;
  586.    ast_struct_specifier *structure;
  587.  
  588.    bool is_array;
  589.    ast_expression *array_size;
  590.  
  591.    /** For precision statements, this is the given precision; otherwise none. */
  592.    unsigned default_precision:2;
  593. };
  594.  
  595.  
  596. class ast_fully_specified_type : public ast_node {
  597. public:
  598.    virtual void print(void) const;
  599.    bool has_qualifiers() const;
  600.  
  601.    const struct glsl_type *glsl_type(const char **name,
  602.                                      struct _mesa_glsl_parse_state *state)
  603.       const;
  604.  
  605.    ast_type_qualifier qualifier;
  606.    ast_type_specifier *specifier;
  607. };
  608.  
  609.  
  610. class ast_declarator_list : public ast_node {
  611. public:
  612.    ast_declarator_list(ast_fully_specified_type *);
  613.    virtual void print(void) const;
  614.  
  615.    virtual ir_rvalue *hir(exec_list *instructions,
  616.                           struct _mesa_glsl_parse_state *state);
  617.  
  618.    ast_fully_specified_type *type;
  619.    /** List of 'ast_declaration *' */
  620.    exec_list declarations;
  621.  
  622.    /**
  623.     * Special flag for vertex shader "invariant" declarations.
  624.     *
  625.     * Vertex shaders can contain "invariant" variable redeclarations that do
  626.     * not include a type.  For example, "invariant gl_Position;".  This flag
  627.     * is used to note these cases when no type is specified.
  628.     */
  629.    int invariant;
  630. };
  631.  
  632.  
  633. class ast_parameter_declarator : public ast_node {
  634. public:
  635.    ast_parameter_declarator() :
  636.       type(NULL),
  637.       identifier(NULL),
  638.       is_array(false),
  639.       array_size(NULL),
  640.       formal_parameter(false),
  641.       is_void(false)
  642.    {
  643.       /* empty */
  644.    }
  645.  
  646.    virtual void print(void) const;
  647.  
  648.    virtual ir_rvalue *hir(exec_list *instructions,
  649.                           struct _mesa_glsl_parse_state *state);
  650.  
  651.    ast_fully_specified_type *type;
  652.    const char *identifier;
  653.    bool is_array;
  654.    ast_expression *array_size;
  655.  
  656.    static void parameters_to_hir(exec_list *ast_parameters,
  657.                                  bool formal, exec_list *ir_parameters,
  658.                                  struct _mesa_glsl_parse_state *state);
  659.  
  660. private:
  661.    /** Is this parameter declaration part of a formal parameter list? */
  662.    bool formal_parameter;
  663.  
  664.    /**
  665.     * Is this parameter 'void' type?
  666.     *
  667.     * This field is set by \c ::hir.
  668.     */
  669.    bool is_void;
  670. };
  671.  
  672.  
  673. class ast_function : public ast_node {
  674. public:
  675.    ast_function(void);
  676.  
  677.    virtual void print(void) const;
  678.  
  679.    virtual ir_rvalue *hir(exec_list *instructions,
  680.                           struct _mesa_glsl_parse_state *state);
  681.  
  682.    ast_fully_specified_type *return_type;
  683.    const char *identifier;
  684.  
  685.    exec_list parameters;
  686.  
  687. private:
  688.    /**
  689.     * Is this prototype part of the function definition?
  690.     *
  691.     * Used by ast_function_definition::hir to process the parameters, etc.
  692.     * of the function.
  693.     *
  694.     * \sa ::hir
  695.     */
  696.    bool is_definition;
  697.  
  698.    /**
  699.     * Function signature corresponding to this function prototype instance
  700.     *
  701.     * Used by ast_function_definition::hir to process the parameters, etc.
  702.     * of the function.
  703.     *
  704.     * \sa ::hir
  705.     */
  706.    class ir_function_signature *signature;
  707.  
  708.    friend class ast_function_definition;
  709. };
  710.  
  711.  
  712. class ast_expression_statement : public ast_node {
  713. public:
  714.    ast_expression_statement(ast_expression *);
  715.    virtual void print(void) const;
  716.  
  717.    virtual ir_rvalue *hir(exec_list *instructions,
  718.                           struct _mesa_glsl_parse_state *state);
  719.  
  720.    ast_expression *expression;
  721. };
  722.  
  723.  
  724. class ast_case_label : public ast_node {
  725. public:
  726.    ast_case_label(ast_expression *test_value);
  727.    virtual void print(void) const;
  728.  
  729.    virtual ir_rvalue *hir(exec_list *instructions,
  730.                           struct _mesa_glsl_parse_state *state);
  731.  
  732.    /**
  733.     * An test value of NULL means 'default'.
  734.     */
  735.    ast_expression *test_value;
  736. };
  737.  
  738.  
  739. class ast_case_label_list : public ast_node {
  740. public:
  741.    ast_case_label_list(void);
  742.    virtual void print(void) const;
  743.  
  744.    virtual ir_rvalue *hir(exec_list *instructions,
  745.                           struct _mesa_glsl_parse_state *state);
  746.  
  747.    /**
  748.     * A list of case labels.
  749.     */
  750.    exec_list labels;
  751. };
  752.  
  753.  
  754. class ast_case_statement : public ast_node {
  755. public:
  756.    ast_case_statement(ast_case_label_list *labels);
  757.    virtual void print(void) const;
  758.  
  759.    virtual ir_rvalue *hir(exec_list *instructions,
  760.                           struct _mesa_glsl_parse_state *state);
  761.  
  762.    ast_case_label_list *labels;
  763.  
  764.    /**
  765.     * A list of statements.
  766.     */
  767.    exec_list stmts;
  768. };
  769.  
  770.  
  771. class ast_case_statement_list : public ast_node {
  772. public:
  773.    ast_case_statement_list(void);
  774.    virtual void print(void) const;
  775.  
  776.    virtual ir_rvalue *hir(exec_list *instructions,
  777.                           struct _mesa_glsl_parse_state *state);
  778.  
  779.    /**
  780.     * A list of cases.
  781.     */
  782.    exec_list cases;
  783. };
  784.  
  785.  
  786. class ast_switch_body : public ast_node {
  787. public:
  788.    ast_switch_body(ast_case_statement_list *stmts);
  789.    virtual void print(void) const;
  790.  
  791.    virtual ir_rvalue *hir(exec_list *instructions,
  792.                           struct _mesa_glsl_parse_state *state);
  793.  
  794.    ast_case_statement_list *stmts;
  795. };
  796.  
  797.  
  798. class ast_selection_statement : public ast_node {
  799. public:
  800.    ast_selection_statement(ast_expression *condition,
  801.                            ast_node *then_statement,
  802.                            ast_node *else_statement);
  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_expression *condition;
  809.    ast_node *then_statement;
  810.    ast_node *else_statement;
  811. };
  812.  
  813.  
  814. class ast_switch_statement : public ast_node {
  815. public:
  816.    ast_switch_statement(ast_expression *test_expression,
  817.                         ast_node *body);
  818.    virtual void print(void) const;
  819.  
  820.    virtual ir_rvalue *hir(exec_list *instructions,
  821.                           struct _mesa_glsl_parse_state *state);
  822.  
  823.    ast_expression *test_expression;
  824.    ast_node *body;
  825.  
  826. protected:
  827.    void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
  828. };
  829.  
  830. class ast_iteration_statement : public ast_node {
  831. public:
  832.    ast_iteration_statement(int mode, ast_node *init, ast_node *condition,
  833.                            ast_expression *rest_expression, ast_node *body);
  834.  
  835.    virtual void print(void) const;
  836.  
  837.    virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
  838.  
  839.    enum ast_iteration_modes {
  840.       ast_for,
  841.       ast_while,
  842.       ast_do_while
  843.    } mode;
  844.    
  845.  
  846.    ast_node *init_statement;
  847.    ast_node *condition;
  848.    ast_expression *rest_expression;
  849.  
  850.    ast_node *body;
  851.  
  852. private:
  853.    /**
  854.     * Generate IR from the condition of a loop
  855.     *
  856.     * This is factored out of ::hir because some loops have the condition
  857.     * test at the top (for and while), and others have it at the end (do-while).
  858.     */
  859.    void condition_to_hir(class ir_loop *, struct _mesa_glsl_parse_state *);
  860. };
  861.  
  862.  
  863. class ast_jump_statement : public ast_node {
  864. public:
  865.    ast_jump_statement(int mode, ast_expression *return_value);
  866.    virtual void print(void) const;
  867.  
  868.    virtual ir_rvalue *hir(exec_list *instructions,
  869.                           struct _mesa_glsl_parse_state *state);
  870.  
  871.    enum ast_jump_modes {
  872.       ast_continue,
  873.       ast_break,
  874.       ast_return,
  875.       ast_discard
  876.    } mode;
  877.  
  878.    ast_expression *opt_return_value;
  879. };
  880.  
  881.  
  882. class ast_function_definition : public ast_node {
  883. public:
  884.    virtual void print(void) const;
  885.  
  886.    virtual ir_rvalue *hir(exec_list *instructions,
  887.                           struct _mesa_glsl_parse_state *state);
  888.  
  889.    ast_function *prototype;
  890.    ast_compound_statement *body;
  891. };
  892.  
  893. class ast_interface_block : public ast_node {
  894. public:
  895.    ast_interface_block(ast_type_qualifier layout,
  896.                      const char *instance_name,
  897.                      ast_expression *array_size)
  898.    : layout(layout), block_name(NULL), instance_name(instance_name),
  899.      array_size(array_size)
  900.    {
  901.       /* empty */
  902.    }
  903.  
  904.    virtual ir_rvalue *hir(exec_list *instructions,
  905.                           struct _mesa_glsl_parse_state *state);
  906.  
  907.    ast_type_qualifier layout;
  908.    const char *block_name;
  909.  
  910.    /**
  911.     * Declared name of the block instance, if specified.
  912.     *
  913.     * If the block does not have an instance name, this field will be
  914.     * \c NULL.
  915.     */
  916.    const char *instance_name;
  917.  
  918.    /** List of ast_declarator_list * */
  919.    exec_list declarations;
  920.  
  921.    /**
  922.     * Declared array size of the block instance
  923.     *
  924.     * If the block is not declared as an array, this field will be \c NULL.
  925.     *
  926.     * \note
  927.     * A block can only be an array if it also has an instance name.  If this
  928.     * field is not \c NULL, ::instance_name must also not be \c NULL.
  929.     */
  930.    ast_expression *array_size;
  931. };
  932. /*@}*/
  933.  
  934. extern void
  935. _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state);
  936.  
  937. extern ir_rvalue *
  938. _mesa_ast_field_selection_to_hir(const ast_expression *expr,
  939.                                  exec_list *instructions,
  940.                                  struct _mesa_glsl_parse_state *state);
  941.  
  942. extern ir_rvalue *
  943. _mesa_ast_array_index_to_hir(void *mem_ctx,
  944.                              struct _mesa_glsl_parse_state *state,
  945.                              ir_rvalue *array, ir_rvalue *idx,
  946.                              YYLTYPE &loc, YYLTYPE &idx_loc);
  947.  
  948. extern void
  949. _mesa_ast_set_aggregate_type(const ast_type_specifier *type,
  950.                              ast_expression *expr,
  951.                              _mesa_glsl_parse_state *state);
  952.  
  953. void
  954. emit_function(_mesa_glsl_parse_state *state, ir_function *f);
  955.  
  956. extern void
  957. check_builtin_array_max_size(const char *name, unsigned size,
  958.                              YYLTYPE loc, struct _mesa_glsl_parse_state *state);
  959.  
  960. #endif /* AST_H */
  961.