blob: 79f14bc6581df45cbb9c0c66d8749d3078598602 [file] [log] [blame]
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001//===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-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 Lattnera3bcb7a2006-11-04 07:16:25 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattnercbe4f772007-08-08 22:51:59 +000010// This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
11// pretty print the AST back out to C code.
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "clang/AST/StmtVisitor.h"
Douglas Gregorc7acfdf2009-01-06 05:10:23 +000016#include "clang/AST/DeclCXX.h"
Ted Kremenek5c84c012007-10-17 18:36:42 +000017#include "clang/AST/DeclObjC.h"
Douglas Gregorcdbc5392011-01-15 01:15:58 +000018#include "clang/AST/DeclTemplate.h"
Ted Kremenek04f3cee2007-08-31 21:30:12 +000019#include "clang/AST/PrettyPrinter.h"
Ted Kremenek2d470fc2008-09-13 05:16:45 +000020#include "llvm/Support/Format.h"
Douglas Gregor882211c2010-04-28 22:16:22 +000021#include "clang/AST/Expr.h"
Douglas Gregor2b88c112010-09-08 00:15:04 +000022#include "clang/AST/ExprCXX.h"
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000023using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// StmtPrinter Visitor
27//===----------------------------------------------------------------------===//
28
29namespace {
Benjamin Kramer26222b62009-11-28 19:03:38 +000030 class StmtPrinter : public StmtVisitor<StmtPrinter> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000031 raw_ostream &OS;
Eli Friedmanef334fd2009-05-30 05:03:24 +000032 ASTContext &Context;
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000033 unsigned IndentLevel;
Ted Kremenek04f3cee2007-08-31 21:30:12 +000034 clang::PrinterHelper* Helper;
Douglas Gregor7de59662009-05-29 20:38:28 +000035 PrintingPolicy Policy;
36
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000037 public:
Chris Lattner0e62c1c2011-07-23 10:55:15 +000038 StmtPrinter(raw_ostream &os, ASTContext &C, PrinterHelper* helper,
Chris Lattnerc61089a2009-06-30 01:26:17 +000039 const PrintingPolicy &Policy,
Douglas Gregor7de59662009-05-29 20:38:28 +000040 unsigned Indentation = 0)
Eli Friedmanef334fd2009-05-30 05:03:24 +000041 : OS(os), Context(C), IndentLevel(Indentation), Helper(helper),
42 Policy(Policy) {}
Mike Stump11289f42009-09-09 15:08:12 +000043
Douglas Gregor7de59662009-05-29 20:38:28 +000044 void PrintStmt(Stmt *S) {
45 PrintStmt(S, Policy.Indentation);
46 }
47
48 void PrintStmt(Stmt *S, int SubIndent) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000049 IndentLevel += SubIndent;
Chris Lattnera076fde2007-05-31 18:21:33 +000050 if (S && isa<Expr>(S)) {
Chris Lattner882f7882006-11-04 18:52:07 +000051 // If this is an expr used in a stmt context, indent and newline it.
52 Indent();
Chris Lattner62249a62007-08-21 04:04:25 +000053 Visit(S);
Chris Lattnerfc068c12007-05-30 17:57:36 +000054 OS << ";\n";
Chris Lattner882f7882006-11-04 18:52:07 +000055 } else if (S) {
Chris Lattner62249a62007-08-21 04:04:25 +000056 Visit(S);
Chris Lattner882f7882006-11-04 18:52:07 +000057 } else {
Chris Lattner2f6ac262007-05-28 01:47:47 +000058 Indent() << "<<<NULL STATEMENT>>>\n";
Chris Lattner882f7882006-11-04 18:52:07 +000059 }
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000060 IndentLevel -= SubIndent;
Chris Lattner882f7882006-11-04 18:52:07 +000061 }
Eli Friedman15ea8802009-05-30 00:19:54 +000062
Chris Lattner073926e2007-05-20 23:04:55 +000063 void PrintRawCompoundStmt(CompoundStmt *S);
Chris Lattnerfdc195a2007-06-05 20:52:47 +000064 void PrintRawDecl(Decl *D);
Ted Kremenek15e6b402008-10-06 18:39:36 +000065 void PrintRawDeclStmt(DeclStmt *S);
Chris Lattnerc0a38dd2007-06-11 22:26:23 +000066 void PrintRawIfStmt(IfStmt *If);
Sebastian Redl9b244a82008-12-22 21:35:02 +000067 void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
Peter Collingbourne4b279a02011-02-08 21:17:54 +000068 void PrintCallArgs(CallExpr *E);
John Wiegley1c0675e2011-04-28 01:08:34 +000069 void PrintRawSEHExceptHandler(SEHExceptStmt *S);
70 void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000071
Chris Lattner882f7882006-11-04 18:52:07 +000072 void PrintExpr(Expr *E) {
73 if (E)
Chris Lattner62249a62007-08-21 04:04:25 +000074 Visit(E);
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000075 else
Chris Lattner882f7882006-11-04 18:52:07 +000076 OS << "<null expr>";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000077 }
Mike Stump11289f42009-09-09 15:08:12 +000078
Chris Lattner0e62c1c2011-07-23 10:55:15 +000079 raw_ostream &Indent(int Delta = 0) {
Douglas Gregor7de59662009-05-29 20:38:28 +000080 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
81 OS << " ";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000082 return OS;
83 }
Mike Stump11289f42009-09-09 15:08:12 +000084
Mike Stump11289f42009-09-09 15:08:12 +000085 void Visit(Stmt* S) {
Ted Kremenek04f3cee2007-08-31 21:30:12 +000086 if (Helper && Helper->handledStmt(S,OS))
87 return;
88 else StmtVisitor<StmtPrinter>::Visit(S);
89 }
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +000090
Chandler Carruthb7967b92010-10-23 08:21:37 +000091 void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +000092 Indent() << "<<unknown stmt type>>\n";
93 }
Chandler Carruthb7967b92010-10-23 08:21:37 +000094 void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +000095 OS << "<<unknown expr type>>";
96 }
97 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +000098
Argyrios Kyrtzidis30805532010-08-15 01:15:33 +000099#define ABSTRACT_STMT(CLASS)
Douglas Gregorbe35ce92008-11-14 12:46:07 +0000100#define STMT(CLASS, PARENT) \
Chris Lattner62249a62007-08-21 04:04:25 +0000101 void Visit##CLASS(CLASS *Node);
Alexis Hunt656bb312010-05-05 15:24:00 +0000102#include "clang/AST/StmtNodes.inc"
Chris Lattner71e23ce2006-11-04 20:18:38 +0000103 };
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000104}
105
Chris Lattner71e23ce2006-11-04 20:18:38 +0000106//===----------------------------------------------------------------------===//
107// Stmt printing methods.
108//===----------------------------------------------------------------------===//
109
Chris Lattner073926e2007-05-20 23:04:55 +0000110/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
111/// with no newline after the }.
112void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
113 OS << "{\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000114 for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
Chris Lattner882f7882006-11-04 18:52:07 +0000115 I != E; ++I)
116 PrintStmt(*I);
Mike Stump11289f42009-09-09 15:08:12 +0000117
Chris Lattner073926e2007-05-20 23:04:55 +0000118 Indent() << "}";
119}
120
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000121void StmtPrinter::PrintRawDecl(Decl *D) {
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000122 D->print(OS, Policy, IndentLevel);
Mike Stump74a76472009-02-10 20:16:46 +0000123}
124
Ted Kremenek15e6b402008-10-06 18:39:36 +0000125void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) {
Eli Friedman15ea8802009-05-30 00:19:54 +0000126 DeclStmt::decl_iterator Begin = S->decl_begin(), End = S->decl_end();
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000127 SmallVector<Decl*, 2> Decls;
Mike Stump11289f42009-09-09 15:08:12 +0000128 for ( ; Begin != End; ++Begin)
Eli Friedman79635842009-05-30 04:20:30 +0000129 Decls.push_back(*Begin);
Eli Friedman15ea8802009-05-30 00:19:54 +0000130
Argyrios Kyrtzidis8a803cc2009-06-30 02:35:04 +0000131 Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
Ted Kremenek15e6b402008-10-06 18:39:36 +0000132}
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000133
134void StmtPrinter::VisitNullStmt(NullStmt *Node) {
135 Indent() << ";\n";
136}
137
138void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
Eli Friedman15ea8802009-05-30 00:19:54 +0000139 Indent();
140 PrintRawDeclStmt(Node);
141 OS << ";\n";
Steve Naroff2a8ad182007-05-29 22:59:26 +0000142}
143
Chris Lattner073926e2007-05-20 23:04:55 +0000144void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
145 Indent();
146 PrintRawCompoundStmt(Node);
Chris Lattnerdf3cafb2007-05-31 05:08:56 +0000147 OS << "\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000148}
149
Chris Lattner6c0ff132006-11-05 00:19:50 +0000150void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000151 Indent(-1) << "case ";
Chris Lattner6c0ff132006-11-05 00:19:50 +0000152 PrintExpr(Node->getLHS());
153 if (Node->getRHS()) {
154 OS << " ... ";
155 PrintExpr(Node->getRHS());
156 }
157 OS << ":\n";
Mike Stump11289f42009-09-09 15:08:12 +0000158
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000159 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000160}
161
162void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000163 Indent(-1) << "default:\n";
164 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000165}
166
167void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000168 Indent(-1) << Node->getName() << ":\n";
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000169 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000170}
171
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000172void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
Sebastian Redl7b7cec62009-02-07 20:05:48 +0000173 OS << "if (";
Chris Lattner882f7882006-11-04 18:52:07 +0000174 PrintExpr(If->getCond());
Sebastian Redl7b7cec62009-02-07 20:05:48 +0000175 OS << ')';
Mike Stump11289f42009-09-09 15:08:12 +0000176
Chris Lattner073926e2007-05-20 23:04:55 +0000177 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
178 OS << ' ';
179 PrintRawCompoundStmt(CS);
180 OS << (If->getElse() ? ' ' : '\n');
181 } else {
182 OS << '\n';
183 PrintStmt(If->getThen());
184 if (If->getElse()) Indent();
185 }
Mike Stump11289f42009-09-09 15:08:12 +0000186
Chris Lattner073926e2007-05-20 23:04:55 +0000187 if (Stmt *Else = If->getElse()) {
188 OS << "else";
Mike Stump11289f42009-09-09 15:08:12 +0000189
Chris Lattner073926e2007-05-20 23:04:55 +0000190 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
191 OS << ' ';
192 PrintRawCompoundStmt(CS);
193 OS << '\n';
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000194 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
195 OS << ' ';
196 PrintRawIfStmt(ElseIf);
Chris Lattner073926e2007-05-20 23:04:55 +0000197 } else {
198 OS << '\n';
199 PrintStmt(If->getElse());
200 }
Chris Lattner882f7882006-11-04 18:52:07 +0000201 }
Chris Lattner85ed8732006-11-04 20:40:44 +0000202}
203
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000204void StmtPrinter::VisitIfStmt(IfStmt *If) {
205 Indent();
206 PrintRawIfStmt(If);
207}
208
Chris Lattnerf2174b62006-11-04 20:59:27 +0000209void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
210 Indent() << "switch (";
211 PrintExpr(Node->getCond());
Chris Lattner073926e2007-05-20 23:04:55 +0000212 OS << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000213
Chris Lattner073926e2007-05-20 23:04:55 +0000214 // Pretty print compoundstmt bodies (very common).
215 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
216 OS << " ";
217 PrintRawCompoundStmt(CS);
218 OS << "\n";
219 } else {
220 OS << "\n";
221 PrintStmt(Node->getBody());
222 }
Chris Lattnerf2174b62006-11-04 20:59:27 +0000223}
224
Chris Lattner85ed8732006-11-04 20:40:44 +0000225void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
226 Indent() << "while (";
227 PrintExpr(Node->getCond());
228 OS << ")\n";
229 PrintStmt(Node->getBody());
230}
231
232void StmtPrinter::VisitDoStmt(DoStmt *Node) {
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000233 Indent() << "do ";
234 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
235 PrintRawCompoundStmt(CS);
236 OS << " ";
237 } else {
238 OS << "\n";
239 PrintStmt(Node->getBody());
240 Indent();
241 }
Mike Stump11289f42009-09-09 15:08:12 +0000242
Eli Friedman8f1d33e2009-05-17 01:05:34 +0000243 OS << "while (";
Chris Lattner85ed8732006-11-04 20:40:44 +0000244 PrintExpr(Node->getCond());
Eli Friedman8f1d33e2009-05-17 01:05:34 +0000245 OS << ");\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000246}
247
Chris Lattner71e23ce2006-11-04 20:18:38 +0000248void StmtPrinter::VisitForStmt(ForStmt *Node) {
249 Indent() << "for (";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000250 if (Node->getInit()) {
251 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
Ted Kremenek15e6b402008-10-06 18:39:36 +0000252 PrintRawDeclStmt(DS);
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000253 else
254 PrintExpr(cast<Expr>(Node->getInit()));
255 }
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000256 OS << ";";
257 if (Node->getCond()) {
258 OS << " ";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000259 PrintExpr(Node->getCond());
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000260 }
261 OS << ";";
262 if (Node->getInc()) {
263 OS << " ";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000264 PrintExpr(Node->getInc());
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000265 }
266 OS << ") ";
Mike Stump11289f42009-09-09 15:08:12 +0000267
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000268 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
269 PrintRawCompoundStmt(CS);
270 OS << "\n";
271 } else {
272 OS << "\n";
273 PrintStmt(Node->getBody());
274 }
Chris Lattner71e23ce2006-11-04 20:18:38 +0000275}
276
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000277void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
Fariborz Jahanian83615522008-01-02 22:54:34 +0000278 Indent() << "for (";
279 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
Ted Kremenek15e6b402008-10-06 18:39:36 +0000280 PrintRawDeclStmt(DS);
Fariborz Jahanian83615522008-01-02 22:54:34 +0000281 else
282 PrintExpr(cast<Expr>(Node->getElement()));
283 OS << " in ";
284 PrintExpr(Node->getCollection());
285 OS << ") ";
Mike Stump11289f42009-09-09 15:08:12 +0000286
Fariborz Jahanian83615522008-01-02 22:54:34 +0000287 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
288 PrintRawCompoundStmt(CS);
289 OS << "\n";
290 } else {
291 OS << "\n";
292 PrintStmt(Node->getBody());
293 }
294}
295
Richard Smith02e85f32011-04-14 22:09:26 +0000296void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
297 Indent() << "for (";
298 PrintingPolicy SubPolicy(Policy);
299 SubPolicy.SuppressInitializers = true;
300 Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
301 OS << " : ";
302 PrintExpr(Node->getRangeInit());
303 OS << ") {\n";
304 PrintStmt(Node->getBody());
305 Indent() << "}\n";
306}
307
Chris Lattner16976d32006-11-05 01:46:01 +0000308void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000309 Indent() << "goto " << Node->getLabel()->getName() << ";\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000310}
311
312void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
Chris Lattner36ad1232006-11-05 01:51:06 +0000313 Indent() << "goto *";
Chris Lattner16976d32006-11-05 01:46:01 +0000314 PrintExpr(Node->getTarget());
Chris Lattnerb4619482007-05-31 06:00:14 +0000315 OS << ";\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000316}
317
318void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
Chris Lattnerb4619482007-05-31 06:00:14 +0000319 Indent() << "continue;\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000320}
321
322void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
Chris Lattnerb4619482007-05-31 06:00:14 +0000323 Indent() << "break;\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000324}
325
326
Chris Lattner882f7882006-11-04 18:52:07 +0000327void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
328 Indent() << "return";
329 if (Node->getRetValue()) {
330 OS << " ";
331 PrintExpr(Node->getRetValue());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000332 }
Chris Lattnerb4619482007-05-31 06:00:14 +0000333 OS << ";\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000334}
335
Chris Lattner73c56c02007-10-29 04:04:16 +0000336
337void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
Anders Carlsson660bdd12007-11-23 23:12:25 +0000338 Indent() << "asm ";
Mike Stump11289f42009-09-09 15:08:12 +0000339
Anders Carlsson660bdd12007-11-23 23:12:25 +0000340 if (Node->isVolatile())
341 OS << "volatile ";
Mike Stump11289f42009-09-09 15:08:12 +0000342
Anders Carlsson660bdd12007-11-23 23:12:25 +0000343 OS << "(";
Anders Carlsson81a5a692007-11-20 19:21:03 +0000344 VisitStringLiteral(Node->getAsmString());
Mike Stump11289f42009-09-09 15:08:12 +0000345
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000346 // Outputs
347 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
348 Node->getNumClobbers() != 0)
349 OS << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000350
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000351 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
352 if (i != 0)
353 OS << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000354
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000355 if (!Node->getOutputName(i).empty()) {
356 OS << '[';
357 OS << Node->getOutputName(i);
358 OS << "] ";
359 }
Mike Stump11289f42009-09-09 15:08:12 +0000360
Chris Lattner72bbf172009-03-10 04:59:06 +0000361 VisitStringLiteral(Node->getOutputConstraintLiteral(i));
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000362 OS << " ";
363 Visit(Node->getOutputExpr(i));
364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000366 // Inputs
367 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
368 OS << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000369
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000370 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
371 if (i != 0)
372 OS << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000373
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000374 if (!Node->getInputName(i).empty()) {
375 OS << '[';
376 OS << Node->getInputName(i);
377 OS << "] ";
378 }
Mike Stump11289f42009-09-09 15:08:12 +0000379
Chris Lattner72bbf172009-03-10 04:59:06 +0000380 VisitStringLiteral(Node->getInputConstraintLiteral(i));
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000381 OS << " ";
382 Visit(Node->getInputExpr(i));
383 }
Mike Stump11289f42009-09-09 15:08:12 +0000384
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000385 // Clobbers
386 if (Node->getNumClobbers() != 0)
387 OS << " : ";
Mike Stump11289f42009-09-09 15:08:12 +0000388
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000389 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
390 if (i != 0)
391 OS << ", ";
Mike Stump11289f42009-09-09 15:08:12 +0000392
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000393 VisitStringLiteral(Node->getClobber(i));
394 }
Mike Stump11289f42009-09-09 15:08:12 +0000395
Anders Carlsson81a5a692007-11-20 19:21:03 +0000396 OS << ");\n";
Chris Lattner73c56c02007-10-29 04:04:16 +0000397}
398
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000399void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
Fariborz Jahanian88157952007-11-02 18:16:07 +0000400 Indent() << "@try";
401 if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
402 PrintRawCompoundStmt(TS);
403 OS << "\n";
404 }
Mike Stump11289f42009-09-09 15:08:12 +0000405
Douglas Gregor96c79492010-04-23 22:50:49 +0000406 for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
407 ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
Fariborz Jahanian88157952007-11-02 18:16:07 +0000408 Indent() << "@catch(";
Steve Naroff371b8fb2009-03-03 19:52:17 +0000409 if (catchStmt->getCatchParamDecl()) {
410 if (Decl *DS = catchStmt->getCatchParamDecl())
411 PrintRawDecl(DS);
Fariborz Jahanian88157952007-11-02 18:16:07 +0000412 }
413 OS << ")";
Mike Stump11289f42009-09-09 15:08:12 +0000414 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
415 PrintRawCompoundStmt(CS);
416 OS << "\n";
417 }
Fariborz Jahanian88157952007-11-02 18:16:07 +0000418 }
Mike Stump11289f42009-09-09 15:08:12 +0000419
420 if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
421 Node->getFinallyStmt())) {
Fariborz Jahaniandefbf9a2007-11-07 00:46:42 +0000422 Indent() << "@finally";
423 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
Fariborz Jahanian88157952007-11-02 18:16:07 +0000424 OS << "\n";
Mike Stump11289f42009-09-09 15:08:12 +0000425 }
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000426}
427
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000428void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000429}
430
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000431void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000432 Indent() << "@catch (...) { /* todo */ } \n";
433}
434
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000435void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000436 Indent() << "@throw";
437 if (Node->getThrowExpr()) {
438 OS << " ";
439 PrintExpr(Node->getThrowExpr());
440 }
441 OS << ";\n";
442}
443
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000444void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
Fariborz Jahanianf89ca382008-01-29 18:21:32 +0000445 Indent() << "@synchronized (";
446 PrintExpr(Node->getSynchExpr());
447 OS << ")";
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000448 PrintRawCompoundStmt(Node->getSynchBody());
449 OS << "\n";
Fariborz Jahanianf89ca382008-01-29 18:21:32 +0000450}
451
John McCall31168b02011-06-15 23:02:42 +0000452void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
453 Indent() << "@autoreleasepool";
454 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
455 OS << "\n";
456}
457
Sebastian Redl9b244a82008-12-22 21:35:02 +0000458void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
459 OS << "catch (";
Sebastian Redl54c04d42008-12-22 19:15:10 +0000460 if (Decl *ExDecl = Node->getExceptionDecl())
461 PrintRawDecl(ExDecl);
462 else
463 OS << "...";
464 OS << ") ";
465 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
Sebastian Redl9b244a82008-12-22 21:35:02 +0000466}
467
468void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
469 Indent();
470 PrintRawCXXCatchStmt(Node);
471 OS << "\n";
472}
473
474void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
475 Indent() << "try ";
476 PrintRawCompoundStmt(Node->getTryBlock());
Mike Stump11289f42009-09-09 15:08:12 +0000477 for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
Sebastian Redl9b244a82008-12-22 21:35:02 +0000478 OS << " ";
479 PrintRawCXXCatchStmt(Node->getHandler(i));
480 }
Sebastian Redl54c04d42008-12-22 19:15:10 +0000481 OS << "\n";
482}
483
John Wiegley1c0675e2011-04-28 01:08:34 +0000484void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
485 Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
486 PrintRawCompoundStmt(Node->getTryBlock());
487 SEHExceptStmt *E = Node->getExceptHandler();
488 SEHFinallyStmt *F = Node->getFinallyHandler();
489 if(E)
490 PrintRawSEHExceptHandler(E);
491 else {
492 assert(F && "Must have a finally block...");
493 PrintRawSEHFinallyStmt(F);
494 }
495 OS << "\n";
496}
497
498void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
499 OS << "__finally ";
500 PrintRawCompoundStmt(Node->getBlock());
501 OS << "\n";
502}
503
504void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
505 OS << "__except (";
506 VisitExpr(Node->getFilterExpr());
507 OS << ")\n";
508 PrintRawCompoundStmt(Node->getBlock());
509 OS << "\n";
510}
511
512void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
513 Indent();
514 PrintRawSEHExceptHandler(Node);
515 OS << "\n";
516}
517
518void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
519 Indent();
520 PrintRawSEHFinallyStmt(Node);
521 OS << "\n";
522}
523
Chris Lattner71e23ce2006-11-04 20:18:38 +0000524//===----------------------------------------------------------------------===//
525// Expr printing methods.
526//===----------------------------------------------------------------------===//
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000527
Chris Lattner882f7882006-11-04 18:52:07 +0000528void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000529 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
530 Qualifier->print(OS, Policy);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000531 OS << Node->getNameInfo();
John McCallb3774b52010-08-19 23:49:38 +0000532 if (Node->hasExplicitTemplateArgs())
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000533 OS << TemplateSpecializationType::PrintTemplateArgumentList(
534 Node->getTemplateArgs(),
535 Node->getNumTemplateArgs(),
Alexis Hunta8136cc2010-05-05 15:23:54 +0000536 Policy);
Douglas Gregorc7acfdf2009-01-06 05:10:23 +0000537}
538
John McCall8cd78132009-11-19 22:55:06 +0000539void StmtPrinter::VisitDependentScopeDeclRefExpr(
540 DependentScopeDeclRefExpr *Node) {
Axel Naumann20b27862011-01-24 15:44:00 +0000541 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
542 Qualifier->print(OS, Policy);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000543 OS << Node->getNameInfo();
John McCalle66edc12009-11-24 19:00:30 +0000544 if (Node->hasExplicitTemplateArgs())
545 OS << TemplateSpecializationType::PrintTemplateArgumentList(
546 Node->getTemplateArgs(),
547 Node->getNumTemplateArgs(),
548 Policy);
Douglas Gregor90a1a652009-03-19 17:26:29 +0000549}
550
John McCalld14a8642009-11-21 08:51:07 +0000551void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
Douglas Gregora727cb92009-06-30 22:34:41 +0000552 if (Node->getQualifier())
553 Node->getQualifier()->print(OS, Policy);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000554 OS << Node->getNameInfo();
John McCalle66edc12009-11-24 19:00:30 +0000555 if (Node->hasExplicitTemplateArgs())
556 OS << TemplateSpecializationType::PrintTemplateArgumentList(
557 Node->getTemplateArgs(),
Douglas Gregora727cb92009-06-30 22:34:41 +0000558 Node->getNumTemplateArgs(),
John McCalle66edc12009-11-24 19:00:30 +0000559 Policy);
Douglas Gregora727cb92009-06-30 22:34:41 +0000560}
561
Steve Naroffe46504b2007-11-12 14:29:37 +0000562void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Fariborz Jahanian21f54ee2007-11-12 22:29:28 +0000563 if (Node->getBase()) {
564 PrintExpr(Node->getBase());
565 OS << (Node->isArrow() ? "->" : ".");
566 }
Benjamin Kramerb11416d2010-04-17 09:33:03 +0000567 OS << Node->getDecl();
Steve Naroffe46504b2007-11-12 14:29:37 +0000568}
569
Steve Naroffec944032008-05-30 00:40:33 +0000570void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000571 if (Node->isSuperReceiver())
572 OS << "super.";
573 else if (Node->getBase()) {
Steve Naroffec944032008-05-30 00:40:33 +0000574 PrintExpr(Node->getBase());
575 OS << ".";
576 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +0000577
John McCallb7bd14f2010-12-02 01:19:52 +0000578 if (Node->isImplicitProperty())
579 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
580 else
581 OS << Node->getExplicitProperty()->getName();
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +0000582}
583
Chris Lattner6307f192008-08-10 01:53:14 +0000584void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
Anders Carlsson625bfc82007-07-21 05:21:51 +0000585 switch (Node->getIdentType()) {
586 default:
587 assert(0 && "unknown case");
Chris Lattner6307f192008-08-10 01:53:14 +0000588 case PredefinedExpr::Func:
Anders Carlsson625bfc82007-07-21 05:21:51 +0000589 OS << "__func__";
590 break;
Chris Lattner6307f192008-08-10 01:53:14 +0000591 case PredefinedExpr::Function:
Anders Carlsson625bfc82007-07-21 05:21:51 +0000592 OS << "__FUNCTION__";
593 break;
Chris Lattner6307f192008-08-10 01:53:14 +0000594 case PredefinedExpr::PrettyFunction:
Anders Carlsson625bfc82007-07-21 05:21:51 +0000595 OS << "__PRETTY_FUNCTION__";
596 break;
597 }
598}
599
Steve Naroffae4143e2007-04-26 20:39:23 +0000600void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000601 unsigned value = Node->getValue();
Douglas Gregorfb65e592011-07-27 05:40:30 +0000602
603 switch (Node->getKind()) {
604 case CharacterLiteral::Ascii: break; // no prefix.
605 case CharacterLiteral::Wide: OS << 'L'; break;
606 case CharacterLiteral::UTF16: OS << 'u'; break;
607 case CharacterLiteral::UTF32: OS << 'U'; break;
608 }
609
Chris Lattner666115c2007-07-13 23:58:20 +0000610 switch (value) {
611 case '\\':
612 OS << "'\\\\'";
613 break;
614 case '\'':
615 OS << "'\\''";
616 break;
617 case '\a':
618 // TODO: K&R: the meaning of '\\a' is different in traditional C
619 OS << "'\\a'";
620 break;
621 case '\b':
622 OS << "'\\b'";
623 break;
624 // Nonstandard escape sequence.
625 /*case '\e':
626 OS << "'\\e'";
627 break;*/
628 case '\f':
629 OS << "'\\f'";
630 break;
631 case '\n':
632 OS << "'\\n'";
633 break;
634 case '\r':
635 OS << "'\\r'";
636 break;
637 case '\t':
638 OS << "'\\t'";
639 break;
640 case '\v':
641 OS << "'\\v'";
642 break;
643 default:
Ted Kremenek652d18e2008-02-23 00:52:04 +0000644 if (value < 256 && isprint(value)) {
Chris Lattner666115c2007-07-13 23:58:20 +0000645 OS << "'" << (char)value << "'";
646 } else if (value < 256) {
Ted Kremenek2d470fc2008-09-13 05:16:45 +0000647 OS << "'\\x" << llvm::format("%x", value) << "'";
Chris Lattner666115c2007-07-13 23:58:20 +0000648 } else {
649 // FIXME what to really do here?
650 OS << value;
651 }
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000652 }
Steve Naroffae4143e2007-04-26 20:39:23 +0000653}
654
Steve Naroffdf7855b2007-02-21 23:46:25 +0000655void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
Chris Lattner06430412007-05-21 05:45:03 +0000656 bool isSigned = Node->getType()->isSignedIntegerType();
657 OS << Node->getValue().toString(10, isSigned);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Chris Lattner06430412007-05-21 05:45:03 +0000659 // Emit suffixes. Integer literals are always a builtin integer type.
John McCall9dd450b2009-09-21 23:43:11 +0000660 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
Chris Lattner06430412007-05-21 05:45:03 +0000661 default: assert(0 && "Unexpected type for integer literal!");
662 case BuiltinType::Int: break; // no suffix.
663 case BuiltinType::UInt: OS << 'U'; break;
664 case BuiltinType::Long: OS << 'L'; break;
665 case BuiltinType::ULong: OS << "UL"; break;
666 case BuiltinType::LongLong: OS << "LL"; break;
667 case BuiltinType::ULongLong: OS << "ULL"; break;
668 }
Chris Lattner882f7882006-11-04 18:52:07 +0000669}
Steve Naroffab624882007-02-21 22:05:47 +0000670void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
Chris Lattnerbf2f3862007-08-01 00:23:58 +0000671 // FIXME: print value more precisely.
Chris Lattnera0173132008-06-07 22:13:43 +0000672 OS << Node->getValueAsApproximateDouble();
Chris Lattner882f7882006-11-04 18:52:07 +0000673}
Chris Lattner1c20a172007-08-26 03:42:43 +0000674
675void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
676 PrintExpr(Node->getSubExpr());
677 OS << "i";
678}
679
Steve Naroffdf7855b2007-02-21 23:46:25 +0000680void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
Douglas Gregorfb65e592011-07-27 05:40:30 +0000681 switch (Str->getKind()) {
682 case StringLiteral::Ascii: break; // no prefix.
683 case StringLiteral::Wide: OS << 'L'; break;
684 case StringLiteral::UTF8: OS << "u8"; break;
685 case StringLiteral::UTF16: OS << 'u'; break;
686 case StringLiteral::UTF32: OS << 'U'; break;
687 }
Chris Lattner5d8f4942006-11-04 20:29:31 +0000688 OS << '"';
Anders Carlssoncbfc4b82007-10-15 02:50:23 +0000689
Chris Lattner5d8f4942006-11-04 20:29:31 +0000690 // FIXME: this doesn't print wstrings right.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000691 StringRef StrData = Str->getString();
692 for (StringRef::iterator I = StrData.begin(), E = StrData.end();
Benjamin Kramer35b077e2010-08-17 12:54:38 +0000693 I != E; ++I) {
694 unsigned char Char = *I;
Mike Stump11289f42009-09-09 15:08:12 +0000695
Chris Lattnerbb96cc42009-01-16 19:25:18 +0000696 switch (Char) {
697 default:
698 if (isprint(Char))
699 OS << (char)Char;
700 else // Output anything hard as an octal escape.
701 OS << '\\'
702 << (char)('0'+ ((Char >> 6) & 7))
703 << (char)('0'+ ((Char >> 3) & 7))
704 << (char)('0'+ ((Char >> 0) & 7));
705 break;
706 // Handle some common non-printable cases to make dumps prettier.
Chris Lattner5d8f4942006-11-04 20:29:31 +0000707 case '\\': OS << "\\\\"; break;
708 case '"': OS << "\\\""; break;
709 case '\n': OS << "\\n"; break;
710 case '\t': OS << "\\t"; break;
711 case '\a': OS << "\\a"; break;
712 case '\b': OS << "\\b"; break;
713 }
714 }
715 OS << '"';
Chris Lattner882f7882006-11-04 18:52:07 +0000716}
717void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
718 OS << "(";
719 PrintExpr(Node->getSubExpr());
Chris Lattnera076fde2007-05-31 18:21:33 +0000720 OS << ")";
Chris Lattner882f7882006-11-04 18:52:07 +0000721}
722void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattnere5b60442007-08-23 21:46:40 +0000723 if (!Node->isPostfix()) {
Chris Lattner15768702006-11-05 23:54:51 +0000724 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Mike Stump11289f42009-09-09 15:08:12 +0000725
Eli Friedman1cf25362009-06-14 22:39:26 +0000726 // Print a space if this is an "identifier operator" like __real, or if
727 // it might be concatenated incorrectly like '+'.
Chris Lattnere5b60442007-08-23 21:46:40 +0000728 switch (Node->getOpcode()) {
729 default: break;
John McCalle3027922010-08-25 11:45:40 +0000730 case UO_Real:
731 case UO_Imag:
732 case UO_Extension:
Chris Lattnere5b60442007-08-23 21:46:40 +0000733 OS << ' ';
734 break;
John McCalle3027922010-08-25 11:45:40 +0000735 case UO_Plus:
736 case UO_Minus:
Eli Friedman1cf25362009-06-14 22:39:26 +0000737 if (isa<UnaryOperator>(Node->getSubExpr()))
738 OS << ' ';
739 break;
Chris Lattnere5b60442007-08-23 21:46:40 +0000740 }
741 }
Chris Lattner882f7882006-11-04 18:52:07 +0000742 PrintExpr(Node->getSubExpr());
Mike Stump11289f42009-09-09 15:08:12 +0000743
Chris Lattner15768702006-11-05 23:54:51 +0000744 if (Node->isPostfix())
745 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattner882f7882006-11-04 18:52:07 +0000746}
Chris Lattner98dbf0a2007-08-30 17:59:59 +0000747
Douglas Gregor882211c2010-04-28 22:16:22 +0000748void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
749 OS << "__builtin_offsetof(";
Daniel Dunbar219fa692010-06-30 19:16:48 +0000750 OS << Node->getTypeSourceInfo()->getType().getAsString(Policy) << ", ";
Douglas Gregor882211c2010-04-28 22:16:22 +0000751 bool PrintedSomething = false;
752 for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
753 OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
754 if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
755 // Array node
756 OS << "[";
757 PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
758 OS << "]";
759 PrintedSomething = true;
760 continue;
761 }
Douglas Gregord1702062010-04-29 00:18:15 +0000762
763 // Skip implicit base indirections.
764 if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
765 continue;
766
Douglas Gregor882211c2010-04-28 22:16:22 +0000767 // Field or identifier node.
768 IdentifierInfo *Id = ON.getFieldName();
769 if (!Id)
770 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000771
Douglas Gregor882211c2010-04-28 22:16:22 +0000772 if (PrintedSomething)
773 OS << ".";
774 else
775 PrintedSomething = true;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000776 OS << Id->getName();
Douglas Gregor882211c2010-04-28 22:16:22 +0000777 }
778 OS << ")";
779}
780
Peter Collingbournee190dee2011-03-11 19:24:49 +0000781void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
782 switch(Node->getKind()) {
783 case UETT_SizeOf:
784 OS << "sizeof";
785 break;
786 case UETT_AlignOf:
787 OS << "__alignof";
788 break;
789 case UETT_VecStep:
790 OS << "vec_step";
791 break;
792 }
Sebastian Redl6f282892008-11-11 17:56:53 +0000793 if (Node->isArgumentType())
Daniel Dunbar219fa692010-06-30 19:16:48 +0000794 OS << "(" << Node->getArgumentType().getAsString(Policy) << ")";
Sebastian Redl6f282892008-11-11 17:56:53 +0000795 else {
796 OS << " ";
797 PrintExpr(Node->getArgumentExpr());
798 }
Chris Lattner882f7882006-11-04 18:52:07 +0000799}
Peter Collingbourne91147592011-04-15 00:35:48 +0000800
801void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
802 OS << "_Generic(";
803 PrintExpr(Node->getControllingExpr());
804 for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
805 OS << ", ";
806 QualType T = Node->getAssocType(i);
807 if (T.isNull())
808 OS << "default";
809 else
810 OS << T.getAsString(Policy);
811 OS << ": ";
812 PrintExpr(Node->getAssocExpr(i));
813 }
814 OS << ")";
815}
816
Chris Lattner882f7882006-11-04 18:52:07 +0000817void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
Ted Kremenekc81614d2007-08-20 16:18:38 +0000818 PrintExpr(Node->getLHS());
Chris Lattner882f7882006-11-04 18:52:07 +0000819 OS << "[";
Ted Kremenekc81614d2007-08-20 16:18:38 +0000820 PrintExpr(Node->getRHS());
Chris Lattner882f7882006-11-04 18:52:07 +0000821 OS << "]";
822}
823
Peter Collingbourne4b279a02011-02-08 21:17:54 +0000824void StmtPrinter::PrintCallArgs(CallExpr *Call) {
Chris Lattner882f7882006-11-04 18:52:07 +0000825 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000826 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
827 // Don't print any defaulted arguments
828 break;
829 }
830
Chris Lattner882f7882006-11-04 18:52:07 +0000831 if (i) OS << ", ";
832 PrintExpr(Call->getArg(i));
833 }
Peter Collingbourne4b279a02011-02-08 21:17:54 +0000834}
835
836void StmtPrinter::VisitCallExpr(CallExpr *Call) {
837 PrintExpr(Call->getCallee());
838 OS << "(";
839 PrintCallArgs(Call);
Chris Lattner882f7882006-11-04 18:52:07 +0000840 OS << ")";
841}
842void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
Douglas Gregore4b414c2009-01-08 22:45:41 +0000843 // FIXME: Suppress printing implicit bases (like "this")
844 PrintExpr(Node->getBase());
Fariborz Jahanian2990c022010-01-11 21:17:32 +0000845 if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
846 if (FD->isAnonymousStructOrUnion())
847 return;
Douglas Gregore4b414c2009-01-08 22:45:41 +0000848 OS << (Node->isArrow() ? "->" : ".");
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000849 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
850 Qualifier->print(OS, Policy);
851
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000852 OS << Node->getMemberNameInfo();
Mike Stump11289f42009-09-09 15:08:12 +0000853
John McCallb3774b52010-08-19 23:49:38 +0000854 if (Node->hasExplicitTemplateArgs())
Douglas Gregor84f14dd2009-09-01 00:37:14 +0000855 OS << TemplateSpecializationType::PrintTemplateArgumentList(
856 Node->getTemplateArgs(),
857 Node->getNumTemplateArgs(),
858 Policy);
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000859}
Steve Naroffe87026a2009-07-24 17:54:45 +0000860void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
861 PrintExpr(Node->getBase());
862 OS << (Node->isArrow() ? "->isa" : ".isa");
863}
864
Nate Begemance4d7fc2008-04-18 23:10:10 +0000865void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Steve Narofff7a5da12007-07-28 23:10:27 +0000866 PrintExpr(Node->getBase());
867 OS << ".";
868 OS << Node->getAccessor().getName();
869}
Douglas Gregorf19b2312008-10-28 15:36:24 +0000870void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
Fariborz Jahaniane33c1162010-06-30 16:31:08 +0000871 OS << "(" << Node->getType().getAsString(Policy) << ")";
Chris Lattner882f7882006-11-04 18:52:07 +0000872 PrintExpr(Node->getSubExpr());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000873}
Steve Naroff57eb2c52007-07-19 21:32:11 +0000874void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
Daniel Dunbar219fa692010-06-30 19:16:48 +0000875 OS << "(" << Node->getType().getAsString(Policy) << ")";
Steve Naroff57eb2c52007-07-19 21:32:11 +0000876 PrintExpr(Node->getInitializer());
877}
Steve Naroff7a5af782007-07-13 16:58:59 +0000878void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000879 // No need to print anything, simply forward to the sub expression.
880 PrintExpr(Node->getSubExpr());
Steve Naroff7a5af782007-07-13 16:58:59 +0000881}
Chris Lattner882f7882006-11-04 18:52:07 +0000882void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
883 PrintExpr(Node->getLHS());
884 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
885 PrintExpr(Node->getRHS());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000886}
Chris Lattner86928112007-08-25 02:00:02 +0000887void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
888 PrintExpr(Node->getLHS());
889 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
890 PrintExpr(Node->getRHS());
891}
Chris Lattner882f7882006-11-04 18:52:07 +0000892void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
893 PrintExpr(Node->getCond());
John McCallc07a0c72011-02-17 10:25:35 +0000894 OS << " ? ";
895 PrintExpr(Node->getLHS());
896 OS << " : ";
Chris Lattner882f7882006-11-04 18:52:07 +0000897 PrintExpr(Node->getRHS());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000898}
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000899
Chris Lattnereefa10e2007-05-28 06:56:27 +0000900// GNU extensions.
901
John McCallc07a0c72011-02-17 10:25:35 +0000902void
903StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
904 PrintExpr(Node->getCommon());
905 OS << " ?: ";
906 PrintExpr(Node->getFalseExpr());
907}
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000908void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000909 OS << "&&" << Node->getLabel()->getName();
Chris Lattnereefa10e2007-05-28 06:56:27 +0000910}
911
Chris Lattner366727f2007-07-24 16:58:17 +0000912void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
913 OS << "(";
914 PrintRawCompoundStmt(E->getSubStmt());
915 OS << ")";
916}
917
Steve Naroff9efdabc2007-08-03 21:21:27 +0000918void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
919 OS << "__builtin_choose_expr(";
920 PrintExpr(Node->getCond());
Chris Lattner81a96882007-08-04 00:20:15 +0000921 OS << ", ";
Steve Naroff9efdabc2007-08-03 21:21:27 +0000922 PrintExpr(Node->getLHS());
Chris Lattner81a96882007-08-04 00:20:15 +0000923 OS << ", ";
Steve Naroff9efdabc2007-08-03 21:21:27 +0000924 PrintExpr(Node->getRHS());
925 OS << ")";
926}
Chris Lattner366727f2007-07-24 16:58:17 +0000927
Douglas Gregor3be4b122008-11-29 04:51:27 +0000928void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
929 OS << "__null";
930}
931
Eli Friedmana1b4ed82008-05-14 19:38:39 +0000932void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
933 OS << "__builtin_shufflevector(";
934 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
935 if (i) OS << ", ";
936 PrintExpr(Node->getExpr(i));
937 }
938 OS << ")";
939}
940
Anders Carlsson4692db02007-08-31 04:56:16 +0000941void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
Douglas Gregor36098ff2009-05-30 00:56:08 +0000942 if (Node->getSyntacticForm()) {
943 Visit(Node->getSyntacticForm());
944 return;
945 }
946
Anders Carlsson4692db02007-08-31 04:56:16 +0000947 OS << "{ ";
948 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
949 if (i) OS << ", ";
Douglas Gregor347f7ea2009-01-28 21:54:33 +0000950 if (Node->getInit(i))
951 PrintExpr(Node->getInit(i));
952 else
953 OS << "0";
Anders Carlsson4692db02007-08-31 04:56:16 +0000954 }
955 OS << " }";
956}
957
Nate Begeman5ec4b312009-08-10 23:49:36 +0000958void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
959 OS << "( ";
960 for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
961 if (i) OS << ", ";
962 PrintExpr(Node->getExpr(i));
963 }
964 OS << " )";
965}
966
Douglas Gregore4a0bb72009-01-22 00:58:24 +0000967void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
Douglas Gregor347f7ea2009-01-28 21:54:33 +0000968 for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
969 DEnd = Node->designators_end();
970 D != DEnd; ++D) {
971 if (D->isFieldDesignator()) {
972 if (D->getDotLoc().isInvalid())
973 OS << D->getFieldName()->getName() << ":";
974 else
975 OS << "." << D->getFieldName()->getName();
976 } else {
977 OS << "[";
978 if (D->isArrayDesignator()) {
979 PrintExpr(Node->getArrayIndex(*D));
980 } else {
981 PrintExpr(Node->getArrayRangeStart(*D));
982 OS << " ... ";
Mike Stump11289f42009-09-09 15:08:12 +0000983 PrintExpr(Node->getArrayRangeEnd(*D));
Douglas Gregor347f7ea2009-01-28 21:54:33 +0000984 }
985 OS << "]";
986 }
987 }
988
989 OS << " = ";
990 PrintExpr(Node->getInit());
Douglas Gregore4a0bb72009-01-22 00:58:24 +0000991}
992
Douglas Gregor0202cb42009-01-29 17:44:32 +0000993void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
Chris Lattnerc61089a2009-06-30 01:26:17 +0000994 if (Policy.LangOpts.CPlusPlus)
Douglas Gregor278f52e2009-05-30 00:08:05 +0000995 OS << "/*implicit*/" << Node->getType().getAsString(Policy) << "()";
996 else {
997 OS << "/*implicit*/(" << Node->getType().getAsString(Policy) << ")";
998 if (Node->getType()->isRecordType())
999 OS << "{}";
1000 else
1001 OS << 0;
1002 }
Douglas Gregor0202cb42009-01-29 17:44:32 +00001003}
1004
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001005void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
Eli Friedman79635842009-05-30 04:20:30 +00001006 OS << "__builtin_va_arg(";
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001007 PrintExpr(Node->getSubExpr());
1008 OS << ", ";
Daniel Dunbar219fa692010-06-30 19:16:48 +00001009 OS << Node->getType().getAsString(Policy);
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001010 OS << ")";
1011}
1012
Chris Lattnereefa10e2007-05-28 06:56:27 +00001013// C++
Douglas Gregor993603d2008-11-14 16:09:21 +00001014void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1015 const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1016 "",
1017#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1018 Spelling,
1019#include "clang/Basic/OperatorKinds.def"
1020 };
1021
1022 OverloadedOperatorKind Kind = Node->getOperator();
1023 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1024 if (Node->getNumArgs() == 1) {
1025 OS << OpStrings[Kind] << ' ';
1026 PrintExpr(Node->getArg(0));
1027 } else {
1028 PrintExpr(Node->getArg(0));
1029 OS << ' ' << OpStrings[Kind];
1030 }
1031 } else if (Kind == OO_Call) {
1032 PrintExpr(Node->getArg(0));
1033 OS << '(';
1034 for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1035 if (ArgIdx > 1)
1036 OS << ", ";
1037 if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1038 PrintExpr(Node->getArg(ArgIdx));
1039 }
1040 OS << ')';
1041 } else if (Kind == OO_Subscript) {
1042 PrintExpr(Node->getArg(0));
1043 OS << '[';
1044 PrintExpr(Node->getArg(1));
1045 OS << ']';
1046 } else if (Node->getNumArgs() == 1) {
1047 OS << OpStrings[Kind] << ' ';
1048 PrintExpr(Node->getArg(0));
1049 } else if (Node->getNumArgs() == 2) {
1050 PrintExpr(Node->getArg(0));
1051 OS << ' ' << OpStrings[Kind] << ' ';
1052 PrintExpr(Node->getArg(1));
1053 } else {
1054 assert(false && "unknown overloaded operator");
1055 }
1056}
Chris Lattnereefa10e2007-05-28 06:56:27 +00001057
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001058void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1059 VisitCallExpr(cast<CallExpr>(Node));
1060}
1061
Peter Collingbourne41f85462011-02-09 21:07:24 +00001062void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1063 PrintExpr(Node->getCallee());
1064 OS << "<<<";
1065 PrintCallArgs(Node->getConfig());
1066 OS << ">>>(";
1067 PrintCallArgs(Node);
1068 OS << ")";
1069}
1070
Douglas Gregore200adc2008-10-27 19:41:14 +00001071void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1072 OS << Node->getCastName() << '<';
Daniel Dunbar219fa692010-06-30 19:16:48 +00001073 OS << Node->getTypeAsWritten().getAsString(Policy) << ">(";
Chris Lattnereefa10e2007-05-28 06:56:27 +00001074 PrintExpr(Node->getSubExpr());
1075 OS << ")";
1076}
1077
Douglas Gregore200adc2008-10-27 19:41:14 +00001078void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1079 VisitCXXNamedCastExpr(Node);
1080}
1081
1082void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1083 VisitCXXNamedCastExpr(Node);
1084}
1085
1086void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1087 VisitCXXNamedCastExpr(Node);
1088}
1089
1090void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1091 VisitCXXNamedCastExpr(Node);
1092}
1093
Sebastian Redlc4704762008-11-11 11:37:55 +00001094void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1095 OS << "typeid(";
1096 if (Node->isTypeOperand()) {
Daniel Dunbar219fa692010-06-30 19:16:48 +00001097 OS << Node->getTypeOperand().getAsString(Policy);
Sebastian Redlc4704762008-11-11 11:37:55 +00001098 } else {
1099 PrintExpr(Node->getExprOperand());
1100 }
1101 OS << ")";
1102}
1103
Francois Pichet9f4f2072010-09-08 12:20:18 +00001104void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1105 OS << "__uuidof(";
1106 if (Node->isTypeOperand()) {
1107 OS << Node->getTypeOperand().getAsString(Policy);
1108 } else {
1109 PrintExpr(Node->getExprOperand());
1110 }
1111 OS << ")";
1112}
1113
Chris Lattnereefa10e2007-05-28 06:56:27 +00001114void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1115 OS << (Node->getValue() ? "true" : "false");
1116}
1117
Sebastian Redl576fd422009-05-10 18:38:11 +00001118void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1119 OS << "nullptr";
1120}
1121
Douglas Gregor97a9c812008-11-04 14:32:21 +00001122void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1123 OS << "this";
1124}
1125
Chris Lattnerb7e656b2008-02-26 00:51:44 +00001126void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1127 if (Node->getSubExpr() == 0)
1128 OS << "throw";
1129 else {
1130 OS << "throw ";
1131 PrintExpr(Node->getSubExpr());
1132 }
1133}
1134
Chris Lattneraa9c7ae2008-04-08 04:40:51 +00001135void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1136 // Nothing to print: we picked up the default argument
1137}
1138
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001139void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
Daniel Dunbar219fa692010-06-30 19:16:48 +00001140 OS << Node->getType().getAsString(Policy);
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001141 OS << "(";
1142 PrintExpr(Node->getSubExpr());
1143 OS << ")";
1144}
1145
Anders Carlsson993a4b32009-05-30 20:03:25 +00001146void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1147 PrintExpr(Node->getSubExpr());
1148}
1149
Douglas Gregordd04d332009-01-16 18:33:17 +00001150void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
Daniel Dunbar219fa692010-06-30 19:16:48 +00001151 OS << Node->getType().getAsString(Policy);
Douglas Gregordd04d332009-01-16 18:33:17 +00001152 OS << "(";
1153 for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump11289f42009-09-09 15:08:12 +00001154 ArgEnd = Node->arg_end();
Douglas Gregordd04d332009-01-16 18:33:17 +00001155 Arg != ArgEnd; ++Arg) {
1156 if (Arg != Node->arg_begin())
1157 OS << ", ";
1158 PrintExpr(*Arg);
1159 }
1160 OS << ")";
1161}
1162
Douglas Gregor747eb782010-07-08 06:14:04 +00001163void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00001164 if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
1165 OS << TSInfo->getType().getAsString(Policy) << "()";
1166 else
1167 OS << Node->getType().getAsString(Policy) << "()";
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001168}
1169
Sebastian Redlbd150f42008-11-21 19:14:01 +00001170void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1171 if (E->isGlobalNew())
1172 OS << "::";
1173 OS << "new ";
1174 unsigned NumPlace = E->getNumPlacementArgs();
1175 if (NumPlace > 0) {
1176 OS << "(";
1177 PrintExpr(E->getPlacementArg(0));
1178 for (unsigned i = 1; i < NumPlace; ++i) {
1179 OS << ", ";
1180 PrintExpr(E->getPlacementArg(i));
1181 }
1182 OS << ") ";
1183 }
1184 if (E->isParenTypeId())
1185 OS << "(";
Sebastian Redld6d55ee2008-12-02 22:08:59 +00001186 std::string TypeS;
1187 if (Expr *Size = E->getArraySize()) {
1188 llvm::raw_string_ostream s(TypeS);
Eli Friedmanc4fc8392009-05-30 05:32:46 +00001189 Size->printPretty(s, Context, Helper, Policy);
Sebastian Redld6d55ee2008-12-02 22:08:59 +00001190 s.flush();
1191 TypeS = "[" + TypeS + "]";
1192 }
Douglas Gregor7de59662009-05-29 20:38:28 +00001193 E->getAllocatedType().getAsStringInternal(TypeS, Policy);
Sebastian Redld6d55ee2008-12-02 22:08:59 +00001194 OS << TypeS;
Sebastian Redlbd150f42008-11-21 19:14:01 +00001195 if (E->isParenTypeId())
1196 OS << ")";
1197
1198 if (E->hasInitializer()) {
1199 OS << "(";
1200 unsigned NumCons = E->getNumConstructorArgs();
1201 if (NumCons > 0) {
1202 PrintExpr(E->getConstructorArg(0));
1203 for (unsigned i = 1; i < NumCons; ++i) {
1204 OS << ", ";
1205 PrintExpr(E->getConstructorArg(i));
1206 }
1207 }
1208 OS << ")";
1209 }
1210}
1211
1212void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1213 if (E->isGlobalDelete())
1214 OS << "::";
1215 OS << "delete ";
1216 if (E->isArrayForm())
1217 OS << "[] ";
1218 PrintExpr(E->getArgument());
1219}
1220
Douglas Gregorad8a3362009-09-04 17:36:40 +00001221void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1222 PrintExpr(E->getBase());
1223 if (E->isArrow())
1224 OS << "->";
1225 else
1226 OS << '.';
1227 if (E->getQualifier())
1228 E->getQualifier()->print(OS, Policy);
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregorad8a3362009-09-04 17:36:40 +00001230 std::string TypeS;
Douglas Gregor678f90d2010-02-25 01:56:36 +00001231 if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1232 OS << II->getName();
1233 else
1234 E->getDestroyedType().getAsStringInternal(TypeS, Policy);
Douglas Gregorad8a3362009-09-04 17:36:40 +00001235 OS << TypeS;
1236}
1237
Anders Carlsson0781ce72009-04-23 02:32:43 +00001238void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregorbaba85d2011-01-24 17:25:03 +00001239 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
1240 if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
1241 // Don't print any defaulted arguments
1242 break;
1243 }
1244
1245 if (i) OS << ", ";
1246 PrintExpr(E->getArg(i));
Fariborz Jahaniand0bbf662010-01-13 21:41:11 +00001247 }
Anders Carlsson0781ce72009-04-23 02:32:43 +00001248}
1249
John McCall5d413782010-12-06 08:20:24 +00001250void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
Anders Carlssondefc6442009-04-24 22:47:04 +00001251 // Just forward to the sub expression.
1252 PrintExpr(E->getSubExpr());
1253}
1254
Mike Stump11289f42009-09-09 15:08:12 +00001255void
Douglas Gregorce934142009-05-20 18:46:25 +00001256StmtPrinter::VisitCXXUnresolvedConstructExpr(
1257 CXXUnresolvedConstructExpr *Node) {
Daniel Dunbar219fa692010-06-30 19:16:48 +00001258 OS << Node->getTypeAsWritten().getAsString(Policy);
Douglas Gregorce934142009-05-20 18:46:25 +00001259 OS << "(";
1260 for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump11289f42009-09-09 15:08:12 +00001261 ArgEnd = Node->arg_end();
Douglas Gregorce934142009-05-20 18:46:25 +00001262 Arg != ArgEnd; ++Arg) {
1263 if (Arg != Node->arg_begin())
1264 OS << ", ";
1265 PrintExpr(*Arg);
1266 }
1267 OS << ")";
1268}
1269
John McCall8cd78132009-11-19 22:55:06 +00001270void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1271 CXXDependentScopeMemberExpr *Node) {
John McCall2d74de92009-12-01 22:10:20 +00001272 if (!Node->isImplicitAccess()) {
1273 PrintExpr(Node->getBase());
1274 OS << (Node->isArrow() ? "->" : ".");
1275 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001276 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1277 Qualifier->print(OS, Policy);
John McCall2d74de92009-12-01 22:10:20 +00001278 else if (Node->hasExplicitTemplateArgs())
Douglas Gregor308047d2009-09-09 00:23:06 +00001279 // FIXME: Track use of "template" keyword explicitly?
1280 OS << "template ";
Mike Stump11289f42009-09-09 15:08:12 +00001281
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001282 OS << Node->getMemberNameInfo();
Mike Stump11289f42009-09-09 15:08:12 +00001283
John McCall2d74de92009-12-01 22:10:20 +00001284 if (Node->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001285 OS << TemplateSpecializationType::PrintTemplateArgumentList(
1286 Node->getTemplateArgs(),
1287 Node->getNumTemplateArgs(),
1288 Policy);
1289 }
Douglas Gregora8db9542009-05-22 21:13:27 +00001290}
1291
John McCall10eae182009-11-30 22:42:35 +00001292void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
John McCall2d74de92009-12-01 22:10:20 +00001293 if (!Node->isImplicitAccess()) {
1294 PrintExpr(Node->getBase());
1295 OS << (Node->isArrow() ? "->" : ".");
1296 }
John McCall10eae182009-11-30 22:42:35 +00001297 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1298 Qualifier->print(OS, Policy);
1299
1300 // FIXME: this might originally have been written with 'template'
1301
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001302 OS << Node->getMemberNameInfo();
John McCall10eae182009-11-30 22:42:35 +00001303
1304 if (Node->hasExplicitTemplateArgs()) {
1305 OS << TemplateSpecializationType::PrintTemplateArgumentList(
1306 Node->getTemplateArgs(),
1307 Node->getNumTemplateArgs(),
1308 Policy);
1309 }
1310}
1311
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001312static const char *getTypeTraitName(UnaryTypeTrait UTT) {
1313 switch (UTT) {
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001314 case UTT_HasNothrowAssign: return "__has_nothrow_assign";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001315 case UTT_HasNothrowConstructor: return "__has_nothrow_constructor";
John Wiegley65497cc2011-04-27 23:09:49 +00001316 case UTT_HasNothrowCopy: return "__has_nothrow_copy";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001317 case UTT_HasTrivialAssign: return "__has_trivial_assign";
Alexis Huntf479f1b2011-05-09 18:22:59 +00001318 case UTT_HasTrivialDefaultConstructor: return "__has_trivial_constructor";
John Wiegley65497cc2011-04-27 23:09:49 +00001319 case UTT_HasTrivialCopy: return "__has_trivial_copy";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001320 case UTT_HasTrivialDestructor: return "__has_trivial_destructor";
1321 case UTT_HasVirtualDestructor: return "__has_virtual_destructor";
1322 case UTT_IsAbstract: return "__is_abstract";
John Wiegley65497cc2011-04-27 23:09:49 +00001323 case UTT_IsArithmetic: return "__is_arithmetic";
1324 case UTT_IsArray: return "__is_array";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001325 case UTT_IsClass: return "__is_class";
John Wiegley65497cc2011-04-27 23:09:49 +00001326 case UTT_IsCompleteType: return "__is_complete_type";
1327 case UTT_IsCompound: return "__is_compound";
1328 case UTT_IsConst: return "__is_const";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001329 case UTT_IsEmpty: return "__is_empty";
1330 case UTT_IsEnum: return "__is_enum";
John Wiegley65497cc2011-04-27 23:09:49 +00001331 case UTT_IsFloatingPoint: return "__is_floating_point";
1332 case UTT_IsFunction: return "__is_function";
1333 case UTT_IsFundamental: return "__is_fundamental";
1334 case UTT_IsIntegral: return "__is_integral";
Chandler Carruth8e2d6f42011-05-01 07:23:20 +00001335 case UTT_IsLiteral: return "__is_literal";
John Wiegley65497cc2011-04-27 23:09:49 +00001336 case UTT_IsLvalueReference: return "__is_lvalue_reference";
1337 case UTT_IsMemberFunctionPointer: return "__is_member_function_pointer";
1338 case UTT_IsMemberObjectPointer: return "__is_member_object_pointer";
1339 case UTT_IsMemberPointer: return "__is_member_pointer";
1340 case UTT_IsObject: return "__is_object";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001341 case UTT_IsPOD: return "__is_pod";
John Wiegley65497cc2011-04-27 23:09:49 +00001342 case UTT_IsPointer: return "__is_pointer";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001343 case UTT_IsPolymorphic: return "__is_polymorphic";
John Wiegley65497cc2011-04-27 23:09:49 +00001344 case UTT_IsReference: return "__is_reference";
John Wiegley65497cc2011-04-27 23:09:49 +00001345 case UTT_IsRvalueReference: return "__is_rvalue_reference";
1346 case UTT_IsScalar: return "__is_scalar";
1347 case UTT_IsSigned: return "__is_signed";
1348 case UTT_IsStandardLayout: return "__is_standard_layout";
1349 case UTT_IsTrivial: return "__is_trivial";
Alexis Huntd9a5cc12011-05-13 00:31:07 +00001350 case UTT_IsTriviallyCopyable: return "__is_trivially_copyable";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001351 case UTT_IsUnion: return "__is_union";
John Wiegley65497cc2011-04-27 23:09:49 +00001352 case UTT_IsUnsigned: return "__is_unsigned";
1353 case UTT_IsVoid: return "__is_void";
1354 case UTT_IsVolatile: return "__is_volatile";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001355 }
Chandler Carruth8e2d6f42011-05-01 07:23:20 +00001356 llvm_unreachable("Type trait not covered by switch statement");
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001357}
1358
1359static const char *getTypeTraitName(BinaryTypeTrait BTT) {
1360 switch (BTT) {
Francois Pichet34b21132010-12-08 22:35:30 +00001361 case BTT_IsBaseOf: return "__is_base_of";
John Wiegley65497cc2011-04-27 23:09:49 +00001362 case BTT_IsConvertible: return "__is_convertible";
1363 case BTT_IsSame: return "__is_same";
Francois Pichet34b21132010-12-08 22:35:30 +00001364 case BTT_TypeCompatible: return "__builtin_types_compatible_p";
Douglas Gregor8006e762011-01-27 20:28:01 +00001365 case BTT_IsConvertibleTo: return "__is_convertible_to";
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001366 }
Chandler Carruthe46eaf32011-05-01 07:23:23 +00001367 llvm_unreachable("Binary type trait not covered by switch");
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001368}
1369
John Wiegley6242b6a2011-04-28 00:16:57 +00001370static const char *getTypeTraitName(ArrayTypeTrait ATT) {
1371 switch (ATT) {
1372 case ATT_ArrayRank: return "__array_rank";
1373 case ATT_ArrayExtent: return "__array_extent";
1374 }
Chandler Carruthe46eaf32011-05-01 07:23:23 +00001375 llvm_unreachable("Array type trait not covered by switch");
John Wiegley6242b6a2011-04-28 00:16:57 +00001376}
1377
John Wiegleyf9f65842011-04-25 06:54:41 +00001378static const char *getExpressionTraitName(ExpressionTrait ET) {
1379 switch (ET) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001380 case ET_IsLValueExpr: return "__is_lvalue_expr";
1381 case ET_IsRValueExpr: return "__is_rvalue_expr";
1382 }
Chandler Carruthe46eaf32011-05-01 07:23:23 +00001383 llvm_unreachable("Expression type trait not covered by switch");
John Wiegleyf9f65842011-04-25 06:54:41 +00001384}
1385
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001386void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
1387 OS << getTypeTraitName(E->getTrait()) << "("
Daniel Dunbar219fa692010-06-30 19:16:48 +00001388 << E->getQueriedType().getAsString(Policy) << ")";
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001389}
1390
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001391void StmtPrinter::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
1392 OS << getTypeTraitName(E->getTrait()) << "("
1393 << E->getLhsType().getAsString(Policy) << ","
1394 << E->getRhsType().getAsString(Policy) << ")";
1395}
1396
John Wiegley6242b6a2011-04-28 00:16:57 +00001397void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1398 OS << getTypeTraitName(E->getTrait()) << "("
1399 << E->getQueriedType().getAsString(Policy) << ")";
1400}
1401
John Wiegleyf9f65842011-04-25 06:54:41 +00001402void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1403 OS << getExpressionTraitName(E->getTrait()) << "(";
1404 PrintExpr(E->getQueriedExpression());
1405 OS << ")";
1406}
1407
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001408void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1409 OS << "noexcept(";
1410 PrintExpr(E->getOperand());
1411 OS << ")";
1412}
1413
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001414void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001415 PrintExpr(E->getPattern());
1416 OS << "...";
1417}
1418
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001419void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1420 OS << "sizeof...(" << E->getPack()->getNameAsString() << ")";
1421}
1422
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001423void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
1424 SubstNonTypeTemplateParmPackExpr *Node) {
1425 OS << Node->getParameterPack()->getNameAsString();
1426}
1427
John McCall7c454bb2011-07-15 05:09:51 +00001428void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
1429 SubstNonTypeTemplateParmExpr *Node) {
1430 Visit(Node->getReplacement());
1431}
1432
Douglas Gregorfe314812011-06-21 17:03:29 +00001433void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
1434 PrintExpr(Node->GetTemporaryExpr());
1435}
1436
Mike Stump11289f42009-09-09 15:08:12 +00001437// Obj-C
Anders Carlsson76f4a902007-08-21 17:43:55 +00001438
1439void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1440 OS << "@";
1441 VisitStringLiteral(Node->getString());
1442}
Chris Lattnereefa10e2007-05-28 06:56:27 +00001443
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001444void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Daniel Dunbar219fa692010-06-30 19:16:48 +00001445 OS << "@encode(" << Node->getEncodedType().getAsString(Policy) << ')';
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001446}
1447
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001448void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
Chris Lattner1cbaacc2008-11-24 04:00:27 +00001449 OS << "@selector(" << Node->getSelector().getAsString() << ')';
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001450}
1451
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001452void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001453 OS << "@protocol(" << Node->getProtocol() << ')';
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001454}
1455
Steve Naroffd54978b2007-09-18 23:55:05 +00001456void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1457 OS << "[";
Douglas Gregor9a129192010-04-21 00:45:42 +00001458 switch (Mess->getReceiverKind()) {
1459 case ObjCMessageExpr::Instance:
1460 PrintExpr(Mess->getInstanceReceiver());
1461 break;
1462
1463 case ObjCMessageExpr::Class:
1464 OS << Mess->getClassReceiver().getAsString(Policy);
1465 break;
1466
1467 case ObjCMessageExpr::SuperInstance:
1468 case ObjCMessageExpr::SuperClass:
1469 OS << "Super";
1470 break;
1471 }
1472
Ted Kremeneka06e7122008-05-02 17:32:38 +00001473 OS << ' ';
Ted Kremenekb65a67d2008-04-16 04:30:16 +00001474 Selector selector = Mess->getSelector();
Steve Naroffc6814ea2007-10-02 20:01:56 +00001475 if (selector.isUnarySelector()) {
Douglas Gregoraf2a6ae2011-02-18 22:29:55 +00001476 OS << selector.getNameForSlot(0);
Steve Naroffc6814ea2007-10-02 20:01:56 +00001477 } else {
1478 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
Ted Kremeneka06e7122008-05-02 17:32:38 +00001479 if (i < selector.getNumArgs()) {
1480 if (i > 0) OS << ' ';
1481 if (selector.getIdentifierInfoForSlot(i))
Chris Lattner1cbaacc2008-11-24 04:00:27 +00001482 OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
Ted Kremeneka06e7122008-05-02 17:32:38 +00001483 else
1484 OS << ":";
1485 }
1486 else OS << ", "; // Handle variadic methods.
Mike Stump11289f42009-09-09 15:08:12 +00001487
Steve Naroffc6814ea2007-10-02 20:01:56 +00001488 PrintExpr(Mess->getArg(i));
1489 }
Steve Naroffd54978b2007-09-18 23:55:05 +00001490 }
1491 OS << "]";
1492}
1493
John McCall31168b02011-06-15 23:02:42 +00001494void
1495StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1496 PrintExpr(E->getSubExpr());
1497}
1498
1499void
1500StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1501 OS << "(" << E->getBridgeKindName() << E->getType().getAsString(Policy)
1502 << ")";
1503 PrintExpr(E->getSubExpr());
1504}
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001505
Steve Naroffc540d662008-09-03 18:15:37 +00001506void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
Steve Naroff415d3d52008-10-08 17:01:13 +00001507 BlockDecl *BD = Node->getBlockDecl();
Steve Naroffc540d662008-09-03 18:15:37 +00001508 OS << "^";
Mike Stump11289f42009-09-09 15:08:12 +00001509
Steve Naroffc540d662008-09-03 18:15:37 +00001510 const FunctionType *AFT = Node->getFunctionType();
Mike Stump11289f42009-09-09 15:08:12 +00001511
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001512 if (isa<FunctionNoProtoType>(AFT)) {
Steve Naroffc540d662008-09-03 18:15:37 +00001513 OS << "()";
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001514 } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
Steve Naroffc540d662008-09-03 18:15:37 +00001515 OS << '(';
1516 std::string ParamStr;
Steve Naroff415d3d52008-10-08 17:01:13 +00001517 for (BlockDecl::param_iterator AI = BD->param_begin(),
1518 E = BD->param_end(); AI != E; ++AI) {
1519 if (AI != BD->param_begin()) OS << ", ";
Chris Lattner1cbaacc2008-11-24 04:00:27 +00001520 ParamStr = (*AI)->getNameAsString();
Douglas Gregor7de59662009-05-29 20:38:28 +00001521 (*AI)->getType().getAsStringInternal(ParamStr, Policy);
Steve Naroffc540d662008-09-03 18:15:37 +00001522 OS << ParamStr;
1523 }
Mike Stump11289f42009-09-09 15:08:12 +00001524
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001525 const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
Steve Naroffc540d662008-09-03 18:15:37 +00001526 if (FT->isVariadic()) {
Steve Naroff415d3d52008-10-08 17:01:13 +00001527 if (!BD->param_empty()) OS << ", ";
Steve Naroffc540d662008-09-03 18:15:37 +00001528 OS << "...";
1529 }
1530 OS << ')';
1531 }
1532}
1533
Steve Naroffc540d662008-09-03 18:15:37 +00001534void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) {
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001535 OS << Node->getDecl();
Steve Naroffc540d662008-09-03 18:15:37 +00001536}
John McCall8d69a212010-11-15 23:31:06 +00001537
1538void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {}
1539
Tanya Lattner55808c12011-06-04 00:47:47 +00001540void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
1541 OS << "__builtin_astype(";
1542 PrintExpr(Node->getSrcExpr());
1543 OS << ", " << Node->getType().getAsString();
1544 OS << ")";
1545}
1546
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001547//===----------------------------------------------------------------------===//
1548// Stmt method implementations
1549//===----------------------------------------------------------------------===//
1550
Eli Friedmanef334fd2009-05-30 05:03:24 +00001551void Stmt::dumpPretty(ASTContext& Context) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00001552 printPretty(llvm::errs(), Context, 0,
Chris Lattnerc61089a2009-06-30 01:26:17 +00001553 PrintingPolicy(Context.getLangOptions()));
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001554}
1555
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001556void Stmt::printPretty(raw_ostream &OS, ASTContext& Context,
Eli Friedmanef334fd2009-05-30 05:03:24 +00001557 PrinterHelper* Helper,
Douglas Gregor7de59662009-05-29 20:38:28 +00001558 const PrintingPolicy &Policy,
1559 unsigned Indentation) const {
Chris Lattner882f7882006-11-04 18:52:07 +00001560 if (this == 0) {
1561 OS << "<NULL>";
1562 return;
1563 }
1564
Douglas Gregor8655e882009-10-16 22:46:09 +00001565 if (Policy.Dump && &Context) {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00001566 dump(OS, Context.getSourceManager());
Douglas Gregor278f52e2009-05-30 00:08:05 +00001567 return;
1568 }
Mike Stump11289f42009-09-09 15:08:12 +00001569
Eli Friedmanef334fd2009-05-30 05:03:24 +00001570 StmtPrinter P(OS, Context, Helper, Policy, Indentation);
Chris Lattner62249a62007-08-21 04:04:25 +00001571 P.Visit(const_cast<Stmt*>(this));
Chris Lattnera3bcb7a2006-11-04 07:16:25 +00001572}
Ted Kremenek04f3cee2007-08-31 21:30:12 +00001573
1574//===----------------------------------------------------------------------===//
1575// PrinterHelper
1576//===----------------------------------------------------------------------===//
1577
1578// Implement virtual destructor.
Gabor Greif412af032007-09-11 15:32:40 +00001579PrinterHelper::~PrinterHelper() {}