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   const PrintingPolicy &Policy;
597   /// \brief Process clauses with list of variables.
598   template <typename T>
599   void VisitOMPClauseList(T *Node, char StartSym);
600 public:
601   OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
602     : OS(OS), Policy(Policy) { }
603 #define OPENMP_CLAUSE(Name, Class)                              \
604   void Visit##Class(Class *S);
605 #include "clang/Basic/OpenMPKinds.def"
606 };
607 
608 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
609   OS << "if(";
610   Node->getCondition()->printPretty(OS, 0, Policy, 0);
611   OS << ")";
612 }
613 
614 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
615   OS << "default("
616      << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
617      << ")";
618 }
619 
620 template<typename T>
621 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
622   for (typename T::varlist_iterator I = Node->varlist_begin(),
623                                     E = Node->varlist_end();
624          I != E; ++I)
625     OS << (I == Node->varlist_begin() ? StartSym : ',')
626        << *cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
627 }
628 
629 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
630   if (!Node->varlist_empty()) {
631     OS << "private";
632     VisitOMPClauseList(Node, '(');
633     OS << ")";
634   }
635 }
636 
637 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
638   if (!Node->varlist_empty()) {
639     OS << "firstprivate";
640     VisitOMPClauseList(Node, '(');
641     OS << ")";
642   }
643 }
644 
645 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
646   if (!Node->varlist_empty()) {
647     OS << "shared";
648     VisitOMPClauseList(Node, '(');
649     OS << ")";
650   }
651 }
652 
653 }
654 
655 //===----------------------------------------------------------------------===//
656 //  OpenMP directives printing methods
657 //===----------------------------------------------------------------------===//
658 
659 void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
660   Indent() << "#pragma omp parallel ";
661 
662   OMPClausePrinter Printer(OS, Policy);
663   ArrayRef<OMPClause *> Clauses = Node->clauses();
664   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
665        I != E; ++I)
666     if (*I && !(*I)->isImplicit()) {
667       Printer.Visit(*I);
668       OS << ' ';
669     }
670   OS << "\n";
671   if (Node->getAssociatedStmt()) {
672     assert(isa<CapturedStmt>(Node->getAssociatedStmt()) &&
673            "Expected captured statement!");
674     Stmt *CS = cast<CapturedStmt>(Node->getAssociatedStmt())->getCapturedStmt();
675     PrintStmt(CS);
676   }
677 }
678 //===----------------------------------------------------------------------===//
679 //  Expr printing methods.
680 //===----------------------------------------------------------------------===//
681 
682 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
683   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
684     Qualifier->print(OS, Policy);
685   if (Node->hasTemplateKeyword())
686     OS << "template ";
687   OS << Node->getNameInfo();
688   if (Node->hasExplicitTemplateArgs())
689     TemplateSpecializationType::PrintTemplateArgumentList(
690         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
691 }
692 
693 void StmtPrinter::VisitDependentScopeDeclRefExpr(
694                                            DependentScopeDeclRefExpr *Node) {
695   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
696     Qualifier->print(OS, Policy);
697   if (Node->hasTemplateKeyword())
698     OS << "template ";
699   OS << Node->getNameInfo();
700   if (Node->hasExplicitTemplateArgs())
701     TemplateSpecializationType::PrintTemplateArgumentList(
702         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
703 }
704 
705 void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
706   if (Node->getQualifier())
707     Node->getQualifier()->print(OS, Policy);
708   if (Node->hasTemplateKeyword())
709     OS << "template ";
710   OS << Node->getNameInfo();
711   if (Node->hasExplicitTemplateArgs())
712     TemplateSpecializationType::PrintTemplateArgumentList(
713         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
714 }
715 
716 void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
717   if (Node->getBase()) {
718     PrintExpr(Node->getBase());
719     OS << (Node->isArrow() ? "->" : ".");
720   }
721   OS << *Node->getDecl();
722 }
723 
724 void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
725   if (Node->isSuperReceiver())
726     OS << "super.";
727   else if (Node->isObjectReceiver() && Node->getBase()) {
728     PrintExpr(Node->getBase());
729     OS << ".";
730   } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
731     OS << Node->getClassReceiver()->getName() << ".";
732   }
733 
734   if (Node->isImplicitProperty())
735     Node->getImplicitPropertyGetter()->getSelector().print(OS);
736   else
737     OS << Node->getExplicitProperty()->getName();
738 }
739 
740 void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
741 
742   PrintExpr(Node->getBaseExpr());
743   OS << "[";
744   PrintExpr(Node->getKeyExpr());
745   OS << "]";
746 }
747 
748 void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
749   switch (Node->getIdentType()) {
750     default:
751       llvm_unreachable("unknown case");
752     case PredefinedExpr::Func:
753       OS << "__func__";
754       break;
755     case PredefinedExpr::Function:
756       OS << "__FUNCTION__";
757       break;
758     case PredefinedExpr::FuncDName:
759       OS << "__FUNCDNAME__";
760       break;
761     case PredefinedExpr::LFunction:
762       OS << "L__FUNCTION__";
763       break;
764     case PredefinedExpr::PrettyFunction:
765       OS << "__PRETTY_FUNCTION__";
766       break;
767   }
768 }
769 
770 void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
771   unsigned value = Node->getValue();
772 
773   switch (Node->getKind()) {
774   case CharacterLiteral::Ascii: break; // no prefix.
775   case CharacterLiteral::Wide:  OS << 'L'; break;
776   case CharacterLiteral::UTF16: OS << 'u'; break;
777   case CharacterLiteral::UTF32: OS << 'U'; break;
778   }
779 
780   switch (value) {
781   case '\\':
782     OS << "'\\\\'";
783     break;
784   case '\'':
785     OS << "'\\''";
786     break;
787   case '\a':
788     // TODO: K&R: the meaning of '\\a' is different in traditional C
789     OS << "'\\a'";
790     break;
791   case '\b':
792     OS << "'\\b'";
793     break;
794   // Nonstandard escape sequence.
795   /*case '\e':
796     OS << "'\\e'";
797     break;*/
798   case '\f':
799     OS << "'\\f'";
800     break;
801   case '\n':
802     OS << "'\\n'";
803     break;
804   case '\r':
805     OS << "'\\r'";
806     break;
807   case '\t':
808     OS << "'\\t'";
809     break;
810   case '\v':
811     OS << "'\\v'";
812     break;
813   default:
814     if (value < 256 && isPrintable((unsigned char)value))
815       OS << "'" << (char)value << "'";
816     else if (value < 256)
817       OS << "'\\x" << llvm::format("%02x", value) << "'";
818     else if (value <= 0xFFFF)
819       OS << "'\\u" << llvm::format("%04x", value) << "'";
820     else
821       OS << "'\\U" << llvm::format("%08x", value) << "'";
822   }
823 }
824 
825 void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
826   bool isSigned = Node->getType()->isSignedIntegerType();
827   OS << Node->getValue().toString(10, isSigned);
828 
829   // Emit suffixes.  Integer literals are always a builtin integer type.
830   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
831   default: llvm_unreachable("Unexpected type for integer literal!");
832   // FIXME: The Short and UShort cases are to handle cases where a short
833   // integeral literal is formed during template instantiation.  They should
834   // be removed when template instantiation no longer needs integer literals.
835   case BuiltinType::Short:
836   case BuiltinType::UShort:
837   case BuiltinType::Int:       break; // no suffix.
838   case BuiltinType::UInt:      OS << 'U'; break;
839   case BuiltinType::Long:      OS << 'L'; break;
840   case BuiltinType::ULong:     OS << "UL"; break;
841   case BuiltinType::LongLong:  OS << "LL"; break;
842   case BuiltinType::ULongLong: OS << "ULL"; break;
843   case BuiltinType::Int128:    OS << "i128"; break;
844   case BuiltinType::UInt128:   OS << "Ui128"; break;
845   }
846 }
847 
848 static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
849                                  bool PrintSuffix) {
850   SmallString<16> Str;
851   Node->getValue().toString(Str);
852   OS << Str;
853   if (Str.find_first_not_of("-0123456789") == StringRef::npos)
854     OS << '.'; // Trailing dot in order to separate from ints.
855 
856   if (!PrintSuffix)
857     return;
858 
859   // Emit suffixes.  Float literals are always a builtin float type.
860   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
861   default: llvm_unreachable("Unexpected type for float literal!");
862   case BuiltinType::Half:       break; // FIXME: suffix?
863   case BuiltinType::Double:     break; // no suffix.
864   case BuiltinType::Float:      OS << 'F'; break;
865   case BuiltinType::LongDouble: OS << 'L'; break;
866   }
867 }
868 
869 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
870   PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
871 }
872 
873 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
874   PrintExpr(Node->getSubExpr());
875   OS << "i";
876 }
877 
878 void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
879   Str->outputString(OS);
880 }
881 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
882   OS << "(";
883   PrintExpr(Node->getSubExpr());
884   OS << ")";
885 }
886 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
887   if (!Node->isPostfix()) {
888     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
889 
890     // Print a space if this is an "identifier operator" like __real, or if
891     // it might be concatenated incorrectly like '+'.
892     switch (Node->getOpcode()) {
893     default: break;
894     case UO_Real:
895     case UO_Imag:
896     case UO_Extension:
897       OS << ' ';
898       break;
899     case UO_Plus:
900     case UO_Minus:
901       if (isa<UnaryOperator>(Node->getSubExpr()))
902         OS << ' ';
903       break;
904     }
905   }
906   PrintExpr(Node->getSubExpr());
907 
908   if (Node->isPostfix())
909     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
910 }
911 
912 void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
913   OS << "__builtin_offsetof(";
914   Node->getTypeSourceInfo()->getType().print(OS, Policy);
915   OS << ", ";
916   bool PrintedSomething = false;
917   for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
918     OffsetOfExpr::OffsetOfNode ON = Node->getComponent(i);
919     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Array) {
920       // Array node
921       OS << "[";
922       PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
923       OS << "]";
924       PrintedSomething = true;
925       continue;
926     }
927 
928     // Skip implicit base indirections.
929     if (ON.getKind() == OffsetOfExpr::OffsetOfNode::Base)
930       continue;
931 
932     // Field or identifier node.
933     IdentifierInfo *Id = ON.getFieldName();
934     if (!Id)
935       continue;
936 
937     if (PrintedSomething)
938       OS << ".";
939     else
940       PrintedSomething = true;
941     OS << Id->getName();
942   }
943   OS << ")";
944 }
945 
946 void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
947   switch(Node->getKind()) {
948   case UETT_SizeOf:
949     OS << "sizeof";
950     break;
951   case UETT_AlignOf:
952     if (Policy.LangOpts.CPlusPlus)
953       OS << "alignof";
954     else if (Policy.LangOpts.C11)
955       OS << "_Alignof";
956     else
957       OS << "__alignof";
958     break;
959   case UETT_VecStep:
960     OS << "vec_step";
961     break;
962   }
963   if (Node->isArgumentType()) {
964     OS << '(';
965     Node->getArgumentType().print(OS, Policy);
966     OS << ')';
967   } else {
968     OS << " ";
969     PrintExpr(Node->getArgumentExpr());
970   }
971 }
972 
973 void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
974   OS << "_Generic(";
975   PrintExpr(Node->getControllingExpr());
976   for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
977     OS << ", ";
978     QualType T = Node->getAssocType(i);
979     if (T.isNull())
980       OS << "default";
981     else
982       T.print(OS, Policy);
983     OS << ": ";
984     PrintExpr(Node->getAssocExpr(i));
985   }
986   OS << ")";
987 }
988 
989 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
990   PrintExpr(Node->getLHS());
991   OS << "[";
992   PrintExpr(Node->getRHS());
993   OS << "]";
994 }
995 
996 void StmtPrinter::PrintCallArgs(CallExpr *Call) {
997   for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
998     if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
999       // Don't print any defaulted arguments
1000       break;
1001     }
1002 
1003     if (i) OS << ", ";
1004     PrintExpr(Call->getArg(i));
1005   }
1006 }
1007 
1008 void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1009   PrintExpr(Call->getCallee());
1010   OS << "(";
1011   PrintCallArgs(Call);
1012   OS << ")";
1013 }
1014 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1015   // FIXME: Suppress printing implicit bases (like "this")
1016   PrintExpr(Node->getBase());
1017 
1018   MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1019   FieldDecl  *ParentDecl   = ParentMember
1020     ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : NULL;
1021 
1022   if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1023     OS << (Node->isArrow() ? "->" : ".");
1024 
1025   if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1026     if (FD->isAnonymousStructOrUnion())
1027       return;
1028 
1029   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1030     Qualifier->print(OS, Policy);
1031   if (Node->hasTemplateKeyword())
1032     OS << "template ";
1033   OS << Node->getMemberNameInfo();
1034   if (Node->hasExplicitTemplateArgs())
1035     TemplateSpecializationType::PrintTemplateArgumentList(
1036         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1037 }
1038 void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1039   PrintExpr(Node->getBase());
1040   OS << (Node->isArrow() ? "->isa" : ".isa");
1041 }
1042 
1043 void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1044   PrintExpr(Node->getBase());
1045   OS << ".";
1046   OS << Node->getAccessor().getName();
1047 }
1048 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1049   OS << '(';
1050   Node->getTypeAsWritten().print(OS, Policy);
1051   OS << ')';
1052   PrintExpr(Node->getSubExpr());
1053 }
1054 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1055   OS << '(';
1056   Node->getType().print(OS, Policy);
1057   OS << ')';
1058   PrintExpr(Node->getInitializer());
1059 }
1060 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1061   // No need to print anything, simply forward to the subexpression.
1062   PrintExpr(Node->getSubExpr());
1063 }
1064 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1065   PrintExpr(Node->getLHS());
1066   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1067   PrintExpr(Node->getRHS());
1068 }
1069 void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1070   PrintExpr(Node->getLHS());
1071   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1072   PrintExpr(Node->getRHS());
1073 }
1074 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1075   PrintExpr(Node->getCond());
1076   OS << " ? ";
1077   PrintExpr(Node->getLHS());
1078   OS << " : ";
1079   PrintExpr(Node->getRHS());
1080 }
1081 
1082 // GNU extensions.
1083 
1084 void
1085 StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1086   PrintExpr(Node->getCommon());
1087   OS << " ?: ";
1088   PrintExpr(Node->getFalseExpr());
1089 }
1090 void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1091   OS << "&&" << Node->getLabel()->getName();
1092 }
1093 
1094 void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1095   OS << "(";
1096   PrintRawCompoundStmt(E->getSubStmt());
1097   OS << ")";
1098 }
1099 
1100 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1101   OS << "__builtin_choose_expr(";
1102   PrintExpr(Node->getCond());
1103   OS << ", ";
1104   PrintExpr(Node->getLHS());
1105   OS << ", ";
1106   PrintExpr(Node->getRHS());
1107   OS << ")";
1108 }
1109 
1110 void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1111   OS << "__null";
1112 }
1113 
1114 void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1115   OS << "__builtin_shufflevector(";
1116   for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1117     if (i) OS << ", ";
1118     PrintExpr(Node->getExpr(i));
1119   }
1120   OS << ")";
1121 }
1122 
1123 void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1124   OS << "__builtin_convertvector(";
1125   PrintExpr(Node->getSrcExpr());
1126   OS << ", ";
1127   Node->getType().print(OS, Policy);
1128   OS << ")";
1129 }
1130 
1131 void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1132   if (Node->getSyntacticForm()) {
1133     Visit(Node->getSyntacticForm());
1134     return;
1135   }
1136 
1137   OS << "{ ";
1138   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1139     if (i) OS << ", ";
1140     if (Node->getInit(i))
1141       PrintExpr(Node->getInit(i));
1142     else
1143       OS << "0";
1144   }
1145   OS << " }";
1146 }
1147 
1148 void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1149   OS << "( ";
1150   for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1151     if (i) OS << ", ";
1152     PrintExpr(Node->getExpr(i));
1153   }
1154   OS << " )";
1155 }
1156 
1157 void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1158   for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1159                       DEnd = Node->designators_end();
1160        D != DEnd; ++D) {
1161     if (D->isFieldDesignator()) {
1162       if (D->getDotLoc().isInvalid())
1163         OS << D->getFieldName()->getName() << ":";
1164       else
1165         OS << "." << D->getFieldName()->getName();
1166     } else {
1167       OS << "[";
1168       if (D->isArrayDesignator()) {
1169         PrintExpr(Node->getArrayIndex(*D));
1170       } else {
1171         PrintExpr(Node->getArrayRangeStart(*D));
1172         OS << " ... ";
1173         PrintExpr(Node->getArrayRangeEnd(*D));
1174       }
1175       OS << "]";
1176     }
1177   }
1178 
1179   OS << " = ";
1180   PrintExpr(Node->getInit());
1181 }
1182 
1183 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1184   if (Policy.LangOpts.CPlusPlus) {
1185     OS << "/*implicit*/";
1186     Node->getType().print(OS, Policy);
1187     OS << "()";
1188   } else {
1189     OS << "/*implicit*/(";
1190     Node->getType().print(OS, Policy);
1191     OS << ')';
1192     if (Node->getType()->isRecordType())
1193       OS << "{}";
1194     else
1195       OS << 0;
1196   }
1197 }
1198 
1199 void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1200   OS << "__builtin_va_arg(";
1201   PrintExpr(Node->getSubExpr());
1202   OS << ", ";
1203   Node->getType().print(OS, Policy);
1204   OS << ")";
1205 }
1206 
1207 void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1208   PrintExpr(Node->getSyntacticForm());
1209 }
1210 
1211 void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1212   const char *Name = 0;
1213   switch (Node->getOp()) {
1214 #define BUILTIN(ID, TYPE, ATTRS)
1215 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1216   case AtomicExpr::AO ## ID: \
1217     Name = #ID "("; \
1218     break;
1219 #include "clang/Basic/Builtins.def"
1220   }
1221   OS << Name;
1222 
1223   // AtomicExpr stores its subexpressions in a permuted order.
1224   PrintExpr(Node->getPtr());
1225   if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1226       Node->getOp() != AtomicExpr::AO__atomic_load_n) {
1227     OS << ", ";
1228     PrintExpr(Node->getVal1());
1229   }
1230   if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1231       Node->isCmpXChg()) {
1232     OS << ", ";
1233     PrintExpr(Node->getVal2());
1234   }
1235   if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1236       Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1237     OS << ", ";
1238     PrintExpr(Node->getWeak());
1239   }
1240   if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1241     OS << ", ";
1242     PrintExpr(Node->getOrder());
1243   }
1244   if (Node->isCmpXChg()) {
1245     OS << ", ";
1246     PrintExpr(Node->getOrderFail());
1247   }
1248   OS << ")";
1249 }
1250 
1251 // C++
1252 void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1253   const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1254     "",
1255 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1256     Spelling,
1257 #include "clang/Basic/OperatorKinds.def"
1258   };
1259 
1260   OverloadedOperatorKind Kind = Node->getOperator();
1261   if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1262     if (Node->getNumArgs() == 1) {
1263       OS << OpStrings[Kind] << ' ';
1264       PrintExpr(Node->getArg(0));
1265     } else {
1266       PrintExpr(Node->getArg(0));
1267       OS << ' ' << OpStrings[Kind];
1268     }
1269   } else if (Kind == OO_Arrow) {
1270     PrintExpr(Node->getArg(0));
1271   } else if (Kind == OO_Call) {
1272     PrintExpr(Node->getArg(0));
1273     OS << '(';
1274     for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1275       if (ArgIdx > 1)
1276         OS << ", ";
1277       if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1278         PrintExpr(Node->getArg(ArgIdx));
1279     }
1280     OS << ')';
1281   } else if (Kind == OO_Subscript) {
1282     PrintExpr(Node->getArg(0));
1283     OS << '[';
1284     PrintExpr(Node->getArg(1));
1285     OS << ']';
1286   } else if (Node->getNumArgs() == 1) {
1287     OS << OpStrings[Kind] << ' ';
1288     PrintExpr(Node->getArg(0));
1289   } else if (Node->getNumArgs() == 2) {
1290     PrintExpr(Node->getArg(0));
1291     OS << ' ' << OpStrings[Kind] << ' ';
1292     PrintExpr(Node->getArg(1));
1293   } else {
1294     llvm_unreachable("unknown overloaded operator");
1295   }
1296 }
1297 
1298 void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1299   VisitCallExpr(cast<CallExpr>(Node));
1300 }
1301 
1302 void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1303   PrintExpr(Node->getCallee());
1304   OS << "<<<";
1305   PrintCallArgs(Node->getConfig());
1306   OS << ">>>(";
1307   PrintCallArgs(Node);
1308   OS << ")";
1309 }
1310 
1311 void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1312   OS << Node->getCastName() << '<';
1313   Node->getTypeAsWritten().print(OS, Policy);
1314   OS << ">(";
1315   PrintExpr(Node->getSubExpr());
1316   OS << ")";
1317 }
1318 
1319 void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1320   VisitCXXNamedCastExpr(Node);
1321 }
1322 
1323 void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1324   VisitCXXNamedCastExpr(Node);
1325 }
1326 
1327 void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1328   VisitCXXNamedCastExpr(Node);
1329 }
1330 
1331 void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1332   VisitCXXNamedCastExpr(Node);
1333 }
1334 
1335 void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1336   OS << "typeid(";
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::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1346   OS << "__uuidof(";
1347   if (Node->isTypeOperand()) {
1348     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1349   } else {
1350     PrintExpr(Node->getExprOperand());
1351   }
1352   OS << ")";
1353 }
1354 
1355 void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1356   PrintExpr(Node->getBaseExpr());
1357   if (Node->isArrow())
1358     OS << "->";
1359   else
1360     OS << ".";
1361   if (NestedNameSpecifier *Qualifier =
1362       Node->getQualifierLoc().getNestedNameSpecifier())
1363     Qualifier->print(OS, Policy);
1364   OS << Node->getPropertyDecl()->getDeclName();
1365 }
1366 
1367 void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1368   switch (Node->getLiteralOperatorKind()) {
1369   case UserDefinedLiteral::LOK_Raw:
1370     OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
1371     break;
1372   case UserDefinedLiteral::LOK_Template: {
1373     DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1374     const TemplateArgumentList *Args =
1375       cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1376     assert(Args);
1377     const TemplateArgument &Pack = Args->get(0);
1378     for (TemplateArgument::pack_iterator I = Pack.pack_begin(),
1379                                          E = Pack.pack_end(); I != E; ++I) {
1380       char C = (char)I->getAsIntegral().getZExtValue();
1381       OS << C;
1382     }
1383     break;
1384   }
1385   case UserDefinedLiteral::LOK_Integer: {
1386     // Print integer literal without suffix.
1387     IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1388     OS << Int->getValue().toString(10, /*isSigned*/false);
1389     break;
1390   }
1391   case UserDefinedLiteral::LOK_Floating: {
1392     // Print floating literal without suffix.
1393     FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1394     PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1395     break;
1396   }
1397   case UserDefinedLiteral::LOK_String:
1398   case UserDefinedLiteral::LOK_Character:
1399     PrintExpr(Node->getCookedLiteral());
1400     break;
1401   }
1402   OS << Node->getUDSuffix()->getName();
1403 }
1404 
1405 void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1406   OS << (Node->getValue() ? "true" : "false");
1407 }
1408 
1409 void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1410   OS << "nullptr";
1411 }
1412 
1413 void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1414   OS << "this";
1415 }
1416 
1417 void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1418   if (Node->getSubExpr() == 0)
1419     OS << "throw";
1420   else {
1421     OS << "throw ";
1422     PrintExpr(Node->getSubExpr());
1423   }
1424 }
1425 
1426 void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1427   // Nothing to print: we picked up the default argument.
1428 }
1429 
1430 void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1431   // Nothing to print: we picked up the default initializer.
1432 }
1433 
1434 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1435   Node->getType().print(OS, Policy);
1436   OS << "(";
1437   PrintExpr(Node->getSubExpr());
1438   OS << ")";
1439 }
1440 
1441 void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1442   PrintExpr(Node->getSubExpr());
1443 }
1444 
1445 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1446   Node->getType().print(OS, Policy);
1447   OS << "(";
1448   for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
1449                                          ArgEnd = Node->arg_end();
1450        Arg != ArgEnd; ++Arg) {
1451     if (Arg->isDefaultArgument())
1452       break;
1453     if (Arg != Node->arg_begin())
1454       OS << ", ";
1455     PrintExpr(*Arg);
1456   }
1457   OS << ")";
1458 }
1459 
1460 void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1461   OS << '[';
1462   bool NeedComma = false;
1463   switch (Node->getCaptureDefault()) {
1464   case LCD_None:
1465     break;
1466 
1467   case LCD_ByCopy:
1468     OS << '=';
1469     NeedComma = true;
1470     break;
1471 
1472   case LCD_ByRef:
1473     OS << '&';
1474     NeedComma = true;
1475     break;
1476   }
1477   for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
1478                                  CEnd = Node->explicit_capture_end();
1479        C != CEnd;
1480        ++C) {
1481     if (NeedComma)
1482       OS << ", ";
1483     NeedComma = true;
1484 
1485     switch (C->getCaptureKind()) {
1486     case LCK_This:
1487       OS << "this";
1488       break;
1489 
1490     case LCK_ByRef:
1491       if (Node->getCaptureDefault() != LCD_ByRef || C->isInitCapture())
1492         OS << '&';
1493       OS << C->getCapturedVar()->getName();
1494       break;
1495 
1496     case LCK_ByCopy:
1497       OS << C->getCapturedVar()->getName();
1498       break;
1499     }
1500 
1501     if (C->isInitCapture())
1502       PrintExpr(C->getCapturedVar()->getInit());
1503   }
1504   OS << ']';
1505 
1506   if (Node->hasExplicitParameters()) {
1507     OS << " (";
1508     CXXMethodDecl *Method = Node->getCallOperator();
1509     NeedComma = false;
1510     for (CXXMethodDecl::param_iterator P = Method->param_begin(),
1511                                     PEnd = Method->param_end();
1512          P != PEnd; ++P) {
1513       if (NeedComma) {
1514         OS << ", ";
1515       } else {
1516         NeedComma = true;
1517       }
1518       std::string ParamStr = (*P)->getNameAsString();
1519       (*P)->getOriginalType().print(OS, Policy, ParamStr);
1520     }
1521     if (Method->isVariadic()) {
1522       if (NeedComma)
1523         OS << ", ";
1524       OS << "...";
1525     }
1526     OS << ')';
1527 
1528     if (Node->isMutable())
1529       OS << " mutable";
1530 
1531     const FunctionProtoType *Proto
1532       = Method->getType()->getAs<FunctionProtoType>();
1533     Proto->printExceptionSpecification(OS, Policy);
1534 
1535     // FIXME: Attributes
1536 
1537     // Print the trailing return type if it was specified in the source.
1538     if (Node->hasExplicitResultType()) {
1539       OS << " -> ";
1540       Proto->getReturnType().print(OS, Policy);
1541     }
1542   }
1543 
1544   // Print the body.
1545   CompoundStmt *Body = Node->getBody();
1546   OS << ' ';
1547   PrintStmt(Body);
1548 }
1549 
1550 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
1551   if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
1552     TSInfo->getType().print(OS, Policy);
1553   else
1554     Node->getType().print(OS, Policy);
1555   OS << "()";
1556 }
1557 
1558 void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
1559   if (E->isGlobalNew())
1560     OS << "::";
1561   OS << "new ";
1562   unsigned NumPlace = E->getNumPlacementArgs();
1563   if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
1564     OS << "(";
1565     PrintExpr(E->getPlacementArg(0));
1566     for (unsigned i = 1; i < NumPlace; ++i) {
1567       if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
1568         break;
1569       OS << ", ";
1570       PrintExpr(E->getPlacementArg(i));
1571     }
1572     OS << ") ";
1573   }
1574   if (E->isParenTypeId())
1575     OS << "(";
1576   std::string TypeS;
1577   if (Expr *Size = E->getArraySize()) {
1578     llvm::raw_string_ostream s(TypeS);
1579     s << '[';
1580     Size->printPretty(s, Helper, Policy);
1581     s << ']';
1582   }
1583   E->getAllocatedType().print(OS, Policy, TypeS);
1584   if (E->isParenTypeId())
1585     OS << ")";
1586 
1587   CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
1588   if (InitStyle) {
1589     if (InitStyle == CXXNewExpr::CallInit)
1590       OS << "(";
1591     PrintExpr(E->getInitializer());
1592     if (InitStyle == CXXNewExpr::CallInit)
1593       OS << ")";
1594   }
1595 }
1596 
1597 void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1598   if (E->isGlobalDelete())
1599     OS << "::";
1600   OS << "delete ";
1601   if (E->isArrayForm())
1602     OS << "[] ";
1603   PrintExpr(E->getArgument());
1604 }
1605 
1606 void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1607   PrintExpr(E->getBase());
1608   if (E->isArrow())
1609     OS << "->";
1610   else
1611     OS << '.';
1612   if (E->getQualifier())
1613     E->getQualifier()->print(OS, Policy);
1614   OS << "~";
1615 
1616   if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
1617     OS << II->getName();
1618   else
1619     E->getDestroyedType().print(OS, Policy);
1620 }
1621 
1622 void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
1623   if (E->isListInitialization())
1624     OS << "{ ";
1625 
1626   for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
1627     if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
1628       // Don't print any defaulted arguments
1629       break;
1630     }
1631 
1632     if (i) OS << ", ";
1633     PrintExpr(E->getArg(i));
1634   }
1635 
1636   if (E->isListInitialization())
1637     OS << " }";
1638 }
1639 
1640 void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1641   PrintExpr(E->getSubExpr());
1642 }
1643 
1644 void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
1645   // Just forward to the subexpression.
1646   PrintExpr(E->getSubExpr());
1647 }
1648 
1649 void
1650 StmtPrinter::VisitCXXUnresolvedConstructExpr(
1651                                            CXXUnresolvedConstructExpr *Node) {
1652   Node->getTypeAsWritten().print(OS, Policy);
1653   OS << "(";
1654   for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
1655                                              ArgEnd = Node->arg_end();
1656        Arg != ArgEnd; ++Arg) {
1657     if (Arg != Node->arg_begin())
1658       OS << ", ";
1659     PrintExpr(*Arg);
1660   }
1661   OS << ")";
1662 }
1663 
1664 void StmtPrinter::VisitCXXDependentScopeMemberExpr(
1665                                          CXXDependentScopeMemberExpr *Node) {
1666   if (!Node->isImplicitAccess()) {
1667     PrintExpr(Node->getBase());
1668     OS << (Node->isArrow() ? "->" : ".");
1669   }
1670   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1671     Qualifier->print(OS, Policy);
1672   if (Node->hasTemplateKeyword())
1673     OS << "template ";
1674   OS << Node->getMemberNameInfo();
1675   if (Node->hasExplicitTemplateArgs())
1676     TemplateSpecializationType::PrintTemplateArgumentList(
1677         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1678 }
1679 
1680 void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
1681   if (!Node->isImplicitAccess()) {
1682     PrintExpr(Node->getBase());
1683     OS << (Node->isArrow() ? "->" : ".");
1684   }
1685   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1686     Qualifier->print(OS, Policy);
1687   if (Node->hasTemplateKeyword())
1688     OS << "template ";
1689   OS << Node->getMemberNameInfo();
1690   if (Node->hasExplicitTemplateArgs())
1691     TemplateSpecializationType::PrintTemplateArgumentList(
1692         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1693 }
1694 
1695 static const char *getTypeTraitName(TypeTrait TT) {
1696   switch (TT) {
1697 #define TYPE_TRAIT_1(Spelling, Name, Key) \
1698 case clang::UTT_##Name: return #Spelling;
1699 #define TYPE_TRAIT_2(Spelling, Name, Key) \
1700 case clang::BTT_##Name: return #Spelling;
1701 #define TYPE_TRAIT_N(Spelling, Name, Key) \
1702   case clang::TT_##Name: return #Spelling;
1703 #include "clang/Basic/TokenKinds.def"
1704   }
1705   llvm_unreachable("Type trait not covered by switch");
1706 }
1707 
1708 static const char *getTypeTraitName(ArrayTypeTrait ATT) {
1709   switch (ATT) {
1710   case ATT_ArrayRank:        return "__array_rank";
1711   case ATT_ArrayExtent:      return "__array_extent";
1712   }
1713   llvm_unreachable("Array type trait not covered by switch");
1714 }
1715 
1716 static const char *getExpressionTraitName(ExpressionTrait ET) {
1717   switch (ET) {
1718   case ET_IsLValueExpr:      return "__is_lvalue_expr";
1719   case ET_IsRValueExpr:      return "__is_rvalue_expr";
1720   }
1721   llvm_unreachable("Expression type trait not covered by switch");
1722 }
1723 
1724 void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
1725   OS << getTypeTraitName(E->getTrait()) << "(";
1726   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
1727     if (I > 0)
1728       OS << ", ";
1729     E->getArg(I)->getType().print(OS, Policy);
1730   }
1731   OS << ")";
1732 }
1733 
1734 void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
1735   OS << getTypeTraitName(E->getTrait()) << '(';
1736   E->getQueriedType().print(OS, Policy);
1737   OS << ')';
1738 }
1739 
1740 void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
1741   OS << getExpressionTraitName(E->getTrait()) << '(';
1742   PrintExpr(E->getQueriedExpression());
1743   OS << ')';
1744 }
1745 
1746 void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
1747   OS << "noexcept(";
1748   PrintExpr(E->getOperand());
1749   OS << ")";
1750 }
1751 
1752 void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
1753   PrintExpr(E->getPattern());
1754   OS << "...";
1755 }
1756 
1757 void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
1758   OS << "sizeof...(" << *E->getPack() << ")";
1759 }
1760 
1761 void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
1762                                        SubstNonTypeTemplateParmPackExpr *Node) {
1763   OS << *Node->getParameterPack();
1764 }
1765 
1766 void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
1767                                        SubstNonTypeTemplateParmExpr *Node) {
1768   Visit(Node->getReplacement());
1769 }
1770 
1771 void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
1772   OS << *E->getParameterPack();
1773 }
1774 
1775 void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
1776   PrintExpr(Node->GetTemporaryExpr());
1777 }
1778 
1779 // Obj-C
1780 
1781 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
1782   OS << "@";
1783   VisitStringLiteral(Node->getString());
1784 }
1785 
1786 void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1787   OS << "@";
1788   Visit(E->getSubExpr());
1789 }
1790 
1791 void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1792   OS << "@[ ";
1793   StmtRange ch = E->children();
1794   if (ch.first != ch.second) {
1795     while (1) {
1796       Visit(*ch.first);
1797       ++ch.first;
1798       if (ch.first == ch.second) break;
1799       OS << ", ";
1800     }
1801   }
1802   OS << " ]";
1803 }
1804 
1805 void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1806   OS << "@{ ";
1807   for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
1808     if (I > 0)
1809       OS << ", ";
1810 
1811     ObjCDictionaryElement Element = E->getKeyValueElement(I);
1812     Visit(Element.Key);
1813     OS << " : ";
1814     Visit(Element.Value);
1815     if (Element.isPackExpansion())
1816       OS << "...";
1817   }
1818   OS << " }";
1819 }
1820 
1821 void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
1822   OS << "@encode(";
1823   Node->getEncodedType().print(OS, Policy);
1824   OS << ')';
1825 }
1826 
1827 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
1828   OS << "@selector(";
1829   Node->getSelector().print(OS);
1830   OS << ')';
1831 }
1832 
1833 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
1834   OS << "@protocol(" << *Node->getProtocol() << ')';
1835 }
1836 
1837 void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
1838   OS << "[";
1839   switch (Mess->getReceiverKind()) {
1840   case ObjCMessageExpr::Instance:
1841     PrintExpr(Mess->getInstanceReceiver());
1842     break;
1843 
1844   case ObjCMessageExpr::Class:
1845     Mess->getClassReceiver().print(OS, Policy);
1846     break;
1847 
1848   case ObjCMessageExpr::SuperInstance:
1849   case ObjCMessageExpr::SuperClass:
1850     OS << "Super";
1851     break;
1852   }
1853 
1854   OS << ' ';
1855   Selector selector = Mess->getSelector();
1856   if (selector.isUnarySelector()) {
1857     OS << selector.getNameForSlot(0);
1858   } else {
1859     for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
1860       if (i < selector.getNumArgs()) {
1861         if (i > 0) OS << ' ';
1862         if (selector.getIdentifierInfoForSlot(i))
1863           OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
1864         else
1865            OS << ":";
1866       }
1867       else OS << ", "; // Handle variadic methods.
1868 
1869       PrintExpr(Mess->getArg(i));
1870     }
1871   }
1872   OS << "]";
1873 }
1874 
1875 void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
1876   OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
1877 }
1878 
1879 void
1880 StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1881   PrintExpr(E->getSubExpr());
1882 }
1883 
1884 void
1885 StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1886   OS << '(' << E->getBridgeKindName();
1887   E->getType().print(OS, Policy);
1888   OS << ')';
1889   PrintExpr(E->getSubExpr());
1890 }
1891 
1892 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
1893   BlockDecl *BD = Node->getBlockDecl();
1894   OS << "^";
1895 
1896   const FunctionType *AFT = Node->getFunctionType();
1897 
1898   if (isa<FunctionNoProtoType>(AFT)) {
1899     OS << "()";
1900   } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
1901     OS << '(';
1902     for (BlockDecl::param_iterator AI = BD->param_begin(),
1903          E = BD->param_end(); AI != E; ++AI) {
1904       if (AI != BD->param_begin()) OS << ", ";
1905       std::string ParamStr = (*AI)->getNameAsString();
1906       (*AI)->getType().print(OS, Policy, ParamStr);
1907     }
1908 
1909     const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
1910     if (FT->isVariadic()) {
1911       if (!BD->param_empty()) OS << ", ";
1912       OS << "...";
1913     }
1914     OS << ')';
1915   }
1916   OS << "{ }";
1917 }
1918 
1919 void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
1920   PrintExpr(Node->getSourceExpr());
1921 }
1922 
1923 void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
1924   OS << "__builtin_astype(";
1925   PrintExpr(Node->getSrcExpr());
1926   OS << ", ";
1927   Node->getType().print(OS, Policy);
1928   OS << ")";
1929 }
1930 
1931 //===----------------------------------------------------------------------===//
1932 // Stmt method implementations
1933 //===----------------------------------------------------------------------===//
1934 
1935 void Stmt::dumpPretty(const ASTContext &Context) const {
1936   printPretty(llvm::errs(), 0, PrintingPolicy(Context.getLangOpts()));
1937 }
1938 
1939 void Stmt::printPretty(raw_ostream &OS,
1940                        PrinterHelper *Helper,
1941                        const PrintingPolicy &Policy,
1942                        unsigned Indentation) const {
1943   if (this == 0) {
1944     OS << "<NULL>";
1945     return;
1946   }
1947 
1948   StmtPrinter P(OS, Helper, Policy, Indentation);
1949   P.Visit(const_cast<Stmt*>(this));
1950 }
1951 
1952 //===----------------------------------------------------------------------===//
1953 // PrinterHelper
1954 //===----------------------------------------------------------------------===//
1955 
1956 // Implement virtual destructor.
1957 PrinterHelper::~PrinterHelper() {}
1958