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) { |
Fariborz Jahanian | 4f213d3 | 2009-09-11 22:27:50 +0000 | [diff] [blame] | 291 | if (RD == this) { |
| 292 | // If root class, all conversions are visible. |
| 293 | if (RD->bases_begin() == RD->bases_end()) |
| 294 | return &Conversions; |
| 295 | // If visible conversion list is already evaluated, return it. |
| 296 | if (VisibleConversions.function_begin() |
| 297 | != VisibleConversions.function_end()) |
| 298 | return &VisibleConversions; |
| 299 | } |
| 300 | |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 301 | QualType ClassType = Context.getTypeDeclType(this); |
| 302 | if (const RecordType *Record = ClassType->getAs<RecordType>()) { |
| 303 | OverloadedFunctionDecl *Conversions |
| 304 | = cast<CXXRecordDecl>(Record->getDecl())->getConversionFunctions(); |
| 305 | for (OverloadedFunctionDecl::function_iterator |
| 306 | Func = Conversions->function_begin(), |
| 307 | FuncEnd = Conversions->function_end(); |
| 308 | Func != FuncEnd; ++Func) { |
| 309 | if (FunctionTemplateDecl *ConversionTemplate = |
| 310 | dyn_cast<FunctionTemplateDecl>(*Func)) { |
| 311 | RD->addVisibleConversionFunction(Context, ConversionTemplate); |
| 312 | continue; |
| 313 | } |
| 314 | CXXConversionDecl *Conv = cast<CXXConversionDecl>(*Func); |
| 315 | bool Candidate = true; |
| 316 | // Only those conversions not exact match of conversions in current |
| 317 | // class are candidateconversion routines. |
| 318 | if (RD != this) { |
| 319 | OverloadedFunctionDecl *TopConversions = RD->getConversionFunctions(); |
| 320 | QualType ConvType = Context.getCanonicalType(Conv->getType()); |
| 321 | for (OverloadedFunctionDecl::function_iterator |
| 322 | TFunc = TopConversions->function_begin(), |
| 323 | TFuncEnd = TopConversions->function_end(); |
| 324 | TFunc != TFuncEnd; ++TFunc) { |
| 325 | CXXConversionDecl *TopConv = cast<CXXConversionDecl>(*TFunc); |
| 326 | QualType TConvType = Context.getCanonicalType(TopConv->getType()); |
| 327 | if (ConvType == TConvType) { |
| 328 | Candidate = false; |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | if (Candidate) { |
| 334 | if (FunctionTemplateDecl *ConversionTemplate |
| 335 | = Conv->getDescribedFunctionTemplate()) |
| 336 | RD->addVisibleConversionFunction(Context, ConversionTemplate); |
| 337 | else if (!Conv->getPrimaryTemplate()) // ignore specializations |
| 338 | RD->addVisibleConversionFunction(Context, Conv); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | for (CXXRecordDecl::base_class_iterator VBase = vbases_begin(), |
| 344 | E = vbases_end(); VBase != E; ++VBase) { |
| 345 | CXXRecordDecl *VBaseClassDecl |
| 346 | = cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl()); |
| 347 | VBaseClassDecl->getVisibleConversionFunctions(Context, RD); |
| 348 | } |
| 349 | for (CXXRecordDecl::base_class_iterator Base = bases_begin(), |
| 350 | E = bases_end(); Base != E; ++Base) { |
| 351 | if (Base->isVirtual()) |
| 352 | continue; |
| 353 | CXXRecordDecl *BaseClassDecl |
| 354 | = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
| 355 | BaseClassDecl->getVisibleConversionFunctions(Context, RD); |
| 356 | } |
| 357 | return &VisibleConversions; |
| 358 | } |
| 359 | |
| 360 | void CXXRecordDecl::addVisibleConversionFunction(ASTContext &Context, |
| 361 | CXXConversionDecl *ConvDecl) { |
| 362 | assert(!ConvDecl->getDescribedFunctionTemplate() && |
| 363 | "Conversion function templates should cast to FunctionTemplateDecl."); |
| 364 | VisibleConversions.addOverload(ConvDecl); |
| 365 | } |
| 366 | |
| 367 | void CXXRecordDecl::addVisibleConversionFunction(ASTContext &Context, |
| 368 | FunctionTemplateDecl *ConvDecl) { |
| 369 | assert(isa<CXXConversionDecl>(ConvDecl->getTemplatedDecl()) && |
| 370 | "Function template is not a conversion function template"); |
| 371 | VisibleConversions.addOverload(ConvDecl); |
| 372 | } |
| 373 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 375 | CXXConversionDecl *ConvDecl) { |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 376 | assert(!ConvDecl->getDescribedFunctionTemplate() && |
| 377 | "Conversion function templates should cast to FunctionTemplateDecl."); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 378 | Conversions.addOverload(ConvDecl); |
| 379 | } |
| 380 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 382 | FunctionTemplateDecl *ConvDecl) { |
| 383 | assert(isa<CXXConversionDecl>(ConvDecl->getTemplatedDecl()) && |
| 384 | "Function template is not a conversion function template"); |
| 385 | Conversions.addOverload(ConvDecl); |
| 386 | } |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 387 | |
| 388 | CXXConstructorDecl * |
| 389 | CXXRecordDecl::getDefaultConstructor(ASTContext &Context) { |
| 390 | QualType ClassType = Context.getTypeDeclType(this); |
| 391 | DeclarationName ConstructorName |
| 392 | = Context.DeclarationNames.getCXXConstructorName( |
| 393 | Context.getCanonicalType(ClassType.getUnqualifiedType())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 394 | |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 395 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 396 | for (llvm::tie(Con, ConEnd) = lookup(ConstructorName); |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 397 | Con != ConEnd; ++Con) { |
Douglas Gregor | d93bacf | 2009-09-04 14:46:39 +0000 | [diff] [blame] | 398 | // FIXME: In C++0x, a constructor template can be a default constructor. |
| 399 | if (isa<FunctionTemplateDecl>(*Con)) |
| 400 | continue; |
| 401 | |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 402 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 403 | if (Constructor->isDefaultConstructor()) |
| 404 | return Constructor; |
| 405 | } |
| 406 | return 0; |
| 407 | } |
| 408 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 409 | const CXXDestructorDecl * |
| 410 | CXXRecordDecl::getDestructor(ASTContext &Context) { |
| 411 | QualType ClassType = Context.getTypeDeclType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | |
| 413 | DeclarationName Name |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 414 | = Context.DeclarationNames.getCXXDestructorName( |
| 415 | Context.getCanonicalType(ClassType)); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 416 | |
| 417 | DeclContext::lookup_iterator I, E; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 418 | llvm::tie(I, E) = lookup(Name); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 419 | assert(I != E && "Did not find a destructor!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 421 | const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); |
| 422 | assert(++I == E && "Found more than one destructor!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 424 | return Dtor; |
| 425 | } |
| 426 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 427 | CXXMethodDecl * |
| 428 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 429 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 430 | QualType T, DeclaratorInfo *DInfo, |
| 431 | bool isStatic, bool isInline) { |
| 432 | return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, DInfo, |
| 433 | isStatic, isInline); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 436 | typedef llvm::DenseMap<const CXXMethodDecl*, |
| 437 | std::vector<const CXXMethodDecl *> *> |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 438 | OverriddenMethodsMapTy; |
| 439 | |
Mike Stump | b9871a2 | 2009-08-21 01:45:00 +0000 | [diff] [blame] | 440 | // FIXME: We hate static data. This doesn't survive PCH saving/loading, and |
| 441 | // the vtable building code uses it at CG time. |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 442 | static OverriddenMethodsMapTy *OverriddenMethods = 0; |
| 443 | |
| 444 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
| 445 | // FIXME: The CXXMethodDecl dtor needs to remove and free the entry. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 447 | if (!OverriddenMethods) |
| 448 | OverriddenMethods = new OverriddenMethodsMapTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 450 | std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this]; |
| 451 | if (!Methods) |
| 452 | Methods = new std::vector<const CXXMethodDecl *>; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 453 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 454 | Methods->push_back(MD); |
| 455 | } |
| 456 | |
| 457 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
| 458 | if (!OverriddenMethods) |
| 459 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 461 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 462 | if (it == OverriddenMethods->end() || it->second->empty()) |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 463 | return 0; |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 464 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 465 | return &(*it->second)[0]; |
| 466 | } |
| 467 | |
| 468 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
| 469 | if (!OverriddenMethods) |
| 470 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 471 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 472 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 473 | if (it == OverriddenMethods->end() || it->second->empty()) |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 474 | return 0; |
| 475 | |
Daniel Dunbar | 637ec32 | 2009-08-02 01:48:29 +0000 | [diff] [blame] | 476 | return &(*it->second)[0] + it->second->size(); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 479 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 480 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 481 | // If the member function is declared const, the type of this is const X*, |
| 482 | // if the member function is declared volatile, the type of this is |
| 483 | // volatile X*, and if the member function is declared const volatile, |
| 484 | // the type of this is const volatile X*. |
| 485 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 486 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 487 | |
| 488 | QualType ClassTy; |
| 489 | if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate()) |
| 490 | ClassTy = TD->getInjectedClassNameType(C); |
| 491 | else |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 492 | ClassTy = C.getTagDeclType(getParent()); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 493 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 494 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 497 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 498 | CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 499 | CXXConstructorDecl *C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | SourceLocation L, SourceLocation R) |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 501 | : Args(0), NumArgs(0), CtorOrAnonUnion(), IdLoc(L), RParenLoc(R) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 502 | BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr()); |
| 503 | assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer"); |
| 504 | BaseOrMember |= 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 505 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 506 | if (NumArgs > 0) { |
| 507 | this->NumArgs = NumArgs; |
Fariborz Jahanian | 50b8eea | 2009-07-24 17:57:02 +0000 | [diff] [blame] | 508 | // FIXME. Allocation via Context |
| 509 | this->Args = new Stmt*[NumArgs]; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 510 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 511 | this->Args[Idx] = Args[Idx]; |
| 512 | } |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 513 | CtorOrAnonUnion = C; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 517 | CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 518 | CXXConstructorDecl *C, |
Anders Carlsson | 8c57a66 | 2009-08-29 01:31:33 +0000 | [diff] [blame] | 519 | SourceLocation L, SourceLocation R) |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 520 | : Args(0), NumArgs(0), CtorOrAnonUnion(), IdLoc(L), RParenLoc(R) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 521 | BaseOrMember = reinterpret_cast<uintptr_t>(Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer"); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 523 | |
| 524 | if (NumArgs > 0) { |
| 525 | this->NumArgs = NumArgs; |
Fariborz Jahanian | 50b8eea | 2009-07-24 17:57:02 +0000 | [diff] [blame] | 526 | this->Args = new Stmt*[NumArgs]; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 527 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 528 | this->Args[Idx] = Args[Idx]; |
| 529 | } |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 530 | CtorOrAnonUnion = C; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() { |
| 534 | delete [] Args; |
| 535 | } |
| 536 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 537 | CXXConstructorDecl * |
| 538 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 539 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 540 | QualType T, DeclaratorInfo *DInfo, |
| 541 | bool isExplicit, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 542 | bool isInline, bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 543 | assert(N.getNameKind() == DeclarationName::CXXConstructorName && |
| 544 | "Name must refer to a constructor"); |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 545 | return new (C) CXXConstructorDecl(RD, L, N, T, DInfo, isExplicit, isInline, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 546 | isImplicitlyDeclared); |
| 547 | } |
| 548 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 549 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 550 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 551 | // A default constructor for a class X is a constructor of class |
| 552 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 553 | return (getNumParams() == 0) || |
Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame] | 554 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 557 | bool |
| 558 | CXXConstructorDecl::isCopyConstructor(ASTContext &Context, |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 559 | unsigned &TypeQuals) const { |
| 560 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 561 | // A non-template constructor for class X is a copy constructor |
| 562 | // if its first parameter is of type X&, const X&, volatile X& or |
| 563 | // const volatile X&, and either there are no other parameters |
| 564 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 565 | if ((getNumParams() < 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 566 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg())) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 567 | return false; |
| 568 | |
| 569 | const ParmVarDecl *Param = getParamDecl(0); |
| 570 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 571 | // Do we have a reference type? Rvalue references don't count. |
| 572 | const LValueReferenceType *ParamRefType = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 573 | Param->getType()->getAs<LValueReferenceType>(); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 574 | if (!ParamRefType) |
| 575 | return false; |
| 576 | |
| 577 | // Is it a reference to our class type? |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 578 | QualType PointeeType |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 579 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 580 | QualType ClassTy = Context.getTagDeclType(getParent()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 581 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 582 | return false; |
| 583 | |
| 584 | // We have a copy constructor. |
| 585 | TypeQuals = PointeeType.getCVRQualifiers(); |
| 586 | return true; |
| 587 | } |
| 588 | |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 589 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 590 | // C++ [class.conv.ctor]p1: |
| 591 | // A constructor declared without the function-specifier explicit |
| 592 | // that can be called with a single parameter specifies a |
| 593 | // conversion from the type of its first parameter to the type of |
| 594 | // its class. Such a constructor is called a converting |
| 595 | // constructor. |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 596 | if (isExplicit() && !AllowExplicit) |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 597 | return false; |
| 598 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 599 | return (getNumParams() == 0 && |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 600 | getType()->getAsFunctionProtoType()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 601 | (getNumParams() == 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 602 | (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 603 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 604 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 605 | CXXDestructorDecl * |
| 606 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 607 | SourceLocation L, DeclarationName N, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | QualType T, bool isInline, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 609 | bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 610 | assert(N.getNameKind() == DeclarationName::CXXDestructorName && |
| 611 | "Name must refer to a destructor"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | return new (C) CXXDestructorDecl(RD, L, N, T, isInline, |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 613 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 616 | void |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 617 | CXXDestructorDecl::Destroy(ASTContext& C) { |
| 618 | C.Deallocate(BaseOrMemberDestructions); |
| 619 | CXXMethodDecl::Destroy(C); |
| 620 | } |
| 621 | |
| 622 | void |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 623 | CXXConstructorDecl::Destroy(ASTContext& C) { |
| 624 | C.Deallocate(BaseOrMemberInitializers); |
Fariborz Jahanian | 0d3c26c | 2009-07-07 16:24:08 +0000 | [diff] [blame] | 625 | CXXMethodDecl::Destroy(C); |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 628 | CXXConversionDecl * |
| 629 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 630 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 631 | QualType T, DeclaratorInfo *DInfo, |
| 632 | bool isInline, bool isExplicit) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 633 | assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && |
| 634 | "Name must refer to a conversion function"); |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 635 | return new (C) CXXConversionDecl(RD, L, N, T, DInfo, isInline, isExplicit); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 638 | OverloadedFunctionDecl * |
| 639 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 640 | DeclarationName N) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 641 | return new (C) OverloadedFunctionDecl(DC, N); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 642 | } |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 644 | OverloadIterator::OverloadIterator(NamedDecl *ND) : D(0) { |
| 645 | if (!ND) |
| 646 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 647 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 648 | if (isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND)) |
| 649 | D = ND; |
| 650 | else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(ND)) { |
Douglas Gregor | 8f1d89e | 2009-09-01 16:58:52 +0000 | [diff] [blame] | 651 | if (Ovl->size() != 0) { |
| 652 | D = ND; |
| 653 | Iter = Ovl->function_begin(); |
| 654 | } |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
Douglas Gregor | 364e021 | 2009-06-27 21:05:07 +0000 | [diff] [blame] | 658 | void OverloadedFunctionDecl::addOverload(AnyFunctionDecl F) { |
| 659 | Functions.push_back(F); |
| 660 | this->setLocation(F.get()->getLocation()); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 663 | OverloadIterator::reference OverloadIterator::operator*() const { |
| 664 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 665 | return FD; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 667 | if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 668 | return FTD; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 670 | assert(isa<OverloadedFunctionDecl>(D)); |
| 671 | return *Iter; |
| 672 | } |
| 673 | |
| 674 | OverloadIterator &OverloadIterator::operator++() { |
| 675 | if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) { |
| 676 | D = 0; |
| 677 | return *this; |
| 678 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 680 | if (++Iter == cast<OverloadedFunctionDecl>(D)->function_end()) |
| 681 | D = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 683 | return *this; |
| 684 | } |
| 685 | |
| 686 | bool OverloadIterator::Equals(const OverloadIterator &Other) const { |
| 687 | if (!D || !Other.D) |
| 688 | return D == Other.D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 690 | if (D != Other.D) |
| 691 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 693 | return !isa<OverloadedFunctionDecl>(D) || Iter == Other.Iter; |
| 694 | } |
| 695 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 696 | FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, |
| 697 | SourceLocation L, |
| 698 | FriendUnion Friend, |
| 699 | SourceLocation FriendL) { |
Daniel Dunbar | e32ecce | 2009-08-31 19:16:38 +0000 | [diff] [blame] | 700 | #ifndef NDEBUG |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 701 | if (Friend.is<NamedDecl*>()) { |
| 702 | NamedDecl *D = Friend.get<NamedDecl*>(); |
| 703 | assert(isa<FunctionDecl>(D) || |
| 704 | isa<CXXRecordDecl>(D) || |
| 705 | isa<FunctionTemplateDecl>(D) || |
| 706 | isa<ClassTemplateDecl>(D)); |
| 707 | assert(D->getFriendObjectKind()); |
| 708 | } |
Daniel Dunbar | e32ecce | 2009-08-31 19:16:38 +0000 | [diff] [blame] | 709 | #endif |
John McCall | c48fbdf | 2009-08-11 21:13:21 +0000 | [diff] [blame] | 710 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 711 | return new (C) FriendDecl(DC, L, Friend, FriendL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | } |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 713 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 714 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | DeclContext *DC, |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 716 | SourceLocation L, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 717 | LanguageIDs Lang, bool Braces) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 718 | return new (C) LinkageSpecDecl(DC, L, Lang, Braces); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 719 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 720 | |
| 721 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 722 | SourceLocation L, |
| 723 | SourceLocation NamespaceLoc, |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 724 | SourceRange QualifierRange, |
| 725 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 726 | SourceLocation IdentLoc, |
| 727 | NamespaceDecl *Used, |
| 728 | DeclContext *CommonAncestor) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange, |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 730 | Qualifier, IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 734 | SourceLocation L, |
| 735 | SourceLocation AliasLoc, |
| 736 | IdentifierInfo *Alias, |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 737 | SourceRange QualifierRange, |
| 738 | NestedNameSpecifier *Qualifier, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | SourceLocation IdentLoc, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 740 | NamedDecl *Namespace) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange, |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 742 | Qualifier, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 745 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, |
| 746 | SourceLocation L, SourceRange NNR, SourceLocation TargetNL, |
| 747 | SourceLocation UL, NamedDecl* Target, |
| 748 | NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) { |
| 749 | return new (C) UsingDecl(DC, L, NNR, TargetNL, UL, Target, |
| 750 | TargetNNS, IsTypeNameArg); |
| 751 | } |
| 752 | |
Anders Carlsson | 665b49c | 2009-08-28 05:30:28 +0000 | [diff] [blame] | 753 | UnresolvedUsingDecl *UnresolvedUsingDecl::Create(ASTContext &C, DeclContext *DC, |
| 754 | SourceLocation UsingLoc, |
| 755 | SourceRange TargetNNR, |
| 756 | NestedNameSpecifier *TargetNNS, |
| 757 | SourceLocation TargetNameLoc, |
| 758 | DeclarationName TargetName, |
| 759 | bool IsTypeNameArg) { |
| 760 | return new (C) UnresolvedUsingDecl(DC, UsingLoc, TargetNNR, TargetNNS, |
| 761 | TargetNameLoc, TargetName, IsTypeNameArg); |
| 762 | } |
| 763 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 764 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
| 765 | SourceLocation L, Expr *AssertExpr, |
| 766 | StringLiteral *Message) { |
| 767 | return new (C) StaticAssertDecl(DC, L, AssertExpr, Message); |
| 768 | } |
| 769 | |
| 770 | void StaticAssertDecl::Destroy(ASTContext& C) { |
| 771 | AssertExpr->Destroy(C); |
| 772 | Message->Destroy(C); |
| 773 | this->~StaticAssertDecl(); |
| 774 | C.Deallocate((void *)this); |
| 775 | } |
| 776 | |
| 777 | StaticAssertDecl::~StaticAssertDecl() { |
| 778 | } |
| 779 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 780 | static const char *getAccessName(AccessSpecifier AS) { |
| 781 | switch (AS) { |
| 782 | default: |
| 783 | case AS_none: |
| 784 | assert("Invalid access specifier!"); |
| 785 | return 0; |
| 786 | case AS_public: |
| 787 | return "public"; |
| 788 | case AS_private: |
| 789 | return "private"; |
| 790 | case AS_protected: |
| 791 | return "protected"; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 796 | AccessSpecifier AS) { |
| 797 | return DB << getAccessName(AS); |
| 798 | } |
| 799 | |
| 800 | |