clang  3.9.0
ASTReaderInternals.h
Go to the documentation of this file.
1 //===--- ASTReaderInternals.h - AST Reader Internals ------------*- 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 provides internal definitions used in the AST reader.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
14 #define LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
15 
18 #include "llvm/ADT/DenseSet.h"
19 #include "llvm/ADT/PointerUnion.h"
20 #include "llvm/ADT/TinyPtrVector.h"
21 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/OnDiskHashTable.h"
23 #include "MultiOnDiskHashTable.h"
24 #include <utility>
25 
26 namespace clang {
27 
28 class ASTReader;
29 class HeaderSearch;
30 struct HeaderFileInfo;
31 class FileEntry;
32 
33 namespace serialization {
34 
35 class ModuleFile;
36 
37 namespace reader {
38 
39 /// \brief Class that performs name lookup into a DeclContext stored
40 /// in an AST file.
42  ASTReader &Reader;
43  ModuleFile &F;
44 
45 public:
46  // Maximum number of lookup tables we allow before condensing the tables.
47  static const int MaxTables = 4;
48 
49  /// The lookup result is a list of global declaration IDs.
54 
56  void insert(DeclID ID) {
57  // Just use a linear scan unless we have more than a few IDs.
58  if (Found.empty() && !Data.empty()) {
59  if (Data.size() <= 4) {
60  for (auto I : Found)
61  if (I == ID)
62  return;
63  Data.push_back(ID);
64  return;
65  }
66 
67  // Switch to tracking found IDs in the set.
68  Found.insert(Data.begin(), Data.end());
69  }
70 
71  if (Found.insert(ID).second)
72  Data.push_back(ID);
73  }
74  };
75  typedef unsigned hash_value_type;
76  typedef unsigned offset_type;
78 
81 
83  : Reader(Reader), F(F) { }
84 
85  static bool EqualKey(const internal_key_type &a, const internal_key_type &b) {
86  return a == b;
87  }
88 
90  return Key.getHash();
91  }
93  return Name;
94  }
95 
96  static std::pair<unsigned, unsigned>
97  ReadKeyDataLength(const unsigned char *&d);
98 
99  internal_key_type ReadKey(const unsigned char *d, unsigned);
100 
101  void ReadDataInto(internal_key_type, const unsigned char *d,
102  unsigned DataLen, data_type_builder &Val);
103 
104  static void MergeDataInto(const data_type &From, data_type_builder &To) {
105  To.Data.reserve(To.Data.size() + From.size());
106  for (DeclID ID : From)
107  To.insert(ID);
108  }
109 
110  file_type ReadFileRef(const unsigned char *&d);
111 };
112 
115 
116  // These look redundant, but don't remove them -- they work around MSVC 2013's
117  // inability to synthesize move operations. Without them, the
118  // MultiOnDiskHashTable will be copied (despite being move-only!).
121  : Table(std::move(O.Table)) {}
123  Table = std::move(O.Table);
124  return *this;
125  }
126 };
127 
128 /// \brief Base class for the trait describing the on-disk hash table for the
129 /// identifiers in an AST file.
130 ///
131 /// This class is not useful by itself; rather, it provides common
132 /// functionality for accessing the on-disk hash table of identifiers
133 /// in an AST file. Different subclasses customize that functionality
134 /// based on what information they are interested in. Those subclasses
135 /// must provide the \c data_type typedef and the ReadData operation,
136 /// only.
138 public:
139  typedef StringRef external_key_type;
140  typedef StringRef internal_key_type;
141  typedef unsigned hash_value_type;
142  typedef unsigned offset_type;
143 
144  static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
145  return a == b;
146  }
147 
149 
150  static std::pair<unsigned, unsigned>
151  ReadKeyDataLength(const unsigned char*& d);
152 
153  // This hopefully will just get inlined and removed by the optimizer.
154  static const internal_key_type&
155  GetInternalKey(const external_key_type& x) { return x; }
156 
157  // This hopefully will just get inlined and removed by the optimizer.
158  static const external_key_type&
159  GetExternalKey(const internal_key_type& x) { return x; }
160 
161  static internal_key_type ReadKey(const unsigned char* d, unsigned n);
162 };
163 
164 /// \brief Class that performs lookup for an identifier stored in an AST file.
166  ASTReader &Reader;
167  ModuleFile &F;
168 
169  // If we know the IdentifierInfo in advance, it is here and we will
170  // not build a new one. Used when deserializing information about an
171  // identifier that was constructed before the AST file was read.
172  IdentifierInfo *KnownII;
173 
174 public:
176 
178  IdentifierInfo *II = nullptr)
179  : Reader(Reader), F(F), KnownII(II) { }
180 
182  const unsigned char* d,
183  unsigned DataLen);
184 
185  IdentID ReadIdentifierID(const unsigned char *d);
186 
187  ASTReader &getReader() const { return Reader; }
188 };
189 
190 /// \brief The on-disk hash table used to contain information about
191 /// all of the identifiers in the program.
194 
195 /// \brief Class that performs lookup for a selector's entries in the global
196 /// method pool stored in an AST file.
198  ASTReader &Reader;
199  ModuleFile &F;
200 
201 public:
202  struct data_type {
204  unsigned InstanceBits;
205  unsigned FactoryBits;
210  };
211 
214  typedef unsigned hash_value_type;
215  typedef unsigned offset_type;
216 
218  : Reader(Reader), F(F) { }
219 
220  static bool EqualKey(const internal_key_type& a,
221  const internal_key_type& b) {
222  return a == b;
223  }
224 
226 
227  static const internal_key_type&
228  GetInternalKey(const external_key_type& x) { return x; }
229 
230  static std::pair<unsigned, unsigned>
231  ReadKeyDataLength(const unsigned char*& d);
232 
233  internal_key_type ReadKey(const unsigned char* d, unsigned);
234  data_type ReadData(Selector, const unsigned char* d, unsigned DataLen);
235 };
236 
237 /// \brief The on-disk hash table used for the global method pool.
240 
241 /// \brief Trait class used to search the on-disk hash table containing all of
242 /// the header search information.
243 ///
244 /// The on-disk hash table contains a mapping from each header path to
245 /// information about that header (how many times it has been included, its
246 /// controlling macro, etc.). Note that we actually hash based on the size
247 /// and mtime, and support "deep" comparisons of file names based on current
248 /// inode numbers, so that the search can cope with non-normalized path names
249 /// and symlinks.
251  ASTReader &Reader;
252  ModuleFile &M;
253  HeaderSearch *HS;
254  const char *FrameworkStrings;
255 
256 public:
257  typedef const FileEntry *external_key_type;
258 
260  off_t Size;
261  time_t ModTime;
262  const char *Filename;
263  bool Imported;
264  };
266 
268  typedef unsigned hash_value_type;
269  typedef unsigned offset_type;
270 
272  const char *FrameworkStrings)
273  : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { }
274 
276  internal_key_type GetInternalKey(const FileEntry *FE);
278 
279  static std::pair<unsigned, unsigned>
280  ReadKeyDataLength(const unsigned char*& d);
281 
282  static internal_key_type ReadKey(const unsigned char *d, unsigned);
283 
284  data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
285 };
286 
287 /// \brief The on-disk hash table used for known header files.
290 
291 } // end namespace clang::serialization::reader
292 } // end namespace clang::serialization
293 } // end namespace clang
294 
295 
296 #endif
llvm::SmallVector< DeclID, 4 > data_type
The lookup result is a list of global declaration IDs.
DeclContextLookupTable & operator=(DeclContextLookupTable &&O)
Smart pointer class that efficiently represents Objective-C method names.
static hash_value_type ComputeHash(Selector Sel)
Definition: ASTReader.cpp:667
unsigned getHash() const
Compute a fingerprint of this key for use in on-disk hash table.
Definition: ASTReader.cpp:897
static bool EqualKey(const internal_key_type &a, const internal_key_type &b)
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:932
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:123
static internal_key_type GetInternalKey(const external_key_type &Name)
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:63
Class that performs name lookup into a DeclContext stored in an AST file.
static void MergeDataInto(const data_type &From, data_type_builder &To)
data_type ReadData(Selector, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:702
static const external_key_type & GetExternalKey(const internal_key_type &x)
static const internal_key_type & GetInternalKey(const external_key_type &x)
One of these records is kept for each identifier that is lexed.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:681
internal_key_type GetInternalKey(const FileEntry *FE)
Definition: ASTReader.cpp:1535
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:1567
static hash_value_type ComputeHash(const internal_key_type &Key)
data_type ReadData(internal_key_ref, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:1586
static internal_key_type ReadKey(const unsigned char *d, unsigned n)
Definition: ASTReader.cpp:749
A collection of on-disk hash tables, merged when relevant for performance.
detail::InMemoryDirectory::const_iterator I
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:39
bool EqualKey(internal_key_ref a, internal_key_ref b)
Definition: ASTReader.cpp:1542
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:137
Base class for the trait describing the on-disk hash table for the identifiers in an AST file...
Information about a module that has been loaded by the ASTReader.
Trait class used to search the on-disk hash table containing all of the header search information...
static bool EqualKey(const internal_key_type &a, const internal_key_type &b)
static bool EqualKey(const internal_key_type &a, const internal_key_type &b)
const std::string ID
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
Class that performs lookup for a selector's entries in the global method pool stored in an AST file...
IdentID ReadIdentifierID(const unsigned char *d)
Definition: ASTReader.cpp:771
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:312
DeclarationName - The name of a declaration.
Class that performs lookup for an identifier stored in an AST file.
void ReadDataInto(internal_key_type, const unsigned char *d, unsigned DataLen, data_type_builder &Val)
Definition: ASTReader.cpp:976
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:741
llvm::OnDiskChainedHashTable< HeaderFileInfoTrait > HeaderFileInfoLookupTable
The on-disk hash table used for known header files.
A key used when looking up entities by DeclarationName.
Definition: ASTBitCodes.h:1573
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:673
ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:142
llvm::OnDiskChainedHashTable< ASTSelectorLookupTrait > ASTSelectorLookupTable
The on-disk hash table used for the global method pool.
static hash_value_type ComputeHash(const internal_key_type &a)
Definition: ASTReader.cpp:736
static internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:1575
data_type ReadData(const internal_key_type &k, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:786
ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F, IdentifierInfo *II=nullptr)
MultiOnDiskHashTable< ASTDeclContextNameLookupTrait > Table
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:940
static const internal_key_type & GetInternalKey(const external_key_type &x)
llvm::OnDiskIterableChainedHashTable< ASTIdentifierLookupTrait > ASTIdentifierLookupTable
The on-disk hash table used to contain information about all of the identifiers in the program...
static hash_value_type ComputeHash(internal_key_ref ikey)
Definition: ASTReader.cpp:1530
HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS, const char *FrameworkStrings)