//===- DeclarationName.h - Representation of declaration names --*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file declares the DeclarationName and DeclarationNameTable classes. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H #define LLVM_CLANG_AST_DECLARATIONNAME_H #include "clang/AST/Type.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/type_traits.h" #include <cassert> #include <cstdint> #include <cstring> #include <string> namespace clang { class ASTContext; template <typename> class CanQual; class DeclarationName; class DeclarationNameTable; struct PrintingPolicy; class TemplateDecl; class TypeSourceInfo; CanQualType; namespace detail { /// CXXSpecialNameExtra records the type associated with one of the "special" /// kinds of declaration names in C++, e.g., constructors, destructors, and /// conversion functions. Note that CXXSpecialName is used for C++ constructor, /// destructor and conversion functions, but the actual kind is not stored in /// CXXSpecialName. Instead we use three different FoldingSet<CXXSpecialName> /// in DeclarationNameTable. class alignas(IdentifierInfoAlignment) CXXSpecialNameExtra : public llvm::FoldingSetNode { … }; /// Contains extra information for the name of a C++ deduction guide. class alignas(IdentifierInfoAlignment) CXXDeductionGuideNameExtra : public detail::DeclarationNameExtra, public llvm::FoldingSetNode { … }; /// Contains extra information for the name of an overloaded operator /// in C++, such as "operator+. This do not includes literal or conversion /// operators. For literal operators see CXXLiteralOperatorIdName and for /// conversion operators see CXXSpecialNameExtra. class alignas(IdentifierInfoAlignment) CXXOperatorIdName { … }; /// Contains the actual identifier that makes up the /// name of a C++ literal operator. class alignas(IdentifierInfoAlignment) CXXLiteralOperatorIdName : public detail::DeclarationNameExtra, public llvm::FoldingSetNode { … }; } // namespace detail /// The name of a declaration. In the common case, this just stores /// an IdentifierInfo pointer to a normal name. However, it also provides /// encodings for Objective-C selectors (optimizing zero- and one-argument /// selectors, which make up 78% percent of all selectors in Cocoa.h), /// special C++ names for constructors, destructors, and conversion functions, /// and C++ overloaded operators. class DeclarationName { … }; raw_ostream &operator<<(raw_ostream &OS, DeclarationName N); /// Ordering on two declaration names. If both names are identifiers, /// this provides a lexicographical ordering. inline bool operator<(DeclarationName LHS, DeclarationName RHS) { … } /// Ordering on two declaration names. If both names are identifiers, /// this provides a lexicographical ordering. inline bool operator>(DeclarationName LHS, DeclarationName RHS) { … } /// Ordering on two declaration names. If both names are identifiers, /// this provides a lexicographical ordering. inline bool operator<=(DeclarationName LHS, DeclarationName RHS) { … } /// Ordering on two declaration names. If both names are identifiers, /// this provides a lexicographical ordering. inline bool operator>=(DeclarationName LHS, DeclarationName RHS) { … } /// DeclarationNameTable is used to store and retrieve DeclarationName /// instances for the various kinds of declaration names, e.g., normal /// identifiers, C++ constructor names, etc. This class contains /// uniqued versions of each of the C++ special names, which can be /// retrieved using its member functions (e.g., getCXXConstructorName). class DeclarationNameTable { … }; /// DeclarationNameLoc - Additional source/type location info /// for a declaration name. Needs a DeclarationName in order /// to be interpreted correctly. class DeclarationNameLoc { … }; /// DeclarationNameInfo - A collector data type for bundling together /// a DeclarationName and the corresponding source/type location info. struct DeclarationNameInfo { … }; /// Insertion operator for partial diagnostics. This allows binding /// DeclarationName's into a partial diagnostic with <<. inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD, DeclarationName N) { … } raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo); } // namespace clang namespace llvm { /// Define DenseMapInfo so that DeclarationNames can be used as keys /// in DenseMap and DenseSets. template<> struct DenseMapInfo<clang::DeclarationName> { … }; template <> struct PointerLikeTypeTraits<clang::DeclarationName> { … }; } // namespace llvm // The definition of AssumedTemplateStorage is factored out of TemplateName to // resolve a cyclic dependency between it and DeclarationName (via Type). namespace clang { /// A structure for storing the information associated with a name that has /// been assumed to be a template name (despite finding no TemplateDecls). class AssumedTemplateStorage : public UncommonTemplateNameStorage { … }; } // namespace clang #endif // LLVM_CLANG_AST_DECLARATIONNAME_H