/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/DeclCXX.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | /// \file |
10 | | /// Defines the C++ Decl subclasses, other than those for templates |
11 | | /// (found in DeclTemplate.h) and friends (in DeclFriend.h). |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_CLANG_AST_DECLCXX_H |
16 | | #define LLVM_CLANG_AST_DECLCXX_H |
17 | | |
18 | | #include "clang/AST/ASTUnresolvedSet.h" |
19 | | #include "clang/AST/Decl.h" |
20 | | #include "clang/AST/DeclBase.h" |
21 | | #include "clang/AST/DeclarationName.h" |
22 | | #include "clang/AST/Expr.h" |
23 | | #include "clang/AST/ExternalASTSource.h" |
24 | | #include "clang/AST/LambdaCapture.h" |
25 | | #include "clang/AST/NestedNameSpecifier.h" |
26 | | #include "clang/AST/Redeclarable.h" |
27 | | #include "clang/AST/Stmt.h" |
28 | | #include "clang/AST/Type.h" |
29 | | #include "clang/AST/TypeLoc.h" |
30 | | #include "clang/AST/UnresolvedSet.h" |
31 | | #include "clang/Basic/LLVM.h" |
32 | | #include "clang/Basic/Lambda.h" |
33 | | #include "clang/Basic/LangOptions.h" |
34 | | #include "clang/Basic/OperatorKinds.h" |
35 | | #include "clang/Basic/SourceLocation.h" |
36 | | #include "clang/Basic/Specifiers.h" |
37 | | #include "llvm/ADT/ArrayRef.h" |
38 | | #include "llvm/ADT/DenseMap.h" |
39 | | #include "llvm/ADT/PointerIntPair.h" |
40 | | #include "llvm/ADT/PointerUnion.h" |
41 | | #include "llvm/ADT/STLExtras.h" |
42 | | #include "llvm/ADT/TinyPtrVector.h" |
43 | | #include "llvm/ADT/iterator_range.h" |
44 | | #include "llvm/Support/Casting.h" |
45 | | #include "llvm/Support/Compiler.h" |
46 | | #include "llvm/Support/PointerLikeTypeTraits.h" |
47 | | #include "llvm/Support/TrailingObjects.h" |
48 | | #include <cassert> |
49 | | #include <cstddef> |
50 | | #include <iterator> |
51 | | #include <memory> |
52 | | #include <vector> |
53 | | |
54 | | namespace clang { |
55 | | |
56 | | class ASTContext; |
57 | | class ClassTemplateDecl; |
58 | | class ConstructorUsingShadowDecl; |
59 | | class CXXBasePath; |
60 | | class CXXBasePaths; |
61 | | class CXXConstructorDecl; |
62 | | class CXXDestructorDecl; |
63 | | class CXXFinalOverriderMap; |
64 | | class CXXIndirectPrimaryBaseSet; |
65 | | class CXXMethodDecl; |
66 | | class DecompositionDecl; |
67 | | class DiagnosticBuilder; |
68 | | class FriendDecl; |
69 | | class FunctionTemplateDecl; |
70 | | class IdentifierInfo; |
71 | | class MemberSpecializationInfo; |
72 | | class TemplateDecl; |
73 | | class TemplateParameterList; |
74 | | class UsingDecl; |
75 | | |
76 | | /// Represents an access specifier followed by colon ':'. |
77 | | /// |
78 | | /// An objects of this class represents sugar for the syntactic occurrence |
79 | | /// of an access specifier followed by a colon in the list of member |
80 | | /// specifiers of a C++ class definition. |
81 | | /// |
82 | | /// Note that they do not represent other uses of access specifiers, |
83 | | /// such as those occurring in a list of base specifiers. |
84 | | /// Also note that this class has nothing to do with so-called |
85 | | /// "access declarations" (C++98 11.3 [class.access.dcl]). |
86 | | class AccessSpecDecl : public Decl { |
87 | | /// The location of the ':'. |
88 | | SourceLocation ColonLoc; |
89 | | |
90 | | AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, |
91 | | SourceLocation ASLoc, SourceLocation ColonLoc) |
92 | 342k | : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { |
93 | 342k | setAccess(AS); |
94 | 342k | } |
95 | | |
96 | 36.4k | AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {} |
97 | | |
98 | | virtual void anchor(); |
99 | | |
100 | | public: |
101 | | /// The location of the access specifier. |
102 | 165k | SourceLocation getAccessSpecifierLoc() const { return getLocation(); } |
103 | | |
104 | | /// Sets the location of the access specifier. |
105 | 0 | void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } |
106 | | |
107 | | /// The location of the colon following the access specifier. |
108 | 214k | SourceLocation getColonLoc() const { return ColonLoc; } |
109 | | |
110 | | /// Sets the location of the colon. |
111 | 36.4k | void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } |
112 | | |
113 | 429 | SourceRange getSourceRange() const override LLVM_READONLY { |
114 | 429 | return SourceRange(getAccessSpecifierLoc(), getColonLoc()); |
115 | 429 | } |
116 | | |
117 | | static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, |
118 | | DeclContext *DC, SourceLocation ASLoc, |
119 | 342k | SourceLocation ColonLoc) { |
120 | 342k | return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); |
121 | 342k | } |
122 | | |
123 | | static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
124 | | |
125 | | // Implement isa/cast/dyncast/etc. |
126 | 21.8k | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
127 | 21.8k | static bool classofKind(Kind K) { return K == AccessSpec; } |
128 | | }; |
129 | | |
130 | | /// Represents a base class of a C++ class. |
131 | | /// |
132 | | /// Each CXXBaseSpecifier represents a single, direct base class (or |
133 | | /// struct) of a C++ class (or struct). It specifies the type of that |
134 | | /// base class, whether it is a virtual or non-virtual base, and what |
135 | | /// level of access (public, protected, private) is used for the |
136 | | /// derivation. For example: |
137 | | /// |
138 | | /// \code |
139 | | /// class A { }; |
140 | | /// class B { }; |
141 | | /// class C : public virtual A, protected B { }; |
142 | | /// \endcode |
143 | | /// |
144 | | /// In this code, C will have two CXXBaseSpecifiers, one for "public |
145 | | /// virtual A" and the other for "protected B". |
146 | | class CXXBaseSpecifier { |
147 | | /// The source code range that covers the full base |
148 | | /// specifier, including the "virtual" (if present) and access |
149 | | /// specifier (if present). |
150 | | SourceRange Range; |
151 | | |
152 | | /// The source location of the ellipsis, if this is a pack |
153 | | /// expansion. |
154 | | SourceLocation EllipsisLoc; |
155 | | |
156 | | /// Whether this is a virtual base class or not. |
157 | | unsigned Virtual : 1; |
158 | | |
159 | | /// Whether this is the base of a class (true) or of a struct (false). |
160 | | /// |
161 | | /// This determines the mapping from the access specifier as written in the |
162 | | /// source code to the access specifier used for semantic analysis. |
163 | | unsigned BaseOfClass : 1; |
164 | | |
165 | | /// Access specifier as written in the source code (may be AS_none). |
166 | | /// |
167 | | /// The actual type of data stored here is an AccessSpecifier, but we use |
168 | | /// "unsigned" here to work around a VC++ bug. |
169 | | unsigned Access : 2; |
170 | | |
171 | | /// Whether the class contains a using declaration |
172 | | /// to inherit the named class's constructors. |
173 | | unsigned InheritConstructors : 1; |
174 | | |
175 | | /// The type of the base class. |
176 | | /// |
177 | | /// This will be a class or struct (or a typedef of such). The source code |
178 | | /// range does not include the \c virtual or the access specifier. |
179 | | TypeSourceInfo *BaseTypeInfo; |
180 | | |
181 | | public: |
182 | 540k | CXXBaseSpecifier() = default; |
183 | | CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, |
184 | | TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) |
185 | | : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), |
186 | 477k | Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {} |
187 | | |
188 | | /// Retrieves the source range that contains the entire base specifier. |
189 | 508k | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
190 | 85.2k | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
191 | 12 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
192 | | |
193 | | /// Get the location at which the base class type was written. |
194 | 35.2k | SourceLocation getBaseTypeLoc() const LLVM_READONLY { |
195 | 35.2k | return BaseTypeInfo->getTypeLoc().getBeginLoc(); |
196 | 35.2k | } |
197 | | |
198 | | /// Determines whether the base class is a virtual base class (or not). |
199 | 8.98M | bool isVirtual() const { return Virtual; } |
200 | | |
201 | | /// Determine whether this base class is a base of a class declared |
202 | | /// with the 'class' keyword (vs. one declared with the 'struct' keyword). |
203 | 46.8k | bool isBaseOfClass() const { return BaseOfClass; } |
204 | | |
205 | | /// Determine whether this base specifier is a pack expansion. |
206 | 267k | bool isPackExpansion() const { return EllipsisLoc.isValid(); } |
207 | | |
208 | | /// Determine whether this base class's constructors get inherited. |
209 | 24.2k | bool getInheritConstructors() const { return InheritConstructors; } |
210 | | |
211 | | /// Set that this base class's constructors should be inherited. |
212 | 37.8k | void setInheritConstructors(bool Inherit = true) { |
213 | 37.8k | InheritConstructors = Inherit; |
214 | 37.8k | } |
215 | | |
216 | | /// For a pack expansion, determine the location of the ellipsis. |
217 | 1.72k | SourceLocation getEllipsisLoc() const { |
218 | 1.72k | return EllipsisLoc; |
219 | 1.72k | } |
220 | | |
221 | | /// Returns the access specifier for this base specifier. |
222 | | /// |
223 | | /// This is the actual base specifier as used for semantic analysis, so |
224 | | /// the result can never be AS_none. To retrieve the access specifier as |
225 | | /// written in the source code, use getAccessSpecifierAsWritten(). |
226 | 1.80M | AccessSpecifier getAccessSpecifier() const { |
227 | 1.80M | if ((AccessSpecifier)Access == AS_none) |
228 | 596k | return BaseOfClass? AS_private5.85k : AS_public590k ; |
229 | 1.21M | else |
230 | 1.21M | return (AccessSpecifier)Access; |
231 | 1.80M | } |
232 | | |
233 | | /// Retrieves the access specifier as written in the source code |
234 | | /// (which may mean that no access specifier was explicitly written). |
235 | | /// |
236 | | /// Use getAccessSpecifier() to retrieve the access specifier for use in |
237 | | /// semantic analysis. |
238 | 274k | AccessSpecifier getAccessSpecifierAsWritten() const { |
239 | 274k | return (AccessSpecifier)Access; |
240 | 274k | } |
241 | | |
242 | | /// Retrieves the type of the base class. |
243 | | /// |
244 | | /// This type will always be an unqualified class type. |
245 | 18.4M | QualType getType() const { |
246 | 18.4M | return BaseTypeInfo->getType().getUnqualifiedType(); |
247 | 18.4M | } |
248 | | |
249 | | /// Retrieves the type and source location of the base class. |
250 | 289k | TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } |
251 | | }; |
252 | | |
253 | | /// Represents a C++ struct/union/class. |
254 | | class CXXRecordDecl : public RecordDecl { |
255 | | friend class ASTDeclReader; |
256 | | friend class ASTDeclWriter; |
257 | | friend class ASTNodeImporter; |
258 | | friend class ASTReader; |
259 | | friend class ASTRecordWriter; |
260 | | friend class ASTWriter; |
261 | | friend class DeclContext; |
262 | | friend class LambdaExpr; |
263 | | |
264 | | friend void FunctionDecl::setPure(bool); |
265 | | friend void TagDecl::startDefinition(); |
266 | | |
267 | | /// Values used in DefinitionData fields to represent special members. |
268 | | enum SpecialMemberFlags { |
269 | | SMF_DefaultConstructor = 0x1, |
270 | | SMF_CopyConstructor = 0x2, |
271 | | SMF_MoveConstructor = 0x4, |
272 | | SMF_CopyAssignment = 0x8, |
273 | | SMF_MoveAssignment = 0x10, |
274 | | SMF_Destructor = 0x20, |
275 | | SMF_All = 0x3f |
276 | | }; |
277 | | |
278 | | struct DefinitionData { |
279 | | #define FIELD(Name, Width, Merge) \ |
280 | | unsigned Name : Width; |
281 | | #include "CXXRecordDeclDefinitionBits.def" |
282 | | |
283 | | /// Whether this class describes a C++ lambda. |
284 | | unsigned IsLambda : 1; |
285 | | |
286 | | /// Whether we are currently parsing base specifiers. |
287 | | unsigned IsParsingBaseSpecifiers : 1; |
288 | | |
289 | | /// True when visible conversion functions are already computed |
290 | | /// and are available. |
291 | | unsigned ComputedVisibleConversions : 1; |
292 | | |
293 | | unsigned HasODRHash : 1; |
294 | | |
295 | | /// A hash of parts of the class to help in ODR checking. |
296 | | unsigned ODRHash = 0; |
297 | | |
298 | | /// The number of base class specifiers in Bases. |
299 | | unsigned NumBases = 0; |
300 | | |
301 | | /// The number of virtual base class specifiers in VBases. |
302 | | unsigned NumVBases = 0; |
303 | | |
304 | | /// Base classes of this class. |
305 | | /// |
306 | | /// FIXME: This is wasted space for a union. |
307 | | LazyCXXBaseSpecifiersPtr Bases; |
308 | | |
309 | | /// direct and indirect virtual base classes of this class. |
310 | | LazyCXXBaseSpecifiersPtr VBases; |
311 | | |
312 | | /// The conversion functions of this C++ class (but not its |
313 | | /// inherited conversion functions). |
314 | | /// |
315 | | /// Each of the entries in this overload set is a CXXConversionDecl. |
316 | | LazyASTUnresolvedSet Conversions; |
317 | | |
318 | | /// The conversion functions of this C++ class and all those |
319 | | /// inherited conversion functions that are visible in this class. |
320 | | /// |
321 | | /// Each of the entries in this overload set is a CXXConversionDecl or a |
322 | | /// FunctionTemplateDecl. |
323 | | LazyASTUnresolvedSet VisibleConversions; |
324 | | |
325 | | /// The declaration which defines this record. |
326 | | CXXRecordDecl *Definition; |
327 | | |
328 | | /// The first friend declaration in this class, or null if there |
329 | | /// aren't any. |
330 | | /// |
331 | | /// This is actually currently stored in reverse order. |
332 | | LazyDeclPtr FirstFriend; |
333 | | |
334 | | DefinitionData(CXXRecordDecl *D); |
335 | | |
336 | | /// Retrieve the set of direct base classes. |
337 | 40.7M | CXXBaseSpecifier *getBases() const { |
338 | 40.7M | if (!Bases.isOffset()) |
339 | 40.7M | return Bases.get(nullptr); |
340 | 33.8k | return getBasesSlowCase(); |
341 | 33.8k | } |
342 | | |
343 | | /// Retrieve the set of virtual base classes. |
344 | 2.99M | CXXBaseSpecifier *getVBases() const { |
345 | 2.99M | if (!VBases.isOffset()) |
346 | 2.99M | return VBases.get(nullptr); |
347 | 14 | return getVBasesSlowCase(); |
348 | 14 | } |
349 | | |
350 | 20.8k | ArrayRef<CXXBaseSpecifier> bases() const { |
351 | 20.8k | return llvm::makeArrayRef(getBases(), NumBases); |
352 | 20.8k | } |
353 | | |
354 | 117 | ArrayRef<CXXBaseSpecifier> vbases() const { |
355 | 117 | return llvm::makeArrayRef(getVBases(), NumVBases); |
356 | 117 | } |
357 | | |
358 | | private: |
359 | | CXXBaseSpecifier *getBasesSlowCase() const; |
360 | | CXXBaseSpecifier *getVBasesSlowCase() const; |
361 | | }; |
362 | | |
363 | | struct DefinitionData *DefinitionData; |
364 | | |
365 | | /// Describes a C++ closure type (generated by a lambda expression). |
366 | | struct LambdaDefinitionData : public DefinitionData { |
367 | | using Capture = LambdaCapture; |
368 | | |
369 | | /// Whether this lambda is known to be dependent, even if its |
370 | | /// context isn't dependent. |
371 | | /// |
372 | | /// A lambda with a non-dependent context can be dependent if it occurs |
373 | | /// within the default argument of a function template, because the |
374 | | /// lambda will have been created with the enclosing context as its |
375 | | /// declaration context, rather than function. This is an unfortunate |
376 | | /// artifact of having to parse the default arguments before. |
377 | | unsigned Dependent : 1; |
378 | | |
379 | | /// Whether this lambda is a generic lambda. |
380 | | unsigned IsGenericLambda : 1; |
381 | | |
382 | | /// The Default Capture. |
383 | | unsigned CaptureDefault : 2; |
384 | | |
385 | | /// The number of captures in this lambda is limited 2^NumCaptures. |
386 | | unsigned NumCaptures : 15; |
387 | | |
388 | | /// The number of explicit captures in this lambda. |
389 | | unsigned NumExplicitCaptures : 13; |
390 | | |
391 | | /// Has known `internal` linkage. |
392 | | unsigned HasKnownInternalLinkage : 1; |
393 | | |
394 | | /// The number used to indicate this lambda expression for name |
395 | | /// mangling in the Itanium C++ ABI. |
396 | | unsigned ManglingNumber : 31; |
397 | | |
398 | | /// The declaration that provides context for this lambda, if the |
399 | | /// actual DeclContext does not suffice. This is used for lambdas that |
400 | | /// occur within default arguments of function parameters within the class |
401 | | /// or within a data member initializer. |
402 | | LazyDeclPtr ContextDecl; |
403 | | |
404 | | /// The list of captures, both explicit and implicit, for this |
405 | | /// lambda. |
406 | | Capture *Captures = nullptr; |
407 | | |
408 | | /// The type of the call method. |
409 | | TypeSourceInfo *MethodTyInfo; |
410 | | |
411 | | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent, |
412 | | bool IsGeneric, LambdaCaptureDefault CaptureDefault) |
413 | | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
414 | | CaptureDefault(CaptureDefault), NumCaptures(0), |
415 | | NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0), |
416 | 10.3k | MethodTyInfo(Info) { |
417 | 10.3k | IsLambda = true; |
418 | | |
419 | | // C++1z [expr.prim.lambda]p4: |
420 | | // This class type is not an aggregate type. |
421 | 10.3k | Aggregate = false; |
422 | 10.3k | PlainOldData = false; |
423 | 10.3k | } |
424 | | }; |
425 | | |
426 | 265M | struct DefinitionData *dataPtr() const { |
427 | | // Complete the redecl chain (if necessary). |
428 | 265M | getMostRecentDecl(); |
429 | 265M | return DefinitionData; |
430 | 265M | } |
431 | | |
432 | 264M | struct DefinitionData &data() const { |
433 | 264M | auto *DD = dataPtr(); |
434 | 264M | assert(DD && "queried property of class with no definition"); |
435 | 264M | return *DD; |
436 | 264M | } |
437 | | |
438 | 762k | struct LambdaDefinitionData &getLambdaData() const { |
439 | | // No update required: a merged definition cannot change any lambda |
440 | | // properties. |
441 | 762k | auto *DD = DefinitionData; |
442 | 762k | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class"); |
443 | 762k | return static_cast<LambdaDefinitionData&>(*DD); |
444 | 762k | } |
445 | | |
446 | | /// The template or declaration that this declaration |
447 | | /// describes or was instantiated from, respectively. |
448 | | /// |
449 | | /// For non-templates, this value will be null. For record |
450 | | /// declarations that describe a class template, this will be a |
451 | | /// pointer to a ClassTemplateDecl. For member |
452 | | /// classes of class template specializations, this will be the |
453 | | /// MemberSpecializationInfo referring to the member class that was |
454 | | /// instantiated or specialized. |
455 | | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
456 | | TemplateOrInstantiation; |
457 | | |
458 | | /// Called from setBases and addedMember to notify the class that a |
459 | | /// direct or virtual base class or a member of class type has been added. |
460 | | void addedClassSubobject(CXXRecordDecl *Base); |
461 | | |
462 | | /// Notify the class that member has been added. |
463 | | /// |
464 | | /// This routine helps maintain information about the class based on which |
465 | | /// members have been added. It will be invoked by DeclContext::addDecl() |
466 | | /// whenever a member is added to this record. |
467 | | void addedMember(Decl *D); |
468 | | |
469 | | void markedVirtualFunctionPure(); |
470 | | |
471 | | /// Get the head of our list of friend declarations, possibly |
472 | | /// deserializing the friends from an external AST source. |
473 | | FriendDecl *getFirstFriend() const; |
474 | | |
475 | | /// Determine whether this class has an empty base class subobject of type X |
476 | | /// or of one of the types that might be at offset 0 within X (per the C++ |
477 | | /// "standard layout" rules). |
478 | | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
479 | | const CXXRecordDecl *X); |
480 | | |
481 | | protected: |
482 | | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
483 | | SourceLocation StartLoc, SourceLocation IdLoc, |
484 | | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
485 | | |
486 | | public: |
487 | | /// Iterator that traverses the base classes of a class. |
488 | | using base_class_iterator = CXXBaseSpecifier *; |
489 | | |
490 | | /// Iterator that traverses the base classes of a class. |
491 | | using base_class_const_iterator = const CXXBaseSpecifier *; |
492 | | |
493 | 41.2M | CXXRecordDecl *getCanonicalDecl() override { |
494 | 41.2M | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
495 | 41.2M | } |
496 | | |
497 | 6.30M | const CXXRecordDecl *getCanonicalDecl() const { |
498 | 6.30M | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
499 | 6.30M | } |
500 | | |
501 | 3.27M | CXXRecordDecl *getPreviousDecl() { |
502 | 3.27M | return cast_or_null<CXXRecordDecl>( |
503 | 3.27M | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
504 | 3.27M | } |
505 | | |
506 | 248k | const CXXRecordDecl *getPreviousDecl() const { |
507 | 248k | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
508 | 248k | } |
509 | | |
510 | 267M | CXXRecordDecl *getMostRecentDecl() { |
511 | 267M | return cast<CXXRecordDecl>( |
512 | 267M | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
513 | 267M | } |
514 | | |
515 | 265M | const CXXRecordDecl *getMostRecentDecl() const { |
516 | 265M | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
517 | 265M | } |
518 | | |
519 | 1.97M | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
520 | 1.97M | CXXRecordDecl *Recent = |
521 | 1.97M | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
522 | 3.11M | while (Recent->isInjectedClassName()) { |
523 | | // FIXME: Does injected class name need to be in the redeclarations chain? |
524 | 1.13M | assert(Recent->getPreviousDecl()); |
525 | 1.13M | Recent = Recent->getPreviousDecl(); |
526 | 1.13M | } |
527 | 1.97M | return Recent; |
528 | 1.97M | } |
529 | | |
530 | 4.15k | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
531 | 4.15k | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
532 | 4.15k | } |
533 | | |
534 | 81.9M | CXXRecordDecl *getDefinition() const { |
535 | | // We only need an update if we don't already know which |
536 | | // declaration is the definition. |
537 | 81.1M | auto *DD = DefinitionData ? DefinitionData : dataPtr()817k ; |
538 | 81.1M | return DD ? DD->Definition : nullptr817k ; |
539 | 81.9M | } |
540 | | |
541 | 4.63M | bool hasDefinition() const { return DefinitionData || dataPtr()192k ; } |
542 | | |
543 | | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
544 | | SourceLocation StartLoc, SourceLocation IdLoc, |
545 | | IdentifierInfo *Id, |
546 | | CXXRecordDecl *PrevDecl = nullptr, |
547 | | bool DelayTypeCreation = false); |
548 | | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
549 | | TypeSourceInfo *Info, SourceLocation Loc, |
550 | | bool DependentLambda, bool IsGeneric, |
551 | | LambdaCaptureDefault CaptureDefault); |
552 | | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
553 | | |
554 | 4.34M | bool isDynamicClass() const { |
555 | 4.34M | return data().Polymorphic || data().NumVBases != 04.18M ; |
556 | 4.34M | } |
557 | | |
558 | | /// @returns true if class is dynamic or might be dynamic because the |
559 | | /// definition is incomplete of dependent. |
560 | 26 | bool mayBeDynamicClass() const { |
561 | 26 | return !hasDefinition() || isDynamicClass()16 || hasAnyDependentBases()3 ; |
562 | 26 | } |
563 | | |
564 | | /// @returns true if class is non dynamic or might be non dynamic because the |
565 | | /// definition is incomplete of dependent. |
566 | 13 | bool mayBeNonDynamicClass() const { |
567 | 13 | return !hasDefinition() || !isDynamicClass()5 || hasAnyDependentBases()3 ; |
568 | 13 | } |
569 | | |
570 | 194k | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
571 | | |
572 | 1.76k | bool isParsingBaseSpecifiers() const { |
573 | 1.76k | return data().IsParsingBaseSpecifiers; |
574 | 1.76k | } |
575 | | |
576 | | unsigned getODRHash() const; |
577 | | |
578 | | /// Sets the base classes of this struct or class. |
579 | | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
580 | | |
581 | | /// Retrieves the number of base classes of this class. |
582 | 922k | unsigned getNumBases() const { return data().NumBases; } |
583 | | |
584 | | using base_class_range = llvm::iterator_range<base_class_iterator>; |
585 | | using base_class_const_range = |
586 | | llvm::iterator_range<base_class_const_iterator>; |
587 | | |
588 | 2.71M | base_class_range bases() { |
589 | 2.71M | return base_class_range(bases_begin(), bases_end()); |
590 | 2.71M | } |
591 | 13.8M | base_class_const_range bases() const { |
592 | 13.8M | return base_class_const_range(bases_begin(), bases_end()); |
593 | 13.8M | } |
594 | | |
595 | 6.15M | base_class_iterator bases_begin() { return data().getBases(); } |
596 | 34.0M | base_class_const_iterator bases_begin() const { return data().getBases(); } |
597 | 2.96M | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
598 | 17.0M | base_class_const_iterator bases_end() const { |
599 | 17.0M | return bases_begin() + data().NumBases; |
600 | 17.0M | } |
601 | | |
602 | | /// Retrieves the number of virtual base classes of this class. |
603 | 2.95M | unsigned getNumVBases() const { return data().NumVBases; } |
604 | | |
605 | 1.12M | base_class_range vbases() { |
606 | 1.12M | return base_class_range(vbases_begin(), vbases_end()); |
607 | 1.12M | } |
608 | 365k | base_class_const_range vbases() const { |
609 | 365k | return base_class_const_range(vbases_begin(), vbases_end()); |
610 | 365k | } |
611 | | |
612 | 2.24M | base_class_iterator vbases_begin() { return data().getVBases(); } |
613 | 747k | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
614 | 1.12M | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
615 | 373k | base_class_const_iterator vbases_end() const { |
616 | 373k | return vbases_begin() + data().NumVBases; |
617 | 373k | } |
618 | | |
619 | | /// Determine whether this class has any dependent base classes which |
620 | | /// are not the current instantiation. |
621 | | bool hasAnyDependentBases() const; |
622 | | |
623 | | /// Iterator access to method members. The method iterator visits |
624 | | /// all method members of the class, including non-instance methods, |
625 | | /// special methods, etc. |
626 | | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
627 | | using method_range = |
628 | | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
629 | | |
630 | 2.49M | method_range methods() const { |
631 | 2.49M | return method_range(method_begin(), method_end()); |
632 | 2.49M | } |
633 | | |
634 | | /// Method begin iterator. Iterates in the order the methods |
635 | | /// were declared. |
636 | 2.49M | method_iterator method_begin() const { |
637 | 2.49M | return method_iterator(decls_begin()); |
638 | 2.49M | } |
639 | | |
640 | | /// Method past-the-end iterator. |
641 | 2.49M | method_iterator method_end() const { |
642 | 2.49M | return method_iterator(decls_end()); |
643 | 2.49M | } |
644 | | |
645 | | /// Iterator access to constructor members. |
646 | | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
647 | | using ctor_range = |
648 | | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
649 | | |
650 | 5.78k | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
651 | | |
652 | 5.78k | ctor_iterator ctor_begin() const { |
653 | 5.78k | return ctor_iterator(decls_begin()); |
654 | 5.78k | } |
655 | | |
656 | 5.78k | ctor_iterator ctor_end() const { |
657 | 5.78k | return ctor_iterator(decls_end()); |
658 | 5.78k | } |
659 | | |
660 | | /// An iterator over friend declarations. All of these are defined |
661 | | /// in DeclFriend.h. |
662 | | class friend_iterator; |
663 | | using friend_range = llvm::iterator_range<friend_iterator>; |
664 | | |
665 | | friend_range friends() const; |
666 | | friend_iterator friend_begin() const; |
667 | | friend_iterator friend_end() const; |
668 | | void pushFriendDecl(FriendDecl *FD); |
669 | | |
670 | | /// Determines whether this record has any friends. |
671 | 29 | bool hasFriends() const { |
672 | 29 | return data().FirstFriend.isValid(); |
673 | 29 | } |
674 | | |
675 | | /// \c true if a defaulted copy constructor for this class would be |
676 | | /// deleted. |
677 | 974k | bool defaultedCopyConstructorIsDeleted() const { |
678 | 974k | assert((!needsOverloadResolutionForCopyConstructor() || |
679 | 974k | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && |
680 | 974k | "this property has not yet been computed by Sema"); |
681 | 974k | return data().DefaultedCopyConstructorIsDeleted; |
682 | 974k | } |
683 | | |
684 | | /// \c true if a defaulted move constructor for this class would be |
685 | | /// deleted. |
686 | 945k | bool defaultedMoveConstructorIsDeleted() const { |
687 | 945k | assert((!needsOverloadResolutionForMoveConstructor() || |
688 | 945k | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && |
689 | 945k | "this property has not yet been computed by Sema"); |
690 | 945k | return data().DefaultedMoveConstructorIsDeleted; |
691 | 945k | } |
692 | | |
693 | | /// \c true if a defaulted destructor for this class would be deleted. |
694 | 970k | bool defaultedDestructorIsDeleted() const { |
695 | 970k | assert((!needsOverloadResolutionForDestructor() || |
696 | 970k | (data().DeclaredSpecialMembers & SMF_Destructor)) && |
697 | 970k | "this property has not yet been computed by Sema"); |
698 | 970k | return data().DefaultedDestructorIsDeleted; |
699 | 970k | } |
700 | | |
701 | | /// \c true if we know for sure that this class has a single, |
702 | | /// accessible, unambiguous copy constructor that is not deleted. |
703 | 706k | bool hasSimpleCopyConstructor() const { |
704 | 706k | return !hasUserDeclaredCopyConstructor() && |
705 | 686k | !data().DefaultedCopyConstructorIsDeleted; |
706 | 706k | } |
707 | | |
708 | | /// \c true if we know for sure that this class has a single, |
709 | | /// accessible, unambiguous move constructor that is not deleted. |
710 | 706k | bool hasSimpleMoveConstructor() const { |
711 | 706k | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor()698k && |
712 | 671k | !data().DefaultedMoveConstructorIsDeleted; |
713 | 706k | } |
714 | | |
715 | | /// \c true if we know for sure that this class has a single, |
716 | | /// accessible, unambiguous copy assignment operator that is not deleted. |
717 | 706k | bool hasSimpleCopyAssignment() const { |
718 | 706k | return !hasUserDeclaredCopyAssignment() && |
719 | 690k | !data().DefaultedCopyAssignmentIsDeleted; |
720 | 706k | } |
721 | | |
722 | | /// \c true if we know for sure that this class has a single, |
723 | | /// accessible, unambiguous move assignment operator that is not deleted. |
724 | 706k | bool hasSimpleMoveAssignment() const { |
725 | 706k | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment()699k && |
726 | 671k | !data().DefaultedMoveAssignmentIsDeleted; |
727 | 706k | } |
728 | | |
729 | | /// \c true if we know for sure that this class has an accessible |
730 | | /// destructor that is not deleted. |
731 | 706k | bool hasSimpleDestructor() const { |
732 | 706k | return !hasUserDeclaredDestructor() && |
733 | 675k | !data().DefaultedDestructorIsDeleted; |
734 | 706k | } |
735 | | |
736 | | /// Determine whether this class has any default constructors. |
737 | 962k | bool hasDefaultConstructor() const { |
738 | 962k | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
739 | 693k | needsImplicitDefaultConstructor(); |
740 | 962k | } |
741 | | |
742 | | /// Determine if we need to declare a default constructor for |
743 | | /// this class. |
744 | | /// |
745 | | /// This value is used for lazy creation of default constructors. |
746 | 3.25M | bool needsImplicitDefaultConstructor() const { |
747 | 3.25M | return (!data().UserDeclaredConstructor && |
748 | 2.66M | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
749 | 2.55M | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()16.5k )) || |
750 | | // FIXME: Proposed fix to core wording issue: if a class inherits |
751 | | // a default constructor and doesn't explicitly declare one, one |
752 | | // is declared implicitly. |
753 | 712k | (data().HasInheritedDefaultConstructor && |
754 | 736 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor)); |
755 | 3.25M | } |
756 | | |
757 | | /// Determine whether this class has any user-declared constructors. |
758 | | /// |
759 | | /// When true, a default constructor will not be implicitly declared. |
760 | 1.15M | bool hasUserDeclaredConstructor() const { |
761 | 1.15M | return data().UserDeclaredConstructor; |
762 | 1.15M | } |
763 | | |
764 | | /// Whether this class has a user-provided default constructor |
765 | | /// per C++11. |
766 | 1.35k | bool hasUserProvidedDefaultConstructor() const { |
767 | 1.35k | return data().UserProvidedDefaultConstructor; |
768 | 1.35k | } |
769 | | |
770 | | /// Determine whether this class has a user-declared copy constructor. |
771 | | /// |
772 | | /// When false, a copy constructor will be implicitly declared. |
773 | 8.54M | bool hasUserDeclaredCopyConstructor() const { |
774 | 8.54M | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
775 | 8.54M | } |
776 | | |
777 | | /// Determine whether this class needs an implicit copy |
778 | | /// constructor to be lazily declared. |
779 | 3.24M | bool needsImplicitCopyConstructor() const { |
780 | 3.24M | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
781 | 3.24M | } |
782 | | |
783 | | /// Determine whether we need to eagerly declare a defaulted copy |
784 | | /// constructor for this class. |
785 | 2.20M | bool needsOverloadResolutionForCopyConstructor() const { |
786 | | // C++17 [class.copy.ctor]p6: |
787 | | // If the class definition declares a move constructor or move assignment |
788 | | // operator, the implicitly declared copy constructor is defined as |
789 | | // deleted. |
790 | | // In MSVC mode, sometimes a declared move assignment does not delete an |
791 | | // implicit copy constructor, so defer this choice to Sema. |
792 | 2.20M | if (data().UserDeclaredSpecialMembers & |
793 | 2.20M | (SMF_MoveConstructor | SMF_MoveAssignment)) |
794 | 9.83k | return true; |
795 | 2.19M | return data().NeedOverloadResolutionForCopyConstructor; |
796 | 2.19M | } |
797 | | |
798 | | /// Determine whether an implicit copy constructor for this type |
799 | | /// would have a parameter with a const-qualified reference type. |
800 | 641k | bool implicitCopyConstructorHasConstParam() const { |
801 | 641k | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
802 | 641k | (isAbstract() || |
803 | 640k | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
804 | 641k | } |
805 | | |
806 | | /// Determine whether this class has a copy constructor with |
807 | | /// a parameter type which is a reference to a const-qualified type. |
808 | 704k | bool hasCopyConstructorWithConstParam() const { |
809 | 704k | return data().HasDeclaredCopyConstructorWithConstParam || |
810 | 525k | (needsImplicitCopyConstructor() && |
811 | 525k | implicitCopyConstructorHasConstParam()); |
812 | 704k | } |
813 | | |
814 | | /// Whether this class has a user-declared move constructor or |
815 | | /// assignment operator. |
816 | | /// |
817 | | /// When false, a move constructor and assignment operator may be |
818 | | /// implicitly declared. |
819 | 0 | bool hasUserDeclaredMoveOperation() const { |
820 | 0 | return data().UserDeclaredSpecialMembers & |
821 | 0 | (SMF_MoveConstructor | SMF_MoveAssignment); |
822 | 0 | } |
823 | | |
824 | | /// Determine whether this class has had a move constructor |
825 | | /// declared by the user. |
826 | 3.44M | bool hasUserDeclaredMoveConstructor() const { |
827 | 3.44M | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
828 | 3.44M | } |
829 | | |
830 | | /// Determine whether this class has a move constructor. |
831 | 3.20M | bool hasMoveConstructor() const { |
832 | 3.20M | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
833 | 2.74M | needsImplicitMoveConstructor(); |
834 | 3.20M | } |
835 | | |
836 | | /// Set that we attempted to declare an implicit copy |
837 | | /// constructor, but overload resolution failed so we deleted it. |
838 | 9.48k | void setImplicitCopyConstructorIsDeleted() { |
839 | 9.48k | assert((data().DefaultedCopyConstructorIsDeleted || |
840 | 9.48k | needsOverloadResolutionForCopyConstructor()) && |
841 | 9.48k | "Copy constructor should not be deleted"); |
842 | 9.48k | data().DefaultedCopyConstructorIsDeleted = true; |
843 | 9.48k | } |
844 | | |
845 | | /// Set that we attempted to declare an implicit move |
846 | | /// constructor, but overload resolution failed so we deleted it. |
847 | 1.82k | void setImplicitMoveConstructorIsDeleted() { |
848 | 1.82k | assert((data().DefaultedMoveConstructorIsDeleted || |
849 | 1.82k | needsOverloadResolutionForMoveConstructor()) && |
850 | 1.82k | "move constructor should not be deleted"); |
851 | 1.82k | data().DefaultedMoveConstructorIsDeleted = true; |
852 | 1.82k | } |
853 | | |
854 | | /// Set that we attempted to declare an implicit destructor, |
855 | | /// but overload resolution failed so we deleted it. |
856 | 786 | void setImplicitDestructorIsDeleted() { |
857 | 786 | assert((data().DefaultedDestructorIsDeleted || |
858 | 786 | needsOverloadResolutionForDestructor()) && |
859 | 786 | "destructor should not be deleted"); |
860 | 786 | data().DefaultedDestructorIsDeleted = true; |
861 | 786 | } |
862 | | |
863 | | /// Determine whether this class should get an implicit move |
864 | | /// constructor or if any existing special member function inhibits this. |
865 | 5.58M | bool needsImplicitMoveConstructor() const { |
866 | 5.58M | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
867 | 5.18M | !hasUserDeclaredCopyConstructor() && |
868 | 4.99M | !hasUserDeclaredCopyAssignment() && |
869 | 4.98M | !hasUserDeclaredMoveAssignment() && |
870 | 4.98M | !hasUserDeclaredDestructor(); |
871 | 5.58M | } |
872 | | |
873 | | /// Determine whether we need to eagerly declare a defaulted move |
874 | | /// constructor for this class. |
875 | 2.10M | bool needsOverloadResolutionForMoveConstructor() const { |
876 | 2.10M | return data().NeedOverloadResolutionForMoveConstructor; |
877 | 2.10M | } |
878 | | |
879 | | /// Determine whether this class has a user-declared copy assignment |
880 | | /// operator. |
881 | | /// |
882 | | /// When false, a copy assignment operator will be implicitly declared. |
883 | 8.28M | bool hasUserDeclaredCopyAssignment() const { |
884 | 8.28M | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
885 | 8.28M | } |
886 | | |
887 | | /// Set that we attempted to declare an implicit copy assignment |
888 | | /// operator, but overload resolution failed so we deleted it. |
889 | 11.1k | void setImplicitCopyAssignmentIsDeleted() { |
890 | 11.1k | assert((data().DefaultedCopyAssignmentIsDeleted || |
891 | 11.1k | needsOverloadResolutionForCopyAssignment()) && |
892 | 11.1k | "copy assignment should not be deleted"); |
893 | 11.1k | data().DefaultedCopyAssignmentIsDeleted = true; |
894 | 11.1k | } |
895 | | |
896 | | /// Determine whether this class needs an implicit copy |
897 | | /// assignment operator to be lazily declared. |
898 | 1.81M | bool needsImplicitCopyAssignment() const { |
899 | 1.81M | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
900 | 1.81M | } |
901 | | |
902 | | /// Determine whether we need to eagerly declare a defaulted copy |
903 | | /// assignment operator for this class. |
904 | 1.05M | bool needsOverloadResolutionForCopyAssignment() const { |
905 | | // C++20 [class.copy.assign]p2: |
906 | | // If the class definition declares a move constructor or move assignment |
907 | | // operator, the implicitly declared copy assignment operator is defined |
908 | | // as deleted. |
909 | | // In MSVC mode, sometimes a declared move constructor does not delete an |
910 | | // implicit copy assignment, so defer this choice to Sema. |
911 | 1.05M | if (data().UserDeclaredSpecialMembers & |
912 | 1.05M | (SMF_MoveConstructor | SMF_MoveAssignment)) |
913 | 8.51k | return true; |
914 | 1.04M | return data().NeedOverloadResolutionForCopyAssignment; |
915 | 1.04M | } |
916 | | |
917 | | /// Determine whether an implicit copy assignment operator for this |
918 | | /// type would have a parameter with a const-qualified reference type. |
919 | 709k | bool implicitCopyAssignmentHasConstParam() const { |
920 | 709k | return data().ImplicitCopyAssignmentHasConstParam; |
921 | 709k | } |
922 | | |
923 | | /// Determine whether this class has a copy assignment operator with |
924 | | /// a parameter type which is a reference to a const-qualified type or is not |
925 | | /// a reference. |
926 | 701k | bool hasCopyAssignmentWithConstParam() const { |
927 | 701k | return data().HasDeclaredCopyAssignmentWithConstParam || |
928 | 660k | (needsImplicitCopyAssignment() && |
929 | 660k | implicitCopyAssignmentHasConstParam()); |
930 | 701k | } |
931 | | |
932 | | /// Determine whether this class has had a move assignment |
933 | | /// declared by the user. |
934 | 5.85M | bool hasUserDeclaredMoveAssignment() const { |
935 | 5.85M | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
936 | 5.85M | } |
937 | | |
938 | | /// Determine whether this class has a move assignment operator. |
939 | 1.42M | bool hasMoveAssignment() const { |
940 | 1.42M | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
941 | 1.39M | needsImplicitMoveAssignment(); |
942 | 1.42M | } |
943 | | |
944 | | /// Set that we attempted to declare an implicit move assignment |
945 | | /// operator, but overload resolution failed so we deleted it. |
946 | 2.87k | void setImplicitMoveAssignmentIsDeleted() { |
947 | 2.87k | assert((data().DefaultedMoveAssignmentIsDeleted || |
948 | 2.87k | needsOverloadResolutionForMoveAssignment()) && |
949 | 2.87k | "move assignment should not be deleted"); |
950 | 2.87k | data().DefaultedMoveAssignmentIsDeleted = true; |
951 | 2.87k | } |
952 | | |
953 | | /// Determine whether this class should get an implicit move |
954 | | /// assignment operator or if any existing special member function inhibits |
955 | | /// this. |
956 | 2.68M | bool needsImplicitMoveAssignment() const { |
957 | 2.68M | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
958 | 2.64M | !hasUserDeclaredCopyConstructor() && |
959 | 2.57M | !hasUserDeclaredCopyAssignment() && |
960 | 2.57M | !hasUserDeclaredMoveConstructor() && |
961 | 2.57M | !hasUserDeclaredDestructor() && |
962 | 2.51M | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()12.3k ); |
963 | 2.68M | } |
964 | | |
965 | | /// Determine whether we need to eagerly declare a move assignment |
966 | | /// operator for this class. |
967 | 1.00M | bool needsOverloadResolutionForMoveAssignment() const { |
968 | 1.00M | return data().NeedOverloadResolutionForMoveAssignment; |
969 | 1.00M | } |
970 | | |
971 | | /// Determine whether this class has a user-declared destructor. |
972 | | /// |
973 | | /// When false, a destructor will be implicitly declared. |
974 | 8.27M | bool hasUserDeclaredDestructor() const { |
975 | 8.27M | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
976 | 8.27M | } |
977 | | |
978 | | /// Determine whether this class needs an implicit destructor to |
979 | | /// be lazily declared. |
980 | 2.33M | bool needsImplicitDestructor() const { |
981 | 2.33M | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
982 | 2.33M | } |
983 | | |
984 | | /// Determine whether we need to eagerly declare a destructor for this |
985 | | /// class. |
986 | 1.96M | bool needsOverloadResolutionForDestructor() const { |
987 | 1.96M | return data().NeedOverloadResolutionForDestructor; |
988 | 1.96M | } |
989 | | |
990 | | /// Determine whether this class describes a lambda function object. |
991 | 77.4M | bool isLambda() const { |
992 | | // An update record can't turn a non-lambda into a lambda. |
993 | 77.4M | auto *DD = DefinitionData; |
994 | 77.4M | return DD && DD->IsLambda72.5M ; |
995 | 77.4M | } |
996 | | |
997 | | /// Determine whether this class describes a generic |
998 | | /// lambda function object (i.e. function call operator is |
999 | | /// a template). |
1000 | | bool isGenericLambda() const; |
1001 | | |
1002 | | /// Determine whether this lambda should have an implicit default constructor |
1003 | | /// and copy and move assignment operators. |
1004 | | bool lambdaIsDefaultConstructibleAndAssignable() const; |
1005 | | |
1006 | | /// Retrieve the lambda call operator of the closure type |
1007 | | /// if this is a closure type. |
1008 | | CXXMethodDecl *getLambdaCallOperator() const; |
1009 | | |
1010 | | /// Retrieve the dependent lambda call operator of the closure type |
1011 | | /// if this is a templated closure type. |
1012 | | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
1013 | | |
1014 | | /// Retrieve the lambda static invoker, the address of which |
1015 | | /// is returned by the conversion operator, and the body of which |
1016 | | /// is forwarded to the lambda call operator. The version that does not |
1017 | | /// take a calling convention uses the 'default' calling convention for free |
1018 | | /// functions if the Lambda's calling convention was not modified via |
1019 | | /// attribute. Otherwise, it will return the calling convention specified for |
1020 | | /// the lambda. |
1021 | | CXXMethodDecl *getLambdaStaticInvoker() const; |
1022 | | CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const; |
1023 | | |
1024 | | /// Retrieve the generic lambda's template parameter list. |
1025 | | /// Returns null if the class does not represent a lambda or a generic |
1026 | | /// lambda. |
1027 | | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
1028 | | |
1029 | | /// Retrieve the lambda template parameters that were specified explicitly. |
1030 | | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
1031 | | |
1032 | 65.2k | LambdaCaptureDefault getLambdaCaptureDefault() const { |
1033 | 65.2k | assert(isLambda()); |
1034 | 65.2k | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
1035 | 65.2k | } |
1036 | | |
1037 | | /// Set the captures for this lambda closure type. |
1038 | | void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures); |
1039 | | |
1040 | | /// For a closure type, retrieve the mapping from captured |
1041 | | /// variables and \c this to the non-static data members that store the |
1042 | | /// values or references of the captures. |
1043 | | /// |
1044 | | /// \param Captures Will be populated with the mapping from captured |
1045 | | /// variables to the corresponding fields. |
1046 | | /// |
1047 | | /// \param ThisCapture Will be set to the field declaration for the |
1048 | | /// \c this capture. |
1049 | | /// |
1050 | | /// \note No entries will be added for init-captures, as they do not capture |
1051 | | /// variables. |
1052 | | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1053 | | FieldDecl *&ThisCapture) const; |
1054 | | |
1055 | | using capture_const_iterator = const LambdaCapture *; |
1056 | | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
1057 | | |
1058 | 2.87k | capture_const_range captures() const { |
1059 | 2.87k | return capture_const_range(captures_begin(), captures_end()); |
1060 | 2.87k | } |
1061 | | |
1062 | 6.78k | capture_const_iterator captures_begin() const { |
1063 | 6.78k | return isLambda() ? getLambdaData().Captures : nullptr0 ; |
1064 | 6.78k | } |
1065 | | |
1066 | 2.98k | capture_const_iterator captures_end() const { |
1067 | 2.98k | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
1068 | 0 | : nullptr; |
1069 | 2.98k | } |
1070 | | |
1071 | 45.9k | unsigned capture_size() const { return getLambdaData().NumCaptures; } |
1072 | | |
1073 | | using conversion_iterator = UnresolvedSetIterator; |
1074 | | |
1075 | 3.48M | conversion_iterator conversion_begin() const { |
1076 | 3.48M | return data().Conversions.get(getASTContext()).begin(); |
1077 | 3.48M | } |
1078 | | |
1079 | 3.48M | conversion_iterator conversion_end() const { |
1080 | 3.48M | return data().Conversions.get(getASTContext()).end(); |
1081 | 3.48M | } |
1082 | | |
1083 | | /// Removes a conversion function from this class. The conversion |
1084 | | /// function must currently be a member of this class. Furthermore, |
1085 | | /// this class must currently be in the process of being defined. |
1086 | | void removeConversion(const NamedDecl *Old); |
1087 | | |
1088 | | /// Get all conversion functions visible in current class, |
1089 | | /// including conversion function templates. |
1090 | | llvm::iterator_range<conversion_iterator> |
1091 | | getVisibleConversionFunctions() const; |
1092 | | |
1093 | | /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]), |
1094 | | /// which is a class with no user-declared constructors, no private |
1095 | | /// or protected non-static data members, no base classes, and no virtual |
1096 | | /// functions (C++ [dcl.init.aggr]p1). |
1097 | 1.84M | bool isAggregate() const { return data().Aggregate; } |
1098 | | |
1099 | | /// Whether this class has any in-class initializers |
1100 | | /// for non-static data members (including those in anonymous unions or |
1101 | | /// structs). |
1102 | 18.2k | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
1103 | | |
1104 | | /// Whether this class or any of its subobjects has any members of |
1105 | | /// reference type which would make value-initialization ill-formed. |
1106 | | /// |
1107 | | /// Per C++03 [dcl.init]p5: |
1108 | | /// - if T is a non-union class type without a user-declared constructor, |
1109 | | /// then every non-static data member and base-class component of T is |
1110 | | /// value-initialized [...] A program that calls for [...] |
1111 | | /// value-initialization of an entity of reference type is ill-formed. |
1112 | 701k | bool hasUninitializedReferenceMember() const { |
1113 | 701k | return !isUnion() && !hasUserDeclaredConstructor()691k && |
1114 | 627k | data().HasUninitializedReferenceMember; |
1115 | 701k | } |
1116 | | |
1117 | | /// Whether this class is a POD-type (C++ [class]p4) |
1118 | | /// |
1119 | | /// For purposes of this function a class is POD if it is an aggregate |
1120 | | /// that has no non-static non-POD data members, no reference data |
1121 | | /// members, no user-defined copy assignment operator and no |
1122 | | /// user-defined destructor. |
1123 | | /// |
1124 | | /// Note that this is the C++ TR1 definition of POD. |
1125 | 611k | bool isPOD() const { return data().PlainOldData; } |
1126 | | |
1127 | | /// True if this class is C-like, without C++-specific features, e.g. |
1128 | | /// it contains only public fields, no bases, tag kind is not 'class', etc. |
1129 | | bool isCLike() const; |
1130 | | |
1131 | | /// Determine whether this is an empty class in the sense of |
1132 | | /// (C++11 [meta.unary.prop]). |
1133 | | /// |
1134 | | /// The CXXRecordDecl is a class type, but not a union type, |
1135 | | /// with no non-static data members other than bit-fields of length 0, |
1136 | | /// no virtual member functions, no virtual base classes, |
1137 | | /// and no base class B for which is_empty<B>::value is false. |
1138 | | /// |
1139 | | /// \note This does NOT include a check for union-ness. |
1140 | 2.88M | bool isEmpty() const { return data().Empty; } |
1141 | | |
1142 | 99 | bool hasPrivateFields() const { |
1143 | 99 | return data().HasPrivateFields; |
1144 | 99 | } |
1145 | | |
1146 | 99 | bool hasProtectedFields() const { |
1147 | 99 | return data().HasProtectedFields; |
1148 | 99 | } |
1149 | | |
1150 | | /// Determine whether this class has direct non-static data members. |
1151 | 370k | bool hasDirectFields() const { |
1152 | 370k | auto &D = data(); |
1153 | 370k | return D.HasPublicFields || D.HasProtectedFields366k || D.HasPrivateFields363k ; |
1154 | 370k | } |
1155 | | |
1156 | | /// Whether this class is polymorphic (C++ [class.virtual]), |
1157 | | /// which means that the class contains or inherits a virtual function. |
1158 | 1.93M | bool isPolymorphic() const { return data().Polymorphic; } |
1159 | | |
1160 | | /// Determine whether this class has a pure virtual function. |
1161 | | /// |
1162 | | /// The class is is abstract per (C++ [class.abstract]p2) if it declares |
1163 | | /// a pure virtual function or inherits a pure virtual function that is |
1164 | | /// not overridden. |
1165 | 4.94M | bool isAbstract() const { return data().Abstract; } |
1166 | | |
1167 | | /// Determine whether this class is standard-layout per |
1168 | | /// C++ [class]p7. |
1169 | 731k | bool isStandardLayout() const { return data().IsStandardLayout; } |
1170 | | |
1171 | | /// Determine whether this class was standard-layout per |
1172 | | /// C++11 [class]p7, specifically using the C++11 rules without any DRs. |
1173 | 700k | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
1174 | | |
1175 | | /// Determine whether this class, or any of its class subobjects, |
1176 | | /// contains a mutable field. |
1177 | 737k | bool hasMutableFields() const { return data().HasMutableFields; } |
1178 | | |
1179 | | /// Determine whether this class has any variant members. |
1180 | 333k | bool hasVariantMembers() const { return data().HasVariantMembers; } |
1181 | | |
1182 | | /// Determine whether this class has a trivial default constructor |
1183 | | /// (C++11 [class.ctor]p5). |
1184 | 960k | bool hasTrivialDefaultConstructor() const { |
1185 | 960k | return hasDefaultConstructor() && |
1186 | 929k | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
1187 | 960k | } |
1188 | | |
1189 | | /// Determine whether this class has a non-trivial default constructor |
1190 | | /// (C++11 [class.ctor]p5). |
1191 | 1.71k | bool hasNonTrivialDefaultConstructor() const { |
1192 | 1.71k | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
1193 | 1.53k | (needsImplicitDefaultConstructor() && |
1194 | 987 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
1195 | 1.71k | } |
1196 | | |
1197 | | /// Determine whether this class has at least one constexpr constructor |
1198 | | /// other than the copy or move constructors. |
1199 | 112k | bool hasConstexprNonCopyMoveConstructor() const { |
1200 | 112k | return data().HasConstexprNonCopyMoveConstructor || |
1201 | 72.7k | (needsImplicitDefaultConstructor() && |
1202 | 42.2k | defaultedDefaultConstructorIsConstexpr()); |
1203 | 112k | } |
1204 | | |
1205 | | /// Determine whether a defaulted default constructor for this class |
1206 | | /// would be constexpr. |
1207 | 601k | bool defaultedDefaultConstructorIsConstexpr() const { |
1208 | 601k | return data().DefaultedDefaultConstructorIsConstexpr && |
1209 | 292k | (!isUnion() || hasInClassInitializer()12.6k || !hasVariantMembers()12.4k || |
1210 | 12.3k | getLangOpts().CPlusPlus20); |
1211 | 601k | } |
1212 | | |
1213 | | /// Determine whether this class has a constexpr default constructor. |
1214 | 698k | bool hasConstexprDefaultConstructor() const { |
1215 | 698k | return data().HasConstexprDefaultConstructor || |
1216 | 548k | (needsImplicitDefaultConstructor() && |
1217 | 494k | defaultedDefaultConstructorIsConstexpr()); |
1218 | 698k | } |
1219 | | |
1220 | | /// Determine whether this class has a trivial copy constructor |
1221 | | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1222 | 1.07M | bool hasTrivialCopyConstructor() const { |
1223 | 1.07M | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
1224 | 1.07M | } |
1225 | | |
1226 | 1.77M | bool hasTrivialCopyConstructorForCall() const { |
1227 | 1.77M | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
1228 | 1.77M | } |
1229 | | |
1230 | | /// Determine whether this class has a non-trivial copy constructor |
1231 | | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1232 | 279k | bool hasNonTrivialCopyConstructor() const { |
1233 | 279k | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
1234 | 226k | !hasTrivialCopyConstructor(); |
1235 | 279k | } |
1236 | | |
1237 | 321 | bool hasNonTrivialCopyConstructorForCall() const { |
1238 | 321 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1239 | 321 | SMF_CopyConstructor) || |
1240 | 307 | !hasTrivialCopyConstructorForCall(); |
1241 | 321 | } |
1242 | | |
1243 | | /// Determine whether this class has a trivial move constructor |
1244 | | /// (C++11 [class.copy]p12) |
1245 | 781k | bool hasTrivialMoveConstructor() const { |
1246 | 781k | return hasMoveConstructor() && |
1247 | 756k | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
1248 | 781k | } |
1249 | | |
1250 | 1.72M | bool hasTrivialMoveConstructorForCall() const { |
1251 | 1.72M | return hasMoveConstructor() && |
1252 | 1.69M | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
1253 | 1.72M | } |
1254 | | |
1255 | | /// Determine whether this class has a non-trivial move constructor |
1256 | | /// (C++11 [class.copy]p12) |
1257 | 194k | bool hasNonTrivialMoveConstructor() const { |
1258 | 194k | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
1259 | 188k | (needsImplicitMoveConstructor() && |
1260 | 122k | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
1261 | 194k | } |
1262 | | |
1263 | 0 | bool hasNonTrivialMoveConstructorForCall() const { |
1264 | 0 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1265 | 0 | SMF_MoveConstructor) || |
1266 | 0 | (needsImplicitMoveConstructor() && |
1267 | 0 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
1268 | 0 | } |
1269 | | |
1270 | | /// Determine whether this class has a trivial copy assignment operator |
1271 | | /// (C++ [class.copy]p11, C++11 [class.copy]p25) |
1272 | 968k | bool hasTrivialCopyAssignment() const { |
1273 | 968k | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
1274 | 968k | } |
1275 | | |
1276 | | /// Determine whether this class has a non-trivial copy assignment |
1277 | | /// operator (C++ [class.copy]p11, C++11 [class.copy]p25) |
1278 | 220k | bool hasNonTrivialCopyAssignment() const { |
1279 | 220k | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
1280 | 217k | !hasTrivialCopyAssignment(); |
1281 | 220k | } |
1282 | | |
1283 | | /// Determine whether this class has a trivial move assignment operator |
1284 | | /// (C++11 [class.copy]p25) |
1285 | 719k | bool hasTrivialMoveAssignment() const { |
1286 | 719k | return hasMoveAssignment() && |
1287 | 693k | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
1288 | 719k | } |
1289 | | |
1290 | | /// Determine whether this class has a non-trivial move assignment |
1291 | | /// operator (C++11 [class.copy]p25) |
1292 | 185k | bool hasNonTrivialMoveAssignment() const { |
1293 | 185k | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
1294 | 184k | (needsImplicitMoveAssignment() && |
1295 | 160k | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
1296 | 185k | } |
1297 | | |
1298 | | /// Determine whether a defaulted default constructor for this class |
1299 | | /// would be constexpr. |
1300 | 608k | bool defaultedDestructorIsConstexpr() const { |
1301 | 608k | return data().DefaultedDestructorIsConstexpr && |
1302 | 497k | getLangOpts().CPlusPlus20; |
1303 | 608k | } |
1304 | | |
1305 | | /// Determine whether this class has a constexpr destructor. |
1306 | | bool hasConstexprDestructor() const; |
1307 | | |
1308 | | /// Determine whether this class has a trivial destructor |
1309 | | /// (C++ [class.dtor]p3) |
1310 | 2.18M | bool hasTrivialDestructor() const { |
1311 | 2.18M | return data().HasTrivialSpecialMembers & SMF_Destructor; |
1312 | 2.18M | } |
1313 | | |
1314 | 1.75M | bool hasTrivialDestructorForCall() const { |
1315 | 1.75M | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
1316 | 1.75M | } |
1317 | | |
1318 | | /// Determine whether this class has a non-trivial destructor |
1319 | | /// (C++ [class.dtor]p3) |
1320 | 1.43M | bool hasNonTrivialDestructor() const { |
1321 | 1.43M | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
1322 | 1.43M | } |
1323 | | |
1324 | 333 | bool hasNonTrivialDestructorForCall() const { |
1325 | 333 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
1326 | 333 | } |
1327 | | |
1328 | 7.34k | void setHasTrivialSpecialMemberForCall() { |
1329 | 7.34k | data().HasTrivialSpecialMembersForCall = |
1330 | 7.34k | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
1331 | 7.34k | } |
1332 | | |
1333 | | /// Determine whether declaring a const variable with this type is ok |
1334 | | /// per core issue 253. |
1335 | 703k | bool allowConstDefaultInit() const { |
1336 | 703k | return !data().HasUninitializedFields || |
1337 | 320k | !(data().HasDefaultedDefaultConstructor || |
1338 | 312k | needsImplicitDefaultConstructor()); |
1339 | 703k | } |
1340 | | |
1341 | | /// Determine whether this class has a destructor which has no |
1342 | | /// semantic effect. |
1343 | | /// |
1344 | | /// Any such destructor will be trivial, public, defaulted and not deleted, |
1345 | | /// and will call only irrelevant destructors. |
1346 | 956k | bool hasIrrelevantDestructor() const { |
1347 | 956k | return data().HasIrrelevantDestructor; |
1348 | 956k | } |
1349 | | |
1350 | | /// Determine whether this class has a non-literal or/ volatile type |
1351 | | /// non-static data member or base class. |
1352 | 1.12M | bool hasNonLiteralTypeFieldsOrBases() const { |
1353 | 1.12M | return data().HasNonLiteralTypeFieldsOrBases; |
1354 | 1.12M | } |
1355 | | |
1356 | | /// Determine whether this class has a using-declaration that names |
1357 | | /// a user-declared base class constructor. |
1358 | 2.90M | bool hasInheritedConstructor() const { |
1359 | 2.90M | return data().HasInheritedConstructor; |
1360 | 2.90M | } |
1361 | | |
1362 | | /// Determine whether this class has a using-declaration that names |
1363 | | /// a base class assignment operator. |
1364 | 1.94M | bool hasInheritedAssignment() const { |
1365 | 1.94M | return data().HasInheritedAssignment; |
1366 | 1.94M | } |
1367 | | |
1368 | | /// Determine whether this class is considered trivially copyable per |
1369 | | /// (C++11 [class]p6). |
1370 | | bool isTriviallyCopyable() const; |
1371 | | |
1372 | | /// Determine whether this class is considered trivial. |
1373 | | /// |
1374 | | /// C++11 [class]p6: |
1375 | | /// "A trivial class is a class that has a trivial default constructor and |
1376 | | /// is trivially copyable." |
1377 | 176k | bool isTrivial() const { |
1378 | 176k | return isTriviallyCopyable() && hasTrivialDefaultConstructor()133k ; |
1379 | 176k | } |
1380 | | |
1381 | | /// Determine whether this class is a literal type. |
1382 | | /// |
1383 | | /// C++11 [basic.types]p10: |
1384 | | /// A class type that has all the following properties: |
1385 | | /// - it has a trivial destructor |
1386 | | /// - every constructor call and full-expression in the |
1387 | | /// brace-or-equal-intializers for non-static data members (if any) is |
1388 | | /// a constant expression. |
1389 | | /// - it is an aggregate type or has at least one constexpr constructor |
1390 | | /// or constructor template that is not a copy or move constructor, and |
1391 | | /// - all of its non-static data members and base classes are of literal |
1392 | | /// types |
1393 | | /// |
1394 | | /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by |
1395 | | /// treating types with trivial default constructors as literal types. |
1396 | | /// |
1397 | | /// Only in C++17 and beyond, are lambdas literal types. |
1398 | 781k | bool isLiteral() const { |
1399 | 781k | const LangOptions &LangOpts = getLangOpts(); |
1400 | 781k | return (LangOpts.CPlusPlus20 ? hasConstexprDestructor()10.4k |
1401 | 771k | : hasTrivialDestructor()) && |
1402 | 741k | (!isLambda() || LangOpts.CPlusPlus171.52k ) && |
1403 | 741k | !hasNonLiteralTypeFieldsOrBases() && |
1404 | 731k | (isAggregate() || isLambda()112k || |
1405 | 111k | hasConstexprNonCopyMoveConstructor() || |
1406 | 32.9k | hasTrivialDefaultConstructor()); |
1407 | 781k | } |
1408 | | |
1409 | | /// Determine whether this is a structural type. |
1410 | 241 | bool isStructural() const { |
1411 | 241 | return isLiteral() && data().StructuralIfLiteral234 ; |
1412 | 241 | } |
1413 | | |
1414 | | /// If this record is an instantiation of a member class, |
1415 | | /// retrieves the member class from which it was instantiated. |
1416 | | /// |
1417 | | /// This routine will return non-null for (non-templated) member |
1418 | | /// classes of class templates. For example, given: |
1419 | | /// |
1420 | | /// \code |
1421 | | /// template<typename T> |
1422 | | /// struct X { |
1423 | | /// struct A { }; |
1424 | | /// }; |
1425 | | /// \endcode |
1426 | | /// |
1427 | | /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl |
1428 | | /// whose parent is the class template specialization X<int>. For |
1429 | | /// this declaration, getInstantiatedFromMemberClass() will return |
1430 | | /// the CXXRecordDecl X<T>::A. When a complete definition of |
1431 | | /// X<int>::A is required, it will be instantiated from the |
1432 | | /// declaration returned by getInstantiatedFromMemberClass(). |
1433 | | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
1434 | | |
1435 | | /// If this class is an instantiation of a member class of a |
1436 | | /// class template specialization, retrieves the member specialization |
1437 | | /// information. |
1438 | | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1439 | | |
1440 | | /// Specify that this record is an instantiation of the |
1441 | | /// member class \p RD. |
1442 | | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1443 | | TemplateSpecializationKind TSK); |
1444 | | |
1445 | | /// Retrieves the class template that is described by this |
1446 | | /// class declaration. |
1447 | | /// |
1448 | | /// Every class template is represented as a ClassTemplateDecl and a |
1449 | | /// CXXRecordDecl. The former contains template properties (such as |
1450 | | /// the template parameter lists) while the latter contains the |
1451 | | /// actual description of the template's |
1452 | | /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the |
1453 | | /// CXXRecordDecl that from a ClassTemplateDecl, while |
1454 | | /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from |
1455 | | /// a CXXRecordDecl. |
1456 | | ClassTemplateDecl *getDescribedClassTemplate() const; |
1457 | | |
1458 | | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
1459 | | |
1460 | | /// Determine whether this particular class is a specialization or |
1461 | | /// instantiation of a class template or member class of a class template, |
1462 | | /// and how it was instantiated or specialized. |
1463 | | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1464 | | |
1465 | | /// Set the kind of specialization or template instantiation this is. |
1466 | | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
1467 | | |
1468 | | /// Retrieve the record declaration from which this record could be |
1469 | | /// instantiated. Returns null if this class is not a template instantiation. |
1470 | | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
1471 | | |
1472 | 1.27M | CXXRecordDecl *getTemplateInstantiationPattern() { |
1473 | 1.27M | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
1474 | 1.27M | ->getTemplateInstantiationPattern()); |
1475 | 1.27M | } |
1476 | | |
1477 | | /// Returns the destructor decl for this class. |
1478 | | CXXDestructorDecl *getDestructor() const; |
1479 | | |
1480 | | /// Returns true if the class destructor, or any implicitly invoked |
1481 | | /// destructors are marked noreturn. |
1482 | | bool isAnyDestructorNoReturn() const; |
1483 | | |
1484 | | /// If the class is a local class [class.local], returns |
1485 | | /// the enclosing function declaration. |
1486 | 5.13M | const FunctionDecl *isLocalClass() const { |
1487 | 5.13M | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
1488 | 928k | return RD->isLocalClass(); |
1489 | | |
1490 | 4.21M | return dyn_cast<FunctionDecl>(getDeclContext()); |
1491 | 4.21M | } |
1492 | | |
1493 | 1.27M | FunctionDecl *isLocalClass() { |
1494 | 1.27M | return const_cast<FunctionDecl*>( |
1495 | 1.27M | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
1496 | 1.27M | } |
1497 | | |
1498 | | /// Determine whether this dependent class is a current instantiation, |
1499 | | /// when viewed from within the given context. |
1500 | | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
1501 | | |
1502 | | /// Determine whether this class is derived from the class \p Base. |
1503 | | /// |
1504 | | /// This routine only determines whether this class is derived from \p Base, |
1505 | | /// but does not account for factors that may make a Derived -> Base class |
1506 | | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1507 | | /// base class subobjects. |
1508 | | /// |
1509 | | /// \param Base the base class we are searching for. |
1510 | | /// |
1511 | | /// \returns true if this class is derived from Base, false otherwise. |
1512 | | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
1513 | | |
1514 | | /// Determine whether this class is derived from the type \p Base. |
1515 | | /// |
1516 | | /// This routine only determines whether this class is derived from \p Base, |
1517 | | /// but does not account for factors that may make a Derived -> Base class |
1518 | | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1519 | | /// base class subobjects. |
1520 | | /// |
1521 | | /// \param Base the base class we are searching for. |
1522 | | /// |
1523 | | /// \param Paths will contain the paths taken from the current class to the |
1524 | | /// given \p Base class. |
1525 | | /// |
1526 | | /// \returns true if this class is derived from \p Base, false otherwise. |
1527 | | /// |
1528 | | /// \todo add a separate parameter to configure IsDerivedFrom, rather than |
1529 | | /// tangling input and output in \p Paths |
1530 | | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
1531 | | |
1532 | | /// Determine whether this class is virtually derived from |
1533 | | /// the class \p Base. |
1534 | | /// |
1535 | | /// This routine only determines whether this class is virtually |
1536 | | /// derived from \p Base, but does not account for factors that may |
1537 | | /// make a Derived -> Base class ill-formed, such as |
1538 | | /// private/protected inheritance or multiple, ambiguous base class |
1539 | | /// subobjects. |
1540 | | /// |
1541 | | /// \param Base the base class we are searching for. |
1542 | | /// |
1543 | | /// \returns true if this class is virtually derived from Base, |
1544 | | /// false otherwise. |
1545 | | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
1546 | | |
1547 | | /// Determine whether this class is provably not derived from |
1548 | | /// the type \p Base. |
1549 | | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
1550 | | |
1551 | | /// Function type used by forallBases() as a callback. |
1552 | | /// |
1553 | | /// \param BaseDefinition the definition of the base class |
1554 | | /// |
1555 | | /// \returns true if this base matched the search criteria |
1556 | | using ForallBasesCallback = |
1557 | | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
1558 | | |
1559 | | /// Determines if the given callback holds for all the direct |
1560 | | /// or indirect base classes of this type. |
1561 | | /// |
1562 | | /// The class itself does not count as a base class. This routine |
1563 | | /// returns false if the class has non-computable base classes. |
1564 | | /// |
1565 | | /// \param BaseMatches Callback invoked for each (direct or indirect) base |
1566 | | /// class of this type until a call returns false. |
1567 | | bool forallBases(ForallBasesCallback BaseMatches) const; |
1568 | | |
1569 | | /// Function type used by lookupInBases() to determine whether a |
1570 | | /// specific base class subobject matches the lookup criteria. |
1571 | | /// |
1572 | | /// \param Specifier the base-class specifier that describes the inheritance |
1573 | | /// from the base class we are trying to match. |
1574 | | /// |
1575 | | /// \param Path the current path, from the most-derived class down to the |
1576 | | /// base named by the \p Specifier. |
1577 | | /// |
1578 | | /// \returns true if this base matched the search criteria, false otherwise. |
1579 | | using BaseMatchesCallback = |
1580 | | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
1581 | | CXXBasePath &Path)>; |
1582 | | |
1583 | | /// Look for entities within the base classes of this C++ class, |
1584 | | /// transitively searching all base class subobjects. |
1585 | | /// |
1586 | | /// This routine uses the callback function \p BaseMatches to find base |
1587 | | /// classes meeting some search criteria, walking all base class subobjects |
1588 | | /// and populating the given \p Paths structure with the paths through the |
1589 | | /// inheritance hierarchy that resulted in a match. On a successful search, |
1590 | | /// the \p Paths structure can be queried to retrieve the matching paths and |
1591 | | /// to determine if there were any ambiguities. |
1592 | | /// |
1593 | | /// \param BaseMatches callback function used to determine whether a given |
1594 | | /// base matches the user-defined search criteria. |
1595 | | /// |
1596 | | /// \param Paths used to record the paths from this class to its base class |
1597 | | /// subobjects that match the search criteria. |
1598 | | /// |
1599 | | /// \param LookupInDependent can be set to true to extend the search to |
1600 | | /// dependent base classes. |
1601 | | /// |
1602 | | /// \returns true if there exists any path from this class to a base class |
1603 | | /// subobject that matches the search criteria. |
1604 | | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
1605 | | bool LookupInDependent = false) const; |
1606 | | |
1607 | | /// Base-class lookup callback that determines whether the given |
1608 | | /// base class specifier refers to a specific class declaration. |
1609 | | /// |
1610 | | /// This callback can be used with \c lookupInBases() to determine whether |
1611 | | /// a given derived class has is a base class subobject of a particular type. |
1612 | | /// The base record pointer should refer to the canonical CXXRecordDecl of the |
1613 | | /// base class that we are searching for. |
1614 | | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
1615 | | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
1616 | | |
1617 | | /// Base-class lookup callback that determines whether the |
1618 | | /// given base class specifier refers to a specific class |
1619 | | /// declaration and describes virtual derivation. |
1620 | | /// |
1621 | | /// This callback can be used with \c lookupInBases() to determine |
1622 | | /// whether a given derived class has is a virtual base class |
1623 | | /// subobject of a particular type. The base record pointer should |
1624 | | /// refer to the canonical CXXRecordDecl of the base class that we |
1625 | | /// are searching for. |
1626 | | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
1627 | | CXXBasePath &Path, |
1628 | | const CXXRecordDecl *BaseRecord); |
1629 | | |
1630 | | /// Retrieve the final overriders for each virtual member |
1631 | | /// function in the class hierarchy where this class is the |
1632 | | /// most-derived class in the class hierarchy. |
1633 | | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
1634 | | |
1635 | | /// Get the indirect primary bases for this class. |
1636 | | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
1637 | | |
1638 | | /// Determine whether this class has a member with the given name, possibly |
1639 | | /// in a non-dependent base class. |
1640 | | /// |
1641 | | /// No check for ambiguity is performed, so this should never be used when |
1642 | | /// implementing language semantics, but it may be appropriate for warnings, |
1643 | | /// static analysis, or similar. |
1644 | | bool hasMemberName(DeclarationName N) const; |
1645 | | |
1646 | | /// Performs an imprecise lookup of a dependent name in this class. |
1647 | | /// |
1648 | | /// This function does not follow strict semantic rules and should be used |
1649 | | /// only when lookup rules can be relaxed, e.g. indexing. |
1650 | | std::vector<const NamedDecl *> |
1651 | | lookupDependentName(DeclarationName Name, |
1652 | | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
1653 | | |
1654 | | /// Renders and displays an inheritance diagram |
1655 | | /// for this C++ class and all of its base classes (transitively) using |
1656 | | /// GraphViz. |
1657 | | void viewInheritance(ASTContext& Context) const; |
1658 | | |
1659 | | /// Calculates the access of a decl that is reached |
1660 | | /// along a path. |
1661 | | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
1662 | 931k | AccessSpecifier DeclAccess) { |
1663 | 931k | assert(DeclAccess != AS_none); |
1664 | 931k | if (DeclAccess == AS_private) return AS_none29.9k ; |
1665 | 901k | return (PathAccess > DeclAccess ? PathAccess70.8k : DeclAccess830k ); |
1666 | 901k | } |
1667 | | |
1668 | | /// Indicates that the declaration of a defaulted or deleted special |
1669 | | /// member function is now complete. |
1670 | | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
1671 | | |
1672 | | void setTrivialForCallFlags(CXXMethodDecl *MD); |
1673 | | |
1674 | | /// Indicates that the definition of this class is now complete. |
1675 | | void completeDefinition() override; |
1676 | | |
1677 | | /// Indicates that the definition of this class is now complete, |
1678 | | /// and provides a final overrider map to help determine |
1679 | | /// |
1680 | | /// \param FinalOverriders The final overrider map for this class, which can |
1681 | | /// be provided as an optimization for abstract-class checking. If NULL, |
1682 | | /// final overriders will be computed if they are needed to complete the |
1683 | | /// definition. |
1684 | | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
1685 | | |
1686 | | /// Determine whether this class may end up being abstract, even though |
1687 | | /// it is not yet known to be abstract. |
1688 | | /// |
1689 | | /// \returns true if this class is not known to be abstract but has any |
1690 | | /// base classes that are abstract. In this case, \c completeDefinition() |
1691 | | /// will need to compute final overriders to determine whether the class is |
1692 | | /// actually abstract. |
1693 | | bool mayBeAbstract() const; |
1694 | | |
1695 | | /// Determine whether it's impossible for a class to be derived from this |
1696 | | /// class. This is best-effort, and may conservatively return false. |
1697 | | bool isEffectivelyFinal() const; |
1698 | | |
1699 | | /// If this is the closure type of a lambda expression, retrieve the |
1700 | | /// number to be used for name mangling in the Itanium C++ ABI. |
1701 | | /// |
1702 | | /// Zero indicates that this closure type has internal linkage, so the |
1703 | | /// mangling number does not matter, while a non-zero value indicates which |
1704 | | /// lambda expression this is in this particular context. |
1705 | 35.3k | unsigned getLambdaManglingNumber() const { |
1706 | 35.3k | assert(isLambda() && "Not a lambda closure type!"); |
1707 | 35.3k | return getLambdaData().ManglingNumber; |
1708 | 35.3k | } |
1709 | | |
1710 | | /// The lambda is known to has internal linkage no matter whether it has name |
1711 | | /// mangling number. |
1712 | 13.9k | bool hasKnownLambdaInternalLinkage() const { |
1713 | 13.9k | assert(isLambda() && "Not a lambda closure type!"); |
1714 | 13.9k | return getLambdaData().HasKnownInternalLinkage; |
1715 | 13.9k | } |
1716 | | |
1717 | | /// Retrieve the declaration that provides additional context for a |
1718 | | /// lambda, when the normal declaration context is not specific enough. |
1719 | | /// |
1720 | | /// Certain contexts (default arguments of in-class function parameters and |
1721 | | /// the initializers of data members) have separate name mangling rules for |
1722 | | /// lambdas within the Itanium C++ ABI. For these cases, this routine provides |
1723 | | /// the declaration in which the lambda occurs, e.g., the function parameter |
1724 | | /// or the non-static data member. Otherwise, it returns NULL to imply that |
1725 | | /// the declaration context suffices. |
1726 | | Decl *getLambdaContextDecl() const; |
1727 | | |
1728 | | /// Set the mangling number and context declaration for a lambda |
1729 | | /// class. |
1730 | | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl, |
1731 | 6.09k | bool HasKnownInternalLinkage = false) { |
1732 | 6.09k | assert(isLambda() && "Not a lambda closure type!"); |
1733 | 6.09k | getLambdaData().ManglingNumber = ManglingNumber; |
1734 | 6.09k | getLambdaData().ContextDecl = ContextDecl; |
1735 | 6.09k | getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage; |
1736 | 6.09k | } |
1737 | | |
1738 | | /// Returns the inheritance model used for this record. |
1739 | | MSInheritanceModel getMSInheritanceModel() const; |
1740 | | |
1741 | | /// Calculate what the inheritance model would be for this class. |
1742 | | MSInheritanceModel calculateInheritanceModel() const; |
1743 | | |
1744 | | /// In the Microsoft C++ ABI, use zero for the field offset of a null data |
1745 | | /// member pointer if we can guarantee that zero is not a valid field offset, |
1746 | | /// or if the member pointer has multiple fields. Polymorphic classes have a |
1747 | | /// vfptr at offset zero, so we can use zero for null. If there are multiple |
1748 | | /// fields, we can use zero even if it is a valid field offset because |
1749 | | /// null-ness testing will check the other fields. |
1750 | | bool nullFieldOffsetIsZero() const; |
1751 | | |
1752 | | /// Controls when vtordisps will be emitted if this record is used as a |
1753 | | /// virtual base. |
1754 | | MSVtorDispMode getMSVtorDispMode() const; |
1755 | | |
1756 | | /// Determine whether this lambda expression was known to be dependent |
1757 | | /// at the time it was created, even if its context does not appear to be |
1758 | | /// dependent. |
1759 | | /// |
1760 | | /// This flag is a workaround for an issue with parsing, where default |
1761 | | /// arguments are parsed before their enclosing function declarations have |
1762 | | /// been created. This means that any lambda expressions within those |
1763 | | /// default arguments will have as their DeclContext the context enclosing |
1764 | | /// the function declaration, which may be non-dependent even when the |
1765 | | /// function declaration itself is dependent. This flag indicates when we |
1766 | | /// know that the lambda is dependent despite that. |
1767 | 40.6M | bool isDependentLambda() const { |
1768 | 40.6M | return isLambda() && getLambdaData().Dependent333k ; |
1769 | 40.6M | } |
1770 | | |
1771 | 10.0k | TypeSourceInfo *getLambdaTypeInfo() const { |
1772 | 10.0k | return getLambdaData().MethodTyInfo; |
1773 | 10.0k | } |
1774 | | |
1775 | | // Determine whether this type is an Interface Like type for |
1776 | | // __interface inheritance purposes. |
1777 | | bool isInterfaceLike() const; |
1778 | | |
1779 | 767M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1780 | 1.39G | static bool classofKind(Kind K) { |
1781 | 1.39G | return K >= firstCXXRecord && K <= lastCXXRecord1.20G ; |
1782 | 1.39G | } |
1783 | | }; |
1784 | | |
1785 | | /// Store information needed for an explicit specifier. |
1786 | | /// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl. |
1787 | | class ExplicitSpecifier { |
1788 | | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
1789 | | nullptr, ExplicitSpecKind::ResolvedFalse}; |
1790 | | |
1791 | | public: |
1792 | 95.6M | ExplicitSpecifier() = default; |
1793 | | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
1794 | 2.88M | : ExplicitSpec(Expression, Kind) {} |
1795 | 393k | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
1796 | 4.99k | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
1797 | 5.16M | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
1798 | | |
1799 | | /// Determine if the declaration had an explicit specifier of any kind. |
1800 | 98.3M | bool isSpecified() const { |
1801 | 98.3M | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
1802 | 98.2M | ExplicitSpec.getPointer(); |
1803 | 98.3M | } |
1804 | | |
1805 | | /// Check for equivalence of explicit specifiers. |
1806 | | /// \return true if the explicit specifier are equivalent, false otherwise. |
1807 | | bool isEquivalent(const ExplicitSpecifier Other) const; |
1808 | | /// Determine whether this specifier is known to correspond to an explicit |
1809 | | /// declaration. Returns false if the specifier is absent or has an |
1810 | | /// expression that is value-dependent or evaluates to false. |
1811 | 4.26M | bool isExplicit() const { |
1812 | 4.26M | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
1813 | 4.26M | } |
1814 | | /// Determine if the explicit specifier is invalid. |
1815 | | /// This state occurs after a substitution failures. |
1816 | 969k | bool isInvalid() const { |
1817 | 969k | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
1818 | 174 | !ExplicitSpec.getPointer(); |
1819 | 969k | } |
1820 | 288 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
1821 | 288 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
1822 | | // Retrieve the explicit specifier in the given declaration, if any. |
1823 | | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
1824 | 42 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
1825 | 42 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
1826 | 42 | } |
1827 | 142 | static ExplicitSpecifier Invalid() { |
1828 | 142 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
1829 | 142 | } |
1830 | | }; |
1831 | | |
1832 | | /// Represents a C++ deduction guide declaration. |
1833 | | /// |
1834 | | /// \code |
1835 | | /// template<typename T> struct A { A(); A(T); }; |
1836 | | /// A() -> A<int>; |
1837 | | /// \endcode |
1838 | | /// |
1839 | | /// In this example, there will be an explicit deduction guide from the |
1840 | | /// second line, and implicit deduction guide templates synthesized from |
1841 | | /// the constructors of \c A. |
1842 | | class CXXDeductionGuideDecl : public FunctionDecl { |
1843 | | void anchor() override; |
1844 | | |
1845 | | private: |
1846 | | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1847 | | ExplicitSpecifier ES, |
1848 | | const DeclarationNameInfo &NameInfo, QualType T, |
1849 | | TypeSourceInfo *TInfo, SourceLocation EndLocation) |
1850 | | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
1851 | | SC_None, false, ConstexprSpecKind::Unspecified), |
1852 | 2.25k | ExplicitSpec(ES) { |
1853 | 2.25k | if (EndLocation.isValid()) |
1854 | 2.18k | setRangeEnd(EndLocation); |
1855 | 2.25k | setIsCopyDeductionCandidate(false); |
1856 | 2.25k | } |
1857 | | |
1858 | | ExplicitSpecifier ExplicitSpec; |
1859 | 69 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
1860 | | |
1861 | | public: |
1862 | | friend class ASTDeclReader; |
1863 | | friend class ASTDeclWriter; |
1864 | | |
1865 | | static CXXDeductionGuideDecl * |
1866 | | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1867 | | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
1868 | | TypeSourceInfo *TInfo, SourceLocation EndLocation); |
1869 | | |
1870 | | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1871 | | |
1872 | 1.57k | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
1873 | 0 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
1874 | | |
1875 | | /// Return true if the declartion is already resolved to be explicit. |
1876 | 138 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
1877 | | |
1878 | | /// Get the template for which this guide performs deduction. |
1879 | 1.09k | TemplateDecl *getDeducedTemplate() const { |
1880 | 1.09k | return getDeclName().getCXXDeductionGuideTemplate(); |
1881 | 1.09k | } |
1882 | | |
1883 | 2.62k | void setIsCopyDeductionCandidate(bool isCDC = true) { |
1884 | 2.62k | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
1885 | 2.62k | } |
1886 | | |
1887 | 1.15k | bool isCopyDeductionCandidate() const { |
1888 | 1.15k | return FunctionDeclBits.IsCopyDeductionCandidate; |
1889 | 1.15k | } |
1890 | | |
1891 | | // Implement isa/cast/dyncast/etc. |
1892 | 7.78M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1893 | 7.78M | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
1894 | | }; |
1895 | | |
1896 | | /// \brief Represents the body of a requires-expression. |
1897 | | /// |
1898 | | /// This decl exists merely to serve as the DeclContext for the local |
1899 | | /// parameters of the requires expression as well as other declarations inside |
1900 | | /// it. |
1901 | | /// |
1902 | | /// \code |
1903 | | /// template<typename T> requires requires (T t) { {t++} -> regular; } |
1904 | | /// \endcode |
1905 | | /// |
1906 | | /// In this example, a RequiresExpr object will be generated for the expression, |
1907 | | /// and a RequiresExprBodyDecl will be created to hold the parameter t and the |
1908 | | /// template argument list imposed by the compound requirement. |
1909 | | class RequiresExprBodyDecl : public Decl, public DeclContext { |
1910 | | RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc) |
1911 | 384 | : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {} |
1912 | | |
1913 | | public: |
1914 | | friend class ASTDeclReader; |
1915 | | friend class ASTDeclWriter; |
1916 | | |
1917 | | static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC, |
1918 | | SourceLocation StartLoc); |
1919 | | |
1920 | | static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1921 | | |
1922 | | // Implement isa/cast/dyncast/etc. |
1923 | 4 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1924 | 112M | static bool classofKind(Kind K) { return K == RequiresExprBody; } |
1925 | | }; |
1926 | | |
1927 | | /// Represents a static or instance method of a struct/union/class. |
1928 | | /// |
1929 | | /// In the terminology of the C++ Standard, these are the (static and |
1930 | | /// non-static) member functions, whether virtual or not. |
1931 | | class CXXMethodDecl : public FunctionDecl { |
1932 | | void anchor() override; |
1933 | | |
1934 | | protected: |
1935 | | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
1936 | | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
1937 | | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
1938 | | bool isInline, ConstexprSpecKind ConstexprKind, |
1939 | | SourceLocation EndLocation, |
1940 | | Expr *TrailingRequiresClause = nullptr) |
1941 | | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, |
1942 | 3.40M | ConstexprKind, TrailingRequiresClause) { |
1943 | 3.40M | if (EndLocation.isValid()) |
1944 | 740k | setRangeEnd(EndLocation); |
1945 | 3.40M | } |
1946 | | |
1947 | | public: |
1948 | | static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
1949 | | SourceLocation StartLoc, |
1950 | | const DeclarationNameInfo &NameInfo, QualType T, |
1951 | | TypeSourceInfo *TInfo, StorageClass SC, |
1952 | | bool isInline, ConstexprSpecKind ConstexprKind, |
1953 | | SourceLocation EndLocation, |
1954 | | Expr *TrailingRequiresClause = nullptr); |
1955 | | |
1956 | | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1957 | | |
1958 | | bool isStatic() const; |
1959 | 9.05M | bool isInstance() const { return !isStatic(); } |
1960 | | |
1961 | | /// Returns true if the given operator is implicitly static in a record |
1962 | | /// context. |
1963 | 20.1M | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
1964 | | // [class.free]p1: |
1965 | | // Any allocation function for a class T is a static member |
1966 | | // (even if not explicitly declared static). |
1967 | | // [class.free]p6 Any deallocation function for a class X is a static member |
1968 | | // (even if not explicitly declared static). |
1969 | 20.1M | return OOK == OO_New || OOK == OO_Array_New20.1M || OOK == OO_Delete20.1M || |
1970 | 20.1M | OOK == OO_Array_Delete; |
1971 | 20.1M | } |
1972 | | |
1973 | 666k | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
1974 | 607k | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
1975 | | |
1976 | 10.1M | bool isVirtual() const { |
1977 | 10.1M | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
1978 | | |
1979 | | // Member function is virtual if it is marked explicitly so, or if it is |
1980 | | // declared in __interface -- then it is automatically pure virtual. |
1981 | 10.1M | if (CD->isVirtualAsWritten() || CD->isPure()9.58M ) |
1982 | 543k | return true; |
1983 | | |
1984 | 9.58M | return CD->size_overridden_methods() != 0; |
1985 | 9.58M | } |
1986 | | |
1987 | | /// If it's possible to devirtualize a call to this method, return the called |
1988 | | /// function. Otherwise, return null. |
1989 | | |
1990 | | /// \param Base The object on which this virtual function is called. |
1991 | | /// \param IsAppleKext True if we are compiling for Apple kext. |
1992 | | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
1993 | | |
1994 | | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
1995 | 1.67k | bool IsAppleKext) const { |
1996 | 1.67k | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
1997 | 1.67k | Base, IsAppleKext); |
1998 | 1.67k | } |
1999 | | |
2000 | | /// Determine whether this is a usual deallocation function (C++ |
2001 | | /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or |
2002 | | /// delete[] operator with a particular signature. Populates \p PreventedBy |
2003 | | /// with the declarations of the functions of the same kind if they were the |
2004 | | /// reason for this function returning false. This is used by |
2005 | | /// Sema::isUsualDeallocationFunction to reconsider the answer based on the |
2006 | | /// context. |
2007 | | bool isUsualDeallocationFunction( |
2008 | | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
2009 | | |
2010 | | /// Determine whether this is a copy-assignment operator, regardless |
2011 | | /// of whether it was declared implicitly or explicitly. |
2012 | | bool isCopyAssignmentOperator() const; |
2013 | | |
2014 | | /// Determine whether this is a move assignment operator. |
2015 | | bool isMoveAssignmentOperator() const; |
2016 | | |
2017 | 66.5M | CXXMethodDecl *getCanonicalDecl() override { |
2018 | 66.5M | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
2019 | 66.5M | } |
2020 | 33.4M | const CXXMethodDecl *getCanonicalDecl() const { |
2021 | 33.4M | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2022 | 33.4M | } |
2023 | | |
2024 | 164k | CXXMethodDecl *getMostRecentDecl() { |
2025 | 164k | return cast<CXXMethodDecl>( |
2026 | 164k | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
2027 | 164k | } |
2028 | 0 | const CXXMethodDecl *getMostRecentDecl() const { |
2029 | 0 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
2030 | 0 | } |
2031 | | |
2032 | | void addOverriddenMethod(const CXXMethodDecl *MD); |
2033 | | |
2034 | | using method_iterator = const CXXMethodDecl *const *; |
2035 | | |
2036 | | method_iterator begin_overridden_methods() const; |
2037 | | method_iterator end_overridden_methods() const; |
2038 | | unsigned size_overridden_methods() const; |
2039 | | |
2040 | | using overridden_method_range = llvm::iterator_range< |
2041 | | llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>; |
2042 | | |
2043 | | overridden_method_range overridden_methods() const; |
2044 | | |
2045 | | /// Return the parent of this method declaration, which |
2046 | | /// is the class in which this method is defined. |
2047 | 28.8M | const CXXRecordDecl *getParent() const { |
2048 | 28.8M | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
2049 | 28.8M | } |
2050 | | |
2051 | | /// Return the parent of this method declaration, which |
2052 | | /// is the class in which this method is defined. |
2053 | 9.73M | CXXRecordDecl *getParent() { |
2054 | 9.73M | return const_cast<CXXRecordDecl *>( |
2055 | 9.73M | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
2056 | 9.73M | } |
2057 | | |
2058 | | /// Return the type of the \c this pointer. |
2059 | | /// |
2060 | | /// Should only be called for instance (i.e., non-static) methods. Note |
2061 | | /// that for the call operator of a lambda closure type, this returns the |
2062 | | /// desugared 'this' type (a pointer to the closure type), not the captured |
2063 | | /// 'this' type. |
2064 | | QualType getThisType() const; |
2065 | | |
2066 | | /// Return the type of the object pointed by \c this. |
2067 | | /// |
2068 | | /// See getThisType() for usage restriction. |
2069 | | QualType getThisObjectType() const; |
2070 | | |
2071 | | static QualType getThisType(const FunctionProtoType *FPT, |
2072 | | const CXXRecordDecl *Decl); |
2073 | | |
2074 | | static QualType getThisObjectType(const FunctionProtoType *FPT, |
2075 | | const CXXRecordDecl *Decl); |
2076 | | |
2077 | 5.55M | Qualifiers getMethodQualifiers() const { |
2078 | 5.55M | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
2079 | 5.55M | } |
2080 | | |
2081 | | /// Retrieve the ref-qualifier associated with this method. |
2082 | | /// |
2083 | | /// In the following example, \c f() has an lvalue ref-qualifier, \c g() |
2084 | | /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. |
2085 | | /// @code |
2086 | | /// struct X { |
2087 | | /// void f() &; |
2088 | | /// void g() &&; |
2089 | | /// void h(); |
2090 | | /// }; |
2091 | | /// @endcode |
2092 | 5.55M | RefQualifierKind getRefQualifier() const { |
2093 | 5.55M | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
2094 | 5.55M | } |
2095 | | |
2096 | | bool hasInlineBody() const; |
2097 | | |
2098 | | /// Determine whether this is a lambda closure type's static member |
2099 | | /// function that is used for the result of the lambda's conversion to |
2100 | | /// function pointer (for a lambda with no captures). |
2101 | | /// |
2102 | | /// The function itself, if used, will have a placeholder body that will be |
2103 | | /// supplied by IR generation to either forward to the function call operator |
2104 | | /// or clone the function call operator. |
2105 | | bool isLambdaStaticInvoker() const; |
2106 | | |
2107 | | /// Find the method in \p RD that corresponds to this one. |
2108 | | /// |
2109 | | /// Find if \p RD or one of the classes it inherits from override this method. |
2110 | | /// If so, return it. \p RD is assumed to be a subclass of the class defining |
2111 | | /// this method (or be the class itself), unless \p MayBeBase is set to true. |
2112 | | CXXMethodDecl * |
2113 | | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2114 | | bool MayBeBase = false); |
2115 | | |
2116 | | const CXXMethodDecl * |
2117 | | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2118 | 705 | bool MayBeBase = false) const { |
2119 | 705 | return const_cast<CXXMethodDecl *>(this) |
2120 | 705 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
2121 | 705 | } |
2122 | | |
2123 | | /// Find if \p RD declares a function that overrides this function, and if so, |
2124 | | /// return it. Does not search base classes. |
2125 | | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2126 | | bool MayBeBase = false); |
2127 | | const CXXMethodDecl * |
2128 | | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2129 | 172 | bool MayBeBase = false) const { |
2130 | 172 | return const_cast<CXXMethodDecl *>(this) |
2131 | 172 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
2132 | 172 | } |
2133 | | |
2134 | | // Implement isa/cast/dyncast/etc. |
2135 | 375M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2136 | 571M | static bool classofKind(Kind K) { |
2137 | 571M | return K >= firstCXXMethod && K <= lastCXXMethod305M ; |
2138 | 571M | } |
2139 | | }; |
2140 | | |
2141 | | /// Represents a C++ base or member initializer. |
2142 | | /// |
2143 | | /// This is part of a constructor initializer that |
2144 | | /// initializes one non-static member variable or one base class. For |
2145 | | /// example, in the following, both 'A(a)' and 'f(3.14159)' are member |
2146 | | /// initializers: |
2147 | | /// |
2148 | | /// \code |
2149 | | /// class A { }; |
2150 | | /// class B : public A { |
2151 | | /// float f; |
2152 | | /// public: |
2153 | | /// B(A& a) : A(a), f(3.14159) { } |
2154 | | /// }; |
2155 | | /// \endcode |
2156 | | class CXXCtorInitializer final { |
2157 | | /// Either the base class name/delegating constructor type (stored as |
2158 | | /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field |
2159 | | /// (IndirectFieldDecl*) being initialized. |
2160 | | llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
2161 | | Initializee; |
2162 | | |
2163 | | /// The source location for the field name or, for a base initializer |
2164 | | /// pack expansion, the location of the ellipsis. |
2165 | | /// |
2166 | | /// In the case of a delegating |
2167 | | /// constructor, it will still include the type's source location as the |
2168 | | /// Initializee points to the CXXConstructorDecl (to allow loop detection). |
2169 | | SourceLocation MemberOrEllipsisLocation; |
2170 | | |
2171 | | /// The argument used to initialize the base or member, which may |
2172 | | /// end up constructing an object (when multiple arguments are involved). |
2173 | | Stmt *Init; |
2174 | | |
2175 | | /// Location of the left paren of the ctor-initializer. |
2176 | | SourceLocation LParenLoc; |
2177 | | |
2178 | | /// Location of the right paren of the ctor-initializer. |
2179 | | SourceLocation RParenLoc; |
2180 | | |
2181 | | /// If the initializee is a type, whether that type makes this |
2182 | | /// a delegating initialization. |
2183 | | unsigned IsDelegating : 1; |
2184 | | |
2185 | | /// If the initializer is a base initializer, this keeps track |
2186 | | /// of whether the base is virtual or not. |
2187 | | unsigned IsVirtual : 1; |
2188 | | |
2189 | | /// Whether or not the initializer is explicitly written |
2190 | | /// in the sources. |
2191 | | unsigned IsWritten : 1; |
2192 | | |
2193 | | /// If IsWritten is true, then this number keeps track of the textual order |
2194 | | /// of this initializer in the original sources, counting from 0. |
2195 | | unsigned SourceOrder : 13; |
2196 | | |
2197 | | public: |
2198 | | /// Creates a new base-class initializer. |
2199 | | explicit |
2200 | | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
2201 | | SourceLocation L, Expr *Init, SourceLocation R, |
2202 | | SourceLocation EllipsisLoc); |
2203 | | |
2204 | | /// Creates a new member initializer. |
2205 | | explicit |
2206 | | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2207 | | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2208 | | SourceLocation R); |
2209 | | |
2210 | | /// Creates a new anonymous field initializer. |
2211 | | explicit |
2212 | | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
2213 | | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2214 | | SourceLocation R); |
2215 | | |
2216 | | /// Creates a new delegating initializer. |
2217 | | explicit |
2218 | | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
2219 | | SourceLocation L, Expr *Init, SourceLocation R); |
2220 | | |
2221 | | /// \return Unique reproducible object identifier. |
2222 | | int64_t getID(const ASTContext &Context) const; |
2223 | | |
2224 | | /// Determine whether this initializer is initializing a base class. |
2225 | 485k | bool isBaseInitializer() const { |
2226 | 485k | return Initializee.is<TypeSourceInfo*>() && !IsDelegating226k ; |
2227 | 485k | } |
2228 | | |
2229 | | /// Determine whether this initializer is initializing a non-static |
2230 | | /// data member. |
2231 | 1.43M | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
2232 | | |
2233 | 646k | bool isAnyMemberInitializer() const { |
2234 | 646k | return isMemberInitializer() || isIndirectMemberInitializer()97.8k ; |
2235 | 646k | } |
2236 | | |
2237 | 188k | bool isIndirectMemberInitializer() const { |
2238 | 188k | return Initializee.is<IndirectFieldDecl*>(); |
2239 | 188k | } |
2240 | | |
2241 | | /// Determine whether this initializer is an implicit initializer |
2242 | | /// generated for a field with an initializer defined on the member |
2243 | | /// declaration. |
2244 | | /// |
2245 | | /// In-class member initializers (also known as "non-static data member |
2246 | | /// initializations", NSDMIs) were introduced in C++11. |
2247 | 133k | bool isInClassMemberInitializer() const { |
2248 | 133k | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
2249 | 133k | } |
2250 | | |
2251 | | /// Determine whether this initializer is creating a delegating |
2252 | | /// constructor. |
2253 | 85.5k | bool isDelegatingInitializer() const { |
2254 | 85.5k | return Initializee.is<TypeSourceInfo*>() && IsDelegating13.9k ; |
2255 | 85.5k | } |
2256 | | |
2257 | | /// Determine whether this initializer is a pack expansion. |
2258 | 41.0k | bool isPackExpansion() const { |
2259 | 41.0k | return isBaseInitializer() && MemberOrEllipsisLocation.isValid()14.5k ; |
2260 | 41.0k | } |
2261 | | |
2262 | | // For a pack expansion, returns the location of the ellipsis. |
2263 | 697 | SourceLocation getEllipsisLoc() const { |
2264 | 697 | assert(isPackExpansion() && "Initializer is not a pack expansion"); |
2265 | 697 | return MemberOrEllipsisLocation; |
2266 | 697 | } |
2267 | | |
2268 | | /// If this is a base class initializer, returns the type of the |
2269 | | /// base class with location information. Otherwise, returns an NULL |
2270 | | /// type location. |
2271 | | TypeLoc getBaseClassLoc() const; |
2272 | | |
2273 | | /// If this is a base class initializer, returns the type of the base class. |
2274 | | /// Otherwise, returns null. |
2275 | | const Type *getBaseClass() const; |
2276 | | |
2277 | | /// Returns whether the base is virtual or not. |
2278 | 36.4k | bool isBaseVirtual() const { |
2279 | 36.4k | assert(isBaseInitializer() && "Must call this on base initializer!"); |
2280 | | |
2281 | 36.4k | return IsVirtual; |
2282 | 36.4k | } |
2283 | | |
2284 | | /// Returns the declarator information for a base class or delegating |
2285 | | /// initializer. |
2286 | 57.6k | TypeSourceInfo *getTypeSourceInfo() const { |
2287 | 57.6k | return Initializee.dyn_cast<TypeSourceInfo *>(); |
2288 | 57.6k | } |
2289 | | |
2290 | | /// If this is a member initializer, returns the declaration of the |
2291 | | /// non-static data member being initialized. Otherwise, returns null. |
2292 | 180k | FieldDecl *getMember() const { |
2293 | 180k | if (isMemberInitializer()) |
2294 | 178k | return Initializee.get<FieldDecl*>(); |
2295 | 1.53k | return nullptr; |
2296 | 1.53k | } |
2297 | | |
2298 | 535k | FieldDecl *getAnyMember() const { |
2299 | 535k | if (isMemberInitializer()) |
2300 | 526k | return Initializee.get<FieldDecl*>(); |
2301 | 9.01k | if (isIndirectMemberInitializer()) |
2302 | 1.06k | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
2303 | 7.95k | return nullptr; |
2304 | 7.95k | } |
2305 | | |
2306 | 55.2k | IndirectFieldDecl *getIndirectMember() const { |
2307 | 55.2k | if (isIndirectMemberInitializer()) |
2308 | 1.09k | return Initializee.get<IndirectFieldDecl*>(); |
2309 | 54.1k | return nullptr; |
2310 | 54.1k | } |
2311 | | |
2312 | 182k | SourceLocation getMemberLocation() const { |
2313 | 182k | return MemberOrEllipsisLocation; |
2314 | 182k | } |
2315 | | |
2316 | | /// Determine the source location of the initializer. |
2317 | | SourceLocation getSourceLocation() const; |
2318 | | |
2319 | | /// Determine the source range covering the entire initializer. |
2320 | | SourceRange getSourceRange() const LLVM_READONLY; |
2321 | | |
2322 | | /// Determine whether this initializer is explicitly written |
2323 | | /// in the source code. |
2324 | 163k | bool isWritten() const { return IsWritten; } |
2325 | | |
2326 | | /// Return the source position of the initializer, counting from 0. |
2327 | | /// If the initializer was implicit, -1 is returned. |
2328 | 20.5k | int getSourceOrder() const { |
2329 | 20.5k | return IsWritten ? static_cast<int>(SourceOrder) : -10 ; |
2330 | 20.5k | } |
2331 | | |
2332 | | /// Set the source order of this initializer. |
2333 | | /// |
2334 | | /// This can only be called once for each initializer; it cannot be called |
2335 | | /// on an initializer having a positive number of (implicit) array indices. |
2336 | | /// |
2337 | | /// This assumes that the initializer was written in the source code, and |
2338 | | /// ensures that isWritten() returns true. |
2339 | 267k | void setSourceOrder(int Pos) { |
2340 | 267k | assert(!IsWritten && |
2341 | 267k | "setSourceOrder() used on implicit initializer"); |
2342 | 267k | assert(SourceOrder == 0 && |
2343 | 267k | "calling twice setSourceOrder() on the same initializer"); |
2344 | 267k | assert(Pos >= 0 && |
2345 | 267k | "setSourceOrder() used to make an initializer implicit"); |
2346 | 267k | IsWritten = true; |
2347 | 267k | SourceOrder = static_cast<unsigned>(Pos); |
2348 | 267k | } |
2349 | | |
2350 | 56.8k | SourceLocation getLParenLoc() const { return LParenLoc; } |
2351 | 56.9k | SourceLocation getRParenLoc() const { return RParenLoc; } |
2352 | | |
2353 | | /// Get the initializer. |
2354 | 410k | Expr *getInit() const { return static_cast<Expr *>(Init); } |
2355 | | }; |
2356 | | |
2357 | | /// Description of a constructor that was inherited from a base class. |
2358 | | class InheritedConstructor { |
2359 | | ConstructorUsingShadowDecl *Shadow = nullptr; |
2360 | | CXXConstructorDecl *BaseCtor = nullptr; |
2361 | | |
2362 | | public: |
2363 | 1.82M | InheritedConstructor() = default; |
2364 | | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
2365 | | CXXConstructorDecl *BaseCtor) |
2366 | 310 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
2367 | | |
2368 | 3.53M | explicit operator bool() const { return Shadow; } |
2369 | | |
2370 | 1.39k | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
2371 | 2.45k | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
2372 | | }; |
2373 | | |
2374 | | /// Represents a C++ constructor within a class. |
2375 | | /// |
2376 | | /// For example: |
2377 | | /// |
2378 | | /// \code |
2379 | | /// class X { |
2380 | | /// public: |
2381 | | /// explicit X(int); // represented by a CXXConstructorDecl. |
2382 | | /// }; |
2383 | | /// \endcode |
2384 | | class CXXConstructorDecl final |
2385 | | : public CXXMethodDecl, |
2386 | | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
2387 | | ExplicitSpecifier> { |
2388 | | // This class stores some data in DeclContext::CXXConstructorDeclBits |
2389 | | // to save some space. Use the provided accessors to access it. |
2390 | | |
2391 | | /// \name Support for base and member initializers. |
2392 | | /// \{ |
2393 | | /// The arguments used to initialize the base or member. |
2394 | | LazyCXXCtorInitializersPtr CtorInitializers; |
2395 | | |
2396 | | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2397 | | const DeclarationNameInfo &NameInfo, QualType T, |
2398 | | TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, |
2399 | | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2400 | | InheritedConstructor Inherited, |
2401 | | Expr *TrailingRequiresClause); |
2402 | | |
2403 | | void anchor() override; |
2404 | | |
2405 | 48.4k | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
2406 | 48.4k | return CXXConstructorDeclBits.IsInheritingConstructor; |
2407 | 48.4k | } |
2408 | 47.1k | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
2409 | 47.1k | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
2410 | 47.1k | } |
2411 | | |
2412 | 2.58M | ExplicitSpecifier getExplicitSpecifierInternal() const { |
2413 | 2.58M | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
2414 | 1.13k | return *getTrailingObjects<ExplicitSpecifier>(); |
2415 | 2.58M | return ExplicitSpecifier( |
2416 | 2.58M | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
2417 | 380k | ? ExplicitSpecKind::ResolvedTrue |
2418 | 2.20M | : ExplicitSpecKind::ResolvedFalse); |
2419 | 2.58M | } |
2420 | | |
2421 | | enum TraillingAllocKind { |
2422 | | TAKInheritsConstructor = 1, |
2423 | | TAKHasTailExplicit = 1 << 1, |
2424 | | }; |
2425 | | |
2426 | 47.1k | uint64_t getTraillingAllocKind() const { |
2427 | 47.1k | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
2428 | 47.1k | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
2429 | 47.1k | } |
2430 | | |
2431 | | public: |
2432 | | friend class ASTDeclReader; |
2433 | | friend class ASTDeclWriter; |
2434 | | friend TrailingObjects; |
2435 | | |
2436 | | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
2437 | | uint64_t AllocKind); |
2438 | | static CXXConstructorDecl * |
2439 | | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2440 | | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2441 | | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2442 | | ConstexprSpecKind ConstexprKind, |
2443 | | InheritedConstructor Inherited = InheritedConstructor(), |
2444 | | Expr *TrailingRequiresClause = nullptr); |
2445 | | |
2446 | 1.15M | void setExplicitSpecifier(ExplicitSpecifier ES) { |
2447 | 1.15M | assert((!ES.getExpr() || |
2448 | 1.15M | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && |
2449 | 1.15M | "cannot set this explicit specifier. no trail-allocated space for " |
2450 | 1.15M | "explicit"); |
2451 | 1.15M | if (ES.getExpr()) |
2452 | 164 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
2453 | 1.15M | else |
2454 | 1.15M | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
2455 | 1.15M | } |
2456 | | |
2457 | 1.50M | ExplicitSpecifier getExplicitSpecifier() { |
2458 | 1.50M | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2459 | 1.50M | } |
2460 | 1.08M | const ExplicitSpecifier getExplicitSpecifier() const { |
2461 | 1.08M | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2462 | 1.08M | } |
2463 | | |
2464 | | /// Return true if the declartion is already resolved to be explicit. |
2465 | 1.08M | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2466 | | |
2467 | | /// Iterates through the member/base initializer list. |
2468 | | using init_iterator = CXXCtorInitializer **; |
2469 | | |
2470 | | /// Iterates through the member/base initializer list. |
2471 | | using init_const_iterator = CXXCtorInitializer *const *; |
2472 | | |
2473 | | using init_range = llvm::iterator_range<init_iterator>; |
2474 | | using init_const_range = llvm::iterator_range<init_const_iterator>; |
2475 | | |
2476 | 94.1k | init_range inits() { return init_range(init_begin(), init_end()); } |
2477 | 100k | init_const_range inits() const { |
2478 | 100k | return init_const_range(init_begin(), init_end()); |
2479 | 100k | } |
2480 | | |
2481 | | /// Retrieve an iterator to the first initializer. |
2482 | 188k | init_iterator init_begin() { |
2483 | 188k | const auto *ConstThis = this; |
2484 | 188k | return const_cast<init_iterator>(ConstThis->init_begin()); |
2485 | 188k | } |
2486 | | |
2487 | | /// Retrieve an iterator to the first initializer. |
2488 | | init_const_iterator init_begin() const; |
2489 | | |
2490 | | /// Retrieve an iterator past the last initializer. |
2491 | 94.1k | init_iterator init_end() { |
2492 | 94.1k | return init_begin() + getNumCtorInitializers(); |
2493 | 94.1k | } |
2494 | | |
2495 | | /// Retrieve an iterator past the last initializer. |
2496 | 139k | init_const_iterator init_end() const { |
2497 | 139k | return init_begin() + getNumCtorInitializers(); |
2498 | 139k | } |
2499 | | |
2500 | | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
2501 | | using init_const_reverse_iterator = |
2502 | | std::reverse_iterator<init_const_iterator>; |
2503 | | |
2504 | 0 | init_reverse_iterator init_rbegin() { |
2505 | 0 | return init_reverse_iterator(init_end()); |
2506 | 0 | } |
2507 | 0 | init_const_reverse_iterator init_rbegin() const { |
2508 | 0 | return init_const_reverse_iterator(init_end()); |
2509 | 0 | } |
2510 | | |
2511 | 0 | init_reverse_iterator init_rend() { |
2512 | 0 | return init_reverse_iterator(init_begin()); |
2513 | 0 | } |
2514 | 0 | init_const_reverse_iterator init_rend() const { |
2515 | 0 | return init_const_reverse_iterator(init_begin()); |
2516 | 0 | } |
2517 | | |
2518 | | /// Determine the number of arguments used to initialize the member |
2519 | | /// or base. |
2520 | 461k | unsigned getNumCtorInitializers() const { |
2521 | 461k | return CXXConstructorDeclBits.NumCtorInitializers; |
2522 | 461k | } |
2523 | | |
2524 | 1.20M | void setNumCtorInitializers(unsigned numCtorInitializers) { |
2525 | 1.20M | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
2526 | | // This assert added because NumCtorInitializers is stored |
2527 | | // in CXXConstructorDeclBits as a bitfield and its width has |
2528 | | // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields. |
2529 | 1.20M | assert(CXXConstructorDeclBits.NumCtorInitializers == |
2530 | 1.20M | numCtorInitializers && "NumCtorInitializers overflow!"); |
2531 | 1.20M | } |
2532 | | |
2533 | 228k | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
2534 | 228k | CtorInitializers = Initializers; |
2535 | 228k | } |
2536 | | |
2537 | | /// Determine whether this constructor is a delegating constructor. |
2538 | 58.6k | bool isDelegatingConstructor() const { |
2539 | 58.6k | return (getNumCtorInitializers() == 1) && |
2540 | 29.9k | init_begin()[0]->isDelegatingInitializer(); |
2541 | 58.6k | } |
2542 | | |
2543 | | /// When this constructor delegates to another, retrieve the target. |
2544 | | CXXConstructorDecl *getTargetConstructor() const; |
2545 | | |
2546 | | /// Whether this constructor is a default |
2547 | | /// constructor (C++ [class.ctor]p5), which can be used to |
2548 | | /// default-initialize a class of this type. |
2549 | | bool isDefaultConstructor() const; |
2550 | | |
2551 | | /// Whether this constructor is a copy constructor (C++ [class.copy]p2, |
2552 | | /// which can be used to copy the class. |
2553 | | /// |
2554 | | /// \p TypeQuals will be set to the qualifiers on the |
2555 | | /// argument type. For example, \p TypeQuals would be set to \c |
2556 | | /// Qualifiers::Const for the following copy constructor: |
2557 | | /// |
2558 | | /// \code |
2559 | | /// class X { |
2560 | | /// public: |
2561 | | /// X(const X&); |
2562 | | /// }; |
2563 | | /// \endcode |
2564 | | bool isCopyConstructor(unsigned &TypeQuals) const; |
2565 | | |
2566 | | /// Whether this constructor is a copy |
2567 | | /// constructor (C++ [class.copy]p2, which can be used to copy the |
2568 | | /// class. |
2569 | 651k | bool isCopyConstructor() const { |
2570 | 651k | unsigned TypeQuals = 0; |
2571 | 651k | return isCopyConstructor(TypeQuals); |
2572 | 651k | } |
2573 | | |
2574 | | /// Determine whether this constructor is a move constructor |
2575 | | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2576 | | /// |
2577 | | /// \param TypeQuals If this constructor is a move constructor, will be set |
2578 | | /// to the type qualifiers on the referent of the first parameter's type. |
2579 | | bool isMoveConstructor(unsigned &TypeQuals) const; |
2580 | | |
2581 | | /// Determine whether this constructor is a move constructor |
2582 | | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2583 | 752k | bool isMoveConstructor() const { |
2584 | 752k | unsigned TypeQuals = 0; |
2585 | 752k | return isMoveConstructor(TypeQuals); |
2586 | 752k | } |
2587 | | |
2588 | | /// Determine whether this is a copy or move constructor. |
2589 | | /// |
2590 | | /// \param TypeQuals Will be set to the type qualifiers on the reference |
2591 | | /// parameter, if in fact this is a copy or move constructor. |
2592 | | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
2593 | | |
2594 | | /// Determine whether this a copy or move constructor. |
2595 | 1.07M | bool isCopyOrMoveConstructor() const { |
2596 | 1.07M | unsigned Quals; |
2597 | 1.07M | return isCopyOrMoveConstructor(Quals); |
2598 | 1.07M | } |
2599 | | |
2600 | | /// Whether this constructor is a |
2601 | | /// converting constructor (C++ [class.conv.ctor]), which can be |
2602 | | /// used for user-defined conversions. |
2603 | | bool isConvertingConstructor(bool AllowExplicit) const; |
2604 | | |
2605 | | /// Determine whether this is a member template specialization that |
2606 | | /// would copy the object to itself. Such constructors are never used to copy |
2607 | | /// an object. |
2608 | | bool isSpecializationCopyingObject() const; |
2609 | | |
2610 | | /// Determine whether this is an implicit constructor synthesized to |
2611 | | /// model a call to a constructor inherited from a base class. |
2612 | 1.88M | bool isInheritingConstructor() const { |
2613 | 1.88M | return CXXConstructorDeclBits.IsInheritingConstructor; |
2614 | 1.88M | } |
2615 | | |
2616 | | /// State that this is an implicit constructor synthesized to |
2617 | | /// model a call to a constructor inherited from a base class. |
2618 | 1.03M | void setInheritingConstructor(bool isIC = true) { |
2619 | 1.03M | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
2620 | 1.03M | } |
2621 | | |
2622 | | /// Get the constructor that this inheriting constructor is based on. |
2623 | 917k | InheritedConstructor getInheritedConstructor() const { |
2624 | 917k | return isInheritingConstructor() ? |
2625 | 912k | *getTrailingObjects<InheritedConstructor>()5.19k : InheritedConstructor(); |
2626 | 917k | } |
2627 | | |
2628 | 31.2M | CXXConstructorDecl *getCanonicalDecl() override { |
2629 | 31.2M | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
2630 | 31.2M | } |
2631 | 1.08M | const CXXConstructorDecl *getCanonicalDecl() const { |
2632 | 1.08M | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
2633 | 1.08M | } |
2634 | | |
2635 | | // Implement isa/cast/dyncast/etc. |
2636 | 148M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2637 | 148M | static bool classofKind(Kind K) { return K == CXXConstructor; } |
2638 | | }; |
2639 | | |
2640 | | /// Represents a C++ destructor within a class. |
2641 | | /// |
2642 | | /// For example: |
2643 | | /// |
2644 | | /// \code |
2645 | | /// class X { |
2646 | | /// public: |
2647 | | /// ~X(); // represented by a CXXDestructorDecl. |
2648 | | /// }; |
2649 | | /// \endcode |
2650 | | class CXXDestructorDecl : public CXXMethodDecl { |
2651 | | friend class ASTDeclReader; |
2652 | | friend class ASTDeclWriter; |
2653 | | |
2654 | | // FIXME: Don't allocate storage for these except in the first declaration |
2655 | | // of a virtual destructor. |
2656 | | FunctionDecl *OperatorDelete = nullptr; |
2657 | | Expr *OperatorDeleteThisArg = nullptr; |
2658 | | |
2659 | | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2660 | | const DeclarationNameInfo &NameInfo, QualType T, |
2661 | | TypeSourceInfo *TInfo, bool isInline, |
2662 | | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2663 | | Expr *TrailingRequiresClause = nullptr) |
2664 | | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2665 | | SC_None, isInline, ConstexprKind, SourceLocation(), |
2666 | 166k | TrailingRequiresClause) { |
2667 | 166k | setImplicit(isImplicitlyDeclared); |
2668 | 166k | } |
2669 | | |
2670 | | void anchor() override; |
2671 | | |
2672 | | public: |
2673 | | static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
2674 | | SourceLocation StartLoc, |
2675 | | const DeclarationNameInfo &NameInfo, |
2676 | | QualType T, TypeSourceInfo *TInfo, |
2677 | | bool isInline, bool isImplicitlyDeclared, |
2678 | | ConstexprSpecKind ConstexprKind, |
2679 | | Expr *TrailingRequiresClause = nullptr); |
2680 | | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
2681 | | |
2682 | | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
2683 | | |
2684 | 44.5k | const FunctionDecl *getOperatorDelete() const { |
2685 | 44.5k | return getCanonicalDecl()->OperatorDelete; |
2686 | 44.5k | } |
2687 | | |
2688 | 11.0k | Expr *getOperatorDeleteThisArg() const { |
2689 | 11.0k | return getCanonicalDecl()->OperatorDeleteThisArg; |
2690 | 11.0k | } |
2691 | | |
2692 | 7.52M | CXXDestructorDecl *getCanonicalDecl() override { |
2693 | 7.52M | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
2694 | 7.52M | } |
2695 | 55.5k | const CXXDestructorDecl *getCanonicalDecl() const { |
2696 | 55.5k | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
2697 | 55.5k | } |
2698 | | |
2699 | | // Implement isa/cast/dyncast/etc. |
2700 | 110M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2701 | 110M | static bool classofKind(Kind K) { return K == CXXDestructor; } |
2702 | | }; |
2703 | | |
2704 | | /// Represents a C++ conversion function within a class. |
2705 | | /// |
2706 | | /// For example: |
2707 | | /// |
2708 | | /// \code |
2709 | | /// class X { |
2710 | | /// public: |
2711 | | /// operator bool(); |
2712 | | /// }; |
2713 | | /// \endcode |
2714 | | class CXXConversionDecl : public CXXMethodDecl { |
2715 | | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2716 | | const DeclarationNameInfo &NameInfo, QualType T, |
2717 | | TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, |
2718 | | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
2719 | | Expr *TrailingRequiresClause = nullptr) |
2720 | | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
2721 | | SC_None, isInline, ConstexprKind, EndLocation, |
2722 | | TrailingRequiresClause), |
2723 | 38.2k | ExplicitSpec(ES) {} |
2724 | | void anchor() override; |
2725 | | |
2726 | | ExplicitSpecifier ExplicitSpec; |
2727 | | |
2728 | | public: |
2729 | | friend class ASTDeclReader; |
2730 | | friend class ASTDeclWriter; |
2731 | | |
2732 | | static CXXConversionDecl * |
2733 | | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2734 | | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2735 | | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2736 | | SourceLocation EndLocation, Expr *TrailingRequiresClause = nullptr); |
2737 | | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2738 | | |
2739 | 21.0k | ExplicitSpecifier getExplicitSpecifier() { |
2740 | 21.0k | return getCanonicalDecl()->ExplicitSpec; |
2741 | 21.0k | } |
2742 | | |
2743 | 1.05M | const ExplicitSpecifier getExplicitSpecifier() const { |
2744 | 1.05M | return getCanonicalDecl()->ExplicitSpec; |
2745 | 1.05M | } |
2746 | | |
2747 | | /// Return true if the declartion is already resolved to be explicit. |
2748 | 1.05M | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2749 | 4.09k | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2750 | | |
2751 | | /// Returns the type that this conversion function is converting to. |
2752 | 1.30M | QualType getConversionType() const { |
2753 | 1.30M | return getType()->castAs<FunctionType>()->getReturnType(); |
2754 | 1.30M | } |
2755 | | |
2756 | | /// Determine whether this conversion function is a conversion from |
2757 | | /// a lambda closure type to a block pointer. |
2758 | | bool isLambdaToBlockPointerConversion() const; |
2759 | | |
2760 | 3.69M | CXXConversionDecl *getCanonicalDecl() override { |
2761 | 3.69M | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
2762 | 3.69M | } |
2763 | 1.05M | const CXXConversionDecl *getCanonicalDecl() const { |
2764 | 1.05M | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
2765 | 1.05M | } |
2766 | | |
2767 | | // Implement isa/cast/dyncast/etc. |
2768 | 14.4M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2769 | 14.4M | static bool classofKind(Kind K) { return K == CXXConversion; } |
2770 | | }; |
2771 | | |
2772 | | /// Represents a linkage specification. |
2773 | | /// |
2774 | | /// For example: |
2775 | | /// \code |
2776 | | /// extern "C" void foo(); |
2777 | | /// \endcode |
2778 | | class LinkageSpecDecl : public Decl, public DeclContext { |
2779 | | virtual void anchor(); |
2780 | | // This class stores some data in DeclContext::LinkageSpecDeclBits to save |
2781 | | // some space. Use the provided accessors to access it. |
2782 | | public: |
2783 | | /// Represents the language in a linkage specification. |
2784 | | /// |
2785 | | /// The values are part of the serialization ABI for |
2786 | | /// ASTs and cannot be changed without altering that ABI. |
2787 | | enum LanguageIDs { lang_c = 1, lang_cxx = 2 }; |
2788 | | |
2789 | | private: |
2790 | | /// The source location for the extern keyword. |
2791 | | SourceLocation ExternLoc; |
2792 | | |
2793 | | /// The source location for the right brace (if valid). |
2794 | | SourceLocation RBraceLoc; |
2795 | | |
2796 | | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2797 | | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
2798 | | |
2799 | | public: |
2800 | | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
2801 | | SourceLocation ExternLoc, |
2802 | | SourceLocation LangLoc, LanguageIDs Lang, |
2803 | | bool HasBraces); |
2804 | | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2805 | | |
2806 | | /// Return the language specified by this linkage specification. |
2807 | 6.62M | LanguageIDs getLanguage() const { |
2808 | 6.62M | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
2809 | 6.62M | } |
2810 | | |
2811 | | /// Set the language specified by this linkage specification. |
2812 | 279k | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
2813 | | |
2814 | | /// Determines whether this linkage specification had braces in |
2815 | | /// its syntactic form. |
2816 | 229k | bool hasBraces() const { |
2817 | 229k | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces); |
2818 | 229k | return LinkageSpecDeclBits.HasBraces; |
2819 | 229k | } |
2820 | | |
2821 | 26.3k | SourceLocation getExternLoc() const { return ExternLoc; } |
2822 | 55.5k | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
2823 | 22.7k | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
2824 | 88.8k | void setRBraceLoc(SourceLocation L) { |
2825 | 88.8k | RBraceLoc = L; |
2826 | 88.8k | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
2827 | 88.8k | } |
2828 | | |
2829 | 31.4k | SourceLocation getEndLoc() const LLVM_READONLY { |
2830 | 31.4k | if (hasBraces()) |
2831 | 31.3k | return getRBraceLoc(); |
2832 | | // No braces: get the end location of the (only) declaration in context |
2833 | | // (if present). |
2834 | 51 | return decls_empty() ? getLocation()0 : decls_begin()->getEndLoc(); |
2835 | 51 | } |
2836 | | |
2837 | 31.4k | SourceRange getSourceRange() const override LLVM_READONLY { |
2838 | 31.4k | return SourceRange(ExternLoc, getEndLoc()); |
2839 | 31.4k | } |
2840 | | |
2841 | 767k | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2842 | 38.0M | static bool classofKind(Kind K) { return K == LinkageSpec; } |
2843 | | |
2844 | 12.6k | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
2845 | 12.6k | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
2846 | 12.6k | } |
2847 | | |
2848 | 0 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
2849 | 0 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
2850 | 0 | } |
2851 | | }; |
2852 | | |
2853 | | /// Represents C++ using-directive. |
2854 | | /// |
2855 | | /// For example: |
2856 | | /// \code |
2857 | | /// using namespace std; |
2858 | | /// \endcode |
2859 | | /// |
2860 | | /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide |
2861 | | /// artificial names for all using-directives in order to store |
2862 | | /// them in DeclContext effectively. |
2863 | | class UsingDirectiveDecl : public NamedDecl { |
2864 | | /// The location of the \c using keyword. |
2865 | | SourceLocation UsingLoc; |
2866 | | |
2867 | | /// The location of the \c namespace keyword. |
2868 | | SourceLocation NamespaceLoc; |
2869 | | |
2870 | | /// The nested-name-specifier that precedes the namespace. |
2871 | | NestedNameSpecifierLoc QualifierLoc; |
2872 | | |
2873 | | /// The namespace nominated by this using-directive. |
2874 | | NamedDecl *NominatedNamespace; |
2875 | | |
2876 | | /// Enclosing context containing both using-directive and nominated |
2877 | | /// namespace. |
2878 | | DeclContext *CommonAncestor; |
2879 | | |
2880 | | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
2881 | | SourceLocation NamespcLoc, |
2882 | | NestedNameSpecifierLoc QualifierLoc, |
2883 | | SourceLocation IdentLoc, |
2884 | | NamedDecl *Nominated, |
2885 | | DeclContext *CommonAncestor) |
2886 | | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
2887 | | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
2888 | 5.11k | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
2889 | | |
2890 | | /// Returns special DeclarationName used by using-directives. |
2891 | | /// |
2892 | | /// This is only used by DeclContext for storing UsingDirectiveDecls in |
2893 | | /// its lookup structure. |
2894 | 54.7M | static DeclarationName getName() { |
2895 | 54.7M | return DeclarationName::getUsingDirectiveName(); |
2896 | 54.7M | } |
2897 | | |
2898 | | void anchor() override; |
2899 | | |
2900 | | public: |
2901 | | friend class ASTDeclReader; |
2902 | | |
2903 | | // Friend for getUsingDirectiveName. |
2904 | | friend class DeclContext; |
2905 | | |
2906 | | /// Retrieve the nested-name-specifier that qualifies the |
2907 | | /// name of the namespace, with source-location information. |
2908 | 1.19k | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
2909 | | |
2910 | | /// Retrieve the nested-name-specifier that qualifies the |
2911 | | /// name of the namespace. |
2912 | 8 | NestedNameSpecifier *getQualifier() const { |
2913 | 8 | return QualifierLoc.getNestedNameSpecifier(); |
2914 | 8 | } |
2915 | | |
2916 | 10 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
2917 | 6 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
2918 | 6 | return NominatedNamespace; |
2919 | 6 | } |
2920 | | |
2921 | | /// Returns the namespace nominated by this using-directive. |
2922 | | NamespaceDecl *getNominatedNamespace(); |
2923 | | |
2924 | 824 | const NamespaceDecl *getNominatedNamespace() const { |
2925 | 824 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
2926 | 824 | } |
2927 | | |
2928 | | /// Returns the common ancestor context of this using-directive and |
2929 | | /// its nominated namespace. |
2930 | 644 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
2931 | 0 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
2932 | | |
2933 | | /// Return the location of the \c using keyword. |
2934 | 267 | SourceLocation getUsingLoc() const { return UsingLoc; } |
2935 | | |
2936 | | // FIXME: Could omit 'Key' in name. |
2937 | | /// Returns the location of the \c namespace keyword. |
2938 | 281 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
2939 | | |
2940 | | /// Returns the location of this using declaration's identifier. |
2941 | 140 | SourceLocation getIdentLocation() const { return getLocation(); } |
2942 | | |
2943 | | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
2944 | | SourceLocation UsingLoc, |
2945 | | SourceLocation NamespaceLoc, |
2946 | | NestedNameSpecifierLoc QualifierLoc, |
2947 | | SourceLocation IdentLoc, |
2948 | | NamedDecl *Nominated, |
2949 | | DeclContext *CommonAncestor); |
2950 | | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2951 | | |
2952 | 74 | SourceRange getSourceRange() const override LLVM_READONLY { |
2953 | 74 | return SourceRange(UsingLoc, getLocation()); |
2954 | 74 | } |
2955 | | |
2956 | 17.2M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2957 | 17.2M | static bool classofKind(Kind K) { return K == UsingDirective; } |
2958 | | }; |
2959 | | |
2960 | | /// Represents a C++ namespace alias. |
2961 | | /// |
2962 | | /// For example: |
2963 | | /// |
2964 | | /// \code |
2965 | | /// namespace Foo = Bar; |
2966 | | /// \endcode |
2967 | | class NamespaceAliasDecl : public NamedDecl, |
2968 | | public Redeclarable<NamespaceAliasDecl> { |
2969 | | friend class ASTDeclReader; |
2970 | | |
2971 | | /// The location of the \c namespace keyword. |
2972 | | SourceLocation NamespaceLoc; |
2973 | | |
2974 | | /// The location of the namespace's identifier. |
2975 | | /// |
2976 | | /// This is accessed by TargetNameLoc. |
2977 | | SourceLocation IdentLoc; |
2978 | | |
2979 | | /// The nested-name-specifier that precedes the namespace. |
2980 | | NestedNameSpecifierLoc QualifierLoc; |
2981 | | |
2982 | | /// The Decl that this alias points to, either a NamespaceDecl or |
2983 | | /// a NamespaceAliasDecl. |
2984 | | NamedDecl *Namespace; |
2985 | | |
2986 | | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
2987 | | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
2988 | | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
2989 | | SourceLocation IdentLoc, NamedDecl *Namespace) |
2990 | | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
2991 | | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
2992 | 345 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
2993 | | |
2994 | | void anchor() override; |
2995 | | |
2996 | | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
2997 | | |
2998 | | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
2999 | | NamespaceAliasDecl *getPreviousDeclImpl() override; |
3000 | | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
3001 | | |
3002 | | public: |
3003 | | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
3004 | | SourceLocation NamespaceLoc, |
3005 | | SourceLocation AliasLoc, |
3006 | | IdentifierInfo *Alias, |
3007 | | NestedNameSpecifierLoc QualifierLoc, |
3008 | | SourceLocation IdentLoc, |
3009 | | NamedDecl *Namespace); |
3010 | | |
3011 | | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3012 | | |
3013 | | using redecl_range = redeclarable_base::redecl_range; |
3014 | | using redecl_iterator = redeclarable_base::redecl_iterator; |
3015 | | |
3016 | | using redeclarable_base::redecls_begin; |
3017 | | using redeclarable_base::redecls_end; |
3018 | | using redeclarable_base::redecls; |
3019 | | using redeclarable_base::getPreviousDecl; |
3020 | | using redeclarable_base::getMostRecentDecl; |
3021 | | |
3022 | 269 | NamespaceAliasDecl *getCanonicalDecl() override { |
3023 | 269 | return getFirstDecl(); |
3024 | 269 | } |
3025 | 0 | const NamespaceAliasDecl *getCanonicalDecl() const { |
3026 | 0 | return getFirstDecl(); |
3027 | 0 | } |
3028 | | |
3029 | | /// Retrieve the nested-name-specifier that qualifies the |
3030 | | /// name of the namespace, with source-location information. |
3031 | 296 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3032 | | |
3033 | | /// Retrieve the nested-name-specifier that qualifies the |
3034 | | /// name of the namespace. |
3035 | 7 | NestedNameSpecifier *getQualifier() const { |
3036 | 7 | return QualifierLoc.getNestedNameSpecifier(); |
3037 | 7 | } |
3038 | | |
3039 | | /// Retrieve the namespace declaration aliased by this directive. |
3040 | 6.45k | NamespaceDecl *getNamespace() { |
3041 | 6.45k | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
3042 | 145 | return AD->getNamespace(); |
3043 | | |
3044 | 6.31k | return cast<NamespaceDecl>(Namespace); |
3045 | 6.31k | } |
3046 | | |
3047 | 14 | const NamespaceDecl *getNamespace() const { |
3048 | 14 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
3049 | 14 | } |
3050 | | |
3051 | | /// Returns the location of the alias name, i.e. 'foo' in |
3052 | | /// "namespace foo = ns::bar;". |
3053 | 5 | SourceLocation getAliasLoc() const { return getLocation(); } |
3054 | | |
3055 | | /// Returns the location of the \c namespace keyword. |
3056 | 18 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
3057 | | |
3058 | | /// Returns the location of the identifier in the named namespace. |
3059 | 29 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
3060 | | |
3061 | | /// Retrieve the namespace that this alias refers to, which |
3062 | | /// may either be a NamespaceDecl or a NamespaceAliasDecl. |
3063 | 101 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
3064 | | |
3065 | 47 | SourceRange getSourceRange() const override LLVM_READONLY { |
3066 | 47 | return SourceRange(NamespaceLoc, IdentLoc); |
3067 | 47 | } |
3068 | | |
3069 | 35.3M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3070 | 35.3M | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
3071 | | }; |
3072 | | |
3073 | | /// Implicit declaration of a temporary that was materialized by |
3074 | | /// a MaterializeTemporaryExpr and lifetime-extended by a declaration |
3075 | | class LifetimeExtendedTemporaryDecl final |
3076 | | : public Decl, |
3077 | | public Mergeable<LifetimeExtendedTemporaryDecl> { |
3078 | | friend class MaterializeTemporaryExpr; |
3079 | | friend class ASTDeclReader; |
3080 | | |
3081 | | Stmt *ExprWithTemporary = nullptr; |
3082 | | |
3083 | | /// The declaration which lifetime-extended this reference, if any. |
3084 | | /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. |
3085 | | ValueDecl *ExtendingDecl = nullptr; |
3086 | | unsigned ManglingNumber; |
3087 | | |
3088 | | mutable APValue *Value = nullptr; |
3089 | | |
3090 | | virtual void anchor(); |
3091 | | |
3092 | | LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling) |
3093 | | : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(), |
3094 | | EDecl->getLocation()), |
3095 | | ExprWithTemporary(Temp), ExtendingDecl(EDecl), |
3096 | 2.19k | ManglingNumber(Mangling) {} |
3097 | | |
3098 | | LifetimeExtendedTemporaryDecl(EmptyShell) |
3099 | 23 | : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {} |
3100 | | |
3101 | | public: |
3102 | | static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec, |
3103 | 2.19k | unsigned Mangling) { |
3104 | 2.19k | return new (EDec->getASTContext(), EDec->getDeclContext()) |
3105 | 2.19k | LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling); |
3106 | 2.19k | } |
3107 | | static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C, |
3108 | 23 | unsigned ID) { |
3109 | 23 | return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{}); |
3110 | 23 | } |
3111 | | |
3112 | 1.70k | ValueDecl *getExtendingDecl() { return ExtendingDecl; } |
3113 | 10.5k | const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } |
3114 | | |
3115 | | /// Retrieve the storage duration for the materialized temporary. |
3116 | | StorageDuration getStorageDuration() const; |
3117 | | |
3118 | | /// Retrieve the expression to which the temporary materialization conversion |
3119 | | /// was applied. This isn't necessarily the initializer of the temporary due |
3120 | | /// to the C++98 delayed materialization rules, but |
3121 | | /// skipRValueSubobjectAdjustments can be used to find said initializer within |
3122 | | /// the subexpression. |
3123 | 26.2k | Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); } |
3124 | 0 | const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); } |
3125 | | |
3126 | 259 | unsigned getManglingNumber() const { return ManglingNumber; } |
3127 | | |
3128 | | /// Get the storage for the constant value of a materialized temporary |
3129 | | /// of static storage duration. |
3130 | | APValue *getOrCreateValue(bool MayCreate) const; |
3131 | | |
3132 | 39 | APValue *getValue() const { return Value; } |
3133 | | |
3134 | | // Iterators |
3135 | 6.19k | Stmt::child_range childrenExpr() { |
3136 | 6.19k | return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3137 | 6.19k | } |
3138 | | |
3139 | 0 | Stmt::const_child_range childrenExpr() const { |
3140 | 0 | return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3141 | 0 | } |
3142 | | |
3143 | 36.1M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3144 | 36.1M | static bool classofKind(Kind K) { |
3145 | 36.1M | return K == Decl::LifetimeExtendedTemporary; |
3146 | 36.1M | } |
3147 | | }; |
3148 | | |
3149 | | /// Represents a shadow declaration introduced into a scope by a |
3150 | | /// (resolved) using declaration. |
3151 | | /// |
3152 | | /// For example, |
3153 | | /// \code |
3154 | | /// namespace A { |
3155 | | /// void foo(); |
3156 | | /// } |
3157 | | /// namespace B { |
3158 | | /// using A::foo; // <- a UsingDecl |
3159 | | /// // Also creates a UsingShadowDecl for A::foo() in B |
3160 | | /// } |
3161 | | /// \endcode |
3162 | | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
3163 | | friend class UsingDecl; |
3164 | | |
3165 | | /// The referenced declaration. |
3166 | | NamedDecl *Underlying = nullptr; |
3167 | | |
3168 | | /// The using declaration which introduced this decl or the next using |
3169 | | /// shadow declaration contained in the aforementioned using declaration. |
3170 | | NamedDecl *UsingOrNextShadow = nullptr; |
3171 | | |
3172 | | void anchor() override; |
3173 | | |
3174 | | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
3175 | | |
3176 | 181k | UsingShadowDecl *getNextRedeclarationImpl() override { |
3177 | 181k | return getNextRedeclaration(); |
3178 | 181k | } |
3179 | | |
3180 | 521 | UsingShadowDecl *getPreviousDeclImpl() override { |
3181 | 521 | return getPreviousDecl(); |
3182 | 521 | } |
3183 | | |
3184 | 383k | UsingShadowDecl *getMostRecentDeclImpl() override { |
3185 | 383k | return getMostRecentDecl(); |
3186 | 383k | } |
3187 | | |
3188 | | protected: |
3189 | | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3190 | | UsingDecl *Using, NamedDecl *Target); |
3191 | | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
3192 | | |
3193 | | public: |
3194 | | friend class ASTDeclReader; |
3195 | | friend class ASTDeclWriter; |
3196 | | |
3197 | | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3198 | | SourceLocation Loc, UsingDecl *Using, |
3199 | 172k | NamedDecl *Target) { |
3200 | 172k | return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target); |
3201 | 172k | } |
3202 | | |
3203 | | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3204 | | |
3205 | | using redecl_range = redeclarable_base::redecl_range; |
3206 | | using redecl_iterator = redeclarable_base::redecl_iterator; |
3207 | | |
3208 | | using redeclarable_base::redecls_begin; |
3209 | | using redeclarable_base::redecls_end; |
3210 | | using redeclarable_base::redecls; |
3211 | | using redeclarable_base::getPreviousDecl; |
3212 | | using redeclarable_base::getMostRecentDecl; |
3213 | | using redeclarable_base::isFirstDecl; |
3214 | | |
3215 | 1.01M | UsingShadowDecl *getCanonicalDecl() override { |
3216 | 1.01M | return getFirstDecl(); |
3217 | 1.01M | } |
3218 | 0 | const UsingShadowDecl *getCanonicalDecl() const { |
3219 | 0 | return getFirstDecl(); |
3220 | 0 | } |
3221 | | |
3222 | | /// Gets the underlying declaration which has been brought into the |
3223 | | /// local scope. |
3224 | 1.51M | NamedDecl *getTargetDecl() const { return Underlying; } |
3225 | | |
3226 | | /// Sets the underlying declaration which has been brought into the |
3227 | | /// local scope. |
3228 | 174k | void setTargetDecl(NamedDecl *ND) { |
3229 | 174k | assert(ND && "Target decl is null!"); |
3230 | 174k | Underlying = ND; |
3231 | | // A UsingShadowDecl is never a friend or local extern declaration, even |
3232 | | // if it is a shadow declaration for one. |
3233 | 174k | IdentifierNamespace = |
3234 | 174k | ND->getIdentifierNamespace() & |
3235 | 174k | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
3236 | 174k | } |
3237 | | |
3238 | | /// Gets the using declaration to which this declaration is tied. |
3239 | | UsingDecl *getUsingDecl() const; |
3240 | | |
3241 | | /// The next using shadow declaration contained in the shadow decl |
3242 | | /// chain of the using declaration which introduced this decl. |
3243 | 428k | UsingShadowDecl *getNextUsingShadowDecl() const { |
3244 | 428k | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
3245 | 428k | } |
3246 | | |
3247 | 72.9M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3248 | 72.9M | static bool classofKind(Kind K) { |
3249 | 72.9M | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow69.2M ; |
3250 | 72.9M | } |
3251 | | }; |
3252 | | |
3253 | | /// Represents a shadow constructor declaration introduced into a |
3254 | | /// class by a C++11 using-declaration that names a constructor. |
3255 | | /// |
3256 | | /// For example: |
3257 | | /// \code |
3258 | | /// struct Base { Base(int); }; |
3259 | | /// struct Derived { |
3260 | | /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl |
3261 | | /// }; |
3262 | | /// \endcode |
3263 | | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
3264 | | /// If this constructor using declaration inherted the constructor |
3265 | | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3266 | | /// in the named direct base class from which the declaration was inherited. |
3267 | | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
3268 | | |
3269 | | /// If this constructor using declaration inherted the constructor |
3270 | | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3271 | | /// that will be used to construct the unique direct or virtual base class |
3272 | | /// that receives the constructor arguments. |
3273 | | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
3274 | | |
3275 | | /// \c true if the constructor ultimately named by this using shadow |
3276 | | /// declaration is within a virtual base class subobject of the class that |
3277 | | /// contains this declaration. |
3278 | | unsigned IsVirtual : 1; |
3279 | | |
3280 | | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3281 | | UsingDecl *Using, NamedDecl *Target, |
3282 | | bool TargetInVirtualBase) |
3283 | | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using, |
3284 | | Target->getUnderlyingDecl()), |
3285 | | NominatedBaseClassShadowDecl( |
3286 | | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
3287 | | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
3288 | 2.14k | IsVirtual(TargetInVirtualBase) { |
3289 | | // If we found a constructor that chains to a constructor for a virtual |
3290 | | // base, we should directly call that virtual base constructor instead. |
3291 | | // FIXME: This logic belongs in Sema. |
3292 | 2.14k | if (NominatedBaseClassShadowDecl && |
3293 | 801 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
3294 | 79 | ConstructedBaseClassShadowDecl = |
3295 | 79 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
3296 | 79 | IsVirtual = true; |
3297 | 79 | } |
3298 | 2.14k | } |
3299 | | |
3300 | | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
3301 | 68 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
3302 | | |
3303 | | void anchor() override; |
3304 | | |
3305 | | public: |
3306 | | friend class ASTDeclReader; |
3307 | | friend class ASTDeclWriter; |
3308 | | |
3309 | | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3310 | | SourceLocation Loc, |
3311 | | UsingDecl *Using, NamedDecl *Target, |
3312 | | bool IsVirtual); |
3313 | | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
3314 | | unsigned ID); |
3315 | | |
3316 | | /// Returns the parent of this using shadow declaration, which |
3317 | | /// is the class in which this is declared. |
3318 | | //@{ |
3319 | 0 | const CXXRecordDecl *getParent() const { |
3320 | 0 | return cast<CXXRecordDecl>(getDeclContext()); |
3321 | 0 | } |
3322 | 4.79k | CXXRecordDecl *getParent() { |
3323 | 4.79k | return cast<CXXRecordDecl>(getDeclContext()); |
3324 | 4.79k | } |
3325 | | //@} |
3326 | | |
3327 | | /// Get the inheriting constructor declaration for the direct base |
3328 | | /// class from which this using shadow declaration was inherited, if there is |
3329 | | /// one. This can be different for each redeclaration of the same shadow decl. |
3330 | 975 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
3331 | 975 | return NominatedBaseClassShadowDecl; |
3332 | 975 | } |
3333 | | |
3334 | | /// Get the inheriting constructor declaration for the base class |
3335 | | /// for which we don't have an explicit initializer, if there is one. |
3336 | 159 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
3337 | 159 | return ConstructedBaseClassShadowDecl; |
3338 | 159 | } |
3339 | | |
3340 | | /// Get the base class that was named in the using declaration. This |
3341 | | /// can be different for each redeclaration of this same shadow decl. |
3342 | | CXXRecordDecl *getNominatedBaseClass() const; |
3343 | | |
3344 | | /// Get the base class whose constructor or constructor shadow |
3345 | | /// declaration is passed the constructor arguments. |
3346 | 927 | CXXRecordDecl *getConstructedBaseClass() const { |
3347 | 927 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
3348 | 316 | ? ConstructedBaseClassShadowDecl |
3349 | 611 | : getTargetDecl()) |
3350 | 927 | ->getDeclContext()); |
3351 | 927 | } |
3352 | | |
3353 | | /// Returns \c true if the constructed base class is a virtual base |
3354 | | /// class subobject of this declaration's class. |
3355 | 2.99k | bool constructsVirtualBase() const { |
3356 | 2.99k | return IsVirtual; |
3357 | 2.99k | } |
3358 | | |
3359 | 2.76M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3360 | 2.76M | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
3361 | | }; |
3362 | | |
3363 | | /// Represents a C++ using-declaration. |
3364 | | /// |
3365 | | /// For example: |
3366 | | /// \code |
3367 | | /// using someNameSpace::someIdentifier; |
3368 | | /// \endcode |
3369 | | class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> { |
3370 | | /// The source location of the 'using' keyword itself. |
3371 | | SourceLocation UsingLocation; |
3372 | | |
3373 | | /// The nested-name-specifier that precedes the name. |
3374 | | NestedNameSpecifierLoc QualifierLoc; |
3375 | | |
3376 | | /// Provides source/type location info for the declaration name |
3377 | | /// embedded in the ValueDecl base class. |
3378 | | DeclarationNameLoc DNLoc; |
3379 | | |
3380 | | /// The first shadow declaration of the shadow decl chain associated |
3381 | | /// with this using declaration. |
3382 | | /// |
3383 | | /// The bool member of the pair store whether this decl has the \c typename |
3384 | | /// keyword. |
3385 | | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
3386 | | |
3387 | | UsingDecl(DeclContext *DC, SourceLocation UL, |
3388 | | NestedNameSpecifierLoc QualifierLoc, |
3389 | | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
3390 | | : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
3391 | | UsingLocation(UL), QualifierLoc(QualifierLoc), |
3392 | 133k | DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) { |
3393 | 133k | } |
3394 | | |
3395 | | void anchor() override; |
3396 | | |
3397 | | public: |
3398 | | friend class ASTDeclReader; |
3399 | | friend class ASTDeclWriter; |
3400 | | |
3401 | | /// Return the source location of the 'using' keyword. |
3402 | 8.06k | SourceLocation getUsingLoc() const { return UsingLocation; } |
3403 | | |
3404 | | /// Set the source location of the 'using' keyword. |
3405 | 2.24k | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3406 | | |
3407 | | /// Retrieve the nested-name-specifier that qualifies the name, |
3408 | | /// with source-location information. |
3409 | 12.9k | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3410 | | |
3411 | | /// Retrieve the nested-name-specifier that qualifies the name. |
3412 | 16.1k | NestedNameSpecifier *getQualifier() const { |
3413 | 16.1k | return QualifierLoc.getNestedNameSpecifier(); |
3414 | 16.1k | } |
3415 | | |
3416 | 8.93k | DeclarationNameInfo getNameInfo() const { |
3417 | 8.93k | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3418 | 8.93k | } |
3419 | | |
3420 | | /// Return true if it is a C++03 access declaration (no 'using'). |
3421 | 497 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3422 | | |
3423 | | /// Return true if the using declaration has 'typename'. |
3424 | 9.04k | bool hasTypename() const { return FirstUsingShadow.getInt(); } |
3425 | | |
3426 | | /// Sets whether the using declaration has 'typename'. |
3427 | 2.24k | void setTypename(bool TN) { FirstUsingShadow.setInt(TN); } |
3428 | | |
3429 | | /// Iterates through the using shadow declarations associated with |
3430 | | /// this using declaration. |
3431 | | class shadow_iterator { |
3432 | | /// The current using shadow declaration. |
3433 | | UsingShadowDecl *Current = nullptr; |
3434 | | |
3435 | | public: |
3436 | | using value_type = UsingShadowDecl *; |
3437 | | using reference = UsingShadowDecl *; |
3438 | | using pointer = UsingShadowDecl *; |
3439 | | using iterator_category = std::forward_iterator_tag; |
3440 | | using difference_type = std::ptrdiff_t; |
3441 | | |
3442 | 457k | shadow_iterator() = default; |
3443 | 389k | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
3444 | | |
3445 | 415k | reference operator*() const { return Current; } |
3446 | 0 | pointer operator->() const { return Current; } |
3447 | | |
3448 | 428k | shadow_iterator& operator++() { |
3449 | 428k | Current = Current->getNextUsingShadowDecl(); |
3450 | 428k | return *this; |
3451 | 428k | } |
3452 | | |
3453 | 0 | shadow_iterator operator++(int) { |
3454 | 0 | shadow_iterator tmp(*this); |
3455 | 0 | ++(*this); |
3456 | 0 | return tmp; |
3457 | 0 | } |
3458 | | |
3459 | 174k | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
3460 | 174k | return x.Current == y.Current; |
3461 | 174k | } |
3462 | 712k | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
3463 | 712k | return x.Current != y.Current; |
3464 | 712k | } |
3465 | | }; |
3466 | | |
3467 | | using shadow_range = llvm::iterator_range<shadow_iterator>; |
3468 | | |
3469 | 2.16k | shadow_range shadows() const { |
3470 | 2.16k | return shadow_range(shadow_begin(), shadow_end()); |
3471 | 2.16k | } |
3472 | | |
3473 | 389k | shadow_iterator shadow_begin() const { |
3474 | 389k | return shadow_iterator(FirstUsingShadow.getPointer()); |
3475 | 389k | } |
3476 | | |
3477 | 457k | shadow_iterator shadow_end() const { return shadow_iterator(); } |
3478 | | |
3479 | | /// Return the number of shadowed declarations associated with this |
3480 | | /// using declaration. |
3481 | 106k | unsigned shadow_size() const { |
3482 | 106k | return std::distance(shadow_begin(), shadow_end()); |
3483 | 106k | } |
3484 | | |
3485 | | void addShadowDecl(UsingShadowDecl *S); |
3486 | | void removeShadowDecl(UsingShadowDecl *S); |
3487 | | |
3488 | | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
3489 | | SourceLocation UsingL, |
3490 | | NestedNameSpecifierLoc QualifierLoc, |
3491 | | const DeclarationNameInfo &NameInfo, |
3492 | | bool HasTypenameKeyword); |
3493 | | |
3494 | | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3495 | | |
3496 | | SourceRange getSourceRange() const override LLVM_READONLY; |
3497 | | |
3498 | | /// Retrieves the canonical declaration of this declaration. |
3499 | 297k | UsingDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3500 | 0 | const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3501 | | |
3502 | 64.1M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3503 | 64.1M | static bool classofKind(Kind K) { return K == Using; } |
3504 | | }; |
3505 | | |
3506 | | /// Represents a pack of using declarations that a single |
3507 | | /// using-declarator pack-expanded into. |
3508 | | /// |
3509 | | /// \code |
3510 | | /// template<typename ...T> struct X : T... { |
3511 | | /// using T::operator()...; |
3512 | | /// using T::operator T...; |
3513 | | /// }; |
3514 | | /// \endcode |
3515 | | /// |
3516 | | /// In the second case above, the UsingPackDecl will have the name |
3517 | | /// 'operator T' (which contains an unexpanded pack), but the individual |
3518 | | /// UsingDecls and UsingShadowDecls will have more reasonable names. |
3519 | | class UsingPackDecl final |
3520 | | : public NamedDecl, public Mergeable<UsingPackDecl>, |
3521 | | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
3522 | | /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from |
3523 | | /// which this waas instantiated. |
3524 | | NamedDecl *InstantiatedFrom; |
3525 | | |
3526 | | /// The number of using-declarations created by this pack expansion. |
3527 | | unsigned NumExpansions; |
3528 | | |
3529 | | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
3530 | | ArrayRef<NamedDecl *> UsingDecls) |
3531 | | : NamedDecl(UsingPack, DC, |
3532 | | InstantiatedFrom ? InstantiatedFrom->getLocation() |
3533 | | : SourceLocation(), |
3534 | | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
3535 | | : DeclarationName()), |
3536 | 54 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
3537 | 54 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
3538 | 54 | getTrailingObjects<NamedDecl *>()); |
3539 | 54 | } |
3540 | | |
3541 | | void anchor() override; |
3542 | | |
3543 | | public: |
3544 | | friend class ASTDeclReader; |
3545 | | friend class ASTDeclWriter; |
3546 | | friend TrailingObjects; |
3547 | | |
3548 | | /// Get the using declaration from which this was instantiated. This will |
3549 | | /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl |
3550 | | /// that is a pack expansion. |
3551 | 38 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
3552 | | |
3553 | | /// Get the set of using declarations that this pack expanded into. Note that |
3554 | | /// some of these may still be unresolved. |
3555 | 45 | ArrayRef<NamedDecl *> expansions() const { |
3556 | 45 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
3557 | 45 | } |
3558 | | |
3559 | | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
3560 | | NamedDecl *InstantiatedFrom, |
3561 | | ArrayRef<NamedDecl *> UsingDecls); |
3562 | | |
3563 | | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3564 | | unsigned NumExpansions); |
3565 | | |
3566 | 0 | SourceRange getSourceRange() const override LLVM_READONLY { |
3567 | 0 | return InstantiatedFrom->getSourceRange(); |
3568 | 0 | } |
3569 | | |
3570 | 6 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3571 | 0 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3572 | | |
3573 | 799k | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3574 | 799k | static bool classofKind(Kind K) { return K == UsingPack; } |
3575 | | }; |
3576 | | |
3577 | | /// Represents a dependent using declaration which was not marked with |
3578 | | /// \c typename. |
3579 | | /// |
3580 | | /// Unlike non-dependent using declarations, these *only* bring through |
3581 | | /// non-types; otherwise they would break two-phase lookup. |
3582 | | /// |
3583 | | /// \code |
3584 | | /// template \<class T> class A : public Base<T> { |
3585 | | /// using Base<T>::foo; |
3586 | | /// }; |
3587 | | /// \endcode |
3588 | | class UnresolvedUsingValueDecl : public ValueDecl, |
3589 | | public Mergeable<UnresolvedUsingValueDecl> { |
3590 | | /// The source location of the 'using' keyword |
3591 | | SourceLocation UsingLocation; |
3592 | | |
3593 | | /// If this is a pack expansion, the location of the '...'. |
3594 | | SourceLocation EllipsisLoc; |
3595 | | |
3596 | | /// The nested-name-specifier that precedes the name. |
3597 | | NestedNameSpecifierLoc QualifierLoc; |
3598 | | |
3599 | | /// Provides source/type location info for the declaration name |
3600 | | /// embedded in the ValueDecl base class. |
3601 | | DeclarationNameLoc DNLoc; |
3602 | | |
3603 | | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
3604 | | SourceLocation UsingLoc, |
3605 | | NestedNameSpecifierLoc QualifierLoc, |
3606 | | const DeclarationNameInfo &NameInfo, |
3607 | | SourceLocation EllipsisLoc) |
3608 | | : ValueDecl(UnresolvedUsingValue, DC, |
3609 | | NameInfo.getLoc(), NameInfo.getName(), Ty), |
3610 | | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
3611 | 559 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
3612 | | |
3613 | | void anchor() override; |
3614 | | |
3615 | | public: |
3616 | | friend class ASTDeclReader; |
3617 | | friend class ASTDeclWriter; |
3618 | | |
3619 | | /// Returns the source location of the 'using' keyword. |
3620 | 605 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3621 | | |
3622 | | /// Set the source location of the 'using' keyword. |
3623 | 71 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3624 | | |
3625 | | /// Return true if it is a C++03 access declaration (no 'using'). |
3626 | 110 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3627 | | |
3628 | | /// Retrieve the nested-name-specifier that qualifies the name, |
3629 | | /// with source-location information. |
3630 | 909 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3631 | | |
3632 | | /// Retrieve the nested-name-specifier that qualifies the name. |
3633 | 231 | NestedNameSpecifier *getQualifier() const { |
3634 | 231 | return QualifierLoc.getNestedNameSpecifier(); |
3635 | 231 | } |
3636 | | |
3637 | 809 | DeclarationNameInfo getNameInfo() const { |
3638 | 809 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3639 | 809 | } |
3640 | | |
3641 | | /// Determine whether this is a pack expansion. |
3642 | 607 | bool isPackExpansion() const { |
3643 | 607 | return EllipsisLoc.isValid(); |
3644 | 607 | } |
3645 | | |
3646 | | /// Get the location of the ellipsis if this is a pack expansion. |
3647 | 1.02k | SourceLocation getEllipsisLoc() const { |
3648 | 1.02k | return EllipsisLoc; |
3649 | 1.02k | } |
3650 | | |
3651 | | static UnresolvedUsingValueDecl * |
3652 | | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3653 | | NestedNameSpecifierLoc QualifierLoc, |
3654 | | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
3655 | | |
3656 | | static UnresolvedUsingValueDecl * |
3657 | | CreateDeserialized(ASTContext &C, unsigned ID); |
3658 | | |
3659 | | SourceRange getSourceRange() const override LLVM_READONLY; |
3660 | | |
3661 | | /// Retrieves the canonical declaration of this declaration. |
3662 | 1.48k | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
3663 | 1.48k | return getFirstDecl(); |
3664 | 1.48k | } |
3665 | 0 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
3666 | 0 | return getFirstDecl(); |
3667 | 0 | } |
3668 | | |
3669 | 245M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3670 | 245M | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
3671 | | }; |
3672 | | |
3673 | | /// Represents a dependent using declaration which was marked with |
3674 | | /// \c typename. |
3675 | | /// |
3676 | | /// \code |
3677 | | /// template \<class T> class A : public Base<T> { |
3678 | | /// using typename Base<T>::foo; |
3679 | | /// }; |
3680 | | /// \endcode |
3681 | | /// |
3682 | | /// The type associated with an unresolved using typename decl is |
3683 | | /// currently always a typename type. |
3684 | | class UnresolvedUsingTypenameDecl |
3685 | | : public TypeDecl, |
3686 | | public Mergeable<UnresolvedUsingTypenameDecl> { |
3687 | | friend class ASTDeclReader; |
3688 | | |
3689 | | /// The source location of the 'typename' keyword |
3690 | | SourceLocation TypenameLocation; |
3691 | | |
3692 | | /// If this is a pack expansion, the location of the '...'. |
3693 | | SourceLocation EllipsisLoc; |
3694 | | |
3695 | | /// The nested-name-specifier that precedes the name. |
3696 | | NestedNameSpecifierLoc QualifierLoc; |
3697 | | |
3698 | | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
3699 | | SourceLocation TypenameLoc, |
3700 | | NestedNameSpecifierLoc QualifierLoc, |
3701 | | SourceLocation TargetNameLoc, |
3702 | | IdentifierInfo *TargetName, |
3703 | | SourceLocation EllipsisLoc) |
3704 | | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
3705 | | UsingLoc), |
3706 | | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
3707 | 1.11k | QualifierLoc(QualifierLoc) {} |
3708 | | |
3709 | | void anchor() override; |
3710 | | |
3711 | | public: |
3712 | | /// Returns the source location of the 'using' keyword. |
3713 | 875 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
3714 | | |
3715 | | /// Returns the source location of the 'typename' keyword. |
3716 | 974 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
3717 | | |
3718 | | /// Retrieve the nested-name-specifier that qualifies the name, |
3719 | | /// with source-location information. |
3720 | 1.08k | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3721 | | |
3722 | | /// Retrieve the nested-name-specifier that qualifies the name. |
3723 | 42 | NestedNameSpecifier *getQualifier() const { |
3724 | 42 | return QualifierLoc.getNestedNameSpecifier(); |
3725 | 42 | } |
3726 | | |
3727 | 680 | DeclarationNameInfo getNameInfo() const { |
3728 | 680 | return DeclarationNameInfo(getDeclName(), getLocation()); |
3729 | 680 | } |
3730 | | |
3731 | | /// Determine whether this is a pack expansion. |
3732 | 794 | bool isPackExpansion() const { |
3733 | 794 | return EllipsisLoc.isValid(); |
3734 | 794 | } |
3735 | | |
3736 | | /// Get the location of the ellipsis if this is a pack expansion. |
3737 | 1.64k | SourceLocation getEllipsisLoc() const { |
3738 | 1.64k | return EllipsisLoc; |
3739 | 1.64k | } |
3740 | | |
3741 | | static UnresolvedUsingTypenameDecl * |
3742 | | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3743 | | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
3744 | | SourceLocation TargetNameLoc, DeclarationName TargetName, |
3745 | | SourceLocation EllipsisLoc); |
3746 | | |
3747 | | static UnresolvedUsingTypenameDecl * |
3748 | | CreateDeserialized(ASTContext &C, unsigned ID); |
3749 | | |
3750 | | /// Retrieves the canonical declaration of this declaration. |
3751 | 3.29k | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
3752 | 3.29k | return getFirstDecl(); |
3753 | 3.29k | } |
3754 | 0 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
3755 | 0 | return getFirstDecl(); |
3756 | 0 | } |
3757 | | |
3758 | 2.64M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3759 | 2.64M | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
3760 | | }; |
3761 | | |
3762 | | /// Represents a C++11 static_assert declaration. |
3763 | | class StaticAssertDecl : public Decl { |
3764 | | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
3765 | | StringLiteral *Message; |
3766 | | SourceLocation RParenLoc; |
3767 | | |
3768 | | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
3769 | | Expr *AssertExpr, StringLiteral *Message, |
3770 | | SourceLocation RParenLoc, bool Failed) |
3771 | | : Decl(StaticAssert, DC, StaticAssertLoc), |
3772 | | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
3773 | 101k | RParenLoc(RParenLoc) {} |
3774 | | |
3775 | | virtual void anchor(); |
3776 | | |
3777 | | public: |
3778 | | friend class ASTDeclReader; |
3779 | | |
3780 | | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
3781 | | SourceLocation StaticAssertLoc, |
3782 | | Expr *AssertExpr, StringLiteral *Message, |
3783 | | SourceLocation RParenLoc, bool Failed); |
3784 | | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3785 | | |
3786 | 57.5k | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
3787 | 2.52k | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
3788 | | |
3789 | 57.5k | StringLiteral *getMessage() { return Message; } |
3790 | 2.52k | const StringLiteral *getMessage() const { return Message; } |
3791 | | |
3792 | 90.9k | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
3793 | | |
3794 | 53.3k | SourceLocation getRParenLoc() const { return RParenLoc; } |
3795 | | |
3796 | 62 | SourceRange getSourceRange() const override LLVM_READONLY { |
3797 | 62 | return SourceRange(getLocation(), getRParenLoc()); |
3798 | 62 | } |
3799 | | |
3800 | 43.3M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3801 | 43.3M | static bool classofKind(Kind K) { return K == StaticAssert; } |
3802 | | }; |
3803 | | |
3804 | | /// A binding in a decomposition declaration. For instance, given: |
3805 | | /// |
3806 | | /// int n[3]; |
3807 | | /// auto &[a, b, c] = n; |
3808 | | /// |
3809 | | /// a, b, and c are BindingDecls, whose bindings are the expressions |
3810 | | /// x[0], x[1], and x[2] respectively, where x is the implicit |
3811 | | /// DecompositionDecl of type 'int (&)[3]'. |
3812 | | class BindingDecl : public ValueDecl { |
3813 | | /// The declaration that this binding binds to part of. |
3814 | | LazyDeclPtr Decomp; |
3815 | | /// The binding represented by this declaration. References to this |
3816 | | /// declaration are effectively equivalent to this expression (except |
3817 | | /// that it is only evaluated once at the point of declaration of the |
3818 | | /// binding). |
3819 | | Expr *Binding = nullptr; |
3820 | | |
3821 | | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
3822 | 662 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
3823 | | |
3824 | | void anchor() override; |
3825 | | |
3826 | | public: |
3827 | | friend class ASTDeclReader; |
3828 | | |
3829 | | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
3830 | | SourceLocation IdLoc, IdentifierInfo *Id); |
3831 | | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3832 | | |
3833 | | /// Get the expression to which this declaration is bound. This may be null |
3834 | | /// in two different cases: while parsing the initializer for the |
3835 | | /// decomposition declaration, and when the initializer is type-dependent. |
3836 | 2.84k | Expr *getBinding() const { return Binding; } |
3837 | | |
3838 | | /// Get the decomposition declaration that this binding represents a |
3839 | | /// decomposition of. |
3840 | | ValueDecl *getDecomposedDecl() const; |
3841 | | |
3842 | | /// Get the variable (if any) that holds the value of evaluating the binding. |
3843 | | /// Only present for user-defined bindings for tuple-like types. |
3844 | | VarDecl *getHoldingVar() const; |
3845 | | |
3846 | | /// Set the binding for this BindingDecl, along with its declared type (which |
3847 | | /// should be a possibly-cv-qualified form of the type of the binding, or a |
3848 | | /// reference to such a type). |
3849 | 508 | void setBinding(QualType DeclaredType, Expr *Binding) { |
3850 | 508 | setType(DeclaredType); |
3851 | 508 | this->Binding = Binding; |
3852 | 508 | } |
3853 | | |
3854 | | /// Set the decomposed variable for this BindingDecl. |
3855 | 662 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
3856 | | |
3857 | 22.1M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3858 | 22.1M | static bool classofKind(Kind K) { return K == Decl::Binding; } |
3859 | | }; |
3860 | | |
3861 | | /// A decomposition declaration. For instance, given: |
3862 | | /// |
3863 | | /// int n[3]; |
3864 | | /// auto &[a, b, c] = n; |
3865 | | /// |
3866 | | /// the second line declares a DecompositionDecl of type 'int (&)[3]', and |
3867 | | /// three BindingDecls (named a, b, and c). An instance of this class is always |
3868 | | /// unnamed, but behaves in almost all other respects like a VarDecl. |
3869 | | class DecompositionDecl final |
3870 | | : public VarDecl, |
3871 | | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
3872 | | /// The number of BindingDecl*s following this object. |
3873 | | unsigned NumBindings; |
3874 | | |
3875 | | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3876 | | SourceLocation LSquareLoc, QualType T, |
3877 | | TypeSourceInfo *TInfo, StorageClass SC, |
3878 | | ArrayRef<BindingDecl *> Bindings) |
3879 | | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
3880 | | SC), |
3881 | 375 | NumBindings(Bindings.size()) { |
3882 | 375 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
3883 | 375 | getTrailingObjects<BindingDecl *>()); |
3884 | 375 | for (auto *B : Bindings) |
3885 | 650 | B->setDecomposedDecl(this); |
3886 | 375 | } |
3887 | | |
3888 | | void anchor() override; |
3889 | | |
3890 | | public: |
3891 | | friend class ASTDeclReader; |
3892 | | friend TrailingObjects; |
3893 | | |
3894 | | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
3895 | | SourceLocation StartLoc, |
3896 | | SourceLocation LSquareLoc, |
3897 | | QualType T, TypeSourceInfo *TInfo, |
3898 | | StorageClass S, |
3899 | | ArrayRef<BindingDecl *> Bindings); |
3900 | | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3901 | | unsigned NumBindings); |
3902 | | |
3903 | 1.51k | ArrayRef<BindingDecl *> bindings() const { |
3904 | 1.51k | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
3905 | 1.51k | } |
3906 | | |
3907 | | void printName(raw_ostream &os) const override; |
3908 | | |
3909 | 81.2M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3910 | 81.2M | static bool classofKind(Kind K) { return K == Decomposition; } |
3911 | | }; |
3912 | | |
3913 | | /// An instance of this class represents the declaration of a property |
3914 | | /// member. This is a Microsoft extension to C++, first introduced in |
3915 | | /// Visual Studio .NET 2003 as a parallel to similar features in C# |
3916 | | /// and Managed C++. |
3917 | | /// |
3918 | | /// A property must always be a non-static class member. |
3919 | | /// |
3920 | | /// A property member superficially resembles a non-static data |
3921 | | /// member, except preceded by a property attribute: |
3922 | | /// __declspec(property(get=GetX, put=PutX)) int x; |
3923 | | /// Either (but not both) of the 'get' and 'put' names may be omitted. |
3924 | | /// |
3925 | | /// A reference to a property is always an lvalue. If the lvalue |
3926 | | /// undergoes lvalue-to-rvalue conversion, then a getter name is |
3927 | | /// required, and that member is called with no arguments. |
3928 | | /// If the lvalue is assigned into, then a setter name is required, |
3929 | | /// and that member is called with one argument, the value assigned. |
3930 | | /// Both operations are potentially overloaded. Compound assignments |
3931 | | /// are permitted, as are the increment and decrement operators. |
3932 | | /// |
3933 | | /// The getter and putter methods are permitted to be overloaded, |
3934 | | /// although their return and parameter types are subject to certain |
3935 | | /// restrictions according to the type of the property. |
3936 | | /// |
3937 | | /// A property declared using an incomplete array type may |
3938 | | /// additionally be subscripted, adding extra parameters to the getter |
3939 | | /// and putter methods. |
3940 | | class MSPropertyDecl : public DeclaratorDecl { |
3941 | | IdentifierInfo *GetterId, *SetterId; |
3942 | | |
3943 | | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
3944 | | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
3945 | | IdentifierInfo *Getter, IdentifierInfo *Setter) |
3946 | | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
3947 | 136 | GetterId(Getter), SetterId(Setter) {} |
3948 | | |
3949 | | void anchor() override; |
3950 | | public: |
3951 | | friend class ASTDeclReader; |
3952 | | |
3953 | | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
3954 | | SourceLocation L, DeclarationName N, QualType T, |
3955 | | TypeSourceInfo *TInfo, SourceLocation StartL, |
3956 | | IdentifierInfo *Getter, IdentifierInfo *Setter); |
3957 | | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3958 | | |
3959 | 4.72M | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
3960 | | |
3961 | 177 | bool hasGetter() const { return GetterId != nullptr; } |
3962 | 214 | IdentifierInfo* getGetterId() const { return GetterId; } |
3963 | 100 | bool hasSetter() const { return SetterId != nullptr; } |
3964 | 124 | IdentifierInfo* getSetterId() const { return SetterId; } |
3965 | | }; |
3966 | | |
3967 | | /// Parts of a decomposed MSGuidDecl. Factored out to avoid unnecessary |
3968 | | /// dependencies on DeclCXX.h. |
3969 | | struct MSGuidDeclParts { |
3970 | | /// {01234567-... |
3971 | | uint32_t Part1; |
3972 | | /// ...-89ab-... |
3973 | | uint16_t Part2; |
3974 | | /// ...-cdef-... |
3975 | | uint16_t Part3; |
3976 | | /// ...-0123-456789abcdef} |
3977 | | uint8_t Part4And5[8]; |
3978 | | |
3979 | 231 | uint64_t getPart4And5AsUint64() const { |
3980 | 231 | uint64_t Val; |
3981 | 231 | memcpy(&Val, &Part4And5, sizeof(Part4And5)); |
3982 | 231 | return Val; |
3983 | 231 | } |
3984 | | }; |
3985 | | |
3986 | | /// A global _GUID constant. These are implicitly created by UuidAttrs. |
3987 | | /// |
3988 | | /// struct _declspec(uuid("01234567-89ab-cdef-0123-456789abcdef")) X{}; |
3989 | | /// |
3990 | | /// X is a CXXRecordDecl that contains a UuidAttr that references the (unique) |
3991 | | /// MSGuidDecl for the specified UUID. |
3992 | | class MSGuidDecl : public ValueDecl, |
3993 | | public Mergeable<MSGuidDecl>, |
3994 | | public llvm::FoldingSetNode { |
3995 | | public: |
3996 | | using Parts = MSGuidDeclParts; |
3997 | | |
3998 | | private: |
3999 | | /// The decomposed form of the UUID. |
4000 | | Parts PartVal; |
4001 | | |
4002 | | /// The resolved value of the UUID as an APValue. Computed on demand and |
4003 | | /// cached. |
4004 | | mutable APValue APVal; |
4005 | | |
4006 | | void anchor() override; |
4007 | | |
4008 | | MSGuidDecl(DeclContext *DC, QualType T, Parts P); |
4009 | | |
4010 | | static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P); |
4011 | | static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4012 | | |
4013 | | // Only ASTContext::getMSGuidDecl and deserialization create these. |
4014 | | friend class ASTContext; |
4015 | | friend class ASTReader; |
4016 | | friend class ASTDeclReader; |
4017 | | |
4018 | | public: |
4019 | | /// Print this UUID in a human-readable format. |
4020 | | void printName(llvm::raw_ostream &OS) const override; |
4021 | | |
4022 | | /// Get the decomposed parts of this declaration. |
4023 | 81 | Parts getParts() const { return PartVal; } |
4024 | | |
4025 | | /// Get the value of this MSGuidDecl as an APValue. This may fail and return |
4026 | | /// an absent APValue if the type of the declaration is not of the expected |
4027 | | /// shape. |
4028 | | APValue &getAsAPValue() const; |
4029 | | |
4030 | 231 | static void Profile(llvm::FoldingSetNodeID &ID, Parts P) { |
4031 | 231 | ID.AddInteger(P.Part1); |
4032 | 231 | ID.AddInteger(P.Part2); |
4033 | 231 | ID.AddInteger(P.Part3); |
4034 | 231 | ID.AddInteger(P.getPart4And5AsUint64()); |
4035 | 231 | } |
4036 | 84 | void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); } |
4037 | | |
4038 | 23.2M | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4039 | 23.2M | static bool classofKind(Kind K) { return K == Decl::MSGuid; } |
4040 | | }; |
4041 | | |
4042 | | /// Insertion operator for diagnostics. This allows sending an AccessSpecifier |
4043 | | /// into a diagnostic with <<. |
4044 | | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
4045 | | AccessSpecifier AS); |
4046 | | |
4047 | | } // namespace clang |
4048 | | |
4049 | | #endif // LLVM_CLANG_AST_DECLCXX_H |