From ef19b423b46bed4739a1e86a26cfbb18c221d497 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 8 Nov 2017 11:09:17 -0500 Subject: Cleanup of "suport generic interface method". Add a GenericValueParamDecl case in doesGenericSignatureMatchRequirement() Return a substituted DeclaredSubtypeWitness in DeclaredSubtypeWitness::SubstituteImpl() instead of return this. --- source/slang/check.cpp | 9 +++++++++ source/slang/syntax.cpp | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 320b22bdb..233a82eef 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1609,6 +1609,15 @@ namespace Slang else return false; } + else if (auto genValMbr = genMbr.As()) + { + if (auto requiredGenValMbr = requiredGenMbr.As()) + { + return genValMbr->type->Equals(requiredGenValMbr->type); + } + else + return false; + } else if (auto genTypeConstraintMbr = genMbr.As()) { if (auto requiredTypeConstraintMbr = requiredGenMbr.As()) diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index 4e1778e6e..70730ff95 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1579,7 +1579,11 @@ void Type::accept(IValVisitor* visitor, void* extra) } } } - return this; + RefPtr rs = new DeclaredSubtypeWitness(); + rs->sub = sub->SubstituteImpl(subst, ioDiff).As(); + rs->sup = sup->SubstituteImpl(subst, ioDiff).As(); + rs->declRef = declRef.SubstituteImpl(subst, ioDiff); + return rs; } String DeclaredSubtypeWitness::ToString() -- cgit v1.2.3 From f408165a88e12467c4993199a0e515a8808083c3 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 8 Nov 2017 12:08:13 -0500 Subject: Cleanup substitution of DeclaredSubtypeWitness. Now using DeclaredSubtypeWitness::declRef to determine the proper argument index in a GenericSubstitution. --- source/slang/syntax.cpp | 67 ++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) (limited to 'source') diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index 70730ff95..81df49713 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1529,54 +1529,41 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr DeclaredSubtypeWitness::SubstituteImpl(Substitutions* subst, int * ioDiff) { - DeclRef genParamDeclRef; - if (auto subDeclRefType = this->sub.As()) + if (auto genConstraintDecl = declRef.As()) { - genParamDeclRef = subDeclRefType->declRef.As(); - } - if (!genParamDeclRef) - return this; - auto genParamDecl = genParamDeclRef.getDecl(); - // search for a substitution that might apply to us - for (auto s = subst; s; s = s->outer.Ptr()) - { - if (auto genericSubst = dynamic_cast(s)) + // search for a substitution that might apply to us + for (auto s = subst; s; s = s->outer.Ptr()) { - // the generic decl associated with the substitution list must be - // the generic decl that declared this parameter - auto genericDecl = genericSubst->genericDecl; - if (genericDecl != genParamDecl->ParentDecl) - continue; - bool found = false; - int index = 0; - for (auto m : genericDecl->Members) + if (auto genericSubst = dynamic_cast(s)) { - if (m.Ptr() == genParamDecl) - { - // We've found it, so return the corresponding specialization argument - (*ioDiff)++; - found = true; - break; - } - else if (auto typeParam = m.As()) - { - index++; - } - else if (auto valParam = m.As()) + // the generic decl associated with the substitution list must be + // the generic decl that declared this parameter + auto genericDecl = genericSubst->genericDecl; + if (genericDecl != genConstraintDecl.getDecl()->ParentDecl) + continue; + bool found = false; + UInt index = 0; + for (auto m : genericDecl->Members) { - index++; + if (auto constraintParam = m.As()) + { + if (constraintParam.Ptr() == declRef.getDecl()) + { + found = true; + break; + } + index++; + } } - else + if (found) { + (*ioDiff)++; + auto ordinaryParamCount = genericDecl->getMembersOfType().Count() + + genericDecl->getMembersOfType().Count(); + SLANG_ASSERT(index + ordinaryParamCount < genericSubst->args.Count()); + return genericSubst->args[index + ordinaryParamCount]; } } - if (found) - { - auto ordinaryParamCount = genericDecl->getMembersOfType().Count() + - genericDecl->getMembersOfType().Count(); - SLANG_ASSERT(ordinaryParamCount + index < genericSubst->args.Count()); - return genericSubst->args[ordinaryParamCount + index]; - } } } RefPtr rs = new DeclaredSubtypeWitness(); -- cgit v1.2.3