diff options
Diffstat (limited to 'typing.cpp')
-rw-r--r-- | typing.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -21,7 +21,7 @@ void Constraints::constrain(TEnv& tenv, const AST* o, AType* t) { - assert(!dynamic_cast<const AType*>(o)); + assert(!o->to<const AType*>()); push_back(Constraint(tenv.var(o), t, o->loc)); } @@ -65,7 +65,7 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const // Add parameters to environment frame for (size_t i = 0; i < prot()->size(); ++i) { - ASymbol* sym = dynamic_cast<ASymbol*>(prot()->at(i)); + ASymbol* sym = prot()->at(i)->to<ASymbol*>(); if (!sym) throw Error("parameter name is not a symbol", prot()->at(i)->loc); if (defined.find(sym) != defined.end()) @@ -78,7 +78,7 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const size_t e = 2; for (; e < size(); ++e) { AST* exp = at(e); - ADefinition* def = dynamic_cast<ADefinition*>(exp); + ADefinition* def = exp->to<ADefinition*>(); if (def) { ASymbol* sym = def->sym(); if (defined.find(sym) != defined.end()) @@ -95,7 +95,7 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const AType* protT = new AType(loc, NULL); for (size_t i = 0; i < prot()->size(); ++i) { - AType* tvar = tenv.fresh(dynamic_cast<ASymbol*>(prot()->at(i))); + AType* tvar = tenv.fresh(prot()->at(i)->to<ASymbol*>()); protT->push_back(tvar); assert(frame[i].first == prot()->at(i)); frame[i].second.first = prot()->at(i); @@ -127,7 +127,7 @@ ACall::constrain(TEnv& tenv, Constraints& c) const at(i)->constrain(tenv, c); AST* callee = tenv.resolve(at(0)); - AClosure* closure = dynamic_cast<AClosure*>(callee); + AClosure* closure = callee->to<AClosure*>(); if (closure) { if (size() - 1 != closure->prot()->size()) throw Error("incorrect number of arguments", loc); @@ -153,7 +153,7 @@ void ADefinition::constrain(TEnv& tenv, Constraints& c) const { if (size() != 3) throw Error("`def' requires exactly 2 arguments", loc); - const ASymbol* sym = dynamic_cast<const ASymbol*>(at(1)); + const ASymbol* sym = at(1)->to<const ASymbol*>(); if (!sym) throw Error("`def' name is not a symbol", loc); if (tenv.lookup(sym)) @@ -185,7 +185,7 @@ AIf::constrain(TEnv& tenv, Constraints& c) const void APrimitive::constrain(TEnv& tenv, Constraints& c) const { - const string n = dynamic_cast<ASymbol*>(at(0))->str(); + const string n = at(0)->to<ASymbol*>()->str(); enum { ARITHMETIC, BINARY, LOGICAL, COMPARISON } type; if (n == "+" || n == "-" || n == "*" || n == "/") type = ARITHMETIC; @@ -279,7 +279,7 @@ substitute(ATuple* tup, const AST* from, AST* to) if (*tup->at(i) == *from) tup->at(i) = to; else if (tup->at(i) != to) - substitute(dynamic_cast<ATuple*>(tup->at(i)), from, to); + substitute(tup->at(i)->to<ATuple*>(), from, to); } @@ -330,8 +330,8 @@ TEnv::unify(const Constraints& constraints) // TAPL 22.4 return Subst::compose(unify(cp), Subst(t, s)); } else if (s->kind == AType::EXPR && s->kind == t->kind && s->size() == t->size()) { for (size_t i = 0; i < s->size(); ++i) { - AType* si = dynamic_cast<AType*>(s->at(i)); - AType* ti = dynamic_cast<AType*>(t->at(i)); + AType* si = s->at(i)->to<AType*>(); + AType* ti = t->at(i)->to<AType*>(); if (si && ti) cp.push_back(Constraint(si, ti, si->loc)); } |