blob: 5f64693845892c26b05abee81121a88d1334686b [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//
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000010// This file implements the Stmt::dump method, which dumps out the
Chris Lattner6000dac2007-08-08 22:51:59 +000011// AST in a form that exposes type details and other fields.
12//
13//===----------------------------------------------------------------------===//
14
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000015#include "clang/AST/PrettyPrinter.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000016#include "clang/AST/ASTContext.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclObjC.h"
19#include "clang/AST/StmtVisitor.h"
Chris Lattnere300c872007-08-30 06:17:34 +000020#include "clang/Basic/SourceManager.h"
Daniel Dunbar806c12e2009-12-03 09:13:13 +000021#include "llvm/Support/raw_ostream.h"
Chris Lattner6000dac2007-08-08 22:51:59 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// StmtDumper Visitor
26//===----------------------------------------------------------------------===//
27
28namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000029 class StmtDumper : public StmtVisitor<StmtDumper> {
Chris Lattnere300c872007-08-30 06:17:34 +000030 SourceManager *SM;
Chris Lattner5f9e2722011-07-23 10:55:15 +000031 raw_ostream &OS;
Chris Lattner6000dac2007-08-08 22:51:59 +000032 unsigned IndentLevel;
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000033 bool IsFirstLine;
Mike Stump1eb44332009-09-09 15:08:12 +000034
Alexander Kornienko21c8b192012-12-11 15:28:09 +000035 /// Keep track of the last location we print out so that we can
36 /// print out deltas from then on out.
Chris Lattnere300c872007-08-30 06:17:34 +000037 const char *LastLocFilename;
38 unsigned LastLocLine;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000039
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000040 class IndentScope {
41 StmtDumper &Dumper;
42 public:
43 IndentScope(StmtDumper &Dumper) : Dumper(Dumper) {
44 Dumper.indent();
45 }
46 ~IndentScope() {
47 Dumper.unindent();
48 }
49 };
50
Chris Lattner6000dac2007-08-08 22:51:59 +000051 public:
Dmitri Gribenko95f61902012-11-16 21:43:31 +000052 StmtDumper(SourceManager *SM, raw_ostream &OS)
53 : SM(SM), OS(OS), IndentLevel(0), IsFirstLine(true),
54 LastLocFilename(""), LastLocLine(~0U) { }
Mike Stump1eb44332009-09-09 15:08:12 +000055
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000056 ~StmtDumper() {
57 OS << "\n";
58 }
59
Alexander Kornienkod5bc3592012-12-11 15:20:44 +000060 void dumpDecl(Decl *D);
61 void dumpStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +000062
Alexander Kornienko21c8b192012-12-11 15:28:09 +000063 // Utilities
64 void indent();
65 void unindent();
66 void dumpSourceRange(const Stmt *Node);
67 void dumpLocation(SourceLocation Loc);
68 void dumpType(QualType T);
69 void dumpDeclRef(Decl *node);
Mike Stump1eb44332009-09-09 15:08:12 +000070
Chris Lattner17a1a722007-08-30 01:00:35 +000071 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +000072 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +000073 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000074 void VisitLabelStmt(LabelStmt *Node);
75 void VisitGotoStmt(GotoStmt *Node);
Mike Stump1eb44332009-09-09 15:08:12 +000076
Chris Lattner17a1a722007-08-30 01:00:35 +000077 // Exprs
78 void VisitExpr(Expr *Node);
Anders Carlsson27a5b9b2009-08-22 23:33:40 +000079 void VisitCastExpr(CastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000080 void VisitDeclRefExpr(DeclRefExpr *Node);
Chris Lattnerd9f69102008-08-10 01:53:14 +000081 void VisitPredefinedExpr(PredefinedExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000082 void VisitCharacterLiteral(CharacterLiteral *Node);
83 void VisitIntegerLiteral(IntegerLiteral *Node);
84 void VisitFloatingLiteral(FloatingLiteral *Node);
85 void VisitStringLiteral(StringLiteral *Str);
86 void VisitUnaryOperator(UnaryOperator *Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +000087 void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000088 void VisitMemberExpr(MemberExpr *Node);
Nate Begeman213541a2008-04-18 23:10:10 +000089 void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000090 void VisitBinaryOperator(BinaryOperator *Node);
91 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
92 void VisitAddrLabelExpr(AddrLabelExpr *Node);
John McCall6b5a61b2011-02-07 10:33:21 +000093 void VisitBlockExpr(BlockExpr *Node);
John McCall4b9c2d22011-11-06 09:01:30 +000094 void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000095
96 // C++
Douglas Gregor49badde2008-10-27 19:41:14 +000097 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +000098 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
Douglas Gregorcd9b46e2008-11-04 14:56:14 +000099 void VisitCXXThisExpr(CXXThisExpr *Node);
Douglas Gregor49badde2008-10-27 19:41:14 +0000100 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000101 void VisitCXXConstructExpr(CXXConstructExpr *Node);
102 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
John McCall4765fa02010-12-06 08:20:24 +0000103 void VisitExprWithCleanups(ExprWithCleanups *Node);
John McCall9d5f35e2009-12-11 21:50:11 +0000104 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000105 void dumpCXXTemporary(CXXTemporary *Temporary);
Mike Stump1eb44332009-09-09 15:08:12 +0000106
Chris Lattner17a1a722007-08-30 01:00:35 +0000107 // ObjC
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000108 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000109 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000110 void VisitObjCMessageExpr(ObjCMessageExpr *Node);
111 void VisitObjCBoxedExpr(ObjCBoxedExpr *Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000112 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000113 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000114 void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000115 void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000116 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000117 void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000118 };
119}
120
121//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000122// Utilities
123//===----------------------------------------------------------------------===//
124
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000125void StmtDumper::indent() {
126 if (IsFirstLine)
127 IsFirstLine = false;
128 else
129 OS << "\n";
130 OS.indent(IndentLevel * 2);
131 OS << "(";
132 IndentLevel++;
133}
134
135void StmtDumper::unindent() {
136 OS << ")";
137 IndentLevel--;
138}
139
140void StmtDumper::dumpLocation(SourceLocation Loc) {
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000141 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000142
Chris Lattnere300c872007-08-30 06:17:34 +0000143 // The general format we print out is filename:line:col, but we drop pieces
144 // that haven't changed since the last loc printed.
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000145 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
146
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000147 if (PLoc.isInvalid()) {
148 OS << "<invalid sloc>";
149 return;
150 }
151
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000152 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000153 OS << PLoc.getFilename() << ':' << PLoc.getLine()
154 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000155 LastLocFilename = PLoc.getFilename();
156 LastLocLine = PLoc.getLine();
157 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000158 OS << "line" << ':' << PLoc.getLine()
159 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000160 LastLocLine = PLoc.getLine();
Chris Lattnere300c872007-08-30 06:17:34 +0000161 } else {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000162 OS << "col" << ':' << PLoc.getColumn();
Chris Lattnere300c872007-08-30 06:17:34 +0000163 }
164}
165
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000166void StmtDumper::dumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000167 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000168 if (!SM)
169 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000170
Chris Lattnere300c872007-08-30 06:17:34 +0000171 // TODO: If the parent expression is available, we can print a delta vs its
172 // location.
173 SourceRange R = Node->getSourceRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000175 OS << " <";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000176 dumpLocation(R.getBegin());
Chris Lattner311ff022007-10-16 22:36:42 +0000177 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000178 OS << ", ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000179 dumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000180 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000181 OS << ">";
Mike Stump1eb44332009-09-09 15:08:12 +0000182
Chris Lattnere300c872007-08-30 06:17:34 +0000183 // <t2.c:123:421[blah], t2.c:412:321>
184
185}
186
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000187void StmtDumper::dumpType(QualType T) {
188 SplitQualType T_split = T.split();
189 OS << "'" << QualType::getAsString(T_split) << "'";
190
191 if (!T.isNull()) {
192 // If the type is sugared, also dump a (shallow) desugared type.
193 SplitQualType D_split = T.getSplitDesugaredType();
194 if (T_split != D_split)
195 OS << ":'" << QualType::getAsString(D_split) << "'";
196 }
197}
198
199void StmtDumper::dumpDeclRef(Decl *D) {
200 OS << D->getDeclKindName() << ' ' << (void*) D;
201
202 if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
203 OS << " '";
204 ND->getDeclName().printName(OS);
205 OS << "'";
206 }
207
208 if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
209 OS << ' ';
210 dumpType(VD->getType());
211 }
212}
213
Chris Lattnere300c872007-08-30 06:17:34 +0000214//===----------------------------------------------------------------------===//
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000215// Decl dumping methods.
Chris Lattner6000dac2007-08-08 22:51:59 +0000216//===----------------------------------------------------------------------===//
217
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000218void StmtDumper::dumpDecl(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000219 // FIXME: Need to complete/beautify this... this code simply shows the
220 // nodes are where they need to be.
221 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000222 OS << "\"typedef " << localType->getUnderlyingType().getAsString()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000223 << ' ' << *localType << '"';
Richard Smith162e1c12011-04-15 14:24:37 +0000224 } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000225 OS << "\"using " << *localType << " = "
Richard Smith162e1c12011-04-15 14:24:37 +0000226 << localType->getUnderlyingType().getAsString() << '"';
Chris Lattner6000dac2007-08-08 22:51:59 +0000227 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000228 OS << "\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000229 // Emit storage class for vardecls.
230 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
John McCalld931b082010-08-26 03:08:43 +0000231 if (V->getStorageClass() != SC_None)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000232 OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
233 << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +0000234 }
Mike Stump1eb44332009-09-09 15:08:12 +0000235
Chris Lattner39f34e92008-11-24 04:00:27 +0000236 std::string Name = VD->getNameAsString();
Mike Stump1eb44332009-09-09 15:08:12 +0000237 VD->getType().getAsStringInternal(Name,
David Blaikie4e4d0842012-03-11 07:00:24 +0000238 PrintingPolicy(VD->getASTContext().getLangOpts()));
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000239 OS << Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000240
Chris Lattner6000dac2007-08-08 22:51:59 +0000241 // If this is a vardecl with an initializer, emit it.
242 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
243 if (V->getInit()) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000244 OS << " =";
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000245 dumpStmt(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000246 }
247 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000248 OS << '"';
Steve Naroff92199282007-11-17 21:37:36 +0000249 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
250 // print a free standing tag decl (e.g. "struct x;").
251 const char *tagname;
252 if (const IdentifierInfo *II = TD->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000253 tagname = II->getNameStart();
Steve Naroff92199282007-11-17 21:37:36 +0000254 else
255 tagname = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000256 OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
Steve Naroff92199282007-11-17 21:37:36 +0000257 // FIXME: print tag bodies.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000258 } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
259 // print using-directive decl (e.g. "using namespace x;")
260 const char *ns;
261 if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000262 ns = II->getNameStart();
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000263 else
264 ns = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000265 OS << '"' << UD->getDeclKindName() << ns << ";\"";
Sebastian Redl0ca43592010-05-04 10:20:17 +0000266 } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
267 // print using decl (e.g. "using std::string;")
268 const char *tn = UD->isTypeName() ? "typename " : "";
269 OS << '"' << UD->getDeclKindName() << tn;
Douglas Gregordc355712011-02-25 00:36:19 +0000270 UD->getQualifier()->print(OS,
David Blaikie4e4d0842012-03-11 07:00:24 +0000271 PrintingPolicy(UD->getASTContext().getLangOpts()));
Sebastian Redl0ca43592010-05-04 10:20:17 +0000272 OS << ";\"";
Chris Lattner4ae493c2011-02-18 02:08:43 +0000273 } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000274 OS << "label " << *LD;
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000275 } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000276 OS << "\"static_assert(";
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000277 dumpStmt(SAD->getAssertExpr());
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000278 OS << ",";
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000279 dumpStmt(SAD->getMessage());
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000280 OS << ");\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000281 } else {
David Blaikieb219cfc2011-09-23 05:06:16 +0000282 llvm_unreachable("Unexpected decl");
Chris Lattner6000dac2007-08-08 22:51:59 +0000283 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000284}
285
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000286//===----------------------------------------------------------------------===//
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000287// Stmt dumping methods.
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000288//===----------------------------------------------------------------------===//
289
290void StmtDumper::dumpStmt(Stmt *S) {
291 IndentScope Indent(*this);
292
293 if (!S) {
294 OS << "<<<NULL>>>";
295 return;
296 }
297
298 if (DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
299 VisitDeclStmt(DS);
300 return;
301 }
302
303 Visit(S);
304 for (Stmt::child_range CI = S->children(); CI; ++CI)
305 dumpStmt(*CI);
306}
307
308void StmtDumper::VisitStmt(Stmt *Node) {
309 OS << Node->getStmtClassName() << " " << (const void *)Node;
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000310 dumpSourceRange(Node);
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000311}
312
Ted Kremenek5399ce22007-12-12 06:59:42 +0000313void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000314 VisitStmt(Node);
Ted Kremenek04a72b72008-10-06 18:38:35 +0000315 for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
316 DI != DE; ++DI) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000317 IndentScope Indent(*this);
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000318 Decl *D = *DI;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000319 OS << (void*) D << " ";
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000320 dumpDecl(D);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000321 }
322}
323
Chris Lattner6000dac2007-08-08 22:51:59 +0000324void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000325 VisitStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000326 OS << " '" << Node->getName() << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000327}
328
Chris Lattner6000dac2007-08-08 22:51:59 +0000329void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000330 VisitStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000331 OS << " '" << Node->getLabel()->getName()
332 << "':" << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000333}
334
Chris Lattner6000dac2007-08-08 22:51:59 +0000335//===----------------------------------------------------------------------===//
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000336// Expr dumping methods.
Chris Lattner6000dac2007-08-08 22:51:59 +0000337//===----------------------------------------------------------------------===//
338
339void StmtDumper::VisitExpr(Expr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000340 VisitStmt(Node);
341 OS << ' ';
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000342 dumpType(Node->getType());
343
344 switch (Node->getValueKind()) {
345 case VK_RValue:
346 break;
347 case VK_LValue:
348 OS << " lvalue";
349 break;
350 case VK_XValue:
351 OS << " xvalue";
352 break;
353 }
354
355 switch (Node->getObjectKind()) {
356 case OK_Ordinary:
357 break;
358 case OK_BitField:
359 OS << " bitfield";
360 break;
361 case OK_ObjCProperty:
362 OS << " objcproperty";
363 break;
364 case OK_ObjCSubscript:
365 OS << " objcsubscript";
366 break;
367 case OK_VectorComponent:
368 OS << " vectorcomponent";
369 break;
370 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000371}
372
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000373static void dumpBasePath(raw_ostream &OS, CastExpr *Node) {
John McCallf871d0c2010-08-07 06:22:56 +0000374 if (Node->path_empty())
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000375 return;
376
377 OS << " (";
378 bool First = true;
John McCallf871d0c2010-08-07 06:22:56 +0000379 for (CastExpr::path_iterator
380 I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000381 const CXXBaseSpecifier *Base = *I;
382 if (!First)
383 OS << " -> ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000384
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000385 const CXXRecordDecl *RD =
386 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000387
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000388 if (Base->isVirtual())
389 OS << "virtual ";
390 OS << RD->getName();
391 First = false;
392 }
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000393
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000394 OS << ')';
395}
396
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000397void StmtDumper::VisitCastExpr(CastExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000398 VisitExpr(Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000399 OS << " <" << Node->getCastKindName();
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000400 dumpBasePath(OS, Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000401 OS << ">";
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000402}
403
Chris Lattner6000dac2007-08-08 22:51:59 +0000404void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000405 VisitExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000406
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000407 OS << " ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000408 dumpDeclRef(Node->getDecl());
Chandler Carruth3aa81402011-05-01 23:48:14 +0000409 if (Node->getDecl() != Node->getFoundDecl()) {
410 OS << " (";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000411 dumpDeclRef(Node->getFoundDecl());
Chandler Carruth3aa81402011-05-01 23:48:14 +0000412 OS << ")";
413 }
John McCall6b5a61b2011-02-07 10:33:21 +0000414}
415
John McCall9d5f35e2009-12-11 21:50:11 +0000416void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000417 VisitExpr(Node);
John McCall9d5f35e2009-12-11 21:50:11 +0000418 OS << " (";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000419 if (!Node->requiresADL())
420 OS << "no ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000421 OS << "ADL) = '" << Node->getName() << '\'';
John McCall9d5f35e2009-12-11 21:50:11 +0000422
423 UnresolvedLookupExpr::decls_iterator
424 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000425 if (I == E)
426 OS << " empty";
John McCall9d5f35e2009-12-11 21:50:11 +0000427 for (; I != E; ++I)
428 OS << " " << (void*) *I;
429}
430
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000431void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000432 VisitExpr(Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000433
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000434 OS << " " << Node->getDecl()->getDeclKindName()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000435 << "Decl='" << *Node->getDecl()
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000436 << "' " << (void*)Node->getDecl();
Steve Naroff218543b2008-05-23 22:01:24 +0000437 if (Node->isFreeIvar())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000438 OS << " isFreeIvar";
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000439}
440
Chris Lattnerd9f69102008-08-10 01:53:14 +0000441void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000442 VisitExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000443 switch (Node->getIdentType()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000444 default: llvm_unreachable("unknown case");
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000445 case PredefinedExpr::Func: OS << " __func__"; break;
446 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000447 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000448 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000449 }
450}
451
452void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000453 VisitExpr(Node);
Richard Trieu49cf8842011-11-03 23:56:23 +0000454 OS << " " << Node->getValue();
Chris Lattner6000dac2007-08-08 22:51:59 +0000455}
456
457void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000458 VisitExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000459
460 bool isSigned = Node->getType()->isSignedIntegerType();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000461 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattner6000dac2007-08-08 22:51:59 +0000462}
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000463
Chris Lattner6000dac2007-08-08 22:51:59 +0000464void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000465 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000466 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattner6000dac2007-08-08 22:51:59 +0000467}
Chris Lattner5d661452007-08-26 03:42:43 +0000468
Chris Lattner6000dac2007-08-08 22:51:59 +0000469void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000470 VisitExpr(Str);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000471 OS << " ";
Richard Trieu8ab09da2012-06-13 20:25:24 +0000472 Str->outputString(OS);
Chris Lattner6000dac2007-08-08 22:51:59 +0000473}
Chris Lattner17a1a722007-08-30 01:00:35 +0000474
Chris Lattner6000dac2007-08-08 22:51:59 +0000475void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000476 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000477 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
478 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000479}
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000480
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000481void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000482 VisitExpr(Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000483 switch(Node->getKind()) {
484 case UETT_SizeOf:
485 OS << " sizeof ";
486 break;
487 case UETT_AlignOf:
Jordan Rosef70a8862012-06-30 21:33:57 +0000488 OS << " alignof ";
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000489 break;
490 case UETT_VecStep:
491 OS << " vec_step ";
492 break;
493 }
Sebastian Redl05189992008-11-11 17:56:53 +0000494 if (Node->isArgumentType())
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000495 dumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000496}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000497
Chris Lattner6000dac2007-08-08 22:51:59 +0000498void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000499 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000500 OS << " " << (Node->isArrow() ? "->" : ".")
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000501 << *Node->getMemberDecl() << ' '
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000502 << (void*)Node->getMemberDecl();
Chris Lattner6000dac2007-08-08 22:51:59 +0000503}
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000504
Nate Begeman213541a2008-04-18 23:10:10 +0000505void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000506 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000507 OS << " " << Node->getAccessor().getNameStart();
Chris Lattner6000dac2007-08-08 22:51:59 +0000508}
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000509
Chris Lattner6000dac2007-08-08 22:51:59 +0000510void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000511 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000512 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnereb14fe82007-08-25 02:00:02 +0000513}
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000514
Chris Lattnereb14fe82007-08-25 02:00:02 +0000515void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000516 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000517 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
518 << "' ComputeLHSTy=";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000519 dumpType(Node->getComputationLHSType());
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000520 OS << " ComputeResultTy=";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000521 dumpType(Node->getComputationResultType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000522}
Chris Lattner6000dac2007-08-08 22:51:59 +0000523
John McCall6b5a61b2011-02-07 10:33:21 +0000524void StmtDumper::VisitBlockExpr(BlockExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000525 VisitExpr(Node);
John McCall6b5a61b2011-02-07 10:33:21 +0000526
John McCall6b5a61b2011-02-07 10:33:21 +0000527 BlockDecl *block = Node->getBlockDecl();
John McCall89da8cf2012-03-10 03:04:55 +0000528 OS << " decl=" << block;
529
John McCall6b5a61b2011-02-07 10:33:21 +0000530 if (block->capturesCXXThis()) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000531 IndentScope Indent(*this);
532 OS << "capture this";
John McCall6b5a61b2011-02-07 10:33:21 +0000533 }
534 for (BlockDecl::capture_iterator
535 i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000536 IndentScope Indent(*this);
537 OS << "capture ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000538 if (i->isByRef())
539 OS << "byref ";
540 if (i->isNested())
541 OS << "nested ";
Douglas Gregorac1303e2012-02-22 05:02:47 +0000542 if (i->getVariable())
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000543 dumpDeclRef(i->getVariable());
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000544 if (i->hasCopyExpr())
545 dumpStmt(i->getCopyExpr());
John McCall6b5a61b2011-02-07 10:33:21 +0000546 }
John McCall6b5a61b2011-02-07 10:33:21 +0000547
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000548 dumpStmt(block->getBody());
John McCall6b5a61b2011-02-07 10:33:21 +0000549}
550
John McCall4b9c2d22011-11-06 09:01:30 +0000551void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000552 VisitExpr(Node);
John McCall4b9c2d22011-11-06 09:01:30 +0000553
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000554 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000555 dumpStmt(Source);
John McCall4b9c2d22011-11-06 09:01:30 +0000556}
557
Chris Lattner6000dac2007-08-08 22:51:59 +0000558// GNU extensions.
559
560void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000561 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000562 OS << " " << Node->getLabel()->getName()
563 << " " << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000564}
565
Chris Lattnerf9e05812007-08-09 18:03:18 +0000566//===----------------------------------------------------------------------===//
567// C++ Expressions
568//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000569
Douglas Gregor49badde2008-10-27 19:41:14 +0000570void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000571 VisitExpr(Node);
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000572 OS << " " << Node->getCastName()
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000573 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000574 << " <" << Node->getCastKindName();
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000575 dumpBasePath(OS, Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000576 OS << ">";
Chris Lattner6000dac2007-08-08 22:51:59 +0000577}
578
579void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000580 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000581 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000582}
583
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000584void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000585 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000586 OS << " this";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000587}
588
Douglas Gregor49badde2008-10-27 19:41:14 +0000589void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000590 VisitExpr(Node);
Eli Friedmancc2fca22011-09-02 17:38:59 +0000591 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
592 << " <" << Node->getCastKindName() << ">";
Douglas Gregor49badde2008-10-27 19:41:14 +0000593}
594
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000595void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000596 VisitExpr(Node);
John McCalld4bbdfe2010-02-02 19:03:45 +0000597 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000598 dumpType(Ctor->getType());
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000599 if (Node->isElidable())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000600 OS << " elidable";
John McCallf8cf0b02010-08-07 06:38:55 +0000601 if (Node->requiresZeroInitialization())
602 OS << " zeroing";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000603}
604
605void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000606 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000607 OS << " ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000608 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000609}
610
John McCall4765fa02010-12-06 08:20:24 +0000611void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000612 VisitExpr(Node);
John McCall80ee6e82011-11-10 05:35:25 +0000613 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000614 IndentScope Indent(*this);
615 OS << "cleanup ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000616 dumpDeclRef(Node->getObject(i));
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000617 }
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000618}
619
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000620void StmtDumper::dumpCXXTemporary(CXXTemporary *Temporary) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000621 OS << "(CXXTemporary " << (void *)Temporary << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000622}
623
Anders Carlsson55085182007-08-21 17:43:55 +0000624//===----------------------------------------------------------------------===//
625// Obj-C Expressions
626//===----------------------------------------------------------------------===//
627
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000628void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000629 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000630 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor04badcf2010-04-21 00:45:42 +0000631 switch (Node->getReceiverKind()) {
632 case ObjCMessageExpr::Instance:
633 break;
634
635 case ObjCMessageExpr::Class:
636 OS << " class=";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000637 dumpType(Node->getClassReceiver());
Douglas Gregor04badcf2010-04-21 00:45:42 +0000638 break;
639
640 case ObjCMessageExpr::SuperInstance:
641 OS << " super (instance)";
642 break;
643
644 case ObjCMessageExpr::SuperClass:
645 OS << " super (class)";
646 break;
647 }
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000648}
649
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000650void StmtDumper::VisitObjCBoxedExpr(ObjCBoxedExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000651 VisitExpr(Node);
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000652 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
653}
654
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000655void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000656 VisitStmt(Node);
Douglas Gregorc00d8e12010-04-26 16:46:50 +0000657 if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000658 OS << " catch parm = ";
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000659 dumpDecl(CatchParam);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000660 } else {
661 OS << " catch all";
662 }
663}
664
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000665void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000666 VisitExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000667 OS << " ";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000668 dumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000669}
670
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000671void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000672 VisitExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000673
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000674 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000675}
676
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000677void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000678 VisitExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000679
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000680 OS << ' ' << *Node->getProtocol();
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000681}
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000682
683void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000684 VisitExpr(Node);
John McCall12f78a62010-12-02 01:19:52 +0000685 if (Node->isImplicitProperty()) {
Fariborz Jahanian99130e52010-12-22 19:46:35 +0000686 OS << " Kind=MethodRef Getter=\"";
687 if (Node->getImplicitPropertyGetter())
688 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
689 else
690 OS << "(null)";
691
692 OS << "\" Setter=\"";
John McCall12f78a62010-12-02 01:19:52 +0000693 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
694 OS << Setter->getSelector().getAsString();
695 else
696 OS << "(null)";
697 OS << "\"";
698 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000699 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCall12f78a62010-12-02 01:19:52 +0000700 }
Fariborz Jahanian5daf5702008-11-22 18:39:36 +0000701
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000702 if (Node->isSuperReceiver())
703 OS << " super";
Argyrios Kyrtzidisb085d892012-03-30 00:19:18 +0000704
705 OS << " Messaging=";
706 if (Node->isMessagingGetter() && Node->isMessagingSetter())
707 OS << "Getter&Setter";
708 else if (Node->isMessagingGetter())
709 OS << "Getter";
710 else if (Node->isMessagingSetter())
711 OS << "Setter";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000712}
713
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000714void StmtDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000715 VisitExpr(Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000716 if (Node->isArraySubscriptRefExpr())
717 OS << " Kind=ArraySubscript GetterForArray=\"";
718 else
719 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
720 if (Node->getAtIndexMethodDecl())
721 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
722 else
723 OS << "(null)";
Alexander Kornienko21c8b192012-12-11 15:28:09 +0000724
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000725 if (Node->isArraySubscriptRefExpr())
726 OS << "\" SetterForArray=\"";
727 else
728 OS << "\" SetterForDictionary=\"";
729 if (Node->setAtIndexMethodDecl())
730 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
731 else
732 OS << "(null)";
733}
734
735void StmtDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000736 VisitExpr(Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000737 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
738}
739
Chris Lattner6000dac2007-08-08 22:51:59 +0000740//===----------------------------------------------------------------------===//
741// Stmt method implementations
742//===----------------------------------------------------------------------===//
743
Chris Lattnere300c872007-08-30 06:17:34 +0000744void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000745 dump(llvm::errs(), SM);
746}
747
Chris Lattner5f9e2722011-07-23 10:55:15 +0000748void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Dmitri Gribenko95f61902012-11-16 21:43:31 +0000749 StmtDumper P(&SM, OS);
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000750 P.dumpStmt(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000751}
752
Chris Lattner6000dac2007-08-08 22:51:59 +0000753void Stmt::dump() const {
Dmitri Gribenko95f61902012-11-16 21:43:31 +0000754 StmtDumper P(0, llvm::errs());
Alexander Kornienkod5bc3592012-12-11 15:20:44 +0000755 P.dumpStmt(const_cast<Stmt*>(this));
Chris Lattner6000dac2007-08-08 22:51:59 +0000756}