summaryrefslogtreecommitdiff
path: root/source/slang/lookup.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-10-30 19:31:52 -0400
committerGitHub <noreply@github.com>2017-10-30 19:31:52 -0400
commit832d9c708891b10145c6648d893b04ca4a0b879a (patch)
treee1f44fc27bf80d94de5ac0e866c7409b2adcec22 /source/slang/lookup.cpp
parentc24c173101c2c124401af77d8c513a23efac3b7e (diff)
parent3ffdf610d05a9318731bd7237da530c3d312a9a9 (diff)
Merge pull request #235 from tfoleyNV/explicit-this-expr
Support `this` expressions (explicit and implicit)
Diffstat (limited to 'source/slang/lookup.cpp')
-rw-r--r--source/slang/lookup.cpp53
1 files changed, 24 insertions, 29 deletions
diff --git a/source/slang/lookup.cpp b/source/slang/lookup.cpp
index cf51ae720..c0cb657c4 100644
--- a/source/slang/lookup.cpp
+++ b/source/slang/lookup.cpp
@@ -319,40 +319,35 @@ void DoLookupImpl(
if(!containerDecl)
continue;
- // If the container is a generic, then we need to instantiate it
- // at the parameters themselves, so provide a fully-resolved
- // declaration reference for lookup.
- RefPtr<Substitutions> subst = nullptr;
-#if 1
- // Actually, the above rationale seems bogus. If we are looking
- // up from "inside" a generic declaration, we don't want to
- // get its members pre-specialized, right?
-#else
- if(auto parentGenericDecl = dynamic_cast<GenericDecl*>(containerDecl->ParentDecl))
+ DeclRef<ContainerDecl> containerDeclRef =
+ DeclRef<Decl>(containerDecl, nullptr).As<ContainerDecl>();
+
+ BreadcrumbInfo breadcrumb;
+ BreadcrumbInfo* breadcrumbs = nullptr;
+
+ // Depending on the kind of container we are looking into,
+ // we may need to insert something like a `this` expression
+ // to resolve the lookup result.
+ //
+ // Note: We are checking for `AggTypeDeclBase` here, and not
+ // just `AggTypeDecl`, because we want to catch `extension`
+ // declarations as well.
+ //
+ if (auto aggTypeDeclRef = containerDeclRef.As<AggTypeDeclBase>())
{
- subst = new Substitutions();
- subst->genericDecl = parentGenericDecl;
-
- for( auto pp : parentGenericDecl->Members )
- {
- if( auto genericTypeParam = pp.As<GenericTypeParamDecl>() )
- {
- subst->args.Add(DeclRefType::Create(
- session,
- DeclRef<GenericTypeParamDecl>(genericTypeParam.Ptr(), nullptr)));
- }
- else if( auto genericValParam = pp.As<GenericValueParamDecl>() )
- {
- subst->args.Add(new GenericParamIntVal(DeclRef<GenericValueParamDecl>(genericValParam.Ptr(), nullptr)));
- }
- }
+ breadcrumb.kind = LookupResultItem::Breadcrumb::Kind::This;
+ breadcrumb.declRef = aggTypeDeclRef;
+ breadcrumb.prev = nullptr;
+
+ breadcrumbs = &breadcrumb;
}
-#endif
- DeclRef<ContainerDecl> containerRef = DeclRef<Decl>(containerDecl, subst).As<ContainerDecl>();
+ // Now perform "local" lookup in the context of the container,
+ // as if we were looking up a member directly.
+ //
DoLocalLookupImpl(
session,
- name, containerRef, request, result, nullptr);
+ name, containerDeclRef, request, result, breadcrumbs);
}
if (result.isValid())