dri2: Hard-code the DRI2 version
[mesa.git] / src / glsl / ast.h
index 878f48b20706613373c7959c998c499559ecf616..4438b85bbdafb6db037eaca4c4dd5396cc5895f0 100644 (file)
@@ -206,7 +206,8 @@ public:
       subexpressions[0] = NULL;
       subexpressions[1] = NULL;
       subexpressions[2] = NULL;
-      primary_expression.identifier = (char *) identifier;
+      primary_expression.identifier = identifier;
+      this->non_lvalue_description = NULL;
    }
 
    static const char *operator_string(enum ast_operators op);
@@ -221,7 +222,7 @@ public:
    ast_expression *subexpressions[3];
 
    union {
-      char *identifier;
+      const char *identifier;
       int int_constant;
       float float_constant;
       unsigned uint_constant;
@@ -234,6 +235,18 @@ public:
     * \c ast_function_call
     */
    exec_list expressions;
+
+   /**
+    * For things that can't be l-values, this describes what it is.
+    *
+    * This text is used by the code that generates IR for assignments to
+    * detect and emit useful messages for assignments to some things that
+    * can't be l-values.  For example, pre- or post-incerement expressions.
+    *
+    * \note
+    * This pointer may be \c NULL.
+    */
+   const char *non_lvalue_description;
 };
 
 class ast_expression_bin : public ast_expression {
@@ -304,11 +317,11 @@ public:
 
 class ast_declaration : public ast_node {
 public:
-   ast_declaration(char *identifier, int is_array, ast_expression *array_size,
+   ast_declaration(const char *identifier, int is_array, ast_expression *array_size,
                   ast_expression *initializer);
    virtual void print(void) const;
 
-   char *identifier;
+   const char *identifier;
    
    int is_array;
    ast_expression *array_size;
@@ -350,6 +363,11 @@ struct ast_type_qualifier {
          * qualifier is used.
          */
         unsigned explicit_location:1;
+        /**
+         * Flag set if GL_ARB_explicit_attrib_location "index" layout
+         * qualifier is used.
+         */
+        unsigned explicit_index:1;
 
          /** \name Layout qualifiers for GL_AMD_conservative_depth */
          /** \{ */
@@ -358,6 +376,15 @@ struct ast_type_qualifier {
          unsigned depth_less:1;
          unsigned depth_unchanged:1;
          /** \} */
+
+        /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
+        /** \{ */
+         unsigned std140:1;
+         unsigned shared:1;
+         unsigned packed:1;
+         unsigned column_major:1;
+         unsigned row_major:1;
+        /** \} */
       }
       /** \brief Set of flags, accessed by name. */
       q;
@@ -372,7 +399,14 @@ struct ast_type_qualifier {
     * \note
     * This field is only valid if \c explicit_location is set.
     */
-   unsigned location;
+   int location;
+   /**
+    * Index specified via GL_ARB_explicit_attrib_location layout
+    *
+    * \note
+    * This field is only valid if \c explicit_index is set.
+    */
+   int index;
 
    /**
     * Return true if and only if an interpolation qualifier is present.
@@ -392,84 +426,29 @@ struct ast_type_qualifier {
    const char *interpolation_string() const;
 };
 
+class ast_declarator_list;
+
 class ast_struct_specifier : public ast_node {
 public:
-   ast_struct_specifier(char *identifier, ast_node *declarator_list);
+   ast_struct_specifier(const char *identifier,
+                       ast_declarator_list *declarator_list);
    virtual void print(void) const;
 
    virtual ir_rvalue *hir(exec_list *instructions,
                          struct _mesa_glsl_parse_state *state);
 
-   char *name;
+   const char *name;
+   /* List of ast_declarator_list * */
    exec_list declarations;
 };
 
 
-enum ast_types {
-   ast_void,
-   ast_float,
-   ast_int,
-   ast_uint,
-   ast_bool,
-   ast_vec2,
-   ast_vec3,
-   ast_vec4,
-   ast_bvec2,
-   ast_bvec3,
-   ast_bvec4,
-   ast_ivec2,
-   ast_ivec3,
-   ast_ivec4,
-   ast_uvec2,
-   ast_uvec3,
-   ast_uvec4,
-   ast_mat2,
-   ast_mat2x3,
-   ast_mat2x4,
-   ast_mat3x2,
-   ast_mat3,
-   ast_mat3x4,
-   ast_mat4x2,
-   ast_mat4x3,
-   ast_mat4,
-   ast_sampler1d,
-   ast_sampler2d,
-   ast_sampler2drect,
-   ast_sampler3d,
-   ast_samplercube,
-   ast_sampler1dshadow,
-   ast_sampler2dshadow,
-   ast_sampler2drectshadow,
-   ast_samplercubeshadow,
-   ast_sampler1darray,
-   ast_sampler2darray,
-   ast_sampler1darrayshadow,
-   ast_sampler2darrayshadow,
-   ast_isampler1d,
-   ast_isampler2d,
-   ast_isampler3d,
-   ast_isamplercube,
-   ast_isampler1darray,
-   ast_isampler2darray,
-   ast_usampler1d,
-   ast_usampler2d,
-   ast_usampler3d,
-   ast_usamplercube,
-   ast_usampler1darray,
-   ast_usampler2darray,
-
-   ast_struct,
-   ast_type_name
-};
-
 
 class ast_type_specifier : public ast_node {
 public:
-   ast_type_specifier(int specifier);
-
    /** Construct a type specifier from a type name */
    ast_type_specifier(const char *name) 
-      : type_specifier(ast_type_name), type_name(name), structure(NULL),
+      : type_name(name), structure(NULL),
        is_array(false), array_size(NULL), precision(ast_precision_none),
        is_precision_statement(false)
    {
@@ -478,7 +457,7 @@ public:
 
    /** Construct a type specifier from a structure definition */
    ast_type_specifier(ast_struct_specifier *s)
-      : type_specifier(ast_struct), type_name(s->name), structure(s),
+      : type_name(s->name), structure(s),
        is_array(false), array_size(NULL), precision(ast_precision_none),
        is_precision_statement(false)
    {
@@ -493,8 +472,6 @@ public:
 
    ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
 
-   enum ast_types type_specifier;
-
    const char *type_name;
    ast_struct_specifier *structure;
 
@@ -554,7 +531,7 @@ public:
                          struct _mesa_glsl_parse_state *state);
 
    ast_fully_specified_type *type;
-   char *identifier;
+   const char *identifier;
    int is_array;
    ast_expression *array_size;
 
@@ -585,7 +562,7 @@ public:
                          struct _mesa_glsl_parse_state *state);
 
    ast_fully_specified_type *return_type;
-   char *identifier;
+   const char *identifier;
 
    exec_list parameters;
 
@@ -628,13 +605,78 @@ public:
 
 class ast_case_label : public ast_node {
 public:
+   ast_case_label(ast_expression *test_value);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   /**
+    * An test value of NULL means 'default'.
+    */
+   ast_expression *test_value;
+};
+
+
+class ast_case_label_list : public ast_node {
+public:
+   ast_case_label_list(void);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
 
    /**
-    * An expression of NULL means 'default'.
+    * A list of case labels.
     */
-   ast_expression *expression;
+   exec_list labels;
+};
+
+
+class ast_case_statement : public ast_node {
+public:
+   ast_case_statement(ast_case_label_list *labels);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_case_label_list *labels;
+
+   /**
+    * A list of statements.
+    */
+   exec_list stmts;
+};
+
+
+class ast_case_statement_list : public ast_node {
+public:
+   ast_case_statement_list(void);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   /**
+    * A list of cases.
+    */
+   exec_list cases;
+};
+
+
+class ast_switch_body : public ast_node {
+public:
+   ast_switch_body(ast_case_statement_list *stmts);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_case_statement_list *stmts;
 };
 
+
 class ast_selection_statement : public ast_node {
 public:
    ast_selection_statement(ast_expression *condition,
@@ -653,8 +695,18 @@ public:
 
 class ast_switch_statement : public ast_node {
 public:
-   ast_expression *expression;
-   exec_list statements;
+   ast_switch_statement(ast_expression *test_expression,
+                       ast_node *body);
+   virtual void print(void) const;
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_expression *test_expression;
+   ast_node *body;
+
+protected:
+   void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
 };
 
 class ast_iteration_statement : public ast_node {
@@ -719,6 +771,25 @@ public:
    ast_function *prototype;
    ast_compound_statement *body;
 };
+
+class ast_uniform_block : public ast_node {
+public:
+   ast_uniform_block(ast_type_qualifier layout,
+                    const char *block_name,
+                    ast_declarator_list *member_list)
+   : layout(layout), block_name(block_name)
+   {
+      declarations.push_degenerate_list_at_head(&member_list->link);
+   }
+
+   virtual ir_rvalue *hir(exec_list *instructions,
+                         struct _mesa_glsl_parse_state *state);
+
+   ast_type_qualifier layout;
+   const char *block_name;
+   /** List of ast_declarator_list * */
+   exec_list declarations;
+};
 /*@}*/
 
 extern void
@@ -730,7 +801,6 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
                                 struct _mesa_glsl_parse_state *state);
 
 void
-emit_function(_mesa_glsl_parse_state *state, exec_list *instructions,
-             ir_function *f);
+emit_function(_mesa_glsl_parse_state *state, ir_function *f);
 
 #endif /* AST_H */