blob: 66411f1730d6d77004e679414fa1d7a3351761f3 [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);
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000136 void VisitObjCMessageExpr(ObjCMessageExpr* Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000137 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000138 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000139 };
140}
141
142//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000143// Utilities
144//===----------------------------------------------------------------------===//
145
146void StmtDumper::DumpLocation(SourceLocation Loc) {
147 SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
148
149 // The general format we print out is filename:line:col, but we drop pieces
150 // that haven't changed since the last loc printed.
151 const char *Filename = SM->getSourceName(PhysLoc);
152 unsigned LineNo = SM->getLineNumber(PhysLoc);
153 if (strcmp(Filename, LastLocFilename) != 0) {
154 fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
155 LastLocFilename = Filename;
156 LastLocLine = LineNo;
157 } else if (LineNo != LastLocLine) {
158 fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
159 LastLocLine = LineNo;
160 } else {
161 fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
162 }
163}
164
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000165void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000166 // Can't translate locations if a SourceManager isn't available.
167 if (SM == 0) return;
168
169 // TODO: If the parent expression is available, we can print a delta vs its
170 // location.
171 SourceRange R = Node->getSourceRange();
172
173 fprintf(stderr, " <");
Chris Lattner311ff022007-10-16 22:36:42 +0000174 DumpLocation(R.getBegin());
175 if (R.getBegin() != R.getEnd()) {
Chris Lattnere300c872007-08-30 06:17:34 +0000176 fprintf(stderr, ", ");
Chris Lattner311ff022007-10-16 22:36:42 +0000177 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000178 }
179 fprintf(stderr, ">");
180
181 // <t2.c:123:421[blah], t2.c:412:321>
182
183}
184
185
186//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000187// Stmt printing methods.
188//===----------------------------------------------------------------------===//
189
190void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000191 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000192}
193
Chris Lattnerf9e05812007-08-09 18:03:18 +0000194void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000195 // FIXME: Need to complete/beautify this... this code simply shows the
196 // nodes are where they need to be.
197 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000198 fprintf(F, "\"typedef %s %s\"",
199 localType->getUnderlyingType().getAsString().c_str(),
200 localType->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000201 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000202 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000203 // Emit storage class for vardecls.
204 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
205 switch (V->getStorageClass()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000206 default: assert(0 && "Unknown storage class!");
207 case VarDecl::None: break;
208 case VarDecl::Extern: fprintf(F, "extern "); break;
209 case VarDecl::Static: fprintf(F, "static "); break;
210 case VarDecl::Auto: fprintf(F, "auto "); break;
211 case VarDecl::Register: fprintf(F, "register "); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000212 }
213 }
214
215 std::string Name = VD->getName();
216 VD->getType().getAsStringInternal(Name);
Chris Lattnerf9e05812007-08-09 18:03:18 +0000217 fprintf(F, "%s", Name.c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000218
219 // If this is a vardecl with an initializer, emit it.
220 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
221 if (V->getInit()) {
Chris Lattnerf9e05812007-08-09 18:03:18 +0000222 fprintf(F, " =\n");
223 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000224 }
225 }
Chris Lattnerf9e05812007-08-09 18:03:18 +0000226 fprintf(F, "\"");
Steve Naroff92199282007-11-17 21:37:36 +0000227 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
228 // print a free standing tag decl (e.g. "struct x;").
229 const char *tagname;
230 if (const IdentifierInfo *II = TD->getIdentifier())
231 tagname = II->getName();
232 else
233 tagname = "<anonymous>";
234 fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname);
235 // FIXME: print tag bodies.
Chris Lattner6000dac2007-08-08 22:51:59 +0000236 } else {
Chris Lattner6000dac2007-08-08 22:51:59 +0000237 assert(0 && "Unexpected decl");
238 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000239}
240
Ted Kremenek5399ce22007-12-12 06:59:42 +0000241void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
242 DumpStmt(Node);
243 fprintf(F,"\n");
244 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
245 ++IndentLevel;
246 Indent();
247 fprintf(F, "%p ", (void*) D);
248 DumpDeclarator(D);
249 if (D->getNextDeclarator())
250 fprintf(F,"\n");
251 --IndentLevel;
252 }
253}
254
Chris Lattner6000dac2007-08-08 22:51:59 +0000255void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
256 DumpStmt(Node);
257 fprintf(F, " '%s'\n", Node->getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000258}
259
Chris Lattner6000dac2007-08-08 22:51:59 +0000260void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
261 DumpStmt(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000262 fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000263}
264
Chris Lattner6000dac2007-08-08 22:51:59 +0000265//===----------------------------------------------------------------------===//
266// Expr printing methods.
267//===----------------------------------------------------------------------===//
268
269void StmtDumper::VisitExpr(Expr *Node) {
270 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000271}
272
273void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
274 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000275
276 fprintf(F, " ");
277 switch (Node->getDecl()->getKind()) {
278 case Decl::Function: fprintf(F,"FunctionDecl"); break;
Chris Lattneraa9fc462007-10-08 21:37:32 +0000279 case Decl::BlockVar: fprintf(F,"BlockVar"); break;
280 case Decl::FileVar: fprintf(F,"FileVar"); break;
281 case Decl::ParmVar: fprintf(F,"ParmVar"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000282 case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
283 case Decl::Typedef: fprintf(F,"Typedef"); break;
284 case Decl::Struct: fprintf(F,"Struct"); break;
285 case Decl::Union: fprintf(F,"Union"); break;
286 case Decl::Class: fprintf(F,"Class"); break;
287 case Decl::Enum: fprintf(F,"Enum"); break;
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000288 case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
289 case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
Ted Kremenekeb641f92007-09-10 17:32:55 +0000290 default: fprintf(F,"Decl"); break;
291 }
292
293 fprintf(F, "='%s' %p", Node->getDecl()->getName(), (void*)Node->getDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000294}
295
296void StmtDumper::VisitPreDefinedExpr(PreDefinedExpr *Node) {
297 DumpExpr(Node);
298 switch (Node->getIdentType()) {
299 default:
300 assert(0 && "unknown case");
301 case PreDefinedExpr::Func:
Chris Lattnerb3938792007-08-30 00:53:54 +0000302 fprintf(F, " __func__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000303 break;
304 case PreDefinedExpr::Function:
Chris Lattnerb3938792007-08-30 00:53:54 +0000305 fprintf(F, " __FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000306 break;
307 case PreDefinedExpr::PrettyFunction:
Chris Lattnerb3938792007-08-30 00:53:54 +0000308 fprintf(F, " __PRETTY_FUNCTION__");
Chris Lattner6000dac2007-08-08 22:51:59 +0000309 break;
310 }
311}
312
313void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000314 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000315 fprintf(F, " %d", Node->getValue());
Chris Lattner6000dac2007-08-08 22:51:59 +0000316}
317
318void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
319 DumpExpr(Node);
320
321 bool isSigned = Node->getType()->isSignedIntegerType();
Chris Lattnerb3938792007-08-30 00:53:54 +0000322 fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
Chris Lattner6000dac2007-08-08 22:51:59 +0000323}
324void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
325 DumpExpr(Node);
Chris Lattnerc9bec4b2007-09-22 18:47:25 +0000326 fprintf(F, " %f", Node->getValueAsDouble());
Chris Lattner6000dac2007-08-08 22:51:59 +0000327}
Chris Lattner5d661452007-08-26 03:42:43 +0000328
Chris Lattner6000dac2007-08-08 22:51:59 +0000329void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000330 DumpExpr(Str);
331 // FIXME: this doesn't print wstrings right.
Chris Lattner5fc61072007-08-09 17:14:24 +0000332 fprintf(F, " %s\"", Str->isWide() ? "L" : "");
Chris Lattnera0df31a2007-08-09 01:04:32 +0000333
Chris Lattner6000dac2007-08-08 22:51:59 +0000334 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5fc61072007-08-09 17:14:24 +0000335 switch (char C = Str->getStrData()[i]) {
336 default:
337 if (isprint(C))
338 fputc(C, F);
339 else
340 fprintf(F, "\\%03o", C);
341 break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000342 // Handle some common ones to make dumps prettier.
Chris Lattner5fc61072007-08-09 17:14:24 +0000343 case '\\': fprintf(F, "\\\\"); break;
344 case '"': fprintf(F, "\\\""); break;
345 case '\n': fprintf(F, "\\n"); break;
346 case '\t': fprintf(F, "\\t"); break;
347 case '\a': fprintf(F, "\\a"); break;
348 case '\b': fprintf(F, "\\b"); break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000349 }
350 }
Chris Lattnerb3938792007-08-30 00:53:54 +0000351 fprintf(F, "\"");
Chris Lattner6000dac2007-08-08 22:51:59 +0000352}
Chris Lattner17a1a722007-08-30 01:00:35 +0000353
Chris Lattner6000dac2007-08-08 22:51:59 +0000354void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000355 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000356 fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000357 UnaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000358}
359void StmtDumper::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000360 DumpExpr(Node);
361 fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
362 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000363}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000364
Chris Lattner6000dac2007-08-08 22:51:59 +0000365void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000366 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000367 fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
Chris Lattner13cb21f2007-08-09 17:35:30 +0000368 Node->getMemberDecl()->getName(), (void*)Node->getMemberDecl());
Chris Lattner6000dac2007-08-08 22:51:59 +0000369}
370void StmtDumper::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000371 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000372 fprintf(F, " %s", Node->getAccessor().getName());
Chris Lattner6000dac2007-08-08 22:51:59 +0000373}
Chris Lattner6000dac2007-08-08 22:51:59 +0000374void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
375 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000376 fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
Chris Lattnereb14fe82007-08-25 02:00:02 +0000377}
378void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
379 DumpExpr(Node);
380 fprintf(F, " '%s' ComputeTy=",
381 BinaryOperator::getOpcodeStr(Node->getOpcode()));
382 DumpType(Node->getComputationType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000383}
Chris Lattner6000dac2007-08-08 22:51:59 +0000384
385// GNU extensions.
386
387void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000388 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000389 fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
Chris Lattner6000dac2007-08-08 22:51:59 +0000390}
391
Chris Lattner6000dac2007-08-08 22:51:59 +0000392void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000393 DumpExpr(Node);
394 fprintf(F, " ");
395 DumpType(Node->getArgType1());
396 fprintf(F, " ");
397 DumpType(Node->getArgType2());
Chris Lattner6000dac2007-08-08 22:51:59 +0000398}
399
Chris Lattnerf9e05812007-08-09 18:03:18 +0000400//===----------------------------------------------------------------------===//
401// C++ Expressions
402//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000403
404void StmtDumper::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000405 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000406 fprintf(F, " %s", CXXCastExpr::getOpcodeStr(Node->getOpcode()));
Chris Lattner6000dac2007-08-08 22:51:59 +0000407}
408
409void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000410 DumpExpr(Node);
Chris Lattnerb3938792007-08-30 00:53:54 +0000411 fprintf(F, " %s", Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000412}
413
Anders Carlsson55085182007-08-21 17:43:55 +0000414//===----------------------------------------------------------------------===//
415// Obj-C Expressions
416//===----------------------------------------------------------------------===//
417
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000418void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
419 DumpExpr(Node);
420 fprintf(F, " selector=%s", Node->getSelector().getName().c_str());
421}
422
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000423void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
424 DumpExpr(Node);
425
426 fprintf(F, " ");
427 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000428}
429
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000430void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
431 DumpExpr(Node);
432
433 fprintf(F, " ");
434 Selector &selector = Node->getSelector();
Fariborz Jahanianc5c42f52007-10-16 21:07:53 +0000435 fprintf(F, "%s", selector.getName().c_str());
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000436}
437
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000438void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
439 DumpExpr(Node);
440
441 fprintf(F, " ");
442 fprintf(F, "%s", Node->getProtocol()->getName());
443}
Chris Lattner6000dac2007-08-08 22:51:59 +0000444//===----------------------------------------------------------------------===//
445// Stmt method implementations
446//===----------------------------------------------------------------------===//
447
448/// dump - This does a local dump of the specified AST fragment. It dumps the
449/// specified node and a few nodes underneath it, but not the whole subtree.
450/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000451void Stmt::dump(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000452 StmtDumper P(&SM, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000453 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000454 fprintf(stderr, "\n");
455}
456
457/// dump - This does a local dump of the specified AST fragment. It dumps the
458/// specified node and a few nodes underneath it, but not the whole subtree.
459/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000460void Stmt::dump() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000461 StmtDumper P(0, stderr, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000462 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000463 fprintf(stderr, "\n");
464}
465
466/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000467void Stmt::dumpAll(SourceManager &SM) const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000468 StmtDumper P(&SM, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000469 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000470 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000471}
472
473/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
474void Stmt::dumpAll() const {
Chris Lattner0c727a32007-08-30 00:40:08 +0000475 StmtDumper P(0, stderr, ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000476 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattneree41ce52007-08-10 21:51:12 +0000477 fprintf(stderr, "\n");
Chris Lattner6000dac2007-08-08 22:51:59 +0000478}