summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-05-28 20:06:05 -0400
committerAdrian Thurston <thurston@complang.org>2012-05-28 20:06:05 -0400
commitabdec3f192cd435854bbcf9eb51eab2189a9622d (patch)
tree12edbefe93c4e97efee40abc0994b2b9a3c7232e
parent6f5e276c1b14cf356c9c3183dad98b8df99febdf (diff)
downloadcolm-abdec3f192cd435854bbcf9eb51eab2189a9622d.tar.gz
code cleanup
Eliminated the name resolution walk within the state machine. This is from ragel and is not needed. Also removed some top level code for constructing state machines not in a scanner. We don't have this in colm, all state machines are in a scanner.
-rw-r--r--colm/compiler.cc36
-rw-r--r--colm/parsedata.h5
-rw-r--r--colm/parsetree.cc201
-rw-r--r--colm/parsetree.h12
4 files changed, 3 insertions, 251 deletions
diff --git a/colm/compiler.cc b/colm/compiler.cc
index 4a8407aa..bf45e818 100644
--- a/colm/compiler.cc
+++ b/colm/compiler.cc
@@ -892,7 +892,6 @@ NameInst *Compiler::makeJoinNameTree( Join *join )
return rootName;
}
-
/* Build the name tree and supporting data structures. */
NameInst *Compiler::makeNameTree()
{
@@ -910,43 +909,12 @@ NameInst *Compiler::makeNameTree()
return rootName;
}
-
-FsmGraph *Compiler::makeJoin( Join *join )
-{
- /* Build the name tree and supporting data structures. */
- NameInst *rootName = makeJoinNameTree( join );
- NameInst **nameIndex = makeNameIndex( rootName );
-
- /* Resove name references in the tree. */
- initNameWalk( rootName );
- join->resolveNameRefs( this );
-
- /* Make all the instantiations, we know that main exists in this list. */
- initNameWalk( rootName );
-
- /* Build the graph from a walk of the parse tree. */
- FsmGraph *newGraph = join->walk( this );
-
- /* Wrap up the construction. */
- finishGraphBuild( newGraph );
-
- newGraph->rootName = rootName;
- newGraph->nameIndex = nameIndex;
-
- return newGraph;
-}
-
FsmGraph *Compiler::makeAllRegions()
{
/* Build the name tree and supporting data structures. */
NameInst *rootName = makeNameTree( );
NameInst **nameIndex = makeNameIndex( rootName );
- /* Resove name references in the tree. */
- initNameWalk( rootName );
- for ( RegionGraphList::Iter glel = instanceList; glel.lte(); glel++ )
- glel->value->resolveNameRefs( this );
-
/* Resovle the implicit name references to the nfa instantiations. */
referenceRegions( rootName );
@@ -1045,10 +1013,10 @@ void Compiler::analyzeGraph( FsmGraph *graph )
}
}
-FsmGraph *Compiler::makeFsmGraph( Join *join )
+FsmGraph *Compiler::makeScanner()
{
/* Make the graph, do minimization. */
- FsmGraph *fsmGraph = join != 0 ? makeJoin( join ) : makeAllRegions();
+ FsmGraph *fsmGraph = makeAllRegions();
/* If any errors have occured in the input file then don't write anything. */
if ( gblErrorCount > 0 )
diff --git a/colm/parsedata.h b/colm/parsedata.h
index 5e3a59c2..79ba08c1 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -571,11 +571,8 @@ struct Compiler
/* Make the graph from a graph dict node. Does minimization. */
void finishGraphBuild( FsmGraph *graph );
- FsmGraph *makeJoin( Join *join );
FsmGraph *makeAllRegions();
- FsmGraph *makeFsmGraph( Join *join );
- FsmGraph *makeScanner()
- { return makeFsmGraph(0); }
+ FsmGraph *makeScanner();
void analyzeAction( Action *action, InlineList *inlineList );
void analyzeGraph( FsmGraph *graph );
diff --git a/colm/parsetree.cc b/colm/parsetree.cc
index 5ae345c7..64f8178a 100644
--- a/colm/parsetree.cc
+++ b/colm/parsetree.cc
@@ -227,18 +227,6 @@ void VarDef::makeNameTree( const InputLoc &loc, Compiler *pd )
pd->curNameInst = prevNameInst;
}
-void VarDef::resolveNameRefs( Compiler *pd )
-{
- /* Entering into a new scope. */
- NameFrame nameFrame = pd->enterNameScope( true, 1 );
-
- /* Recurse. */
- join->resolveNameRefs( pd );
-
- /* The name scope ends, pop the name instantiation. */
- pd->popNameScope( nameFrame );
-}
-
FsmGraph *RegionDef::walk( Compiler *pd )
{
/* We enter into a new name scope. */
@@ -282,18 +270,6 @@ void RegionDef::makeNameTree( const InputLoc &loc, Compiler *pd )
pd->curNameInst = prevNameInst;
}
-void RegionDef::resolveNameRefs( Compiler *pd )
-{
- /* Entering into a new scope. */
- NameFrame nameFrame = pd->enterNameScope( true, 1 );
-
- /* Recurse. */
- tokenRegion->resolveNameRefs( pd );
-
- /* The name scope ends, pop the name instantiation. */
- pd->popNameScope( nameFrame );
-}
-
InputLoc TokenDef::getLoc()
{
return action != 0 ? action->loc : semiLoc;
@@ -424,21 +400,6 @@ void TokenRegion::makeNameTree( Compiler *pd )
pd->curNameInst = prevNameInst;
}
-void TokenRegion::resolveNameRefs( Compiler *pd )
-{
- /* The longest match gets its own name scope. */
- NameFrame nameFrame = pd->enterNameScope( true, 1 );
-
- /* Take an action reference for each longest match item and recurse. */
- for ( TokenDefListReg::Iter lmi = tokenDefList; lmi.lte(); lmi++ ) {
- /* Watch out for patternless tokens. */
- if ( lmi->join != 0 )
- lmi->join->resolveNameRefs( pd );
- }
-
- /* The name scope ends, pop the name instantiation. */
- pd->popNameScope( nameFrame );
-}
void TokenRegion::restart( FsmGraph *graph, FsmTrans *trans )
{
@@ -698,11 +659,6 @@ void JoinOrLm::makeNameTree( Compiler *pd )
join->makeNameTree( pd );
}
-void JoinOrLm::resolveNameRefs( Compiler *pd )
-{
- join->resolveNameRefs( pd );
-}
-
FsmGraph *RegionJoinOrLm::walk( Compiler *pd )
{
FsmGraph *rtnVal = 0;
@@ -715,11 +671,6 @@ void RegionJoinOrLm::makeNameTree( Compiler *pd )
tokenRegion->makeNameTree( pd );
}
-void RegionJoinOrLm::resolveNameRefs( Compiler *pd )
-{
- tokenRegion->resolveNameRefs( pd );
-}
-
/* Construct with a location and the first expression. */
Join::Join( Expression *expr )
:
@@ -759,19 +710,6 @@ void Join::makeNameTree( Compiler *pd )
}
-void Join::resolveNameRefs( Compiler *pd )
-{
- /* Branch on whether or not there is to be a join. */
- assert( exprList.length() == 1 );
-
- /* Recurse into the single expression. */
- exprList.head->resolveNameRefs( pd );
-
- /* Maybe the the context. */
- if ( context != 0 )
- context->resolveNameRefs( pd );
-}
-
/* Clean up after an expression node. */
Expression::~Expression()
{
@@ -873,24 +811,6 @@ void Expression::makeNameTree( Compiler *pd )
}
}
-void Expression::resolveNameRefs( Compiler *pd )
-{
- switch ( type ) {
- case OrType:
- case IntersectType:
- case SubtractType:
- case StrongSubtractType:
- expression->resolveNameRefs( pd );
- term->resolveNameRefs( pd );
- break;
- case TermType:
- term->resolveNameRefs( pd );
- break;
- case BuiltinType:
- break;
- }
-}
-
/* Clean up after a term node. */
Term::~Term()
{
@@ -1023,22 +943,6 @@ void Term::makeNameTree( Compiler *pd )
}
}
-void Term::resolveNameRefs( Compiler *pd )
-{
- switch ( type ) {
- case ConcatType:
- case RightStartType:
- case RightFinishType:
- case LeftType:
- term->resolveNameRefs( pd );
- factorWithAug->resolveNameRefs( pd );
- break;
- case FactorWithAugType:
- factorWithAug->resolveNameRefs( pd );
- break;
- }
-}
-
/* Clean up after a factor with augmentation node. */
FactorWithAug::~FactorWithAug()
{
@@ -1361,63 +1265,6 @@ void FactorWithAug::makeNameTree( Compiler *pd )
}
-void FactorWithAug::resolveNameRefs( Compiler *pd )
-{
- /* Enter into the name scope created by any labels. */
- NameFrame nameFrame = pd->enterNameScope( false, labels.length() );
-
- /* Recurse first. IMPORTANT: we must do the exact same traversal as when
- * the tree is constructed. */
- factorWithRep->resolveNameRefs( pd );
-
- /* Resolve epsilon transitions. */
- for ( int ep = 0; ep < epsilonLinks.length(); ep++ ) {
- /* Get the link. */
- EpsilonLink &link = epsilonLinks[ep];
- NameInst *resolvedName = 0;
-
- if ( link.target.length() == 1 && strcmp( link.target.data[0], "final" ) == 0 ) {
- /* Epsilon drawn to an implicit final state. An implicit final is
- * only available in join operations. */
- resolvedName = pd->localNameScope->final;
- }
- else {
- /* Do an search for the name. */
- NameSet resolved;
- pd->resolveFrom( resolved, pd->localNameScope, link.target, 0 );
- if ( resolved.length() > 0 ) {
- /* Take the first one. */
- resolvedName = resolved[0];
- if ( resolved.length() > 1 ) {
- /* Complain about the multiple references. */
- error(link.loc) << "state reference " << link.target <<
- " resolves to multiple entry points" << endl;
- errorStateLabels( resolved );
- }
- }
- }
-
- /* This is tricky, we stuff resolved epsilon transitions into one long
- * vector in the parse data structure. Since the name resolution and
- * graph generation both do identical walks of the parse tree we
- * should always find the link resolutions in the right place. */
- pd->epsilonResolvedLinks.append( resolvedName );
-
- if ( resolvedName != 0 ) {
- /* Found the name, bump of the reference count on it. */
- resolvedName->numRefs += 1;
- }
- else {
- /* Complain, no recovery action, the epsilon op will ignore any
- * epsilon transitions whose names did not resolve. */
- error(link.loc) << "could not resolve label " << link.target << endl;
- }
- }
-
- if ( labels.length() > 0 )
- pd->popNameScope( nameFrame );
-}
-
/* Clean up after a factor with repetition node. */
FactorWithRep::~FactorWithRep()
@@ -1694,25 +1541,6 @@ void FactorWithRep::makeNameTree( Compiler *pd )
}
}
-void FactorWithRep::resolveNameRefs( Compiler *pd )
-{
- switch ( type ) {
- case StarType:
- case StarStarType:
- case OptionalType:
- case PlusType:
- case ExactType:
- case MaxType:
- case MinType:
- case RangeType:
- factorWithRep->resolveNameRefs( pd );
- break;
- case FactorWithNegType:
- factorWithNeg->resolveNameRefs( pd );
- break;
- }
-}
-
/* Clean up after a factor with negation node. */
FactorWithNeg::~FactorWithNeg()
{
@@ -1774,18 +1602,6 @@ void FactorWithNeg::makeNameTree( Compiler *pd )
}
}
-void FactorWithNeg::resolveNameRefs( Compiler *pd )
-{
- switch ( type ) {
- case NegateType:
- case CharNegateType:
- factorWithNeg->resolveNameRefs( pd );
- break;
- case FactorType:
- factor->resolveNameRefs( pd );
- break;
- }
-}
/* Clean up after a factor node. */
Factor::~Factor()
@@ -1856,23 +1672,6 @@ void Factor::makeNameTree( Compiler *pd )
}
}
-void Factor::resolveNameRefs( Compiler *pd )
-{
- switch ( type ) {
- case LiteralType:
- case RangeType:
- case OrExprType:
- case RegExprType:
- break;
- case ReferenceType:
- varDef->resolveNameRefs( pd );
- break;
- case ParenType:
- join->resolveNameRefs( pd );
- break;
- }
-}
-
/* Clean up a range object. Must delete the two literals. */
Range::~Range()
{
diff --git a/colm/parsetree.h b/colm/parsetree.h
index ded36445..f6edbc35 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -323,7 +323,6 @@ struct VarDef
/* Parse tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( const InputLoc &loc, Compiler *pd );
- void resolveNameRefs( Compiler *pd );
String name;
Join *join;
@@ -340,7 +339,6 @@ struct RegionDef
/* Parse tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( const InputLoc &loc, Compiler *pd );
- void resolveNameRefs( Compiler *pd );
String name;
TokenRegion *tokenRegion;
@@ -551,7 +549,6 @@ struct TokenRegion
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
void runLongestMatch( Compiler *pd, FsmGraph *graph );
void transferScannerLeavingActions( FsmGraph *graph );
Action *newAction( Compiler *pd, const InputLoc &loc, const String &name,
@@ -769,7 +766,6 @@ struct JoinOrLm
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
Join *join;
};
@@ -783,7 +779,6 @@ struct RegionJoinOrLm
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
TokenRegion *tokenRegion;
};
@@ -799,7 +794,6 @@ struct Join
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
/* Data. */
ExprList exprList;
@@ -842,7 +836,6 @@ struct Expression
/* Tree traversal. */
FsmGraph *walk( Compiler *pd, bool lastInSeq = true );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
/* Node data. */
Expression *expression;
@@ -879,7 +872,6 @@ struct Term
FsmGraph *walk( Compiler *pd, bool lastInSeq = true );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
Term *term;
FactorWithAug *factorWithAug;
@@ -900,7 +892,6 @@ struct FactorWithAug
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
void assignActions( Compiler *pd, FsmGraph *graph, int *actionOrd );
void assignPriorities( FsmGraph *graph, int *priorOrd );
@@ -948,7 +939,6 @@ struct FactorWithRep
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
InputLoc loc;
FactorWithRep *factorWithRep;
@@ -980,7 +970,6 @@ struct FactorWithNeg
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
InputLoc loc;
FactorWithNeg *factorWithNeg;
@@ -1033,7 +1022,6 @@ struct Factor
/* Tree traversal. */
FsmGraph *walk( Compiler *pd );
void makeNameTree( Compiler *pd );
- void resolveNameRefs( Compiler *pd );
InputLoc loc;
Literal *literal;