diff options
author | David Robillard <d@drobilla.net> | 2010-12-04 23:12:06 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-04 23:12:06 +0000 |
commit | 1f488a7bd89d4cef07bd41ab22a290b0e230172d (patch) | |
tree | b96a87f0b35167ffd3c62f6da3f7da872ee8d7f6 /src/lift.cpp | |
parent | 8ee352054cff3512c8e6dc3fd4738ee24ad267af (diff) | |
download | resp-1f488a7bd89d4cef07bd41ab22a290b0e230172d.tar.gz resp-1f488a7bd89d4cef07bd41ab22a290b0e230172d.tar.bz2 resp-1f488a7bd89d4cef07bd41ab22a290b0e230172d.zip |
More const-correctness (remove all use of const_cast from lift.cpp).
git-svn-id: http://svn.drobilla.net/resp/resp@296 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/lift.cpp')
-rw-r--r-- | src/lift.cpp | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src/lift.cpp b/src/lift.cpp index 5b3f871..10c4707 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -27,7 +27,7 @@ using namespace std; -static AST* +static const AST* lift_symbol(CEnv& cenv, Code& code, const ASymbol* sym) throw() { const std::string& cppstr = sym->cppstr; @@ -45,15 +45,15 @@ lift_symbol(CEnv& cenv, Code& code, const ASymbol* sym) throw() new ALiteral<int32_t>(T_INT32, index, Cursor()), NULL); } else { - return const_cast<ASymbol*>(sym); + return sym; } } -static AST* +static const AST* lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() { - List<ATuple,AST> impl; - impl.push_back(const_cast<AST*>(fn->head())); + List<ATuple, const AST> impl; + impl.push_back(fn->head()); const string fnName = cenv.name(fn); const string nameBase = cenv.penv.gensymstr(((fnName != "") ? fnName : "fn").c_str()); @@ -68,21 +68,19 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() AType::const_iterator tp = type->prot()->begin(); List<AType,AType> implProtT; - List<ATuple,AST> implProt; + List<ATuple, const AST> implProt; // Prepend closure parameter - implProt.push_back(const_cast<ASymbol*>(cenv.penv.sym("_me"))); + implProt.push_back(cenv.penv.sym("_me")); for (ATuple::const_iterator p = fn->prot()->begin(); p != fn->prot()->end(); ++p) { const AType* paramType = (*tp++)->as_type(); if (paramType->kind == AType::EXPR && *paramType->head() == *cenv.tenv.Fn) { - AType* fnType = new AType(const_cast<AType*>(cenv.tenv.var()), - const_cast<AType*>(paramType), - fnType->loc); + const AType* fnType = new AType(cenv.tenv.var(), paramType, fnType->loc); paramType = tup<const AType>((*p)->loc, cenv.tenv.Tup, fnType, NULL); } cenv.def((*p)->as_symbol(), *p, paramType, NULL); - implProt.push_back(const_cast<AST*>(*p)); + implProt.push_back(*p); implProtT.push_back(new AType(*paramType)); } @@ -92,7 +90,7 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() const AType* implRetT = NULL; for (ATuple::const_iterator i = fn->iter_at(2); i != fn->end(); ++i) { const AST* lifted = resp_lift(cenv, code, *i); - impl.push_back(const_cast<AST*>(lifted)); + impl.push_back(lifted); implRetT = cenv.type(lifted); } @@ -106,21 +104,21 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() TList implT; // Type of the implementation function TList tupT(fn->loc, cenv.tenv.Tup, cenv.tenv.var(), NULL); TList consT; - List<ATuple, AST> cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); + List<ATuple, const AST> cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); const CEnv::FreeVars& freeVars = cenv.liftStack.top(); for (CEnv::FreeVars::const_iterator i = freeVars.begin(); i != freeVars.end(); ++i) { - cons.push_back(const_cast<ASymbol*>(*i)); - tupT.push_back(const_cast<AType*>(cenv.type(*i))); - consT.push_back(const_cast<AType*>(cenv.type(*i))); + cons.push_back(*i); + tupT.push_back(cenv.type(*i)); + consT.push_back(cenv.type(*i)); } cenv.liftStack.pop(); implProtT.push_front(tupT); - implT.push_back(const_cast<AType*>((AType*)type->head())); - implT.push_back(const_cast<AType*>(implProtT.head)); - implT.push_back(const_cast<AType*>(implRetT)); + implT.push_back((AType*)type->head()); + implT.push_back(implProtT.head); + implT.push_back(implRetT); consT.push_front(implT.head); consT.push_front(cenv.tenv.Tup); @@ -135,14 +133,14 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() return cons; } -static AST* +static const AST* lift_call(CEnv& cenv, Code& code, const ATuple* call) throw() { - List<ATuple, AST> copy; + List<ATuple, const AST> copy; // Lift all children (callee and arguments, recursively) for (ATuple::const_iterator i = call->begin(); i != call->end(); ++i) - copy.push_back(const_cast<AST*>(resp_lift(cenv, code, *i))); + copy.push_back(resp_lift(cenv, code, *i)); copy.head->loc = call->loc; @@ -162,9 +160,9 @@ lift_call(CEnv& cenv, Code& code, const ATuple* call) throw() * closure as the first parameter: * (_impl (Fn _impl ...) ...) */ - const ATuple* closure = copy.head->list_ref(0)->as_tuple(); - ASymbol* implSym = const_cast<ASymbol*>(closure->list_ref(1)->as_symbol()); - const AType* implT = cenv.type(cenv.resolve(implSym)); + const ATuple* closure = copy.head->list_ref(0)->as_tuple(); + const ASymbol* implSym = closure->list_ref(1)->as_symbol(); + const AType* implT = cenv.type(cenv.resolve(implSym)); copy.push_front(implSym); copyT = implT->list_ref(2)->as_type(); } else { @@ -184,7 +182,7 @@ lift_call(CEnv& cenv, Code& code, const ATuple* call) throw() return copy; } -static AST* +static const AST* lift_def(CEnv& cenv, Code& code, const ATuple* def) throw() { // Define stub first for recursion @@ -195,14 +193,13 @@ lift_def(CEnv& cenv, Code& code, const ATuple* def) throw() cenv.setName(body->as_tuple(), sym->str()); assert(def->list_ref(1)->to_symbol()); - List<ATuple, AST> copy; - copy.push_back(const_cast<AST*>(def->head())); - copy.push_back(const_cast<AST*>(resp_lift(cenv, code, def->list_ref(1)))); + List<ATuple, const AST> copy; + copy.push_back(def->head()); + copy.push_back(resp_lift(cenv, code, def->list_ref(1))); for (ATuple::const_iterator t = def->iter_at(2); t != def->end(); ++t) - copy.push_back(const_cast<AST*>(resp_lift(cenv, code, *t))); + copy.push_back(resp_lift(cenv, code, *t)); - cenv.setTypeSameAs(const_cast<AST*>(static_cast<const AST*>(copy.head)), - const_cast<AST*>(static_cast<const AST*>(def))); + cenv.setTypeSameAs(copy.head, def); if (copy.head->list_ref(1) == copy.head->list_ref(2)) return NULL; // Definition created by lift_fn when body was lifted @@ -214,18 +211,17 @@ lift_def(CEnv& cenv, Code& code, const ATuple* def) throw() return copy; } -static AST* +static const AST* lift_builtin_call(CEnv& cenv, Code& code, const ATuple* call) throw() { - List<ATuple,AST> copy; - copy.push_back(const_cast<AST*>(call->head())); + List<ATuple, const AST> copy; + copy.push_back(call->head()); // Lift all arguments for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) - copy.push_back(const_cast<AST*>(resp_lift(cenv, code, *i))); + copy.push_back(resp_lift(cenv, code, *i)); - cenv.setTypeSameAs(const_cast<AST*>(static_cast<const AST*>(copy.head)), - const_cast<AST*>(static_cast<const AST*>(call))); + cenv.setTypeSameAs(copy.head, call); return copy; } |