Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1 | //===- ASTReaderInternals.h - AST Reader Internals --------------*- C++ -*-===// |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file provides internal definitions used in the AST reader. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 12 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 13 | #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H |
| 14 | #define LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 15 | |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 16 | #include "MultiOnDiskHashTable.h" |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclarationName.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 18 | #include "clang/Basic/LLVM.h" |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 19 | #include "clang/Serialization/ASTBitCodes.h" |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseSet.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | #include "llvm/ADT/StringRef.h" |
Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 23 | #include "llvm/Support/OnDiskHashTable.h" |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 24 | #include <ctime> |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include <utility> |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 26 | |
| 27 | namespace clang { |
| 28 | |
| 29 | class ASTReader; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 30 | class FileEntry; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 31 | struct HeaderFileInfo; |
| 32 | class HeaderSearch; |
| 33 | class IdentifierTable; |
| 34 | class ObjCMethodDecl; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 35 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 36 | namespace serialization { |
| 37 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 38 | class ModuleFile; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 39 | |
| 40 | namespace reader { |
| 41 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 42 | /// Class that performs name lookup into a DeclContext stored |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 43 | /// in an AST file. |
| 44 | class ASTDeclContextNameLookupTrait { |
| 45 | ASTReader &Reader; |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 46 | ModuleFile &F; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 47 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 48 | public: |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 49 | // Maximum number of lookup tables we allow before condensing the tables. |
| 50 | static const int MaxTables = 4; |
| 51 | |
| 52 | /// The lookup result is a list of global declaration IDs. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 53 | using data_type = SmallVector<DeclID, 4>; |
| 54 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 55 | struct data_type_builder { |
| 56 | data_type &Data; |
| 57 | llvm::DenseSet<DeclID> Found; |
| 58 | |
| 59 | data_type_builder(data_type &D) : Data(D) {} |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 60 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 61 | void insert(DeclID ID) { |
| 62 | // Just use a linear scan unless we have more than a few IDs. |
| 63 | if (Found.empty() && !Data.empty()) { |
| 64 | if (Data.size() <= 4) { |
| 65 | for (auto I : Found) |
| 66 | if (I == ID) |
| 67 | return; |
| 68 | Data.push_back(ID); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Switch to tracking found IDs in the set. |
| 73 | Found.insert(Data.begin(), Data.end()); |
| 74 | } |
| 75 | |
| 76 | if (Found.insert(ID).second) |
| 77 | Data.push_back(ID); |
| 78 | } |
| 79 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 80 | using hash_value_type = unsigned; |
| 81 | using offset_type = unsigned; |
| 82 | using file_type = ModuleFile *; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 83 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 84 | using external_key_type = DeclarationName; |
| 85 | using internal_key_type = DeclarationNameKey; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 86 | |
Nick Lewycky | 2bd0ab2 | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 87 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F) |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 88 | : Reader(Reader), F(F) {} |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 89 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 90 | static bool EqualKey(const internal_key_type &a, const internal_key_type &b) { |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 91 | return a == b; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 94 | static hash_value_type ComputeHash(const internal_key_type &Key) { |
| 95 | return Key.getHash(); |
| 96 | } |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 97 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 98 | static internal_key_type GetInternalKey(const external_key_type &Name) { |
| 99 | return Name; |
| 100 | } |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 101 | |
Nick Lewycky | 2bd0ab2 | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 102 | static std::pair<unsigned, unsigned> |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 103 | ReadKeyDataLength(const unsigned char *&d); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 104 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 105 | internal_key_type ReadKey(const unsigned char *d, unsigned); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 106 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 107 | void ReadDataInto(internal_key_type, const unsigned char *d, |
| 108 | unsigned DataLen, data_type_builder &Val); |
| 109 | |
| 110 | static void MergeDataInto(const data_type &From, data_type_builder &To) { |
| 111 | To.Data.reserve(To.Data.size() + From.size()); |
| 112 | for (DeclID ID : From) |
| 113 | To.insert(ID); |
| 114 | } |
| 115 | |
| 116 | file_type ReadFileRef(const unsigned char *&d); |
| 117 | }; |
| 118 | |
| 119 | struct DeclContextLookupTable { |
| 120 | MultiOnDiskHashTable<ASTDeclContextNameLookupTrait> Table; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 123 | /// Base class for the trait describing the on-disk hash table for the |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 124 | /// identifiers in an AST file. |
| 125 | /// |
| 126 | /// This class is not useful by itself; rather, it provides common |
| 127 | /// functionality for accessing the on-disk hash table of identifiers |
| 128 | /// in an AST file. Different subclasses customize that functionality |
| 129 | /// based on what information they are interested in. Those subclasses |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 130 | /// must provide the \c data_type type and the ReadData operation, only. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 131 | class ASTIdentifierLookupTraitBase { |
| 132 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 133 | using external_key_type = StringRef; |
| 134 | using internal_key_type = StringRef; |
| 135 | using hash_value_type = unsigned; |
| 136 | using offset_type = unsigned; |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 137 | |
| 138 | static bool EqualKey(const internal_key_type& a, const internal_key_type& b) { |
| 139 | return a == b; |
| 140 | } |
| 141 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 142 | static hash_value_type ComputeHash(const internal_key_type& a); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 144 | static std::pair<unsigned, unsigned> |
| 145 | ReadKeyDataLength(const unsigned char*& d); |
| 146 | |
| 147 | // This hopefully will just get inlined and removed by the optimizer. |
| 148 | static const internal_key_type& |
| 149 | GetInternalKey(const external_key_type& x) { return x; } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 151 | // This hopefully will just get inlined and removed by the optimizer. |
| 152 | static const external_key_type& |
| 153 | GetExternalKey(const internal_key_type& x) { return x; } |
| 154 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 155 | static internal_key_type ReadKey(const unsigned char* d, unsigned n); |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 158 | /// Class that performs lookup for an identifier stored in an AST file. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 159 | class ASTIdentifierLookupTrait : public ASTIdentifierLookupTraitBase { |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 160 | ASTReader &Reader; |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 161 | ModuleFile &F; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 162 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 163 | // If we know the IdentifierInfo in advance, it is here and we will |
| 164 | // not build a new one. Used when deserializing information about an |
| 165 | // identifier that was constructed before the AST file was read. |
| 166 | IdentifierInfo *KnownII; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 168 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 169 | using data_type = IdentifierInfo *; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 170 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 171 | ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 172 | IdentifierInfo *II = nullptr) |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 173 | : Reader(Reader), F(F), KnownII(II) {} |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 174 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 175 | data_type ReadData(const internal_key_type& k, |
| 176 | const unsigned char* d, |
| 177 | unsigned DataLen); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 178 | |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 179 | IdentID ReadIdentifierID(const unsigned char *d); |
| 180 | |
Douglas Gregor | 247afcc | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 181 | ASTReader &getReader() const { return Reader; } |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 182 | }; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 183 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 184 | /// The on-disk hash table used to contain information about |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 185 | /// all of the identifiers in the program. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 186 | using ASTIdentifierLookupTable = |
| 187 | llvm::OnDiskIterableChainedHashTable<ASTIdentifierLookupTrait>; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 188 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 189 | /// Class that performs lookup for a selector's entries in the global |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 190 | /// method pool stored in an AST file. |
| 191 | class ASTSelectorLookupTrait { |
| 192 | ASTReader &Reader; |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 193 | ModuleFile &F; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 194 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 195 | public: |
| 196 | struct data_type { |
| 197 | SelectorID ID; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 198 | unsigned InstanceBits; |
| 199 | unsigned FactoryBits; |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 200 | bool InstanceHasMoreThanOneDecl; |
| 201 | bool FactoryHasMoreThanOneDecl; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 202 | SmallVector<ObjCMethodDecl *, 2> Instance; |
| 203 | SmallVector<ObjCMethodDecl *, 2> Factory; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 204 | }; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 205 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 206 | using external_key_type = Selector; |
| 207 | using internal_key_type = external_key_type; |
| 208 | using hash_value_type = unsigned; |
| 209 | using offset_type = unsigned; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 210 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 211 | ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F) |
| 212 | : Reader(Reader), F(F) {} |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 214 | static bool EqualKey(const internal_key_type& a, |
| 215 | const internal_key_type& b) { |
| 216 | return a == b; |
| 217 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 218 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 219 | static hash_value_type ComputeHash(Selector Sel); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 220 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 221 | static const internal_key_type& |
Chris Lattner | d2cd41c | 2011-09-10 16:13:42 +0000 | [diff] [blame] | 222 | GetInternalKey(const external_key_type& x) { return x; } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 223 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 224 | static std::pair<unsigned, unsigned> |
| 225 | ReadKeyDataLength(const unsigned char*& d); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 226 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 227 | internal_key_type ReadKey(const unsigned char* d, unsigned); |
| 228 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen); |
| 229 | }; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 230 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 231 | /// The on-disk hash table used for the global method pool. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 232 | using ASTSelectorLookupTable = |
| 233 | llvm::OnDiskChainedHashTable<ASTSelectorLookupTrait>; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 234 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 235 | /// Trait class used to search the on-disk hash table containing all of |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 236 | /// the header search information. |
| 237 | /// |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 238 | /// The on-disk hash table contains a mapping from each header path to |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 239 | /// information about that header (how many times it has been included, its |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 240 | /// controlling macro, etc.). Note that we actually hash based on the size |
| 241 | /// and mtime, and support "deep" comparisons of file names based on current |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 242 | /// inode numbers, so that the search can cope with non-normalized path names |
| 243 | /// and symlinks. |
| 244 | class HeaderFileInfoTrait { |
| 245 | ASTReader &Reader; |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 246 | ModuleFile &M; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 247 | HeaderSearch *HS; |
| 248 | const char *FrameworkStrings; |
Ted Kremenek | 03cb137 | 2013-02-05 06:21:59 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 250 | public: |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 251 | using external_key_type = const FileEntry *; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 252 | |
| 253 | struct internal_key_type { |
| 254 | off_t Size; |
| 255 | time_t ModTime; |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 256 | StringRef Filename; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 257 | bool Imported; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 258 | }; |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 259 | |
| 260 | using internal_key_ref = const internal_key_type &; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 261 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 262 | using data_type = HeaderFileInfo; |
| 263 | using hash_value_type = unsigned; |
| 264 | using offset_type = unsigned; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 265 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 266 | HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS, |
Argyrios Kyrtzidis | b42863e | 2013-03-06 18:12:41 +0000 | [diff] [blame] | 267 | const char *FrameworkStrings) |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 268 | : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) {} |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 269 | |
Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 270 | static hash_value_type ComputeHash(internal_key_ref ikey); |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 271 | internal_key_type GetInternalKey(const FileEntry *FE); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 272 | bool EqualKey(internal_key_ref a, internal_key_ref b); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 273 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 274 | static std::pair<unsigned, unsigned> |
| 275 | ReadKeyDataLength(const unsigned char*& d); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 276 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 277 | static internal_key_type ReadKey(const unsigned char *d, unsigned); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 278 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 279 | data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 280 | }; |
| 281 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 282 | /// The on-disk hash table used for known header files. |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 283 | using HeaderFileInfoLookupTable = |
| 284 | llvm::OnDiskChainedHashTable<HeaderFileInfoTrait>; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 285 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 286 | } // namespace reader |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 287 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 288 | } // namespace serialization |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 289 | |
Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 290 | } // namespace clang |
| 291 | |
| 292 | #endif // LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H |