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