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 | |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 42 | // CXXBoolLiteralExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | Stmt::child_iterator CXXBoolLiteralExpr::child_begin() { |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 44 | return child_iterator(); |
| 45 | } |
| 46 | Stmt::child_iterator CXXBoolLiteralExpr::child_end() { |
| 47 | return child_iterator(); |
| 48 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 49 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 50 | // CXXNullPtrLiteralExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 51 | Stmt::child_iterator CXXNullPtrLiteralExpr::child_begin() { |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 52 | return child_iterator(); |
| 53 | } |
| 54 | Stmt::child_iterator CXXNullPtrLiteralExpr::child_end() { |
| 55 | return child_iterator(); |
| 56 | } |
| 57 | |
Douglas Gregor | 796da18 | 2008-11-04 14:32:21 +0000 | [diff] [blame] | 58 | // CXXThisExpr |
| 59 | Stmt::child_iterator CXXThisExpr::child_begin() { return child_iterator(); } |
| 60 | Stmt::child_iterator CXXThisExpr::child_end() { return child_iterator(); } |
| 61 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 62 | // CXXThrowExpr |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 63 | Stmt::child_iterator CXXThrowExpr::child_begin() { return &Op; } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 64 | Stmt::child_iterator CXXThrowExpr::child_end() { |
| 65 | // If Op is 0, we are processing throw; which has no children. |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 66 | return Op ? &Op+1 : &Op; |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 67 | } |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 68 | |
| 69 | // CXXDefaultArgExpr |
| 70 | Stmt::child_iterator CXXDefaultArgExpr::child_begin() { |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 71 | return child_iterator(); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 72 | } |
| 73 | Stmt::child_iterator CXXDefaultArgExpr::child_end() { |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 74 | return child_iterator(); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 75 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 76 | |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 77 | // CXXScalarValueInitExpr |
| 78 | Stmt::child_iterator CXXScalarValueInitExpr::child_begin() { |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 79 | return child_iterator(); |
| 80 | } |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 81 | Stmt::child_iterator CXXScalarValueInitExpr::child_end() { |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 82 | return child_iterator(); |
| 83 | } |
Argyrios Kyrtzidis | 9e922b1 | 2008-09-09 23:47:53 +0000 | [diff] [blame] | 84 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 85 | // CXXNewExpr |
Ted Kremenek | ad7fe86 | 2010-02-11 22:51:03 +0000 | [diff] [blame] | 86 | CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 87 | Expr **placementArgs, unsigned numPlaceArgs, |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 88 | bool parenTypeId, Expr *arraySize, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 89 | CXXConstructorDecl *constructor, bool initializer, |
| 90 | Expr **constructorArgs, unsigned numConsArgs, |
| 91 | FunctionDecl *operatorDelete, QualType ty, |
| 92 | SourceLocation startLoc, SourceLocation endLoc) |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 93 | : Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()), |
| 94 | GlobalNew(globalNew), ParenTypeId(parenTypeId), |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 95 | Initializer(initializer), SubExprs(0), OperatorNew(operatorNew), |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 96 | OperatorDelete(operatorDelete), Constructor(constructor), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | StartLoc(startLoc), EndLoc(endLoc) { |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 98 | |
| 99 | AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 100 | unsigned i = 0; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 101 | if (Array) |
| 102 | SubExprs[i++] = arraySize; |
| 103 | for (unsigned j = 0; j < NumPlacementArgs; ++j) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 104 | SubExprs[i++] = placementArgs[j]; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 105 | for (unsigned j = 0; j < NumConstructorArgs; ++j) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 106 | SubExprs[i++] = constructorArgs[j]; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 109 | void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray, |
| 110 | unsigned numPlaceArgs, unsigned numConsArgs){ |
| 111 | assert(SubExprs == 0 && "SubExprs already allocated"); |
| 112 | Array = isArray; |
| 113 | NumPlacementArgs = numPlaceArgs; |
| 114 | NumConstructorArgs = numConsArgs; |
| 115 | |
| 116 | unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs; |
| 117 | SubExprs = new (C) Stmt*[TotalSize]; |
| 118 | } |
| 119 | |
| 120 | |
Ted Kremenek | ad7fe86 | 2010-02-11 22:51:03 +0000 | [diff] [blame] | 121 | void CXXNewExpr::DoDestroy(ASTContext &C) { |
| 122 | DestroyChildren(C); |
| 123 | if (SubExprs) |
| 124 | C.Deallocate(SubExprs); |
| 125 | this->~CXXNewExpr(); |
| 126 | C.Deallocate((void*)this); |
| 127 | } |
| 128 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 129 | Stmt::child_iterator CXXNewExpr::child_begin() { return &SubExprs[0]; } |
| 130 | Stmt::child_iterator CXXNewExpr::child_end() { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 131 | return &SubExprs[0] + Array + getNumPlacementArgs() + getNumConstructorArgs(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | // CXXDeleteExpr |
| 135 | Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; } |
| 136 | Stmt::child_iterator CXXDeleteExpr::child_end() { return &Argument+1; } |
| 137 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 138 | // CXXPseudoDestructorExpr |
| 139 | Stmt::child_iterator CXXPseudoDestructorExpr::child_begin() { return &Base; } |
| 140 | Stmt::child_iterator CXXPseudoDestructorExpr::child_end() { |
| 141 | return &Base + 1; |
| 142 | } |
| 143 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 144 | PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) |
| 145 | : Type(Info) |
| 146 | { |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 147 | Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | QualType CXXPseudoDestructorExpr::getDestroyedType() const { |
| 151 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
| 152 | return TInfo->getType(); |
| 153 | |
| 154 | return QualType(); |
| 155 | } |
| 156 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 157 | SourceRange CXXPseudoDestructorExpr::getSourceRange() const { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 158 | SourceLocation End = DestroyedType.getLocation(); |
| 159 | if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 160 | End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 161 | return SourceRange(Base->getLocStart(), End); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 165 | // UnresolvedLookupExpr |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 166 | UnresolvedLookupExpr * |
| 167 | UnresolvedLookupExpr::Create(ASTContext &C, bool Dependent, |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 168 | CXXRecordDecl *NamingClass, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 169 | NestedNameSpecifier *Qualifier, |
| 170 | SourceRange QualifierRange, DeclarationName Name, |
| 171 | SourceLocation NameLoc, bool ADL, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 172 | const TemplateArgumentListInfo &Args, |
| 173 | UnresolvedSetIterator Begin, |
| 174 | UnresolvedSetIterator End) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 175 | { |
| 176 | void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) + |
| 177 | ExplicitTemplateArgumentList::sizeFor(Args)); |
| 178 | UnresolvedLookupExpr *ULE |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 179 | = new (Mem) UnresolvedLookupExpr(C, |
| 180 | Dependent ? C.DependentTy : C.OverloadTy, |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 181 | Dependent, NamingClass, |
| 182 | Qualifier, QualifierRange, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 183 | Name, NameLoc, ADL, |
| 184 | /*Overload*/ true, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 185 | /*ExplicitTemplateArgs*/ true, |
| 186 | Begin, End); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 187 | |
| 188 | reinterpret_cast<ExplicitTemplateArgumentList*>(ULE+1)->initializeFrom(Args); |
| 189 | |
| 190 | return ULE; |
| 191 | } |
| 192 | |
Argyrios Kyrtzidis | bd65bb5 | 2010-06-25 09:03:34 +0000 | [diff] [blame] | 193 | UnresolvedLookupExpr * |
| 194 | UnresolvedLookupExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) { |
| 195 | std::size_t size = sizeof(UnresolvedLookupExpr); |
| 196 | if (NumTemplateArgs != 0) |
| 197 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 198 | |
| 199 | void *Mem = C.Allocate(size, llvm::alignof<UnresolvedLookupExpr>()); |
| 200 | UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); |
| 201 | E->HasExplicitTemplateArgs = NumTemplateArgs != 0; |
| 202 | return E; |
| 203 | } |
| 204 | |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 205 | OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C, QualType T, |
| 206 | bool Dependent, NestedNameSpecifier *Qualifier, |
| 207 | SourceRange QRange, DeclarationName Name, |
| 208 | SourceLocation NameLoc, bool HasTemplateArgs, |
| 209 | UnresolvedSetIterator Begin, |
| 210 | UnresolvedSetIterator End) |
| 211 | : Expr(K, T, Dependent, Dependent), |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 212 | Results(0), NumResults(0), Name(Name), Qualifier(Qualifier), |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 213 | QualifierRange(QRange), NameLoc(NameLoc), |
| 214 | HasExplicitTemplateArgs(HasTemplateArgs) |
| 215 | { |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 216 | initializeResults(C, Begin, End); |
| 217 | } |
| 218 | |
| 219 | void OverloadExpr::initializeResults(ASTContext &C, |
| 220 | UnresolvedSetIterator Begin, |
| 221 | UnresolvedSetIterator End) { |
| 222 | assert(Results == 0 && "Results already initialized!"); |
| 223 | NumResults = End - Begin; |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 224 | if (NumResults) { |
| 225 | Results = static_cast<DeclAccessPair *>( |
| 226 | C.Allocate(sizeof(DeclAccessPair) * NumResults, |
| 227 | llvm::alignof<DeclAccessPair>())); |
| 228 | memcpy(Results, &*Begin.getIterator(), |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 229 | NumResults * sizeof(DeclAccessPair)); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 233 | |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 234 | bool OverloadExpr::ComputeDependence(UnresolvedSetIterator Begin, |
| 235 | UnresolvedSetIterator End, |
| 236 | const TemplateArgumentListInfo *Args) { |
John McCall | eec51cf | 2010-01-20 00:46:10 +0000 | [diff] [blame] | 237 | for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 238 | if ((*I)->getDeclContext()->isDependentContext()) |
| 239 | return true; |
| 240 | |
| 241 | if (Args && TemplateSpecializationType::anyDependentTemplateArguments(*Args)) |
| 242 | return true; |
| 243 | |
| 244 | return false; |
| 245 | } |
| 246 | |
John McCall | e9ee23e | 2010-04-22 18:44:12 +0000 | [diff] [blame] | 247 | CXXRecordDecl *OverloadExpr::getNamingClass() const { |
| 248 | if (isa<UnresolvedLookupExpr>(this)) |
| 249 | return cast<UnresolvedLookupExpr>(this)->getNamingClass(); |
| 250 | else |
| 251 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
| 252 | } |
| 253 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 254 | Stmt::child_iterator UnresolvedLookupExpr::child_begin() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 255 | return child_iterator(); |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 256 | } |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 257 | Stmt::child_iterator UnresolvedLookupExpr::child_end() { |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 258 | return child_iterator(); |
| 259 | } |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 260 | // UnaryTypeTraitExpr |
| 261 | Stmt::child_iterator UnaryTypeTraitExpr::child_begin() { |
| 262 | return child_iterator(); |
| 263 | } |
| 264 | Stmt::child_iterator UnaryTypeTraitExpr::child_end() { |
| 265 | return child_iterator(); |
| 266 | } |
| 267 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 268 | // DependentScopeDeclRefExpr |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 269 | DependentScopeDeclRefExpr * |
| 270 | DependentScopeDeclRefExpr::Create(ASTContext &C, |
| 271 | NestedNameSpecifier *Qualifier, |
| 272 | SourceRange QualifierRange, |
| 273 | DeclarationName Name, |
| 274 | SourceLocation NameLoc, |
| 275 | const TemplateArgumentListInfo *Args) { |
| 276 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
| 277 | if (Args) size += ExplicitTemplateArgumentList::sizeFor(*Args); |
| 278 | void *Mem = C.Allocate(size); |
| 279 | |
| 280 | DependentScopeDeclRefExpr *DRE |
| 281 | = new (Mem) DependentScopeDeclRefExpr(C.DependentTy, |
| 282 | Qualifier, QualifierRange, |
| 283 | Name, NameLoc, |
| 284 | Args != 0); |
| 285 | |
| 286 | if (Args) |
| 287 | reinterpret_cast<ExplicitTemplateArgumentList*>(DRE+1) |
| 288 | ->initializeFrom(*Args); |
| 289 | |
| 290 | return DRE; |
| 291 | } |
| 292 | |
Argyrios Kyrtzidis | 12dffcd | 2010-06-28 09:31:56 +0000 | [diff] [blame] | 293 | DependentScopeDeclRefExpr * |
| 294 | DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C, |
| 295 | unsigned NumTemplateArgs) { |
| 296 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
| 297 | if (NumTemplateArgs) |
| 298 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 299 | void *Mem = C.Allocate(size); |
| 300 | |
| 301 | return new (Mem) DependentScopeDeclRefExpr(QualType(), 0, SourceRange(), |
| 302 | DeclarationName(),SourceLocation(), |
| 303 | NumTemplateArgs != 0); |
| 304 | } |
| 305 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 306 | StmtIterator DependentScopeDeclRefExpr::child_begin() { |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 307 | return child_iterator(); |
| 308 | } |
| 309 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 310 | StmtIterator DependentScopeDeclRefExpr::child_end() { |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 311 | return child_iterator(); |
| 312 | } |
| 313 | |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 314 | bool UnaryTypeTraitExpr::EvaluateTrait(ASTContext& C) const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 315 | switch(UTT) { |
| 316 | default: assert(false && "Unknown type trait or not implemented"); |
| 317 | case UTT_IsPOD: return QueriedType->isPODType(); |
Sebastian Redl | ccf4350 | 2009-12-03 00:13:20 +0000 | [diff] [blame] | 318 | case UTT_IsLiteral: return QueriedType->isLiteralType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 319 | case UTT_IsClass: // Fallthrough |
| 320 | case UTT_IsUnion: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 321 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 322 | bool Union = Record->getDecl()->isUnion(); |
| 323 | return UTT == UTT_IsUnion ? Union : !Union; |
| 324 | } |
| 325 | return false; |
| 326 | case UTT_IsEnum: return QueriedType->isEnumeralType(); |
| 327 | case UTT_IsPolymorphic: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 328 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 329 | // Type traits are only parsed in C++, so we've got CXXRecords. |
| 330 | return cast<CXXRecordDecl>(Record->getDecl())->isPolymorphic(); |
| 331 | } |
| 332 | return false; |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 333 | case UTT_IsAbstract: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 334 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 335 | return cast<CXXRecordDecl>(RT->getDecl())->isAbstract(); |
| 336 | return false; |
Eli Friedman | 1d954f6 | 2009-08-15 21:55:26 +0000 | [diff] [blame] | 337 | case UTT_IsEmpty: |
| 338 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
| 339 | return !Record->getDecl()->isUnion() |
| 340 | && cast<CXXRecordDecl>(Record->getDecl())->isEmpty(); |
| 341 | } |
| 342 | return false; |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 343 | case UTT_HasTrivialConstructor: |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 344 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 345 | // If __is_pod (type) is true then the trait is true, else if type is |
| 346 | // a cv class or union type (or array thereof) with a trivial default |
| 347 | // constructor ([class.ctor]) then the trait is true, else it is false. |
| 348 | if (QueriedType->isPODType()) |
| 349 | return true; |
| 350 | if (const RecordType *RT = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 351 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 352 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialConstructor(); |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 353 | return false; |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 354 | case UTT_HasTrivialCopy: |
| 355 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 356 | // If __is_pod (type) is true or type is a reference type then |
| 357 | // the trait is true, else if type is a cv class or union type |
| 358 | // with a trivial copy constructor ([class.copy]) then the trait |
| 359 | // is true, else it is false. |
| 360 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 361 | return true; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 362 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 363 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialCopyConstructor(); |
| 364 | return false; |
| 365 | case UTT_HasTrivialAssign: |
| 366 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 367 | // If type is const qualified or is a reference type then the |
| 368 | // trait is false. Otherwise if __is_pod (type) is true then the |
| 369 | // trait is true, else if type is a cv class or union type with |
| 370 | // a trivial copy assignment ([class.copy]) then the trait is |
| 371 | // true, else it is false. |
| 372 | // Note: the const and reference restrictions are interesting, |
| 373 | // given that const and reference members don't prevent a class |
| 374 | // from having a trivial copy assignment operator (but do cause |
| 375 | // errors if the copy assignment operator is actually used, q.v. |
| 376 | // [class.copy]p12). |
| 377 | |
| 378 | if (C.getBaseElementType(QueriedType).isConstQualified()) |
| 379 | return false; |
| 380 | if (QueriedType->isPODType()) |
| 381 | return true; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 382 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 383 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialCopyAssignment(); |
| 384 | return false; |
| 385 | case UTT_HasTrivialDestructor: |
| 386 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 387 | // If __is_pod (type) is true or type is a reference type |
| 388 | // then the trait is true, else if type is a cv class or union |
| 389 | // type (or array thereof) with a trivial destructor |
| 390 | // ([class.dtor]) then the trait is true, else it is |
| 391 | // false. |
| 392 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 393 | return true; |
| 394 | if (const RecordType *RT = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 395 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 396 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialDestructor(); |
| 397 | return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Ted Kremenek | e383768 | 2009-12-23 04:00:48 +0000 | [diff] [blame] | 401 | SourceRange CXXConstructExpr::getSourceRange() const { |
| 402 | // FIXME: Should we know where the parentheses are, if there are any? |
| 403 | for (std::reverse_iterator<Stmt**> I(&Args[NumArgs]), E(&Args[0]); I!=E;++I) { |
| 404 | // Ignore CXXDefaultExprs when computing the range, as they don't |
| 405 | // have a range. |
| 406 | if (!isa<CXXDefaultArgExpr>(*I)) |
| 407 | return SourceRange(Loc, (*I)->getLocEnd()); |
| 408 | } |
| 409 | |
| 410 | return SourceRange(Loc); |
| 411 | } |
| 412 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 413 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 414 | OverloadedOperatorKind Kind = getOperator(); |
| 415 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 416 | if (getNumArgs() == 1) |
| 417 | // Prefix operator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 418 | return SourceRange(getOperatorLoc(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 419 | getArg(0)->getSourceRange().getEnd()); |
| 420 | else |
| 421 | // Postfix operator |
| 422 | return SourceRange(getArg(0)->getSourceRange().getEnd(), |
| 423 | getOperatorLoc()); |
| 424 | } else if (Kind == OO_Call) { |
| 425 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 426 | } else if (Kind == OO_Subscript) { |
| 427 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 428 | } else if (getNumArgs() == 1) { |
| 429 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 430 | } else if (getNumArgs() == 2) { |
| 431 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 432 | getArg(1)->getSourceRange().getEnd()); |
| 433 | } else { |
| 434 | return SourceRange(); |
| 435 | } |
| 436 | } |
| 437 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 438 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() { |
| 439 | if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 440 | return MemExpr->getBase(); |
| 441 | |
| 442 | // FIXME: Will eventually need to cope with member pointers. |
| 443 | return 0; |
| 444 | } |
| 445 | |
Douglas Gregor | 00b98c2 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 446 | SourceRange CXXMemberCallExpr::getSourceRange() const { |
| 447 | SourceLocation LocStart = getCallee()->getLocStart(); |
| 448 | if (LocStart.isInvalid() && getNumArgs() > 0) |
| 449 | LocStart = getArg(0)->getLocStart(); |
| 450 | return SourceRange(LocStart, getRParenLoc()); |
| 451 | } |
| 452 | |
| 453 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 454 | //===----------------------------------------------------------------------===// |
| 455 | // Named casts |
| 456 | //===----------------------------------------------------------------------===// |
| 457 | |
| 458 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 459 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 460 | /// "const_cast". The returned pointer must not be freed. |
| 461 | const char *CXXNamedCastExpr::getCastName() const { |
| 462 | switch (getStmtClass()) { |
| 463 | case CXXStaticCastExprClass: return "static_cast"; |
| 464 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 465 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 466 | case CXXConstCastExprClass: return "const_cast"; |
| 467 | default: return "<invalid cast>"; |
| 468 | } |
| 469 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 470 | |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 471 | CXXDefaultArgExpr * |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 472 | CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc, |
| 473 | ParmVarDecl *Param, Expr *SubExpr) { |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 474 | void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 475 | return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, |
| 476 | SubExpr); |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void CXXDefaultArgExpr::DoDestroy(ASTContext &C) { |
| 480 | if (Param.getInt()) |
| 481 | getExpr()->Destroy(C); |
| 482 | this->~CXXDefaultArgExpr(); |
| 483 | C.Deallocate(this); |
| 484 | } |
| 485 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 487 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 488 | return new (C) CXXTemporary(Destructor); |
| 489 | } |
| 490 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 491 | void CXXTemporary::Destroy(ASTContext &Ctx) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 492 | this->~CXXTemporary(); |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 493 | Ctx.Deallocate(this); |
Anders Carlsson | c1ce477 | 2009-05-30 19:54:15 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 497 | CXXTemporary *Temp, |
| 498 | Expr* SubExpr) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | assert(SubExpr->getType()->isRecordType() && |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 500 | "Expression bound to a temporary must have record type!"); |
| 501 | |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 502 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 505 | void CXXBindTemporaryExpr::DoDestroy(ASTContext &C) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 506 | Temp->Destroy(C); |
| 507 | this->~CXXBindTemporaryExpr(); |
| 508 | C.Deallocate(this); |
| 509 | } |
| 510 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 511 | CXXBindReferenceExpr *CXXBindReferenceExpr::Create(ASTContext &C, Expr *SubExpr, |
| 512 | bool ExtendsLifetime, |
| 513 | bool RequiresTemporaryCopy) { |
| 514 | return new (C) CXXBindReferenceExpr(SubExpr, |
| 515 | ExtendsLifetime, |
| 516 | RequiresTemporaryCopy); |
| 517 | } |
| 518 | |
| 519 | void CXXBindReferenceExpr::DoDestroy(ASTContext &C) { |
| 520 | this->~CXXBindReferenceExpr(); |
| 521 | C.Deallocate(this); |
| 522 | } |
| 523 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 524 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 525 | CXXConstructorDecl *Cons, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 526 | QualType writtenTy, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 527 | SourceLocation tyBeginLoc, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 528 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | unsigned NumArgs, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 530 | SourceLocation rParenLoc, |
| 531 | bool ZeroInitialization) |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 532 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, tyBeginLoc, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 533 | Cons, false, Args, NumArgs, ZeroInitialization), |
Anders Carlsson | 524fa13 | 2009-04-24 17:34:38 +0000 | [diff] [blame] | 534 | TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) { |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 535 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 536 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 538 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 539 | CXXConstructorDecl *D, bool Elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 540 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 541 | bool ZeroInitialization, |
Anders Carlsson | fcaeef2 | 2010-05-02 23:53:04 +0000 | [diff] [blame] | 542 | ConstructionKind ConstructKind) { |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 543 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 544 | Elidable, Args, NumArgs, ZeroInitialization, |
Anders Carlsson | fcaeef2 | 2010-05-02 23:53:04 +0000 | [diff] [blame] | 545 | ConstructKind); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 548 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 549 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 550 | CXXConstructorDecl *D, bool elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 551 | Expr **args, unsigned numargs, |
Anders Carlsson | 72e96fd | 2010-05-02 22:54:08 +0000 | [diff] [blame] | 552 | bool ZeroInitialization, |
| 553 | ConstructionKind ConstructKind) |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 554 | : Expr(SC, T, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 555 | T->isDependentType(), |
| 556 | (T->isDependentType() || |
| 557 | CallExpr::hasAnyValueDependentArguments(args, numargs))), |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 558 | Constructor(D), Loc(Loc), Elidable(elidable), |
Anders Carlsson | 72e96fd | 2010-05-02 22:54:08 +0000 | [diff] [blame] | 559 | ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind), |
| 560 | Args(0), NumArgs(numargs) |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 561 | { |
| 562 | if (NumArgs) { |
| 563 | Args = new (C) Stmt*[NumArgs]; |
| 564 | |
| 565 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 566 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
| 567 | Args[i] = args[i]; |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 568 | } |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 569 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 572 | void CXXConstructExpr::DoDestroy(ASTContext &C) { |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 573 | DestroyChildren(C); |
| 574 | if (Args) |
| 575 | C.Deallocate(Args); |
| 576 | this->~CXXConstructExpr(); |
| 577 | C.Deallocate(this); |
| 578 | } |
| 579 | |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 580 | CXXExprWithTemporaries::CXXExprWithTemporaries(ASTContext &C, |
| 581 | Expr *subexpr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | CXXTemporary **temps, |
Anders Carlsson | 0ece491 | 2009-12-15 20:51:39 +0000 | [diff] [blame] | 583 | unsigned numtemps) |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 584 | : Expr(CXXExprWithTemporariesClass, subexpr->getType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | subexpr->isTypeDependent(), subexpr->isValueDependent()), |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 586 | SubExpr(subexpr), Temps(0), NumTemps(0) { |
Chris Lattner | aff32cb | 2010-05-10 00:45:12 +0000 | [diff] [blame] | 587 | if (numtemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 588 | setNumTemporaries(C, numtemps); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 589 | for (unsigned i = 0; i != numtemps; ++i) |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 590 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 594 | void CXXExprWithTemporaries::setNumTemporaries(ASTContext &C, unsigned N) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 595 | assert(Temps == 0 && "Cannot resize with this"); |
Daniel Dunbar | 90556d4 | 2010-05-10 15:59:37 +0000 | [diff] [blame] | 596 | NumTemps = N; |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 597 | Temps = new (C) CXXTemporary*[NumTemps]; |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 602 | Expr *SubExpr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | CXXTemporary **Temps, |
Anders Carlsson | 0ece491 | 2009-12-15 20:51:39 +0000 | [diff] [blame] | 604 | unsigned NumTemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 605 | return new (C) CXXExprWithTemporaries(C, SubExpr, Temps, NumTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 608 | void CXXExprWithTemporaries::DoDestroy(ASTContext &C) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 609 | DestroyChildren(C); |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 610 | if (Temps) |
| 611 | C.Deallocate(Temps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 612 | this->~CXXExprWithTemporaries(); |
| 613 | C.Deallocate(this); |
| 614 | } |
| 615 | |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 616 | CXXExprWithTemporaries::~CXXExprWithTemporaries() {} |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 617 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 618 | // CXXBindTemporaryExpr |
| 619 | Stmt::child_iterator CXXBindTemporaryExpr::child_begin() { |
| 620 | return &SubExpr; |
| 621 | } |
| 622 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | Stmt::child_iterator CXXBindTemporaryExpr::child_end() { |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 624 | return &SubExpr + 1; |
| 625 | } |
| 626 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 627 | // CXXBindReferenceExpr |
| 628 | Stmt::child_iterator CXXBindReferenceExpr::child_begin() { |
| 629 | return &SubExpr; |
| 630 | } |
| 631 | |
| 632 | Stmt::child_iterator CXXBindReferenceExpr::child_end() { |
| 633 | return &SubExpr + 1; |
| 634 | } |
| 635 | |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 636 | // CXXConstructExpr |
| 637 | Stmt::child_iterator CXXConstructExpr::child_begin() { |
| 638 | return &Args[0]; |
| 639 | } |
| 640 | Stmt::child_iterator CXXConstructExpr::child_end() { |
| 641 | return &Args[0]+NumArgs; |
| 642 | } |
| 643 | |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 644 | // CXXExprWithTemporaries |
| 645 | Stmt::child_iterator CXXExprWithTemporaries::child_begin() { |
| 646 | return &SubExpr; |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 647 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 648 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | Stmt::child_iterator CXXExprWithTemporaries::child_end() { |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 650 | return &SubExpr + 1; |
| 651 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 652 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 653 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr( |
| 654 | SourceLocation TyBeginLoc, |
| 655 | QualType T, |
| 656 | SourceLocation LParenLoc, |
| 657 | Expr **Args, |
| 658 | unsigned NumArgs, |
| 659 | SourceLocation RParenLoc) |
| 660 | : Expr(CXXUnresolvedConstructExprClass, T.getNonReferenceType(), |
| 661 | T->isDependentType(), true), |
| 662 | TyBeginLoc(TyBeginLoc), |
| 663 | Type(T), |
| 664 | LParenLoc(LParenLoc), |
| 665 | RParenLoc(RParenLoc), |
| 666 | NumArgs(NumArgs) { |
| 667 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
| 668 | memcpy(StoredArgs, Args, sizeof(Expr *) * NumArgs); |
| 669 | } |
| 670 | |
| 671 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 673 | SourceLocation TyBegin, |
| 674 | QualType T, |
| 675 | SourceLocation LParenLoc, |
| 676 | Expr **Args, |
| 677 | unsigned NumArgs, |
| 678 | SourceLocation RParenLoc) { |
| 679 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 680 | sizeof(Expr *) * NumArgs); |
| 681 | return new (Mem) CXXUnresolvedConstructExpr(TyBegin, T, LParenLoc, |
| 682 | Args, NumArgs, RParenLoc); |
| 683 | } |
| 684 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 685 | CXXUnresolvedConstructExpr * |
| 686 | CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) { |
| 687 | Stmt::EmptyShell Empty; |
| 688 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 689 | sizeof(Expr *) * NumArgs); |
| 690 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 691 | } |
| 692 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 693 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_begin() { |
| 694 | return child_iterator(reinterpret_cast<Stmt **>(this + 1)); |
| 695 | } |
| 696 | |
| 697 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_end() { |
| 698 | return child_iterator(reinterpret_cast<Stmt **>(this + 1) + NumArgs); |
| 699 | } |
Sebastian Redl | 8b0b475 | 2009-05-16 18:50:46 +0000 | [diff] [blame] | 700 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 701 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 702 | Expr *Base, QualType BaseType, |
| 703 | bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 704 | SourceLocation OperatorLoc, |
| 705 | NestedNameSpecifier *Qualifier, |
| 706 | SourceRange QualifierRange, |
| 707 | NamedDecl *FirstQualifierFoundInScope, |
| 708 | DeclarationName Member, |
| 709 | SourceLocation MemberLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 710 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 711 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 712 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 713 | HasExplicitTemplateArgs(TemplateArgs != 0), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 714 | OperatorLoc(OperatorLoc), |
| 715 | Qualifier(Qualifier), QualifierRange(QualifierRange), |
| 716 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | Member(Member), MemberLoc(MemberLoc) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 718 | if (TemplateArgs) |
| 719 | getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 720 | } |
| 721 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 722 | CXXDependentScopeMemberExpr * |
| 723 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 724 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 725 | SourceLocation OperatorLoc, |
| 726 | NestedNameSpecifier *Qualifier, |
| 727 | SourceRange QualifierRange, |
| 728 | NamedDecl *FirstQualifierFoundInScope, |
| 729 | DeclarationName Member, |
| 730 | SourceLocation MemberLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 731 | const TemplateArgumentListInfo *TemplateArgs) { |
| 732 | if (!TemplateArgs) |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 733 | return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 734 | IsArrow, OperatorLoc, |
| 735 | Qualifier, QualifierRange, |
| 736 | FirstQualifierFoundInScope, |
| 737 | Member, MemberLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 739 | std::size_t size = sizeof(CXXDependentScopeMemberExpr); |
| 740 | if (TemplateArgs) |
| 741 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 742 | |
| 743 | void *Mem = C.Allocate(size, llvm::alignof<CXXDependentScopeMemberExpr>()); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 744 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 745 | IsArrow, OperatorLoc, |
| 746 | Qualifier, QualifierRange, |
| 747 | FirstQualifierFoundInScope, |
| 748 | Member, MemberLoc, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 751 | CXXDependentScopeMemberExpr * |
| 752 | CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C, |
| 753 | unsigned NumTemplateArgs) { |
| 754 | if (NumTemplateArgs == 0) |
| 755 | return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), |
| 756 | 0, SourceLocation(), 0, |
| 757 | SourceRange(), 0, |
| 758 | DeclarationName(), |
| 759 | SourceLocation()); |
| 760 | |
| 761 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) + |
| 762 | ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 763 | void *Mem = C.Allocate(size, llvm::alignof<CXXDependentScopeMemberExpr>()); |
| 764 | CXXDependentScopeMemberExpr *E |
| 765 | = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), |
| 766 | 0, SourceLocation(), 0, |
| 767 | SourceRange(), 0, |
| 768 | DeclarationName(), |
| 769 | SourceLocation(), 0); |
| 770 | E->HasExplicitTemplateArgs = true; |
| 771 | return E; |
| 772 | } |
| 773 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 774 | Stmt::child_iterator CXXDependentScopeMemberExpr::child_begin() { |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 775 | return child_iterator(&Base); |
| 776 | } |
| 777 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 778 | Stmt::child_iterator CXXDependentScopeMemberExpr::child_end() { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 779 | if (isImplicitAccess()) |
| 780 | return child_iterator(&Base); |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 781 | return child_iterator(&Base + 1); |
| 782 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 783 | |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 784 | UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, QualType T, |
| 785 | bool Dependent, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 786 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 787 | Expr *Base, QualType BaseType, |
| 788 | bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 789 | SourceLocation OperatorLoc, |
| 790 | NestedNameSpecifier *Qualifier, |
| 791 | SourceRange QualifierRange, |
| 792 | DeclarationName MemberName, |
| 793 | SourceLocation MemberLoc, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 794 | const TemplateArgumentListInfo *TemplateArgs, |
| 795 | UnresolvedSetIterator Begin, |
| 796 | UnresolvedSetIterator End) |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 797 | : OverloadExpr(UnresolvedMemberExprClass, C, T, Dependent, |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 798 | Qualifier, QualifierRange, MemberName, MemberLoc, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 799 | TemplateArgs != 0, Begin, End), |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 800 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 801 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 802 | if (TemplateArgs) |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 803 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | UnresolvedMemberExpr * |
| 807 | UnresolvedMemberExpr::Create(ASTContext &C, bool Dependent, |
| 808 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 809 | Expr *Base, QualType BaseType, bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 810 | SourceLocation OperatorLoc, |
| 811 | NestedNameSpecifier *Qualifier, |
| 812 | SourceRange QualifierRange, |
| 813 | DeclarationName Member, |
| 814 | SourceLocation MemberLoc, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 815 | const TemplateArgumentListInfo *TemplateArgs, |
| 816 | UnresolvedSetIterator Begin, |
| 817 | UnresolvedSetIterator End) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 818 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 819 | if (TemplateArgs) |
| 820 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 821 | |
| 822 | void *Mem = C.Allocate(size, llvm::alignof<UnresolvedMemberExpr>()); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 823 | return new (Mem) UnresolvedMemberExpr(C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 824 | Dependent ? C.DependentTy : C.OverloadTy, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 825 | Dependent, HasUnresolvedUsing, Base, BaseType, |
| 826 | IsArrow, OperatorLoc, Qualifier, QualifierRange, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 827 | Member, MemberLoc, TemplateArgs, Begin, End); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 830 | UnresolvedMemberExpr * |
| 831 | UnresolvedMemberExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) { |
| 832 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 833 | if (NumTemplateArgs != 0) |
| 834 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 835 | |
| 836 | void *Mem = C.Allocate(size, llvm::alignof<UnresolvedMemberExpr>()); |
| 837 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
| 838 | E->HasExplicitTemplateArgs = NumTemplateArgs != 0; |
| 839 | return E; |
| 840 | } |
| 841 | |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 842 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 843 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 844 | |
| 845 | // If there was a nested name specifier, it names the naming class. |
| 846 | // It can't be dependent: after all, we were actually able to do the |
| 847 | // lookup. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 848 | CXXRecordDecl *Record = 0; |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 849 | if (getQualifier()) { |
| 850 | Type *T = getQualifier()->getAsType(); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 851 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 852 | Record = T->getAsCXXRecordDecl(); |
| 853 | assert(Record && "qualifier in member expression does not name record"); |
| 854 | } |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 855 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 856 | else { |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 857 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 858 | if (isArrow()) { |
| 859 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 860 | assert(PT && "base of arrow member access is not pointer"); |
| 861 | BaseType = PT->getPointeeType(); |
| 862 | } |
| 863 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 864 | Record = BaseType->getAsCXXRecordDecl(); |
| 865 | assert(Record && "base of member expression does not name record"); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 868 | return Record; |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 869 | } |
| 870 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 871 | Stmt::child_iterator UnresolvedMemberExpr::child_begin() { |
| 872 | return child_iterator(&Base); |
| 873 | } |
| 874 | |
| 875 | Stmt::child_iterator UnresolvedMemberExpr::child_end() { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 876 | if (isImplicitAccess()) |
| 877 | return child_iterator(&Base); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 878 | return child_iterator(&Base + 1); |
| 879 | } |