[gtk+/wip/otte/shader: 86/175] gskslnode: Parse return statements



commit f26662b8119e26223923284bf9168e608b7bd2c9
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 18 18:39:50 2017 +0200

    gskslnode: Parse return statements

 gsk/gskslfunction.c    |    7 ++-
 gsk/gskslnode.c        |  178 +++++++++++++++++++++++++++++++++++++----------
 gsk/gsksltype.c        |  163 ++++++++++++++++----------------------------
 gsk/gsksltypeprivate.h |    6 +-
 4 files changed, 205 insertions(+), 149 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 24e484d..9b27ed1 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, " ");
@@ -907,6 +908,70 @@ static const GskSlNodeClass GSK_SL_NODE_FUNCTION_CALL = {
   gsk_sl_node_function_call_is_constant
 };
 
+/* RETURN */
+
+typedef struct _GskSlNodeReturn GskSlNodeReturn;
+
+struct _GskSlNodeReturn {
+  GskSlNode parent;
+
+  GskSlNode *value;
+};
+
+static void
+gsk_sl_node_return_free (GskSlNode *node)
+{
+  GskSlNodeReturn *return_node = (GskSlNodeReturn *) node;
+
+  if (return_node->value)
+    gsk_sl_node_unref (return_node->value);
+
+  g_slice_free (GskSlNodeReturn, return_node);
+}
+
+static void
+gsk_sl_node_return_print (GskSlNode *node,
+                          GString   *string)
+{
+  GskSlNodeReturn *return_node = (GskSlNodeReturn *) node;
+
+  g_string_append (string, "return");
+  if (return_node->value)
+    {
+      g_string_append (string, " ");
+      gsk_sl_node_print (return_node->value, string);
+    }
+}
+
+static GskSlType *
+gsk_sl_node_return_get_return_type (GskSlNode *node)
+{
+  GskSlNodeReturn *return_node = (GskSlNodeReturn *) node;
+
+  if (return_node->value)
+    return gsk_sl_node_get_return_type (return_node->value);
+  else
+    return NULL;
+}
+
+static gboolean
+gsk_sl_node_return_is_constant (GskSlNode *node)
+{
+  GskSlNodeReturn *return_node = (GskSlNodeReturn *) node;
+
+  if (return_node->value)
+    return gsk_sl_node_is_constant (return_node->value);
+  else
+    return TRUE;
+}
+
+static const GskSlNodeClass GSK_SL_NODE_RETURN = {
+  gsk_sl_node_return_free,
+  gsk_sl_node_return_print,
+  gsk_sl_node_return_get_return_type,
+  gsk_sl_node_return_is_constant
+};
+
 /* CONSTANT */
 
 typedef struct _GskSlNodeConstant GskSlNodeConstant;
@@ -1694,18 +1759,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);
@@ -1751,18 +1814,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);
@@ -1808,18 +1869,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);
@@ -1877,7 +1936,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);
@@ -2057,6 +2116,49 @@ gsk_sl_node_parse_function_definition (GskSlNodeProgram  *program,
         }
         break;
 
+      case GSK_SL_TOKEN_RETURN:
+        {
+          GskSlNodeReturn *return_node;
+
+          return_node = gsk_sl_node_new (GskSlNodeReturn, &GSK_SL_NODE_RETURN);
+          gsk_sl_preprocessor_consume (stream, (GskSlNode *) return_node);
+          token = gsk_sl_preprocessor_get (stream);
+          if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
+            {
+              return_node->value = gsk_sl_node_parse_expression (program, function->scope, stream);
+              if (return_node->value == NULL)
+                {
+                  gsk_sl_node_unref ((GskSlNode *) return_node);
+                  break;
+                }
+              if (function->return_type == NULL)
+                {
+                  gsk_sl_preprocessor_error (stream, "Cannot return a value from a void function.");
+                  gsk_sl_node_unref ((GskSlNode *) return_node);
+                  break;
+                }
+              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 %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;
+                }
+              }
+            else
+              {
+                if (function->return_type != NULL)
+                  {
+                    gsk_sl_preprocessor_error (stream, "Return statement does not return a value.");
+                    gsk_sl_node_unref ((GskSlNode *) return_node);
+                    break;
+                  }
+              }
+            function->statements = g_slist_append (function->statements, return_node);
+          }
+        break;
+
       default:
         node = gsk_sl_node_parse_expression (program, function->scope, stream);
         if (node)
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index ffa1511..b295872 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -39,8 +39,7 @@ struct _GskSlType
 struct _GskSlTypeClass {
   void                  (* free)                                (GskSlType           *type);
 
-  void                  (* print)                               (const GskSlType     *type,
-                                                                 GString             *string);
+  const char *          (* get_name)                            (const GskSlType     *type);
   GskSlScalarType       (* get_scalar_type)                     (const GskSlType     *type);
   GskSlType *           (* get_index_type)                      (const GskSlType     *type);
   guint                 (* get_length)                          (const GskSlType     *type);
@@ -64,32 +63,25 @@ gsk_sl_type_scalar_free (GskSlType *type)
   g_assert_not_reached ();
 }
 
-static void
-gsk_sl_type_scalar_print (const GskSlType *type,
-                          GString         *string)
+static const char *
+gsk_sl_type_scalar_get_name (const GskSlType *type)
 {
-  GskSlTypeScalar *scalar = (GskSlTypeScalar *) type;
+  const GskSlTypeScalar *scalar = (const 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 (const 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 (const GskSlType *type,
-                          GString         *string)
+static const char *
+gsk_sl_type_vector_get_name (const 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;
-  }
+  const GskSlTypeVector *vector = (const GskSlTypeVector *) type;
 
-  g_string_append_printf (string, "%u", vector->length);
+  return vector->name;
 }
 
 static GskSlScalarType
@@ -229,7 +198,7 @@ gsk_sl_type_vector_can_convert (const 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 (const GskSlType *type,
-                          GString         *string)
+static const char *
+gsk_sl_type_matrix_get_name (const GskSlType *type)
 {
   const GskSlTypeMatrix *matrix = (const 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 (const 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]