Skip to content

Commit

Permalink
[analyzer] Add dumps to CheckerRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
Szelethus committed May 31, 2020
1 parent c15d5d1 commit 77e1181
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -133,6 +134,9 @@ class CheckerRegistry {
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>;
Expand Down Expand Up @@ -189,6 +193,9 @@ class CheckerRegistry {

// 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;
Expand All @@ -206,6 +213,9 @@ class CheckerRegistry {
}

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>;
Expand Down
61 changes: 61 additions & 0 deletions clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 77e1181

Please sign in to comment.