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