Skip to content

Commit 58e4016

Browse files
committed
ModuleObjcMessageTrace: consolidate all source code file paths to a side table
1 parent 84ba789 commit 58e4016

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,8 @@ const static unsigned OBJC_METHOD_TRACE_FILE_FORMAT_VERSION = 1;
821821
class ObjcMethodReferenceCollector: public SourceEntityWalker {
822822
std::string target;
823823
std::string targetVariant;
824-
StringRef visitingFilePath;
824+
SmallVector<StringRef, 32> FilePaths;
825+
unsigned CurrentFileID;
825826
llvm::DenseSet<const clang::ObjCMethodDecl*> results;
826827
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
827828
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef,
@@ -859,7 +860,8 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
859860
}
860861
void setFileBeforeVisiting(SourceFile *SF) {
861862
assert(SF && "need to visit actual source files");
862-
visitingFilePath = SF->getFilename();
863+
FilePaths.push_back(SF->getFilename());
864+
CurrentFileID = FilePaths.size();
863865
}
864866
void serializeAsJson(llvm::raw_ostream &OS) {
865867
llvm::json::OStream out(OS, /*IndentSize=*/4);
@@ -884,7 +886,15 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
884886
}
885887
out.attribute(selectMethodKey(clangD), clangD->getNameAsString());
886888
out.attribute("declared_at", Loc.printToString(SM));
887-
out.attribute("referenced_at", visitingFilePath);
889+
out.attribute("referenced_at_file_id", CurrentFileID);
890+
});
891+
}
892+
});
893+
out.attributeArray("fileMap", [&]{
894+
for (unsigned I = 0, N = FilePaths.size(); I != N; I ++) {
895+
out.object([&] {
896+
out.attribute("file_id", I + 1);
897+
out.attribute("file_path", FilePaths[I]);
888898
});
889899
}
890900
});

test/IDE/objc_send_collector.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public func testProperties(_ x: FooClassBase) {
1818
// CHECK-DAG: "class_method": "fooBaseClassFunc0"
1919
// CHECK-DAG: "interface_type": "FooClassBase"
2020
// CHECK-DAG: "declared_at": "SOURCE_DIR/test/IDE/Inputs/mock-sdk/Foo.framework/Headers/Foo.h
21-
// CHECK-DAG: "referenced_at": "SOURCE_DIR/test/IDE/objc_send_collector.swift"
21+
// CHECK-DAG: "referenced_at_file_id": 1
22+
// CHECK-DAG: "file_id": 1,
23+
// CHECK-DAG: "file_path": "SOURCE_DIR/test/IDE/objc_send_collector.swift"

0 commit comments

Comments
 (0)