1 //===--- ASTReaderInternals.h - AST Reader Internals ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides internal definitions used in the AST reader.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
14 #define LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
16 #include "clang/AST/DeclarationName.h"
17 #include "clang/Serialization/ASTBitCodes.h"
18 #include "llvm/Support/Endian.h"
19 #include "llvm/Support/OnDiskHashTable.h"
26 struct HeaderFileInfo;
29 namespace serialization {
35 /// \brief Class that performs name lookup into a DeclContext stored
37 class ASTDeclContextNameLookupTrait {
42 /// \brief Pair of begin/end iterators for DeclIDs.
44 /// Note that these declaration IDs are local to the module that contains this
45 /// particular lookup t
46 typedef llvm::support::ulittle32_t LE32DeclID;
47 typedef std::pair<LE32DeclID *, LE32DeclID *> data_type;
48 typedef unsigned hash_value_type;
49 typedef unsigned offset_type;
51 /// \brief Special internal key for declaration names.
52 /// The hash table creates keys for comparison; we do not create
53 /// a DeclarationName for the internal key to avoid deserializing types.
55 DeclarationName::NameKind Kind;
57 DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { }
60 typedef DeclarationName external_key_type;
61 typedef DeclNameKey internal_key_type;
63 explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
64 : Reader(Reader), F(F) { }
66 static bool EqualKey(const internal_key_type& a,
67 const internal_key_type& b) {
68 return a.Kind == b.Kind && a.Data == b.Data;
71 static hash_value_type ComputeHash(const DeclNameKey &Key);
72 static internal_key_type GetInternalKey(const external_key_type& Name);
74 static std::pair<unsigned, unsigned>
75 ReadKeyDataLength(const unsigned char*& d);
77 internal_key_type ReadKey(const unsigned char* d, unsigned);
79 data_type ReadData(internal_key_type, const unsigned char* d,
83 /// \brief Base class for the trait describing the on-disk hash table for the
84 /// identifiers in an AST file.
86 /// This class is not useful by itself; rather, it provides common
87 /// functionality for accessing the on-disk hash table of identifiers
88 /// in an AST file. Different subclasses customize that functionality
89 /// based on what information they are interested in. Those subclasses
90 /// must provide the \c data_type typedef and the ReadData operation,
92 class ASTIdentifierLookupTraitBase {
94 typedef StringRef external_key_type;
95 typedef StringRef internal_key_type;
96 typedef unsigned hash_value_type;
97 typedef unsigned offset_type;
99 static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
103 static hash_value_type ComputeHash(const internal_key_type& a);
105 static std::pair<unsigned, unsigned>
106 ReadKeyDataLength(const unsigned char*& d);
108 // This hopefully will just get inlined and removed by the optimizer.
109 static const internal_key_type&
110 GetInternalKey(const external_key_type& x) { return x; }
112 // This hopefully will just get inlined and removed by the optimizer.
113 static const external_key_type&
114 GetExternalKey(const internal_key_type& x) { return x; }
116 static internal_key_type ReadKey(const unsigned char* d, unsigned n);
119 /// \brief Class that performs lookup for an identifier stored in an AST file.
120 class ASTIdentifierLookupTrait : public ASTIdentifierLookupTraitBase {
124 // If we know the IdentifierInfo in advance, it is here and we will
125 // not build a new one. Used when deserializing information about an
126 // identifier that was constructed before the AST file was read.
127 IdentifierInfo *KnownII;
130 typedef IdentifierInfo * data_type;
132 ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
133 IdentifierInfo *II = nullptr)
134 : Reader(Reader), F(F), KnownII(II) { }
136 data_type ReadData(const internal_key_type& k,
137 const unsigned char* d,
140 ASTReader &getReader() const { return Reader; }
143 /// \brief The on-disk hash table used to contain information about
144 /// all of the identifiers in the program.
145 typedef llvm::OnDiskIterableChainedHashTable<ASTIdentifierLookupTrait>
146 ASTIdentifierLookupTable;
148 /// \brief Class that performs lookup for a selector's entries in the global
149 /// method pool stored in an AST file.
150 class ASTSelectorLookupTrait {
157 unsigned InstanceBits;
158 unsigned FactoryBits;
159 bool InstanceHasMoreThanOneDecl;
160 bool FactoryHasMoreThanOneDecl;
161 SmallVector<ObjCMethodDecl *, 2> Instance;
162 SmallVector<ObjCMethodDecl *, 2> Factory;
165 typedef Selector external_key_type;
166 typedef external_key_type internal_key_type;
167 typedef unsigned hash_value_type;
168 typedef unsigned offset_type;
170 ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
171 : Reader(Reader), F(F) { }
173 static bool EqualKey(const internal_key_type& a,
174 const internal_key_type& b) {
178 static hash_value_type ComputeHash(Selector Sel);
180 static const internal_key_type&
181 GetInternalKey(const external_key_type& x) { return x; }
183 static std::pair<unsigned, unsigned>
184 ReadKeyDataLength(const unsigned char*& d);
186 internal_key_type ReadKey(const unsigned char* d, unsigned);
187 data_type ReadData(Selector, const unsigned char* d, unsigned DataLen);
190 /// \brief The on-disk hash table used for the global method pool.
191 typedef llvm::OnDiskChainedHashTable<ASTSelectorLookupTrait>
192 ASTSelectorLookupTable;
194 /// \brief Trait class used to search the on-disk hash table containing all of
195 /// the header search information.
197 /// The on-disk hash table contains a mapping from each header path to
198 /// information about that header (how many times it has been included, its
199 /// controlling macro, etc.). Note that we actually hash based on the size
200 /// and mtime, and support "deep" comparisons of file names based on current
201 /// inode numbers, so that the search can cope with non-normalized path names
203 class HeaderFileInfoTrait {
207 const char *FrameworkStrings;
210 typedef const FileEntry *external_key_type;
212 struct internal_key_type {
215 const char *Filename;
218 typedef const internal_key_type &internal_key_ref;
220 typedef HeaderFileInfo data_type;
221 typedef unsigned hash_value_type;
222 typedef unsigned offset_type;
224 HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS,
225 const char *FrameworkStrings)
226 : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { }
228 static hash_value_type ComputeHash(internal_key_ref ikey);
229 static internal_key_type GetInternalKey(const FileEntry *FE);
230 bool EqualKey(internal_key_ref a, internal_key_ref b);
232 static std::pair<unsigned, unsigned>
233 ReadKeyDataLength(const unsigned char*& d);
235 static internal_key_type ReadKey(const unsigned char *d, unsigned);
237 data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
240 /// \brief The on-disk hash table used for known header files.
241 typedef llvm::OnDiskChainedHashTable<HeaderFileInfoTrait>
242 HeaderFileInfoLookupTable;
244 } // end namespace clang::serialization::reader
245 } // end namespace clang::serialization
246 } // end namespace clang