Skip to content

Commit 95f2523

Browse files
committed
ModuleObjcMessageTrace: report ObjC method calls from all source files under compilation
1 parent 108ad6f commit 95f2523

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,14 +823,14 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
823823
std::string targetVariant;
824824
SmallVector<StringRef, 32> FilePaths;
825825
unsigned CurrentFileID;
826-
llvm::DenseSet<const clang::ObjCMethodDecl*> results;
826+
llvm::DenseMap<const clang::ObjCMethodDecl*, unsigned> results;
827827
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
828828
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef,
829829
Type T, ReferenceMetaData Data) override {
830830
if (!Range.isValid())
831831
return true;
832832
if (auto *clangD = dyn_cast_or_null<clang::ObjCMethodDecl>(D->getClangDecl())) {
833-
results.insert(clangD);
833+
results[clangD] = CurrentFileID;
834834
}
835835
return true;
836836
}
@@ -873,22 +873,23 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
873873
if (!targetVariant.empty())
874874
out.attribute("target-variant", targetVariant);
875875
out.attributeArray("references", [&] {
876-
for (const clang::ObjCMethodDecl* clangD: results) {
876+
for (auto pair: results) {
877+
auto *clangD = pair.first;
877878
auto &SM = clangD->getASTContext().getSourceManager();
878879
clang::SourceLocation Loc = clangD->getLocation();
879880
if (!Loc.isValid()) {
880881
continue;
881882
}
882883
out.object([&] {
883884
if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
884-
->getParent())) {
885+
->getParent())) {
885886
auto pName = parent->getName();
886887
if (!pName.empty())
887888
out.attribute(selectMethodOwnerKey(parent), pName);
888889
}
889890
out.attribute(selectMethodKey(clangD), clangD->getNameAsString());
890891
out.attribute("declared_at", Loc.printToString(SM));
891-
out.attribute("referenced_at_file_id", CurrentFileID);
892+
out.attribute("referenced_at_file_id", pair.second);
892893
});
893894
}
894895
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Foo
2+
3+
public func testProperties2(_ x: FooClassBase, _ y: FooProtocolBase) {
4+
y.fooProtoFunc()
5+
}

test/IDE/objc_send_collector.swift renamed to test/IDE/objc_send_collector_1.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -I %t/lib/swift -typecheck %s -module-name main -swift-version 5 -F %S/Inputs/mock-sdk -emit-loaded-module-trace-path %t/.MODULE_TRACE
3+
// RUN: %target-swift-frontend -I %t/lib/swift -typecheck %s %S/Inputs/objc_send_collector_2.swift -module-name main -swift-version 5 -F %S/Inputs/mock-sdk -emit-loaded-module-trace-path %t/.MODULE_TRACE
44
// RUN: cat %t/.SWIFT_FINE_DEPENDENCY_TRACE/* | %FileCheck %s
55

66
// REQUIRES: objc_interop
@@ -21,5 +21,7 @@ public func testProperties(_ x: FooClassBase, _ y: FooProtocolBase) {
2121
// CHECK-DAG: "protocol_type": "FooProtocolBase"
2222
// CHECK-DAG: "declared_at": "SOURCE_DIR/test/IDE/Inputs/mock-sdk/Foo.framework/Headers/Foo.h
2323
// CHECK-DAG: "referenced_at_file_id": 1
24+
// CHECK-DAG: "referenced_at_file_id": 2
2425
// CHECK-DAG: "file_id": 1,
25-
// CHECK-DAG: "file_path": "SOURCE_DIR/test/IDE/objc_send_collector.swift"
26+
// CHECK-DAG: "file_path": "SOURCE_DIR/test/IDE/objc_send_collector_1.swift"
27+
// CHECK-DAG: "file_path": "SOURCE_DIR/test/IDE/Inputs/objc_send_collector_2.swift"

0 commit comments

Comments
 (0)