Skip to content

Commit edddcdd

Browse files
committed
InterfaceLister: Print source location of member function use
1 parent 74c85d6 commit edddcdd

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

reporting/InterfaceLister.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ void InterfaceLister::registerMatchers(MatchFinder *Finder) {
2323
}
2424

2525
void InterfaceLister::check(const MatchFinder::MatchResult &Result) {
26-
const auto *MatchedCallExpr = Result.Nodes.getNodeAs<CXXMemberCallExpr>("member");
27-
if(MatchedCallExpr)
28-
{
29-
if (std::strcmp(MatchedCallExpr->getRecordDecl()->getDeclName().getAsString().c_str(), ClassName.c_str()) != 0)
26+
const auto *MatchedCallExpr =
27+
Result.Nodes.getNodeAs<CXXMemberCallExpr>("member");
28+
if (MatchedCallExpr) {
29+
if (std::strcmp(MatchedCallExpr->getRecordDecl()
30+
->getDeclName()
31+
.getAsString()
32+
.c_str(),
33+
ClassName.c_str()) != 0)
3034
return;
3135

32-
std::cerr << ClassName << " : " << MatchedCallExpr->getMethodDecl()->getQualifiedNameAsString() << "\n";
36+
std::string sourceInfo(MatchedCallExpr->getExprLoc().printToString(
37+
MyContext->getSourceManager()));
38+
std::cerr << sourceInfo << " ; " << ClassName << " : "
39+
<< MatchedCallExpr->getMethodDecl()->getQualifiedNameAsString()
40+
<< "\n";
3341
}
3442
}
3543

reporting/InterfaceLister.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class InterfaceLister : public ClangTidyCheck {
2323
private:
2424
const std::string ClassName; // the class name for which we want to find
2525
// used interfaces
26-
26+
ClangTidyContext * MyContext;
2727
public:
2828
InterfaceLister(StringRef Name, ClangTidyContext *Context)
29-
: ClangTidyCheck(Name, Context), ClassName(Options.get("ClassName", "")) {}
29+
: ClangTidyCheck(Name, Context), ClassName(Options.get("ClassName", "")), MyContext(Context) {}
3030

3131
void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
3232
Options.store(Opts, "ClassName", ClassName);

0 commit comments

Comments
 (0)