blob: b36c80b237f441e659f4947beaa072d36516d203 [file] [log] [blame]
Chris Lattner95578782007-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"
Ted Kremenek10364dd2007-10-17 18:36:42 +000017#include "clang/AST/DeclObjC.h"
Chris Lattner95578782007-08-08 22:51:59 +000018#include "clang/AST/ExprCXX.h"
Chris Lattner2fd1c652007-10-07 08:58:51 +000019#include "clang/Basic/IdentifierTable.h"
Chris Lattner99b994b2007-08-30 06:17:34 +000020#include "clang/Basic/SourceManager.h"
Chris Lattner95578782007-08-08 22:51:59 +000021#include "llvm/Support/Compiler.h"
22#include <cstdio>
23using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// StmtDumper Visitor
27//===----------------------------------------------------------------------===//
28
29namespace {
Chris Lattner7ba21fa2007-08-21 04:04:25 +000030 class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
Chris Lattner99b994b2007-08-30 06:17:34 +000031 SourceManager *SM;
Chris Lattner95578782007-08-08 22:51:59 +000032 FILE *F;
33 unsigned IndentLevel;
34
35 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
36 /// the first few levels of an AST. This keeps track of how many ast levels
37 /// are left.
38 unsigned MaxDepth;
Chris Lattner99b994b2007-08-30 06:17:34 +000039
40 /// LastLocFilename/LastLocLine - Keep track of the last location we print
41 /// out so that we can print out deltas from then on out.
42 const char *LastLocFilename;
43 unsigned LastLocLine;
Chris Lattner95578782007-08-08 22:51:59 +000044 public:
Chris Lattner99b994b2007-08-30 06:17:34 +000045 StmtDumper(SourceManager *sm, FILE *f, unsigned maxDepth)
46 : SM(sm), F(f), IndentLevel(0-1), MaxDepth(maxDepth) {
47 LastLocFilename = "";
48 LastLocLine = ~0U;
49 }
Chris Lattner95578782007-08-08 22:51:59 +000050
Chris Lattner412a4192007-08-09 18:03:18 +000051 void DumpSubTree(Stmt *S) {
Chris Lattner95578782007-08-08 22:51:59 +000052 // Prune the recursion if not using dump all.
53 if (MaxDepth == 0) return;
54
Chris Lattner412a4192007-08-09 18:03:18 +000055 ++IndentLevel;
Chris Lattner95578782007-08-08 22:51:59 +000056 if (S) {
Chris Lattner7ba21fa2007-08-21 04:04:25 +000057 Visit(S);
Chris Lattnerf3e2a252007-08-30 00:53:54 +000058
59 // Print out children.
60 Stmt::child_iterator CI = S->child_begin(), CE = S->child_end();
61 if (CI != CE) {
62 while (CI != CE) {
63 fprintf(F, "\n");
64 DumpSubTree(*CI++);
65 }
66 }
67 fprintf(F, ")");
Chris Lattner95578782007-08-08 22:51:59 +000068 } else {
69 Indent();
Chris Lattnerf38cbc72007-08-26 03:53:29 +000070 fprintf(F, "<<<NULL>>>");
Chris Lattner95578782007-08-08 22:51:59 +000071 }
Chris Lattner412a4192007-08-09 18:03:18 +000072 --IndentLevel;
Chris Lattner95578782007-08-08 22:51:59 +000073 }
74
Chris Lattner412a4192007-08-09 18:03:18 +000075 void DumpDeclarator(Decl *D);
Chris Lattner95578782007-08-08 22:51:59 +000076
77 void Indent() const {
78 for (int i = 0, e = IndentLevel; i < e; ++i)
79 fprintf(F, " ");
80 }
81
Steve Naroffa610eab2007-09-01 21:08:38 +000082 void DumpType(QualType T) {
Chris Lattner7e4a2c72007-08-09 00:36:22 +000083 fprintf(F, "'%s'", T.getAsString().c_str());
84
85 // If the type is directly a typedef, strip off typedefness to give at
86 // least one level of concreteness.
87 if (TypedefType *TDT = dyn_cast<TypedefType>(T))
88 fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
89 }
Steve Naroffa610eab2007-09-01 21:08:38 +000090 void DumpStmt(const Stmt *Node) {
Chris Lattner95578782007-08-08 22:51:59 +000091 Indent();
92 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
Steve Naroffa610eab2007-09-01 21:08:38 +000093 DumpSourceRange(Node);
Chris Lattner95578782007-08-08 22:51:59 +000094 }
Steve Naroffa610eab2007-09-01 21:08:38 +000095 void DumpExpr(const Expr *Node) {
Chris Lattner95578782007-08-08 22:51:59 +000096 DumpStmt(Node);
Chris Lattner7e4a2c72007-08-09 00:36:22 +000097 fprintf(F, " ");
98 DumpType(Node->getType());
Chris Lattner95578782007-08-08 22:51:59 +000099 }
Steve Naroffa610eab2007-09-01 21:08:38 +0000100 void DumpSourceRange(const Stmt *Node);
Chris Lattner99b994b2007-08-30 06:17:34 +0000101 void DumpLocation(SourceLocation Loc);
Chris Lattner99b994b2007-08-30 06:17:34 +0000102
Chris Lattner35122932007-08-30 01:00:35 +0000103 // Stmts.
Chris Lattner7ba21fa2007-08-21 04:04:25 +0000104 void VisitStmt(Stmt *Node);
Chris Lattner35122932007-08-30 01:00:35 +0000105 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);
Fariborz Jahanianf807c202007-10-16 20:40:23 +0000131 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +0000132 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Chris Lattner95578782007-08-08 22:51:59 +0000133 };
134}
135
136//===----------------------------------------------------------------------===//
Chris Lattner99b994b2007-08-30 06:17:34 +0000137// Utilities
138//===----------------------------------------------------------------------===//
139
140void StmtDumper::DumpLocation(SourceLocation Loc) {
141 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
142
143 // The general format we print out is filename:line:col, but we drop pieces
144 // that haven't changed since the last loc printed.
145 const char *Filename = SM->getSourceName(PhysLoc);
146 unsigned LineNo = SM->getLineNumber(PhysLoc);
147 if (strcmp(Filename, LastLocFilename) != 0) {
148 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
149 LastLocFilename = Filename;
150 LastLocLine = LineNo;
151 } else if (LineNo != LastLocLine) {
152 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
153 LastLocLine = LineNo;
154 } else {
155 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
156 }
157}
158
Steve Naroffa610eab2007-09-01 21:08:38 +0000159void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattner99b994b2007-08-30 06:17:34 +0000160 // Can't translate locations if a SourceManager isn't available.
161 if (SM == 0) return;
162
163 // TODO: If the parent expression is available, we can print a delta vs its
164 // location.
165 SourceRange R = Node->getSourceRange();
166
167 fprintf(stderr, " <");
Chris Lattner6fe8b272007-10-16 22:36:42 +0000168 DumpLocation(R.getBegin());
169 if (R.getBegin() != R.getEnd()) {
Chris Lattner99b994b2007-08-30 06:17:34 +0000170 fprintf(stderr, ", ");
Chris Lattner6fe8b272007-10-16 22:36:42 +0000171 DumpLocation(R.getEnd());
Chris Lattner99b994b2007-08-30 06:17:34 +0000172 }
173 fprintf(stderr, ">");
174
175 // <t2.c:123:421[blah], t2.c:412:321>
176
177}
178
179
180//===----------------------------------------------------------------------===//
Chris Lattner95578782007-08-08 22:51:59 +0000181// Stmt printing methods.
182//===----------------------------------------------------------------------===//
183
184void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner35122932007-08-30 01:00:35 +0000185 DumpStmt(Node);
Chris Lattner95578782007-08-08 22:51:59 +0000186}
187
Chris Lattner412a4192007-08-09 18:03:18 +0000188void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner95578782007-08-08 22:51:59 +0000189 // FIXME: Need to complete/beautify this... this code simply shows the
190 // nodes are where they need to be.
191 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattner412a4192007-08-09 18:03:18 +0000192 fprintf(F, "\"typedef %s %s\"",
193 localType->getUnderlyingType().getAsString().c_str(),
194 localType->getName());
Chris Lattner95578782007-08-08 22:51:59 +0000195 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattner412a4192007-08-09 18:03:18 +0000196 fprintf(F, "\"");
Chris Lattner95578782007-08-08 22:51:59 +0000197 // Emit storage class for vardecls.
198 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
199 switch (V->getStorageClass()) {
Chris Lattner412a4192007-08-09 18:03:18 +0000200 default: assert(0 && "Unknown storage class!");
201 case VarDecl::None: break;
202 case VarDecl::Extern: fprintf(F, "extern "); break;
203 case VarDecl::Static: fprintf(F, "static "); break;
204 case VarDecl::Auto: fprintf(F, "auto "); break;
205 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner95578782007-08-08 22:51:59 +0000206 }
207 }
208
209 std::string Name = VD->getName();
210 VD->getType().getAsStringInternal(Name);
Chris Lattner412a4192007-08-09 18:03:18 +0000211 fprintf(F, "%s", Name.c_str());
Chris Lattner95578782007-08-08 22:51:59 +0000212
213 // If this is a vardecl with an initializer, emit it.
214 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
215 if (V->getInit()) {
Chris Lattner412a4192007-08-09 18:03:18 +0000216 fprintf(F, " =\n");
217 DumpSubTree(V->getInit());
Chris Lattner95578782007-08-08 22:51:59 +0000218 }
219 }
Chris Lattner412a4192007-08-09 18:03:18 +0000220 fprintf(F, "\"");
Steve Naroffedafc0b2007-11-17 21:37:36 +0000221 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
222 // print a free standing tag decl (e.g. "struct x;").
223 const char *tagname;
224 if (const IdentifierInfo *II = TD->getIdentifier())
225 tagname = II->getName();
226 else
227 tagname = "<anonymous>";
228 fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname);
229 // FIXME: print tag bodies.
Chris Lattner95578782007-08-08 22:51:59 +0000230 } else {
Chris Lattner95578782007-08-08 22:51:59 +0000231 assert(0 && "Unexpected decl");
232 }
Chris Lattner95578782007-08-08 22:51:59 +0000233}
234
Chris Lattner95578782007-08-08 22:51:59 +0000235void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
236 DumpStmt(Node);
237 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner95578782007-08-08 22:51:59 +0000238}
239
Chris Lattner95578782007-08-08 22:51:59 +0000240void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
241 DumpStmt(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000242 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner95578782007-08-08 22:51:59 +0000243}
244
Chris Lattner95578782007-08-08 22:51:59 +0000245//===----------------------------------------------------------------------===//
246// Expr printing methods.
247//===----------------------------------------------------------------------===//
248
249void StmtDumper::VisitExpr(Expr *Node) {
250 DumpExpr(Node);
Chris Lattner95578782007-08-08 22:51:59 +0000251}
252
253void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
254 DumpExpr(Node);
Ted Kremenek97a0ad52007-09-10 17:32:55 +0000255
256 fprintf(F, " ");
257 switch (Node->getDecl()->getKind()) {
258 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Chris Lattner3289bca2007-10-08 21:37:32 +0000259 case Decl::BlockVar: fprintf(F,"BlockVar"); break;
260 case Decl::FileVar: fprintf(F,"FileVar"); break;
261 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenek97a0ad52007-09-10 17:32:55 +0000262 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
263 case Decl::Typedef: fprintf(F,"Typedef"); break;
264 case Decl::Struct: fprintf(F,"Struct"); break;
265 case Decl::Union: fprintf(F,"Union"); break;
266 case Decl::Class: fprintf(F,"Class"); break;
267 case Decl::Enum: fprintf(F,"Enum"); break;
268 case Decl::ObjcInterface: fprintf(F,"ObjcInterface"); break;
269 case Decl::ObjcClass: fprintf(F,"ObjcClass"); break;
270 default: fprintf(F,"Decl"); break;
271 }
272
273 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner95578782007-08-08 22:51:59 +0000274}
275
276void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
277 DumpExpr(Node);
278 switch (Node->getIdentType()) {
279 default:
280 assert(0 && "unknown case");
281 case PreDefinedExpr::Func:
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000282 fprintf(F, " __func__");
Chris Lattner95578782007-08-08 22:51:59 +0000283 break;
284 case PreDefinedExpr::Function:
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000285 fprintf(F, " __FUNCTION__");
Chris Lattner95578782007-08-08 22:51:59 +0000286 break;
287 case PreDefinedExpr::PrettyFunction:
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000288 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner95578782007-08-08 22:51:59 +0000289 break;
290 }
291}
292
293void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattner9a6d6ae2007-08-09 01:04:32 +0000294 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000295 fprintf(F, " %d", Node->getValue());
Chris Lattner95578782007-08-08 22:51:59 +0000296}
297
298void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
299 DumpExpr(Node);
300
301 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000302 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner95578782007-08-08 22:51:59 +0000303}
304void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
305 DumpExpr(Node);
Chris Lattner7f298762007-09-22 18:47:25 +0000306 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner95578782007-08-08 22:51:59 +0000307}
Chris Lattner1de66eb2007-08-26 03:42:43 +0000308
Chris Lattner95578782007-08-08 22:51:59 +0000309void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattner9a6d6ae2007-08-09 01:04:32 +0000310 DumpExpr(Str);
311 // FIXME: this doesn't print wstrings right.
Chris Lattner9fb40242007-08-09 17:14:24 +0000312 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattner9a6d6ae2007-08-09 01:04:32 +0000313
Chris Lattner95578782007-08-08 22:51:59 +0000314 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner9fb40242007-08-09 17:14:24 +0000315 switch (char C = Str->getStrData()[i]) {
316 default:
317 if (isprint(C))
318 fputc(C, F);
319 else
320 fprintf(F, "\\%03o", C);
321 break;
Chris Lattner95578782007-08-08 22:51:59 +0000322 // Handle some common ones to make dumps prettier.
Chris Lattner9fb40242007-08-09 17:14:24 +0000323 case '\\': fprintf(F, "\\\\"); break;
324 case '"': fprintf(F, "\\\""); break;
325 case '\n': fprintf(F, "\\n"); break;
326 case '\t': fprintf(F, "\\t"); break;
327 case '\a': fprintf(F, "\\a"); break;
328 case '\b': fprintf(F, "\\b"); break;
Chris Lattner95578782007-08-08 22:51:59 +0000329 }
330 }
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000331 fprintf(F, "\"");
Chris Lattner95578782007-08-08 22:51:59 +0000332}
Chris Lattner35122932007-08-30 01:00:35 +0000333
Chris Lattner95578782007-08-08 22:51:59 +0000334void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000335 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000336 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000337 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner95578782007-08-08 22:51:59 +0000338}
339void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000340 DumpExpr(Node);
341 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
342 DumpType(Node->getArgumentType());
Chris Lattner95578782007-08-08 22:51:59 +0000343}
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000344
Chris Lattner95578782007-08-08 22:51:59 +0000345void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000346 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000347 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000348 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner95578782007-08-08 22:51:59 +0000349}
350void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000351 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000352 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner95578782007-08-08 22:51:59 +0000353}
Chris Lattner95578782007-08-08 22:51:59 +0000354void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
355 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000356 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner06078d22007-08-25 02:00:02 +0000357}
358void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
359 DumpExpr(Node);
360 fprintf(F, " '%s' ComputeTy=",
361 BinaryOperator::getOpcodeStr(Node->getOpcode()));
362 DumpType(Node->getComputationType());
Chris Lattner95578782007-08-08 22:51:59 +0000363}
Chris Lattner95578782007-08-08 22:51:59 +0000364
365// GNU extensions.
366
367void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000368 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000369 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner95578782007-08-08 22:51:59 +0000370}
371
Chris Lattner95578782007-08-08 22:51:59 +0000372void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000373 DumpExpr(Node);
374 fprintf(F, " ");
375 DumpType(Node->getArgType1());
376 fprintf(F, " ");
377 DumpType(Node->getArgType2());
Chris Lattner95578782007-08-08 22:51:59 +0000378}
379
Chris Lattner412a4192007-08-09 18:03:18 +0000380//===----------------------------------------------------------------------===//
381// C++ Expressions
382//===----------------------------------------------------------------------===//
Chris Lattner95578782007-08-08 22:51:59 +0000383
384void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000385 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000386 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner95578782007-08-08 22:51:59 +0000387}
388
389void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattnerb4ee7b32007-08-09 17:35:30 +0000390 DumpExpr(Node);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000391 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner95578782007-08-08 22:51:59 +0000392}
393
Anders Carlssona66cad42007-08-21 17:43:55 +0000394//===----------------------------------------------------------------------===//
395// Obj-C Expressions
396//===----------------------------------------------------------------------===//
397
Anders Carlsson8be1d402007-08-22 15:14:15 +0000398void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
399 DumpExpr(Node);
400
401 fprintf(F, " ");
402 DumpType(Node->getEncodedType());
Anders Carlsson8be1d402007-08-22 15:14:15 +0000403}
404
Fariborz Jahanianf807c202007-10-16 20:40:23 +0000405void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
406 DumpExpr(Node);
407
408 fprintf(F, " ");
409 Selector &selector = Node->getSelector();
Fariborz Jahanianda25d112007-10-16 21:07:53 +0000410 fprintf(F, "%s", selector.getName().c_str());
Fariborz Jahanianf807c202007-10-16 20:40:23 +0000411}
412
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +0000413void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
414 DumpExpr(Node);
415
416 fprintf(F, " ");
417 fprintf(F, "%s", Node->getProtocol()->getName());
418}
Chris Lattner95578782007-08-08 22:51:59 +0000419//===----------------------------------------------------------------------===//
420// Stmt method implementations
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 Lattner99b994b2007-08-30 06:17:34 +0000426void Stmt::dump(SourceManager &SM) const {
Chris Lattnerbbc51ad2007-08-30 00:40:08 +0000427 StmtDumper P(&SM, stderr, 4);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000428 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattnerbbc51ad2007-08-30 00:40:08 +0000429 fprintf(stderr, "\n");
430}
431
432/// dump - This does a local dump of the specified AST fragment. It dumps the
433/// specified node and a few nodes underneath it, but not the whole subtree.
434/// This is useful in a debugger.
Chris Lattner95578782007-08-08 22:51:59 +0000435void Stmt::dump() const {
Chris Lattnerbbc51ad2007-08-30 00:40:08 +0000436 StmtDumper P(0, stderr, 4);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000437 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattnerbbc51ad2007-08-30 00:40:08 +0000438 fprintf(stderr, "\n");
439}
440
441/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattner99b994b2007-08-30 06:17:34 +0000442void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattnerbbc51ad2007-08-30 00:40:08 +0000443 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000444 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner7eaddd72007-08-10 21:51:12 +0000445 fprintf(stderr, "\n");
Chris Lattner95578782007-08-08 22:51:59 +0000446}
447
448/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
449void Stmt::dumpAll() const {
Chris Lattnerbbc51ad2007-08-30 00:40:08 +0000450 StmtDumper P(0, stderr, ~0U);
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000451 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner7eaddd72007-08-10 21:51:12 +0000452 fprintf(stderr, "\n");
Chris Lattner95578782007-08-08 22:51:59 +0000453}