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