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" |
| 15 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 18 | #include "clang/AST/TypeLoc.h" |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 21 | |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
| 23 | // Child Iterators for iterating over subexpressions/substatements |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 26 | QualType CXXTypeidExpr::getTypeOperand() const { |
| 27 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
| 28 | return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() |
| 29 | .getUnqualifiedType(); |
| 30 | } |
| 31 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 32 | QualType CXXUuidofExpr::getTypeOperand() const { |
| 33 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
| 34 | return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() |
| 35 | .getUnqualifiedType(); |
| 36 | } |
| 37 | |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 38 | // CXXScalarValueInitExpr |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 39 | SourceRange CXXScalarValueInitExpr::getSourceRange() const { |
| 40 | SourceLocation Start = RParenLoc; |
| 41 | if (TypeInfo) |
| 42 | Start = TypeInfo->getTypeLoc().getBeginLoc(); |
| 43 | return SourceRange(Start, RParenLoc); |
| 44 | } |
| 45 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 46 | // CXXNewExpr |
Ted Kremenek | ad7fe86 | 2010-02-11 22:51:03 +0000 | [diff] [blame] | 47 | CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 48 | Expr **placementArgs, unsigned numPlaceArgs, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 49 | SourceRange TypeIdParens, Expr *arraySize, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 50 | CXXConstructorDecl *constructor, bool initializer, |
| 51 | Expr **constructorArgs, unsigned numConsArgs, |
John McCall | 6ec278d | 2011-01-27 09:37:56 +0000 | [diff] [blame] | 52 | FunctionDecl *operatorDelete, |
| 53 | bool usualArrayDeleteWantsSize, QualType ty, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 54 | TypeSourceInfo *AllocatedTypeInfo, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 55 | SourceLocation startLoc, SourceLocation endLoc, |
| 56 | SourceLocation constructorLParen, |
| 57 | SourceLocation constructorRParen) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 58 | : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 59 | ty->isDependentType(), ty->isDependentType(), |
| 60 | ty->containsUnexpandedParameterPack()), |
John McCall | 6ec278d | 2011-01-27 09:37:56 +0000 | [diff] [blame] | 61 | GlobalNew(globalNew), Initializer(initializer), |
| 62 | UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), |
| 63 | SubExprs(0), OperatorNew(operatorNew), |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 64 | OperatorDelete(operatorDelete), Constructor(constructor), |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 65 | AllocatedTypeInfo(AllocatedTypeInfo), TypeIdParens(TypeIdParens), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 66 | StartLoc(startLoc), EndLoc(endLoc), ConstructorLParen(constructorLParen), |
| 67 | ConstructorRParen(constructorRParen) { |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 68 | AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 69 | unsigned i = 0; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 70 | if (Array) { |
| 71 | if (arraySize->containsUnexpandedParameterPack()) |
| 72 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 73 | |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 74 | SubExprs[i++] = arraySize; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | for (unsigned j = 0; j < NumPlacementArgs; ++j) { |
| 78 | if (placementArgs[j]->containsUnexpandedParameterPack()) |
| 79 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 80 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 81 | SubExprs[i++] = placementArgs[j]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | for (unsigned j = 0; j < NumConstructorArgs; ++j) { |
| 85 | if (constructorArgs[j]->containsUnexpandedParameterPack()) |
| 86 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 87 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 88 | SubExprs[i++] = constructorArgs[j]; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 89 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 92 | void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray, |
| 93 | unsigned numPlaceArgs, unsigned numConsArgs){ |
| 94 | assert(SubExprs == 0 && "SubExprs already allocated"); |
| 95 | Array = isArray; |
| 96 | NumPlacementArgs = numPlaceArgs; |
| 97 | NumConstructorArgs = numConsArgs; |
| 98 | |
| 99 | unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs; |
| 100 | SubExprs = new (C) Stmt*[TotalSize]; |
| 101 | } |
| 102 | |
Sebastian Redl | 8026f6d | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 103 | bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const { |
John McCall | c2f3e7f | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 104 | return getOperatorNew()->getType()-> |
Sebastian Redl | 8026f6d | 2011-03-13 17:09:40 +0000 | [diff] [blame] | 105 | castAs<FunctionProtoType>()->isNothrow(Ctx); |
John McCall | c2f3e7f | 2011-03-07 03:12:35 +0000 | [diff] [blame] | 106 | } |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 107 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 108 | // CXXDeleteExpr |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 109 | QualType CXXDeleteExpr::getDestroyedType() const { |
| 110 | const Expr *Arg = getArgument(); |
| 111 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg)) { |
| 112 | if (ICE->getCastKind() != CK_UserDefinedConversion && |
| 113 | ICE->getType()->isVoidPointerType()) |
| 114 | Arg = ICE->getSubExpr(); |
| 115 | else |
| 116 | break; |
| 117 | } |
Craig Silverstein | 0fa0b78 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 118 | // 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] | 119 | const QualType ArgType = Arg->getType(); |
Craig Silverstein | a437ad3 | 2010-11-16 07:16:25 +0000 | [diff] [blame] | 120 | |
| 121 | if (ArgType->isDependentType() && !ArgType->isPointerType()) |
| 122 | return QualType(); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 123 | |
Craig Silverstein | 0fa0b78 | 2010-10-20 00:38:15 +0000 | [diff] [blame] | 124 | return ArgType->getAs<PointerType>()->getPointeeType(); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 127 | // CXXPseudoDestructorExpr |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 128 | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
| 129 | : Type(Info) |
| 130 | { |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 131 | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 132 | } |
| 133 | |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 134 | CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 135 | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
| 136 | NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, |
| 137 | SourceLocation ColonColonLoc, SourceLocation TildeLoc, |
| 138 | PseudoDestructorTypeStorage DestroyedType) |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 139 | : Expr(CXXPseudoDestructorExprClass, |
| 140 | Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, |
| 141 | FunctionProtoType::ExtProtoInfo())), |
| 142 | VK_RValue, OK_Ordinary, |
| 143 | /*isTypeDependent=*/(Base->isTypeDependent() || |
| 144 | (DestroyedType.getTypeSourceInfo() && |
| 145 | DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 146 | /*isValueDependent=*/Base->isValueDependent(), |
| 147 | // ContainsUnexpandedParameterPack |
| 148 | (Base->containsUnexpandedParameterPack() || |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 149 | (QualifierLoc && |
| 150 | QualifierLoc.getNestedNameSpecifier() |
| 151 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 152 | (ScopeType && |
| 153 | ScopeType->getType()->containsUnexpandedParameterPack()) || |
| 154 | (DestroyedType.getTypeSourceInfo() && |
| 155 | DestroyedType.getTypeSourceInfo()->getType() |
| 156 | ->containsUnexpandedParameterPack()))), |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 157 | Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 158 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 159 | ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), |
| 160 | DestroyedType(DestroyedType) { } |
| 161 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 162 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
| 163 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 164 | return TInfo->getType(); |
| 165 | |
| 166 | return QualType(); |
| 167 | } |
| 168 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 169 | SourceRange CXXPseudoDestructorExpr::getSourceRange() const { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 170 | SourceLocation End = DestroyedType.getLocation(); |
| 171 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 172 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 173 | return SourceRange(Base->getLocStart(), End); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 177 | // UnresolvedLookupExpr |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 178 | UnresolvedLookupExpr * |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 179 | UnresolvedLookupExpr::Create(ASTContext &C, |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 180 | CXXRecordDecl *NamingClass, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 181 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 182 | const DeclarationNameInfo &NameInfo, |
| 183 | bool ADL, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 184 | const TemplateArgumentListInfo &Args, |
| 185 | UnresolvedSetIterator Begin, |
| 186 | UnresolvedSetIterator End) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 187 | { |
| 188 | void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) + |
| 189 | ExplicitTemplateArgumentList::sizeFor(Args)); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 190 | return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 191 | ADL, /*Overload*/ true, &Args, |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 192 | Begin, End, /*StdIsAssociated=*/false); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 195 | UnresolvedLookupExpr * |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 196 | UnresolvedLookupExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs, |
| 197 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 198 | std::size_t size = sizeof(UnresolvedLookupExpr); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 199 | if (HasExplicitTemplateArgs) |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 200 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 201 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 202 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>()); |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 203 | UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 204 | E->HasExplicitTemplateArgs = HasExplicitTemplateArgs; |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 205 | return E; |
| 206 | } |
| 207 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 208 | OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 209 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 210 | const DeclarationNameInfo &NameInfo, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 211 | const TemplateArgumentListInfo *TemplateArgs, |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 212 | UnresolvedSetIterator Begin, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 213 | UnresolvedSetIterator End, |
| 214 | bool KnownDependent, |
| 215 | bool KnownContainsUnexpandedParameterPack) |
| 216 | : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, |
| 217 | KnownDependent, |
| 218 | (KnownContainsUnexpandedParameterPack || |
| 219 | NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 220 | (QualifierLoc && |
| 221 | QualifierLoc.getNestedNameSpecifier() |
| 222 | ->containsUnexpandedParameterPack()))), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 223 | Results(0), NumResults(End - Begin), NameInfo(NameInfo), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 224 | QualifierLoc(QualifierLoc), HasExplicitTemplateArgs(TemplateArgs != 0) |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 225 | { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 226 | NumResults = End - Begin; |
| 227 | if (NumResults) { |
| 228 | // Determine whether this expression is type-dependent. |
| 229 | for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) { |
| 230 | if ((*I)->getDeclContext()->isDependentContext() || |
| 231 | isa<UnresolvedUsingValueDecl>(*I)) { |
| 232 | ExprBits.TypeDependent = true; |
| 233 | ExprBits.ValueDependent = true; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | Results = static_cast<DeclAccessPair *>( |
| 238 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 239 | llvm::alignOf<DeclAccessPair>())); |
| 240 | memcpy(Results, &*Begin.getIterator(), |
| 241 | NumResults * sizeof(DeclAccessPair)); |
| 242 | } |
| 243 | |
| 244 | // If we have explicit template arguments, check for dependent |
| 245 | // template arguments and whether they contain any unexpanded pack |
| 246 | // expansions. |
| 247 | if (TemplateArgs) { |
| 248 | bool Dependent = false; |
| 249 | bool ContainsUnexpandedParameterPack = false; |
| 250 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent, |
| 251 | ContainsUnexpandedParameterPack); |
| 252 | |
| 253 | if (Dependent) { |
| 254 | ExprBits.TypeDependent = true; |
| 255 | ExprBits.ValueDependent = true; |
| 256 | } |
| 257 | if (ContainsUnexpandedParameterPack) |
| 258 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 259 | } |
| 260 | |
| 261 | if (isTypeDependent()) |
| 262 | setType(C.DependentTy); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void OverloadExpr::initializeResults(ASTContext &C, |
| 266 | UnresolvedSetIterator Begin, |
| 267 | UnresolvedSetIterator End) { |
| 268 | assert(Results == 0 && "Results already initialized!"); |
| 269 | NumResults = End - Begin; |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 270 | if (NumResults) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 271 | Results = static_cast<DeclAccessPair *>( |
| 272 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 273 | |
| 274 | llvm::alignOf<DeclAccessPair>())); |
| 275 | memcpy(Results, &*Begin.getIterator(), |
| 276 | NumResults * sizeof(DeclAccessPair)); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
John McCall | e9ee23e | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 280 | CXXRecordDecl *OverloadExpr::getNamingClass() const { |
| 281 | if (isa<UnresolvedLookupExpr>(this)) |
| 282 | return cast<UnresolvedLookupExpr>(this)->getNamingClass(); |
| 283 | else |
| 284 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
| 285 | } |
| 286 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 287 | // DependentScopeDeclRefExpr |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 288 | DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T, |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 289 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 290 | const DeclarationNameInfo &NameInfo, |
| 291 | const TemplateArgumentListInfo *Args) |
| 292 | : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, |
| 293 | true, true, |
| 294 | (NameInfo.containsUnexpandedParameterPack() || |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 295 | (QualifierLoc && |
| 296 | QualifierLoc.getNestedNameSpecifier() |
| 297 | ->containsUnexpandedParameterPack()))), |
| 298 | QualifierLoc(QualifierLoc), NameInfo(NameInfo), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 299 | HasExplicitTemplateArgs(Args != 0) |
| 300 | { |
| 301 | if (Args) { |
| 302 | bool Dependent = true; |
| 303 | bool ContainsUnexpandedParameterPack |
| 304 | = ExprBits.ContainsUnexpandedParameterPack; |
| 305 | |
| 306 | reinterpret_cast<ExplicitTemplateArgumentList*>(this+1) |
| 307 | ->initializeFrom(*Args, Dependent, ContainsUnexpandedParameterPack); |
| 308 | ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; |
| 309 | } |
| 310 | } |
| 311 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 312 | DependentScopeDeclRefExpr * |
| 313 | DependentScopeDeclRefExpr::Create(ASTContext &C, |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 314 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 315 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 316 | const TemplateArgumentListInfo *Args) { |
| 317 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 318 | if (Args) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 319 | size += ExplicitTemplateArgumentList::sizeFor(*Args); |
| 320 | void *Mem = C.Allocate(size); |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 321 | return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 322 | NameInfo, Args); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 325 | DependentScopeDeclRefExpr * |
| 326 | DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C, |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 327 | bool HasExplicitTemplateArgs, |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 328 | unsigned NumTemplateArgs) { |
| 329 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 330 | if (HasExplicitTemplateArgs) |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 331 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 332 | void *Mem = C.Allocate(size); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 333 | DependentScopeDeclRefExpr *E |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 334 | = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 335 | DeclarationNameInfo(), 0); |
| 336 | E->HasExplicitTemplateArgs = HasExplicitTemplateArgs; |
| 337 | return E; |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 340 | SourceRange CXXConstructExpr::getSourceRange() const { |
John McCall | 2882eca | 2011-02-21 06:23:05 +0000 | [diff] [blame] | 341 | if (isa<CXXTemporaryObjectExpr>(this)) |
| 342 | return cast<CXXTemporaryObjectExpr>(this)->getSourceRange(); |
| 343 | |
Douglas Gregor | 40749ee | 2010-11-03 00:35:38 +0000 | [diff] [blame] | 344 | if (ParenRange.isValid()) |
| 345 | return SourceRange(Loc, ParenRange.getEnd()); |
| 346 | |
| 347 | SourceLocation End = Loc; |
| 348 | for (unsigned I = getNumArgs(); I > 0; --I) { |
| 349 | const Expr *Arg = getArg(I-1); |
| 350 | if (!Arg->isDefaultArgument()) { |
| 351 | SourceLocation NewEnd = Arg->getLocEnd(); |
| 352 | if (NewEnd.isValid()) { |
| 353 | End = NewEnd; |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return SourceRange(Loc, End); |
Ted Kremenek | e383768 | 2009-12-23 04:00:48 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 362 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 363 | OverloadedOperatorKind Kind = getOperator(); |
| 364 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 365 | if (getNumArgs() == 1) |
| 366 | // Prefix operator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | return SourceRange(getOperatorLoc(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 368 | getArg(0)->getSourceRange().getEnd()); |
| 369 | else |
| 370 | // Postfix operator |
Chandler Carruth | d765061 | 2011-04-02 09:47:38 +0000 | [diff] [blame] | 371 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 372 | getOperatorLoc()); |
Chandler Carruth | d765061 | 2011-04-02 09:47:38 +0000 | [diff] [blame] | 373 | } else if (Kind == OO_Arrow) { |
| 374 | return getArg(0)->getSourceRange(); |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 375 | } else if (Kind == OO_Call) { |
| 376 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 377 | } else if (Kind == OO_Subscript) { |
| 378 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 379 | } else if (getNumArgs() == 1) { |
| 380 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 381 | } else if (getNumArgs() == 2) { |
| 382 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 383 | getArg(1)->getSourceRange().getEnd()); |
| 384 | } else { |
| 385 | return SourceRange(); |
| 386 | } |
| 387 | } |
| 388 | |
Ted Kremenek | b277159 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 389 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { |
| 390 | if (const MemberExpr *MemExpr = |
| 391 | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 392 | return MemExpr->getBase(); |
| 393 | |
| 394 | // FIXME: Will eventually need to cope with member pointers. |
| 395 | return 0; |
| 396 | } |
| 397 | |
Ted Kremenek | b277159 | 2011-03-30 17:41:19 +0000 | [diff] [blame] | 398 | CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { |
| 399 | if (const MemberExpr *MemExpr = |
| 400 | dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 401 | return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
| 402 | |
| 403 | // FIXME: Will eventually need to cope with member pointers. |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | |
Chandler Carruth | 007a9b1 | 2010-10-27 06:55:41 +0000 | [diff] [blame] | 408 | CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() { |
| 409 | Expr* ThisArg = getImplicitObjectArgument(); |
| 410 | if (!ThisArg) |
| 411 | return 0; |
| 412 | |
| 413 | if (ThisArg->getType()->isAnyPointerType()) |
| 414 | return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); |
| 415 | |
| 416 | return ThisArg->getType()->getAsCXXRecordDecl(); |
| 417 | } |
| 418 | |
Douglas Gregor | 00b98c2 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 419 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 420 | //===----------------------------------------------------------------------===// |
| 421 | // Named casts |
| 422 | //===----------------------------------------------------------------------===// |
| 423 | |
| 424 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 425 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 426 | /// "const_cast". The returned pointer must not be freed. |
| 427 | const char *CXXNamedCastExpr::getCastName() const { |
| 428 | switch (getStmtClass()) { |
| 429 | case CXXStaticCastExprClass: return "static_cast"; |
| 430 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 431 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 432 | case CXXConstCastExprClass: return "const_cast"; |
| 433 | default: return "<invalid cast>"; |
| 434 | } |
| 435 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 436 | |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 437 | CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 438 | ExprValueKind VK, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 439 | CastKind K, Expr *Op, |
| 440 | const CXXCastPath *BasePath, |
| 441 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 442 | SourceLocation L, |
| 443 | SourceLocation RParenLoc) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 444 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 445 | void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr) |
| 446 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 447 | CXXStaticCastExpr *E = |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 448 | new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 449 | RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 450 | if (PathSize) E->setCastPath(*BasePath); |
| 451 | return E; |
| 452 | } |
| 453 | |
| 454 | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C, |
| 455 | unsigned PathSize) { |
| 456 | void *Buffer = |
| 457 | C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 458 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
| 459 | } |
| 460 | |
| 461 | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 462 | ExprValueKind VK, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 463 | CastKind K, Expr *Op, |
| 464 | const CXXCastPath *BasePath, |
| 465 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 466 | SourceLocation L, |
| 467 | SourceLocation RParenLoc) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 468 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 469 | void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr) |
| 470 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 471 | CXXDynamicCastExpr *E = |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 472 | new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 473 | RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 474 | if (PathSize) E->setCastPath(*BasePath); |
| 475 | return E; |
| 476 | } |
| 477 | |
| 478 | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C, |
| 479 | unsigned PathSize) { |
| 480 | void *Buffer = |
| 481 | C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 482 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
| 483 | } |
| 484 | |
Anders Carlsson | 0fee330 | 2011-04-11 01:43:55 +0000 | [diff] [blame] | 485 | /// isAlwaysNull - Return whether the result of the dynamic_cast is proven |
| 486 | /// to always be null. For example: |
| 487 | /// |
| 488 | /// struct A { }; |
| 489 | /// struct B final : A { }; |
| 490 | /// struct C { }; |
| 491 | /// |
| 492 | /// C *f(B* b) { return dynamic_cast<C*>(b); } |
| 493 | bool CXXDynamicCastExpr::isAlwaysNull() const |
| 494 | { |
| 495 | QualType SrcType = getSubExpr()->getType(); |
| 496 | QualType DestType = getType(); |
| 497 | |
| 498 | if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) { |
| 499 | SrcType = SrcPTy->getPointeeType(); |
| 500 | DestType = DestType->castAs<PointerType>()->getPointeeType(); |
| 501 | } |
| 502 | |
| 503 | const CXXRecordDecl *SrcRD = |
| 504 | cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); |
| 505 | |
| 506 | if (!SrcRD->hasAttr<FinalAttr>()) |
| 507 | return false; |
| 508 | |
| 509 | const CXXRecordDecl *DestRD = |
| 510 | cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); |
| 511 | |
| 512 | return !DestRD->isDerivedFrom(SrcRD); |
| 513 | } |
| 514 | |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 515 | CXXReinterpretCastExpr * |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 516 | CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK, |
| 517 | CastKind K, Expr *Op, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 518 | const CXXCastPath *BasePath, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 519 | TypeSourceInfo *WrittenTy, SourceLocation L, |
| 520 | SourceLocation RParenLoc) { |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 521 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 522 | void *Buffer = |
| 523 | C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 524 | CXXReinterpretCastExpr *E = |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 525 | new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, |
| 526 | RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 527 | if (PathSize) E->setCastPath(*BasePath); |
| 528 | return E; |
| 529 | } |
| 530 | |
| 531 | CXXReinterpretCastExpr * |
| 532 | CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 533 | void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr) |
| 534 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 535 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
| 536 | } |
| 537 | |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 538 | CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T, |
| 539 | ExprValueKind VK, Expr *Op, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 540 | TypeSourceInfo *WrittenTy, |
Douglas Gregor | 1d5d0b9 | 2011-01-12 22:41:29 +0000 | [diff] [blame] | 541 | SourceLocation L, |
| 542 | SourceLocation RParenLoc) { |
| 543 | return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) { |
| 547 | return new (C) CXXConstCastExpr(EmptyShell()); |
| 548 | } |
| 549 | |
| 550 | CXXFunctionalCastExpr * |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 551 | CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK, |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 552 | TypeSourceInfo *Written, SourceLocation L, |
| 553 | CastKind K, Expr *Op, const CXXCastPath *BasePath, |
| 554 | SourceLocation R) { |
| 555 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 556 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 557 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 558 | CXXFunctionalCastExpr *E = |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 559 | new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R); |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 560 | if (PathSize) E->setCastPath(*BasePath); |
| 561 | return E; |
| 562 | } |
| 563 | |
| 564 | CXXFunctionalCastExpr * |
| 565 | CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 566 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 567 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 568 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
| 569 | } |
| 570 | |
| 571 | |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 572 | CXXDefaultArgExpr * |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 573 | CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc, |
| 574 | ParmVarDecl *Param, Expr *SubExpr) { |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 575 | void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 576 | return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, |
| 577 | SubExpr); |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 580 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 581 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 582 | return new (C) CXXTemporary(Destructor); |
| 583 | } |
| 584 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 586 | CXXTemporary *Temp, |
| 587 | Expr* SubExpr) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 588 | assert(SubExpr->getType()->isRecordType() && |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 589 | "Expression bound to a temporary must have record type!"); |
| 590 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 591 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 594 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 595 | CXXConstructorDecl *Cons, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 596 | TypeSourceInfo *Type, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 597 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | unsigned NumArgs, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 599 | SourceRange parenRange, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 600 | bool ZeroInitialization) |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 601 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, |
| 602 | Type->getType().getNonReferenceType(), |
| 603 | Type->getTypeLoc().getBeginLoc(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 604 | Cons, false, Args, NumArgs, ZeroInitialization, |
| 605 | CXXConstructExpr::CK_Complete, parenRange), |
| 606 | Type(Type) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | SourceRange CXXTemporaryObjectExpr::getSourceRange() const { |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 610 | return SourceRange(Type->getTypeLoc().getBeginLoc(), |
| 611 | getParenRange().getEnd()); |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 612 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 613 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 615 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 616 | CXXConstructorDecl *D, bool Elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 617 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 618 | bool ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 619 | ConstructionKind ConstructKind, |
| 620 | SourceRange ParenRange) { |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 621 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 622 | Elidable, Args, NumArgs, ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 623 | ConstructKind, ParenRange); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 627 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 628 | CXXConstructorDecl *D, bool elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 629 | Expr **args, unsigned numargs, |
Anders Carlsson | 72e96fd | 2010-05-02 22:54:08 +0000 | [diff] [blame] | 630 | bool ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 631 | ConstructionKind ConstructKind, |
| 632 | SourceRange ParenRange) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 633 | : Expr(SC, T, VK_RValue, OK_Ordinary, |
| 634 | T->isDependentType(), T->isDependentType(), |
| 635 | T->containsUnexpandedParameterPack()), |
| 636 | Constructor(D), Loc(Loc), ParenRange(ParenRange), Elidable(elidable), |
| 637 | ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind), |
| 638 | Args(0), NumArgs(numargs) |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 639 | { |
| 640 | if (NumArgs) { |
| 641 | Args = new (C) Stmt*[NumArgs]; |
| 642 | |
| 643 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 644 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 645 | |
| 646 | if (args[i]->isValueDependent()) |
| 647 | ExprBits.ValueDependent = true; |
| 648 | if (args[i]->containsUnexpandedParameterPack()) |
| 649 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 650 | |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 651 | Args[i] = args[i]; |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 652 | } |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 653 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 654 | } |
| 655 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 656 | ExprWithCleanups::ExprWithCleanups(ASTContext &C, |
| 657 | Expr *subexpr, |
| 658 | CXXTemporary **temps, |
| 659 | unsigned numtemps) |
| 660 | : Expr(ExprWithCleanupsClass, subexpr->getType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 661 | subexpr->getValueKind(), subexpr->getObjectKind(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 662 | subexpr->isTypeDependent(), subexpr->isValueDependent(), |
| 663 | subexpr->containsUnexpandedParameterPack()), |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 664 | SubExpr(subexpr), Temps(0), NumTemps(0) { |
Chris Lattner | aff32cb | 2010-05-10 00:45:12 +0000 | [diff] [blame] | 665 | if (numtemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 666 | setNumTemporaries(C, numtemps); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 667 | for (unsigned i = 0; i != numtemps; ++i) |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 668 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 672 | void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 673 | assert(Temps == 0 && "Cannot resize with this"); |
Daniel Dunbar | 90556d4 | 2010-05-10 15:59:37 +0000 | [diff] [blame] | 674 | NumTemps = N; |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 675 | Temps = new (C) CXXTemporary*[NumTemps]; |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 679 | ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, |
| 680 | Expr *SubExpr, |
| 681 | CXXTemporary **Temps, |
| 682 | unsigned NumTemps) { |
| 683 | return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 686 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 687 | SourceLocation LParenLoc, |
| 688 | Expr **Args, |
| 689 | unsigned NumArgs, |
| 690 | SourceLocation RParenLoc) |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 691 | : Expr(CXXUnresolvedConstructExprClass, |
| 692 | Type->getType().getNonReferenceType(), |
John McCall | 0943168 | 2010-11-18 19:01:18 +0000 | [diff] [blame] | 693 | VK_LValue, OK_Ordinary, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 694 | Type->getType()->isDependentType(), true, |
| 695 | Type->getType()->containsUnexpandedParameterPack()), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 696 | Type(Type), |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 697 | LParenLoc(LParenLoc), |
| 698 | RParenLoc(RParenLoc), |
| 699 | NumArgs(NumArgs) { |
| 700 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 701 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 702 | if (Args[I]->containsUnexpandedParameterPack()) |
| 703 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 704 | |
| 705 | StoredArgs[I] = Args[I]; |
| 706 | } |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 711 | TypeSourceInfo *Type, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 712 | SourceLocation LParenLoc, |
| 713 | Expr **Args, |
| 714 | unsigned NumArgs, |
| 715 | SourceLocation RParenLoc) { |
| 716 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 717 | sizeof(Expr *) * NumArgs); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 718 | return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 719 | Args, NumArgs, RParenLoc); |
| 720 | } |
| 721 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 722 | CXXUnresolvedConstructExpr * |
| 723 | CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) { |
| 724 | Stmt::EmptyShell Empty; |
| 725 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 726 | sizeof(Expr *) * NumArgs); |
| 727 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 728 | } |
| 729 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 730 | SourceRange CXXUnresolvedConstructExpr::getSourceRange() const { |
| 731 | return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc); |
| 732 | } |
| 733 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 734 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 735 | Expr *Base, QualType BaseType, |
| 736 | bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 737 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 738 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 739 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 740 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 741 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 742 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 743 | VK_LValue, OK_Ordinary, true, true, |
| 744 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 745 | (QualifierLoc && |
| 746 | QualifierLoc.getNestedNameSpecifier() |
| 747 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 748 | MemberNameInfo.containsUnexpandedParameterPack())), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 749 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 750 | HasExplicitTemplateArgs(TemplateArgs != 0), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 751 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 752 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 753 | MemberNameInfo(MemberNameInfo) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 754 | if (TemplateArgs) { |
| 755 | bool Dependent = true; |
| 756 | bool ContainsUnexpandedParameterPack = false; |
| 757 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent, |
| 758 | ContainsUnexpandedParameterPack); |
| 759 | if (ContainsUnexpandedParameterPack) |
| 760 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 761 | } |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 764 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
| 765 | Expr *Base, QualType BaseType, |
| 766 | bool IsArrow, |
| 767 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 768 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 769 | NamedDecl *FirstQualifierFoundInScope, |
| 770 | DeclarationNameInfo MemberNameInfo) |
| 771 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
| 772 | VK_LValue, OK_Ordinary, true, true, |
| 773 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 774 | (QualifierLoc && |
| 775 | QualifierLoc.getNestedNameSpecifier()-> |
| 776 | containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 777 | MemberNameInfo.containsUnexpandedParameterPack())), |
| 778 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 779 | HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 780 | QualifierLoc(QualifierLoc), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 781 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
| 782 | MemberNameInfo(MemberNameInfo) { } |
| 783 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 784 | CXXDependentScopeMemberExpr * |
| 785 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 786 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 787 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 788 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 789 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 790 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 791 | const TemplateArgumentListInfo *TemplateArgs) { |
| 792 | if (!TemplateArgs) |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 793 | return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 794 | IsArrow, OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 795 | QualifierLoc, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 796 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 797 | MemberNameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 799 | std::size_t size = sizeof(CXXDependentScopeMemberExpr); |
| 800 | if (TemplateArgs) |
| 801 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 802 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 803 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 804 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 805 | IsArrow, OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 806 | QualifierLoc, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 807 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 808 | MemberNameInfo, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 811 | CXXDependentScopeMemberExpr * |
| 812 | CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C, |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 813 | bool HasExplicitTemplateArgs, |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 814 | unsigned NumTemplateArgs) { |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 815 | if (!HasExplicitTemplateArgs) |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 816 | return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 817 | 0, SourceLocation(), |
| 818 | NestedNameSpecifierLoc(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 819 | DeclarationNameInfo()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 820 | |
| 821 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) + |
| 822 | ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 823 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 824 | CXXDependentScopeMemberExpr *E |
| 825 | = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 826 | 0, SourceLocation(), |
| 827 | NestedNameSpecifierLoc(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 828 | DeclarationNameInfo(), 0); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 829 | E->HasExplicitTemplateArgs = true; |
| 830 | return E; |
| 831 | } |
| 832 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 833 | bool CXXDependentScopeMemberExpr::isImplicitAccess() const { |
| 834 | if (Base == 0) |
| 835 | return true; |
| 836 | |
Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 837 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 838 | } |
| 839 | |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 840 | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
| 841 | UnresolvedSetIterator end) { |
| 842 | do { |
| 843 | NamedDecl *decl = *begin; |
| 844 | if (isa<UnresolvedUsingValueDecl>(decl)) |
| 845 | return false; |
| 846 | if (isa<UsingShadowDecl>(decl)) |
| 847 | decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl(); |
| 848 | |
| 849 | // Unresolved member expressions should only contain methods and |
| 850 | // method templates. |
| 851 | assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl)); |
| 852 | |
| 853 | if (isa<FunctionTemplateDecl>(decl)) |
| 854 | decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl(); |
| 855 | if (cast<CXXMethodDecl>(decl)->isStatic()) |
| 856 | return false; |
| 857 | } while (++begin != end); |
| 858 | |
| 859 | return true; |
| 860 | } |
| 861 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 862 | UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 863 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 864 | Expr *Base, QualType BaseType, |
| 865 | bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 866 | SourceLocation OperatorLoc, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 867 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 868 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 869 | const TemplateArgumentListInfo *TemplateArgs, |
| 870 | UnresolvedSetIterator Begin, |
| 871 | UnresolvedSetIterator End) |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 872 | : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 873 | TemplateArgs, Begin, End, |
| 874 | // Dependent |
| 875 | ((Base && Base->isTypeDependent()) || |
| 876 | BaseType->isDependentType()), |
| 877 | // Contains unexpanded parameter pack |
| 878 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 879 | BaseType->containsUnexpandedParameterPack())), |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 880 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 881 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 882 | |
| 883 | // Check whether all of the members are non-static member functions, |
| 884 | // and if so, mark give this bound-member type instead of overload type. |
| 885 | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
| 886 | setType(C.BoundMemberTy); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 889 | bool UnresolvedMemberExpr::isImplicitAccess() const { |
| 890 | if (Base == 0) |
| 891 | return true; |
| 892 | |
Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 893 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 894 | } |
| 895 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 896 | UnresolvedMemberExpr * |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 897 | UnresolvedMemberExpr::Create(ASTContext &C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 898 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 899 | Expr *Base, QualType BaseType, bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 900 | SourceLocation OperatorLoc, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 901 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 902 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 903 | const TemplateArgumentListInfo *TemplateArgs, |
| 904 | UnresolvedSetIterator Begin, |
| 905 | UnresolvedSetIterator End) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 906 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 907 | if (TemplateArgs) |
| 908 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 909 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 910 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 911 | return new (Mem) UnresolvedMemberExpr(C, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 912 | HasUnresolvedUsing, Base, BaseType, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 913 | IsArrow, OperatorLoc, QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 914 | MemberNameInfo, TemplateArgs, Begin, End); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 917 | UnresolvedMemberExpr * |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 918 | UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs, |
| 919 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 920 | std::size_t size = sizeof(UnresolvedMemberExpr); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 921 | if (HasExplicitTemplateArgs) |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 922 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 923 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 924 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 925 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 926 | E->HasExplicitTemplateArgs = HasExplicitTemplateArgs; |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 927 | return E; |
| 928 | } |
| 929 | |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 930 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 931 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 932 | |
| 933 | // If there was a nested name specifier, it names the naming class. |
| 934 | // It can't be dependent: after all, we were actually able to do the |
| 935 | // lookup. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 936 | CXXRecordDecl *Record = 0; |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 937 | if (getQualifier()) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 938 | const Type *T = getQualifier()->getAsType(); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 939 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 940 | Record = T->getAsCXXRecordDecl(); |
| 941 | assert(Record && "qualifier in member expression does not name record"); |
| 942 | } |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 943 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 944 | else { |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 945 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 946 | if (isArrow()) { |
| 947 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 948 | assert(PT && "base of arrow member access is not pointer"); |
| 949 | BaseType = PT->getPointeeType(); |
| 950 | } |
| 951 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 952 | Record = BaseType->getAsCXXRecordDecl(); |
| 953 | assert(Record && "base of member expression does not name record"); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 956 | return Record; |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 959 | SubstNonTypeTemplateParmPackExpr:: |
| 960 | SubstNonTypeTemplateParmPackExpr(QualType T, |
| 961 | NonTypeTemplateParmDecl *Param, |
| 962 | SourceLocation NameLoc, |
| 963 | const TemplateArgument &ArgPack) |
| 964 | : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, |
| 965 | true, false, true), |
| 966 | Param(Param), Arguments(ArgPack.pack_begin()), |
| 967 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } |
| 968 | |
| 969 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
| 970 | return TemplateArgument(Arguments, NumArguments); |
| 971 | } |
| 972 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 973 | |