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