| 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" | 
| Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" | 
| Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 18 | #include "clang/AST/CXXInheritance.h" | 
| Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 20 | #include "clang/AST/TypeLoc.h" | 
| Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 21 | #include "clang/Basic/IdentifierTable.h" | 
| Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" | 
| Fariborz Jahanian | faebcbb | 2009-09-12 19:52:10 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallPtrSet.h" | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 24 | using namespace clang; | 
 | 25 |  | 
 | 26 | //===----------------------------------------------------------------------===// | 
 | 27 | // Decl Allocation/Deallocation Method Implementations | 
 | 28 | //===----------------------------------------------------------------------===// | 
| Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 29 |  | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 30 | CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) | 
 | 31 |   : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), | 
| Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 32 |     UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false), | 
| Eli Friedman | 97c134e | 2009-08-15 22:23:00 +0000 | [diff] [blame] | 33 |     Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), | 
 | 34 |     Abstract(false), HasTrivialConstructor(true), | 
 | 35 |     HasTrivialCopyConstructor(true), HasTrivialCopyAssignment(true), | 
| Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 36 |     HasTrivialDestructor(true), ComputedVisibleConversions(false), | 
| Douglas Gregor | 1827403 | 2010-07-03 00:47:00 +0000 | [diff] [blame] | 37 |     DeclaredDefaultConstructor(false), DeclaredCopyConstructor(false),  | 
| Douglas Gregor | a376d10 | 2010-07-02 21:50:04 +0000 | [diff] [blame] | 38 |     DeclaredCopyAssignment(false), DeclaredDestructor(false), | 
| Anders Carlsson | cb88a1f | 2011-01-24 16:26:15 +0000 | [diff] [blame] | 39 |     NumBases(0), NumVBases(0), Bases(), VBases(), | 
 | 40 |   Definition(D), FirstFriend(0) { | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 41 | } | 
 | 42 |  | 
 | 43 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, | 
 | 44 |                              SourceLocation L, IdentifierInfo *Id, | 
 | 45 |                              CXXRecordDecl *PrevDecl, | 
 | 46 |                              SourceLocation TKL) | 
 | 47 |   : RecordDecl(K, TK, DC, L, Id, PrevDecl, TKL), | 
 | 48 |     DefinitionData(PrevDecl ? PrevDecl->DefinitionData : 0), | 
| Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 49 |     TemplateOrInstantiation() { } | 
| Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 50 |  | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 51 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, | 
 | 52 |                                      DeclContext *DC, SourceLocation L, | 
 | 53 |                                      IdentifierInfo *Id, SourceLocation TKL, | 
| Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 54 |                                      CXXRecordDecl* PrevDecl, | 
 | 55 |                                      bool DelayTypeCreation) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 |   CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id, | 
| Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 57 |                                            PrevDecl, TKL); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 58 |  | 
| Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 59 |   // FIXME: DelayTypeCreation seems like such a hack | 
| Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 60 |   if (!DelayTypeCreation) | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 61 |     C.getTypeDeclType(R, PrevDecl); | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 62 |   return R; | 
 | 63 | } | 
 | 64 |  | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 65 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, EmptyShell Empty) { | 
| Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 66 |   return new (C) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), 0, 0, | 
 | 67 |                                SourceLocation()); | 
 | 68 | } | 
 | 69 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | void | 
| Douglas Gregor | 2d5b703 | 2010-02-11 01:30:34 +0000 | [diff] [blame] | 71 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, | 
| Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 72 |                         unsigned NumBases) { | 
| Douglas Gregor | 2d5b703 | 2010-02-11 01:30:34 +0000 | [diff] [blame] | 73 |   ASTContext &C = getASTContext(); | 
 | 74 |    | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 75 |   // C++ [dcl.init.aggr]p1: | 
| Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 76 |   //   An aggregate is an array or a class (clause 9) with [...] | 
 | 77 |   //   no base classes [...]. | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 78 |   data().Aggregate = false; | 
| Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 79 |  | 
| Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 80 |   if (!data().Bases.isOffset() && data().NumBases > 0) | 
 | 81 |     C.Deallocate(data().getBases()); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 82 |  | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 83 |   // The set of seen virtual base types. | 
| Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 84 |   llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 85 |    | 
 | 86 |   // The virtual bases of this class. | 
 | 87 |   llvm::SmallVector<const CXXBaseSpecifier *, 8> VBases; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 |  | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 89 |   data().Bases = new(C) CXXBaseSpecifier [NumBases]; | 
 | 90 |   data().NumBases = NumBases; | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 91 |   for (unsigned i = 0; i < NumBases; ++i) { | 
| Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 92 |     data().getBases()[i] = *Bases[i]; | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 93 |     // Keep track of inherited vbases for this base class. | 
 | 94 |     const CXXBaseSpecifier *Base = Bases[i]; | 
 | 95 |     QualType BaseType = Base->getType(); | 
| Douglas Gregor | 5fe8c04 | 2010-02-27 00:25:28 +0000 | [diff] [blame] | 96 |     // Skip dependent types; we can't do any checking on them now. | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 97 |     if (BaseType->isDependentType()) | 
 | 98 |       continue; | 
 | 99 |     CXXRecordDecl *BaseClassDecl | 
| Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 100 |       = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 101 |  | 
| Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 102 |     // C++ [dcl.init.aggr]p1: | 
 | 103 |     //   An aggregate is [...] a class with [...] no base classes [...]. | 
 | 104 |     data().Aggregate = false;     | 
 | 105 |      | 
 | 106 |     // C++ [class]p4: | 
 | 107 |     //   A POD-struct is an aggregate class... | 
 | 108 |     data().PlainOldData = false; | 
 | 109 |      | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 110 |     // A class with a non-empty base class is not empty. | 
 | 111 |     // FIXME: Standard ref? | 
 | 112 |     if (!BaseClassDecl->isEmpty()) | 
 | 113 |       data().Empty = false; | 
 | 114 |      | 
| Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 115 |     // C++ [class.virtual]p1: | 
 | 116 |     //   A class that declares or inherits a virtual function is called a  | 
 | 117 |     //   polymorphic class. | 
 | 118 |     if (BaseClassDecl->isPolymorphic()) | 
 | 119 |       data().Polymorphic = true; | 
 | 120 |      | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 121 |     // Now go through all virtual bases of this base and add them. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 |     for (CXXRecordDecl::base_class_iterator VBase = | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 123 |           BaseClassDecl->vbases_begin(), | 
 | 124 |          E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 125 |       // Add this base if it's not already in the list. | 
| Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 126 |       if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType()))) | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 127 |         VBases.push_back(VBase); | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 128 |     } | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 129 |  | 
 | 130 |     if (Base->isVirtual()) { | 
 | 131 |       // Add this base if it's not already in the list. | 
| Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 132 |       if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType))) | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 133 |           VBases.push_back(Base); | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 134 |        | 
 | 135 |       // C++0x [meta.unary.prop] is_empty: | 
 | 136 |       //    T is a class type, but not a union type, with ... no virtual base | 
 | 137 |       //    classes | 
 | 138 |       data().Empty = false; | 
| Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 139 |        | 
 | 140 |       // C++ [class.ctor]p5: | 
 | 141 |       //   A constructor is trivial if its class has no virtual base classes. | 
 | 142 |       data().HasTrivialConstructor = false; | 
 | 143 |        | 
 | 144 |       // C++ [class.copy]p6: | 
 | 145 |       //   A copy constructor is trivial if its class has no virtual base  | 
 | 146 |       //   classes. | 
 | 147 |       data().HasTrivialCopyConstructor = false; | 
 | 148 |        | 
 | 149 |       // C++ [class.copy]p11: | 
 | 150 |       //   A copy assignment operator is trivial if its class has no virtual | 
 | 151 |       //   base classes. | 
 | 152 |       data().HasTrivialCopyAssignment = false; | 
 | 153 |     } else { | 
 | 154 |       // C++ [class.ctor]p5: | 
 | 155 |       //   A constructor is trivial if all the direct base classes of its | 
 | 156 |       //   class have trivial constructors. | 
 | 157 |       if (!BaseClassDecl->hasTrivialConstructor()) | 
 | 158 |         data().HasTrivialConstructor = false; | 
 | 159 |        | 
 | 160 |       // C++ [class.copy]p6: | 
 | 161 |       //   A copy constructor is trivial if all the direct base classes of its | 
 | 162 |       //   class have trivial copy constructors. | 
 | 163 |       if (!BaseClassDecl->hasTrivialCopyConstructor()) | 
 | 164 |         data().HasTrivialCopyConstructor = false; | 
 | 165 |        | 
 | 166 |       // C++ [class.copy]p11: | 
 | 167 |       //   A copy assignment operator is trivial if all the direct base classes | 
 | 168 |       //   of its class have trivial copy assignment operators. | 
 | 169 |       if (!BaseClassDecl->hasTrivialCopyAssignment()) | 
 | 170 |         data().HasTrivialCopyAssignment = false; | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 171 |     } | 
| Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 172 |      | 
 | 173 |     // C++ [class.ctor]p3: | 
 | 174 |     //   A destructor is trivial if all the direct base classes of its class | 
 | 175 |     //   have trivial destructors. | 
 | 176 |     if (!BaseClassDecl->hasTrivialDestructor()) | 
 | 177 |       data().HasTrivialDestructor = false; | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 178 |   } | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 179 |    | 
 | 180 |   if (VBases.empty()) | 
 | 181 |     return; | 
 | 182 |  | 
 | 183 |   // Create base specifier for any direct or indirect virtual bases. | 
 | 184 |   data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; | 
 | 185 |   data().NumVBases = VBases.size(); | 
 | 186 |   for (int I = 0, E = VBases.size(); I != E; ++I) { | 
| Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 187 |     TypeSourceInfo *VBaseTypeInfo = VBases[I]->getTypeSourceInfo(); | 
 | 188 |  | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 189 |     // Skip dependent types; we can't do any checking on them now. | 
| Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 190 |     if (VBaseTypeInfo->getType()->isDependentType()) | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 191 |       continue; | 
 | 192 |  | 
| Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 193 |     CXXRecordDecl *VBaseClassDecl = cast<CXXRecordDecl>( | 
 | 194 |       VBaseTypeInfo->getType()->getAs<RecordType>()->getDecl()); | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 195 |  | 
| Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 196 |     data().getVBases()[I] = | 
| Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 197 |       CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true, | 
| Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 198 |                        VBaseClassDecl->getTagKind() == TTK_Class, | 
| Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 199 |                        VBases[I]->getAccessSpecifier(), VBaseTypeInfo, | 
 | 200 |                        SourceLocation()); | 
| Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 201 |   } | 
| Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 202 | } | 
 | 203 |  | 
| Douglas Gregor | 9edad9b | 2010-01-14 17:47:39 +0000 | [diff] [blame] | 204 | /// Callback function for CXXRecordDecl::forallBases that acknowledges | 
 | 205 | /// that it saw a base class. | 
 | 206 | static bool SawBase(const CXXRecordDecl *, void *) { | 
 | 207 |   return true; | 
 | 208 | } | 
 | 209 |  | 
 | 210 | bool CXXRecordDecl::hasAnyDependentBases() const { | 
 | 211 |   if (!isDependentContext()) | 
 | 212 |     return false; | 
 | 213 |  | 
 | 214 |   return !forallBases(SawBase, 0); | 
 | 215 | } | 
 | 216 |  | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 217 | bool CXXRecordDecl::hasConstCopyConstructor(const ASTContext &Context) const { | 
| John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 218 |   return getCopyConstructor(Context, Qualifiers::Const) != 0; | 
| Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 219 | } | 
 | 220 |  | 
| Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 221 | /// \brief Perform a simplistic form of overload resolution that only considers | 
 | 222 | /// cv-qualifiers on a single parameter, and return the best overload candidate | 
 | 223 | /// (if there is one). | 
 | 224 | static CXXMethodDecl * | 
 | 225 | GetBestOverloadCandidateSimple( | 
 | 226 |   const llvm::SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) { | 
 | 227 |   if (Cands.empty()) | 
 | 228 |     return 0; | 
 | 229 |   if (Cands.size() == 1) | 
 | 230 |     return Cands[0].first; | 
 | 231 |    | 
 | 232 |   unsigned Best = 0, N = Cands.size(); | 
 | 233 |   for (unsigned I = 1; I != N; ++I) | 
 | 234 |     if (Cands[Best].second.isSupersetOf(Cands[I].second)) | 
 | 235 |       Best = I; | 
 | 236 |    | 
 | 237 |   for (unsigned I = 1; I != N; ++I) | 
 | 238 |     if (Cands[Best].second.isSupersetOf(Cands[I].second)) | 
 | 239 |       return 0; | 
 | 240 |    | 
 | 241 |   return Cands[Best].first; | 
 | 242 | } | 
 | 243 |  | 
| Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 244 | CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(const ASTContext &Context, | 
| Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 245 |                                                       unsigned TypeQuals) const{ | 
| Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 246 |   QualType ClassType | 
 | 247 |     = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 |   DeclarationName ConstructorName | 
| Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 249 |     = Context.DeclarationNames.getCXXConstructorName( | 
| Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 250 |                                           Context.getCanonicalType(ClassType)); | 
 | 251 |   unsigned FoundTQs; | 
| Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 252 |   llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; | 
| Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 253 |   DeclContext::lookup_const_iterator Con, ConEnd; | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 254 |   for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); | 
| Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 255 |        Con != ConEnd; ++Con) { | 
| Douglas Gregor | d93bacf | 2009-09-04 14:46:39 +0000 | [diff] [blame] | 256 |     // C++ [class.copy]p2: | 
 | 257 |     //   A non-template constructor for class X is a copy constructor if [...] | 
 | 258 |     if (isa<FunctionTemplateDecl>(*Con)) | 
 | 259 |       continue; | 
 | 260 |  | 
| Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 261 |     CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); | 
 | 262 |     if (Constructor->isCopyConstructor(FoundTQs)) { | 
| John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 263 |       if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) || | 
 | 264 |           (!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const))) | 
| Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 265 |         Found.push_back(std::make_pair( | 
 | 266 |                                  const_cast<CXXConstructorDecl *>(Constructor),  | 
 | 267 |                                        Qualifiers::fromCVRMask(FoundTQs))); | 
| Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 268 |     } | 
| Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 269 |   } | 
| Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 270 |    | 
 | 271 |   return cast_or_null<CXXConstructorDecl>( | 
 | 272 |                                         GetBestOverloadCandidateSimple(Found)); | 
| Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 273 | } | 
 | 274 |  | 
| Douglas Gregor | b87786f | 2010-07-01 17:48:08 +0000 | [diff] [blame] | 275 | CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const { | 
 | 276 |   ASTContext &Context = getASTContext(); | 
 | 277 |   QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this)); | 
 | 278 |   DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal); | 
 | 279 |    | 
 | 280 |   llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; | 
 | 281 |   DeclContext::lookup_const_iterator Op, OpEnd; | 
 | 282 |   for (llvm::tie(Op, OpEnd) = this->lookup(Name); Op != OpEnd; ++Op) { | 
 | 283 |     // C++ [class.copy]p9: | 
 | 284 |     //   A user-declared copy assignment operator is a non-static non-template | 
 | 285 |     //   member function of class X with exactly one parameter of type X, X&, | 
 | 286 |     //   const X&, volatile X& or const volatile X&. | 
 | 287 |     const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op); | 
 | 288 |     if (!Method || Method->isStatic() || Method->getPrimaryTemplate()) | 
 | 289 |       continue; | 
 | 290 |      | 
 | 291 |     const FunctionProtoType *FnType  | 
 | 292 |       = Method->getType()->getAs<FunctionProtoType>(); | 
 | 293 |     assert(FnType && "Overloaded operator has no prototype."); | 
 | 294 |     // Don't assert on this; an invalid decl might have been left in the AST. | 
 | 295 |     if (FnType->getNumArgs() != 1 || FnType->isVariadic()) | 
 | 296 |       continue; | 
 | 297 |      | 
 | 298 |     QualType ArgType = FnType->getArgType(0); | 
 | 299 |     Qualifiers Quals; | 
 | 300 |     if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) { | 
 | 301 |       ArgType = Ref->getPointeeType(); | 
 | 302 |       // If we have a const argument and we have a reference to a non-const, | 
 | 303 |       // this function does not match. | 
 | 304 |       if (ArgIsConst && !ArgType.isConstQualified()) | 
 | 305 |         continue; | 
 | 306 |        | 
 | 307 |       Quals = ArgType.getQualifiers(); | 
 | 308 |     } else { | 
 | 309 |       // By-value copy-assignment operators are treated like const X& | 
 | 310 |       // copy-assignment operators. | 
 | 311 |       Quals = Qualifiers::fromCVRMask(Qualifiers::Const); | 
 | 312 |     } | 
 | 313 |      | 
 | 314 |     if (!Context.hasSameUnqualifiedType(ArgType, Class)) | 
 | 315 |       continue; | 
 | 316 |  | 
 | 317 |     // Save this copy-assignment operator. It might be "the one". | 
 | 318 |     Found.push_back(std::make_pair(const_cast<CXXMethodDecl *>(Method), Quals)); | 
 | 319 |   } | 
 | 320 |    | 
 | 321 |   // Use a simplistic form of overload resolution to find the candidate. | 
 | 322 |   return GetBestOverloadCandidateSimple(Found); | 
 | 323 | } | 
 | 324 |  | 
| Douglas Gregor | 2138664 | 2010-09-28 21:55:22 +0000 | [diff] [blame] | 325 | void CXXRecordDecl::markedVirtualFunctionPure() { | 
 | 326 |   // C++ [class.abstract]p2:  | 
 | 327 |   //   A class is abstract if it has at least one pure virtual function. | 
 | 328 |   data().Abstract = true; | 
 | 329 | } | 
 | 330 |  | 
 | 331 | void CXXRecordDecl::addedMember(Decl *D) { | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 332 |   // Ignore friends and invalid declarations. | 
 | 333 |   if (D->getFriendObjectKind() || D->isInvalidDecl()) | 
| Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 334 |     return; | 
 | 335 |    | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 336 |   FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); | 
 | 337 |   if (FunTmpl) | 
 | 338 |     D = FunTmpl->getTemplatedDecl(); | 
 | 339 |    | 
| Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 340 |   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { | 
 | 341 |     if (Method->isVirtual()) { | 
 | 342 |       // C++ [dcl.init.aggr]p1: | 
 | 343 |       //   An aggregate is an array or a class with [...] no virtual functions. | 
 | 344 |       data().Aggregate = false; | 
 | 345 |        | 
 | 346 |       // C++ [class]p4: | 
 | 347 |       //   A POD-struct is an aggregate class... | 
 | 348 |       data().PlainOldData = false; | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 349 |        | 
 | 350 |       // Virtual functions make the class non-empty. | 
 | 351 |       // FIXME: Standard ref? | 
 | 352 |       data().Empty = false; | 
| Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 353 |  | 
 | 354 |       // C++ [class.virtual]p1: | 
 | 355 |       //   A class that declares or inherits a virtual function is called a  | 
 | 356 |       //   polymorphic class. | 
 | 357 |       data().Polymorphic = true; | 
 | 358 |        | 
 | 359 |       // None of the special member functions are trivial. | 
 | 360 |       data().HasTrivialConstructor = false; | 
 | 361 |       data().HasTrivialCopyConstructor = false; | 
 | 362 |       data().HasTrivialCopyAssignment = false; | 
 | 363 |       // FIXME: Destructor? | 
| Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 364 |     } | 
 | 365 |   } | 
 | 366 |    | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 367 |   if (D->isImplicit()) { | 
| Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 368 |     // Notify that an implicit member was added after the definition | 
 | 369 |     // was completed. | 
 | 370 |     if (!isBeingDefined()) | 
 | 371 |       if (ASTMutationListener *L = getASTMutationListener()) | 
 | 372 |         L->AddedCXXImplicitMember(data().Definition, D); | 
| Argyrios Kyrtzidis | 046c03b | 2010-10-20 23:48:42 +0000 | [diff] [blame] | 373 |  | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 374 |     if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { | 
 | 375 |       // If this is the implicit default constructor, note that we have now | 
 | 376 |       // declared it. | 
 | 377 |       if (Constructor->isDefaultConstructor()) | 
 | 378 |         data().DeclaredDefaultConstructor = true; | 
 | 379 |       // If this is the implicit copy constructor, note that we have now | 
 | 380 |       // declared it. | 
 | 381 |       else if (Constructor->isCopyConstructor()) | 
 | 382 |         data().DeclaredCopyConstructor = true; | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 383 |       return; | 
 | 384 |     }  | 
 | 385 |  | 
 | 386 |     if (isa<CXXDestructorDecl>(D)) { | 
| Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 387 |       data().DeclaredDestructor = true; | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 388 |       return; | 
 | 389 |     }  | 
 | 390 |  | 
 | 391 |     if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 392 |       // If this is the implicit copy constructor, note that we have now | 
 | 393 |       // declared it. | 
 | 394 |       // FIXME: Move constructors | 
| Douglas Gregor | 3e9438b | 2010-09-27 22:37:28 +0000 | [diff] [blame] | 395 |       if (Method->getOverloadedOperator() == OO_Equal) | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 396 |         data().DeclaredCopyAssignment = true; | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 397 |       return; | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 398 |     } | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 399 |  | 
 | 400 |     // Any other implicit declarations are handled like normal declarations. | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 401 |   } | 
 | 402 |    | 
 | 403 |   // Handle (user-declared) constructors. | 
 | 404 |   if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { | 
 | 405 |     // Note that we have a user-declared constructor. | 
 | 406 |     data().UserDeclaredConstructor = true; | 
 | 407 |  | 
 | 408 |     // Note that we have no need of an implicitly-declared default constructor. | 
 | 409 |     data().DeclaredDefaultConstructor = true; | 
 | 410 |      | 
 | 411 |     // C++ [dcl.init.aggr]p1: | 
 | 412 |     //   An aggregate is an array or a class (clause 9) with no | 
 | 413 |     //   user-declared constructors (12.1) [...]. | 
 | 414 |     data().Aggregate = false; | 
 | 415 |  | 
 | 416 |     // C++ [class]p4: | 
 | 417 |     //   A POD-struct is an aggregate class [...] | 
 | 418 |     data().PlainOldData = false; | 
 | 419 |  | 
 | 420 |     // C++ [class.ctor]p5: | 
 | 421 |     //   A constructor is trivial if it is an implicitly-declared default | 
 | 422 |     //   constructor. | 
 | 423 |     // FIXME: C++0x: don't do this for "= default" default constructors. | 
 | 424 |     data().HasTrivialConstructor = false; | 
 | 425 |  | 
 | 426 |     // Note when we have a user-declared copy constructor, which will | 
 | 427 |     // suppress the implicit declaration of a copy constructor. | 
 | 428 |     if (!FunTmpl && Constructor->isCopyConstructor()) { | 
 | 429 |       data().UserDeclaredCopyConstructor = true; | 
| Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 430 |       data().DeclaredCopyConstructor = true; | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 431 |        | 
 | 432 |       // C++ [class.copy]p6: | 
 | 433 |       //   A copy constructor is trivial if it is implicitly declared. | 
 | 434 |       // FIXME: C++0x: don't do this for "= default" copy constructors. | 
 | 435 |       data().HasTrivialCopyConstructor = false; | 
 | 436 |     } | 
| Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 437 |      | 
| Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 438 |     return; | 
 | 439 |   } | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 440 |  | 
| Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 441 |   // Handle (user-declared) destructors. | 
 | 442 |   if (isa<CXXDestructorDecl>(D)) { | 
 | 443 |     data().DeclaredDestructor = true; | 
 | 444 |     data().UserDeclaredDestructor = true; | 
| Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 445 |      | 
 | 446 |     // C++ [class]p4:  | 
 | 447 |     //   A POD-struct is an aggregate class that has [...] no user-defined  | 
 | 448 |     //   destructor. | 
 | 449 |     data().PlainOldData = false; | 
 | 450 |      | 
| Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 451 |     // C++ [class.dtor]p3:  | 
 | 452 |     //   A destructor is trivial if it is an implicitly-declared destructor and | 
 | 453 |     //   [...]. | 
 | 454 |     // | 
 | 455 |     // FIXME: C++0x: don't do this for "= default" destructors | 
 | 456 |     data().HasTrivialDestructor = false; | 
 | 457 |      | 
| Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 458 |     return; | 
 | 459 |   } | 
| Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 460 |    | 
| Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 461 |   // Handle (user-declared) member functions. | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 462 |   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { | 
 | 463 |     if (Method->getOverloadedOperator() == OO_Equal) { | 
 | 464 |       // We're interested specifically in copy assignment operators. | 
 | 465 |       const FunctionProtoType *FnType  | 
 | 466 |         = Method->getType()->getAs<FunctionProtoType>(); | 
 | 467 |       assert(FnType && "Overloaded operator has no proto function type."); | 
 | 468 |       assert(FnType->getNumArgs() == 1 && !FnType->isVariadic()); | 
 | 469 |        | 
 | 470 |       // Copy assignment operators must be non-templates. | 
 | 471 |       if (Method->getPrimaryTemplate() || FunTmpl) | 
 | 472 |         return; | 
 | 473 |        | 
 | 474 |       ASTContext &Context = getASTContext(); | 
 | 475 |       QualType ArgType = FnType->getArgType(0); | 
 | 476 |       if (const LValueReferenceType *Ref =ArgType->getAs<LValueReferenceType>()) | 
 | 477 |         ArgType = Ref->getPointeeType(); | 
 | 478 |        | 
 | 479 |       ArgType = ArgType.getUnqualifiedType(); | 
 | 480 |       QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( | 
 | 481 |                                              const_cast<CXXRecordDecl*>(this))); | 
 | 482 |        | 
 | 483 |       if (!Context.hasSameUnqualifiedType(ClassType, ArgType)) | 
 | 484 |         return; | 
 | 485 |        | 
 | 486 |       // This is a copy assignment operator. | 
| Douglas Gregor | 3e9438b | 2010-09-27 22:37:28 +0000 | [diff] [blame] | 487 |       // FIXME: Move assignment operators. | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 488 |        | 
 | 489 |       // Suppress the implicit declaration of a copy constructor. | 
 | 490 |       data().UserDeclaredCopyAssignment = true; | 
 | 491 |       data().DeclaredCopyAssignment = true; | 
 | 492 |        | 
 | 493 |       // C++ [class.copy]p11: | 
 | 494 |       //   A copy assignment operator is trivial if it is implicitly declared. | 
 | 495 |       // FIXME: C++0x: don't do this for "= default" copy operators. | 
 | 496 |       data().HasTrivialCopyAssignment = false; | 
 | 497 |        | 
 | 498 |       // C++ [class]p4: | 
 | 499 |       //   A POD-struct is an aggregate class that [...] has no user-defined copy | 
 | 500 |       //   assignment operator [...]. | 
 | 501 |       data().PlainOldData = false; | 
 | 502 |     } | 
| Douglas Gregor | 2258431 | 2010-07-02 23:41:54 +0000 | [diff] [blame] | 503 |      | 
| Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 504 |     // Keep the list of conversion functions up-to-date. | 
 | 505 |     if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { | 
 | 506 |       // We don't record specializations. | 
 | 507 |       if (Conversion->getPrimaryTemplate()) | 
 | 508 |         return; | 
 | 509 |        | 
 | 510 |       // FIXME: We intentionally don't use the decl's access here because it | 
 | 511 |       // hasn't been set yet.  That's really just a misdesign in Sema. | 
 | 512 |  | 
 | 513 |       if (FunTmpl) { | 
 | 514 |         if (FunTmpl->getPreviousDeclaration()) | 
 | 515 |           data().Conversions.replace(FunTmpl->getPreviousDeclaration(), | 
 | 516 |                                      FunTmpl); | 
 | 517 |         else | 
 | 518 |           data().Conversions.addDecl(FunTmpl); | 
 | 519 |       } else { | 
 | 520 |         if (Conversion->getPreviousDeclaration()) | 
 | 521 |           data().Conversions.replace(Conversion->getPreviousDeclaration(), | 
 | 522 |                                      Conversion); | 
 | 523 |         else | 
 | 524 |           data().Conversions.addDecl(Conversion);         | 
 | 525 |       } | 
 | 526 |     } | 
 | 527 |      | 
| Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 528 |     return; | 
| Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 529 |   } | 
| Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 530 |    | 
 | 531 |   // Handle non-static data members. | 
 | 532 |   if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { | 
 | 533 |     // C++ [dcl.init.aggr]p1: | 
 | 534 |     //   An aggregate is an array or a class (clause 9) with [...] no | 
 | 535 |     //   private or protected non-static data members (clause 11). | 
 | 536 |     // | 
 | 537 |     // A POD must be an aggregate.     | 
 | 538 |     if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { | 
 | 539 |       data().Aggregate = false; | 
 | 540 |       data().PlainOldData = false; | 
 | 541 |     } | 
 | 542 |      | 
 | 543 |     // C++ [class]p9: | 
 | 544 |     //   A POD struct is a class that is both a trivial class and a  | 
 | 545 |     //   standard-layout class, and has no non-static data members of type  | 
 | 546 |     //   non-POD struct, non-POD union (or array of such types). | 
 | 547 |     ASTContext &Context = getASTContext(); | 
 | 548 |     QualType T = Context.getBaseElementType(Field->getType()); | 
 | 549 |     if (!T->isPODType()) | 
 | 550 |       data().PlainOldData = false; | 
| Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 551 |     if (T->isReferenceType()) | 
 | 552 |       data().HasTrivialConstructor = false; | 
 | 553 |      | 
 | 554 |     if (const RecordType *RecordTy = T->getAs<RecordType>()) { | 
 | 555 |       CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); | 
 | 556 |       if (FieldRec->getDefinition()) { | 
 | 557 |         if (!FieldRec->hasTrivialConstructor()) | 
 | 558 |           data().HasTrivialConstructor = false; | 
 | 559 |         if (!FieldRec->hasTrivialCopyConstructor()) | 
 | 560 |           data().HasTrivialCopyConstructor = false; | 
 | 561 |         if (!FieldRec->hasTrivialCopyAssignment()) | 
 | 562 |           data().HasTrivialCopyAssignment = false; | 
 | 563 |         if (!FieldRec->hasTrivialDestructor()) | 
 | 564 |           data().HasTrivialDestructor = false; | 
 | 565 |       } | 
 | 566 |     } | 
| Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 567 |      | 
 | 568 |     // If this is not a zero-length bit-field, then the class is not empty. | 
 | 569 |     if (data().Empty) { | 
 | 570 |       if (!Field->getBitWidth()) | 
 | 571 |         data().Empty = false; | 
 | 572 |       else if (!Field->getBitWidth()->isTypeDependent() && | 
 | 573 |                !Field->getBitWidth()->isValueDependent()) { | 
 | 574 |         llvm::APSInt Bits; | 
 | 575 |         if (Field->getBitWidth()->isIntegerConstantExpr(Bits, Context)) | 
 | 576 |           if (!!Bits) | 
 | 577 |             data().Empty = false; | 
 | 578 |       }  | 
 | 579 |     } | 
| Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 580 |   } | 
| Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 581 |    | 
 | 582 |   // Handle using declarations of conversion functions. | 
 | 583 |   if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) | 
 | 584 |     if (Shadow->getDeclName().getNameKind() | 
 | 585 |           == DeclarationName::CXXConversionFunctionName) | 
 | 586 |       data().Conversions.addDecl(Shadow, Shadow->getAccess()); | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 587 | } | 
 | 588 |  | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 589 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { | 
 | 590 |   QualType T; | 
| John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 591 |   if (isa<UsingShadowDecl>(Conv)) | 
 | 592 |     Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl(); | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 593 |   if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv)) | 
 | 594 |     T = ConvTemp->getTemplatedDecl()->getResultType(); | 
 | 595 |   else  | 
 | 596 |     T = cast<CXXConversionDecl>(Conv)->getConversionType(); | 
 | 597 |   return Context.getCanonicalType(T); | 
| Fariborz Jahanian | 0351a1e | 2009-10-07 20:43:36 +0000 | [diff] [blame] | 598 | } | 
 | 599 |  | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 600 | /// Collect the visible conversions of a base class. | 
 | 601 | /// | 
 | 602 | /// \param Base a base class of the class we're considering | 
 | 603 | /// \param InVirtual whether this base class is a virtual base (or a base | 
 | 604 | ///   of a virtual base) | 
 | 605 | /// \param Access the access along the inheritance path to this base | 
 | 606 | /// \param ParentHiddenTypes the conversions provided by the inheritors | 
 | 607 | ///   of this base | 
 | 608 | /// \param Output the set to which to add conversions from non-virtual bases | 
 | 609 | /// \param VOutput the set to which to add conversions from virtual bases | 
 | 610 | /// \param HiddenVBaseCs the set of conversions which were hidden in a | 
 | 611 | ///   virtual base along some inheritance path | 
 | 612 | static void CollectVisibleConversions(ASTContext &Context, | 
 | 613 |                                       CXXRecordDecl *Record, | 
 | 614 |                                       bool InVirtual, | 
 | 615 |                                       AccessSpecifier Access, | 
 | 616 |                   const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, | 
 | 617 |                                       UnresolvedSetImpl &Output, | 
 | 618 |                                       UnresolvedSetImpl &VOutput, | 
 | 619 |                            llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { | 
 | 620 |   // The set of types which have conversions in this class or its | 
 | 621 |   // subclasses.  As an optimization, we don't copy the derived set | 
 | 622 |   // unless it might change. | 
 | 623 |   const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; | 
 | 624 |   llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; | 
 | 625 |  | 
 | 626 |   // Collect the direct conversions and figure out which conversions | 
 | 627 |   // will be hidden in the subclasses. | 
 | 628 |   UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); | 
 | 629 |   if (!Cs.empty()) { | 
 | 630 |     HiddenTypesBuffer = ParentHiddenTypes; | 
 | 631 |     HiddenTypes = &HiddenTypesBuffer; | 
 | 632 |  | 
 | 633 |     for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) { | 
 | 634 |       bool Hidden = | 
 | 635 |         !HiddenTypesBuffer.insert(GetConversionType(Context, I.getDecl())); | 
 | 636 |  | 
 | 637 |       // If this conversion is hidden and we're in a virtual base, | 
 | 638 |       // remember that it's hidden along some inheritance path. | 
 | 639 |       if (Hidden && InVirtual) | 
 | 640 |         HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); | 
 | 641 |  | 
 | 642 |       // If this conversion isn't hidden, add it to the appropriate output. | 
 | 643 |       else if (!Hidden) { | 
 | 644 |         AccessSpecifier IAccess | 
 | 645 |           = CXXRecordDecl::MergeAccess(Access, I.getAccess()); | 
 | 646 |  | 
 | 647 |         if (InVirtual) | 
 | 648 |           VOutput.addDecl(I.getDecl(), IAccess); | 
| Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 649 |         else | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 650 |           Output.addDecl(I.getDecl(), IAccess); | 
| Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 651 |       } | 
 | 652 |     } | 
 | 653 |   } | 
| Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 654 |  | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 655 |   // Collect information recursively from any base classes. | 
 | 656 |   for (CXXRecordDecl::base_class_iterator | 
 | 657 |          I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { | 
 | 658 |     const RecordType *RT = I->getType()->getAs<RecordType>(); | 
 | 659 |     if (!RT) continue; | 
| Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 660 |  | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 661 |     AccessSpecifier BaseAccess | 
 | 662 |       = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier()); | 
 | 663 |     bool BaseInVirtual = InVirtual || I->isVirtual(); | 
| Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 664 |  | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 665 |     CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); | 
 | 666 |     CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, | 
 | 667 |                               *HiddenTypes, Output, VOutput, HiddenVBaseCs); | 
| Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 668 |   } | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 669 | } | 
| Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 670 |  | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 671 | /// Collect the visible conversions of a class. | 
 | 672 | /// | 
 | 673 | /// This would be extremely straightforward if it weren't for virtual | 
 | 674 | /// bases.  It might be worth special-casing that, really. | 
 | 675 | static void CollectVisibleConversions(ASTContext &Context, | 
 | 676 |                                       CXXRecordDecl *Record, | 
 | 677 |                                       UnresolvedSetImpl &Output) { | 
 | 678 |   // The collection of all conversions in virtual bases that we've | 
 | 679 |   // found.  These will be added to the output as long as they don't | 
 | 680 |   // appear in the hidden-conversions set. | 
 | 681 |   UnresolvedSet<8> VBaseCs; | 
 | 682 |    | 
 | 683 |   // The set of conversions in virtual bases that we've determined to | 
 | 684 |   // be hidden. | 
 | 685 |   llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; | 
 | 686 |  | 
 | 687 |   // The set of types hidden by classes derived from this one. | 
 | 688 |   llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; | 
 | 689 |  | 
 | 690 |   // Go ahead and collect the direct conversions and add them to the | 
 | 691 |   // hidden-types set. | 
 | 692 |   UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); | 
 | 693 |   Output.append(Cs.begin(), Cs.end()); | 
 | 694 |   for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) | 
 | 695 |     HiddenTypes.insert(GetConversionType(Context, I.getDecl())); | 
 | 696 |  | 
 | 697 |   // Recursively collect conversions from base classes. | 
 | 698 |   for (CXXRecordDecl::base_class_iterator | 
 | 699 |          I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { | 
 | 700 |     const RecordType *RT = I->getType()->getAs<RecordType>(); | 
 | 701 |     if (!RT) continue; | 
 | 702 |  | 
 | 703 |     CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), | 
 | 704 |                               I->isVirtual(), I->getAccessSpecifier(), | 
 | 705 |                               HiddenTypes, Output, VBaseCs, HiddenVBaseCs); | 
 | 706 |   } | 
 | 707 |  | 
 | 708 |   // Add any unhidden conversions provided by virtual bases. | 
 | 709 |   for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); | 
 | 710 |          I != E; ++I) { | 
 | 711 |     if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) | 
 | 712 |       Output.addDecl(I.getDecl(), I.getAccess()); | 
| Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 713 |   } | 
| Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 714 | } | 
 | 715 |  | 
 | 716 | /// getVisibleConversionFunctions - get all conversion functions visible | 
 | 717 | /// in current class; including conversion function templates. | 
| John McCall | eec51cf | 2010-01-20 00:46:10 +0000 | [diff] [blame] | 718 | const UnresolvedSetImpl *CXXRecordDecl::getVisibleConversionFunctions() { | 
| Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 719 |   // If root class, all conversions are visible. | 
 | 720 |   if (bases_begin() == bases_end()) | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 721 |     return &data().Conversions; | 
| Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 722 |   // If visible conversion list is already evaluated, return it. | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 723 |   if (data().ComputedVisibleConversions) | 
 | 724 |     return &data().VisibleConversions; | 
| John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 725 |   CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); | 
| John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 726 |   data().ComputedVisibleConversions = true; | 
 | 727 |   return &data().VisibleConversions; | 
| Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 728 | } | 
 | 729 |  | 
| John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 730 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { | 
 | 731 |   // This operation is O(N) but extremely rare.  Sema only uses it to | 
 | 732 |   // remove UsingShadowDecls in a class that were followed by a direct | 
 | 733 |   // declaration, e.g.: | 
 | 734 |   //   class A : B { | 
 | 735 |   //     using B::operator int; | 
 | 736 |   //     operator int(); | 
 | 737 |   //   }; | 
 | 738 |   // This is uncommon by itself and even more uncommon in conjunction | 
 | 739 |   // with sufficiently large numbers of directly-declared conversions | 
 | 740 |   // that asymptotic behavior matters. | 
 | 741 |  | 
 | 742 |   UnresolvedSetImpl &Convs = *getConversionFunctions(); | 
 | 743 |   for (unsigned I = 0, E = Convs.size(); I != E; ++I) { | 
 | 744 |     if (Convs[I].getDecl() == ConvDecl) { | 
 | 745 |       Convs.erase(I); | 
 | 746 |       assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() | 
 | 747 |              && "conversion was found multiple times in unresolved set"); | 
 | 748 |       return; | 
 | 749 |     } | 
 | 750 |   } | 
 | 751 |  | 
 | 752 |   llvm_unreachable("conversion not found in set!"); | 
| Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 753 | } | 
| Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 754 |  | 
| Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 755 | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { | 
| Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 756 |   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) | 
| Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 757 |     return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); | 
 | 758 |    | 
 | 759 |   return 0; | 
 | 760 | } | 
 | 761 |  | 
| Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 762 | MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { | 
 | 763 |   return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); | 
 | 764 | } | 
 | 765 |  | 
| Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 766 | void  | 
 | 767 | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, | 
 | 768 |                                              TemplateSpecializationKind TSK) { | 
 | 769 |   assert(TemplateOrInstantiation.isNull() &&  | 
 | 770 |          "Previous template or instantiation?"); | 
 | 771 |   assert(!isa<ClassTemplateSpecializationDecl>(this)); | 
 | 772 |   TemplateOrInstantiation  | 
 | 773 |     = new (getASTContext()) MemberSpecializationInfo(RD, TSK); | 
 | 774 | } | 
 | 775 |  | 
| Anders Carlsson | b13e357 | 2009-12-07 06:33:48 +0000 | [diff] [blame] | 776 | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ | 
 | 777 |   if (const ClassTemplateSpecializationDecl *Spec | 
| Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 778 |         = dyn_cast<ClassTemplateSpecializationDecl>(this)) | 
 | 779 |     return Spec->getSpecializationKind(); | 
 | 780 |    | 
| Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 781 |   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) | 
| Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 782 |     return MSInfo->getTemplateSpecializationKind(); | 
 | 783 |    | 
 | 784 |   return TSK_Undeclared; | 
 | 785 | } | 
 | 786 |  | 
 | 787 | void  | 
 | 788 | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { | 
 | 789 |   if (ClassTemplateSpecializationDecl *Spec | 
 | 790 |       = dyn_cast<ClassTemplateSpecializationDecl>(this)) { | 
 | 791 |     Spec->setSpecializationKind(TSK); | 
 | 792 |     return; | 
 | 793 |   } | 
 | 794 |    | 
| Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 795 |   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { | 
| Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 796 |     MSInfo->setTemplateSpecializationKind(TSK); | 
 | 797 |     return; | 
 | 798 |   } | 
 | 799 |    | 
 | 800 |   assert(false && "Not a class template or member class specialization"); | 
 | 801 | } | 
 | 802 |  | 
| Douglas Gregor | 1d110e0 | 2010-07-01 14:13:13 +0000 | [diff] [blame] | 803 | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { | 
 | 804 |   ASTContext &Context = getASTContext(); | 
| Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 805 |   QualType ClassType = Context.getTypeDeclType(this); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 |  | 
 | 807 |   DeclarationName Name | 
| Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 808 |     = Context.DeclarationNames.getCXXDestructorName( | 
 | 809 |                                           Context.getCanonicalType(ClassType)); | 
| Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 810 |  | 
| John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 811 |   DeclContext::lookup_const_iterator I, E; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 |   llvm::tie(I, E) = lookup(Name); | 
| Sebastian Redl | d4b25cb | 2010-09-02 23:19:42 +0000 | [diff] [blame] | 813 |   if (I == E) | 
 | 814 |     return 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 |  | 
| Anders Carlsson | 5ec02ae | 2009-12-02 17:15:43 +0000 | [diff] [blame] | 816 |   CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); | 
| Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 817 |   assert(++I == E && "Found more than one destructor!"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 818 |  | 
| Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 819 |   return Dtor; | 
 | 820 | } | 
 | 821 |  | 
| Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 822 | void CXXRecordDecl::completeDefinition() { | 
 | 823 |   completeDefinition(0); | 
 | 824 | } | 
 | 825 |  | 
 | 826 | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { | 
 | 827 |   RecordDecl::completeDefinition(); | 
 | 828 |    | 
| Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 829 |   // If the class may be abstract (but hasn't been marked as such), check for | 
 | 830 |   // any pure final overriders. | 
 | 831 |   if (mayBeAbstract()) { | 
 | 832 |     CXXFinalOverriderMap MyFinalOverriders; | 
 | 833 |     if (!FinalOverriders) { | 
 | 834 |       getFinalOverriders(MyFinalOverriders); | 
 | 835 |       FinalOverriders = &MyFinalOverriders; | 
 | 836 |     } | 
 | 837 |      | 
 | 838 |     bool Done = false; | 
 | 839 |     for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(),  | 
 | 840 |                                      MEnd = FinalOverriders->end(); | 
 | 841 |          M != MEnd && !Done; ++M) { | 
 | 842 |       for (OverridingMethods::iterator SO = M->second.begin(),  | 
 | 843 |                                     SOEnd = M->second.end(); | 
 | 844 |            SO != SOEnd && !Done; ++SO) { | 
 | 845 |         assert(SO->second.size() > 0 &&  | 
 | 846 |                "All virtual functions have overridding virtual functions"); | 
 | 847 |          | 
 | 848 |         // C++ [class.abstract]p4: | 
 | 849 |         //   A class is abstract if it contains or inherits at least one | 
 | 850 |         //   pure virtual function for which the final overrider is pure | 
 | 851 |         //   virtual. | 
 | 852 |         if (SO->second.front().Method->isPure()) { | 
 | 853 |           data().Abstract = true; | 
 | 854 |           Done = true; | 
 | 855 |           break; | 
 | 856 |         } | 
 | 857 |       } | 
 | 858 |     } | 
 | 859 |   } | 
| Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 860 |    | 
 | 861 |   // Set access bits correctly on the directly-declared conversions. | 
 | 862 |   for (UnresolvedSetIterator I = data().Conversions.begin(),  | 
 | 863 |                              E = data().Conversions.end();  | 
 | 864 |        I != E; ++I) | 
 | 865 |     data().Conversions.setAccess(I, (*I)->getAccess()); | 
| Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 866 | } | 
 | 867 |  | 
 | 868 | bool CXXRecordDecl::mayBeAbstract() const { | 
 | 869 |   if (data().Abstract || isInvalidDecl() || !data().Polymorphic || | 
 | 870 |       isDependentContext()) | 
 | 871 |     return false; | 
 | 872 |    | 
 | 873 |   for (CXXRecordDecl::base_class_const_iterator B = bases_begin(), | 
 | 874 |                                              BEnd = bases_end(); | 
 | 875 |        B != BEnd; ++B) { | 
 | 876 |     CXXRecordDecl *BaseDecl  | 
 | 877 |       = cast<CXXRecordDecl>(B->getType()->getAs<RecordType>()->getDecl()); | 
 | 878 |     if (BaseDecl->isAbstract()) | 
 | 879 |       return true; | 
 | 880 |   } | 
 | 881 |    | 
 | 882 |   return false; | 
 | 883 | } | 
 | 884 |  | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 885 | CXXMethodDecl * | 
 | 886 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 887 |                       const DeclarationNameInfo &NameInfo, | 
| John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 888 |                       QualType T, TypeSourceInfo *TInfo, | 
| Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 889 |                       bool isStatic, StorageClass SCAsWritten, bool isInline) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 890 |   return new (C) CXXMethodDecl(CXXMethod, RD, NameInfo, T, TInfo, | 
| Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 891 |                                isStatic, SCAsWritten, isInline); | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 892 | } | 
 | 893 |  | 
| Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 894 | bool CXXMethodDecl::isUsualDeallocationFunction() const { | 
 | 895 |   if (getOverloadedOperator() != OO_Delete && | 
 | 896 |       getOverloadedOperator() != OO_Array_Delete) | 
 | 897 |     return false; | 
| Douglas Gregor | 6d90870 | 2010-02-26 05:06:18 +0000 | [diff] [blame] | 898 |  | 
 | 899 |   // C++ [basic.stc.dynamic.deallocation]p2: | 
 | 900 |   //   A template instance is never a usual deallocation function, | 
 | 901 |   //   regardless of its signature. | 
 | 902 |   if (getPrimaryTemplate()) | 
 | 903 |     return false; | 
 | 904 |  | 
| Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 905 |   // C++ [basic.stc.dynamic.deallocation]p2: | 
 | 906 |   //   If a class T has a member deallocation function named operator delete  | 
 | 907 |   //   with exactly one parameter, then that function is a usual (non-placement) | 
 | 908 |   //   deallocation function. [...] | 
 | 909 |   if (getNumParams() == 1) | 
 | 910 |     return true; | 
 | 911 |    | 
 | 912 |   // C++ [basic.stc.dynamic.deallocation]p2: | 
 | 913 |   //   [...] If class T does not declare such an operator delete but does  | 
 | 914 |   //   declare a member deallocation function named operator delete with  | 
 | 915 |   //   exactly two parameters, the second of which has type std::size_t (18.1), | 
 | 916 |   //   then this function is a usual deallocation function. | 
 | 917 |   ASTContext &Context = getASTContext(); | 
 | 918 |   if (getNumParams() != 2 || | 
| Chandler Carruth | e228ba9 | 2010-02-08 18:54:05 +0000 | [diff] [blame] | 919 |       !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), | 
 | 920 |                                       Context.getSizeType())) | 
| Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 921 |     return false; | 
 | 922 |                   | 
 | 923 |   // This function is a usual deallocation function if there are no  | 
 | 924 |   // single-parameter deallocation functions of the same kind. | 
 | 925 |   for (DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName()); | 
 | 926 |        R.first != R.second; ++R.first) { | 
 | 927 |     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*R.first)) | 
 | 928 |       if (FD->getNumParams() == 1) | 
 | 929 |         return false; | 
 | 930 |   } | 
 | 931 |    | 
 | 932 |   return true; | 
 | 933 | } | 
 | 934 |  | 
| Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 935 | bool CXXMethodDecl::isCopyAssignmentOperator() const { | 
 | 936 |   // C++0x [class.copy]p19: | 
 | 937 |   //  A user-declared copy assignment operator X::operator= is a non-static  | 
 | 938 |   //  non-template member function of class X with exactly one parameter of  | 
 | 939 |   //  type X, X&, const X&, volatile X& or const volatile X&. | 
 | 940 |   if (/*operator=*/getOverloadedOperator() != OO_Equal || | 
 | 941 |       /*non-static*/ isStatic() ||  | 
 | 942 |       /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() || | 
 | 943 |       /*exactly one parameter*/getNumParams() != 1) | 
 | 944 |     return false; | 
 | 945 |        | 
 | 946 |   QualType ParamType = getParamDecl(0)->getType(); | 
 | 947 |   if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) | 
 | 948 |     ParamType = Ref->getPointeeType(); | 
 | 949 |    | 
 | 950 |   ASTContext &Context = getASTContext(); | 
 | 951 |   QualType ClassType | 
 | 952 |     = Context.getCanonicalType(Context.getTypeDeclType(getParent())); | 
 | 953 |   return Context.hasSameUnqualifiedType(ClassType, ParamType); | 
 | 954 | } | 
 | 955 |  | 
| Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 956 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { | 
| Anders Carlsson | 3aaf486 | 2009-12-04 05:51:56 +0000 | [diff] [blame] | 957 |   assert(MD->isCanonicalDecl() && "Method is not canonical!"); | 
| Anders Carlsson | c076c45 | 2010-01-30 17:42:34 +0000 | [diff] [blame] | 958 |   assert(!MD->getParent()->isDependentContext() && | 
 | 959 |          "Can't add an overridden method to a class template!"); | 
 | 960 |  | 
| Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 961 |   getASTContext().addOverriddenMethod(this, MD); | 
| Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 962 | } | 
 | 963 |  | 
 | 964 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { | 
| Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 965 |   return getASTContext().overridden_methods_begin(this); | 
| Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 966 | } | 
 | 967 |  | 
 | 968 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { | 
| Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 969 |   return getASTContext().overridden_methods_end(this); | 
| Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 970 | } | 
 | 971 |  | 
| Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 972 | unsigned CXXMethodDecl::size_overridden_methods() const { | 
 | 973 |   return getASTContext().overridden_methods_size(this); | 
 | 974 | } | 
 | 975 |  | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 976 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { | 
| Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 977 |   // C++ 9.3.2p1: The type of this in a member function of a class X is X*. | 
 | 978 |   // If the member function is declared const, the type of this is const X*, | 
 | 979 |   // if the member function is declared volatile, the type of this is | 
 | 980 |   // volatile X*, and if the member function is declared const volatile, | 
 | 981 |   // the type of this is const volatile X*. | 
 | 982 |  | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 983 |   assert(isInstance() && "No 'this' for static methods!"); | 
| Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 984 |  | 
| John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 985 |   QualType ClassTy = C.getTypeDeclType(getParent()); | 
| John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 986 |   ClassTy = C.getQualifiedType(ClassTy, | 
 | 987 |                                Qualifiers::fromCVRMask(getTypeQualifiers())); | 
| Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 988 |   return C.getPointerType(ClassTy); | 
| Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 989 | } | 
 | 990 |  | 
| Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 991 | bool CXXMethodDecl::hasInlineBody() const { | 
| Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 992 |   // If this function is a template instantiation, look at the template from  | 
 | 993 |   // which it was instantiated. | 
 | 994 |   const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); | 
 | 995 |   if (!CheckFn) | 
 | 996 |     CheckFn = this; | 
 | 997 |    | 
| Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 998 |   const FunctionDecl *fn; | 
| Argyrios Kyrtzidis | 06a54a3 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 999 |   return CheckFn->hasBody(fn) && !fn->isOutOfLine(); | 
| Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1000 | } | 
 | 1001 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1002 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | 
 | 1003 |                                        TypeSourceInfo *TInfo, bool IsVirtual, | 
 | 1004 |                                        SourceLocation L, Expr *Init, | 
 | 1005 |                                        SourceLocation R, | 
 | 1006 |                                        SourceLocation EllipsisLoc) | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1007 |   : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),  | 
| Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1008 |     LParenLoc(L), RParenLoc(R), IsVirtual(IsVirtual), IsWritten(false), | 
 | 1009 |     SourceOrderOrNumArrayIndices(0) | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1010 | { | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1011 | } | 
 | 1012 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1013 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | 
 | 1014 |                                        FieldDecl *Member, | 
 | 1015 |                                        SourceLocation MemberLoc, | 
 | 1016 |                                        SourceLocation L, Expr *Init, | 
 | 1017 |                                        SourceLocation R) | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1018 |   : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), | 
| Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1019 |     LParenLoc(L), RParenLoc(R), IsVirtual(false), | 
 | 1020 |     IsWritten(false), SourceOrderOrNumArrayIndices(0) | 
 | 1021 | { | 
 | 1022 | } | 
 | 1023 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1024 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | 
 | 1025 |                                        IndirectFieldDecl *Member, | 
 | 1026 |                                        SourceLocation MemberLoc, | 
 | 1027 |                                        SourceLocation L, Expr *Init, | 
 | 1028 |                                        SourceLocation R) | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1029 |   : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), | 
| Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1030 |     LParenLoc(L), RParenLoc(R), IsVirtual(false), | 
| Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1031 |     IsWritten(false), SourceOrderOrNumArrayIndices(0) | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1032 | { | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1033 | } | 
 | 1034 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1035 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | 
| Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame^] | 1036 |                                        SourceLocation D, SourceLocation L, | 
 | 1037 |                                        CXXConstructorDecl *Target, Expr *Init, | 
 | 1038 |                                        SourceLocation R) | 
 | 1039 |   : Initializee(Target), MemberOrEllipsisLocation(D), Init(Init), | 
 | 1040 |     LParenLoc(L), RParenLoc(R), IsVirtual(false), | 
 | 1041 |     IsWritten(false), SourceOrderOrNumArrayIndices(0) | 
 | 1042 | { | 
 | 1043 | } | 
 | 1044 |  | 
 | 1045 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1046 |                                        FieldDecl *Member, | 
 | 1047 |                                        SourceLocation MemberLoc, | 
 | 1048 |                                        SourceLocation L, Expr *Init, | 
 | 1049 |                                        SourceLocation R, | 
 | 1050 |                                        VarDecl **Indices, | 
 | 1051 |                                        unsigned NumIndices) | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1052 |   : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),  | 
| Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1053 |     LParenLoc(L), RParenLoc(R), IsVirtual(false), | 
| Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1054 |     IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) | 
| Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1055 | { | 
 | 1056 |   VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1); | 
 | 1057 |   memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *)); | 
 | 1058 | } | 
 | 1059 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1060 | CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, | 
 | 1061 |                                                FieldDecl *Member,  | 
 | 1062 |                                                SourceLocation MemberLoc, | 
 | 1063 |                                                SourceLocation L, Expr *Init, | 
 | 1064 |                                                SourceLocation R, | 
 | 1065 |                                                VarDecl **Indices, | 
 | 1066 |                                                unsigned NumIndices) { | 
 | 1067 |   void *Mem = Context.Allocate(sizeof(CXXCtorInitializer) + | 
| Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1068 |                                sizeof(VarDecl *) * NumIndices, | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1069 |                                llvm::alignOf<CXXCtorInitializer>()); | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1070 |   return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, | 
 | 1071 |                                       Indices, NumIndices); | 
| Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1072 | } | 
 | 1073 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1074 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1075 |   if (isBaseInitializer()) | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1076 |     return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1077 |   else | 
 | 1078 |     return TypeLoc(); | 
 | 1079 | } | 
 | 1080 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1081 | const Type *CXXCtorInitializer::getBaseClass() const { | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1082 |   if (isBaseInitializer()) | 
| Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1083 |     return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1084 |   else | 
 | 1085 |     return 0; | 
 | 1086 | } | 
 | 1087 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1088 | SourceLocation CXXCtorInitializer::getSourceLocation() const { | 
| Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame^] | 1089 |   if (isAnyMemberInitializer() || isDelegatingInitializer()) | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1090 |     return getMemberLocation(); | 
 | 1091 |    | 
| Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 1092 |   return getBaseClassLoc().getLocalSourceRange().getBegin(); | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1093 | } | 
 | 1094 |  | 
| Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1095 | SourceRange CXXCtorInitializer::getSourceRange() const { | 
| Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1096 |   return SourceRange(getSourceLocation(), getRParenLoc()); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1097 | } | 
 | 1098 |  | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1099 | CXXConstructorDecl * | 
| Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1100 | CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1101 |   return new (C) CXXConstructorDecl(0, DeclarationNameInfo(), | 
| Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1102 |                                     QualType(), 0, false, false, false); | 
 | 1103 | } | 
 | 1104 |  | 
 | 1105 | CXXConstructorDecl * | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1106 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1107 |                            const DeclarationNameInfo &NameInfo, | 
| John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1108 |                            QualType T, TypeSourceInfo *TInfo, | 
| Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1109 |                            bool isExplicit, | 
| Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1110 |                            bool isInline, | 
 | 1111 |                            bool isImplicitlyDeclared) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1112 |   assert(NameInfo.getName().getNameKind() | 
 | 1113 |          == DeclarationName::CXXConstructorName && | 
| Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1114 |          "Name must refer to a constructor"); | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1115 |   return new (C) CXXConstructorDecl(RD, NameInfo, T, TInfo, isExplicit, | 
| Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1116 |                                     isInline, isImplicitlyDeclared); | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1117 | } | 
 | 1118 |  | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1119 | bool CXXConstructorDecl::isDefaultConstructor() const { | 
 | 1120 |   // C++ [class.ctor]p5: | 
| Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1121 |   //   A default constructor for a class X is a constructor of class | 
 | 1122 |   //   X that can be called without an argument. | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1123 |   return (getNumParams() == 0) || | 
| Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame] | 1124 |          (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1125 | } | 
 | 1126 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | bool | 
| Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1128 | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1129 |   return isCopyOrMoveConstructor(TypeQuals) && | 
 | 1130 |          getParamDecl(0)->getType()->isLValueReferenceType(); | 
 | 1131 | } | 
 | 1132 |  | 
 | 1133 | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { | 
 | 1134 |   return isCopyOrMoveConstructor(TypeQuals) && | 
 | 1135 |     getParamDecl(0)->getType()->isRValueReferenceType(); | 
 | 1136 | } | 
 | 1137 |  | 
 | 1138 | /// \brief Determine whether this is a copy or move constructor. | 
 | 1139 | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1140 |   // C++ [class.copy]p2: | 
| Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1141 |   //   A non-template constructor for class X is a copy constructor | 
 | 1142 |   //   if its first parameter is of type X&, const X&, volatile X& or | 
 | 1143 |   //   const volatile X&, and either there are no other parameters | 
 | 1144 |   //   or else all other parameters have default arguments (8.3.6). | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1145 |   // C++0x [class.copy]p3: | 
 | 1146 |   //   A non-template constructor for class X is a move constructor if its | 
 | 1147 |   //   first parameter is of type X&&, const X&&, volatile X&&, or  | 
 | 1148 |   //   const volatile X&&, and either there are no other parameters or else  | 
 | 1149 |   //   all other parameters have default arguments. | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1150 |   if ((getNumParams() < 1) || | 
| Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1151 |       (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || | 
| Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1152 |       (getPrimaryTemplate() != 0) || | 
| Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1153 |       (getDescribedFunctionTemplate() != 0)) | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1154 |     return false; | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1155 |    | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1156 |   const ParmVarDecl *Param = getParamDecl(0); | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1157 |    | 
 | 1158 |   // Do we have a reference type?  | 
 | 1159 |   const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); | 
| Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1160 |   if (!ParamRefType) | 
 | 1161 |     return false; | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1162 |    | 
| Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1163 |   // Is it a reference to our class type? | 
| Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1164 |   ASTContext &Context = getASTContext(); | 
 | 1165 |    | 
| Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1166 |   CanQualType PointeeType | 
 | 1167 |     = Context.getCanonicalType(ParamRefType->getPointeeType()); | 
| Douglas Gregor | 14e0b3d | 2009-09-15 20:50:23 +0000 | [diff] [blame] | 1168 |   CanQualType ClassTy  | 
 | 1169 |     = Context.getCanonicalType(Context.getTagDeclType(getParent())); | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1170 |   if (PointeeType.getUnqualifiedType() != ClassTy) | 
 | 1171 |     return false; | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1172 |    | 
| John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1173 |   // FIXME: other qualifiers? | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1174 |    | 
 | 1175 |   // We have a copy or move constructor. | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1176 |   TypeQuals = PointeeType.getCVRQualifiers(); | 
| Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1177 |   return true;   | 
| Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1178 | } | 
 | 1179 |  | 
| Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1180 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { | 
| Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1181 |   // C++ [class.conv.ctor]p1: | 
 | 1182 |   //   A constructor declared without the function-specifier explicit | 
 | 1183 |   //   that can be called with a single parameter specifies a | 
 | 1184 |   //   conversion from the type of its first parameter to the type of | 
 | 1185 |   //   its class. Such a constructor is called a converting | 
 | 1186 |   //   constructor. | 
| Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1187 |   if (isExplicit() && !AllowExplicit) | 
| Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1188 |     return false; | 
 | 1189 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 |   return (getNumParams() == 0 && | 
| John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1191 |           getType()->getAs<FunctionProtoType>()->isVariadic()) || | 
| Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1192 |          (getNumParams() == 1) || | 
| Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 1193 |          (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); | 
| Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1194 | } | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1195 |  | 
| Douglas Gregor | 6493cc5 | 2010-11-08 17:16:59 +0000 | [diff] [blame] | 1196 | bool CXXConstructorDecl::isSpecializationCopyingObject() const { | 
| Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1197 |   if ((getNumParams() < 1) || | 
 | 1198 |       (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || | 
 | 1199 |       (getPrimaryTemplate() == 0) || | 
 | 1200 |       (getDescribedFunctionTemplate() != 0)) | 
 | 1201 |     return false; | 
 | 1202 |  | 
 | 1203 |   const ParmVarDecl *Param = getParamDecl(0); | 
 | 1204 |  | 
 | 1205 |   ASTContext &Context = getASTContext(); | 
 | 1206 |   CanQualType ParamType = Context.getCanonicalType(Param->getType()); | 
 | 1207 |    | 
| Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1208 |   // Is it the same as our our class type? | 
 | 1209 |   CanQualType ClassTy  | 
 | 1210 |     = Context.getCanonicalType(Context.getTagDeclType(getParent())); | 
 | 1211 |   if (ParamType.getUnqualifiedType() != ClassTy) | 
 | 1212 |     return false; | 
 | 1213 |    | 
 | 1214 |   return true;   | 
 | 1215 | } | 
 | 1216 |  | 
| Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1217 | const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { | 
 | 1218 |   // Hack: we store the inherited constructor in the overridden method table | 
 | 1219 |   method_iterator It = begin_overridden_methods(); | 
 | 1220 |   if (It == end_overridden_methods()) | 
 | 1221 |     return 0; | 
 | 1222 |  | 
 | 1223 |   return cast<CXXConstructorDecl>(*It); | 
 | 1224 | } | 
 | 1225 |  | 
 | 1226 | void | 
 | 1227 | CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ | 
 | 1228 |   // Hack: we store the inherited constructor in the overridden method table | 
 | 1229 |   assert(size_overridden_methods() == 0 && "Base ctor already set."); | 
 | 1230 |   addOverriddenMethod(BaseCtor); | 
 | 1231 | } | 
 | 1232 |  | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1233 | CXXDestructorDecl * | 
| Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1234 | CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1235 |   return new (C) CXXDestructorDecl(0, DeclarationNameInfo(), | 
| Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1236 |                                    QualType(), 0, false, false); | 
| Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1237 | } | 
 | 1238 |  | 
 | 1239 | CXXDestructorDecl * | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1240 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1241 |                           const DeclarationNameInfo &NameInfo, | 
| Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1242 |                           QualType T, TypeSourceInfo *TInfo, | 
 | 1243 |                           bool isInline, | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1244 |                           bool isImplicitlyDeclared) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1245 |   assert(NameInfo.getName().getNameKind() | 
 | 1246 |          == DeclarationName::CXXDestructorName && | 
| Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1247 |          "Name must refer to a destructor"); | 
| Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1248 |   return new (C) CXXDestructorDecl(RD, NameInfo, T, TInfo, isInline, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1249 |                                    isImplicitlyDeclared); | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1250 | } | 
 | 1251 |  | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1252 | CXXConversionDecl * | 
| Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1253 | CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1254 |   return new (C) CXXConversionDecl(0, DeclarationNameInfo(), | 
| Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1255 |                                    QualType(), 0, false, false); | 
 | 1256 | } | 
 | 1257 |  | 
 | 1258 | CXXConversionDecl * | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1259 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1260 |                           const DeclarationNameInfo &NameInfo, | 
| John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1261 |                           QualType T, TypeSourceInfo *TInfo, | 
| Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1262 |                           bool isInline, bool isExplicit) { | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1263 |   assert(NameInfo.getName().getNameKind() | 
 | 1264 |          == DeclarationName::CXXConversionFunctionName && | 
| Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1265 |          "Name must refer to a conversion function"); | 
| Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1266 |   return new (C) CXXConversionDecl(RD, NameInfo, T, TInfo, | 
 | 1267 |                                    isInline, isExplicit); | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1268 | } | 
 | 1269 |  | 
| Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 1270 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1271 |                                          DeclContext *DC, | 
| Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 1272 |                                          SourceLocation L, | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 1273 |                                          LanguageIDs Lang, bool Braces) { | 
| Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 1274 |   return new (C) LinkageSpecDecl(DC, L, Lang, Braces); | 
| Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 1275 | } | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1276 |  | 
 | 1277 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, | 
 | 1278 |                                                SourceLocation L, | 
 | 1279 |                                                SourceLocation NamespaceLoc, | 
| Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1280 |                                            NestedNameSpecifierLoc QualifierLoc, | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1281 |                                                SourceLocation IdentLoc, | 
| Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1282 |                                                NamedDecl *Used, | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1283 |                                                DeclContext *CommonAncestor) { | 
| Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1284 |   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) | 
 | 1285 |     Used = NS->getOriginalNamespace(); | 
| Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1286 |   return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, | 
 | 1287 |                                     IdentLoc, Used, CommonAncestor); | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1288 | } | 
 | 1289 |  | 
| Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1290 | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { | 
 | 1291 |   if (NamespaceAliasDecl *NA = | 
 | 1292 |         dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) | 
 | 1293 |     return NA->getNamespace(); | 
 | 1294 |   return cast_or_null<NamespaceDecl>(NominatedNamespace); | 
 | 1295 | } | 
 | 1296 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, | 
| Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 1298 |                                                SourceLocation UsingLoc, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 |                                                SourceLocation AliasLoc, | 
 | 1300 |                                                IdentifierInfo *Alias, | 
| Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1301 |                                            NestedNameSpecifierLoc QualifierLoc, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 |                                                SourceLocation IdentLoc, | 
| Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1303 |                                                NamedDecl *Namespace) { | 
| Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1304 |   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) | 
 | 1305 |     Namespace = NS->getOriginalNamespace(); | 
| Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1306 |   return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias,  | 
 | 1307 |                                     QualifierLoc, IdentLoc, Namespace); | 
| Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1308 | } | 
 | 1309 |  | 
| Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1310 | UsingDecl *UsingShadowDecl::getUsingDecl() const { | 
 | 1311 |   const UsingShadowDecl *Shadow = this; | 
 | 1312 |   while (const UsingShadowDecl *NextShadow = | 
 | 1313 |          dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) | 
 | 1314 |     Shadow = NextShadow; | 
 | 1315 |   return cast<UsingDecl>(Shadow->UsingOrNextShadow); | 
 | 1316 | } | 
 | 1317 |  | 
 | 1318 | void UsingDecl::addShadowDecl(UsingShadowDecl *S) { | 
 | 1319 |   assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && | 
 | 1320 |          "declaration already in set"); | 
 | 1321 |   assert(S->getUsingDecl() == this); | 
 | 1322 |  | 
 | 1323 |   if (FirstUsingShadow) | 
 | 1324 |     S->UsingOrNextShadow = FirstUsingShadow; | 
 | 1325 |   FirstUsingShadow = S; | 
 | 1326 | } | 
 | 1327 |  | 
 | 1328 | void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { | 
 | 1329 |   assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && | 
 | 1330 |          "declaration not in set"); | 
 | 1331 |   assert(S->getUsingDecl() == this); | 
 | 1332 |  | 
 | 1333 |   // Remove S from the shadow decl chain. This is O(n) but hopefully rare. | 
 | 1334 |  | 
 | 1335 |   if (FirstUsingShadow == S) { | 
 | 1336 |     FirstUsingShadow = dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow); | 
 | 1337 |     S->UsingOrNextShadow = this; | 
 | 1338 |     return; | 
 | 1339 |   } | 
 | 1340 |  | 
 | 1341 |   UsingShadowDecl *Prev = FirstUsingShadow; | 
 | 1342 |   while (Prev->UsingOrNextShadow != S) | 
 | 1343 |     Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); | 
 | 1344 |   Prev->UsingOrNextShadow = S->UsingOrNextShadow; | 
 | 1345 |   S->UsingOrNextShadow = this; | 
 | 1346 | } | 
 | 1347 |  | 
| Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1348 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, | 
 | 1349 |                              NestedNameSpecifierLoc QualifierLoc, | 
| Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1350 |                              const DeclarationNameInfo &NameInfo, | 
 | 1351 |                              bool IsTypeNameArg) { | 
| Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1352 |   return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, IsTypeNameArg); | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1353 | } | 
 | 1354 |  | 
| John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1355 | UnresolvedUsingValueDecl * | 
 | 1356 | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, | 
 | 1357 |                                  SourceLocation UsingLoc, | 
| Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1358 |                                  NestedNameSpecifierLoc QualifierLoc, | 
| Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1359 |                                  const DeclarationNameInfo &NameInfo) { | 
| John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1360 |   return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, | 
| Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1361 |                                           QualifierLoc, NameInfo); | 
| John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1362 | } | 
 | 1363 |  | 
 | 1364 | UnresolvedUsingTypenameDecl * | 
 | 1365 | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, | 
 | 1366 |                                     SourceLocation UsingLoc, | 
 | 1367 |                                     SourceLocation TypenameLoc, | 
| Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1368 |                                     NestedNameSpecifierLoc QualifierLoc, | 
| John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1369 |                                     SourceLocation TargetNameLoc, | 
 | 1370 |                                     DeclarationName TargetName) { | 
 | 1371 |   return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc, | 
| Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1372 |                                              QualifierLoc, TargetNameLoc, | 
| John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1373 |                                              TargetName.getAsIdentifierInfo()); | 
| Anders Carlsson | 665b49c | 2009-08-28 05:30:28 +0000 | [diff] [blame] | 1374 | } | 
 | 1375 |  | 
| Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 1376 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, | 
 | 1377 |                                            SourceLocation L, Expr *AssertExpr, | 
 | 1378 |                                            StringLiteral *Message) { | 
 | 1379 |   return new (C) StaticAssertDecl(DC, L, AssertExpr, Message); | 
 | 1380 | } | 
 | 1381 |  | 
| Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 1382 | static const char *getAccessName(AccessSpecifier AS) { | 
 | 1383 |   switch (AS) { | 
 | 1384 |     default: | 
 | 1385 |     case AS_none: | 
 | 1386 |       assert("Invalid access specifier!"); | 
 | 1387 |       return 0; | 
 | 1388 |     case AS_public: | 
 | 1389 |       return "public"; | 
 | 1390 |     case AS_private: | 
 | 1391 |       return "private"; | 
 | 1392 |     case AS_protected: | 
 | 1393 |       return "protected"; | 
 | 1394 |   } | 
 | 1395 | } | 
 | 1396 |  | 
 | 1397 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, | 
 | 1398 |                                            AccessSpecifier AS) { | 
 | 1399 |   return DB << getAccessName(AS); | 
 | 1400 | } |