blob: 082d2a2259571c1f97b5349ea88caa0aad158345 [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.
Chris Lattnerbad37852008-04-02 05:06:23 +000091 if (TypedefType *TDT = dyn_cast<TypedefType>(T)) {
92 QualType Simplified =
93 TDT->LookThroughTypedefs().getQualifiedType(T.getCVRQualifiers());
94 fprintf(F, ":'%s'", Simplified.getAsString().c_str());
95 }
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000096 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +000097 void DumpStmt(const Stmt *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000098 Indent();
99 fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000100 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000101 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000102 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000103 DumpStmt(Node);
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000104 fprintf(F, " ");
105 DumpType(Node->getType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000106 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000107 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000108 void DumpLocation(SourceLocation Loc);
Chris Lattnere300c872007-08-30 06:17:34 +0000109
Chris Lattner17a1a722007-08-30 01:00:35 +0000110 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000111 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000112 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000113 void VisitLabelStmt(LabelStmt *Node);
114 void VisitGotoStmt(GotoStmt *Node);
115
116 // Exprs
117 void VisitExpr(Expr *Node);
118 void VisitDeclRefExpr(DeclRefExpr *Node);
119 void VisitPreDefinedExpr(PreDefinedExpr *Node);
120 void VisitCharacterLiteral(CharacterLiteral *Node);
121 void VisitIntegerLiteral(IntegerLiteral *Node);
122 void VisitFloatingLiteral(FloatingLiteral *Node);
123 void VisitStringLiteral(StringLiteral *Str);
124 void VisitUnaryOperator(UnaryOperator *Node);
125 void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node);
126 void VisitMemberExpr(MemberExpr *Node);
Nate Begeman213541a2008-04-18 23:10:10 +0000127 void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000128 void VisitBinaryOperator(BinaryOperator *Node);
129 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
130 void VisitAddrLabelExpr(AddrLabelExpr *Node);
131 void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
132
133 // C++
134 void VisitCXXCastExpr(CXXCastExpr *Node);
135 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
136
137 // ObjC
138 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000139 void VisitObjCMessageExpr(ObjCMessageExpr* Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000140 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000141 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000142 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000143 };
144}
145
146//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000147// Utilities
148//===----------------------------------------------------------------------===//
149
150void StmtDumper::DumpLocation(SourceLocation Loc) {
151 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
152
153 // The general format we print out is filename:line:col, but we drop pieces
154 // that haven't changed since the last loc printed.
155 const char *Filename = SM->getSourceName(PhysLoc);
156 unsigned LineNo = SM->getLineNumber(PhysLoc);
157 if (strcmp(Filename, LastLocFilename) != 0) {
158 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
159 LastLocFilename = Filename;
160 LastLocLine = LineNo;
161 } else if (LineNo != LastLocLine) {
162 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
163 LastLocLine = LineNo;
164 } else {
165 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
166 }
167}
168
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000169void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000170 // Can't translate locations if a SourceManager isn't available.
171 if (SM == 0) return;
172
173 // TODO: If the parent expression is available, we can print a delta vs its
174 // location.
175 SourceRange R = Node->getSourceRange();
176
177 fprintf(stderr, " <");
Chris Lattner311ff022007-10-16 22:36:42 +0000178 DumpLocation(R.getBegin());
179 if (R.getBegin() != R.getEnd()) {
Chris Lattnere300c872007-08-30 06:17:34 +0000180 fprintf(stderr, ", ");
Chris Lattner311ff022007-10-16 22:36:42 +0000181 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000182 }
183 fprintf(stderr, ">");
184
185 // <t2.c:123:421[blah], t2.c:412:321>
186
187}
188
189
190//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000191// Stmt printing methods.
192//===----------------------------------------------------------------------===//
193
194void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000195 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000196}
197
Chris Lattnerf9e05812007-08-09 18:03:18 +0000198void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000199 // FIXME: Need to complete/beautify this... this code simply shows the
200 // nodes are where they need to be.
201 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000202 fprintf(F, "\"typedef %s %s\"",
203 localType->getUnderlyingType().getAsString().c_str(),
204 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000205 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000206 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000207 // Emit storage class for vardecls.
208 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
209 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000210 default: assert(0 && "Unknown storage class!");
211 case VarDecl::None: break;
212 case VarDecl::Extern: fprintf(F, "extern "); break;
213 case VarDecl::Static: fprintf(F, "static "); break;
214 case VarDecl::Auto: fprintf(F, "auto "); break;
215 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000216 }
217 }
218
219 std::string Name = VD->getName();
220 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000221 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000222
223 // If this is a vardecl with an initializer, emit it.
224 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
225 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000226 fprintf(F, " =\n");
227 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000228 }
229 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000230 fprintf(F, "\"");
Steve Naroff92199282007-11-17 21:37:36 +0000231 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
232 // print a free standing tag decl (e.g. "struct x;").
233 const char *tagname;
234 if (const IdentifierInfo *II = TD->getIdentifier())
235 tagname = II->getName();
236 else
237 tagname = "<anonymous>";
238 fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname);
239 // FIXME: print tag bodies.
Chris Lattner6000dac2007-08-08 22:51:59 +0000240 } else {
Chris Lattner6000dac2007-08-08 22:51:59 +0000241 assert(0 && "Unexpected decl");
242 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000243}
244
Ted Kremenek5399ce22007-12-12 06:59:42 +0000245void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
246 DumpStmt(Node);
247 fprintf(F,"\n");
248 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
249 ++IndentLevel;
250 Indent();
251 fprintf(F, "%p ", (void*) D);
252 DumpDeclarator(D);
253 if (D->getNextDeclarator())
254 fprintf(F,"\n");
255 --IndentLevel;
256 }
257}
258
Chris Lattner6000dac2007-08-08 22:51:59 +0000259void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
260 DumpStmt(Node);
261 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000262}
263
Chris Lattner6000dac2007-08-08 22:51:59 +0000264void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
265 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000266 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000267}
268
Chris Lattner6000dac2007-08-08 22:51:59 +0000269//===----------------------------------------------------------------------===//
270// Expr printing methods.
271//===----------------------------------------------------------------------===//
272
273void StmtDumper::VisitExpr(Expr *Node) {
274 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000275}
276
277void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
278 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000279
280 fprintf(F, " ");
281 switch (Node->getDecl()->getKind()) {
282 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Steve Naroff248a7532008-04-15 22:42:06 +0000283 case Decl::Var: fprintf(F,"Var"); break;
Chris Lattneraa9fc462007-10-08 21:37:32 +0000284 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000285 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
286 case Decl::Typedef: fprintf(F,"Typedef"); break;
287 case Decl::Struct: fprintf(F,"Struct"); break;
288 case Decl::Union: fprintf(F,"Union"); break;
289 case Decl::Class: fprintf(F,"Class"); break;
290 case Decl::Enum: fprintf(F,"Enum"); break;
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000291 case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
292 case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000293 default: fprintf(F,"Decl"); break;
294 }
295
296 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000297}
298
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000299void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Steve Naroff466c2e32008-05-23 00:59:14 +0000300 DumpExpr(Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000301
Steve Naroff466c2e32008-05-23 00:59:14 +0000302 fprintf(F, " %sDecl='%s' %p", Node->getDecl()->getDeclKindName(),
303 Node->getDecl()->getName(), (void*)Node->getDecl());
Steve Naroff218543b2008-05-23 22:01:24 +0000304 if (Node->isFreeIvar())
305 fprintf(F, " isFreeIvar");
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000306}
307
Chris Lattner6000dac2007-08-08 22:51:59 +0000308void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
309 DumpExpr(Node);
310 switch (Node->getIdentType()) {
311 default:
312 assert(0 && "unknown case");
313 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000314 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000315 break;
316 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000317 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000318 break;
319 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000320 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000321 break;
322 }
323}
324
325void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000326 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000327 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000328}
329
330void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
331 DumpExpr(Node);
332
333 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000334 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000335}
336void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
337 DumpExpr(Node);
Chris Lattnerc9bec4b2007-09-22 18:47:25 +0000338 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner6000dac2007-08-08 22:51:59 +0000339}
Chris Lattner5d661452007-08-26 03:42:43 +0000340
Chris Lattner6000dac2007-08-08 22:51:59 +0000341void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000342 DumpExpr(Str);
343 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000344 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000345
Chris Lattner6000dac2007-08-08 22:51:59 +0000346 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000347 switch (char C = Str->getStrData()[i]) {
348 default:
349 if (isprint(C))
350 fputc(C, F);
351 else
352 fprintf(F, "\\%03o", C);
353 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000354 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000355 case '\\': fprintf(F, "\\\\"); break;
356 case '"': fprintf(F, "\\\""); break;
357 case '\n': fprintf(F, "\\n"); break;
358 case '\t': fprintf(F, "\\t"); break;
359 case '\a': fprintf(F, "\\a"); break;
360 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000361 }
362 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000363 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000364}
Chris Lattner17a1a722007-08-30 01:00:35 +0000365
Chris Lattner6000dac2007-08-08 22:51:59 +0000366void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000367 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000368 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000369 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000370}
371void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000372 DumpExpr(Node);
373 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
374 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000375}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000376
Chris Lattner6000dac2007-08-08 22:51:59 +0000377void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000378 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000379 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000380 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000381}
Nate Begeman213541a2008-04-18 23:10:10 +0000382void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000383 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000384 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000385}
Chris Lattner6000dac2007-08-08 22:51:59 +0000386void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
387 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000388 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000389}
390void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
391 DumpExpr(Node);
392 fprintf(F, " '%s' ComputeTy=",
393 BinaryOperator::getOpcodeStr(Node->getOpcode()));
394 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000395}
Chris Lattner6000dac2007-08-08 22:51:59 +0000396
397// GNU extensions.
398
399void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000400 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000401 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000402}
403
Chris Lattner6000dac2007-08-08 22:51:59 +0000404void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000405 DumpExpr(Node);
406 fprintf(F, " ");
407 DumpType(Node->getArgType1());
408 fprintf(F, " ");
409 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000410}
411
Chris Lattnerf9e05812007-08-09 18:03:18 +0000412//===----------------------------------------------------------------------===//
413// C++ Expressions
414//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000415
416void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000417 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000418 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000419}
420
421void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000422 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000423 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000424}
425
Anders Carlsson55085182007-08-21 17:43:55 +0000426//===----------------------------------------------------------------------===//
427// Obj-C Expressions
428//===----------------------------------------------------------------------===//
429
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000430void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
431 DumpExpr(Node);
432 fprintf(F, " selector=%s", Node->getSelector().getName().c_str());
Ted Kremenekea958e572008-05-01 17:26:20 +0000433 IdentifierInfo* clsName = Node->getClassName();
434 if (clsName) fprintf(F, " class=%s", clsName->getName());
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000435}
436
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000437void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
438 DumpExpr(Node);
439
440 fprintf(F, " ");
441 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000442}
443
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000444void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
445 DumpExpr(Node);
446
447 fprintf(F, " ");
Ted Kremenek97b7f262008-04-16 04:30:16 +0000448 Selector selector = Node->getSelector();
Fariborz Jahanianc5c42f52007-10-16 21:07:53 +0000449 fprintf(F, "%s", selector.getName().c_str());
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000450}
451
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000452void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
453 DumpExpr(Node);
454
455 fprintf(F, " ");
456 fprintf(F, "%s", Node->getProtocol()->getName());
457}
Chris Lattner6000dac2007-08-08 22:51:59 +0000458//===----------------------------------------------------------------------===//
459// Stmt method implementations
460//===----------------------------------------------------------------------===//
461
462/// dump - This does a local dump of the specified AST fragment. It dumps the
463/// specified node and a few nodes underneath it, but not the whole subtree.
464/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000465void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000466 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000467 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000468 fprintf(stderr, "\n");
469}
470
471/// dump - This does a local dump of the specified AST fragment. It dumps the
472/// specified node and a few nodes underneath it, but not the whole subtree.
473/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000474void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000475 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000476 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000477 fprintf(stderr, "\n");
478}
479
480/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000481void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000482 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000483 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000484 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000485}
486
487/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
488void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000489 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000490 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000491 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000492}