summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.cc1
-rw-r--r--src/consinit.cc6
-rw-r--r--src/loadcolm.cc12
-rw-r--r--src/loadinit.cc8
-rw-r--r--src/lookup.cc10
-rw-r--r--src/parsedata.h2
-rw-r--r--src/parser.cc23
-rw-r--r--src/parsetree.h19
-rw-r--r--src/resolve.cc8
-rw-r--r--src/synthesis.cc25
10 files changed, 52 insertions, 62 deletions
diff --git a/src/compiler.cc b/src/compiler.cc
index aa3ae26a..e2c0282a 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -397,7 +397,6 @@ Compiler::Compiler( )
predValue(0),
nextMatchEndNum(0),
argvTypeRef(0),
- context(0),
inContiguous(false),
contiguousOffset(0),
contiguousStretch(0)
diff --git a/src/consinit.cc b/src/consinit.cc
index 32c4f264..394b51f5 100644
--- a/src/consinit.cc
+++ b/src/consinit.cc
@@ -746,7 +746,7 @@ void ConsInit::parseInput( StmtList *stmtList )
popQual->append( QualItem( QualItem::Dot, internal, String( "argv" ) ) );
LangVarRef *popRef = LangVarRef::cons( internal,
- pd->curLocalFrame->rootScope, popQual, String("pop") );
+ 0, pd->curLocalFrame->rootScope, popQual, String("pop") );
LangExpr *pop = LangExpr::cons( LangTerm::cons( InputLoc(), popRef, popArgs ) );
/* Construct a literal string 'r', for second arg to open. */
@@ -758,7 +758,7 @@ void ConsInit::parseInput( StmtList *stmtList )
/* Call open. */
QualItemVect *openQual = new QualItemVect;
LangVarRef *openRef = LangVarRef::cons( internal,
- pd->curLocalFrame->rootScope, openQual, String("open") );
+ 0, pd->curLocalFrame->rootScope, openQual, String("open") );
CallArgVect *openArgs = new CallArgVect;
openArgs->append( new CallArg(pop) );
openArgs->append( new CallArg(modeExpr) );
@@ -780,7 +780,7 @@ void ConsInit::parseInput( StmtList *stmtList )
void ConsInit::exportTree( StmtList *stmtList )
{
QualItemVect *qual = new QualItemVect;
- LangVarRef *varRef = LangVarRef::cons( internal, pd->curLocalFrame->rootScope, qual, String("P") );
+ LangVarRef *varRef = LangVarRef::cons( internal, 0, pd->curLocalFrame->rootScope, qual, String("P") );
LangExpr *expr = LangExpr::cons( LangTerm::cons( internal, LangTerm::VarRefType, varRef ) );
NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() );
diff --git a/src/loadcolm.cc b/src/loadcolm.cc
index d6877587..85eed886 100644
--- a/src/loadcolm.cc
+++ b/src/loadcolm.cc
@@ -423,11 +423,13 @@ 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(),
- pd->curLocalFrame->curScope, id );
+ context, pd->curLocalFrame->curScope, id );
}
return varRef;
}
@@ -1145,11 +1147,13 @@ 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(),
- pd->curLocalFrame->curScope, qualItemVect, id );
+ context, pd->curLocalFrame->curScope, qualItemVect, id );
return langVarRef;
}
@@ -1792,6 +1796,8 @@ struct LoadColm
LangIterCall *walkIterCall( iter_call IterCall )
{
+ Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
+
LangIterCall *iterCall = 0;
switch ( IterCall.prodName() ) {
case iter_call::_Call: {
@@ -1804,7 +1810,7 @@ struct LoadColm
case iter_call::_Id: {
String tree = IterCall.id().data();
LangVarRef *varRef = LangVarRef::cons( IterCall.id().loc(),
- pd->curLocalFrame->curScope, tree );
+ context, pd->curLocalFrame->curScope, tree );
LangTerm *langTerm = LangTerm::cons( IterCall.id().loc(),
LangTerm::VarRefType, varRef );
LangExpr *langExpr = LangExpr::cons( langTerm );
diff --git a/src/loadinit.cc b/src/loadinit.cc
index be6ce6db..aed5072d 100644
--- a/src/loadinit.cc
+++ b/src/loadinit.cc
@@ -285,7 +285,7 @@ void LoadInit::consParseStmt( StmtList *stmtList )
QualItemVect *popQual = new QualItemVect;
popQual->append( QualItem( QualItem::Dot, internal, String( "argv" ) ) );
- LangVarRef *popRef = LangVarRef::cons( internal, pd->curLocalFrame->rootScope, popQual, String("pop") );
+ LangVarRef *popRef = LangVarRef::cons( internal, 0, pd->curLocalFrame->rootScope, popQual, String("pop") );
LangExpr *pop = LangExpr::cons( LangTerm::cons( InputLoc(), popRef, popArgs ) );
/* Construct a literal string 'r', for second arg to open. */
@@ -297,7 +297,7 @@ void LoadInit::consParseStmt( StmtList *stmtList )
/* Call open. */
QualItemVect *openQual = new QualItemVect;
LangVarRef *openRef = LangVarRef::cons( internal,
- pd->curLocalFrame->rootScope, openQual, String("open") );
+ 0, pd->curLocalFrame->rootScope, openQual, String("open") );
CallArgVect *openArgs = new CallArgVect;
openArgs->append( new CallArg(pop) );
openArgs->append( new CallArg(modeExpr) );
@@ -319,7 +319,7 @@ void LoadInit::consParseStmt( StmtList *stmtList )
void LoadInit::consExportTree( StmtList *stmtList )
{
QualItemVect *qual = new QualItemVect;
- LangVarRef *varRef = LangVarRef::cons( internal, pd->curLocalFrame->rootScope, qual, String("P") );
+ LangVarRef *varRef = LangVarRef::cons( internal, 0, pd->curLocalFrame->rootScope, qual, String("P") );
LangExpr *expr = LangExpr::cons( LangTerm::cons( internal, LangTerm::VarRefType, varRef ) );
NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() );
@@ -332,7 +332,7 @@ void LoadInit::consExportTree( StmtList *stmtList )
void LoadInit::consExportError( StmtList *stmtList )
{
QualItemVect *qual = new QualItemVect;
- LangVarRef *varRef = LangVarRef::cons( internal, pd->curLocalFrame->rootScope, qual, String("error") );
+ LangVarRef *varRef = LangVarRef::cons( internal, 0, pd->curLocalFrame->rootScope, qual, String("error") );
LangExpr *expr = LangExpr::cons( LangTerm::cons( internal, LangTerm::VarRefType, varRef ) );
NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() );
diff --git a/src/lookup.cc b/src/lookup.cc
index 3b8986bc..57ab56c3 100644
--- a/src/lookup.cc
+++ b/src/lookup.cc
@@ -129,14 +129,14 @@ bool LangVarRef::isLocalRef( Compiler *pd ) const
bool LangVarRef::isContextRef( Compiler *pd ) const
{
- if ( pd->context != 0 ) {
+ if ( context != 0 ) {
if ( qual->length() > 0 ) {
- if ( pd->context->contextObjDef->rootScope->findField( qual->data[0].data ) != 0 )
+ if ( context->contextObjDef->rootScope->findField( qual->data[0].data ) != 0 )
return true;
}
- else if ( pd->context->contextObjDef->rootScope->findField( name ) != 0 )
+ else if ( context->contextObjDef->rootScope->findField( name ) != 0 )
return true;
- else if ( pd->context->contextObjDef->findMethod( name ) != 0 )
+ else if ( context->contextObjDef->findMethod( name ) != 0 )
return true;
}
@@ -172,7 +172,7 @@ VarRefLookup LangVarRef::lookupObj( Compiler *pd ) const
if ( isLocalRef( pd ) )
rootScope = scope;
else if ( isContextRef( pd ) )
- rootScope = pd->context->contextObjDef->rootScope;
+ rootScope = context->contextObjDef->rootScope;
else
rootScope = pd->globalObjectDef->rootScope;
diff --git a/src/parsedata.h b/src/parsedata.h
index d1d07ec9..c527fef5 100644
--- a/src/parsedata.h
+++ b/src/parsedata.h
@@ -971,8 +971,6 @@ struct Compiler
TypeRef *argvTypeRef;
- Context *context;
-
bool inContiguous;
int contiguousOffset;
int contiguousStretch;
diff --git a/src/parser.cc b/src/parser.cc
index 121aa3cb..6662f853 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -376,11 +376,12 @@ LangStmt *BaseParser::globalDef( ObjectField *objField, LangExpr *expr,
{
LangStmt *stmt = 0;
- ObjectDef *object;
+ Context *context = 0;
+ ObjectDef *object = 0;
if ( contextStack.length() == 0 )
object = pd->globalObjectDef;
else {
- Context *context = contextStack.top();
+ context = contextStack.top();
objField->context = context;
object = context->contextObjDef;
}
@@ -392,7 +393,7 @@ LangStmt *BaseParser::globalDef( ObjectField *objField, LangExpr *expr,
if ( expr != 0 ) {
LangVarRef *varRef = LangVarRef::cons( objField->loc,
- pd->curLocalFrame->curScope, objField->name );
+ context, pd->curLocalFrame->curScope, objField->name );
stmt = LangStmt::cons( objField->loc,
assignType, varRef, expr );
@@ -556,6 +557,7 @@ 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. */
@@ -569,7 +571,7 @@ LangExpr *BaseParser::parseCmd( const InputLoc &loc, bool stop, ObjectField *obj
LangVarRef *varRef = 0;
if ( objField != 0 ) {
varRef = LangVarRef::cons( objField->loc,
- pd->curLocalFrame->curScope, objField->name );
+ context, pd->curLocalFrame->curScope, objField->name );
}
/* The typeref for the parser. */
@@ -667,6 +669,8 @@ ConsItemList *BaseParser::consListConcat( ConsItemList *list1,
LangStmt *BaseParser::forScope( const InputLoc &loc, const String &data,
ObjNameScope *scope, TypeRef *typeRef, LangIterCall *iterCall, StmtList *stmtList )
{
+ Context *context = contextStack.length() == 0 ? 0 : contextStack.top();
+
/* Check for redeclaration. */
if ( pd->curLocalFrame->checkRedecl( data ) != 0 )
error( loc ) << "variable " << data << " redeclared" << endp;
@@ -678,7 +682,7 @@ LangStmt *BaseParser::forScope( const InputLoc &loc, const String &data,
pd->curLocalFrame->insertField( data, iterField );
LangStmt *stmt = LangStmt::cons( loc, LangStmt::ForIterType,
- iterField, typeRef, iterCall, stmtList, scope );
+ iterField, typeRef, iterCall, stmtList, context, scope );
return stmt;
}
@@ -761,6 +765,8 @@ 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++ );
pd->replList.append( constructor );
@@ -768,7 +774,7 @@ LangExpr *BaseParser::construct( const InputLoc &loc, ObjectField *objField,
LangVarRef *varRef = 0;
if ( objField != 0 ) {
varRef = LangVarRef::cons( objField->loc,
- pd->curLocalFrame->curScope, objField->name );
+ context, pd->curLocalFrame->curScope, objField->name );
}
LangExpr *expr = LangExpr::cons( LangTerm::cons( loc, LangTerm::ConstructType,
@@ -808,6 +814,7 @@ 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 ( pd->curLocalFrame->checkRedecl( objField->name ) != 0 ) {
@@ -822,7 +829,7 @@ LangStmt *BaseParser::varDef( ObjectField *objField,
if ( expr != 0 ) {
LangVarRef *varRef = LangVarRef::cons( objField->loc,
- pd->curLocalFrame->curScope, objField->name );
+ context, pd->curLocalFrame->curScope, objField->name );
stmt = LangStmt::cons( objField->loc, assignType, varRef, expr );
}
@@ -847,7 +854,7 @@ LangStmt *BaseParser::exportStmt( ObjectField *objField, LangStmt::Type assignTy
if ( expr != 0 ) {
LangVarRef *varRef = LangVarRef::cons( objField->loc,
- pd->curLocalFrame->curScope, objField->name );
+ 0, pd->curLocalFrame->curScope, objField->name );
stmt = LangStmt::cons( objField->loc, assignType, varRef, expr );
}
diff --git a/src/parsetree.h b/src/parsetree.h
index 0ec77e28..b8666b4b 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -2502,24 +2502,20 @@ typedef Vector<QualItem> QualItemVect;
struct LangVarRef
{
- LangVarRef()
- :
- qual(0)
- {}
-
- static LangVarRef *cons( const InputLoc &loc, ObjNameScope *scope, QualItemVect *qual, const String &name )
+ static LangVarRef *cons( const InputLoc &loc, Context *context, ObjNameScope *scope, QualItemVect *qual, const String &name )
{
LangVarRef *l = new LangVarRef;
l->loc = loc;
+ l->context = context;
l->scope = scope;
l->qual = qual;
l->name = name;
return l;
}
- static LangVarRef *cons( const InputLoc &loc, ObjNameScope *scope, const String &name )
+ static LangVarRef *cons( const InputLoc &loc, Context *context, ObjNameScope *scope, const String &name )
{
- return cons( loc, scope, new QualItemVect, name );
+ return cons( loc, context, scope, new QualItemVect, name );
}
void resolve( Compiler *pd ) const;
@@ -2572,6 +2568,7 @@ struct LangVarRef
VarRefLookup &lookup, CallArgVect *args ) const;
InputLoc loc;
+ Context *context;
ObjNameScope *scope;
QualItemVect *qual;
String name;
@@ -2926,6 +2923,7 @@ struct LangStmt
stmtList(0),
elsePart(0),
iterCall(0),
+ context(0),
scope(0),
/* Normally you don't need to initialize double list pointers, however,
@@ -3047,7 +3045,8 @@ struct LangStmt
}
static LangStmt *cons( const InputLoc &loc, Type type, ObjectField *objField,
- TypeRef *typeRef, LangIterCall *iterCall, StmtList *stmtList, ObjNameScope *scope )
+ TypeRef *typeRef, LangIterCall *iterCall, StmtList *stmtList,
+ Context *context, ObjNameScope *scope )
{
LangStmt *s = new LangStmt;
s->loc = loc;
@@ -3056,6 +3055,7 @@ struct LangStmt
s->typeRef = typeRef;
s->iterCall = iterCall;
s->stmtList = stmtList;
+ s->context = context;
s->scope = scope;
return s;
}
@@ -3093,6 +3093,7 @@ struct LangStmt
LangStmt *elsePart;
String name;
LangIterCall *iterCall;
+ Context *context;
ObjNameScope *scope;
/* Normally you don't need to initialize double list pointers, however, we
diff --git a/src/resolve.cc b/src/resolve.cc
index 2dd1ac29..7b46b470 100644
--- a/src/resolve.cc
+++ b/src/resolve.cc
@@ -597,15 +597,9 @@ void Compiler::resolveReductionCode( Production *prod )
void Compiler::resolveParseTree()
{
/* Compile functions. */
- for ( FunctionList::Iter f = functionList; f.lte(); f++ ) {
- if ( f->inContext != 0 )
- context = f->inContext;
-
+ for ( FunctionList::Iter f = functionList; f.lte(); f++ )
resolveFunction( f );
- context = 0;
- }
-
/* Compile the reduction code. */
for ( DefList::Iter prod = prodList; prod.lte(); prod++ ) {
if ( prod->redBlock != 0 )
diff --git a/src/synthesis.cc b/src/synthesis.cc
index 84b24c26..1a06cfe6 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -472,7 +472,7 @@ void LangVarRef::loadContextObj( Compiler *pd, CodeVect &code,
int lastPtrInQual, bool forWriting ) const
{
/* Start the search in the global object. */
- ObjectDef *rootObj = pd->context->contextObjDef;
+ ObjectDef *rootObj = context->contextObjDef;
if ( forWriting && lastPtrInQual < 0 ) {
/* If we are writing an no reference was found in the qualification
@@ -1981,7 +1981,7 @@ void LangStmt::compileForIterBody( Compiler *pd,
void LangStmt::chooseDefaultIter( Compiler *pd, LangIterCall *iterCall ) const
{
/* The iterator name. */
- LangVarRef *callVarRef = LangVarRef::cons( loc, scope, "triter" );
+ LangVarRef *callVarRef = LangVarRef::cons( loc, context, scope, "triter" );
/* The parameters. */
CallArgVect *callExprVect = new CallArgVect;
@@ -3303,44 +3303,29 @@ void Compiler::compileByteCode()
/* Compile functions. */
for ( FunctionList::Iter f = functionList; f.lte(); f++ ) {
- if ( f->inContext != 0 )
- context = f->inContext;
if ( f->isUserIter )
compileUserIter( f );
else
compileFunction( f );
- context = 0;
}
/* Compile the reduction code. */
for ( DefList::Iter prod = prodList; prod.lte(); prod++ ) {
makeProdCopies( prod );
- if ( prod->redBlock != 0 ) {
- if ( prod->redBlock->context != 0 )
- context = prod->redBlock->context;
+ if ( prod->redBlock != 0 )
compileReductionCode( prod );
- context = 0;
- }
}
/* Compile the token translation code. */
for ( LelList::Iter lel = langEls; lel.lte(); lel++ ) {
- if ( lel->transBlock != 0 ) {
- if ( lel->transBlock->context != 0 )
- context = lel->transBlock->context;
+ if ( lel->transBlock != 0 )
compileTranslateBlock( lel );
- context = 0;
- }
}
/* Compile preeof blocks. */
for ( RegionList::Iter r = regionList; r.lte(); r++ ) {
- if ( r->preEofBlock != 0 ) {
- if ( r->preEofBlock->context != 0 )
- context = r->preEofBlock->context;
+ if ( r->preEofBlock != 0 )
compilePreEof( r );
- context = 0;
- }
}
/* Compile the init code */