|
33 | 33 | #include "llvm/ADT/StringExtras.h" |
34 | 34 | #include "llvm/ADT/StringRef.h" |
35 | 35 | #include "llvm/ADT/Twine.h" |
36 | | -#include "llvm/ADT/identity.h" |
37 | 36 | #include "llvm/Support/Casting.h" |
38 | 37 | #include "llvm/Support/ErrorHandling.h" |
39 | 38 | #include "llvm/Support/FormatVariadic.h" |
@@ -339,53 +338,6 @@ QualType maybeDesugar(ASTContext &AST, QualType QT) { |
339 | 338 | return QT; |
340 | 339 | } |
341 | 340 |
|
342 | | -// Given a callee expression `Fn`, if the call is through a function pointer, |
343 | | -// try to find the declaration of the corresponding function pointer type, |
344 | | -// so that we can recover argument names from it. |
345 | | -// FIXME: This function is mostly duplicated in SemaCodeComplete.cpp; unify. |
346 | | -static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) { |
347 | | - TypeLoc Target; |
348 | | - Expr *NakedFn = Fn->IgnoreParenCasts(); |
349 | | - if (const auto *T = NakedFn->getType().getTypePtr()->getAs<TypedefType>()) { |
350 | | - Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc(); |
351 | | - } else if (const auto *DR = dyn_cast<DeclRefExpr>(NakedFn)) { |
352 | | - const auto *D = DR->getDecl(); |
353 | | - if (const auto *const VD = dyn_cast<VarDecl>(D)) { |
354 | | - Target = VD->getTypeSourceInfo()->getTypeLoc(); |
355 | | - } |
356 | | - } |
357 | | - |
358 | | - if (!Target) |
359 | | - return {}; |
360 | | - |
361 | | - // Unwrap types that may be wrapping the function type |
362 | | - while (true) { |
363 | | - if (auto P = Target.getAs<PointerTypeLoc>()) { |
364 | | - Target = P.getPointeeLoc(); |
365 | | - continue; |
366 | | - } |
367 | | - if (auto A = Target.getAs<AttributedTypeLoc>()) { |
368 | | - Target = A.getModifiedLoc(); |
369 | | - continue; |
370 | | - } |
371 | | - if (auto P = Target.getAs<ParenTypeLoc>()) { |
372 | | - Target = P.getInnerLoc(); |
373 | | - continue; |
374 | | - } |
375 | | - break; |
376 | | - } |
377 | | - |
378 | | - if (auto F = Target.getAs<FunctionProtoTypeLoc>()) { |
379 | | - // In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc |
380 | | - // which has null parameters. Avoid these as they don't contain useful |
381 | | - // information. |
382 | | - if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>())) |
383 | | - return F; |
384 | | - } |
385 | | - |
386 | | - return {}; |
387 | | -} |
388 | | - |
389 | 341 | ArrayRef<const ParmVarDecl *> |
390 | 342 | maybeDropCxxExplicitObjectParameters(ArrayRef<const ParmVarDecl *> Params) { |
391 | 343 | if (!Params.empty() && Params.front()->isExplicitObjectParameter()) |
@@ -514,7 +466,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> { |
514 | 466 | Callee.Decl = FD; |
515 | 467 | else if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(CalleeDecls[0])) |
516 | 468 | Callee.Decl = FTD->getTemplatedDecl(); |
517 | | - else if (FunctionProtoTypeLoc Loc = getPrototypeLoc(E->getCallee())) |
| 469 | + else if (FunctionProtoTypeLoc Loc = |
| 470 | + Resolver->getFunctionProtoTypeLoc(E->getCallee())) |
518 | 471 | Callee.Loc = Loc; |
519 | 472 | else |
520 | 473 | return true; |
|
0 commit comments