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