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