13#include "llvm/ADT/STLExtras.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/FileSystem.h"
18#include "llvm/Support/ManagedStatic.h"
19#include "llvm/Support/raw_ostream.h"
27 std::vector<BoolEPStat *> BoolStats;
28 std::vector<CounterEPStat *> CounterStats;
29 std::vector<UnsignedMaxEPStat *> UnsignedMaxStats;
30 std::vector<UnsignedEPStat *> UnsignedStats;
32 bool IsLocked =
false;
35 const Decl *EntryPoint;
36 std::vector<bool> BoolStatValues;
37 std::vector<unsigned> UnsignedStatValues;
39 void dumpAsCSV(llvm::raw_ostream &
OS)
const;
42 std::vector<Snapshot> Snapshots;
43 std::string EscapedCPPFileName;
50template <
typename Callback>
void enumerateStatVectors(
const Callback &Fn) {
62 constexpr std::array AllowedSpecialChars = {
63 '+',
'-',
'_',
'=',
':',
'(',
')',
'@',
'!',
'~',
64 '$',
'%',
'^',
'&',
'*',
'\'',
';',
'<',
'>',
'/'};
65 for (
unsigned char C : M->
name()) {
66 if (!std::isalnum(
C) && !llvm::is_contained(AllowedSpecialChars,
C)) {
67 llvm::errs() <<
"Stat name \"" << M->
name() <<
"\" contains character '"
68 <<
C <<
"' (" <<
static_cast<int>(
C)
69 <<
") that is not allowed.";
70 assert(
false &&
"The Stat name contains unallowed character");
77 return L->
name() < R->name();
80 [CmpByNames](
auto &Stats) { llvm::sort(Stats, CmpByNames); });
82 [](
const auto &Stats) { llvm::for_each(Stats,
checkStatName); });
85 llvm::printEscapedString(CPPFileName,
OS);
88[[maybe_unused]]
static bool isRegistered(llvm::StringLiteral Name) {
89 auto ByName = [Name](
const EntryPointStat *M) {
return M->name() == Name; };
91 enumerateStatVectors([ByName, &Result](
const auto &Stats) {
92 Result = Result || llvm::any_of(Stats, ByName);
110 : EntryPointStat(Name) {
117 : EntryPointStat(Name) {
124 std::vector<unsigned> Result;
129 Result.push_back(M->value());
133 Result.push_back(M->value());
137 Result.push_back(M->value());
144 std::vector<llvm::StringLiteral> Ret;
146 enumerateStatVectors([GetName, &Ret](
const auto &Stats) {
147 transform(Stats, std::back_inserter(Ret), GetName);
155 assert(
false &&
"This should never fail");
158 return llvm::toStringRef(Buf).str();
161void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &
OS)
const {
163 llvm::printEscapedString(
getUSR(EntryPoint),
OS);
166 llvm::printEscapedString(
169 auto PrintAsBool = [&
OS](
bool B) {
OS << (B ?
"true" :
"false"); };
170 llvm::interleave(BoolStatValues,
OS, PrintAsBool,
",");
171 OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ?
"" :
",");
172 llvm::interleave(UnsignedStatValues,
OS, [&
OS](
unsigned U) {
OS << U; },
",");
176 std::vector<bool> Result;
179 Result.push_back(M->value());
189 {EntryPoint, std::move(BoolValues), std::move(UnsignedValues)});
194 llvm::raw_fd_ostream
File(
FileName, EC, llvm::sys::fs::OF_Text);
201 OS <<
"USR,File,DebugName,";
205 std::vector<std::string> Rows;
209 llvm::raw_string_ostream RowOs(Row);
210 Snapshot.dumpAsCSV(RowOs);
212 Rows.push_back(RowOs.str());
215 for (
const auto &Row : Rows) {
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static void checkStatName(const EntryPointStat *M)
static std::vector< unsigned > consumeUnsignedStats()
static llvm::ManagedStatic< Registry > StatsRegistry
static std::vector< llvm::StringLiteral > getStatNames()
static bool isRegistered(llvm::StringLiteral Name)
static std::vector< bool > consumeBoolStats()
static std::string getUSR(const Decl *D)
static std::string getFunctionName(const Decl *D)
Decl - This represents one declaration (or definition), e.g.
BoolEPStat(llvm::StringLiteral Name)
CounterEPStat(llvm::StringLiteral Name)
static void lockRegistry(llvm::StringRef CPPFileName)
static void dumpStatsAsCSV(llvm::raw_ostream &OS)
static void takeSnapshot(const Decl *EntryPoint)
llvm::StringLiteral name() const
EntryPointStat(llvm::StringLiteral Name)
UnsignedEPStat(llvm::StringLiteral Name)
UnsignedMaxEPStat(llvm::StringLiteral Name)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.