1 //===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
11 // pretty print the AST back out to C code.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Attr.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclTemplate.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.h"
22 #include "clang/AST/PrettyPrinter.h"
23 #include "clang/AST/StmtVisitor.h"
24 #include "clang/Basic/CharInfo.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/Support/Format.h"
27 using namespace clang;
28 
29 //===----------------------------------------------------------------------===//
30 // StmtPrinter Visitor
31 //===----------------------------------------------------------------------===//
32 
33 namespace  {
34   class StmtPrinter : public StmtVisitor<StmtPrinter> {
35     raw_ostream &OS;
36     unsigned IndentLevel;
37     clang::PrinterHelper* Helper;
38     PrintingPolicy Policy;
39 
40   public:
41     StmtPrinter(raw_ostream &os, PrinterHelper* helper,
42                 const PrintingPolicy &Policy,
43                 unsigned Indentation = 0)
44       : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
45 
46     void PrintStmt(Stmt *S) {
47       PrintStmt(S, Policy.Indentation);
48     }
49 
50     void PrintStmt(Stmt *S, int SubIndent) {
51       IndentLevel += SubIndent;
52       if (S && isa<Expr>(S)) {
53         // If this is an expr used in a stmt context, indent and newline it.
54         Indent();
55         Visit(S);
56         OS << ";\n";
57       } else if (S) {
58         Visit(S);
59       } else {
60         Indent() << "<<<NULL STATEMENT>>>\n";
61       }
62       IndentLevel -= SubIndent;
63     }
64 
65     void PrintRawCompoundStmt(CompoundStmt *S);
66     void PrintRawDecl(Decl *D);
67     void PrintRawDeclStmt(const DeclStmt *S);
68     void PrintRawIfStmt(IfStmt *If);
69     void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
70     void PrintCallArgs(CallExpr *E);
71     void PrintRawSEHExceptHandler(SEHExceptStmt *S);
72     void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
73 
74     void PrintExpr(Expr *E) {
75       if (E)
76         Visit(E);
77       else
78         OS << "<null expr>";
79     }
80 
81     raw_ostream &Indent(int Delta = 0) {
82       for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
83         OS << "  ";
84       return OS;
85     }
86 
87     void Visit(Stmt* S) {
88       if (Helper && Helper->handledStmt(S,OS))
89           return;
90       else StmtVisitor<StmtPrinter>::Visit(S);
91     }
92 
93     void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
94       Indent() << "<<unknown stmt type>>\n";
95     }
96     void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
97       OS << "<<unknown expr type>>";
98     }
99     void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
100 
101 #define ABSTRACT_STMT(CLASS)
102 #define STMT(CLASS, PARENT) \
103     void Visit##CLASS(CLASS *Node);
104 #include "clang/AST/StmtNodes.inc"
105   };
106 }
107 
108 //===----------------------------------------------------------------------===//
109 //  Stmt printing methods.
110 //===----------------------------------------------------------------------===//
111 
112 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
113 /// with no newline after the }.
114 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
115   OS << "{\n";
116   for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
117        I != E; ++I)
118     PrintStmt(*I);
119 
120   Indent() << "}";
121 }
122 
123 void StmtPrinter::PrintRawDecl(Decl *D) {
124   D->print(OS, Policy, IndentLevel);
125 }
126 
127 void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
128   DeclStmt::const_decl_iterator Begin = S->decl_begin(), End = S->decl_end();
129   SmallVector<Decl*, 2> Decls;
130   for ( ; Begin != End; ++Begin)
131     Decls.push_back(*Begin);
132 
133   Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
134 }
135 
136 void StmtPrinter::VisitNullStmt(NullStmt *Node) {
137   Indent() << ";\n";
138 }
139 
140 void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
141   Indent();
142   PrintRawDeclStmt(Node);
143   OS << ";\n";
144 }
145 
146 void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
147   Indent();
148   PrintRawCompoundStmt(Node);
149   OS << "\n";
150 }
151 
152 void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
153   Indent(-1) << "case ";
154   PrintExpr(Node->getLHS());
155   if (Node->getRHS()) {
156     OS << " ... ";
157     PrintExpr(Node->getRHS());
158   }
159   OS << ":\n";
160 
161   PrintStmt(Node->getSubStmt(), 0);
162 }
163 
164 void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
165   Indent(-1) << "default:\n";
166   PrintStmt(Node->getSubStmt(), 0);
167 }
168 
169 void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
170   Indent(-1) << Node->getName() << ":\n";
171   PrintStmt(Node->getSubStmt(), 0);
172 }
173 
174 void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
175   OS << "[[";
176   bool first = true;
177   for (ArrayRef<const Attr*>::iterator it = Node->getAttrs().begin(),
178                                        end = Node->getAttrs().end();
179                                        it != end; ++it) {
180     if (!first) {
181       OS << ", ";
182       first = false;
183     }
184     // TODO: check this
185     (*it)->printPretty(OS, Policy);
186   }
187   OS << "]] ";
188   PrintStmt(Node->getSubStmt(), 0);
189 }
190 
191 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
192   OS << "if (";
193   if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
194     PrintRawDeclStmt(DS);
195   else
196     PrintExpr(If->getCond());
197   OS << ')';
198 
199   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
200     OS << ' ';
201     PrintRawCompoundStmt(CS);
202     OS << (If->getElse() ? ' ' : '\n');
203   } else {
204     OS << '\n';
205     PrintStmt(If->getThen());
206     if (If->getElse()) Indent();
207   }
208 
209   if (Stmt *Else = If->getElse()) {
210     OS << "else";
211 
212     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
213       OS << ' ';
214       PrintRawCompoundStmt(CS);
215       OS << '\n';
216     } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
217       OS << ' ';
218       PrintRawIfStmt(ElseIf);
219     } else {
220       OS << '\n';
221       PrintStmt(If->getElse());
222     }
223   }
224 }
225 
226 void StmtPrinter::VisitIfStmt(IfStmt *If) {
227   Indent();
228   PrintRawIfStmt(If);
229 }
230 
231 void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
232   Indent() << "switch (";
233   if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
234     PrintRawDeclStmt(DS);
235   else
236     PrintExpr(Node->getCond());
237   OS << ")";
238 
239   // Pretty print compoundstmt bodies (very common).
240   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
241     OS << " ";
242     PrintRawCompoundStmt(CS);
243     OS << "\n";
244   } else {
245     OS << "\n";
246     PrintStmt(Node->getBody());
247   }
248 }
249 
250 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
251   Indent() << "while (";
252   if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
253     PrintRawDeclStmt(DS);
254   else
255     PrintExpr(Node->getCond());
256   OS << ")\n";
257   PrintStmt(Node->getBody());
258 }
259 
260 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
261   Indent() << "do ";
262   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
263     PrintRawCompoundStmt(CS);
264     OS << " ";
265   } else {
266     OS << "\n";
267     PrintStmt(Node->getBody());
268     Indent();
269   }
270 
271   OS << "while (";
272   PrintExpr(Node->getCond());
273   OS << ");\n";
274 }
275 
276 void StmtPrinter::VisitForStmt(ForStmt *Node) {
277   Indent() << "for (";
278   if (Node->getInit()) {
279     if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
280       PrintRawDeclStmt(DS);
281     else
282       PrintExpr(cast<Expr>(Node->getInit()));
283   }
284   OS << ";";
285   if (Node->getCond()) {
286     OS << " ";
287     PrintExpr(Node->getCond());
288   }
289   OS << ";";
290   if (Node->getInc()) {
291     OS << " ";
292     PrintExpr(Node->getInc());
293   }
294   OS << ") ";
295 
296   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
297     PrintRawCompoundStmt(CS);
298     OS << "\n";
299   } else {
300     OS << "\n";
301     PrintStmt(Node->getBody());
302   }
303 }
304 
305 void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
306   Indent() << "for (";
307   if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
308     PrintRawDeclStmt(DS);
309   else
310     PrintExpr(cast<Expr>(Node->getElement()));
311   OS << " in ";
312   PrintExpr(Node->getCollection());
313   OS << ") ";
314 
315   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
316     PrintRawCompoundStmt(CS);
317     OS << "\n";
318   } else {
319     OS << "\n";
320     PrintStmt(Node->getBody());
321   }
322 }
323 
324 void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
325   Indent() << "for (";
326   PrintingPolicy SubPolicy(Policy);
327   SubPolicy.SuppressInitializers = true;
328   Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
329   OS << " : ";
330   PrintExpr(Node->getRangeInit());
331   OS << ") {\n";
332   PrintStmt(Node->getBody());
333   Indent() << "}";
334   if (Policy.IncludeNewlines) OS << "\n";
335 }
336 
337 void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
338   Indent();
339   if (Node->isIfExists())
340     OS << "__if_exists (";
341   else
342     OS << "__if_not_exists (";
343 
344   if (NestedNameSpecifier *Qualifier
345         = Node->getQualifierLoc().getNestedNameSpecifier())
346     Qualifier->print(OS, Policy);
347 
348   OS << Node->getNameInfo() << ") ";
349 
350   PrintRawCompoundStmt(Node->getSubStmt());
351 }
352 
353 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
354   Indent() << "goto " << Node->getLabel()->getName() << ";";
355   if (Policy.IncludeNewlines) OS << "\n";
356 }
357 
358 void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
359   Indent() << "goto *";
360   PrintExpr(Node->getTarget());
361   OS << ";";
362   if (Policy.IncludeNewlines) OS << "\n";
363 }
364 
365 void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
366   Indent() << "continue;";
367   if (Policy.IncludeNewlines) OS << "\n";
368 }
369 
370 void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
371   Indent() << "break;";
372   if (Policy.IncludeNewlines) OS << "\n";
373 }
374 
375 
376 void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
377   Indent() << "return";
378   if (Node->getRetValue()) {
379     OS << " ";
380     PrintExpr(Node->getRetValue());
381   }
382   OS << ";";
383   if (Policy.IncludeNewlines) OS << "\n";
384 }
385 
386 
387 void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
388   Indent() << "asm ";
389 
390   if (Node->isVolatile())
391     OS << "volatile ";
392 
393   OS << "(";
394   VisitStringLiteral(Node->getAsmString());
395 
396   // Outputs
397   if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
398       Node->getNumClobbers() != 0)
399     OS << " : ";
400 
401   for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
402     if (i != 0)
403       OS << ", ";
404 
405     if (!Node->getOutputName(i).empty()) {
406       OS << '[';
407       OS << Node->getOutputName(i);
408       OS << "] ";
409     }
410 
411     VisitStringLiteral(Node->getOutputConstraintLiteral(i));
412     OS << " ";
413     Visit(Node->getOutputExpr(i));
414   }
415 
416   // Inputs
417   if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
418     OS << " : ";
419 
420   for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
421     if (i != 0)
422       OS << ", ";
423 
424     if (!Node->getInputName(i).empty()) {
425       OS << '[';
426       OS << Node->getInputName(i);
427       OS << "] ";
428     }
429 
430     VisitStringLiteral(Node->getInputConstraintLiteral(i));
431     OS << " ";
432     Visit(Node->getInputExpr(i));
433   }
434 
435   // Clobbers
436   if (Node->getNumClobbers() != 0)
437     OS << " : ";
438 
439   for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
440     if (i != 0)
441       OS << ", ";
442 
443     VisitStringLiteral(Node->getClobberStringLiteral(i));
444   }
445 
446   OS << ");";
447   if (Policy.IncludeNewlines) OS << "\n";
448 }
449 
450 void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
451   // FIXME: Implement MS style inline asm statement printer.
452   Indent() << "__asm ";
453   if (Node->hasBraces())
454     OS << "{\n";
455   OS << Node->getAsmString() << "\n";
456   if (Node->hasBraces())
457     Indent() << "}\n";
458 }
459 
460 void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
461   PrintStmt(Node->getCapturedDecl()->getBody());
462 }
463 
464 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
465   Indent() << "@try";
466   if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
467     PrintRawCompoundStmt(TS);
468     OS << "\n";
469   }
470 
471   for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
472     ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
473     Indent() << "@catch(";
474     if (catchStmt->getCatchParamDecl()) {
475       if (Decl *DS = catchStmt->getCatchParamDecl())
476         PrintRawDecl(DS);
477     }
478     OS << ")";
479     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
480       PrintRawCompoundStmt(CS);
481       OS << "\n";
482     }
483   }
484 
485   if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
486         Node->getFinallyStmt())) {
487     Indent() << "@finally";
488     PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
489     OS << "\n";
490   }
491 }
492 
493 void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
494 }
495 
496 void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
497   Indent() << "@catch (...) { /* todo */ } \n";
498 }
499 
500 void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
501   Indent() << "@throw";
502   if (Node->getThrowExpr()) {
503     OS << " ";
504     PrintExpr(Node->getThrowExpr());
505   }
506   OS << ";\n";
507 }
508 
509 void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
510   Indent() << "@synchronized (";
511   PrintExpr(Node->getSynchExpr());
512   OS << ")";
513   PrintRawCompoundStmt(Node->getSynchBody());
514   OS << "\n";
515 }
516 
517 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
518   Indent() << "@autoreleasepool";
519   PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
520   OS << "\n";
521 }
522 
523 void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
524   OS << "catch (";
525   if (Decl *ExDecl = Node->getExceptionDecl())
526     PrintRawDecl(ExDecl);
527   else
528     OS << "...";
529   OS << ") ";
530   PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
531 }
532 
533 void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
534   Indent();
535   PrintRawCXXCatchStmt(Node);
536   OS << "\n";
537 }
538 
539 void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
540   Indent() << "try ";
541   PrintRawCompoundStmt(Node->getTryBlock());
542   for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
543     OS << " ";
544     PrintRawCXXCatchStmt(Node->getHandler(i));
545   }
546   OS << "\n";
547 }
548 
549 void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
550   Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
551   PrintRawCompoundStmt(Node->getTryBlock());
552   SEHExceptStmt *E = Node->getExceptHandler();
553   SEHFinallyStmt *F = Node->getFinallyHandler();
554   if(E)
555     PrintRawSEHExceptHandler(E);
556   else {
557     assert(F && "Must have a finally block...");
558     PrintRawSEHFinallyStmt(F);
559   }
560   OS << "\n";
561 }
562 
563 void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
564   OS << "__finally ";
565   PrintRawCompoundStmt(Node->getBlock());
566   OS << "\n";
567 }
568 
569 void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
570   OS << "__except (";
571   VisitExpr(Node->getFilterExpr());
572   OS << ")\n";
573   PrintRawCompoundStmt(Node->getBlock());
574   OS << "\n";
575 }
576 
577 void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
578   Indent();
579   PrintRawSEHExceptHandler(Node);
580   OS << "\n";
581 }
582 
583 void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
584   Indent();
585   PrintRawSEHFinallyStmt(Node);
586   OS << "\n";
587 }
588 
589 //===----------------------------------------------------------------------===//
590 //  OpenMP clauses printing methods
591 //===----------------------------------------------------------------------===//
592 
593 namespace {
594 class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
595   raw_ostream &OS;
596   /// \brief Process clauses with list of variables.
597   template <typename T>
598   void VisitOMPClauseList(T *Node, char StartSym);
599 public:
600   OMPClausePrinter(raw_ostream &OS) : OS(OS) { }
601 #define OPENMP_CLAUSE(Name, Class)                              \
602   void Visit##Class(Class *S);
603 #include "clang/Basic/OpenMPKinds.def"
604 };
605 
606 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
607   OS << "default("
608      << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
609      << ")";
610 }
611 
612 template<typename T>
613 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
614   for (typename T::varlist_iterator I = Node->varlist_begin(),
615                                     E = Node->varlist_end();
616          I != E; ++I)
617     OS << (I == Node->varlist_begin() ? StartSym : ',')
618        << *cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
619 }
620 
621 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
622   if (!Node->varlist_empty()) {
623     OS << "private";
624     VisitOMPClauseList(Node, '(');
625     OS << ")";
626   }
627 }
628 
629 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
630   if (!Node->varlist_empty()) {
631     OS << "firstprivate";
632     VisitOMPClauseList(Node, '(');
633     OS << ")";
634   }
635 }
636 
637 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
638   if (!Node->varlist_empty()) {
639     OS << "shared";
640     VisitOMPClauseList(Node, '(');
641     OS << ")";
642   }
643 }
644 
645 }
646 
647 //===----------------------------------------------------------------------===//
648 //  OpenMP directives printing methods
649 //===----------------------------------------------------------------------===//
650 
651 void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
652   Indent() << "#pragma omp parallel ";
653 
654   OMPClausePrinter Printer(OS);
655   ArrayRef<OMPClause *> Clauses = Node->clauses();
656   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
657        I != E; ++I)
658     if (*I && !(*I)->isImplicit()) {
659       Printer.Visit(*I);
660       OS << ' ';
661     }
662   OS << "\n";
663   if (Node->getAssociatedStmt()) {
664     assert(isa<CapturedStmt>(Node->getAssociatedStmt()) &&
665            "Expected captured statement!");
666     Stmt *CS = cast<CapturedStmt>(Node->getAssociatedStmt())->getCapturedStmt();
667     PrintStmt(CS);
668   }
669 }
670 //===----------------------------------------------------------------------===//
671 //  Expr printing methods.
672 //===----------------------------------------------------------------------===//
673 
674 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
675   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
676     Qualifier->print(OS, Policy);
677   if (Node->hasTemplateKeyword())
678     OS << "template ";
679   OS << Node->getNameInfo();
680   if (Node->hasExplicitTemplateArgs())
681     TemplateSpecializationType::PrintTemplateArgumentList(
682         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
683 }
684 
685 void StmtPrinter::VisitDependentScopeDeclRefExpr(
686                                            DependentScopeDeclRefExpr *Node) {
687   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
688     Qualifier->print(OS, Policy);
689   if (Node->hasTemplateKeyword())
690     OS << "template ";
691   OS << Node->getNameInfo();
692   if (Node->hasExplicitTemplateArgs())
693     TemplateSpecializationType::PrintTemplateArgumentList(
694         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
695 }
696 
697 void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
698   if (Node->getQualifier())
699     Node->getQualifier()->print(OS, Policy);
700   if (Node->hasTemplateKeyword())
701     OS << "template ";
702   OS << Node->getNameInfo();
703   if (Node->hasExplicitTemplateArgs())
704     TemplateSpecializationType::PrintTemplateArgumentList(
705         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
706 }
707 
708 void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
709   if (Node->getBase()) {
710     PrintExpr(Node->getBase());
711     OS << (Node->isArrow() ? "->" : ".");
712   }
713   OS << *Node->getDecl();
714 }
715 
716 void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
717   if (Node->isSuperReceiver())
718     OS << "super.";
719   else if (Node->getBase()) {
720     PrintExpr(Node->getBase());
721     OS << ".";
722   }
723 
724   if (Node->isImplicitProperty())
725     Node->getImplicitPropertyGetter()->getSelector().print(OS);
726   else
727     OS << Node->getExplicitProperty()->getName();
728 }
729 
730 void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
731 
732   PrintExpr(Node->getBaseExpr());
733   OS << "[";
734   PrintExpr(Node->getKeyExpr());
735   OS << "]";
736 }
737 
738 void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
739   switch (Node->getIdentType()) {
740     default:
741       llvm_unreachable("unknown case");
742     case PredefinedExpr::Func:
743       OS << "__func__";
744       break;
745     case PredefinedExpr::Function:
746       OS << "__FUNCTION__";
747       break;
748     case PredefinedExpr::FuncDName:
749       OS << "__FUNCDNAME__";
750       break;
751     case PredefinedExpr::LFunction:
752       OS << "L__FUNCTION__";
753       break;
754     case PredefinedExpr::PrettyFunction:
755       OS << "__PRETTY_FUNCTION__";
756       break;
757   }
758 }
759 
760 void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
761   unsigned value = Node->getValue();
762 
763   switch (Node->getKind()) {
764   case CharacterLiteral::Ascii: break; // no prefix.
765   case CharacterLiteral::Wide:  OS << 'L'; break;
766   case CharacterLiteral::UTF16: OS << 'u'; break;
767   case CharacterLiteral::UTF32: OS << 'U'; break;
768   }
769 
770   switch (value) {
771   case '\\':
772     OS << "'\\\\'";
773     break;
774   case '\'':
775     OS << "'\\''";
776     break;
777   case '\a':
778     // TODO: K&R: the meaning of '\\a' is different in traditional C
779     OS << "'\\a'";
780     break;
781   case '\b':
782     OS << "'\\b'";
783     break;
784   // Nonstandard escape sequence.
785   /*case '\e':
786     OS << "'\\e'";
787     break;*/
788   case '\f':
789     OS << "'\\f'";
790     break;
791   case '\n':
792     OS << "'\\n'";
793     break;
794   case '\r':
795     OS << "'\\r'";
796     break;
797   case '\t':
798     OS << "'\\t'";
799     break;
800   case '\v':
801     OS << "'\\v'";
802     break;
803   default:
804     if (value < 256 && isPrintable((unsigned char)value))
805       OS << "'" << (char)value << "'";
806     else if (value < 256)
807       OS << "'\\x" << llvm::format("%02x", value) << "'";
808     else if (value <= 0xFFFF)
809       OS << "'\\u" << llvm::format("%04x", value) << "'";
810     else
811       OS << "'\\U" << llvm::format("%08x", value) << "'";
812   }
813 }
814 
815 void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
816   bool isSigned = Node->getType()->isSignedIntegerType();
817   OS << Node->getValue().toString(10, isSigned);
818 
819   // Emit suffixes.  Integer literals are always a builtin integer type.
820   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
821   default: llvm_unreachable("Unexpected type for integer literal!");
822   // FIXME: The Short and UShort cases are to handle cases where a short
823   // integeral literal is formed during template instantiation.  They should
824   // be removed when template instantiation no longer needs integer literals.
825   case BuiltinType::Short:
826   case BuiltinType::UShort:
827   case BuiltinType::Int:       break; // no suffix.
828   case BuiltinType::UInt:      OS << 'U'; break;
829   case BuiltinType::Long:      OS << 'L'; break;
830   case BuiltinType::ULong:     OS << "UL"; break;
831   case BuiltinType::LongLong:  OS << "LL"; break;
832   case BuiltinType::ULongLong: OS << "ULL"; break;
833   case BuiltinType::Int128:    OS << "i128"; break;
834   case BuiltinType::UInt128:   OS << "Ui128"; break;
835   }
836 }
837 
838 static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
839                                  bool PrintSuffix) {
840   SmallString<16> Str;
841   Node->getValue().toString(Str);
842   OS << Str;
843   if (Str.find_first_not_of("-0123456789") == StringRef::npos)
844     OS << '.'; // Trailing dot in order to separate from ints.
845 
846   if (!PrintSuffix)
847     return;
848 
849   // Emit suffixes.  Float literals are always a builtin float type.
850   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
851   default: llvm_unreachable("Unexpected type for float literal!");
852   case BuiltinType::Half:       break; // FIXME: suffix?
853   case BuiltinType::Double:     break; // no suffix.
854   case BuiltinType::Float:      OS << 'F'; break;
855   case BuiltinType::LongDouble: OS << 'L'; break;
856   }
857 }
858 
859 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
860   PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
861 }
862 
863 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
864   PrintExpr(Node->getSubExpr());
865   OS << "i";
866 }
867 
868 void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
869   Str->outputString(OS);
870 }
871 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
872   OS << "(";
873   PrintExpr(Node->getSubExpr());
874   OS << ")";
875 }
876 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
877   if (!Node->isPostfix()) {
878     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
879 
880     // Print a space if this is an "identifier operator" like __real, or if
881     // it might be concatenated incorrectly like '+'.
882     switch (Node->getOpcode()) {
883     default: break;
884     case UO_Real:
885     case UO_Imag:
886     case UO_Extension:
887       OS << ' ';
888       break;
889     case UO_Plus:
890     case UO_Minus:
891       if (isa<UnaryOperator>(Node->getSubExpr()))
892         OS << ' ';
893       break;
894     }
895   }
896   PrintExpr(Node->getSubExpr());
897 
898   if (Node->isPostfix())
899     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
900 }
901 
902 void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
903   OS << "__builtin_offsetof(";
904   Node->getTypeSourceInfo()->getType().print(OS, Policy);
905   OS << ", ";
906   bool PrintedSomething = false;
907   for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
908     OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
909     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
910       // Array node
911       OS << "[";
912       PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
913       OS << "]";
914       PrintedSomething = true;
915       continue;
916     }
917 
918     // Skip implicit base indirections.
919     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
920       continue;
921 
922     // Field or identifier node.
923     IdentifierInfo *Id = ON.getFieldName();
924     if (!Id)
925       continue;
926 
927     if (PrintedSomething)
928       OS << ".";
929     else
930       PrintedSomething = true;
931     OS << Id->getName();
932   }
933   OS << ")";
934 }
935 
936 void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
937   switch(Node->getKind()) {
938   case UETT_SizeOf:
939     OS << "sizeof";
940     break;
941   case UETT_AlignOf:
942     if (Policy.LangOpts.CPlusPlus)
943       OS << "alignof";
944     else if (Policy.LangOpts.C11)
945       OS << "_Alignof";
946     else
947       OS << "__alignof";
948     break;
949   case UETT_VecStep:
950     OS << "vec_step";
951     break;
952   }
953   if (Node->isArgumentType()) {
954     OS << '(';
955     Node->getArgumentType().print(OS, Policy);
956     OS << ')';
957   } else {
958     OS << " ";
959     PrintExpr(Node->getArgumentExpr());
960   }
961 }
962 
963 void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
964   OS << "_Generic(";
965   PrintExpr(Node->getControllingExpr());
966   for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
967     OS << ", ";
968     QualType T = Node->getAssocType(i);
969     if (T.isNull())
970       OS << "default";
971     else
972       T.print(OS, Policy);
973     OS << ": ";
974     PrintExpr(Node->getAssocExpr(i));
975   }
976   OS << ")";
977 }
978 
979 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
980   PrintExpr(Node->getLHS());
981   OS << "[";
982   PrintExpr(Node->getRHS());
983   OS << "]";
984 }
985 
986 void StmtPrinter::PrintCallArgs(CallExpr *Call) {
987   for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
988     if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
989       // Don't print any defaulted arguments
990       break;
991     }
992 
993     if (i) OS << ", ";
994     PrintExpr(Call->getArg(i));
995   }
996 }
997 
998 void StmtPrinter::VisitCallExpr(CallExpr *Call) {
999   PrintExpr(Call->getCallee());
1000   OS << "(";
1001   PrintCallArgs(Call);
1002   OS << ")";
1003 }
1004 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1005   // FIXME: Suppress printing implicit bases (like "this")
1006   PrintExpr(Node->getBase());
1007 
1008   MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1009   FieldDecl  *ParentDecl   = ParentMember
1010     ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : NULL;
1011 
1012   if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1013     OS << (Node->isArrow() ? "->" : ".");
1014 
1015   if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1016     if (FD->isAnonymousStructOrUnion())
1017       return;
1018 
1019   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1020     Qualifier->print(OS, Policy);
1021   if (Node->hasTemplateKeyword())
1022     OS << "template ";
1023   OS << Node->getMemberNameInfo();
1024   if (Node->hasExplicitTemplateArgs())
1025     TemplateSpecializationType::PrintTemplateArgumentList(
1026         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1027 }
1028 void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1029   PrintExpr(Node->getBase());
1030   OS << (Node->isArrow() ? "->isa" : ".isa");
1031 }
1032 
1033 void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1034   PrintExpr(Node->getBase());
1035   OS << ".";
1036   OS << Node->getAccessor().getName();
1037 }
1038 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1039   OS << '(';
1040   Node->getTypeAsWritten().print(OS, Policy);
1041   OS << ')';
1042   PrintExpr(Node->getSubExpr());
1043 }
1044 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1045   OS << '(';
1046   Node->getType().print(OS, Policy);
1047   OS << ')';
1048   PrintExpr(Node->getInitializer());
1049 }
1050 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1051   // No need to print anything, simply forward to the subexpression.
1052   PrintExpr(Node->getSubExpr());
1053 }
1054 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1055   PrintExpr(Node->getLHS());
1056   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1057   PrintExpr(Node->getRHS());
1058 }
1059 void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1060   PrintExpr(Node->getLHS());
1061   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1062   PrintExpr(Node->getRHS());
1063 }
1064 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1065   PrintExpr(Node->getCond());
1066   OS << " ? ";
1067   PrintExpr(Node->getLHS());
1068   OS << " : ";
1069   PrintExpr(Node->getRHS());
1070 }
1071 
1072 // GNU extensions.
1073 
1074 void
1075 StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1076   PrintExpr(Node->getCommon());
1077   OS << " ?: ";
1078   PrintExpr(Node->getFalseExpr());
1079 }
1080 void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1081   OS << "&&" << Node->getLabel()->getName();
1082 }
1083 
1084 void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1085   OS << "(";
1086   PrintRawCompoundStmt(E->getSubStmt());
1087   OS << ")";
1088 }
1089 
1090 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1091   OS << "__builtin_choose_expr(";
1092   PrintExpr(Node->getCond());
1093   OS << ", ";
1094   PrintExpr(Node->getLHS());
1095   OS << ", ";
1096   PrintExpr(Node->getRHS());
1097   OS << ")";
1098 }
1099 
1100 void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1101   OS << "__null";
1102 }
1103 
1104 void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1105   OS << "__builtin_shufflevector(";
1106   for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1107     if (i) OS << ", ";
1108     PrintExpr(Node->getExpr(i));
1109   }
1110   OS << ")";
1111 }
1112 
1113 void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1114   OS << "__builtin_convertvector(";
1115   PrintExpr(Node->getSrcExpr());
1116   OS << ", ";
1117   Node->getType().print(OS, Policy);
1118   OS << ")";
1119 }
1120 
1121 void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1122   if (Node->getSyntacticForm()) {
1123     Visit(Node->getSyntacticForm());
1124     return;
1125   }
1126 
1127   OS << "{ ";
1128   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1129     if (i) OS << ", ";
1130     if (Node->getInit(i))
1131       PrintExpr(Node->getInit(i));
1132     else
1133       OS << "0";
1134   }
1135   OS << " }";
1136 }
1137 
1138 void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1139   OS << "( ";
1140   for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1141     if (i) OS << ", ";
1142     PrintExpr(Node->getExpr(i));
1143   }
1144   OS << " )";
1145 }
1146 
1147 void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1148   for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1149                       DEnd = Node->designators_end();
1150        D != DEnd; ++D) {
1151     if (D->isFieldDesignator()) {
1152       if (D->getDotLoc().isInvalid())
1153         OS << D->getFieldName()->getName() << ":";
1154       else
1155         OS << "." << D->getFieldName()->getName();
1156     } else {
1157       OS << "[";
1158       if (D->isArrayDesignator()) {
1159         PrintExpr(Node->getArrayIndex(*D));
1160       } else {
1161         PrintExpr(Node->getArrayRangeStart(*D));
1162         OS << " ... ";
1163         PrintExpr(Node->getArrayRangeEnd(*D));
1164       }
1165       OS << "]";
1166     }
1167   }
1168 
1169   OS << " = ";
1170   PrintExpr(Node->getInit());
1171 }
1172 
1173 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1174   if (Policy.LangOpts.CPlusPlus) {
1175     OS << "/*implicit*/";
1176     Node->getType().print(OS, Policy);
1177     OS << "()";
1178   } else {
1179     OS << "/*implicit*/(";
1180     Node->getType().print(OS, Policy);
1181     OS << ')';
1182     if (Node->getType()->isRecordType())
1183       OS << "{}";
1184     else
1185       OS << 0;
1186   }
1187 }
1188 
1189 void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1190   OS << "__builtin_va_arg(";
1191   PrintExpr(Node->getSubExpr());
1192   OS << ", ";
1193   Node->getType().print(OS, Policy);
1194   OS << ")";
1195 }
1196 
1197 void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1198   PrintExpr(Node->getSyntacticForm());
1199 }
1200 
1201 void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1202   const char *Name = 0;
1203   switch (Node->getOp()) {
1204 #define BUILTIN(ID, TYPE, ATTRS)
1205 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1206   case AtomicExpr::AO ## ID: \
1207     Name = #ID "("; \
1208     break;
1209 #include "clang/Basic/Builtins.def"
1210   }
1211   OS << Name;
1212 
1213   // AtomicExpr stores its subexpressions in a permuted order.
1214   PrintExpr(Node->getPtr());
1215   if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1216       Node->getOp() != AtomicExpr::AO__atomic_load_n) {
1217     OS << ", ";
1218     PrintExpr(Node->getVal1());
1219   }
1220   if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1221       Node->isCmpXChg()) {
1222     OS << ", ";
1223     PrintExpr(Node->getVal2());
1224   }
1225   if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1226       Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1227     OS << ", ";
1228     PrintExpr(Node->getWeak());
1229   }
1230   if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1231     OS << ", ";
1232     PrintExpr(Node->getOrder());
1233   }
1234   if (Node->isCmpXChg()) {
1235     OS << ", ";
1236     PrintExpr(Node->getOrderFail());
1237   }
1238   OS << ")";
1239 }
1240 
1241 // C++
1242 void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1243   const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1244     "",
1245 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1246     Spelling,
1247 #include "clang/Basic/OperatorKinds.def"
1248   };
1249 
1250   OverloadedOperatorKind Kind = Node->getOperator();
1251   if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1252     if (Node->getNumArgs() == 1) {
1253       OS << OpStrings[Kind] << ' ';
1254       PrintExpr(Node->getArg(0));
1255     } else {
1256       PrintExpr(Node->getArg(0));
1257       OS << ' ' << OpStrings[Kind];
1258     }
1259   } else if (Kind == OO_Arrow) {
1260     PrintExpr(Node->getArg(0));
1261   } else if (Kind == OO_Call) {
1262     PrintExpr(Node->getArg(0));
1263     OS << '(';
1264     for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1265       if (ArgIdx > 1)
1266         OS << ", ";
1267       if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1268         PrintExpr(Node->getArg(ArgIdx));
1269     }
1270     OS << ')';
1271   } else if (Kind == OO_Subscript) {
1272     PrintExpr(Node->getArg(0));
1273     OS << '[';
1274     PrintExpr(Node->getArg(1));
1275     OS << ']';
1276   } else if (Node->getNumArgs() == 1) {
1277     OS << OpStrings[Kind] << ' ';
1278     PrintExpr(Node->getArg(0));
1279   } else if (Node->getNumArgs() == 2) {
1280     PrintExpr(Node->getArg(0));
1281     OS << ' ' << OpStrings[Kind] << ' ';
1282     PrintExpr(Node->getArg(1));
1283   } else {
1284     llvm_unreachable("unknown overloaded operator");
1285   }
1286 }
1287 
1288 void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1289   VisitCallExpr(cast<CallExpr>(Node));
1290 }
1291 
1292 void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1293   PrintExpr(Node->getCallee());
1294   OS << "<<<";
1295   PrintCallArgs(Node->getConfig());
1296   OS << ">>>(";
1297   PrintCallArgs(Node);
1298   OS << ")";
1299 }
1300 
1301 void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1302   OS << Node->getCastName() << '<';
1303   Node->getTypeAsWritten().print(OS, Policy);
1304   OS << ">(";
1305   PrintExpr(Node->getSubExpr());
1306   OS << ")";
1307 }
1308 
1309 void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1310   VisitCXXNamedCastExpr(Node);
1311 }
1312 
1313 void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1314   VisitCXXNamedCastExpr(Node);
1315 }
1316 
1317 void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1318   VisitCXXNamedCastExpr(Node);
1319 }
1320 
1321 void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1322   VisitCXXNamedCastExpr(Node);
1323 }
1324 
1325 void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1326   OS << "typeid(";
1327   if (Node->isTypeOperand()) {
1328     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1329   } else {
1330     PrintExpr(Node->getExprOperand());
1331   }
1332   OS << ")";
1333 }
1334 
1335 void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1336   OS << "__uuidof(";
1337   if (Node->isTypeOperand()) {
1338     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1339   } else {
1340     PrintExpr(Node->getExprOperand());
1341   }
1342   OS << ")";
1343 }
1344 
1345 void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1346   PrintExpr(Node->getBaseExpr());
1347   if (Node->isArrow())
1348     OS << "->";
1349   else
1350     OS << ".";
1351   if (NestedNameSpecifier *Qualifier =
1352       Node->getQualifierLoc().getNestedNameSpecifier())
1353     Qualifier->print(OS, Policy);
1354   OS << Node->getPropertyDecl()->getDeclName();
1355 }
1356 
1357 void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1358   switch (Node->getLiteralOperatorKind()) {
1359   case UserDefinedLiteral::LOK_Raw:
1360     OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
1361     break;
1362   case UserDefinedLiteral::LOK_Template: {
1363     DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1364     const TemplateArgumentList *Args =
1365       cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1366     assert(Args);
1367     const TemplateArgument &Pack = Args->get(0);
1368     for (TemplateArgument::pack_iterator I = Pack.pack_begin(),
1369                                          E = Pack.pack_end(); I != E; ++I) {
1370       char C = (char)I->getAsIntegral().getZExtValue();
1371       OS << C;
1372     }
1373     break;
1374   }
1375   case UserDefinedLiteral::LOK_Integer: {
1376     // Print integer literal without suffix.
1377     IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1378     OS << Int->getValue().toString(10, /*isSigned*/false);
1379     break;
1380   }
1381   case UserDefinedLiteral::LOK_Floating: {
1382     // Print floating literal without suffix.
1383     FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1384     PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1385     break;
1386   }
1387   case UserDefinedLiteral::LOK_String:
1388   case UserDefinedLiteral::LOK_Character:
1389     PrintExpr(Node->getCookedLiteral());
1390     break;
1391   }
1392   OS << Node->getUDSuffix()->getName();
1393 }
1394 
1395 void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1396   OS << (Node->getValue() ? "true" : "false");
1397 }
1398 
1399 void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1400   OS << "nullptr";
1401 }
1402 
1403 void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1404   OS << "this";
1405 }
1406 
1407 void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1408   if (Node->getSubExpr() == 0)
1409     OS << "throw";
1410   else {
1411     OS << "throw ";
1412     PrintExpr(Node->getSubExpr());
1413   }
1414 }
1415 
1416 void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1417   // Nothing to print: we picked up the default argument.
1418 }
1419 
1420 void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1421   // Nothing to print: we picked up the default initializer.
1422 }
1423 
1424 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1425   Node->getType().print(OS, Policy);
1426   OS << "(";
1427   PrintExpr(Node->getSubExpr());
1428   OS << ")";
1429 }
1430 
1431 void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1432   PrintExpr(Node->getSubExpr());
1433 }
1434 
1435 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1436   Node->getType().print(OS, Policy);
1437   OS << "(";
1438   for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
1439                                          ArgEnd = Node->arg_end();
1440        Arg != ArgEnd; ++Arg) {
1441     if (Arg->isDefaultArgument())
1442       break;
1443     if (Arg != Node->arg_begin())
1444       OS << ", ";
1445     PrintExpr(*Arg);
1446   }
1447   OS << ")";
1448 }
1449 
1450 void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1451   OS << '[';
1452   bool NeedComma = false;
1453   switch (Node->getCaptureDefault()) {
1454   case LCD_None:
1455     break;
1456 
1457   case LCD_ByCopy:
1458     OS << '=';
1459     NeedComma = true;
1460     break;
1461 
1462   case LCD_ByRef:
1463     OS << '&';
1464     NeedComma = true;
1465     break;
1466   }
1467   for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
1468                                  CEnd = Node->explicit_capture_end();
1469        C != CEnd;
1470        ++C) {
1471     if (NeedComma)
1472       OS << ", ";
1473     NeedComma = true;
1474 
1475     switch (C->getCaptureKind()) {
1476     case LCK_This:
1477       OS << "this";
1478       break;
1479 
1480     case LCK_ByRef:
1481       if (Node->getCaptureDefault() != LCD_ByRef || C->isInitCapture())
1482         OS << '&';
1483       OS << C->getCapturedVar()->getName();
1484       break;
1485 
1486     case LCK_ByCopy:
1487       OS << C->getCapturedVar()->getName();
1488       break;
1489     }
1490 
1491     if (C->isInitCapture())
1492       PrintExpr(C->getCapturedVar()->getInit());
1493   }
1494   OS << ']';
1495 
1496   if (Node->hasExplicitParameters()) {
1497     OS << " (";
1498     CXXMethodDecl *Method = Node->getCallOperator();
1499     NeedComma = false;
1500     for (CXXMethodDecl::param_iterator P = Method->param_begin(),
1501                                     PEnd = Method->param_end();
1502          P != PEnd; ++P) {
1503       if (NeedComma) {
1504         OS << ", ";
1505       } else {
1506         NeedComma = true;
1507       }
1508       std::string ParamStr = (*P)->getNameAsString();
1509       (*P)->getOriginalType().print(OS, Policy, ParamStr);
1510     }
1511     if (Method->isVariadic()) {
1512       if (NeedComma)
1513         OS << ", ";
1514       OS << "...";
1515     }
1516     OS << ')';
1517 
1518     if (Node->isMutable())
1519       OS << " mutable";
1520 
1521     const FunctionProtoType *Proto
1522       = Method->getType()->getAs<FunctionProtoType>();
1523     Proto->printExceptionSpecification(OS, Policy);
1524 
1525     // FIXME: Attributes
1526 
1527     // Print the trailing return type if it was specified in the source.
1528     if (Node->hasExplicitResultType()) {
1529       OS << " -> ";
1530       Proto->getResultType().print(OS, Policy);
1531     }
1532   }
1533 
1534   // Print the body.
1535   CompoundStmt *Body = Node->getBody();
1536   OS << ' ';
1537   PrintStmt(Body);
1538 }
1539 
1540 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
1541   if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
1542     TSInfo->getType().print(OS, Policy);
1543   else
1544     Node->getType().print(OS, Policy);
1545   OS << "()";
1546 }
1547 
1548 void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1549   if (E->isGlobalNew())
1550     OS << "::";
1551   OS << "new ";
1552   unsigned NumPlace = E->getNumPlacementArgs();
1553   if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
1554     OS << "(";
1555     PrintExpr(E->getPlacementArg(0));
1556     for (unsigned i = 1; i < NumPlace; ++i) {
1557       if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
1558         break;
1559       OS << ", ";
1560       PrintExpr(E->getPlacementArg(i));
1561     }
1562     OS << ") ";
1563   }
1564   if (E->isParenTypeId())
1565     OS << "(";
1566   std::string TypeS;
1567   if (Expr *Size = E->getArraySize()) {
1568     llvm::raw_string_ostream s(TypeS);
1569     s << '[';
1570     Size->printPretty(s, Helper, Policy);
1571     s << ']';
1572   }
1573   E->getAllocatedType().print(OS, Policy, TypeS);
1574   if (E->isParenTypeId())
1575     OS << ")";
1576 
1577   CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
1578   if (InitStyle) {
1579     if (InitStyle == CXXNewExpr::CallInit)
1580       OS << "(";
1581     PrintExpr(E->getInitializer());
1582     if (InitStyle == CXXNewExpr::CallInit)
1583       OS << ")";
1584   }
1585 }
1586 
1587 void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1588   if (E->isGlobalDelete())
1589     OS << "::";
1590   OS << "delete ";
1591   if (E->isArrayForm())
1592     OS << "[] ";
1593   PrintExpr(E->getArgument());
1594 }
1595 
1596 void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1597   PrintExpr(E->getBase());
1598   if (E->isArrow())
1599     OS << "->";
1600   else
1601     OS << '.';
1602   if (E->getQualifier())
1603     E->getQualifier()->print(OS, Policy);
1604   OS << "~";
1605 
1606   if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1607     OS << II->getName();
1608   else
1609     E->getDestroyedType().print(OS, Policy);
1610 }
1611 
1612 void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1613   if (E->isListInitialization())
1614     OS << "{ ";
1615 
1616   for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
1617     if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
1618       // Don't print any defaulted arguments
1619       break;
1620     }
1621 
1622     if (i) OS << ", ";
1623     PrintExpr(E->getArg(i));
1624   }
1625 
1626   if (E->isListInitialization())
1627     OS << " }";
1628 }
1629 
1630 void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1631   PrintExpr(E->getSubExpr());
1632 }
1633 
1634 void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
1635   // Just forward to the subexpression.
1636   PrintExpr(E->getSubExpr());
1637 }
1638 
1639 void
1640 StmtPrinter::VisitCXXUnresolvedConstructExpr(
1641                                            CXXUnresolvedConstructExpr *Node) {
1642   Node->getTypeAsWritten().print(OS, Policy);
1643   OS << "(";
1644   for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
1645                                              ArgEnd = Node->arg_end();
1646        Arg != ArgEnd; ++Arg) {
1647     if (Arg != Node->arg_begin())
1648       OS << ", ";
1649     PrintExpr(*Arg);
1650   }
1651   OS << ")";
1652 }
1653 
1654 void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1655                                          CXXDependentScopeMemberExpr *Node) {
1656   if (!Node->isImplicitAccess()) {
1657     PrintExpr(Node->getBase());
1658     OS << (Node->isArrow() ? "->" : ".");
1659   }
1660   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1661     Qualifier->print(OS, Policy);
1662   if (Node->hasTemplateKeyword())
1663     OS << "template ";
1664   OS << Node->getMemberNameInfo();
1665   if (Node->hasExplicitTemplateArgs())
1666     TemplateSpecializationType::PrintTemplateArgumentList(
1667         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1668 }
1669 
1670 void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
1671   if (!Node->isImplicitAccess()) {
1672     PrintExpr(Node->getBase());
1673     OS << (Node->isArrow() ? "->" : ".");
1674   }
1675   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1676     Qualifier->print(OS, Policy);
1677   if (Node->hasTemplateKeyword())
1678     OS << "template ";
1679   OS << Node->getMemberNameInfo();
1680   if (Node->hasExplicitTemplateArgs())
1681     TemplateSpecializationType::PrintTemplateArgumentList(
1682         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1683 }
1684 
1685 static const char *getTypeTraitName(TypeTrait TT) {
1686   switch (TT) {
1687 #define TYPE_TRAIT_1(Spelling, Name, Key) \
1688 case clang::UTT_##Name: return #Spelling;
1689 #define TYPE_TRAIT_2(Spelling, Name, Key) \
1690 case clang::BTT_##Name: return #Spelling;
1691 #define TYPE_TRAIT_N(Spelling, Name, Key) \
1692   case clang::TT_##Name: return #Spelling;
1693 #include "clang/Basic/TokenKinds.def"
1694   }
1695   llvm_unreachable("Type trait not covered by switch");
1696 }
1697 
1698 static const char *getTypeTraitName(ArrayTypeTrait ATT) {
1699   switch (ATT) {
1700   case ATT_ArrayRank:        return "__array_rank";
1701   case ATT_ArrayExtent:      return "__array_extent";
1702   }
1703   llvm_unreachable("Array type trait not covered by switch");
1704 }
1705 
1706 static const char *getExpressionTraitName(ExpressionTrait ET) {
1707   switch (ET) {
1708   case ET_IsLValueExpr:      return "__is_lvalue_expr";
1709   case ET_IsRValueExpr:      return "__is_rvalue_expr";
1710   }
1711   llvm_unreachable("Expression type trait not covered by switch");
1712 }
1713 
1714 void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1715   OS << getTypeTraitName(E->getTrait()) << "(";
1716   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
1717     if (I > 0)
1718       OS << ", ";
1719     E->getArg(I)->getType().print(OS, Policy);
1720   }
1721   OS << ")";
1722 }
1723 
1724 void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1725   OS << getTypeTraitName(E->getTrait()) << '(';
1726   E->getQueriedType().print(OS, Policy);
1727   OS << ')';
1728 }
1729 
1730 void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1731   OS << getExpressionTraitName(E->getTrait()) << '(';
1732   PrintExpr(E->getQueriedExpression());
1733   OS << ')';
1734 }
1735 
1736 void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1737   OS << "noexcept(";
1738   PrintExpr(E->getOperand());
1739   OS << ")";
1740 }
1741 
1742 void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1743   PrintExpr(E->getPattern());
1744   OS << "...";
1745 }
1746 
1747 void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1748   OS << "sizeof...(" << *E->getPack() << ")";
1749 }
1750 
1751 void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
1752                                        SubstNonTypeTemplateParmPackExpr *Node) {
1753   OS << *Node->getParameterPack();
1754 }
1755 
1756 void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
1757                                        SubstNonTypeTemplateParmExpr *Node) {
1758   Visit(Node->getReplacement());
1759 }
1760 
1761 void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1762   OS << *E->getParameterPack();
1763 }
1764 
1765 void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
1766   PrintExpr(Node->GetTemporaryExpr());
1767 }
1768 
1769 // Obj-C
1770 
1771 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1772   OS << "@";
1773   VisitStringLiteral(Node->getString());
1774 }
1775 
1776 void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1777   OS << "@";
1778   Visit(E->getSubExpr());
1779 }
1780 
1781 void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1782   OS << "@[ ";
1783   StmtRange ch = E->children();
1784   if (ch.first != ch.second) {
1785     while (1) {
1786       Visit(*ch.first);
1787       ++ch.first;
1788       if (ch.first == ch.second) break;
1789       OS << ", ";
1790     }
1791   }
1792   OS << " ]";
1793 }
1794 
1795 void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1796   OS << "@{ ";
1797   for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
1798     if (I > 0)
1799       OS << ", ";
1800 
1801     ObjCDictionaryElement Element = E->getKeyValueElement(I);
1802     Visit(Element.Key);
1803     OS << " : ";
1804     Visit(Element.Value);
1805     if (Element.isPackExpansion())
1806       OS << "...";
1807   }
1808   OS << " }";
1809 }
1810 
1811 void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
1812   OS << "@encode(";
1813   Node->getEncodedType().print(OS, Policy);
1814   OS << ')';
1815 }
1816 
1817 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
1818   OS << "@selector(";
1819   Node->getSelector().print(OS);
1820   OS << ')';
1821 }
1822 
1823 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
1824   OS << "@protocol(" << *Node->getProtocol() << ')';
1825 }
1826 
1827 void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1828   OS << "[";
1829   switch (Mess->getReceiverKind()) {
1830   case ObjCMessageExpr::Instance:
1831     PrintExpr(Mess->getInstanceReceiver());
1832     break;
1833 
1834   case ObjCMessageExpr::Class:
1835     Mess->getClassReceiver().print(OS, Policy);
1836     break;
1837 
1838   case ObjCMessageExpr::SuperInstance:
1839   case ObjCMessageExpr::SuperClass:
1840     OS << "Super";
1841     break;
1842   }
1843 
1844   OS << ' ';
1845   Selector selector = Mess->getSelector();
1846   if (selector.isUnarySelector()) {
1847     OS << selector.getNameForSlot(0);
1848   } else {
1849     for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
1850       if (i < selector.getNumArgs()) {
1851         if (i > 0) OS << ' ';
1852         if (selector.getIdentifierInfoForSlot(i))
1853           OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
1854         else
1855            OS << ":";
1856       }
1857       else OS << ", "; // Handle variadic methods.
1858 
1859       PrintExpr(Mess->getArg(i));
1860     }
1861   }
1862   OS << "]";
1863 }
1864 
1865 void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
1866   OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
1867 }
1868 
1869 void
1870 StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1871   PrintExpr(E->getSubExpr());
1872 }
1873 
1874 void
1875 StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1876   OS << '(' << E->getBridgeKindName();
1877   E->getType().print(OS, Policy);
1878   OS << ')';
1879   PrintExpr(E->getSubExpr());
1880 }
1881 
1882 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
1883   BlockDecl *BD = Node->getBlockDecl();
1884   OS << "^";
1885 
1886   const FunctionType *AFT = Node->getFunctionType();
1887 
1888   if (isa<FunctionNoProtoType>(AFT)) {
1889     OS << "()";
1890   } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
1891     OS << '(';
1892     for (BlockDecl::param_iterator AI = BD->param_begin(),
1893          E = BD->param_end(); AI != E; ++AI) {
1894       if (AI != BD->param_begin()) OS << ", ";
1895       std::string ParamStr = (*AI)->getNameAsString();
1896       (*AI)->getType().print(OS, Policy, ParamStr);
1897     }
1898 
1899     const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
1900     if (FT->isVariadic()) {
1901       if (!BD->param_empty()) OS << ", ";
1902       OS << "...";
1903     }
1904     OS << ')';
1905   }
1906   OS << "{ }";
1907 }
1908 
1909 void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
1910   PrintExpr(Node->getSourceExpr());
1911 }
1912 
1913 void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
1914   OS << "__builtin_astype(";
1915   PrintExpr(Node->getSrcExpr());
1916   OS << ", ";
1917   Node->getType().print(OS, Policy);
1918   OS << ")";
1919 }
1920 
1921 //===----------------------------------------------------------------------===//
1922 // Stmt method implementations
1923 //===----------------------------------------------------------------------===//
1924 
1925 void Stmt::dumpPretty(const ASTContext &Context) const {
1926   printPretty(llvm::errs(), 0, PrintingPolicy(Context.getLangOpts()));
1927 }
1928 
1929 void Stmt::printPretty(raw_ostream &OS,
1930                        PrinterHelper *Helper,
1931                        const PrintingPolicy &Policy,
1932                        unsigned Indentation) const {
1933   if (this == 0) {
1934     OS << "<NULL>";
1935     return;
1936   }
1937 
1938   StmtPrinter P(OS, Helper, Policy, Indentation);
1939   P.Visit(const_cast<Stmt*>(this));
1940 }
1941 
1942 //===----------------------------------------------------------------------===//
1943 // PrinterHelper
1944 //===----------------------------------------------------------------------===//
1945 
1946 // Implement virtual destructor.
1947 PrinterHelper::~PrinterHelper() {}
1948