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