summaryrefslogtreecommitdiff
path: root/AST/Stmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-25 01:42:24 +0000
committerChris Lattner <sabre@nondot.org>2007-08-25 01:42:24 +0000
commit63381358122e26284a49cf018325505d50cada87 (patch)
tree51c33a01518a31e8f72757c942d97d82c0a9f0d0 /AST/Stmt.cpp
parentf1120de60490560d22328bcc83045b77ab46dcde (diff)
downloadclang-63381358122e26284a49cf018325505d50cada87.tar.gz
rename sNames -> StmtClassInfo. Make lookups constant time.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41390 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'AST/Stmt.cpp')
-rw-r--r--AST/Stmt.cpp57
1 files changed, 33 insertions, 24 deletions
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index 28370342b1..58d0eb755c 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -18,56 +18,65 @@
using namespace clang;
static struct StmtClassNameTable {
- int enumValue;
- const char *className;
- unsigned counter;
- unsigned size;
-} sNames[] = {
-#define STMT(N, CLASS, PARENT) { N, #CLASS, 0, sizeof(CLASS) },
+ const char *Name;
+ unsigned Counter;
+ unsigned Size;
+} StmtClassInfo[Stmt::lastExprConstant];
+
+static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
+ static bool Initialized = false;
+ if (Initialized)
+ return StmtClassInfo[E];
+
+ // Intialize the table on the first use.
+ Initialized = true;
+#define STMT(N, CLASS, PARENT) \
+ StmtClassInfo[N].Name = #CLASS; \
+ StmtClassInfo[N].Size = sizeof(CLASS);
#include "clang/AST/StmtNodes.def"
- { 0, 0, 0, 0 }
-};
+ return StmtClassInfo[E];
+}
+
const char *Stmt::getStmtClassName() const {
- for (int i = 0; sNames[i].className; i++) {
- if (sClass == sNames[i].enumValue)
- return sNames[i].className;
- }
- return 0; // should never happen....
+ return getStmtInfoTableEntry(sClass).Name;
}
void Stmt::PrintStats() {
+ // Ensure the table is primed.
+ getStmtInfoTableEntry(Stmt::NullStmtClass);
+
unsigned sum = 0;
fprintf(stderr, "*** Stmt/Expr Stats:\n");
- for (int i = 0; sNames[i].className; i++) {
- sum += sNames[i].counter;
+ for (int i = 0; i != Stmt::lastExprConstant; i++) {
+ if (StmtClassInfo[i].Name == 0) continue;
+ sum += StmtClassInfo[i].Counter;
}
fprintf(stderr, " %d stmts/exprs total.\n", sum);
sum = 0;
- for (int i = 0; sNames[i].className; i++) {
+ for (int i = 0; i != Stmt::lastExprConstant; i++) {
+ if (StmtClassInfo[i].Name == 0) continue;
fprintf(stderr, " %d %s, %d each (%d bytes)\n",
- sNames[i].counter, sNames[i].className, sNames[i].size, sNames[i].counter*sNames[i].size);
- sum += sNames[i].counter*sNames[i].size;
+ StmtClassInfo[i].Counter, StmtClassInfo[i].Name,
+ StmtClassInfo[i].Size,
+ StmtClassInfo[i].Counter*StmtClassInfo[i].Size);
+ sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
}
fprintf(stderr, "Total bytes = %d\n", sum);
}
void Stmt::addStmtClass(StmtClass s) {
- for (int i = 0; sNames[i].className; i++) {
- if (s == sNames[i].enumValue)
- sNames[i].counter++;
- }
+ ++getStmtInfoTableEntry(s).Counter;
}
static bool StatSwitch = false;
bool Stmt::CollectingStats(bool enable) {
if (enable) StatSwitch = true;
- return StatSwitch;
+ return StatSwitch;
}
-
const char *LabelStmt::getName() const {
return getID()->getName();
}