diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-19 15:03:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 15:03:56 -0700 |
| commit | 453683bf44f2112719802eaac2b332d49eebd640 (patch) | |
| tree | d399db4c9cba90c11980186d3df1ffcc4d423b5a /source/slang/slang-lookup.cpp | |
| parent | ecf85df6eee3da76ef54b14e4ab083f22da89e46 (diff) | |
Tuple swizzling, concat, comparison and `countof`. (#4856)
* Tuple swizzling and element access.
* Update proposal status.
* Cleanup.
* Fix merrge error.
* Address review.
Diffstat (limited to 'source/slang/slang-lookup.cpp')
| -rw-r--r-- | source/slang/slang-lookup.cpp | 105 |
1 files changed, 62 insertions, 43 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index c1895d754..7acaa030b 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -387,53 +387,16 @@ static void _lookUpMembersInSuperType( _lookUpMembersInSuperTypeImpl(astBuilder, name, leafType, superType, leafIsSuperWitness, request, ioResult, &breadcrumb); } -static void _lookUpMembersInSuperTypeDeclImpl( - ASTBuilder* astBuilder, +static void _lookupMembersInSuperTypeFacets(ASTBuilder* astBuilder, Name* name, - DeclRef<Decl> declRef, + Type* selfType, + InheritanceInfo const& inheritanceInfo, LookupRequest const& request, LookupResult& ioResult, BreadcrumbInfo* inBreadcrumbs) { - auto semantics = request.semantics; - if (!as<InterfaceDecl>(declRef.getDecl()) && getText(name) == "This") - { - // If we are looking for `This` in anything other than an InterfaceDecl, - // we just need to return the declRef itself. - AddToLookupResult(ioResult, CreateLookupResultItem(declRef, inBreadcrumbs)); - return; - } - - // If the semantics context hasn't been established yet (e.g. when looking up during parsing), - // we simply do a direct lookup without considering subtypes or extensions. - // - if (!semantics) - { - // In this case we can only lookup in an aggregate type. - if (auto aggTypeDeclBaseRef = declRef.as<AggTypeDeclBase>()) - { - _lookUpDirectAndTransparentMembers(astBuilder, name, aggTypeDeclBaseRef.getDecl(), aggTypeDeclBaseRef, request, ioResult, inBreadcrumbs); - } - return; - } - - ensureDecl(semantics, declRef.getDecl(), DeclCheckState::ReadyForLookup); - - // With semantics context, we can do a comprehensive lookup by scanning through - // the linearized inheritance list. + - auto selfType = DeclRefType::create(astBuilder, declRef); - InheritanceInfo inheritanceInfo; - if (auto extDeclRef = declRef.as<ExtensionDecl>()) - { - inheritanceInfo = semantics->getShared()->getInheritanceInfo(extDeclRef); - } - else - { - selfType = selfType->getCanonicalType(); - inheritanceInfo = semantics->getShared()->getInheritanceInfo(selfType); - } - for (auto facet : inheritanceInfo.facets) { auto containerDeclRef = facet->getDeclRef().as<ContainerDecl>(); @@ -457,12 +420,12 @@ static void _lookUpMembersInSuperTypeDeclImpl( continue; } // If we are looking up only immediate members, ignore non "Self" facets or extension to "Self" - else if (int(request.options) & int(LookupOptions::IgnoreInheritance) + else if (int(request.options) & int(LookupOptions::IgnoreInheritance) && (facet.getImpl()->directness != Facet::Directness::Self && (!extensionFacet || !extensionFacet->targetType.type->equals(selfType)) )) { - continue; + continue; } // Some things that are syntactically `InheritanceDecl`s don't actually @@ -527,6 +490,56 @@ static void _lookUpMembersInSuperTypeDeclImpl( } } +static void _lookUpMembersInSuperTypeDeclImpl( + ASTBuilder* astBuilder, + Name* name, + DeclRef<Decl> declRef, + LookupRequest const& request, + LookupResult& ioResult, + BreadcrumbInfo* inBreadcrumbs) +{ + auto semantics = request.semantics; + if (!as<InterfaceDecl>(declRef.getDecl()) && getText(name) == "This") + { + // If we are looking for `This` in anything other than an InterfaceDecl, + // we just need to return the declRef itself. + AddToLookupResult(ioResult, CreateLookupResultItem(declRef, inBreadcrumbs)); + return; + } + + // If the semantics context hasn't been established yet (e.g. when looking up during parsing), + // we simply do a direct lookup without considering subtypes or extensions. + // + if (!semantics) + { + // In this case we can only lookup in an aggregate type. + if (auto aggTypeDeclBaseRef = declRef.as<AggTypeDeclBase>()) + { + _lookUpDirectAndTransparentMembers(astBuilder, name, aggTypeDeclBaseRef.getDecl(), aggTypeDeclBaseRef, request, ioResult, inBreadcrumbs); + } + return; + } + + ensureDecl(semantics, declRef.getDecl(), DeclCheckState::ReadyForLookup); + + // With semantics context, we can do a comprehensive lookup by scanning through + // the linearized inheritance list. + + auto selfType = DeclRefType::create(astBuilder, declRef); + InheritanceInfo inheritanceInfo; + if (auto extDeclRef = declRef.as<ExtensionDecl>()) + { + inheritanceInfo = semantics->getShared()->getInheritanceInfo(extDeclRef); + } + else + { + selfType = selfType->getCanonicalType(); + inheritanceInfo = semantics->getShared()->getInheritanceInfo(selfType); + } + + _lookupMembersInSuperTypeFacets(astBuilder, name, selfType, inheritanceInfo, request, ioResult, inBreadcrumbs); +} + static void _lookUpMembersInSuperTypeImpl( ASTBuilder* astBuilder, Name* name, @@ -565,6 +578,12 @@ static void _lookUpMembersInSuperTypeImpl( _lookUpMembersInSuperTypeDeclImpl(astBuilder, name, declRef, request, ioResult, inBreadcrumbs); } + else if (auto eachType = as<EachType>(superType)) + { + auto canEachType = eachType->getCanonicalType(); + InheritanceInfo inheritanceInfo = request.semantics->getShared()->getInheritanceInfo(canEachType); + _lookupMembersInSuperTypeFacets(astBuilder, name, canEachType, inheritanceInfo, request, ioResult, inBreadcrumbs); + } else if (auto extractExistentialType = as<ExtractExistentialType>(superType)) { // We want lookup to be performed on the underlying interface type of the existential, |
