diff options
author | Adrian Thurston <thurston@complang.org> | 2012-05-12 11:22:52 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-05-12 11:22:52 -0400 |
commit | 0805fc9fab3812a408bddf0314f798a472e1b72c (patch) | |
tree | 810ac14176408b441d37b7485445500484d0fe91 | |
parent | 72f73c3c7877620fcecfd6fe8b2ffde183002fbc (diff) | |
download | colm-0805fc9fab3812a408bddf0314f798a472e1b72c.tar.gz |
Simplified the restore of accumulated parse trees when they are detached. Only
a single walk.
-rw-r--r-- | colm/pdarun.c | 25 | ||||
-rw-r--r-- | colm/tree.c | 19 |
2 files changed, 19 insertions, 25 deletions
diff --git a/colm/pdarun.c b/colm/pdarun.c index d0ee2f7a..e691fe20 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -320,20 +320,33 @@ void detachIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, Kid assert( leftIgnore != 0 ); /* Transfer the trees to accumIgnore. */ - pdaRun->accumIgnore = reverseKidList( parseTree->ignore ); + Kid *ignore = parseTree->ignore; parseTree->ignore = 0; - /* Put the data trees underneath the parse trees. */ - Kid *dataIgnore = reverseKidList( leftIgnore->child ); + Kid *dataIgnore = leftIgnore->child; leftIgnore->child = 0; - Kid *ignore = pdaRun->accumIgnore; + Kid *last = 0, *dataLast = 0; while ( ignore != 0 ) { + Kid *next = ignore->next; + Kid *dataNext = dataIgnore->next; + + /* Put the data trees underneath the parse trees. */ pt(ignore->tree)->shadow = dataIgnore; - ignore = ignore->next; - dataIgnore = dataIgnore->next; + /* Reverse. */ + ignore->next = last; + dataIgnore->next = dataLast; + + /* Keep last for reversal. */ + last = ignore; + dataLast = dataIgnore; + + ignore = next; + dataIgnore = dataNext; } + + pdaRun->accumIgnore = last; } treeDownref( prg, sp, leftIgnore ); diff --git a/colm/tree.c b/colm/tree.c index 1bdae1ab..dd263394 100644 --- a/colm/tree.c +++ b/colm/tree.c @@ -1001,25 +1001,6 @@ Kid *treeAttr( Program *prg, const Tree *tree ) return kid; } -Kid *reverseKidList( Kid *kid ) -{ - if ( kid != 0 ) { - /* Reverse the list. */ - Kid *last = 0; - while ( true ) { - Kid *next = kid->next; - kid->next = last; - - if ( next == 0 ) - break; - - last = kid; - kid = next; - } - } - return kid; -} - void attachLeftIgnore( Program *prg, Tree *tree, IgnoreList *ignoreList ) { assert( ! (tree->flags & AF_LEFT_IGNORE) ); |