blob: 151d333afccc04d11129b3ebb99f61e0c5e2d87f [file] [log] [blame]
Ted Kremenek4b7c9832008-09-05 17:16:31 +00001//===--- 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 Gregord475b8d2009-03-25 21:17:03 +000015#include "clang/AST/DeclTemplate.h"
Ted Kremenek4b7c9832008-09-05 17:16:31 +000016#include "clang/AST/ASTContext.h"
Anders Carlssonfb311762009-03-14 00:25:26 +000017#include "clang/AST/Expr.h"
Douglas Gregor802ab452009-12-02 22:36:29 +000018#include "clang/AST/TypeLoc.h"
Douglas Gregor7d7e6722008-11-12 23:21:09 +000019#include "clang/Basic/IdentifierTable.h"
Douglas Gregorfdfab6b2008-12-23 21:31:30 +000020#include "llvm/ADT/STLExtras.h"
Fariborz Jahanianfaebcbb2009-09-12 19:52:10 +000021#include "llvm/ADT/SmallPtrSet.h"
Ted Kremenek4b7c9832008-09-05 17:16:31 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// Decl Allocation/Deallocation Method Implementations
26//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +000027
John McCall86ff3082010-02-04 22:26:26 +000028CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
29 : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
Sebastian Redl64b45f72009-01-05 20:52:13 +000030 UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false),
Eli Friedman97c134e2009-08-15 22:23:00 +000031 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
32 Abstract(false), HasTrivialConstructor(true),
33 HasTrivialCopyConstructor(true), HasTrivialCopyAssignment(true),
Fariborz Jahanian62509212009-09-12 18:26:03 +000034 HasTrivialDestructor(true), ComputedVisibleConversions(false),
Douglas Gregor18274032010-07-03 00:47:00 +000035 DeclaredDefaultConstructor(false), DeclaredCopyConstructor(false),
Douglas Gregora376d102010-07-02 21:50:04 +000036 DeclaredCopyAssignment(false), DeclaredDestructor(false),
Fariborz Jahanian62509212009-09-12 18:26:03 +000037 Bases(0), NumBases(0), VBases(0), NumVBases(0),
John McCalld60e22e2010-03-12 01:19:31 +000038 Definition(D), FirstFriend(0) {
John McCall86ff3082010-02-04 22:26:26 +000039}
40
41CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
42 SourceLocation L, IdentifierInfo *Id,
43 CXXRecordDecl *PrevDecl,
44 SourceLocation TKL)
45 : RecordDecl(K, TK, DC, L, Id, PrevDecl, TKL),
46 DefinitionData(PrevDecl ? PrevDecl->DefinitionData : 0),
Douglas Gregord475b8d2009-03-25 21:17:03 +000047 TemplateOrInstantiation() { }
Douglas Gregor7d7e6722008-11-12 23:21:09 +000048
Ted Kremenek4b7c9832008-09-05 17:16:31 +000049CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
50 SourceLocation L, IdentifierInfo *Id,
Douglas Gregor741dd9a2009-07-21 14:46:17 +000051 SourceLocation TKL,
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000052 CXXRecordDecl* PrevDecl,
53 bool DelayTypeCreation) {
Mike Stump1eb44332009-09-09 15:08:12 +000054 CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000055 PrevDecl, TKL);
Mike Stump1eb44332009-09-09 15:08:12 +000056
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000057 // FIXME: DelayTypeCreation seems like such a hack
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000058 if (!DelayTypeCreation)
Mike Stump1eb44332009-09-09 15:08:12 +000059 C.getTypeDeclType(R, PrevDecl);
Ted Kremenek4b7c9832008-09-05 17:16:31 +000060 return R;
61}
62
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +000063CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, EmptyShell Empty) {
64 return new (C) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), 0, 0,
65 SourceLocation());
66}
67
Mike Stump1eb44332009-09-09 15:08:12 +000068void
Douglas Gregor2d5b7032010-02-11 01:30:34 +000069CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
Douglas Gregor57c856b2008-10-23 18:13:27 +000070 unsigned NumBases) {
Douglas Gregor2d5b7032010-02-11 01:30:34 +000071 ASTContext &C = getASTContext();
72
Mike Stump1eb44332009-09-09 15:08:12 +000073 // C++ [dcl.init.aggr]p1:
Douglas Gregor64bffa92008-11-05 16:20:31 +000074 // An aggregate is an array or a class (clause 9) with [...]
75 // no base classes [...].
John McCall86ff3082010-02-04 22:26:26 +000076 data().Aggregate = false;
Douglas Gregor64bffa92008-11-05 16:20:31 +000077
John McCall86ff3082010-02-04 22:26:26 +000078 if (data().Bases)
79 C.Deallocate(data().Bases);
Mike Stump1eb44332009-09-09 15:08:12 +000080
Anders Carlsson6f6de732010-03-29 05:13:12 +000081 // The set of seen virtual base types.
Anders Carlsson1c363932010-03-29 19:49:09 +000082 llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
Anders Carlsson6f6de732010-03-29 05:13:12 +000083
84 // The virtual bases of this class.
85 llvm::SmallVector<const CXXBaseSpecifier *, 8> VBases;
Mike Stump1eb44332009-09-09 15:08:12 +000086
John McCall86ff3082010-02-04 22:26:26 +000087 data().Bases = new(C) CXXBaseSpecifier [NumBases];
88 data().NumBases = NumBases;
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000089 for (unsigned i = 0; i < NumBases; ++i) {
John McCall86ff3082010-02-04 22:26:26 +000090 data().Bases[i] = *Bases[i];
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000091 // Keep track of inherited vbases for this base class.
92 const CXXBaseSpecifier *Base = Bases[i];
93 QualType BaseType = Base->getType();
Douglas Gregor5fe8c042010-02-27 00:25:28 +000094 // Skip dependent types; we can't do any checking on them now.
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000095 if (BaseType->isDependentType())
96 continue;
97 CXXRecordDecl *BaseClassDecl
Ted Kremenek6217b802009-07-29 21:53:49 +000098 = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
Anders Carlsson6f6de732010-03-29 05:13:12 +000099
Douglas Gregor6e3c7712010-09-27 23:16:44 +0000100 // C++ [dcl.init.aggr]p1:
101 // An aggregate is [...] a class with [...] no base classes [...].
102 data().Aggregate = false;
103
104 // C++ [class]p4:
105 // A POD-struct is an aggregate class...
106 data().PlainOldData = false;
107
Douglas Gregorcdbfa6c2010-09-27 23:31:14 +0000108 // A class with a non-empty base class is not empty.
109 // FIXME: Standard ref?
110 if (!BaseClassDecl->isEmpty())
111 data().Empty = false;
112
Douglas Gregor4a74df52010-09-27 23:39:06 +0000113 // C++ [class.virtual]p1:
114 // A class that declares or inherits a virtual function is called a
115 // polymorphic class.
116 if (BaseClassDecl->isPolymorphic())
117 data().Polymorphic = true;
118
Anders Carlsson6f6de732010-03-29 05:13:12 +0000119 // Now go through all virtual bases of this base and add them.
Mike Stump1eb44332009-09-09 15:08:12 +0000120 for (CXXRecordDecl::base_class_iterator VBase =
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000121 BaseClassDecl->vbases_begin(),
122 E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) {
Anders Carlsson6f6de732010-03-29 05:13:12 +0000123 // Add this base if it's not already in the list.
Anders Carlsson1c363932010-03-29 19:49:09 +0000124 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType())))
Anders Carlsson6f6de732010-03-29 05:13:12 +0000125 VBases.push_back(VBase);
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000126 }
Anders Carlsson6f6de732010-03-29 05:13:12 +0000127
128 if (Base->isVirtual()) {
129 // Add this base if it's not already in the list.
Anders Carlsson1c363932010-03-29 19:49:09 +0000130 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)))
Anders Carlsson6f6de732010-03-29 05:13:12 +0000131 VBases.push_back(Base);
Douglas Gregorcdbfa6c2010-09-27 23:31:14 +0000132
133 // C++0x [meta.unary.prop] is_empty:
134 // T is a class type, but not a union type, with ... no virtual base
135 // classes
136 data().Empty = false;
Anders Carlsson6f6de732010-03-29 05:13:12 +0000137 }
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000138 }
Anders Carlsson6f6de732010-03-29 05:13:12 +0000139
140 if (VBases.empty())
141 return;
142
143 // Create base specifier for any direct or indirect virtual bases.
144 data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
145 data().NumVBases = VBases.size();
146 for (int I = 0, E = VBases.size(); I != E; ++I) {
Nick Lewycky56062202010-07-26 16:56:01 +0000147 TypeSourceInfo *VBaseTypeInfo = VBases[I]->getTypeSourceInfo();
148
Anders Carlsson6f6de732010-03-29 05:13:12 +0000149 // Skip dependent types; we can't do any checking on them now.
Nick Lewycky56062202010-07-26 16:56:01 +0000150 if (VBaseTypeInfo->getType()->isDependentType())
Anders Carlsson6f6de732010-03-29 05:13:12 +0000151 continue;
152
Nick Lewycky56062202010-07-26 16:56:01 +0000153 CXXRecordDecl *VBaseClassDecl = cast<CXXRecordDecl>(
154 VBaseTypeInfo->getType()->getAs<RecordType>()->getDecl());
Anders Carlsson6f6de732010-03-29 05:13:12 +0000155
156 data().VBases[I] =
157 CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000158 VBaseClassDecl->getTagKind() == TTK_Class,
Nick Lewycky56062202010-07-26 16:56:01 +0000159 VBases[I]->getAccessSpecifier(), VBaseTypeInfo);
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000160 }
Douglas Gregor57c856b2008-10-23 18:13:27 +0000161}
162
Douglas Gregor9edad9b2010-01-14 17:47:39 +0000163/// Callback function for CXXRecordDecl::forallBases that acknowledges
164/// that it saw a base class.
165static bool SawBase(const CXXRecordDecl *, void *) {
166 return true;
167}
168
169bool CXXRecordDecl::hasAnyDependentBases() const {
170 if (!isDependentContext())
171 return false;
172
173 return !forallBases(SawBase, 0);
174}
175
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000176bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const {
John McCall0953e762009-09-24 19:53:00 +0000177 return getCopyConstructor(Context, Qualifiers::Const) != 0;
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000178}
179
Douglas Gregor0d405db2010-07-01 20:59:04 +0000180/// \brief Perform a simplistic form of overload resolution that only considers
181/// cv-qualifiers on a single parameter, and return the best overload candidate
182/// (if there is one).
183static CXXMethodDecl *
184GetBestOverloadCandidateSimple(
185 const llvm::SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) {
186 if (Cands.empty())
187 return 0;
188 if (Cands.size() == 1)
189 return Cands[0].first;
190
191 unsigned Best = 0, N = Cands.size();
192 for (unsigned I = 1; I != N; ++I)
193 if (Cands[Best].second.isSupersetOf(Cands[I].second))
194 Best = I;
195
196 for (unsigned I = 1; I != N; ++I)
197 if (Cands[Best].second.isSupersetOf(Cands[I].second))
198 return 0;
199
200 return Cands[Best].first;
201}
202
Mike Stump1eb44332009-09-09 15:08:12 +0000203CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context,
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000204 unsigned TypeQuals) const{
Sebastian Redl64b45f72009-01-05 20:52:13 +0000205 QualType ClassType
206 = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this));
Mike Stump1eb44332009-09-09 15:08:12 +0000207 DeclarationName ConstructorName
Douglas Gregor9e7d9de2008-12-15 21:24:18 +0000208 = Context.DeclarationNames.getCXXConstructorName(
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000209 Context.getCanonicalType(ClassType));
210 unsigned FoundTQs;
Douglas Gregor0d405db2010-07-01 20:59:04 +0000211 llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found;
Douglas Gregorfdfab6b2008-12-23 21:31:30 +0000212 DeclContext::lookup_const_iterator Con, ConEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000213 for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName);
Douglas Gregorfdfab6b2008-12-23 21:31:30 +0000214 Con != ConEnd; ++Con) {
Douglas Gregord93bacf2009-09-04 14:46:39 +0000215 // C++ [class.copy]p2:
216 // A non-template constructor for class X is a copy constructor if [...]
217 if (isa<FunctionTemplateDecl>(*Con))
218 continue;
219
Douglas Gregor0d405db2010-07-01 20:59:04 +0000220 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con);
221 if (Constructor->isCopyConstructor(FoundTQs)) {
John McCall0953e762009-09-24 19:53:00 +0000222 if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) ||
223 (!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const)))
Douglas Gregor0d405db2010-07-01 20:59:04 +0000224 Found.push_back(std::make_pair(
225 const_cast<CXXConstructorDecl *>(Constructor),
226 Qualifiers::fromCVRMask(FoundTQs)));
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000227 }
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000228 }
Douglas Gregor0d405db2010-07-01 20:59:04 +0000229
230 return cast_or_null<CXXConstructorDecl>(
231 GetBestOverloadCandidateSimple(Found));
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000232}
233
Douglas Gregorb87786f2010-07-01 17:48:08 +0000234CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const {
235 ASTContext &Context = getASTContext();
236 QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this));
237 DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal);
238
239 llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found;
240 DeclContext::lookup_const_iterator Op, OpEnd;
241 for (llvm::tie(Op, OpEnd) = this->lookup(Name); Op != OpEnd; ++Op) {
242 // C++ [class.copy]p9:
243 // A user-declared copy assignment operator is a non-static non-template
244 // member function of class X with exactly one parameter of type X, X&,
245 // const X&, volatile X& or const volatile X&.
246 const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op);
247 if (!Method || Method->isStatic() || Method->getPrimaryTemplate())
248 continue;
249
250 const FunctionProtoType *FnType
251 = Method->getType()->getAs<FunctionProtoType>();
252 assert(FnType && "Overloaded operator has no prototype.");
253 // Don't assert on this; an invalid decl might have been left in the AST.
254 if (FnType->getNumArgs() != 1 || FnType->isVariadic())
255 continue;
256
257 QualType ArgType = FnType->getArgType(0);
258 Qualifiers Quals;
259 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) {
260 ArgType = Ref->getPointeeType();
261 // If we have a const argument and we have a reference to a non-const,
262 // this function does not match.
263 if (ArgIsConst && !ArgType.isConstQualified())
264 continue;
265
266 Quals = ArgType.getQualifiers();
267 } else {
268 // By-value copy-assignment operators are treated like const X&
269 // copy-assignment operators.
270 Quals = Qualifiers::fromCVRMask(Qualifiers::Const);
271 }
272
273 if (!Context.hasSameUnqualifiedType(ArgType, Class))
274 continue;
275
276 // Save this copy-assignment operator. It might be "the one".
277 Found.push_back(std::make_pair(const_cast<CXXMethodDecl *>(Method), Quals));
278 }
279
280 // Use a simplistic form of overload resolution to find the candidate.
281 return GetBestOverloadCandidateSimple(Found);
282}
283
Sebastian Redl64b45f72009-01-05 20:52:13 +0000284void
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000285CXXRecordDecl::addedMember(Decl *D) {
286 // Ignore friends and invalid declarations.
287 if (D->getFriendObjectKind() || D->isInvalidDecl())
Douglas Gregor5c0646b2010-09-27 21:17:54 +0000288 return;
289
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000290 FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
291 if (FunTmpl)
292 D = FunTmpl->getTemplatedDecl();
293
Douglas Gregor6e3c7712010-09-27 23:16:44 +0000294 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
295 if (Method->isVirtual()) {
296 // C++ [dcl.init.aggr]p1:
297 // An aggregate is an array or a class with [...] no virtual functions.
298 data().Aggregate = false;
299
300 // C++ [class]p4:
301 // A POD-struct is an aggregate class...
302 data().PlainOldData = false;
Douglas Gregorcdbfa6c2010-09-27 23:31:14 +0000303
304 // Virtual functions make the class non-empty.
305 // FIXME: Standard ref?
306 data().Empty = false;
Douglas Gregor4a74df52010-09-27 23:39:06 +0000307
308 // C++ [class.virtual]p1:
309 // A class that declares or inherits a virtual function is called a
310 // polymorphic class.
311 data().Polymorphic = true;
Douglas Gregor6e3c7712010-09-27 23:16:44 +0000312 }
313 }
314
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000315 if (D->isImplicit()) {
316 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
317 // If this is the implicit default constructor, note that we have now
318 // declared it.
319 if (Constructor->isDefaultConstructor())
320 data().DeclaredDefaultConstructor = true;
321 // If this is the implicit copy constructor, note that we have now
322 // declared it.
323 else if (Constructor->isCopyConstructor())
324 data().DeclaredCopyConstructor = true;
Douglas Gregor0ed2e082010-09-27 22:48:58 +0000325 } else if (isa<CXXDestructorDecl>(D)) {
326 data().DeclaredDestructor = true;
327 } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000328 // If this is the implicit copy constructor, note that we have now
329 // declared it.
330 // FIXME: Move constructors
Douglas Gregor3e9438b2010-09-27 22:37:28 +0000331 if (Method->getOverloadedOperator() == OO_Equal)
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000332 data().DeclaredCopyAssignment = true;
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000333 }
334
335 // Nothing else to do for implicitly-declared members.
336 return;
337 }
338
339 // Handle (user-declared) constructors.
340 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
341 // Note that we have a user-declared constructor.
342 data().UserDeclaredConstructor = true;
343
344 // Note that we have no need of an implicitly-declared default constructor.
345 data().DeclaredDefaultConstructor = true;
346
347 // C++ [dcl.init.aggr]p1:
348 // An aggregate is an array or a class (clause 9) with no
349 // user-declared constructors (12.1) [...].
350 data().Aggregate = false;
351
352 // C++ [class]p4:
353 // A POD-struct is an aggregate class [...]
354 data().PlainOldData = false;
355
356 // C++ [class.ctor]p5:
357 // A constructor is trivial if it is an implicitly-declared default
358 // constructor.
359 // FIXME: C++0x: don't do this for "= default" default constructors.
360 data().HasTrivialConstructor = false;
361
362 // Note when we have a user-declared copy constructor, which will
363 // suppress the implicit declaration of a copy constructor.
364 if (!FunTmpl && Constructor->isCopyConstructor()) {
365 data().UserDeclaredCopyConstructor = true;
Douglas Gregor5c0646b2010-09-27 21:17:54 +0000366 data().DeclaredCopyConstructor = true;
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000367
368 // C++ [class.copy]p6:
369 // A copy constructor is trivial if it is implicitly declared.
370 // FIXME: C++0x: don't do this for "= default" copy constructors.
371 data().HasTrivialCopyConstructor = false;
372 }
Douglas Gregor5c0646b2010-09-27 21:17:54 +0000373
Douglas Gregor5c0646b2010-09-27 21:17:54 +0000374 return;
375 }
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000376
Douglas Gregor0ed2e082010-09-27 22:48:58 +0000377 // Handle (user-declared) destructors.
378 if (isa<CXXDestructorDecl>(D)) {
379 data().DeclaredDestructor = true;
380 data().UserDeclaredDestructor = true;
Douglas Gregor6e3c7712010-09-27 23:16:44 +0000381
382 // C++ [class]p4:
383 // A POD-struct is an aggregate class that has [...] no user-defined
384 // destructor.
385 data().PlainOldData = false;
386
Douglas Gregor0ed2e082010-09-27 22:48:58 +0000387 return;
388 }
Douglas Gregor5c0646b2010-09-27 21:17:54 +0000389
Douglas Gregor0ed2e082010-09-27 22:48:58 +0000390 // Handle (user-declared) member functions.
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000391 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
392 if (Method->getOverloadedOperator() == OO_Equal) {
393 // We're interested specifically in copy assignment operators.
394 const FunctionProtoType *FnType
395 = Method->getType()->getAs<FunctionProtoType>();
396 assert(FnType && "Overloaded operator has no proto function type.");
397 assert(FnType->getNumArgs() == 1 && !FnType->isVariadic());
398
399 // Copy assignment operators must be non-templates.
400 if (Method->getPrimaryTemplate() || FunTmpl)
401 return;
402
403 ASTContext &Context = getASTContext();
404 QualType ArgType = FnType->getArgType(0);
405 if (const LValueReferenceType *Ref =ArgType->getAs<LValueReferenceType>())
406 ArgType = Ref->getPointeeType();
407
408 ArgType = ArgType.getUnqualifiedType();
409 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
410 const_cast<CXXRecordDecl*>(this)));
411
412 if (!Context.hasSameUnqualifiedType(ClassType, ArgType))
413 return;
414
415 // This is a copy assignment operator.
Douglas Gregor3e9438b2010-09-27 22:37:28 +0000416 // FIXME: Move assignment operators.
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000417
418 // Suppress the implicit declaration of a copy constructor.
419 data().UserDeclaredCopyAssignment = true;
420 data().DeclaredCopyAssignment = true;
421
422 // C++ [class.copy]p11:
423 // A copy assignment operator is trivial if it is implicitly declared.
424 // FIXME: C++0x: don't do this for "= default" copy operators.
425 data().HasTrivialCopyAssignment = false;
426
427 // C++ [class]p4:
428 // A POD-struct is an aggregate class that [...] has no user-defined copy
429 // assignment operator [...].
430 data().PlainOldData = false;
431 }
Douglas Gregor22584312010-07-02 23:41:54 +0000432
Douglas Gregor27c08ab2010-09-27 22:06:20 +0000433 return;
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000434 }
Douglas Gregor6e3c7712010-09-27 23:16:44 +0000435
436 // Handle non-static data members.
437 if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) {
438 // C++ [dcl.init.aggr]p1:
439 // An aggregate is an array or a class (clause 9) with [...] no
440 // private or protected non-static data members (clause 11).
441 //
442 // A POD must be an aggregate.
443 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) {
444 data().Aggregate = false;
445 data().PlainOldData = false;
446 }
447
448 // C++ [class]p9:
449 // A POD struct is a class that is both a trivial class and a
450 // standard-layout class, and has no non-static data members of type
451 // non-POD struct, non-POD union (or array of such types).
452 ASTContext &Context = getASTContext();
453 QualType T = Context.getBaseElementType(Field->getType());
454 if (!T->isPODType())
455 data().PlainOldData = false;
Douglas Gregorcdbfa6c2010-09-27 23:31:14 +0000456
457 // If this is not a zero-length bit-field, then the class is not empty.
458 if (data().Empty) {
459 if (!Field->getBitWidth())
460 data().Empty = false;
461 else if (!Field->getBitWidth()->isTypeDependent() &&
462 !Field->getBitWidth()->isValueDependent()) {
463 llvm::APSInt Bits;
464 if (Field->getBitWidth()->isIntegerConstantExpr(Bits, Context))
465 if (!!Bits)
466 data().Empty = false;
467 }
468 }
Douglas Gregor6e3c7712010-09-27 23:16:44 +0000469 }
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000470}
471
John McCallb05b5f32010-03-15 09:07:48 +0000472static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
473 QualType T;
John McCall32daa422010-03-31 01:36:47 +0000474 if (isa<UsingShadowDecl>(Conv))
475 Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl();
John McCallb05b5f32010-03-15 09:07:48 +0000476 if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv))
477 T = ConvTemp->getTemplatedDecl()->getResultType();
478 else
479 T = cast<CXXConversionDecl>(Conv)->getConversionType();
480 return Context.getCanonicalType(T);
Fariborz Jahanian0351a1e2009-10-07 20:43:36 +0000481}
482
John McCallb05b5f32010-03-15 09:07:48 +0000483/// Collect the visible conversions of a base class.
484///
485/// \param Base a base class of the class we're considering
486/// \param InVirtual whether this base class is a virtual base (or a base
487/// of a virtual base)
488/// \param Access the access along the inheritance path to this base
489/// \param ParentHiddenTypes the conversions provided by the inheritors
490/// of this base
491/// \param Output the set to which to add conversions from non-virtual bases
492/// \param VOutput the set to which to add conversions from virtual bases
493/// \param HiddenVBaseCs the set of conversions which were hidden in a
494/// virtual base along some inheritance path
495static void CollectVisibleConversions(ASTContext &Context,
496 CXXRecordDecl *Record,
497 bool InVirtual,
498 AccessSpecifier Access,
499 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
500 UnresolvedSetImpl &Output,
501 UnresolvedSetImpl &VOutput,
502 llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) {
503 // The set of types which have conversions in this class or its
504 // subclasses. As an optimization, we don't copy the derived set
505 // unless it might change.
506 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
507 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
508
509 // Collect the direct conversions and figure out which conversions
510 // will be hidden in the subclasses.
511 UnresolvedSetImpl &Cs = *Record->getConversionFunctions();
512 if (!Cs.empty()) {
513 HiddenTypesBuffer = ParentHiddenTypes;
514 HiddenTypes = &HiddenTypesBuffer;
515
516 for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) {
517 bool Hidden =
518 !HiddenTypesBuffer.insert(GetConversionType(Context, I.getDecl()));
519
520 // If this conversion is hidden and we're in a virtual base,
521 // remember that it's hidden along some inheritance path.
522 if (Hidden && InVirtual)
523 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
524
525 // If this conversion isn't hidden, add it to the appropriate output.
526 else if (!Hidden) {
527 AccessSpecifier IAccess
528 = CXXRecordDecl::MergeAccess(Access, I.getAccess());
529
530 if (InVirtual)
531 VOutput.addDecl(I.getDecl(), IAccess);
Fariborz Jahanian62509212009-09-12 18:26:03 +0000532 else
John McCallb05b5f32010-03-15 09:07:48 +0000533 Output.addDecl(I.getDecl(), IAccess);
Fariborz Jahanian53462782009-09-11 21:44:33 +0000534 }
535 }
536 }
Sebastian Redl9994a342009-10-25 17:03:50 +0000537
John McCallb05b5f32010-03-15 09:07:48 +0000538 // Collect information recursively from any base classes.
539 for (CXXRecordDecl::base_class_iterator
540 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) {
541 const RecordType *RT = I->getType()->getAs<RecordType>();
542 if (!RT) continue;
Sebastian Redl9994a342009-10-25 17:03:50 +0000543
John McCallb05b5f32010-03-15 09:07:48 +0000544 AccessSpecifier BaseAccess
545 = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier());
546 bool BaseInVirtual = InVirtual || I->isVirtual();
Sebastian Redl9994a342009-10-25 17:03:50 +0000547
John McCallb05b5f32010-03-15 09:07:48 +0000548 CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
549 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
550 *HiddenTypes, Output, VOutput, HiddenVBaseCs);
Fariborz Jahanian53462782009-09-11 21:44:33 +0000551 }
John McCallb05b5f32010-03-15 09:07:48 +0000552}
Sebastian Redl9994a342009-10-25 17:03:50 +0000553
John McCallb05b5f32010-03-15 09:07:48 +0000554/// Collect the visible conversions of a class.
555///
556/// This would be extremely straightforward if it weren't for virtual
557/// bases. It might be worth special-casing that, really.
558static void CollectVisibleConversions(ASTContext &Context,
559 CXXRecordDecl *Record,
560 UnresolvedSetImpl &Output) {
561 // The collection of all conversions in virtual bases that we've
562 // found. These will be added to the output as long as they don't
563 // appear in the hidden-conversions set.
564 UnresolvedSet<8> VBaseCs;
565
566 // The set of conversions in virtual bases that we've determined to
567 // be hidden.
568 llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs;
569
570 // The set of types hidden by classes derived from this one.
571 llvm::SmallPtrSet<CanQualType, 8> HiddenTypes;
572
573 // Go ahead and collect the direct conversions and add them to the
574 // hidden-types set.
575 UnresolvedSetImpl &Cs = *Record->getConversionFunctions();
576 Output.append(Cs.begin(), Cs.end());
577 for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I)
578 HiddenTypes.insert(GetConversionType(Context, I.getDecl()));
579
580 // Recursively collect conversions from base classes.
581 for (CXXRecordDecl::base_class_iterator
582 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) {
583 const RecordType *RT = I->getType()->getAs<RecordType>();
584 if (!RT) continue;
585
586 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
587 I->isVirtual(), I->getAccessSpecifier(),
588 HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
589 }
590
591 // Add any unhidden conversions provided by virtual bases.
592 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
593 I != E; ++I) {
594 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
595 Output.addDecl(I.getDecl(), I.getAccess());
Fariborz Jahanian53462782009-09-11 21:44:33 +0000596 }
Fariborz Jahanian62509212009-09-12 18:26:03 +0000597}
598
599/// getVisibleConversionFunctions - get all conversion functions visible
600/// in current class; including conversion function templates.
John McCalleec51cf2010-01-20 00:46:10 +0000601const UnresolvedSetImpl *CXXRecordDecl::getVisibleConversionFunctions() {
Fariborz Jahanian62509212009-09-12 18:26:03 +0000602 // If root class, all conversions are visible.
603 if (bases_begin() == bases_end())
John McCall86ff3082010-02-04 22:26:26 +0000604 return &data().Conversions;
Fariborz Jahanian62509212009-09-12 18:26:03 +0000605 // If visible conversion list is already evaluated, return it.
John McCall86ff3082010-02-04 22:26:26 +0000606 if (data().ComputedVisibleConversions)
607 return &data().VisibleConversions;
John McCallb05b5f32010-03-15 09:07:48 +0000608 CollectVisibleConversions(getASTContext(), this, data().VisibleConversions);
John McCall86ff3082010-02-04 22:26:26 +0000609 data().ComputedVisibleConversions = true;
610 return &data().VisibleConversions;
Fariborz Jahanian53462782009-09-11 21:44:33 +0000611}
612
John McCall32daa422010-03-31 01:36:47 +0000613#ifndef NDEBUG
614void CXXRecordDecl::CheckConversionFunction(NamedDecl *ConvDecl) {
John McCallb05b5f32010-03-15 09:07:48 +0000615 assert(ConvDecl->getDeclContext() == this &&
616 "conversion function does not belong to this record");
617
John McCall32daa422010-03-31 01:36:47 +0000618 ConvDecl = ConvDecl->getUnderlyingDecl();
619 if (FunctionTemplateDecl *Temp = dyn_cast<FunctionTemplateDecl>(ConvDecl)) {
620 assert(isa<CXXConversionDecl>(Temp->getTemplatedDecl()));
621 } else {
622 assert(isa<CXXConversionDecl>(ConvDecl));
623 }
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000624}
John McCall32daa422010-03-31 01:36:47 +0000625#endif
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000626
John McCall32daa422010-03-31 01:36:47 +0000627void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) {
628 // This operation is O(N) but extremely rare. Sema only uses it to
629 // remove UsingShadowDecls in a class that were followed by a direct
630 // declaration, e.g.:
631 // class A : B {
632 // using B::operator int;
633 // operator int();
634 // };
635 // This is uncommon by itself and even more uncommon in conjunction
636 // with sufficiently large numbers of directly-declared conversions
637 // that asymptotic behavior matters.
638
639 UnresolvedSetImpl &Convs = *getConversionFunctions();
640 for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
641 if (Convs[I].getDecl() == ConvDecl) {
642 Convs.erase(I);
643 assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end()
644 && "conversion was found multiple times in unresolved set");
645 return;
646 }
647 }
648
649 llvm_unreachable("conversion not found in set!");
Douglas Gregor65ec1fd2009-08-21 23:19:43 +0000650}
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000651
Fariborz Jahaniane7184df2009-12-03 18:44:40 +0000652void CXXRecordDecl::setMethodAsVirtual(FunctionDecl *Method) {
653 Method->setVirtualAsWritten(true);
Fariborz Jahaniane7184df2009-12-03 18:44:40 +0000654 setHasTrivialConstructor(false);
655 setHasTrivialCopyConstructor(false);
656 setHasTrivialCopyAssignment(false);
657}
658
Douglas Gregorf6b11852009-10-08 15:14:33 +0000659CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const {
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000660 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
Douglas Gregorf6b11852009-10-08 15:14:33 +0000661 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
662
663 return 0;
664}
665
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000666MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const {
667 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
668}
669
Douglas Gregorf6b11852009-10-08 15:14:33 +0000670void
671CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD,
672 TemplateSpecializationKind TSK) {
673 assert(TemplateOrInstantiation.isNull() &&
674 "Previous template or instantiation?");
675 assert(!isa<ClassTemplateSpecializationDecl>(this));
676 TemplateOrInstantiation
677 = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
678}
679
Anders Carlssonb13e3572009-12-07 06:33:48 +0000680TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{
681 if (const ClassTemplateSpecializationDecl *Spec
Douglas Gregorf6b11852009-10-08 15:14:33 +0000682 = dyn_cast<ClassTemplateSpecializationDecl>(this))
683 return Spec->getSpecializationKind();
684
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000685 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
Douglas Gregorf6b11852009-10-08 15:14:33 +0000686 return MSInfo->getTemplateSpecializationKind();
687
688 return TSK_Undeclared;
689}
690
691void
692CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
693 if (ClassTemplateSpecializationDecl *Spec
694 = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
695 Spec->setSpecializationKind(TSK);
696 return;
697 }
698
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000699 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
Douglas Gregorf6b11852009-10-08 15:14:33 +0000700 MSInfo->setTemplateSpecializationKind(TSK);
701 return;
702 }
703
704 assert(false && "Not a class template or member class specialization");
705}
706
Douglas Gregor1d110e02010-07-01 14:13:13 +0000707CXXDestructorDecl *CXXRecordDecl::getDestructor() const {
708 ASTContext &Context = getASTContext();
Anders Carlsson7267c162009-05-29 21:03:38 +0000709 QualType ClassType = Context.getTypeDeclType(this);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
711 DeclarationName Name
Douglas Gregor50d62d12009-08-05 05:36:45 +0000712 = Context.DeclarationNames.getCXXDestructorName(
713 Context.getCanonicalType(ClassType));
Anders Carlsson7267c162009-05-29 21:03:38 +0000714
John McCallc0bf4622010-02-23 00:48:20 +0000715 DeclContext::lookup_const_iterator I, E;
Mike Stump1eb44332009-09-09 15:08:12 +0000716 llvm::tie(I, E) = lookup(Name);
Sebastian Redld4b25cb2010-09-02 23:19:42 +0000717 if (I == E)
718 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000719
Anders Carlsson5ec02ae2009-12-02 17:15:43 +0000720 CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I);
Anders Carlsson7267c162009-05-29 21:03:38 +0000721 assert(++I == E && "Found more than one destructor!");
Mike Stump1eb44332009-09-09 15:08:12 +0000722
Anders Carlsson7267c162009-05-29 21:03:38 +0000723 return Dtor;
724}
725
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000726CXXMethodDecl *
727CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Abramo Bagnara25777432010-08-11 22:01:17 +0000728 const DeclarationNameInfo &NameInfo,
John McCalla93c9342009-12-07 02:54:59 +0000729 QualType T, TypeSourceInfo *TInfo,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000730 bool isStatic, StorageClass SCAsWritten, bool isInline) {
Abramo Bagnara25777432010-08-11 22:01:17 +0000731 return new (C) CXXMethodDecl(CXXMethod, RD, NameInfo, T, TInfo,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000732 isStatic, SCAsWritten, isInline);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000733}
734
Douglas Gregor90916562009-09-29 18:16:17 +0000735bool CXXMethodDecl::isUsualDeallocationFunction() const {
736 if (getOverloadedOperator() != OO_Delete &&
737 getOverloadedOperator() != OO_Array_Delete)
738 return false;
Douglas Gregor6d908702010-02-26 05:06:18 +0000739
740 // C++ [basic.stc.dynamic.deallocation]p2:
741 // A template instance is never a usual deallocation function,
742 // regardless of its signature.
743 if (getPrimaryTemplate())
744 return false;
745
Douglas Gregor90916562009-09-29 18:16:17 +0000746 // C++ [basic.stc.dynamic.deallocation]p2:
747 // If a class T has a member deallocation function named operator delete
748 // with exactly one parameter, then that function is a usual (non-placement)
749 // deallocation function. [...]
750 if (getNumParams() == 1)
751 return true;
752
753 // C++ [basic.stc.dynamic.deallocation]p2:
754 // [...] If class T does not declare such an operator delete but does
755 // declare a member deallocation function named operator delete with
756 // exactly two parameters, the second of which has type std::size_t (18.1),
757 // then this function is a usual deallocation function.
758 ASTContext &Context = getASTContext();
759 if (getNumParams() != 2 ||
Chandler Carruthe228ba92010-02-08 18:54:05 +0000760 !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(),
761 Context.getSizeType()))
Douglas Gregor90916562009-09-29 18:16:17 +0000762 return false;
763
764 // This function is a usual deallocation function if there are no
765 // single-parameter deallocation functions of the same kind.
766 for (DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName());
767 R.first != R.second; ++R.first) {
768 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*R.first))
769 if (FD->getNumParams() == 1)
770 return false;
771 }
772
773 return true;
774}
775
Douglas Gregor06a9f362010-05-01 20:49:11 +0000776bool CXXMethodDecl::isCopyAssignmentOperator() const {
777 // C++0x [class.copy]p19:
778 // A user-declared copy assignment operator X::operator= is a non-static
779 // non-template member function of class X with exactly one parameter of
780 // type X, X&, const X&, volatile X& or const volatile X&.
781 if (/*operator=*/getOverloadedOperator() != OO_Equal ||
782 /*non-static*/ isStatic() ||
783 /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() ||
784 /*exactly one parameter*/getNumParams() != 1)
785 return false;
786
787 QualType ParamType = getParamDecl(0)->getType();
788 if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>())
789 ParamType = Ref->getPointeeType();
790
791 ASTContext &Context = getASTContext();
792 QualType ClassType
793 = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
794 return Context.hasSameUnqualifiedType(ClassType, ParamType);
795}
796
Anders Carlsson05eb2442009-05-16 23:58:37 +0000797void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
Anders Carlsson3aaf4862009-12-04 05:51:56 +0000798 assert(MD->isCanonicalDecl() && "Method is not canonical!");
Anders Carlssonc076c452010-01-30 17:42:34 +0000799 assert(!MD->getParent()->isDependentContext() &&
800 "Can't add an overridden method to a class template!");
801
Douglas Gregor7d10b7e2010-03-02 23:58:15 +0000802 getASTContext().addOverriddenMethod(this, MD);
Anders Carlsson05eb2442009-05-16 23:58:37 +0000803}
804
805CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
Douglas Gregor7d10b7e2010-03-02 23:58:15 +0000806 return getASTContext().overridden_methods_begin(this);
Anders Carlsson05eb2442009-05-16 23:58:37 +0000807}
808
809CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
Douglas Gregor7d10b7e2010-03-02 23:58:15 +0000810 return getASTContext().overridden_methods_end(this);
Anders Carlsson05eb2442009-05-16 23:58:37 +0000811}
812
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000813unsigned CXXMethodDecl::size_overridden_methods() const {
814 return getASTContext().overridden_methods_size(this);
815}
816
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000817QualType CXXMethodDecl::getThisType(ASTContext &C) const {
Argyrios Kyrtzidisb0d178d2008-10-24 22:28:18 +0000818 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
819 // If the member function is declared const, the type of this is const X*,
820 // if the member function is declared volatile, the type of this is
821 // volatile X*, and if the member function is declared const volatile,
822 // the type of this is const volatile X*.
823
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000824 assert(isInstance() && "No 'this' for static methods!");
Anders Carlsson31a08752009-06-13 02:59:33 +0000825
John McCall3cb0ebd2010-03-10 03:28:59 +0000826 QualType ClassTy = C.getTypeDeclType(getParent());
John McCall0953e762009-09-24 19:53:00 +0000827 ClassTy = C.getQualifiedType(ClassTy,
828 Qualifiers::fromCVRMask(getTypeQualifiers()));
Anders Carlsson4e579922009-07-10 21:35:09 +0000829 return C.getPointerType(ClassTy);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000830}
831
Eli Friedmand7d7f672009-12-06 20:50:05 +0000832bool CXXMethodDecl::hasInlineBody() const {
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000833 // If this function is a template instantiation, look at the template from
834 // which it was instantiated.
835 const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
836 if (!CheckFn)
837 CheckFn = this;
838
Eli Friedmand7d7f672009-12-06 20:50:05 +0000839 const FunctionDecl *fn;
Argyrios Kyrtzidis06a54a32010-07-07 11:31:19 +0000840 return CheckFn->hasBody(fn) && !fn->isOutOfLine();
Eli Friedmand7d7f672009-12-06 20:50:05 +0000841}
842
Douglas Gregor7ad83902008-11-05 04:29:56 +0000843CXXBaseOrMemberInitializer::
Douglas Gregor802ab452009-12-02 22:36:29 +0000844CXXBaseOrMemberInitializer(ASTContext &Context,
Anders Carlsson80638c52010-04-12 00:51:03 +0000845 TypeSourceInfo *TInfo, bool IsVirtual,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000846 SourceLocation L, Expr *Init, SourceLocation R)
Abramo Bagnaraa0af3b42010-05-26 18:09:23 +0000847 : BaseOrMember(TInfo), Init(Init), AnonUnionMember(0),
848 LParenLoc(L), RParenLoc(R), IsVirtual(IsVirtual), IsWritten(false),
849 SourceOrderOrNumArrayIndices(0)
Douglas Gregor802ab452009-12-02 22:36:29 +0000850{
Douglas Gregor7ad83902008-11-05 04:29:56 +0000851}
852
853CXXBaseOrMemberInitializer::
Douglas Gregor802ab452009-12-02 22:36:29 +0000854CXXBaseOrMemberInitializer(ASTContext &Context,
855 FieldDecl *Member, SourceLocation MemberLoc,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000856 SourceLocation L, Expr *Init, SourceLocation R)
Abramo Bagnaraa0af3b42010-05-26 18:09:23 +0000857 : BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
858 AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
859 IsWritten(false), SourceOrderOrNumArrayIndices(0)
Douglas Gregor802ab452009-12-02 22:36:29 +0000860{
Douglas Gregor7ad83902008-11-05 04:29:56 +0000861}
862
Douglas Gregorfb8cc252010-05-05 05:51:00 +0000863CXXBaseOrMemberInitializer::
864CXXBaseOrMemberInitializer(ASTContext &Context,
865 FieldDecl *Member, SourceLocation MemberLoc,
866 SourceLocation L, Expr *Init, SourceLocation R,
867 VarDecl **Indices,
868 unsigned NumIndices)
869 : BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
Abramo Bagnaraa0af3b42010-05-26 18:09:23 +0000870 AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
871 IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices)
Douglas Gregorfb8cc252010-05-05 05:51:00 +0000872{
873 VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1);
874 memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *));
875}
876
877CXXBaseOrMemberInitializer *
878CXXBaseOrMemberInitializer::Create(ASTContext &Context,
879 FieldDecl *Member,
880 SourceLocation MemberLoc,
881 SourceLocation L,
882 Expr *Init,
883 SourceLocation R,
884 VarDecl **Indices,
885 unsigned NumIndices) {
886 void *Mem = Context.Allocate(sizeof(CXXBaseOrMemberInitializer) +
887 sizeof(VarDecl *) * NumIndices,
888 llvm::alignof<CXXBaseOrMemberInitializer>());
889 return new (Mem) CXXBaseOrMemberInitializer(Context, Member, MemberLoc,
890 L, Init, R, Indices, NumIndices);
891}
892
Douglas Gregor802ab452009-12-02 22:36:29 +0000893TypeLoc CXXBaseOrMemberInitializer::getBaseClassLoc() const {
894 if (isBaseInitializer())
John McCalla93c9342009-12-07 02:54:59 +0000895 return BaseOrMember.get<TypeSourceInfo*>()->getTypeLoc();
Douglas Gregor802ab452009-12-02 22:36:29 +0000896 else
897 return TypeLoc();
898}
899
900Type *CXXBaseOrMemberInitializer::getBaseClass() {
901 if (isBaseInitializer())
John McCalla93c9342009-12-07 02:54:59 +0000902 return BaseOrMember.get<TypeSourceInfo*>()->getType().getTypePtr();
Douglas Gregor802ab452009-12-02 22:36:29 +0000903 else
904 return 0;
905}
906
907const Type *CXXBaseOrMemberInitializer::getBaseClass() const {
908 if (isBaseInitializer())
John McCalla93c9342009-12-07 02:54:59 +0000909 return BaseOrMember.get<TypeSourceInfo*>()->getType().getTypePtr();
Douglas Gregor802ab452009-12-02 22:36:29 +0000910 else
911 return 0;
912}
913
914SourceLocation CXXBaseOrMemberInitializer::getSourceLocation() const {
915 if (isMemberInitializer())
916 return getMemberLocation();
917
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000918 return getBaseClassLoc().getLocalSourceRange().getBegin();
Douglas Gregor802ab452009-12-02 22:36:29 +0000919}
920
921SourceRange CXXBaseOrMemberInitializer::getSourceRange() const {
922 return SourceRange(getSourceLocation(), getRParenLoc());
Douglas Gregor7ad83902008-11-05 04:29:56 +0000923}
924
Douglas Gregorb48fe382008-10-31 09:07:45 +0000925CXXConstructorDecl *
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000926CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) {
Abramo Bagnara25777432010-08-11 22:01:17 +0000927 return new (C) CXXConstructorDecl(0, DeclarationNameInfo(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000928 QualType(), 0, false, false, false);
929}
930
931CXXConstructorDecl *
Douglas Gregorb48fe382008-10-31 09:07:45 +0000932CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Abramo Bagnara25777432010-08-11 22:01:17 +0000933 const DeclarationNameInfo &NameInfo,
John McCalla93c9342009-12-07 02:54:59 +0000934 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000935 bool isExplicit,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000936 bool isInline,
937 bool isImplicitlyDeclared) {
Abramo Bagnara25777432010-08-11 22:01:17 +0000938 assert(NameInfo.getName().getNameKind()
939 == DeclarationName::CXXConstructorName &&
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000940 "Name must refer to a constructor");
Abramo Bagnara25777432010-08-11 22:01:17 +0000941 return new (C) CXXConstructorDecl(RD, NameInfo, T, TInfo, isExplicit,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000942 isInline, isImplicitlyDeclared);
Douglas Gregorb48fe382008-10-31 09:07:45 +0000943}
944
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000945bool CXXConstructorDecl::isDefaultConstructor() const {
946 // C++ [class.ctor]p5:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000947 // A default constructor for a class X is a constructor of class
948 // X that can be called without an argument.
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000949 return (getNumParams() == 0) ||
Anders Carlssonda3f4e22009-08-25 05:12:04 +0000950 (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg());
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000951}
952
Mike Stump1eb44332009-09-09 15:08:12 +0000953bool
Douglas Gregor9e9199d2009-12-22 00:34:07 +0000954CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000955 // C++ [class.copy]p2:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000956 // A non-template constructor for class X is a copy constructor
957 // if its first parameter is of type X&, const X&, volatile X& or
958 // const volatile X&, and either there are no other parameters
959 // or else all other parameters have default arguments (8.3.6).
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000960 if ((getNumParams() < 1) ||
Douglas Gregor77da3f42009-10-13 23:45:19 +0000961 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
Douglas Gregorfd476482009-11-13 23:59:09 +0000962 (getPrimaryTemplate() != 0) ||
Douglas Gregor77da3f42009-10-13 23:45:19 +0000963 (getDescribedFunctionTemplate() != 0))
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000964 return false;
965
966 const ParmVarDecl *Param = getParamDecl(0);
967
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000968 // Do we have a reference type? Rvalue references don't count.
Douglas Gregorfd476482009-11-13 23:59:09 +0000969 const LValueReferenceType *ParamRefType =
970 Param->getType()->getAs<LValueReferenceType>();
971 if (!ParamRefType)
972 return false;
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000973
Douglas Gregorfd476482009-11-13 23:59:09 +0000974 // Is it a reference to our class type?
Douglas Gregor9e9199d2009-12-22 00:34:07 +0000975 ASTContext &Context = getASTContext();
976
Douglas Gregorfd476482009-11-13 23:59:09 +0000977 CanQualType PointeeType
978 = Context.getCanonicalType(ParamRefType->getPointeeType());
Douglas Gregor14e0b3d2009-09-15 20:50:23 +0000979 CanQualType ClassTy
980 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000981 if (PointeeType.getUnqualifiedType() != ClassTy)
982 return false;
983
John McCall0953e762009-09-24 19:53:00 +0000984 // FIXME: other qualifiers?
985
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000986 // We have a copy constructor.
987 TypeQuals = PointeeType.getCVRQualifiers();
988 return true;
989}
990
Anders Carlssonfaccd722009-08-28 16:57:08 +0000991bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
Douglas Gregor60d62c22008-10-31 16:23:19 +0000992 // C++ [class.conv.ctor]p1:
993 // A constructor declared without the function-specifier explicit
994 // that can be called with a single parameter specifies a
995 // conversion from the type of its first parameter to the type of
996 // its class. Such a constructor is called a converting
997 // constructor.
Anders Carlssonfaccd722009-08-28 16:57:08 +0000998 if (isExplicit() && !AllowExplicit)
Douglas Gregor60d62c22008-10-31 16:23:19 +0000999 return false;
1000
Mike Stump1eb44332009-09-09 15:08:12 +00001001 return (getNumParams() == 0 &&
John McCall183700f2009-09-21 23:43:11 +00001002 getType()->getAs<FunctionProtoType>()->isVariadic()) ||
Douglas Gregor60d62c22008-10-31 16:23:19 +00001003 (getNumParams() == 1) ||
Anders Carlssonae0b4e72009-06-06 04:14:07 +00001004 (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg());
Douglas Gregor60d62c22008-10-31 16:23:19 +00001005}
Douglas Gregorb48fe382008-10-31 09:07:45 +00001006
Douglas Gregor66724ea2009-11-14 01:20:54 +00001007bool CXXConstructorDecl::isCopyConstructorLikeSpecialization() const {
1008 if ((getNumParams() < 1) ||
1009 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
1010 (getPrimaryTemplate() == 0) ||
1011 (getDescribedFunctionTemplate() != 0))
1012 return false;
1013
1014 const ParmVarDecl *Param = getParamDecl(0);
1015
1016 ASTContext &Context = getASTContext();
1017 CanQualType ParamType = Context.getCanonicalType(Param->getType());
1018
1019 // Strip off the lvalue reference, if any.
1020 if (CanQual<LValueReferenceType> ParamRefType
1021 = ParamType->getAs<LValueReferenceType>())
1022 ParamType = ParamRefType->getPointeeType();
1023
1024
1025 // Is it the same as our our class type?
1026 CanQualType ClassTy
1027 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
1028 if (ParamType.getUnqualifiedType() != ClassTy)
1029 return false;
1030
1031 return true;
1032}
1033
Douglas Gregor42a552f2008-11-05 20:51:48 +00001034CXXDestructorDecl *
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001035CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) {
Abramo Bagnara25777432010-08-11 22:01:17 +00001036 return new (C) CXXDestructorDecl(0, DeclarationNameInfo(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001037 QualType(), false, false);
1038}
1039
1040CXXDestructorDecl *
Douglas Gregor42a552f2008-11-05 20:51:48 +00001041CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Abramo Bagnara25777432010-08-11 22:01:17 +00001042 const DeclarationNameInfo &NameInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001043 QualType T, bool isInline,
Douglas Gregor42a552f2008-11-05 20:51:48 +00001044 bool isImplicitlyDeclared) {
Abramo Bagnara25777432010-08-11 22:01:17 +00001045 assert(NameInfo.getName().getNameKind()
1046 == DeclarationName::CXXDestructorName &&
Douglas Gregor2e1cd422008-11-17 14:58:09 +00001047 "Name must refer to a destructor");
Abramo Bagnara25777432010-08-11 22:01:17 +00001048 return new (C) CXXDestructorDecl(RD, NameInfo, T, isInline,
1049 isImplicitlyDeclared);
Douglas Gregor42a552f2008-11-05 20:51:48 +00001050}
1051
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001052CXXConversionDecl *
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001053CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) {
Abramo Bagnara25777432010-08-11 22:01:17 +00001054 return new (C) CXXConversionDecl(0, DeclarationNameInfo(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001055 QualType(), 0, false, false);
1056}
1057
1058CXXConversionDecl *
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001059CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Abramo Bagnara25777432010-08-11 22:01:17 +00001060 const DeclarationNameInfo &NameInfo,
John McCalla93c9342009-12-07 02:54:59 +00001061 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001062 bool isInline, bool isExplicit) {
Abramo Bagnara25777432010-08-11 22:01:17 +00001063 assert(NameInfo.getName().getNameKind()
1064 == DeclarationName::CXXConversionFunctionName &&
Douglas Gregor2e1cd422008-11-17 14:58:09 +00001065 "Name must refer to a conversion function");
Abramo Bagnara25777432010-08-11 22:01:17 +00001066 return new (C) CXXConversionDecl(RD, NameInfo, T, TInfo,
1067 isInline, isExplicit);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001068}
1069
Chris Lattner21ef7ae2008-11-04 16:51:42 +00001070LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +00001071 DeclContext *DC,
Chris Lattner21ef7ae2008-11-04 16:51:42 +00001072 SourceLocation L,
Douglas Gregor074149e2009-01-05 19:45:36 +00001073 LanguageIDs Lang, bool Braces) {
Steve Naroff3e970492009-01-27 21:25:57 +00001074 return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
Douglas Gregorf44515a2008-12-16 22:23:02 +00001075}
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001076
1077UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
1078 SourceLocation L,
1079 SourceLocation NamespaceLoc,
Douglas Gregor8419fa32009-05-30 06:31:56 +00001080 SourceRange QualifierRange,
1081 NestedNameSpecifier *Qualifier,
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001082 SourceLocation IdentLoc,
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001083 NamedDecl *Used,
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001084 DeclContext *CommonAncestor) {
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001085 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used))
1086 Used = NS->getOriginalNamespace();
Mike Stump1eb44332009-09-09 15:08:12 +00001087 return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange,
Douglas Gregor8419fa32009-05-30 06:31:56 +00001088 Qualifier, IdentLoc, Used, CommonAncestor);
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001089}
1090
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001091NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
1092 if (NamespaceAliasDecl *NA =
1093 dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
1094 return NA->getNamespace();
1095 return cast_or_null<NamespaceDecl>(NominatedNamespace);
1096}
1097
Mike Stump1eb44332009-09-09 15:08:12 +00001098NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001099 SourceLocation UsingLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001100 SourceLocation AliasLoc,
1101 IdentifierInfo *Alias,
Douglas Gregor6c9c9402009-05-30 06:48:27 +00001102 SourceRange QualifierRange,
1103 NestedNameSpecifier *Qualifier,
Mike Stump1eb44332009-09-09 15:08:12 +00001104 SourceLocation IdentLoc,
Anders Carlsson68771c72009-03-28 22:58:02 +00001105 NamedDecl *Namespace) {
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001106 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
1107 Namespace = NS->getOriginalNamespace();
Douglas Gregor0a35bce2010-09-01 03:07:18 +00001108 return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, QualifierRange,
Douglas Gregor6c9c9402009-05-30 06:48:27 +00001109 Qualifier, IdentLoc, Namespace);
Anders Carlsson68771c72009-03-28 22:58:02 +00001110}
1111
Douglas Gregor9cfbe482009-06-20 00:51:54 +00001112UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC,
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001113 SourceRange NNR, SourceLocation UL,
1114 NestedNameSpecifier* TargetNNS,
1115 const DeclarationNameInfo &NameInfo,
1116 bool IsTypeNameArg) {
1117 return new (C) UsingDecl(DC, NNR, UL, TargetNNS, NameInfo, IsTypeNameArg);
Douglas Gregor9cfbe482009-06-20 00:51:54 +00001118}
1119
John McCall7ba107a2009-11-18 02:36:19 +00001120UnresolvedUsingValueDecl *
1121UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
1122 SourceLocation UsingLoc,
1123 SourceRange TargetNNR,
1124 NestedNameSpecifier *TargetNNS,
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001125 const DeclarationNameInfo &NameInfo) {
John McCall7ba107a2009-11-18 02:36:19 +00001126 return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001127 TargetNNR, TargetNNS, NameInfo);
John McCall7ba107a2009-11-18 02:36:19 +00001128}
1129
1130UnresolvedUsingTypenameDecl *
1131UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
1132 SourceLocation UsingLoc,
1133 SourceLocation TypenameLoc,
1134 SourceRange TargetNNR,
1135 NestedNameSpecifier *TargetNNS,
1136 SourceLocation TargetNameLoc,
1137 DeclarationName TargetName) {
1138 return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc,
1139 TargetNNR, TargetNNS,
1140 TargetNameLoc,
1141 TargetName.getAsIdentifierInfo());
Anders Carlsson665b49c2009-08-28 05:30:28 +00001142}
1143
Anders Carlssonfb311762009-03-14 00:25:26 +00001144StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
1145 SourceLocation L, Expr *AssertExpr,
1146 StringLiteral *Message) {
1147 return new (C) StaticAssertDecl(DC, L, AssertExpr, Message);
1148}
1149
Anders Carlsson05bf2c72009-03-26 23:46:50 +00001150static const char *getAccessName(AccessSpecifier AS) {
1151 switch (AS) {
1152 default:
1153 case AS_none:
1154 assert("Invalid access specifier!");
1155 return 0;
1156 case AS_public:
1157 return "public";
1158 case AS_private:
1159 return "private";
1160 case AS_protected:
1161 return "protected";
1162 }
1163}
1164
1165const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
1166 AccessSpecifier AS) {
1167 return DB << getAccessName(AS);
1168}