blob: a6f2b823fe6d4b769e3d385de036ab68da0c48c4 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-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 Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner95578782007-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 Lattner4b009652007-07-25 00:24:17 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "clang/AST/StmtVisitor.h"
Douglas Gregor566782a2009-01-06 05:10:23 +000016#include "clang/AST/DeclCXX.h"
Ted Kremenek10364dd2007-10-17 18:36:42 +000017#include "clang/AST/DeclObjC.h"
Ted Kremenek08176a52007-08-31 21:30:12 +000018#include "clang/AST/PrettyPrinter.h"
Chris Lattner4b009652007-07-25 00:24:17 +000019#include "llvm/Support/Compiler.h"
Ted Kremenek7b6f67b2008-09-13 05:16:45 +000020#include "llvm/Support/Format.h"
Chris Lattner4b009652007-07-25 00:24:17 +000021using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// StmtPrinter Visitor
25//===----------------------------------------------------------------------===//
26
27namespace {
Chris Lattner7ba21fa2007-08-21 04:04:25 +000028 class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
Ted Kremenek7b6f67b2008-09-13 05:16:45 +000029 llvm::raw_ostream &OS;
Eli Friedman4bdae722009-05-30 05:03:24 +000030 ASTContext &Context;
Chris Lattner4b009652007-07-25 00:24:17 +000031 unsigned IndentLevel;
Ted Kremenek08176a52007-08-31 21:30:12 +000032 clang::PrinterHelper* Helper;
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +000033 PrintingPolicy Policy;
34
Chris Lattner4b009652007-07-25 00:24:17 +000035 public:
Mike Stump25cf7602009-09-09 15:08:12 +000036 StmtPrinter(llvm::raw_ostream &os, ASTContext &C, PrinterHelper* helper,
Chris Lattner7099c782009-06-30 01:26:17 +000037 const PrintingPolicy &Policy,
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +000038 unsigned Indentation = 0)
Eli Friedman4bdae722009-05-30 05:03:24 +000039 : OS(os), Context(C), IndentLevel(Indentation), Helper(helper),
40 Policy(Policy) {}
Mike Stump25cf7602009-09-09 15:08:12 +000041
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +000042 void PrintStmt(Stmt *S) {
43 PrintStmt(S, Policy.Indentation);
44 }
45
46 void PrintStmt(Stmt *S, int SubIndent) {
Chris Lattner4b009652007-07-25 00:24:17 +000047 IndentLevel += SubIndent;
48 if (S && isa<Expr>(S)) {
49 // If this is an expr used in a stmt context, indent and newline it.
50 Indent();
Chris Lattner7ba21fa2007-08-21 04:04:25 +000051 Visit(S);
Chris Lattner4b009652007-07-25 00:24:17 +000052 OS << ";\n";
53 } else if (S) {
Chris Lattner7ba21fa2007-08-21 04:04:25 +000054 Visit(S);
Chris Lattner4b009652007-07-25 00:24:17 +000055 } else {
56 Indent() << "<<<NULL STATEMENT>>>\n";
57 }
58 IndentLevel -= SubIndent;
59 }
Eli Friedmane66ecf52009-05-30 00:19:54 +000060
Chris Lattner4b009652007-07-25 00:24:17 +000061 void PrintRawCompoundStmt(CompoundStmt *S);
62 void PrintRawDecl(Decl *D);
Ted Kremenek388b2842008-10-06 18:39:36 +000063 void PrintRawDeclStmt(DeclStmt *S);
Chris Lattner4b009652007-07-25 00:24:17 +000064 void PrintRawIfStmt(IfStmt *If);
Sebastian Redl237116b2008-12-22 21:35:02 +000065 void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
Mike Stump25cf7602009-09-09 15:08:12 +000066
Chris Lattner4b009652007-07-25 00:24:17 +000067 void PrintExpr(Expr *E) {
68 if (E)
Chris Lattner7ba21fa2007-08-21 04:04:25 +000069 Visit(E);
Chris Lattner4b009652007-07-25 00:24:17 +000070 else
71 OS << "<null expr>";
72 }
Mike Stump25cf7602009-09-09 15:08:12 +000073
Mike Stumpc43f4fc2009-02-10 20:16:46 +000074 llvm::raw_ostream &Indent(int Delta = 0) {
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +000075 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
76 OS << " ";
Chris Lattner4b009652007-07-25 00:24:17 +000077 return OS;
78 }
Mike Stump25cf7602009-09-09 15:08:12 +000079
Chris Lattner2af6a802007-08-30 17:59:59 +000080 bool PrintOffsetOfDesignator(Expr *E);
81 void VisitUnaryOffsetOf(UnaryOperator *Node);
Mike Stump25cf7602009-09-09 15:08:12 +000082
83 void Visit(Stmt* S) {
Ted Kremenek08176a52007-08-31 21:30:12 +000084 if (Helper && Helper->handledStmt(S,OS))
85 return;
86 else StmtVisitor<StmtPrinter>::Visit(S);
87 }
Mike Stump25cf7602009-09-09 15:08:12 +000088
Chris Lattner7ba21fa2007-08-21 04:04:25 +000089 void VisitStmt(Stmt *Node);
Douglas Gregor19330152008-11-14 12:46:07 +000090#define STMT(CLASS, PARENT) \
Chris Lattner7ba21fa2007-08-21 04:04:25 +000091 void Visit##CLASS(CLASS *Node);
Chris Lattner4b009652007-07-25 00:24:17 +000092#include "clang/AST/StmtNodes.def"
93 };
94}
95
96//===----------------------------------------------------------------------===//
97// Stmt printing methods.
98//===----------------------------------------------------------------------===//
99
100void StmtPrinter::VisitStmt(Stmt *Node) {
101 Indent() << "<<unknown stmt type>>\n";
102}
103
104/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
105/// with no newline after the }.
106void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
107 OS << "{\n";
108 for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
109 I != E; ++I)
110 PrintStmt(*I);
Mike Stump25cf7602009-09-09 15:08:12 +0000111
Chris Lattner4b009652007-07-25 00:24:17 +0000112 Indent() << "}";
113}
114
115void StmtPrinter::PrintRawDecl(Decl *D) {
Argiris Kirtzidis9a6fb962009-06-30 02:35:04 +0000116 D->print(OS, Policy, IndentLevel);
Mike Stumpc43f4fc2009-02-10 20:16:46 +0000117}
118
Ted Kremenek388b2842008-10-06 18:39:36 +0000119void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) {
Eli Friedmane66ecf52009-05-30 00:19:54 +0000120 DeclStmt::decl_iterator Begin = S->decl_begin(), End = S->decl_end();
Eli Friedmand73364a2009-05-30 04:20:30 +0000121 llvm::SmallVector<Decl*, 2> Decls;
Mike Stump25cf7602009-09-09 15:08:12 +0000122 for ( ; Begin != End; ++Begin)
Eli Friedmand73364a2009-05-30 04:20:30 +0000123 Decls.push_back(*Begin);
Eli Friedmane66ecf52009-05-30 00:19:54 +0000124
Argiris Kirtzidis9a6fb962009-06-30 02:35:04 +0000125 Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
Ted Kremenek388b2842008-10-06 18:39:36 +0000126}
Chris Lattner4b009652007-07-25 00:24:17 +0000127
128void StmtPrinter::VisitNullStmt(NullStmt *Node) {
129 Indent() << ";\n";
130}
131
132void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
Eli Friedmane66ecf52009-05-30 00:19:54 +0000133 Indent();
134 PrintRawDeclStmt(Node);
135 OS << ";\n";
Chris Lattner4b009652007-07-25 00:24:17 +0000136}
137
138void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
139 Indent();
140 PrintRawCompoundStmt(Node);
141 OS << "\n";
142}
143
144void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
145 Indent(-1) << "case ";
146 PrintExpr(Node->getLHS());
147 if (Node->getRHS()) {
148 OS << " ... ";
149 PrintExpr(Node->getRHS());
150 }
151 OS << ":\n";
Mike Stump25cf7602009-09-09 15:08:12 +0000152
Chris Lattner4b009652007-07-25 00:24:17 +0000153 PrintStmt(Node->getSubStmt(), 0);
154}
155
156void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
157 Indent(-1) << "default:\n";
158 PrintStmt(Node->getSubStmt(), 0);
159}
160
161void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
162 Indent(-1) << Node->getName() << ":\n";
163 PrintStmt(Node->getSubStmt(), 0);
164}
165
166void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
Sebastian Redlfd835a22009-02-07 20:05:48 +0000167 OS << "if (";
Chris Lattner4b009652007-07-25 00:24:17 +0000168 PrintExpr(If->getCond());
Sebastian Redlfd835a22009-02-07 20:05:48 +0000169 OS << ')';
Mike Stump25cf7602009-09-09 15:08:12 +0000170
Chris Lattner4b009652007-07-25 00:24:17 +0000171 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
172 OS << ' ';
173 PrintRawCompoundStmt(CS);
174 OS << (If->getElse() ? ' ' : '\n');
175 } else {
176 OS << '\n';
177 PrintStmt(If->getThen());
178 if (If->getElse()) Indent();
179 }
Mike Stump25cf7602009-09-09 15:08:12 +0000180
Chris Lattner4b009652007-07-25 00:24:17 +0000181 if (Stmt *Else = If->getElse()) {
182 OS << "else";
Mike Stump25cf7602009-09-09 15:08:12 +0000183
Chris Lattner4b009652007-07-25 00:24:17 +0000184 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
185 OS << ' ';
186 PrintRawCompoundStmt(CS);
187 OS << '\n';
188 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
189 OS << ' ';
190 PrintRawIfStmt(ElseIf);
191 } else {
192 OS << '\n';
193 PrintStmt(If->getElse());
194 }
195 }
196}
197
198void StmtPrinter::VisitIfStmt(IfStmt *If) {
199 Indent();
200 PrintRawIfStmt(If);
201}
202
203void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
204 Indent() << "switch (";
205 PrintExpr(Node->getCond());
206 OS << ")";
Mike Stump25cf7602009-09-09 15:08:12 +0000207
Chris Lattner4b009652007-07-25 00:24:17 +0000208 // Pretty print compoundstmt bodies (very common).
209 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
210 OS << " ";
211 PrintRawCompoundStmt(CS);
212 OS << "\n";
213 } else {
214 OS << "\n";
215 PrintStmt(Node->getBody());
216 }
217}
218
219void StmtPrinter::VisitSwitchCase(SwitchCase*) {
220 assert(0 && "SwitchCase is an abstract class");
221}
222
223void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
224 Indent() << "while (";
225 PrintExpr(Node->getCond());
226 OS << ")\n";
227 PrintStmt(Node->getBody());
228}
229
230void StmtPrinter::VisitDoStmt(DoStmt *Node) {
Chris Lattnercfe0ff02007-09-15 21:49:37 +0000231 Indent() << "do ";
232 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
233 PrintRawCompoundStmt(CS);
234 OS << " ";
235 } else {
236 OS << "\n";
237 PrintStmt(Node->getBody());
238 Indent();
239 }
Mike Stump25cf7602009-09-09 15:08:12 +0000240
Eli Friedmanea6a2622009-05-17 01:05:34 +0000241 OS << "while (";
Chris Lattner4b009652007-07-25 00:24:17 +0000242 PrintExpr(Node->getCond());
Eli Friedmanea6a2622009-05-17 01:05:34 +0000243 OS << ");\n";
Chris Lattner4b009652007-07-25 00:24:17 +0000244}
245
246void StmtPrinter::VisitForStmt(ForStmt *Node) {
247 Indent() << "for (";
248 if (Node->getInit()) {
249 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
Ted Kremenek388b2842008-10-06 18:39:36 +0000250 PrintRawDeclStmt(DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000251 else
252 PrintExpr(cast<Expr>(Node->getInit()));
253 }
Chris Lattnercfe0ff02007-09-15 21:49:37 +0000254 OS << ";";
255 if (Node->getCond()) {
256 OS << " ";
Chris Lattner4b009652007-07-25 00:24:17 +0000257 PrintExpr(Node->getCond());
Chris Lattnercfe0ff02007-09-15 21:49:37 +0000258 }
259 OS << ";";
260 if (Node->getInc()) {
261 OS << " ";
Chris Lattner4b009652007-07-25 00:24:17 +0000262 PrintExpr(Node->getInc());
Chris Lattnercfe0ff02007-09-15 21:49:37 +0000263 }
264 OS << ") ";
Mike Stump25cf7602009-09-09 15:08:12 +0000265
Chris Lattnercfe0ff02007-09-15 21:49:37 +0000266 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
267 PrintRawCompoundStmt(CS);
268 OS << "\n";
269 } else {
270 OS << "\n";
271 PrintStmt(Node->getBody());
272 }
Chris Lattner4b009652007-07-25 00:24:17 +0000273}
274
Ted Kremenek42730c52008-01-07 19:49:32 +0000275void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
Fariborz Jahanian9e920f32008-01-02 22:54:34 +0000276 Indent() << "for (";
277 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
Ted Kremenek388b2842008-10-06 18:39:36 +0000278 PrintRawDeclStmt(DS);
Fariborz Jahanian9e920f32008-01-02 22:54:34 +0000279 else
280 PrintExpr(cast<Expr>(Node->getElement()));
281 OS << " in ";
282 PrintExpr(Node->getCollection());
283 OS << ") ";
Mike Stump25cf7602009-09-09 15:08:12 +0000284
Fariborz Jahanian9e920f32008-01-02 22:54:34 +0000285 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
286 PrintRawCompoundStmt(CS);
287 OS << "\n";
288 } else {
289 OS << "\n";
290 PrintStmt(Node->getBody());
291 }
292}
293
Chris Lattner4b009652007-07-25 00:24:17 +0000294void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
295 Indent() << "goto " << Node->getLabel()->getName() << ";\n";
296}
297
298void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
299 Indent() << "goto *";
300 PrintExpr(Node->getTarget());
301 OS << ";\n";
302}
303
304void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
305 Indent() << "continue;\n";
306}
307
308void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
309 Indent() << "break;\n";
310}
311
312
313void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
314 Indent() << "return";
315 if (Node->getRetValue()) {
316 OS << " ";
317 PrintExpr(Node->getRetValue());
318 }
319 OS << ";\n";
320}
321
Chris Lattner8a40a832007-10-29 04:04:16 +0000322
323void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
Anders Carlsson759f45d2007-11-23 23:12:25 +0000324 Indent() << "asm ";
Mike Stump25cf7602009-09-09 15:08:12 +0000325
Anders Carlsson759f45d2007-11-23 23:12:25 +0000326 if (Node->isVolatile())
327 OS << "volatile ";
Mike Stump25cf7602009-09-09 15:08:12 +0000328
Anders Carlsson759f45d2007-11-23 23:12:25 +0000329 OS << "(";
Anders Carlsson076c1112007-11-20 19:21:03 +0000330 VisitStringLiteral(Node->getAsmString());
Mike Stump25cf7602009-09-09 15:08:12 +0000331
Anders Carlsson965d5202007-11-22 01:36:19 +0000332 // Outputs
333 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
334 Node->getNumClobbers() != 0)
335 OS << " : ";
Mike Stump25cf7602009-09-09 15:08:12 +0000336
Anders Carlsson965d5202007-11-22 01:36:19 +0000337 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
338 if (i != 0)
339 OS << ", ";
Mike Stump25cf7602009-09-09 15:08:12 +0000340
Anders Carlsson965d5202007-11-22 01:36:19 +0000341 if (!Node->getOutputName(i).empty()) {
342 OS << '[';
343 OS << Node->getOutputName(i);
344 OS << "] ";
345 }
Mike Stump25cf7602009-09-09 15:08:12 +0000346
Chris Lattnere8625112009-03-10 04:59:06 +0000347 VisitStringLiteral(Node->getOutputConstraintLiteral(i));
Anders Carlsson965d5202007-11-22 01:36:19 +0000348 OS << " ";
349 Visit(Node->getOutputExpr(i));
350 }
Mike Stump25cf7602009-09-09 15:08:12 +0000351
Anders Carlsson965d5202007-11-22 01:36:19 +0000352 // Inputs
353 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
354 OS << " : ";
Mike Stump25cf7602009-09-09 15:08:12 +0000355
Anders Carlsson965d5202007-11-22 01:36:19 +0000356 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
357 if (i != 0)
358 OS << ", ";
Mike Stump25cf7602009-09-09 15:08:12 +0000359
Anders Carlsson965d5202007-11-22 01:36:19 +0000360 if (!Node->getInputName(i).empty()) {
361 OS << '[';
362 OS << Node->getInputName(i);
363 OS << "] ";
364 }
Mike Stump25cf7602009-09-09 15:08:12 +0000365
Chris Lattnere8625112009-03-10 04:59:06 +0000366 VisitStringLiteral(Node->getInputConstraintLiteral(i));
Anders Carlsson965d5202007-11-22 01:36:19 +0000367 OS << " ";
368 Visit(Node->getInputExpr(i));
369 }
Mike Stump25cf7602009-09-09 15:08:12 +0000370
Anders Carlsson965d5202007-11-22 01:36:19 +0000371 // Clobbers
372 if (Node->getNumClobbers() != 0)
373 OS << " : ";
Mike Stump25cf7602009-09-09 15:08:12 +0000374
Anders Carlsson965d5202007-11-22 01:36:19 +0000375 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
376 if (i != 0)
377 OS << ", ";
Mike Stump25cf7602009-09-09 15:08:12 +0000378
Anders Carlsson965d5202007-11-22 01:36:19 +0000379 VisitStringLiteral(Node->getClobber(i));
380 }
Mike Stump25cf7602009-09-09 15:08:12 +0000381
Anders Carlsson076c1112007-11-20 19:21:03 +0000382 OS << ");\n";
Chris Lattner8a40a832007-10-29 04:04:16 +0000383}
384
Ted Kremenek42730c52008-01-07 19:49:32 +0000385void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
Fariborz Jahanian59e9e042007-11-02 18:16:07 +0000386 Indent() << "@try";
387 if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
388 PrintRawCompoundStmt(TS);
389 OS << "\n";
390 }
Mike Stump25cf7602009-09-09 15:08:12 +0000391
392 for (ObjCAtCatchStmt *catchStmt =
Ted Kremenek42730c52008-01-07 19:49:32 +0000393 static_cast<ObjCAtCatchStmt *>(Node->getCatchStmts());
Mike Stump25cf7602009-09-09 15:08:12 +0000394 catchStmt;
395 catchStmt =
Ted Kremenek42730c52008-01-07 19:49:32 +0000396 static_cast<ObjCAtCatchStmt *>(catchStmt->getNextCatchStmt())) {
Fariborz Jahanian59e9e042007-11-02 18:16:07 +0000397 Indent() << "@catch(";
Steve Naroff0e8b96a2009-03-03 19:52:17 +0000398 if (catchStmt->getCatchParamDecl()) {
399 if (Decl *DS = catchStmt->getCatchParamDecl())
400 PrintRawDecl(DS);
Fariborz Jahanian59e9e042007-11-02 18:16:07 +0000401 }
402 OS << ")";
Mike Stump25cf7602009-09-09 15:08:12 +0000403 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
404 PrintRawCompoundStmt(CS);
405 OS << "\n";
406 }
Fariborz Jahanian59e9e042007-11-02 18:16:07 +0000407 }
Mike Stump25cf7602009-09-09 15:08:12 +0000408
409 if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
410 Node->getFinallyStmt())) {
Fariborz Jahanian50b47922007-11-07 00:46:42 +0000411 Indent() << "@finally";
412 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
Fariborz Jahanian59e9e042007-11-02 18:16:07 +0000413 OS << "\n";
Mike Stump25cf7602009-09-09 15:08:12 +0000414 }
Fariborz Jahanian70952482007-11-01 21:12:44 +0000415}
416
Ted Kremenek42730c52008-01-07 19:49:32 +0000417void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
Fariborz Jahanian70952482007-11-01 21:12:44 +0000418}
419
Ted Kremenek42730c52008-01-07 19:49:32 +0000420void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
Fariborz Jahanian70952482007-11-01 21:12:44 +0000421 Indent() << "@catch (...) { /* todo */ } \n";
422}
423
Fariborz Jahanian5f5d6222008-01-30 17:38:29 +0000424void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000425 Indent() << "@throw";
426 if (Node->getThrowExpr()) {
427 OS << " ";
428 PrintExpr(Node->getThrowExpr());
429 }
430 OS << ";\n";
431}
432
Fariborz Jahanian5f5d6222008-01-30 17:38:29 +0000433void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
Fariborz Jahanian993360a2008-01-29 18:21:32 +0000434 Indent() << "@synchronized (";
435 PrintExpr(Node->getSynchExpr());
436 OS << ")";
Fariborz Jahanian5f5d6222008-01-30 17:38:29 +0000437 PrintRawCompoundStmt(Node->getSynchBody());
438 OS << "\n";
Fariborz Jahanian993360a2008-01-29 18:21:32 +0000439}
440
Sebastian Redl237116b2008-12-22 21:35:02 +0000441void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
442 OS << "catch (";
Sebastian Redl743c8162008-12-22 19:15:10 +0000443 if (Decl *ExDecl = Node->getExceptionDecl())
444 PrintRawDecl(ExDecl);
445 else
446 OS << "...";
447 OS << ") ";
448 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
Sebastian Redl237116b2008-12-22 21:35:02 +0000449}
450
451void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
452 Indent();
453 PrintRawCXXCatchStmt(Node);
454 OS << "\n";
455}
456
457void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
458 Indent() << "try ";
459 PrintRawCompoundStmt(Node->getTryBlock());
Mike Stump25cf7602009-09-09 15:08:12 +0000460 for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
Sebastian Redl237116b2008-12-22 21:35:02 +0000461 OS << " ";
462 PrintRawCXXCatchStmt(Node->getHandler(i));
463 }
Sebastian Redl743c8162008-12-22 19:15:10 +0000464 OS << "\n";
465}
466
Chris Lattner4b009652007-07-25 00:24:17 +0000467//===----------------------------------------------------------------------===//
468// Expr printing methods.
469//===----------------------------------------------------------------------===//
470
471void StmtPrinter::VisitExpr(Expr *Node) {
472 OS << "<<unknown expr type>>";
473}
474
475void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
Chris Lattner6c5ec622008-11-24 04:00:27 +0000476 OS << Node->getDecl()->getNameAsString();
Chris Lattner4b009652007-07-25 00:24:17 +0000477}
478
Mike Stump25cf7602009-09-09 15:08:12 +0000479void StmtPrinter::VisitQualifiedDeclRefExpr(QualifiedDeclRefExpr *Node) {
Douglas Gregor566782a2009-01-06 05:10:23 +0000480 NamedDecl *D = Node->getDecl();
481
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +0000482 Node->getQualifier()->print(OS, Policy);
Douglas Gregor566782a2009-01-06 05:10:23 +0000483 OS << D->getNameAsString();
484}
485
Mike Stump25cf7602009-09-09 15:08:12 +0000486void StmtPrinter::VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *Node) {
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +0000487 Node->getQualifier()->print(OS, Policy);
Douglas Gregor47bde7c2009-03-19 17:26:29 +0000488 OS << Node->getDeclName().getAsString();
489}
490
Douglas Gregor28857752009-06-30 22:34:41 +0000491void StmtPrinter::VisitTemplateIdRefExpr(TemplateIdRefExpr *Node) {
492 if (Node->getQualifier())
493 Node->getQualifier()->print(OS, Policy);
494 Node->getTemplateName().print(OS, Policy, true);
Douglas Gregor28857752009-06-30 22:34:41 +0000495 OS << TemplateSpecializationType::PrintTemplateArgumentList(
496 Node->getTemplateArgs(),
497 Node->getNumTemplateArgs(),
498 Policy);
Douglas Gregor28857752009-06-30 22:34:41 +0000499}
500
Steve Naroff5eb2a4a2007-11-12 14:29:37 +0000501void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Fariborz Jahanian4af72492007-11-12 22:29:28 +0000502 if (Node->getBase()) {
503 PrintExpr(Node->getBase());
504 OS << (Node->isArrow() ? "->" : ".");
505 }
Chris Lattner6c5ec622008-11-24 04:00:27 +0000506 OS << Node->getDecl()->getNameAsString();
Steve Naroff5eb2a4a2007-11-12 14:29:37 +0000507}
508
Steve Naroff05391d22008-05-30 00:40:33 +0000509void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
510 if (Node->getBase()) {
511 PrintExpr(Node->getBase());
512 OS << ".";
513 }
Steve Naroff0e948412008-12-04 16:24:46 +0000514 OS << Node->getProperty()->getNameAsCString();
Steve Naroff05391d22008-05-30 00:40:33 +0000515}
516
Fariborz Jahanian128cdc52009-08-20 17:02:02 +0000517void StmtPrinter::VisitObjCImplicitSetterGetterRefExpr(
518 ObjCImplicitSetterGetterRefExpr *Node) {
Fariborz Jahanianf18d4c82008-11-22 18:39:36 +0000519 if (Node->getBase()) {
520 PrintExpr(Node->getBase());
521 OS << ".";
522 }
Fariborz Jahanian1c4da452009-08-18 20:50:23 +0000523 if (Node->getGetterMethod())
524 OS << Node->getGetterMethod()->getNameAsString();
Mike Stump25cf7602009-09-09 15:08:12 +0000525
Fariborz Jahanianf18d4c82008-11-22 18:39:36 +0000526}
527
Chris Lattner69909292008-08-10 01:53:14 +0000528void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
Chris Lattner4b009652007-07-25 00:24:17 +0000529 switch (Node->getIdentType()) {
530 default:
531 assert(0 && "unknown case");
Chris Lattner69909292008-08-10 01:53:14 +0000532 case PredefinedExpr::Func:
Chris Lattner4b009652007-07-25 00:24:17 +0000533 OS << "__func__";
534 break;
Chris Lattner69909292008-08-10 01:53:14 +0000535 case PredefinedExpr::Function:
Chris Lattner4b009652007-07-25 00:24:17 +0000536 OS << "__FUNCTION__";
537 break;
Chris Lattner69909292008-08-10 01:53:14 +0000538 case PredefinedExpr::PrettyFunction:
Chris Lattner4b009652007-07-25 00:24:17 +0000539 OS << "__PRETTY_FUNCTION__";
540 break;
541 }
542}
543
544void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattner4b009652007-07-25 00:24:17 +0000545 unsigned value = Node->getValue();
Chris Lattner1aaf71c2008-06-07 22:35:38 +0000546 if (Node->isWide())
547 OS << "L";
Chris Lattner4b009652007-07-25 00:24:17 +0000548 switch (value) {
549 case '\\':
550 OS << "'\\\\'";
551 break;
552 case '\'':
553 OS << "'\\''";
554 break;
555 case '\a':
556 // TODO: K&R: the meaning of '\\a' is different in traditional C
557 OS << "'\\a'";
558 break;
559 case '\b':
560 OS << "'\\b'";
561 break;
562 // Nonstandard escape sequence.
563 /*case '\e':
564 OS << "'\\e'";
565 break;*/
566 case '\f':
567 OS << "'\\f'";
568 break;
569 case '\n':
570 OS << "'\\n'";
571 break;
572 case '\r':
573 OS << "'\\r'";
574 break;
575 case '\t':
576 OS << "'\\t'";
577 break;
578 case '\v':
579 OS << "'\\v'";
580 break;
581 default:
Ted Kremenekf91bc1d2008-02-23 00:52:04 +0000582 if (value < 256 && isprint(value)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000583 OS << "'" << (char)value << "'";
584 } else if (value < 256) {
Ted Kremenek7b6f67b2008-09-13 05:16:45 +0000585 OS << "'\\x" << llvm::format("%x", value) << "'";
Chris Lattner4b009652007-07-25 00:24:17 +0000586 } else {
587 // FIXME what to really do here?
588 OS << value;
589 }
590 }
591}
592
593void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
594 bool isSigned = Node->getType()->isSignedIntegerType();
595 OS << Node->getValue().toString(10, isSigned);
Mike Stump25cf7602009-09-09 15:08:12 +0000596
Chris Lattner4b009652007-07-25 00:24:17 +0000597 // Emit suffixes. Integer literals are always a builtin integer type.
Chris Lattnerd5a56aa2008-07-26 22:17:49 +0000598 switch (Node->getType()->getAsBuiltinType()->getKind()) {
Chris Lattner4b009652007-07-25 00:24:17 +0000599 default: assert(0 && "Unexpected type for integer literal!");
600 case BuiltinType::Int: break; // no suffix.
601 case BuiltinType::UInt: OS << 'U'; break;
602 case BuiltinType::Long: OS << 'L'; break;
603 case BuiltinType::ULong: OS << "UL"; break;
604 case BuiltinType::LongLong: OS << "LL"; break;
605 case BuiltinType::ULongLong: OS << "ULL"; break;
606 }
607}
608void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
Chris Lattner6a390402007-08-01 00:23:58 +0000609 // FIXME: print value more precisely.
Chris Lattnere0391b22008-06-07 22:13:43 +0000610 OS << Node->getValueAsApproximateDouble();
Chris Lattner4b009652007-07-25 00:24:17 +0000611}
Chris Lattner1de66eb2007-08-26 03:42:43 +0000612
613void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
614 PrintExpr(Node->getSubExpr());
615 OS << "i";
616}
617
Chris Lattner4b009652007-07-25 00:24:17 +0000618void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
619 if (Str->isWide()) OS << 'L';
620 OS << '"';
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000621
Chris Lattner4b009652007-07-25 00:24:17 +0000622 // FIXME: this doesn't print wstrings right.
623 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
Chris Lattner5919a852009-01-16 19:25:18 +0000624 unsigned char Char = Str->getStrData()[i];
Mike Stump25cf7602009-09-09 15:08:12 +0000625
Chris Lattner5919a852009-01-16 19:25:18 +0000626 switch (Char) {
627 default:
628 if (isprint(Char))
629 OS << (char)Char;
630 else // Output anything hard as an octal escape.
631 OS << '\\'
632 << (char)('0'+ ((Char >> 6) & 7))
633 << (char)('0'+ ((Char >> 3) & 7))
634 << (char)('0'+ ((Char >> 0) & 7));
635 break;
636 // Handle some common non-printable cases to make dumps prettier.
Chris Lattner4b009652007-07-25 00:24:17 +0000637 case '\\': OS << "\\\\"; break;
638 case '"': OS << "\\\""; break;
639 case '\n': OS << "\\n"; break;
640 case '\t': OS << "\\t"; break;
641 case '\a': OS << "\\a"; break;
642 case '\b': OS << "\\b"; break;
643 }
644 }
645 OS << '"';
646}
647void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
648 OS << "(";
649 PrintExpr(Node->getSubExpr());
650 OS << ")";
651}
652void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner2b97b092007-08-23 21:46:40 +0000653 if (!Node->isPostfix()) {
Chris Lattner4b009652007-07-25 00:24:17 +0000654 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Mike Stump25cf7602009-09-09 15:08:12 +0000655
Eli Friedman34084c22009-06-14 22:39:26 +0000656 // Print a space if this is an "identifier operator" like __real, or if
657 // it might be concatenated incorrectly like '+'.
Chris Lattner2b97b092007-08-23 21:46:40 +0000658 switch (Node->getOpcode()) {
659 default: break;
Chris Lattner2b97b092007-08-23 21:46:40 +0000660 case UnaryOperator::Real:
661 case UnaryOperator::Imag:
662 case UnaryOperator::Extension:
663 OS << ' ';
664 break;
Eli Friedman34084c22009-06-14 22:39:26 +0000665 case UnaryOperator::Plus:
666 case UnaryOperator::Minus:
667 if (isa<UnaryOperator>(Node->getSubExpr()))
668 OS << ' ';
669 break;
Chris Lattner2b97b092007-08-23 21:46:40 +0000670 }
671 }
Chris Lattner4b009652007-07-25 00:24:17 +0000672 PrintExpr(Node->getSubExpr());
Mike Stump25cf7602009-09-09 15:08:12 +0000673
Chris Lattner4b009652007-07-25 00:24:17 +0000674 if (Node->isPostfix())
675 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattner4b009652007-07-25 00:24:17 +0000676}
Chris Lattner2af6a802007-08-30 17:59:59 +0000677
678bool StmtPrinter::PrintOffsetOfDesignator(Expr *E) {
Eli Friedman342d9432009-02-27 06:44:11 +0000679 if (isa<UnaryOperator>(E)) {
Chris Lattner2af6a802007-08-30 17:59:59 +0000680 // Base case, print the type and comma.
681 OS << E->getType().getAsString() << ", ";
682 return true;
683 } else if (ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
684 PrintOffsetOfDesignator(ASE->getLHS());
685 OS << "[";
686 PrintExpr(ASE->getRHS());
687 OS << "]";
688 return false;
689 } else {
690 MemberExpr *ME = cast<MemberExpr>(E);
691 bool IsFirst = PrintOffsetOfDesignator(ME->getBase());
Chris Lattner6c5ec622008-11-24 04:00:27 +0000692 OS << (IsFirst ? "" : ".") << ME->getMemberDecl()->getNameAsString();
Chris Lattner2af6a802007-08-30 17:59:59 +0000693 return false;
694 }
695}
696
697void StmtPrinter::VisitUnaryOffsetOf(UnaryOperator *Node) {
698 OS << "__builtin_offsetof(";
699 PrintOffsetOfDesignator(Node->getSubExpr());
700 OS << ")";
701}
702
Sebastian Redl0cb7c872008-11-11 17:56:53 +0000703void StmtPrinter::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) {
704 OS << (Node->isSizeOf() ? "sizeof" : "__alignof");
705 if (Node->isArgumentType())
706 OS << "(" << Node->getArgumentType().getAsString() << ")";
707 else {
708 OS << " ";
709 PrintExpr(Node->getArgumentExpr());
710 }
Chris Lattner4b009652007-07-25 00:24:17 +0000711}
712void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
Ted Kremenek1c1700f2007-08-20 16:18:38 +0000713 PrintExpr(Node->getLHS());
Chris Lattner4b009652007-07-25 00:24:17 +0000714 OS << "[";
Ted Kremenek1c1700f2007-08-20 16:18:38 +0000715 PrintExpr(Node->getRHS());
Chris Lattner4b009652007-07-25 00:24:17 +0000716 OS << "]";
717}
718
719void StmtPrinter::VisitCallExpr(CallExpr *Call) {
720 PrintExpr(Call->getCallee());
721 OS << "(";
722 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
Chris Lattner3e254fb2008-04-08 04:40:51 +0000723 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
724 // Don't print any defaulted arguments
725 break;
726 }
727
Chris Lattner4b009652007-07-25 00:24:17 +0000728 if (i) OS << ", ";
729 PrintExpr(Call->getArg(i));
730 }
731 OS << ")";
732}
733void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
Douglas Gregorbdbbc2d2009-01-08 22:45:41 +0000734 // FIXME: Suppress printing implicit bases (like "this")
735 PrintExpr(Node->getBase());
736 OS << (Node->isArrow() ? "->" : ".");
737 // FIXME: Suppress printing references to unnamed objects
738 // representing anonymous unions/structs
Douglas Gregorc1991bf2009-08-31 23:41:50 +0000739 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
740 Qualifier->print(OS, Policy);
741
Douglas Gregor82d44772008-12-20 23:49:58 +0000742 OS << Node->getMemberDecl()->getNameAsString();
Mike Stump25cf7602009-09-09 15:08:12 +0000743
Douglas Gregord33e3282009-09-01 00:37:14 +0000744 if (Node->hasExplicitTemplateArgumentList())
745 OS << TemplateSpecializationType::PrintTemplateArgumentList(
746 Node->getTemplateArgs(),
747 Node->getNumTemplateArgs(),
748 Policy);
Chris Lattner4b009652007-07-25 00:24:17 +0000749}
Steve Naroff29d293b2009-07-24 17:54:45 +0000750void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
751 PrintExpr(Node->getBase());
752 OS << (Node->isArrow() ? "->isa" : ".isa");
753}
754
Nate Begemanaf6ed502008-04-18 23:10:10 +0000755void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Steve Naroffc11705f2007-07-28 23:10:27 +0000756 PrintExpr(Node->getBase());
757 OS << ".";
758 OS << Node->getAccessor().getName();
759}
Argiris Kirtzidisc45e2fb2008-08-18 23:01:59 +0000760void StmtPrinter::VisitCastExpr(CastExpr *) {
761 assert(0 && "CastExpr is an abstract class");
762}
Douglas Gregor21a04f32008-10-27 19:41:14 +0000763void StmtPrinter::VisitExplicitCastExpr(ExplicitCastExpr *) {
764 assert(0 && "ExplicitCastExpr is an abstract class");
765}
Douglas Gregor035d0882008-10-28 15:36:24 +0000766void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
Chris Lattner4b009652007-07-25 00:24:17 +0000767 OS << "(" << Node->getType().getAsString() << ")";
768 PrintExpr(Node->getSubExpr());
769}
770void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
771 OS << "(" << Node->getType().getAsString() << ")";
772 PrintExpr(Node->getInitializer());
773}
774void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
775 // No need to print anything, simply forward to the sub expression.
776 PrintExpr(Node->getSubExpr());
777}
778void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
779 PrintExpr(Node->getLHS());
780 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
781 PrintExpr(Node->getRHS());
782}
Chris Lattner06078d22007-08-25 02:00:02 +0000783void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
784 PrintExpr(Node->getLHS());
785 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
786 PrintExpr(Node->getRHS());
787}
Chris Lattner4b009652007-07-25 00:24:17 +0000788void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
789 PrintExpr(Node->getCond());
Mike Stump25cf7602009-09-09 15:08:12 +0000790
Ted Kremenekeecd9e82007-11-26 18:27:54 +0000791 if (Node->getLHS()) {
792 OS << " ? ";
793 PrintExpr(Node->getLHS());
794 OS << " : ";
795 }
Douglas Gregor996677c2009-05-30 00:08:05 +0000796 else { // Handle GCC extension where LHS can be NULL.
Ted Kremenekeecd9e82007-11-26 18:27:54 +0000797 OS << " ?: ";
798 }
Mike Stump25cf7602009-09-09 15:08:12 +0000799
Chris Lattner4b009652007-07-25 00:24:17 +0000800 PrintExpr(Node->getRHS());
801}
802
803// GNU extensions.
804
Chris Lattnera0d03a72007-08-03 17:31:20 +0000805void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner4b009652007-07-25 00:24:17 +0000806 OS << "&&" << Node->getLabel()->getName();
807}
808
809void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
810 OS << "(";
811 PrintRawCompoundStmt(E->getSubStmt());
812 OS << ")";
813}
814
Steve Naroff63bad2d2007-08-01 22:05:33 +0000815void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
816 OS << "__builtin_types_compatible_p(";
817 OS << Node->getArgType1().getAsString() << ",";
818 OS << Node->getArgType2().getAsString() << ")";
819}
820
Steve Naroff93c53012007-08-03 21:21:27 +0000821void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
822 OS << "__builtin_choose_expr(";
823 PrintExpr(Node->getCond());
Chris Lattner44fcf4f2007-08-04 00:20:15 +0000824 OS << ", ";
Steve Naroff93c53012007-08-03 21:21:27 +0000825 PrintExpr(Node->getLHS());
Chris Lattner44fcf4f2007-08-04 00:20:15 +0000826 OS << ", ";
Steve Naroff93c53012007-08-03 21:21:27 +0000827 PrintExpr(Node->getRHS());
828 OS << ")";
829}
Chris Lattner4b009652007-07-25 00:24:17 +0000830
Douglas Gregorad4b3792008-11-29 04:51:27 +0000831void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
832 OS << "__null";
833}
834
Eli Friedmand0e9d092008-05-14 19:38:39 +0000835void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
836 OS << "__builtin_shufflevector(";
837 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
838 if (i) OS << ", ";
839 PrintExpr(Node->getExpr(i));
840 }
841 OS << ")";
842}
843
Anders Carlsson762b7c72007-08-31 04:56:16 +0000844void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
Douglas Gregor1fa5d0d2009-05-30 00:56:08 +0000845 if (Node->getSyntacticForm()) {
846 Visit(Node->getSyntacticForm());
847 return;
848 }
849
Anders Carlsson762b7c72007-08-31 04:56:16 +0000850 OS << "{ ";
851 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
852 if (i) OS << ", ";
Douglas Gregorf603b472009-01-28 21:54:33 +0000853 if (Node->getInit(i))
854 PrintExpr(Node->getInit(i));
855 else
856 OS << "0";
Anders Carlsson762b7c72007-08-31 04:56:16 +0000857 }
858 OS << " }";
859}
860
Nate Begemane85f43d2009-08-10 23:49:36 +0000861void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
862 OS << "( ";
863 for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
864 if (i) OS << ", ";
865 PrintExpr(Node->getExpr(i));
866 }
867 OS << " )";
868}
869
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000870void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
Douglas Gregorf603b472009-01-28 21:54:33 +0000871 for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
872 DEnd = Node->designators_end();
873 D != DEnd; ++D) {
874 if (D->isFieldDesignator()) {
875 if (D->getDotLoc().isInvalid())
876 OS << D->getFieldName()->getName() << ":";
877 else
878 OS << "." << D->getFieldName()->getName();
879 } else {
880 OS << "[";
881 if (D->isArrayDesignator()) {
882 PrintExpr(Node->getArrayIndex(*D));
883 } else {
884 PrintExpr(Node->getArrayRangeStart(*D));
885 OS << " ... ";
Mike Stump25cf7602009-09-09 15:08:12 +0000886 PrintExpr(Node->getArrayRangeEnd(*D));
Douglas Gregorf603b472009-01-28 21:54:33 +0000887 }
888 OS << "]";
889 }
890 }
891
892 OS << " = ";
893 PrintExpr(Node->getInit());
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000894}
895
Douglas Gregorc9e012a2009-01-29 17:44:32 +0000896void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
Chris Lattner7099c782009-06-30 01:26:17 +0000897 if (Policy.LangOpts.CPlusPlus)
Douglas Gregor996677c2009-05-30 00:08:05 +0000898 OS << "/*implicit*/" << Node->getType().getAsString(Policy) << "()";
899 else {
900 OS << "/*implicit*/(" << Node->getType().getAsString(Policy) << ")";
901 if (Node->getType()->isRecordType())
902 OS << "{}";
903 else
904 OS << 0;
905 }
Douglas Gregorc9e012a2009-01-29 17:44:32 +0000906}
907
Anders Carlsson36760332007-10-15 20:28:48 +0000908void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
Eli Friedmand73364a2009-05-30 04:20:30 +0000909 OS << "__builtin_va_arg(";
Anders Carlsson36760332007-10-15 20:28:48 +0000910 PrintExpr(Node->getSubExpr());
911 OS << ", ";
912 OS << Node->getType().getAsString();
913 OS << ")";
914}
915
Chris Lattner4b009652007-07-25 00:24:17 +0000916// C++
Douglas Gregor65fedaf2008-11-14 16:09:21 +0000917void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
918 const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
919 "",
920#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
921 Spelling,
922#include "clang/Basic/OperatorKinds.def"
923 };
924
925 OverloadedOperatorKind Kind = Node->getOperator();
926 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
927 if (Node->getNumArgs() == 1) {
928 OS << OpStrings[Kind] << ' ';
929 PrintExpr(Node->getArg(0));
930 } else {
931 PrintExpr(Node->getArg(0));
932 OS << ' ' << OpStrings[Kind];
933 }
934 } else if (Kind == OO_Call) {
935 PrintExpr(Node->getArg(0));
936 OS << '(';
937 for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
938 if (ArgIdx > 1)
939 OS << ", ";
940 if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
941 PrintExpr(Node->getArg(ArgIdx));
942 }
943 OS << ')';
944 } else if (Kind == OO_Subscript) {
945 PrintExpr(Node->getArg(0));
946 OS << '[';
947 PrintExpr(Node->getArg(1));
948 OS << ']';
949 } else if (Node->getNumArgs() == 1) {
950 OS << OpStrings[Kind] << ' ';
951 PrintExpr(Node->getArg(0));
952 } else if (Node->getNumArgs() == 2) {
953 PrintExpr(Node->getArg(0));
954 OS << ' ' << OpStrings[Kind] << ' ';
955 PrintExpr(Node->getArg(1));
956 } else {
957 assert(false && "unknown overloaded operator");
958 }
959}
Chris Lattner4b009652007-07-25 00:24:17 +0000960
Douglas Gregor3257fb52008-12-22 05:46:06 +0000961void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
962 VisitCallExpr(cast<CallExpr>(Node));
963}
964
Douglas Gregor21a04f32008-10-27 19:41:14 +0000965void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
966 OS << Node->getCastName() << '<';
967 OS << Node->getTypeAsWritten().getAsString() << ">(";
Chris Lattner4b009652007-07-25 00:24:17 +0000968 PrintExpr(Node->getSubExpr());
969 OS << ")";
970}
971
Douglas Gregor21a04f32008-10-27 19:41:14 +0000972void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
973 VisitCXXNamedCastExpr(Node);
974}
975
976void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
977 VisitCXXNamedCastExpr(Node);
978}
979
980void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
981 VisitCXXNamedCastExpr(Node);
982}
983
984void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
985 VisitCXXNamedCastExpr(Node);
986}
987
Sebastian Redlb93b49c2008-11-11 11:37:55 +0000988void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
989 OS << "typeid(";
990 if (Node->isTypeOperand()) {
991 OS << Node->getTypeOperand().getAsString();
992 } else {
993 PrintExpr(Node->getExprOperand());
994 }
995 OS << ")";
996}
997
Chris Lattner4b009652007-07-25 00:24:17 +0000998void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
999 OS << (Node->getValue() ? "true" : "false");
1000}
1001
Sebastian Redl5d0ead72009-05-10 18:38:11 +00001002void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1003 OS << "nullptr";
1004}
1005
Douglas Gregora5b022a2008-11-04 14:32:21 +00001006void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1007 OS << "this";
1008}
1009
Chris Lattnera7447ba2008-02-26 00:51:44 +00001010void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1011 if (Node->getSubExpr() == 0)
1012 OS << "throw";
1013 else {
1014 OS << "throw ";
1015 PrintExpr(Node->getSubExpr());
1016 }
1017}
1018
Chris Lattner3e254fb2008-04-08 04:40:51 +00001019void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1020 // Nothing to print: we picked up the default argument
1021}
1022
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001023void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1024 OS << Node->getType().getAsString();
1025 OS << "(";
1026 PrintExpr(Node->getSubExpr());
1027 OS << ")";
1028}
1029
Anders Carlsson873176e2009-05-30 20:03:25 +00001030void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1031 PrintExpr(Node->getSubExpr());
1032}
1033
Douglas Gregor861e7902009-01-16 18:33:17 +00001034void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1035 OS << Node->getType().getAsString();
1036 OS << "(";
1037 for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump25cf7602009-09-09 15:08:12 +00001038 ArgEnd = Node->arg_end();
Douglas Gregor861e7902009-01-16 18:33:17 +00001039 Arg != ArgEnd; ++Arg) {
1040 if (Arg != Node->arg_begin())
1041 OS << ", ";
1042 PrintExpr(*Arg);
1043 }
1044 OS << ")";
1045}
1046
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001047void StmtPrinter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *Node) {
1048 OS << Node->getType().getAsString() << "()";
1049}
1050
Argiris Kirtzidisdbce6c12008-09-09 23:47:53 +00001051void
1052StmtPrinter::VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E) {
1053 PrintRawDecl(E->getVarDecl());
1054}
1055
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001056void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1057 if (E->isGlobalNew())
1058 OS << "::";
1059 OS << "new ";
1060 unsigned NumPlace = E->getNumPlacementArgs();
1061 if (NumPlace > 0) {
1062 OS << "(";
1063 PrintExpr(E->getPlacementArg(0));
1064 for (unsigned i = 1; i < NumPlace; ++i) {
1065 OS << ", ";
1066 PrintExpr(E->getPlacementArg(i));
1067 }
1068 OS << ") ";
1069 }
1070 if (E->isParenTypeId())
1071 OS << "(";
Sebastian Redl516432a2008-12-02 22:08:59 +00001072 std::string TypeS;
1073 if (Expr *Size = E->getArraySize()) {
1074 llvm::raw_string_ostream s(TypeS);
Eli Friedman1fd09bb2009-05-30 05:32:46 +00001075 Size->printPretty(s, Context, Helper, Policy);
Sebastian Redl516432a2008-12-02 22:08:59 +00001076 s.flush();
1077 TypeS = "[" + TypeS + "]";
1078 }
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +00001079 E->getAllocatedType().getAsStringInternal(TypeS, Policy);
Sebastian Redl516432a2008-12-02 22:08:59 +00001080 OS << TypeS;
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001081 if (E->isParenTypeId())
1082 OS << ")";
1083
1084 if (E->hasInitializer()) {
1085 OS << "(";
1086 unsigned NumCons = E->getNumConstructorArgs();
1087 if (NumCons > 0) {
1088 PrintExpr(E->getConstructorArg(0));
1089 for (unsigned i = 1; i < NumCons; ++i) {
1090 OS << ", ";
1091 PrintExpr(E->getConstructorArg(i));
1092 }
1093 }
1094 OS << ")";
1095 }
1096}
1097
1098void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1099 if (E->isGlobalDelete())
1100 OS << "::";
1101 OS << "delete ";
1102 if (E->isArrayForm())
1103 OS << "[] ";
1104 PrintExpr(E->getArgument());
1105}
1106
Douglas Gregor3e368512009-09-04 17:36:40 +00001107void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1108 PrintExpr(E->getBase());
1109 if (E->isArrow())
1110 OS << "->";
1111 else
1112 OS << '.';
1113 if (E->getQualifier())
1114 E->getQualifier()->print(OS, Policy);
Mike Stump25cf7602009-09-09 15:08:12 +00001115
Douglas Gregor3e368512009-09-04 17:36:40 +00001116 std::string TypeS;
1117 E->getDestroyedType().getAsStringInternal(TypeS, Policy);
1118 OS << TypeS;
1119}
1120
Douglas Gregor4646f9c2009-02-04 15:01:18 +00001121void StmtPrinter::VisitUnresolvedFunctionNameExpr(UnresolvedFunctionNameExpr *E) {
1122 OS << E->getName().getAsString();
Douglas Gregora133e262008-12-06 00:22:45 +00001123}
1124
Anders Carlssondbbab8c2009-04-23 02:32:43 +00001125void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1126 // Nothing to print.
1127}
1128
Anders Carlsson9f4aef72009-05-01 22:18:43 +00001129void StmtPrinter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
Anders Carlssonb5d9c472009-04-24 22:47:04 +00001130 // Just forward to the sub expression.
1131 PrintExpr(E->getSubExpr());
1132}
1133
Mike Stump25cf7602009-09-09 15:08:12 +00001134void
Douglas Gregorf27b7652009-05-20 18:46:25 +00001135StmtPrinter::VisitCXXUnresolvedConstructExpr(
1136 CXXUnresolvedConstructExpr *Node) {
1137 OS << Node->getTypeAsWritten().getAsString();
1138 OS << "(";
1139 for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
Mike Stump25cf7602009-09-09 15:08:12 +00001140 ArgEnd = Node->arg_end();
Douglas Gregorf27b7652009-05-20 18:46:25 +00001141 Arg != ArgEnd; ++Arg) {
1142 if (Arg != Node->arg_begin())
1143 OS << ", ";
1144 PrintExpr(*Arg);
1145 }
1146 OS << ")";
1147}
1148
Douglas Gregor93b8b0f2009-05-22 21:13:27 +00001149void StmtPrinter::VisitCXXUnresolvedMemberExpr(CXXUnresolvedMemberExpr *Node) {
1150 PrintExpr(Node->getBase());
1151 OS << (Node->isArrow() ? "->" : ".");
Douglas Gregor0f927cf2009-09-03 16:14:30 +00001152 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1153 Qualifier->print(OS, Policy);
Douglas Gregorcc00fc02009-09-09 00:23:06 +00001154 else if (Node->hasExplicitTemplateArgumentList())
1155 // FIXME: Track use of "template" keyword explicitly?
1156 OS << "template ";
Mike Stump25cf7602009-09-09 15:08:12 +00001157
Douglas Gregor93b8b0f2009-05-22 21:13:27 +00001158 OS << Node->getMember().getAsString();
Mike Stump25cf7602009-09-09 15:08:12 +00001159
Douglas Gregorcc00fc02009-09-09 00:23:06 +00001160 if (Node->hasExplicitTemplateArgumentList()) {
1161 OS << TemplateSpecializationType::PrintTemplateArgumentList(
1162 Node->getTemplateArgs(),
1163 Node->getNumTemplateArgs(),
1164 Policy);
1165 }
Douglas Gregor93b8b0f2009-05-22 21:13:27 +00001166}
1167
Sebastian Redl39c0f6f2009-01-05 20:52:13 +00001168static const char *getTypeTraitName(UnaryTypeTrait UTT) {
1169 switch (UTT) {
1170 default: assert(false && "Unknown type trait");
1171 case UTT_HasNothrowAssign: return "__has_nothrow_assign";
1172 case UTT_HasNothrowCopy: return "__has_nothrow_copy";
1173 case UTT_HasNothrowConstructor: return "__has_nothrow_constructor";
1174 case UTT_HasTrivialAssign: return "__has_trivial_assign";
1175 case UTT_HasTrivialCopy: return "__has_trivial_copy";
1176 case UTT_HasTrivialConstructor: return "__has_trivial_constructor";
1177 case UTT_HasTrivialDestructor: return "__has_trivial_destructor";
1178 case UTT_HasVirtualDestructor: return "__has_virtual_destructor";
1179 case UTT_IsAbstract: return "__is_abstract";
1180 case UTT_IsClass: return "__is_class";
1181 case UTT_IsEmpty: return "__is_empty";
1182 case UTT_IsEnum: return "__is_enum";
1183 case UTT_IsPOD: return "__is_pod";
1184 case UTT_IsPolymorphic: return "__is_polymorphic";
1185 case UTT_IsUnion: return "__is_union";
1186 }
1187}
1188
1189void StmtPrinter::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
1190 OS << getTypeTraitName(E->getTrait()) << "("
1191 << E->getQueriedType().getAsString() << ")";
1192}
1193
Mike Stump25cf7602009-09-09 15:08:12 +00001194// Obj-C
Anders Carlssona66cad42007-08-21 17:43:55 +00001195
1196void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1197 OS << "@";
1198 VisitStringLiteral(Node->getString());
1199}
Chris Lattner4b009652007-07-25 00:24:17 +00001200
Anders Carlsson8be1d402007-08-22 15:14:15 +00001201void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Chris Lattner6c5ec622008-11-24 04:00:27 +00001202 OS << "@encode(" << Node->getEncodedType().getAsString() << ')';
Anders Carlsson8be1d402007-08-22 15:14:15 +00001203}
1204
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001205void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
Chris Lattner6c5ec622008-11-24 04:00:27 +00001206 OS << "@selector(" << Node->getSelector().getAsString() << ')';
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001207}
1208
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001209void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
Chris Lattner6c5ec622008-11-24 04:00:27 +00001210 OS << "@protocol(" << Node->getProtocol()->getNameAsString() << ')';
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001211}
1212
Steve Naroffc39ca262007-09-18 23:55:05 +00001213void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1214 OS << "[";
Steve Narofffa465d12007-10-02 20:01:56 +00001215 Expr *receiver = Mess->getReceiver();
1216 if (receiver) PrintExpr(receiver);
1217 else OS << Mess->getClassName()->getName();
Ted Kremenekbfec9492008-05-02 17:32:38 +00001218 OS << ' ';
Ted Kremenek2287cee2008-04-16 04:30:16 +00001219 Selector selector = Mess->getSelector();
Steve Narofffa465d12007-10-02 20:01:56 +00001220 if (selector.isUnarySelector()) {
Ted Kremenekbfec9492008-05-02 17:32:38 +00001221 OS << selector.getIdentifierInfoForSlot(0)->getName();
Steve Narofffa465d12007-10-02 20:01:56 +00001222 } else {
1223 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
Ted Kremenekbfec9492008-05-02 17:32:38 +00001224 if (i < selector.getNumArgs()) {
1225 if (i > 0) OS << ' ';
1226 if (selector.getIdentifierInfoForSlot(i))
Chris Lattner6c5ec622008-11-24 04:00:27 +00001227 OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
Ted Kremenekbfec9492008-05-02 17:32:38 +00001228 else
1229 OS << ":";
1230 }
1231 else OS << ", "; // Handle variadic methods.
Mike Stump25cf7602009-09-09 15:08:12 +00001232
Steve Narofffa465d12007-10-02 20:01:56 +00001233 PrintExpr(Mess->getArg(i));
1234 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001235 }
1236 OS << "]";
1237}
1238
Douglas Gregord8606632008-11-04 14:56:14 +00001239void StmtPrinter::VisitObjCSuperExpr(ObjCSuperExpr *) {
1240 OS << "super";
1241}
1242
Steve Naroff52a81c02008-09-03 18:15:37 +00001243void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
Steve Naroff9ac456d2008-10-08 17:01:13 +00001244 BlockDecl *BD = Node->getBlockDecl();
Steve Naroff52a81c02008-09-03 18:15:37 +00001245 OS << "^";
Mike Stump25cf7602009-09-09 15:08:12 +00001246
Steve Naroff52a81c02008-09-03 18:15:37 +00001247 const FunctionType *AFT = Node->getFunctionType();
Mike Stump25cf7602009-09-09 15:08:12 +00001248
Douglas Gregor4fa58902009-02-26 23:50:07 +00001249 if (isa<FunctionNoProtoType>(AFT)) {
Steve Naroff52a81c02008-09-03 18:15:37 +00001250 OS << "()";
Douglas Gregor4fa58902009-02-26 23:50:07 +00001251 } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
Steve Naroff52a81c02008-09-03 18:15:37 +00001252 OS << '(';
1253 std::string ParamStr;
Steve Naroff9ac456d2008-10-08 17:01:13 +00001254 for (BlockDecl::param_iterator AI = BD->param_begin(),
1255 E = BD->param_end(); AI != E; ++AI) {
1256 if (AI != BD->param_begin()) OS << ", ";
Chris Lattner6c5ec622008-11-24 04:00:27 +00001257 ParamStr = (*AI)->getNameAsString();
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +00001258 (*AI)->getType().getAsStringInternal(ParamStr, Policy);
Steve Naroff52a81c02008-09-03 18:15:37 +00001259 OS << ParamStr;
1260 }
Mike Stump25cf7602009-09-09 15:08:12 +00001261
Douglas Gregor4fa58902009-02-26 23:50:07 +00001262 const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
Steve Naroff52a81c02008-09-03 18:15:37 +00001263 if (FT->isVariadic()) {
Steve Naroff9ac456d2008-10-08 17:01:13 +00001264 if (!BD->param_empty()) OS << ", ";
Steve Naroff52a81c02008-09-03 18:15:37 +00001265 OS << "...";
1266 }
1267 OS << ')';
1268 }
1269}
1270
Steve Naroff52a81c02008-09-03 18:15:37 +00001271void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) {
Chris Lattner6c5ec622008-11-24 04:00:27 +00001272 OS << Node->getDecl()->getNameAsString();
Steve Naroff52a81c02008-09-03 18:15:37 +00001273}
Chris Lattner4b009652007-07-25 00:24:17 +00001274//===----------------------------------------------------------------------===//
1275// Stmt method implementations
1276//===----------------------------------------------------------------------===//
1277
Eli Friedman4bdae722009-05-30 05:03:24 +00001278void Stmt::dumpPretty(ASTContext& Context) const {
Chris Lattner7099c782009-06-30 01:26:17 +00001279 printPretty(llvm::errs(), Context, 0,
1280 PrintingPolicy(Context.getLangOptions()));
Chris Lattner4b009652007-07-25 00:24:17 +00001281}
1282
Eli Friedman4bdae722009-05-30 05:03:24 +00001283void Stmt::printPretty(llvm::raw_ostream &OS, ASTContext& Context,
1284 PrinterHelper* Helper,
Douglas Gregor3bf3bbc2009-05-29 20:38:28 +00001285 const PrintingPolicy &Policy,
1286 unsigned Indentation) const {
Chris Lattner4b009652007-07-25 00:24:17 +00001287 if (this == 0) {
1288 OS << "<NULL>";
1289 return;
1290 }
1291
Douglas Gregor996677c2009-05-30 00:08:05 +00001292 if (Policy.Dump) {
Argiris Kirtzidisaec06482009-07-14 03:20:38 +00001293 dump(Context.getSourceManager());
Douglas Gregor996677c2009-05-30 00:08:05 +00001294 return;
1295 }
Mike Stump25cf7602009-09-09 15:08:12 +00001296
Eli Friedman4bdae722009-05-30 05:03:24 +00001297 StmtPrinter P(OS, Context, Helper, Policy, Indentation);
Chris Lattner7ba21fa2007-08-21 04:04:25 +00001298 P.Visit(const_cast<Stmt*>(this));
Chris Lattner4b009652007-07-25 00:24:17 +00001299}
Ted Kremenek08176a52007-08-31 21:30:12 +00001300
1301//===----------------------------------------------------------------------===//
1302// PrinterHelper
1303//===----------------------------------------------------------------------===//
1304
1305// Implement virtual destructor.
Gabor Greif61ce98c2007-09-11 15:32:40 +00001306PrinterHelper::~PrinterHelper() {}