]> git.vouivredigital.com Git - vouivre.git/commitdiff
Incorporate `list_wrap_names' into `list_dependencies'
authoradmin <admin@vouivredigital.com>
Sun, 27 Oct 2024 16:10:30 +0000 (12:10 -0400)
committeradmin <admin@vouivredigital.com>
Sun, 27 Oct 2024 16:10:30 +0000 (12:10 -0400)
src/v.c

diff --git a/src/v.c b/src/v.c
index 9d39ae21447e1a3634a22afed140ed5b3ed7c522..a50f6f21661ccfa4987c0a766aa73d0fba0c8695 100644 (file)
--- a/src/v.c
+++ b/src/v.c
@@ -320,12 +320,17 @@ copy_user_data(gconstpointer src, gpointer data)
   return data;
 }
 
+/* Return whether or not the judgment is the conclusion of the rule. */
 bool
 conclusion_p(struct rule *rule, struct judgment *judgment)
 {
   return judgment == rule->conclusion ? TRUE : FALSE;
 }
 
+/*
+ * Remove entries with contextual scope.  This is the end of the line for
+ * variables.
+ */
 void
 clear_contextuals(GHashTable *temporaries)
 {
@@ -341,6 +346,10 @@ clear_contextuals(GHashTable *temporaries)
   }
 }
 
+/*
+ * Remove all temporaries and generic contexts/theses.  This is the end of the
+ * line for both contextual and local names.
+ */
 void
 clear_locals(struct state *state)
 {
@@ -349,27 +358,37 @@ clear_locals(struct state *state)
   g_hash_table_steal_all(state->temporaries);
 }
 
+/*
+ * List all names involved (origin or replacement) in the reference,
+ * recursively.
+ */
 GSList *
-reference_list_type_names(GSList *list, struct reference *ref)
+list_reference_type_names(GSList *list, struct reference *ref)
 {
   GSList *l;
 
   list = g_slist_prepend(list, ref->origin);
   l = ref->replacements;
   while (l) {
-    list = reference_list_type_names(list, l->data);
+    list = list_reference_type_names(list, l->data);
     l = l->next;
   }
   return list;
 }
 
+/*
+ * List all names involved (origin or through a reference — see
+ * `list_reference_type_name') in the wrap, recursively.
+ */
 GSList *
-wrap_list_type_names(GSList *list, struct wrap *wrap)
+list_wrap_names(GSList *list, struct wrap *wrap)
 {
+  if (!wrap)
+    return NULL;
   if (wrap->is_origin)
     list = g_slist_prepend(list, wrap->ptr);
   else
-    list = reference_list_type_names(list, wrap->ptr);
+    list = list_reference_type_names(list, wrap->ptr);
   return list;
 }
 
@@ -573,15 +592,15 @@ copy_wrap(struct wrap *wrap)
  *    type's dependencies first then the element's dependencies)
  */
 GSList *
-list_dependencies(struct name *ptr, GHashTable *temporaries,
-                 GSList *type_names)
+list_dependencies(struct name *ptr, GHashTable *temporaries)
 {
-  GSList *deps, *types, *l, *prev;
+  GSList *deps, *types, *l, *prev, *type_names;
   GHashTableIter iter;
   gpointer key, value;
   struct name *name;
 
   deps = NULL;
+  type_names = !ptr ? NULL : list_wrap_names(NULL, ptr->type);
   g_hash_table_iter_init(&iter, temporaries);
   while (g_hash_table_iter_next(&iter, &key, &value)) {
     name = value;
@@ -595,6 +614,7 @@ list_dependencies(struct name *ptr, GHashTable *temporaries,
     if (name != ptr && !g_slist_find(type_names, name))
        deps = g_slist_prepend(deps, name);
   }
+  g_slist_free(g_steal_pointer(&type_names));
 
   /* Remove names that are types of other names in the dependency list. */
   prev = NULL;
@@ -621,11 +641,19 @@ list_dependencies(struct name *ptr, GHashTable *temporaries,
   return deps;
 }
 
+void
+insert_name(GHashTable *temporaries, struct name *name)
+{
+  if (name->scope != scope_global)
+    g_hash_table_insert(temporaries, name->str, name);
+}
+
 void
 next_slot(struct state *state)
 {
   GSList *l;
-  struct name *name;
+  struct name *name, *ptr;
+  struct wrap *wrap;
 
   switch (state->st) {
   case slot_type_rule_dots:
@@ -644,11 +672,9 @@ next_slot(struct state *state)
     state->st = slot_type_ctx_dots;
     state->caret += 1;
     name = (struct name *)g_slist_last(state->judgment->vdecls)->data;
-    g_hash_table_insert(state->temporaries, name->str, name);
-    if (name->type->is_origin) {
-      name = name->type->ptr;
-      g_hash_table_insert(state->temporaries, name->str, name);
-    }
+    insert_name(state->temporaries, name);
+    if (name->type->is_origin)
+      insert_name(state->temporaries, name->type->ptr);
     break;
   case slot_type_ctx_dots:
     state->st = slot_type_ctx_r;
@@ -694,11 +720,8 @@ next_slot(struct state *state)
     else
       state->st = slot_type_rule_dots;
     state->caret += 1;
-    if (state->judgment->a->is_origin) {
-      name = state->judgment->a->ptr;
-      if (name->scope != scope_global)
-       g_hash_table_insert(state->temporaries, name->str, name);
-    }
+    if (state->judgment->a->is_origin)
+      insert_name(state->temporaries, state->judgment->a->ptr);
     clear_contextuals(state->temporaries);
     break;
   case slot_type_element_thesis_element:
@@ -720,30 +743,20 @@ next_slot(struct state *state)
     else
       state->st = slot_type_rule_dots;
     state->caret += 1;
-    if (state->judgment->a->is_origin)
-      name = state->judgment->a->ptr;
-    else
-      name = ((struct reference *)state->judgment->a->ptr)->origin;
+    name = get_wrap_name(state->judgment->a);
     if (state->judgment->a->is_origin) {
-      l = wrap_list_type_names(NULL, name->type);
-      name->dependencies = list_dependencies(name, state->temporaries, l);
-      g_slist_free(g_steal_pointer(&l));
-      if (name->scope != scope_global)
-       g_hash_table_insert(state->temporaries, name->str, name);
-    }
-    if (name->type->is_origin) {
-      name = name->type->ptr;
-      g_hash_table_insert(state->temporaries, name->str, name);
+      name->dependencies = list_dependencies(name, state->temporaries);
+      insert_name(state->temporaries, name);
     }
+    if (name->type->is_origin)
+      insert_name(state->temporaries, name->type->ptr);
     clear_contextuals(state->temporaries);
     break;
   case slot_type_type_equal_thesis_type_1:
     state->st = slot_type_type_equal_thesis_type_2;
     state->caret += 1;
-    if (state->judgment->a->is_origin) {
-      name = state->judgment->a->ptr;
-      g_hash_table_insert(state->temporaries, name->str, name);
-    }
+    if (state->judgment->a->is_origin)
+      insert_name(state->temporaries, state->judgment->a->ptr);
     break;
   case slot_type_type_equal_thesis_type_2:
     if (conclusion_p(state->rule, state->judgment))
@@ -751,10 +764,8 @@ next_slot(struct state *state)
     else
       state->st = slot_type_rule_dots;
     state->caret += 1;
-    if (state->judgment->b->is_origin) {
-      name = state->judgment->b->ptr;
-      g_hash_table_insert(state->temporaries, name->str, name);
-    }
+    if (state->judgment->b->is_origin)
+      insert_name(state->temporaries, state->judgment->b->ptr);
     clear_contextuals(state->temporaries);
     break;
   case slot_type_element_equal_thesis_element_1:
@@ -762,7 +773,7 @@ next_slot(struct state *state)
     state->caret += 1;
     break;
   case slot_type_element_equal_thesis_element_2:
-    if (state->judgment->a->is_origin) {
+    if (state->judgment->a->is_origin && state->judgment->b->is_origin) {
       state->st = slot_type_element_equal_thesis_type;
       state->caret += 1;
     }
@@ -773,24 +784,22 @@ next_slot(struct state *state)
        state->st = slot_type_rule_dots;
       state->caret += 2;
 
-      /* Since we skip the type slot we should add the dependencies and
-        temporaries here if needed. */
-      *get_wrap_type_addr(state->judgment->b) =
-       copy_wrap(get_wrap_type(state->judgment->a));
+      /* Since we skip the type slot we should add dependencies to originals,
+        here. */
+      ptr = NULL;
       if (state->judgment->a->is_origin) {
        name = state->judgment->a->ptr;
-       l = wrap_list_type_names(NULL, name->type);
-       name->dependencies = list_dependencies(name, state->temporaries, l);
-       g_slist_free(g_steal_pointer(&l));
-       g_hash_table_insert(state->temporaries, name->str, name);
+       name->type = copy_wrap(get_wrap_type(state->judgment->b));
+       name->dependencies = list_dependencies(name, state->temporaries);
+       ptr = name;            /* Don't insert `a' before we listed `b's deps */
       }
       if (state->judgment->b->is_origin) {
        name = state->judgment->b->ptr;
-       l = wrap_list_type_names(NULL, name->type);
-       name->dependencies = list_dependencies(name, state->temporaries, l);
-       g_slist_free(g_steal_pointer(&l));
-       g_hash_table_insert(state->temporaries, name->str, name);
+       name->type = copy_wrap(get_wrap_type(state->judgment->a));
+       name->dependencies = list_dependencies(name, state->temporaries);
+       insert_name(state->temporaries, name);
       }
+      if (ptr) insert_name(state->temporaries, ptr);
     }
     break;
   case slot_type_element_equal_thesis_type:
@@ -799,31 +808,24 @@ next_slot(struct state *state)
     else
       state->st = slot_type_rule_dots;
     state->caret += 1;
-    *get_wrap_type_addr(state->judgment->b) =
-      copy_wrap(get_wrap_type(state->judgment->a));
+
+    ptr = NULL;
     if (state->judgment->a->is_origin) {
       name = state->judgment->a->ptr;
-      l = wrap_list_type_names(NULL, name->type);
-      name->dependencies = list_dependencies(name, state->temporaries, l);
-      g_slist_free(g_steal_pointer(&l));
-      g_hash_table_insert(state->temporaries, name->str, name);
+      name->type = copy_wrap(get_wrap_type(state->judgment->b));
+      name->dependencies = list_dependencies(name, state->temporaries);
+      ptr = name;             /* Don't insert `a' before we listed `b's deps */
     }
     if (state->judgment->b->is_origin) {
       name = state->judgment->b->ptr;
-      l = wrap_list_type_names(NULL, name->type);
-      name->dependencies = list_dependencies(name, state->temporaries, l);
-      g_slist_free(g_steal_pointer(&l));
-      g_hash_table_insert(state->temporaries, name->str, name);
-    }
-    if (state->judgment->a->is_origin)
-      name = state->judgment->a->ptr;
-    else
-      name = ((struct reference *)state->judgment->a->ptr)->origin;
-    if (name->type->is_origin) {
-      name = name->type->ptr;
-      g_hash_table_insert(state->temporaries, name->str, name);
+      name->type = copy_wrap(get_wrap_type(state->judgment->a));
+      name->dependencies = list_dependencies(name, state->temporaries);
+      insert_name(state->temporaries, name);
     }
-
+    if (ptr) insert_name(state->temporaries, ptr);
+    wrap = get_wrap_type(state->judgment->a);
+    if (wrap->is_origin)
+      insert_name(state->temporaries, wrap->ptr);
     clear_contextuals(state->temporaries);
     break;
   case slot_type_rule_name:
@@ -978,6 +980,18 @@ draw_ref(WINDOW *w, int *y, int *x, bool virtual,
     if (l) {
       draw_slot(w, y, x, virtual, FALSE, PAIR_NORMAL, "[");
       while (l) {
+       /* dep = TBD; */
+       /* l1 = list_out_of_scope_dependencies(name, temporaries);  */
+       /* while (l1) { */
+       /*   set_ctp_and_pair(&ctp, &pair, caret, (*point)++); */
+       /*   draw_slot(w, y, x, virtual, FALSE, pair, NULL); */
+       /*   if (l1->next) */
+       /*     draw_slot(w, y, x, virtual, FALSE, PAIR_NORMAL, ", "); */
+       /*   else */
+       /*     draw_slot(w, y, x, virtual, FALSE, PAIR_NORMAL, ". "); */
+       /*   l1 = l1->next; */
+       /* } */
+
        draw_ref(w, y, x, virtual, caret, point, inputstr, l->data);
        l = l->next;
        if (l)
@@ -1536,7 +1550,7 @@ validate_generic_context(struct state *state, bool is_left)
                     nk,
                     NULL,
                     state->rule,
-                    list_dependencies(NULL, state->temporaries, NULL),
+                    list_dependencies(NULL, state->temporaries),
                     strdup(state->input->str));
   wrap = create_wrap(TRUE, name);
   if (is_left)
@@ -1576,7 +1590,7 @@ validate_generic_thesis(struct state *state)
                     nk_generic_thesis,
                     NULL,
                     state->rule,
-                    list_dependencies(NULL, state->temporaries, NULL),
+                    list_dependencies(NULL, state->temporaries),
                     strdup(state->input->str));
   wrap = create_wrap(TRUE, name);
   state->judgment->a = wrap;
@@ -1629,7 +1643,7 @@ validate_vet_input(void *addr, struct state *state,
       scope = scope_local;
     name = create_name(scope, nk_vet, NULL, state->rule,
                       no_deps ? NULL :
-                      list_dependencies(NULL, state->temporaries, NULL),
+                      list_dependencies(NULL, state->temporaries),
                       strdup(state->input->str));
     state->input = g_string_erase(state->input, 0, -1);
     if (vetk == vetk_variable)