summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-05-14 11:57:05 -0400
committerAdrian Thurston <thurston@complang.org>2012-05-14 11:57:05 -0400
commitc07ff3da211df08d3fcbc3ea0b7fe67350a08142 (patch)
tree1ae1f0712869bd9d6c1a3378830285d53b4428ee
parent4c7b1e79d8c07485c067833cee998123acfcf57f (diff)
downloadcolm-c07ff3da211df08d3fcbc3ea0b7fe67350a08142.tar.gz
Added a separate Kid data structure for use with parse trees.
-rw-r--r--colm/pdarun.c41
-rw-r--r--colm/pdarun.h2
-rw-r--r--colm/pool.c14
-rw-r--r--colm/pool.h3
-rw-r--r--colm/tree.h12
5 files changed, 49 insertions, 23 deletions
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 25bcbfdb..6cec9c6c 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -224,9 +224,9 @@ void sendBackTree( InputStream *inputStream, Tree *tree )
* PcrRevIgnore
*/
static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun,
- InputStream *inputStream, Kid *_ignore )
+ InputStream *inputStream, Kid2 *_ignore )
{
- Kid *ignoreKidList = pt(_ignore->tree)->shadow;
+ Kid *ignoreKidList = _ignore->tree->shadow;
Kid *ignore = ignoreKidList;
#ifdef COLM_LOG
@@ -259,8 +259,6 @@ static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsm
kidFree( prg, ignore );
}
-
-
void attachInput( FsmRun *fsmRun, InputStream *is )
{
if ( is->attached != 0 && is->attached != fsmRun )
@@ -431,15 +429,15 @@ void ignoreTree( Program *prg, PdaRun *pdaRun, Tree *tree )
parseTree->shadow = kidAllocate( prg );
parseTree->shadow->tree = tree;
- Kid *ignore = kidAllocate( prg );
- ignore->tree = (Tree*)parseTree;
+ Kid2 *ignore = kid2Allocate( prg );
+ ignore->tree = parseTree;
ignore->next = pdaRun->accumIgnore;
pdaRun->accumIgnore = ignore;
transferReverseCode( pdaRun, (Tree*)parseTree );
- setRegion( pdaRun, emptyIgnore, pt(pdaRun->accumIgnore->tree) );
+ setRegion( pdaRun, emptyIgnore, pdaRun->accumIgnore->tree );
}
Kid *makeTokenWithData( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, int id,
@@ -554,18 +552,18 @@ static void attachIgnoreRight( Program *prg, Tree **sp, PdaRun *pdaRun )
/* The data list needs to be extracted and reversed. The parse tree list
* can remain in stack order. */
- Kid *child = pdaRun->accumIgnore, *last = 0;
- Kid *dataChild = 0;
+ Kid2 *child = pdaRun->accumIgnore;
+ Kid *dataChild = 0, *dataLast = 0;
while ( child ) {
- dataChild = pt(child->tree)->shadow;
+ dataChild = child->tree->shadow;
Kid *kid = kidAllocate( prg );
kid->tree = dataChild->tree;
- kid->next = last;
+ kid->next = dataLast;
treeUpref( kid->tree );
- last = kid;
+ dataLast = kid;
child = child->next;
}
@@ -615,17 +613,17 @@ static void attachIgnoreLeft( Program *prg, Tree **sp, PdaRun *pdaRun, Kid *to )
input->tree->flags &= ~AF_LEFT_IL_ATTACHED;
input->tree->flags &= ~AF_RIGHT_IL_ATTACHED;
- Kid *accum = pdaRun->accumIgnore;
+ Kid2 *accum = pdaRun->accumIgnore;
pdaRun->accumIgnore = 0;
/* The data list needs to be extracted and reversed. The parse tree list
* can remain in stack order. */
- Kid *child = accum, *last = 0;
+ Kid2 *child = accum, *last = 0;
Kid *dataChild = 0, *dataLast = 0;
while ( child ) {
dataChild = pt(child->tree)->shadow;
- Kid *next = child->next;
+ Kid2 *next = child->next;
/* Reverse the lists. */
dataChild->next = dataLast;
@@ -745,19 +743,20 @@ static void detachIgnoreLeft( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *f
assert( leftIgnore != 0 );
/* Transfer the trees to accumIgnore. */
- Kid *ignore = parseTree->ignore;
+ Kid2 *ignore = parseTree->ignore;
parseTree->ignore = 0;
Kid *dataIgnore = leftIgnore->child;
leftIgnore->child = 0;
- Kid *last = 0, *dataLast = 0;
+ Kid2 *last = 0;
+ Kid *dataLast = 0;
while ( ignore != 0 ) {
- Kid *next = ignore->next;
+ Kid2 *next = ignore->next;
Kid *dataNext = dataIgnore->next;
/* Put the data trees underneath the parse trees. */
- pt(ignore->tree)->shadow = dataIgnore;
+ ignore->tree->shadow = dataIgnore;
/* Reverse. */
ignore->next = last;
@@ -2178,11 +2177,11 @@ case PcrReverse:
/* Send back any accumulated ignore tokens, then trigger error
* in the the parser. */
- Kid *ignore = pdaRun->accumIgnore;
+ Kid2 *ignore = pdaRun->accumIgnore;
pdaRun->accumIgnore = pdaRun->accumIgnore->next;
ignore->next = 0;
- long region = pt(ignore->tree)->region;
+ long region = ignore->tree->region;
pdaRun->next = region > 0 ? region + 1 : 0;
pdaRun->checkNext = true;
pdaRun->checkStop = true;
diff --git a/colm/pdarun.h b/colm/pdarun.h
index 62fc0a9d..80ea2869 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -286,7 +286,7 @@ typedef struct _PdaRun
int stopParsing;
long stopTarget;
- Kid *accumIgnore;
+ Kid2 *accumIgnore;
Kid *btPoint;
diff --git a/colm/pool.c b/colm/pool.c
index ee2196bd..148b3ec1 100644
--- a/colm/pool.c
+++ b/colm/pool.c
@@ -157,6 +157,20 @@ long kidNumLost( Program *prg )
}
/*
+ * Kid2
+ */
+
+Kid2 *kid2Allocate( Program *prg )
+{
+ return (Kid2*) kidAllocate( prg );
+}
+
+void kid2Free( Program *prg, Kid2 *el )
+{
+ kidFree( prg, (Kid2*)el );
+}
+
+/*
* Tree
*/
diff --git a/colm/pool.h b/colm/pool.h
index da95e454..0bb167f8 100644
--- a/colm/pool.h
+++ b/colm/pool.h
@@ -40,6 +40,9 @@ void kidFree( Program *prg, Kid *el );
void kidClear( Program *prg );
long kidNumLost( Program *prg );
+Kid2 *kid2Allocate( Program *prg );
+void kid2Free( Program *prg, Kid2 *el );
+
Tree *treeAllocate( Program *prg );
void treeFree( Program *prg, Tree *el );
void treeClear( Program *prg );
diff --git a/colm/tree.h b/colm/tree.h
index f1b1bd8b..d846e561 100644
--- a/colm/tree.h
+++ b/colm/tree.h
@@ -65,6 +65,16 @@ typedef struct ColmKid
unsigned char flags;
} Kid;
+typedef struct ColmKid2
+{
+ /* The tree needs to be first since pointers to kids are used to reference
+ * trees on the stack. A pointer to the word that is a Tree* is cast to
+ * a Kid*. */
+ struct _ParseTree *tree;
+ struct ColmKid2 *next;
+ unsigned char flags;
+} Kid2;
+
typedef struct _Ref
{
struct ColmKid *kid;
@@ -125,7 +135,7 @@ typedef struct _ParseTree
char retryUpper;
Kid *shadow;
- Kid *ignore;
+ Kid2 *ignore;
} ParseTree;
typedef struct _Int