diff options
author | Adrian Thurston <thurston@complang.org> | 2012-05-17 09:05:31 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-05-17 09:05:31 -0400 |
commit | c29e6a911513cac0fb6b780ac052a92fb70b8f96 (patch) | |
tree | 559930c840d63f4c5a5c653c5ff337c8d62135aa | |
parent | 830657d3dc49c3276c1c3e5ff8fe76908022fb3c (diff) | |
download | colm-c29e6a911513cac0fb6b780ac052a92fb70b8f96.tar.gz |
Use the parse trees in the bindings array. Probably can turn this into a bit in
the parse tree, but that is a change for another day.
-rw-r--r-- | colm/ctinput.cc | 22 | ||||
-rw-r--r-- | colm/fsmcodegen.cc | 4 | ||||
-rw-r--r-- | colm/parsedata.h | 2 | ||||
-rw-r--r-- | colm/pdabuild.cc | 2 | ||||
-rw-r--r-- | colm/pdarun.c | 35 | ||||
-rw-r--r-- | colm/pdarun.h | 6 |
6 files changed, 33 insertions, 38 deletions
diff --git a/colm/ctinput.cc b/colm/ctinput.cc index 0a6a86c6..b5086268 100644 --- a/colm/ctinput.cc +++ b/colm/ctinput.cc @@ -405,15 +405,15 @@ void sendNamedLangEl( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, I Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, inputStream, klangEl->id, tokdata ); - if ( bindId > 0 ) - makeTokenPushBinding( pdaRun, bindId, input->tree ); - incrementSteps( pdaRun ); ParseTree *parseTree = parseTreeAllocate( prg ); parseTree->id = input->tree->id; parseTree->flags |= PF_NAMED; parseTree->shadow = input; + + if ( bindId > 0 ) + pushBinding( pdaRun, parseTree ); pdaRun->parseInput = parseTree; } @@ -425,21 +425,15 @@ void initBindings( PdaRun *pdaRun ) pdaRun->bindings->push(0); } -void makeTokenPushBinding( PdaRun *pdaRun, int bindId, Tree *tree ) +void pushBinding( PdaRun *pdaRun, ParseTree *parseTree ) { /* If the item is bound then store it in the bindings array. */ - if ( bindId > 0 ) { - pdaRun->bindings->push( tree ); - treeUpref( tree ); - } + pdaRun->bindings->push( parseTree ); } -void unbind( Program *prg, Tree **sp, PdaRun *pdaRun, Tree *tree ) +void popBinding( PdaRun *pdaRun, ParseTree *parseTree ) { - Tree *lastBound = pdaRun->bindings->top(); - if ( lastBound == tree ) { + ParseTree *lastBound = pdaRun->bindings->top(); + if ( lastBound == parseTree ) pdaRun->bindings->pop(); - treeDownref( prg, sp, tree ); - } } - diff --git a/colm/fsmcodegen.cc b/colm/fsmcodegen.cc index 2a401764..d98e6b0b 100644 --- a/colm/fsmcodegen.cc +++ b/colm/fsmcodegen.cc @@ -1071,8 +1071,8 @@ void FsmCodeGen::writeCode() "void sendNamedLangEl( Program *prg, Tree **tree, PdaRun *pdaRun,\n" " FsmRun *fsmRun, InputStream *inputStream ) { }\n" "void initBindings( PdaRun *pdaRun ) {}\n" - "void makeTokenPushBinding( PdaRun *pdaRun, int bindId, Tree *tree ) {}\n" - "void unbind( Program *prg, Tree **sp, PdaRun *pdaRun, Tree *tree ) {}\n" + "void pushBinding( PdaRun *pdaRun, ParseTree *parseTree ) {}\n" + "void popBinding( PdaRun *pdaRun, ParseTree *tree ) {}\n" "void initStaticFuncs() {}\n" "void initPatternFuncs() {}\n" "void initReplFuncs() {}\n" diff --git a/colm/parsedata.h b/colm/parsedata.h index 8d2f4014..695a36a2 100644 --- a/colm/parsedata.h +++ b/colm/parsedata.h @@ -76,7 +76,7 @@ struct Definition; * runtime code. The runtime functions that access it are defined in * ctinput.cpp and stubbed in fsmcodegen.cpp */ struct Bindings - : public Vector<Tree*> + : public Vector<ParseTree*> {}; struct DefListEl { Definition *prev, *next; }; diff --git a/colm/pdabuild.cc b/colm/pdabuild.cc index c5dc709f..61d00637 100644 --- a/colm/pdabuild.cc +++ b/colm/pdabuild.cc @@ -1658,7 +1658,7 @@ void fillNodes( Program *prg, int &nextAvail, Bindings *bindings, long &bindId, /* Since the parser is bottom up the bindings are in a bottom up * traversal order. Check after recursing. */ node.bindId = 0; - if ( bindId < bindings->length() && bindings->data[bindId] == kid->tree ) { + if ( bindId < bindings->length() && bindings->data[bindId] == parseTree ) { /* Remember that binding ids are indexed from one. */ node.bindId = bindId++; diff --git a/colm/pdarun.c b/colm/pdarun.c index b5643edc..e648df1e 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -334,13 +334,12 @@ void resetToken( FsmRun *fsmRun ) * PcrRevToken */ - static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, - InputStream *inputStream, ParseTree *input ) + InputStream *inputStream, ParseTree *parseTree ) { - debug( REALM_PARSE, "sending back: %s\n", prg->rtd->lelInfo[input->id].name ); + debug( REALM_PARSE, "sending back: %s\n", prg->rtd->lelInfo[parseTree->id].name ); - if ( input->flags & PF_NAMED ) { + if ( parseTree->flags & PF_NAMED ) { ///* Send back anything in the buffer that has not been parsed. */ //if ( fsmRun->p == fsmRun->runBuf->data ) // sendBackRunBufHead( fsmRun, inputStream ); @@ -353,36 +352,36 @@ static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, decrementSteps( pdaRun ); /* Artifical were not parsed, instead sent in as items. */ - if ( input->flags & PF_ARTIFICIAL ) { + if ( parseTree->flags & PF_ARTIFICIAL ) { /* Check for reverse code. */ - if ( input->flags & PF_HAS_RCODE ) { + if ( parseTree->flags & PF_HAS_RCODE ) { debug( REALM_PARSE, "tree has rcode, setting on deck\n" ); pdaRun->onDeck = true; - input->flags &= ~PF_HAS_RCODE; + parseTree->flags &= ~PF_HAS_RCODE; } - treeUpref( input->shadow->tree ); + treeUpref( parseTree->shadow->tree ); - sendBackTree( inputStream, input->shadow->tree ); + sendBackTree( inputStream, parseTree->shadow->tree ); } else { /* Check for reverse code. */ - if ( input->flags & PF_HAS_RCODE ) { + if ( parseTree->flags & PF_HAS_RCODE ) { debug( REALM_PARSE, "tree has rcode, setting on deck\n" ); pdaRun->onDeck = true; - input->flags &= ~PF_HAS_RCODE; + parseTree->flags &= ~PF_HAS_RCODE; } /* Push back the token data. */ - sendBackText( fsmRun, inputStream, stringData( input->shadow->tree->tokdata ), - stringLength( input->shadow->tree->tokdata ) ); + sendBackText( fsmRun, inputStream, stringData( parseTree->shadow->tree->tokdata ), + stringLength( parseTree->shadow->tree->tokdata ) ); /* If eof was just sent back remember that it needs to be sent again. */ - if ( input->id == prg->rtd->eofLelIds[pdaRun->parserId] ) + if ( parseTree->id == prg->rtd->eofLelIds[pdaRun->parserId] ) inputStream->eofSent = false; /* If the item is bound then store remove it from the bindings array. */ - unbind( prg, sp, pdaRun, input->shadow->tree ); + popBinding( pdaRun, parseTree ); } if ( pdaRun->steps == pdaRun->targetSteps ) { @@ -391,9 +390,9 @@ static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, } /* Downref the tree that was sent back and free the kid. */ - treeDownref( prg, sp, input->shadow->tree ); - kidFree( prg, input->shadow ); - parseTreeFree( prg, input ); + treeDownref( prg, sp, parseTree->shadow->tree ); + kidFree( prg, parseTree->shadow ); + parseTreeFree( prg, parseTree ); } void setRegion( PdaRun *pdaRun, int emptyIgnore, ParseTree *tree ) diff --git a/colm/pdarun.h b/colm/pdarun.h index a1dc9555..f14e5f21 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -426,10 +426,12 @@ void streamPushText( FsmRun *fsmRun, InputStream *inputStream, const char *data, void streamPushTree( FsmRun *fsmRun, InputStream *inputStream, Tree *tree, int ignore ); void undoStreamPush( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, InputStream *inputStream, long length ); void undoStreamAppend( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, InputStream *inputStream, struct ColmTree *tree, long length ); -void unbind( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, Tree *tree ); Kid *makeTokenWithData( struct ColmProgram *prg, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, int id, Head *tokdata ); -void makeTokenPushBinding( PdaRun *pdaRun, int bindId, Tree *tree ); + +void pushBinding( PdaRun *pdaRun, ParseTree *parseTree ); +void popBinding( PdaRun *pdaRun, ParseTree *parseTree ); + void executeGenerationAction( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, PdaRun *pdaRun, InputStream *inputStream, int frameId, Code *code, long id, Head *tokdata ); Kid *extractIgnore( PdaRun *pdaRun ); |