[gtk+/wip/otte/shader: 6/28] gskslnode: Add gsk_sl_node_get_return_type()



commit cba3fb093ebb1168b867c9e67cf36af2d2f48779
Author: Benjamin Otte <otte redhat com>
Date:   Sat Sep 16 21:34:27 2017 +0200

    gskslnode: Add gsk_sl_node_get_return_type()
    
    It's unused for now.
    
    But the idea is that (most) nodes return a value and we can know the
    type of value they return at compile-time. And then we can check type
    compatibility while parsing using this function.

 gsk/gskslnode.c        |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 gsk/gskslnodeprivate.h |    2 ++
 2 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index e43530c..89f2176 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -77,9 +77,16 @@ gsk_sl_node_program_print (GskSlNode *node,
     gsk_sl_node_print (l->data, string);
 }
 
+static GskSlType *
+gsk_sl_node_program_get_return_type (GskSlNode *node)
+{
+  return NULL;
+}
+
 static const GskSlNodeClass GSK_SL_NODE_PROGRAM = {
   gsk_sl_node_program_free,
-  gsk_sl_node_program_print
+  gsk_sl_node_program_print,
+  gsk_sl_node_program_get_return_type
 };
 
 /* FUNCTION */
@@ -131,9 +138,18 @@ gsk_sl_node_function_print (GskSlNode *node,
   g_string_append (string, "}\n");
 }
 
+static GskSlType *
+gsk_sl_node_function_get_return_type (GskSlNode *node)
+{
+  GskSlNodeFunction *function = (GskSlNodeFunction *) node;
+
+  return function->return_type;
+}
+
 static const GskSlNodeClass GSK_SL_NODE_FUNCTION = {
   gsk_sl_node_function_free,
-  gsk_sl_node_function_print
+  gsk_sl_node_function_print,
+  gsk_sl_node_function_get_return_type
 };
 
 /* ASSIGNMENT */
@@ -210,9 +226,18 @@ gsk_sl_node_assignment_print (GskSlNode *node,
   gsk_sl_node_print (assignment->rvalue, string);
 }
 
+static GskSlType *
+gsk_sl_node_assignment_get_return_type (GskSlNode *node)
+{
+  GskSlNodeAssignment *assignment = (GskSlNodeAssignment *) node;
+
+  return gsk_sl_node_get_return_type (assignment->lvalue);
+}
+
 static const GskSlNodeClass GSK_SL_NODE_ASSIGNMENT = {
   gsk_sl_node_assignment_free,
-  gsk_sl_node_assignment_print
+  gsk_sl_node_assignment_print,
+  gsk_sl_node_assignment_get_return_type
 };
 
 /* CONSTANT */
@@ -282,9 +307,18 @@ gsk_sl_node_constant_print (GskSlNode *node,
   }
 }
 
+static GskSlType *
+gsk_sl_node_constant_get_return_type (GskSlNode *node)
+{
+  GskSlNodeConstant *constant = (GskSlNodeConstant *) node;
+
+  return gsk_sl_type_get_builtin (constant->type);
+}
+
 static const GskSlNodeClass GSK_SL_NODE_CONSTANT = {
   gsk_sl_node_constant_free,
-  gsk_sl_node_constant_print
+  gsk_sl_node_constant_print,
+  gsk_sl_node_constant_get_return_type
 };
 
 /* API */
@@ -577,3 +611,9 @@ gsk_sl_node_print (GskSlNode *node,
 {
   node->class->print (node, string);
 }
+
+GskSlType *
+gsk_sl_node_get_return_type (GskSlNode *node)
+{
+  return node->class->get_return_type (node);
+}
diff --git a/gsk/gskslnodeprivate.h b/gsk/gskslnodeprivate.h
index 9066d8f..e5020bf 100644
--- a/gsk/gskslnodeprivate.h
+++ b/gsk/gskslnodeprivate.h
@@ -37,6 +37,7 @@ struct _GskSlNodeClass {
 
   void                  (* print)                               (GskSlNode           *node,
                                                                  GString             *string);
+  GskSlType *           (* get_return_type)                     (GskSlNode           *node);
 };
 
 GskSlNode *             gsk_sl_node_new_program                 (GBytes              *source,
@@ -47,6 +48,7 @@ void                    gsk_sl_node_unref                       (GskSlNode
 
 void                    gsk_sl_node_print                       (GskSlNode           *node,
                                                                  GString             *string);
+GskSlType *             gsk_sl_node_get_return_type             (GskSlNode           *node);
 
 G_END_DECLS
 


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