//===--- DeclID.h - ID number for deserialized declarations ----*- 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 defines DeclID class family to describe the deserialized // declarations. The DeclID is widely used in AST via LazyDeclPtr, or calls to // `ExternalASTSource::getExternalDecl`. It will be helpful for type safety to // require the use of `DeclID` to explicit. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_AST_DECLID_H #define LLVM_CLANG_AST_DECLID_H #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/iterator.h" namespace clang { /// Predefined declaration IDs. /// /// These declaration IDs correspond to predefined declarations in the AST /// context, such as the NULL declaration ID. Such declarations are never /// actually serialized, since they will be built by the AST context when /// it is created. enum PredefinedDeclIDs { … }; /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the /// LocalDeclID to the ModuleFile been writting is equal to the GlobalDeclID. /// Outside the serializer, all the DeclID been used should be GlobalDeclID. /// We can translate a LocalDeclID to the GlobalDeclID by /// `ASTReader::getGlobalDeclID()`. class DeclIDBase { … }; class ASTWriter; class ASTReader; namespace serialization { class ModuleFile; } // namespace serialization class LocalDeclID : public DeclIDBase { … }; class GlobalDeclID : public DeclIDBase { … }; /// A helper iterator adaptor to convert the iterators to /// `SmallVector<SomeDeclID>` to the iterators to `SmallVector<OtherDeclID>`. template <class FromTy, class ToTy> class DeclIDIterator : public llvm::iterator_adaptor_base<DeclIDIterator<FromTy, ToTy>, const FromTy *, std::forward_iterator_tag, ToTy> { … }; } // namespace clang namespace llvm { template <> struct DenseMapInfo<clang::GlobalDeclID> { … }; template <> struct DenseMapInfo<clang::LocalDeclID> { … }; } // namespace llvm #endif