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