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), |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 59 | UserDeclaredDestructor(false), Aggregate(true), Polymorphic(false), |
| 60 | Bases(0), NumBases(0), |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 61 | 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 { |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 94 | QualType ClassType = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
| 95 | DeclarationName ConstructorName |
| 96 | = Context.DeclarationNames.getCXXConstructorName( |
| 97 | Context.getCanonicalType(ClassType)); |
| 98 | unsigned TypeQuals; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 99 | DeclContext::lookup_const_iterator Con, ConEnd; |
| 100 | for (llvm::tie(Con, ConEnd) = this->lookup(Context, ConstructorName); |
| 101 | Con != ConEnd; ++Con) { |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 102 | if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context, TypeQuals) && |
Eli Friedman | e8e3205 | 2008-12-16 20:06:41 +0000 | [diff] [blame] | 103 | (TypeQuals & QualType::Const) != 0) |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 104 | return true; |
| 105 | } |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 107 | return false; |
| 108 | } |
| 109 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 110 | void |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 111 | CXXRecordDecl::addedConstructor(ASTContext &Context, |
| 112 | CXXConstructorDecl *ConDecl) { |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 113 | if (!ConDecl->isImplicitlyDeclared()) { |
| 114 | // Note that we have a user-declared constructor. |
| 115 | UserDeclaredConstructor = true; |
| 116 | |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 117 | // C++ [dcl.init.aggr]p1: |
| 118 | // An aggregate is an array or a class (clause 9) with no |
| 119 | // user-declared constructors (12.1) [...]. |
| 120 | Aggregate = false; |
| 121 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 122 | // Note when we have a user-declared copy constructor, which will |
| 123 | // suppress the implicit declaration of a copy constructor. |
| 124 | if (ConDecl->isCopyConstructor(Context)) |
| 125 | UserDeclaredCopyConstructor = true; |
| 126 | } |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 129 | void CXXRecordDecl::addConversionFunction(ASTContext &Context, |
| 130 | CXXConversionDecl *ConvDecl) { |
| 131 | Conversions.addOverload(ConvDecl); |
| 132 | } |
| 133 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 134 | CXXMethodDecl * |
| 135 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 136 | SourceLocation L, DeclarationName N, |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 137 | QualType T, bool isStatic, bool isInline, |
| 138 | ScopedDecl *PrevDecl) { |
| 139 | void *Mem = C.getAllocator().Allocate<CXXMethodDecl>(); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 140 | return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline, |
| 141 | PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 145 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 146 | // If the member function is declared const, the type of this is const X*, |
| 147 | // if the member function is declared volatile, the type of this is |
| 148 | // volatile X*, and if the member function is declared const volatile, |
| 149 | // the type of this is const volatile X*. |
| 150 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 151 | assert(isInstance() && "No 'this' for static methods!"); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 152 | QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(getParent())); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 153 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
| 154 | return C.getPointerType(ClassTy).withConst(); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 157 | CXXBaseOrMemberInitializer:: |
| 158 | CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs) |
| 159 | : Args(0), NumArgs(0) { |
| 160 | BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr()); |
| 161 | assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer"); |
| 162 | BaseOrMember |= 0x01; |
| 163 | |
| 164 | if (NumArgs > 0) { |
| 165 | this->NumArgs = NumArgs; |
| 166 | this->Args = new Expr*[NumArgs]; |
| 167 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 168 | this->Args[Idx] = Args[Idx]; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | CXXBaseOrMemberInitializer:: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 173 | CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs) |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 174 | : Args(0), NumArgs(0) { |
| 175 | BaseOrMember = reinterpret_cast<uintptr_t>(Member); |
| 176 | assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer"); |
| 177 | |
| 178 | if (NumArgs > 0) { |
| 179 | this->NumArgs = NumArgs; |
| 180 | this->Args = new Expr*[NumArgs]; |
| 181 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 182 | this->Args[Idx] = Args[Idx]; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() { |
| 187 | delete [] Args; |
| 188 | } |
| 189 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 190 | CXXConstructorDecl * |
| 191 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 192 | SourceLocation L, DeclarationName N, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 193 | QualType T, bool isExplicit, |
| 194 | bool isInline, bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 195 | assert(N.getNameKind() == DeclarationName::CXXConstructorName && |
| 196 | "Name must refer to a constructor"); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 197 | void *Mem = C.getAllocator().Allocate<CXXConstructorDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 198 | return new (Mem) CXXConstructorDecl(RD, L, N, T, isExplicit, isInline, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 199 | isImplicitlyDeclared); |
| 200 | } |
| 201 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 202 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 203 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 204 | // A default constructor for a class X is a constructor of class |
| 205 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 206 | return (getNumParams() == 0) || |
Douglas Gregor | f03d7c7 | 2008-11-05 15:29:30 +0000 | [diff] [blame] | 207 | (getNumParams() > 0 && getParamDecl(0)->getDefaultArg() != 0); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | bool |
| 211 | CXXConstructorDecl::isCopyConstructor(ASTContext &Context, |
| 212 | unsigned &TypeQuals) const { |
| 213 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 214 | // A non-template constructor for class X is a copy constructor |
| 215 | // if its first parameter is of type X&, const X&, volatile X& or |
| 216 | // const volatile X&, and either there are no other parameters |
| 217 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 218 | if ((getNumParams() < 1) || |
| 219 | (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() == 0)) |
| 220 | return false; |
| 221 | |
| 222 | const ParmVarDecl *Param = getParamDecl(0); |
| 223 | |
| 224 | // Do we have a reference type? |
| 225 | const ReferenceType *ParamRefType = Param->getType()->getAsReferenceType(); |
| 226 | if (!ParamRefType) |
| 227 | return false; |
| 228 | |
| 229 | // Is it a reference to our class type? |
| 230 | QualType PointeeType |
| 231 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
| 232 | QualType ClassTy |
| 233 | = Context.getTagDeclType(const_cast<CXXRecordDecl*>(getParent())); |
| 234 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 235 | return false; |
| 236 | |
| 237 | // We have a copy constructor. |
| 238 | TypeQuals = PointeeType.getCVRQualifiers(); |
| 239 | return true; |
| 240 | } |
| 241 | |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 242 | bool CXXConstructorDecl::isConvertingConstructor() const { |
| 243 | // C++ [class.conv.ctor]p1: |
| 244 | // A constructor declared without the function-specifier explicit |
| 245 | // that can be called with a single parameter specifies a |
| 246 | // conversion from the type of its first parameter to the type of |
| 247 | // its class. Such a constructor is called a converting |
| 248 | // constructor. |
| 249 | if (isExplicit()) |
| 250 | return false; |
| 251 | |
| 252 | return (getNumParams() == 0 && |
| 253 | getType()->getAsFunctionTypeProto()->isVariadic()) || |
| 254 | (getNumParams() == 1) || |
| 255 | (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() != 0); |
| 256 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 257 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 258 | CXXDestructorDecl * |
| 259 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 260 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 261 | QualType T, bool isInline, |
| 262 | bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 263 | assert(N.getNameKind() == DeclarationName::CXXDestructorName && |
| 264 | "Name must refer to a destructor"); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 265 | void *Mem = C.getAllocator().Allocate<CXXDestructorDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 266 | return new (Mem) CXXDestructorDecl(RD, L, N, T, isInline, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 267 | isImplicitlyDeclared); |
| 268 | } |
| 269 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 270 | CXXConversionDecl * |
| 271 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 272 | SourceLocation L, DeclarationName N, |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 273 | QualType T, bool isInline, bool isExplicit) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 274 | assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && |
| 275 | "Name must refer to a conversion function"); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 276 | void *Mem = C.getAllocator().Allocate<CXXConversionDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 277 | return new (Mem) CXXConversionDecl(RD, L, N, T, isInline, isExplicit); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 280 | CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
| 281 | SourceLocation L, IdentifierInfo *Id, |
| 282 | QualType T, ScopedDecl *PrevDecl) { |
| 283 | void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>(); |
| 284 | return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl); |
| 285 | } |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 286 | |
| 287 | OverloadedFunctionDecl * |
| 288 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 289 | DeclarationName N) { |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 290 | void *Mem = C.getAllocator().Allocate<OverloadedFunctionDecl>(); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 291 | return new (Mem) OverloadedFunctionDecl(DC, N); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 292 | } |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 293 | |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 294 | LinkageSpecDecl::LinkageSpecDecl(SourceLocation L, LanguageIDs lang, |
| 295 | Decl **InDecls, unsigned InNumDecls) |
| 296 | : Decl(LinkageSpec, L), Language(lang), HadBraces(true), |
| 297 | Decls(0), NumDecls(InNumDecls) { |
| 298 | Decl **NewDecls = new Decl*[NumDecls]; |
| 299 | for (unsigned I = 0; I < NumDecls; ++I) |
| 300 | NewDecls[I] = InDecls[I]; |
| 301 | Decls = NewDecls; |
| 302 | } |
| 303 | |
| 304 | LinkageSpecDecl::~LinkageSpecDecl() { |
| 305 | if (HadBraces) |
| 306 | delete [] (Decl**)Decls; |
| 307 | } |
| 308 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 309 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
| 310 | SourceLocation L, |
| 311 | LanguageIDs Lang, Decl *D) { |
| 312 | void *Mem = C.getAllocator().Allocate<LinkageSpecDecl>(); |
| 313 | return new (Mem) LinkageSpecDecl(L, Lang, D); |
| 314 | } |
| 315 | |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 316 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
| 317 | SourceLocation L, |
| 318 | LanguageIDs Lang, |
| 319 | Decl **Decls, unsigned NumDecls) { |
| 320 | void *Mem = C.getAllocator().Allocate<LinkageSpecDecl>(); |
| 321 | return new (Mem) LinkageSpecDecl(L, Lang, Decls, NumDecls); |
| 322 | } |
| 323 | |
| 324 | LinkageSpecDecl::decl_const_iterator LinkageSpecDecl::decls_begin() const { |
| 325 | if (hasBraces()) return (Decl**)Decls; |
| 326 | else return (Decl**)&Decls; |
| 327 | } |
| 328 | |
| 329 | LinkageSpecDecl::decl_iterator LinkageSpecDecl::decls_end() const { |
| 330 | if (hasBraces()) return (Decl**)Decls + NumDecls; |
| 331 | else return (Decl**)&Decls + 1; |
| 332 | } |