ModuleObjcMessageTrace: report ObjC method calls from all source files under compilation

This commit is contained in:
Xi Ge
2024-10-31 14:50:14 -07:00
parent 108ad6f115
commit 95f2523ef3
3 changed files with 15 additions and 7 deletions

View File

@@ -823,14 +823,14 @@ class ObjcMethodReferenceCollector: public SourceEntityWalker {
std::string targetVariant;
SmallVector<StringRef, 32> FilePaths;
unsigned CurrentFileID;
llvm::DenseSet<const clang::ObjCMethodDecl*> results;
llvm::DenseMap<const clang::ObjCMethodDecl*, unsigned> results;
bool visitDeclReference(ValueDecl *D, CharSourceRange Range,
TypeDecl *CtorTyRef, ExtensionDecl *ExtTyRef,
Type T, ReferenceMetaData Data) override {
if (!Range.isValid())
return true;
if (auto *clangD = dyn_cast_or_null<clang::ObjCMethodDecl>(D->getClangDecl())) {
results.insert(clangD);
results[clangD] = CurrentFileID;
}
return true;
}
@@ -873,7 +873,8 @@ public:
if (!targetVariant.empty())
out.attribute("target-variant", targetVariant);
out.attributeArray("references", [&] {
for (const clang::ObjCMethodDecl* clangD: results) {
for (auto pair: results) {
auto *clangD = pair.first;
auto &SM = clangD->getASTContext().getSourceManager();
clang::SourceLocation Loc = clangD->getLocation();
if (!Loc.isValid()) {
@@ -881,14 +882,14 @@ public:
}
out.object([&] {
if (auto *parent = dyn_cast_or_null<clang::NamedDecl>(clangD
->getParent())) {
->getParent())) {
auto pName = parent->getName();
if (!pName.empty())
out.attribute(selectMethodOwnerKey(parent), pName);
}
out.attribute(selectMethodKey(clangD), clangD->getNameAsString());
out.attribute("declared_at", Loc.printToString(SM));
out.attribute("referenced_at_file_id", CurrentFileID);
out.attribute("referenced_at_file_id", pair.second);
});
}
});