diff options
author | Adrian Thurston <thurston@complang.org> | 2014-01-06 20:17:58 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2014-01-06 20:17:58 -0500 |
commit | 15eac716323f2f7a786e7fa4c62d0db2c10a1451 (patch) | |
tree | de7d5507ed21f7f885e07c28a153a0e6307d0677 | |
parent | 9fc587e3e0c9cd4a3744e8d01887a8bad096aaa1 (diff) | |
download | colm-15eac716323f2f7a786e7fa4c62d0db2c10a1451.tar.gz |
added wrapper function for current namespace
-rw-r--r-- | src/consinit.cc | 22 | ||||
-rw-r--r-- | src/loadcolm.cc | 6 | ||||
-rw-r--r-- | src/loadinit.cc | 10 | ||||
-rw-r--r-- | src/parser.cc | 35 | ||||
-rw-r--r-- | src/parser.h | 4 |
5 files changed, 36 insertions, 41 deletions
diff --git a/src/consinit.cc b/src/consinit.cc index 1174bbd2..81d06e22 100644 --- a/src/consinit.cc +++ b/src/consinit.cc @@ -334,7 +334,7 @@ void ConsInit::keyword( const String &kw ) ProdEl *ConsInit::prodRefName( const String &name ) { ProdEl *prodEl = prodElName( internal, name, - NamespaceQual::cons(namespaceStack.top()), 0, + NamespaceQual::cons( curNspace() ), 0, RepeatNone, false ); return prodEl; } @@ -343,7 +343,7 @@ ProdEl *ConsInit::prodRefName( const String &capture, const String &name ) { ObjectField *captureField = ObjectField::cons( internal, 0, capture ); ProdEl *prodEl = prodElName( internal, name, - NamespaceQual::cons(namespaceStack.top()), captureField, + NamespaceQual::cons( curNspace() ), captureField, RepeatNone, false ); return prodEl; } @@ -351,7 +351,7 @@ ProdEl *ConsInit::prodRefName( const String &capture, const String &name ) ProdEl *ConsInit::prodRefNameRepeat( const String &name ) { ProdEl *prodEl = prodElName( internal, name, - NamespaceQual::cons(namespaceStack.top()), 0, + NamespaceQual::cons( curNspace() ), 0, RepeatRepeat, false ); return prodEl; } @@ -360,7 +360,7 @@ ProdEl *ConsInit::prodRefNameRepeat( const String &capture, const String &name ) { ObjectField *captureField = ObjectField::cons( internal, 0, capture ); ProdEl *prodEl = prodElName( internal, name, - NamespaceQual::cons(namespaceStack.top()), captureField, + NamespaceQual::cons( curNspace() ), captureField, RepeatRepeat, false ); return prodEl; } @@ -368,7 +368,7 @@ ProdEl *ConsInit::prodRefNameRepeat( const String &capture, const String &name ) ProdEl *ConsInit::prodRefLit( const String &lit ) { ProdEl *prodEl = prodElLiteral( internal, lit, - NamespaceQual::cons(namespaceStack.top()), 0, + NamespaceQual::cons( curNspace() ), 0, RepeatNone, false ); return prodEl; } @@ -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(), curContext(), false ); + NtDef *ntDef = NtDef::cons( name, curNspace(), 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(), curContext(), false ); + NtDef *ntDef = NtDef::cons( name, curNspace(), 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(), curContext(), false ); + NtDef *ntDef = NtDef::cons( name, curNspace(), 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(), curContext(), false ); + NtDef *ntDef = NtDef::cons( name, curNspace(), curContext(), false ); ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ ); cflDef( ntDef, objectDef, defList ); } @@ -737,7 +737,7 @@ void ConsInit::startProd() void ConsInit::parseInput( StmtList *stmtList ) { /* Parse the "start" def. */ - NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() ); + NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() ); TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, String("start"), RepeatNone ); /* Pop argv, this yields the file name . */ @@ -783,7 +783,7 @@ void ConsInit::exportTree( StmtList *stmtList ) LangVarRef *varRef = LangVarRef::cons( internal, 0, curLocalFrame->rootScope, qual, String("P") ); LangExpr *expr = LangExpr::cons( LangTerm::cons( internal, LangTerm::VarRefType, varRef ) ); - NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() ); + NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() ); TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, String("start"), RepeatNone ); ObjectField *program = ObjectField::cons( internal, typeRef, String("ColmTree") ); LangStmt *programExport = exportStmt( program, LangStmt::AssignType, expr ); diff --git a/src/loadcolm.cc b/src/loadcolm.cc index a69983d6..43eaa314 100644 --- a/src/loadcolm.cc +++ b/src/loadcolm.cc @@ -701,7 +701,7 @@ struct LoadColm break; } case region_qual::_Base: { - qual = NamespaceQual::cons( namespaceStack.top() ); + qual = NamespaceQual::cons( curNspace() ); break; }} return qual; @@ -1064,7 +1064,7 @@ struct LoadColm LexExpression *expr = walkLexExpr( LexExpr ); LexJoin *join = LexJoin::cons( expr ); - addRegularDef( rlDef.id().loc(), namespaceStack.top(), id, join ); + addRegularDef( rlDef.id().loc(), curNspace(), id, join ); } void walkLexRegion( region_def regionDef ) @@ -1085,7 +1085,7 @@ struct LoadColm bool reduceFirst = cflDef.opt_reduce_first().REDUCEFIRST() != 0; - NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), + NtDef *ntDef = NtDef::cons( name, curNspace(), curContext(), reduceFirst ); BaseParser::cflDef( ntDef, objectDef, defList ); diff --git a/src/loadinit.cc b/src/loadinit.cc index 1330ac6d..6cc76b03 100644 --- a/src/loadinit.cc +++ b/src/loadinit.cc @@ -68,7 +68,7 @@ void LoadInit::walkProdElList( String defName, ProdElList *list, prod_el_list &p repeatType = RepeatRepeat; ProdEl *prodEl = prodElName( internal, typeName, - NamespaceQual::cons(namespaceStack.top()), + NamespaceQual::cons( curNspace() ), captureField, repeatType, false ); appendProdEl( list, prodEl ); @@ -269,7 +269,7 @@ void LoadInit::walkDefinition( item &define ) LelDefList *defList = new LelDefList; walkProdList( name, defList, ProdList ); - NtDef *ntDef = NtDef::cons( name, namespaceStack.top(), curContext(), false ); + NtDef *ntDef = NtDef::cons( name, curNspace(), curContext(), false ); ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, name, pd->nextObjectId++ ); cflDef( ntDef, objectDef, defList ); } @@ -277,7 +277,7 @@ void LoadInit::walkDefinition( item &define ) void LoadInit::consParseStmt( StmtList *stmtList ) { /* Parse the "start" def. */ - NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() ); + NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() ); TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, String("start"), RepeatNone ); /* Pop argv, this yields the file name . */ @@ -322,7 +322,7 @@ void LoadInit::consExportTree( StmtList *stmtList ) LangVarRef *varRef = LangVarRef::cons( internal, 0, curLocalFrame->rootScope, qual, String("P") ); LangExpr *expr = LangExpr::cons( LangTerm::cons( internal, LangTerm::VarRefType, varRef ) ); - NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() ); + NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() ); TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, String("start"), RepeatNone ); ObjectField *program = ObjectField::cons( internal, typeRef, String("ColmTree") ); LangStmt *programExport = exportStmt( program, LangStmt::AssignType, expr ); @@ -335,7 +335,7 @@ void LoadInit::consExportError( StmtList *stmtList ) LangVarRef *varRef = LangVarRef::cons( internal, 0, curLocalFrame->rootScope, qual, String("error") ); LangExpr *expr = LangExpr::cons( LangTerm::cons( internal, LangTerm::VarRefType, varRef ) ); - NamespaceQual *nspaceQual = NamespaceQual::cons( namespaceStack.top() ); + NamespaceQual *nspaceQual = NamespaceQual::cons( curNspace() ); TypeRef *typeRef = TypeRef::cons( internal, nspaceQual, String("str"), RepeatNone ); ObjectField *program = ObjectField::cons( internal, typeRef, String("ColmError") ); LangStmt *programExport = exportStmt( program, LangStmt::AssignType, expr ); diff --git a/src/parser.cc b/src/parser.cc index f8d627fb..462255d5 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -184,7 +184,7 @@ void BaseParser::defineToken( const InputLoc &loc, String name, LexJoin *join, O if ( name == 0 ) name.setAs( 32, "_ignore_%.4x", pd->nextTokenId ); - Namespace *nspace = namespaceStack.top(); + Namespace *nspace = curNspace(); RegionSet *regionSet = regionStack.top(); TokenDef *tokenDef = TokenDef::cons( name, String(), false, ignore, join, @@ -231,7 +231,7 @@ void BaseParser::defineToken( const InputLoc &loc, String name, LexJoin *join, O if ( join != 0 ) { /* Create a regular language definition so the token can be used to * make other tokens */ - addRegularDef( loc, namespaceStack.top(), name, join ); + addRegularDef( loc, curNspace(), name, join ); } } @@ -247,7 +247,7 @@ void BaseParser::zeroDef( const InputLoc &loc, const String &data, String interp("");; /* Look for the production's associated region. */ - Namespace *nspace = namespaceStack.top(); + Namespace *nspace = curNspace(); RegionSet *regionSet = regionStack.top(); LiteralDictEl *ldel = nspace->literalDict.find( interp ); @@ -289,7 +289,7 @@ void BaseParser::literalDef( const InputLoc &loc, const String &data, prepareLitString( interp, unusedCI, data, loc ); /* Look for the production's associated region. */ - Namespace *nspace = namespaceStack.top(); + Namespace *nspace = curNspace(); RegionSet *regionSet = regionStack.top(); LiteralDictEl *ldel = nspace->literalDict.find( interp ); @@ -408,7 +408,7 @@ LangStmt *BaseParser::globalDef( ObjectField *objField, LangExpr *expr, void BaseParser::cflDef( NtDef *ntDef, ObjectDef *objectDef, LelDefList *defList ) { - Namespace *nspace = namespaceStack.top(); + Namespace *nspace = curNspace(); ntDef->objectDef = objectDef; ntDef->defList = defList; @@ -467,7 +467,7 @@ LexFactor *BaseParser::lexRlFactorName( const String &data, const InputLoc &loc { LexFactor *factor = 0; /* Find the named graph. */ - Namespace *nspace = namespaceStack.top(); + Namespace *nspace = curNspace(); while ( nspace != 0 ) { GraphDictEl *gdNode = nspace->rlMap.find( data ); @@ -547,8 +547,7 @@ LexJoin *BaseParser::lexOptJoin( LexJoin *join, LexJoin *context ) LangExpr *BaseParser::send( const InputLoc &loc, LangVarRef *varRef, ConsItemList *list, bool eof ) { - Namespace *nspace = namespaceStack.top(); - ParserText *parserText = ParserText::cons( loc, nspace, list ); + ParserText *parserText = ParserText::cons( loc, curNspace(), list ); pd->parserTextList.append( parserText ); return LangExpr::cons( LangTerm::consSend( loc, varRef, @@ -560,13 +559,11 @@ LangExpr *BaseParser::parseCmd( const InputLoc &loc, bool stop, ObjectField *obj { LangExpr *expr = 0; - Namespace *nspace = namespaceStack.top(); - /* We are constructing a parser, sending it items, then returning it. * Thisis the constructor for the parser. */ ConsItemList *emptyConsItemList = new ConsItemList; - Constructor *constructor = Constructor::cons( loc, nspace, + Constructor *constructor = Constructor::cons( loc, curNspace(), emptyConsItemList, pd->nextPatConsId++ ); pd->replList.append( constructor ); @@ -581,7 +578,7 @@ LangExpr *BaseParser::parseCmd( const InputLoc &loc, bool stop, ObjectField *obj TypeRef *parserTypeRef = TypeRef::cons( loc, TypeRef::Parser, 0, typeRef, 0 ); - ParserText *parserText = ParserText::cons( loc, nspace, list ); + ParserText *parserText = ParserText::cons( loc, curNspace(), list ); pd->parserTextList.append( parserText ); expr = LangExpr::cons( LangTerm::cons( loc, @@ -765,9 +762,7 @@ LelDefList *BaseParser::prodAppend( LelDefList *defList, Production *definition LangExpr *BaseParser::construct( const InputLoc &loc, ObjectField *objField, ConsItemList *list, TypeRef *typeRef, FieldInitVect *fieldInitVect ) { - Namespace *nspace = namespaceStack.top(); - - Constructor *constructor = Constructor::cons( loc, nspace, + Constructor *constructor = Constructor::cons( loc, curNspace(), list, pd->nextPatConsId++ ); pd->replList.append( constructor ); @@ -798,9 +793,7 @@ LangExpr *BaseParser::construct( const InputLoc &loc, ObjectField *objField, LangExpr *BaseParser::match( const InputLoc &loc, LangVarRef *varRef, PatternItemList *list ) { - Namespace *nspace = namespaceStack.top(); - - Pattern *pattern = Pattern::cons( loc, nspace, + Pattern *pattern = Pattern::cons( loc, curNspace(), list, pd->nextPatConsId++ ); pd->patternList.append( pattern ); @@ -864,9 +857,7 @@ LangStmt *BaseParser::exportStmt( ObjectField *objField, LangStmt::Type assignTy LangExpr *BaseParser::require( const InputLoc &loc, LangVarRef *varRef, PatternItemList *list ) { - Namespace *nspace = namespaceStack.top(); - - Pattern *pattern = Pattern::cons( loc, nspace, + Pattern *pattern = Pattern::cons( loc, curNspace(), list, pd->nextPatConsId++ ); pd->patternList.append( pattern ); @@ -946,7 +937,7 @@ PredDecl *BaseParser::predTokenLit( const InputLoc &loc, const String &data, void BaseParser::alias( const InputLoc &loc, const String &data, TypeRef *typeRef ) { - Namespace *nspace = namespaceStack.top(); + Namespace *nspace = curNspace(); TypeAlias *typeAlias = new TypeAlias( loc, nspace, data, typeRef ); nspace->typeAliasList.append( typeAlias ); } diff --git a/src/parser.h b/src/parser.h index a3829d55..37af7e7e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -49,9 +49,13 @@ struct BaseParser bool insideRegion() { return regionStack.length() > 0; } + Context *curContext() { return contextStack.length() == 0 ? 0 : contextStack.top(); } + Namespace *curNspace() + { return namespaceStack.top(); } + /* Lexical feedback. */ void init(); |