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