summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-05-26 10:37:54 -0400
committerAdrian Thurston <thurston@complang.org>2012-05-26 10:37:54 -0400
commit421902f02d3e583225afa6d6686b64bc099a5366 (patch)
treeed26eece4735a9ba27a15a9cdc46b0155f076ab1
parent918350b6c680388081bd073b04306660a0f887b1 (diff)
downloadcolm-421902f02d3e583225afa6d6686b64bc099a5366.tar.gz
cleanup of the mainline
Allocating the primary processing objects in the mainline and calling them, previously had scanners allocating parser and parsers allocating parse data.
-rw-r--r--colm/lmparse.kh10
-rw-r--r--colm/lmscan.h13
-rw-r--r--colm/lmscan.rl26
-rw-r--r--colm/main.cc23
4 files changed, 37 insertions, 35 deletions
diff --git a/colm/lmparse.kh b/colm/lmparse.kh
index 722e8082..ff77d0a6 100644
--- a/colm/lmparse.kh
+++ b/colm/lmparse.kh
@@ -30,6 +30,10 @@
struct ColmParser
{
+ ColmParser( ParseData *pd, const char *fileName, const char *sectionName, const InputLoc &sectionLoc )
+ : pd(pd), sectionName(sectionName), enterRl(false)
+ {}
+
%%{
parser ColmParser;
@@ -68,14 +72,10 @@ struct ColmParser
%% write instance_data;
+
void init();
int parseLangEl( int type, const Token *token );
- ColmParser( const char *fileName, const char *sectionName, const InputLoc &sectionLoc )
- : sectionName(sectionName), enterRl(false)
- {
- pd = new ParseData( fileName, sectionName, sectionLoc, std::cout );
- }
int token( InputLoc &loc, int tokId, char *tokstart, int toklen );
void addRegularDef( const InputLoc &loc, Namespace *nspace,
diff --git a/colm/lmscan.h b/colm/lmscan.h
index 55f466b4..5badaed5 100644
--- a/colm/lmscan.h
+++ b/colm/lmscan.h
@@ -57,23 +57,18 @@ typedef Vector<const char *> ArgsVector;
extern ArgsVector includePaths;
-struct Scanner
+struct ColmScanner
{
- Scanner( const char *fileName, istream &input,
- ostream &output, ColmParser *includeToParser, int includeDepth )
+ ColmScanner( const char *fileName, istream &input,
+ ostream &output, ColmParser *parser, int includeDepth )
:
fileName(fileName), input(input), output(output),
includeDepth(includeDepth),
line(1), column(1), lastnl(0),
+ parser(parser),
parserExistsError(false),
whitespaceOn(true)
{
- if ( includeToParser != 0 )
- parser = includeToParser;
- else {
- parser = new ColmParser( fileName, "machine", InputLoc() );
- parser->init();
- }
}
ifstream *tryOpenInclude( char **pathChecks, long &found );
diff --git a/colm/lmscan.rl b/colm/lmscan.rl
index cadc8dc3..dea9da65 100644
--- a/colm/lmscan.rl
+++ b/colm/lmscan.rl
@@ -45,12 +45,12 @@ using std::endl;
write data;
}%%
-void Scanner::sectionParseInit()
+void ColmScanner::sectionParseInit()
{
%% write init;
}
-ostream &Scanner::scan_error()
+ostream &ColmScanner::scan_error()
{
/* Maintain the error count. */
gblErrorCount += 1;
@@ -58,7 +58,7 @@ ostream &Scanner::scan_error()
return cerr;
}
-bool Scanner::recursiveInclude( const char *inclFileName )
+bool ColmScanner::recursiveInclude( const char *inclFileName )
{
for ( IncludeStack::Iter si = includeStack; si.lte(); si++ ) {
if ( strcmp( si->fileName, inclFileName ) == 0 )
@@ -67,7 +67,7 @@ bool Scanner::recursiveInclude( const char *inclFileName )
return false;
}
-void Scanner::updateCol()
+void ColmScanner::updateCol()
{
char *from = lastnl;
if ( from == 0 )
@@ -77,12 +77,12 @@ void Scanner::updateCol()
lastnl = 0;
}
-void Scanner::token( int type, char c )
+void ColmScanner::token( int type, char c )
{
token( type, &c, &c + 1 );
}
-void Scanner::token( int type )
+void ColmScanner::token( int type )
{
token( type, 0, 0 );
}
@@ -92,7 +92,7 @@ bool isAbsolutePath( const char *path )
return path[0] == '/';
}
-ifstream *Scanner::tryOpenInclude( char **pathChecks, long &found )
+ifstream *ColmScanner::tryOpenInclude( char **pathChecks, long &found )
{
char **check = pathChecks;
ifstream *inFile = new ifstream;
@@ -111,7 +111,7 @@ ifstream *Scanner::tryOpenInclude( char **pathChecks, long &found )
return 0;
}
-char **Scanner::makeIncludePathChecks( const char *thisFileName, const char *fileName )
+char **ColmScanner::makeIncludePathChecks( const char *thisFileName, const char *fileName )
{
char **checks = 0;
long nextCheck = 0;
@@ -199,7 +199,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName, const char *fil
* name then check if what we are including is already in the stack. */
includeStack.append( IncludeStackItem( checks[found] ) );
- Scanner scanner( fileName, *inFile, output, parser, includeDepth+1 );
+ ColmScanner scanner( fileName, *inFile, output, parser, includeDepth+1 );
scanner.scan();
delete inFile;
@@ -253,7 +253,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName, const char *fil
)*;
}%%
-void Scanner::token( int type, char *start, char *end )
+void ColmScanner::token( int type, char *start, char *end )
{
char *tokdata = 0;
int toklen = 0;
@@ -276,7 +276,7 @@ void Scanner::token( int type, char *start, char *end )
updateCol();
}
-void Scanner::endSection( )
+void ColmScanner::endSection( )
{
/* Execute the eof actions for the section parser. */
/* Probably use: token( -1 ); */
@@ -546,7 +546,7 @@ void Scanner::endSection( )
%% write data;
-void Scanner::scan()
+void ColmScanner::scan()
{
int bufsize = 8;
char *buf = new char[bufsize];
@@ -624,7 +624,7 @@ void Scanner::scan()
delete[] buf;
}
-void Scanner::eof()
+void ColmScanner::eof()
{
InputLoc loc;
loc.fileName = "<EOF>";
diff --git a/colm/main.cc b/colm/main.cc
index 3f0f373b..058f2324 100644
--- a/colm/main.cc
+++ b/colm/main.cc
@@ -567,28 +567,31 @@ int main(int argc, const char **argv)
if ( gblErrorCount > 0 )
exit(1);
+ ParseData *pd = new ParseData( inputFileName, "machine", InputLoc(), std::cout );
+ ColmParser *parser = new ColmParser( pd, inputFileName, "machine", InputLoc() );
+ ColmScanner *scanner = new ColmScanner( inputFileName, *inStream, cout, parser, 0 );
- Scanner scanner( inputFileName, *inStream, cout, 0, 0 );
- scanner.scan();
- scanner.eof();
+ parser->init();
+ scanner->scan();
+ scanner->eof();
/* Parsing complete, check for errors.. */
if ( gblErrorCount > 0 )
return 1;
/* Initiate a compile following a parse. */
- scanner.parser->pd->semanticAnalysis();
+ pd->semanticAnalysis();
/*
* Write output.
*/
if ( generateGraphviz ) {
outStream = &cout;
- scanner.parser->pd->writeDotFile();
+ pd->writeDotFile();
}
else {
openOutput();
- scanner.parser->pd->generateOutput();
+ pd->generateOutput();
if ( outStream != 0 )
delete outStream;
@@ -602,15 +605,19 @@ int main(int argc, const char **argv)
if ( gblExportTo != 0 ) {
openExports();
- scanner.parser->pd->generateExports();
+ pd->generateExports();
delete outStream;
}
if ( gblExpImplTo != 0 ) {
openExportsImpl();
- scanner.parser->pd->generateExportsImpl();
+ scanner->parser->pd->generateExportsImpl();
delete outStream;
}
}
+ delete scanner;
+ delete parser;
+ delete pd;
+
return 0;
}