From f8913779ce2793fc1f9996236e7c8a7ab18e31a1 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sat, 6 Apr 2013 23:10:21 -0400 Subject: eliminated RegionDef --- colm/compiler.cc | 13 +++++-------- colm/parsedata.h | 3 --- colm/parser.cc | 4 ---- colm/parsetree.cc | 23 +++++++---------------- colm/parsetree.h | 22 +--------------------- 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( 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 StringVect; typedef CmpTable 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 GraphDict; typedef DList GraphList; -typedef DList RegionDefList; - struct TypeAlias { TypeAlias( const InputLoc &loc, Namespace *nspace, -- cgit v1.2.1