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