2017-11-11 08:08:50 +08:00
|
|
|
//===- ASTReaderInternals.h - AST Reader Internals --------------*- C++ -*-===//
|
2011-08-26 04:47:51 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-08-26 04:47:51 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides internal definitions used in the AST reader.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-11-11 08:08:50 +08:00
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
|
|
|
|
#define LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "MultiOnDiskHashTable.h"
|
2011-08-26 04:47:51 +08:00
|
|
|
#include "clang/AST/DeclarationName.h"
|
2017-11-11 08:08:50 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2013-01-24 02:53:14 +08:00
|
|
|
#include "clang/Serialization/ASTBitCodes.h"
|
2015-09-02 04:35:42 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2017-11-11 08:08:50 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2014-04-19 03:57:06 +08:00
|
|
|
#include "llvm/Support/OnDiskHashTable.h"
|
2017-11-11 08:08:50 +08:00
|
|
|
#include <ctime>
|
2012-12-04 17:13:33 +08:00
|
|
|
#include <utility>
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class ASTReader;
|
2013-03-07 02:12:47 +08:00
|
|
|
class FileEntry;
|
2017-11-11 08:08:50 +08:00
|
|
|
struct HeaderFileInfo;
|
|
|
|
class HeaderSearch;
|
|
|
|
class ObjCMethodDecl;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
namespace serialization {
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
class ModuleFile;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
namespace reader {
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Class that performs name lookup into a DeclContext stored
|
2011-08-26 04:47:51 +08:00
|
|
|
/// in an AST file.
|
|
|
|
class ASTDeclContextNameLookupTrait {
|
|
|
|
ASTReader &Reader;
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleFile &F;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
public:
|
2015-09-02 04:35:42 +08:00
|
|
|
// Maximum number of lookup tables we allow before condensing the tables.
|
|
|
|
static const int MaxTables = 4;
|
|
|
|
|
|
|
|
/// The lookup result is a list of global declaration IDs.
|
2017-11-11 08:08:50 +08:00
|
|
|
using data_type = SmallVector<DeclID, 4>;
|
|
|
|
|
2015-09-02 04:35:42 +08:00
|
|
|
struct data_type_builder {
|
|
|
|
data_type &Data;
|
|
|
|
llvm::DenseSet<DeclID> Found;
|
|
|
|
|
|
|
|
data_type_builder(data_type &D) : Data(D) {}
|
2017-11-11 08:08:50 +08:00
|
|
|
|
2015-09-02 04:35:42 +08:00
|
|
|
void insert(DeclID ID) {
|
|
|
|
// Just use a linear scan unless we have more than a few IDs.
|
|
|
|
if (Found.empty() && !Data.empty()) {
|
|
|
|
if (Data.size() <= 4) {
|
|
|
|
for (auto I : Found)
|
|
|
|
if (I == ID)
|
|
|
|
return;
|
|
|
|
Data.push_back(ID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switch to tracking found IDs in the set.
|
|
|
|
Found.insert(Data.begin(), Data.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Found.insert(ID).second)
|
|
|
|
Data.push_back(ID);
|
|
|
|
}
|
|
|
|
};
|
2017-11-11 08:08:50 +08:00
|
|
|
using hash_value_type = unsigned;
|
|
|
|
using offset_type = unsigned;
|
|
|
|
using file_type = ModuleFile *;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
using external_key_type = DeclarationName;
|
|
|
|
using internal_key_type = DeclarationNameKey;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2012-04-16 10:51:46 +08:00
|
|
|
explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
|
2017-11-11 08:08:50 +08:00
|
|
|
: Reader(Reader), F(F) {}
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2015-09-02 04:35:42 +08:00
|
|
|
static bool EqualKey(const internal_key_type &a, const internal_key_type &b) {
|
2015-08-27 07:55:49 +08:00
|
|
|
return a == b;
|
2011-08-26 04:47:51 +08:00
|
|
|
}
|
|
|
|
|
2015-08-27 07:55:49 +08:00
|
|
|
static hash_value_type ComputeHash(const internal_key_type &Key) {
|
|
|
|
return Key.getHash();
|
|
|
|
}
|
2017-11-11 08:08:50 +08:00
|
|
|
|
2015-08-27 07:55:49 +08:00
|
|
|
static internal_key_type GetInternalKey(const external_key_type &Name) {
|
|
|
|
return Name;
|
|
|
|
}
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2012-04-16 10:51:46 +08:00
|
|
|
static std::pair<unsigned, unsigned>
|
2015-08-27 07:55:49 +08:00
|
|
|
ReadKeyDataLength(const unsigned char *&d);
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2015-08-27 07:55:49 +08:00
|
|
|
internal_key_type ReadKey(const unsigned char *d, unsigned);
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2015-09-02 04:35:42 +08:00
|
|
|
void ReadDataInto(internal_key_type, const unsigned char *d,
|
|
|
|
unsigned DataLen, data_type_builder &Val);
|
|
|
|
|
|
|
|
static void MergeDataInto(const data_type &From, data_type_builder &To) {
|
|
|
|
To.Data.reserve(To.Data.size() + From.size());
|
|
|
|
for (DeclID ID : From)
|
|
|
|
To.insert(ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
file_type ReadFileRef(const unsigned char *&d);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeclContextLookupTable {
|
|
|
|
MultiOnDiskHashTable<ASTDeclContextNameLookupTrait> Table;
|
2011-08-26 04:47:51 +08:00
|
|
|
};
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Base class for the trait describing the on-disk hash table for the
|
2013-01-24 02:53:14 +08:00
|
|
|
/// identifiers in an AST file.
|
|
|
|
///
|
|
|
|
/// This class is not useful by itself; rather, it provides common
|
|
|
|
/// functionality for accessing the on-disk hash table of identifiers
|
|
|
|
/// in an AST file. Different subclasses customize that functionality
|
|
|
|
/// based on what information they are interested in. Those subclasses
|
2017-11-11 08:08:50 +08:00
|
|
|
/// must provide the \c data_type type and the ReadData operation, only.
|
2013-01-24 02:53:14 +08:00
|
|
|
class ASTIdentifierLookupTraitBase {
|
|
|
|
public:
|
2017-11-11 08:08:50 +08:00
|
|
|
using external_key_type = StringRef;
|
|
|
|
using internal_key_type = StringRef;
|
|
|
|
using hash_value_type = unsigned;
|
|
|
|
using offset_type = unsigned;
|
2013-01-24 02:53:14 +08:00
|
|
|
|
|
|
|
static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
2014-04-19 04:27:24 +08:00
|
|
|
static hash_value_type ComputeHash(const internal_key_type& a);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-01-24 02:53:14 +08:00
|
|
|
static std::pair<unsigned, unsigned>
|
|
|
|
ReadKeyDataLength(const unsigned char*& d);
|
|
|
|
|
|
|
|
// This hopefully will just get inlined and removed by the optimizer.
|
|
|
|
static const internal_key_type&
|
|
|
|
GetInternalKey(const external_key_type& x) { return x; }
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-01-24 02:53:14 +08:00
|
|
|
// This hopefully will just get inlined and removed by the optimizer.
|
|
|
|
static const external_key_type&
|
|
|
|
GetExternalKey(const internal_key_type& x) { return x; }
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
static internal_key_type ReadKey(const unsigned char* d, unsigned n);
|
2013-01-24 02:53:14 +08:00
|
|
|
};
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Class that performs lookup for an identifier stored in an AST file.
|
2013-01-24 02:53:14 +08:00
|
|
|
class ASTIdentifierLookupTrait : public ASTIdentifierLookupTraitBase {
|
2011-08-26 04:47:51 +08:00
|
|
|
ASTReader &Reader;
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleFile &F;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
// If we know the IdentifierInfo in advance, it is here and we will
|
|
|
|
// not build a new one. Used when deserializing information about an
|
|
|
|
// identifier that was constructed before the AST file was read.
|
|
|
|
IdentifierInfo *KnownII;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
public:
|
2017-11-11 08:08:50 +08:00
|
|
|
using data_type = IdentifierInfo *;
|
2014-05-22 13:54:18 +08:00
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
|
2014-05-22 13:54:18 +08:00
|
|
|
IdentifierInfo *II = nullptr)
|
2017-11-11 08:08:50 +08:00
|
|
|
: Reader(Reader), F(F), KnownII(II) {}
|
2014-05-22 13:54:18 +08:00
|
|
|
|
2013-01-24 02:53:14 +08:00
|
|
|
data_type ReadData(const internal_key_type& k,
|
|
|
|
const unsigned char* d,
|
|
|
|
unsigned DataLen);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2015-08-24 11:33:22 +08:00
|
|
|
IdentID ReadIdentifierID(const unsigned char *d);
|
|
|
|
|
2012-01-24 23:24:38 +08:00
|
|
|
ASTReader &getReader() const { return Reader; }
|
2011-08-26 04:47:51 +08:00
|
|
|
};
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The on-disk hash table used to contain information about
|
2011-08-26 04:47:51 +08:00
|
|
|
/// all of the identifiers in the program.
|
2017-11-11 08:08:50 +08:00
|
|
|
using ASTIdentifierLookupTable =
|
|
|
|
llvm::OnDiskIterableChainedHashTable<ASTIdentifierLookupTrait>;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Class that performs lookup for a selector's entries in the global
|
2011-08-26 04:47:51 +08:00
|
|
|
/// method pool stored in an AST file.
|
|
|
|
class ASTSelectorLookupTrait {
|
|
|
|
ASTReader &Reader;
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleFile &F;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
public:
|
|
|
|
struct data_type {
|
|
|
|
SelectorID ID;
|
2013-04-17 08:08:58 +08:00
|
|
|
unsigned InstanceBits;
|
|
|
|
unsigned FactoryBits;
|
2014-12-28 06:14:15 +08:00
|
|
|
bool InstanceHasMoreThanOneDecl;
|
|
|
|
bool FactoryHasMoreThanOneDecl;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<ObjCMethodDecl *, 2> Instance;
|
|
|
|
SmallVector<ObjCMethodDecl *, 2> Factory;
|
2011-08-26 04:47:51 +08:00
|
|
|
};
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
using external_key_type = Selector;
|
|
|
|
using internal_key_type = external_key_type;
|
|
|
|
using hash_value_type = unsigned;
|
|
|
|
using offset_type = unsigned;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
|
|
|
|
: Reader(Reader), F(F) {}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
static bool EqualKey(const internal_key_type& a,
|
|
|
|
const internal_key_type& b) {
|
|
|
|
return a == b;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-04-19 04:27:24 +08:00
|
|
|
static hash_value_type ComputeHash(Selector Sel);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
static const internal_key_type&
|
2011-09-11 00:13:42 +08:00
|
|
|
GetInternalKey(const external_key_type& x) { return x; }
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
static std::pair<unsigned, unsigned>
|
|
|
|
ReadKeyDataLength(const unsigned char*& d);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
internal_key_type ReadKey(const unsigned char* d, unsigned);
|
|
|
|
data_type ReadData(Selector, const unsigned char* d, unsigned DataLen);
|
|
|
|
};
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The on-disk hash table used for the global method pool.
|
2017-11-11 08:08:50 +08:00
|
|
|
using ASTSelectorLookupTable =
|
|
|
|
llvm::OnDiskChainedHashTable<ASTSelectorLookupTrait>;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Trait class used to search the on-disk hash table containing all of
|
2011-08-26 04:47:51 +08:00
|
|
|
/// the header search information.
|
|
|
|
///
|
2018-07-31 03:24:48 +08:00
|
|
|
/// The on-disk hash table contains a mapping from each header path to
|
2011-08-26 04:47:51 +08:00
|
|
|
/// information about that header (how many times it has been included, its
|
2014-12-06 06:42:13 +08:00
|
|
|
/// controlling macro, etc.). Note that we actually hash based on the size
|
|
|
|
/// and mtime, and support "deep" comparisons of file names based on current
|
2011-08-26 04:47:51 +08:00
|
|
|
/// inode numbers, so that the search can cope with non-normalized path names
|
|
|
|
/// and symlinks.
|
|
|
|
class HeaderFileInfoTrait {
|
|
|
|
ASTReader &Reader;
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleFile &M;
|
2011-08-26 04:47:51 +08:00
|
|
|
HeaderSearch *HS;
|
|
|
|
const char *FrameworkStrings;
|
2013-02-05 14:21:59 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
public:
|
2017-11-11 08:08:50 +08:00
|
|
|
using external_key_type = const FileEntry *;
|
2013-03-07 02:12:47 +08:00
|
|
|
|
|
|
|
struct internal_key_type {
|
|
|
|
off_t Size;
|
|
|
|
time_t ModTime;
|
2016-10-11 06:52:47 +08:00
|
|
|
StringRef Filename;
|
2014-12-06 06:42:13 +08:00
|
|
|
bool Imported;
|
2013-03-07 02:12:47 +08:00
|
|
|
};
|
2017-11-11 08:08:50 +08:00
|
|
|
|
|
|
|
using internal_key_ref = const internal_key_type &;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
using data_type = HeaderFileInfo;
|
|
|
|
using hash_value_type = unsigned;
|
|
|
|
using offset_type = unsigned;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS,
|
2013-03-07 02:12:41 +08:00
|
|
|
const char *FrameworkStrings)
|
2017-11-11 08:08:50 +08:00
|
|
|
: Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) {}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-04-19 04:27:24 +08:00
|
|
|
static hash_value_type ComputeHash(internal_key_ref ikey);
|
2015-08-17 15:13:32 +08:00
|
|
|
internal_key_type GetInternalKey(const FileEntry *FE);
|
2013-03-07 02:12:47 +08:00
|
|
|
bool EqualKey(internal_key_ref a, internal_key_ref b);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
static std::pair<unsigned, unsigned>
|
|
|
|
ReadKeyDataLength(const unsigned char*& d);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-03-07 02:12:47 +08:00
|
|
|
static internal_key_type ReadKey(const unsigned char *d, unsigned);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-03-07 02:12:47 +08:00
|
|
|
data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
|
2011-08-26 04:47:51 +08:00
|
|
|
};
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The on-disk hash table used for known header files.
|
2017-11-11 08:08:50 +08:00
|
|
|
using HeaderFileInfoLookupTable =
|
|
|
|
llvm::OnDiskChainedHashTable<HeaderFileInfoTrait>;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
} // namespace reader
|
|
|
|
|
|
|
|
} // namespace serialization
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
} // namespace clang
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2017-11-11 08:08:50 +08:00
|
|
|
#endif // LLVM_CLANG_LIB_SERIALIZATION_ASTREADERINTERNALS_H
|