From d33e6b7475a87d5a62101afc81813e9c9e458a70 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 14 Jan 2018 16:22:11 -0500 Subject: allow extension of a concrete type to implement additional interface Also support the scenario that the extension declares conformance to interface I, and a method M in I is already supported by the base implementation. --- source/slang/syntax.h | 52 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'source/slang/syntax.h') diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 375eb5f1c..ab26b1f6d 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -978,6 +978,30 @@ namespace Slang { return items.Count() > 1 ? items[0].declRef.GetName() : item.declRef.GetName(); } + LookupResultItem* begin() + { + if (isValid()) + { + if (isOverloaded()) + return items.begin(); + else + return &item; + } + else + return nullptr; + } + LookupResultItem* end() + { + if (isValid()) + { + if (isOverloaded()) + return items.end(); + else + return &item + 1; + } + else + return nullptr; + } }; struct SemanticsVisitor; @@ -1085,6 +1109,27 @@ namespace Slang return FilteredMemberRefList(declRef.getDecl()->Members, declRef.substitutions); } + inline ExtensionDecl* GetCandidateExtensions(DeclRef const& declRef) + { + return declRef.getDecl()->candidateExtensions; + } + + template + inline FilteredMemberRefList getMembersOfTypeWithExt(DeclRef const& declRef) + { + auto rs = getMembersOfType(declRef); + if (auto aggDeclRef = declRef.As()) + { + for (auto ext = GetCandidateExtensions(aggDeclRef); ext; ext = ext->nextCandidateExtension) + { + auto extMembers = getMembersOfType(DeclRef(ext, declRef.substitutions)); + const_cast>&>(rs.decls).AddRange(extMembers.decls); + } + } + return rs; + } + + inline RefPtr GetType(DeclRef const& declRef) { return declRef.Substitute(declRef.getDecl()->type.Ptr()); @@ -1099,12 +1144,7 @@ namespace Slang { return declRef.Substitute(declRef.getDecl()->targetType.Ptr()); } - - inline ExtensionDecl* GetCandidateExtensions(DeclRef const& declRef) - { - return declRef.getDecl()->candidateExtensions; - } - + inline FilteredMemberRefList GetFields(DeclRef const& declRef) { return getMembersOfType(declRef); -- cgit v1.2.3