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