23
23
#include " swift/Basic/JSONSerialization.h"
24
24
#include " swift/Basic/SourceManager.h"
25
25
#include " swift/Frontend/FrontendOptions.h"
26
+ #include " swift/Frontend/ModuleInterfaceSupport.h"
26
27
#include " swift/IDE/SourceEntityWalker.h"
27
28
28
29
#include " clang/AST/DeclObjC.h"
@@ -819,18 +820,19 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
819
820
const static unsigned OBJC_METHOD_TRACE_FILE_FORMAT_VERSION = 1 ;
820
821
821
822
class ObjcMethodReferenceCollector : public SourceEntityWalker {
823
+ std::string compilerVer;
822
824
std::string target;
823
825
std::string targetVariant;
824
826
SmallVector<StringRef, 32 > FilePaths;
825
827
unsigned CurrentFileID;
826
- llvm::DenseSet <const clang::ObjCMethodDecl*> results;
828
+ llvm::DenseMap <const clang::ObjCMethodDecl*, unsigned > results;
827
829
bool visitDeclReference (ValueDecl *D, CharSourceRange Range,
828
830
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef,
829
831
Type T, ReferenceMetaData Data) override {
830
832
if (!Range.isValid ())
831
833
return true ;
832
834
if (auto *clangD = dyn_cast_or_null<clang::ObjCMethodDecl>(D->getClangDecl ())) {
833
- results. insert ( clangD) ;
835
+ results[ clangD] = CurrentFileID ;
834
836
}
835
837
return true ;
836
838
}
@@ -855,6 +857,8 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
855
857
}
856
858
public:
857
859
ObjcMethodReferenceCollector (ModuleDecl *MD) {
860
+ compilerVer =
861
+ getSwiftInterfaceCompilerVersionForCurrentCompiler (MD->getASTContext ());
858
862
auto &Opts = MD->getASTContext ().LangOpts ;
859
863
target = Opts.Target .str ();
860
864
targetVariant = Opts.TargetVariant .has_value () ?
@@ -868,27 +872,29 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
868
872
void serializeAsJson (llvm::raw_ostream &OS) {
869
873
llvm::json::OStream out (OS, /* IndentSize=*/ 4 );
870
874
out.object ([&] {
875
+ out.attribute (" swift-compiler-version" , compilerVer);
871
876
out.attribute (" format-vesion" , OBJC_METHOD_TRACE_FILE_FORMAT_VERSION);
872
877
out.attribute (" target" , target);
873
878
if (!targetVariant.empty ())
874
879
out.attribute (" target-variant" , targetVariant);
875
880
out.attributeArray (" references" , [&] {
876
- for (const clang::ObjCMethodDecl* clangD: results) {
881
+ for (auto pair: results) {
882
+ auto *clangD = pair.first ;
877
883
auto &SM = clangD->getASTContext ().getSourceManager ();
878
884
clang::SourceLocation Loc = clangD->getLocation ();
879
885
if (!Loc.isValid ()) {
880
886
continue ;
881
887
}
882
888
out.object ([&] {
883
889
if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
884
- ->getParent ())) {
890
+ ->getParent ())) {
885
891
auto pName = parent->getName ();
886
892
if (!pName.empty ())
887
893
out.attribute (selectMethodOwnerKey (parent), pName);
888
894
}
889
895
out.attribute (selectMethodKey (clangD), clangD->getNameAsString ());
890
896
out.attribute (" declared_at" , Loc.printToString (SM));
891
- out.attribute (" referenced_at_file_id" , CurrentFileID );
897
+ out.attribute (" referenced_at_file_id" , pair. second );
892
898
});
893
899
}
894
900
});
0 commit comments