blob: fbc990f6b3c21fa1c0dc404fb4e521eb43fa0da3 [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
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;
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000033 bool IsFirstLine;
Mike Stump1eb44332009-09-09 15:08:12 +000034
Chris Lattner6000dac2007-08-08 22:51:59 +000035 /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump
36 /// the first few levels of an AST. This keeps track of how many ast levels
37 /// are left.
38 unsigned MaxDepth;
Mike Stump1eb44332009-09-09 15:08:12 +000039
Chris Lattnere300c872007-08-30 06:17:34 +000040 /// LastLocFilename/LastLocLine - Keep track of the last location we print
41 /// out so that we can print out deltas from then on out.
42 const char *LastLocFilename;
43 unsigned LastLocLine;
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000044
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000045 class IndentScope {
46 StmtDumper &Dumper;
47 public:
48 IndentScope(StmtDumper &Dumper) : Dumper(Dumper) {
49 Dumper.indent();
50 }
51 ~IndentScope() {
52 Dumper.unindent();
53 }
54 };
55
Chris Lattner6000dac2007-08-08 22:51:59 +000056 public:
Chris Lattner5f9e2722011-07-23 10:55:15 +000057 StmtDumper(SourceManager *sm, raw_ostream &os, unsigned maxDepth)
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000058 : SM(sm), OS(os), IndentLevel(0), IsFirstLine(true), MaxDepth(maxDepth) {
Chris Lattnere300c872007-08-30 06:17:34 +000059 LastLocFilename = "";
60 LastLocLine = ~0U;
61 }
Mike Stump1eb44332009-09-09 15:08:12 +000062
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000063 ~StmtDumper() {
64 OS << "\n";
65 }
66
Chris Lattnerf9e05812007-08-09 18:03:18 +000067 void DumpSubTree(Stmt *S) {
Chris Lattner6000dac2007-08-08 22:51:59 +000068 // Prune the recursion if not using dump all.
69 if (MaxDepth == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +000070
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000071 IndentScope Indent(*this);
Mike Stump1eb44332009-09-09 15:08:12 +000072
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000073 if (!S) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +000074 OS << "<<<NULL>>>";
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000075 return;
Chris Lattner6000dac2007-08-08 22:51:59 +000076 }
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000077
78 if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) {
79 VisitDeclStmt(DS);
80 return;
81 }
82
83 Visit(S);
84 for (Stmt::child_range CI = S->children(); CI; CI++)
85 DumpSubTree(*CI);
Chris Lattner6000dac2007-08-08 22:51:59 +000086 }
Mike Stump1eb44332009-09-09 15:08:12 +000087
Chris Lattnerf9e05812007-08-09 18:03:18 +000088 void DumpDeclarator(Decl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000089
Manuel Klimekcb7b45e2012-11-07 00:33:12 +000090 void indent() {
91 if (IsFirstLine)
92 IsFirstLine = false;
93 else
94 OS << "\n";
95 OS.indent(IndentLevel * 2);
96 OS << "(";
97 IndentLevel++;
98 }
99
100 void unindent() {
101 OS << ")";
102 IndentLevel--;
Chris Lattner6000dac2007-08-08 22:51:59 +0000103 }
Mike Stump1eb44332009-09-09 15:08:12 +0000104
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000105 void DumpType(QualType T) {
John McCall49f4e1c2010-12-10 11:01:00 +0000106 SplitQualType T_split = T.split();
107 OS << "'" << QualType::getAsString(T_split) << "'";
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000108
Douglas Gregor61366e92008-12-24 00:01:03 +0000109 if (!T.isNull()) {
John McCall0953e762009-09-24 19:53:00 +0000110 // If the type is sugared, also dump a (shallow) desugared type.
John McCall49f4e1c2010-12-10 11:01:00 +0000111 SplitQualType D_split = T.getSplitDesugaredType();
112 if (T_split != D_split)
113 OS << ":'" << QualType::getAsString(D_split) << "'";
Chris Lattnerbad37852008-04-02 05:06:23 +0000114 }
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000115 }
John McCall6b5a61b2011-02-07 10:33:21 +0000116 void DumpDeclRef(Decl *node);
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000117 void DumpStmt(const Stmt *Node) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000118 OS << Node->getStmtClassName()
Roman Divacky31ba6132012-09-06 15:59:27 +0000119 << " " << (const void*)Node;
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000120 DumpSourceRange(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000121 }
John McCallf89e55a2010-11-18 06:31:45 +0000122 void DumpValueKind(ExprValueKind K) {
123 switch (K) {
124 case VK_RValue: break;
125 case VK_LValue: OS << " lvalue"; break;
126 case VK_XValue: OS << " xvalue"; break;
127 }
128 }
129 void DumpObjectKind(ExprObjectKind K) {
130 switch (K) {
131 case OK_Ordinary: break;
132 case OK_BitField: OS << " bitfield"; break;
133 case OK_ObjCProperty: OS << " objcproperty"; break;
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000134 case OK_ObjCSubscript: OS << " objcsubscript"; break;
John McCallf89e55a2010-11-18 06:31:45 +0000135 case OK_VectorComponent: OS << " vectorcomponent"; break;
136 }
137 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000138 void DumpExpr(const Expr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000139 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000140 OS << ' ';
Chris Lattnerfd8f7da2007-08-09 00:36:22 +0000141 DumpType(Node->getType());
John McCallf89e55a2010-11-18 06:31:45 +0000142 DumpValueKind(Node->getValueKind());
143 DumpObjectKind(Node->getObjectKind());
Chris Lattner6000dac2007-08-08 22:51:59 +0000144 }
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000145 void DumpSourceRange(const Stmt *Node);
Chris Lattnere300c872007-08-30 06:17:34 +0000146 void DumpLocation(SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Chris Lattner17a1a722007-08-30 01:00:35 +0000148 // Stmts.
Chris Lattnerc5598cb2007-08-21 04:04:25 +0000149 void VisitStmt(Stmt *Node);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000150 void VisitDeclStmt(DeclStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000151 void VisitLabelStmt(LabelStmt *Node);
152 void VisitGotoStmt(GotoStmt *Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Chris Lattner17a1a722007-08-30 01:00:35 +0000154 // Exprs
155 void VisitExpr(Expr *Node);
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000156 void VisitCastExpr(CastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000157 void VisitDeclRefExpr(DeclRefExpr *Node);
Chris Lattnerd9f69102008-08-10 01:53:14 +0000158 void VisitPredefinedExpr(PredefinedExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000159 void VisitCharacterLiteral(CharacterLiteral *Node);
160 void VisitIntegerLiteral(IntegerLiteral *Node);
161 void VisitFloatingLiteral(FloatingLiteral *Node);
162 void VisitStringLiteral(StringLiteral *Str);
163 void VisitUnaryOperator(UnaryOperator *Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000164 void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000165 void VisitMemberExpr(MemberExpr *Node);
Nate Begeman213541a2008-04-18 23:10:10 +0000166 void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000167 void VisitBinaryOperator(BinaryOperator *Node);
168 void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
169 void VisitAddrLabelExpr(AddrLabelExpr *Node);
John McCall6b5a61b2011-02-07 10:33:21 +0000170 void VisitBlockExpr(BlockExpr *Node);
John McCall4b9c2d22011-11-06 09:01:30 +0000171 void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000172
173 // C++
Douglas Gregor49badde2008-10-27 19:41:14 +0000174 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000175 void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000176 void VisitCXXThisExpr(CXXThisExpr *Node);
Douglas Gregor49badde2008-10-27 19:41:14 +0000177 void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000178 void VisitCXXConstructExpr(CXXConstructExpr *Node);
179 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
John McCall4765fa02010-12-06 08:20:24 +0000180 void VisitExprWithCleanups(ExprWithCleanups *Node);
John McCall9d5f35e2009-12-11 21:50:11 +0000181 void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000182 void DumpCXXTemporary(CXXTemporary *Temporary);
Mike Stump1eb44332009-09-09 15:08:12 +0000183
Chris Lattner17a1a722007-08-30 01:00:35 +0000184 // ObjC
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000185 void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
Chris Lattner17a1a722007-08-30 01:00:35 +0000186 void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000187 void VisitObjCMessageExpr(ObjCMessageExpr* Node);
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000188 void VisitObjCBoxedExpr(ObjCBoxedExpr* Node);
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000189 void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000190 void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000191 void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000192 void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000193 void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000194 void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000195 };
196}
197
198//===----------------------------------------------------------------------===//
Chris Lattnere300c872007-08-30 06:17:34 +0000199// Utilities
200//===----------------------------------------------------------------------===//
201
202void StmtDumper::DumpLocation(SourceLocation Loc) {
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000203 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000204
Chris Lattnere300c872007-08-30 06:17:34 +0000205 // The general format we print out is filename:line:col, but we drop pieces
206 // that haven't changed since the last loc printed.
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000207 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
208
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000209 if (PLoc.isInvalid()) {
210 OS << "<invalid sloc>";
211 return;
212 }
213
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000214 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000215 OS << PLoc.getFilename() << ':' << PLoc.getLine()
216 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000217 LastLocFilename = PLoc.getFilename();
218 LastLocLine = PLoc.getLine();
219 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000220 OS << "line" << ':' << PLoc.getLine()
221 << ':' << PLoc.getColumn();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000222 LastLocLine = PLoc.getLine();
Chris Lattnere300c872007-08-30 06:17:34 +0000223 } else {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000224 OS << "col" << ':' << PLoc.getColumn();
Chris Lattnere300c872007-08-30 06:17:34 +0000225 }
226}
227
Steve Naroff9dcbfa42007-09-01 21:08:38 +0000228void StmtDumper::DumpSourceRange(const Stmt *Node) {
Chris Lattnere300c872007-08-30 06:17:34 +0000229 // Can't translate locations if a SourceManager isn't available.
230 if (SM == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000231
Chris Lattnere300c872007-08-30 06:17:34 +0000232 // TODO: If the parent expression is available, we can print a delta vs its
233 // location.
234 SourceRange R = Node->getSourceRange();
Mike Stump1eb44332009-09-09 15:08:12 +0000235
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000236 OS << " <";
Chris Lattner311ff022007-10-16 22:36:42 +0000237 DumpLocation(R.getBegin());
238 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000239 OS << ", ";
Chris Lattner311ff022007-10-16 22:36:42 +0000240 DumpLocation(R.getEnd());
Chris Lattnere300c872007-08-30 06:17:34 +0000241 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000242 OS << ">";
Mike Stump1eb44332009-09-09 15:08:12 +0000243
Chris Lattnere300c872007-08-30 06:17:34 +0000244 // <t2.c:123:421[blah], t2.c:412:321>
245
246}
247
248
249//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000250// Stmt printing methods.
251//===----------------------------------------------------------------------===//
252
253void StmtDumper::VisitStmt(Stmt *Node) {
Chris Lattner17a1a722007-08-30 01:00:35 +0000254 DumpStmt(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000255}
256
Chris Lattnerf9e05812007-08-09 18:03:18 +0000257void StmtDumper::DumpDeclarator(Decl *D) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000258 // FIXME: Need to complete/beautify this... this code simply shows the
259 // nodes are where they need to be.
260 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000261 OS << "\"typedef " << localType->getUnderlyingType().getAsString()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000262 << ' ' << *localType << '"';
Richard Smith162e1c12011-04-15 14:24:37 +0000263 } else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000264 OS << "\"using " << *localType << " = "
Richard Smith162e1c12011-04-15 14:24:37 +0000265 << localType->getUnderlyingType().getAsString() << '"';
Chris Lattner6000dac2007-08-08 22:51:59 +0000266 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000267 OS << "\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000268 // Emit storage class for vardecls.
269 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
John McCalld931b082010-08-26 03:08:43 +0000270 if (V->getStorageClass() != SC_None)
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000271 OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
272 << " ";
Chris Lattner6000dac2007-08-08 22:51:59 +0000273 }
Mike Stump1eb44332009-09-09 15:08:12 +0000274
Chris Lattner39f34e92008-11-24 04:00:27 +0000275 std::string Name = VD->getNameAsString();
Mike Stump1eb44332009-09-09 15:08:12 +0000276 VD->getType().getAsStringInternal(Name,
David Blaikie4e4d0842012-03-11 07:00:24 +0000277 PrintingPolicy(VD->getASTContext().getLangOpts()));
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000278 OS << Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000279
Chris Lattner6000dac2007-08-08 22:51:59 +0000280 // If this is a vardecl with an initializer, emit it.
281 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
282 if (V->getInit()) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000283 OS << " =";
Chris Lattnerf9e05812007-08-09 18:03:18 +0000284 DumpSubTree(V->getInit());
Chris Lattner6000dac2007-08-08 22:51:59 +0000285 }
286 }
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000287 OS << '"';
Steve Naroff92199282007-11-17 21:37:36 +0000288 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
289 // print a free standing tag decl (e.g. "struct x;").
290 const char *tagname;
291 if (const IdentifierInfo *II = TD->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000292 tagname = II->getNameStart();
Steve Naroff92199282007-11-17 21:37:36 +0000293 else
294 tagname = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000295 OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
Steve Naroff92199282007-11-17 21:37:36 +0000296 // FIXME: print tag bodies.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000297 } else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
298 // print using-directive decl (e.g. "using namespace x;")
299 const char *ns;
300 if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
Daniel Dunbare013d682009-10-18 20:26:12 +0000301 ns = II->getNameStart();
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000302 else
303 ns = "<anonymous>";
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000304 OS << '"' << UD->getDeclKindName() << ns << ";\"";
Sebastian Redl0ca43592010-05-04 10:20:17 +0000305 } else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
306 // print using decl (e.g. "using std::string;")
307 const char *tn = UD->isTypeName() ? "typename " : "";
308 OS << '"' << UD->getDeclKindName() << tn;
Douglas Gregordc355712011-02-25 00:36:19 +0000309 UD->getQualifier()->print(OS,
David Blaikie4e4d0842012-03-11 07:00:24 +0000310 PrintingPolicy(UD->getASTContext().getLangOpts()));
Sebastian Redl0ca43592010-05-04 10:20:17 +0000311 OS << ";\"";
Chris Lattner4ae493c2011-02-18 02:08:43 +0000312 } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
Benjamin Kramera59d20b2012-02-07 11:57:57 +0000313 OS << "label " << *LD;
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000314 } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000315 OS << "\"static_assert(";
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000316 DumpSubTree(SAD->getAssertExpr());
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000317 OS << ",";
Peter Collingbourne28ac87e2011-03-16 18:37:27 +0000318 DumpSubTree(SAD->getMessage());
319 OS << ");\"";
Chris Lattner6000dac2007-08-08 22:51:59 +0000320 } else {
David Blaikieb219cfc2011-09-23 05:06:16 +0000321 llvm_unreachable("Unexpected decl");
Chris Lattner6000dac2007-08-08 22:51:59 +0000322 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000323}
324
Ted Kremenek5399ce22007-12-12 06:59:42 +0000325void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
326 DumpStmt(Node);
Ted Kremenek04a72b72008-10-06 18:38:35 +0000327 for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
328 DI != DE; ++DI) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000329 IndentScope Indent(*this);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000330 Decl* D = *DI;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000331 OS << (void*) D << " ";
Ted Kremenek5399ce22007-12-12 06:59:42 +0000332 DumpDeclarator(D);
Ted Kremenek5399ce22007-12-12 06:59:42 +0000333 }
334}
335
Chris Lattner6000dac2007-08-08 22:51:59 +0000336void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
337 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000338 OS << " '" << Node->getName() << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000339}
340
Chris Lattner6000dac2007-08-08 22:51:59 +0000341void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
342 DumpStmt(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000343 OS << " '" << Node->getLabel()->getName()
344 << "':" << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000345}
346
Chris Lattner6000dac2007-08-08 22:51:59 +0000347//===----------------------------------------------------------------------===//
348// Expr printing methods.
349//===----------------------------------------------------------------------===//
350
351void StmtDumper::VisitExpr(Expr *Node) {
352 DumpExpr(Node);
Chris Lattner6000dac2007-08-08 22:51:59 +0000353}
354
Chris Lattner5f9e2722011-07-23 10:55:15 +0000355static void DumpBasePath(raw_ostream &OS, CastExpr *Node) {
John McCallf871d0c2010-08-07 06:22:56 +0000356 if (Node->path_empty())
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000357 return;
358
359 OS << " (";
360 bool First = true;
John McCallf871d0c2010-08-07 06:22:56 +0000361 for (CastExpr::path_iterator
362 I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000363 const CXXBaseSpecifier *Base = *I;
364 if (!First)
365 OS << " -> ";
366
367 const CXXRecordDecl *RD =
368 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
369
370 if (Base->isVirtual())
371 OS << "virtual ";
372 OS << RD->getName();
373 First = false;
374 }
375
376 OS << ')';
377}
378
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000379void StmtDumper::VisitCastExpr(CastExpr *Node) {
380 DumpExpr(Node);
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000381 OS << " <" << Node->getCastKindName();
382 DumpBasePath(OS, Node);
383 OS << ">";
Anders Carlsson27a5b9b2009-08-22 23:33:40 +0000384}
385
Chris Lattner6000dac2007-08-08 22:51:59 +0000386void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
387 DumpExpr(Node);
Ted Kremenekeb641f92007-09-10 17:32:55 +0000388
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000389 OS << " ";
John McCall6b5a61b2011-02-07 10:33:21 +0000390 DumpDeclRef(Node->getDecl());
Chandler Carruth3aa81402011-05-01 23:48:14 +0000391 if (Node->getDecl() != Node->getFoundDecl()) {
392 OS << " (";
393 DumpDeclRef(Node->getFoundDecl());
394 OS << ")";
395 }
John McCall6b5a61b2011-02-07 10:33:21 +0000396}
397
398void StmtDumper::DumpDeclRef(Decl *d) {
399 OS << d->getDeclKindName() << ' ' << (void*) d;
400
401 if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) {
402 OS << " '";
403 nd->getDeclName().printName(OS);
404 OS << "'";
Ted Kremenekeb641f92007-09-10 17:32:55 +0000405 }
Mike Stump1eb44332009-09-09 15:08:12 +0000406
John McCall6b5a61b2011-02-07 10:33:21 +0000407 if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) {
408 OS << ' '; DumpType(vd->getType());
409 }
Chris Lattner6000dac2007-08-08 22:51:59 +0000410}
411
John McCall9d5f35e2009-12-11 21:50:11 +0000412void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
413 DumpExpr(Node);
414 OS << " (";
415 if (!Node->requiresADL()) OS << "no ";
Benjamin Kramer900fc632010-04-17 09:33:03 +0000416 OS << "ADL) = '" << Node->getName() << '\'';
John McCall9d5f35e2009-12-11 21:50:11 +0000417
418 UnresolvedLookupExpr::decls_iterator
419 I = Node->decls_begin(), E = Node->decls_end();
420 if (I == E) OS << " empty";
421 for (; I != E; ++I)
422 OS << " " << (void*) *I;
423}
424
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000425void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Steve Naroff466c2e32008-05-23 00:59:14 +0000426 DumpExpr(Node);
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000427
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000428 OS << " " << Node->getDecl()->getDeclKindName()
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000429 << "Decl='" << *Node->getDecl()
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000430 << "' " << (void*)Node->getDecl();
Steve Naroff218543b2008-05-23 22:01:24 +0000431 if (Node->isFreeIvar())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000432 OS << " isFreeIvar";
Steve Naroff3c64d9e2008-03-12 13:19:12 +0000433}
434
Chris Lattnerd9f69102008-08-10 01:53:14 +0000435void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
Chris Lattner6000dac2007-08-08 22:51:59 +0000436 DumpExpr(Node);
437 switch (Node->getIdentType()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000438 default: llvm_unreachable("unknown case");
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000439 case PredefinedExpr::Func: OS << " __func__"; break;
440 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Nico Weber28ad0632012-06-23 02:07:59 +0000441 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000442 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattner6000dac2007-08-08 22:51:59 +0000443 }
444}
445
446void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000447 DumpExpr(Node);
Richard Trieu49cf8842011-11-03 23:56:23 +0000448 OS << " " << Node->getValue();
Chris Lattner6000dac2007-08-08 22:51:59 +0000449}
450
451void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
452 DumpExpr(Node);
453
454 bool isSigned = Node->getType()->isSignedIntegerType();
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000455 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattner6000dac2007-08-08 22:51:59 +0000456}
457void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
458 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000459 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattner6000dac2007-08-08 22:51:59 +0000460}
Chris Lattner5d661452007-08-26 03:42:43 +0000461
Chris Lattner6000dac2007-08-08 22:51:59 +0000462void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
Chris Lattnera0df31a2007-08-09 01:04:32 +0000463 DumpExpr(Str);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000464 OS << " ";
Richard Trieu8ab09da2012-06-13 20:25:24 +0000465 Str->outputString(OS);
Chris Lattner6000dac2007-08-08 22:51:59 +0000466}
Chris Lattner17a1a722007-08-30 01:00:35 +0000467
Chris Lattner6000dac2007-08-08 22:51:59 +0000468void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000469 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000470 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
471 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner6000dac2007-08-08 22:51:59 +0000472}
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000473void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000474 DumpExpr(Node);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000475 switch(Node->getKind()) {
476 case UETT_SizeOf:
477 OS << " sizeof ";
478 break;
479 case UETT_AlignOf:
Jordan Rosef70a8862012-06-30 21:33:57 +0000480 OS << " alignof ";
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +0000481 break;
482 case UETT_VecStep:
483 OS << " vec_step ";
484 break;
485 }
Sebastian Redl05189992008-11-11 17:56:53 +0000486 if (Node->isArgumentType())
487 DumpType(Node->getArgumentType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000488}
Chris Lattner13cb21f2007-08-09 17:35:30 +0000489
Chris Lattner6000dac2007-08-08 22:51:59 +0000490void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000491 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000492 OS << " " << (Node->isArrow() ? "->" : ".")
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000493 << *Node->getMemberDecl() << ' '
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000494 << (void*)Node->getMemberDecl();
Chris Lattner6000dac2007-08-08 22:51:59 +0000495}
Nate Begeman213541a2008-04-18 23:10:10 +0000496void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000497 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000498 OS << " " << Node->getAccessor().getNameStart();
Chris Lattner6000dac2007-08-08 22:51:59 +0000499}
Chris Lattner6000dac2007-08-08 22:51:59 +0000500void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
501 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000502 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnereb14fe82007-08-25 02:00:02 +0000503}
504void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
505 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000506 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
507 << "' ComputeLHSTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000508 DumpType(Node->getComputationLHSType());
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000509 OS << " ComputeResultTy=";
Eli Friedmanab3a8522009-03-28 01:22:36 +0000510 DumpType(Node->getComputationResultType());
Chris Lattner6000dac2007-08-08 22:51:59 +0000511}
Chris Lattner6000dac2007-08-08 22:51:59 +0000512
John McCall6b5a61b2011-02-07 10:33:21 +0000513void StmtDumper::VisitBlockExpr(BlockExpr *Node) {
514 DumpExpr(Node);
515
John McCall6b5a61b2011-02-07 10:33:21 +0000516 BlockDecl *block = Node->getBlockDecl();
John McCall89da8cf2012-03-10 03:04:55 +0000517 OS << " decl=" << block;
518
John McCall6b5a61b2011-02-07 10:33:21 +0000519 if (block->capturesCXXThis()) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000520 IndentScope Indent(*this);
521 OS << "capture this";
John McCall6b5a61b2011-02-07 10:33:21 +0000522 }
523 for (BlockDecl::capture_iterator
524 i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000525 IndentScope Indent(*this);
526 OS << "capture ";
John McCall6b5a61b2011-02-07 10:33:21 +0000527 if (i->isByRef()) OS << "byref ";
528 if (i->isNested()) OS << "nested ";
Douglas Gregorac1303e2012-02-22 05:02:47 +0000529 if (i->getVariable())
530 DumpDeclRef(i->getVariable());
John McCall6b5a61b2011-02-07 10:33:21 +0000531 if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr());
John McCall6b5a61b2011-02-07 10:33:21 +0000532 }
John McCall6b5a61b2011-02-07 10:33:21 +0000533
534 DumpSubTree(block->getBody());
535}
536
John McCall4b9c2d22011-11-06 09:01:30 +0000537void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
538 DumpExpr(Node);
539
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000540 if (Expr *Source = Node->getSourceExpr())
John McCall4b9c2d22011-11-06 09:01:30 +0000541 DumpSubTree(Source);
John McCall4b9c2d22011-11-06 09:01:30 +0000542}
543
Chris Lattner6000dac2007-08-08 22:51:59 +0000544// GNU extensions.
545
546void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000547 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000548 OS << " " << Node->getLabel()->getName()
549 << " " << (void*)Node->getLabel();
Chris Lattner6000dac2007-08-08 22:51:59 +0000550}
551
Chris Lattnerf9e05812007-08-09 18:03:18 +0000552//===----------------------------------------------------------------------===//
553// C++ Expressions
554//===----------------------------------------------------------------------===//
Chris Lattner6000dac2007-08-08 22:51:59 +0000555
Douglas Gregor49badde2008-10-27 19:41:14 +0000556void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000557 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000558 OS << " " << Node->getCastName()
559 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlsson5cf86ba2010-04-24 19:06:50 +0000560 << " <" << Node->getCastKindName();
561 DumpBasePath(OS, Node);
562 OS << ">";
Chris Lattner6000dac2007-08-08 22:51:59 +0000563}
564
565void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
Chris Lattner13cb21f2007-08-09 17:35:30 +0000566 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000567 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattner6000dac2007-08-08 22:51:59 +0000568}
569
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000570void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
571 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000572 OS << " this";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000573}
574
Douglas Gregor49badde2008-10-27 19:41:14 +0000575void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
576 DumpExpr(Node);
Eli Friedmancc2fca22011-09-02 17:38:59 +0000577 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
578 << " <" << Node->getCastKindName() << ">";
Douglas Gregor49badde2008-10-27 19:41:14 +0000579}
580
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000581void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
582 DumpExpr(Node);
John McCalld4bbdfe2010-02-02 19:03:45 +0000583 CXXConstructorDecl *Ctor = Node->getConstructor();
584 DumpType(Ctor->getType());
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000585 if (Node->isElidable())
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000586 OS << " elidable";
John McCallf8cf0b02010-08-07 06:38:55 +0000587 if (Node->requiresZeroInitialization())
588 OS << " zeroing";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000589}
590
591void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
592 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000593 OS << " ";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000594 DumpCXXTemporary(Node->getTemporary());
595}
596
John McCall4765fa02010-12-06 08:20:24 +0000597void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000598 DumpExpr(Node);
John McCall80ee6e82011-11-10 05:35:25 +0000599 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) {
Manuel Klimekcb7b45e2012-11-07 00:33:12 +0000600 IndentScope Indent(*this);
601 OS << "cleanup ";
John McCall80ee6e82011-11-10 05:35:25 +0000602 DumpDeclRef(Node->getObject(i));
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000603 }
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000604}
605
606void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) {
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000607 OS << "(CXXTemporary " << (void *)Temporary << ")";
Anders Carlsson0eca1b62009-08-12 00:21:52 +0000608}
609
Anders Carlsson55085182007-08-21 17:43:55 +0000610//===----------------------------------------------------------------------===//
611// Obj-C Expressions
612//===----------------------------------------------------------------------===//
613
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000614void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
615 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000616 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor04badcf2010-04-21 00:45:42 +0000617 switch (Node->getReceiverKind()) {
618 case ObjCMessageExpr::Instance:
619 break;
620
621 case ObjCMessageExpr::Class:
622 OS << " class=";
623 DumpType(Node->getClassReceiver());
624 break;
625
626 case ObjCMessageExpr::SuperInstance:
627 OS << " super (instance)";
628 break;
629
630 case ObjCMessageExpr::SuperClass:
631 OS << " super (class)";
632 break;
633 }
Ted Kremenekb3d914b2008-02-29 22:04:05 +0000634}
635
Argyrios Kyrtzidis36faadd2012-05-10 20:02:31 +0000636void StmtDumper::VisitObjCBoxedExpr(ObjCBoxedExpr* Node) {
637 DumpExpr(Node);
638 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
639}
640
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000641void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
642 DumpStmt(Node);
Douglas Gregorc00d8e12010-04-26 16:46:50 +0000643 if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000644 OS << " catch parm = ";
645 DumpDeclarator(CatchParam);
646 } else {
647 OS << " catch all";
648 }
649}
650
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000651void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
652 DumpExpr(Node);
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000653 OS << " ";
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000654 DumpType(Node->getEncodedType());
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000655}
656
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000657void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
658 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000659
Daniel Dunbar806c12e2009-12-03 09:13:13 +0000660 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000661}
662
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000663void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
664 DumpExpr(Node);
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000666 OS << ' ' <<* Node->getProtocol();
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000667}
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000668
669void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
670 DumpExpr(Node);
John McCall12f78a62010-12-02 01:19:52 +0000671 if (Node->isImplicitProperty()) {
Fariborz Jahanian99130e52010-12-22 19:46:35 +0000672 OS << " Kind=MethodRef Getter=\"";
673 if (Node->getImplicitPropertyGetter())
674 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
675 else
676 OS << "(null)";
677
678 OS << "\" Setter=\"";
John McCall12f78a62010-12-02 01:19:52 +0000679 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
680 OS << Setter->getSelector().getAsString();
681 else
682 OS << "(null)";
683 OS << "\"";
684 } else {
Benjamin Kramerb8989f22011-10-14 18:45:37 +0000685 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCall12f78a62010-12-02 01:19:52 +0000686 }
Fariborz Jahanian5daf5702008-11-22 18:39:36 +0000687
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +0000688 if (Node->isSuperReceiver())
689 OS << " super";
Argyrios Kyrtzidisb085d892012-03-30 00:19:18 +0000690
691 OS << " Messaging=";
692 if (Node->isMessagingGetter() && Node->isMessagingSetter())
693 OS << "Getter&Setter";
694 else if (Node->isMessagingGetter())
695 OS << "Getter";
696 else if (Node->isMessagingSetter())
697 OS << "Setter";
Douglas Gregorcd9b46e2008-11-04 14:56:14 +0000698}
699
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000700void StmtDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
701 DumpExpr(Node);
702 if (Node->isArraySubscriptRefExpr())
703 OS << " Kind=ArraySubscript GetterForArray=\"";
704 else
705 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
706 if (Node->getAtIndexMethodDecl())
707 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
708 else
709 OS << "(null)";
710
711 if (Node->isArraySubscriptRefExpr())
712 OS << "\" SetterForArray=\"";
713 else
714 OS << "\" SetterForDictionary=\"";
715 if (Node->setAtIndexMethodDecl())
716 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
717 else
718 OS << "(null)";
719}
720
721void StmtDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
722 DumpExpr(Node);
723 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
724}
725
Chris Lattner6000dac2007-08-08 22:51:59 +0000726//===----------------------------------------------------------------------===//
727// Stmt method implementations
728//===----------------------------------------------------------------------===//
729
730/// dump - This does a local dump of the specified AST fragment. It dumps the
731/// specified node and a few nodes underneath it, but not the whole subtree.
732/// This is useful in a debugger.
Chris Lattnere300c872007-08-30 06:17:34 +0000733void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000734 dump(llvm::errs(), SM);
735}
736
Chris Lattner5f9e2722011-07-23 10:55:15 +0000737void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000738 StmtDumper P(&SM, OS, 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000739 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000740}
741
742/// dump - This does a local dump of the specified AST fragment. It dumps the
743/// specified node and a few nodes underneath it, but not the whole subtree.
744/// This is useful in a debugger.
Chris Lattner6000dac2007-08-08 22:51:59 +0000745void Stmt::dump() const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000746 StmtDumper P(0, llvm::errs(), 4);
Chris Lattnerb3938792007-08-30 00:53:54 +0000747 P.DumpSubTree(const_cast<Stmt*>(this));
Chris Lattner0c727a32007-08-30 00:40:08 +0000748}
749
750/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
Chris Lattnere300c872007-08-30 06:17:34 +0000751void Stmt::dumpAll(SourceManager &SM) const {
Argyrios Kyrtzidis96680332010-08-09 10:54:31 +0000752 StmtDumper P(&SM, llvm::errs(), ~0U);
Chris Lattnerb3938792007-08-30 00:53:54 +0000753 P.DumpSubTree(const_cast<Stmt*>(this));
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));
Chris Lattner6000dac2007-08-08 22:51:59 +0000760}