blob: 9cc2c3af8a59f852d4d4435d6845353f7385489f [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//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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"
16#include "clang/AST/Decl.h"
17#include "clang/AST/ExprCXX.h"
Ted Kremenek08176a52007-08-31 21:30:12 +000018#include "clang/AST/PrettyPrinter.h"
Chris Lattner4b009652007-07-25 00:24:17 +000019#include "clang/Lex/IdentifierTable.h"
20#include "llvm/Support/Compiler.h"
21#include <iostream>
22#include <iomanip>
23using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// StmtPrinter Visitor
27//===----------------------------------------------------------------------===//
28
29namespace {
Chris Lattner7ba21fa2007-08-21 04:04:25 +000030 class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
Chris Lattner4b009652007-07-25 00:24:17 +000031 std::ostream &OS;
32 unsigned IndentLevel;
Ted Kremenek08176a52007-08-31 21:30:12 +000033 clang::PrinterHelper* Helper;
Chris Lattner4b009652007-07-25 00:24:17 +000034 public:
Ted Kremenek08176a52007-08-31 21:30:12 +000035 StmtPrinter(std::ostream &os, PrinterHelper* helper) :
36 OS(os), IndentLevel(0), Helper(helper) {}
Chris Lattner4b009652007-07-25 00:24:17 +000037
38 void PrintStmt(Stmt *S, int SubIndent = 1) {
39 IndentLevel += SubIndent;
40 if (S && isa<Expr>(S)) {
41 // If this is an expr used in a stmt context, indent and newline it.
42 Indent();
Chris Lattner7ba21fa2007-08-21 04:04:25 +000043 Visit(S);
Chris Lattner4b009652007-07-25 00:24:17 +000044 OS << ";\n";
45 } else if (S) {
Chris Lattner7ba21fa2007-08-21 04:04:25 +000046 Visit(S);
Chris Lattner4b009652007-07-25 00:24:17 +000047 } else {
48 Indent() << "<<<NULL STATEMENT>>>\n";
49 }
50 IndentLevel -= SubIndent;
51 }
52
53 void PrintRawCompoundStmt(CompoundStmt *S);
54 void PrintRawDecl(Decl *D);
55 void PrintRawIfStmt(IfStmt *If);
56
57 void PrintExpr(Expr *E) {
58 if (E)
Chris Lattner7ba21fa2007-08-21 04:04:25 +000059 Visit(E);
Chris Lattner4b009652007-07-25 00:24:17 +000060 else
61 OS << "<null expr>";
62 }
63
64 std::ostream &Indent(int Delta = 0) const {
65 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
66 OS << " ";
67 return OS;
68 }
69
Chris Lattner2af6a802007-08-30 17:59:59 +000070 bool PrintOffsetOfDesignator(Expr *E);
71 void VisitUnaryOffsetOf(UnaryOperator *Node);
72
Ted Kremenek08176a52007-08-31 21:30:12 +000073 void Visit(Stmt* S) {
74 if (Helper && Helper->handledStmt(S,OS))
75 return;
76 else StmtVisitor<StmtPrinter>::Visit(S);
77 }
78
Chris Lattner7ba21fa2007-08-21 04:04:25 +000079 void VisitStmt(Stmt *Node);
Chris Lattner4b009652007-07-25 00:24:17 +000080#define STMT(N, CLASS, PARENT) \
Chris Lattner7ba21fa2007-08-21 04:04:25 +000081 void Visit##CLASS(CLASS *Node);
Chris Lattner4b009652007-07-25 00:24:17 +000082#include "clang/AST/StmtNodes.def"
83 };
84}
85
86//===----------------------------------------------------------------------===//
87// Stmt printing methods.
88//===----------------------------------------------------------------------===//
89
90void StmtPrinter::VisitStmt(Stmt *Node) {
91 Indent() << "<<unknown stmt type>>\n";
92}
93
94/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
95/// with no newline after the }.
96void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
97 OS << "{\n";
98 for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
99 I != E; ++I)
100 PrintStmt(*I);
101
102 Indent() << "}";
103}
104
105void StmtPrinter::PrintRawDecl(Decl *D) {
106 // FIXME: Need to complete/beautify this... this code simply shows the
107 // nodes are where they need to be.
108 if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
109 OS << "typedef " << localType->getUnderlyingType().getAsString();
110 OS << " " << localType->getName();
111 } else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
112 // Emit storage class for vardecls.
113 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
114 switch (V->getStorageClass()) {
115 default: assert(0 && "Unknown storage class!");
116 case VarDecl::None: break;
117 case VarDecl::Extern: OS << "extern "; break;
118 case VarDecl::Static: OS << "static "; break;
119 case VarDecl::Auto: OS << "auto "; break;
120 case VarDecl::Register: OS << "register "; break;
121 }
122 }
123
124 std::string Name = VD->getName();
125 VD->getType().getAsStringInternal(Name);
126 OS << Name;
127
128 // If this is a vardecl with an initializer, emit it.
129 if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
130 if (V->getInit()) {
131 OS << " = ";
132 PrintExpr(V->getInit());
133 }
134 }
135 } else {
136 // FIXME: "struct x;"
137 assert(0 && "Unexpected decl");
138 }
139}
140
141
142void StmtPrinter::VisitNullStmt(NullStmt *Node) {
143 Indent() << ";\n";
144}
145
146void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
147 for (Decl *D = Node->getDecl(); D; D = D->getNextDeclarator()) {
148 Indent();
149 PrintRawDecl(D);
150 OS << ";\n";
151 }
152}
153
154void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
155 Indent();
156 PrintRawCompoundStmt(Node);
157 OS << "\n";
158}
159
160void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
161 Indent(-1) << "case ";
162 PrintExpr(Node->getLHS());
163 if (Node->getRHS()) {
164 OS << " ... ";
165 PrintExpr(Node->getRHS());
166 }
167 OS << ":\n";
168
169 PrintStmt(Node->getSubStmt(), 0);
170}
171
172void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
173 Indent(-1) << "default:\n";
174 PrintStmt(Node->getSubStmt(), 0);
175}
176
177void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
178 Indent(-1) << Node->getName() << ":\n";
179 PrintStmt(Node->getSubStmt(), 0);
180}
181
182void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
183 OS << "if ";
184 PrintExpr(If->getCond());
185
186 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
187 OS << ' ';
188 PrintRawCompoundStmt(CS);
189 OS << (If->getElse() ? ' ' : '\n');
190 } else {
191 OS << '\n';
192 PrintStmt(If->getThen());
193 if (If->getElse()) Indent();
194 }
195
196 if (Stmt *Else = If->getElse()) {
197 OS << "else";
198
199 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
200 OS << ' ';
201 PrintRawCompoundStmt(CS);
202 OS << '\n';
203 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
204 OS << ' ';
205 PrintRawIfStmt(ElseIf);
206 } else {
207 OS << '\n';
208 PrintStmt(If->getElse());
209 }
210 }
211}
212
213void StmtPrinter::VisitIfStmt(IfStmt *If) {
214 Indent();
215 PrintRawIfStmt(If);
216}
217
218void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
219 Indent() << "switch (";
220 PrintExpr(Node->getCond());
221 OS << ")";
222
223 // Pretty print compoundstmt bodies (very common).
224 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
225 OS << " ";
226 PrintRawCompoundStmt(CS);
227 OS << "\n";
228 } else {
229 OS << "\n";
230 PrintStmt(Node->getBody());
231 }
232}
233
234void StmtPrinter::VisitSwitchCase(SwitchCase*) {
235 assert(0 && "SwitchCase is an abstract class");
236}
237
238void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
239 Indent() << "while (";
240 PrintExpr(Node->getCond());
241 OS << ")\n";
242 PrintStmt(Node->getBody());
243}
244
245void StmtPrinter::VisitDoStmt(DoStmt *Node) {
246 Indent() << "do\n";
247 PrintStmt(Node->getBody());
248 Indent() << "while ";
249 PrintExpr(Node->getCond());
250 OS << ";\n";
251}
252
253void StmtPrinter::VisitForStmt(ForStmt *Node) {
254 Indent() << "for (";
255 if (Node->getInit()) {
256 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
257 PrintRawDecl(DS->getDecl());
258 else
259 PrintExpr(cast<Expr>(Node->getInit()));
260 }
261 OS << "; ";
262 if (Node->getCond())
263 PrintExpr(Node->getCond());
264 OS << "; ";
265 if (Node->getInc())
266 PrintExpr(Node->getInc());
267 OS << ")\n";
268 PrintStmt(Node->getBody());
269}
270
271void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
272 Indent() << "goto " << Node->getLabel()->getName() << ";\n";
273}
274
275void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
276 Indent() << "goto *";
277 PrintExpr(Node->getTarget());
278 OS << ";\n";
279}
280
281void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
282 Indent() << "continue;\n";
283}
284
285void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
286 Indent() << "break;\n";
287}
288
289
290void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
291 Indent() << "return";
292 if (Node->getRetValue()) {
293 OS << " ";
294 PrintExpr(Node->getRetValue());
295 }
296 OS << ";\n";
297}
298
299//===----------------------------------------------------------------------===//
300// Expr printing methods.
301//===----------------------------------------------------------------------===//
302
303void StmtPrinter::VisitExpr(Expr *Node) {
304 OS << "<<unknown expr type>>";
305}
306
307void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
308 OS << Node->getDecl()->getName();
309}
310
311void StmtPrinter::VisitPreDefinedExpr(PreDefinedExpr *Node) {
312 switch (Node->getIdentType()) {
313 default:
314 assert(0 && "unknown case");
315 case PreDefinedExpr::Func:
316 OS << "__func__";
317 break;
318 case PreDefinedExpr::Function:
319 OS << "__FUNCTION__";
320 break;
321 case PreDefinedExpr::PrettyFunction:
322 OS << "__PRETTY_FUNCTION__";
323 break;
324 }
325}
326
327void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
328 // FIXME should print an L for wchar_t constants
329 unsigned value = Node->getValue();
330 switch (value) {
331 case '\\':
332 OS << "'\\\\'";
333 break;
334 case '\'':
335 OS << "'\\''";
336 break;
337 case '\a':
338 // TODO: K&R: the meaning of '\\a' is different in traditional C
339 OS << "'\\a'";
340 break;
341 case '\b':
342 OS << "'\\b'";
343 break;
344 // Nonstandard escape sequence.
345 /*case '\e':
346 OS << "'\\e'";
347 break;*/
348 case '\f':
349 OS << "'\\f'";
350 break;
351 case '\n':
352 OS << "'\\n'";
353 break;
354 case '\r':
355 OS << "'\\r'";
356 break;
357 case '\t':
358 OS << "'\\t'";
359 break;
360 case '\v':
361 OS << "'\\v'";
362 break;
363 default:
364 if (isprint(value) && value < 256) {
365 OS << "'" << (char)value << "'";
366 } else if (value < 256) {
367 OS << "'\\x" << std::hex << value << std::dec << "'";
368 } else {
369 // FIXME what to really do here?
370 OS << value;
371 }
372 }
373}
374
375void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
376 bool isSigned = Node->getType()->isSignedIntegerType();
377 OS << Node->getValue().toString(10, isSigned);
378
379 // Emit suffixes. Integer literals are always a builtin integer type.
380 switch (cast<BuiltinType>(Node->getType().getCanonicalType())->getKind()) {
381 default: assert(0 && "Unexpected type for integer literal!");
382 case BuiltinType::Int: break; // no suffix.
383 case BuiltinType::UInt: OS << 'U'; break;
384 case BuiltinType::Long: OS << 'L'; break;
385 case BuiltinType::ULong: OS << "UL"; break;
386 case BuiltinType::LongLong: OS << "LL"; break;
387 case BuiltinType::ULongLong: OS << "ULL"; break;
388 }
389}
390void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
Chris Lattner6a390402007-08-01 00:23:58 +0000391 // FIXME: print value more precisely.
392 OS << Node->getValue();
Chris Lattner4b009652007-07-25 00:24:17 +0000393}
Chris Lattner1de66eb2007-08-26 03:42:43 +0000394
395void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
396 PrintExpr(Node->getSubExpr());
397 OS << "i";
398}
399
Chris Lattner4b009652007-07-25 00:24:17 +0000400void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
401 if (Str->isWide()) OS << 'L';
402 OS << '"';
403
404 // FIXME: this doesn't print wstrings right.
405 for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
406 switch (Str->getStrData()[i]) {
407 default: OS << Str->getStrData()[i]; break;
408 // Handle some common ones to make dumps prettier.
409 case '\\': OS << "\\\\"; break;
410 case '"': OS << "\\\""; break;
411 case '\n': OS << "\\n"; break;
412 case '\t': OS << "\\t"; break;
413 case '\a': OS << "\\a"; break;
414 case '\b': OS << "\\b"; break;
415 }
416 }
417 OS << '"';
418}
419void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
420 OS << "(";
421 PrintExpr(Node->getSubExpr());
422 OS << ")";
423}
424void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
Chris Lattner2b97b092007-08-23 21:46:40 +0000425 if (!Node->isPostfix()) {
Chris Lattner4b009652007-07-25 00:24:17 +0000426 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattner2b97b092007-08-23 21:46:40 +0000427
428 // Print a space if this is an "identifier operator" like sizeof or __real.
429 switch (Node->getOpcode()) {
430 default: break;
431 case UnaryOperator::SizeOf:
432 case UnaryOperator::AlignOf:
433 case UnaryOperator::Real:
434 case UnaryOperator::Imag:
435 case UnaryOperator::Extension:
436 OS << ' ';
437 break;
438 }
439 }
Chris Lattner4b009652007-07-25 00:24:17 +0000440 PrintExpr(Node->getSubExpr());
441
442 if (Node->isPostfix())
443 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
Chris Lattner4b009652007-07-25 00:24:17 +0000444}
Chris Lattner2af6a802007-08-30 17:59:59 +0000445
446bool StmtPrinter::PrintOffsetOfDesignator(Expr *E) {
447 if (isa<CompoundLiteralExpr>(E)) {
448 // Base case, print the type and comma.
449 OS << E->getType().getAsString() << ", ";
450 return true;
451 } else if (ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
452 PrintOffsetOfDesignator(ASE->getLHS());
453 OS << "[";
454 PrintExpr(ASE->getRHS());
455 OS << "]";
456 return false;
457 } else {
458 MemberExpr *ME = cast<MemberExpr>(E);
459 bool IsFirst = PrintOffsetOfDesignator(ME->getBase());
460 OS << (IsFirst ? "" : ".") << ME->getMemberDecl()->getName();
461 return false;
462 }
463}
464
465void StmtPrinter::VisitUnaryOffsetOf(UnaryOperator *Node) {
466 OS << "__builtin_offsetof(";
467 PrintOffsetOfDesignator(Node->getSubExpr());
468 OS << ")";
469}
470
Chris Lattner4b009652007-07-25 00:24:17 +0000471void StmtPrinter::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
472 OS << (Node->isSizeOf() ? "sizeof(" : "__alignof(");
473 OS << Node->getArgumentType().getAsString() << ")";
474}
475void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
Ted Kremenek1c1700f2007-08-20 16:18:38 +0000476 PrintExpr(Node->getLHS());
Chris Lattner4b009652007-07-25 00:24:17 +0000477 OS << "[";
Ted Kremenek1c1700f2007-08-20 16:18:38 +0000478 PrintExpr(Node->getRHS());
Chris Lattner4b009652007-07-25 00:24:17 +0000479 OS << "]";
480}
481
482void StmtPrinter::VisitCallExpr(CallExpr *Call) {
483 PrintExpr(Call->getCallee());
484 OS << "(";
485 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
486 if (i) OS << ", ";
487 PrintExpr(Call->getArg(i));
488 }
489 OS << ")";
490}
491void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
492 PrintExpr(Node->getBase());
493 OS << (Node->isArrow() ? "->" : ".");
494
495 FieldDecl *Field = Node->getMemberDecl();
496 assert(Field && "MemberExpr should alway reference a field!");
497 OS << Field->getName();
498}
Chris Lattnera0d03a72007-08-03 17:31:20 +0000499void StmtPrinter::VisitOCUVectorElementExpr(OCUVectorElementExpr *Node) {
Steve Naroffc11705f2007-07-28 23:10:27 +0000500 PrintExpr(Node->getBase());
501 OS << ".";
502 OS << Node->getAccessor().getName();
503}
Chris Lattner4b009652007-07-25 00:24:17 +0000504void StmtPrinter::VisitCastExpr(CastExpr *Node) {
505 OS << "(" << Node->getType().getAsString() << ")";
506 PrintExpr(Node->getSubExpr());
507}
508void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
509 OS << "(" << Node->getType().getAsString() << ")";
510 PrintExpr(Node->getInitializer());
511}
512void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
513 // No need to print anything, simply forward to the sub expression.
514 PrintExpr(Node->getSubExpr());
515}
516void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
517 PrintExpr(Node->getLHS());
518 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
519 PrintExpr(Node->getRHS());
520}
Chris Lattner06078d22007-08-25 02:00:02 +0000521void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
522 PrintExpr(Node->getLHS());
523 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
524 PrintExpr(Node->getRHS());
525}
Chris Lattner4b009652007-07-25 00:24:17 +0000526void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
527 PrintExpr(Node->getCond());
528 OS << " ? ";
529 PrintExpr(Node->getLHS());
530 OS << " : ";
531 PrintExpr(Node->getRHS());
532}
533
534// GNU extensions.
535
Chris Lattnera0d03a72007-08-03 17:31:20 +0000536void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
Chris Lattner4b009652007-07-25 00:24:17 +0000537 OS << "&&" << Node->getLabel()->getName();
538}
539
540void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
541 OS << "(";
542 PrintRawCompoundStmt(E->getSubStmt());
543 OS << ")";
544}
545
Steve Naroff63bad2d2007-08-01 22:05:33 +0000546void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
547 OS << "__builtin_types_compatible_p(";
548 OS << Node->getArgType1().getAsString() << ",";
549 OS << Node->getArgType2().getAsString() << ")";
550}
551
Steve Naroff93c53012007-08-03 21:21:27 +0000552void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
553 OS << "__builtin_choose_expr(";
554 PrintExpr(Node->getCond());
Chris Lattner44fcf4f2007-08-04 00:20:15 +0000555 OS << ", ";
Steve Naroff93c53012007-08-03 21:21:27 +0000556 PrintExpr(Node->getLHS());
Chris Lattner44fcf4f2007-08-04 00:20:15 +0000557 OS << ", ";
Steve Naroff93c53012007-08-03 21:21:27 +0000558 PrintExpr(Node->getRHS());
559 OS << ")";
560}
Chris Lattner4b009652007-07-25 00:24:17 +0000561
Anders Carlsson762b7c72007-08-31 04:56:16 +0000562void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
563 OS << "{ ";
564 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
565 if (i) OS << ", ";
566 PrintExpr(Node->getInit(i));
567 }
568 OS << " }";
569}
570
Chris Lattner4b009652007-07-25 00:24:17 +0000571// C++
572
573void StmtPrinter::VisitCXXCastExpr(CXXCastExpr *Node) {
Chris Lattnerac485c12007-08-09 17:34:19 +0000574 OS << CXXCastExpr::getOpcodeStr(Node->getOpcode()) << '<';
Chris Lattner4b009652007-07-25 00:24:17 +0000575 OS << Node->getDestType().getAsString() << ">(";
576 PrintExpr(Node->getSubExpr());
577 OS << ")";
578}
579
580void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
581 OS << (Node->getValue() ? "true" : "false");
582}
583
Anders Carlssona66cad42007-08-21 17:43:55 +0000584// Obj-C
585
586void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
587 OS << "@";
588 VisitStringLiteral(Node->getString());
589}
Chris Lattner4b009652007-07-25 00:24:17 +0000590
Anders Carlsson8be1d402007-08-22 15:14:15 +0000591void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
592 OS << "@encode(";
593 OS << Node->getEncodedType().getAsString() << ")";
594}
595
Chris Lattner4b009652007-07-25 00:24:17 +0000596//===----------------------------------------------------------------------===//
597// Stmt method implementations
598//===----------------------------------------------------------------------===//
599
Chris Lattner95578782007-08-08 22:51:59 +0000600void Stmt::dumpPretty() const {
Chris Lattner4b009652007-07-25 00:24:17 +0000601 // FIXME: eliminate use of <iostream>
Chris Lattner95578782007-08-08 22:51:59 +0000602 printPretty(std::cerr);
Chris Lattner4b009652007-07-25 00:24:17 +0000603}
604
Ted Kremenek08176a52007-08-31 21:30:12 +0000605void Stmt::printPretty(std::ostream &OS, PrinterHelper* Helper) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000606 if (this == 0) {
607 OS << "<NULL>";
608 return;
609 }
610
Ted Kremenek08176a52007-08-31 21:30:12 +0000611 StmtPrinter P(OS, Helper);
Chris Lattner7ba21fa2007-08-21 04:04:25 +0000612 P.Visit(const_cast<Stmt*>(this));
Chris Lattner4b009652007-07-25 00:24:17 +0000613}
Ted Kremenek08176a52007-08-31 21:30:12 +0000614
615//===----------------------------------------------------------------------===//
616// PrinterHelper
617//===----------------------------------------------------------------------===//
618
619// Implement virtual destructor.
Gabor Greif61ce98c2007-09-11 15:32:40 +0000620PrinterHelper::~PrinterHelper() {}