blob: 3695bf3430ba7ac9a23bede206ae763b3d8d4134 [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"
Benjamin Kramer478851c2012-07-04 17:04:04 +000016#include "clang/AST/ASTContext.h"
Ted Kremenek91d1d7a2007-10-17 18:36:42 +000017#include "clang/AST/DeclObjC.h"
Douglas Gregor2a3009a2009-02-03 19:21:40 +000018#include "clang/AST/DeclCXX.h"
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000019#include "clang/AST/PrettyPrinter.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;
Mike Stump1eb44332009-09-09 15:08:12 +000033
Chris Lattner6000dac2007-08-08 22:51:59 +000034 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
35 /// the first few levels of an AST. This keeps track of how many ast levels
36 /// are left.
37 unsigned MaxDepth;
Mike Stump1eb44332009-09-09 15:08:12 +000038
Chris Lattnere300c872007-08-30 06:17:34 +000039 /// LastLocFilename/LastLocLine - Keep track of the last location we print
40 /// out so that we can print out deltas from then on out.
41 const char *LastLocFilename;
42 unsigned LastLocLine;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000043
Chris Lattner6000dac2007-08-08 22:51:59 +000044 public:
Chris Lattner5f9e2722011-07-23 10:55:15 +000045 StmtDumper(SourceManager *sm, raw_ostream &os, unsigned maxDepth)
Daniel Dunbar806c12e2009-12-03 09:13:13 +000046 : SM(sm), OS(os), IndentLevel(0-1), MaxDepth(maxDepth) {
Chris Lattnere300c872007-08-30 06:17:34 +000047 LastLocFilename = "";
48 LastLocLine = ~0U;
49 }
Mike Stump1eb44332009-09-09 15:08:12 +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;
Mike Stump1eb44332009-09-09 15:08:12 +000054
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);
Mike Stump1eb44332009-09-09 15:08:12 +000059 else {
Ted Kremenek5399ce22007-12-12 06:59:42 +000060 Visit(S);
Mike Stump1eb44332009-09-09 15:08:12 +000061
Ted Kremenek5399ce22007-12-12 06:59:42 +000062 // Print out children.
John McCall7502c1d2011-02-13 04:07:26 +000063 Stmt::child_range CI = S->children();
64 if (CI) {
65 while (CI) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +000066 OS << '\n';
Ted Kremenek5399ce22007-12-12 06:59:42 +000067 DumpSubTree(*CI++);
68 }
Chris Lattnerb3938792007-08-30 00:53:54 +000069 }
70 }
Chris Lattnera46325e2010-05-25 17:56:43 +000071 OS << ')';
Chris Lattner6000dac2007-08-08 22:51:59 +000072 } else {
73 Indent();
Daniel Dunbar806c12e2009-12-03 09:13:13 +000074 OS << "<<<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 }
Mike Stump1eb44332009-09-09 15:08:12 +000078
Chris Lattnerf9e05812007-08-09 18:03:18 +000079 void DumpDeclarator(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000080
Chris Lattner6000dac2007-08-08 22:51:59 +000081 void Indent() const {
82 for (int i = 0, e = IndentLevel; i < e; ++i)
Daniel Dunbar806c12e2009-12-03 09:13:13 +000083 OS << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +000084 }
Mike Stump1eb44332009-09-09 15:08:12 +000085
Steve Naroff9dcbfa42007-09-01 21:08:38 +000086 void DumpType(QualType T) {
John McCall49f4e1c2010-12-10 11:01:00 +000087 SplitQualType T_split = T.split();
88 OS << "'" << QualType::getAsString(T_split) << "'";
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000089
Douglas Gregor61366e92008-12-24 00:01:03 +000090 if (!T.isNull()) {
John McCall0953e762009-09-24 19:53:00 +000091 // If the type is sugared, also dump a (shallow) desugared type.
John McCall49f4e1c2010-12-10 11:01:00 +000092 SplitQualType D_split = T.getSplitDesugaredType();
93 if (T_split != D_split)
94 OS << ":'" << QualType::getAsString(D_split) << "'";
Chris Lattnerbad37852008-04-02 05:06:23 +000095 }
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000096 }
John McCall6b5a61b2011-02-07 10:33:21 +000097 void DumpDeclRef(Decl *node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +000098 void DumpStmt(const Stmt *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000099 Indent();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000100 OS << "(" << Node->getStmtClassName()
Roman Divacky31ba6132012-09-06 15:59:27 +0000101 << " " << (const void*)Node;
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000102 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000103 }
John McCallf89e55a2010-11-18 06:31:45 +0000104 void DumpValueKind(ExprValueKind K) {
105 switch (K) {
106 case VK_RValue: break;
107 case VK_LValue: OS << " lvalue"; break;
108 case VK_XValue: OS << " xvalue"; break;
109 }
110 }
111 void DumpObjectKind(ExprObjectKind K) {
112 switch (K) {
113 case OK_Ordinary: break;
114 case OK_BitField: OS << " bitfield"; break;
115 case OK_ObjCProperty: OS << " objcproperty"; break;
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000116 case OK_ObjCSubscript: OS << " objcsubscript"; break;
John McCallf89e55a2010-11-18 06:31:45 +0000117 case OK_VectorComponent: OS << " vectorcomponent"; break;
118 }
119 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000120 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000121 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000122 OS << ' ';
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000123 DumpType(Node->getType());
John McCallf89e55a2010-11-18 06:31:45 +0000124 DumpValueKind(Node->getValueKind());
125 DumpObjectKind(Node->getObjectKind());
Chris Lattner6000dac2007-08-08 22:51:59 +0000126 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000127 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000128 void DumpLocation(SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000129
Chris Lattner17a1a722007-08-30 01:00:35 +0000130 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000131 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000132 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000133 void VisitLabelStmt(LabelStmt *Node);
134 void VisitGotoStmt(GotoStmt *Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000135
Chris Lattner17a1a722007-08-30 01:00:35 +0000136 // Exprs
137 void VisitExpr(Expr *Node);
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000138 void VisitCastExpr(CastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000139 void VisitDeclRefExpr(DeclRefExpr *Node);
Chris Lattnerd9f69102008-08-10 01:53:14 +0000140 void VisitPredefinedExpr(PredefinedExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000141 void VisitCharacterLiteral(CharacterLiteral *Node);
142 void VisitIntegerLiteral(IntegerLiteral *Node);
143 void VisitFloatingLiteral(FloatingLiteral *Node);
144 void VisitStringLiteral(StringLiteral *Str);
145 void VisitUnaryOperator(UnaryOperator *Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000146 void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000147 void VisitMemberExpr(MemberExpr *Node);
Nate Begeman213541a2008-04-18 23:10:10 +0000148 void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000149 void VisitBinaryOperator(BinaryOperator *Node);
150 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
151 void VisitAddrLabelExpr(AddrLabelExpr *Node);
John McCall6b5a61b2011-02-07 10:33:21 +0000152 void VisitBlockExpr(BlockExpr *Node);
John McCall4b9c2d22011-11-06 09:01:30 +0000153 void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000154
155 // C++
Douglas Gregor49badde2008-10-27 19:41:14 +0000156 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000157 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000158 void VisitCXXThisExpr(CXXThisExpr *Node);
Douglas Gregor49badde2008-10-27 19:41:14 +0000159 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000160 void VisitCXXConstructExpr(CXXConstructExpr *Node);
161 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
John McCall4765fa02010-12-06 08:20:24 +0000162 void VisitExprWithCleanups(ExprWithCleanups *Node);
John McCall9d5f35e2009-12-11 21:50:11 +0000163 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000164 void DumpCXXTemporary(CXXTemporary *Temporary);
Mike Stump1eb44332009-09-09 15:08:12 +0000165
Chris Lattner17a1a722007-08-30 01:00:35 +0000166 // ObjC
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000167 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000168 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000169 void VisitObjCMessageExpr(ObjCMessageExpr* Node);
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000170 void VisitObjCBoxedExpr(ObjCBoxedExpr* Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000171 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000172 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000173 void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000174 void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000175 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000176 void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000177 };
178}
179
180//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000181// Utilities
182//===----------------------------------------------------------------------===//
183
184void StmtDumper::DumpLocation(SourceLocation Loc) {
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000185 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000186
Chris Lattnere300c872007-08-30 06:17:34 +0000187 // The general format we print out is filename:line:col, but we drop pieces
188 // that haven't changed since the last loc printed.
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000189 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
190
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000191 if (PLoc.isInvalid()) {
192 OS << "<invalid sloc>";
193 return;
194 }
195
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000196 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000197 OS << PLoc.getFilename() << ':' << PLoc.getLine()
198 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000199 LastLocFilename = PLoc.getFilename();
200 LastLocLine = PLoc.getLine();
201 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000202 OS << "line" << ':' << PLoc.getLine()
203 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000204 LastLocLine = PLoc.getLine();
Chris Lattnere300c872007-08-30 06:17:34 +0000205 } else {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000206 OS << "col" << ':' << PLoc.getColumn();
Chris Lattnere300c872007-08-30 06:17:34 +0000207 }
208}
209
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000210void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000211 // Can't translate locations if a SourceManager isn't available.
212 if (SM == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Chris Lattnere300c872007-08-30 06:17:34 +0000214 // TODO: If the parent expression is available, we can print a delta vs its
215 // location.
216 SourceRange R = Node->getSourceRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000217
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000218 OS << " <";
Chris Lattner311ff022007-10-16 22:36:42 +0000219 DumpLocation(R.getBegin());
220 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000221 OS << ", ";
Chris Lattner311ff022007-10-16 22:36:42 +0000222 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000223 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000224 OS << ">";
Mike Stump1eb44332009-09-09 15:08:12 +0000225
Chris Lattnere300c872007-08-30 06:17:34 +0000226 // <t2.c:123:421[blah], t2.c:412:321>
227
228}
229
230
231//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000232// Stmt printing methods.
233//===----------------------------------------------------------------------===//
234
235void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000236 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000237}
238
Chris Lattnerf9e05812007-08-09 18:03:18 +0000239void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000240 // FIXME: Need to complete/beautify this... this code simply shows the
241 // nodes are where they need to be.
242 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000243 OS << "\"typedef " << localType->getUnderlyingType().getAsString()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000244 << ' ' << *localType << '"';
Richard Smith162e1c12011-04-15 14:24:37 +0000245 } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000246 OS << "\"using " << *localType << " = "
Richard Smith162e1c12011-04-15 14:24:37 +0000247 << localType->getUnderlyingType().getAsString() << '"';
Chris Lattner6000dac2007-08-08 22:51:59 +0000248 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000249 OS << "\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000250 // Emit storage class for vardecls.
251 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
John McCalld931b082010-08-26 03:08:43 +0000252 if (V->getStorageClass() != SC_None)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000253 OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
254 << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +0000255 }
Mike Stump1eb44332009-09-09 15:08:12 +0000256
Chris Lattner39f34e92008-11-24 04:00:27 +0000257 std::string Name = VD->getNameAsString();
Mike Stump1eb44332009-09-09 15:08:12 +0000258 VD->getType().getAsStringInternal(Name,
David Blaikie4e4d0842012-03-11 07:00:24 +0000259 PrintingPolicy(VD->getASTContext().getLangOpts()));
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000260 OS << Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000261
Chris Lattner6000dac2007-08-08 22:51:59 +0000262 // If this is a vardecl with an initializer, emit it.
263 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
264 if (V->getInit()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000265 OS << " =\n";
Chris Lattnerf9e05812007-08-09 18:03:18 +0000266 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000267 }
268 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000269 OS << '"';
Steve Naroff92199282007-11-17 21:37:36 +0000270 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
271 // print a free standing tag decl (e.g. "struct x;").
272 const char *tagname;
273 if (const IdentifierInfo *II = TD->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000274 tagname = II->getNameStart();
Steve Naroff92199282007-11-17 21:37:36 +0000275 else
276 tagname = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000277 OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
Steve Naroff92199282007-11-17 21:37:36 +0000278 // FIXME: print tag bodies.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000279 } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
280 // print using-directive decl (e.g. "using namespace x;")
281 const char *ns;
282 if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000283 ns = II->getNameStart();
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000284 else
285 ns = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000286 OS << '"' << UD->getDeclKindName() << ns << ";\"";
Sebastian Redl0ca43592010-05-04 10:20:17 +0000287 } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
288 // print using decl (e.g. "using std::string;")
289 const char *tn = UD->isTypeName() ? "typename " : "";
290 OS << '"' << UD->getDeclKindName() << tn;
Douglas Gregordc355712011-02-25 00:36:19 +0000291 UD->getQualifier()->print(OS,
David Blaikie4e4d0842012-03-11 07:00:24 +0000292 PrintingPolicy(UD->getASTContext().getLangOpts()));
Sebastian Redl0ca43592010-05-04 10:20:17 +0000293 OS << ";\"";
Chris Lattner4ae493c2011-02-18 02:08:43 +0000294 } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000295 OS << "label " << *LD;
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000296 } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
297 OS << "\"static_assert(\n";
298 DumpSubTree(SAD->getAssertExpr());
299 OS << ",\n";
300 DumpSubTree(SAD->getMessage());
301 OS << ");\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000302 } else {
David Blaikieb219cfc2011-09-23 05:06:16 +0000303 llvm_unreachable("Unexpected decl");
Chris Lattner6000dac2007-08-08 22:51:59 +0000304 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000305}
306
Ted Kremenek5399ce22007-12-12 06:59:42 +0000307void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
308 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000309 OS << "\n";
Ted Kremenek04a72b72008-10-06 18:38:35 +0000310 for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
311 DI != DE; ++DI) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000312 Decl* D = *DI;
Ted Kremenek5399ce22007-12-12 06:59:42 +0000313 ++IndentLevel;
314 Indent();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000315 OS << (void*) D << " ";
Ted Kremenek5399ce22007-12-12 06:59:42 +0000316 DumpDeclarator(D);
Chris Lattnerf2797252009-03-29 16:04:50 +0000317 if (DI+1 != DE)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000318 OS << "\n";
Ted Kremenek5399ce22007-12-12 06:59:42 +0000319 --IndentLevel;
320 }
321}
322
Chris Lattner6000dac2007-08-08 22:51:59 +0000323void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
324 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000325 OS << " '" << Node->getName() << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000326}
327
Chris Lattner6000dac2007-08-08 22:51:59 +0000328void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
329 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000330 OS << " '" << Node->getLabel()->getName()
331 << "':" << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000332}
333
Chris Lattner6000dac2007-08-08 22:51:59 +0000334//===----------------------------------------------------------------------===//
335// Expr printing methods.
336//===----------------------------------------------------------------------===//
337
338void StmtDumper::VisitExpr(Expr *Node) {
339 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000340}
341
Chris Lattner5f9e2722011-07-23 10:55:15 +0000342static void DumpBasePath(raw_ostream &OS, CastExpr *Node) {
John McCallf871d0c2010-08-07 06:22:56 +0000343 if (Node->path_empty())
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000344 return;
345
346 OS << " (";
347 bool First = true;
John McCallf871d0c2010-08-07 06:22:56 +0000348 for (CastExpr::path_iterator
349 I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000350 const CXXBaseSpecifier *Base = *I;
351 if (!First)
352 OS << " -> ";
353
354 const CXXRecordDecl *RD =
355 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
356
357 if (Base->isVirtual())
358 OS << "virtual ";
359 OS << RD->getName();
360 First = false;
361 }
362
363 OS << ')';
364}
365
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000366void StmtDumper::VisitCastExpr(CastExpr *Node) {
367 DumpExpr(Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000368 OS << " <" << Node->getCastKindName();
369 DumpBasePath(OS, Node);
370 OS << ">";
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000371}
372
Chris Lattner6000dac2007-08-08 22:51:59 +0000373void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
374 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000375
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000376 OS << " ";
John McCall6b5a61b2011-02-07 10:33:21 +0000377 DumpDeclRef(Node->getDecl());
Chandler Carruth3aa81402011-05-01 23:48:14 +0000378 if (Node->getDecl() != Node->getFoundDecl()) {
379 OS << " (";
380 DumpDeclRef(Node->getFoundDecl());
381 OS << ")";
382 }
John McCall6b5a61b2011-02-07 10:33:21 +0000383}
384
385void StmtDumper::DumpDeclRef(Decl *d) {
386 OS << d->getDeclKindName() << ' ' << (void*) d;
387
388 if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) {
389 OS << " '";
390 nd->getDeclName().printName(OS);
391 OS << "'";
Ted Kremenekeb641f92007-09-10 17:32:55 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
John McCall6b5a61b2011-02-07 10:33:21 +0000394 if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) {
395 OS << ' '; DumpType(vd->getType());
396 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000397}
398
John McCall9d5f35e2009-12-11 21:50:11 +0000399void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
400 DumpExpr(Node);
401 OS << " (";
402 if (!Node->requiresADL()) OS << "no ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000403 OS << "ADL) = '" << Node->getName() << '\'';
John McCall9d5f35e2009-12-11 21:50:11 +0000404
405 UnresolvedLookupExpr::decls_iterator
406 I = Node->decls_begin(), E = Node->decls_end();
407 if (I == E) OS << " empty";
408 for (; I != E; ++I)
409 OS << " " << (void*) *I;
410}
411
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000412void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Steve Naroff466c2e32008-05-23 00:59:14 +0000413 DumpExpr(Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000414
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000415 OS << " " << Node->getDecl()->getDeclKindName()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000416 << "Decl='" << *Node->getDecl()
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000417 << "' " << (void*)Node->getDecl();
Steve Naroff218543b2008-05-23 22:01:24 +0000418 if (Node->isFreeIvar())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000419 OS << " isFreeIvar";
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000420}
421
Chris Lattnerd9f69102008-08-10 01:53:14 +0000422void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000423 DumpExpr(Node);
424 switch (Node->getIdentType()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000425 default: llvm_unreachable("unknown case");
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000426 case PredefinedExpr::Func: OS << " __func__"; break;
427 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Nico Weber28ad0632012-06-23 02:07:59 +0000428 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000429 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000430 }
431}
432
433void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000434 DumpExpr(Node);
Richard Trieu49cf8842011-11-03 23:56:23 +0000435 OS << " " << Node->getValue();
Chris Lattner6000dac2007-08-08 22:51:59 +0000436}
437
438void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
439 DumpExpr(Node);
440
441 bool isSigned = Node->getType()->isSignedIntegerType();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000442 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattner6000dac2007-08-08 22:51:59 +0000443}
444void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
445 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000446 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattner6000dac2007-08-08 22:51:59 +0000447}
Chris Lattner5d661452007-08-26 03:42:43 +0000448
Chris Lattner6000dac2007-08-08 22:51:59 +0000449void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000450 DumpExpr(Str);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000451 OS << " ";
Richard Trieu8ab09da2012-06-13 20:25:24 +0000452 Str->outputString(OS);
Chris Lattner6000dac2007-08-08 22:51:59 +0000453}
Chris Lattner17a1a722007-08-30 01:00:35 +0000454
Chris Lattner6000dac2007-08-08 22:51:59 +0000455void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000456 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000457 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
458 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000459}
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000460void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000461 DumpExpr(Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000462 switch(Node->getKind()) {
463 case UETT_SizeOf:
464 OS << " sizeof ";
465 break;
466 case UETT_AlignOf:
Jordan Rosef70a8862012-06-30 21:33:57 +0000467 OS << " alignof ";
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000468 break;
469 case UETT_VecStep:
470 OS << " vec_step ";
471 break;
472 }
Sebastian Redl05189992008-11-11 17:56:53 +0000473 if (Node->isArgumentType())
474 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000475}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000476
Chris Lattner6000dac2007-08-08 22:51:59 +0000477void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000478 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000479 OS << " " << (Node->isArrow() ? "->" : ".")
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000480 << *Node->getMemberDecl() << ' '
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000481 << (void*)Node->getMemberDecl();
Chris Lattner6000dac2007-08-08 22:51:59 +0000482}
Nate Begeman213541a2008-04-18 23:10:10 +0000483void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000484 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000485 OS << " " << Node->getAccessor().getNameStart();
Chris Lattner6000dac2007-08-08 22:51:59 +0000486}
Chris Lattner6000dac2007-08-08 22:51:59 +0000487void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
488 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000489 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnereb14fe82007-08-25 02:00:02 +0000490}
491void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
492 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000493 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
494 << "' ComputeLHSTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000495 DumpType(Node->getComputationLHSType());
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000496 OS << " ComputeResultTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000497 DumpType(Node->getComputationResultType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000498}
Chris Lattner6000dac2007-08-08 22:51:59 +0000499
John McCall6b5a61b2011-02-07 10:33:21 +0000500void StmtDumper::VisitBlockExpr(BlockExpr *Node) {
501 DumpExpr(Node);
502
John McCall6b5a61b2011-02-07 10:33:21 +0000503 BlockDecl *block = Node->getBlockDecl();
John McCall89da8cf2012-03-10 03:04:55 +0000504 OS << " decl=" << block;
505
506 IndentLevel++;
John McCall6b5a61b2011-02-07 10:33:21 +0000507 if (block->capturesCXXThis()) {
508 OS << '\n'; Indent(); OS << "(capture this)";
509 }
510 for (BlockDecl::capture_iterator
511 i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
512 OS << '\n';
513 Indent();
514 OS << "(capture ";
515 if (i->isByRef()) OS << "byref ";
516 if (i->isNested()) OS << "nested ";
Douglas Gregorac1303e2012-02-22 05:02:47 +0000517 if (i->getVariable())
518 DumpDeclRef(i->getVariable());
John McCall6b5a61b2011-02-07 10:33:21 +0000519 if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr());
520 OS << ")";
521 }
522 IndentLevel--;
523
John McCall89da8cf2012-03-10 03:04:55 +0000524 OS << '\n';
John McCall6b5a61b2011-02-07 10:33:21 +0000525 DumpSubTree(block->getBody());
526}
527
John McCall4b9c2d22011-11-06 09:01:30 +0000528void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
529 DumpExpr(Node);
530
531 if (Expr *Source = Node->getSourceExpr()) {
532 OS << '\n';
533 DumpSubTree(Source);
534 }
535}
536
Chris Lattner6000dac2007-08-08 22:51:59 +0000537// GNU extensions.
538
539void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000540 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000541 OS << " " << Node->getLabel()->getName()
542 << " " << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000543}
544
Chris Lattnerf9e05812007-08-09 18:03:18 +0000545//===----------------------------------------------------------------------===//
546// C++ Expressions
547//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000548
Douglas Gregor49badde2008-10-27 19:41:14 +0000549void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000550 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000551 OS << " " << Node->getCastName()
552 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000553 << " <" << Node->getCastKindName();
554 DumpBasePath(OS, Node);
555 OS << ">";
Chris Lattner6000dac2007-08-08 22:51:59 +0000556}
557
558void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000559 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000560 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000561}
562
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000563void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
564 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000565 OS << " this";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000566}
567
Douglas Gregor49badde2008-10-27 19:41:14 +0000568void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
569 DumpExpr(Node);
Eli Friedmancc2fca22011-09-02 17:38:59 +0000570 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
571 << " <" << Node->getCastKindName() << ">";
Douglas Gregor49badde2008-10-27 19:41:14 +0000572}
573
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000574void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
575 DumpExpr(Node);
John McCalld4bbdfe2010-02-02 19:03:45 +0000576 CXXConstructorDecl *Ctor = Node->getConstructor();
577 DumpType(Ctor->getType());
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000578 if (Node->isElidable())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000579 OS << " elidable";
John McCallf8cf0b02010-08-07 06:38:55 +0000580 if (Node->requiresZeroInitialization())
581 OS << " zeroing";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000582}
583
584void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
585 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000586 OS << " ";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000587 DumpCXXTemporary(Node->getTemporary());
588}
589
John McCall4765fa02010-12-06 08:20:24 +0000590void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000591 DumpExpr(Node);
592 ++IndentLevel;
John McCall80ee6e82011-11-10 05:35:25 +0000593 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000594 OS << "\n";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000595 Indent();
John McCall80ee6e82011-11-10 05:35:25 +0000596 OS << "(cleanup ";
597 DumpDeclRef(Node->getObject(i));
598 OS << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000599 }
600 --IndentLevel;
601}
602
603void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000604 OS << "(CXXTemporary " << (void *)Temporary << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000605}
606
Anders Carlsson55085182007-08-21 17:43:55 +0000607//===----------------------------------------------------------------------===//
608// Obj-C Expressions
609//===----------------------------------------------------------------------===//
610
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000611void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
612 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000613 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor04badcf2010-04-21 00:45:42 +0000614 switch (Node->getReceiverKind()) {
615 case ObjCMessageExpr::Instance:
616 break;
617
618 case ObjCMessageExpr::Class:
619 OS << " class=";
620 DumpType(Node->getClassReceiver());
621 break;
622
623 case ObjCMessageExpr::SuperInstance:
624 OS << " super (instance)";
625 break;
626
627 case ObjCMessageExpr::SuperClass:
628 OS << " super (class)";
629 break;
630 }
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000631}
632
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000633void StmtDumper::VisitObjCBoxedExpr(ObjCBoxedExpr* Node) {
634 DumpExpr(Node);
635 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
636}
637
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000638void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
639 DumpStmt(Node);
Douglas Gregorc00d8e12010-04-26 16:46:50 +0000640 if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000641 OS << " catch parm = ";
642 DumpDeclarator(CatchParam);
643 } else {
644 OS << " catch all";
645 }
646}
647
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000648void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
649 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000650 OS << " ";
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000651 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000652}
653
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000654void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
655 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000656
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000657 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000658}
659
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000660void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
661 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000662
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000663 OS << ' ' <<* Node->getProtocol();
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000664}
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000665
666void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
667 DumpExpr(Node);
John McCall12f78a62010-12-02 01:19:52 +0000668 if (Node->isImplicitProperty()) {
Fariborz Jahanian99130e52010-12-22 19:46:35 +0000669 OS << " Kind=MethodRef Getter=\"";
670 if (Node->getImplicitPropertyGetter())
671 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
672 else
673 OS << "(null)";
674
675 OS << "\" Setter=\"";
John McCall12f78a62010-12-02 01:19:52 +0000676 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
677 OS << Setter->getSelector().getAsString();
678 else
679 OS << "(null)";
680 OS << "\"";
681 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000682 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCall12f78a62010-12-02 01:19:52 +0000683 }
Fariborz Jahanian5daf5702008-11-22 18:39:36 +0000684
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000685 if (Node->isSuperReceiver())
686 OS << " super";
Argyrios Kyrtzidisb085d892012-03-30 00:19:18 +0000687
688 OS << " Messaging=";
689 if (Node->isMessagingGetter() && Node->isMessagingSetter())
690 OS << "Getter&Setter";
691 else if (Node->isMessagingGetter())
692 OS << "Getter";
693 else if (Node->isMessagingSetter())
694 OS << "Setter";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000695}
696
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000697void StmtDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
698 DumpExpr(Node);
699 if (Node->isArraySubscriptRefExpr())
700 OS << " Kind=ArraySubscript GetterForArray=\"";
701 else
702 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
703 if (Node->getAtIndexMethodDecl())
704 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
705 else
706 OS << "(null)";
707
708 if (Node->isArraySubscriptRefExpr())
709 OS << "\" SetterForArray=\"";
710 else
711 OS << "\" SetterForDictionary=\"";
712 if (Node->setAtIndexMethodDecl())
713 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
714 else
715 OS << "(null)";
716}
717
718void StmtDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
719 DumpExpr(Node);
720 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
721}
722
Chris Lattner6000dac2007-08-08 22:51:59 +0000723//===----------------------------------------------------------------------===//
724// Stmt method implementations
725//===----------------------------------------------------------------------===//
726
727/// dump - This does a local dump of the specified AST fragment. It dumps the
728/// specified node and a few nodes underneath it, but not the whole subtree.
729/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000730void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000731 dump(llvm::errs(), SM);
732}
733
Chris Lattner5f9e2722011-07-23 10:55:15 +0000734void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000735 StmtDumper P(&SM, OS, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000736 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000737 OS << "\n";
Chris Lattner0c727a32007-08-30 00:40:08 +0000738}
739
740/// dump - This does a local dump of the specified AST fragment. It dumps the
741/// specified node and a few nodes underneath it, but not the whole subtree.
742/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000743void Stmt::dump() const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000744 StmtDumper P(0, llvm::errs(), 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000745 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000746 llvm::errs() << "\n";
Chris Lattner0c727a32007-08-30 00:40:08 +0000747}
748
749/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000750void Stmt::dumpAll(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000751 StmtDumper P(&SM, llvm::errs(), ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000752 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000753 llvm::errs() << "\n";
Chris Lattner6000dac2007-08-08 22:51:59 +0000754}
755
756/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
757void Stmt::dumpAll() const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000758 StmtDumper P(0, llvm::errs(), ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000759 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000760 llvm::errs() << "\n";
Chris Lattner6000dac2007-08-08 22:51:59 +0000761}