diff options
-rw-r--r-- | colm/bytecode.c | 6 | ||||
-rw-r--r-- | colm/compiler.cc | 6 | ||||
-rw-r--r-- | colm/ctinput.cc | 4 | ||||
-rw-r--r-- | colm/exports.cc | 2 | ||||
-rw-r--r-- | colm/input.c | 28 | ||||
-rw-r--r-- | colm/input.h | 11 | ||||
-rw-r--r-- | colm/load.cc | 10 | ||||
-rw-r--r-- | colm/main.cc | 10 | ||||
-rw-r--r-- | colm/pdarun.c | 3 | ||||
-rw-r--r-- | colm/string.c | 2 | ||||
-rw-r--r-- | colm/tree.c | 15 | ||||
-rw-r--r-- | colm/tree.h | 10 |
12 files changed, 52 insertions, 55 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index 6fa56eb8..b0e9779a 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -3506,7 +3506,7 @@ again: Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); if ( prg->stdinVal == 0 ) { - prg->stdinVal = openStreamFd( prg, 0 ); + prg->stdinVal = openStreamFd( prg, "<stdin>", 0 ); treeUpref( (Tree*)prg->stdinVal ); } @@ -3521,7 +3521,7 @@ again: Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); if ( prg->stdoutVal == 0 ) { - prg->stdoutVal = openStreamFd( prg, 1 ); + prg->stdoutVal = openStreamFd( prg, "<stdout>", 1 ); treeUpref( (Tree*)prg->stdoutVal ); } @@ -3536,7 +3536,7 @@ again: Tree *obj = vm_pop(); treeDownref( prg, sp, obj ); if ( prg->stderrVal == 0 ) { - prg->stderrVal = openStreamFd( prg, 2 ); + prg->stderrVal = openStreamFd( prg, "<stderr>", 2 ); treeUpref( (Tree*)prg->stderrVal ); } diff --git a/colm/compiler.cc b/colm/compiler.cc index 447e6a67..627e1e83 100644 --- a/colm/compiler.cc +++ b/colm/compiler.cc @@ -1012,7 +1012,7 @@ void Compiler::initEmptyScanners() PdaRun *Compiler::parsePattern( Program *prg, Tree **sp, const InputLoc &loc, int parserId, StreamImpl *sourceStream ) { - StreamImpl *in = newSourceStreamGeneric(); + StreamImpl *in = newSourceStreamGeneric( "<internal>" ); PdaRun *pdaRun = new PdaRun; initPdaRun( prg, pdaRun, pdaTables, parserId, 0, false, 0 ); @@ -1050,12 +1050,12 @@ void Compiler::parsePatterns() Tree **sp = prg->stackRoot; for ( ConsList::Iter cons = replList; cons.lte(); cons++ ) { - StreamImpl *in = newSourceStreamCons( cons ); + StreamImpl *in = newSourceStreamCons( "<internal>", cons ); cons->pdaRun = parsePattern( prg, sp, cons->loc, cons->langEl->parserId, in ); } for ( PatList::Iter pat = patternList; pat.lte(); pat++ ) { - StreamImpl *in = newSourceStreamPat( pat ); + StreamImpl *in = newSourceStreamPat( "<internal>", pat ); pat->pdaRun = parsePattern( prg, sp, pat->loc, pat->langEl->parserId, in ); } diff --git a/colm/ctinput.cc b/colm/ctinput.cc index 2a3ff833..e8aa0f7f 100644 --- a/colm/ctinput.cc +++ b/colm/ctinput.cc @@ -37,7 +37,7 @@ extern StreamFuncs replFuncs; * Pattern */ -StreamImpl *newSourceStreamPat( Pattern *pattern ) +StreamImpl *newSourceStreamPat( const char *name, Pattern *pattern ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); memset( ss, 0, sizeof(StreamImpl) ); @@ -235,7 +235,7 @@ StreamFuncs patternFuncs = * Constructor */ -StreamImpl *newSourceStreamCons( Constructor *constructor ) +StreamImpl *newSourceStreamCons( const char *name, Constructor *constructor ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); memset( ss, 0, sizeof(StreamImpl) ); diff --git a/colm/exports.cc b/colm/exports.cc index 4dff5a0d..071aca85 100644 --- a/colm/exports.cc +++ b/colm/exports.cc @@ -66,7 +66,7 @@ void Compiler::generateExports() out << "struct ColmLocation\n" "{\n" - " void *file;\n" + " const char *name;\n" " long line;\n" " long column;\n" " long byte;\n" diff --git a/colm/input.c b/colm/input.c index 38e592a8..ee62af36 100644 --- a/colm/input.c +++ b/colm/input.c @@ -49,10 +49,6 @@ extern struct StreamFuncs fileFuncs; extern struct StreamFuncs fdFuncs; extern struct StreamFuncs streamFuncs; -void initSourceStream( StreamImpl *inputStream ) -{ -} - void clearSourceStream( struct ColmProgram *prg, Tree **sp, StreamImpl *sourceStream ) { RunBuf *buf = sourceStream->queue; @@ -269,6 +265,7 @@ int fdConsumeData( StreamImpl *ss, int length, Location *loc ) break; else { if ( loc->line == 0 ) { + loc->name = ss->name; loc->line = ss->line; loc->column = ss->column; loc->byte = ss->byte; @@ -345,13 +342,14 @@ int fdGetDataSource( StreamImpl *ss, char *dest, int length ) * StreamImpl struct, this wraps the list of input streams. */ -void initStreamImpl( StreamImpl *inputStream ) +void initStreamImpl( StreamImpl *is, const char *name ) { - memset( inputStream, 0, sizeof(StreamImpl) ); + memset( is, 0, sizeof(StreamImpl) ); - inputStream->line = 1; - inputStream->column = 1; - inputStream->byte = 0; + is->name = name; + is->line = 1; + is->column = 1; + is->byte = 0; } void clearStreamImpl( struct ColmProgram *prg, Tree **sp, StreamImpl *inputStream ) @@ -975,10 +973,10 @@ struct StreamFuncs fileFuncs = }; -StreamImpl *newSourceStreamFile( FILE *file ) +StreamImpl *newSourceStreamFile( const char *name, FILE *file ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); - initStreamImpl( ss ); + initStreamImpl( ss, name ); ss->funcs = &fileFuncs; ss->file = file; @@ -986,10 +984,10 @@ StreamImpl *newSourceStreamFile( FILE *file ) return ss; } -StreamImpl *newSourceStreamFd( long fd ) +StreamImpl *newSourceStreamFd( const char *name, long fd ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); - initStreamImpl( ss ); + initStreamImpl( ss, name ); ss->funcs = &fdFuncs; ss->fd = fd; @@ -997,10 +995,10 @@ StreamImpl *newSourceStreamFd( long fd ) return ss; } -StreamImpl *newSourceStreamGeneric( ) +StreamImpl *newSourceStreamGeneric( const char *name ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); - initStreamImpl( ss ); + initStreamImpl( ss, name ); ss->funcs = &streamFuncs; return ss; diff --git a/colm/input.h b/colm/input.h index 93b3c28f..9cbd5f38 100644 --- a/colm/input.h +++ b/colm/input.h @@ -147,6 +147,7 @@ struct _StreamImpl long column; long byte; + const char *name; FILE *file; long fd; @@ -158,14 +159,14 @@ struct _StreamImpl int consumed; }; -StreamImpl *newSourceStreamPat( struct Pattern *pattern ); -StreamImpl *newSourceStreamCons( struct Constructor *constructor ); -StreamImpl *newSourceStreamFile( FILE *file ); -StreamImpl *newSourceStreamFd( long fd ); +StreamImpl *newSourceStreamPat( const char *name, struct Pattern *pattern ); +StreamImpl *newSourceStreamCons( const char *name, struct Constructor *constructor ); +StreamImpl *newSourceStreamFile( const char *name, FILE *file ); +StreamImpl *newSourceStreamFd( const char *name, long fd ); +StreamImpl *newSourceStreamGeneric( const char *name ); 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/load.cc b/colm/load.cc index f79babb4..8702130a 100644 --- a/colm/load.cc +++ b/colm/load.cc @@ -36,14 +36,14 @@ extern RuntimeData main_runtimeData; InputLoc::InputLoc( ColmLocation *pcloc ) -: - fileName(0) { if ( pcloc != 0 ) { + fileName = pcloc->name; line = pcloc->line; col = pcloc->column; } else { + fileName = 0; line = -1; col = -1; } @@ -645,7 +645,8 @@ struct LoadSource if ( Start == 0 ) { gblErrorCount += 1; - std::cerr << inputFileName << ": parse error: " << Error.text() << std::endl; + InputLoc loc = Error.loc(); + error(loc) << file.data << ": parse error: " << Error.text() << std::endl; return 0; } @@ -1902,7 +1903,8 @@ void LoadSource::go( long activeRealm ) if ( Start == 0 ) { gblErrorCount += 1; - std::cerr << inputFileName << ": parse error: " << Error.text() << std::endl; + InputLoc loc = Error.loc(); + error(loc) << inputFileName << ": parse error: " << Error.text() << std::endl; return; } diff --git a/colm/main.cc b/colm/main.cc index 1a084555..25a2c074 100644 --- a/colm/main.cc +++ b/colm/main.cc @@ -113,12 +113,16 @@ ostream &error( const InputLoc &loc ) /* Keep the error count. */ gblErrorCount += 1; + if ( loc.fileName != 0 ) + cerr << loc.fileName << ":"; + else + cerr << "<input>:"; + if ( loc.line == -1 ) { - cerr << "error: INTERNAL: "; + cerr << "INT: "; } else { - cerr << "error: " << inputFileName << ":" << - loc.line << ":" << loc.col << ": "; + cerr << loc.line << ":" << loc.col << ": "; } return cerr; } diff --git a/colm/pdarun.c b/colm/pdarun.c index 0d352d5d..faaf45fb 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -525,10 +525,11 @@ static void reportParseError( Program *prg, Tree **sp, PdaRun *pdaRun ) errorHead = stringAllocFull( prg, formatted, strlen(formatted) ); errorHead->location = locationAllocate( prg ); + + errorHead->location->name = deepest->location->name; errorHead->location->line = line; errorHead->location->column = column; errorHead->location->byte = byte; - errorHead->location->file = deepest->location->file; } Tree *tree = constructString( prg, errorHead ); diff --git a/colm/string.c b/colm/string.c index 5b5e39e2..31472e21 100644 --- a/colm/string.c +++ b/colm/string.c @@ -47,7 +47,7 @@ Head *stringCopy( Program *prg, Head *head ) if ( head->location != 0 ) { result->location = locationAllocate( prg ); - result->location->file = head->location->file; + result->location->name = head->location->name; result->location->line = head->location->line; result->location->column = head->location->column; result->location->byte = head->location->byte; diff --git a/colm/tree.c b/colm/tree.c index 67529778..81ba92a0 100644 --- a/colm/tree.c +++ b/colm/tree.c @@ -230,21 +230,19 @@ Kid *kidListConcat( Kid *list1, Kid *list2 ) } -Stream *openStreamFile( Program *prg, FILE *file ) +Stream *openStreamFile( Program *prg, char *name, FILE *file ) { Stream *res = (Stream*)mapElAllocate( prg ); res->id = LEL_ID_STREAM; - res->in = newSourceStreamFile( file ); - initSourceStream( res->in ); + res->in = newSourceStreamFile( name, file ); return res; } -Stream *openStreamFd( Program *prg, long fd ) +Stream *openStreamFd( Program *prg, char *name, long fd ) { Stream *res = (Stream*)mapElAllocate( prg ); res->id = LEL_ID_STREAM; - res->in = newSourceStreamFd( fd ); - initSourceStream( res->in ); + res->in = newSourceStreamFd( name, fd ); return res; } @@ -268,8 +266,7 @@ Stream *openFile( Program *prg, Tree *name, Tree *mode ) memcpy( fileName, stringData(headName), stringLength(headName) ); fileName[stringLength(headName)] = 0; FILE *file = fopen( fileName, fopenMode ); - free(fileName); - return openStreamFile( prg, file ); + return openStreamFile( prg, fileName, file ); } Tree *constructInteger( Program *prg, long i ) @@ -325,7 +322,7 @@ Tree *constructStream( Program *prg ) input->refs = 0; input->id = LEL_ID_STREAM; - input->in = newSourceStreamGeneric(); + input->in = newSourceStreamGeneric( "<internal>" ); return (Tree*)input; } diff --git a/colm/tree.h b/colm/tree.h index d137a8c9..edfb60f9 100644 --- a/colm/tree.h +++ b/colm/tree.h @@ -33,15 +33,9 @@ typedef unsigned long Word; typedef unsigned long Half; struct Bindings; -typedef struct _File -{ - struct _File *prev; - struct _File *next; -} File; - typedef struct _Location { - File *file; + const char *name; long line; long column; long byte; @@ -277,7 +271,7 @@ Tree *constructStream( struct ColmProgram *prg ); int testFalse( struct ColmProgram *prg, Tree *tree ); Tree *makeTree( struct ColmProgram *prg, Tree **root, long nargs ); Stream *openFile( struct ColmProgram *prg, Tree *name, Tree *mode ); -Stream *openStreamFd( struct ColmProgram *prg, long fd ); +Stream *openStreamFd( struct ColmProgram *prg, char *name, long fd ); Kid *copyIgnoreList( struct ColmProgram *prg, Kid *ignoreHeader ); Kid *copyKidList( struct ColmProgram *prg, Kid *kidList ); void streamFree( struct ColmProgram *prg, Stream *s ); |