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