clang  10.0.0svn
ExprCXX.cpp
Go to the documentation of this file.
1 //===- ExprCXX.cpp - (C++) Expression AST Node 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 the subclesses of Expr class declared in ExprCXX.h
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/ExprCXX.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/DeclCXX.h"
21 #include "clang/AST/Expr.h"
24 #include "clang/AST/TemplateBase.h"
25 #include "clang/AST/Type.h"
26 #include "clang/AST/TypeLoc.h"
27 #include "clang/Basic/LLVM.h"
30 #include "clang/Basic/Specifiers.h"
31 #include "llvm/ADT/ArrayRef.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include <cassert>
35 #include <cstddef>
36 #include <cstring>
37 #include <memory>
38 
39 using namespace clang;
40 
41 //===----------------------------------------------------------------------===//
42 // Child Iterators for iterating over subexpressions/substatements
43 //===----------------------------------------------------------------------===//
44 
46  // An infix binary operator is any operator with two arguments other than
47  // operator() and operator[]. Note that none of these operators can have
48  // default arguments, so it suffices to check the number of argument
49  // expressions.
50  if (getNumArgs() != 2)
51  return false;
52 
53  switch (getOperator()) {
54  case OO_Call: case OO_Subscript:
55  return false;
56  default:
57  return true;
58  }
59 }
60 
64  const Expr *E = getSemanticForm()->IgnoreImplicit();
65 
66  // Remove an outer '!' if it exists (only happens for a '!=' rewrite).
67  bool SkippedNot = false;
68  if (auto *NotEq = dyn_cast<UnaryOperator>(E)) {
69  assert(NotEq->getOpcode() == UO_LNot);
70  E = NotEq->getSubExpr()->IgnoreImplicit();
71  SkippedNot = true;
72  }
73 
74  // Decompose the outer binary operator.
75  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
76  assert(!SkippedNot || BO->getOpcode() == BO_EQ);
77  Result.Opcode = SkippedNot ? BO_NE : BO->getOpcode();
78  Result.LHS = BO->getLHS();
79  Result.RHS = BO->getRHS();
80  Result.InnerBinOp = BO;
81  } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
82  assert(!SkippedNot || BO->getOperator() == OO_EqualEqual);
83  assert(BO->isInfixBinaryOp());
84  switch (BO->getOperator()) {
85  case OO_Less: Result.Opcode = BO_LT; break;
86  case OO_LessEqual: Result.Opcode = BO_LE; break;
87  case OO_Greater: Result.Opcode = BO_GT; break;
88  case OO_GreaterEqual: Result.Opcode = BO_GE; break;
89  case OO_Spaceship: Result.Opcode = BO_Cmp; break;
90  case OO_EqualEqual: Result.Opcode = SkippedNot ? BO_NE : BO_EQ; break;
91  default: llvm_unreachable("unexpected binop in rewritten operator expr");
92  }
93  Result.LHS = BO->getArg(0);
94  Result.RHS = BO->getArg(1);
95  Result.InnerBinOp = BO;
96  } else {
97  llvm_unreachable("unexpected rewritten operator form");
98  }
99 
100  // Put the operands in the right order for == and !=, and canonicalize the
101  // <=> subexpression onto the LHS for all other forms.
102  if (isReversed())
103  std::swap(Result.LHS, Result.RHS);
104 
105  // If this isn't a spaceship rewrite, we're done.
106  if (Result.Opcode == BO_EQ || Result.Opcode == BO_NE)
107  return Result;
108 
109  // Otherwise, we expect a <=> to now be on the LHS.
110  E = Result.LHS->IgnoreImplicit();
111  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
112  assert(BO->getOpcode() == BO_Cmp);
113  Result.LHS = BO->getLHS();
114  Result.RHS = BO->getRHS();
115  Result.InnerBinOp = BO;
116  } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
117  assert(BO->getOperator() == OO_Spaceship);
118  Result.LHS = BO->getArg(0);
119  Result.RHS = BO->getArg(1);
120  Result.InnerBinOp = BO;
121  } else {
122  llvm_unreachable("unexpected rewritten operator form");
123  }
124 
125  // Put the comparison operands in the right order.
126  if (isReversed())
127  std::swap(Result.LHS, Result.RHS);
128  return Result;
129 }
130 
132  if (isTypeOperand())
133  return false;
134 
135  // C++11 [expr.typeid]p3:
136  // When typeid is applied to an expression other than a glvalue of
137  // polymorphic class type, [...] the expression is an unevaluated operand.
138  const Expr *E = getExprOperand();
139  if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
140  if (RD->isPolymorphic() && E->isGLValue())
141  return true;
142 
143  return false;
144 }
145 
147  assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
148  Qualifiers Quals;
149  return Context.getUnqualifiedArrayType(
150  Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
151 }
152 
154  assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
155  Qualifiers Quals;
156  return Context.getUnqualifiedArrayType(
157  Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
158 }
159 
160 // CXXScalarValueInitExpr
162  return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc();
163 }
164 
165 // CXXNewExpr
166 CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
167  FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
168  bool UsualArrayDeleteWantsSize,
169  ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
170  Optional<Expr *> ArraySize,
171  InitializationStyle InitializationStyle,
173  TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
174  SourceRange DirectInitRange)
175  : Expr(CXXNewExprClass, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(),
178  OperatorNew(OperatorNew), OperatorDelete(OperatorDelete),
179  AllocatedTypeInfo(AllocatedTypeInfo), Range(Range),
180  DirectInitRange(DirectInitRange) {
181 
182  assert((Initializer != nullptr || InitializationStyle == NoInit) &&
183  "Only NoInit can have no initializer!");
184 
185  CXXNewExprBits.IsGlobalNew = IsGlobalNew;
186  CXXNewExprBits.IsArray = ArraySize.hasValue();
187  CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment;
188  CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
189  CXXNewExprBits.StoredInitializationStyle =
190  Initializer ? InitializationStyle + 1 : 0;
191  bool IsParenTypeId = TypeIdParens.isValid();
192  CXXNewExprBits.IsParenTypeId = IsParenTypeId;
193  CXXNewExprBits.NumPlacementArgs = PlacementArgs.size();
194 
195  if (ArraySize) {
196  if (Expr *SizeExpr = *ArraySize) {
197  if (SizeExpr->isValueDependent())
198  ExprBits.ValueDependent = true;
199  if (SizeExpr->isInstantiationDependent())
200  ExprBits.InstantiationDependent = true;
201  if (SizeExpr->containsUnexpandedParameterPack())
202  ExprBits.ContainsUnexpandedParameterPack = true;
203  }
204 
205  getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
206  }
207 
208  if (Initializer) {
209  if (Initializer->isValueDependent())
210  ExprBits.ValueDependent = true;
211  if (Initializer->isInstantiationDependent())
212  ExprBits.InstantiationDependent = true;
213  if (Initializer->containsUnexpandedParameterPack())
214  ExprBits.ContainsUnexpandedParameterPack = true;
215 
216  getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
217  }
218 
219  for (unsigned I = 0; I != PlacementArgs.size(); ++I) {
220  if (PlacementArgs[I]->isValueDependent())
221  ExprBits.ValueDependent = true;
222  if (PlacementArgs[I]->isInstantiationDependent())
223  ExprBits.InstantiationDependent = true;
224  if (PlacementArgs[I]->containsUnexpandedParameterPack())
225  ExprBits.ContainsUnexpandedParameterPack = true;
226 
227  getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
228  PlacementArgs[I];
229  }
230 
231  if (IsParenTypeId)
232  getTrailingObjects<SourceRange>()[0] = TypeIdParens;
233 
234  switch (getInitializationStyle()) {
235  case CallInit:
236  this->Range.setEnd(DirectInitRange.getEnd());
237  break;
238  case ListInit:
239  this->Range.setEnd(getInitializer()->getSourceRange().getEnd());
240  break;
241  default:
242  if (IsParenTypeId)
243  this->Range.setEnd(TypeIdParens.getEnd());
244  break;
245  }
246 }
247 
248 CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray,
249  unsigned NumPlacementArgs, bool IsParenTypeId)
250  : Expr(CXXNewExprClass, Empty) {
251  CXXNewExprBits.IsArray = IsArray;
252  CXXNewExprBits.NumPlacementArgs = NumPlacementArgs;
253  CXXNewExprBits.IsParenTypeId = IsParenTypeId;
254 }
255 
256 CXXNewExpr *
257 CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew,
258  FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete,
259  bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize,
260  ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
261  Optional<Expr *> ArraySize,
263  QualType Ty, TypeSourceInfo *AllocatedTypeInfo,
264  SourceRange Range, SourceRange DirectInitRange) {
265  bool IsArray = ArraySize.hasValue();
266  bool HasInit = Initializer != nullptr;
267  unsigned NumPlacementArgs = PlacementArgs.size();
268  bool IsParenTypeId = TypeIdParens.isValid();
269  void *Mem =
270  Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
271  IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
272  alignof(CXXNewExpr));
273  return new (Mem)
274  CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment,
275  UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
276  ArraySize, InitializationStyle, Initializer, Ty,
277  AllocatedTypeInfo, Range, DirectInitRange);
278 }
279 
281  bool HasInit, unsigned NumPlacementArgs,
282  bool IsParenTypeId) {
283  void *Mem =
284  Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
285  IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
286  alignof(CXXNewExpr));
287  return new (Mem)
288  CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId);
289 }
290 
292  return getOperatorNew()
293  ->getType()
294  ->castAs<FunctionProtoType>()
295  ->isNothrow() &&
296  !getOperatorNew()->isReservedGlobalPlacementOperator();
297 }
298 
299 // CXXDeleteExpr
301  const Expr *Arg = getArgument();
302 
303  // For a destroying operator delete, we may have implicitly converted the
304  // pointer type to the type of the parameter of the 'operator delete'
305  // function.
306  while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
307  if (ICE->getCastKind() == CK_DerivedToBase ||
308  ICE->getCastKind() == CK_UncheckedDerivedToBase ||
309  ICE->getCastKind() == CK_NoOp) {
310  assert((ICE->getCastKind() == CK_NoOp ||
311  getOperatorDelete()->isDestroyingOperatorDelete()) &&
312  "only a destroying operator delete can have a converted arg");
313  Arg = ICE->getSubExpr();
314  } else
315  break;
316  }
317 
318  // The type-to-delete may not be a pointer if it's a dependent type.
319  const QualType ArgType = Arg->getType();
320 
321  if (ArgType->isDependentType() && !ArgType->isPointerType())
322  return QualType();
323 
324  return ArgType->castAs<PointerType>()->getPointeeType();
325 }
326 
327 // CXXPseudoDestructorExpr
329  : Type(Info) {
330  Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
331 }
332 
334  Expr *Base, bool isArrow, SourceLocation OperatorLoc,
335  NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
336  SourceLocation ColonColonLoc, SourceLocation TildeLoc,
337  PseudoDestructorTypeStorage DestroyedType)
338  : Expr(CXXPseudoDestructorExprClass,
339  Context.BoundMemberTy,
341  /*isTypeDependent=*/(Base->isTypeDependent() ||
342  (DestroyedType.getTypeSourceInfo() &&
343  DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
344  /*isValueDependent=*/Base->isValueDependent(),
345  (Base->isInstantiationDependent() ||
346  (QualifierLoc &&
347  QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
348  (ScopeType &&
349  ScopeType->getType()->isInstantiationDependentType()) ||
350  (DestroyedType.getTypeSourceInfo() &&
351  DestroyedType.getTypeSourceInfo()->getType()
352  ->isInstantiationDependentType())),
353  // ContainsUnexpandedParameterPack
354  (Base->containsUnexpandedParameterPack() ||
355  (QualifierLoc &&
356  QualifierLoc.getNestedNameSpecifier()
357  ->containsUnexpandedParameterPack()) ||
358  (ScopeType &&
359  ScopeType->getType()->containsUnexpandedParameterPack()) ||
360  (DestroyedType.getTypeSourceInfo() &&
361  DestroyedType.getTypeSourceInfo()->getType()
362  ->containsUnexpandedParameterPack()))),
363  Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
364  OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
365  ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
366  DestroyedType(DestroyedType) {}
367 
369  if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
370  return TInfo->getType();
371 
372  return QualType();
373 }
374 
376  SourceLocation End = DestroyedType.getLocation();
377  if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
378  End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
379  return End;
380 }
381 
382 // UnresolvedLookupExpr
383 UnresolvedLookupExpr::UnresolvedLookupExpr(
384  const ASTContext &Context, CXXRecordDecl *NamingClass,
385  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
386  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
389  : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
390  TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
391  false, false),
392  NamingClass(NamingClass) {
393  UnresolvedLookupExprBits.RequiresADL = RequiresADL;
394  UnresolvedLookupExprBits.Overloaded = Overloaded;
395 }
396 
397 UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty,
398  unsigned NumResults,
399  bool HasTemplateKWAndArgsInfo)
400  : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults,
401  HasTemplateKWAndArgsInfo) {}
402 
404  const ASTContext &Context, CXXRecordDecl *NamingClass,
405  NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
406  bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin,
407  UnresolvedSetIterator End) {
408  unsigned NumResults = End - Begin;
409  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
410  TemplateArgumentLoc>(NumResults, 0, 0);
411  void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
412  return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
413  SourceLocation(), NameInfo, RequiresADL,
414  Overloaded, nullptr, Begin, End);
415 }
416 
418  const ASTContext &Context, CXXRecordDecl *NamingClass,
419  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
420  const DeclarationNameInfo &NameInfo, bool RequiresADL,
422  UnresolvedSetIterator End) {
423  assert(Args || TemplateKWLoc.isValid());
424  unsigned NumResults = End - Begin;
425  unsigned NumTemplateArgs = Args ? Args->size() : 0;
426  unsigned Size =
427  totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
428  TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs);
429  void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
430  return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
431  TemplateKWLoc, NameInfo, RequiresADL,
432  /*Overloaded*/ true, Args, Begin, End);
433 }
434 
436  const ASTContext &Context, unsigned NumResults,
437  bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
438  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
439  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
441  NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
442  void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
443  return new (Mem)
444  UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
445 }
446 
448  NestedNameSpecifierLoc QualifierLoc,
449  SourceLocation TemplateKWLoc,
450  const DeclarationNameInfo &NameInfo,
451  const TemplateArgumentListInfo *TemplateArgs,
452  UnresolvedSetIterator Begin,
453  UnresolvedSetIterator End, bool KnownDependent,
454  bool KnownInstantiationDependent,
455  bool KnownContainsUnexpandedParameterPack)
456  : Expr(
457  SC, Context.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
458  KnownDependent,
459  (KnownInstantiationDependent || NameInfo.isInstantiationDependent() ||
460  (QualifierLoc &&
461  QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
462  (KnownContainsUnexpandedParameterPack ||
463  NameInfo.containsUnexpandedParameterPack() ||
464  (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
466  NameInfo(NameInfo), QualifierLoc(QualifierLoc) {
467  unsigned NumResults = End - Begin;
468  OverloadExprBits.NumResults = NumResults;
469  OverloadExprBits.HasTemplateKWAndArgsInfo =
470  (TemplateArgs != nullptr ) || TemplateKWLoc.isValid();
471 
472  if (NumResults) {
473  // Determine whether this expression is type-dependent.
474  for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
475  if ((*I)->getDeclContext()->isDependentContext() ||
476  isa<UnresolvedUsingValueDecl>(*I)) {
477  ExprBits.TypeDependent = true;
478  ExprBits.ValueDependent = true;
479  ExprBits.InstantiationDependent = true;
480  }
481  }
482 
483  // Copy the results to the trailing array past UnresolvedLookupExpr
484  // or UnresolvedMemberExpr.
485  DeclAccessPair *Results = getTrailingResults();
486  memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
487  }
488 
489  // If we have explicit template arguments, check for dependent
490  // template arguments and whether they contain any unexpanded pack
491  // expansions.
492  if (TemplateArgs) {
493  bool Dependent = false;
494  bool InstantiationDependent = false;
495  bool ContainsUnexpandedParameterPack = false;
497  TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(),
498  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
499 
500  if (Dependent) {
501  ExprBits.TypeDependent = true;
502  ExprBits.ValueDependent = true;
503  }
504  if (InstantiationDependent)
505  ExprBits.InstantiationDependent = true;
506  if (ContainsUnexpandedParameterPack)
507  ExprBits.ContainsUnexpandedParameterPack = true;
508  } else if (TemplateKWLoc.isValid()) {
510  }
511 
512  if (isTypeDependent())
513  setType(Context.DependentTy);
514 }
515 
516 OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
517  bool HasTemplateKWAndArgsInfo)
518  : Expr(SC, Empty) {
519  OverloadExprBits.NumResults = NumResults;
520  OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
521 }
522 
523 // DependentScopeDeclRefExpr
524 DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(
525  QualType Ty, NestedNameSpecifierLoc QualifierLoc,
526  SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
527  const TemplateArgumentListInfo *Args)
528  : Expr(
529  DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary, true,
530  true,
531  (NameInfo.isInstantiationDependent() ||
532  (QualifierLoc &&
534  (NameInfo.containsUnexpandedParameterPack() ||
535  (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
537  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {
538  DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
539  (Args != nullptr) || TemplateKWLoc.isValid();
540  if (Args) {
541  bool Dependent = true;
542  bool InstantiationDependent = true;
543  bool ContainsUnexpandedParameterPack
544  = ExprBits.ContainsUnexpandedParameterPack;
545  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
546  TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(),
547  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
548  ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
549  } else if (TemplateKWLoc.isValid()) {
550  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
551  TemplateKWLoc);
552  }
553 }
554 
556  const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
557  SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
558  const TemplateArgumentListInfo *Args) {
559  assert(QualifierLoc && "should be created for dependent qualifiers");
560  bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
561  std::size_t Size =
562  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
563  HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
564  void *Mem = Context.Allocate(Size);
565  return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc,
566  TemplateKWLoc, NameInfo, Args);
567 }
568 
571  bool HasTemplateKWAndArgsInfo,
572  unsigned NumTemplateArgs) {
573  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
574  std::size_t Size =
575  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
576  HasTemplateKWAndArgsInfo, NumTemplateArgs);
577  void *Mem = Context.Allocate(Size);
578  auto *E = new (Mem) DependentScopeDeclRefExpr(
580  DeclarationNameInfo(), nullptr);
581  E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
582  HasTemplateKWAndArgsInfo;
583  return E;
584 }
585 
587  if (isa<CXXTemporaryObjectExpr>(this))
588  return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc();
589  return getLocation();
590 }
591 
593  if (isa<CXXTemporaryObjectExpr>(this))
594  return cast<CXXTemporaryObjectExpr>(this)->getEndLoc();
595 
596  if (ParenOrBraceRange.isValid())
597  return ParenOrBraceRange.getEnd();
598 
599  SourceLocation End = getLocation();
600  for (unsigned I = getNumArgs(); I > 0; --I) {
601  const Expr *Arg = getArg(I-1);
602  if (!Arg->isDefaultArgument()) {
603  SourceLocation NewEnd = Arg->getEndLoc();
604  if (NewEnd.isValid()) {
605  End = NewEnd;
606  break;
607  }
608  }
609  }
610 
611  return End;
612 }
613 
614 CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
615  Expr *Fn, ArrayRef<Expr *> Args,
616  QualType Ty, ExprValueKind VK,
617  SourceLocation OperatorLoc,
618  FPOptions FPFeatures,
619  ADLCallKind UsesADL)
620  : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
621  OperatorLoc, /*MinNumArgs=*/0, UsesADL) {
622  CXXOperatorCallExprBits.OperatorKind = OpKind;
623  CXXOperatorCallExprBits.FPFeatures = FPFeatures.getInt();
624  assert(
625  (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
626  "OperatorKind overflow!");
627  assert((CXXOperatorCallExprBits.FPFeatures == FPFeatures.getInt()) &&
628  "FPFeatures overflow!");
629  Range = getSourceRangeImpl();
630 }
631 
632 CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty)
633  : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
634 
636  const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
638  SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL) {
639  // Allocate storage for the trailing objects of CallExpr.
640  unsigned NumArgs = Args.size();
641  unsigned SizeOfTrailingObjects =
642  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
643  void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
644  alignof(CXXOperatorCallExpr));
645  return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc,
646  FPFeatures, UsesADL);
647 }
648 
650  unsigned NumArgs,
651  EmptyShell Empty) {
652  // Allocate storage for the trailing objects of CallExpr.
653  unsigned SizeOfTrailingObjects =
654  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
655  void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
656  alignof(CXXOperatorCallExpr));
657  return new (Mem) CXXOperatorCallExpr(NumArgs, Empty);
658 }
659 
660 SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
661  OverloadedOperatorKind Kind = getOperator();
662  if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
663  if (getNumArgs() == 1)
664  // Prefix operator
665  return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
666  else
667  // Postfix operator
668  return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
669  } else if (Kind == OO_Arrow) {
670  return getArg(0)->getSourceRange();
671  } else if (Kind == OO_Call) {
672  return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
673  } else if (Kind == OO_Subscript) {
674  return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
675  } else if (getNumArgs() == 1) {
676  return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
677  } else if (getNumArgs() == 2) {
678  return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc());
679  } else {
680  return getOperatorLoc();
681  }
682 }
683 
684 CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args,
685  QualType Ty, ExprValueKind VK,
686  SourceLocation RP, unsigned MinNumArgs)
687  : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP,
688  MinNumArgs, NotADL) {}
689 
690 CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty)
691  : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
692 
694  ArrayRef<Expr *> Args, QualType Ty,
695  ExprValueKind VK,
696  SourceLocation RP,
697  unsigned MinNumArgs) {
698  // Allocate storage for the trailing objects of CallExpr.
699  unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
700  unsigned SizeOfTrailingObjects =
701  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
702  void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
703  alignof(CXXMemberCallExpr));
704  return new (Mem) CXXMemberCallExpr(Fn, Args, Ty, VK, RP, MinNumArgs);
705 }
706 
708  unsigned NumArgs,
709  EmptyShell Empty) {
710  // Allocate storage for the trailing objects of CallExpr.
711  unsigned SizeOfTrailingObjects =
712  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
713  void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
714  alignof(CXXMemberCallExpr));
715  return new (Mem) CXXMemberCallExpr(NumArgs, Empty);
716 }
717 
719  const Expr *Callee = getCallee()->IgnoreParens();
720  if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
721  return MemExpr->getBase();
722  if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
723  if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
724  return BO->getLHS();
725 
726  // FIXME: Will eventually need to cope with member pointers.
727  return nullptr;
728 }
729 
731  QualType Ty = getImplicitObjectArgument()->getType();
732  if (Ty->isPointerType())
733  Ty = Ty->getPointeeType();
734  return Ty;
735 }
736 
738  if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
739  return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
740 
741  // FIXME: Will eventually need to cope with member pointers.
742  return nullptr;
743 }
744 
746  Expr* ThisArg = getImplicitObjectArgument();
747  if (!ThisArg)
748  return nullptr;
749 
750  if (ThisArg->getType()->isAnyPointerType())
751  return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
752 
753  return ThisArg->getType()->getAsCXXRecordDecl();
754 }
755 
756 //===----------------------------------------------------------------------===//
757 // Named casts
758 //===----------------------------------------------------------------------===//
759 
760 /// getCastName - Get the name of the C++ cast being used, e.g.,
761 /// "static_cast", "dynamic_cast", "reinterpret_cast", or
762 /// "const_cast". The returned pointer must not be freed.
763 const char *CXXNamedCastExpr::getCastName() const {
764  switch (getStmtClass()) {
765  case CXXStaticCastExprClass: return "static_cast";
766  case CXXDynamicCastExprClass: return "dynamic_cast";
767  case CXXReinterpretCastExprClass: return "reinterpret_cast";
768  case CXXConstCastExprClass: return "const_cast";
769  default: return "<invalid cast>";
770  }
771 }
772 
774  ExprValueKind VK,
775  CastKind K, Expr *Op,
776  const CXXCastPath *BasePath,
777  TypeSourceInfo *WrittenTy,
778  SourceLocation L,
779  SourceLocation RParenLoc,
780  SourceRange AngleBrackets) {
781  unsigned PathSize = (BasePath ? BasePath->size() : 0);
782  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
783  auto *E =
784  new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
785  RParenLoc, AngleBrackets);
786  if (PathSize)
787  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
788  E->getTrailingObjects<CXXBaseSpecifier *>());
789  return E;
790 }
791 
793  unsigned PathSize) {
794  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
795  return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
796 }
797 
799  ExprValueKind VK,
800  CastKind K, Expr *Op,
801  const CXXCastPath *BasePath,
802  TypeSourceInfo *WrittenTy,
803  SourceLocation L,
804  SourceLocation RParenLoc,
805  SourceRange AngleBrackets) {
806  unsigned PathSize = (BasePath ? BasePath->size() : 0);
807  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
808  auto *E =
809  new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
810  RParenLoc, AngleBrackets);
811  if (PathSize)
812  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
813  E->getTrailingObjects<CXXBaseSpecifier *>());
814  return E;
815 }
816 
818  unsigned PathSize) {
819  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
820  return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
821 }
822 
823 /// isAlwaysNull - Return whether the result of the dynamic_cast is proven
824 /// to always be null. For example:
825 ///
826 /// struct A { };
827 /// struct B final : A { };
828 /// struct C { };
829 ///
830 /// C *f(B* b) { return dynamic_cast<C*>(b); }
832 {
833  QualType SrcType = getSubExpr()->getType();
834  QualType DestType = getType();
835 
836  if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
837  SrcType = SrcPTy->getPointeeType();
838  DestType = DestType->castAs<PointerType>()->getPointeeType();
839  }
840 
841  if (DestType->isVoidType())
842  return false;
843 
844  const auto *SrcRD =
845  cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
846 
847  if (!SrcRD->hasAttr<FinalAttr>())
848  return false;
849 
850  const auto *DestRD =
851  cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
852 
853  return !DestRD->isDerivedFrom(SrcRD);
854 }
855 
858  ExprValueKind VK, CastKind K, Expr *Op,
859  const CXXCastPath *BasePath,
860  TypeSourceInfo *WrittenTy, SourceLocation L,
861  SourceLocation RParenLoc,
862  SourceRange AngleBrackets) {
863  unsigned PathSize = (BasePath ? BasePath->size() : 0);
864  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
865  auto *E =
866  new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
867  RParenLoc, AngleBrackets);
868  if (PathSize)
869  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
870  E->getTrailingObjects<CXXBaseSpecifier *>());
871  return E;
872 }
873 
876  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
877  return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
878 }
879 
881  ExprValueKind VK, Expr *Op,
882  TypeSourceInfo *WrittenTy,
883  SourceLocation L,
884  SourceLocation RParenLoc,
885  SourceRange AngleBrackets) {
886  return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
887 }
888 
890  return new (C) CXXConstCastExpr(EmptyShell());
891 }
892 
895  TypeSourceInfo *Written, CastKind K, Expr *Op,
896  const CXXCastPath *BasePath,
898  unsigned PathSize = (BasePath ? BasePath->size() : 0);
899  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
900  auto *E =
901  new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
902  if (PathSize)
903  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
904  E->getTrailingObjects<CXXBaseSpecifier *>());
905  return E;
906 }
907 
909 CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
910  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
911  return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
912 }
913 
915  return getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
916 }
917 
919  return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc();
920 }
921 
922 UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args,
923  QualType Ty, ExprValueKind VK,
924  SourceLocation LitEndLoc,
925  SourceLocation SuffixLoc)
926  : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
927  LitEndLoc, /*MinNumArgs=*/0, NotADL),
928  UDSuffixLoc(SuffixLoc) {}
929 
930 UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty)
931  : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
932 
934  ArrayRef<Expr *> Args,
935  QualType Ty, ExprValueKind VK,
936  SourceLocation LitEndLoc,
937  SourceLocation SuffixLoc) {
938  // Allocate storage for the trailing objects of CallExpr.
939  unsigned NumArgs = Args.size();
940  unsigned SizeOfTrailingObjects =
941  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
942  void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
943  alignof(UserDefinedLiteral));
944  return new (Mem) UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc);
945 }
946 
948  unsigned NumArgs,
949  EmptyShell Empty) {
950  // Allocate storage for the trailing objects of CallExpr.
951  unsigned SizeOfTrailingObjects =
952  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
953  void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
954  alignof(UserDefinedLiteral));
955  return new (Mem) UserDefinedLiteral(NumArgs, Empty);
956 }
957 
960  if (getNumArgs() == 0)
961  return LOK_Template;
962  if (getNumArgs() == 2)
963  return LOK_String;
964 
965  assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
966  QualType ParamTy =
967  cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
968  if (ParamTy->isPointerType())
969  return LOK_Raw;
970  if (ParamTy->isAnyCharacterType())
971  return LOK_Character;
972  if (ParamTy->isIntegerType())
973  return LOK_Integer;
974  if (ParamTy->isFloatingType())
975  return LOK_Floating;
976 
977  llvm_unreachable("unknown kind of literal operator");
978 }
979 
981 #ifndef NDEBUG
982  LiteralOperatorKind LOK = getLiteralOperatorKind();
983  assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
984 #endif
985  return getArg(0);
986 }
987 
989  return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
990 }
991 
992 CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
993  FieldDecl *Field, QualType Ty,
994  DeclContext *UsedContext)
995  : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx),
997  ? VK_XValue
998  : VK_RValue,
999  /*FIXME*/ OK_Ordinary, false, false, false, false),
1000  Field(Field), UsedContext(UsedContext) {
1001  CXXDefaultInitExprBits.Loc = Loc;
1002  assert(Field->hasInClassInitializer());
1003 }
1004 
1006  const CXXDestructorDecl *Destructor) {
1007  return new (C) CXXTemporary(Destructor);
1008 }
1009 
1011  CXXTemporary *Temp,
1012  Expr* SubExpr) {
1013  assert((SubExpr->getType()->isRecordType() ||
1014  SubExpr->getType()->isArrayType()) &&
1015  "Expression bound to a temporary must have record or array type!");
1016 
1017  return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
1018 }
1019 
1020 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(
1021  CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI,
1022  ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
1023  bool HadMultipleCandidates, bool ListInitialization,
1024  bool StdInitListInitialization, bool ZeroInitialization)
1025  : CXXConstructExpr(
1026  CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(),
1027  Cons, /* Elidable=*/false, Args, HadMultipleCandidates,
1028  ListInitialization, StdInitListInitialization, ZeroInitialization,
1029  CXXConstructExpr::CK_Complete, ParenOrBraceRange),
1030  TSI(TSI) {}
1031 
1032 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty,
1033  unsigned NumArgs)
1034  : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {}
1035 
1037  const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
1038  TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
1039  bool HadMultipleCandidates, bool ListInitialization,
1040  bool StdInitListInitialization, bool ZeroInitialization) {
1041  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1042  void *Mem =
1043  Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
1044  alignof(CXXTemporaryObjectExpr));
1045  return new (Mem) CXXTemporaryObjectExpr(
1046  Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates,
1047  ListInitialization, StdInitListInitialization, ZeroInitialization);
1048 }
1049 
1051 CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) {
1052  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1053  void *Mem =
1054  Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
1055  alignof(CXXTemporaryObjectExpr));
1056  return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs);
1057 }
1058 
1060  return getTypeSourceInfo()->getTypeLoc().getBeginLoc();
1061 }
1062 
1064  SourceLocation Loc = getParenOrBraceRange().getEnd();
1065  if (Loc.isInvalid() && getNumArgs())
1066  Loc = getArg(getNumArgs() - 1)->getEndLoc();
1067  return Loc;
1068 }
1069 
1071  const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
1072  CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
1073  bool HadMultipleCandidates, bool ListInitialization,
1074  bool StdInitListInitialization, bool ZeroInitialization,
1075  ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) {
1076  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1077  void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1078  alignof(CXXConstructExpr));
1079  return new (Mem) CXXConstructExpr(
1080  CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args,
1081  HadMultipleCandidates, ListInitialization, StdInitListInitialization,
1082  ZeroInitialization, ConstructKind, ParenOrBraceRange);
1083 }
1084 
1086  unsigned NumArgs) {
1087  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1088  void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1089  alignof(CXXConstructExpr));
1090  return new (Mem)
1091  CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs);
1092 }
1093 
1096  bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1097  bool ListInitialization, bool StdInitListInitialization,
1098  bool ZeroInitialization, ConstructionKind ConstructKind,
1099  SourceRange ParenOrBraceRange)
1100  : Expr(SC, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(),
1101  Ty->isDependentType(), Ty->isInstantiationDependentType(),
1103  Constructor(Ctor), ParenOrBraceRange(ParenOrBraceRange),
1104  NumArgs(Args.size()) {
1105  CXXConstructExprBits.Elidable = Elidable;
1106  CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates;
1107  CXXConstructExprBits.ListInitialization = ListInitialization;
1108  CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization;
1109  CXXConstructExprBits.ZeroInitialization = ZeroInitialization;
1110  CXXConstructExprBits.ConstructionKind = ConstructKind;
1111  CXXConstructExprBits.Loc = Loc;
1112 
1113  Stmt **TrailingArgs = getTrailingArgs();
1114  for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1115  assert(Args[I] && "NULL argument in CXXConstructExpr!");
1116 
1117  if (Args[I]->isValueDependent())
1118  ExprBits.ValueDependent = true;
1119  if (Args[I]->isInstantiationDependent())
1120  ExprBits.InstantiationDependent = true;
1121  if (Args[I]->containsUnexpandedParameterPack())
1122  ExprBits.ContainsUnexpandedParameterPack = true;
1123 
1124  TrailingArgs[I] = Args[I];
1125  }
1126 }
1127 
1129  unsigned NumArgs)
1130  : Expr(SC, Empty), NumArgs(NumArgs) {}
1131 
1134  SourceLocation EllipsisLoc)
1135  : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
1136  unsigned Bits = 0;
1137  if (Implicit)
1138  Bits |= Capture_Implicit;
1139 
1140  switch (Kind) {
1141  case LCK_StarThis:
1142  Bits |= Capture_ByCopy;
1143  LLVM_FALLTHROUGH;
1144  case LCK_This:
1145  assert(!Var && "'this' capture cannot have a variable!");
1146  Bits |= Capture_This;
1147  break;
1148 
1149  case LCK_ByCopy:
1150  Bits |= Capture_ByCopy;
1151  LLVM_FALLTHROUGH;
1152  case LCK_ByRef:
1153  assert(Var && "capture must have a variable!");
1154  break;
1155  case LCK_VLAType:
1156  assert(!Var && "VLA type capture cannot have a variable!");
1157  break;
1158  }
1159  DeclAndBits.setInt(Bits);
1160 }
1161 
1163  if (capturesVLAType())
1164  return LCK_VLAType;
1165  bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
1166  if (capturesThis())
1167  return CapByCopy ? LCK_StarThis : LCK_This;
1168  return CapByCopy ? LCK_ByCopy : LCK_ByRef;
1169 }
1170 
1171 LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
1172  LambdaCaptureDefault CaptureDefault,
1173  SourceLocation CaptureDefaultLoc,
1174  ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1175  bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1176  SourceLocation ClosingBrace,
1177  bool ContainsUnexpandedParameterPack)
1178  : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(),
1179  T->isDependentType(), T->isDependentType(),
1180  ContainsUnexpandedParameterPack),
1181  IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
1182  NumCaptures(Captures.size()), CaptureDefault(CaptureDefault),
1183  ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType),
1184  ClosingBrace(ClosingBrace) {
1185  assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
1186  CXXRecordDecl *Class = getLambdaClass();
1187  CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
1188 
1189  // FIXME: Propagate "has unexpanded parameter pack" bit.
1190 
1191  // Copy captures.
1192  const ASTContext &Context = Class->getASTContext();
1193  Data.NumCaptures = NumCaptures;
1194  Data.NumExplicitCaptures = 0;
1195  Data.Captures =
1196  (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures);
1197  LambdaCapture *ToCapture = Data.Captures;
1198  for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
1199  if (Captures[I].isExplicit())
1200  ++Data.NumExplicitCaptures;
1201 
1202  *ToCapture++ = Captures[I];
1203  }
1204 
1205  // Copy initialization expressions for the non-static data members.
1206  Stmt **Stored = getStoredStmts();
1207  for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
1208  *Stored++ = CaptureInits[I];
1209 
1210  // Copy the body of the lambda.
1211  *Stored++ = getCallOperator()->getBody();
1212 }
1213 
1215  const ASTContext &Context, CXXRecordDecl *Class,
1216  SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault,
1217  SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1218  bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1219  SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) {
1220  // Determine the type of the expression (i.e., the type of the
1221  // function object we're creating).
1222  QualType T = Context.getTypeDeclType(Class);
1223 
1224  unsigned Size = totalSizeToAlloc<Stmt *>(Captures.size() + 1);
1225  void *Mem = Context.Allocate(Size);
1226  return new (Mem)
1227  LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
1228  Captures, ExplicitParams, ExplicitResultType, CaptureInits,
1229  ClosingBrace, ContainsUnexpandedParameterPack);
1230 }
1231 
1233  unsigned NumCaptures) {
1234  unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
1235  void *Mem = C.Allocate(Size);
1236  return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
1237 }
1238 
1240  return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
1241  (getCallOperator() == C->getCapturedVar()->getDeclContext()));
1242 }
1243 
1245  return getLambdaClass()->getLambdaData().Captures;
1246 }
1247 
1249  return capture_begin() + NumCaptures;
1250 }
1251 
1253  return capture_range(capture_begin(), capture_end());
1254 }
1255 
1257  return capture_begin();
1258 }
1259 
1261  struct CXXRecordDecl::LambdaDefinitionData &Data
1262  = getLambdaClass()->getLambdaData();
1263  return Data.Captures + Data.NumExplicitCaptures;
1264 }
1265 
1267  return capture_range(explicit_capture_begin(), explicit_capture_end());
1268 }
1269 
1271  return explicit_capture_end();
1272 }
1273 
1275  return capture_end();
1276 }
1277 
1279  return capture_range(implicit_capture_begin(), implicit_capture_end());
1280 }
1281 
1283  return getType()->getAsCXXRecordDecl();
1284 }
1285 
1287  CXXRecordDecl *Record = getLambdaClass();
1288  return Record->getLambdaCallOperator();
1289 }
1290 
1292  CXXRecordDecl *Record = getLambdaClass();
1293  return Record->getDependentLambdaCallOperator();
1294 }
1295 
1297  CXXRecordDecl *Record = getLambdaClass();
1298  return Record->getGenericLambdaTemplateParameterList();
1299 }
1300 
1302  const CXXRecordDecl *Record = getLambdaClass();
1303  return Record->getLambdaExplicitTemplateParameters();
1304 }
1305 
1307  // FIXME: this mutation in getBody is bogus. It should be
1308  // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I
1309  // don't understand, that doesn't work.
1310  if (!getStoredStmts()[NumCaptures])
1311  *const_cast<Stmt **>(&getStoredStmts()[NumCaptures]) =
1312  getCallOperator()->getBody();
1313 
1314  return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1315 }
1316 
1318  return !getCallOperator()->isConst();
1319 }
1320 
1321 ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1322  bool CleanupsHaveSideEffects,
1323  ArrayRef<CleanupObject> objects)
1324  : FullExpr(ExprWithCleanupsClass, subexpr) {
1325  ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
1326  ExprWithCleanupsBits.NumObjects = objects.size();
1327  for (unsigned i = 0, e = objects.size(); i != e; ++i)
1328  getTrailingObjects<CleanupObject>()[i] = objects[i];
1329 }
1330 
1332  bool CleanupsHaveSideEffects,
1333  ArrayRef<CleanupObject> objects) {
1334  void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
1335  alignof(ExprWithCleanups));
1336  return new (buffer)
1337  ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
1338 }
1339 
1340 ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1341  : FullExpr(ExprWithCleanupsClass, empty) {
1342  ExprWithCleanupsBits.NumObjects = numObjects;
1343 }
1344 
1346  EmptyShell empty,
1347  unsigned numObjects) {
1348  void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
1349  alignof(ExprWithCleanups));
1350  return new (buffer) ExprWithCleanups(empty, numObjects);
1351 }
1352 
1353 CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *TSI,
1354  SourceLocation LParenLoc,
1355  ArrayRef<Expr *> Args,
1356  SourceLocation RParenLoc)
1357  : Expr(CXXUnresolvedConstructExprClass,
1358  TSI->getType().getNonReferenceType(),
1359  (TSI->getType()->isLValueReferenceType()
1360  ? VK_LValue
1362  : VK_RValue),
1363  OK_Ordinary,
1364  TSI->getType()->isDependentType() ||
1365  TSI->getType()->getContainedDeducedType(),
1366  true, true, TSI->getType()->containsUnexpandedParameterPack()),
1367  TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
1368  CXXUnresolvedConstructExprBits.NumArgs = Args.size();
1369  auto **StoredArgs = getTrailingObjects<Expr *>();
1370  for (unsigned I = 0; I != Args.size(); ++I) {
1371  if (Args[I]->containsUnexpandedParameterPack())
1372  ExprBits.ContainsUnexpandedParameterPack = true;
1373 
1374  StoredArgs[I] = Args[I];
1375  }
1376 }
1377 
1379  const ASTContext &Context, TypeSourceInfo *TSI, SourceLocation LParenLoc,
1380  ArrayRef<Expr *> Args, SourceLocation RParenLoc) {
1381  void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1382  return new (Mem) CXXUnresolvedConstructExpr(TSI, LParenLoc, Args, RParenLoc);
1383 }
1384 
1387  unsigned NumArgs) {
1388  void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1389  return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs);
1390 }
1391 
1393  return TSI->getTypeLoc().getBeginLoc();
1394 }
1395 
1396 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1397  const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1398  SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1399  SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1400  DeclarationNameInfo MemberNameInfo,
1401  const TemplateArgumentListInfo *TemplateArgs)
1402  : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue,
1403  OK_Ordinary, true, true, true,
1404  ((Base && Base->containsUnexpandedParameterPack()) ||
1405  (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
1407  MemberNameInfo.containsUnexpandedParameterPack())),
1408  Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc),
1409  MemberNameInfo(MemberNameInfo) {
1410  CXXDependentScopeMemberExprBits.IsArrow = IsArrow;
1411  CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1412  (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1413  CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1414  FirstQualifierFoundInScope != nullptr;
1415  CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc;
1416 
1417  if (TemplateArgs) {
1418  bool Dependent = true;
1419  bool InstantiationDependent = true;
1420  bool ContainsUnexpandedParameterPack = false;
1421  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1422  TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1423  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
1424  if (ContainsUnexpandedParameterPack)
1425  ExprBits.ContainsUnexpandedParameterPack = true;
1426  } else if (TemplateKWLoc.isValid()) {
1427  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1428  TemplateKWLoc);
1429  }
1430 
1431  if (hasFirstQualifierFoundInScope())
1432  *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope;
1433 }
1434 
1435 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1436  EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
1437  bool HasFirstQualifierFoundInScope)
1438  : Expr(CXXDependentScopeMemberExprClass, Empty) {
1439  CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1440  HasTemplateKWAndArgsInfo;
1441  CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1442  HasFirstQualifierFoundInScope;
1443 }
1444 
1446  const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1447  SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1448  SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1449  DeclarationNameInfo MemberNameInfo,
1450  const TemplateArgumentListInfo *TemplateArgs) {
1451  bool HasTemplateKWAndArgsInfo =
1452  (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1453  unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1454  bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr;
1455 
1456  unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1458  HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1459 
1460  void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1461  return new (Mem) CXXDependentScopeMemberExpr(
1462  Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
1463  FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs);
1464 }
1465 
1467  const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
1468  unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) {
1469  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1470 
1471  unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1473  HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1474 
1475  void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1476  return new (Mem) CXXDependentScopeMemberExpr(
1477  EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope);
1478 }
1479 
1481  UnresolvedSetIterator end) {
1482  do {
1483  NamedDecl *decl = *begin;
1484  if (isa<UnresolvedUsingValueDecl>(decl))
1485  return false;
1486 
1487  // Unresolved member expressions should only contain methods and
1488  // method templates.
1489  if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1490  ->isStatic())
1491  return false;
1492  } while (++begin != end);
1493 
1494  return true;
1495 }
1496 
1497 UnresolvedMemberExpr::UnresolvedMemberExpr(
1498  const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1499  QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1500  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1501  const DeclarationNameInfo &MemberNameInfo,
1502  const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1504  : OverloadExpr(
1505  UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc,
1506  MemberNameInfo, TemplateArgs, Begin, End,
1507  // Dependent
1508  ((Base && Base->isTypeDependent()) || BaseType->isDependentType()),
1509  ((Base && Base->isInstantiationDependent()) ||
1510  BaseType->isInstantiationDependentType()),
1511  // Contains unexpanded parameter pack
1512  ((Base && Base->containsUnexpandedParameterPack()) ||
1513  BaseType->containsUnexpandedParameterPack())),
1514  Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
1515  UnresolvedMemberExprBits.IsArrow = IsArrow;
1516  UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing;
1517 
1518  // Check whether all of the members are non-static member functions,
1519  // and if so, mark give this bound-member type instead of overload type.
1520  if (hasOnlyNonStaticMemberFunctions(Begin, End))
1521  setType(Context.BoundMemberTy);
1522 }
1523 
1524 UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty,
1525  unsigned NumResults,
1526  bool HasTemplateKWAndArgsInfo)
1527  : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults,
1528  HasTemplateKWAndArgsInfo) {}
1529 
1531  if (!Base)
1532  return true;
1533 
1534  return cast<Expr>(Base)->isImplicitCXXThis();
1535 }
1536 
1538  const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1539  QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1540  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1541  const DeclarationNameInfo &MemberNameInfo,
1542  const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1543  UnresolvedSetIterator End) {
1544  unsigned NumResults = End - Begin;
1545  bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1546  unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1547  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1549  NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1550  void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1551  return new (Mem) UnresolvedMemberExpr(
1552  Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc,
1553  QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
1554 }
1555 
1557  const ASTContext &Context, unsigned NumResults,
1558  bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
1559  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1560  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1562  NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1563  void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1564  return new (Mem)
1565  UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
1566 }
1567 
1569  // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1570 
1571  // If there was a nested name specifier, it names the naming class.
1572  // It can't be dependent: after all, we were actually able to do the
1573  // lookup.
1574  CXXRecordDecl *Record = nullptr;
1575  auto *NNS = getQualifier();
1576  if (NNS && NNS->getKind() != NestedNameSpecifier::Super) {
1577  const Type *T = getQualifier()->getAsType();
1578  assert(T && "qualifier in member expression does not name type");
1579  Record = T->getAsCXXRecordDecl();
1580  assert(Record && "qualifier in member expression does not name record");
1581  }
1582  // Otherwise the naming class must have been the base class.
1583  else {
1584  QualType BaseType = getBaseType().getNonReferenceType();
1585  if (isArrow())
1586  BaseType = BaseType->castAs<PointerType>()->getPointeeType();
1587 
1588  Record = BaseType->getAsCXXRecordDecl();
1589  assert(Record && "base of member expression does not name record");
1590  }
1591 
1592  return Record;
1593 }
1594 
1597  NamedDecl *Pack, SourceLocation PackLoc,
1598  SourceLocation RParenLoc,
1599  Optional<unsigned> Length,
1600  ArrayRef<TemplateArgument> PartialArgs) {
1601  void *Storage =
1602  Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
1603  return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1604  PackLoc, RParenLoc, Length, PartialArgs);
1605 }
1606 
1608  unsigned NumPartialArgs) {
1609  void *Storage =
1610  Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
1611  return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1612 }
1613 
1614 SubstNonTypeTemplateParmPackExpr::
1615 SubstNonTypeTemplateParmPackExpr(QualType T,
1616  ExprValueKind ValueKind,
1617  NonTypeTemplateParmDecl *Param,
1618  SourceLocation NameLoc,
1619  const TemplateArgument &ArgPack)
1620  : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary,
1621  true, true, true, true),
1622  Param(Param), Arguments(ArgPack.pack_begin()),
1623  NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {}
1624 
1626  return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
1627 }
1628 
1629 FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
1630  SourceLocation NameLoc,
1631  unsigned NumParams,
1632  VarDecl *const *Params)
1633  : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true,
1634  true, true),
1635  ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1636  if (Params)
1637  std::uninitialized_copy(Params, Params + NumParams,
1638  getTrailingObjects<VarDecl *>());
1639 }
1640 
1643  VarDecl *ParamPack, SourceLocation NameLoc,
1644  ArrayRef<VarDecl *> Params) {
1645  return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size())))
1646  FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1647 }
1648 
1651  unsigned NumParams) {
1652  return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams)))
1653  FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
1654 }
1655 
1657  unsigned ManglingNumber) {
1658  // We only need extra state if we have to remember more than just the Stmt.
1659  if (!ExtendedBy)
1660  return;
1661 
1662  // We may need to allocate extra storage for the mangling number and the
1663  // extended-by ValueDecl.
1664  if (!State.is<ExtraState *>()) {
1665  auto *ES = new (ExtendedBy->getASTContext()) ExtraState;
1666  ES->Temporary = State.get<Stmt *>();
1667  State = ES;
1668  }
1669 
1670  auto ES = State.get<ExtraState *>();
1671  ES->ExtendingDecl = ExtendedBy;
1672  ES->ManglingNumber = ManglingNumber;
1673 }
1674 
1675 TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1677  SourceLocation RParenLoc,
1678  bool Value)
1679  : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1680  /*TypeDependent=*/false,
1681  /*ValueDependent=*/false,
1682  /*InstantiationDependent=*/false,
1683  /*ContainsUnexpandedParameterPack=*/false),
1684  Loc(Loc), RParenLoc(RParenLoc) {
1685  TypeTraitExprBits.Kind = Kind;
1686  TypeTraitExprBits.Value = Value;
1687  TypeTraitExprBits.NumArgs = Args.size();
1688 
1689  auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1690 
1691  for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1692  if (Args[I]->getType()->isDependentType())
1693  setValueDependent(true);
1694  if (Args[I]->getType()->isInstantiationDependentType())
1696  if (Args[I]->getType()->containsUnexpandedParameterPack())
1698 
1699  ToArgs[I] = Args[I];
1700  }
1701 }
1702 
1704  SourceLocation Loc,
1705  TypeTrait Kind,
1707  SourceLocation RParenLoc,
1708  bool Value) {
1709  void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
1710  return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1711 }
1712 
1714  unsigned NumArgs) {
1715  void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
1716  return new (Mem) TypeTraitExpr(EmptyShell());
1717 }
1718 
1719 CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
1720  ArrayRef<Expr *> Args, QualType Ty,
1722  unsigned MinNumArgs)
1723  : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK,
1724  RP, MinNumArgs, NotADL) {}
1725 
1726 CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty)
1727  : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs,
1728  Empty) {}
1729 
1733  SourceLocation RP, unsigned MinNumArgs) {
1734  // Allocate storage for the trailing objects of CallExpr.
1735  unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1736  unsigned SizeOfTrailingObjects =
1737  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1738  void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1739  alignof(CUDAKernelCallExpr));
1740  return new (Mem) CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, MinNumArgs);
1741 }
1742 
1744  unsigned NumArgs,
1745  EmptyShell Empty) {
1746  // Allocate storage for the trailing objects of CallExpr.
1747  unsigned SizeOfTrailingObjects =
1748  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1749  void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1750  alignof(CUDAKernelCallExpr));
1751  return new (Mem) CUDAKernelCallExpr(NumArgs, Empty);
1752 }
1753 
1754 ConceptSpecializationExpr::ConceptSpecializationExpr(ASTContext &C,
1755  NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc,
1756  SourceLocation ConceptNameLoc, NamedDecl *FoundDecl,
1757  ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten,
1758  ArrayRef<TemplateArgument> ConvertedArgs, Optional<bool> IsSatisfied)
1759  : Expr(ConceptSpecializationExprClass, C.BoolTy, VK_RValue, OK_Ordinary,
1760  /*TypeDependent=*/false,
1761  // All the flags below are set in setTemplateArguments.
1762  /*ValueDependent=*/!IsSatisfied.hasValue(),
1763  /*InstantiationDependent=*/false,
1764  /*ContainsUnexpandedParameterPacks=*/false),
1765  NestedNameSpec(NNS), TemplateKWLoc(TemplateKWLoc),
1766  ConceptNameLoc(ConceptNameLoc), FoundDecl(FoundDecl),
1767  NamedConcept(NamedConcept, IsSatisfied ? *IsSatisfied : true),
1768  NumTemplateArgs(ConvertedArgs.size()) {
1769 
1770  setTemplateArguments(ArgsAsWritten, ConvertedArgs);
1771 }
1772 
1773 ConceptSpecializationExpr::ConceptSpecializationExpr(EmptyShell Empty,
1774  unsigned NumTemplateArgs)
1775  : Expr(ConceptSpecializationExprClass, Empty),
1776  NumTemplateArgs(NumTemplateArgs) { }
1777 
1779  const ASTTemplateArgumentListInfo *ArgsAsWritten,
1780  ArrayRef<TemplateArgument> Converted) {
1781  assert(Converted.size() == NumTemplateArgs);
1782  assert(!this->ArgsAsWritten && "setTemplateArguments can only be used once");
1783  this->ArgsAsWritten = ArgsAsWritten;
1784  std::uninitialized_copy(Converted.begin(), Converted.end(),
1785  getTrailingObjects<TemplateArgument>());
1786  bool IsInstantiationDependent = false;
1787  bool ContainsUnexpandedParameterPack = false;
1788  for (const TemplateArgumentLoc& LocInfo : ArgsAsWritten->arguments()) {
1789  if (LocInfo.getArgument().isInstantiationDependent())
1790  IsInstantiationDependent = true;
1791  if (LocInfo.getArgument().containsUnexpandedParameterPack())
1792  ContainsUnexpandedParameterPack = true;
1793  if (ContainsUnexpandedParameterPack && IsInstantiationDependent)
1794  break;
1795  }
1796 
1797  // Currently guaranteed by the fact concepts can only be at namespace-scope.
1798  assert(!NestedNameSpec ||
1799  (!NestedNameSpec.getNestedNameSpecifier()->isInstantiationDependent() &&
1800  !NestedNameSpec.getNestedNameSpecifier()
1801  ->containsUnexpandedParameterPack()));
1802  setInstantiationDependent(IsInstantiationDependent);
1803  setContainsUnexpandedParameterPack(ContainsUnexpandedParameterPack);
1804  assert((!isValueDependent() || isInstantiationDependent()) &&
1805  "should not be value-dependent");
1806 }
1807 
1810  SourceLocation TemplateKWLoc,
1811  SourceLocation ConceptNameLoc,
1812  NamedDecl *FoundDecl,
1813  ConceptDecl *NamedConcept,
1814  const ASTTemplateArgumentListInfo *ArgsAsWritten,
1815  ArrayRef<TemplateArgument> ConvertedArgs,
1816  Optional<bool> IsSatisfied) {
1817  void *Buffer = C.Allocate(totalSizeToAlloc<TemplateArgument>(
1818  ConvertedArgs.size()));
1819  return new (Buffer) ConceptSpecializationExpr(C, NNS, TemplateKWLoc,
1820  ConceptNameLoc, FoundDecl,
1821  NamedConcept, ArgsAsWritten,
1822  ConvertedArgs, IsSatisfied);
1823 }
1824 
1827  unsigned NumTemplateArgs) {
1828  void *Buffer = C.Allocate(totalSizeToAlloc<TemplateArgument>(
1829  NumTemplateArgs));
1830  return new (Buffer) ConceptSpecializationExpr(Empty, NumTemplateArgs);
1831 }
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:78
static DependentScopeDeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:570
void setValueDependent(bool VD)
Set whether this expression is value-dependent or not.
Definition: Expr.h:161
Defines the clang::ASTContext interface.
LiteralOperatorKind
The kind of literal operator which is invoked.
Definition: ExprCXX.h:590
void setTemplateArguments(const ASTTemplateArgumentListInfo *ArgsAsWritten, ArrayRef< TemplateArgument > Converted)
Set new template arguments for this concept specialization.
Definition: ExprCXX.cpp:1778
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
capture_iterator explicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of explicit lambda captures.
Definition: ExprCXX.cpp:1260
static CXXConstructExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs)
Create an empty C++ construction expression.
Definition: ExprCXX.cpp:1085
Represents a function declaration or definition.
Definition: Decl.h:1784
SourceLocation getRParenLoc() const
Definition: Expr.h:2764
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
Definition: ExprCXX.cpp:153
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2585
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2428
A (possibly-)qualified type.
Definition: Type.h:643
bool isArrayType() const
Definition: Type.h:6447
static const TemplateArgument & getArgument(const TemplateArgument &A)
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition: ExprCXX.cpp:1248
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2627
BinaryOperatorKind Opcode
The original opcode, prior to rewriting.
Definition: ExprCXX.h:298
Stmt - This represents one statement.
Definition: Stmt.h:66
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2664
LambdaCapture(SourceLocation Loc, bool Implicit, LambdaCaptureKind Kind, VarDecl *Var=nullptr, SourceLocation EllipsisLoc=SourceLocation())
Create a new capture of a variable or of this.
Definition: ExprCXX.cpp:1132
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:557
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:798
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1537
C Language Family Type Representation.
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
bool isRecordType() const
Definition: Type.h:6471
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs)
Return the size in bytes needed for the trailing objects.
Definition: Expr.h:2585
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Definition: ExprCXX.cpp:718
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
void setType(QualType t)
Definition: Expr.h:138
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3037
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6339
The base class of the type hierarchy.
Definition: Type.h:1436
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:592
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1422
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
Definition: DeclCXX.cpp:1475
A container of type source information.
Definition: Decl.h:86
const Expr * RHS
The original right-hand side.
Definition: ExprCXX.h:302
Floating point control options.
Definition: LangOptions.h:323
bool isInstantiationDependent() const
Determine whether this name involves a template parameter.
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, SourceLocation LPLoc, SourceLocation RPLoc)
Definition: ExprCXX.cpp:894
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2365
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:2783
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:635
capture_range implicit_captures() const
Retrieve this lambda&#39;s implicit captures.
Definition: ExprCXX.cpp:1278
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:586
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr *> Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition: ExprCXX.cpp:1070
CXXRecordDecl * getRecordDecl() const
Retrieve the CXXRecordDecl for the underlying type of the implicit object argument.
Definition: ExprCXX.cpp:745
Represents a variable declaration or definition.
Definition: Decl.h:827
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6858
DecomposedForm getDecomposedForm() const LLVM_READONLY
Decompose this operator into its syntactic form.
Definition: ExprCXX.cpp:62
static FunctionParmPackExpr * CreateEmpty(const ASTContext &Context, unsigned NumParams)
Definition: ExprCXX.cpp:1650
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:439
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:375
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:603
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:67
void setContainsUnexpandedParameterPack(bool PP=true)
Set the bit that describes whether this expression contains an unexpanded parameter pack...
Definition: Expr.h:229
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:631
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Definition: ExprCXX.h:3306
FunctionTemplateDecl * getDependentCallOperator() const
Retrieve the function template call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1291
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr *> Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition: ExprCXX.cpp:1036
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda&#39;s template parameter list.
Definition: DeclCXX.cpp:1466
Defines the clang::Expr interface and subclasses for C++ expressions.
The collection of all-type qualifiers we support.
Definition: Type.h:137
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1282
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:409
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, TypeSourceInfo *Type, SourceLocation LParenLoc, ArrayRef< Expr *> Args, SourceLocation RParenLoc)
Definition: ExprCXX.cpp:1378
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
A C++ nested-name-specifier augmented with source location information.
LineState State
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:925
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:274
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:33
Represents a member of a struct/union/class.
Definition: Decl.h:2643
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:1063
CompoundStmt * getBody() const
Retrieve the body of the lambda.
Definition: ExprCXX.cpp:1306
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:914
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:31
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:368
capture_iterator implicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of implicit lambda captures.
Definition: ExprCXX.cpp:1274
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:40
Represents a C++ member access expression for which lookup produced a set of overloaded functions...
Definition: ExprCXX.h:3771
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:125
bool isGLValue() const
Definition: Expr.h:261
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition: ExprCXX.cpp:1625
CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr *> Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Build a C++ construction expression.
Definition: ExprCXX.cpp:1094
< Capturing the *this object by copy
Definition: Lambda.h:36
bool capturesThis() const
Determine whether this capture handles the C++ this pointer.
Definition: LambdaCapture.h:82
A convenient class for passing around template argument information.
Definition: TemplateBase.h:554
SourceLocation getLocation() const
Definition: ExprCXX.h:2452
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
An x-value expression is a reference to an object with independent storage but which can be "moved"...
Definition: Specifiers.h:134
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1871
bool isRValueReferenceType() const
Definition: Type.h:6411
unsigned getInt() const
Used to serialize this.
Definition: LangOptions.h:368
QualType getObjectType() const
Retrieve the type of the object argument.
Definition: ExprCXX.cpp:730
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1373
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1818
DeclAccessPair * getTrailingResults()
Return the results. Defined after UnresolvedMemberExpr.
Definition: ExprCXX.h:3925
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:176
An ordinary object is located at an address in memory.
Definition: Specifiers.h:141
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3511
bool containsUnexpandedParameterPack() const
Determine whether this name contains an unexpanded parameter pack.
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda&#39;s captures is an init-capture.
Definition: ExprCXX.cpp:1239
StmtClass
Definition: Stmt.h:68
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:403
const IdentifierInfo * getUDSuffix() const
Returns the ud-suffix specified for this literal.
Definition: ExprCXX.cpp:988
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:650
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:20
const Expr * InnerBinOp
The inner == or <=> operator expression.
Definition: ExprCXX.h:304
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
Expr()=delete
ASTTemplateKWAndArgsInfo * getTrailingASTTemplateKWAndArgsInfo()
Return the optional template keyword and arguments info.
Definition: ExprCXX.h:3931
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1320
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1692
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3725
CastKind
CastKind - The kind of operation required for a conversion.
SourceRange getLocalSourceRange() const
Get the local source range.
Definition: TypeLoc.h:156
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl *> Params)
Definition: ExprCXX.cpp:1642
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:189
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:1059
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:644
This represents one expression.
Definition: Expr.h:108
SourceLocation End
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo *> Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition: ExprCXX.cpp:1703
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:122
static CXXMemberCallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, EmptyShell Empty)
Definition: ExprCXX.cpp:707
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition: ExprCXX.cpp:1530
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6923
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1750
A C++ const_cast expression (C++ [expr.const.cast]).
Definition: ExprCXX.h:527
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2629
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Defines an enumeration for C++ overloaded operators.
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:773
static CXXReinterpretCastExpr * CreateEmpty(const ASTContext &Context, unsigned pathSize)
Definition: ExprCXX.cpp:875
DeclContext * getDeclContext()
Definition: DeclBase.h:438
ExprBitfields ExprBits
Definition: Stmt.h:968
static UserDefinedLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, EmptyShell Empty)
Definition: ExprCXX.cpp:947
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1445
SourceLocation Begin
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4091
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
CXXDefaultInitExprBitfields CXXDefaultInitExprBits
Definition: Stmt.h:996
Defines the clang::TypeLoc interface and its subclasses.
QualType getType() const
Definition: Expr.h:137
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< LambdaCapture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr *> CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1214
SourceLocation getEnd() const
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Definition: ExprCXX.cpp:737
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Definition: ExprCXX.cpp:146
static UnresolvedLookupExpr * CreateEmpty(const ASTContext &Context, unsigned NumResults, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:435
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1403
The result type of a method or function.
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:300
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1286
SourceRange getSourceRange() const
Definition: ExprCXX.h:141
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:287
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:88
LiteralOperatorKind getLiteralOperatorKind() const
Returns the kind of literal operator invocation which this expression represents. ...
Definition: ExprCXX.cpp:959
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:445
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:880
Kind
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1010
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
Definition: ExprCXX.h:2844
capture_iterator implicit_capture_begin() const
Retrieve an iterator pointing to the first implicit lambda capture.
Definition: ExprCXX.cpp:1270
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Definition: Expr.h:200
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:218
static CXXDynamicCastExpr * CreateEmpty(const ASTContext &Context, unsigned pathSize)
Definition: ExprCXX.cpp:817
Encodes a location in the source.
const Expr * LHS
The original left-hand side.
Definition: ExprCXX.h:300
capture_iterator explicit_capture_begin() const
Retrieve an iterator pointing to the first explicit lambda capture.
Definition: ExprCXX.cpp:1256
FunctionTemplateDecl * getDependentLambdaCallOperator() const
Retrieve the dependent lambda call operator of the closure type if this is a templated closure type...
Definition: DeclCXX.cpp:1415
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:918
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:555
static CXXOperatorCallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, EmptyShell Empty)
Definition: ExprCXX.cpp:649
UnresolvedLookupExprBitfields UnresolvedLookupExprBits
Definition: Stmt.h:1007
Represents a C++ temporary.
Definition: ExprCXX.h:1341
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
Definition: ExprCXX.cpp:291
static CXXConstCastExpr * CreateEmpty(const ASTContext &Context)
Definition: ExprCXX.cpp:889
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:2100
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit...
Definition: ExprCXX.h:564
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1596
Represents a call to a member function that may be written either with member call syntax (e...
Definition: ExprCXX.h:171
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:377
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1905
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1345
ArrayRef< NamedDecl * > getExplicitTemplateParameters() const
Get the template parameters were explicitly specified (as opposed to being invented by use of an auto...
Definition: ExprCXX.cpp:1301
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:158
bool isAnyPointerType() const
Definition: Type.h:6395
bool isInfixBinaryOp() const
Is this written as an infix binary operator?
Definition: ExprCXX.cpp:45
bool isExplicit() const
Determine whether this was an explicit capture (written between the square brackets introducing the l...
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1910
static CXXDependentScopeMemberExpr * CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope)
Definition: ExprCXX.cpp:1466
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
static SizeOfPackExpr * CreateDeserialized(ASTContext &Context, unsigned NumPartialArgs)
Definition: ExprCXX.cpp:1607
CXXRecordDecl * getNamingClass()
Retrieve the naming class of this lookup.
Definition: ExprCXX.cpp:1568
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:161
static CXXTemporaryObjectExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs)
Definition: ExprCXX.cpp:1051
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:857
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2127
A placeholder type used to construct an empty shell of a type, that will be filled in later (e...
Definition: Stmt.h:1044
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3155
static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, UnresolvedSetIterator end)
Definition: ExprCXX.cpp:1480
Defines various enumerations that describe declaration and type specifiers.
A POD class for pairing a NamedDecl* with an access specifier.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:685
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4337
Represents a template argument.
Definition: TemplateBase.h:50
static CXXUnresolvedConstructExpr * CreateEmpty(const ASTContext &Context, unsigned NumArgs)
Definition: ExprCXX.cpp:1386
bool isMutable() const
Determine whether the lambda is mutable, meaning that any captures values can be modified.
Definition: ExprCXX.cpp:1317
Dataflow Directional Tag Classes.
void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber)
Definition: ExprCXX.cpp:1656
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
bool isValid() const
Return true if this is a valid SourceLocation object.
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:1420
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.cpp:1810
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:107
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition: ExprCXX.h:487
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1162
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2444
bool capturesVLAType() const
Determine whether this captures a variable length array bound expression.
Definition: LambdaCapture.h:94
StmtClass getStmtClass() const
Definition: Stmt.h:1097
static LambdaExpr * CreateDeserialized(const ASTContext &C, unsigned NumCaptures)
Construct a new lambda expression that will be deserialized from an external source.
Definition: ExprCXX.cpp:1232
void setInstantiationDependent(bool ID)
Set whether this expression is instantiation-dependent or not.
Definition: Expr.h:205
DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits
Definition: Stmt.h:1001
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1426
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it...
Definition: ExprCXX.cpp:1296
CXXNewExprBitfields CXXNewExprBits
Definition: Stmt.h:998
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:1392
OverloadExpr(StmtClass SC, const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent, bool KnownContainsUnexpandedParameterPack)
Definition: ExprCXX.cpp:447
Capturing variable-length array type.
Definition: Lambda.h:38
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2958
CXXConstructExprBitfields CXXConstructExprBits
Definition: Stmt.h:1002
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4444
TemplateArgumentLoc * getTrailingTemplateArgumentLoc()
Return the optional template arguments.
Definition: ExprCXX.h:3941
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:449
static CUDAKernelCallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, EmptyShell Empty)
Definition: ExprCXX.cpp:1743
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6684
CanQualType DependentTy
Definition: ASTContext.h:1044
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:224
TypeTraitExprBitfields TypeTraitExprBits
Definition: Stmt.h:1000
CanQualType BoundMemberTy
Definition: ASTContext.h:1044
static CXXFunctionalCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize)
Definition: ExprCXX.cpp:909
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2918
Capturing the *this object by reference.
Definition: Lambda.h:34
Represents a base class of a C++ class.
Definition: DeclCXX.h:147
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3390
bool isLValueReferenceType() const
Definition: Type.h:6407
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:240
OverloadExprBitfields OverloadExprBits
Definition: Stmt.h:1006
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:693
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
void setEnd(SourceLocation e)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
static CXXStaticCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize)
Definition: ExprCXX.cpp:792
bool isValid() const
bool isVoidType() const
Definition: Type.h:6650
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1005
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr.type.conv]).
Definition: ExprCXX.h:1688
static TypeTraitExpr * CreateDeserialized(const ASTContext &C, unsigned NumArgs)
Definition: ExprCXX.cpp:1713
CXXOperatorCallExprBitfields CXXOperatorCallExprBits
Definition: Stmt.h:989
Capturing by reference.
Definition: Lambda.h:37
Represents the specialization of a concept - evaluates to a prvalue of type bool. ...
Definition: ExprCXX.h:4849
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
static CXXNewExpr * CreateEmpty(const ASTContext &Ctx, bool IsArray, bool HasInit, unsigned NumPlacementArgs, bool IsParenTypeId)
Create an empty c++ new expression.
Definition: ExprCXX.cpp:280
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:223
capture_range captures() const
Retrieve this lambda&#39;s captures.
Definition: ExprCXX.cpp:1252
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2521
CXXPseudoDestructorExpr(const ASTContext &Context, Expr *Base, bool isArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
Definition: ExprCXX.cpp:333
static CUDAKernelCallExpr * Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:1731
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition: ExprCXX.cpp:1244
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2121
bool isAlwaysNull() const
isAlwaysNull - Return whether the result of the dynamic_cast is proven to always be null...
Definition: ExprCXX.cpp:831
bool isPointerType() const
Definition: Type.h:6391
const char * getCastName() const
getCastName - Get the name of the C++ cast being used, e.g., "static_cast", "dynamic_cast", "reinterpret_cast", or "const_cast".
Definition: ExprCXX.cpp:763
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2999
#define true
Definition: stdbool.h:16
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:129
bool isFloatingType() const
Definition: Type.cpp:2008
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
CanQualType BoolTy
Definition: ASTContext.h:1016
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr...
Definition: ExprCXX.cpp:131
static UserDefinedLiteral * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation LitEndLoc, SourceLocation SuffixLoc)
Definition: ExprCXX.cpp:933
capture_range explicit_captures() const
Retrieve this lambda&#39;s explicit captures.
Definition: ExprCXX.cpp:1266
static ConceptSpecializationExpr * Create(ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, SourceLocation ConceptNameLoc, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten, ArrayRef< TemplateArgument > ConvertedArgs, Optional< bool > IsSatisfied)
Definition: ExprCXX.cpp:1809
SourceLocation getBegin() const
Declaration of a template function.
Definition: DeclTemplate.h:961
llvm::iterator_range< capture_iterator > capture_range
An iterator over a range of lambda captures.
Definition: ExprCXX.h:1906
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
Defines the LambdaCapture class.
Expr * getCookedLiteral()
If this is not a raw user-defined literal, get the underlying cooked literal (representing the litera...
Definition: ExprCXX.cpp:980
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr *> PlacementArgs, SourceRange TypeIdParens, Optional< Expr *> ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:257
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2962
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
static UnresolvedMemberExpr * CreateEmpty(const ASTContext &Context, unsigned NumResults, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:1556