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