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