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