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