-
Notifications
You must be signed in to change notification settings - Fork 62
/
CodeStyleCheckerMain.cpp
71 lines (63 loc) · 2.64 KB
/
CodeStyleCheckerMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//==============================================================================
// FILE:
// CodeStyleCheckerMain.cpp
//
// DESCRIPTION:
// A standalone tool that runs the CodeStyleChecker plugin. See
// CodeStyleChecker.cpp for a complete description.
//
// USAGE:
// Main TU only:
// * ct-code-style-checker input-file.cpp
// All TUs (the main file and the #includ-ed header files)
// * ct-code-style-checker -main-tu-only=false input-file.cpp
//
// License: The Unlicense
//==============================================================================
#include "CodeStyleChecker.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
using namespace llvm;
using namespace clang;
//===----------------------------------------------------------------------===https://
// Command line options
//===----------------------------------------------------------------------===https://
static llvm::cl::OptionCategory CSCCategory("ct-code-style-checker options");
static cl::opt<bool> MainTuOnly{
"main-tu-only",
cl::desc("Only run on the main translation unit "
"(e.g. ignore included header files)"),
cl::init(true), cl::cat(CSCCategory)};
//===----------------------------------------------------------------------===https://
// PluginASTAction
//===----------------------------------------------------------------------===https://
class CSCPluginAction : public PluginASTAction {
public:
bool ParseArgs(const CompilerInstance &CI,
const std::vector<std::string> &args) override {
return true;
}
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef file) override {
return std::make_unique<CodeStyleCheckerASTConsumer>(
&CI.getASTContext(), MainTuOnly, CI.getSourceManager());
}
};
//===----------------------------------------------------------------------===https://
// Main driver code.
//===----------------------------------------------------------------------===https://
int main(int Argc, const char **Argv) {
Expected<tooling::CommonOptionsParser> eOptParser =
clang::tooling::CommonOptionsParser::create(Argc, Argv, CSCCategory);
if (auto E = eOptParser.takeError()) {
errs() << "Problem constructing CommonOptionsParser "
<< toString(std::move(E)) << '\n';
return EXIT_FAILURE;
}
clang::tooling::ClangTool Tool(eOptParser->getCompilations(),
eOptParser->getSourcePathList());
return Tool.run(
clang::tooling::newFrontendActionFactory<CSCPluginAction>().get());
}