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_SERIALIZATION_ASTREADER_INTERNALS_H
14 #define LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
16 #include "clang/AST/DeclarationName.h"
17 #include "clang/Basic/OnDiskHashTable.h"
18 #include "clang/Serialization/ASTBitCodes.h"
19 #include "llvm/Support/Endian.h"
27 struct HeaderFileInfo;
30 namespace serialization {
36 /// \brief Class that performs name lookup into a DeclContext stored
38 class ASTDeclContextNameLookupTrait {
43 /// \brief Pair of begin/end iterators for DeclIDs.
45 /// Note that these declaration IDs are local to the module that contains this
46 /// particular lookup t
47 typedef llvm::support::ulittle32_t LE32DeclID;
48 typedef std::pair<LE32DeclID *, LE32DeclID *> data_type;
50 /// \brief Special internal key for declaration names.
51 /// The hash table creates keys for comparison; we do not create
52 /// a DeclarationName for the internal key to avoid deserializing types.
54 DeclarationName::NameKind Kind;
56 DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { }
59 typedef DeclarationName external_key_type;
60 typedef DeclNameKey internal_key_type;
62 explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
63 : Reader(Reader), F(F) { }
65 static bool EqualKey(const internal_key_type& a,
66 const internal_key_type& b) {
67 return a.Kind == b.Kind && a.Data == b.Data;
70 unsigned ComputeHash(const DeclNameKey &Key) const;
71 internal_key_type GetInternalKey(const external_key_type& Name) const;
73 static std::pair<unsigned, unsigned>
74 ReadKeyDataLength(const unsigned char*& d);
76 internal_key_type ReadKey(const unsigned char* d, unsigned);
78 data_type ReadData(internal_key_type, const unsigned char* d,
82 /// \brief Base class for the trait describing the on-disk hash table for the
83 /// identifiers in an AST file.
85 /// This class is not useful by itself; rather, it provides common
86 /// functionality for accessing the on-disk hash table of identifiers
87 /// in an AST file. Different subclasses customize that functionality
88 /// based on what information they are interested in. Those subclasses
89 /// must provide the \c data_type typedef and the ReadData operation,
91 class ASTIdentifierLookupTraitBase {
93 typedef StringRef external_key_type;
94 typedef StringRef internal_key_type;
97 static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
101 static unsigned ComputeHash(const internal_key_type& a);
103 static std::pair<unsigned, unsigned>
104 ReadKeyDataLength(const unsigned char*& d);
106 // This hopefully will just get inlined and removed by the optimizer.
107 static const internal_key_type&
108 GetInternalKey(const external_key_type& x) { return x; }
110 // This hopefully will just get inlined and removed by the optimizer.
111 static const external_key_type&
112 GetExternalKey(const internal_key_type& x) { return x; }
114 static internal_key_type ReadKey(const unsigned char* d, unsigned n);
117 /// \brief Class that performs lookup for an identifier stored in an AST file.
118 class ASTIdentifierLookupTrait : public ASTIdentifierLookupTraitBase {
122 // If we know the IdentifierInfo in advance, it is here and we will
123 // not build a new one. Used when deserializing information about an
124 // identifier that was constructed before the AST file was read.
125 IdentifierInfo *KnownII;
128 typedef IdentifierInfo * data_type;
130 ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
131 IdentifierInfo *II = 0)
132 : Reader(Reader), F(F), KnownII(II) { }
134 data_type ReadData(const internal_key_type& k,
135 const unsigned char* d,
138 ASTReader &getReader() const { return Reader; }
141 /// \brief The on-disk hash table used to contain information about
142 /// all of the identifiers in the program.
143 typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait>
144 ASTIdentifierLookupTable;
146 /// \brief Class that performs lookup for a selector's entries in the global
147 /// method pool stored in an AST file.
148 class ASTSelectorLookupTrait {
155 unsigned InstanceBits;
156 unsigned FactoryBits;
157 SmallVector<ObjCMethodDecl *, 2> Instance;
158 SmallVector<ObjCMethodDecl *, 2> Factory;
161 typedef Selector external_key_type;
162 typedef external_key_type internal_key_type;
164 ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
165 : Reader(Reader), F(F) { }
167 static bool EqualKey(const internal_key_type& a,
168 const internal_key_type& b) {
172 static unsigned ComputeHash(Selector Sel);
174 static const internal_key_type&
175 GetInternalKey(const external_key_type& x) { return x; }
177 static std::pair<unsigned, unsigned>
178 ReadKeyDataLength(const unsigned char*& d);
180 internal_key_type ReadKey(const unsigned char* d, unsigned);
181 data_type ReadData(Selector, const unsigned char* d, unsigned DataLen);
184 /// \brief The on-disk hash table used for the global method pool.
185 typedef OnDiskChainedHashTable<ASTSelectorLookupTrait>
186 ASTSelectorLookupTable;
188 /// \brief Trait class used to search the on-disk hash table containing all of
189 /// the header search information.
191 /// The on-disk hash table contains a mapping from each header path to
192 /// information about that header (how many times it has been included, its
193 /// controlling macro, etc.). Note that we actually hash based on the
194 /// filename, and support "deep" comparisons of file names based on current
195 /// inode numbers, so that the search can cope with non-normalized path names
197 class HeaderFileInfoTrait {
201 const char *FrameworkStrings;
204 typedef const FileEntry *external_key_type;
206 struct internal_key_type {
209 const char *Filename;
211 typedef const internal_key_type &internal_key_ref;
213 typedef HeaderFileInfo data_type;
215 HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS,
216 const char *FrameworkStrings)
217 : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { }
219 static unsigned ComputeHash(internal_key_ref ikey);
220 static internal_key_type GetInternalKey(const FileEntry *FE);
221 bool EqualKey(internal_key_ref a, internal_key_ref b);
223 static std::pair<unsigned, unsigned>
224 ReadKeyDataLength(const unsigned char*& d);
226 static internal_key_type ReadKey(const unsigned char *d, unsigned);
228 data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
231 /// \brief The on-disk hash table used for known header files.
232 typedef OnDiskChainedHashTable<HeaderFileInfoTrait>
233 HeaderFileInfoLookupTable;
235 } // end namespace clang::serialization::reader
236 } // end namespace clang::serialization
237 } // end namespace clang