diff options
author | Adrian Thurston <thurston@complang.org> | 2014-01-05 10:41:33 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2014-01-05 10:41:33 -0500 |
commit | fdded46bc52dd2feb5fa1000443f5dc6d3a6908b (patch) | |
tree | 97ab3ea2615fa0d4e56d93a82fb0e32538ea08e2 /src | |
parent | a3add30246bbf7f04a104e7be7b61e81542c84f6 (diff) | |
download | colm-fdded46bc52dd2feb5fa1000443f5dc6d3a6908b.tar.gz |
some code cleanup: Form and constructor arg order
Diffstat (limited to 'src')
-rw-r--r-- | src/ctinput.cc | 8 | ||||
-rw-r--r-- | src/declare.cc | 6 | ||||
-rw-r--r-- | src/loadcolm.cc | 50 | ||||
-rw-r--r-- | src/parser.cc | 10 | ||||
-rw-r--r-- | src/parser.h | 2 | ||||
-rw-r--r-- | src/parsetree.h | 46 | ||||
-rw-r--r-- | src/resolve.cc | 14 |
7 files changed, 69 insertions, 67 deletions
diff --git a/src/ctinput.cc b/src/ctinput.cc index eccd4e03..c8005ff1 100644 --- a/src/ctinput.cc +++ b/src/ctinput.cc @@ -70,10 +70,10 @@ int inputStreamPatternGetParseBlock( StreamImpl *ss, int skip, char **pdp, int * if ( buf == 0 ) return INPUT_EOD; - if ( buf->form == PatternItem::TypeRef ) + if ( buf->form == PatternItem::TypeRefForm ) return INPUT_LANG_EL; - assert ( buf->form == PatternItem::InputText ); + assert ( buf->form == PatternItem::InputTextForm ); int avail = buf->data.length() - offset; if ( avail > 0 ) { @@ -117,10 +117,10 @@ int inputStreamPatternGetData( StreamImpl *ss, char *dest, int length ) if ( buf == 0 ) break; - if ( buf->form == PatternItem::TypeRef ) + if ( buf->form == PatternItem::TypeRefForm ) break; - assert ( buf->form == PatternItem::InputText ); + assert ( buf->form == PatternItem::InputTextForm ); int avail = buf->data.length() - offset; if ( avail > 0 ) { diff --git a/src/declare.cc b/src/declare.cc index dd3147d2..93e250b2 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -511,7 +511,7 @@ void Compiler::makeIgnoreCollectors() } } -void LangStmt::chooseDefaultIter( Compiler *pd, LangIterCall *iterCall ) const +void LangStmt::chooseDefaultIter( Compiler *pd, IterCall *iterCall ) const { /* The iterator name. */ LangVarRef *callVarRef = LangVarRef::cons( loc, context, scope, "triter" ); @@ -521,13 +521,13 @@ void LangStmt::chooseDefaultIter( Compiler *pd, LangIterCall *iterCall ) const callExprVect->append( new CallArg( iterCall->langExpr ) ); iterCall->langTerm = LangTerm::cons( InputLoc(), callVarRef, callExprVect ); iterCall->langExpr = 0; - iterCall->type = LangIterCall::IterCall; + iterCall->form = IterCall::IterCallForm; } void LangStmt::declareForIter( Compiler *pd ) const { - if ( iterCall->type != LangIterCall::IterCall ) + if ( iterCall->form != IterCall::IterCallForm ) chooseDefaultIter( pd, iterCall ); objField->typeRef = TypeRef::cons( loc, typeRef, iterCall ); diff --git a/src/loadcolm.cc b/src/loadcolm.cc index 85eed886..320de4f0 100644 --- a/src/loadcolm.cc +++ b/src/loadcolm.cc @@ -225,7 +225,7 @@ struct LoadColm TypeRef *typeRef = walkTypeRef( Statement.type_ref() ); StmtList *stmtList = walkBlockOrSingle( Statement.block_or_single() ); - LangIterCall *iterCall = walkIterCall( Statement.iter_call() ); + IterCall *iterCall = walkIterCall( Statement.iter_call() ); stmt = forScope( Statement.id().loc(), forDecl, pd->curLocalFrame->curScope, typeRef, iterCall, stmtList ); @@ -439,19 +439,21 @@ struct LoadColm PatternItemList *list = 0; switch ( patternEl.prodName() ) { case pattern_el::_Dq: { - list = walkLitpatElList( patternEl.LitpatElList(), patternEl.dq_lit_term().CONS_NL(), patternVarRef ); + list = walkLitpatElList( patternEl.LitpatElList(), + patternEl.dq_lit_term().CONS_NL(), patternVarRef ); break; } case pattern_el::_Tilde: { String patternData = patternEl.opt_tilde_data().text().c_str(); patternData += '\n'; - PatternItem *patternItem = PatternItem::cons( patternEl.opt_tilde_data().loc(), - patternData, PatternItem::InputText ); + PatternItem *patternItem = PatternItem::cons( PatternItem::InputTextForm, + patternEl.opt_tilde_data().loc(), patternData ); list = PatternItemList::cons( patternItem ); break; } case pattern_el::_PatternEl: { - PatternItemList *typeOrLitList = walkPatternElTypeOrLit( patternEl.pattern_el_lel(), patternVarRef ); + PatternItemList *typeOrLitList = walkPatternElTypeOrLit( + patternEl.pattern_el_lel(), patternVarRef ); LangVarRef *varRef = walkOptLabel( patternEl.opt_label() ); list = consPatternEl( varRef, typeOrLitList ); break; @@ -465,8 +467,8 @@ struct LoadColm switch ( litpatEl.prodName() ) { case litpat_el::_ConsData: { String consData = unescape( litpatEl.cons_data().text().c_str() ); - PatternItem *patternItem = PatternItem::cons( litpatEl.cons_data().loc(), - consData, PatternItem::InputText ); + PatternItem *patternItem = PatternItem::cons( PatternItem::InputTextForm, + litpatEl.cons_data().loc(), consData ); list = PatternItemList::cons( patternItem ); break; } @@ -488,7 +490,8 @@ struct LoadColm if ( Nl != 0 ) { String nl = unescape( Nl.data() ); - PatternItem *patternItem = PatternItem::cons( Nl.loc(), nl, PatternItem::InputText ); + PatternItem *patternItem = PatternItem::cons( PatternItem::InputTextForm, + Nl.loc(), nl ); PatternItemList *term = PatternItemList::cons( patternItem ); list = patListConcat( list, term ); } @@ -512,14 +515,15 @@ struct LoadColm PatternItemList *list = 0; switch ( patternTopEl.prodName() ) { case pattern_top_el::_Dq: { - list = walkLitpatElList( patternTopEl.LitpatElList(), patternTopEl.dq_lit_term().CONS_NL(), patternVarRef ); + list = walkLitpatElList( patternTopEl.LitpatElList(), + patternTopEl.dq_lit_term().CONS_NL(), patternVarRef ); break; } case pattern_top_el::_Tilde: { String patternData = patternTopEl.opt_tilde_data().text().c_str(); patternData += '\n'; - PatternItem *patternItem = PatternItem::cons( patternTopEl.opt_tilde_data().loc(), - patternData, PatternItem::InputText ); + PatternItem *patternItem = PatternItem::cons( PatternItem::InputTextForm, + patternTopEl.opt_tilde_data().loc(), patternData ); list = PatternItemList::cons( patternItem ); break; } @@ -1794,32 +1798,32 @@ struct LoadColm return ObjectField::cons( varDef.id().loc(), typeRef, id ); } - LangIterCall *walkIterCall( iter_call IterCall ) + IterCall *walkIterCall( iter_call Tree ) { Context *context = contextStack.length() == 0 ? 0 : contextStack.top(); - LangIterCall *iterCall = 0; - switch ( IterCall.prodName() ) { + IterCall *iterCall = 0; + switch ( Tree.prodName() ) { case iter_call::_Call: { - LangVarRef *varRef = walkVarRef( IterCall.var_ref() ); - CallArgVect *exprVect = walkCodeExprList( IterCall.CodeExprList() ); + LangVarRef *varRef = walkVarRef( Tree.var_ref() ); + CallArgVect *exprVect = walkCodeExprList( Tree.CodeExprList() ); LangTerm *langTerm = LangTerm::cons( varRef->loc, varRef, exprVect ); - iterCall = LangIterCall::cons( LangIterCall::IterCall, langTerm ); + iterCall = IterCall::cons( IterCall::IterCallForm, langTerm ); break; } case iter_call::_Id: { - String tree = IterCall.id().data(); - LangVarRef *varRef = LangVarRef::cons( IterCall.id().loc(), + String tree = Tree.id().data(); + LangVarRef *varRef = LangVarRef::cons( Tree.id().loc(), context, pd->curLocalFrame->curScope, tree ); - LangTerm *langTerm = LangTerm::cons( IterCall.id().loc(), + LangTerm *langTerm = LangTerm::cons( Tree.id().loc(), LangTerm::VarRefType, varRef ); LangExpr *langExpr = LangExpr::cons( langTerm ); - iterCall = LangIterCall::cons( LangIterCall::VarRef, langExpr ); + iterCall = IterCall::cons( IterCall::VarRefForm, langExpr ); break; } case iter_call::_Expr: { - LangExpr *langExpr = walkCodeExpr( IterCall.code_expr() ); - iterCall = LangIterCall::cons( LangIterCall::Expr, langExpr ); + LangExpr *langExpr = walkCodeExpr( Tree.code_expr() ); + iterCall = IterCall::cons( IterCall::ExprForm, langExpr ); break; }} diff --git a/src/parser.cc b/src/parser.cc index c2c6ba4d..e0f81ebc 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 Adrian Thurston <thurston@complang.org> + * Copyright 2006-2014 Adrian Thurston <thurston@complang.org> */ /* This file is part of Colm. @@ -30,8 +30,6 @@ #include "global.h" #include "input.h" -using std::cout; -using std::cerr; using std::endl; void BaseParser::init() @@ -630,7 +628,7 @@ PatternItemList *BaseParser::patternElNamed( const InputLoc &loc, { TypeRef *typeRef = TypeRef::cons( loc, parsedVarRef, nspaceQual, data, repeatType ); ProdEl *prodEl = new ProdEl( ProdEl::ReferenceType, loc, 0, false, typeRef, 0 ); - PatternItem *patternItem = PatternItem::cons( loc, prodEl, PatternItem::TypeRef ); + PatternItem *patternItem = PatternItem::cons( PatternItem::TypeRefForm, loc, prodEl ); return PatternItemList::cons( patternItem ); } @@ -642,7 +640,7 @@ PatternItemList *BaseParser::patternElType( const InputLoc &loc, TypeRef *typeRef = TypeRef::cons( loc, parsedVarRef, nspaceQual, literal, repeatType ); ProdEl *prodEl = new ProdEl( ProdEl::ReferenceType, loc, 0, false, typeRef, 0 ); - PatternItem *patternItem = PatternItem::cons( loc, prodEl, PatternItem::TypeRef ); + PatternItem *patternItem = PatternItem::cons( PatternItem::TypeRefForm, loc, prodEl ); return PatternItemList::cons( patternItem ); } @@ -670,7 +668,7 @@ ConsItemList *BaseParser::consListConcat( ConsItemList *list1, } LangStmt *BaseParser::forScope( const InputLoc &loc, const String &data, - ObjNameScope *scope, TypeRef *typeRef, LangIterCall *iterCall, StmtList *stmtList ) + ObjNameScope *scope, TypeRef *typeRef, IterCall *iterCall, StmtList *stmtList ) { Context *context = contextStack.length() == 0 ? 0 : contextStack.top(); diff --git a/src/parser.h b/src/parser.h index 428c55bd..dbe4bbc9 100644 --- a/src/parser.h +++ b/src/parser.h @@ -97,7 +97,7 @@ struct BaseParser PatternItemList *patListConcat( PatternItemList *list1, PatternItemList *list2 ); ConsItemList *consListConcat( ConsItemList *list1, ConsItemList *list2 ); LangStmt *forScope( const InputLoc &loc, const String &data, - ObjNameScope *scope, TypeRef *typeRef, LangIterCall *iterCall, StmtList *stmtList ); + ObjNameScope *scope, TypeRef *typeRef, IterCall *iterCall, StmtList *stmtList ); void preEof( const InputLoc &loc, StmtList *stmtList, ObjectDef *localFrame ); ProdEl *prodElName( const InputLoc &loc, const String &data, diff --git a/src/parsetree.h b/src/parsetree.h index 14542bb5..f0b6546f 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -64,7 +64,7 @@ struct PdaLiteral; struct TypeAlias; struct RegionSet; struct ObjNameScope; -struct LangIterCall; +struct IterCall; typedef struct _PdaRun PdaRun; /* @@ -1536,11 +1536,11 @@ struct ObjectField; struct PatternItem { enum Form { - TypeRef, - InputText + TypeRefForm, + InputTextForm }; - static PatternItem *cons( const InputLoc &loc, const String &data, Form form ) + static PatternItem *cons( Form form, const InputLoc &loc, const String &data ) { PatternItem *p = new PatternItem; p->form = form; @@ -1553,7 +1553,7 @@ struct PatternItem return p; } - static PatternItem *cons( const InputLoc &loc, ProdEl *prodEl, Form form ) + static PatternItem *cons( Form form, const InputLoc &loc, ProdEl *prodEl ) { PatternItem *p = new PatternItem; p->form = form; @@ -2136,7 +2136,7 @@ struct TypeRef /* Resolution not needed. */ /* Iterator definition. */ - static TypeRef *cons( const InputLoc &loc, TypeRef *typeRef, LangIterCall *iterCall ) + static TypeRef *cons( const InputLoc &loc, TypeRef *typeRef, IterCall *iterCall ) { TypeRef *t = new TypeRef; t->type = Iterator; @@ -2177,7 +2177,7 @@ struct TypeRef NamespaceQual *nspaceQual; String typeName; PdaLiteral *pdaLiteral; - LangIterCall *iterCall; + IterCall *iterCall; IterDef *iterDef; TypeRef *typeRef1; TypeRef *typeRef2; @@ -2881,39 +2881,39 @@ struct LangExpr struct LangStmt; typedef DList<LangStmt> StmtList; -struct LangIterCall +struct IterCall { - enum Type { - VarRef, - IterCall, - Expr + enum Form { + VarRefForm, + IterCallForm, + ExprForm }; - LangIterCall() + IterCall() : langTerm(0), langExpr(0) {} - static LangIterCall *cons( Type type, LangTerm *langTerm ) + static IterCall *cons( Form form, LangTerm *langTerm ) { - LangIterCall *iterCall = new LangIterCall; - iterCall->type = type; + IterCall *iterCall = new IterCall; + iterCall->form = form; iterCall->langTerm = langTerm; return iterCall; } - static LangIterCall *cons( Type type, LangExpr *langExpr ) + static IterCall *cons( Form form, LangExpr *langExpr ) { - LangIterCall *iterCall = new LangIterCall; - iterCall->type = type; + IterCall *iterCall = new IterCall; + iterCall->form = form; iterCall->langExpr = langExpr; return iterCall; } void resolve( Compiler *pd ) const; - Type type; + Form form; LangTerm *langTerm; LangExpr *langExpr; }; @@ -3074,7 +3074,7 @@ struct LangStmt } static LangStmt *cons( const InputLoc &loc, Type type, ObjectField *objField, - TypeRef *typeRef, LangIterCall *iterCall, StmtList *stmtList, + TypeRef *typeRef, IterCall *iterCall, StmtList *stmtList, Context *context, ObjNameScope *scope ) { LangStmt *s = new LangStmt; @@ -3105,7 +3105,7 @@ struct LangStmt void resolve( Compiler *pd ) const; void resolveParserItems( Compiler *pd ) const; - void chooseDefaultIter( Compiler *pd, LangIterCall *iterCall ) const; + void chooseDefaultIter( Compiler *pd, IterCall *iterCall ) const; void compileWhile( Compiler *pd, CodeVect &code ) const; void compileForIterBody( Compiler *pd, CodeVect &code, UniqueType *iterUT ) const; void compileForIter( Compiler *pd, CodeVect &code ) const; @@ -3126,7 +3126,7 @@ struct LangStmt /* Either another if, or an else. */ LangStmt *elsePart; String name; - LangIterCall *iterCall; + IterCall *iterCall; Context *context; ObjNameScope *scope; diff --git a/src/resolve.cc b/src/resolve.cc index 9372a96c..fa74c566 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -404,11 +404,11 @@ void LangTerm::resolve( Compiler *pd ) case MatchType: for ( PatternItemList::Iter item = *pattern->list; item.lte(); item++ ) { switch ( item->form ) { - case PatternItem::TypeRef: + case PatternItem::TypeRefForm: /* Use pdaFactor reference resolving. */ pd->resolveProdEl( item->prodEl ); break; - case PatternItem::InputText: + case PatternItem::InputTextForm: /* Nothing to do here. */ break; } @@ -484,14 +484,14 @@ void LangExpr::resolve( Compiler *pd ) const } } -void LangIterCall::resolve( Compiler *pd ) const +void IterCall::resolve( Compiler *pd ) const { - switch ( type ) { - case IterCall: + switch ( form ) { + case IterCallForm: langTerm->resolve( pd ); break; - case VarRef: - case Expr: + case VarRefForm: + case ExprForm: langExpr->resolve( pd ); break; } |