Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 02892a6

Browse files
committed
AST/stats: Don't effectively use an out-of-line function to return a static
bool. Ugh. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152062 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7034fb6 commit 02892a6

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

include/clang/AST/DeclBase.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class Decl {
260260
/// are regarded as "referenced" but not "used".
261261
unsigned Referenced : 1;
262262

263+
/// \brief Whether statistic collection is enabled.
264+
static bool StatisticsEnabled;
265+
263266
protected:
264267
/// Access - Used by C++ decls for the access specifier.
265268
// NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
@@ -304,7 +307,7 @@ class Decl {
304307
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
305308
HasCachedLinkage(0)
306309
{
307-
if (Decl::CollectingStats()) add(DK);
310+
if (StatisticsEnabled) add(DK);
308311
}
309312

310313
Decl(Kind DK, EmptyShell Empty)
@@ -314,7 +317,7 @@ class Decl {
314317
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
315318
HasCachedLinkage(0)
316319
{
317-
if (Decl::CollectingStats()) add(DK);
320+
if (StatisticsEnabled) add(DK);
318321
}
319322

320323
virtual ~Decl();
@@ -761,7 +764,7 @@ class Decl {
761764

762765
// global temp stats (until we have a per-module visitor)
763766
static void add(Kind k);
764-
static bool CollectingStats(bool Enable = false);
767+
static void EnableStatistics();
765768
static void PrintStats();
766769

767770
/// isTemplateParameter - Determines whether this declaration is a

include/clang/AST/Stmt.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,21 @@ class Stmt {
319319
/// de-serialization).
320320
struct EmptyShell { };
321321

322+
private:
323+
/// \brief Whether statistic collection is enabled.
324+
static bool StatisticsEnabled;
325+
322326
protected:
323327
/// \brief Construct an empty statement.
324328
explicit Stmt(StmtClass SC, EmptyShell) {
325329
StmtBits.sClass = SC;
326-
if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
330+
if (StatisticsEnabled) Stmt::addStmtClass(SC);
327331
}
328332

329333
public:
330334
Stmt(StmtClass SC) {
331335
StmtBits.sClass = SC;
332-
if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
336+
if (StatisticsEnabled) Stmt::addStmtClass(SC);
333337
}
334338

335339
StmtClass getStmtClass() const {
@@ -347,7 +351,7 @@ class Stmt {
347351

348352
// global temp stats (until we have a per-module visitor)
349353
static void addStmtClass(const StmtClass s);
350-
static bool CollectingStats(bool Enable = false);
354+
static void EnableStatistics();
351355
static void PrintStats();
352356

353357
/// dump - This does a local dump of the specified AST fragment. It dumps the

lib/AST/DeclBase.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ using namespace clang;
3939
#define ABSTRACT_DECL(DECL)
4040
#include "clang/AST/DeclNodes.inc"
4141

42-
static bool StatSwitch = false;
43-
4442
void *Decl::AllocateDeserializedDecl(const ASTContext &Context,
4543
unsigned ID,
4644
unsigned Size) {
@@ -88,9 +86,9 @@ const char *DeclContext::getDeclKindName() const {
8886
}
8987
}
9088

91-
bool Decl::CollectingStats(bool Enable) {
92-
if (Enable) StatSwitch = true;
93-
return StatSwitch;
89+
bool Decl::StatisticsEnabled = false;
90+
void Decl::EnableStatistics() {
91+
StatisticsEnabled = true;
9492
}
9593

9694
void Decl::PrintStats() {

lib/AST/Stmt.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ void Stmt::addStmtClass(StmtClass s) {
7878
++getStmtInfoTableEntry(s).Counter;
7979
}
8080

81-
static bool StatSwitch = false;
82-
83-
bool Stmt::CollectingStats(bool Enable) {
84-
if (Enable) StatSwitch = true;
85-
return StatSwitch;
81+
bool Stmt::StatisticsEnabled = false;
82+
void Stmt::EnableStatistics() {
83+
StatisticsEnabled = true;
8684
}
8785

8886
Stmt *Stmt::IgnoreImplicit() {

lib/Parse/ParseAST.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
5353
void clang::ParseAST(Sema &S, bool PrintStats) {
5454
// Collect global stats on Decls/Stmts (until we have a module streamer).
5555
if (PrintStats) {
56-
Decl::CollectingStats(true);
57-
Stmt::CollectingStats(true);
56+
Decl::EnableStatistics();
57+
Stmt::EnableStatistics();
5858
}
5959

6060
// Also turn on collection of stats inside of the Sema object.

0 commit comments

Comments
 (0)