summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2015-10-20 20:21:44 (GMT)
committerdgp <dgp@users.sourceforge.net>2015-10-20 20:21:44 (GMT)
commitbc85f89c10afaf5368f4c41a235e11955886a1a3 (patch)
treea4b1253b0b21a324ac93ecaa8709fcdeca12e2dc /generic
parent75ed02d88822dad90ad256551f2df875aa884975 (diff)
downloadtcl-bc85f89c10afaf5368f4c41a235e11955886a1a3.zip
tcl-bc85f89c10afaf5368f4c41a235e11955886a1a3.tar.gz
tcl-bc85f89c10afaf5368f4c41a235e11955886a1a3.tar.bz2
Adaptation of most of the re-mopup.patch from Tom Lane @ postgress.
Still should add the new tests.
Diffstat (limited to 'generic')
-rw-r--r--generic/regc_nfa.c50
-rw-r--r--generic/regcomp.c12
2 files changed, 22 insertions, 40 deletions
diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c
index 5568bff..6280e5e 100644
--- a/generic/regc_nfa.c
+++ b/generic/regc_nfa.c
@@ -843,15 +843,13 @@ moveins(
/*
- copyins - copy in arcs of a state to another state
- * Either all arcs, or only non-empty ones as determined by all value.
^ static VOID copyins(struct nfa *, struct state *, struct state *, int);
*/
static void
copyins(
struct nfa *nfa,
struct state *oldState,
- struct state *newState,
- int all)
+ struct state *newState)
{
assert(oldState != newState);
@@ -860,9 +858,7 @@ copyins(
struct arc *a;
for (a = oldState->ins; a != NULL; a = a->inchain) {
- if (all || a->type != EMPTY) {
- cparc(nfa, a, a->from, newState);
- }
+ cparc(nfa, a, a->from, newState);
}
} else {
/*
@@ -892,11 +888,6 @@ copyins(
while (oa != NULL && na != NULL) {
struct arc *a = oa;
- if (!all && a->type == EMPTY) {
- oa = oa->inchain;
- continue;
- }
-
switch (sortins_cmp(&oa, &na)) {
case -1:
/* newState does not have anything matching oa */
@@ -920,11 +911,6 @@ copyins(
/* newState does not have anything matching oa */
struct arc *a = oa;
- if (!all && a->type == EMPTY) {
- oa = oa->inchain;
- continue;
- }
-
oa = oa->inchain;
createarc(nfa, a->type, a->co, a->from, newState);
}
@@ -1114,15 +1100,13 @@ moveouts(
/*
- copyouts - copy out arcs of a state to another state
- * Either all arcs, or only non-empty ones as determined by all value.
^ static VOID copyouts(struct nfa *, struct state *, struct state *, int);
*/
static void
copyouts(
struct nfa *nfa,
struct state *oldState,
- struct state *newState,
- int all)
+ struct state *newState)
{
assert(oldState != newState);
@@ -1131,9 +1115,7 @@ copyouts(
struct arc *a;
for (a = oldState->outs; a != NULL; a = a->outchain) {
- if (all || a->type != EMPTY) {
- cparc(nfa, a, newState, a->to);
- }
+ cparc(nfa, a, newState, a->to);
}
} else {
/*
@@ -1163,11 +1145,6 @@ copyouts(
while (oa != NULL && na != NULL) {
struct arc *a = oa;
- if (!all && a->type == EMPTY) {
- oa = oa->outchain;
- continue;
- }
-
switch (sortouts_cmp(&oa, &na)) {
case -1:
/* newState does not have anything matching oa */
@@ -1191,11 +1168,6 @@ copyouts(
/* newState does not have anything matching oa */
struct arc *a = oa;
- if (!all && a->type == EMPTY){
- oa = oa->outchain;
- continue;
- }
-
oa = oa->outchain;
createarc(nfa, a->type, a->co, newState, a->to);
}
@@ -1446,6 +1418,11 @@ optimize(
fprintf(f, "\nfinal cleanup:\n");
}
cleanup(nfa); /* final tidying */
+#ifdef REG_DEBUG
+ if (verbose) {
+ dumpnfa(nfa, f);
+ }
+#endif
return analyze(nfa); /* and analysis */
}
@@ -1570,7 +1547,7 @@ pull(
if (NISERR()) {
return 0;
}
- copyins(nfa, from, s, 1); /* duplicate inarcs */
+ copyins(nfa, from, s); /* duplicate inarcs */
cparc(nfa, con, s, to); /* move constraint arc */
freearc(nfa, con);
if (NISERR()) {
@@ -1749,7 +1726,7 @@ push(
if (NISERR()) {
return 0;
}
- copyouts(nfa, to, s, 1); /* duplicate outarcs */
+ copyouts(nfa, to, s); /* duplicate outarcs */
cparc(nfa, con, from, s); /* move constraint arc */
freearc(nfa, con);
if (NISERR()) {
@@ -2958,6 +2935,8 @@ dumpnfa(
{
#ifdef REG_DEBUG
struct state *s;
+ int nstates = 0;
+ int narcs = 0;
fprintf(f, "pre %d, post %d", nfa->pre->no, nfa->post->no);
if (nfa->bos[0] != COLORLESS) {
@@ -2975,7 +2954,10 @@ dumpnfa(
fprintf(f, "\n");
for (s = nfa->states; s != NULL; s = s->next) {
dumpstate(s, f);
+ nstates++;
+ narcs += s->nouts;
}
+ fprintf(f, "total of %d states, %d arcs\n", nstates, narcs);
if (nfa->parent == NULL) {
dumpcolors(nfa->cm, f);
}
diff --git a/generic/regcomp.c b/generic/regcomp.c
index 3c91962..8287b7e 100644
--- a/generic/regcomp.c
+++ b/generic/regcomp.c
@@ -131,10 +131,10 @@ static int sortins_cmp(const void *, const void *);
static void sortouts(struct nfa *, struct state *);
static int sortouts_cmp(const void *, const void *);
static void moveins(struct nfa *, struct state *, struct state *);
-static void copyins(struct nfa *, struct state *, struct state *, int);
+static void copyins(struct nfa *, struct state *, struct state *);
static void mergeins(struct nfa *, struct state *, struct arc **, int);
static void moveouts(struct nfa *, struct state *, struct state *);
-static void copyouts(struct nfa *, struct state *, struct state *, int);
+static void copyouts(struct nfa *, struct state *, struct state *);
static void cloneouts(struct nfa *, struct state *, struct state *, struct state *, int);
static void delsub(struct nfa *, struct state *, struct state *);
static void deltraverse(struct nfa *, struct state *, struct state *);
@@ -173,7 +173,6 @@ static void dumpnfa(struct nfa *, FILE *);
#ifdef REG_DEBUG
static void dumpstate(struct state *, FILE *);
static void dumparcs(struct state *, FILE *);
-static int dumprarcs(struct arc *, struct state *, FILE *, int);
static void dumparc(struct arc *, struct state *, FILE *);
#endif
static void dumpcnfa(struct cnfa *, FILE *);
@@ -627,8 +626,9 @@ makesearch(
for (s=slist ; s!=NULL ; s=s2) {
s2 = newstate(nfa);
-
- copyouts(nfa, s, s2, 1);
+ NOERR();
+ copyouts(nfa, s, s2);
+ NOERR();
for (a=s->ins ; a!=NULL ; a=b) {
b = a->inchain;
@@ -2061,7 +2061,7 @@ dump(
dumpcolors(&g->cmap, f);
if (!NULLCNFA(g->search)) {
- printf("\nsearch:\n");
+ fprintf(f, "\nsearch:\n");
dumpcnfa(&g->search, f);
}
for (i = 1; i < g->nlacons; i++) {