diff options
Diffstat (limited to 'typing.cpp')
-rw-r--r-- | typing.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
@@ -34,7 +34,7 @@ ASymbol::constrain(TEnv& tenv, Constraints& c) const { addr = tenv.lookup(this); if (!addr) - throw Error((format("undefined symbol `%1%'") % cppstr).str(), loc); + throw Error(loc, (format("undefined symbol `%1%'") % cppstr).str()); c.push_back(Constraint(tenv.var(this), tenv.deref(addr).second, loc)); } @@ -64,9 +64,9 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const for (size_t i = 0; i < prot()->size(); ++i) { ASymbol* sym = prot()->at(i)->to<ASymbol*>(); if (!sym) - throw Error("parameter name is not a symbol", prot()->at(i)->loc); + throw Error(prot()->at(i)->loc, "parameter name is not a symbol"); if (defined.find(sym) != defined.end()) - throw Error((format("duplicate parameter `%1%'") % sym->str()).str(), sym->loc); + throw Error(sym->loc, (format("duplicate parameter `%1%'") % sym->str()).str()); defined.insert(sym); frame.push_back(make_pair(sym, make_pair((AST*)NULL, (AType*)NULL))); } @@ -79,7 +79,7 @@ AClosure::constrain(TEnv& tenv, Constraints& c) const if (def) { ASymbol* sym = def->sym(); if (defined.find(sym) != defined.end()) - throw Error((format("`%1%' defined twice") % sym->str()).str(), def->loc); + throw Error(def->loc, (format("`%1%' defined twice") % sym->str()).str()); defined.insert(def->sym()); frame.push_back(make_pair(def->sym(), make_pair(def->at(2), (AType*)NULL))); } @@ -127,7 +127,7 @@ ACall::constrain(TEnv& tenv, Constraints& c) const AClosure* closure = callee->to<AClosure*>(); if (closure) { if (size() - 1 != closure->prot()->size()) - throw Error("incorrect number of arguments", loc); + throw Error(loc, "incorrect number of arguments"); TEnv::GenericTypes::iterator gt = tenv.genericTypes.find(closure); if (gt != tenv.genericTypes.end()) { for (size_t i = 1; i < size(); ++i) @@ -149,9 +149,9 @@ ACall::constrain(TEnv& tenv, Constraints& c) const void ADefinition::constrain(TEnv& tenv, Constraints& c) const { - THROW_IF(size() != 3, "`def' requires exactly 2 arguments", loc); + THROW_IF(size() != 3, loc, "`def' requires exactly 2 arguments"); const ASymbol* sym = this->sym(); - THROW_IF(!sym, "`def' has no symbol", loc) + THROW_IF(!sym, loc, "`def' has no symbol") AType* tvar = tenv.var(at(2)); tenv.def(sym, make_pair(at(2), tvar)); @@ -162,8 +162,8 @@ ADefinition::constrain(TEnv& tenv, Constraints& c) const void AIf::constrain(TEnv& tenv, Constraints& c) const { - THROW_IF(size() < 4, "`if' requires at least 3 arguments", loc); - THROW_IF(size() % 2 != 0, "`if' missing final else clause", loc) + THROW_IF(size() < 4, loc, "`if' requires at least 3 arguments"); + THROW_IF(size() % 2 != 0, loc, "`if' missing final else clause") for (size_t i = 1; i < size(); ++i) at(i)->constrain(tenv, c); AType* retT = tenv.var(this); @@ -191,7 +191,7 @@ APrimitive::constrain(TEnv& tenv, Constraints& c) const else if (n == "=" || n == "!=" || n == ">" || n == ">=" || n == "<" || n == "<=") type = COMPARISON; else - throw Error((format("unknown primitive `%1%'") % n).str(), loc); + throw Error(loc, (format("unknown primitive `%1%'") % n).str()); for (size_t i = 1; i < size(); ++i) at(i)->constrain(tenv, c); @@ -199,38 +199,38 @@ APrimitive::constrain(TEnv& tenv, Constraints& c) const switch (type) { case ARITHMETIC: if (size() < 3) - throw Error((format("`%1%' requires at least 2 arguments") % n).str(), loc); + throw Error(loc, (format("`%1%' requires at least 2 arguments") % n).str()); for (size_t i = 1; i < size(); ++i) c.constrain(tenv, at(i), tenv.var(this)); break; case BINARY: if (size() != 3) - throw Error((format("`%1%' requires exactly 2 arguments") % n).str(), loc); + throw Error(loc, (format("`%1%' requires exactly 2 arguments") % n).str()); c.constrain(tenv, at(1), tenv.var(this)); c.constrain(tenv, at(2), tenv.var(this)); break; case LOGICAL: if (size() != 3) - throw Error((format("`%1%' requires exactly 2 arguments") % n).str(), loc); + throw Error(loc, (format("`%1%' requires exactly 2 arguments") % n).str()); c.constrain(tenv, this, tenv.named("Bool")); c.constrain(tenv, at(1), tenv.named("Bool")); c.constrain(tenv, at(2), tenv.named("Bool")); break; case COMPARISON: if (size() != 3) - throw Error((format("`%1%' requires exactly 2 arguments") % n).str(), loc); + throw Error(loc, (format("`%1%' requires exactly 2 arguments") % n).str()); c.constrain(tenv, this, tenv.named("Bool")); c.constrain(tenv, at(1), tenv.var(at(2))); break; default: - throw Error((format("unknown primitive `%1%'") % n).str(), loc); + throw Error(loc, (format("unknown primitive `%1%'") % n).str()); } } void AConsCall::constrain(TEnv& tenv, Constraints& c) const { - THROW_IF(size() != 3, "`cons' requires exactly 2 arguments", loc) + THROW_IF(size() != 3, loc, "`cons' requires exactly 2 arguments") AType* t = new AType(loc, tenv.penv.sym("Pair"), 0); for (size_t i = 1; i < size(); ++i) { at(i)->constrain(tenv, c); @@ -242,7 +242,7 @@ AConsCall::constrain(TEnv& tenv, Constraints& c) const void ACarCall::constrain(TEnv& tenv, Constraints& c) const { - THROW_IF(size() != 2, "`car' requires exactly 1 argument", loc) + THROW_IF(size() != 2, loc, "`car' requires exactly 1 argument") at(1)->constrain(tenv, c); AType* carT = tenv.var(this); AType* pairT = new AType(at(1)->loc, tenv.penv.sym("Pair"), carT, tenv.var(), 0); @@ -253,7 +253,7 @@ ACarCall::constrain(TEnv& tenv, Constraints& c) const void ACdrCall::constrain(TEnv& tenv, Constraints& c) const { - THROW_IF(size() != 2, "`cdr' requires exactly 1 argument", loc) + THROW_IF(size() != 2, loc, "`cdr' requires exactly 1 argument") at(1)->constrain(tenv, c); AType* cdrT = tenv.var(this); AType* pairT = new AType(at(1)->loc, tenv.penv.sym("Pair"), tenv.var(), cdrT, 0); @@ -332,8 +332,8 @@ TEnv::unify(const Constraints& constraints) // TAPL 22.4 } return unify(cp); } else { - throw Error((format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str(), - s->loc ? s->loc : t->loc); + throw Error(s->loc ? s->loc : t->loc, + (format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str()); } } |