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" |
| 15 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 16 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | // Decl Allocation/Deallocation Method Implementations |
| 22 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 23 | |
| 24 | TemplateTypeParmDecl * |
| 25 | TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC, |
Nate Begeman | fea8685 | 2008-12-16 19:57:09 +0000 | [diff] [blame] | 26 | SourceLocation L, IdentifierInfo *Id, |
| 27 | bool Typename) { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 28 | void *Mem = C.getAllocator().Allocate<TemplateTypeParmDecl>(); |
| 29 | return new (Mem) TemplateTypeParmDecl(DC, L, Id, Typename); |
| 30 | } |
| 31 | |
| 32 | NonTypeTemplateParmDecl * |
| 33 | NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
Nate Begeman | fea8685 | 2008-12-16 19:57:09 +0000 | [diff] [blame] | 34 | SourceLocation L, IdentifierInfo *Id, |
| 35 | QualType T, SourceLocation TypeSpecStartLoc) { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 36 | void *Mem = C.getAllocator().Allocate<NonTypeTemplateParmDecl>(); |
| 37 | return new (Mem) NonTypeTemplateParmDecl(DC, L, Id, T, TypeSpecStartLoc); |
| 38 | } |
| 39 | |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 40 | TemplateParameterList::TemplateParameterList(Decl **Params, unsigned NumParams) |
| 41 | : NumParams(NumParams) { |
| 42 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) |
| 43 | begin()[Idx] = Params[Idx]; |
| 44 | } |
| 45 | |
| 46 | TemplateParameterList * |
| 47 | TemplateParameterList::Create(ASTContext &C, Decl **Params, |
| 48 | unsigned NumParams) { |
| 49 | unsigned Size = sizeof(TemplateParameterList) + sizeof(Decl *) * NumParams; |
| 50 | unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment; |
| 51 | void *Mem = C.getAllocator().Allocate(Size, Align); |
| 52 | return new (Mem) TemplateParameterList(Params, NumParams); |
| 53 | } |
| 54 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 55 | CXXRecordDecl::CXXRecordDecl(TagKind TK, DeclContext *DC, |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 56 | SourceLocation L, IdentifierInfo *Id) |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 57 | : RecordDecl(CXXRecord, TK, DC, L, Id), |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 58 | UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 59 | UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false), |
| 60 | Aggregate(true), PlainOldData(true), Polymorphic(false), Bases(0), |
| 61 | NumBases(0), Conversions(DC, DeclarationName()) { } |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 62 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 63 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
| 64 | SourceLocation L, IdentifierInfo *Id, |
| 65 | CXXRecordDecl* PrevDecl) { |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 66 | void *Mem = C.getAllocator().Allocate<CXXRecordDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 67 | CXXRecordDecl* R = new (Mem) CXXRecordDecl(TK, DC, L, Id); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 68 | C.getTypeDeclType(R, PrevDecl); |
| 69 | return R; |
| 70 | } |
| 71 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 72 | CXXRecordDecl::~CXXRecordDecl() { |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 73 | delete [] Bases; |
| 74 | } |
| 75 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 76 | void |
| 77 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, |
| 78 | unsigned NumBases) { |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 79 | // C++ [dcl.init.aggr]p1: |
| 80 | // An aggregate is an array or a class (clause 9) with [...] |
| 81 | // no base classes [...]. |
| 82 | Aggregate = false; |
| 83 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 84 | if (this->Bases) |
| 85 | delete [] this->Bases; |
| 86 | |
| 87 | this->Bases = new CXXBaseSpecifier[NumBases]; |
| 88 | this->NumBases = NumBases; |
| 89 | for (unsigned i = 0; i < NumBases; ++i) |
| 90 | this->Bases[i] = *Bases[i]; |
| 91 | } |
| 92 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 93 | bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 94 | QualType ClassType |
| 95 | = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 96 | DeclarationName ConstructorName |
| 97 | = Context.DeclarationNames.getCXXConstructorName( |
| 98 | Context.getCanonicalType(ClassType)); |
| 99 | unsigned TypeQuals; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 100 | DeclContext::lookup_const_iterator Con, ConEnd; |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame^] | 101 | for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 102 | Con != ConEnd; ++Con) { |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 103 | if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context, TypeQuals) && |
Eli Friedman | e8e3205 | 2008-12-16 20:06:41 +0000 | [diff] [blame] | 104 | (TypeQuals & QualType::Const) != 0) |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 105 | return true; |
| 106 | } |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 111 | bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context) const { |
| 112 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 113 | const_cast<CXXRecordDecl*>(this))); |
| 114 | DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 115 | |
| 116 | DeclContext::lookup_const_iterator Op, OpEnd; |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame^] | 117 | for (llvm::tie(Op, OpEnd) = this->lookup(OpName); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 118 | Op != OpEnd; ++Op) { |
| 119 | // C++ [class.copy]p9: |
| 120 | // A user-declared copy assignment operator is a non-static non-template |
| 121 | // member function of class X with exactly one parameter of type X, X&, |
| 122 | // const X&, volatile X& or const volatile X&. |
| 123 | const CXXMethodDecl* Method = cast<CXXMethodDecl>(*Op); |
| 124 | if (Method->isStatic()) |
| 125 | continue; |
| 126 | // TODO: Skip templates? Or is this implicitly done due to parameter types? |
| 127 | const FunctionTypeProto *FnType = |
| 128 | Method->getType()->getAsFunctionTypeProto(); |
| 129 | assert(FnType && "Overloaded operator has no prototype."); |
| 130 | // Don't assert on this; an invalid decl might have been left in the AST. |
| 131 | if (FnType->getNumArgs() != 1 || FnType->isVariadic()) |
| 132 | continue; |
| 133 | bool AcceptsConst = true; |
| 134 | QualType ArgType = FnType->getArgType(0); |
| 135 | if (const ReferenceType *Ref = ArgType->getAsReferenceType()) { |
| 136 | ArgType = Ref->getPointeeType(); |
| 137 | // Is it a non-const reference? |
| 138 | if (!ArgType.isConstQualified()) |
| 139 | AcceptsConst = false; |
| 140 | } |
| 141 | if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType) |
| 142 | continue; |
| 143 | |
| 144 | // We have a single argument of type cv X or cv X&, i.e. we've found the |
| 145 | // copy assignment operator. Return whether it accepts const arguments. |
| 146 | return AcceptsConst; |
| 147 | } |
| 148 | assert(isInvalidDecl() && |
| 149 | "No copy assignment operator declared in valid code."); |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | void |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 154 | CXXRecordDecl::addedConstructor(ASTContext &Context, |
| 155 | CXXConstructorDecl *ConDecl) { |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 156 | if (!ConDecl->isImplicit()) { |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 157 | // Note that we have a user-declared constructor. |
| 158 | UserDeclaredConstructor = true; |
| 159 | |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 160 | // C++ [dcl.init.aggr]p1: |
| 161 | // An aggregate is an array or a class (clause 9) with no |
| 162 | // user-declared constructors (12.1) [...]. |
| 163 | Aggregate = false; |
| 164 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 165 | // C++ [class]p4: |
| 166 | // A POD-struct is an aggregate class [...] |
| 167 | PlainOldData = false; |
| 168 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 169 | // Note when we have a user-declared copy constructor, which will |
| 170 | // suppress the implicit declaration of a copy constructor. |
| 171 | if (ConDecl->isCopyConstructor(Context)) |
| 172 | UserDeclaredCopyConstructor = true; |
| 173 | } |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 176 | void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context, |
| 177 | CXXMethodDecl *OpDecl) { |
| 178 | // We're interested specifically in copy assignment operators. |
| 179 | // Unlike addedConstructor, this method is not called for implicit |
| 180 | // declarations. |
| 181 | const FunctionTypeProto *FnType = OpDecl->getType()->getAsFunctionTypeProto(); |
| 182 | assert(FnType && "Overloaded operator has no proto function type."); |
| 183 | assert(FnType->getNumArgs() == 1 && !FnType->isVariadic()); |
| 184 | QualType ArgType = FnType->getArgType(0); |
| 185 | if (const ReferenceType *Ref = ArgType->getAsReferenceType()) |
| 186 | ArgType = Ref->getPointeeType(); |
| 187 | |
| 188 | ArgType = ArgType.getUnqualifiedType(); |
| 189 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 190 | const_cast<CXXRecordDecl*>(this))); |
| 191 | |
| 192 | if (ClassType != Context.getCanonicalType(ArgType)) |
| 193 | return; |
| 194 | |
| 195 | // This is a copy assignment operator. |
| 196 | // Suppress the implicit declaration of a copy constructor. |
| 197 | UserDeclaredCopyAssignment = true; |
| 198 | |
| 199 | // C++ [class]p4: |
| 200 | // A POD-struct is an aggregate class that [...] has no user-defined copy |
| 201 | // assignment operator [...]. |
| 202 | PlainOldData = false; |
| 203 | } |
| 204 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 205 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
| 206 | CXXConversionDecl *ConvDecl) { |
| 207 | Conversions.addOverload(ConvDecl); |
| 208 | } |
| 209 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 210 | CXXMethodDecl * |
| 211 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 212 | SourceLocation L, DeclarationName N, |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 213 | QualType T, bool isStatic, bool isInline, |
| 214 | ScopedDecl *PrevDecl) { |
| 215 | void *Mem = C.getAllocator().Allocate<CXXMethodDecl>(); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 216 | return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline, |
| 217 | PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 221 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 222 | // If the member function is declared const, the type of this is const X*, |
| 223 | // if the member function is declared volatile, the type of this is |
| 224 | // volatile X*, and if the member function is declared const volatile, |
| 225 | // the type of this is const volatile X*. |
| 226 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 227 | assert(isInstance() && "No 'this' for static methods!"); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 228 | QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(getParent())); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 229 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
| 230 | return C.getPointerType(ClassTy).withConst(); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 233 | CXXBaseOrMemberInitializer:: |
| 234 | CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs) |
| 235 | : Args(0), NumArgs(0) { |
| 236 | BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr()); |
| 237 | assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer"); |
| 238 | BaseOrMember |= 0x01; |
| 239 | |
| 240 | if (NumArgs > 0) { |
| 241 | this->NumArgs = NumArgs; |
| 242 | this->Args = new Expr*[NumArgs]; |
| 243 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 244 | this->Args[Idx] = Args[Idx]; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | CXXBaseOrMemberInitializer:: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 249 | CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs) |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 250 | : Args(0), NumArgs(0) { |
| 251 | BaseOrMember = reinterpret_cast<uintptr_t>(Member); |
| 252 | assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer"); |
| 253 | |
| 254 | if (NumArgs > 0) { |
| 255 | this->NumArgs = NumArgs; |
| 256 | this->Args = new Expr*[NumArgs]; |
| 257 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 258 | this->Args[Idx] = Args[Idx]; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() { |
| 263 | delete [] Args; |
| 264 | } |
| 265 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 266 | CXXConstructorDecl * |
| 267 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 268 | SourceLocation L, DeclarationName N, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 269 | QualType T, bool isExplicit, |
| 270 | bool isInline, bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 271 | assert(N.getNameKind() == DeclarationName::CXXConstructorName && |
| 272 | "Name must refer to a constructor"); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 273 | void *Mem = C.getAllocator().Allocate<CXXConstructorDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 274 | return new (Mem) CXXConstructorDecl(RD, L, N, T, isExplicit, isInline, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 275 | isImplicitlyDeclared); |
| 276 | } |
| 277 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 278 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 279 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 280 | // A default constructor for a class X is a constructor of class |
| 281 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 282 | return (getNumParams() == 0) || |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 283 | (getNumParams() > 0 && getParamDecl(0)->getDefaultArg() != 0); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | bool |
| 287 | CXXConstructorDecl::isCopyConstructor(ASTContext &Context, |
| 288 | unsigned &TypeQuals) const { |
| 289 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 290 | // A non-template constructor for class X is a copy constructor |
| 291 | // if its first parameter is of type X&, const X&, volatile X& or |
| 292 | // const volatile X&, and either there are no other parameters |
| 293 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 294 | if ((getNumParams() < 1) || |
| 295 | (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() == 0)) |
| 296 | return false; |
| 297 | |
| 298 | const ParmVarDecl *Param = getParamDecl(0); |
| 299 | |
| 300 | // Do we have a reference type? |
| 301 | const ReferenceType *ParamRefType = Param->getType()->getAsReferenceType(); |
| 302 | if (!ParamRefType) |
| 303 | return false; |
| 304 | |
| 305 | // Is it a reference to our class type? |
| 306 | QualType PointeeType |
| 307 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
| 308 | QualType ClassTy |
| 309 | = Context.getTagDeclType(const_cast<CXXRecordDecl*>(getParent())); |
| 310 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 311 | return false; |
| 312 | |
| 313 | // We have a copy constructor. |
| 314 | TypeQuals = PointeeType.getCVRQualifiers(); |
| 315 | return true; |
| 316 | } |
| 317 | |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 318 | bool CXXConstructorDecl::isConvertingConstructor() const { |
| 319 | // C++ [class.conv.ctor]p1: |
| 320 | // A constructor declared without the function-specifier explicit |
| 321 | // that can be called with a single parameter specifies a |
| 322 | // conversion from the type of its first parameter to the type of |
| 323 | // its class. Such a constructor is called a converting |
| 324 | // constructor. |
| 325 | if (isExplicit()) |
| 326 | return false; |
| 327 | |
| 328 | return (getNumParams() == 0 && |
| 329 | getType()->getAsFunctionTypeProto()->isVariadic()) || |
| 330 | (getNumParams() == 1) || |
| 331 | (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() != 0); |
| 332 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 333 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 334 | CXXDestructorDecl * |
| 335 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 336 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 337 | QualType T, bool isInline, |
| 338 | bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 339 | assert(N.getNameKind() == DeclarationName::CXXDestructorName && |
| 340 | "Name must refer to a destructor"); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 341 | void *Mem = C.getAllocator().Allocate<CXXDestructorDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 342 | return new (Mem) CXXDestructorDecl(RD, L, N, T, isInline, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 343 | isImplicitlyDeclared); |
| 344 | } |
| 345 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 346 | CXXConversionDecl * |
| 347 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 348 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 349 | QualType T, bool isInline, bool isExplicit) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 350 | assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && |
| 351 | "Name must refer to a conversion function"); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 352 | void *Mem = C.getAllocator().Allocate<CXXConversionDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 353 | return new (Mem) CXXConversionDecl(RD, L, N, T, isInline, isExplicit); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 356 | CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 357 | SourceLocation L, IdentifierInfo *Id, |
| 358 | QualType T, ScopedDecl *PrevDecl) { |
| 359 | void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>(); |
| 360 | return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl); |
| 361 | } |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 362 | |
| 363 | OverloadedFunctionDecl * |
| 364 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 365 | DeclarationName N) { |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 366 | void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 367 | return new (Mem) OverloadedFunctionDecl(DC, N); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 368 | } |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 369 | |
| 370 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 371 | DeclContext *DC, |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 372 | SourceLocation L, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 373 | LanguageIDs Lang, bool Braces) { |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 374 | void *Mem = C.getAllocator().Allocate<LinkageSpecDecl>(); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 375 | return new (Mem) LinkageSpecDecl(DC, L, Lang, Braces); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 376 | } |