summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-10-10 16:38:11 +0000
committerHaojian Wu <hokein@google.com>2016-10-10 16:38:11 +0000
commiteaf77911b29a7cb54fc5c7f8636ee72807e7f690 (patch)
treeec6457e74502bc1c85ad08eba5fe1f9d1a678d16 /clang-tools-extra/clang-tidy/google
parentce2da5e1431cd9ef4fddffefe6552b495864b38d (diff)
downloadbcm5719-llvm-eaf77911b29a7cb54fc5c7f8636ee72807e7f690.tar.gz
bcm5719-llvm-eaf77911b29a7cb54fc5c7f8636ee72807e7f690.zip
[clang-tidy] Add a whitelist option in google-runtime-references.
Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25244 llvm-svn: 283777
Diffstat (limited to 'clang-tools-extra/clang-tidy/google')
-rw-r--r--clang-tools-extra/clang-tidy/google/NonConstReferences.cpp24
-rw-r--r--clang-tools-extra/clang-tidy/google/NonConstReferences.h7
2 files changed, 29 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp b/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
index 5667bd19502..d1bc1534c70 100644
--- a/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
+++ b/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "NonConstReferences.h"
+#include "../utils/OptionsUtils.h"
#include "clang/AST/DeclBase.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -19,7 +20,21 @@ namespace tidy {
namespace google {
namespace runtime {
+NonConstReferences::NonConstReferences(StringRef Name,
+ ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ WhiteListTypes(
+ utils::options::parseStringList(Options.get("WhiteListTypes", ""))) {}
+
+void NonConstReferences::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "WhiteListTypes",
+ utils::options::serializeStringList(WhiteListTypes));
+}
+
void NonConstReferences::registerMatchers(MatchFinder *Finder) {
+ if (!getLangOpts().CPlusPlus)
+ return;
+
Finder->addMatcher(
parmVarDecl(
unless(isInstantiated()),
@@ -52,6 +67,15 @@ void NonConstReferences::check(const MatchFinder::MatchResult &Result) {
}
auto ReferencedType = *Result.Nodes.getNodeAs<QualType>("referenced_type");
+
+ if (std::find_if(WhiteListTypes.begin(), WhiteListTypes.end(),
+ [&](llvm::StringRef WhiteListType) {
+ return ReferencedType.getCanonicalType().getAsString(
+ Result.Context->getPrintingPolicy()) ==
+ WhiteListType;
+ }) != WhiteListTypes.end())
+ return;
+
// Don't warn on function references, they shouldn't be constant.
if (ReferencedType->isFunctionProtoType())
return;
diff --git a/clang-tools-extra/clang-tidy/google/NonConstReferences.h b/clang-tools-extra/clang-tidy/google/NonConstReferences.h
index 3adb1f9d40d..a665813fff0 100644
--- a/clang-tools-extra/clang-tidy/google/NonConstReferences.h
+++ b/clang-tools-extra/clang-tidy/google/NonConstReferences.h
@@ -22,10 +22,13 @@ namespace runtime {
/// https://google.github.io/styleguide/cppguide.html#Reference_Arguments
class NonConstReferences : public ClangTidyCheck {
public:
- NonConstReferences(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ NonConstReferences(StringRef Name, ClangTidyContext *Context);
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
+private:
+ const std::vector<std::string> WhiteListTypes;
};
} // namespace runtime
OpenPOWER on IntegriCloud