Coverage Report

Created: 2021-06-15 06:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/TemplateBase.h
Line
Count
Source (jump to first uncovered line)
1
//===- TemplateBase.h - Core classes for C++ templates ----------*- C++ -*-===//
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 provides definitions which are common for all kinds of
10
//  template representation.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_TEMPLATEBASE_H
15
#define LLVM_CLANG_AST_TEMPLATEBASE_H
16
17
#include "clang/AST/DependenceFlags.h"
18
#include "clang/AST/NestedNameSpecifier.h"
19
#include "clang/AST/TemplateName.h"
20
#include "clang/AST/Type.h"
21
#include "clang/Basic/LLVM.h"
22
#include "clang/Basic/SourceLocation.h"
23
#include "llvm/ADT/APInt.h"
24
#include "llvm/ADT/APSInt.h"
25
#include "llvm/ADT/ArrayRef.h"
26
#include "llvm/ADT/None.h"
27
#include "llvm/ADT/Optional.h"
28
#include "llvm/ADT/SmallVector.h"
29
#include "llvm/Support/Compiler.h"
30
#include "llvm/Support/TrailingObjects.h"
31
#include <cassert>
32
#include <cstddef>
33
#include <cstdint>
34
35
namespace llvm {
36
37
class FoldingSetNodeID;
38
39
// Provide PointerLikeTypeTraits for clang::Expr*, this default one requires a
40
// full definition of Expr, but this file only sees a forward del because of
41
// the dependency.
42
template <> struct PointerLikeTypeTraits<clang::Expr *> {
43
565M
  static inline void *getAsVoidPointer(clang::Expr *P) { return P; }
44
984M
  static inline clang::Expr *getFromVoidPointer(void *P) {
45
984M
    return static_cast<clang::Expr *>(P);
46
984M
  }
47
  static constexpr int NumLowBitsAvailable = 2;
48
};
49
50
} // namespace llvm
51
52
namespace clang {
53
54
class ASTContext;
55
class DiagnosticBuilder;
56
class Expr;
57
struct PrintingPolicy;
58
class TypeSourceInfo;
59
class ValueDecl;
60
61
/// Represents a template argument.
62
class TemplateArgument {
63
public:
64
  /// The kind of template argument we're storing.
65
  enum ArgKind {
66
    /// Represents an empty template argument, e.g., one that has not
67
    /// been deduced.
68
    Null = 0,
69
70
    /// The template argument is a type.
71
    Type,
72
73
    /// The template argument is a declaration that was provided for a pointer,
74
    /// reference, or pointer to member non-type template parameter.
75
    Declaration,
76
77
    /// The template argument is a null pointer or null pointer to member that
78
    /// was provided for a non-type template parameter.
79
    NullPtr,
80
81
    /// The template argument is an integral value stored in an llvm::APSInt
82
    /// that was provided for an integral non-type template parameter.
83
    Integral,
84
85
    /// The template argument is a template name that was provided for a
86
    /// template template parameter.
87
    Template,
88
89
    /// The template argument is a pack expansion of a template name that was
90
    /// provided for a template template parameter.
91
    TemplateExpansion,
92
93
    /// The template argument is an expression, and we've not resolved it to one
94
    /// of the other forms yet, either because it's dependent or because we're
95
    /// representing a non-canonical template argument (for instance, in a
96
    /// TemplateSpecializationType).
97
    Expression,
98
99
    /// The template argument is actually a parameter pack. Arguments are stored
100
    /// in the Args struct.
101
    Pack
102
  };
103
104
private:
105
  /// The kind of template argument we're storing.
106
107
  struct DA {
108
    unsigned Kind;
109
    void *QT;
110
    ValueDecl *D;
111
  };
112
  struct I {
113
    unsigned Kind;
114
    // We store a decomposed APSInt with the data allocated by ASTContext if
115
    // BitWidth > 64. The memory may be shared between multiple
116
    // TemplateArgument instances.
117
    unsigned BitWidth : 31;
118
    unsigned IsUnsigned : 1;
119
    union {
120
      /// Used to store the <= 64 bits integer value.
121
      uint64_t VAL;
122
123
      /// Used to store the >64 bits integer value.
124
      const uint64_t *pVal;
125
    };
126
    void *Type;
127
  };
128
  struct A {
129
    unsigned Kind;
130
    unsigned NumArgs;
131
    const TemplateArgument *Args;
132
  };
133
  struct TA {
134
    unsigned Kind;
135
    unsigned NumExpansions;
136
    void *Name;
137
  };
138
  struct TV {
139
    unsigned Kind;
140
    uintptr_t V;
141
  };
142
  union {
143
    struct DA DeclArg;
144
    struct I Integer;
145
    struct A Args;
146
    struct TA TemplateArg;
147
    struct TV TypeOrValue;
148
  };
149
150
public:
151
  /// Construct an empty, invalid template argument.
152
23.2M
  constexpr TemplateArgument() : TypeOrValue({Null, 0}) {}
153
154
  /// Construct a template type argument.
155
42.6M
  TemplateArgument(QualType T, bool isNullPtr = false) {
156
42.6M
    TypeOrValue.Kind = isNullPtr ? 
NullPtr410
:
Type42.6M
;
157
42.6M
    TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
158
42.6M
  }
159
160
  /// Construct a template argument that refers to a
161
  /// declaration, which is either an external declaration or a
162
  /// template declaration.
163
4.68k
  TemplateArgument(ValueDecl *D, QualType QT) {
164
4.68k
    assert(D && "Expected decl");
165
0
    DeclArg.Kind = Declaration;
166
4.68k
    DeclArg.QT = QT.getAsOpaquePtr();
167
4.68k
    DeclArg.D = D;
168
4.68k
  }
169
170
  /// Construct an integral constant template argument. The memory to
171
  /// store the value is allocated with Ctx.
172
  TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type);
173
174
  /// Construct an integral constant template argument with the same
175
  /// value as Other but a different type.
176
928k
  TemplateArgument(const TemplateArgument &Other, QualType Type) {
177
928k
    Integer = Other.Integer;
178
928k
    Integer.Type = Type.getAsOpaquePtr();
179
928k
  }
180
181
  /// Construct a template argument that is a template.
182
  ///
183
  /// This form of template argument is generally used for template template
184
  /// parameters. However, the template name could be a dependent template
185
  /// name that ends up being instantiated to a function template whose address
186
  /// is taken.
187
  ///
188
  /// \param Name The template name.
189
427k
  TemplateArgument(TemplateName Name) {
190
427k
    TemplateArg.Kind = Template;
191
427k
    TemplateArg.Name = Name.getAsVoidPointer();
192
427k
    TemplateArg.NumExpansions = 0;
193
427k
  }
194
195
  /// Construct a template argument that is a template pack expansion.
196
  ///
197
  /// This form of template argument is generally used for template template
198
  /// parameters. However, the template name could be a dependent template
199
  /// name that ends up being instantiated to a function template whose address
200
  /// is taken.
201
  ///
202
  /// \param Name The template name.
203
  ///
204
  /// \param NumExpansions The number of expansions that will be generated by
205
  /// instantiating
206
220
  TemplateArgument(TemplateName Name, Optional<unsigned> NumExpansions) {
207
220
    TemplateArg.Kind = TemplateExpansion;
208
220
    TemplateArg.Name = Name.getAsVoidPointer();
209
220
    if (NumExpansions)
210
4
      TemplateArg.NumExpansions = *NumExpansions + 1;
211
216
    else
212
216
      TemplateArg.NumExpansions = 0;
213
220
  }
214
215
  /// Construct a template argument that is an expression.
216
  ///
217
  /// This form of template argument only occurs in template argument
218
  /// lists used for dependent types and for expression; it will not
219
  /// occur in a non-dependent, canonical template argument list.
220
7.39M
  TemplateArgument(Expr *E) {
221
7.39M
    TypeOrValue.Kind = Expression;
222
7.39M
    TypeOrValue.V = reinterpret_cast<uintptr_t>(E);
223
7.39M
  }
224
225
  /// Construct a template argument that is a template argument pack.
226
  ///
227
  /// We assume that storage for the template arguments provided
228
  /// outlives the TemplateArgument itself.
229
1.28M
  explicit TemplateArgument(ArrayRef<TemplateArgument> Args) {
230
1.28M
    this->Args.Kind = Pack;
231
1.28M
    this->Args.Args = Args.data();
232
1.28M
    this->Args.NumArgs = Args.size();
233
1.28M
  }
234
235
  TemplateArgument(TemplateName, bool) = delete;
236
237
37.7k
  static TemplateArgument getEmptyPack() { return TemplateArgument(None); }
238
239
  /// Create a new template argument pack by copying the given set of
240
  /// template arguments.
241
  static TemplateArgument CreatePackCopy(ASTContext &Context,
242
                                         ArrayRef<TemplateArgument> Args);
243
244
  /// Return the kind of stored template argument.
245
521M
  ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; }
246
247
  /// Determine whether this template argument has no value.
248
13.1M
  bool isNull() const { return getKind() == Null; }
249
250
  TemplateArgumentDependence getDependence() const;
251
252
  /// Whether this template argument is dependent on a template
253
  /// parameter such that its result can change from one instantiation to
254
  /// another.
255
  bool isDependent() const;
256
257
  /// Whether this template argument is dependent on a template
258
  /// parameter.
259
  bool isInstantiationDependent() const;
260
261
  /// Whether this template argument contains an unexpanded
262
  /// parameter pack.
263
  bool containsUnexpandedParameterPack() const;
264
265
  /// Determine whether this template argument is a pack expansion.
266
  bool isPackExpansion() const;
267
268
  /// Retrieve the type for a type template argument.
269
160M
  QualType getAsType() const {
270
160M
    assert(getKind() == Type && "Unexpected kind");
271
0
    return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
272
160M
  }
273
274
  /// Retrieve the declaration for a declaration non-type
275
  /// template argument.
276
35.6k
  ValueDecl *getAsDecl() const {
277
35.6k
    assert(getKind() == Declaration && "Unexpected kind");
278
0
    return DeclArg.D;
279
35.6k
  }
280
281
18.0k
  QualType getParamTypeForDecl() const {
282
18.0k
    assert(getKind() == Declaration && "Unexpected kind");
283
0
    return QualType::getFromOpaquePtr(DeclArg.QT);
284
18.0k
  }
285
286
  /// Retrieve the type for null non-type template argument.
287
1.17k
  QualType getNullPtrType() const {
288
1.17k
    assert(getKind() == NullPtr && "Unexpected kind");
289
0
    return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
290
1.17k
  }
291
292
  /// Retrieve the template name for a template name argument.
293
246k
  TemplateName getAsTemplate() const {
294
246k
    assert(getKind() == Template && "Unexpected kind");
295
0
    return TemplateName::getFromVoidPointer(TemplateArg.Name);
296
246k
  }
297
298
  /// Retrieve the template argument as a template name; if the argument
299
  /// is a pack expansion, return the pattern as a template name.
300
160k
  TemplateName getAsTemplateOrTemplatePattern() const {
301
160k
    assert((getKind() == Template || getKind() == TemplateExpansion) &&
302
160k
           "Unexpected kind");
303
304
0
    return TemplateName::getFromVoidPointer(TemplateArg.Name);
305
160k
  }
306
307
  /// Retrieve the number of expansions that a template template argument
308
  /// expansion will produce, if known.
309
  Optional<unsigned> getNumTemplateExpansions() const;
310
311
  /// Retrieve the template argument as an integral value.
312
  // FIXME: Provide a way to read the integral data without copying the value.
313
6.02M
  llvm::APSInt getAsIntegral() const {
314
6.02M
    assert(getKind() == Integral && "Unexpected kind");
315
316
0
    using namespace llvm;
317
318
6.02M
    if (Integer.BitWidth <= 64)
319
6.02M
      return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
320
321
64
    unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
322
64
    return APSInt(APInt(Integer.BitWidth, makeArrayRef(Integer.pVal, NumWords)),
323
64
                  Integer.IsUnsigned);
324
6.02M
  }
325
326
  /// Retrieve the type of the integral value.
327
6.67M
  QualType getIntegralType() const {
328
6.67M
    assert(getKind() == Integral && "Unexpected kind");
329
0
    return QualType::getFromOpaquePtr(Integer.Type);
330
6.67M
  }
331
332
0
  void setIntegralType(QualType T) {
333
0
    assert(getKind() == Integral && "Unexpected kind");
334
0
    Integer.Type = T.getAsOpaquePtr();
335
0
  }
336
337
  /// If this is a non-type template argument, get its type. Otherwise,
338
  /// returns a null QualType.
339
  QualType getNonTypeTemplateArgumentType() const;
340
341
  /// Retrieve the template argument as an expression.
342
27.1M
  Expr *getAsExpr() const {
343
27.1M
    assert(getKind() == Expression && "Unexpected kind");
344
0
    return reinterpret_cast<Expr *>(TypeOrValue.V);
345
27.1M
  }
346
347
  /// Iterator that traverses the elements of a template argument pack.
348
  using pack_iterator = const TemplateArgument *;
349
350
  /// Iterator referencing the first argument of a template argument
351
  /// pack.
352
2.42M
  pack_iterator pack_begin() const {
353
2.42M
    assert(getKind() == Pack);
354
0
    return Args.Args;
355
2.42M
  }
356
357
  /// Iterator referencing one past the last argument of a template
358
  /// argument pack.
359
1.77M
  pack_iterator pack_end() const {
360
1.77M
    assert(getKind() == Pack);
361
0
    return Args.Args + Args.NumArgs;
362
1.77M
  }
363
364
  /// Iterator range referencing all of the elements of a template
365
  /// argument pack.
366
1.31M
  ArrayRef<TemplateArgument> pack_elements() const {
367
1.31M
    return llvm::makeArrayRef(pack_begin(), pack_end());
368
1.31M
  }
369
370
  /// The number of template arguments in the given template argument
371
  /// pack.
372
2.52M
  unsigned pack_size() const {
373
2.52M
    assert(getKind() == Pack);
374
0
    return Args.NumArgs;
375
2.52M
  }
376
377
  /// Return the array of arguments in this template argument pack.
378
177k
  ArrayRef<TemplateArgument> getPackAsArray() const {
379
177k
    assert(getKind() == Pack);
380
0
    return llvm::makeArrayRef(Args.Args, Args.NumArgs);
381
177k
  }
382
383
  /// Determines whether two template arguments are superficially the
384
  /// same.
385
  bool structurallyEquals(const TemplateArgument &Other) const;
386
387
  /// When the template argument is a pack expansion, returns
388
  /// the pattern of the pack expansion.
389
  TemplateArgument getPackExpansionPattern() const;
390
391
  /// Print this template argument to the given output stream.
392
  void print(const PrintingPolicy &Policy, raw_ostream &Out,
393
             bool IncludeType) const;
394
395
  /// Debugging aid that dumps the template argument.
396
  void dump(raw_ostream &Out) const;
397
398
  /// Debugging aid that dumps the template argument to standard error.
399
  void dump() const;
400
401
  /// Used to insert TemplateArguments into FoldingSets.
402
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
403
};
404
405
/// Location information for a TemplateArgument.
406
struct TemplateArgumentLocInfo {
407
private:
408
  struct TemplateTemplateArgLocInfo {
409
    // FIXME: We'd like to just use the qualifier in the TemplateName,
410
    // but template arguments get canonicalized too quickly.
411
    NestedNameSpecifier *Qualifier;
412
    void *QualifierLocData;
413
    SourceLocation TemplateNameLoc;
414
    SourceLocation EllipsisLoc;
415
  };
416
417
  llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
418
      Pointer;
419
420
226k
  TemplateTemplateArgLocInfo *getTemplate() const {
421
226k
    return Pointer.get<TemplateTemplateArgLocInfo *>();
422
226k
  }
423
424
public:
425
7.85M
  TemplateArgumentLocInfo() {}
426
14.8M
  TemplateArgumentLocInfo(TypeSourceInfo *Declarator) { Pointer = Declarator; }
427
428
6.36M
  TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
429
  // Ctx is used for allocation -- this case is unusually large and also rare,
430
  // so we store the payload out-of-line.
431
  TemplateArgumentLocInfo(ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
432
                          SourceLocation TemplateNameLoc,
433
                          SourceLocation EllipsisLoc);
434
435
17.0M
  TypeSourceInfo *getAsTypeSourceInfo() const {
436
17.0M
    return Pointer.get<TypeSourceInfo *>();
437
17.0M
  }
438
439
2.09M
  Expr *getAsExpr() const { return Pointer.get<Expr *>(); }
440
441
66.0k
  NestedNameSpecifierLoc getTemplateQualifierLoc() const {
442
66.0k
    const auto *Template = getTemplate();
443
66.0k
    return NestedNameSpecifierLoc(Template->Qualifier,
444
66.0k
                                  Template->QualifierLocData);
445
66.0k
  }
446
447
159k
  SourceLocation getTemplateNameLoc() const {
448
159k
    return getTemplate()->TemplateNameLoc;
449
159k
  }
450
451
1.36k
  SourceLocation getTemplateEllipsisLoc() const {
452
1.36k
    return getTemplate()->EllipsisLoc;
453
1.36k
  }
454
};
455
456
/// Location wrapper for a TemplateArgument.  TemplateArgument is to
457
/// TemplateArgumentLoc as Type is to TypeLoc.
458
class TemplateArgumentLoc {
459
  TemplateArgument Argument;
460
  TemplateArgumentLocInfo LocInfo;
461
462
public:
463
7.78M
  TemplateArgumentLoc() {}
464
465
  TemplateArgumentLoc(const TemplateArgument &Argument,
466
                      TemplateArgumentLocInfo Opaque)
467
7.79M
      : Argument(Argument), LocInfo(Opaque) {}
468
469
  TemplateArgumentLoc(const TemplateArgument &Argument, TypeSourceInfo *TInfo)
470
11.0M
      : Argument(Argument), LocInfo(TInfo) {
471
11.0M
    assert(Argument.getKind() == TemplateArgument::Type);
472
11.0M
  }
473
474
  TemplateArgumentLoc(const TemplateArgument &Argument, Expr *E)
475
5.19M
      : Argument(Argument), LocInfo(E) {
476
477
    // Permit any kind of template argument that can be represented with an
478
    // expression.
479
5.19M
    assert(Argument.getKind() == TemplateArgument::NullPtr ||
480
5.19M
           Argument.getKind() == TemplateArgument::Integral ||
481
5.19M
           Argument.getKind() == TemplateArgument::Declaration ||
482
5.19M
           Argument.getKind() == TemplateArgument::Expression);
483
5.19M
  }
484
485
  TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument,
486
                      NestedNameSpecifierLoc QualifierLoc,
487
                      SourceLocation TemplateNameLoc,
488
                      SourceLocation EllipsisLoc = SourceLocation())
489
      : Argument(Argument),
490
63.9k
        LocInfo(Ctx, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
491
63.9k
    assert(Argument.getKind() == TemplateArgument::Template ||
492
63.9k
           Argument.getKind() == TemplateArgument::TemplateExpansion);
493
63.9k
  }
494
495
  /// - Fetches the primary location of the argument.
496
78.0k
  SourceLocation getLocation() const {
497
78.0k
    if (Argument.getKind() == TemplateArgument::Template ||
498
78.0k
        
Argument.getKind() == TemplateArgument::TemplateExpansion18.3k
)
499
59.7k
      return getTemplateNameLoc();
500
501
18.3k
    return getSourceRange().getBegin();
502
78.0k
  }
503
504
  /// - Fetches the full source range of the argument.
505
  SourceRange getSourceRange() const LLVM_READONLY;
506
507
66.5M
  const TemplateArgument &getArgument() const {
508
66.5M
    return Argument;
509
66.5M
  }
510
511
10.7M
  TemplateArgumentLocInfo getLocInfo() const {
512
10.7M
    return LocInfo;
513
10.7M
  }
514
515
16.5M
  TypeSourceInfo *getTypeSourceInfo() const {
516
16.5M
    if (Argument.getKind() != TemplateArgument::Type)
517
0
      return nullptr;
518
16.5M
    return LocInfo.getAsTypeSourceInfo();
519
16.5M
  }
520
521
2.00M
  Expr *getSourceExpression() const {
522
2.00M
    assert(Argument.getKind() == TemplateArgument::Expression);
523
0
    return LocInfo.getAsExpr();
524
2.00M
  }
525
526
0
  Expr *getSourceDeclExpression() const {
527
0
    assert(Argument.getKind() == TemplateArgument::Declaration);
528
0
    return LocInfo.getAsExpr();
529
0
  }
530
531
0
  Expr *getSourceNullPtrExpression() const {
532
0
    assert(Argument.getKind() == TemplateArgument::NullPtr);
533
0
    return LocInfo.getAsExpr();
534
0
  }
535
536
0
  Expr *getSourceIntegralExpression() const {
537
0
    assert(Argument.getKind() == TemplateArgument::Integral);
538
0
    return LocInfo.getAsExpr();
539
0
  }
540
541
63.3k
  NestedNameSpecifierLoc getTemplateQualifierLoc() const {
542
63.3k
    if (Argument.getKind() != TemplateArgument::Template &&
543
63.3k
        
Argument.getKind() != TemplateArgument::TemplateExpansion38
)
544
0
      return NestedNameSpecifierLoc();
545
63.3k
    return LocInfo.getTemplateQualifierLoc();
546
63.3k
  }
547
548
156k
  SourceLocation getTemplateNameLoc() const {
549
156k
    if (Argument.getKind() != TemplateArgument::Template &&
550
156k
        
Argument.getKind() != TemplateArgument::TemplateExpansion56
)
551
0
      return SourceLocation();
552
156k
    return LocInfo.getTemplateNameLoc();
553
156k
  }
554
555
37
  SourceLocation getTemplateEllipsisLoc() const {
556
37
    if (Argument.getKind() != TemplateArgument::TemplateExpansion)
557
0
      return SourceLocation();
558
37
    return LocInfo.getTemplateEllipsisLoc();
559
37
  }
560
};
561
562
/// A convenient class for passing around template argument
563
/// information.  Designed to be passed by reference.
564
class TemplateArgumentListInfo {
565
  SmallVector<TemplateArgumentLoc, 8> Arguments;
566
  SourceLocation LAngleLoc;
567
  SourceLocation RAngleLoc;
568
569
public:
570
56.0M
  TemplateArgumentListInfo() = default;
571
572
  TemplateArgumentListInfo(SourceLocation LAngleLoc,
573
                           SourceLocation RAngleLoc)
574
3.29M
      : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
575
576
  // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
577
  // instead.
578
  void *operator new(size_t bytes, ASTContext &C) = delete;
579
580
1.08M
  SourceLocation getLAngleLoc() const { return LAngleLoc; }
581
14.5M
  SourceLocation getRAngleLoc() const { return RAngleLoc; }
582
583
4.67M
  void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
584
4.67M
  void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
585
586
20.8M
  unsigned size() const { return Arguments.size(); }
587
588
57
  const TemplateArgumentLoc *getArgumentArray() const {
589
57
    return Arguments.data();
590
57
  }
591
592
11.8M
  llvm::ArrayRef<TemplateArgumentLoc> arguments() const {
593
11.8M
    return Arguments;
594
11.8M
  }
595
596
2.73M
  const TemplateArgumentLoc &operator[](unsigned I) const {
597
2.73M
    return Arguments[I];
598
2.73M
  }
599
600
31.8M
  TemplateArgumentLoc &operator[](unsigned I) {
601
31.8M
    return Arguments[I];
602
31.8M
  }
603
604
11.9M
  void addArgument(const TemplateArgumentLoc &Loc) {
605
11.9M
    Arguments.push_back(Loc);
606
11.9M
  }
607
};
608
609
/// Represents an explicit template argument list in C++, e.g.,
610
/// the "<int>" in "sort<int>".
611
/// This is safe to be used inside an AST node, in contrast with
612
/// TemplateArgumentListInfo.
613
struct ASTTemplateArgumentListInfo final
614
    : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
615
                                    TemplateArgumentLoc> {
616
private:
617
  friend class ASTNodeImporter;
618
  friend TrailingObjects;
619
620
  ASTTemplateArgumentListInfo(const TemplateArgumentListInfo &List);
621
622
public:
623
  /// The source location of the left angle bracket ('<').
624
  SourceLocation LAngleLoc;
625
626
  /// The source location of the right angle bracket ('>').
627
  SourceLocation RAngleLoc;
628
629
  /// The number of template arguments in TemplateArgs.
630
  unsigned NumTemplateArgs;
631
632
81
  SourceLocation getLAngleLoc() const { return LAngleLoc; }
633
84
  SourceLocation getRAngleLoc() const { return RAngleLoc; }
634
635
  /// Retrieve the template arguments
636
250k
  const TemplateArgumentLoc *getTemplateArgs() const {
637
250k
    return getTrailingObjects<TemplateArgumentLoc>();
638
250k
  }
639
3.04k
  unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
640
641
2.96k
  llvm::ArrayRef<TemplateArgumentLoc> arguments() const {
642
2.96k
    return llvm::makeArrayRef(getTemplateArgs(), getNumTemplateArgs());
643
2.96k
  }
644
645
113
  const TemplateArgumentLoc &operator[](unsigned I) const {
646
113
    return getTemplateArgs()[I];
647
113
  }
648
649
  static const ASTTemplateArgumentListInfo *
650
  Create(const ASTContext &C, const TemplateArgumentListInfo &List);
651
};
652
653
/// Represents an explicit template argument list in C++, e.g.,
654
/// the "<int>" in "sort<int>".
655
///
656
/// It is intended to be used as a trailing object on AST nodes, and
657
/// as such, doesn't contain the array of TemplateArgumentLoc itself,
658
/// but expects the containing object to also provide storage for
659
/// that.
660
struct alignas(void *) ASTTemplateKWAndArgsInfo {
661
  /// The source location of the left angle bracket ('<').
662
  SourceLocation LAngleLoc;
663
664
  /// The source location of the right angle bracket ('>').
665
  SourceLocation RAngleLoc;
666
667
  /// The source location of the template keyword; this is used
668
  /// as part of the representation of qualified identifiers, such as
669
  /// S<T>::template apply<T>.  Will be empty if this expression does
670
  /// not have a template keyword.
671
  SourceLocation TemplateKWLoc;
672
673
  /// The number of template arguments in TemplateArgs.
674
  unsigned NumTemplateArgs;
675
676
  void initializeFrom(SourceLocation TemplateKWLoc,
677
                      const TemplateArgumentListInfo &List,
678
                      TemplateArgumentLoc *OutArgArray);
679
  // FIXME: The parameter Deps is the result populated by this method, the
680
  // caller doesn't need it since it is populated by computeDependence. remove
681
  // it.
682
  void initializeFrom(SourceLocation TemplateKWLoc,
683
                      const TemplateArgumentListInfo &List,
684
                      TemplateArgumentLoc *OutArgArray,
685
                      TemplateArgumentDependence &Deps);
686
  void initializeFrom(SourceLocation TemplateKWLoc);
687
688
  void copyInto(const TemplateArgumentLoc *ArgArray,
689
                TemplateArgumentListInfo &List) const;
690
};
691
692
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
693
                                      const TemplateArgument &Arg);
694
695
inline TemplateSpecializationType::iterator
696
536k
    TemplateSpecializationType::end() const {
697
536k
  return getArgs() + getNumArgs();
698
536k
}
699
700
inline DependentTemplateSpecializationType::iterator
701
0
    DependentTemplateSpecializationType::end() const {
702
0
  return getArgs() + getNumArgs();
703
0
}
704
705
inline const TemplateArgument &
706
15.1M
    TemplateSpecializationType::getArg(unsigned Idx) const {
707
15.1M
  assert(Idx < getNumArgs() && "Template argument out of range");
708
0
  return getArgs()[Idx];
709
15.1M
}
710
711
inline const TemplateArgument &
712
245k
    DependentTemplateSpecializationType::getArg(unsigned Idx) const {
713
245k
  assert(Idx < getNumArgs() && "Template argument out of range");
714
0
  return getArgs()[Idx];
715
245k
}
716
717
0
inline const TemplateArgument &AutoType::getArg(unsigned Idx) const {
718
0
  assert(Idx < getNumArgs() && "Template argument out of range");
719
0
  return getArgs()[Idx];
720
0
}
721
722
} // namespace clang
723
724
#endif // LLVM_CLANG_AST_TEMPLATEBASE_H