From d5bff57e97494e5a25626c2877880a7eda5485c7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 15 Mar 2009 15:30:00 +0000 Subject: Abstract away (and prettify/shrink) dynamic_cast of AST objects. git-svn-id: http://svn.drobilla.net/resp/tuplr@104 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- llvm.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'llvm.cpp') diff --git a/llvm.cpp b/llvm.cpp index 64fc6a6..c354b79 100644 --- a/llvm.cpp +++ b/llvm.cpp @@ -61,7 +61,7 @@ lltype(const AType* t) if (t->at(0)->str() == "Pair") { vector types; for (size_t i = 1; i < t->size(); ++i) - types.push_back(lltype(dynamic_cast(t->at(i)))); + types.push_back(lltype(t->at(i)->to())); return PointerType::get(StructType::get(types, false), 0); } } @@ -218,10 +218,10 @@ AClosure::liftCall(CEnv& cenv, const vector& argsT) if (!genericType->concrete()) { // Find type and build substitution assert(argsT.size() == prot()->size()); - ATuple* genericProtT = dynamic_cast(genericType->at(1)); + ATuple* genericProtT = genericType->at(1)->to(); assert(genericProtT); for (size_t i = 0; i < argsT.size(); ++i) - argsSubst[dynamic_cast(genericProtT->at(i))] = dynamic_cast(argsT.at(i)); + argsSubst[genericProtT->at(i)->to()] = argsT.at(i)->to(); thisType = argsSubst.apply(genericType)->as(); @@ -239,7 +239,7 @@ AClosure::liftCall(CEnv& cenv, const vector& argsT) // Write function declaration string name = this->name == "" ? cenv.gensym("_fn") : this->name; Function* f = compileFunction(cenv, name, - lltype(dynamic_cast(thisType->at(thisType->size() - 1))), + lltype(thisType->at(thisType->size()-1)->to()), *protT); cenv.push(); @@ -281,7 +281,7 @@ static AST* maybeLookup(CEnv& cenv, AST* ast) { - ASymbol* s = dynamic_cast(ast); + ASymbol* s = ast->to(); if (s && s->addr) return cenv.tenv.deref(s->addr).first; return ast; @@ -290,8 +290,7 @@ maybeLookup(CEnv& cenv, AST* ast) void ACall::lift(CEnv& cenv) { - AClosure* c = dynamic_cast(maybeLookup(cenv, at(0))); - + AClosure* c = maybeLookup(cenv, at(0))->to(); vector argsT; // Lift arguments @@ -313,7 +312,7 @@ ACall::lift(CEnv& cenv) CValue ACall::compile(CEnv& cenv) { - AClosure* c = dynamic_cast(maybeLookup(cenv, at(0))); + AClosure* c = maybeLookup(cenv, at(0))->to(); if (!c) return NULL; // Primitive @@ -341,7 +340,7 @@ ADefinition::lift(CEnv& cenv) { // Define first for recursion cenv.def(at(1)->as(), at(2), cenv.type(at(2)), NULL); - AClosure* c = dynamic_cast(at(2)); + AClosure* c = at(2)->to(); if (c) c->name = at(1)->str(); at(2)->lift(cenv); @@ -405,7 +404,7 @@ APrimitive::compile(CEnv& cenv) Value* a = LLVal(cenv.compile(at(1))); Value* b = LLVal(cenv.compile(at(2))); bool isFloat = cenv.type(at(1))->str() == "Float"; - const string n = dynamic_cast(at(0))->str(); + const string n = at(0)->to()->str(); // Binary arithmetic operations Instruction::BinaryOps op = (Instruction::BinaryOps)0; -- cgit v1.2.1