diff options
author | Adrian Thurston <thurston@complang.org> | 2012-01-16 00:27:50 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-01-16 00:27:50 +0000 |
commit | 4d30106a01b776483cb4e6af1a220f962f282e3f (patch) | |
tree | f7e6d5c92154e018771bd4fb187bf6322fe36cf8 /colm | |
parent | 3243d15a0c97d1d7539bbd8ed39aed72f16ffcda (diff) | |
download | colm-4d30106a01b776483cb4e6af1a220f962f282e3f.tar.gz |
Bit of cleanup around attaching FSM run to input and source.
Diffstat (limited to 'colm')
-rw-r--r-- | colm/input.c | 44 | ||||
-rw-r--r-- | colm/input.h | 4 | ||||
-rw-r--r-- | colm/pdarun.c | 59 | ||||
-rw-r--r-- | colm/pdarun.h | 12 |
4 files changed, 61 insertions, 58 deletions
diff --git a/colm/input.c b/colm/input.c index 82902dfb..287a73a0 100644 --- a/colm/input.c +++ b/colm/input.c @@ -426,7 +426,7 @@ int getData( FsmRun *fsmRun, InputStream *is, int skip, char *dest, int length, Stream *stream = (Stream*)buf->tree; int type = stream->in->funcs->getData( stream->in, skip, dest, length, copied ); - attachInput2( fsmRun, stream->in ); + attachSource( fsmRun, stream->in ); if ( type == INPUT_EOD && is->eof ) { ret = INPUT_EOF; @@ -477,7 +477,7 @@ int getData( FsmRun *fsmRun, InputStream *is, int skip, char *dest, int length, buf = buf->next; } - attachInput1( fsmRun, is ); + attachInput( fsmRun, is ); #if DEBUG switch ( ret ) { @@ -559,8 +559,8 @@ int undoConsumeData( FsmRun *fsmRun, InputStream *is, const char *data, int leng Stream *stream = (Stream*)is->queue->tree; int len = stream->in->funcs->undoConsumeData( stream->in, data, length ); - if ( stream->in->attached2 != 0 ) - detachInput2( stream->in->attached2, stream->in ); + if ( stream->in->attached != 0 ) + detachSource( stream->in->attached, stream->in ); return len; } @@ -570,8 +570,8 @@ int undoConsumeData( FsmRun *fsmRun, InputStream *is, const char *data, int leng memcpy( newBuf->data, data, length ); inputStreamPrepend( is, newBuf ); - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); return length; } @@ -598,8 +598,8 @@ Tree *consumeTree( InputStream *is ) void undoConsumeTree( InputStream *is, Tree *tree, int ignore ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of @@ -634,8 +634,8 @@ void undoConsumeLangEl( InputStream *is ) void prependData( InputStream *is, const char *data, long length ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of @@ -651,8 +651,8 @@ void prependData( InputStream *is, const char *data, long length ) int undoPrependData( InputStream *is, int length ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); debug( REALM_INPUT, "consuming %d bytes\n", length ); @@ -700,8 +700,8 @@ int undoPrependData( InputStream *is, int length ) void prependTree( InputStream *is, Tree *tree, int ignore ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of @@ -714,8 +714,8 @@ void prependTree( InputStream *is, Tree *tree, int ignore ) Tree *undoPrependTree( InputStream *is ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); while ( is->queue != 0 && is->queue->type == RunBufDataType && is->queue->offset == is->queue->length ) { RunBuf *runBuf = inputStreamPopHead( is ); @@ -754,8 +754,8 @@ void appendData( InputStream *is, const char *data, long len ) Tree *undoAppendData( InputStream *is, int length ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); int consumed = 0; @@ -816,8 +816,8 @@ void appendStream( InputStream *in, struct ColmTree *tree ) Tree *undoAppendStream( InputStream *is ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); RunBuf *runBuf = inputStreamPopTail( is ); Tree *tree = runBuf->tree; @@ -827,8 +827,8 @@ Tree *undoAppendStream( InputStream *is ) Tree *undoAppendTree( InputStream *is ) { - if ( is->attached1 != 0 ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 ) + detachInput( is->attached, is ); RunBuf *runBuf = inputStreamPopTail( is ); Tree *tree = runBuf->tree; diff --git a/colm/input.h b/colm/input.h index 773b1bc8..e6ef3439 100644 --- a/colm/input.h +++ b/colm/input.h @@ -132,7 +132,7 @@ struct _SourceStream struct Replacement *replacement; struct ReplItem *replItem; - struct _FsmRun *attached2; + struct _FsmRun *attached; }; SourceStream *newSourceStreamPattern( struct Pattern *pattern ); @@ -174,7 +174,7 @@ struct _InputStream struct Replacement *replacement; struct ReplItem *replItem; - struct _FsmRun *attached1; + struct _FsmRun *attached; }; typedef struct _InputStream InputStream; diff --git a/colm/pdarun.c b/colm/pdarun.c index 9782caf2..ff93e544 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -71,8 +71,8 @@ void initFsmRun( FsmRun *fsmRun, Program *prg ) fsmRun->p = fsmRun->pe = fsmRun->runBuf->data; fsmRun->peof = 0; - fsmRun->attached1 = 0; - fsmRun->attached2 = 0; + fsmRun->attachedInput = 0; + fsmRun->attachedSource = 0; } void clearFsmRun( Program *prg, FsmRun *fsmRun ) @@ -317,57 +317,60 @@ void detachIgnores( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, Kid treeDownref( prg, sp, leftIgnore ); } -void attachInput1( FsmRun *fsmRun, InputStream *is ) +void attachInput( FsmRun *fsmRun, InputStream *is ) { - if ( is->attached1 != 0 && is->attached1 != fsmRun ) - detachInput1( is->attached1, is ); + if ( is->attached != 0 && is->attached != fsmRun ) + detachInput( is->attached, is ); - debug( REALM_INPUT, "attaching fsm run to input stream: %p %p\n", fsmRun, is ); - fsmRun->attached1 = is; - is->attached1 = fsmRun; + if ( is->attached != fsmRun ) { + debug( REALM_INPUT, "attaching fsm run to input stream: %p %p\n", fsmRun, is ); + fsmRun->attachedInput = is; + is->attached = fsmRun; + } } -void attachInput2( FsmRun *fsmRun, SourceStream *is ) +void attachSource( FsmRun *fsmRun, SourceStream *ss ) { - if ( is->attached2 != 0 && is->attached2 != fsmRun ) - detachInput2( is->attached2, is ); + if ( ss->attached != 0 && ss->attached != fsmRun ) + detachSource( ss->attached, ss ); - debug( REALM_INPUT, "attaching fsm run to source stream: %p %p\n", fsmRun, is ); - fsmRun->attached2 = is; - is->attached2 = fsmRun; + if ( ss->attached != fsmRun ) { + debug( REALM_INPUT, "attaching fsm run to source stream: %p %p\n", fsmRun, ss ); + fsmRun->attachedSource = ss; + ss->attached = fsmRun; + } } -void detachInput1( FsmRun *fsmRun, InputStream *is ) +void detachInput( FsmRun *fsmRun, InputStream *is ) { debug( REALM_INPUT, "detaching fsm run from input stream: %p %p\n", fsmRun, is ); - fsmRun->attached1 = 0; - is->attached1 = 0; + fsmRun->attachedInput = 0; + is->attached = 0; clearBuffered( fsmRun ); - if ( fsmRun->attached2 != 0 ) { - fsmRun->attached2->attached2 = 0; - fsmRun->attached2 = 0; + if ( fsmRun->attachedSource != 0 ) { + fsmRun->attachedSource->attached = 0; + fsmRun->attachedSource = 0; } } -void detachInput2( FsmRun *fsmRun, SourceStream *is ) +void detachSource( FsmRun *fsmRun, SourceStream *is ) { debug( REALM_INPUT, "detaching fsm run from source stream: %p %p\n", fsmRun, is ); - fsmRun->attached2 = 0; - is->attached2 = 0; + fsmRun->attachedSource = 0; + is->attached = 0; clearBuffered( fsmRun ); - if ( fsmRun->attached1 != 0 ) { - fsmRun->attached1->attached1 = 0; - fsmRun->attached1 = 0; + if ( fsmRun->attachedInput != 0 ) { + fsmRun->attachedInput->attached = 0; + fsmRun->attachedInput = 0; } } - void clearBuffered( FsmRun *fsmRun ) { /* If there is data in the current buffer then send the whole send back @@ -1028,7 +1031,7 @@ case PcrStart: pdaRun->stop = false; while ( true ) { - debug( REALM_PARSE, "parse loop start\n" ); + debug( REALM_PARSE, "parse loop start %d:%d\n", inputStream->line, inputStream->column ); /* Pull the current scanner from the parser. This can change during * parsing due to inputStream pushes, usually for the purpose of includes. diff --git a/colm/pdarun.h b/colm/pdarun.h index 5a79fb9f..1e683e60 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -83,8 +83,8 @@ typedef struct _FsmRun char *mark[MARK_SLOTS]; long matchedToken; - InputStream *attached1; - SourceStream *attached2; + InputStream *attachedInput; + SourceStream *attachedSource; } FsmRun; void initFsmRun( FsmRun *fsmRun, struct ColmProgram *prg ); @@ -456,10 +456,10 @@ void detachIgnores( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, FsmRun * void clearBuffered( FsmRun *fsmRun ); void resetToken( FsmRun *fsmRun ); -void detachInput1( FsmRun *fsmRun, InputStream *is ); -void attachInput1( FsmRun *fsmRun, InputStream *is ); -void detachInput2( FsmRun *fsmRun, SourceStream *is ); -void attachInput2( FsmRun *fsmRun, SourceStream *is ); +void detachInput( FsmRun *fsmRun, InputStream *is ); +void attachInput( FsmRun *fsmRun, InputStream *is ); +void detachSource( FsmRun *fsmRun, SourceStream *ss ); +void attachSource( FsmRun *fsmRun, SourceStream *ss ); #ifdef __cplusplus } |