blob: b7a31229c7b8ea1b283a4ab35f58a8d8b0084599 [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//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner6000dac2007-08-08 22:51:59 +00007//
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) {
Ted Kremenek5399ce22007-12-12 06:59:42 +000057 if (DeclStmt* DS = dyn_cast<DeclStmt>(S))
58 VisitDeclStmt(DS);
59 else {
60 Visit(S);
61
62 // Print out children.
63 Stmt::child_iterator CI = S->child_begin(), CE = S->child_end();
64 if (CI != CE) {
65 while (CI != CE) {
66 fprintf(F, "\n");
67 DumpSubTree(*CI++);
68 }
Chris Lattnerb3938792007-08-30 00:53:54 +000069 }
Ted Kremenek5399ce22007-12-12 06:59:42 +000070 fprintf(F, ")");
Chris Lattnerb3938792007-08-30 00:53:54 +000071 }
Chris Lattner6000dac2007-08-08 22:51:59 +000072 } else {
73 Indent();
Chris Lattner4a70adb2007-08-26 03:53:29 +000074 fprintf(F, "<<<NULL>>>");
Chris Lattner6000dac2007-08-08 22:51:59 +000075 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000076 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000077 }
78
Chris Lattnerf9e05812007-08-09 18:03:18 +000079 void DumpDeclarator(Decl *D);
Chris Lattner6000dac2007-08-08 22:51:59 +000080
81 void Indent() const {
82 for (int i = 0, e = IndentLevel; i < e; ++i)
83 fprintf(F, " ");
84 }
85
Steve Naroff9dcbfa42007-09-01 21:08:38 +000086 void DumpType(QualType T) {
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000087 fprintf(F, "'%s'", T.getAsString().c_str());
88
89 // If the type is directly a typedef, strip off typedefness to give at
90 // least one level of concreteness.
91 if (TypedefType *TDT = dyn_cast<TypedefType>(T))
92 fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
93 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000094 void DumpStmt(const Stmt *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000095 Indent();
96 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +000097 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +000098 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000099 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000100 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000101 fprintf(F, " ");
102 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000103 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000104 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000105 void DumpLocation(SourceLocation Loc);
Chris Lattnere300c872007-08-30 06:17:34 +0000106
Chris Lattner17a1a722007-08-30 01:00:35 +0000107 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000108 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000109 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000110 void VisitLabelStmt(LabelStmt *Node);
111 void VisitGotoStmt(GotoStmt *Node);
112
113 // Exprs
114 void VisitExpr(Expr *Node);
115 void VisitDeclRefExpr(DeclRefExpr *Node);
116 void VisitPreDefinedExpr(PreDefinedExpr *Node);
117 void VisitCharacterLiteral(CharacterLiteral *Node);
118 void VisitIntegerLiteral(IntegerLiteral *Node);
119 void VisitFloatingLiteral(FloatingLiteral *Node);
120 void VisitStringLiteral(StringLiteral *Str);
121 void VisitUnaryOperator(UnaryOperator *Node);
122 void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node);
123 void VisitMemberExpr(MemberExpr *Node);
124 void VisitOCUVectorElementExpr(OCUVectorElementExpr *Node);
125 void VisitBinaryOperator(BinaryOperator *Node);
126 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
127 void VisitAddrLabelExpr(AddrLabelExpr *Node);
128 void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
129
130 // C++
131 void VisitCXXCastExpr(CXXCastExpr *Node);
132 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
133
134 // ObjC
135 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000136 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000137 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000138 };
139}
140
141//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000142// Utilities
143//===----------------------------------------------------------------------===//
144
145void StmtDumper::DumpLocation(SourceLocation Loc) {
146 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
147
148 // The general format we print out is filename:line:col, but we drop pieces
149 // that haven't changed since the last loc printed.
150 const char *Filename = SM->getSourceName(PhysLoc);
151 unsigned LineNo = SM->getLineNumber(PhysLoc);
152 if (strcmp(Filename, LastLocFilename) != 0) {
153 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
154 LastLocFilename = Filename;
155 LastLocLine = LineNo;
156 } else if (LineNo != LastLocLine) {
157 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
158 LastLocLine = LineNo;
159 } else {
160 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
161 }
162}
163
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000164void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000165 // Can't translate locations if a SourceManager isn't available.
166 if (SM == 0) return;
167
168 // TODO: If the parent expression is available, we can print a delta vs its
169 // location.
170 SourceRange R = Node->getSourceRange();
171
172 fprintf(stderr, " <");
Chris Lattner311ff022007-10-16 22:36:42 +0000173 DumpLocation(R.getBegin());
174 if (R.getBegin() != R.getEnd()) {
Chris Lattnere300c872007-08-30 06:17:34 +0000175 fprintf(stderr, ", ");
Chris Lattner311ff022007-10-16 22:36:42 +0000176 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000177 }
178 fprintf(stderr, ">");
179
180 // <t2.c:123:421[blah], t2.c:412:321>
181
182}
183
184
185//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000186// Stmt printing methods.
187//===----------------------------------------------------------------------===//
188
189void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000190 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000191}
192
Chris Lattnerf9e05812007-08-09 18:03:18 +0000193void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000194 // FIXME: Need to complete/beautify this... this code simply shows the
195 // nodes are where they need to be.
196 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000197 fprintf(F, "\"typedef %s %s\"",
198 localType->getUnderlyingType().getAsString().c_str(),
199 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000200 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000201 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000202 // Emit storage class for vardecls.
203 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
204 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000205 default: assert(0 && "Unknown storage class!");
206 case VarDecl::None: break;
207 case VarDecl::Extern: fprintf(F, "extern "); break;
208 case VarDecl::Static: fprintf(F, "static "); break;
209 case VarDecl::Auto: fprintf(F, "auto "); break;
210 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000211 }
212 }
213
214 std::string Name = VD->getName();
215 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000216 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000217
218 // If this is a vardecl with an initializer, emit it.
219 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
220 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000221 fprintf(F, " =\n");
222 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000223 }
224 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000225 fprintf(F, "\"");
Steve Naroff92199282007-11-17 21:37:36 +0000226 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
227 // print a free standing tag decl (e.g. "struct x;").
228 const char *tagname;
229 if (const IdentifierInfo *II = TD->getIdentifier())
230 tagname = II->getName();
231 else
232 tagname = "<anonymous>";
233 fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname);
234 // FIXME: print tag bodies.
Chris Lattner6000dac2007-08-08 22:51:59 +0000235 } else {
Chris Lattner6000dac2007-08-08 22:51:59 +0000236 assert(0 && "Unexpected decl");
237 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000238}
239
Ted Kremenek5399ce22007-12-12 06:59:42 +0000240void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
241 DumpStmt(Node);
242 fprintf(F,"\n");
243 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
244 ++IndentLevel;
245 Indent();
246 fprintf(F, "%p ", (void*) D);
247 DumpDeclarator(D);
248 if (D->getNextDeclarator())
249 fprintf(F,"\n");
250 --IndentLevel;
251 }
252}
253
Chris Lattner6000dac2007-08-08 22:51:59 +0000254void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
255 DumpStmt(Node);
256 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000257}
258
Chris Lattner6000dac2007-08-08 22:51:59 +0000259void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
260 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000261 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000262}
263
Chris Lattner6000dac2007-08-08 22:51:59 +0000264//===----------------------------------------------------------------------===//
265// Expr printing methods.
266//===----------------------------------------------------------------------===//
267
268void StmtDumper::VisitExpr(Expr *Node) {
269 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000270}
271
272void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
273 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000274
275 fprintf(F, " ");
276 switch (Node->getDecl()->getKind()) {
277 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Chris Lattneraa9fc462007-10-08 21:37:32 +0000278 case Decl::BlockVar: fprintf(F,"BlockVar"); break;
279 case Decl::FileVar: fprintf(F,"FileVar"); break;
280 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000281 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
282 case Decl::Typedef: fprintf(F,"Typedef"); break;
283 case Decl::Struct: fprintf(F,"Struct"); break;
284 case Decl::Union: fprintf(F,"Union"); break;
285 case Decl::Class: fprintf(F,"Class"); break;
286 case Decl::Enum: fprintf(F,"Enum"); break;
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000287 case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
288 case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000289 default: fprintf(F,"Decl"); break;
290 }
291
292 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000293}
294
295void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
296 DumpExpr(Node);
297 switch (Node->getIdentType()) {
298 default:
299 assert(0 && "unknown case");
300 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000301 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000302 break;
303 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000304 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000305 break;
306 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000307 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000308 break;
309 }
310}
311
312void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000313 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000314 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000315}
316
317void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
318 DumpExpr(Node);
319
320 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000321 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000322}
323void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
324 DumpExpr(Node);
Chris Lattnerc9bec4b2007-09-22 18:47:25 +0000325 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner6000dac2007-08-08 22:51:59 +0000326}
Chris Lattner5d661452007-08-26 03:42:43 +0000327
Chris Lattner6000dac2007-08-08 22:51:59 +0000328void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000329 DumpExpr(Str);
330 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000331 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000332
Chris Lattner6000dac2007-08-08 22:51:59 +0000333 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000334 switch (char C = Str->getStrData()[i]) {
335 default:
336 if (isprint(C))
337 fputc(C, F);
338 else
339 fprintf(F, "\\%03o", C);
340 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000341 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000342 case '\\': fprintf(F, "\\\\"); break;
343 case '"': fprintf(F, "\\\""); break;
344 case '\n': fprintf(F, "\\n"); break;
345 case '\t': fprintf(F, "\\t"); break;
346 case '\a': fprintf(F, "\\a"); break;
347 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000348 }
349 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000350 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000351}
Chris Lattner17a1a722007-08-30 01:00:35 +0000352
Chris Lattner6000dac2007-08-08 22:51:59 +0000353void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000354 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000355 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000356 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000357}
358void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000359 DumpExpr(Node);
360 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
361 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000362}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000363
Chris Lattner6000dac2007-08-08 22:51:59 +0000364void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000365 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000366 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000367 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000368}
369void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000370 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000371 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000372}
Chris Lattner6000dac2007-08-08 22:51:59 +0000373void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
374 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000375 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000376}
377void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
378 DumpExpr(Node);
379 fprintf(F, " '%s' ComputeTy=",
380 BinaryOperator::getOpcodeStr(Node->getOpcode()));
381 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000382}
Chris Lattner6000dac2007-08-08 22:51:59 +0000383
384// GNU extensions.
385
386void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000387 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000388 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000389}
390
Chris Lattner6000dac2007-08-08 22:51:59 +0000391void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000392 DumpExpr(Node);
393 fprintf(F, " ");
394 DumpType(Node->getArgType1());
395 fprintf(F, " ");
396 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000397}
398
Chris Lattnerf9e05812007-08-09 18:03:18 +0000399//===----------------------------------------------------------------------===//
400// C++ Expressions
401//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000402
403void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000404 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000405 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000406}
407
408void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000409 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000410 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000411}
412
Anders Carlsson55085182007-08-21 17:43:55 +0000413//===----------------------------------------------------------------------===//
414// Obj-C Expressions
415//===----------------------------------------------------------------------===//
416
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000417void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
418 DumpExpr(Node);
419
420 fprintf(F, " ");
421 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000422}
423
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000424void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
425 DumpExpr(Node);
426
427 fprintf(F, " ");
428 Selector &selector = Node->getSelector();
Fariborz Jahanianc5c42f52007-10-16 21:07:53 +0000429 fprintf(F, "%s", selector.getName().c_str());
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000430}
431
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000432void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
433 DumpExpr(Node);
434
435 fprintf(F, " ");
436 fprintf(F, "%s", Node->getProtocol()->getName());
437}
Chris Lattner6000dac2007-08-08 22:51:59 +0000438//===----------------------------------------------------------------------===//
439// Stmt method implementations
440//===----------------------------------------------------------------------===//
441
442/// dump - This does a local dump of the specified AST fragment. It dumps the
443/// specified node and a few nodes underneath it, but not the whole subtree.
444/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000445void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000446 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000447 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000448 fprintf(stderr, "\n");
449}
450
451/// dump - This does a local dump of the specified AST fragment. It dumps the
452/// specified node and a few nodes underneath it, but not the whole subtree.
453/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000454void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000455 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000456 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000457 fprintf(stderr, "\n");
458}
459
460/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000461void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000462 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000463 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000464 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000465}
466
467/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
468void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000469 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000470 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000471 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000472}