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/DeclOpenMP.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/ExprOpenMP.h"
24 #include "clang/AST/PrettyPrinter.h"
25 #include "clang/AST/StmtVisitor.h"
26 #include "clang/Basic/CharInfo.h"
27 #include "llvm/ADT/SmallString.h"
28 #include "llvm/Support/Format.h"
29 using namespace clang;
30 
31 //===----------------------------------------------------------------------===//
32 // StmtPrinter Visitor
33 //===----------------------------------------------------------------------===//
34 
35 namespace  {
36   class StmtPrinter : public StmtVisitor<StmtPrinter> {
37     raw_ostream &OS;
38     unsigned IndentLevel;
39     clang::PrinterHelper* Helper;
40     PrintingPolicy Policy;
41 
42   public:
43     StmtPrinter(raw_ostream &os, PrinterHelper* helper,
44                 const PrintingPolicy &Policy,
45                 unsigned Indentation = 0)
46       : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
47 
48     void PrintStmt(Stmt *S) {
49       PrintStmt(S, Policy.Indentation);
50     }
51 
52     void PrintStmt(Stmt *S, int SubIndent) {
53       IndentLevel += SubIndent;
54       if (S && isa<Expr>(S)) {
55         // If this is an expr used in a stmt context, indent and newline it.
56         Indent();
57         Visit(S);
58         OS << ";\n";
59       } else if (S) {
60         Visit(S);
61       } else {
62         Indent() << "<<<NULL STATEMENT>>>\n";
63       }
64       IndentLevel -= SubIndent;
65     }
66 
67     void PrintRawCompoundStmt(CompoundStmt *S);
68     void PrintRawDecl(Decl *D);
69     void PrintRawDeclStmt(const DeclStmt *S);
70     void PrintRawIfStmt(IfStmt *If);
71     void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
72     void PrintCallArgs(CallExpr *E);
73     void PrintRawSEHExceptHandler(SEHExceptStmt *S);
74     void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
75     void PrintOMPExecutableDirective(OMPExecutableDirective *S);
76 
77     void PrintExpr(Expr *E) {
78       if (E)
79         Visit(E);
80       else
81         OS << "<null expr>";
82     }
83 
84     raw_ostream &Indent(int Delta = 0) {
85       for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
86         OS << "  ";
87       return OS;
88     }
89 
90     void Visit(Stmt* S) {
91       if (Helper && Helper->handledStmt(S,OS))
92           return;
93       else StmtVisitor<StmtPrinter>::Visit(S);
94     }
95 
96     void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
97       Indent() << "<<unknown stmt type>>\n";
98     }
99     void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
100       OS << "<<unknown expr type>>";
101     }
102     void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
103 
104 #define ABSTRACT_STMT(CLASS)
105 #define STMT(CLASS, PARENT) \
106     void Visit##CLASS(CLASS *Node);
107 #include "clang/AST/StmtNodes.inc"
108   };
109 }
110 
111 //===----------------------------------------------------------------------===//
112 //  Stmt printing methods.
113 //===----------------------------------------------------------------------===//
114 
115 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
116 /// with no newline after the }.
117 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
118   OS << "{\n";
119   for (auto *I : Node->body())
120     PrintStmt(I);
121 
122   Indent() << "}";
123 }
124 
125 void StmtPrinter::PrintRawDecl(Decl *D) {
126   D->print(OS, Policy, IndentLevel);
127 }
128 
129 void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
130   SmallVector<Decl*, 2> Decls(S->decls());
131   Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
132 }
133 
134 void StmtPrinter::VisitNullStmt(NullStmt *Node) {
135   Indent() << ";\n";
136 }
137 
138 void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
139   Indent();
140   PrintRawDeclStmt(Node);
141   OS << ";\n";
142 }
143 
144 void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
145   Indent();
146   PrintRawCompoundStmt(Node);
147   OS << "\n";
148 }
149 
150 void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
151   Indent(-1) << "case ";
152   PrintExpr(Node->getLHS());
153   if (Node->getRHS()) {
154     OS << " ... ";
155     PrintExpr(Node->getRHS());
156   }
157   OS << ":\n";
158 
159   PrintStmt(Node->getSubStmt(), 0);
160 }
161 
162 void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
163   Indent(-1) << "default:\n";
164   PrintStmt(Node->getSubStmt(), 0);
165 }
166 
167 void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
168   Indent(-1) << Node->getName() << ":\n";
169   PrintStmt(Node->getSubStmt(), 0);
170 }
171 
172 void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
173   for (const auto *Attr : Node->getAttrs()) {
174     Attr->printPretty(OS, Policy);
175   }
176 
177   PrintStmt(Node->getSubStmt(), 0);
178 }
179 
180 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
181   OS << "if (";
182   if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
183     PrintRawDeclStmt(DS);
184   else
185     PrintExpr(If->getCond());
186   OS << ')';
187 
188   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
189     OS << ' ';
190     PrintRawCompoundStmt(CS);
191     OS << (If->getElse() ? ' ' : '\n');
192   } else {
193     OS << '\n';
194     PrintStmt(If->getThen());
195     if (If->getElse()) Indent();
196   }
197 
198   if (Stmt *Else = If->getElse()) {
199     OS << "else";
200 
201     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
202       OS << ' ';
203       PrintRawCompoundStmt(CS);
204       OS << '\n';
205     } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
206       OS << ' ';
207       PrintRawIfStmt(ElseIf);
208     } else {
209       OS << '\n';
210       PrintStmt(If->getElse());
211     }
212   }
213 }
214 
215 void StmtPrinter::VisitIfStmt(IfStmt *If) {
216   Indent();
217   PrintRawIfStmt(If);
218 }
219 
220 void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
221   Indent() << "switch (";
222   if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
223     PrintRawDeclStmt(DS);
224   else
225     PrintExpr(Node->getCond());
226   OS << ")";
227 
228   // Pretty print compoundstmt bodies (very common).
229   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
230     OS << " ";
231     PrintRawCompoundStmt(CS);
232     OS << "\n";
233   } else {
234     OS << "\n";
235     PrintStmt(Node->getBody());
236   }
237 }
238 
239 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
240   Indent() << "while (";
241   if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
242     PrintRawDeclStmt(DS);
243   else
244     PrintExpr(Node->getCond());
245   OS << ")\n";
246   PrintStmt(Node->getBody());
247 }
248 
249 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
250   Indent() << "do ";
251   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
252     PrintRawCompoundStmt(CS);
253     OS << " ";
254   } else {
255     OS << "\n";
256     PrintStmt(Node->getBody());
257     Indent();
258   }
259 
260   OS << "while (";
261   PrintExpr(Node->getCond());
262   OS << ");\n";
263 }
264 
265 void StmtPrinter::VisitForStmt(ForStmt *Node) {
266   Indent() << "for (";
267   if (Node->getInit()) {
268     if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
269       PrintRawDeclStmt(DS);
270     else
271       PrintExpr(cast<Expr>(Node->getInit()));
272   }
273   OS << ";";
274   if (Node->getCond()) {
275     OS << " ";
276     PrintExpr(Node->getCond());
277   }
278   OS << ";";
279   if (Node->getInc()) {
280     OS << " ";
281     PrintExpr(Node->getInc());
282   }
283   OS << ") ";
284 
285   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
286     PrintRawCompoundStmt(CS);
287     OS << "\n";
288   } else {
289     OS << "\n";
290     PrintStmt(Node->getBody());
291   }
292 }
293 
294 void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
295   Indent() << "for (";
296   if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
297     PrintRawDeclStmt(DS);
298   else
299     PrintExpr(cast<Expr>(Node->getElement()));
300   OS << " in ";
301   PrintExpr(Node->getCollection());
302   OS << ") ";
303 
304   if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
305     PrintRawCompoundStmt(CS);
306     OS << "\n";
307   } else {
308     OS << "\n";
309     PrintStmt(Node->getBody());
310   }
311 }
312 
313 void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
314   Indent() << "for (";
315   PrintingPolicy SubPolicy(Policy);
316   SubPolicy.SuppressInitializers = true;
317   Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
318   OS << " : ";
319   PrintExpr(Node->getRangeInit());
320   OS << ") {\n";
321   PrintStmt(Node->getBody());
322   Indent() << "}";
323   if (Policy.IncludeNewlines) OS << "\n";
324 }
325 
326 void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
327   Indent();
328   if (Node->isIfExists())
329     OS << "__if_exists (";
330   else
331     OS << "__if_not_exists (";
332 
333   if (NestedNameSpecifier *Qualifier
334         = Node->getQualifierLoc().getNestedNameSpecifier())
335     Qualifier->print(OS, Policy);
336 
337   OS << Node->getNameInfo() << ") ";
338 
339   PrintRawCompoundStmt(Node->getSubStmt());
340 }
341 
342 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
343   Indent() << "goto " << Node->getLabel()->getName() << ";";
344   if (Policy.IncludeNewlines) OS << "\n";
345 }
346 
347 void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
348   Indent() << "goto *";
349   PrintExpr(Node->getTarget());
350   OS << ";";
351   if (Policy.IncludeNewlines) OS << "\n";
352 }
353 
354 void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
355   Indent() << "continue;";
356   if (Policy.IncludeNewlines) OS << "\n";
357 }
358 
359 void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
360   Indent() << "break;";
361   if (Policy.IncludeNewlines) OS << "\n";
362 }
363 
364 
365 void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
366   Indent() << "return";
367   if (Node->getRetValue()) {
368     OS << " ";
369     PrintExpr(Node->getRetValue());
370   }
371   OS << ";";
372   if (Policy.IncludeNewlines) OS << "\n";
373 }
374 
375 
376 void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
377   Indent() << "asm ";
378 
379   if (Node->isVolatile())
380     OS << "volatile ";
381 
382   OS << "(";
383   VisitStringLiteral(Node->getAsmString());
384 
385   // Outputs
386   if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
387       Node->getNumClobbers() != 0)
388     OS << " : ";
389 
390   for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
391     if (i != 0)
392       OS << ", ";
393 
394     if (!Node->getOutputName(i).empty()) {
395       OS << '[';
396       OS << Node->getOutputName(i);
397       OS << "] ";
398     }
399 
400     VisitStringLiteral(Node->getOutputConstraintLiteral(i));
401     OS << " (";
402     Visit(Node->getOutputExpr(i));
403     OS << ")";
404   }
405 
406   // Inputs
407   if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
408     OS << " : ";
409 
410   for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
411     if (i != 0)
412       OS << ", ";
413 
414     if (!Node->getInputName(i).empty()) {
415       OS << '[';
416       OS << Node->getInputName(i);
417       OS << "] ";
418     }
419 
420     VisitStringLiteral(Node->getInputConstraintLiteral(i));
421     OS << " (";
422     Visit(Node->getInputExpr(i));
423     OS << ")";
424   }
425 
426   // Clobbers
427   if (Node->getNumClobbers() != 0)
428     OS << " : ";
429 
430   for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
431     if (i != 0)
432       OS << ", ";
433 
434     VisitStringLiteral(Node->getClobberStringLiteral(i));
435   }
436 
437   OS << ");";
438   if (Policy.IncludeNewlines) OS << "\n";
439 }
440 
441 void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
442   // FIXME: Implement MS style inline asm statement printer.
443   Indent() << "__asm ";
444   if (Node->hasBraces())
445     OS << "{\n";
446   OS << Node->getAsmString() << "\n";
447   if (Node->hasBraces())
448     Indent() << "}\n";
449 }
450 
451 void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
452   PrintStmt(Node->getCapturedDecl()->getBody());
453 }
454 
455 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
456   Indent() << "@try";
457   if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
458     PrintRawCompoundStmt(TS);
459     OS << "\n";
460   }
461 
462   for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
463     ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
464     Indent() << "@catch(";
465     if (catchStmt->getCatchParamDecl()) {
466       if (Decl *DS = catchStmt->getCatchParamDecl())
467         PrintRawDecl(DS);
468     }
469     OS << ")";
470     if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
471       PrintRawCompoundStmt(CS);
472       OS << "\n";
473     }
474   }
475 
476   if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
477         Node->getFinallyStmt())) {
478     Indent() << "@finally";
479     PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
480     OS << "\n";
481   }
482 }
483 
484 void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
485 }
486 
487 void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
488   Indent() << "@catch (...) { /* todo */ } \n";
489 }
490 
491 void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
492   Indent() << "@throw";
493   if (Node->getThrowExpr()) {
494     OS << " ";
495     PrintExpr(Node->getThrowExpr());
496   }
497   OS << ";\n";
498 }
499 
500 void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
501   Indent() << "@synchronized (";
502   PrintExpr(Node->getSynchExpr());
503   OS << ")";
504   PrintRawCompoundStmt(Node->getSynchBody());
505   OS << "\n";
506 }
507 
508 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
509   Indent() << "@autoreleasepool";
510   PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
511   OS << "\n";
512 }
513 
514 void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
515   OS << "catch (";
516   if (Decl *ExDecl = Node->getExceptionDecl())
517     PrintRawDecl(ExDecl);
518   else
519     OS << "...";
520   OS << ") ";
521   PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
522 }
523 
524 void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
525   Indent();
526   PrintRawCXXCatchStmt(Node);
527   OS << "\n";
528 }
529 
530 void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
531   Indent() << "try ";
532   PrintRawCompoundStmt(Node->getTryBlock());
533   for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
534     OS << " ";
535     PrintRawCXXCatchStmt(Node->getHandler(i));
536   }
537   OS << "\n";
538 }
539 
540 void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
541   Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
542   PrintRawCompoundStmt(Node->getTryBlock());
543   SEHExceptStmt *E = Node->getExceptHandler();
544   SEHFinallyStmt *F = Node->getFinallyHandler();
545   if(E)
546     PrintRawSEHExceptHandler(E);
547   else {
548     assert(F && "Must have a finally block...");
549     PrintRawSEHFinallyStmt(F);
550   }
551   OS << "\n";
552 }
553 
554 void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
555   OS << "__finally ";
556   PrintRawCompoundStmt(Node->getBlock());
557   OS << "\n";
558 }
559 
560 void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
561   OS << "__except (";
562   VisitExpr(Node->getFilterExpr());
563   OS << ")\n";
564   PrintRawCompoundStmt(Node->getBlock());
565   OS << "\n";
566 }
567 
568 void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
569   Indent();
570   PrintRawSEHExceptHandler(Node);
571   OS << "\n";
572 }
573 
574 void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
575   Indent();
576   PrintRawSEHFinallyStmt(Node);
577   OS << "\n";
578 }
579 
580 void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
581   Indent() << "__leave;";
582   if (Policy.IncludeNewlines) OS << "\n";
583 }
584 
585 //===----------------------------------------------------------------------===//
586 //  OpenMP clauses printing methods
587 //===----------------------------------------------------------------------===//
588 
589 namespace {
590 class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
591   raw_ostream &OS;
592   const PrintingPolicy &Policy;
593   /// \brief Process clauses with list of variables.
594   template <typename T>
595   void VisitOMPClauseList(T *Node, char StartSym);
596 public:
597   OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
598     : OS(OS), Policy(Policy) { }
599 #define OPENMP_CLAUSE(Name, Class)                              \
600   void Visit##Class(Class *S);
601 #include "clang/Basic/OpenMPKinds.def"
602 };
603 
604 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
605   OS << "if(";
606   if (Node->getNameModifier() != OMPD_unknown)
607     OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
608   Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
609   OS << ")";
610 }
611 
612 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
613   OS << "final(";
614   Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
615   OS << ")";
616 }
617 
618 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
619   OS << "num_threads(";
620   Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
621   OS << ")";
622 }
623 
624 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
625   OS << "safelen(";
626   Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
627   OS << ")";
628 }
629 
630 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
631   OS << "simdlen(";
632   Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
633   OS << ")";
634 }
635 
636 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
637   OS << "collapse(";
638   Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
639   OS << ")";
640 }
641 
642 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
643   OS << "default("
644      << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
645      << ")";
646 }
647 
648 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
649   OS << "proc_bind("
650      << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
651      << ")";
652 }
653 
654 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
655   OS << "schedule(";
656   if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
657     OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
658                                         Node->getFirstScheduleModifier());
659     if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
660       OS << ", ";
661       OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
662                                           Node->getSecondScheduleModifier());
663     }
664     OS << ": ";
665   }
666   OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
667   if (auto *E = Node->getChunkSize()) {
668     OS << ", ";
669     E->printPretty(OS, nullptr, Policy);
670   }
671   OS << ")";
672 }
673 
674 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
675   OS << "ordered";
676   if (auto *Num = Node->getNumForLoops()) {
677     OS << "(";
678     Num->printPretty(OS, nullptr, Policy, 0);
679     OS << ")";
680   }
681 }
682 
683 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
684   OS << "nowait";
685 }
686 
687 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
688   OS << "untied";
689 }
690 
691 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
692   OS << "nogroup";
693 }
694 
695 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
696   OS << "mergeable";
697 }
698 
699 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
700 
701 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
702 
703 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
704   OS << "update";
705 }
706 
707 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
708   OS << "capture";
709 }
710 
711 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
712   OS << "seq_cst";
713 }
714 
715 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
716   OS << "threads";
717 }
718 
719 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
720 
721 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
722   OS << "device(";
723   Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
724   OS << ")";
725 }
726 
727 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
728   OS << "num_teams(";
729   Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
730   OS << ")";
731 }
732 
733 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
734   OS << "thread_limit(";
735   Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
736   OS << ")";
737 }
738 
739 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
740   OS << "priority(";
741   Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
742   OS << ")";
743 }
744 
745 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
746   OS << "grainsize(";
747   Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
748   OS << ")";
749 }
750 
751 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
752   OS << "num_tasks(";
753   Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
754   OS << ")";
755 }
756 
757 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
758   OS << "hint(";
759   Node->getHint()->printPretty(OS, nullptr, Policy, 0);
760   OS << ")";
761 }
762 
763 template<typename T>
764 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
765   for (typename T::varlist_iterator I = Node->varlist_begin(),
766                                     E = Node->varlist_end();
767        I != E; ++I) {
768     assert(*I && "Expected non-null Stmt");
769     OS << (I == Node->varlist_begin() ? StartSym : ',');
770     if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(*I)) {
771       if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
772         DRE->printPretty(OS, nullptr, Policy, 0);
773       else
774         DRE->getDecl()->printQualifiedName(OS);
775     } else
776       (*I)->printPretty(OS, nullptr, Policy, 0);
777   }
778 }
779 
780 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
781   if (!Node->varlist_empty()) {
782     OS << "private";
783     VisitOMPClauseList(Node, '(');
784     OS << ")";
785   }
786 }
787 
788 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
789   if (!Node->varlist_empty()) {
790     OS << "firstprivate";
791     VisitOMPClauseList(Node, '(');
792     OS << ")";
793   }
794 }
795 
796 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
797   if (!Node->varlist_empty()) {
798     OS << "lastprivate";
799     VisitOMPClauseList(Node, '(');
800     OS << ")";
801   }
802 }
803 
804 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
805   if (!Node->varlist_empty()) {
806     OS << "shared";
807     VisitOMPClauseList(Node, '(');
808     OS << ")";
809   }
810 }
811 
812 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
813   if (!Node->varlist_empty()) {
814     OS << "reduction(";
815     NestedNameSpecifier *QualifierLoc =
816         Node->getQualifierLoc().getNestedNameSpecifier();
817     OverloadedOperatorKind OOK =
818         Node->getNameInfo().getName().getCXXOverloadedOperator();
819     if (QualifierLoc == nullptr && OOK != OO_None) {
820       // Print reduction identifier in C format
821       OS << getOperatorSpelling(OOK);
822     } else {
823       // Use C++ format
824       if (QualifierLoc != nullptr)
825         QualifierLoc->print(OS, Policy);
826       OS << Node->getNameInfo();
827     }
828     OS << ":";
829     VisitOMPClauseList(Node, ' ');
830     OS << ")";
831   }
832 }
833 
834 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
835   if (!Node->varlist_empty()) {
836     OS << "linear";
837     if (Node->getModifierLoc().isValid()) {
838       OS << '('
839          << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
840     }
841     VisitOMPClauseList(Node, '(');
842     if (Node->getModifierLoc().isValid())
843       OS << ')';
844     if (Node->getStep() != nullptr) {
845       OS << ": ";
846       Node->getStep()->printPretty(OS, nullptr, Policy, 0);
847     }
848     OS << ")";
849   }
850 }
851 
852 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
853   if (!Node->varlist_empty()) {
854     OS << "aligned";
855     VisitOMPClauseList(Node, '(');
856     if (Node->getAlignment() != nullptr) {
857       OS << ": ";
858       Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
859     }
860     OS << ")";
861   }
862 }
863 
864 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
865   if (!Node->varlist_empty()) {
866     OS << "copyin";
867     VisitOMPClauseList(Node, '(');
868     OS << ")";
869   }
870 }
871 
872 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
873   if (!Node->varlist_empty()) {
874     OS << "copyprivate";
875     VisitOMPClauseList(Node, '(');
876     OS << ")";
877   }
878 }
879 
880 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
881   if (!Node->varlist_empty()) {
882     VisitOMPClauseList(Node, '(');
883     OS << ")";
884   }
885 }
886 
887 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
888   OS << "depend(";
889   OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
890                                       Node->getDependencyKind());
891   if (!Node->varlist_empty()) {
892     OS << " :";
893     VisitOMPClauseList(Node, ' ');
894   }
895   OS << ")";
896 }
897 
898 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
899   if (!Node->varlist_empty()) {
900     OS << "map(";
901     if (Node->getMapType() != OMPC_MAP_unknown) {
902       if (Node->getMapTypeModifier() != OMPC_MAP_unknown) {
903         OS << getOpenMPSimpleClauseTypeName(OMPC_map,
904                                             Node->getMapTypeModifier());
905         OS << ',';
906       }
907       OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
908       OS << ':';
909     }
910     VisitOMPClauseList(Node, ' ');
911     OS << ")";
912   }
913 }
914 
915 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
916   OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
917                            OMPC_dist_schedule, Node->getDistScheduleKind());
918   if (auto *E = Node->getChunkSize()) {
919     OS << ", ";
920     E->printPretty(OS, nullptr, Policy);
921   }
922   OS << ")";
923 }
924 
925 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
926   OS << "defaultmap(";
927   OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
928                                       Node->getDefaultmapModifier());
929   OS << ": ";
930   OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
931     Node->getDefaultmapKind());
932   OS << ")";
933 }
934 }
935 
936 //===----------------------------------------------------------------------===//
937 //  OpenMP directives printing methods
938 //===----------------------------------------------------------------------===//
939 
940 void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S) {
941   OMPClausePrinter Printer(OS, Policy);
942   ArrayRef<OMPClause *> Clauses = S->clauses();
943   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
944        I != E; ++I)
945     if (*I && !(*I)->isImplicit()) {
946       Printer.Visit(*I);
947       OS << ' ';
948     }
949   OS << "\n";
950   if (S->hasAssociatedStmt() && S->getAssociatedStmt()) {
951     assert(isa<CapturedStmt>(S->getAssociatedStmt()) &&
952            "Expected captured statement!");
953     Stmt *CS = cast<CapturedStmt>(S->getAssociatedStmt())->getCapturedStmt();
954     PrintStmt(CS);
955   }
956 }
957 
958 void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
959   Indent() << "#pragma omp parallel ";
960   PrintOMPExecutableDirective(Node);
961 }
962 
963 void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
964   Indent() << "#pragma omp simd ";
965   PrintOMPExecutableDirective(Node);
966 }
967 
968 void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
969   Indent() << "#pragma omp for ";
970   PrintOMPExecutableDirective(Node);
971 }
972 
973 void StmtPrinter::VisitOMPForSimdDirective(OMPForSimdDirective *Node) {
974   Indent() << "#pragma omp for simd ";
975   PrintOMPExecutableDirective(Node);
976 }
977 
978 void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
979   Indent() << "#pragma omp sections ";
980   PrintOMPExecutableDirective(Node);
981 }
982 
983 void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
984   Indent() << "#pragma omp section";
985   PrintOMPExecutableDirective(Node);
986 }
987 
988 void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
989   Indent() << "#pragma omp single ";
990   PrintOMPExecutableDirective(Node);
991 }
992 
993 void StmtPrinter::VisitOMPMasterDirective(OMPMasterDirective *Node) {
994   Indent() << "#pragma omp master";
995   PrintOMPExecutableDirective(Node);
996 }
997 
998 void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) {
999   Indent() << "#pragma omp critical";
1000   if (Node->getDirectiveName().getName()) {
1001     OS << " (";
1002     Node->getDirectiveName().printName(OS);
1003     OS << ")";
1004   }
1005   OS << " ";
1006   PrintOMPExecutableDirective(Node);
1007 }
1008 
1009 void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) {
1010   Indent() << "#pragma omp parallel for ";
1011   PrintOMPExecutableDirective(Node);
1012 }
1013 
1014 void StmtPrinter::VisitOMPParallelForSimdDirective(
1015     OMPParallelForSimdDirective *Node) {
1016   Indent() << "#pragma omp parallel for simd ";
1017   PrintOMPExecutableDirective(Node);
1018 }
1019 
1020 void StmtPrinter::VisitOMPParallelSectionsDirective(
1021     OMPParallelSectionsDirective *Node) {
1022   Indent() << "#pragma omp parallel sections ";
1023   PrintOMPExecutableDirective(Node);
1024 }
1025 
1026 void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) {
1027   Indent() << "#pragma omp task ";
1028   PrintOMPExecutableDirective(Node);
1029 }
1030 
1031 void StmtPrinter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *Node) {
1032   Indent() << "#pragma omp taskyield";
1033   PrintOMPExecutableDirective(Node);
1034 }
1035 
1036 void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) {
1037   Indent() << "#pragma omp barrier";
1038   PrintOMPExecutableDirective(Node);
1039 }
1040 
1041 void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) {
1042   Indent() << "#pragma omp taskwait";
1043   PrintOMPExecutableDirective(Node);
1044 }
1045 
1046 void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) {
1047   Indent() << "#pragma omp taskgroup";
1048   PrintOMPExecutableDirective(Node);
1049 }
1050 
1051 void StmtPrinter::VisitOMPFlushDirective(OMPFlushDirective *Node) {
1052   Indent() << "#pragma omp flush ";
1053   PrintOMPExecutableDirective(Node);
1054 }
1055 
1056 void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
1057   Indent() << "#pragma omp ordered ";
1058   PrintOMPExecutableDirective(Node);
1059 }
1060 
1061 void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) {
1062   Indent() << "#pragma omp atomic ";
1063   PrintOMPExecutableDirective(Node);
1064 }
1065 
1066 void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) {
1067   Indent() << "#pragma omp target ";
1068   PrintOMPExecutableDirective(Node);
1069 }
1070 
1071 void StmtPrinter::VisitOMPTargetDataDirective(OMPTargetDataDirective *Node) {
1072   Indent() << "#pragma omp target data ";
1073   PrintOMPExecutableDirective(Node);
1074 }
1075 
1076 void StmtPrinter::VisitOMPTargetEnterDataDirective(
1077     OMPTargetEnterDataDirective *Node) {
1078   Indent() << "#pragma omp target enter data ";
1079   PrintOMPExecutableDirective(Node);
1080 }
1081 
1082 void StmtPrinter::VisitOMPTargetExitDataDirective(
1083     OMPTargetExitDataDirective *Node) {
1084   Indent() << "#pragma omp target exit data ";
1085   PrintOMPExecutableDirective(Node);
1086 }
1087 
1088 void StmtPrinter::VisitOMPTargetParallelDirective(
1089     OMPTargetParallelDirective *Node) {
1090   Indent() << "#pragma omp target parallel ";
1091   PrintOMPExecutableDirective(Node);
1092 }
1093 
1094 void StmtPrinter::VisitOMPTargetParallelForDirective(
1095     OMPTargetParallelForDirective *Node) {
1096   Indent() << "#pragma omp target parallel for ";
1097   PrintOMPExecutableDirective(Node);
1098 }
1099 
1100 void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {
1101   Indent() << "#pragma omp teams ";
1102   PrintOMPExecutableDirective(Node);
1103 }
1104 
1105 void StmtPrinter::VisitOMPCancellationPointDirective(
1106     OMPCancellationPointDirective *Node) {
1107   Indent() << "#pragma omp cancellation point "
1108            << getOpenMPDirectiveName(Node->getCancelRegion());
1109   PrintOMPExecutableDirective(Node);
1110 }
1111 
1112 void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
1113   Indent() << "#pragma omp cancel "
1114            << getOpenMPDirectiveName(Node->getCancelRegion()) << " ";
1115   PrintOMPExecutableDirective(Node);
1116 }
1117 
1118 void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) {
1119   Indent() << "#pragma omp taskloop ";
1120   PrintOMPExecutableDirective(Node);
1121 }
1122 
1123 void StmtPrinter::VisitOMPTaskLoopSimdDirective(
1124     OMPTaskLoopSimdDirective *Node) {
1125   Indent() << "#pragma omp taskloop simd ";
1126   PrintOMPExecutableDirective(Node);
1127 }
1128 
1129 void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) {
1130   Indent() << "#pragma omp distribute ";
1131   PrintOMPExecutableDirective(Node);
1132 }
1133 
1134 //===----------------------------------------------------------------------===//
1135 //  Expr printing methods.
1136 //===----------------------------------------------------------------------===//
1137 
1138 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
1139   if (auto *OCED = dyn_cast<OMPCapturedExprDecl>(Node->getDecl())) {
1140     OCED->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy);
1141     return;
1142   }
1143   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1144     Qualifier->print(OS, Policy);
1145   if (Node->hasTemplateKeyword())
1146     OS << "template ";
1147   OS << Node->getNameInfo();
1148   if (Node->hasExplicitTemplateArgs())
1149     TemplateSpecializationType::PrintTemplateArgumentList(
1150         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1151 }
1152 
1153 void StmtPrinter::VisitDependentScopeDeclRefExpr(
1154                                            DependentScopeDeclRefExpr *Node) {
1155   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1156     Qualifier->print(OS, Policy);
1157   if (Node->hasTemplateKeyword())
1158     OS << "template ";
1159   OS << Node->getNameInfo();
1160   if (Node->hasExplicitTemplateArgs())
1161     TemplateSpecializationType::PrintTemplateArgumentList(
1162         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1163 }
1164 
1165 void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
1166   if (Node->getQualifier())
1167     Node->getQualifier()->print(OS, Policy);
1168   if (Node->hasTemplateKeyword())
1169     OS << "template ";
1170   OS << Node->getNameInfo();
1171   if (Node->hasExplicitTemplateArgs())
1172     TemplateSpecializationType::PrintTemplateArgumentList(
1173         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1174 }
1175 
1176 void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
1177   if (Node->getBase()) {
1178     PrintExpr(Node->getBase());
1179     OS << (Node->isArrow() ? "->" : ".");
1180   }
1181   OS << *Node->getDecl();
1182 }
1183 
1184 void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
1185   if (Node->isSuperReceiver())
1186     OS << "super.";
1187   else if (Node->isObjectReceiver() && Node->getBase()) {
1188     PrintExpr(Node->getBase());
1189     OS << ".";
1190   } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
1191     OS << Node->getClassReceiver()->getName() << ".";
1192   }
1193 
1194   if (Node->isImplicitProperty())
1195     Node->getImplicitPropertyGetter()->getSelector().print(OS);
1196   else
1197     OS << Node->getExplicitProperty()->getName();
1198 }
1199 
1200 void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
1201 
1202   PrintExpr(Node->getBaseExpr());
1203   OS << "[";
1204   PrintExpr(Node->getKeyExpr());
1205   OS << "]";
1206 }
1207 
1208 void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
1209   OS << PredefinedExpr::getIdentTypeName(Node->getIdentType());
1210 }
1211 
1212 void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
1213   unsigned value = Node->getValue();
1214 
1215   switch (Node->getKind()) {
1216   case CharacterLiteral::Ascii: break; // no prefix.
1217   case CharacterLiteral::Wide:  OS << 'L'; break;
1218   case CharacterLiteral::UTF8:  OS << "u8"; break;
1219   case CharacterLiteral::UTF16: OS << 'u'; break;
1220   case CharacterLiteral::UTF32: OS << 'U'; break;
1221   }
1222 
1223   switch (value) {
1224   case '\\':
1225     OS << "'\\\\'";
1226     break;
1227   case '\'':
1228     OS << "'\\''";
1229     break;
1230   case '\a':
1231     // TODO: K&R: the meaning of '\\a' is different in traditional C
1232     OS << "'\\a'";
1233     break;
1234   case '\b':
1235     OS << "'\\b'";
1236     break;
1237   // Nonstandard escape sequence.
1238   /*case '\e':
1239     OS << "'\\e'";
1240     break;*/
1241   case '\f':
1242     OS << "'\\f'";
1243     break;
1244   case '\n':
1245     OS << "'\\n'";
1246     break;
1247   case '\r':
1248     OS << "'\\r'";
1249     break;
1250   case '\t':
1251     OS << "'\\t'";
1252     break;
1253   case '\v':
1254     OS << "'\\v'";
1255     break;
1256   default:
1257     // A character literal might be sign-extended, which
1258     // would result in an invalid \U escape sequence.
1259     // FIXME: multicharacter literals such as '\xFF\xFF\xFF\xFF'
1260     // are not correctly handled.
1261     if ((value & ~0xFFu) == ~0xFFu && Node->getKind() == CharacterLiteral::Ascii)
1262       value &= 0xFFu;
1263     if (value < 256 && isPrintable((unsigned char)value))
1264       OS << "'" << (char)value << "'";
1265     else if (value < 256)
1266       OS << "'\\x" << llvm::format("%02x", value) << "'";
1267     else if (value <= 0xFFFF)
1268       OS << "'\\u" << llvm::format("%04x", value) << "'";
1269     else
1270       OS << "'\\U" << llvm::format("%08x", value) << "'";
1271   }
1272 }
1273 
1274 void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
1275   bool isSigned = Node->getType()->isSignedIntegerType();
1276   OS << Node->getValue().toString(10, isSigned);
1277 
1278   // Emit suffixes.  Integer literals are always a builtin integer type.
1279   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1280   default: llvm_unreachable("Unexpected type for integer literal!");
1281   case BuiltinType::Char_S:
1282   case BuiltinType::Char_U:    OS << "i8"; break;
1283   case BuiltinType::UChar:     OS << "Ui8"; break;
1284   case BuiltinType::Short:     OS << "i16"; break;
1285   case BuiltinType::UShort:    OS << "Ui16"; break;
1286   case BuiltinType::Int:       break; // no suffix.
1287   case BuiltinType::UInt:      OS << 'U'; break;
1288   case BuiltinType::Long:      OS << 'L'; break;
1289   case BuiltinType::ULong:     OS << "UL"; break;
1290   case BuiltinType::LongLong:  OS << "LL"; break;
1291   case BuiltinType::ULongLong: OS << "ULL"; break;
1292   }
1293 }
1294 
1295 static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
1296                                  bool PrintSuffix) {
1297   SmallString<16> Str;
1298   Node->getValue().toString(Str);
1299   OS << Str;
1300   if (Str.find_first_not_of("-0123456789") == StringRef::npos)
1301     OS << '.'; // Trailing dot in order to separate from ints.
1302 
1303   if (!PrintSuffix)
1304     return;
1305 
1306   // Emit suffixes.  Float literals are always a builtin float type.
1307   switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1308   default: llvm_unreachable("Unexpected type for float literal!");
1309   case BuiltinType::Half:       break; // FIXME: suffix?
1310   case BuiltinType::Double:     break; // no suffix.
1311   case BuiltinType::Float:      OS << 'F'; break;
1312   case BuiltinType::LongDouble: OS << 'L'; break;
1313   }
1314 }
1315 
1316 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
1317   PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
1318 }
1319 
1320 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
1321   PrintExpr(Node->getSubExpr());
1322   OS << "i";
1323 }
1324 
1325 void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
1326   Str->outputString(OS);
1327 }
1328 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
1329   OS << "(";
1330   PrintExpr(Node->getSubExpr());
1331   OS << ")";
1332 }
1333 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
1334   if (!Node->isPostfix()) {
1335     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1336 
1337     // Print a space if this is an "identifier operator" like __real, or if
1338     // it might be concatenated incorrectly like '+'.
1339     switch (Node->getOpcode()) {
1340     default: break;
1341     case UO_Real:
1342     case UO_Imag:
1343     case UO_Extension:
1344       OS << ' ';
1345       break;
1346     case UO_Plus:
1347     case UO_Minus:
1348       if (isa<UnaryOperator>(Node->getSubExpr()))
1349         OS << ' ';
1350       break;
1351     }
1352   }
1353   PrintExpr(Node->getSubExpr());
1354 
1355   if (Node->isPostfix())
1356     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1357 }
1358 
1359 void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
1360   OS << "__builtin_offsetof(";
1361   Node->getTypeSourceInfo()->getType().print(OS, Policy);
1362   OS << ", ";
1363   bool PrintedSomething = false;
1364   for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
1365     OffsetOfNode ON = Node->getComponent(i);
1366     if (ON.getKind() == OffsetOfNode::Array) {
1367       // Array node
1368       OS << "[";
1369       PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
1370       OS << "]";
1371       PrintedSomething = true;
1372       continue;
1373     }
1374 
1375     // Skip implicit base indirections.
1376     if (ON.getKind() == OffsetOfNode::Base)
1377       continue;
1378 
1379     // Field or identifier node.
1380     IdentifierInfo *Id = ON.getFieldName();
1381     if (!Id)
1382       continue;
1383 
1384     if (PrintedSomething)
1385       OS << ".";
1386     else
1387       PrintedSomething = true;
1388     OS << Id->getName();
1389   }
1390   OS << ")";
1391 }
1392 
1393 void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
1394   switch(Node->getKind()) {
1395   case UETT_SizeOf:
1396     OS << "sizeof";
1397     break;
1398   case UETT_AlignOf:
1399     if (Policy.LangOpts.CPlusPlus)
1400       OS << "alignof";
1401     else if (Policy.LangOpts.C11)
1402       OS << "_Alignof";
1403     else
1404       OS << "__alignof";
1405     break;
1406   case UETT_VecStep:
1407     OS << "vec_step";
1408     break;
1409   case UETT_OpenMPRequiredSimdAlign:
1410     OS << "__builtin_omp_required_simd_align";
1411     break;
1412   }
1413   if (Node->isArgumentType()) {
1414     OS << '(';
1415     Node->getArgumentType().print(OS, Policy);
1416     OS << ')';
1417   } else {
1418     OS << " ";
1419     PrintExpr(Node->getArgumentExpr());
1420   }
1421 }
1422 
1423 void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1424   OS << "_Generic(";
1425   PrintExpr(Node->getControllingExpr());
1426   for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
1427     OS << ", ";
1428     QualType T = Node->getAssocType(i);
1429     if (T.isNull())
1430       OS << "default";
1431     else
1432       T.print(OS, Policy);
1433     OS << ": ";
1434     PrintExpr(Node->getAssocExpr(i));
1435   }
1436   OS << ")";
1437 }
1438 
1439 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
1440   PrintExpr(Node->getLHS());
1441   OS << "[";
1442   PrintExpr(Node->getRHS());
1443   OS << "]";
1444 }
1445 
1446 void StmtPrinter::VisitOMPArraySectionExpr(OMPArraySectionExpr *Node) {
1447   PrintExpr(Node->getBase());
1448   OS << "[";
1449   if (Node->getLowerBound())
1450     PrintExpr(Node->getLowerBound());
1451   if (Node->getColonLoc().isValid()) {
1452     OS << ":";
1453     if (Node->getLength())
1454       PrintExpr(Node->getLength());
1455   }
1456   OS << "]";
1457 }
1458 
1459 void StmtPrinter::PrintCallArgs(CallExpr *Call) {
1460   for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
1461     if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1462       // Don't print any defaulted arguments
1463       break;
1464     }
1465 
1466     if (i) OS << ", ";
1467     PrintExpr(Call->getArg(i));
1468   }
1469 }
1470 
1471 void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1472   PrintExpr(Call->getCallee());
1473   OS << "(";
1474   PrintCallArgs(Call);
1475   OS << ")";
1476 }
1477 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1478   // FIXME: Suppress printing implicit bases (like "this")
1479   PrintExpr(Node->getBase());
1480 
1481   MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1482   FieldDecl  *ParentDecl   = ParentMember
1483     ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : nullptr;
1484 
1485   if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1486     OS << (Node->isArrow() ? "->" : ".");
1487 
1488   if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1489     if (FD->isAnonymousStructOrUnion())
1490       return;
1491 
1492   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1493     Qualifier->print(OS, Policy);
1494   if (Node->hasTemplateKeyword())
1495     OS << "template ";
1496   OS << Node->getMemberNameInfo();
1497   if (Node->hasExplicitTemplateArgs())
1498     TemplateSpecializationType::PrintTemplateArgumentList(
1499         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1500 }
1501 void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1502   PrintExpr(Node->getBase());
1503   OS << (Node->isArrow() ? "->isa" : ".isa");
1504 }
1505 
1506 void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1507   PrintExpr(Node->getBase());
1508   OS << ".";
1509   OS << Node->getAccessor().getName();
1510 }
1511 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1512   OS << '(';
1513   Node->getTypeAsWritten().print(OS, Policy);
1514   OS << ')';
1515   PrintExpr(Node->getSubExpr());
1516 }
1517 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1518   OS << '(';
1519   Node->getType().print(OS, Policy);
1520   OS << ')';
1521   PrintExpr(Node->getInitializer());
1522 }
1523 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1524   // No need to print anything, simply forward to the subexpression.
1525   PrintExpr(Node->getSubExpr());
1526 }
1527 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1528   PrintExpr(Node->getLHS());
1529   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1530   PrintExpr(Node->getRHS());
1531 }
1532 void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1533   PrintExpr(Node->getLHS());
1534   OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1535   PrintExpr(Node->getRHS());
1536 }
1537 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1538   PrintExpr(Node->getCond());
1539   OS << " ? ";
1540   PrintExpr(Node->getLHS());
1541   OS << " : ";
1542   PrintExpr(Node->getRHS());
1543 }
1544 
1545 // GNU extensions.
1546 
1547 void
1548 StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1549   PrintExpr(Node->getCommon());
1550   OS << " ?: ";
1551   PrintExpr(Node->getFalseExpr());
1552 }
1553 void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1554   OS << "&&" << Node->getLabel()->getName();
1555 }
1556 
1557 void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1558   OS << "(";
1559   PrintRawCompoundStmt(E->getSubStmt());
1560   OS << ")";
1561 }
1562 
1563 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1564   OS << "__builtin_choose_expr(";
1565   PrintExpr(Node->getCond());
1566   OS << ", ";
1567   PrintExpr(Node->getLHS());
1568   OS << ", ";
1569   PrintExpr(Node->getRHS());
1570   OS << ")";
1571 }
1572 
1573 void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1574   OS << "__null";
1575 }
1576 
1577 void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1578   OS << "__builtin_shufflevector(";
1579   for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1580     if (i) OS << ", ";
1581     PrintExpr(Node->getExpr(i));
1582   }
1583   OS << ")";
1584 }
1585 
1586 void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1587   OS << "__builtin_convertvector(";
1588   PrintExpr(Node->getSrcExpr());
1589   OS << ", ";
1590   Node->getType().print(OS, Policy);
1591   OS << ")";
1592 }
1593 
1594 void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1595   if (Node->getSyntacticForm()) {
1596     Visit(Node->getSyntacticForm());
1597     return;
1598   }
1599 
1600   OS << "{";
1601   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1602     if (i) OS << ", ";
1603     if (Node->getInit(i))
1604       PrintExpr(Node->getInit(i));
1605     else
1606       OS << "{}";
1607   }
1608   OS << "}";
1609 }
1610 
1611 void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1612   OS << "(";
1613   for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1614     if (i) OS << ", ";
1615     PrintExpr(Node->getExpr(i));
1616   }
1617   OS << ")";
1618 }
1619 
1620 void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1621   bool NeedsEquals = true;
1622   for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1623                       DEnd = Node->designators_end();
1624        D != DEnd; ++D) {
1625     if (D->isFieldDesignator()) {
1626       if (D->getDotLoc().isInvalid()) {
1627         if (IdentifierInfo *II = D->getFieldName()) {
1628           OS << II->getName() << ":";
1629           NeedsEquals = false;
1630         }
1631       } else {
1632         OS << "." << D->getFieldName()->getName();
1633       }
1634     } else {
1635       OS << "[";
1636       if (D->isArrayDesignator()) {
1637         PrintExpr(Node->getArrayIndex(*D));
1638       } else {
1639         PrintExpr(Node->getArrayRangeStart(*D));
1640         OS << " ... ";
1641         PrintExpr(Node->getArrayRangeEnd(*D));
1642       }
1643       OS << "]";
1644     }
1645   }
1646 
1647   if (NeedsEquals)
1648     OS << " = ";
1649   else
1650     OS << " ";
1651   PrintExpr(Node->getInit());
1652 }
1653 
1654 void StmtPrinter::VisitDesignatedInitUpdateExpr(
1655     DesignatedInitUpdateExpr *Node) {
1656   OS << "{";
1657   OS << "/*base*/";
1658   PrintExpr(Node->getBase());
1659   OS << ", ";
1660 
1661   OS << "/*updater*/";
1662   PrintExpr(Node->getUpdater());
1663   OS << "}";
1664 }
1665 
1666 void StmtPrinter::VisitNoInitExpr(NoInitExpr *Node) {
1667   OS << "/*no init*/";
1668 }
1669 
1670 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1671   if (Policy.LangOpts.CPlusPlus) {
1672     OS << "/*implicit*/";
1673     Node->getType().print(OS, Policy);
1674     OS << "()";
1675   } else {
1676     OS << "/*implicit*/(";
1677     Node->getType().print(OS, Policy);
1678     OS << ')';
1679     if (Node->getType()->isRecordType())
1680       OS << "{}";
1681     else
1682       OS << 0;
1683   }
1684 }
1685 
1686 void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1687   OS << "__builtin_va_arg(";
1688   PrintExpr(Node->getSubExpr());
1689   OS << ", ";
1690   Node->getType().print(OS, Policy);
1691   OS << ")";
1692 }
1693 
1694 void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1695   PrintExpr(Node->getSyntacticForm());
1696 }
1697 
1698 void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1699   const char *Name = nullptr;
1700   switch (Node->getOp()) {
1701 #define BUILTIN(ID, TYPE, ATTRS)
1702 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1703   case AtomicExpr::AO ## ID: \
1704     Name = #ID "("; \
1705     break;
1706 #include "clang/Basic/Builtins.def"
1707   }
1708   OS << Name;
1709 
1710   // AtomicExpr stores its subexpressions in a permuted order.
1711   PrintExpr(Node->getPtr());
1712   if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1713       Node->getOp() != AtomicExpr::AO__atomic_load_n) {
1714     OS << ", ";
1715     PrintExpr(Node->getVal1());
1716   }
1717   if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1718       Node->isCmpXChg()) {
1719     OS << ", ";
1720     PrintExpr(Node->getVal2());
1721   }
1722   if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1723       Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1724     OS << ", ";
1725     PrintExpr(Node->getWeak());
1726   }
1727   if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1728     OS << ", ";
1729     PrintExpr(Node->getOrder());
1730   }
1731   if (Node->isCmpXChg()) {
1732     OS << ", ";
1733     PrintExpr(Node->getOrderFail());
1734   }
1735   OS << ")";
1736 }
1737 
1738 // C++
1739 void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1740   const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1741     "",
1742 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1743     Spelling,
1744 #include "clang/Basic/OperatorKinds.def"
1745   };
1746 
1747   OverloadedOperatorKind Kind = Node->getOperator();
1748   if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1749     if (Node->getNumArgs() == 1) {
1750       OS << OpStrings[Kind] << ' ';
1751       PrintExpr(Node->getArg(0));
1752     } else {
1753       PrintExpr(Node->getArg(0));
1754       OS << ' ' << OpStrings[Kind];
1755     }
1756   } else if (Kind == OO_Arrow) {
1757     PrintExpr(Node->getArg(0));
1758   } else if (Kind == OO_Call) {
1759     PrintExpr(Node->getArg(0));
1760     OS << '(';
1761     for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1762       if (ArgIdx > 1)
1763         OS << ", ";
1764       if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1765         PrintExpr(Node->getArg(ArgIdx));
1766     }
1767     OS << ')';
1768   } else if (Kind == OO_Subscript) {
1769     PrintExpr(Node->getArg(0));
1770     OS << '[';
1771     PrintExpr(Node->getArg(1));
1772     OS << ']';
1773   } else if (Node->getNumArgs() == 1) {
1774     OS << OpStrings[Kind] << ' ';
1775     PrintExpr(Node->getArg(0));
1776   } else if (Node->getNumArgs() == 2) {
1777     PrintExpr(Node->getArg(0));
1778     OS << ' ' << OpStrings[Kind] << ' ';
1779     PrintExpr(Node->getArg(1));
1780   } else {
1781     llvm_unreachable("unknown overloaded operator");
1782   }
1783 }
1784 
1785 void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1786   // If we have a conversion operator call only print the argument.
1787   CXXMethodDecl *MD = Node->getMethodDecl();
1788   if (MD && isa<CXXConversionDecl>(MD)) {
1789     PrintExpr(Node->getImplicitObjectArgument());
1790     return;
1791   }
1792   VisitCallExpr(cast<CallExpr>(Node));
1793 }
1794 
1795 void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1796   PrintExpr(Node->getCallee());
1797   OS << "<<<";
1798   PrintCallArgs(Node->getConfig());
1799   OS << ">>>(";
1800   PrintCallArgs(Node);
1801   OS << ")";
1802 }
1803 
1804 void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1805   OS << Node->getCastName() << '<';
1806   Node->getTypeAsWritten().print(OS, Policy);
1807   OS << ">(";
1808   PrintExpr(Node->getSubExpr());
1809   OS << ")";
1810 }
1811 
1812 void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1813   VisitCXXNamedCastExpr(Node);
1814 }
1815 
1816 void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1817   VisitCXXNamedCastExpr(Node);
1818 }
1819 
1820 void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1821   VisitCXXNamedCastExpr(Node);
1822 }
1823 
1824 void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1825   VisitCXXNamedCastExpr(Node);
1826 }
1827 
1828 void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1829   OS << "typeid(";
1830   if (Node->isTypeOperand()) {
1831     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1832   } else {
1833     PrintExpr(Node->getExprOperand());
1834   }
1835   OS << ")";
1836 }
1837 
1838 void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1839   OS << "__uuidof(";
1840   if (Node->isTypeOperand()) {
1841     Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1842   } else {
1843     PrintExpr(Node->getExprOperand());
1844   }
1845   OS << ")";
1846 }
1847 
1848 void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1849   PrintExpr(Node->getBaseExpr());
1850   if (Node->isArrow())
1851     OS << "->";
1852   else
1853     OS << ".";
1854   if (NestedNameSpecifier *Qualifier =
1855       Node->getQualifierLoc().getNestedNameSpecifier())
1856     Qualifier->print(OS, Policy);
1857   OS << Node->getPropertyDecl()->getDeclName();
1858 }
1859 
1860 void StmtPrinter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *Node) {
1861   PrintExpr(Node->getBase());
1862   OS << "[";
1863   PrintExpr(Node->getIdx());
1864   OS << "]";
1865 }
1866 
1867 void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1868   switch (Node->getLiteralOperatorKind()) {
1869   case UserDefinedLiteral::LOK_Raw:
1870     OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
1871     break;
1872   case UserDefinedLiteral::LOK_Template: {
1873     DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1874     const TemplateArgumentList *Args =
1875       cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1876     assert(Args);
1877 
1878     if (Args->size() != 1) {
1879       OS << "operator\"\"" << Node->getUDSuffix()->getName();
1880       TemplateSpecializationType::PrintTemplateArgumentList(
1881           OS, Args->data(), Args->size(), Policy);
1882       OS << "()";
1883       return;
1884     }
1885 
1886     const TemplateArgument &Pack = Args->get(0);
1887     for (const auto &P : Pack.pack_elements()) {
1888       char C = (char)P.getAsIntegral().getZExtValue();
1889       OS << C;
1890     }
1891     break;
1892   }
1893   case UserDefinedLiteral::LOK_Integer: {
1894     // Print integer literal without suffix.
1895     IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1896     OS << Int->getValue().toString(10, /*isSigned*/false);
1897     break;
1898   }
1899   case UserDefinedLiteral::LOK_Floating: {
1900     // Print floating literal without suffix.
1901     FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1902     PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1903     break;
1904   }
1905   case UserDefinedLiteral::LOK_String:
1906   case UserDefinedLiteral::LOK_Character:
1907     PrintExpr(Node->getCookedLiteral());
1908     break;
1909   }
1910   OS << Node->getUDSuffix()->getName();
1911 }
1912 
1913 void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1914   OS << (Node->getValue() ? "true" : "false");
1915 }
1916 
1917 void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1918   OS << "nullptr";
1919 }
1920 
1921 void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1922   OS << "this";
1923 }
1924 
1925 void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1926   if (!Node->getSubExpr())
1927     OS << "throw";
1928   else {
1929     OS << "throw ";
1930     PrintExpr(Node->getSubExpr());
1931   }
1932 }
1933 
1934 void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1935   // Nothing to print: we picked up the default argument.
1936 }
1937 
1938 void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1939   // Nothing to print: we picked up the default initializer.
1940 }
1941 
1942 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1943   Node->getType().print(OS, Policy);
1944   // If there are no parens, this is list-initialization, and the braces are
1945   // part of the syntax of the inner construct.
1946   if (Node->getLParenLoc().isValid())
1947     OS << "(";
1948   PrintExpr(Node->getSubExpr());
1949   if (Node->getLParenLoc().isValid())
1950     OS << ")";
1951 }
1952 
1953 void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1954   PrintExpr(Node->getSubExpr());
1955 }
1956 
1957 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1958   Node->getType().print(OS, Policy);
1959   if (Node->isStdInitListInitialization())
1960     /* Nothing to do; braces are part of creating the std::initializer_list. */;
1961   else if (Node->isListInitialization())
1962     OS << "{";
1963   else
1964     OS << "(";
1965   for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
1966                                          ArgEnd = Node->arg_end();
1967        Arg != ArgEnd; ++Arg) {
1968     if ((*Arg)->isDefaultArgument())
1969       break;
1970     if (Arg != Node->arg_begin())
1971       OS << ", ";
1972     PrintExpr(*Arg);
1973   }
1974   if (Node->isStdInitListInitialization())
1975     /* See above. */;
1976   else if (Node->isListInitialization())
1977     OS << "}";
1978   else
1979     OS << ")";
1980 }
1981 
1982 void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1983   OS << '[';
1984   bool NeedComma = false;
1985   switch (Node->getCaptureDefault()) {
1986   case LCD_None:
1987     break;
1988 
1989   case LCD_ByCopy:
1990     OS << '=';
1991     NeedComma = true;
1992     break;
1993 
1994   case LCD_ByRef:
1995     OS << '&';
1996     NeedComma = true;
1997     break;
1998   }
1999   for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
2000                                  CEnd = Node->explicit_capture_end();
2001        C != CEnd;
2002        ++C) {
2003     if (NeedComma)
2004       OS << ", ";
2005     NeedComma = true;
2006 
2007     switch (C->getCaptureKind()) {
2008     case LCK_This:
2009       OS << "this";
2010       break;
2011     case LCK_StarThis:
2012       OS << "*this";
2013       break;
2014     case LCK_ByRef:
2015       if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C))
2016         OS << '&';
2017       OS << C->getCapturedVar()->getName();
2018       break;
2019 
2020     case LCK_ByCopy:
2021       OS << C->getCapturedVar()->getName();
2022       break;
2023     case LCK_VLAType:
2024       llvm_unreachable("VLA type in explicit captures.");
2025     }
2026 
2027     if (Node->isInitCapture(C))
2028       PrintExpr(C->getCapturedVar()->getInit());
2029   }
2030   OS << ']';
2031 
2032   if (Node->hasExplicitParameters()) {
2033     OS << " (";
2034     CXXMethodDecl *Method = Node->getCallOperator();
2035     NeedComma = false;
2036     for (auto P : Method->params()) {
2037       if (NeedComma) {
2038         OS << ", ";
2039       } else {
2040         NeedComma = true;
2041       }
2042       std::string ParamStr = P->getNameAsString();
2043       P->getOriginalType().print(OS, Policy, ParamStr);
2044     }
2045     if (Method->isVariadic()) {
2046       if (NeedComma)
2047         OS << ", ";
2048       OS << "...";
2049     }
2050     OS << ')';
2051 
2052     if (Node->isMutable())
2053       OS << " mutable";
2054 
2055     const FunctionProtoType *Proto
2056       = Method->getType()->getAs<FunctionProtoType>();
2057     Proto->printExceptionSpecification(OS, Policy);
2058 
2059     // FIXME: Attributes
2060 
2061     // Print the trailing return type if it was specified in the source.
2062     if (Node->hasExplicitResultType()) {
2063       OS << " -> ";
2064       Proto->getReturnType().print(OS, Policy);
2065     }
2066   }
2067 
2068   // Print the body.
2069   CompoundStmt *Body = Node->getBody();
2070   OS << ' ';
2071   PrintStmt(Body);
2072 }
2073 
2074 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
2075   if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
2076     TSInfo->getType().print(OS, Policy);
2077   else
2078     Node->getType().print(OS, Policy);
2079   OS << "()";
2080 }
2081 
2082 void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
2083   if (E->isGlobalNew())
2084     OS << "::";
2085   OS << "new ";
2086   unsigned NumPlace = E->getNumPlacementArgs();
2087   if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
2088     OS << "(";
2089     PrintExpr(E->getPlacementArg(0));
2090     for (unsigned i = 1; i < NumPlace; ++i) {
2091       if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
2092         break;
2093       OS << ", ";
2094       PrintExpr(E->getPlacementArg(i));
2095     }
2096     OS << ") ";
2097   }
2098   if (E->isParenTypeId())
2099     OS << "(";
2100   std::string TypeS;
2101   if (Expr *Size = E->getArraySize()) {
2102     llvm::raw_string_ostream s(TypeS);
2103     s << '[';
2104     Size->printPretty(s, Helper, Policy);
2105     s << ']';
2106   }
2107   E->getAllocatedType().print(OS, Policy, TypeS);
2108   if (E->isParenTypeId())
2109     OS << ")";
2110 
2111   CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
2112   if (InitStyle) {
2113     if (InitStyle == CXXNewExpr::CallInit)
2114       OS << "(";
2115     PrintExpr(E->getInitializer());
2116     if (InitStyle == CXXNewExpr::CallInit)
2117       OS << ")";
2118   }
2119 }
2120 
2121 void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
2122   if (E->isGlobalDelete())
2123     OS << "::";
2124   OS << "delete ";
2125   if (E->isArrayForm())
2126     OS << "[] ";
2127   PrintExpr(E->getArgument());
2128 }
2129 
2130 void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
2131   PrintExpr(E->getBase());
2132   if (E->isArrow())
2133     OS << "->";
2134   else
2135     OS << '.';
2136   if (E->getQualifier())
2137     E->getQualifier()->print(OS, Policy);
2138   OS << "~";
2139 
2140   if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
2141     OS << II->getName();
2142   else
2143     E->getDestroyedType().print(OS, Policy);
2144 }
2145 
2146 void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
2147   if (E->isListInitialization() && !E->isStdInitListInitialization())
2148     OS << "{";
2149 
2150   for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
2151     if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
2152       // Don't print any defaulted arguments
2153       break;
2154     }
2155 
2156     if (i) OS << ", ";
2157     PrintExpr(E->getArg(i));
2158   }
2159 
2160   if (E->isListInitialization() && !E->isStdInitListInitialization())
2161     OS << "}";
2162 }
2163 
2164 void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
2165   PrintExpr(E->getSubExpr());
2166 }
2167 
2168 void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
2169   // Just forward to the subexpression.
2170   PrintExpr(E->getSubExpr());
2171 }
2172 
2173 void
2174 StmtPrinter::VisitCXXUnresolvedConstructExpr(
2175                                            CXXUnresolvedConstructExpr *Node) {
2176   Node->getTypeAsWritten().print(OS, Policy);
2177   OS << "(";
2178   for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
2179                                              ArgEnd = Node->arg_end();
2180        Arg != ArgEnd; ++Arg) {
2181     if (Arg != Node->arg_begin())
2182       OS << ", ";
2183     PrintExpr(*Arg);
2184   }
2185   OS << ")";
2186 }
2187 
2188 void StmtPrinter::VisitCXXDependentScopeMemberExpr(
2189                                          CXXDependentScopeMemberExpr *Node) {
2190   if (!Node->isImplicitAccess()) {
2191     PrintExpr(Node->getBase());
2192     OS << (Node->isArrow() ? "->" : ".");
2193   }
2194   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2195     Qualifier->print(OS, Policy);
2196   if (Node->hasTemplateKeyword())
2197     OS << "template ";
2198   OS << Node->getMemberNameInfo();
2199   if (Node->hasExplicitTemplateArgs())
2200     TemplateSpecializationType::PrintTemplateArgumentList(
2201         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
2202 }
2203 
2204 void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
2205   if (!Node->isImplicitAccess()) {
2206     PrintExpr(Node->getBase());
2207     OS << (Node->isArrow() ? "->" : ".");
2208   }
2209   if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2210     Qualifier->print(OS, Policy);
2211   if (Node->hasTemplateKeyword())
2212     OS << "template ";
2213   OS << Node->getMemberNameInfo();
2214   if (Node->hasExplicitTemplateArgs())
2215     TemplateSpecializationType::PrintTemplateArgumentList(
2216         OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
2217 }
2218 
2219 static const char *getTypeTraitName(TypeTrait TT) {
2220   switch (TT) {
2221 #define TYPE_TRAIT_1(Spelling, Name, Key) \
2222 case clang::UTT_##Name: return #Spelling;
2223 #define TYPE_TRAIT_2(Spelling, Name, Key) \
2224 case clang::BTT_##Name: return #Spelling;
2225 #define TYPE_TRAIT_N(Spelling, Name, Key) \
2226   case clang::TT_##Name: return #Spelling;
2227 #include "clang/Basic/TokenKinds.def"
2228   }
2229   llvm_unreachable("Type trait not covered by switch");
2230 }
2231 
2232 static const char *getTypeTraitName(ArrayTypeTrait ATT) {
2233   switch (ATT) {
2234   case ATT_ArrayRank:        return "__array_rank";
2235   case ATT_ArrayExtent:      return "__array_extent";
2236   }
2237   llvm_unreachable("Array type trait not covered by switch");
2238 }
2239 
2240 static const char *getExpressionTraitName(ExpressionTrait ET) {
2241   switch (ET) {
2242   case ET_IsLValueExpr:      return "__is_lvalue_expr";
2243   case ET_IsRValueExpr:      return "__is_rvalue_expr";
2244   }
2245   llvm_unreachable("Expression type trait not covered by switch");
2246 }
2247 
2248 void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
2249   OS << getTypeTraitName(E->getTrait()) << "(";
2250   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
2251     if (I > 0)
2252       OS << ", ";
2253     E->getArg(I)->getType().print(OS, Policy);
2254   }
2255   OS << ")";
2256 }
2257 
2258 void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2259   OS << getTypeTraitName(E->getTrait()) << '(';
2260   E->getQueriedType().print(OS, Policy);
2261   OS << ')';
2262 }
2263 
2264 void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2265   OS << getExpressionTraitName(E->getTrait()) << '(';
2266   PrintExpr(E->getQueriedExpression());
2267   OS << ')';
2268 }
2269 
2270 void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2271   OS << "noexcept(";
2272   PrintExpr(E->getOperand());
2273   OS << ")";
2274 }
2275 
2276 void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2277   PrintExpr(E->getPattern());
2278   OS << "...";
2279 }
2280 
2281 void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2282   OS << "sizeof...(" << *E->getPack() << ")";
2283 }
2284 
2285 void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
2286                                        SubstNonTypeTemplateParmPackExpr *Node) {
2287   OS << *Node->getParameterPack();
2288 }
2289 
2290 void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
2291                                        SubstNonTypeTemplateParmExpr *Node) {
2292   Visit(Node->getReplacement());
2293 }
2294 
2295 void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2296   OS << *E->getParameterPack();
2297 }
2298 
2299 void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
2300   PrintExpr(Node->GetTemporaryExpr());
2301 }
2302 
2303 void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2304   OS << "(";
2305   if (E->getLHS()) {
2306     PrintExpr(E->getLHS());
2307     OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2308   }
2309   OS << "...";
2310   if (E->getRHS()) {
2311     OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2312     PrintExpr(E->getRHS());
2313   }
2314   OS << ")";
2315 }
2316 
2317 // C++ Coroutines TS
2318 
2319 void StmtPrinter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
2320   Visit(S->getBody());
2321 }
2322 
2323 void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) {
2324   OS << "co_return";
2325   if (S->getOperand()) {
2326     OS << " ";
2327     Visit(S->getOperand());
2328   }
2329   OS << ";";
2330 }
2331 
2332 void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) {
2333   OS << "co_await ";
2334   PrintExpr(S->getOperand());
2335 }
2336 
2337 void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) {
2338   OS << "co_yield ";
2339   PrintExpr(S->getOperand());
2340 }
2341 
2342 // Obj-C
2343 
2344 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
2345   OS << "@";
2346   VisitStringLiteral(Node->getString());
2347 }
2348 
2349 void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
2350   OS << "@";
2351   Visit(E->getSubExpr());
2352 }
2353 
2354 void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
2355   OS << "@[ ";
2356   ObjCArrayLiteral::child_range Ch = E->children();
2357   for (auto I = Ch.begin(), E = Ch.end(); I != E; ++I) {
2358     if (I != Ch.begin())
2359       OS << ", ";
2360     Visit(*I);
2361   }
2362   OS << " ]";
2363 }
2364 
2365 void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
2366   OS << "@{ ";
2367   for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
2368     if (I > 0)
2369       OS << ", ";
2370 
2371     ObjCDictionaryElement Element = E->getKeyValueElement(I);
2372     Visit(Element.Key);
2373     OS << " : ";
2374     Visit(Element.Value);
2375     if (Element.isPackExpansion())
2376       OS << "...";
2377   }
2378   OS << " }";
2379 }
2380 
2381 void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
2382   OS << "@encode(";
2383   Node->getEncodedType().print(OS, Policy);
2384   OS << ')';
2385 }
2386 
2387 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
2388   OS << "@selector(";
2389   Node->getSelector().print(OS);
2390   OS << ')';
2391 }
2392 
2393 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
2394   OS << "@protocol(" << *Node->getProtocol() << ')';
2395 }
2396 
2397 void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
2398   OS << "[";
2399   switch (Mess->getReceiverKind()) {
2400   case ObjCMessageExpr::Instance:
2401     PrintExpr(Mess->getInstanceReceiver());
2402     break;
2403 
2404   case ObjCMessageExpr::Class:
2405     Mess->getClassReceiver().print(OS, Policy);
2406     break;
2407 
2408   case ObjCMessageExpr::SuperInstance:
2409   case ObjCMessageExpr::SuperClass:
2410     OS << "Super";
2411     break;
2412   }
2413 
2414   OS << ' ';
2415   Selector selector = Mess->getSelector();
2416   if (selector.isUnarySelector()) {
2417     OS << selector.getNameForSlot(0);
2418   } else {
2419     for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
2420       if (i < selector.getNumArgs()) {
2421         if (i > 0) OS << ' ';
2422         if (selector.getIdentifierInfoForSlot(i))
2423           OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
2424         else
2425            OS << ":";
2426       }
2427       else OS << ", "; // Handle variadic methods.
2428 
2429       PrintExpr(Mess->getArg(i));
2430     }
2431   }
2432   OS << "]";
2433 }
2434 
2435 void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
2436   OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
2437 }
2438 
2439 void
2440 StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
2441   PrintExpr(E->getSubExpr());
2442 }
2443 
2444 void
2445 StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
2446   OS << '(' << E->getBridgeKindName();
2447   E->getType().print(OS, Policy);
2448   OS << ')';
2449   PrintExpr(E->getSubExpr());
2450 }
2451 
2452 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
2453   BlockDecl *BD = Node->getBlockDecl();
2454   OS << "^";
2455 
2456   const FunctionType *AFT = Node->getFunctionType();
2457 
2458   if (isa<FunctionNoProtoType>(AFT)) {
2459     OS << "()";
2460   } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
2461     OS << '(';
2462     for (BlockDecl::param_iterator AI = BD->param_begin(),
2463          E = BD->param_end(); AI != E; ++AI) {
2464       if (AI != BD->param_begin()) OS << ", ";
2465       std::string ParamStr = (*AI)->getNameAsString();
2466       (*AI)->getType().print(OS, Policy, ParamStr);
2467     }
2468 
2469     const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
2470     if (FT->isVariadic()) {
2471       if (!BD->param_empty()) OS << ", ";
2472       OS << "...";
2473     }
2474     OS << ')';
2475   }
2476   OS << "{ }";
2477 }
2478 
2479 void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
2480   PrintExpr(Node->getSourceExpr());
2481 }
2482 
2483 void StmtPrinter::VisitTypoExpr(TypoExpr *Node) {
2484   // TODO: Print something reasonable for a TypoExpr, if necessary.
2485   llvm_unreachable("Cannot print TypoExpr nodes");
2486 }
2487 
2488 void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
2489   OS << "__builtin_astype(";
2490   PrintExpr(Node->getSrcExpr());
2491   OS << ", ";
2492   Node->getType().print(OS, Policy);
2493   OS << ")";
2494 }
2495 
2496 //===----------------------------------------------------------------------===//
2497 // Stmt method implementations
2498 //===----------------------------------------------------------------------===//
2499 
2500 void Stmt::dumpPretty(const ASTContext &Context) const {
2501   printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
2502 }
2503 
2504 void Stmt::printPretty(raw_ostream &OS,
2505                        PrinterHelper *Helper,
2506                        const PrintingPolicy &Policy,
2507                        unsigned Indentation) const {
2508   StmtPrinter P(OS, Helper, Policy, Indentation);
2509   P.Visit(const_cast<Stmt*>(this));
2510 }
2511 
2512 //===----------------------------------------------------------------------===//
2513 // PrinterHelper
2514 //===----------------------------------------------------------------------===//
2515 
2516 // Implement virtual destructor.
2517 PrinterHelper::~PrinterHelper() {}
2518