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