blob: 4a07d5149437a86d867b08fb45767e21a302a7a9 [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)
39 : SM(sm), F(f), IndentLevel(0), 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 Lattner6000dac2007-08-08 22:51:59 +000048 } else {
49 Indent();
Chris Lattner4a70adb2007-08-26 03:53:29 +000050 fprintf(F, "<<<NULL>>>");
Chris Lattner6000dac2007-08-08 22:51:59 +000051 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000052 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000053 }
54
Chris Lattnerf9e05812007-08-09 18:03:18 +000055 void DumpDeclarator(Decl *D);
Chris Lattner6000dac2007-08-08 22:51:59 +000056
57 void Indent() const {
58 for (int i = 0, e = IndentLevel; i < e; ++i)
59 fprintf(F, " ");
60 }
61
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000062 void DumpType(QualType T) const {
63 fprintf(F, "'%s'", T.getAsString().c_str());
64
65 // If the type is directly a typedef, strip off typedefness to give at
66 // least one level of concreteness.
67 if (TypedefType *TDT = dyn_cast<TypedefType>(T))
68 fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
69 }
70
Chris Lattner6000dac2007-08-08 22:51:59 +000071 void DumpStmt(const Stmt *Node) const {
72 Indent();
73 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
74 }
75
76 void DumpExpr(Expr *Node) const {
77 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000078 fprintf(F, " ");
79 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +000080 }
81
Chris Lattnerc5598cb2007-08-21 04:04:25 +000082 void VisitStmt(Stmt *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000083#define STMT(N, CLASS, PARENT) \
Chris Lattnerc5598cb2007-08-21 04:04:25 +000084 void Visit##CLASS(CLASS *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000085#include "clang/AST/StmtNodes.def"
86 };
87}
88
89//===----------------------------------------------------------------------===//
90// Stmt printing methods.
91//===----------------------------------------------------------------------===//
92
93void StmtDumper::VisitStmt(Stmt *Node) {
94 Indent();
95 fprintf(F, "<<unknown stmt type>>\n");
96}
97
Chris Lattnerf9e05812007-08-09 18:03:18 +000098void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +000099 // FIXME: Need to complete/beautify this... this code simply shows the
100 // nodes are where they need to be.
101 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000102 fprintf(F, "\"typedef %s %s\"",
103 localType->getUnderlyingType().getAsString().c_str(),
104 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000105 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000106 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000107 // Emit storage class for vardecls.
108 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
109 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000110 default: assert(0 && "Unknown storage class!");
111 case VarDecl::None: break;
112 case VarDecl::Extern: fprintf(F, "extern "); break;
113 case VarDecl::Static: fprintf(F, "static "); break;
114 case VarDecl::Auto: fprintf(F, "auto "); break;
115 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000116 }
117 }
118
119 std::string Name = VD->getName();
120 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000121 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000122
123 // If this is a vardecl with an initializer, emit it.
124 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
125 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000126 fprintf(F, " =\n");
127 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000128 }
129 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000130 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000131 } else {
132 // FIXME: "struct x;"
133 assert(0 && "Unexpected decl");
134 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000135}
136
137
138void StmtDumper::VisitNullStmt(NullStmt *Node) {
139 DumpStmt(Node);
140 fprintf(F, ")");
141}
142
143void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
144 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000145 fprintf(F, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000146 for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000147 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000148 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000149 fprintf(F, "%p ", (void*)D);
150 DumpDeclarator(D);
151 if (D->getNextDeclarator())
152 fprintf(F, "\n");
153 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000154 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000155
156 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000157}
158
159void StmtDumper::VisitCompoundStmt(CompoundStmt *Node) {
160 DumpStmt(Node);
161 if (!Node->body_empty()) fprintf(F, "\n");
162
163 for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
164 I != E; ) {
165 DumpSubTree(*I);
166 ++I;
167 if (I != E)
168 fprintf(F, "\n");
169 }
170 fprintf(F, ")");
171}
172
173void StmtDumper::VisitCaseStmt(CaseStmt *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000174 DumpStmt(Node);
175 fprintf(F, "\n");
176 DumpSubTree(Node->getLHS());
177 fprintf(F, "\n");
178 DumpSubTree(Node->getRHS());
179 fprintf(F, "\n");
180 DumpSubTree(Node->getSubStmt());
181 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000182}
183
184void StmtDumper::VisitDefaultStmt(DefaultStmt *Node) {
185 DumpStmt(Node);
186 fprintf(F, "\n");
187 DumpSubTree(Node->getSubStmt());
188 fprintf(F, ")");
189}
190
191void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
192 DumpStmt(Node);
193 fprintf(F, " '%s'\n", Node->getName());
194 DumpSubTree(Node->getSubStmt());
195 fprintf(F, "\n");
196}
197
198void StmtDumper::VisitIfStmt(IfStmt *Node) {
199 DumpStmt(Node);
200 fprintf(F, "\n");
201 DumpSubTree(Node->getCond());
202 fprintf(F, "\n");
203 DumpSubTree(Node->getThen());
204 fprintf(F, "\n");
205 DumpSubTree(Node->getElse());
206 fprintf(F, ")");
207}
208
209void StmtDumper::VisitSwitchStmt(SwitchStmt *Node) {
210 DumpStmt(Node);
211 fprintf(F, "\n");
212 DumpSubTree(Node->getCond());
213 fprintf(F, "\n");
214 DumpSubTree(Node->getBody());
215 fprintf(F, ")");
216}
217
218void StmtDumper::VisitSwitchCase(SwitchCase*) {
219 assert(0 && "SwitchCase is an abstract class");
220}
221
222void StmtDumper::VisitWhileStmt(WhileStmt *Node) {
223 DumpStmt(Node);
224 fprintf(F, "\n");
225 DumpSubTree(Node->getCond());
226 fprintf(F, "\n");
227 DumpSubTree(Node->getBody());
228 fprintf(F, ")");
229}
230
231void StmtDumper::VisitDoStmt(DoStmt *Node) {
232 DumpStmt(Node);
233 fprintf(F, "\n");
234 DumpSubTree(Node->getBody());
235 fprintf(F, "\n");
236 DumpSubTree(Node->getCond());
237 fprintf(F, ")");
238}
239
240void StmtDumper::VisitForStmt(ForStmt *Node) {
241 DumpStmt(Node);
242 fprintf(F, "\n");
243 DumpSubTree(Node->getInit());
244 fprintf(F, "\n");
245 DumpSubTree(Node->getCond());
246 fprintf(F, "\n");
247 DumpSubTree(Node->getInc());
248 fprintf(F, "\n");
249 DumpSubTree(Node->getBody());
250 fprintf(F, ")");
251}
252
253void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
254 DumpStmt(Node);
255 fprintf(F, " '%s':%p)", Node->getLabel()->getName(), (void*)Node->getLabel());
256}
257
258void StmtDumper::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
259 DumpStmt(Node);
260 fprintf(F, "\n");
261 DumpSubTree(Node->getTarget());
262 fprintf(F, ")");
263}
264
265void StmtDumper::VisitContinueStmt(ContinueStmt *Node) {
266 DumpStmt(Node);
267 fprintf(F, ")");
268}
269
270void StmtDumper::VisitBreakStmt(BreakStmt *Node) {
271 DumpStmt(Node);
272 fprintf(F, ")");
273}
274
275
276void StmtDumper::VisitReturnStmt(ReturnStmt *Node) {
277 DumpStmt(Node);
278 if (Expr *RV = Node->getRetValue()) {
279 fprintf(F, "\n");
280 DumpSubTree(RV);
281 }
282 fprintf(F, ")");
283}
284
285//===----------------------------------------------------------------------===//
286// Expr printing methods.
287//===----------------------------------------------------------------------===//
288
289void StmtDumper::VisitExpr(Expr *Node) {
290 DumpExpr(Node);
291 fprintf(F, ": UNKNOWN EXPR to StmtDumper)");
292}
293
294void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
295 DumpExpr(Node);
296 fprintf(F, " Decl='%s' %p)", Node->getDecl()->getName(),
297 (void*)Node->getDecl());
298}
299
300void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
301 DumpExpr(Node);
302 switch (Node->getIdentType()) {
303 default:
304 assert(0 && "unknown case");
305 case PreDefinedExpr::Func:
306 fprintf(F, " __func__)");
307 break;
308 case PreDefinedExpr::Function:
309 fprintf(F, " __FUNCTION__)");
310 break;
311 case PreDefinedExpr::PrettyFunction:
312 fprintf(F, " __PRETTY_FUNCTION__)");
313 break;
314 }
315}
316
317void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000318 DumpExpr(Node);
319 fprintf(F, " %d)", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000320}
321
322void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
323 DumpExpr(Node);
324
325 bool isSigned = Node->getType()->isSignedIntegerType();
326 fprintf(F, " %s)", Node->getValue().toString(10, isSigned).c_str());
327}
328void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
329 DumpExpr(Node);
330 fprintf(F, " %f)", Node->getValue());
331}
Chris Lattner5d661452007-08-26 03:42:43 +0000332
333void StmtDumper::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
334 DumpExpr(Node);
335 fprintf(F, "\n");
336 DumpSubTree(Node->getSubExpr());
337 fprintf(F, ")");
338}
339
Chris Lattner6000dac2007-08-08 22:51:59 +0000340void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000341 DumpExpr(Str);
342 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000343 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000344
Chris Lattner6000dac2007-08-08 22:51:59 +0000345 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000346 switch (char C = Str->getStrData()[i]) {
347 default:
348 if (isprint(C))
349 fputc(C, F);
350 else
351 fprintf(F, "\\%03o", C);
352 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000353 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000354 case '\\': fprintf(F, "\\\\"); break;
355 case '"': fprintf(F, "\\\""); break;
356 case '\n': fprintf(F, "\\n"); break;
357 case '\t': fprintf(F, "\\t"); break;
358 case '\a': fprintf(F, "\\a"); break;
359 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000360 }
361 }
Chris Lattner5fc61072007-08-09 17:14:24 +0000362 fprintf(F, "\")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000363}
364void StmtDumper::VisitParenExpr(ParenExpr *Node) {
365 DumpExpr(Node);
366 fprintf(F, "\n");
367 DumpSubTree(Node->getSubExpr());
368 fprintf(F, ")");
369}
370void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000371 DumpExpr(Node);
372 fprintf(F, " %s '%s'\n", Node->isPostfix() ? "postfix" : "prefix",
373 UnaryOperator::getOpcodeStr(Node->getOpcode()));
374 DumpSubTree(Node->getSubExpr());
375 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000376}
377void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000378 DumpExpr(Node);
379 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
380 DumpType(Node->getArgumentType());
381 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000382}
383void StmtDumper::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
384 DumpExpr(Node);
385 fprintf(F, "\n");
Ted Kremenek23245122007-08-20 16:18:38 +0000386 DumpSubTree(Node->getLHS());
Chris Lattner6000dac2007-08-08 22:51:59 +0000387 fprintf(F, "\n");
Ted Kremenek23245122007-08-20 16:18:38 +0000388 DumpSubTree(Node->getRHS());
Chris Lattner6000dac2007-08-08 22:51:59 +0000389 fprintf(F, ")");
390}
391
392void StmtDumper::VisitCallExpr(CallExpr *Node) {
393 DumpExpr(Node);
394 fprintf(F, "\n");
395 DumpSubTree(Node->getCallee());
396
397 for (unsigned i = 0, e = Node->getNumArgs(); i != e; ++i) {
398 fprintf(F, "\n");
399 DumpSubTree(Node->getArg(i));
400 }
401 fprintf(F, ")");
402}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000403
Chris Lattner6000dac2007-08-08 22:51:59 +0000404void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000405 DumpExpr(Node);
406 fprintf(F, " %s%s %p\n", Node->isArrow() ? "->" : ".",
407 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
408 DumpSubTree(Node->getBase());
409 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000410}
411void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000412 DumpExpr(Node);
413 fprintf(F, " %s\n", Node->getAccessor().getName());
414 DumpSubTree(Node->getBase());
415 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000416}
417void StmtDumper::VisitCastExpr(CastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000418 DumpExpr(Node);
419 fprintf(F, "\n");
420 DumpSubTree(Node->getSubExpr());
421 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000422}
423void StmtDumper::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000424 DumpExpr(Node);
425 fprintf(F, "\n");
426 DumpSubTree(Node->getInitializer());
427 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000428}
429void StmtDumper::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
430 DumpExpr(Node);
431 fprintf(F, "\n");
432 DumpSubTree(Node->getSubExpr());
433 fprintf(F, ")");
434}
435void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
436 DumpExpr(Node);
Chris Lattnereb14fe82007-08-25 02:00:02 +0000437 fprintf(F, " '%s'\n", BinaryOperator::getOpcodeStr(Node->getOpcode()));
438 DumpSubTree(Node->getLHS());
439 fprintf(F, "\n");
440 DumpSubTree(Node->getRHS());
441 fprintf(F, ")");
442}
443void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
444 DumpExpr(Node);
445 fprintf(F, " '%s' ComputeTy=",
446 BinaryOperator::getOpcodeStr(Node->getOpcode()));
447 DumpType(Node->getComputationType());
Chris Lattnerdfce2a52007-08-24 16:24:49 +0000448 fprintf(F, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000449 DumpSubTree(Node->getLHS());
450 fprintf(F, "\n");
451 DumpSubTree(Node->getRHS());
452 fprintf(F, ")");
453}
454void StmtDumper::VisitConditionalOperator(ConditionalOperator *Node) {
455 DumpExpr(Node);
456 fprintf(F, "\n");
457 DumpSubTree(Node->getCond());
458 fprintf(F, "\n");
459 DumpSubTree(Node->getLHS());
460 fprintf(F, "\n");
461 DumpSubTree(Node->getRHS());
462 fprintf(F, ")");
463}
464
465// GNU extensions.
466
467void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000468 DumpExpr(Node);
469 fprintf(F, " %s %p)", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000470}
471
Chris Lattner13cb21f2007-08-09 17:35:30 +0000472void StmtDumper::VisitStmtExpr(StmtExpr *Node) {
473 DumpExpr(Node);
474 fprintf(F, "\n");
475 DumpSubTree(Node->getSubStmt());
476 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000477}
478
479void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000480 DumpExpr(Node);
481 fprintf(F, " ");
482 DumpType(Node->getArgType1());
483 fprintf(F, " ");
484 DumpType(Node->getArgType2());
485 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000486}
487
488void StmtDumper::VisitChooseExpr(ChooseExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000489 DumpExpr(Node);
490 fprintf(F, "\n");
491 DumpSubTree(Node->getCond());
492 fprintf(F, "\n");
493 DumpSubTree(Node->getLHS());
494 fprintf(F, "\n");
495 DumpSubTree(Node->getRHS());
496 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000497}
498
Chris Lattnerf9e05812007-08-09 18:03:18 +0000499//===----------------------------------------------------------------------===//
500// C++ Expressions
501//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000502
503void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000504 DumpExpr(Node);
505 fprintf(F, " %s\n", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
506 DumpSubTree(Node->getSubExpr());
507 fprintf(F, ")");
Chris Lattner6000dac2007-08-08 22:51:59 +0000508}
509
510void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000511 DumpExpr(Node);
512 fprintf(F, " %s)", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000513}
514
Anders Carlsson55085182007-08-21 17:43:55 +0000515//===----------------------------------------------------------------------===//
516// Obj-C Expressions
517//===----------------------------------------------------------------------===//
518
519void StmtDumper::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
520 DumpExpr(Node);
521 fprintf(F, "\n");
522 DumpSubTree(Node->getString());
523 fprintf(F, ")");
524}
Chris Lattner6000dac2007-08-08 22:51:59 +0000525
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000526void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
527 DumpExpr(Node);
528
529 fprintf(F, " ");
530 DumpType(Node->getEncodedType());
531 fprintf(F, ")");
532}
533
Chris Lattner6000dac2007-08-08 22:51:59 +0000534//===----------------------------------------------------------------------===//
535// Stmt method implementations
536//===----------------------------------------------------------------------===//
537
538/// dump - This does a local dump of the specified AST fragment. It dumps the
539/// specified node and a few nodes underneath it, but not the whole subtree.
540/// This is useful in a debugger.
Chris Lattner0c727a32007-08-30 00:40:08 +0000541void Stmt::dump(const SourceManager &SM) const {
542 StmtDumper P(&SM, stderr, 4);
543 P.Visit(const_cast<Stmt*>(this));
544 fprintf(stderr, "\n");
545}
546
547/// dump - This does a local dump of the specified AST fragment. It dumps the
548/// specified node and a few nodes underneath it, but not the whole subtree.
549/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000550void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000551 StmtDumper P(0, stderr, 4);
552 P.Visit(const_cast<Stmt*>(this));
553 fprintf(stderr, "\n");
554}
555
556/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
557void Stmt::dumpAll(const SourceManager &SM) const {
558 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000559 P.Visit(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000560 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000561}
562
563/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
564void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000565 StmtDumper P(0, stderr, ~0U);
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000566 P.Visit(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000567 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000568}