blob: d56a02641ae60bbbaadc9e5ef78cefb296254ce0 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Stmt.h"
15#include "clang/AST/ExprCXX.h"
16#include "clang/AST/StmtVisitor.h"
17#include "clang/Lex/IdentifierTable.h"
18using namespace clang;
19
Chris Lattner4b009652007-07-25 00:24:17 +000020static struct StmtClassNameTable {
21 int enumValue;
22 const char *className;
23 unsigned counter;
24 unsigned size;
25} sNames[] = {
26#define STMT(N, CLASS, PARENT) { N, #CLASS, 0, sizeof(CLASS) },
27#include "clang/AST/StmtNodes.def"
28 { 0, 0, 0, 0 }
29};
30
31const char *Stmt::getStmtClassName() const {
32 for (int i = 0; sNames[i].className; i++) {
33 if (sClass == sNames[i].enumValue)
34 return sNames[i].className;
35 }
36 return 0; // should never happen....
37}
38
39void Stmt::PrintStats() {
40 unsigned sum = 0;
41 fprintf(stderr, "*** Stmt/Expr Stats:\n");
42 for (int i = 0; sNames[i].className; i++) {
43 sum += sNames[i].counter;
44 }
45 fprintf(stderr, " %d stmts/exprs total.\n", sum);
46 sum = 0;
47 for (int i = 0; sNames[i].className; i++) {
48 fprintf(stderr, " %d %s, %d each (%d bytes)\n",
49 sNames[i].counter, sNames[i].className, sNames[i].size, sNames[i].counter*sNames[i].size);
50 sum += sNames[i].counter*sNames[i].size;
51 }
52 fprintf(stderr, "Total bytes = %d\n", sum);
53}
54
55void Stmt::addStmtClass(StmtClass s) {
56 for (int i = 0; sNames[i].className; i++) {
57 if (s == sNames[i].enumValue)
58 sNames[i].counter++;
59 }
60}
61
62static bool StatSwitch = false;
63
64bool Stmt::CollectingStats(bool enable) {
65 if (enable) StatSwitch = true;
66 return StatSwitch;
67}
68
69
70
71const char *LabelStmt::getName() const {
72 return getID()->getName();
73}
74