[template-glib] scope: add API to list symbols in a scope
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] scope: add API to list symbols in a scope
- Date: Wed, 4 May 2022 18:52:17 +0000 (UTC)
commit cfff88aba201b765c44eb81de5b7896c1c744ab9
Author: Christian Hergert <chergert redhat com>
Date: Wed May 4 11:51:26 2022 -0700
scope: add API to list symbols in a scope
Mostly used for debugging so that you can see if/why you should have missed
something in that list.
src/tmpl-scope.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
src/tmpl-scope.h | 3 +++
2 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/src/tmpl-scope.c b/src/tmpl-scope.c
index aa80ced..e38606b 100644
--- a/src/tmpl-scope.c
+++ b/src/tmpl-scope.c
@@ -322,7 +322,7 @@ tmpl_scope_set_variant (TmplScope *self,
g_return_if_fail (name != NULL);
tmpl_symbol_assign_variant (tmpl_scope_get_full (self, name, TRUE),
- value);
+ value);
}
/**
@@ -342,7 +342,7 @@ tmpl_scope_set_strv (TmplScope *self,
g_return_if_fail (name != NULL);
tmpl_symbol_assign_variant (tmpl_scope_get_full (self, name, TRUE),
- g_variant_new_strv (value, -1));
+ g_variant_new_strv (value, -1));
}
/**
@@ -430,6 +430,8 @@ tmpl_scope_require (TmplScope *self,
if (!(typelib = g_irepository_require (NULL, namespace_, version, 0, NULL)))
return FALSE;
+ g_print ("Inserting %s into scope %p\n", namespace_, typelib);
+
g_value_init (&value, TMPL_TYPE_TYPELIB);
g_value_set_pointer (&value, typelib);
tmpl_scope_set_value (self, namespace_, &value);
@@ -437,3 +439,47 @@ tmpl_scope_require (TmplScope *self,
return TRUE;
}
+
+static void
+tmpl_scope_list_symbols_internal (TmplScope *self,
+ GPtrArray *ar,
+ gboolean recursive)
+{
+ GHashTableIter iter;
+ const char *key;
+
+ g_assert (self != NULL);
+ g_assert (ar != NULL);
+
+ g_hash_table_iter_init (&iter, self->symbols);
+ while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
+ g_ptr_array_add (ar, g_strdup (key));
+
+ if (recursive && self->parent)
+ tmpl_scope_list_symbols_internal (self->parent, ar, recursive);
+}
+
+/**
+ * tmpl_scope_list_symbols:
+ * @self: a #TmplScope
+ * @recursive: if the parent scopes should be included
+ *
+ * Gets the names of all symbols within the scope.
+ *
+ * Returns: (array zero-terminated=1) (element-type utf8) (transfer full):
+ * an array containing the names of all symbols within the scope.
+ */
+char **
+tmpl_scope_list_symbols (TmplScope *self,
+ gboolean recursive)
+{
+ GPtrArray *ar;
+
+ g_return_val_if_fail (self != NULL, NULL);
+
+ ar = g_ptr_array_new ();
+ tmpl_scope_list_symbols_internal (self, ar, recursive);
+ g_ptr_array_add (ar, NULL);
+
+ return (char **)g_ptr_array_free (ar, FALSE);
+}
diff --git a/src/tmpl-scope.h b/src/tmpl-scope.h
index 67c1211..a871bf0 100644
--- a/src/tmpl-scope.h
+++ b/src/tmpl-scope.h
@@ -96,6 +96,9 @@ TMPL_AVAILABLE_IN_3_36
gboolean tmpl_scope_require (TmplScope *self,
const char *namespace_,
const char *version);
+TMPL_AVAILABLE_IN_3_36
+char **tmpl_scope_list_symbols (TmplScope *self,
+ gboolean recursive);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TmplScope, tmpl_scope_unref)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]