blob: 73aef8474275959c203465cb498cd62d80a1f25c [file] [log] [blame]
Chris Lattner6000dac2007-08-08 22:51:59 +00001//===--- StmtDumper.cpp - Dumping implementation for Stmt ASTs ------------===//
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::dump/Stmt::print methods, which dump out the
11// AST in a form that exposes type details and other fields.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/AST/StmtVisitor.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/ExprCXX.h"
18#include "clang/Lex/IdentifierTable.h"
Chris Lattnere300c872007-08-30 06:17:34 +000019#include "clang/Basic/SourceManager.h"
Chris Lattner6000dac2007-08-08 22:51:59 +000020#include "llvm/Support/Compiler.h"
21#include <cstdio>
22using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// StmtDumper Visitor
26//===----------------------------------------------------------------------===//
27
28namespace {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000029 class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
Chris Lattnere300c872007-08-30 06:17:34 +000030 SourceManager *SM;
Chris Lattner6000dac2007-08-08 22:51:59 +000031 FILE *F;
32 unsigned IndentLevel;
33
34 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
35 /// the first few levels of an AST. This keeps track of how many ast levels
36 /// are left.
37 unsigned MaxDepth;
Chris Lattnere300c872007-08-30 06:17:34 +000038
39 /// LastLocFilename/LastLocLine - Keep track of the last location we print
40 /// out so that we can print out deltas from then on out.
41 const char *LastLocFilename;
42 unsigned LastLocLine;
Chris Lattner6000dac2007-08-08 22:51:59 +000043 public:
Chris Lattnere300c872007-08-30 06:17:34 +000044 StmtDumper(SourceManager *sm, FILE *f, unsigned maxDepth)
45 : SM(sm), F(f), IndentLevel(0-1), MaxDepth(maxDepth) {
46 LastLocFilename = "";
47 LastLocLine = ~0U;
48 }
Chris Lattner6000dac2007-08-08 22:51:59 +000049
Chris Lattnerf9e05812007-08-09 18:03:18 +000050 void DumpSubTree(Stmt *S) {
Chris Lattner6000dac2007-08-08 22:51:59 +000051 // Prune the recursion if not using dump all.
52 if (MaxDepth == 0) return;
53
Chris Lattnerf9e05812007-08-09 18:03:18 +000054 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000055 if (S) {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000056 Visit(S);
Chris Lattnerb3938792007-08-30 00:53:54 +000057
58 // Print out children.
59 Stmt::child_iterator CI = S->child_begin(), CE = S->child_end();
60 if (CI != CE) {
61 while (CI != CE) {
62 fprintf(F, "\n");
63 DumpSubTree(*CI++);
64 }
65 }
66 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +000067 } else {
68 Indent();
Chris Lattner4a70adb2007-08-26 03:53:29 +000069 fprintf(F, "<<<NULL>>>");
Chris Lattner6000dac2007-08-08 22:51:59 +000070 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000071 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000072 }
73
Chris Lattnerf9e05812007-08-09 18:03:18 +000074 void DumpDeclarator(Decl *D);
Chris Lattner6000dac2007-08-08 22:51:59 +000075
76 void Indent() const {
77 for (int i = 0, e = IndentLevel; i < e; ++i)
78 fprintf(F, " ");
79 }
80
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000081 void DumpType(QualType T) const {
82 fprintf(F, "'%s'", T.getAsString().c_str());
83
84 // If the type is directly a typedef, strip off typedefness to give at
85 // least one level of concreteness.
86 if (TypedefType *TDT = dyn_cast<TypedefType>(T))
87 fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
88 }
89
Chris Lattner6000dac2007-08-08 22:51:59 +000090 void DumpStmt(const Stmt *Node) const {
91 Indent();
92 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
93 }
94
Chris Lattnere300c872007-08-30 06:17:34 +000095 void DumpExpr(Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000096 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000097 fprintf(F, " ");
98 DumpType(Node->getType());
Chris Lattnere300c872007-08-30 06:17:34 +000099 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000100 }
101
Chris Lattnere300c872007-08-30 06:17:34 +0000102 void DumpSourceRange(Expr *Node);
103 void DumpLocation(SourceLocation Loc);
104
105
Chris Lattner17a1a722007-08-30 01:00:35 +0000106 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000107 void VisitStmt(Stmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000108 void VisitDeclStmt(DeclStmt *Node);
109 void VisitLabelStmt(LabelStmt *Node);
110 void VisitGotoStmt(GotoStmt *Node);
111
112 // Exprs
113 void VisitExpr(Expr *Node);
114 void VisitDeclRefExpr(DeclRefExpr *Node);
115 void VisitPreDefinedExpr(PreDefinedExpr *Node);
116 void VisitCharacterLiteral(CharacterLiteral *Node);
117 void VisitIntegerLiteral(IntegerLiteral *Node);
118 void VisitFloatingLiteral(FloatingLiteral *Node);
119 void VisitStringLiteral(StringLiteral *Str);
120 void VisitUnaryOperator(UnaryOperator *Node);
121 void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node);
122 void VisitMemberExpr(MemberExpr *Node);
123 void VisitOCUVectorElementExpr(OCUVectorElementExpr *Node);
124 void VisitBinaryOperator(BinaryOperator *Node);
125 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
126 void VisitAddrLabelExpr(AddrLabelExpr *Node);
127 void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
128
129 // C++
130 void VisitCXXCastExpr(CXXCastExpr *Node);
131 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
132
133 // ObjC
134 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000135 };
136}
137
138//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000139// Utilities
140//===----------------------------------------------------------------------===//
141
142void StmtDumper::DumpLocation(SourceLocation Loc) {
143 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
144
145 // The general format we print out is filename:line:col, but we drop pieces
146 // that haven't changed since the last loc printed.
147 const char *Filename = SM->getSourceName(PhysLoc);
148 unsigned LineNo = SM->getLineNumber(PhysLoc);
149 if (strcmp(Filename, LastLocFilename) != 0) {
150 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
151 LastLocFilename = Filename;
152 LastLocLine = LineNo;
153 } else if (LineNo != LastLocLine) {
154 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
155 LastLocLine = LineNo;
156 } else {
157 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
158 }
159}
160
161void StmtDumper::DumpSourceRange(Expr *Node) {
162 // Can't translate locations if a SourceManager isn't available.
163 if (SM == 0) return;
164
165 // TODO: If the parent expression is available, we can print a delta vs its
166 // location.
167 SourceRange R = Node->getSourceRange();
168
169 fprintf(stderr, " <");
170 DumpLocation(R.Begin());
171 if (R.Begin() != R.End()) {
172 fprintf(stderr, ", ");
173 DumpLocation(R.End());
174 }
175 fprintf(stderr, ">");
176
177 // <t2.c:123:421[blah], t2.c:412:321>
178
179}
180
181
182//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000183// Stmt printing methods.
184//===----------------------------------------------------------------------===//
185
186void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000187 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000188}
189
Chris Lattnerf9e05812007-08-09 18:03:18 +0000190void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000191 // FIXME: Need to complete/beautify this... this code simply shows the
192 // nodes are where they need to be.
193 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000194 fprintf(F, "\"typedef %s %s\"",
195 localType->getUnderlyingType().getAsString().c_str(),
196 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000197 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000198 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000199 // Emit storage class for vardecls.
200 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
201 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000202 default: assert(0 && "Unknown storage class!");
203 case VarDecl::None: break;
204 case VarDecl::Extern: fprintf(F, "extern "); break;
205 case VarDecl::Static: fprintf(F, "static "); break;
206 case VarDecl::Auto: fprintf(F, "auto "); break;
207 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000208 }
209 }
210
211 std::string Name = VD->getName();
212 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000213 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000214
215 // If this is a vardecl with an initializer, emit it.
216 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
217 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000218 fprintf(F, " =\n");
219 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000220 }
221 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000222 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000223 } else {
224 // FIXME: "struct x;"
225 assert(0 && "Unexpected decl");
226 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000227}
228
Chris Lattner6000dac2007-08-08 22:51:59 +0000229void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
230 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000231 fprintf(F, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000232 for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000233 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000234 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000235 fprintf(F, "%p ", (void*)D);
236 DumpDeclarator(D);
237 if (D->getNextDeclarator())
238 fprintf(F, "\n");
239 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000240 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000241}
242
Chris Lattner6000dac2007-08-08 22:51:59 +0000243void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
244 DumpStmt(Node);
245 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000246}
247
Chris Lattner6000dac2007-08-08 22:51:59 +0000248void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
249 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000250 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000251}
252
Chris Lattner6000dac2007-08-08 22:51:59 +0000253//===----------------------------------------------------------------------===//
254// Expr printing methods.
255//===----------------------------------------------------------------------===//
256
257void StmtDumper::VisitExpr(Expr *Node) {
258 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000259}
260
261void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
262 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000263 fprintf(F, " Decl='%s' %p", Node->getDecl()->getName(),
Chris Lattner6000dac2007-08-08 22:51:59 +0000264 (void*)Node->getDecl());
265}
266
267void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
268 DumpExpr(Node);
269 switch (Node->getIdentType()) {
270 default:
271 assert(0 && "unknown case");
272 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000273 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000274 break;
275 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000276 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000277 break;
278 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000279 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000280 break;
281 }
282}
283
284void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000285 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000286 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000287}
288
289void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
290 DumpExpr(Node);
291
292 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000293 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000294}
295void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
296 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000297 fprintf(F, " %f", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000298}
Chris Lattner5d661452007-08-26 03:42:43 +0000299
Chris Lattner6000dac2007-08-08 22:51:59 +0000300void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000301 DumpExpr(Str);
302 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000303 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000304
Chris Lattner6000dac2007-08-08 22:51:59 +0000305 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000306 switch (char C = Str->getStrData()[i]) {
307 default:
308 if (isprint(C))
309 fputc(C, F);
310 else
311 fprintf(F, "\\%03o", C);
312 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000313 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000314 case '\\': fprintf(F, "\\\\"); break;
315 case '"': fprintf(F, "\\\""); break;
316 case '\n': fprintf(F, "\\n"); break;
317 case '\t': fprintf(F, "\\t"); break;
318 case '\a': fprintf(F, "\\a"); break;
319 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000320 }
321 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000322 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000323}
Chris Lattner17a1a722007-08-30 01:00:35 +0000324
Chris Lattner6000dac2007-08-08 22:51:59 +0000325void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000326 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000327 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000328 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000329}
330void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000331 DumpExpr(Node);
332 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
333 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000334}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000335
Chris Lattner6000dac2007-08-08 22:51:59 +0000336void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000337 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000338 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000339 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000340}
341void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000342 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000343 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000344}
Chris Lattner6000dac2007-08-08 22:51:59 +0000345void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
346 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000347 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000348}
349void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
350 DumpExpr(Node);
351 fprintf(F, " '%s' ComputeTy=",
352 BinaryOperator::getOpcodeStr(Node->getOpcode()));
353 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000354}
Chris Lattner6000dac2007-08-08 22:51:59 +0000355
356// GNU extensions.
357
358void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000359 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000360 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000361}
362
Chris Lattner6000dac2007-08-08 22:51:59 +0000363void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000364 DumpExpr(Node);
365 fprintf(F, " ");
366 DumpType(Node->getArgType1());
367 fprintf(F, " ");
368 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000369}
370
Chris Lattnerf9e05812007-08-09 18:03:18 +0000371//===----------------------------------------------------------------------===//
372// C++ Expressions
373//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000374
375void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000376 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000377 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000378}
379
380void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000381 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000382 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000383}
384
Anders Carlsson55085182007-08-21 17:43:55 +0000385//===----------------------------------------------------------------------===//
386// Obj-C Expressions
387//===----------------------------------------------------------------------===//
388
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000389void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
390 DumpExpr(Node);
391
392 fprintf(F, " ");
393 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000394}
395
Chris Lattner6000dac2007-08-08 22:51:59 +0000396//===----------------------------------------------------------------------===//
397// Stmt method implementations
398//===----------------------------------------------------------------------===//
399
400/// dump - This does a local dump of the specified AST fragment. It dumps the
401/// specified node and a few nodes underneath it, but not the whole subtree.
402/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000403void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000404 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000405 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000406 fprintf(stderr, "\n");
407}
408
409/// dump - This does a local dump of the specified AST fragment. It dumps the
410/// specified node and a few nodes underneath it, but not the whole subtree.
411/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000412void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000413 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000414 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000415 fprintf(stderr, "\n");
416}
417
418/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000419void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000420 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000421 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000422 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000423}
424
425/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
426void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000427 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000428 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000429 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000430}