blob: a30b901c1c4ff018e27517be7dada302b524bf89 [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, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000222 } else {
223 // FIXME: "struct x;"
224 assert(0 && "Unexpected decl");
225 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000226}
227
Chris Lattner6000dac2007-08-08 22:51:59 +0000228void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
229 DumpStmt(Node);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000230 fprintf(F, "\n");
Steve Naroff94745042007-09-13 23:52:58 +0000231 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000232 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000233 Indent();
Chris Lattnerf9e05812007-08-09 18:03:18 +0000234 fprintf(F, "%p ", (void*)D);
235 DumpDeclarator(D);
236 if (D->getNextDeclarator())
237 fprintf(F, "\n");
238 --IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +0000239 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000240}
241
Chris Lattner6000dac2007-08-08 22:51:59 +0000242void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
243 DumpStmt(Node);
244 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000245}
246
Chris Lattner6000dac2007-08-08 22:51:59 +0000247void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
248 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000249 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000250}
251
Chris Lattner6000dac2007-08-08 22:51:59 +0000252//===----------------------------------------------------------------------===//
253// Expr printing methods.
254//===----------------------------------------------------------------------===//
255
256void StmtDumper::VisitExpr(Expr *Node) {
257 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000258}
259
260void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
261 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000262
263 fprintf(F, " ");
264 switch (Node->getDecl()->getKind()) {
265 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Chris Lattneraa9fc462007-10-08 21:37:32 +0000266 case Decl::BlockVar: fprintf(F,"BlockVar"); break;
267 case Decl::FileVar: fprintf(F,"FileVar"); break;
268 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000269 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
270 case Decl::Typedef: fprintf(F,"Typedef"); break;
271 case Decl::Struct: fprintf(F,"Struct"); break;
272 case Decl::Union: fprintf(F,"Union"); break;
273 case Decl::Class: fprintf(F,"Class"); break;
274 case Decl::Enum: fprintf(F,"Enum"); break;
275 case Decl::ObjcInterface: fprintf(F,"ObjcInterface"); break;
276 case Decl::ObjcClass: fprintf(F,"ObjcClass"); break;
277 default: fprintf(F,"Decl"); break;
278 }
279
280 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000281}
282
283void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
284 DumpExpr(Node);
285 switch (Node->getIdentType()) {
286 default:
287 assert(0 && "unknown case");
288 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000289 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000290 break;
291 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000292 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000293 break;
294 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000295 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000296 break;
297 }
298}
299
300void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000301 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000302 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000303}
304
305void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
306 DumpExpr(Node);
307
308 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000309 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000310}
311void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
312 DumpExpr(Node);
Chris Lattnerc9bec4b2007-09-22 18:47:25 +0000313 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner6000dac2007-08-08 22:51:59 +0000314}
Chris Lattner5d661452007-08-26 03:42:43 +0000315
Chris Lattner6000dac2007-08-08 22:51:59 +0000316void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000317 DumpExpr(Str);
318 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000319 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000320
Chris Lattner6000dac2007-08-08 22:51:59 +0000321 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000322 switch (char C = Str->getStrData()[i]) {
323 default:
324 if (isprint(C))
325 fputc(C, F);
326 else
327 fprintf(F, "\\%03o", C);
328 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000329 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000330 case '\\': fprintf(F, "\\\\"); break;
331 case '"': fprintf(F, "\\\""); break;
332 case '\n': fprintf(F, "\\n"); break;
333 case '\t': fprintf(F, "\\t"); break;
334 case '\a': fprintf(F, "\\a"); break;
335 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000336 }
337 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000338 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000339}
Chris Lattner17a1a722007-08-30 01:00:35 +0000340
Chris Lattner6000dac2007-08-08 22:51:59 +0000341void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000342 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000343 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000344 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000345}
346void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000347 DumpExpr(Node);
348 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
349 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000350}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000351
Chris Lattner6000dac2007-08-08 22:51:59 +0000352void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000353 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000354 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000355 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000356}
357void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000358 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000359 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000360}
Chris Lattner6000dac2007-08-08 22:51:59 +0000361void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
362 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000363 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000364}
365void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
366 DumpExpr(Node);
367 fprintf(F, " '%s' ComputeTy=",
368 BinaryOperator::getOpcodeStr(Node->getOpcode()));
369 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000370}
Chris Lattner6000dac2007-08-08 22:51:59 +0000371
372// GNU extensions.
373
374void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000375 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000376 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000377}
378
Chris Lattner6000dac2007-08-08 22:51:59 +0000379void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000380 DumpExpr(Node);
381 fprintf(F, " ");
382 DumpType(Node->getArgType1());
383 fprintf(F, " ");
384 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000385}
386
Chris Lattnerf9e05812007-08-09 18:03:18 +0000387//===----------------------------------------------------------------------===//
388// C++ Expressions
389//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000390
391void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000392 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000393 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000394}
395
396void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000397 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000398 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000399}
400
Anders Carlsson55085182007-08-21 17:43:55 +0000401//===----------------------------------------------------------------------===//
402// Obj-C Expressions
403//===----------------------------------------------------------------------===//
404
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000405void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
406 DumpExpr(Node);
407
408 fprintf(F, " ");
409 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000410}
411
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000412void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
413 DumpExpr(Node);
414
415 fprintf(F, " ");
416 Selector &selector = Node->getSelector();
Fariborz Jahanianc5c42f52007-10-16 21:07:53 +0000417 fprintf(F, "%s", selector.getName().c_str());
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000418}
419
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000420void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
421 DumpExpr(Node);
422
423 fprintf(F, " ");
424 fprintf(F, "%s", Node->getProtocol()->getName());
425}
Chris Lattner6000dac2007-08-08 22:51:59 +0000426//===----------------------------------------------------------------------===//
427// Stmt method implementations
428//===----------------------------------------------------------------------===//
429
430/// dump - This does a local dump of the specified AST fragment. It dumps the
431/// specified node and a few nodes underneath it, but not the whole subtree.
432/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000433void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000434 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000435 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000436 fprintf(stderr, "\n");
437}
438
439/// dump - This does a local dump of the specified AST fragment. It dumps the
440/// specified node and a few nodes underneath it, but not the whole subtree.
441/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000442void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000443 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000444 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000445 fprintf(stderr, "\n");
446}
447
448/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000449void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000450 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000451 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000452 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000453}
454
455/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
456void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000457 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000458 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000459 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000460}