blob: 0ac7a19ddadd84974e1c01adef0b5213ef83a4f1 [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 Lattner6000dac2007-08-08 22:51:59 +000029 FILE *F;
30 unsigned IndentLevel;
31
32 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
33 /// the first few levels of an AST. This keeps track of how many ast levels
34 /// are left.
35 unsigned MaxDepth;
36 public:
37 StmtDumper(FILE *f, unsigned maxDepth)
38 : F(f), IndentLevel(0), MaxDepth(maxDepth) {}
39
Chris Lattnerf9e05812007-08-09 18:03:18 +000040 void DumpSubTree(Stmt *S) {
Chris Lattner6000dac2007-08-08 22:51:59 +000041 // Prune the recursion if not using dump all.
42 if (MaxDepth == 0) return;
43
Chris Lattnerf9e05812007-08-09 18:03:18 +000044 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000045 if (S) {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000046 Visit(S);
Chris Lattner6000dac2007-08-08 22:51:59 +000047 } else {
48 Indent();
49 fprintf(F, "<<<NULL>>>\n");
50 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000051 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000052 }
53
Chris Lattnerf9e05812007-08-09 18:03:18 +000054 void DumpDeclarator(Decl *D);
Chris Lattner6000dac2007-08-08 22:51:59 +000055
56 void Indent() const {
57 for (int i = 0, e = IndentLevel; i < e; ++i)
58 fprintf(F, " ");
59 }
60
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000061 void DumpType(QualType T) const {
62 fprintf(F, "'%s'", T.getAsString().c_str());
63
64 // If the type is directly a typedef, strip off typedefness to give at
65 // least one level of concreteness.
66 if (TypedefType *TDT = dyn_cast<TypedefType>(T))
67 fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
68 }
69
Chris Lattner6000dac2007-08-08 22:51:59 +000070 void DumpStmt(const Stmt *Node) const {
71 Indent();
72 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
73 }
74
75 void DumpExpr(Expr *Node) const {
76 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000077 fprintf(F, " ");
78 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +000079 }
80
Chris Lattnerc5598cb2007-08-21 04:04:25 +000081 void VisitStmt(Stmt *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000082#define STMT(N, CLASS, PARENT) \
Chris Lattnerc5598cb2007-08-21 04:04:25 +000083 void Visit##CLASS(CLASS *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000084#include "clang/AST/StmtNodes.def"
85 };
86}
87
88//===----------------------------------------------------------------------===//
89// Stmt printing methods.
90//===----------------------------------------------------------------------===//
91
92void StmtDumper::VisitStmt(Stmt *Node) {
93 Indent();
94 fprintf(F, "<<unknown stmt type>>\n");
95}
96
Chris Lattnerf9e05812007-08-09 18:03:18 +000097void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +000098 // FIXME: Need to complete/beautify this... this code simply shows the
99 // nodes are where they need to be.
100 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000101 fprintf(F, "\"typedef %s %s\"",
102 localType->getUnderlyingType().getAsString().c_str(),
103 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000104 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000105 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000106 // Emit storage class for vardecls.
107 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
108 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000109 default: assert(0 && "Unknown storage class!");
110 case VarDecl::None: break;
111 case VarDecl::Extern: fprintf(F, "extern "); break;
112 case VarDecl::Static: fprintf(F, "static "); break;
113 case VarDecl::Auto: fprintf(F, "auto "); break;
114 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000115 }
116 }
117
118 std::string Name = VD->getName();
119 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000120 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000121
122 // If this is a vardecl with an initializer, emit it.
123 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
124 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000125 fprintf(F, " =\n");
126 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000127 }
128 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000129 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000130 } else {
131 // FIXME: "struct x;"
132 assert(0 && "Unexpected decl");
133 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000134}
135
136
137void StmtDumper::VisitNullStmt(NullStmt *Node) {
138 DumpStmt(Node);
139 fprintf(F, ")");
140}
141
142void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
143 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000144 fprintf(F, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000145 for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000146 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000147 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000148 fprintf(F, "%p ", (void*)D);
149 DumpDeclarator(D);
150 if (D->getNextDeclarator())
151 fprintf(F, "\n");
152 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000153 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000154
155 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000156}
157
158void StmtDumper::VisitCompoundStmt(CompoundStmt *Node) {
159 DumpStmt(Node);
160 if (!Node->body_empty()) fprintf(F, "\n");
161
162 for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
163 I != E; ) {
164 DumpSubTree(*I);
165 ++I;
166 if (I != E)
167 fprintf(F, "\n");
168 }
169 fprintf(F, ")");
170}
171
172void StmtDumper::VisitCaseStmt(CaseStmt *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000173 DumpStmt(Node);
174 fprintf(F, "\n");
175 DumpSubTree(Node->getLHS());
176 fprintf(F, "\n");
177 DumpSubTree(Node->getRHS());
178 fprintf(F, "\n");
179 DumpSubTree(Node->getSubStmt());
180 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000181}
182
183void StmtDumper::VisitDefaultStmt(DefaultStmt *Node) {
184 DumpStmt(Node);
185 fprintf(F, "\n");
186 DumpSubTree(Node->getSubStmt());
187 fprintf(F, ")");
188}
189
190void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
191 DumpStmt(Node);
192 fprintf(F, " '%s'\n", Node->getName());
193 DumpSubTree(Node->getSubStmt());
194 fprintf(F, "\n");
195}
196
197void StmtDumper::VisitIfStmt(IfStmt *Node) {
198 DumpStmt(Node);
199 fprintf(F, "\n");
200 DumpSubTree(Node->getCond());
201 fprintf(F, "\n");
202 DumpSubTree(Node->getThen());
203 fprintf(F, "\n");
204 DumpSubTree(Node->getElse());
205 fprintf(F, ")");
206}
207
208void StmtDumper::VisitSwitchStmt(SwitchStmt *Node) {
209 DumpStmt(Node);
210 fprintf(F, "\n");
211 DumpSubTree(Node->getCond());
212 fprintf(F, "\n");
213 DumpSubTree(Node->getBody());
214 fprintf(F, ")");
215}
216
217void StmtDumper::VisitSwitchCase(SwitchCase*) {
218 assert(0 && "SwitchCase is an abstract class");
219}
220
221void StmtDumper::VisitWhileStmt(WhileStmt *Node) {
222 DumpStmt(Node);
223 fprintf(F, "\n");
224 DumpSubTree(Node->getCond());
225 fprintf(F, "\n");
226 DumpSubTree(Node->getBody());
227 fprintf(F, ")");
228}
229
230void StmtDumper::VisitDoStmt(DoStmt *Node) {
231 DumpStmt(Node);
232 fprintf(F, "\n");
233 DumpSubTree(Node->getBody());
234 fprintf(F, "\n");
235 DumpSubTree(Node->getCond());
236 fprintf(F, ")");
237}
238
239void StmtDumper::VisitForStmt(ForStmt *Node) {
240 DumpStmt(Node);
241 fprintf(F, "\n");
242 DumpSubTree(Node->getInit());
243 fprintf(F, "\n");
244 DumpSubTree(Node->getCond());
245 fprintf(F, "\n");
246 DumpSubTree(Node->getInc());
247 fprintf(F, "\n");
248 DumpSubTree(Node->getBody());
249 fprintf(F, ")");
250}
251
252void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
253 DumpStmt(Node);
254 fprintf(F, " '%s':%p)", Node->getLabel()->getName(), (void*)Node->getLabel());
255}
256
257void StmtDumper::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
258 DumpStmt(Node);
259 fprintf(F, "\n");
260 DumpSubTree(Node->getTarget());
261 fprintf(F, ")");
262}
263
264void StmtDumper::VisitContinueStmt(ContinueStmt *Node) {
265 DumpStmt(Node);
266 fprintf(F, ")");
267}
268
269void StmtDumper::VisitBreakStmt(BreakStmt *Node) {
270 DumpStmt(Node);
271 fprintf(F, ")");
272}
273
274
275void StmtDumper::VisitReturnStmt(ReturnStmt *Node) {
276 DumpStmt(Node);
277 if (Expr *RV = Node->getRetValue()) {
278 fprintf(F, "\n");
279 DumpSubTree(RV);
280 }
281 fprintf(F, ")");
282}
283
284//===----------------------------------------------------------------------===//
285// Expr printing methods.
286//===----------------------------------------------------------------------===//
287
288void StmtDumper::VisitExpr(Expr *Node) {
289 DumpExpr(Node);
290 fprintf(F, ": UNKNOWN EXPR to StmtDumper)");
291}
292
293void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
294 DumpExpr(Node);
295 fprintf(F, " Decl='%s' %p)", Node->getDecl()->getName(),
296 (void*)Node->getDecl());
297}
298
299void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
300 DumpExpr(Node);
301 switch (Node->getIdentType()) {
302 default:
303 assert(0 && "unknown case");
304 case PreDefinedExpr::Func:
305 fprintf(F, " __func__)");
306 break;
307 case PreDefinedExpr::Function:
308 fprintf(F, " __FUNCTION__)");
309 break;
310 case PreDefinedExpr::PrettyFunction:
311 fprintf(F, " __PRETTY_FUNCTION__)");
312 break;
313 }
314}
315
316void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000317 DumpExpr(Node);
318 fprintf(F, " %d)", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000319}
320
321void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
322 DumpExpr(Node);
323
324 bool isSigned = Node->getType()->isSignedIntegerType();
325 fprintf(F, " %s)", Node->getValue().toString(10, isSigned).c_str());
326}
327void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
328 DumpExpr(Node);
329 fprintf(F, " %f)", Node->getValue());
330}
Chris Lattner5d661452007-08-26 03:42:43 +0000331
332void StmtDumper::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
333 DumpExpr(Node);
334 fprintf(F, "\n");
335 DumpSubTree(Node->getSubExpr());
336 fprintf(F, ")");
337}
338
Chris Lattner6000dac2007-08-08 22:51:59 +0000339void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000340 DumpExpr(Str);
341 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000342 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000343
Chris Lattner6000dac2007-08-08 22:51:59 +0000344 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000345 switch (char C = Str->getStrData()[i]) {
346 default:
347 if (isprint(C))
348 fputc(C, F);
349 else
350 fprintf(F, "\\%03o", C);
351 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000352 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000353 case '\\': fprintf(F, "\\\\"); break;
354 case '"': fprintf(F, "\\\""); break;
355 case '\n': fprintf(F, "\\n"); break;
356 case '\t': fprintf(F, "\\t"); break;
357 case '\a': fprintf(F, "\\a"); break;
358 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000359 }
360 }
Chris Lattner5fc61072007-08-09 17:14:24 +0000361 fprintf(F, "\")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000362}
363void StmtDumper::VisitParenExpr(ParenExpr *Node) {
364 DumpExpr(Node);
365 fprintf(F, "\n");
366 DumpSubTree(Node->getSubExpr());
367 fprintf(F, ")");
368}
369void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000370 DumpExpr(Node);
371 fprintf(F, " %s '%s'\n", Node->isPostfix() ? "postfix" : "prefix",
372 UnaryOperator::getOpcodeStr(Node->getOpcode()));
373 DumpSubTree(Node->getSubExpr());
374 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000375}
376void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000377 DumpExpr(Node);
378 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
379 DumpType(Node->getArgumentType());
380 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000381}
382void StmtDumper::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
383 DumpExpr(Node);
384 fprintf(F, "\n");
Ted Kremenek23245122007-08-20 16:18:38 +0000385 DumpSubTree(Node->getLHS());
Chris Lattner6000dac2007-08-08 22:51:59 +0000386 fprintf(F, "\n");
Ted Kremenek23245122007-08-20 16:18:38 +0000387 DumpSubTree(Node->getRHS());
Chris Lattner6000dac2007-08-08 22:51:59 +0000388 fprintf(F, ")");
389}
390
391void StmtDumper::VisitCallExpr(CallExpr *Node) {
392 DumpExpr(Node);
393 fprintf(F, "\n");
394 DumpSubTree(Node->getCallee());
395
396 for (unsigned i = 0, e = Node->getNumArgs(); i != e; ++i) {
397 fprintf(F, "\n");
398 DumpSubTree(Node->getArg(i));
399 }
400 fprintf(F, ")");
401}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000402
Chris Lattner6000dac2007-08-08 22:51:59 +0000403void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000404 DumpExpr(Node);
405 fprintf(F, " %s%s %p\n", Node->isArrow() ? "->" : ".",
406 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
407 DumpSubTree(Node->getBase());
408 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000409}
410void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000411 DumpExpr(Node);
412 fprintf(F, " %s\n", Node->getAccessor().getName());
413 DumpSubTree(Node->getBase());
414 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000415}
416void StmtDumper::VisitCastExpr(CastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000417 DumpExpr(Node);
418 fprintf(F, "\n");
419 DumpSubTree(Node->getSubExpr());
420 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000421}
422void StmtDumper::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000423 DumpExpr(Node);
424 fprintf(F, "\n");
425 DumpSubTree(Node->getInitializer());
426 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000427}
428void StmtDumper::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
429 DumpExpr(Node);
430 fprintf(F, "\n");
431 DumpSubTree(Node->getSubExpr());
432 fprintf(F, ")");
433}
434void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
435 DumpExpr(Node);
Chris Lattnereb14fe82007-08-25 02:00:02 +0000436 fprintf(F, " '%s'\n", BinaryOperator::getOpcodeStr(Node->getOpcode()));
437 DumpSubTree(Node->getLHS());
438 fprintf(F, "\n");
439 DumpSubTree(Node->getRHS());
440 fprintf(F, ")");
441}
442void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
443 DumpExpr(Node);
444 fprintf(F, " '%s' ComputeTy=",
445 BinaryOperator::getOpcodeStr(Node->getOpcode()));
446 DumpType(Node->getComputationType());
Chris Lattnerdfce2a52007-08-24 16:24:49 +0000447 fprintf(F, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000448 DumpSubTree(Node->getLHS());
449 fprintf(F, "\n");
450 DumpSubTree(Node->getRHS());
451 fprintf(F, ")");
452}
453void StmtDumper::VisitConditionalOperator(ConditionalOperator *Node) {
454 DumpExpr(Node);
455 fprintf(F, "\n");
456 DumpSubTree(Node->getCond());
457 fprintf(F, "\n");
458 DumpSubTree(Node->getLHS());
459 fprintf(F, "\n");
460 DumpSubTree(Node->getRHS());
461 fprintf(F, ")");
462}
463
464// GNU extensions.
465
466void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000467 DumpExpr(Node);
468 fprintf(F, " %s %p)", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000469}
470
Chris Lattner13cb21f2007-08-09 17:35:30 +0000471void StmtDumper::VisitStmtExpr(StmtExpr *Node) {
472 DumpExpr(Node);
473 fprintf(F, "\n");
474 DumpSubTree(Node->getSubStmt());
475 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000476}
477
478void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000479 DumpExpr(Node);
480 fprintf(F, " ");
481 DumpType(Node->getArgType1());
482 fprintf(F, " ");
483 DumpType(Node->getArgType2());
484 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000485}
486
487void StmtDumper::VisitChooseExpr(ChooseExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000488 DumpExpr(Node);
489 fprintf(F, "\n");
490 DumpSubTree(Node->getCond());
491 fprintf(F, "\n");
492 DumpSubTree(Node->getLHS());
493 fprintf(F, "\n");
494 DumpSubTree(Node->getRHS());
495 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000496}
497
Chris Lattnerf9e05812007-08-09 18:03:18 +0000498//===----------------------------------------------------------------------===//
499// C++ Expressions
500//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000501
502void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000503 DumpExpr(Node);
504 fprintf(F, " %s\n", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
505 DumpSubTree(Node->getSubExpr());
506 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000507}
508
509void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000510 DumpExpr(Node);
511 fprintf(F, " %s)", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000512}
513
Anders Carlsson55085182007-08-21 17:43:55 +0000514//===----------------------------------------------------------------------===//
515// Obj-C Expressions
516//===----------------------------------------------------------------------===//
517
518void StmtDumper::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
519 DumpExpr(Node);
520 fprintf(F, "\n");
521 DumpSubTree(Node->getString());
522 fprintf(F, ")");
523}
Chris Lattner6000dac2007-08-08 22:51:59 +0000524
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000525void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
526 DumpExpr(Node);
527
528 fprintf(F, " ");
529 DumpType(Node->getEncodedType());
530 fprintf(F, ")");
531}
532
Chris Lattner6000dac2007-08-08 22:51:59 +0000533//===----------------------------------------------------------------------===//
534// Stmt method implementations
535//===----------------------------------------------------------------------===//
536
537/// dump - This does a local dump of the specified AST fragment. It dumps the
538/// specified node and a few nodes underneath it, but not the whole subtree.
539/// This is useful in a debugger.
540void Stmt::dump() const {
541 StmtDumper P(stderr, 4);
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000542 P.Visit(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000543 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000544}
545
546/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
547void Stmt::dumpAll() const {
548 StmtDumper P(stderr, ~0U);
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000549 P.Visit(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000550 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000551}