diff options
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r-- | src/constrain.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index c815bac..024dce4 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -42,7 +42,7 @@ AString::constrain(TEnv& tenv, Constraints& c) const throw(Error) void ASymbol::constrain(TEnv& tenv, Constraints& c) const throw(Error) { - AType** ref = tenv.ref(this); + const AType** ref = tenv.ref(this); THROW_IF(!ref, loc, (format("undefined symbol `%1%'") % cppstr).str()); c.constrain(tenv, this, *ref); } @@ -53,7 +53,7 @@ ATuple::constrain(TEnv& tenv, Constraints& c) const throw(Error) AType* t = tup<AType>(loc, NULL); FOREACHP(const_iterator, p, this) { (*p)->constrain(tenv, c); - t->push_back(tenv.var(*p)); + t->push_back(const_cast<AType*>(tenv.var(*p))); } c.constrain(tenv, this, t); } @@ -72,9 +72,9 @@ AFn::constrain(TEnv& tenv, Constraints& c) const throw(Error) THROW_IF(defs.count(sym) != 0, sym->loc, (format("duplicate parameter `%1%'") % sym->str()).str()); defs.insert(sym); - AType* tvar = tenv.fresh(sym); + const AType* tvar = tenv.fresh(sym); frame.push_back(make_pair(sym, tvar)); - protT->push_back(tvar); + protT->push_back(const_cast<AType*>(tvar)); } const_iterator i = begin() + 1; @@ -95,13 +95,12 @@ AFn::constrain(TEnv& tenv, Constraints& c) const throw(Error) tenv.push(frame); - c.constrain(tenv, this, tenv.var()); AST* exp = NULL; for (i = begin() + 2; i != end(); ++i) (exp = *i)->constrain(tenv, c); - AType* bodyT = tenv.var(exp); - AType* fnT = tup<AType>(loc, tenv.Fn, protT, bodyT, 0); + const AType* bodyT = tenv.var(exp); + const AType* fnT = tup<const AType>(loc, tenv.Fn, protT, bodyT, 0); Object::pool.addRoot(fnT); tenv.pop(); @@ -127,10 +126,10 @@ ACall::constrain(TEnv& tenv, Constraints& c) const throw(Error) (format("expected %1% arguments, got %2%") % numArgs % (size() - 1)).str()); } - AType* retT = tenv.var(); - AType* argsT = tup<AType>(loc, 0); + const AType* retT = tenv.var(); + AType* argsT = tup<AType>(loc, 0); for (const_iterator i = begin() + 1; i != end(); ++i) - argsT->push_back(tenv.var(*i)); + argsT->push_back(const_cast<AType*>(tenv.var(*i))); c.constrain(tenv, head(), tup<AType>(head()->loc, tenv.Fn, argsT, retT, 0)); c.constrain(tenv, this, retT); @@ -143,7 +142,7 @@ ADef::constrain(TEnv& tenv, Constraints& c) const throw(Error) const ASymbol* sym = this->sym(); THROW_IF(!sym, loc, "`def' has no symbol") - AType* tvar = tenv.var(body()); + const AType* tvar = tenv.var(body()); tenv.def(sym, tvar); body()->constrain(tenv, c); c.constrain(tenv, sym, tvar); @@ -157,7 +156,7 @@ AIf::constrain(TEnv& tenv, Constraints& c) const throw(Error) THROW_IF(size() % 2 != 0, loc, "`if' missing final else clause") for (const_iterator i = begin() + 1; i != end(); ++i) (*i)->constrain(tenv, c); - AType* retT = tenv.var(this); + const AType* retT = tenv.var(this); for (const_iterator i = begin() + 1; true; ++i) { const_iterator next = i; ++next; @@ -178,7 +177,7 @@ ACons::constrain(TEnv& tenv, Constraints& c) const throw(Error) AType* type = tup<AType>(loc, tenv.Tup, 0); for (const_iterator i = begin() + 1; i != end(); ++i) { (*i)->constrain(tenv, c); - type->push_back(tenv.var(*i)); + type->push_back(const_cast<AType*>(tenv.var(*i))); } c.constrain(tenv, this, type); @@ -194,13 +193,13 @@ ADot::constrain(TEnv& tenv, Constraints& c) const throw(Error) THROW_IF(!idx, loc, "the 2nd argument to `.' must be a literal integer"); obj->constrain(tenv, c); - AType* retT = tenv.var(this); + const AType* retT = tenv.var(this); c.constrain(tenv, this, retT); AType* objT = tup<AType>(loc, tenv.Tup, 0); for (int i = 0; i < idx->val; ++i) - objT->push_back(tenv.var()); - objT->push_back(retT); + objT->push_back(const_cast<AType*>(tenv.var())); + objT->push_back(const_cast<AType*>(retT)); objT->push_back(new AType(obj->loc, AType::DOTS)); c.constrain(tenv, obj, objT); } @@ -228,7 +227,7 @@ APrimitive::constrain(TEnv& tenv, Constraints& c) const throw(Error) i = begin(); - AType* var = NULL; + const AType* var = NULL; switch (type) { case ARITHMETIC: if (size() < 3) |