[gtk+/wip/otte/shader: 71/176] gsksltype: Turn void into a custom type class
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 71/176] gsksltype: Turn void into a custom type class
- Date: Wed, 25 Oct 2017 03:22:42 +0000 (UTC)
commit 28fc52106523bd38aab0a9f80a0f82d401b8631f
Author: Benjamin Otte <otte redhat com>
Date: Sun Oct 1 04:31:18 2017 +0200
gsksltype: Turn void into a custom type class
Previously, void was a scalar type. It's not anymore.
On the plus side, we now got a gsk_sl_type_is_void() function that's
kinda useful in places.
gsk/gskslpointertype.c | 3 +-
gsk/gskslstatement.c | 4 +-
gsk/gsksltype.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++--
gsk/gsksltypeprivate.h | 2 +
4 files changed, 142 insertions(+), 8 deletions(-)
---
diff --git a/gsk/gskslpointertype.c b/gsk/gskslpointertype.c
index 7886225..cdc9dbe 100644
--- a/gsk/gskslpointertype.c
+++ b/gsk/gskslpointertype.c
@@ -186,7 +186,6 @@ gsk_sl_decoration_list_parse_layout (GskSlPreprocessor *preproc,
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected layout identifier.");
gsk_sl_preprocessor_consume (preproc, NULL);
- continue;
}
token = gsk_sl_preprocessor_get (preproc);
@@ -332,7 +331,7 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
gsk_sl_decoration_list_parse_layout (preproc, scope, list);
token = gsk_sl_preprocessor_get (preproc);
- if (gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
+ if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected closing \")\" at end of layout
specifier");
gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_PAREN);
diff --git a/gsk/gskslstatement.c b/gsk/gskslstatement.c
index 4e08e14..299bd56 100644
--- a/gsk/gskslstatement.c
+++ b/gsk/gskslstatement.c
@@ -743,14 +743,14 @@ its_a_type:
}
else if (return_statement->value == NULL)
{
- if (!gsk_sl_type_equal (return_type, gsk_sl_type_get_scalar (GSK_SL_VOID)))
+ if (!gsk_sl_type_is_void (return_type))
{
gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH,"Functions expectes a return value of type
%s", gsk_sl_type_get_name (return_type));
}
}
else
{
- if (gsk_sl_type_equal (return_type, gsk_sl_type_get_scalar (GSK_SL_VOID)))
+ if (gsk_sl_type_is_void (return_type))
{
gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH, "Cannot return a value from a void
function.");
}
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index a34b544..787f090 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -333,6 +333,125 @@ gsk_sl_type_alloc (const GskSlTypeClass *klass,
}
#define gsk_sl_type_new(_name, _klass) ((_name *) gsk_sl_type_alloc ((_klass), sizeof (_name)))
+/* VOID */
+
+typedef struct _GskSlTypeVoid GskSlTypeVoid;
+
+struct _GskSlTypeVoid {
+ GskSlType parent;
+};
+
+static void
+gsk_sl_type_void_free (GskSlType *type)
+{
+ g_assert_not_reached ();
+}
+
+static const char *
+gsk_sl_type_void_get_name (const GskSlType *type)
+{
+ return "void";
+}
+
+static GskSlScalarType
+gsk_sl_type_void_get_scalar_type (const GskSlType *type)
+{
+ return GSK_SL_VOID;
+}
+
+static GskSlType *
+gsk_sl_type_void_get_index_type (const GskSlType *type)
+{
+ return NULL;
+}
+
+static gsize
+gsk_sl_type_void_get_index_stride (const GskSlType *type)
+{
+ return 0;
+}
+
+static guint
+gsk_sl_type_void_get_length (const GskSlType *type)
+{
+ return 0;
+}
+
+static gsize
+gsk_sl_type_void_get_size (const GskSlType *type)
+{
+ return 0;
+}
+
+static guint
+gsk_sl_type_void_get_n_members (const GskSlType *type)
+{
+ return 0;
+}
+
+static const GskSlTypeMember *
+gsk_sl_type_void_get_member (const GskSlType *type,
+ guint n)
+{
+ return NULL;
+}
+
+static gboolean
+gsk_sl_type_void_can_convert (const GskSlType *target,
+ const GskSlType *source)
+{
+ return FALSE;
+}
+
+static guint32
+gsk_sl_type_void_write_spv (GskSlType *type,
+ GskSpvWriter *writer)
+{
+ guint32 result;
+
+ result = gsk_spv_writer_next_id (writer);
+ gsk_spv_writer_add (writer,
+ GSK_SPV_WRITER_SECTION_DECLARE,
+ 2, GSK_SPV_OP_TYPE_VOID,
+ (guint32[1]) { result });
+
+ return result;
+}
+
+static void
+gsk_sl_type_void_print_value (const GskSlType *type,
+ GskSlPrinter *printer,
+ gconstpointer value)
+{
+ g_assert_not_reached ();
+}
+
+static guint32
+gsk_sl_type_void_write_value_spv (GskSlType *type,
+ GskSpvWriter *writer,
+ gconstpointer value)
+{
+ g_assert_not_reached ();
+
+ return 0;
+}
+
+static const GskSlTypeClass GSK_SL_TYPE_VOID = {
+ gsk_sl_type_void_free,
+ gsk_sl_type_void_get_name,
+ gsk_sl_type_void_get_scalar_type,
+ gsk_sl_type_void_get_index_type,
+ gsk_sl_type_void_get_index_stride,
+ gsk_sl_type_void_get_length,
+ gsk_sl_type_void_get_size,
+ gsk_sl_type_void_get_n_members,
+ gsk_sl_type_void_get_member,
+ gsk_sl_type_void_can_convert,
+ gsk_sl_type_void_write_spv,
+ gsk_sl_type_void_print_value,
+ gsk_sl_type_void_write_value_spv
+};
+
/* SCALAR */
typedef struct _GskSlTypeScalar GskSlTypeScalar;
@@ -1198,7 +1317,7 @@ gsk_sl_type_get_builtin (GskSlBuiltinType builtin)
switch (builtin)
{
case GSK_SL_BUILTIN_VOID:
- return gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_VOID));
+ return gsk_sl_type_ref (gsk_sl_type_get_void ());
case GSK_SL_BUILTIN_FLOAT:
return gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_FLOAT));
case GSK_SL_BUILTIN_DOUBLE:
@@ -1277,7 +1396,7 @@ gsk_sl_type_get_builtin (GskSlBuiltinType builtin)
return gsk_sl_type_ref (gsk_sl_type_get_matrix (GSK_SL_DOUBLE, 4, 4));
default:
g_assert_not_reached ();
- return gsk_sl_type_get_scalar (GSK_SL_VOID);
+ return gsk_sl_type_get_void ();
}
}
@@ -1293,7 +1412,7 @@ gsk_sl_type_new_parse (GskSlScope *scope,
switch ((guint) token->type)
{
case GSK_SL_TOKEN_VOID:
- type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_VOID));
+ type = gsk_sl_type_ref (gsk_sl_type_get_void ());
break;
case GSK_SL_TOKEN_FLOAT:
type = gsk_sl_type_ref (gsk_sl_type_get_scalar (GSK_SL_FLOAT));
@@ -1438,9 +1557,16 @@ gsk_sl_type_new_parse (GskSlScope *scope,
return type;
}
+static GskSlTypeVoid void_type = { { &GSK_SL_TYPE_VOID, 1 } };
+
+GskSlType *
+gsk_sl_type_get_void (void)
+{
+ return &void_type.parent;
+}
+
static GskSlTypeScalar
builtin_scalar_types[N_SCALAR_TYPES] = {
- [GSK_SL_VOID] = { { &GSK_SL_TYPE_SCALAR, 1 }, GSK_SL_VOID },
[GSK_SL_FLOAT] = { { &GSK_SL_TYPE_SCALAR, 1 }, GSK_SL_FLOAT },
[GSK_SL_DOUBLE] = { { &GSK_SL_TYPE_SCALAR, 1 }, GSK_SL_DOUBLE },
[GSK_SL_INT] = { { &GSK_SL_TYPE_SCALAR, 1 }, GSK_SL_INT },
@@ -1452,6 +1578,7 @@ GskSlType *
gsk_sl_type_get_scalar (GskSlScalarType scalar)
{
g_assert (scalar < N_SCALAR_TYPES);
+ g_return_val_if_fail (scalar != GSK_SL_VOID, &void_type.parent);
return &builtin_scalar_types[scalar].parent;
}
@@ -1580,6 +1707,12 @@ gsk_sl_type_get_name (const GskSlType *type)
}
gboolean
+gsk_sl_type_is_void (const GskSlType *type)
+{
+ return type->class == &GSK_SL_TYPE_VOID;
+}
+
+gboolean
gsk_sl_type_is_scalar (const GskSlType *type)
{
return type->class == &GSK_SL_TYPE_SCALAR;
diff --git a/gsk/gsksltypeprivate.h b/gsk/gsksltypeprivate.h
index f21c382..6e4f1f7 100644
--- a/gsk/gsksltypeprivate.h
+++ b/gsk/gsksltypeprivate.h
@@ -29,6 +29,7 @@ typedef struct _GskSlTypeBuilder GskSlTypeBuilder;
GskSlType * gsk_sl_type_new_parse (GskSlScope *scope,
GskSlPreprocessor *preproc);
+GskSlType * gsk_sl_type_get_void (void);
GskSlType * gsk_sl_type_get_scalar (GskSlScalarType scalar);
GskSlType * gsk_sl_type_get_vector (GskSlScalarType scalar,
guint length);
@@ -40,6 +41,7 @@ GskSlType * gsk_sl_type_get_builtin (GskSlBuiltinTyp
GskSlType * gsk_sl_type_ref (GskSlType *type);
void gsk_sl_type_unref (GskSlType *type);
+gboolean gsk_sl_type_is_void (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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]