From 8905a0e25858a047e0844c55ed8a025153ab25d9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 4 Dec 2010 23:21:09 +0000 Subject: More const-correctness (remove all use of const_cast). git-svn-id: http://svn.drobilla.net/resp/resp@297 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/parse.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/parse.cpp') diff --git a/src/parse.cpp b/src/parse.cpp index 7f107aa..8a7e3e0 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -23,16 +23,16 @@ using namespace std; -ATuple* +const ATuple* parseTuple(PEnv& penv, const ATuple* e) { - List ret; + List ret; FOREACHP(ATuple::const_iterator, i, e) ret.push_back(penv.parse(*i)); return ret.head; } -AST* +const AST* PEnv::parse(const AST* exp) { const ATuple* tup = exp->to_tuple(); @@ -86,7 +86,7 @@ PEnv::parse(const AST* exp) * Macro Functions * ***************************************************************************/ -inline AST* +inline const AST* macDef(PEnv& penv, const AST* exp) { const ATuple* tup = exp->to_tuple(); @@ -95,28 +95,28 @@ macDef(PEnv& penv, const AST* exp) const AST* arg1 = *(++i); THROW_IF(i == tup->end(), arg1->loc, "Unexpected end of `def' macro call"); if (arg1->to_lexeme()) { - return const_cast(exp); + return exp; } else { // (def (f x) y) => (def f (fn (x) y)) const ATuple* pat = arg1->to_tuple(); - List argsExp; + List argsExp; ATuple::const_iterator j = pat->begin(); for (++j; j != pat->end(); ++j) - argsExp.push_back(const_cast(*j)); + argsExp.push_back(*j); argsExp.head->loc = exp->loc; const AST* body = *(++i); - List fnExp; + List fnExp; fnExp.push_back(new ALexeme(exp->loc, "fn")); fnExp.push_back(argsExp.head); for (; i != tup->end(); ++i) - fnExp.push_back(const_cast(*i)); + fnExp.push_back(*i); fnExp.head->loc = body->loc; - List ret; - ret.push_back(const_cast(tup->head())); - ret.push_back(const_cast(pat->head())); + List ret; + ret.push_back(tup->head()); + ret.push_back(pat->head()); ret.push_back(fnExp.head); ret.head->loc = exp->loc; return ret.head; @@ -128,26 +128,26 @@ macDef(PEnv& penv, const AST* exp) * Parser Functions * ***************************************************************************/ -inline AST* +inline const AST* parseCall(PEnv& penv, const AST* exp, void* arg) { return parseTuple(penv, exp->to_tuple()); } -inline AST* +inline const AST* parseBool(PEnv& penv, const AST* exp, void* arg) { return new ALiteral(T_BOOL, *reinterpret_cast(arg), exp->loc); } -inline AST* +inline const AST* parseFn(PEnv& penv, const AST* exp, void* arg) { const ATuple* texp = exp->to_tuple(); ATuple::const_iterator a = texp->begin(); THROW_IF(++a == texp->end(), exp->loc, "Unexpected end of `fn' form"); - ATuple* prot = parseTuple(penv, (*a++)->to_tuple()); - List ret(new ATuple(penv.sym("fn"), NULL, Cursor())); + const ATuple* prot = parseTuple(penv, (*a++)->to_tuple()); + List ret(new ATuple(penv.sym("fn"), NULL, Cursor())); ret.push_back(prot); while (a != texp->end()) ret.push_back(penv.parse(*a++)); @@ -155,7 +155,7 @@ parseFn(PEnv& penv, const AST* exp, void* arg) return new ATuple(*ret.head); } -inline AST* +inline const AST* parseQuote(PEnv& penv, const AST* exp, void* arg) { const ATuple* texp = exp->to_tuple(); @@ -190,7 +190,7 @@ initLang(PEnv& penv, TEnv& tenv) penv.reg(false, "#f", PEnv::Handler(parseBool, &falseVal)); // Macros - penv.defmac("def", macDef); + penv.defmac("def", macDef); // Special forms penv.reg(true, "fn", PEnv::Handler(parseFn)); -- cgit v1.2.1