blob: c6ab29880da066bb98c7acd9094a52d111245c0e [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"
Ted Kremenek91d1d7a2007-10-17 18:36:42 +000017#include "clang/AST/DeclObjC.h"
Chris Lattner6000dac2007-08-08 22:51:59 +000018#include "clang/AST/ExprCXX.h"
Chris Lattnerc7229c32007-10-07 08:58:51 +000019#include "clang/Basic/IdentifierTable.h"
Chris Lattnere300c872007-08-30 06:17:34 +000020#include "clang/Basic/SourceManager.h"
Chris Lattner6000dac2007-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 Lattnerc5598cb2007-08-21 04:04:25 +000030 class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
Chris Lattnere300c872007-08-30 06:17:34 +000031 SourceManager *SM;
Chris Lattner6000dac2007-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 Lattnere300c872007-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 Lattner6000dac2007-08-08 22:51:59 +000044 public:
Chris Lattnere300c872007-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 Lattner6000dac2007-08-08 22:51:59 +000050
Chris Lattnerf9e05812007-08-09 18:03:18 +000051 void DumpSubTree(Stmt *S) {
Chris Lattner6000dac2007-08-08 22:51:59 +000052 // Prune the recursion if not using dump all.
53 if (MaxDepth == 0) return;
54
Chris Lattnerf9e05812007-08-09 18:03:18 +000055 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000056 if (S) {
Chris Lattnerc5598cb2007-08-21 04:04:25 +000057 Visit(S);
Chris Lattnerb3938792007-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 Lattner6000dac2007-08-08 22:51:59 +000068 } else {
69 Indent();
Chris Lattner4a70adb2007-08-26 03:53:29 +000070 fprintf(F, "<<<NULL>>>");
Chris Lattner6000dac2007-08-08 22:51:59 +000071 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000072 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000073 }
74
Chris Lattnerf9e05812007-08-09 18:03:18 +000075 void DumpDeclarator(Decl *D);
Chris Lattner6000dac2007-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 Naroff9dcbfa42007-09-01 21:08:38 +000082 void DumpType(QualType T) {
Chris Lattnerfd8f7da2007-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 Naroff9dcbfa42007-09-01 21:08:38 +000090 void DumpStmt(const Stmt *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000091 Indent();
92 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +000093 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000094 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000095 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000096 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000097 fprintf(F, " ");
98 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +000099 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000100 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000101 void DumpLocation(SourceLocation Loc);
Chris Lattnere300c872007-08-30 06:17:34 +0000102
Chris Lattner17a1a722007-08-30 01:00:35 +0000103 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000104 void VisitStmt(Stmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000105 void VisitDeclStmt(DeclStmt *Node);
106 void VisitLabelStmt(LabelStmt *Node);
107 void VisitGotoStmt(GotoStmt *Node);
108
109 // Exprs
110 void VisitExpr(Expr *Node);
111 void VisitDeclRefExpr(DeclRefExpr *Node);
112 void VisitPreDefinedExpr(PreDefinedExpr *Node);
113 void VisitCharacterLiteral(CharacterLiteral *Node);
114 void VisitIntegerLiteral(IntegerLiteral *Node);
115 void VisitFloatingLiteral(FloatingLiteral *Node);
116 void VisitStringLiteral(StringLiteral *Str);
117 void VisitUnaryOperator(UnaryOperator *Node);
118 void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node);
119 void VisitMemberExpr(MemberExpr *Node);
120 void VisitOCUVectorElementExpr(OCUVectorElementExpr *Node);
121 void VisitBinaryOperator(BinaryOperator *Node);
122 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
123 void VisitAddrLabelExpr(AddrLabelExpr *Node);
124 void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
125
126 // C++
127 void VisitCXXCastExpr(CXXCastExpr *Node);
128 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
129
130 // ObjC
131 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000132 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000133 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000134 };
135}
136
137//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000138// Utilities
139//===----------------------------------------------------------------------===//
140
141void StmtDumper::DumpLocation(SourceLocation Loc) {
142 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
143
144 // The general format we print out is filename:line:col, but we drop pieces
145 // that haven't changed since the last loc printed.
146 const char *Filename = SM->getSourceName(PhysLoc);
147 unsigned LineNo = SM->getLineNumber(PhysLoc);
148 if (strcmp(Filename, LastLocFilename) != 0) {
149 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
150 LastLocFilename = Filename;
151 LastLocLine = LineNo;
152 } else if (LineNo != LastLocLine) {
153 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
154 LastLocLine = LineNo;
155 } else {
156 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
157 }
158}
159
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000160void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000161 // Can't translate locations if a SourceManager isn't available.
162 if (SM == 0) return;
163
164 // TODO: If the parent expression is available, we can print a delta vs its
165 // location.
166 SourceRange R = Node->getSourceRange();
167
168 fprintf(stderr, " <");
Chris Lattner311ff022007-10-16 22:36:42 +0000169 DumpLocation(R.getBegin());
170 if (R.getBegin() != R.getEnd()) {
Chris Lattnere300c872007-08-30 06:17:34 +0000171 fprintf(stderr, ", ");
Chris Lattner311ff022007-10-16 22:36:42 +0000172 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000173 }
174 fprintf(stderr, ">");
175
176 // <t2.c:123:421[blah], t2.c:412:321>
177
178}
179
180
181//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000182// Stmt printing methods.
183//===----------------------------------------------------------------------===//
184
185void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000186 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000187}
188
Chris Lattnerf9e05812007-08-09 18:03:18 +0000189void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000190 // FIXME: Need to complete/beautify this... this code simply shows the
191 // nodes are where they need to be.
192 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000193 fprintf(F, "\"typedef %s %s\"",
194 localType->getUnderlyingType().getAsString().c_str(),
195 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000196 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000197 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000198 // Emit storage class for vardecls.
199 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
200 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000201 default: assert(0 && "Unknown storage class!");
202 case VarDecl::None: break;
203 case VarDecl::Extern: fprintf(F, "extern "); break;
204 case VarDecl::Static: fprintf(F, "static "); break;
205 case VarDecl::Auto: fprintf(F, "auto "); break;
206 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000207 }
208 }
209
210 std::string Name = VD->getName();
211 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000212 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000213
214 // If this is a vardecl with an initializer, emit it.
215 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
216 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000217 fprintf(F, " =\n");
218 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000219 }
220 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000221 fprintf(F, "\"");
Steve Naroff92199282007-11-17 21:37:36 +0000222 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
223 // print a free standing tag decl (e.g. "struct x;").
224 const char *tagname;
225 if (const IdentifierInfo *II = TD->getIdentifier())
226 tagname = II->getName();
227 else
228 tagname = "<anonymous>";
229 fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname);
230 // FIXME: print tag bodies.
Chris Lattner6000dac2007-08-08 22:51:59 +0000231 } else {
Chris Lattner6000dac2007-08-08 22:51:59 +0000232 assert(0 && "Unexpected decl");
233 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000234}
235
Chris Lattner6000dac2007-08-08 22:51:59 +0000236void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
237 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000238 fprintf(F, "\n");
Steve Naroff94745042007-09-13 23:52:58 +0000239 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000240 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000241 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000242 fprintf(F, "%p ", (void*)D);
243 DumpDeclarator(D);
244 if (D->getNextDeclarator())
245 fprintf(F, "\n");
246 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000247 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000248}
249
Chris Lattner6000dac2007-08-08 22:51:59 +0000250void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
251 DumpStmt(Node);
252 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000253}
254
Chris Lattner6000dac2007-08-08 22:51:59 +0000255void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
256 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000257 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000258}
259
Chris Lattner6000dac2007-08-08 22:51:59 +0000260//===----------------------------------------------------------------------===//
261// Expr printing methods.
262//===----------------------------------------------------------------------===//
263
264void StmtDumper::VisitExpr(Expr *Node) {
265 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000266}
267
268void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
269 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000270
271 fprintf(F, " ");
272 switch (Node->getDecl()->getKind()) {
273 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Chris Lattneraa9fc462007-10-08 21:37:32 +0000274 case Decl::BlockVar: fprintf(F,"BlockVar"); break;
275 case Decl::FileVar: fprintf(F,"FileVar"); break;
276 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000277 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
278 case Decl::Typedef: fprintf(F,"Typedef"); break;
279 case Decl::Struct: fprintf(F,"Struct"); break;
280 case Decl::Union: fprintf(F,"Union"); break;
281 case Decl::Class: fprintf(F,"Class"); break;
282 case Decl::Enum: fprintf(F,"Enum"); break;
283 case Decl::ObjcInterface: fprintf(F,"ObjcInterface"); break;
284 case Decl::ObjcClass: fprintf(F,"ObjcClass"); break;
285 default: fprintf(F,"Decl"); break;
286 }
287
288 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000289}
290
291void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
292 DumpExpr(Node);
293 switch (Node->getIdentType()) {
294 default:
295 assert(0 && "unknown case");
296 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000297 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000298 break;
299 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000300 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000301 break;
302 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000303 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000304 break;
305 }
306}
307
308void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000309 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000310 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000311}
312
313void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
314 DumpExpr(Node);
315
316 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000317 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000318}
319void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
320 DumpExpr(Node);
Chris Lattnerc9bec4b2007-09-22 18:47:25 +0000321 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner6000dac2007-08-08 22:51:59 +0000322}
Chris Lattner5d661452007-08-26 03:42:43 +0000323
Chris Lattner6000dac2007-08-08 22:51:59 +0000324void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000325 DumpExpr(Str);
326 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000327 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000328
Chris Lattner6000dac2007-08-08 22:51:59 +0000329 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000330 switch (char C = Str->getStrData()[i]) {
331 default:
332 if (isprint(C))
333 fputc(C, F);
334 else
335 fprintf(F, "\\%03o", C);
336 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000337 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000338 case '\\': fprintf(F, "\\\\"); break;
339 case '"': fprintf(F, "\\\""); break;
340 case '\n': fprintf(F, "\\n"); break;
341 case '\t': fprintf(F, "\\t"); break;
342 case '\a': fprintf(F, "\\a"); break;
343 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000344 }
345 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000346 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000347}
Chris Lattner17a1a722007-08-30 01:00:35 +0000348
Chris Lattner6000dac2007-08-08 22:51:59 +0000349void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000350 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000351 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000352 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000353}
354void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000355 DumpExpr(Node);
356 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
357 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000358}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000359
Chris Lattner6000dac2007-08-08 22:51:59 +0000360void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000361 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000362 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000363 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000364}
365void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000366 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000367 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000368}
Chris Lattner6000dac2007-08-08 22:51:59 +0000369void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
370 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000371 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000372}
373void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
374 DumpExpr(Node);
375 fprintf(F, " '%s' ComputeTy=",
376 BinaryOperator::getOpcodeStr(Node->getOpcode()));
377 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000378}
Chris Lattner6000dac2007-08-08 22:51:59 +0000379
380// GNU extensions.
381
382void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000383 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000384 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000385}
386
Chris Lattner6000dac2007-08-08 22:51:59 +0000387void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000388 DumpExpr(Node);
389 fprintf(F, " ");
390 DumpType(Node->getArgType1());
391 fprintf(F, " ");
392 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000393}
394
Chris Lattnerf9e05812007-08-09 18:03:18 +0000395//===----------------------------------------------------------------------===//
396// C++ Expressions
397//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000398
399void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000400 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000401 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000402}
403
404void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000405 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000406 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000407}
408
Anders Carlsson55085182007-08-21 17:43:55 +0000409//===----------------------------------------------------------------------===//
410// Obj-C Expressions
411//===----------------------------------------------------------------------===//
412
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000413void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
414 DumpExpr(Node);
415
416 fprintf(F, " ");
417 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000418}
419
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000420void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
421 DumpExpr(Node);
422
423 fprintf(F, " ");
424 Selector &selector = Node->getSelector();
Fariborz Jahanianc5c42f52007-10-16 21:07:53 +0000425 fprintf(F, "%s", selector.getName().c_str());
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000426}
427
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000428void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
429 DumpExpr(Node);
430
431 fprintf(F, " ");
432 fprintf(F, "%s", Node->getProtocol()->getName());
433}
Chris Lattner6000dac2007-08-08 22:51:59 +0000434//===----------------------------------------------------------------------===//
435// Stmt method implementations
436//===----------------------------------------------------------------------===//
437
438/// dump - This does a local dump of the specified AST fragment. It dumps the
439/// specified node and a few nodes underneath it, but not the whole subtree.
440/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000441void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000442 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000443 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000444 fprintf(stderr, "\n");
445}
446
447/// dump - This does a local dump of the specified AST fragment. It dumps the
448/// specified node and a few nodes underneath it, but not the whole subtree.
449/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000450void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000451 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000452 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000453 fprintf(stderr, "\n");
454}
455
456/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000457void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000458 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000459 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000460 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000461}
462
463/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
464void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000465 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000466 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000467 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000468}