Skip to content

Commit 7b32de2

Browse files
committed
ModuleObjcMessageTrace: also include the source file name where an ObjcMethod is referenced. rdar://138776708
1 parent 2747057 commit 7b32de2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Basic/Assertions.h"
2222
#include "swift/Basic/FileTypes.h"
2323
#include "swift/Basic/JSONSerialization.h"
24+
#include "swift/Basic/SourceManager.h"
2425
#include "swift/Frontend/FrontendOptions.h"
2526
#include "swift/IDE/SourceEntityWalker.h"
2627

@@ -816,6 +817,7 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
816817
}
817818

818819
class ObjcMethodReferenceCollector: public SourceEntityWalker {
820+
StringRef visitingFilePath;
819821
llvm::DenseSet<const clang::ObjCMethodDecl*> results;
820822
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
821823
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef,
@@ -828,6 +830,10 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
828830
return true;
829831
}
830832
public:
833+
void setFileBeforeVisiting(SourceFile *SF) {
834+
assert(SF && "need to visit actual source files");
835+
visitingFilePath = SF->getFilename();
836+
}
831837
void serializeAsJson(llvm::raw_ostream &OS) {
832838
llvm::json::OStream out(OS, /*IndentSize=*/4);
833839
out.array([&] {
@@ -845,7 +851,8 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
845851
out.attribute("type", pName);
846852
}
847853
out.attribute("method", clangD->getNameAsString());
848-
out.attribute("location", Loc.printToString(SM));
854+
out.attribute("declared_at", Loc.printToString(SM));
855+
out.attribute("referenced_at", visitingFilePath);
849856
});
850857
}
851858
});
@@ -879,6 +886,7 @@ bool swift::emitObjCMessageSendTraceIfNeeded(ModuleDecl *mainModule,
879886
ObjcMethodReferenceCollector collector;
880887
for (auto *FU : mainModule->getFiles()) {
881888
if (auto *SF = dyn_cast<SourceFile>(FU)) {
889+
collector.setFileBeforeVisiting(SF);
882890
collector.walk(*SF);
883891
}
884892
}

test/IDE/objc_send_collector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public func testProperties(_ x: FooClassBase) {
1515
// CHECK-DAG: fooBaseInstanceFunc0
1616
// CHECK-DAG: fooBaseInstanceFunc1
1717
// CHECK-DAG: "type": "FooClassBase"
18-
// CHECK-DAG: SOURCE_DIR/test/IDE/Inputs/mock-sdk/Foo.framework/Headers/Foo.h
18+
// CHECK-DAG: "declared_at": "SOURCE_DIR/test/IDE/Inputs/mock-sdk/Foo.framework/Headers/Foo.h
19+
// CHECK-DAG: "referenced_at": "SOURCE_DIR/test/IDE/objc_send_collector.swift"

0 commit comments

Comments
 (0)