diff options
Diffstat (limited to 'lib/StaticAnalyzer/Core/CheckerRegistry.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/CheckerRegistry.cpp | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/lib/StaticAnalyzer/Core/CheckerRegistry.cpp b/lib/StaticAnalyzer/Core/CheckerRegistry.cpp index c9cb189a5b729..645845ec2181f 100644 --- a/lib/StaticAnalyzer/Core/CheckerRegistry.cpp +++ b/lib/StaticAnalyzer/Core/CheckerRegistry.cpp @@ -1,4 +1,4 @@ -//===--- CheckerRegistry.cpp - Maintains all available checkers -*- C++ -*-===// +//===- CheckerRegistry.cpp - Maintains all available checkers -------------===// // // The LLVM Compiler Infrastructure // @@ -9,18 +9,26 @@ #include "clang/StaticAnalyzer/Core/CheckerRegistry.h" #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/LLVM.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/CheckerOptInfo.h" #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cstddef> +#include <tuple> using namespace clang; using namespace ento; static const char PackageSeparator = '.'; -typedef llvm::SetVector<const CheckerRegistry::CheckerInfo *> CheckerInfoSet; +using CheckerInfoSet = llvm::SetVector<const CheckerRegistry::CheckerInfo *>; static bool checkerNameLT(const CheckerRegistry::CheckerInfo &a, const CheckerRegistry::CheckerInfo &b) { @@ -50,8 +58,7 @@ static void collectCheckers(const CheckerRegistry::CheckerInfoList &checkers, // Use a binary search to find the possible start of the package. CheckerRegistry::CheckerInfo packageInfo(nullptr, opt.getName(), ""); auto end = checkers.cend(); - CheckerRegistry::CheckerInfoList::const_iterator i = - std::lower_bound(checkers.cbegin(), end, packageInfo, checkerNameLT); + auto i = std::lower_bound(checkers.cbegin(), end, packageInfo, checkerNameLT); // If we didn't even find a possible package, give up. if (i == end) @@ -73,12 +80,11 @@ static void collectCheckers(const CheckerRegistry::CheckerInfoList &checkers, size = packageSize->getValue(); // Step through all the checkers in the package. - for (auto checkEnd = i+size; i != checkEnd; ++i) { + for (auto checkEnd = i+size; i != checkEnd; ++i) if (opt.isEnabled()) collected.insert(&*i); else collected.remove(&*i); - } } void CheckerRegistry::addChecker(InitializationFunction fn, StringRef name, @@ -97,42 +103,38 @@ void CheckerRegistry::addChecker(InitializationFunction fn, StringRef name, void CheckerRegistry::initializeManager(CheckerManager &checkerMgr, SmallVectorImpl<CheckerOptInfo> &opts) const { // Sort checkers for efficient collection. - std::sort(Checkers.begin(), Checkers.end(), checkerNameLT); + llvm::sort(Checkers.begin(), Checkers.end(), checkerNameLT); // Collect checkers enabled by the options. CheckerInfoSet enabledCheckers; - for (SmallVectorImpl<CheckerOptInfo>::iterator - i = opts.begin(), e = opts.end(); i != e; ++i) { - collectCheckers(Checkers, Packages, *i, enabledCheckers); - } + for (auto &i : opts) + collectCheckers(Checkers, Packages, i, enabledCheckers); // Initialize the CheckerManager with all enabled checkers. - for (CheckerInfoSet::iterator - i = enabledCheckers.begin(), e = enabledCheckers.end(); i != e; ++i) { - checkerMgr.setCurrentCheckName(CheckName((*i)->FullName)); - (*i)->Initialize(checkerMgr); + for (const auto *i :enabledCheckers) { + checkerMgr.setCurrentCheckName(CheckName(i->FullName)); + i->Initialize(checkerMgr); } } void CheckerRegistry::validateCheckerOptions(const AnalyzerOptions &opts, DiagnosticsEngine &diags) const { - for (auto &config : opts.Config) { + for (const auto &config : opts.Config) { size_t pos = config.getKey().find(':'); if (pos == StringRef::npos) continue; bool hasChecker = false; StringRef checkerName = config.getKey().substr(0, pos); - for (auto &checker : Checkers) { + for (const auto &checker : Checkers) { if (checker.FullName.startswith(checkerName) && (checker.FullName.size() == pos || checker.FullName[pos] == '.')) { hasChecker = true; break; } } - if (!hasChecker) { + if (!hasChecker) diags.Report(diag::err_unknown_analyzer_checker) << checkerName; - } } } @@ -141,7 +143,7 @@ void CheckerRegistry::printHelp(raw_ostream &out, // FIXME: Alphabetical sort puts 'experimental' in the middle. // Would it be better to name it '~experimental' or something else // that's ASCIIbetically last? - std::sort(Checkers.begin(), Checkers.end(), checkerNameLT); + llvm::sort(Checkers.begin(), Checkers.end(), checkerNameLT); // FIXME: Print available packages. @@ -149,28 +151,26 @@ void CheckerRegistry::printHelp(raw_ostream &out, // Find the maximum option length. size_t optionFieldWidth = 0; - for (CheckerInfoList::const_iterator i = Checkers.begin(), e = Checkers.end(); - i != e; ++i) { + for (const auto &i : Checkers) { // Limit the amount of padding we are willing to give up for alignment. // Package.Name Description [Hidden] - size_t nameLength = i->FullName.size(); + size_t nameLength = i.FullName.size(); if (nameLength <= maxNameChars) optionFieldWidth = std::max(optionFieldWidth, nameLength); } const size_t initialPad = 2; - for (CheckerInfoList::const_iterator i = Checkers.begin(), e = Checkers.end(); - i != e; ++i) { - out.indent(initialPad) << i->FullName; + for (const auto &i : Checkers) { + out.indent(initialPad) << i.FullName; - int pad = optionFieldWidth - i->FullName.size(); + int pad = optionFieldWidth - i.FullName.size(); // Break on long option names. if (pad < 0) { out << '\n'; pad = optionFieldWidth + initialPad; } - out.indent(pad + 2) << i->Desc; + out.indent(pad + 2) << i.Desc; out << '\n'; } @@ -178,19 +178,13 @@ void CheckerRegistry::printHelp(raw_ostream &out, void CheckerRegistry::printList( raw_ostream &out, SmallVectorImpl<CheckerOptInfo> &opts) const { - std::sort(Checkers.begin(), Checkers.end(), checkerNameLT); + llvm::sort(Checkers.begin(), Checkers.end(), checkerNameLT); // Collect checkers enabled by the options. CheckerInfoSet enabledCheckers; - for (SmallVectorImpl<CheckerOptInfo>::iterator i = opts.begin(), - e = opts.end(); - i != e; ++i) { - collectCheckers(Checkers, Packages, *i, enabledCheckers); - } + for (auto &i : opts) + collectCheckers(Checkers, Packages, i, enabledCheckers); - for (CheckerInfoSet::const_iterator i = enabledCheckers.begin(), - e = enabledCheckers.end(); - i != e; ++i) { - out << (*i)->FullName << '\n'; - } + for (const auto *i : enabledCheckers) + out << i->FullName << '\n'; } |