[gtk+/wip/otte/shader: 3/38] gsksltype: Turn gsk_sl_type_print() into gsk_sl_type_get_name()



commit 18fc88a0606fe9210ac903e04d70d624c27050b3
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 18 19:36:41 2017 +0200

    gsksltype: Turn gsk_sl_type_print() into gsk_sl_type_get_name()
    
    This way, we can use it in printf error messages way easier.
    
    Because of this, rework error messages to be more descriptive about types.

 gsk/gskslfunction.c    |    7 ++-
 gsk/gskslnode.c        |   75 +++++++++++------------
 gsk/gsksltype.c        |  159 +++++++++++++++++-------------------------------
 gsk/gsksltypeprivate.h |    6 +-
 4 files changed, 99 insertions(+), 148 deletions(-)
---
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index 111ba6e..bbff985 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -71,7 +71,7 @@ gsk_sl_function_constructor_print_name (GskSlFunction *function,
 {
   GskSlFunctionConstructor *constructor = (GskSlFunctionConstructor *) function;
 
-  gsk_sl_type_print (constructor->type, string);
+  g_string_append (string, gsk_sl_type_get_name (constructor->type));
 }
 
 
@@ -114,7 +114,10 @@ gsk_sl_function_constructor_matches (GskSlFunction  *function,
       provided = gsk_sl_function_builtin_get_args_by_type (arguments[i]);
       if (provided == 0)
         {
-          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Invalid type for constructor in argument 
%"G_GSIZE_FORMAT, i + 1);
+          g_set_error (error,
+                       G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                       "Invalid type %s for constructor in argument %"G_GSIZE_FORMAT,
+                       gsk_sl_type_get_name (arguments[i]), i + 1);
           return FALSE;
         }
 
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index 19b852f..22a4ba4 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -139,7 +139,7 @@ gsk_sl_node_function_print (GskSlNode *node,
   GskSlNodeFunction *function = (GskSlNodeFunction *) node;
   GSList *l;
 
-  gsk_sl_type_print (function->return_type, string);
+  g_string_append (string, gsk_sl_type_get_name (function->return_type));
   g_string_append (string, "\n");
 
   g_string_append (string, function->name);
@@ -372,11 +372,8 @@ gsk_sl_node_arithmetic_type_check (GskSlPreprocessor *stream,
     {
       if (stream)
         {
-          char *lstr = gsk_sl_type_to_string (ltype);
-          char *rstr = gsk_sl_type_to_string (rtype);
-          gsk_sl_preprocessor_error (stream, "Operand types %s and %s do not share compatible scalar 
types.", lstr, rstr);
-          g_free (lstr);
-          g_free (rstr);
+          gsk_sl_preprocessor_error (stream, "Operand types %s and %s do not share compatible scalar types.",
+                                             gsk_sl_type_get_name (ltype), gsk_sl_type_get_name (rtype));
         }
       return NULL;
     }
@@ -410,7 +407,8 @@ gsk_sl_node_arithmetic_type_check (GskSlPreprocessor *stream,
               else
                 {
                   if (stream)
-                    gsk_sl_preprocessor_error (stream, "Matrices to arithmetic operation have different 
size.");
+                    gsk_sl_preprocessor_error (stream, "Matrix types %s and %s have different size.",
+                                               gsk_sl_type_get_name (ltype), gsk_sl_type_get_name (rtype));
                   return NULL;
                 }
             }
@@ -456,7 +454,8 @@ gsk_sl_node_arithmetic_type_check (GskSlPreprocessor *stream,
               if (gsk_sl_type_get_length (ltype) != gsk_sl_type_get_length (gsk_sl_type_get_index_type 
(rtype)))
                 {
                   if (stream)
-                    gsk_sl_preprocessor_error (stream, "Vector length doesn't match matrix row count.");
+                    gsk_sl_preprocessor_error (stream, "Vector length for %s doesn't match row count for %s",
+                                                       gsk_sl_type_get_name (ltype), gsk_sl_type_get_name 
(rtype));
                   return NULL;
                 }
               return gsk_sl_type_get_vector (scalar, gsk_sl_type_get_length (rtype));
@@ -473,7 +472,8 @@ gsk_sl_node_arithmetic_type_check (GskSlPreprocessor *stream,
           if (gsk_sl_type_get_length (ltype) != gsk_sl_type_get_length (rtype))
             {
               if (stream)
-                gsk_sl_preprocessor_error (stream, "Vector operands to arithmetic operation have different 
length.");
+                gsk_sl_preprocessor_error (stream, "Vector operands %s and %s to arithmetic operation have 
different length.",
+                                                   gsk_sl_type_get_name (ltype), gsk_sl_type_get_name 
(rtype));
               return NULL;
             }
           return gsk_sl_type_get_vector (scalar, gsk_sl_type_get_length (ltype));
@@ -533,33 +533,34 @@ gsk_sl_node_bitwise_type_check (GskSlPreprocessor *stream,
   if (lscalar != GSK_SL_INT && lscalar != GSK_SL_UINT)
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Left operand is not an integer type.");
+        gsk_sl_preprocessor_error (stream, "Left operand %s is not an integer type.", gsk_sl_type_get_name 
(ltype));
       return NULL;
     }
   rscalar = gsk_sl_type_get_scalar_type (ltype);
   if (rscalar != GSK_SL_INT && rscalar != GSK_SL_UINT)
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Right operand is not an integer type.");
+        gsk_sl_preprocessor_error (stream, "Right operand %s is not an integer type.", gsk_sl_type_get_name 
(rtype));
       return NULL;
     }
   if (!gsk_sl_type_is_scalar (ltype) && !gsk_sl_type_is_vector (ltype))
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Left operand is neither a scalar nor a vector.");
+        gsk_sl_preprocessor_error (stream, "Left operand %s is neither a scalar nor a vector.", 
gsk_sl_type_get_name (ltype));
       return NULL;
     }
   if (!gsk_sl_type_is_scalar (rtype) && !gsk_sl_type_is_vector (rtype))
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Right operand is neither a scalar nor a vector.");
+        gsk_sl_preprocessor_error (stream, "Right operand %s is neither a scalar nor a vector.", 
gsk_sl_type_get_name (rtype));
       return NULL;
     }
   if (gsk_sl_type_is_vector (ltype) && gsk_sl_type_is_vector (rtype) &&
       gsk_sl_type_get_length (ltype) != gsk_sl_type_get_length (rtype))
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Vector operands do not have the same length.");
+        gsk_sl_preprocessor_error (stream, "Vector operands %s and %s do not have the same length.",
+                                           gsk_sl_type_get_name (ltype), gsk_sl_type_get_name (rtype));
       return NULL;
     }
 
@@ -581,26 +582,26 @@ gsk_sl_node_shift_type_check (GskSlPreprocessor *stream,
   if (lscalar != GSK_SL_INT && lscalar != GSK_SL_UINT)
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Left operand is not an integer type.");
+        gsk_sl_preprocessor_error (stream, "Left operand %s is not an integer type.", gsk_sl_type_get_name 
(ltype));
       return FALSE;
     }
   rscalar = gsk_sl_type_get_scalar_type (ltype);
   if (rscalar != GSK_SL_INT && rscalar != GSK_SL_UINT)
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Right operand is not an integer type.");
+        gsk_sl_preprocessor_error (stream, "Right operand %s is not an integer type.", gsk_sl_type_get_name 
(rtype));
       return FALSE;
     }
   if (!gsk_sl_type_is_scalar (ltype) && !gsk_sl_type_is_vector (ltype))
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Left operand is neither a scalar nor a vector.");
+        gsk_sl_preprocessor_error (stream, "Left operand %s is neither a scalar nor a vector.", 
gsk_sl_type_get_name (ltype));
       return FALSE;
     }
   if (!gsk_sl_type_is_scalar (rtype) && !gsk_sl_type_is_vector (rtype))
     {
       if (stream)
-        gsk_sl_preprocessor_error (stream, "Right operand is neither a scalar nor a vector.");
+        gsk_sl_preprocessor_error (stream, "Right operand %s is neither a scalar nor a vector.", 
gsk_sl_type_get_name (rtype));
       return FALSE;
     }
   if (gsk_sl_type_is_scalar (ltype) && gsk_sl_type_is_vector (rtype))
@@ -747,7 +748,7 @@ gsk_sl_node_declaration_print (GskSlNode *node,
 {
   GskSlNodeDeclaration *declaration = (GskSlNodeDeclaration *) node;
 
-  gsk_sl_type_print (declaration->type, string);
+  g_string_append (string, gsk_sl_type_get_name (declaration->type));
   if (declaration->name)
     {
       g_string_append (string, " ");
@@ -1757,18 +1758,16 @@ gsk_sl_node_parse_logical_and_expression (GskSlNodeProgram  *program,
       else if (!gsk_sl_type_can_convert (gsk_sl_type_get_scalar (GSK_SL_BOOL),
                                          gsk_sl_node_get_return_type (operation->right)))
         {
-          char *type_name = gsk_sl_type_to_string (gsk_sl_node_get_return_type (operation->right));
-          gsk_sl_preprocessor_error (stream, "Right operand of && expression is not bool but %s", type_name);
-          g_free (type_name);
+          gsk_sl_preprocessor_error (stream, "Right operand of && expression is not bool but %s",
+                                             gsk_sl_type_get_name (gsk_sl_node_get_return_type 
(operation->right)));
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
       else if (!gsk_sl_type_can_convert (gsk_sl_type_get_scalar (GSK_SL_BOOL),
                                          gsk_sl_node_get_return_type (node)))
         {
-          char *type_name = gsk_sl_type_to_string (gsk_sl_node_get_return_type (node));
-          gsk_sl_preprocessor_error (stream, "Left operand of && expression is not bool but %s", type_name);
-          g_free (type_name);
+          gsk_sl_preprocessor_error (stream, "Left operand of && expression is not bool but %s",
+                                             gsk_sl_type_get_name (gsk_sl_node_get_return_type (node)));
           node = operation->right;
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
@@ -1814,18 +1813,16 @@ gsk_sl_node_parse_logical_xor_expression (GskSlNodeProgram  *program,
       else if (!gsk_sl_type_can_convert (gsk_sl_type_get_scalar (GSK_SL_BOOL),
                                          gsk_sl_node_get_return_type (operation->right)))
         {
-          char *type_name = gsk_sl_type_to_string (gsk_sl_node_get_return_type (operation->right));
-          gsk_sl_preprocessor_error (stream, "Right operand of || expression is not bool but %s", type_name);
-          g_free (type_name);
+          gsk_sl_preprocessor_error (stream, "Right operand of ^^ expression is not bool but %s",
+                                             gsk_sl_type_get_name (gsk_sl_node_get_return_type 
(operation->right)));
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
       else if (!gsk_sl_type_can_convert (gsk_sl_type_get_scalar (GSK_SL_BOOL),
                                          gsk_sl_node_get_return_type (node)))
         {
-          char *type_name = gsk_sl_type_to_string (gsk_sl_node_get_return_type (node));
-          gsk_sl_preprocessor_error (stream, "Left operand of || expression is not bool but %s", type_name);
-          g_free (type_name);
+          gsk_sl_preprocessor_error (stream, "Left operand of ^^ expression is not bool but %s",
+                                             gsk_sl_type_get_name (gsk_sl_node_get_return_type (node)));
           node = operation->right;
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
@@ -1871,18 +1868,16 @@ gsk_sl_node_parse_logical_or_expression (GskSlNodeProgram  *program,
       else if (!gsk_sl_type_can_convert (gsk_sl_type_get_scalar (GSK_SL_BOOL),
                                          gsk_sl_node_get_return_type (operation->right)))
         {
-          char *type_name = gsk_sl_type_to_string (gsk_sl_node_get_return_type (operation->right));
-          gsk_sl_preprocessor_error (stream, "Right operand of ^^ expression is not bool but %s", type_name);
-          g_free (type_name);
+          gsk_sl_preprocessor_error (stream, "Right operand of || expression is not bool but %s",
+                                             gsk_sl_type_get_name (gsk_sl_node_get_return_type 
(operation->right)));
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
       else if (!gsk_sl_type_can_convert (gsk_sl_type_get_scalar (GSK_SL_BOOL),
                                          gsk_sl_node_get_return_type (node)))
         {
-          char *type_name = gsk_sl_type_to_string (gsk_sl_node_get_return_type (node));
-          gsk_sl_preprocessor_error (stream, "Left operand of ^^ expression is not bool but %s", type_name);
-          g_free (type_name);
+          gsk_sl_preprocessor_error (stream, "Left operand of || expression is not bool but %s",
+                                             gsk_sl_type_get_name (gsk_sl_node_get_return_type (node)));
           node = operation->right;
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
@@ -1940,7 +1935,7 @@ gsk_sl_node_parse_assignment_expression (GskSlNodeProgram  *program,
 
   if (gsk_sl_node_is_constant (lvalue))
     {
-      gsk_sl_preprocessor_error (stream, "Cannot assign to a constant lvalue.");
+      gsk_sl_preprocessor_error (stream, "Cannot assign to a return lvalue.");
 
       /* Continue parsing like normal here to get more errors */
       gsk_sl_preprocessor_consume (stream, lvalue);
@@ -2143,7 +2138,9 @@ gsk_sl_node_parse_function_definition (GskSlNodeProgram  *program,
                 }
               else if (!gsk_sl_type_can_convert (function->return_type, gsk_sl_node_get_return_type 
(return_node->value)))
                 {
-                  gsk_sl_preprocessor_error (stream, "Cannot convert return type to function type.");
+                  gsk_sl_preprocessor_error (stream, "Cannot convert return type %s to function type %s.",
+                                                     gsk_sl_type_get_name (gsk_sl_node_get_return_type 
(return_node->value)),
+                                                     gsk_sl_type_get_name (function->return_type));
                   gsk_sl_node_unref ((GskSlNode *) return_node);
                   break;
                 }
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index 5184fe5..70fb138 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -39,8 +39,7 @@ struct _GskSlType
 struct _GskSlTypeClass {
   void                  (* free)                                (GskSlType           *type);
 
-  void                  (* print)                               (GskSlType           *type,
-                                                                 GString             *string);
+  const char *          (* get_name)                            (GskSlType           *type);
   GskSlScalarType       (* get_scalar_type)                     (GskSlType           *type);
   GskSlType *           (* get_index_type)                      (GskSlType           *type);
   guint                 (* get_length)                          (GskSlType           *type);
@@ -64,32 +63,25 @@ gsk_sl_type_scalar_free (GskSlType *type)
   g_assert_not_reached ();
 }
 
-static void
-gsk_sl_type_scalar_print (GskSlType *type,
-                          GString   *string)
+static const char *
+gsk_sl_type_scalar_get_name (GskSlType *type)
 {
   GskSlTypeScalar *scalar = (GskSlTypeScalar *) type;
 
   switch (scalar->scalar)
   {
     case GSK_SL_VOID:
-      g_string_append (string, "void");
-      break;
+      return "void";
     case GSK_SL_FLOAT:
-      g_string_append (string, "float");
-      break;
+      return "float";
     case GSK_SL_DOUBLE:
-      g_string_append (string, "double");
-      break;
+      return "double";
     case GSK_SL_INT:
-      g_string_append (string, "int");
-      break;
+      return "int";
     case GSK_SL_UINT:
-      g_string_append (string, "uint");
-      break;
+      return "uint";
     case GSK_SL_BOOL:
-      g_string_append (string, "bool");
-      break;
+      return "bool";
     default:
       g_assert_not_reached ();
       break;
@@ -131,7 +123,7 @@ gsk_sl_type_scalar_can_convert (GskSlType *target,
 
 static const GskSlTypeClass GSK_SL_TYPE_SCALAR = {
   gsk_sl_type_scalar_free,
-  gsk_sl_type_scalar_print,
+  gsk_sl_type_scalar_get_name,
   gsk_sl_type_scalar_get_scalar_type,
   gsk_sl_type_scalar_get_index_type,
   gsk_sl_type_scalar_get_length,
@@ -145,6 +137,7 @@ typedef struct _GskSlTypeVector GskSlTypeVector;
 struct _GskSlTypeVector {
   GskSlType parent;
 
+  const char *name;
   GskSlScalarType scalar;
   guint length;
 };
@@ -155,36 +148,12 @@ gsk_sl_type_vector_free (GskSlType *type)
   g_assert_not_reached ();
 }
 
-static void
-gsk_sl_type_vector_print (GskSlType *type,
-                          GString   *string)
+static const char *
+gsk_sl_type_vector_get_name (GskSlType *type)
 {
   GskSlTypeVector *vector = (GskSlTypeVector *) type;
 
-  switch (vector->scalar)
-  {
-    case GSK_SL_FLOAT:
-      g_string_append (string, "vec");
-      break;
-    case GSK_SL_DOUBLE:
-      g_string_append (string, "dvec");
-      break;
-    case GSK_SL_INT:
-      g_string_append (string, "ivec");
-      break;
-    case GSK_SL_UINT:
-      g_string_append (string, "uvec");
-      break;
-    case GSK_SL_BOOL:
-      g_string_append (string, "bvec");
-      break;
-    case GSK_SL_VOID:
-    default:
-      g_assert_not_reached ();
-      break;
-  }
-
-  g_string_append_printf (string, "%u", vector->length);
+  return vector->name;
 }
 
 static GskSlScalarType
@@ -229,7 +198,7 @@ gsk_sl_type_vector_can_convert (GskSlType *target,
 
 static const GskSlTypeClass GSK_SL_TYPE_VECTOR = {
   gsk_sl_type_vector_free,
-  gsk_sl_type_vector_print,
+  gsk_sl_type_vector_get_name,
   gsk_sl_type_vector_get_scalar_type,
   gsk_sl_type_vector_get_index_type,
   gsk_sl_type_vector_get_length,
@@ -243,6 +212,7 @@ typedef struct _GskSlTypeMatrix GskSlTypeMatrix;
 struct _GskSlTypeMatrix {
   GskSlType parent;
 
+  const char *name;
   GskSlScalarType scalar;
   guint columns;
   guint rows;
@@ -254,18 +224,12 @@ gsk_sl_type_matrix_free (GskSlType *type)
   g_assert_not_reached ();
 }
 
-static void
-gsk_sl_type_matrix_print (GskSlType *type,
-                          GString   *string)
+static const char *
+gsk_sl_type_matrix_get_name (GskSlType *type)
 {
   GskSlTypeMatrix *matrix = (GskSlTypeMatrix *) type;
 
-  g_string_append (string, matrix->scalar == GSK_SL_DOUBLE ? "dmat" : "mat");
-  g_string_append_printf (string, "%u", matrix->columns);
-  if (matrix->columns != matrix->rows)
-    {
-      g_string_append_printf (string, "x%u", matrix->rows);
-    }
+  return matrix->name;
 }
 
 static GskSlScalarType
@@ -311,7 +275,7 @@ gsk_sl_type_matrix_can_convert (GskSlType *target,
 
 static const GskSlTypeClass GSK_SL_TYPE_MATRIX = {
   gsk_sl_type_matrix_free,
-  gsk_sl_type_matrix_print,
+  gsk_sl_type_matrix_get_name,
   gsk_sl_type_matrix_get_scalar_type,
   gsk_sl_type_matrix_get_index_type,
   gsk_sl_type_matrix_get_length,
@@ -482,25 +446,25 @@ gsk_sl_type_get_scalar (GskSlScalarType scalar)
 static GskSlTypeVector
 builtin_vector_types[3][N_SCALAR_TYPES] = {
   {
-    [GSK_SL_FLOAT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_FLOAT, 2 },
-    [GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_DOUBLE, 2 },
-    [GSK_SL_INT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_INT, 2 },
-    [GSK_SL_UINT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_UINT, 2 },
-    [GSK_SL_BOOL] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_BOOL, 2 },
+    [GSK_SL_FLOAT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "vec2", GSK_SL_FLOAT, 2 },
+    [GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_VECTOR, 1 }, "dvec2", GSK_SL_DOUBLE, 2 },
+    [GSK_SL_INT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "ivec2", GSK_SL_INT, 2 },
+    [GSK_SL_UINT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "uvec2", GSK_SL_UINT, 2 },
+    [GSK_SL_BOOL] = { { &GSK_SL_TYPE_VECTOR, 1 }, "bvec2", GSK_SL_BOOL, 2 },
   },
   {
-    [GSK_SL_FLOAT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_FLOAT, 3 },
-    [GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_DOUBLE, 3 },
-    [GSK_SL_INT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_INT, 3 },
-    [GSK_SL_UINT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_UINT, 3 },
-    [GSK_SL_BOOL] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_BOOL, 3 },
+    [GSK_SL_FLOAT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "vec3", GSK_SL_FLOAT, 3 },
+    [GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_VECTOR, 1 }, "dvec3", GSK_SL_DOUBLE, 3 },
+    [GSK_SL_INT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "ivec3", GSK_SL_INT, 3 },
+    [GSK_SL_UINT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "uvec3", GSK_SL_UINT, 3 },
+    [GSK_SL_BOOL] = { { &GSK_SL_TYPE_VECTOR, 1 }, "bvec3", GSK_SL_BOOL, 3 },
   },
   {
-    [GSK_SL_FLOAT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_FLOAT, 4 },
-    [GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_DOUBLE, 4 },
-    [GSK_SL_INT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_INT, 4 },
-    [GSK_SL_UINT] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_UINT, 4 },
-    [GSK_SL_BOOL] = { { &GSK_SL_TYPE_VECTOR, 1 }, GSK_SL_BOOL, 4 },
+    [GSK_SL_FLOAT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "vec4", GSK_SL_FLOAT, 4 },
+    [GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_VECTOR, 1 }, "dvec4", GSK_SL_DOUBLE, 4 },
+    [GSK_SL_INT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "ivec4", GSK_SL_INT, 4 },
+    [GSK_SL_UINT] = { { &GSK_SL_TYPE_VECTOR, 1 }, "uvec4", GSK_SL_UINT, 4 },
+    [GSK_SL_BOOL] = { { &GSK_SL_TYPE_VECTOR, 1 }, "bvec4", GSK_SL_BOOL, 4 },
   }
 };
 
@@ -519,44 +483,44 @@ static GskSlTypeMatrix
 builtin_matrix_types[3][3][2] = {
   {
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 2, 2 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 2, 2 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat2",    GSK_SL_FLOAT,  2, 2 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat2",   GSK_SL_DOUBLE, 2, 2 }
     },
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 2, 3 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 2, 3 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat2x3",  GSK_SL_FLOAT,  2, 3 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat2x3", GSK_SL_DOUBLE, 2, 3 }
     },
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 2, 4 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 2, 4 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat2x4",  GSK_SL_FLOAT,  2, 4 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat2x4", GSK_SL_DOUBLE, 2, 4 }
     },
   },
   {
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 3, 2 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 3, 2 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat3x2",  GSK_SL_FLOAT,  3, 2 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat3x2", GSK_SL_DOUBLE, 3, 2 }
     },
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 3, 3 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 3, 3 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat3",    GSK_SL_FLOAT,  3, 3 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat3",   GSK_SL_DOUBLE, 3, 3 }
     },
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 3, 4 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 3, 4 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat3x4",  GSK_SL_FLOAT,  3, 4 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat3x4", GSK_SL_DOUBLE, 3, 4 }
     },
   },
   {
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 4, 2 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 4, 2 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat4x2",  GSK_SL_FLOAT,  4, 2 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat4x2", GSK_SL_DOUBLE, 4, 2 }
     },
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 4, 3 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 4, 3 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat4x3",  GSK_SL_FLOAT,  4, 3 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat4x3", GSK_SL_DOUBLE, 4, 3 }
     },
     {
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_FLOAT, 4, 4 },
-      { { &GSK_SL_TYPE_MATRIX, 1 }, GSK_SL_DOUBLE, 4, 4 }
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "mat4",    GSK_SL_FLOAT,  4, 4 },
+      { { &GSK_SL_TYPE_MATRIX, 1 }, "dmat4",   GSK_SL_DOUBLE, 4, 4 }
     },
   },
 };
@@ -596,21 +560,10 @@ gsk_sl_type_unref (GskSlType *type)
   g_assert_not_reached ();
 }
 
-void
-gsk_sl_type_print (const GskSlType *type,
-                   GString         *string)
-{
-  return type->class->print (type, string);
-}
-
-char *
-gsk_sl_type_to_string (const GskSlType *type)
+const char *
+gsk_sl_type_get_name (const GskSlType *type)
 {
-  GString *string;
-
-  string = g_string_new (NULL);
-  gsk_sl_type_print (type, string);
-  return g_string_free (string, FALSE);
+  return type->class->get_name (type);
 }
 
 gboolean
diff --git a/gsk/gsksltypeprivate.h b/gsk/gsksltypeprivate.h
index d522e1b..3fd84c3 100644
--- a/gsk/gsksltypeprivate.h
+++ b/gsk/gsksltypeprivate.h
@@ -45,13 +45,11 @@ GskSlType *             gsk_sl_type_get_matrix                  (GskSlScalarType
 GskSlType *             gsk_sl_type_ref                         (GskSlType           *type);
 void                    gsk_sl_type_unref                       (GskSlType           *type);
 
-void                    gsk_sl_type_print                       (const GskSlType     *type,
-                                                                 GString             *string);
-char *                  gsk_sl_type_to_string                   (const GskSlType     *type);
-
 gboolean                gsk_sl_type_is_scalar                   (const GskSlType     *type);
 gboolean                gsk_sl_type_is_vector                   (const GskSlType     *type);
 gboolean                gsk_sl_type_is_matrix                   (const GskSlType     *type);
+
+const char *            gsk_sl_type_get_name                    (const GskSlType     *type);
 GskSlScalarType         gsk_sl_type_get_scalar_type             (const GskSlType     *type);
 GskSlType *             gsk_sl_type_get_index_type              (const GskSlType     *type);
 guint                   gsk_sl_type_get_length                  (const GskSlType     *type);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]