summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-12-31 16:33:18 -0500
committerAdrian Thurston <thurston@complang.org>2012-12-31 16:33:18 -0500
commitc6e716adc4a646824715536741ea55aa89a44c5a (patch)
tree3d1def71ff52335a843e1e85133cd75637571eab
parentf2cc568992508e4baa5427bfa740e7b518bc366b (diff)
downloadcolm-c6e716adc4a646824715536741ea55aa89a44c5a.tar.gz
unification of stream types
Added function pointers for the stream functions called the parser runtime. Now using StreamFuncs as the interface to the stream. Renamed both InputStream and SourceStream to StreamImpl. This takes us closer to a unified stream type.
-rw-r--r--colm/bytecode.c24
-rw-r--r--colm/bytecode.h2
-rw-r--r--colm/compiler.cc12
-rw-r--r--colm/ctinput.cc54
-rw-r--r--colm/fsmexec.cc2
-rw-r--r--colm/input.c137
-rw-r--r--colm/input.h91
-rw-r--r--colm/parsedata.h2
-rw-r--r--colm/pdarun.c192
-rw-r--r--colm/pdarun.h60
-rw-r--r--colm/tree.c2
-rw-r--r--colm/tree.h4
12 files changed, 317 insertions, 265 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c
index cb4d50e0..ac0a8b04 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -158,7 +158,7 @@ Head *treeToStr( Program *prg, Tree **sp, Tree *tree, int trim )
return ret;
}
-Word streamAppend( Program *prg, Tree **sp, Tree *input, InputStream *inputStream )
+Word streamAppend( Program *prg, Tree **sp, Tree *input, StreamImpl *is )
{
long length = 0;
@@ -169,17 +169,17 @@ Word streamAppend( Program *prg, Tree **sp, Tree *input, InputStream *inputStrea
printTreeCollect( prg, sp, &collect, input, true );
/* Load it into the input. */
- appendData( inputStream, collect.data, collect.length );
+ is->funcs->appendData( is, collect.data, collect.length );
length = collect.length;
strCollectDestroy( &collect );
}
else if ( input->id == LEL_ID_STREAM ) {
treeUpref( input );
- appendStream( inputStream, input );
+ is->funcs->appendStream( is, input );
}
else {
treeUpref( input );
- appendTree( inputStream, input );
+ is->funcs->appendTree( is, input );
}
return length;
@@ -220,7 +220,7 @@ switch ( entry ) {
case PcrStart:
if ( parser->pdaRun->stopTarget <= 0 ) {
- setEof( parser->input->in );
+ parser->input->in->funcs->setEof( parser->input->in );
if ( ! parser->pdaRun->parseError ) {
long pcr = parseLoop( prg, sp, parser->pdaRun, parser->fsmRun, parser->input->in, entry );
@@ -259,7 +259,7 @@ break; }
long undoParseFrag( Program *prg, Tree **sp, Parser *parser, long steps, long entry )
{
- InputStream *inputStream = parser->input->in;
+ StreamImpl *is = parser->input->in;
FsmRun *fsmRun = parser->fsmRun;
PdaRun *pdaRun = parser->pdaRun;
@@ -278,7 +278,7 @@ case PcrStart:
pdaRun->triggerUndo = 1;
/* The parse loop will recognise the situation. */
- long pcr = parseLoop( prg, sp, pdaRun, fsmRun, inputStream, entry );
+ long pcr = parseLoop( prg, sp, pdaRun, fsmRun, is, entry );
while ( pcr != PcrDone ) {
return pcr;
@@ -287,7 +287,7 @@ case PcrGeneration:
case PcrPreEof:
case PcrReverse:
- pcr = parseLoop( prg, sp, pdaRun, fsmRun, inputStream, entry );
+ pcr = parseLoop( prg, sp, pdaRun, fsmRun, is, entry );
}
/* Reset environment. */
@@ -302,21 +302,21 @@ break; }
return PcrDone;
}
-Tree *streamPullBc( Program *prg, FsmRun *fsmRun, InputStream *in, Tree *length )
+Tree *streamPullBc( Program *prg, FsmRun *fsmRun, StreamImpl *in, Tree *length )
{
long len = ((Int*)length)->value;
Head *tokdata = streamPull( prg, fsmRun, in, len );
return constructString( prg, tokdata );
}
-void undoPull( Program *prg, InputStream *in, Tree *str )
+void undoPull( Program *prg, StreamImpl *in, Tree *str )
{
const char *data = stringData( ( (Str*)str )->value );
long length = stringLength( ( (Str*)str )->value );
undoStreamPull( in, data, length );
}
-long streamPush( Program *prg, Tree **sp, FsmRun *fsmRun, InputStream *in, Tree *tree, int ignore )
+long streamPush( Program *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *in, Tree *tree, int ignore )
{
if ( tree->id == LEL_ID_STR ) {
/* This should become a compile error. If it's text, it's up to the
@@ -2443,7 +2443,7 @@ again:
exec->pcr = (long)vm_pop();
exec->parser = (Parser*)vm_pop();
- unsetEof( parser->input->in );
+ parser->input->in->funcs->unsetEof( parser->input->in );
treeDownref( prg, sp, (Tree*)parser );
break;
}
diff --git a/colm/bytecode.h b/colm/bytecode.h
index 376b76f5..2e115339 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -499,7 +499,7 @@ void allocGlobal( struct ColmProgram *prg );
Tree **executeCode( struct ColmProgram *prg, Execution *exec, Tree **sp, Code *instr );
void rcodeDownref( struct ColmProgram *prg, Tree **sp, Code *instr );
Code *popReverseCode( RtCodeVect *allRev );
-void sendBackBuffered( FsmRun *fsmRun, InputStream *inputStream );
+void sendBackBuffered( FsmRun *fsmRun, StreamImpl *inputStream );
#ifdef __cplusplus
}
diff --git a/colm/compiler.cc b/colm/compiler.cc
index b6afa899..2c0d1a0e 100644
--- a/colm/compiler.cc
+++ b/colm/compiler.cc
@@ -1237,9 +1237,9 @@ void Compiler::initEmptyScanners()
}
PdaRun *Compiler::parsePattern( Program *prg, Tree **sp, const InputLoc &loc,
- int parserId, SourceStream *sourceStream )
+ int parserId, StreamImpl *sourceStream )
{
- InputStream *in = new InputStream;
+ StreamImpl *in = new StreamImpl;
FsmRun *fsmRun = new FsmRun;
PdaRun *pdaRun = new PdaRun;
@@ -1250,8 +1250,8 @@ PdaRun *Compiler::parsePattern( Program *prg, Tree **sp, const InputLoc &loc,
Stream *res = streamAllocate( prg );
res->id = LEL_ID_STREAM;
res->in = sourceStream;
- appendStream( in, (Tree*)res );
- setEof( in );
+ in->funcs->appendStream( in, (Tree*)res );
+ in->funcs->setEof( in );
newToken( prg, pdaRun, fsmRun );
long pcr = parseLoop( prg, sp, pdaRun, fsmRun, in, PcrStart );
@@ -1281,12 +1281,12 @@ void Compiler::parsePatterns()
Tree **sp = prg->stackRoot;
for ( ConsList::Iter cons = replList; cons.lte(); cons++ ) {
- SourceStream *in = newSourceStreamCons( cons );
+ StreamImpl *in = newSourceStreamCons( cons );
cons->pdaRun = parsePattern( prg, sp, cons->loc, cons->langEl->parserId, in );
}
for ( PatList::Iter pat = patternList; pat.lte(); pat++ ) {
- SourceStream *in = newSourceStreamPat( pat );
+ StreamImpl *in = newSourceStreamPat( pat );
pat->pdaRun = parsePattern( prg, sp, pat->loc, pat->langEl->parserId, in );
}
diff --git a/colm/ctinput.cc b/colm/ctinput.cc
index dca56a3b..a10d03f5 100644
--- a/colm/ctinput.cc
+++ b/colm/ctinput.cc
@@ -31,24 +31,24 @@
using std::cerr;
using std::endl;
-SourceFuncs patternFuncs;
-SourceFuncs replFuncs;
+StreamFuncs patternFuncs;
+StreamFuncs replFuncs;
/*
* Pattern
*/
-SourceStream *newSourceStreamPat( Pattern *pattern )
+StreamImpl *newSourceStreamPat( Pattern *pattern )
{
- SourceStream *ss = (SourceStream*)malloc(sizeof(SourceStream));
- memset( ss, 0, sizeof(SourceStream) );
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ memset( ss, 0, sizeof(StreamImpl) );
ss->pattern = pattern;
ss->patItem = pattern->list->head;
ss->funcs = &patternFuncs;
return ss;
}
-LangEl *inputStreamPatternGetLangEl( SourceStream *ss, long *bindId, char **data, long *length )
+LangEl *inputStreamPatternGetLangEl( StreamImpl *ss, long *bindId, char **data, long *length )
{
LangEl *klangEl = ss->patItem->factor->langEl;
*bindId = ss->patItem->bindId;
@@ -60,7 +60,7 @@ LangEl *inputStreamPatternGetLangEl( SourceStream *ss, long *bindId, char **data
return klangEl;
}
-int inputStreamPatternGetData( SourceStream *ss, int skip, char *dest, int length, int *copied )
+int inputStreamPatternGetData( FsmRun *fsmRun, StreamImpl *ss, int skip, char *dest, int length, int *copied )
{
*copied = 0;
@@ -107,7 +107,7 @@ int inputStreamPatternGetData( SourceStream *ss, int skip, char *dest, int lengt
return INPUT_DATA;
}
-void inputStreamPatternBackup( SourceStream *ss )
+void inputStreamPatternBackup( StreamImpl *ss )
{
if ( ss->patItem == 0 )
ss->patItem = ss->pattern->list->tail;
@@ -115,7 +115,7 @@ void inputStreamPatternBackup( SourceStream *ss )
ss->patItem = ss->patItem->prev;
}
-void inputStreamPatternPushBackBuf( SourceStream *ss, RunBuf *runBuf )
+void inputStreamPatternPushBackBuf( StreamImpl *ss, RunBuf *runBuf )
{
char *data = runBuf->data + runBuf->offset;
long length = runBuf->length;
@@ -136,13 +136,13 @@ void inputStreamPatternPushBackBuf( SourceStream *ss, RunBuf *runBuf )
assert( memcmp( &ss->patItem->data[ss->offset], data, length ) == 0 );
}
-void inputStreamPatternUndoConsumeLangEl( SourceStream *ss )
+void inputStreamPatternUndoConsumeLangEl( StreamImpl *ss )
{
inputStreamPatternBackup( ss );
ss->offset = ss->patItem->data.length();
}
-int inputStreamPatternConsumeData( SourceStream *ss, int length )
+int inputStreamPatternConsumeData( StreamImpl *ss, int length )
{
debug( REALM_INPUT, "consuming %ld bytes\n", length );
@@ -176,7 +176,7 @@ int inputStreamPatternConsumeData( SourceStream *ss, int length )
return consumed;
}
-int inputStreamPatternUndoConsumeData( SourceStream *ss, const char *data, int length )
+int inputStreamPatternUndoConsumeData( FsmRun *fsmRun, StreamImpl *ss, const char *data, int length )
{
ss->offset -= length;
return length;
@@ -184,7 +184,7 @@ int inputStreamPatternUndoConsumeData( SourceStream *ss, const char *data, int l
extern "C" void initPatFuncs()
{
- memset( &patternFuncs, 0, sizeof(SourceFuncs) );
+ memset( &patternFuncs, 0, sizeof(StreamFuncs) );
patternFuncs.getData = &inputStreamPatternGetData;
patternFuncs.consumeData = &inputStreamPatternConsumeData;
@@ -199,17 +199,17 @@ extern "C" void initPatFuncs()
* Constructor
*/
-SourceStream *newSourceStreamCons( Constructor *constructor )
+StreamImpl *newSourceStreamCons( Constructor *constructor )
{
- SourceStream *ss = (SourceStream*)malloc(sizeof(SourceStream));
- memset( ss, 0, sizeof(SourceStream) );
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ memset( ss, 0, sizeof(StreamImpl) );
ss->constructor = constructor;
ss->consItem = constructor->list->head;
ss->funcs = &replFuncs;
return ss;
}
-LangEl *inputStreamConsGetLangEl( SourceStream *ss, long *bindId, char **data, long *length )
+LangEl *inputStreamConsGetLangEl( StreamImpl *ss, long *bindId, char **data, long *length )
{
LangEl *klangEl = ss->consItem->type == ConsItem::ExprType ?
ss->consItem->langEl : ss->consItem->factor->langEl;
@@ -235,7 +235,7 @@ LangEl *inputStreamConsGetLangEl( SourceStream *ss, long *bindId, char **data, l
return klangEl;
}
-int inputStreamConsGetData( SourceStream *ss, int skip, char *dest, int length, int *copied )
+int inputStreamConsGetData( FsmRun *fsmRun, StreamImpl *ss, int skip, char *dest, int length, int *copied )
{
*copied = 0;
@@ -282,7 +282,7 @@ int inputStreamConsGetData( SourceStream *ss, int skip, char *dest, int length,
return INPUT_DATA;
}
-void inputStreamConsBackup( SourceStream *ss )
+void inputStreamConsBackup( StreamImpl *ss )
{
if ( ss->consItem == 0 )
ss->consItem = ss->constructor->list->tail;
@@ -290,7 +290,7 @@ void inputStreamConsBackup( SourceStream *ss )
ss->consItem = ss->consItem->prev;
}
-void inputStreamConsPushBackBuf( SourceStream *ss, RunBuf *runBuf )
+void inputStreamConsPushBackBuf( StreamImpl *ss, RunBuf *runBuf )
{
char *data = runBuf->data + runBuf->offset;
long length = runBuf->length;
@@ -315,13 +315,13 @@ void inputStreamConsPushBackBuf( SourceStream *ss, RunBuf *runBuf )
assert( memcmp( &ss->consItem->data[ss->offset], data, length ) == 0 );
}
-void inputStreamConsUndoConsumeLangEl( SourceStream *ss )
+void inputStreamConsUndoConsumeLangEl( StreamImpl *ss )
{
inputStreamConsBackup( ss );
ss->offset = ss->consItem->data.length();
}
-int inputStreamConsConsumeData( SourceStream *ss, int length )
+int inputStreamConsConsumeData( StreamImpl *ss, int length )
{
int consumed = 0;
@@ -353,7 +353,7 @@ int inputStreamConsConsumeData( SourceStream *ss, int length )
return consumed;
}
-int inputStreamConsUndoConsumeData( SourceStream *ss, const char *data, int length )
+int inputStreamConsUndoConsumeData( FsmRun *fsmRun, StreamImpl *ss, const char *data, int length )
{
ss->offset -= length;
return length;
@@ -361,7 +361,7 @@ int inputStreamConsUndoConsumeData( SourceStream *ss, const char *data, int leng
extern "C" void initConsFuncs()
{
- memset( &replFuncs, 0, sizeof(SourceFuncs) );
+ memset( &replFuncs, 0, sizeof(StreamFuncs) );
replFuncs.getData = &inputStreamConsGetData;
replFuncs.consumeData = &inputStreamConsConsumeData;
@@ -371,14 +371,14 @@ extern "C" void initConsFuncs()
replFuncs.undoConsumeLangEl = &inputStreamConsUndoConsumeLangEl;
}
-void sendNamedLangEl( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream )
+void sendNamedLangEl( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *is )
{
/* All three set by consumeLangEl. */
long bindId;
char *data;
long length;
- LangEl *klangEl = consumeLangEl( inputStream, &bindId, &data, &length );
+ LangEl *klangEl = is->funcs->consumeLangEl( is, &bindId, &data, &length );
//cerr << "named langEl: " << prg->rtd->lelInfo[klangEl->id].name << endl;
@@ -387,7 +387,7 @@ void sendNamedLangEl( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, I
if ( data != 0 )
tokdata = stringAllocFull( prg, data, length );
- Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, inputStream, klangEl->id, tokdata );
+ Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, is, klangEl->id, tokdata );
incrementSteps( pdaRun );
diff --git a/colm/fsmexec.cc b/colm/fsmexec.cc
index f922c7a4..9b945374 100644
--- a/colm/fsmexec.cc
+++ b/colm/fsmexec.cc
@@ -92,7 +92,7 @@ void execAction( FsmRun *fsmRun, GenAction *genAction )
fsmRun->mark[genAction->markId-1] = fsmRun->p;
}
-void fsmExecute( FsmRun *fsmRun, InputStream *inputStream )
+void fsmExecute( FsmRun *fsmRun, StreamImpl *inputStream )
{
int _klen;
unsigned int _trans;
diff --git a/colm/input.c b/colm/input.c
index b1524c27..951222d4 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -40,20 +40,22 @@ RunBuf *newRunBuf()
return rb;
}
+void initStreamFuncs();
void initFdFuncs();
void initFileFuncs();
void initPatFuncs();
void initConsFuncs();
-struct SourceFuncs dynamicFuncs;
-struct SourceFuncs fileFuncs;
-struct SourceFuncs fdFuncs;
+struct StreamFuncs dynamicFuncs;
+struct StreamFuncs fileFuncs;
+struct StreamFuncs fdFuncs;
+struct StreamFuncs streamFuncs;
-void initSourceStream( SourceStream *inputStream )
+void initSourceStream( StreamImpl *inputStream )
{
}
-void clearSourceStream( struct ColmProgram *prg, Tree **sp, SourceStream *sourceStream )
+void clearSourceStream( struct ColmProgram *prg, Tree **sp, StreamImpl *sourceStream )
{
RunBuf *buf = sourceStream->queue;
while ( buf != 0 ) {
@@ -76,25 +78,25 @@ void clearSourceStream( struct ColmProgram *prg, Tree **sp, SourceStream *source
sourceStream->queue = 0;
}
-SourceStream *newSourceStreamFile( FILE *file )
+StreamImpl *newSourceStreamFile( FILE *file )
{
- SourceStream *ss = (SourceStream*)malloc(sizeof(SourceStream));
- memset( ss, 0, sizeof(SourceStream) );
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ memset( ss, 0, sizeof(StreamImpl) );
ss->file = file;
ss->funcs = &fileFuncs;
return ss;
}
-SourceStream *newSourceStreamFd( long fd )
+StreamImpl *newSourceStreamFd( long fd )
{
- SourceStream *ss = (SourceStream*)malloc(sizeof(SourceStream));
- memset( ss, 0, sizeof(SourceStream) );
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ memset( ss, 0, sizeof(StreamImpl) );
ss->fd = fd;
ss->funcs = &fdFuncs;
return ss;
}
-static RunBuf *sourceStreamPopHead( SourceStream *ss )
+static RunBuf *sourceStreamPopHead( StreamImpl *ss )
{
RunBuf *ret = ss->queue;
ss->queue = ss->queue->next;
@@ -105,7 +107,7 @@ static RunBuf *sourceStreamPopHead( SourceStream *ss )
return ret;
}
-static void sourceStreamAppend( SourceStream *ss, RunBuf *runBuf )
+static void sourceStreamAppend( StreamImpl *ss, RunBuf *runBuf )
{
if ( ss->queue == 0 ) {
runBuf->prev = runBuf->next = 0;
@@ -119,7 +121,7 @@ static void sourceStreamAppend( SourceStream *ss, RunBuf *runBuf )
}
}
-static void sourceStreamPrepend( SourceStream *ss, RunBuf *runBuf )
+static void sourceStreamPrepend( StreamImpl *ss, RunBuf *runBuf )
{
if ( ss->queue == 0 ) {
runBuf->prev = runBuf->next = 0;
@@ -133,8 +135,38 @@ static void sourceStreamPrepend( SourceStream *ss, RunBuf *runBuf )
}
}
+void initStreamFuncs()
+{
+ memset( &streamFuncs, 0, sizeof(struct StreamFuncs) );
+ streamFuncs.getData = &_getData;
+ streamFuncs.consumeData = &_consumeData;
+ streamFuncs.undoConsumeData = &_undoConsumeData;
+ streamFuncs.consumeTree = &_consumeTree;
+ streamFuncs.undoConsumeTree = &_undoConsumeTree;
+ streamFuncs.consumeLangEl = &_consumeLangEl;
+ streamFuncs.undoConsumeLangEl = &_undoConsumeLangEl;
+
+ streamFuncs.setEof = &_setEof;
+ streamFuncs.unsetEof = &_unsetEof;
+
+ streamFuncs.prependData = &_prependData;
+ streamFuncs.undoPrependData = &_undoPrependData;
+
+ streamFuncs.prependTree = &_prependTree;
+ streamFuncs.undoPrependTree = &_undoPrependTree;
+
+ streamFuncs.appendData = &_appendData;
+ streamFuncs.appendTree = &_appendTree;
+ streamFuncs.appendStream = &_appendStream;
+ streamFuncs.undoAppendData = &_undoAppendData;
+ streamFuncs.undoAppendStream = &_undoAppendStream;
+ streamFuncs.undoAppendTree = &_undoAppendTree;
+}
+
+
void initInputFuncs()
{
+ initStreamFuncs();
initFdFuncs();
initFileFuncs();
initPatFuncs();
@@ -145,7 +177,7 @@ void initInputFuncs()
* Base run-time input streams.
*/
-int fdGetData( SourceStream *ss, int skip, char *dest, int length, int *copied )
+int fdGetData( FsmRun *fsmRun, StreamImpl *ss, int skip, char *dest, int length, int *copied )
{
int ret = 0;
*copied = 0;
@@ -204,7 +236,7 @@ int fdGetData( SourceStream *ss, int skip, char *dest, int length, int *copied )
return ret;
}
-int fdConsumeData( SourceStream *ss, int length )
+int fdConsumeData( StreamImpl *ss, int length )
{
debug( REALM_INPUT, "source consuming %ld bytes\n", length );
@@ -244,7 +276,7 @@ int fdConsumeData( SourceStream *ss, int length )
return consumed;
}
-int fdUndoConsumeData( SourceStream *ss, const char *data, int length )
+int fdUndoConsumeData( FsmRun *fsmRun, StreamImpl *ss, const char *data, int length )
{
debug( REALM_INPUT, "undoing consume of %ld bytes\n", length );
@@ -260,7 +292,7 @@ int fdUndoConsumeData( SourceStream *ss, const char *data, int length )
* File
*/
-int fileGetDataSource( SourceStream *ss, char *dest, int length )
+int fileGetDataSource( StreamImpl *ss, char *dest, int length )
{
debug( REALM_INPUT, "inputStreamFileGetDataSource length = %ld\n", length );
size_t res = fread( dest, 1, length, ss->file );
@@ -269,7 +301,7 @@ int fileGetDataSource( SourceStream *ss, char *dest, int length )
void initFileFuncs()
{
- memset( &fileFuncs, 0, sizeof(struct SourceFuncs) );
+ memset( &fileFuncs, 0, sizeof(struct StreamFuncs) );
fileFuncs.getData = &fdGetData;
fileFuncs.consumeData = &fdConsumeData;
fileFuncs.undoConsumeData = &fdUndoConsumeData;
@@ -280,7 +312,7 @@ void initFileFuncs()
* FD
*/
-int fdGetDataSource( SourceStream *ss, char *dest, int length )
+int fdGetDataSource( StreamImpl *ss, char *dest, int length )
{
if ( ss->eof )
return 0;
@@ -294,7 +326,7 @@ int fdGetDataSource( SourceStream *ss, char *dest, int length )
void initFdFuncs()
{
- memset( &fdFuncs, 0, sizeof(struct SourceFuncs) );
+ memset( &fdFuncs, 0, sizeof(struct StreamFuncs) );
fdFuncs.getData = &fdGetData;
fdFuncs.consumeData = &fdConsumeData;
fdFuncs.undoConsumeData = &fdUndoConsumeData;
@@ -302,20 +334,21 @@ void initFdFuncs()
}
/*
- * InputStream struct, this wraps the list of input streams.
+ * StreamImpl struct, this wraps the list of input streams.
*/
-void initInputStream( InputStream *inputStream )
+void initInputStream( StreamImpl *inputStream )
{
- memset( inputStream, 0, sizeof(InputStream) );
+ memset( inputStream, 0, sizeof(StreamImpl) );
- /* FIXME: correct values here. */
inputStream->line = 1;
inputStream->column = 1;
inputStream->byte = 0;
+
+ inputStream->funcs = &streamFuncs;
}
-void clearInputStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStream )
+void clearInputStream( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream )
{
RunBuf *buf = inputStream->queue;
while ( buf != 0 ) {
@@ -338,7 +371,7 @@ void clearInputStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStr
inputStream->queue = 0;
}
-static void inputStreamPrepend( InputStream *is, RunBuf *runBuf )
+static void inputStreamPrepend( StreamImpl *is, RunBuf *runBuf )
{
if ( is->queue == 0 ) {
runBuf->prev = runBuf->next = 0;
@@ -352,7 +385,7 @@ static void inputStreamPrepend( InputStream *is, RunBuf *runBuf )
}
}
-static RunBuf *inputStreamPopHead( InputStream *is )
+static RunBuf *inputStreamPopHead( StreamImpl *is )
{
RunBuf *ret = is->queue;
is->queue = is->queue->next;
@@ -363,7 +396,7 @@ static RunBuf *inputStreamPopHead( InputStream *is )
return ret;
}
-static void inputStreamAppend( InputStream *is, RunBuf *runBuf )
+static void inputStreamAppend( StreamImpl *is, RunBuf *runBuf )
{
if ( is->queue == 0 ) {
runBuf->prev = runBuf->next = 0;
@@ -377,7 +410,7 @@ static void inputStreamAppend( InputStream *is, RunBuf *runBuf )
}
}
-static RunBuf *inputStreamPopTail( InputStream *is )
+static RunBuf *inputStreamPopTail( StreamImpl *is )
{
RunBuf *ret = is->queueTail;
is->queueTail = is->queueTail->prev;
@@ -388,20 +421,20 @@ static RunBuf *inputStreamPopTail( InputStream *is )
return ret;
}
-static int isSourceStream( InputStream *is )
+static int isSourceStream( StreamImpl *is )
{
if ( is->queue != 0 && is->queue->type == RunBufSourceType )
return true;
return false;
}
-void setEof( InputStream *is )
+void _setEof( StreamImpl *is )
{
debug( REALM_INPUT, "setting EOF in input stream\n" );
is->eof = true;
}
-void unsetEof( InputStream *is )
+void _unsetEof( StreamImpl *is )
{
if ( isSourceStream( is ) ) {
Stream *stream = (Stream*)is->queue->tree;
@@ -412,7 +445,7 @@ void unsetEof( InputStream *is )
}
}
-int getData( FsmRun *fsmRun, InputStream *is, int skip, char *dest, int length, int *copied )
+int _getData( FsmRun *fsmRun, StreamImpl *is, int skip, char *dest, int length, int *copied )
{
int ret = 0;
*copied = 0;
@@ -428,7 +461,7 @@ int getData( FsmRun *fsmRun, InputStream *is, int skip, char *dest, int length,
if ( buf->type == RunBufSourceType ) {
Stream *stream = (Stream*)buf->tree;
- int type = stream->in->funcs->getData( stream->in, skip, dest, length, copied );
+ int type = stream->in->funcs->getData( fsmRun, stream->in, skip, dest, length, copied );
attachSource( fsmRun, stream->in );
@@ -509,7 +542,7 @@ int getData( FsmRun *fsmRun, InputStream *is, int skip, char *dest, int length,
return ret;
}
-int consumeData( InputStream *is, int length )
+int _consumeData( StreamImpl *is, int length )
{
debug( REALM_INPUT, "consuming %d bytes\n", length );
@@ -555,13 +588,13 @@ int consumeData( InputStream *is, int length )
return consumed;
}
-int undoConsumeData( FsmRun *fsmRun, InputStream *is, const char *data, int length )
+int _undoConsumeData( FsmRun *fsmRun, StreamImpl *is, const char *data, int length )
{
debug( REALM_INPUT, "undoing consume of %ld bytes\n", length );
if ( isSourceStream( is ) ) {
Stream *stream = (Stream*)is->queue->tree;
- int len = stream->in->funcs->undoConsumeData( stream->in, data, length );
+ int len = stream->in->funcs->undoConsumeData( fsmRun, stream->in, data, length );
if ( stream->in->attached != 0 )
detachSource( stream->in->attached, stream->in );
@@ -581,7 +614,7 @@ int undoConsumeData( FsmRun *fsmRun, InputStream *is, const char *data, int leng
}
}
-Tree *consumeTree( InputStream *is )
+Tree *_consumeTree( StreamImpl *is )
{
while ( is->queue != 0 && is->queue->type == RunBufDataType && is->queue->offset == is->queue->length ) {
RunBuf *runBuf = inputStreamPopHead( is );
@@ -600,7 +633,7 @@ Tree *consumeTree( InputStream *is )
return 0;
}
-void undoConsumeTree( InputStream *is, Tree *tree, int ignore )
+void _undoConsumeTree( StreamImpl *is, Tree *tree, int ignore )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -614,7 +647,7 @@ void undoConsumeTree( InputStream *is, Tree *tree, int ignore )
inputStreamPrepend( is, newBuf );
}
-struct LangEl *consumeLangEl( InputStream *is, long *bindId, char **data, long *length )
+struct LangEl *_consumeLangEl( StreamImpl *is, long *bindId, char **data, long *length )
{
if ( isSourceStream( is ) ) {
Stream *stream = (Stream*)is->queue->tree;
@@ -625,7 +658,7 @@ struct LangEl *consumeLangEl( InputStream *is, long *bindId, char **data, long *
}
}
-void undoConsumeLangEl( InputStream *is )
+void _undoConsumeLangEl( StreamImpl *is )
{
if ( isSourceStream( is ) ) {
Stream *stream = (Stream*)is->queue->tree;
@@ -636,7 +669,7 @@ void undoConsumeLangEl( InputStream *is )
}
}
-void prependData( InputStream *is, const char *data, long length )
+void _prependData( StreamImpl *is, const char *data, long length )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -653,7 +686,7 @@ void prependData( InputStream *is, const char *data, long length )
inputStreamPrepend( is, newBuf );
}
-int undoPrependData( InputStream *is, int length )
+int _undoPrependData( StreamImpl *is, int length )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -702,7 +735,7 @@ int undoPrependData( InputStream *is, int length )
return consumed;
}
-void prependTree( InputStream *is, Tree *tree, int ignore )
+void _prependTree( StreamImpl *is, Tree *tree, int ignore )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -716,7 +749,7 @@ void prependTree( InputStream *is, Tree *tree, int ignore )
inputStreamPrepend( is, newBuf );
}
-Tree *undoPrependTree( InputStream *is )
+Tree *_undoPrependTree( StreamImpl *is )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -738,7 +771,7 @@ Tree *undoPrependTree( InputStream *is )
return 0;
}
-void appendData( InputStream *is, const char *data, long len )
+void _appendData( StreamImpl *is, const char *data, long len )
{
while ( len > 0 ) {
RunBuf *ad = newRunBuf();
@@ -756,7 +789,7 @@ void appendData( InputStream *is, const char *data, long len )
}
}
-Tree *undoAppendData( InputStream *is, int length )
+Tree *_undoAppendData( StreamImpl *is, int length )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -796,7 +829,7 @@ Tree *undoAppendData( InputStream *is, int length )
return 0;
}
-void appendTree( InputStream *is, Tree *tree )
+void _appendTree( StreamImpl *is, Tree *tree )
{
RunBuf *ad = newRunBuf();
@@ -807,7 +840,7 @@ void appendTree( InputStream *is, Tree *tree )
ad->length = 0;
}
-void appendStream( InputStream *in, struct ColmTree *tree )
+void _appendStream( StreamImpl *in, struct ColmTree *tree )
{
RunBuf *ad = newRunBuf();
@@ -818,7 +851,7 @@ void appendStream( InputStream *in, struct ColmTree *tree )
ad->length = 0;
}
-Tree *undoAppendStream( InputStream *is )
+Tree *_undoAppendStream( StreamImpl *is )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
@@ -829,7 +862,7 @@ Tree *undoAppendStream( InputStream *is )
return tree;
}
-Tree *undoAppendTree( InputStream *is )
+Tree *_undoAppendTree( StreamImpl *is )
{
if ( is->attached != 0 )
detachInput( is->attached, is );
diff --git a/colm/input.h b/colm/input.h
index 73ecb58c..2bbcdae6 100644
--- a/colm/input.h
+++ b/colm/input.h
@@ -83,27 +83,47 @@ typedef struct _RunBuf
RunBuf *newRunBuf();
-typedef struct _SourceStream SourceStream;
+typedef struct _StreamImpl StreamImpl;
-struct SourceFuncs
+struct StreamFuncs
{
/* Data. */
- int (*getData)( SourceStream *ss, int offset, char *dest, int length, int *copied );
- int (*consumeData)( SourceStream *ss, int length );
- int (*undoConsumeData)( SourceStream *ss, const char *data, int length );
+ int (*getData)( struct _FsmRun *fsmRun, StreamImpl *ss, int offset, char *dest, int length, int *copied );
+
+ int (*consumeData)( StreamImpl *ss, int length );
+ int (*undoConsumeData)( struct _FsmRun *fsmRun, StreamImpl *ss, const char *data, int length );
+
+ struct ColmTree *(*consumeTree)( StreamImpl *ss );
+ void (*undoConsumeTree)( StreamImpl *ss, struct ColmTree *tree, int ignore );
/* Language elments (compile-time). */
- struct LangEl *(*consumeLangEl)( SourceStream *ss, long *bindId, char **data, long *length );
- void (*undoConsumeLangEl)( SourceStream *ss );
+ struct LangEl *(*consumeLangEl)( StreamImpl *ss, long *bindId, char **data, long *length );
+ void (*undoConsumeLangEl)( StreamImpl *ss );
/* Private implmentation for some shared get data functions. */
- int (*getDataSource)( SourceStream *ss, char *dest, int length );
+ int (*getDataSource)( StreamImpl *ss, char *dest, int length );
+
+ void (*setEof)( StreamImpl *is );
+ void (*unsetEof)( StreamImpl *is );
+
+ void (*prependData)( StreamImpl *in, const char *data, long len );
+ int (*undoPrependData)( StreamImpl *is, int length );
+
+ void (*prependTree)( StreamImpl *is, struct ColmTree *tree, int ignore );
+ struct ColmTree *(*undoPrependTree)( StreamImpl *is );
+
+ void (*appendData)( StreamImpl *in, const char *data, long len );
+ void (*appendTree)( StreamImpl *in, struct ColmTree *tree );
+ void (*appendStream)( StreamImpl *in, struct ColmTree *tree );
+ struct ColmTree *(*undoAppendData)( StreamImpl *in, int length );
+ struct ColmTree *(*undoAppendStream)( StreamImpl *in );
+ struct ColmTree *(*undoAppendTree)( StreamImpl *in );
};
/* List of source streams. Enables streams to be pushed/popped. */
-struct _SourceStream
+struct _StreamImpl
{
- struct SourceFuncs *funcs;
+ struct StreamFuncs *funcs;
struct _FsmRun *attached;
char eofSent;
@@ -129,46 +149,45 @@ struct _SourceStream
struct ConsItem *consItem;
};
-SourceStream *newSourceStreamPat( struct Pattern *pattern );
-SourceStream *newSourceStreamCons( struct Constructor *constructor );
-SourceStream *newSourceStreamFile( FILE *file );
-SourceStream *newSourceStreamFd( long fd );
+typedef struct _StreamImpl StreamImpl;
+
+StreamImpl *newSourceStreamPat( struct Pattern *pattern );
+StreamImpl *newSourceStreamCons( struct Constructor *constructor );
+StreamImpl *newSourceStreamFile( FILE *file );
+StreamImpl *newSourceStreamFd( long fd );
void initInputFuncs();
void initStaticFuncs();
void initPatFuncs();
void initConsFuncs();
-typedef struct _SourceStream _InputStream;
-typedef struct _SourceStream InputStream;
-
/* The input stream interface. */
-int getData( struct _FsmRun *fsmRun, InputStream *in, int offset, char *dest, int length, int *copied );
-int consumeData( InputStream *in, int length );
-int undoConsumeData( struct _FsmRun *fsmRun, InputStream *is, const char *data, int length );
+int _getData( struct _FsmRun *fsmRun, StreamImpl *in, int offset, char *dest, int length, int *copied );
+int _consumeData( StreamImpl *in, int length );
+int _undoConsumeData( struct _FsmRun *fsmRun, StreamImpl *is, const char *data, int length );
-struct ColmTree *consumeTree( InputStream *in );
-void undoConsumeTree( InputStream *in, struct ColmTree *tree, int ignore );
+struct ColmTree *_consumeTree( StreamImpl *in );
+void _undoConsumeTree( StreamImpl *in, struct ColmTree *tree, int ignore );
-struct LangEl *consumeLangEl( InputStream *in, long *bindId, char **data, long *length );
-void undoConsumeLangEl( InputStream *in );
+struct LangEl *_consumeLangEl( StreamImpl *in, long *bindId, char **data, long *length );
+void _undoConsumeLangEl( StreamImpl *in );
-void setEof( InputStream *is );
-void unsetEof( InputStream *is );
+void _setEof( StreamImpl *is );
+void _unsetEof( StreamImpl *is );
-void prependData( InputStream *in, const char *data, long len );
-int undoPrependData( InputStream *is, int length );
+void _prependData( StreamImpl *in, const char *data, long len );
+int _undoPrependData( StreamImpl *is, int length );
-void prependTree( InputStream *is, struct ColmTree *tree, int ignore );
-struct ColmTree *undoPrependTree( InputStream *is );
+void _prependTree( StreamImpl *is, struct ColmTree *tree, int ignore );
+struct ColmTree *_undoPrependTree( StreamImpl *is );
-void appendData( InputStream *in, const char *data, long len );
-void appendTree( InputStream *in, struct ColmTree *tree );
-void appendStream( InputStream *in, struct ColmTree *tree );
-struct ColmTree *undoAppendData( InputStream *in, int length );
-struct ColmTree *undoAppendStream( InputStream *in );
-struct ColmTree *undoAppendTree( InputStream *in );
+void _appendData( StreamImpl *in, const char *data, long len );
+void _appendTree( StreamImpl *in, struct ColmTree *tree );
+void _appendStream( StreamImpl *in, struct ColmTree *tree );
+struct ColmTree *_undoAppendData( StreamImpl *in, int length );
+struct ColmTree *_undoAppendStream( StreamImpl *in );
+struct ColmTree *_undoAppendTree( StreamImpl *in );
#ifdef __cplusplus
}
diff --git a/colm/parsedata.h b/colm/parsedata.h
index 69e97be6..b94386c7 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -791,7 +791,7 @@ struct Compiler
void prepGrammar();
PdaRun *parsePattern( Program *prg, Tree **sp, const InputLoc &loc,
- int parserId, SourceStream *sourceStream );
+ int parserId, StreamImpl *sourceStream );
void parsePatterns();
void collectParserEls( LangElSet &parserEls );
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 72b0e2e2..e99a1fad 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -90,33 +90,33 @@ void clearFsmRun( Program *prg, FsmRun *fsmRun )
}
/* Keep the position up to date after consuming text. */
-void updatePosition( InputStream *inputStream, const char *data, long length )
+void updatePosition( StreamImpl *is, const char *data, long length )
{
int i;
for ( i = 0; i < length; i++ ) {
if ( data[i] != '\n' )
- inputStream->column += 1;
+ is->column += 1;
else {
- inputStream->line += 1;
- inputStream->column = 1;
+ is->line += 1;
+ is->column = 1;
}
}
- inputStream->byte += length;
+ is->byte += length;
}
/* Keep the position up to date after sending back text. */
-void undoPosition( InputStream *inputStream, const char *data, long length )
+void undoPosition( StreamImpl *is, const char *data, long length )
{
/* FIXME: this needs to fetch the position information from the parsed
* token and restore based on that.. */
int i;
for ( i = 0; i < length; i++ ) {
if ( data[i] == '\n' )
- inputStream->line -= 1;
+ is->line -= 1;
}
- inputStream->byte -= length;
+ is->byte -= length;
}
void incrementSteps( PdaRun *pdaRun )
@@ -133,7 +133,7 @@ void decrementSteps( PdaRun *pdaRun )
/* Load up a token, starting from tokstart if it is set. If not set then
* start it at data. */
-Head *streamPull( Program *prg, FsmRun *fsmRun, InputStream *inputStream, long length )
+Head *streamPull( Program *prg, FsmRun *fsmRun, StreamImpl *is, long length )
{
/* We should not be in the midst of getting a token. */
assert( fsmRun->tokstart == 0 );
@@ -143,52 +143,52 @@ Head *streamPull( Program *prg, FsmRun *fsmRun, InputStream *inputStream, long l
fsmRun->runBuf = runBuf;
int len = 0;
- getData( fsmRun, inputStream, 0, runBuf->data, length, &len );
- consumeData( inputStream, length );
+ is->funcs->getData( fsmRun, is, 0, runBuf->data, length, &len );
+ is->funcs->consumeData( is, length );
fsmRun->p = fsmRun->pe = runBuf->data + length;
Head *tokdata = stringAllocPointer( prg, runBuf->data, length );
- updatePosition( inputStream, runBuf->data, length );
+ updatePosition( is, runBuf->data, length );
return tokdata;
}
-void undoStreamPull( InputStream *inputStream, const char *data, long length )
+void undoStreamPull( StreamImpl *is, const char *data, long length )
{
debug( REALM_PARSE, "undoing stream pull\n" );
- prependData( inputStream, data, length );
+ is->funcs->prependData( is, data, length );
}
-void streamPushText( FsmRun *fsmRun, InputStream *inputStream, const char *data, long length )
+void streamPushText( FsmRun *fsmRun, StreamImpl *is, const char *data, long length )
{
- prependData( inputStream, data, length );
+ is->funcs->prependData( is, data, length );
}
-void streamPushTree( FsmRun *fsmRun, InputStream *inputStream, Tree *tree, int ignore )
+void streamPushTree( FsmRun *fsmRun, StreamImpl *is, Tree *tree, int ignore )
{
- prependTree( inputStream, tree, ignore );
+ is->funcs->prependTree( is, tree, ignore );
}
-void undoStreamPush( Program *prg, Tree **sp, FsmRun *fsmRun, InputStream *inputStream, long length )
+void undoStreamPush( Program *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *is, long length )
{
if ( length < 0 ) {
- Tree *tree = undoPrependTree( inputStream );
+ Tree *tree = is->funcs->undoPrependTree( is );
treeDownref( prg, sp, tree );
}
else {
- undoPrependData( inputStream, length );
+ is->funcs->undoPrependData( is, length );
}
}
-void undoStreamAppend( Program *prg, Tree **sp, FsmRun *fsmRun, InputStream *inputStream, Tree *input, long length )
+void undoStreamAppend( Program *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *is, Tree *input, long length )
{
if ( input->id == LEL_ID_STR )
- undoAppendData( inputStream, length );
+ is->funcs->undoAppendData( is, length );
else if ( input->id == LEL_ID_STREAM )
- undoAppendStream( inputStream );
+ is->funcs->undoAppendStream( is );
else {
- Tree *tree = undoAppendTree( inputStream );
+ Tree *tree = is->funcs->undoAppendTree( is );
treeDownref( prg, sp, tree );
}
}
@@ -196,7 +196,7 @@ void undoStreamAppend( Program *prg, Tree **sp, FsmRun *fsmRun, InputStream *inp
/* Should only be sending back whole tokens/ignores, therefore the send back
* should never cross a buffer boundary. Either we slide back data, or we move to
* a previous buffer and slide back data. */
-static void sendBackText( FsmRun *fsmRun, InputStream *inputStream, const char *data, long length )
+static void sendBackText( FsmRun *fsmRun, StreamImpl *is, const char *data, long length )
{
debug( REALM_PARSE, "push back of %ld characters\n", length );
@@ -206,13 +206,13 @@ static void sendBackText( FsmRun *fsmRun, InputStream *inputStream, const char *
debug( REALM_PARSE, "sending back text: %.*s\n",
(int)length, data );
- undoConsumeData( fsmRun, inputStream, data, length );
- undoPosition( inputStream, data, length );
+ is->funcs->undoConsumeData( fsmRun, is, data, length );
+ undoPosition( is, data, length );
}
-void sendBackTree( InputStream *inputStream, Tree *tree )
+void sendBackTree( StreamImpl *is, Tree *tree )
{
- undoConsumeTree( inputStream, tree, false );
+ is->funcs->undoConsumeTree( is, tree, false );
}
/*
@@ -220,7 +220,7 @@ void sendBackTree( InputStream *inputStream, Tree *tree )
* PcrRevIgnore
*/
static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun,
- InputStream *inputStream, ParseTree *parseTree )
+ StreamImpl *is, ParseTree *parseTree )
{
#ifdef DEBUG
LangElInfo *lelInfo = prg->rtd->lelInfo;
@@ -233,7 +233,7 @@ static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsm
int artificial = parseTree->flags & PF_ARTIFICIAL;
if ( head != 0 && !artificial )
- sendBackText( fsmRun, inputStream, stringData( head ), head->length );
+ sendBackText( fsmRun, is, stringData( head ), head->length );
decrementSteps( pdaRun );
@@ -250,7 +250,7 @@ static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsm
}
-void attachInput( FsmRun *fsmRun, InputStream *is )
+void attachInput( FsmRun *fsmRun, StreamImpl *is )
{
if ( is->attached != 0 && is->attached != fsmRun )
detachInput( is->attached, is );
@@ -262,7 +262,7 @@ void attachInput( FsmRun *fsmRun, InputStream *is )
}
}
-void attachSource( FsmRun *fsmRun, SourceStream *ss )
+void attachSource( FsmRun *fsmRun, StreamImpl *ss )
{
if ( ss->attached != 0 && ss->attached != fsmRun )
detachSource( ss->attached, ss );
@@ -274,7 +274,7 @@ void attachSource( FsmRun *fsmRun, SourceStream *ss )
}
}
-void detachInput( FsmRun *fsmRun, InputStream *is )
+void detachInput( FsmRun *fsmRun, StreamImpl *is )
{
debug( REALM_INPUT, "detaching fsm run from input stream: %p %p\n", fsmRun, is );
@@ -289,7 +289,7 @@ void detachInput( FsmRun *fsmRun, InputStream *is )
}
}
-void detachSource( FsmRun *fsmRun, SourceStream *is )
+void detachSource( FsmRun *fsmRun, StreamImpl *is )
{
debug( REALM_INPUT, "detaching fsm run from source stream: %p %p\n", fsmRun, is );
@@ -332,18 +332,18 @@ void resetToken( FsmRun *fsmRun )
*/
static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun,
- InputStream *inputStream, ParseTree *parseTree )
+ StreamImpl *is, ParseTree *parseTree )
{
debug( REALM_PARSE, "sending back: %s\n", prg->rtd->lelInfo[parseTree->id].name );
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 );
+ // sendBackRunBufHead( fsmRun, is );
/* Send the named lang el back first, then send back any leading
* whitespace. */
- undoConsumeLangEl( inputStream );
+ is->funcs->undoConsumeLangEl( is );
}
decrementSteps( pdaRun );
@@ -359,7 +359,7 @@ static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun,
treeUpref( parseTree->shadow->tree );
- sendBackTree( inputStream, parseTree->shadow->tree );
+ sendBackTree( is, parseTree->shadow->tree );
}
else {
/* Check for reverse code. */
@@ -370,12 +370,12 @@ static void sendBack( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun,
}
/* Push back the token data. */
- sendBackText( fsmRun, inputStream, stringData( parseTree->shadow->tree->tokdata ),
+ sendBackText( fsmRun, is, 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 ( parseTree->id == prg->rtd->eofLelIds[pdaRun->parserId] )
- inputStream->eofSent = false;
+ is->eofSent = false;
/* If the item is bound then store remove it from the bindings array. */
popBinding( pdaRun, parseTree );
@@ -443,7 +443,7 @@ void ignoreTree2( Program *prg, PdaRun *pdaRun, Tree *tree )
}
Kid *makeTokenWithData( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun,
- InputStream *inputStream, int id, Head *tokdata )
+ StreamImpl *is, int id, Head *tokdata )
{
/* Make the token object. */
long objectLength = prg->rtd->lelInfo[id].objectLength;
@@ -788,13 +788,13 @@ void handleError( Program *prg, Tree **sp, PdaRun *pdaRun )
}
}
-void sendIgnore( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmRun, PdaRun *pdaRun, long id )
+void sendIgnore( Program *prg, Tree **sp, StreamImpl *is, FsmRun *fsmRun, PdaRun *pdaRun, long id )
{
debug( REALM_PARSE, "ignoring: %s\n", prg->rtd->lelInfo[id].name );
/* Make the ignore string. */
- Head *ignoreStr = extractMatch( prg, fsmRun, inputStream );
- updatePosition( inputStream, fsmRun->tokstart, ignoreStr->length );
+ Head *ignoreStr = extractMatch( prg, fsmRun, is );
+ updatePosition( is, fsmRun->tokstart, ignoreStr->length );
debug( REALM_PARSE, "ignoring: %.*s\n", ignoreStr->length, ignoreStr->data );
@@ -809,51 +809,51 @@ void sendIgnore( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmR
/* Doesn't consume. */
-Head *peekMatch( Program *prg, FsmRun *fsmRun, InputStream *inputStream )
+Head *peekMatch( Program *prg, FsmRun *fsmRun, StreamImpl *is )
{
long length = fsmRun->p - fsmRun->tokstart;
Head *head = stringAllocPointer( prg, fsmRun->tokstart, length );
head->location = locationAllocate( prg );
- head->location->line = inputStream->line;
- head->location->column = inputStream->column;
- head->location->byte = inputStream->byte;
+ head->location->line = is->line;
+ head->location->column = is->column;
+ head->location->byte = is->byte;
- debug( REALM_PARSE, "location byte: %d\n", inputStream->byte );
+ debug( REALM_PARSE, "location byte: %d\n", is->byte );
return head;
}
/* Consumes. */
-Head *extractMatch( Program *prg, FsmRun *fsmRun, InputStream *inputStream )
+Head *extractMatch( Program *prg, FsmRun *fsmRun, StreamImpl *is )
{
long length = fsmRun->p - fsmRun->tokstart;
Head *head = stringAllocPointer( prg, fsmRun->tokstart, length );
head->location = locationAllocate( prg );
- head->location->line = inputStream->line;
- head->location->column = inputStream->column;
- head->location->byte = inputStream->byte;
+ head->location->line = is->line;
+ head->location->column = is->column;
+ head->location->byte = is->byte;
- debug( REALM_PARSE, "location byte: %d\n", inputStream->byte );
+ debug( REALM_PARSE, "location byte: %d\n", is->byte );
- consumeData( inputStream, length );
+ is->funcs->consumeData( is, length );
return head;
}
-static void sendToken( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmRun, PdaRun *pdaRun, long id )
+static void sendToken( Program *prg, Tree **sp, StreamImpl *is, FsmRun *fsmRun, PdaRun *pdaRun, long id )
{
int emptyIgnore = pdaRun->accumIgnore == 0;
/* Make the token data. */
- Head *tokdata = extractMatch( prg, fsmRun, inputStream );
+ Head *tokdata = extractMatch( prg, fsmRun, is );
debug( REALM_PARSE, "token: %s text: %.*s\n",
prg->rtd->lelInfo[id].name,
stringLength(tokdata), stringData(tokdata) );
- updatePosition( inputStream, fsmRun->tokstart, tokdata->length );
+ updatePosition( is, fsmRun->tokstart, tokdata->length );
- Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, inputStream, id, tokdata );
+ Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, is, id, tokdata );
incrementSteps( pdaRun );
@@ -868,10 +868,10 @@ static void sendToken( Program *prg, Tree **sp, InputStream *inputStream, FsmRun
setRegion( pdaRun, emptyIgnore, parseTree );
}
-static void sendTree( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream )
+static void sendTree( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *is )
{
Kid *input = kidAllocate( prg );
- input->tree = consumeTree( inputStream );
+ input->tree = is->funcs->consumeTree( is );
incrementSteps( pdaRun );
@@ -883,13 +883,13 @@ static void sendTree( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, I
pdaRun->parseInput = parseTree;
}
-static void sendIgnoreTree( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream )
+static void sendIgnoreTree( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *is )
{
- Tree *tree = consumeTree( inputStream );
+ Tree *tree = is->funcs->consumeTree( is );
ignoreTree2( prg, pdaRun, tree );
}
-static void sendCi( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmRun, PdaRun *pdaRun, int id )
+static void sendCi( Program *prg, Tree **sp, StreamImpl *is, FsmRun *fsmRun, PdaRun *pdaRun, int id )
{
debug( REALM_PARSE, "token: CI\n" );
@@ -900,17 +900,17 @@ static void sendCi( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *f
/* Make the token data. */
Head *tokdata = headAllocate( prg );
tokdata->location = locationAllocate( prg );
- tokdata->location->line = inputStream->line;
- tokdata->location->column = inputStream->column;
- tokdata->location->byte = inputStream->byte;
+ tokdata->location->line = is->line;
+ tokdata->location->column = is->column;
+ tokdata->location->byte = is->byte;
debug( REALM_PARSE, "token: %s text: %.*s\n",
prg->rtd->lelInfo[id].name,
stringLength(tokdata), stringData(tokdata) );
- updatePosition( inputStream, fsmRun->tokstart, tokdata->length );
+ updatePosition( is, fsmRun->tokstart, tokdata->length );
- Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, inputStream, id, tokdata );
+ Kid *input = makeTokenWithData( prg, pdaRun, fsmRun, is, id, tokdata );
incrementSteps( pdaRun );
@@ -926,7 +926,7 @@ static void sendCi( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *f
}
-static void sendEof( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmRun, PdaRun *pdaRun )
+static void sendEof( Program *prg, Tree **sp, StreamImpl *is, FsmRun *fsmRun, PdaRun *pdaRun )
{
debug( REALM_PARSE, "token: _EOF\n" );
@@ -934,9 +934,9 @@ static void sendEof( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *
Head *head = headAllocate( prg );
head->location = locationAllocate( prg );
- head->location->line = inputStream->line;
- head->location->column = inputStream->column;
- head->location->byte = inputStream->byte;
+ head->location->line = is->line;
+ head->location->column = is->column;
+ head->location->byte = is->byte;
Kid *input = kidAllocate( prg );
input->tree = treeAllocate( prg );
@@ -1016,13 +1016,13 @@ static void pushBtPoint( Program *prg, PdaRun *pdaRun )
#define SCAN_LANG_EL -2
#define SCAN_EOF -1
-long scanToken( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream )
+long scanToken( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *is )
{
if ( pdaRun->triggerUndo )
return SCAN_UNDO;
while ( true ) {
- fsmExecute( fsmRun, inputStream );
+ fsmExecute( fsmRun, is );
/* First check if scanning stopped because we have a token. */
if ( fsmRun->matchedToken > 0 ) {
@@ -1119,7 +1119,7 @@ long scanToken( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *input
int have = fsmRun->tokstart != 0 ? fsmRun->p - fsmRun->tokstart : 0;
int len = 0;
debug( REALM_SCAN, "fetching data: have: %d space: %d\n", have, space );
- int type = getData( fsmRun, inputStream, have, fsmRun->p, space, &len );
+ int type = is->funcs->getData( fsmRun, is, have, fsmRun->p, space, &len );
switch ( type ) {
case INPUT_DATA:
@@ -1173,7 +1173,7 @@ long scanToken( Program *prg, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *input
*/
long parseLoop( Program *prg, Tree **sp, PdaRun *pdaRun,
- FsmRun *fsmRun, InputStream *inputStream, long entry )
+ FsmRun *fsmRun, StreamImpl *is, long entry )
{
LangElInfo *lelInfo = prg->rtd->lelInfo;
@@ -1183,12 +1183,12 @@ case PcrStart:
pdaRun->stop = false;
while ( true ) {
- debug( REALM_PARSE, "parse loop start %d:%d\n", inputStream->line, inputStream->column );
+ debug( REALM_PARSE, "parse loop start %d:%d\n", is->line, is->column );
/* Pull the current scanner from the parser. This can change during
* parsing due to inputStream pushes, usually for the purpose of includes.
* */
- pdaRun->tokenId = scanToken( prg, pdaRun, fsmRun, inputStream );
+ pdaRun->tokenId = scanToken( prg, pdaRun, fsmRun, is );
if ( pdaRun->tokenId == SCAN_ERROR ) {
if ( fsmRun->preRegion >= 0 ) {
@@ -1204,7 +1204,7 @@ case PcrStart:
( prg->rtd->regionInfo[fsmRun->region].ciLelId > 0 ) )
{
debug( REALM_PARSE, "sending a collect ignore\n" );
- sendCi( prg, sp, inputStream, fsmRun, pdaRun, prg->rtd->regionInfo[fsmRun->region].ciLelId );
+ sendCi( prg, sp, is, fsmRun, pdaRun, prg->rtd->regionInfo[fsmRun->region].ciLelId );
goto yes;
}
@@ -1218,8 +1218,8 @@ case PcrStart:
/* Check for EOF. */
if ( pdaRun->tokenId == SCAN_EOF ) {
- inputStream->eofSent = true;
- sendEof( prg, sp, inputStream, fsmRun, pdaRun );
+ is->eofSent = true;
+ sendEof( prg, sp, is, fsmRun, pdaRun );
pdaRun->frameId = prg->rtd->regionInfo[fsmRun->region].eofFrameId;
@@ -1269,19 +1269,19 @@ case PcrPreEof:
debug( REALM_PARSE, "sending an named lang el\n" );
/* A named language element (parsing colm program). */
- sendNamedLangEl( prg, sp, pdaRun, fsmRun, inputStream );
+ sendNamedLangEl( prg, sp, pdaRun, fsmRun, is );
}
else if ( pdaRun->tokenId == SCAN_TREE ) {
debug( REALM_PARSE, "sending a tree\n" );
/* A tree already built. */
- sendTree( prg, sp, pdaRun, fsmRun, inputStream );
+ sendTree( prg, sp, pdaRun, fsmRun, is );
}
else if ( pdaRun->tokenId == SCAN_IGNORE ) {
debug( REALM_PARSE, "sending an ignore token\n" );
/* A tree to ignore. */
- sendIgnoreTree( prg, sp, pdaRun, fsmRun, inputStream );
+ sendIgnoreTree( prg, sp, pdaRun, fsmRun, is );
goto skipSend;
}
else if ( prg->ctxDepParsing && lelInfo[pdaRun->tokenId].frameId >= 0 ) {
@@ -1290,7 +1290,7 @@ case PcrPreEof:
prg->rtd->lelInfo[pdaRun->tokenId].name );
/* Make the token data. */
- pdaRun->tokdata = peekMatch( prg, fsmRun, inputStream );
+ pdaRun->tokdata = peekMatch( prg, fsmRun, is );
/* Note that we don't update the position now. It is done when the token
* data is pulled from the inputStream. */
@@ -1317,7 +1317,7 @@ case PcrGeneration:
prg->rtd->lelInfo[pdaRun->tokenId].name );
/* Is an ignore token. */
- sendIgnore( prg, sp, inputStream, fsmRun, pdaRun, pdaRun->tokenId );
+ sendIgnore( prg, sp, is, fsmRun, pdaRun, pdaRun->tokenId );
goto skipSend;
}
else {
@@ -1325,7 +1325,7 @@ case PcrGeneration:
prg->rtd->lelInfo[pdaRun->tokenId].name );
/* Is a plain token. */
- sendToken( prg, sp, inputStream, fsmRun, pdaRun, pdaRun->tokenId );
+ sendToken( prg, sp, is, fsmRun, pdaRun, pdaRun->tokenId );
}
yes:
@@ -1340,7 +1340,7 @@ yes:
}
}
- long pcr = parseToken( prg, sp, pdaRun, fsmRun, inputStream, PcrStart );
+ long pcr = parseToken( prg, sp, pdaRun, fsmRun, is, PcrStart );
while ( pcr != PcrDone ) {
@@ -1348,7 +1348,7 @@ return pcr;
case PcrReduction:
case PcrReverse:
- pcr = parseToken( prg, sp, pdaRun, fsmRun, inputStream, entry );
+ pcr = parseToken( prg, sp, pdaRun, fsmRun, is, entry );
}
assert( pcr == PcrDone );
@@ -1366,7 +1366,7 @@ skipSend:
break;
}
- if ( inputStream->eofSent ) {
+ if ( is->eofSent ) {
debug( REALM_PARSE, "parsing stopped by EOF\n" );
break;
}
@@ -1733,7 +1733,7 @@ void commitFull( Program *prg, Tree **sp, PdaRun *pdaRun, long causeReduce )
* PcrRevReduction
*/
long parseToken( Program *prg, Tree **sp, PdaRun *pdaRun,
- FsmRun *fsmRun, InputStream *inputStream, long entry )
+ FsmRun *fsmRun, StreamImpl *is, long entry )
{
int pos;
unsigned int *action;
@@ -2098,7 +2098,7 @@ case PcrReverse:
pdaRun->checkNext = true;
pdaRun->checkStop = true;
- sendBack( prg, sp, pdaRun, fsmRun, inputStream, pdaRun->parseInput );
+ sendBack( prg, sp, pdaRun, fsmRun, is, pdaRun->parseInput );
pdaRun->parseInput = 0;
}
@@ -2186,7 +2186,7 @@ case PcrReverse:
pdaRun->checkNext = true;
pdaRun->checkStop = true;
- sendBackIgnore( prg, sp, pdaRun, fsmRun, inputStream, ignore );
+ sendBackIgnore( prg, sp, pdaRun, fsmRun, is, ignore );
treeDownref( prg, sp, ignore->shadow->tree );
kidFree( prg, ignore->shadow );
diff --git a/colm/pdarun.h b/colm/pdarun.h
index d402a83f..6017ccf1 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -84,16 +84,16 @@ typedef struct _FsmRun
char *mark[MARK_SLOTS];
long matchedToken;
- InputStream *attachedInput;
- SourceStream *attachedSource;
+ StreamImpl *attachedInput;
+ StreamImpl *attachedSource;
} FsmRun;
void initFsmRun( FsmRun *fsmRun, struct ColmProgram *prg );
void clearFsmRun( struct ColmProgram *prg, FsmRun *fsmRun );
-void updatePosition( InputStream *inputStream, const char *data, long length );
-void undoPosition( InputStream *inputStream, const char *data, long length );
-void sendBackRunBufHead( FsmRun *fsmRun, InputStream *inputStream );
-void undoStreamPull( InputStream *inputStream, const char *data, long length );
+void updatePosition( StreamImpl *inputStream, const char *data, long length );
+void undoPosition( StreamImpl *inputStream, const char *data, long length );
+void sendBackRunBufHead( FsmRun *fsmRun, StreamImpl *inputStream );
+void undoStreamPull( StreamImpl *inputStream, const char *data, long length );
#if SIZEOF_LONG != 4 && SIZEOF_LONG != 8
@@ -400,10 +400,10 @@ void initPdaRun( PdaRun *pdaRun, struct ColmProgram *prg, PdaTables *tables,
FsmRun *fsmRun, int parserId, long stopTarget, int revertOn, Tree *context );
void clearPdaRun( struct ColmProgram *prg, Tree **root, PdaRun *pdaRun );
-void initInputStream( InputStream *inputStream );
-void clearInputStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStream );
-void initSourceStream( SourceStream *in );
-void clearSourceStream( struct ColmProgram *prg, Tree **sp, SourceStream *sourceStream );
+void initInputStream( StreamImpl *inputStream );
+void clearInputStream( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream );
+void initSourceStream( StreamImpl *in );
+void clearSourceStream( struct ColmProgram *prg, Tree **sp, StreamImpl *sourceStream );
void clearContext( PdaRun *pdaRun, Tree **sp );
@@ -425,48 +425,48 @@ int pdaRunGetNextPreRegion( PdaRun *pdaRun );
#define PcrReverse 6
long parseToken( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun,
- FsmRun *fsmRun, InputStream *inputStream, long entry );
+ FsmRun *fsmRun, StreamImpl *inputStream, long entry );
-long undoParse( Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, Tree *tree );
+long undoParse( Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *inputStream, Tree *tree );
-Head *streamPull( struct ColmProgram *prg, FsmRun *fsmRun, InputStream *inputStream, long length );
+Head *streamPull( struct ColmProgram *prg, FsmRun *fsmRun, StreamImpl *inputStream, long length );
Head *stringAllocPointer( struct ColmProgram *prg, const char *data, long length );
-void streamPushText( FsmRun *fsmRun, InputStream *inputStream, const char *data, long length );
-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 streamPushText( FsmRun *fsmRun, StreamImpl *inputStream, const char *data, long length );
+void streamPushTree( FsmRun *fsmRun, StreamImpl *inputStream, Tree *tree, int ignore );
+void undoStreamPush( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *inputStream, long length );
+void undoStreamAppend( struct ColmProgram *prg, Tree **sp, FsmRun *fsmRun, StreamImpl *inputStream, struct ColmTree *tree, long length );
Kid *makeTokenWithData( struct ColmProgram *prg, PdaRun *pdaRun, FsmRun *fsmRun,
- InputStream *inputStream, int id, Head *tokdata );
+ StreamImpl *inputStream, int id, Head *tokdata );
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 );
+ StreamImpl *inputStream, int frameId, Code *code, long id, Head *tokdata );
Kid *extractIgnore( PdaRun *pdaRun );
-long sendBackQueuedIgnore( struct ColmProgram *prg, Tree **sp, InputStream *inputStream,
+long sendBackQueuedIgnore( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream,
FsmRun *fsmRun, PdaRun *pdaRun, long entry );
void clearIgnoreList( struct ColmProgram *prg, Tree **sp, Kid *kid );
-Head *extractMatch( struct ColmProgram *prg, FsmRun *fsmRun, InputStream *inputStream );
-Head *extractMatch( struct ColmProgram *prg, FsmRun *fsmRun, InputStream *inputStream );
+Head *extractMatch( struct ColmProgram *prg, FsmRun *fsmRun, StreamImpl *inputStream );
+Head *extractMatch( struct ColmProgram *prg, FsmRun *fsmRun, StreamImpl *inputStream );
void newToken( struct ColmProgram *prg, PdaRun *pdaRun, FsmRun *fsmRun );
-void fsmExecute( FsmRun *fsmRun, InputStream *inputStream );
-void sendNamedLangEl( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream );
+void fsmExecute( FsmRun *fsmRun, StreamImpl *inputStream );
+void sendNamedLangEl( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, StreamImpl *inputStream );
long parseLoop( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun,
- FsmRun *fsmRun, InputStream *inputStream, long entry );
+ FsmRun *fsmRun, StreamImpl *inputStream, long entry );
void initBindings( PdaRun *pdaRun );
Tree *getParsedRoot( PdaRun *pdaRun, int stop );
-void undoParseStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmRun,
+void undoParseStream( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream, FsmRun *fsmRun,
PdaRun *pdaRun, long steps );
void clearBuffered( FsmRun *fsmRun );
void resetToken( FsmRun *fsmRun );
-void detachInput( FsmRun *fsmRun, InputStream *is );
-void attachInput( FsmRun *fsmRun, InputStream *is );
-void detachSource( FsmRun *fsmRun, SourceStream *ss );
-void attachSource( FsmRun *fsmRun, SourceStream *ss );
+void detachInput( FsmRun *fsmRun, StreamImpl *is );
+void attachInput( FsmRun *fsmRun, StreamImpl *is );
+void detachSource( FsmRun *fsmRun, StreamImpl *ss );
+void attachSource( FsmRun *fsmRun, StreamImpl *ss );
#ifdef __cplusplus
}
diff --git a/colm/tree.c b/colm/tree.c
index 93a529d8..7ed3d5d0 100644
--- a/colm/tree.c
+++ b/colm/tree.c
@@ -326,7 +326,7 @@ Tree *constructInput( Program *prg )
Input *input = inputAllocate( prg );
input->refs = 0;
input->id = LEL_ID_INPUT;
- input->in = malloc( sizeof(InputStream) );
+ input->in = malloc( sizeof(StreamImpl) );
initInputStream( input->in );
return (Tree*)input;
}
diff --git a/colm/tree.h b/colm/tree.h
index 828bab36..1c442ad7 100644
--- a/colm/tree.h
+++ b/colm/tree.h
@@ -191,7 +191,7 @@ typedef struct _Stream
FILE *file;
int fd;
- SourceStream *in;
+ StreamImpl *in;
} Stream;
typedef struct _Input
@@ -202,7 +202,7 @@ typedef struct _Input
long refs;
Kid *child;
- InputStream *in;
+ StreamImpl *in;
} Input;
typedef struct _Parser