From 1f488a7bd89d4cef07bd41ab22a290b0e230172d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 4 Dec 2010 23:12:06 +0000 Subject: 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 --- src/lift.cpp | 72 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) (limited to 'src/lift.cpp') 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(T_INT32, index, Cursor()), NULL); } else { - return const_cast(sym); + return sym; } } -static AST* +static const AST* lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() { - List impl; - impl.push_back(const_cast(fn->head())); + List 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 implProtT; - List implProt; + List implProt; // Prepend closure parameter - implProt.push_back(const_cast(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(cenv.tenv.var()), - const_cast(paramType), - fnType->loc); + const AType* fnType = new AType(cenv.tenv.var(), paramType, fnType->loc); paramType = tup((*p)->loc, cenv.tenv.Tup, fnType, NULL); } cenv.def((*p)->as_symbol(), *p, paramType, NULL); - implProt.push_back(const_cast(*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(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 cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); + List 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(*i)); - tupT.push_back(const_cast(cenv.type(*i))); - consT.push_back(const_cast(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*)type->head())); - implT.push_back(const_cast(implProtT.head)); - implT.push_back(const_cast(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 copy; + List copy; // Lift all children (callee and arguments, recursively) for (ATuple::const_iterator i = call->begin(); i != call->end(); ++i) - copy.push_back(const_cast(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(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 copy; - copy.push_back(const_cast(def->head())); - copy.push_back(const_cast(resp_lift(cenv, code, def->list_ref(1)))); + List 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(resp_lift(cenv, code, *t))); + copy.push_back(resp_lift(cenv, code, *t)); - cenv.setTypeSameAs(const_cast(static_cast(copy.head)), - const_cast(static_cast(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 copy; - copy.push_back(const_cast(call->head())); + List 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(resp_lift(cenv, code, *i))); + copy.push_back(resp_lift(cenv, code, *i)); - cenv.setTypeSameAs(const_cast(static_cast(copy.head)), - const_cast(static_cast(call))); + cenv.setTypeSameAs(copy.head, call); return copy; } -- cgit v1.2.1