clang  3.8.0
ExprCXX.cpp
Go to the documentation of this file.
1 //===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the subclesses of Expr class declared in ExprCXX.h
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/ExprCXX.h"
19 #include "clang/AST/TypeLoc.h"
21 using namespace clang;
22 
23 
24 //===----------------------------------------------------------------------===//
25 // Child Iterators for iterating over subexpressions/substatements
26 //===----------------------------------------------------------------------===//
27 
29  if (isTypeOperand())
30  return false;
31 
32  // C++11 [expr.typeid]p3:
33  // When typeid is applied to an expression other than a glvalue of
34  // polymorphic class type, [...] the expression is an unevaluated operand.
35  const Expr *E = getExprOperand();
36  if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
37  if (RD->isPolymorphic() && E->isGLValue())
38  return true;
39 
40  return false;
41 }
42 
44  assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
45  Qualifiers Quals;
46  return Context.getUnqualifiedArrayType(
47  Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
48 }
49 
51  assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
52  Qualifiers Quals;
53  return Context.getUnqualifiedArrayType(
54  Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
55 }
56 
57 // static
59  bool *RDHasMultipleGUIDsPtr) {
60  // Optionally remove one level of pointer, reference or array indirection.
61  const Type *Ty = QT.getTypePtr();
62  if (QT->isPointerType() || QT->isReferenceType())
63  Ty = QT->getPointeeType().getTypePtr();
64  else if (QT->isArrayType())
65  Ty = Ty->getBaseElementTypeUnsafe();
66 
67  const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
68  if (!RD)
69  return nullptr;
70 
71  if (const UuidAttr *Uuid = RD->getMostRecentDecl()->getAttr<UuidAttr>())
72  return Uuid;
73 
74  // __uuidof can grab UUIDs from template arguments.
75  if (const ClassTemplateSpecializationDecl *CTSD =
76  dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
77  const TemplateArgumentList &TAL = CTSD->getTemplateArgs();
78  const UuidAttr *UuidForRD = nullptr;
79 
80  for (const TemplateArgument &TA : TAL.asArray()) {
81  bool SeenMultipleGUIDs = false;
82 
83  const UuidAttr *UuidForTA = nullptr;
84  if (TA.getKind() == TemplateArgument::Type)
85  UuidForTA = GetUuidAttrOfType(TA.getAsType(), &SeenMultipleGUIDs);
86  else if (TA.getKind() == TemplateArgument::Declaration)
87  UuidForTA =
88  GetUuidAttrOfType(TA.getAsDecl()->getType(), &SeenMultipleGUIDs);
89 
90  // If the template argument has a UUID, there are three cases:
91  // - This is the first UUID seen for this RecordDecl.
92  // - This is a different UUID than previously seen for this RecordDecl.
93  // - This is the same UUID than previously seen for this RecordDecl.
94  if (UuidForTA) {
95  if (!UuidForRD)
96  UuidForRD = UuidForTA;
97  else if (UuidForRD != UuidForTA)
98  SeenMultipleGUIDs = true;
99  }
100 
101  // Seeing multiple UUIDs means that we couldn't find a UUID
102  if (SeenMultipleGUIDs) {
103  if (RDHasMultipleGUIDsPtr)
104  *RDHasMultipleGUIDsPtr = true;
105  return nullptr;
106  }
107  }
108 
109  return UuidForRD;
110  }
111 
112  return nullptr;
113 }
114 
116  StringRef Uuid;
117  if (isTypeOperand())
118  Uuid = CXXUuidofExpr::GetUuidAttrOfType(getTypeOperand(Context))->getGuid();
119  else {
120  // Special case: __uuidof(0) means an all-zero GUID.
121  Expr *Op = getExprOperand();
123  Uuid = CXXUuidofExpr::GetUuidAttrOfType(Op->getType())->getGuid();
124  else
125  Uuid = "00000000-0000-0000-0000-000000000000";
126  }
127  return Uuid;
128 }
129 
130 // CXXScalarValueInitExpr
132  return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc;
133 }
134 
135 // CXXNewExpr
136 CXXNewExpr::CXXNewExpr(const ASTContext &C, bool globalNew,
137  FunctionDecl *operatorNew, FunctionDecl *operatorDelete,
138  bool usualArrayDeleteWantsSize,
139  ArrayRef<Expr*> placementArgs,
140  SourceRange typeIdParens, Expr *arraySize,
141  InitializationStyle initializationStyle,
142  Expr *initializer, QualType ty,
143  TypeSourceInfo *allocatedTypeInfo,
144  SourceRange Range, SourceRange directInitRange)
145  : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
146  ty->isDependentType(), ty->isDependentType(),
147  ty->isInstantiationDependentType(),
148  ty->containsUnexpandedParameterPack()),
149  SubExprs(nullptr), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
150  AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
151  Range(Range), DirectInitRange(directInitRange),
152  GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
153  assert((initializer != nullptr || initializationStyle == NoInit) &&
154  "Only NoInit can have no initializer.");
155  StoredInitializationStyle = initializer ? initializationStyle + 1 : 0;
156  AllocateArgsArray(C, arraySize != nullptr, placementArgs.size(),
157  initializer != nullptr);
158  unsigned i = 0;
159  if (Array) {
160  if (arraySize->isInstantiationDependent())
161  ExprBits.InstantiationDependent = true;
162 
163  if (arraySize->containsUnexpandedParameterPack())
164  ExprBits.ContainsUnexpandedParameterPack = true;
165 
166  SubExprs[i++] = arraySize;
167  }
168 
169  if (initializer) {
170  if (initializer->isInstantiationDependent())
171  ExprBits.InstantiationDependent = true;
172 
173  if (initializer->containsUnexpandedParameterPack())
174  ExprBits.ContainsUnexpandedParameterPack = true;
175 
176  SubExprs[i++] = initializer;
177  }
178 
179  for (unsigned j = 0; j != placementArgs.size(); ++j) {
180  if (placementArgs[j]->isInstantiationDependent())
181  ExprBits.InstantiationDependent = true;
182  if (placementArgs[j]->containsUnexpandedParameterPack())
183  ExprBits.ContainsUnexpandedParameterPack = true;
184 
185  SubExprs[i++] = placementArgs[j];
186  }
187 
188  switch (getInitializationStyle()) {
189  case CallInit:
190  this->Range.setEnd(DirectInitRange.getEnd()); break;
191  case ListInit:
192  this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break;
193  default:
194  if (TypeIdParens.isValid())
195  this->Range.setEnd(TypeIdParens.getEnd());
196  break;
197  }
198 }
199 
200 void CXXNewExpr::AllocateArgsArray(const ASTContext &C, bool isArray,
201  unsigned numPlaceArgs, bool hasInitializer){
202  assert(SubExprs == nullptr && "SubExprs already allocated");
203  Array = isArray;
204  NumPlacementArgs = numPlaceArgs;
205 
206  unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
207  SubExprs = new (C) Stmt*[TotalSize];
208 }
209 
211  return getOperatorNew()->getType()->castAs<FunctionProtoType>()->isNothrow(
212  Ctx) &&
214 }
215 
216 // CXXDeleteExpr
218  const Expr *Arg = getArgument();
219  // The type-to-delete may not be a pointer if it's a dependent type.
220  const QualType ArgType = Arg->getType();
221 
222  if (ArgType->isDependentType() && !ArgType->isPointerType())
223  return QualType();
224 
225  return ArgType->getAs<PointerType>()->getPointeeType();
226 }
227 
228 // CXXPseudoDestructorExpr
230  : Type(Info)
231 {
232  Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
233 }
234 
236  Expr *Base, bool isArrow, SourceLocation OperatorLoc,
237  NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
238  SourceLocation ColonColonLoc, SourceLocation TildeLoc,
239  PseudoDestructorTypeStorage DestroyedType)
240  : Expr(CXXPseudoDestructorExprClass,
241  Context.BoundMemberTy,
243  /*isTypeDependent=*/(Base->isTypeDependent() ||
244  (DestroyedType.getTypeSourceInfo() &&
245  DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
246  /*isValueDependent=*/Base->isValueDependent(),
247  (Base->isInstantiationDependent() ||
248  (QualifierLoc &&
249  QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
250  (ScopeType &&
251  ScopeType->getType()->isInstantiationDependentType()) ||
252  (DestroyedType.getTypeSourceInfo() &&
253  DestroyedType.getTypeSourceInfo()->getType()
254  ->isInstantiationDependentType())),
255  // ContainsUnexpandedParameterPack
256  (Base->containsUnexpandedParameterPack() ||
257  (QualifierLoc &&
258  QualifierLoc.getNestedNameSpecifier()
259  ->containsUnexpandedParameterPack()) ||
260  (ScopeType &&
261  ScopeType->getType()->containsUnexpandedParameterPack()) ||
262  (DestroyedType.getTypeSourceInfo() &&
263  DestroyedType.getTypeSourceInfo()->getType()
264  ->containsUnexpandedParameterPack()))),
265  Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
266  OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
267  ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
268  DestroyedType(DestroyedType) { }
269 
271  if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
272  return TInfo->getType();
273 
274  return QualType();
275 }
276 
278  SourceLocation End = DestroyedType.getLocation();
279  if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
280  End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
281  return End;
282 }
283 
284 // UnresolvedLookupExpr
287  CXXRecordDecl *NamingClass,
288  NestedNameSpecifierLoc QualifierLoc,
289  SourceLocation TemplateKWLoc,
290  const DeclarationNameInfo &NameInfo,
291  bool ADL,
292  const TemplateArgumentListInfo *Args,
293  UnresolvedSetIterator Begin,
295 {
296  assert(Args || TemplateKWLoc.isValid());
297  unsigned num_args = Args ? Args->size() : 0;
298 
299  std::size_t Size =
300  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(1,
301  num_args);
302  void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedLookupExpr>());
303  return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
304  TemplateKWLoc, NameInfo,
305  ADL, /*Overload*/ true, Args,
306  Begin, End);
307 }
308 
311  bool HasTemplateKWAndArgsInfo,
312  unsigned NumTemplateArgs) {
313  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
314  std::size_t Size =
315  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
316  HasTemplateKWAndArgsInfo, NumTemplateArgs);
317  void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedLookupExpr>());
318  UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
320  return E;
321 }
322 
324  NestedNameSpecifierLoc QualifierLoc,
325  SourceLocation TemplateKWLoc,
326  const DeclarationNameInfo &NameInfo,
327  const TemplateArgumentListInfo *TemplateArgs,
328  UnresolvedSetIterator Begin,
330  bool KnownDependent,
331  bool KnownInstantiationDependent,
332  bool KnownContainsUnexpandedParameterPack)
333  : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
334  KnownDependent,
335  (KnownInstantiationDependent ||
336  NameInfo.isInstantiationDependent() ||
337  (QualifierLoc &&
338  QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
339  (KnownContainsUnexpandedParameterPack ||
340  NameInfo.containsUnexpandedParameterPack() ||
341  (QualifierLoc &&
342  QualifierLoc.getNestedNameSpecifier()
343  ->containsUnexpandedParameterPack()))),
344  NameInfo(NameInfo), QualifierLoc(QualifierLoc),
345  Results(nullptr), NumResults(End - Begin),
346  HasTemplateKWAndArgsInfo(TemplateArgs != nullptr ||
347  TemplateKWLoc.isValid()) {
348  NumResults = End - Begin;
349  if (NumResults) {
350  // Determine whether this expression is type-dependent.
351  for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
352  if ((*I)->getDeclContext()->isDependentContext() ||
353  isa<UnresolvedUsingValueDecl>(*I)) {
354  ExprBits.TypeDependent = true;
355  ExprBits.ValueDependent = true;
356  ExprBits.InstantiationDependent = true;
357  }
358  }
359 
360  Results = static_cast<DeclAccessPair *>(
361  C.Allocate(sizeof(DeclAccessPair) * NumResults,
362  llvm::alignOf<DeclAccessPair>()));
363  memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
364  }
365 
366  // If we have explicit template arguments, check for dependent
367  // template arguments and whether they contain any unexpanded pack
368  // expansions.
369  if (TemplateArgs) {
370  bool Dependent = false;
371  bool InstantiationDependent = false;
372  bool ContainsUnexpandedParameterPack = false;
373  getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(
374  TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(),
375  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
376 
377  if (Dependent) {
378  ExprBits.TypeDependent = true;
379  ExprBits.ValueDependent = true;
380  }
381  if (InstantiationDependent)
382  ExprBits.InstantiationDependent = true;
383  if (ContainsUnexpandedParameterPack)
384  ExprBits.ContainsUnexpandedParameterPack = true;
385  } else if (TemplateKWLoc.isValid()) {
386  getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
387  }
388 
389  if (isTypeDependent())
390  setType(C.DependentTy);
391 }
392 
394  UnresolvedSetIterator Begin,
396  assert(!Results && "Results already initialized!");
397  NumResults = End - Begin;
398  if (NumResults) {
399  Results = static_cast<DeclAccessPair *>(
400  C.Allocate(sizeof(DeclAccessPair) * NumResults,
401 
402  llvm::alignOf<DeclAccessPair>()));
403  memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
404  }
405 }
406 
408  if (isa<UnresolvedLookupExpr>(this))
409  return cast<UnresolvedLookupExpr>(this)->getNamingClass();
410  else
411  return cast<UnresolvedMemberExpr>(this)->getNamingClass();
412 }
413 
414 // DependentScopeDeclRefExpr
415 DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
416  NestedNameSpecifierLoc QualifierLoc,
417  SourceLocation TemplateKWLoc,
418  const DeclarationNameInfo &NameInfo,
419  const TemplateArgumentListInfo *Args)
420  : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
421  true, true,
422  (NameInfo.isInstantiationDependent() ||
423  (QualifierLoc &&
424  QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
425  (NameInfo.containsUnexpandedParameterPack() ||
426  (QualifierLoc &&
427  QualifierLoc.getNestedNameSpecifier()
428  ->containsUnexpandedParameterPack()))),
429  QualifierLoc(QualifierLoc), NameInfo(NameInfo),
430  HasTemplateKWAndArgsInfo(Args != nullptr || TemplateKWLoc.isValid())
431 {
432  if (Args) {
433  bool Dependent = true;
434  bool InstantiationDependent = true;
435  bool ContainsUnexpandedParameterPack
436  = ExprBits.ContainsUnexpandedParameterPack;
437  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
438  TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(),
439  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
440  ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
441  } else if (TemplateKWLoc.isValid()) {
442  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
443  TemplateKWLoc);
444  }
445 }
446 
449  NestedNameSpecifierLoc QualifierLoc,
450  SourceLocation TemplateKWLoc,
451  const DeclarationNameInfo &NameInfo,
452  const TemplateArgumentListInfo *Args) {
453  assert(QualifierLoc && "should be created for dependent qualifiers");
454  bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
455  std::size_t Size =
456  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
457  HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
458  void *Mem = C.Allocate(Size);
459  return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
460  TemplateKWLoc, NameInfo, Args);
461 }
462 
465  bool HasTemplateKWAndArgsInfo,
466  unsigned NumTemplateArgs) {
467  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
468  std::size_t Size =
469  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
470  HasTemplateKWAndArgsInfo, NumTemplateArgs);
471  void *Mem = C.Allocate(Size);
474  SourceLocation(),
475  DeclarationNameInfo(), nullptr);
476  E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
477  return E;
478 }
479 
481  if (isa<CXXTemporaryObjectExpr>(this))
482  return cast<CXXTemporaryObjectExpr>(this)->getLocStart();
483  return Loc;
484 }
485 
487  if (isa<CXXTemporaryObjectExpr>(this))
488  return cast<CXXTemporaryObjectExpr>(this)->getLocEnd();
489 
490  if (ParenOrBraceRange.isValid())
491  return ParenOrBraceRange.getEnd();
492 
493  SourceLocation End = Loc;
494  for (unsigned I = getNumArgs(); I > 0; --I) {
495  const Expr *Arg = getArg(I-1);
496  if (!Arg->isDefaultArgument()) {
497  SourceLocation NewEnd = Arg->getLocEnd();
498  if (NewEnd.isValid()) {
499  End = NewEnd;
500  break;
501  }
502  }
503  }
504 
505  return End;
506 }
507 
508 SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
510  if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
511  if (getNumArgs() == 1)
512  // Prefix operator
513  return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
514  else
515  // Postfix operator
516  return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
517  } else if (Kind == OO_Arrow) {
518  return getArg(0)->getSourceRange();
519  } else if (Kind == OO_Call) {
520  return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
521  } else if (Kind == OO_Subscript) {
522  return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
523  } else if (getNumArgs() == 1) {
524  return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
525  } else if (getNumArgs() == 2) {
526  return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
527  } else {
528  return getOperatorLoc();
529  }
530 }
531 
533  const Expr *Callee = getCallee()->IgnoreParens();
534  if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
535  return MemExpr->getBase();
536  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
537  if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
538  return BO->getLHS();
539 
540  // FIXME: Will eventually need to cope with member pointers.
541  return nullptr;
542 }
543 
545  if (const MemberExpr *MemExpr =
546  dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
547  return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
548 
549  // FIXME: Will eventually need to cope with member pointers.
550  return nullptr;
551 }
552 
553 
555  Expr* ThisArg = getImplicitObjectArgument();
556  if (!ThisArg)
557  return nullptr;
558 
559  if (ThisArg->getType()->isAnyPointerType())
560  return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
561 
562  return ThisArg->getType()->getAsCXXRecordDecl();
563 }
564 
565 
566 //===----------------------------------------------------------------------===//
567 // Named casts
568 //===----------------------------------------------------------------------===//
569 
570 /// getCastName - Get the name of the C++ cast being used, e.g.,
571 /// "static_cast", "dynamic_cast", "reinterpret_cast", or
572 /// "const_cast". The returned pointer must not be freed.
573 const char *CXXNamedCastExpr::getCastName() const {
574  switch (getStmtClass()) {
575  case CXXStaticCastExprClass: return "static_cast";
576  case CXXDynamicCastExprClass: return "dynamic_cast";
577  case CXXReinterpretCastExprClass: return "reinterpret_cast";
578  case CXXConstCastExprClass: return "const_cast";
579  default: return "<invalid cast>";
580  }
581 }
582 
584  ExprValueKind VK,
585  CastKind K, Expr *Op,
586  const CXXCastPath *BasePath,
587  TypeSourceInfo *WrittenTy,
588  SourceLocation L,
589  SourceLocation RParenLoc,
590  SourceRange AngleBrackets) {
591  unsigned PathSize = (BasePath ? BasePath->size() : 0);
592  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
594  new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
595  RParenLoc, AngleBrackets);
596  if (PathSize)
597  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
598  E->getTrailingObjects<CXXBaseSpecifier *>());
599  return E;
600 }
601 
603  unsigned PathSize) {
604  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
605  return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
606 }
607 
609  ExprValueKind VK,
610  CastKind K, Expr *Op,
611  const CXXCastPath *BasePath,
612  TypeSourceInfo *WrittenTy,
613  SourceLocation L,
614  SourceLocation RParenLoc,
615  SourceRange AngleBrackets) {
616  unsigned PathSize = (BasePath ? BasePath->size() : 0);
617  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
619  new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
620  RParenLoc, AngleBrackets);
621  if (PathSize)
622  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
623  E->getTrailingObjects<CXXBaseSpecifier *>());
624  return E;
625 }
626 
628  unsigned PathSize) {
629  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
630  return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
631 }
632 
633 /// isAlwaysNull - Return whether the result of the dynamic_cast is proven
634 /// to always be null. For example:
635 ///
636 /// struct A { };
637 /// struct B final : A { };
638 /// struct C { };
639 ///
640 /// C *f(B* b) { return dynamic_cast<C*>(b); }
642 {
643  QualType SrcType = getSubExpr()->getType();
644  QualType DestType = getType();
645 
646  if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
647  SrcType = SrcPTy->getPointeeType();
648  DestType = DestType->castAs<PointerType>()->getPointeeType();
649  }
650 
651  if (DestType->isVoidType())
652  return false;
653 
654  const CXXRecordDecl *SrcRD =
655  cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
656 
657  if (!SrcRD->hasAttr<FinalAttr>())
658  return false;
659 
660  const CXXRecordDecl *DestRD =
661  cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
662 
663  return !DestRD->isDerivedFrom(SrcRD);
664 }
665 
668  ExprValueKind VK, CastKind K, Expr *Op,
669  const CXXCastPath *BasePath,
670  TypeSourceInfo *WrittenTy, SourceLocation L,
671  SourceLocation RParenLoc,
672  SourceRange AngleBrackets) {
673  unsigned PathSize = (BasePath ? BasePath->size() : 0);
674  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
676  new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
677  RParenLoc, AngleBrackets);
678  if (PathSize)
679  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
680  E->getTrailingObjects<CXXBaseSpecifier *>());
681  return E;
682 }
683 
686  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
687  return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
688 }
689 
691  ExprValueKind VK, Expr *Op,
692  TypeSourceInfo *WrittenTy,
693  SourceLocation L,
694  SourceLocation RParenLoc,
695  SourceRange AngleBrackets) {
696  return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
697 }
698 
700  return new (C) CXXConstCastExpr(EmptyShell());
701 }
702 
705  TypeSourceInfo *Written, CastKind K, Expr *Op,
706  const CXXCastPath *BasePath,
708  unsigned PathSize = (BasePath ? BasePath->size() : 0);
709  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
711  new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
712  if (PathSize)
713  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
714  E->getTrailingObjects<CXXBaseSpecifier *>());
715  return E;
716 }
717 
719 CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
720  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
721  return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
722 }
723 
726 }
727 
729  return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd();
730 }
731 
734  if (getNumArgs() == 0)
735  return LOK_Template;
736  if (getNumArgs() == 2)
737  return LOK_String;
738 
739  assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
740  QualType ParamTy =
741  cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
742  if (ParamTy->isPointerType())
743  return LOK_Raw;
744  if (ParamTy->isAnyCharacterType())
745  return LOK_Character;
746  if (ParamTy->isIntegerType())
747  return LOK_Integer;
748  if (ParamTy->isFloatingType())
749  return LOK_Floating;
750 
751  llvm_unreachable("unknown kind of literal operator");
752 }
753 
755 #ifndef NDEBUG
757  assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
758 #endif
759  return getArg(0);
760 }
761 
763  return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
764 }
765 
766 CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc,
767  FieldDecl *Field, QualType T)
768  : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C),
769  T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType()
770  ? VK_XValue
771  : VK_RValue,
772  /*FIXME*/ OK_Ordinary, false, false, false, false),
773  Field(Field), Loc(Loc) {
774  assert(Field->hasInClassInitializer());
775 }
776 
778  const CXXDestructorDecl *Destructor) {
779  return new (C) CXXTemporary(Destructor);
780 }
781 
783  CXXTemporary *Temp,
784  Expr* SubExpr) {
785  assert((SubExpr->getType()->isRecordType() ||
786  SubExpr->getType()->isArrayType()) &&
787  "Expression bound to a temporary must have record or array type!");
788 
789  return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
790 }
791 
793  CXXConstructorDecl *Cons,
795  ArrayRef<Expr*> Args,
796  SourceRange ParenOrBraceRange,
797  bool HadMultipleCandidates,
798  bool ListInitialization,
799  bool StdInitListInitialization,
800  bool ZeroInitialization)
801  : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
802  Type->getType().getNonReferenceType(),
803  Type->getTypeLoc().getBeginLoc(),
804  Cons, false, Args,
805  HadMultipleCandidates,
806  ListInitialization,
807  StdInitListInitialization,
808  ZeroInitialization,
809  CXXConstructExpr::CK_Complete, ParenOrBraceRange),
810  Type(Type) {
811 }
812 
814  return Type->getTypeLoc().getBeginLoc();
815 }
816 
819  if (Loc.isInvalid() && getNumArgs())
820  Loc = getArg(getNumArgs()-1)->getLocEnd();
821  return Loc;
822 }
823 
825  SourceLocation Loc,
826  CXXConstructorDecl *D, bool Elidable,
827  ArrayRef<Expr*> Args,
828  bool HadMultipleCandidates,
829  bool ListInitialization,
830  bool StdInitListInitialization,
831  bool ZeroInitialization,
832  ConstructionKind ConstructKind,
833  SourceRange ParenOrBraceRange) {
834  return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
835  Elidable, Args,
836  HadMultipleCandidates, ListInitialization,
837  StdInitListInitialization,
838  ZeroInitialization, ConstructKind,
839  ParenOrBraceRange);
840 }
841 
843  QualType T, SourceLocation Loc,
844  CXXConstructorDecl *D, bool elidable,
845  ArrayRef<Expr*> args,
846  bool HadMultipleCandidates,
847  bool ListInitialization,
848  bool StdInitListInitialization,
849  bool ZeroInitialization,
850  ConstructionKind ConstructKind,
851  SourceRange ParenOrBraceRange)
852  : Expr(SC, T, VK_RValue, OK_Ordinary,
853  T->isDependentType(), T->isDependentType(),
854  T->isInstantiationDependentType(),
855  T->containsUnexpandedParameterPack()),
856  Constructor(D), Loc(Loc), ParenOrBraceRange(ParenOrBraceRange),
857  NumArgs(args.size()),
858  Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
859  ListInitialization(ListInitialization),
860  StdInitListInitialization(StdInitListInitialization),
861  ZeroInitialization(ZeroInitialization),
862  ConstructKind(ConstructKind), Args(nullptr)
863 {
864  if (NumArgs) {
865  Args = new (C) Stmt*[args.size()];
866 
867  for (unsigned i = 0; i != args.size(); ++i) {
868  assert(args[i] && "NULL argument in CXXConstructExpr");
869 
870  if (args[i]->isValueDependent())
871  ExprBits.ValueDependent = true;
872  if (args[i]->isInstantiationDependent())
873  ExprBits.InstantiationDependent = true;
874  if (args[i]->containsUnexpandedParameterPack())
875  ExprBits.ContainsUnexpandedParameterPack = true;
876 
877  Args[i] = args[i];
878  }
879  }
880 }
881 
883  LambdaCaptureKind Kind, VarDecl *Var,
884  SourceLocation EllipsisLoc)
885  : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
886 {
887  unsigned Bits = 0;
888  if (Implicit)
889  Bits |= Capture_Implicit;
890 
891  switch (Kind) {
892  case LCK_This:
893  assert(!Var && "'this' capture cannot have a variable!");
894  break;
895 
896  case LCK_ByCopy:
897  Bits |= Capture_ByCopy;
898  // Fall through
899  case LCK_ByRef:
900  assert(Var && "capture must have a variable!");
901  break;
902  case LCK_VLAType:
903  assert(!Var && "VLA type capture cannot have a variable!");
904  Bits |= Capture_ByCopy;
905  break;
906  }
907  DeclAndBits.setInt(Bits);
908 }
909 
911  Decl *D = DeclAndBits.getPointer();
912  bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
913  if (!D)
914  return CapByCopy ? LCK_VLAType : LCK_This;
915 
916  return CapByCopy ? LCK_ByCopy : LCK_ByRef;
917 }
918 
919 LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
920  LambdaCaptureDefault CaptureDefault,
921  SourceLocation CaptureDefaultLoc,
922  ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
923  bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
924  ArrayRef<VarDecl *> ArrayIndexVars,
925  ArrayRef<unsigned> ArrayIndexStarts,
926  SourceLocation ClosingBrace,
927  bool ContainsUnexpandedParameterPack)
928  : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(),
929  T->isDependentType(), T->isDependentType(),
930  ContainsUnexpandedParameterPack),
931  IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
932  NumCaptures(Captures.size()), CaptureDefault(CaptureDefault),
933  ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType),
934  ClosingBrace(ClosingBrace) {
935  assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
936  CXXRecordDecl *Class = getLambdaClass();
937  CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
938 
939  // FIXME: Propagate "has unexpanded parameter pack" bit.
940 
941  // Copy captures.
942  const ASTContext &Context = Class->getASTContext();
943  Data.NumCaptures = NumCaptures;
944  Data.NumExplicitCaptures = 0;
945  Data.Captures =
946  (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures);
947  LambdaCapture *ToCapture = Data.Captures;
948  for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
949  if (Captures[I].isExplicit())
950  ++Data.NumExplicitCaptures;
951 
952  *ToCapture++ = Captures[I];
953  }
954 
955  // Copy initialization expressions for the non-static data members.
956  Stmt **Stored = getStoredStmts();
957  for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
958  *Stored++ = CaptureInits[I];
959 
960  // Copy the body of the lambda.
961  *Stored++ = getCallOperator()->getBody();
962 
963  // Copy the array index variables, if any.
964  HasArrayIndexVars = !ArrayIndexVars.empty();
965  if (HasArrayIndexVars) {
966  assert(ArrayIndexStarts.size() == NumCaptures);
967  memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
968  sizeof(VarDecl *) * ArrayIndexVars.size());
969  memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
970  sizeof(unsigned) * Captures.size());
971  getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
972  }
973 }
974 
976  const ASTContext &Context, CXXRecordDecl *Class,
977  SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault,
978  SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
979  bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
980  ArrayRef<VarDecl *> ArrayIndexVars, ArrayRef<unsigned> ArrayIndexStarts,
981  SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) {
982  // Determine the type of the expression (i.e., the type of the
983  // function object we're creating).
984  QualType T = Context.getTypeDeclType(Class);
985 
986  unsigned Size = totalSizeToAlloc<Stmt *, unsigned, VarDecl *>(
987  Captures.size() + 1, ArrayIndexVars.empty() ? 0 : Captures.size() + 1,
988  ArrayIndexVars.size());
989  void *Mem = Context.Allocate(Size);
990  return new (Mem) LambdaExpr(T, IntroducerRange,
991  CaptureDefault, CaptureDefaultLoc, Captures,
992  ExplicitParams, ExplicitResultType,
993  CaptureInits, ArrayIndexVars, ArrayIndexStarts,
994  ClosingBrace, ContainsUnexpandedParameterPack);
995 }
996 
998  unsigned NumCaptures,
999  unsigned NumArrayIndexVars) {
1000  unsigned Size = totalSizeToAlloc<Stmt *, unsigned, VarDecl *>(
1001  NumCaptures + 1, NumArrayIndexVars ? NumCaptures + 1 : 0,
1002  NumArrayIndexVars);
1003  void *Mem = C.Allocate(Size);
1004  return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
1005 }
1006 
1008  return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
1010 }
1011 
1013  return getLambdaClass()->getLambdaData().Captures;
1014 }
1015 
1017  return capture_begin() + NumCaptures;
1018 }
1019 
1022 }
1023 
1025  return capture_begin();
1026 }
1027 
1029  struct CXXRecordDecl::LambdaDefinitionData &Data
1030  = getLambdaClass()->getLambdaData();
1031  return Data.Captures + Data.NumExplicitCaptures;
1032 }
1033 
1036 }
1037 
1039  return explicit_capture_end();
1040 }
1041 
1043  return capture_end();
1044 }
1045 
1048 }
1049 
1052  assert(HasArrayIndexVars && "No array index-var data?");
1053 
1054  unsigned Index = Iter - capture_init_begin();
1055  assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
1056  "Capture index out-of-range");
1057  VarDecl *const *IndexVars = getArrayIndexVars();
1058  const unsigned *IndexStarts = getArrayIndexStarts();
1059  return llvm::makeArrayRef(IndexVars + IndexStarts[Index],
1060  IndexVars + IndexStarts[Index + 1]);
1061 }
1062 
1064  return getType()->getAsCXXRecordDecl();
1065 }
1066 
1068  CXXRecordDecl *Record = getLambdaClass();
1069  return Record->getLambdaCallOperator();
1070 }
1071 
1073  CXXRecordDecl *Record = getLambdaClass();
1074  return Record->getGenericLambdaTemplateParameterList();
1075 
1076 }
1077 
1079  // FIXME: this mutation in getBody is bogus. It should be
1080  // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I
1081  // don't understand, that doesn't work.
1082  if (!getStoredStmts()[NumCaptures])
1083  *const_cast<clang::Stmt **>(&getStoredStmts()[NumCaptures]) =
1084  getCallOperator()->getBody();
1085 
1086  return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1087 }
1088 
1090  return !getCallOperator()->isConst();
1091 }
1092 
1093 ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1094  ArrayRef<CleanupObject> objects)
1095  : Expr(ExprWithCleanupsClass, subexpr->getType(),
1096  subexpr->getValueKind(), subexpr->getObjectKind(),
1097  subexpr->isTypeDependent(), subexpr->isValueDependent(),
1098  subexpr->isInstantiationDependent(),
1099  subexpr->containsUnexpandedParameterPack()),
1100  SubExpr(subexpr) {
1101  ExprWithCleanupsBits.NumObjects = objects.size();
1102  for (unsigned i = 0, e = objects.size(); i != e; ++i)
1103  getTrailingObjects<CleanupObject>()[i] = objects[i];
1104 }
1105 
1107  ArrayRef<CleanupObject> objects) {
1108  void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
1109  llvm::alignOf<ExprWithCleanups>());
1110  return new (buffer) ExprWithCleanups(subexpr, objects);
1111 }
1112 
1113 ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1114  : Expr(ExprWithCleanupsClass, empty) {
1115  ExprWithCleanupsBits.NumObjects = numObjects;
1116 }
1117 
1119  EmptyShell empty,
1120  unsigned numObjects) {
1121  void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
1122  llvm::alignOf<ExprWithCleanups>());
1123  return new (buffer) ExprWithCleanups(empty, numObjects);
1124 }
1125 
1126 CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
1127  SourceLocation LParenLoc,
1128  ArrayRef<Expr*> Args,
1129  SourceLocation RParenLoc)
1130  : Expr(CXXUnresolvedConstructExprClass,
1131  Type->getType().getNonReferenceType(),
1132  (Type->getType()->isLValueReferenceType() ? VK_LValue
1133  :Type->getType()->isRValueReferenceType()? VK_XValue
1134  :VK_RValue),
1135  OK_Ordinary,
1136  Type->getType()->isDependentType(), true, true,
1137  Type->getType()->containsUnexpandedParameterPack()),
1138  Type(Type),
1139  LParenLoc(LParenLoc),
1140  RParenLoc(RParenLoc),
1141  NumArgs(Args.size()) {
1142  Expr **StoredArgs = getTrailingObjects<Expr *>();
1143  for (unsigned I = 0; I != Args.size(); ++I) {
1144  if (Args[I]->containsUnexpandedParameterPack())
1145  ExprBits.ContainsUnexpandedParameterPack = true;
1146 
1147  StoredArgs[I] = Args[I];
1148  }
1149 }
1150 
1153  TypeSourceInfo *Type,
1154  SourceLocation LParenLoc,
1155  ArrayRef<Expr*> Args,
1156  SourceLocation RParenLoc) {
1157  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1158  return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
1159 }
1160 
1163  Stmt::EmptyShell Empty;
1164  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1165  return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1166 }
1167 
1169  return Type->getTypeLoc().getBeginLoc();
1170 }
1171 
1172 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1173  const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
1174  SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1175  SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1176  DeclarationNameInfo MemberNameInfo,
1177  const TemplateArgumentListInfo *TemplateArgs)
1178  : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, VK_LValue,
1180  ((Base && Base->containsUnexpandedParameterPack()) ||
1181  (QualifierLoc &&
1182  QualifierLoc.getNestedNameSpecifier()
1183  ->containsUnexpandedParameterPack()) ||
1184  MemberNameInfo.containsUnexpandedParameterPack())),
1185  Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1186  HasTemplateKWAndArgsInfo(TemplateArgs != nullptr ||
1187  TemplateKWLoc.isValid()),
1188  OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
1189  FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1190  MemberNameInfo(MemberNameInfo) {
1191  if (TemplateArgs) {
1192  bool Dependent = true;
1193  bool InstantiationDependent = true;
1194  bool ContainsUnexpandedParameterPack = false;
1195  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1196  TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1197  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
1198  if (ContainsUnexpandedParameterPack)
1199  ExprBits.ContainsUnexpandedParameterPack = true;
1200  } else if (TemplateKWLoc.isValid()) {
1201  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1202  TemplateKWLoc);
1203  }
1204 }
1205 
1208  Expr *Base, QualType BaseType, bool IsArrow,
1209  SourceLocation OperatorLoc,
1210  NestedNameSpecifierLoc QualifierLoc,
1211  SourceLocation TemplateKWLoc,
1212  NamedDecl *FirstQualifierFoundInScope,
1213  DeclarationNameInfo MemberNameInfo,
1214  const TemplateArgumentListInfo *TemplateArgs) {
1215  bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1216  unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1217  std::size_t Size =
1218  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1219  HasTemplateKWAndArgsInfo, NumTemplateArgs);
1220 
1221  void *Mem = C.Allocate(Size, llvm::alignOf<CXXDependentScopeMemberExpr>());
1222  return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1223  IsArrow, OperatorLoc,
1224  QualifierLoc,
1225  TemplateKWLoc,
1226  FirstQualifierFoundInScope,
1227  MemberNameInfo, TemplateArgs);
1228 }
1229 
1232  bool HasTemplateKWAndArgsInfo,
1233  unsigned NumTemplateArgs) {
1234  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1235  std::size_t Size =
1236  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1237  HasTemplateKWAndArgsInfo, NumTemplateArgs);
1238  void *Mem = C.Allocate(Size, llvm::alignOf<CXXDependentScopeMemberExpr>());
1240  = new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(),
1241  0, SourceLocation(),
1243  SourceLocation(), nullptr,
1244  DeclarationNameInfo(), nullptr);
1245  E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
1246  return E;
1247 }
1248 
1250  if (!Base)
1251  return true;
1252 
1253  return cast<Expr>(Base)->isImplicitCXXThis();
1254 }
1255 
1258  do {
1259  NamedDecl *decl = *begin;
1260  if (isa<UnresolvedUsingValueDecl>(decl))
1261  return false;
1262 
1263  // Unresolved member expressions should only contain methods and
1264  // method templates.
1265  if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1266  ->isStatic())
1267  return false;
1268  } while (++begin != end);
1269 
1270  return true;
1271 }
1272 
1273 UnresolvedMemberExpr::UnresolvedMemberExpr(const ASTContext &C,
1274  bool HasUnresolvedUsing,
1275  Expr *Base, QualType BaseType,
1276  bool IsArrow,
1277  SourceLocation OperatorLoc,
1278  NestedNameSpecifierLoc QualifierLoc,
1279  SourceLocation TemplateKWLoc,
1280  const DeclarationNameInfo &MemberNameInfo,
1281  const TemplateArgumentListInfo *TemplateArgs,
1282  UnresolvedSetIterator Begin,
1284  : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1285  MemberNameInfo, TemplateArgs, Begin, End,
1286  // Dependent
1287  ((Base && Base->isTypeDependent()) ||
1288  BaseType->isDependentType()),
1289  ((Base && Base->isInstantiationDependent()) ||
1290  BaseType->isInstantiationDependentType()),
1291  // Contains unexpanded parameter pack
1292  ((Base && Base->containsUnexpandedParameterPack()) ||
1293  BaseType->containsUnexpandedParameterPack())),
1294  IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1295  Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
1296 
1297  // Check whether all of the members are non-static member functions,
1298  // and if so, mark give this bound-member type instead of overload type.
1299  if (hasOnlyNonStaticMemberFunctions(Begin, End))
1300  setType(C.BoundMemberTy);
1301 }
1302 
1303 bool UnresolvedMemberExpr::isImplicitAccess() const {
1304  if (!Base)
1305  return true;
1306 
1307  return cast<Expr>(Base)->isImplicitCXXThis();
1308 }
1309 
1311  const ASTContext &C, bool HasUnresolvedUsing, Expr *Base, QualType BaseType,
1312  bool IsArrow, SourceLocation OperatorLoc,
1313  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1314  const DeclarationNameInfo &MemberNameInfo,
1315  const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1316  UnresolvedSetIterator End) {
1317  bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1318  std::size_t Size =
1319  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1320  HasTemplateKWAndArgsInfo, TemplateArgs ? TemplateArgs->size() : 0);
1321 
1322  void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedMemberExpr>());
1323  return new (Mem) UnresolvedMemberExpr(
1324  C, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc,
1325  TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
1326 }
1327 
1330  bool HasTemplateKWAndArgsInfo,
1331  unsigned NumTemplateArgs) {
1332  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1333  std::size_t Size =
1334  totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1335  HasTemplateKWAndArgsInfo, NumTemplateArgs);
1336 
1337  void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedMemberExpr>());
1338  UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
1340  return E;
1341 }
1342 
1344  // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1345 
1346  // If there was a nested name specifier, it names the naming class.
1347  // It can't be dependent: after all, we were actually able to do the
1348  // lookup.
1349  CXXRecordDecl *Record = nullptr;
1350  auto *NNS = getQualifier();
1351  if (NNS && NNS->getKind() != NestedNameSpecifier::Super) {
1352  const Type *T = getQualifier()->getAsType();
1353  assert(T && "qualifier in member expression does not name type");
1354  Record = T->getAsCXXRecordDecl();
1355  assert(Record && "qualifier in member expression does not name record");
1356  }
1357  // Otherwise the naming class must have been the base class.
1358  else {
1359  QualType BaseType = getBaseType().getNonReferenceType();
1360  if (isArrow()) {
1361  const PointerType *PT = BaseType->getAs<PointerType>();
1362  assert(PT && "base of arrow member access is not pointer");
1363  BaseType = PT->getPointeeType();
1364  }
1365 
1366  Record = BaseType->getAsCXXRecordDecl();
1367  assert(Record && "base of member expression does not name record");
1368  }
1369 
1370  return Record;
1371 }
1372 
1375  NamedDecl *Pack, SourceLocation PackLoc,
1376  SourceLocation RParenLoc,
1378  ArrayRef<TemplateArgument> PartialArgs) {
1379  void *Storage =
1380  Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
1381  return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1382  PackLoc, RParenLoc, Length, PartialArgs);
1383 }
1384 
1386  unsigned NumPartialArgs) {
1387  void *Storage =
1388  Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
1389  return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1390 }
1391 
1392 SubstNonTypeTemplateParmPackExpr::
1393 SubstNonTypeTemplateParmPackExpr(QualType T,
1394  NonTypeTemplateParmDecl *Param,
1395  SourceLocation NameLoc,
1396  const TemplateArgument &ArgPack)
1397  : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
1398  true, true, true, true),
1399  Param(Param), Arguments(ArgPack.pack_begin()),
1400  NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1401 
1403  return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
1404 }
1405 
1406 FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1407  SourceLocation NameLoc,
1408  unsigned NumParams,
1409  ParmVarDecl *const *Params)
1410  : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true,
1411  true, true),
1412  ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1413  if (Params)
1414  std::uninitialized_copy(Params, Params + NumParams,
1415  getTrailingObjects<ParmVarDecl *>());
1416 }
1417 
1420  ParmVarDecl *ParamPack, SourceLocation NameLoc,
1421  ArrayRef<ParmVarDecl *> Params) {
1422  return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(Params.size())))
1423  FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1424 }
1425 
1428  unsigned NumParams) {
1429  return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(NumParams)))
1430  FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
1431 }
1432 
1434  unsigned ManglingNumber) {
1435  // We only need extra state if we have to remember more than just the Stmt.
1436  if (!ExtendedBy)
1437  return;
1438 
1439  // We may need to allocate extra storage for the mangling number and the
1440  // extended-by ValueDecl.
1441  if (!State.is<ExtraState *>()) {
1442  auto ES = new (ExtendedBy->getASTContext()) ExtraState;
1443  ES->Temporary = State.get<Stmt *>();
1444  State = ES;
1445  }
1446 
1447  auto ES = State.get<ExtraState *>();
1448  ES->ExtendingDecl = ExtendedBy;
1449  ES->ManglingNumber = ManglingNumber;
1450 }
1451 
1452 TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1454  SourceLocation RParenLoc,
1455  bool Value)
1456  : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1457  /*TypeDependent=*/false,
1458  /*ValueDependent=*/false,
1459  /*InstantiationDependent=*/false,
1460  /*ContainsUnexpandedParameterPack=*/false),
1461  Loc(Loc), RParenLoc(RParenLoc)
1462 {
1463  TypeTraitExprBits.Kind = Kind;
1464  TypeTraitExprBits.Value = Value;
1465  TypeTraitExprBits.NumArgs = Args.size();
1466 
1467  TypeSourceInfo **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1468 
1469  for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1470  if (Args[I]->getType()->isDependentType())
1471  setValueDependent(true);
1472  if (Args[I]->getType()->isInstantiationDependentType())
1474  if (Args[I]->getType()->containsUnexpandedParameterPack())
1476 
1477  ToArgs[I] = Args[I];
1478  }
1479 }
1480 
1482  SourceLocation Loc,
1483  TypeTrait Kind,
1485  SourceLocation RParenLoc,
1486  bool Value) {
1487  void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
1488  return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1489 }
1490 
1492  unsigned NumArgs) {
1493  void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
1494  return new (Mem) TypeTraitExpr(EmptyShell());
1495 }
1496 
1497 void ArrayTypeTraitExpr::anchor() { }
Raw form: operator "" X (const char *)
Definition: ExprCXX.h:408
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1292
void setValueDependent(bool VD)
Set whether this expression is value-dependent or not.
Definition: Expr.h:149
Defines the clang::ASTContext interface.
LiteralOperatorKind
The kind of literal operator which is invoked.
Definition: ExprCXX.h:407
operator "" X (long double)
Definition: ExprCXX.h:411
CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew, FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, ArrayRef< Expr * > placementArgs, SourceRange typeIdParens, Expr *arraySize, InitializationStyle initializationStyle, Expr *initializer, QualType ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange directInitRange)
Definition: ExprCXX.cpp:136
SourceLocation getEnd() const
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2147
unsigned Length
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:1997
A (possibly-)qualified type.
Definition: Type.h:575
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:211
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2199
static CXXDependentScopeMemberExpr * Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1207
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2191
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:1757
static CXXConstructExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, CXXConstructorDecl *D, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Definition: ExprCXX.cpp:824
static UnresolvedLookupExpr * Create(const ASTContext &C, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool ADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.h:2634
StringRef getUuidAsStringRef(ASTContext &Context) const
Definition: ExprCXX.cpp:115
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1680
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:882
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
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:608
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
bool isRecordType() const
Definition: Type.h:5362
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:77
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:23
void setType(QualType t)
Definition: Expr.h:126
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2586
Defines the C++ template declaration subclasses.
capture_range captures() const
Retrieve this lambda's captures.
Definition: ExprCXX.cpp:1020
The base class of the type hierarchy.
Definition: Type.h:1249
std::unique_ptr< llvm::MemoryBuffer > Buffer
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1149
A container of type source information.
Definition: Decl.h:61
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.cpp:724
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:704
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2134
SourceLocation getLocEnd() const LLVM_READONLY
Definition: ExprCXX.cpp:817
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition: ExprCXX.cpp:1012
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition: ExprCXX.h:1581
SourceRange getSourceRange() const LLVM_READONLY
Definition: ExprCXX.h:1909
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
const Expr * getCallee() const
Definition: Expr.h:2170
SourceLocation getLocEnd() const LLVM_READONLY
Definition: ExprCXX.cpp:277
static FunctionParmPackExpr * CreateEmpty(const ASTContext &Context, unsigned NumParams)
Definition: ExprCXX.cpp:1427
static DependentScopeDeclRefExpr * CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:464
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:319
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:48
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
Definition: ExprCXX.h:87
void setContainsUnexpandedParameterPack(bool PP=true)
Set the bit that describes whether this expression contains an unexpanded parameter pack...
Definition: Expr.h:217
void initializeResults(const ASTContext &C, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:393
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:2847
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1521
iterator begin() const
Definition: Type.h:4072
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1299
QualType getBaseType() const
Definition: ExprCXX.h:3345
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Definition: Expr.cpp:3257
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isVoidType() const
Definition: Type.h:5546
The collection of all-type qualifiers we support.
Definition: Type.h:116
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:238
static CXXUnresolvedConstructExpr * Create(const ASTContext &C, TypeSourceInfo *Type, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc)
Definition: ExprCXX.cpp:1152
void AllocateArgsArray(const ASTContext &C, bool isArray, unsigned numPlaceArgs, bool hasInitializer)
Definition: ExprCXX.cpp:200
bool isConst() const
Definition: DeclCXX.h:1742
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
bool hasAttr() const
Definition: DeclBase.h:498
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
A C++ nested-name-specifier augmented with source location information.
LineState State
bool isReferenceType() const
Definition: Type.h:5314
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to 'this' in C++.
Definition: Expr.cpp:2700
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:34
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2209
bool isAnyPointerType() const
Definition: Type.h:5308
CXXRecordDecl * getNamingClass() const
Gets the naming class of this lookup, if any.
Definition: ExprCXX.cpp:407
Expr * getImplicitObjectArgument() const
Retrieves the implicit object argument for the member call.
Definition: ExprCXX.cpp:532
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:259
CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons, TypeSourceInfo *Type, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition: ExprCXX.cpp:792
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:28
SourceRange getLocalSourceRange() const
Get the local source range.
Definition: TypeLoc.h:134
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr...
Definition: ExprCXX.cpp:28
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1067
Represents a C++ member access expression for which lookup produced a set of overloaded functions...
Definition: ExprCXX.h:3268
Expr * getSubExpr()
Definition: Expr.h:2662
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:1191
SourceLocation getRParenLoc() const
Definition: Expr.h:2266
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:102
T * getAttr() const
Definition: DeclBase.h:495
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:170
bool isAlwaysNull() const
isAlwaysNull - Return whether the result of the dynamic_cast is proven to always be null...
Definition: ExprCXX.cpp:641
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
A convenient class for passing around template argument information.
Definition: TemplateBase.h:517
ArrayRef< VarDecl * > getCaptureInitIndexVars(const_capture_init_iterator Iter) const
Retrieve the set of index variables used in the capture initializer of an array captured by copy...
Definition: ExprCXX.cpp:1051
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
Definition: ExprCXX.h:1595
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:1851
An x-value expression is a reference to an object with independent storage but which can be "moved"...
Definition: Specifiers.h:111
Expr * getExprOperand() const
Definition: ExprCXX.h:614
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition: ExprCXX.cpp:1016
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2875
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:146
InitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition: ExprCXX.h:1844
New-expression has a C++98 paren-delimited initializer.
Definition: ExprCXX.h:1765
SourceLocation getLocEnd() const LLVM_READONLY
Definition: ExprCXX.cpp:486
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2013
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
Definition: LambdaCapture.h:93
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:217
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1106
CompoundStmt * getBody() const
Retrieve the body of the lambda.
Definition: ExprCXX.cpp:1078
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1422
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
Definition: ExprCXX.cpp:50
iterator end() const
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to...
Definition: Expr.h:2796
An ordinary object is located at an address in memory.
Definition: Specifiers.h:118
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3034
capture_iterator implicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of implicit lambda captures.
Definition: ExprCXX.cpp:1042
detail::InMemoryDirectory::const_iterator I
QualType getType() const
Definition: Decl.h:530
bool isInvalid() const
New-expression has no initializer as written.
Definition: ExprCXX.h:1764
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
SourceLocation getLocation() const
Definition: ExprCXX.h:2021
static LambdaExpr * CreateDeserialized(const ASTContext &C, unsigned NumCaptures, unsigned NumArrayIndexVars)
Construct a new lambda expression that will be deserialized from an external source.
Definition: ExprCXX.cpp:997
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:666
ASTTemplateKWAndArgsInfo * getTrailingASTTemplateKWAndArgsInfo()
Return the optional template keyword and arguments info.
Definition: ExprCXX.h:3403
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:539
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3041
CXXMethodDecl * getMethodDecl() const
Retrieves the declaration of the called method.
Definition: ExprCXX.cpp:544
CastKind
CastKind - The kind of operation required for a conversion.
ASTContext * Context
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Definition: Expr.h:188
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
bool HasTemplateKWAndArgsInfo
Whether the name includes info for explicit template keyword and arguments.
Definition: ExprCXX.h:2419
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:226
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:415
bool isMutable() const
Determine whether the lambda is mutable, meaning that any captures values can be modified.
Definition: ExprCXX.cpp:1089
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:521
Expr - This represents one expression.
Definition: Expr.h:104
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:99
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.cpp:813
A C++ const_cast expression (C++ [expr.const.cast]).
Definition: ExprCXX.h:356
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2345
New-expression has a C++11 list-initializer.
Definition: ExprCXX.h:1766
CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T, SourceLocation Loc, CXXConstructorDecl *d, bool elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Definition: ExprCXX.cpp:842
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:583
static CXXReinterpretCastExpr * CreateEmpty(const ASTContext &Context, unsigned pathSize)
Definition: ExprCXX.cpp:685
DeclContext * getDeclContext()
Definition: DeclBase.h:393
bool isFloatingType() const
Definition: Type.cpp:1777
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:3555
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
static DependentScopeDeclRefExpr * Create(const ASTContext &C, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:448
Defines the clang::TypeLoc interface and its subclasses.
CXXRecordDecl * getNamingClass() const
Retrieve the naming class of this lookup.
Definition: ExprCXX.cpp:1343
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition: Expr.h:684
bool isExplicit() const
Determine whether this was an explicit capture (written between the square brackets introducing the l...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool shouldNullCheckAllocation(const ASTContext &Ctx) const
True if the allocation result needs to be null-checked.
Definition: ExprCXX.cpp:210
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1751
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:984
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:3988
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
bool isGLValue() const
Definition: Expr.h:249
capture_iterator implicit_capture_begin() const
Retrieve an iterator pointing to the first implicit lambda capture.
Definition: ExprCXX.cpp:1038
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.h:96
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:910
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
Definition: Decl.cpp:2497
Expr * getArgument()
Definition: ExprCXX.h:1974
bool isArray() const
Definition: ExprCXX.h:1813
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:215
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:274
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.cpp:131
#define false
Definition: stdbool.h:33
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:690
Kind
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:782
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
Definition: ExprCXX.h:2402
operator "" X (const CharT *, size_t)
Definition: ExprCXX.h:412
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:187
Raw form: operator "" X<cs...> ()
Definition: ExprCXX.h:409
static CXXDynamicCastExpr * CreateEmpty(const ASTContext &Context, unsigned pathSize)
Definition: ExprCXX.cpp:627
CXXRecordDecl * getRecordDecl() const
Retrieves the CXXRecordDecl for the underlying type of the implicit object argument.
Definition: ExprCXX.cpp:554
Encodes a location in the source.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5089
Represents a C++ temporary.
Definition: ExprCXX.h:1075
static CXXDependentScopeMemberExpr * CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:1231
static CXXConstCastExpr * CreateEmpty(const ASTContext &Context)
Definition: ExprCXX.cpp:699
bool isValid() const
Return true if this is a valid SourceLocation object.
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1374
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:311
bool isValid() const
static const UuidAttr * GetUuidAttrOfType(QualType QT, bool *HasMultipleGUIDsPtr=nullptr)
Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to a single GUID...
Definition: ExprCXX.cpp:58
OverloadExpr(StmtClass K, const ASTContext &C, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent, bool KnownContainsUnexpandedParameterPack)
Definition: ExprCXX.cpp:323
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it...
Definition: ExprCXX.cpp:1072
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition: ExprCXX.cpp:1402
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1701
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1118
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition: ExprCXX.cpp:1249
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.cpp:1168
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition: ExprCXX.cpp:1007
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:5640
LiteralOperatorKind getLiteralOperatorKind() const
Returns the kind of literal operator invocation which this expression represents. ...
Definition: ExprCXX.cpp:733
capture_iterator explicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of explicit lambda captures.
Definition: ExprCXX.cpp:1028
SourceLocation getBegin() const
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:164
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:5706
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '...
Definition: ExprCXX.h:3353
static SizeOfPackExpr * CreateDeserialized(ASTContext &Context, unsigned NumPartialArgs)
Definition: ExprCXX.cpp:1385
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:69
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:667
__SIZE_TYPE__ size_t
Definition: stddef.h:62
QualType getPointeeType() const
Definition: Type.h:2161
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:2706
static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, UnresolvedSetIterator end)
Definition: ExprCXX.cpp:1256
A POD class for pairing a NamedDecl* with an access specifier.
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:573
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1207
QualType getType() const
Definition: Expr.h:125
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
Represents a reference to a function parameter pack that has been substituted but not yet expanded...
Definition: ExprCXX.h:3786
Represents a template argument.
Definition: TemplateBase.h:40
void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber)
Definition: ExprCXX.cpp:1433
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Definition: ExprCXX.cpp:43
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
SourceLocation getLocStart() const LLVM_READONLY
Definition: TypeLoc.h:130
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2619
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition: ExprCXX.h:316
void setInstantiationDependent(bool ID)
Set whether this expression is instantiation-dependent or not.
Definition: Expr.h:193
bool isTypeOperand() const
Definition: ExprCXX.h:796
detail::InMemoryDirectory::const_iterator E
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2187
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
unsigned getNumArgs() const
Definition: ExprCXX.h:1272
SourceLocation getLocEnd() const LLVM_READONLY
Definition: ExprCXX.cpp:728
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:5255
Decl * getCalleeDecl()
Definition: Expr.cpp:1186
Capturing variable-length array type.
Definition: Lambda.h:38
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3544
TemplateArgumentLoc * getTrailingTemplateArgumentLoc()
Return the optional template arguments.
Definition: ExprCXX.h:3415
llvm::iterator_range< capture_iterator > capture_range
An iterator over a range of lambda captures.
Definition: ExprCXX.h:1538
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:1808
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5675
capture_iterator explicit_capture_begin() const
Retrieve an iterator pointing to the first explicit lambda capture.
Definition: ExprCXX.cpp:1024
static UnresolvedMemberExpr * CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:1329
CanQualType DependentTy
Definition: ASTContext.h:896
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1275
CanQualType BoundMemberTy
Definition: ASTContext.h:896
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1522
Expr * getExprOperand() const
Definition: ExprCXX.h:813
The template argument is a type.
Definition: TemplateBase.h:48
static CXXFunctionalCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize)
Definition: ExprCXX.cpp:719
Capturing the this pointer.
Definition: Lambda.h:35
Represents a base class of a C++ class.
Definition: DeclCXX.h:157
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
Definition: DeclCXX.cpp:1035
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, ParmVarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< ParmVarDecl * > Params)
Definition: ExprCXX.cpp:1419
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:2927
A template argument list.
Definition: DeclTemplate.h:172
static UnresolvedMemberExpr * Create(const ASTContext &C, 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:1310
static UnresolvedLookupExpr * CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:310
capture_range explicit_captures() const
Retrieve this lambda's explicit captures.
Definition: ExprCXX.cpp:1034
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2297
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:80
const IdentifierInfo * getUDSuffix() const
Returns the ud-suffix specified for this literal.
Definition: ExprCXX.cpp:762
void setEnd(SourceLocation e)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
static CXXStaticCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize)
Definition: ExprCXX.cpp:602
SourceLocation getLocStart() const LLVM_READONLY
Definition: ExprCXX.cpp:480
capture_range implicit_captures() const
Retrieve this lambda's implicit captures.
Definition: ExprCXX.cpp:1046
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:777
static CXXUnresolvedConstructExpr * CreateEmpty(const ASTContext &C, unsigned NumArgs)
Definition: ExprCXX.cpp:1162
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr.type.conv]).
Definition: ExprCXX.h:1315
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:1481
static TypeTraitExpr * CreateDeserialized(const ASTContext &C, unsigned NumArgs)
Definition: ExprCXX.cpp:1491
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:560
Capturing by reference.
Definition: Lambda.h:37
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:2561
SourceLocation getLocEnd() const LLVM_READONLY
Definition: ExprCXX.h:97
bool isArrayType() const
Definition: Type.h:5344
CXXPseudoDestructorExpr(const ASTContext &Context, Expr *Base, bool isArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
Definition: ExprCXX.cpp:235
#define true
Definition: stdbool.h:32
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:106
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:145
NestedNameSpecifier * getQualifier() const
Fetches the nested-name qualifier, if one was given.
Definition: ExprCXX.h:2512
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:270
bool isTypeOperand() const
Definition: ExprCXX.h:597
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< LambdaCapture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, ArrayRef< VarDecl * > ArrayIndexVars, ArrayRef< unsigned > ArrayIndexStarts, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:975
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1063
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
operator "" X (unsigned long long)
Definition: ExprCXX.h:410
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:5568
Expr * getCookedLiteral()
If this is not a raw user-defined literal, get the underlying cooked literal (representing the litera...
Definition: ExprCXX.cpp:754
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2433
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:77
bool hasInClassInitializer() const
hasInClassInitializer - Determine whether this member has a C++11 in-class initializer.
Definition: Decl.h:2324
bool isPointerType() const
Definition: Type.h:5305