summaryrefslogtreecommitdiff
path: root/colm
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-02-23 09:42:56 -0500
committerAdrian Thurston <thurston@complang.org>2013-02-23 09:42:56 -0500
commite05748a53520a7feb110934a8d0fd2303b0e97de (patch)
tree45f8b2ed382649c251b481ac2dd788de21b5ea81 /colm
parent666ed6d54171b326ed65f3a6ad1bedab12e0db4c (diff)
downloadcolm-e05748a53520a7feb110934a8d0fd2303b0e97de.tar.gz
added a function to the context stack for retreiving the top
Diffstat (limited to 'colm')
-rw-r--r--colm/lmparse.kh2
-rw-r--r--colm/lmparse.kl16
-rw-r--r--colm/parsetree.h8
3 files changed, 15 insertions, 11 deletions
diff --git a/colm/lmparse.kh b/colm/lmparse.kh
index 14ff9960..116bd911 100644
--- a/colm/lmparse.kh
+++ b/colm/lmparse.kh
@@ -84,7 +84,7 @@ struct ColmParser
RegionSetVect regionStack;
NamespaceVect namespaceStack;
- ContextVect contextStack;
+ ContextStack contextStack;
String curDefineId;
ObjectDef *curObjectDef;
diff --git a/colm/lmparse.kl b/colm/lmparse.kl
index 110077bd..8164e353 100644
--- a/colm/lmparse.kl
+++ b/colm/lmparse.kl
@@ -204,7 +204,7 @@ void ColmParser::tokenDef( const InputLoc &loc, String name, LexJoin *join,
TokenDef *tokenDef = TokenDef::cons( name, String(), false, ignore, join,
transBlock, loc, pd->nextTokenId++, nspace, regionSet->tokenIgnore,
&reCaptureVect, curObjectDef,
- contextStack.length() > 0 ? contextStack.top() : 0 );
+ contextStack.top() );
regionSet->tokenIgnore->tokenDefList.append( tokenDef );
nspace->tokenDefList.append( tokenDef );
@@ -217,7 +217,7 @@ void ColmParser::tokenDef( const InputLoc &loc, String name, LexJoin *join,
TokenDef *tokenDefIgn = TokenDef::cons( name + "_ign", String(), false, ignore, join,
0, loc, pd->nextTokenId++, nspace, regionSet->ignoreOnly,
&reCaptureVect, curObjectDef,
- contextStack.length() > 0 ? contextStack.top() : 0 );
+ contextStack.top() );
tokenDefIgn->dupOf = tokenDef;
@@ -228,7 +228,7 @@ void ColmParser::tokenDef( const InputLoc &loc, String name, LexJoin *join,
TokenDef *tokenDefTok = TokenDef::cons( name + "_tok", String(), false, ignore, join,
0, loc, pd->nextTokenId++, nspace, regionSet->tokenOnly,
&reCaptureVect, curObjectDef,
- contextStack.length() > 0 ? contextStack.top() : 0 );
+ contextStack.top() );
tokenDefTok->dupOf = tokenDef;
@@ -346,9 +346,7 @@ void ColmParser::functionDef( StmtList *stmtList, ObjectDef *localFrame,
Function *newFunction = Function::cons( typeRef, name,
paramList, codeBlock, pd->nextFuncId++, false );
pd->functionList.append( newFunction );
-
- if ( contextStack.length() > 0 )
- newFunction->inContext = contextStack.top();
+ newFunction->inContext = contextStack.top();
}
void ColmParser::iterDef( StmtList *stmtList, ObjectDef *localFrame,
@@ -398,7 +396,7 @@ void ColmParser::cflDef( const String &name, LelDefList *defList, bool reduceFir
nspace,
defList,
curObjectDef,
- contextStack.length() > 0 ? contextStack.top() : 0,
+ contextStack.top(),
reduceFirst );
nspace->ntDefList.append( ntDef );
@@ -1857,7 +1855,7 @@ opt_translate:
block_open lang_stmt_list block_close
final {
$$->transBlock = CodeBlock::cons( $2->stmtList, $1->localFrame );
- $$->transBlock->context = contextStack.length() == 0 ? 0 : contextStack.top();
+ $$->transBlock->context = contextStack.top();
};
opt_translate:
@@ -1912,7 +1910,7 @@ opt_reduce_code:
start_reduce lang_stmt_list block_close
final {
$$->codeBlock = CodeBlock::cons( $2->stmtList, $1->localFrame );
- $$->codeBlock->context = contextStack.length() == 0 ? 0 : contextStack.top();
+ $$->codeBlock->context = contextStack.top();
};
nonterm start_reduce uses block_open;
diff --git a/colm/parsetree.h b/colm/parsetree.h
index d204a541..6a3e4c31 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -326,7 +326,13 @@ struct ReCapture
ObjectField *objField;
};
-typedef Vector<Context*> ContextVect;
+struct ContextStack
+ : public Vector<Context*>
+{
+ Context *top()
+ { return length() > 0 ? Vector<Context*>::top() : 0; }
+};
+
struct Context
{