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
@@ -803,7 +791,11 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
803791 if (!CtorRefs.empty () && BaseNameLoc.isValid ()) {
804792 Expr *Fn = CtorRefs.back ()->getFn ();
805793 if (Fn->getLoc () == BaseNameLoc) {
806- D = extractDecl (Fn);
794+ D = ide::getReferencedDecl (Fn).second .getDecl ();
795+ if (D == nullptr ) {
796+ assert (false && " Unhandled constructor reference" );
797+ return true ;
798+ }
807799 CtorTyRef = TD;
808800 }
809801 }
@@ -818,12 +810,6 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
818810 }
819811 }
820812
821- if (D == nullptr ) {
822- // FIXME: When does this happen?
823- assert (false && " unhandled reference" );
824- return true ;
825- }
826-
827813 CharSourceRange CharRange =
828814 Lexer::getCharSourceRangeFromSourceRange (D->getASTContext ().SourceMgr ,
829815 Range);
@@ -842,7 +828,7 @@ bool SemaAnnotator::passReference(ModuleEntity Mod,
842828}
843829
844830bool SemaAnnotator::passCallArgNames (Expr *Fn, ArgumentList *ArgList) {
845- ValueDecl *D = extractDecl (Fn);
831+ ValueDecl *D = ide::getReferencedDecl (Fn). second . getDecl ( );
846832 if (!D)
847833 return true ; // continue.
848834
0 commit comments