[gtk+/wip/otte/shader] gskslfunction: Change name printing to name getting



commit 5c33bc6e5c841e33ced709cc84d93c2bd8267b4f
Author: Benjamin Otte <otte redhat com>
Date:   Sun Sep 24 23:17:18 2017 +0200

    gskslfunction: Change name printing to name getting
    
    Since gsk_sl_type_get_name() exists now, we can have a name getter also
    for builtin constructors.

 gsk/gskslexpression.c      |    2 +-
 gsk/gskslfunction.c        |   25 +++++++++++--------------
 gsk/gskslfunctionprivate.h |    6 ++----
 gsk/gskslprogram.c         |    4 +---
 4 files changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index 3213c4a..3a3389d 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -731,7 +731,7 @@ gsk_sl_expression_function_call_print (const GskSlExpression *expression,
   const GskSlExpressionFunctionCall *function_call = (const GskSlExpressionFunctionCall *) expression;
   guint i;
 
-  gsk_sl_function_print_name (function_call->function, string);
+  g_string_append (string, gsk_sl_function_get_name (function_call->function));
   g_string_append (string, " (");
   
   for (i = 0; i < function_call->n_arguments; i++)
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index ec9b84f..981100c 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -70,13 +70,12 @@ gsk_sl_function_builtin_constructor_get_return_type (const GskSlFunction *functi
   return builtin_constructor->type;
 }
 
-static void
-gsk_sl_function_builtin_constructor_print_name (const GskSlFunction *function,
-                                                GString             *string)
+static const char *
+gsk_sl_function_builtin_constructor_get_name (const GskSlFunction *function)
 {
   const GskSlFunctionBuiltinConstructor *builtin_constructor = (const GskSlFunctionBuiltinConstructor *) 
function;
 
-  g_string_append (string, gsk_sl_type_get_name (builtin_constructor->type));
+  return gsk_sl_type_get_name (builtin_constructor->type);
 }
 
 static void
@@ -147,7 +146,7 @@ gsk_sl_function_builtin_constructor_write_spv (const GskSlFunction *function,
 static const GskSlFunctionClass GSK_SL_FUNCTION_BUILTIN_CONSTRUCTOR = {
   gsk_sl_function_builtin_constructor_free,
   gsk_sl_function_builtin_constructor_get_return_type,
-  gsk_sl_function_builtin_constructor_print_name,
+  gsk_sl_function_builtin_constructor_get_name,
   gsk_sl_function_builtin_constructor_print,
   gsk_sl_function_builtin_constructor_matches,
   gsk_sl_function_builtin_constructor_write_spv,
@@ -189,13 +188,12 @@ gsk_sl_function_declared_get_return_type (const GskSlFunction *function)
   return declared->return_type;
 }
 
-static void
-gsk_sl_function_declared_print_name (const GskSlFunction *function,
-                                     GString             *string)
+static const char *
+gsk_sl_function_declared_get_name (const GskSlFunction *function)
 {
   const GskSlFunctionDeclared *declared = (const GskSlFunctionDeclared *) function;
 
-  g_string_append (string, declared->name);
+  return declared->name;
 }
 
 static void
@@ -288,7 +286,7 @@ gsk_sl_function_declared_write_spv (const GskSlFunction *function,
 static const GskSlFunctionClass GSK_SL_FUNCTION_DECLARED = {
   gsk_sl_function_declared_free,
   gsk_sl_function_declared_get_return_type,
-  gsk_sl_function_declared_print_name,
+  gsk_sl_function_declared_get_name,
   gsk_sl_function_declared_print,
   gsk_sl_function_declared_matches,
   gsk_sl_function_declared_write_spv,
@@ -416,11 +414,10 @@ gsk_sl_function_get_return_type (const GskSlFunction *function)
   return function->class->get_return_type (function);
 }
 
-void
-gsk_sl_function_print_name (const GskSlFunction *function,
-                            GString             *string)
+const char *
+gsk_sl_function_get_name (const GskSlFunction *function)
 {
-  function->class->print_name (function, string);
+  return function->class->get_name (function);
 }
 
 void
diff --git a/gsk/gskslfunctionprivate.h b/gsk/gskslfunctionprivate.h
index 99967cb..9e28374 100644
--- a/gsk/gskslfunctionprivate.h
+++ b/gsk/gskslfunctionprivate.h
@@ -38,8 +38,7 @@ struct _GskSlFunctionClass {
   void                  (* free)                                (GskSlFunction  *function);
 
   GskSlType *           (* get_return_type)                     (const GskSlFunction    *function);
-  void                  (* print_name)                          (const GskSlFunction    *function,
-                                                                 GString                *string);
+  const char *          (* get_name)                            (const GskSlFunction    *function);
   void                  (* print)                               (const GskSlFunction    *function,
                                                                  GString                *string);
   gboolean              (* matches)                             (const GskSlFunction    *function,
@@ -62,8 +61,7 @@ void                    gsk_sl_function_unref                   (GskSlFunction
 void                    gsk_sl_function_print                   (const GskSlFunction    *function,
                                                                  GString                *string);
 
-void                    gsk_sl_function_print_name              (const GskSlFunction    *function,
-                                                                 GString                *string);
+const char *            gsk_sl_function_get_name                (const GskSlFunction    *function);
 GskSlType *             gsk_sl_function_get_return_type         (const GskSlFunction    *function);
 gboolean                gsk_sl_function_matches                 (const GskSlFunction    *function,
                                                                  GskSlType             **arguments,
diff --git a/gsk/gskslprogram.c b/gsk/gskslprogram.c
index 75b5c4d..e0d45da 100644
--- a/gsk/gskslprogram.c
+++ b/gsk/gskslprogram.c
@@ -151,15 +151,13 @@ gsk_sl_program_write_spv (GskSlProgram *program,
   for (l = program->declarations; l; l = l->next)
     gsk_sl_node_write_spv (l->data, writer);
 
-#if 0
   for (l = program->functions; l; l = l->next)
     {
       guint32 id = gsk_sl_node_write_spv (l->data, writer);
 
-      if (g_str_equal (((GskSlNodeFunction *) l->data)->name, "main"))
+      if (g_str_equal (gsk_sl_function_get_name (l->data), "main"))
         gsk_spv_writer_set_entry_point (writer, id);
     }
-#endif
 }
 
 GBytes *


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