[analyzer] Add dumps to CheckerRegistry

This commit is contained in:
Kirstóf Umann 2020-05-31 21:22:35 +02:00
parent c15d5d12c6
commit 77e1181df4
2 changed files with 71 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
#include <vector>
@ -133,6 +134,9 @@ public:
DevelopmentStatus == "released") &&
"Invalid development status!");
}
LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
};
using CmdLineOptionList = llvm::SmallVector<CmdLineOption, 0>;
@ -189,6 +193,9 @@ public:
// Used for lower_bound.
explicit CheckerInfo(StringRef FullName) : FullName(FullName) {}
LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
};
using StateFromCmdLine = CheckerInfo::StateFromCmdLine;
@ -206,6 +213,9 @@ public:
}
explicit PackageInfo(StringRef FullName) : FullName(FullName) {}
LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
};
using PackageInfoList = llvm::SmallVector<PackageInfo, 0>;

View File

@ -27,6 +27,10 @@ using namespace clang;
using namespace ento;
using llvm::sys::DynamicLibrary;
//===----------------------------------------------------------------------===//
// Utilities.
//===----------------------------------------------------------------------===//
using RegisterCheckersFn = void (*)(CheckerRegistry &);
static bool isCompatibleAPIVersion(const char *VersionString) {
@ -86,6 +90,63 @@ static bool isInPackage(const CheckerRegistry::CheckerInfo &Checker,
return false;
}
//===----------------------------------------------------------------------===//
// Methods of CmdLineOption, PackageInfo and CheckerInfo.
//===----------------------------------------------------------------------===//
LLVM_DUMP_METHOD void
CheckerRegistry::CmdLineOption::dumpToStream(llvm::raw_ostream &Out) const {
// The description can be just checked in Checkers.inc, the point here is to
// debug whether we succeeded in parsing it.
Out << OptionName << " (" << OptionType << ", "
<< (IsHidden ? "hidden, " : "") << DevelopmentStatus << ") default: \""
<< DefaultValStr;
}
static StringRef toString(CheckerRegistry::StateFromCmdLine Kind) {
switch (Kind) {
case CheckerRegistry::StateFromCmdLine::State_Disabled:
return "Disabled";
case CheckerRegistry::StateFromCmdLine::State_Enabled:
return "Enabled";
case CheckerRegistry::StateFromCmdLine::State_Unspecified:
return "Unspecified";
}
}
LLVM_DUMP_METHOD void
CheckerRegistry::CheckerInfo::dumpToStream(llvm::raw_ostream &Out) const {
// The description can be just checked in Checkers.inc, the point here is to
// debug whether we succeeded in parsing it. Same with documentation uri.
Out << FullName << " (" << toString(State) << (IsHidden ? ", hidden" : "")
<< ")\n";
Out << " Options:\n";
for (const CmdLineOption &Option : CmdLineOptions) {
Out << " ";
Option.dumpToStream(Out);
Out << '\n';
}
Out << " Dependencies:\n";
for (const CheckerInfo *Dependency : Dependencies) {
Out << " " << Dependency->FullName << '\n';
}
}
LLVM_DUMP_METHOD void
CheckerRegistry::PackageInfo::dumpToStream(llvm::raw_ostream &Out) const {
Out << FullName << "\n";
Out << " Options:\n";
for (const CmdLineOption &Option : CmdLineOptions) {
Out << " ";
Option.dumpToStream(Out);
Out << '\n';
}
}
//===----------------------------------------------------------------------===//
// Methods of CheckerRegistry.
//===----------------------------------------------------------------------===//
CheckerRegistry::CheckerInfoListRange
CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
auto It = binaryFind(Checkers, CmdLineArg);