blob: d5e12c873d0e13771052e850475128fca4d17693 [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"
Ted Kremenek91d1d7a2007-10-17 18:36:42 +000016#include "clang/AST/DeclObjC.h"
Douglas Gregor2a3009a2009-02-03 19:21:40 +000017#include "clang/AST/DeclCXX.h"
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000018#include "clang/AST/PrettyPrinter.h"
Chris Lattnere300c872007-08-30 06:17:34 +000019#include "clang/Basic/SourceManager.h"
Daniel Dunbar806c12e2009-12-03 09:13:13 +000020#include "llvm/Support/raw_ostream.h"
Chris Lattner6000dac2007-08-08 22:51:59 +000021using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// StmtDumper Visitor
25//===----------------------------------------------------------------------===//
26
27namespace {
Benjamin Kramer770b4a82009-11-28 19:03:38 +000028 class StmtDumper : public StmtVisitor<StmtDumper> {
Chris Lattnere300c872007-08-30 06:17:34 +000029 SourceManager *SM;
Chris Lattner5f9e2722011-07-23 10:55:15 +000030 raw_ostream &OS;
Chris Lattner6000dac2007-08-08 22:51:59 +000031 unsigned IndentLevel;
Mike Stump1eb44332009-09-09 15:08:12 +000032
Chris Lattner6000dac2007-08-08 22:51:59 +000033 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
34 /// the first few levels of an AST. This keeps track of how many ast levels
35 /// are left.
36 unsigned MaxDepth;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Chris Lattnere300c872007-08-30 06:17:34 +000038 /// LastLocFilename/LastLocLine - Keep track of the last location we print
39 /// out so that we can print out deltas from then on out.
40 const char *LastLocFilename;
41 unsigned LastLocLine;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000042
Chris Lattner6000dac2007-08-08 22:51:59 +000043 public:
Chris Lattner5f9e2722011-07-23 10:55:15 +000044 StmtDumper(SourceManager *sm, raw_ostream &os, unsigned maxDepth)
Daniel Dunbar806c12e2009-12-03 09:13:13 +000045 : SM(sm), OS(os), IndentLevel(0-1), MaxDepth(maxDepth) {
Chris Lattnere300c872007-08-30 06:17:34 +000046 LastLocFilename = "";
47 LastLocLine = ~0U;
48 }
Mike Stump1eb44332009-09-09 15:08:12 +000049
Chris Lattnerf9e05812007-08-09 18:03:18 +000050 void DumpSubTree(Stmt *S) {
Chris Lattner6000dac2007-08-08 22:51:59 +000051 // Prune the recursion if not using dump all.
52 if (MaxDepth == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +000053
Chris Lattnerf9e05812007-08-09 18:03:18 +000054 ++IndentLevel;
Chris Lattner6000dac2007-08-08 22:51:59 +000055 if (S) {
Ted Kremenek5399ce22007-12-12 06:59:42 +000056 if (DeclStmt* DS = dyn_cast<DeclStmt>(S))
57 VisitDeclStmt(DS);
Mike Stump1eb44332009-09-09 15:08:12 +000058 else {
Ted Kremenek5399ce22007-12-12 06:59:42 +000059 Visit(S);
Mike Stump1eb44332009-09-09 15:08:12 +000060
Ted Kremenek5399ce22007-12-12 06:59:42 +000061 // Print out children.
John McCall7502c1d2011-02-13 04:07:26 +000062 Stmt::child_range CI = S->children();
63 if (CI) {
64 while (CI) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +000065 OS << '\n';
Ted Kremenek5399ce22007-12-12 06:59:42 +000066 DumpSubTree(*CI++);
67 }
Chris Lattnerb3938792007-08-30 00:53:54 +000068 }
69 }
Chris Lattnera46325e2010-05-25 17:56:43 +000070 OS << ')';
Chris Lattner6000dac2007-08-08 22:51:59 +000071 } else {
72 Indent();
Daniel Dunbar806c12e2009-12-03 09:13:13 +000073 OS << "<<<NULL>>>";
Chris Lattner6000dac2007-08-08 22:51:59 +000074 }
Chris Lattnerf9e05812007-08-09 18:03:18 +000075 --IndentLevel;
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
Chris Lattner6000dac2007-08-08 22:51:59 +000080 void Indent() const {
81 for (int i = 0, e = IndentLevel; i < e; ++i)
Daniel Dunbar806c12e2009-12-03 09:13:13 +000082 OS << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +000083 }
Mike Stump1eb44332009-09-09 15:08:12 +000084
Steve Naroff9dcbfa42007-09-01 21:08:38 +000085 void DumpType(QualType T) {
John McCall49f4e1c2010-12-10 11:01:00 +000086 SplitQualType T_split = T.split();
87 OS << "'" << QualType::getAsString(T_split) << "'";
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000088
Douglas Gregor61366e92008-12-24 00:01:03 +000089 if (!T.isNull()) {
John McCall0953e762009-09-24 19:53:00 +000090 // If the type is sugared, also dump a (shallow) desugared type.
John McCall49f4e1c2010-12-10 11:01:00 +000091 SplitQualType D_split = T.getSplitDesugaredType();
92 if (T_split != D_split)
93 OS << ":'" << QualType::getAsString(D_split) << "'";
Chris Lattnerbad37852008-04-02 05:06:23 +000094 }
Chris Lattnerfd8f7da2007-08-09 00:36:22 +000095 }
John McCall6b5a61b2011-02-07 10:33:21 +000096 void DumpDeclRef(Decl *node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +000097 void DumpStmt(const Stmt *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +000098 Indent();
Daniel Dunbar806c12e2009-12-03 09:13:13 +000099 OS << "(" << Node->getStmtClassName()
100 << " " << (void*)Node;
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000101 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000102 }
John McCallf89e55a2010-11-18 06:31:45 +0000103 void DumpValueKind(ExprValueKind K) {
104 switch (K) {
105 case VK_RValue: break;
106 case VK_LValue: OS << " lvalue"; break;
107 case VK_XValue: OS << " xvalue"; break;
108 }
109 }
110 void DumpObjectKind(ExprObjectKind K) {
111 switch (K) {
112 case OK_Ordinary: break;
113 case OK_BitField: OS << " bitfield"; break;
114 case OK_ObjCProperty: OS << " objcproperty"; break;
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000115 case OK_ObjCSubscript: OS << " objcsubscript"; break;
John McCallf89e55a2010-11-18 06:31:45 +0000116 case OK_VectorComponent: OS << " vectorcomponent"; break;
117 }
118 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000119 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000120 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000121 OS << ' ';
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000122 DumpType(Node->getType());
John McCallf89e55a2010-11-18 06:31:45 +0000123 DumpValueKind(Node->getValueKind());
124 DumpObjectKind(Node->getObjectKind());
Chris Lattner6000dac2007-08-08 22:51:59 +0000125 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000126 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000127 void DumpLocation(SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000128
Chris Lattner17a1a722007-08-30 01:00:35 +0000129 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000130 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000131 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000132 void VisitLabelStmt(LabelStmt *Node);
133 void VisitGotoStmt(GotoStmt *Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000134
Chris Lattner17a1a722007-08-30 01:00:35 +0000135 // Exprs
136 void VisitExpr(Expr *Node);
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000137 void VisitCastExpr(CastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000138 void VisitDeclRefExpr(DeclRefExpr *Node);
Chris Lattnerd9f69102008-08-10 01:53:14 +0000139 void VisitPredefinedExpr(PredefinedExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000140 void VisitCharacterLiteral(CharacterLiteral *Node);
141 void VisitIntegerLiteral(IntegerLiteral *Node);
142 void VisitFloatingLiteral(FloatingLiteral *Node);
143 void VisitStringLiteral(StringLiteral *Str);
144 void VisitUnaryOperator(UnaryOperator *Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000145 void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000146 void VisitMemberExpr(MemberExpr *Node);
Nate Begeman213541a2008-04-18 23:10:10 +0000147 void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000148 void VisitBinaryOperator(BinaryOperator *Node);
149 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
150 void VisitAddrLabelExpr(AddrLabelExpr *Node);
John McCall6b5a61b2011-02-07 10:33:21 +0000151 void VisitBlockExpr(BlockExpr *Node);
John McCall4b9c2d22011-11-06 09:01:30 +0000152 void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000153
154 // C++
Douglas Gregor49badde2008-10-27 19:41:14 +0000155 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000156 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000157 void VisitCXXThisExpr(CXXThisExpr *Node);
Douglas Gregor49badde2008-10-27 19:41:14 +0000158 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000159 void VisitCXXConstructExpr(CXXConstructExpr *Node);
160 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
John McCall4765fa02010-12-06 08:20:24 +0000161 void VisitExprWithCleanups(ExprWithCleanups *Node);
John McCall9d5f35e2009-12-11 21:50:11 +0000162 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000163 void DumpCXXTemporary(CXXTemporary *Temporary);
Mike Stump1eb44332009-09-09 15:08:12 +0000164
Chris Lattner17a1a722007-08-30 01:00:35 +0000165 // ObjC
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000166 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000167 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000168 void VisitObjCMessageExpr(ObjCMessageExpr* Node);
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000169 void VisitObjCBoxedExpr(ObjCBoxedExpr* Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000170 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000171 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000172 void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000173 void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000174 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000175 void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000176 };
177}
178
179//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000180// Utilities
181//===----------------------------------------------------------------------===//
182
183void StmtDumper::DumpLocation(SourceLocation Loc) {
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000184 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Chris Lattnere300c872007-08-30 06:17:34 +0000186 // The general format we print out is filename:line:col, but we drop pieces
187 // that haven't changed since the last loc printed.
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000188 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
189
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000190 if (PLoc.isInvalid()) {
191 OS << "<invalid sloc>";
192 return;
193 }
194
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000195 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000196 OS << PLoc.getFilename() << ':' << PLoc.getLine()
197 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000198 LastLocFilename = PLoc.getFilename();
199 LastLocLine = PLoc.getLine();
200 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000201 OS << "line" << ':' << PLoc.getLine()
202 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000203 LastLocLine = PLoc.getLine();
Chris Lattnere300c872007-08-30 06:17:34 +0000204 } else {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000205 OS << "col" << ':' << PLoc.getColumn();
Chris Lattnere300c872007-08-30 06:17:34 +0000206 }
207}
208
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000209void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000210 // Can't translate locations if a SourceManager isn't available.
211 if (SM == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000212
Chris Lattnere300c872007-08-30 06:17:34 +0000213 // TODO: If the parent expression is available, we can print a delta vs its
214 // location.
215 SourceRange R = Node->getSourceRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000216
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000217 OS << " <";
Chris Lattner311ff022007-10-16 22:36:42 +0000218 DumpLocation(R.getBegin());
219 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000220 OS << ", ";
Chris Lattner311ff022007-10-16 22:36:42 +0000221 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000222 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000223 OS << ">";
Mike Stump1eb44332009-09-09 15:08:12 +0000224
Chris Lattnere300c872007-08-30 06:17:34 +0000225 // <t2.c:123:421[blah], t2.c:412:321>
226
227}
228
229
230//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000231// Stmt printing methods.
232//===----------------------------------------------------------------------===//
233
234void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000235 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000236}
237
Chris Lattnerf9e05812007-08-09 18:03:18 +0000238void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000239 // FIXME: Need to complete/beautify this... this code simply shows the
240 // nodes are where they need to be.
241 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000242 OS << "\"typedef " << localType->getUnderlyingType().getAsString()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000243 << ' ' << *localType << '"';
Richard Smith162e1c12011-04-15 14:24:37 +0000244 } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000245 OS << "\"using " << *localType << " = "
Richard Smith162e1c12011-04-15 14:24:37 +0000246 << localType->getUnderlyingType().getAsString() << '"';
Chris Lattner6000dac2007-08-08 22:51:59 +0000247 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000248 OS << "\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000249 // Emit storage class for vardecls.
250 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
John McCalld931b082010-08-26 03:08:43 +0000251 if (V->getStorageClass() != SC_None)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000252 OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
253 << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +0000254 }
Mike Stump1eb44332009-09-09 15:08:12 +0000255
Chris Lattner39f34e92008-11-24 04:00:27 +0000256 std::string Name = VD->getNameAsString();
Mike Stump1eb44332009-09-09 15:08:12 +0000257 VD->getType().getAsStringInternal(Name,
David Blaikie4e4d0842012-03-11 07:00:24 +0000258 PrintingPolicy(VD->getASTContext().getLangOpts()));
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000259 OS << Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000260
Chris Lattner6000dac2007-08-08 22:51:59 +0000261 // If this is a vardecl with an initializer, emit it.
262 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
263 if (V->getInit()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000264 OS << " =\n";
Chris Lattnerf9e05812007-08-09 18:03:18 +0000265 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000266 }
267 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000268 OS << '"';
Steve Naroff92199282007-11-17 21:37:36 +0000269 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
270 // print a free standing tag decl (e.g. "struct x;").
271 const char *tagname;
272 if (const IdentifierInfo *II = TD->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000273 tagname = II->getNameStart();
Steve Naroff92199282007-11-17 21:37:36 +0000274 else
275 tagname = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000276 OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
Steve Naroff92199282007-11-17 21:37:36 +0000277 // FIXME: print tag bodies.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000278 } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
279 // print using-directive decl (e.g. "using namespace x;")
280 const char *ns;
281 if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000282 ns = II->getNameStart();
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000283 else
284 ns = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000285 OS << '"' << UD->getDeclKindName() << ns << ";\"";
Sebastian Redl0ca43592010-05-04 10:20:17 +0000286 } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
287 // print using decl (e.g. "using std::string;")
288 const char *tn = UD->isTypeName() ? "typename " : "";
289 OS << '"' << UD->getDeclKindName() << tn;
Douglas Gregordc355712011-02-25 00:36:19 +0000290 UD->getQualifier()->print(OS,
David Blaikie4e4d0842012-03-11 07:00:24 +0000291 PrintingPolicy(UD->getASTContext().getLangOpts()));
Sebastian Redl0ca43592010-05-04 10:20:17 +0000292 OS << ";\"";
Chris Lattner4ae493c2011-02-18 02:08:43 +0000293 } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000294 OS << "label " << *LD;
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000295 } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
296 OS << "\"static_assert(\n";
297 DumpSubTree(SAD->getAssertExpr());
298 OS << ",\n";
299 DumpSubTree(SAD->getMessage());
300 OS << ");\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000301 } else {
David Blaikieb219cfc2011-09-23 05:06:16 +0000302 llvm_unreachable("Unexpected decl");
Chris Lattner6000dac2007-08-08 22:51:59 +0000303 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000304}
305
Ted Kremenek5399ce22007-12-12 06:59:42 +0000306void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
307 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000308 OS << "\n";
Ted Kremenek04a72b72008-10-06 18:38:35 +0000309 for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
310 DI != DE; ++DI) {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000311 Decl* D = *DI;
Ted Kremenek5399ce22007-12-12 06:59:42 +0000312 ++IndentLevel;
313 Indent();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000314 OS << (void*) D << " ";
Ted Kremenek5399ce22007-12-12 06:59:42 +0000315 DumpDeclarator(D);
Chris Lattnerf2797252009-03-29 16:04:50 +0000316 if (DI+1 != DE)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000317 OS << "\n";
Ted Kremenek5399ce22007-12-12 06:59:42 +0000318 --IndentLevel;
319 }
320}
321
Chris Lattner6000dac2007-08-08 22:51:59 +0000322void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
323 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000324 OS << " '" << Node->getName() << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000325}
326
Chris Lattner6000dac2007-08-08 22:51:59 +0000327void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
328 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000329 OS << " '" << Node->getLabel()->getName()
330 << "':" << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000331}
332
Chris Lattner6000dac2007-08-08 22:51:59 +0000333//===----------------------------------------------------------------------===//
334// Expr printing methods.
335//===----------------------------------------------------------------------===//
336
337void StmtDumper::VisitExpr(Expr *Node) {
338 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000339}
340
Chris Lattner5f9e2722011-07-23 10:55:15 +0000341static void DumpBasePath(raw_ostream &OS, CastExpr *Node) {
John McCallf871d0c2010-08-07 06:22:56 +0000342 if (Node->path_empty())
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000343 return;
344
345 OS << " (";
346 bool First = true;
John McCallf871d0c2010-08-07 06:22:56 +0000347 for (CastExpr::path_iterator
348 I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000349 const CXXBaseSpecifier *Base = *I;
350 if (!First)
351 OS << " -> ";
352
353 const CXXRecordDecl *RD =
354 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
355
356 if (Base->isVirtual())
357 OS << "virtual ";
358 OS << RD->getName();
359 First = false;
360 }
361
362 OS << ')';
363}
364
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000365void StmtDumper::VisitCastExpr(CastExpr *Node) {
366 DumpExpr(Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000367 OS << " <" << Node->getCastKindName();
368 DumpBasePath(OS, Node);
369 OS << ">";
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000370}
371
Chris Lattner6000dac2007-08-08 22:51:59 +0000372void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
373 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000374
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000375 OS << " ";
John McCall6b5a61b2011-02-07 10:33:21 +0000376 DumpDeclRef(Node->getDecl());
Chandler Carruth3aa81402011-05-01 23:48:14 +0000377 if (Node->getDecl() != Node->getFoundDecl()) {
378 OS << " (";
379 DumpDeclRef(Node->getFoundDecl());
380 OS << ")";
381 }
John McCall6b5a61b2011-02-07 10:33:21 +0000382}
383
384void StmtDumper::DumpDeclRef(Decl *d) {
385 OS << d->getDeclKindName() << ' ' << (void*) d;
386
387 if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) {
388 OS << " '";
389 nd->getDeclName().printName(OS);
390 OS << "'";
Ted Kremenekeb641f92007-09-10 17:32:55 +0000391 }
Mike Stump1eb44332009-09-09 15:08:12 +0000392
John McCall6b5a61b2011-02-07 10:33:21 +0000393 if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) {
394 OS << ' '; DumpType(vd->getType());
395 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000396}
397
John McCall9d5f35e2009-12-11 21:50:11 +0000398void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
399 DumpExpr(Node);
400 OS << " (";
401 if (!Node->requiresADL()) OS << "no ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000402 OS << "ADL) = '" << Node->getName() << '\'';
John McCall9d5f35e2009-12-11 21:50:11 +0000403
404 UnresolvedLookupExpr::decls_iterator
405 I = Node->decls_begin(), E = Node->decls_end();
406 if (I == E) OS << " empty";
407 for (; I != E; ++I)
408 OS << " " << (void*) *I;
409}
410
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000411void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Steve Naroff466c2e32008-05-23 00:59:14 +0000412 DumpExpr(Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000413
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000414 OS << " " << Node->getDecl()->getDeclKindName()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000415 << "Decl='" << *Node->getDecl()
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000416 << "' " << (void*)Node->getDecl();
Steve Naroff218543b2008-05-23 22:01:24 +0000417 if (Node->isFreeIvar())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000418 OS << " isFreeIvar";
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000419}
420
Chris Lattnerd9f69102008-08-10 01:53:14 +0000421void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000422 DumpExpr(Node);
423 switch (Node->getIdentType()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000424 default: llvm_unreachable("unknown case");
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000425 case PredefinedExpr::Func: OS << " __func__"; break;
426 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Nico Weber28ad0632012-06-23 02:07:59 +0000427 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000428 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000429 }
430}
431
432void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000433 DumpExpr(Node);
Richard Trieu49cf8842011-11-03 23:56:23 +0000434 OS << " " << Node->getValue();
Chris Lattner6000dac2007-08-08 22:51:59 +0000435}
436
437void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
438 DumpExpr(Node);
439
440 bool isSigned = Node->getType()->isSignedIntegerType();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000441 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattner6000dac2007-08-08 22:51:59 +0000442}
443void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
444 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000445 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattner6000dac2007-08-08 22:51:59 +0000446}
Chris Lattner5d661452007-08-26 03:42:43 +0000447
Chris Lattner6000dac2007-08-08 22:51:59 +0000448void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000449 DumpExpr(Str);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000450 OS << " ";
Richard Trieu8ab09da2012-06-13 20:25:24 +0000451 Str->outputString(OS);
Chris Lattner6000dac2007-08-08 22:51:59 +0000452}
Chris Lattner17a1a722007-08-30 01:00:35 +0000453
Chris Lattner6000dac2007-08-08 22:51:59 +0000454void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000455 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000456 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
457 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000458}
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000459void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000460 DumpExpr(Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000461 switch(Node->getKind()) {
462 case UETT_SizeOf:
463 OS << " sizeof ";
464 break;
465 case UETT_AlignOf:
Jordan Rosef70a8862012-06-30 21:33:57 +0000466 OS << " alignof ";
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000467 break;
468 case UETT_VecStep:
469 OS << " vec_step ";
470 break;
471 }
Sebastian Redl05189992008-11-11 17:56:53 +0000472 if (Node->isArgumentType())
473 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000474}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000475
Chris Lattner6000dac2007-08-08 22:51:59 +0000476void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000477 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000478 OS << " " << (Node->isArrow() ? "->" : ".")
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000479 << *Node->getMemberDecl() << ' '
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000480 << (void*)Node->getMemberDecl();
Chris Lattner6000dac2007-08-08 22:51:59 +0000481}
Nate Begeman213541a2008-04-18 23:10:10 +0000482void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000483 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000484 OS << " " << Node->getAccessor().getNameStart();
Chris Lattner6000dac2007-08-08 22:51:59 +0000485}
Chris Lattner6000dac2007-08-08 22:51:59 +0000486void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
487 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000488 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnereb14fe82007-08-25 02:00:02 +0000489}
490void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
491 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000492 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
493 << "' ComputeLHSTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000494 DumpType(Node->getComputationLHSType());
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000495 OS << " ComputeResultTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000496 DumpType(Node->getComputationResultType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000497}
Chris Lattner6000dac2007-08-08 22:51:59 +0000498
John McCall6b5a61b2011-02-07 10:33:21 +0000499void StmtDumper::VisitBlockExpr(BlockExpr *Node) {
500 DumpExpr(Node);
501
John McCall6b5a61b2011-02-07 10:33:21 +0000502 BlockDecl *block = Node->getBlockDecl();
John McCall89da8cf2012-03-10 03:04:55 +0000503 OS << " decl=" << block;
504
505 IndentLevel++;
John McCall6b5a61b2011-02-07 10:33:21 +0000506 if (block->capturesCXXThis()) {
507 OS << '\n'; Indent(); OS << "(capture this)";
508 }
509 for (BlockDecl::capture_iterator
510 i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
511 OS << '\n';
512 Indent();
513 OS << "(capture ";
514 if (i->isByRef()) OS << "byref ";
515 if (i->isNested()) OS << "nested ";
Douglas Gregorac1303e2012-02-22 05:02:47 +0000516 if (i->getVariable())
517 DumpDeclRef(i->getVariable());
John McCall6b5a61b2011-02-07 10:33:21 +0000518 if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr());
519 OS << ")";
520 }
521 IndentLevel--;
522
John McCall89da8cf2012-03-10 03:04:55 +0000523 OS << '\n';
John McCall6b5a61b2011-02-07 10:33:21 +0000524 DumpSubTree(block->getBody());
525}
526
John McCall4b9c2d22011-11-06 09:01:30 +0000527void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
528 DumpExpr(Node);
529
530 if (Expr *Source = Node->getSourceExpr()) {
531 OS << '\n';
532 DumpSubTree(Source);
533 }
534}
535
Chris Lattner6000dac2007-08-08 22:51:59 +0000536// GNU extensions.
537
538void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000539 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000540 OS << " " << Node->getLabel()->getName()
541 << " " << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000542}
543
Chris Lattnerf9e05812007-08-09 18:03:18 +0000544//===----------------------------------------------------------------------===//
545// C++ Expressions
546//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000547
Douglas Gregor49badde2008-10-27 19:41:14 +0000548void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000549 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000550 OS << " " << Node->getCastName()
551 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000552 << " <" << Node->getCastKindName();
553 DumpBasePath(OS, Node);
554 OS << ">";
Chris Lattner6000dac2007-08-08 22:51:59 +0000555}
556
557void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000558 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000559 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000560}
561
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000562void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
563 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000564 OS << " this";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000565}
566
Douglas Gregor49badde2008-10-27 19:41:14 +0000567void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
568 DumpExpr(Node);
Eli Friedmancc2fca22011-09-02 17:38:59 +0000569 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
570 << " <" << Node->getCastKindName() << ">";
Douglas Gregor49badde2008-10-27 19:41:14 +0000571}
572
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000573void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
574 DumpExpr(Node);
John McCalld4bbdfe2010-02-02 19:03:45 +0000575 CXXConstructorDecl *Ctor = Node->getConstructor();
576 DumpType(Ctor->getType());
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000577 if (Node->isElidable())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000578 OS << " elidable";
John McCallf8cf0b02010-08-07 06:38:55 +0000579 if (Node->requiresZeroInitialization())
580 OS << " zeroing";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000581}
582
583void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
584 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000585 OS << " ";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000586 DumpCXXTemporary(Node->getTemporary());
587}
588
John McCall4765fa02010-12-06 08:20:24 +0000589void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000590 DumpExpr(Node);
591 ++IndentLevel;
John McCall80ee6e82011-11-10 05:35:25 +0000592 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000593 OS << "\n";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000594 Indent();
John McCall80ee6e82011-11-10 05:35:25 +0000595 OS << "(cleanup ";
596 DumpDeclRef(Node->getObject(i));
597 OS << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000598 }
599 --IndentLevel;
600}
601
602void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000603 OS << "(CXXTemporary " << (void *)Temporary << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000604}
605
Anders Carlsson55085182007-08-21 17:43:55 +0000606//===----------------------------------------------------------------------===//
607// Obj-C Expressions
608//===----------------------------------------------------------------------===//
609
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000610void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
611 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000612 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor04badcf2010-04-21 00:45:42 +0000613 switch (Node->getReceiverKind()) {
614 case ObjCMessageExpr::Instance:
615 break;
616
617 case ObjCMessageExpr::Class:
618 OS << " class=";
619 DumpType(Node->getClassReceiver());
620 break;
621
622 case ObjCMessageExpr::SuperInstance:
623 OS << " super (instance)";
624 break;
625
626 case ObjCMessageExpr::SuperClass:
627 OS << " super (class)";
628 break;
629 }
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000630}
631
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000632void StmtDumper::VisitObjCBoxedExpr(ObjCBoxedExpr* Node) {
633 DumpExpr(Node);
634 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
635}
636
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000637void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
638 DumpStmt(Node);
Douglas Gregorc00d8e12010-04-26 16:46:50 +0000639 if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000640 OS << " catch parm = ";
641 DumpDeclarator(CatchParam);
642 } else {
643 OS << " catch all";
644 }
645}
646
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000647void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
648 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000649 OS << " ";
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000650 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000651}
652
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000653void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
654 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000655
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000656 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000657}
658
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000659void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
660 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000662 OS << ' ' <<* Node->getProtocol();
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000663}
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000664
665void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
666 DumpExpr(Node);
John McCall12f78a62010-12-02 01:19:52 +0000667 if (Node->isImplicitProperty()) {
Fariborz Jahanian99130e52010-12-22 19:46:35 +0000668 OS << " Kind=MethodRef Getter=\"";
669 if (Node->getImplicitPropertyGetter())
670 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
671 else
672 OS << "(null)";
673
674 OS << "\" Setter=\"";
John McCall12f78a62010-12-02 01:19:52 +0000675 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
676 OS << Setter->getSelector().getAsString();
677 else
678 OS << "(null)";
679 OS << "\"";
680 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000681 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCall12f78a62010-12-02 01:19:52 +0000682 }
Fariborz Jahanian5daf5702008-11-22 18:39:36 +0000683
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000684 if (Node->isSuperReceiver())
685 OS << " super";
Argyrios Kyrtzidisb085d892012-03-30 00:19:18 +0000686
687 OS << " Messaging=";
688 if (Node->isMessagingGetter() && Node->isMessagingSetter())
689 OS << "Getter&Setter";
690 else if (Node->isMessagingGetter())
691 OS << "Getter";
692 else if (Node->isMessagingSetter())
693 OS << "Setter";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000694}
695
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000696void StmtDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
697 DumpExpr(Node);
698 if (Node->isArraySubscriptRefExpr())
699 OS << " Kind=ArraySubscript GetterForArray=\"";
700 else
701 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
702 if (Node->getAtIndexMethodDecl())
703 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
704 else
705 OS << "(null)";
706
707 if (Node->isArraySubscriptRefExpr())
708 OS << "\" SetterForArray=\"";
709 else
710 OS << "\" SetterForDictionary=\"";
711 if (Node->setAtIndexMethodDecl())
712 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
713 else
714 OS << "(null)";
715}
716
717void StmtDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
718 DumpExpr(Node);
719 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
720}
721
Chris Lattner6000dac2007-08-08 22:51:59 +0000722//===----------------------------------------------------------------------===//
723// Stmt method implementations
724//===----------------------------------------------------------------------===//
725
726/// dump - This does a local dump of the specified AST fragment. It dumps the
727/// specified node and a few nodes underneath it, but not the whole subtree.
728/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000729void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000730 dump(llvm::errs(), SM);
731}
732
Chris Lattner5f9e2722011-07-23 10:55:15 +0000733void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000734 StmtDumper P(&SM, OS, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000735 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000736 OS << "\n";
Chris Lattner0c727a32007-08-30 00:40:08 +0000737}
738
739/// dump - This does a local dump of the specified AST fragment. It dumps the
740/// specified node and a few nodes underneath it, but not the whole subtree.
741/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000742void Stmt::dump() const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000743 StmtDumper P(0, llvm::errs(), 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000744 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000745 llvm::errs() << "\n";
Chris Lattner0c727a32007-08-30 00:40:08 +0000746}
747
748/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000749void Stmt::dumpAll(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000750 StmtDumper P(&SM, llvm::errs(), ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000751 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000752 llvm::errs() << "\n";
Chris Lattner6000dac2007-08-08 22:51:59 +0000753}
754
755/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
756void Stmt::dumpAll() const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000757 StmtDumper P(0, llvm::errs(), ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000758 P.DumpSubTree(const_cast<Stmt*>(this));
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000759 llvm::errs() << "\n";
Chris Lattner6000dac2007-08-08 22:51:59 +0000760}