summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/consinit.cc8
-rw-r--r--src/loadcolm.cc18
-rw-r--r--src/loadinit.cc2
-rw-r--r--src/parser.cc29
-rw-r--r--src/parser.h2
5 files changed, 25 insertions, 34 deletions
diff --git a/src/consinit.cc b/src/consinit.cc
index f447a372..1174bbd2 100644
--- a/src/consinit.cc
+++ b/src/consinit.cc
@@ -451,7 +451,7 @@ void ConsInit::definition( const String &name, Production *prod1, Production *pr
prodAppend( defList, prod3 );
prodAppend( defList, prod4 );
- NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), contextStack.top(), false );
+ NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), curContext(), false );
ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ );
cflDef( ntDef, objectDef, defList );
}
@@ -463,7 +463,7 @@ void ConsInit::definition( const String &name, Production *prod1, Production *pr
prodAppend( defList, prod2 );
prodAppend( defList, prod3 );
- NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), contextStack.top(), false );
+ NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), curContext(), false );
ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ );
cflDef( ntDef, objectDef, defList );
}
@@ -474,7 +474,7 @@ void ConsInit::definition( const String &name, Production *prod1, Production *pr
prodAppend( defList, prod1 );
prodAppend( defList, prod2 );
- NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), contextStack.top(), false );
+ NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), curContext(), false );
ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ );
cflDef( ntDef, objectDef, defList );
}
@@ -484,7 +484,7 @@ void ConsInit::definition( const String &name, Production *prod )
LelDefList *defList = new LelDefList;
prodAppend( defList, prod );
- NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), contextStack.top(), false );
+ NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), curContext(), false );
ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ );
cflDef( ntDef, objectDef, defList );
}
diff --git a/src/loadcolm.cc b/src/loadcolm.cc
index c6be2c49..a69983d6 100644
--- a/src/loadcolm.cc
+++ b/src/loadcolm.cc
@@ -423,13 +423,11 @@ struct LoadColm
LangVarRef *walkOptLabel( opt_label optLabel )
{
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
-
LangVarRef *varRef = 0;
if ( optLabel.prodName() == opt_label::_Id ) {
String id = optLabel.id().data();
varRef = LangVarRef::cons( optLabel.id().loc(),
- context, curScope, id );
+ curContext(), curScope, id );
}
return varRef;
}
@@ -594,7 +592,7 @@ struct LoadColm
ObjectDef *localFrame = blockOpen();
StmtList *stmtList = walkLangStmtList( optTranslate.lang_stmt_list() );
block = CodeBlock::cons( stmtList, localFrame );
- block->context = contextStack.top();
+ block->context = curContext();
blockClose();
}
return block;
@@ -848,7 +846,7 @@ struct LoadColm
StmtList *stmtList = walkLangStmtList( OptReduce.lang_stmt_list() );
block = CodeBlock::cons( stmtList, localFrame );
- block->context = contextStack.top();
+ block->context = curContext();
blockClose();
}
@@ -1088,7 +1086,7 @@ struct LoadColm
bool reduceFirst = cflDef.opt_reduce_first().REDUCEFIRST() != 0;
NtDef *ntDef = NtDef::cons( name, namespaceStack.top(),
- contextStack.top(), reduceFirst );
+ curContext(), reduceFirst );
BaseParser::cflDef( ntDef, objectDef, defList );
}
@@ -1151,13 +1149,11 @@ struct LoadColm
LangVarRef *walkVarRef( var_ref varRef )
{
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
-
qual Qual = varRef.qual();
QualItemVect *qualItemVect = walkQual( Qual );
String id = varRef.id().data();
LangVarRef *langVarRef = LangVarRef::cons( varRef.id().loc(),
- context, curScope, qualItemVect, id );
+ curContext(), curScope, qualItemVect, id );
return langVarRef;
}
@@ -1800,8 +1796,6 @@ struct LoadColm
IterCall *walkIterCall( iter_call Tree )
{
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
-
IterCall *iterCall = 0;
switch ( Tree.prodName() ) {
case iter_call::_Call: {
@@ -1814,7 +1808,7 @@ struct LoadColm
case iter_call::_Id: {
String tree = Tree.id().data();
LangVarRef *varRef = LangVarRef::cons( Tree.id().loc(),
- context, curScope, tree );
+ curContext(), curScope, tree );
LangTerm *langTerm = LangTerm::cons( Tree.id().loc(),
LangTerm::VarRefType, varRef );
LangExpr *langExpr = LangExpr::cons( langTerm );
diff --git a/src/loadinit.cc b/src/loadinit.cc
index e26f731d..1330ac6d 100644
--- a/src/loadinit.cc
+++ b/src/loadinit.cc
@@ -269,7 +269,7 @@ void LoadInit::walkDefinition( item &define )
LelDefList *defList = new LelDefList;
walkProdList( name, defList, ProdList );
- NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), contextStack.top(), false );
+ NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), curContext(), false );
ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ );
cflDef( ntDef, objectDef, defList );
}
diff --git a/src/parser.cc b/src/parser.cc
index 586aefe2..f8d627fb 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -188,7 +188,7 @@ void BaseParser::defineToken( const InputLoc &loc, String name, LexJoin *join, O
RegionSet *regionSet = regionStack.top();
TokenDef *tokenDef = TokenDef::cons( name, String(), false, ignore, join,
- transBlock, loc, 0, nspace, regionSet, objectDef, contextStack.top() );
+ transBlock, loc, 0, nspace, regionSet, objectDef, curContext() );
regionSet->tokenDefList.append( tokenDef );
nspace->tokenDefList.append( tokenDef );
@@ -363,7 +363,7 @@ void BaseParser::functionDef( StmtList *stmtList, ObjectDef *localFrame,
Function *newFunction = Function::cons( typeRef, name,
paramList, codeBlock, pd->nextFuncId++, false, exprt );
pd->functionList.append( newFunction );
- newFunction->inContext = contextStack.top();
+ newFunction->inContext = curContext();
}
void BaseParser::iterDef( StmtList *stmtList, ObjectDef *localFrame,
@@ -382,10 +382,10 @@ LangStmt *BaseParser::globalDef( ObjectField *objField, LangExpr *expr,
Context *context = 0;
ObjectDef *object = 0;
- if ( contextStack.length() == 0 )
+ if ( curContext() == 0 )
object = pd->globalObjectDef;
else {
- context = contextStack.top();
+ context = curContext();
objField->context = context;
object = context->contextObjDef;
}
@@ -561,7 +561,6 @@ LangExpr *BaseParser::parseCmd( const InputLoc &loc, bool stop, ObjectField *obj
LangExpr *expr = 0;
Namespace *nspace = namespaceStack.top();
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
/* We are constructing a parser, sending it items, then returning it.
* Thisis the constructor for the parser. */
@@ -575,7 +574,7 @@ LangExpr *BaseParser::parseCmd( const InputLoc &loc, bool stop, ObjectField *obj
LangVarRef *varRef = 0;
if ( objField != 0 ) {
varRef = LangVarRef::cons( objField->loc,
- context, curScope, objField->name );
+ curContext(), curScope, objField->name );
}
/* The typeref for the parser. */
@@ -673,8 +672,6 @@ ConsItemList *BaseParser::consListConcat( ConsItemList *list1,
LangStmt *BaseParser::forScope( const InputLoc &loc, const String &data,
ObjNameScope *scope, TypeRef *typeRef, IterCall *iterCall, StmtList *stmtList )
{
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
-
/* Check for redeclaration. */
if ( curScope->checkRedecl( data ) != 0 )
error( loc ) << "variable " << data << " redeclared" << endp;
@@ -686,7 +683,7 @@ LangStmt *BaseParser::forScope( const InputLoc &loc, const String &data,
curScope->insertField( data, iterField );
LangStmt *stmt = LangStmt::cons( loc, LangStmt::ForIterType,
- iterField, typeRef, iterCall, stmtList, context, scope );
+ iterField, typeRef, iterCall, stmtList, curContext(), scope );
return stmt;
}
@@ -697,7 +694,7 @@ void BaseParser::preEof( const InputLoc &loc, StmtList *stmtList, ObjectDef *loc
error(loc) << "preeof must be used inside an existing region" << endl;
CodeBlock *codeBlock = CodeBlock::cons( stmtList, localFrame );
- codeBlock->context = contextStack.length() == 0 ? 0 : contextStack.top();
+ codeBlock->context = curContext();
RegionSet *regionSet = regionStack.top();
regionSet->tokenIgnore->preEofBlock = codeBlock;
@@ -769,7 +766,6 @@ LangExpr *BaseParser::construct( const InputLoc &loc, ObjectField *objField,
ConsItemList *list, TypeRef *typeRef, FieldInitVect *fieldInitVect )
{
Namespace *nspace = namespaceStack.top();
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
Constructor *constructor = Constructor::cons( loc, nspace,
list, pd->nextPatConsId++ );
@@ -778,7 +774,7 @@ LangExpr *BaseParser::construct( const InputLoc &loc, ObjectField *objField,
LangVarRef *varRef = 0;
if ( objField != 0 ) {
varRef = LangVarRef::cons( objField->loc,
- context, curScope, objField->name );
+ curContext(), curScope, objField->name );
}
LangExpr *expr = LangExpr::cons( LangTerm::cons( loc, LangTerm::ConstructType,
@@ -818,7 +814,6 @@ LangStmt *BaseParser::varDef( ObjectField *objField,
LangExpr *expr, LangStmt::Type assignType )
{
LangStmt *stmt = 0;
- Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
/* Check for redeclaration. */
if ( curScope->checkRedecl( objField->name ) != 0 ) {
@@ -833,7 +828,7 @@ LangStmt *BaseParser::varDef( ObjectField *objField,
if ( expr != 0 ) {
LangVarRef *varRef = LangVarRef::cons( objField->loc,
- context, curScope, objField->name );
+ curContext(), curScope, objField->name );
stmt = LangStmt::cons( objField->loc, assignType, varRef, expr );
}
@@ -845,7 +840,7 @@ LangStmt *BaseParser::exportStmt( ObjectField *objField, LangStmt::Type assignTy
{
LangStmt *stmt = 0;
- if ( contextStack.length() != 0 )
+ if ( curContext() != 0 )
error(objField->loc) << "cannot export parser context variables" << endp;
ObjectDef *object = pd->globalObjectDef;
@@ -883,10 +878,10 @@ LangExpr *BaseParser::require( const InputLoc &loc,
void BaseParser::contextVarDef( const InputLoc &loc, ObjectField *objField )
{
ObjectDef *object;
- if ( contextStack.length() == 0 )
+ if ( curContext() == 0 )
error(loc) << "internal error: no context stack items found" << endp;
- Context *context = contextStack.top();
+ Context *context = curContext();
objField->context = context;
object = context->contextObjDef;
diff --git a/src/parser.h b/src/parser.h
index 3eec64ce..a3829d55 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -49,6 +49,8 @@ struct BaseParser
bool insideRegion()
{ return regionStack.length() > 0; }
+ Context *curContext()
+ { return contextStack.length() == 0 ? 0 : contextStack.top(); }
/* Lexical feedback. */