r352279 - [analyzer][NFC] Supply CheckerRegistry with AnalyzerOptions
Kristof Umann via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 26 07:59:22 PST 2019
Author: szelethus
Date: Sat Jan 26 07:59:21 2019
New Revision: 352279
URL: http://llvm.org/viewvc/llvm-project?rev=352279&view=rev
Log:
[analyzer][NFC] Supply CheckerRegistry with AnalyzerOptions
Since pretty much all methods of CheckerRegistry has AnalyzerOptions as an
argument, it makes sense to just simply require it in it's constructor.
Differential Revision: https://reviews.llvm.org/D56988
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h
cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=352279&r1=352278&r2=352279&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h Sat Jan 26 07:59:21 2019
@@ -82,7 +82,7 @@ namespace ento {
class CheckerRegistry {
public:
CheckerRegistry(ArrayRef<std::string> plugins, DiagnosticsEngine &diags,
- const LangOptions &LangOpts);
+ AnalyzerOptions &AnOpts, const LangOptions &LangOpts);
/// Initialization functions perform any necessary setup for a checker.
/// They should include a call to CheckerManager::registerChecker.
@@ -137,24 +137,24 @@ public:
/// all checkers specified by the given CheckerOptInfo list. The order of this
/// list is significant; later options can be used to reverse earlier ones.
/// This can be used to exclude certain checkers in an included package.
- void initializeManager(CheckerManager &mgr,
- const AnalyzerOptions &Opts) const;
+ void initializeManager(CheckerManager &mgr) const;
/// Check if every option corresponds to a specific checker or package.
- void validateCheckerOptions(const AnalyzerOptions &opts) const;
+ void validateCheckerOptions() const;
/// Prints the name and description of all checkers in this registry.
/// This output is not intended to be machine-parseable.
void printHelp(raw_ostream &out, size_t maxNameChars = 30) const;
- void printList(raw_ostream &out, const AnalyzerOptions &opts) const;
+ void printList(raw_ostream &out) const;
private:
- CheckerInfoSet getEnabledCheckers(const AnalyzerOptions &Opts) const;
+ CheckerInfoSet getEnabledCheckers() const;
mutable CheckerInfoList Checkers;
mutable llvm::StringMap<size_t> Packages;
DiagnosticsEngine &Diags;
+ AnalyzerOptions &AnOpts;
const LangOptions &LangOpts;
};
Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h?rev=352279&r1=352278&r2=352279&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h Sat Jan 26 07:59:21 2019
@@ -51,10 +51,13 @@ private:
llvm::StringMap<Stmt *> &Bodies;
};
-void printCheckerHelp(raw_ostream &OS, ArrayRef<std::string> plugins,
- DiagnosticsEngine &diags, const LangOptions &LangOpts);
+void printCheckerHelp(raw_ostream &OS,
+ ArrayRef<std::string> plugins,
+ AnalyzerOptions &opts,
+ DiagnosticsEngine &diags,
+ const LangOptions &LangOpts);
void printEnabledCheckerList(raw_ostream &OS, ArrayRef<std::string> plugins,
- const AnalyzerOptions &opts,
+ AnalyzerOptions &opts,
DiagnosticsEngine &diags,
const LangOptions &LangOpts);
void printAnalyzerConfigList(raw_ostream &OS);
Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=352279&r1=352278&r2=352279&view=diff
==============================================================================
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Sat Jan 26 07:59:21 2019
@@ -237,8 +237,11 @@ bool ExecuteCompilerInvocation(CompilerI
// Honor -analyzer-checker-help.
// This should happen AFTER plugins have been loaded!
if (Clang->getAnalyzerOpts()->ShowCheckerHelp) {
- ento::printCheckerHelp(llvm::outs(), Clang->getFrontendOpts().Plugins,
- Clang->getDiagnostics(), Clang->getLangOpts());
+ ento::printCheckerHelp(llvm::outs(),
+ Clang->getFrontendOpts().Plugins,
+ *Clang->getAnalyzerOpts(),
+ Clang->getDiagnostics(),
+ Clang->getLangOpts());
return true;
}
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=352279&r1=352278&r2=352279&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Sat Jan 26 07:59:21 2019
@@ -33,35 +33,36 @@ std::unique_ptr<CheckerManager> ento::cr
DiagnosticsEngine &diags) {
auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
- CheckerRegistry allCheckers(plugins, diags, context.getLangOpts());
+ CheckerRegistry allCheckers(plugins, diags, opts, context.getLangOpts());
for (const auto &Fn : checkerRegistrationFns)
Fn(allCheckers);
- allCheckers.initializeManager(*checkerMgr, opts);
- allCheckers.validateCheckerOptions(opts);
+ allCheckers.initializeManager(*checkerMgr);
+ allCheckers.validateCheckerOptions();
checkerMgr->finishedCheckerRegistration();
return checkerMgr;
}
void ento::printCheckerHelp(raw_ostream &out, ArrayRef<std::string> plugins,
+ AnalyzerOptions &anopts,
DiagnosticsEngine &diags,
const LangOptions &langOpts) {
out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
out << "USAGE: -analyzer-checker <CHECKER or PACKAGE,...>\n\n";
- CheckerRegistry(plugins, diags, langOpts).printHelp(out);
+ CheckerRegistry(plugins, diags, anopts, langOpts).printHelp(out);
}
void ento::printEnabledCheckerList(raw_ostream &out,
ArrayRef<std::string> plugins,
- const AnalyzerOptions &opts,
+ AnalyzerOptions &anopts,
DiagnosticsEngine &diags,
const LangOptions &langOpts) {
out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
- CheckerRegistry(plugins, diags, langOpts).printList(out, opts);
+ CheckerRegistry(plugins, diags, anopts, langOpts).printList(out);
}
void ento::printAnalyzerConfigList(raw_ostream &out) {
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=352279&r1=352278&r2=352279&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Sat Jan 26 07:59:21 2019
@@ -40,8 +40,9 @@ static bool isCompatibleAPIVersion(const
CheckerRegistry::CheckerRegistry(ArrayRef<std::string> plugins,
DiagnosticsEngine &diags,
+ AnalyzerOptions &AnOpts,
const LangOptions &LangOpts)
- : Diags(diags), LangOpts(LangOpts) {
+ : Diags(diags), AnOpts(AnOpts), LangOpts(LangOpts) {
#define GET_CHECKERS
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI) \
@@ -106,8 +107,7 @@ static bool isInPackage(const CheckerReg
return false;
}
-CheckerRegistry::CheckerInfoSet CheckerRegistry::getEnabledCheckers(
- const AnalyzerOptions &Opts) const {
+CheckerRegistry::CheckerInfoSet CheckerRegistry::getEnabledCheckers() const {
assert(std::is_sorted(Checkers.begin(), Checkers.end(), checkerNameLT) &&
"In order to efficiently gather checkers, this function expects them "
@@ -116,7 +116,7 @@ CheckerRegistry::CheckerInfoSet CheckerR
CheckerInfoSet enabledCheckers;
const auto end = Checkers.cend();
- for (const std::pair<std::string, bool> &opt : Opts.CheckersControlList) {
+ for (const std::pair<std::string, bool> &opt : AnOpts.CheckersControlList) {
// Use a binary search to find the possible start of the package.
CheckerRegistry::CheckerInfo
packageInfo(nullptr, nullptr, opt.first, "", "");
@@ -167,13 +167,12 @@ void CheckerRegistry::addChecker(Initial
}
}
-void CheckerRegistry::initializeManager(CheckerManager &checkerMgr,
- const AnalyzerOptions &Opts) const {
+void CheckerRegistry::initializeManager(CheckerManager &checkerMgr) const {
// Sort checkers for efficient collection.
llvm::sort(Checkers, checkerNameLT);
// Collect checkers enabled by the options.
- CheckerInfoSet enabledCheckers = getEnabledCheckers(Opts);
+ CheckerInfoSet enabledCheckers = getEnabledCheckers();
// Initialize the CheckerManager with all enabled checkers.
for (const auto *i : enabledCheckers) {
@@ -182,9 +181,8 @@ void CheckerRegistry::initializeManager(
}
}
-void CheckerRegistry::validateCheckerOptions(
- const AnalyzerOptions &opts) const {
- for (const auto &config : opts.Config) {
+void CheckerRegistry::validateCheckerOptions() const {
+ for (const auto &config : AnOpts.Config) {
size_t pos = config.getKey().find(':');
if (pos == StringRef::npos)
continue;
@@ -241,13 +239,12 @@ void CheckerRegistry::printHelp(raw_ostr
}
}
-void CheckerRegistry::printList(raw_ostream &out,
- const AnalyzerOptions &opts) const {
+void CheckerRegistry::printList(raw_ostream &out) const {
// Sort checkers for efficient collection.
llvm::sort(Checkers, checkerNameLT);
// Collect checkers enabled by the options.
- CheckerInfoSet enabledCheckers = getEnabledCheckers(opts);
+ CheckerInfoSet enabledCheckers = getEnabledCheckers();
for (const auto *i : enabledCheckers)
out << i->FullName << '\n';
More information about the cfe-commits
mailing list