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