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