[gtk+/wip/otte/shader: 3/12] gsksltype: Prepare type system for rework



commit 9dccfeb2163fb6088c6f61020268fb04fa3e6fe9
Author: Benjamin Otte <otte redhat com>
Date:   Sun Sep 17 06:21:33 2017 +0200

    gsksltype: Prepare type system for rework
    
    Rename "builtin" types to "scalar" types and use them only for scalar
    types.

 gsk/gskslnode.c        |   16 +++++-----
 gsk/gsksltype.c        |   69 +++++++++++++++++------------------------------
 gsk/gsksltypeprivate.h |   11 ++-----
 3 files changed, 36 insertions(+), 60 deletions(-)
---
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index 8d76292..81a28ec 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -509,7 +509,7 @@ typedef struct _GskSlNodeConstant GskSlNodeConstant;
 struct _GskSlNodeConstant {
   GskSlNode parent;
 
-  GskSlBuiltinType type;
+  GskSlScalarType type;
   union {
     gint32       i32;
     guint32      u32;
@@ -574,7 +574,7 @@ gsk_sl_node_constant_get_return_type (GskSlNode *node)
 {
   GskSlNodeConstant *constant = (GskSlNodeConstant *) node;
 
-  return gsk_sl_type_get_builtin (constant->type);
+  return gsk_sl_type_get_scalar (constant->type);
 }
 
 static gboolean
@@ -748,7 +748,7 @@ gsk_sl_node_parse_logical_and_expression (GskSlNodeProgram *program,
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
-      else if (!gsk_sl_type_can_convert (gsk_sl_type_get_builtin (GSK_SL_BOOL),
+      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));
@@ -757,7 +757,7 @@ gsk_sl_node_parse_logical_and_expression (GskSlNodeProgram *program,
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
-      else if (!gsk_sl_type_can_convert (gsk_sl_type_get_builtin (GSK_SL_BOOL),
+      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));
@@ -805,7 +805,7 @@ gsk_sl_node_parse_logical_xor_expression (GskSlNodeProgram *program,
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
-      else if (!gsk_sl_type_can_convert (gsk_sl_type_get_builtin (GSK_SL_BOOL),
+      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));
@@ -814,7 +814,7 @@ gsk_sl_node_parse_logical_xor_expression (GskSlNodeProgram *program,
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
-      else if (!gsk_sl_type_can_convert (gsk_sl_type_get_builtin (GSK_SL_BOOL),
+      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));
@@ -862,7 +862,7 @@ gsk_sl_node_parse_logical_or_expression (GskSlNodeProgram *program,
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
-      else if (!gsk_sl_type_can_convert (gsk_sl_type_get_builtin (GSK_SL_BOOL),
+      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));
@@ -871,7 +871,7 @@ gsk_sl_node_parse_logical_or_expression (GskSlNodeProgram *program,
           gsk_sl_node_ref (node);
           gsk_sl_node_unref ((GskSlNode *) operation);
         }
-      else if (!gsk_sl_type_can_convert (gsk_sl_type_get_builtin (GSK_SL_BOOL),
+      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));
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index 4ab562a..f2b8c1a 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -29,26 +29,25 @@ struct _GskSlType
 {
   int ref_count;
 
-  GskSlBuiltinType builtin;
+  GskSlScalarType scalar;
 };
 
+#define N_SCALAR_TYPES 6
+
 static GskSlType
-builtin_types[GSK_SL_N_BUILTIN_TYPES] = {
+builtin_types[N_SCALAR_TYPES] = {
   [GSK_SL_VOID] = { 1, GSK_SL_VOID },
   [GSK_SL_FLOAT] = { 1, GSK_SL_FLOAT },
   [GSK_SL_DOUBLE] = { 1, GSK_SL_DOUBLE },
   [GSK_SL_INT] = { 1, GSK_SL_INT },
   [GSK_SL_UINT] = { 1, GSK_SL_UINT },
   [GSK_SL_BOOL] = { 1, GSK_SL_BOOL },
-  [GSK_SL_VEC2] = { 1, GSK_SL_VEC2 },
-  [GSK_SL_VEC3] = { 1, GSK_SL_VEC3 },
-  [GSK_SL_VEC4] = { 1, GSK_SL_VEC4 }
 };
 
 GskSlType *
 gsk_sl_type_new_parse (GskSlTokenStream *stream)
 {
-  GskSlBuiltinType builtin;
+  GskSlType *type;
   const GskSlToken *token;
 
   token = gsk_sl_token_stream_get (stream);
@@ -56,31 +55,22 @@ gsk_sl_type_new_parse (GskSlTokenStream *stream)
   switch (token->type)
   {
     case GSK_SL_TOKEN_VOID:
-      builtin = GSK_SL_VOID;
+      type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_VOID));
       break;
     case GSK_SL_TOKEN_FLOAT:
-      builtin = GSK_SL_FLOAT;
+      type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_FLOAT));
       break;
     case GSK_SL_TOKEN_DOUBLE:
-      builtin = GSK_SL_DOUBLE;
+      type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_DOUBLE));
       break;
     case GSK_SL_TOKEN_INT:
-      builtin = GSK_SL_INT;
+      type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_INT));
       break;
     case GSK_SL_TOKEN_UINT:
-      builtin = GSK_SL_UINT;
+      type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_UINT));
       break;
     case GSK_SL_TOKEN_BOOL:
-      builtin = GSK_SL_BOOL;
-      break;
-    case GSK_SL_TOKEN_VEC2:
-      builtin = GSK_SL_VEC2;
-      break;
-    case GSK_SL_TOKEN_VEC3:
-      builtin = GSK_SL_VEC3;
-      break;
-    case GSK_SL_TOKEN_VEC4:
-      builtin = GSK_SL_VEC4;
+      type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_BOOL));
       break;
     default:
       gsk_sl_token_stream_error (stream, "Expected type specifier");
@@ -88,15 +78,16 @@ gsk_sl_type_new_parse (GskSlTokenStream *stream)
   }
 
   gsk_sl_token_stream_consume (stream, NULL);
-  return gsk_sl_type_ref (gsk_sl_type_get_builtin (builtin));
+
+  return type;
 }
 
 GskSlType *
-gsk_sl_type_get_builtin (GskSlBuiltinType builtin)
+gsk_sl_type_get_scalar (GskSlScalarType scalar)
 {
-  g_assert (builtin < GSK_SL_N_BUILTIN_TYPES);
+  g_assert (scalar < N_SCALAR_TYPES);
 
-  return &builtin_types[builtin];
+  return &builtin_types[scalar];
 }
 
 GskSlType *
@@ -126,7 +117,7 @@ void
 gsk_sl_type_print (const GskSlType *type,
                    GString         *string)
 {
-  switch (type->builtin)
+  switch (type->scalar)
   {
     case GSK_SL_VOID:
       g_string_append (string, "void");
@@ -146,17 +137,7 @@ gsk_sl_type_print (const GskSlType *type,
     case GSK_SL_BOOL:
       g_string_append (string, "bool");
       break;
-    case GSK_SL_VEC2:
-      g_string_append (string, "vec2");
-      break;
-    case GSK_SL_VEC3:
-      g_string_append (string, "vec3");
-      break;
-    case GSK_SL_VEC4:
-      g_string_append (string, "vec4");
-      break;
     /* add more above */
-    case GSK_SL_N_BUILTIN_TYPES:
     default:
       g_assert_not_reached ();
       break;
@@ -177,20 +158,20 @@ gboolean
 gsk_sl_type_can_convert (const GskSlType *target,
                          const GskSlType *source)
 {
-  if (target->builtin == source->builtin)
+  if (target->scalar == source->scalar)
     return TRUE;
 
-  switch (source->builtin)
+  switch (source->scalar)
   {
     case GSK_SL_INT:
-      return target->builtin == GSK_SL_UINT
-          || target->builtin == GSK_SL_FLOAT
-          || target->builtin == GSK_SL_DOUBLE;
+      return target->scalar == GSK_SL_UINT
+          || target->scalar == GSK_SL_FLOAT
+          || target->scalar == GSK_SL_DOUBLE;
     case GSK_SL_UINT:
-      return target->builtin == GSK_SL_FLOAT
-          || target->builtin == GSK_SL_DOUBLE;
+      return target->scalar == GSK_SL_FLOAT
+          || target->scalar == GSK_SL_DOUBLE;
     case GSK_SL_FLOAT:
-      return target->builtin == GSK_SL_DOUBLE;
+      return target->scalar == GSK_SL_DOUBLE;
     default:
       return FALSE;
   }
diff --git a/gsk/gsksltypeprivate.h b/gsk/gsksltypeprivate.h
index 45f4fd2..7670aa1 100644
--- a/gsk/gsksltypeprivate.h
+++ b/gsk/gsksltypeprivate.h
@@ -31,18 +31,13 @@ typedef enum {
   GSK_SL_DOUBLE,
   GSK_SL_INT,
   GSK_SL_UINT,
-  GSK_SL_BOOL,
-  GSK_SL_VEC2,
-  GSK_SL_VEC3,
-  GSK_SL_VEC4,
-  /* add more above */
-  GSK_SL_N_BUILTIN_TYPES
-} GskSlBuiltinType;
+  GSK_SL_BOOL
+} GskSlScalarType;
 
 typedef struct _GskSlType GskSlType;
 
 GskSlType *             gsk_sl_type_new_parse                   (GskSlTokenStream    *stream);
-GskSlType *             gsk_sl_type_get_builtin                 (GskSlBuiltinType     builtin);
+GskSlType *             gsk_sl_type_get_scalar                  (GskSlScalarType      scalar);
 
 GskSlType *             gsk_sl_type_ref                         (GskSlType           *type);
 void                    gsk_sl_type_unref                       (GskSlType           *type);


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