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) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | assert(SubExpr->getType()->isRecordType() && |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 622 | "Expression bound to a temporary must have record type!"); |
| 623 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 624 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 627 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 628 | CXXConstructorDecl *Cons, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 629 | TypeSourceInfo *Type, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 630 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | unsigned NumArgs, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 632 | SourceRange parenRange, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame^] | 633 | bool HadMultipleCandidates, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 634 | bool ZeroInitialization) |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 635 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, |
| 636 | Type->getType().getNonReferenceType(), |
| 637 | Type->getTypeLoc().getBeginLoc(), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame^] | 638 | Cons, false, Args, NumArgs, |
| 639 | HadMultipleCandidates, ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 640 | CXXConstructExpr::CK_Complete, parenRange), |
| 641 | Type(Type) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | SourceRange CXXTemporaryObjectExpr::getSourceRange() const { |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 645 | return SourceRange(Type->getTypeLoc().getBeginLoc(), |
| 646 | getParenRange().getEnd()); |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 647 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 648 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 650 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 651 | CXXConstructorDecl *D, bool Elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 652 | Expr **Args, unsigned NumArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame^] | 653 | bool HadMultipleCandidates, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 654 | bool ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 655 | ConstructionKind ConstructKind, |
| 656 | SourceRange ParenRange) { |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 657 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame^] | 658 | Elidable, Args, NumArgs, |
| 659 | HadMultipleCandidates, ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 660 | ConstructKind, ParenRange); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 664 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 665 | CXXConstructorDecl *D, bool elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 666 | Expr **args, unsigned numargs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame^] | 667 | bool HadMultipleCandidates, |
| 668 | bool ZeroInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 669 | ConstructionKind ConstructKind, |
| 670 | SourceRange ParenRange) |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 671 | : Expr(SC, T, VK_RValue, OK_Ordinary, |
| 672 | T->isDependentType(), T->isDependentType(), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 673 | T->isInstantiationDependentType(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 674 | T->containsUnexpandedParameterPack()), |
Douglas Gregor | a48e676 | 2011-09-26 14:47:03 +0000 | [diff] [blame] | 675 | Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(numargs), |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame^] | 676 | Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates), |
| 677 | ZeroInitialization(ZeroInitialization), |
Douglas Gregor | a48e676 | 2011-09-26 14:47:03 +0000 | [diff] [blame] | 678 | ConstructKind(ConstructKind), Args(0) |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 679 | { |
| 680 | if (NumArgs) { |
| 681 | Args = new (C) Stmt*[NumArgs]; |
| 682 | |
| 683 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 684 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 685 | |
| 686 | if (args[i]->isValueDependent()) |
| 687 | ExprBits.ValueDependent = true; |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 688 | if (args[i]->isInstantiationDependent()) |
| 689 | ExprBits.InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 690 | if (args[i]->containsUnexpandedParameterPack()) |
| 691 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 692 | |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 693 | Args[i] = args[i]; |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 694 | } |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 695 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 696 | } |
| 697 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 698 | ExprWithCleanups::ExprWithCleanups(ASTContext &C, |
| 699 | Expr *subexpr, |
| 700 | CXXTemporary **temps, |
| 701 | unsigned numtemps) |
| 702 | : Expr(ExprWithCleanupsClass, subexpr->getType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 703 | subexpr->getValueKind(), subexpr->getObjectKind(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 704 | subexpr->isTypeDependent(), subexpr->isValueDependent(), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 705 | subexpr->isInstantiationDependent(), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 706 | subexpr->containsUnexpandedParameterPack()), |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 707 | SubExpr(subexpr), Temps(0), NumTemps(0) { |
Chris Lattner | aff32cb | 2010-05-10 00:45:12 +0000 | [diff] [blame] | 708 | if (numtemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 709 | setNumTemporaries(C, numtemps); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 710 | for (unsigned i = 0; i != numtemps; ++i) |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 711 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 715 | void ExprWithCleanups::setNumTemporaries(ASTContext &C, unsigned N) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 716 | assert(Temps == 0 && "Cannot resize with this"); |
Daniel Dunbar | 90556d4 | 2010-05-10 15:59:37 +0000 | [diff] [blame] | 717 | NumTemps = N; |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 718 | Temps = new (C) CXXTemporary*[NumTemps]; |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 722 | ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, |
| 723 | Expr *SubExpr, |
| 724 | CXXTemporary **Temps, |
| 725 | unsigned NumTemps) { |
| 726 | return new (C) ExprWithCleanups(C, SubExpr, Temps, NumTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 729 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 730 | SourceLocation LParenLoc, |
| 731 | Expr **Args, |
| 732 | unsigned NumArgs, |
| 733 | SourceLocation RParenLoc) |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 734 | : Expr(CXXUnresolvedConstructExprClass, |
| 735 | Type->getType().getNonReferenceType(), |
Douglas Gregor | 032c869 | 2011-07-08 15:50:43 +0000 | [diff] [blame] | 736 | (Type->getType()->isLValueReferenceType() ? VK_LValue |
| 737 | :Type->getType()->isRValueReferenceType()? VK_XValue |
| 738 | :VK_RValue), |
| 739 | OK_Ordinary, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 740 | Type->getType()->isDependentType(), true, true, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 741 | Type->getType()->containsUnexpandedParameterPack()), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 742 | Type(Type), |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 743 | LParenLoc(LParenLoc), |
| 744 | RParenLoc(RParenLoc), |
| 745 | NumArgs(NumArgs) { |
| 746 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 747 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 748 | if (Args[I]->containsUnexpandedParameterPack()) |
| 749 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 750 | |
| 751 | StoredArgs[I] = Args[I]; |
| 752 | } |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 757 | TypeSourceInfo *Type, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 758 | SourceLocation LParenLoc, |
| 759 | Expr **Args, |
| 760 | unsigned NumArgs, |
| 761 | SourceLocation RParenLoc) { |
| 762 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 763 | sizeof(Expr *) * NumArgs); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 764 | return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 765 | Args, NumArgs, RParenLoc); |
| 766 | } |
| 767 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 768 | CXXUnresolvedConstructExpr * |
| 769 | CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) { |
| 770 | Stmt::EmptyShell Empty; |
| 771 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 772 | sizeof(Expr *) * NumArgs); |
| 773 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 774 | } |
| 775 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 776 | SourceRange CXXUnresolvedConstructExpr::getSourceRange() const { |
| 777 | return SourceRange(Type->getTypeLoc().getBeginLoc(), RParenLoc); |
| 778 | } |
| 779 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 780 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 781 | Expr *Base, QualType BaseType, |
| 782 | bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 783 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 784 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 785 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 786 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 787 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 788 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 789 | VK_LValue, OK_Ordinary, true, true, true, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 790 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 791 | (QualifierLoc && |
| 792 | QualifierLoc.getNestedNameSpecifier() |
| 793 | ->containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 794 | MemberNameInfo.containsUnexpandedParameterPack())), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 795 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 796 | HasExplicitTemplateArgs(TemplateArgs != 0), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 797 | OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 798 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 799 | MemberNameInfo(MemberNameInfo) { |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 800 | if (TemplateArgs) { |
| 801 | bool Dependent = true; |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 802 | bool InstantiationDependent = true; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 803 | bool ContainsUnexpandedParameterPack = false; |
| 804 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 805 | InstantiationDependent, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 806 | ContainsUnexpandedParameterPack); |
| 807 | if (ContainsUnexpandedParameterPack) |
| 808 | ExprBits.ContainsUnexpandedParameterPack = true; |
| 809 | } |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 812 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
| 813 | Expr *Base, QualType BaseType, |
| 814 | bool IsArrow, |
| 815 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 816 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 817 | NamedDecl *FirstQualifierFoundInScope, |
| 818 | DeclarationNameInfo MemberNameInfo) |
| 819 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 820 | VK_LValue, OK_Ordinary, true, true, true, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 821 | ((Base && Base->containsUnexpandedParameterPack()) || |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 822 | (QualifierLoc && |
| 823 | QualifierLoc.getNestedNameSpecifier()-> |
| 824 | containsUnexpandedParameterPack()) || |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 825 | MemberNameInfo.containsUnexpandedParameterPack())), |
| 826 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 827 | HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 828 | QualifierLoc(QualifierLoc), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 829 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
| 830 | MemberNameInfo(MemberNameInfo) { } |
| 831 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 832 | CXXDependentScopeMemberExpr * |
| 833 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 834 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 835 | SourceLocation OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 836 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 837 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 838 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 839 | const TemplateArgumentListInfo *TemplateArgs) { |
| 840 | if (!TemplateArgs) |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 841 | return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 842 | IsArrow, OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 843 | QualifierLoc, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 844 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 845 | MemberNameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 847 | std::size_t size = sizeof(CXXDependentScopeMemberExpr); |
| 848 | if (TemplateArgs) |
Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 849 | size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 850 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 851 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 852 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 853 | IsArrow, OperatorLoc, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 854 | QualifierLoc, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 855 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 856 | MemberNameInfo, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 859 | CXXDependentScopeMemberExpr * |
| 860 | CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C, |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 861 | bool HasExplicitTemplateArgs, |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 862 | unsigned NumTemplateArgs) { |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 863 | if (!HasExplicitTemplateArgs) |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 864 | return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 865 | 0, SourceLocation(), |
| 866 | NestedNameSpecifierLoc(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 867 | DeclarationNameInfo()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 868 | |
| 869 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) + |
Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 870 | ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 871 | void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 872 | CXXDependentScopeMemberExpr *E |
| 873 | = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 874 | 0, SourceLocation(), |
| 875 | NestedNameSpecifierLoc(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 876 | DeclarationNameInfo(), 0); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 877 | E->HasExplicitTemplateArgs = true; |
| 878 | return E; |
| 879 | } |
| 880 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 881 | bool CXXDependentScopeMemberExpr::isImplicitAccess() const { |
| 882 | if (Base == 0) |
| 883 | return true; |
| 884 | |
Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 885 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 886 | } |
| 887 | |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 888 | static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, |
| 889 | UnresolvedSetIterator end) { |
| 890 | do { |
| 891 | NamedDecl *decl = *begin; |
| 892 | if (isa<UnresolvedUsingValueDecl>(decl)) |
| 893 | return false; |
| 894 | if (isa<UsingShadowDecl>(decl)) |
| 895 | decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl(); |
| 896 | |
| 897 | // Unresolved member expressions should only contain methods and |
| 898 | // method templates. |
| 899 | assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl)); |
| 900 | |
| 901 | if (isa<FunctionTemplateDecl>(decl)) |
| 902 | decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl(); |
| 903 | if (cast<CXXMethodDecl>(decl)->isStatic()) |
| 904 | return false; |
| 905 | } while (++begin != end); |
| 906 | |
| 907 | return true; |
| 908 | } |
| 909 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 910 | UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 911 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 912 | Expr *Base, QualType BaseType, |
| 913 | bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 914 | SourceLocation OperatorLoc, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 915 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 916 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 917 | const TemplateArgumentListInfo *TemplateArgs, |
| 918 | UnresolvedSetIterator Begin, |
| 919 | UnresolvedSetIterator End) |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 920 | : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, MemberNameInfo, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 921 | TemplateArgs, Begin, End, |
| 922 | // Dependent |
| 923 | ((Base && Base->isTypeDependent()) || |
| 924 | BaseType->isDependentType()), |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 925 | ((Base && Base->isInstantiationDependent()) || |
| 926 | BaseType->isInstantiationDependentType()), |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 927 | // Contains unexpanded parameter pack |
| 928 | ((Base && Base->containsUnexpandedParameterPack()) || |
| 929 | BaseType->containsUnexpandedParameterPack())), |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 930 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 931 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 932 | |
| 933 | // Check whether all of the members are non-static member functions, |
| 934 | // and if so, mark give this bound-member type instead of overload type. |
| 935 | if (hasOnlyNonStaticMemberFunctions(Begin, End)) |
| 936 | setType(C.BoundMemberTy); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 939 | bool UnresolvedMemberExpr::isImplicitAccess() const { |
| 940 | if (Base == 0) |
| 941 | return true; |
| 942 | |
Douglas Gregor | 75e8504 | 2011-03-02 21:06:53 +0000 | [diff] [blame] | 943 | return cast<Expr>(Base)->isImplicitCXXThis(); |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 944 | } |
| 945 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 946 | UnresolvedMemberExpr * |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 947 | UnresolvedMemberExpr::Create(ASTContext &C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 948 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 949 | Expr *Base, QualType BaseType, bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 950 | SourceLocation OperatorLoc, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 951 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 952 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 953 | const TemplateArgumentListInfo *TemplateArgs, |
| 954 | UnresolvedSetIterator Begin, |
| 955 | UnresolvedSetIterator End) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 956 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 957 | if (TemplateArgs) |
Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 958 | size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 959 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 960 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 961 | return new (Mem) UnresolvedMemberExpr(C, |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 962 | HasUnresolvedUsing, Base, BaseType, |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 963 | IsArrow, OperatorLoc, QualifierLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 964 | MemberNameInfo, TemplateArgs, Begin, End); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 967 | UnresolvedMemberExpr * |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 968 | UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs, |
| 969 | unsigned NumTemplateArgs) { |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 970 | std::size_t size = sizeof(UnresolvedMemberExpr); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 971 | if (HasExplicitTemplateArgs) |
Argyrios Kyrtzidis | b0c3e09 | 2011-09-22 20:07:03 +0000 | [diff] [blame] | 972 | size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 973 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 974 | void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 975 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
Douglas Gregor | def0354 | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 976 | E->HasExplicitTemplateArgs = HasExplicitTemplateArgs; |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 977 | return E; |
| 978 | } |
| 979 | |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 980 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 981 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 982 | |
| 983 | // If there was a nested name specifier, it names the naming class. |
| 984 | // It can't be dependent: after all, we were actually able to do the |
| 985 | // lookup. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 986 | CXXRecordDecl *Record = 0; |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 987 | if (getQualifier()) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 988 | const Type *T = getQualifier()->getAsType(); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 989 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 990 | Record = T->getAsCXXRecordDecl(); |
| 991 | assert(Record && "qualifier in member expression does not name record"); |
| 992 | } |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 993 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 994 | else { |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 995 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 996 | if (isArrow()) { |
| 997 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 998 | assert(PT && "base of arrow member access is not pointer"); |
| 999 | BaseType = PT->getPointeeType(); |
| 1000 | } |
| 1001 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1002 | Record = BaseType->getAsCXXRecordDecl(); |
| 1003 | assert(Record && "base of member expression does not name record"); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1006 | return Record; |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1009 | SubstNonTypeTemplateParmPackExpr:: |
| 1010 | SubstNonTypeTemplateParmPackExpr(QualType T, |
| 1011 | NonTypeTemplateParmDecl *Param, |
| 1012 | SourceLocation NameLoc, |
| 1013 | const TemplateArgument &ArgPack) |
| 1014 | : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 1015 | true, true, true, true), |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1016 | Param(Param), Arguments(ArgPack.pack_begin()), |
| 1017 | NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } |
| 1018 | |
| 1019 | TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { |
| 1020 | return TemplateArgument(Arguments, NumArguments); |
| 1021 | } |
| 1022 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 1023 | |