clang 20.0.0git
StmtPrinter.cpp
Go to the documentation of this file.
1//===- StmtPrinter.cpp - Printing implementation for Stmt ASTs ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
10// pretty print the AST back out to C code.
11//
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/Attr.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclBase.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclObjC.h"
22#include "clang/AST/Expr.h"
23#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
29#include "clang/AST/Stmt.h"
30#include "clang/AST/StmtCXX.h"
31#include "clang/AST/StmtObjC.h"
35#include "clang/AST/Type.h"
39#include "clang/Basic/LLVM.h"
40#include "clang/Basic/Lambda.h"
45#include "clang/Lex/Lexer.h"
46#include "llvm/ADT/ArrayRef.h"
47#include "llvm/ADT/SmallVector.h"
48#include "llvm/ADT/StringExtras.h"
49#include "llvm/ADT/StringRef.h"
50#include "llvm/Support/Compiler.h"
51#include "llvm/Support/ErrorHandling.h"
52#include "llvm/Support/raw_ostream.h"
53#include <cassert>
54#include <optional>
55#include <string>
56
57using namespace clang;
58
59//===----------------------------------------------------------------------===//
60// StmtPrinter Visitor
61//===----------------------------------------------------------------------===//
62
63namespace {
64
65 class StmtPrinter : public StmtVisitor<StmtPrinter> {
66 raw_ostream &OS;
67 unsigned IndentLevel;
68 PrinterHelper* Helper;
69 PrintingPolicy Policy;
70 std::string NL;
71 const ASTContext *Context;
72
73 public:
74 StmtPrinter(raw_ostream &os, PrinterHelper *helper,
75 const PrintingPolicy &Policy, unsigned Indentation = 0,
76 StringRef NL = "\n", const ASTContext *Context = nullptr)
77 : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy),
78 NL(NL), Context(Context) {}
79
80 void PrintStmt(Stmt *S) { PrintStmt(S, Policy.Indentation); }
81
82 void PrintStmt(Stmt *S, int SubIndent) {
83 IndentLevel += SubIndent;
84 if (isa_and_nonnull<Expr>(S)) {
85 // If this is an expr used in a stmt context, indent and newline it.
86 Indent();
87 Visit(S);
88 OS << ";" << NL;
89 } else if (S) {
90 Visit(S);
91 } else {
92 Indent() << "<<<NULL STATEMENT>>>" << NL;
93 }
94 IndentLevel -= SubIndent;
95 }
96
97 void PrintInitStmt(Stmt *S, unsigned PrefixWidth) {
98 // FIXME: Cope better with odd prefix widths.
99 IndentLevel += (PrefixWidth + 1) / 2;
100 if (auto *DS = dyn_cast<DeclStmt>(S))
101 PrintRawDeclStmt(DS);
102 else
103 PrintExpr(cast<Expr>(S));
104 OS << "; ";
105 IndentLevel -= (PrefixWidth + 1) / 2;
106 }
107
108 void PrintControlledStmt(Stmt *S) {
109 if (auto *CS = dyn_cast<CompoundStmt>(S)) {
110 OS << " ";
111 PrintRawCompoundStmt(CS);
112 OS << NL;
113 } else {
114 OS << NL;
115 PrintStmt(S);
116 }
117 }
118
119 void PrintRawCompoundStmt(CompoundStmt *S);
120 void PrintRawDecl(Decl *D);
121 void PrintRawDeclStmt(const DeclStmt *S);
122 void PrintRawIfStmt(IfStmt *If);
123 void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
124 void PrintCallArgs(CallExpr *E);
125 void PrintRawSEHExceptHandler(SEHExceptStmt *S);
126 void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
127 void PrintOMPExecutableDirective(OMPExecutableDirective *S,
128 bool ForceNoStmt = false);
129 void PrintFPPragmas(CompoundStmt *S);
130 void PrintOpenACCClauseList(OpenACCConstructStmt *S);
131 void PrintOpenACCConstruct(OpenACCConstructStmt *S);
132
133 void PrintExpr(Expr *E) {
134 if (E)
135 Visit(E);
136 else
137 OS << "<null expr>";
138 }
139
140 raw_ostream &Indent(int Delta = 0) {
141 for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
142 OS << " ";
143 return OS;
144 }
145
146 void Visit(Stmt* S) {
147 if (Helper && Helper->handledStmt(S,OS))
148 return;
150 }
151
152 void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
153 Indent() << "<<unknown stmt type>>" << NL;
154 }
155
156 void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
157 OS << "<<unknown expr type>>";
158 }
159
160 void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
161
162#define ABSTRACT_STMT(CLASS)
163#define STMT(CLASS, PARENT) \
164 void Visit##CLASS(CLASS *Node);
165#include "clang/AST/StmtNodes.inc"
166 };
167
168} // namespace
169
170//===----------------------------------------------------------------------===//
171// Stmt printing methods.
172//===----------------------------------------------------------------------===//
173
174/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
175/// with no newline after the }.
176void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
177 assert(Node && "Compound statement cannot be null");
178 OS << "{" << NL;
179 PrintFPPragmas(Node);
180 for (auto *I : Node->body())
181 PrintStmt(I);
182
183 Indent() << "}";
184}
185
186void StmtPrinter::PrintFPPragmas(CompoundStmt *S) {
187 if (!S->hasStoredFPFeatures())
188 return;
189 FPOptionsOverride FPO = S->getStoredFPFeatures();
190 bool FEnvAccess = false;
191 if (FPO.hasAllowFEnvAccessOverride()) {
192 FEnvAccess = FPO.getAllowFEnvAccessOverride();
193 Indent() << "#pragma STDC FENV_ACCESS " << (FEnvAccess ? "ON" : "OFF")
194 << NL;
195 }
196 if (FPO.hasSpecifiedExceptionModeOverride()) {
198 FPO.getSpecifiedExceptionModeOverride();
199 if (!FEnvAccess || EM != LangOptions::FPE_Strict) {
200 Indent() << "#pragma clang fp exceptions(";
201 switch (FPO.getSpecifiedExceptionModeOverride()) {
202 default:
203 break;
204 case LangOptions::FPE_Ignore:
205 OS << "ignore";
206 break;
207 case LangOptions::FPE_MayTrap:
208 OS << "maytrap";
209 break;
210 case LangOptions::FPE_Strict:
211 OS << "strict";
212 break;
213 }
214 OS << ")\n";
215 }
216 }
217 if (FPO.hasConstRoundingModeOverride()) {
218 LangOptions::RoundingMode RM = FPO.getConstRoundingModeOverride();
219 Indent() << "#pragma STDC FENV_ROUND ";
220 switch (RM) {
221 case llvm::RoundingMode::TowardZero:
222 OS << "FE_TOWARDZERO";
223 break;
224 case llvm::RoundingMode::NearestTiesToEven:
225 OS << "FE_TONEAREST";
226 break;
227 case llvm::RoundingMode::TowardPositive:
228 OS << "FE_UPWARD";
229 break;
230 case llvm::RoundingMode::TowardNegative:
231 OS << "FE_DOWNWARD";
232 break;
233 case llvm::RoundingMode::NearestTiesToAway:
234 OS << "FE_TONEARESTFROMZERO";
235 break;
236 case llvm::RoundingMode::Dynamic:
237 OS << "FE_DYNAMIC";
238 break;
239 default:
240 llvm_unreachable("Invalid rounding mode");
241 }
242 OS << NL;
243 }
244}
245
246void StmtPrinter::PrintRawDecl(Decl *D) {
247 D->print(OS, Policy, IndentLevel);
248}
249
250void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
251 SmallVector<Decl *, 2> Decls(S->decls());
252 Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
253}
254
255void StmtPrinter::VisitNullStmt(NullStmt *Node) {
256 Indent() << ";" << NL;
257}
258
259void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
260 Indent();
261 PrintRawDeclStmt(Node);
262 OS << ";" << NL;
263}
264
265void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
266 Indent();
267 PrintRawCompoundStmt(Node);
268 OS << "" << NL;
269}
270
271void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
272 Indent(-1) << "case ";
273 PrintExpr(Node->getLHS());
274 if (Node->getRHS()) {
275 OS << " ... ";
276 PrintExpr(Node->getRHS());
277 }
278 OS << ":" << NL;
279
280 PrintStmt(Node->getSubStmt(), 0);
281}
282
283void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
284 Indent(-1) << "default:" << NL;
285 PrintStmt(Node->getSubStmt(), 0);
286}
287
288void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
289 Indent(-1) << Node->getName() << ":" << NL;
290 PrintStmt(Node->getSubStmt(), 0);
291}
292
293void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
294 llvm::ArrayRef<const Attr *> Attrs = Node->getAttrs();
295 for (const auto *Attr : Attrs) {
296 Attr->printPretty(OS, Policy);
297 if (Attr != Attrs.back())
298 OS << ' ';
299 }
300
301 PrintStmt(Node->getSubStmt(), 0);
302}
303
304void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
305 if (If->isConsteval()) {
306 OS << "if ";
307 if (If->isNegatedConsteval())
308 OS << "!";
309 OS << "consteval";
310 OS << NL;
311 PrintStmt(If->getThen());
312 if (Stmt *Else = If->getElse()) {
313 Indent();
314 OS << "else";
315 PrintStmt(Else);
316 OS << NL;
317 }
318 return;
319 }
320
321 OS << "if (";
322 if (If->getInit())
323 PrintInitStmt(If->getInit(), 4);
324 if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
325 PrintRawDeclStmt(DS);
326 else
327 PrintExpr(If->getCond());
328 OS << ')';
329
330 if (auto *CS = dyn_cast<CompoundStmt>(If->getThen())) {
331 OS << ' ';
332 PrintRawCompoundStmt(CS);
333 OS << (If->getElse() ? " " : NL);
334 } else {
335 OS << NL;
336 PrintStmt(If->getThen());
337 if (If->getElse()) Indent();
338 }
339
340 if (Stmt *Else = If->getElse()) {
341 OS << "else";
342
343 if (auto *CS = dyn_cast<CompoundStmt>(Else)) {
344 OS << ' ';
345 PrintRawCompoundStmt(CS);
346 OS << NL;
347 } else if (auto *ElseIf = dyn_cast<IfStmt>(Else)) {
348 OS << ' ';
349 PrintRawIfStmt(ElseIf);
350 } else {
351 OS << NL;
352 PrintStmt(If->getElse());
353 }
354 }
355}
356
357void StmtPrinter::VisitIfStmt(IfStmt *If) {
358 Indent();
359 PrintRawIfStmt(If);
360}
361
362void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
363 Indent() << "switch (";
364 if (Node->getInit())
365 PrintInitStmt(Node->getInit(), 8);
366 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
367 PrintRawDeclStmt(DS);
368 else
369 PrintExpr(Node->getCond());
370 OS << ")";
371 PrintControlledStmt(Node->getBody());
372}
373
374void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
375 Indent() << "while (";
376 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
377 PrintRawDeclStmt(DS);
378 else
379 PrintExpr(Node->getCond());
380 OS << ")" << NL;
381 PrintStmt(Node->getBody());
382}
383
384void StmtPrinter::VisitDoStmt(DoStmt *Node) {
385 Indent() << "do ";
386 if (auto *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
387 PrintRawCompoundStmt(CS);
388 OS << " ";
389 } else {
390 OS << NL;
391 PrintStmt(Node->getBody());
392 Indent();
393 }
394
395 OS << "while (";
396 PrintExpr(Node->getCond());
397 OS << ");" << NL;
398}
399
400void StmtPrinter::VisitForStmt(ForStmt *Node) {
401 Indent() << "for (";
402 if (Node->getInit())
403 PrintInitStmt(Node->getInit(), 5);
404 else
405 OS << (Node->getCond() ? "; " : ";");
406 if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
407 PrintRawDeclStmt(DS);
408 else if (Node->getCond())
409 PrintExpr(Node->getCond());
410 OS << ";";
411 if (Node->getInc()) {
412 OS << " ";
413 PrintExpr(Node->getInc());
414 }
415 OS << ")";
416 PrintControlledStmt(Node->getBody());
417}
418
419void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
420 Indent() << "for (";
421 if (auto *DS = dyn_cast<DeclStmt>(Node->getElement()))
422 PrintRawDeclStmt(DS);
423 else
424 PrintExpr(cast<Expr>(Node->getElement()));
425 OS << " in ";
426 PrintExpr(Node->getCollection());
427 OS << ")";
428 PrintControlledStmt(Node->getBody());
429}
430
431void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
432 Indent() << "for (";
433 if (Node->getInit())
434 PrintInitStmt(Node->getInit(), 5);
435 PrintingPolicy SubPolicy(Policy);
436 SubPolicy.SuppressInitializers = true;
437 Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
438 OS << " : ";
439 PrintExpr(Node->getRangeInit());
440 OS << ")";
441 PrintControlledStmt(Node->getBody());
442}
443
444void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
445 Indent();
446 if (Node->isIfExists())
447 OS << "__if_exists (";
448 else
449 OS << "__if_not_exists (";
450
451 if (NestedNameSpecifier *Qualifier
452 = Node->getQualifierLoc().getNestedNameSpecifier())
453 Qualifier->print(OS, Policy);
454
455 OS << Node->getNameInfo() << ") ";
456
457 PrintRawCompoundStmt(Node->getSubStmt());
458}
459
460void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
461 Indent() << "goto " << Node->getLabel()->getName() << ";";
462 if (Policy.IncludeNewlines) OS << NL;
463}
464
465void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
466 Indent() << "goto *";
467 PrintExpr(Node->getTarget());
468 OS << ";";
469 if (Policy.IncludeNewlines) OS << NL;
470}
471
472void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
473 Indent() << "continue;";
474 if (Policy.IncludeNewlines) OS << NL;
475}
476
477void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
478 Indent() << "break;";
479 if (Policy.IncludeNewlines) OS << NL;
480}
481
482void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
483 Indent() << "return";
484 if (Node->getRetValue()) {
485 OS << " ";
486 PrintExpr(Node->getRetValue());
487 }
488 OS << ";";
489 if (Policy.IncludeNewlines) OS << NL;
490}
491
492void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
493 Indent() << "asm ";
494
495 if (Node->isVolatile())
496 OS << "volatile ";
497
498 if (Node->isAsmGoto())
499 OS << "goto ";
500
501 OS << "(";
502 VisitStringLiteral(Node->getAsmString());
503
504 // Outputs
505 if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
506 Node->getNumClobbers() != 0 || Node->getNumLabels() != 0)
507 OS << " : ";
508
509 for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
510 if (i != 0)
511 OS << ", ";
512
513 if (!Node->getOutputName(i).empty()) {
514 OS << '[';
515 OS << Node->getOutputName(i);
516 OS << "] ";
517 }
518
519 VisitStringLiteral(Node->getOutputConstraintLiteral(i));
520 OS << " (";
521 Visit(Node->getOutputExpr(i));
522 OS << ")";
523 }
524
525 // Inputs
526 if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0 ||
527 Node->getNumLabels() != 0)
528 OS << " : ";
529
530 for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
531 if (i != 0)
532 OS << ", ";
533
534 if (!Node->getInputName(i).empty()) {
535 OS << '[';
536 OS << Node->getInputName(i);
537 OS << "] ";
538 }
539
540 VisitStringLiteral(Node->getInputConstraintLiteral(i));
541 OS << " (";
542 Visit(Node->getInputExpr(i));
543 OS << ")";
544 }
545
546 // Clobbers
547 if (Node->getNumClobbers() != 0 || Node->getNumLabels())
548 OS << " : ";
549
550 for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
551 if (i != 0)
552 OS << ", ";
553
554 VisitStringLiteral(Node->getClobberStringLiteral(i));
555 }
556
557 // Labels
558 if (Node->getNumLabels() != 0)
559 OS << " : ";
560
561 for (unsigned i = 0, e = Node->getNumLabels(); i != e; ++i) {
562 if (i != 0)
563 OS << ", ";
564 OS << Node->getLabelName(i);
565 }
566
567 OS << ");";
568 if (Policy.IncludeNewlines) OS << NL;
569}
570
571void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
572 // FIXME: Implement MS style inline asm statement printer.
573 Indent() << "__asm ";
574 if (Node->hasBraces())
575 OS << "{" << NL;
576 OS << Node->getAsmString() << NL;
577 if (Node->hasBraces())
578 Indent() << "}" << NL;
579}
580
581void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
582 PrintStmt(Node->getCapturedDecl()->getBody());
583}
584
585void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
586 Indent() << "@try";
587 if (auto *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
588 PrintRawCompoundStmt(TS);
589 OS << NL;
590 }
591
592 for (ObjCAtCatchStmt *catchStmt : Node->catch_stmts()) {
593 Indent() << "@catch(";
594 if (Decl *DS = catchStmt->getCatchParamDecl())
595 PrintRawDecl(DS);
596 OS << ")";
597 if (auto *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
598 PrintRawCompoundStmt(CS);
599 OS << NL;
600 }
601 }
602
603 if (auto *FS = static_cast<ObjCAtFinallyStmt *>(Node->getFinallyStmt())) {
604 Indent() << "@finally";
605 if (auto *CS = dyn_cast<CompoundStmt>(FS->getFinallyBody())) {
606 PrintRawCompoundStmt(CS);
607 OS << NL;
608 }
609 }
610}
611
612void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
613}
614
615void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
616 Indent() << "@catch (...) { /* todo */ } " << NL;
617}
618
619void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
620 Indent() << "@throw";
621 if (Node->getThrowExpr()) {
622 OS << " ";
623 PrintExpr(Node->getThrowExpr());
624 }
625 OS << ";" << NL;
626}
627
628void StmtPrinter::VisitObjCAvailabilityCheckExpr(
630 OS << "@available(...)";
631}
632
633void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
634 Indent() << "@synchronized (";
635 PrintExpr(Node->getSynchExpr());
636 OS << ")";
637 PrintRawCompoundStmt(Node->getSynchBody());
638 OS << NL;
639}
640
641void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
642 Indent() << "@autoreleasepool";
643 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getSubStmt()));
644 OS << NL;
645}
646
647void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
648 OS << "catch (";
649 if (Decl *ExDecl = Node->getExceptionDecl())
650 PrintRawDecl(ExDecl);
651 else
652 OS << "...";
653 OS << ") ";
654 PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
655}
656
657void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
658 Indent();
659 PrintRawCXXCatchStmt(Node);
660 OS << NL;
661}
662
663void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
664 Indent() << "try ";
665 PrintRawCompoundStmt(Node->getTryBlock());
666 for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
667 OS << " ";
668 PrintRawCXXCatchStmt(Node->getHandler(i));
669 }
670 OS << NL;
671}
672
673void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
674 Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
675 PrintRawCompoundStmt(Node->getTryBlock());
676 SEHExceptStmt *E = Node->getExceptHandler();
677 SEHFinallyStmt *F = Node->getFinallyHandler();
678 if(E)
679 PrintRawSEHExceptHandler(E);
680 else {
681 assert(F && "Must have a finally block...");
682 PrintRawSEHFinallyStmt(F);
683 }
684 OS << NL;
685}
686
687void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
688 OS << "__finally ";
689 PrintRawCompoundStmt(Node->getBlock());
690 OS << NL;
691}
692
693void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
694 OS << "__except (";
695 VisitExpr(Node->getFilterExpr());
696 OS << ")" << NL;
697 PrintRawCompoundStmt(Node->getBlock());
698 OS << NL;
699}
700
701void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
702 Indent();
703 PrintRawSEHExceptHandler(Node);
704 OS << NL;
705}
706
707void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
708 Indent();
709 PrintRawSEHFinallyStmt(Node);
710 OS << NL;
711}
712
713void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
714 Indent() << "__leave;";
715 if (Policy.IncludeNewlines) OS << NL;
716}
717
718//===----------------------------------------------------------------------===//
719// OpenMP directives printing methods
720//===----------------------------------------------------------------------===//
721
722void StmtPrinter::VisitOMPCanonicalLoop(OMPCanonicalLoop *Node) {
723 PrintStmt(Node->getLoopStmt());
724}
725
726void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S,
727 bool ForceNoStmt) {
728 OMPClausePrinter Printer(OS, Policy);
729 ArrayRef<OMPClause *> Clauses = S->clauses();
730 for (auto *Clause : Clauses)
731 if (Clause && !Clause->isImplicit()) {
732 OS << ' ';
733 Printer.Visit(Clause);
734 }
735 OS << NL;
736 if (!ForceNoStmt && S->hasAssociatedStmt())
737 PrintStmt(S->getRawStmt());
738}
739
740void StmtPrinter::VisitOMPMetaDirective(OMPMetaDirective *Node) {
741 Indent() << "#pragma omp metadirective";
742 PrintOMPExecutableDirective(Node);
743}
744
745void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
746 Indent() << "#pragma omp parallel";
747 PrintOMPExecutableDirective(Node);
748}
749
750void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
751 Indent() << "#pragma omp simd";
752 PrintOMPExecutableDirective(Node);
753}
754
755void StmtPrinter::VisitOMPTileDirective(OMPTileDirective *Node) {
756 Indent() << "#pragma omp tile";
757 PrintOMPExecutableDirective(Node);
758}
759
760void StmtPrinter::VisitOMPUnrollDirective(OMPUnrollDirective *Node) {
761 Indent() << "#pragma omp unroll";
762 PrintOMPExecutableDirective(Node);
763}
764
765void StmtPrinter::VisitOMPReverseDirective(OMPReverseDirective *Node) {
766 Indent() << "#pragma omp reverse";
767 PrintOMPExecutableDirective(Node);
768}
769
770void StmtPrinter::VisitOMPInterchangeDirective(OMPInterchangeDirective *Node) {
771 Indent() << "#pragma omp interchange";
772 PrintOMPExecutableDirective(Node);
773}
774
775void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
776 Indent() << "#pragma omp for";
777 PrintOMPExecutableDirective(Node);
778}
779
780void StmtPrinter::VisitOMPForSimdDirective(OMPForSimdDirective *Node) {
781 Indent() << "#pragma omp for simd";
782 PrintOMPExecutableDirective(Node);
783}
784
785void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
786 Indent() << "#pragma omp sections";
787 PrintOMPExecutableDirective(Node);
788}
789
790void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
791 Indent() << "#pragma omp section";
792 PrintOMPExecutableDirective(Node);
793}
794
795void StmtPrinter::VisitOMPScopeDirective(OMPScopeDirective *Node) {
796 Indent() << "#pragma omp scope";
797 PrintOMPExecutableDirective(Node);
798}
799
800void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
801 Indent() << "#pragma omp single";
802 PrintOMPExecutableDirective(Node);
803}
804
805void StmtPrinter::VisitOMPMasterDirective(OMPMasterDirective *Node) {
806 Indent() << "#pragma omp master";
807 PrintOMPExecutableDirective(Node);
808}
809
810void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) {
811 Indent() << "#pragma omp critical";
812 if (Node->getDirectiveName().getName()) {
813 OS << " (";
814 Node->getDirectiveName().printName(OS, Policy);
815 OS << ")";
816 }
817 PrintOMPExecutableDirective(Node);
818}
819
820void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) {
821 Indent() << "#pragma omp parallel for";
822 PrintOMPExecutableDirective(Node);
823}
824
825void StmtPrinter::VisitOMPParallelForSimdDirective(
827 Indent() << "#pragma omp parallel for simd";
828 PrintOMPExecutableDirective(Node);
829}
830
831void StmtPrinter::VisitOMPParallelMasterDirective(
833 Indent() << "#pragma omp parallel master";
834 PrintOMPExecutableDirective(Node);
835}
836
837void StmtPrinter::VisitOMPParallelMaskedDirective(
839 Indent() << "#pragma omp parallel masked";
840 PrintOMPExecutableDirective(Node);
841}
842
843void StmtPrinter::VisitOMPParallelSectionsDirective(
845 Indent() << "#pragma omp parallel sections";
846 PrintOMPExecutableDirective(Node);
847}
848
849void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) {
850 Indent() << "#pragma omp task";
851 PrintOMPExecutableDirective(Node);
852}
853
854void StmtPrinter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *Node) {
855 Indent() << "#pragma omp taskyield";
856 PrintOMPExecutableDirective(Node);
857}
858
859void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) {
860 Indent() << "#pragma omp barrier";
861 PrintOMPExecutableDirective(Node);
862}
863
864void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) {
865 Indent() << "#pragma omp taskwait";
866 PrintOMPExecutableDirective(Node);
867}
868
869void StmtPrinter::VisitOMPAssumeDirective(OMPAssumeDirective *Node) {
870 Indent() << "#pragma omp assume";
871 PrintOMPExecutableDirective(Node);
872}
873
874void StmtPrinter::VisitOMPErrorDirective(OMPErrorDirective *Node) {
875 Indent() << "#pragma omp error";
876 PrintOMPExecutableDirective(Node);
877}
878
879void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) {
880 Indent() << "#pragma omp taskgroup";
881 PrintOMPExecutableDirective(Node);
882}
883
884void StmtPrinter::VisitOMPFlushDirective(OMPFlushDirective *Node) {
885 Indent() << "#pragma omp flush";
886 PrintOMPExecutableDirective(Node);
887}
888
889void StmtPrinter::VisitOMPDepobjDirective(OMPDepobjDirective *Node) {
890 Indent() << "#pragma omp depobj";
891 PrintOMPExecutableDirective(Node);
892}
893
894void StmtPrinter::VisitOMPScanDirective(OMPScanDirective *Node) {
895 Indent() << "#pragma omp scan";
896 PrintOMPExecutableDirective(Node);
897}
898
899void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
900 Indent() << "#pragma omp ordered";
901 PrintOMPExecutableDirective(Node, Node->hasClausesOfKind<OMPDependClause>());
902}
903
904void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) {
905 Indent() << "#pragma omp atomic";
906 PrintOMPExecutableDirective(Node);
907}
908
909void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) {
910 Indent() << "#pragma omp target";
911 PrintOMPExecutableDirective(Node);
912}
913
914void StmtPrinter::VisitOMPTargetDataDirective(OMPTargetDataDirective *Node) {
915 Indent() << "#pragma omp target data";
916 PrintOMPExecutableDirective(Node);
917}
918
919void StmtPrinter::VisitOMPTargetEnterDataDirective(
921 Indent() << "#pragma omp target enter data";
922 PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
923}
924
925void StmtPrinter::VisitOMPTargetExitDataDirective(
927 Indent() << "#pragma omp target exit data";
928 PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
929}
930
931void StmtPrinter::VisitOMPTargetParallelDirective(
933 Indent() << "#pragma omp target parallel";
934 PrintOMPExecutableDirective(Node);
935}
936
937void StmtPrinter::VisitOMPTargetParallelForDirective(
939 Indent() << "#pragma omp target parallel for";
940 PrintOMPExecutableDirective(Node);
941}
942
943void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {
944 Indent() << "#pragma omp teams";
945 PrintOMPExecutableDirective(Node);
946}
947
948void StmtPrinter::VisitOMPCancellationPointDirective(
950 Indent() << "#pragma omp cancellation point "
951 << getOpenMPDirectiveName(Node->getCancelRegion());
952 PrintOMPExecutableDirective(Node);
953}
954
955void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
956 Indent() << "#pragma omp cancel "
957 << getOpenMPDirectiveName(Node->getCancelRegion());
958 PrintOMPExecutableDirective(Node);
959}
960
961void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) {
962 Indent() << "#pragma omp taskloop";
963 PrintOMPExecutableDirective(Node);
964}
965
966void StmtPrinter::VisitOMPTaskLoopSimdDirective(
968 Indent() << "#pragma omp taskloop simd";
969 PrintOMPExecutableDirective(Node);
970}
971
972void StmtPrinter::VisitOMPMasterTaskLoopDirective(
974 Indent() << "#pragma omp master taskloop";
975 PrintOMPExecutableDirective(Node);
976}
977
978void StmtPrinter::VisitOMPMaskedTaskLoopDirective(
980 Indent() << "#pragma omp masked taskloop";
981 PrintOMPExecutableDirective(Node);
982}
983
984void StmtPrinter::VisitOMPMasterTaskLoopSimdDirective(
986 Indent() << "#pragma omp master taskloop simd";
987 PrintOMPExecutableDirective(Node);
988}
989
990void StmtPrinter::VisitOMPMaskedTaskLoopSimdDirective(
992 Indent() << "#pragma omp masked taskloop simd";
993 PrintOMPExecutableDirective(Node);
994}
995
996void StmtPrinter::VisitOMPParallelMasterTaskLoopDirective(
998 Indent() << "#pragma omp parallel master taskloop";
999 PrintOMPExecutableDirective(Node);
1000}
1001
1002void StmtPrinter::VisitOMPParallelMaskedTaskLoopDirective(
1004 Indent() << "#pragma omp parallel masked taskloop";
1005 PrintOMPExecutableDirective(Node);
1006}
1007
1008void StmtPrinter::VisitOMPParallelMasterTaskLoopSimdDirective(
1010 Indent() << "#pragma omp parallel master taskloop simd";
1011 PrintOMPExecutableDirective(Node);
1012}
1013
1014void StmtPrinter::VisitOMPParallelMaskedTaskLoopSimdDirective(
1016 Indent() << "#pragma omp parallel masked taskloop simd";
1017 PrintOMPExecutableDirective(Node);
1018}
1019
1020void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) {
1021 Indent() << "#pragma omp distribute";
1022 PrintOMPExecutableDirective(Node);
1023}
1024
1025void StmtPrinter::VisitOMPTargetUpdateDirective(
1027 Indent() << "#pragma omp target update";
1028 PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
1029}
1030
1031void StmtPrinter::VisitOMPDistributeParallelForDirective(
1033 Indent() << "#pragma omp distribute parallel for";
1034 PrintOMPExecutableDirective(Node);
1035}
1036
1037void StmtPrinter::VisitOMPDistributeParallelForSimdDirective(
1039 Indent() << "#pragma omp distribute parallel for simd";
1040 PrintOMPExecutableDirective(Node);
1041}
1042
1043void StmtPrinter::VisitOMPDistributeSimdDirective(
1045 Indent() << "#pragma omp distribute simd";
1046 PrintOMPExecutableDirective(Node);
1047}
1048
1049void StmtPrinter::VisitOMPTargetParallelForSimdDirective(
1051 Indent() << "#pragma omp target parallel for simd";
1052 PrintOMPExecutableDirective(Node);
1053}
1054
1055void StmtPrinter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *Node) {
1056 Indent() << "#pragma omp target simd";
1057 PrintOMPExecutableDirective(Node);
1058}
1059
1060void StmtPrinter::VisitOMPTeamsDistributeDirective(
1062 Indent() << "#pragma omp teams distribute";
1063 PrintOMPExecutableDirective(Node);
1064}
1065
1066void StmtPrinter::VisitOMPTeamsDistributeSimdDirective(
1068 Indent() << "#pragma omp teams distribute simd";
1069 PrintOMPExecutableDirective(Node);
1070}
1071
1072void StmtPrinter::VisitOMPTeamsDistributeParallelForSimdDirective(
1074 Indent() << "#pragma omp teams distribute parallel for simd";
1075 PrintOMPExecutableDirective(Node);
1076}
1077
1078void StmtPrinter::VisitOMPTeamsDistributeParallelForDirective(
1080 Indent() << "#pragma omp teams distribute parallel for";
1081 PrintOMPExecutableDirective(Node);
1082}
1083
1084void StmtPrinter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *Node) {
1085 Indent() << "#pragma omp target teams";
1086 PrintOMPExecutableDirective(Node);
1087}
1088
1089void StmtPrinter::VisitOMPTargetTeamsDistributeDirective(
1091 Indent() << "#pragma omp target teams distribute";
1092 PrintOMPExecutableDirective(Node);
1093}
1094
1095void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForDirective(
1097 Indent() << "#pragma omp target teams distribute parallel for";
1098 PrintOMPExecutableDirective(Node);
1099}
1100
1101void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1103 Indent() << "#pragma omp target teams distribute parallel for simd";
1104 PrintOMPExecutableDirective(Node);
1105}
1106
1107void StmtPrinter::VisitOMPTargetTeamsDistributeSimdDirective(
1109 Indent() << "#pragma omp target teams distribute simd";
1110 PrintOMPExecutableDirective(Node);
1111}
1112
1113void StmtPrinter::VisitOMPInteropDirective(OMPInteropDirective *Node) {
1114 Indent() << "#pragma omp interop";
1115 PrintOMPExecutableDirective(Node);
1116}
1117
1118void StmtPrinter::VisitOMPDispatchDirective(OMPDispatchDirective *Node) {
1119 Indent() << "#pragma omp dispatch";
1120 PrintOMPExecutableDirective(Node);
1121}
1122
1123void StmtPrinter::VisitOMPMaskedDirective(OMPMaskedDirective *Node) {
1124 Indent() << "#pragma omp masked";
1125 PrintOMPExecutableDirective(Node);
1126}
1127
1128void StmtPrinter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *Node) {
1129 Indent() << "#pragma omp loop";
1130 PrintOMPExecutableDirective(Node);
1131}
1132
1133void StmtPrinter::VisitOMPTeamsGenericLoopDirective(
1135 Indent() << "#pragma omp teams loop";
1136 PrintOMPExecutableDirective(Node);
1137}
1138
1139void StmtPrinter::VisitOMPTargetTeamsGenericLoopDirective(
1141 Indent() << "#pragma omp target teams loop";
1142 PrintOMPExecutableDirective(Node);
1143}
1144
1145void StmtPrinter::VisitOMPParallelGenericLoopDirective(
1147 Indent() << "#pragma omp parallel loop";
1148 PrintOMPExecutableDirective(Node);
1149}
1150
1151void StmtPrinter::VisitOMPTargetParallelGenericLoopDirective(
1153 Indent() << "#pragma omp target parallel loop";
1154 PrintOMPExecutableDirective(Node);
1155}
1156
1157//===----------------------------------------------------------------------===//
1158// OpenACC construct printing methods
1159//===----------------------------------------------------------------------===//
1160void StmtPrinter::PrintOpenACCClauseList(OpenACCConstructStmt *S) {
1161 if (!S->clauses().empty()) {
1162 OS << ' ';
1163 OpenACCClausePrinter Printer(OS, Policy);
1164 Printer.VisitClauseList(S->clauses());
1165 }
1166}
1167void StmtPrinter::PrintOpenACCConstruct(OpenACCConstructStmt *S) {
1168 Indent() << "#pragma acc " << S->getDirectiveKind();
1169 PrintOpenACCClauseList(S);
1170 OS << '\n';
1171}
1172void StmtPrinter::VisitOpenACCComputeConstruct(OpenACCComputeConstruct *S) {
1173 PrintOpenACCConstruct(S);
1174 PrintStmt(S->getStructuredBlock());
1175}
1176
1177void StmtPrinter::VisitOpenACCLoopConstruct(OpenACCLoopConstruct *S) {
1178 PrintOpenACCConstruct(S);
1179 PrintStmt(S->getLoop());
1180}
1181
1182void StmtPrinter::VisitOpenACCCombinedConstruct(OpenACCCombinedConstruct *S) {
1183 PrintOpenACCConstruct(S);
1184 PrintStmt(S->getLoop());
1185}
1186
1187void StmtPrinter::VisitOpenACCDataConstruct(OpenACCDataConstruct *S) {
1188 PrintOpenACCConstruct(S);
1189 PrintStmt(S->getStructuredBlock());
1190}
1191void StmtPrinter::VisitOpenACCHostDataConstruct(OpenACCHostDataConstruct *S) {
1192 PrintOpenACCConstruct(S);
1193 PrintStmt(S->getStructuredBlock());
1194}
1195void StmtPrinter::VisitOpenACCEnterDataConstruct(OpenACCEnterDataConstruct *S) {
1196 PrintOpenACCConstruct(S);
1197}
1198void StmtPrinter::VisitOpenACCExitDataConstruct(OpenACCExitDataConstruct *S) {
1199 PrintOpenACCConstruct(S);
1200}
1201void StmtPrinter::VisitOpenACCInitConstruct(OpenACCInitConstruct *S) {
1202 PrintOpenACCConstruct(S);
1203}
1204void StmtPrinter::VisitOpenACCShutdownConstruct(OpenACCShutdownConstruct *S) {
1205 PrintOpenACCConstruct(S);
1206}
1207
1208void StmtPrinter::VisitOpenACCWaitConstruct(OpenACCWaitConstruct *S) {
1209 Indent() << "#pragma acc wait";
1210 if (!S->getLParenLoc().isInvalid()) {
1211 OS << "(";
1212 if (S->hasDevNumExpr()) {
1213 OS << "devnum: ";
1214 S->getDevNumExpr()->printPretty(OS, nullptr, Policy);
1215 OS << " : ";
1216 }
1217
1218 if (S->hasQueuesTag())
1219 OS << "queues: ";
1220
1221 llvm::interleaveComma(S->getQueueIdExprs(), OS, [&](const Expr *E) {
1222 E->printPretty(OS, nullptr, Policy);
1223 });
1224
1225 OS << ")";
1226 }
1227
1228 PrintOpenACCClauseList(S);
1229 OS << '\n';
1230}
1231
1232//===----------------------------------------------------------------------===//
1233// Expr printing methods.
1234//===----------------------------------------------------------------------===//
1235
1236void StmtPrinter::VisitSourceLocExpr(SourceLocExpr *Node) {
1237 OS << Node->getBuiltinStr() << "()";
1238}
1239
1240void StmtPrinter::VisitEmbedExpr(EmbedExpr *Node) {
1241 llvm::report_fatal_error("Not implemented");
1242}
1243
1244void StmtPrinter::VisitConstantExpr(ConstantExpr *Node) {
1245 PrintExpr(Node->getSubExpr());
1246}
1247
1248void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
1249 if (const auto *OCED = dyn_cast<OMPCapturedExprDecl>(Node->getDecl())) {
1250 OCED->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy);
1251 return;
1252 }
1253 if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(Node->getDecl())) {
1254 TPOD->printAsExpr(OS, Policy);
1255 return;
1256 }
1257 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1258 Qualifier->print(OS, Policy);
1259 if (Node->hasTemplateKeyword())
1260 OS << "template ";
1261 if (Policy.CleanUglifiedParameters &&
1262 isa<ParmVarDecl, NonTypeTemplateParmDecl>(Node->getDecl()) &&
1263 Node->getDecl()->getIdentifier())
1264 OS << Node->getDecl()->getIdentifier()->deuglifiedName();
1265 else
1266 Node->getNameInfo().printName(OS, Policy);
1267 if (Node->hasExplicitTemplateArgs()) {
1268 const TemplateParameterList *TPL = nullptr;
1269 if (!Node->hadMultipleCandidates())
1270 if (auto *TD = dyn_cast<TemplateDecl>(Node->getDecl()))
1271 TPL = TD->getTemplateParameters();
1272 printTemplateArgumentList(OS, Node->template_arguments(), Policy, TPL);
1273 }
1274}
1275
1276void StmtPrinter::VisitDependentScopeDeclRefExpr(
1278 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1279 Qualifier->print(OS, Policy);
1280 if (Node->hasTemplateKeyword())
1281 OS << "template ";
1282 OS << Node->getNameInfo();
1283 if (Node->hasExplicitTemplateArgs())
1284 printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1285}
1286
1287void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
1288 if (Node->getQualifier())
1289 Node->getQualifier()->print(OS, Policy);
1290 if (Node->hasTemplateKeyword())
1291 OS << "template ";
1292 OS << Node->getNameInfo();
1293 if (Node->hasExplicitTemplateArgs())
1294 printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1295}
1296
1297static bool isImplicitSelf(const Expr *E) {
1298 if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
1299 if (const auto *PD = dyn_cast<ImplicitParamDecl>(DRE->getDecl())) {
1300 if (PD->getParameterKind() == ImplicitParamKind::ObjCSelf &&
1301 DRE->getBeginLoc().isInvalid())
1302 return true;
1303 }
1304 }
1305 return false;
1306}
1307
1308void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
1309 if (Node->getBase()) {
1310 if (!Policy.SuppressImplicitBase ||
1311 !isImplicitSelf(Node->getBase()->IgnoreImpCasts())) {
1312 PrintExpr(Node->getBase());
1313 OS << (Node->isArrow() ? "->" : ".");
1314 }
1315 }
1316 OS << *Node->getDecl();
1317}
1318
1319void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
1320 if (Node->isSuperReceiver())
1321 OS << "super.";
1322 else if (Node->isObjectReceiver() && Node->getBase()) {
1323 PrintExpr(Node->getBase());
1324 OS << ".";
1325 } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
1326 OS << Node->getClassReceiver()->getName() << ".";
1327 }
1328
1329 if (Node->isImplicitProperty()) {
1330 if (const auto *Getter = Node->getImplicitPropertyGetter())
1331 Getter->getSelector().print(OS);
1332 else
1334 Node->getImplicitPropertySetter()->getSelector());
1335 } else
1336 OS << Node->getExplicitProperty()->getName();
1337}
1338
1339void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
1340 PrintExpr(Node->getBaseExpr());
1341 OS << "[";
1342 PrintExpr(Node->getKeyExpr());
1343 OS << "]";
1344}
1345
1346void StmtPrinter::VisitSYCLUniqueStableNameExpr(
1348 OS << "__builtin_sycl_unique_stable_name(";
1349 Node->getTypeSourceInfo()->getType().print(OS, Policy);
1350 OS << ")";
1351}
1352
1353void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
1354 OS << PredefinedExpr::getIdentKindName(Node->getIdentKind());
1355}
1356
1357void StmtPrinter::VisitOpenACCAsteriskSizeExpr(OpenACCAsteriskSizeExpr *Node) {
1358 OS << '*';
1359}
1360
1361void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
1362 CharacterLiteral::print(Node->getValue(), Node->getKind(), OS);
1363}
1364
1365/// Prints the given expression using the original source text. Returns true on
1366/// success, false otherwise.
1367static bool printExprAsWritten(raw_ostream &OS, Expr *E,
1368 const ASTContext *Context) {
1369 if (!Context)
1370 return false;
1371 bool Invalid = false;
1372 StringRef Source = Lexer::getSourceText(
1374 Context->getSourceManager(), Context->getLangOpts(), &Invalid);
1375 if (!Invalid) {
1376 OS << Source;
1377 return true;
1378 }
1379 return false;
1380}
1381
1382void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
1383 if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context))
1384 return;
1385 bool isSigned = Node->getType()->isSignedIntegerType();
1386 OS << toString(Node->getValue(), 10, isSigned);
1387
1388 if (isa<BitIntType>(Node->getType())) {
1389 OS << (isSigned ? "wb" : "uwb");
1390 return;
1391 }
1392
1393 // Emit suffixes. Integer literals are always a builtin integer type.
1394 switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
1395 default: llvm_unreachable("Unexpected type for integer literal!");
1396 case BuiltinType::Char_S:
1397 case BuiltinType::Char_U: OS << "i8"; break;
1398 case BuiltinType::UChar: OS << "Ui8"; break;
1399 case BuiltinType::SChar: OS << "i8"; break;
1400 case BuiltinType::Short: OS << "i16"; break;
1401 case BuiltinType::UShort: OS << "Ui16"; break;
1402 case BuiltinType::Int: break; // no suffix.
1403 case BuiltinType::UInt: OS << 'U'; break;
1404 case BuiltinType::Long: OS << 'L'; break;
1405 case BuiltinType::ULong: OS << "UL"; break;
1406 case BuiltinType::LongLong: OS << "LL"; break;
1407 case BuiltinType::ULongLong: OS << "ULL"; break;
1408 case BuiltinType::Int128:
1409 break; // no suffix.
1410 case BuiltinType::UInt128:
1411 break; // no suffix.
1412 case BuiltinType::WChar_S:
1413 case BuiltinType::WChar_U:
1414 break; // no suffix
1415 }
1416}
1417
1418void StmtPrinter::VisitFixedPointLiteral(FixedPointLiteral *Node) {
1419 if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context))
1420 return;
1421 OS << Node->getValueAsString(/*Radix=*/10);
1422
1423 switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
1424 default: llvm_unreachable("Unexpected type for fixed point literal!");
1425 case BuiltinType::ShortFract: OS << "hr"; break;
1426 case BuiltinType::ShortAccum: OS << "hk"; break;
1427 case BuiltinType::UShortFract: OS << "uhr"; break;
1428 case BuiltinType::UShortAccum: OS << "uhk"; break;
1429 case BuiltinType::Fract: OS << "r"; break;
1430 case BuiltinType::Accum: OS << "k"; break;
1431 case BuiltinType::UFract: OS << "ur"; break;
1432 case BuiltinType::UAccum: OS << "uk"; break;
1433 case BuiltinType::LongFract: OS << "lr"; break;
1434 case BuiltinType::LongAccum: OS << "lk"; break;
1435 case BuiltinType::ULongFract: OS << "ulr"; break;
1436 case BuiltinType::ULongAccum: OS << "ulk"; break;
1437 }
1438}
1439
1440static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
1441 bool PrintSuffix) {
1442 SmallString<16> Str;
1443 Node->getValue().toString(Str);
1444 OS << Str;
1445 if (Str.find_first_not_of("-0123456789") == StringRef::npos)
1446 OS << '.'; // Trailing dot in order to separate from ints.
1447
1448 if (!PrintSuffix)
1449 return;
1450
1451 // Emit suffixes. Float literals are always a builtin float type.
1452 switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
1453 default: llvm_unreachable("Unexpected type for float literal!");
1454 case BuiltinType::Half: break; // FIXME: suffix?
1455 case BuiltinType::Ibm128: break; // FIXME: No suffix for ibm128 literal
1456 case BuiltinType::Double: break; // no suffix.
1457 case BuiltinType::Float16: OS << "F16"; break;
1458 case BuiltinType::Float: OS << 'F'; break;
1459 case BuiltinType::LongDouble: OS << 'L'; break;
1460 case BuiltinType::Float128: OS << 'Q'; break;
1461 }
1462}
1463
1464void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
1465 if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context))
1466 return;
1467 PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
1468}
1469
1470void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
1471 PrintExpr(Node->getSubExpr());
1472 OS << "i";
1473}
1474
1475void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
1476 Str->outputString(OS);
1477}
1478
1479void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
1480 OS << "(";
1481 PrintExpr(Node->getSubExpr());
1482 OS << ")";
1483}
1484
1485void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
1486 if (!Node->isPostfix()) {
1487 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1488
1489 // Print a space if this is an "identifier operator" like __real, or if
1490 // it might be concatenated incorrectly like '+'.
1491 switch (Node->getOpcode()) {
1492 default: break;
1493 case UO_Real:
1494 case UO_Imag:
1495 case UO_Extension:
1496 OS << ' ';
1497 break;
1498 case UO_Plus:
1499 case UO_Minus:
1500 if (isa<UnaryOperator>(Node->getSubExpr()))
1501 OS << ' ';
1502 break;
1503 }
1504 }
1505 PrintExpr(Node->getSubExpr());
1506
1507 if (Node->isPostfix())
1508 OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1509}
1510
1511void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
1512 OS << "__builtin_offsetof(";
1513 Node->getTypeSourceInfo()->getType().print(OS, Policy);
1514 OS << ", ";
1515 bool PrintedSomething = false;
1516 for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
1517 OffsetOfNode ON = Node->getComponent(i);
1518 if (ON.getKind() == OffsetOfNode::Array) {
1519 // Array node
1520 OS << "[";
1521 PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
1522 OS << "]";
1523 PrintedSomething = true;
1524 continue;
1525 }
1526
1527 // Skip implicit base indirections.
1528 if (ON.getKind() == OffsetOfNode::Base)
1529 continue;
1530
1531 // Field or identifier node.
1532 const IdentifierInfo *Id = ON.getFieldName();
1533 if (!Id)
1534 continue;
1535
1536 if (PrintedSomething)
1537 OS << ".";
1538 else
1539 PrintedSomething = true;
1540 OS << Id->getName();
1541 }
1542 OS << ")";
1543}
1544
1545void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(
1547 const char *Spelling = getTraitSpelling(Node->getKind());
1548 if (Node->getKind() == UETT_AlignOf) {
1549 if (Policy.Alignof)
1550 Spelling = "alignof";
1551 else if (Policy.UnderscoreAlignof)
1552 Spelling = "_Alignof";
1553 else
1554 Spelling = "__alignof";
1555 }
1556
1557 OS << Spelling;
1558
1559 if (Node->isArgumentType()) {
1560 OS << '(';
1561 Node->getArgumentType().print(OS, Policy);
1562 OS << ')';
1563 } else {
1564 OS << " ";
1565 PrintExpr(Node->getArgumentExpr());
1566 }
1567}
1568
1569void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1570 OS << "_Generic(";
1571 if (Node->isExprPredicate())
1572 PrintExpr(Node->getControllingExpr());
1573 else
1574 Node->getControllingType()->getType().print(OS, Policy);
1575
1576 for (const GenericSelectionExpr::Association &Assoc : Node->associations()) {
1577 OS << ", ";
1578 QualType T = Assoc.getType();
1579 if (T.isNull())
1580 OS << "default";
1581 else
1582 T.print(OS, Policy);
1583 OS << ": ";
1584 PrintExpr(Assoc.getAssociationExpr());
1585 }
1586 OS << ")";
1587}
1588
1589void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
1590 PrintExpr(Node->getLHS());
1591 OS << "[";
1592 PrintExpr(Node->getRHS());
1593 OS << "]";
1594}
1595
1596void StmtPrinter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *Node) {
1597 PrintExpr(Node->getBase());
1598 OS << "[";
1599 PrintExpr(Node->getRowIdx());
1600 OS << "]";
1601 OS << "[";
1602 PrintExpr(Node->getColumnIdx());
1603 OS << "]";
1604}
1605
1606void StmtPrinter::VisitArraySectionExpr(ArraySectionExpr *Node) {
1607 PrintExpr(Node->getBase());
1608 OS << "[";
1609 if (Node->getLowerBound())
1610 PrintExpr(Node->getLowerBound());
1611 if (Node->getColonLocFirst().isValid()) {
1612 OS << ":";
1613 if (Node->getLength())
1614 PrintExpr(Node->getLength());
1615 }
1616 if (Node->isOMPArraySection() && Node->getColonLocSecond().isValid()) {
1617 OS << ":";
1618 if (Node->getStride())
1619 PrintExpr(Node->getStride());
1620 }
1621 OS << "]";
1622}
1623
1624void StmtPrinter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *Node) {
1625 OS << "(";
1626 for (Expr *E : Node->getDimensions()) {
1627 OS << "[";
1628 PrintExpr(E);
1629 OS << "]";
1630 }
1631 OS << ")";
1632 PrintExpr(Node->getBase());
1633}
1634
1635void StmtPrinter::VisitOMPIteratorExpr(OMPIteratorExpr *Node) {
1636 OS << "iterator(";
1637 for (unsigned I = 0, E = Node->numOfIterators(); I < E; ++I) {
1638 auto *VD = cast<ValueDecl>(Node->getIteratorDecl(I));
1639 VD->getType().print(OS, Policy);
1640 const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I);
1641 OS << " " << VD->getName() << " = ";
1642 PrintExpr(Range.Begin);
1643 OS << ":";
1644 PrintExpr(Range.End);
1645 if (Range.Step) {
1646 OS << ":";
1647 PrintExpr(Range.Step);
1648 }
1649 if (I < E - 1)
1650 OS << ", ";
1651 }
1652 OS << ")";
1653}
1654
1655void StmtPrinter::PrintCallArgs(CallExpr *Call) {
1656 for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
1657 if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1658 // Don't print any defaulted arguments
1659 break;
1660 }
1661
1662 if (i) OS << ", ";
1663 PrintExpr(Call->getArg(i));
1664 }
1665}
1666
1667void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1668 PrintExpr(Call->getCallee());
1669 OS << "(";
1670 PrintCallArgs(Call);
1671 OS << ")";
1672}
1673
1674static bool isImplicitThis(const Expr *E) {
1675 if (const auto *TE = dyn_cast<CXXThisExpr>(E))
1676 return TE->isImplicit();
1677 return false;
1678}
1679
1680void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1681 if (!Policy.SuppressImplicitBase || !isImplicitThis(Node->getBase())) {
1682 PrintExpr(Node->getBase());
1683
1684 auto *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1685 FieldDecl *ParentDecl =
1686 ParentMember ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl())
1687 : nullptr;
1688
1689 if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1690 OS << (Node->isArrow() ? "->" : ".");
1691 }
1692
1693 if (auto *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1694 if (FD->isAnonymousStructOrUnion())
1695 return;
1696
1697 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1698 Qualifier->print(OS, Policy);
1699 if (Node->hasTemplateKeyword())
1700 OS << "template ";
1701 OS << Node->getMemberNameInfo();
1702 const TemplateParameterList *TPL = nullptr;
1703 if (auto *FD = dyn_cast<FunctionDecl>(Node->getMemberDecl())) {
1704 if (!Node->hadMultipleCandidates())
1705 if (auto *FTD = FD->getPrimaryTemplate())
1706 TPL = FTD->getTemplateParameters();
1707 } else if (auto *VTSD =
1708 dyn_cast<VarTemplateSpecializationDecl>(Node->getMemberDecl()))
1709 TPL = VTSD->getSpecializedTemplate()->getTemplateParameters();
1710 if (Node->hasExplicitTemplateArgs())
1711 printTemplateArgumentList(OS, Node->template_arguments(), Policy, TPL);
1712}
1713
1714void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1715 PrintExpr(Node->getBase());
1716 OS << (Node->isArrow() ? "->isa" : ".isa");
1717}
1718
1719void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1720 PrintExpr(Node->getBase());
1721 OS << ".";
1722 OS << Node->getAccessor().getName();
1723}
1724
1725void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1726 OS << '(';
1727 Node->getTypeAsWritten().print(OS, Policy);
1728 OS << ')';
1729 PrintExpr(Node->getSubExpr());
1730}
1731
1732void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1733 OS << '(';
1734 Node->getType().print(OS, Policy);
1735 OS << ')';
1736 PrintExpr(Node->getInitializer());
1737}
1738
1739void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1740 // No need to print anything, simply forward to the subexpression.
1741 PrintExpr(Node->getSubExpr());
1742}
1743
1744void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1745 PrintExpr(Node->getLHS());
1746 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1747 PrintExpr(Node->getRHS());
1748}
1749
1750void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1751 PrintExpr(Node->getLHS());
1752 OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1753 PrintExpr(Node->getRHS());
1754}
1755
1756void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1757 PrintExpr(Node->getCond());
1758 OS << " ? ";
1759 PrintExpr(Node->getLHS());
1760 OS << " : ";
1761 PrintExpr(Node->getRHS());
1762}
1763
1764// GNU extensions.
1765
1766void
1767StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1768 PrintExpr(Node->getCommon());
1769 OS << " ?: ";
1770 PrintExpr(Node->getFalseExpr());
1771}
1772
1773void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1774 OS << "&&" << Node->getLabel()->getName();
1775}
1776
1777void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1778 OS << "(";
1779 PrintRawCompoundStmt(E->getSubStmt());
1780 OS << ")";
1781}
1782
1783void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1784 OS << "__builtin_choose_expr(";
1785 PrintExpr(Node->getCond());
1786 OS << ", ";
1787 PrintExpr(Node->getLHS());
1788 OS << ", ";
1789 PrintExpr(Node->getRHS());
1790 OS << ")";
1791}
1792
1793void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1794 OS << "__null";
1795}
1796
1797void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1798 OS << "__builtin_shufflevector(";
1799 for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1800 if (i) OS << ", ";
1801 PrintExpr(Node->getExpr(i));
1802 }
1803 OS << ")";
1804}
1805
1806void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1807 OS << "__builtin_convertvector(";
1808 PrintExpr(Node->getSrcExpr());
1809 OS << ", ";
1810 Node->getType().print(OS, Policy);
1811 OS << ")";
1812}
1813
1814void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1815 if (Node->getSyntacticForm()) {
1816 Visit(Node->getSyntacticForm());
1817 return;
1818 }
1819
1820 OS << "{";
1821 for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1822 if (i) OS << ", ";
1823 if (Node->getInit(i))
1824 PrintExpr(Node->getInit(i));
1825 else
1826 OS << "{}";
1827 }
1828 OS << "}";
1829}
1830
1831void StmtPrinter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *Node) {
1832 // There's no way to express this expression in any of our supported
1833 // languages, so just emit something terse and (hopefully) clear.
1834 OS << "{";
1835 PrintExpr(Node->getSubExpr());
1836 OS << "}";
1837}
1838
1839void StmtPrinter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *Node) {
1840 OS << "*";
1841}
1842
1843void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1844 OS << "(";
1845 for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1846 if (i) OS << ", ";
1847 PrintExpr(Node->getExpr(i));
1848 }
1849 OS << ")";
1850}
1851
1852void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1853 bool NeedsEquals = true;
1854 for (const DesignatedInitExpr::Designator &D : Node->designators()) {
1855 if (D.isFieldDesignator()) {
1856 if (D.getDotLoc().isInvalid()) {
1857 if (const IdentifierInfo *II = D.getFieldName()) {
1858 OS << II->getName() << ":";
1859 NeedsEquals = false;
1860 }
1861 } else {
1862 OS << "." << D.getFieldName()->getName();
1863 }
1864 } else {
1865 OS << "[";
1866 if (D.isArrayDesignator()) {
1867 PrintExpr(Node->getArrayIndex(D));
1868 } else {
1869 PrintExpr(Node->getArrayRangeStart(D));
1870 OS << " ... ";
1871 PrintExpr(Node->getArrayRangeEnd(D));
1872 }
1873 OS << "]";
1874 }
1875 }
1876
1877 if (NeedsEquals)
1878 OS << " = ";
1879 else
1880 OS << " ";
1881 PrintExpr(Node->getInit());
1882}
1883
1884void StmtPrinter::VisitDesignatedInitUpdateExpr(
1886 OS << "{";
1887 OS << "/*base*/";
1888 PrintExpr(Node->getBase());
1889 OS << ", ";
1890
1891 OS << "/*updater*/";
1892 PrintExpr(Node->getUpdater());
1893 OS << "}";
1894}
1895
1896void StmtPrinter::VisitNoInitExpr(NoInitExpr *Node) {
1897 OS << "/*no init*/";
1898}
1899
1900void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1901 if (Node->getType()->getAsCXXRecordDecl()) {
1902 OS << "/*implicit*/";
1903 Node->getType().print(OS, Policy);
1904 OS << "()";
1905 } else {
1906 OS << "/*implicit*/(";
1907 Node->getType().print(OS, Policy);
1908 OS << ')';
1909 if (Node->getType()->isRecordType())
1910 OS << "{}";
1911 else
1912 OS << 0;
1913 }
1914}
1915
1916void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1917 OS << "__builtin_va_arg(";
1918 PrintExpr(Node->getSubExpr());
1919 OS << ", ";
1920 Node->getType().print(OS, Policy);
1921 OS << ")";
1922}
1923
1924void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1925 PrintExpr(Node->getSyntacticForm());
1926}
1927
1928void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1929 const char *Name = nullptr;
1930 switch (Node->getOp()) {
1931#define BUILTIN(ID, TYPE, ATTRS)
1932#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1933 case AtomicExpr::AO ## ID: \
1934 Name = #ID "("; \
1935 break;
1936#include "clang/Basic/Builtins.inc"
1937 }
1938 OS << Name;
1939
1940 // AtomicExpr stores its subexpressions in a permuted order.
1941 PrintExpr(Node->getPtr());
1942 if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1943 Node->getOp() != AtomicExpr::AO__atomic_load_n &&
1944 Node->getOp() != AtomicExpr::AO__scoped_atomic_load_n &&
1945 Node->getOp() != AtomicExpr::AO__opencl_atomic_load &&
1946 Node->getOp() != AtomicExpr::AO__hip_atomic_load) {
1947 OS << ", ";
1948 PrintExpr(Node->getVal1());
1949 }
1950 if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1951 Node->isCmpXChg()) {
1952 OS << ", ";
1953 PrintExpr(Node->getVal2());
1954 }
1955 if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1956 Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1957 OS << ", ";
1958 PrintExpr(Node->getWeak());
1959 }
1960 if (Node->getOp() != AtomicExpr::AO__c11_atomic_init &&
1961 Node->getOp() != AtomicExpr::AO__opencl_atomic_init) {
1962 OS << ", ";
1963 PrintExpr(Node->getOrder());
1964 }
1965 if (Node->isCmpXChg()) {
1966 OS << ", ";
1967 PrintExpr(Node->getOrderFail());
1968 }
1969 OS << ")";
1970}
1971
1972// C++
1973void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1974 OverloadedOperatorKind Kind = Node->getOperator();
1975 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1976 if (Node->getNumArgs() == 1) {
1977 OS << getOperatorSpelling(Kind) << ' ';
1978 PrintExpr(Node->getArg(0));
1979 } else {
1980 PrintExpr(Node->getArg(0));
1981 OS << ' ' << getOperatorSpelling(Kind);
1982 }
1983 } else if (Kind == OO_Arrow) {
1984 PrintExpr(Node->getArg(0));
1985 } else if (Kind == OO_Call || Kind == OO_Subscript) {
1986 PrintExpr(Node->getArg(0));
1987 OS << (Kind == OO_Call ? '(' : '[');
1988 for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1989 if (ArgIdx > 1)
1990 OS << ", ";
1991 if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1992 PrintExpr(Node->getArg(ArgIdx));
1993 }
1994 OS << (Kind == OO_Call ? ')' : ']');
1995 } else if (Node->getNumArgs() == 1) {
1996 OS << getOperatorSpelling(Kind) << ' ';
1997 PrintExpr(Node->getArg(0));
1998 } else if (Node->getNumArgs() == 2) {
1999 PrintExpr(Node->getArg(0));
2000 OS << ' ' << getOperatorSpelling(Kind) << ' ';
2001 PrintExpr(Node->getArg(1));
2002 } else {
2003 llvm_unreachable("unknown overloaded operator");
2004 }
2005}
2006
2007void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
2008 // If we have a conversion operator call only print the argument.
2009 CXXMethodDecl *MD = Node->getMethodDecl();
2010 if (isa_and_nonnull<CXXConversionDecl>(MD)) {
2011 PrintExpr(Node->getImplicitObjectArgument());
2012 return;
2013 }
2014 VisitCallExpr(cast<CallExpr>(Node));
2015}
2016
2017void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
2018 PrintExpr(Node->getCallee());
2019 OS << "<<<";
2020 PrintCallArgs(Node->getConfig());
2021 OS << ">>>(";
2022 PrintCallArgs(Node);
2023 OS << ")";
2024}
2025
2026void StmtPrinter::VisitCXXRewrittenBinaryOperator(
2029 Node->getDecomposedForm();
2030 PrintExpr(const_cast<Expr*>(Decomposed.LHS));
2031 OS << ' ' << BinaryOperator::getOpcodeStr(Decomposed.Opcode) << ' ';
2032 PrintExpr(const_cast<Expr*>(Decomposed.RHS));
2033}
2034
2035void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
2036 OS << Node->getCastName() << '<';
2037 Node->getTypeAsWritten().print(OS, Policy);
2038 OS << ">(";
2039 PrintExpr(Node->getSubExpr());
2040 OS << ")";
2041}
2042
2043void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
2044 VisitCXXNamedCastExpr(Node);
2045}
2046
2047void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
2048 VisitCXXNamedCastExpr(Node);
2049}
2050
2051void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
2052 VisitCXXNamedCastExpr(Node);
2053}
2054
2055void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
2056 VisitCXXNamedCastExpr(Node);
2057}
2058
2059void StmtPrinter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *Node) {
2060 OS << "__builtin_bit_cast(";
2061 Node->getTypeInfoAsWritten()->getType().print(OS, Policy);
2062 OS << ", ";
2063 PrintExpr(Node->getSubExpr());
2064 OS << ")";
2065}
2066
2067void StmtPrinter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *Node) {
2068 VisitCXXNamedCastExpr(Node);
2069}
2070
2071void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
2072 OS << "typeid(";
2073 if (Node->isTypeOperand()) {
2074 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
2075 } else {
2076 PrintExpr(Node->getExprOperand());
2077 }
2078 OS << ")";
2079}
2080
2081void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
2082 OS << "__uuidof(";
2083 if (Node->isTypeOperand()) {
2084 Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
2085 } else {
2086 PrintExpr(Node->getExprOperand());
2087 }
2088 OS << ")";
2089}
2090
2091void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
2092 PrintExpr(Node->getBaseExpr());
2093 if (Node->isArrow())
2094 OS << "->";
2095 else
2096 OS << ".";
2097 if (NestedNameSpecifier *Qualifier =
2098 Node->getQualifierLoc().getNestedNameSpecifier())
2099 Qualifier->print(OS, Policy);
2100 OS << Node->getPropertyDecl()->getDeclName();
2101}
2102
2103void StmtPrinter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *Node) {
2104 PrintExpr(Node->getBase());
2105 OS << "[";
2106 PrintExpr(Node->getIdx());
2107 OS << "]";
2108}
2109
2110void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
2111 switch (Node->getLiteralOperatorKind()) {
2113 OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
2114 break;
2116 const auto *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
2117 const TemplateArgumentList *Args =
2118 cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
2119 assert(Args);
2120
2121 if (Args->size() != 1 || Args->get(0).getKind() != TemplateArgument::Pack) {
2122 const TemplateParameterList *TPL = nullptr;
2123 if (!DRE->hadMultipleCandidates())
2124 if (const auto *TD = dyn_cast<TemplateDecl>(DRE->getDecl()))
2125 TPL = TD->getTemplateParameters();
2126 OS << "operator\"\"" << Node->getUDSuffix()->getName();
2127 printTemplateArgumentList(OS, Args->asArray(), Policy, TPL);
2128 OS << "()";
2129 return;
2130 }
2131
2132 const TemplateArgument &Pack = Args->get(0);
2133 for (const auto &P : Pack.pack_elements()) {
2134 char C = (char)P.getAsIntegral().getZExtValue();
2135 OS << C;
2136 }
2137 break;
2138 }
2140 // Print integer literal without suffix.
2141 const auto *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
2142 OS << toString(Int->getValue(), 10, /*isSigned*/false);
2143 break;
2144 }
2146 // Print floating literal without suffix.
2147 auto *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
2148 PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
2149 break;
2150 }
2153 PrintExpr(Node->getCookedLiteral());
2154 break;
2155 }
2156 OS << Node->getUDSuffix()->getName();
2157}
2158
2159void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
2160 OS << (Node->getValue() ? "true" : "false");
2161}
2162
2163void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
2164 OS << "nullptr";
2165}
2166
2167void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
2168 OS << "this";
2169}
2170
2171void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
2172 if (!Node->getSubExpr())
2173 OS << "throw";
2174 else {
2175 OS << "throw ";
2176 PrintExpr(Node->getSubExpr());
2177 }
2178}
2179
2180void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
2181 // Nothing to print: we picked up the default argument.
2182}
2183
2184void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
2185 // Nothing to print: we picked up the default initializer.
2186}
2187
2188void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
2189 auto TargetType = Node->getType();
2190 auto *Auto = TargetType->getContainedDeducedType();
2191 bool Bare = Auto && Auto->isDeduced();
2192
2193 // Parenthesize deduced casts.
2194 if (Bare)
2195 OS << '(';
2196 TargetType.print(OS, Policy);
2197 if (Bare)
2198 OS << ')';
2199
2200 // No extra braces surrounding the inner construct.
2201 if (!Node->isListInitialization())
2202 OS << '(';
2203 PrintExpr(Node->getSubExpr());
2204 if (!Node->isListInitialization())
2205 OS << ')';
2206}
2207
2208void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
2209 PrintExpr(Node->getSubExpr());
2210}
2211
2212void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
2213 Node->getType().print(OS, Policy);
2214 if (Node->isStdInitListInitialization())
2215 /* Nothing to do; braces are part of creating the std::initializer_list. */;
2216 else if (Node->isListInitialization())
2217 OS << "{";
2218 else
2219 OS << "(";
2220 for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
2221 ArgEnd = Node->arg_end();
2222 Arg != ArgEnd; ++Arg) {
2223 if ((*Arg)->isDefaultArgument())
2224 break;
2225 if (Arg != Node->arg_begin())
2226 OS << ", ";
2227 PrintExpr(*Arg);
2228 }
2229 if (Node->isStdInitListInitialization())
2230 /* See above. */;
2231 else if (Node->isListInitialization())
2232 OS << "}";
2233 else
2234 OS << ")";
2235}
2236
2237void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
2238 OS << '[';
2239 bool NeedComma = false;
2240 switch (Node->getCaptureDefault()) {
2241 case LCD_None:
2242 break;
2243
2244 case LCD_ByCopy:
2245 OS << '=';
2246 NeedComma = true;
2247 break;
2248
2249 case LCD_ByRef:
2250 OS << '&';
2251 NeedComma = true;
2252 break;
2253 }
2254 for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
2255 CEnd = Node->explicit_capture_end();
2256 C != CEnd;
2257 ++C) {
2258 if (C->capturesVLAType())
2259 continue;
2260
2261 if (NeedComma)
2262 OS << ", ";
2263 NeedComma = true;
2264
2265 switch (C->getCaptureKind()) {
2266 case LCK_This:
2267 OS << "this";
2268 break;
2269
2270 case LCK_StarThis:
2271 OS << "*this";
2272 break;
2273
2274 case LCK_ByRef:
2275 if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C))
2276 OS << '&';
2277 OS << C->getCapturedVar()->getName();
2278 break;
2279
2280 case LCK_ByCopy:
2281 OS << C->getCapturedVar()->getName();
2282 break;
2283
2284 case LCK_VLAType:
2285 llvm_unreachable("VLA type in explicit captures.");
2286 }
2287
2288 if (C->isPackExpansion())
2289 OS << "...";
2290
2291 if (Node->isInitCapture(C)) {
2292 // Init captures are always VarDecl.
2293 auto *D = cast<VarDecl>(C->getCapturedVar());
2294
2295 llvm::StringRef Pre;
2296 llvm::StringRef Post;
2297 if (D->getInitStyle() == VarDecl::CallInit &&
2298 !isa<ParenListExpr>(D->getInit())) {
2299 Pre = "(";
2300 Post = ")";
2301 } else if (D->getInitStyle() == VarDecl::CInit) {
2302 Pre = " = ";
2303 }
2304
2305 OS << Pre;
2306 PrintExpr(D->getInit());
2307 OS << Post;
2308 }
2309 }
2310 OS << ']';
2311
2312 if (!Node->getExplicitTemplateParameters().empty()) {
2313 Node->getTemplateParameterList()->print(
2314 OS, Node->getLambdaClass()->getASTContext(),
2315 /*OmitTemplateKW*/true);
2316 }
2317
2318 if (Node->hasExplicitParameters()) {
2319 OS << '(';
2320 CXXMethodDecl *Method = Node->getCallOperator();
2321 NeedComma = false;
2322 for (const auto *P : Method->parameters()) {
2323 if (NeedComma) {
2324 OS << ", ";
2325 } else {
2326 NeedComma = true;
2327 }
2328 std::string ParamStr =
2329 (Policy.CleanUglifiedParameters && P->getIdentifier())
2330 ? P->getIdentifier()->deuglifiedName().str()
2331 : P->getNameAsString();
2332 P->getOriginalType().print(OS, Policy, ParamStr);
2333 }
2334 if (Method->isVariadic()) {
2335 if (NeedComma)
2336 OS << ", ";
2337 OS << "...";
2338 }
2339 OS << ')';
2340
2341 if (Node->isMutable())
2342 OS << " mutable";
2343
2344 auto *Proto = Method->getType()->castAs<FunctionProtoType>();
2345 Proto->printExceptionSpecification(OS, Policy);
2346
2347 // FIXME: Attributes
2348
2349 // Print the trailing return type if it was specified in the source.
2350 if (Node->hasExplicitResultType()) {
2351 OS << " -> ";
2352 Proto->getReturnType().print(OS, Policy);
2353 }
2354 }
2355
2356 // Print the body.
2357 OS << ' ';
2358 if (Policy.TerseOutput)
2359 OS << "{}";
2360 else
2361 PrintRawCompoundStmt(Node->getCompoundStmtBody());
2362}
2363
2364void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
2365 if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
2366 TSInfo->getType().print(OS, Policy);
2367 else
2368 Node->getType().print(OS, Policy);
2369 OS << "()";
2370}
2371
2372void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
2373 if (E->isGlobalNew())
2374 OS << "::";
2375 OS << "new ";
2376 unsigned NumPlace = E->getNumPlacementArgs();
2377 if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
2378 OS << "(";
2379 PrintExpr(E->getPlacementArg(0));
2380 for (unsigned i = 1; i < NumPlace; ++i) {
2381 if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
2382 break;
2383 OS << ", ";
2384 PrintExpr(E->getPlacementArg(i));
2385 }
2386 OS << ") ";
2387 }
2388 if (E->isParenTypeId())
2389 OS << "(";
2390 std::string TypeS;
2391 if (E->isArray()) {
2392 llvm::raw_string_ostream s(TypeS);
2393 s << '[';
2394 if (std::optional<Expr *> Size = E->getArraySize())
2395 (*Size)->printPretty(s, Helper, Policy);
2396 s << ']';
2397 }
2398 E->getAllocatedType().print(OS, Policy, TypeS);
2399 if (E->isParenTypeId())
2400 OS << ")";
2401
2402 CXXNewInitializationStyle InitStyle = E->getInitializationStyle();
2403 if (InitStyle != CXXNewInitializationStyle::None) {
2404 bool Bare = InitStyle == CXXNewInitializationStyle::Parens &&
2405 !isa<ParenListExpr>(E->getInitializer());
2406 if (Bare)
2407 OS << "(";
2408 PrintExpr(E->getInitializer());
2409 if (Bare)
2410 OS << ")";
2411 }
2412}
2413
2414void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
2415 if (E->isGlobalDelete())
2416 OS << "::";
2417 OS << "delete ";
2418 if (E->isArrayForm())
2419 OS << "[] ";
2420 PrintExpr(E->getArgument());
2421}
2422
2423void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
2424 PrintExpr(E->getBase());
2425 if (E->isArrow())
2426 OS << "->";
2427 else
2428 OS << '.';
2429 if (E->getQualifier())
2430 E->getQualifier()->print(OS, Policy);
2431 OS << "~";
2432
2433 if (const IdentifierInfo *II = E->getDestroyedTypeIdentifier())
2434 OS << II->getName();
2435 else
2436 E->getDestroyedType().print(OS, Policy);
2437}
2438
2439void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
2440 if (E->isListInitialization() && !E->isStdInitListInitialization())
2441 OS << "{";
2442
2443 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
2444 if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
2445 // Don't print any defaulted arguments
2446 break;
2447 }
2448
2449 if (i) OS << ", ";
2450 PrintExpr(E->getArg(i));
2451 }
2452
2453 if (E->isListInitialization() && !E->isStdInitListInitialization())
2454 OS << "}";
2455}
2456
2457void StmtPrinter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
2458 // Parens are printed by the surrounding context.
2459 OS << "<forwarded>";
2460}
2461
2462void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
2463 PrintExpr(E->getSubExpr());
2464}
2465
2466void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
2467 // Just forward to the subexpression.
2468 PrintExpr(E->getSubExpr());
2469}
2470
2471void StmtPrinter::VisitCXXUnresolvedConstructExpr(
2473 Node->getTypeAsWritten().print(OS, Policy);
2474 if (!Node->isListInitialization())
2475 OS << '(';
2476 for (auto Arg = Node->arg_begin(), ArgEnd = Node->arg_end(); Arg != ArgEnd;
2477 ++Arg) {
2478 if (Arg != Node->arg_begin())
2479 OS << ", ";
2480 PrintExpr(*Arg);
2481 }
2482 if (!Node->isListInitialization())
2483 OS << ')';
2484}
2485
2486void StmtPrinter::VisitCXXDependentScopeMemberExpr(
2488 if (!Node->isImplicitAccess()) {
2489 PrintExpr(Node->getBase());
2490 OS << (Node->isArrow() ? "->" : ".");
2491 }
2492 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2493 Qualifier->print(OS, Policy);
2494 if (Node->hasTemplateKeyword())
2495 OS << "template ";
2496 OS << Node->getMemberNameInfo();
2497 if (Node->hasExplicitTemplateArgs())
2498 printTemplateArgumentList(OS, Node->template_arguments(), Policy);
2499}
2500
2501void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
2502 if (!Node->isImplicitAccess()) {
2503 PrintExpr(Node->getBase());
2504 OS << (Node->isArrow() ? "->" : ".");
2505 }
2506 if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2507 Qualifier->print(OS, Policy);
2508 if (Node->hasTemplateKeyword())
2509 OS << "template ";
2510 OS << Node->getMemberNameInfo();
2511 if (Node->hasExplicitTemplateArgs())
2512 printTemplateArgumentList(OS, Node->template_arguments(), Policy);
2513}
2514
2515void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
2516 OS << getTraitSpelling(E->getTrait()) << "(";
2517 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
2518 if (I > 0)
2519 OS << ", ";
2520 E->getArg(I)->getType().print(OS, Policy);
2521 }
2522 OS << ")";
2523}
2524
2525void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2526 OS << getTraitSpelling(E->getTrait()) << '(';
2527 E->getQueriedType().print(OS, Policy);
2528 OS << ')';
2529}
2530
2531void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2532 OS << getTraitSpelling(E->getTrait()) << '(';
2533 PrintExpr(E->getQueriedExpression());
2534 OS << ')';
2535}
2536
2537void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2538 OS << "noexcept(";
2539 PrintExpr(E->getOperand());
2540 OS << ")";
2541}
2542
2543void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2544 PrintExpr(E->getPattern());
2545 OS << "...";
2546}
2547
2548void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2549 OS << "sizeof...(" << *E->getPack() << ")";
2550}
2551
2552void StmtPrinter::VisitPackIndexingExpr(PackIndexingExpr *E) {
2553 PrintExpr(E->getPackIdExpression());
2554 OS << "...[";
2555 PrintExpr(E->getIndexExpr());
2556 OS << "]";
2557}
2558
2559void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
2561 OS << *Node->getParameterPack();
2562}
2563
2564void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
2566 Visit(Node->getReplacement());
2567}
2568
2569void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2570 OS << *E->getParameterPack();
2571}
2572
2573void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
2574 PrintExpr(Node->getSubExpr());
2575}
2576
2577void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2578 OS << "(";
2579 if (E->getLHS()) {
2580 PrintExpr(E->getLHS());
2581 OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2582 }
2583 OS << "...";
2584 if (E->getRHS()) {
2585 OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2586 PrintExpr(E->getRHS());
2587 }
2588 OS << ")";
2589}
2590
2591void StmtPrinter::VisitCXXParenListInitExpr(CXXParenListInitExpr *Node) {
2592 OS << "(";
2593 llvm::interleaveComma(Node->getInitExprs(), OS,
2594 [&](Expr *E) { PrintExpr(E); });
2595 OS << ")";
2596}
2597
2598void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {
2599 NestedNameSpecifierLoc NNS = E->getNestedNameSpecifierLoc();
2600 if (NNS)
2601 NNS.getNestedNameSpecifier()->print(OS, Policy);
2602 if (E->getTemplateKWLoc().isValid())
2603 OS << "template ";
2604 OS << E->getFoundDecl()->getName();
2605 printTemplateArgumentList(OS, E->getTemplateArgsAsWritten()->arguments(),
2606 Policy,
2607 E->getNamedConcept()->getTemplateParameters());
2608}
2609
2610void StmtPrinter::VisitRequiresExpr(RequiresExpr *E) {
2611 OS << "requires ";
2612 auto LocalParameters = E->getLocalParameters();
2613 if (!LocalParameters.empty()) {
2614 OS << "(";
2615 for (ParmVarDecl *LocalParam : LocalParameters) {
2616 PrintRawDecl(LocalParam);
2617 if (LocalParam != LocalParameters.back())
2618 OS << ", ";
2619 }
2620
2621 OS << ") ";
2622 }
2623 OS << "{ ";
2624 auto Requirements = E->getRequirements();
2625 for (concepts::Requirement *Req : Requirements) {
2626 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
2627 if (TypeReq->isSubstitutionFailure())
2628 OS << "<<error-type>>";
2629 else
2630 TypeReq->getType()->getType().print(OS, Policy);
2631 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
2632 if (ExprReq->isCompound())
2633 OS << "{ ";
2634 if (ExprReq->isExprSubstitutionFailure())
2635 OS << "<<error-expression>>";
2636 else
2637 PrintExpr(ExprReq->getExpr());
2638 if (ExprReq->isCompound()) {
2639 OS << " }";
2640 if (ExprReq->getNoexceptLoc().isValid())
2641 OS << " noexcept";
2642 const auto &RetReq = ExprReq->getReturnTypeRequirement();
2643 if (!RetReq.isEmpty()) {
2644 OS << " -> ";
2645 if (RetReq.isSubstitutionFailure())
2646 OS << "<<error-type>>";
2647 else if (RetReq.isTypeConstraint())
2648 RetReq.getTypeConstraint()->print(OS, Policy);
2649 }
2650 }
2651 } else {
2652 auto *NestedReq = cast<concepts::NestedRequirement>(Req);
2653 OS << "requires ";
2654 if (NestedReq->hasInvalidConstraint())
2655 OS << "<<error-expression>>";
2656 else
2657 PrintExpr(NestedReq->getConstraintExpr());
2658 }
2659 OS << "; ";
2660 }
2661 OS << "}";
2662}
2663
2664// C++ Coroutines
2665
2666void StmtPrinter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
2667 Visit(S->getBody());
2668}
2669
2670void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) {
2671 OS << "co_return";
2672 if (S->getOperand()) {
2673 OS << " ";
2674 Visit(S->getOperand());
2675 }
2676 OS << ";";
2677}
2678
2679void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) {
2680 OS << "co_await ";
2681 PrintExpr(S->getOperand());
2682}
2683
2684void StmtPrinter::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) {
2685 OS << "co_await ";
2686 PrintExpr(S->getOperand());
2687}
2688
2689void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) {
2690 OS << "co_yield ";
2691 PrintExpr(S->getOperand());
2692}
2693
2694// Obj-C
2695
2696void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
2697 OS << "@";
2698 VisitStringLiteral(Node->getString());
2699}
2700
2701void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
2702 OS << "@";
2703 Visit(E->getSubExpr());
2704}
2705
2706void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
2707 OS << "@[ ";
2709 for (auto I = Ch.begin(), E = Ch.end(); I != E; ++I) {
2710 if (I != Ch.begin())
2711 OS << ", ";
2712 Visit(*I);
2713 }
2714 OS << " ]";
2715}
2716
2717void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
2718 OS << "@{ ";
2719 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
2720 if (I > 0)
2721 OS << ", ";
2722
2723 ObjCDictionaryElement Element = E->getKeyValueElement(I);
2724 Visit(Element.Key);
2725 OS << " : ";
2726 Visit(Element.Value);
2727 if (Element.isPackExpansion())
2728 OS << "...";
2729 }
2730 OS << " }";
2731}
2732
2733void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
2734 OS << "@encode(";
2735 Node->getEncodedType().print(OS, Policy);
2736 OS << ')';
2737}
2738
2739void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
2740 OS << "@selector(";
2741 Node->getSelector().print(OS);
2742 OS << ')';
2743}
2744
2745void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
2746 OS << "@protocol(" << *Node->getProtocol() << ')';
2747}
2748
2749void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
2750 OS << "[";
2751 switch (Mess->getReceiverKind()) {
2753 PrintExpr(Mess->getInstanceReceiver());
2754 break;
2755
2757 Mess->getClassReceiver().print(OS, Policy);
2758 break;
2759
2762 OS << "Super";
2763 break;
2764 }
2765
2766 OS << ' ';
2767 Selector selector = Mess->getSelector();
2768 if (selector.isUnarySelector()) {
2769 OS << selector.getNameForSlot(0);
2770 } else {
2771 for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
2772 if (i < selector.getNumArgs()) {
2773 if (i > 0) OS << ' ';
2774 if (selector.getIdentifierInfoForSlot(i))
2775 OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
2776 else
2777 OS << ":";
2778 }
2779 else OS << ", "; // Handle variadic methods.
2780
2781 PrintExpr(Mess->getArg(i));
2782 }
2783 }
2784 OS << "]";
2785}
2786
2787void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
2788 OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
2789}
2790
2791void
2792StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
2793 PrintExpr(E->getSubExpr());
2794}
2795
2796void
2797StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
2798 OS << '(' << E->getBridgeKindName();
2799 E->getType().print(OS, Policy);
2800 OS << ')';
2801 PrintExpr(E->getSubExpr());
2802}
2803
2804void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
2805 BlockDecl *BD = Node->getBlockDecl();
2806 OS << "^";
2807
2808 const FunctionType *AFT = Node->getFunctionType();
2809
2810 if (isa<FunctionNoProtoType>(AFT)) {
2811 OS << "()";
2812 } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
2813 OS << '(';
2814 for (BlockDecl::param_iterator AI = BD->param_begin(),
2815 E = BD->param_end(); AI != E; ++AI) {
2816 if (AI != BD->param_begin()) OS << ", ";
2817 std::string ParamStr = (*AI)->getNameAsString();
2818 (*AI)->getType().print(OS, Policy, ParamStr);
2819 }
2820
2821 const auto *FT = cast<FunctionProtoType>(AFT);
2822 if (FT->isVariadic()) {
2823 if (!BD->param_empty()) OS << ", ";
2824 OS << "...";
2825 }
2826 OS << ')';
2827 }
2828 OS << "{ }";
2829}
2830
2831void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
2832 PrintExpr(Node->getSourceExpr());
2833}
2834
2835void StmtPrinter::VisitTypoExpr(TypoExpr *Node) {
2836 // TODO: Print something reasonable for a TypoExpr, if necessary.
2837 llvm_unreachable("Cannot print TypoExpr nodes");
2838}
2839
2840void StmtPrinter::VisitRecoveryExpr(RecoveryExpr *Node) {
2841 OS << "<recovery-expr>(";
2842 const char *Sep = "";
2843 for (Expr *E : Node->subExpressions()) {
2844 OS << Sep;
2845 PrintExpr(E);
2846 Sep = ", ";
2847 }
2848 OS << ')';
2849}
2850
2851void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
2852 OS << "__builtin_astype(";
2853 PrintExpr(Node->getSrcExpr());
2854 OS << ", ";
2855 Node->getType().print(OS, Policy);
2856 OS << ")";
2857}
2858
2859void StmtPrinter::VisitHLSLOutArgExpr(HLSLOutArgExpr *Node) {
2860 PrintExpr(Node->getArgLValue());
2861}
2862
2863//===----------------------------------------------------------------------===//
2864// Stmt method implementations
2865//===----------------------------------------------------------------------===//
2866
2867void Stmt::dumpPretty(const ASTContext &Context) const {
2868 printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
2869}
2870
2871void Stmt::printPretty(raw_ostream &Out, PrinterHelper *Helper,
2872 const PrintingPolicy &Policy, unsigned Indentation,
2873 StringRef NL, const ASTContext *Context) const {
2874 StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
2875 P.Visit(const_cast<Stmt *>(this));
2876}
2877
2878void Stmt::printPrettyControlled(raw_ostream &Out, PrinterHelper *Helper,
2879 const PrintingPolicy &Policy,
2880 unsigned Indentation, StringRef NL,
2881 const ASTContext *Context) const {
2882 StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
2883 P.PrintControlledStmt(const_cast<Stmt *>(this));
2884}
2885
2886void Stmt::printJson(raw_ostream &Out, PrinterHelper *Helper,
2887 const PrintingPolicy &Policy, bool AddQuotes) const {
2888 std::string Buf;
2889 llvm::raw_string_ostream TempOut(Buf);
2890
2891 printPretty(TempOut, Helper, Policy);
2892
2893 Out << JsonFormat(TempOut.str(), AddQuotes);
2894}
2895
2896//===----------------------------------------------------------------------===//
2897// PrinterHelper
2898//===----------------------------------------------------------------------===//
2899
2900// Implement virtual destructor.
Defines the clang::ASTContext interface.
DynTypedNode Node
StringRef P
const Decl * D
Expr * E
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1172
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines enumerations for expression traits intrinsics.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
Defines an enumeration for C++ overloaded operators.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
uint32_t Id
Definition: SemaARM.cpp:1134
SourceRange Range
Definition: SemaObjC.cpp:758
Defines the clang::SourceLocation class and associated facilities.
Defines the Objective-C statement AST node classes.
This file defines OpenMP AST classes for executable directives and clauses.
static bool isImplicitThis(const Expr *E)
static bool isImplicitSelf(const Expr *E)
static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node, bool PrintSuffix)
static bool printExprAsWritten(raw_ostream &OS, Expr *E, const ASTContext *Context)
Prints the given expression using the original source text.
Defines enumerations for the type traits support.
C Language Family Type Representation.
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
SourceManager & getSourceManager()
Definition: ASTContext.h:741
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4421
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5805
Represents a loop initializing the elements of an array.
Definition: Expr.h:5752
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition: Expr.h:6986
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2718
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition: Expr.h:6475
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6678
Attr - This represents one attribute.
Definition: Attr.h:43
void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const
Represents an attribute applied to a statement.
Definition: Stmt.h:2107
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4324
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
StringRef getOpcodeStr() const
Definition: Expr.h:3975
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4474
param_iterator param_end()
Definition: Decl.h:4573
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition: Decl.h:4568
param_iterator param_begin()
Definition: Decl.h:4572
bool param_empty() const
Definition: Decl.h:4571
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6414
BreakStmt - This represents a break.
Definition: Stmt.h:3007
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5298
This class is used for builtin types like 'int'.
Definition: Type.h:3034
Kind getKind() const
Definition: Type.h:3082
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition: Expr.h:3840
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:231
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition: ExprCXX.h:601
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
A C++ const_cast expression (C++ [expr.const.cast]).
Definition: ExprCXX.h:563
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1268
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1375
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2498
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3683
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:478
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4846
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:135
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition: ExprCXX.h:1817
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2241
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4126
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4960
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2617
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition: ExprCXX.h:523
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:433
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1885
Represents the this expression in C++.
Definition: ExprCXX.h:1152
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1206
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:1066
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
This captures a statement into a function.
Definition: Stmt.h:3784
CaseStmt - Represent a case statement.
Definition: Stmt.h:1828
static CharSourceRange getTokenRange(SourceRange R)
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition: Expr.cpp:1018
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4641
Represents a 'co_await' expression.
Definition: ExprCXX.h:5191
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4171
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3477
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1628
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition: ExprConcepts.h:42
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4262
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1077
ContinueStmt - This represents a continue.
Definition: Stmt.h:2977
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4582
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition: StmtCXX.h:473
Represents the body of a coroutine.
Definition: StmtCXX.h:320
Represents a 'co_yield' expression.
Definition: ExprCXX.h:5272
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1519
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
Represents a 'co_await' expression while the type of the promise is dependent.
Definition: ExprCXX.h:5223
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
Represents a single C99 designator.
Definition: Expr.h:5376
Represents a C99 designated initializer expression.
Definition: Expr.h:5333
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2752
void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const
Prints the node to the given output stream.
Represents a reference to #emded data.
Definition: Expr.h:4916
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3474
This represents one expression.
Definition: Expr.h:110
QualType getType() const
Definition: Expr.h:142
An expression trait intrinsic.
Definition: ExprCXX.h:2924
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:6354
Represents difference between two FPOptions values.
Definition: LangOptions.h:978
Represents a member of a struct/union/class.
Definition: Decl.h:3033
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition: Decl.cpp:4570
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2808
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2649
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:3096
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4654
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4321
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3286
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4716
Represents a C11 generic selection.
Definition: Expr.h:5966
AssociationTy< false > Association
Definition: Expr.h:6197
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2889
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition: Expr.h:7152
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2165
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1717
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2928
Describes an C or C++ initializer list.
Definition: Expr.h:5088
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2058
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:76
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:287
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
Definition: Lexer.cpp:1023
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:3509
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name.
Definition: StmtCXX.h:253
A member reference to an MSPropertyDecl.
Definition: ExprCXX.h:933
MS property subscript expression.
Definition: ExprCXX.h:1004
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4734
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition: Expr.h:2796
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3236
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
Represents a place-holder for an object not to be initialized by anything.
Definition: Expr.h:5661
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1591
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
Definition: ExprOpenMP.h:24
This represents '#pragma omp atomic' directive.
Definition: StmtOpenMP.h:2947
This represents '#pragma omp barrier' directive.
Definition: StmtOpenMP.h:2625
This represents '#pragma omp cancel' directive.
Definition: StmtOpenMP.h:3655
This represents '#pragma omp cancellation point' directive.
Definition: StmtOpenMP.h:3597
Representation of an OpenMP canonical loop.
Definition: StmtOpenMP.h:142
This represents '#pragma omp critical' directive.
Definition: StmtOpenMP.h:2076
This represents implicit clause 'depend' for the '#pragma omp task' directive.
This represents '#pragma omp depobj' directive.
Definition: StmtOpenMP.h:2841
This represents '#pragma omp dispatch' directive.
Definition: StmtOpenMP.h:5948
This represents '#pragma omp distribute' directive.
Definition: StmtOpenMP.h:4425
This represents '#pragma omp distribute parallel for' composite directive.
Definition: StmtOpenMP.h:4547
This represents '#pragma omp distribute parallel for simd' composite directive.
Definition: StmtOpenMP.h:4643
This represents '#pragma omp distribute simd' composite directive.
Definition: StmtOpenMP.h:4708
This represents '#pragma omp error' directive.
Definition: StmtOpenMP.h:6432
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:266
This represents '#pragma omp flush' directive.
Definition: StmtOpenMP.h:2789
This represents '#pragma omp for' directive.
Definition: StmtOpenMP.h:1634
This represents '#pragma omp for simd' directive.
Definition: StmtOpenMP.h:1724
This represents '#pragma omp loop' directive.
Definition: StmtOpenMP.h:6103
Represents the '#pragma omp interchange' loop transformation directive.
Definition: StmtOpenMP.h:5769
This represents '#pragma omp interop' directive.
Definition: StmtOpenMP.h:5895
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition: ExprOpenMP.h:151
This represents '#pragma omp masked' directive.
Definition: StmtOpenMP.h:6013
This represents '#pragma omp masked taskloop' directive.
Definition: StmtOpenMP.h:3930
This represents '#pragma omp masked taskloop simd' directive.
Definition: StmtOpenMP.h:4071
This represents '#pragma omp master' directive.
Definition: StmtOpenMP.h:2028
This represents '#pragma omp master taskloop' directive.
Definition: StmtOpenMP.h:3854
This represents '#pragma omp master taskloop simd' directive.
Definition: StmtOpenMP.h:4006
This represents '#pragma omp metadirective' directive.
Definition: StmtOpenMP.h:6064
This represents '#pragma omp ordered' directive.
Definition: StmtOpenMP.h:2893
This represents '#pragma omp parallel' directive.
Definition: StmtOpenMP.h:612
This represents '#pragma omp parallel for' directive.
Definition: StmtOpenMP.h:2147
This represents '#pragma omp parallel for simd' directive.
Definition: StmtOpenMP.h:2244
This represents '#pragma omp parallel loop' directive.
Definition: StmtOpenMP.h:6305
This represents '#pragma omp parallel masked' directive.
Definition: StmtOpenMP.h:2372
This represents '#pragma omp parallel masked taskloop' directive.
Definition: StmtOpenMP.h:4215
This represents '#pragma omp parallel masked taskloop simd' directive.
Definition: StmtOpenMP.h:4360
This represents '#pragma omp parallel master' directive.
Definition: StmtOpenMP.h:2309
This represents '#pragma omp parallel master taskloop' directive.
Definition: StmtOpenMP.h:4137
This represents '#pragma omp parallel master taskloop simd' directive.
Definition: StmtOpenMP.h:4293
This represents '#pragma omp parallel sections' directive.
Definition: StmtOpenMP.h:2436
Represents the '#pragma omp reverse' loop transformation directive.
Definition: StmtOpenMP.h:5704
This represents '#pragma omp scan' directive.
Definition: StmtOpenMP.h:5842
This represents '#pragma omp scope' directive.
Definition: StmtOpenMP.h:1925
This represents '#pragma omp section' directive.
Definition: StmtOpenMP.h:1864
This represents '#pragma omp sections' directive.
Definition: StmtOpenMP.h:1787
This represents '#pragma omp simd' directive.
Definition: StmtOpenMP.h:1571
This represents '#pragma omp single' directive.
Definition: StmtOpenMP.h:1977
This represents '#pragma omp target data' directive.
Definition: StmtOpenMP.h:3206
This represents '#pragma omp target' directive.
Definition: StmtOpenMP.h:3152
This represents '#pragma omp target enter data' directive.
Definition: StmtOpenMP.h:3260
This represents '#pragma omp target exit data' directive.
Definition: StmtOpenMP.h:3315
This represents '#pragma omp target parallel' directive.
Definition: StmtOpenMP.h:3369
This represents '#pragma omp target parallel for' directive.
Definition: StmtOpenMP.h:3449
This represents '#pragma omp target parallel for simd' directive.
Definition: StmtOpenMP.h:4774
This represents '#pragma omp target parallel loop' directive.
Definition: StmtOpenMP.h:6370
This represents '#pragma omp target simd' directive.
Definition: StmtOpenMP.h:4841
This represents '#pragma omp target teams' directive.
Definition: StmtOpenMP.h:5199
This represents '#pragma omp target teams distribute' combined directive.
Definition: StmtOpenMP.h:5255
This represents '#pragma omp target teams distribute parallel for' combined directive.
Definition: StmtOpenMP.h:5322
This represents '#pragma omp target teams distribute parallel for simd' combined directive.
Definition: StmtOpenMP.h:5420
This represents '#pragma omp target teams distribute simd' combined directive.
Definition: StmtOpenMP.h:5490
This represents '#pragma omp target teams loop' directive.
Definition: StmtOpenMP.h:6230
This represents '#pragma omp target update' directive.
Definition: StmtOpenMP.h:4491
This represents '#pragma omp task' directive.
Definition: StmtOpenMP.h:2517
This represents '#pragma omp taskloop' directive.
Definition: StmtOpenMP.h:3715
This represents '#pragma omp taskloop simd' directive.
Definition: StmtOpenMP.h:3788
This represents '#pragma omp taskgroup' directive.
Definition: StmtOpenMP.h:2722
This represents '#pragma omp taskwait' directive.
Definition: StmtOpenMP.h:2671
This represents '#pragma omp taskyield' directive.
Definition: StmtOpenMP.h:2579
This represents '#pragma omp teams' directive.
Definition: StmtOpenMP.h:3544
This represents '#pragma omp teams distribute' directive.
Definition: StmtOpenMP.h:4906
This represents '#pragma omp teams distribute parallel for' composite directive.
Definition: StmtOpenMP.h:5106
This represents '#pragma omp teams distribute parallel for simd' composite directive.
Definition: StmtOpenMP.h:5040
This represents '#pragma omp teams distribute simd' combined directive.
Definition: StmtOpenMP.h:4972
This represents '#pragma omp teams loop' directive.
Definition: StmtOpenMP.h:6165
This represents the '#pragma omp tile' loop transformation directive.
Definition: StmtOpenMP.h:5548
This represents the '#pragma omp unroll' loop transformation directive.
Definition: StmtOpenMP.h:5630
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition: ExprObjC.h:191
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:167
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:394
A runtime availability query.
Definition: ExprObjC.h:1692
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition: ExprObjC.h:87
ObjCBoxedExpr - used for generalized expression boxing.
Definition: ExprObjC.h:127
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition: ExprObjC.h:1632
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:309
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:410
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition: ExprObjC.h:1571
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition: ExprObjC.h:1487
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:549
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:941
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: ExprObjC.h:1391
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition: ExprObjC.h:1256
Selector getSelector() const
Definition: ExprObjC.cpp:291
@ SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:955
@ Instance
The receiver is an object instance.
Definition: ExprObjC.h:949
@ SuperClass
The receiver is a superclass.
Definition: ExprObjC.h:952
@ Class
The receiver is a class.
Definition: ExprObjC.h:946
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
Definition: ExprObjC.h:1275
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1230
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition: ExprObjC.h:1378
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition: ExprObjC.h:505
ObjCSelectorExpr used for @selector in Objective-C.
Definition: ExprObjC.h:455
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:51
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition: ExprObjC.h:840
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2519
Helper class for OffsetOfExpr.
Definition: Expr.h:2413
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2471
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1700
@ Array
An index into an array.
Definition: Expr.h:2418
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2425
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2467
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition: Expr.h:2078
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Definition: StmtOpenACC.h:131
This is the base class for an OpenACC statement-level construct, other construct types are expected t...
Definition: StmtOpenACC.h:25
This class represents a 'loop' construct.
Definition: StmtOpenACC.h:194
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
Represents a parameter to a function.
Definition: Decl.h:1725
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1991
StringRef getIdentKindName() const
Definition: Expr.h:2048
virtual bool handledStmt(Stmt *E, raw_ostream &OS)=0
virtual ~PrinterHelper()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6546
A (possibly-)qualified type.
Definition: Type.h:929
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:7258
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:502
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3046
Represents a __leave statement.
Definition: Stmt.h:3745
static std::string getPropertyNameFromSetterSelector(Selector Sel)
Return the property name for the given setter selector.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isUnarySelector() const
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4514
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4258
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4810
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4466
RetTy Visit(PTR(Stmt) S, ParamTys... P)
Definition: StmtVisitor.h:44
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:185
Stmt - This represents one statement.
Definition: Stmt.h:84
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
child_range children()
Definition: Stmt.cpp:294
void printJson(raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const
Pretty-prints in JSON format.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:333
void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1469
void dumpPretty(const ASTContext &Context) const
dumpPretty/printPretty - These two methods do a "pretty print" of the AST back to its original source...
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1778
void outputString(raw_ostream &OS) const
Definition: Expr.cpp:1209
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4490
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition: ExprCXX.h:4575
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2415
A template argument list.
Definition: DeclTemplate.h:250
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:286
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:271
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:280
Represents a template argument.
Definition: TemplateBase.h:61
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
A container of type source information.
Definition: Type.h:7902
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2768
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8800
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
Definition: Expr.h:6837
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2622
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
Definition: Expr.cpp:1401
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3943
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition: ExprCXX.h:637
@ LOK_String
operator "" X (const CharT *, size_t)
Definition: ExprCXX.h:679
@ LOK_Raw
Raw form: operator "" X (const char *)
Definition: ExprCXX.h:667
@ LOK_Floating
operator "" X (long double)
Definition: ExprCXX.h:676
@ LOK_Integer
operator "" X (unsigned long long)
Definition: ExprCXX.h:673
@ LOK_Template
Raw form: operator "" X<cs...> ()
Definition: ExprCXX.h:670
@ LOK_Character
operator "" X (CharT)
Definition: ExprCXX.h:682
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4750
QualType getType() const
Definition: Decl.h:682
@ CInit
C-style initialization with assignment.
Definition: Decl.h:887
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:890
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2611
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:168
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
@ LCK_VLAType
Capturing variable-length array type.
Definition: Lambda.h:38
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
@ LCK_This
Capturing the *this object by reference.
Definition: Lambda.h:34
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...
std::string JsonFormat(StringRef RawSR, bool AddQuotes)
Definition: JsonSupport.h:28
@ LCD_ByRef
Definition: Lambda.h:25
@ LCD_None
Definition: Lambda.h:23
@ LCD_ByCopy
Definition: Lambda.h:24
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
const FunctionProtoType * T
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
CXXNewInitializationStyle
Definition: ExprCXX.h:2226
const Expr * RHS
The original right-hand side.
Definition: ExprCXX.h:310
BinaryOperatorKind Opcode
The original opcode, prior to rewriting.
Definition: ExprCXX.h:306
const Expr * LHS
The original left-hand side.
Definition: ExprCXX.h:308
Iterator range representation begin:end[:step].
Definition: ExprOpenMP.h:154
An element in an Objective-C dictionary literal.
Definition: ExprObjC.h:262
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned Alignof
Whether we can use 'alignof' rather than '__alignof'.
unsigned CleanUglifiedParameters
Whether to strip underscores when printing reserved parameter names.
unsigned ConstantsAsWritten
Whether we should print the constant expressions as written in the sources.
unsigned IncludeNewlines
When true, include newlines after statements like "break", etc.
unsigned Indentation
The number of spaces to use to indent each line.
Definition: PrettyPrinter.h:95
unsigned TerseOutput
Provide a 'terse' output.
unsigned UnderscoreAlignof
Whether we can use '_Alignof' rather than '__alignof'.
unsigned SuppressImplicitBase
When true, don't print the implicit 'self' or 'this' expressions.
Iterator for iterating over Stmt * arrays that contain only T *.
Definition: Stmt.h:1338