summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-04-06 12:27:47 -0400
committerAdrian Thurston <thurston@complang.org>2013-04-06 12:27:47 -0400
commit2d2bef4a39aef0721ad19e75770852e60524c198 (patch)
tree0c74ec8e846773d5fd21079ca3f3499657b00ec7
parentfb0c16f087087cac05bdd92477ea1839943cd677 (diff)
downloadcolm-2d2bef4a39aef0721ad19e75770852e60524c198.tar.gz
initialize all StreamImpl structs
Moved all StreamImpl allocation to input.c, made sure all impls are allocated through a reasonable call hierarchy.
-rw-r--r--colm/compiler.cc3
-rw-r--r--colm/input.c52
-rw-r--r--colm/input.h1
-rw-r--r--colm/pdarun.h1
-rw-r--r--colm/tree.c4
5 files changed, 36 insertions, 25 deletions
diff --git a/colm/compiler.cc b/colm/compiler.cc
index 6344608c..447e6a67 100644
--- a/colm/compiler.cc
+++ b/colm/compiler.cc
@@ -1012,8 +1012,7 @@ void Compiler::initEmptyScanners()
PdaRun *Compiler::parsePattern( Program *prg, Tree **sp, const InputLoc &loc,
int parserId, StreamImpl *sourceStream )
{
- StreamImpl *in = new StreamImpl;
- initStreamImpl( in );
+ StreamImpl *in = newSourceStreamGeneric();
PdaRun *pdaRun = new PdaRun;
initPdaRun( prg, pdaRun, pdaTables, parserId, 0, false, 0 );
diff --git a/colm/input.c b/colm/input.c
index 5ccedb0c..38e592a8 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -76,24 +76,6 @@ void clearSourceStream( struct ColmProgram *prg, Tree **sp, StreamImpl *sourceSt
sourceStream->queue = 0;
}
-StreamImpl *newSourceStreamFile( FILE *file )
-{
- StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
- memset( ss, 0, sizeof(StreamImpl) );
- ss->file = file;
- ss->funcs = &fileFuncs;
- return ss;
-}
-
-StreamImpl *newSourceStreamFd( long fd )
-{
- StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
- memset( ss, 0, sizeof(StreamImpl) );
- ss->fd = fd;
- ss->funcs = &fdFuncs;
- return ss;
-}
-
/* Keep the position up to date after consuming text. */
void updatePosition( StreamImpl *is, const char *data, long length )
{
@@ -370,8 +352,6 @@ void initStreamImpl( StreamImpl *inputStream )
inputStream->line = 1;
inputStream->column = 1;
inputStream->byte = 0;
-
- inputStream->funcs = &streamFuncs;
}
void clearStreamImpl( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream )
@@ -993,3 +973,35 @@ struct StreamFuncs fileFuncs =
.undoConsumeData = &fdUndoConsumeData,
.getDataSource = &fileGetDataSource,
};
+
+
+StreamImpl *newSourceStreamFile( FILE *file )
+{
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ initStreamImpl( ss );
+ ss->funcs = &fileFuncs;
+
+ ss->file = file;
+
+ return ss;
+}
+
+StreamImpl *newSourceStreamFd( long fd )
+{
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ initStreamImpl( ss );
+ ss->funcs = &fdFuncs;
+
+ ss->fd = fd;
+
+ return ss;
+}
+
+StreamImpl *newSourceStreamGeneric( )
+{
+ StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl));
+ initStreamImpl( ss );
+ ss->funcs = &streamFuncs;
+
+ return ss;
+}
diff --git a/colm/input.h b/colm/input.h
index 314dc32a..93b3c28f 100644
--- a/colm/input.h
+++ b/colm/input.h
@@ -165,6 +165,7 @@ StreamImpl *newSourceStreamFd( long fd );
void updatePosition( StreamImpl *inputStream, const char *data, long length );
void undoPosition( StreamImpl *inputStream, const char *data, long length );
+StreamImpl *newSourceStreamGeneric();
#ifdef __cplusplus
}
diff --git a/colm/pdarun.h b/colm/pdarun.h
index c9d6285a..f30e602a 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -397,7 +397,6 @@ void decrementSteps( PdaRun *pdaRun );
int makeReverseCode( PdaRun *pdaRun );
void transferReverseCode( PdaRun *pdaRun, ParseTree *tree );
-void initStreamImpl( StreamImpl *inputStream );
void clearStreamImpl( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream );
void initSourceStream( StreamImpl *in );
void clearSourceStream( struct ColmProgram *prg, Tree **sp, StreamImpl *sourceStream );
diff --git a/colm/tree.c b/colm/tree.c
index b1b46355..67529778 100644
--- a/colm/tree.c
+++ b/colm/tree.c
@@ -324,8 +324,8 @@ Tree *constructStream( Program *prg )
Stream *input = streamAllocate( prg );
input->refs = 0;
input->id = LEL_ID_STREAM;
- input->in = malloc( sizeof(StreamImpl) );
- initStreamImpl( input->in );
+
+ input->in = newSourceStreamGeneric();
return (Tree*)input;
}