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