[gtk+/wip/otte/shader: 48/176] gskslscope: Track function calls



commit b2a92bbacfd4558d03e9beccd2f013e3253eae27
Author: Benjamin Otte <otte redhat com>
Date:   Wed Sep 27 18:44:50 2017 +0200

    gskslscope: Track function calls

 gsk/gskslprogram.c      |    1 +
 gsk/gskslscope.c        |   29 +++++++++++++++++++++++++++++
 gsk/gskslscopeprivate.h |    4 ++++
 3 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskslprogram.c b/gsk/gskslprogram.c
index 04969a4..9220034 100644
--- a/gsk/gskslprogram.c
+++ b/gsk/gskslprogram.c
@@ -179,6 +179,7 @@ gsk_sl_program_parse_declaration (GskSlProgram      *program,
                                             preproc,
                                             type,
                                             name);
+      gsk_sl_scope_add_function (scope, function);
       program->functions = g_slist_append (program->functions, function);
     }
   else
diff --git a/gsk/gskslscope.c b/gsk/gskslscope.c
index e1b3ca0..e75b444 100644
--- a/gsk/gskslscope.c
+++ b/gsk/gskslscope.c
@@ -21,6 +21,7 @@
 #include "gskslscopeprivate.h"
 
 #include "gsksltypeprivate.h"
+#include "gskslfunctionprivate.h"
 #include "gskslvariableprivate.h"
 
 #include <string.h>
@@ -34,6 +35,7 @@ struct _GskSlScope
   GskSlType *return_type;
   
   GHashTable *variables;
+  GHashTable *functions;
 };
 
 GskSlScope *
@@ -53,6 +55,7 @@ gsk_sl_scope_new (GskSlScope *parent,
   if (return_type)
     scope->return_type = gsk_sl_type_ref (return_type);
   scope->variables = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) 
gsk_sl_variable_unref);
+  scope->functions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) 
gsk_sl_function_unref);
 
   return scope;
 }
@@ -80,6 +83,7 @@ gsk_sl_scope_unref (GskSlScope *scope)
     return;
 
   g_hash_table_unref (scope->variables);
+  g_hash_table_unref (scope->functions);
 
   if (scope->parent)
     scope->parent->children = g_slist_remove (scope->parent->children, scope);
@@ -122,3 +126,28 @@ gsk_sl_scope_lookup_variable (GskSlScope *scope,
 
   return NULL;
 }
+
+void
+gsk_sl_scope_add_function (GskSlScope    *scope,
+                           GskSlFunction *function)
+{
+  g_hash_table_replace (scope->functions, (gpointer) gsk_sl_function_get_name (function), 
gsk_sl_function_ref (function));
+}
+
+GskSlFunction *
+gsk_sl_scope_lookup_function (GskSlScope *scope,
+                              const char *name)
+{
+  GskSlFunction *result;
+
+  for (;
+       scope != NULL;
+       scope = scope->parent)
+    {
+      result = g_hash_table_lookup (scope->functions, name);
+      if (result)
+        return result;
+    }
+
+  return NULL;
+}
diff --git a/gsk/gskslscopeprivate.h b/gsk/gskslscopeprivate.h
index 9a41bef..869c94d 100644
--- a/gsk/gskslscopeprivate.h
+++ b/gsk/gskslscopeprivate.h
@@ -37,6 +37,10 @@ void                    gsk_sl_scope_add_variable               (GskSlScope
                                                                  GskSlVariable        *variable);
 GskSlVariable *         gsk_sl_scope_lookup_variable            (GskSlScope           *scope,
                                                                  const char           *name);
+void                    gsk_sl_scope_add_function               (GskSlScope           *scope,
+                                                                 GskSlFunction        *function);
+GskSlFunction *         gsk_sl_scope_lookup_function            (GskSlScope           *scope,
+                                                                 const char           *name);
 
 G_END_DECLS
 


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