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" |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprCXX.h" |
| 17 | using namespace clang; |
| 18 | |
Argyrios Kyrtzidis | 4189a76 | 2008-09-10 02:14:49 +0000 | [diff] [blame] | 19 | void CXXConditionDeclExpr::Destroy(ASTContext& C) { |
Sebastian Redl | df2d3cf | 2009-02-05 15:12:41 +0000 | [diff] [blame] | 20 | // FIXME: Cannot destroy the decl here, because it is linked into the |
| 21 | // DeclContext's chain. |
| 22 | //getVarDecl()->Destroy(C); |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 23 | this->~CXXConditionDeclExpr(); |
| 24 | C.Deallocate(this); |
Argyrios Kyrtzidis | 4189a76 | 2008-09-10 02:14:49 +0000 | [diff] [blame] | 25 | } |
Argyrios Kyrtzidis | 9e922b1 | 2008-09-09 23:47:53 +0000 | [diff] [blame] | 26 | |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | // Child Iterators for iterating over subexpressions/substatements |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 31 | // CXXTypeidExpr - has child iterators if the operand is an expression |
| 32 | Stmt::child_iterator CXXTypeidExpr::child_begin() { |
Sebastian Redl | d457589 | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 33 | return isTypeOperand() ? child_iterator() : &Operand.Ex; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 34 | } |
| 35 | Stmt::child_iterator CXXTypeidExpr::child_end() { |
Sebastian Redl | d457589 | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 36 | return isTypeOperand() ? child_iterator() : &Operand.Ex+1; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 37 | } |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 38 | |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 39 | // CXXBoolLiteralExpr |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 40 | Stmt::child_iterator CXXBoolLiteralExpr::child_begin() { |
| 41 | return child_iterator(); |
| 42 | } |
| 43 | Stmt::child_iterator CXXBoolLiteralExpr::child_end() { |
| 44 | return child_iterator(); |
| 45 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 46 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 47 | // CXXNullPtrLiteralExpr |
| 48 | Stmt::child_iterator CXXNullPtrLiteralExpr::child_begin() { |
| 49 | return child_iterator(); |
| 50 | } |
| 51 | Stmt::child_iterator CXXNullPtrLiteralExpr::child_end() { |
| 52 | return child_iterator(); |
| 53 | } |
| 54 | |
Douglas Gregor | 796da18 | 2008-11-04 14:32:21 +0000 | [diff] [blame] | 55 | // CXXThisExpr |
| 56 | Stmt::child_iterator CXXThisExpr::child_begin() { return child_iterator(); } |
| 57 | Stmt::child_iterator CXXThisExpr::child_end() { return child_iterator(); } |
| 58 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 59 | // CXXThrowExpr |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 60 | Stmt::child_iterator CXXThrowExpr::child_begin() { return &Op; } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 61 | Stmt::child_iterator CXXThrowExpr::child_end() { |
| 62 | // If Op is 0, we are processing throw; which has no children. |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 63 | return Op ? &Op+1 : &Op; |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 64 | } |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 65 | |
| 66 | // CXXDefaultArgExpr |
| 67 | Stmt::child_iterator CXXDefaultArgExpr::child_begin() { |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 68 | return child_iterator(); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 69 | } |
| 70 | Stmt::child_iterator CXXDefaultArgExpr::child_end() { |
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 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 73 | |
| 74 | // CXXZeroInitValueExpr |
| 75 | Stmt::child_iterator CXXZeroInitValueExpr::child_begin() { |
| 76 | return child_iterator(); |
| 77 | } |
| 78 | Stmt::child_iterator CXXZeroInitValueExpr::child_end() { |
| 79 | return child_iterator(); |
| 80 | } |
Argyrios Kyrtzidis | 9e922b1 | 2008-09-09 23:47:53 +0000 | [diff] [blame] | 81 | |
| 82 | // CXXConditionDeclExpr |
| 83 | Stmt::child_iterator CXXConditionDeclExpr::child_begin() { |
| 84 | return getVarDecl(); |
| 85 | } |
| 86 | Stmt::child_iterator CXXConditionDeclExpr::child_end() { |
| 87 | return child_iterator(); |
| 88 | } |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 89 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 90 | // CXXNewExpr |
| 91 | CXXNewExpr::CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, |
| 92 | Expr **placementArgs, unsigned numPlaceArgs, |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 93 | bool parenTypeId, Expr *arraySize, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 94 | CXXConstructorDecl *constructor, bool initializer, |
| 95 | Expr **constructorArgs, unsigned numConsArgs, |
| 96 | FunctionDecl *operatorDelete, QualType ty, |
| 97 | SourceLocation startLoc, SourceLocation endLoc) |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 98 | : Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()), |
| 99 | GlobalNew(globalNew), ParenTypeId(parenTypeId), |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 100 | Initializer(initializer), Array(arraySize), NumPlacementArgs(numPlaceArgs), |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 101 | NumConstructorArgs(numConsArgs), OperatorNew(operatorNew), |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 102 | OperatorDelete(operatorDelete), Constructor(constructor), |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 103 | StartLoc(startLoc), EndLoc(endLoc) |
| 104 | { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 105 | unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 106 | SubExprs = new Stmt*[TotalSize]; |
| 107 | unsigned i = 0; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 108 | if (Array) |
| 109 | SubExprs[i++] = arraySize; |
| 110 | for (unsigned j = 0; j < NumPlacementArgs; ++j) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 111 | SubExprs[i++] = placementArgs[j]; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 112 | for (unsigned j = 0; j < NumConstructorArgs; ++j) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 113 | SubExprs[i++] = constructorArgs[j]; |
| 114 | assert(i == TotalSize); |
| 115 | } |
| 116 | |
| 117 | Stmt::child_iterator CXXNewExpr::child_begin() { return &SubExprs[0]; } |
| 118 | Stmt::child_iterator CXXNewExpr::child_end() { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 119 | return &SubExprs[0] + Array + getNumPlacementArgs() + getNumConstructorArgs(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // CXXDeleteExpr |
| 123 | Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; } |
| 124 | Stmt::child_iterator CXXDeleteExpr::child_end() { return &Argument+1; } |
| 125 | |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 126 | // UnresolvedFunctionNameExpr |
| 127 | Stmt::child_iterator UnresolvedFunctionNameExpr::child_begin() { |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 128 | return child_iterator(); |
| 129 | } |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 130 | Stmt::child_iterator UnresolvedFunctionNameExpr::child_end() { |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 131 | return child_iterator(); |
| 132 | } |
| 133 | |
Douglas Gregor | 4a2487a | 2009-05-19 00:38:01 +0000 | [diff] [blame] | 134 | UnresolvedFunctionNameExpr* |
| 135 | UnresolvedFunctionNameExpr::Clone(ASTContext &C) const { |
| 136 | return new (C) UnresolvedFunctionNameExpr(Name, getType(), Loc); |
| 137 | } |
| 138 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 139 | // UnaryTypeTraitExpr |
| 140 | Stmt::child_iterator UnaryTypeTraitExpr::child_begin() { |
| 141 | return child_iterator(); |
| 142 | } |
| 143 | Stmt::child_iterator UnaryTypeTraitExpr::child_end() { |
| 144 | return child_iterator(); |
| 145 | } |
| 146 | |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 147 | // UnresolvedDeclRefExpr |
| 148 | StmtIterator UnresolvedDeclRefExpr::child_begin() { |
| 149 | return child_iterator(); |
| 150 | } |
| 151 | |
| 152 | StmtIterator UnresolvedDeclRefExpr::child_end() { |
| 153 | return child_iterator(); |
| 154 | } |
| 155 | |
Daniel Dunbar | c87a282 | 2009-02-17 23:20:26 +0000 | [diff] [blame] | 156 | bool UnaryTypeTraitExpr::EvaluateTrait() const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 157 | switch(UTT) { |
| 158 | default: assert(false && "Unknown type trait or not implemented"); |
| 159 | case UTT_IsPOD: return QueriedType->isPODType(); |
| 160 | case UTT_IsClass: // Fallthrough |
| 161 | case UTT_IsUnion: |
| 162 | if (const RecordType *Record = QueriedType->getAsRecordType()) { |
| 163 | bool Union = Record->getDecl()->isUnion(); |
| 164 | return UTT == UTT_IsUnion ? Union : !Union; |
| 165 | } |
| 166 | return false; |
| 167 | case UTT_IsEnum: return QueriedType->isEnumeralType(); |
| 168 | case UTT_IsPolymorphic: |
| 169 | if (const RecordType *Record = QueriedType->getAsRecordType()) { |
| 170 | // Type traits are only parsed in C++, so we've got CXXRecords. |
| 171 | return cast<CXXRecordDecl>(Record->getDecl())->isPolymorphic(); |
| 172 | } |
| 173 | return false; |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 174 | case UTT_IsAbstract: |
| 175 | if (const RecordType *RT = QueriedType->getAsRecordType()) |
| 176 | return cast<CXXRecordDecl>(RT->getDecl())->isAbstract(); |
| 177 | return false; |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 178 | case UTT_HasTrivialConstructor: |
| 179 | if (const RecordType *RT = QueriedType->getAsRecordType()) |
| 180 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialConstructor(); |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 181 | return false; |
| 182 | case UTT_HasTrivialDestructor: |
| 183 | if (const RecordType *RT = QueriedType->getAsRecordType()) |
| 184 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialDestructor(); |
| 185 | return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 189 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 190 | OverloadedOperatorKind Kind = getOperator(); |
| 191 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 192 | if (getNumArgs() == 1) |
| 193 | // Prefix operator |
| 194 | return SourceRange(getOperatorLoc(), |
| 195 | getArg(0)->getSourceRange().getEnd()); |
| 196 | else |
| 197 | // Postfix operator |
| 198 | return SourceRange(getArg(0)->getSourceRange().getEnd(), |
| 199 | getOperatorLoc()); |
| 200 | } else if (Kind == OO_Call) { |
| 201 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 202 | } else if (Kind == OO_Subscript) { |
| 203 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 204 | } else if (getNumArgs() == 1) { |
| 205 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 206 | } else if (getNumArgs() == 2) { |
| 207 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 208 | getArg(1)->getSourceRange().getEnd()); |
| 209 | } else { |
| 210 | return SourceRange(); |
| 211 | } |
| 212 | } |
| 213 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 214 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() { |
| 215 | if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 216 | return MemExpr->getBase(); |
| 217 | |
| 218 | // FIXME: Will eventually need to cope with member pointers. |
| 219 | return 0; |
| 220 | } |
| 221 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 222 | //===----------------------------------------------------------------------===// |
| 223 | // Named casts |
| 224 | //===----------------------------------------------------------------------===// |
| 225 | |
| 226 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 227 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 228 | /// "const_cast". The returned pointer must not be freed. |
| 229 | const char *CXXNamedCastExpr::getCastName() const { |
| 230 | switch (getStmtClass()) { |
| 231 | case CXXStaticCastExprClass: return "static_cast"; |
| 232 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 233 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 234 | case CXXConstCastExprClass: return "const_cast"; |
| 235 | default: return "<invalid cast>"; |
| 236 | } |
| 237 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 238 | |
Anders Carlsson | c1ce477 | 2009-05-30 19:54:15 +0000 | [diff] [blame] | 239 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 240 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 241 | return new (C) CXXTemporary(Destructor); |
| 242 | } |
| 243 | |
| 244 | void CXXTemporary::Destroy(ASTContext &C) { |
| 245 | this->~CXXTemporary(); |
| 246 | C.Deallocate(this); |
Anders Carlsson | c1ce477 | 2009-05-30 19:54:15 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 249 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
| 250 | CXXTemporary *Temp, |
| 251 | Expr* SubExpr) { |
| 252 | assert(SubExpr->getType()->isRecordType() && |
| 253 | "Expression bound to a temporary must have record type!"); |
| 254 | |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 255 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 258 | void CXXBindTemporaryExpr::Destroy(ASTContext &C) { |
| 259 | Temp->Destroy(C); |
| 260 | this->~CXXBindTemporaryExpr(); |
| 261 | C.Deallocate(this); |
| 262 | } |
| 263 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 264 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 265 | CXXConstructorDecl *Cons, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 266 | QualType writtenTy, |
| 267 | SourceLocation tyBeginLoc, |
| 268 | Expr **Args, |
| 269 | unsigned NumArgs, |
| 270 | SourceLocation rParenLoc) |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 271 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, Cons, |
Anders Carlsson | 524fa13 | 2009-04-24 17:34:38 +0000 | [diff] [blame] | 272 | false, Args, NumArgs), |
| 273 | TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) { |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 274 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 275 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 276 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
| 277 | CXXConstructorDecl *D, bool Elidable, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 278 | Expr **Args, unsigned NumArgs) { |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 279 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, D, Elidable, |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 280 | Args, NumArgs); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 283 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
| 284 | CXXConstructorDecl *D, bool elidable, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 285 | Expr **args, unsigned numargs) |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 286 | : Expr(SC, T, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 287 | T->isDependentType(), |
| 288 | (T->isDependentType() || |
| 289 | CallExpr::hasAnyValueDependentArguments(args, numargs))), |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 290 | Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) { |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 291 | if (NumArgs > 0) { |
| 292 | Args = new (C) Stmt*[NumArgs]; |
| 293 | for (unsigned i = 0; i < NumArgs; ++i) |
| 294 | Args[i] = args[i]; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | void CXXConstructExpr::Destroy(ASTContext &C) { |
| 299 | DestroyChildren(C); |
| 300 | if (Args) |
| 301 | C.Deallocate(Args); |
| 302 | this->~CXXConstructExpr(); |
| 303 | C.Deallocate(this); |
| 304 | } |
| 305 | |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 306 | CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr, |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 307 | CXXTemporary **temps, |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 308 | unsigned numtemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame^] | 309 | bool shoulddestroytemps) |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 310 | : Expr(CXXExprWithTemporariesClass, subexpr->getType(), |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 311 | subexpr->isTypeDependent(), subexpr->isValueDependent()), |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame^] | 312 | SubExpr(subexpr), Temps(0), NumTemps(numtemps), |
| 313 | ShouldDestroyTemps(shoulddestroytemps) { |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 314 | if (NumTemps > 0) { |
| 315 | Temps = new CXXTemporary*[NumTemps]; |
| 316 | for (unsigned i = 0; i < NumTemps; ++i) |
| 317 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 321 | CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, |
| 322 | Expr *SubExpr, |
| 323 | CXXTemporary **Temps, |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 324 | unsigned NumTemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame^] | 325 | bool ShouldDestroyTemps){ |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 326 | return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame^] | 327 | ShouldDestroyTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void CXXExprWithTemporaries::Destroy(ASTContext &C) { |
| 331 | DestroyChildren(C); |
| 332 | this->~CXXExprWithTemporaries(); |
| 333 | C.Deallocate(this); |
| 334 | } |
| 335 | |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 336 | CXXExprWithTemporaries::~CXXExprWithTemporaries() { |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 337 | delete[] Temps; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 340 | // CXXBindTemporaryExpr |
| 341 | Stmt::child_iterator CXXBindTemporaryExpr::child_begin() { |
| 342 | return &SubExpr; |
| 343 | } |
| 344 | |
| 345 | Stmt::child_iterator CXXBindTemporaryExpr::child_end() { |
| 346 | return &SubExpr + 1; |
| 347 | } |
| 348 | |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 349 | // CXXConstructExpr |
| 350 | Stmt::child_iterator CXXConstructExpr::child_begin() { |
| 351 | return &Args[0]; |
| 352 | } |
| 353 | Stmt::child_iterator CXXConstructExpr::child_end() { |
| 354 | return &Args[0]+NumArgs; |
| 355 | } |
| 356 | |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 357 | // CXXExprWithTemporaries |
| 358 | Stmt::child_iterator CXXExprWithTemporaries::child_begin() { |
| 359 | return &SubExpr; |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 360 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 361 | |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 362 | Stmt::child_iterator CXXExprWithTemporaries::child_end() { |
| 363 | return &SubExpr + 1; |
| 364 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 365 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 366 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr( |
| 367 | SourceLocation TyBeginLoc, |
| 368 | QualType T, |
| 369 | SourceLocation LParenLoc, |
| 370 | Expr **Args, |
| 371 | unsigned NumArgs, |
| 372 | SourceLocation RParenLoc) |
| 373 | : Expr(CXXUnresolvedConstructExprClass, T.getNonReferenceType(), |
| 374 | T->isDependentType(), true), |
| 375 | TyBeginLoc(TyBeginLoc), |
| 376 | Type(T), |
| 377 | LParenLoc(LParenLoc), |
| 378 | RParenLoc(RParenLoc), |
| 379 | NumArgs(NumArgs) { |
| 380 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
| 381 | memcpy(StoredArgs, Args, sizeof(Expr *) * NumArgs); |
| 382 | } |
| 383 | |
| 384 | CXXUnresolvedConstructExpr * |
| 385 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
| 386 | SourceLocation TyBegin, |
| 387 | QualType T, |
| 388 | SourceLocation LParenLoc, |
| 389 | Expr **Args, |
| 390 | unsigned NumArgs, |
| 391 | SourceLocation RParenLoc) { |
| 392 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 393 | sizeof(Expr *) * NumArgs); |
| 394 | return new (Mem) CXXUnresolvedConstructExpr(TyBegin, T, LParenLoc, |
| 395 | Args, NumArgs, RParenLoc); |
| 396 | } |
| 397 | |
| 398 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_begin() { |
| 399 | return child_iterator(reinterpret_cast<Stmt **>(this + 1)); |
| 400 | } |
| 401 | |
| 402 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_end() { |
| 403 | return child_iterator(reinterpret_cast<Stmt **>(this + 1) + NumArgs); |
| 404 | } |
Sebastian Redl | 8b0b475 | 2009-05-16 18:50:46 +0000 | [diff] [blame] | 405 | |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 406 | Stmt::child_iterator CXXUnresolvedMemberExpr::child_begin() { |
| 407 | return child_iterator(&Base); |
| 408 | } |
| 409 | |
| 410 | Stmt::child_iterator CXXUnresolvedMemberExpr::child_end() { |
| 411 | return child_iterator(&Base + 1); |
| 412 | } |
| 413 | |
Sebastian Redl | 8b0b475 | 2009-05-16 18:50:46 +0000 | [diff] [blame] | 414 | //===----------------------------------------------------------------------===// |
| 415 | // Cloners |
| 416 | //===----------------------------------------------------------------------===// |
| 417 | |
| 418 | CXXBoolLiteralExpr* CXXBoolLiteralExpr::Clone(ASTContext &C) const { |
| 419 | return new (C) CXXBoolLiteralExpr(Value, getType(), Loc); |
| 420 | } |
| 421 | |
| 422 | CXXNullPtrLiteralExpr* CXXNullPtrLiteralExpr::Clone(ASTContext &C) const { |
| 423 | return new (C) CXXNullPtrLiteralExpr(getType(), Loc); |
| 424 | } |
Douglas Gregor | d94546a | 2009-05-20 21:38:11 +0000 | [diff] [blame] | 425 | |
| 426 | CXXZeroInitValueExpr* CXXZeroInitValueExpr::Clone(ASTContext &C) const { |
| 427 | return new (C) CXXZeroInitValueExpr(getType(), TyBeginLoc, RParenLoc); |
| 428 | } |