Skip to content

Commit 7b78f65

Browse files
[clang][Sema] Replace most of SemaCodeComplete's getApproximateType() with calls to HeuristicResolver
1 parent 82f9511 commit 7b78f65

File tree

1 file changed

+7
-90
lines changed

1 file changed

+7
-90
lines changed

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 7 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,96 +5830,13 @@ class ConceptInfo {
58305830
// We accept some lossiness (like dropping parameters).
58315831
// We only try to handle common expressions on the LHS of MemberExpr.
58325832
QualType getApproximateType(const Expr *E, HeuristicResolver &Resolver) {
5833-
if (E->getType().isNull())
5834-
return QualType();
5835-
// Don't drop implicit cast if it's an array decay.
5836-
if (auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5837-
!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay)
5838-
E = E->IgnoreParenImpCasts();
5839-
QualType Unresolved = E->getType();
5840-
// Resolve DependentNameType
5841-
if (const auto *DNT = Unresolved->getAs<DependentNameType>()) {
5842-
if (auto Decls = Resolver.resolveDependentNameType(DNT);
5843-
Decls.size() == 1) {
5844-
if (const auto *TD = dyn_cast<TypeDecl>(Decls[0]))
5845-
return TD->getASTContext().getTypeDeclType(TD);
5846-
}
5847-
}
5848-
// We only resolve DependentTy, or undeduced autos (including auto* etc).
5849-
if (!Unresolved->isSpecificBuiltinType(BuiltinType::Dependent)) {
5850-
AutoType *Auto = Unresolved->getContainedAutoType();
5851-
if (!Auto || !Auto->isUndeducedAutoType())
5852-
return Unresolved;
5853-
}
5854-
// A call: approximate-resolve callee to a function type, get its return type
5855-
if (const CallExpr *CE = llvm::dyn_cast<CallExpr>(E)) {
5856-
QualType Callee = getApproximateType(CE->getCallee(), Resolver);
5857-
if (Callee.isNull() ||
5858-
Callee->isSpecificPlaceholderType(BuiltinType::BoundMember))
5859-
Callee = Expr::findBoundMemberType(CE->getCallee());
5860-
if (Callee.isNull())
5861-
return Unresolved;
5862-
5863-
if (const auto *FnTypePtr = Callee->getAs<PointerType>()) {
5864-
Callee = FnTypePtr->getPointeeType();
5865-
} else if (const auto *BPT = Callee->getAs<BlockPointerType>()) {
5866-
Callee = BPT->getPointeeType();
5867-
}
5868-
if (const FunctionType *FnType = Callee->getAs<FunctionType>())
5869-
return FnType->getReturnType().getNonReferenceType();
5870-
5871-
// Unresolved call: try to guess the return type.
5872-
if (const auto *OE = llvm::dyn_cast<OverloadExpr>(CE->getCallee())) {
5873-
// If all candidates have the same approximate return type, use it.
5874-
// Discard references and const to allow more to be "the same".
5875-
// (In particular, if there's one candidate + ADL, resolve it).
5876-
const Type *Common = nullptr;
5877-
for (const auto *D : OE->decls()) {
5878-
QualType ReturnType;
5879-
if (const auto *FD = llvm::dyn_cast<FunctionDecl>(D))
5880-
ReturnType = FD->getReturnType();
5881-
else if (const auto *FTD = llvm::dyn_cast<FunctionTemplateDecl>(D))
5882-
ReturnType = FTD->getTemplatedDecl()->getReturnType();
5883-
if (ReturnType.isNull())
5884-
continue;
5885-
const Type *Candidate =
5886-
ReturnType.getNonReferenceType().getCanonicalType().getTypePtr();
5887-
if (Common && Common != Candidate)
5888-
return Unresolved; // Multiple candidates.
5889-
Common = Candidate;
5890-
}
5891-
if (Common != nullptr)
5892-
return QualType(Common, 0);
5893-
}
5894-
}
5895-
// A dependent member: resolve using HeuristicResolver.
5896-
if (const auto *CDSME = llvm::dyn_cast<CXXDependentScopeMemberExpr>(E)) {
5897-
for (const auto *Member : Resolver.resolveMemberExpr(CDSME)) {
5898-
if (const auto *VD = dyn_cast<ValueDecl>(Member)) {
5899-
return VD->getType().getNonReferenceType();
5900-
}
5901-
}
5902-
}
5903-
// A reference to an `auto` variable: approximate-resolve its initializer.
5904-
if (const auto *DRE = llvm::dyn_cast<DeclRefExpr>(E)) {
5905-
if (const auto *VD = llvm::dyn_cast<VarDecl>(DRE->getDecl())) {
5906-
if (VD->hasInit())
5907-
return getApproximateType(VD->getInit(), Resolver);
5908-
}
5909-
}
5910-
if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
5911-
if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
5912-
// We recurse into the subexpression because it could be of dependent
5913-
// type.
5914-
if (auto Pointee =
5915-
getApproximateType(UO->getSubExpr(), Resolver)->getPointeeType();
5916-
!Pointee.isNull())
5917-
return Pointee;
5918-
// Our caller expects a non-null result, even though the SubType is
5919-
// supposed to have a pointee. Fall through to Unresolved anyway.
5920-
}
5921-
}
5922-
return Unresolved;
5833+
QualType Result = Resolver.resolveExprToType(E);
5834+
if (Result.isNull())
5835+
return Result;
5836+
Result = Resolver.simplifyType(Result.getNonReferenceType(), E, false);
5837+
if (Result.isNull())
5838+
return Result;
5839+
return Result.getNonReferenceType();
59235840
}
59245841

59255842
// If \p Base is ParenListExpr, assume a chain of comma operators and pick the

0 commit comments

Comments
 (0)