diff options
author | David Robillard <d@drobilla.net> | 2009-10-13 22:15:04 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-10-13 22:15:04 +0000 |
commit | 2dfcc9d781b2df3637fd96f1c5007703377b8109 (patch) | |
tree | 09381127a88e54ff1bd024a95b8a0c2eb7ed9b35 | |
parent | ba5c979bafd4be26ceeea41d09ca0c5c6025bdd5 (diff) | |
download | resp-2dfcc9d781b2df3637fd96f1c5007703377b8109.tar.gz resp-2dfcc9d781b2df3637fd96f1c5007703377b8109.tar.bz2 resp-2dfcc9d781b2df3637fd96f1c5007703377b8109.zip |
Move TEnv::buildSubst to unify.cpp.
git-svn-id: http://svn.drobilla.net/resp/tuplr@212 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | src/constrain.cpp | 33 | ||||
-rw-r--r-- | src/unify.cpp | 34 |
2 files changed, 34 insertions, 33 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index e751895..7106ec8 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -22,39 +22,6 @@ #include <set> #include "tuplr.hpp" -/** Build a type substitution for calling a generic function type - * with a specific set of argument types - */ -Subst -TEnv::buildSubst(AType* genericT, const AType& argsT) -{ - Subst subst; - - // Build substitution to apply to generic type - const ATuple* genericProtT = genericT->at(1)->as<const ATuple*>(); - assert(argsT.size() == genericProtT->size()); - ATuple::const_iterator g = genericProtT->begin(); - AType::const_iterator a = argsT.begin(); - for (; a != argsT.end(); ++a, ++g) { - const AType* genericArgT = (*g)->to<const AType*>(); - AType* callArgT = (*a)->to<AType*>(); - if (callArgT->kind == AType::EXPR) { - assert(genericArgT->kind == AType::EXPR); - assert(callArgT->size() == genericArgT->size()); - for (size_t i = 0; i < callArgT->size(); ++i) { - const AType* gT = genericArgT->at(i)->to<const AType*>(); - AType* aT = callArgT->at(i)->to<AType*>(); - if (gT && aT) - subst.add(gT, aT); - } - } else { - subst.add(genericArgT, callArgT); - } - } - - return subst; -} - #define CONSTRAIN_LITERAL(CT, NAME) \ template<> void \ ALiteral<CT>::constrain(TEnv& tenv, Constraints& c) const { \ diff --git a/src/unify.cpp b/src/unify.cpp index 74e35fd..eebd75c 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -22,6 +22,40 @@ #include <set> #include "tuplr.hpp" +/** Build a type substitution for calling a generic function type + * with a specific set of argument types + */ +Subst +TEnv::buildSubst(AType* genericT, const AType& argsT) +{ + Subst subst; + + // Build substitution to apply to generic type + const ATuple* genericProtT = genericT->at(1)->as<const ATuple*>(); + assert(argsT.size() == genericProtT->size()); + ATuple::const_iterator g = genericProtT->begin(); + AType::const_iterator a = argsT.begin(); + for (; a != argsT.end(); ++a, ++g) { + const AType* genericArgT = (*g)->to<const AType*>(); + AType* callArgT = (*a)->to<AType*>(); + if (callArgT->kind == AType::EXPR) { + assert(genericArgT->kind == AType::EXPR); + assert(callArgT->size() == genericArgT->size()); + for (size_t i = 0; i < callArgT->size(); ++i) { + const AType* gT = genericArgT->at(i)->to<const AType*>(); + AType* aT = callArgT->at(i)->to<AType*>(); + if (gT && aT) + subst.add(gT, aT); + } + } else { + subst.add(genericArgT, callArgT); + } + } + + return subst; +} + + void Constraints::constrain(TEnv& tenv, const AST* o, AType* t) { |