Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 1 | //===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the subclesses of Expr class declared in ExprCXX.h |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 4ab984e | 2012-07-04 20:19:54 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/Attr.h" |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | a727cb9 | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 18 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 19 | #include "clang/AST/TypeLoc.h" |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 20 | #include "clang/Basic/IdentifierTable.h" |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 23 | |
Ted Kremenek | e3a0c14 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // Child Iterators for iterating over subexpressions/substatements |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Richard Smith | 6609443 | 2016-10-20 00:55:15 +0000 | [diff] [blame] | 28 | bool CXXOperatorCallExpr::isInfixBinaryOp() const { |
| 29 | // An infix binary operator is any operator with two arguments other than |
| 30 | // operator() and operator[]. Note that none of these operators can have |
| 31 | // default arguments, so it suffices to check the number of argument |
| 32 | // expressions. |
| 33 | if (getNumArgs() != 2) |
| 34 | return false; |
| 35 | |
| 36 | switch (getOperator()) { |
| 37 | case OO_Call: case OO_Subscript: |
| 38 | return false; |
| 39 | default: |
| 40 | return true; |
| 41 | } |
| 42 | } |
| 43 | |
Richard Smith | ef8bf43 | 2012-08-13 20:08:14 +0000 | [diff] [blame] | 44 | bool CXXTypeidExpr::isPotentiallyEvaluated() const { |
| 45 | if (isTypeOperand()) |
| 46 | return false; |
| 47 | |
| 48 | // C++11 [expr.typeid]p3: |
| 49 | // When typeid is applied to an expression other than a glvalue of |
| 50 | // polymorphic class type, [...] the expression is an unevaluated operand. |
| 51 | const Expr *E = getExprOperand(); |
| 52 | if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) |
| 53 | if (RD->isPolymorphic() && E->isGLValue()) |
| 54 | return true; |
| 55 | |
| 56 | return false; |
| 57 | } |
| 58 | |
David Majnemer | 143c55e | 2013-09-27 07:04:31 +0000 | [diff] [blame] | 59 | QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 60 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
David Majnemer | 143c55e | 2013-09-27 07:04:31 +0000 | [diff] [blame] | 61 | Qualifiers Quals; |
| 62 | return Context.getUnqualifiedArrayType( |
| 63 | Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 64 | } |
| 65 | |
David Majnemer | 143c55e | 2013-09-27 07:04:31 +0000 | [diff] [blame] | 66 | QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 67 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
David Majnemer | 143c55e | 2013-09-27 07:04:31 +0000 | [diff] [blame] | 68 | Qualifiers Quals; |
| 69 | return Context.getUnqualifiedArrayType( |
| 70 | Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 73 | // CXXScalarValueInitExpr |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 74 | SourceLocation CXXScalarValueInitExpr::getLocStart() const { |
| 75 | return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc; |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 78 | // CXXNewExpr |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 79 | CXXNewExpr::CXXNewExpr(const ASTContext &C, bool globalNew, |
| 80 | FunctionDecl *operatorNew, FunctionDecl *operatorDelete, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 81 | bool PassAlignment, bool usualArrayDeleteWantsSize, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 82 | ArrayRef<Expr*> placementArgs, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 83 | SourceRange typeIdParens, Expr *arraySize, |
| 84 | InitializationStyle initializationStyle, |
| 85 | Expr *initializer, QualType ty, |
| 86 | TypeSourceInfo *allocatedTypeInfo, |
David Blaikie | 7b97aef | 2012-11-07 00:12:38 +0000 | [diff] [blame] | 87 | SourceRange Range, SourceRange directInitRange) |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 88 | : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 89 | ty->isDependentType(), ty->isDependentType(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 90 | ty->isInstantiationDependentType(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 91 | ty->containsUnexpandedParameterPack()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 92 | SubExprs(nullptr), OperatorNew(operatorNew), OperatorDelete(operatorDelete), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 93 | AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), |
David Blaikie | 7b97aef | 2012-11-07 00:12:38 +0000 | [diff] [blame] | 94 | Range(Range), DirectInitRange(directInitRange), |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 95 | GlobalNew(globalNew), PassAlignment(PassAlignment), |
| 96 | UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 97 | assert((initializer != nullptr || initializationStyle == NoInit) && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 98 | "Only NoInit can have no initializer."); |
| 99 | StoredInitializationStyle = initializer ? initializationStyle + 1 : 0; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 100 | AllocateArgsArray(C, arraySize != nullptr, placementArgs.size(), |
| 101 | initializer != nullptr); |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 102 | unsigned i = 0; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 103 | if (Array) { |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 104 | if (arraySize->isInstantiationDependent()) |
| 105 | ExprBits.InstantiationDependent = true; |
| 106 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 107 | if (arraySize->containsUnexpandedParameterPack()) |
| 108 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 109 | |
Sebastian Redl | 351bb78 | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 110 | SubExprs[i++] = arraySize; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 113 | if (initializer) { |
| 114 | if (initializer->isInstantiationDependent()) |
| 115 | ExprBits.InstantiationDependent = true; |
| 116 | |
| 117 | if (initializer->containsUnexpandedParameterPack()) |
| 118 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 119 | |
| 120 | SubExprs[i++] = initializer; |
| 121 | } |
| 122 | |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 123 | for (unsigned j = 0; j != placementArgs.size(); ++j) { |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 124 | if (placementArgs[j]->isInstantiationDependent()) |
| 125 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 126 | if (placementArgs[j]->containsUnexpandedParameterPack()) |
| 127 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 128 | |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 129 | SubExprs[i++] = placementArgs[j]; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 130 | } |
David Blaikie | 3a0de21 | 2012-11-08 22:53:48 +0000 | [diff] [blame] | 131 | |
| 132 | switch (getInitializationStyle()) { |
| 133 | case CallInit: |
| 134 | this->Range.setEnd(DirectInitRange.getEnd()); break; |
| 135 | case ListInit: |
| 136 | this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break; |
Eli Friedman | 2dcbdc0 | 2013-06-17 22:35:10 +0000 | [diff] [blame] | 137 | default: |
| 138 | if (TypeIdParens.isValid()) |
| 139 | this->Range.setEnd(TypeIdParens.getEnd()); |
| 140 | break; |
David Blaikie | 3a0de21 | 2012-11-08 22:53:48 +0000 | [diff] [blame] | 141 | } |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 144 | void CXXNewExpr::AllocateArgsArray(const ASTContext &C, bool isArray, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 145 | unsigned numPlaceArgs, bool hasInitializer){ |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 146 | assert(SubExprs == nullptr && "SubExprs already allocated"); |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 147 | Array = isArray; |
| 148 | NumPlacementArgs = numPlaceArgs; |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 149 | |
| 150 | unsigned TotalSize = Array + hasInitializer + NumPlacementArgs; |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 151 | SubExprs = new (C) Stmt*[TotalSize]; |
| 152 | } |
| 153 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 154 | bool CXXNewExpr::shouldNullCheckAllocation(const ASTContext &Ctx) const { |
Richard Smith | 902a023 | 2015-02-14 01:52:20 +0000 | [diff] [blame] | 155 | return getOperatorNew()->getType()->castAs<FunctionProtoType>()->isNothrow( |
| 156 | Ctx) && |
| 157 | !getOperatorNew()->isReservedGlobalPlacementOperator(); |
John McCall | 75f9498 | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 158 | } |
Chris Lattner | abfb58d | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 159 | |
Sebastian Redl | bd150f4 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 160 | // CXXDeleteExpr |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 161 | QualType CXXDeleteExpr::getDestroyedType() const { |
| 162 | const Expr *Arg = getArgument(); |
Craig Silverstein | 20f7ab7 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 163 | // The type-to-delete may not be a pointer if it's a dependent type. |
Craig Silverstein | 3b9936f | 2010-10-20 00:56:01 +0000 | [diff] [blame] | 164 | const QualType ArgType = Arg->getType(); |
Craig Silverstein | 9e448da | 2010-11-16 07:16:25 +0000 | [diff] [blame] | 165 | |
| 166 | if (ArgType->isDependentType() && !ArgType->isPointerType()) |
| 167 | return QualType(); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 168 | |
Craig Silverstein | 20f7ab7 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 169 | return ArgType->getAs<PointerType>()->getPointeeType(); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 172 | // CXXPseudoDestructorExpr |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 173 | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
| 174 | : Type(Info) |
| 175 | { |
Abramo Bagnara | 1108e7b | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 176 | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 179 | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 180 | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
| 181 | NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, |
| 182 | SourceLocation ColonColonLoc, SourceLocation TildeLoc, |
| 183 | PseudoDestructorTypeStorage DestroyedType) |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 184 | : Expr(CXXPseudoDestructorExprClass, |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 185 | Context.BoundMemberTy, |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 186 | VK_RValue, OK_Ordinary, |
| 187 | /*isTypeDependent=*/(Base->isTypeDependent() || |
| 188 | (DestroyedType.getTypeSourceInfo() && |
| 189 | DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 190 | /*isValueDependent=*/Base->isValueDependent(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 191 | (Base->isInstantiationDependent() || |
| 192 | (QualifierLoc && |
| 193 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) || |
| 194 | (ScopeType && |
| 195 | ScopeType->getType()->isInstantiationDependentType()) || |
| 196 | (DestroyedType.getTypeSourceInfo() && |
| 197 | DestroyedType.getTypeSourceInfo()->getType() |
| 198 | ->isInstantiationDependentType())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 199 | // ContainsUnexpandedParameterPack |
| 200 | (Base->containsUnexpandedParameterPack() || |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 201 | (QualifierLoc && |
| 202 | QualifierLoc.getNestedNameSpecifier() |
| 203 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 204 | (ScopeType && |
| 205 | ScopeType->getType()->containsUnexpandedParameterPack()) || |
| 206 | (DestroyedType.getTypeSourceInfo() && |
| 207 | DestroyedType.getTypeSourceInfo()->getType() |
| 208 | ->containsUnexpandedParameterPack()))), |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 209 | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 210 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 211 | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
| 212 | DestroyedType(DestroyedType) { } |
| 213 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 214 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
| 215 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 216 | return TInfo->getType(); |
| 217 | |
| 218 | return QualType(); |
| 219 | } |
| 220 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 221 | SourceLocation CXXPseudoDestructorExpr::getLocEnd() const { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 222 | SourceLocation End = DestroyedType.getLocation(); |
| 223 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
Abramo Bagnara | 1108e7b | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 224 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 225 | return End; |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 226 | } |
| 227 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 228 | // UnresolvedLookupExpr |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 229 | UnresolvedLookupExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 230 | UnresolvedLookupExpr::Create(const ASTContext &C, |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 231 | CXXRecordDecl *NamingClass, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 232 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 233 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 234 | const DeclarationNameInfo &NameInfo, |
| 235 | bool ADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 236 | const TemplateArgumentListInfo *Args, |
| 237 | UnresolvedSetIterator Begin, |
| 238 | UnresolvedSetIterator End) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 239 | { |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 240 | assert(Args || TemplateKWLoc.isValid()); |
| 241 | unsigned num_args = Args ? Args->size() : 0; |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 242 | |
| 243 | std::size_t Size = |
| 244 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(1, |
| 245 | num_args); |
| 246 | void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedLookupExpr>()); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 247 | return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, |
| 248 | TemplateKWLoc, NameInfo, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 249 | ADL, /*Overload*/ true, Args, |
Richard Smith | b662674 | 2012-10-18 17:56:02 +0000 | [diff] [blame] | 250 | Begin, End); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 253 | UnresolvedLookupExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 254 | UnresolvedLookupExpr::CreateEmpty(const ASTContext &C, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 255 | bool HasTemplateKWAndArgsInfo, |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 256 | unsigned NumTemplateArgs) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 257 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 258 | std::size_t Size = |
| 259 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 260 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
| 261 | void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedLookupExpr>()); |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 262 | UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 263 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | 58e01ad | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 264 | return E; |
| 265 | } |
| 266 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 267 | OverloadExpr::OverloadExpr(StmtClass K, const ASTContext &C, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 268 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 269 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 270 | const DeclarationNameInfo &NameInfo, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 271 | const TemplateArgumentListInfo *TemplateArgs, |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 272 | UnresolvedSetIterator Begin, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 273 | UnresolvedSetIterator End, |
| 274 | bool KnownDependent, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 275 | bool KnownInstantiationDependent, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 276 | bool KnownContainsUnexpandedParameterPack) |
| 277 | : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, |
| 278 | KnownDependent, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 279 | (KnownInstantiationDependent || |
| 280 | NameInfo.isInstantiationDependent() || |
| 281 | (QualifierLoc && |
| 282 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 283 | (KnownContainsUnexpandedParameterPack || |
| 284 | NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 285 | (QualifierLoc && |
| 286 | QualifierLoc.getNestedNameSpecifier() |
| 287 | ->containsUnexpandedParameterPack()))), |
Benjamin Kramer | b73f76b | 2012-02-26 20:37:14 +0000 | [diff] [blame] | 288 | NameInfo(NameInfo), QualifierLoc(QualifierLoc), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 289 | Results(nullptr), NumResults(End - Begin), |
| 290 | HasTemplateKWAndArgsInfo(TemplateArgs != nullptr || |
| 291 | TemplateKWLoc.isValid()) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 292 | NumResults = End - Begin; |
| 293 | if (NumResults) { |
| 294 | // Determine whether this expression is type-dependent. |
| 295 | for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) { |
| 296 | if ((*I)->getDeclContext()->isDependentContext() || |
| 297 | isa<UnresolvedUsingValueDecl>(*I)) { |
| 298 | ExprBits.TypeDependent = true; |
| 299 | ExprBits.ValueDependent = true; |
Richard Smith | 47726b2 | 2012-08-13 21:29:18 +0000 | [diff] [blame] | 300 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | Results = static_cast<DeclAccessPair *>( |
| 305 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 306 | llvm::alignOf<DeclAccessPair>())); |
Benjamin Kramer | 04ec7e3 | 2015-02-01 20:31:36 +0000 | [diff] [blame] | 307 | memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair)); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // If we have explicit template arguments, check for dependent |
| 311 | // template arguments and whether they contain any unexpanded pack |
| 312 | // expansions. |
| 313 | if (TemplateArgs) { |
| 314 | bool Dependent = false; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 315 | bool InstantiationDependent = false; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 316 | bool ContainsUnexpandedParameterPack = false; |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 317 | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom( |
| 318 | TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(), |
| 319 | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 320 | |
| 321 | if (Dependent) { |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 322 | ExprBits.TypeDependent = true; |
| 323 | ExprBits.ValueDependent = true; |
| 324 | } |
| 325 | if (InstantiationDependent) |
| 326 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 327 | if (ContainsUnexpandedParameterPack) |
| 328 | ExprBits.ContainsUnexpandedParameterPack = true; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 329 | } else if (TemplateKWLoc.isValid()) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 330 | getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | if (isTypeDependent()) |
| 334 | setType(C.DependentTy); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 337 | void OverloadExpr::initializeResults(const ASTContext &C, |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 338 | UnresolvedSetIterator Begin, |
| 339 | UnresolvedSetIterator End) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 340 | assert(!Results && "Results already initialized!"); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 341 | NumResults = End - Begin; |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 342 | if (NumResults) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 343 | Results = static_cast<DeclAccessPair *>( |
| 344 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 345 | |
| 346 | llvm::alignOf<DeclAccessPair>())); |
Benjamin Kramer | 04ec7e3 | 2015-02-01 20:31:36 +0000 | [diff] [blame] | 347 | memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair)); |
Douglas Gregor | c69978f | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
John McCall | 8c12dc4 | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 351 | CXXRecordDecl *OverloadExpr::getNamingClass() const { |
| 352 | if (isa<UnresolvedLookupExpr>(this)) |
| 353 | return cast<UnresolvedLookupExpr>(this)->getNamingClass(); |
| 354 | else |
| 355 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
| 356 | } |
| 357 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 358 | // DependentScopeDeclRefExpr |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 359 | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T, |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 360 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 361 | SourceLocation TemplateKWLoc, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 362 | const DeclarationNameInfo &NameInfo, |
| 363 | const TemplateArgumentListInfo *Args) |
| 364 | : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, |
| 365 | true, true, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 366 | (NameInfo.isInstantiationDependent() || |
| 367 | (QualifierLoc && |
| 368 | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 369 | (NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 370 | (QualifierLoc && |
| 371 | QualifierLoc.getNestedNameSpecifier() |
| 372 | ->containsUnexpandedParameterPack()))), |
| 373 | QualifierLoc(QualifierLoc), NameInfo(NameInfo), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 374 | HasTemplateKWAndArgsInfo(Args != nullptr || TemplateKWLoc.isValid()) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 375 | { |
| 376 | if (Args) { |
| 377 | bool Dependent = true; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 378 | bool InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 379 | bool ContainsUnexpandedParameterPack |
| 380 | = ExprBits.ContainsUnexpandedParameterPack; |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 381 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 382 | TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(), |
| 383 | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 384 | ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 385 | } else if (TemplateKWLoc.isValid()) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 386 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 387 | TemplateKWLoc); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 391 | DependentScopeDeclRefExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 392 | DependentScopeDeclRefExpr::Create(const ASTContext &C, |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 393 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 394 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 395 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 396 | const TemplateArgumentListInfo *Args) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 397 | assert(QualifierLoc && "should be created for dependent qualifiers"); |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 398 | bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid(); |
| 399 | std::size_t Size = |
| 400 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 401 | HasTemplateKWAndArgsInfo, Args ? Args->size() : 0); |
| 402 | void *Mem = C.Allocate(Size); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 403 | return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc, |
| 404 | TemplateKWLoc, NameInfo, Args); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 407 | DependentScopeDeclRefExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 408 | DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &C, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 409 | bool HasTemplateKWAndArgsInfo, |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 410 | unsigned NumTemplateArgs) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 411 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 412 | std::size_t Size = |
| 413 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 414 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
| 415 | void *Mem = C.Allocate(Size); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 416 | DependentScopeDeclRefExpr *E |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 417 | = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 418 | SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 419 | DeclarationNameInfo(), nullptr); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 420 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 421 | return E; |
Argyrios Kyrtzidis | cd444d1a | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 424 | SourceLocation CXXConstructExpr::getLocStart() const { |
John McCall | 701417a | 2011-02-21 06:23:05 +0000 | [diff] [blame] | 425 | if (isa<CXXTemporaryObjectExpr>(this)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 426 | return cast<CXXTemporaryObjectExpr>(this)->getLocStart(); |
| 427 | return Loc; |
| 428 | } |
| 429 | |
| 430 | SourceLocation CXXConstructExpr::getLocEnd() const { |
| 431 | if (isa<CXXTemporaryObjectExpr>(this)) |
| 432 | return cast<CXXTemporaryObjectExpr>(this)->getLocEnd(); |
John McCall | 701417a | 2011-02-21 06:23:05 +0000 | [diff] [blame] | 433 | |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 434 | if (ParenOrBraceRange.isValid()) |
| 435 | return ParenOrBraceRange.getEnd(); |
Douglas Gregor | 15417cf | 2010-11-03 00:35:38 +0000 | [diff] [blame] | 436 | |
| 437 | SourceLocation End = Loc; |
| 438 | for (unsigned I = getNumArgs(); I > 0; --I) { |
| 439 | const Expr *Arg = getArg(I-1); |
| 440 | if (!Arg->isDefaultArgument()) { |
| 441 | SourceLocation NewEnd = Arg->getLocEnd(); |
| 442 | if (NewEnd.isValid()) { |
| 443 | End = NewEnd; |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 449 | return End; |
Ted Kremenek | 49ace5c | 2009-12-23 04:00:48 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Argyrios Kyrtzidis | d8e0769 | 2012-04-30 22:12:22 +0000 | [diff] [blame] | 452 | SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 453 | OverloadedOperatorKind Kind = getOperator(); |
| 454 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 455 | if (getNumArgs() == 1) |
| 456 | // Prefix operator |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 457 | return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 458 | else |
| 459 | // Postfix operator |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 460 | return SourceRange(getArg(0)->getLocStart(), getOperatorLoc()); |
Chandler Carruth | f20ec923 | 2011-04-02 09:47:38 +0000 | [diff] [blame] | 461 | } else if (Kind == OO_Arrow) { |
| 462 | return getArg(0)->getSourceRange(); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 463 | } else if (Kind == OO_Call) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 464 | return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 465 | } else if (Kind == OO_Subscript) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 466 | return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 467 | } else if (getNumArgs() == 1) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 468 | return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 469 | } else if (getNumArgs() == 2) { |
Argyrios Kyrtzidis | 5f20a7e | 2012-05-01 22:19:11 +0000 | [diff] [blame] | 470 | return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd()); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 471 | } else { |
Argyrios Kyrtzidis | d8e0769 | 2012-04-30 22:12:22 +0000 | [diff] [blame] | 472 | return getOperatorLoc(); |
Douglas Gregor | 993603d | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
Ted Kremenek | 98a24e3 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 476 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
Jordan Rose | 16fe35e | 2012-08-03 23:08:39 +0000 | [diff] [blame] | 477 | const Expr *Callee = getCallee()->IgnoreParens(); |
| 478 | if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee)) |
Douglas Gregor | 97fd6e2 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 479 | return MemExpr->getBase(); |
Jordan Rose | 16fe35e | 2012-08-03 23:08:39 +0000 | [diff] [blame] | 480 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee)) |
| 481 | if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) |
| 482 | return BO->getLHS(); |
Douglas Gregor | 97fd6e2 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 483 | |
| 484 | // FIXME: Will eventually need to cope with member pointers. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 485 | return nullptr; |
Douglas Gregor | 97fd6e2 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Ted Kremenek | 98a24e3 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 488 | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
| 489 | if (const MemberExpr *MemExpr = |
| 490 | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 491 | return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
| 492 | |
| 493 | // FIXME: Will eventually need to cope with member pointers. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 494 | return nullptr; |
Ted Kremenek | 98a24e3 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
David Blaikie | c0f5866 | 2012-05-03 16:25:49 +0000 | [diff] [blame] | 498 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const { |
Chandler Carruth | 00426b4 | 2010-10-27 06:55:41 +0000 | [diff] [blame] | 499 | Expr* ThisArg = getImplicitObjectArgument(); |
| 500 | if (!ThisArg) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 501 | return nullptr; |
Chandler Carruth | 00426b4 | 2010-10-27 06:55:41 +0000 | [diff] [blame] | 502 | |
| 503 | if (ThisArg->getType()->isAnyPointerType()) |
| 504 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
| 505 | |
| 506 | return ThisArg->getType()->getAsCXXRecordDecl(); |
| 507 | } |
| 508 | |
Douglas Gregor | ef986e8 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 509 | |
Douglas Gregor | e200adc | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 510 | //===----------------------------------------------------------------------===// |
| 511 | // Named casts |
| 512 | //===----------------------------------------------------------------------===// |
| 513 | |
| 514 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 515 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 516 | /// "const_cast". The returned pointer must not be freed. |
| 517 | const char *CXXNamedCastExpr::getCastName() const { |
| 518 | switch (getStmtClass()) { |
| 519 | case CXXStaticCastExprClass: return "static_cast"; |
| 520 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 521 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 522 | case CXXConstCastExprClass: return "const_cast"; |
| 523 | default: return "<invalid cast>"; |
| 524 | } |
| 525 | } |
Douglas Gregor | dd04d33 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 526 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 527 | CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 528 | ExprValueKind VK, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 529 | CastKind K, Expr *Op, |
| 530 | const CXXCastPath *BasePath, |
| 531 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 532 | SourceLocation L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 533 | SourceLocation RParenLoc, |
| 534 | SourceRange AngleBrackets) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 535 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 536 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 537 | CXXStaticCastExpr *E = |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 538 | new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 539 | RParenLoc, AngleBrackets); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 540 | if (PathSize) |
| 541 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
| 542 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 543 | return E; |
| 544 | } |
| 545 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 546 | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 547 | unsigned PathSize) { |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 548 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 549 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
| 550 | } |
| 551 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 552 | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 553 | ExprValueKind VK, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 554 | CastKind K, Expr *Op, |
| 555 | const CXXCastPath *BasePath, |
| 556 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 557 | SourceLocation L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 558 | SourceLocation RParenLoc, |
| 559 | SourceRange AngleBrackets) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 560 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 561 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 562 | CXXDynamicCastExpr *E = |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 563 | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 564 | RParenLoc, AngleBrackets); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 565 | if (PathSize) |
| 566 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
| 567 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 568 | return E; |
| 569 | } |
| 570 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 571 | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 572 | unsigned PathSize) { |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 573 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 574 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
| 575 | } |
| 576 | |
Anders Carlsson | 267c0c9 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 577 | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
| 578 | /// to always be null. For example: |
| 579 | /// |
| 580 | /// struct A { }; |
| 581 | /// struct B final : A { }; |
| 582 | /// struct C { }; |
| 583 | /// |
| 584 | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
| 585 | bool CXXDynamicCastExpr::isAlwaysNull() const |
| 586 | { |
| 587 | QualType SrcType = getSubExpr()->getType(); |
| 588 | QualType DestType = getType(); |
| 589 | |
| 590 | if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) { |
| 591 | SrcType = SrcPTy->getPointeeType(); |
| 592 | DestType = DestType->castAs<PointerType>()->getPointeeType(); |
| 593 | } |
| 594 | |
Alexis Hunt | 78e2b91 | 2012-06-19 23:44:55 +0000 | [diff] [blame] | 595 | if (DestType->isVoidType()) |
| 596 | return false; |
| 597 | |
Anders Carlsson | 267c0c9 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 598 | const CXXRecordDecl *SrcRD = |
| 599 | cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); |
| 600 | |
Jakob Stoklund Olesen | e1c0ae6 | 2012-06-19 21:48:43 +0000 | [diff] [blame] | 601 | if (!SrcRD->hasAttr<FinalAttr>()) |
| 602 | return false; |
| 603 | |
Anders Carlsson | 267c0c9 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 604 | const CXXRecordDecl *DestRD = |
| 605 | cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); |
| 606 | |
| 607 | return !DestRD->isDerivedFrom(SrcRD); |
| 608 | } |
| 609 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 610 | CXXReinterpretCastExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 611 | CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T, |
| 612 | ExprValueKind VK, CastKind K, Expr *Op, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 613 | const CXXCastPath *BasePath, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 614 | TypeSourceInfo *WrittenTy, SourceLocation L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 615 | SourceLocation RParenLoc, |
| 616 | SourceRange AngleBrackets) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 617 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 618 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 619 | CXXReinterpretCastExpr *E = |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 620 | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 621 | RParenLoc, AngleBrackets); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 622 | if (PathSize) |
| 623 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
| 624 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 625 | return E; |
| 626 | } |
| 627 | |
| 628 | CXXReinterpretCastExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 629 | CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 630 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 631 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
| 632 | } |
| 633 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 634 | CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 635 | ExprValueKind VK, Expr *Op, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 636 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 4478f85 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 637 | SourceLocation L, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 638 | SourceLocation RParenLoc, |
| 639 | SourceRange AngleBrackets) { |
| 640 | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 643 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 644 | return new (C) CXXConstCastExpr(EmptyShell()); |
| 645 | } |
| 646 | |
| 647 | CXXFunctionalCastExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 648 | CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 649 | TypeSourceInfo *Written, CastKind K, Expr *Op, |
| 650 | const CXXCastPath *BasePath, |
| 651 | SourceLocation L, SourceLocation R) { |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 652 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 653 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 654 | CXXFunctionalCastExpr *E = |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 655 | new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 656 | if (PathSize) |
| 657 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
| 658 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 659 | return E; |
| 660 | } |
| 661 | |
| 662 | CXXFunctionalCastExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 663 | CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { |
James Y Knight | 1d75c5e | 2015-12-30 02:27:28 +0000 | [diff] [blame] | 664 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 665 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
| 666 | } |
| 667 | |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 668 | SourceLocation CXXFunctionalCastExpr::getLocStart() const { |
| 669 | return getTypeInfoAsWritten()->getTypeLoc().getLocStart(); |
| 670 | } |
| 671 | |
| 672 | SourceLocation CXXFunctionalCastExpr::getLocEnd() const { |
| 673 | return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd(); |
| 674 | } |
| 675 | |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 676 | UserDefinedLiteral::LiteralOperatorKind |
| 677 | UserDefinedLiteral::getLiteralOperatorKind() const { |
| 678 | if (getNumArgs() == 0) |
| 679 | return LOK_Template; |
| 680 | if (getNumArgs() == 2) |
| 681 | return LOK_String; |
| 682 | |
| 683 | assert(getNumArgs() == 1 && "unexpected #args in literal operator call"); |
| 684 | QualType ParamTy = |
| 685 | cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType(); |
| 686 | if (ParamTy->isPointerType()) |
| 687 | return LOK_Raw; |
| 688 | if (ParamTy->isAnyCharacterType()) |
| 689 | return LOK_Character; |
| 690 | if (ParamTy->isIntegerType()) |
| 691 | return LOK_Integer; |
| 692 | if (ParamTy->isFloatingType()) |
| 693 | return LOK_Floating; |
| 694 | |
| 695 | llvm_unreachable("unknown kind of literal operator"); |
| 696 | } |
| 697 | |
| 698 | Expr *UserDefinedLiteral::getCookedLiteral() { |
| 699 | #ifndef NDEBUG |
| 700 | LiteralOperatorKind LOK = getLiteralOperatorKind(); |
| 701 | assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal"); |
| 702 | #endif |
| 703 | return getArg(0); |
| 704 | } |
| 705 | |
| 706 | const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { |
| 707 | return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier(); |
| 708 | } |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 709 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 710 | CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 711 | FieldDecl *Field, QualType T) |
| 712 | : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C), |
| 713 | T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType() |
| 714 | ? VK_XValue |
| 715 | : VK_RValue, |
| 716 | /*FIXME*/ OK_Ordinary, false, false, false, false), |
| 717 | Field(Field), Loc(Loc) { |
| 718 | assert(Field->hasInClassInitializer()); |
| 719 | } |
| 720 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 721 | CXXTemporary *CXXTemporary::Create(const ASTContext &C, |
Anders Carlsson | ffda606 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 722 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 73b836b | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 723 | return new (C) CXXTemporary(Destructor); |
| 724 | } |
| 725 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 726 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C, |
Anders Carlsson | 993a4b3 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 727 | CXXTemporary *Temp, |
| 728 | Expr* SubExpr) { |
Peter Collingbourne | fbef4c8 | 2011-11-27 22:09:28 +0000 | [diff] [blame] | 729 | assert((SubExpr->getType()->isRecordType() || |
| 730 | SubExpr->getType()->isArrayType()) && |
| 731 | "Expression bound to a temporary must have record or array type!"); |
Anders Carlsson | 993a4b3 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 732 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 733 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | 993a4b3 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 736 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(const ASTContext &C, |
Anders Carlsson | 56c5bd8 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 737 | CXXConstructorDecl *Cons, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 738 | TypeSourceInfo *Type, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 739 | ArrayRef<Expr*> Args, |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 740 | SourceRange ParenOrBraceRange, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 741 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 742 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 743 | bool StdInitListInitialization, |
Douglas Gregor | 199db36 | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 744 | bool ZeroInitialization) |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 745 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, |
| 746 | Type->getType().getNonReferenceType(), |
| 747 | Type->getTypeLoc().getBeginLoc(), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 748 | Cons, false, Args, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 749 | HadMultipleCandidates, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 750 | ListInitialization, |
| 751 | StdInitListInitialization, |
| 752 | ZeroInitialization, |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 753 | CXXConstructExpr::CK_Complete, ParenOrBraceRange), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 754 | Type(Type) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 757 | SourceLocation CXXTemporaryObjectExpr::getLocStart() const { |
| 758 | return Type->getTypeLoc().getBeginLoc(); |
| 759 | } |
| 760 | |
| 761 | SourceLocation CXXTemporaryObjectExpr::getLocEnd() const { |
Argyrios Kyrtzidis | 623ecfd | 2013-09-11 23:23:27 +0000 | [diff] [blame] | 762 | SourceLocation Loc = getParenOrBraceRange().getEnd(); |
| 763 | if (Loc.isInvalid() && getNumArgs()) |
| 764 | Loc = getArg(getNumArgs()-1)->getLocEnd(); |
| 765 | return Loc; |
Douglas Gregor | dd04d33 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 766 | } |
Anders Carlsson | 6f28783 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 767 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 768 | CXXConstructExpr *CXXConstructExpr::Create(const ASTContext &C, QualType T, |
Douglas Gregor | 85dabae | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 769 | SourceLocation Loc, |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 770 | CXXConstructorDecl *Ctor, |
| 771 | bool Elidable, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 772 | ArrayRef<Expr*> Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 773 | bool HadMultipleCandidates, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 774 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 775 | bool StdInitListInitialization, |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 776 | bool ZeroInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 777 | ConstructionKind ConstructKind, |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 778 | SourceRange ParenOrBraceRange) { |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 779 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 780 | Ctor, Elidable, Args, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 781 | HadMultipleCandidates, ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 782 | StdInitListInitialization, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 783 | ZeroInitialization, ConstructKind, |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 784 | ParenOrBraceRange); |
Anders Carlsson | 0781ce7 | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 787 | CXXConstructExpr::CXXConstructExpr(const ASTContext &C, StmtClass SC, |
| 788 | QualType T, SourceLocation Loc, |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 789 | CXXConstructorDecl *Ctor, |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 790 | bool Elidable, |
| 791 | ArrayRef<Expr*> Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 792 | bool HadMultipleCandidates, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 793 | bool ListInitialization, |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 794 | bool StdInitListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 795 | bool ZeroInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 796 | ConstructionKind ConstructKind, |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 797 | SourceRange ParenOrBraceRange) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 798 | : Expr(SC, T, VK_RValue, OK_Ordinary, |
| 799 | T->isDependentType(), T->isDependentType(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 800 | T->isInstantiationDependentType(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 801 | T->containsUnexpandedParameterPack()), |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 802 | Constructor(Ctor), Loc(Loc), ParenOrBraceRange(ParenOrBraceRange), |
| 803 | NumArgs(Args.size()), |
| 804 | Elidable(Elidable), HadMultipleCandidates(HadMultipleCandidates), |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 805 | ListInitialization(ListInitialization), |
Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 806 | StdInitListInitialization(StdInitListInitialization), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 807 | ZeroInitialization(ZeroInitialization), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 808 | ConstructKind(ConstructKind), Args(nullptr) |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 809 | { |
| 810 | if (NumArgs) { |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 811 | this->Args = new (C) Stmt*[Args.size()]; |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 812 | |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 813 | for (unsigned i = 0; i != Args.size(); ++i) { |
| 814 | assert(Args[i] && "NULL argument in CXXConstructExpr"); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 815 | |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 816 | if (Args[i]->isValueDependent()) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 817 | ExprBits.ValueDependent = true; |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 818 | if (Args[i]->isInstantiationDependent()) |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 819 | ExprBits.InstantiationDependent = true; |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 820 | if (Args[i]->containsUnexpandedParameterPack()) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 821 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 822 | |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 823 | this->Args[i] = Args[i]; |
Anders Carlsson | 0781ce7 | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 824 | } |
Douglas Gregor | 4f4b186 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 825 | } |
Anders Carlsson | 0781ce7 | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 828 | LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit, |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 829 | LambdaCaptureKind Kind, VarDecl *Var, |
| 830 | SourceLocation EllipsisLoc) |
John Brawn | 771721c | 2016-06-15 14:14:51 +0000 | [diff] [blame] | 831 | : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 832 | { |
| 833 | unsigned Bits = 0; |
| 834 | if (Implicit) |
| 835 | Bits |= Capture_Implicit; |
| 836 | |
| 837 | switch (Kind) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 838 | case LCK_StarThis: |
| 839 | Bits |= Capture_ByCopy; |
| 840 | // Fall through |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 841 | case LCK_This: |
| 842 | assert(!Var && "'this' capture cannot have a variable!"); |
John Brawn | 771721c | 2016-06-15 14:14:51 +0000 | [diff] [blame] | 843 | Bits |= Capture_This; |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | case LCK_ByCopy: |
| 847 | Bits |= Capture_ByCopy; |
| 848 | // Fall through |
| 849 | case LCK_ByRef: |
| 850 | assert(Var && "capture must have a variable!"); |
| 851 | break; |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 852 | case LCK_VLAType: |
| 853 | assert(!Var && "VLA type capture cannot have a variable!"); |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 854 | break; |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 855 | } |
John Brawn | 771721c | 2016-06-15 14:14:51 +0000 | [diff] [blame] | 856 | DeclAndBits.setInt(Bits); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 859 | LambdaCaptureKind LambdaCapture::getCaptureKind() const { |
John Brawn | 771721c | 2016-06-15 14:14:51 +0000 | [diff] [blame] | 860 | if (capturesVLAType()) |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 861 | return LCK_VLAType; |
John Brawn | 771721c | 2016-06-15 14:14:51 +0000 | [diff] [blame] | 862 | bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy; |
| 863 | if (capturesThis()) |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 864 | return CapByCopy ? LCK_StarThis : LCK_This; |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 865 | return CapByCopy ? LCK_ByCopy : LCK_ByRef; |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 866 | } |
| 867 | |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 868 | LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange, |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 869 | LambdaCaptureDefault CaptureDefault, |
James Dennett | ddd36ff | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 870 | SourceLocation CaptureDefaultLoc, |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 871 | ArrayRef<LambdaCapture> Captures, bool ExplicitParams, |
| 872 | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 873 | ArrayRef<VarDecl *> ArrayIndexVars, |
| 874 | ArrayRef<unsigned> ArrayIndexStarts, |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 875 | SourceLocation ClosingBrace, |
| 876 | bool ContainsUnexpandedParameterPack) |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 877 | : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(), |
| 878 | T->isDependentType(), T->isDependentType(), |
| 879 | ContainsUnexpandedParameterPack), |
| 880 | IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc), |
| 881 | NumCaptures(Captures.size()), CaptureDefault(CaptureDefault), |
| 882 | ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType), |
| 883 | ClosingBrace(ClosingBrace) { |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 884 | assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments"); |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 885 | CXXRecordDecl *Class = getLambdaClass(); |
| 886 | CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData(); |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 887 | |
| 888 | // FIXME: Propagate "has unexpanded parameter pack" bit. |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 889 | |
| 890 | // Copy captures. |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 891 | const ASTContext &Context = Class->getASTContext(); |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 892 | Data.NumCaptures = NumCaptures; |
| 893 | Data.NumExplicitCaptures = 0; |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 894 | Data.Captures = |
| 895 | (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures); |
| 896 | LambdaCapture *ToCapture = Data.Captures; |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 897 | for (unsigned I = 0, N = Captures.size(); I != N; ++I) { |
| 898 | if (Captures[I].isExplicit()) |
| 899 | ++Data.NumExplicitCaptures; |
| 900 | |
| 901 | *ToCapture++ = Captures[I]; |
| 902 | } |
| 903 | |
| 904 | // Copy initialization expressions for the non-static data members. |
| 905 | Stmt **Stored = getStoredStmts(); |
| 906 | for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I) |
| 907 | *Stored++ = CaptureInits[I]; |
| 908 | |
| 909 | // Copy the body of the lambda. |
| 910 | *Stored++ = getCallOperator()->getBody(); |
| 911 | |
| 912 | // Copy the array index variables, if any. |
| 913 | HasArrayIndexVars = !ArrayIndexVars.empty(); |
| 914 | if (HasArrayIndexVars) { |
| 915 | assert(ArrayIndexStarts.size() == NumCaptures); |
| 916 | memcpy(getArrayIndexVars(), ArrayIndexVars.data(), |
| 917 | sizeof(VarDecl *) * ArrayIndexVars.size()); |
| 918 | memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(), |
| 919 | sizeof(unsigned) * Captures.size()); |
| 920 | getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size(); |
Douglas Gregor | 6f88e5e | 2012-02-21 04:17:39 +0000 | [diff] [blame] | 921 | } |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 922 | } |
| 923 | |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 924 | LambdaExpr *LambdaExpr::Create( |
| 925 | const ASTContext &Context, CXXRecordDecl *Class, |
| 926 | SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, |
| 927 | SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures, |
| 928 | bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
| 929 | ArrayRef<VarDecl *> ArrayIndexVars, ArrayRef<unsigned> ArrayIndexStarts, |
| 930 | SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) { |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 931 | // Determine the type of the expression (i.e., the type of the |
| 932 | // function object we're creating). |
| 933 | QualType T = Context.getTypeDeclType(Class); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 934 | |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 935 | unsigned Size = totalSizeToAlloc<Stmt *, unsigned, VarDecl *>( |
| 936 | Captures.size() + 1, ArrayIndexVars.empty() ? 0 : Captures.size() + 1, |
| 937 | ArrayIndexVars.size()); |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 938 | void *Mem = Context.Allocate(Size); |
James Dennett | ddd36ff | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 939 | return new (Mem) LambdaExpr(T, IntroducerRange, |
| 940 | CaptureDefault, CaptureDefaultLoc, Captures, |
| 941 | ExplicitParams, ExplicitResultType, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 942 | CaptureInits, ArrayIndexVars, ArrayIndexStarts, |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 943 | ClosingBrace, ContainsUnexpandedParameterPack); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 946 | LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C, |
| 947 | unsigned NumCaptures, |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 948 | unsigned NumArrayIndexVars) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 949 | unsigned Size = totalSizeToAlloc<Stmt *, unsigned, VarDecl *>( |
| 950 | NumCaptures + 1, NumArrayIndexVars ? NumCaptures + 1 : 0, |
| 951 | NumArrayIndexVars); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 952 | void *Mem = C.Allocate(Size); |
| 953 | return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0); |
| 954 | } |
| 955 | |
James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 956 | bool LambdaExpr::isInitCapture(const LambdaCapture *C) const { |
| 957 | return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() && |
| 958 | (getCallOperator() == C->getCapturedVar()->getDeclContext())); |
| 959 | } |
| 960 | |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 961 | LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 962 | return getLambdaClass()->getLambdaData().Captures; |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | LambdaExpr::capture_iterator LambdaExpr::capture_end() const { |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 966 | return capture_begin() + NumCaptures; |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 967 | } |
| 968 | |
James Dennett | 1575cb4 | 2014-05-27 19:13:04 +0000 | [diff] [blame] | 969 | LambdaExpr::capture_range LambdaExpr::captures() const { |
| 970 | return capture_range(capture_begin(), capture_end()); |
| 971 | } |
| 972 | |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 973 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { |
| 974 | return capture_begin(); |
| 975 | } |
| 976 | |
| 977 | LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { |
| 978 | struct CXXRecordDecl::LambdaDefinitionData &Data |
| 979 | = getLambdaClass()->getLambdaData(); |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 980 | return Data.Captures + Data.NumExplicitCaptures; |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 981 | } |
| 982 | |
James Dennett | 1575cb4 | 2014-05-27 19:13:04 +0000 | [diff] [blame] | 983 | LambdaExpr::capture_range LambdaExpr::explicit_captures() const { |
| 984 | return capture_range(explicit_capture_begin(), explicit_capture_end()); |
| 985 | } |
| 986 | |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 987 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { |
| 988 | return explicit_capture_end(); |
| 989 | } |
| 990 | |
| 991 | LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { |
| 992 | return capture_end(); |
| 993 | } |
| 994 | |
James Dennett | 1575cb4 | 2014-05-27 19:13:04 +0000 | [diff] [blame] | 995 | LambdaExpr::capture_range LambdaExpr::implicit_captures() const { |
| 996 | return capture_range(implicit_capture_begin(), implicit_capture_end()); |
| 997 | } |
| 998 | |
James Y Knight | 53c7616 | 2015-07-17 18:21:37 +0000 | [diff] [blame] | 999 | ArrayRef<VarDecl *> |
| 1000 | LambdaExpr::getCaptureInitIndexVars(const_capture_init_iterator Iter) const { |
Douglas Gregor | e556163 | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 1001 | assert(HasArrayIndexVars && "No array index-var data?"); |
Douglas Gregor | 54fcea6 | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 1002 | |
| 1003 | unsigned Index = Iter - capture_init_begin(); |
Matt Beaumont-Gay | f2ee067 | 2012-02-13 19:29:45 +0000 | [diff] [blame] | 1004 | assert(Index < getLambdaClass()->getLambdaData().NumCaptures && |
| 1005 | "Capture index out-of-range"); |
James Y Knight | 53c7616 | 2015-07-17 18:21:37 +0000 | [diff] [blame] | 1006 | VarDecl *const *IndexVars = getArrayIndexVars(); |
| 1007 | const unsigned *IndexStarts = getArrayIndexStarts(); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 1008 | return llvm::makeArrayRef(IndexVars + IndexStarts[Index], |
| 1009 | IndexVars + IndexStarts[Index + 1]); |
Douglas Gregor | 54fcea6 | 2012-02-13 16:35:30 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 1012 | CXXRecordDecl *LambdaExpr::getLambdaClass() const { |
| 1013 | return getType()->getAsCXXRecordDecl(); |
| 1014 | } |
| 1015 | |
| 1016 | CXXMethodDecl *LambdaExpr::getCallOperator() const { |
| 1017 | CXXRecordDecl *Record = getLambdaClass(); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1018 | return Record->getLambdaCallOperator(); |
| 1019 | } |
| 1020 | |
| 1021 | TemplateParameterList *LambdaExpr::getTemplateParameterList() const { |
| 1022 | CXXRecordDecl *Record = getLambdaClass(); |
| 1023 | return Record->getGenericLambdaTemplateParameterList(); |
| 1024 | |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1027 | CompoundStmt *LambdaExpr::getBody() const { |
James Y Knight | 53c7616 | 2015-07-17 18:21:37 +0000 | [diff] [blame] | 1028 | // FIXME: this mutation in getBody is bogus. It should be |
| 1029 | // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I |
| 1030 | // don't understand, that doesn't work. |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1031 | if (!getStoredStmts()[NumCaptures]) |
James Y Knight | 53c7616 | 2015-07-17 18:21:37 +0000 | [diff] [blame] | 1032 | *const_cast<clang::Stmt **>(&getStoredStmts()[NumCaptures]) = |
| 1033 | getCallOperator()->getBody(); |
| 1034 | |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1035 | return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 1038 | bool LambdaExpr::isMutable() const { |
David Blaikie | f5697e5 | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 1039 | return !getCallOperator()->isConst(); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1042 | ExprWithCleanups::ExprWithCleanups(Expr *subexpr, |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 1043 | bool CleanupsHaveSideEffects, |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1044 | ArrayRef<CleanupObject> objects) |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 1045 | : Expr(ExprWithCleanupsClass, subexpr->getType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1046 | subexpr->getValueKind(), subexpr->getObjectKind(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1047 | subexpr->isTypeDependent(), subexpr->isValueDependent(), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1048 | subexpr->isInstantiationDependent(), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1049 | subexpr->containsUnexpandedParameterPack()), |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1050 | SubExpr(subexpr) { |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 1051 | ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects; |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1052 | ExprWithCleanupsBits.NumObjects = objects.size(); |
| 1053 | for (unsigned i = 0, e = objects.size(); i != e; ++i) |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1054 | getTrailingObjects<CleanupObject>()[i] = objects[i]; |
Anders Carlsson | defc644 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1057 | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr, |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 1058 | bool CleanupsHaveSideEffects, |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1059 | ArrayRef<CleanupObject> objects) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1060 | void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()), |
| 1061 | llvm::alignOf<ExprWithCleanups>()); |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 1062 | return new (buffer) |
| 1063 | ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1066 | ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) |
| 1067 | : Expr(ExprWithCleanupsClass, empty) { |
| 1068 | ExprWithCleanupsBits.NumObjects = numObjects; |
| 1069 | } |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 1070 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1071 | ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, |
| 1072 | EmptyShell empty, |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1073 | unsigned numObjects) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1074 | void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects), |
| 1075 | llvm::alignOf<ExprWithCleanups>()); |
John McCall | 28fc709 | 2011-11-10 05:35:25 +0000 | [diff] [blame] | 1076 | return new (buffer) ExprWithCleanups(empty, numObjects); |
Anders Carlsson | 73b836b | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1079 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1080 | SourceLocation LParenLoc, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1081 | ArrayRef<Expr*> Args, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1082 | SourceLocation RParenLoc) |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1083 | : Expr(CXXUnresolvedConstructExprClass, |
| 1084 | Type->getType().getNonReferenceType(), |
Douglas Gregor | 6336f29 | 2011-07-08 15:50:43 +0000 | [diff] [blame] | 1085 | (Type->getType()->isLValueReferenceType() ? VK_LValue |
| 1086 | :Type->getType()->isRValueReferenceType()? VK_XValue |
| 1087 | :VK_RValue), |
| 1088 | OK_Ordinary, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1089 | Type->getType()->isDependentType(), true, true, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1090 | Type->getType()->containsUnexpandedParameterPack()), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1091 | Type(Type), |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1092 | LParenLoc(LParenLoc), |
| 1093 | RParenLoc(RParenLoc), |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1094 | NumArgs(Args.size()) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1095 | Expr **StoredArgs = getTrailingObjects<Expr *>(); |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1096 | for (unsigned I = 0; I != Args.size(); ++I) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1097 | if (Args[I]->containsUnexpandedParameterPack()) |
| 1098 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 1099 | |
| 1100 | StoredArgs[I] = Args[I]; |
| 1101 | } |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | CXXUnresolvedConstructExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1105 | CXXUnresolvedConstructExpr::Create(const ASTContext &C, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1106 | TypeSourceInfo *Type, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1107 | SourceLocation LParenLoc, |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1108 | ArrayRef<Expr*> Args, |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1109 | SourceLocation RParenLoc) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1110 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Args.size())); |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 1111 | return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc); |
Douglas Gregor | ce93414 | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1114 | CXXUnresolvedConstructExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1115 | CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &C, unsigned NumArgs) { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1116 | Stmt::EmptyShell Empty; |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1117 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumArgs)); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1118 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 1119 | } |
| 1120 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 1121 | SourceLocation CXXUnresolvedConstructExpr::getLocStart() const { |
| 1122 | return Type->getTypeLoc().getBeginLoc(); |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1125 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr( |
| 1126 | const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow, |
| 1127 | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
| 1128 | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
| 1129 | DeclarationNameInfo MemberNameInfo, |
| 1130 | const TemplateArgumentListInfo *TemplateArgs) |
| 1131 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, VK_LValue, |
| 1132 | OK_Ordinary, true, true, true, |
| 1133 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 1134 | (QualifierLoc && |
| 1135 | QualifierLoc.getNestedNameSpecifier() |
| 1136 | ->containsUnexpandedParameterPack()) || |
| 1137 | MemberNameInfo.containsUnexpandedParameterPack())), |
| 1138 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 1139 | HasTemplateKWAndArgsInfo(TemplateArgs != nullptr || |
| 1140 | TemplateKWLoc.isValid()), |
| 1141 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
| 1142 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
| 1143 | MemberNameInfo(MemberNameInfo) { |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1144 | if (TemplateArgs) { |
| 1145 | bool Dependent = true; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1146 | bool InstantiationDependent = true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1147 | bool ContainsUnexpandedParameterPack = false; |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1148 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 1149 | TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(), |
| 1150 | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1151 | if (ContainsUnexpandedParameterPack) |
| 1152 | ExprBits.ContainsUnexpandedParameterPack = true; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1153 | } else if (TemplateKWLoc.isValid()) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1154 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
| 1155 | TemplateKWLoc); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1156 | } |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1159 | CXXDependentScopeMemberExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1160 | CXXDependentScopeMemberExpr::Create(const ASTContext &C, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1161 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1162 | SourceLocation OperatorLoc, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1163 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1164 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1165 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1166 | DeclarationNameInfo MemberNameInfo, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1167 | const TemplateArgumentListInfo *TemplateArgs) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1168 | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1169 | unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0; |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1170 | std::size_t Size = |
| 1171 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 1172 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1173 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1174 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1175 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 1176 | IsArrow, OperatorLoc, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1177 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1178 | TemplateKWLoc, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1179 | FirstQualifierFoundInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1180 | MemberNameInfo, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1183 | CXXDependentScopeMemberExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1184 | CXXDependentScopeMemberExpr::CreateEmpty(const ASTContext &C, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1185 | bool HasTemplateKWAndArgsInfo, |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1186 | unsigned NumTemplateArgs) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1187 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 1188 | std::size_t Size = |
| 1189 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 1190 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
| 1191 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1192 | CXXDependentScopeMemberExpr *E |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1193 | = new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1194 | 0, SourceLocation(), |
| 1195 | NestedNameSpecifierLoc(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1196 | SourceLocation(), nullptr, |
| 1197 | DeclarationNameInfo(), nullptr); |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1198 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 1199 | return E; |
| 1200 | } |
| 1201 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1202 | bool CXXDependentScopeMemberExpr::isImplicitAccess() const { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1203 | if (!Base) |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1204 | return true; |
| 1205 | |
Douglas Gregor | 25b7e05 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 1206 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1209 | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
| 1210 | UnresolvedSetIterator end) { |
| 1211 | do { |
| 1212 | NamedDecl *decl = *begin; |
| 1213 | if (isa<UnresolvedUsingValueDecl>(decl)) |
| 1214 | return false; |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1215 | |
| 1216 | // Unresolved member expressions should only contain methods and |
| 1217 | // method templates. |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 1218 | if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction()) |
| 1219 | ->isStatic()) |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1220 | return false; |
| 1221 | } while (++begin != end); |
| 1222 | |
| 1223 | return true; |
| 1224 | } |
| 1225 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1226 | UnresolvedMemberExpr::UnresolvedMemberExpr(const ASTContext &C, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1227 | bool HasUnresolvedUsing, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1228 | Expr *Base, QualType BaseType, |
| 1229 | bool IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1230 | SourceLocation OperatorLoc, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1231 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1232 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1233 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 30a4f4c | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 1234 | const TemplateArgumentListInfo *TemplateArgs, |
| 1235 | UnresolvedSetIterator Begin, |
| 1236 | UnresolvedSetIterator End) |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1237 | : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc, |
| 1238 | MemberNameInfo, TemplateArgs, Begin, End, |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1239 | // Dependent |
| 1240 | ((Base && Base->isTypeDependent()) || |
| 1241 | BaseType->isDependentType()), |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1242 | ((Base && Base->isInstantiationDependent()) || |
| 1243 | BaseType->isInstantiationDependentType()), |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 1244 | // Contains unexpanded parameter pack |
| 1245 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 1246 | BaseType->containsUnexpandedParameterPack())), |
John McCall | 1acbbb5 | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 1247 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 1248 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 1249 | |
| 1250 | // Check whether all of the members are non-static member functions, |
| 1251 | // and if so, mark give this bound-member type instead of overload type. |
| 1252 | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
| 1253 | setType(C.BoundMemberTy); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1256 | bool UnresolvedMemberExpr::isImplicitAccess() const { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1257 | if (!Base) |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1258 | return true; |
| 1259 | |
Douglas Gregor | 25b7e05 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 1260 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1263 | UnresolvedMemberExpr *UnresolvedMemberExpr::Create( |
| 1264 | const ASTContext &C, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, |
| 1265 | bool IsArrow, SourceLocation OperatorLoc, |
| 1266 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 1267 | const DeclarationNameInfo &MemberNameInfo, |
| 1268 | const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, |
| 1269 | UnresolvedSetIterator End) { |
| 1270 | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); |
| 1271 | std::size_t Size = |
| 1272 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 1273 | HasTemplateKWAndArgsInfo, TemplateArgs ? TemplateArgs->size() : 0); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1274 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1275 | void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedMemberExpr>()); |
| 1276 | return new (Mem) UnresolvedMemberExpr( |
| 1277 | C, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, |
| 1278 | TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1281 | UnresolvedMemberExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1282 | UnresolvedMemberExpr::CreateEmpty(const ASTContext &C, |
| 1283 | bool HasTemplateKWAndArgsInfo, |
Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 1284 | unsigned NumTemplateArgs) { |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1285 | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
| 1286 | std::size_t Size = |
| 1287 | totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
| 1288 | HasTemplateKWAndArgsInfo, NumTemplateArgs); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1289 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 1290 | void *Mem = C.Allocate(Size, llvm::alignOf<UnresolvedMemberExpr>()); |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1291 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1292 | E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; |
Argyrios Kyrtzidis | b8d3c63 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 1293 | return E; |
| 1294 | } |
| 1295 | |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1296 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 1297 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 1298 | |
| 1299 | // If there was a nested name specifier, it names the naming class. |
| 1300 | // It can't be dependent: after all, we were actually able to do the |
| 1301 | // lookup. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1302 | CXXRecordDecl *Record = nullptr; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 1303 | auto *NNS = getQualifier(); |
| 1304 | if (NNS && NNS->getKind() != NestedNameSpecifier::Super) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1305 | const Type *T = getQualifier()->getAsType(); |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1306 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1307 | Record = T->getAsCXXRecordDecl(); |
| 1308 | assert(Record && "qualifier in member expression does not name record"); |
| 1309 | } |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1310 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1311 | else { |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1312 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 1313 | if (isArrow()) { |
| 1314 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 1315 | assert(PT && "base of arrow member access is not pointer"); |
| 1316 | BaseType = PT->getPointeeType(); |
| 1317 | } |
| 1318 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1319 | Record = BaseType->getAsCXXRecordDecl(); |
| 1320 | assert(Record && "base of member expression does not name record"); |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1323 | return Record; |
John McCall | 58cc69d | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 1326 | SizeOfPackExpr * |
| 1327 | SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc, |
| 1328 | NamedDecl *Pack, SourceLocation PackLoc, |
| 1329 | SourceLocation RParenLoc, |
| 1330 | Optional<unsigned> Length, |
| 1331 | ArrayRef<TemplateArgument> PartialArgs) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1332 | void *Storage = |
| 1333 | Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size())); |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 1334 | return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack, |
| 1335 | PackLoc, RParenLoc, Length, PartialArgs); |
| 1336 | } |
| 1337 | |
| 1338 | SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context, |
| 1339 | unsigned NumPartialArgs) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1340 | void *Storage = |
| 1341 | Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs)); |
Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 1342 | return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs); |
| 1343 | } |
| 1344 | |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1345 | SubstNonTypeTemplateParmPackExpr:: |
| 1346 | SubstNonTypeTemplateParmPackExpr(QualType T, |
| 1347 | NonTypeTemplateParmDecl *Param, |
| 1348 | SourceLocation NameLoc, |
| 1349 | const TemplateArgument &ArgPack) |
| 1350 | : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1351 | true, true, true, true), |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1352 | Param(Param), Arguments(ArgPack.pack_begin()), |
| 1353 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } |
| 1354 | |
| 1355 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1356 | return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments)); |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1359 | FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, |
| 1360 | SourceLocation NameLoc, |
| 1361 | unsigned NumParams, |
James Y Knight | 48fefa3 | 2015-09-30 14:04:23 +0000 | [diff] [blame] | 1362 | ParmVarDecl *const *Params) |
| 1363 | : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true, |
| 1364 | true, true), |
| 1365 | ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) { |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1366 | if (Params) |
| 1367 | std::uninitialized_copy(Params, Params + NumParams, |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1368 | getTrailingObjects<ParmVarDecl *>()); |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | FunctionParmPackExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1372 | FunctionParmPackExpr::Create(const ASTContext &Context, QualType T, |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1373 | ParmVarDecl *ParamPack, SourceLocation NameLoc, |
James Y Knight | 48fefa3 | 2015-09-30 14:04:23 +0000 | [diff] [blame] | 1374 | ArrayRef<ParmVarDecl *> Params) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1375 | return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(Params.size()))) |
| 1376 | FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data()); |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | FunctionParmPackExpr * |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1380 | FunctionParmPackExpr::CreateEmpty(const ASTContext &Context, |
| 1381 | unsigned NumParams) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1382 | return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(NumParams))) |
| 1383 | FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr); |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
David Majnemer | daff370 | 2014-05-01 17:50:17 +0000 | [diff] [blame] | 1386 | void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy, |
| 1387 | unsigned ManglingNumber) { |
| 1388 | // We only need extra state if we have to remember more than just the Stmt. |
| 1389 | if (!ExtendedBy) |
| 1390 | return; |
| 1391 | |
| 1392 | // We may need to allocate extra storage for the mangling number and the |
| 1393 | // extended-by ValueDecl. |
| 1394 | if (!State.is<ExtraState *>()) { |
| 1395 | auto ES = new (ExtendedBy->getASTContext()) ExtraState; |
| 1396 | ES->Temporary = State.get<Stmt *>(); |
| 1397 | State = ES; |
| 1398 | } |
| 1399 | |
| 1400 | auto ES = State.get<ExtraState *>(); |
| 1401 | ES->ExtendingDecl = ExtendedBy; |
| 1402 | ES->ManglingNumber = ManglingNumber; |
| 1403 | } |
| 1404 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1405 | TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, |
| 1406 | ArrayRef<TypeSourceInfo *> Args, |
| 1407 | SourceLocation RParenLoc, |
| 1408 | bool Value) |
| 1409 | : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary, |
| 1410 | /*TypeDependent=*/false, |
| 1411 | /*ValueDependent=*/false, |
| 1412 | /*InstantiationDependent=*/false, |
| 1413 | /*ContainsUnexpandedParameterPack=*/false), |
| 1414 | Loc(Loc), RParenLoc(RParenLoc) |
| 1415 | { |
| 1416 | TypeTraitExprBits.Kind = Kind; |
| 1417 | TypeTraitExprBits.Value = Value; |
| 1418 | TypeTraitExprBits.NumArgs = Args.size(); |
| 1419 | |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1420 | TypeSourceInfo **ToArgs = getTrailingObjects<TypeSourceInfo *>(); |
| 1421 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1422 | for (unsigned I = 0, N = Args.size(); I != N; ++I) { |
| 1423 | if (Args[I]->getType()->isDependentType()) |
| 1424 | setValueDependent(true); |
| 1425 | if (Args[I]->getType()->isInstantiationDependentType()) |
| 1426 | setInstantiationDependent(true); |
| 1427 | if (Args[I]->getType()->containsUnexpandedParameterPack()) |
| 1428 | setContainsUnexpandedParameterPack(true); |
| 1429 | |
| 1430 | ToArgs[I] = Args[I]; |
| 1431 | } |
| 1432 | } |
| 1433 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1434 | TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1435 | SourceLocation Loc, |
| 1436 | TypeTrait Kind, |
| 1437 | ArrayRef<TypeSourceInfo *> Args, |
| 1438 | SourceLocation RParenLoc, |
| 1439 | bool Value) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1440 | void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size())); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1441 | return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); |
| 1442 | } |
| 1443 | |
Craig Topper | a31a882 | 2013-08-22 07:09:37 +0000 | [diff] [blame] | 1444 | TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1445 | unsigned NumArgs) { |
James Y Knight | e00a67e | 2015-12-31 04:18:25 +0000 | [diff] [blame] | 1446 | void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs)); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 1447 | return new (Mem) TypeTraitExpr(EmptyShell()); |
| 1448 | } |
| 1449 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1450 | void ArrayTypeTraitExpr::anchor() { } |