blob: d56a02641ae60bbbaadc9e5ef78cefb296254ce0 [file] [log] [blame]
Chris Lattnerf42cce72006-10-25 04:09:21 +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"
Chris Lattner29375652006-12-04 18:06:35 +000015#include "clang/AST/ExprCXX.h"
Chris Lattner5e9a8782006-11-04 06:21:51 +000016#include "clang/AST/StmtVisitor.h"
Chris Lattnereefa10e2007-05-28 06:56:27 +000017#include "clang/Lex/IdentifierTable.h"
Chris Lattnerf42cce72006-10-25 04:09:21 +000018using namespace clang;
19
Steve Narofff84d11f2007-05-23 21:48:04 +000020static struct StmtClassNameTable {
Steve Narofff1e53692007-03-23 22:27:02 +000021 int enumValue;
22 const char *className;
Steve Narofff84d11f2007-05-23 21:48:04 +000023 unsigned counter;
24 unsigned size;
Steve Narofff1e53692007-03-23 22:27:02 +000025} sNames[] = {
Steve Narofff84d11f2007-05-23 21:48:04 +000026#define STMT(N, CLASS, PARENT) { N, #CLASS, 0, sizeof(CLASS) },
Steve Narofff1e53692007-03-23 22:27:02 +000027#include "clang/AST/StmtNodes.def"
Steve Narofff84d11f2007-05-23 21:48:04 +000028 { 0, 0, 0, 0 }
Steve Narofff1e53692007-03-23 22:27:02 +000029};
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}
Steve Narofff84d11f2007-05-23 21:48:04 +000038
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
Chris Lattnereefa10e2007-05-28 06:56:27 +000070
71const char *LabelStmt::getName() const {
72 return getID()->getName();
73}
74