[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
cex: isolate missing API from gl_list
From: |
Akim Demaille |
Subject: |
cex: isolate missing API from gl_list |
Date: |
Sat, 16 May 2020 10:50:37 +0200 |
> Le 16 mai 2020 à 10:34, Akim Demaille <address@hidden> a écrit :
>
> I'm also pushing more stylistic changes, as I try to understand the first
> crash (test 247). There are many uninitialized variables. We avoid that.
> We actually even try to be "functional" and assign variables only once, when
> possible.
Another case.
commit 487c26e269e0a8cc7474db582c13621d369361f5
Author: Akim Demaille <address@hidden>
Date: Sat May 16 10:41:06 2020 +0200
cex: isolate missing API from gl_list
* src/counterexample.c (list_get_end): New.
Use it.
Reduce scopes.
diff --git a/TODO b/TODO
index 006284eb..4265674e 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,17 @@
* Bison 3.7
+** Cex
+Don't do this (counterexample.c):
+
+// This is the fastest way to get the tail node from the gl_list API.
+gl_list_node_t
+list_get_end (gl_list_t list)
+{
+ gl_list_node_t sentinel = gl_list_add_last (list, NULL);
+ gl_list_node_t res = gl_list_previous_node (list, sentinel);
+ gl_list_remove_node (list, sentinel);
+ return res;
+}
+
** Bistromathic
- Hitting tab on a line with a syntax error is ugly
diff --git a/src/counterexample.c b/src/counterexample.c
index 2a8fb276..ea7bd87b 100644
--- a/src/counterexample.c
+++ b/src/counterexample.c
@@ -58,6 +58,16 @@
#define CUMULATIVE_TIME_LIMIT 120.0f
+// This is the fastest way to get the tail node from the gl_list API.
+gl_list_node_t
+list_get_end (gl_list_t list)
+{
+ gl_list_node_t sentinel = gl_list_add_last (list, NULL);
+ gl_list_node_t res = gl_list_previous_node (list, sentinel);
+ gl_list_remove_node (list, sentinel);
+ return res;
+}
+
typedef struct
{
const derivation *d1;
@@ -266,19 +276,17 @@ complete_diverging_example (symbol_number conflict_sym,
gl_list_add_last (result, derivation_dot ());
lookahead_required = true;
}
- // This is the fastest way to get the tail node from the gl_list API
- gl_list_node_t tmpd = gl_list_add_last (derivs, NULL);
- gl_list_node_t tmps = gl_list_add_last (path, NULL);
- gl_list_node_t deriv = gl_list_previous_node (derivs, tmpd);
- gl_list_node_t state_node = gl_list_previous_node (path, tmps);
- gl_list_remove_node (derivs, tmpd);
- gl_list_remove_node (path, tmps);
- // we go backwards through the path to create the derivation tree bottom-up.
+
+ gl_list_node_t deriv = list_get_end (derivs);
+
+ // We go backwards through the path to create the derivation tree bottom-up.
// Effectively this loops through each production once, and generates a
// derivation of the left hand side by appending all of the rhs symbols.
// this becomes the derivation of the non-terminal after the dot in the
// next production, and all of the other symbols of the rule are added as
normal.
- for (; state_node != NULL; state_node = gl_list_previous_node (path,
state_node))
+ for (gl_list_node_t state_node = list_get_end (path);
+ state_node != NULL;
+ state_node = gl_list_previous_node (path, state_node))
{
state_item *si = (state_item *) gl_list_node_value (path, state_node);
item_number *item = si->item;
- [PATCH 2/5] Parse simulator, (continued)
- [PATCH 2/5] Parse simulator, Vincent Imbimbo, 2020/05/12
- [PATCH 3/5] Counterexample search, Vincent Imbimbo, 2020/05/12
- [PATCH 4/5] counterexample generation integration, Vincent Imbimbo, 2020/05/12
- [PATCH 5/5] counterexample test suite, Vincent Imbimbo, 2020/05/12
- Re: [PATCH 0/5] Conflict Counterexample Generation, Akim Demaille, 2020/05/13
- Re: [PATCH 0/5] Conflict Counterexample Generation, Vincent Imbimbo, 2020/05/13
- Re: [PATCH 0/5] Conflict Counterexample Generation, Akim Demaille, 2020/05/13
- Re: [PATCH 0/5] Conflict Counterexample Generation, Akim Demaille, 2020/05/13
- Re: [PATCH 0/5] Conflict Counterexample Generation, Akim Demaille, 2020/05/14
- Re: [PATCH 0/5] Conflict Counterexample Generation, Akim Demaille, 2020/05/16
- cex: isolate missing API from gl_list,
Akim Demaille <=
- cex: stylistic changes, Akim Demaille, 2020/05/16
- cex: fix a crash, Akim Demaille, 2020/05/16
- cex: style changes in state-item, Akim Demaille, 2020/05/16
- cex: avoid uninitialized variables, Akim Demaille, 2020/05/16