Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/StmtPrinter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- StmtPrinter.cpp - Printing implementation for Stmt ASTs ------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which
10
// pretty print the AST back out to C code.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/ASTContext.h"
15
#include "clang/AST/Attr.h"
16
#include "clang/AST/Decl.h"
17
#include "clang/AST/DeclBase.h"
18
#include "clang/AST/DeclCXX.h"
19
#include "clang/AST/DeclObjC.h"
20
#include "clang/AST/DeclOpenMP.h"
21
#include "clang/AST/DeclTemplate.h"
22
#include "clang/AST/Expr.h"
23
#include "clang/AST/ExprCXX.h"
24
#include "clang/AST/ExprObjC.h"
25
#include "clang/AST/ExprOpenMP.h"
26
#include "clang/AST/NestedNameSpecifier.h"
27
#include "clang/AST/OpenMPClause.h"
28
#include "clang/AST/PrettyPrinter.h"
29
#include "clang/AST/Stmt.h"
30
#include "clang/AST/StmtCXX.h"
31
#include "clang/AST/StmtObjC.h"
32
#include "clang/AST/StmtOpenMP.h"
33
#include "clang/AST/StmtVisitor.h"
34
#include "clang/AST/TemplateBase.h"
35
#include "clang/AST/Type.h"
36
#include "clang/Basic/CharInfo.h"
37
#include "clang/Basic/ExpressionTraits.h"
38
#include "clang/Basic/IdentifierTable.h"
39
#include "clang/Basic/JsonSupport.h"
40
#include "clang/Basic/LLVM.h"
41
#include "clang/Basic/Lambda.h"
42
#include "clang/Basic/OpenMPKinds.h"
43
#include "clang/Basic/OperatorKinds.h"
44
#include "clang/Basic/SourceLocation.h"
45
#include "clang/Basic/TypeTraits.h"
46
#include "clang/Lex/Lexer.h"
47
#include "llvm/ADT/ArrayRef.h"
48
#include "llvm/ADT/SmallString.h"
49
#include "llvm/ADT/SmallVector.h"
50
#include "llvm/ADT/StringExtras.h"
51
#include "llvm/ADT/StringRef.h"
52
#include "llvm/Support/Casting.h"
53
#include "llvm/Support/Compiler.h"
54
#include "llvm/Support/ErrorHandling.h"
55
#include "llvm/Support/raw_ostream.h"
56
#include <cassert>
57
#include <string>
58
59
using namespace clang;
60
61
//===----------------------------------------------------------------------===//
62
// StmtPrinter Visitor
63
//===----------------------------------------------------------------------===//
64
65
namespace {
66
67
  class StmtPrinter : public StmtVisitor<StmtPrinter> {
68
    raw_ostream &OS;
69
    unsigned IndentLevel;
70
    PrinterHelper* Helper;
71
    PrintingPolicy Policy;
72
    std::string NL;
73
    const ASTContext *Context;
74
75
  public:
76
    StmtPrinter(raw_ostream &os, PrinterHelper *helper,
77
                const PrintingPolicy &Policy, unsigned Indentation = 0,
78
                StringRef NL = "\n", const ASTContext *Context = nullptr)
79
        : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy),
80
200k
          NL(NL), Context(Context) {}
81
82
45.7k
    void PrintStmt(Stmt *S) { PrintStmt(S, Policy.Indentation); }
83
84
45.8k
    void PrintStmt(Stmt *S, int SubIndent) {
85
45.8k
      IndentLevel += SubIndent;
86
45.8k
      if (S && isa<Expr>(S)) {
87
        // If this is an expr used in a stmt context, indent and newline it.
88
10.2k
        Indent();
89
10.2k
        Visit(S);
90
10.2k
        OS << ";" << NL;
91
35.5k
      } else if (S) {
92
35.5k
        Visit(S);
93
35.5k
      } else {
94
0
        Indent() << "<<<NULL STATEMENT>>>" << NL;
95
0
      }
96
45.8k
      IndentLevel -= SubIndent;
97
45.8k
    }
98
99
7.95k
    void PrintInitStmt(Stmt *S, unsigned PrefixWidth) {
100
      // FIXME: Cope better with odd prefix widths.
101
7.95k
      IndentLevel += (PrefixWidth + 1) / 2;
102
7.95k
      if (auto *DS = dyn_cast<DeclStmt>(S))
103
7.84k
        PrintRawDeclStmt(DS);
104
114
      else
105
114
        PrintExpr(cast<Expr>(S));
106
7.95k
      OS << "; ";
107
7.95k
      IndentLevel -= (PrefixWidth + 1) / 2;
108
7.95k
    }
109
110
13.4k
    void PrintControlledStmt(Stmt *S) {
111
13.4k
      if (auto *CS = dyn_cast<CompoundStmt>(S)) {
112
6.80k
        OS << " ";
113
6.80k
        PrintRawCompoundStmt(CS);
114
6.80k
        OS << NL;
115
6.80k
      } else {
116
6.66k
        OS << NL;
117
6.66k
        PrintStmt(S);
118
6.66k
      }
119
13.4k
    }
120
121
    void PrintRawCompoundStmt(CompoundStmt *S);
122
    void PrintRawDecl(Decl *D);
123
    void PrintRawDeclStmt(const DeclStmt *S);
124
    void PrintRawIfStmt(IfStmt *If);
125
    void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
126
    void PrintCallArgs(CallExpr *E);
127
    void PrintRawSEHExceptHandler(SEHExceptStmt *S);
128
    void PrintRawSEHFinallyStmt(SEHFinallyStmt *S);
129
    void PrintOMPExecutableDirective(OMPExecutableDirective *S,
130
                                     bool ForceNoStmt = false);
131
    void PrintFPPragmas(CompoundStmt *S);
132
133
288k
    void PrintExpr(Expr *E) {
134
288k
      if (E)
135
288k
        Visit(E);
136
0
      else
137
0
        OS << "<null expr>";
138
288k
    }
139
140
56.4k
    raw_ostream &Indent(int Delta = 0) {
141
294k
      for (int i = 0, e = IndentLevel+Delta; i < e; 
++i237k
)
142
237k
        OS << "  ";
143
56.4k
      return OS;
144
56.4k
    }
145
146
536k
    void Visit(Stmt* S) {
147
536k
      if (Helper && 
Helper->handledStmt(S,OS)268k
)
148
130k
          return;
149
406k
      else StmtVisitor<StmtPrinter>::Visit(S);
150
536k
    }
151
152
0
    void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
153
0
      Indent() << "<<unknown stmt type>>" << NL;
154
0
    }
155
156
0
    void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
157
0
      OS << "<<unknown expr type>>";
158
0
    }
159
160
    void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
161
162
#define ABSTRACT_STMT(CLASS)
163
#define STMT(CLASS, PARENT) \
164
    void Visit##CLASS(CLASS *Node);
165
#include "clang/AST/StmtNodes.inc"
166
  };
167
168
} // namespace
169
170
//===----------------------------------------------------------------------===//
171
//  Stmt printing methods.
172
//===----------------------------------------------------------------------===//
173
174
/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
175
/// with no newline after the }.
176
9.09k
void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
177
9.09k
  OS << "{" << NL;
178
9.09k
  PrintFPPragmas(Node);
179
9.09k
  for (auto *I : Node->body())
180
26.4k
    PrintStmt(I);
181
182
9.09k
  Indent() << "}";
183
9.09k
}
184
185
9.09k
void StmtPrinter::PrintFPPragmas(CompoundStmt *S) {
186
9.09k
  if (!S->hasStoredFPFeatures())
187
9.06k
    return;
188
26
  FPOptionsOverride FPO = S->getStoredFPFeatures();
189
26
  bool FEnvAccess = false;
190
26
  if (FPO.hasAllowFEnvAccessOverride()) {
191
5
    FEnvAccess = FPO.getAllowFEnvAccessOverride();
192
5
    Indent() << "#pragma STDC FENV_ACCESS " << (FEnvAccess ? 
"ON"3
:
"OFF"2
)
193
5
             << NL;
194
5
  }
195
26
  if (FPO.hasSpecifiedExceptionModeOverride()) {
196
1
    LangOptions::FPExceptionModeKind EM =
197
1
        FPO.getSpecifiedExceptionModeOverride();
198
1
    if (!FEnvAccess || EM != LangOptions::FPE_Strict) {
199
1
      Indent() << "#pragma clang fp exceptions(";
200
1
      switch (FPO.getSpecifiedExceptionModeOverride()) {
201
0
      default:
202
0
        break;
203
0
      case LangOptions::FPE_Ignore:
204
0
        OS << "ignore";
205
0
        break;
206
1
      case LangOptions::FPE_MayTrap:
207
1
        OS << "maytrap";
208
1
        break;
209
0
      case LangOptions::FPE_Strict:
210
0
        OS << "strict";
211
0
        break;
212
1
      }
213
1
      OS << ")\n";
214
1
    }
215
1
  }
216
26
  if (FPO.hasConstRoundingModeOverride()) {
217
3
    LangOptions::RoundingMode RM = FPO.getConstRoundingModeOverride();
218
3
    Indent() << "#pragma STDC FENV_ROUND ";
219
3
    switch (RM) {
220
1
    case llvm::RoundingMode::TowardZero:
221
1
      OS << "FE_TOWARDZERO";
222
1
      break;
223
0
    case llvm::RoundingMode::NearestTiesToEven:
224
0
      OS << "FE_TONEAREST";
225
0
      break;
226
1
    case llvm::RoundingMode::TowardPositive:
227
1
      OS << "FE_UPWARD";
228
1
      break;
229
1
    case llvm::RoundingMode::TowardNegative:
230
1
      OS << "FE_DOWNWARD";
231
1
      break;
232
0
    case llvm::RoundingMode::NearestTiesToAway:
233
0
      OS << "FE_TONEARESTFROMZERO";
234
0
      break;
235
0
    case llvm::RoundingMode::Dynamic:
236
0
      OS << "FE_DYNAMIC";
237
0
      break;
238
0
    default:
239
0
      llvm_unreachable("Invalid rounding mode");
240
3
    }
241
3
    OS << NL;
242
3
  }
243
26
}
244
245
31
void StmtPrinter::PrintRawDecl(Decl *D) {
246
31
  D->print(OS, Policy, IndentLevel);
247
31
}
248
249
15.9k
void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
250
15.9k
  SmallVector<Decl *, 2> Decls(S->decls());
251
15.9k
  Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
252
15.9k
}
253
254
608
void StmtPrinter::VisitNullStmt(NullStmt *Node) {
255
608
  Indent() << ";" << NL;
256
608
}
257
258
8.12k
void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
259
8.12k
  Indent();
260
8.12k
  PrintRawDeclStmt(Node);
261
8.12k
  OS << ";" << NL;
262
8.12k
}
263
264
1.92k
void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
265
1.92k
  Indent();
266
1.92k
  PrintRawCompoundStmt(Node);
267
1.92k
  OS << "" << NL;
268
1.92k
}
269
270
32
void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
271
32
  Indent(-1) << "case ";
272
32
  PrintExpr(Node->getLHS());
273
32
  if (Node->getRHS()) {
274
2
    OS << " ... ";
275
2
    PrintExpr(Node->getRHS());
276
2
  }
277
32
  OS << ":" << NL;
278
279
32
  PrintStmt(Node->getSubStmt(), 0);
280
32
}
281
282
18
void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
283
18
  Indent(-1) << "default:" << NL;
284
18
  PrintStmt(Node->getSubStmt(), 0);
285
18
}
286
287
8
void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
288
8
  Indent(-1) << Node->getName() << ":" << NL;
289
8
  PrintStmt(Node->getSubStmt(), 0);
290
8
}
291
292
26
void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
293
55
  for (const auto *Attr : Node->getAttrs()) {
294
55
    Attr->printPretty(OS, Policy);
295
55
  }
296
297
26
  PrintStmt(Node->getSubStmt(), 0);
298
26
}
299
300
283
void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
301
283
  if (If->isConsteval()) {
302
0
    OS << "if ";
303
0
    if (If->isNegatedConsteval())
304
0
      OS << "!";
305
0
    OS << "consteval";
306
0
    OS << NL;
307
0
    PrintStmt(If->getThen());
308
0
    if (Stmt *Else = If->getElse()) {
309
0
      Indent();
310
0
      OS << "else";
311
0
      PrintStmt(Else);
312
0
      OS << NL;
313
0
    }
314
0
    return;
315
0
  }
316
317
283
  OS << "if (";
318
283
  if (If->getInit())
319
0
    PrintInitStmt(If->getInit(), 4);
320
283
  if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
321
1
    PrintRawDeclStmt(DS);
322
282
  else
323
282
    PrintExpr(If->getCond());
324
283
  OS << ')';
325
326
283
  if (auto *CS = dyn_cast<CompoundStmt>(If->getThen())) {
327
176
    OS << ' ';
328
176
    PrintRawCompoundStmt(CS);
329
176
    OS << (If->getElse() ? 
" "4
:
NL172
);
330
176
  } else {
331
107
    OS << NL;
332
107
    PrintStmt(If->getThen());
333
107
    if (If->getElse()) 
Indent()0
;
334
107
  }
335
336
283
  if (Stmt *Else = If->getElse()) {
337
4
    OS << "else";
338
339
4
    if (auto *CS = dyn_cast<CompoundStmt>(Else)) {
340
2
      OS << ' ';
341
2
      PrintRawCompoundStmt(CS);
342
2
      OS << NL;
343
2
    } else if (auto *ElseIf = dyn_cast<IfStmt>(Else)) {
344
2
      OS << ' ';
345
2
      PrintRawIfStmt(ElseIf);
346
2
    } else {
347
0
      OS << NL;
348
0
      PrintStmt(If->getElse());
349
0
    }
350
4
  }
351
283
}
352
353
281
void StmtPrinter::VisitIfStmt(IfStmt *If) {
354
281
  Indent();
355
281
  PrintRawIfStmt(If);
356
281
}
357
358
26
void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
359
26
  Indent() << "switch (";
360
26
  if (Node->getInit())
361
0
    PrintInitStmt(Node->getInit(), 8);
362
26
  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
363
1
    PrintRawDeclStmt(DS);
364
25
  else
365
25
    PrintExpr(Node->getCond());
366
26
  OS << ")";
367
26
  PrintControlledStmt(Node->getBody());
368
26
}
369
370
22
void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
371
22
  Indent() << "while (";
372
22
  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
373
1
    PrintRawDeclStmt(DS);
374
21
  else
375
21
    PrintExpr(Node->getCond());
376
22
  OS << ")" << NL;
377
22
  PrintStmt(Node->getBody());
378
22
}
379
380
2
void StmtPrinter::VisitDoStmt(DoStmt *Node) {
381
2
  Indent() << "do ";
382
2
  if (auto *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
383
2
    PrintRawCompoundStmt(CS);
384
2
    OS << " ";
385
2
  } else {
386
0
    OS << NL;
387
0
    PrintStmt(Node->getBody());
388
0
    Indent();
389
0
  }
390
391
2
  OS << "while (";
392
2
  PrintExpr(Node->getCond());
393
2
  OS << ");" << NL;
394
2
}
395
396
7.95k
void StmtPrinter::VisitForStmt(ForStmt *Node) {
397
7.95k
  Indent() << "for (";
398
7.95k
  if (Node->getInit())
399
7.95k
    PrintInitStmt(Node->getInit(), 5);
400
2
  else
401
2
    OS << (Node->getCond() ? 
"; "0
: ";");
402
7.95k
  if (Node->getCond())
403
7.95k
    PrintExpr(Node->getCond());
404
7.95k
  OS << ";";
405
7.95k
  if (Node->getInc()) {
406
7.95k
    OS << " ";
407
7.95k
    PrintExpr(Node->getInc());
408
7.95k
  }
409
7.95k
  OS << ")";
410
7.95k
  PrintControlledStmt(Node->getBody());
411
7.95k
}
412
413
1
void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) {
414
1
  Indent() << "for (";
415
1
  if (auto *DS = dyn_cast<DeclStmt>(Node->getElement()))
416
1
    PrintRawDeclStmt(DS);
417
0
  else
418
0
    PrintExpr(cast<Expr>(Node->getElement()));
419
1
  OS << " in ";
420
1
  PrintExpr(Node->getCollection());
421
1
  OS << ")";
422
1
  PrintControlledStmt(Node->getBody());
423
1
}
424
425
33
void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
426
33
  Indent() << "for (";
427
33
  if (Node->getInit())
428
1
    PrintInitStmt(Node->getInit(), 5);
429
33
  PrintingPolicy SubPolicy(Policy);
430
33
  SubPolicy.SuppressInitializers = true;
431
33
  Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
432
33
  OS << " : ";
433
33
  PrintExpr(Node->getRangeInit());
434
33
  OS << ")";
435
33
  PrintControlledStmt(Node->getBody());
436
33
}
437
438
0
void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
439
0
  Indent();
440
0
  if (Node->isIfExists())
441
0
    OS << "__if_exists (";
442
0
  else
443
0
    OS << "__if_not_exists (";
444
445
0
  if (NestedNameSpecifier *Qualifier
446
0
        = Node->getQualifierLoc().getNestedNameSpecifier())
447
0
    Qualifier->print(OS, Policy);
448
449
0
  OS << Node->getNameInfo() << ") ";
450
451
0
  PrintRawCompoundStmt(Node->getSubStmt());
452
0
}
453
454
21
void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
455
21
  Indent() << "goto " << Node->getLabel()->getName() << ";";
456
21
  if (Policy.IncludeNewlines) 
OS << NL6
;
457
21
}
458
459
2
void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
460
2
  Indent() << "goto *";
461
2
  PrintExpr(Node->getTarget());
462
2
  OS << ";";
463
2
  if (Policy.IncludeNewlines) OS << NL;
464
2
}
465
466
21
void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
467
21
  Indent() << "continue;";
468
21
  if (Policy.IncludeNewlines) 
OS << NL2
;
469
21
}
470
471
116
void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
472
116
  Indent() << "break;";
473
116
  if (Policy.IncludeNewlines) 
OS << NL45
;
474
116
}
475
476
2.57k
void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
477
2.57k
  Indent() << "return";
478
2.57k
  if (Node->getRetValue()) {
479
2.46k
    OS << " ";
480
2.46k
    PrintExpr(Node->getRetValue());
481
2.46k
  }
482
2.57k
  OS << ";";
483
2.57k
  if (Policy.IncludeNewlines) OS << NL;
484
2.57k
}
485
486
15
void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
487
15
  Indent() << "asm ";
488
489
15
  if (Node->isVolatile())
490
1
    OS << "volatile ";
491
492
15
  if (Node->isAsmGoto())
493
10
    OS << "goto ";
494
495
15
  OS << "(";
496
15
  VisitStringLiteral(Node->getAsmString());
497
498
  // Outputs
499
15
  if (Node->getNumOutputs() != 0 || 
Node->getNumInputs() != 012
||
500
15
      
Node->getNumClobbers() != 04
||
Node->getNumLabels() != 04
)
501
13
    OS << " : ";
502
503
18
  for (unsigned i = 0, e = Node->getNumOutputs(); i != e; 
++i3
) {
504
3
    if (i != 0)
505
0
      OS << ", ";
506
507
3
    if (!Node->getOutputName(i).empty()) {
508
0
      OS << '[';
509
0
      OS << Node->getOutputName(i);
510
0
      OS << "] ";
511
0
    }
512
513
3
    VisitStringLiteral(Node->getOutputConstraintLiteral(i));
514
3
    OS << " (";
515
3
    Visit(Node->getOutputExpr(i));
516
3
    OS << ")";
517
3
  }
518
519
  // Inputs
520
15
  if (Node->getNumInputs() != 0 || 
Node->getNumClobbers() != 06
||
521
15
      
Node->getNumLabels() != 06
)
522
11
    OS << " : ";
523
524
25
  for (unsigned i = 0, e = Node->getNumInputs(); i != e; 
++i10
) {
525
10
    if (i != 0)
526
1
      OS << ", ";
527
528
10
    if (!Node->getInputName(i).empty()) {
529
0
      OS << '[';
530
0
      OS << Node->getInputName(i);
531
0
      OS << "] ";
532
0
    }
533
534
10
    VisitStringLiteral(Node->getInputConstraintLiteral(i));
535
10
    OS << " (";
536
10
    Visit(Node->getInputExpr(i));
537
10
    OS << ")";
538
10
  }
539
540
  // Clobbers
541
15
  if (Node->getNumClobbers() != 0 || Node->getNumLabels())
542
10
    OS << " : ";
543
544
15
  for (unsigned i = 0, e = Node->getNumClobbers(); i != e; 
++i0
) {
545
0
    if (i != 0)
546
0
      OS << ", ";
547
548
0
    VisitStringLiteral(Node->getClobberStringLiteral(i));
549
0
  }
550
551
  // Labels
552
15
  if (Node->getNumLabels() != 0)
553
10
    OS << " : ";
554
555
37
  for (unsigned i = 0, e = Node->getNumLabels(); i != e; 
++i22
) {
556
22
    if (i != 0)
557
12
      OS << ", ";
558
22
    OS << Node->getLabelName(i);
559
22
  }
560
561
15
  OS << ");";
562
15
  if (Policy.IncludeNewlines) 
OS << NL7
;
563
15
}
564
565
0
void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
566
  // FIXME: Implement MS style inline asm statement printer.
567
0
  Indent() << "__asm ";
568
0
  if (Node->hasBraces())
569
0
    OS << "{" << NL;
570
0
  OS << Node->getAsmString() << NL;
571
0
  if (Node->hasBraces())
572
0
    Indent() << "}" << NL;
573
0
}
574
575
0
void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
576
0
  PrintStmt(Node->getCapturedDecl()->getBody());
577
0
}
578
579
3
void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
580
3
  Indent() << "@try";
581
3
  if (auto *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
582
3
    PrintRawCompoundStmt(TS);
583
3
    OS << NL;
584
3
  }
585
586
8
  for (ObjCAtCatchStmt *catchStmt : Node->catch_stmts()) {
587
8
    Indent() << "@catch(";
588
8
    if (Decl *DS = catchStmt->getCatchParamDecl())
589
6
      PrintRawDecl(DS);
590
8
    OS << ")";
591
8
    if (auto *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
592
8
      PrintRawCompoundStmt(CS);
593
8
      OS << NL;
594
8
    }
595
8
  }
596
597
3
  if (auto *FS = static_cast<ObjCAtFinallyStmt *>(Node->getFinallyStmt())) {
598
3
    Indent() << "@finally";
599
3
    PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
600
3
    OS << NL;
601
3
  }
602
3
}
603
604
0
void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) {
605
0
}
606
607
0
void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
608
0
  Indent() << "@catch (...) { /* todo */ } " << NL;
609
0
}
610
611
2
void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
612
2
  Indent() << "@throw";
613
2
  if (Node->getThrowExpr()) {
614
1
    OS << " ";
615
1
    PrintExpr(Node->getThrowExpr());
616
1
  }
617
2
  OS << ";" << NL;
618
2
}
619
620
void StmtPrinter::VisitObjCAvailabilityCheckExpr(
621
0
    ObjCAvailabilityCheckExpr *Node) {
622
0
  OS << "@available(...)";
623
0
}
624
625
1
void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
626
1
  Indent() << "@synchronized (";
627
1
  PrintExpr(Node->getSynchExpr());
628
1
  OS << ")";
629
1
  PrintRawCompoundStmt(Node->getSynchBody());
630
1
  OS << NL;
631
1
}
632
633
0
void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
634
0
  Indent() << "@autoreleasepool";
635
0
  PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
636
0
  OS << NL;
637
0
}
638
639
8
void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
640
8
  OS << "catch (";
641
8
  if (Decl *ExDecl = Node->getExceptionDecl())
642
8
    PrintRawDecl(ExDecl);
643
0
  else
644
0
    OS << "...";
645
8
  OS << ") ";
646
8
  PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock()));
647
8
}
648
649
8
void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
650
8
  Indent();
651
8
  PrintRawCXXCatchStmt(Node);
652
8
  OS << NL;
653
8
}
654
655
0
void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
656
0
  Indent() << "try ";
657
0
  PrintRawCompoundStmt(Node->getTryBlock());
658
0
  for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) {
659
0
    OS << " ";
660
0
    PrintRawCXXCatchStmt(Node->getHandler(i));
661
0
  }
662
0
  OS << NL;
663
0
}
664
665
0
void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
666
0
  Indent() << (Node->getIsCXXTry() ? "try " : "__try ");
667
0
  PrintRawCompoundStmt(Node->getTryBlock());
668
0
  SEHExceptStmt *E = Node->getExceptHandler();
669
0
  SEHFinallyStmt *F = Node->getFinallyHandler();
670
0
  if(E)
671
0
    PrintRawSEHExceptHandler(E);
672
0
  else {
673
0
    assert(F && "Must have a finally block...");
674
0
    PrintRawSEHFinallyStmt(F);
675
0
  }
676
0
  OS << NL;
677
0
}
678
679
0
void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
680
0
  OS << "__finally ";
681
0
  PrintRawCompoundStmt(Node->getBlock());
682
0
  OS << NL;
683
0
}
684
685
0
void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
686
0
  OS << "__except (";
687
0
  VisitExpr(Node->getFilterExpr());
688
0
  OS << ")" << NL;
689
0
  PrintRawCompoundStmt(Node->getBlock());
690
0
  OS << NL;
691
0
}
692
693
0
void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
694
0
  Indent();
695
0
  PrintRawSEHExceptHandler(Node);
696
0
  OS << NL;
697
0
}
698
699
0
void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
700
0
  Indent();
701
0
  PrintRawSEHFinallyStmt(Node);
702
0
  OS << NL;
703
0
}
704
705
0
void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
706
0
  Indent() << "__leave;";
707
0
  if (Policy.IncludeNewlines) OS << NL;
708
0
}
709
710
//===----------------------------------------------------------------------===//
711
//  OpenMP directives printing methods
712
//===----------------------------------------------------------------------===//
713
714
0
void StmtPrinter::VisitOMPCanonicalLoop(OMPCanonicalLoop *Node) {
715
0
  PrintStmt(Node->getLoopStmt());
716
0
}
717
718
void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S,
719
15.3k
                                              bool ForceNoStmt) {
720
15.3k
  OMPClausePrinter Printer(OS, Policy);
721
15.3k
  ArrayRef<OMPClause *> Clauses = S->clauses();
722
15.3k
  for (auto *Clause : Clauses)
723
32.9k
    if (Clause && !Clause->isImplicit()) {
724
31.8k
      OS << ' ';
725
31.8k
      Printer.Visit(Clause);
726
31.8k
    }
727
15.3k
  OS << NL;
728
15.3k
  if (!ForceNoStmt && 
S->hasAssociatedStmt()13.0k
)
729
12.4k
    PrintStmt(S->getRawStmt());
730
15.3k
}
731
732
0
void StmtPrinter::VisitOMPMetaDirective(OMPMetaDirective *Node) {
733
0
  Indent() << "#pragma omp metadirective";
734
0
  PrintOMPExecutableDirective(Node);
735
0
}
736
737
707
void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
738
707
  Indent() << "#pragma omp parallel";
739
707
  PrintOMPExecutableDirective(Node);
740
707
}
741
742
119
void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) {
743
119
  Indent() << "#pragma omp simd";
744
119
  PrintOMPExecutableDirective(Node);
745
119
}
746
747
18
void StmtPrinter::VisitOMPTileDirective(OMPTileDirective *Node) {
748
18
  Indent() << "#pragma omp tile";
749
18
  PrintOMPExecutableDirective(Node);
750
18
}
751
752
18
void StmtPrinter::VisitOMPUnrollDirective(OMPUnrollDirective *Node) {
753
18
  Indent() << "#pragma omp unroll";
754
18
  PrintOMPExecutableDirective(Node);
755
18
}
756
757
294
void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
758
294
  Indent() << "#pragma omp for";
759
294
  PrintOMPExecutableDirective(Node);
760
294
}
761
762
121
void StmtPrinter::VisitOMPForSimdDirective(OMPForSimdDirective *Node) {
763
121
  Indent() << "#pragma omp for simd";
764
121
  PrintOMPExecutableDirective(Node);
765
121
}
766
767
28
void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
768
28
  Indent() << "#pragma omp sections";
769
28
  PrintOMPExecutableDirective(Node);
770
28
}
771
772
28
void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
773
28
  Indent() << "#pragma omp section";
774
28
  PrintOMPExecutableDirective(Node);
775
28
}
776
777
49
void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
778
49
  Indent() << "#pragma omp single";
779
49
  PrintOMPExecutableDirective(Node);
780
49
}
781
782
5
void StmtPrinter::VisitOMPMasterDirective(OMPMasterDirective *Node) {
783
5
  Indent() << "#pragma omp master";
784
5
  PrintOMPExecutableDirective(Node);
785
5
}
786
787
33
void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) {
788
33
  Indent() << "#pragma omp critical";
789
33
  if (Node->getDirectiveName().getName()) {
790
12
    OS << " (";
791
12
    Node->getDirectiveName().printName(OS, Policy);
792
12
    OS << ")";
793
12
  }
794
33
  PrintOMPExecutableDirective(Node);
795
33
}
796
797
87
void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) {
798
87
  Indent() << "#pragma omp parallel for";
799
87
  PrintOMPExecutableDirective(Node);
800
87
}
801
802
void StmtPrinter::VisitOMPParallelForSimdDirective(
803
117
    OMPParallelForSimdDirective *Node) {
804
117
  Indent() << "#pragma omp parallel for simd";
805
117
  PrintOMPExecutableDirective(Node);
806
117
}
807
808
void StmtPrinter::VisitOMPParallelMasterDirective(
809
128
    OMPParallelMasterDirective *Node) {
810
128
  Indent() << "#pragma omp parallel master";
811
128
  PrintOMPExecutableDirective(Node);
812
128
}
813
814
void StmtPrinter::VisitOMPParallelMaskedDirective(
815
129
    OMPParallelMaskedDirective *Node) {
816
129
  Indent() << "#pragma omp parallel masked";
817
129
  PrintOMPExecutableDirective(Node);
818
129
}
819
820
void StmtPrinter::VisitOMPParallelSectionsDirective(
821
45
    OMPParallelSectionsDirective *Node) {
822
45
  Indent() << "#pragma omp parallel sections";
823
45
  PrintOMPExecutableDirective(Node);
824
45
}
825
826
101
void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) {
827
101
  Indent() << "#pragma omp task";
828
101
  PrintOMPExecutableDirective(Node);
829
101
}
830
831
16
void StmtPrinter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *Node) {
832
16
  Indent() << "#pragma omp taskyield";
833
16
  PrintOMPExecutableDirective(Node);
834
16
}
835
836
64
void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) {
837
64
  Indent() << "#pragma omp barrier";
838
64
  PrintOMPExecutableDirective(Node);
839
64
}
840
841
32
void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) {
842
32
  Indent() << "#pragma omp taskwait";
843
32
  PrintOMPExecutableDirective(Node);
844
32
}
845
846
297
void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) {
847
297
  Indent() << "#pragma omp taskgroup";
848
297
  PrintOMPExecutableDirective(Node);
849
297
}
850
851
80
void StmtPrinter::VisitOMPFlushDirective(OMPFlushDirective *Node) {
852
80
  Indent() << "#pragma omp flush";
853
80
  PrintOMPExecutableDirective(Node);
854
80
}
855
856
44
void StmtPrinter::VisitOMPDepobjDirective(OMPDepobjDirective *Node) {
857
44
  Indent() << "#pragma omp depobj";
858
44
  PrintOMPExecutableDirective(Node);
859
44
}
860
861
16
void StmtPrinter::VisitOMPScanDirective(OMPScanDirective *Node) {
862
16
  Indent() << "#pragma omp scan";
863
16
  PrintOMPExecutableDirective(Node);
864
16
}
865
866
85
void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
867
85
  Indent() << "#pragma omp ordered";
868
85
  PrintOMPExecutableDirective(Node, Node->hasClausesOfKind<OMPDependClause>());
869
85
}
870
871
1.51k
void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) {
872
1.51k
  Indent() << "#pragma omp atomic";
873
1.51k
  PrintOMPExecutableDirective(Node);
874
1.51k
}
875
876
3.38k
void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) {
877
3.38k
  Indent() << "#pragma omp target";
878
3.38k
  PrintOMPExecutableDirective(Node);
879
3.38k
}
880
881
400
void StmtPrinter::VisitOMPTargetDataDirective(OMPTargetDataDirective *Node) {
882
400
  Indent() << "#pragma omp target data";
883
400
  PrintOMPExecutableDirective(Node);
884
400
}
885
886
void StmtPrinter::VisitOMPTargetEnterDataDirective(
887
768
    OMPTargetEnterDataDirective *Node) {
888
768
  Indent() << "#pragma omp target enter data";
889
768
  PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
890
768
}
891
892
void StmtPrinter::VisitOMPTargetExitDataDirective(
893
832
    OMPTargetExitDataDirective *Node) {
894
832
  Indent() << "#pragma omp target exit data";
895
832
  PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
896
832
}
897
898
void StmtPrinter::VisitOMPTargetParallelDirective(
899
345
    OMPTargetParallelDirective *Node) {
900
345
  Indent() << "#pragma omp target parallel";
901
345
  PrintOMPExecutableDirective(Node);
902
345
}
903
904
void StmtPrinter::VisitOMPTargetParallelForDirective(
905
385
    OMPTargetParallelForDirective *Node) {
906
385
  Indent() << "#pragma omp target parallel for";
907
385
  PrintOMPExecutableDirective(Node);
908
385
}
909
910
481
void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {
911
481
  Indent() << "#pragma omp teams";
912
481
  PrintOMPExecutableDirective(Node);
913
481
}
914
915
void StmtPrinter::VisitOMPCancellationPointDirective(
916
100
    OMPCancellationPointDirective *Node) {
917
100
  Indent() << "#pragma omp cancellation point "
918
100
           << getOpenMPDirectiveName(Node->getCancelRegion());
919
100
  PrintOMPExecutableDirective(Node);
920
100
}
921
922
124
void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
923
124
  Indent() << "#pragma omp cancel "
924
124
           << getOpenMPDirectiveName(Node->getCancelRegion());
925
124
  PrintOMPExecutableDirective(Node);
926
124
}
927
928
33
void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) {
929
33
  Indent() << "#pragma omp taskloop";
930
33
  PrintOMPExecutableDirective(Node);
931
33
}
932
933
void StmtPrinter::VisitOMPTaskLoopSimdDirective(
934
65
    OMPTaskLoopSimdDirective *Node) {
935
65
  Indent() << "#pragma omp taskloop simd";
936
65
  PrintOMPExecutableDirective(Node);
937
65
}
938
939
void StmtPrinter::VisitOMPMasterTaskLoopDirective(
940
32
    OMPMasterTaskLoopDirective *Node) {
941
32
  Indent() << "#pragma omp master taskloop";
942
32
  PrintOMPExecutableDirective(Node);
943
32
}
944
945
void StmtPrinter::VisitOMPMaskedTaskLoopDirective(
946
33
    OMPMaskedTaskLoopDirective *Node) {
947
33
  Indent() << "#pragma omp masked taskloop";
948
33
  PrintOMPExecutableDirective(Node);
949
33
}
950
951
void StmtPrinter::VisitOMPMasterTaskLoopSimdDirective(
952
64
    OMPMasterTaskLoopSimdDirective *Node) {
953
64
  Indent() << "#pragma omp master taskloop simd";
954
64
  PrintOMPExecutableDirective(Node);
955
64
}
956
957
void StmtPrinter::VisitOMPMaskedTaskLoopSimdDirective(
958
65
    OMPMaskedTaskLoopSimdDirective *Node) {
959
65
  Indent() << "#pragma omp masked taskloop simd";
960
65
  PrintOMPExecutableDirective(Node);
961
65
}
962
963
void StmtPrinter::VisitOMPParallelMasterTaskLoopDirective(
964
32
    OMPParallelMasterTaskLoopDirective *Node) {
965
32
  Indent() << "#pragma omp parallel master taskloop";
966
32
  PrintOMPExecutableDirective(Node);
967
32
}
968
969
void StmtPrinter::VisitOMPParallelMaskedTaskLoopDirective(
970
33
    OMPParallelMaskedTaskLoopDirective *Node) {
971
33
  Indent() << "#pragma omp parallel masked taskloop";
972
33
  PrintOMPExecutableDirective(Node);
973
33
}
974
975
void StmtPrinter::VisitOMPParallelMasterTaskLoopSimdDirective(
976
64
    OMPParallelMasterTaskLoopSimdDirective *Node) {
977
64
  Indent() << "#pragma omp parallel master taskloop simd";
978
64
  PrintOMPExecutableDirective(Node);
979
64
}
980
981
void StmtPrinter::VisitOMPParallelMaskedTaskLoopSimdDirective(
982
65
    OMPParallelMaskedTaskLoopSimdDirective *Node) {
983
65
  Indent() << "#pragma omp parallel masked taskloop simd";
984
65
  PrintOMPExecutableDirective(Node);
985
65
}
986
987
124
void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) {
988
124
  Indent() << "#pragma omp distribute";
989
124
  PrintOMPExecutableDirective(Node);
990
124
}
991
992
void StmtPrinter::VisitOMPTargetUpdateDirective(
993
689
    OMPTargetUpdateDirective *Node) {
994
689
  Indent() << "#pragma omp target update";
995
689
  PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true);
996
689
}
997
998
void StmtPrinter::VisitOMPDistributeParallelForDirective(
999
121
    OMPDistributeParallelForDirective *Node) {
1000
121
  Indent() << "#pragma omp distribute parallel for";
1001
121
  PrintOMPExecutableDirective(Node);
1002
121
}
1003
1004
void StmtPrinter::VisitOMPDistributeParallelForSimdDirective(
1005
113
    OMPDistributeParallelForSimdDirective *Node) {
1006
113
  Indent() << "#pragma omp distribute parallel for simd";
1007
113
  PrintOMPExecutableDirective(Node);
1008
113
}
1009
1010
void StmtPrinter::VisitOMPDistributeSimdDirective(
1011
113
    OMPDistributeSimdDirective *Node) {
1012
113
  Indent() << "#pragma omp distribute simd";
1013
113
  PrintOMPExecutableDirective(Node);
1014
113
}
1015
1016
void StmtPrinter::VisitOMPTargetParallelForSimdDirective(
1017
589
    OMPTargetParallelForSimdDirective *Node) {
1018
589
  Indent() << "#pragma omp target parallel for simd";
1019
589
  PrintOMPExecutableDirective(Node);
1020
589
}
1021
1022
450
void StmtPrinter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *Node) {
1023
450
  Indent() << "#pragma omp target simd";
1024
450
  PrintOMPExecutableDirective(Node);
1025
450
}
1026
1027
void StmtPrinter::VisitOMPTeamsDistributeDirective(
1028
60
    OMPTeamsDistributeDirective *Node) {
1029
60
  Indent() << "#pragma omp teams distribute";
1030
60
  PrintOMPExecutableDirective(Node);
1031
60
}
1032
1033
void StmtPrinter::VisitOMPTeamsDistributeSimdDirective(
1034
169
    OMPTeamsDistributeSimdDirective *Node) {
1035
169
  Indent() << "#pragma omp teams distribute simd";
1036
169
  PrintOMPExecutableDirective(Node);
1037
169
}
1038
1039
void StmtPrinter::VisitOMPTeamsDistributeParallelForSimdDirective(
1040
169
    OMPTeamsDistributeParallelForSimdDirective *Node) {
1041
169
  Indent() << "#pragma omp teams distribute parallel for simd";
1042
169
  PrintOMPExecutableDirective(Node);
1043
169
}
1044
1045
void StmtPrinter::VisitOMPTeamsDistributeParallelForDirective(
1046
69
    OMPTeamsDistributeParallelForDirective *Node) {
1047
69
  Indent() << "#pragma omp teams distribute parallel for";
1048
69
  PrintOMPExecutableDirective(Node);
1049
69
}
1050
1051
193
void StmtPrinter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *Node) {
1052
193
  Indent() << "#pragma omp target teams";
1053
193
  PrintOMPExecutableDirective(Node);
1054
193
}
1055
1056
void StmtPrinter::VisitOMPTargetTeamsDistributeDirective(
1057
61
    OMPTargetTeamsDistributeDirective *Node) {
1058
61
  Indent() << "#pragma omp target teams distribute";
1059
61
  PrintOMPExecutableDirective(Node);
1060
61
}
1061
1062
void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForDirective(
1063
213
    OMPTargetTeamsDistributeParallelForDirective *Node) {
1064
213
  Indent() << "#pragma omp target teams distribute parallel for";
1065
213
  PrintOMPExecutableDirective(Node);
1066
213
}
1067
1068
void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1069
225
    OMPTargetTeamsDistributeParallelForSimdDirective *Node) {
1070
225
  Indent() << "#pragma omp target teams distribute parallel for simd";
1071
225
  PrintOMPExecutableDirective(Node);
1072
225
}
1073
1074
void StmtPrinter::VisitOMPTargetTeamsDistributeSimdDirective(
1075
309
    OMPTargetTeamsDistributeSimdDirective *Node) {
1076
309
  Indent() << "#pragma omp target teams distribute simd";
1077
309
  PrintOMPExecutableDirective(Node);
1078
309
}
1079
1080
56
void StmtPrinter::VisitOMPInteropDirective(OMPInteropDirective *Node) {
1081
56
  Indent() << "#pragma omp interop";
1082
56
  PrintOMPExecutableDirective(Node);
1083
56
}
1084
1085
42
void StmtPrinter::VisitOMPDispatchDirective(OMPDispatchDirective *Node) {
1086
42
  Indent() << "#pragma omp dispatch";
1087
42
  PrintOMPExecutableDirective(Node);
1088
42
}
1089
1090
12
void StmtPrinter::VisitOMPMaskedDirective(OMPMaskedDirective *Node) {
1091
12
  Indent() << "#pragma omp masked";
1092
12
  PrintOMPExecutableDirective(Node);
1093
12
}
1094
1095
16
void StmtPrinter::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *Node) {
1096
16
  Indent() << "#pragma omp loop";
1097
16
  PrintOMPExecutableDirective(Node);
1098
16
}
1099
1100
void StmtPrinter::VisitOMPTeamsGenericLoopDirective(
1101
15
    OMPTeamsGenericLoopDirective *Node) {
1102
15
  Indent() << "#pragma omp teams loop";
1103
15
  PrintOMPExecutableDirective(Node);
1104
15
}
1105
1106
void StmtPrinter::VisitOMPTargetTeamsGenericLoopDirective(
1107
20
    OMPTargetTeamsGenericLoopDirective *Node) {
1108
20
  Indent() << "#pragma omp target teams loop";
1109
20
  PrintOMPExecutableDirective(Node);
1110
20
}
1111
1112
void StmtPrinter::VisitOMPParallelGenericLoopDirective(
1113
17
    OMPParallelGenericLoopDirective *Node) {
1114
17
  Indent() << "#pragma omp parallel loop";
1115
17
  PrintOMPExecutableDirective(Node);
1116
17
}
1117
1118
void StmtPrinter::VisitOMPTargetParallelGenericLoopDirective(
1119
20
    OMPTargetParallelGenericLoopDirective *Node) {
1120
20
  Indent() << "#pragma omp target parallel loop";
1121
20
  PrintOMPExecutableDirective(Node);
1122
20
}
1123
1124
//===----------------------------------------------------------------------===//
1125
//  Expr printing methods.
1126
//===----------------------------------------------------------------------===//
1127
1128
8
void StmtPrinter::VisitSourceLocExpr(SourceLocExpr *Node) {
1129
8
  OS << Node->getBuiltinStr() << "()";
1130
8
}
1131
1132
8.78k
void StmtPrinter::VisitConstantExpr(ConstantExpr *Node) {
1133
8.78k
  PrintExpr(Node->getSubExpr());
1134
8.78k
}
1135
1136
79.9k
void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
1137
79.9k
  if (const auto *OCED = dyn_cast<OMPCapturedExprDecl>(Node->getDecl())) {
1138
3.58k
    OCED->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy);
1139
3.58k
    return;
1140
3.58k
  }
1141
76.3k
  if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(Node->getDecl())) {
1142
4
    TPOD->printAsExpr(OS, Policy);
1143
4
    return;
1144
4
  }
1145
76.3k
  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1146
250
    Qualifier->print(OS, Policy);
1147
76.3k
  if (Node->hasTemplateKeyword())
1148
2
    OS << "template ";
1149
76.3k
  if (Policy.CleanUglifiedParameters &&
1150
76.3k
      
isa<ParmVarDecl, NonTypeTemplateParmDecl>(Node->getDecl())2
&&
1151
76.3k
      
Node->getDecl()->getIdentifier()2
)
1152
2
    OS << Node->getDecl()->getIdentifier()->deuglifiedName();
1153
76.3k
  else
1154
76.3k
    Node->getNameInfo().printName(OS, Policy);
1155
76.3k
  if (Node->hasExplicitTemplateArgs()) {
1156
1.24k
    const TemplateParameterList *TPL = nullptr;
1157
1.24k
    if (!Node->hadMultipleCandidates())
1158
1.22k
      if (auto *TD = dyn_cast<TemplateDecl>(Node->getDecl()))
1159
0
        TPL = TD->getTemplateParameters();
1160
1.24k
    printTemplateArgumentList(OS, Node->template_arguments(), Policy, TPL);
1161
1.24k
  }
1162
76.3k
}
1163
1164
void StmtPrinter::VisitDependentScopeDeclRefExpr(
1165
183
                                           DependentScopeDeclRefExpr *Node) {
1166
183
  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1167
183
    Qualifier->print(OS, Policy);
1168
183
  if (Node->hasTemplateKeyword())
1169
8
    OS << "template ";
1170
183
  OS << Node->getNameInfo();
1171
183
  if (Node->hasExplicitTemplateArgs())
1172
6
    printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1173
183
}
1174
1175
104
void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
1176
104
  if (Node->getQualifier())
1177
46
    Node->getQualifier()->print(OS, Policy);
1178
104
  if (Node->hasTemplateKeyword())
1179
5
    OS << "template ";
1180
104
  OS << Node->getNameInfo();
1181
104
  if (Node->hasExplicitTemplateArgs())
1182
60
    printTemplateArgumentList(OS, Node->template_arguments(), Policy);
1183
104
}
1184
1185
1
static bool isImplicitSelf(const Expr *E) {
1186
1
  if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
1187
1
    if (const auto *PD = dyn_cast<ImplicitParamDecl>(DRE->getDecl())) {
1188
1
      if (PD->getParameterKind() == ImplicitParamDecl::ObjCSelf &&
1189
1
          DRE->getBeginLoc().isInvalid())
1190
1
        return true;
1191
1
    }
1192
1
  }
1193
0
  return false;
1194
1
}
1195
1196
28
void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
1197
28
  if (Node->getBase()) {
1198
28
    if (!Policy.SuppressImplicitBase ||
1199
28
        
!isImplicitSelf(Node->getBase()->IgnoreImpCasts())1
) {
1200
27
      PrintExpr(Node->getBase());
1201
27
      OS << (Node->isArrow() ? 
"->"25
:
"."2
);
1202
27
    }
1203
28
  }
1204
28
  OS << *Node->getDecl();
1205
28
}
1206
1207
5
void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
1208
5
  if (Node->isSuperReceiver())
1209
1
    OS << "super.";
1210
4
  else if (Node->isObjectReceiver() && 
Node->getBase()1
) {
1211
1
    PrintExpr(Node->getBase());
1212
1
    OS << ".";
1213
3
  } else if (Node->isClassReceiver() && Node->getClassReceiver()) {
1214
3
    OS << Node->getClassReceiver()->getName() << ".";
1215
3
  }
1216
1217
5
  if (Node->isImplicitProperty()) {
1218
4
    if (const auto *Getter = Node->getImplicitPropertyGetter())
1219
3
      Getter->getSelector().print(OS);
1220
1
    else
1221
1
      OS << SelectorTable::getPropertyNameFromSetterSelector(
1222
1
          Node->getImplicitPropertySetter()->getSelector());
1223
4
  } else
1224
1
    OS << Node->getExplicitProperty()->getName();
1225
5
}
1226
1227
4
void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
1228
4
  PrintExpr(Node->getBaseExpr());
1229
4
  OS << "[";
1230
4
  PrintExpr(Node->getKeyExpr());
1231
4
  OS << "]";
1232
4
}
1233
1234
void StmtPrinter::VisitSYCLUniqueStableNameExpr(
1235
6
    SYCLUniqueStableNameExpr *Node) {
1236
6
  OS << "__builtin_sycl_unique_stable_name(";
1237
6
  Node->getTypeSourceInfo()->getType().print(OS, Policy);
1238
6
  OS << ")";
1239
6
}
1240
1241
15
void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
1242
15
  OS << PredefinedExpr::getIdentKindName(Node->getIdentKind());
1243
15
}
1244
1245
446
void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
1246
446
  CharacterLiteral::print(Node->getValue(), Node->getKind(), OS);
1247
446
}
1248
1249
/// Prints the given expression using the original source text. Returns true on
1250
/// success, false otherwise.
1251
static bool printExprAsWritten(raw_ostream &OS, Expr *E,
1252
14
                               const ASTContext *Context) {
1253
14
  if (!Context)
1254
2
    return false;
1255
12
  bool Invalid = false;
1256
12
  StringRef Source = Lexer::getSourceText(
1257
12
      CharSourceRange::getTokenRange(E->getSourceRange()),
1258
12
      Context->getSourceManager(), Context->getLangOpts(), &Invalid);
1259
12
  if (!Invalid) {
1260
11
    OS << Source;
1261
11
    return true;
1262
11
  }
1263
1
  return false;
1264
12
}
1265
1266
32.8k
void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
1267
32.8k
  if (Policy.ConstantsAsWritten && 
printExprAsWritten(OS, Node, Context)13
)
1268
10
    return;
1269
32.8k
  bool isSigned = Node->getType()->isSignedIntegerType();
1270
32.8k
  OS << toString(Node->getValue(), 10, isSigned);
1271
1272
32.8k
  if (isa<BitIntType>(Node->getType())) {
1273
28
    OS << (isSigned ? 
"wb"16
:
"uwb"12
);
1274
28
    return;
1275
28
  }
1276
1277
  // Emit suffixes.  Integer literals are always a builtin integer type.
1278
32.8k
  switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
1279
0
  default: llvm_unreachable("Unexpected type for integer literal!");
1280
2
  case BuiltinType::Char_S:
1281
2
  case BuiltinType::Char_U:    OS << "i8"; break;
1282
1
  case BuiltinType::UChar:     OS << "Ui8"; break;
1283
2
  case BuiltinType::Short:     OS << "i16"; break;
1284
1
  case BuiltinType::UShort:    OS << "Ui16"; break;
1285
31.1k
  case BuiltinType::Int:       break; // no suffix.
1286
165
  case BuiltinType::UInt:      OS << 'U'; break;
1287
29
  case BuiltinType::Long:      OS << 'L'; break;
1288
1.51k
  case BuiltinType::ULong:     OS << "UL"; break;
1289
8
  case BuiltinType::LongLong:  OS << "LL"; break;
1290
2
  case BuiltinType::ULongLong: OS << "ULL"; break;
1291
0
  case BuiltinType::Int128:
1292
0
    break; // no suffix.
1293
2
  case BuiltinType::UInt128:
1294
2
    break; // no suffix.
1295
32.8k
  }
1296
32.8k
}
1297
1298
14
void StmtPrinter::VisitFixedPointLiteral(FixedPointLiteral *Node) {
1299
14
  if (Policy.ConstantsAsWritten && 
printExprAsWritten(OS, Node, Context)0
)
1300
0
    return;
1301
14
  OS << Node->getValueAsString(/*Radix=*/10);
1302
1303
14
  switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
1304
0
    default: llvm_unreachable("Unexpected type for fixed point literal!");
1305
0
    case BuiltinType::ShortFract:   OS << "hr"; break;
1306
0
    case BuiltinType::ShortAccum:   OS << "hk"; break;
1307
0
    case BuiltinType::UShortFract:  OS << "uhr"; break;
1308
0
    case BuiltinType::UShortAccum:  OS << "uhk"; break;
1309
8
    case BuiltinType::Fract:        OS << "r"; break;
1310
4
    case BuiltinType::Accum:        OS << "k"; break;
1311
0
    case BuiltinType::UFract:       OS << "ur"; break;
1312
0
    case BuiltinType::UAccum:       OS << "uk"; break;
1313
0
    case BuiltinType::LongFract:    OS << "lr"; break;
1314
2
    case BuiltinType::LongAccum:    OS << "lk"; break;
1315
0
    case BuiltinType::ULongFract:   OS << "ulr"; break;
1316
0
    case BuiltinType::ULongAccum:   OS << "ulk"; break;
1317
14
  }
1318
14
}
1319
1320
static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
1321
157
                                 bool PrintSuffix) {
1322
157
  SmallString<16> Str;
1323
157
  Node->getValue().toString(Str);
1324
157
  OS << Str;
1325
157
  if (Str.find_first_not_of("-0123456789") == StringRef::npos)
1326
114
    OS << '.'; // Trailing dot in order to separate from ints.
1327
1328
157
  if (!PrintSuffix)
1329
2
    return;
1330
1331
  // Emit suffixes.  Float literals are always a builtin float type.
1332
155
  switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
1333
0
  default: llvm_unreachable("Unexpected type for float literal!");
1334
0
  case BuiltinType::Half:       break; // FIXME: suffix?
1335
0
  case BuiltinType::Ibm128:     break; // FIXME: No suffix for ibm128 literal
1336
123
  case BuiltinType::Double:     break; // no suffix.
1337
0
  case BuiltinType::Float16:    OS << "F16"; break;
1338
21
  case BuiltinType::Float:      OS << 'F'; break;
1339
11
  case BuiltinType::LongDouble: OS << 'L'; break;
1340
0
  case BuiltinType::Float128:   OS << 'Q'; break;
1341
155
  }
1342
155
}
1343
1344
156
void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) {
1345
156
  if (Policy.ConstantsAsWritten && 
printExprAsWritten(OS, Node, Context)1
)
1346
1
    return;
1347
155
  PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true);
1348
155
}
1349
1350
22
void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {
1351
22
  PrintExpr(Node->getSubExpr());
1352
22
  OS << "i";
1353
22
}
1354
1355
802
void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
1356
802
  Str->outputString(OS);
1357
802
}
1358
1359
3.80k
void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
1360
3.80k
  OS << "(";
1361
3.80k
  PrintExpr(Node->getSubExpr());
1362
3.80k
  OS << ")";
1363
3.80k
}
1364
1365
51.8k
void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
1366
51.8k
  if (!Node->isPostfix()) {
1367
49.7k
    OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1368
1369
    // Print a space if this is an "identifier operator" like __real, or if
1370
    // it might be concatenated incorrectly like '+'.
1371
49.7k
    switch (Node->getOpcode()) {
1372
49.5k
    default: break;
1373
49.5k
    case UO_Real:
1374
6
    case UO_Imag:
1375
8
    case UO_Extension:
1376
8
      OS << ' ';
1377
8
      break;
1378
11
    case UO_Plus:
1379
143
    case UO_Minus:
1380
143
      if (isa<UnaryOperator>(Node->getSubExpr()))
1381
0
        OS << ' ';
1382
143
      break;
1383
49.7k
    }
1384
49.7k
  }
1385
51.8k
  PrintExpr(Node->getSubExpr());
1386
1387
51.8k
  if (Node->isPostfix())
1388
2.15k
    OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
1389
51.8k
}
1390
1391
2
void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
1392
2
  OS << "__builtin_offsetof(";
1393
2
  Node->getTypeSourceInfo()->getType().print(OS, Policy);
1394
2
  OS << ", ";
1395
2
  bool PrintedSomething = false;
1396
4
  for (unsigned i = 0, n = Node->getNumComponents(); i < n; 
++i2
) {
1397
2
    OffsetOfNode ON = Node->getComponent(i);
1398
2
    if (ON.getKind() == OffsetOfNode::Array) {
1399
      // Array node
1400
0
      OS << "[";
1401
0
      PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex()));
1402
0
      OS << "]";
1403
0
      PrintedSomething = true;
1404
0
      continue;
1405
0
    }
1406
1407
    // Skip implicit base indirections.
1408
2
    if (ON.getKind() == OffsetOfNode::Base)
1409
0
      continue;
1410
1411
    // Field or identifier node.
1412
2
    IdentifierInfo *Id = ON.getFieldName();
1413
2
    if (!Id)
1414
0
      continue;
1415
1416
2
    if (PrintedSomething)
1417
0
      OS << ".";
1418
2
    else
1419
2
      PrintedSomething = true;
1420
2
    OS << Id->getName();
1421
2
  }
1422
2
  OS << ")";
1423
2
}
1424
1425
void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(
1426
686
    UnaryExprOrTypeTraitExpr *Node) {
1427
686
  const char *Spelling = getTraitSpelling(Node->getKind());
1428
686
  if (Node->getKind() == UETT_AlignOf) {
1429
15
    if (Policy.Alignof)
1430
15
      Spelling = "alignof";
1431
0
    else if (Policy.UnderscoreAlignof)
1432
0
      Spelling = "_Alignof";
1433
0
    else
1434
0
      Spelling = "__alignof";
1435
15
  }
1436
1437
686
  OS << Spelling;
1438
1439
686
  if (Node->isArgumentType()) {
1440
535
    OS << '(';
1441
535
    Node->getArgumentType().print(OS, Policy);
1442
535
    OS << ')';
1443
535
  } else {
1444
151
    OS << " ";
1445
151
    PrintExpr(Node->getArgumentExpr());
1446
151
  }
1447
686
}
1448
1449
4
void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) {
1450
4
  OS << "_Generic(";
1451
4
  PrintExpr(Node->getControllingExpr());
1452
8
  for (const GenericSelectionExpr::Association Assoc : Node->associations()) {
1453
8
    OS << ", ";
1454
8
    QualType T = Assoc.getType();
1455
8
    if (T.isNull())
1456
0
      OS << "default";
1457
8
    else
1458
8
      T.print(OS, Policy);
1459
8
    OS << ": ";
1460
8
    PrintExpr(Assoc.getAssociationExpr());
1461
8
  }
1462
4
  OS << ")";
1463
4
}
1464
1465
2.42k
void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) {
1466
2.42k
  PrintExpr(Node->getLHS());
1467
2.42k
  OS << "[";
1468
2.42k
  PrintExpr(Node->getRHS());
1469
2.42k
  OS << "]";
1470
2.42k
}
1471
1472
0
void StmtPrinter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *Node) {
1473
0
  PrintExpr(Node->getBase());
1474
0
  OS << "[";
1475
0
  PrintExpr(Node->getRowIdx());
1476
0
  OS << "]";
1477
0
  OS << "[";
1478
0
  PrintExpr(Node->getColumnIdx());
1479
0
  OS << "]";
1480
0
}
1481
1482
3.94k
void StmtPrinter::VisitOMPArraySectionExpr(OMPArraySectionExpr *Node) {
1483
3.94k
  PrintExpr(Node->getBase());
1484
3.94k
  OS << "[";
1485
3.94k
  if (Node->getLowerBound())
1486
1.98k
    PrintExpr(Node->getLowerBound());
1487
3.94k
  if (Node->getColonLocFirst().isValid()) {
1488
3.89k
    OS << ":";
1489
3.89k
    if (Node->getLength())
1490
2.88k
      PrintExpr(Node->getLength());
1491
3.89k
  }
1492
3.94k
  if (Node->getColonLocSecond().isValid()) {
1493
200
    OS << ":";
1494
200
    if (Node->getStride())
1495
152
      PrintExpr(Node->getStride());
1496
200
  }
1497
3.94k
  OS << "]";
1498
3.94k
}
1499
1500
96
void StmtPrinter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *Node) {
1501
96
  OS << "(";
1502
208
  for (Expr *E : Node->getDimensions()) {
1503
208
    OS << "[";
1504
208
    PrintExpr(E);
1505
208
    OS << "]";
1506
208
  }
1507
96
  OS << ")";
1508
96
  PrintExpr(Node->getBase());
1509
96
}
1510
1511
32
void StmtPrinter::VisitOMPIteratorExpr(OMPIteratorExpr *Node) {
1512
32
  OS << "iterator(";
1513
84
  for (unsigned I = 0, E = Node->numOfIterators(); I < E; 
++I52
) {
1514
52
    auto *VD = cast<ValueDecl>(Node->getIteratorDecl(I));
1515
52
    VD->getType().print(OS, Policy);
1516
52
    const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I);
1517
52
    OS << " " << VD->getName() << " = ";
1518
52
    PrintExpr(Range.Begin);
1519
52
    OS << ":";
1520
52
    PrintExpr(Range.End);
1521
52
    if (Range.Step) {
1522
20
      OS << ":";
1523
20
      PrintExpr(Range.Step);
1524
20
    }
1525
52
    if (I < E - 1)
1526
20
      OS << ", ";
1527
52
  }
1528
32
  OS << ")";
1529
32
}
1530
1531
23.9k
void StmtPrinter::PrintCallArgs(CallExpr *Call) {
1532
27.3k
  for (unsigned i = 0, e = Call->getNumArgs(); i != e; 
++i3.40k
) {
1533
3.40k
    if (isa<CXXDefaultArgExpr>(Call->getArg(i))) {
1534
      // Don't print any defaulted arguments
1535
2
      break;
1536
2
    }
1537
1538
3.40k
    if (i) 
OS << ", "1.38k
;
1539
3.40k
    PrintExpr(Call->getArg(i));
1540
3.40k
  }
1541
23.9k
}
1542
1543
23.9k
void StmtPrinter::VisitCallExpr(CallExpr *Call) {
1544
23.9k
  PrintExpr(Call->getCallee());
1545
23.9k
  OS << "(";
1546
23.9k
  PrintCallArgs(Call);
1547
23.9k
  OS << ")";
1548
23.9k
}
1549
1550
1
static bool isImplicitThis(const Expr *E) {
1551
1
  if (const auto *TE = dyn_cast<CXXThisExpr>(E))
1552
1
    return TE->isImplicit();
1553
0
  return false;
1554
1
}
1555
1556
7.33k
void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
1557
7.33k
  if (!Policy.SuppressImplicitBase || 
!isImplicitThis(Node->getBase())1
) {
1558
7.33k
    PrintExpr(Node->getBase());
1559
1560
7.33k
    auto *ParentMember = dyn_cast<MemberExpr>(Node->getBase());
1561
7.33k
    FieldDecl *ParentDecl =
1562
7.33k
        ParentMember ? 
dyn_cast<FieldDecl>(ParentMember->getMemberDecl())767
1563
7.33k
                     : 
nullptr6.56k
;
1564
1565
7.33k
    if (!ParentDecl || 
!ParentDecl->isAnonymousStructOrUnion()767
)
1566
7.32k
      OS << (Node->isArrow() ? 
"->"4.70k
:
"."2.62k
);
1567
7.33k
  }
1568
1569
7.33k
  if (auto *FD = dyn_cast<FieldDecl>(Node->getMemberDecl()))
1570
6.92k
    if (FD->isAnonymousStructOrUnion())
1571
4
      return;
1572
1573
7.32k
  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
1574
778
    Qualifier->print(OS, Policy);
1575
7.32k
  if (Node->hasTemplateKeyword())
1576
11
    OS << "template ";
1577
7.32k
  OS << Node->getMemberNameInfo();
1578
7.32k
  const TemplateParameterList *TPL = nullptr;
1579
7.32k
  if (auto *FD = dyn_cast<FunctionDecl>(Node->getMemberDecl())) {
1580
373
    if (!Node->hadMultipleCandidates())
1581
243
      if (auto *FTD = FD->getPrimaryTemplate())
1582
0
        TPL = FTD->getTemplateParameters();
1583
6.95k
  } else if (auto *VTSD =
1584
6.95k
                 dyn_cast<VarTemplateSpecializationDecl>(Node->getMemberDecl()))
1585
23
    TPL = VTSD->getSpecializedTemplate()->getTemplateParameters();
1586
7.32k
  if (Node->hasExplicitTemplateArgs())
1587
18
    printTemplateArgumentList(OS, Node->template_arguments(), Policy, TPL);
1588
7.32k
}
1589
1590
0
void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
1591
0
  PrintExpr(Node->getBase());
1592
0
  OS << (Node->isArrow() ? "->isa" : ".isa");
1593
0
}
1594
1595
8
void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
1596
8
  PrintExpr(Node->getBase());
1597
8
  OS << ".";
1598
8
  OS << Node->getAccessor().getName();
1599
8
}
1600
1601
2.23k
void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
1602
2.23k
  OS << '(';
1603
2.23k
  Node->getTypeAsWritten().print(OS, Policy);
1604
2.23k
  OS << ')';
1605
2.23k
  PrintExpr(Node->getSubExpr());
1606
2.23k
}
1607
1608
25
void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
1609
25
  OS << '(';
1610
25
  Node->getType().print(OS, Policy);
1611
25
  OS << ')';
1612
25
  PrintExpr(Node->getInitializer());
1613
25
}
1614
1615
99.3k
void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
1616
  // No need to print anything, simply forward to the subexpression.
1617
99.3k
  PrintExpr(Node->getSubExpr());
1618
99.3k
}
1619
1620
21.1k
void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
1621
21.1k
  PrintExpr(Node->getLHS());
1622
21.1k
  OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1623
21.1k
  PrintExpr(Node->getRHS());
1624
21.1k
}
1625
1626
583
void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
1627
583
  PrintExpr(Node->getLHS());
1628
583
  OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " ";
1629
583
  PrintExpr(Node->getRHS());
1630
583
}
1631
1632
397
void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) {
1633
397
  PrintExpr(Node->getCond());
1634
397
  OS << " ? ";
1635
397
  PrintExpr(Node->getLHS());
1636
397
  OS << " : ";
1637
397
  PrintExpr(Node->getRHS());
1638
397
}
1639
1640
// GNU extensions.
1641
1642
void
1643
39
StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) {
1644
39
  PrintExpr(Node->getCommon());
1645
39
  OS << " ?: ";
1646
39
  PrintExpr(Node->getFalseExpr());
1647
39
}
1648
1649
46
void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) {
1650
46
  OS << "&&" << Node->getLabel()->getName();
1651
46
}
1652
1653
6
void StmtPrinter::VisitStmtExpr(StmtExpr *E) {
1654
6
  OS << "(";
1655
6
  PrintRawCompoundStmt(E->getSubStmt());
1656
6
  OS << ")";
1657
6
}
1658
1659
4
void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
1660
4
  OS << "__builtin_choose_expr(";
1661
4
  PrintExpr(Node->getCond());
1662
4
  OS << ", ";
1663
4
  PrintExpr(Node->getLHS());
1664
4
  OS << ", ";
1665
4
  PrintExpr(Node->getRHS());
1666
4
  OS << ")";
1667
4
}
1668
1669
4
void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) {
1670
4
  OS << "__null";
1671
4
}
1672
1673
4
void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) {
1674
4
  OS << "__builtin_shufflevector(";
1675
28
  for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; 
++i24
) {
1676
24
    if (i) 
OS << ", "20
;
1677
24
    PrintExpr(Node->getExpr(i));
1678
24
  }
1679
4
  OS << ")";
1680
4
}
1681
1682
0
void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) {
1683
0
  OS << "__builtin_convertvector(";
1684
0
  PrintExpr(Node->getSrcExpr());
1685
0
  OS << ", ";
1686
0
  Node->getType().print(OS, Policy);
1687
0
  OS << ")";
1688
0
}
1689
1690
1.05k
void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
1691
1.05k
  if (Node->getSyntacticForm()) {
1692
465
    Visit(Node->getSyntacticForm());
1693
465
    return;
1694
465
  }
1695
1696
591
  OS << "{";
1697
2.20k
  for (unsigned i = 0, e = Node->getNumInits(); i != e; 
++i1.61k
) {
1698
1.61k
    if (i) 
OS << ", "1.06k
;
1699
1.61k
    if (Node->getInit(i))
1700
1.61k
      PrintExpr(Node->getInit(i));
1701
0
    else
1702
0
      OS << "{}";
1703
1.61k
  }
1704
591
  OS << "}";
1705
591
}
1706
1707
4
void StmtPrinter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *Node) {
1708
  // There's no way to express this expression in any of our supported
1709
  // languages, so just emit something terse and (hopefully) clear.
1710
4
  OS << "{";
1711
4
  PrintExpr(Node->getSubExpr());
1712
4
  OS << "}";
1713
4
}
1714
1715
4
void StmtPrinter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *Node) {
1716
4
  OS << "*";
1717
4
}
1718
1719
12
void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) {
1720
12
  OS << "(";
1721
27
  for (unsigned i = 0, e = Node->getNumExprs(); i != e; 
++i15
) {
1722
15
    if (i) 
OS << ", "3
;
1723
15
    PrintExpr(Node->getExpr(i));
1724
15
  }
1725
12
  OS << ")";
1726
12
}
1727
1728
38
void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) {
1729
38
  bool NeedsEquals = true;
1730
70
  for (const DesignatedInitExpr::Designator &D : Node->designators()) {
1731
70
    if (D.isFieldDesignator()) {
1732
42
      if (D.getDotLoc().isInvalid()) {
1733
3
        if (IdentifierInfo *II = D.getFieldName()) {
1734
1
          OS << II->getName() << ":";
1735
1
          NeedsEquals = false;
1736
1
        }
1737
39
      } else {
1738
39
        OS << "." << D.getFieldName()->getName();
1739
39
      }
1740
42
    } else {
1741
28
      OS << "[";
1742
28
      if (D.isArrayDesignator()) {
1743
28
        PrintExpr(Node->getArrayIndex(D));
1744
28
      } else {
1745
0
        PrintExpr(Node->getArrayRangeStart(D));
1746
0
        OS << " ... ";
1747
0
        PrintExpr(Node->getArrayRangeEnd(D));
1748
0
      }
1749
28
      OS << "]";
1750
28
    }
1751
70
  }
1752
1753
38
  if (NeedsEquals)
1754
37
    OS << " = ";
1755
1
  else
1756
1
    OS << " ";
1757
38
  PrintExpr(Node->getInit());
1758
38
}
1759
1760
void StmtPrinter::VisitDesignatedInitUpdateExpr(
1761
2
    DesignatedInitUpdateExpr *Node) {
1762
2
  OS << "{";
1763
2
  OS << "/*base*/";
1764
2
  PrintExpr(Node->getBase());
1765
2
  OS << ", ";
1766
1767
2
  OS << "/*updater*/";
1768
2
  PrintExpr(Node->getUpdater());
1769
2
  OS << "}";
1770
2
}
1771
1772
4
void StmtPrinter::VisitNoInitExpr(NoInitExpr *Node) {
1773
4
  OS << "/*no init*/";
1774
4
}
1775
1776
6
void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
1777
6
  if (Node->getType()->getAsCXXRecordDecl()) {
1778
0
    OS << "/*implicit*/";
1779
0
    Node->getType().print(OS, Policy);
1780
0
    OS << "()";
1781
6
  } else {
1782
6
    OS << "/*implicit*/(";
1783
6
    Node->getType().print(OS, Policy);
1784
6
    OS << ')';
1785
6
    if (Node->getType()->isRecordType())
1786
0
      OS << "{}";
1787
6
    else
1788
6
      OS << 0;
1789
6
  }
1790
6
}
1791
1792
6
void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) {
1793
6
  OS << "__builtin_va_arg(";
1794
6
  PrintExpr(Node->getSubExpr());
1795
6
  OS << ", ";
1796
6
  Node->getType().print(OS, Policy);
1797
6
  OS << ")";
1798
6
}
1799
1800
33
void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) {
1801
33
  PrintExpr(Node->getSyntacticForm());
1802
33
}
1803
1804
6
void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
1805
6
  const char *Name = nullptr;
1806
6
  switch (Node->getOp()) {
1807
0
#define BUILTIN(ID, TYPE, ATTRS)
1808
0
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1809
6
  case AtomicExpr::AO ## ID: \
1810
6
    Name = #ID "("; \
1811
6
    break;
1812
6
#include 
"clang/Basic/Builtins.def"0
1813
6
  }
1814
6
  OS << Name;
1815
1816
  // AtomicExpr stores its subexpressions in a permuted order.
1817
6
  PrintExpr(Node->getPtr());
1818
6
  if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1819
6
      
Node->getOp() != AtomicExpr::AO__atomic_load_n5
&&
1820
6
      
Node->getOp() != AtomicExpr::AO__opencl_atomic_load1
&&
1821
6
      
Node->getOp() != AtomicExpr::AO__hip_atomic_load1
) {
1822
1
    OS << ", ";
1823
1
    PrintExpr(Node->getVal1());
1824
1
  }
1825
6
  if (Node->getOp() == AtomicExpr::AO__atomic_exchange ||
1826
6
      Node->isCmpXChg()) {
1827
0
    OS << ", ";
1828
0
    PrintExpr(Node->getVal2());
1829
0
  }
1830
6
  if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange ||
1831
6
      Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) {
1832
0
    OS << ", ";
1833
0
    PrintExpr(Node->getWeak());
1834
0
  }
1835
6
  if (Node->getOp() != AtomicExpr::AO__c11_atomic_init &&
1836
6
      
Node->getOp() != AtomicExpr::AO__opencl_atomic_init5
) {
1837
5
    OS << ", ";
1838
5
    PrintExpr(Node->getOrder());
1839
5
  }
1840
6
  if (Node->isCmpXChg()) {
1841
0
    OS << ", ";
1842
0
    PrintExpr(Node->getOrderFail());
1843
0
  }
1844
6
  OS << ")";
1845
6
}
1846
1847
// C++
1848
144
void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
1849
144
  OverloadedOperatorKind Kind = Node->getOperator();
1850
144
  if (Kind == OO_PlusPlus || 
Kind == OO_MinusMinus143
) {
1851
1
    if (Node->getNumArgs() == 1) {
1852
0
      OS << getOperatorSpelling(Kind) << ' ';
1853
0
      PrintExpr(Node->getArg(0));
1854
1
    } else {
1855
1
      PrintExpr(Node->getArg(0));
1856
1
      OS << ' ' << getOperatorSpelling(Kind);
1857
1
    }
1858
143
  } else if (Kind == OO_Arrow) {
1859
3
    PrintExpr(Node->getArg(0));
1860
140
  } else if (Kind == OO_Call || 
Kind == OO_Subscript55
) {
1861
85
    PrintExpr(Node->getArg(0));
1862
85
    OS << (Kind == OO_Call ? '(' : 
'['0
);
1863
99
    for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); 
++ArgIdx14
) {
1864
14
      if (ArgIdx > 1)
1865
3
        OS << ", ";
1866
14
      if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
1867
13
        PrintExpr(Node->getArg(ArgIdx));
1868
14
    }
1869
85
    OS << (Kind == OO_Call ? ')' : 
']'0
);
1870
85
  } else 
if (55
Node->getNumArgs() == 155
) {
1871
1
    OS << getOperatorSpelling(Kind) << ' ';
1872
1
    PrintExpr(Node->getArg(0));
1873
54
  } else if (Node->getNumArgs() == 2) {
1874
54
    PrintExpr(Node->getArg(0));
1875
54
    OS << ' ' << getOperatorSpelling(Kind) << ' ';
1876
54
    PrintExpr(Node->getArg(1));
1877
54
  } else {
1878
0
    llvm_unreachable("unknown overloaded operator");
1879
0
  }
1880
144
}
1881
1882
448
void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
1883
  // If we have a conversion operator call only print the argument.
1884
448
  CXXMethodDecl *MD = Node->getMethodDecl();
1885
448
  if (MD && isa<CXXConversionDecl>(MD)) {
1886
297
    PrintExpr(Node->getImplicitObjectArgument());
1887
297
    return;
1888
297
  }
1889
151
  VisitCallExpr(cast<CallExpr>(Node));
1890
151
}
1891
1892
0
void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
1893
0
  PrintExpr(Node->getCallee());
1894
0
  OS << "<<<";
1895
0
  PrintCallArgs(Node->getConfig());
1896
0
  OS << ">>>(";
1897
0
  PrintCallArgs(Node);
1898
0
  OS << ")";
1899
0
}
1900
1901
void StmtPrinter::VisitCXXRewrittenBinaryOperator(
1902
21
    CXXRewrittenBinaryOperator *Node) {
1903
21
  CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
1904
21
      Node->getDecomposedForm();
1905
21
  PrintExpr(const_cast<Expr*>(Decomposed.LHS));
1906
21
  OS << ' ' << BinaryOperator::getOpcodeStr(Decomposed.Opcode) << ' ';
1907
21
  PrintExpr(const_cast<Expr*>(Decomposed.RHS));
1908
21
}
1909
1910
31
void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
1911
31
  OS << Node->getCastName() << '<';
1912
31
  Node->getTypeAsWritten().print(OS, Policy);
1913
31
  OS << ">(";
1914
31
  PrintExpr(Node->getSubExpr());
1915
31
  OS << ")";
1916
31
}
1917
1918
19
void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) {
1919
19
  VisitCXXNamedCastExpr(Node);
1920
19
}
1921
1922
4
void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) {
1923
4
  VisitCXXNamedCastExpr(Node);
1924
4
}
1925
1926
4
void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) {
1927
4
  VisitCXXNamedCastExpr(Node);
1928
4
}
1929
1930
4
void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) {
1931
4
  VisitCXXNamedCastExpr(Node);
1932
4
}
1933
1934
0
void StmtPrinter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *Node) {
1935
0
  OS << "__builtin_bit_cast(";
1936
0
  Node->getTypeInfoAsWritten()->getType().print(OS, Policy);
1937
0
  OS << ", ";
1938
0
  PrintExpr(Node->getSubExpr());
1939
0
  OS << ")";
1940
0
}
1941
1942
0
void StmtPrinter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *Node) {
1943
0
  VisitCXXNamedCastExpr(Node);
1944
0
}
1945
1946
28
void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) {
1947
28
  OS << "typeid(";
1948
28
  if (Node->isTypeOperand()) {
1949
14
    Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1950
14
  } else {
1951
14
    PrintExpr(Node->getExprOperand());
1952
14
  }
1953
28
  OS << ")";
1954
28
}
1955
1956
0
void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) {
1957
0
  OS << "__uuidof(";
1958
0
  if (Node->isTypeOperand()) {
1959
0
    Node->getTypeOperandSourceInfo()->getType().print(OS, Policy);
1960
0
  } else {
1961
0
    PrintExpr(Node->getExprOperand());
1962
0
  }
1963
0
  OS << ")";
1964
0
}
1965
1966
22
void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) {
1967
22
  PrintExpr(Node->getBaseExpr());
1968
22
  if (Node->isArrow())
1969
22
    OS << "->";
1970
0
  else
1971
0
    OS << ".";
1972
22
  if (NestedNameSpecifier *Qualifier =
1973
22
      Node->getQualifierLoc().getNestedNameSpecifier())
1974
0
    Qualifier->print(OS, Policy);
1975
22
  OS << Node->getPropertyDecl()->getDeclName();
1976
22
}
1977
1978
40
void StmtPrinter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *Node) {
1979
40
  PrintExpr(Node->getBase());
1980
40
  OS << "[";
1981
40
  PrintExpr(Node->getIdx());
1982
40
  OS << "]";
1983
40
}
1984
1985
14
void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
1986
14
  switch (Node->getLiteralOperatorKind()) {
1987
2
  case UserDefinedLiteral::LOK_Raw:
1988
2
    OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString();
1989
2
    break;
1990
3
  case UserDefinedLiteral::LOK_Template: {
1991
3
    const auto *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts());
1992
3
    const TemplateArgumentList *Args =
1993
3
      cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs();
1994
3
    assert(Args);
1995
1996
3
    if (Args->size() != 1) {
1997
1
      const TemplateParameterList *TPL = nullptr;
1998
1
      if (!DRE->hadMultipleCandidates())
1999
1
        if (const auto *TD = dyn_cast<TemplateDecl>(DRE->getDecl()))
2000
0
          TPL = TD->getTemplateParameters();
2001
1
      OS << "operator\"\"" << Node->getUDSuffix()->getName();
2002
1
      printTemplateArgumentList(OS, Args->asArray(), Policy, TPL);
2003
1
      OS << "()";
2004
1
      return;
2005
1
    }
2006
2007
2
    const TemplateArgument &Pack = Args->get(0);
2008
16
    for (const auto &P : Pack.pack_elements()) {
2009
16
      char C = (char)P.getAsIntegral().getZExtValue();
2010
16
      OS << C;
2011
16
    }
2012
2
    break;
2013
3
  }
2014
2
  case UserDefinedLiteral::LOK_Integer: {
2015
    // Print integer literal without suffix.
2016
2
    const auto *Int = cast<IntegerLiteral>(Node->getCookedLiteral());
2017
2
    OS << toString(Int->getValue(), 10, /*isSigned*/false);
2018
2
    break;
2019
3
  }
2020
2
  case UserDefinedLiteral::LOK_Floating: {
2021
    // Print floating literal without suffix.
2022
2
    auto *Float = cast<FloatingLiteral>(Node->getCookedLiteral());
2023
2
    PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false);
2024
2
    break;
2025
3
  }
2026
4
  case UserDefinedLiteral::LOK_String:
2027
5
  case UserDefinedLiteral::LOK_Character:
2028
5
    PrintExpr(Node->getCookedLiteral());
2029
5
    break;
2030
14
  }
2031
13
  OS << Node->getUDSuffix()->getName();
2032
13
}
2033
2034
3.96k
void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
2035
3.96k
  OS << (Node->getValue() ? 
"true"3.78k
:
"false"181
);
2036
3.96k
}
2037
2038
125
void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) {
2039
125
  OS << "nullptr";
2040
125
}
2041
2042
5.32k
void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) {
2043
5.32k
  OS << "this";
2044
5.32k
}
2045
2046
2
void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
2047
2
  if (!Node->getSubExpr())
2048
2
    OS << "throw";
2049
0
  else {
2050
0
    OS << "throw ";
2051
0
    PrintExpr(Node->getSubExpr());
2052
0
  }
2053
2
}
2054
2055
8
void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) {
2056
  // Nothing to print: we picked up the default argument.
2057
8
}
2058
2059
1
void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
2060
  // Nothing to print: we picked up the default initializer.
2061
1
}
2062
2063
299
void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
2064
299
  auto TargetType = Node->getType();
2065
299
  auto *Auto = TargetType->getContainedDeducedType();
2066
299
  bool Bare = Auto && 
Auto->isDeduced()4
;
2067
2068
  // Parenthesize deduced casts.
2069
299
  if (Bare)
2070
4
    OS << '(';
2071
299
  TargetType.print(OS, Policy);
2072
299
  if (Bare)
2073
4
    OS << ')';
2074
2075
  // No extra braces surrounding the inner construct.
2076
299
  if (!Node->isListInitialization())
2077
198
    OS << '(';
2078
299
  PrintExpr(Node->getSubExpr());
2079
299
  if (!Node->isListInitialization())
2080
198
    OS << ')';
2081
299
}
2082
2083
880
void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
2084
880
  PrintExpr(Node->getSubExpr());
2085
880
}
2086
2087
802
void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) {
2088
802
  Node->getType().print(OS, Policy);
2089
802
  if (Node->isStdInitListInitialization())
2090
0
    /* Nothing to do; braces are part of creating the std::initializer_list. */;
2091
802
  else if (Node->isListInitialization())
2092
53
    OS << "{";
2093
749
  else
2094
749
    OS << "(";
2095
802
  for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
2096
802
                                         ArgEnd = Node->arg_end();
2097
815
       Arg != ArgEnd; 
++Arg13
) {
2098
14
    if ((*Arg)->isDefaultArgument())
2099
1
      break;
2100
13
    if (Arg != Node->arg_begin())
2101
7
      OS << ", ";
2102
13
    PrintExpr(*Arg);
2103
13
  }
2104
802
  if (Node->isStdInitListInitialization())
2105
0
    /* See above. */;
2106
802
  else if (Node->isListInitialization())
2107
53
    OS << "}";
2108
749
  else
2109
749
    OS << ")";
2110
802
}
2111
2112
154
void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
2113
154
  OS << '[';
2114
154
  bool NeedComma = false;
2115
154
  switch (Node->getCaptureDefault()) {
2116
86
  case LCD_None:
2117
86
    break;
2118
2119
14
  case LCD_ByCopy:
2120
14
    OS << '=';
2121
14
    NeedComma = true;
2122
14
    break;
2123
2124
54
  case LCD_ByRef:
2125
54
    OS << '&';
2126
54
    NeedComma = true;
2127
54
    break;
2128
154
  }
2129
154
  for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(),
2130
154
                                 CEnd = Node->explicit_capture_end();
2131
224
       C != CEnd;
2132
154
       
++C70
) {
2133
70
    if (C->capturesVLAType())
2134
1
      continue;
2135
2136
69
    if (NeedComma)
2137
15
      OS << ", ";
2138
69
    NeedComma = true;
2139
2140
69
    switch (C->getCaptureKind()) {
2141
5
    case LCK_This:
2142
5
      OS << "this";
2143
5
      break;
2144
2145
0
    case LCK_StarThis:
2146
0
      OS << "*this";
2147
0
      break;
2148
2149
25
    case LCK_ByRef:
2150
25
      if (Node->getCaptureDefault() != LCD_ByRef || 
Node->isInitCapture(C)0
)
2151
25
        OS << '&';
2152
25
      OS << C->getCapturedVar()->getName();
2153
25
      break;
2154
2155
39
    case LCK_ByCopy:
2156
39
      OS << C->getCapturedVar()->getName();
2157
39
      break;
2158
2159
0
    case LCK_VLAType:
2160
0
      llvm_unreachable("VLA type in explicit captures.");
2161
69
    }
2162
2163
69
    if (C->isPackExpansion())
2164
4
      OS << "...";
2165
2166
69
    if (Node->isInitCapture(C)) {
2167
17
      VarDecl *D = C->getCapturedVar();
2168
2169
17
      llvm::StringRef Pre;
2170
17
      llvm::StringRef Post;
2171
17
      if (D->getInitStyle() == VarDecl::CallInit &&
2172
17
          
!isa<ParenListExpr>(D->getInit())8
) {
2173
5
        Pre = "(";
2174
5
        Post = ")";
2175
12
      } else if (D->getInitStyle() == VarDecl::CInit) {
2176
7
        Pre = " = ";
2177
7
      }
2178
2179
17
      OS << Pre;
2180
17
      PrintExpr(D->getInit());
2181
17
      OS << Post;
2182
17
    }
2183
69
  }
2184
154
  OS << ']';
2185
2186
154
  if (!Node->getExplicitTemplateParameters().empty()) {
2187
1
    Node->getTemplateParameterList()->print(
2188
1
        OS, Node->getLambdaClass()->getASTContext(),
2189
1
        /*OmitTemplateKW*/true);
2190
1
  }
2191
2192
154
  if (Node->hasExplicitParameters()) {
2193
97
    OS << '(';
2194
97
    CXXMethodDecl *Method = Node->getCallOperator();
2195
97
    NeedComma = false;
2196
97
    for (const auto *P : Method->parameters()) {
2197
33
      if (NeedComma) {
2198
14
        OS << ", ";
2199
19
      } else {
2200
19
        NeedComma = true;
2201
19
      }
2202
33
      std::string ParamStr =
2203
33
          (Policy.CleanUglifiedParameters && 
P->getIdentifier()0
)
2204
33
              ? 
P->getIdentifier()->deuglifiedName().str()0
2205
33
              : P->getNameAsString();
2206
33
      P->getOriginalType().print(OS, Policy, ParamStr);
2207
33
    }
2208
97
    if (Method->isVariadic()) {
2209
0
      if (NeedComma)
2210
0
        OS << ", ";
2211
0
      OS << "...";
2212
0
    }
2213
97
    OS << ')';
2214
2215
97
    if (Node->isMutable())
2216
11
      OS << " mutable";
2217
2218
97
    auto *Proto = Method->getType()->castAs<FunctionProtoType>();
2219
97
    Proto->printExceptionSpecification(OS, Policy);
2220
2221
    // FIXME: Attributes
2222
2223
    // Print the trailing return type if it was specified in the source.
2224
97
    if (Node->hasExplicitResultType()) {
2225
6
      OS << " -> ";
2226
6
      Proto->getReturnType().print(OS, Policy);
2227
6
    }
2228
97
  }
2229
2230
  // Print the body.
2231
154
  OS << ' ';
2232
154
  if (Policy.TerseOutput)
2233
1
    OS << "{}";
2234
153
  else
2235
153
    PrintRawCompoundStmt(Node->getCompoundStmtBody());
2236
154
}
2237
2238
352
void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
2239
352
  if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo())
2240
352
    TSInfo->getType().print(OS, Policy);
2241
0
  else
2242
0
    Node->getType().print(OS, Policy);
2243
352
  OS << "()";
2244
352
}
2245
2246
169
void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
2247
169
  if (E->isGlobalNew())
2248
0
    OS << "::";
2249
169
  OS << "new ";
2250
169
  unsigned NumPlace = E->getNumPlacementArgs();
2251
169
  if (NumPlace > 0 && 
!isa<CXXDefaultArgExpr>(E->getPlacementArg(0))16
) {
2252
15
    OS << "(";
2253
15
    PrintExpr(E->getPlacementArg(0));
2254
15
    for (unsigned i = 1; i < NumPlace; 
++i0
) {
2255
1
      if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
2256
1
        break;
2257
0
      OS << ", ";
2258
0
      PrintExpr(E->getPlacementArg(i));
2259
0
    }
2260
15
    OS << ") ";
2261
15
  }
2262
169
  if (E->isParenTypeId())
2263
0
    OS << "(";
2264
169
  std::string TypeS;
2265
169
  if (E->isArray()) {
2266
11
    llvm::raw_string_ostream s(TypeS);
2267
11
    s << '[';
2268
11
    if (Optional<Expr *> Size = E->getArraySize())
2269
11
      (*Size)->printPretty(s, Helper, Policy);
2270
11
    s << ']';
2271
11
  }
2272
169
  E->getAllocatedType().print(OS, Policy, TypeS);
2273
169
  if (E->isParenTypeId())
2274
0
    OS << ")";
2275
2276
169
  CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
2277
169
  if (InitStyle != CXXNewExpr::NoInit) {
2278
74
    bool Bare = InitStyle == CXXNewExpr::CallInit &&
2279
74
                
!isa<ParenListExpr>(E->getInitializer())65
;
2280
74
    if (Bare)
2281
62
      OS << "(";
2282
74
    PrintExpr(E->getInitializer());
2283
74
    if (Bare)
2284
62
      OS << ")";
2285
74
  }
2286
169
}
2287
2288
4
void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
2289
4
  if (E->isGlobalDelete())
2290
0
    OS << "::";
2291
4
  OS << "delete ";
2292
4
  if (E->isArrayForm())
2293
2
    OS << "[] ";
2294
4
  PrintExpr(E->getArgument());
2295
4
}
2296
2297
5
void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
2298
5
  PrintExpr(E->getBase());
2299
5
  if (E->isArrow())
2300
4
    OS << "->";
2301
1
  else
2302
1
    OS << '.';
2303
5
  if (E->getQualifier())
2304
0
    E->getQualifier()->print(OS, Policy);
2305
5
  OS << "~";
2306
2307
5
  if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
2308
0
    OS << II->getName();
2309
5
  else
2310
5
    E->getDestroyedType().print(OS, Policy);
2311
5
}
2312
2313
1.40k
void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) {
2314
1.40k
  if (E->isListInitialization() && 
!E->isStdInitListInitialization()47
)
2315
47
    OS << "{";
2316
2317
2.36k
  for (unsigned i = 0, e = E->getNumArgs(); i != e; 
++i958
) {
2318
966
    if (isa<CXXDefaultArgExpr>(E->getArg(i))) {
2319
      // Don't print any defaulted arguments
2320
8
      break;
2321
8
    }
2322
2323
958
    if (i) 
OS << ", "7
;
2324
958
    PrintExpr(E->getArg(i));
2325
958
  }
2326
2327
1.40k
  if (E->isListInitialization() && 
!E->isStdInitListInitialization()47
)
2328
47
    OS << "}";
2329
1.40k
}
2330
2331
0
void StmtPrinter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
2332
  // Parens are printed by the surrounding context.
2333
0
  OS << "<forwarded>";
2334
0
}
2335
2336
0
void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
2337
0
  PrintExpr(E->getSubExpr());
2338
0
}
2339
2340
388
void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
2341
  // Just forward to the subexpression.
2342
388
  PrintExpr(E->getSubExpr());
2343
388
}
2344
2345
void StmtPrinter::VisitCXXUnresolvedConstructExpr(
2346
320
    CXXUnresolvedConstructExpr *Node) {
2347
320
  Node->getTypeAsWritten().print(OS, Policy);
2348
320
  if (!Node->isListInitialization())
2349
314
    OS << '(';
2350
351
  for (auto Arg = Node->arg_begin(), ArgEnd = Node->arg_end(); Arg != ArgEnd;
2351
320
       
++Arg31
) {
2352
31
    if (Arg != Node->arg_begin())
2353
4
      OS << ", ";
2354
31
    PrintExpr(*Arg);
2355
31
  }
2356
320
  if (!Node->isListInitialization())
2357
314
    OS << ')';
2358
320
}
2359
2360
void StmtPrinter::VisitCXXDependentScopeMemberExpr(
2361
2.28k
                                         CXXDependentScopeMemberExpr *Node) {
2362
2.28k
  if (!Node->isImplicitAccess()) {
2363
2.10k
    PrintExpr(Node->getBase());
2364
2.10k
    OS << (Node->isArrow() ? 
"->"634
:
"."1.47k
);
2365
2.10k
  }
2366
2.28k
  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2367
180
    Qualifier->print(OS, Policy);
2368
2.28k
  if (Node->hasTemplateKeyword())
2369
3
    OS << "template ";
2370
2.28k
  OS << Node->getMemberNameInfo();
2371
2.28k
  if (Node->hasExplicitTemplateArgs())
2372
2
    printTemplateArgumentList(OS, Node->template_arguments(), Policy);
2373
2.28k
}
2374
2375
8
void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
2376
8
  if (!Node->isImplicitAccess()) {
2377
8
    PrintExpr(Node->getBase());
2378
8
    OS << (Node->isArrow() ? 
"->"0
: ".");
2379
8
  }
2380
8
  if (NestedNameSpecifier *Qualifier = Node->getQualifier())
2381
0
    Qualifier->print(OS, Policy);
2382
8
  if (Node->hasTemplateKeyword())
2383
1
    OS << "template ";
2384
8
  OS << Node->getMemberNameInfo();
2385
8
  if (Node->hasExplicitTemplateArgs())
2386
8
    printTemplateArgumentList(OS, Node->template_arguments(), Policy);
2387
8
}
2388
2389
214
void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) {
2390
214
  OS << getTraitSpelling(E->getTrait()) << "(";
2391
446
  for (unsigned I = 0, N = E->getNumArgs(); I != N; 
++I232
) {
2392
232
    if (I > 0)
2393
18
      OS << ", ";
2394
232
    E->getArg(I)->getType().print(OS, Policy);
2395
232
  }
2396
214
  OS << ")";
2397
214
}
2398
2399
0
void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2400
0
  OS << getTraitSpelling(E->getTrait()) << '(';
2401
0
  E->getQueriedType().print(OS, Policy);
2402
0
  OS << ')';
2403
0
}
2404
2405
0
void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2406
0
  OS << getTraitSpelling(E->getTrait()) << '(';
2407
0
  PrintExpr(E->getQueriedExpression());
2408
0
  OS << ')';
2409
0
}
2410
2411
0
void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2412
0
  OS << "noexcept(";
2413
0
  PrintExpr(E->getOperand());
2414
0
  OS << ")";
2415
0
}
2416
2417
630
void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
2418
630
  PrintExpr(E->getPattern());
2419
630
  OS << "...";
2420
630
}
2421
2422
21
void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2423
21
  OS << "sizeof...(" << *E->getPack() << ")";
2424
21
}
2425
2426
void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
2427
5
                                       SubstNonTypeTemplateParmPackExpr *Node) {
2428
5
  OS << *Node->getParameterPack();
2429
5
}
2430
2431
void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(
2432
6.91k
                                       SubstNonTypeTemplateParmExpr *Node) {
2433
6.91k
  Visit(Node->getReplacement());
2434
6.91k
}
2435
2436
0
void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2437
0
  OS << *E->getParameterPack();
2438
0
}
2439
2440
1.24k
void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){
2441
1.24k
  PrintExpr(Node->getSubExpr());
2442
1.24k
}
2443
2444
16
void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
2445
16
  OS << "(";
2446
16
  if (E->getLHS()) {
2447
12
    PrintExpr(E->getLHS());
2448
12
    OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2449
12
  }
2450
16
  OS << "...";
2451
16
  if (E->getRHS()) {
2452
12
    OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " ";
2453
12
    PrintExpr(E->getRHS());
2454
12
  }
2455
16
  OS << ")";
2456
16
}
2457
2458
67
void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {
2459
67
  NestedNameSpecifierLoc NNS = E->getNestedNameSpecifierLoc();
2460
67
  if (NNS)
2461
0
    NNS.getNestedNameSpecifier()->print(OS, Policy);
2462
67
  if (E->getTemplateKWLoc().isValid())
2463
0
    OS << "template ";
2464
67
  OS << E->getFoundDecl()->getName();
2465
67
  printTemplateArgumentList(OS, E->getTemplateArgsAsWritten()->arguments(),
2466
67
                            Policy,
2467
67
                            E->getNamedConcept()->getTemplateParameters());
2468
67
}
2469
2470
39
void StmtPrinter::VisitRequiresExpr(RequiresExpr *E) {
2471
39
  OS << "requires ";
2472
39
  auto LocalParameters = E->getLocalParameters();
2473
39
  if (!LocalParameters.empty()) {
2474
16
    OS << "(";
2475
17
    for (ParmVarDecl *LocalParam : LocalParameters) {
2476
17
      PrintRawDecl(LocalParam);
2477
17
      if (LocalParam != LocalParameters.back())
2478
1
        OS << ", ";
2479
17
    }
2480
2481
16
    OS << ") ";
2482
16
  }
2483
39
  OS << "{ ";
2484
39
  auto Requirements = E->getRequirements();
2485
59
  for (concepts::Requirement *Req : Requirements) {
2486
59
    if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
2487
15
      if (TypeReq->isSubstitutionFailure())
2488
4
        OS << "<<error-type>>";
2489
11
      else
2490
11
        TypeReq->getType()->getType().print(OS, Policy);
2491
44
    } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
2492
25
      if (ExprReq->isCompound())
2493
13
        OS << "{ ";
2494
25
      if (ExprReq->isExprSubstitutionFailure())
2495
2
        OS << "<<error-expression>>";
2496
23
      else
2497
23
        PrintExpr(ExprReq->getExpr());
2498
25
      if (ExprReq->isCompound()) {
2499
13
        OS << " }";
2500
13
        if (ExprReq->getNoexceptLoc().isValid())
2501
6
          OS << " noexcept";
2502
13
        const auto &RetReq = ExprReq->getReturnTypeRequirement();
2503
13
        if (!RetReq.isEmpty()) {
2504
11
          OS << " -> ";
2505
11
          if (RetReq.isSubstitutionFailure())
2506
1
            OS << "<<error-type>>";
2507
10
          else if (RetReq.isTypeConstraint())
2508
10
            RetReq.getTypeConstraint()->print(OS, Policy);
2509
11
        }
2510
13
      }
2511
25
    } else {
2512
19
      auto *NestedReq = cast<concepts::NestedRequirement>(Req);
2513
19
      OS << "requires ";
2514
19
      if (NestedReq->isSubstitutionFailure())
2515
1
        OS << "<<error-expression>>";
2516
18
      else
2517
18
        PrintExpr(NestedReq->getConstraintExpr());
2518
19
    }
2519
59
    OS << "; ";
2520
59
  }
2521
39
  OS << "}";
2522
39
}
2523
2524
// C++ Coroutines TS
2525
2526
0
void StmtPrinter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
2527
0
  Visit(S->getBody());
2528
0
}
2529
2530
1
void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) {
2531
1
  OS << "co_return";
2532
1
  if (S->getOperand()) {
2533
1
    OS << " ";
2534
1
    Visit(S->getOperand());
2535
1
  }
2536
1
  OS << ";";
2537
1
}
2538
2539
0
void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) {
2540
0
  OS << "co_await ";
2541
0
  PrintExpr(S->getOperand());
2542
0
}
2543
2544
0
void StmtPrinter::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) {
2545
0
  OS << "co_await ";
2546
0
  PrintExpr(S->getOperand());
2547
0
}
2548
2549
0
void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) {
2550
0
  OS << "co_yield ";
2551
0
  PrintExpr(S->getOperand());
2552
0
}
2553
2554
// Obj-C
2555
2556
4
void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
2557
4
  OS << "@";
2558
4
  VisitStringLiteral(Node->getString());
2559
4
}
2560
2561
8
void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
2562
8
  OS << "@";
2563
8
  Visit(E->getSubExpr());
2564
8
}
2565
2566
1
void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
2567
1
  OS << "@[ ";
2568
1
  ObjCArrayLiteral::child_range Ch = E->children();
2569
3
  for (auto I = Ch.begin(), E = Ch.end(); I != E; 
++I2
) {
2570
2
    if (I != Ch.begin())
2571
1
      OS << ", ";
2572
2
    Visit(*I);
2573
2
  }
2574
1
  OS << " ]";
2575
1
}
2576
2577
3
void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
2578
3
  OS << "@{ ";
2579
8
  for (unsigned I = 0, N = E->getNumElements(); I != N; 
++I5
) {
2580
5
    if (I > 0)
2581
2
      OS << ", ";
2582
2583
5
    ObjCDictionaryElement Element = E->getKeyValueElement(I);
2584
5
    Visit(Element.Key);
2585
5
    OS << " : ";
2586
5
    Visit(Element.Value);
2587
5
    if (Element.isPackExpansion())
2588
1
      OS << "...";
2589
5
  }
2590
3
  OS << " }";
2591
3
}
2592
2593
6
void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
2594
6
  OS << "@encode(";
2595
6
  Node->getEncodedType().print(OS, Policy);
2596
6
  OS << ')';
2597
6
}
2598
2599
0
void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
2600
0
  OS << "@selector(";
2601
0
  Node->getSelector().print(OS);
2602
0
  OS << ')';
2603
0
}
2604
2605
0
void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
2606
0
  OS << "@protocol(" << *Node->getProtocol() << ')';
2607
0
}
2608
2609
23
void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
2610
23
  OS << "[";
2611
23
  switch (Mess->getReceiverKind()) {
2612
19
  case ObjCMessageExpr::Instance:
2613
19
    PrintExpr(Mess->getInstanceReceiver());
2614
19
    break;
2615
2616
2
  case ObjCMessageExpr::Class:
2617
2
    Mess->getClassReceiver().print(OS, Policy);
2618
2
    break;
2619
2620
1
  case ObjCMessageExpr::SuperInstance:
2621
2
  case ObjCMessageExpr::SuperClass:
2622
2
    OS << "Super";
2623
2
    break;
2624
23
  }
2625
2626
23
  OS << ' ';
2627
23
  Selector selector = Mess->getSelector();
2628
23
  if (selector.isUnarySelector()) {
2629
19
    OS << selector.getNameForSlot(0);
2630
19
  } else {
2631
8
    for (unsigned i = 0, e = Mess->getNumArgs(); i != e; 
++i4
) {
2632
4
      if (i < selector.getNumArgs()) {
2633
4
        if (i > 0) 
OS << ' '0
;
2634
4
        if (selector.getIdentifierInfoForSlot(i))
2635
4
          OS << selector.getIdentifierInfoForSlot(i)->getName() << ':';
2636
0
        else
2637
0
           OS << ":";
2638
4
      }
2639
0
      else OS << ", "; // Handle variadic methods.
2640
2641
4
      PrintExpr(Mess->getArg(i));
2642
4
    }
2643
4
  }
2644
23
  OS << "]";
2645
23
}
2646
2647
0
void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
2648
0
  OS << (Node->getValue() ? "__objc_yes" : "__objc_no");
2649
0
}
2650
2651
void
2652
0
StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
2653
0
  PrintExpr(E->getSubExpr());
2654
0
}
2655
2656
void
2657
0
StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
2658
0
  OS << '(' << E->getBridgeKindName();
2659
0
  E->getType().print(OS, Policy);
2660
0
  OS << ')';
2661
0
  PrintExpr(E->getSubExpr());
2662
0
}
2663
2664
10
void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
2665
10
  BlockDecl *BD = Node->getBlockDecl();
2666
10
  OS << "^";
2667
2668
10
  const FunctionType *AFT = Node->getFunctionType();
2669
2670
10
  if (isa<FunctionNoProtoType>(AFT)) {
2671
0
    OS << "()";
2672
10
  } else if (!BD->param_empty() || 
cast<FunctionProtoType>(AFT)->isVariadic()7
) {
2673
3
    OS << '(';
2674
3
    for (BlockDecl::param_iterator AI = BD->param_begin(),
2675
9
         E = BD->param_end(); AI != E; 
++AI6
) {
2676
6
      if (AI != BD->param_begin()) 
OS << ", "3
;
2677
6
      std::string ParamStr = (*AI)->getNameAsString();
2678
6
      (*AI)->getType().print(OS, Policy, ParamStr);
2679
6
    }
2680
2681
3
    const auto *FT = cast<FunctionProtoType>(AFT);
2682
3
    if (FT->isVariadic()) {
2683
0
      if (!BD->param_empty()) OS << ", ";
2684
0
      OS << "...";
2685
0
    }
2686
3
    OS << ')';
2687
3
  }
2688
10
  OS << "{ }";
2689
10
}
2690
2691
118
void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
2692
118
  PrintExpr(Node->getSourceExpr());
2693
118
}
2694
2695
0
void StmtPrinter::VisitTypoExpr(TypoExpr *Node) {
2696
  // TODO: Print something reasonable for a TypoExpr, if necessary.
2697
0
  llvm_unreachable("Cannot print TypoExpr nodes");
2698
0
}
2699
2700
27
void StmtPrinter::VisitRecoveryExpr(RecoveryExpr *Node) {
2701
27
  OS << "<recovery-expr>(";
2702
27
  const char *Sep = "";
2703
27
  for (Expr *E : Node->subExpressions()) {
2704
21
    OS << Sep;
2705
21
    PrintExpr(E);
2706
21
    Sep = ", ";
2707
21
  }
2708
27
  OS << ')';
2709
27
}
2710
2711
0
void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) {
2712
0
  OS << "__builtin_astype(";
2713
0
  PrintExpr(Node->getSrcExpr());
2714
0
  OS << ", ";
2715
0
  Node->getType().print(OS, Policy);
2716
0
  OS << ")";
2717
0
}
2718
2719
//===----------------------------------------------------------------------===//
2720
// Stmt method implementations
2721
//===----------------------------------------------------------------------===//
2722
2723
0
void Stmt::dumpPretty(const ASTContext &Context) const {
2724
0
  printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
2725
0
}
2726
2727
void Stmt::printPretty(raw_ostream &Out, PrinterHelper *Helper,
2728
                       const PrintingPolicy &Policy, unsigned Indentation,
2729
195k
                       StringRef NL, const ASTContext *Context) const {
2730
195k
  StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
2731
195k
  P.Visit(const_cast<Stmt *>(this));
2732
195k
}
2733
2734
void Stmt::printPrettyControlled(raw_ostream &Out, PrinterHelper *Helper,
2735
                                 const PrintingPolicy &Policy,
2736
                                 unsigned Indentation, StringRef NL,
2737
5.44k
                                 const ASTContext *Context) const {
2738
5.44k
  StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
2739
5.44k
  P.PrintControlledStmt(const_cast<Stmt *>(this));
2740
5.44k
}
2741
2742
void Stmt::printJson(raw_ostream &Out, PrinterHelper *Helper,
2743
325
                     const PrintingPolicy &Policy, bool AddQuotes) const {
2744
325
  std::string Buf;
2745
325
  llvm::raw_string_ostream TempOut(Buf);
2746
2747
325
  printPretty(TempOut, Helper, Policy);
2748
2749
325
  Out << JsonFormat(TempOut.str(), AddQuotes);
2750
325
}
2751
2752
//===----------------------------------------------------------------------===//
2753
// PrinterHelper
2754
//===----------------------------------------------------------------------===//
2755
2756
// Implement virtual destructor.
2757
122k
PrinterHelper::~PrinterHelper() = default;