-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a standalone tool that runs CodeStyleChecker
- Loading branch information
1 parent
589f838
commit b40fc9e
Showing
4 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: ../bin/ct-code-style-checker %s 2>&1 | FileCheck -implicit-check-not warning: %s | ||
|
||
// This is a rather simplified test for CodeStyleChecker that focuses on the | ||
// standalone wrapper tool: ct-code-style-checker. | ||
// | ||
// Unlike `clang -cc1`, ct-code-style-checker does not support `-verify` and we | ||
// cannot re-use the tests implemented for the plugin (which do rely on | ||
// `-verify`). Instead, this test is added as a small sanity-check. For proper | ||
// testing of CodeStyleChecker see the other tests that use the plugin version. | ||
|
||
// CHECK: CodeStyleChecker-standalone-tool.cpp:[[@LINE+1]]:6: warning: Function names should start with lower-case letter | ||
void ClangTutorFuncBad(); | ||
void clangTutorFuncOK(); | ||
|
||
// CHECK: CodeStyleChecker-standalone-tool.cpp:[[@LINE+1]]:7: warning: Type and variable names should start with upper-case letter | ||
class clangTutorClassBad; | ||
class ClangTutorClassOK; | ||
|
||
// CHECK: CodeStyleChecker-standalone-tool.cpp:[[@LINE+1]]:22: warning: `_` in names is not allowed | ||
class ClangTutorClass_Bad; | ||
class ClangTutorClassOK; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
add_executable(lacommenter | ||
# THE LIST OF TOOLS AND THE CORRESPONDING SOURCE FILES | ||
# ==================================================== | ||
set(CLANG_TUTOR_TOOLS | ||
lacommenter | ||
ct-code-refactor | ||
ct-code-style-checker | ||
) | ||
|
||
set(lacommenter_SOURCES | ||
LACommenterMain.cpp | ||
../lib/LACommenter.cpp | ||
) | ||
|
||
add_executable(ct-code-refactor | ||
set(ct-code-refactor_SOURCES | ||
CodeRefactorMain.cpp | ||
../lib/CodeRefactor.cpp | ||
) | ||
|
||
target_link_libraries(lacommenter | ||
clangTooling | ||
) | ||
set(ct-code-style-checker_SOURCES | ||
CodeStyleCheckerMain.cpp | ||
../lib/CodeStyleChecker.cpp | ||
) | ||
|
||
target_link_libraries(ct-code-refactor | ||
clangTooling | ||
) | ||
# CONFIGURE THE TOOLS | ||
# =================== | ||
foreach( tool ${CLANG_TUTOR_TOOLS} ) | ||
# Create a library corresponding to 'plugin' | ||
add_executable( | ||
${tool} | ||
${${tool}_SOURCES} | ||
) | ||
|
||
target_include_directories( | ||
lacommenter | ||
PRIVATE | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../include") | ||
# Link with libclangTooling | ||
target_link_libraries( | ||
${tool} | ||
clangTooling | ||
) | ||
|
||
target_include_directories( | ||
ct-code-refactor | ||
PRIVATE | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../include") | ||
# Configure include directories for 'tool' | ||
target_include_directories( | ||
${tool} | ||
PRIVATE | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../include" | ||
) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//============================================================================== | ||
// FILE: | ||
// CodeStyleCheckerMain.cpp | ||
// | ||
// DESCRIPTION: | ||
// | ||
// USAGE: | ||
// | ||
// REFERENCES: | ||
// | ||
// 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; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Command line options | ||
//===----------------------------------------------------------------------===// | ||
static llvm::cl::OptionCategory CSCCategory("ct-code-style-checker options"); | ||
|
||
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<CSCConsumer>(&CI.getASTContext()); | ||
} | ||
}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Main driver code. | ||
//===----------------------------------------------------------------------===// | ||
int main(int Argc, const char **Argv) { | ||
clang::tooling::CommonOptionsParser OptionsParser(Argc, Argv, CSCCategory); | ||
clang::tooling::ClangTool Tool(OptionsParser.getCompilations(), | ||
OptionsParser.getSourcePathList()); | ||
|
||
return Tool.run( | ||
clang::tooling::newFrontendActionFactory<CSCPluginAction>().get()); | ||
} |