aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-04 23:01:58 +0000
committerDavid Robillard <d@drobilla.net>2010-12-04 23:01:58 +0000
commit8ee352054cff3512c8e6dc3fd4738ee24ad267af (patch)
tree4b87b064a689815b790c42d6c20208b56dcfc285
parent7bbb36a7085576958993cc6c394d5af8455a948d (diff)
downloadresp-8ee352054cff3512c8e6dc3fd4738ee24ad267af.tar.gz
resp-8ee352054cff3512c8e6dc3fd4738ee24ad267af.tar.bz2
resp-8ee352054cff3512c8e6dc3fd4738ee24ad267af.zip
More const-correctness.
git-svn-id: http://svn.drobilla.net/resp/resp@295 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--src/lift.cpp27
-rw-r--r--src/resp.hpp6
2 files changed, 18 insertions, 15 deletions
diff --git a/src/lift.cpp b/src/lift.cpp
index e98ddc6..5b3f871 100644
--- a/src/lift.cpp
+++ b/src/lift.cpp
@@ -50,10 +50,10 @@ lift_symbol(CEnv& cenv, Code& code, const ASymbol* sym) throw()
}
static AST*
-lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw()
+lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw()
{
List<ATuple,AST> impl;
- impl.push_back(fn->head());
+ impl.push_back(const_cast<AST*>(fn->head()));
const string fnName = cenv.name(fn);
const string nameBase = cenv.penv.gensymstr(((fnName != "") ? fnName : "fn").c_str());
@@ -61,7 +61,7 @@ lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw()
cenv.setName(impl, implNameStr);
cenv.liftStack.push(CEnv::FreeVars(fn, implNameStr));
-
+
// Create a new stub environment frame for parameters
cenv.push();
const AType* type = cenv.type(fn);
@@ -136,7 +136,7 @@ lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw()
}
static AST*
-lift_call(CEnv& cenv, Code& code, ATuple* call) throw()
+lift_call(CEnv& cenv, Code& code, const ATuple* call) throw()
{
List<ATuple, AST> copy;
@@ -185,7 +185,7 @@ lift_call(CEnv& cenv, Code& code, ATuple* call) throw()
}
static AST*
-lift_def(CEnv& cenv, Code& code, ATuple* def) throw()
+lift_def(CEnv& cenv, Code& code, const ATuple* def) throw()
{
// Define stub first for recursion
const ASymbol* const sym = def->list_ref(1)->as_symbol();
@@ -196,12 +196,13 @@ 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(const_cast<AST*>(def->head()));
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(const_cast<AST*>(resp_lift(cenv, code, *t)));
- cenv.setTypeSameAs(copy, def);
+ cenv.setTypeSameAs(const_cast<AST*>(static_cast<const AST*>(copy.head)),
+ const_cast<AST*>(static_cast<const AST*>(def)));
if (copy.head->list_ref(1) == copy.head->list_ref(2))
return NULL; // Definition created by lift_fn when body was lifted
@@ -214,16 +215,18 @@ lift_def(CEnv& cenv, Code& code, ATuple* def) throw()
}
static AST*
-lift_builtin_call(CEnv& cenv, Code& code, ATuple* call) throw()
+lift_builtin_call(CEnv& cenv, Code& code, const ATuple* call) throw()
{
- List<ATuple, AST> copy;
- copy.push_back(call->head());
+ List<ATuple,AST> copy;
+ copy.push_back(const_cast<AST*>(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)));
+
+ cenv.setTypeSameAs(const_cast<AST*>(static_cast<const AST*>(copy.head)),
+ const_cast<AST*>(static_cast<const AST*>(call)));
- cenv.setTypeSameAs(copy, call);
return copy;
}
@@ -234,7 +237,7 @@ resp_lift(CEnv& cenv, Code& code, const AST* ast) throw()
if (sym)
return lift_symbol(cenv, code, sym);
- ATuple* const call = const_cast<ATuple*>(ast->to_tuple());
+ const ATuple* const call = ast->to_tuple();
if (call) {
const ASymbol* const sym = call->head()->to_symbol();
const std::string form = sym ? sym->cppstr : "";
diff --git a/src/resp.hpp b/src/resp.hpp
index c629cc8..2756f23 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -845,9 +845,9 @@ struct CEnv {
CFunc currentFn; ///< Currently compiling function
struct FreeVars : public std::vector<const ASymbol*> {
- FreeVars(ATuple* f, const std::string& n) : fn(f), implName(n) {}
- ATuple* const fn;
- const std::string implName;
+ FreeVars(const ATuple* f, const std::string& n) : fn(f), implName(n) {}
+ const ATuple* const fn;
+ const std::string implName;
int32_t index(const ASymbol* sym) {
const_iterator i = find(begin(), end(), sym);
if (i != end()) {