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 | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 27 | SourceLocation L, IdentifierInfo *Id) |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 28 | : RecordDecl(K, TK, DC, L, Id), |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 29 | UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 30 | UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false), |
Anders Carlsson | 67e4dd2 | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 31 | Aggregate(true), PlainOldData(true), Polymorphic(false), Abstract(false), |
Anders Carlsson | 072abef | 2009-04-17 02:34:54 +0000 | [diff] [blame] | 32 | HasTrivialConstructor(true), HasTrivialDestructor(true), |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 33 | Bases(0), NumBases(0), VBases(0), NumVBases(0), |
| 34 | Conversions(DC, DeclarationName()), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 35 | TemplateOrInstantiation() { } |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 36 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 37 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
| 38 | SourceLocation L, IdentifierInfo *Id, |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 39 | CXXRecordDecl* PrevDecl, |
| 40 | bool DelayTypeCreation) { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 41 | CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id); |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 42 | if (!DelayTypeCreation) |
| 43 | C.getTypeDeclType(R, PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 44 | return R; |
| 45 | } |
| 46 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 47 | CXXRecordDecl::~CXXRecordDecl() { |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void CXXRecordDecl::Destroy(ASTContext &C) { |
| 51 | C.Deallocate(Bases); |
| 52 | this->RecordDecl::Destroy(C); |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 55 | void |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 56 | CXXRecordDecl::setBases(ASTContext &C, |
| 57 | CXXBaseSpecifier const * const *Bases, |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 58 | unsigned NumBases) { |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 59 | // C++ [dcl.init.aggr]p1: |
| 60 | // An aggregate is an array or a class (clause 9) with [...] |
| 61 | // no base classes [...]. |
| 62 | Aggregate = false; |
| 63 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 64 | if (this->Bases) |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 65 | C.Deallocate(this->Bases); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 66 | |
| 67 | int vbaseCount = 0; |
| 68 | llvm::SmallVector<const CXXBaseSpecifier*, 8> UniqueVbases; |
| 69 | bool hasDirectVirtualBase = false; |
| 70 | |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 71 | this->Bases = new(C) CXXBaseSpecifier [NumBases]; |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 72 | this->NumBases = NumBases; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 73 | for (unsigned i = 0; i < NumBases; ++i) { |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 74 | this->Bases[i] = *Bases[i]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 75 | // Keep track of inherited vbases for this base class. |
| 76 | const CXXBaseSpecifier *Base = Bases[i]; |
| 77 | QualType BaseType = Base->getType(); |
| 78 | // Skip template types. |
| 79 | // FIXME. This means that this list must be rebuilt during template |
| 80 | // instantiation. |
| 81 | if (BaseType->isDependentType()) |
| 82 | continue; |
| 83 | CXXRecordDecl *BaseClassDecl |
| 84 | = cast<CXXRecordDecl>(BaseType->getAsRecordType()->getDecl()); |
| 85 | if (Base->isVirtual()) |
| 86 | hasDirectVirtualBase = true; |
| 87 | for (CXXRecordDecl::base_class_iterator VBase = |
| 88 | BaseClassDecl->vbases_begin(), |
| 89 | E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { |
| 90 | // Add this vbase to the array of vbases for current class if it is |
| 91 | // not already in the list. |
| 92 | // FIXME. Note that we do a linear search as number of such classes are |
| 93 | // very few. |
| 94 | int i; |
| 95 | for (i = 0; i < vbaseCount; ++i) |
| 96 | if (UniqueVbases[i]->getType() == VBase->getType()) |
| 97 | break; |
| 98 | if (i == vbaseCount) { |
| 99 | UniqueVbases.push_back(VBase); |
| 100 | ++vbaseCount; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | if (hasDirectVirtualBase) { |
| 105 | // Iterate one more time through the direct bases and add the virtual |
| 106 | // base to the list of vritual bases for current class. |
| 107 | for (unsigned i = 0; i < NumBases; ++i) { |
| 108 | const CXXBaseSpecifier *VBase = Bases[i]; |
| 109 | if (!VBase->isVirtual()) |
| 110 | continue; |
| 111 | int i; |
| 112 | for (i = 0; i < vbaseCount; ++i) |
| 113 | if (UniqueVbases[i]->getType() == VBase->getType()) |
| 114 | break; |
| 115 | if (i == vbaseCount) { |
| 116 | UniqueVbases.push_back(VBase); |
| 117 | ++vbaseCount; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | if (vbaseCount > 0) { |
| 122 | // build AST for inhireted, direct or indirect, virtual bases. |
| 123 | this->VBases = new(C) CXXBaseSpecifier [vbaseCount]; |
| 124 | this->NumVBases = vbaseCount; |
| 125 | for (int i = 0; i < vbaseCount; i++) { |
| 126 | QualType QT = UniqueVbases[i]->getType(); |
| 127 | CXXRecordDecl *VBaseClassDecl |
| 128 | = cast<CXXRecordDecl>(QT->getAsRecordType()->getDecl()); |
| 129 | this->VBases[i] = |
| 130 | *new CXXBaseSpecifier( |
| 131 | VBaseClassDecl->getSourceRange(), true, |
| 132 | VBaseClassDecl->getTagKind() == RecordDecl::TK_class, |
| 133 | UniqueVbases[i]->getAccessSpecifier(), QT); |
| 134 | } |
| 135 | } |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 138 | bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const { |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 139 | return getCopyConstructor(Context, QualType::Const) != 0; |
| 140 | } |
| 141 | |
| 142 | CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context, |
| 143 | unsigned TypeQuals) const{ |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 144 | QualType ClassType |
| 145 | = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 146 | DeclarationName ConstructorName |
| 147 | = Context.DeclarationNames.getCXXConstructorName( |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 148 | Context.getCanonicalType(ClassType)); |
| 149 | unsigned FoundTQs; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 150 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 151 | for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 152 | Con != ConEnd; ++Con) { |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 153 | if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context, |
| 154 | FoundTQs)) { |
| 155 | if (((TypeQuals & QualType::Const) == (FoundTQs & QualType::Const)) || |
| 156 | (!(TypeQuals & QualType::Const) && (FoundTQs & QualType::Const))) |
| 157 | return cast<CXXConstructorDecl>(*Con); |
| 158 | |
| 159 | } |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 160 | } |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 161 | return 0; |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 164 | bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context) const { |
| 165 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 166 | const_cast<CXXRecordDecl*>(this))); |
| 167 | DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 168 | |
| 169 | DeclContext::lookup_const_iterator Op, OpEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 170 | for (llvm::tie(Op, OpEnd) = this->lookup(OpName); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 171 | Op != OpEnd; ++Op) { |
| 172 | // C++ [class.copy]p9: |
| 173 | // A user-declared copy assignment operator is a non-static non-template |
| 174 | // member function of class X with exactly one parameter of type X, X&, |
| 175 | // const X&, volatile X& or const volatile X&. |
| 176 | const CXXMethodDecl* Method = cast<CXXMethodDecl>(*Op); |
| 177 | if (Method->isStatic()) |
| 178 | continue; |
| 179 | // TODO: Skip templates? Or is this implicitly done due to parameter types? |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 180 | const FunctionProtoType *FnType = |
| 181 | Method->getType()->getAsFunctionProtoType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 182 | assert(FnType && "Overloaded operator has no prototype."); |
| 183 | // Don't assert on this; an invalid decl might have been left in the AST. |
| 184 | if (FnType->getNumArgs() != 1 || FnType->isVariadic()) |
| 185 | continue; |
| 186 | bool AcceptsConst = true; |
| 187 | QualType ArgType = FnType->getArgType(0); |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 188 | if (const LValueReferenceType *Ref = ArgType->getAsLValueReferenceType()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 189 | ArgType = Ref->getPointeeType(); |
Douglas Gregor | 2ff4478 | 2009-03-20 20:21:37 +0000 | [diff] [blame] | 190 | // Is it a non-const lvalue reference? |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 191 | if (!ArgType.isConstQualified()) |
| 192 | AcceptsConst = false; |
| 193 | } |
| 194 | if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType) |
| 195 | continue; |
| 196 | |
| 197 | // We have a single argument of type cv X or cv X&, i.e. we've found the |
| 198 | // copy assignment operator. Return whether it accepts const arguments. |
| 199 | return AcceptsConst; |
| 200 | } |
| 201 | assert(isInvalidDecl() && |
| 202 | "No copy assignment operator declared in valid code."); |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | void |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 207 | CXXRecordDecl::addedConstructor(ASTContext &Context, |
| 208 | CXXConstructorDecl *ConDecl) { |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 209 | assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl"); |
| 210 | // Note that we have a user-declared constructor. |
| 211 | UserDeclaredConstructor = true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 212 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 213 | // C++ [dcl.init.aggr]p1: |
| 214 | // An aggregate is an array or a class (clause 9) with no |
| 215 | // user-declared constructors (12.1) [...]. |
| 216 | Aggregate = false; |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 217 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 218 | // C++ [class]p4: |
| 219 | // A POD-struct is an aggregate class [...] |
| 220 | PlainOldData = false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 221 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 222 | // C++ [class.ctor]p5: |
| 223 | // A constructor is trivial if it is an implicitly-declared default |
| 224 | // constructor. |
| 225 | HasTrivialConstructor = false; |
Anders Carlsson | 347ba89 | 2009-04-16 00:08:20 +0000 | [diff] [blame] | 226 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 227 | // Note when we have a user-declared copy constructor, which will |
| 228 | // suppress the implicit declaration of a copy constructor. |
| 229 | if (ConDecl->isCopyConstructor(Context)) |
| 230 | UserDeclaredCopyConstructor = true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 233 | void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context, |
| 234 | CXXMethodDecl *OpDecl) { |
| 235 | // We're interested specifically in copy assignment operators. |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 236 | const FunctionProtoType *FnType = OpDecl->getType()->getAsFunctionProtoType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 237 | assert(FnType && "Overloaded operator has no proto function type."); |
| 238 | assert(FnType->getNumArgs() == 1 && !FnType->isVariadic()); |
| 239 | QualType ArgType = FnType->getArgType(0); |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 240 | if (const LValueReferenceType *Ref = ArgType->getAsLValueReferenceType()) |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 241 | ArgType = Ref->getPointeeType(); |
| 242 | |
| 243 | ArgType = ArgType.getUnqualifiedType(); |
| 244 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 245 | const_cast<CXXRecordDecl*>(this))); |
| 246 | |
| 247 | if (ClassType != Context.getCanonicalType(ArgType)) |
| 248 | return; |
| 249 | |
| 250 | // This is a copy assignment operator. |
| 251 | // Suppress the implicit declaration of a copy constructor. |
| 252 | UserDeclaredCopyAssignment = true; |
| 253 | |
| 254 | // C++ [class]p4: |
| 255 | // A POD-struct is an aggregate class that [...] has no user-defined copy |
| 256 | // assignment operator [...]. |
| 257 | PlainOldData = false; |
| 258 | } |
| 259 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 260 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
| 261 | CXXConversionDecl *ConvDecl) { |
| 262 | Conversions.addOverload(ConvDecl); |
| 263 | } |
| 264 | |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 265 | |
| 266 | CXXConstructorDecl * |
| 267 | CXXRecordDecl::getDefaultConstructor(ASTContext &Context) { |
| 268 | QualType ClassType = Context.getTypeDeclType(this); |
| 269 | DeclarationName ConstructorName |
| 270 | = Context.DeclarationNames.getCXXConstructorName( |
| 271 | Context.getCanonicalType(ClassType.getUnqualifiedType())); |
| 272 | |
| 273 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 274 | for (llvm::tie(Con, ConEnd) = lookup(ConstructorName); |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 275 | Con != ConEnd; ++Con) { |
| 276 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 277 | if (Constructor->isDefaultConstructor()) |
| 278 | return Constructor; |
| 279 | } |
| 280 | return 0; |
| 281 | } |
| 282 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 283 | const CXXDestructorDecl * |
| 284 | CXXRecordDecl::getDestructor(ASTContext &Context) { |
| 285 | QualType ClassType = Context.getTypeDeclType(this); |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 286 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 287 | DeclarationName Name |
| 288 | = Context.DeclarationNames.getCXXDestructorName(ClassType); |
| 289 | |
| 290 | DeclContext::lookup_iterator I, E; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 291 | llvm::tie(I, E) = lookup(Name); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 292 | assert(I != E && "Did not find a destructor!"); |
| 293 | |
| 294 | const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); |
| 295 | assert(++I == E && "Found more than one destructor!"); |
| 296 | |
| 297 | return Dtor; |
| 298 | } |
| 299 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 300 | CXXMethodDecl * |
| 301 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 302 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 303 | QualType T, bool isStatic, bool isInline) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 304 | return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 307 | |
| 308 | typedef llvm::DenseMap<const CXXMethodDecl*, |
| 309 | std::vector<const CXXMethodDecl *> *> |
| 310 | OverriddenMethodsMapTy; |
| 311 | |
| 312 | static OverriddenMethodsMapTy *OverriddenMethods = 0; |
| 313 | |
| 314 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
| 315 | // FIXME: The CXXMethodDecl dtor needs to remove and free the entry. |
| 316 | |
| 317 | if (!OverriddenMethods) |
| 318 | OverriddenMethods = new OverriddenMethodsMapTy(); |
| 319 | |
| 320 | std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this]; |
| 321 | if (!Methods) |
| 322 | Methods = new std::vector<const CXXMethodDecl *>; |
| 323 | |
| 324 | Methods->push_back(MD); |
| 325 | } |
| 326 | |
| 327 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
| 328 | if (!OverriddenMethods) |
| 329 | return 0; |
| 330 | |
| 331 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
| 332 | if (it == OverriddenMethods->end()) |
| 333 | return 0; |
| 334 | return &(*it->second)[0]; |
| 335 | } |
| 336 | |
| 337 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
| 338 | if (!OverriddenMethods) |
| 339 | return 0; |
| 340 | |
| 341 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
| 342 | if (it == OverriddenMethods->end()) |
| 343 | return 0; |
| 344 | |
| 345 | return &(*it->second)[it->second->size()]; |
| 346 | } |
| 347 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 348 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 349 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 350 | // If the member function is declared const, the type of this is const X*, |
| 351 | // if the member function is declared volatile, the type of this is |
| 352 | // volatile X*, and if the member function is declared const volatile, |
| 353 | // the type of this is const volatile X*. |
| 354 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 355 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 356 | |
| 357 | QualType ClassTy; |
| 358 | if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate()) |
| 359 | ClassTy = TD->getInjectedClassNameType(C); |
| 360 | else |
| 361 | ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(getParent())); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 362 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame^] | 363 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 366 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 367 | CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, |
| 368 | SourceLocation L) |
| 369 | : Args(0), NumArgs(0), IdLoc(L) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 370 | BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr()); |
| 371 | assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer"); |
| 372 | BaseOrMember |= 0x01; |
| 373 | |
| 374 | if (NumArgs > 0) { |
| 375 | this->NumArgs = NumArgs; |
| 376 | this->Args = new Expr*[NumArgs]; |
| 377 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 378 | this->Args[Idx] = Args[Idx]; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 383 | CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, |
| 384 | SourceLocation L) |
| 385 | : Args(0), NumArgs(0), IdLoc(L) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 386 | BaseOrMember = reinterpret_cast<uintptr_t>(Member); |
| 387 | assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer"); |
| 388 | |
| 389 | if (NumArgs > 0) { |
| 390 | this->NumArgs = NumArgs; |
| 391 | this->Args = new Expr*[NumArgs]; |
| 392 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 393 | this->Args[Idx] = Args[Idx]; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() { |
| 398 | delete [] Args; |
| 399 | } |
| 400 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 401 | CXXConstructorDecl * |
| 402 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 403 | SourceLocation L, DeclarationName N, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 404 | QualType T, bool isExplicit, |
| 405 | bool isInline, bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 406 | assert(N.getNameKind() == DeclarationName::CXXConstructorName && |
| 407 | "Name must refer to a constructor"); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 408 | return new (C) CXXConstructorDecl(RD, L, N, T, isExplicit, isInline, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 409 | isImplicitlyDeclared); |
| 410 | } |
| 411 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 412 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 413 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 414 | // A default constructor for a class X is a constructor of class |
| 415 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 416 | return (getNumParams() == 0) || |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 417 | (getNumParams() > 0 && getParamDecl(0)->getDefaultArg() != 0); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | bool |
| 421 | CXXConstructorDecl::isCopyConstructor(ASTContext &Context, |
| 422 | unsigned &TypeQuals) const { |
| 423 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 424 | // A non-template constructor for class X is a copy constructor |
| 425 | // if its first parameter is of type X&, const X&, volatile X& or |
| 426 | // const volatile X&, and either there are no other parameters |
| 427 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 428 | if ((getNumParams() < 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 429 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg())) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 430 | return false; |
| 431 | |
| 432 | const ParmVarDecl *Param = getParamDecl(0); |
| 433 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 434 | // Do we have a reference type? Rvalue references don't count. |
| 435 | const LValueReferenceType *ParamRefType = |
| 436 | Param->getType()->getAsLValueReferenceType(); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 437 | if (!ParamRefType) |
| 438 | return false; |
| 439 | |
| 440 | // Is it a reference to our class type? |
| 441 | QualType PointeeType |
| 442 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
| 443 | QualType ClassTy |
| 444 | = Context.getTagDeclType(const_cast<CXXRecordDecl*>(getParent())); |
| 445 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 446 | return false; |
| 447 | |
| 448 | // We have a copy constructor. |
| 449 | TypeQuals = PointeeType.getCVRQualifiers(); |
| 450 | return true; |
| 451 | } |
| 452 | |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 453 | bool CXXConstructorDecl::isConvertingConstructor() const { |
| 454 | // C++ [class.conv.ctor]p1: |
| 455 | // A constructor declared without the function-specifier explicit |
| 456 | // that can be called with a single parameter specifies a |
| 457 | // conversion from the type of its first parameter to the type of |
| 458 | // its class. Such a constructor is called a converting |
| 459 | // constructor. |
| 460 | if (isExplicit()) |
| 461 | return false; |
| 462 | |
| 463 | return (getNumParams() == 0 && |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 464 | getType()->getAsFunctionProtoType()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 465 | (getNumParams() == 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 466 | (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 467 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 468 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 469 | CXXDestructorDecl * |
| 470 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 471 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 472 | QualType T, bool isInline, |
| 473 | bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 474 | assert(N.getNameKind() == DeclarationName::CXXDestructorName && |
| 475 | "Name must refer to a destructor"); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 476 | return new (C) CXXDestructorDecl(RD, L, N, T, isInline, |
| 477 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 480 | void |
| 481 | CXXConstructorDecl::setBaseOrMemberInitializers( |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 482 | ASTContext &C, |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 483 | CXXBaseOrMemberInitializer **Initializers, |
| 484 | unsigned NumInitializers) { |
| 485 | if (NumInitializers > 0) { |
| 486 | NumBaseOrMemberInitializers = NumInitializers; |
| 487 | BaseOrMemberInitializers = |
Fariborz Jahanian | 0d3c26c | 2009-07-07 16:24:08 +0000 | [diff] [blame] | 488 | new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 489 | for (unsigned Idx = 0; Idx < NumInitializers; ++Idx) |
| 490 | BaseOrMemberInitializers[Idx] = Initializers[Idx]; |
| 491 | } |
| 492 | } |
| 493 | |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 494 | void |
| 495 | CXXConstructorDecl::Destroy(ASTContext& C) { |
| 496 | C.Deallocate(BaseOrMemberInitializers); |
Fariborz Jahanian | 0d3c26c | 2009-07-07 16:24:08 +0000 | [diff] [blame] | 497 | CXXMethodDecl::Destroy(C); |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 500 | CXXConversionDecl * |
| 501 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 502 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 503 | QualType T, bool isInline, bool isExplicit) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 504 | assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && |
| 505 | "Name must refer to a conversion function"); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 506 | return new (C) CXXConversionDecl(RD, L, N, T, isInline, isExplicit); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 509 | OverloadedFunctionDecl * |
| 510 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 511 | DeclarationName N) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 512 | return new (C) OverloadedFunctionDecl(DC, N); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 513 | } |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 514 | |
Douglas Gregor | 364e021 | 2009-06-27 21:05:07 +0000 | [diff] [blame] | 515 | void OverloadedFunctionDecl::addOverload(AnyFunctionDecl F) { |
| 516 | Functions.push_back(F); |
| 517 | this->setLocation(F.get()->getLocation()); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 520 | OverloadIterator::reference OverloadIterator::operator*() const { |
| 521 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 522 | return FD; |
| 523 | |
| 524 | if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 525 | return FTD; |
| 526 | |
| 527 | assert(isa<OverloadedFunctionDecl>(D)); |
| 528 | return *Iter; |
| 529 | } |
| 530 | |
| 531 | OverloadIterator &OverloadIterator::operator++() { |
| 532 | if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) { |
| 533 | D = 0; |
| 534 | return *this; |
| 535 | } |
| 536 | |
| 537 | if (++Iter == cast<OverloadedFunctionDecl>(D)->function_end()) |
| 538 | D = 0; |
| 539 | |
| 540 | return *this; |
| 541 | } |
| 542 | |
| 543 | bool OverloadIterator::Equals(const OverloadIterator &Other) const { |
| 544 | if (!D || !Other.D) |
| 545 | return D == Other.D; |
| 546 | |
| 547 | if (D != Other.D) |
| 548 | return false; |
| 549 | |
| 550 | return !isa<OverloadedFunctionDecl>(D) || Iter == Other.Iter; |
| 551 | } |
| 552 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 553 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 554 | DeclContext *DC, |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 555 | SourceLocation L, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 556 | LanguageIDs Lang, bool Braces) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 557 | return new (C) LinkageSpecDecl(DC, L, Lang, Braces); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 558 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 559 | |
| 560 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 561 | SourceLocation L, |
| 562 | SourceLocation NamespaceLoc, |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 563 | SourceRange QualifierRange, |
| 564 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 565 | SourceLocation IdentLoc, |
| 566 | NamespaceDecl *Used, |
| 567 | DeclContext *CommonAncestor) { |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 568 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange, |
| 569 | Qualifier, IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 572 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 573 | SourceLocation L, |
| 574 | SourceLocation AliasLoc, |
| 575 | IdentifierInfo *Alias, |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 576 | SourceRange QualifierRange, |
| 577 | NestedNameSpecifier *Qualifier, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 578 | SourceLocation IdentLoc, |
| 579 | NamedDecl *Namespace) { |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 580 | return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange, |
| 581 | Qualifier, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 584 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, |
| 585 | SourceLocation L, SourceRange NNR, SourceLocation TargetNL, |
| 586 | SourceLocation UL, NamedDecl* Target, |
| 587 | NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) { |
| 588 | return new (C) UsingDecl(DC, L, NNR, TargetNL, UL, Target, |
| 589 | TargetNNS, IsTypeNameArg); |
| 590 | } |
| 591 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 592 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
| 593 | SourceLocation L, Expr *AssertExpr, |
| 594 | StringLiteral *Message) { |
| 595 | return new (C) StaticAssertDecl(DC, L, AssertExpr, Message); |
| 596 | } |
| 597 | |
| 598 | void StaticAssertDecl::Destroy(ASTContext& C) { |
| 599 | AssertExpr->Destroy(C); |
| 600 | Message->Destroy(C); |
| 601 | this->~StaticAssertDecl(); |
| 602 | C.Deallocate((void *)this); |
| 603 | } |
| 604 | |
| 605 | StaticAssertDecl::~StaticAssertDecl() { |
| 606 | } |
| 607 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 608 | static const char *getAccessName(AccessSpecifier AS) { |
| 609 | switch (AS) { |
| 610 | default: |
| 611 | case AS_none: |
| 612 | assert("Invalid access specifier!"); |
| 613 | return 0; |
| 614 | case AS_public: |
| 615 | return "public"; |
| 616 | case AS_private: |
| 617 | return "private"; |
| 618 | case AS_protected: |
| 619 | return "protected"; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 624 | AccessSpecifier AS) { |
| 625 | return DB << getAccessName(AS); |
| 626 | } |
| 627 | |
| 628 | |