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 |
| 76 | CXXNewExpr::CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, |
| 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; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 90 | SubExprs = new Stmt*[TotalSize]; |
| 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 | |
| 101 | Stmt::child_iterator CXXNewExpr::child_begin() { return &SubExprs[0]; } |
| 102 | Stmt::child_iterator CXXNewExpr::child_end() { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 103 | return &SubExprs[0] + Array + getNumPlacementArgs() + getNumConstructorArgs(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // CXXDeleteExpr |
| 107 | Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; } |
| 108 | Stmt::child_iterator CXXDeleteExpr::child_end() { return &Argument+1; } |
| 109 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 110 | // CXXPseudoDestructorExpr |
| 111 | Stmt::child_iterator CXXPseudoDestructorExpr::child_begin() { return &Base; } |
| 112 | Stmt::child_iterator CXXPseudoDestructorExpr::child_end() { |
| 113 | return &Base + 1; |
| 114 | } |
| 115 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 116 | // UnresolvedLookupExpr |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 117 | UnresolvedLookupExpr * |
| 118 | UnresolvedLookupExpr::Create(ASTContext &C, bool Dependent, |
| 119 | NestedNameSpecifier *Qualifier, |
| 120 | SourceRange QualifierRange, DeclarationName Name, |
| 121 | SourceLocation NameLoc, bool ADL, |
| 122 | const TemplateArgumentListInfo &Args) |
| 123 | { |
| 124 | void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) + |
| 125 | ExplicitTemplateArgumentList::sizeFor(Args)); |
| 126 | UnresolvedLookupExpr *ULE |
| 127 | = new (Mem) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy, |
| 128 | Dependent, Qualifier, QualifierRange, |
| 129 | Name, NameLoc, ADL, |
| 130 | /*Overload*/ true, |
| 131 | /*ExplicitTemplateArgs*/ true); |
| 132 | |
| 133 | reinterpret_cast<ExplicitTemplateArgumentList*>(ULE+1)->initializeFrom(Args); |
| 134 | |
| 135 | return ULE; |
| 136 | } |
| 137 | |
| 138 | bool UnresolvedLookupExpr::ComputeDependence(NamedDecl * const *Begin, |
| 139 | NamedDecl * const *End, |
| 140 | const TemplateArgumentListInfo *Args) { |
| 141 | for (NamedDecl * const *I = Begin; I != End; ++I) |
| 142 | if ((*I)->getDeclContext()->isDependentContext()) |
| 143 | return true; |
| 144 | |
| 145 | if (Args && TemplateSpecializationType::anyDependentTemplateArguments(*Args)) |
| 146 | return true; |
| 147 | |
| 148 | return false; |
| 149 | } |
| 150 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 151 | Stmt::child_iterator UnresolvedLookupExpr::child_begin() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 152 | return child_iterator(); |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 153 | } |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 154 | Stmt::child_iterator UnresolvedLookupExpr::child_end() { |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 155 | return child_iterator(); |
| 156 | } |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 157 | // UnaryTypeTraitExpr |
| 158 | Stmt::child_iterator UnaryTypeTraitExpr::child_begin() { |
| 159 | return child_iterator(); |
| 160 | } |
| 161 | Stmt::child_iterator UnaryTypeTraitExpr::child_end() { |
| 162 | return child_iterator(); |
| 163 | } |
| 164 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 165 | // DependentScopeDeclRefExpr |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 166 | DependentScopeDeclRefExpr * |
| 167 | DependentScopeDeclRefExpr::Create(ASTContext &C, |
| 168 | NestedNameSpecifier *Qualifier, |
| 169 | SourceRange QualifierRange, |
| 170 | DeclarationName Name, |
| 171 | SourceLocation NameLoc, |
| 172 | const TemplateArgumentListInfo *Args) { |
| 173 | std::size_t size = sizeof(DependentScopeDeclRefExpr); |
| 174 | if (Args) size += ExplicitTemplateArgumentList::sizeFor(*Args); |
| 175 | void *Mem = C.Allocate(size); |
| 176 | |
| 177 | DependentScopeDeclRefExpr *DRE |
| 178 | = new (Mem) DependentScopeDeclRefExpr(C.DependentTy, |
| 179 | Qualifier, QualifierRange, |
| 180 | Name, NameLoc, |
| 181 | Args != 0); |
| 182 | |
| 183 | if (Args) |
| 184 | reinterpret_cast<ExplicitTemplateArgumentList*>(DRE+1) |
| 185 | ->initializeFrom(*Args); |
| 186 | |
| 187 | return DRE; |
| 188 | } |
| 189 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 190 | StmtIterator DependentScopeDeclRefExpr::child_begin() { |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 191 | return child_iterator(); |
| 192 | } |
| 193 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 194 | StmtIterator DependentScopeDeclRefExpr::child_end() { |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 195 | return child_iterator(); |
| 196 | } |
| 197 | |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 198 | bool UnaryTypeTraitExpr::EvaluateTrait(ASTContext& C) const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 199 | switch(UTT) { |
| 200 | default: assert(false && "Unknown type trait or not implemented"); |
| 201 | case UTT_IsPOD: return QueriedType->isPODType(); |
| 202 | case UTT_IsClass: // Fallthrough |
| 203 | case UTT_IsUnion: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 204 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 205 | bool Union = Record->getDecl()->isUnion(); |
| 206 | return UTT == UTT_IsUnion ? Union : !Union; |
| 207 | } |
| 208 | return false; |
| 209 | case UTT_IsEnum: return QueriedType->isEnumeralType(); |
| 210 | case UTT_IsPolymorphic: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 211 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 212 | // Type traits are only parsed in C++, so we've got CXXRecords. |
| 213 | return cast<CXXRecordDecl>(Record->getDecl())->isPolymorphic(); |
| 214 | } |
| 215 | return false; |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 216 | case UTT_IsAbstract: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 217 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 218 | return cast<CXXRecordDecl>(RT->getDecl())->isAbstract(); |
| 219 | return false; |
Eli Friedman | 1d954f6 | 2009-08-15 21:55:26 +0000 | [diff] [blame] | 220 | case UTT_IsEmpty: |
| 221 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
| 222 | return !Record->getDecl()->isUnion() |
| 223 | && cast<CXXRecordDecl>(Record->getDecl())->isEmpty(); |
| 224 | } |
| 225 | return false; |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 226 | case UTT_HasTrivialConstructor: |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 227 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 228 | // If __is_pod (type) is true then the trait is true, else if type is |
| 229 | // a cv class or union type (or array thereof) with a trivial default |
| 230 | // constructor ([class.ctor]) then the trait is true, else it is false. |
| 231 | if (QueriedType->isPODType()) |
| 232 | return true; |
| 233 | if (const RecordType *RT = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 234 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 235 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialConstructor(); |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 236 | return false; |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 237 | case UTT_HasTrivialCopy: |
| 238 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 239 | // If __is_pod (type) is true or type is a reference type then |
| 240 | // the trait is true, else if type is a cv class or union type |
| 241 | // with a trivial copy constructor ([class.copy]) then the trait |
| 242 | // is true, else it is false. |
| 243 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 244 | return true; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 245 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 246 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialCopyConstructor(); |
| 247 | return false; |
| 248 | case UTT_HasTrivialAssign: |
| 249 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 250 | // If type is const qualified or is a reference type then the |
| 251 | // trait is false. Otherwise if __is_pod (type) is true then the |
| 252 | // trait is true, else if type is a cv class or union type with |
| 253 | // a trivial copy assignment ([class.copy]) then the trait is |
| 254 | // true, else it is false. |
| 255 | // Note: the const and reference restrictions are interesting, |
| 256 | // given that const and reference members don't prevent a class |
| 257 | // from having a trivial copy assignment operator (but do cause |
| 258 | // errors if the copy assignment operator is actually used, q.v. |
| 259 | // [class.copy]p12). |
| 260 | |
| 261 | if (C.getBaseElementType(QueriedType).isConstQualified()) |
| 262 | return false; |
| 263 | if (QueriedType->isPODType()) |
| 264 | return true; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 265 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 266 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialCopyAssignment(); |
| 267 | return false; |
| 268 | case UTT_HasTrivialDestructor: |
| 269 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 270 | // If __is_pod (type) is true or type is a reference type |
| 271 | // then the trait is true, else if type is a cv class or union |
| 272 | // type (or array thereof) with a trivial destructor |
| 273 | // ([class.dtor]) then the trait is true, else it is |
| 274 | // false. |
| 275 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 276 | return true; |
| 277 | if (const RecordType *RT = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 278 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 279 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialDestructor(); |
| 280 | return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 284 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 285 | OverloadedOperatorKind Kind = getOperator(); |
| 286 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 287 | if (getNumArgs() == 1) |
| 288 | // Prefix operator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | return SourceRange(getOperatorLoc(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 290 | getArg(0)->getSourceRange().getEnd()); |
| 291 | else |
| 292 | // Postfix operator |
| 293 | return SourceRange(getArg(0)->getSourceRange().getEnd(), |
| 294 | getOperatorLoc()); |
| 295 | } else if (Kind == OO_Call) { |
| 296 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 297 | } else if (Kind == OO_Subscript) { |
| 298 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 299 | } else if (getNumArgs() == 1) { |
| 300 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 301 | } else if (getNumArgs() == 2) { |
| 302 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 303 | getArg(1)->getSourceRange().getEnd()); |
| 304 | } else { |
| 305 | return SourceRange(); |
| 306 | } |
| 307 | } |
| 308 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 309 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() { |
| 310 | if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 311 | return MemExpr->getBase(); |
| 312 | |
| 313 | // FIXME: Will eventually need to cope with member pointers. |
| 314 | return 0; |
| 315 | } |
| 316 | |
Douglas Gregor | 00b98c2 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 317 | SourceRange CXXMemberCallExpr::getSourceRange() const { |
| 318 | SourceLocation LocStart = getCallee()->getLocStart(); |
| 319 | if (LocStart.isInvalid() && getNumArgs() > 0) |
| 320 | LocStart = getArg(0)->getLocStart(); |
| 321 | return SourceRange(LocStart, getRParenLoc()); |
| 322 | } |
| 323 | |
| 324 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 325 | //===----------------------------------------------------------------------===// |
| 326 | // Named casts |
| 327 | //===----------------------------------------------------------------------===// |
| 328 | |
| 329 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 330 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 331 | /// "const_cast". The returned pointer must not be freed. |
| 332 | const char *CXXNamedCastExpr::getCastName() const { |
| 333 | switch (getStmtClass()) { |
| 334 | case CXXStaticCastExprClass: return "static_cast"; |
| 335 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 336 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 337 | case CXXConstCastExprClass: return "const_cast"; |
| 338 | default: return "<invalid cast>"; |
| 339 | } |
| 340 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 341 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 343 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 344 | return new (C) CXXTemporary(Destructor); |
| 345 | } |
| 346 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 347 | void CXXTemporary::Destroy(ASTContext &Ctx) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 348 | this->~CXXTemporary(); |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 349 | Ctx.Deallocate(this); |
Anders Carlsson | c1ce477 | 2009-05-30 19:54:15 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 353 | CXXTemporary *Temp, |
| 354 | Expr* SubExpr) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | assert(SubExpr->getType()->isRecordType() && |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 356 | "Expression bound to a temporary must have record type!"); |
| 357 | |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 358 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 361 | void CXXBindTemporaryExpr::DoDestroy(ASTContext &C) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 362 | Temp->Destroy(C); |
| 363 | this->~CXXBindTemporaryExpr(); |
| 364 | C.Deallocate(this); |
| 365 | } |
| 366 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 367 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 368 | CXXConstructorDecl *Cons, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 369 | QualType writtenTy, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | SourceLocation tyBeginLoc, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 371 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | unsigned NumArgs, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 373 | SourceLocation rParenLoc) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, Cons, |
| 375 | false, Args, NumArgs), |
Anders Carlsson | 524fa13 | 2009-04-24 17:34:38 +0000 | [diff] [blame] | 376 | TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) { |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 377 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 378 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 379 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 380 | CXXConstructorDecl *D, bool Elidable, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 381 | Expr **Args, unsigned NumArgs) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, D, Elidable, |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 383 | Args, NumArgs); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 386 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 387 | CXXConstructorDecl *D, bool elidable, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | Expr **args, unsigned numargs) |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 389 | : Expr(SC, T, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 390 | T->isDependentType(), |
| 391 | (T->isDependentType() || |
| 392 | CallExpr::hasAnyValueDependentArguments(args, numargs))), |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 393 | Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) { |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 394 | if (NumArgs) { |
| 395 | Args = new (C) Stmt*[NumArgs]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 397 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 398 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 399 | Args[i] = args[i]; |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 400 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame] | 404 | CXXConstructExpr::CXXConstructExpr(EmptyShell Empty, ASTContext &C, |
| 405 | unsigned numargs) |
| 406 | : Expr(CXXConstructExprClass, Empty), Args(0), NumArgs(numargs) |
| 407 | { |
| 408 | if (NumArgs) |
| 409 | Args = new (C) Stmt*[NumArgs]; |
| 410 | } |
| 411 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 412 | void CXXConstructExpr::DoDestroy(ASTContext &C) { |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 413 | DestroyChildren(C); |
| 414 | if (Args) |
| 415 | C.Deallocate(Args); |
| 416 | this->~CXXConstructExpr(); |
| 417 | C.Deallocate(this); |
| 418 | } |
| 419 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr, |
| 421 | CXXTemporary **temps, |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 422 | unsigned numtemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 423 | bool shoulddestroytemps) |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 424 | : Expr(CXXExprWithTemporariesClass, subexpr->getType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | subexpr->isTypeDependent(), subexpr->isValueDependent()), |
| 426 | SubExpr(subexpr), Temps(0), NumTemps(numtemps), |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 427 | ShouldDestroyTemps(shoulddestroytemps) { |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 428 | if (NumTemps > 0) { |
| 429 | Temps = new CXXTemporary*[NumTemps]; |
| 430 | for (unsigned i = 0; i < NumTemps; ++i) |
| 431 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 436 | Expr *SubExpr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | CXXTemporary **Temps, |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 438 | unsigned NumTemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 439 | bool ShouldDestroyTemps){ |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 441 | ShouldDestroyTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 444 | void CXXExprWithTemporaries::DoDestroy(ASTContext &C) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 445 | DestroyChildren(C); |
| 446 | this->~CXXExprWithTemporaries(); |
| 447 | C.Deallocate(this); |
| 448 | } |
| 449 | |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 450 | CXXExprWithTemporaries::~CXXExprWithTemporaries() { |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 451 | delete[] Temps; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 454 | // CXXBindTemporaryExpr |
| 455 | Stmt::child_iterator CXXBindTemporaryExpr::child_begin() { |
| 456 | return &SubExpr; |
| 457 | } |
| 458 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 459 | Stmt::child_iterator CXXBindTemporaryExpr::child_end() { |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 460 | return &SubExpr + 1; |
| 461 | } |
| 462 | |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 463 | // CXXConstructExpr |
| 464 | Stmt::child_iterator CXXConstructExpr::child_begin() { |
| 465 | return &Args[0]; |
| 466 | } |
| 467 | Stmt::child_iterator CXXConstructExpr::child_end() { |
| 468 | return &Args[0]+NumArgs; |
| 469 | } |
| 470 | |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 471 | // CXXExprWithTemporaries |
| 472 | Stmt::child_iterator CXXExprWithTemporaries::child_begin() { |
| 473 | return &SubExpr; |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 474 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 475 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 476 | Stmt::child_iterator CXXExprWithTemporaries::child_end() { |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 477 | return &SubExpr + 1; |
| 478 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 479 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 480 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr( |
| 481 | SourceLocation TyBeginLoc, |
| 482 | QualType T, |
| 483 | SourceLocation LParenLoc, |
| 484 | Expr **Args, |
| 485 | unsigned NumArgs, |
| 486 | SourceLocation RParenLoc) |
| 487 | : Expr(CXXUnresolvedConstructExprClass, T.getNonReferenceType(), |
| 488 | T->isDependentType(), true), |
| 489 | TyBeginLoc(TyBeginLoc), |
| 490 | Type(T), |
| 491 | LParenLoc(LParenLoc), |
| 492 | RParenLoc(RParenLoc), |
| 493 | NumArgs(NumArgs) { |
| 494 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
| 495 | memcpy(StoredArgs, Args, sizeof(Expr *) * NumArgs); |
| 496 | } |
| 497 | |
| 498 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 500 | SourceLocation TyBegin, |
| 501 | QualType T, |
| 502 | SourceLocation LParenLoc, |
| 503 | Expr **Args, |
| 504 | unsigned NumArgs, |
| 505 | SourceLocation RParenLoc) { |
| 506 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 507 | sizeof(Expr *) * NumArgs); |
| 508 | return new (Mem) CXXUnresolvedConstructExpr(TyBegin, T, LParenLoc, |
| 509 | Args, NumArgs, RParenLoc); |
| 510 | } |
| 511 | |
| 512 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_begin() { |
| 513 | return child_iterator(reinterpret_cast<Stmt **>(this + 1)); |
| 514 | } |
| 515 | |
| 516 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_end() { |
| 517 | return child_iterator(reinterpret_cast<Stmt **>(this + 1) + NumArgs); |
| 518 | } |
Sebastian Redl | 8b0b475 | 2009-05-16 18:50:46 +0000 | [diff] [blame] | 519 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 520 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | Expr *Base, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 522 | SourceLocation OperatorLoc, |
| 523 | NestedNameSpecifier *Qualifier, |
| 524 | SourceRange QualifierRange, |
| 525 | NamedDecl *FirstQualifierFoundInScope, |
| 526 | DeclarationName Member, |
| 527 | SourceLocation MemberLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 528 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 529 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | Base(Base), IsArrow(IsArrow), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 531 | HasExplicitTemplateArgumentList(TemplateArgs), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 532 | OperatorLoc(OperatorLoc), |
| 533 | Qualifier(Qualifier), QualifierRange(QualifierRange), |
| 534 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | Member(Member), MemberLoc(MemberLoc) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 536 | if (TemplateArgs) |
| 537 | getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 538 | } |
| 539 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 540 | CXXDependentScopeMemberExpr * |
| 541 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | Expr *Base, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 543 | SourceLocation OperatorLoc, |
| 544 | NestedNameSpecifier *Qualifier, |
| 545 | SourceRange QualifierRange, |
| 546 | NamedDecl *FirstQualifierFoundInScope, |
| 547 | DeclarationName Member, |
| 548 | SourceLocation MemberLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 549 | const TemplateArgumentListInfo *TemplateArgs) { |
| 550 | if (!TemplateArgs) |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 551 | return new (C) CXXDependentScopeMemberExpr(C, Base, IsArrow, OperatorLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 552 | Qualifier, QualifierRange, |
| 553 | FirstQualifierFoundInScope, |
| 554 | Member, MemberLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 556 | std::size_t size = sizeof(CXXDependentScopeMemberExpr); |
| 557 | if (TemplateArgs) |
| 558 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 559 | |
| 560 | void *Mem = C.Allocate(size, llvm::alignof<CXXDependentScopeMemberExpr>()); |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 561 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, IsArrow, OperatorLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 562 | Qualifier, QualifierRange, |
| 563 | FirstQualifierFoundInScope, |
| 564 | Member, |
| 565 | MemberLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 566 | TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 567 | } |
| 568 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 569 | Stmt::child_iterator CXXDependentScopeMemberExpr::child_begin() { |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 570 | return child_iterator(&Base); |
| 571 | } |
| 572 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 573 | Stmt::child_iterator CXXDependentScopeMemberExpr::child_end() { |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 574 | return child_iterator(&Base + 1); |
| 575 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 576 | |
| 577 | UnresolvedMemberExpr::UnresolvedMemberExpr(QualType T, bool Dependent, |
| 578 | bool HasUnresolvedUsing, |
| 579 | Expr *Base, bool IsArrow, |
| 580 | SourceLocation OperatorLoc, |
| 581 | NestedNameSpecifier *Qualifier, |
| 582 | SourceRange QualifierRange, |
| 583 | DeclarationName MemberName, |
| 584 | SourceLocation MemberLoc, |
| 585 | const TemplateArgumentListInfo *TemplateArgs) |
| 586 | : Expr(UnresolvedMemberExprClass, T, Dependent, Dependent), |
| 587 | Base(Base), IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 588 | HasExplicitTemplateArgs(TemplateArgs != 0), |
| 589 | OperatorLoc(OperatorLoc), |
| 590 | Qualifier(Qualifier), QualifierRange(QualifierRange), |
| 591 | MemberName(MemberName), MemberLoc(MemberLoc) { |
| 592 | if (TemplateArgs) |
| 593 | getExplicitTemplateArgs()->initializeFrom(*TemplateArgs); |
| 594 | } |
| 595 | |
| 596 | UnresolvedMemberExpr * |
| 597 | UnresolvedMemberExpr::Create(ASTContext &C, bool Dependent, |
| 598 | bool HasUnresolvedUsing, |
| 599 | Expr *Base, bool IsArrow, |
| 600 | SourceLocation OperatorLoc, |
| 601 | NestedNameSpecifier *Qualifier, |
| 602 | SourceRange QualifierRange, |
| 603 | DeclarationName Member, |
| 604 | SourceLocation MemberLoc, |
| 605 | const TemplateArgumentListInfo *TemplateArgs) { |
| 606 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 607 | if (TemplateArgs) |
| 608 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 609 | |
| 610 | void *Mem = C.Allocate(size, llvm::alignof<UnresolvedMemberExpr>()); |
| 611 | return new (Mem) UnresolvedMemberExpr( |
| 612 | Dependent ? C.DependentTy : C.OverloadTy, |
| 613 | Dependent, HasUnresolvedUsing, Base, IsArrow, |
| 614 | OperatorLoc, Qualifier, QualifierRange, |
| 615 | Member, MemberLoc, TemplateArgs); |
| 616 | } |
| 617 | |
| 618 | Stmt::child_iterator UnresolvedMemberExpr::child_begin() { |
| 619 | return child_iterator(&Base); |
| 620 | } |
| 621 | |
| 622 | Stmt::child_iterator UnresolvedMemberExpr::child_end() { |
| 623 | return child_iterator(&Base + 1); |
| 624 | } |