Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/TemplateBase.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- TemplateBase.cpp - Common template AST class implementation --------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements common classes used throughout C++ template
10
// representations.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/TemplateBase.h"
15
#include "clang/AST/ASTContext.h"
16
#include "clang/AST/Decl.h"
17
#include "clang/AST/DeclBase.h"
18
#include "clang/AST/DeclTemplate.h"
19
#include "clang/AST/DependenceFlags.h"
20
#include "clang/AST/Expr.h"
21
#include "clang/AST/ExprCXX.h"
22
#include "clang/AST/PrettyPrinter.h"
23
#include "clang/AST/TemplateName.h"
24
#include "clang/AST/Type.h"
25
#include "clang/AST/TypeLoc.h"
26
#include "clang/Basic/Diagnostic.h"
27
#include "clang/Basic/LLVM.h"
28
#include "clang/Basic/LangOptions.h"
29
#include "clang/Basic/SourceLocation.h"
30
#include "llvm/ADT/APSInt.h"
31
#include "llvm/ADT/FoldingSet.h"
32
#include "llvm/ADT/None.h"
33
#include "llvm/ADT/SmallString.h"
34
#include "llvm/ADT/StringExtras.h"
35
#include "llvm/ADT/StringRef.h"
36
#include "llvm/Support/Casting.h"
37
#include "llvm/Support/Compiler.h"
38
#include "llvm/Support/ErrorHandling.h"
39
#include "llvm/Support/raw_ostream.h"
40
#include <cassert>
41
#include <cstddef>
42
#include <cstdint>
43
#include <cstring>
44
45
using namespace clang;
46
47
/// Print a template integral argument value.
48
///
49
/// \param TemplArg the TemplateArgument instance to print.
50
///
51
/// \param Out the raw_ostream instance to use for printing.
52
///
53
/// \param Policy the printing policy for EnumConstantDecl printing.
54
///
55
/// \param IncludeType If set, ensure that the type of the expression printed
56
/// matches the type of the template argument.
57
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
58
199k
                          const PrintingPolicy &Policy, bool IncludeType) {
59
199k
  const Type *T = TemplArg.getIntegralType().getTypePtr();
60
199k
  const llvm::APSInt &Val = TemplArg.getAsIntegral();
61
62
199k
  if (const EnumType *ET = T->getAs<EnumType>()) {
63
1.26k
    for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
64
      // In Sema::CheckTemplateArugment, enum template arguments value are
65
      // extended to the size of the integer underlying the enum type.  This
66
      // may create a size difference between the enum value and template
67
      // argument value, requiring isSameValue here instead of operator==.
68
1.26k
      if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
69
1.23k
        ECD->printQualifiedName(Out, Policy);
70
1.23k
        return;
71
1.23k
      }
72
1.26k
    }
73
1.23k
  }
74
75
198k
  if (Policy.MSVCFormatting)
76
16
    IncludeType = false;
77
78
198k
  if (T->isBooleanType()) {
79
85.8k
    if (!Policy.MSVCFormatting)
80
85.8k
      Out << (Val.getBoolValue() ? 
"true"35.1k
:
"false"50.7k
);
81
0
    else
82
0
      Out << Val;
83
112k
  } else if (T->isCharType()) {
84
115
    if (IncludeType) {
85
43
      if (T->isSpecificBuiltinType(BuiltinType::SChar))
86
4
        Out << "(signed char)";
87
39
      else if (T->isSpecificBuiltinType(BuiltinType::UChar))
88
4
        Out << "(unsigned char)";
89
43
    }
90
115
    CharacterLiteral::print(Val.getZExtValue(), CharacterLiteral::Ascii, Out);
91
112k
  } else if (T->isAnyCharacterType() && 
!Policy.MSVCFormatting104
) {
92
90
    CharacterLiteral::CharacterKind Kind;
93
90
    if (T->isWideCharType())
94
21
      Kind = CharacterLiteral::Wide;
95
69
    else if (T->isChar8Type())
96
46
      Kind = CharacterLiteral::UTF8;
97
23
    else if (T->isChar16Type())
98
0
      Kind = CharacterLiteral::UTF16;
99
23
    else if (T->isChar32Type())
100
23
      Kind = CharacterLiteral::UTF32;
101
0
    else
102
0
      Kind = CharacterLiteral::Ascii;
103
90
    CharacterLiteral::print(Val.getExtValue(), Kind, Out);
104
112k
  } else if (IncludeType) {
105
7.80k
    if (const auto *BT = T->getAs<BuiltinType>()) {
106
7.80k
      switch (BT->getKind()) {
107
4
      case BuiltinType::ULongLong:
108
4
        Out << Val << "ULL";
109
4
        break;
110
0
      case BuiltinType::LongLong:
111
0
        Out << Val << "LL";
112
0
        break;
113
3.37k
      case BuiltinType::ULong:
114
3.37k
        Out << Val << "UL";
115
3.37k
        break;
116
31
      case BuiltinType::Long:
117
31
        Out << Val << "L";
118
31
        break;
119
154
      case BuiltinType::UInt:
120
154
        Out << Val << "U";
121
154
        break;
122
4.23k
      case BuiltinType::Int:
123
4.23k
        Out << Val;
124
4.23k
        break;
125
4
      default:
126
4
        Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
127
4
            << Val;
128
4
        break;
129
7.80k
      }
130
7.80k
    } else
131
1
      Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
132
1
          << Val;
133
7.80k
  } else
134
104k
    Out << Val;
135
198k
}
136
137
168
static unsigned getArrayDepth(QualType type) {
138
168
  unsigned count = 0;
139
273
  while (const auto *arrayType = type->getAsArrayTypeUnsafe()) {
140
105
    count++;
141
105
    type = arrayType->getElementType();
142
105
  }
143
168
  return count;
144
168
}
145
146
1.79k
static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType) {
147
  // Generally, if the parameter type is a pointer, we must be taking the
148
  // address of something and need a &.  However, if the argument is an array,
149
  // this could be implicit via array-to-pointer decay.
150
1.79k
  if (!paramType->isPointerType())
151
373
    return paramType->isMemberPointerType();
152
1.42k
  if (argType->isArrayType())
153
84
    return getArrayDepth(argType) == getArrayDepth(paramType->getPointeeType());
154
1.34k
  return true;
155
1.42k
}
156
157
//===----------------------------------------------------------------------===//
158
// TemplateArgument Implementation
159
//===----------------------------------------------------------------------===//
160
161
TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
162
2.17M
                                   QualType Type) {
163
2.17M
  Integer.Kind = Integral;
164
  // Copy the APSInt value into our decomposed form.
165
2.17M
  Integer.BitWidth = Value.getBitWidth();
166
2.17M
  Integer.IsUnsigned = Value.isUnsigned();
167
  // If the value is large, we have to get additional memory from the ASTContext
168
2.17M
  unsigned NumWords = Value.getNumWords();
169
2.17M
  if (NumWords > 1) {
170
22
    void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
171
22
    std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
172
22
    Integer.pVal = static_cast<uint64_t *>(Mem);
173
2.17M
  } else {
174
2.17M
    Integer.VAL = Value.getZExtValue();
175
2.17M
  }
176
177
2.17M
  Integer.Type = Type.getAsOpaquePtr();
178
2.17M
}
179
180
TemplateArgument
181
TemplateArgument::CreatePackCopy(ASTContext &Context,
182
644k
                                 ArrayRef<TemplateArgument> Args) {
183
644k
  if (Args.empty())
184
27.8k
    return getEmptyPack();
185
186
616k
  return TemplateArgument(Args.copy(Context));
187
644k
}
188
189
31.4M
TemplateArgumentDependence TemplateArgument::getDependence() const {
190
31.4M
  auto Deps = TemplateArgumentDependence::None;
191
31.4M
  switch (getKind()) {
192
0
  case Null:
193
0
    llvm_unreachable("Should not have a NULL template argument");
194
195
24.4M
  case Type:
196
24.4M
    Deps = toTemplateArgumentDependence(getAsType()->getDependence());
197
24.4M
    if (isa<PackExpansionType>(getAsType()))
198
605k
      Deps |= TemplateArgumentDependence::Dependent;
199
24.4M
    return Deps;
200
201
117k
  case Template:
202
117k
    return toTemplateArgumentDependence(getAsTemplate().getDependence());
203
204
216
  case TemplateExpansion:
205
216
    return TemplateArgumentDependence::Dependent |
206
216
           TemplateArgumentDependence::Instantiation;
207
208
3.84k
  case Declaration: {
209
3.84k
    auto *DC = dyn_cast<DeclContext>(getAsDecl());
210
3.84k
    if (!DC)
211
2.41k
      DC = getAsDecl()->getDeclContext();
212
3.84k
    if (DC->isDependentContext())
213
10
      Deps = TemplateArgumentDependence::Dependent |
214
10
             TemplateArgumentDependence::Instantiation;
215
3.84k
    return Deps;
216
0
  }
217
218
1.69k
  case NullPtr:
219
1.58M
  case Integral:
220
1.58M
    return TemplateArgumentDependence::None;
221
222
4.67M
  case Expression:
223
4.67M
    Deps = toTemplateArgumentDependence(getAsExpr()->getDependence());
224
4.67M
    if (isa<PackExpansionExpr>(getAsExpr()))
225
116k
      Deps |= TemplateArgumentDependence::Dependent |
226
116k
              TemplateArgumentDependence::Instantiation;
227
4.67M
    return Deps;
228
229
563k
  case Pack:
230
563k
    for (const auto &P : pack_elements())
231
925k
      Deps |= P.getDependence();
232
563k
    return Deps;
233
31.4M
  }
234
0
  llvm_unreachable("unhandled ArgKind");
235
0
}
236
237
7.35M
bool TemplateArgument::isDependent() const {
238
7.35M
  return getDependence() & TemplateArgumentDependence::Dependent;
239
7.35M
}
240
241
2.89M
bool TemplateArgument::isInstantiationDependent() const {
242
2.89M
  return getDependence() & TemplateArgumentDependence::Instantiation;
243
2.89M
}
244
245
31.7M
bool TemplateArgument::isPackExpansion() const {
246
31.7M
  switch (getKind()) {
247
0
  case Null:
248
2.79k
  case Declaration:
249
1.96M
  case Integral:
250
2.02M
  case Pack:
251
2.10M
  case Template:
252
2.10M
  case NullPtr:
253
2.10M
    return false;
254
255
189
  case TemplateExpansion:
256
189
    return true;
257
258
24.5M
  case Type:
259
24.5M
    return isa<PackExpansionType>(getAsType());
260
261
5.16M
  case Expression:
262
5.16M
    return isa<PackExpansionExpr>(getAsExpr());
263
31.7M
  }
264
265
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
266
0
}
267
268
930k
bool TemplateArgument::containsUnexpandedParameterPack() const {
269
930k
  return getDependence() & TemplateArgumentDependence::UnexpandedPack;
270
930k
}
271
272
147
Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
273
147
  assert(getKind() == TemplateExpansion);
274
147
  if (TemplateArg.NumExpansions)
275
3
    return TemplateArg.NumExpansions - 1;
276
277
144
  return None;
278
147
}
279
280
90.5k
QualType TemplateArgument::getNonTypeTemplateArgumentType() const {
281
90.5k
  switch (getKind()) {
282
0
  case TemplateArgument::Null:
283
88.3k
  case TemplateArgument::Type:
284
88.3k
  case TemplateArgument::Template:
285
88.3k
  case TemplateArgument::TemplateExpansion:
286
88.5k
  case TemplateArgument::Pack:
287
88.5k
    return QualType();
288
289
232
  case TemplateArgument::Integral:
290
232
    return getIntegralType();
291
292
1.77k
  case TemplateArgument::Expression:
293
1.77k
    return getAsExpr()->getType();
294
295
26
  case TemplateArgument::Declaration:
296
26
    return getParamTypeForDecl();
297
298
0
  case TemplateArgument::NullPtr:
299
0
    return getNullPtrType();
300
90.5k
  }
301
302
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
303
0
}
304
305
void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
306
37.0M
                               const ASTContext &Context) const {
307
37.0M
  ID.AddInteger(getKind());
308
37.0M
  switch (getKind()) {
309
0
  case Null:
310
0
    break;
311
312
27.8M
  case Type:
313
27.8M
    getAsType().Profile(ID);
314
27.8M
    break;
315
316
11.1k
  case NullPtr:
317
11.1k
    getNullPtrType().Profile(ID);
318
11.1k
    break;
319
320
10.0k
  case Declaration:
321
10.0k
    getParamTypeForDecl().Profile(ID);
322
10.0k
    ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : 
nullptr0
);
323
10.0k
    break;
324
325
93.7k
  case Template:
326
93.9k
  case TemplateExpansion: {
327
93.9k
    TemplateName Template = getAsTemplateOrTemplatePattern();
328
93.9k
    if (TemplateTemplateParmDecl *TTP
329
93.9k
          = dyn_cast_or_null<TemplateTemplateParmDecl>(
330
93.9k
                                                Template.getAsTemplateDecl())) {
331
14.8k
      ID.AddBoolean(true);
332
14.8k
      ID.AddInteger(TTP->getDepth());
333
14.8k
      ID.AddInteger(TTP->getPosition());
334
14.8k
      ID.AddBoolean(TTP->isParameterPack());
335
79.0k
    } else {
336
79.0k
      ID.AddBoolean(false);
337
79.0k
      ID.AddPointer(Context.getCanonicalTemplateName(Template)
338
79.0k
                                                          .getAsVoidPointer());
339
79.0k
    }
340
93.9k
    break;
341
93.7k
  }
342
343
3.48M
  case Integral:
344
3.48M
    getAsIntegral().Profile(ID);
345
3.48M
    getIntegralType().Profile(ID);
346
3.48M
    break;
347
348
4.18M
  case Expression:
349
4.18M
    getAsExpr()->Profile(ID, Context, true);
350
4.18M
    break;
351
352
1.41M
  case Pack:
353
1.41M
    ID.AddInteger(Args.NumArgs);
354
3.61M
    for (unsigned I = 0; I != Args.NumArgs; 
++I2.19M
)
355
2.19M
      Args.Args[I].Profile(ID, Context);
356
37.0M
  }
357
37.0M
}
358
359
84.8k
bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const {
360
84.8k
  if (getKind() != Other.getKind()) 
return false665
;
361
362
84.2k
  switch (getKind()) {
363
0
  case Null:
364
79.0k
  case Type:
365
80.9k
  case Expression:
366
80.9k
  case NullPtr:
367
80.9k
    return TypeOrValue.V == Other.TypeOrValue.V;
368
369
3.22k
  case Template:
370
3.23k
  case TemplateExpansion:
371
3.23k
    return TemplateArg.Name == Other.TemplateArg.Name &&
372
3.23k
           
TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions3.04k
;
373
374
0
  case Declaration:
375
0
    return getAsDecl() == Other.getAsDecl();
376
377
1
  case Integral:
378
1
    return getIntegralType() == Other.getIntegralType() &&
379
1
           getAsIntegral() == Other.getAsIntegral();
380
381
0
  case Pack:
382
0
    if (Args.NumArgs != Other.Args.NumArgs) return false;
383
0
    for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
384
0
      if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
385
0
        return false;
386
0
    return true;
387
84.2k
  }
388
389
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
390
0
}
391
392
103k
TemplateArgument TemplateArgument::getPackExpansionPattern() const {
393
103k
  assert(isPackExpansion());
394
395
0
  switch (getKind()) {
396
90.4k
  case Type:
397
90.4k
    return getAsType()->castAs<PackExpansionType>()->getPattern();
398
399
12.9k
  case Expression:
400
12.9k
    return cast<PackExpansionExpr>(getAsExpr())->getPattern();
401
402
54
  case TemplateExpansion:
403
54
    return TemplateArgument(getAsTemplateOrTemplatePattern());
404
405
0
  case Declaration:
406
0
  case Integral:
407
0
  case Pack:
408
0
  case Null:
409
0
  case Template:
410
0
  case NullPtr:
411
0
    return TemplateArgument();
412
103k
  }
413
414
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
415
0
}
416
417
void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
418
1.59M
                             bool IncludeType) const {
419
420
1.59M
  switch (getKind()) {
421
95
  case Null:
422
95
    Out << "(no value)";
423
95
    break;
424
425
1.36M
  case Type: {
426
1.36M
    PrintingPolicy SubPolicy(Policy);
427
1.36M
    SubPolicy.SuppressStrongLifetime = true;
428
1.36M
    getAsType().print(Out, SubPolicy);
429
1.36M
    break;
430
0
  }
431
432
1.81k
  case Declaration: {
433
    // FIXME: Include the type if it's not obvious from the context.
434
1.81k
    NamedDecl *ND = getAsDecl();
435
1.81k
    if (getParamTypeForDecl()->isRecordType()) {
436
19
      if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
437
19
        TPO->printAsInit(Out);
438
19
        break;
439
19
      }
440
19
    }
441
1.79k
    if (auto *VD = dyn_cast<ValueDecl>(ND)) {
442
1.79k
      if (needsAmpersandOnTemplateArg(getParamTypeForDecl(), VD->getType()))
443
1.36k
        Out << "&";
444
1.79k
    }
445
1.79k
    ND->printQualifiedName(Out);
446
1.79k
    break;
447
1.81k
  }
448
449
1.26k
  case NullPtr:
450
    // FIXME: Include the type if it's not obvious from the context.
451
1.26k
    Out << "nullptr";
452
1.26k
    break;
453
454
1.77k
  case Template:
455
1.77k
    getAsTemplate().print(Out, Policy, TemplateName::Qualified::Fully);
456
1.77k
    break;
457
458
2
  case TemplateExpansion:
459
2
    getAsTemplateOrTemplatePattern().print(Out, Policy);
460
2
    Out << "...";
461
2
    break;
462
463
199k
  case Integral:
464
199k
    printIntegral(*this, Out, Policy, IncludeType);
465
199k
    break;
466
467
19.7k
  case Expression:
468
19.7k
    getAsExpr()->printPretty(Out, nullptr, Policy);
469
19.7k
    break;
470
471
1.26k
  case Pack:
472
1.26k
    Out << "<";
473
1.26k
    bool First = true;
474
2.43k
    for (const auto &P : pack_elements()) {
475
2.43k
      if (First)
476
1.20k
        First = false;
477
1.22k
      else
478
1.22k
        Out << ", ";
479
480
2.43k
      P.print(Policy, Out, IncludeType);
481
2.43k
    }
482
1.26k
    Out << ">";
483
1.26k
    break;
484
1.59M
  }
485
1.59M
}
486
487
0
void TemplateArgument::dump(raw_ostream &Out) const {
488
0
  LangOptions LO; // FIXME! see also TemplateName::dump().
489
0
  LO.CPlusPlus = true;
490
0
  LO.Bool = true;
491
0
  print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
492
0
}
493
494
0
LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
495
496
//===----------------------------------------------------------------------===//
497
// TemplateArgumentLoc Implementation
498
//===----------------------------------------------------------------------===//
499
500
336k
SourceRange TemplateArgumentLoc::getSourceRange() const {
501
336k
  switch (Argument.getKind()) {
502
121k
  case TemplateArgument::Expression:
503
121k
    return getSourceExpression()->getSourceRange();
504
505
0
  case TemplateArgument::Declaration:
506
0
    return getSourceDeclExpression()->getSourceRange();
507
508
0
  case TemplateArgument::NullPtr:
509
0
    return getSourceNullPtrExpression()->getSourceRange();
510
511
206k
  case TemplateArgument::Type:
512
206k
    if (TypeSourceInfo *TSI = getTypeSourceInfo())
513
206k
      return TSI->getTypeLoc().getSourceRange();
514
0
    else
515
0
      return SourceRange();
516
517
8.72k
  case TemplateArgument::Template:
518
8.72k
    if (getTemplateQualifierLoc())
519
43
      return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
520
43
                         getTemplateNameLoc());
521
8.68k
    return SourceRange(getTemplateNameLoc());
522
523
2
  case TemplateArgument::TemplateExpansion:
524
2
    if (getTemplateQualifierLoc())
525
1
      return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
526
1
                         getTemplateEllipsisLoc());
527
1
    return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc());
528
529
0
  case TemplateArgument::Integral:
530
0
    return getSourceIntegralExpression()->getSourceRange();
531
532
0
  case TemplateArgument::Pack:
533
0
  case TemplateArgument::Null:
534
0
    return SourceRange();
535
336k
  }
536
537
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
538
0
}
539
540
template <typename T>
541
1.12k
static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
542
1.12k
  switch (Arg.getKind()) {
543
0
  case TemplateArgument::Null:
544
    // This is bad, but not as bad as crashing because of argument
545
    // count mismatches.
546
0
    return DB << "(null template argument)";
547
548
506
  case TemplateArgument::Type:
549
506
    return DB << Arg.getAsType();
550
551
8
  case TemplateArgument::Declaration:
552
8
    return DB << Arg.getAsDecl();
553
554
0
  case TemplateArgument::NullPtr:
555
0
    return DB << "nullptr";
556
557
44
  case TemplateArgument::Integral:
558
44
    return DB << toString(Arg.getAsIntegral(), 10);
559
560
20
  case TemplateArgument::Template:
561
20
    return DB << Arg.getAsTemplate();
562
563
0
  case TemplateArgument::TemplateExpansion:
564
0
    return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
565
566
425
  case TemplateArgument::Expression: {
567
    // This shouldn't actually ever happen, so it's okay that we're
568
    // regurgitating an expression here.
569
    // FIXME: We're guessing at LangOptions!
570
425
    SmallString<32> Str;
571
425
    llvm::raw_svector_ostream OS(Str);
572
425
    LangOptions LangOpts;
573
425
    LangOpts.CPlusPlus = true;
574
425
    PrintingPolicy Policy(LangOpts);
575
425
    Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
576
425
    return DB << OS.str();
577
0
  }
578
579
126
  case TemplateArgument::Pack: {
580
    // FIXME: We're guessing at LangOptions!
581
126
    SmallString<32> Str;
582
126
    llvm::raw_svector_ostream OS(Str);
583
126
    LangOptions LangOpts;
584
126
    LangOpts.CPlusPlus = true;
585
126
    PrintingPolicy Policy(LangOpts);
586
126
    Arg.print(Policy, OS, /*IncludeType*/ true);
587
126
    return DB << OS.str();
588
0
  }
589
1.12k
  }
590
591
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
592
0
}
593
594
const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
595
1.12k
                                             const TemplateArgument &Arg) {
596
1.12k
  return DiagTemplateArg(DB, Arg);
597
1.12k
}
598
599
clang::TemplateArgumentLocInfo::TemplateArgumentLocInfo(
600
    ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
601
79.0k
    SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
602
79.0k
  TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
603
79.0k
  Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
604
79.0k
  Template->QualifierLocData = QualifierLoc.getOpaqueData();
605
79.0k
  Template->TemplateNameLoc = TemplateNameLoc;
606
79.0k
  Template->EllipsisLoc = EllipsisLoc;
607
79.0k
  Pointer = Template;
608
79.0k
}
609
610
const ASTTemplateArgumentListInfo *
611
ASTTemplateArgumentListInfo::Create(const ASTContext &C,
612
197k
                                    const TemplateArgumentListInfo &List) {
613
197k
  std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
614
197k
  void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
615
197k
  return new (Mem) ASTTemplateArgumentListInfo(List);
616
197k
}
617
618
ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
619
197k
    const TemplateArgumentListInfo &Info) {
620
197k
  LAngleLoc = Info.getLAngleLoc();
621
197k
  RAngleLoc = Info.getRAngleLoc();
622
197k
  NumTemplateArgs = Info.size();
623
624
197k
  TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
625
617k
  for (unsigned i = 0; i != NumTemplateArgs; 
++i419k
)
626
419k
    new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
627
197k
}
628
629
void ASTTemplateKWAndArgsInfo::initializeFrom(
630
    SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
631
47.9k
    TemplateArgumentLoc *OutArgArray) {
632
47.9k
  this->TemplateKWLoc = TemplateKWLoc;
633
47.9k
  LAngleLoc = Info.getLAngleLoc();
634
47.9k
  RAngleLoc = Info.getRAngleLoc();
635
47.9k
  NumTemplateArgs = Info.size();
636
637
117k
  for (unsigned i = 0; i != NumTemplateArgs; 
++i69.8k
)
638
69.8k
    new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
639
47.9k
}
640
641
243
void ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc) {
642
243
  assert(TemplateKWLoc.isValid());
643
0
  LAngleLoc = SourceLocation();
644
243
  RAngleLoc = SourceLocation();
645
243
  this->TemplateKWLoc = TemplateKWLoc;
646
243
  NumTemplateArgs = 0;
647
243
}
648
649
void ASTTemplateKWAndArgsInfo::initializeFrom(
650
    SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
651
582k
    TemplateArgumentLoc *OutArgArray, TemplateArgumentDependence &Deps) {
652
582k
  this->TemplateKWLoc = TemplateKWLoc;
653
582k
  LAngleLoc = Info.getLAngleLoc();
654
582k
  RAngleLoc = Info.getRAngleLoc();
655
582k
  NumTemplateArgs = Info.size();
656
657
1.36M
  for (unsigned i = 0; i != NumTemplateArgs; 
++i783k
) {
658
783k
    Deps |= Info[i].getArgument().getDependence();
659
660
783k
    new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
661
783k
  }
662
582k
}
663
664
void ASTTemplateKWAndArgsInfo::copyInto(const TemplateArgumentLoc *ArgArray,
665
290k
                                        TemplateArgumentListInfo &Info) const {
666
290k
  Info.setLAngleLoc(LAngleLoc);
667
290k
  Info.setRAngleLoc(RAngleLoc);
668
643k
  for (unsigned I = 0; I != NumTemplateArgs; 
++I353k
)
669
353k
    Info.addArgument(ArgArray[I]);
670
290k
}