clang  8.0.0svn
DeclarationName.h
Go to the documentation of this file.
1 //===- DeclarationName.h - Representation of declaration names --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the DeclarationName and DeclarationNameTable classes.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
15 #define LLVM_CLANG_AST_DECLARATIONNAME_H
16 
17 #include "clang/AST/Type.h"
18 #include "clang/Basic/Diagnostic.h"
23 #include "llvm/ADT/DenseMapInfo.h"
24 #include "llvm/ADT/FoldingSet.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 
32 namespace clang {
33 
34 class ASTContext;
35 template <typename> class CanQual;
36 class DeclarationName;
37 class DeclarationNameTable;
38 class MultiKeywordSelector;
39 struct PrintingPolicy;
40 class TemplateDecl;
41 class TypeSourceInfo;
42 class UsingDirectiveDecl;
43 
44 using CanQualType = CanQual<Type>;
45 
46 namespace detail {
47 
48 /// CXXSpecialNameExtra records the type associated with one of the "special"
49 /// kinds of declaration names in C++, e.g., constructors, destructors, and
50 /// conversion functions. Note that CXXSpecialName is used for C++ constructor,
51 /// destructor and conversion functions, but the actual kind is not stored in
52 /// CXXSpecialName. Instead we use three different FoldingSet<CXXSpecialName>
53 /// in DeclarationNameTable.
54 class alignas(IdentifierInfoAlignment) CXXSpecialNameExtra
55  : public llvm::FoldingSetNode {
56  friend class clang::DeclarationName;
58 
59  /// The type associated with this declaration name.
60  QualType Type;
61 
62  /// Extra information associated with this declaration name that
63  /// can be used by the front end. All bits are really needed
64  /// so it is not possible to stash something in the low order bits.
65  void *FETokenInfo;
66 
67  CXXSpecialNameExtra(QualType QT) : Type(QT), FETokenInfo(nullptr) {}
68 
69 public:
70  void Profile(llvm::FoldingSetNodeID &ID) {
71  ID.AddPointer(Type.getAsOpaquePtr());
72  }
73 };
74 
75 /// Contains extra information for the name of a C++ deduction guide.
76 class alignas(IdentifierInfoAlignment) CXXDeductionGuideNameExtra
78  public llvm::FoldingSetNode {
79  friend class clang::DeclarationName;
81 
82  /// The template named by the deduction guide.
83  TemplateDecl *Template;
84 
85  /// Extra information associated with this operator name that
86  /// can be used by the front end. All bits are really needed
87  /// so it is not possible to stash something in the low order bits.
88  void *FETokenInfo;
89 
91  : DeclarationNameExtra(CXXDeductionGuideName), Template(TD),
92  FETokenInfo(nullptr) {}
93 
94 public:
95  void Profile(llvm::FoldingSetNodeID &ID) { ID.AddPointer(Template); }
96 };
97 
98 /// Contains extra information for the name of an overloaded operator
99 /// in C++, such as "operator+. This do not includes literal or conversion
100 /// operators. For literal operators see CXXLiteralOperatorIdName and for
101 /// conversion operators see CXXSpecialNameExtra.
102 class alignas(IdentifierInfoAlignment) CXXOperatorIdName {
105 
106  /// The kind of this operator.
108 
109  /// Extra information associated with this operator name that
110  /// can be used by the front end. All bits are really needed
111  /// so it is not possible to stash something in the low order bits.
112  void *FETokenInfo = nullptr;
113 };
114 
115 /// Contains the actual identifier that makes up the
116 /// name of a C++ literal operator.
117 class alignas(IdentifierInfoAlignment) CXXLiteralOperatorIdName
119  public llvm::FoldingSetNode {
122 
124 
125  /// Extra information associated with this operator name that
126  /// can be used by the front end. All bits are really needed
127  /// so it is not possible to stash something in the low order bits.
128  void *FETokenInfo;
129 
131  : DeclarationNameExtra(CXXLiteralOperatorName), ID(II),
132  FETokenInfo(nullptr) {}
133 
134 public:
135  void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); }
136 };
137 
138 } // namespace detail
139 
140 /// The name of a declaration. In the common case, this just stores
141 /// an IdentifierInfo pointer to a normal name. However, it also provides
142 /// encodings for Objective-C selectors (optimizing zero- and one-argument
143 /// selectors, which make up 78% percent of all selectors in Cocoa.h),
144 /// special C++ names for constructors, destructors, and conversion functions,
145 /// and C++ overloaded operators.
147  friend class DeclarationNameTable;
148  friend class NamedDecl;
149 
150  /// StoredNameKind represent the kind of name that is actually stored in the
151  /// upper bits of the Ptr field. This is only used internally.
152  ///
153  /// NameKind, StoredNameKind, and DeclarationNameExtra::ExtraKind
154  /// must satisfy the following properties. These properties enable
155  /// efficient conversion between the various kinds.
156  ///
157  /// * The first seven enumerators of StoredNameKind must have the same
158  /// numerical value as the first seven enumerators of NameKind.
159  /// This enable efficient conversion between the two enumerations
160  /// in the usual case.
161  ///
162  /// * The enumerations values of DeclarationNameExtra::ExtraKind must start
163  /// at zero, and correspond to the numerical value of the first non-inline
164  /// enumeration values of NameKind minus an offset. This makes conversion
165  /// between DeclarationNameExtra::ExtraKind and NameKind possible with
166  /// a single addition/substraction.
167  ///
168  /// * The enumeration values of Selector::IdentifierInfoFlag must correspond
169  /// to the relevant enumeration values of StoredNameKind.
170  /// More specifically:
171  /// * ZeroArg == StoredObjCZeroArgSelector,
172  /// * OneArg == StoredObjCOneArgSelector,
173  /// * MultiArg == StoredDeclarationNameExtra
174  ///
175  /// * PtrMask must mask the low 3 bits of Ptr.
176  enum StoredNameKind {
177  StoredIdentifier = 0,
178  StoredObjCZeroArgSelector = Selector::ZeroArg,
179  StoredObjCOneArgSelector = Selector::OneArg,
180  StoredCXXConstructorName = 3,
181  StoredCXXDestructorName = 4,
182  StoredCXXConversionFunctionName = 5,
183  StoredCXXOperatorName = 6,
184  StoredDeclarationNameExtra = Selector::MultiArg,
185  PtrMask = 7,
186  UncommonNameKindOffset = 8
187  };
188 
189  static_assert(alignof(IdentifierInfo) >= 8 &&
190  alignof(detail::DeclarationNameExtra) >= 8 &&
191  alignof(detail::CXXSpecialNameExtra) >= 8 &&
192  alignof(detail::CXXOperatorIdName) >= 8 &&
193  alignof(detail::CXXDeductionGuideNameExtra) >= 8 &&
194  alignof(detail::CXXLiteralOperatorIdName) >= 8,
195  "The various classes that DeclarationName::Ptr can point to"
196  " must be at least aligned to 8 bytes!");
197 
198 public:
199  /// The kind of the name stored in this DeclarationName.
200  /// The first 7 enumeration values are stored inline and correspond
201  /// to frequently used kinds. The rest is stored in DeclarationNameExtra
202  /// and correspond to infrequently used kinds.
203  enum NameKind {
204  Identifier = StoredIdentifier,
205  ObjCZeroArgSelector = StoredObjCZeroArgSelector,
206  ObjCOneArgSelector = StoredObjCOneArgSelector,
207  CXXConstructorName = StoredCXXConstructorName,
208  CXXDestructorName = StoredCXXDestructorName,
209  CXXConversionFunctionName = StoredCXXConversionFunctionName,
210  CXXOperatorName = StoredCXXOperatorName,
211  CXXDeductionGuideName = UncommonNameKindOffset +
213  CXXLiteralOperatorName =
214  UncommonNameKindOffset +
216  CXXUsingDirective = UncommonNameKindOffset +
218  ObjCMultiArgSelector = UncommonNameKindOffset +
220  };
221 
222 private:
223  /// The lowest three bits of Ptr are used to express what kind of name
224  /// we're actually storing, using the values of StoredNameKind. Depending
225  /// on the kind of name this is, the upper bits of Ptr may have one
226  /// of several different meanings:
227  ///
228  /// StoredIdentifier - The name is a normal identifier, and Ptr is
229  /// a normal IdentifierInfo pointer.
230  ///
231  /// StoredObjCZeroArgSelector - The name is an Objective-C
232  /// selector with zero arguments, and Ptr is an IdentifierInfo
233  /// pointer pointing to the selector name.
234  ///
235  /// StoredObjCOneArgSelector - The name is an Objective-C selector
236  /// with one argument, and Ptr is an IdentifierInfo pointer
237  /// pointing to the selector name.
238  ///
239  /// StoredCXXConstructorName - The name of a C++ constructor,
240  /// Ptr points to a CXXSpecialNameExtra.
241  ///
242  /// StoredCXXDestructorName - The name of a C++ destructor,
243  /// Ptr points to a CXXSpecialNameExtra.
244  ///
245  /// StoredCXXConversionFunctionName - The name of a C++ conversion function,
246  /// Ptr points to a CXXSpecialNameExtra.
247  ///
248  /// StoredCXXOperatorName - The name of an overloaded C++ operator,
249  /// Ptr points to a CXXOperatorIdName.
250  ///
251  /// StoredDeclarationNameExtra - Ptr is actually a pointer to a
252  /// DeclarationNameExtra structure, whose first value will tell us
253  /// whether this is an Objective-C selector, C++ deduction guide,
254  /// C++ literal operator, or C++ using directive.
255  uintptr_t Ptr = 0;
256 
257  StoredNameKind getStoredNameKind() const {
258  return static_cast<StoredNameKind>(Ptr & PtrMask);
259  }
260 
261  void *getPtr() const { return reinterpret_cast<void *>(Ptr & ~PtrMask); }
262 
263  void setPtrAndKind(const void *P, StoredNameKind Kind) {
264  uintptr_t PAsInteger = reinterpret_cast<uintptr_t>(P);
265  assert((Kind & ~PtrMask) == 0 &&
266  "Invalid StoredNameKind in setPtrAndKind!");
267  assert((PAsInteger & PtrMask) == 0 &&
268  "Improperly aligned pointer in setPtrAndKind!");
269  Ptr = PAsInteger | Kind;
270  }
271 
272  /// Construct a declaration name from a DeclarationNameExtra.
274  setPtrAndKind(Name, StoredDeclarationNameExtra);
275  }
276 
277  /// Construct a declaration name from a CXXSpecialNameExtra.
279  StoredNameKind StoredKind) {
280  assert((StoredKind == StoredCXXConstructorName ||
281  StoredKind == StoredCXXDestructorName ||
282  StoredKind == StoredCXXConversionFunctionName) &&
283  "Invalid StoredNameKind when constructing a DeclarationName"
284  " from a CXXSpecialNameExtra!");
285  setPtrAndKind(Name, StoredKind);
286  }
287 
288  /// Construct a DeclarationName from a CXXOperatorIdName.
290  setPtrAndKind(Name, StoredCXXOperatorName);
291  }
292 
293  /// Assert that the stored pointer points to an IdentifierInfo and return it.
294  IdentifierInfo *castAsIdentifierInfo() const {
295  assert((getStoredNameKind() == StoredIdentifier) &&
296  "DeclarationName does not store an IdentifierInfo!");
297  return static_cast<IdentifierInfo *>(getPtr());
298  }
299 
300  /// Assert that the stored pointer points to a DeclarationNameExtra
301  /// and return it.
302  detail::DeclarationNameExtra *castAsExtra() const {
303  assert((getStoredNameKind() == StoredDeclarationNameExtra) &&
304  "DeclarationName does not store an Extra structure!");
305  return static_cast<detail::DeclarationNameExtra *>(getPtr());
306  }
307 
308  /// Assert that the stored pointer points to a CXXSpecialNameExtra
309  /// and return it.
310  detail::CXXSpecialNameExtra *castAsCXXSpecialNameExtra() const {
311  assert((getStoredNameKind() == StoredCXXConstructorName ||
312  getStoredNameKind() == StoredCXXDestructorName ||
313  getStoredNameKind() == StoredCXXConversionFunctionName) &&
314  "DeclarationName does not store a CXXSpecialNameExtra!");
315  return static_cast<detail::CXXSpecialNameExtra *>(getPtr());
316  }
317 
318  /// Assert that the stored pointer points to a CXXOperatorIdName
319  /// and return it.
320  detail::CXXOperatorIdName *castAsCXXOperatorIdName() const {
321  assert((getStoredNameKind() == StoredCXXOperatorName) &&
322  "DeclarationName does not store a CXXOperatorIdName!");
323  return static_cast<detail::CXXOperatorIdName *>(getPtr());
324  }
325 
326  /// Assert that the stored pointer points to a CXXDeductionGuideNameExtra
327  /// and return it.
328  detail::CXXDeductionGuideNameExtra *castAsCXXDeductionGuideNameExtra() const {
329  assert(getNameKind() == CXXDeductionGuideName &&
330  "DeclarationName does not store a CXXDeductionGuideNameExtra!");
331  return static_cast<detail::CXXDeductionGuideNameExtra *>(getPtr());
332  }
333 
334  /// Assert that the stored pointer points to a CXXLiteralOperatorIdName
335  /// and return it.
336  detail::CXXLiteralOperatorIdName *castAsCXXLiteralOperatorIdName() const {
337  assert(getNameKind() == CXXLiteralOperatorName &&
338  "DeclarationName does not store a CXXLiteralOperatorIdName!");
339  return static_cast<detail::CXXLiteralOperatorIdName *>(getPtr());
340  }
341 
342  /// Get and set the FETokenInfo in the less common cases where the
343  /// declaration name do not point to an identifier.
344  void *getFETokenInfoSlow() const;
345  void setFETokenInfoSlow(void *T);
346 
347 public:
348  /// Construct an empty declaration name.
349  DeclarationName() { setPtrAndKind(nullptr, StoredIdentifier); }
350 
351  /// Construct a declaration name from an IdentifierInfo *.
353  setPtrAndKind(II, StoredIdentifier);
354  }
355 
356  /// Construct a declaration name from an Objective-C selector.
357  DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) {}
358 
359  /// Returns the name for all C++ using-directives.
361  // Single instance of DeclarationNameExtra for using-directive
362  static detail::DeclarationNameExtra UDirExtra(
364  return DeclarationName(&UDirExtra);
365  }
366 
367  /// Evaluates true when this declaration name is non-empty.
368  explicit operator bool() const {
369  return getPtr() || (getStoredNameKind() != StoredIdentifier);
370  }
371 
372  /// Evaluates true when this declaration name is empty.
373  bool isEmpty() const { return !*this; }
374 
375  /// Predicate functions for querying what type of name this is.
376  bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
377  bool isObjCZeroArgSelector() const {
378  return getStoredNameKind() == StoredObjCZeroArgSelector;
379  }
380  bool isObjCOneArgSelector() const {
381  return getStoredNameKind() == StoredObjCOneArgSelector;
382  }
383 
384  /// Determine what kind of name this is.
386  // We rely on the fact that the first 7 NameKind and StoredNameKind
387  // have the same numerical value. This makes the usual case efficient.
388  StoredNameKind StoredKind = getStoredNameKind();
389  if (StoredKind != StoredDeclarationNameExtra)
390  return static_cast<NameKind>(StoredKind);
391  // We have to consult DeclarationNameExtra. We rely on the fact that the
392  // enumeration values of ExtraKind correspond to the enumeration values of
393  // NameKind minus an offset of UncommonNameKindOffset.
394  unsigned ExtraKind = castAsExtra()->getKind();
395  return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind);
396  }
397 
398  /// Determines whether the name itself is dependent, e.g., because it
399  /// involves a C++ type that is itself dependent.
400  ///
401  /// Note that this does not capture all of the notions of "dependent name",
402  /// because an identifier can be a dependent name if it is used as the
403  /// callee in a call expression with dependent arguments.
404  bool isDependentName() const;
405 
406  /// Retrieve the human-readable string for this name.
407  std::string getAsString() const;
408 
409  /// Retrieve the IdentifierInfo * stored in this declaration name,
410  /// or null if this declaration name isn't a simple identifier.
412  if (isIdentifier())
413  return castAsIdentifierInfo();
414  return nullptr;
415  }
416 
417  /// Get the representation of this declaration name as an opaque integer.
418  uintptr_t getAsOpaqueInteger() const { return Ptr; }
419 
420  /// Get the representation of this declaration name as an opaque pointer.
421  void *getAsOpaquePtr() const { return reinterpret_cast<void *>(Ptr); }
422 
423  /// Get a declaration name from an opaque pointer returned by getAsOpaquePtr.
425  DeclarationName N;
426  N.Ptr = reinterpret_cast<uintptr_t>(P);
427  return N;
428  }
429 
430  /// Get a declaration name from an opaque integer
431  /// returned by getAsOpaqueInteger.
433  DeclarationName N;
434  N.Ptr = P;
435  return N;
436  }
437 
438  /// If this name is one of the C++ names (of a constructor, destructor,
439  /// or conversion function), return the type associated with that name.
441  if (getStoredNameKind() == StoredCXXConstructorName ||
442  getStoredNameKind() == StoredCXXDestructorName ||
443  getStoredNameKind() == StoredCXXConversionFunctionName) {
444  assert(getPtr() && "getCXXNameType on a null DeclarationName!");
445  return castAsCXXSpecialNameExtra()->Type;
446  }
447  return QualType();
448  }
449 
450  /// If this name is the name of a C++ deduction guide, return the
451  /// template associated with that name.
453  if (getNameKind() == CXXDeductionGuideName) {
454  assert(getPtr() &&
455  "getCXXDeductionGuideTemplate on a null DeclarationName!");
456  return castAsCXXDeductionGuideNameExtra()->Template;
457  }
458  return nullptr;
459  }
460 
461  /// If this name is the name of an overloadable operator in C++
462  /// (e.g., @c operator+), retrieve the kind of overloaded operator.
464  if (getStoredNameKind() == StoredCXXOperatorName) {
465  assert(getPtr() && "getCXXOverloadedOperator on a null DeclarationName!");
466  return castAsCXXOperatorIdName()->Kind;
467  }
468  return OO_None;
469  }
470 
471  /// If this name is the name of a literal operator,
472  /// retrieve the identifier associated with it.
474  if (getNameKind() == CXXLiteralOperatorName) {
475  assert(getPtr() && "getCXXLiteralIdentifier on a null DeclarationName!");
476  return castAsCXXLiteralOperatorIdName()->ID;
477  }
478  return nullptr;
479  }
480 
481  /// Get the Objective-C selector stored in this declaration name.
483  assert((getNameKind() == ObjCZeroArgSelector ||
484  getNameKind() == ObjCOneArgSelector ||
485  getNameKind() == ObjCMultiArgSelector || !getPtr()) &&
486  "Not a selector!");
487  return Selector(Ptr);
488  }
489 
490  /// Get and set FETokenInfo. The language front-end is allowed to associate
491  /// arbitrary metadata with some kinds of declaration names, including normal
492  /// identifiers and C++ constructors, destructors, and conversion functions.
493  void *getFETokenInfo() const {
494  assert(getPtr() && "getFETokenInfo on an empty DeclarationName!");
495  if (getStoredNameKind() == StoredIdentifier)
496  return castAsIdentifierInfo()->getFETokenInfo();
497  return getFETokenInfoSlow();
498  }
499 
500  void setFETokenInfo(void *T) {
501  assert(getPtr() && "setFETokenInfo on an empty DeclarationName!");
502  if (getStoredNameKind() == StoredIdentifier)
503  castAsIdentifierInfo()->setFETokenInfo(T);
504  else
505  setFETokenInfoSlow(T);
506  }
507 
508  /// Determine whether the specified names are identical.
510  return LHS.Ptr == RHS.Ptr;
511  }
512 
513  /// Determine whether the specified names are different.
515  return LHS.Ptr != RHS.Ptr;
516  }
517 
519  DeclarationName Name;
520  Name.Ptr = uintptr_t(-1);
521  return Name;
522  }
523 
525  DeclarationName Name;
526  Name.Ptr = uintptr_t(-2);
527  return Name;
528  }
529 
530  static int compare(DeclarationName LHS, DeclarationName RHS);
531 
532  void print(raw_ostream &OS, const PrintingPolicy &Policy);
533 
534  void dump() const;
535 };
536 
537 raw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
538 
539 /// Ordering on two declaration names. If both names are identifiers,
540 /// this provides a lexicographical ordering.
542  return DeclarationName::compare(LHS, RHS) < 0;
543 }
544 
545 /// Ordering on two declaration names. If both names are identifiers,
546 /// this provides a lexicographical ordering.
548  return DeclarationName::compare(LHS, RHS) > 0;
549 }
550 
551 /// Ordering on two declaration names. If both names are identifiers,
552 /// this provides a lexicographical ordering.
554  return DeclarationName::compare(LHS, RHS) <= 0;
555 }
556 
557 /// Ordering on two declaration names. If both names are identifiers,
558 /// this provides a lexicographical ordering.
560  return DeclarationName::compare(LHS, RHS) >= 0;
561 }
562 
563 /// DeclarationNameTable is used to store and retrieve DeclarationName
564 /// instances for the various kinds of declaration names, e.g., normal
565 /// identifiers, C++ constructor names, etc. This class contains
566 /// uniqued versions of each of the C++ special names, which can be
567 /// retrieved using its member functions (e.g., getCXXConstructorName).
569  /// Used to allocate elements in the FoldingSets below.
570  const ASTContext &Ctx;
571 
572  /// Manage the uniqued CXXSpecialNameExtra representing C++ constructors.
573  /// getCXXConstructorName and getCXXSpecialName can be used to obtain
574  /// a DeclarationName from the corresponding type of the constructor.
575  llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames;
576 
577  /// Manage the uniqued CXXSpecialNameExtra representing C++ destructors.
578  /// getCXXDestructorName and getCXXSpecialName can be used to obtain
579  /// a DeclarationName from the corresponding type of the destructor.
580  llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames;
581 
582  /// Manage the uniqued CXXSpecialNameExtra representing C++ conversion
583  /// functions. getCXXConversionFunctionName and getCXXSpecialName can be
584  /// used to obtain a DeclarationName from the corresponding type of the
585  /// conversion function.
586  llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames;
587 
588  /// Manage the uniqued CXXOperatorIdName, which contain extra information
589  /// for the name of overloaded C++ operators. getCXXOperatorName
590  /// can be used to obtain a DeclarationName from the operator kind.
592 
593  /// Manage the uniqued CXXLiteralOperatorIdName, which contain extra
594  /// information for the name of C++ literal operators.
595  /// getCXXLiteralOperatorName can be used to obtain a DeclarationName
596  /// from the corresponding IdentifierInfo.
597  llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames;
598 
599  /// Manage the uniqued CXXDeductionGuideNameExtra, which contain
600  /// extra information for the name of a C++ deduction guide.
601  /// getCXXDeductionGuideName can be used to obtain a DeclarationName
602  /// from the corresponding template declaration.
603  llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames;
604 
605 public:
607  DeclarationNameTable(const DeclarationNameTable &) = delete;
608  DeclarationNameTable &operator=(const DeclarationNameTable &) = delete;
610  DeclarationNameTable &operator=(DeclarationNameTable &&) = delete;
611  ~DeclarationNameTable() = default;
612 
613  /// Create a declaration name that is a simple identifier.
615  return DeclarationName(ID);
616  }
617 
618  /// Returns the name of a C++ constructor for the given Type.
619  DeclarationName getCXXConstructorName(CanQualType Ty);
620 
621  /// Returns the name of a C++ destructor for the given Type.
622  DeclarationName getCXXDestructorName(CanQualType Ty);
623 
624  /// Returns the name of a C++ deduction guide for the given template.
625  DeclarationName getCXXDeductionGuideName(TemplateDecl *TD);
626 
627  /// Returns the name of a C++ conversion function for the given Type.
628  DeclarationName getCXXConversionFunctionName(CanQualType Ty);
629 
630  /// Returns a declaration name for special kind of C++ name,
631  /// e.g., for a constructor, destructor, or conversion function.
632  /// Kind must be one of:
633  /// * DeclarationName::CXXConstructorName,
634  /// * DeclarationName::CXXDestructorName or
635  /// * DeclarationName::CXXConversionFunctionName
637  CanQualType Ty);
638 
639  /// Get the name of the overloadable C++ operator corresponding to Op.
641  return DeclarationName(&CXXOperatorNames[Op]);
642  }
643 
644  /// Get the name of the literal operator function with II as the identifier.
645  DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
646 };
647 
648 /// DeclarationNameLoc - Additional source/type location info
649 /// for a declaration name. Needs a DeclarationName in order
650 /// to be interpreted correctly.
652  // The source location for identifier stored elsewhere.
653  // struct {} Identifier;
654 
655  // Type info for constructors, destructors and conversion functions.
656  // Locations (if any) for the tilde (destructor) or operator keyword
657  // (conversion) are stored elsewhere.
658  struct NT {
660  };
661 
662  // The location (if any) of the operator keyword is stored elsewhere.
663  struct CXXOpName {
664  unsigned BeginOpNameLoc;
665  unsigned EndOpNameLoc;
666  };
667 
668  // The location (if any) of the operator keyword is stored elsewhere.
669  struct CXXLitOpName {
670  unsigned OpNameLoc;
671  };
672 
673  // struct {} CXXUsingDirective;
674  // struct {} ObjCZeroArgSelector;
675  // struct {} ObjCOneArgSelector;
676  // struct {} ObjCMultiArgSelector;
677  union {
678  struct NT NamedType;
679  struct CXXOpName CXXOperatorName;
680  struct CXXLitOpName CXXLiteralOperatorName;
681  };
682 
684 
685  // FIXME: this should go away once all DNLocs are properly initialized.
686  DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
687 };
688 
689 /// DeclarationNameInfo - A collector data type for bundling together
690 /// a DeclarationName and the correspnding source/type location info.
692 private:
693  /// Name - The declaration name, also encoding name kind.
694  DeclarationName Name;
695 
696  /// Loc - The main source location for the declaration name.
697  SourceLocation NameLoc;
698 
699  /// Info - Further source/type location info for special kinds of names.
700  DeclarationNameLoc LocInfo;
701 
702 public:
703  // FIXME: remove it.
704  DeclarationNameInfo() = default;
705 
707  : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
708 
710  DeclarationNameLoc LocInfo)
711  : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
712 
713  /// getName - Returns the embedded declaration name.
714  DeclarationName getName() const { return Name; }
715 
716  /// setName - Sets the embedded declaration name.
717  void setName(DeclarationName N) { Name = N; }
718 
719  /// getLoc - Returns the main location of the declaration name.
720  SourceLocation getLoc() const { return NameLoc; }
721 
722  /// setLoc - Sets the main location of the declaration name.
723  void setLoc(SourceLocation L) { NameLoc = L; }
724 
725  const DeclarationNameLoc &getInfo() const { return LocInfo; }
726  DeclarationNameLoc &getInfo() { return LocInfo; }
727  void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
728 
729  /// getNamedTypeInfo - Returns the source type info associated to
730  /// the name. Assumes it is a constructor, destructor or conversion.
735  return LocInfo.NamedType.TInfo;
736  }
737 
738  /// setNamedTypeInfo - Sets the source type info associated to
739  /// the name. Assumes it is a constructor, destructor or conversion.
744  LocInfo.NamedType.TInfo = TInfo;
745  }
746 
747  /// getCXXOperatorNameRange - Gets the range of the operator name
748  /// (without the operator keyword). Assumes it is a (non-literal) operator.
751  return SourceRange(
754  );
755  }
756 
757  /// setCXXOperatorNameRange - Sets the range of the operator name
758  /// (without the operator keyword). Assumes it is a C++ operator.
763  }
764 
765  /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
766  /// operator name (not the operator keyword).
767  /// Assumes it is a literal operator.
770  return SourceLocation::
772  }
773 
774  /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
775  /// operator name (not the operator keyword).
776  /// Assumes it is a literal operator.
780  }
781 
782  /// Determine whether this name involves a template parameter.
783  bool isInstantiationDependent() const;
784 
785  /// Determine whether this name contains an unexpanded
786  /// parameter pack.
787  bool containsUnexpandedParameterPack() const;
788 
789  /// getAsString - Retrieve the human-readable string for this name.
790  std::string getAsString() const;
791 
792  /// printName - Print the human-readable name to a stream.
793  void printName(raw_ostream &OS) const;
794 
795  /// getBeginLoc - Retrieve the location of the first token.
796  SourceLocation getBeginLoc() const { return NameLoc; }
797 
798  /// getSourceRange - The range of the declaration name.
799  SourceRange getSourceRange() const LLVM_READONLY {
800  return SourceRange(getBeginLoc(), getEndLoc());
801  }
802 
803  SourceLocation getEndLoc() const LLVM_READONLY {
804  SourceLocation EndLoc = getEndLocPrivate();
805  return EndLoc.isValid() ? EndLoc : getBeginLoc();
806  }
807 
808 private:
809  SourceLocation getEndLocPrivate() const;
810 };
811 
812 /// Insertion operator for diagnostics. This allows sending DeclarationName's
813 /// into a diagnostic with <<.
815  DeclarationName N) {
818  return DB;
819 }
820 
821 /// Insertion operator for partial diagnostics. This allows binding
822 /// DeclarationName's into a partial diagnostic with <<.
824  DeclarationName N) {
827  return PD;
828 }
829 
830 inline raw_ostream &operator<<(raw_ostream &OS,
831  DeclarationNameInfo DNInfo) {
832  DNInfo.printName(OS);
833  return OS;
834 }
835 
836 } // namespace clang
837 
838 namespace llvm {
839 
840 /// Define DenseMapInfo so that DeclarationNames can be used as keys
841 /// in DenseMap and DenseSets.
842 template<>
843 struct DenseMapInfo<clang::DeclarationName> {
846  }
847 
850  }
851 
852  static unsigned getHashValue(clang::DeclarationName Name) {
854  }
855 
856  static inline bool
858  return LHS == RHS;
859  }
860 };
861 
862 template <>
863 struct isPodLike<clang::DeclarationName> { static const bool value = true; };
864 
865 } // namespace llvm
866 
867 #endif // LLVM_CLANG_AST_DECLARATIONNAME_H
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
void setInfo(const DeclarationNameLoc &Info)
StringRef Identifier
Definition: Format.cpp:1636
void Profile(llvm::FoldingSetNodeID &ID)
Smart pointer class that efficiently represents Objective-C method names.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
Definition: Type.h:642
DeclarationNameExtra is used as a base of various uncommon special names.
static bool isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS)
NameKind
The kind of the name stored in this DeclarationName.
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword)...
const DeclarationNameLoc & getInfo() const
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
C Language Family Type Representation.
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
StringRef P
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:335
The base class of the type hierarchy.
Definition: Type.h:1415
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
SourceLocation getEndLoc() const LLVM_READONLY
A container of type source information.
Definition: Decl.h:86
bool isEmpty() const
Evaluates true when this declaration name is empty.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void * getAsOpaquePtr() const
Get the representation of this declaration name as an opaque pointer.
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1153
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
NameKind getNameKind() const
Determine what kind of name this is.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
friend bool operator==(DeclarationName LHS, DeclarationName RHS)
Determine whether the specified names are identical.
static DeclarationName getFromOpaquePtr(void *P)
Get a declaration name from an opaque pointer returned by getAsOpaquePtr.
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword)...
uintptr_t getAsOpaqueInteger() const
Get the representation of this declaration name as an opaque integer.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
DeclarationName(const IdentifierInfo *II)
Construct a declaration name from an IdentifierInfo *.
Defines the Diagnostic-related interfaces.
static clang::DeclarationName getTombstoneKey()
void Profile(llvm::FoldingSetNodeID &ID)
__DEVICE__ void * memset(void *__a, int __b, size_t __c)
static unsigned getHashValue(clang::DeclarationName Name)
void * getAsOpaquePtr() const
Definition: Type.h:687
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1040
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:51
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y)
friend bool operator!=(DeclarationName LHS, DeclarationName RHS)
Determine whether the specified names are different.
DeclarationNameTable is used to store and retrieve DeclarationName instances for the various kinds of...
Contains extra information for the name of a C++ deduction guide.
Defines an enumeration for C++ overloaded operators.
DeclarationName(Selector Sel)
Construct a declaration name from an Objective-C selector.
#define bool
Definition: stdbool.h:31
static clang::DeclarationName getEmptyKey()
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
static DeclarationName getFromOpaqueInteger(uintptr_t P)
Get a declaration name from an opaque integer returned by getAsOpaqueInteger.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn&#39;t...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
SourceLocation getEnd() const
struct CXXOpName CXXOperatorName
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:90
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
bool isObjCOneArgSelector() const
Kind
void Profile(llvm::FoldingSetNodeID &FSID)
Encodes a location in the source.
DeclarationName getName() const
getName - Returns the embedded declaration name.
CXXSpecialNameExtra records the type associated with one of the "special" kinds of declaration names ...
DeclarationName getIdentifier(const IdentifierInfo *ID)
Create a declaration name that is a simple identifier.
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.
Contains extra information for the name of an overloaded operator in C++, such as "operator+...
void printName(raw_ostream &OS) const
printName - Print the human-readable name to a stream.
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc, DeclarationNameLoc LocInfo)
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
The name of a declaration.
DeclarationNameLoc & getInfo()
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
DeclarationName()
Construct an empty declaration name.
Not an overloaded operator.
Definition: OperatorKinds.h:23
struct CXXLitOpName CXXLiteralOperatorName
void * getFETokenInfo() const
Get and set FETokenInfo.
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.
static DeclarationName getTombstoneMarker()
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
Defines the clang::SourceLocation class and associated facilities.
static int compare(DeclarationName LHS, DeclarationName RHS)
void setFETokenInfo(void *T)
Contains the actual identifier that makes up the name of a C++ literal operator.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it...
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
static DeclarationName getEmptyMarker()
SourceLocation getBegin() const
bool isObjCZeroArgSelector() const