-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] Heuristic resolution for explicit object parameter #155143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c1cdb39
0d48289
cd3601a
ea15161
c2b8ac4
bf73e27
b48fa0e
466efd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,21 @@ QualType HeuristicResolverImpl::simplifyType(QualType Type, const Expr *E, | |
| } | ||
| } | ||
| } | ||
| // check if member expr is in the context of an explicit object method | ||
| if (!T.Type.isNull() && | ||
| (T.Type->isUndeducedAutoType() || T.Type->isTemplateTypeParmType())) { | ||
| if (auto *DRE = dyn_cast_if_present<DeclRefExpr>(T.E)) { | ||
| auto *PrDecl = dyn_cast_if_present<ParmVarDecl>(DRE->getDecl()); | ||
| // Then the type of 'this' should be type of the record the method is | ||
|
||
| // defined in | ||
| if (PrDecl && PrDecl->isExplicitObjectParameter()) { | ||
| const auto *Parent = | ||
| dyn_cast<TypeDecl>(PrDecl->getDeclContext()->getParent()); | ||
| return {Ctx.getTypeDeclType(Parent)}; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return T; | ||
| }; | ||
| // As an additional protection against infinite loops, bound the number of | ||
|
|
@@ -302,33 +317,17 @@ std::vector<const NamedDecl *> HeuristicResolverImpl::resolveMemberExpr( | |
| return {}; | ||
| } | ||
|
|
||
| // check if member expr is in the context of an explicit object method | ||
| // If so, it's safe to assume the templated arg is of type of the record | ||
| const auto ExplicitMemberHeuristic = [&](const Expr *Base) -> QualType { | ||
| if (auto *DeclRef = dyn_cast_if_present<DeclRefExpr>(Base)) { | ||
| auto *PrDecl = dyn_cast_if_present<ParmVarDecl>(DeclRef->getDecl()); | ||
|
|
||
| if (PrDecl && PrDecl->isExplicitObjectParameter()) { | ||
| // get the parent, a cxxrecord | ||
| return Ctx.getTypeDeclType( | ||
| dyn_cast<TypeDecl>(PrDecl->getDeclContext()->getParent())); | ||
| } | ||
| } | ||
|
|
||
| return {}; | ||
| }; | ||
|
|
||
| // Try resolving the member inside the expression's base type. | ||
| Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase(); | ||
| QualType BaseType = ME->getBaseType(); | ||
| BaseType = simplifyType(BaseType, Base, ME->isArrow()); | ||
|
|
||
| if (!BaseType.isNull() && | ||
| (BaseType->isUndeducedAutoType() || BaseType->isTemplateTypeParmType())) { | ||
| if (auto Type = ExplicitMemberHeuristic(Base); !Type.isNull()) { | ||
| BaseType = Type; | ||
| } | ||
| } | ||
| // fflush(stdout); | ||
|
||
| // fflush(stderr); | ||
| // std::flush(std::cout); | ||
| // std::flush(std::cerr); | ||
| // using namespace std::chrono_literals; | ||
| // std::this_thread::sleep_for(10ms); | ||
|
|
||
| return resolveDependentMember(BaseType, ME->getMember(), NoFilter); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would reword / expand on this as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!