From e0389f5a1f32cb611e5a595a5974ee1d5c15f43d Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 15 Jun 2017 16:35:10 -0700 Subject: Replace `DeclRef` approach For context: a `DeclRef` is supposed to capture both a pointer to a particualr declaration, and also any information needed to specialize that declaration for a context (e.g., generic parameter substitutions). The existing approach had a hiearchy of specialized decl-ref types that mirrored the AST hierarchy, but that led to a lot of boilerplate where you had to recapitulate the exact same hierarchy. The new appraoch basically treats `DeclRef` as a sort of "smart pointer" in that it wraps a pointer to a `T` (the declaration), plus a side field for the specialization info, and then allows it to be cast as needed to other types (where the pointer cast would be allowed), while carrying along the side info. To enable this, all the things that used to be member functions of declaration-reference types are now free functions that take a `DeclRef` for some specific `T` as a parameter. --- source/slang/lookup.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'source/slang/lookup.cpp') diff --git a/source/slang/lookup.cpp b/source/slang/lookup.cpp index 89d07e223..e9c2177de 100644 --- a/source/slang/lookup.cpp +++ b/source/slang/lookup.cpp @@ -9,13 +9,13 @@ namespace Slang { struct BreadcrumbInfo { LookupResultItem::Breadcrumb::Kind kind; - DeclRef declRef; + DeclRef declRef; BreadcrumbInfo* prev = nullptr; }; void DoLocalLookupImpl( String const& name, - ContainerDeclRef containerDeclRef, + DeclRef containerDeclRef, LookupRequest const& request, LookupResult& result, BreadcrumbInfo* inBreadcrumbs); @@ -113,7 +113,7 @@ LookupResult refineLookup(LookupResult const& inResult, LookupMask mask) LookupResult result; for (auto item : inResult.items) { - if (!DeclPassesLookupMask(item.declRef.GetDecl(), mask)) + if (!DeclPassesLookupMask(item.declRef.getDecl(), mask)) continue; AddToLookupResult(result, item); @@ -122,7 +122,7 @@ LookupResult refineLookup(LookupResult const& inResult, LookupMask mask) } LookupResultItem CreateLookupResultItem( - DeclRef declRef, + DeclRef declRef, BreadcrumbInfo* breadcrumbInfos) { LookupResultItem item; @@ -167,7 +167,7 @@ void DoMemberLookupImpl( if (auto baseDeclRefType = baseType->As()) { - if (auto baseAggTypeDeclRef = baseDeclRefType->declRef.As()) + if (auto baseAggTypeDeclRef = baseDeclRefType->declRef.As()) { DoLocalLookupImpl(name, baseAggTypeDeclRef, request, ioResult, breadcrumbs); } @@ -178,7 +178,7 @@ void DoMemberLookupImpl( void DoMemberLookupImpl( String const& name, - DeclRef baseDeclRef, + DeclRef baseDeclRef, LookupRequest const& request, LookupResult& ioResult, BreadcrumbInfo* breadcrumbs) @@ -190,12 +190,12 @@ void DoMemberLookupImpl( // Look for members of the given name in the given container for declarations void DoLocalLookupImpl( String const& name, - ContainerDeclRef containerDeclRef, + DeclRef containerDeclRef, LookupRequest const& request, LookupResult& result, BreadcrumbInfo* inBreadcrumbs) { - ContainerDecl* containerDecl = containerDeclRef.GetDecl(); + ContainerDecl* containerDecl = containerDeclRef.getDecl(); // Ensure that the lookup dictionary in the container is up to date if (!containerDecl->memberDictionaryIsValid) @@ -217,7 +217,7 @@ void DoLocalLookupImpl( continue; // The declaration passed the test, so add it! - AddToLookupResult(result, CreateLookupResultItem(DeclRef(m, containerDeclRef.substitutions), inBreadcrumbs)); + AddToLookupResult(result, CreateLookupResultItem(DeclRef(m, containerDeclRef.substitutions), inBreadcrumbs)); } @@ -228,7 +228,7 @@ void DoLocalLookupImpl( { // The reference to the transparent member should use whatever // substitutions we used in referring to its outer container - DeclRef transparentMemberDeclRef(transparentInfo.decl, containerDeclRef.substitutions); + DeclRef transparentMemberDeclRef(transparentInfo.decl, containerDeclRef.substitutions); // We need to leave a breadcrumb so that we know that the result // of lookup involves a member lookup step here @@ -261,7 +261,7 @@ void DoLookupImpl( if(!link->containerDecl) continue; - ContainerDeclRef containerRef = DeclRef(link->containerDecl, nullptr).As(); + DeclRef containerRef = DeclRef(link->containerDecl, nullptr).As(); DoLocalLookupImpl(name, containerRef, request, result, nullptr); } @@ -292,7 +292,7 @@ LookupResult LookUp(String const& name, RefPtr scope) // perform lookup within the context of a particular container declaration, // and do *not* look further up the chain -LookupResult LookUpLocal(String const& name, ContainerDeclRef containerDeclRef) +LookupResult LookUpLocal(String const& name, DeclRef containerDeclRef) { LookupRequest request; LookupResult result; @@ -300,11 +300,4 @@ LookupResult LookUpLocal(String const& name, ContainerDeclRef containerDeclRef) return result; } -LookupResult LookUpLocal(String const& name, ContainerDecl* containerDecl) -{ - ContainerDeclRef containerRef = DeclRef(containerDecl, nullptr).As(); - return LookUpLocal(name, containerRef); -} - - } -- cgit v1.2.3