clang 20.0.0git
DeclarationName.h
Go to the documentation of this file.
1//===- DeclarationName.h - Representation of declaration names --*- 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// This file declares the DeclarationName and DeclarationNameTable classes.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
14#define LLVM_CLANG_AST_DECLARATIONNAME_H
15
16#include "clang/AST/Type.h"
22#include "llvm/ADT/DenseMapInfo.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/Support/Compiler.h"
26#include "llvm/Support/type_traits.h"
27#include <cassert>
28#include <cstdint>
29#include <cstring>
30#include <string>
31
32namespace clang {
33
34class ASTContext;
35template <typename> class CanQual;
36class DeclarationName;
37class DeclarationNameTable;
38struct PrintingPolicy;
39class TemplateDecl;
40class TypeSourceInfo;
41
42using CanQualType = CanQual<Type>;
43
44namespace detail {
45
46/// CXXSpecialNameExtra records the type associated with one of the "special"
47/// kinds of declaration names in C++, e.g., constructors, destructors, and
48/// conversion functions. Note that CXXSpecialName is used for C++ constructor,
49/// destructor and conversion functions, but the actual kind is not stored in
50/// CXXSpecialName. Instead we use three different FoldingSet<CXXSpecialName>
51/// in DeclarationNameTable.
52class alignas(IdentifierInfoAlignment) CXXSpecialNameExtra
53 : public llvm::FoldingSetNode {
56
57 /// The type associated with this declaration name.
59
60 /// Extra information associated with this declaration name that
61 /// can be used by the front end. All bits are really needed
62 /// so it is not possible to stash something in the low order bits.
63 void *FETokenInfo;
64
65 CXXSpecialNameExtra(QualType QT) : Type(QT), FETokenInfo(nullptr) {}
66
67public:
68 void Profile(llvm::FoldingSetNodeID &ID) {
69 ID.AddPointer(Type.getAsOpaquePtr());
70 }
71};
72
73/// Contains extra information for the name of a C++ deduction guide.
74class alignas(IdentifierInfoAlignment) CXXDeductionGuideNameExtra
76 public llvm::FoldingSetNode {
79
80 /// The template named by the deduction guide.
81 TemplateDecl *Template;
82
83 /// Extra information associated with this operator name that
84 /// can be used by the front end. All bits are really needed
85 /// so it is not possible to stash something in the low order bits.
86 void *FETokenInfo;
87
89 : DeclarationNameExtra(CXXDeductionGuideName), Template(TD),
90 FETokenInfo(nullptr) {}
91
92public:
93 void Profile(llvm::FoldingSetNodeID &ID) { ID.AddPointer(Template); }
94};
95
96/// Contains extra information for the name of an overloaded operator
97/// in C++, such as "operator+. This do not includes literal or conversion
98/// operators. For literal operators see CXXLiteralOperatorIdName and for
99/// conversion operators see CXXSpecialNameExtra.
100class alignas(IdentifierInfoAlignment) CXXOperatorIdName {
103
104 /// The kind of this operator.
106
107 /// Extra information associated with this operator name that
108 /// can be used by the front end. All bits are really needed
109 /// so it is not possible to stash something in the low order bits.
110 void *FETokenInfo = nullptr;
111};
112
113/// Contains the actual identifier that makes up the
114/// name of a C++ literal operator.
115class alignas(IdentifierInfoAlignment) CXXLiteralOperatorIdName
117 public llvm::FoldingSetNode {
120
121 const IdentifierInfo *ID;
122
123 /// Extra information associated with this operator name that
124 /// can be used by the front end. All bits are really needed
125 /// so it is not possible to stash something in the low order bits.
126 void *FETokenInfo;
127
129 : DeclarationNameExtra(CXXLiteralOperatorName), ID(II),
130 FETokenInfo(nullptr) {}
131
132public:
133 void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); }
134};
135
136} // namespace detail
137
138/// The name of a declaration. In the common case, this just stores
139/// an IdentifierInfo pointer to a normal name. However, it also provides
140/// encodings for Objective-C selectors (optimizing zero- and one-argument
141/// selectors, which make up 78% percent of all selectors in Cocoa.h),
142/// special C++ names for constructors, destructors, and conversion functions,
143/// and C++ overloaded operators.
146 friend class NamedDecl;
147
148 /// StoredNameKind represent the kind of name that is actually stored in the
149 /// upper bits of the Ptr field. This is only used internally.
150 ///
151 /// NameKind, StoredNameKind, and DeclarationNameExtra::ExtraKind
152 /// must satisfy the following properties. These properties enable
153 /// efficient conversion between the various kinds.
154 ///
155 /// * The first seven enumerators of StoredNameKind must have the same
156 /// numerical value as the first seven enumerators of NameKind.
157 /// This enable efficient conversion between the two enumerations
158 /// in the usual case.
159 ///
160 /// * The enumerations values of DeclarationNameExtra::ExtraKind must start
161 /// at zero, and correspond to the numerical value of the first non-inline
162 /// enumeration values of NameKind minus an offset. This makes conversion
163 /// between DeclarationNameExtra::ExtraKind and NameKind possible with
164 /// a single addition/substraction.
165 ///
166 /// * The enumeration values of Selector::IdentifierInfoFlag must correspond
167 /// to the relevant enumeration values of StoredNameKind.
168 /// More specifically:
169 /// * ZeroArg == StoredObjCZeroArgSelector,
170 /// * OneArg == StoredObjCOneArgSelector,
171 /// * MultiArg == StoredDeclarationNameExtra
172 ///
173 /// * PtrMask must mask the low 3 bits of Ptr.
174 enum StoredNameKind {
175 StoredIdentifier = 0,
176 StoredObjCZeroArgSelector = Selector::ZeroArg,
177 StoredObjCOneArgSelector = Selector::OneArg,
178 StoredCXXConstructorName = 3,
179 StoredCXXDestructorName = 4,
180 StoredCXXConversionFunctionName = 5,
181 StoredCXXOperatorName = 6,
182 StoredDeclarationNameExtra = Selector::MultiArg,
183 PtrMask = 7,
184 UncommonNameKindOffset = 8
185 };
186
187 static_assert(alignof(IdentifierInfo) >= 8 &&
188 alignof(detail::DeclarationNameExtra) >= 8 &&
189 alignof(detail::CXXSpecialNameExtra) >= 8 &&
190 alignof(detail::CXXOperatorIdName) >= 8 &&
193 "The various classes that DeclarationName::Ptr can point to"
194 " must be at least aligned to 8 bytes!");
195
196 static_assert(
197 std::is_same<std::underlying_type_t<StoredNameKind>,
198 std::underlying_type_t<
200 "The various enums used to compute values for NameKind should "
201 "all have the same underlying type");
202
203public:
204 /// The kind of the name stored in this DeclarationName.
205 /// The first 7 enumeration values are stored inline and correspond
206 /// to frequently used kinds. The rest is stored in DeclarationNameExtra
207 /// and correspond to infrequently used kinds.
208 enum NameKind {
209 Identifier = StoredIdentifier,
210 ObjCZeroArgSelector = StoredObjCZeroArgSelector,
211 ObjCOneArgSelector = StoredObjCOneArgSelector,
212 CXXConstructorName = StoredCXXConstructorName,
213 CXXDestructorName = StoredCXXDestructorName,
214 CXXConversionFunctionName = StoredCXXConversionFunctionName,
215 CXXOperatorName = StoredCXXOperatorName,
216 CXXDeductionGuideName = llvm::addEnumValues(
217 UncommonNameKindOffset,
218 detail::DeclarationNameExtra::CXXDeductionGuideName),
219 CXXLiteralOperatorName = llvm::addEnumValues(
220 UncommonNameKindOffset,
221 detail::DeclarationNameExtra::CXXLiteralOperatorName),
222 CXXUsingDirective =
223 llvm::addEnumValues(UncommonNameKindOffset,
224 detail::DeclarationNameExtra::CXXUsingDirective),
225 ObjCMultiArgSelector =
226 llvm::addEnumValues(UncommonNameKindOffset,
227 detail::DeclarationNameExtra::ObjCMultiArgSelector),
228 };
229
230private:
231 /// The lowest three bits of Ptr are used to express what kind of name
232 /// we're actually storing, using the values of StoredNameKind. Depending
233 /// on the kind of name this is, the upper bits of Ptr may have one
234 /// of several different meanings:
235 ///
236 /// StoredIdentifier - The name is a normal identifier, and Ptr is
237 /// a normal IdentifierInfo pointer.
238 ///
239 /// StoredObjCZeroArgSelector - The name is an Objective-C
240 /// selector with zero arguments, and Ptr is an IdentifierInfo
241 /// pointer pointing to the selector name.
242 ///
243 /// StoredObjCOneArgSelector - The name is an Objective-C selector
244 /// with one argument, and Ptr is an IdentifierInfo pointer
245 /// pointing to the selector name.
246 ///
247 /// StoredCXXConstructorName - The name of a C++ constructor,
248 /// Ptr points to a CXXSpecialNameExtra.
249 ///
250 /// StoredCXXDestructorName - The name of a C++ destructor,
251 /// Ptr points to a CXXSpecialNameExtra.
252 ///
253 /// StoredCXXConversionFunctionName - The name of a C++ conversion function,
254 /// Ptr points to a CXXSpecialNameExtra.
255 ///
256 /// StoredCXXOperatorName - The name of an overloaded C++ operator,
257 /// Ptr points to a CXXOperatorIdName.
258 ///
259 /// StoredDeclarationNameExtra - Ptr is actually a pointer to a
260 /// DeclarationNameExtra structure, whose first value will tell us
261 /// whether this is an Objective-C selector, C++ deduction guide,
262 /// C++ literal operator, or C++ using directive.
263 uintptr_t Ptr = 0;
264
265 StoredNameKind getStoredNameKind() const {
266 return static_cast<StoredNameKind>(Ptr & PtrMask);
267 }
268
269 void *getPtr() const { return reinterpret_cast<void *>(Ptr & ~PtrMask); }
270
271 void setPtrAndKind(const void *P, StoredNameKind Kind) {
272 uintptr_t PAsInteger = reinterpret_cast<uintptr_t>(P);
273 assert((Kind & ~PtrMask) == 0 &&
274 "Invalid StoredNameKind in setPtrAndKind!");
275 assert((PAsInteger & PtrMask) == 0 &&
276 "Improperly aligned pointer in setPtrAndKind!");
277 Ptr = PAsInteger | Kind;
278 }
279
280 /// Construct a declaration name from a DeclarationNameExtra.
281 DeclarationName(detail::DeclarationNameExtra *Name) {
282 setPtrAndKind(Name, StoredDeclarationNameExtra);
283 }
284
285 /// Construct a declaration name from a CXXSpecialNameExtra.
286 DeclarationName(detail::CXXSpecialNameExtra *Name,
287 StoredNameKind StoredKind) {
288 assert((StoredKind == StoredCXXConstructorName ||
289 StoredKind == StoredCXXDestructorName ||
290 StoredKind == StoredCXXConversionFunctionName) &&
291 "Invalid StoredNameKind when constructing a DeclarationName"
292 " from a CXXSpecialNameExtra!");
293 setPtrAndKind(Name, StoredKind);
294 }
295
296 /// Construct a DeclarationName from a CXXOperatorIdName.
297 DeclarationName(detail::CXXOperatorIdName *Name) {
298 setPtrAndKind(Name, StoredCXXOperatorName);
299 }
300
301 /// Assert that the stored pointer points to an IdentifierInfo and return it.
302 IdentifierInfo *castAsIdentifierInfo() const {
303 assert((getStoredNameKind() == StoredIdentifier) &&
304 "DeclarationName does not store an IdentifierInfo!");
305 return static_cast<IdentifierInfo *>(getPtr());
306 }
307
308 /// Assert that the stored pointer points to a DeclarationNameExtra
309 /// and return it.
310 detail::DeclarationNameExtra *castAsExtra() const {
311 assert((getStoredNameKind() == StoredDeclarationNameExtra) &&
312 "DeclarationName does not store an Extra structure!");
313 return static_cast<detail::DeclarationNameExtra *>(getPtr());
314 }
315
316 /// Assert that the stored pointer points to a CXXSpecialNameExtra
317 /// and return it.
318 detail::CXXSpecialNameExtra *castAsCXXSpecialNameExtra() const {
319 assert((getStoredNameKind() == StoredCXXConstructorName ||
320 getStoredNameKind() == StoredCXXDestructorName ||
321 getStoredNameKind() == StoredCXXConversionFunctionName) &&
322 "DeclarationName does not store a CXXSpecialNameExtra!");
323 return static_cast<detail::CXXSpecialNameExtra *>(getPtr());
324 }
325
326 /// Assert that the stored pointer points to a CXXOperatorIdName
327 /// and return it.
328 detail::CXXOperatorIdName *castAsCXXOperatorIdName() const {
329 assert((getStoredNameKind() == StoredCXXOperatorName) &&
330 "DeclarationName does not store a CXXOperatorIdName!");
331 return static_cast<detail::CXXOperatorIdName *>(getPtr());
332 }
333
334 /// Assert that the stored pointer points to a CXXDeductionGuideNameExtra
335 /// and return it.
336 detail::CXXDeductionGuideNameExtra *castAsCXXDeductionGuideNameExtra() const {
337 assert(getNameKind() == CXXDeductionGuideName &&
338 "DeclarationName does not store a CXXDeductionGuideNameExtra!");
339 return static_cast<detail::CXXDeductionGuideNameExtra *>(getPtr());
340 }
341
342 /// Assert that the stored pointer points to a CXXLiteralOperatorIdName
343 /// and return it.
344 detail::CXXLiteralOperatorIdName *castAsCXXLiteralOperatorIdName() const {
345 assert(getNameKind() == CXXLiteralOperatorName &&
346 "DeclarationName does not store a CXXLiteralOperatorIdName!");
347 return static_cast<detail::CXXLiteralOperatorIdName *>(getPtr());
348 }
349
350 /// Get and set the FETokenInfo in the less common cases where the
351 /// declaration name do not point to an identifier.
352 void *getFETokenInfoSlow() const;
353 void setFETokenInfoSlow(void *T);
354
355public:
356 /// Construct an empty declaration name.
357 DeclarationName() { setPtrAndKind(nullptr, StoredIdentifier); }
358
359 /// Construct a declaration name from an IdentifierInfo *.
361 setPtrAndKind(II, StoredIdentifier);
362 }
363
364 /// Construct a declaration name from an Objective-C selector.
366 : Ptr(reinterpret_cast<uintptr_t>(Sel.InfoPtr.getOpaqueValue())) {}
367
368 /// Returns the name for all C++ using-directives.
370 // Single instance of DeclarationNameExtra for using-directive
371 static detail::DeclarationNameExtra UDirExtra(
372 detail::DeclarationNameExtra::CXXUsingDirective);
373 return DeclarationName(&UDirExtra);
374 }
375
376 /// Evaluates true when this declaration name is non-empty.
377 explicit operator bool() const {
378 return getPtr() || (getStoredNameKind() != StoredIdentifier);
379 }
380
381 /// Evaluates true when this declaration name is empty.
382 bool isEmpty() const { return !*this; }
383
384 /// Predicate functions for querying what type of name this is.
385 bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
387 return getStoredNameKind() == StoredObjCZeroArgSelector;
388 }
389 bool isObjCOneArgSelector() const {
390 return getStoredNameKind() == StoredObjCOneArgSelector;
391 }
392
393 /// Determine what kind of name this is.
395 // We rely on the fact that the first 7 NameKind and StoredNameKind
396 // have the same numerical value. This makes the usual case efficient.
397 StoredNameKind StoredKind = getStoredNameKind();
398 if (StoredKind != StoredDeclarationNameExtra)
399 return static_cast<NameKind>(StoredKind);
400 // We have to consult DeclarationNameExtra. We rely on the fact that the
401 // enumeration values of ExtraKind correspond to the enumeration values of
402 // NameKind minus an offset of UncommonNameKindOffset.
403 unsigned ExtraKind = castAsExtra()->getKind();
404 return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind);
405 }
406
407 /// Determines whether the name itself is dependent, e.g., because it
408 /// involves a C++ type that is itself dependent.
409 ///
410 /// Note that this does not capture all of the notions of "dependent name",
411 /// because an identifier can be a dependent name if it is used as the
412 /// callee in a call expression with dependent arguments.
413 bool isDependentName() const;
414
415 /// Retrieve the human-readable string for this name.
416 std::string getAsString() const;
417
418 /// Retrieve the IdentifierInfo * stored in this declaration name,
419 /// or null if this declaration name isn't a simple identifier.
421 if (isIdentifier())
422 return castAsIdentifierInfo();
423 return nullptr;
424 }
425
426 /// Get the representation of this declaration name as an opaque integer.
427 uintptr_t getAsOpaqueInteger() const { return Ptr; }
428
429 /// Get the representation of this declaration name as an opaque pointer.
430 void *getAsOpaquePtr() const { return reinterpret_cast<void *>(Ptr); }
431
432 /// Get a declaration name from an opaque pointer returned by getAsOpaquePtr.
435 N.Ptr = reinterpret_cast<uintptr_t>(P);
436 return N;
437 }
438
439 /// Get a declaration name from an opaque integer
440 /// returned by getAsOpaqueInteger.
443 N.Ptr = P;
444 return N;
445 }
446
447 /// If this name is one of the C++ names (of a constructor, destructor,
448 /// or conversion function), return the type associated with that name.
450 if (getStoredNameKind() == StoredCXXConstructorName ||
451 getStoredNameKind() == StoredCXXDestructorName ||
452 getStoredNameKind() == StoredCXXConversionFunctionName) {
453 assert(getPtr() && "getCXXNameType on a null DeclarationName!");
454 return castAsCXXSpecialNameExtra()->Type;
455 }
456 return QualType();
457 }
458
459 /// If this name is the name of a C++ deduction guide, return the
460 /// template associated with that name.
462 if (getNameKind() == CXXDeductionGuideName) {
463 assert(getPtr() &&
464 "getCXXDeductionGuideTemplate on a null DeclarationName!");
465 return castAsCXXDeductionGuideNameExtra()->Template;
466 }
467 return nullptr;
468 }
469
470 /// If this name is the name of an overloadable operator in C++
471 /// (e.g., @c operator+), retrieve the kind of overloaded operator.
473 if (getStoredNameKind() == StoredCXXOperatorName) {
474 assert(getPtr() && "getCXXOverloadedOperator on a null DeclarationName!");
475 return castAsCXXOperatorIdName()->Kind;
476 }
477 return OO_None;
478 }
479
480 /// If this name is the name of a literal operator,
481 /// retrieve the identifier associated with it.
483 if (getNameKind() == CXXLiteralOperatorName) {
484 assert(getPtr() && "getCXXLiteralIdentifier on a null DeclarationName!");
485 return castAsCXXLiteralOperatorIdName()->ID;
486 }
487 return nullptr;
488 }
489
490 /// Get the Objective-C selector stored in this declaration name.
492 assert((getNameKind() == ObjCZeroArgSelector ||
493 getNameKind() == ObjCOneArgSelector ||
494 getNameKind() == ObjCMultiArgSelector || !getPtr()) &&
495 "Not a selector!");
496 return Selector(Ptr);
497 }
498
499 /// Get and set FETokenInfo. The language front-end is allowed to associate
500 /// arbitrary metadata with some kinds of declaration names, including normal
501 /// identifiers and C++ constructors, destructors, and conversion functions.
502 void *getFETokenInfo() const {
503 assert(getPtr() && "getFETokenInfo on an empty DeclarationName!");
504 if (getStoredNameKind() == StoredIdentifier)
505 return castAsIdentifierInfo()->getFETokenInfo();
506 return getFETokenInfoSlow();
507 }
508
509 void setFETokenInfo(void *T) {
510 assert(getPtr() && "setFETokenInfo on an empty DeclarationName!");
511 if (getStoredNameKind() == StoredIdentifier)
512 castAsIdentifierInfo()->setFETokenInfo(T);
513 else
514 setFETokenInfoSlow(T);
515 }
516
517 /// Determine whether the specified names are identical.
519 return LHS.Ptr == RHS.Ptr;
520 }
521
522 /// Determine whether the specified names are different.
524 return LHS.Ptr != RHS.Ptr;
525 }
526
528 DeclarationName Name;
529 Name.Ptr = uintptr_t(-1);
530 return Name;
531 }
532
534 DeclarationName Name;
535 Name.Ptr = uintptr_t(-2);
536 return Name;
537 }
538
539 static int compare(DeclarationName LHS, DeclarationName RHS);
540
541 void print(raw_ostream &OS, const PrintingPolicy &Policy) const;
542
543 void dump() const;
544};
545
546raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
547
548/// Ordering on two declaration names. If both names are identifiers,
549/// this provides a lexicographical ordering.
551 return DeclarationName::compare(LHS, RHS) < 0;
552}
553
554/// Ordering on two declaration names. If both names are identifiers,
555/// this provides a lexicographical ordering.
557 return DeclarationName::compare(LHS, RHS) > 0;
558}
559
560/// Ordering on two declaration names. If both names are identifiers,
561/// this provides a lexicographical ordering.
563 return DeclarationName::compare(LHS, RHS) <= 0;
564}
565
566/// Ordering on two declaration names. If both names are identifiers,
567/// this provides a lexicographical ordering.
569 return DeclarationName::compare(LHS, RHS) >= 0;
570}
571
572/// DeclarationNameTable is used to store and retrieve DeclarationName
573/// instances for the various kinds of declaration names, e.g., normal
574/// identifiers, C++ constructor names, etc. This class contains
575/// uniqued versions of each of the C++ special names, which can be
576/// retrieved using its member functions (e.g., getCXXConstructorName).
578 /// Used to allocate elements in the FoldingSets below.
579 const ASTContext &Ctx;
580
581 /// Manage the uniqued CXXSpecialNameExtra representing C++ constructors.
582 /// getCXXConstructorName and getCXXSpecialName can be used to obtain
583 /// a DeclarationName from the corresponding type of the constructor.
584 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames;
585
586 /// Manage the uniqued CXXSpecialNameExtra representing C++ destructors.
587 /// getCXXDestructorName and getCXXSpecialName can be used to obtain
588 /// a DeclarationName from the corresponding type of the destructor.
589 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames;
590
591 /// Manage the uniqued CXXSpecialNameExtra representing C++ conversion
592 /// functions. getCXXConversionFunctionName and getCXXSpecialName can be
593 /// used to obtain a DeclarationName from the corresponding type of the
594 /// conversion function.
595 llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames;
596
597 /// Manage the uniqued CXXOperatorIdName, which contain extra information
598 /// for the name of overloaded C++ operators. getCXXOperatorName
599 /// can be used to obtain a DeclarationName from the operator kind.
601
602 /// Manage the uniqued CXXLiteralOperatorIdName, which contain extra
603 /// information for the name of C++ literal operators.
604 /// getCXXLiteralOperatorName can be used to obtain a DeclarationName
605 /// from the corresponding IdentifierInfo.
606 llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames;
607
608 /// Manage the uniqued CXXDeductionGuideNameExtra, which contain
609 /// extra information for the name of a C++ deduction guide.
610 /// getCXXDeductionGuideName can be used to obtain a DeclarationName
611 /// from the corresponding template declaration.
612 llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames;
613
614public:
621
622 /// Create a declaration name that is a simple identifier.
624 return DeclarationName(ID);
625 }
626
627 /// Returns the name of a C++ constructor for the given Type.
628 DeclarationName getCXXConstructorName(CanQualType Ty);
629
630 /// Returns the name of a C++ destructor for the given Type.
631 DeclarationName getCXXDestructorName(CanQualType Ty);
632
633 /// Returns the name of a C++ deduction guide for the given template.
634 DeclarationName getCXXDeductionGuideName(TemplateDecl *TD);
635
636 /// Returns the name of a C++ conversion function for the given Type.
637 DeclarationName getCXXConversionFunctionName(CanQualType Ty);
638
639 /// Returns a declaration name for special kind of C++ name,
640 /// e.g., for a constructor, destructor, or conversion function.
641 /// Kind must be one of:
642 /// * DeclarationName::CXXConstructorName,
643 /// * DeclarationName::CXXDestructorName or
644 /// * DeclarationName::CXXConversionFunctionName
646 CanQualType Ty);
647
648 /// Get the name of the overloadable C++ operator corresponding to Op.
650 return DeclarationName(&CXXOperatorNames[Op]);
651 }
652
653 /// Get the name of the literal operator function with II as the identifier.
654 DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II);
655};
656
657/// DeclarationNameLoc - Additional source/type location info
658/// for a declaration name. Needs a DeclarationName in order
659/// to be interpreted correctly.
661 // The source location for identifier stored elsewhere.
662 // struct {} Identifier;
663
664 // Type info for constructors, destructors and conversion functions.
665 // Locations (if any) for the tilde (destructor) or operator keyword
666 // (conversion) are stored elsewhere.
667 struct NT {
668 TypeSourceInfo *TInfo;
669 };
670
671 // The location (if any) of the operator keyword is stored elsewhere.
672 struct CXXOpName {
673 SourceLocation::UIntTy BeginOpNameLoc;
674 SourceLocation::UIntTy EndOpNameLoc;
675 };
676
677 // The location (if any) of the operator keyword is stored elsewhere.
678 struct CXXLitOpName {
679 SourceLocation::UIntTy OpNameLoc;
680 };
681
682 // struct {} CXXUsingDirective;
683 // struct {} ObjCZeroArgSelector;
684 // struct {} ObjCOneArgSelector;
685 // struct {} ObjCMultiArgSelector;
686 union {
687 struct NT NamedType;
688 struct CXXOpName CXXOperatorName;
689 struct CXXLitOpName CXXLiteralOperatorName;
690 };
691
692 void setNamedTypeLoc(TypeSourceInfo *TInfo) { NamedType.TInfo = TInfo; }
693
694 void setCXXOperatorNameRange(SourceRange Range) {
695 CXXOperatorName.BeginOpNameLoc = Range.getBegin().getRawEncoding();
696 CXXOperatorName.EndOpNameLoc = Range.getEnd().getRawEncoding();
697 }
698
699 void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
700 CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
701 }
702
703public:
704 DeclarationNameLoc(DeclarationName Name);
705 // FIXME: this should go away once all DNLocs are properly initialized.
706 DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
707
708 /// Returns the source type info. Assumes that the object stores location
709 /// information of a constructor, destructor or conversion operator.
710 TypeSourceInfo *getNamedTypeInfo() const { return NamedType.TInfo; }
711
712 /// Return the beginning location of the getCXXOperatorNameRange() range.
714 return SourceLocation::getFromRawEncoding(CXXOperatorName.BeginOpNameLoc);
715 }
716
717 /// Return the end location of the getCXXOperatorNameRange() range.
719 return SourceLocation::getFromRawEncoding(CXXOperatorName.EndOpNameLoc);
720 }
721
722 /// Return the range of the operator name (without the operator keyword).
723 /// Assumes that the object stores location information of a (non-literal)
724 /// operator.
726 return SourceRange(getCXXOperatorNameBeginLoc(),
727 getCXXOperatorNameEndLoc());
728 }
729
730 /// Return the location of the literal operator name (without the operator
731 /// keyword). Assumes that the object stores location information of a literal
732 /// operator.
734 return SourceLocation::getFromRawEncoding(CXXLiteralOperatorName.OpNameLoc);
735 }
736
737 /// Construct location information for a constructor, destructor or conversion
738 /// operator.
741 DNL.setNamedTypeLoc(TInfo);
742 return DNL;
743 }
744
745 /// Construct location information for a non-literal C++ operator.
747 SourceLocation EndLoc) {
748 return makeCXXOperatorNameLoc(SourceRange(BeginLoc, EndLoc));
749 }
750
751 /// Construct location information for a non-literal C++ operator.
754 DNL.setCXXOperatorNameRange(Range);
755 return DNL;
756 }
757
758 /// Construct location information for a literal C++ operator.
761 DNL.setCXXLiteralOperatorNameLoc(Loc);
762 return DNL;
763 }
764};
765
766/// DeclarationNameInfo - A collector data type for bundling together
767/// a DeclarationName and the corresponding source/type location info.
769private:
770 /// Name - The declaration name, also encoding name kind.
771 DeclarationName Name;
772
773 /// Loc - The main source location for the declaration name.
774 SourceLocation NameLoc;
775
776 /// Info - Further source/type location info for special kinds of names.
777 DeclarationNameLoc LocInfo;
778
779public:
780 // FIXME: remove it.
782
784 : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
785
787 DeclarationNameLoc LocInfo)
788 : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
789
790 /// getName - Returns the embedded declaration name.
791 DeclarationName getName() const { return Name; }
792
793 /// setName - Sets the embedded declaration name.
794 void setName(DeclarationName N) { Name = N; }
795
796 /// getLoc - Returns the main location of the declaration name.
797 SourceLocation getLoc() const { return NameLoc; }
798
799 /// setLoc - Sets the main location of the declaration name.
800 void setLoc(SourceLocation L) { NameLoc = L; }
801
802 const DeclarationNameLoc &getInfo() const { return LocInfo; }
803 void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
804
805 /// getNamedTypeInfo - Returns the source type info associated to
806 /// the name. Assumes it is a constructor, destructor or conversion.
808 if (Name.getNameKind() != DeclarationName::CXXConstructorName &&
809 Name.getNameKind() != DeclarationName::CXXDestructorName &&
810 Name.getNameKind() != DeclarationName::CXXConversionFunctionName)
811 return nullptr;
812 return LocInfo.getNamedTypeInfo();
813 }
814
815 /// setNamedTypeInfo - Sets the source type info associated to
816 /// the name. Assumes it is a constructor, destructor or conversion.
818 assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
819 Name.getNameKind() == DeclarationName::CXXDestructorName ||
820 Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
821 LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
822 }
823
824 /// getCXXOperatorNameRange - Gets the range of the operator name
825 /// (without the operator keyword). Assumes it is a (non-literal) operator.
827 if (Name.getNameKind() != DeclarationName::CXXOperatorName)
828 return SourceRange();
829 return LocInfo.getCXXOperatorNameRange();
830 }
831
832 /// setCXXOperatorNameRange - Sets the range of the operator name
833 /// (without the operator keyword). Assumes it is a C++ operator.
835 assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
836 LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
837 }
838
839 /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
840 /// operator name (not the operator keyword).
841 /// Assumes it is a literal operator.
843 if (Name.getNameKind() != DeclarationName::CXXLiteralOperatorName)
844 return SourceLocation();
845 return LocInfo.getCXXLiteralOperatorNameLoc();
846 }
847
848 /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
849 /// operator name (not the operator keyword).
850 /// Assumes it is a literal operator.
852 assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
853 LocInfo = DeclarationNameLoc::makeCXXLiteralOperatorNameLoc(Loc);
854 }
855
856 /// Determine whether this name involves a template parameter.
857 bool isInstantiationDependent() const;
858
859 /// Determine whether this name contains an unexpanded
860 /// parameter pack.
861 bool containsUnexpandedParameterPack() const;
862
863 /// getAsString - Retrieve the human-readable string for this name.
864 std::string getAsString() const;
865
866 /// printName - Print the human-readable name to a stream.
867 void printName(raw_ostream &OS, PrintingPolicy Policy) const;
868
869 /// getBeginLoc - Retrieve the location of the first token.
870 SourceLocation getBeginLoc() const { return NameLoc; }
871
872 /// getSourceRange - The range of the declaration name.
873 SourceRange getSourceRange() const LLVM_READONLY {
874 return SourceRange(getBeginLoc(), getEndLoc());
875 }
876
877 SourceLocation getEndLoc() const LLVM_READONLY {
878 SourceLocation EndLoc = getEndLocPrivate();
879 return EndLoc.isValid() ? EndLoc : getBeginLoc();
880 }
881
882private:
883 SourceLocation getEndLocPrivate() const;
884};
885
886/// Insertion operator for partial diagnostics. This allows binding
887/// DeclarationName's into a partial diagnostic with <<.
888inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
889 DeclarationName N) {
891 DiagnosticsEngine::ak_declarationname);
892 return PD;
893}
894
895raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo);
896
897} // namespace clang
898
899namespace llvm {
900
901/// Define DenseMapInfo so that DeclarationNames can be used as keys
902/// in DenseMap and DenseSets.
903template<>
904struct DenseMapInfo<clang::DeclarationName> {
907 }
908
911 }
912
913 static unsigned getHashValue(clang::DeclarationName Name) {
914 return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
915 }
916
917 static inline bool
919 return LHS == RHS;
920 }
921};
922
923template <> struct PointerLikeTypeTraits<clang::DeclarationName> {
925 return P.getAsOpaquePtr();
926 }
929 }
930 static constexpr int NumLowBitsAvailable = 0;
931};
932
933} // namespace llvm
934
935// The definition of AssumedTemplateStorage is factored out of TemplateName to
936// resolve a cyclic dependency between it and DeclarationName (via Type).
937namespace clang {
938
939/// A structure for storing the information associated with a name that has
940/// been assumed to be a template name (despite finding no TemplateDecls).
942 friend class ASTContext;
943
945 : UncommonTemplateNameStorage(Assumed, 0, 0), Name(Name) {}
946 DeclarationName Name;
947
948public:
949 /// Get the name of the template.
950 DeclarationName getDeclName() const { return Name; }
951};
952
953} // namespace clang
954
955#endif // LLVM_CLANG_AST_DECLARATIONNAME_H
MatchType Type
StringRef P
static char ID
Definition: Arena.cpp:183
Defines the Diagnostic-related interfaces.
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
StringRef Identifier
Definition: Format.cpp:3009
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, QualType Ty)
Defines an enumeration for C++ overloaded operators.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y)
SourceRange Range
Definition: SemaObjC.cpp:758
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
__DEVICE__ void * memset(void *__a, int __b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
DeclarationNameLoc - Additional source/type location info for a declaration name.
static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo)
Construct location information for a constructor, destructor or conversion operator.
static DeclarationNameLoc makeCXXLiteralOperatorNameLoc(SourceLocation Loc)
Construct location information for a literal C++ operator.
SourceLocation getCXXLiteralOperatorNameLoc() const
Return the location of the literal operator name (without the operator keyword).
SourceLocation getCXXOperatorNameBeginLoc() const
Return the beginning location of the getCXXOperatorNameRange() range.
TypeSourceInfo * getNamedTypeInfo() const
Returns the source type info.
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc, SourceLocation EndLoc)
Construct location information for a non-literal C++ operator.
SourceLocation getCXXOperatorNameEndLoc() const
Return the end location of the getCXXOperatorNameRange() range.
SourceRange getCXXOperatorNameRange() const
Return the range of the operator name (without the operator keyword).
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceRange Range)
Construct location information for a non-literal C++ operator.
DeclarationNameTable is used to store and retrieve DeclarationName instances for the various kinds of...
DeclarationName getIdentifier(const IdentifierInfo *ID)
Create a declaration name that is a simple identifier.
DeclarationNameTable(const DeclarationNameTable &)=delete
DeclarationNameTable & operator=(const DeclarationNameTable &)=delete
DeclarationNameTable(DeclarationNameTable &&)=delete
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationNameTable & operator=(DeclarationNameTable &&)=delete
The name of a declaration.
static DeclarationName getFromOpaqueInteger(uintptr_t P)
Get a declaration name from an opaque integer returned by getAsOpaqueInteger.
uintptr_t getAsOpaqueInteger() const
Get the representation of this declaration name as an opaque integer.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
static DeclarationName getEmptyMarker()
static DeclarationName getFromOpaquePtr(void *P)
Get a declaration name from an opaque pointer returned by getAsOpaquePtr.
static DeclarationName getTombstoneMarker()
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
DeclarationName(Selector Sel)
Construct a declaration name from an Objective-C selector.
void * getAsOpaquePtr() const
Get the representation of this declaration name as an opaque pointer.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
friend bool operator==(DeclarationName LHS, DeclarationName RHS)
Determine whether the specified names are identical.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
friend bool operator!=(DeclarationName LHS, DeclarationName RHS)
Determine whether the specified names are different.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isObjCZeroArgSelector() const
NameKind
The kind of the name stored in this DeclarationName.
void * getFETokenInfo() const
Get and set FETokenInfo.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
bool isObjCOneArgSelector() const
DeclarationName()
Construct an empty declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
DeclarationName(const IdentifierInfo *II)
Construct a declaration name from an IdentifierInfo *.
void setFETokenInfo(void *T)
bool isIdentifier() const
Predicate functions for querying what type of name this is.
One of these records is kept for each identifier that is lexed.
This represents a decl that may have a name.
Definition: Decl.h:249
A (possibly-)qualified type.
Definition: Type.h:941
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1115
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1189
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
A container of type source information.
Definition: Type.h:7726
The base class of the type hierarchy.
Definition: Type.h:1829
Implementation class used to describe either a set of overloaded template names or an already-substit...
Definition: TemplateName.h:48
Contains extra information for the name of a C++ deduction guide.
void Profile(llvm::FoldingSetNodeID &ID)
Contains the actual identifier that makes up the name of a C++ literal operator.
void Profile(llvm::FoldingSetNodeID &FSID)
Contains extra information for the name of an overloaded operator in C++, such as "operator+.
CXXSpecialNameExtra records the type associated with one of the "special" kinds of declaration names ...
void Profile(llvm::FoldingSetNodeID &ID)
DeclarationNameExtra is used as a base of various uncommon special names.
ExtraKind
The kind of "extra" information stored in the DeclarationName.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
@ NUM_OVERLOADED_OPERATORS
Definition: OperatorKinds.h:26
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
const FunctionProtoType * T
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:60
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define bool
Definition: stdbool.h:24
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setInfo(const DeclarationNameLoc &Info)
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
const DeclarationNameLoc & getInfo() const
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc, DeclarationNameLoc LocInfo)
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
SourceLocation getEndLoc() const LLVM_READONLY
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
static clang::DeclarationName getEmptyKey()
static clang::DeclarationName getTombstoneKey()
static bool isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS)
static unsigned getHashValue(clang::DeclarationName Name)
static void * getAsVoidPointer(clang::DeclarationName P)
static clang::DeclarationName getFromVoidPointer(void *P)