diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/google')
| -rw-r--r-- | clang-tools-extra/clang-tidy/google/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp | 61 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/google/GoogleTidyModule.h | 31 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/google/Makefile | 12 |
4 files changed, 114 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/google/CMakeLists.txt b/clang-tools-extra/clang-tidy/google/CMakeLists.txt new file mode 100644 index 00000000000..a6bba75b7f0 --- /dev/null +++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt @@ -0,0 +1,10 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyGoogleModule + GoogleTidyModule.cpp + ) +target_link_libraries(clangTidyGoogleModule + clangTooling + clangBasic + clangASTMatchers + ) diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp new file mode 100644 index 00000000000..0839a06df55 --- /dev/null +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -0,0 +1,61 @@ +//===--- GoogleTidyModule.cpp - clang-tidy --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "GoogleTidyModule.h" +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PPCallbacks.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { + +void +ExplicitConstructorCheck::registerMatchers(ast_matchers::MatchFinder *Finder) { + Finder->addMatcher(constructorDecl().bind("construct"), this); +} + +void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) { + const CXXConstructorDecl *Ctor = + Result.Nodes.getNodeAs<CXXConstructorDecl>("construct"); + if (!Ctor->isExplicit() && !Ctor->isImplicit() && Ctor->getNumParams() >= 1 && + Ctor->getMinRequiredArguments() <= 1) { + SourceLocation Loc = Ctor->getLocation(); + Context->Diag(Loc, "Single-argument constructors must be explicit") + << FixItHint::CreateInsertion(Loc, "explicit "); + } +} + +class GoogleModule : public ClangTidyModule { +public: + virtual void addCheckFactories(ClangTidyCheckFactories &CheckFactories) { + CheckFactories.addCheckFactory( + "google-explicit-constructor", + new ClangTidyCheckFactory<ExplicitConstructorCheck>()); + } +}; + +// Register the GoogleTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module", + "Adds Google lint checks."); + +// This anchor is used to force the linker to link in the generated object file +// and thus register the GoogleModule. +volatile int GoogleModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.h b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.h new file mode 100644 index 00000000000..aed9b5f7ef0 --- /dev/null +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.h @@ -0,0 +1,31 @@ +//===--- GoogleTidyModule.h - clang-tidy ------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_GOOGLE_TIDY_MODULE_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_GOOGLE_TIDY_MODULE_H + +#include "../ClangTidy.h" + +namespace clang { +namespace tidy { + +/// \brief Checks that all single-argument constructors are explicit. +/// +/// see: +/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Explicit_Constructors +class ExplicitConstructorCheck : public ClangTidyCheck { +public: + virtual void registerMatchers(ast_matchers::MatchFinder *Finder); + virtual void check(const ast_matchers::MatchFinder::MatchResult &Result); +}; + +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_GOOGLE_TIDY_MODULE_H diff --git a/clang-tools-extra/clang-tidy/google/Makefile b/clang-tools-extra/clang-tidy/google/Makefile new file mode 100644 index 00000000000..4a39fddf51c --- /dev/null +++ b/clang-tools-extra/clang-tidy/google/Makefile @@ -0,0 +1,12 @@ +##===- clang-tidy/google/Makefile --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +CLANG_LEVEL := ../../../.. +LIBRARYNAME := clangTidyGoogleModule + +include $(CLANG_LEVEL)/Makefile |

