Skip to content

Commit 779c068

Browse files
committed
Added simple reporting module + interface lister
1 parent 4976a08 commit 779c068

File tree

7 files changed

+143
-2
lines changed

7 files changed

+143
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ add_subdirectory(tool)
3535

3636
# the specific aliceO2 checker code
3737
add_subdirectory(aliceO2)
38+
# the specific reporting tools code
39+
add_subdirectory(reporting)
3840

3941

4042
endif()

reporting/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(LLVM_LINK_COMPONENTS support)
2+
3+
add_clang_library(clangTidyReportingModule
4+
ReportingTidyModule.cpp
5+
InterfaceLister.cpp
6+
7+
LINK_LIBS
8+
clangAST
9+
clangASTMatchers
10+
clangBasic
11+
clangLex
12+
clangTidy
13+
clangTidyUtils
14+
clangTooling
15+
)

reporting/InterfaceLister.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- InterfaceLister.cpp - clang-tidy---------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "InterfaceLister.h"
11+
#include "clang/AST/ASTContext.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include <iostream>
14+
15+
using namespace clang::ast_matchers;
16+
17+
namespace clang {
18+
namespace tidy {
19+
namespace reporting {
20+
21+
void InterfaceLister::registerMatchers(MatchFinder *Finder) {
22+
Finder->addMatcher(cxxMemberCallExpr().bind("member"), this);
23+
}
24+
25+
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)
30+
return;
31+
32+
std::cerr << ClassName << " : " << MatchedCallExpr->getMethodDecl()->getQualifiedNameAsString() << "\n";
33+
}
34+
}
35+
36+
} // namespace aliceO2
37+
} // namespace tidy
38+
} // namespace clang

reporting/InterfaceLister.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===--- MemberNamesCheck.h - clang-tidy-------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INTERFACELISTER_NAMES_H
11+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INTERFACELISTER_NAMES_H
12+
13+
#include "../ClangTidy.h"
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace reporting {
18+
19+
/// A simple tool/check that given a ClassName reports the interfaces
20+
/// used in the code base
21+
///
22+
class InterfaceLister : public ClangTidyCheck {
23+
private:
24+
const std::string ClassName; // the class name for which we want to find
25+
// used interfaces
26+
27+
public:
28+
InterfaceLister(StringRef Name, ClangTidyContext *Context)
29+
: ClangTidyCheck(Name, Context), ClassName(Options.get("ClassName", "")) {}
30+
31+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
32+
Options.store(Opts, "ClassName", ClassName);
33+
}
34+
35+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37+
};
38+
39+
} // namespace reporting
40+
} // namespace tidy
41+
} // namespace clang
42+
43+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INTERFACELISTER_NAMES_H

reporting/ReportingTidyModule.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- AliceO2TidyModule.cpp - clang-tidy ----------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "../ClangTidy.h"
11+
#include "../ClangTidyModule.h"
12+
#include "../ClangTidyModuleRegistry.h"
13+
#include "InterfaceLister.h"
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace reporting {
18+
19+
class ReportingModule : public ClangTidyModule {
20+
public:
21+
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
22+
CheckFactories.registerCheck<InterfaceLister>("Reporting-interfaces-used");
23+
}
24+
};
25+
26+
} // namespace Reporting
27+
28+
// Register the ReportingTidyModule using this statically initialized variable.
29+
static ClangTidyModuleRegistry::Add<reporting::ReportingModule>
30+
X("Reporting-module", "Adds Reporting tools (for simple analytics)");
31+
32+
// This anchor is used to force the linker to link in the generated object file
33+
// and thus register the ReportingModule.
34+
volatile int ReportingModuleAnchorSource = 0;
35+
36+
} // namespace tidy
37+
} // namespace clang

tool/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ target_link_libraries(O2codecheck
1414

1515
# link our own checks
1616
clangTidyAliceO2Module
17+
clangTidyReportingModule
1718

1819
# include checkers available from main clang-tidy
1920
clangTidyBoostModule
@@ -37,4 +38,4 @@ install(PROGRAMS run_O2CodeChecker.py DESTINATION bin)
3738

3839
# we need to install the builtin headers in a path which is searched by the tool
3940
# FIXME: a soft link would be better
40-
install(DIRECTORY ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/include DESTINATION lib/clang/${LLVM_PACKAGE_VERSION})
41+
install(DIRECTORY ${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/include DESTINATION lib/clang/${LLVM_PACKAGE_VERSION})

tool/ClangTidyMain.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,16 @@ extern volatile int ReadabilityModuleAnchorSource;
465465
static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
466466
ReadabilityModuleAnchorSource;
467467

468-
// This anchor is used to force the linker to link the ReadabilityModule.
468+
// This anchor is used to force the linker to link the AliceO2Module.
469469
extern volatile int AliceO2ModuleAnchorSource;
470470
static int LLVM_ATTRIBUTE_UNUSED AliceO2ModuleAnchorDestination =
471471
AliceO2ModuleAnchorSource;
472472

473+
// This anchor is used to force the linker to link the ReportingModule.
474+
extern volatile int ReportingModuleAnchorSource;
475+
static int LLVM_ATTRIBUTE_UNUSED ReportingModuleAnchorDestination =
476+
ReportingModuleAnchorSource;
477+
473478
} // namespace tidy
474479
} // namespace clang
475480

0 commit comments

Comments
 (0)