1010//
1111// ===----------------------------------------------------------------------===//
1212
13- #include " swift/IDE/SourceEntityWalker.h"
1413#include " swift/AST/ASTContext.h"
1514#include " swift/AST/ASTWalker.h"
1615#include " swift/AST/Decl.h"
2625#include " swift/Basic/SourceManager.h"
2726#include " swift/Parse/Lexer.h"
2827#include " clang/Basic/Module.h"
28+ #include " swift/IDE/SourceEntityWalker.h"
29+ #include " swift/IDE/Utils.h"
2930
3031using namespace swift ;
3132
@@ -93,19 +94,6 @@ class SemaAnnotator : public ASTWalker {
9394 bool passCallArgNames (Expr *Fn, ArgumentList *ArgList);
9495
9596 bool shouldIgnore (Decl *D);
96-
97- ValueDecl *extractDecl (Expr *Fn) const {
98- Fn = Fn->getSemanticsProvidingExpr ();
99- if (auto *DRE = dyn_cast<DeclRefExpr>(Fn))
100- return DRE->getDecl ();
101- if (auto ApplyE = dyn_cast<ApplyExpr>(Fn))
102- return extractDecl (ApplyE->getFn ());
103- if (auto *ACE = dyn_cast<AutoClosureExpr>(Fn)) {
104- if (auto *Unwrapped = ACE->getUnwrappedCurryThunkExpr ())
105- return extractDecl (Unwrapped);
106- }
107- return nullptr ;
108- }
10997};
11098
11199} // end anonymous namespace
@@ -800,7 +788,11 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
800788 if (!CtorRefs.empty () && BaseNameLoc.isValid ()) {
801789 Expr *Fn = CtorRefs.back ()->getFn ();
802790 if (Fn->getLoc () == BaseNameLoc) {
803- D = extractDecl (Fn);
791+ D = ide::getReferencedDecl (Fn).second .getDecl ();
792+ if (D == nullptr ) {
793+ assert (false && " Unhandled constructor reference" );
794+ return true ;
795+ }
804796 CtorTyRef = TD;
805797 }
806798 }
@@ -815,12 +807,6 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
815807 }
816808 }
817809
818- if (D == nullptr ) {
819- // FIXME: When does this happen?
820- assert (false && " unhandled reference" );
821- return true ;
822- }
823-
824810 CharSourceRange CharRange =
825811 Lexer::getCharSourceRangeFromSourceRange (D->getASTContext ().SourceMgr ,
826812 Range);
@@ -839,7 +825,7 @@ bool SemaAnnotator::passReference(ModuleEntity Mod,
839825}
840826
841827bool SemaAnnotator::passCallArgNames (Expr *Fn, ArgumentList *ArgList) {
842- ValueDecl *D = extractDecl (Fn);
828+ ValueDecl *D = ide::getReferencedDecl (Fn). second . getDecl ( );
843829 if (!D)
844830 return true ; // continue.
845831
0 commit comments