Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/TypePrinter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- TypePrinter.cpp - Pretty-Print Clang Types -------------------------===//
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 contains code to print types from Clang's type system.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/ASTContext.h"
14
#include "clang/AST/Attr.h"
15
#include "clang/AST/Decl.h"
16
#include "clang/AST/DeclBase.h"
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/DeclObjC.h"
19
#include "clang/AST/DeclTemplate.h"
20
#include "clang/AST/Expr.h"
21
#include "clang/AST/NestedNameSpecifier.h"
22
#include "clang/AST/PrettyPrinter.h"
23
#include "clang/AST/TemplateBase.h"
24
#include "clang/AST/TemplateName.h"
25
#include "clang/AST/Type.h"
26
#include "clang/Basic/AddressSpaces.h"
27
#include "clang/Basic/ExceptionSpecificationType.h"
28
#include "clang/Basic/IdentifierTable.h"
29
#include "clang/Basic/LLVM.h"
30
#include "clang/Basic/LangOptions.h"
31
#include "clang/Basic/SourceLocation.h"
32
#include "clang/Basic/SourceManager.h"
33
#include "clang/Basic/Specifiers.h"
34
#include "llvm/ADT/ArrayRef.h"
35
#include "llvm/ADT/SmallString.h"
36
#include "llvm/ADT/StringRef.h"
37
#include "llvm/ADT/Twine.h"
38
#include "llvm/Support/Casting.h"
39
#include "llvm/Support/Compiler.h"
40
#include "llvm/Support/ErrorHandling.h"
41
#include "llvm/Support/SaveAndRestore.h"
42
#include "llvm/Support/raw_ostream.h"
43
#include <cassert>
44
#include <string>
45
46
using namespace clang;
47
48
namespace {
49
50
  /// RAII object that enables printing of the ARC __strong lifetime
51
  /// qualifier.
52
  class IncludeStrongLifetimeRAII {
53
    PrintingPolicy &Policy;
54
    bool Old;
55
56
  public:
57
    explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy)
58
1.76M
        : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
59
1.76M
        if (!Policy.SuppressLifetimeQualifiers)
60
1.76M
          Policy.SuppressStrongLifetime = false;
61
1.76M
    }
62
63
1.76M
    ~IncludeStrongLifetimeRAII() {
64
1.76M
      Policy.SuppressStrongLifetime = Old;
65
1.76M
    }
66
  };
67
68
  class ParamPolicyRAII {
69
    PrintingPolicy &Policy;
70
    bool Old;
71
72
  public:
73
    explicit ParamPolicyRAII(PrintingPolicy &Policy)
74
39.6k
        : Policy(Policy), Old(Policy.SuppressSpecifiers) {
75
39.6k
      Policy.SuppressSpecifiers = false;
76
39.6k
    }
77
78
39.6k
    ~ParamPolicyRAII() {
79
39.6k
      Policy.SuppressSpecifiers = Old;
80
39.6k
    }
81
  };
82
83
  class DefaultTemplateArgsPolicyRAII {
84
    PrintingPolicy &Policy;
85
    bool Old;
86
87
  public:
88
    explicit DefaultTemplateArgsPolicyRAII(PrintingPolicy &Policy)
89
188k
        : Policy(Policy), Old(Policy.SuppressDefaultTemplateArgs) {
90
188k
      Policy.SuppressDefaultTemplateArgs = false;
91
188k
    }
92
93
188k
    ~DefaultTemplateArgsPolicyRAII() {
94
188k
      Policy.SuppressDefaultTemplateArgs = Old;
95
188k
    }
96
  };
97
98
  class ElaboratedTypePolicyRAII {
99
    PrintingPolicy &Policy;
100
    bool SuppressTagKeyword;
101
    bool SuppressScope;
102
103
  public:
104
10.3k
    explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
105
10.3k
      SuppressTagKeyword = Policy.SuppressTagKeyword;
106
10.3k
      SuppressScope = Policy.SuppressScope;
107
10.3k
      Policy.SuppressTagKeyword = true;
108
10.3k
      Policy.SuppressScope = true;
109
10.3k
    }
110
111
10.3k
    ~ElaboratedTypePolicyRAII() {
112
10.3k
      Policy.SuppressTagKeyword = SuppressTagKeyword;
113
10.3k
      Policy.SuppressScope = SuppressScope;
114
10.3k
    }
115
  };
116
117
  class TypePrinter {
118
    PrintingPolicy Policy;
119
    unsigned Indentation;
120
    bool HasEmptyPlaceHolder = false;
121
    bool InsideCCAttribute = false;
122
123
  public:
124
    explicit TypePrinter(const PrintingPolicy &Policy, unsigned Indentation = 0)
125
2.88M
        : Policy(Policy), Indentation(Indentation) {}
126
127
    void print(const Type *ty, Qualifiers qs, raw_ostream &OS,
128
               StringRef PlaceHolder);
129
    void print(QualType T, raw_ostream &OS, StringRef PlaceHolder);
130
131
    static bool canPrefixQualifiers(const Type *T, bool &NeedARCStrongQualifier);
132
    void spaceBeforePlaceHolder(raw_ostream &OS);
133
    void printTypeSpec(NamedDecl *D, raw_ostream &OS);
134
    void printTemplateId(const TemplateSpecializationType *T, raw_ostream &OS,
135
                         bool FullyQualify);
136
137
    void printBefore(QualType T, raw_ostream &OS);
138
    void printAfter(QualType T, raw_ostream &OS);
139
    void AppendScope(DeclContext *DC, raw_ostream &OS,
140
                     DeclarationName NameInScope);
141
    void printTag(TagDecl *T, raw_ostream &OS);
142
    void printFunctionAfter(const FunctionType::ExtInfo &Info, raw_ostream &OS);
143
#define ABSTRACT_TYPE(CLASS, PARENT)
144
#define TYPE(CLASS, PARENT) \
145
    void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
146
    void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
147
#include "clang/AST/TypeNodes.inc"
148
149
  private:
150
    void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);
151
    void printAfter(const Type *ty, Qualifiers qs, raw_ostream &OS);
152
  };
153
154
} // namespace
155
156
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
157
110k
                               bool HasRestrictKeyword) {
158
110k
  bool appendSpace = false;
159
110k
  if (TypeQuals & Qualifiers::Const) {
160
108k
    OS << "const";
161
108k
    appendSpace = true;
162
108k
  }
163
110k
  if (TypeQuals & Qualifiers::Volatile) {
164
2.69k
    if (appendSpace) 
OS << ' '1.26k
;
165
2.69k
    OS << "volatile";
166
2.69k
    appendSpace = true;
167
2.69k
  }
168
110k
  if (TypeQuals & Qualifiers::Restrict) {
169
2.54k
    if (appendSpace) 
OS << ' '2.34k
;
170
2.54k
    if (HasRestrictKeyword) {
171
1.85k
      OS << "restrict";
172
1.85k
    } else {
173
691
      OS << "__restrict";
174
691
    }
175
2.54k
  }
176
110k
}
177
178
2.91M
void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
179
2.91M
  if (!HasEmptyPlaceHolder)
180
432k
    OS << ' ';
181
2.91M
}
182
183
static SplitQualType splitAccordingToPolicy(QualType QT,
184
3.98M
                                            const PrintingPolicy &Policy) {
185
3.98M
  if (Policy.PrintCanonicalTypes)
186
1.13M
    QT = QT.getCanonicalType();
187
3.98M
  return QT.split();
188
3.98M
}
189
190
42.8k
void TypePrinter::print(QualType t, raw_ostream &OS, StringRef PlaceHolder) {
191
42.8k
  SplitQualType split = splitAccordingToPolicy(t, Policy);
192
42.8k
  print(split.Ty, split.Quals, OS, PlaceHolder);
193
42.8k
}
194
195
void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
196
2.92M
                        StringRef PlaceHolder) {
197
2.92M
  if (!T) {
198
112
    OS << "NULL TYPE";
199
112
    return;
200
112
  }
201
202
2.92M
  SaveAndRestore<bool> PHVal(HasEmptyPlaceHolder, PlaceHolder.empty());
203
204
2.92M
  printBefore(T, Quals, OS);
205
2.92M
  OS << PlaceHolder;
206
2.92M
  printAfter(T, Quals, OS);
207
2.92M
}
208
209
bool TypePrinter::canPrefixQualifiers(const Type *T,
210
3.53M
                                      bool &NeedARCStrongQualifier) {
211
  // CanPrefixQualifiers - We prefer to print type qualifiers before the type,
212
  // so that we get "const int" instead of "int const", but we can't do this if
213
  // the type is complex.  For example if the type is "int*", we *must* print
214
  // "int * const", printing "const int *" is different.  Only do this when the
215
  // type expands to a simple string.
216
3.53M
  bool CanPrefixQualifiers = false;
217
3.53M
  NeedARCStrongQualifier = false;
218
3.53M
  const Type *UnderlyingType = T;
219
3.53M
  if (const auto *AT = dyn_cast<AutoType>(T))
220
4.45k
    UnderlyingType = AT->desugar().getTypePtr();
221
3.53M
  if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))
222
19.7k
    UnderlyingType = Subst->getReplacementType().getTypePtr();
223
3.53M
  Type::TypeClass TC = UnderlyingType->getTypeClass();
224
225
3.53M
  switch (TC) {
226
1.73k
    case Type::Auto:
227
1.29M
    case Type::Builtin:
228
1.29M
    case Type::Complex:
229
1.29M
    case Type::UnresolvedUsing:
230
1.29M
    case Type::Using:
231
1.34M
    case Type::Typedef:
232
1.34M
    case Type::TypeOfExpr:
233
1.34M
    case Type::TypeOf:
234
1.34M
    case Type::Decltype:
235
1.34M
    case Type::UnaryTransform:
236
2.38M
    case Type::Record:
237
2.39M
    case Type::Enum:
238
2.40M
    case Type::Elaborated:
239
2.73M
    case Type::TemplateTypeParm:
240
2.73M
    case Type::SubstTemplateTypeParmPack:
241
2.73M
    case Type::DeducedTemplateSpecialization:
242
2.73M
    case Type::TemplateSpecialization:
243
2.92M
    case Type::InjectedClassName:
244
2.92M
    case Type::DependentName:
245
2.92M
    case Type::DependentTemplateSpecialization:
246
2.92M
    case Type::ObjCObject:
247
2.92M
    case Type::ObjCTypeParam:
248
2.96M
    case Type::ObjCInterface:
249
2.96M
    case Type::Atomic:
250
2.96M
    case Type::Pipe:
251
2.96M
    case Type::BitInt:
252
2.96M
    case Type::DependentBitInt:
253
2.96M
    case Type::BTFTagAttributed:
254
2.96M
      CanPrefixQualifiers = true;
255
2.96M
      break;
256
257
26.5k
    case Type::ObjCObjectPointer:
258
26.5k
      CanPrefixQualifiers = T->isObjCIdType() || 
T->isObjCClassType()24.0k
||
259
26.5k
        
T->isObjCQualifiedIdType()23.6k
||
T->isObjCQualifiedClassType()22.4k
;
260
26.5k
      break;
261
262
346
    case Type::VariableArray:
263
549
    case Type::DependentSizedArray:
264
549
      NeedARCStrongQualifier = true;
265
549
      LLVM_FALLTHROUGH;
266
267
17.9k
    case Type::ConstantArray:
268
19.7k
    case Type::IncompleteArray:
269
19.7k
      return canPrefixQualifiers(
270
19.7k
          cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(),
271
19.7k
          NeedARCStrongQualifier);
272
273
0
    case Type::Adjusted:
274
278
    case Type::Decayed:
275
370k
    case Type::Pointer:
276
371k
    case Type::BlockPointer:
277
417k
    case Type::LValueReference:
278
427k
    case Type::RValueReference:
279
430k
    case Type::MemberPointer:
280
430k
    case Type::DependentAddressSpace:
281
430k
    case Type::DependentVector:
282
431k
    case Type::DependentSizedExtVector:
283
435k
    case Type::Vector:
284
439k
    case Type::ExtVector:
285
440k
    case Type::ConstantMatrix:
286
440k
    case Type::DependentSizedMatrix:
287
480k
    case Type::FunctionProto:
288
480k
    case Type::FunctionNoProto:
289
483k
    case Type::Paren:
290
522k
    case Type::PackExpansion:
291
522k
    case Type::SubstTemplateTypeParm:
292
522k
    case Type::MacroQualified:
293
522k
      CanPrefixQualifiers = false;
294
522k
      break;
295
296
1.74k
    case Type::Attributed: {
297
      // We still want to print the address_space before the type if it is an
298
      // address_space attribute.
299
1.74k
      const auto *AttrTy = cast<AttributedType>(UnderlyingType);
300
1.74k
      CanPrefixQualifiers = AttrTy->getAttrKind() == attr::AddressSpace;
301
1.74k
      break;
302
522k
    }
303
3.53M
  }
304
305
3.51M
  return CanPrefixQualifiers;
306
3.53M
}
307
308
598k
void TypePrinter::printBefore(QualType T, raw_ostream &OS) {
309
598k
  SplitQualType Split = splitAccordingToPolicy(T, Policy);
310
311
  // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2
312
  // at this level.
313
598k
  Qualifiers Quals = Split.Quals;
314
598k
  if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(Split.Ty))
315
3.54k
    Quals -= QualType(Subst, 0).getQualifiers();
316
317
598k
  printBefore(Split.Ty, Quals, OS);
318
598k
}
319
320
/// Prints the part of the type string before an identifier, e.g. for
321
/// "int foo[10]" it prints "int ".
322
3.52M
void TypePrinter::printBefore(const Type *T,Qualifiers Quals, raw_ostream &OS) {
323
3.52M
  if (Policy.SuppressSpecifiers && 
T->isSpecifierType()6.05k
)
324
5.70k
    return;
325
326
3.51M
  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder);
327
328
  // Print qualifiers as appropriate.
329
330
3.51M
  bool CanPrefixQualifiers = false;
331
3.51M
  bool NeedARCStrongQualifier = false;
332
3.51M
  CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
333
334
3.51M
  if (CanPrefixQualifiers && 
!Quals.empty()2.96M
) {
335
111k
    if (NeedARCStrongQualifier) {
336
0
      IncludeStrongLifetimeRAII Strong(Policy);
337
0
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
338
111k
    } else {
339
111k
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
340
111k
    }
341
111k
  }
342
343
3.51M
  bool hasAfterQuals = false;
344
3.51M
  if (!CanPrefixQualifiers && 
!Quals.empty()546k
) {
345
9.64k
    hasAfterQuals = !Quals.isEmptyWhenPrinted(Policy);
346
9.64k
    if (hasAfterQuals)
347
9.61k
      HasEmptyPlaceHolder = false;
348
9.64k
  }
349
350
3.51M
  switch (T->getTypeClass()) {
351
0
#define ABSTRACT_TYPE(CLASS, PARENT)
352
3.51M
#define TYPE(CLASS, PARENT) case Type::CLASS: \
353
3.51M
    print##CLASS##Before(cast<CLASS##Type>(T), OS); \
354
3.51M
    break;
355
3.51M
#include 
"clang/AST/TypeNodes.inc"0
356
3.51M
  }
357
358
3.51M
  if (hasAfterQuals) {
359
9.61k
    if (NeedARCStrongQualifier) {
360
0
      IncludeStrongLifetimeRAII Strong(Policy);
361
0
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
362
9.61k
    } else {
363
9.61k
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
364
9.61k
    }
365
9.61k
  }
366
3.51M
}
367
368
571k
void TypePrinter::printAfter(QualType t, raw_ostream &OS) {
369
571k
  SplitQualType split = splitAccordingToPolicy(t, Policy);
370
571k
  printAfter(split.Ty, split.Quals, OS);
371
571k
}
372
373
/// Prints the part of the type string after an identifier, e.g. for
374
/// "int foo[10]" it prints "[10]".
375
3.49M
void TypePrinter::printAfter(const Type *T, Qualifiers Quals, raw_ostream &OS) {
376
3.49M
  switch (T->getTypeClass()) {
377
0
#define ABSTRACT_TYPE(CLASS, PARENT)
378
3.49M
#define TYPE(CLASS, PARENT) case Type::CLASS: \
379
3.49M
    print##CLASS##After(cast<CLASS##Type>(T), OS); \
380
3.49M
    break;
381
3.49M
#include 
"clang/AST/TypeNodes.inc"0
382
3.49M
  }
383
3.49M
}
384
385
1.26M
void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) {
386
1.26M
  OS << T->getName(Policy);
387
1.26M
  spaceBeforePlaceHolder(OS);
388
1.26M
}
389
390
1.26M
void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) {}
391
392
743
void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) {
393
743
  OS << "_Complex ";
394
743
  printBefore(T->getElementType(), OS);
395
743
}
396
397
745
void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) {
398
745
  printAfter(T->getElementType(), OS);
399
745
}
400
401
367k
void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) {
402
367k
  IncludeStrongLifetimeRAII Strong(Policy);
403
367k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
404
367k
  printBefore(T->getPointeeType(), OS);
405
  // Handle things like 'int (*A)[4];' correctly.
406
  // FIXME: this should include vectors, but vectors use attributes I guess.
407
367k
  if (isa<ArrayType>(T->getPointeeType()))
408
1.22k
    OS << '(';
409
367k
  OS << '*';
410
367k
}
411
412
367k
void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) {
413
367k
  IncludeStrongLifetimeRAII Strong(Policy);
414
367k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
415
  // Handle things like 'int (*A)[4];' correctly.
416
  // FIXME: this should include vectors, but vectors use attributes I guess.
417
367k
  if (isa<ArrayType>(T->getPointeeType()))
418
1.22k
    OS << ')';
419
367k
  printAfter(T->getPointeeType(), OS);
420
367k
}
421
422
void TypePrinter::printBlockPointerBefore(const BlockPointerType *T,
423
1.13k
                                          raw_ostream &OS) {
424
1.13k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
425
1.13k
  printBefore(T->getPointeeType(), OS);
426
1.13k
  OS << '^';
427
1.13k
}
428
429
void TypePrinter::printBlockPointerAfter(const BlockPointerType *T,
430
1.13k
                                          raw_ostream &OS) {
431
1.13k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
432
1.13k
  printAfter(T->getPointeeType(), OS);
433
1.13k
}
434
435
// When printing a reference, the referenced type might also be a reference.
436
// If so, we want to skip that before printing the inner type.
437
112k
static QualType skipTopLevelReferences(QualType T) {
438
112k
  if (auto *Ref = T->getAs<ReferenceType>())
439
390
    return skipTopLevelReferences(Ref->getPointeeTypeAsWritten());
440
111k
  return T;
441
112k
}
442
443
void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
444
45.5k
                                             raw_ostream &OS) {
445
45.5k
  IncludeStrongLifetimeRAII Strong(Policy);
446
45.5k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
447
45.5k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
448
45.5k
  printBefore(Inner, OS);
449
  // Handle things like 'int (&A)[4];' correctly.
450
  // FIXME: this should include vectors, but vectors use attributes I guess.
451
45.5k
  if (isa<ArrayType>(Inner))
452
1.07k
    OS << '(';
453
45.5k
  OS << '&';
454
45.5k
}
455
456
void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T,
457
45.5k
                                            raw_ostream &OS) {
458
45.5k
  IncludeStrongLifetimeRAII Strong(Policy);
459
45.5k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
460
45.5k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
461
  // Handle things like 'int (&A)[4];' correctly.
462
  // FIXME: this should include vectors, but vectors use attributes I guess.
463
45.5k
  if (isa<ArrayType>(Inner))
464
1.07k
    OS << ')';
465
45.5k
  printAfter(Inner, OS);
466
45.5k
}
467
468
void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
469
10.3k
                                             raw_ostream &OS) {
470
10.3k
  IncludeStrongLifetimeRAII Strong(Policy);
471
10.3k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
472
10.3k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
473
10.3k
  printBefore(Inner, OS);
474
  // Handle things like 'int (&&A)[4];' correctly.
475
  // FIXME: this should include vectors, but vectors use attributes I guess.
476
10.3k
  if (isa<ArrayType>(Inner))
477
7
    OS << '(';
478
10.3k
  OS << "&&";
479
10.3k
}
480
481
void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T,
482
10.3k
                                            raw_ostream &OS) {
483
10.3k
  IncludeStrongLifetimeRAII Strong(Policy);
484
10.3k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
485
10.3k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
486
  // Handle things like 'int (&&A)[4];' correctly.
487
  // FIXME: this should include vectors, but vectors use attributes I guess.
488
10.3k
  if (isa<ArrayType>(Inner))
489
7
    OS << ')';
490
10.3k
  printAfter(Inner, OS);
491
10.3k
}
492
493
void TypePrinter::printMemberPointerBefore(const MemberPointerType *T,
494
3.45k
                                           raw_ostream &OS) {
495
3.45k
  IncludeStrongLifetimeRAII Strong(Policy);
496
3.45k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
497
3.45k
  printBefore(T->getPointeeType(), OS);
498
  // Handle things like 'int (Cls::*A)[4];' correctly.
499
  // FIXME: this should include vectors, but vectors use attributes I guess.
500
3.45k
  if (isa<ArrayType>(T->getPointeeType()))
501
0
    OS << '(';
502
503
3.45k
  PrintingPolicy InnerPolicy(Policy);
504
3.45k
  InnerPolicy.IncludeTagDefinition = false;
505
3.45k
  TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
506
507
3.45k
  OS << "::*";
508
3.45k
}
509
510
void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
511
3.45k
                                          raw_ostream &OS) {
512
3.45k
  IncludeStrongLifetimeRAII Strong(Policy);
513
3.45k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
514
  // Handle things like 'int (Cls::*A)[4];' correctly.
515
  // FIXME: this should include vectors, but vectors use attributes I guess.
516
3.45k
  if (isa<ArrayType>(T->getPointeeType()))
517
0
    OS << ')';
518
3.45k
  printAfter(T->getPointeeType(), OS);
519
3.45k
}
520
521
void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
522
16.5k
                                           raw_ostream &OS) {
523
16.5k
  IncludeStrongLifetimeRAII Strong(Policy);
524
16.5k
  printBefore(T->getElementType(), OS);
525
16.5k
}
526
527
void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
528
16.5k
                                          raw_ostream &OS) {
529
16.5k
  OS << '[';
530
16.5k
  if (T->getIndexTypeQualifiers().hasQualifiers()) {
531
1
    AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(),
532
1
                       Policy.Restrict);
533
1
    OS << ' ';
534
1
  }
535
536
16.5k
  if (T->getSizeModifier() == ArrayType::Static)
537
2
    OS << "static ";
538
539
16.5k
  OS << T->getSize().getZExtValue() << ']';
540
16.5k
  printAfter(T->getElementType(), OS);
541
16.5k
}
542
543
void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
544
1.75k
                                             raw_ostream &OS) {
545
1.75k
  IncludeStrongLifetimeRAII Strong(Policy);
546
1.75k
  printBefore(T->getElementType(), OS);
547
1.75k
}
548
549
void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
550
1.75k
                                            raw_ostream &OS) {
551
1.75k
  OS << "[]";
552
1.75k
  printAfter(T->getElementType(), OS);
553
1.75k
}
554
555
void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
556
251
                                           raw_ostream &OS) {
557
251
  IncludeStrongLifetimeRAII Strong(Policy);
558
251
  printBefore(T->getElementType(), OS);
559
251
}
560
561
void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
562
251
                                          raw_ostream &OS) {
563
251
  OS << '[';
564
251
  if (T->getIndexTypeQualifiers().hasQualifiers()) {
565
1
    AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict);
566
1
    OS << ' ';
567
1
  }
568
569
251
  if (T->getSizeModifier() == VariableArrayType::Static)
570
2
    OS << "static ";
571
249
  else if (T->getSizeModifier() == VariableArrayType::Star)
572
10
    OS << '*';
573
574
251
  if (T->getSizeExpr())
575
241
    T->getSizeExpr()->printPretty(OS, nullptr, Policy);
576
251
  OS << ']';
577
578
251
  printAfter(T->getElementType(), OS);
579
251
}
580
581
278
void TypePrinter::printAdjustedBefore(const AdjustedType *T, raw_ostream &OS) {
582
  // Print the adjusted representation, otherwise the adjustment will be
583
  // invisible.
584
278
  printBefore(T->getAdjustedType(), OS);
585
278
}
586
587
278
void TypePrinter::printAdjustedAfter(const AdjustedType *T, raw_ostream &OS) {
588
278
  printAfter(T->getAdjustedType(), OS);
589
278
}
590
591
278
void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) {
592
  // Print as though it's a pointer.
593
278
  printAdjustedBefore(T, OS);
594
278
}
595
596
278
void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) {
597
278
  printAdjustedAfter(T, OS);
598
278
}
599
600
void TypePrinter::printDependentSizedArrayBefore(
601
                                               const DependentSizedArrayType *T,
602
203
                                               raw_ostream &OS) {
603
203
  IncludeStrongLifetimeRAII Strong(Policy);
604
203
  printBefore(T->getElementType(), OS);
605
203
}
606
607
void TypePrinter::printDependentSizedArrayAfter(
608
                                               const DependentSizedArrayType *T,
609
203
                                               raw_ostream &OS) {
610
203
  OS << '[';
611
203
  if (T->getSizeExpr())
612
203
    T->getSizeExpr()->printPretty(OS, nullptr, Policy);
613
203
  OS << ']';
614
203
  printAfter(T->getElementType(), OS);
615
203
}
616
617
void TypePrinter::printDependentAddressSpaceBefore(
618
2
    const DependentAddressSpaceType *T, raw_ostream &OS) {
619
2
  printBefore(T->getPointeeType(), OS);
620
2
}
621
622
void TypePrinter::printDependentAddressSpaceAfter(
623
2
    const DependentAddressSpaceType *T, raw_ostream &OS) {
624
2
  OS << " __attribute__((address_space(";
625
2
  if (T->getAddrSpaceExpr())
626
2
    T->getAddrSpaceExpr()->printPretty(OS, nullptr, Policy);
627
2
  OS << ")))";
628
2
  printAfter(T->getPointeeType(), OS);
629
2
}
630
631
void TypePrinter::printDependentSizedExtVectorBefore(
632
                                          const DependentSizedExtVectorType *T,
633
42
                                          raw_ostream &OS) {
634
42
  printBefore(T->getElementType(), OS);
635
42
}
636
637
void TypePrinter::printDependentSizedExtVectorAfter(
638
                                          const DependentSizedExtVectorType *T,
639
42
                                          raw_ostream &OS) {
640
42
  OS << " __attribute__((ext_vector_type(";
641
42
  if (T->getSizeExpr())
642
42
    T->getSizeExpr()->printPretty(OS, nullptr, Policy);
643
42
  OS << ")))";
644
42
  printAfter(T->getElementType(), OS);
645
42
}
646
647
4.55k
void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) {
648
4.55k
  switch (T->getVectorKind()) {
649
52
  case VectorType::AltiVecPixel:
650
52
    OS << "__vector __pixel ";
651
52
    break;
652
988
  case VectorType::AltiVecBool:
653
988
    OS << "__vector __bool ";
654
988
    printBefore(T->getElementType(), OS);
655
988
    break;
656
2.02k
  case VectorType::AltiVecVector:
657
2.02k
    OS << "__vector ";
658
2.02k
    printBefore(T->getElementType(), OS);
659
2.02k
    break;
660
124
  case VectorType::NeonVector:
661
124
    OS << "__attribute__((neon_vector_type("
662
124
       << T->getNumElements() << "))) ";
663
124
    printBefore(T->getElementType(), OS);
664
124
    break;
665
0
  case VectorType::NeonPolyVector:
666
0
    OS << "__attribute__((neon_polyvector_type(" <<
667
0
          T->getNumElements() << "))) ";
668
0
    printBefore(T->getElementType(), OS);
669
0
    break;
670
1.23k
  case VectorType::GenericVector: {
671
    // FIXME: We prefer to print the size directly here, but have no way
672
    // to get the size of the type.
673
1.23k
    OS << "__attribute__((__vector_size__("
674
1.23k
       << T->getNumElements()
675
1.23k
       << " * sizeof(";
676
1.23k
    print(T->getElementType(), OS, StringRef());
677
1.23k
    OS << ")))) ";
678
1.23k
    printBefore(T->getElementType(), OS);
679
1.23k
    break;
680
0
  }
681
118
  case VectorType::SveFixedLengthDataVector:
682
134
  case VectorType::SveFixedLengthPredicateVector:
683
    // FIXME: We prefer to print the size directly here, but have no way
684
    // to get the size of the type.
685
134
    OS << "__attribute__((__arm_sve_vector_bits__(";
686
687
134
    if (T->getVectorKind() == VectorType::SveFixedLengthPredicateVector)
688
      // Predicates take a bit per byte of the vector size, multiply by 8 to
689
      // get the number of bits passed to the attribute.
690
16
      OS << T->getNumElements() * 8;
691
118
    else
692
118
      OS << T->getNumElements();
693
694
134
    OS << " * sizeof(";
695
134
    print(T->getElementType(), OS, StringRef());
696
    // Multiply by 8 for the number of bits.
697
134
    OS << ") * 8))) ";
698
134
    printBefore(T->getElementType(), OS);
699
4.55k
  }
700
4.55k
}
701
702
4.55k
void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) {
703
4.55k
  printAfter(T->getElementType(), OS);
704
4.55k
}
705
706
void TypePrinter::printDependentVectorBefore(
707
0
    const DependentVectorType *T, raw_ostream &OS) {
708
0
  switch (T->getVectorKind()) {
709
0
  case VectorType::AltiVecPixel:
710
0
    OS << "__vector __pixel ";
711
0
    break;
712
0
  case VectorType::AltiVecBool:
713
0
    OS << "__vector __bool ";
714
0
    printBefore(T->getElementType(), OS);
715
0
    break;
716
0
  case VectorType::AltiVecVector:
717
0
    OS << "__vector ";
718
0
    printBefore(T->getElementType(), OS);
719
0
    break;
720
0
  case VectorType::NeonVector:
721
0
    OS << "__attribute__((neon_vector_type(";
722
0
    if (T->getSizeExpr())
723
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
724
0
    OS << "))) ";
725
0
    printBefore(T->getElementType(), OS);
726
0
    break;
727
0
  case VectorType::NeonPolyVector:
728
0
    OS << "__attribute__((neon_polyvector_type(";
729
0
    if (T->getSizeExpr())
730
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
731
0
    OS << "))) ";
732
0
    printBefore(T->getElementType(), OS);
733
0
    break;
734
0
  case VectorType::GenericVector: {
735
    // FIXME: We prefer to print the size directly here, but have no way
736
    // to get the size of the type.
737
0
    OS << "__attribute__((__vector_size__(";
738
0
    if (T->getSizeExpr())
739
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
740
0
    OS << " * sizeof(";
741
0
    print(T->getElementType(), OS, StringRef());
742
0
    OS << ")))) ";
743
0
    printBefore(T->getElementType(), OS);
744
0
    break;
745
0
  }
746
0
  case VectorType::SveFixedLengthDataVector:
747
0
  case VectorType::SveFixedLengthPredicateVector:
748
    // FIXME: We prefer to print the size directly here, but have no way
749
    // to get the size of the type.
750
0
    OS << "__attribute__((__arm_sve_vector_bits__(";
751
0
    if (T->getSizeExpr()) {
752
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
753
0
      if (T->getVectorKind() == VectorType::SveFixedLengthPredicateVector)
754
        // Predicates take a bit per byte of the vector size, multiply by 8 to
755
        // get the number of bits passed to the attribute.
756
0
        OS << " * 8";
757
0
      OS << " * sizeof(";
758
0
      print(T->getElementType(), OS, StringRef());
759
      // Multiply by 8 for the number of bits.
760
0
      OS << ") * 8";
761
0
    }
762
0
    OS << "))) ";
763
0
    printBefore(T->getElementType(), OS);
764
0
  }
765
0
}
766
767
void TypePrinter::printDependentVectorAfter(
768
0
    const DependentVectorType *T, raw_ostream &OS) {
769
0
  printAfter(T->getElementType(), OS);
770
0
}
771
772
void TypePrinter::printExtVectorBefore(const ExtVectorType *T,
773
4.14k
                                       raw_ostream &OS) {
774
4.14k
  printBefore(T->getElementType(), OS);
775
4.14k
}
776
777
4.14k
void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) {
778
4.14k
  printAfter(T->getElementType(), OS);
779
4.14k
  OS << " __attribute__((ext_vector_type(";
780
4.14k
  OS << T->getNumElements();
781
4.14k
  OS << ")))";
782
4.14k
}
783
784
void TypePrinter::printConstantMatrixBefore(const ConstantMatrixType *T,
785
611
                                            raw_ostream &OS) {
786
611
  printBefore(T->getElementType(), OS);
787
611
  OS << " __attribute__((matrix_type(";
788
611
  OS << T->getNumRows() << ", " << T->getNumColumns();
789
611
  OS << ")))";
790
611
}
791
792
void TypePrinter::printConstantMatrixAfter(const ConstantMatrixType *T,
793
611
                                           raw_ostream &OS) {
794
611
  printAfter(T->getElementType(), OS);
795
611
}
796
797
void TypePrinter::printDependentSizedMatrixBefore(
798
0
    const DependentSizedMatrixType *T, raw_ostream &OS) {
799
0
  printBefore(T->getElementType(), OS);
800
0
  OS << " __attribute__((matrix_type(";
801
0
  if (T->getRowExpr()) {
802
0
    T->getRowExpr()->printPretty(OS, nullptr, Policy);
803
0
  }
804
0
  OS << ", ";
805
0
  if (T->getColumnExpr()) {
806
0
    T->getColumnExpr()->printPretty(OS, nullptr, Policy);
807
0
  }
808
0
  OS << ")))";
809
0
}
810
811
void TypePrinter::printDependentSizedMatrixAfter(
812
0
    const DependentSizedMatrixType *T, raw_ostream &OS) {
813
0
  printAfter(T->getElementType(), OS);
814
0
}
815
816
void
817
FunctionProtoType::printExceptionSpecification(raw_ostream &OS,
818
                                               const PrintingPolicy &Policy)
819
39.7k
                                                                         const {
820
39.7k
  if (hasDynamicExceptionSpec()) {
821
177
    OS << " throw(";
822
177
    if (getExceptionSpecType() == EST_MSAny)
823
0
      OS << "...";
824
177
    else
825
230
      
for (unsigned I = 0, N = getNumExceptions(); 177
I != N;
++I53
) {
826
53
        if (I)
827
9
          OS << ", ";
828
829
53
        OS << getExceptionType(I).stream(Policy);
830
53
      }
831
177
    OS << ')';
832
39.5k
  } else if (EST_NoThrow == getExceptionSpecType()) {
833
39
    OS << " __attribute__((nothrow))";
834
39.5k
  } else if (isNoexceptExceptionSpec(getExceptionSpecType())) {
835
1.89k
    OS << " noexcept";
836
    // FIXME:Is it useful to print out the expression for a non-dependent
837
    // noexcept specification?
838
1.89k
    if (isComputedNoexcept(getExceptionSpecType())) {
839
36
      OS << '(';
840
36
      if (getNoexceptExpr())
841
36
        getNoexceptExpr()->printPretty(OS, nullptr, Policy);
842
36
      OS << ')';
843
36
    }
844
1.89k
  }
845
39.7k
}
846
847
void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T,
848
39.6k
                                           raw_ostream &OS) {
849
39.6k
  if (T->hasTrailingReturn()) {
850
201
    OS << "auto ";
851
201
    if (!HasEmptyPlaceHolder)
852
37
      OS << '(';
853
39.4k
  } else {
854
    // If needed for precedence reasons, wrap the inner part in grouping parens.
855
39.4k
    SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
856
39.4k
    printBefore(T->getReturnType(), OS);
857
39.4k
    if (!PrevPHIsEmpty.get())
858
25.6k
      OS << '(';
859
39.4k
  }
860
39.6k
}
861
862
31
StringRef clang::getParameterABISpelling(ParameterABI ABI) {
863
31
  switch (ABI) {
864
0
  case ParameterABI::Ordinary:
865
0
    llvm_unreachable("asking for spelling of ordinary parameter ABI");
866
6
  case ParameterABI::SwiftContext:
867
6
    return "swift_context";
868
8
  case ParameterABI::SwiftAsyncContext:
869
8
    return "swift_async_context";
870
9
  case ParameterABI::SwiftErrorResult:
871
9
    return "swift_error_result";
872
8
  case ParameterABI::SwiftIndirectResult:
873
8
    return "swift_indirect_result";
874
31
  }
875
0
  llvm_unreachable("bad parameter ABI kind");
876
0
}
877
878
void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T,
879
39.6k
                                          raw_ostream &OS) {
880
  // If needed for precedence reasons, wrap the inner part in grouping parens.
881
39.6k
  if (!HasEmptyPlaceHolder)
882
25.7k
    OS << ')';
883
39.6k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
884
885
39.6k
  OS << '(';
886
39.6k
  {
887
39.6k
    ParamPolicyRAII ParamPolicy(Policy);
888
73.4k
    for (unsigned i = 0, e = T->getNumParams(); i != e; 
++i33.7k
) {
889
33.7k
      if (i) 
OS << ", "7.04k
;
890
891
33.7k
      auto EPI = T->getExtParameterInfo(i);
892
33.7k
      if (EPI.isConsumed()) 
OS << "__attribute__((ns_consumed)) "159
;
893
33.7k
      if (EPI.isNoEscape())
894
38
        OS << "__attribute__((noescape)) ";
895
33.7k
      auto ABI = EPI.getABI();
896
33.7k
      if (ABI != ParameterABI::Ordinary)
897
0
        OS << "__attribute__((" << getParameterABISpelling(ABI) << ")) ";
898
899
33.7k
      print(T->getParamType(i), OS, StringRef());
900
33.7k
    }
901
39.6k
  }
902
903
39.6k
  if (T->isVariadic()) {
904
539
    if (T->getNumParams())
905
402
      OS << ", ";
906
539
    OS << "...";
907
39.0k
  } else if (T->getNumParams() == 0 && 
Policy.UseVoidForZeroParams12.7k
) {
908
    // Do not emit int() if we have a proto, emit 'int(void)'.
909
1.98k
    OS << "void";
910
1.98k
  }
911
912
39.6k
  OS << ')';
913
914
39.6k
  FunctionType::ExtInfo Info = T->getExtInfo();
915
916
39.6k
  printFunctionAfter(Info, OS);
917
918
39.6k
  if (!T->getMethodQuals().empty())
919
2.26k
    OS << " " << T->getMethodQuals().getAsString();
920
921
39.6k
  switch (T->getRefQualifier()) {
922
39.5k
  case RQ_None:
923
39.5k
    break;
924
925
48
  case RQ_LValue:
926
48
    OS << " &";
927
48
    break;
928
929
35
  case RQ_RValue:
930
35
    OS << " &&";
931
35
    break;
932
39.6k
  }
933
39.6k
  T->printExceptionSpecification(OS, Policy);
934
935
39.6k
  if (T->hasTrailingReturn()) {
936
201
    OS << " -> ";
937
201
    print(T->getReturnType(), OS, StringRef());
938
201
  } else
939
39.4k
    printAfter(T->getReturnType(), OS);
940
39.6k
}
941
942
void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
943
39.9k
                                     raw_ostream &OS) {
944
39.9k
  if (!InsideCCAttribute) {
945
39.6k
    switch (Info.getCC()) {
946
38.5k
    case CC_C:
947
      // The C calling convention is the default on the vast majority of platforms
948
      // we support.  If the user wrote it explicitly, it will usually be printed
949
      // while traversing the AttributedType.  If the type has been desugared, let
950
      // the canonical spelling be the implicit calling convention.
951
      // FIXME: It would be better to be explicit in certain contexts, such as a
952
      // cdecl function typedef used to declare a member function with the
953
      // Microsoft C++ ABI.
954
38.5k
      break;
955
50
    case CC_X86StdCall:
956
50
      OS << " __attribute__((stdcall))";
957
50
      break;
958
43
    case CC_X86FastCall:
959
43
      OS << " __attribute__((fastcall))";
960
43
      break;
961
578
    case CC_X86ThisCall:
962
578
      OS << " __attribute__((thiscall))";
963
578
      break;
964
278
    case CC_X86VectorCall:
965
278
      OS << " __attribute__((vectorcall))";
966
278
      break;
967
1
    case CC_X86Pascal:
968
1
      OS << " __attribute__((pascal))";
969
1
      break;
970
0
    case CC_AAPCS:
971
0
      OS << " __attribute__((pcs(\"aapcs\")))";
972
0
      break;
973
0
    case CC_AAPCS_VFP:
974
0
      OS << " __attribute__((pcs(\"aapcs-vfp\")))";
975
0
      break;
976
3
    case CC_AArch64VectorCall:
977
3
      OS << "__attribute__((aarch64_vector_pcs))";
978
3
      break;
979
3
    case CC_AArch64SVEPCS:
980
3
      OS << "__attribute__((aarch64_sve_pcs))";
981
3
      break;
982
0
    case CC_AMDGPUKernelCall:
983
0
      OS << "__attribute__((amdgpu_kernel))";
984
0
      break;
985
0
    case CC_IntelOclBicc:
986
0
      OS << " __attribute__((intel_ocl_bicc))";
987
0
      break;
988
5
    case CC_Win64:
989
5
      OS << " __attribute__((ms_abi))";
990
5
      break;
991
5
    case CC_X86_64SysV:
992
5
      OS << " __attribute__((sysv_abi))";
993
5
      break;
994
3
    case CC_X86RegCall:
995
3
      OS << " __attribute__((regcall))";
996
3
      break;
997
11
    case CC_SpirFunction:
998
98
    case CC_OpenCLKernel:
999
      // Do nothing. These CCs are not available as attributes.
1000
98
      break;
1001
0
    case CC_Swift:
1002
0
      OS << " __attribute__((swiftcall))";
1003
0
      break;
1004
0
    case CC_SwiftAsync:
1005
0
      OS << "__attribute__((swiftasynccall))";
1006
0
      break;
1007
20
    case CC_PreserveMost:
1008
20
      OS << " __attribute__((preserve_most))";
1009
20
      break;
1010
20
    case CC_PreserveAll:
1011
20
      OS << " __attribute__((preserve_all))";
1012
20
      break;
1013
39.6k
    }
1014
39.6k
  }
1015
1016
39.9k
  if (Info.getNoReturn())
1017
73
    OS << " __attribute__((noreturn))";
1018
39.9k
  if (Info.getCmseNSCall())
1019
18
    OS << " __attribute__((cmse_nonsecure_call))";
1020
39.9k
  if (Info.getProducesResult())
1021
5
    OS << " __attribute__((ns_returns_retained))";
1022
39.9k
  if (Info.getRegParm())
1023
0
    OS << " __attribute__((regparm ("
1024
0
       << Info.getRegParm() << ")))";
1025
39.9k
  if (Info.getNoCallerSavedRegs())
1026
4
    OS << " __attribute__((no_caller_saved_registers))";
1027
39.9k
  if (Info.getNoCfCheck())
1028
10
    OS << " __attribute__((nocf_check))";
1029
39.9k
}
1030
1031
void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T,
1032
270
                                             raw_ostream &OS) {
1033
  // If needed for precedence reasons, wrap the inner part in grouping parens.
1034
270
  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
1035
270
  printBefore(T->getReturnType(), OS);
1036
270
  if (!PrevPHIsEmpty.get())
1037
100
    OS << '(';
1038
270
}
1039
1040
void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T,
1041
270
                                            raw_ostream &OS) {
1042
  // If needed for precedence reasons, wrap the inner part in grouping parens.
1043
270
  if (!HasEmptyPlaceHolder)
1044
100
    OS << ')';
1045
270
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
1046
1047
270
  OS << "()";
1048
270
  printFunctionAfter(T->getExtInfo(), OS);
1049
270
  printAfter(T->getReturnType(), OS);
1050
270
}
1051
1052
63.9k
void TypePrinter::printTypeSpec(NamedDecl *D, raw_ostream &OS) {
1053
1054
  // Compute the full nested-name-specifier for this type.
1055
  // In C, this will always be empty except when the type
1056
  // being printed is anonymous within other Record.
1057
63.9k
  if (!Policy.SuppressScope)
1058
61.3k
    AppendScope(D->getDeclContext(), OS, D->getDeclName());
1059
1060
63.9k
  IdentifierInfo *II = D->getIdentifier();
1061
63.9k
  OS << II->getName();
1062
63.9k
  spaceBeforePlaceHolder(OS);
1063
63.9k
}
1064
1065
void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T,
1066
0
                                             raw_ostream &OS) {
1067
0
  printTypeSpec(T->getDecl(), OS);
1068
0
}
1069
1070
void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T,
1071
0
                                            raw_ostream &OS) {}
1072
1073
67
void TypePrinter::printUsingBefore(const UsingType *T, raw_ostream &OS) {
1074
  // After `namespace b { using a::X }`, is the type X within B a::X or b::X?
1075
  //
1076
  // - b::X is more formally correct given the UsingType model
1077
  // - b::X makes sense if "re-exporting" a symbol in a new namespace
1078
  // - a::X makes sense if "importing" a symbol for convenience
1079
  //
1080
  // The "importing" use seems much more common, so we print a::X.
1081
  // This could be a policy option, but the right choice seems to rest more
1082
  // with the intent of the code than the caller.
1083
67
  printTypeSpec(T->getFoundDecl()->getUnderlyingDecl(), OS);
1084
67
}
1085
1086
67
void TypePrinter::printUsingAfter(const UsingType *T, raw_ostream &OS) {}
1087
1088
41.4k
void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) {
1089
41.4k
  printTypeSpec(T->getDecl(), OS);
1090
41.4k
}
1091
1092
void TypePrinter::printMacroQualifiedBefore(const MacroQualifiedType *T,
1093
37
                                            raw_ostream &OS) {
1094
37
  StringRef MacroName = T->getMacroIdentifier()->getName();
1095
37
  OS << MacroName << " ";
1096
1097
  // Since this type is meant to print the macro instead of the whole attribute,
1098
  // we trim any attributes and go directly to the original modified type.
1099
37
  printBefore(T->getModifiedType(), OS);
1100
37
}
1101
1102
void TypePrinter::printMacroQualifiedAfter(const MacroQualifiedType *T,
1103
37
                                           raw_ostream &OS) {
1104
37
  printAfter(T->getModifiedType(), OS);
1105
37
}
1106
1107
41.4k
void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {}
1108
1109
void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
1110
122
                                        raw_ostream &OS) {
1111
122
  OS << "typeof ";
1112
122
  if (T->getUnderlyingExpr())
1113
122
    T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
1114
122
  spaceBeforePlaceHolder(OS);
1115
122
}
1116
1117
void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
1118
122
                                       raw_ostream &OS) {}
1119
1120
5
void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
1121
5
  OS << "typeof(";
1122
5
  print(T->getUnderlyingType(), OS, StringRef());
1123
5
  OS << ')';
1124
5
  spaceBeforePlaceHolder(OS);
1125
5
}
1126
1127
5
void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) {}
1128
1129
276
void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
1130
276
  OS << "decltype(";
1131
276
  if (T->getUnderlyingExpr())
1132
276
    T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
1133
276
  OS << ')';
1134
276
  spaceBeforePlaceHolder(OS);
1135
276
}
1136
1137
276
void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) {}
1138
1139
void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T,
1140
4
                                            raw_ostream &OS) {
1141
4
  IncludeStrongLifetimeRAII Strong(Policy);
1142
1143
4
  switch (T->getUTTKind()) {
1144
4
    case UnaryTransformType::EnumUnderlyingType:
1145
4
      OS << "__underlying_type(";
1146
4
      print(T->getBaseType(), OS, StringRef());
1147
4
      OS << ')';
1148
4
      spaceBeforePlaceHolder(OS);
1149
4
      return;
1150
4
  }
1151
1152
0
  printBefore(T->getBaseType(), OS);
1153
0
}
1154
1155
void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T,
1156
4
                                           raw_ostream &OS) {
1157
4
  IncludeStrongLifetimeRAII Strong(Policy);
1158
1159
4
  switch (T->getUTTKind()) {
1160
4
    case UnaryTransformType::EnumUnderlyingType:
1161
4
      return;
1162
4
  }
1163
1164
0
  printAfter(T->getBaseType(), OS);
1165
0
}
1166
1167
4.45k
void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
1168
  // If the type has been deduced, do not print 'auto'.
1169
4.45k
  if (!T->getDeducedType().isNull()) {
1170
2.81k
    printBefore(T->getDeducedType(), OS);
1171
2.81k
  } else {
1172
1.63k
    if (T->isConstrained()) {
1173
      // FIXME: Track a TypeConstraint as type sugar, so that we can print the
1174
      // type as it was written.
1175
20
      T->getTypeConstraintConcept()->getDeclName().print(OS, Policy);
1176
20
      auto Args = T->getTypeConstraintArguments();
1177
20
      if (!Args.empty())
1178
10
        printTemplateArgumentList(
1179
10
            OS, Args, Policy,
1180
10
            T->getTypeConstraintConcept()->getTemplateParameters());
1181
20
      OS << ' ';
1182
20
    }
1183
1.63k
    switch (T->getKeyword()) {
1184
1.55k
    case AutoTypeKeyword::Auto: OS << "auto"; break;
1185
81
    case AutoTypeKeyword::DecltypeAuto: OS << "decltype(auto)"; break;
1186
4
    case AutoTypeKeyword::GNUAutoType: OS << "__auto_type"; break;
1187
1.63k
    }
1188
1.63k
    spaceBeforePlaceHolder(OS);
1189
1.63k
  }
1190
4.45k
}
1191
1192
4.45k
void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) {
1193
  // If the type has been deduced, do not print 'auto'.
1194
4.45k
  if (!T->getDeducedType().isNull())
1195
2.81k
    printAfter(T->getDeducedType(), OS);
1196
4.45k
}
1197
1198
void TypePrinter::printDeducedTemplateSpecializationBefore(
1199
182
    const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1200
  // If the type has been deduced, print the deduced type.
1201
182
  if (!T->getDeducedType().isNull()) {
1202
57
    printBefore(T->getDeducedType(), OS);
1203
125
  } else {
1204
125
    IncludeStrongLifetimeRAII Strong(Policy);
1205
125
    T->getTemplateName().print(OS, Policy);
1206
125
    spaceBeforePlaceHolder(OS);
1207
125
  }
1208
182
}
1209
1210
void TypePrinter::printDeducedTemplateSpecializationAfter(
1211
182
    const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1212
  // If the type has been deduced, print the deduced type.
1213
182
  if (!T->getDeducedType().isNull())
1214
57
    printAfter(T->getDeducedType(), OS);
1215
182
}
1216
1217
752
void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) {
1218
752
  IncludeStrongLifetimeRAII Strong(Policy);
1219
1220
752
  OS << "_Atomic(";
1221
752
  print(T->getValueType(), OS, StringRef());
1222
752
  OS << ')';
1223
752
  spaceBeforePlaceHolder(OS);
1224
752
}
1225
1226
752
void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) {}
1227
1228
262
void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
1229
262
  IncludeStrongLifetimeRAII Strong(Policy);
1230
1231
262
  if (T->isReadOnly())
1232
208
    OS << "read_only ";
1233
54
  else
1234
54
    OS << "write_only ";
1235
262
  OS << "pipe ";
1236
262
  print(T->getElementType(), OS, StringRef());
1237
262
  spaceBeforePlaceHolder(OS);
1238
262
}
1239
1240
262
void TypePrinter::printPipeAfter(const PipeType *T, raw_ostream &OS) {}
1241
1242
138
void TypePrinter::printBitIntBefore(const BitIntType *T, raw_ostream &OS) {
1243
138
  if (T->isUnsigned())
1244
40
    OS << "unsigned ";
1245
138
  OS << "_BitInt(" << T->getNumBits() << ")";
1246
138
  spaceBeforePlaceHolder(OS);
1247
138
}
1248
1249
138
void TypePrinter::printBitIntAfter(const BitIntType *T, raw_ostream &OS) {}
1250
1251
void TypePrinter::printDependentBitIntBefore(const DependentBitIntType *T,
1252
0
                                             raw_ostream &OS) {
1253
0
  if (T->isUnsigned())
1254
0
    OS << "unsigned ";
1255
0
  OS << "_BitInt(";
1256
0
  T->getNumBitsExpr()->printPretty(OS, nullptr, Policy);
1257
0
  OS << ")";
1258
0
  spaceBeforePlaceHolder(OS);
1259
0
}
1260
1261
void TypePrinter::printDependentBitIntAfter(const DependentBitIntType *T,
1262
0
                                            raw_ostream &OS) {}
1263
1264
/// Appends the given scope to the end of a string.
1265
void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS,
1266
2.65M
                              DeclarationName NameInScope) {
1267
2.65M
  if (DC->isTranslationUnit())
1268
1.04M
    return;
1269
1270
  // FIXME: Consider replacing this with NamedDecl::printNestedNameSpecifier,
1271
  // which can also print names for function and method scopes.
1272
1.60M
  if (DC->isFunctionOrMethod())
1273
12.4k
    return;
1274
1275
1.59M
  if (Policy.Callbacks && 
Policy.Callbacks->isScopeVisible(DC)437k
)
1276
0
    return;
1277
1278
1.59M
  if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1279
1.54M
    if (Policy.SuppressUnwrittenScope && 
NS->isAnonymousNamespace()19.6k
)
1280
41
      return AppendScope(DC->getParent(), OS, NameInScope);
1281
1282
    // Only suppress an inline namespace if the name has the same lookup
1283
    // results in the enclosing namespace.
1284
1.54M
    if (Policy.SuppressInlineNamespace && 
NS->isInline()385k
&&
NameInScope158k
&&
1285
1.54M
        
NS->isRedundantInlineQualifierFor(NameInScope)158k
)
1286
158k
      return AppendScope(DC->getParent(), OS, NameInScope);
1287
1288
1.38M
    AppendScope(DC->getParent(), OS, NS->getDeclName());
1289
1.38M
    if (NS->getIdentifier())
1290
1.38M
      OS << NS->getName() << "::";
1291
207
    else
1292
207
      OS << "(anonymous namespace)::";
1293
1.38M
  } else 
if (const auto *56.5k
Spec56.5k
= dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1294
26.9k
    AppendScope(DC->getParent(), OS, Spec->getDeclName());
1295
26.9k
    IncludeStrongLifetimeRAII Strong(Policy);
1296
26.9k
    OS << Spec->getIdentifier()->getName();
1297
26.9k
    const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1298
26.9k
    printTemplateArgumentList(
1299
26.9k
        OS, TemplateArgs.asArray(), Policy,
1300
26.9k
        Spec->getSpecializedTemplate()->getTemplateParameters());
1301
26.9k
    OS << "::";
1302
29.6k
  } else if (const auto *Tag = dyn_cast<TagDecl>(DC)) {
1303
14.2k
    AppendScope(DC->getParent(), OS, Tag->getDeclName());
1304
14.2k
    if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
1305
27
      OS << Typedef->getIdentifier()->getName() << "::";
1306
14.1k
    else if (Tag->getIdentifier())
1307
14.0k
      OS << Tag->getIdentifier()->getName() << "::";
1308
166
    else
1309
166
      return;
1310
15.4k
  } else {
1311
15.4k
    AppendScope(DC->getParent(), OS, NameInScope);
1312
15.4k
  }
1313
1.59M
}
1314
1315
1.02M
void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
1316
1.02M
  if (Policy.IncludeTagDefinition) {
1317
0
    PrintingPolicy SubPolicy = Policy;
1318
0
    SubPolicy.IncludeTagDefinition = false;
1319
0
    D->print(OS, SubPolicy, Indentation);
1320
0
    spaceBeforePlaceHolder(OS);
1321
0
    return;
1322
0
  }
1323
1324
1.02M
  bool HasKindDecoration = false;
1325
1326
  // We don't print tags unless this is an elaborated type.
1327
  // In C, we just assume every RecordType is an elaborated type.
1328
1.02M
  if (!Policy.SuppressTagKeyword && 
!D->getTypedefNameForAnonDecl()15.3k
) {
1329
15.0k
    HasKindDecoration = true;
1330
15.0k
    OS << D->getKindName();
1331
15.0k
    OS << ' ';
1332
15.0k
  }
1333
1334
  // Compute the full nested-name-specifier for this type.
1335
  // In C, this will always be empty except when the type
1336
  // being printed is anonymous within other Record.
1337
1.02M
  if (!Policy.SuppressScope)
1338
1.00M
    AppendScope(D->getDeclContext(), OS, D->getDeclName());
1339
1340
1.02M
  if (const IdentifierInfo *II = D->getIdentifier())
1341
1.00M
    OS << II->getName();
1342
16.8k
  else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
1343
815
    assert(Typedef->getIdentifier() && "Typedef without identifier?");
1344
0
    OS << Typedef->getIdentifier()->getName();
1345
16.0k
  } else {
1346
    // Make an unambiguous representation for anonymous types, e.g.
1347
    //   (anonymous enum at /usr/include/string.h:120:9)
1348
16.0k
    OS << (Policy.MSVCFormatting ? 
'`'5
:
'('16.0k
);
1349
1350
16.0k
    if (isa<CXXRecordDecl>(D) && 
cast<CXXRecordDecl>(D)->isLambda()14.9k
) {
1351
8.21k
      OS << "lambda";
1352
8.21k
      HasKindDecoration = true;
1353
8.21k
    } else 
if (7.80k
(7.80k
isa<RecordDecl>(D)7.80k
&&
cast<RecordDecl>(D)->isAnonymousStructOrUnion()7.49k
)) {
1354
5.92k
      OS << "anonymous";
1355
5.92k
    } else {
1356
1.87k
      OS << "unnamed";
1357
1.87k
    }
1358
1359
16.0k
    if (Policy.AnonymousTagLocations) {
1360
      // Suppress the redundant tag keyword if we just printed one.
1361
      // We don't have to worry about ElaboratedTypes here because you can't
1362
      // refer to an anonymous type with one.
1363
16.0k
      if (!HasKindDecoration)
1364
6.96k
        OS << " " << D->getKindName();
1365
1366
16.0k
      PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
1367
16.0k
          D->getLocation());
1368
16.0k
      if (PLoc.isValid()) {
1369
9.90k
        OS << " at ";
1370
9.90k
        StringRef File = PLoc.getFilename();
1371
9.90k
        if (auto *Callbacks = Policy.Callbacks)
1372
3.20k
          OS << Callbacks->remapPath(File);
1373
6.70k
        else
1374
6.70k
          OS << File;
1375
9.90k
        OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
1376
9.90k
      }
1377
16.0k
    }
1378
1379
16.0k
    OS << (Policy.MSVCFormatting ? 
'\''5
:
')'16.0k
);
1380
16.0k
  }
1381
1382
  // If this is a class template specialization, print the template
1383
  // arguments.
1384
1.02M
  if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1385
636k
    ArrayRef<TemplateArgument> Args;
1386
636k
    TypeSourceInfo *TAW = Spec->getTypeAsWritten();
1387
636k
    if (!Policy.PrintCanonicalTypes && 
TAW366k
) {
1388
1.34k
      const TemplateSpecializationType *TST =
1389
1.34k
        cast<TemplateSpecializationType>(TAW->getType());
1390
1.34k
      Args = TST->template_arguments();
1391
634k
    } else {
1392
634k
      const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1393
634k
      Args = TemplateArgs.asArray();
1394
634k
    }
1395
636k
    IncludeStrongLifetimeRAII Strong(Policy);
1396
636k
    printTemplateArgumentList(
1397
636k
        OS, Args, Policy,
1398
636k
        Spec->getSpecializedTemplate()->getTemplateParameters());
1399
636k
  }
1400
1401
1.02M
  spaceBeforePlaceHolder(OS);
1402
1.02M
}
1403
1404
1.03M
void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
1405
  // Print the preferred name if we have one for this type.
1406
1.03M
  if (Policy.UsePreferredNames) {
1407
822k
    for (const auto *PNA : T->getDecl()->specific_attrs<PreferredNameAttr>()) {
1408
22.5k
      if (!declaresSameEntity(PNA->getTypedefType()->getAsCXXRecordDecl(),
1409
22.5k
                              T->getDecl()))
1410
64
        continue;
1411
      // Find the outermost typedef or alias template.
1412
22.4k
      QualType T = PNA->getTypedefType();
1413
22.4k
      while (true) {
1414
22.4k
        if (auto *TT = dyn_cast<TypedefType>(T))
1415
22.3k
          return printTypeSpec(TT->getDecl(), OS);
1416
104
        if (auto *TST = dyn_cast<TemplateSpecializationType>(T))
1417
52
          return printTemplateId(TST, OS, /*FullyQualify=*/true);
1418
52
        T = T->getLocallyUnqualifiedSingleStepDesugaredType();
1419
52
      }
1420
22.4k
    }
1421
822k
  }
1422
1423
1.01M
  printTag(T->getDecl(), OS);
1424
1.01M
}
1425
1426
1.03M
void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) {}
1427
1428
10.0k
void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) {
1429
10.0k
  printTag(T->getDecl(), OS);
1430
10.0k
}
1431
1432
10.0k
void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) {}
1433
1434
void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T,
1435
326k
                                              raw_ostream &OS) {
1436
326k
  TemplateTypeParmDecl *D = T->getDecl();
1437
326k
  if (D && 
D->isImplicit()322k
) {
1438
174
    if (auto *TC = D->getTypeConstraint()) {
1439
18
      TC->print(OS, Policy);
1440
18
      OS << ' ';
1441
18
    }
1442
174
    OS << "auto";
1443
326k
  } else if (IdentifierInfo *Id = T->getIdentifier())
1444
308k
    OS << (Policy.CleanUglifiedParameters ? 
Id->deuglifiedName()992
1445
308k
                                          : 
Id->getName()307k
);
1446
17.6k
  else
1447
17.6k
    OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex();
1448
1449
326k
  spaceBeforePlaceHolder(OS);
1450
326k
}
1451
1452
void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T,
1453
328k
                                             raw_ostream &OS) {}
1454
1455
void TypePrinter::printSubstTemplateTypeParmBefore(
1456
                                             const SubstTemplateTypeParmType *T,
1457
18.9k
                                             raw_ostream &OS) {
1458
18.9k
  IncludeStrongLifetimeRAII Strong(Policy);
1459
18.9k
  printBefore(T->getReplacementType(), OS);
1460
18.9k
}
1461
1462
void TypePrinter::printSubstTemplateTypeParmAfter(
1463
                                             const SubstTemplateTypeParmType *T,
1464
21.0k
                                             raw_ostream &OS) {
1465
21.0k
  IncludeStrongLifetimeRAII Strong(Policy);
1466
21.0k
  printAfter(T->getReplacementType(), OS);
1467
21.0k
}
1468
1469
void TypePrinter::printSubstTemplateTypeParmPackBefore(
1470
                                        const SubstTemplateTypeParmPackType *T,
1471
28
                                        raw_ostream &OS) {
1472
28
  IncludeStrongLifetimeRAII Strong(Policy);
1473
28
  printTemplateTypeParmBefore(T->getReplacedParameter(), OS);
1474
28
}
1475
1476
void TypePrinter::printSubstTemplateTypeParmPackAfter(
1477
                                        const SubstTemplateTypeParmPackType *T,
1478
28
                                        raw_ostream &OS) {
1479
28
  IncludeStrongLifetimeRAII Strong(Policy);
1480
28
  printTemplateTypeParmAfter(T->getReplacedParameter(), OS);
1481
28
}
1482
1483
void TypePrinter::printTemplateId(const TemplateSpecializationType *T,
1484
188k
                                  raw_ostream &OS, bool FullyQualify) {
1485
188k
  IncludeStrongLifetimeRAII Strong(Policy);
1486
1487
188k
  TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
1488
  // FIXME: Null TD never excercised in test suite.
1489
188k
  if (FullyQualify && 
TD54
) {
1490
54
    if (!Policy.SuppressScope)
1491
20
      AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
1492
1493
54
    OS << TD->getName();
1494
188k
  } else {
1495
188k
    T->getTemplateName().print(OS, Policy);
1496
188k
  }
1497
1498
188k
  DefaultTemplateArgsPolicyRAII TemplateArgs(Policy);
1499
188k
  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : 
nullptr0
;
1500
188k
  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
1501
188k
  spaceBeforePlaceHolder(OS);
1502
188k
}
1503
1504
void TypePrinter::printTemplateSpecializationBefore(
1505
                                            const TemplateSpecializationType *T,
1506
188k
                                            raw_ostream &OS) {
1507
188k
  printTemplateId(T, OS, Policy.FullyQualifiedName);
1508
188k
}
1509
1510
void TypePrinter::printTemplateSpecializationAfter(
1511
                                            const TemplateSpecializationType *T,
1512
6.89k
                                            raw_ostream &OS) {}
1513
1514
void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T,
1515
181k
                                               raw_ostream &OS) {
1516
181k
  if (Policy.PrintInjectedClassNameWithArguments)
1517
181k
    return printTemplateSpecializationBefore(T->getInjectedTST(), OS);
1518
1519
0
  IncludeStrongLifetimeRAII Strong(Policy);
1520
0
  T->getTemplateName().print(OS, Policy);
1521
0
  spaceBeforePlaceHolder(OS);
1522
0
}
1523
1524
void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
1525
181k
                                               raw_ostream &OS) {}
1526
1527
void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
1528
5.40k
                                        raw_ostream &OS) {
1529
5.40k
  if (Policy.IncludeTagDefinition && 
T->getOwnedTagDecl()252
) {
1530
252
    TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
1531
252
    assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
1532
252
           "OwnedTagDecl expected to be a declaration for the type");
1533
0
    PrintingPolicy SubPolicy = Policy;
1534
252
    SubPolicy.IncludeTagDefinition = false;
1535
252
    OwnedTagDecl->print(OS, SubPolicy, Indentation);
1536
252
    spaceBeforePlaceHolder(OS);
1537
252
    return;
1538
252
  }
1539
1540
  // The tag definition will take care of these.
1541
5.15k
  if (!Policy.IncludeTagDefinition)
1542
5.15k
  {
1543
5.15k
    OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1544
5.15k
    if (T->getKeyword() != ETK_None)
1545
3.87k
      OS << " ";
1546
5.15k
    NestedNameSpecifier *Qualifier = T->getQualifier();
1547
5.15k
    if (Qualifier)
1548
1.81k
      Qualifier->print(OS, Policy);
1549
5.15k
  }
1550
1551
5.15k
  ElaboratedTypePolicyRAII PolicyRAII(Policy);
1552
5.15k
  printBefore(T->getNamedType(), OS);
1553
5.15k
}
1554
1555
void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
1556
5.43k
                                        raw_ostream &OS) {
1557
5.43k
  if (Policy.IncludeTagDefinition && 
T->getOwnedTagDecl()252
)
1558
252
    return;
1559
5.17k
  ElaboratedTypePolicyRAII PolicyRAII(Policy);
1560
5.17k
  printAfter(T->getNamedType(), OS);
1561
5.17k
}
1562
1563
2.96k
void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) {
1564
2.96k
  if (!HasEmptyPlaceHolder && 
!isa<FunctionType>(T->getInnerType())2.72k
) {
1565
377
    printBefore(T->getInnerType(), OS);
1566
377
    OS << '(';
1567
377
  } else
1568
2.58k
    printBefore(T->getInnerType(), OS);
1569
2.96k
}
1570
1571
2.96k
void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) {
1572
2.96k
  if (!HasEmptyPlaceHolder && 
!isa<FunctionType>(T->getInnerType())2.72k
) {
1573
376
    OS << ')';
1574
376
    printAfter(T->getInnerType(), OS);
1575
376
  } else
1576
2.58k
    printAfter(T->getInnerType(), OS);
1577
2.96k
}
1578
1579
void TypePrinter::printDependentNameBefore(const DependentNameType *T,
1580
275
                                           raw_ostream &OS) {
1581
275
  OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1582
275
  if (T->getKeyword() != ETK_None)
1583
268
    OS << " ";
1584
1585
275
  T->getQualifier()->print(OS, Policy);
1586
1587
275
  OS << T->getIdentifier()->getName();
1588
275
  spaceBeforePlaceHolder(OS);
1589
275
}
1590
1591
void TypePrinter::printDependentNameAfter(const DependentNameType *T,
1592
275
                                          raw_ostream &OS) {}
1593
1594
void TypePrinter::printDependentTemplateSpecializationBefore(
1595
13
        const DependentTemplateSpecializationType *T, raw_ostream &OS) {
1596
13
  IncludeStrongLifetimeRAII Strong(Policy);
1597
1598
13
  OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1599
13
  if (T->getKeyword() != ETK_None)
1600
13
    OS << " ";
1601
1602
13
  if (T->getQualifier())
1603
13
    T->getQualifier()->print(OS, Policy);
1604
13
  OS << "template " << T->getIdentifier()->getName();
1605
13
  printTemplateArgumentList(OS, T->template_arguments(), Policy);
1606
13
  spaceBeforePlaceHolder(OS);
1607
13
}
1608
1609
void TypePrinter::printDependentTemplateSpecializationAfter(
1610
13
        const DependentTemplateSpecializationType *T, raw_ostream &OS) {}
1611
1612
void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
1613
39.0k
                                           raw_ostream &OS) {
1614
39.0k
  printBefore(T->getPattern(), OS);
1615
39.0k
}
1616
1617
void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
1618
39.0k
                                          raw_ostream &OS) {
1619
39.0k
  printAfter(T->getPattern(), OS);
1620
39.0k
  OS << "...";
1621
39.0k
}
1622
1623
void TypePrinter::printAttributedBefore(const AttributedType *T,
1624
1.74k
                                        raw_ostream &OS) {
1625
  // FIXME: Generate this with TableGen.
1626
1627
  // Prefer the macro forms of the GC and ownership qualifiers.
1628
1.74k
  if (T->getAttrKind() == attr::ObjCGC ||
1629
1.74k
      
T->getAttrKind() == attr::ObjCOwnership1.70k
)
1630
496
    return printBefore(T->getEquivalentType(), OS);
1631
1632
1.24k
  if (T->getAttrKind() == attr::ObjCKindOf)
1633
76
    OS << "__kindof ";
1634
1635
1.24k
  if (T->getAttrKind() == attr::AddressSpace)
1636
64
    printBefore(T->getEquivalentType(), OS);
1637
1.18k
  else
1638
1.18k
    printBefore(T->getModifiedType(), OS);
1639
1640
1.24k
  if (T->isMSTypeSpec()) {
1641
11
    switch (T->getAttrKind()) {
1642
0
    default: return;
1643
5
    case attr::Ptr32: OS << " __ptr32"; break;
1644
2
    case attr::Ptr64: OS << " __ptr64"; break;
1645
2
    case attr::SPtr: OS << " __sptr"; break;
1646
2
    case attr::UPtr: OS << " __uptr"; break;
1647
11
    }
1648
11
    spaceBeforePlaceHolder(OS);
1649
11
  }
1650
1651
  // Print nullability type specifiers.
1652
1.24k
  if (T->getImmediateNullability()) {
1653
824
    if (T->getAttrKind() == attr::TypeNonNull)
1654
219
      OS << " _Nonnull";
1655
605
    else if (T->getAttrKind() == attr::TypeNullable)
1656
581
      OS << " _Nullable";
1657
24
    else if (T->getAttrKind() == attr::TypeNullUnspecified)
1658
16
      OS << " _Null_unspecified";
1659
8
    else if (T->getAttrKind() == attr::TypeNullableResult)
1660
8
      OS << " _Nullable_result";
1661
0
    else
1662
0
      llvm_unreachable("unhandled nullability");
1663
824
    spaceBeforePlaceHolder(OS);
1664
824
  }
1665
1.24k
}
1666
1667
void TypePrinter::printAttributedAfter(const AttributedType *T,
1668
1.68k
                                       raw_ostream &OS) {
1669
  // FIXME: Generate this with TableGen.
1670
1671
  // Prefer the macro forms of the GC and ownership qualifiers.
1672
1.68k
  if (T->getAttrKind() == attr::ObjCGC ||
1673
1.68k
      
T->getAttrKind() == attr::ObjCOwnership1.64k
)
1674
496
    return printAfter(T->getEquivalentType(), OS);
1675
1676
  // If this is a calling convention attribute, don't print the implicit CC from
1677
  // the modified type.
1678
1.18k
  SaveAndRestore<bool> MaybeSuppressCC(InsideCCAttribute, T->isCallingConv());
1679
1680
1.18k
  printAfter(T->getModifiedType(), OS);
1681
1682
  // Some attributes are printed as qualifiers before the type, so we have
1683
  // nothing left to do.
1684
1.18k
  if (T->getAttrKind() == attr::ObjCKindOf ||
1685
1.18k
      
T->isMSTypeSpec()1.16k
||
T->getImmediateNullability()1.15k
)
1686
852
    return;
1687
1688
  // Don't print the inert __unsafe_unretained attribute at all.
1689
334
  if (T->getAttrKind() == attr::ObjCInertUnsafeUnretained)
1690
2
    return;
1691
1692
  // Don't print ns_returns_retained unless it had an effect.
1693
332
  if (T->getAttrKind() == attr::NSReturnsRetained &&
1694
332
      !T->getEquivalentType()->castAs<FunctionType>()
1695
3
                             ->getExtInfo().getProducesResult())
1696
0
    return;
1697
1698
332
  if (T->getAttrKind() == attr::LifetimeBound) {
1699
0
    OS << " [[clang::lifetimebound]]";
1700
0
    return;
1701
0
  }
1702
1703
  // The printing of the address_space attribute is handled by the qualifier
1704
  // since it is still stored in the qualifier. Return early to prevent printing
1705
  // this twice.
1706
332
  if (T->getAttrKind() == attr::AddressSpace)
1707
64
    return;
1708
1709
268
  if (T->getAttrKind() == attr::AnnotateType) {
1710
    // FIXME: Print the attribute arguments once we have a way to retrieve these
1711
    // here. For the meantime, we just print `[[clang::annotate_type(...)]]`
1712
    // without the arguments so that we know at least that we had _some_
1713
    // annotation on the type.
1714
2
    OS << " [[clang::annotate_type(...)]]";
1715
2
    return;
1716
2
  }
1717
1718
266
  OS << " __attribute__((";
1719
266
  switch (T->getAttrKind()) {
1720
0
#define TYPE_ATTR(NAME)
1721
0
#define DECL_OR_TYPE_ATTR(NAME)
1722
0
#define ATTR(NAME) case attr::NAME:
1723
0
#include "clang/Basic/AttrList.inc"
1724
0
    llvm_unreachable("non-type attribute attached to type");
1725
1726
0
  case attr::BTFTypeTag:
1727
0
    llvm_unreachable("BTFTypeTag attribute handled separately");
1728
1729
0
  case attr::OpenCLPrivateAddressSpace:
1730
0
  case attr::OpenCLGlobalAddressSpace:
1731
0
  case attr::OpenCLGlobalDeviceAddressSpace:
1732
0
  case attr::OpenCLGlobalHostAddressSpace:
1733
0
  case attr::OpenCLLocalAddressSpace:
1734
0
  case attr::OpenCLConstantAddressSpace:
1735
0
  case attr::OpenCLGenericAddressSpace:
1736
    // FIXME: Update printAttributedBefore to print these once we generate
1737
    // AttributedType nodes for them.
1738
0
    break;
1739
1740
0
  case attr::LifetimeBound:
1741
0
  case attr::TypeNonNull:
1742
0
  case attr::TypeNullable:
1743
0
  case attr::TypeNullableResult:
1744
0
  case attr::TypeNullUnspecified:
1745
0
  case attr::ObjCGC:
1746
0
  case attr::ObjCInertUnsafeUnretained:
1747
0
  case attr::ObjCKindOf:
1748
0
  case attr::ObjCOwnership:
1749
0
  case attr::Ptr32:
1750
0
  case attr::Ptr64:
1751
0
  case attr::SPtr:
1752
0
  case attr::UPtr:
1753
0
  case attr::AddressSpace:
1754
0
  case attr::CmseNSCall:
1755
0
  case attr::AnnotateType:
1756
0
    llvm_unreachable("This attribute should have been handled already");
1757
1758
3
  case attr::NSReturnsRetained:
1759
3
    OS << "ns_returns_retained";
1760
3
    break;
1761
1762
  // FIXME: When Sema learns to form this AttributedType, avoid printing the
1763
  // attribute again in printFunctionProtoAfter.
1764
0
  case attr::AnyX86NoCfCheck: OS << "nocf_check"; break;
1765
100
  case attr::CDecl: OS << "cdecl"; break;
1766
25
  case attr::FastCall: OS << "fastcall"; break;
1767
26
  case attr::StdCall: OS << "stdcall"; break;
1768
29
  case attr::ThisCall: OS << "thiscall"; break;
1769
0
  case attr::SwiftCall: OS << "swiftcall"; break;
1770
0
  case attr::SwiftAsyncCall: OS << "swiftasynccall"; break;
1771
23
  case attr::VectorCall: OS << "vectorcall"; break;
1772
0
  case attr::Pascal: OS << "pascal"; break;
1773
6
  case attr::MSABI: OS << "ms_abi"; break;
1774
6
  case attr::SysVABI: OS << "sysv_abi"; break;
1775
2
  case attr::RegCall: OS << "regcall"; break;
1776
0
  case attr::Pcs: {
1777
0
    OS << "pcs(";
1778
0
   QualType t = T->getEquivalentType();
1779
0
   while (!t->isFunctionType())
1780
0
     t = t->getPointeeType();
1781
0
   OS << (t->castAs<FunctionType>()->getCallConv() == CC_AAPCS ?
1782
0
         "\"aapcs\"" : "\"aapcs-vfp\"");
1783
0
   OS << ')';
1784
0
   break;
1785
0
  }
1786
0
  case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break;
1787
0
  case attr::AArch64SVEPcs: OS << "aarch64_sve_pcs"; break;
1788
0
  case attr::AMDGPUKernelCall: OS << "amdgpu_kernel"; break;
1789
0
  case attr::IntelOclBicc: OS << "inteloclbicc"; break;
1790
20
  case attr::PreserveMost:
1791
20
    OS << "preserve_most";
1792
20
    break;
1793
1794
20
  case attr::PreserveAll:
1795
20
    OS << "preserve_all";
1796
20
    break;
1797
6
  case attr::NoDeref:
1798
6
    OS << "noderef";
1799
6
    break;
1800
0
  case attr::AcquireHandle:
1801
0
    OS << "acquire_handle";
1802
0
    break;
1803
0
  case attr::ArmMveStrictPolymorphism:
1804
0
    OS << "__clang_arm_mve_strict_polymorphism";
1805
0
    break;
1806
266
  }
1807
266
  OS << "))";
1808
266
}
1809
1810
void TypePrinter::printBTFTagAttributedBefore(const BTFTagAttributedType *T,
1811
2
                                              raw_ostream &OS) {
1812
2
  printBefore(T->getWrappedType(), OS);
1813
2
  OS << " btf_type_tag(" << T->getAttr()->getBTFTypeTag() << ")";
1814
2
}
1815
1816
void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T,
1817
2
                                             raw_ostream &OS) {
1818
2
  printAfter(T->getWrappedType(), OS);
1819
2
}
1820
1821
void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
1822
35.7k
                                           raw_ostream &OS) {
1823
35.7k
  OS << T->getDecl()->getName();
1824
35.7k
  spaceBeforePlaceHolder(OS);
1825
35.7k
}
1826
1827
void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T,
1828
14.4k
                                          raw_ostream &OS) {}
1829
1830
void TypePrinter::printObjCTypeParamBefore(const ObjCTypeParamType *T,
1831
101
                                          raw_ostream &OS) {
1832
101
  OS << T->getDecl()->getName();
1833
101
  if (!T->qual_empty()) {
1834
0
    bool isFirst = true;
1835
0
    OS << '<';
1836
0
    for (const auto *I : T->quals()) {
1837
0
      if (isFirst)
1838
0
        isFirst = false;
1839
0
      else
1840
0
        OS << ',';
1841
0
      OS << I->getName();
1842
0
    }
1843
0
    OS << '>';
1844
0
  }
1845
1846
101
  spaceBeforePlaceHolder(OS);
1847
101
}
1848
1849
void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T,
1850
101
                                          raw_ostream &OS) {}
1851
1852
void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T,
1853
7.16k
                                        raw_ostream &OS) {
1854
7.16k
  if (T->qual_empty() && 
T->isUnspecializedAsWritten()5.55k
&&
1855
7.16k
      
!T->isKindOfTypeAsWritten()4.87k
)
1856
4.81k
    return printBefore(T->getBaseType(), OS);
1857
1858
2.34k
  if (T->isKindOfTypeAsWritten())
1859
68
    OS << "__kindof ";
1860
1861
2.34k
  print(T->getBaseType(), OS, StringRef());
1862
1863
2.34k
  if (T->isSpecializedAsWritten()) {
1864
687
    bool isFirst = true;
1865
687
    OS << '<';
1866
716
    for (auto typeArg : T->getTypeArgsAsWritten()) {
1867
716
      if (isFirst)
1868
687
        isFirst = false;
1869
29
      else
1870
29
        OS << ",";
1871
1872
716
      print(typeArg, OS, StringRef());
1873
716
    }
1874
687
    OS << '>';
1875
687
  }
1876
1877
2.34k
  if (!T->qual_empty()) {
1878
1.61k
    bool isFirst = true;
1879
1.61k
    OS << '<';
1880
2.46k
    for (const auto *I : T->quals()) {
1881
2.46k
      if (isFirst)
1882
1.61k
        isFirst = false;
1883
859
      else
1884
859
        OS << ',';
1885
2.46k
      OS << I->getName();
1886
2.46k
    }
1887
1.61k
    OS << '>';
1888
1.61k
  }
1889
1890
2.34k
  spaceBeforePlaceHolder(OS);
1891
2.34k
}
1892
1893
void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1894
2.02k
                                        raw_ostream &OS) {
1895
2.02k
  if (T->qual_empty() && 
T->isUnspecializedAsWritten()1.99k
&&
1896
2.02k
      
!T->isKindOfTypeAsWritten()1.98k
)
1897
1.98k
    return printAfter(T->getBaseType(), OS);
1898
2.02k
}
1899
1900
void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1901
26.4k
                                               raw_ostream &OS) {
1902
26.4k
  printBefore(T->getPointeeType(), OS);
1903
1904
  // If we need to print the pointer, print it now.
1905
26.4k
  if (!T->isObjCIdType() && 
!T->isObjCQualifiedIdType()24.0k
&&
1906
26.4k
      
!T->isObjCClassType()22.9k
&&
!T->isObjCQualifiedClassType()22.4k
) {
1907
22.3k
    if (HasEmptyPlaceHolder)
1908
21.0k
      OS << ' ';
1909
22.3k
    OS << '*';
1910
22.3k
  }
1911
26.4k
}
1912
1913
void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
1914
26.4k
                                              raw_ostream &OS) {}
1915
1916
static
1917
2.28M
const TemplateArgument &getArgument(const TemplateArgument &A) { return A; }
1918
1919
4.10k
static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) {
1920
4.10k
  return A.getArgument();
1921
4.10k
}
1922
1923
static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
1924
2.10M
                          llvm::raw_ostream &OS, bool IncludeType) {
1925
2.10M
  A.print(PP, OS, IncludeType);
1926
2.10M
}
1927
1928
static void printArgument(const TemplateArgumentLoc &A,
1929
                          const PrintingPolicy &PP, llvm::raw_ostream &OS,
1930
3.79k
                          bool IncludeType) {
1931
3.79k
  const TemplateArgument::ArgKind &Kind = A.getArgument().getKind();
1932
3.79k
  if (Kind == TemplateArgument::ArgKind::Type)
1933
3.29k
    return A.getTypeSourceInfo()->getType().print(OS, PP);
1934
505
  return A.getArgument().print(PP, OS, IncludeType);
1935
3.79k
}
1936
1937
static bool isSubstitutedTemplateArgument(ASTContext &Ctx, TemplateArgument Arg,
1938
                                          TemplateArgument Pattern,
1939
                                          ArrayRef<TemplateArgument> Args,
1940
                                          unsigned Depth);
1941
1942
static bool isSubstitutedType(ASTContext &Ctx, QualType T, QualType Pattern,
1943
6.97k
                              ArrayRef<TemplateArgument> Args, unsigned Depth) {
1944
6.97k
  if (Ctx.hasSameType(T, Pattern))
1945
0
    return true;
1946
1947
  // A type parameter matches its argument.
1948
6.97k
  if (auto *TTPT = Pattern->getAs<TemplateTypeParmType>()) {
1949
3.13k
    if (TTPT->getDepth() == Depth && TTPT->getIndex() < Args.size() &&
1950
3.13k
        Args[TTPT->getIndex()].getKind() == TemplateArgument::Type) {
1951
3.13k
      QualType SubstArg = Ctx.getQualifiedType(
1952
3.13k
          Args[TTPT->getIndex()].getAsType(), Pattern.getQualifiers());
1953
3.13k
      return Ctx.hasSameType(SubstArg, T);
1954
3.13k
    }
1955
0
    return false;
1956
3.13k
  }
1957
1958
  // FIXME: Recurse into array types.
1959
1960
  // All other cases will need the types to be identically qualified.
1961
3.84k
  Qualifiers TQual, PatQual;
1962
3.84k
  T = Ctx.getUnqualifiedArrayType(T, TQual);
1963
3.84k
  Pattern = Ctx.getUnqualifiedArrayType(Pattern, PatQual);
1964
3.84k
  if (TQual != PatQual)
1965
40
    return false;
1966
1967
  // Recurse into pointer-like types.
1968
3.80k
  {
1969
3.80k
    QualType TPointee = T->getPointeeType();
1970
3.80k
    QualType PPointee = Pattern->getPointeeType();
1971
3.80k
    if (!TPointee.isNull() && 
!PPointee.isNull()72
)
1972
0
      return T->getTypeClass() == Pattern->getTypeClass() &&
1973
0
             isSubstitutedType(Ctx, TPointee, PPointee, Args, Depth);
1974
3.80k
  }
1975
1976
  // Recurse into template specialization types.
1977
3.80k
  if (auto *PTST =
1978
3.80k
          Pattern.getCanonicalType()->getAs<TemplateSpecializationType>()) {
1979
3.37k
    TemplateName Template;
1980
3.37k
    ArrayRef<TemplateArgument> TemplateArgs;
1981
3.37k
    if (auto *TTST = T->getAs<TemplateSpecializationType>()) {
1982
0
      Template = TTST->getTemplateName();
1983
0
      TemplateArgs = TTST->template_arguments();
1984
3.37k
    } else if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
1985
3.37k
                   T->getAsCXXRecordDecl())) {
1986
3.24k
      Template = TemplateName(CTSD->getSpecializedTemplate());
1987
3.24k
      TemplateArgs = CTSD->getTemplateArgs().asArray();
1988
3.24k
    } else {
1989
129
      return false;
1990
129
    }
1991
1992
3.24k
    if (!isSubstitutedTemplateArgument(Ctx, Template, PTST->getTemplateName(),
1993
3.24k
                                       Args, Depth))
1994
81
      return false;
1995
3.16k
    if (TemplateArgs.size() != PTST->getNumArgs())
1996
0
      return false;
1997
6.31k
    
for (unsigned I = 0, N = TemplateArgs.size(); 3.16k
I != N;
++I3.15k
)
1998
3.19k
      if (!isSubstitutedTemplateArgument(Ctx, TemplateArgs[I], PTST->getArg(I),
1999
3.19k
                                         Args, Depth))
2000
40
        return false;
2001
3.12k
    return true;
2002
3.16k
  }
2003
2004
  // FIXME: Handle more cases.
2005
430
  return false;
2006
3.80k
}
2007
2008
static bool isSubstitutedTemplateArgument(ASTContext &Ctx, TemplateArgument Arg,
2009
                                          TemplateArgument Pattern,
2010
                                          ArrayRef<TemplateArgument> Args,
2011
11.7k
                                          unsigned Depth) {
2012
11.7k
  Arg = Ctx.getCanonicalTemplateArgument(Arg);
2013
11.7k
  Pattern = Ctx.getCanonicalTemplateArgument(Pattern);
2014
11.7k
  if (Arg.structurallyEquals(Pattern))
2015
3.89k
    return true;
2016
2017
7.82k
  if (Pattern.getKind() == TemplateArgument::Expression) {
2018
674
    if (auto *DRE =
2019
674
            dyn_cast<DeclRefExpr>(Pattern.getAsExpr()->IgnoreParenImpCasts())) {
2020
101
      if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
2021
1
        return NTTP->getDepth() == Depth && Args.size() > NTTP->getIndex() &&
2022
1
               Args[NTTP->getIndex()].structurallyEquals(Arg);
2023
101
    }
2024
674
  }
2025
2026
7.82k
  if (Arg.getKind() != Pattern.getKind())
2027
673
    return false;
2028
2029
7.15k
  if (Arg.getKind() == TemplateArgument::Type)
2030
6.97k
    return isSubstitutedType(Ctx, Arg.getAsType(), Pattern.getAsType(), Args,
2031
6.97k
                             Depth);
2032
2033
177
  if (Arg.getKind() == TemplateArgument::Template) {
2034
177
    TemplateDecl *PatTD = Pattern.getAsTemplate().getAsTemplateDecl();
2035
177
    if (auto *TTPD = dyn_cast_or_null<TemplateTemplateParmDecl>(PatTD))
2036
12
      return TTPD->getDepth() == Depth && Args.size() > TTPD->getIndex() &&
2037
12
             Ctx.getCanonicalTemplateArgument(Args[TTPD->getIndex()])
2038
12
                 .structurallyEquals(Arg);
2039
177
  }
2040
2041
  // FIXME: Handle more cases.
2042
165
  return false;
2043
177
}
2044
2045
/// Make a best-effort determination of whether the type T can be produced by
2046
/// substituting Args into the default argument of Param.
2047
static bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
2048
                                         const NamedDecl *Param,
2049
                                         ArrayRef<TemplateArgument> Args,
2050
44.5k
                                         unsigned Depth) {
2051
  // An empty pack is equivalent to not providing a pack argument.
2052
44.5k
  if (Arg.getKind() == TemplateArgument::Pack && 
Arg.pack_size() == 01.13k
)
2053
367
    return true;
2054
2055
44.2k
  if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Param)) {
2056
35.0k
    return TTPD->hasDefaultArgument() &&
2057
35.0k
           isSubstitutedTemplateArgument(Ctx, Arg, TTPD->getDefaultArgument(),
2058
4.38k
                                         Args, Depth);
2059
35.0k
  } else 
if (auto *9.22k
TTPD9.22k
= dyn_cast<TemplateTemplateParmDecl>(Param)) {
2060
561
    return TTPD->hasDefaultArgument() &&
2061
561
           isSubstitutedTemplateArgument(
2062
263
               Ctx, Arg, TTPD->getDefaultArgument().getArgument(), Args, Depth);
2063
8.66k
  } else if (auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2064
8.66k
    return NTTPD->hasDefaultArgument() &&
2065
8.66k
           isSubstitutedTemplateArgument(Ctx, Arg, NTTPD->getDefaultArgument(),
2066
634
                                         Args, Depth);
2067
8.66k
  }
2068
0
  return false;
2069
44.2k
}
2070
2071
template <typename TA>
2072
static void
2073
printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
2074
1.29M
        const TemplateParameterList *TPL, bool IsPack, unsigned ParmIndex) {
2075
  // Drop trailing template arguments that match default arguments.
2076
1.29M
  if (TPL && 
Policy.SuppressDefaultTemplateArgs1.22M
&&
2077
1.29M
      
!Policy.PrintCanonicalTypes526k
&&
!Args.empty()41.7k
&&
!IsPack41.7k
&&
2078
1.29M
      
Args.size() <= TPL->size()40.9k
) {
2079
40.9k
    ASTContext &Ctx = TPL->getParam(0)->getASTContext();
2080
40.9k
    llvm::SmallVector<TemplateArgument, 8> OrigArgs;
2081
40.9k
    for (const TA &A : Args)
2082
55.0k
      OrigArgs.push_back(getArgument(A));
2083
45.1k
    while (!Args.empty() &&
2084
45.1k
           isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
2085
44.5k
                                        TPL->getParam(Args.size() - 1),
2086
44.5k
                                        OrigArgs, TPL->getDepth()))
2087
4.20k
      Args = Args.drop_back();
2088
40.9k
  }
2089
2090
1.29M
  const char *Comma = Policy.MSVCFormatting ? 
","55
:
", "1.29M
;
2091
1.29M
  if (!IsPack)
2092
1.22M
    OS << '<';
2093
2094
1.29M
  bool NeedSpace = false;
2095
1.29M
  bool FirstArg = true;
2096
2.18M
  for (const auto &Arg : Args) {
2097
    // Print the argument into a string.
2098
2.18M
    SmallString<128> Buf;
2099
2.18M
    llvm::raw_svector_ostream ArgOS(Buf);
2100
2.18M
    const TemplateArgument &Argument = getArgument(Arg);
2101
2.18M
    if (Argument.getKind() == TemplateArgument::Pack) {
2102
75.6k
      if (Argument.pack_size() && 
!FirstArg71.4k
)
2103
11.6k
        OS << Comma;
2104
75.6k
      printTo(ArgOS, Argument.getPackAsArray(), Policy, TPL,
2105
75.6k
              /*IsPack*/ true, ParmIndex);
2106
2.11M
    } else {
2107
2.11M
      if (!FirstArg)
2108
881k
        OS << Comma;
2109
      // Tries to print the argument with location info if exists.
2110
2.11M
      printArgument(Arg, Policy, ArgOS,
2111
2.11M
                    TemplateParameterList::shouldIncludeTypeForArgument(
2112
2.11M
                        Policy, TPL, ParmIndex));
2113
2.11M
    }
2114
2.18M
    StringRef ArgString = ArgOS.str();
2115
2116
    // If this is the first argument and its string representation
2117
    // begins with the global scope specifier ('::foo'), add a space
2118
    // to avoid printing the diagraph '<:'.
2119
2.18M
    if (FirstArg && 
!ArgString.empty()1.29M
&&
ArgString[0] == ':'1.29M
)
2120
3
      OS << ' ';
2121
2122
2.18M
    OS << ArgString;
2123
2124
    // If the last character of our string is '>', add another space to
2125
    // keep the two '>''s separate tokens.
2126
2.18M
    if (!ArgString.empty()) {
2127
2.18M
      NeedSpace = Policy.SplitTemplateClosers && 
ArgString.back() == '>'1.70M
;
2128
2.18M
      FirstArg = false;
2129
2.18M
    }
2130
2131
    // Use same template parameter for all elements of Pack
2132
2.18M
    if (!IsPack)
2133
2.08M
      ParmIndex++;
2134
2.18M
  }
2135
2136
1.29M
  if (!IsPack) {
2137
1.22M
    if (NeedSpace)
2138
246k
      OS << ' ';
2139
1.22M
    OS << '>';
2140
1.22M
  }
2141
1.29M
}
TypePrinter.cpp:void printTo<clang::TemplateArgument>(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, clang::TemplateParameterList const*, bool, unsigned int)
Line
Count
Source
2074
1.29M
        const TemplateParameterList *TPL, bool IsPack, unsigned ParmIndex) {
2075
  // Drop trailing template arguments that match default arguments.
2076
1.29M
  if (TPL && 
Policy.SuppressDefaultTemplateArgs1.22M
&&
2077
1.29M
      
!Policy.PrintCanonicalTypes526k
&&
!Args.empty()41.6k
&&
!IsPack41.6k
&&
2078
1.29M
      
Args.size() <= TPL->size()40.8k
) {
2079
40.8k
    ASTContext &Ctx = TPL->getParam(0)->getASTContext();
2080
40.8k
    llvm::SmallVector<TemplateArgument, 8> OrigArgs;
2081
40.8k
    for (const TA &A : Args)
2082
54.9k
      OrigArgs.push_back(getArgument(A));
2083
45.0k
    while (!Args.empty() &&
2084
45.0k
           isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
2085
44.4k
                                        TPL->getParam(Args.size() - 1),
2086
44.4k
                                        OrigArgs, TPL->getDepth()))
2087
4.20k
      Args = Args.drop_back();
2088
40.8k
  }
2089
2090
1.29M
  const char *Comma = Policy.MSVCFormatting ? 
","55
:
", "1.29M
;
2091
1.29M
  if (!IsPack)
2092
1.22M
    OS << '<';
2093
2094
1.29M
  bool NeedSpace = false;
2095
1.29M
  bool FirstArg = true;
2096
2.18M
  for (const auto &Arg : Args) {
2097
    // Print the argument into a string.
2098
2.18M
    SmallString<128> Buf;
2099
2.18M
    llvm::raw_svector_ostream ArgOS(Buf);
2100
2.18M
    const TemplateArgument &Argument = getArgument(Arg);
2101
2.18M
    if (Argument.getKind() == TemplateArgument::Pack) {
2102
75.6k
      if (Argument.pack_size() && 
!FirstArg71.4k
)
2103
11.6k
        OS << Comma;
2104
75.6k
      printTo(ArgOS, Argument.getPackAsArray(), Policy, TPL,
2105
75.6k
              /*IsPack*/ true, ParmIndex);
2106
2.10M
    } else {
2107
2.10M
      if (!FirstArg)
2108
878k
        OS << Comma;
2109
      // Tries to print the argument with location info if exists.
2110
2.10M
      printArgument(Arg, Policy, ArgOS,
2111
2.10M
                    TemplateParameterList::shouldIncludeTypeForArgument(
2112
2.10M
                        Policy, TPL, ParmIndex));
2113
2.10M
    }
2114
2.18M
    StringRef ArgString = ArgOS.str();
2115
2116
    // If this is the first argument and its string representation
2117
    // begins with the global scope specifier ('::foo'), add a space
2118
    // to avoid printing the diagraph '<:'.
2119
2.18M
    if (FirstArg && 
!ArgString.empty()1.29M
&&
ArgString[0] == ':'1.29M
)
2120
3
      OS << ' ';
2121
2122
2.18M
    OS << ArgString;
2123
2124
    // If the last character of our string is '>', add another space to
2125
    // keep the two '>''s separate tokens.
2126
2.18M
    if (!ArgString.empty()) {
2127
2.17M
      NeedSpace = Policy.SplitTemplateClosers && 
ArgString.back() == '>'1.70M
;
2128
2.17M
      FirstArg = false;
2129
2.17M
    }
2130
2131
    // Use same template parameter for all elements of Pack
2132
2.18M
    if (!IsPack)
2133
2.08M
      ParmIndex++;
2134
2.18M
  }
2135
2136
1.29M
  if (!IsPack) {
2137
1.22M
    if (NeedSpace)
2138
246k
      OS << ' ';
2139
1.22M
    OS << '>';
2140
1.22M
  }
2141
1.29M
}
TypePrinter.cpp:void printTo<clang::TemplateArgumentLoc>(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgumentLoc>, clang::PrintingPolicy const&, clang::TemplateParameterList const*, bool, unsigned int)
Line
Count
Source
2074
1.51k
        const TemplateParameterList *TPL, bool IsPack, unsigned ParmIndex) {
2075
  // Drop trailing template arguments that match default arguments.
2076
1.51k
  if (TPL && 
Policy.SuppressDefaultTemplateArgs179
&&
2077
1.51k
      
!Policy.PrintCanonicalTypes179
&&
!Args.empty()154
&&
!IsPack154
&&
2078
1.51k
      
Args.size() <= TPL->size()154
) {
2079
137
    ASTContext &Ctx = TPL->getParam(0)->getASTContext();
2080
137
    llvm::SmallVector<TemplateArgument, 8> OrigArgs;
2081
137
    for (const TA &A : Args)
2082
171
      OrigArgs.push_back(getArgument(A));
2083
138
    while (!Args.empty() &&
2084
138
           isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
2085
138
                                        TPL->getParam(Args.size() - 1),
2086
138
                                        OrigArgs, TPL->getDepth()))
2087
1
      Args = Args.drop_back();
2088
137
  }
2089
2090
1.51k
  const char *Comma = Policy.MSVCFormatting ? 
","0
: ", ";
2091
1.51k
  if (!IsPack)
2092
1.51k
    OS << '<';
2093
2094
1.51k
  bool NeedSpace = false;
2095
1.51k
  bool FirstArg = true;
2096
3.79k
  for (const auto &Arg : Args) {
2097
    // Print the argument into a string.
2098
3.79k
    SmallString<128> Buf;
2099
3.79k
    llvm::raw_svector_ostream ArgOS(Buf);
2100
3.79k
    const TemplateArgument &Argument = getArgument(Arg);
2101
3.79k
    if (Argument.getKind() == TemplateArgument::Pack) {
2102
0
      if (Argument.pack_size() && !FirstArg)
2103
0
        OS << Comma;
2104
0
      printTo(ArgOS, Argument.getPackAsArray(), Policy, TPL,
2105
0
              /*IsPack*/ true, ParmIndex);
2106
3.79k
    } else {
2107
3.79k
      if (!FirstArg)
2108
2.28k
        OS << Comma;
2109
      // Tries to print the argument with location info if exists.
2110
3.79k
      printArgument(Arg, Policy, ArgOS,
2111
3.79k
                    TemplateParameterList::shouldIncludeTypeForArgument(
2112
3.79k
                        Policy, TPL, ParmIndex));
2113
3.79k
    }
2114
3.79k
    StringRef ArgString = ArgOS.str();
2115
2116
    // If this is the first argument and its string representation
2117
    // begins with the global scope specifier ('::foo'), add a space
2118
    // to avoid printing the diagraph '<:'.
2119
3.79k
    if (FirstArg && 
!ArgString.empty()1.51k
&&
ArgString[0] == ':'1.51k
)
2120
0
      OS << ' ';
2121
2122
3.79k
    OS << ArgString;
2123
2124
    // If the last character of our string is '>', add another space to
2125
    // keep the two '>''s separate tokens.
2126
3.79k
    if (!ArgString.empty()) {
2127
3.79k
      NeedSpace = Policy.SplitTemplateClosers && 
ArgString.back() == '>'270
;
2128
3.79k
      FirstArg = false;
2129
3.79k
    }
2130
2131
    // Use same template parameter for all elements of Pack
2132
3.79k
    if (!IsPack)
2133
3.79k
      ParmIndex++;
2134
3.79k
  }
2135
2136
1.51k
  if (!IsPack) {
2137
1.51k
    if (NeedSpace)
2138
3
      OS << ' ';
2139
1.51k
    OS << '>';
2140
1.51k
  }
2141
1.51k
}
2142
2143
void clang::printTemplateArgumentList(raw_ostream &OS,
2144
                                      const TemplateArgumentListInfo &Args,
2145
                                      const PrintingPolicy &Policy,
2146
0
                                      const TemplateParameterList *TPL) {
2147
0
  printTemplateArgumentList(OS, Args.arguments(), Policy, TPL);
2148
0
}
2149
2150
void clang::printTemplateArgumentList(raw_ostream &OS,
2151
                                      ArrayRef<TemplateArgument> Args,
2152
                                      const PrintingPolicy &Policy,
2153
1.22M
                                      const TemplateParameterList *TPL) {
2154
1.22M
  printTo(OS, Args, Policy, TPL, /*isPack*/ false, /*parmIndex*/ 0);
2155
1.22M
}
2156
2157
void clang::printTemplateArgumentList(raw_ostream &OS,
2158
                                      ArrayRef<TemplateArgumentLoc> Args,
2159
                                      const PrintingPolicy &Policy,
2160
1.51k
                                      const TemplateParameterList *TPL) {
2161
1.51k
  printTo(OS, Args, Policy, TPL, /*isPack*/ false, /*parmIndex*/ 0);
2162
1.51k
}
2163
2164
3.00k
std::string Qualifiers::getAsString() const {
2165
3.00k
  LangOptions LO;
2166
3.00k
  return getAsString(PrintingPolicy(LO));
2167
3.00k
}
2168
2169
// Appends qualifiers to the given string, separated by spaces.  Will
2170
// prefix a space if the string is non-empty.  Will not append a final
2171
// space.
2172
3.00k
std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
2173
3.00k
  SmallString<64> Buf;
2174
3.00k
  llvm::raw_svector_ostream StrOS(Buf);
2175
3.00k
  print(StrOS, Policy);
2176
3.00k
  return std::string(StrOS.str());
2177
3.00k
}
2178
2179
9.64k
bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
2180
9.64k
  if (getCVRQualifiers())
2181
5.75k
    return false;
2182
2183
3.89k
  if (getAddressSpace() != LangAS::Default)
2184
3.38k
    return false;
2185
2186
513
  if (getObjCGCAttr())
2187
45
    return false;
2188
2189
468
  if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
2190
468
    if (!(lifetime == Qualifiers::OCL_Strong && 
Policy.SuppressStrongLifetime349
))
2191
437
      return false;
2192
2193
31
  return true;
2194
468
}
2195
2196
124k
std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
2197
124k
  switch (AS) {
2198
112k
  case LangAS::Default:
2199
112k
    return "";
2200
2.05k
  case LangAS::opencl_global:
2201
2.10k
  case LangAS::sycl_global:
2202
2.10k
    return "__global";
2203
1.23k
  case LangAS::opencl_local:
2204
1.25k
  case LangAS::sycl_local:
2205
1.25k
    return "__local";
2206
5.15k
  case LangAS::opencl_private:
2207
5.17k
  case LangAS::sycl_private:
2208
5.17k
    return "__private";
2209
1.44k
  case LangAS::opencl_constant:
2210
1.44k
    return "__constant";
2211
1.51k
  case LangAS::opencl_generic:
2212
1.51k
    return "__generic";
2213
54
  case LangAS::opencl_global_device:
2214
62
  case LangAS::sycl_global_device:
2215
62
    return "__global_device";
2216
54
  case LangAS::opencl_global_host:
2217
62
  case LangAS::sycl_global_host:
2218
62
    return "__global_host";
2219
0
  case LangAS::cuda_device:
2220
0
    return "__device__";
2221
0
  case LangAS::cuda_constant:
2222
0
    return "__constant__";
2223
0
  case LangAS::cuda_shared:
2224
0
    return "__shared__";
2225
0
  case LangAS::ptr32_sptr:
2226
0
    return "__sptr __ptr32";
2227
0
  case LangAS::ptr32_uptr:
2228
0
    return "__uptr __ptr32";
2229
0
  case LangAS::ptr64:
2230
0
    return "__ptr64";
2231
451
  default:
2232
451
    return std::to_string(toTargetAddressSpace(AS));
2233
124k
  }
2234
124k
}
2235
2236
// Appends qualifiers to the given string, separated by spaces.  Will
2237
// prefix a space if the string is non-empty.  Will not append a final
2238
// space.
2239
void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
2240
124k
                       bool appendSpaceIfNonEmpty) const {
2241
124k
  bool addSpace = false;
2242
2243
124k
  unsigned quals = getCVRQualifiers();
2244
124k
  if (quals) {
2245
110k
    AppendTypeQualList(OS, quals, Policy.Restrict);
2246
110k
    addSpace = true;
2247
110k
  }
2248
124k
  if (hasUnaligned()) {
2249
87
    if (addSpace)
2250
0
      OS << ' ';
2251
87
    OS << "__unaligned";
2252
87
    addSpace = true;
2253
87
  }
2254
124k
  auto ASStr = getAddrSpaceAsString(getAddressSpace());
2255
124k
  if (!ASStr.empty()) {
2256
11.9k
    if (addSpace)
2257
521
      OS << ' ';
2258
11.9k
    addSpace = true;
2259
    // Wrap target address space into an attribute syntax
2260
11.9k
    if (isTargetAddressSpace(getAddressSpace()))
2261
445
      OS << "__attribute__((address_space(" << ASStr << ")))";
2262
11.5k
    else
2263
11.5k
      OS << ASStr;
2264
11.9k
  }
2265
2266
124k
  if (Qualifiers::GC gc = getObjCGCAttr()) {
2267
69
    if (addSpace)
2268
0
      OS << ' ';
2269
69
    addSpace = true;
2270
69
    if (gc == Qualifiers::Weak)
2271
28
      OS << "__weak";
2272
41
    else
2273
41
      OS << "__strong";
2274
69
  }
2275
124k
  if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
2276
1.83k
    if (!(lifetime == Qualifiers::OCL_Strong && 
Policy.SuppressStrongLifetime1.10k
)){
2277
1.79k
      if (addSpace)
2278
91
        OS << ' ';
2279
1.79k
      addSpace = true;
2280
1.79k
    }
2281
2282
1.83k
    switch (lifetime) {
2283
0
    case Qualifiers::OCL_None: llvm_unreachable("none but true");
2284
68
    case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
2285
1.10k
    case Qualifiers::OCL_Strong:
2286
1.10k
      if (!Policy.SuppressStrongLifetime)
2287
1.06k
        OS << "__strong";
2288
1.10k
      break;
2289
2290
510
    case Qualifiers::OCL_Weak: OS << "__weak"; break;
2291
151
    case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
2292
1.83k
    }
2293
1.83k
  }
2294
2295
124k
  if (appendSpaceIfNonEmpty && 
addSpace115k
)
2296
115k
    OS << ' ';
2297
124k
}
2298
2299
24.2k
std::string QualType::getAsString() const {
2300
24.2k
  return getAsString(split(), LangOptions());
2301
24.2k
}
2302
2303
647k
std::string QualType::getAsString(const PrintingPolicy &Policy) const {
2304
647k
  std::string S;
2305
647k
  getAsStringInternal(S, Policy);
2306
647k
  return S;
2307
647k
}
2308
2309
std::string QualType::getAsString(const Type *ty, Qualifiers qs,
2310
94.9k
                                  const PrintingPolicy &Policy) {
2311
94.9k
  std::string buffer;
2312
94.9k
  getAsStringInternal(ty, qs, buffer, Policy);
2313
94.9k
  return buffer;
2314
94.9k
}
2315
2316
void QualType::print(raw_ostream &OS, const PrintingPolicy &Policy,
2317
2.11M
                     const Twine &PlaceHolder, unsigned Indentation) const {
2318
2.11M
  print(splitAccordingToPolicy(*this, Policy), OS, Policy, PlaceHolder,
2319
2.11M
        Indentation);
2320
2.11M
}
2321
2322
void QualType::print(const Type *ty, Qualifiers qs,
2323
                     raw_ostream &OS, const PrintingPolicy &policy,
2324
2.11M
                     const Twine &PlaceHolder, unsigned Indentation) {
2325
2.11M
  SmallString<128> PHBuf;
2326
2.11M
  StringRef PH = PlaceHolder.toStringRef(PHBuf);
2327
2328
2.11M
  TypePrinter(policy, Indentation).print(ty, qs, OS, PH);
2329
2.11M
}
2330
2331
void QualType::getAsStringInternal(std::string &Str,
2332
655k
                                   const PrintingPolicy &Policy) const {
2333
655k
  return getAsStringInternal(splitAccordingToPolicy(*this, Policy), Str,
2334
655k
                             Policy);
2335
655k
}
2336
2337
void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
2338
                                   std::string &buffer,
2339
750k
                                   const PrintingPolicy &policy) {
2340
750k
  SmallString<256> Buf;
2341
750k
  llvm::raw_svector_ostream StrOS(Buf);
2342
750k
  TypePrinter(policy).print(ty, qs, StrOS, buffer);
2343
750k
  std::string str = std::string(StrOS.str());
2344
750k
  buffer.swap(str);
2345
750k
}
2346
2347
16.3k
raw_ostream &clang::operator<<(raw_ostream &OS, QualType QT) {
2348
16.3k
  SplitQualType S = QT.split();
2349
16.3k
  TypePrinter(LangOptions()).print(S.Ty, S.Quals, OS, /*PlaceHolder=*/"");
2350
16.3k
  return OS;
2351
16.3k
}