summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-01-01 18:00:40 -0500
committerAdrian Thurston <thurston@complang.org>2013-01-01 18:00:40 -0500
commit77d5b90279ce68dd2239e9c95a59bcab61ad2930 (patch)
treed94512a48eb0d7921c50dd0a69596208a18e7782
parente3f122ddb9a970a2a0038fcc9486d72eb49d9231 (diff)
downloadcolm-77d5b90279ce68dd2239e9c95a59bcab61ad2930.tar.gz
removed pointers from FsmRun back to attached streams
These pointers are not necessary. "Attached" means "FsmRun holds the data of" a stream. Suffices to point from stream to FsmRun and when data is copied into an FsmRun to check if there is an other FsmRun holding the stream's data. At that point the detach can occur. Also unified the two stream attach/detach functions.
-rw-r--r--colm/input.c24
-rw-r--r--colm/pdarun.c39
-rw-r--r--colm/pdarun.h9
3 files changed, 19 insertions, 53 deletions
diff --git a/colm/input.c b/colm/input.c
index 294039de..8ff9f56b 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -463,7 +463,7 @@ int _getData( FsmRun *fsmRun, StreamImpl *is, int skip, char *dest, int length,
Stream *stream = (Stream*)buf->tree;
int type = stream->in->funcs->getData( fsmRun, stream->in, skip, dest, length, copied );
- attachSource( fsmRun, stream->in );
+ attachStream( fsmRun, stream->in );
if ( type == INPUT_EOD && is->eof ) {
ret = INPUT_EOF;
@@ -514,7 +514,7 @@ int _getData( FsmRun *fsmRun, StreamImpl *is, int skip, char *dest, int length,
buf = buf->next;
}
- attachInput( fsmRun, is );
+ attachStream( fsmRun, is );
#if DEBUG
switch ( ret ) {
@@ -597,7 +597,7 @@ int _undoConsumeData( FsmRun *fsmRun, StreamImpl *is, const char *data, int leng
int len = stream->in->funcs->undoConsumeData( fsmRun, stream->in, data, length );
if ( stream->in->attached != 0 )
- detachSource( stream->in->attached, stream->in );
+ detachStream( stream->in->attached, stream->in );
return len;
}
@@ -608,7 +608,7 @@ int _undoConsumeData( FsmRun *fsmRun, StreamImpl *is, const char *data, int leng
inputStreamPrepend( is, newBuf );
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
return length;
}
@@ -636,7 +636,7 @@ Tree *_consumeTree( StreamImpl *is )
void _undoConsumeTree( StreamImpl *is, Tree *tree, int ignore )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( 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
@@ -672,7 +672,7 @@ void _undoConsumeLangEl( StreamImpl *is )
void _prependData( StreamImpl *is, const char *data, long length )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( 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
@@ -689,7 +689,7 @@ void _prependData( StreamImpl *is, const char *data, long length )
int _undoPrependData( StreamImpl *is, int length )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
debug( REALM_INPUT, "consuming %d bytes\n", length );
@@ -738,7 +738,7 @@ int _undoPrependData( StreamImpl *is, int length )
void _prependTree( StreamImpl *is, Tree *tree, int ignore )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( 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
@@ -752,7 +752,7 @@ void _prependTree( StreamImpl *is, Tree *tree, int ignore )
Tree *_undoPrependTree( StreamImpl *is )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
while ( is->queue != 0 && is->queue->type == RunBufDataType && is->queue->offset == is->queue->length ) {
RunBuf *runBuf = inputStreamPopHead( is );
@@ -792,7 +792,7 @@ void _appendData( StreamImpl *is, const char *data, long len )
Tree *_undoAppendData( StreamImpl *is, int length )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
int consumed = 0;
@@ -854,7 +854,7 @@ void _appendStream( StreamImpl *in, struct ColmTree *tree )
Tree *_undoAppendStream( StreamImpl *is )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
RunBuf *runBuf = inputStreamPopTail( is );
Tree *tree = runBuf->tree;
@@ -865,7 +865,7 @@ Tree *_undoAppendStream( StreamImpl *is )
Tree *_undoAppendTree( StreamImpl *is )
{
if ( is->attached != 0 )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
RunBuf *runBuf = inputStreamPopTail( is );
Tree *tree = runBuf->tree;
diff --git a/colm/pdarun.c b/colm/pdarun.c
index e99a1fad..667a0eb5 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -70,8 +70,6 @@ void initFsmRun( FsmRun *fsmRun, Program *prg )
fsmRun->p = fsmRun->pe = fsmRun->runBuf->data;
fsmRun->peof = 0;
- fsmRun->attachedInput = 0;
- fsmRun->attachedSource = 0;
fsmRun->preRegion = -1;
}
@@ -250,58 +248,31 @@ static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsm
}
-void attachInput( FsmRun *fsmRun, StreamImpl *is )
+void attachStream( FsmRun *fsmRun, StreamImpl *is )
{
if ( is->attached != 0 && is->attached != fsmRun )
- detachInput( is->attached, is );
+ detachStream( is->attached, is );
if ( is->attached != fsmRun ) {
- debug( REALM_INPUT, "attaching fsm run to input stream: %p %p\n", fsmRun, is );
- fsmRun->attachedInput = is;
+ debug( REALM_INPUT, "attaching FsmRun to stream: %p %p\n", fsmRun, is );
is->attached = fsmRun;
}
}
-void attachSource( FsmRun *fsmRun, StreamImpl *ss )
+void detachStream( FsmRun *fsmRun, StreamImpl *is )
{
- if ( ss->attached != 0 && ss->attached != fsmRun )
- detachSource( ss->attached, ss );
+ debug( REALM_INPUT, "detaching FsmRun from stream: %p %p\n", fsmRun, is );
- 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 detachInput( FsmRun *fsmRun, StreamImpl *is )
-{
- debug( REALM_INPUT, "detaching fsm run from input stream: %p %p\n", fsmRun, is );
-
- fsmRun->attachedInput = 0;
is->attached = 0;
-
clearBuffered( fsmRun );
-
- if ( fsmRun->attachedSource != 0 ) {
- fsmRun->attachedSource->attached = 0;
- fsmRun->attachedSource = 0;
- }
}
void detachSource( FsmRun *fsmRun, StreamImpl *is )
{
debug( REALM_INPUT, "detaching fsm run from source stream: %p %p\n", fsmRun, is );
- fsmRun->attachedSource = 0;
is->attached = 0;
-
clearBuffered( fsmRun );
-
- if ( fsmRun->attachedInput != 0 ) {
- fsmRun->attachedInput->attached = 0;
- fsmRun->attachedInput = 0;
- }
}
void clearBuffered( FsmRun *fsmRun )
diff --git a/colm/pdarun.h b/colm/pdarun.h
index 73b3d0bb..cf159ead 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -83,9 +83,6 @@ typedef struct _FsmRun
int returnResult;
char *mark[MARK_SLOTS];
long matchedToken;
-
- StreamImpl *attachedInput;
- StreamImpl *attachedSource;
} FsmRun;
void initFsmRun( FsmRun *fsmRun, struct ColmProgram *prg );
@@ -463,10 +460,8 @@ void undoParseStream( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStrea
void clearBuffered( FsmRun *fsmRun );
void resetToken( FsmRun *fsmRun );
-void detachInput( FsmRun *fsmRun, StreamImpl *is );
-void attachInput( FsmRun *fsmRun, StreamImpl *is );
-void detachSource( FsmRun *fsmRun, StreamImpl *ss );
-void attachSource( FsmRun *fsmRun, StreamImpl *ss );
+void detachStream( FsmRun *fsmRun, StreamImpl *is );
+void attachStream( FsmRun *fsmRun, StreamImpl *is );
#ifdef __cplusplus
}