Coverage Report

Created: 2020-02-15 09:57

/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/PrettyPrinter.h"
14
#include "clang/AST/ASTContext.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/TemplateBase.h"
23
#include "clang/AST/TemplateName.h"
24
#include "clang/AST/Type.h"
25
#include "clang/Basic/AddressSpaces.h"
26
#include "clang/Basic/ExceptionSpecificationType.h"
27
#include "clang/Basic/IdentifierTable.h"
28
#include "clang/Basic/LLVM.h"
29
#include "clang/Basic/LangOptions.h"
30
#include "clang/Basic/SourceLocation.h"
31
#include "clang/Basic/SourceManager.h"
32
#include "clang/Basic/Specifiers.h"
33
#include "llvm/ADT/ArrayRef.h"
34
#include "llvm/ADT/SmallString.h"
35
#include "llvm/ADT/StringRef.h"
36
#include "llvm/ADT/Twine.h"
37
#include "llvm/Support/Casting.h"
38
#include "llvm/Support/Compiler.h"
39
#include "llvm/Support/ErrorHandling.h"
40
#include "llvm/Support/SaveAndRestore.h"
41
#include "llvm/Support/raw_ostream.h"
42
#include <cassert>
43
#include <string>
44
45
using namespace clang;
46
47
namespace {
48
49
  /// RAII object that enables printing of the ARC __strong lifetime
50
  /// qualifier.
51
  class IncludeStrongLifetimeRAII {
52
    PrintingPolicy &Policy;
53
    bool Old;
54
55
  public:
56
    explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy)
57
1.41M
        : Policy(Policy), Old(Policy.SuppressStrongLifetime) {
58
1.41M
        if (!Policy.SuppressLifetimeQualifiers)
59
1.41M
          Policy.SuppressStrongLifetime = false;
60
1.41M
    }
61
62
1.41M
    ~IncludeStrongLifetimeRAII() {
63
1.41M
      Policy.SuppressStrongLifetime = Old;
64
1.41M
    }
65
  };
66
67
  class ParamPolicyRAII {
68
    PrintingPolicy &Policy;
69
    bool Old;
70
71
  public:
72
    explicit ParamPolicyRAII(PrintingPolicy &Policy)
73
35.6k
        : Policy(Policy), Old(Policy.SuppressSpecifiers) {
74
35.6k
      Policy.SuppressSpecifiers = false;
75
35.6k
    }
76
77
35.6k
    ~ParamPolicyRAII() {
78
35.6k
      Policy.SuppressSpecifiers = Old;
79
35.6k
    }
80
  };
81
82
  class ElaboratedTypePolicyRAII {
83
    PrintingPolicy &Policy;
84
    bool SuppressTagKeyword;
85
    bool SuppressScope;
86
87
  public:
88
9.78k
    explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
89
9.78k
      SuppressTagKeyword = Policy.SuppressTagKeyword;
90
9.78k
      SuppressScope = Policy.SuppressScope;
91
9.78k
      Policy.SuppressTagKeyword = true;
92
9.78k
      Policy.SuppressScope = true;
93
9.78k
    }
94
95
9.78k
    ~ElaboratedTypePolicyRAII() {
96
9.78k
      Policy.SuppressTagKeyword = SuppressTagKeyword;
97
9.78k
      Policy.SuppressScope = SuppressScope;
98
9.78k
    }
99
  };
100
101
  class TypePrinter {
102
    PrintingPolicy Policy;
103
    unsigned Indentation;
104
    bool HasEmptyPlaceHolder = false;
105
    bool InsideCCAttribute = false;
106
107
  public:
108
    explicit TypePrinter(const PrintingPolicy &Policy, unsigned Indentation = 0)
109
1.91M
        : Policy(Policy), Indentation(Indentation) {}
110
111
    void print(const Type *ty, Qualifiers qs, raw_ostream &OS,
112
               StringRef PlaceHolder);
113
    void print(QualType T, raw_ostream &OS, StringRef PlaceHolder);
114
115
    static bool canPrefixQualifiers(const Type *T, bool &NeedARCStrongQualifier);
116
    void spaceBeforePlaceHolder(raw_ostream &OS);
117
    void printTypeSpec(NamedDecl *D, raw_ostream &OS);
118
119
    void printBefore(QualType T, raw_ostream &OS);
120
    void printAfter(QualType T, raw_ostream &OS);
121
    void AppendScope(DeclContext *DC, raw_ostream &OS);
122
    void printTag(TagDecl *T, raw_ostream &OS);
123
    void printFunctionAfter(const FunctionType::ExtInfo &Info, raw_ostream &OS);
124
#define ABSTRACT_TYPE(CLASS, PARENT)
125
#define TYPE(CLASS, PARENT) \
126
    void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
127
    void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
128
#include "clang/AST/TypeNodes.inc"
129
130
  private:
131
    void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);
132
    void printAfter(const Type *ty, Qualifiers qs, raw_ostream &OS);
133
  };
134
135
} // namespace
136
137
static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
138
81.1k
                               bool HasRestrictKeyword) {
139
81.1k
  bool appendSpace = false;
140
81.1k
  if (TypeQuals & Qualifiers::Const) {
141
74.2k
    OS << "const";
142
74.2k
    appendSpace = true;
143
74.2k
  }
144
81.1k
  if (TypeQuals & Qualifiers::Volatile) {
145
7.45k
    if (appendSpace) 
OS << ' '715
;
146
7.45k
    OS << "volatile";
147
7.45k
    appendSpace = true;
148
7.45k
  }
149
81.1k
  if (TypeQuals & Qualifiers::Restrict) {
150
1.97k
    if (appendSpace) 
OS << ' '1.85k
;
151
1.97k
    if (HasRestrictKeyword) {
152
1.73k
      OS << "restrict";
153
1.73k
    } else {
154
244
      OS << "__restrict";
155
244
    }
156
1.97k
  }
157
81.1k
}
158
159
1.94M
void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
160
1.94M
  if (!HasEmptyPlaceHolder)
161
419k
    OS << ' ';
162
1.94M
}
163
164
static SplitQualType splitAccordingToPolicy(QualType QT,
165
2.89M
                                            const PrintingPolicy &Policy) {
166
2.89M
  if (Policy.PrintCanonicalTypes)
167
765k
    QT = QT.getCanonicalType();
168
2.89M
  return QT.split();
169
2.89M
}
170
171
34.8k
void TypePrinter::print(QualType t, raw_ostream &OS, StringRef PlaceHolder) {
172
34.8k
  SplitQualType split = splitAccordingToPolicy(t, Policy);
173
34.8k
  print(split.Ty, split.Quals, OS, PlaceHolder);
174
34.8k
}
175
176
void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
177
1.94M
                        StringRef PlaceHolder) {
178
1.94M
  if (!T) {
179
39
    OS << "NULL TYPE";
180
39
    return;
181
39
  }
182
1.94M
183
1.94M
  SaveAndRestore<bool> PHVal(HasEmptyPlaceHolder, PlaceHolder.empty());
184
1.94M
185
1.94M
  printBefore(T, Quals, OS);
186
1.94M
  OS << PlaceHolder;
187
1.94M
  printAfter(T, Quals, OS);
188
1.94M
}
189
190
bool TypePrinter::canPrefixQualifiers(const Type *T,
191
2.46M
                                      bool &NeedARCStrongQualifier) {
192
2.46M
  // CanPrefixQualifiers - We prefer to print type qualifiers before the type,
193
2.46M
  // so that we get "const int" instead of "int const", but we can't do this if
194
2.46M
  // the type is complex.  For example if the type is "int*", we *must* print
195
2.46M
  // "int * const", printing "const int *" is different.  Only do this when the
196
2.46M
  // type expands to a simple string.
197
2.46M
  bool CanPrefixQualifiers = false;
198
2.46M
  NeedARCStrongQualifier = false;
199
2.46M
  Type::TypeClass TC = T->getTypeClass();
200
2.46M
  if (const auto *AT = dyn_cast<AutoType>(T))
201
1.76k
    TC = AT->desugar()->getTypeClass();
202
2.46M
  if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))
203
13.5k
    TC = Subst->getReplacementType()->getTypeClass();
204
2.46M
205
2.46M
  switch (TC) {
206
1.96M
    case Type::Auto:
207
1.96M
    case Type::Builtin:
208
1.96M
    case Type::Complex:
209
1.96M
    case Type::UnresolvedUsing:
210
1.96M
    case Type::Typedef:
211
1.96M
    case Type::TypeOfExpr:
212
1.96M
    case Type::TypeOf:
213
1.96M
    case Type::Decltype:
214
1.96M
    case Type::UnaryTransform:
215
1.96M
    case Type::Record:
216
1.96M
    case Type::Enum:
217
1.96M
    case Type::Elaborated:
218
1.96M
    case Type::TemplateTypeParm:
219
1.96M
    case Type::SubstTemplateTypeParmPack:
220
1.96M
    case Type::DeducedTemplateSpecialization:
221
1.96M
    case Type::TemplateSpecialization:
222
1.96M
    case Type::InjectedClassName:
223
1.96M
    case Type::DependentName:
224
1.96M
    case Type::DependentTemplateSpecialization:
225
1.96M
    case Type::ObjCObject:
226
1.96M
    case Type::ObjCTypeParam:
227
1.96M
    case Type::ObjCInterface:
228
1.96M
    case Type::Atomic:
229
1.96M
    case Type::Pipe:
230
1.96M
      CanPrefixQualifiers = true;
231
1.96M
      break;
232
1.96M
233
1.96M
    case Type::ObjCObjectPointer:
234
21.6k
      CanPrefixQualifiers = T->isObjCIdType() || 
T->isObjCClassType()19.6k
||
235
21.6k
        
T->isObjCQualifiedIdType()19.2k
||
T->isObjCQualifiedClassType()18.1k
;
236
21.6k
      break;
237
1.96M
238
1.96M
    case Type::ConstantArray:
239
11.2k
    case Type::IncompleteArray:
240
11.2k
    case Type::VariableArray:
241
11.2k
    case Type::DependentSizedArray:
242
11.2k
      NeedARCStrongQualifier = true;
243
11.2k
      LLVM_FALLTHROUGH;
244
11.2k
245
474k
    case Type::Adjusted:
246
474k
    case Type::Decayed:
247
474k
    case Type::Pointer:
248
474k
    case Type::BlockPointer:
249
474k
    case Type::LValueReference:
250
474k
    case Type::RValueReference:
251
474k
    case Type::MemberPointer:
252
474k
    case Type::DependentAddressSpace:
253
474k
    case Type::DependentVector:
254
474k
    case Type::DependentSizedExtVector:
255
474k
    case Type::Vector:
256
474k
    case Type::ExtVector:
257
474k
    case Type::FunctionProto:
258
474k
    case Type::FunctionNoProto:
259
474k
    case Type::Paren:
260
474k
    case Type::PackExpansion:
261
474k
    case Type::SubstTemplateTypeParm:
262
474k
    case Type::MacroQualified:
263
474k
      CanPrefixQualifiers = false;
264
474k
      break;
265
474k
266
474k
    case Type::Attributed: {
267
1.39k
      // We still want to print the address_space before the type if it is an
268
1.39k
      // address_space attribute.
269
1.39k
      const auto *AttrTy = cast<AttributedType>(T);
270
1.39k
      CanPrefixQualifiers = AttrTy->getAttrKind() == attr::AddressSpace;
271
1.39k
    }
272
2.46M
  }
273
2.46M
274
2.46M
  return CanPrefixQualifiers;
275
2.46M
}
276
277
519k
void TypePrinter::printBefore(QualType T, raw_ostream &OS) {
278
519k
  SplitQualType Split = splitAccordingToPolicy(T, Policy);
279
519k
280
519k
  // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2
281
519k
  // at this level.
282
519k
  Qualifiers Quals = Split.Quals;
283
519k
  if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(Split.Ty))
284
1.66k
    Quals -= QualType(Subst, 0).getQualifiers();
285
519k
286
519k
  printBefore(Split.Ty, Quals, OS);
287
519k
}
288
289
/// Prints the part of the type string before an identifier, e.g. for
290
/// "int foo[10]" it prints "int ".
291
2.46M
void TypePrinter::printBefore(const Type *T,Qualifiers Quals, raw_ostream &OS) {
292
2.46M
  if (Policy.SuppressSpecifiers && 
T->isSpecifierType()4.76k
)
293
4.53k
    return;
294
2.46M
295
2.46M
  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder);
296
2.46M
297
2.46M
  // Print qualifiers as appropriate.
298
2.46M
299
2.46M
  bool CanPrefixQualifiers = false;
300
2.46M
  bool NeedARCStrongQualifier = false;
301
2.46M
  CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
302
2.46M
303
2.46M
  if (CanPrefixQualifiers && 
!Quals.empty()1.96M
) {
304
74.6k
    if (NeedARCStrongQualifier) {
305
0
      IncludeStrongLifetimeRAII Strong(Policy);
306
0
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
307
74.6k
    } else {
308
74.6k
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
309
74.6k
    }
310
74.6k
  }
311
2.46M
312
2.46M
  bool hasAfterQuals = false;
313
2.46M
  if (!CanPrefixQualifiers && 
!Quals.empty()494k
) {
314
13.0k
    hasAfterQuals = !Quals.isEmptyWhenPrinted(Policy);
315
13.0k
    if (hasAfterQuals)
316
13.0k
      HasEmptyPlaceHolder = false;
317
13.0k
  }
318
2.46M
319
2.46M
  switch (T->getTypeClass()) {
320
0
#define ABSTRACT_TYPE(CLASS, PARENT)
321
2.46M
#define TYPE(CLASS, PARENT) case Type::CLASS: \
322
2.46M
    print##CLASS##Before(cast<CLASS##Type>(T), OS); \
323
2.46M
    break;
324
0
#include "clang/AST/TypeNodes.inc"
325
2.46M
  }
326
2.46M
327
2.46M
  if (hasAfterQuals) {
328
13.0k
    if (NeedARCStrongQualifier) {
329
1.29k
      IncludeStrongLifetimeRAII Strong(Policy);
330
1.29k
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
331
11.7k
    } else {
332
11.7k
      Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
333
11.7k
    }
334
13.0k
  }
335
2.46M
}
336
337
497k
void TypePrinter::printAfter(QualType t, raw_ostream &OS) {
338
497k
  SplitQualType split = splitAccordingToPolicy(t, Policy);
339
497k
  printAfter(split.Ty, split.Quals, OS);
340
497k
}
341
342
/// Prints the part of the type string after an identifier, e.g. for
343
/// "int foo[10]" it prints "[10]".
344
2.44M
void TypePrinter::printAfter(const Type *T, Qualifiers Quals, raw_ostream &OS) {
345
2.44M
  switch (T->getTypeClass()) {
346
0
#define ABSTRACT_TYPE(CLASS, PARENT)
347
2.44M
#define TYPE(CLASS, PARENT) case Type::CLASS: \
348
2.44M
    print##CLASS##After(cast<CLASS##Type>(T), OS); \
349
2.44M
    break;
350
0
#include "clang/AST/TypeNodes.inc"
351
2.44M
  }
352
2.44M
}
353
354
877k
void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) {
355
877k
  OS << T->getName(Policy);
356
877k
  spaceBeforePlaceHolder(OS);
357
877k
}
358
359
878k
void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) {}
360
361
480
void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) {
362
480
  OS << "_Complex ";
363
480
  printBefore(T->getElementType(), OS);
364
480
}
365
366
482
void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) {
367
482
  printAfter(T->getElementType(), OS);
368
482
}
369
370
340k
void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) {
371
340k
  IncludeStrongLifetimeRAII Strong(Policy);
372
340k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
373
340k
  printBefore(T->getPointeeType(), OS);
374
340k
  // Handle things like 'int (*A)[4];' correctly.
375
340k
  // FIXME: this should include vectors, but vectors use attributes I guess.
376
340k
  if (isa<ArrayType>(T->getPointeeType()))
377
818
    OS << '(';
378
340k
  OS << '*';
379
340k
}
380
381
340k
void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) {
382
340k
  IncludeStrongLifetimeRAII Strong(Policy);
383
340k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
384
340k
  // Handle things like 'int (*A)[4];' correctly.
385
340k
  // FIXME: this should include vectors, but vectors use attributes I guess.
386
340k
  if (isa<ArrayType>(T->getPointeeType()))
387
818
    OS << ')';
388
340k
  printAfter(T->getPointeeType(), OS);
389
340k
}
390
391
void TypePrinter::printBlockPointerBefore(const BlockPointerType *T,
392
868
                                          raw_ostream &OS) {
393
868
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
394
868
  printBefore(T->getPointeeType(), OS);
395
868
  OS << '^';
396
868
}
397
398
void TypePrinter::printBlockPointerAfter(const BlockPointerType *T,
399
868
                                          raw_ostream &OS) {
400
868
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
401
868
  printAfter(T->getPointeeType(), OS);
402
868
}
403
404
// When printing a reference, the referenced type might also be a reference.
405
// If so, we want to skip that before printing the inner type.
406
122k
static QualType skipTopLevelReferences(QualType T) {
407
122k
  if (auto *Ref = T->getAs<ReferenceType>())
408
306
    return skipTopLevelReferences(Ref->getPointeeTypeAsWritten());
409
121k
  return T;
410
121k
}
411
412
void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
413
47.1k
                                             raw_ostream &OS) {
414
47.1k
  IncludeStrongLifetimeRAII Strong(Policy);
415
47.1k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
416
47.1k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
417
47.1k
  printBefore(Inner, OS);
418
47.1k
  // Handle things like 'int (&A)[4];' correctly.
419
47.1k
  // FIXME: this should include vectors, but vectors use attributes I guess.
420
47.1k
  if (isa<ArrayType>(Inner))
421
1.00k
    OS << '(';
422
47.1k
  OS << '&';
423
47.1k
}
424
425
void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T,
426
47.1k
                                            raw_ostream &OS) {
427
47.1k
  IncludeStrongLifetimeRAII Strong(Policy);
428
47.1k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
429
47.1k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
430
47.1k
  // Handle things like 'int (&A)[4];' correctly.
431
47.1k
  // FIXME: this should include vectors, but vectors use attributes I guess.
432
47.1k
  if (isa<ArrayType>(Inner))
433
1.00k
    OS << ')';
434
47.1k
  printAfter(Inner, OS);
435
47.1k
}
436
437
void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
438
13.7k
                                             raw_ostream &OS) {
439
13.7k
  IncludeStrongLifetimeRAII Strong(Policy);
440
13.7k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
441
13.7k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
442
13.7k
  printBefore(Inner, OS);
443
13.7k
  // Handle things like 'int (&&A)[4];' correctly.
444
13.7k
  // FIXME: this should include vectors, but vectors use attributes I guess.
445
13.7k
  if (isa<ArrayType>(Inner))
446
0
    OS << '(';
447
13.7k
  OS << "&&";
448
13.7k
}
449
450
void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T,
451
13.7k
                                            raw_ostream &OS) {
452
13.7k
  IncludeStrongLifetimeRAII Strong(Policy);
453
13.7k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
454
13.7k
  QualType Inner = skipTopLevelReferences(T->getPointeeTypeAsWritten());
455
13.7k
  // Handle things like 'int (&&A)[4];' correctly.
456
13.7k
  // FIXME: this should include vectors, but vectors use attributes I guess.
457
13.7k
  if (isa<ArrayType>(Inner))
458
0
    OS << ')';
459
13.7k
  printAfter(Inner, OS);
460
13.7k
}
461
462
void TypePrinter::printMemberPointerBefore(const MemberPointerType *T,
463
2.76k
                                           raw_ostream &OS) {
464
2.76k
  IncludeStrongLifetimeRAII Strong(Policy);
465
2.76k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
466
2.76k
  printBefore(T->getPointeeType(), OS);
467
2.76k
  // Handle things like 'int (Cls::*A)[4];' correctly.
468
2.76k
  // FIXME: this should include vectors, but vectors use attributes I guess.
469
2.76k
  if (isa<ArrayType>(T->getPointeeType()))
470
0
    OS << '(';
471
2.76k
472
2.76k
  PrintingPolicy InnerPolicy(Policy);
473
2.76k
  InnerPolicy.IncludeTagDefinition = false;
474
2.76k
  TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
475
2.76k
476
2.76k
  OS << "::*";
477
2.76k
}
478
479
void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
480
2.76k
                                          raw_ostream &OS) {
481
2.76k
  IncludeStrongLifetimeRAII Strong(Policy);
482
2.76k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
483
2.76k
  // Handle things like 'int (Cls::*A)[4];' correctly.
484
2.76k
  // FIXME: this should include vectors, but vectors use attributes I guess.
485
2.76k
  if (isa<ArrayType>(T->getPointeeType()))
486
0
    OS << ')';
487
2.76k
  printAfter(T->getPointeeType(), OS);
488
2.76k
}
489
490
void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
491
9.51k
                                           raw_ostream &OS) {
492
9.51k
  IncludeStrongLifetimeRAII Strong(Policy);
493
9.51k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
494
9.51k
  printBefore(T->getElementType(), OS);
495
9.51k
}
496
497
void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
498
9.51k
                                          raw_ostream &OS) {
499
9.51k
  OS << '[';
500
9.51k
  if (T->getIndexTypeQualifiers().hasQualifiers()) {
501
1
    AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(),
502
1
                       Policy.Restrict);
503
1
    OS << ' ';
504
1
  }
505
9.51k
506
9.51k
  if (T->getSizeModifier() == ArrayType::Static)
507
2
    OS << "static ";
508
9.51k
509
9.51k
  OS << T->getSize().getZExtValue() << ']';
510
9.51k
  printAfter(T->getElementType(), OS);
511
9.51k
}
512
513
void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
514
1.32k
                                             raw_ostream &OS) {
515
1.32k
  IncludeStrongLifetimeRAII Strong(Policy);
516
1.32k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
517
1.32k
  printBefore(T->getElementType(), OS);
518
1.32k
}
519
520
void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
521
1.32k
                                            raw_ostream &OS) {
522
1.32k
  OS << "[]";
523
1.32k
  printAfter(T->getElementType(), OS);
524
1.32k
}
525
526
void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
527
201
                                           raw_ostream &OS) {
528
201
  IncludeStrongLifetimeRAII Strong(Policy);
529
201
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
530
201
  printBefore(T->getElementType(), OS);
531
201
}
532
533
void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
534
201
                                          raw_ostream &OS) {
535
201
  OS << '[';
536
201
  if (T->getIndexTypeQualifiers().hasQualifiers()) {
537
1
    AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict);
538
1
    OS << ' ';
539
1
  }
540
201
541
201
  if (T->getSizeModifier() == VariableArrayType::Static)
542
2
    OS << "static ";
543
199
  else if (T->getSizeModifier() == VariableArrayType::Star)
544
8
    OS << '*';
545
201
546
201
  if (T->getSizeExpr())
547
193
    T->getSizeExpr()->printPretty(OS, nullptr, Policy);
548
201
  OS << ']';
549
201
550
201
  printAfter(T->getElementType(), OS);
551
201
}
552
553
237
void TypePrinter::printAdjustedBefore(const AdjustedType *T, raw_ostream &OS) {
554
237
  // Print the adjusted representation, otherwise the adjustment will be
555
237
  // invisible.
556
237
  printBefore(T->getAdjustedType(), OS);
557
237
}
558
559
237
void TypePrinter::printAdjustedAfter(const AdjustedType *T, raw_ostream &OS) {
560
237
  printAfter(T->getAdjustedType(), OS);
561
237
}
562
563
237
void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) {
564
237
  // Print as though it's a pointer.
565
237
  printAdjustedBefore(T, OS);
566
237
}
567
568
237
void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) {
569
237
  printAdjustedAfter(T, OS);
570
237
}
571
572
void TypePrinter::printDependentSizedArrayBefore(
573
                                               const DependentSizedArrayType *T,
574
138
                                               raw_ostream &OS) {
575
138
  IncludeStrongLifetimeRAII Strong(Policy);
576
138
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
577
138
  printBefore(T->getElementType(), OS);
578
138
}
579
580
void TypePrinter::printDependentSizedArrayAfter(
581
                                               const DependentSizedArrayType *T,
582
138
                                               raw_ostream &OS) {
583
138
  OS << '[';
584
138
  if (T->getSizeExpr())
585
138
    T->getSizeExpr()->printPretty(OS, nullptr, Policy);
586
138
  OS << ']';
587
138
  printAfter(T->getElementType(), OS);
588
138
}
589
590
void TypePrinter::printDependentAddressSpaceBefore(
591
1
    const DependentAddressSpaceType *T, raw_ostream &OS) {
592
1
  printBefore(T->getPointeeType(), OS);
593
1
}
594
595
void TypePrinter::printDependentAddressSpaceAfter(
596
1
    const DependentAddressSpaceType *T, raw_ostream &OS) {
597
1
  OS << " __attribute__((address_space(";
598
1
  if (T->getAddrSpaceExpr())
599
1
    T->getAddrSpaceExpr()->printPretty(OS, nullptr, Policy);
600
1
  OS << ")))";
601
1
  printAfter(T->getPointeeType(), OS);
602
1
}
603
604
void TypePrinter::printDependentSizedExtVectorBefore(
605
                                          const DependentSizedExtVectorType *T,
606
0
                                          raw_ostream &OS) {
607
0
  printBefore(T->getElementType(), OS);
608
0
}
609
610
void TypePrinter::printDependentSizedExtVectorAfter(
611
                                          const DependentSizedExtVectorType *T,
612
0
                                          raw_ostream &OS) {
613
0
  OS << " __attribute__((ext_vector_type(";
614
0
  if (T->getSizeExpr())
615
0
    T->getSizeExpr()->printPretty(OS, nullptr, Policy);
616
0
  OS << ")))";
617
0
  printAfter(T->getElementType(), OS);
618
0
}
619
620
14.7k
void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) {
621
14.7k
  switch (T->getVectorKind()) {
622
0
  case VectorType::AltiVecPixel:
623
0
    OS << "__vector __pixel ";
624
0
    break;
625
2.62k
  case VectorType::AltiVecBool:
626
2.62k
    OS << "__vector __bool ";
627
2.62k
    printBefore(T->getElementType(), OS);
628
2.62k
    break;
629
11.3k
  case VectorType::AltiVecVector:
630
11.3k
    OS << "__vector ";
631
11.3k
    printBefore(T->getElementType(), OS);
632
11.3k
    break;
633
67
  case VectorType::NeonVector:
634
67
    OS << "__attribute__((neon_vector_type("
635
67
       << T->getNumElements() << "))) ";
636
67
    printBefore(T->getElementType(), OS);
637
67
    break;
638
0
  case VectorType::NeonPolyVector:
639
0
    OS << "__attribute__((neon_polyvector_type(" <<
640
0
          T->getNumElements() << "))) ";
641
0
    printBefore(T->getElementType(), OS);
642
0
    break;
643
709
  case VectorType::GenericVector: {
644
709
    // FIXME: We prefer to print the size directly here, but have no way
645
709
    // to get the size of the type.
646
709
    OS << "__attribute__((__vector_size__("
647
709
       << T->getNumElements()
648
709
       << " * sizeof(";
649
709
    print(T->getElementType(), OS, StringRef());
650
709
    OS << ")))) ";
651
709
    printBefore(T->getElementType(), OS);
652
709
    break;
653
0
  }
654
14.7k
  }
655
14.7k
}
656
657
14.7k
void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) {
658
14.7k
  printAfter(T->getElementType(), OS);
659
14.7k
}
660
661
void TypePrinter::printDependentVectorBefore(
662
0
    const DependentVectorType *T, raw_ostream &OS) {
663
0
  switch (T->getVectorKind()) {
664
0
  case VectorType::AltiVecPixel:
665
0
    OS << "__vector __pixel ";
666
0
    break;
667
0
  case VectorType::AltiVecBool:
668
0
    OS << "__vector __bool ";
669
0
    printBefore(T->getElementType(), OS);
670
0
    break;
671
0
  case VectorType::AltiVecVector:
672
0
    OS << "__vector ";
673
0
    printBefore(T->getElementType(), OS);
674
0
    break;
675
0
  case VectorType::NeonVector:
676
0
    OS << "__attribute__((neon_vector_type(";
677
0
    if (T->getSizeExpr())
678
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
679
0
    OS << "))) ";
680
0
    printBefore(T->getElementType(), OS);
681
0
    break;
682
0
  case VectorType::NeonPolyVector:
683
0
    OS << "__attribute__((neon_polyvector_type(";
684
0
    if (T->getSizeExpr())
685
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
686
0
    OS << "))) ";
687
0
    printBefore(T->getElementType(), OS);
688
0
    break;
689
0
  case VectorType::GenericVector: {
690
0
    // FIXME: We prefer to print the size directly here, but have no way
691
0
    // to get the size of the type.
692
0
    OS << "__attribute__((__vector_size__(";
693
0
    if (T->getSizeExpr())
694
0
      T->getSizeExpr()->printPretty(OS, nullptr, Policy);
695
0
    OS << " * sizeof(";
696
0
    print(T->getElementType(), OS, StringRef());
697
0
    OS << ")))) ";
698
0
    printBefore(T->getElementType(), OS);
699
0
    break;
700
0
  }
701
0
  }
702
0
}
703
704
void TypePrinter::printDependentVectorAfter(
705
0
    const DependentVectorType *T, raw_ostream &OS) {
706
0
  printAfter(T->getElementType(), OS);
707
0
}
708
709
void TypePrinter::printExtVectorBefore(const ExtVectorType *T,
710
3.31k
                                       raw_ostream &OS) {
711
3.31k
  printBefore(T->getElementType(), OS);
712
3.31k
}
713
714
3.31k
void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) {
715
3.31k
  printAfter(T->getElementType(), OS);
716
3.31k
  OS << " __attribute__((ext_vector_type(";
717
3.31k
  OS << T->getNumElements();
718
3.31k
  OS << ")))";
719
3.31k
}
720
721
void
722
FunctionProtoType::printExceptionSpecification(raw_ostream &OS,
723
                                               const PrintingPolicy &Policy)
724
35.7k
                                                                         const {
725
35.7k
  if (hasDynamicExceptionSpec()) {
726
167
    OS << " throw(";
727
167
    if (getExceptionSpecType() == EST_MSAny)
728
0
      OS << "...";
729
167
    else
730
228
      
for (unsigned I = 0, N = getNumExceptions(); 167
I != N;
++I61
) {
731
61
        if (I)
732
9
          OS << ", ";
733
61
734
61
        OS << getExceptionType(I).stream(Policy);
735
61
      }
736
167
    OS << ')';
737
35.5k
  } else if (EST_NoThrow == getExceptionSpecType()) {
738
6
    OS << " __attribute__((nothrow))";
739
35.5k
  } else if (isNoexceptExceptionSpec(getExceptionSpecType())) {
740
779
    OS << " noexcept";
741
779
    // FIXME:Is it useful to print out the expression for a non-dependent
742
779
    // noexcept specification?
743
779
    if (isComputedNoexcept(getExceptionSpecType())) {
744
20
      OS << '(';
745
20
      if (getNoexceptExpr())
746
20
        getNoexceptExpr()->printPretty(OS, nullptr, Policy);
747
20
      OS << ')';
748
20
    }
749
779
  }
750
35.7k
}
751
752
void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T,
753
35.6k
                                           raw_ostream &OS) {
754
35.6k
  if (T->hasTrailingReturn()) {
755
71
    OS << "auto ";
756
71
    if (!HasEmptyPlaceHolder)
757
24
      OS << '(';
758
35.5k
  } else {
759
35.5k
    // If needed for precedence reasons, wrap the inner part in grouping parens.
760
35.5k
    SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
761
35.5k
    printBefore(T->getReturnType(), OS);
762
35.5k
    if (!PrevPHIsEmpty.get())
763
22.7k
      OS << '(';
764
35.5k
  }
765
35.6k
}
766
767
23
StringRef clang::getParameterABISpelling(ParameterABI ABI) {
768
23
  switch (ABI) {
769
0
  case ParameterABI::Ordinary:
770
0
    llvm_unreachable("asking for spelling of ordinary parameter ABI");
771
6
  case ParameterABI::SwiftContext:
772
6
    return "swift_context";
773
9
  case ParameterABI::SwiftErrorResult:
774
9
    return "swift_error_result";
775
8
  case ParameterABI::SwiftIndirectResult:
776
8
    return "swift_indirect_result";
777
0
  }
778
0
  llvm_unreachable("bad parameter ABI kind");
779
0
}
780
781
void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T,
782
35.6k
                                          raw_ostream &OS) {
783
35.6k
  // If needed for precedence reasons, wrap the inner part in grouping parens.
784
35.6k
  if (!HasEmptyPlaceHolder)
785
22.7k
    OS << ')';
786
35.6k
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
787
35.6k
788
35.6k
  OS << '(';
789
35.6k
  {
790
35.6k
    ParamPolicyRAII ParamPolicy(Policy);
791
63.5k
    for (unsigned i = 0, e = T->getNumParams(); i != e; 
++i27.8k
) {
792
27.8k
      if (i) 
OS << ", "4.95k
;
793
27.8k
794
27.8k
      auto EPI = T->getExtParameterInfo(i);
795
27.8k
      if (EPI.isConsumed()) 
OS << "__attribute__((ns_consumed)) "159
;
796
27.8k
      if (EPI.isNoEscape())
797
37
        OS << "__attribute__((noescape)) ";
798
27.8k
      auto ABI = EPI.getABI();
799
27.8k
      if (ABI != ParameterABI::Ordinary)
800
0
        OS << "__attribute__((" << getParameterABISpelling(ABI) << ")) ";
801
27.8k
802
27.8k
      print(T->getParamType(i), OS, StringRef());
803
27.8k
    }
804
35.6k
  }
805
35.6k
806
35.6k
  if (T->isVariadic()) {
807
389
    if (T->getNumParams())
808
364
      OS << ", ";
809
389
    OS << "...";
810
35.2k
  } else if (T->getNumParams() == 0 && 
Policy.UseVoidForZeroParams12.7k
) {
811
880
    // Do not emit int() if we have a proto, emit 'int(void)'.
812
880
    OS << "void";
813
880
  }
814
35.6k
815
35.6k
  OS << ')';
816
35.6k
817
35.6k
  FunctionType::ExtInfo Info = T->getExtInfo();
818
35.6k
819
35.6k
  printFunctionAfter(Info, OS);
820
35.6k
821
35.6k
  if (!T->getMethodQuals().empty())
822
1.41k
    OS << " " << T->getMethodQuals().getAsString();
823
35.6k
824
35.6k
  switch (T->getRefQualifier()) {
825
35.5k
  case RQ_None:
826
35.5k
    break;
827
0
828
46
  case RQ_LValue:
829
46
    OS << " &";
830
46
    break;
831
0
832
33
  case RQ_RValue:
833
33
    OS << " &&";
834
33
    break;
835
35.6k
  }
836
35.6k
  T->printExceptionSpecification(OS, Policy);
837
35.6k
838
35.6k
  if (T->hasTrailingReturn()) {
839
71
    OS << " -> ";
840
71
    print(T->getReturnType(), OS, StringRef());
841
71
  } else
842
35.5k
    printAfter(T->getReturnType(), OS);
843
35.6k
}
844
845
void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
846
36.0k
                                     raw_ostream &OS) {
847
36.0k
  if (!InsideCCAttribute) {
848
35.7k
    switch (Info.getCC()) {
849
35.2k
    case CC_C:
850
35.2k
      // The C calling convention is the default on the vast majority of platforms
851
35.2k
      // we support.  If the user wrote it explicitly, it will usually be printed
852
35.2k
      // while traversing the AttributedType.  If the type has been desugared, let
853
35.2k
      // the canonical spelling be the implicit calling convention.
854
35.2k
      // FIXME: It would be better to be explicit in certain contexts, such as a
855
35.2k
      // cdecl function typedef used to declare a member function with the
856
35.2k
      // Microsoft C++ ABI.
857
35.2k
      break;
858
49
    case CC_X86StdCall:
859
49
      OS << " __attribute__((stdcall))";
860
49
      break;
861
42
    case CC_X86FastCall:
862
42
      OS << " __attribute__((fastcall))";
863
42
      break;
864
299
    case CC_X86ThisCall:
865
299
      OS << " __attribute__((thiscall))";
866
299
      break;
867
6
    case CC_X86VectorCall:
868
6
      OS << " __attribute__((vectorcall))";
869
6
      break;
870
0
    case CC_X86Pascal:
871
0
      OS << " __attribute__((pascal))";
872
0
      break;
873
0
    case CC_AAPCS:
874
0
      OS << " __attribute__((pcs(\"aapcs\")))";
875
0
      break;
876
0
    case CC_AAPCS_VFP:
877
0
      OS << " __attribute__((pcs(\"aapcs-vfp\")))";
878
0
      break;
879
3
    case CC_AArch64VectorCall:
880
3
      OS << "__attribute__((aarch64_vector_pcs))";
881
3
      break;
882
0
    case CC_IntelOclBicc:
883
0
      OS << " __attribute__((intel_ocl_bicc))";
884
0
      break;
885
4
    case CC_Win64:
886
4
      OS << " __attribute__((ms_abi))";
887
4
      break;
888
4
    case CC_X86_64SysV:
889
4
      OS << " __attribute__((sysv_abi))";
890
4
      break;
891
0
    case CC_X86RegCall:
892
0
      OS << " __attribute__((regcall))";
893
0
      break;
894
84
    case CC_SpirFunction:
895
84
    case CC_OpenCLKernel:
896
84
      // Do nothing. These CCs are not available as attributes.
897
84
      break;
898
84
    case CC_Swift:
899
0
      OS << " __attribute__((swiftcall))";
900
0
      break;
901
84
    case CC_PreserveMost:
902
20
      OS << " __attribute__((preserve_most))";
903
20
      break;
904
84
    case CC_PreserveAll:
905
20
      OS << " __attribute__((preserve_all))";
906
20
      break;
907
36.0k
    }
908
36.0k
  }
909
36.0k
910
36.0k
  if (Info.getNoReturn())
911
69
    OS << " __attribute__((noreturn))";
912
36.0k
  if (Info.getProducesResult())
913
5
    OS << " __attribute__((ns_returns_retained))";
914
36.0k
  if (Info.getRegParm())
915
0
    OS << " __attribute__((regparm ("
916
0
       << Info.getRegParm() << ")))";
917
36.0k
  if (Info.getNoCallerSavedRegs())
918
4
    OS << " __attribute__((no_caller_saved_registers))";
919
36.0k
  if (Info.getNoCfCheck())
920
10
    OS << " __attribute__((nocf_check))";
921
36.0k
}
922
923
void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T,
924
372
                                             raw_ostream &OS) {
925
372
  // If needed for precedence reasons, wrap the inner part in grouping parens.
926
372
  SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
927
372
  printBefore(T->getReturnType(), OS);
928
372
  if (!PrevPHIsEmpty.get())
929
154
    OS << '(';
930
372
}
931
932
void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T,
933
372
                                            raw_ostream &OS) {
934
372
  // If needed for precedence reasons, wrap the inner part in grouping parens.
935
372
  if (!HasEmptyPlaceHolder)
936
154
    OS << ')';
937
372
  SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
938
372
939
372
  OS << "()";
940
372
  printFunctionAfter(T->getExtInfo(), OS);
941
372
  printAfter(T->getReturnType(), OS);
942
372
}
943
944
21.6k
void TypePrinter::printTypeSpec(NamedDecl *D, raw_ostream &OS) {
945
21.6k
946
21.6k
  // Compute the full nested-name-specifier for this type.
947
21.6k
  // In C, this will always be empty except when the type
948
21.6k
  // being printed is anonymous within other Record.
949
21.6k
  if (!Policy.SuppressScope)
950
19.6k
    AppendScope(D->getDeclContext(), OS);
951
21.6k
952
21.6k
  IdentifierInfo *II = D->getIdentifier();
953
21.6k
  OS << II->getName();
954
21.6k
  spaceBeforePlaceHolder(OS);
955
21.6k
}
956
957
void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T,
958
0
                                             raw_ostream &OS) {
959
0
  printTypeSpec(T->getDecl(), OS);
960
0
}
961
962
void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T,
963
0
                                            raw_ostream &OS) {}
964
965
21.6k
void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) {
966
21.6k
  printTypeSpec(T->getDecl(), OS);
967
21.6k
}
968
969
void TypePrinter::printMacroQualifiedBefore(const MacroQualifiedType *T,
970
33
                                            raw_ostream &OS) {
971
33
  StringRef MacroName = T->getMacroIdentifier()->getName();
972
33
  OS << MacroName << " ";
973
33
974
33
  // Since this type is meant to print the macro instead of the whole attribute,
975
33
  // we trim any attributes and go directly to the original modified type.
976
33
  printBefore(T->getModifiedType(), OS);
977
33
}
978
979
void TypePrinter::printMacroQualifiedAfter(const MacroQualifiedType *T,
980
33
                                           raw_ostream &OS) {
981
33
  printAfter(T->getModifiedType(), OS);
982
33
}
983
984
21.6k
void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {}
985
986
void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
987
98
                                        raw_ostream &OS) {
988
98
  OS << "typeof ";
989
98
  if (T->getUnderlyingExpr())
990
98
    T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
991
98
  spaceBeforePlaceHolder(OS);
992
98
}
993
994
void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
995
98
                                       raw_ostream &OS) {}
996
997
5
void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
998
5
  OS << "typeof(";
999
5
  print(T->getUnderlyingType(), OS, StringRef());
1000
5
  OS << ')';
1001
5
  spaceBeforePlaceHolder(OS);
1002
5
}
1003
1004
5
void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) {}
1005
1006
197
void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
1007
197
  OS << "decltype(";
1008
197
  if (T->getUnderlyingExpr())
1009
197
    T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
1010
197
  OS << ')';
1011
197
  spaceBeforePlaceHolder(OS);
1012
197
}
1013
1014
197
void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) {}
1015
1016
void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T,
1017
4
                                            raw_ostream &OS) {
1018
4
  IncludeStrongLifetimeRAII Strong(Policy);
1019
4
1020
4
  switch (T->getUTTKind()) {
1021
4
    case UnaryTransformType::EnumUnderlyingType:
1022
4
      OS << "__underlying_type(";
1023
4
      print(T->getBaseType(), OS, StringRef());
1024
4
      OS << ')';
1025
4
      spaceBeforePlaceHolder(OS);
1026
4
      return;
1027
0
  }
1028
0
1029
0
  printBefore(T->getBaseType(), OS);
1030
0
}
1031
1032
void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T,
1033
4
                                           raw_ostream &OS) {
1034
4
  IncludeStrongLifetimeRAII Strong(Policy);
1035
4
1036
4
  switch (T->getUTTKind()) {
1037
4
    case UnaryTransformType::EnumUnderlyingType:
1038
4
      return;
1039
0
  }
1040
0
1041
0
  printAfter(T->getBaseType(), OS);
1042
0
}
1043
1044
1.76k
void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
1045
1.76k
  // If the type has been deduced, do not print 'auto'.
1046
1.76k
  if (!T->getDeducedType().isNull()) {
1047
802
    printBefore(T->getDeducedType(), OS);
1048
962
  } else {
1049
962
    if (T->isConstrained()) {
1050
8
      OS << T->getTypeConstraintConcept()->getName();
1051
8
      auto Args = T->getTypeConstraintArguments();
1052
8
      if (!Args.empty())
1053
2
        printTemplateArgumentList(OS, Args, Policy);
1054
8
      OS << ' ';
1055
8
    }
1056
962
    switch (T->getKeyword()) {
1057
910
    case AutoTypeKeyword::Auto: OS << "auto"; break;
1058
50
    case AutoTypeKeyword::DecltypeAuto: OS << "decltype(auto)"; break;
1059
2
    case AutoTypeKeyword::GNUAutoType: OS << "__auto_type"; break;
1060
962
    }
1061
962
    spaceBeforePlaceHolder(OS);
1062
962
  }
1063
1.76k
}
1064
1065
1.76k
void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) {
1066
1.76k
  // If the type has been deduced, do not print 'auto'.
1067
1.76k
  if (!T->getDeducedType().isNull())
1068
802
    printAfter(T->getDeducedType(), OS);
1069
1.76k
}
1070
1071
void TypePrinter::printDeducedTemplateSpecializationBefore(
1072
104
    const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1073
104
  // If the type has been deduced, print the deduced type.
1074
104
  if (!T->getDeducedType().isNull()) {
1075
20
    printBefore(T->getDeducedType(), OS);
1076
84
  } else {
1077
84
    IncludeStrongLifetimeRAII Strong(Policy);
1078
84
    T->getTemplateName().print(OS, Policy);
1079
84
    spaceBeforePlaceHolder(OS);
1080
84
  }
1081
104
}
1082
1083
void TypePrinter::printDeducedTemplateSpecializationAfter(
1084
104
    const DeducedTemplateSpecializationType *T, raw_ostream &OS) {
1085
104
  // If the type has been deduced, print the deduced type.
1086
104
  if (!T->getDeducedType().isNull())
1087
20
    printAfter(T->getDeducedType(), OS);
1088
104
}
1089
1090
407
void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) {
1091
407
  IncludeStrongLifetimeRAII Strong(Policy);
1092
407
1093
407
  OS << "_Atomic(";
1094
407
  print(T->getValueType(), OS, StringRef());
1095
407
  OS << ')';
1096
407
  spaceBeforePlaceHolder(OS);
1097
407
}
1098
1099
407
void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) {}
1100
1101
96
void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
1102
96
  IncludeStrongLifetimeRAII Strong(Policy);
1103
96
1104
96
  if (T->isReadOnly())
1105
74
    OS << "read_only ";
1106
22
  else
1107
22
    OS << "write_only ";
1108
96
  OS << "pipe ";
1109
96
  print(T->getElementType(), OS, StringRef());
1110
96
  spaceBeforePlaceHolder(OS);
1111
96
}
1112
1113
96
void TypePrinter::printPipeAfter(const PipeType *T, raw_ostream &OS) {}
1114
1115
/// Appends the given scope to the end of a string.
1116
2.40M
void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
1117
2.40M
  if (DC->isTranslationUnit()) 
return950k
;
1118
1.45M
  if (DC->isFunctionOrMethod()) 
return14.4k
;
1119
1.43M
  AppendScope(DC->getParent(), OS);
1120
1.43M
1121
1.43M
  if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1122
1.37M
    if (Policy.SuppressUnwrittenScope &&
1123
1.37M
        
(0
NS->isAnonymousNamespace()0
||
NS->isInline()0
))
1124
0
      return;
1125
1.37M
    if (NS->getIdentifier())
1126
1.37M
      OS << NS->getName() << "::";
1127
119
    else
1128
119
      OS << "(anonymous namespace)::";
1129
1.37M
  } else 
if (const auto *68.1k
Spec68.1k
= dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1130
23.3k
    IncludeStrongLifetimeRAII Strong(Policy);
1131
23.3k
    OS << Spec->getIdentifier()->getName();
1132
23.3k
    const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1133
23.3k
    printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy);
1134
23.3k
    OS << "::";
1135
44.7k
  } else if (const auto *Tag = dyn_cast<TagDecl>(DC)) {
1136
21.1k
    if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
1137
0
      OS << Typedef->getIdentifier()->getName() << "::";
1138
21.1k
    else if (Tag->getIdentifier())
1139
21.0k
      OS << Tag->getIdentifier()->getName() << "::";
1140
138
    else
1141
138
      return;
1142
21.1k
  }
1143
1.43M
}
1144
1145
955k
void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
1146
955k
  if (Policy.IncludeTagDefinition) {
1147
0
    PrintingPolicy SubPolicy = Policy;
1148
0
    SubPolicy.IncludeTagDefinition = false;
1149
0
    D->print(OS, SubPolicy, Indentation);
1150
0
    spaceBeforePlaceHolder(OS);
1151
0
    return;
1152
0
  }
1153
955k
1154
955k
  bool HasKindDecoration = false;
1155
955k
1156
955k
  // We don't print tags unless this is an elaborated type.
1157
955k
  // In C, we just assume every RecordType is an elaborated type.
1158
955k
  if (!Policy.SuppressTagKeyword && 
!D->getTypedefNameForAnonDecl()12.6k
) {
1159
12.4k
    HasKindDecoration = true;
1160
12.4k
    OS << D->getKindName();
1161
12.4k
    OS << ' ';
1162
12.4k
  }
1163
955k
1164
955k
  // Compute the full nested-name-specifier for this type.
1165
955k
  // In C, this will always be empty except when the type
1166
955k
  // being printed is anonymous within other Record.
1167
955k
  if (!Policy.SuppressScope)
1168
945k
    AppendScope(D->getDeclContext(), OS);
1169
955k
1170
955k
  if (const IdentifierInfo *II = D->getIdentifier())
1171
938k
    OS << II->getName();
1172
16.7k
  else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
1173
728
    assert(Typedef->getIdentifier() && "Typedef without identifier?");
1174
728
    OS << Typedef->getIdentifier()->getName();
1175
15.9k
  } else {
1176
15.9k
    // Make an unambiguous representation for anonymous types, e.g.
1177
15.9k
    //   (anonymous enum at /usr/include/string.h:120:9)
1178
15.9k
    OS << (Policy.MSVCFormatting ? 
'`'5
:
'('15.9k
);
1179
15.9k
1180
15.9k
    if (isa<CXXRecordDecl>(D) && 
cast<CXXRecordDecl>(D)->isLambda()14.8k
) {
1181
8.10k
      OS << "lambda";
1182
8.10k
      HasKindDecoration = true;
1183
8.10k
    } else {
1184
7.88k
      OS << "anonymous";
1185
7.88k
    }
1186
15.9k
1187
15.9k
    if (Policy.AnonymousTagLocations) {
1188
15.9k
      // Suppress the redundant tag keyword if we just printed one.
1189
15.9k
      // We don't have to worry about ElaboratedTypes here because you can't
1190
15.9k
      // refer to an anonymous type with one.
1191
15.9k
      if (!HasKindDecoration)
1192
7.07k
        OS << " " << D->getKindName();
1193
15.9k
1194
15.9k
      PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
1195
15.9k
          D->getLocation());
1196
15.9k
      if (PLoc.isValid()) {
1197
9.46k
        OS << " at ";
1198
9.46k
        StringRef File = PLoc.getFilename();
1199
9.46k
        if (auto *Callbacks = Policy.Callbacks)
1200
5.56k
          OS << Callbacks->remapPath(File);
1201
3.89k
        else
1202
3.89k
          OS << File;
1203
9.46k
        OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
1204
9.46k
      }
1205
15.9k
    }
1206
15.9k
1207
15.9k
    OS << (Policy.MSVCFormatting ? 
'\''5
:
')'15.9k
);
1208
15.9k
  }
1209
955k
1210
955k
  // If this is a class template specialization, print the template
1211
955k
  // arguments.
1212
955k
  if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1213
519k
    ArrayRef<TemplateArgument> Args;
1214
519k
    TypeSourceInfo *TAW = Spec->getTypeAsWritten();
1215
519k
    if (!Policy.PrintCanonicalTypes && 
TAW301k
) {
1216
6.64k
      const TemplateSpecializationType *TST =
1217
6.64k
        cast<TemplateSpecializationType>(TAW->getType());
1218
6.64k
      Args = TST->template_arguments();
1219
512k
    } else {
1220
512k
      const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1221
512k
      Args = TemplateArgs.asArray();
1222
512k
    }
1223
519k
    IncludeStrongLifetimeRAII Strong(Policy);
1224
519k
    printTemplateArgumentList(OS, Args, Policy);
1225
519k
  }
1226
955k
1227
955k
  spaceBeforePlaceHolder(OS);
1228
955k
}
1229
1230
946k
void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
1231
946k
  printTag(T->getDecl(), OS);
1232
946k
}
1233
1234
946k
void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) {}
1235
1236
8.83k
void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) {
1237
8.83k
  printTag(T->getDecl(), OS);
1238
8.83k
}
1239
1240
8.84k
void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) {}
1241
1242
void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T,
1243
33.5k
                                              raw_ostream &OS) {
1244
33.5k
  TemplateTypeParmDecl *D = T->getDecl();
1245
33.5k
  if (D && 
D->isImplicit()31.1k
) {
1246
49
    if (auto *TC = D->getTypeConstraint()) {
1247
3
      TC->print(OS, Policy);
1248
3
      OS << ' ';
1249
3
    }
1250
49
    OS << "auto";
1251
33.5k
  } else if (IdentifierInfo *Id = T->getIdentifier())
1252
31.0k
    OS << Id->getName();
1253
2.47k
  else
1254
2.47k
    OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex();
1255
33.5k
1256
33.5k
  spaceBeforePlaceHolder(OS);
1257
33.5k
}
1258
1259
void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T,
1260
34.6k
                                             raw_ostream &OS) {}
1261
1262
void TypePrinter::printSubstTemplateTypeParmBefore(
1263
                                             const SubstTemplateTypeParmType *T,
1264
13.5k
                                             raw_ostream &OS) {
1265
13.5k
  IncludeStrongLifetimeRAII Strong(Policy);
1266
13.5k
  printBefore(T->getReplacementType(), OS);
1267
13.5k
}
1268
1269
void TypePrinter::printSubstTemplateTypeParmAfter(
1270
                                             const SubstTemplateTypeParmType *T,
1271
15.0k
                                             raw_ostream &OS) {
1272
15.0k
  IncludeStrongLifetimeRAII Strong(Policy);
1273
15.0k
  printAfter(T->getReplacementType(), OS);
1274
15.0k
}
1275
1276
void TypePrinter::printSubstTemplateTypeParmPackBefore(
1277
                                        const SubstTemplateTypeParmPackType *T,
1278
8
                                        raw_ostream &OS) {
1279
8
  IncludeStrongLifetimeRAII Strong(Policy);
1280
8
  printTemplateTypeParmBefore(T->getReplacedParameter(), OS);
1281
8
}
1282
1283
void TypePrinter::printSubstTemplateTypeParmPackAfter(
1284
                                        const SubstTemplateTypeParmPackType *T,
1285
8
                                        raw_ostream &OS) {
1286
8
  IncludeStrongLifetimeRAII Strong(Policy);
1287
8
  printTemplateTypeParmAfter(T->getReplacedParameter(), OS);
1288
8
}
1289
1290
void TypePrinter::printTemplateSpecializationBefore(
1291
                                            const TemplateSpecializationType *T,
1292
22.3k
                                            raw_ostream &OS) {
1293
22.3k
  IncludeStrongLifetimeRAII Strong(Policy);
1294
22.3k
  T->getTemplateName().print(OS, Policy);
1295
22.3k
1296
22.3k
  printTemplateArgumentList(OS, T->template_arguments(), Policy);
1297
22.3k
  spaceBeforePlaceHolder(OS);
1298
22.3k
}
1299
1300
void TypePrinter::printTemplateSpecializationAfter(
1301
                                            const TemplateSpecializationType *T,
1302
5.54k
                                            raw_ostream &OS) {}
1303
1304
void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T,
1305
16.7k
                                               raw_ostream &OS) {
1306
16.7k
  printTemplateSpecializationBefore(T->getInjectedTST(), OS);
1307
16.7k
}
1308
1309
void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
1310
16.7k
                                               raw_ostream &OS) {}
1311
1312
void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
1313
5.12k
                                        raw_ostream &OS) {
1314
5.12k
  if (Policy.IncludeTagDefinition && 
T->getOwnedTagDecl()246
) {
1315
246
    TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
1316
246
    assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
1317
246
           "OwnedTagDecl expected to be a declaration for the type");
1318
246
    PrintingPolicy SubPolicy = Policy;
1319
246
    SubPolicy.IncludeTagDefinition = false;
1320
246
    OwnedTagDecl->print(OS, SubPolicy, Indentation);
1321
246
    spaceBeforePlaceHolder(OS);
1322
246
    return;
1323
246
  }
1324
4.88k
1325
4.88k
  // The tag definition will take care of these.
1326
4.88k
  if (!Policy.IncludeTagDefinition)
1327
4.88k
  {
1328
4.88k
    OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1329
4.88k
    if (T->getKeyword() != ETK_None)
1330
3.83k
      OS << " ";
1331
4.88k
    NestedNameSpecifier *Qualifier = T->getQualifier();
1332
4.88k
    if (Qualifier)
1333
2.29k
      Qualifier->print(OS, Policy);
1334
4.88k
  }
1335
4.88k
1336
4.88k
  ElaboratedTypePolicyRAII PolicyRAII(Policy);
1337
4.88k
  printBefore(T->getNamedType(), OS);
1338
4.88k
}
1339
1340
void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
1341
5.14k
                                        raw_ostream &OS) {
1342
5.14k
  if (Policy.IncludeTagDefinition && 
T->getOwnedTagDecl()246
)
1343
246
    return;
1344
4.90k
  ElaboratedTypePolicyRAII PolicyRAII(Policy);
1345
4.90k
  printAfter(T->getNamedType(), OS);
1346
4.90k
}
1347
1348
2.23k
void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) {
1349
2.23k
  if (!HasEmptyPlaceHolder && 
!isa<FunctionType>(T->getInnerType())1.98k
) {
1350
201
    printBefore(T->getInnerType(), OS);
1351
201
    OS << '(';
1352
201
  } else
1353
2.03k
    printBefore(T->getInnerType(), OS);
1354
2.23k
}
1355
1356
2.23k
void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) {
1357
2.23k
  if (!HasEmptyPlaceHolder && 
!isa<FunctionType>(T->getInnerType())1.98k
) {
1358
200
    OS << ')';
1359
200
    printAfter(T->getInnerType(), OS);
1360
200
  } else
1361
2.03k
    printAfter(T->getInnerType(), OS);
1362
2.23k
}
1363
1364
void TypePrinter::printDependentNameBefore(const DependentNameType *T,
1365
196
                                           raw_ostream &OS) {
1366
196
  OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1367
196
  if (T->getKeyword() != ETK_None)
1368
189
    OS << " ";
1369
196
1370
196
  T->getQualifier()->print(OS, Policy);
1371
196
1372
196
  OS << T->getIdentifier()->getName();
1373
196
  spaceBeforePlaceHolder(OS);
1374
196
}
1375
1376
void TypePrinter::printDependentNameAfter(const DependentNameType *T,
1377
196
                                          raw_ostream &OS) {}
1378
1379
void TypePrinter::printDependentTemplateSpecializationBefore(
1380
21
        const DependentTemplateSpecializationType *T, raw_ostream &OS) {
1381
21
  IncludeStrongLifetimeRAII Strong(Policy);
1382
21
1383
21
  OS << TypeWithKeyword::getKeywordName(T->getKeyword());
1384
21
  if (T->getKeyword() != ETK_None)
1385
21
    OS << " ";
1386
21
1387
21
  if (T->getQualifier())
1388
13
    T->getQualifier()->print(OS, Policy);
1389
21
  OS << T->getIdentifier()->getName();
1390
21
  printTemplateArgumentList(OS, T->template_arguments(), Policy);
1391
21
  spaceBeforePlaceHolder(OS);
1392
21
}
1393
1394
void TypePrinter::printDependentTemplateSpecializationAfter(
1395
21
        const DependentTemplateSpecializationType *T, raw_ostream &OS) {}
1396
1397
void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
1398
448
                                           raw_ostream &OS) {
1399
448
  printBefore(T->getPattern(), OS);
1400
448
}
1401
1402
void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
1403
448
                                          raw_ostream &OS) {
1404
448
  printAfter(T->getPattern(), OS);
1405
448
  OS << "...";
1406
448
}
1407
1408
void TypePrinter::printAttributedBefore(const AttributedType *T,
1409
1.39k
                                        raw_ostream &OS) {
1410
1.39k
  // FIXME: Generate this with TableGen.
1411
1.39k
1412
1.39k
  // Prefer the macro forms of the GC and ownership qualifiers.
1413
1.39k
  if (T->getAttrKind() == attr::ObjCGC ||
1414
1.39k
      
T->getAttrKind() == attr::ObjCOwnership1.35k
)
1415
483
    return printBefore(T->getEquivalentType(), OS);
1416
907
1417
907
  if (T->getAttrKind() == attr::ObjCKindOf)
1418
76
    OS << "__kindof ";
1419
907
1420
907
  if (T->getAttrKind() == attr::AddressSpace)
1421
59
    printBefore(T->getEquivalentType(), OS);
1422
848
  else
1423
848
    printBefore(T->getModifiedType(), OS);
1424
907
1425
907
  if (T->isMSTypeSpec()) {
1426
11
    switch (T->getAttrKind()) {
1427
0
    default: return;
1428
5
    case attr::Ptr32: OS << " __ptr32"; break;
1429
2
    case attr::Ptr64: OS << " __ptr64"; break;
1430
2
    case attr::SPtr: OS << " __sptr"; break;
1431
2
    case attr::UPtr: OS << " __uptr"; break;
1432
11
    }
1433
11
    spaceBeforePlaceHolder(OS);
1434
11
  }
1435
907
1436
907
  // Print nullability type specifiers.
1437
907
  if (T->getImmediateNullability()) {
1438
519
    if (T->getAttrKind() == attr::TypeNonNull)
1439
182
      OS << " _Nonnull";
1440
337
    else if (T->getAttrKind() == attr::TypeNullable)
1441
321
      OS << " _Nullable";
1442
16
    else if (T->getAttrKind() == attr::TypeNullUnspecified)
1443
16
      OS << " _Null_unspecified";
1444
16
    else
1445
16
      
llvm_unreachable0
("unhandled nullability");
1446
519
    spaceBeforePlaceHolder(OS);
1447
519
  }
1448
907
}
1449
1450
void TypePrinter::printAttributedAfter(const AttributedType *T,
1451
1.33k
                                       raw_ostream &OS) {
1452
1.33k
  // FIXME: Generate this with TableGen.
1453
1.33k
1454
1.33k
  // Prefer the macro forms of the GC and ownership qualifiers.
1455
1.33k
  if (T->getAttrKind() == attr::ObjCGC ||
1456
1.33k
      
T->getAttrKind() == attr::ObjCOwnership1.29k
)
1457
483
    return printAfter(T->getEquivalentType(), OS);
1458
848
1459
848
  // If this is a calling convention attribute, don't print the implicit CC from
1460
848
  // the modified type.
1461
848
  SaveAndRestore<bool> MaybeSuppressCC(InsideCCAttribute, T->isCallingConv());
1462
848
1463
848
  printAfter(T->getModifiedType(), OS);
1464
848
1465
848
  // Some attributes are printed as qualifiers before the type, so we have
1466
848
  // nothing left to do.
1467
848
  if (T->getAttrKind() == attr::ObjCKindOf ||
1468
848
      
T->isMSTypeSpec()831
||
T->getImmediateNullability()820
)
1469
547
    return;
1470
301
1471
301
  // Don't print the inert __unsafe_unretained attribute at all.
1472
301
  if (T->getAttrKind() == attr::ObjCInertUnsafeUnretained)
1473
2
    return;
1474
299
1475
299
  // Don't print ns_returns_retained unless it had an effect.
1476
299
  if (T->getAttrKind() == attr::NSReturnsRetained &&
1477
299
      !T->getEquivalentType()->castAs<FunctionType>()
1478
3
                             ->getExtInfo().getProducesResult())
1479
0
    return;
1480
299
1481
299
  if (T->getAttrKind() == attr::LifetimeBound) {
1482
0
    OS << " [[clang::lifetimebound]]";
1483
0
    return;
1484
0
  }
1485
299
1486
299
  // The printing of the address_space attribute is handled by the qualifier
1487
299
  // since it is still stored in the qualifier. Return early to prevent printing
1488
299
  // this twice.
1489
299
  if (T->getAttrKind() == attr::AddressSpace)
1490
59
    return;
1491
240
1492
240
  OS << " __attribute__((";
1493
240
  switch (T->getAttrKind()) {
1494
0
#define TYPE_ATTR(NAME)
1495
0
#define DECL_OR_TYPE_ATTR(NAME)
1496
0
#define ATTR(NAME) case attr::NAME:
1497
0
#include "clang/Basic/AttrList.inc"
1498
0
    llvm_unreachable("non-type attribute attached to type");
1499
0
1500
0
  case attr::OpenCLPrivateAddressSpace:
1501
0
  case attr::OpenCLGlobalAddressSpace:
1502
0
  case attr::OpenCLLocalAddressSpace:
1503
0
  case attr::OpenCLConstantAddressSpace:
1504
0
  case attr::OpenCLGenericAddressSpace:
1505
0
    // FIXME: Update printAttributedBefore to print these once we generate
1506
0
    // AttributedType nodes for them.
1507
0
    break;
1508
0
1509
0
  case attr::LifetimeBound:
1510
0
  case attr::TypeNonNull:
1511
0
  case attr::TypeNullable:
1512
0
  case attr::TypeNullUnspecified:
1513
0
  case attr::ObjCGC:
1514
0
  case attr::ObjCInertUnsafeUnretained:
1515
0
  case attr::ObjCKindOf:
1516
0
  case attr::ObjCOwnership:
1517
0
  case attr::Ptr32:
1518
0
  case attr::Ptr64:
1519
0
  case attr::SPtr:
1520
0
  case attr::UPtr:
1521
0
  case attr::AddressSpace:
1522
0
    llvm_unreachable("This attribute should have been handled already");
1523
0
1524
3
  case attr::NSReturnsRetained:
1525
3
    OS << "ns_returns_retained";
1526
3
    break;
1527
0
1528
0
  // FIXME: When Sema learns to form this AttributedType, avoid printing the
1529
0
  // attribute again in printFunctionProtoAfter.
1530
0
  case attr::AnyX86NoCfCheck: OS << "nocf_check"; break;
1531
97
  case attr::CDecl: OS << "cdecl"; break;
1532
25
  case attr::FastCall: OS << "fastcall"; break;
1533
26
  case attr::StdCall: OS << "stdcall"; break;
1534
27
  case attr::ThisCall: OS << "thiscall"; break;
1535
0
  case attr::SwiftCall: OS << "swiftcall"; break;
1536
6
  case attr::VectorCall: OS << "vectorcall"; break;
1537
0
  case attr::Pascal: OS << "pascal"; break;
1538
6
  case attr::MSABI: OS << "ms_abi"; break;
1539
6
  case attr::SysVABI: OS << "sysv_abi"; break;
1540
0
  case attr::RegCall: OS << "regcall"; break;
1541
0
  case attr::Pcs: {
1542
0
    OS << "pcs(";
1543
0
   QualType t = T->getEquivalentType();
1544
0
   while (!t->isFunctionType())
1545
0
     t = t->getPointeeType();
1546
0
   OS << (t->castAs<FunctionType>()->getCallConv() == CC_AAPCS ?
1547
0
         "\"aapcs\"" : "\"aapcs-vfp\"");
1548
0
   OS << ')';
1549
0
   break;
1550
0
  }
1551
0
  case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break;
1552
0
  case attr::IntelOclBicc: OS << "inteloclbicc"; break;
1553
20
  case attr::PreserveMost:
1554
20
    OS << "preserve_most";
1555
20
    break;
1556
0
1557
20
  case attr::PreserveAll:
1558
20
    OS << "preserve_all";
1559
20
    break;
1560
4
  case attr::NoDeref:
1561
4
    OS << "noderef";
1562
4
    break;
1563
0
  case attr::AcquireHandle:
1564
0
    OS << "acquire_handle";
1565
0
    break;
1566
0
  case attr::ArmMveStrictPolymorphism:
1567
0
    OS << "__clang_arm_mve_strict_polymorphism";
1568
0
    break;
1569
240
  }
1570
240
  OS << "))";
1571
240
}
1572
1573
void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
1574
28.5k
                                           raw_ostream &OS) {
1575
28.5k
  OS << T->getDecl()->getName();
1576
28.5k
  spaceBeforePlaceHolder(OS);
1577
28.5k
}
1578
1579
void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T,
1580
11.4k
                                          raw_ostream &OS) {}
1581
1582
void TypePrinter::printObjCTypeParamBefore(const ObjCTypeParamType *T,
1583
15
                                          raw_ostream &OS) {
1584
15
  OS << T->getDecl()->getName();
1585
15
  if (!T->qual_empty()) {
1586
0
    bool isFirst = true;
1587
0
    OS << '<';
1588
0
    for (const auto *I : T->quals()) {
1589
0
      if (isFirst)
1590
0
        isFirst = false;
1591
0
      else
1592
0
        OS << ',';
1593
0
      OS << I->getName();
1594
0
    }
1595
0
    OS << '>';
1596
0
  }
1597
15
1598
15
  spaceBeforePlaceHolder(OS);
1599
15
}
1600
1601
void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T,
1602
15
                                          raw_ostream &OS) {}
1603
1604
void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T,
1605
5.84k
                                        raw_ostream &OS) {
1606
5.84k
  if (T->qual_empty() && 
T->isUnspecializedAsWritten()4.40k
&&
1607
5.84k
      
!T->isKindOfTypeAsWritten()3.72k
)
1608
3.67k
    return printBefore(T->getBaseType(), OS);
1609
2.17k
1610
2.17k
  if (T->isKindOfTypeAsWritten())
1611
68
    OS << "__kindof ";
1612
2.17k
1613
2.17k
  print(T->getBaseType(), OS, StringRef());
1614
2.17k
1615
2.17k
  if (T->isSpecializedAsWritten()) {
1616
687
    bool isFirst = true;
1617
687
    OS << '<';
1618
716
    for (auto typeArg : T->getTypeArgsAsWritten()) {
1619
716
      if (isFirst)
1620
687
        isFirst = false;
1621
29
      else
1622
29
        OS << ",";
1623
716
1624
716
      print(typeArg, OS, StringRef());
1625
716
    }
1626
687
    OS << '>';
1627
687
  }
1628
2.17k
1629
2.17k
  if (!T->qual_empty()) {
1630
1.44k
    bool isFirst = true;
1631
1.44k
    OS << '<';
1632
2.27k
    for (const auto *I : T->quals()) {
1633
2.27k
      if (isFirst)
1634
1.44k
        isFirst = false;
1635
835
      else
1636
835
        OS << ',';
1637
2.27k
      OS << I->getName();
1638
2.27k
    }
1639
1.44k
    OS << '>';
1640
1.44k
  }
1641
2.17k
1642
2.17k
  spaceBeforePlaceHolder(OS);
1643
2.17k
}
1644
1645
void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
1646
1.34k
                                        raw_ostream &OS) {
1647
1.34k
  if (T->qual_empty() && 
T->isUnspecializedAsWritten()1.31k
&&
1648
1.34k
      
!T->isKindOfTypeAsWritten()1.30k
)
1649
1.30k
    return printAfter(T->getBaseType(), OS);
1650
1.34k
}
1651
1652
void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
1653
21.6k
                                               raw_ostream &OS) {
1654
21.6k
  printBefore(T->getPointeeType(), OS);
1655
21.6k
1656
21.6k
  // If we need to print the pointer, print it now.
1657
21.6k
  if (!T->isObjCIdType() && 
!T->isObjCQualifiedIdType()19.6k
&&
1658
21.6k
      
!T->isObjCClassType()18.5k
&&
!T->isObjCQualifiedClassType()18.1k
) {
1659
18.0k
    if (HasEmptyPlaceHolder)
1660
16.9k
      OS << ' ';
1661
18.0k
    OS << '*';
1662
18.0k
  }
1663
21.6k
}
1664
1665
void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
1666
21.6k
                                              raw_ostream &OS) {}
1667
1668
static
1669
1.48M
const TemplateArgument &getArgument(const TemplateArgument &A) { return A; }
1670
1671
1.35k
static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) {
1672
1.35k
  return A.getArgument();
1673
1.35k
}
1674
1675
static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
1676
1.44M
                          llvm::raw_ostream &OS) {
1677
1.44M
  A.print(PP, OS);
1678
1.44M
}
1679
1680
static void printArgument(const TemplateArgumentLoc &A,
1681
1.35k
                          const PrintingPolicy &PP, llvm::raw_ostream &OS) {
1682
1.35k
  const TemplateArgument::ArgKind &Kind = A.getArgument().getKind();
1683
1.35k
  if (Kind == TemplateArgument::ArgKind::Type)
1684
1.01k
    return A.getTypeSourceInfo()->getType().print(OS, PP);
1685
343
  return A.getArgument().print(PP, OS);
1686
343
}
1687
1688
template<typename TA>
1689
static void printTo(raw_ostream &OS, ArrayRef<TA> Args,
1690
881k
                    const PrintingPolicy &Policy, bool SkipBrackets) {
1691
881k
  const char *Comma = Policy.MSVCFormatting ? 
","38
:
", "881k
;
1692
881k
  if (!SkipBrackets)
1693
843k
    OS << '<';
1694
881k
1695
881k
  bool NeedSpace = false;
1696
881k
  bool FirstArg = true;
1697
1.48M
  for (const auto &Arg : Args) {
1698
1.48M
    // Print the argument into a string.
1699
1.48M
    SmallString<128> Buf;
1700
1.48M
    llvm::raw_svector_ostream ArgOS(Buf);
1701
1.48M
    const TemplateArgument &Argument = getArgument(Arg);
1702
1.48M
    if (Argument.getKind() == TemplateArgument::Pack) {
1703
37.6k
      if (Argument.pack_size() && 
!FirstArg33.2k
)
1704
12.5k
        OS << Comma;
1705
37.6k
      printTo(ArgOS, Argument.getPackAsArray(), Policy, true);
1706
1.45M
    } else {
1707
1.45M
      if (!FirstArg)
1708
595k
        OS << Comma;
1709
1.45M
      // Tries to print the argument with location info if exists.
1710
1.45M
      printArgument(Arg, Policy, ArgOS);
1711
1.45M
    }
1712
1.48M
    StringRef ArgString = ArgOS.str();
1713
1.48M
1714
1.48M
    // If this is the first argument and its string representation
1715
1.48M
    // begins with the global scope specifier ('::foo'), add a space
1716
1.48M
    // to avoid printing the diagraph '<:'.
1717
1.48M
    if (FirstArg && 
!ArgString.empty()876k
&&
ArgString[0] == ':'875k
)
1718
0
      OS << ' ';
1719
1.48M
1720
1.48M
    OS << ArgString;
1721
1.48M
1722
1.48M
    NeedSpace = (!ArgString.empty() && 
ArgString.back() == '>'1.48M
);
1723
1.48M
    FirstArg = false;
1724
1.48M
  }
1725
881k
1726
881k
  // If the last character of our string is '>', add another space to
1727
881k
  // keep the two '>''s separate tokens. We don't *have* to do this in
1728
881k
  // C++0x, but it's still good hygiene.
1729
881k
  if (NeedSpace)
1730
255k
    OS << ' ';
1731
881k
1732
881k
  if (!SkipBrackets)
1733
843k
    OS << '>';
1734
881k
}
TypePrinter.cpp:void printTo<clang::TemplateArgumentLoc>(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgumentLoc>, clang::PrintingPolicy const&, bool)
Line
Count
Source
1690
861
                    const PrintingPolicy &Policy, bool SkipBrackets) {
1691
861
  const char *Comma = Policy.MSVCFormatting ? 
","0
: ", ";
1692
861
  if (!SkipBrackets)
1693
861
    OS << '<';
1694
861
1695
861
  bool NeedSpace = false;
1696
861
  bool FirstArg = true;
1697
1.35k
  for (const auto &Arg : Args) {
1698
1.35k
    // Print the argument into a string.
1699
1.35k
    SmallString<128> Buf;
1700
1.35k
    llvm::raw_svector_ostream ArgOS(Buf);
1701
1.35k
    const TemplateArgument &Argument = getArgument(Arg);
1702
1.35k
    if (Argument.getKind() == TemplateArgument::Pack) {
1703
0
      if (Argument.pack_size() && !FirstArg)
1704
0
        OS << Comma;
1705
0
      printTo(ArgOS, Argument.getPackAsArray(), Policy, true);
1706
1.35k
    } else {
1707
1.35k
      if (!FirstArg)
1708
499
        OS << Comma;
1709
1.35k
      // Tries to print the argument with location info if exists.
1710
1.35k
      printArgument(Arg, Policy, ArgOS);
1711
1.35k
    }
1712
1.35k
    StringRef ArgString = ArgOS.str();
1713
1.35k
1714
1.35k
    // If this is the first argument and its string representation
1715
1.35k
    // begins with the global scope specifier ('::foo'), add a space
1716
1.35k
    // to avoid printing the diagraph '<:'.
1717
1.35k
    if (FirstArg && 
!ArgString.empty()859
&&
ArgString[0] == ':'859
)
1718
0
      OS << ' ';
1719
1.35k
1720
1.35k
    OS << ArgString;
1721
1.35k
1722
1.35k
    NeedSpace = (!ArgString.empty() && ArgString.back() == '>');
1723
1.35k
    FirstArg = false;
1724
1.35k
  }
1725
861
1726
861
  // If the last character of our string is '>', add another space to
1727
861
  // keep the two '>''s separate tokens. We don't *have* to do this in
1728
861
  // C++0x, but it's still good hygiene.
1729
861
  if (NeedSpace)
1730
82
    OS << ' ';
1731
861
1732
861
  if (!SkipBrackets)
1733
861
    OS << '>';
1734
861
}
TypePrinter.cpp:void printTo<clang::TemplateArgument>(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, bool)
Line
Count
Source
1690
880k
                    const PrintingPolicy &Policy, bool SkipBrackets) {
1691
880k
  const char *Comma = Policy.MSVCFormatting ? 
","38
:
", "880k
;
1692
880k
  if (!SkipBrackets)
1693
843k
    OS << '<';
1694
880k
1695
880k
  bool NeedSpace = false;
1696
880k
  bool FirstArg = true;
1697
1.48M
  for (const auto &Arg : Args) {
1698
1.48M
    // Print the argument into a string.
1699
1.48M
    SmallString<128> Buf;
1700
1.48M
    llvm::raw_svector_ostream ArgOS(Buf);
1701
1.48M
    const TemplateArgument &Argument = getArgument(Arg);
1702
1.48M
    if (Argument.getKind() == TemplateArgument::Pack) {
1703
37.6k
      if (Argument.pack_size() && 
!FirstArg33.2k
)
1704
12.5k
        OS << Comma;
1705
37.6k
      printTo(ArgOS, Argument.getPackAsArray(), Policy, true);
1706
1.44M
    } else {
1707
1.44M
      if (!FirstArg)
1708
594k
        OS << Comma;
1709
1.44M
      // Tries to print the argument with location info if exists.
1710
1.44M
      printArgument(Arg, Policy, ArgOS);
1711
1.44M
    }
1712
1.48M
    StringRef ArgString = ArgOS.str();
1713
1.48M
1714
1.48M
    // If this is the first argument and its string representation
1715
1.48M
    // begins with the global scope specifier ('::foo'), add a space
1716
1.48M
    // to avoid printing the diagraph '<:'.
1717
1.48M
    if (FirstArg && 
!ArgString.empty()875k
&&
ArgString[0] == ':'874k
)
1718
0
      OS << ' ';
1719
1.48M
1720
1.48M
    OS << ArgString;
1721
1.48M
1722
1.48M
    NeedSpace = (!ArgString.empty() && 
ArgString.back() == '>'1.48M
);
1723
1.48M
    FirstArg = false;
1724
1.48M
  }
1725
880k
1726
880k
  // If the last character of our string is '>', add another space to
1727
880k
  // keep the two '>''s separate tokens. We don't *have* to do this in
1728
880k
  // C++0x, but it's still good hygiene.
1729
880k
  if (NeedSpace)
1730
255k
    OS << ' ';
1731
880k
1732
880k
  if (!SkipBrackets)
1733
843k
    OS << '>';
1734
880k
}
1735
1736
void clang::printTemplateArgumentList(raw_ostream &OS,
1737
                                      const TemplateArgumentListInfo &Args,
1738
0
                                      const PrintingPolicy &Policy) {
1739
0
  return printTo(OS, Args.arguments(), Policy, false);
1740
0
}
1741
1742
void clang::printTemplateArgumentList(raw_ostream &OS,
1743
                                      ArrayRef<TemplateArgument> Args,
1744
843k
                                      const PrintingPolicy &Policy) {
1745
843k
  printTo(OS, Args, Policy, false);
1746
843k
}
1747
1748
void clang::printTemplateArgumentList(raw_ostream &OS,
1749
                                      ArrayRef<TemplateArgumentLoc> Args,
1750
861
                                      const PrintingPolicy &Policy) {
1751
861
  printTo(OS, Args, Policy, false);
1752
861
}
1753
1754
1.90k
std::string Qualifiers::getAsString() const {
1755
1.90k
  LangOptions LO;
1756
1.90k
  return getAsString(PrintingPolicy(LO));
1757
1.90k
}
1758
1759
// Appends qualifiers to the given string, separated by spaces.  Will
1760
// prefix a space if the string is non-empty.  Will not append a final
1761
// space.
1762
1.90k
std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
1763
1.90k
  SmallString<64> Buf;
1764
1.90k
  llvm::raw_svector_ostream StrOS(Buf);
1765
1.90k
  print(StrOS, Policy);
1766
1.90k
  return std::string(StrOS.str());
1767
1.90k
}
1768
1769
13.0k
bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
1770
13.0k
  if (getCVRQualifiers())
1771
10.6k
    return false;
1772
2.44k
1773
2.44k
  if (getAddressSpace() != LangAS::Default)
1774
1.97k
    return false;
1775
468
1776
468
  if (getObjCGCAttr())
1777
45
    return false;
1778
423
1779
423
  if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
1780
420
    if (!(lifetime == Qualifiers::OCL_Strong && 
Policy.SuppressStrongLifetime306
))
1781
389
      return false;
1782
34
1783
34
  return true;
1784
34
}
1785
1786
89.8k
std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
1787
89.8k
  switch (AS) {
1788
82.9k
  case LangAS::Default:
1789
82.9k
    return "";
1790
1.12k
  case LangAS::opencl_global:
1791
1.12k
    return "__global";
1792
721
  case LangAS::opencl_local:
1793
721
    return "__local";
1794
3.15k
  case LangAS::opencl_private:
1795
3.15k
    return "__private";
1796
742
  case LangAS::opencl_constant:
1797
742
    return "__constant";
1798
751
  case LangAS::opencl_generic:
1799
751
    return "__generic";
1800
0
  case LangAS::cuda_device:
1801
0
    return "__device__";
1802
0
  case LangAS::cuda_constant:
1803
0
    return "__constant__";
1804
0
  case LangAS::cuda_shared:
1805
0
    return "__shared__";
1806
0
  case LangAS::ptr32_sptr:
1807
0
    return "__sptr __ptr32";
1808
0
  case LangAS::ptr32_uptr:
1809
0
    return "__uptr __ptr32";
1810
0
  case LangAS::ptr64:
1811
0
    return "__ptr64";
1812
424
  default:
1813
424
    return std::to_string(toTargetAddressSpace(AS));
1814
89.8k
  }
1815
89.8k
}
1816
1817
// Appends qualifiers to the given string, separated by spaces.  Will
1818
// prefix a space if the string is non-empty.  Will not append a final
1819
// space.
1820
void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
1821
89.8k
                       bool appendSpaceIfNonEmpty) const {
1822
89.8k
  bool addSpace = false;
1823
89.8k
1824
89.8k
  unsigned quals = getCVRQualifiers();
1825
89.8k
  if (quals) {
1826
81.1k
    AppendTypeQualList(OS, quals, Policy.Restrict);
1827
81.1k
    addSpace = true;
1828
81.1k
  }
1829
89.8k
  if (hasUnaligned()) {
1830
81
    if (addSpace)
1831
0
      OS << ' ';
1832
81
    OS << "__unaligned";
1833
81
    addSpace = true;
1834
81
  }
1835
89.8k
  auto ASStr = getAddrSpaceAsString(getAddressSpace());
1836
89.8k
  if (!ASStr.empty()) {
1837
6.86k
    if (addSpace)
1838
249
      OS << ' ';
1839
6.86k
    addSpace = true;
1840
6.86k
    // Wrap target address space into an attribute syntax
1841
6.86k
    if (isTargetAddressSpace(getAddressSpace()))
1842
418
      OS << "__attribute__((address_space(" << ASStr << ")))";
1843
6.45k
    else
1844
6.45k
      OS << ASStr;
1845
6.86k
  }
1846
89.8k
1847
89.8k
  if (Qualifiers::GC gc = getObjCGCAttr()) {
1848
69
    if (addSpace)
1849
0
      OS << ' ';
1850
69
    addSpace = true;
1851
69
    if (gc == Qualifiers::Weak)
1852
28
      OS << "__weak";
1853
41
    else
1854
41
      OS << "__strong";
1855
69
  }
1856
89.8k
  if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
1857
1.73k
    if (!(lifetime == Qualifiers::OCL_Strong && 
Policy.SuppressStrongLifetime1.00k
)){
1858
1.69k
      if (addSpace)
1859
91
        OS << ' ';
1860
1.69k
      addSpace = true;
1861
1.69k
    }
1862
1.73k
1863
1.73k
    switch (lifetime) {
1864
0
    case Qualifiers::OCL_None: llvm_unreachable("none but true");
1865
68
    case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
1866
1.00k
    case Qualifiers::OCL_Strong:
1867
1.00k
      if (!Policy.SuppressStrongLifetime)
1868
968
        OS << "__strong";
1869
1.00k
      break;
1870
0
1871
506
    case Qualifiers::OCL_Weak: OS << "__weak"; break;
1872
150
    case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
1873
89.8k
    }
1874
89.8k
  }
1875
89.8k
1876
89.8k
  if (appendSpaceIfNonEmpty && 
addSpace78.4k
)
1877
78.4k
    OS << ' ';
1878
89.8k
}
1879
1880
34.5k
std::string QualType::getAsString() const {
1881
34.5k
  return getAsString(split(), LangOptions());
1882
34.5k
}
1883
1884
536k
std::string QualType::getAsString(const PrintingPolicy &Policy) const {
1885
536k
  std::string S;
1886
536k
  getAsStringInternal(S, Policy);
1887
536k
  return S;
1888
536k
}
1889
1890
std::string QualType::getAsString(const Type *ty, Qualifiers qs,
1891
70.5k
                                  const PrintingPolicy &Policy) {
1892
70.5k
  std::string buffer;
1893
70.5k
  getAsStringInternal(ty, qs, buffer, Policy);
1894
70.5k
  return buffer;
1895
70.5k
}
1896
1897
void QualType::print(raw_ostream &OS, const PrintingPolicy &Policy,
1898
1.29M
                     const Twine &PlaceHolder, unsigned Indentation) const {
1899
1.29M
  print(splitAccordingToPolicy(*this, Policy), OS, Policy, PlaceHolder,
1900
1.29M
        Indentation);
1901
1.29M
}
1902
1903
void QualType::print(const Type *ty, Qualifiers qs,
1904
                     raw_ostream &OS, const PrintingPolicy &policy,
1905
1.29M
                     const Twine &PlaceHolder, unsigned Indentation) {
1906
1.29M
  SmallString<128> PHBuf;
1907
1.29M
  StringRef PH = PlaceHolder.toStringRef(PHBuf);
1908
1.29M
1909
1.29M
  TypePrinter(policy, Indentation).print(ty, qs, OS, PH);
1910
1.29M
}
1911
1912
void QualType::getAsStringInternal(std::string &Str,
1913
543k
                                   const PrintingPolicy &Policy) const {
1914
543k
  return getAsStringInternal(splitAccordingToPolicy(*this, Policy), Str,
1915
543k
                             Policy);
1916
543k
}
1917
1918
void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
1919
                                   std::string &buffer,
1920
614k
                                   const PrintingPolicy &policy) {
1921
614k
  SmallString<256> Buf;
1922
614k
  llvm::raw_svector_ostream StrOS(Buf);
1923
614k
  TypePrinter(policy).print(ty, qs, StrOS, buffer);
1924
614k
  std::string str = std::string(StrOS.str());
1925
614k
  buffer.swap(str);
1926
614k
}