blob: e43f03c404a92e4b56fda4c9891f491ebd524ded [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +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
20// Implement all the AST node visit methods using the StmtNodes.def database.
21#define STMT(N, CLASS, PARENT) \
22void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
23
24STMT(0, Stmt, )
25#include "clang/AST/StmtNodes.def"
26
27static struct StmtClassNameTable {
28 int enumValue;
29 const char *className;
30 unsigned counter;
31 unsigned size;
32} sNames[] = {
33#define STMT(N, CLASS, PARENT) { N, #CLASS, 0, sizeof(CLASS) },
34#include "clang/AST/StmtNodes.def"
35 { 0, 0, 0, 0 }
36};
37
38const char *Stmt::getStmtClassName() const {
39 for (int i = 0; sNames[i].className; i++) {
40 if (sClass == sNames[i].enumValue)
41 return sNames[i].className;
42 }
43 return 0; // should never happen....
44}
45
46void Stmt::PrintStats() {
47 unsigned sum = 0;
48 fprintf(stderr, "*** Stmt/Expr Stats:\n");
49 for (int i = 0; sNames[i].className; i++) {
50 sum += sNames[i].counter;
51 }
52 fprintf(stderr, " %d stmts/exprs total.\n", sum);
53 sum = 0;
54 for (int i = 0; sNames[i].className; i++) {
55 fprintf(stderr, " %d %s, %d each (%d bytes)\n",
56 sNames[i].counter, sNames[i].className, sNames[i].size, sNames[i].counter*sNames[i].size);
57 sum += sNames[i].counter*sNames[i].size;
58 }
59 fprintf(stderr, "Total bytes = %d\n", sum);
60}
61
62void Stmt::addStmtClass(StmtClass s) {
63 for (int i = 0; sNames[i].className; i++) {
64 if (s == sNames[i].enumValue)
65 sNames[i].counter++;
66 }
67}
68
69static bool StatSwitch = false;
70
71bool Stmt::CollectingStats(bool enable) {
72 if (enable) StatSwitch = true;
73 return StatSwitch;
74}
75
76
77
78const char *LabelStmt::getName() const {
79 return getID()->getName();
80}
81