Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 1 | //===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the subclesses of Expr class declared in ExprCXX.h |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 14 | #include "clang/Basic/IdentifierTable.h" |
| 15 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprCXX.h" |
| 18 | using namespace clang; |
| 19 | |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | // Child Iterators for iterating over subexpressions/substatements |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 24 | // CXXTypeidExpr - has child iterators if the operand is an expression |
| 25 | Stmt::child_iterator CXXTypeidExpr::child_begin() { |
Sebastian Redl | d457589 | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 26 | return isTypeOperand() ? child_iterator() : &Operand.Ex; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 27 | } |
| 28 | Stmt::child_iterator CXXTypeidExpr::child_end() { |
Sebastian Redl | d457589 | 2008-12-03 23:17:54 +0000 | [diff] [blame] | 29 | return isTypeOperand() ? child_iterator() : &Operand.Ex+1; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 30 | } |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 31 | |
Ted Kremenek | a758d09 | 2007-08-24 20:21:10 +0000 | [diff] [blame] | 32 | // CXXBoolLiteralExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | Stmt::child_iterator CXXBoolLiteralExpr::child_begin() { |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 34 | return child_iterator(); |
| 35 | } |
| 36 | Stmt::child_iterator CXXBoolLiteralExpr::child_end() { |
| 37 | return child_iterator(); |
| 38 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 39 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 40 | // CXXNullPtrLiteralExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | Stmt::child_iterator CXXNullPtrLiteralExpr::child_begin() { |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 42 | return child_iterator(); |
| 43 | } |
| 44 | Stmt::child_iterator CXXNullPtrLiteralExpr::child_end() { |
| 45 | return child_iterator(); |
| 46 | } |
| 47 | |
Douglas Gregor | 796da18 | 2008-11-04 14:32:21 +0000 | [diff] [blame] | 48 | // CXXThisExpr |
| 49 | Stmt::child_iterator CXXThisExpr::child_begin() { return child_iterator(); } |
| 50 | Stmt::child_iterator CXXThisExpr::child_end() { return child_iterator(); } |
| 51 | |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 52 | // CXXThrowExpr |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 53 | Stmt::child_iterator CXXThrowExpr::child_begin() { return &Op; } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 54 | Stmt::child_iterator CXXThrowExpr::child_end() { |
| 55 | // If Op is 0, we are processing throw; which has no children. |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 56 | return Op ? &Op+1 : &Op; |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 57 | } |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 58 | |
| 59 | // CXXDefaultArgExpr |
| 60 | Stmt::child_iterator CXXDefaultArgExpr::child_begin() { |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 61 | return child_iterator(); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 62 | } |
| 63 | Stmt::child_iterator CXXDefaultArgExpr::child_end() { |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 64 | return child_iterator(); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 65 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 66 | |
| 67 | // CXXZeroInitValueExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | Stmt::child_iterator CXXZeroInitValueExpr::child_begin() { |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 69 | return child_iterator(); |
| 70 | } |
| 71 | Stmt::child_iterator CXXZeroInitValueExpr::child_end() { |
| 72 | return child_iterator(); |
| 73 | } |
Argyrios Kyrtzidis | 9e922b1 | 2008-09-09 23:47:53 +0000 | [diff] [blame] | 74 | |
| 75 | // CXXConditionDeclExpr |
| 76 | Stmt::child_iterator CXXConditionDeclExpr::child_begin() { |
| 77 | return getVarDecl(); |
| 78 | } |
| 79 | Stmt::child_iterator CXXConditionDeclExpr::child_end() { |
| 80 | return child_iterator(); |
| 81 | } |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 82 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 83 | // CXXNewExpr |
| 84 | CXXNewExpr::CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, |
| 85 | Expr **placementArgs, unsigned numPlaceArgs, |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 86 | bool parenTypeId, Expr *arraySize, |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 87 | CXXConstructorDecl *constructor, bool initializer, |
| 88 | Expr **constructorArgs, unsigned numConsArgs, |
| 89 | FunctionDecl *operatorDelete, QualType ty, |
| 90 | SourceLocation startLoc, SourceLocation endLoc) |
Sebastian Redl | 2850784 | 2009-02-26 14:39:58 +0000 | [diff] [blame] | 91 | : Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()), |
| 92 | GlobalNew(globalNew), ParenTypeId(parenTypeId), |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 93 | Initializer(initializer), Array(arraySize), NumPlacementArgs(numPlaceArgs), |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 94 | NumConstructorArgs(numConsArgs), OperatorNew(operatorNew), |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 95 | OperatorDelete(operatorDelete), Constructor(constructor), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | StartLoc(startLoc), EndLoc(endLoc) { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 97 | unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 98 | SubExprs = new Stmt*[TotalSize]; |
| 99 | unsigned i = 0; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 100 | if (Array) |
| 101 | SubExprs[i++] = arraySize; |
| 102 | for (unsigned j = 0; j < NumPlacementArgs; ++j) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 103 | SubExprs[i++] = placementArgs[j]; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 104 | for (unsigned j = 0; j < NumConstructorArgs; ++j) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 105 | SubExprs[i++] = constructorArgs[j]; |
| 106 | assert(i == TotalSize); |
| 107 | } |
| 108 | |
| 109 | Stmt::child_iterator CXXNewExpr::child_begin() { return &SubExprs[0]; } |
| 110 | Stmt::child_iterator CXXNewExpr::child_end() { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 111 | return &SubExprs[0] + Array + getNumPlacementArgs() + getNumConstructorArgs(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | // CXXDeleteExpr |
| 115 | Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; } |
| 116 | Stmt::child_iterator CXXDeleteExpr::child_end() { return &Argument+1; } |
| 117 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 118 | // CXXPseudoDestructorExpr |
| 119 | Stmt::child_iterator CXXPseudoDestructorExpr::child_begin() { return &Base; } |
| 120 | Stmt::child_iterator CXXPseudoDestructorExpr::child_end() { |
| 121 | return &Base + 1; |
| 122 | } |
| 123 | |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 124 | // UnresolvedFunctionNameExpr |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | Stmt::child_iterator UnresolvedFunctionNameExpr::child_begin() { |
| 126 | return child_iterator(); |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 127 | } |
Douglas Gregor | 1733001 | 2009-02-04 15:01:18 +0000 | [diff] [blame] | 128 | Stmt::child_iterator UnresolvedFunctionNameExpr::child_end() { |
Douglas Gregor | 5c37de7 | 2008-12-06 00:22:45 +0000 | [diff] [blame] | 129 | return child_iterator(); |
| 130 | } |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 131 | // UnaryTypeTraitExpr |
| 132 | Stmt::child_iterator UnaryTypeTraitExpr::child_begin() { |
| 133 | return child_iterator(); |
| 134 | } |
| 135 | Stmt::child_iterator UnaryTypeTraitExpr::child_end() { |
| 136 | return child_iterator(); |
| 137 | } |
| 138 | |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 139 | // UnresolvedDeclRefExpr |
| 140 | StmtIterator UnresolvedDeclRefExpr::child_begin() { |
| 141 | return child_iterator(); |
| 142 | } |
| 143 | |
| 144 | StmtIterator UnresolvedDeclRefExpr::child_end() { |
| 145 | return child_iterator(); |
| 146 | } |
| 147 | |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 148 | TemplateIdRefExpr::TemplateIdRefExpr(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 150 | SourceRange QualifierRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | TemplateName Template, |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 152 | SourceLocation TemplateNameLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | SourceLocation LAngleLoc, |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 154 | const TemplateArgument *TemplateArgs, |
| 155 | unsigned NumTemplateArgs, |
| 156 | SourceLocation RAngleLoc) |
| 157 | : Expr(TemplateIdRefExprClass, T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | (Template.isDependent() || |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 159 | TemplateSpecializationType::anyDependentTemplateArguments( |
| 160 | TemplateArgs, NumTemplateArgs)), |
| 161 | (Template.isDependent() || |
| 162 | TemplateSpecializationType::anyDependentTemplateArguments( |
| 163 | TemplateArgs, NumTemplateArgs))), |
| 164 | Qualifier(Qualifier), QualifierRange(QualifierRange), Template(Template), |
| 165 | TemplateNameLoc(TemplateNameLoc), LAngleLoc(LAngleLoc), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | RAngleLoc(RAngleLoc), NumTemplateArgs(NumTemplateArgs) { |
| 167 | TemplateArgument *StoredTemplateArgs |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 168 | = reinterpret_cast<TemplateArgument *> (this+1); |
| 169 | for (unsigned I = 0; I != NumTemplateArgs; ++I) |
| 170 | new (StoredTemplateArgs + I) TemplateArgument(TemplateArgs[I]); |
| 171 | } |
| 172 | |
| 173 | TemplateIdRefExpr * |
| 174 | TemplateIdRefExpr::Create(ASTContext &Context, QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 176 | SourceRange QualifierRange, |
| 177 | TemplateName Template, SourceLocation TemplateNameLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | SourceLocation LAngleLoc, |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 179 | const TemplateArgument *TemplateArgs, |
| 180 | unsigned NumTemplateArgs, SourceLocation RAngleLoc) { |
| 181 | void *Mem = Context.Allocate(sizeof(TemplateIdRefExpr) + |
| 182 | sizeof(TemplateArgument) * NumTemplateArgs); |
| 183 | return new (Mem) TemplateIdRefExpr(T, Qualifier, QualifierRange, Template, |
| 184 | TemplateNameLoc, LAngleLoc, TemplateArgs, |
| 185 | NumTemplateArgs, RAngleLoc); |
| 186 | } |
| 187 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 188 | void TemplateIdRefExpr::DoDestroy(ASTContext &Context) { |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 189 | const TemplateArgument *TemplateArgs = getTemplateArgs(); |
| 190 | for (unsigned I = 0; I != NumTemplateArgs; ++I) |
| 191 | if (Expr *E = TemplateArgs[I].getAsExpr()) |
| 192 | E->Destroy(Context); |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 193 | this->~TemplateIdRefExpr(); |
| 194 | Context.Deallocate(this); |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | Stmt::child_iterator TemplateIdRefExpr::child_begin() { |
| 198 | // FIXME: Walk the expressions in the template arguments (?) |
| 199 | return Stmt::child_iterator(); |
| 200 | } |
| 201 | |
| 202 | Stmt::child_iterator TemplateIdRefExpr::child_end() { |
| 203 | // FIXME: Walk the expressions in the template arguments (?) |
| 204 | return Stmt::child_iterator(); |
| 205 | } |
| 206 | |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 207 | bool UnaryTypeTraitExpr::EvaluateTrait(ASTContext& C) const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 208 | switch(UTT) { |
| 209 | default: assert(false && "Unknown type trait or not implemented"); |
| 210 | case UTT_IsPOD: return QueriedType->isPODType(); |
| 211 | case UTT_IsClass: // Fallthrough |
| 212 | case UTT_IsUnion: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 213 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 214 | bool Union = Record->getDecl()->isUnion(); |
| 215 | return UTT == UTT_IsUnion ? Union : !Union; |
| 216 | } |
| 217 | return false; |
| 218 | case UTT_IsEnum: return QueriedType->isEnumeralType(); |
| 219 | case UTT_IsPolymorphic: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 220 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 221 | // Type traits are only parsed in C++, so we've got CXXRecords. |
| 222 | return cast<CXXRecordDecl>(Record->getDecl())->isPolymorphic(); |
| 223 | } |
| 224 | return false; |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 225 | case UTT_IsAbstract: |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 226 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 227 | return cast<CXXRecordDecl>(RT->getDecl())->isAbstract(); |
| 228 | return false; |
Eli Friedman | 1d954f6 | 2009-08-15 21:55:26 +0000 | [diff] [blame] | 229 | case UTT_IsEmpty: |
| 230 | if (const RecordType *Record = QueriedType->getAs<RecordType>()) { |
| 231 | return !Record->getDecl()->isUnion() |
| 232 | && cast<CXXRecordDecl>(Record->getDecl())->isEmpty(); |
| 233 | } |
| 234 | return false; |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 235 | case UTT_HasTrivialConstructor: |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 236 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 237 | // If __is_pod (type) is true then the trait is true, else if type is |
| 238 | // a cv class or union type (or array thereof) with a trivial default |
| 239 | // constructor ([class.ctor]) then the trait is true, else it is false. |
| 240 | if (QueriedType->isPODType()) |
| 241 | return true; |
| 242 | if (const RecordType *RT = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 243 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 244 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialConstructor(); |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 245 | return false; |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 246 | case UTT_HasTrivialCopy: |
| 247 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 248 | // If __is_pod (type) is true or type is a reference type then |
| 249 | // the trait is true, else if type is a cv class or union type |
| 250 | // with a trivial copy constructor ([class.copy]) then the trait |
| 251 | // is true, else it is false. |
| 252 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 253 | return true; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 254 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 255 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialCopyConstructor(); |
| 256 | return false; |
| 257 | case UTT_HasTrivialAssign: |
| 258 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 259 | // If type is const qualified or is a reference type then the |
| 260 | // trait is false. Otherwise if __is_pod (type) is true then the |
| 261 | // trait is true, else if type is a cv class or union type with |
| 262 | // a trivial copy assignment ([class.copy]) then the trait is |
| 263 | // true, else it is false. |
| 264 | // Note: the const and reference restrictions are interesting, |
| 265 | // given that const and reference members don't prevent a class |
| 266 | // from having a trivial copy assignment operator (but do cause |
| 267 | // errors if the copy assignment operator is actually used, q.v. |
| 268 | // [class.copy]p12). |
| 269 | |
| 270 | if (C.getBaseElementType(QueriedType).isConstQualified()) |
| 271 | return false; |
| 272 | if (QueriedType->isPODType()) |
| 273 | return true; |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 274 | if (const RecordType *RT = QueriedType->getAs<RecordType>()) |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 275 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialCopyAssignment(); |
| 276 | return false; |
| 277 | case UTT_HasTrivialDestructor: |
| 278 | // http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html: |
| 279 | // If __is_pod (type) is true or type is a reference type |
| 280 | // then the trait is true, else if type is a cv class or union |
| 281 | // type (or array thereof) with a trivial destructor |
| 282 | // ([class.dtor]) then the trait is true, else it is |
| 283 | // false. |
| 284 | if (QueriedType->isPODType() || QueriedType->isReferenceType()) |
| 285 | return true; |
| 286 | if (const RecordType *RT = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 287 | C.getBaseElementType(QueriedType)->getAs<RecordType>()) |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 288 | return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialDestructor(); |
| 289 | return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 293 | SourceRange CXXOperatorCallExpr::getSourceRange() const { |
| 294 | OverloadedOperatorKind Kind = getOperator(); |
| 295 | if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { |
| 296 | if (getNumArgs() == 1) |
| 297 | // Prefix operator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | return SourceRange(getOperatorLoc(), |
Douglas Gregor | b460980 | 2008-11-14 16:09:21 +0000 | [diff] [blame] | 299 | getArg(0)->getSourceRange().getEnd()); |
| 300 | else |
| 301 | // Postfix operator |
| 302 | return SourceRange(getArg(0)->getSourceRange().getEnd(), |
| 303 | getOperatorLoc()); |
| 304 | } else if (Kind == OO_Call) { |
| 305 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 306 | } else if (Kind == OO_Subscript) { |
| 307 | return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc()); |
| 308 | } else if (getNumArgs() == 1) { |
| 309 | return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd()); |
| 310 | } else if (getNumArgs() == 2) { |
| 311 | return SourceRange(getArg(0)->getSourceRange().getBegin(), |
| 312 | getArg(1)->getSourceRange().getEnd()); |
| 313 | } else { |
| 314 | return SourceRange(); |
| 315 | } |
| 316 | } |
| 317 | |
Douglas Gregor | 88a3514 | 2008-12-22 05:46:06 +0000 | [diff] [blame] | 318 | Expr *CXXMemberCallExpr::getImplicitObjectArgument() { |
| 319 | if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) |
| 320 | return MemExpr->getBase(); |
| 321 | |
| 322 | // FIXME: Will eventually need to cope with member pointers. |
| 323 | return 0; |
| 324 | } |
| 325 | |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 326 | //===----------------------------------------------------------------------===// |
| 327 | // Named casts |
| 328 | //===----------------------------------------------------------------------===// |
| 329 | |
| 330 | /// getCastName - Get the name of the C++ cast being used, e.g., |
| 331 | /// "static_cast", "dynamic_cast", "reinterpret_cast", or |
| 332 | /// "const_cast". The returned pointer must not be freed. |
| 333 | const char *CXXNamedCastExpr::getCastName() const { |
| 334 | switch (getStmtClass()) { |
| 335 | case CXXStaticCastExprClass: return "static_cast"; |
| 336 | case CXXDynamicCastExprClass: return "dynamic_cast"; |
| 337 | case CXXReinterpretCastExprClass: return "reinterpret_cast"; |
| 338 | case CXXConstCastExprClass: return "const_cast"; |
| 339 | default: return "<invalid cast>"; |
| 340 | } |
| 341 | } |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 342 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | CXXTemporary *CXXTemporary::Create(ASTContext &C, |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 344 | const CXXDestructorDecl *Destructor) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 345 | return new (C) CXXTemporary(Destructor); |
| 346 | } |
| 347 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 348 | void CXXTemporary::Destroy(ASTContext &Ctx) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 349 | this->~CXXTemporary(); |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 350 | Ctx.Deallocate(this); |
Anders Carlsson | c1ce477 | 2009-05-30 19:54:15 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 353 | CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 354 | CXXTemporary *Temp, |
| 355 | Expr* SubExpr) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | assert(SubExpr->getType()->isRecordType() && |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 357 | "Expression bound to a temporary must have record type!"); |
| 358 | |
Anders Carlsson | b859f35 | 2009-05-30 20:34:37 +0000 | [diff] [blame] | 359 | return new (C) CXXBindTemporaryExpr(Temp, SubExpr); |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 362 | void CXXBindTemporaryExpr::DoDestroy(ASTContext &C) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 363 | Temp->Destroy(C); |
| 364 | this->~CXXBindTemporaryExpr(); |
| 365 | C.Deallocate(this); |
| 366 | } |
| 367 | |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 368 | CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, |
Anders Carlsson | 26de549 | 2009-04-24 05:23:13 +0000 | [diff] [blame] | 369 | CXXConstructorDecl *Cons, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 370 | QualType writtenTy, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | SourceLocation tyBeginLoc, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 372 | Expr **Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | unsigned NumArgs, |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 374 | SourceLocation rParenLoc) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, Cons, |
| 376 | false, Args, NumArgs), |
Anders Carlsson | 524fa13 | 2009-04-24 17:34:38 +0000 | [diff] [blame] | 377 | TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) { |
Douglas Gregor | 506ae41 | 2009-01-16 18:33:17 +0000 | [diff] [blame] | 378 | } |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 379 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 381 | CXXConstructorDecl *D, bool Elidable, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 382 | Expr **Args, unsigned NumArgs) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 383 | return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, D, Elidable, |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 384 | Args, NumArgs); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 388 | CXXConstructorDecl *D, bool elidable, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | Expr **args, unsigned numargs) |
Anders Carlsson | bd6734e | 2009-04-24 05:04:04 +0000 | [diff] [blame] | 390 | : Expr(SC, T, |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 391 | T->isDependentType(), |
| 392 | (T->isDependentType() || |
| 393 | CallExpr::hasAnyValueDependentArguments(args, numargs))), |
Anders Carlsson | 8e587a1 | 2009-05-30 20:56:46 +0000 | [diff] [blame] | 394 | Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) { |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame^] | 395 | if (NumArgs) { |
| 396 | Args = new (C) Stmt*[NumArgs]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame^] | 398 | for (unsigned i = 0; i != NumArgs; ++i) { |
| 399 | assert(args[i] && "NULL argument in CXXConstructExpr"); |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 400 | Args[i] = args[i]; |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame^] | 401 | } |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Douglas Gregor | 39da0b8 | 2009-09-09 23:08:42 +0000 | [diff] [blame^] | 405 | CXXConstructExpr::CXXConstructExpr(EmptyShell Empty, ASTContext &C, |
| 406 | unsigned numargs) |
| 407 | : Expr(CXXConstructExprClass, Empty), Args(0), NumArgs(numargs) |
| 408 | { |
| 409 | if (NumArgs) |
| 410 | Args = new (C) Stmt*[NumArgs]; |
| 411 | } |
| 412 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 413 | void CXXConstructExpr::DoDestroy(ASTContext &C) { |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 414 | DestroyChildren(C); |
| 415 | if (Args) |
| 416 | C.Deallocate(Args); |
| 417 | this->~CXXConstructExpr(); |
| 418 | C.Deallocate(this); |
| 419 | } |
| 420 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr, |
| 422 | CXXTemporary **temps, |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 423 | unsigned numtemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 424 | bool shoulddestroytemps) |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 425 | : Expr(CXXExprWithTemporariesClass, subexpr->getType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | subexpr->isTypeDependent(), subexpr->isValueDependent()), |
| 427 | SubExpr(subexpr), Temps(0), NumTemps(numtemps), |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 428 | ShouldDestroyTemps(shoulddestroytemps) { |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 429 | if (NumTemps > 0) { |
| 430 | Temps = new CXXTemporary*[NumTemps]; |
| 431 | for (unsigned i = 0; i < NumTemps; ++i) |
| 432 | Temps[i] = temps[i]; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 436 | CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C, |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 437 | Expr *SubExpr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | CXXTemporary **Temps, |
Anders Carlsson | 99ba36d | 2009-06-05 15:38:08 +0000 | [diff] [blame] | 439 | unsigned NumTemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 440 | bool ShouldDestroyTemps){ |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps, |
Anders Carlsson | f54741e | 2009-06-16 03:37:31 +0000 | [diff] [blame] | 442 | ShouldDestroyTemps); |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Douglas Gregor | 42602bb | 2009-08-07 06:08:38 +0000 | [diff] [blame] | 445 | void CXXExprWithTemporaries::DoDestroy(ASTContext &C) { |
Anders Carlsson | 88eaf07 | 2009-05-30 22:38:53 +0000 | [diff] [blame] | 446 | DestroyChildren(C); |
| 447 | this->~CXXExprWithTemporaries(); |
| 448 | C.Deallocate(this); |
| 449 | } |
| 450 | |
Anders Carlsson | 2d44e8a | 2009-05-01 22:18:43 +0000 | [diff] [blame] | 451 | CXXExprWithTemporaries::~CXXExprWithTemporaries() { |
Anders Carlsson | ff6b3d6 | 2009-05-30 21:05:25 +0000 | [diff] [blame] | 452 | delete[] Temps; |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 455 | // CXXBindTemporaryExpr |
| 456 | Stmt::child_iterator CXXBindTemporaryExpr::child_begin() { |
| 457 | return &SubExpr; |
| 458 | } |
| 459 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | Stmt::child_iterator CXXBindTemporaryExpr::child_end() { |
Anders Carlsson | fceb0a8 | 2009-05-30 20:03:25 +0000 | [diff] [blame] | 461 | return &SubExpr + 1; |
| 462 | } |
| 463 | |
Anders Carlsson | e349bea | 2009-04-23 02:32:43 +0000 | [diff] [blame] | 464 | // CXXConstructExpr |
| 465 | Stmt::child_iterator CXXConstructExpr::child_begin() { |
| 466 | return &Args[0]; |
| 467 | } |
| 468 | Stmt::child_iterator CXXConstructExpr::child_end() { |
| 469 | return &Args[0]+NumArgs; |
| 470 | } |
| 471 | |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 472 | // CXXExprWithTemporaries |
| 473 | Stmt::child_iterator CXXExprWithTemporaries::child_begin() { |
| 474 | return &SubExpr; |
Anders Carlsson | 19d28a6 | 2009-04-21 02:22:11 +0000 | [diff] [blame] | 475 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 476 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | Stmt::child_iterator CXXExprWithTemporaries::child_end() { |
Anders Carlsson | 55674ac | 2009-05-01 22:21:22 +0000 | [diff] [blame] | 478 | return &SubExpr + 1; |
| 479 | } |
Anders Carlsson | 02bbfa3 | 2009-04-24 22:47:04 +0000 | [diff] [blame] | 480 | |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 481 | CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr( |
| 482 | SourceLocation TyBeginLoc, |
| 483 | QualType T, |
| 484 | SourceLocation LParenLoc, |
| 485 | Expr **Args, |
| 486 | unsigned NumArgs, |
| 487 | SourceLocation RParenLoc) |
| 488 | : Expr(CXXUnresolvedConstructExprClass, T.getNonReferenceType(), |
| 489 | T->isDependentType(), true), |
| 490 | TyBeginLoc(TyBeginLoc), |
| 491 | Type(T), |
| 492 | LParenLoc(LParenLoc), |
| 493 | RParenLoc(RParenLoc), |
| 494 | NumArgs(NumArgs) { |
| 495 | Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); |
| 496 | memcpy(StoredArgs, Args, sizeof(Expr *) * NumArgs); |
| 497 | } |
| 498 | |
| 499 | CXXUnresolvedConstructExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | CXXUnresolvedConstructExpr::Create(ASTContext &C, |
Douglas Gregor | d81e6ca | 2009-05-20 18:46:25 +0000 | [diff] [blame] | 501 | SourceLocation TyBegin, |
| 502 | QualType T, |
| 503 | SourceLocation LParenLoc, |
| 504 | Expr **Args, |
| 505 | unsigned NumArgs, |
| 506 | SourceLocation RParenLoc) { |
| 507 | void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + |
| 508 | sizeof(Expr *) * NumArgs); |
| 509 | return new (Mem) CXXUnresolvedConstructExpr(TyBegin, T, LParenLoc, |
| 510 | Args, NumArgs, RParenLoc); |
| 511 | } |
| 512 | |
| 513 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_begin() { |
| 514 | return child_iterator(reinterpret_cast<Stmt **>(this + 1)); |
| 515 | } |
| 516 | |
| 517 | Stmt::child_iterator CXXUnresolvedConstructExpr::child_end() { |
| 518 | return child_iterator(reinterpret_cast<Stmt **>(this + 1) + NumArgs); |
| 519 | } |
Sebastian Redl | 8b0b475 | 2009-05-16 18:50:46 +0000 | [diff] [blame] | 520 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | CXXUnresolvedMemberExpr::CXXUnresolvedMemberExpr(ASTContext &C, |
| 522 | Expr *Base, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 523 | SourceLocation OperatorLoc, |
| 524 | NestedNameSpecifier *Qualifier, |
| 525 | SourceRange QualifierRange, |
| 526 | NamedDecl *FirstQualifierFoundInScope, |
| 527 | DeclarationName Member, |
| 528 | SourceLocation MemberLoc, |
| 529 | bool HasExplicitTemplateArgs, |
| 530 | SourceLocation LAngleLoc, |
| 531 | const TemplateArgument *TemplateArgs, |
| 532 | unsigned NumTemplateArgs, |
| 533 | SourceLocation RAngleLoc) |
| 534 | : Expr(CXXUnresolvedMemberExprClass, C.DependentTy, true, true), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | Base(Base), IsArrow(IsArrow), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 536 | HasExplicitTemplateArgumentList(HasExplicitTemplateArgs), |
| 537 | OperatorLoc(OperatorLoc), |
| 538 | Qualifier(Qualifier), QualifierRange(QualifierRange), |
| 539 | FirstQualifierFoundInScope(FirstQualifierFoundInScope), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | Member(Member), MemberLoc(MemberLoc) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 541 | if (HasExplicitTemplateArgumentList) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | ExplicitTemplateArgumentList *ETemplateArgs |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 543 | = getExplicitTemplateArgumentList(); |
| 544 | ETemplateArgs->LAngleLoc = LAngleLoc; |
| 545 | ETemplateArgs->RAngleLoc = RAngleLoc; |
| 546 | ETemplateArgs->NumTemplateArgs = NumTemplateArgs; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 547 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 548 | TemplateArgument *SavedTemplateArgs = ETemplateArgs->getTemplateArgs(); |
| 549 | for (unsigned I = 0; I < NumTemplateArgs; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | new (SavedTemplateArgs + I) TemplateArgument(TemplateArgs[I]); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
| 554 | CXXUnresolvedMemberExpr * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | CXXUnresolvedMemberExpr::Create(ASTContext &C, |
| 556 | Expr *Base, bool IsArrow, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 557 | SourceLocation OperatorLoc, |
| 558 | NestedNameSpecifier *Qualifier, |
| 559 | SourceRange QualifierRange, |
| 560 | NamedDecl *FirstQualifierFoundInScope, |
| 561 | DeclarationName Member, |
| 562 | SourceLocation MemberLoc, |
| 563 | bool HasExplicitTemplateArgs, |
| 564 | SourceLocation LAngleLoc, |
| 565 | const TemplateArgument *TemplateArgs, |
| 566 | unsigned NumTemplateArgs, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | SourceLocation RAngleLoc) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 568 | if (!HasExplicitTemplateArgs) |
| 569 | return new (C) CXXUnresolvedMemberExpr(C, Base, IsArrow, OperatorLoc, |
| 570 | Qualifier, QualifierRange, |
| 571 | FirstQualifierFoundInScope, |
| 572 | Member, MemberLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 574 | void *Mem = C.Allocate(sizeof(CXXUnresolvedMemberExpr) + |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 575 | sizeof(ExplicitTemplateArgumentList) + |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 576 | sizeof(TemplateArgument) * NumTemplateArgs, |
| 577 | llvm::alignof<CXXUnresolvedMemberExpr>()); |
| 578 | return new (Mem) CXXUnresolvedMemberExpr(C, Base, IsArrow, OperatorLoc, |
| 579 | Qualifier, QualifierRange, |
| 580 | FirstQualifierFoundInScope, |
| 581 | Member, |
| 582 | MemberLoc, |
| 583 | HasExplicitTemplateArgs, |
| 584 | LAngleLoc, |
| 585 | TemplateArgs, |
| 586 | NumTemplateArgs, |
| 587 | RAngleLoc); |
| 588 | } |
| 589 | |
Douglas Gregor | 1c0ca59 | 2009-05-22 21:13:27 +0000 | [diff] [blame] | 590 | Stmt::child_iterator CXXUnresolvedMemberExpr::child_begin() { |
| 591 | return child_iterator(&Base); |
| 592 | } |
| 593 | |
| 594 | Stmt::child_iterator CXXUnresolvedMemberExpr::child_end() { |
| 595 | return child_iterator(&Base + 1); |
| 596 | } |