diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-15 16:35:10 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-15 16:35:10 -0700 |
| commit | e0389f5a1f32cb611e5a595a5974ee1d5c15f43d (patch) | |
| tree | 7bee1ed3a1f235ac97de9f8d9893f2994015c5c3 /source/slang/lookup.cpp | |
| parent | 04d43cd71f081f1b8d2f0fd803a47cb6342e4fcd (diff) | |
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<T>` 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<T>` for some specific `T` as a parameter.
Diffstat (limited to 'source/slang/lookup.cpp')
| -rw-r--r-- | source/slang/lookup.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
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<Decl> declRef; BreadcrumbInfo* prev = nullptr; }; void DoLocalLookupImpl( String const& name, - ContainerDeclRef containerDeclRef, + DeclRef<ContainerDecl> 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<Decl> declRef, BreadcrumbInfo* breadcrumbInfos) { LookupResultItem item; @@ -167,7 +167,7 @@ void DoMemberLookupImpl( if (auto baseDeclRefType = baseType->As<DeclRefType>()) { - if (auto baseAggTypeDeclRef = baseDeclRefType->declRef.As<AggTypeDeclRef>()) + if (auto baseAggTypeDeclRef = baseDeclRefType->declRef.As<AggTypeDecl>()) { DoLocalLookupImpl(name, baseAggTypeDeclRef, request, ioResult, breadcrumbs); } @@ -178,7 +178,7 @@ void DoMemberLookupImpl( void DoMemberLookupImpl( String const& name, - DeclRef baseDeclRef, + DeclRef<Decl> 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<ContainerDecl> 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<Decl>(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<Decl> 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<ContainerDeclRef>(); + DeclRef<ContainerDecl> containerRef = DeclRef<Decl>(link->containerDecl, nullptr).As<ContainerDecl>(); DoLocalLookupImpl(name, containerRef, request, result, nullptr); } @@ -292,7 +292,7 @@ LookupResult LookUp(String const& name, RefPtr<Scope> 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<ContainerDecl> 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<ContainerDeclRef>(); - return LookUpLocal(name, containerRef); -} - - } |
