blob: 2310913bb2e24380fd3628d9f33cb890bb83a04a [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"
19#include "llvm/Support/Compiler.h"
20#include <cstdio>
21using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// StmtDumper Visitor
25//===----------------------------------------------------------------------===//
26
27namespace {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000028 class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
Chris Lattner0c727a32007-08-30 00:40:08 +000029 const SourceManager *SM;
Chris Lattner6000dac2007-08-08 22:51:59 +000030 FILE *F;
31 unsigned IndentLevel;
32
33 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
34 /// the first few levels of an AST. This keeps track of how many ast levels
35 /// are left.
36 unsigned MaxDepth;
37 public:
Chris Lattner0c727a32007-08-30 00:40:08 +000038 StmtDumper(const SourceManager *sm, FILE *f, unsigned maxDepth)
Chris Lattnerb3938792007-08-30 00:53:54 +000039 : SM(sm), F(f), IndentLevel(0-1), MaxDepth(maxDepth) {}
Chris Lattner6000dac2007-08-08 22:51:59 +000040
Chris Lattnerf9e05812007-08-09 18:03:18 +000041 void DumpSubTree(Stmt *S) {
Chris Lattner6000dac2007-08-08 22:51:59 +000042 // Prune the recursion if not using dump all.
43 if (MaxDepth == 0) return;
44
Chris Lattnerf9e05812007-08-09 18:03:18 +000045 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000046 if (S) {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000047 Visit(S);
Chris Lattnerb3938792007-08-30 00:53:54 +000048
49 // Print out children.
50 Stmt::child_iterator CI = S->child_begin(), CE = S->child_end();
51 if (CI != CE) {
52 while (CI != CE) {
53 fprintf(F, "\n");
54 DumpSubTree(*CI++);
55 }
56 }
57 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +000058 } else {
59 Indent();
Chris Lattner4a70adb2007-08-26 03:53:29 +000060 fprintf(F, "<<<NULL>>>");
Chris Lattner6000dac2007-08-08 22:51:59 +000061 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000062 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000063 }
64
Chris Lattnerf9e05812007-08-09 18:03:18 +000065 void DumpDeclarator(Decl *D);
Chris Lattner6000dac2007-08-08 22:51:59 +000066
67 void Indent() const {
68 for (int i = 0, e = IndentLevel; i < e; ++i)
69 fprintf(F, " ");
70 }
71
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000072 void DumpType(QualType T) const {
73 fprintf(F, "'%s'", T.getAsString().c_str());
74
75 // If the type is directly a typedef, strip off typedefness to give at
76 // least one level of concreteness.
77 if (TypedefType *TDT = dyn_cast<TypedefType>(T))
78 fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
79 }
80
Chris Lattner6000dac2007-08-08 22:51:59 +000081 void DumpStmt(const Stmt *Node) const {
82 Indent();
83 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
84 }
85
86 void DumpExpr(Expr *Node) const {
87 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000088 fprintf(F, " ");
89 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +000090 }
91
Chris Lattnerc5598cb2007-08-21 04:04:25 +000092 void VisitStmt(Stmt *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000093#define STMT(N, CLASS, PARENT) \
Chris Lattnerc5598cb2007-08-21 04:04:25 +000094 void Visit##CLASS(CLASS *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000095#include "clang/AST/StmtNodes.def"
96 };
97}
98
99//===----------------------------------------------------------------------===//
100// Stmt printing methods.
101//===----------------------------------------------------------------------===//
102
103void StmtDumper::VisitStmt(Stmt *Node) {
104 Indent();
105 fprintf(F, "<<unknown stmt type>>\n");
106}
107
Chris Lattnerf9e05812007-08-09 18:03:18 +0000108void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000109 // FIXME: Need to complete/beautify this... this code simply shows the
110 // nodes are where they need to be.
111 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000112 fprintf(F, "\"typedef %s %s\"",
113 localType->getUnderlyingType().getAsString().c_str(),
114 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000115 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000116 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000117 // Emit storage class for vardecls.
118 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
119 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000120 default: assert(0 && "Unknown storage class!");
121 case VarDecl::None: break;
122 case VarDecl::Extern: fprintf(F, "extern "); break;
123 case VarDecl::Static: fprintf(F, "static "); break;
124 case VarDecl::Auto: fprintf(F, "auto "); break;
125 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000126 }
127 }
128
129 std::string Name = VD->getName();
130 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000131 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000132
133 // If this is a vardecl with an initializer, emit it.
134 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
135 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000136 fprintf(F, " =\n");
137 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000138 }
139 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000140 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000141 } else {
142 // FIXME: "struct x;"
143 assert(0 && "Unexpected decl");
144 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000145}
146
147
148void StmtDumper::VisitNullStmt(NullStmt *Node) {
149 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000150}
151
152void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
153 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000154 fprintf(F, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000155 for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000156 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000157 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000158 fprintf(F, "%p ", (void*)D);
159 DumpDeclarator(D);
160 if (D->getNextDeclarator())
161 fprintf(F, "\n");
162 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000163 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000164}
165
166void StmtDumper::VisitCompoundStmt(CompoundStmt *Node) {
167 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000168}
169
170void StmtDumper::VisitCaseStmt(CaseStmt *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000171 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000172}
173
174void StmtDumper::VisitDefaultStmt(DefaultStmt *Node) {
175 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000176}
177
178void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
179 DumpStmt(Node);
180 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000181}
182
183void StmtDumper::VisitIfStmt(IfStmt *Node) {
184 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000185}
186
187void StmtDumper::VisitSwitchStmt(SwitchStmt *Node) {
188 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000189}
190
191void StmtDumper::VisitSwitchCase(SwitchCase*) {
192 assert(0 && "SwitchCase is an abstract class");
193}
194
195void StmtDumper::VisitWhileStmt(WhileStmt *Node) {
196 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000197}
198
199void StmtDumper::VisitDoStmt(DoStmt *Node) {
200 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000201}
202
203void StmtDumper::VisitForStmt(ForStmt *Node) {
204 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000205}
206
207void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
208 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000209 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000210}
211
212void StmtDumper::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
213 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000214}
215
216void StmtDumper::VisitContinueStmt(ContinueStmt *Node) {
217 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000218}
219
220void StmtDumper::VisitBreakStmt(BreakStmt *Node) {
221 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000222}
223
224
225void StmtDumper::VisitReturnStmt(ReturnStmt *Node) {
226 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000227}
228
229//===----------------------------------------------------------------------===//
230// Expr printing methods.
231//===----------------------------------------------------------------------===//
232
233void StmtDumper::VisitExpr(Expr *Node) {
234 DumpExpr(Node);
235 fprintf(F, ": UNKNOWN EXPR to StmtDumper)");
236}
237
238void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
239 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000240 fprintf(F, " Decl='%s' %p", Node->getDecl()->getName(),
Chris Lattner6000dac2007-08-08 22:51:59 +0000241 (void*)Node->getDecl());
242}
243
244void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
245 DumpExpr(Node);
246 switch (Node->getIdentType()) {
247 default:
248 assert(0 && "unknown case");
249 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000250 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000251 break;
252 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000253 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000254 break;
255 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000256 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000257 break;
258 }
259}
260
261void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000262 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000263 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000264}
265
266void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
267 DumpExpr(Node);
268
269 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000270 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000271}
272void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
273 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000274 fprintf(F, " %f", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000275}
Chris Lattner5d661452007-08-26 03:42:43 +0000276
277void StmtDumper::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
278 DumpExpr(Node);
Chris Lattner5d661452007-08-26 03:42:43 +0000279}
280
Chris Lattner6000dac2007-08-08 22:51:59 +0000281void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000282 DumpExpr(Str);
283 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000284 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000285
Chris Lattner6000dac2007-08-08 22:51:59 +0000286 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000287 switch (char C = Str->getStrData()[i]) {
288 default:
289 if (isprint(C))
290 fputc(C, F);
291 else
292 fprintf(F, "\\%03o", C);
293 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000294 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000295 case '\\': fprintf(F, "\\\\"); break;
296 case '"': fprintf(F, "\\\""); break;
297 case '\n': fprintf(F, "\\n"); break;
298 case '\t': fprintf(F, "\\t"); break;
299 case '\a': fprintf(F, "\\a"); break;
300 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000301 }
302 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000303 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000304}
305void StmtDumper::VisitParenExpr(ParenExpr *Node) {
306 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000307}
308void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000309 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000310 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000311 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000312}
313void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000314 DumpExpr(Node);
315 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
316 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000317}
318void StmtDumper::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
319 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000320}
321
322void StmtDumper::VisitCallExpr(CallExpr *Node) {
323 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000324}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000325
Chris Lattner6000dac2007-08-08 22:51:59 +0000326void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000327 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000328 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000329 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000330}
331void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000332 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000333 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000334}
335void StmtDumper::VisitCastExpr(CastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000336 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000337}
338void StmtDumper::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000339 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000340}
341void StmtDumper::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
342 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000343}
344void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
345 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000346 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000347}
348void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
349 DumpExpr(Node);
350 fprintf(F, " '%s' ComputeTy=",
351 BinaryOperator::getOpcodeStr(Node->getOpcode()));
352 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000353}
354void StmtDumper::VisitConditionalOperator(ConditionalOperator *Node) {
355 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000356}
357
358// GNU extensions.
359
360void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000361 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000362 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000363}
364
Chris Lattner13cb21f2007-08-09 17:35:30 +0000365void StmtDumper::VisitStmtExpr(StmtExpr *Node) {
366 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000367}
368
369void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000370 DumpExpr(Node);
371 fprintf(F, " ");
372 DumpType(Node->getArgType1());
373 fprintf(F, " ");
374 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000375}
376
377void StmtDumper::VisitChooseExpr(ChooseExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000378 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000379}
380
Chris Lattnerf9e05812007-08-09 18:03:18 +0000381//===----------------------------------------------------------------------===//
382// C++ Expressions
383//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000384
385void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000386 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000387 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000388}
389
390void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000391 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000392 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000393}
394
Anders Carlsson55085182007-08-21 17:43:55 +0000395//===----------------------------------------------------------------------===//
396// Obj-C Expressions
397//===----------------------------------------------------------------------===//
398
399void StmtDumper::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
400 DumpExpr(Node);
Anders Carlsson55085182007-08-21 17:43:55 +0000401}
Chris Lattner6000dac2007-08-08 22:51:59 +0000402
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000403void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
404 DumpExpr(Node);
405
406 fprintf(F, " ");
407 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000408}
409
Chris Lattner6000dac2007-08-08 22:51:59 +0000410//===----------------------------------------------------------------------===//
411// Stmt method implementations
412//===----------------------------------------------------------------------===//
413
414/// dump - This does a local dump of the specified AST fragment. It dumps the
415/// specified node and a few nodes underneath it, but not the whole subtree.
416/// This is useful in a debugger.
Chris Lattner0c727a32007-08-30 00:40:08 +0000417void Stmt::dump(const SourceManager &SM) const {
418 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000419 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000420 fprintf(stderr, "\n");
421}
422
423/// dump - This does a local dump of the specified AST fragment. It dumps the
424/// specified node and a few nodes underneath it, but not the whole subtree.
425/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000426void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000427 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000428 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000429 fprintf(stderr, "\n");
430}
431
432/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
433void Stmt::dumpAll(const SourceManager &SM) const {
434 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000435 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000436 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000437}
438
439/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
440void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000441 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000442 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000443 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000444}