clang  14.0.0git
TemplateBase.cpp
Go to the documentation of this file.
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"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.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"
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  const PrintingPolicy &Policy, bool IncludeType) {
59  const Type *T = TemplArg.getIntegralType().getTypePtr();
60  const llvm::APSInt &Val = TemplArg.getAsIntegral();
61 
62  if (const EnumType *ET = T->getAs<EnumType>()) {
63  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  if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
69  ECD->printQualifiedName(Out, Policy);
70  return;
71  }
72  }
73  }
74 
75  if (Policy.MSVCFormatting)
76  IncludeType = false;
77 
78  if (T->isBooleanType()) {
79  if (!Policy.MSVCFormatting)
80  Out << (Val.getBoolValue() ? "true" : "false");
81  else
82  Out << Val;
83  } else if (T->isCharType()) {
84  if (IncludeType) {
85  if (T->isSpecificBuiltinType(BuiltinType::SChar))
86  Out << "(signed char)";
87  else if (T->isSpecificBuiltinType(BuiltinType::UChar))
88  Out << "(unsigned char)";
89  }
90  CharacterLiteral::print(Val.getZExtValue(), CharacterLiteral::Ascii, Out);
91  } else if (T->isAnyCharacterType() && !Policy.MSVCFormatting) {
93  if (T->isWideCharType())
95  else if (T->isChar8Type())
97  else if (T->isChar16Type())
99  else if (T->isChar32Type())
101  else
103  CharacterLiteral::print(Val.getExtValue(), Kind, Out);
104  } else if (IncludeType) {
105  if (const auto *BT = T->getAs<BuiltinType>()) {
106  switch (BT->getKind()) {
107  case BuiltinType::ULongLong:
108  Out << Val << "ULL";
109  break;
110  case BuiltinType::LongLong:
111  Out << Val << "LL";
112  break;
113  case BuiltinType::ULong:
114  Out << Val << "UL";
115  break;
116  case BuiltinType::Long:
117  Out << Val << "L";
118  break;
119  case BuiltinType::UInt:
120  Out << Val << "U";
121  break;
122  case BuiltinType::Int:
123  Out << Val;
124  break;
125  default:
126  Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
127  << Val;
128  break;
129  }
130  } else
131  Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
132  << Val;
133  } else
134  Out << Val;
135 }
136 
137 static unsigned getArrayDepth(QualType type) {
138  unsigned count = 0;
139  while (const auto *arrayType = type->getAsArrayTypeUnsafe()) {
140  count++;
141  type = arrayType->getElementType();
142  }
143  return count;
144 }
145 
146 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  if (!paramType->isPointerType())
151  return paramType->isMemberPointerType();
152  if (argType->isArrayType())
153  return getArrayDepth(argType) == getArrayDepth(paramType->getPointeeType());
154  return true;
155 }
156 
157 //===----------------------------------------------------------------------===//
158 // TemplateArgument Implementation
159 //===----------------------------------------------------------------------===//
160 
162  QualType Type) {
163  Integer.Kind = Integral;
164  // Copy the APSInt value into our decomposed form.
165  Integer.BitWidth = Value.getBitWidth();
166  Integer.IsUnsigned = Value.isUnsigned();
167  // If the value is large, we have to get additional memory from the ASTContext
168  unsigned NumWords = Value.getNumWords();
169  if (NumWords > 1) {
170  void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
171  std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
172  Integer.pVal = static_cast<uint64_t *>(Mem);
173  } else {
174  Integer.VAL = Value.getZExtValue();
175  }
176 
177  Integer.Type = Type.getAsOpaquePtr();
178 }
179 
183  if (Args.empty())
184  return getEmptyPack();
185 
186  return TemplateArgument(Args.copy(Context));
187 }
188 
189 TemplateArgumentDependence TemplateArgument::getDependence() const {
191  switch (getKind()) {
192  case Null:
193  llvm_unreachable("Should not have a NULL template argument");
194 
195  case Type:
197  if (isa<PackExpansionType>(getAsType()))
198  Deps |= TemplateArgumentDependence::Dependent;
199  return Deps;
200 
201  case Template:
203 
204  case TemplateExpansion:
205  return TemplateArgumentDependence::Dependent |
206  TemplateArgumentDependence::Instantiation;
207 
208  case Declaration: {
209  auto *DC = dyn_cast<DeclContext>(getAsDecl());
210  if (!DC)
211  DC = getAsDecl()->getDeclContext();
212  if (DC->isDependentContext())
213  Deps = TemplateArgumentDependence::Dependent |
214  TemplateArgumentDependence::Instantiation;
215  return Deps;
216  }
217 
218  case NullPtr:
219  case Integral:
221 
222  case Expression:
224  if (isa<PackExpansionExpr>(getAsExpr()))
225  Deps |= TemplateArgumentDependence::Dependent |
226  TemplateArgumentDependence::Instantiation;
227  return Deps;
228 
229  case Pack:
230  for (const auto &P : pack_elements())
231  Deps |= P.getDependence();
232  return Deps;
233  }
234  llvm_unreachable("unhandled ArgKind");
235 }
236 
238  return getDependence() & TemplateArgumentDependence::Dependent;
239 }
240 
242  return getDependence() & TemplateArgumentDependence::Instantiation;
243 }
244 
246  switch (getKind()) {
247  case Null:
248  case Declaration:
249  case Integral:
250  case Pack:
251  case Template:
252  case NullPtr:
253  return false;
254 
255  case TemplateExpansion:
256  return true;
257 
258  case Type:
259  return isa<PackExpansionType>(getAsType());
260 
261  case Expression:
262  return isa<PackExpansionExpr>(getAsExpr());
263  }
264 
265  llvm_unreachable("Invalid TemplateArgument Kind!");
266 }
267 
269  return getDependence() & TemplateArgumentDependence::UnexpandedPack;
270 }
271 
273  assert(getKind() == TemplateExpansion);
274  if (TemplateArg.NumExpansions)
275  return TemplateArg.NumExpansions - 1;
276 
277  return None;
278 }
279 
281  switch (getKind()) {
287  return QualType();
288 
290  return getIntegralType();
291 
293  return getAsExpr()->getType();
294 
296  return getParamTypeForDecl();
297 
299  return getNullPtrType();
300  }
301 
302  llvm_unreachable("Invalid TemplateArgument Kind!");
303 }
304 
305 void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
306  const ASTContext &Context) const {
307  ID.AddInteger(getKind());
308  switch (getKind()) {
309  case Null:
310  break;
311 
312  case Type:
313  getAsType().Profile(ID);
314  break;
315 
316  case NullPtr:
318  break;
319 
320  case Declaration:
322  ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
323  break;
324 
325  case Template:
326  case TemplateExpansion: {
328  if (TemplateTemplateParmDecl *TTP
329  = dyn_cast_or_null<TemplateTemplateParmDecl>(
330  Template.getAsTemplateDecl())) {
331  ID.AddBoolean(true);
332  ID.AddInteger(TTP->getDepth());
333  ID.AddInteger(TTP->getPosition());
334  ID.AddBoolean(TTP->isParameterPack());
335  } else {
336  ID.AddBoolean(false);
337  ID.AddPointer(Context.getCanonicalTemplateName(Template)
338  .getAsVoidPointer());
339  }
340  break;
341  }
342 
343  case Integral:
344  getAsIntegral().Profile(ID);
346  break;
347 
348  case Expression:
349  getAsExpr()->Profile(ID, Context, true);
350  break;
351 
352  case Pack:
353  ID.AddInteger(Args.NumArgs);
354  for (unsigned I = 0; I != Args.NumArgs; ++I)
355  Args.Args[I].Profile(ID, Context);
356  }
357 }
358 
360  if (getKind() != Other.getKind()) return false;
361 
362  switch (getKind()) {
363  case Null:
364  case Type:
365  case Expression:
366  case NullPtr:
367  return TypeOrValue.V == Other.TypeOrValue.V;
368 
369  case Template:
370  case TemplateExpansion:
371  return TemplateArg.Name == Other.TemplateArg.Name &&
372  TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
373 
374  case Declaration:
375  return getAsDecl() == Other.getAsDecl();
376 
377  case Integral:
378  return getIntegralType() == Other.getIntegralType() &&
379  getAsIntegral() == Other.getAsIntegral();
380 
381  case Pack:
382  if (Args.NumArgs != Other.Args.NumArgs) return false;
383  for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
384  if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
385  return false;
386  return true;
387  }
388 
389  llvm_unreachable("Invalid TemplateArgument Kind!");
390 }
391 
393  assert(isPackExpansion());
394 
395  switch (getKind()) {
396  case Type:
397  return getAsType()->castAs<PackExpansionType>()->getPattern();
398 
399  case Expression:
400  return cast<PackExpansionExpr>(getAsExpr())->getPattern();
401 
402  case TemplateExpansion:
404 
405  case Declaration:
406  case Integral:
407  case Pack:
408  case Null:
409  case Template:
410  case NullPtr:
411  return TemplateArgument();
412  }
413 
414  llvm_unreachable("Invalid TemplateArgument Kind!");
415 }
416 
417 void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
418  bool IncludeType) const {
419 
420  switch (getKind()) {
421  case Null:
422  Out << "(no value)";
423  break;
424 
425  case Type: {
426  PrintingPolicy SubPolicy(Policy);
427  SubPolicy.SuppressStrongLifetime = true;
428  getAsType().print(Out, SubPolicy);
429  break;
430  }
431 
432  case Declaration: {
433  // FIXME: Include the type if it's not obvious from the context.
434  NamedDecl *ND = getAsDecl();
436  if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
437  TPO->printAsInit(Out);
438  break;
439  }
440  }
441  if (auto *VD = dyn_cast<ValueDecl>(ND)) {
442  if (needsAmpersandOnTemplateArg(getParamTypeForDecl(), VD->getType()))
443  Out << "&";
444  }
445  ND->printQualifiedName(Out);
446  break;
447  }
448 
449  case NullPtr:
450  // FIXME: Include the type if it's not obvious from the context.
451  Out << "nullptr";
452  break;
453 
454  case Template:
456  break;
457 
458  case TemplateExpansion:
459  getAsTemplateOrTemplatePattern().print(Out, Policy);
460  Out << "...";
461  break;
462 
463  case Integral:
464  printIntegral(*this, Out, Policy, IncludeType);
465  break;
466 
467  case Expression:
468  getAsExpr()->printPretty(Out, nullptr, Policy);
469  break;
470 
471  case Pack:
472  Out << "<";
473  bool First = true;
474  for (const auto &P : pack_elements()) {
475  if (First)
476  First = false;
477  else
478  Out << ", ";
479 
480  P.print(Policy, Out, IncludeType);
481  }
482  Out << ">";
483  break;
484  }
485 }
486 
487 void TemplateArgument::dump(raw_ostream &Out) const {
488  LangOptions LO; // FIXME! see also TemplateName::dump().
489  LO.CPlusPlus = true;
490  LO.Bool = true;
491  print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
492 }
493 
494 LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
495 
496 //===----------------------------------------------------------------------===//
497 // TemplateArgumentLoc Implementation
498 //===----------------------------------------------------------------------===//
499 
501  switch (Argument.getKind()) {
504 
507 
510 
512  if (TypeSourceInfo *TSI = getTypeSourceInfo())
513  return TSI->getTypeLoc().getSourceRange();
514  else
515  return SourceRange();
516 
519  return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
522 
525  return SourceRange(getTemplateQualifierLoc().getBeginLoc(),
528 
531 
534  return SourceRange();
535  }
536 
537  llvm_unreachable("Invalid TemplateArgument Kind!");
538 }
539 
540 template <typename T>
541 static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) {
542  switch (Arg.getKind()) {
544  // This is bad, but not as bad as crashing because of argument
545  // count mismatches.
546  return DB << "(null template argument)";
547 
549  return DB << Arg.getAsType();
550 
552  return DB << Arg.getAsDecl();
553 
555  return DB << "nullptr";
556 
558  return DB << toString(Arg.getAsIntegral(), 10);
559 
561  return DB << Arg.getAsTemplate();
562 
564  return DB << Arg.getAsTemplateOrTemplatePattern() << "...";
565 
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  SmallString<32> Str;
571  llvm::raw_svector_ostream OS(Str);
572  LangOptions LangOpts;
573  LangOpts.CPlusPlus = true;
574  PrintingPolicy Policy(LangOpts);
575  Arg.getAsExpr()->printPretty(OS, nullptr, Policy);
576  return DB << OS.str();
577  }
578 
579  case TemplateArgument::Pack: {
580  // FIXME: We're guessing at LangOptions!
581  SmallString<32> Str;
582  llvm::raw_svector_ostream OS(Str);
583  LangOptions LangOpts;
584  LangOpts.CPlusPlus = true;
585  PrintingPolicy Policy(LangOpts);
586  Arg.print(Policy, OS, /*IncludeType*/ true);
587  return DB << OS.str();
588  }
589  }
590 
591  llvm_unreachable("Invalid TemplateArgument Kind!");
592 }
593 
595  const TemplateArgument &Arg) {
596  return DiagTemplateArg(DB, Arg);
597 }
598 
600  ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
601  SourceLocation TemplateNameLoc, SourceLocation EllipsisLoc) {
602  TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
603  Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
604  Template->QualifierLocData = QualifierLoc.getOpaqueData();
605  Template->TemplateNameLoc = TemplateNameLoc;
606  Template->EllipsisLoc = EllipsisLoc;
607  Pointer = Template;
608 }
609 
612  const TemplateArgumentListInfo &List) {
613  std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size());
614  void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo));
615  return new (Mem) ASTTemplateArgumentListInfo(List);
616 }
617 
618 ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo(
619  const TemplateArgumentListInfo &Info) {
620  LAngleLoc = Info.getLAngleLoc();
621  RAngleLoc = Info.getRAngleLoc();
622  NumTemplateArgs = Info.size();
623 
624  TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>();
625  for (unsigned i = 0; i != NumTemplateArgs; ++i)
626  new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
627 }
628 
630  SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
631  TemplateArgumentLoc *OutArgArray) {
632  this->TemplateKWLoc = TemplateKWLoc;
633  LAngleLoc = Info.getLAngleLoc();
634  RAngleLoc = Info.getRAngleLoc();
635  NumTemplateArgs = Info.size();
636 
637  for (unsigned i = 0; i != NumTemplateArgs; ++i)
638  new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
639 }
640 
642  assert(TemplateKWLoc.isValid());
645  this->TemplateKWLoc = TemplateKWLoc;
646  NumTemplateArgs = 0;
647 }
648 
650  SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info,
651  TemplateArgumentLoc *OutArgArray, TemplateArgumentDependence &Deps) {
652  this->TemplateKWLoc = TemplateKWLoc;
653  LAngleLoc = Info.getLAngleLoc();
654  RAngleLoc = Info.getRAngleLoc();
655  NumTemplateArgs = Info.size();
656 
657  for (unsigned i = 0; i != NumTemplateArgs; ++i) {
658  Deps |= Info[i].getArgument().getDependence();
659 
660  new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]);
661  }
662 }
663 
665  TemplateArgumentListInfo &Info) const {
666  Info.setLAngleLoc(LAngleLoc);
667  Info.setRAngleLoc(RAngleLoc);
668  for (unsigned I = 0; I != NumTemplateArgs; ++I)
669  Info.addArgument(ArgArray[I]);
670 }
clang::BuiltinType
This class is used for builtin types like 'int'.
Definition: Type.h:2493
clang::TemplateName::Qualified::Fully
@ Fully
clang::CharacterLiteral::CharacterKind
CharacterKind
Definition: Expr.h:1580
type
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
clang::TemplateArgument::getDependence
TemplateArgumentDependence getDependence() const
Definition: TemplateBase.cpp:189
clang::TemplateArgument::getAsTemplateOrTemplatePattern
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:300
clang::ASTTemplateKWAndArgsInfo::RAngleLoc
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:665
clang::TemplateArgument::pack_elements
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:366
clang::TemplateArgument::Null
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:68
DependenceFlags.h
clang::TemplateArgumentLoc::getSourceExpression
Expr * getSourceExpression() const
Definition: TemplateBase.h:521
clang::Type::isCharType
bool isCharType() const
Definition: Type.cpp:1956
clang::TemplateArgumentLoc::getTemplateEllipsisLoc
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:555
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::ASTTemplateKWAndArgsInfo::TemplateKWLoc
SourceLocation TemplateKWLoc
The source location of the template keyword; this is used as part of the representation of qualified ...
Definition: TemplateBase.h:671
clang::TemplateArgument::TemplateArg
struct TA TemplateArg
Definition: TemplateBase.h:146
clang::TemplateArgument::Profile
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
Definition: TemplateBase.cpp:305
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::TemplateArgument::getIntegralType
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:327
clang::Type::isWideCharType
bool isWideCharType() const
Definition: Type.cpp:1965
needsAmpersandOnTemplateArg
static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType)
Definition: TemplateBase.cpp:146
clang::Stmt::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
clang::TemplateArgument::getParamTypeForDecl
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:281
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:54
clang::TemplateArgumentLocInfo::TemplateArgumentLocInfo
TemplateArgumentLocInfo()
Definition: TemplateBase.h:425
clang::TemplateArgumentListInfo::getRAngleLoc
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:581
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1549
clang::TemplateArgument::Declaration
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:75
llvm::Optional< unsigned >
clang::ComparisonCategoryType::First
@ First
clang::CharacterLiteral::UTF8
@ UTF8
Definition: Expr.h:1583
clang::QualType::getAsString
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1015
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:59
clang::ASTTemplateArgumentListInfo::NumTemplateArgs
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:630
clang::ASTTemplateKWAndArgsInfo::LAngleLoc
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:662
clang::TemplateArgument::getAsExpr
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:342
TemplateName.h
clang::TemplateArgumentLoc::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:515
clang::TemplateArgument::Expression
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:97
clang::TemplateArgument::getAsIntegral
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:313
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
Decl.h
clang::TemplateArgumentListInfo::getLAngleLoc
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:580
clang::TemplateArgument::Integral
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:83
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:102
PrettyPrinter.h
clang::TemplateArgument::TypeOrValue
struct TV TypeOrValue
Definition: TemplateBase.h:147
clang::toTemplateArgumentDependence
TemplateArgumentDependence toTemplateArgumentDependence(TypeDependence D)
Definition: DependenceFlags.h:279
APSInt
llvm::APSInt APSInt
Definition: ByteCodeEmitter.cpp:19
clang::TemplateArgument::NullPtr
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:79
clang::ASTContext::Allocate
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:708
clang::TemplateArgumentLoc::getSourceDeclExpression
Expr * getSourceDeclExpression() const
Definition: TemplateBase.h:526
TemplateBase.h
clang::TemplateArgument::getKind
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:245
DeclTemplate.h
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5632
clang::TemplateArgumentListInfo
A convenient class for passing around template argument information.
Definition: TemplateBase.h:564
clang::CharacterLiteral::Wide
@ Wide
Definition: Expr.h:1582
clang::Stmt::printPretty
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
Definition: StmtPrinter.cpp:2589
DeclBase.h
clang::TemplateArgumentListInfo::addArgument
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:604
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::Type::isAnyCharacterType
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1992
printIntegral
static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, const PrintingPolicy &Policy, bool IncludeType)
Print a template integral argument value.
Definition: TemplateBase.cpp:57
clang::TemplateArgument::getEmptyPack
static TemplateArgument getEmptyPack()
Definition: TemplateBase.h:237
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
clang::StreamingDiagnostic
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1108
LangOptions.h
Diagnostic.h
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7161
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:62
clang::Type::isChar8Type
bool isChar8Type() const
Definition: Type.cpp:1972
clang::ASTTemplateKWAndArgsInfo::initializeFrom
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
Definition: TemplateBase.cpp:629
clang::TemplateArgumentLoc
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:458
clang::TemplateArgumentLoc::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition: TemplateBase.cpp:500
Type.h
Expr.h
llvm::SmallString< 32 >
clang::TemplateTemplateParmDecl
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Definition: DeclTemplate.h:1601
clang::TemplateArgumentListInfo::setLAngleLoc
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:583
ASTContext.h
clang::PrintingPolicy::MSVCFormatting
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
Definition: PrettyPrinter.h:242
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::Type::getCanonicalTypeInternal
QualType getCanonicalTypeInternal() const
Definition: Type.h:2457
clang::TemplateArgument::CreatePackCopy
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
Definition: TemplateBase.cpp:181
clang::EnumConstantDecl
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3050
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:243
clang::Stmt::Profile
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
Definition: StmtProfile.cpp:2287
ExprCXX.h
clang::TemplateArgument::isPackExpansion
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Definition: TemplateBase.cpp:245
clang::operator<<
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
Definition: ASTContext.cpp:11777
clang::ast_matchers::arrayType
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
Definition: ASTMatchersInternal.cpp:1033
clang::TemplateArgument::getNonTypeTemplateArgumentType
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
Definition: TemplateBase.cpp:280
clang::CharacterLiteral::Ascii
@ Ascii
Definition: Expr.h:1581
clang::TemplateArgument::TemplateExpansion
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:91
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7226
clang::NestedNameSpecifierLoc::getOpaqueData
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
Definition: NestedNameSpecifier.h:279
SourceLocation.h
clang::TemplateName::getAsVoidPointer
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
Definition: TemplateName.h:336
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::CharacterLiteral::UTF16
@ UTF16
Definition: Expr.h:1584
clang::Type::isMemberPointerType
bool isMemberPointerType() const
Definition: Type.h:6720
clang::TemplateArgument::containsUnexpandedParameterPack
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
Definition: TemplateBase.cpp:268
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6672
clang::ASTTemplateArgumentListInfo::LAngleLoc
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:624
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:192
clang::TemplateArgument::Args
struct A Args
Definition: TemplateBase.h:145
getCanonicalDecl
static const Decl * getCanonicalDecl(const Decl *D)
Definition: IndexingContext.cpp:301
clang::TemplateArgumentListInfo::size
unsigned size() const
Definition: TemplateBase.h:586
clang::TemplateArgumentLoc::getSourceIntegralExpression
Expr * getSourceIntegralExpression() const
Definition: TemplateBase.h:536
clang::TemplateArgument::dump
void dump() const
Debugging aid that dumps the template argument to standard error.
Definition: TemplateBase.cpp:494
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
getArrayDepth
static unsigned getArrayDepth(QualType type)
Definition: TemplateBase.cpp:137
clang::TemplateArgument::getNumTemplateExpansions
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
Definition: TemplateBase.cpp:272
clang::TemplateArgument::isDependent
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
Definition: TemplateBase.cpp:237
LLVM.h
clang::TemplateArgument::isInstantiationDependent
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
Definition: TemplateBase.cpp:241
clang::PrintingPolicy::SuppressStrongLifetime
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
Definition: PrettyPrinter.h:178
clang::ASTContext::getCanonicalTemplateName
TemplateName getCanonicalTemplateName(TemplateName Name) const
Retrieves the "canonical" template name that refers to a given template.
Definition: ASTContext.cpp:6030
clang::TemplateArgument::TemplateArgument
constexpr TemplateArgument()
Construct an empty, invalid template argument.
Definition: TemplateBase.h:152
clang::TemplateArgumentLoc::getSourceNullPtrExpression
Expr * getSourceNullPtrExpression() const
Definition: TemplateBase.h:531
DiagTemplateArg
static const T & DiagTemplateArg(const T &DB, const TemplateArgument &Arg)
Definition: TemplateBase.cpp:541
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::Type::isBooleanType
bool isBooleanType() const
Definition: Type.h:7071
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::ASTTemplateKWAndArgsInfo::copyInto
void copyInto(const TemplateArgumentLoc *ArgArray, TemplateArgumentListInfo &List) const
Definition: TemplateBase.cpp:664
clang::TemplateArgument::getAsDecl
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:276
isRecordType
static bool isRecordType(QualType T)
Definition: SemaExprMember.cpp:1213
clang::TemplateArgument::print
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
Definition: TemplateBase.cpp:417
clang::TemplateName::print
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
Definition: TemplateName.cpp:223
clang::QualType::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1081
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang::TemplateArgument::Type
@ Type
The template argument is a type.
Definition: TemplateBase.h:71
clang
Definition: CalledOnceCheck.h:17
clang::TemplateArgumentListInfo::setRAngleLoc
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:584
clang::TemplateArgument::getPackExpansionPattern
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
Definition: TemplateBase.cpp:392
clang::Type::isArrayType
bool isArrayType() const
Definition: Type.h:6738
clang::CharacterLiteral::UTF32
@ UTF32
Definition: Expr.h:1585
clang::TemplateArgument::getNullPtrType
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:287
clang::TemplateArgument::Template
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:87
clang::TemplateArgument::getAsTemplate
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:293
clang::NestedNameSpecifierLoc::getNestedNameSpecifier
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Definition: NestedNameSpecifier.h:274
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:112
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6395
clang::ASTTemplateArgumentListInfo::Create
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Definition: TemplateBase.cpp:611
clang::ASTTemplateKWAndArgsInfo::NumTemplateArgs
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:674
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6424
clang::QualType::print
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: TypePrinter.cpp:2248
GCCTypeClass::Pointer
@ Pointer
clang::ASTTemplateArgumentListInfo
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:613
clang::TemplateArgumentLoc::getTemplateQualifierLoc
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:541
clang::Type::isSpecificBuiltinType
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:6924
clang::TemplateArgumentLoc::getTemplateNameLoc
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:548
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4639
clang::NamedDecl::printQualifiedName
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
Definition: Decl.cpp:1589
clang::Type::isChar16Type
bool isChar16Type() const
Definition: Type.cpp:1978
GCCTypeClass::None
@ None
clang::ASTTemplateArgumentListInfo::RAngleLoc
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:627
clang::TemplateArgument::Integer
struct I Integer
Definition: TemplateBase.h:144
clang::Type::isChar32Type
bool isChar32Type() const
Definition: Type.cpp:1984
clang::TemplateArgument::structurallyEquals
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
Definition: TemplateBase.cpp:359
TypeLoc.h
clang::TemplateArgument::getAsType
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:269
clang::CharacterLiteral::print
static void print(unsigned val, CharacterKind Kind, raw_ostream &OS)
Definition: Expr.cpp:928
clang::TemplateArgument::Pack
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:101
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:439