blob: d52f48ed2105acde04c6c72f68c22308d7552783 [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"
Chris Lattner5efbb332006-11-20 05:01:40 +000016#include "clang/AST/Decl.h"
Ted Kremenek5c84c012007-10-17 18:36:42 +000017#include "clang/AST/DeclObjC.h"
Chris Lattner29375652006-12-04 18:06:35 +000018#include "clang/AST/ExprCXX.h"
Steve Naroff021ca182008-05-29 21:12:08 +000019#include "clang/AST/ExprObjC.h"
Ted Kremenek04f3cee2007-08-31 21:30:12 +000020#include "clang/AST/PrettyPrinter.h"
Chris Lattneref6b1362007-10-07 08:58:51 +000021#include "clang/Basic/IdentifierTable.h"
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000022#include "llvm/Support/Compiler.h"
Ted Kremenek871422e2007-11-26 22:50:46 +000023#include "llvm/Support/Streams.h"
Chris Lattner6e9d9b32007-07-13 05:18:11 +000024#include <iomanip>
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000025using namespace clang;
26
27//===----------------------------------------------------------------------===//
28// StmtPrinter Visitor
29//===----------------------------------------------------------------------===//
30
31namespace {
Chris Lattner62249a62007-08-21 04:04:25 +000032 class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000033 std::ostream &OS;
34 unsigned IndentLevel;
Ted Kremenek04f3cee2007-08-31 21:30:12 +000035 clang::PrinterHelper* Helper;
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000036 public:
Ted Kremenek04f3cee2007-08-31 21:30:12 +000037 StmtPrinter(std::ostream &os, PrinterHelper* helper) :
38 OS(os), IndentLevel(0), Helper(helper) {}
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000039
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000040 void PrintStmt(Stmt *S, int SubIndent = 1) {
41 IndentLevel += SubIndent;
Chris Lattnera076fde2007-05-31 18:21:33 +000042 if (S && isa<Expr>(S)) {
Chris Lattner882f7882006-11-04 18:52:07 +000043 // If this is an expr used in a stmt context, indent and newline it.
44 Indent();
Chris Lattner62249a62007-08-21 04:04:25 +000045 Visit(S);
Chris Lattnerfc068c12007-05-30 17:57:36 +000046 OS << ";\n";
Chris Lattner882f7882006-11-04 18:52:07 +000047 } else if (S) {
Chris Lattner62249a62007-08-21 04:04:25 +000048 Visit(S);
Chris Lattner882f7882006-11-04 18:52:07 +000049 } else {
Chris Lattner2f6ac262007-05-28 01:47:47 +000050 Indent() << "<<<NULL STATEMENT>>>\n";
Chris Lattner882f7882006-11-04 18:52:07 +000051 }
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000052 IndentLevel -= SubIndent;
Chris Lattner882f7882006-11-04 18:52:07 +000053 }
Chris Lattner073926e2007-05-20 23:04:55 +000054
55 void PrintRawCompoundStmt(CompoundStmt *S);
Chris Lattnerfdc195a2007-06-05 20:52:47 +000056 void PrintRawDecl(Decl *D);
Chris Lattnerc0a38dd2007-06-11 22:26:23 +000057 void PrintRawIfStmt(IfStmt *If);
58
Chris Lattner882f7882006-11-04 18:52:07 +000059 void PrintExpr(Expr *E) {
60 if (E)
Chris Lattner62249a62007-08-21 04:04:25 +000061 Visit(E);
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000062 else
Chris Lattner882f7882006-11-04 18:52:07 +000063 OS << "<null expr>";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000064 }
65
Chris Lattnerb9eb5a12007-05-20 22:52:15 +000066 std::ostream &Indent(int Delta = 0) const {
Chris Lattnerd5322cd2007-05-29 23:49:07 +000067 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000068 OS << " ";
69 return OS;
70 }
71
Chris Lattner98dbf0a2007-08-30 17:59:59 +000072 bool PrintOffsetOfDesignator(Expr *E);
73 void VisitUnaryOffsetOf(UnaryOperator *Node);
74
Ted Kremenek04f3cee2007-08-31 21:30:12 +000075 void Visit(Stmt* S) {
76 if (Helper && Helper->handledStmt(S,OS))
77 return;
78 else StmtVisitor<StmtPrinter>::Visit(S);
79 }
80
Chris Lattner62249a62007-08-21 04:04:25 +000081 void VisitStmt(Stmt *Node);
Steve Naroff7f890eb2007-02-27 02:53:10 +000082#define STMT(N, CLASS, PARENT) \
Chris Lattner62249a62007-08-21 04:04:25 +000083 void Visit##CLASS(CLASS *Node);
Chris Lattnerf2174b62006-11-04 20:59:27 +000084#include "clang/AST/StmtNodes.def"
Chris Lattner71e23ce2006-11-04 20:18:38 +000085 };
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000086}
87
Chris Lattner71e23ce2006-11-04 20:18:38 +000088//===----------------------------------------------------------------------===//
89// Stmt printing methods.
90//===----------------------------------------------------------------------===//
91
Chris Lattner882f7882006-11-04 18:52:07 +000092void StmtPrinter::VisitStmt(Stmt *Node) {
93 Indent() << "<<unknown stmt type>>\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +000094}
95
Chris Lattner073926e2007-05-20 23:04:55 +000096/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
97/// with no newline after the }.
98void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
99 OS << "{\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000100 for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
Chris Lattner882f7882006-11-04 18:52:07 +0000101 I != E; ++I)
102 PrintStmt(*I);
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000103
Chris Lattner073926e2007-05-20 23:04:55 +0000104 Indent() << "}";
105}
106
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000107void StmtPrinter::PrintRawDecl(Decl *D) {
108 // FIXME: Need to complete/beautify this... this code simply shows the
Steve Naroff2a8ad182007-05-29 22:59:26 +0000109 // nodes are where they need to be.
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000110 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
111 OS << "typedef " << localType->getUnderlyingType().getAsString();
112 OS << " " << localType->getName();
113 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
Chris Lattnerb4522b42007-06-02 05:27:01 +0000114 // Emit storage class for vardecls.
115 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
116 switch (V->getStorageClass()) {
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000117 default: assert(0 && "Unknown storage class!");
118 case VarDecl::None: break;
119 case VarDecl::Extern: OS << "extern "; break;
120 case VarDecl::Static: OS << "static "; break;
121 case VarDecl::Auto: OS << "auto "; break;
122 case VarDecl::Register: OS << "register "; break;
Chris Lattnerb4522b42007-06-02 05:27:01 +0000123 }
124 }
125
Chris Lattnere0c4ae12007-06-02 03:38:08 +0000126 std::string Name = VD->getName();
127 VD->getType().getAsStringInternal(Name);
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000128 OS << Name;
129
Chris Lattner79c57592007-07-12 00:36:32 +0000130 // If this is a vardecl with an initializer, emit it.
131 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
132 if (V->getInit()) {
133 OS << " = ";
134 PrintExpr(V->getInit());
135 }
136 }
Steve Naroffc1e6d602007-11-17 21:21:01 +0000137 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
138 // print a free standing tag decl (e.g. "struct x;").
139 OS << TD->getKindName();
140 OS << " ";
141 if (const IdentifierInfo *II = TD->getIdentifier())
142 OS << II->getName();
143 else
144 OS << "<anonymous>";
145 // FIXME: print tag bodies.
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000146 } else {
Chris Lattnere0c4ae12007-06-02 03:38:08 +0000147 assert(0 && "Unexpected decl");
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000148 }
149}
150
151
152void StmtPrinter::VisitNullStmt(NullStmt *Node) {
153 Indent() << ";\n";
154}
155
156void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
Steve Naroffa23cc792007-09-13 23:52:58 +0000157 for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattner776fac82007-06-09 00:53:06 +0000158 Indent();
159 PrintRawDecl(D);
160 OS << ";\n";
161 }
Steve Naroff2a8ad182007-05-29 22:59:26 +0000162}
163
Chris Lattner073926e2007-05-20 23:04:55 +0000164void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
165 Indent();
166 PrintRawCompoundStmt(Node);
Chris Lattnerdf3cafb2007-05-31 05:08:56 +0000167 OS << "\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000168}
169
Chris Lattner6c0ff132006-11-05 00:19:50 +0000170void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000171 Indent(-1) << "case ";
Chris Lattner6c0ff132006-11-05 00:19:50 +0000172 PrintExpr(Node->getLHS());
173 if (Node->getRHS()) {
174 OS << " ... ";
175 PrintExpr(Node->getRHS());
176 }
177 OS << ":\n";
178
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000179 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000180}
181
182void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000183 Indent(-1) << "default:\n";
184 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000185}
186
187void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000188 Indent(-1) << Node->getName() << ":\n";
Chris Lattnerb9eb5a12007-05-20 22:52:15 +0000189 PrintStmt(Node->getSubStmt(), 0);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000190}
191
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000192void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
193 OS << "if ";
Chris Lattner882f7882006-11-04 18:52:07 +0000194 PrintExpr(If->getCond());
Chris Lattner073926e2007-05-20 23:04:55 +0000195
196 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
197 OS << ' ';
198 PrintRawCompoundStmt(CS);
199 OS << (If->getElse() ? ' ' : '\n');
200 } else {
201 OS << '\n';
202 PrintStmt(If->getThen());
203 if (If->getElse()) Indent();
204 }
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000205
Chris Lattner073926e2007-05-20 23:04:55 +0000206 if (Stmt *Else = If->getElse()) {
207 OS << "else";
208
209 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
210 OS << ' ';
211 PrintRawCompoundStmt(CS);
212 OS << '\n';
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000213 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
214 OS << ' ';
215 PrintRawIfStmt(ElseIf);
Chris Lattner073926e2007-05-20 23:04:55 +0000216 } else {
217 OS << '\n';
218 PrintStmt(If->getElse());
219 }
Chris Lattner882f7882006-11-04 18:52:07 +0000220 }
Chris Lattner85ed8732006-11-04 20:40:44 +0000221}
222
Chris Lattnerc0a38dd2007-06-11 22:26:23 +0000223void StmtPrinter::VisitIfStmt(IfStmt *If) {
224 Indent();
225 PrintRawIfStmt(If);
226}
227
Chris Lattnerf2174b62006-11-04 20:59:27 +0000228void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
229 Indent() << "switch (";
230 PrintExpr(Node->getCond());
Chris Lattner073926e2007-05-20 23:04:55 +0000231 OS << ")";
232
233 // Pretty print compoundstmt bodies (very common).
234 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
235 OS << " ";
236 PrintRawCompoundStmt(CS);
237 OS << "\n";
238 } else {
239 OS << "\n";
240 PrintStmt(Node->getBody());
241 }
Chris Lattnerf2174b62006-11-04 20:59:27 +0000242}
243
Anders Carlsson51873c22007-07-22 07:07:56 +0000244void StmtPrinter::VisitSwitchCase(SwitchCase*) {
245 assert(0 && "SwitchCase is an abstract class");
246}
247
Chris Lattner85ed8732006-11-04 20:40:44 +0000248void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
249 Indent() << "while (";
250 PrintExpr(Node->getCond());
251 OS << ")\n";
252 PrintStmt(Node->getBody());
253}
254
255void StmtPrinter::VisitDoStmt(DoStmt *Node) {
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000256 Indent() << "do ";
257 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
258 PrintRawCompoundStmt(CS);
259 OS << " ";
260 } else {
261 OS << "\n";
262 PrintStmt(Node->getBody());
263 Indent();
264 }
265
266 OS << "while ";
Chris Lattner85ed8732006-11-04 20:40:44 +0000267 PrintExpr(Node->getCond());
Chris Lattnera076fde2007-05-31 18:21:33 +0000268 OS << ";\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000269}
270
Chris Lattner71e23ce2006-11-04 20:18:38 +0000271void StmtPrinter::VisitForStmt(ForStmt *Node) {
272 Indent() << "for (";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000273 if (Node->getInit()) {
274 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
275 PrintRawDecl(DS->getDecl());
276 else
277 PrintExpr(cast<Expr>(Node->getInit()));
278 }
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000279 OS << ";";
280 if (Node->getCond()) {
281 OS << " ";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000282 PrintExpr(Node->getCond());
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000283 }
284 OS << ";";
285 if (Node->getInc()) {
286 OS << " ";
Chris Lattnerfdc195a2007-06-05 20:52:47 +0000287 PrintExpr(Node->getInc());
Chris Lattner5a4e9d22007-09-15 21:49:37 +0000288 }
289 OS << ") ";
290
291 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
292 PrintRawCompoundStmt(CS);
293 OS << "\n";
294 } else {
295 OS << "\n";
296 PrintStmt(Node->getBody());
297 }
Chris Lattner71e23ce2006-11-04 20:18:38 +0000298}
299
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000300void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
Fariborz Jahanian83615522008-01-02 22:54:34 +0000301 Indent() << "for (";
302 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
303 PrintRawDecl(DS->getDecl());
304 else
305 PrintExpr(cast<Expr>(Node->getElement()));
306 OS << " in ";
307 PrintExpr(Node->getCollection());
308 OS << ") ";
309
310 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
311 PrintRawCompoundStmt(CS);
312 OS << "\n";
313 } else {
314 OS << "\n";
315 PrintStmt(Node->getBody());
316 }
317}
318
Chris Lattner16976d32006-11-05 01:46:01 +0000319void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000320 Indent() << "goto " << Node->getLabel()->getName() << ";\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000321}
322
323void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
Chris Lattner36ad1232006-11-05 01:51:06 +0000324 Indent() << "goto *";
Chris Lattner16976d32006-11-05 01:46:01 +0000325 PrintExpr(Node->getTarget());
Chris Lattnerb4619482007-05-31 06:00:14 +0000326 OS << ";\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000327}
328
329void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
Chris Lattnerb4619482007-05-31 06:00:14 +0000330 Indent() << "continue;\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000331}
332
333void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
Chris Lattnerb4619482007-05-31 06:00:14 +0000334 Indent() << "break;\n";
Chris Lattner16976d32006-11-05 01:46:01 +0000335}
336
337
Chris Lattner882f7882006-11-04 18:52:07 +0000338void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
339 Indent() << "return";
340 if (Node->getRetValue()) {
341 OS << " ";
342 PrintExpr(Node->getRetValue());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000343 }
Chris Lattnerb4619482007-05-31 06:00:14 +0000344 OS << ";\n";
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000345}
346
Chris Lattner73c56c02007-10-29 04:04:16 +0000347
348void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
Anders Carlsson660bdd12007-11-23 23:12:25 +0000349 Indent() << "asm ";
350
351 if (Node->isVolatile())
352 OS << "volatile ";
353
354 OS << "(";
Anders Carlsson81a5a692007-11-20 19:21:03 +0000355 VisitStringLiteral(Node->getAsmString());
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000356
357 // Outputs
358 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
359 Node->getNumClobbers() != 0)
360 OS << " : ";
361
362 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
363 if (i != 0)
364 OS << ", ";
365
366 if (!Node->getOutputName(i).empty()) {
367 OS << '[';
368 OS << Node->getOutputName(i);
369 OS << "] ";
370 }
371
372 VisitStringLiteral(Node->getOutputConstraint(i));
373 OS << " ";
374 Visit(Node->getOutputExpr(i));
375 }
376
377 // Inputs
378 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
379 OS << " : ";
380
381 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
382 if (i != 0)
383 OS << ", ";
384
385 if (!Node->getInputName(i).empty()) {
386 OS << '[';
387 OS << Node->getInputName(i);
388 OS << "] ";
389 }
390
391 VisitStringLiteral(Node->getInputConstraint(i));
392 OS << " ";
393 Visit(Node->getInputExpr(i));
394 }
395
396 // Clobbers
397 if (Node->getNumClobbers() != 0)
398 OS << " : ";
399
400 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
401 if (i != 0)
402 OS << ", ";
403
404 VisitStringLiteral(Node->getClobber(i));
405 }
406
Anders Carlsson81a5a692007-11-20 19:21:03 +0000407 OS << ");\n";
Chris Lattner73c56c02007-10-29 04:04:16 +0000408}
409
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000410void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
Fariborz Jahanian88157952007-11-02 18:16:07 +0000411 Indent() << "@try";
412 if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
413 PrintRawCompoundStmt(TS);
414 OS << "\n";
415 }
416
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000417 for (ObjCAtCatchStmt *catchStmt =
418 static_cast<ObjCAtCatchStmt *>(Node->getCatchStmts());
Fariborz Jahanian88157952007-11-02 18:16:07 +0000419 catchStmt;
420 catchStmt =
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000421 static_cast<ObjCAtCatchStmt *>(catchStmt->getNextCatchStmt())) {
Fariborz Jahanian88157952007-11-02 18:16:07 +0000422 Indent() << "@catch(";
423 if (catchStmt->getCatchParamStmt()) {
424 if (DeclStmt *DS = dyn_cast<DeclStmt>(catchStmt->getCatchParamStmt()))
425 PrintRawDecl(DS->getDecl());
426 }
427 OS << ")";
428 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody()))
429 {
430 PrintRawCompoundStmt(CS);
431 OS << "\n";
432 }
433 }
434
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000435 if (ObjCAtFinallyStmt *FS =static_cast<ObjCAtFinallyStmt *>(
Fariborz Jahaniandefbf9a2007-11-07 00:46:42 +0000436 Node->getFinallyStmt())) {
437 Indent() << "@finally";
438 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
Fariborz Jahanian88157952007-11-02 18:16:07 +0000439 OS << "\n";
440 }
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000441}
442
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000443void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000444}
445
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000446void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
Fariborz Jahanian65590b22007-11-01 21:12:44 +0000447 Indent() << "@catch (...) { /* todo */ } \n";
448}
449
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000450void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000451 Indent() << "@throw";
452 if (Node->getThrowExpr()) {
453 OS << " ";
454 PrintExpr(Node->getThrowExpr());
455 }
456 OS << ";\n";
457}
458
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000459void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
Fariborz Jahanianf89ca382008-01-29 18:21:32 +0000460 Indent() << "@synchronized (";
461 PrintExpr(Node->getSynchExpr());
462 OS << ")";
Fariborz Jahanian049fa582008-01-30 17:38:29 +0000463 PrintRawCompoundStmt(Node->getSynchBody());
464 OS << "\n";
Fariborz Jahanianf89ca382008-01-29 18:21:32 +0000465}
466
Chris Lattner71e23ce2006-11-04 20:18:38 +0000467//===----------------------------------------------------------------------===//
468// Expr printing methods.
469//===----------------------------------------------------------------------===//
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000470
Chris Lattner882f7882006-11-04 18:52:07 +0000471void StmtPrinter::VisitExpr(Expr *Node) {
472 OS << "<<unknown expr type>>";
473}
474
475void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
Chris Lattner5efbb332006-11-20 05:01:40 +0000476 OS << Node->getDecl()->getName();
Chris Lattner882f7882006-11-04 18:52:07 +0000477}
478
Steve Naroffe46504b2007-11-12 14:29:37 +0000479void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
Fariborz Jahanian21f54ee2007-11-12 22:29:28 +0000480 if (Node->getBase()) {
481 PrintExpr(Node->getBase());
482 OS << (Node->isArrow() ? "->" : ".");
483 }
Steve Naroffe46504b2007-11-12 14:29:37 +0000484 OS << Node->getDecl()->getName();
485}
486
Steve Naroffec944032008-05-30 00:40:33 +0000487void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
488 if (Node->getBase()) {
489 PrintExpr(Node->getBase());
490 OS << ".";
491 }
492 // FIXME: OS << Node->getDecl()->getName();
493}
494
Anders Carlsson625bfc82007-07-21 05:21:51 +0000495void StmtPrinter::VisitPreDefinedExpr(PreDefinedExpr *Node) {
496 switch (Node->getIdentType()) {
497 default:
498 assert(0 && "unknown case");
499 case PreDefinedExpr::Func:
500 OS << "__func__";
501 break;
502 case PreDefinedExpr::Function:
503 OS << "__FUNCTION__";
504 break;
505 case PreDefinedExpr::PrettyFunction:
506 OS << "__PRETTY_FUNCTION__";
507 break;
508 }
509}
510
Steve Naroffae4143e2007-04-26 20:39:23 +0000511void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
Chris Lattner666115c2007-07-13 23:58:20 +0000512 // FIXME should print an L for wchar_t constants
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000513 unsigned value = Node->getValue();
Chris Lattner666115c2007-07-13 23:58:20 +0000514 switch (value) {
515 case '\\':
516 OS << "'\\\\'";
517 break;
518 case '\'':
519 OS << "'\\''";
520 break;
521 case '\a':
522 // TODO: K&R: the meaning of '\\a' is different in traditional C
523 OS << "'\\a'";
524 break;
525 case '\b':
526 OS << "'\\b'";
527 break;
528 // Nonstandard escape sequence.
529 /*case '\e':
530 OS << "'\\e'";
531 break;*/
532 case '\f':
533 OS << "'\\f'";
534 break;
535 case '\n':
536 OS << "'\\n'";
537 break;
538 case '\r':
539 OS << "'\\r'";
540 break;
541 case '\t':
542 OS << "'\\t'";
543 break;
544 case '\v':
545 OS << "'\\v'";
546 break;
547 default:
Ted Kremenek652d18e2008-02-23 00:52:04 +0000548 if (value < 256 && isprint(value)) {
Chris Lattner666115c2007-07-13 23:58:20 +0000549 OS << "'" << (char)value << "'";
550 } else if (value < 256) {
551 OS << "'\\x" << std::hex << value << std::dec << "'";
552 } else {
553 // FIXME what to really do here?
554 OS << value;
555 }
Chris Lattner6e9d9b32007-07-13 05:18:11 +0000556 }
Steve Naroffae4143e2007-04-26 20:39:23 +0000557}
558
Steve Naroffdf7855b2007-02-21 23:46:25 +0000559void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
Chris Lattner06430412007-05-21 05:45:03 +0000560 bool isSigned = Node->getType()->isSignedIntegerType();
561 OS << Node->getValue().toString(10, isSigned);
562
563 // Emit suffixes. Integer literals are always a builtin integer type.
564 switch (cast<BuiltinType>(Node->getType().getCanonicalType())->getKind()) {
565 default: assert(0 && "Unexpected type for integer literal!");
566 case BuiltinType::Int: break; // no suffix.
567 case BuiltinType::UInt: OS << 'U'; break;
568 case BuiltinType::Long: OS << 'L'; break;
569 case BuiltinType::ULong: OS << "UL"; break;
570 case BuiltinType::LongLong: OS << "LL"; break;
571 case BuiltinType::ULongLong: OS << "ULL"; break;
572 }
Chris Lattner882f7882006-11-04 18:52:07 +0000573}
Steve Naroffab624882007-02-21 22:05:47 +0000574void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
Chris Lattnerbf2f3862007-08-01 00:23:58 +0000575 // FIXME: print value more precisely.
Chris Lattner2dd003e2007-09-22 18:47:25 +0000576 OS << Node->getValueAsDouble();
Chris Lattner882f7882006-11-04 18:52:07 +0000577}
Chris Lattner1c20a172007-08-26 03:42:43 +0000578
579void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
580 PrintExpr(Node->getSubExpr());
581 OS << "i";
582}
583
Steve Naroffdf7855b2007-02-21 23:46:25 +0000584void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
Chris Lattner882f7882006-11-04 18:52:07 +0000585 if (Str->isWide()) OS << 'L';
Chris Lattner5d8f4942006-11-04 20:29:31 +0000586 OS << '"';
Anders Carlssoncbfc4b82007-10-15 02:50:23 +0000587
Chris Lattner5d8f4942006-11-04 20:29:31 +0000588 // FIXME: this doesn't print wstrings right.
589 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
590 switch (Str->getStrData()[i]) {
591 default: OS << Str->getStrData()[i]; break;
592 // Handle some common ones to make dumps prettier.
593 case '\\': OS << "\\\\"; break;
594 case '"': OS << "\\\""; break;
595 case '\n': OS << "\\n"; break;
596 case '\t': OS << "\\t"; break;
597 case '\a': OS << "\\a"; break;
598 case '\b': OS << "\\b"; break;
599 }
600 }
601 OS << '"';
Chris Lattner882f7882006-11-04 18:52:07 +0000602}
603void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
604 OS << "(";
605 PrintExpr(Node->getSubExpr());
Chris Lattnera076fde2007-05-31 18:21:33 +0000606 OS << ")";
Chris Lattner882f7882006-11-04 18:52:07 +0000607}
608void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattnere5b60442007-08-23 21:46:40 +0000609 if (!Node->isPostfix()) {
Chris Lattner15768702006-11-05 23:54:51 +0000610 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattnere5b60442007-08-23 21:46:40 +0000611
612 // Print a space if this is an "identifier operator" like sizeof or __real.
613 switch (Node->getOpcode()) {
614 default: break;
615 case UnaryOperator::SizeOf:
616 case UnaryOperator::AlignOf:
617 case UnaryOperator::Real:
618 case UnaryOperator::Imag:
619 case UnaryOperator::Extension:
620 OS << ' ';
621 break;
622 }
623 }
Chris Lattner882f7882006-11-04 18:52:07 +0000624 PrintExpr(Node->getSubExpr());
Chris Lattner15768702006-11-05 23:54:51 +0000625
626 if (Node->isPostfix())
627 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattner882f7882006-11-04 18:52:07 +0000628}
Chris Lattner98dbf0a2007-08-30 17:59:59 +0000629
630bool StmtPrinter::PrintOffsetOfDesignator(Expr *E) {
631 if (isa<CompoundLiteralExpr>(E)) {
632 // Base case, print the type and comma.
633 OS << E->getType().getAsString() << ", ";
634 return true;
635 } else if (ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
636 PrintOffsetOfDesignator(ASE->getLHS());
637 OS << "[";
638 PrintExpr(ASE->getRHS());
639 OS << "]";
640 return false;
641 } else {
642 MemberExpr *ME = cast<MemberExpr>(E);
643 bool IsFirst = PrintOffsetOfDesignator(ME->getBase());
644 OS << (IsFirst ? "" : ".") << ME->getMemberDecl()->getName();
645 return false;
646 }
647}
648
649void StmtPrinter::VisitUnaryOffsetOf(UnaryOperator *Node) {
650 OS << "__builtin_offsetof(";
651 PrintOffsetOfDesignator(Node->getSubExpr());
652 OS << ")";
653}
654
Chris Lattner882f7882006-11-04 18:52:07 +0000655void StmtPrinter::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
Chris Lattner33e8a552006-11-19 01:48:02 +0000656 OS << (Node->isSizeOf() ? "sizeof(" : "__alignof(");
Chris Lattner3dc3d772007-05-16 18:07:12 +0000657 OS << Node->getArgumentType().getAsString() << ")";
Chris Lattner882f7882006-11-04 18:52:07 +0000658}
659void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
Ted Kremenekc81614d2007-08-20 16:18:38 +0000660 PrintExpr(Node->getLHS());
Chris Lattner882f7882006-11-04 18:52:07 +0000661 OS << "[";
Ted Kremenekc81614d2007-08-20 16:18:38 +0000662 PrintExpr(Node->getRHS());
Chris Lattner882f7882006-11-04 18:52:07 +0000663 OS << "]";
664}
665
666void StmtPrinter::VisitCallExpr(CallExpr *Call) {
667 PrintExpr(Call->getCallee());
668 OS << "(";
669 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000670 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
671 // Don't print any defaulted arguments
672 break;
673 }
674
Chris Lattner882f7882006-11-04 18:52:07 +0000675 if (i) OS << ", ";
676 PrintExpr(Call->getArg(i));
677 }
678 OS << ")";
679}
680void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
681 PrintExpr(Node->getBase());
682 OS << (Node->isArrow() ? "->" : ".");
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000683
Chris Lattner24e0d6c2007-05-24 00:47:01 +0000684 FieldDecl *Field = Node->getMemberDecl();
685 assert(Field && "MemberExpr should alway reference a field!");
686 OS << Field->getName();
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000687}
Nate Begemance4d7fc2008-04-18 23:10:10 +0000688void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
Steve Narofff7a5da12007-07-28 23:10:27 +0000689 PrintExpr(Node->getBase());
690 OS << ".";
691 OS << Node->getAccessor().getName();
692}
Chris Lattner882f7882006-11-04 18:52:07 +0000693void StmtPrinter::VisitCastExpr(CastExpr *Node) {
Chris Lattner51aff8b2007-07-15 23:54:50 +0000694 OS << "(" << Node->getType().getAsString() << ")";
Chris Lattner882f7882006-11-04 18:52:07 +0000695 PrintExpr(Node->getSubExpr());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000696}
Steve Naroff57eb2c52007-07-19 21:32:11 +0000697void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
698 OS << "(" << Node->getType().getAsString() << ")";
699 PrintExpr(Node->getInitializer());
700}
Steve Naroff7a5af782007-07-13 16:58:59 +0000701void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000702 // No need to print anything, simply forward to the sub expression.
703 PrintExpr(Node->getSubExpr());
Steve Naroff7a5af782007-07-13 16:58:59 +0000704}
Chris Lattner882f7882006-11-04 18:52:07 +0000705void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
706 PrintExpr(Node->getLHS());
707 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
708 PrintExpr(Node->getRHS());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000709}
Chris Lattner86928112007-08-25 02:00:02 +0000710void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
711 PrintExpr(Node->getLHS());
712 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
713 PrintExpr(Node->getRHS());
714}
Chris Lattner882f7882006-11-04 18:52:07 +0000715void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
716 PrintExpr(Node->getCond());
Ted Kremenekebb1c0c2007-11-26 18:27:54 +0000717
718 if (Node->getLHS()) {
719 OS << " ? ";
720 PrintExpr(Node->getLHS());
721 OS << " : ";
722 }
723 else { // Handle GCC extention where LHS can be NULL.
724 OS << " ?: ";
725 }
726
Chris Lattner882f7882006-11-04 18:52:07 +0000727 PrintExpr(Node->getRHS());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000728}
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000729
Chris Lattnereefa10e2007-05-28 06:56:27 +0000730// GNU extensions.
731
Chris Lattnerd268a7a2007-08-03 17:31:20 +0000732void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattnereefa10e2007-05-28 06:56:27 +0000733 OS << "&&" << Node->getLabel()->getName();
Chris Lattnereefa10e2007-05-28 06:56:27 +0000734}
735
Chris Lattner366727f2007-07-24 16:58:17 +0000736void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
737 OS << "(";
738 PrintRawCompoundStmt(E->getSubStmt());
739 OS << ")";
740}
741
Steve Naroff78864672007-08-01 22:05:33 +0000742void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
743 OS << "__builtin_types_compatible_p(";
744 OS << Node->getArgType1().getAsString() << ",";
745 OS << Node->getArgType2().getAsString() << ")";
746}
747
Steve Naroff9efdabc2007-08-03 21:21:27 +0000748void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
749 OS << "__builtin_choose_expr(";
750 PrintExpr(Node->getCond());
Chris Lattner81a96882007-08-04 00:20:15 +0000751 OS << ", ";
Steve Naroff9efdabc2007-08-03 21:21:27 +0000752 PrintExpr(Node->getLHS());
Chris Lattner81a96882007-08-04 00:20:15 +0000753 OS << ", ";
Steve Naroff9efdabc2007-08-03 21:21:27 +0000754 PrintExpr(Node->getRHS());
755 OS << ")";
756}
Chris Lattner366727f2007-07-24 16:58:17 +0000757
Nate Begeman1e36a852008-01-17 17:46:27 +0000758void StmtPrinter::VisitOverloadExpr(OverloadExpr *Node) {
759 OS << "__builtin_overload(";
Nate Begeman936b2072008-01-30 20:50:20 +0000760 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
Nate Begeman1e36a852008-01-17 17:46:27 +0000761 if (i) OS << ", ";
Nate Begeman936b2072008-01-30 20:50:20 +0000762 PrintExpr(Node->getExpr(i));
Nate Begeman1e36a852008-01-17 17:46:27 +0000763 }
764 OS << ")";
765}
766
Eli Friedmana1b4ed82008-05-14 19:38:39 +0000767void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
768 OS << "__builtin_shufflevector(";
769 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
770 if (i) OS << ", ";
771 PrintExpr(Node->getExpr(i));
772 }
773 OS << ")";
774}
775
Anders Carlsson4692db02007-08-31 04:56:16 +0000776void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
777 OS << "{ ";
778 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
779 if (i) OS << ", ";
780 PrintExpr(Node->getInit(i));
781 }
782 OS << " }";
783}
784
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000785void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
786 OS << "va_arg(";
787 PrintExpr(Node->getSubExpr());
788 OS << ", ";
789 OS << Node->getType().getAsString();
790 OS << ")";
791}
792
Chris Lattnereefa10e2007-05-28 06:56:27 +0000793// C++
794
795void StmtPrinter::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattner3f5e4682007-08-09 17:34:19 +0000796 OS << CXXCastExpr::getOpcodeStr(Node->getOpcode()) << '<';
Chris Lattnereefa10e2007-05-28 06:56:27 +0000797 OS << Node->getDestType().getAsString() << ">(";
798 PrintExpr(Node->getSubExpr());
799 OS << ")";
800}
801
802void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
803 OS << (Node->getValue() ? "true" : "false");
804}
805
Chris Lattnerb7e656b2008-02-26 00:51:44 +0000806void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
807 if (Node->getSubExpr() == 0)
808 OS << "throw";
809 else {
810 OS << "throw ";
811 PrintExpr(Node->getSubExpr());
812 }
813}
814
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000815void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
816 // Nothing to print: we picked up the default argument
817}
818
Anders Carlsson76f4a902007-08-21 17:43:55 +0000819// Obj-C
820
821void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
822 OS << "@";
823 VisitStringLiteral(Node->getString());
824}
Chris Lattnereefa10e2007-05-28 06:56:27 +0000825
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000826void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Chris Lattnerc7f39812007-10-18 00:39:29 +0000827 OS << "@encode(" << Node->getEncodedType().getAsString() << ")";
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000828}
829
Fariborz Jahanian4bef4622007-10-16 20:40:23 +0000830void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
Chris Lattnerc7f39812007-10-18 00:39:29 +0000831 OS << "@selector(" << Node->getSelector().getName() << ")";
Fariborz Jahanian4bef4622007-10-16 20:40:23 +0000832}
833
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +0000834void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
Chris Lattnerc7f39812007-10-18 00:39:29 +0000835 OS << "@protocol(" << Node->getProtocol()->getName() << ")";
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +0000836}
837
Steve Naroffd54978b2007-09-18 23:55:05 +0000838void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
839 OS << "[";
Steve Naroffc6814ea2007-10-02 20:01:56 +0000840 Expr *receiver = Mess->getReceiver();
841 if (receiver) PrintExpr(receiver);
842 else OS << Mess->getClassName()->getName();
Ted Kremeneka06e7122008-05-02 17:32:38 +0000843 OS << ' ';
Ted Kremenekb65a67d2008-04-16 04:30:16 +0000844 Selector selector = Mess->getSelector();
Steve Naroffc6814ea2007-10-02 20:01:56 +0000845 if (selector.isUnarySelector()) {
Ted Kremeneka06e7122008-05-02 17:32:38 +0000846 OS << selector.getIdentifierInfoForSlot(0)->getName();
Steve Naroffc6814ea2007-10-02 20:01:56 +0000847 } else {
848 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
Ted Kremeneka06e7122008-05-02 17:32:38 +0000849 if (i < selector.getNumArgs()) {
850 if (i > 0) OS << ' ';
851 if (selector.getIdentifierInfoForSlot(i))
852 OS << selector.getIdentifierInfoForSlot(i)->getName() << ":";
853 else
854 OS << ":";
855 }
856 else OS << ", "; // Handle variadic methods.
857
Steve Naroffc6814ea2007-10-02 20:01:56 +0000858 PrintExpr(Mess->getArg(i));
859 }
Steve Naroffd54978b2007-09-18 23:55:05 +0000860 }
861 OS << "]";
862}
863
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000864//===----------------------------------------------------------------------===//
865// Stmt method implementations
866//===----------------------------------------------------------------------===//
867
Chris Lattnercbe4f772007-08-08 22:51:59 +0000868void Stmt::dumpPretty() const {
Ted Kremenek871422e2007-11-26 22:50:46 +0000869 printPretty(*llvm::cerr.stream());
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000870}
871
Ted Kremenek04f3cee2007-08-31 21:30:12 +0000872void Stmt::printPretty(std::ostream &OS, PrinterHelper* Helper) const {
Chris Lattner882f7882006-11-04 18:52:07 +0000873 if (this == 0) {
874 OS << "<NULL>";
875 return;
876 }
877
Ted Kremenek04f3cee2007-08-31 21:30:12 +0000878 StmtPrinter P(OS, Helper);
Chris Lattner62249a62007-08-21 04:04:25 +0000879 P.Visit(const_cast<Stmt*>(this));
Chris Lattnera3bcb7a2006-11-04 07:16:25 +0000880}
Ted Kremenek04f3cee2007-08-31 21:30:12 +0000881
882//===----------------------------------------------------------------------===//
883// PrinterHelper
884//===----------------------------------------------------------------------===//
885
886// Implement virtual destructor.
Gabor Greif412af032007-09-11 15:32:40 +0000887PrinterHelper::~PrinterHelper() {}