blob: 0abbe47bf455a9fbf0ceafcc09092bb7aabd2408 [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 llvm;
19using namespace clang;
20
Chris Lattner76af8442006-11-04 20:54:18 +000021// Implement all the AST node visit methods using the StmtNodes.def database.
Steve Naroff7f890eb2007-02-27 02:53:10 +000022#define STMT(N, CLASS, PARENT) \
Chris Lattner9ea960a2006-11-04 07:16:04 +000023void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
Chris Lattnere5cca062006-10-25 04:29:46 +000024
Steve Naroff7f890eb2007-02-27 02:53:10 +000025STMT(0, Stmt, )
Chris Lattner76af8442006-11-04 20:54:18 +000026#include "clang/AST/StmtNodes.def"
Steve Narofff1e53692007-03-23 22:27:02 +000027
Steve Narofff84d11f2007-05-23 21:48:04 +000028static struct StmtClassNameTable {
Steve Narofff1e53692007-03-23 22:27:02 +000029 int enumValue;
30 const char *className;
Steve Narofff84d11f2007-05-23 21:48:04 +000031 unsigned counter;
32 unsigned size;
Steve Narofff1e53692007-03-23 22:27:02 +000033} sNames[] = {
Steve Narofff84d11f2007-05-23 21:48:04 +000034#define STMT(N, CLASS, PARENT) { N, #CLASS, 0, sizeof(CLASS) },
Steve Narofff1e53692007-03-23 22:27:02 +000035#include "clang/AST/StmtNodes.def"
Steve Narofff84d11f2007-05-23 21:48:04 +000036 { 0, 0, 0, 0 }
Steve Narofff1e53692007-03-23 22:27:02 +000037};
38
39const char *Stmt::getStmtClassName() const {
40 for (int i = 0; sNames[i].className; i++) {
41 if (sClass == sNames[i].enumValue)
42 return sNames[i].className;
43 }
44 return 0; // should never happen....
45}
Steve Narofff84d11f2007-05-23 21:48:04 +000046
47void Stmt::PrintStats() {
48 unsigned sum = 0;
49 fprintf(stderr, "*** Stmt/Expr Stats:\n");
50 for (int i = 0; sNames[i].className; i++) {
51 sum += sNames[i].counter;
52 }
53 fprintf(stderr, " %d stmts/exprs total.\n", sum);
54 sum = 0;
55 for (int i = 0; sNames[i].className; i++) {
56 fprintf(stderr, " %d %s, %d each (%d bytes)\n",
57 sNames[i].counter, sNames[i].className, sNames[i].size, sNames[i].counter*sNames[i].size);
58 sum += sNames[i].counter*sNames[i].size;
59 }
60 fprintf(stderr, "Total bytes = %d\n", sum);
61}
62
63void Stmt::addStmtClass(StmtClass s) {
64 for (int i = 0; sNames[i].className; i++) {
65 if (s == sNames[i].enumValue)
66 sNames[i].counter++;
67 }
68}
69
70static bool StatSwitch = false;
71
72bool Stmt::CollectingStats(bool enable) {
73 if (enable) StatSwitch = true;
74 return StatSwitch;
75}
76
77
Chris Lattnereefa10e2007-05-28 06:56:27 +000078
79const char *LabelStmt::getName() const {
80 return getID()->getName();
81}
82