Change type of function_identifier to silence bison warning
[mesa.git] / glsl_types.h
index c69da9562249d2a54d8b88f5ccb471f195bbb2ec..45037b37869b74ac0a65aa3bad99bf762d76bd90 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- c++ -*- */
 /*
  * Copyright © 2009 Intel Corporation
  *
@@ -25,6 +26,8 @@
 #ifndef GLSL_TYPES_H
 #define GLSL_TYPES_H
 
+#include <cstring>
+
 #define GLSL_TYPE_UINT          0
 #define GLSL_TYPE_INT           1
 #define GLSL_TYPE_FLOAT         2
 
 #define is_error_type(t) ((t)->base_type == GLSL_TYPE_ERROR)
 
-#define GLSL_SAMPLER_DIM_1D     0
-#define GLSL_SAMPLER_DIM_2D     1
-#define GLSL_SAMPLER_DIM_3D     2
-#define GLSL_SAMPLER_DIM_CUBE   3
-#define GLSL_SAMPLER_DIM_RECT   4
-#define GLSL_SAMPLER_DIM_BUF    5
+enum glsl_sampler_dim {
+   GLSL_SAMPLER_DIM_1D = 0,
+   GLSL_SAMPLER_DIM_2D,
+   GLSL_SAMPLER_DIM_3D,
+   GLSL_SAMPLER_DIM_CUBE,
+   GLSL_SAMPLER_DIM_RECT,
+   GLSL_SAMPLER_DIM_BUF
+};
 
 
 struct glsl_type {
@@ -94,22 +99,74 @@ struct glsl_type {
       const struct glsl_type *parameters;       /**< Parameters to function. */
       const struct glsl_struct_field *structure;/**< List of struct fields. */
    } fields;
-};
 
-#define is_glsl_type_scalar(t)                 \
-   (((t)->vector_elements == 0)                        \
-    && ((t)->base_type >= GLSL_TYPE_UINT)      \
-    && ((t)->base_type <= GLSL_TYPE_BOOL))
 
-#define is_glsl_type_vector(t)                 \
-   (((t)->vector_elements > 0)                 \
-    && ((t)->matrix_rows == 0)                 \
-    && ((t)->base_type >= GLSL_TYPE_UINT)      \
-    && ((t)->base_type <= GLSL_TYPE_BOOL))
+   glsl_type(unsigned base_type, unsigned vector_elements,
+            unsigned matrix_rows, const char *name) :
+      base_type(base_type), 
+      sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+      sampler_type(0),
+      vector_elements(vector_elements), matrix_rows(matrix_rows),
+      name(name),
+      length(0)
+   {
+      memset(& fields, 0, sizeof(fields));
+   }
+
+   glsl_type(enum glsl_sampler_dim dim, bool shadow, bool array,
+            unsigned type, const char *name) :
+      base_type(GLSL_TYPE_SAMPLER),
+      sampler_dimensionality(dim), sampler_shadow(shadow),
+      sampler_array(array), sampler_type(type),
+      vector_elements(0), matrix_rows(0),
+      name(name),
+      length(0)
+   {
+      memset(& fields, 0, sizeof(fields));
+   }
+
+   glsl_type(const glsl_struct_field *fields, unsigned num_fields,
+            const char *name) :
+      base_type(GLSL_TYPE_STRUCT),
+      sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+      sampler_type(0),
+      vector_elements(0), matrix_rows(0),
+      name(name),
+      length(num_fields)
+   {
+      this->fields.structure = fields;
+   }
+
+   /**
+    * Query whether or not a type is a scalar (non-vector and non-matrix).
+    */
+   bool is_scalar() const
+   {
+      return (vector_elements == 0)
+        && (base_type >= GLSL_TYPE_UINT)
+        && (base_type <= GLSL_TYPE_BOOL);
+   }
+
+   /**
+    * Query whether or not a type is a vector
+    */
+   bool is_vector() const
+   {
+      return (vector_elements > 0)
+        && (matrix_rows == 0)
+        && (base_type >= GLSL_TYPE_UINT)
+        && (base_type <= GLSL_TYPE_BOOL);
+   }
 
-#define is_glsl_type_matrix(t)                 \
-   (((t)->matrix_rows > 0)                     \
-    && ((t)->base_type == GLSL_TYPE_FLOAT)) /* GLSL only has float matrices. */
+   /**
+    * Query whether or not a type is a matrix
+    */
+   bool is_matrix() const
+   {
+      /* GLSL only has float matrices. */
+      return (matrix_rows > 0) && (base_type == GLSL_TYPE_FLOAT);
+   }
+};
 
 struct glsl_struct_field {
    const struct glsl_type *type;