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