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" |
Fariborz Jahanian | faebcbb | 2009-09-12 19:52:10 +0000 | [diff] [blame^] | 20 | #include "llvm/ADT/SmallPtrSet.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // Decl Allocation/Deallocation Method Implementations |
| 25 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 26 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 27 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 28 | SourceLocation L, IdentifierInfo *Id, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 29 | CXXRecordDecl *PrevDecl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 30 | SourceLocation TKL) |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 31 | : RecordDecl(K, TK, DC, L, Id, PrevDecl, TKL), |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 32 | UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 33 | UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false), |
Eli Friedman | 97c134e | 2009-08-15 22:23:00 +0000 | [diff] [blame] | 34 | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), |
| 35 | Abstract(false), HasTrivialConstructor(true), |
| 36 | HasTrivialCopyConstructor(true), HasTrivialCopyAssignment(true), |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 37 | HasTrivialDestructor(true), ComputedVisibleConversions(false), |
| 38 | Bases(0), NumBases(0), VBases(0), NumVBases(0), |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 39 | Conversions(DC, DeclarationName()), |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 40 | VisibleConversions(DC, DeclarationName()), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 41 | TemplateOrInstantiation() { } |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 42 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 43 | CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
| 44 | SourceLocation L, IdentifierInfo *Id, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 45 | SourceLocation TKL, |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 46 | CXXRecordDecl* PrevDecl, |
| 47 | bool DelayTypeCreation) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 49 | PrevDecl, TKL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 50 | |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 51 | // FIXME: DelayTypeCreation seems like such a hack |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 52 | if (!DelayTypeCreation) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | C.getTypeDeclType(R, PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 54 | return R; |
| 55 | } |
| 56 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 57 | CXXRecordDecl::~CXXRecordDecl() { |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void CXXRecordDecl::Destroy(ASTContext &C) { |
| 61 | C.Deallocate(Bases); |
Fariborz Jahanian | 71c6e71 | 2009-07-22 17:41:53 +0000 | [diff] [blame] | 62 | C.Deallocate(VBases); |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 63 | this->RecordDecl::Destroy(C); |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 66 | void |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 67 | CXXRecordDecl::setBases(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | CXXBaseSpecifier const * const *Bases, |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 69 | unsigned NumBases) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | // C++ [dcl.init.aggr]p1: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 71 | // An aggregate is an array or a class (clause 9) with [...] |
| 72 | // no base classes [...]. |
| 73 | Aggregate = false; |
| 74 | |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 75 | if (this->Bases) |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 76 | C.Deallocate(this->Bases); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 78 | int vbaseCount = 0; |
| 79 | llvm::SmallVector<const CXXBaseSpecifier*, 8> UniqueVbases; |
| 80 | bool hasDirectVirtualBase = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | |
Fariborz Jahanian | 5ffcd7b | 2009-07-02 18:26:15 +0000 | [diff] [blame] | 82 | this->Bases = new(C) CXXBaseSpecifier [NumBases]; |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 83 | this->NumBases = NumBases; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 84 | for (unsigned i = 0; i < NumBases; ++i) { |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 85 | this->Bases[i] = *Bases[i]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 86 | // Keep track of inherited vbases for this base class. |
| 87 | const CXXBaseSpecifier *Base = Bases[i]; |
| 88 | QualType BaseType = Base->getType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | // Skip template types. |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 90 | // FIXME. This means that this list must be rebuilt during template |
| 91 | // instantiation. |
| 92 | if (BaseType->isDependentType()) |
| 93 | continue; |
| 94 | CXXRecordDecl *BaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 95 | = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 96 | if (Base->isVirtual()) |
| 97 | hasDirectVirtualBase = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | for (CXXRecordDecl::base_class_iterator VBase = |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 99 | BaseClassDecl->vbases_begin(), |
| 100 | E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | // Add this vbase to the array of vbases for current class if it is |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 102 | // not already in the list. |
| 103 | // FIXME. Note that we do a linear search as number of such classes are |
| 104 | // very few. |
| 105 | int i; |
| 106 | for (i = 0; i < vbaseCount; ++i) |
| 107 | if (UniqueVbases[i]->getType() == VBase->getType()) |
| 108 | break; |
| 109 | if (i == vbaseCount) { |
| 110 | UniqueVbases.push_back(VBase); |
| 111 | ++vbaseCount; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | if (hasDirectVirtualBase) { |
| 116 | // Iterate one more time through the direct bases and add the virtual |
| 117 | // base to the list of vritual bases for current class. |
| 118 | for (unsigned i = 0; i < NumBases; ++i) { |
| 119 | const CXXBaseSpecifier *VBase = Bases[i]; |
| 120 | if (!VBase->isVirtual()) |
| 121 | continue; |
Alisdair Meredith | 002b91f | 2009-07-11 14:32:10 +0000 | [diff] [blame] | 122 | int j; |
| 123 | for (j = 0; j < vbaseCount; ++j) |
| 124 | if (UniqueVbases[j]->getType() == VBase->getType()) |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 125 | break; |
Alisdair Meredith | 002b91f | 2009-07-11 14:32:10 +0000 | [diff] [blame] | 126 | if (j == vbaseCount) { |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 127 | UniqueVbases.push_back(VBase); |
| 128 | ++vbaseCount; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | if (vbaseCount > 0) { |
| 133 | // build AST for inhireted, direct or indirect, virtual bases. |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 134 | this->VBases = new (C) CXXBaseSpecifier [vbaseCount]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 135 | this->NumVBases = vbaseCount; |
| 136 | for (int i = 0; i < vbaseCount; i++) { |
| 137 | QualType QT = UniqueVbases[i]->getType(); |
| 138 | CXXRecordDecl *VBaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 139 | = cast<CXXRecordDecl>(QT->getAs<RecordType>()->getDecl()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 140 | this->VBases[i] = |
Douglas Gregor | 2aef06d | 2009-07-22 20:55:49 +0000 | [diff] [blame] | 141 | CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true, |
| 142 | VBaseClassDecl->getTagKind() == RecordDecl::TK_class, |
| 143 | UniqueVbases[i]->getAccessSpecifier(), QT); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 148 | bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const { |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 149 | return getCopyConstructor(Context, QualType::Const) != 0; |
| 150 | } |
| 151 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 152 | CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context, |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 153 | unsigned TypeQuals) const{ |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 154 | QualType ClassType |
| 155 | = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | DeclarationName ConstructorName |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 157 | = Context.DeclarationNames.getCXXConstructorName( |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 158 | Context.getCanonicalType(ClassType)); |
| 159 | unsigned FoundTQs; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 160 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 161 | for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 162 | Con != ConEnd; ++Con) { |
Douglas Gregor | d93bacf | 2009-09-04 14:46:39 +0000 | [diff] [blame] | 163 | // C++ [class.copy]p2: |
| 164 | // A non-template constructor for class X is a copy constructor if [...] |
| 165 | if (isa<FunctionTemplateDecl>(*Con)) |
| 166 | continue; |
| 167 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context, |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 169 | FoundTQs)) { |
| 170 | if (((TypeQuals & QualType::Const) == (FoundTQs & QualType::Const)) || |
| 171 | (!(TypeQuals & QualType::Const) && (FoundTQs & QualType::Const))) |
| 172 | return cast<CXXConstructorDecl>(*Con); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 174 | } |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 175 | } |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 176 | return 0; |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Fariborz Jahanian | 0270b8a | 2009-08-12 23:34:46 +0000 | [diff] [blame] | 179 | bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context, |
| 180 | const CXXMethodDecl *& MD) const { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 181 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 182 | const_cast<CXXRecordDecl*>(this))); |
| 183 | DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 184 | |
| 185 | DeclContext::lookup_const_iterator Op, OpEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 186 | for (llvm::tie(Op, OpEnd) = this->lookup(OpName); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 187 | Op != OpEnd; ++Op) { |
| 188 | // C++ [class.copy]p9: |
| 189 | // A user-declared copy assignment operator is a non-static non-template |
| 190 | // member function of class X with exactly one parameter of type X, X&, |
| 191 | // const X&, volatile X& or const volatile X&. |
| 192 | const CXXMethodDecl* Method = cast<CXXMethodDecl>(*Op); |
| 193 | if (Method->isStatic()) |
| 194 | continue; |
| 195 | // TODO: Skip templates? Or is this implicitly done due to parameter types? |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 196 | const FunctionProtoType *FnType = |
| 197 | Method->getType()->getAsFunctionProtoType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 198 | assert(FnType && "Overloaded operator has no prototype."); |
| 199 | // Don't assert on this; an invalid decl might have been left in the AST. |
| 200 | if (FnType->getNumArgs() != 1 || FnType->isVariadic()) |
| 201 | continue; |
| 202 | bool AcceptsConst = true; |
| 203 | QualType ArgType = FnType->getArgType(0); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 204 | if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 205 | ArgType = Ref->getPointeeType(); |
Douglas Gregor | 2ff4478 | 2009-03-20 20:21:37 +0000 | [diff] [blame] | 206 | // Is it a non-const lvalue reference? |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 207 | if (!ArgType.isConstQualified()) |
| 208 | AcceptsConst = false; |
| 209 | } |
| 210 | if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType) |
| 211 | continue; |
Fariborz Jahanian | 0270b8a | 2009-08-12 23:34:46 +0000 | [diff] [blame] | 212 | MD = Method; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 213 | // We have a single argument of type cv X or cv X&, i.e. we've found the |
| 214 | // copy assignment operator. Return whether it accepts const arguments. |
| 215 | return AcceptsConst; |
| 216 | } |
| 217 | assert(isInvalidDecl() && |
| 218 | "No copy assignment operator declared in valid code."); |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | void |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 223 | CXXRecordDecl::addedConstructor(ASTContext &Context, |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 224 | CXXConstructorDecl *ConDecl) { |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 225 | assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl"); |
| 226 | // Note that we have a user-declared constructor. |
| 227 | UserDeclaredConstructor = true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 228 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 229 | // C++ [dcl.init.aggr]p1: |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 230 | // An aggregate is an array or a class (clause 9) with no |
| 231 | // user-declared constructors (12.1) [...]. |
| 232 | Aggregate = false; |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 233 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 234 | // C++ [class]p4: |
| 235 | // A POD-struct is an aggregate class [...] |
| 236 | PlainOldData = false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 237 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 238 | // C++ [class.ctor]p5: |
| 239 | // A constructor is trivial if it is an implicitly-declared default |
| 240 | // constructor. |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 241 | // FIXME: C++0x: don't do this for "= default" default constructors. |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 242 | HasTrivialConstructor = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 243 | |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 244 | // Note when we have a user-declared copy constructor, which will |
| 245 | // suppress the implicit declaration of a copy constructor. |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 246 | if (ConDecl->isCopyConstructor(Context)) { |
Fariborz Jahanian | 8bc3fa4 | 2009-06-17 22:44:31 +0000 | [diff] [blame] | 247 | UserDeclaredCopyConstructor = true; |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 248 | |
| 249 | // C++ [class.copy]p6: |
| 250 | // A copy constructor is trivial if it is implicitly declared. |
| 251 | // FIXME: C++0x: don't do this for "= default" copy constructors. |
| 252 | HasTrivialCopyConstructor = false; |
| 253 | } |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 256 | void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context, |
| 257 | CXXMethodDecl *OpDecl) { |
| 258 | // We're interested specifically in copy assignment operators. |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 259 | const FunctionProtoType *FnType = OpDecl->getType()->getAsFunctionProtoType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 260 | assert(FnType && "Overloaded operator has no proto function type."); |
| 261 | assert(FnType->getNumArgs() == 1 && !FnType->isVariadic()); |
| 262 | QualType ArgType = FnType->getArgType(0); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 263 | if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 264 | ArgType = Ref->getPointeeType(); |
| 265 | |
| 266 | ArgType = ArgType.getUnqualifiedType(); |
| 267 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 268 | const_cast<CXXRecordDecl*>(this))); |
| 269 | |
| 270 | if (ClassType != Context.getCanonicalType(ArgType)) |
| 271 | return; |
| 272 | |
| 273 | // This is a copy assignment operator. |
| 274 | // Suppress the implicit declaration of a copy constructor. |
| 275 | UserDeclaredCopyAssignment = true; |
| 276 | |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 277 | // C++ [class.copy]p11: |
| 278 | // A copy assignment operator is trivial if it is implicitly declared. |
| 279 | // FIXME: C++0x: don't do this for "= default" copy operators. |
| 280 | HasTrivialCopyAssignment = false; |
| 281 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 282 | // C++ [class]p4: |
| 283 | // A POD-struct is an aggregate class that [...] has no user-defined copy |
| 284 | // assignment operator [...]. |
| 285 | PlainOldData = false; |
| 286 | } |
| 287 | |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 288 | /// getNestedVisibleConversionFunctions - imports unique conversion |
| 289 | /// functions from base classes into the visible conversion function |
| 290 | /// list of the class 'RD'. This is a private helper method. |
| 291 | void |
| 292 | CXXRecordDecl::getNestedVisibleConversionFunctions(CXXRecordDecl *RD) { |
| 293 | QualType ClassType = getASTContext().getTypeDeclType(this); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 294 | if (const RecordType *Record = ClassType->getAs<RecordType>()) { |
| 295 | OverloadedFunctionDecl *Conversions |
| 296 | = cast<CXXRecordDecl>(Record->getDecl())->getConversionFunctions(); |
Fariborz Jahanian | faebcbb | 2009-09-12 19:52:10 +0000 | [diff] [blame^] | 297 | llvm::SmallPtrSet<QualType, 8> TopConversionsTypeSet; |
| 298 | bool inTopClass = (RD == this); |
| 299 | if (!inTopClass && |
| 300 | (Conversions->function_begin() != Conversions->function_end())) { |
| 301 | // populate the TypeSet with the type of current class's conversions. |
| 302 | OverloadedFunctionDecl *TopConversions = RD->getConversionFunctions(); |
| 303 | for (OverloadedFunctionDecl::function_iterator |
| 304 | TFunc = TopConversions->function_begin(), |
| 305 | TFuncEnd = TopConversions->function_end(); |
| 306 | TFunc != TFuncEnd; ++TFunc) { |
| 307 | NamedDecl *TopConv = TFunc->get(); |
| 308 | QualType TConvType; |
| 309 | if (FunctionTemplateDecl *TConversionTemplate = |
| 310 | dyn_cast<FunctionTemplateDecl>(TopConv)) |
| 311 | TConvType = |
| 312 | getASTContext().getCanonicalType( |
| 313 | TConversionTemplate->getTemplatedDecl()->getType()); |
| 314 | else |
| 315 | TConvType = |
| 316 | getASTContext().getCanonicalType( |
| 317 | cast<FunctionDecl>(TopConv)->getType()); |
| 318 | TopConversionsTypeSet.insert(TConvType); |
| 319 | } |
| 320 | } |
| 321 | |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 322 | for (OverloadedFunctionDecl::function_iterator |
| 323 | Func = Conversions->function_begin(), |
| 324 | FuncEnd = Conversions->function_end(); |
| 325 | Func != FuncEnd; ++Func) { |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 326 | NamedDecl *Conv = Func->get(); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 327 | // Only those conversions not exact match of conversions in current |
| 328 | // class are candidateconversion routines. |
Fariborz Jahanian | faebcbb | 2009-09-12 19:52:10 +0000 | [diff] [blame^] | 329 | QualType ConvType; |
| 330 | if (FunctionTemplateDecl *ConversionTemplate = |
| 331 | dyn_cast<FunctionTemplateDecl>(Conv)) |
| 332 | ConvType = |
| 333 | getASTContext().getCanonicalType( |
| 334 | ConversionTemplate->getTemplatedDecl()->getType()); |
| 335 | else |
| 336 | ConvType = |
| 337 | getASTContext().getCanonicalType(cast<FunctionDecl>(Conv)->getType()); |
| 338 | if (inTopClass || !TopConversionsTypeSet.count(ConvType)) { |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 339 | if (FunctionTemplateDecl *ConversionTemplate = |
| 340 | dyn_cast<FunctionTemplateDecl>(Conv)) |
| 341 | RD->addVisibleConversionFunction(ConversionTemplate); |
| 342 | else |
| 343 | RD->addVisibleConversionFunction(cast<CXXConversionDecl>(Conv)); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | for (CXXRecordDecl::base_class_iterator VBase = vbases_begin(), |
| 349 | E = vbases_end(); VBase != E; ++VBase) { |
| 350 | CXXRecordDecl *VBaseClassDecl |
| 351 | = cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 352 | VBaseClassDecl->getNestedVisibleConversionFunctions(RD); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 353 | } |
| 354 | for (CXXRecordDecl::base_class_iterator Base = bases_begin(), |
| 355 | E = bases_end(); Base != E; ++Base) { |
| 356 | if (Base->isVirtual()) |
| 357 | continue; |
| 358 | CXXRecordDecl *BaseClassDecl |
| 359 | = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 360 | BaseClassDecl->getNestedVisibleConversionFunctions(RD); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 361 | } |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /// getVisibleConversionFunctions - get all conversion functions visible |
| 365 | /// in current class; including conversion function templates. |
| 366 | OverloadedFunctionDecl * |
| 367 | CXXRecordDecl::getVisibleConversionFunctions() { |
| 368 | // If root class, all conversions are visible. |
| 369 | if (bases_begin() == bases_end()) |
| 370 | return &Conversions; |
| 371 | // If visible conversion list is already evaluated, return it. |
| 372 | if (ComputedVisibleConversions) |
| 373 | return &VisibleConversions; |
| 374 | getNestedVisibleConversionFunctions(this); |
| 375 | ComputedVisibleConversions = true; |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 376 | return &VisibleConversions; |
| 377 | } |
| 378 | |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 379 | void CXXRecordDecl::addVisibleConversionFunction( |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 380 | CXXConversionDecl *ConvDecl) { |
| 381 | assert(!ConvDecl->getDescribedFunctionTemplate() && |
| 382 | "Conversion function templates should cast to FunctionTemplateDecl."); |
| 383 | VisibleConversions.addOverload(ConvDecl); |
| 384 | } |
| 385 | |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 386 | void CXXRecordDecl::addVisibleConversionFunction( |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 387 | FunctionTemplateDecl *ConvDecl) { |
| 388 | assert(isa<CXXConversionDecl>(ConvDecl->getTemplatedDecl()) && |
| 389 | "Function template is not a conversion function template"); |
| 390 | VisibleConversions.addOverload(ConvDecl); |
| 391 | } |
| 392 | |
Fariborz Jahanian | debc629 | 2009-09-12 19:02:34 +0000 | [diff] [blame] | 393 | void CXXRecordDecl::addConversionFunction(CXXConversionDecl *ConvDecl) { |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 394 | assert(!ConvDecl->getDescribedFunctionTemplate() && |
| 395 | "Conversion function templates should cast to FunctionTemplateDecl."); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 396 | Conversions.addOverload(ConvDecl); |
| 397 | } |
| 398 | |
Fariborz Jahanian | debc629 | 2009-09-12 19:02:34 +0000 | [diff] [blame] | 399 | void CXXRecordDecl::addConversionFunction(FunctionTemplateDecl *ConvDecl) { |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 400 | assert(isa<CXXConversionDecl>(ConvDecl->getTemplatedDecl()) && |
| 401 | "Function template is not a conversion function template"); |
| 402 | Conversions.addOverload(ConvDecl); |
| 403 | } |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 404 | |
| 405 | CXXConstructorDecl * |
| 406 | CXXRecordDecl::getDefaultConstructor(ASTContext &Context) { |
| 407 | QualType ClassType = Context.getTypeDeclType(this); |
| 408 | DeclarationName ConstructorName |
| 409 | = Context.DeclarationNames.getCXXConstructorName( |
| 410 | Context.getCanonicalType(ClassType.getUnqualifiedType())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 412 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 413 | for (llvm::tie(Con, ConEnd) = lookup(ConstructorName); |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 414 | Con != ConEnd; ++Con) { |
Douglas Gregor | d93bacf | 2009-09-04 14:46:39 +0000 | [diff] [blame] | 415 | // FIXME: In C++0x, a constructor template can be a default constructor. |
| 416 | if (isa<FunctionTemplateDecl>(*Con)) |
| 417 | continue; |
| 418 | |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 419 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 420 | if (Constructor->isDefaultConstructor()) |
| 421 | return Constructor; |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 426 | const CXXDestructorDecl * |
| 427 | CXXRecordDecl::getDestructor(ASTContext &Context) { |
| 428 | QualType ClassType = Context.getTypeDeclType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | |
| 430 | DeclarationName Name |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 431 | = Context.DeclarationNames.getCXXDestructorName( |
| 432 | Context.getCanonicalType(ClassType)); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 433 | |
| 434 | DeclContext::lookup_iterator I, E; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | llvm::tie(I, E) = lookup(Name); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 436 | assert(I != E && "Did not find a destructor!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 438 | const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); |
| 439 | assert(++I == E && "Found more than one destructor!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 441 | return Dtor; |
| 442 | } |
| 443 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 444 | CXXMethodDecl * |
| 445 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 446 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 447 | QualType T, DeclaratorInfo *DInfo, |
| 448 | bool isStatic, bool isInline) { |
| 449 | return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, DInfo, |
| 450 | isStatic, isInline); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 453 | typedef llvm::DenseMap<const CXXMethodDecl*, |
| 454 | std::vector<const CXXMethodDecl *> *> |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 455 | OverriddenMethodsMapTy; |
| 456 | |
Mike Stump | b9871a2 | 2009-08-21 01:45:00 +0000 | [diff] [blame] | 457 | // FIXME: We hate static data. This doesn't survive PCH saving/loading, and |
| 458 | // the vtable building code uses it at CG time. |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 459 | static OverriddenMethodsMapTy *OverriddenMethods = 0; |
| 460 | |
| 461 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
| 462 | // FIXME: The CXXMethodDecl dtor needs to remove and free the entry. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 464 | if (!OverriddenMethods) |
| 465 | OverriddenMethods = new OverriddenMethodsMapTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 467 | std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this]; |
| 468 | if (!Methods) |
| 469 | Methods = new std::vector<const CXXMethodDecl *>; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 470 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 471 | Methods->push_back(MD); |
| 472 | } |
| 473 | |
| 474 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
| 475 | if (!OverriddenMethods) |
| 476 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 478 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 479 | if (it == OverriddenMethods->end() || it->second->empty()) |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 480 | return 0; |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 481 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 482 | return &(*it->second)[0]; |
| 483 | } |
| 484 | |
| 485 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
| 486 | if (!OverriddenMethods) |
| 487 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 489 | OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this); |
Daniel Dunbar | 0908c33 | 2009-08-01 23:40:20 +0000 | [diff] [blame] | 490 | if (it == OverriddenMethods->end() || it->second->empty()) |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 491 | return 0; |
| 492 | |
Daniel Dunbar | 637ec32 | 2009-08-02 01:48:29 +0000 | [diff] [blame] | 493 | return &(*it->second)[0] + it->second->size(); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 496 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 497 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 498 | // If the member function is declared const, the type of this is const X*, |
| 499 | // if the member function is declared volatile, the type of this is |
| 500 | // volatile X*, and if the member function is declared const volatile, |
| 501 | // the type of this is const volatile X*. |
| 502 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 503 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 504 | |
| 505 | QualType ClassTy; |
| 506 | if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate()) |
| 507 | ClassTy = TD->getInjectedClassNameType(C); |
| 508 | else |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 509 | ClassTy = C.getTagDeclType(getParent()); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 510 | ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers()); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 511 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 514 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 515 | CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 516 | CXXConstructorDecl *C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | SourceLocation L, SourceLocation R) |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 518 | : Args(0), NumArgs(0), CtorOrAnonUnion(), IdLoc(L), RParenLoc(R) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 519 | BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr()); |
| 520 | assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer"); |
| 521 | BaseOrMember |= 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 523 | if (NumArgs > 0) { |
| 524 | this->NumArgs = NumArgs; |
Fariborz Jahanian | 50b8eea | 2009-07-24 17:57:02 +0000 | [diff] [blame] | 525 | // FIXME. Allocation via Context |
| 526 | this->Args = new Stmt*[NumArgs]; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 527 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 528 | this->Args[Idx] = Args[Idx]; |
| 529 | } |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 530 | CtorOrAnonUnion = C; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | CXXBaseOrMemberInitializer:: |
Fariborz Jahanian | 47deacf | 2009-06-30 00:02:17 +0000 | [diff] [blame] | 534 | CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs, |
Fariborz Jahanian | d7b27e1 | 2009-07-23 00:42:24 +0000 | [diff] [blame] | 535 | CXXConstructorDecl *C, |
Anders Carlsson | 8c57a66 | 2009-08-29 01:31:33 +0000 | [diff] [blame] | 536 | SourceLocation L, SourceLocation R) |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 537 | : Args(0), NumArgs(0), CtorOrAnonUnion(), IdLoc(L), RParenLoc(R) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 538 | BaseOrMember = reinterpret_cast<uintptr_t>(Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer"); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 540 | |
| 541 | if (NumArgs > 0) { |
| 542 | this->NumArgs = NumArgs; |
Fariborz Jahanian | 50b8eea | 2009-07-24 17:57:02 +0000 | [diff] [blame] | 543 | this->Args = new Stmt*[NumArgs]; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 544 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 545 | this->Args[Idx] = Args[Idx]; |
| 546 | } |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 547 | CtorOrAnonUnion = C; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() { |
| 551 | delete [] Args; |
| 552 | } |
| 553 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 554 | CXXConstructorDecl * |
| 555 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 556 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 557 | QualType T, DeclaratorInfo *DInfo, |
| 558 | bool isExplicit, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 559 | bool isInline, bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 560 | assert(N.getNameKind() == DeclarationName::CXXConstructorName && |
| 561 | "Name must refer to a constructor"); |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 562 | return new (C) CXXConstructorDecl(RD, L, N, T, DInfo, isExplicit, isInline, |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 563 | isImplicitlyDeclared); |
| 564 | } |
| 565 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 566 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 567 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 568 | // A default constructor for a class X is a constructor of class |
| 569 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 570 | return (getNumParams() == 0) || |
Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame] | 571 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | bool |
| 575 | CXXConstructorDecl::isCopyConstructor(ASTContext &Context, |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 576 | unsigned &TypeQuals) const { |
| 577 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 578 | // A non-template constructor for class X is a copy constructor |
| 579 | // if its first parameter is of type X&, const X&, volatile X& or |
| 580 | // const volatile X&, and either there are no other parameters |
| 581 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 582 | if ((getNumParams() < 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 583 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg())) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 584 | return false; |
| 585 | |
| 586 | const ParmVarDecl *Param = getParamDecl(0); |
| 587 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 588 | // Do we have a reference type? Rvalue references don't count. |
| 589 | const LValueReferenceType *ParamRefType = |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 590 | Param->getType()->getAs<LValueReferenceType>(); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 591 | if (!ParamRefType) |
| 592 | return false; |
| 593 | |
| 594 | // Is it a reference to our class type? |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 595 | QualType PointeeType |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 596 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
Mike Stump | e607ed0 | 2009-08-07 18:05:12 +0000 | [diff] [blame] | 597 | QualType ClassTy = Context.getTagDeclType(getParent()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 598 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 599 | return false; |
| 600 | |
| 601 | // We have a copy constructor. |
| 602 | TypeQuals = PointeeType.getCVRQualifiers(); |
| 603 | return true; |
| 604 | } |
| 605 | |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 606 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 607 | // C++ [class.conv.ctor]p1: |
| 608 | // A constructor declared without the function-specifier explicit |
| 609 | // that can be called with a single parameter specifies a |
| 610 | // conversion from the type of its first parameter to the type of |
| 611 | // its class. Such a constructor is called a converting |
| 612 | // constructor. |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 613 | if (isExplicit() && !AllowExplicit) |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 614 | return false; |
| 615 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | return (getNumParams() == 0 && |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 617 | getType()->getAsFunctionProtoType()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 618 | (getNumParams() == 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 619 | (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 620 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 622 | CXXDestructorDecl * |
| 623 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 624 | SourceLocation L, DeclarationName N, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | QualType T, bool isInline, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 626 | bool isImplicitlyDeclared) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 627 | assert(N.getNameKind() == DeclarationName::CXXDestructorName && |
| 628 | "Name must refer to a destructor"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 629 | return new (C) CXXDestructorDecl(RD, L, N, T, isInline, |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 630 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Fariborz Jahanian | d45c363 | 2009-07-01 21:05:43 +0000 | [diff] [blame] | 633 | void |
Fariborz Jahanian | 393612e | 2009-07-21 22:36:06 +0000 | [diff] [blame] | 634 | CXXDestructorDecl::Destroy(ASTContext& C) { |
| 635 | C.Deallocate(BaseOrMemberDestructions); |
| 636 | CXXMethodDecl::Destroy(C); |
| 637 | } |
| 638 | |
| 639 | void |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 640 | CXXConstructorDecl::Destroy(ASTContext& C) { |
| 641 | C.Deallocate(BaseOrMemberInitializers); |
Fariborz Jahanian | 0d3c26c | 2009-07-07 16:24:08 +0000 | [diff] [blame] | 642 | CXXMethodDecl::Destroy(C); |
Fariborz Jahanian | 73b85f3 | 2009-07-01 23:35:25 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 645 | CXXConversionDecl * |
| 646 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 647 | SourceLocation L, DeclarationName N, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 648 | QualType T, DeclaratorInfo *DInfo, |
| 649 | bool isInline, bool isExplicit) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 650 | assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName && |
| 651 | "Name must refer to a conversion function"); |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 652 | return new (C) CXXConversionDecl(RD, L, N, T, DInfo, isInline, isExplicit); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 655 | OverloadedFunctionDecl * |
| 656 | OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 657 | DeclarationName N) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 658 | return new (C) OverloadedFunctionDecl(DC, N); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 659 | } |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 661 | OverloadIterator::OverloadIterator(NamedDecl *ND) : D(0) { |
| 662 | if (!ND) |
| 663 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 665 | if (isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND)) |
| 666 | D = ND; |
| 667 | else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(ND)) { |
Douglas Gregor | 8f1d89e | 2009-09-01 16:58:52 +0000 | [diff] [blame] | 668 | if (Ovl->size() != 0) { |
| 669 | D = ND; |
| 670 | Iter = Ovl->function_begin(); |
| 671 | } |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Douglas Gregor | 364e021 | 2009-06-27 21:05:07 +0000 | [diff] [blame] | 675 | void OverloadedFunctionDecl::addOverload(AnyFunctionDecl F) { |
| 676 | Functions.push_back(F); |
| 677 | this->setLocation(F.get()->getLocation()); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 680 | OverloadIterator::reference OverloadIterator::operator*() const { |
| 681 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 682 | return FD; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 684 | if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 685 | return FTD; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 687 | assert(isa<OverloadedFunctionDecl>(D)); |
| 688 | return *Iter; |
| 689 | } |
| 690 | |
| 691 | OverloadIterator &OverloadIterator::operator++() { |
| 692 | if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) { |
| 693 | D = 0; |
| 694 | return *this; |
| 695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 697 | if (++Iter == cast<OverloadedFunctionDecl>(D)->function_end()) |
| 698 | D = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 699 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 700 | return *this; |
| 701 | } |
| 702 | |
| 703 | bool OverloadIterator::Equals(const OverloadIterator &Other) const { |
| 704 | if (!D || !Other.D) |
| 705 | return D == Other.D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 707 | if (D != Other.D) |
| 708 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 709 | |
Douglas Gregor | daa439a | 2009-07-08 10:57:20 +0000 | [diff] [blame] | 710 | return !isa<OverloadedFunctionDecl>(D) || Iter == Other.Iter; |
| 711 | } |
| 712 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 713 | FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC, |
| 714 | SourceLocation L, |
| 715 | FriendUnion Friend, |
| 716 | SourceLocation FriendL) { |
Daniel Dunbar | e32ecce | 2009-08-31 19:16:38 +0000 | [diff] [blame] | 717 | #ifndef NDEBUG |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 718 | if (Friend.is<NamedDecl*>()) { |
| 719 | NamedDecl *D = Friend.get<NamedDecl*>(); |
| 720 | assert(isa<FunctionDecl>(D) || |
| 721 | isa<CXXRecordDecl>(D) || |
| 722 | isa<FunctionTemplateDecl>(D) || |
| 723 | isa<ClassTemplateDecl>(D)); |
| 724 | assert(D->getFriendObjectKind()); |
| 725 | } |
Daniel Dunbar | e32ecce | 2009-08-31 19:16:38 +0000 | [diff] [blame] | 726 | #endif |
John McCall | c48fbdf | 2009-08-11 21:13:21 +0000 | [diff] [blame] | 727 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 728 | return new (C) FriendDecl(DC, L, Friend, FriendL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | } |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 730 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 731 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | DeclContext *DC, |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 733 | SourceLocation L, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 734 | LanguageIDs Lang, bool Braces) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 735 | return new (C) LinkageSpecDecl(DC, L, Lang, Braces); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 736 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 737 | |
| 738 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 739 | SourceLocation L, |
| 740 | SourceLocation NamespaceLoc, |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 741 | SourceRange QualifierRange, |
| 742 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 743 | SourceLocation IdentLoc, |
| 744 | NamespaceDecl *Used, |
| 745 | DeclContext *CommonAncestor) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange, |
Douglas Gregor | 8419fa3 | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 747 | Qualifier, IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 751 | SourceLocation L, |
| 752 | SourceLocation AliasLoc, |
| 753 | IdentifierInfo *Alias, |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 754 | SourceRange QualifierRange, |
| 755 | NestedNameSpecifier *Qualifier, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | SourceLocation IdentLoc, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 757 | NamedDecl *Namespace) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange, |
Douglas Gregor | 6c9c940 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 759 | Qualifier, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 762 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, |
| 763 | SourceLocation L, SourceRange NNR, SourceLocation TargetNL, |
| 764 | SourceLocation UL, NamedDecl* Target, |
| 765 | NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) { |
| 766 | return new (C) UsingDecl(DC, L, NNR, TargetNL, UL, Target, |
| 767 | TargetNNS, IsTypeNameArg); |
| 768 | } |
| 769 | |
Anders Carlsson | 665b49c | 2009-08-28 05:30:28 +0000 | [diff] [blame] | 770 | UnresolvedUsingDecl *UnresolvedUsingDecl::Create(ASTContext &C, DeclContext *DC, |
| 771 | SourceLocation UsingLoc, |
| 772 | SourceRange TargetNNR, |
| 773 | NestedNameSpecifier *TargetNNS, |
| 774 | SourceLocation TargetNameLoc, |
| 775 | DeclarationName TargetName, |
| 776 | bool IsTypeNameArg) { |
| 777 | return new (C) UnresolvedUsingDecl(DC, UsingLoc, TargetNNR, TargetNNS, |
| 778 | TargetNameLoc, TargetName, IsTypeNameArg); |
| 779 | } |
| 780 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 781 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
| 782 | SourceLocation L, Expr *AssertExpr, |
| 783 | StringLiteral *Message) { |
| 784 | return new (C) StaticAssertDecl(DC, L, AssertExpr, Message); |
| 785 | } |
| 786 | |
| 787 | void StaticAssertDecl::Destroy(ASTContext& C) { |
| 788 | AssertExpr->Destroy(C); |
| 789 | Message->Destroy(C); |
| 790 | this->~StaticAssertDecl(); |
| 791 | C.Deallocate((void *)this); |
| 792 | } |
| 793 | |
| 794 | StaticAssertDecl::~StaticAssertDecl() { |
| 795 | } |
| 796 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 797 | static const char *getAccessName(AccessSpecifier AS) { |
| 798 | switch (AS) { |
| 799 | default: |
| 800 | case AS_none: |
| 801 | assert("Invalid access specifier!"); |
| 802 | return 0; |
| 803 | case AS_public: |
| 804 | return "public"; |
| 805 | case AS_private: |
| 806 | return "private"; |
| 807 | case AS_protected: |
| 808 | return "protected"; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 813 | AccessSpecifier AS) { |
| 814 | return DB << getAccessName(AS); |
| 815 | } |
| 816 | |
| 817 | |