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