blob: 410890c2a303c47dcfdc294f108b01c3acae2b61 [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"
Chris Lattnerc7229c32007-10-07 08:58:51 +000018#include "clang/Basic/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
Steve Naroff9dcbfa42007-09-01 21:08:38 +000081 void DumpType(QualType T) {
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000082 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 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000089 void DumpStmt(const Stmt *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000090 Indent();
91 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +000092 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000093 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000094 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000095 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000096 fprintf(F, " ");
97 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +000098 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000099 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000100 void DumpLocation(SourceLocation Loc);
Chris Lattnere300c872007-08-30 06:17:34 +0000101
Chris Lattner17a1a722007-08-30 01:00:35 +0000102 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000103 void VisitStmt(Stmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000104 void VisitDeclStmt(DeclStmt *Node);
105 void VisitLabelStmt(LabelStmt *Node);
106 void VisitGotoStmt(GotoStmt *Node);
107
108 // Exprs
109 void VisitExpr(Expr *Node);
110 void VisitDeclRefExpr(DeclRefExpr *Node);
111 void VisitPreDefinedExpr(PreDefinedExpr *Node);
112 void VisitCharacterLiteral(CharacterLiteral *Node);
113 void VisitIntegerLiteral(IntegerLiteral *Node);
114 void VisitFloatingLiteral(FloatingLiteral *Node);
115 void VisitStringLiteral(StringLiteral *Str);
116 void VisitUnaryOperator(UnaryOperator *Node);
117 void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node);
118 void VisitMemberExpr(MemberExpr *Node);
119 void VisitOCUVectorElementExpr(OCUVectorElementExpr *Node);
120 void VisitBinaryOperator(BinaryOperator *Node);
121 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
122 void VisitAddrLabelExpr(AddrLabelExpr *Node);
123 void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
124
125 // C++
126 void VisitCXXCastExpr(CXXCastExpr *Node);
127 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
128
129 // ObjC
130 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000131 };
132}
133
134//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000135// Utilities
136//===----------------------------------------------------------------------===//
137
138void StmtDumper::DumpLocation(SourceLocation Loc) {
139 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
140
141 // The general format we print out is filename:line:col, but we drop pieces
142 // that haven't changed since the last loc printed.
143 const char *Filename = SM->getSourceName(PhysLoc);
144 unsigned LineNo = SM->getLineNumber(PhysLoc);
145 if (strcmp(Filename, LastLocFilename) != 0) {
146 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
147 LastLocFilename = Filename;
148 LastLocLine = LineNo;
149 } else if (LineNo != LastLocLine) {
150 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
151 LastLocLine = LineNo;
152 } else {
153 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
154 }
155}
156
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000157void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000158 // Can't translate locations if a SourceManager isn't available.
159 if (SM == 0) return;
160
161 // TODO: If the parent expression is available, we can print a delta vs its
162 // location.
163 SourceRange R = Node->getSourceRange();
164
165 fprintf(stderr, " <");
166 DumpLocation(R.Begin());
167 if (R.Begin() != R.End()) {
168 fprintf(stderr, ", ");
169 DumpLocation(R.End());
170 }
171 fprintf(stderr, ">");
172
173 // <t2.c:123:421[blah], t2.c:412:321>
174
175}
176
177
178//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000179// Stmt printing methods.
180//===----------------------------------------------------------------------===//
181
182void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000183 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000184}
185
Chris Lattnerf9e05812007-08-09 18:03:18 +0000186void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000187 // FIXME: Need to complete/beautify this... this code simply shows the
188 // nodes are where they need to be.
189 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000190 fprintf(F, "\"typedef %s %s\"",
191 localType->getUnderlyingType().getAsString().c_str(),
192 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000193 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000194 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000195 // Emit storage class for vardecls.
196 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
197 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000198 default: assert(0 && "Unknown storage class!");
199 case VarDecl::None: break;
200 case VarDecl::Extern: fprintf(F, "extern "); break;
201 case VarDecl::Static: fprintf(F, "static "); break;
202 case VarDecl::Auto: fprintf(F, "auto "); break;
203 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000204 }
205 }
206
207 std::string Name = VD->getName();
208 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000209 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000210
211 // If this is a vardecl with an initializer, emit it.
212 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
213 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000214 fprintf(F, " =\n");
215 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000216 }
217 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000218 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000219 } else {
220 // FIXME: "struct x;"
221 assert(0 && "Unexpected decl");
222 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000223}
224
Chris Lattner6000dac2007-08-08 22:51:59 +0000225void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
226 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000227 fprintf(F, "\n");
Steve Naroff94745042007-09-13 23:52:58 +0000228 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000229 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000230 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000231 fprintf(F, "%p ", (void*)D);
232 DumpDeclarator(D);
233 if (D->getNextDeclarator())
234 fprintf(F, "\n");
235 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000236 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000237}
238
Chris Lattner6000dac2007-08-08 22:51:59 +0000239void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
240 DumpStmt(Node);
241 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000242}
243
Chris Lattner6000dac2007-08-08 22:51:59 +0000244void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
245 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000246 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000247}
248
Chris Lattner6000dac2007-08-08 22:51:59 +0000249//===----------------------------------------------------------------------===//
250// Expr printing methods.
251//===----------------------------------------------------------------------===//
252
253void StmtDumper::VisitExpr(Expr *Node) {
254 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000255}
256
257void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
258 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000259
260 fprintf(F, " ");
261 switch (Node->getDecl()->getKind()) {
262 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Chris Lattneraa9fc462007-10-08 21:37:32 +0000263 case Decl::BlockVar: fprintf(F,"BlockVar"); break;
264 case Decl::FileVar: fprintf(F,"FileVar"); break;
265 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000266 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
267 case Decl::Typedef: fprintf(F,"Typedef"); break;
268 case Decl::Struct: fprintf(F,"Struct"); break;
269 case Decl::Union: fprintf(F,"Union"); break;
270 case Decl::Class: fprintf(F,"Class"); break;
271 case Decl::Enum: fprintf(F,"Enum"); break;
272 case Decl::ObjcInterface: fprintf(F,"ObjcInterface"); break;
273 case Decl::ObjcClass: fprintf(F,"ObjcClass"); break;
274 default: fprintf(F,"Decl"); break;
275 }
276
277 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000278}
279
280void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
281 DumpExpr(Node);
282 switch (Node->getIdentType()) {
283 default:
284 assert(0 && "unknown case");
285 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000286 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000287 break;
288 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000289 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000290 break;
291 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000292 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000293 break;
294 }
295}
296
297void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000298 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000299 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000300}
301
302void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
303 DumpExpr(Node);
304
305 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000306 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000307}
308void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
309 DumpExpr(Node);
Chris Lattnerc9bec4b2007-09-22 18:47:25 +0000310 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner6000dac2007-08-08 22:51:59 +0000311}
Chris Lattner5d661452007-08-26 03:42:43 +0000312
Chris Lattner6000dac2007-08-08 22:51:59 +0000313void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000314 DumpExpr(Str);
315 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000316 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000317
Chris Lattner6000dac2007-08-08 22:51:59 +0000318 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000319 switch (char C = Str->getStrData()[i]) {
320 default:
321 if (isprint(C))
322 fputc(C, F);
323 else
324 fprintf(F, "\\%03o", C);
325 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000326 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000327 case '\\': fprintf(F, "\\\\"); break;
328 case '"': fprintf(F, "\\\""); break;
329 case '\n': fprintf(F, "\\n"); break;
330 case '\t': fprintf(F, "\\t"); break;
331 case '\a': fprintf(F, "\\a"); break;
332 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000333 }
334 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000335 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000336}
Chris Lattner17a1a722007-08-30 01:00:35 +0000337
Chris Lattner6000dac2007-08-08 22:51:59 +0000338void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000339 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000340 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000341 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000342}
343void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000344 DumpExpr(Node);
345 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
346 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000347}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000348
Chris Lattner6000dac2007-08-08 22:51:59 +0000349void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000350 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000351 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000352 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000353}
354void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000355 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000356 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000357}
Chris Lattner6000dac2007-08-08 22:51:59 +0000358void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
359 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000360 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000361}
362void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
363 DumpExpr(Node);
364 fprintf(F, " '%s' ComputeTy=",
365 BinaryOperator::getOpcodeStr(Node->getOpcode()));
366 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000367}
Chris Lattner6000dac2007-08-08 22:51:59 +0000368
369// GNU extensions.
370
371void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000372 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000373 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000374}
375
Chris Lattner6000dac2007-08-08 22:51:59 +0000376void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000377 DumpExpr(Node);
378 fprintf(F, " ");
379 DumpType(Node->getArgType1());
380 fprintf(F, " ");
381 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000382}
383
Chris Lattnerf9e05812007-08-09 18:03:18 +0000384//===----------------------------------------------------------------------===//
385// C++ Expressions
386//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000387
388void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000389 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000390 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000391}
392
393void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000394 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000395 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000396}
397
Anders Carlsson55085182007-08-21 17:43:55 +0000398//===----------------------------------------------------------------------===//
399// Obj-C Expressions
400//===----------------------------------------------------------------------===//
401
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000402void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
403 DumpExpr(Node);
404
405 fprintf(F, " ");
406 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000407}
408
Chris Lattner6000dac2007-08-08 22:51:59 +0000409//===----------------------------------------------------------------------===//
410// Stmt method implementations
411//===----------------------------------------------------------------------===//
412
413/// dump - This does a local dump of the specified AST fragment. It dumps the
414/// specified node and a few nodes underneath it, but not the whole subtree.
415/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000416void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000417 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000418 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000419 fprintf(stderr, "\n");
420}
421
422/// dump - This does a local dump of the specified AST fragment. It dumps the
423/// specified node and a few nodes underneath it, but not the whole subtree.
424/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000425void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000426 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000427 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000428 fprintf(stderr, "\n");
429}
430
431/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000432void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000433 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000434 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000435 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000436}
437
438/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
439void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000440 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000441 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000442 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000443}