1 //===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
11 // pretty print the AST back out to C code.
13 //===----------------------------------------------------------------------===//
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/ExprOpenMP.h"
23 #include "clang/AST/PrettyPrinter.h"
24 #include "clang/AST/StmtVisitor.h"
25 #include "clang/Basic/CharInfo.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/Support/Format.h"
28 using namespace clang;
30 //===----------------------------------------------------------------------===//
31 // StmtPrinter Visitor
32 //===----------------------------------------------------------------------===//
35 class StmtPrinter : public StmtVisitor<StmtPrinter> {
38 clang::PrinterHelper* Helper;
39 PrintingPolicy Policy;
42 StmtPrinter(raw_ostream &os, PrinterHelper* helper,
43 const PrintingPolicy &Policy,
44 unsigned Indentation = 0)
45 : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
47 void PrintStmt(Stmt *S) {
48 PrintStmt(S, Policy.Indentation);
51 void PrintStmt(Stmt *S, int SubIndent) {
52 IndentLevel += SubIndent;
53 if (S && isa<Expr>(S)) {
54 // If this is an expr used in a stmt context, indent and newline it.
61 Indent() << "<<<NULL STATEMENT>>>\n";
63 IndentLevel -= SubIndent;
66 void PrintRawCompoundStmt(CompoundStmt *S);
67 void PrintRawDecl(Decl *D);
68 void PrintRawDeclStmt(const DeclStmt *S);
69 void PrintRawIfStmt(IfStmt *If);
70 void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
71 void PrintCallArgs(CallExpr *E);
72 void PrintRawSEHExceptHandler(SEHExceptStmt *S);
73 void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
74 void PrintOMPExecutableDirective(OMPExecutableDirective *S);
76 void PrintExpr(Expr *E) {
83 raw_ostream &Indent(int Delta = 0) {
84 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
90 if (Helper && Helper->handledStmt(S,OS))
92 else StmtVisitor<StmtPrinter>::Visit(S);
95 void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
96 Indent() << "<<unknown stmt type>>\n";
98 void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
99 OS << "<<unknown expr type>>";
101 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
103 #define ABSTRACT_STMT(CLASS)
104 #define STMT(CLASS, PARENT) \
105 void Visit##CLASS(CLASS *Node);
106 #include "clang/AST/StmtNodes.inc"
110 //===----------------------------------------------------------------------===//
111 // Stmt printing methods.
112 //===----------------------------------------------------------------------===//
114 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
115 /// with no newline after the }.
116 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
118 for (auto *I : Node->body())
124 void StmtPrinter::PrintRawDecl(Decl *D) {
125 D->print(OS, Policy, IndentLevel);
128 void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
129 SmallVector<Decl*, 2> Decls(S->decls());
130 Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
133 void StmtPrinter::VisitNullStmt(NullStmt *Node) {
137 void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
139 PrintRawDeclStmt(Node);
143 void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
145 PrintRawCompoundStmt(Node);
149 void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
150 Indent(-1) << "case ";
151 PrintExpr(Node->getLHS());
152 if (Node->getRHS()) {
154 PrintExpr(Node->getRHS());
158 PrintStmt(Node->getSubStmt(), 0);
161 void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
162 Indent(-1) << "default:\n";
163 PrintStmt(Node->getSubStmt(), 0);
166 void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
167 Indent(-1) << Node->getName() << ":\n";
168 PrintStmt(Node->getSubStmt(), 0);
171 void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
172 for (const auto *Attr : Node->getAttrs()) {
173 Attr->printPretty(OS, Policy);
176 PrintStmt(Node->getSubStmt(), 0);
179 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
181 if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
182 PrintRawDeclStmt(DS);
184 PrintExpr(If->getCond());
187 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
189 PrintRawCompoundStmt(CS);
190 OS << (If->getElse() ? ' ' : '\n');
193 PrintStmt(If->getThen());
194 if (If->getElse()) Indent();
197 if (Stmt *Else = If->getElse()) {
200 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
202 PrintRawCompoundStmt(CS);
204 } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
206 PrintRawIfStmt(ElseIf);
209 PrintStmt(If->getElse());
214 void StmtPrinter::VisitIfStmt(IfStmt *If) {
219 void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
220 Indent() << "switch (";
221 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
222 PrintRawDeclStmt(DS);
224 PrintExpr(Node->getCond());
227 // Pretty print compoundstmt bodies (very common).
228 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
230 PrintRawCompoundStmt(CS);
234 PrintStmt(Node->getBody());
238 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
239 Indent() << "while (";
240 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
241 PrintRawDeclStmt(DS);
243 PrintExpr(Node->getCond());
245 PrintStmt(Node->getBody());
248 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
250 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
251 PrintRawCompoundStmt(CS);
255 PrintStmt(Node->getBody());
260 PrintExpr(Node->getCond());
264 void StmtPrinter::VisitForStmt(ForStmt *Node) {
266 if (Node->getInit()) {
267 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
268 PrintRawDeclStmt(DS);
270 PrintExpr(cast<Expr>(Node->getInit()));
273 if (Node->getCond()) {
275 PrintExpr(Node->getCond());
278 if (Node->getInc()) {
280 PrintExpr(Node->getInc());
284 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
285 PrintRawCompoundStmt(CS);
289 PrintStmt(Node->getBody());
293 void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
295 if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
296 PrintRawDeclStmt(DS);
298 PrintExpr(cast<Expr>(Node->getElement()));
300 PrintExpr(Node->getCollection());
303 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
304 PrintRawCompoundStmt(CS);
308 PrintStmt(Node->getBody());
312 void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
314 PrintingPolicy SubPolicy(Policy);
315 SubPolicy.SuppressInitializers = true;
316 Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
318 PrintExpr(Node->getRangeInit());
320 PrintStmt(Node->getBody());
322 if (Policy.IncludeNewlines) OS << "\n";
325 void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
327 if (Node->isIfExists())
328 OS << "__if_exists (";
330 OS << "__if_not_exists (";
332 if (NestedNameSpecifier *Qualifier
333 = Node->getQualifierLoc().getNestedNameSpecifier())
334 Qualifier->print(OS, Policy);
336 OS << Node->getNameInfo() << ") ";
338 PrintRawCompoundStmt(Node->getSubStmt());
341 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
342 Indent() << "goto " << Node->getLabel()->getName() << ";";
343 if (Policy.IncludeNewlines) OS << "\n";
346 void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
347 Indent() << "goto *";
348 PrintExpr(Node->getTarget());
350 if (Policy.IncludeNewlines) OS << "\n";
353 void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
354 Indent() << "continue;";
355 if (Policy.IncludeNewlines) OS << "\n";
358 void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
359 Indent() << "break;";
360 if (Policy.IncludeNewlines) OS << "\n";
364 void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
365 Indent() << "return";
366 if (Node->getRetValue()) {
368 PrintExpr(Node->getRetValue());
371 if (Policy.IncludeNewlines) OS << "\n";
375 void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
378 if (Node->isVolatile())
382 VisitStringLiteral(Node->getAsmString());
385 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
386 Node->getNumClobbers() != 0)
389 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
393 if (!Node->getOutputName(i).empty()) {
395 OS << Node->getOutputName(i);
399 VisitStringLiteral(Node->getOutputConstraintLiteral(i));
401 Visit(Node->getOutputExpr(i));
406 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
409 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
413 if (!Node->getInputName(i).empty()) {
415 OS << Node->getInputName(i);
419 VisitStringLiteral(Node->getInputConstraintLiteral(i));
421 Visit(Node->getInputExpr(i));
426 if (Node->getNumClobbers() != 0)
429 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
433 VisitStringLiteral(Node->getClobberStringLiteral(i));
437 if (Policy.IncludeNewlines) OS << "\n";
440 void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
441 // FIXME: Implement MS style inline asm statement printer.
442 Indent() << "__asm ";
443 if (Node->hasBraces())
445 OS << Node->getAsmString() << "\n";
446 if (Node->hasBraces())
450 void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
451 PrintStmt(Node->getCapturedDecl()->getBody());
454 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
456 if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
457 PrintRawCompoundStmt(TS);
461 for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
462 ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
463 Indent() << "@catch(";
464 if (catchStmt->getCatchParamDecl()) {
465 if (Decl *DS = catchStmt->getCatchParamDecl())
469 if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
470 PrintRawCompoundStmt(CS);
475 if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
476 Node->getFinallyStmt())) {
477 Indent() << "@finally";
478 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
483 void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
486 void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
487 Indent() << "@catch (...) { /* todo */ } \n";
490 void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
491 Indent() << "@throw";
492 if (Node->getThrowExpr()) {
494 PrintExpr(Node->getThrowExpr());
499 void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
500 Indent() << "@synchronized (";
501 PrintExpr(Node->getSynchExpr());
503 PrintRawCompoundStmt(Node->getSynchBody());
507 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
508 Indent() << "@autoreleasepool";
509 PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
513 void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
515 if (Decl *ExDecl = Node->getExceptionDecl())
516 PrintRawDecl(ExDecl);
520 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
523 void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
525 PrintRawCXXCatchStmt(Node);
529 void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
531 PrintRawCompoundStmt(Node->getTryBlock());
532 for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
534 PrintRawCXXCatchStmt(Node->getHandler(i));
539 void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
540 Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
541 PrintRawCompoundStmt(Node->getTryBlock());
542 SEHExceptStmt *E = Node->getExceptHandler();
543 SEHFinallyStmt *F = Node->getFinallyHandler();
545 PrintRawSEHExceptHandler(E);
547 assert(F && "Must have a finally block...");
548 PrintRawSEHFinallyStmt(F);
553 void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
555 PrintRawCompoundStmt(Node->getBlock());
559 void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
561 VisitExpr(Node->getFilterExpr());
563 PrintRawCompoundStmt(Node->getBlock());
567 void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
569 PrintRawSEHExceptHandler(Node);
573 void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
575 PrintRawSEHFinallyStmt(Node);
579 void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
580 Indent() << "__leave;";
581 if (Policy.IncludeNewlines) OS << "\n";
584 //===----------------------------------------------------------------------===//
585 // OpenMP clauses printing methods
586 //===----------------------------------------------------------------------===//
589 class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
591 const PrintingPolicy &Policy;
592 /// \brief Process clauses with list of variables.
593 template <typename T>
594 void VisitOMPClauseList(T *Node, char StartSym);
596 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
597 : OS(OS), Policy(Policy) { }
598 #define OPENMP_CLAUSE(Name, Class) \
599 void Visit##Class(Class *S);
600 #include "clang/Basic/OpenMPKinds.def"
603 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
605 if (Node->getNameModifier() != OMPD_unknown)
606 OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
607 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
611 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
613 Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
617 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
618 OS << "num_threads(";
619 Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
623 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
625 Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
629 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
631 Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
635 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
637 Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
641 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
643 << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
647 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
649 << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
653 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
655 if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
656 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
657 Node->getFirstScheduleModifier());
658 if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
660 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
661 Node->getSecondScheduleModifier());
665 OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
666 if (Node->getChunkSize()) {
668 Node->getChunkSize()->printPretty(OS, nullptr, Policy);
673 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
675 if (auto *Num = Node->getNumForLoops()) {
677 Num->printPretty(OS, nullptr, Policy, 0);
682 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
686 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
690 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
694 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
698 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
700 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
702 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
706 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
710 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
714 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
718 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
720 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
722 Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
726 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
728 Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
732 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
733 OS << "thread_limit(";
734 Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
738 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
740 Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
744 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
746 Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
750 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
752 Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
756 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
758 Node->getHint()->printPretty(OS, nullptr, Policy, 0);
763 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
764 for (typename T::varlist_iterator I = Node->varlist_begin(),
765 E = Node->varlist_end();
767 assert(*I && "Expected non-null Stmt");
768 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(*I)) {
769 OS << (I == Node->varlist_begin() ? StartSym : ',');
770 cast<NamedDecl>(DRE->getDecl())->printQualifiedName(OS);
772 OS << (I == Node->varlist_begin() ? StartSym : ',');
773 (*I)->printPretty(OS, nullptr, Policy, 0);
778 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
779 if (!Node->varlist_empty()) {
781 VisitOMPClauseList(Node, '(');
786 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
787 if (!Node->varlist_empty()) {
788 OS << "firstprivate";
789 VisitOMPClauseList(Node, '(');
794 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
795 if (!Node->varlist_empty()) {
797 VisitOMPClauseList(Node, '(');
802 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
803 if (!Node->varlist_empty()) {
805 VisitOMPClauseList(Node, '(');
810 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
811 if (!Node->varlist_empty()) {
813 NestedNameSpecifier *QualifierLoc =
814 Node->getQualifierLoc().getNestedNameSpecifier();
815 OverloadedOperatorKind OOK =
816 Node->getNameInfo().getName().getCXXOverloadedOperator();
817 if (QualifierLoc == nullptr && OOK != OO_None) {
818 // Print reduction identifier in C format
819 OS << getOperatorSpelling(OOK);
822 if (QualifierLoc != nullptr)
823 QualifierLoc->print(OS, Policy);
824 OS << Node->getNameInfo();
827 VisitOMPClauseList(Node, ' ');
832 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
833 if (!Node->varlist_empty()) {
835 if (Node->getModifierLoc().isValid()) {
837 << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
839 VisitOMPClauseList(Node, '(');
840 if (Node->getModifierLoc().isValid())
842 if (Node->getStep() != nullptr) {
844 Node->getStep()->printPretty(OS, nullptr, Policy, 0);
850 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
851 if (!Node->varlist_empty()) {
853 VisitOMPClauseList(Node, '(');
854 if (Node->getAlignment() != nullptr) {
856 Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
862 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
863 if (!Node->varlist_empty()) {
865 VisitOMPClauseList(Node, '(');
870 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
871 if (!Node->varlist_empty()) {
873 VisitOMPClauseList(Node, '(');
878 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
879 if (!Node->varlist_empty()) {
880 VisitOMPClauseList(Node, '(');
885 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
887 OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
888 Node->getDependencyKind());
889 if (!Node->varlist_empty()) {
891 VisitOMPClauseList(Node, ' ');
896 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
897 if (!Node->varlist_empty()) {
899 if (Node->getMapType() != OMPC_MAP_unknown) {
900 if (Node->getMapTypeModifier() != OMPC_MAP_unknown) {
901 OS << getOpenMPSimpleClauseTypeName(OMPC_map,
902 Node->getMapTypeModifier());
905 OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
908 VisitOMPClauseList(Node, ' ');
914 //===----------------------------------------------------------------------===//
915 // OpenMP directives printing methods
916 //===----------------------------------------------------------------------===//
918 void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S) {
919 OMPClausePrinter Printer(OS, Policy);
920 ArrayRef<OMPClause *> Clauses = S->clauses();
921 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
923 if (*I && !(*I)->isImplicit()) {
928 if (S->hasAssociatedStmt() && S->getAssociatedStmt()) {
929 assert(isa<CapturedStmt>(S->getAssociatedStmt()) &&
930 "Expected captured statement!");
931 Stmt *CS = cast<CapturedStmt>(S->getAssociatedStmt())->getCapturedStmt();
936 void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
937 Indent() << "#pragma omp parallel ";
938 PrintOMPExecutableDirective(Node);
941 void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
942 Indent() << "#pragma omp simd ";
943 PrintOMPExecutableDirective(Node);
946 void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
947 Indent() << "#pragma omp for ";
948 PrintOMPExecutableDirective(Node);
951 void StmtPrinter::VisitOMPForSimdDirective(OMPForSimdDirective *Node) {
952 Indent() << "#pragma omp for simd ";
953 PrintOMPExecutableDirective(Node);
956 void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
957 Indent() << "#pragma omp sections ";
958 PrintOMPExecutableDirective(Node);
961 void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
962 Indent() << "#pragma omp section";
963 PrintOMPExecutableDirective(Node);
966 void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
967 Indent() << "#pragma omp single ";
968 PrintOMPExecutableDirective(Node);
971 void StmtPrinter::VisitOMPMasterDirective(OMPMasterDirective *Node) {
972 Indent() << "#pragma omp master";
973 PrintOMPExecutableDirective(Node);
976 void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) {
977 Indent() << "#pragma omp critical";
978 if (Node->getDirectiveName().getName()) {
980 Node->getDirectiveName().printName(OS);
984 PrintOMPExecutableDirective(Node);
987 void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) {
988 Indent() << "#pragma omp parallel for ";
989 PrintOMPExecutableDirective(Node);
992 void StmtPrinter::VisitOMPParallelForSimdDirective(
993 OMPParallelForSimdDirective *Node) {
994 Indent() << "#pragma omp parallel for simd ";
995 PrintOMPExecutableDirective(Node);
998 void StmtPrinter::VisitOMPParallelSectionsDirective(
999 OMPParallelSectionsDirective *Node) {
1000 Indent() << "#pragma omp parallel sections ";
1001 PrintOMPExecutableDirective(Node);
1004 void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) {
1005 Indent() << "#pragma omp task ";
1006 PrintOMPExecutableDirective(Node);
1009 void StmtPrinter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *Node) {
1010 Indent() << "#pragma omp taskyield";
1011 PrintOMPExecutableDirective(Node);
1014 void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) {
1015 Indent() << "#pragma omp barrier";
1016 PrintOMPExecutableDirective(Node);
1019 void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) {
1020 Indent() << "#pragma omp taskwait";
1021 PrintOMPExecutableDirective(Node);
1024 void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) {
1025 Indent() << "#pragma omp taskgroup";
1026 PrintOMPExecutableDirective(Node);
1029 void StmtPrinter::VisitOMPFlushDirective(OMPFlushDirective *Node) {
1030 Indent() << "#pragma omp flush ";
1031 PrintOMPExecutableDirective(Node);
1034 void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
1035 Indent() << "#pragma omp ordered ";
1036 PrintOMPExecutableDirective(Node);
1039 void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) {
1040 Indent() << "#pragma omp atomic ";
1041 PrintOMPExecutableDirective(Node);
1044 void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) {
1045 Indent() << "#pragma omp target ";
1046 PrintOMPExecutableDirective(Node);
1049 void StmtPrinter::VisitOMPTargetDataDirective(OMPTargetDataDirective *Node) {
1050 Indent() << "#pragma omp target data ";
1051 PrintOMPExecutableDirective(Node);
1054 void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {
1055 Indent() << "#pragma omp teams ";
1056 PrintOMPExecutableDirective(Node);
1059 void StmtPrinter::VisitOMPCancellationPointDirective(
1060 OMPCancellationPointDirective *Node) {
1061 Indent() << "#pragma omp cancellation point "
1062 << getOpenMPDirectiveName(Node->getCancelRegion());
1063 PrintOMPExecutableDirective(Node);
1066 void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
1067 Indent() << "#pragma omp cancel "
1068 << getOpenMPDirectiveName(Node->getCancelRegion()) << " ";
1069 PrintOMPExecutableDirective(Node);
1072 void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) {
1073 Indent() << "#pragma omp taskloop ";
1074 PrintOMPExecutableDirective(Node);
1077 void StmtPrinter::VisitOMPTaskLoopSimdDirective(
1078 OMPTaskLoopSimdDirective *Node) {
1079 Indent() << "#pragma omp taskloop simd ";
1080 PrintOMPExecutableDirective(Node);
1083 void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) {
1084 Indent() << "#pragma omp distribute ";
1085 PrintOMPExecutableDirective(Node);
1088 //===----------------------------------------------------------------------===//
1089 // Expr printing methods.
1090 //===----------------------------------------------------------------------===//
1092 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
1093 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1094 Qualifier->print(OS, Policy);
1095 if (Node->hasTemplateKeyword())
1097 OS << Node->getNameInfo();
1098 if (Node->hasExplicitTemplateArgs())
1099 TemplateSpecializationType::PrintTemplateArgumentList(
1100 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1103 void StmtPrinter::VisitDependentScopeDeclRefExpr(
1104 DependentScopeDeclRefExpr *Node) {
1105 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1106 Qualifier->print(OS, Policy);
1107 if (Node->hasTemplateKeyword())
1109 OS << Node->getNameInfo();
1110 if (Node->hasExplicitTemplateArgs())
1111 TemplateSpecializationType::PrintTemplateArgumentList(
1112 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1115 void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
1116 if (Node->getQualifier())
1117 Node->getQualifier()->print(OS, Policy);
1118 if (Node->hasTemplateKeyword())
1120 OS << Node->getNameInfo();
1121 if (Node->hasExplicitTemplateArgs())
1122 TemplateSpecializationType::PrintTemplateArgumentList(
1123 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1126 void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
1127 if (Node->getBase()) {
1128 PrintExpr(Node->getBase());
1129 OS << (Node->isArrow() ? "->" : ".");
1131 OS << *Node->getDecl();
1134 void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
1135 if (Node->isSuperReceiver())
1137 else if (Node->isObjectReceiver() && Node->getBase()) {
1138 PrintExpr(Node->getBase());
1140 } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
1141 OS << Node->getClassReceiver()->getName() << ".";
1144 if (Node->isImplicitProperty())
1145 Node->getImplicitPropertyGetter()->getSelector().print(OS);
1147 OS << Node->getExplicitProperty()->getName();
1150 void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
1152 PrintExpr(Node->getBaseExpr());
1154 PrintExpr(Node->getKeyExpr());
1158 void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
1159 OS << PredefinedExpr::getIdentTypeName(Node->getIdentType());
1162 void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
1163 unsigned value = Node->getValue();
1165 switch (Node->getKind()) {
1166 case CharacterLiteral::Ascii: break; // no prefix.
1167 case CharacterLiteral::Wide: OS << 'L'; break;
1168 case CharacterLiteral::UTF8: OS << "u8"; break;
1169 case CharacterLiteral::UTF16: OS << 'u'; break;
1170 case CharacterLiteral::UTF32: OS << 'U'; break;
1181 // TODO: K&R: the meaning of '\\a' is different in traditional C
1187 // Nonstandard escape sequence.
1207 if (value < 256 && isPrintable((unsigned char)value))
1208 OS << "'" << (char)value << "'";
1209 else if (value < 256)
1210 OS << "'\\x" << llvm::format("%02x", value) << "'";
1211 else if (value <= 0xFFFF)
1212 OS << "'\\u" << llvm::format("%04x", value) << "'";
1214 OS << "'\\U" << llvm::format("%08x", value) << "'";
1218 void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
1219 bool isSigned = Node->getType()->isSignedIntegerType();
1220 OS << Node->getValue().toString(10, isSigned);
1222 // Emit suffixes. Integer literals are always a builtin integer type.
1223 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1224 default: llvm_unreachable("Unexpected type for integer literal!");
1225 case BuiltinType::Char_S:
1226 case BuiltinType::Char_U: OS << "i8"; break;
1227 case BuiltinType::UChar: OS << "Ui8"; break;
1228 case BuiltinType::Short: OS << "i16"; break;
1229 case BuiltinType::UShort: OS << "Ui16"; break;
1230 case BuiltinType::Int: break; // no suffix.
1231 case BuiltinType::UInt: OS << 'U'; break;
1232 case BuiltinType::Long: OS << 'L'; break;
1233 case BuiltinType::ULong: OS << "UL"; break;
1234 case BuiltinType::LongLong: OS << "LL"; break;
1235 case BuiltinType::ULongLong: OS << "ULL"; break;
1239 static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
1241 SmallString<16> Str;
1242 Node->getValue().toString(Str);
1244 if (Str.find_first_not_of("-0123456789") == StringRef::npos)
1245 OS << '.'; // Trailing dot in order to separate from ints.
1250 // Emit suffixes. Float literals are always a builtin float type.
1251 switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1252 default: llvm_unreachable("Unexpected type for float literal!");
1253 case BuiltinType::Half: break; // FIXME: suffix?
1254 case BuiltinType::Double: break; // no suffix.
1255 case BuiltinType::Float: OS << 'F'; break;
1256 case BuiltinType::LongDouble: OS << 'L'; break;
1260 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
1261 PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
1264 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
1265 PrintExpr(Node->getSubExpr());
1269 void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
1270 Str->outputString(OS);
1272 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
1274 PrintExpr(Node->getSubExpr());
1277 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
1278 if (!Node->isPostfix()) {
1279 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1281 // Print a space if this is an "identifier operator" like __real, or if
1282 // it might be concatenated incorrectly like '+'.
1283 switch (Node->getOpcode()) {
1292 if (isa<UnaryOperator>(Node->getSubExpr()))
1297 PrintExpr(Node->getSubExpr());
1299 if (Node->isPostfix())
1300 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1303 void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
1304 OS << "__builtin_offsetof(";
1305 Node->getTypeSourceInfo()->getType().print(OS, Policy);
1307 bool PrintedSomething = false;
1308 for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
1309 OffsetOfNode ON = Node->getComponent(i);
1310 if (ON.getKind() == OffsetOfNode::Array) {
1313 PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
1315 PrintedSomething = true;
1319 // Skip implicit base indirections.
1320 if (ON.getKind() == OffsetOfNode::Base)
1323 // Field or identifier node.
1324 IdentifierInfo *Id = ON.getFieldName();
1328 if (PrintedSomething)
1331 PrintedSomething = true;
1332 OS << Id->getName();
1337 void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
1338 switch(Node->getKind()) {
1343 if (Policy.LangOpts.CPlusPlus)
1345 else if (Policy.LangOpts.C11)
1353 case UETT_OpenMPRequiredSimdAlign:
1354 OS << "__builtin_omp_required_simd_align";
1357 if (Node->isArgumentType()) {
1359 Node->getArgumentType().print(OS, Policy);
1363 PrintExpr(Node->getArgumentExpr());
1367 void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1369 PrintExpr(Node->getControllingExpr());
1370 for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
1372 QualType T = Node->getAssocType(i);
1376 T.print(OS, Policy);
1378 PrintExpr(Node->getAssocExpr(i));
1383 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
1384 PrintExpr(Node->getLHS());
1386 PrintExpr(Node->getRHS());
1390 void StmtPrinter::VisitOMPArraySectionExpr(OMPArraySectionExpr *Node) {
1391 PrintExpr(Node->getBase());
1393 if (Node->getLowerBound())
1394 PrintExpr(Node->getLowerBound());
1395 if (Node->getColonLoc().isValid()) {
1397 if (Node->getLength())
1398 PrintExpr(Node->getLength());
1403 void StmtPrinter::PrintCallArgs(CallExpr *Call) {
1404 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
1405 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1406 // Don't print any defaulted arguments
1411 PrintExpr(Call->getArg(i));
1415 void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1416 PrintExpr(Call->getCallee());
1418 PrintCallArgs(Call);
1421 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1422 // FIXME: Suppress printing implicit bases (like "this")
1423 PrintExpr(Node->getBase());
1425 MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1426 FieldDecl *ParentDecl = ParentMember
1427 ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) : nullptr;
1429 if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1430 OS << (Node->isArrow() ? "->" : ".");
1432 if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1433 if (FD->isAnonymousStructOrUnion())
1436 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1437 Qualifier->print(OS, Policy);
1438 if (Node->hasTemplateKeyword())
1440 OS << Node->getMemberNameInfo();
1441 if (Node->hasExplicitTemplateArgs())
1442 TemplateSpecializationType::PrintTemplateArgumentList(
1443 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
1445 void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1446 PrintExpr(Node->getBase());
1447 OS << (Node->isArrow() ? "->isa" : ".isa");
1450 void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1451 PrintExpr(Node->getBase());
1453 OS << Node->getAccessor().getName();
1455 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1457 Node->getTypeAsWritten().print(OS, Policy);
1459 PrintExpr(Node->getSubExpr());
1461 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1463 Node->getType().print(OS, Policy);
1465 PrintExpr(Node->getInitializer());
1467 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1468 // No need to print anything, simply forward to the subexpression.
1469 PrintExpr(Node->getSubExpr());
1471 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1472 PrintExpr(Node->getLHS());
1473 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1474 PrintExpr(Node->getRHS());
1476 void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1477 PrintExpr(Node->getLHS());
1478 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1479 PrintExpr(Node->getRHS());
1481 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1482 PrintExpr(Node->getCond());
1484 PrintExpr(Node->getLHS());
1486 PrintExpr(Node->getRHS());
1492 StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1493 PrintExpr(Node->getCommon());
1495 PrintExpr(Node->getFalseExpr());
1497 void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1498 OS << "&&" << Node->getLabel()->getName();
1501 void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1503 PrintRawCompoundStmt(E->getSubStmt());
1507 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1508 OS << "__builtin_choose_expr(";
1509 PrintExpr(Node->getCond());
1511 PrintExpr(Node->getLHS());
1513 PrintExpr(Node->getRHS());
1517 void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1521 void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1522 OS << "__builtin_shufflevector(";
1523 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1525 PrintExpr(Node->getExpr(i));
1530 void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1531 OS << "__builtin_convertvector(";
1532 PrintExpr(Node->getSrcExpr());
1534 Node->getType().print(OS, Policy);
1538 void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1539 if (Node->getSyntacticForm()) {
1540 Visit(Node->getSyntacticForm());
1545 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1547 if (Node->getInit(i))
1548 PrintExpr(Node->getInit(i));
1555 void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1557 for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1559 PrintExpr(Node->getExpr(i));
1564 void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1565 bool NeedsEquals = true;
1566 for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(),
1567 DEnd = Node->designators_end();
1569 if (D->isFieldDesignator()) {
1570 if (D->getDotLoc().isInvalid()) {
1571 if (IdentifierInfo *II = D->getFieldName()) {
1572 OS << II->getName() << ":";
1573 NeedsEquals = false;
1576 OS << "." << D->getFieldName()->getName();
1580 if (D->isArrayDesignator()) {
1581 PrintExpr(Node->getArrayIndex(*D));
1583 PrintExpr(Node->getArrayRangeStart(*D));
1585 PrintExpr(Node->getArrayRangeEnd(*D));
1595 PrintExpr(Node->getInit());
1598 void StmtPrinter::VisitDesignatedInitUpdateExpr(
1599 DesignatedInitUpdateExpr *Node) {
1602 PrintExpr(Node->getBase());
1605 OS << "/*updater*/";
1606 PrintExpr(Node->getUpdater());
1610 void StmtPrinter::VisitNoInitExpr(NoInitExpr *Node) {
1611 OS << "/*no init*/";
1614 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1615 if (Policy.LangOpts.CPlusPlus) {
1616 OS << "/*implicit*/";
1617 Node->getType().print(OS, Policy);
1620 OS << "/*implicit*/(";
1621 Node->getType().print(OS, Policy);
1623 if (Node->getType()->isRecordType())
1630 void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1631 OS << "__builtin_va_arg(";
1632 PrintExpr(Node->getSubExpr());
1634 Node->getType().print(OS, Policy);
1638 void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1639 PrintExpr(Node->getSyntacticForm());
1642 void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1643 const char *Name = nullptr;
1644 switch (Node->getOp()) {
1645 #define BUILTIN(ID, TYPE, ATTRS)
1646 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1647 case AtomicExpr::AO ## ID: \
1650 #include "clang/Basic/Builtins.def"
1654 // AtomicExpr stores its subexpressions in a permuted order.
1655 PrintExpr(Node->getPtr());
1656 if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1657 Node->getOp() != AtomicExpr::AO__atomic_load_n) {
1659 PrintExpr(Node->getVal1());
1661 if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1662 Node->isCmpXChg()) {
1664 PrintExpr(Node->getVal2());
1666 if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1667 Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1669 PrintExpr(Node->getWeak());
1671 if (Node->getOp() != AtomicExpr::AO__c11_atomic_init) {
1673 PrintExpr(Node->getOrder());
1675 if (Node->isCmpXChg()) {
1677 PrintExpr(Node->getOrderFail());
1683 void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1684 const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1686 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1688 #include "clang/Basic/OperatorKinds.def"
1691 OverloadedOperatorKind Kind = Node->getOperator();
1692 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1693 if (Node->getNumArgs() == 1) {
1694 OS << OpStrings[Kind] << ' ';
1695 PrintExpr(Node->getArg(0));
1697 PrintExpr(Node->getArg(0));
1698 OS << ' ' << OpStrings[Kind];
1700 } else if (Kind == OO_Arrow) {
1701 PrintExpr(Node->getArg(0));
1702 } else if (Kind == OO_Call) {
1703 PrintExpr(Node->getArg(0));
1705 for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1708 if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1709 PrintExpr(Node->getArg(ArgIdx));
1712 } else if (Kind == OO_Subscript) {
1713 PrintExpr(Node->getArg(0));
1715 PrintExpr(Node->getArg(1));
1717 } else if (Node->getNumArgs() == 1) {
1718 OS << OpStrings[Kind] << ' ';
1719 PrintExpr(Node->getArg(0));
1720 } else if (Node->getNumArgs() == 2) {
1721 PrintExpr(Node->getArg(0));
1722 OS << ' ' << OpStrings[Kind] << ' ';
1723 PrintExpr(Node->getArg(1));
1725 llvm_unreachable("unknown overloaded operator");
1729 void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1730 // If we have a conversion operator call only print the argument.
1731 CXXMethodDecl *MD = Node->getMethodDecl();
1732 if (MD && isa<CXXConversionDecl>(MD)) {
1733 PrintExpr(Node->getImplicitObjectArgument());
1736 VisitCallExpr(cast<CallExpr>(Node));
1739 void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1740 PrintExpr(Node->getCallee());
1742 PrintCallArgs(Node->getConfig());
1744 PrintCallArgs(Node);
1748 void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1749 OS << Node->getCastName() << '<';
1750 Node->getTypeAsWritten().print(OS, Policy);
1752 PrintExpr(Node->getSubExpr());
1756 void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1757 VisitCXXNamedCastExpr(Node);
1760 void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1761 VisitCXXNamedCastExpr(Node);
1764 void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1765 VisitCXXNamedCastExpr(Node);
1768 void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1769 VisitCXXNamedCastExpr(Node);
1772 void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1774 if (Node->isTypeOperand()) {
1775 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1777 PrintExpr(Node->getExprOperand());
1782 void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1784 if (Node->isTypeOperand()) {
1785 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1787 PrintExpr(Node->getExprOperand());
1792 void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1793 PrintExpr(Node->getBaseExpr());
1794 if (Node->isArrow())
1798 if (NestedNameSpecifier *Qualifier =
1799 Node->getQualifierLoc().getNestedNameSpecifier())
1800 Qualifier->print(OS, Policy);
1801 OS << Node->getPropertyDecl()->getDeclName();
1804 void StmtPrinter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *Node) {
1805 PrintExpr(Node->getBase());
1807 PrintExpr(Node->getIdx());
1811 void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1812 switch (Node->getLiteralOperatorKind()) {
1813 case UserDefinedLiteral::LOK_Raw:
1814 OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
1816 case UserDefinedLiteral::LOK_Template: {
1817 DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1818 const TemplateArgumentList *Args =
1819 cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1822 if (Args->size() != 1) {
1823 OS << "operator\"\"" << Node->getUDSuffix()->getName();
1824 TemplateSpecializationType::PrintTemplateArgumentList(
1825 OS, Args->data(), Args->size(), Policy);
1830 const TemplateArgument &Pack = Args->get(0);
1831 for (const auto &P : Pack.pack_elements()) {
1832 char C = (char)P.getAsIntegral().getZExtValue();
1837 case UserDefinedLiteral::LOK_Integer: {
1838 // Print integer literal without suffix.
1839 IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
1840 OS << Int->getValue().toString(10, /*isSigned*/false);
1843 case UserDefinedLiteral::LOK_Floating: {
1844 // Print floating literal without suffix.
1845 FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
1846 PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
1849 case UserDefinedLiteral::LOK_String:
1850 case UserDefinedLiteral::LOK_Character:
1851 PrintExpr(Node->getCookedLiteral());
1854 OS << Node->getUDSuffix()->getName();
1857 void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
1858 OS << (Node->getValue() ? "true" : "false");
1861 void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
1865 void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
1869 void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
1870 if (!Node->getSubExpr())
1874 PrintExpr(Node->getSubExpr());
1878 void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
1879 // Nothing to print: we picked up the default argument.
1882 void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
1883 // Nothing to print: we picked up the default initializer.
1886 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
1887 Node->getType().print(OS, Policy);
1888 // If there are no parens, this is list-initialization, and the braces are
1889 // part of the syntax of the inner construct.
1890 if (Node->getLParenLoc().isValid())
1892 PrintExpr(Node->getSubExpr());
1893 if (Node->getLParenLoc().isValid())
1897 void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
1898 PrintExpr(Node->getSubExpr());
1901 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
1902 Node->getType().print(OS, Policy);
1903 if (Node->isStdInitListInitialization())
1904 /* Nothing to do; braces are part of creating the std::initializer_list. */;
1905 else if (Node->isListInitialization())
1909 for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
1910 ArgEnd = Node->arg_end();
1911 Arg != ArgEnd; ++Arg) {
1912 if ((*Arg)->isDefaultArgument())
1914 if (Arg != Node->arg_begin())
1918 if (Node->isStdInitListInitialization())
1920 else if (Node->isListInitialization())
1926 void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
1928 bool NeedComma = false;
1929 switch (Node->getCaptureDefault()) {
1943 for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
1944 CEnd = Node->explicit_capture_end();
1951 switch (C->getCaptureKind()) {
1957 if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C))
1959 OS << C->getCapturedVar()->getName();
1963 OS << C->getCapturedVar()->getName();
1966 llvm_unreachable("VLA type in explicit captures.");
1969 if (Node->isInitCapture(C))
1970 PrintExpr(C->getCapturedVar()->getInit());
1974 if (Node->hasExplicitParameters()) {
1976 CXXMethodDecl *Method = Node->getCallOperator();
1978 for (auto P : Method->params()) {
1984 std::string ParamStr = P->getNameAsString();
1985 P->getOriginalType().print(OS, Policy, ParamStr);
1987 if (Method->isVariadic()) {
1994 if (Node->isMutable())
1997 const FunctionProtoType *Proto
1998 = Method->getType()->getAs<FunctionProtoType>();
1999 Proto->printExceptionSpecification(OS, Policy);
2001 // FIXME: Attributes
2003 // Print the trailing return type if it was specified in the source.
2004 if (Node->hasExplicitResultType()) {
2006 Proto->getReturnType().print(OS, Policy);
2011 CompoundStmt *Body = Node->getBody();
2016 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
2017 if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
2018 TSInfo->getType().print(OS, Policy);
2020 Node->getType().print(OS, Policy);
2024 void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
2025 if (E->isGlobalNew())
2028 unsigned NumPlace = E->getNumPlacementArgs();
2029 if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
2031 PrintExpr(E->getPlacementArg(0));
2032 for (unsigned i = 1; i < NumPlace; ++i) {
2033 if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
2036 PrintExpr(E->getPlacementArg(i));
2040 if (E->isParenTypeId())
2043 if (Expr *Size = E->getArraySize()) {
2044 llvm::raw_string_ostream s(TypeS);
2046 Size->printPretty(s, Helper, Policy);
2049 E->getAllocatedType().print(OS, Policy, TypeS);
2050 if (E->isParenTypeId())
2053 CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
2055 if (InitStyle == CXXNewExpr::CallInit)
2057 PrintExpr(E->getInitializer());
2058 if (InitStyle == CXXNewExpr::CallInit)
2063 void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
2064 if (E->isGlobalDelete())
2067 if (E->isArrayForm())
2069 PrintExpr(E->getArgument());
2072 void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
2073 PrintExpr(E->getBase());
2078 if (E->getQualifier())
2079 E->getQualifier()->print(OS, Policy);
2082 if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
2083 OS << II->getName();
2085 E->getDestroyedType().print(OS, Policy);
2088 void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
2089 if (E->isListInitialization() && !E->isStdInitListInitialization())
2092 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
2093 if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
2094 // Don't print any defaulted arguments
2099 PrintExpr(E->getArg(i));
2102 if (E->isListInitialization() && !E->isStdInitListInitialization())
2106 void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
2107 PrintExpr(E->getSubExpr());
2110 void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
2111 // Just forward to the subexpression.
2112 PrintExpr(E->getSubExpr());
2116 StmtPrinter::VisitCXXUnresolvedConstructExpr(
2117 CXXUnresolvedConstructExpr *Node) {
2118 Node->getTypeAsWritten().print(OS, Policy);
2120 for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
2121 ArgEnd = Node->arg_end();
2122 Arg != ArgEnd; ++Arg) {
2123 if (Arg != Node->arg_begin())
2130 void StmtPrinter::VisitCXXDependentScopeMemberExpr(
2131 CXXDependentScopeMemberExpr *Node) {
2132 if (!Node->isImplicitAccess()) {
2133 PrintExpr(Node->getBase());
2134 OS << (Node->isArrow() ? "->" : ".");
2136 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2137 Qualifier->print(OS, Policy);
2138 if (Node->hasTemplateKeyword())
2140 OS << Node->getMemberNameInfo();
2141 if (Node->hasExplicitTemplateArgs())
2142 TemplateSpecializationType::PrintTemplateArgumentList(
2143 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
2146 void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
2147 if (!Node->isImplicitAccess()) {
2148 PrintExpr(Node->getBase());
2149 OS << (Node->isArrow() ? "->" : ".");
2151 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2152 Qualifier->print(OS, Policy);
2153 if (Node->hasTemplateKeyword())
2155 OS << Node->getMemberNameInfo();
2156 if (Node->hasExplicitTemplateArgs())
2157 TemplateSpecializationType::PrintTemplateArgumentList(
2158 OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy);
2161 static const char *getTypeTraitName(TypeTrait TT) {
2163 #define TYPE_TRAIT_1(Spelling, Name, Key) \
2164 case clang::UTT_##Name: return #Spelling;
2165 #define TYPE_TRAIT_2(Spelling, Name, Key) \
2166 case clang::BTT_##Name: return #Spelling;
2167 #define TYPE_TRAIT_N(Spelling, Name, Key) \
2168 case clang::TT_##Name: return #Spelling;
2169 #include "clang/Basic/TokenKinds.def"
2171 llvm_unreachable("Type trait not covered by switch");
2174 static const char *getTypeTraitName(ArrayTypeTrait ATT) {
2176 case ATT_ArrayRank: return "__array_rank";
2177 case ATT_ArrayExtent: return "__array_extent";
2179 llvm_unreachable("Array type trait not covered by switch");
2182 static const char *getExpressionTraitName(ExpressionTrait ET) {
2184 case ET_IsLValueExpr: return "__is_lvalue_expr";
2185 case ET_IsRValueExpr: return "__is_rvalue_expr";
2187 llvm_unreachable("Expression type trait not covered by switch");
2190 void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
2191 OS << getTypeTraitName(E->getTrait()) << "(";
2192 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
2195 E->getArg(I)->getType().print(OS, Policy);
2200 void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2201 OS << getTypeTraitName(E->getTrait()) << '(';
2202 E->getQueriedType().print(OS, Policy);
2206 void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2207 OS << getExpressionTraitName(E->getTrait()) << '(';
2208 PrintExpr(E->getQueriedExpression());
2212 void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2214 PrintExpr(E->getOperand());
2218 void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2219 PrintExpr(E->getPattern());
2223 void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2224 OS << "sizeof...(" << *E->getPack() << ")";
2227 void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
2228 SubstNonTypeTemplateParmPackExpr *Node) {
2229 OS << *Node->getParameterPack();
2232 void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
2233 SubstNonTypeTemplateParmExpr *Node) {
2234 Visit(Node->getReplacement());
2237 void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2238 OS << *E->getParameterPack();
2241 void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
2242 PrintExpr(Node->GetTemporaryExpr());
2245 void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2248 PrintExpr(E->getLHS());
2249 OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2253 OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2254 PrintExpr(E->getRHS());
2259 // C++ Coroutines TS
2261 void StmtPrinter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
2262 Visit(S->getBody());
2265 void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) {
2267 if (S->getOperand()) {
2269 Visit(S->getOperand());
2274 void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) {
2276 PrintExpr(S->getOperand());
2279 void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) {
2281 PrintExpr(S->getOperand());
2286 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
2288 VisitStringLiteral(Node->getString());
2291 void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
2293 Visit(E->getSubExpr());
2296 void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
2298 ObjCArrayLiteral::child_range Ch = E->children();
2299 for (auto I = Ch.begin(), E = Ch.end(); I != E; ++I) {
2300 if (I != Ch.begin())
2307 void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
2309 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
2313 ObjCDictionaryElement Element = E->getKeyValueElement(I);
2316 Visit(Element.Value);
2317 if (Element.isPackExpansion())
2323 void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
2325 Node->getEncodedType().print(OS, Policy);
2329 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
2331 Node->getSelector().print(OS);
2335 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
2336 OS << "@protocol(" << *Node->getProtocol() << ')';
2339 void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
2341 switch (Mess->getReceiverKind()) {
2342 case ObjCMessageExpr::Instance:
2343 PrintExpr(Mess->getInstanceReceiver());
2346 case ObjCMessageExpr::Class:
2347 Mess->getClassReceiver().print(OS, Policy);
2350 case ObjCMessageExpr::SuperInstance:
2351 case ObjCMessageExpr::SuperClass:
2357 Selector selector = Mess->getSelector();
2358 if (selector.isUnarySelector()) {
2359 OS << selector.getNameForSlot(0);
2361 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
2362 if (i < selector.getNumArgs()) {
2363 if (i > 0) OS << ' ';
2364 if (selector.getIdentifierInfoForSlot(i))
2365 OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
2369 else OS << ", "; // Handle variadic methods.
2371 PrintExpr(Mess->getArg(i));
2377 void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
2378 OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
2382 StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
2383 PrintExpr(E->getSubExpr());
2387 StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
2388 OS << '(' << E->getBridgeKindName();
2389 E->getType().print(OS, Policy);
2391 PrintExpr(E->getSubExpr());
2394 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
2395 BlockDecl *BD = Node->getBlockDecl();
2398 const FunctionType *AFT = Node->getFunctionType();
2400 if (isa<FunctionNoProtoType>(AFT)) {
2402 } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
2404 for (BlockDecl::param_iterator AI = BD->param_begin(),
2405 E = BD->param_end(); AI != E; ++AI) {
2406 if (AI != BD->param_begin()) OS << ", ";
2407 std::string ParamStr = (*AI)->getNameAsString();
2408 (*AI)->getType().print(OS, Policy, ParamStr);
2411 const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
2412 if (FT->isVariadic()) {
2413 if (!BD->param_empty()) OS << ", ";
2421 void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
2422 PrintExpr(Node->getSourceExpr());
2425 void StmtPrinter::VisitTypoExpr(TypoExpr *Node) {
2426 // TODO: Print something reasonable for a TypoExpr, if necessary.
2427 assert(false && "Cannot print TypoExpr nodes");
2430 void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
2431 OS << "__builtin_astype(";
2432 PrintExpr(Node->getSrcExpr());
2434 Node->getType().print(OS, Policy);
2438 //===----------------------------------------------------------------------===//
2439 // Stmt method implementations
2440 //===----------------------------------------------------------------------===//
2442 void Stmt::dumpPretty(const ASTContext &Context) const {
2443 printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
2446 void Stmt::printPretty(raw_ostream &OS,
2447 PrinterHelper *Helper,
2448 const PrintingPolicy &Policy,
2449 unsigned Indentation) const {
2450 StmtPrinter P(OS, Helper, Policy, Indentation);
2451 P.Visit(const_cast<Stmt*>(this));
2454 //===----------------------------------------------------------------------===//
2456 //===----------------------------------------------------------------------===//
2458 // Implement virtual destructor.
2459 PrinterHelper::~PrinterHelper() {}