]> granicus.if.org Git - clang/commitdiff
AST/stats: Don't effectively use an out-of-line function to return a static
authorDaniel Dunbar <daniel@zuster.org>
Mon, 5 Mar 2012 21:42:49 +0000 (21:42 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 5 Mar 2012 21:42:49 +0000 (21:42 +0000)
bool. Ugh.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152062 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
include/clang/AST/Stmt.h
lib/AST/DeclBase.cpp
lib/AST/Stmt.cpp
lib/Parse/ParseAST.cpp

index 72f82aa9e383082ff52af7b3afcf4c8555a23bb9..4ed4b1aea9869e1710c1280ac50dd63810d067bb 100644 (file)
@@ -260,6 +260,9 @@ private:
   /// are regarded as "referenced" but not "used".
   unsigned Referenced : 1;
 
+  /// \brief Whether statistic collection is enabled.
+  static bool StatisticsEnabled;
+
 protected:
   /// Access - Used by C++ decls for the access specifier.
   // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
@@ -304,7 +307,7 @@ protected:
       IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
       HasCachedLinkage(0)
   {
-    if (Decl::CollectingStats()) add(DK);
+    if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
@@ -314,7 +317,7 @@ protected:
       IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
       HasCachedLinkage(0)
   {
-    if (Decl::CollectingStats()) add(DK);
+    if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -761,7 +764,7 @@ public:
 
   // global temp stats (until we have a per-module visitor)
   static void add(Kind k);
-  static bool CollectingStats(bool Enable = false);
+  static void EnableStatistics();
   static void PrintStats();
 
   /// isTemplateParameter - Determines whether this declaration is a
index c81798ccd2fb993a7f8fb2b36c573341e3c73134..4c92520a76a82229e8ee8d5c90336f90fa41e6c1 100644 (file)
@@ -319,17 +319,21 @@ public:
   /// de-serialization).
   struct EmptyShell { };
 
+private:
+  /// \brief Whether statistic collection is enabled.
+  static bool StatisticsEnabled;
+
 protected:
   /// \brief Construct an empty statement.
   explicit Stmt(StmtClass SC, EmptyShell) {
     StmtBits.sClass = SC;
-    if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
+    if (StatisticsEnabled) Stmt::addStmtClass(SC);
   }
 
 public:
   Stmt(StmtClass SC) {
     StmtBits.sClass = SC;
-    if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
+    if (StatisticsEnabled) Stmt::addStmtClass(SC);
   }
 
   StmtClass getStmtClass() const {
@@ -347,7 +351,7 @@ public:
 
   // global temp stats (until we have a per-module visitor)
   static void addStmtClass(const StmtClass s);
-  static bool CollectingStats(bool Enable = false);
+  static void EnableStatistics();
   static void PrintStats();
 
   /// dump - This does a local dump of the specified AST fragment.  It dumps the
index dbb0b6bfa4c6396e63336fc0a055e8d49e0dc3b5..10e612514fd0fa64bcd657a56e02315ba7ffea92 100644 (file)
@@ -39,8 +39,6 @@ using namespace clang;
 #define ABSTRACT_DECL(DECL)
 #include "clang/AST/DeclNodes.inc"
 
-static bool StatSwitch = false;
-
 void *Decl::AllocateDeserializedDecl(const ASTContext &Context, 
                                      unsigned ID,
                                      unsigned Size) {
@@ -88,9 +86,9 @@ const char *DeclContext::getDeclKindName() const {
   }
 }
 
-bool Decl::CollectingStats(bool Enable) {
-  if (Enable) StatSwitch = true;
-  return StatSwitch;
+bool Decl::StatisticsEnabled = false;
+void Decl::EnableStatistics() {
+  StatisticsEnabled = true;
 }
 
 void Decl::PrintStats() {
index 8b2e35376bde0760c85b8ef7a9d139036c0f6465..0deaaa83bada479e45515c6557a6770a89cb1cdd 100644 (file)
@@ -78,11 +78,9 @@ void Stmt::addStmtClass(StmtClass s) {
   ++getStmtInfoTableEntry(s).Counter;
 }
 
-static bool StatSwitch = false;
-
-bool Stmt::CollectingStats(bool Enable) {
-  if (Enable) StatSwitch = true;
-  return StatSwitch;
+bool Stmt::StatisticsEnabled = false;
+void Stmt::EnableStatistics() {
+  StatisticsEnabled = true;
 }
 
 Stmt *Stmt::IgnoreImplicit() {
index 7e087ef7ea477b9ebe55cb552b1ba71664c35c11..236689184df77e623a000024a48c73ed28e4b081 100644 (file)
@@ -53,8 +53,8 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
 void clang::ParseAST(Sema &S, bool PrintStats) {
   // Collect global stats on Decls/Stmts (until we have a module streamer).
   if (PrintStats) {
-    Decl::CollectingStats(true);
-    Stmt::CollectingStats(true);
+    Decl::EnableStatistics();
+    Stmt::EnableStatistics();
   }
 
   // Also turn on collection of stats inside of the Sema object.