Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1 | //===--- DeclCXX.cpp - C++ Declaration AST Node Implementation ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ related Decl classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 18 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // Decl Allocation/Deallocation Method Implementations |
| 24 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 25 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 26 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 27 | SourceLocation L, IdentifierInfo *Id, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 28 | CXXRecordDecl *PrevDecl, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 29 | SourceLocation TKL) |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 30 | : RecordDecl(K, TK, DC, L, Id, PrevDecl, TKL), |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 31 | UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 32 | UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false), |
Eli Friedman | 97c134e | 2009-08-15 22:23:00 +0000 | [diff] [blame] | 33 | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), |
| 34 | Abstract(false), HasTrivialConstructor(true), |
| 35 | HasTrivialCopyConstructor(true), HasTrivialCopyAssignment(true), |
| 36 | HasTrivialDestructor(true), Bases(0), NumBases(0), VBases(0), NumVBases(0), |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 37 | Conversions(DC, DeclarationName()), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 38 | TemplateOrInstantiation() { } |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 39 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 40 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
| 41 | SourceLocation L, IdentifierInfo *Id, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 42 | SourceLocation TKL, |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 43 | CXXRecordDecl* PrevDecl, |
| 44 | bool DelayTypeCreation) { |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 45 | CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id, |
| 46 | PrevDecl, TKL); |
| 47 | |
| 48 | // FIXME: DelayTypeCreation seems like such a hack |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 49 | if (!DelayTypeCreation) |
| 50 | C.getTypeDeclType(R, PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 51 | return R; |
| 52 | } |
| 53 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 54 | CXXRecordDecl::~CXXRecordDecl() { |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void CXXRecordDecl::Destroy(ASTContext &C) { |
| 58 | C.Deallocate(Bases); |
Fariborz Jahanian | 71c6e71 | 2009-07-22 17:41:53 +0000 | [diff] [blame] | 59 | C.Deallocate(VBases); |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 60 | this->RecordDecl::Destroy(C); |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 63 | void |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 64 | CXXRecordDecl::setBases(ASTContext &C, |
| 65 | CXXBaseSpecifier const * const *Bases, |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 66 | unsigned NumBases) { |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 67 | // C++ [dcl.init.aggr]p1: |
| 68 | // An aggregate is an array or a class (clause 9) with [...] |
| 69 | // no base classes [...]. |
| 70 | Aggregate = false; |
| 71 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 72 | if (this->Bases) |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 73 | C.Deallocate(this->Bases); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 74 | |
| 75 | int vbaseCount = 0; |
| 76 | llvm::SmallVector<const CXXBaseSpecifier*, 8> UniqueVbases; |
| 77 | bool hasDirectVirtualBase = false; |
| 78 | |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 79 | this->Bases = new(C) CXXBaseSpecifier [NumBases]; |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 80 | this->NumBases = NumBases; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 81 | for (unsigned i = 0; i < NumBases; ++i) { |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 82 | this->Bases[i] = *Bases[i]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 83 | // Keep track of inherited vbases for this base class. |
| 84 | const CXXBaseSpecifier *Base = Bases[i]; |
| 85 | QualType BaseType = Base->getType(); |
| 86 | // Skip template types. |
| 87 | // FIXME. This means that this list must be rebuilt during template |
| 88 | // instantiation. |
| 89 | if (BaseType->isDependentType()) |
| 90 | continue; |
| 91 | CXXRecordDecl *BaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 92 | = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 93 | if (Base->isVirtual()) |
| 94 | hasDirectVirtualBase = true; |
| 95 | for (CXXRecordDecl::base_class_iterator VBase = |
| 96 | BaseClassDecl->vbases_begin(), |
| 97 | E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { |
| 98 | // Add this vbase to the array of vbases for current class if it is |
| 99 | // not already in the list. |
| 100 | // FIXME. Note that we do a linear search as number of such classes are |
| 101 | // very few. |
| 102 | int i; |
| 103 | for (i = 0; i < vbaseCount; ++i) |
| 104 | if (UniqueVbases[i]->getType() == VBase->getType()) |
| 105 | break; |
| 106 | if (i == vbaseCount) { |
| 107 | UniqueVbases.push_back(VBase); |
| 108 | ++vbaseCount; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | if (hasDirectVirtualBase) { |
| 113 | // Iterate one more time through the direct bases and add the virtual |
| 114 | // base to the list of vritual bases for current class. |
| 115 | for (unsigned i = 0; i < NumBases; ++i) { |
| 116 | const CXXBaseSpecifier *VBase = Bases[i]; |
| 117 | if (!VBase->isVirtual()) |
| 118 | continue; |
Alisdair Meredith | 002b91f | 2009-07-11 14:32:10 +0000 | [diff] [blame] | 119 | int j; |
| 120 | for (j = 0; j < vbaseCount; ++j) |
| 121 | if (UniqueVbases[j]->getType() == VBase->getType()) |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 122 | break; |
Alisdair Meredith | 002b91f | 2009-07-11 14:32:10 +0000 | [diff] [blame] | 123 | if (j == vbaseCount) { |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 124 | UniqueVbases.push_back(VBase); |
| 125 | ++vbaseCount; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | if (vbaseCount > 0) { |
| 130 | // build AST for inhireted, direct or indirect, virtual bases. |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 131 | this->VBases = new (C) CXXBaseSpecifier [vbaseCount]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 132 | this->NumVBases = vbaseCount; |
| 133 | for (int i = 0; i < vbaseCount; i++) { |
| 134 | QualType QT = UniqueVbases[i]->getType(); |
| 135 | CXXRecordDecl *VBaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 136 | = cast<CXXRecordDecl>(QT->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 137 | this->VBases[i] = |
Douglas Gregor | 2aef06d | 2009-07-22 20:55:49 +0000 | [diff] [blame] | 138 | CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true, |
| 139 | VBaseClassDecl->getTagKind() == RecordDecl::TK_class, |
| 140 | UniqueVbases[i]->getAccessSpecifier(), QT); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 141 | } |
| 142 | } |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 145 | bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const { |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 146 | return getCopyConstructor(Context, QualType::Const) != 0; |
| 147 | } |
| 148 | |
| 149 | CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context, |
| 150 | unsigned TypeQuals) const{ |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 151 | QualType ClassType |
| 152 | = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 153 | DeclarationName ConstructorName |
| 154 | = Context.DeclarationNames.getCXXConstructorName( |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 155 | Context.getCanonicalType(ClassType)); |
| 156 | unsigned FoundTQs; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 157 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 158 | for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 159 | Con != ConEnd; ++Con) { |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 160 | if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context, |
| 161 | FoundTQs)) { |
| 162 | if (((TypeQuals & QualType::Const) == (FoundTQs & QualType::Const)) || |
| 163 | (!(TypeQuals & QualType::Const) && (FoundTQs & QualType::Const))) |
| 164 | return cast<CXXConstructorDecl>(*Con); |
| 165 | |
| 166 | } |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 167 | } |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 168 | return 0; |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Fariborz Jahanian | 0270b8a | 2009-08-12 23:34:46 +0000 | [diff] [blame] | 171 | bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context, |
| 172 | const CXXMethodDecl *& MD) const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 173 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 174 | const_cast<CXXRecordDecl*>(this))); |
| 175 | DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 176 | |
| 177 | DeclContext::lookup_const_iterator Op, OpEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 178 | for (llvm::tie(Op, OpEnd) = this->lookup(OpName); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 179 | Op != OpEnd; ++Op) { |
| 180 | // C++ [class.copy]p9: |
| 181 | // A user-declared copy assignment operator is a non-static non-template |
| 182 | // member function of class X with exactly one parameter of type X, X&, |
| 183 | // const X&, volatile X& or const volatile X&. |
| 184 | const CXXMethodDecl* Method = cast<CXXMethodDecl>(*Op); |
| 185 | if (Method->isStatic()) |
| 186 | continue; |
| 187 | // TODO: Skip templates? Or is this implicitly done due to parameter types? |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 188 | const FunctionProtoType *FnType = |
| 189 | Method->getType()->getAsFunctionProtoType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 190 | assert(FnType && "Overloaded operator has no prototype."); |
| 191 | // Don't assert on this; an invalid decl might have been left in the AST. |
| 192 | if (FnType->getNumArgs() != 1 || FnType->isVariadic()) |
| 193 | continue; |
| 194 | bool AcceptsConst = true; |
| 195 | QualType ArgType = FnType->getArgType(0); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 196 | if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 197 | ArgType = Ref->getPointeeType(); |
Douglas Gregor | 2ff4478 | 2009-03-20 20:21:37 +0000 | [diff] [blame] | 198 | // Is it a non-const lvalue reference? |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 199 | if (!ArgType.isConstQualified()) |
| 200 | AcceptsConst = false; |
| 201 | } |
| 202 | if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType) |
| 203 | continue; |
Fariborz Jahanian | 0270b8a | 2009-08-12 23:34:46 +0000 | [diff] [blame] | 204 | MD = Method; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 205 | // We have a single argument of type cv X or cv X&, i.e. we've found the |
| 206 | // copy assignment operator. Return whether it accepts const arguments. |
| 207 | return AcceptsConst; |
| 208 | } |
| 209 | assert(isInvalidDecl() && |
| 210 | "No copy assignment operator declared in valid code."); |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | void |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 215 | CXXRecordDecl::addedConstructor(ASTContext &Context, |
| 216 | CXXConstructorDecl *ConDecl) { |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 217 | assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl"); |
| 218 | // Note that we have a user-declared constructor. |
| 219 | UserDeclaredConstructor = true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 220 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 221 | // C++ [dcl.init.aggr]p1: |
| 222 | // An aggregate is an array or a class (clause 9) with no |
| 223 | // user-declared constructors (12.1) [...]. |
| 224 | Aggregate = false; |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 225 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 226 | // C++ [class]p4: |
| 227 | // A POD-struct is an aggregate class [...] |
| 228 | PlainOldData = false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 229 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 230 | // C++ [class.ctor]p5: |
| 231 | // A constructor is trivial if it is an implicitly-declared default |
| 232 | // constructor. |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 233 | // FIXME: C++0x: don't do this for "= default" default constructors. |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 234 | HasTrivialConstructor = false; |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 235 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 236 | // Note when we have a user-declared copy constructor, which will |
| 237 | // suppress the implicit declaration of a copy constructor. |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 238 | if (ConDecl->isCopyConstructor(Context)) { |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 239 | UserDeclaredCopyConstructor = true; |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 240 | |
| 241 | // C++ [class.copy]p6: |
| 242 | // A copy constructor is trivial if it is implicitly declared. |
| 243 | // FIXME: C++0x: don't do this for "= default" copy constructors. |
| 244 | HasTrivialCopyConstructor = false; |
| 245 | } |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 248 | void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context, |
| 249 | CXXMethodDecl *OpDecl) { |
| 250 | // We're interested specifically in copy assignment operators. |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 251 | const FunctionProtoType *FnType = OpDecl->getType()->getAsFunctionProtoType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 252 | assert(FnType && "Overloaded operator has no proto function type."); |
| 253 | assert(FnType->getNumArgs() == 1 && !FnType->isVariadic()); |
| 254 | QualType ArgType = FnType->getArgType(0); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 255 | if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 256 | ArgType = Ref->getPointeeType(); |
| 257 | |
| 258 | ArgType = ArgType.getUnqualifiedType(); |
| 259 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 260 | const_cast<CXXRecordDecl*>(this))); |
| 261 | |
| 262 | if (ClassType != Context.getCanonicalType(ArgType)) |
| 263 | return; |
| 264 | |
| 265 | // This is a copy assignment operator. |
| 266 | // Suppress the implicit declaration of a copy constructor. |
| 267 | UserDeclaredCopyAssignment = true; |
| 268 | |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 269 | // C++ [class.copy]p11: |
| 270 | // A copy assignment operator is trivial if it is implicitly declared. |
| 271 | // FIXME: C++0x: don't do this for "= default" copy operators. |
| 272 | HasTrivialCopyAssignment = false; |
| 273 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 274 | // C++ [class]p4: |
| 275 | // A POD-struct is an aggregate class that [...] has no user-defined copy |
| 276 | // assignment operator [...]. |
| 277 | PlainOldData = false; |
| 278 | } |
| 279 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 280 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
| 281 | CXXConversionDecl *ConvDecl) { |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 282 | assert(!ConvDecl->getDescribedFunctionTemplate() && |
| 283 | "Conversion function templates should cast to FunctionTemplateDecl."); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 284 | Conversions.addOverload(ConvDecl); |
| 285 | } |
| 286 | |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 287 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
| 288 | FunctionTemplateDecl *ConvDecl) { |
| 289 | assert(isa<CXXConversionDecl>(ConvDecl->getTemplatedDecl()) && |
| 290 | "Function template is not a conversion function template"); |
| 291 | Conversions.addOverload(ConvDecl); |
| 292 | } |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 293 | |
| 294 | CXXConstructorDecl * |
| 295 | CXXRecordDecl::getDefaultConstructor(ASTContext &Context) { |
| 296 | QualType ClassType = Context.getTypeDeclType(this); |
| 297 | DeclarationName ConstructorName |
| 298 | = Context.DeclarationNames.getCXXConstructorName( |
| 299 | Context.getCanonicalType(ClassType.getUnqualifiedType())); |
| 300 | |
| 301 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 302 | for (llvm::tie(Con, ConEnd) = lookup(ConstructorName); |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 303 | Con != ConEnd; ++Con) { |
| 304 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 305 | if (Constructor->isDefaultConstructor()) |
| 306 | return Constructor; |
| 307 | } |
| 308 | return 0; |
| 309 | } |
| 310 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 311 | const CXXDestructorDecl * |
| 312 | CXXRecordDecl::getDestructor(ASTContext &Context) { |
| 313 | QualType ClassType = Context.getTypeDeclType(this); |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 314 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 315 | DeclarationName Name |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 316 | = Context.DeclarationNames.getCXXDestructorName( |
| 317 | Context.getCanonicalType(ClassType)); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 318 | |
| 319 | DeclContext::lookup_iterator I, E; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 320 | llvm::tie(I, E) = lookup(Name); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 321 | assert(I != E && "Did not find a destructor!"); |
| 322 | |
| 323 | const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); |
| 324 | assert(++I == E && "Found more than one destructor!"); |
| 325 | |
| 326 | return Dtor; |
| 327 | } |
| 328 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 329 | CXXMethodDecl * |
| 330 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 331 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 332 | QualType T, DeclaratorInfo *DInfo, |
| 333 | bool isStatic, bool isInline) { |
| 334 | return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, DInfo, |
| 335 | isStatic, isInline); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 338 | |
| 339 | typedef llvm::DenseMap<const CXXMethodDecl*, |
| 340 | std::vector<const CXXMethodDecl *> *> |
| 341 | OverriddenMethodsMapTy; |
| 342 | |
Mike Stump | b9871a2 | 2009-08-21 01:45:00 +0000 | [diff] [blame] | 343 | // FIXME: We hate static data. This doesn't survive PCH saving/loading, and |
| 344 | // the vtable building code uses it at CG time. |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 345 | static OverriddenMethodsMapTy *OverriddenMethods = 0; |
| 346 | |
| 347 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
| 348 | // FIXME: The CXXMethodDecl dtor needs to remove and free the entry. |
| 349 | |
| 350 | if (!OverriddenMethods) |
| 351 | OverriddenMethods = new OverriddenMethodsMapTy(); |
| 352 | |
| 353 | std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this]; |
| 354 | if (!Methods) |
| 355 | Methods = new std::vector<const CXXMethodDecl *>; |
| 356 | |
| 357 | Methods->push_back(MD); |
| 358 | } |
| 359 | |
| 360 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
| 361 | if (!OverriddenMethods) |
| 362 | return 0; |
| 363 | |
| 364 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 365 | if (it == OverriddenMethods->end() || it->second->empty()) |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 366 | return 0; |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 367 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 368 | return &(*it->second)[0]; |
| 369 | } |
| 370 | |
| 371 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
| 372 | if (!OverriddenMethods) |
| 373 | return 0; |
| 374 | |
| 375 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 376 | if (it == OverriddenMethods->end() || it->second->empty()) |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 377 | return 0; |
| 378 | |
Daniel Dunbar | 637ec32 | 2009-08-02 01:48:29 +0000 | [diff] [blame] | 379 | return &(*it->second)[0] + it->second->size(); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 382 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 383 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 384 | // If the member function is declared const, the type of this is const X*, |
| 385 | // if the member function is declared volatile, the type of this is |
| 386 | // volatile X*, and if the member function is declared const volatile, |
| 387 | // the type of this is const volatile X*. |
| 388 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 389 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 390 | |
| 391 | QualType ClassTy; |
| 392 | if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate()) |
| 393 | ClassTy = TD->getInjectedClassNameType(C); |
| 394 | else |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 395 | ClassTy = C.getTagDeclType(getParent()); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 396 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 397 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 400 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 401 | CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 402 | CXXConstructorDecl *C, |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 403 | SourceLocation L) |
| 404 | : Args(0), NumArgs(0), IdLoc(L) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 405 | BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr()); |
| 406 | assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer"); |
| 407 | BaseOrMember |= 0x01; |
| 408 | |
| 409 | if (NumArgs > 0) { |
| 410 | this->NumArgs = NumArgs; |
Fariborz Jahanian | 50b8eea | 2009-07-24 17:57:02 +0000 | [diff] [blame] | 411 | // FIXME. Allocation via Context |
| 412 | this->Args = new Stmt*[NumArgs]; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 413 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 414 | this->Args[Idx] = Args[Idx]; |
| 415 | } |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 416 | CtorToCall = C; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 420 | CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 421 | CXXConstructorDecl *C, |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 422 | SourceLocation L) |
| 423 | : Args(0), NumArgs(0), IdLoc(L) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 424 | BaseOrMember = reinterpret_cast<uintptr_t>(Member); |
| 425 | assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer"); |
| 426 | |
| 427 | if (NumArgs > 0) { |
| 428 | this->NumArgs = NumArgs; |
Fariborz Jahanian | 50b8eea | 2009-07-24 17:57:02 +0000 | [diff] [blame] | 429 | this->Args = new Stmt*[NumArgs]; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 430 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 431 | this->Args[Idx] = Args[Idx]; |
| 432 | } |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 433 | CtorToCall = C; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() { |
| 437 | delete [] Args; |
| 438 | } |
| 439 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 440 | CXXConstructorDecl * |
| 441 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 442 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 443 | QualType T, DeclaratorInfo *DInfo, |
| 444 | bool isExplicit, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 445 | bool isInline, bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 446 | assert(N.getNameKind() == DeclarationName::CXXConstructorName && |
| 447 | "Name must refer to a constructor"); |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 448 | return new (C) CXXConstructorDecl(RD, L, N, T, DInfo, isExplicit, isInline, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 449 | isImplicitlyDeclared); |
| 450 | } |
| 451 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 452 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 453 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 454 | // A default constructor for a class X is a constructor of class |
| 455 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 456 | return (getNumParams() == 0) || |
Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame^] | 457 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | bool |
| 461 | CXXConstructorDecl::isCopyConstructor(ASTContext &Context, |
| 462 | unsigned &TypeQuals) const { |
| 463 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 464 | // A non-template constructor for class X is a copy constructor |
| 465 | // if its first parameter is of type X&, const X&, volatile X& or |
| 466 | // const volatile X&, and either there are no other parameters |
| 467 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 468 | if ((getNumParams() < 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 469 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg())) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 470 | return false; |
| 471 | |
| 472 | const ParmVarDecl *Param = getParamDecl(0); |
| 473 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 474 | // Do we have a reference type? Rvalue references don't count. |
| 475 | const LValueReferenceType *ParamRefType = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 476 | Param->getType()->getAs<LValueReferenceType>(); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 477 | if (!ParamRefType) |
| 478 | return false; |
| 479 | |
| 480 | // Is it a reference to our class type? |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 481 | QualType PointeeType |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 482 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 483 | QualType ClassTy = Context.getTagDeclType(getParent()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 484 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 485 | return false; |
| 486 | |
| 487 | // We have a copy constructor. |
| 488 | TypeQuals = PointeeType.getCVRQualifiers(); |
| 489 | return true; |
| 490 | } |
| 491 | |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 492 | bool CXXConstructorDecl::isConvertingConstructor() const { |
| 493 | // C++ [class.conv.ctor]p1: |
| 494 | // A constructor declared without the function-specifier explicit |
| 495 | // that can be called with a single parameter specifies a |
| 496 | // conversion from the type of its first parameter to the type of |
| 497 | // its class. Such a constructor is called a converting |
| 498 | // constructor. |
| 499 | if (isExplicit()) |
| 500 | return false; |
| 501 | |
| 502 | return (getNumParams() == 0 && |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 503 | getType()->getAsFunctionProtoType()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 504 | (getNumParams() == 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 505 | (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 506 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 508 | CXXDestructorDecl * |
| 509 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 510 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 511 | QualType T, bool isInline, |
| 512 | bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 513 | assert(N.getNameKind() == DeclarationName::CXXDestructorName && |
| 514 | "Name must refer to a destructor"); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 515 | return new (C) CXXDestructorDecl(RD, L, N, T, isInline, |
| 516 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 519 | void |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 520 | CXXDestructorDecl::Destroy(ASTContext& C) { |
| 521 | C.Deallocate(BaseOrMemberDestructions); |
| 522 | CXXMethodDecl::Destroy(C); |
| 523 | } |
| 524 | |
| 525 | void |
| 526 | CXXDestructorDecl::computeBaseOrMembersToDestroy(ASTContext &C) { |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 527 | CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(getDeclContext()); |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 528 | llvm::SmallVector<uintptr_t, 32> AllToDestruct; |
| 529 | |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 530 | for (CXXRecordDecl::base_class_iterator VBase = ClassDecl->vbases_begin(), |
| 531 | E = ClassDecl->vbases_end(); VBase != E; ++VBase) { |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 532 | // Skip over virtual bases which have trivial destructors. |
| 533 | CXXRecordDecl *BaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 534 | = cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 535 | if (BaseClassDecl->hasTrivialDestructor()) |
| 536 | continue; |
| 537 | uintptr_t Member = |
Fariborz Jahanian | cf18312 | 2009-07-22 00:42:46 +0000 | [diff] [blame] | 538 | reinterpret_cast<uintptr_t>(VBase->getType().getTypePtr()) | VBASE; |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 539 | AllToDestruct.push_back(Member); |
| 540 | } |
| 541 | for (CXXRecordDecl::base_class_iterator Base = |
| 542 | ClassDecl->bases_begin(), |
| 543 | E = ClassDecl->bases_end(); Base != E; ++Base) { |
| 544 | if (Base->isVirtual()) |
| 545 | continue; |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 546 | // Skip over virtual bases which have trivial destructors. |
| 547 | CXXRecordDecl *BaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 548 | = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 549 | if (BaseClassDecl->hasTrivialDestructor()) |
| 550 | continue; |
| 551 | |
| 552 | uintptr_t Member = |
Fariborz Jahanian | cf18312 | 2009-07-22 00:42:46 +0000 | [diff] [blame] | 553 | reinterpret_cast<uintptr_t>(Base->getType().getTypePtr()) | DRCTNONVBASE; |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 554 | AllToDestruct.push_back(Member); |
| 555 | } |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 556 | |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 557 | // non-static data members. |
| 558 | for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), |
| 559 | E = ClassDecl->field_end(); Field != E; ++Field) { |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 560 | QualType FieldType = C.getBaseElementType((*Field)->getType()); |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 561 | |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 562 | if (const RecordType* RT = FieldType->getAs<RecordType>()) { |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 563 | // Skip over virtual bases which have trivial destructors. |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 564 | CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl()); |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 565 | if (BaseClassDecl->hasTrivialDestructor()) |
| 566 | continue; |
| 567 | uintptr_t Member = reinterpret_cast<uintptr_t>(*Field); |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 568 | AllToDestruct.push_back(Member); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | unsigned NumDestructions = AllToDestruct.size(); |
| 573 | if (NumDestructions > 0) { |
| 574 | NumBaseOrMemberDestructions = NumDestructions; |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 575 | BaseOrMemberDestructions = new (C) uintptr_t [NumDestructions]; |
Fariborz Jahanian | 560de45 | 2009-07-15 22:34:08 +0000 | [diff] [blame] | 576 | // Insert in reverse order. |
| 577 | for (int Idx = NumDestructions-1, i=0 ; Idx >= 0; --Idx) |
| 578 | BaseOrMemberDestructions[i++] = AllToDestruct[Idx]; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | void |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 583 | CXXConstructorDecl::setBaseOrMemberInitializers( |
Fariborz Jahanian | 87595e4 | 2009-07-23 23:32:59 +0000 | [diff] [blame] | 584 | ASTContext &C, |
| 585 | CXXBaseOrMemberInitializer **Initializers, |
| 586 | unsigned NumInitializers, |
| 587 | llvm::SmallVectorImpl<CXXBaseSpecifier *>& Bases, |
| 588 | llvm::SmallVectorImpl<FieldDecl *>&Fields) { |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 589 | // We need to build the initializer AST according to order of construction |
| 590 | // and not what user specified in the Initializers list. |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 591 | CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(getDeclContext()); |
| 592 | llvm::SmallVector<CXXBaseOrMemberInitializer*, 32> AllToInit; |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 593 | llvm::DenseMap<const void *, CXXBaseOrMemberInitializer*> AllBaseFields; |
| 594 | |
| 595 | for (unsigned i = 0; i < NumInitializers; i++) { |
| 596 | CXXBaseOrMemberInitializer *Member = Initializers[i]; |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 597 | if (Member->isBaseInitializer()) |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 598 | AllBaseFields[Member->getBaseClass()->getAs<RecordType>()] = Member; |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 599 | else |
Fariborz Jahanian | 8c64e00 | 2009-08-10 23:56:17 +0000 | [diff] [blame] | 600 | AllBaseFields[Member->getMember()] = Member; |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 603 | // Push virtual bases before others. |
| 604 | for (CXXRecordDecl::base_class_iterator VBase = |
| 605 | ClassDecl->vbases_begin(), |
| 606 | E = ClassDecl->vbases_end(); VBase != E; ++VBase) { |
Fariborz Jahanian | 77a2b4f | 2009-08-24 17:19:23 +0000 | [diff] [blame] | 607 | if (VBase->getType()->isDependentType()) |
| 608 | continue; |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 609 | if (CXXBaseOrMemberInitializer *Value = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 610 | AllBaseFields.lookup(VBase->getType()->getAs<RecordType>())) |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 611 | AllToInit.push_back(Value); |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 612 | else { |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 613 | CXXRecordDecl *VBaseDecl = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 614 | cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 615 | assert(VBaseDecl && "setBaseOrMemberInitializers - VBaseDecl null"); |
Fariborz Jahanian | 77a2b4f | 2009-08-24 17:19:23 +0000 | [diff] [blame] | 616 | if (!VBaseDecl->getDefaultConstructor(C)) |
Fariborz Jahanian | 87595e4 | 2009-07-23 23:32:59 +0000 | [diff] [blame] | 617 | Bases.push_back(VBase); |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 618 | CXXBaseOrMemberInitializer *Member = |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 619 | new (C) CXXBaseOrMemberInitializer(VBase->getType(), 0, 0, |
| 620 | VBaseDecl->getDefaultConstructor(C), |
| 621 | SourceLocation()); |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 622 | AllToInit.push_back(Member); |
| 623 | } |
| 624 | } |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 625 | |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 626 | for (CXXRecordDecl::base_class_iterator Base = |
| 627 | ClassDecl->bases_begin(), |
| 628 | E = ClassDecl->bases_end(); Base != E; ++Base) { |
| 629 | // Virtuals are in the virtual base list and already constructed. |
| 630 | if (Base->isVirtual()) |
| 631 | continue; |
Fariborz Jahanian | 77a2b4f | 2009-08-24 17:19:23 +0000 | [diff] [blame] | 632 | // Skip dependent types. |
| 633 | if (Base->getType()->isDependentType()) |
| 634 | continue; |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 635 | if (CXXBaseOrMemberInitializer *Value = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 636 | AllBaseFields.lookup(Base->getType()->getAs<RecordType>())) |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 637 | AllToInit.push_back(Value); |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 638 | else { |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 639 | CXXRecordDecl *BaseDecl = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 640 | cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 641 | assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null"); |
Fariborz Jahanian | 77a2b4f | 2009-08-24 17:19:23 +0000 | [diff] [blame] | 642 | if (!BaseDecl->getDefaultConstructor(C)) |
Fariborz Jahanian | 87595e4 | 2009-07-23 23:32:59 +0000 | [diff] [blame] | 643 | Bases.push_back(Base); |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 644 | CXXBaseOrMemberInitializer *Member = |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 645 | new (C) CXXBaseOrMemberInitializer(Base->getType(), 0, 0, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 646 | BaseDecl->getDefaultConstructor(C), |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 647 | SourceLocation()); |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 648 | AllToInit.push_back(Member); |
| 649 | } |
| 650 | } |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 651 | |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 652 | // non-static data members. |
| 653 | for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), |
| 654 | E = ClassDecl->field_end(); Field != E; ++Field) { |
Fariborz Jahanian | 8c64e00 | 2009-08-10 23:56:17 +0000 | [diff] [blame] | 655 | if ((*Field)->isAnonymousStructOrUnion()) { |
| 656 | if (const RecordType *FieldClassType = |
| 657 | Field->getType()->getAs<RecordType>()) { |
| 658 | CXXRecordDecl *FieldClassDecl |
| 659 | = cast<CXXRecordDecl>(FieldClassType->getDecl()); |
| 660 | for(RecordDecl::field_iterator FA = FieldClassDecl->field_begin(), |
| 661 | EA = FieldClassDecl->field_end(); FA != EA; FA++) { |
| 662 | if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(*FA)) { |
Fariborz Jahanian | e649412 | 2009-08-11 18:49:54 +0000 | [diff] [blame] | 663 | // 'Member' is the anonymous union field and 'AnonUnionMember' is |
| 664 | // set to the anonymous union data member used in the initializer |
| 665 | // list. |
| 666 | Value->setMember(*Field); |
| 667 | Value->setAnonUnionMember(*FA); |
Fariborz Jahanian | 8c64e00 | 2009-08-10 23:56:17 +0000 | [diff] [blame] | 668 | AllToInit.push_back(Value); |
| 669 | break; |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | continue; |
| 674 | } |
Fariborz Jahanian | 89350be | 2009-08-10 23:59:59 +0000 | [diff] [blame] | 675 | if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(*Field)) { |
Fariborz Jahanian | 08c6357 | 2009-07-25 01:08:28 +0000 | [diff] [blame] | 676 | AllToInit.push_back(Value); |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 677 | continue; |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 678 | } |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 679 | |
| 680 | QualType FT = C.getBaseElementType((*Field)->getType()); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 681 | if (const RecordType* RT = FT->getAs<RecordType>()) { |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 682 | CXXConstructorDecl *Ctor = |
| 683 | cast<CXXRecordDecl>(RT->getDecl())->getDefaultConstructor(C); |
| 684 | if (!Ctor && !FT->isDependentType()) |
Fariborz Jahanian | 87595e4 | 2009-07-23 23:32:59 +0000 | [diff] [blame] | 685 | Fields.push_back(*Field); |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 686 | CXXBaseOrMemberInitializer *Member = |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 687 | new (C) CXXBaseOrMemberInitializer((*Field), 0, 0, |
| 688 | Ctor, |
| 689 | SourceLocation()); |
Fariborz Jahanian | aa26650 | 2009-07-22 20:25:00 +0000 | [diff] [blame] | 690 | AllToInit.push_back(Member); |
| 691 | } |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 692 | } |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 693 | |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 694 | NumInitializers = AllToInit.size(); |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 695 | if (NumInitializers > 0) { |
| 696 | NumBaseOrMemberInitializers = NumInitializers; |
| 697 | BaseOrMemberInitializers = |
Fariborz Jahanian | 0d3c26c | 2009-07-07 16:24:08 +0000 | [diff] [blame] | 698 | new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 699 | for (unsigned Idx = 0; Idx < NumInitializers; ++Idx) |
Fariborz Jahanian | d01c915 | 2009-07-14 18:24:21 +0000 | [diff] [blame] | 700 | BaseOrMemberInitializers[Idx] = AllToInit[Idx]; |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 704 | void |
| 705 | CXXConstructorDecl::Destroy(ASTContext& C) { |
| 706 | C.Deallocate(BaseOrMemberInitializers); |
Fariborz Jahanian | 0d3c26c | 2009-07-07 16:24:08 +0000 | [diff] [blame] | 707 | CXXMethodDecl::Destroy(C); |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 710 | CXXConversionDecl * |
| 711 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 712 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 713 | QualType T, DeclaratorInfo *DInfo, |
| 714 | bool isInline, bool isExplicit) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 715 | assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && |
| 716 | "Name must refer to a conversion function"); |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 717 | return new (C) CXXConversionDecl(RD, L, N, T, DInfo, isInline, isExplicit); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 720 | OverloadedFunctionDecl * |
| 721 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 722 | DeclarationName N) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 723 | return new (C) OverloadedFunctionDecl(DC, N); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 724 | } |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 726 | OverloadIterator::OverloadIterator(NamedDecl *ND) : D(0) { |
| 727 | if (!ND) |
| 728 | return; |
| 729 | |
| 730 | if (isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND)) |
| 731 | D = ND; |
| 732 | else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(ND)) { |
| 733 | D = ND; |
| 734 | Iter = Ovl->function_begin(); |
| 735 | } |
| 736 | } |
| 737 | |
Douglas Gregor | 364e021 | 2009-06-27 21:05:07 +0000 | [diff] [blame] | 738 | void OverloadedFunctionDecl::addOverload(AnyFunctionDecl F) { |
| 739 | Functions.push_back(F); |
| 740 | this->setLocation(F.get()->getLocation()); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 743 | OverloadIterator::reference OverloadIterator::operator*() const { |
| 744 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 745 | return FD; |
| 746 | |
| 747 | if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 748 | return FTD; |
| 749 | |
| 750 | assert(isa<OverloadedFunctionDecl>(D)); |
| 751 | return *Iter; |
| 752 | } |
| 753 | |
| 754 | OverloadIterator &OverloadIterator::operator++() { |
| 755 | if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) { |
| 756 | D = 0; |
| 757 | return *this; |
| 758 | } |
| 759 | |
| 760 | if (++Iter == cast<OverloadedFunctionDecl>(D)->function_end()) |
| 761 | D = 0; |
| 762 | |
| 763 | return *this; |
| 764 | } |
| 765 | |
| 766 | bool OverloadIterator::Equals(const OverloadIterator &Other) const { |
| 767 | if (!D || !Other.D) |
| 768 | return D == Other.D; |
| 769 | |
| 770 | if (D != Other.D) |
| 771 | return false; |
| 772 | |
| 773 | return !isa<OverloadedFunctionDecl>(D) || Iter == Other.Iter; |
| 774 | } |
| 775 | |
John McCall | c48fbdf | 2009-08-11 21:13:21 +0000 | [diff] [blame] | 776 | FriendFunctionDecl *FriendFunctionDecl::Create(ASTContext &C, |
| 777 | DeclContext *DC, |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 778 | SourceLocation L, |
| 779 | DeclarationName N, QualType T, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 780 | DeclaratorInfo *DInfo, |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 781 | bool isInline, |
| 782 | SourceLocation FriendL) { |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 783 | return new (C) FriendFunctionDecl(DC, L, N, T, DInfo, isInline, FriendL); |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 784 | } |
John McCall | c48fbdf | 2009-08-11 21:13:21 +0000 | [diff] [blame] | 785 | |
| 786 | FriendClassDecl *FriendClassDecl::Create(ASTContext &C, DeclContext *DC, |
| 787 | SourceLocation L, QualType T, |
| 788 | SourceLocation FriendL) { |
| 789 | return new (C) FriendClassDecl(DC, L, T, FriendL); |
| 790 | } |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 791 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 792 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 793 | DeclContext *DC, |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 794 | SourceLocation L, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 795 | LanguageIDs Lang, bool Braces) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 796 | return new (C) LinkageSpecDecl(DC, L, Lang, Braces); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 797 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 798 | |
| 799 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 800 | SourceLocation L, |
| 801 | SourceLocation NamespaceLoc, |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 802 | SourceRange QualifierRange, |
| 803 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 804 | SourceLocation IdentLoc, |
| 805 | NamespaceDecl *Used, |
| 806 | DeclContext *CommonAncestor) { |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 807 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange, |
| 808 | Qualifier, IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 811 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 812 | SourceLocation L, |
| 813 | SourceLocation AliasLoc, |
| 814 | IdentifierInfo *Alias, |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 815 | SourceRange QualifierRange, |
| 816 | NestedNameSpecifier *Qualifier, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 817 | SourceLocation IdentLoc, |
| 818 | NamedDecl *Namespace) { |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 819 | return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange, |
| 820 | Qualifier, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 823 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, |
| 824 | SourceLocation L, SourceRange NNR, SourceLocation TargetNL, |
| 825 | SourceLocation UL, NamedDecl* Target, |
| 826 | NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) { |
| 827 | return new (C) UsingDecl(DC, L, NNR, TargetNL, UL, Target, |
| 828 | TargetNNS, IsTypeNameArg); |
| 829 | } |
| 830 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 831 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
| 832 | SourceLocation L, Expr *AssertExpr, |
| 833 | StringLiteral *Message) { |
| 834 | return new (C) StaticAssertDecl(DC, L, AssertExpr, Message); |
| 835 | } |
| 836 | |
| 837 | void StaticAssertDecl::Destroy(ASTContext& C) { |
| 838 | AssertExpr->Destroy(C); |
| 839 | Message->Destroy(C); |
| 840 | this->~StaticAssertDecl(); |
| 841 | C.Deallocate((void *)this); |
| 842 | } |
| 843 | |
| 844 | StaticAssertDecl::~StaticAssertDecl() { |
| 845 | } |
| 846 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 847 | static const char *getAccessName(AccessSpecifier AS) { |
| 848 | switch (AS) { |
| 849 | default: |
| 850 | case AS_none: |
| 851 | assert("Invalid access specifier!"); |
| 852 | return 0; |
| 853 | case AS_public: |
| 854 | return "public"; |
| 855 | case AS_private: |
| 856 | return "private"; |
| 857 | case AS_protected: |
| 858 | return "protected"; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 863 | AccessSpecifier AS) { |
| 864 | return DB << getAccessName(AS); |
| 865 | } |
| 866 | |
| 867 | |