blob: cb54585f4215ff9e87a487447148e40fcf0549e4 [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
Chris Lattnere300c872007-08-30 06:17:34 +000035 /// LastLocFilename/LastLocLine - Keep track of the last location we print
36 /// out so that we can print out deltas from then on out.
37 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
Chris Lattnerf9e05812007-08-09 18:03:18 +000060 void DumpSubTree(Stmt *S) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000061 IndentScope Indent(*this);
Mike Stump1eb44332009-09-09 15:08:12 +000062
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000063 if (!S) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +000064 OS << "<<<NULL>>>";
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000065 return;
Chris Lattner6000dac2007-08-08 22:51:59 +000066 }
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000067
68 if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) {
69 VisitDeclStmt(DS);
70 return;
71 }
72
73 Visit(S);
74 for (Stmt::child_range CI = S->children(); CI; CI++)
75 DumpSubTree(*CI);
Chris Lattner6000dac2007-08-08 22:51:59 +000076 }
Mike Stump1eb44332009-09-09 15:08:12 +000077
Chris Lattnerf9e05812007-08-09 18:03:18 +000078 void DumpDeclarator(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000079
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000080 void indent() {
81 if (IsFirstLine)
82 IsFirstLine = false;
83 else
84 OS << "\n";
85 OS.indent(IndentLevel * 2);
86 OS << "(";
87 IndentLevel++;
88 }
89
90 void unindent() {
91 OS << ")";
92 IndentLevel--;
Chris Lattner6000dac2007-08-08 22:51:59 +000093 }
Mike Stump1eb44332009-09-09 15:08:12 +000094
Steve Naroff9dcbfa42007-09-01 21:08:38 +000095 void DumpType(QualType T) {
John McCall49f4e1c2010-12-10 11:01:00 +000096 SplitQualType T_split = T.split();
97 OS << "'" << QualType::getAsString(T_split) << "'";
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000098
Douglas Gregor61366e92008-12-24 00:01:03 +000099 if (!T.isNull()) {
John McCall0953e762009-09-24 19:53:00 +0000100 // If the type is sugared, also dump a (shallow) desugared type.
John McCall49f4e1c2010-12-10 11:01:00 +0000101 SplitQualType D_split = T.getSplitDesugaredType();
102 if (T_split != D_split)
103 OS << ":'" << QualType::getAsString(D_split) << "'";
Chris Lattnerbad37852008-04-02 05:06:23 +0000104 }
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000105 }
John McCall6b5a61b2011-02-07 10:33:21 +0000106 void DumpDeclRef(Decl *node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000107 void DumpStmt(const Stmt *Node) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000108 OS << Node->getStmtClassName()
Roman Divacky31ba6132012-09-06 15:59:27 +0000109 << " " << (const void*)Node;
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000110 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000111 }
John McCallf89e55a2010-11-18 06:31:45 +0000112 void DumpValueKind(ExprValueKind K) {
113 switch (K) {
114 case VK_RValue: break;
115 case VK_LValue: OS << " lvalue"; break;
116 case VK_XValue: OS << " xvalue"; break;
117 }
118 }
119 void DumpObjectKind(ExprObjectKind K) {
120 switch (K) {
121 case OK_Ordinary: break;
122 case OK_BitField: OS << " bitfield"; break;
123 case OK_ObjCProperty: OS << " objcproperty"; break;
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000124 case OK_ObjCSubscript: OS << " objcsubscript"; break;
John McCallf89e55a2010-11-18 06:31:45 +0000125 case OK_VectorComponent: OS << " vectorcomponent"; break;
126 }
127 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000128 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000129 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000130 OS << ' ';
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000131 DumpType(Node->getType());
John McCallf89e55a2010-11-18 06:31:45 +0000132 DumpValueKind(Node->getValueKind());
133 DumpObjectKind(Node->getObjectKind());
Chris Lattner6000dac2007-08-08 22:51:59 +0000134 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000135 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000136 void DumpLocation(SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000137
Chris Lattner17a1a722007-08-30 01:00:35 +0000138 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000139 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000140 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000141 void VisitLabelStmt(LabelStmt *Node);
142 void VisitGotoStmt(GotoStmt *Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000143
Chris Lattner17a1a722007-08-30 01:00:35 +0000144 // Exprs
145 void VisitExpr(Expr *Node);
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000146 void VisitCastExpr(CastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000147 void VisitDeclRefExpr(DeclRefExpr *Node);
Chris Lattnerd9f69102008-08-10 01:53:14 +0000148 void VisitPredefinedExpr(PredefinedExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000149 void VisitCharacterLiteral(CharacterLiteral *Node);
150 void VisitIntegerLiteral(IntegerLiteral *Node);
151 void VisitFloatingLiteral(FloatingLiteral *Node);
152 void VisitStringLiteral(StringLiteral *Str);
153 void VisitUnaryOperator(UnaryOperator *Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000154 void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000155 void VisitMemberExpr(MemberExpr *Node);
Nate Begeman213541a2008-04-18 23:10:10 +0000156 void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000157 void VisitBinaryOperator(BinaryOperator *Node);
158 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
159 void VisitAddrLabelExpr(AddrLabelExpr *Node);
John McCall6b5a61b2011-02-07 10:33:21 +0000160 void VisitBlockExpr(BlockExpr *Node);
John McCall4b9c2d22011-11-06 09:01:30 +0000161 void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000162
163 // C++
Douglas Gregor49badde2008-10-27 19:41:14 +0000164 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000165 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000166 void VisitCXXThisExpr(CXXThisExpr *Node);
Douglas Gregor49badde2008-10-27 19:41:14 +0000167 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000168 void VisitCXXConstructExpr(CXXConstructExpr *Node);
169 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
John McCall4765fa02010-12-06 08:20:24 +0000170 void VisitExprWithCleanups(ExprWithCleanups *Node);
John McCall9d5f35e2009-12-11 21:50:11 +0000171 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000172 void DumpCXXTemporary(CXXTemporary *Temporary);
Mike Stump1eb44332009-09-09 15:08:12 +0000173
Chris Lattner17a1a722007-08-30 01:00:35 +0000174 // ObjC
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000175 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000176 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000177 void VisitObjCMessageExpr(ObjCMessageExpr* Node);
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000178 void VisitObjCBoxedExpr(ObjCBoxedExpr* Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000179 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000180 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000181 void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000182 void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000183 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000184 void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000185 };
186}
187
188//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000189// Utilities
190//===----------------------------------------------------------------------===//
191
192void StmtDumper::DumpLocation(SourceLocation Loc) {
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000193 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000194
Chris Lattnere300c872007-08-30 06:17:34 +0000195 // The general format we print out is filename:line:col, but we drop pieces
196 // that haven't changed since the last loc printed.
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000197 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
198
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000199 if (PLoc.isInvalid()) {
200 OS << "<invalid sloc>";
201 return;
202 }
203
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000204 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000205 OS << PLoc.getFilename() << ':' << PLoc.getLine()
206 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000207 LastLocFilename = PLoc.getFilename();
208 LastLocLine = PLoc.getLine();
209 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000210 OS << "line" << ':' << PLoc.getLine()
211 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000212 LastLocLine = PLoc.getLine();
Chris Lattnere300c872007-08-30 06:17:34 +0000213 } else {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000214 OS << "col" << ':' << PLoc.getColumn();
Chris Lattnere300c872007-08-30 06:17:34 +0000215 }
216}
217
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000218void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000219 // Can't translate locations if a SourceManager isn't available.
220 if (SM == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000221
Chris Lattnere300c872007-08-30 06:17:34 +0000222 // TODO: If the parent expression is available, we can print a delta vs its
223 // location.
224 SourceRange R = Node->getSourceRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000225
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000226 OS << " <";
Chris Lattner311ff022007-10-16 22:36:42 +0000227 DumpLocation(R.getBegin());
228 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000229 OS << ", ";
Chris Lattner311ff022007-10-16 22:36:42 +0000230 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000231 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000232 OS << ">";
Mike Stump1eb44332009-09-09 15:08:12 +0000233
Chris Lattnere300c872007-08-30 06:17:34 +0000234 // <t2.c:123:421[blah], t2.c:412:321>
235
236}
237
238
239//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000240// Stmt printing methods.
241//===----------------------------------------------------------------------===//
242
243void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000244 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000245}
246
Chris Lattnerf9e05812007-08-09 18:03:18 +0000247void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000248 // FIXME: Need to complete/beautify this... this code simply shows the
249 // nodes are where they need to be.
250 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000251 OS << "\"typedef " << localType->getUnderlyingType().getAsString()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000252 << ' ' << *localType << '"';
Richard Smith162e1c12011-04-15 14:24:37 +0000253 } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000254 OS << "\"using " << *localType << " = "
Richard Smith162e1c12011-04-15 14:24:37 +0000255 << localType->getUnderlyingType().getAsString() << '"';
Chris Lattner6000dac2007-08-08 22:51:59 +0000256 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000257 OS << "\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000258 // Emit storage class for vardecls.
259 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
John McCalld931b082010-08-26 03:08:43 +0000260 if (V->getStorageClass() != SC_None)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000261 OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
262 << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +0000263 }
Mike Stump1eb44332009-09-09 15:08:12 +0000264
Chris Lattner39f34e92008-11-24 04:00:27 +0000265 std::string Name = VD->getNameAsString();
Mike Stump1eb44332009-09-09 15:08:12 +0000266 VD->getType().getAsStringInternal(Name,
David Blaikie4e4d0842012-03-11 07:00:24 +0000267 PrintingPolicy(VD->getASTContext().getLangOpts()));
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000268 OS << Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000269
Chris Lattner6000dac2007-08-08 22:51:59 +0000270 // If this is a vardecl with an initializer, emit it.
271 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
272 if (V->getInit()) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000273 OS << " =";
Chris Lattnerf9e05812007-08-09 18:03:18 +0000274 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000275 }
276 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000277 OS << '"';
Steve Naroff92199282007-11-17 21:37:36 +0000278 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
279 // print a free standing tag decl (e.g. "struct x;").
280 const char *tagname;
281 if (const IdentifierInfo *II = TD->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000282 tagname = II->getNameStart();
Steve Naroff92199282007-11-17 21:37:36 +0000283 else
284 tagname = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000285 OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
Steve Naroff92199282007-11-17 21:37:36 +0000286 // FIXME: print tag bodies.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000287 } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
288 // print using-directive decl (e.g. "using namespace x;")
289 const char *ns;
290 if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000291 ns = II->getNameStart();
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000292 else
293 ns = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000294 OS << '"' << UD->getDeclKindName() << ns << ";\"";
Sebastian Redl0ca43592010-05-04 10:20:17 +0000295 } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
296 // print using decl (e.g. "using std::string;")
297 const char *tn = UD->isTypeName() ? "typename " : "";
298 OS << '"' << UD->getDeclKindName() << tn;
Douglas Gregordc355712011-02-25 00:36:19 +0000299 UD->getQualifier()->print(OS,
David Blaikie4e4d0842012-03-11 07:00:24 +0000300 PrintingPolicy(UD->getASTContext().getLangOpts()));
Sebastian Redl0ca43592010-05-04 10:20:17 +0000301 OS << ";\"";
Chris Lattner4ae493c2011-02-18 02:08:43 +0000302 } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000303 OS << "label " << *LD;
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000304 } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000305 OS << "\"static_assert(";
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000306 DumpSubTree(SAD->getAssertExpr());
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000307 OS << ",";
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000308 DumpSubTree(SAD->getMessage());
309 OS << ");\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000310 } else {
David Blaikieb219cfc2011-09-23 05:06:16 +0000311 llvm_unreachable("Unexpected decl");
Chris Lattner6000dac2007-08-08 22:51:59 +0000312 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000313}
314
Ted Kremenek5399ce22007-12-12 06:59:42 +0000315void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
316 DumpStmt(Node);
Ted Kremenek04a72b72008-10-06 18:38:35 +0000317 for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
318 DI != DE; ++DI) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000319 IndentScope Indent(*this);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000320 Decl* D = *DI;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000321 OS << (void*) D << " ";
Ted Kremenek5399ce22007-12-12 06:59:42 +0000322 DumpDeclarator(D);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000323 }
324}
325
Chris Lattner6000dac2007-08-08 22:51:59 +0000326void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
327 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000328 OS << " '" << Node->getName() << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000329}
330
Chris Lattner6000dac2007-08-08 22:51:59 +0000331void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
332 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000333 OS << " '" << Node->getLabel()->getName()
334 << "':" << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000335}
336
Chris Lattner6000dac2007-08-08 22:51:59 +0000337//===----------------------------------------------------------------------===//
338// Expr printing methods.
339//===----------------------------------------------------------------------===//
340
341void StmtDumper::VisitExpr(Expr *Node) {
342 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000343}
344
Chris Lattner5f9e2722011-07-23 10:55:15 +0000345static void DumpBasePath(raw_ostream &OS, CastExpr *Node) {
John McCallf871d0c2010-08-07 06:22:56 +0000346 if (Node->path_empty())
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000347 return;
348
349 OS << " (";
350 bool First = true;
John McCallf871d0c2010-08-07 06:22:56 +0000351 for (CastExpr::path_iterator
352 I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000353 const CXXBaseSpecifier *Base = *I;
354 if (!First)
355 OS << " -> ";
356
357 const CXXRecordDecl *RD =
358 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
359
360 if (Base->isVirtual())
361 OS << "virtual ";
362 OS << RD->getName();
363 First = false;
364 }
365
366 OS << ')';
367}
368
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000369void StmtDumper::VisitCastExpr(CastExpr *Node) {
370 DumpExpr(Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000371 OS << " <" << Node->getCastKindName();
372 DumpBasePath(OS, Node);
373 OS << ">";
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000374}
375
Chris Lattner6000dac2007-08-08 22:51:59 +0000376void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
377 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000378
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000379 OS << " ";
John McCall6b5a61b2011-02-07 10:33:21 +0000380 DumpDeclRef(Node->getDecl());
Chandler Carruth3aa81402011-05-01 23:48:14 +0000381 if (Node->getDecl() != Node->getFoundDecl()) {
382 OS << " (";
383 DumpDeclRef(Node->getFoundDecl());
384 OS << ")";
385 }
John McCall6b5a61b2011-02-07 10:33:21 +0000386}
387
388void StmtDumper::DumpDeclRef(Decl *d) {
389 OS << d->getDeclKindName() << ' ' << (void*) d;
390
391 if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) {
392 OS << " '";
393 nd->getDeclName().printName(OS);
394 OS << "'";
Ted Kremenekeb641f92007-09-10 17:32:55 +0000395 }
Mike Stump1eb44332009-09-09 15:08:12 +0000396
John McCall6b5a61b2011-02-07 10:33:21 +0000397 if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) {
398 OS << ' '; DumpType(vd->getType());
399 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000400}
401
John McCall9d5f35e2009-12-11 21:50:11 +0000402void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
403 DumpExpr(Node);
404 OS << " (";
405 if (!Node->requiresADL()) OS << "no ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000406 OS << "ADL) = '" << Node->getName() << '\'';
John McCall9d5f35e2009-12-11 21:50:11 +0000407
408 UnresolvedLookupExpr::decls_iterator
409 I = Node->decls_begin(), E = Node->decls_end();
410 if (I == E) OS << " empty";
411 for (; I != E; ++I)
412 OS << " " << (void*) *I;
413}
414
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000415void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Steve Naroff466c2e32008-05-23 00:59:14 +0000416 DumpExpr(Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000417
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000418 OS << " " << Node->getDecl()->getDeclKindName()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000419 << "Decl='" << *Node->getDecl()
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000420 << "' " << (void*)Node->getDecl();
Steve Naroff218543b2008-05-23 22:01:24 +0000421 if (Node->isFreeIvar())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000422 OS << " isFreeIvar";
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000423}
424
Chris Lattnerd9f69102008-08-10 01:53:14 +0000425void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000426 DumpExpr(Node);
427 switch (Node->getIdentType()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000428 default: llvm_unreachable("unknown case");
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000429 case PredefinedExpr::Func: OS << " __func__"; break;
430 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Nico Weber28ad0632012-06-23 02:07:59 +0000431 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000432 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000433 }
434}
435
436void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000437 DumpExpr(Node);
Richard Trieu49cf8842011-11-03 23:56:23 +0000438 OS << " " << Node->getValue();
Chris Lattner6000dac2007-08-08 22:51:59 +0000439}
440
441void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
442 DumpExpr(Node);
443
444 bool isSigned = Node->getType()->isSignedIntegerType();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000445 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattner6000dac2007-08-08 22:51:59 +0000446}
447void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
448 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000449 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattner6000dac2007-08-08 22:51:59 +0000450}
Chris Lattner5d661452007-08-26 03:42:43 +0000451
Chris Lattner6000dac2007-08-08 22:51:59 +0000452void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000453 DumpExpr(Str);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000454 OS << " ";
Richard Trieu8ab09da2012-06-13 20:25:24 +0000455 Str->outputString(OS);
Chris Lattner6000dac2007-08-08 22:51:59 +0000456}
Chris Lattner17a1a722007-08-30 01:00:35 +0000457
Chris Lattner6000dac2007-08-08 22:51:59 +0000458void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000459 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000460 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
461 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000462}
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000463void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000464 DumpExpr(Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000465 switch(Node->getKind()) {
466 case UETT_SizeOf:
467 OS << " sizeof ";
468 break;
469 case UETT_AlignOf:
Jordan Rosef70a8862012-06-30 21:33:57 +0000470 OS << " alignof ";
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000471 break;
472 case UETT_VecStep:
473 OS << " vec_step ";
474 break;
475 }
Sebastian Redl05189992008-11-11 17:56:53 +0000476 if (Node->isArgumentType())
477 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000478}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000479
Chris Lattner6000dac2007-08-08 22:51:59 +0000480void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000481 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000482 OS << " " << (Node->isArrow() ? "->" : ".")
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000483 << *Node->getMemberDecl() << ' '
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000484 << (void*)Node->getMemberDecl();
Chris Lattner6000dac2007-08-08 22:51:59 +0000485}
Nate Begeman213541a2008-04-18 23:10:10 +0000486void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000487 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000488 OS << " " << Node->getAccessor().getNameStart();
Chris Lattner6000dac2007-08-08 22:51:59 +0000489}
Chris Lattner6000dac2007-08-08 22:51:59 +0000490void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
491 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000492 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnereb14fe82007-08-25 02:00:02 +0000493}
494void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
495 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000496 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
497 << "' ComputeLHSTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000498 DumpType(Node->getComputationLHSType());
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000499 OS << " ComputeResultTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000500 DumpType(Node->getComputationResultType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000501}
Chris Lattner6000dac2007-08-08 22:51:59 +0000502
John McCall6b5a61b2011-02-07 10:33:21 +0000503void StmtDumper::VisitBlockExpr(BlockExpr *Node) {
504 DumpExpr(Node);
505
John McCall6b5a61b2011-02-07 10:33:21 +0000506 BlockDecl *block = Node->getBlockDecl();
John McCall89da8cf2012-03-10 03:04:55 +0000507 OS << " decl=" << block;
508
John McCall6b5a61b2011-02-07 10:33:21 +0000509 if (block->capturesCXXThis()) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000510 IndentScope Indent(*this);
511 OS << "capture this";
John McCall6b5a61b2011-02-07 10:33:21 +0000512 }
513 for (BlockDecl::capture_iterator
514 i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000515 IndentScope Indent(*this);
516 OS << "capture ";
John McCall6b5a61b2011-02-07 10:33:21 +0000517 if (i->isByRef()) OS << "byref ";
518 if (i->isNested()) OS << "nested ";
Douglas Gregorac1303e2012-02-22 05:02:47 +0000519 if (i->getVariable())
520 DumpDeclRef(i->getVariable());
John McCall6b5a61b2011-02-07 10:33:21 +0000521 if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr());
John McCall6b5a61b2011-02-07 10:33:21 +0000522 }
John McCall6b5a61b2011-02-07 10:33:21 +0000523
524 DumpSubTree(block->getBody());
525}
526
John McCall4b9c2d22011-11-06 09:01:30 +0000527void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
528 DumpExpr(Node);
529
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000530 if (Expr *Source = Node->getSourceExpr())
John McCall4b9c2d22011-11-06 09:01:30 +0000531 DumpSubTree(Source);
John McCall4b9c2d22011-11-06 09:01:30 +0000532}
533
Chris Lattner6000dac2007-08-08 22:51:59 +0000534// GNU extensions.
535
536void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000537 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000538 OS << " " << Node->getLabel()->getName()
539 << " " << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000540}
541
Chris Lattnerf9e05812007-08-09 18:03:18 +0000542//===----------------------------------------------------------------------===//
543// C++ Expressions
544//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000545
Douglas Gregor49badde2008-10-27 19:41:14 +0000546void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000547 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000548 OS << " " << Node->getCastName()
549 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000550 << " <" << Node->getCastKindName();
551 DumpBasePath(OS, Node);
552 OS << ">";
Chris Lattner6000dac2007-08-08 22:51:59 +0000553}
554
555void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000556 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000557 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000558}
559
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000560void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
561 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000562 OS << " this";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000563}
564
Douglas Gregor49badde2008-10-27 19:41:14 +0000565void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
566 DumpExpr(Node);
Eli Friedmancc2fca22011-09-02 17:38:59 +0000567 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
568 << " <" << Node->getCastKindName() << ">";
Douglas Gregor49badde2008-10-27 19:41:14 +0000569}
570
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000571void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
572 DumpExpr(Node);
John McCalld4bbdfe2010-02-02 19:03:45 +0000573 CXXConstructorDecl *Ctor = Node->getConstructor();
574 DumpType(Ctor->getType());
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000575 if (Node->isElidable())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000576 OS << " elidable";
John McCallf8cf0b02010-08-07 06:38:55 +0000577 if (Node->requiresZeroInitialization())
578 OS << " zeroing";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000579}
580
581void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
582 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000583 OS << " ";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000584 DumpCXXTemporary(Node->getTemporary());
585}
586
John McCall4765fa02010-12-06 08:20:24 +0000587void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000588 DumpExpr(Node);
John McCall80ee6e82011-11-10 05:35:25 +0000589 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000590 IndentScope Indent(*this);
591 OS << "cleanup ";
John McCall80ee6e82011-11-10 05:35:25 +0000592 DumpDeclRef(Node->getObject(i));
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000593 }
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000594}
595
596void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000597 OS << "(CXXTemporary " << (void *)Temporary << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000598}
599
Anders Carlsson55085182007-08-21 17:43:55 +0000600//===----------------------------------------------------------------------===//
601// Obj-C Expressions
602//===----------------------------------------------------------------------===//
603
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000604void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
605 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000606 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor04badcf2010-04-21 00:45:42 +0000607 switch (Node->getReceiverKind()) {
608 case ObjCMessageExpr::Instance:
609 break;
610
611 case ObjCMessageExpr::Class:
612 OS << " class=";
613 DumpType(Node->getClassReceiver());
614 break;
615
616 case ObjCMessageExpr::SuperInstance:
617 OS << " super (instance)";
618 break;
619
620 case ObjCMessageExpr::SuperClass:
621 OS << " super (class)";
622 break;
623 }
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000624}
625
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000626void StmtDumper::VisitObjCBoxedExpr(ObjCBoxedExpr* Node) {
627 DumpExpr(Node);
628 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
629}
630
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000631void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
632 DumpStmt(Node);
Douglas Gregorc00d8e12010-04-26 16:46:50 +0000633 if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000634 OS << " catch parm = ";
635 DumpDeclarator(CatchParam);
636 } else {
637 OS << " catch all";
638 }
639}
640
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000641void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
642 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000643 OS << " ";
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000644 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000645}
646
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000647void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
648 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000649
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000650 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000651}
652
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000653void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
654 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000655
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000656 OS << ' ' <<* Node->getProtocol();
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000657}
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000658
659void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
660 DumpExpr(Node);
John McCall12f78a62010-12-02 01:19:52 +0000661 if (Node->isImplicitProperty()) {
Fariborz Jahanian99130e52010-12-22 19:46:35 +0000662 OS << " Kind=MethodRef Getter=\"";
663 if (Node->getImplicitPropertyGetter())
664 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
665 else
666 OS << "(null)";
667
668 OS << "\" Setter=\"";
John McCall12f78a62010-12-02 01:19:52 +0000669 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
670 OS << Setter->getSelector().getAsString();
671 else
672 OS << "(null)";
673 OS << "\"";
674 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000675 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCall12f78a62010-12-02 01:19:52 +0000676 }
Fariborz Jahanian5daf5702008-11-22 18:39:36 +0000677
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000678 if (Node->isSuperReceiver())
679 OS << " super";
Argyrios Kyrtzidisb085d892012-03-30 00:19:18 +0000680
681 OS << " Messaging=";
682 if (Node->isMessagingGetter() && Node->isMessagingSetter())
683 OS << "Getter&Setter";
684 else if (Node->isMessagingGetter())
685 OS << "Getter";
686 else if (Node->isMessagingSetter())
687 OS << "Setter";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000688}
689
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000690void StmtDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
691 DumpExpr(Node);
692 if (Node->isArraySubscriptRefExpr())
693 OS << " Kind=ArraySubscript GetterForArray=\"";
694 else
695 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
696 if (Node->getAtIndexMethodDecl())
697 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
698 else
699 OS << "(null)";
700
701 if (Node->isArraySubscriptRefExpr())
702 OS << "\" SetterForArray=\"";
703 else
704 OS << "\" SetterForDictionary=\"";
705 if (Node->setAtIndexMethodDecl())
706 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
707 else
708 OS << "(null)";
709}
710
711void StmtDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
712 DumpExpr(Node);
713 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
714}
715
Chris Lattner6000dac2007-08-08 22:51:59 +0000716//===----------------------------------------------------------------------===//
717// Stmt method implementations
718//===----------------------------------------------------------------------===//
719
Chris Lattnere300c872007-08-30 06:17:34 +0000720void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000721 dump(llvm::errs(), SM);
722}
723
Chris Lattner5f9e2722011-07-23 10:55:15 +0000724void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Dmitri Gribenko95f61902012-11-16 21:43:31 +0000725 StmtDumper P(&SM, OS);
Chris Lattnerb3938792007-08-30 00:53:54 +0000726 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000727}
728
Chris Lattner6000dac2007-08-08 22:51:59 +0000729void Stmt::dump() const {
Dmitri Gribenko95f61902012-11-16 21:43:31 +0000730 StmtDumper P(0, llvm::errs());
Chris Lattnerb3938792007-08-30 00:53:54 +0000731 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner6000dac2007-08-08 22:51:59 +0000732}