summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-04-06 23:10:21 -0400
committerAdrian Thurston <thurston@complang.org>2013-04-06 23:10:21 -0400
commitf8913779ce2793fc1f9996236e7c8a7ab18e31a1 (patch)
treeccd75dca1645d8662392a2c5cc286836c7775745
parentd93b9cea5c7711a4737b04cb6a3f0df7fc0d4f44 (diff)
downloadcolm-f8913779ce2793fc1f9996236e7c8a7ab18e31a1.tar.gz
eliminated RegionDef
-rw-r--r--colm/compiler.cc13
-rw-r--r--colm/parsedata.h3
-rw-r--r--colm/parser.cc4
-rw-r--r--colm/parsetree.cc23
-rw-r--r--colm/parsetree.h22
5 files changed, 13 insertions, 52 deletions
diff --git a/colm/compiler.cc b/colm/compiler.cc
index 627e1e83..bace6ec6 100644
--- a/colm/compiler.cc
+++ b/colm/compiler.cc
@@ -610,9 +610,9 @@ NameInst *Compiler::makeNameTree()
nextNameId = 1;
/* First make the name tree. */
- for ( RegionDefList::Iter rdel = regionDefList; rdel.lte(); rdel++ ) {
+ for ( RegionList::Iter rel = regionList; rel.lte(); rel++ ) {
/* Recurse on the instance. */
- rdel->makeNameTree( rdel->loc, this );
+ rel->makeNameTree( rel->loc, this );
}
return 0;
@@ -625,12 +625,12 @@ FsmGraph *Compiler::makeAllRegions()
NameInst **nameIndex = makeNameIndex();
int numGraphs = 0;
- FsmGraph **graphs = new FsmGraph*[regionDefList.length()];
+ FsmGraph **graphs = new FsmGraph*[regionList.length()];
/* Make all the instantiations, we know that main exists in this list. */
- for ( RegionDefList::Iter rdel = regionDefList; rdel.lte(); rdel++ ) {
+ for ( RegionList::Iter rel = regionList; rel.lte(); rel++ ) {
/* Build the graph from a walk of the parse tree. */
- FsmGraph *newGraph = rdel->walk( this );
+ FsmGraph *newGraph = rel->walk( this );
/* Wrap up the construction. */
finishGraphBuild( newGraph );
@@ -761,9 +761,6 @@ void Compiler::createDefaultScanner()
regionList.length() );
regionList.append( defaultRegion );
- RegionDef *rdel = new RegionDef( defaultRegion, loc );
- regionDefList.append( rdel );
-
RegionSet *regionSet = new RegionSet( defaultRegion, 0, 0, 0 );
regionSetList.append( regionSet );
diff --git a/colm/parsedata.h b/colm/parsedata.h
index d46fca8e..1aae3040 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -563,9 +563,6 @@ struct Compiler
* Data collected during the parse.
*/
- /* The list of instances. */
- RegionDefList regionDefList;
-
/* List of actions. Will be pasted into a switch statement. */
ActionList actionList;
diff --git a/colm/parser.cc b/colm/parser.cc
index 72c4abee..98cf6c8e 100644
--- a/colm/parser.cc
+++ b/colm/parser.cc
@@ -99,10 +99,6 @@ TokenRegion *BaseParser::createRegion( const InputLoc &loc )
pd->regionList.append( tokenRegion );
- /* New element in the dict, all good. */
- RegionDef *regionDef = new RegionDef( tokenRegion, loc );
- pd->regionDefList.append( regionDef );
-
return tokenRegion;
}
diff --git a/colm/parsetree.cc b/colm/parsetree.cc
index 14c774a5..97bbcdaf 100644
--- a/colm/parsetree.cc
+++ b/colm/parsetree.cc
@@ -195,32 +195,20 @@ FsmGraph *LexDefinition::walk( Compiler *pd )
return rtnVal;
}
-
-FsmGraph *RegionDef::walk( Compiler *pd )
-{
- /* Recurse on the expression. */
- FsmGraph *rtnVal = tokenRegion->walk( pd );
-
- /* Need the entry point for the region. */
- rtnVal->setEntry( tokenRegion->regionNameInst->id, rtnVal->startState );
-
- return rtnVal;
-}
-
-void RegionDef::makeNameTree( const InputLoc &loc, Compiler *pd )
+void TokenRegion::makeNameTree( const InputLoc &loc, Compiler *pd )
{
NameInst *nameInst = new NameInst( pd->nextNameId++ );
pd->nameInstList.append( nameInst );
/* Guess we do this now. */
- tokenRegion->makeActions( pd );
+ makeActions( pd );
/* Save off the name inst into the token region. This is only legal for
* token regions because they are only ever referenced once (near the root
* of the name tree). They cannot have more than one corresponding name
* inst. */
- assert( tokenRegion->regionNameInst == 0 );
- tokenRegion->regionNameInst = nameInst;
+ assert( regionNameInst == 0 );
+ regionNameInst = nameInst;
}
InputLoc TokenInstance::getLoc()
@@ -547,6 +535,9 @@ FsmGraph *TokenRegion::walk( Compiler *pd )
delete[] parts;
}
+ /* Need the entry point for the region. */
+ retFsm->setEntry( regionNameInst->id, retFsm->startState );
+
return retFsm;
}
diff --git a/colm/parsetree.h b/colm/parsetree.h
index f71ed97f..6adc09a2 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -274,24 +274,6 @@ struct LexDefinition
LexJoin *join;
};
-/*
- * A Variable Definition
- */
-struct RegionDef
-:
- public DListEl<RegionDef>
-{
- RegionDef( TokenRegion *tokenRegion, const InputLoc &loc )
- : tokenRegion(tokenRegion), loc(loc) { }
-
- /* Parse tree traversal. */
- FsmGraph *walk( Compiler *pd );
- void makeNameTree( const InputLoc &loc, Compiler *pd );
-
- TokenRegion *tokenRegion;
- InputLoc loc;
-};
-
typedef Vector<String> StringVect;
typedef CmpTable<String, CmpStr> CmpStrVect;
@@ -605,7 +587,7 @@ struct TokenRegion
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
- void makeNameTree( Compiler *pd );
+ void makeNameTree( const InputLoc &loc, Compiler *pd );
void runLongestMatch( Compiler *pd, FsmGraph *graph );
void transferScannerLeavingActions( FsmGraph *graph );
Action *newAction( Compiler *pd, const InputLoc &loc, const String &name,
@@ -729,8 +711,6 @@ struct GraphDictEl
typedef AvlTree<GraphDictEl, String, CmpStr> GraphDict;
typedef DList<GraphDictEl> GraphList;
-typedef DList<RegionDef> RegionDefList;
-
struct TypeAlias
{
TypeAlias( const InputLoc &loc, Namespace *nspace,