radeon / r200: Pass the API into _mesa_initialize_context
[mesa.git] / src / glsl / ast.h
index 76911f056d34f148e9f2d76b234df9cfcb84dd2e..0bda28d20dd41ecba0afa580878368e6854bfa0f 100644 (file)
@@ -276,6 +276,43 @@ private:
    bool cons;
 };
 
+class ast_array_specifier : public ast_node {
+public:
+   /** Unsized array specifier ([]) */
+   explicit ast_array_specifier(const struct YYLTYPE &locp)
+     : dimension_count(1), is_unsized_array(true)
+   {
+      set_location(locp);
+   }
+
+   /** Sized array specifier ([dim]) */
+   ast_array_specifier(const struct YYLTYPE &locp, ast_expression *dim)
+     : dimension_count(1), is_unsized_array(false)
+   {
+      set_location(locp);
+      array_dimensions.push_tail(&dim->link);
+   }
+
+   void add_dimension(ast_expression *dim)
+   {
+      array_dimensions.push_tail(&dim->link);
+      dimension_count++;
+   }
+
+   virtual void print(void) const;
+
+   /* Count including sized and unsized dimensions */
+   unsigned dimension_count;
+
+   /* If true, this means that the array has an unsized outermost dimension. */
+   bool is_unsized_array;
+
+   /* This list contains objects of type ast_node containing the
+    * sized dimensions only, in outermost-to-innermost order.
+    */
+   exec_list array_dimensions;
+};
+
 /**
  * C-style aggregate initialization class
  *
@@ -296,7 +333,16 @@ public:
       /* empty */
    }
 
-   ast_type_specifier *constructor_type;
+   /**
+    * glsl_type of the aggregate, which is inferred from the LHS of whatever
+    * the aggregate is being used to initialize.  This can't be inferred at
+    * parse time (since the parser deals with ast_type_specifiers, not
+    * glsl_types), so the parser leaves it NULL.  However, the ast-to-hir
+    * conversion code makes sure to fill it in with the appropriate type
+    * before hir() is called.
+    */
+   const glsl_type *constructor_type;
+
    virtual ir_rvalue *hir(exec_list *instructions,
                           struct _mesa_glsl_parse_state *state);
 };
@@ -325,14 +371,14 @@ public:
 
 class ast_declaration : public ast_node {
 public:
-   ast_declaration(const char *identifier, bool is_array, ast_expression *array_size,
-                  ast_expression *initializer);
+   ast_declaration(const char *identifier,
+                   ast_array_specifier *array_specifier,
+                   ast_expression *initializer);
    virtual void print(void) const;
 
    const char *identifier;
-   
-   bool is_array;
-   ast_expression *array_size;
+
+   ast_array_specifier *array_specifier;
 
    ast_expression *initializer;
 };
@@ -541,10 +587,10 @@ public:
     * Use only if the objects are allocated from the same context and will not
     * be modified. Zeros the inherited ast_node's fields.
     */
-   ast_type_specifier(const ast_type_specifier *that, bool is_array,
-                      ast_expression *array_size)
+   ast_type_specifier(const ast_type_specifier *that,
+                      ast_array_specifier *array_specifier)
       : ast_node(), type_name(that->type_name), structure(that->structure),
-        is_array(is_array), array_size(array_size),
+        array_specifier(array_specifier),
         default_precision(that->default_precision)
    {
       /* empty */
@@ -552,8 +598,7 @@ public:
 
    /** Construct a type specifier from a type name */
    ast_type_specifier(const char *name) 
-      : type_name(name), structure(NULL),
-       is_array(false), array_size(NULL),
+      : type_name(name), structure(NULL), array_specifier(NULL),
        default_precision(ast_precision_none)
    {
       /* empty */
@@ -561,8 +606,7 @@ public:
 
    /** Construct a type specifier from a structure definition */
    ast_type_specifier(ast_struct_specifier *s)
-      : type_name(s->name), structure(s),
-       is_array(false), array_size(NULL),
+      : type_name(s->name), structure(s), array_specifier(NULL),
        default_precision(ast_precision_none)
    {
       /* empty */
@@ -579,8 +623,7 @@ public:
    const char *type_name;
    ast_struct_specifier *structure;
 
-   bool is_array;
-   ast_expression *array_size;
+   ast_array_specifier *array_specifier;
 
    /** For precision statements, this is the given precision; otherwise none. */
    unsigned default_precision:2;
@@ -633,8 +676,7 @@ public:
    ast_parameter_declarator() :
       type(NULL),
       identifier(NULL),
-      is_array(false),
-      array_size(NULL),
+      array_specifier(NULL),
       formal_parameter(false),
       is_void(false)
    {
@@ -648,8 +690,7 @@ public:
 
    ast_fully_specified_type *type;
    const char *identifier;
-   bool is_array;
-   ast_expression *array_size;
+   ast_array_specifier *array_specifier;
 
    static void parameters_to_hir(exec_list *ast_parameters,
                                 bool formal, exec_list *ir_parameters,
@@ -896,13 +937,10 @@ class ast_interface_block : public ast_node {
 public:
    ast_interface_block(ast_type_qualifier layout,
                        const char *instance_name,
-                       bool is_array,
-                       ast_expression *array_size)
+                       ast_array_specifier *array_specifier)
    : layout(layout), block_name(NULL), instance_name(instance_name),
-     is_array(is_array), array_size(array_size)
+     array_specifier(array_specifier)
    {
-      if (!is_array)
-         assert(array_size == NULL);
    }
 
    virtual ir_rvalue *hir(exec_list *instructions,
@@ -922,22 +960,13 @@ public:
    /** List of ast_declarator_list * */
    exec_list declarations;
 
-   /**
-    * True if the block is declared as an array
-    *
-    * \note
-    * A block can only be an array if it also has an instance name.  If this
-    * field is true, ::instance_name must also not be \c NULL.
-    */
-   bool is_array;
-
    /**
     * Declared array size of the block instance
     *
     * If the block is not declared as an array or if the block instance array
     * is unsized, this field will be \c NULL.
     */
-   ast_expression *array_size;
+   ast_array_specifier *array_specifier;
 };
 
 
@@ -978,9 +1007,8 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
                             YYLTYPE &loc, YYLTYPE &idx_loc);
 
 extern void
-_mesa_ast_set_aggregate_type(const ast_type_specifier *type,
-                             ast_expression *expr,
-                             _mesa_glsl_parse_state *state);
+_mesa_ast_set_aggregate_type(const glsl_type *type,
+                             ast_expression *expr);
 
 void
 emit_function(_mesa_glsl_parse_state *state, ir_function *f);