[Stats] Reduce layering violations in FrontendStatsTracer.

This commit is contained in:
Graydon Hoare
2018-01-30 01:32:12 -08:00
parent d39dc43cae
commit 9334779f33
7 changed files with 196 additions and 109 deletions

View File

@@ -5658,3 +5658,37 @@ void Decl::setClangNode(ClangNode Node) {
}
*(ptr - 1) = Node.getOpaqueValue();
}
// See swift/Basic/Statistic.h for declaration: this enables tracing Decls, is
// defined here to avoid too much layering violation / circular linkage
// dependency.
struct DeclTraceFormatter : public UnifiedStatsReporter::TraceFormatter {
void traceName(const void *Entity, raw_ostream &OS) const {
if (!Entity)
return;
const Decl *D = static_cast<const Decl *>(Entity);
if (auto const *VD = dyn_cast<const ValueDecl>(D)) {
VD->getFullName().print(OS, false);
}
}
void traceLoc(const void *Entity, SourceManager *SM,
clang::SourceManager *CSM, raw_ostream &OS) const {
if (!Entity)
return;
const Decl *D = static_cast<const Decl *>(Entity);
D->getSourceRange().print(OS, *SM, false);
}
};
static DeclTraceFormatter TF;
UnifiedStatsReporter::FrontendStatsTracer
UnifiedStatsReporter::getStatsTracer(StringRef EventName, const Decl *D) {
if (LastTracedFrontendCounters)
// Return live tracer object.
return FrontendStatsTracer(EventName, D, &TF, this);
else
// Return inert tracer object.
return FrontendStatsTracer();
}