10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #include " swift/IDE/SourceEntityWalker.h"
14
13
#include " swift/AST/ASTContext.h"
15
14
#include " swift/AST/ASTWalker.h"
16
15
#include " swift/AST/Decl.h"
26
25
#include " swift/Basic/SourceManager.h"
27
26
#include " swift/Parse/Lexer.h"
28
27
#include " clang/Basic/Module.h"
28
+ #include " swift/IDE/SourceEntityWalker.h"
29
+ #include " swift/IDE/Utils.h"
29
30
30
31
using namespace swift ;
31
32
@@ -93,19 +94,6 @@ class SemaAnnotator : public ASTWalker {
93
94
bool passCallArgNames (Expr *Fn, ArgumentList *ArgList);
94
95
95
96
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
- }
109
97
};
110
98
111
99
} // end anonymous namespace
@@ -803,7 +791,11 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
803
791
if (!CtorRefs.empty () && BaseNameLoc.isValid ()) {
804
792
Expr *Fn = CtorRefs.back ()->getFn ();
805
793
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
+ }
807
799
CtorTyRef = TD;
808
800
}
809
801
}
@@ -818,12 +810,6 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
818
810
}
819
811
}
820
812
821
- if (D == nullptr ) {
822
- // FIXME: When does this happen?
823
- assert (false && " unhandled reference" );
824
- return true ;
825
- }
826
-
827
813
CharSourceRange CharRange =
828
814
Lexer::getCharSourceRangeFromSourceRange (D->getASTContext ().SourceMgr ,
829
815
Range);
@@ -842,7 +828,7 @@ bool SemaAnnotator::passReference(ModuleEntity Mod,
842
828
}
843
829
844
830
bool SemaAnnotator::passCallArgNames (Expr *Fn, ArgumentList *ArgList) {
845
- ValueDecl *D = extractDecl (Fn);
831
+ ValueDecl *D = ide::getReferencedDecl (Fn). second . getDecl ( );
846
832
if (!D)
847
833
return true ; // continue.
848
834
0 commit comments