clang  6.0.0svn
StmtPrinter.cpp
Go to the documentation of this file.
1 //===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
11 // pretty print the AST back out to C code.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Attr.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclOpenMP.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/ExprCXX.h"
23 #include "clang/AST/ExprOpenMP.h"
25 #include "clang/AST/StmtVisitor.h"
26 #include "clang/Basic/CharInfo.h"
27 #include "clang/Lex/Lexer.h"
28 #include "llvm/ADT/SmallString.h"
29 #include "llvm/Support/Format.h"
30 using namespace clang;
31 
32 //===----------------------------------------------------------------------===//
33 // StmtPrinter Visitor
34 //===----------------------------------------------------------------------===//
35 
36 namespace {
37  class StmtPrinter : public StmtVisitor<StmtPrinter> {
38  raw_ostream &OS;
39  unsigned IndentLevel;
40  clang::PrinterHelper* Helper;
41  PrintingPolicy Policy;
42  const ASTContext *Context;
43 
44  public:
45  StmtPrinter(raw_ostream &os, PrinterHelper *helper,
46  const PrintingPolicy &Policy, unsigned Indentation = 0,
47  const ASTContext *Context = nullptr)
48  : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy),
49  Context(Context) {}
50 
51  void PrintStmt(Stmt *S) {
52  PrintStmt(S, Policy.Indentation);
53  }
54 
55  void PrintStmt(Stmt *S, int SubIndent) {
56  IndentLevel += SubIndent;
57  if (S && isa<Expr>(S)) {
58  // If this is an expr used in a stmt context, indent and newline it.
59  Indent();
60  Visit(S);
61  OS << ";\n";
62  } else if (S) {
63  Visit(S);
64  } else {
65  Indent() << "<<<NULL STATEMENT>>>\n";
66  }
67  IndentLevel -= SubIndent;
68  }
69 
70  void PrintRawCompoundStmt(CompoundStmt *S);
71  void PrintRawDecl(Decl *D);
72  void PrintRawDeclStmt(const DeclStmt *S);
73  void PrintRawIfStmt(IfStmt *If);
74  void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
75  void PrintCallArgs(CallExpr *E);
76  void PrintRawSEHExceptHandler(SEHExceptStmt *S);
77  void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
78  void PrintOMPExecutableDirective(OMPExecutableDirective *S,
79  bool ForceNoStmt = false);
80 
81  void PrintExpr(Expr *E) {
82  if (E)
83  Visit(E);
84  else
85  OS << "<null expr>";
86  }
87 
88  raw_ostream &Indent(int Delta = 0) {
89  for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
90  OS << " ";
91  return OS;
92  }
93 
94  void Visit(Stmt* S) {
95  if (Helper && Helper->handledStmt(S,OS))
96  return;
98  }
99 
100  void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
101  Indent() << "<<unknown stmt type>>\n";
102  }
103  void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
104  OS << "<<unknown expr type>>";
105  }
106  void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
107 
108 #define ABSTRACT_STMT(CLASS)
109 #define STMT(CLASS, PARENT) \
110  void Visit##CLASS(CLASS *Node);
111 #include "clang/AST/StmtNodes.inc"
112  };
113 }
114 
115 //===----------------------------------------------------------------------===//
116 // Stmt printing methods.
117 //===----------------------------------------------------------------------===//
118 
119 /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
120 /// with no newline after the }.
121 void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
122  OS << "{\n";
123  for (auto *I : Node->body())
124  PrintStmt(I);
125 
126  Indent() << "}";
127 }
128 
129 void StmtPrinter::PrintRawDecl(Decl *D) {
130  D->print(OS, Policy, IndentLevel);
131 }
132 
133 void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
134  SmallVector<Decl*, 2> Decls(S->decls());
135  Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
136 }
137 
138 void StmtPrinter::VisitNullStmt(NullStmt *Node) {
139  Indent() << ";\n";
140 }
141 
142 void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
143  Indent();
144  PrintRawDeclStmt(Node);
145  OS << ";\n";
146 }
147 
148 void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
149  Indent();
150  PrintRawCompoundStmt(Node);
151  OS << "\n";
152 }
153 
154 void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
155  Indent(-1) << "case ";
156  PrintExpr(Node->getLHS());
157  if (Node->getRHS()) {
158  OS << " ... ";
159  PrintExpr(Node->getRHS());
160  }
161  OS << ":\n";
162 
163  PrintStmt(Node->getSubStmt(), 0);
164 }
165 
166 void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
167  Indent(-1) << "default:\n";
168  PrintStmt(Node->getSubStmt(), 0);
169 }
170 
171 void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
172  Indent(-1) << Node->getName() << ":\n";
173  PrintStmt(Node->getSubStmt(), 0);
174 }
175 
176 void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
177  for (const auto *Attr : Node->getAttrs()) {
178  Attr->printPretty(OS, Policy);
179  }
180 
181  PrintStmt(Node->getSubStmt(), 0);
182 }
183 
184 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
185  OS << "if (";
186  if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
187  PrintRawDeclStmt(DS);
188  else
189  PrintExpr(If->getCond());
190  OS << ')';
191 
192  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
193  OS << ' ';
194  PrintRawCompoundStmt(CS);
195  OS << (If->getElse() ? ' ' : '\n');
196  } else {
197  OS << '\n';
198  PrintStmt(If->getThen());
199  if (If->getElse()) Indent();
200  }
201 
202  if (Stmt *Else = If->getElse()) {
203  OS << "else";
204 
205  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Else)) {
206  OS << ' ';
207  PrintRawCompoundStmt(CS);
208  OS << '\n';
209  } else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
210  OS << ' ';
211  PrintRawIfStmt(ElseIf);
212  } else {
213  OS << '\n';
214  PrintStmt(If->getElse());
215  }
216  }
217 }
218 
219 void StmtPrinter::VisitIfStmt(IfStmt *If) {
220  Indent();
221  PrintRawIfStmt(If);
222 }
223 
224 void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
225  Indent() << "switch (";
226  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
227  PrintRawDeclStmt(DS);
228  else
229  PrintExpr(Node->getCond());
230  OS << ")";
231 
232  // Pretty print compoundstmt bodies (very common).
233  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
234  OS << " ";
235  PrintRawCompoundStmt(CS);
236  OS << "\n";
237  } else {
238  OS << "\n";
239  PrintStmt(Node->getBody());
240  }
241 }
242 
243 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
244  Indent() << "while (";
245  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
246  PrintRawDeclStmt(DS);
247  else
248  PrintExpr(Node->getCond());
249  OS << ")\n";
250  PrintStmt(Node->getBody());
251 }
252 
253 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
254  Indent() << "do ";
255  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
256  PrintRawCompoundStmt(CS);
257  OS << " ";
258  } else {
259  OS << "\n";
260  PrintStmt(Node->getBody());
261  Indent();
262  }
263 
264  OS << "while (";
265  PrintExpr(Node->getCond());
266  OS << ");\n";
267 }
268 
269 void StmtPrinter::VisitForStmt(ForStmt *Node) {
270  Indent() << "for (";
271  if (Node->getInit()) {
272  if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getInit()))
273  PrintRawDeclStmt(DS);
274  else
275  PrintExpr(cast<Expr>(Node->getInit()));
276  }
277  OS << ";";
278  if (Node->getCond()) {
279  OS << " ";
280  PrintExpr(Node->getCond());
281  }
282  OS << ";";
283  if (Node->getInc()) {
284  OS << " ";
285  PrintExpr(Node->getInc());
286  }
287  OS << ") ";
288 
289  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
290  PrintRawCompoundStmt(CS);
291  OS << "\n";
292  } else {
293  OS << "\n";
294  PrintStmt(Node->getBody());
295  }
296 }
297 
298 void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
299  Indent() << "for (";
300  if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
301  PrintRawDeclStmt(DS);
302  else
303  PrintExpr(cast<Expr>(Node->getElement()));
304  OS << " in ";
305  PrintExpr(Node->getCollection());
306  OS << ") ";
307 
308  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
309  PrintRawCompoundStmt(CS);
310  OS << "\n";
311  } else {
312  OS << "\n";
313  PrintStmt(Node->getBody());
314  }
315 }
316 
317 void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
318  Indent() << "for (";
319  PrintingPolicy SubPolicy(Policy);
320  SubPolicy.SuppressInitializers = true;
321  Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
322  OS << " : ";
323  PrintExpr(Node->getRangeInit());
324  OS << ") {\n";
325  PrintStmt(Node->getBody());
326  Indent() << "}";
327  if (Policy.IncludeNewlines) OS << "\n";
328 }
329 
330 void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
331  Indent();
332  if (Node->isIfExists())
333  OS << "__if_exists (";
334  else
335  OS << "__if_not_exists (";
336 
337  if (NestedNameSpecifier *Qualifier
339  Qualifier->print(OS, Policy);
340 
341  OS << Node->getNameInfo() << ") ";
342 
343  PrintRawCompoundStmt(Node->getSubStmt());
344 }
345 
346 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
347  Indent() << "goto " << Node->getLabel()->getName() << ";";
348  if (Policy.IncludeNewlines) OS << "\n";
349 }
350 
351 void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
352  Indent() << "goto *";
353  PrintExpr(Node->getTarget());
354  OS << ";";
355  if (Policy.IncludeNewlines) OS << "\n";
356 }
357 
358 void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
359  Indent() << "continue;";
360  if (Policy.IncludeNewlines) OS << "\n";
361 }
362 
363 void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
364  Indent() << "break;";
365  if (Policy.IncludeNewlines) OS << "\n";
366 }
367 
368 
369 void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
370  Indent() << "return";
371  if (Node->getRetValue()) {
372  OS << " ";
373  PrintExpr(Node->getRetValue());
374  }
375  OS << ";";
376  if (Policy.IncludeNewlines) OS << "\n";
377 }
378 
379 
380 void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
381  Indent() << "asm ";
382 
383  if (Node->isVolatile())
384  OS << "volatile ";
385 
386  OS << "(";
387  VisitStringLiteral(Node->getAsmString());
388 
389  // Outputs
390  if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
391  Node->getNumClobbers() != 0)
392  OS << " : ";
393 
394  for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
395  if (i != 0)
396  OS << ", ";
397 
398  if (!Node->getOutputName(i).empty()) {
399  OS << '[';
400  OS << Node->getOutputName(i);
401  OS << "] ";
402  }
403 
404  VisitStringLiteral(Node->getOutputConstraintLiteral(i));
405  OS << " (";
406  Visit(Node->getOutputExpr(i));
407  OS << ")";
408  }
409 
410  // Inputs
411  if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
412  OS << " : ";
413 
414  for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
415  if (i != 0)
416  OS << ", ";
417 
418  if (!Node->getInputName(i).empty()) {
419  OS << '[';
420  OS << Node->getInputName(i);
421  OS << "] ";
422  }
423 
424  VisitStringLiteral(Node->getInputConstraintLiteral(i));
425  OS << " (";
426  Visit(Node->getInputExpr(i));
427  OS << ")";
428  }
429 
430  // Clobbers
431  if (Node->getNumClobbers() != 0)
432  OS << " : ";
433 
434  for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
435  if (i != 0)
436  OS << ", ";
437 
438  VisitStringLiteral(Node->getClobberStringLiteral(i));
439  }
440 
441  OS << ");";
442  if (Policy.IncludeNewlines) OS << "\n";
443 }
444 
445 void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
446  // FIXME: Implement MS style inline asm statement printer.
447  Indent() << "__asm ";
448  if (Node->hasBraces())
449  OS << "{\n";
450  OS << Node->getAsmString() << "\n";
451  if (Node->hasBraces())
452  Indent() << "}\n";
453 }
454 
455 void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
456  PrintStmt(Node->getCapturedDecl()->getBody());
457 }
458 
459 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
460  Indent() << "@try";
461  if (CompoundStmt *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
462  PrintRawCompoundStmt(TS);
463  OS << "\n";
464  }
465 
466  for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
467  ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I);
468  Indent() << "@catch(";
469  if (catchStmt->getCatchParamDecl()) {
470  if (Decl *DS = catchStmt->getCatchParamDecl())
471  PrintRawDecl(DS);
472  }
473  OS << ")";
474  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
475  PrintRawCompoundStmt(CS);
476  OS << "\n";
477  }
478  }
479 
480  if (ObjCAtFinallyStmt *FS = static_cast<ObjCAtFinallyStmt *>(
481  Node->getFinallyStmt())) {
482  Indent() << "@finally";
483  PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
484  OS << "\n";
485  }
486 }
487 
488 void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
489 }
490 
491 void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
492  Indent() << "@catch (...) { /* todo */ } \n";
493 }
494 
495 void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
496  Indent() << "@throw";
497  if (Node->getThrowExpr()) {
498  OS << " ";
499  PrintExpr(Node->getThrowExpr());
500  }
501  OS << ";\n";
502 }
503 
504 void StmtPrinter::VisitObjCAvailabilityCheckExpr(
506  OS << "@available(...)";
507 }
508 
509 void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
510  Indent() << "@synchronized (";
511  PrintExpr(Node->getSynchExpr());
512  OS << ")";
513  PrintRawCompoundStmt(Node->getSynchBody());
514  OS << "\n";
515 }
516 
517 void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
518  Indent() << "@autoreleasepool";
519  PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
520  OS << "\n";
521 }
522 
523 void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
524  OS << "catch (";
525  if (Decl *ExDecl = Node->getExceptionDecl())
526  PrintRawDecl(ExDecl);
527  else
528  OS << "...";
529  OS << ") ";
530  PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
531 }
532 
533 void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
534  Indent();
535  PrintRawCXXCatchStmt(Node);
536  OS << "\n";
537 }
538 
539 void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
540  Indent() << "try ";
541  PrintRawCompoundStmt(Node->getTryBlock());
542  for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
543  OS << " ";
544  PrintRawCXXCatchStmt(Node->getHandler(i));
545  }
546  OS << "\n";
547 }
548 
549 void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
550  Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
551  PrintRawCompoundStmt(Node->getTryBlock());
552  SEHExceptStmt *E = Node->getExceptHandler();
553  SEHFinallyStmt *F = Node->getFinallyHandler();
554  if(E)
555  PrintRawSEHExceptHandler(E);
556  else {
557  assert(F && "Must have a finally block...");
558  PrintRawSEHFinallyStmt(F);
559  }
560  OS << "\n";
561 }
562 
563 void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
564  OS << "__finally ";
565  PrintRawCompoundStmt(Node->getBlock());
566  OS << "\n";
567 }
568 
569 void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
570  OS << "__except (";
571  VisitExpr(Node->getFilterExpr());
572  OS << ")\n";
573  PrintRawCompoundStmt(Node->getBlock());
574  OS << "\n";
575 }
576 
577 void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
578  Indent();
579  PrintRawSEHExceptHandler(Node);
580  OS << "\n";
581 }
582 
583 void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
584  Indent();
585  PrintRawSEHFinallyStmt(Node);
586  OS << "\n";
587 }
588 
589 void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
590  Indent() << "__leave;";
591  if (Policy.IncludeNewlines) OS << "\n";
592 }
593 
594 //===----------------------------------------------------------------------===//
595 // OpenMP clauses printing methods
596 //===----------------------------------------------------------------------===//
597 
598 namespace {
599 class OMPClausePrinter : public OMPClauseVisitor<OMPClausePrinter> {
600  raw_ostream &OS;
601  const PrintingPolicy &Policy;
602  /// \brief Process clauses with list of variables.
603  template <typename T>
604  void VisitOMPClauseList(T *Node, char StartSym);
605 public:
606  OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
607  : OS(OS), Policy(Policy) { }
608 #define OPENMP_CLAUSE(Name, Class) \
609  void Visit##Class(Class *S);
610 #include "clang/Basic/OpenMPKinds.def"
611 };
612 
613 void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
614  OS << "if(";
615  if (Node->getNameModifier() != OMPD_unknown)
616  OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
617  Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
618  OS << ")";
619 }
620 
621 void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
622  OS << "final(";
623  Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
624  OS << ")";
625 }
626 
627 void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
628  OS << "num_threads(";
629  Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
630  OS << ")";
631 }
632 
633 void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
634  OS << "safelen(";
635  Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
636  OS << ")";
637 }
638 
639 void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
640  OS << "simdlen(";
641  Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
642  OS << ")";
643 }
644 
645 void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
646  OS << "collapse(";
647  Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
648  OS << ")";
649 }
650 
651 void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
652  OS << "default("
653  << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
654  << ")";
655 }
656 
657 void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
658  OS << "proc_bind("
659  << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind())
660  << ")";
661 }
662 
663 void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
664  OS << "schedule(";
666  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
667  Node->getFirstScheduleModifier());
669  OS << ", ";
670  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
671  Node->getSecondScheduleModifier());
672  }
673  OS << ": ";
674  }
675  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
676  if (auto *E = Node->getChunkSize()) {
677  OS << ", ";
678  E->printPretty(OS, nullptr, Policy);
679  }
680  OS << ")";
681 }
682 
683 void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
684  OS << "ordered";
685  if (auto *Num = Node->getNumForLoops()) {
686  OS << "(";
687  Num->printPretty(OS, nullptr, Policy, 0);
688  OS << ")";
689  }
690 }
691 
692 void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
693  OS << "nowait";
694 }
695 
696 void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
697  OS << "untied";
698 }
699 
700 void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
701  OS << "nogroup";
702 }
703 
704 void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
705  OS << "mergeable";
706 }
707 
708 void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
709 
710 void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
711 
712 void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
713  OS << "update";
714 }
715 
716 void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
717  OS << "capture";
718 }
719 
720 void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
721  OS << "seq_cst";
722 }
723 
724 void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
725  OS << "threads";
726 }
727 
728 void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
729 
730 void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
731  OS << "device(";
732  Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
733  OS << ")";
734 }
735 
736 void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
737  OS << "num_teams(";
738  Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
739  OS << ")";
740 }
741 
742 void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
743  OS << "thread_limit(";
744  Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
745  OS << ")";
746 }
747 
748 void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
749  OS << "priority(";
750  Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
751  OS << ")";
752 }
753 
754 void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
755  OS << "grainsize(";
756  Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
757  OS << ")";
758 }
759 
760 void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
761  OS << "num_tasks(";
762  Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
763  OS << ")";
764 }
765 
766 void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
767  OS << "hint(";
768  Node->getHint()->printPretty(OS, nullptr, Policy, 0);
769  OS << ")";
770 }
771 
772 template<typename T>
773 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
774  for (typename T::varlist_iterator I = Node->varlist_begin(),
775  E = Node->varlist_end();
776  I != E; ++I) {
777  assert(*I && "Expected non-null Stmt");
778  OS << (I == Node->varlist_begin() ? StartSym : ',');
779  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(*I)) {
780  if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
781  DRE->printPretty(OS, nullptr, Policy, 0);
782  else
783  DRE->getDecl()->printQualifiedName(OS);
784  } else
785  (*I)->printPretty(OS, nullptr, Policy, 0);
786  }
787 }
788 
789 void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
790  if (!Node->varlist_empty()) {
791  OS << "private";
792  VisitOMPClauseList(Node, '(');
793  OS << ")";
794  }
795 }
796 
797 void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
798  if (!Node->varlist_empty()) {
799  OS << "firstprivate";
800  VisitOMPClauseList(Node, '(');
801  OS << ")";
802  }
803 }
804 
805 void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
806  if (!Node->varlist_empty()) {
807  OS << "lastprivate";
808  VisitOMPClauseList(Node, '(');
809  OS << ")";
810  }
811 }
812 
813 void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
814  if (!Node->varlist_empty()) {
815  OS << "shared";
816  VisitOMPClauseList(Node, '(');
817  OS << ")";
818  }
819 }
820 
821 void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
822  if (!Node->varlist_empty()) {
823  OS << "reduction(";
824  NestedNameSpecifier *QualifierLoc =
828  if (QualifierLoc == nullptr && OOK != OO_None) {
829  // Print reduction identifier in C format
830  OS << getOperatorSpelling(OOK);
831  } else {
832  // Use C++ format
833  if (QualifierLoc != nullptr)
834  QualifierLoc->print(OS, Policy);
835  OS << Node->getNameInfo();
836  }
837  OS << ":";
838  VisitOMPClauseList(Node, ' ');
839  OS << ")";
840  }
841 }
842 
843 void OMPClausePrinter::VisitOMPTaskReductionClause(
844  OMPTaskReductionClause *Node) {
845  if (!Node->varlist_empty()) {
846  OS << "task_reduction(";
847  NestedNameSpecifier *QualifierLoc =
851  if (QualifierLoc == nullptr && OOK != OO_None) {
852  // Print reduction identifier in C format
853  OS << getOperatorSpelling(OOK);
854  } else {
855  // Use C++ format
856  if (QualifierLoc != nullptr)
857  QualifierLoc->print(OS, Policy);
858  OS << Node->getNameInfo();
859  }
860  OS << ":";
861  VisitOMPClauseList(Node, ' ');
862  OS << ")";
863  }
864 }
865 
866 void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
867  if (!Node->varlist_empty()) {
868  OS << "in_reduction(";
869  NestedNameSpecifier *QualifierLoc =
873  if (QualifierLoc == nullptr && OOK != OO_None) {
874  // Print reduction identifier in C format
875  OS << getOperatorSpelling(OOK);
876  } else {
877  // Use C++ format
878  if (QualifierLoc != nullptr)
879  QualifierLoc->print(OS, Policy);
880  OS << Node->getNameInfo();
881  }
882  OS << ":";
883  VisitOMPClauseList(Node, ' ');
884  OS << ")";
885  }
886 }
887 
888 void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
889  if (!Node->varlist_empty()) {
890  OS << "linear";
891  if (Node->getModifierLoc().isValid()) {
892  OS << '('
893  << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
894  }
895  VisitOMPClauseList(Node, '(');
896  if (Node->getModifierLoc().isValid())
897  OS << ')';
898  if (Node->getStep() != nullptr) {
899  OS << ": ";
900  Node->getStep()->printPretty(OS, nullptr, Policy, 0);
901  }
902  OS << ")";
903  }
904 }
905 
906 void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
907  if (!Node->varlist_empty()) {
908  OS << "aligned";
909  VisitOMPClauseList(Node, '(');
910  if (Node->getAlignment() != nullptr) {
911  OS << ": ";
912  Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
913  }
914  OS << ")";
915  }
916 }
917 
918 void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
919  if (!Node->varlist_empty()) {
920  OS << "copyin";
921  VisitOMPClauseList(Node, '(');
922  OS << ")";
923  }
924 }
925 
926 void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
927  if (!Node->varlist_empty()) {
928  OS << "copyprivate";
929  VisitOMPClauseList(Node, '(');
930  OS << ")";
931  }
932 }
933 
934 void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
935  if (!Node->varlist_empty()) {
936  VisitOMPClauseList(Node, '(');
937  OS << ")";
938  }
939 }
940 
941 void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
942  OS << "depend(";
943  OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
944  Node->getDependencyKind());
945  if (!Node->varlist_empty()) {
946  OS << " :";
947  VisitOMPClauseList(Node, ' ');
948  }
949  OS << ")";
950 }
951 
952 void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
953  if (!Node->varlist_empty()) {
954  OS << "map(";
955  if (Node->getMapType() != OMPC_MAP_unknown) {
956  if (Node->getMapTypeModifier() != OMPC_MAP_unknown) {
957  OS << getOpenMPSimpleClauseTypeName(OMPC_map,
958  Node->getMapTypeModifier());
959  OS << ',';
960  }
961  OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
962  OS << ':';
963  }
964  VisitOMPClauseList(Node, ' ');
965  OS << ")";
966  }
967 }
968 
969 void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
970  if (!Node->varlist_empty()) {
971  OS << "to";
972  VisitOMPClauseList(Node, '(');
973  OS << ")";
974  }
975 }
976 
977 void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
978  if (!Node->varlist_empty()) {
979  OS << "from";
980  VisitOMPClauseList(Node, '(');
981  OS << ")";
982  }
983 }
984 
985 void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
986  OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
987  OMPC_dist_schedule, Node->getDistScheduleKind());
988  if (auto *E = Node->getChunkSize()) {
989  OS << ", ";
990  E->printPretty(OS, nullptr, Policy);
991  }
992  OS << ")";
993 }
994 
995 void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
996  OS << "defaultmap(";
997  OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
998  Node->getDefaultmapModifier());
999  OS << ": ";
1000  OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1001  Node->getDefaultmapKind());
1002  OS << ")";
1003 }
1004 
1005 void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1006  if (!Node->varlist_empty()) {
1007  OS << "use_device_ptr";
1008  VisitOMPClauseList(Node, '(');
1009  OS << ")";
1010  }
1011 }
1012 
1013 void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1014  if (!Node->varlist_empty()) {
1015  OS << "is_device_ptr";
1016  VisitOMPClauseList(Node, '(');
1017  OS << ")";
1018  }
1019 }
1020 }
1021 
1022 //===----------------------------------------------------------------------===//
1023 // OpenMP directives printing methods
1024 //===----------------------------------------------------------------------===//
1025 
1026 void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S,
1027  bool ForceNoStmt) {
1028  OMPClausePrinter Printer(OS, Policy);
1029  ArrayRef<OMPClause *> Clauses = S->clauses();
1030  for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
1031  I != E; ++I)
1032  if (*I && !(*I)->isImplicit()) {
1033  Printer.Visit(*I);
1034  OS << ' ';
1035  }
1036  OS << "\n";
1037  if (S->hasAssociatedStmt() && S->getAssociatedStmt() && !ForceNoStmt) {
1038  assert(isa<CapturedStmt>(S->getAssociatedStmt()) &&
1039  "Expected captured statement!");
1040  Stmt *CS = cast<CapturedStmt>(S->getAssociatedStmt())->getCapturedStmt();
1041  PrintStmt(CS);
1042  }
1043 }
1044 
1045 void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
1046  Indent() << "#pragma omp parallel ";
1047  PrintOMPExecutableDirective(Node);
1048 }
1049 
1050 void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
1051  Indent() << "#pragma omp simd ";
1052  PrintOMPExecutableDirective(Node);
1053 }
1054 
1055 void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
1056  Indent() << "#pragma omp for ";
1057  PrintOMPExecutableDirective(Node);
1058 }
1059 
1060 void StmtPrinter::VisitOMPForSimdDirective(OMPForSimdDirective *Node) {
1061  Indent() << "#pragma omp for simd ";
1062  PrintOMPExecutableDirective(Node);
1063 }
1064 
1065 void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
1066  Indent() << "#pragma omp sections ";
1067  PrintOMPExecutableDirective(Node);
1068 }
1069 
1070 void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
1071  Indent() << "#pragma omp section";
1072  PrintOMPExecutableDirective(Node);
1073 }
1074 
1075 void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
1076  Indent() << "#pragma omp single ";
1077  PrintOMPExecutableDirective(Node);
1078 }
1079 
1080 void StmtPrinter::VisitOMPMasterDirective(OMPMasterDirective *Node) {
1081  Indent() << "#pragma omp master";
1082  PrintOMPExecutableDirective(Node);
1083 }
1084 
1085 void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) {
1086  Indent() << "#pragma omp critical";
1087  if (Node->getDirectiveName().getName()) {
1088  OS << " (";
1089  Node->getDirectiveName().printName(OS);
1090  OS << ")";
1091  }
1092  OS << " ";
1093  PrintOMPExecutableDirective(Node);
1094 }
1095 
1096 void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) {
1097  Indent() << "#pragma omp parallel for ";
1098  PrintOMPExecutableDirective(Node);
1099 }
1100 
1101 void StmtPrinter::VisitOMPParallelForSimdDirective(
1103  Indent() << "#pragma omp parallel for simd ";
1104  PrintOMPExecutableDirective(Node);
1105 }
1106 
1107 void StmtPrinter::VisitOMPParallelSectionsDirective(
1109  Indent() << "#pragma omp parallel sections ";
1110  PrintOMPExecutableDirective(Node);
1111 }
1112 
1113 void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) {
1114  Indent() << "#pragma omp task ";
1115  PrintOMPExecutableDirective(Node);
1116 }
1117 
1118 void StmtPrinter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *Node) {
1119  Indent() << "#pragma omp taskyield";
1120  PrintOMPExecutableDirective(Node);
1121 }
1122 
1123 void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) {
1124  Indent() << "#pragma omp barrier";
1125  PrintOMPExecutableDirective(Node);
1126 }
1127 
1128 void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) {
1129  Indent() << "#pragma omp taskwait";
1130  PrintOMPExecutableDirective(Node);
1131 }
1132 
1133 void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) {
1134  Indent() << "#pragma omp taskgroup ";
1135  PrintOMPExecutableDirective(Node);
1136 }
1137 
1138 void StmtPrinter::VisitOMPFlushDirective(OMPFlushDirective *Node) {
1139  Indent() << "#pragma omp flush ";
1140  PrintOMPExecutableDirective(Node);
1141 }
1142 
1143 void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
1144  Indent() << "#pragma omp ordered ";
1145  PrintOMPExecutableDirective(Node);
1146 }
1147 
1148 void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) {
1149  Indent() << "#pragma omp atomic ";
1150  PrintOMPExecutableDirective(Node);
1151 }
1152 
1153 void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) {
1154  Indent() << "#pragma omp target ";
1155  PrintOMPExecutableDirective(Node);
1156 }
1157 
1158 void StmtPrinter::VisitOMPTargetDataDirective(OMPTargetDataDirective *Node) {
1159  Indent() << "#pragma omp target data ";
1160  PrintOMPExecutableDirective(Node);
1161 }
1162 
1163 void StmtPrinter::VisitOMPTargetEnterDataDirective(
1165  Indent() << "#pragma omp target enter data ";
1166  PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
1167 }
1168 
1169 void StmtPrinter::VisitOMPTargetExitDataDirective(
1171  Indent() << "#pragma omp target exit data ";
1172  PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
1173 }
1174 
1175 void StmtPrinter::VisitOMPTargetParallelDirective(
1177  Indent() << "#pragma omp target parallel ";
1178  PrintOMPExecutableDirective(Node);
1179 }
1180 
1181 void StmtPrinter::VisitOMPTargetParallelForDirective(
1183  Indent() << "#pragma omp target parallel for ";
1184  PrintOMPExecutableDirective(Node);
1185 }
1186 
1187 void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {
1188  Indent() << "#pragma omp teams ";
1189  PrintOMPExecutableDirective(Node);
1190 }
1191 
1192 void StmtPrinter::VisitOMPCancellationPointDirective(
1194  Indent() << "#pragma omp cancellation point "
1196  PrintOMPExecutableDirective(Node);
1197 }
1198 
1199 void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
1200  Indent() << "#pragma omp cancel "
1201  << getOpenMPDirectiveName(Node->getCancelRegion()) << " ";
1202  PrintOMPExecutableDirective(Node);
1203 }
1204 
1205 void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) {
1206  Indent() << "#pragma omp taskloop ";
1207  PrintOMPExecutableDirective(Node);
1208 }
1209 
1210 void StmtPrinter::VisitOMPTaskLoopSimdDirective(
1211  OMPTaskLoopSimdDirective *Node) {
1212  Indent() << "#pragma omp taskloop simd ";
1213  PrintOMPExecutableDirective(Node);
1214 }
1215 
1216 void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) {
1217  Indent() << "#pragma omp distribute ";
1218  PrintOMPExecutableDirective(Node);
1219 }
1220 
1221 void StmtPrinter::VisitOMPTargetUpdateDirective(
1222  OMPTargetUpdateDirective *Node) {
1223  Indent() << "#pragma omp target update ";
1224  PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
1225 }
1226 
1227 void StmtPrinter::VisitOMPDistributeParallelForDirective(
1229  Indent() << "#pragma omp distribute parallel for ";
1230  PrintOMPExecutableDirective(Node);
1231 }
1232 
1233 void StmtPrinter::VisitOMPDistributeParallelForSimdDirective(
1235  Indent() << "#pragma omp distribute parallel for simd ";
1236  PrintOMPExecutableDirective(Node);
1237 }
1238 
1239 void StmtPrinter::VisitOMPDistributeSimdDirective(
1241  Indent() << "#pragma omp distribute simd ";
1242  PrintOMPExecutableDirective(Node);
1243 }
1244 
1245 void StmtPrinter::VisitOMPTargetParallelForSimdDirective(
1247  Indent() << "#pragma omp target parallel for simd ";
1248  PrintOMPExecutableDirective(Node);
1249 }
1250 
1251 void StmtPrinter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *Node) {
1252  Indent() << "#pragma omp target simd ";
1253  PrintOMPExecutableDirective(Node);
1254 }
1255 
1256 void StmtPrinter::VisitOMPTeamsDistributeDirective(
1258  Indent() << "#pragma omp teams distribute ";
1259  PrintOMPExecutableDirective(Node);
1260 }
1261 
1262 void StmtPrinter::VisitOMPTeamsDistributeSimdDirective(
1264  Indent() << "#pragma omp teams distribute simd ";
1265  PrintOMPExecutableDirective(Node);
1266 }
1267 
1268 void StmtPrinter::VisitOMPTeamsDistributeParallelForSimdDirective(
1270  Indent() << "#pragma omp teams distribute parallel for simd ";
1271  PrintOMPExecutableDirective(Node);
1272 }
1273 
1274 void StmtPrinter::VisitOMPTeamsDistributeParallelForDirective(
1276  Indent() << "#pragma omp teams distribute parallel for ";
1277  PrintOMPExecutableDirective(Node);
1278 }
1279 
1280 void StmtPrinter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *Node) {
1281  Indent() << "#pragma omp target teams ";
1282  PrintOMPExecutableDirective(Node);
1283 }
1284 
1285 void StmtPrinter::VisitOMPTargetTeamsDistributeDirective(
1287  Indent() << "#pragma omp target teams distribute ";
1288  PrintOMPExecutableDirective(Node);
1289 }
1290 
1291 void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForDirective(
1293  Indent() << "#pragma omp target teams distribute parallel for ";
1294  PrintOMPExecutableDirective(Node);
1295 }
1296 
1297 void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1299  Indent() << "#pragma omp target teams distribute parallel for simd ";
1300  PrintOMPExecutableDirective(Node);
1301 }
1302 
1303 void StmtPrinter::VisitOMPTargetTeamsDistributeSimdDirective(
1305  Indent() << "#pragma omp target teams distribute simd ";
1306  PrintOMPExecutableDirective(Node);
1307 }
1308 
1309 //===----------------------------------------------------------------------===//
1310 // Expr printing methods.
1311 //===----------------------------------------------------------------------===//
1312 
1313 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
1314  if (auto *OCED = dyn_cast<OMPCapturedExprDecl>(Node->getDecl())) {
1315  OCED->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy);
1316  return;
1317  }
1318  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1319  Qualifier->print(OS, Policy);
1320  if (Node->hasTemplateKeyword())
1321  OS << "template ";
1322  OS << Node->getNameInfo();
1323  if (Node->hasExplicitTemplateArgs())
1324  printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1325 }
1326 
1327 void StmtPrinter::VisitDependentScopeDeclRefExpr(
1328  DependentScopeDeclRefExpr *Node) {
1329  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1330  Qualifier->print(OS, Policy);
1331  if (Node->hasTemplateKeyword())
1332  OS << "template ";
1333  OS << Node->getNameInfo();
1334  if (Node->hasExplicitTemplateArgs())
1335  printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1336 }
1337 
1338 void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
1339  if (Node->getQualifier())
1340  Node->getQualifier()->print(OS, Policy);
1341  if (Node->hasTemplateKeyword())
1342  OS << "template ";
1343  OS << Node->getNameInfo();
1344  if (Node->hasExplicitTemplateArgs())
1345  printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1346 }
1347 
1348 static bool isImplicitSelf(const Expr *E) {
1349  if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
1350  if (const ImplicitParamDecl *PD =
1351  dyn_cast<ImplicitParamDecl>(DRE->getDecl())) {
1352  if (PD->getParameterKind() == ImplicitParamDecl::ObjCSelf &&
1353  DRE->getLocStart().isInvalid())
1354  return true;
1355  }
1356  }
1357  return false;
1358 }
1359 
1360 void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
1361  if (Node->getBase()) {
1362  if (!Policy.SuppressImplicitBase ||
1363  !isImplicitSelf(Node->getBase()->IgnoreImpCasts())) {
1364  PrintExpr(Node->getBase());
1365  OS << (Node->isArrow() ? "->" : ".");
1366  }
1367  }
1368  OS << *Node->getDecl();
1369 }
1370 
1371 void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
1372  if (Node->isSuperReceiver())
1373  OS << "super.";
1374  else if (Node->isObjectReceiver() && Node->getBase()) {
1375  PrintExpr(Node->getBase());
1376  OS << ".";
1377  } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
1378  OS << Node->getClassReceiver()->getName() << ".";
1379  }
1380 
1381  if (Node->isImplicitProperty())
1383  else
1384  OS << Node->getExplicitProperty()->getName();
1385 }
1386 
1387 void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
1388 
1389  PrintExpr(Node->getBaseExpr());
1390  OS << "[";
1391  PrintExpr(Node->getKeyExpr());
1392  OS << "]";
1393 }
1394 
1395 void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
1397 }
1398 
1399 void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
1400  unsigned value = Node->getValue();
1401 
1402  switch (Node->getKind()) {
1403  case CharacterLiteral::Ascii: break; // no prefix.
1404  case CharacterLiteral::Wide: OS << 'L'; break;
1405  case CharacterLiteral::UTF8: OS << "u8"; break;
1406  case CharacterLiteral::UTF16: OS << 'u'; break;
1407  case CharacterLiteral::UTF32: OS << 'U'; break;
1408  }
1409 
1410  switch (value) {
1411  case '\\':
1412  OS << "'\\\\'";
1413  break;
1414  case '\'':
1415  OS << "'\\''";
1416  break;
1417  case '\a':
1418  // TODO: K&R: the meaning of '\\a' is different in traditional C
1419  OS << "'\\a'";
1420  break;
1421  case '\b':
1422  OS << "'\\b'";
1423  break;
1424  // Nonstandard escape sequence.
1425  /*case '\e':
1426  OS << "'\\e'";
1427  break;*/
1428  case '\f':
1429  OS << "'\\f'";
1430  break;
1431  case '\n':
1432  OS << "'\\n'";
1433  break;
1434  case '\r':
1435  OS << "'\\r'";
1436  break;
1437  case '\t':
1438  OS << "'\\t'";
1439  break;
1440  case '\v':
1441  OS << "'\\v'";
1442  break;
1443  default:
1444  // A character literal might be sign-extended, which
1445  // would result in an invalid \U escape sequence.
1446  // FIXME: multicharacter literals such as '\xFF\xFF\xFF\xFF'
1447  // are not correctly handled.
1448  if ((value & ~0xFFu) == ~0xFFu && Node->getKind() == CharacterLiteral::Ascii)
1449  value &= 0xFFu;
1450  if (value < 256 && isPrintable((unsigned char)value))
1451  OS << "'" << (char)value << "'";
1452  else if (value < 256)
1453  OS << "'\\x" << llvm::format("%02x", value) << "'";
1454  else if (value <= 0xFFFF)
1455  OS << "'\\u" << llvm::format("%04x", value) << "'";
1456  else
1457  OS << "'\\U" << llvm::format("%08x", value) << "'";
1458  }
1459 }
1460 
1461 /// Prints the given expression using the original source text. Returns true on
1462 /// success, false otherwise.
1463 static bool printExprAsWritten(raw_ostream &OS, Expr *E,
1464  const ASTContext *Context) {
1465  if (!Context)
1466  return false;
1467  bool Invalid = false;
1468  StringRef Source = Lexer::getSourceText(
1470  Context->getSourceManager(), Context->getLangOpts(), &Invalid);
1471  if (!Invalid) {
1472  OS << Source;
1473  return true;
1474  }
1475  return false;
1476 }
1477 
1478 void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
1479  if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context))
1480  return;
1481  bool isSigned = Node->getType()->isSignedIntegerType();
1482  OS << Node->getValue().toString(10, isSigned);
1483 
1484  // Emit suffixes. Integer literals are always a builtin integer type.
1485  switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1486  default: llvm_unreachable("Unexpected type for integer literal!");
1487  case BuiltinType::Char_S:
1488  case BuiltinType::Char_U: OS << "i8"; break;
1489  case BuiltinType::UChar: OS << "Ui8"; break;
1490  case BuiltinType::Short: OS << "i16"; break;
1491  case BuiltinType::UShort: OS << "Ui16"; break;
1492  case BuiltinType::Int: break; // no suffix.
1493  case BuiltinType::UInt: OS << 'U'; break;
1494  case BuiltinType::Long: OS << 'L'; break;
1495  case BuiltinType::ULong: OS << "UL"; break;
1496  case BuiltinType::LongLong: OS << "LL"; break;
1497  case BuiltinType::ULongLong: OS << "ULL"; break;
1498  }
1499 }
1500 
1501 static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
1502  bool PrintSuffix) {
1503  SmallString<16> Str;
1504  Node->getValue().toString(Str);
1505  OS << Str;
1506  if (Str.find_first_not_of("-0123456789") == StringRef::npos)
1507  OS << '.'; // Trailing dot in order to separate from ints.
1508 
1509  if (!PrintSuffix)
1510  return;
1511 
1512  // Emit suffixes. Float literals are always a builtin float type.
1513  switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
1514  default: llvm_unreachable("Unexpected type for float literal!");
1515  case BuiltinType::Half: break; // FIXME: suffix?
1516  case BuiltinType::Double: break; // no suffix.
1517  case BuiltinType::Float16: OS << "F16"; break;
1518  case BuiltinType::Float: OS << 'F'; break;
1519  case BuiltinType::LongDouble: OS << 'L'; break;
1520  case BuiltinType::Float128: OS << 'Q'; break;
1521  }
1522 }
1523 
1524 void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
1525  if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context))
1526  return;
1527  PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
1528 }
1529 
1530 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
1531  PrintExpr(Node->getSubExpr());
1532  OS << "i";
1533 }
1534 
1535 void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
1536  Str->outputString(OS);
1537 }
1538 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
1539  OS << "(";
1540  PrintExpr(Node->getSubExpr());
1541  OS << ")";
1542 }
1543 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
1544  if (!Node->isPostfix()) {
1545  OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1546 
1547  // Print a space if this is an "identifier operator" like __real, or if
1548  // it might be concatenated incorrectly like '+'.
1549  switch (Node->getOpcode()) {
1550  default: break;
1551  case UO_Real:
1552  case UO_Imag:
1553  case UO_Extension:
1554  OS << ' ';
1555  break;
1556  case UO_Plus:
1557  case UO_Minus:
1558  if (isa<UnaryOperator>(Node->getSubExpr()))
1559  OS << ' ';
1560  break;
1561  }
1562  }
1563  PrintExpr(Node->getSubExpr());
1564 
1565  if (Node->isPostfix())
1566  OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1567 }
1568 
1569 void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
1570  OS << "__builtin_offsetof(";
1571  Node->getTypeSourceInfo()->getType().print(OS, Policy);
1572  OS << ", ";
1573  bool PrintedSomething = false;
1574  for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) {
1575  OffsetOfNode ON = Node->getComponent(i);
1576  if (ON.getKind() == OffsetOfNode::Array) {
1577  // Array node
1578  OS << "[";
1579  PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
1580  OS << "]";
1581  PrintedSomething = true;
1582  continue;
1583  }
1584 
1585  // Skip implicit base indirections.
1586  if (ON.getKind() == OffsetOfNode::Base)
1587  continue;
1588 
1589  // Field or identifier node.
1590  IdentifierInfo *Id = ON.getFieldName();
1591  if (!Id)
1592  continue;
1593 
1594  if (PrintedSomething)
1595  OS << ".";
1596  else
1597  PrintedSomething = true;
1598  OS << Id->getName();
1599  }
1600  OS << ")";
1601 }
1602 
1603 void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){
1604  switch(Node->getKind()) {
1605  case UETT_SizeOf:
1606  OS << "sizeof";
1607  break;
1608  case UETT_AlignOf:
1609  if (Policy.Alignof)
1610  OS << "alignof";
1611  else if (Policy.UnderscoreAlignof)
1612  OS << "_Alignof";
1613  else
1614  OS << "__alignof";
1615  break;
1616  case UETT_VecStep:
1617  OS << "vec_step";
1618  break;
1620  OS << "__builtin_omp_required_simd_align";
1621  break;
1622  }
1623  if (Node->isArgumentType()) {
1624  OS << '(';
1625  Node->getArgumentType().print(OS, Policy);
1626  OS << ')';
1627  } else {
1628  OS << " ";
1629  PrintExpr(Node->getArgumentExpr());
1630  }
1631 }
1632 
1633 void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1634  OS << "_Generic(";
1635  PrintExpr(Node->getControllingExpr());
1636  for (unsigned i = 0; i != Node->getNumAssocs(); ++i) {
1637  OS << ", ";
1638  QualType T = Node->getAssocType(i);
1639  if (T.isNull())
1640  OS << "default";
1641  else
1642  T.print(OS, Policy);
1643  OS << ": ";
1644  PrintExpr(Node->getAssocExpr(i));
1645  }
1646  OS << ")";
1647 }
1648 
1649 void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
1650  PrintExpr(Node->getLHS());
1651  OS << "[";
1652  PrintExpr(Node->getRHS());
1653  OS << "]";
1654 }
1655 
1656 void StmtPrinter::VisitOMPArraySectionExpr(OMPArraySectionExpr *Node) {
1657  PrintExpr(Node->getBase());
1658  OS << "[";
1659  if (Node->getLowerBound())
1660  PrintExpr(Node->getLowerBound());
1661  if (Node->getColonLoc().isValid()) {
1662  OS << ":";
1663  if (Node->getLength())
1664  PrintExpr(Node->getLength());
1665  }
1666  OS << "]";
1667 }
1668 
1669 void StmtPrinter::PrintCallArgs(CallExpr *Call) {
1670  for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) {
1671  if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1672  // Don't print any defaulted arguments
1673  break;
1674  }
1675 
1676  if (i) OS << ", ";
1677  PrintExpr(Call->getArg(i));
1678  }
1679 }
1680 
1681 void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1682  PrintExpr(Call->getCallee());
1683  OS << "(";
1684  PrintCallArgs(Call);
1685  OS << ")";
1686 }
1687 
1688 static bool isImplicitThis(const Expr *E) {
1689  if (const auto *TE = dyn_cast<CXXThisExpr>(E))
1690  return TE->isImplicit();
1691  return false;
1692 }
1693 
1694 void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1695  if (!Policy.SuppressImplicitBase || !isImplicitThis(Node->getBase())) {
1696  PrintExpr(Node->getBase());
1697 
1698  MemberExpr *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1699  FieldDecl *ParentDecl =
1700  ParentMember ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl())
1701  : nullptr;
1702 
1703  if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion())
1704  OS << (Node->isArrow() ? "->" : ".");
1705  }
1706 
1707  if (FieldDecl *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1708  if (FD->isAnonymousStructOrUnion())
1709  return;
1710 
1711  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1712  Qualifier->print(OS, Policy);
1713  if (Node->hasTemplateKeyword())
1714  OS << "template ";
1715  OS << Node->getMemberNameInfo();
1716  if (Node->hasExplicitTemplateArgs())
1717  printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1718 }
1719 void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1720  PrintExpr(Node->getBase());
1721  OS << (Node->isArrow() ? "->isa" : ".isa");
1722 }
1723 
1724 void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1725  PrintExpr(Node->getBase());
1726  OS << ".";
1727  OS << Node->getAccessor().getName();
1728 }
1729 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1730  OS << '(';
1731  Node->getTypeAsWritten().print(OS, Policy);
1732  OS << ')';
1733  PrintExpr(Node->getSubExpr());
1734 }
1735 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1736  OS << '(';
1737  Node->getType().print(OS, Policy);
1738  OS << ')';
1739  PrintExpr(Node->getInitializer());
1740 }
1741 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1742  // No need to print anything, simply forward to the subexpression.
1743  PrintExpr(Node->getSubExpr());
1744 }
1745 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1746  PrintExpr(Node->getLHS());
1747  OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1748  PrintExpr(Node->getRHS());
1749 }
1750 void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1751  PrintExpr(Node->getLHS());
1752  OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1753  PrintExpr(Node->getRHS());
1754 }
1755 void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1756  PrintExpr(Node->getCond());
1757  OS << " ? ";
1758  PrintExpr(Node->getLHS());
1759  OS << " : ";
1760  PrintExpr(Node->getRHS());
1761 }
1762 
1763 // GNU extensions.
1764 
1765 void
1766 StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1767  PrintExpr(Node->getCommon());
1768  OS << " ?: ";
1769  PrintExpr(Node->getFalseExpr());
1770 }
1771 void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1772  OS << "&&" << Node->getLabel()->getName();
1773 }
1774 
1775 void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1776  OS << "(";
1777  PrintRawCompoundStmt(E->getSubStmt());
1778  OS << ")";
1779 }
1780 
1781 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1782  OS << "__builtin_choose_expr(";
1783  PrintExpr(Node->getCond());
1784  OS << ", ";
1785  PrintExpr(Node->getLHS());
1786  OS << ", ";
1787  PrintExpr(Node->getRHS());
1788  OS << ")";
1789 }
1790 
1791 void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1792  OS << "__null";
1793 }
1794 
1795 void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1796  OS << "__builtin_shufflevector(";
1797  for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) {
1798  if (i) OS << ", ";
1799  PrintExpr(Node->getExpr(i));
1800  }
1801  OS << ")";
1802 }
1803 
1804 void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1805  OS << "__builtin_convertvector(";
1806  PrintExpr(Node->getSrcExpr());
1807  OS << ", ";
1808  Node->getType().print(OS, Policy);
1809  OS << ")";
1810 }
1811 
1812 void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1813  if (Node->getSyntacticForm()) {
1814  Visit(Node->getSyntacticForm());
1815  return;
1816  }
1817 
1818  OS << "{";
1819  for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
1820  if (i) OS << ", ";
1821  if (Node->getInit(i))
1822  PrintExpr(Node->getInit(i));
1823  else
1824  OS << "{}";
1825  }
1826  OS << "}";
1827 }
1828 
1829 void StmtPrinter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *Node) {
1830  // There's no way to express this expression in any of our supported
1831  // languages, so just emit something terse and (hopefully) clear.
1832  OS << "{";
1833  PrintExpr(Node->getSubExpr());
1834  OS << "}";
1835 }
1836 
1837 void StmtPrinter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *Node) {
1838  OS << "*";
1839 }
1840 
1841 void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1842  OS << "(";
1843  for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) {
1844  if (i) OS << ", ";
1845  PrintExpr(Node->getExpr(i));
1846  }
1847  OS << ")";
1848 }
1849 
1850 void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1851  bool NeedsEquals = true;
1852  for (const DesignatedInitExpr::Designator &D : Node->designators()) {
1853  if (D.isFieldDesignator()) {
1854  if (D.getDotLoc().isInvalid()) {
1855  if (IdentifierInfo *II = D.getFieldName()) {
1856  OS << II->getName() << ":";
1857  NeedsEquals = false;
1858  }
1859  } else {
1860  OS << "." << D.getFieldName()->getName();
1861  }
1862  } else {
1863  OS << "[";
1864  if (D.isArrayDesignator()) {
1865  PrintExpr(Node->getArrayIndex(D));
1866  } else {
1867  PrintExpr(Node->getArrayRangeStart(D));
1868  OS << " ... ";
1869  PrintExpr(Node->getArrayRangeEnd(D));
1870  }
1871  OS << "]";
1872  }
1873  }
1874 
1875  if (NeedsEquals)
1876  OS << " = ";
1877  else
1878  OS << " ";
1879  PrintExpr(Node->getInit());
1880 }
1881 
1882 void StmtPrinter::VisitDesignatedInitUpdateExpr(
1883  DesignatedInitUpdateExpr *Node) {
1884  OS << "{";
1885  OS << "/*base*/";
1886  PrintExpr(Node->getBase());
1887  OS << ", ";
1888 
1889  OS << "/*updater*/";
1890  PrintExpr(Node->getUpdater());
1891  OS << "}";
1892 }
1893 
1894 void StmtPrinter::VisitNoInitExpr(NoInitExpr *Node) {
1895  OS << "/*no init*/";
1896 }
1897 
1898 void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1899  if (Node->getType()->getAsCXXRecordDecl()) {
1900  OS << "/*implicit*/";
1901  Node->getType().print(OS, Policy);
1902  OS << "()";
1903  } else {
1904  OS << "/*implicit*/(";
1905  Node->getType().print(OS, Policy);
1906  OS << ')';
1907  if (Node->getType()->isRecordType())
1908  OS << "{}";
1909  else
1910  OS << 0;
1911  }
1912 }
1913 
1914 void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1915  OS << "__builtin_va_arg(";
1916  PrintExpr(Node->getSubExpr());
1917  OS << ", ";
1918  Node->getType().print(OS, Policy);
1919  OS << ")";
1920 }
1921 
1922 void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1923  PrintExpr(Node->getSyntacticForm());
1924 }
1925 
1926 void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1927  const char *Name = nullptr;
1928  switch (Node->getOp()) {
1929 #define BUILTIN(ID, TYPE, ATTRS)
1930 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1931  case AtomicExpr::AO ## ID: \
1932  Name = #ID "("; \
1933  break;
1934 #include "clang/Basic/Builtins.def"
1935  }
1936  OS << Name;
1937 
1938  // AtomicExpr stores its subexpressions in a permuted order.
1939  PrintExpr(Node->getPtr());
1940  if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1941  Node->getOp() != AtomicExpr::AO__atomic_load_n &&
1942  Node->getOp() != AtomicExpr::AO__opencl_atomic_load) {
1943  OS << ", ";
1944  PrintExpr(Node->getVal1());
1945  }
1946  if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1947  Node->isCmpXChg()) {
1948  OS << ", ";
1949  PrintExpr(Node->getVal2());
1950  }
1951  if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1952  Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1953  OS << ", ";
1954  PrintExpr(Node->getWeak());
1955  }
1956  if (Node->getOp() != AtomicExpr::AO__c11_atomic_init &&
1957  Node->getOp() != AtomicExpr::AO__opencl_atomic_init) {
1958  OS << ", ";
1959  PrintExpr(Node->getOrder());
1960  }
1961  if (Node->isCmpXChg()) {
1962  OS << ", ";
1963  PrintExpr(Node->getOrderFail());
1964  }
1965  OS << ")";
1966 }
1967 
1968 // C++
1969 void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1970  const char *OpStrings[NUM_OVERLOADED_OPERATORS] = {
1971  "",
1972 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
1973  Spelling,
1974 #include "clang/Basic/OperatorKinds.def"
1975  };
1976 
1978  if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
1979  if (Node->getNumArgs() == 1) {
1980  OS << OpStrings[Kind] << ' ';
1981  PrintExpr(Node->getArg(0));
1982  } else {
1983  PrintExpr(Node->getArg(0));
1984  OS << ' ' << OpStrings[Kind];
1985  }
1986  } else if (Kind == OO_Arrow) {
1987  PrintExpr(Node->getArg(0));
1988  } else if (Kind == OO_Call) {
1989  PrintExpr(Node->getArg(0));
1990  OS << '(';
1991  for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
1992  if (ArgIdx > 1)
1993  OS << ", ";
1994  if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1995  PrintExpr(Node->getArg(ArgIdx));
1996  }
1997  OS << ')';
1998  } else if (Kind == OO_Subscript) {
1999  PrintExpr(Node->getArg(0));
2000  OS << '[';
2001  PrintExpr(Node->getArg(1));
2002  OS << ']';
2003  } else if (Node->getNumArgs() == 1) {
2004  OS << OpStrings[Kind] << ' ';
2005  PrintExpr(Node->getArg(0));
2006  } else if (Node->getNumArgs() == 2) {
2007  PrintExpr(Node->getArg(0));
2008  OS << ' ' << OpStrings[Kind] << ' ';
2009  PrintExpr(Node->getArg(1));
2010  } else {
2011  llvm_unreachable("unknown overloaded operator");
2012  }
2013 }
2014 
2015 void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
2016  // If we have a conversion operator call only print the argument.
2017  CXXMethodDecl *MD = Node->getMethodDecl();
2018  if (MD && isa<CXXConversionDecl>(MD)) {
2019  PrintExpr(Node->getImplicitObjectArgument());
2020  return;
2021  }
2022  VisitCallExpr(cast<CallExpr>(Node));
2023 }
2024 
2025 void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
2026  PrintExpr(Node->getCallee());
2027  OS << "<<<";
2028  PrintCallArgs(Node->getConfig());
2029  OS << ">>>(";
2030  PrintCallArgs(Node);
2031  OS << ")";
2032 }
2033 
2034 void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
2035  OS << Node->getCastName() << '<';
2036  Node->getTypeAsWritten().print(OS, Policy);
2037  OS << ">(";
2038  PrintExpr(Node->getSubExpr());
2039  OS << ")";
2040 }
2041 
2042 void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
2043  VisitCXXNamedCastExpr(Node);
2044 }
2045 
2046 void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
2047  VisitCXXNamedCastExpr(Node);
2048 }
2049 
2050 void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
2051  VisitCXXNamedCastExpr(Node);
2052 }
2053 
2054 void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
2055  VisitCXXNamedCastExpr(Node);
2056 }
2057 
2058 void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
2059  OS << "typeid(";
2060  if (Node->isTypeOperand()) {
2061  Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
2062  } else {
2063  PrintExpr(Node->getExprOperand());
2064  }
2065  OS << ")";
2066 }
2067 
2068 void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
2069  OS << "__uuidof(";
2070  if (Node->isTypeOperand()) {
2071  Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
2072  } else {
2073  PrintExpr(Node->getExprOperand());
2074  }
2075  OS << ")";
2076 }
2077 
2078 void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
2079  PrintExpr(Node->getBaseExpr());
2080  if (Node->isArrow())
2081  OS << "->";
2082  else
2083  OS << ".";
2084  if (NestedNameSpecifier *Qualifier =
2086  Qualifier->print(OS, Policy);
2087  OS << Node->getPropertyDecl()->getDeclName();
2088 }
2089 
2090 void StmtPrinter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *Node) {
2091  PrintExpr(Node->getBase());
2092  OS << "[";
2093  PrintExpr(Node->getIdx());
2094  OS << "]";
2095 }
2096 
2097 void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
2098  switch (Node->getLiteralOperatorKind()) {
2100  OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
2101  break;
2103  DeclRefExpr *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
2104  const TemplateArgumentList *Args =
2105  cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
2106  assert(Args);
2107 
2108  if (Args->size() != 1) {
2109  OS << "operator\"\"" << Node->getUDSuffix()->getName();
2110  printTemplateArgumentList(OS, Args->asArray(), Policy);
2111  OS << "()";
2112  return;
2113  }
2114 
2115  const TemplateArgument &Pack = Args->get(0);
2116  for (const auto &P : Pack.pack_elements()) {
2117  char C = (char)P.getAsIntegral().getZExtValue();
2118  OS << C;
2119  }
2120  break;
2121  }
2123  // Print integer literal without suffix.
2124  IntegerLiteral *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
2125  OS << Int->getValue().toString(10, /*isSigned*/false);
2126  break;
2127  }
2129  // Print floating literal without suffix.
2130  FloatingLiteral *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
2131  PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
2132  break;
2133  }
2136  PrintExpr(Node->getCookedLiteral());
2137  break;
2138  }
2139  OS << Node->getUDSuffix()->getName();
2140 }
2141 
2142 void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
2143  OS << (Node->getValue() ? "true" : "false");
2144 }
2145 
2146 void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
2147  OS << "nullptr";
2148 }
2149 
2150 void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
2151  OS << "this";
2152 }
2153 
2154 void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
2155  if (!Node->getSubExpr())
2156  OS << "throw";
2157  else {
2158  OS << "throw ";
2159  PrintExpr(Node->getSubExpr());
2160  }
2161 }
2162 
2163 void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
2164  // Nothing to print: we picked up the default argument.
2165 }
2166 
2167 void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
2168  // Nothing to print: we picked up the default initializer.
2169 }
2170 
2171 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
2172  Node->getType().print(OS, Policy);
2173  // If there are no parens, this is list-initialization, and the braces are
2174  // part of the syntax of the inner construct.
2175  if (Node->getLParenLoc().isValid())
2176  OS << "(";
2177  PrintExpr(Node->getSubExpr());
2178  if (Node->getLParenLoc().isValid())
2179  OS << ")";
2180 }
2181 
2182 void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
2183  PrintExpr(Node->getSubExpr());
2184 }
2185 
2186 void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
2187  Node->getType().print(OS, Policy);
2188  if (Node->isStdInitListInitialization())
2189  /* Nothing to do; braces are part of creating the std::initializer_list. */;
2190  else if (Node->isListInitialization())
2191  OS << "{";
2192  else
2193  OS << "(";
2195  ArgEnd = Node->arg_end();
2196  Arg != ArgEnd; ++Arg) {
2197  if ((*Arg)->isDefaultArgument())
2198  break;
2199  if (Arg != Node->arg_begin())
2200  OS << ", ";
2201  PrintExpr(*Arg);
2202  }
2203  if (Node->isStdInitListInitialization())
2204  /* See above. */;
2205  else if (Node->isListInitialization())
2206  OS << "}";
2207  else
2208  OS << ")";
2209 }
2210 
2211 void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
2212  OS << '[';
2213  bool NeedComma = false;
2214  switch (Node->getCaptureDefault()) {
2215  case LCD_None:
2216  break;
2217 
2218  case LCD_ByCopy:
2219  OS << '=';
2220  NeedComma = true;
2221  break;
2222 
2223  case LCD_ByRef:
2224  OS << '&';
2225  NeedComma = true;
2226  break;
2227  }
2229  CEnd = Node->explicit_capture_end();
2230  C != CEnd;
2231  ++C) {
2232  if (C->capturesVLAType())
2233  continue;
2234 
2235  if (NeedComma)
2236  OS << ", ";
2237  NeedComma = true;
2238 
2239  switch (C->getCaptureKind()) {
2240  case LCK_This:
2241  OS << "this";
2242  break;
2243  case LCK_StarThis:
2244  OS << "*this";
2245  break;
2246  case LCK_ByRef:
2247  if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C))
2248  OS << '&';
2249  OS << C->getCapturedVar()->getName();
2250  break;
2251 
2252  case LCK_ByCopy:
2253  OS << C->getCapturedVar()->getName();
2254  break;
2255  case LCK_VLAType:
2256  llvm_unreachable("VLA type in explicit captures.");
2257  }
2258 
2259  if (Node->isInitCapture(C))
2260  PrintExpr(C->getCapturedVar()->getInit());
2261  }
2262  OS << ']';
2263 
2264  if (Node->hasExplicitParameters()) {
2265  OS << " (";
2266  CXXMethodDecl *Method = Node->getCallOperator();
2267  NeedComma = false;
2268  for (auto P : Method->parameters()) {
2269  if (NeedComma) {
2270  OS << ", ";
2271  } else {
2272  NeedComma = true;
2273  }
2274  std::string ParamStr = P->getNameAsString();
2275  P->getOriginalType().print(OS, Policy, ParamStr);
2276  }
2277  if (Method->isVariadic()) {
2278  if (NeedComma)
2279  OS << ", ";
2280  OS << "...";
2281  }
2282  OS << ')';
2283 
2284  if (Node->isMutable())
2285  OS << " mutable";
2286 
2287  const FunctionProtoType *Proto
2288  = Method->getType()->getAs<FunctionProtoType>();
2289  Proto->printExceptionSpecification(OS, Policy);
2290 
2291  // FIXME: Attributes
2292 
2293  // Print the trailing return type if it was specified in the source.
2294  if (Node->hasExplicitResultType()) {
2295  OS << " -> ";
2296  Proto->getReturnType().print(OS, Policy);
2297  }
2298  }
2299 
2300  // Print the body.
2301  CompoundStmt *Body = Node->getBody();
2302  OS << ' ';
2303  PrintStmt(Body);
2304 }
2305 
2306 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
2307  if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
2308  TSInfo->getType().print(OS, Policy);
2309  else
2310  Node->getType().print(OS, Policy);
2311  OS << "()";
2312 }
2313 
2314 void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
2315  if (E->isGlobalNew())
2316  OS << "::";
2317  OS << "new ";
2318  unsigned NumPlace = E->getNumPlacementArgs();
2319  if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) {
2320  OS << "(";
2321  PrintExpr(E->getPlacementArg(0));
2322  for (unsigned i = 1; i < NumPlace; ++i) {
2323  if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
2324  break;
2325  OS << ", ";
2326  PrintExpr(E->getPlacementArg(i));
2327  }
2328  OS << ") ";
2329  }
2330  if (E->isParenTypeId())
2331  OS << "(";
2332  std::string TypeS;
2333  if (Expr *Size = E->getArraySize()) {
2334  llvm::raw_string_ostream s(TypeS);
2335  s << '[';
2336  Size->printPretty(s, Helper, Policy);
2337  s << ']';
2338  }
2339  E->getAllocatedType().print(OS, Policy, TypeS);
2340  if (E->isParenTypeId())
2341  OS << ")";
2342 
2344  if (InitStyle) {
2345  if (InitStyle == CXXNewExpr::CallInit)
2346  OS << "(";
2347  PrintExpr(E->getInitializer());
2348  if (InitStyle == CXXNewExpr::CallInit)
2349  OS << ")";
2350  }
2351 }
2352 
2353 void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
2354  if (E->isGlobalDelete())
2355  OS << "::";
2356  OS << "delete ";
2357  if (E->isArrayForm())
2358  OS << "[] ";
2359  PrintExpr(E->getArgument());
2360 }
2361 
2362 void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
2363  PrintExpr(E->getBase());
2364  if (E->isArrow())
2365  OS << "->";
2366  else
2367  OS << '.';
2368  if (E->getQualifier())
2369  E->getQualifier()->print(OS, Policy);
2370  OS << "~";
2371 
2373  OS << II->getName();
2374  else
2375  E->getDestroyedType().print(OS, Policy);
2376 }
2377 
2378 void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
2380  OS << "{";
2381 
2382  for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
2383  if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
2384  // Don't print any defaulted arguments
2385  break;
2386  }
2387 
2388  if (i) OS << ", ";
2389  PrintExpr(E->getArg(i));
2390  }
2391 
2393  OS << "}";
2394 }
2395 
2396 void StmtPrinter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
2397  // Parens are printed by the surrounding context.
2398  OS << "<forwarded>";
2399 }
2400 
2401 void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
2402  PrintExpr(E->getSubExpr());
2403 }
2404 
2405 void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
2406  // Just forward to the subexpression.
2407  PrintExpr(E->getSubExpr());
2408 }
2409 
2410 void
2411 StmtPrinter::VisitCXXUnresolvedConstructExpr(
2413  Node->getTypeAsWritten().print(OS, Policy);
2414  OS << "(";
2416  ArgEnd = Node->arg_end();
2417  Arg != ArgEnd; ++Arg) {
2418  if (Arg != Node->arg_begin())
2419  OS << ", ";
2420  PrintExpr(*Arg);
2421  }
2422  OS << ")";
2423 }
2424 
2425 void StmtPrinter::VisitCXXDependentScopeMemberExpr(
2427  if (!Node->isImplicitAccess()) {
2428  PrintExpr(Node->getBase());
2429  OS << (Node->isArrow() ? "->" : ".");
2430  }
2431  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2432  Qualifier->print(OS, Policy);
2433  if (Node->hasTemplateKeyword())
2434  OS << "template ";
2435  OS << Node->getMemberNameInfo();
2436  if (Node->hasExplicitTemplateArgs())
2437  printTemplateArgumentList(OS, Node->template_arguments(), Policy);
2438 }
2439 
2440 void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
2441  if (!Node->isImplicitAccess()) {
2442  PrintExpr(Node->getBase());
2443  OS << (Node->isArrow() ? "->" : ".");
2444  }
2445  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2446  Qualifier->print(OS, Policy);
2447  if (Node->hasTemplateKeyword())
2448  OS << "template ";
2449  OS << Node->getMemberNameInfo();
2450  if (Node->hasExplicitTemplateArgs())
2451  printTemplateArgumentList(OS, Node->template_arguments(), Policy);
2452 }
2453 
2454 static const char *getTypeTraitName(TypeTrait TT) {
2455  switch (TT) {
2456 #define TYPE_TRAIT_1(Spelling, Name, Key) \
2457 case clang::UTT_##Name: return #Spelling;
2458 #define TYPE_TRAIT_2(Spelling, Name, Key) \
2459 case clang::BTT_##Name: return #Spelling;
2460 #define TYPE_TRAIT_N(Spelling, Name, Key) \
2461  case clang::TT_##Name: return #Spelling;
2462 #include "clang/Basic/TokenKinds.def"
2463  }
2464  llvm_unreachable("Type trait not covered by switch");
2465 }
2466 
2467 static const char *getTypeTraitName(ArrayTypeTrait ATT) {
2468  switch (ATT) {
2469  case ATT_ArrayRank: return "__array_rank";
2470  case ATT_ArrayExtent: return "__array_extent";
2471  }
2472  llvm_unreachable("Array type trait not covered by switch");
2473 }
2474 
2475 static const char *getExpressionTraitName(ExpressionTrait ET) {
2476  switch (ET) {
2477  case ET_IsLValueExpr: return "__is_lvalue_expr";
2478  case ET_IsRValueExpr: return "__is_rvalue_expr";
2479  }
2480  llvm_unreachable("Expression type trait not covered by switch");
2481 }
2482 
2483 void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
2484  OS << getTypeTraitName(E->getTrait()) << "(";
2485  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
2486  if (I > 0)
2487  OS << ", ";
2488  E->getArg(I)->getType().print(OS, Policy);
2489  }
2490  OS << ")";
2491 }
2492 
2493 void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2494  OS << getTypeTraitName(E->getTrait()) << '(';
2495  E->getQueriedType().print(OS, Policy);
2496  OS << ')';
2497 }
2498 
2499 void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2500  OS << getExpressionTraitName(E->getTrait()) << '(';
2501  PrintExpr(E->getQueriedExpression());
2502  OS << ')';
2503 }
2504 
2505 void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2506  OS << "noexcept(";
2507  PrintExpr(E->getOperand());
2508  OS << ")";
2509 }
2510 
2511 void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2512  PrintExpr(E->getPattern());
2513  OS << "...";
2514 }
2515 
2516 void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2517  OS << "sizeof...(" << *E->getPack() << ")";
2518 }
2519 
2520 void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
2522  OS << *Node->getParameterPack();
2523 }
2524 
2525 void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
2527  Visit(Node->getReplacement());
2528 }
2529 
2530 void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2531  OS << *E->getParameterPack();
2532 }
2533 
2534 void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
2535  PrintExpr(Node->GetTemporaryExpr());
2536 }
2537 
2538 void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2539  OS << "(";
2540  if (E->getLHS()) {
2541  PrintExpr(E->getLHS());
2542  OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2543  }
2544  OS << "...";
2545  if (E->getRHS()) {
2546  OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2547  PrintExpr(E->getRHS());
2548  }
2549  OS << ")";
2550 }
2551 
2552 // C++ Coroutines TS
2553 
2554 void StmtPrinter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
2555  Visit(S->getBody());
2556 }
2557 
2558 void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) {
2559  OS << "co_return";
2560  if (S->getOperand()) {
2561  OS << " ";
2562  Visit(S->getOperand());
2563  }
2564  OS << ";";
2565 }
2566 
2567 void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) {
2568  OS << "co_await ";
2569  PrintExpr(S->getOperand());
2570 }
2571 
2572 
2573 void StmtPrinter::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) {
2574  OS << "co_await ";
2575  PrintExpr(S->getOperand());
2576 }
2577 
2578 
2579 void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) {
2580  OS << "co_yield ";
2581  PrintExpr(S->getOperand());
2582 }
2583 
2584 // Obj-C
2585 
2586 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
2587  OS << "@";
2588  VisitStringLiteral(Node->getString());
2589 }
2590 
2591 void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
2592  OS << "@";
2593  Visit(E->getSubExpr());
2594 }
2595 
2596 void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
2597  OS << "@[ ";
2599  for (auto I = Ch.begin(), E = Ch.end(); I != E; ++I) {
2600  if (I != Ch.begin())
2601  OS << ", ";
2602  Visit(*I);
2603  }
2604  OS << " ]";
2605 }
2606 
2607 void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
2608  OS << "@{ ";
2609  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
2610  if (I > 0)
2611  OS << ", ";
2612 
2613  ObjCDictionaryElement Element = E->getKeyValueElement(I);
2614  Visit(Element.Key);
2615  OS << " : ";
2616  Visit(Element.Value);
2617  if (Element.isPackExpansion())
2618  OS << "...";
2619  }
2620  OS << " }";
2621 }
2622 
2623 void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
2624  OS << "@encode(";
2625  Node->getEncodedType().print(OS, Policy);
2626  OS << ')';
2627 }
2628 
2629 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
2630  OS << "@selector(";
2631  Node->getSelector().print(OS);
2632  OS << ')';
2633 }
2634 
2635 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
2636  OS << "@protocol(" << *Node->getProtocol() << ')';
2637 }
2638 
2639 void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
2640  OS << "[";
2641  switch (Mess->getReceiverKind()) {
2643  PrintExpr(Mess->getInstanceReceiver());
2644  break;
2645 
2647  Mess->getClassReceiver().print(OS, Policy);
2648  break;
2649 
2652  OS << "Super";
2653  break;
2654  }
2655 
2656  OS << ' ';
2657  Selector selector = Mess->getSelector();
2658  if (selector.isUnarySelector()) {
2659  OS << selector.getNameForSlot(0);
2660  } else {
2661  for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
2662  if (i < selector.getNumArgs()) {
2663  if (i > 0) OS << ' ';
2664  if (selector.getIdentifierInfoForSlot(i))
2665  OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
2666  else
2667  OS << ":";
2668  }
2669  else OS << ", "; // Handle variadic methods.
2670 
2671  PrintExpr(Mess->getArg(i));
2672  }
2673  }
2674  OS << "]";
2675 }
2676 
2677 void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
2678  OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
2679 }
2680 
2681 void
2682 StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
2683  PrintExpr(E->getSubExpr());
2684 }
2685 
2686 void
2687 StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
2688  OS << '(' << E->getBridgeKindName();
2689  E->getType().print(OS, Policy);
2690  OS << ')';
2691  PrintExpr(E->getSubExpr());
2692 }
2693 
2694 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
2695  BlockDecl *BD = Node->getBlockDecl();
2696  OS << "^";
2697 
2698  const FunctionType *AFT = Node->getFunctionType();
2699 
2700  if (isa<FunctionNoProtoType>(AFT)) {
2701  OS << "()";
2702  } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) {
2703  OS << '(';
2704  for (BlockDecl::param_iterator AI = BD->param_begin(),
2705  E = BD->param_end(); AI != E; ++AI) {
2706  if (AI != BD->param_begin()) OS << ", ";
2707  std::string ParamStr = (*AI)->getNameAsString();
2708  (*AI)->getType().print(OS, Policy, ParamStr);
2709  }
2710 
2711  const FunctionProtoType *FT = cast<FunctionProtoType>(AFT);
2712  if (FT->isVariadic()) {
2713  if (!BD->param_empty()) OS << ", ";
2714  OS << "...";
2715  }
2716  OS << ')';
2717  }
2718  OS << "{ }";
2719 }
2720 
2721 void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
2722  PrintExpr(Node->getSourceExpr());
2723 }
2724 
2725 void StmtPrinter::VisitTypoExpr(TypoExpr *Node) {
2726  // TODO: Print something reasonable for a TypoExpr, if necessary.
2727  llvm_unreachable("Cannot print TypoExpr nodes");
2728 }
2729 
2730 void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
2731  OS << "__builtin_astype(";
2732  PrintExpr(Node->getSrcExpr());
2733  OS << ", ";
2734  Node->getType().print(OS, Policy);
2735  OS << ")";
2736 }
2737 
2738 //===----------------------------------------------------------------------===//
2739 // Stmt method implementations
2740 //===----------------------------------------------------------------------===//
2741 
2742 void Stmt::dumpPretty(const ASTContext &Context) const {
2743  printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
2744 }
2745 
2746 void Stmt::printPretty(raw_ostream &OS, PrinterHelper *Helper,
2747  const PrintingPolicy &Policy, unsigned Indentation,
2748  const ASTContext *Context) const {
2749  StmtPrinter P(OS, Helper, Policy, Indentation, Context);
2750  P.Visit(const_cast<Stmt*>(this));
2751 }
2752 
2753 //===----------------------------------------------------------------------===//
2754 // PrinterHelper
2755 //===----------------------------------------------------------------------===//
2756 
2757 // Implement virtual destructor.
Expr * getInc()
Definition: Stmt.h:1237
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:577
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition: ExprObjC.h:1517
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:78
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:1060
ExprIterator arg_iterator
Definition: ExprCXX.h:1343
Represents a single C99 designator.
Definition: Expr.h:4181
Raw form: operator "" X (const char *)
Definition: ExprCXX.h:477
Expr * getVal2() const
Definition: Expr.h:5155
Defines the clang::ASTContext interface.
const BlockDecl * getBlockDecl() const
Definition: Expr.h:4865
This represents &#39;#pragma omp distribute simd&#39; composite directive.
Definition: StmtOpenMP.h:3188
This represents &#39;#pragma omp master&#39; directive.
Definition: StmtOpenMP.h:1371
operator "" X (long double)
Definition: ExprCXX.h:486
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition: ExprCXX.h:892
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:565
capture_iterator explicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of explicit lambda captures.
Definition: ExprCXX.cpp:977
This represents &#39;#pragma omp task&#39; directive.
Definition: StmtOpenMP.h:1711
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:1616
Represents a &#39;co_await&#39; expression while the type of the promise is dependent.
Definition: ExprCXX.h:4340
Expr * getArrayIndex(const Designator &D) const
Definition: Expr.cpp:3796
bool getValue() const
Definition: ExprObjC.h:94
This represents &#39;thread_limit&#39; clause in the &#39;#pragma omp ...&#39; directive.
The receiver is an object instance.
Definition: ExprObjC.h:1054
Expr * getLHS() const
Definition: Expr.h:3314
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:2694
const Stmt * getElse() const
Definition: Stmt.h:969
unsigned getNumInputs() const
Definition: Stmt.h:1532
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:5013
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition: ExprCXX.h:2938
bool hasTemplateKeyword() const
Determines whether the member name was preceded by the template keyword.
Definition: Expr.h:2538
ObjCDictionaryElement getKeyValueElement(unsigned Index) const
Definition: ExprObjC.h:344
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition: Expr.cpp:2003
CompoundStmt * getBlock() const
Definition: Stmt.h:1958
Smart pointer class that efficiently represents Objective-C method names.
This represents clause &#39;copyin&#39; in the &#39;#pragma omp ...&#39; directives.
A (possibly-)qualified type.
Definition: Type.h:653
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:2965
bool varlist_empty() const
Definition: OpenMPClause.h:205
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:2483
ArrayRef< OMPClause * > clauses()
Definition: StmtOpenMP.h:235
Expr * getCond() const
Definition: Expr.h:3709
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2278
Selector getSelector() const
Definition: ExprObjC.cpp:312
const Expr * getSubExpr() const
Definition: ExprCXX.h:1007
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:991
Expr * getCond()
Definition: Stmt.h:1127
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Definition: Expr.h:3573
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition: Expr.h:3567
bool isSuperReceiver() const
Definition: ExprObjC.h:739
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2339
CompoundStmt * getSubStmt()
Definition: Expr.h:3504
const Expr * getInit(unsigned Init) const
Definition: Expr.h:3920
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition: ExprCXX.h:1782
ObjCProtocolDecl * getProtocol() const
Definition: ExprObjC.h:490
Represents a &#39;co_return&#39; statement in the C++ Coroutines TS.
Definition: StmtCXX.h:432
Stmt - This represents one statement.
Definition: Stmt.h:66
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2266
This represents clause &#39;in_reduction&#39; in the &#39;#pragma omp task&#39; directives.
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition: StmtObjC.h:224
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3058
CXXCatchStmt * getHandler(unsigned i)
Definition: StmtCXX.h:104
IfStmt - This represents an if/then/else.
Definition: Stmt.h:929
bool param_empty() const
Definition: Decl.h:3785
unsigned getNumOutputs() const
Definition: Stmt.h:1510
static CharSourceRange getTokenRange(SourceRange R)
This represents &#39;#pragma omp for simd&#39; directive.
Definition: StmtOpenMP.h:1121
bool isRecordType() const
Definition: Type.h:6017
Expr * getBase() const
Definition: Expr.h:2477
const StringLiteral * getAsmString() const
Definition: Stmt.h:1642
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
This represents &#39;grainsize&#39; clause in the &#39;#pragma omp ...&#39; directive.
This represents &#39;#pragma omp teams distribute parallel for&#39; composite directive.
Definition: StmtOpenMP.h:3599
Expr * getImplicitObjectArgument() const
Retrieves the implicit object argument for the member call.
Definition: ExprCXX.cpp:505
Stmt * getHandlerBlock() const
Definition: StmtCXX.h:52
bool isVariadic() const
Definition: Type.h:3617
arg_iterator arg_begin()
Definition: ExprCXX.h:1353
llvm::APFloat getValue() const
Definition: Expr.h:1405
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:4545
param_iterator param_end()
Definition: Decl.h:3787
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2736
This represents &#39;if&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:240
const Expr * getSubExpr() const
Definition: Expr.h:3796
DeclarationNameInfo getNameInfo() const
Retrieve the name of the entity we&#39;re testing for, along with location information.
Definition: StmtCXX.h:276
Defines the C++ template declaration subclasses.
Opcode getOpcode() const
Definition: Expr.h:3026
StringRef P
Represents an attribute applied to a statement.
Definition: Stmt.h:878
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1665
static bool isImplicitThis(const Expr *E)
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies this name, if any.
Definition: StmtCXX.h:272
Expr * getLowerBound()
Get lower bound of array section.
Definition: ExprOpenMP.h:91
This represents &#39;priority&#39; clause in the &#39;#pragma omp ...&#39; directive.
This represents &#39;#pragma omp target teams distribute&#39; combined directive.
Definition: StmtOpenMP.h:3736
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
Definition: ExprCXX.h:2912
Represents Objective-C&#39;s @throw statement.
Definition: StmtObjC.h:313
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list...
Definition: Expr.h:1119
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:443
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1239
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition: ExprObjC.h:802
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent...
Definition: ExprCXX.h:2423
bool getIsCXXTry() const
Definition: Stmt.h:1997
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:365
A container of type source information.
Definition: Decl.h:86
This represents &#39;update&#39; clause in the &#39;#pragma omp atomic&#39; directive.
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name...
Definition: ExprCXX.h:2254
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:308
This represents &#39;#pragma omp parallel for&#39; directive.
Definition: StmtOpenMP.h:1492
MS property subscript expression.
Definition: ExprCXX.h:797
This represents &#39;#pragma omp target teams distribute parallel for&#39; combined directive.
Definition: StmtOpenMP.h:3804
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:4035
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition: Decl.h:3782
Expr * getAlignment()
Returns alignment.
void printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const
Expr * getNumForLoops() const
Return the number of associated for-loops.
Definition: OpenMPClause.h:960
const Expr * getSubExpr() const
Definition: Expr.h:1475
Expr * getIndexExpr(unsigned Idx)
Definition: Expr.h:1989
This represents &#39;#pragma omp target exit data&#39; directive.
Definition: StmtOpenMP.h:2403
Stmt * getSubStmt()
Definition: Stmt.h:811
This represents &#39;read&#39; clause in the &#39;#pragma omp atomic&#39; directive.
This represents clause &#39;private&#39; in the &#39;#pragma omp ...&#39; directives.
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC &#39;id&#39; type.
Definition: ExprObjC.h:1436
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2637
This represents &#39;num_threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:382
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6307
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition: ExprCXX.h:2388
This represents &#39;defaultmap&#39; clause in the &#39;#pragma omp ...&#39; directive.
ObjCInterfaceDecl * getClassReceiver() const
Definition: ExprObjC.h:734
bool isArrow() const
Definition: ExprObjC.h:1464
Expr * getVal1() const
Definition: Expr.h:5145
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:594
const char * getName() const
Definition: Stmt.cpp:329
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:1956
This represents implicit clause &#39;flush&#39; for the &#39;#pragma omp flush&#39; directive.
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:985
Expr * getExprOperand() const
Definition: ExprCXX.h:695
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Definition: ExprCXX.h:3000
TypeSourceInfo * getArg(unsigned I) const
Retrieve the Ith argument.
Definition: ExprCXX.h:2391
Defines the clang::Expr interface and subclasses for C++ expressions.
StringRef getInputName(unsigned i) const
Definition: Stmt.h:1738
Expr * getGrainsize() const
Return safe iteration space distance.
This represents &#39;nogroup&#39; clause in the &#39;#pragma omp ...&#39; directive.
This represents &#39;safelen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:447
ObjCPropertyDecl * getExplicitProperty() const
Definition: ExprObjC.h:670
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:302
Expr * getExprOperand() const
Definition: ExprCXX.h:902
const Stmt * getSubStmt() const
Definition: StmtObjC.h:356
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:839
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Definition: Expr.h:2865
Represents a C99 designated initializer expression.
Definition: Expr.h:4106
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:291
One of these records is kept for each identifier that is lexed.
Stmt * getBody()
Definition: Stmt.h:1175
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Definition: ExprCXX.h:4076
An element in an Objective-C dictionary literal.
Definition: ExprObjC.h:239
This represents &#39;#pragma omp parallel&#39; directive.
Definition: StmtOpenMP.h:251
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:3533
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:4340
This represents &#39;simd&#39; clause in the &#39;#pragma omp ...&#39; directive.
child_range children()
Definition: ExprObjC.h:227
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2461
This represents clause &#39;lastprivate&#39; in the &#39;#pragma omp ...&#39; directives.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3507
Represents a place-holder for an object not to be initialized by anything.
Definition: Expr.h:4400
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition: ExprCXX.h:2652
StringLiteral * getString()
Definition: ExprObjC.h:63
CompoundStmt * getBody() const
Retrieve the body of the lambda.
Definition: ExprCXX.cpp:1014
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:1880
const Expr * getRetValue() const
Definition: Stmt.cpp:925
bool SuppressInitializers
Suppress printing of variable initializers.
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:2542
Expr * getChunkSize()
Get chunk size.
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:3744
This represents clause &#39;map&#39; in the &#39;#pragma omp ...&#39; directives.
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:246
This represents clause &#39;to&#39; in the &#39;#pragma omp ...&#39; directives.
Expr * getPlacementArg(unsigned i)
Definition: ExprCXX.h:1962
This represents &#39;#pragma omp target simd&#39; directive.
Definition: StmtOpenMP.h:3324
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:926
Represents a C++ member access expression for which lookup produced a set of overloaded functions...
Definition: ExprCXX.h:3439
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:4790
Expr * getSafelen() const
Return safe iteration space distance.
Definition: OpenMPClause.h:481
Expr * getSubExpr()
Definition: Expr.h:2761
This represents &#39;#pragma omp barrier&#39; directive.
Definition: StmtOpenMP.h:1823
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp, [NSNumber numberWithInt:42]];.
Definition: ExprObjC.h:171
Expr * getNumTeams()
Return NumTeams number.
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition: ExprCXX.h:3894
This represents &#39;#pragma omp critical&#39; directive.
Definition: StmtOpenMP.h:1418
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition: ExprCXX.h:1651
OpenMPDirectiveKind getCancelRegion() const
Get cancellation region for the current cancellation point.
Definition: StmtOpenMP.h:2702
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:2709
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:2941
Selector getSelector() const
Definition: ExprObjC.h:442
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2164
bool isUnarySelector() const
Represents Objective-C&#39;s @catch statement.
Definition: StmtObjC.h:74
Expr * getLHS() const
Definition: ExprCXX.h:4170
StringRef getOpcodeStr() const
Definition: Expr.h:3045
This represents clause &#39;copyprivate&#39; in the &#39;#pragma omp ...&#39; directives.
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:1308
Describes an C or C++ initializer list.
Definition: Expr.h:3872
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:638
This represents &#39;#pragma omp distribute parallel for&#39; composite directive.
Definition: StmtOpenMP.h:3039
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: Decl.cpp:4249
bool isArrow() const
Definition: ExprObjC.h:551
Expr * getKeyExpr() const
Definition: ExprObjC.h:850
This represents &#39;#pragma omp teams distribute parallel for simd&#39; composite directive.
Definition: StmtOpenMP.h:3528
Expr * getArraySize()
Definition: ExprCXX.h:1949
ForStmt - This represents a &#39;for (init;cond;inc)&#39; stmt.
Definition: Stmt.h:1203
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
Expr * getBaseExpr() const
Definition: ExprObjC.h:847
Expr * getOperand() const
Definition: ExprCXX.h:3619
const Expr * getThrowExpr() const
Definition: StmtObjC.h:325
< Capturing the *this object by copy
Definition: Lambda.h:37
bool isGlobalNew() const
Definition: ExprCXX.h:1974
Expr * getPtr() const
Definition: Expr.h:5135
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:1987
Stmt * getBody()
Definition: Stmt.h:1238
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2985
const Expr * getAssocExpr(unsigned i) const
Definition: Expr.h:4717
Stmt * getInit()
Definition: Stmt.h:1217
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:417
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:2570
bool isClassReceiver() const
Definition: ExprObjC.h:740
const StringLiteral * getInputConstraintLiteral(unsigned i) const
Definition: Stmt.h:1747
static bool isPostfix(Opcode Op)
isPostfix - Return true if this is a postfix operation, like x++.
Definition: Expr.h:1752
CXXForRangeStmt - This represents C++0x [stmt.ranged]&#39;s ranged for statement, represented as &#39;for (ra...
Definition: StmtCXX.h:128
bool isArrow() const
Definition: Expr.h:2582
This represents &#39;#pragma omp cancellation point&#39; directive.
Definition: StmtOpenMP.h:2658
This represents &#39;default&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:606
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:51
Expr * getRHS() const
Definition: ExprCXX.h:4171
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, const ASTContext *Context=nullptr) const
const CallExpr * getConfig() const
Definition: ExprCXX.h:216
bool isArrow() const
Definition: ExprCXX.h:781
New-expression has a C++98 paren-delimited initializer.
Definition: ExprCXX.h:1897
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
Definition: Expr.h:5232
This represents &#39;final&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:330
This represents &#39;mergeable&#39; clause in the &#39;#pragma omp ...&#39; directive.
Expr * getCond()
Definition: Stmt.h:1236
This represents &#39;#pragma omp teams&#39; directive.
Definition: StmtOpenMP.h:2601
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
NestedNameSpecifier * getQualifier() const
Fetches the nested-name qualifier, if one was given.
Definition: ExprCXX.h:2661
const Expr * getControllingExpr() const
Definition: Expr.h:4742
This represents clause &#39;reduction&#39; in the &#39;#pragma omp ...&#39; directives.
Helper class for OffsetOfExpr.
Definition: Expr.h:1822
Expr * getOperand() const
Definition: ExprCXX.h:4365
This represents &#39;#pragma omp teams distribute simd&#39; combined directive.
Definition: StmtOpenMP.h:3458
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1196
StringLiteral * getClobberStringLiteral(unsigned i)
Definition: Stmt.h:1781
StringRef getOutputName(unsigned i) const
Definition: Stmt.h:1710
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:90
Expr * Key
The key for the dictionary element.
Definition: ExprObjC.h:241
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1580
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3202
This represents clause &#39;is_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
bool isCmpXChg() const
Definition: Expr.h:5179
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda&#39;s captures is an init-capture.
Definition: ExprCXX.cpp:956
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1821
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1042
bool isTypeOperand() const
Definition: ExprCXX.h:885
const IdentifierInfo * getUDSuffix() const
Returns the ud-suffix specified for this literal.
Definition: ExprCXX.cpp:733
This represents clause &#39;from&#39; in the &#39;#pragma omp ...&#39; directives.
Represents the this expression in C++.
Definition: ExprCXX.h:945
ObjCIvarDecl * getDecl()
Definition: ExprObjC.h:543
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
bool isArrayForm() const
Definition: ExprCXX.h:2112
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition: StmtObjC.h:206
This represents &#39;#pragma omp target parallel for simd&#39; directive.
Definition: StmtOpenMP.h:3256
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition: Expr.h:2911
OpenMP 4.0 [2.4, Array Sections].
Definition: ExprOpenMP.h:45
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3269
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1324
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2197
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:595
OpenMPDefaultClauseKind getDefaultKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:653
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1590
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3270
QualType getQueriedType() const
Definition: ExprCXX.h:2468
This represents &#39;threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
CompoundStmt * getSubStmt() const
Retrieve the compound statement that will be included in the program only if the existence of the sym...
Definition: StmtCXX.h:280
This represents &#39;#pragma omp taskgroup&#39; directive.
Definition: StmtOpenMP.h:1911
Expr * getSimdlen() const
Return safe iteration space distance.
Definition: OpenMPClause.h:535
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name...
Definition: Expr.h:2512
This represents clause &#39;aligned&#39; in the &#39;#pragma omp ...&#39; directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
Definition: Expr.h:2031
arg_iterator arg_end()
Definition: ExprCXX.h:1354
This represents clause &#39;task_reduction&#39; in the &#39;#pragma omp taskgroup&#39; directives.
InitListExpr * getUpdater() const
Definition: Expr.h:4458
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:3778
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
void outputString(raw_ostream &OS) const
Definition: Expr.cpp:891
const DeclStmt * getConditionVariableDeclStmt() const
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
Definition: Stmt.h:958
OpenMPProcBindClauseKind getProcBindKind() const
Returns kind of the clause.
Definition: OpenMPClause.h:723
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:934
unsigned getValue() const
Definition: Expr.h:1372
This represents &#39;#pragma omp distribute&#39; directive.
Definition: StmtOpenMP.h:2912
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:4919
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1802
Expr * getCond() const
Definition: Expr.h:3303
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3689
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:4309
This represents &#39;proc_bind&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:675
This represents &#39;capture&#39; clause in the &#39;#pragma omp atomic&#39; directive.
Expr - This represents one expression.
Definition: Expr.h:106
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:2570
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1391
bool isArrow() const
Determine whether this member expression used the &#39;->&#39; operator; otherwise, it used the &#39;...
Definition: ExprCXX.h:3524
int Id
Definition: ASTDiff.cpp:191
static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node, bool PrintSuffix)
const FunctionProtoType * T
This represents &#39;simdlen&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:501
Expr * getNumTasks() const
Return safe iteration space distance.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition: ExprCXX.cpp:1242
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1530
const Stmt * getThen() const
Definition: Stmt.h:967
A C++ const_cast expression (C++ [expr.const.cast]).
Definition: ExprCXX.h:420
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:4851
VarDecl * getExceptionDecl() const
Definition: StmtCXX.h:50
IdentifierInfo * getDestroyedTypeIdentifier() const
In a dependent pseudo-destructor expression for which we do not have full type information on the des...
Definition: ExprCXX.h:2297
unsigned getNumInits() const
Definition: Expr.h:3902
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition: ExprCXX.cpp:1189
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:4512
const Expr * getCallee() const
Definition: Expr.h:2249
This represents &#39;#pragma omp target teams distribute parallel for simd&#39; combined directive.
Definition: StmtOpenMP.h:3888
QualType getArgumentType() const
Definition: Expr.h:2068
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an &#39;->&#39; (otherwise, it used a &#39;.
Definition: ExprCXX.h:2260
Stmt * getBody()
Definition: Stmt.h:1130
Expr * getOrder() const
Definition: Expr.h:5138
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:288
const CompoundStmt * getSynchBody() const
Definition: StmtObjC.h:282
Expr * getRHS()
Definition: Stmt.h:762
Represents Objective-C&#39;s @synchronized statement.
Definition: StmtObjC.h:262
ObjCSelectorExpr used for @selector in Objective-C.
Definition: ExprObjC.h:429
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:1968
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:3724
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:65
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition: Expr.h:4896
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
IdentifierInfo & getAccessor() const
Definition: Expr.h:4812
This represents &#39;#pragma omp target teams distribute simd&#39; combined directive.
Definition: StmtOpenMP.h:3961
ArrayTypeTrait getTrait() const
Definition: ExprCXX.h:2466
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
This represents &#39;ordered&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:925
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
Definition: Type.cpp:1800
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:1876
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
QualType getType() const
Definition: Expr.h:128
virtual bool handledStmt(Stmt *E, raw_ostream &OS)=0
This represents &#39;#pragma omp for&#39; directive.
Definition: StmtOpenMP.h:1044
LabelDecl * getLabel() const
Definition: Stmt.h:1286
const Stmt * getTryBody() const
Retrieve the @try body.
Definition: StmtObjC.h:197
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4145
QualType getEncodedType() const
Definition: ExprObjC.h:407
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:1413
This represents &#39;#pragma omp target teams&#39; directive.
Definition: StmtOpenMP.h:3677
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:903
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:1795
ObjCMethodDecl * getImplicitPropertyGetter() const
Definition: ExprObjC.h:675
UnaryOperator - This represents the unary-expression&#39;s (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1717
CXXMethodDecl * getMethodDecl() const
Retrieves the declaration of the called method.
Definition: ExprCXX.cpp:517
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition: ExprObjC.h:1187
AtomicOp getOp() const
Definition: Expr.h:5167
A member reference to an MSPropertyDecl.
Definition: ExprCXX.h:728
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:3838
const OffsetOfNode & getComponent(unsigned Idx) const
Definition: Expr.h:1975
unsigned getNumArgs() const
Expr * getDevice()
Return device number.
This represents &#39;#pragma omp cancel&#39; directive.
Definition: StmtOpenMP.h:2716
This represents &#39;collapse&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:555
This represents clause &#39;firstprivate&#39; in the &#39;#pragma omp ...&#39; directives.
ValueDecl * getDecl()
Definition: Expr.h:1041
Selector getSelector() const
Definition: DeclObjC.h:359
const Expr * getSubExpr() const
Definition: Expr.h:1681
const Expr * getSubExpr() const
Definition: ExprCXX.h:1219
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
Definition: Expr.h:2922
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1003
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition: Expr.h:2154
bool getValue() const
Definition: ExprCXX.h:543
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1...
Definition: Expr.h:1463
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: ExprObjC.h:1341
This represents &#39;#pragma omp flush&#39; directive.
Definition: StmtOpenMP.h:1984
This represents &#39;#pragma omp parallel for simd&#39; directive.
Definition: StmtOpenMP.h:1572
DoStmt - This represents a &#39;do/while&#39; stmt.
Definition: Stmt.h:1154
This represents &#39;seq_cst&#39; clause in the &#39;#pragma omp atomic&#39; directive.
This represents &#39;untied&#39; clause in the &#39;#pragma omp ...&#39; directive.
StringRef getBridgeKindName() const
Retrieve the kind of bridge being performed as a string.
Definition: ExprObjC.cpp:355
param_iterator param_begin()
Definition: Decl.h:3786
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the member name.
Definition: ExprCXX.h:3303
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:2896
Expr * getArgument()
Definition: ExprCXX.h:2125
LiteralOperatorKind getLiteralOperatorKind() const
Returns the kind of literal operator invocation which this expression represents. ...
Definition: ExprCXX.cpp:704
This represents &#39;#pragma omp target enter data&#39; directive.
Definition: StmtOpenMP.h:2344
This represents &#39;num_teams&#39; clause in the &#39;#pragma omp ...&#39; directive.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:338
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:868
Expr * getBase() const
Definition: Expr.h:4455
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:3601
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver. ...
Definition: ExprObjC.h:1328
Kind
This captures a statement into a function.
Definition: Stmt.h:2054
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1400
operator "" X (const CharT *, size_t)
Definition: ExprCXX.h:489
ExpressionTrait getTrait() const
Definition: ExprCXX.h:2530
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:4969
bool isImplicitProperty() const
Definition: ExprObjC.h:667
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
Raw form: operator "" X<cs...> ()
Definition: ExprCXX.h:480
unsigned getNumExprs() const
Definition: Expr.h:4618
This represents &#39;#pragma omp single&#39; directive.
Definition: StmtOpenMP.h:1316
unsigned Indentation
The number of spaces to use to indent each line.
Definition: PrettyPrinter.h:68
body_range body()
Definition: Stmt.h:624
QualType getReturnType() const
Definition: Type.h:3203
capture_iterator explicit_capture_begin() const
Retrieve an iterator pointing to the first explicit lambda capture.
Definition: ExprCXX.cpp:973
This represents &#39;hint&#39; clause in the &#39;#pragma omp ...&#39; directive.
unsigned UnderscoreAlignof
Whether we can use &#39;_Alignof&#39; rather than &#39;__alignof&#39;.
const Stmt * getCatchBody() const
Definition: StmtObjC.h:90
unsigned getNumHandlers() const
Definition: StmtCXX.h:103
Expr * getSubExpr() const
Definition: Expr.h:1744
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition: ExprCXX.h:3366
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:33
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:1842
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c dictionary literal.
Definition: ExprObjC.h:342
Expr * getLHS()
Definition: Stmt.h:761
static const char * getExpressionTraitName(ExpressionTrait ET)
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit...
Definition: ExprCXX.h:457
DeclarationName getName() const
getName - Returns the embedded declaration name.
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:911
This represents &#39;schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:744
Represents a call to a member function that may be written either with member call syntax (e...
Definition: ExprCXX.h:164
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:487
This represents clause &#39;shared&#39; in the &#39;#pragma omp ...&#39; directives.
const Expr * getExpr(unsigned Init) const
Definition: Expr.h:4620
DeclarationNameInfo getDirectiveName() const
Return name of the directive.
Definition: StmtOpenMP.h:1476
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1964
Expr * getPriority()
Return Priority number.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:183
SourceLocation getColonLoc() const
Definition: ExprOpenMP.h:109
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This represents &#39;#pragma omp taskwait&#39; directive.
Definition: StmtOpenMP.h:1867
QualType getAllocatedType() const
Definition: ExprCXX.h:1916
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
This file defines OpenMP nodes for declarative directives.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>, and corresponding __opencl_atomic_* for OpenCL 2.0.
Definition: Expr.h:5103
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2062
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition: ExprObjC.h:474
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
Definition: Stmt.h:1719
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2822
bool hasTemplateKeyword() const
Determines whether the member name was preceded by the template keyword.
Definition: ExprCXX.h:3362
OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY
Fetches the map type modifier for the clause.
CharacterKind getKind() const
Definition: Expr.h:1365
This represents &#39;#pragma omp target&#39; directive.
Definition: StmtOpenMP.h:2228
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:428
static const char * getTypeTraitName(TypeTrait TT)
void dumpPretty(const ASTContext &Context) const
dumpPretty/printPretty - These two methods do a "pretty print" of the AST back to its original source...
Expr * getNumForLoops() const
Return the number of associated for-loops.
Definition: OpenMPClause.h:590
bool isParenTypeId() const
Definition: ExprCXX.h:1971
IdentType getIdentType() const
Definition: Expr.h:1215
void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const
Expr * getArrayRangeStart(const Designator &D) const
Definition: Expr.cpp:3801
Expr * getSubExpr()
Definition: ExprObjC.h:135
An expression trait intrinsic.
Definition: ExprCXX.h:2493
This represents &#39;#pragma omp ordered&#39; directive.
Definition: StmtOpenMP.h:2039
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:3488
This represents &#39;#pragma omp target update&#39; directive.
Definition: StmtOpenMP.h:2980
ObjCBoxedExpr - used for generalized expression boxing.
Definition: ExprObjC.h:117
bool isArgumentType() const
Definition: Expr.h:2067
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3394
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
Definition: CharInfo.h:140
const DeclStmt * getConditionVariableDeclStmt() const
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
Definition: Stmt.h:1123
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name...
Definition: StmtCXX.h:240
void printName(raw_ostream &OS) const
printName - Print the human-readable name to a stream.
bool hasTemplateKeyword() const
Determines whether the name in this declaration reference was preceded by the template keyword...
Definition: Expr.h:1115
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:2854
Expr * Value
The value of the dictionary element.
Definition: ExprObjC.h:244
const Expr * getInitializer() const
Definition: Expr.h:2663
InitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition: ExprCXX.h:1980
Expr * getLHS() const
Definition: Expr.h:3029
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:354
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:3191
Represents a C11 generic selection.
Definition: Expr.h:4684
StringRef getName() const
Return the actual identifier string.
const Expr * getBase() const
Definition: Expr.h:4808
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition: ExprObjC.h:1206
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:3444
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers...
Definition: ExprObjC.h:1572
ast_type_traits::DynTypedNode Node
Represents a reference to a function parameter pack that has been substituted but not yet expanded...
Definition: ExprCXX.h:3957
Represents a template argument.
Definition: TemplateBase.h:51
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:3401
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:556
bool isMutable() const
Determine whether the lambda is mutable, meaning that any captures values can be modified.
Definition: ExprCXX.cpp:1025
bool isTypeOperand() const
Definition: ExprCXX.h:678
unsigned getNumAssocs() const
Definition: Expr.h:4711
Dataflow Directional Tag Classes.
This represents &#39;device&#39; clause in the &#39;#pragma omp ...&#39; directive.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isVolatile() const
Definition: Stmt.h:1497
OpenMPDefaultmapClauseKind getDefaultmapKind() const
Get kind of the clause.
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1188
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:2575
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
Definition: ExprCXX.h:2071
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:106
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
Definition: ExprCXX.h:3921
MSPropertyDecl * getPropertyDecl() const
Definition: ExprCXX.h:780
Parameter for Objective-C &#39;self&#39; argument.
Definition: Decl.h:1459
This represents &#39;#pragma omp section&#39; directive.
Definition: StmtOpenMP.h:1254
This represents &#39;#pragma omp teams distribute&#39; directive.
Definition: StmtOpenMP.h:3390
QualType getAssocType(unsigned i) const
Definition: Expr.h:4735
A runtime availability query.
Definition: ExprObjC.h:1633
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition: ExprCXX.h:380
This represents &#39;#pragma omp simd&#39; directive.
Definition: StmtOpenMP.h:979
Represents a &#39;co_yield&#39; expression.
Definition: ExprCXX.h:4387
Expr * getOperand() const
Retrieve the operand of the &#39;co_return&#39; statement.
Definition: StmtCXX.h:456
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3652
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1317
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition: Stmt.cpp:945
This represents clause &#39;linear&#39; in the &#39;#pragma omp ...&#39; directives.
const Expr * getSynchExpr() const
Definition: StmtObjC.h:290
bool isIfExists() const
Determine whether this is an __if_exists statement.
Definition: StmtCXX.h:265
NestedNameSpecifierLoc getQualifierLoc() const
Definition: ExprCXX.h:783
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the full name info for the member that this expression refers to.
Definition: ExprCXX.h:3534
OpenMPDefaultmapClauseModifier getDefaultmapModifier() const
Get the modifier of the clause.
This represents &#39;#pragma omp atomic&#39; directive.
Definition: StmtOpenMP.h:2094
bool SuppressImplicitBase
When true, don&#39;t print the implicit &#39;self&#39; or &#39;this&#39; expressions.
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition: ExprCXX.h:685
Expr * getArrayRangeEnd(const Designator &D) const
Definition: Expr.cpp:3807
const Stmt * getBody() const
Definition: Stmt.h:1046
llvm::APInt getValue() const
Definition: Expr.h:1279
Represents a __leave statement.
Definition: Stmt.h:2019
LabelDecl * getLabel() const
Definition: Expr.h:3466
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
Definition: ExprObjC.h:1225
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:3600
SwitchStmt - This represents a &#39;switch&#39; stmt.
Definition: Stmt.h:1007
Capturing variable-length array type.
Definition: Lambda.h:39
Not an overloaded operator.
Definition: OperatorKinds.h:23
Expr * getOrderFail() const
Definition: Expr.h:5151
DeclarationNameInfo getNameInfo() const
Definition: Expr.h:1045
Represents the body of a coroutine.
Definition: StmtCXX.h:299
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition: ExprCXX.h:2691
Expr * getBase() const
Definition: ExprObjC.h:1462
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2121
OpenMPDirectiveKind getNameModifier() const
Return directive name modifier associated with the clause.
Definition: OpenMPClause.h:311
bool hasBraces() const
Definition: Stmt.h:1823
Represents Objective-C&#39;s collection statement.
Definition: StmtObjC.h:24
static StringRef getIdentTypeName(IdentType IT)
Definition: Expr.cpp:473
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:386
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword...
An implicit indirection through a C++ base class, when the field found is in a base class...
Definition: Expr.h:1834
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:203
Represents a &#39;co_await&#39; expression.
Definition: ExprCXX.h:4304
Opcode getOpcode() const
Definition: Expr.h:1741
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1365
decl_range decls()
Definition: Stmt.h:534
Represents Objective-C&#39;s @finally statement.
Definition: StmtObjC.h:120
StringRef getAsmString() const
Definition: Stmt.h:1829
unsigned Alignof
Whether we can use &#39;alignof&#39; rather than &#39;__alignof&#39;.
bool hasAssociatedStmt() const
Returns true if directive has associated statement.
Definition: StmtOpenMP.h:193
const Expr * getBase() const
Definition: ExprObjC.h:547
bool isArrow() const
Determine whether this member expression used the &#39;->&#39; operator; otherwise, it used the &#39;...
Definition: ExprCXX.h:3296
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
Capturing the *this object by reference.
Definition: Lambda.h:35
This represents &#39;write&#39; clause in the &#39;#pragma omp atomic&#39; directive.
const char * getOpenMPDirectiveName(OpenMPDirectiveKind Kind)
Definition: OpenMPKinds.cpp:31
unsigned getNumClobbers() const
Definition: Stmt.h:1542
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:513
bool ConstantsAsWritten
Whether we should print the constant expressions as written in the sources.
SourceManager & getSourceManager()
Definition: ASTContext.h:643
Expr * getRHS() const
Definition: Expr.h:3713
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3087
SEHFinallyStmt * getFinallyHandler() const
Definition: Stmt.cpp:949
GotoStmt - This represents a direct goto.
Definition: Stmt.h:1274
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1113
Expr * getTarget()
Definition: Stmt.h:1328
A template argument list.
Definition: DeclTemplate.h:210
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:3625
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:1147
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1097
Expr * getCond()
Definition: Stmt.h:1172
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
OpenMPScheduleClauseModifier getSecondScheduleModifier() const
Get the second modifier of the clause.
Definition: OpenMPClause.h:879
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2387
This represents &#39;#pragma omp target parallel&#39; directive.
Definition: StmtOpenMP.h:2461
This represents &#39;nowait&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:975
ContinueStmt - This represents a continue.
Definition: Stmt.h:1351
OpenMPScheduleClauseModifier getFirstScheduleModifier() const
Get the first modifier of the clause.
Definition: OpenMPClause.h:874
Represents a loop initializing the elements of an array.
Definition: Expr.h:4490
This represents &#39;num_tasks&#39; clause in the &#39;#pragma omp ...&#39; directive.
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:3664
Expr * getFilterExpr() const
Definition: Stmt.h:1920
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:3342
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:29
VarDecl * getLoopVariable()
Definition: StmtCXX.cpp:80
An index into an array.
Definition: Expr.h:1827
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr.type.conv]).
Definition: ExprCXX.h:1471
OpenMPScheduleClauseKind getScheduleKind() const
Get kind of the clause.
Definition: OpenMPClause.h:871
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Definition: ExprObjC.h:254
Expr * getOperand() const
Definition: ExprCXX.h:4325
Expr * getRHS() const
Definition: Expr.h:3315
WhileStmt - This represents a &#39;while&#39; stmt.
Definition: Stmt.h:1098
Capturing by reference.
Definition: Lambda.h:38
SourceLocation getLParenLoc() const
Definition: ExprCXX.h:1502
Expr * getThreadLimit()
Return ThreadLimit number.
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2145
CompoundStmt * getTryBlock()
Definition: StmtCXX.h:96
The receiver is a class.
Definition: ExprObjC.h:1051
Represents Objective-C&#39;s @try ... @catch ... @finally statement.
Definition: StmtObjC.h:154
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:265
bool isGlobalDelete() const
Definition: ExprCXX.h:2111
This represents &#39;#pragma omp taskloop simd&#39; directive.
Definition: StmtOpenMP.h:2846
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition: StmtObjC.h:203
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3287
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1509
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition: ExprCXX.h:1779
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2209
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3681
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:270
This represents &#39;dist_schedule&#39; clause in the &#39;#pragma omp ...&#39; directive.
Expr * getLHS() const
Definition: Expr.h:3711
Stmt * getBody() const
Retrieve the body of the coroutine as written.
Definition: StmtCXX.h:360
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:915
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:246
This represents &#39;#pragma omp sections&#39; directive.
Definition: StmtOpenMP.h:1186
Expr * getHint() const
Returns number of threads.
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition: ExprObjC.h:82
bool isObjectReceiver() const
Definition: ExprObjC.h:738
unsigned getNumComponents() const
Definition: Expr.h:1985
This represents &#39;#pragma omp target data&#39; directive.
Definition: StmtOpenMP.h:2286
OpenMPDirectiveKind getCancelRegion() const
Get cancellation region for the current cancellation point.
Definition: StmtOpenMP.h:2765
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:956
static bool printExprAsWritten(raw_ostream &OS, Expr *E, const ASTContext *Context)
Prints the given expression using the original source text.
Expr * getRHS() const
Definition: Expr.h:3031
NestedNameSpecifierLoc getQualifierLoc() const
Gets the nested name specifier.
unsigned IncludeNewlines
When true, include newlines after statements like "break", etc.
BreakStmt - This represents a break.
Definition: Stmt.h:1377
Expr * getChunkSize()
Get chunk size.
Definition: OpenMPClause.h:903
const VarDecl * getCatchParamDecl() const
Definition: StmtObjC.h:94
static bool isImplicitSelf(const Expr *E)
const char * getCastName() const
getCastName - Get the name of the C++ cast being used, e.g., "static_cast", "dynamic_cast", "reinterpret_cast", or "const_cast".
Definition: ExprCXX.cpp:544
Expr * getOperand() const
Definition: ExprCXX.h:4400
Expr * getNumThreads() const
Returns number of threads.
Definition: OpenMPClause.h:426
Stmt * getSubStmt()
Definition: Stmt.h:859
QualType getTypeAsWritten() const
Retrieve the type that is being constructed, as specified in the source code.
Definition: ExprCXX.h:3125
QualType getType() const
Definition: Decl.h:639
ParmVarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Definition: ExprCXX.h:3986
unsigned getNumArgs() const
Definition: ExprCXX.h:1362
const Expr * getBase() const
Definition: ExprObjC.h:719
const Expr * getCond() const
Definition: Stmt.h:965
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to...
Definition: Expr.cpp:1116
This represents &#39;#pragma omp taskyield&#39; directive.
Definition: StmtOpenMP.h:1779
This represents &#39;#pragma omp distribute parallel for simd&#39; composite directive.
Definition: StmtOpenMP.h:3119
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:530
NestedNameSpecifier * getQualifier() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name.
Definition: Expr.h:1068
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
Definition: Expr.h:1926
Expr * getQueriedExpression() const
Definition: ExprCXX.h:2532
This represents &#39;#pragma omp parallel sections&#39; directive.
Definition: StmtOpenMP.h:1640
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:856
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:3382
const Expr * getCond() const
Definition: Stmt.h:1045
The receiver is a superclass.
Definition: ExprObjC.h:1057
BinaryOperatorKind getOperator() const
Definition: ExprCXX.h:4188
const LangOptions & getLangOpts() const
Definition: ASTContext.h:688
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition: ExprCXX.h:3795
Represents Objective-C&#39;s @autoreleasepool Statement.
Definition: StmtObjC.h:345
CompoundStmt * getTryBlock() const
Definition: Stmt.h:1999
Stmt * getSubStmt()
Definition: Stmt.h:915
InitListExpr * getSyntacticForm() const
Definition: Expr.h:4029
Stmt * getAssociatedStmt() const
Returns statement associated with the directive.
Definition: StmtOpenMP.h:196
Expr * getBaseExpr() const
Definition: ExprCXX.h:779
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:4580
CompoundStmt * getBlock() const
Definition: Stmt.h:1924
Expr * getWeak() const
Definition: Expr.h:5161
This represents &#39;#pragma omp target parallel for&#39; directive.
Definition: StmtOpenMP.h:2521
Attr - This represents one attribute.
Definition: Attr.h:43
This represents clause &#39;use_device_ptr&#39; in the &#39;#pragma omp ...&#39; directives.
operator "" X (unsigned long long)
Definition: ExprCXX.h:483
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition: ExprCXX.h:2378
Expr * getLength()
Get length of array section.
Definition: ExprOpenMP.h:99
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3328
Expr * getCookedLiteral()
If this is not a raw user-defined literal, get the underlying cooked literal (representing the litera...
Definition: ExprCXX.cpp:725
Expr * getBase()
An array section can be written only as Base[LowerBound:Length].
Definition: ExprOpenMP.h:82
Stmt * getSubStmt()
Definition: Stmt.h:763
const DeclStmt * getConditionVariableDeclStmt() const
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Definition: Stmt.h:1038
This represents &#39;#pragma omp taskloop&#39; directive.
Definition: StmtOpenMP.h:2781