diff options
author | David Robillard <d@drobilla.net> | 2010-12-04 22:54:17 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-04 22:54:17 +0000 |
commit | 7bbb36a7085576958993cc6c394d5af8455a948d (patch) | |
tree | 1fc50659538100ed8ef6602e7c9e1c52acda051f | |
parent | 6b063941f02808b5e510f8a9c102b3d361de78f3 (diff) | |
download | resp-7bbb36a7085576958993cc6c394d5af8455a948d.tar.gz resp-7bbb36a7085576958993cc6c394d5af8455a948d.tar.bz2 resp-7bbb36a7085576958993cc6c394d5af8455a948d.zip |
Make resp_lift const-correct.
git-svn-id: http://svn.drobilla.net/resp/resp@294 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | src/lift.cpp | 18 | ||||
-rw-r--r-- | src/repl.cpp | 21 | ||||
-rw-r--r-- | src/resp.hpp | 6 |
3 files changed, 24 insertions, 21 deletions
diff --git a/src/lift.cpp b/src/lift.cpp index 979f3c1..e98ddc6 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -91,8 +91,8 @@ lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw() // Lift body const AType* implRetT = NULL; for (ATuple::const_iterator i = fn->iter_at(2); i != fn->end(); ++i) { - AST* lifted = resp_lift(cenv, code, const_cast<AST*>(*i)); - impl.push_back(lifted); + const AST* lifted = resp_lift(cenv, code, *i); + impl.push_back(const_cast<AST*>(lifted)); implRetT = cenv.type(lifted); } @@ -142,7 +142,7 @@ lift_call(CEnv& cenv, Code& code, ATuple* call) throw() // 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, const_cast<AST*>(*i)))); + copy.push_back(const_cast<AST*>(resp_lift(cenv, code, *i))); copy.head->loc = call->loc; @@ -197,9 +197,9 @@ lift_def(CEnv& cenv, Code& code, ATuple* def) throw() assert(def->list_ref(1)->to_symbol()); List<ATuple, AST> copy; copy.push_back(def->head()); - copy.push_back(resp_lift(cenv, code, const_cast<AST*>(def->list_ref(1)))); + copy.push_back(const_cast<AST*>(resp_lift(cenv, code, def->list_ref(1)))); for (ATuple::const_iterator t = def->iter_at(2); t != def->end(); ++t) - copy.push_back(resp_lift(cenv, code, const_cast<AST*>(*t))); + copy.push_back(const_cast<AST*>(resp_lift(cenv, code, *t))); cenv.setTypeSameAs(copy, def); @@ -221,20 +221,20 @@ lift_builtin_call(CEnv& cenv, Code& code, ATuple* call) throw() // Lift all arguments for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) - copy.push_back(resp_lift(cenv, code, const_cast<AST*>(*i))); + copy.push_back(const_cast<AST*>(resp_lift(cenv, code, *i))); cenv.setTypeSameAs(copy, call); return copy; } -AST* -resp_lift(CEnv& cenv, Code& code, AST* ast) throw() +const AST* +resp_lift(CEnv& cenv, Code& code, const AST* ast) throw() { const ASymbol* const sym = ast->to_symbol(); if (sym) return lift_symbol(cenv, code, sym); - ATuple* const call = ast->to_tuple(); + ATuple* const call = const_cast<ATuple*>(ast->to_tuple()); if (call) { const ASymbol* const sym = call->head()->to_symbol(); const std::string form = sym ? sym->cppstr : ""; diff --git a/src/repl.cpp b/src/repl.cpp index 0ec644c..7ef7ff3 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -27,7 +27,7 @@ using namespace std; static bool -readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) +readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, const AST*& ast) { try { exp = readExpression(cursor, is); @@ -65,7 +65,7 @@ readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) } static void -callPrintCollect(CEnv& cenv, CFunc f, AST* result, const AType* resultT, bool execute) +callPrintCollect(CEnv& cenv, CFunc f, const AST* result, const AType* resultT, bool execute) { if (execute) cenv.out << cenv.engine()->call(cenv, f, resultT); @@ -82,14 +82,17 @@ int eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) { AST* exp = NULL; - AST* ast = NULL; - list<AST*> parsed; + const AST* ast = NULL; + + typedef list<const AST*> Parsed; + Parsed parsed; + try { while (readParseType(cenv, cursor, is, exp, ast)) parsed.push_back(ast); if (cenv.args.find("-T") != cenv.args.end()) { - for (list<AST*>::const_iterator i = parsed.begin(); i != parsed.end(); ++i) + for (Parsed::const_iterator i = parsed.begin(); i != parsed.end(); ++i) pprint(cout, *i, &cenv, true); return 0; } @@ -99,10 +102,10 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) // Lift all expressions Code lifted; - for (list<AST*>::iterator i = parsed.begin(); i != parsed.end(); ++i) { - AST* l = resp_lift(cenv, lifted, *i); + for (Parsed::const_iterator i = parsed.begin(); i != parsed.end(); ++i) { + const AST* l = resp_lift(cenv, lifted, *i); if (l) - lifted.push_back(l); + lifted.push_back(const_cast<AST*>(l)); } if (cenv.args.find("-L") != cenv.args.end()) { @@ -158,7 +161,7 @@ int repl(CEnv& cenv) { AST* exp = NULL; - AST* ast = NULL; + const AST* ast = NULL; const string replFnName = cenv.penv.gensymstr("_repl"); while (1) { cenv.out << "() "; diff --git a/src/resp.hpp b/src/resp.hpp index 0112a9e..c629cc8 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -888,9 +888,9 @@ void initLang(PEnv& penv, TEnv& tenv); int eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute); int repl(CEnv& cenv); -void resp_constrain(TEnv& tenv, Constraints& c, const AST* ast) throw(Error); -AST* resp_lift(CEnv& cenv, Code& code, AST* ast) throw(); -CVal resp_compile(CEnv& cenv, const AST* ast) throw(); +void resp_constrain(TEnv& tenv, Constraints& c, const AST* ast) throw(Error); +const AST* resp_lift(CEnv& cenv, Code& code, const AST* ast) throw(); +CVal resp_compile(CEnv& cenv, const AST* ast) throw(); bool is_form(const AST* ast, const std::string& form); bool is_primitive(const PEnv& penv, const AST* ast); |