Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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/Expr.h"
20
#include "clang/AST/ExprCXX.h"
21
#include "clang/AST/PrettyPrinter.h"
22
#include "clang/AST/TemplateName.h"
23
#include "clang/AST/Type.h"
24
#include "clang/AST/TypeLoc.h"
25
#include "clang/Basic/Diagnostic.h"
26
#include "clang/Basic/LLVM.h"
27
#include "clang/Basic/LangOptions.h"
28
#include "clang/Basic/SourceLocation.h"
29
#include "llvm/ADT/APSInt.h"
30
#include "llvm/ADT/FoldingSet.h"
31
#include "llvm/ADT/None.h"
32
#include "llvm/ADT/SmallString.h"
33
#include "llvm/ADT/StringRef.h"
34
#include "llvm/Support/Casting.h"
35
#include "llvm/Support/Compiler.h"
36
#include "llvm/Support/ErrorHandling.h"
37
#include "llvm/Support/raw_ostream.h"
38
#include <cassert>
39
#include <cstddef>
40
#include <cstdint>
41
#include <cstring>
42
43
using namespace clang;
44
45
/// Print a template integral argument value.
46
///
47
/// \param TemplArg the TemplateArgument instance to print.
48
///
49
/// \param Out the raw_ostream instance to use for printing.
50
///
51
/// \param Policy the printing policy for EnumConstantDecl printing.
52
static void printIntegral(const TemplateArgument &TemplArg,
53
109k
                          raw_ostream &Out, const PrintingPolicy& Policy) {
54
109k
  const Type *T = TemplArg.getIntegralType().getTypePtr();
55
109k
  const llvm::APSInt &Val = TemplArg.getAsIntegral();
56
109k
57
109k
  if (const EnumType *ET = T->getAs<EnumType>()) {
58
144
    for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
59
144
      // In Sema::CheckTemplateArugment, enum template arguments value are
60
144
      // extended to the size of the integer underlying the enum type.  This
61
144
      // may create a size difference between the enum value and template
62
144
      // argument value, requiring isSameValue here instead of operator==.
63
144
      if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
64
55
        ECD->printQualifiedName(Out, Policy);
65
55
        return;
66
55
      }
67
144
    }
68
56
  }
69
109k
70
109k
  
if (108k
T->isBooleanType()108k
&&
!Policy.MSVCFormatting57.8k
) {
71
57.8k
    Out << (Val.getBoolValue() ? 
"true"15.0k
:
"false"42.7k
);
72
57.8k
  } else 
if (51.1k
T->isCharType()51.1k
) {
73
94
    const char Ch = Val.getZExtValue();
74
94
    Out << ((Ch == '\'') ? 
"'\\"6
:
"'"88
);
75
94
    Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true);
76
94
    Out << "'";
77
51.0k
  } else {
78
51.0k
    Out << Val;
79
51.0k
  }
80
108k
}
81
82
//===----------------------------------------------------------------------===//
83
// TemplateArgument Implementation
84
//===----------------------------------------------------------------------===//
85
86
TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
87
1.95M
                                   QualType Type) {
88
1.95M
  Integer.Kind = Integral;
89
1.95M
  // Copy the APSInt value into our decomposed form.
90
1.95M
  Integer.BitWidth = Value.getBitWidth();
91
1.95M
  Integer.IsUnsigned = Value.isUnsigned();
92
1.95M
  // If the value is large, we have to get additional memory from the ASTContext
93
1.95M
  unsigned NumWords = Value.getNumWords();
94
1.95M
  if (NumWords > 1) {
95
0
    void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
96
0
    std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
97
0
    Integer.pVal = static_cast<uint64_t *>(Mem);
98
1.95M
  } else {
99
1.95M
    Integer.VAL = Value.getZExtValue();
100
1.95M
  }
101
1.95M
102
1.95M
  Integer.Type = Type.getAsOpaquePtr();
103
1.95M
}
104
105
TemplateArgument
106
TemplateArgument::CreatePackCopy(ASTContext &Context,
107
453k
                                 ArrayRef<TemplateArgument> Args) {
108
453k
  if (Args.empty())
109
29.1k
    return getEmptyPack();
110
424k
111
424k
  return TemplateArgument(Args.copy(Context));
112
424k
}
113
114
8.75M
bool TemplateArgument::isDependent() const {
115
8.75M
  switch (getKind()) {
116
8.75M
  case Null:
117
0
    llvm_unreachable("Should not have a NULL template argument");
118
8.75M
119
8.75M
  case Type:
120
7.21M
    return getAsType()->isDependentType() ||
121
7.21M
           
isa<PackExpansionType>(getAsType())4.02M
;
122
8.75M
123
8.75M
  case Template:
124
24.6k
    return getAsTemplate().isDependent();
125
8.75M
126
8.75M
  case TemplateExpansion:
127
15
    return true;
128
8.75M
129
8.75M
  case Declaration:
130
0
    if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl()))
131
0
      return DC->isDependentContext();
132
0
    return getAsDecl()->getDeclContext()->isDependentContext();
133
0
134
1
  case NullPtr:
135
1
    return false;
136
0
137
0
  case Integral:
138
0
    // Never dependent
139
0
    return false;
140
0
141
1.51M
  case Expression:
142
1.51M
    return (getAsExpr()->isTypeDependent() || 
getAsExpr()->isValueDependent()1.47M
||
143
1.51M
            
isa<PackExpansionExpr>(getAsExpr())807k
);
144
0
145
6.04k
  case Pack:
146
6.04k
    for (const auto &P : pack_elements())
147
6.04k
      if (P.isDependent())
148
6.04k
        return true;
149
6.04k
    
return false0
;
150
0
  }
151
0
152
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
153
0
}
154
155
21.7M
bool TemplateArgument::isInstantiationDependent() const {
156
21.7M
  switch (getKind()) {
157
21.7M
  case Null:
158
0
    llvm_unreachable("Should not have a NULL template argument");
159
21.7M
160
21.7M
  case Type:
161
17.2M
    return getAsType()->isInstantiationDependentType();
162
21.7M
163
21.7M
  case Template:
164
50.6k
    return getAsTemplate().isInstantiationDependent();
165
21.7M
166
21.7M
  case TemplateExpansion:
167
148
    return true;
168
21.7M
169
21.7M
  case Declaration:
170
1.56k
    if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl()))
171
331
      return DC->isDependentContext();
172
1.23k
    return getAsDecl()->getDeclContext()->isDependentContext();
173
1.23k
174
1.23k
  case NullPtr:
175
235
    return false;
176
1.23k
177
532k
  case Integral:
178
532k
    // Never dependent
179
532k
    return false;
180
1.23k
181
3.67M
  case Expression:
182
3.67M
    return getAsExpr()->isInstantiationDependent();
183
1.23k
184
154k
  case Pack:
185
154k
    for (const auto &P : pack_elements())
186
164k
      if (P.isInstantiationDependent())
187
124k
        return true;
188
154k
    
return false29.4k
;
189
0
  }
190
0
191
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
192
0
}
193
194
33.6M
bool TemplateArgument::isPackExpansion() const {
195
33.6M
  switch (getKind()) {
196
33.6M
  case Null:
197
1.91M
  case Declaration:
198
1.91M
  case Integral:
199
1.91M
  case Pack:
200
1.91M
  case Template:
201
1.91M
  case NullPtr:
202
1.91M
    return false;
203
1.91M
204
1.91M
  case TemplateExpansion:
205
91
    return true;
206
1.91M
207
26.8M
  case Type:
208
26.8M
    return isa<PackExpansionType>(getAsType());
209
1.91M
210
4.95M
  case Expression:
211
4.95M
    return isa<PackExpansionExpr>(getAsExpr());
212
0
  }
213
0
214
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
215
0
}
216
217
15.9M
bool TemplateArgument::containsUnexpandedParameterPack() const {
218
15.9M
  switch (getKind()) {
219
15.9M
  case Null:
220
276k
  case Declaration:
221
276k
  case Integral:
222
276k
  case TemplateExpansion:
223
276k
  case NullPtr:
224
276k
    break;
225
276k
226
12.3M
  case Type:
227
12.3M
    if (getAsType()->containsUnexpandedParameterPack())
228
93.6k
      return true;
229
12.2M
    break;
230
12.2M
231
12.2M
  case Template:
232
47.3k
    if (getAsTemplate().containsUnexpandedParameterPack())
233
4
      return true;
234
47.3k
    break;
235
47.3k
236
3.12M
  case Expression:
237
3.12M
    if (getAsExpr()->containsUnexpandedParameterPack())
238
33.9k
      return true;
239
3.08M
    break;
240
3.08M
241
3.08M
  case Pack:
242
124k
    for (const auto &P : pack_elements())
243
147k
      if (P.containsUnexpandedParameterPack())
244
1.58k
        return true;
245
124k
246
124k
    
break123k
;
247
15.7M
  }
248
15.7M
249
15.7M
  return false;
250
15.7M
}
251
252
118
Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const {
253
118
  assert(getKind() == TemplateExpansion);
254
118
  if (TemplateArg.NumExpansions)
255
3
    return TemplateArg.NumExpansions - 1;
256
115
257
115
  return None;
258
115
}
259
260
157k
QualType TemplateArgument::getNonTypeTemplateArgumentType() const {
261
157k
  switch (getKind()) {
262
157k
  case TemplateArgument::Null:
263
154k
  case TemplateArgument::Type:
264
154k
  case TemplateArgument::Template:
265
154k
  case TemplateArgument::TemplateExpansion:
266
154k
  case TemplateArgument::Pack:
267
154k
    return QualType();
268
154k
269
154k
  case TemplateArgument::Integral:
270
1.22k
    return getIntegralType();
271
154k
272
154k
  case TemplateArgument::Expression:
273
1.02k
    return getAsExpr()->getType();
274
154k
275
154k
  case TemplateArgument::Declaration:
276
8
    return getParamTypeForDecl();
277
154k
278
154k
  case TemplateArgument::NullPtr:
279
0
    return getNullPtrType();
280
0
  }
281
0
282
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
283
0
}
284
285
void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
286
31.6M
                               const ASTContext &Context) const {
287
31.6M
  ID.AddInteger(getKind());
288
31.6M
  switch (getKind()) {
289
31.6M
  case Null:
290
0
    break;
291
31.6M
292
31.6M
  case Type:
293
24.0M
    getAsType().Profile(ID);
294
24.0M
    break;
295
31.6M
296
31.6M
  case NullPtr:
297
556
    getNullPtrType().Profile(ID);
298
556
    break;
299
31.6M
300
31.6M
  case Declaration:
301
6.25k
    ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : 
nullptr0
);
302
6.25k
    break;
303
31.6M
304
31.6M
  case Template:
305
38.4k
  case TemplateExpansion: {
306
38.4k
    TemplateName Template = getAsTemplateOrTemplatePattern();
307
38.4k
    if (TemplateTemplateParmDecl *TTP
308
8.96k
          = dyn_cast_or_null<TemplateTemplateParmDecl>(
309
8.96k
                                                Template.getAsTemplateDecl())) {
310
8.96k
      ID.AddBoolean(true);
311
8.96k
      ID.AddInteger(TTP->getDepth());
312
8.96k
      ID.AddInteger(TTP->getPosition());
313
8.96k
      ID.AddBoolean(TTP->isParameterPack());
314
29.5k
    } else {
315
29.5k
      ID.AddBoolean(false);
316
29.5k
      ID.AddPointer(Context.getCanonicalTemplateName(Template)
317
29.5k
                                                          .getAsVoidPointer());
318
29.5k
    }
319
38.4k
    break;
320
38.4k
  }
321
38.4k
322
2.98M
  case Integral:
323
2.98M
    getAsIntegral().Profile(ID);
324
2.98M
    getIntegralType().Profile(ID);
325
2.98M
    break;
326
38.4k
327
3.66M
  case Expression:
328
3.66M
    getAsExpr()->Profile(ID, Context, true);
329
3.66M
    break;
330
38.4k
331
991k
  case Pack:
332
991k
    ID.AddInteger(Args.NumArgs);
333
2.46M
    for (unsigned I = 0; I != Args.NumArgs; 
++I1.47M
)
334
1.47M
      Args.Args[I].Profile(ID, Context);
335
31.6M
  }
336
31.6M
}
337
338
80.2k
bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const {
339
80.2k
  if (getKind() != Other.getKind()) 
return false0
;
340
80.2k
341
80.2k
  switch (getKind()) {
342
80.2k
  case Null:
343
80.2k
  case Type:
344
80.2k
  case Expression:
345
80.2k
  case Template:
346
80.2k
  case TemplateExpansion:
347
80.2k
  case NullPtr:
348
80.2k
    return TypeOrValue.V == Other.TypeOrValue.V;
349
80.2k
350
80.2k
  case Declaration:
351
0
    return getAsDecl() == Other.getAsDecl();
352
80.2k
353
80.2k
  case Integral:
354
0
    return getIntegralType() == Other.getIntegralType() &&
355
0
           getAsIntegral() == Other.getAsIntegral();
356
80.2k
357
80.2k
  case Pack:
358
0
    if (Args.NumArgs != Other.Args.NumArgs) return false;
359
0
    for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
360
0
      if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
361
0
        return false;
362
0
    return true;
363
0
  }
364
0
365
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
366
0
}
367
368
56.0k
TemplateArgument TemplateArgument::getPackExpansionPattern() const {
369
56.0k
  assert(isPackExpansion());
370
56.0k
371
56.0k
  switch (getKind()) {
372
56.0k
  case Type:
373
35.1k
    return getAsType()->getAs<PackExpansionType>()->getPattern();
374
56.0k
375
56.0k
  case Expression:
376
20.7k
    return cast<PackExpansionExpr>(getAsExpr())->getPattern();
377
56.0k
378
56.0k
  case TemplateExpansion:
379
46
    return TemplateArgument(getAsTemplateOrTemplatePattern());
380
56.0k
381
56.0k
  case Declaration:
382
0
  case Integral:
383
0
  case Pack:
384
0
  case Null:
385
0
  case Template:
386
0
  case NullPtr:
387
0
    return TemplateArgument();
388
0
  }
389
0
390
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
391
0
}
392
393
void TemplateArgument::print(const PrintingPolicy &Policy,
394
573k
                             raw_ostream &Out) const {
395
573k
  switch (getKind()) {
396
573k
  case Null:
397
52
    Out << "(no value)";
398
52
    break;
399
573k
400
573k
  case Type: {
401
458k
    PrintingPolicy SubPolicy(Policy);
402
458k
    SubPolicy.SuppressStrongLifetime = true;
403
458k
    getAsType().print(Out, SubPolicy);
404
458k
    break;
405
573k
  }
406
573k
407
573k
  case Declaration: {
408
1.94k
    NamedDecl *ND = getAsDecl();
409
1.94k
    Out << '&';
410
1.94k
    if (ND->getDeclName()) {
411
1.94k
      // FIXME: distinguish between pointer and reference args?
412
1.94k
      ND->printQualifiedName(Out);
413
1.94k
    } else {
414
0
      Out << "(anonymous)";
415
0
    }
416
1.94k
    break;
417
573k
  }
418
573k
419
573k
  case NullPtr:
420
807
    Out << "nullptr";
421
807
    break;
422
573k
423
573k
  case Template:
424
882
    getAsTemplate().print(Out, Policy);
425
882
    break;
426
573k
427
573k
  case TemplateExpansion:
428
2
    getAsTemplateOrTemplatePattern().print(Out, Policy);
429
2
    Out << "...";
430
2
    break;
431
573k
432
573k
  case Integral:
433
109k
    printIntegral(*this, Out, Policy);
434
109k
    break;
435
573k
436
573k
  case Expression:
437
2.17k
    getAsExpr()->printPretty(Out, nullptr, Policy);
438
2.17k
    break;
439
573k
440
573k
  case Pack:
441
168
    Out << "<";
442
168
    bool First = true;
443
235
    for (const auto &P : pack_elements()) {
444
235
      if (First)
445
110
        First = false;
446
125
      else
447
125
        Out << ", ";
448
235
449
235
      P.print(Policy, Out);
450
235
    }
451
168
    Out << ">";
452
168
    break;
453
573k
  }
454
573k
}
455
456
0
void TemplateArgument::dump(raw_ostream &Out) const {
457
0
  LangOptions LO; // FIXME! see also TemplateName::dump().
458
0
  LO.CPlusPlus = true;
459
0
  LO.Bool = true;
460
0
  print(PrintingPolicy(LO), Out);
461
0
}
462
463
0
LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
464
465
//===----------------------------------------------------------------------===//
466
// TemplateArgumentLoc Implementation
467
//===----------------------------------------------------------------------===//
468
469
276k
SourceRange TemplateArgumentLoc::getSourceRange() const {
470
276k
  switch (Argument.getKind()) {
471
276k
  case TemplateArgument::Expression:
472
177k
    return getSourceExpression()->getSourceRange();
473
276k
474
276k
  case TemplateArgument::Declaration:
475
0
    return getSourceDeclExpression()->getSourceRange();
476
276k
477
276k
  case TemplateArgument::NullPtr:
478
0
    return getSourceNullPtrExpression()->getSourceRange();
479
276k
480
276k
  case TemplateArgument::Type:
481
99.1k
    if (TypeSourceInfo *TSI = getTypeSourceInfo())
482
99.1k
      return TSI->getTypeLoc().getSourceRange();
483
0
    else
484
0
      return SourceRange();
485
0
486
230
  case TemplateArgument::Template:
487
230
    if (getTemplateQualifierLoc())
488
40
      return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
489
40
                         getTemplateNameLoc());
490
190
    return SourceRange(getTemplateNameLoc());
491
190
492
190
  case TemplateArgument::TemplateExpansion:
493
1
    if (getTemplateQualifierLoc())
494
1
      return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
495
1
                         getTemplateEllipsisLoc());
496
0
    return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc());
497
0
498
0
  case TemplateArgument::Integral:
499
0
    return getSourceIntegralExpression()->getSourceRange();
500
0
501
0
  case TemplateArgument::Pack:
502
0
  case TemplateArgument::Null:
503
0
    return SourceRange();
504
0
  }
505
0
506
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
507
0
}
508
509
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
510
516
                                           const TemplateArgument &Arg) {
511
516
  switch (Arg.getKind()) {
512
516
  case TemplateArgument::Null:
513
0
    // This is bad, but not as bad as crashing because of argument
514
0
    // count mismatches.
515
0
    return DB << "(null template argument)";
516
516
517
516
  case TemplateArgument::Type:
518
293
    return DB << Arg.getAsType();
519
516
520
516
  case TemplateArgument::Declaration:
521
8
    return DB << Arg.getAsDecl();
522
516
523
516
  case TemplateArgument::NullPtr:
524
0
    return DB << "nullptr";
525
516
526
516
  case TemplateArgument::Integral:
527
44
    return DB << Arg.getAsIntegral().toString(10);
528
516
529
516
  case TemplateArgument::Template:
530
10
    return DB << Arg.getAsTemplate();
531
516
532
516
  case TemplateArgument::TemplateExpansion:
533
0
    return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
534
516
535
516
  case TemplateArgument::Expression: {
536
65
    // This shouldn't actually ever happen, so it's okay that we're
537
65
    // regurgitating an expression here.
538
65
    // FIXME: We're guessing at LangOptions!
539
65
    SmallString<32> Str;
540
65
    llvm::raw_svector_ostream OS(Str);
541
65
    LangOptions LangOpts;
542
65
    LangOpts.CPlusPlus = true;
543
65
    PrintingPolicy Policy(LangOpts);
544
65
    Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
545
65
    return DB << OS.str();
546
516
  }
547
516
548
516
  case TemplateArgument::Pack: {
549
96
    // FIXME: We're guessing at LangOptions!
550
96
    SmallString<32> Str;
551
96
    llvm::raw_svector_ostream OS(Str);
552
96
    LangOptions LangOpts;
553
96
    LangOpts.CPlusPlus = true;
554
96
    PrintingPolicy Policy(LangOpts);
555
96
    Arg.print(Policy, OS);
556
96
    return DB << OS.str();
557
0
  }
558
0
  }
559
0
560
0
  llvm_unreachable("Invalid TemplateArgument Kind!");
561
0
}
562
563
const ASTTemplateArgumentListInfo *
564
ASTTemplateArgumentListInfo::Create(ASTContext &C,
565
184k
                                    const TemplateArgumentListInfo &List) {
566
184k
  std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
567
184k
  void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
568
184k
  return new (Mem) ASTTemplateArgumentListInfo(List);
569
184k
}
570
571
ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
572
184k
    const TemplateArgumentListInfo &Info) {
573
184k
  LAngleLoc = Info.getLAngleLoc();
574
184k
  RAngleLoc = Info.getRAngleLoc();
575
184k
  NumTemplateArgs = Info.size();
576
184k
577
184k
  TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
578
572k
  for (unsigned i = 0; i != NumTemplateArgs; 
++i388k
)
579
388k
    new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
580
184k
}
581
582
void ASTTemplateKWAndArgsInfo::initializeFrom(
583
    SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
584
839
    TemplateArgumentLoc *OutArgArray) {
585
839
  this->TemplateKWLoc = TemplateKWLoc;
586
839
  LAngleLoc = Info.getLAngleLoc();
587
839
  RAngleLoc = Info.getRAngleLoc();
588
839
  NumTemplateArgs = Info.size();
589
839
590
1.95k
  for (unsigned i = 0; i != NumTemplateArgs; 
++i1.11k
)
591
1.11k
    new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
592
839
}
593
594
183
void ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc) {
595
183
  assert(TemplateKWLoc.isValid());
596
183
  LAngleLoc = SourceLocation();
597
183
  RAngleLoc = SourceLocation();
598
183
  this->TemplateKWLoc = TemplateKWLoc;
599
183
  NumTemplateArgs = 0;
600
183
}
601
602
void ASTTemplateKWAndArgsInfo::initializeFrom(
603
    SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
604
    TemplateArgumentLoc *OutArgArray, bool &Dependent,
605
682k
    bool &InstantiationDependent, bool &ContainsUnexpandedParameterPack) {
606
682k
  this->TemplateKWLoc = TemplateKWLoc;
607
682k
  LAngleLoc = Info.getLAngleLoc();
608
682k
  RAngleLoc = Info.getRAngleLoc();
609
682k
  NumTemplateArgs = Info.size();
610
682k
611
1.48M
  for (unsigned i = 0; i != NumTemplateArgs; 
++i803k
) {
612
803k
    Dependent = Dependent || 
Info[i].getArgument().isDependent()707k
;
613
803k
    InstantiationDependent = InstantiationDependent ||
614
803k
                             
Info[i].getArgument().isInstantiationDependent()707k
;
615
803k
    ContainsUnexpandedParameterPack =
616
803k
        ContainsUnexpandedParameterPack ||
617
803k
        Info[i].getArgument().containsUnexpandedParameterPack();
618
803k
619
803k
    new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
620
803k
  }
621
682k
}
622
623
void ASTTemplateKWAndArgsInfo::copyInto(const TemplateArgumentLoc *ArgArray,
624
419k
                                        TemplateArgumentListInfo &Info) const {
625
419k
  Info.setLAngleLoc(LAngleLoc);
626
419k
  Info.setRAngleLoc(RAngleLoc);
627
893k
  for (unsigned I = 0; I != NumTemplateArgs; 
++I474k
)
628
474k
    Info.addArgument(ArgArray[I]);
629
419k
}