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 | c238f09 | 2010-08-31 04:59:00 +0000 | [diff] [blame^] | 389 | // TODO: Propagate nothrowness for implicitly declared special members. |
| 390 | case UTT_HasNothrowAssign: |
| 391 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 392 | // If type is const qualified or is a reference type then the |
| 393 | // trait is false. Otherwise if __has_trivial_assign (type) |
| 394 | // is true then the trait is true, else if type is a cv class |
| 395 | // or union type with copy assignment operators that are known |
| 396 | // not to throw an exception then the trait is true, else it is |
| 397 | // false. |
| 398 | if (C.getBaseElementType(QueriedType).isConstQualified()) |
| 399 | return false; |
| 400 | if (QueriedType->isReferenceType()) |
| 401 | return false; |
| 402 | if (QueriedType->isPODType()) |
| 403 | return true; |
| 404 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) { |
| 405 | CXXRecordDecl* RD = cast<CXXRecordDecl>(RT->getDecl()); |
| 406 | if (RD->hasTrivialCopyAssignment()) |
| 407 | return true; |
| 408 | |
| 409 | bool FoundAssign = false; |
| 410 | bool AllNoThrow = true; |
| 411 | DeclarationName Name = C.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 412 | DeclContext::lookup_const_iterator Op, OpEnd; |
| 413 | for (llvm::tie(Op, OpEnd) = RD->lookup(Name); |
| 414 | Op != OpEnd; ++Op) { |
| 415 | CXXMethodDecl *Operator = cast<CXXMethodDecl>(*Op); |
| 416 | if (Operator->isCopyAssignmentOperator()) { |
| 417 | FoundAssign = true; |
| 418 | const FunctionProtoType *CPT |
| 419 | = Operator->getType()->getAs<FunctionProtoType>(); |
| 420 | if (!CPT->hasEmptyExceptionSpec()) { |
| 421 | AllNoThrow = false; |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | return FoundAssign && AllNoThrow; |
| 428 | } |
| 429 | return false; |
| 430 | case UTT_HasNothrowCopy: |
| 431 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 432 | // If __has_trivial_copy (type) is true then the trait is true, else |
| 433 | // if type is a cv class or union type with copy constructors that are |
| 434 | // known not to throw an exception then the trait is true, else it is |
| 435 | // false. |
| 436 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 437 | return true; |
| 438 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) { |
| 439 | CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); |
| 440 | if (RD->hasTrivialCopyConstructor()) |
| 441 | return true; |
| 442 | |
| 443 | bool FoundConstructor = false; |
| 444 | bool AllNoThrow = true; |
| 445 | unsigned FoundTQs; |
| 446 | DeclarationName ConstructorName |
| 447 | = C.DeclarationNames.getCXXConstructorName( |
| 448 | C.getCanonicalType(QueriedType)); |
| 449 | DeclContext::lookup_const_iterator Con, ConEnd; |
| 450 | for (llvm::tie(Con, ConEnd) = RD->lookup(ConstructorName); |
| 451 | Con != ConEnd; ++Con) { |
| 452 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 453 | if (Constructor->isCopyConstructor(FoundTQs)) { |
| 454 | FoundConstructor = true; |
| 455 | const FunctionProtoType *CPT |
| 456 | = Constructor->getType()->getAs<FunctionProtoType>(); |
| 457 | if (!CPT->hasEmptyExceptionSpec()) { |
| 458 | AllNoThrow = false; |
| 459 | break; |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | return FoundConstructor && AllNoThrow; |
| 465 | } |
| 466 | return false; |
| 467 | case UTT_HasNothrowConstructor: |
| 468 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 469 | // If __has_trivial_constructor (type) is true then the trait is |
| 470 | // true, else if type is a cv class or union type (or array |
| 471 | // thereof) with a default constructor that is known not to |
| 472 | // throw an exception then the trait is true, else it is false. |
| 473 | if (QueriedType->isPODType()) |
| 474 | return true; |
| 475 | if (const RecordType *RT = |
| 476 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) { |
| 477 | CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); |
| 478 | if (RD->hasTrivialConstructor()) |
| 479 | return true; |
| 480 | |
| 481 | if (CXXConstructorDecl *Constructor = RD->getDefaultConstructor()) { |
| 482 | const FunctionProtoType *CPT |
| 483 | = Constructor->getType()->getAs<FunctionProtoType>(); |
| 484 | // TODO: check whether evaluating default arguments can throw. |
| 485 | // For now, we'll be conservative and assume that they can throw. |
| 486 | if (CPT->hasEmptyExceptionSpec() && CPT->getNumArgs() == 0) |
| 487 | return true; |
| 488 | } |
| 489 | } |
| 490 | return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Ted Kremenek | e383768 | 2009-12-23 04:00:48 +0000 | [diff] [blame] | 494 | SourceRange CXXConstructExpr::getSourceRange() const { |
| 495 | // FIXME: Should we know where the parentheses are, if there are any? |
| 496 | for (std::reverse_iterator<Stmt**> I(&Args[NumArgs]), E(&Args[0]); I!=E;++I) { |
| 497 | // Ignore CXXDefaultExprs when computing the range, as they don't |
| 498 | // have a range. |
| 499 | if (!isa<CXXDefaultArgExpr>(*I)) |
| 500 | return SourceRange(Loc, (*I)->getLocEnd()); |
| 501 | } |
| 502 | |
| 503 | return SourceRange(Loc); |
| 504 | } |
| 505 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 506 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 507 | OverloadedOperatorKind Kind = getOperator(); |
| 508 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 509 | if (getNumArgs() == 1) |
| 510 | // Prefix operator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | return SourceRange(getOperatorLoc(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 512 | getArg(0)->getSourceRange().getEnd()); |
| 513 | else |
| 514 | // Postfix operator |
| 515 | return SourceRange(getArg(0)->getSourceRange().getEnd(), |
| 516 | getOperatorLoc()); |
| 517 | } else if (Kind == OO_Call) { |
| 518 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 519 | } else if (Kind == OO_Subscript) { |
| 520 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 521 | } else if (getNumArgs() == 1) { |
| 522 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 523 | } else if (getNumArgs() == 2) { |
| 524 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 525 | getArg(1)->getSourceRange().getEnd()); |
| 526 | } else { |
| 527 | return SourceRange(); |
| 528 | } |
| 529 | } |
| 530 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 531 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() { |
| 532 | if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 533 | return MemExpr->getBase(); |
| 534 | |
| 535 | // FIXME: Will eventually need to cope with member pointers. |
| 536 | return 0; |
| 537 | } |
| 538 | |
Douglas Gregor | 00b98c2 | 2009-11-12 15:31:47 +0000 | [diff] [blame] | 539 | SourceRange CXXMemberCallExpr::getSourceRange() const { |
| 540 | SourceLocation LocStart = getCallee()->getLocStart(); |
| 541 | if (LocStart.isInvalid() && getNumArgs() > 0) |
| 542 | LocStart = getArg(0)->getLocStart(); |
| 543 | return SourceRange(LocStart, getRParenLoc()); |
| 544 | } |
| 545 | |
| 546 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 547 | //===----------------------------------------------------------------------===// |
| 548 | // Named casts |
| 549 | //===----------------------------------------------------------------------===// |
| 550 | |
| 551 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 552 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 553 | /// "const_cast". The returned pointer must not be freed. |
| 554 | const char *CXXNamedCastExpr::getCastName() const { |
| 555 | switch (getStmtClass()) { |
| 556 | case CXXStaticCastExprClass: return "static_cast"; |
| 557 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 558 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 559 | case CXXConstCastExprClass: return "const_cast"; |
| 560 | default: return "<invalid cast>"; |
| 561 | } |
| 562 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 563 | |
John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 564 | CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T, |
| 565 | CastKind K, Expr *Op, |
| 566 | const CXXCastPath *BasePath, |
| 567 | TypeSourceInfo *WrittenTy, |
| 568 | SourceLocation L) { |
| 569 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 570 | void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr) |
| 571 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 572 | CXXStaticCastExpr *E = |
| 573 | new (Buffer) CXXStaticCastExpr(T, K, Op, PathSize, WrittenTy, L); |
| 574 | if (PathSize) E->setCastPath(*BasePath); |
| 575 | return E; |
| 576 | } |
| 577 | |
| 578 | CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C, |
| 579 | unsigned PathSize) { |
| 580 | void *Buffer = |
| 581 | C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 582 | return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); |
| 583 | } |
| 584 | |
| 585 | CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T, |
| 586 | CastKind K, Expr *Op, |
| 587 | const CXXCastPath *BasePath, |
| 588 | TypeSourceInfo *WrittenTy, |
| 589 | SourceLocation L) { |
| 590 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 591 | void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr) |
| 592 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 593 | CXXDynamicCastExpr *E = |
| 594 | new (Buffer) CXXDynamicCastExpr(T, K, Op, PathSize, WrittenTy, L); |
| 595 | if (PathSize) E->setCastPath(*BasePath); |
| 596 | return E; |
| 597 | } |
| 598 | |
| 599 | CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C, |
| 600 | unsigned PathSize) { |
| 601 | void *Buffer = |
| 602 | C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 603 | return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); |
| 604 | } |
| 605 | |
| 606 | CXXReinterpretCastExpr * |
| 607 | CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, CastKind K, Expr *Op, |
| 608 | const CXXCastPath *BasePath, |
| 609 | TypeSourceInfo *WrittenTy, SourceLocation L) { |
| 610 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 611 | void *Buffer = |
| 612 | C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); |
| 613 | CXXReinterpretCastExpr *E = |
| 614 | new (Buffer) CXXReinterpretCastExpr(T, K, Op, PathSize, WrittenTy, L); |
| 615 | if (PathSize) E->setCastPath(*BasePath); |
| 616 | return E; |
| 617 | } |
| 618 | |
| 619 | CXXReinterpretCastExpr * |
| 620 | CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 621 | void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr) |
| 622 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 623 | return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); |
| 624 | } |
| 625 | |
| 626 | CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T, Expr *Op, |
| 627 | TypeSourceInfo *WrittenTy, |
| 628 | SourceLocation L) { |
| 629 | return new (C) CXXConstCastExpr(T, Op, WrittenTy, L); |
| 630 | } |
| 631 | |
| 632 | CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) { |
| 633 | return new (C) CXXConstCastExpr(EmptyShell()); |
| 634 | } |
| 635 | |
| 636 | CXXFunctionalCastExpr * |
| 637 | CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, |
| 638 | TypeSourceInfo *Written, SourceLocation L, |
| 639 | CastKind K, Expr *Op, const CXXCastPath *BasePath, |
| 640 | SourceLocation R) { |
| 641 | unsigned PathSize = (BasePath ? BasePath->size() : 0); |
| 642 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 643 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 644 | CXXFunctionalCastExpr *E = |
| 645 | new (Buffer) CXXFunctionalCastExpr(T, Written, L, K, Op, PathSize, R); |
| 646 | if (PathSize) E->setCastPath(*BasePath); |
| 647 | return E; |
| 648 | } |
| 649 | |
| 650 | CXXFunctionalCastExpr * |
| 651 | CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { |
| 652 | void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) |
| 653 | + PathSize * sizeof(CXXBaseSpecifier*)); |
| 654 | return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); |
| 655 | } |
| 656 | |
| 657 | |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 658 | CXXDefaultArgExpr * |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 659 | CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc, |
| 660 | ParmVarDecl *Param, Expr *SubExpr) { |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 661 | void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 662 | return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, |
| 663 | SubExpr); |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 667 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 668 | return new (C) CXXTemporary(Destructor); |
| 669 | } |
| 670 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 672 | CXXTemporary *Temp, |
| 673 | Expr* SubExpr) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | assert(SubExpr->getType()->isRecordType() && |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 675 | "Expression bound to a temporary must have record type!"); |
| 676 | |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 677 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 680 | CXXBindReferenceExpr *CXXBindReferenceExpr::Create(ASTContext &C, Expr *SubExpr, |
| 681 | bool ExtendsLifetime, |
| 682 | bool RequiresTemporaryCopy) { |
| 683 | return new (C) CXXBindReferenceExpr(SubExpr, |
| 684 | ExtendsLifetime, |
| 685 | RequiresTemporaryCopy); |
| 686 | } |
| 687 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 688 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 689 | CXXConstructorDecl *Cons, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 690 | QualType writtenTy, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | SourceLocation tyBeginLoc, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 692 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | unsigned NumArgs, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 694 | SourceLocation rParenLoc, |
| 695 | bool ZeroInitialization) |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 696 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, tyBeginLoc, |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 697 | Cons, false, Args, NumArgs, ZeroInitialization), |
Anders Carlsson | 524fa13 | 2009-04-24 17:34:38 +0000 | [diff] [blame] | 698 | TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) { |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 699 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 700 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 702 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 703 | CXXConstructorDecl *D, bool Elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 704 | Expr **Args, unsigned NumArgs, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 705 | bool ZeroInitialization, |
Anders Carlsson | fcaeef2 | 2010-05-02 23:53:04 +0000 | [diff] [blame] | 706 | ConstructionKind ConstructKind) { |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 707 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 708 | Elidable, Args, NumArgs, ZeroInitialization, |
Anders Carlsson | fcaeef2 | 2010-05-02 23:53:04 +0000 | [diff] [blame] | 709 | ConstructKind); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Douglas Gregor | 99a2e60 | 2009-12-16 01:38:02 +0000 | [diff] [blame] | 713 | SourceLocation Loc, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 714 | CXXConstructorDecl *D, bool elidable, |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 715 | Expr **args, unsigned numargs, |
Anders Carlsson | 72e96fd | 2010-05-02 22:54:08 +0000 | [diff] [blame] | 716 | bool ZeroInitialization, |
| 717 | ConstructionKind ConstructKind) |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 718 | : Expr(SC, T, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 719 | T->isDependentType(), |
| 720 | (T->isDependentType() || |
| 721 | CallExpr::hasAnyValueDependentArguments(args, numargs))), |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 722 | Constructor(D), Loc(Loc), Elidable(elidable), |
Anders Carlsson | 72e96fd | 2010-05-02 22:54:08 +0000 | [diff] [blame] | 723 | ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind), |
| 724 | Args(0), NumArgs(numargs) |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 725 | { |
| 726 | if (NumArgs) { |
| 727 | Args = new (C) Stmt*[NumArgs]; |
| 728 | |
| 729 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 730 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
| 731 | Args[i] = args[i]; |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 732 | } |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 733 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 736 | CXXExprWithTemporaries::CXXExprWithTemporaries(ASTContext &C, |
| 737 | Expr *subexpr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | CXXTemporary **temps, |
Anders Carlsson | 0ece491 | 2009-12-15 20:51:39 +0000 | [diff] [blame] | 739 | unsigned numtemps) |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 740 | : Expr(CXXExprWithTemporariesClass, subexpr->getType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | subexpr->isTypeDependent(), subexpr->isValueDependent()), |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 742 | SubExpr(subexpr), Temps(0), NumTemps(0) { |
Chris Lattner | aff32cb | 2010-05-10 00:45:12 +0000 | [diff] [blame] | 743 | if (numtemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 744 | setNumTemporaries(C, numtemps); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 745 | for (unsigned i = 0; i != numtemps; ++i) |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 746 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 750 | void CXXExprWithTemporaries::setNumTemporaries(ASTContext &C, unsigned N) { |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 751 | assert(Temps == 0 && "Cannot resize with this"); |
Daniel Dunbar | 90556d4 | 2010-05-10 15:59:37 +0000 | [diff] [blame] | 752 | NumTemps = N; |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 753 | Temps = new (C) CXXTemporary*[NumTemps]; |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 758 | Expr *SubExpr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | CXXTemporary **Temps, |
Anders Carlsson | 0ece491 | 2009-12-15 20:51:39 +0000 | [diff] [blame] | 760 | unsigned NumTemps) { |
Ted Kremenek | d04ed41 | 2010-05-10 20:06:30 +0000 | [diff] [blame] | 761 | return new (C) CXXExprWithTemporaries(C, SubExpr, Temps, NumTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 764 | // CXXBindTemporaryExpr |
| 765 | Stmt::child_iterator CXXBindTemporaryExpr::child_begin() { |
| 766 | return &SubExpr; |
| 767 | } |
| 768 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | Stmt::child_iterator CXXBindTemporaryExpr::child_end() { |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 770 | return &SubExpr + 1; |
| 771 | } |
| 772 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 773 | // CXXBindReferenceExpr |
| 774 | Stmt::child_iterator CXXBindReferenceExpr::child_begin() { |
| 775 | return &SubExpr; |
| 776 | } |
| 777 | |
| 778 | Stmt::child_iterator CXXBindReferenceExpr::child_end() { |
| 779 | return &SubExpr + 1; |
| 780 | } |
| 781 | |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 782 | // CXXConstructExpr |
| 783 | Stmt::child_iterator CXXConstructExpr::child_begin() { |
| 784 | return &Args[0]; |
| 785 | } |
| 786 | Stmt::child_iterator CXXConstructExpr::child_end() { |
| 787 | return &Args[0]+NumArgs; |
| 788 | } |
| 789 | |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 790 | // CXXExprWithTemporaries |
| 791 | Stmt::child_iterator CXXExprWithTemporaries::child_begin() { |
| 792 | return &SubExpr; |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 793 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 794 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 795 | Stmt::child_iterator CXXExprWithTemporaries::child_end() { |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 796 | return &SubExpr + 1; |
| 797 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 798 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 799 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr( |
| 800 | SourceLocation TyBeginLoc, |
| 801 | QualType T, |
| 802 | SourceLocation LParenLoc, |
| 803 | Expr **Args, |
| 804 | unsigned NumArgs, |
| 805 | SourceLocation RParenLoc) |
| 806 | : Expr(CXXUnresolvedConstructExprClass, T.getNonReferenceType(), |
| 807 | T->isDependentType(), true), |
| 808 | TyBeginLoc(TyBeginLoc), |
| 809 | Type(T), |
| 810 | LParenLoc(LParenLoc), |
| 811 | RParenLoc(RParenLoc), |
| 812 | NumArgs(NumArgs) { |
| 813 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
| 814 | memcpy(StoredArgs, Args, sizeof(Expr *) * NumArgs); |
| 815 | } |
| 816 | |
| 817 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 818 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 819 | SourceLocation TyBegin, |
| 820 | QualType T, |
| 821 | SourceLocation LParenLoc, |
| 822 | Expr **Args, |
| 823 | unsigned NumArgs, |
| 824 | SourceLocation RParenLoc) { |
| 825 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 826 | sizeof(Expr *) * NumArgs); |
| 827 | return new (Mem) CXXUnresolvedConstructExpr(TyBegin, T, LParenLoc, |
| 828 | Args, NumArgs, RParenLoc); |
| 829 | } |
| 830 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 831 | CXXUnresolvedConstructExpr * |
| 832 | CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) { |
| 833 | Stmt::EmptyShell Empty; |
| 834 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 835 | sizeof(Expr *) * NumArgs); |
| 836 | return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); |
| 837 | } |
| 838 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 839 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_begin() { |
| 840 | return child_iterator(reinterpret_cast<Stmt **>(this + 1)); |
| 841 | } |
| 842 | |
| 843 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_end() { |
| 844 | return child_iterator(reinterpret_cast<Stmt **>(this + 1) + NumArgs); |
| 845 | } |
Sebastian Redl | 8b0b475 | 2009-05-16 18:50:46 +0000 | [diff] [blame] | 846 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 847 | CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 848 | Expr *Base, QualType BaseType, |
| 849 | bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 850 | SourceLocation OperatorLoc, |
| 851 | NestedNameSpecifier *Qualifier, |
| 852 | SourceRange QualifierRange, |
| 853 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 854 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 855 | const TemplateArgumentListInfo *TemplateArgs) |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 856 | : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 857 | Base(Base), BaseType(BaseType), IsArrow(IsArrow), |
| 858 | HasExplicitTemplateArgs(TemplateArgs != 0), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 859 | OperatorLoc(OperatorLoc), |
| 860 | Qualifier(Qualifier), QualifierRange(QualifierRange), |
| 861 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 862 | MemberNameInfo(MemberNameInfo) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 863 | if (TemplateArgs) |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 864 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 865 | } |
| 866 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 867 | CXXDependentScopeMemberExpr * |
| 868 | CXXDependentScopeMemberExpr::Create(ASTContext &C, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 869 | Expr *Base, QualType BaseType, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 870 | SourceLocation OperatorLoc, |
| 871 | NestedNameSpecifier *Qualifier, |
| 872 | SourceRange QualifierRange, |
| 873 | NamedDecl *FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 874 | DeclarationNameInfo MemberNameInfo, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 875 | const TemplateArgumentListInfo *TemplateArgs) { |
| 876 | if (!TemplateArgs) |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 877 | return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 878 | IsArrow, OperatorLoc, |
| 879 | Qualifier, QualifierRange, |
| 880 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 881 | MemberNameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 883 | std::size_t size = sizeof(CXXDependentScopeMemberExpr); |
| 884 | if (TemplateArgs) |
| 885 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 886 | |
| 887 | void *Mem = C.Allocate(size, llvm::alignof<CXXDependentScopeMemberExpr>()); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 888 | return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, |
| 889 | IsArrow, OperatorLoc, |
| 890 | Qualifier, QualifierRange, |
| 891 | FirstQualifierFoundInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 892 | MemberNameInfo, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 895 | CXXDependentScopeMemberExpr * |
| 896 | CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C, |
| 897 | unsigned NumTemplateArgs) { |
| 898 | if (NumTemplateArgs == 0) |
| 899 | return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), |
| 900 | 0, SourceLocation(), 0, |
| 901 | SourceRange(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 902 | DeclarationNameInfo()); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 903 | |
| 904 | std::size_t size = sizeof(CXXDependentScopeMemberExpr) + |
| 905 | ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 906 | void *Mem = C.Allocate(size, llvm::alignof<CXXDependentScopeMemberExpr>()); |
| 907 | CXXDependentScopeMemberExpr *E |
| 908 | = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), |
| 909 | 0, SourceLocation(), 0, |
| 910 | SourceRange(), 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 911 | DeclarationNameInfo(), 0); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 912 | E->HasExplicitTemplateArgs = true; |
| 913 | return E; |
| 914 | } |
| 915 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 916 | Stmt::child_iterator CXXDependentScopeMemberExpr::child_begin() { |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 917 | return child_iterator(&Base); |
| 918 | } |
| 919 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 920 | Stmt::child_iterator CXXDependentScopeMemberExpr::child_end() { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 921 | if (isImplicitAccess()) |
| 922 | return child_iterator(&Base); |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 923 | return child_iterator(&Base + 1); |
| 924 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 925 | |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 926 | UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C, QualType T, |
| 927 | bool Dependent, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 928 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 929 | Expr *Base, QualType BaseType, |
| 930 | bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 931 | SourceLocation OperatorLoc, |
| 932 | NestedNameSpecifier *Qualifier, |
| 933 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 934 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 935 | const TemplateArgumentListInfo *TemplateArgs, |
| 936 | UnresolvedSetIterator Begin, |
| 937 | UnresolvedSetIterator End) |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 938 | : OverloadExpr(UnresolvedMemberExprClass, C, T, Dependent, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 939 | Qualifier, QualifierRange, MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 940 | TemplateArgs != 0, Begin, End), |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 941 | IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), |
| 942 | Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 943 | if (TemplateArgs) |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 944 | getExplicitTemplateArgs().initializeFrom(*TemplateArgs); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | UnresolvedMemberExpr * |
| 948 | UnresolvedMemberExpr::Create(ASTContext &C, bool Dependent, |
| 949 | bool HasUnresolvedUsing, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 950 | Expr *Base, QualType BaseType, bool IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 951 | SourceLocation OperatorLoc, |
| 952 | NestedNameSpecifier *Qualifier, |
| 953 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 954 | const DeclarationNameInfo &MemberNameInfo, |
Douglas Gregor | 5a84dec | 2010-05-23 18:57:34 +0000 | [diff] [blame] | 955 | const TemplateArgumentListInfo *TemplateArgs, |
| 956 | UnresolvedSetIterator Begin, |
| 957 | UnresolvedSetIterator End) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 958 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 959 | if (TemplateArgs) |
| 960 | size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); |
| 961 | |
| 962 | void *Mem = C.Allocate(size, llvm::alignof<UnresolvedMemberExpr>()); |
Douglas Gregor | 928e6fc | 2010-05-23 19:36:40 +0000 | [diff] [blame] | 963 | return new (Mem) UnresolvedMemberExpr(C, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 964 | Dependent ? C.DependentTy : C.OverloadTy, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 965 | Dependent, HasUnresolvedUsing, Base, BaseType, |
| 966 | IsArrow, OperatorLoc, Qualifier, QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 967 | MemberNameInfo, TemplateArgs, Begin, End); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Argyrios Kyrtzidis | a77eb08 | 2010-06-25 09:03:26 +0000 | [diff] [blame] | 970 | UnresolvedMemberExpr * |
| 971 | UnresolvedMemberExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) { |
| 972 | std::size_t size = sizeof(UnresolvedMemberExpr); |
| 973 | if (NumTemplateArgs != 0) |
| 974 | size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); |
| 975 | |
| 976 | void *Mem = C.Allocate(size, llvm::alignof<UnresolvedMemberExpr>()); |
| 977 | UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); |
| 978 | E->HasExplicitTemplateArgs = NumTemplateArgs != 0; |
| 979 | return E; |
| 980 | } |
| 981 | |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 982 | CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { |
| 983 | // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. |
| 984 | |
| 985 | // If there was a nested name specifier, it names the naming class. |
| 986 | // It can't be dependent: after all, we were actually able to do the |
| 987 | // lookup. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 988 | CXXRecordDecl *Record = 0; |
John McCall | 7bb12da | 2010-02-02 06:20:04 +0000 | [diff] [blame] | 989 | if (getQualifier()) { |
| 990 | Type *T = getQualifier()->getAsType(); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 991 | assert(T && "qualifier in member expression does not name type"); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 992 | Record = T->getAsCXXRecordDecl(); |
| 993 | assert(Record && "qualifier in member expression does not name record"); |
| 994 | } |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 995 | // Otherwise the naming class must have been the base class. |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 996 | else { |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 997 | QualType BaseType = getBaseType().getNonReferenceType(); |
| 998 | if (isArrow()) { |
| 999 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 1000 | assert(PT && "base of arrow member access is not pointer"); |
| 1001 | BaseType = PT->getPointeeType(); |
| 1002 | } |
| 1003 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1004 | Record = BaseType->getAsCXXRecordDecl(); |
| 1005 | assert(Record && "base of member expression does not name record"); |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 1008 | return Record; |
John McCall | c373d48 | 2010-01-27 01:50:18 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1011 | Stmt::child_iterator UnresolvedMemberExpr::child_begin() { |
| 1012 | return child_iterator(&Base); |
| 1013 | } |
| 1014 | |
| 1015 | Stmt::child_iterator UnresolvedMemberExpr::child_end() { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1016 | if (isImplicitAccess()) |
| 1017 | return child_iterator(&Base); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1018 | return child_iterator(&Base + 1); |
| 1019 | } |