clang  3.7.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/Support/Endian.h"
19 #include "llvm/Support/OnDiskHashTable.h"
20 #include <utility>
21 
22 namespace clang {
23 
24 class ASTReader;
25 class HeaderSearch;
26 struct HeaderFileInfo;
27 class FileEntry;
28 
29 namespace serialization {
30 
31 class ModuleFile;
32 
33 namespace reader {
34 
35 /// \brief Class that performs name lookup into a DeclContext stored
36 /// in an AST file.
38  ASTReader &Reader;
39  ModuleFile &F;
40 
41 public:
42  /// \brief Pair of begin/end iterators for DeclIDs.
43  ///
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;
50 
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.
54  struct DeclNameKey {
56  uint64_t Data;
57  DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { }
58  };
59 
62 
64  : Reader(Reader), F(F) { }
65 
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;
69  }
70 
71  static hash_value_type ComputeHash(const DeclNameKey &Key);
73 
74  static std::pair<unsigned, unsigned>
75  ReadKeyDataLength(const unsigned char*& d);
76 
77  internal_key_type ReadKey(const unsigned char* d, unsigned);
78 
79  data_type ReadData(internal_key_type, const unsigned char* d,
80  unsigned DataLen);
81 };
82 
83 /// \brief Base class for the trait describing the on-disk hash table for the
84 /// identifiers in an AST file.
85 ///
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,
91 /// only.
93 public:
94  typedef StringRef external_key_type;
95  typedef StringRef internal_key_type;
96  typedef unsigned hash_value_type;
97  typedef unsigned offset_type;
98 
99  static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
100  return a == b;
101  }
102 
104 
105  static std::pair<unsigned, unsigned>
106  ReadKeyDataLength(const unsigned char*& d);
107 
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; }
111 
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; }
115 
116  static internal_key_type ReadKey(const unsigned char* d, unsigned n);
117 };
118 
119 /// \brief Class that performs lookup for an identifier stored in an AST file.
121  ASTReader &Reader;
122  ModuleFile &F;
123 
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;
128 
129 public:
131 
133  IdentifierInfo *II = nullptr)
134  : Reader(Reader), F(F), KnownII(II) { }
135 
137  const unsigned char* d,
138  unsigned DataLen);
139 
140  ASTReader &getReader() const { return Reader; }
141 };
142 
143 /// \brief The on-disk hash table used to contain information about
144 /// all of the identifiers in the program.
147 
148 /// \brief Class that performs lookup for a selector's entries in the global
149 /// method pool stored in an AST file.
151  ASTReader &Reader;
152  ModuleFile &F;
153 
154 public:
155  struct data_type {
157  unsigned InstanceBits;
158  unsigned FactoryBits;
163  };
164 
167  typedef unsigned hash_value_type;
168  typedef unsigned offset_type;
169 
171  : Reader(Reader), F(F) { }
172 
173  static bool EqualKey(const internal_key_type& a,
174  const internal_key_type& b) {
175  return a == b;
176  }
177 
179 
180  static const internal_key_type&
181  GetInternalKey(const external_key_type& x) { return x; }
182 
183  static std::pair<unsigned, unsigned>
184  ReadKeyDataLength(const unsigned char*& d);
185 
186  internal_key_type ReadKey(const unsigned char* d, unsigned);
187  data_type ReadData(Selector, const unsigned char* d, unsigned DataLen);
188 };
189 
190 /// \brief The on-disk hash table used for the global method pool.
193 
194 /// \brief Trait class used to search the on-disk hash table containing all of
195 /// the header search information.
196 ///
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
202 /// and symlinks.
204  ASTReader &Reader;
205  ModuleFile &M;
206  HeaderSearch *HS;
207  const char *FrameworkStrings;
208 
209 public:
210  typedef const FileEntry *external_key_type;
211 
213  off_t Size;
214  time_t ModTime;
215  const char *Filename;
216  bool Imported;
217  };
219 
221  typedef unsigned hash_value_type;
222  typedef unsigned offset_type;
223 
225  const char *FrameworkStrings)
226  : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { }
227 
229  static internal_key_type GetInternalKey(const FileEntry *FE);
231 
232  static std::pair<unsigned, unsigned>
233  ReadKeyDataLength(const unsigned char*& d);
234 
235  static internal_key_type ReadKey(const unsigned char *d, unsigned);
236 
237  data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
238 };
239 
240 /// \brief The on-disk hash table used for known header files.
243 
244 } // end namespace clang::serialization::reader
245 } // end namespace clang::serialization
246 } // end namespace clang
247 
248 
249 #endif
Smart pointer class that efficiently represents Objective-C method names.
static hash_value_type ComputeHash(Selector Sel)
Definition: ASTReader.cpp:650
data_type ReadData(internal_key_type, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:952
NameKind
NameKind - The kind of name this object contains.
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:907
Class that performs name lookup into a DeclContext stored in an AST file.
static hash_value_type ComputeHash(const DeclNameKey &Key)
Definition: ASTReader.cpp:848
data_type ReadData(Selector, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:685
static const external_key_type & GetExternalKey(const internal_key_type &x)
static const internal_key_type & GetInternalKey(const external_key_type &x)
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:664
static internal_key_type GetInternalKey(const FileEntry *FE)
Definition: ASTReader.cpp:1483
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:1514
data_type ReadData(internal_key_ref, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:1533
static internal_key_type ReadKey(const unsigned char *d, unsigned n)
Definition: ASTReader.cpp:732
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:1489
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:151
llvm::support::ulittle32_t LE32DeclID
Pair of begin/end iterators for DeclIDs.
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)
Special internal key for declaration names. The hash table creates keys for comparison; we do not cre...
static bool EqualKey(const internal_key_type &a, const internal_key_type &b)
Kind
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...
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:302
Class that performs lookup for an identifier stored in an AST file.
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:724
llvm::OnDiskChainedHashTable< HeaderFileInfoTrait > HeaderFileInfoLookupTable
The on-disk hash table used for known header files.
static std::pair< unsigned, unsigned > ReadKeyDataLength(const unsigned char *&d)
Definition: ASTReader.cpp:656
ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:144
static internal_key_type GetInternalKey(const external_key_type &Name)
Definition: ASTReader.cpp:876
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:719
static internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:1522
data_type ReadData(const internal_key_type &k, const unsigned char *d, unsigned DataLen)
Definition: ASTReader.cpp:747
ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F, IdentifierInfo *II=nullptr)
internal_key_type ReadKey(const unsigned char *d, unsigned)
Definition: ASTReader.cpp:915
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:1478
HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS, const char *FrameworkStrings)