2011-08-26 04:47:51 +08:00
|
|
|
//===--- ASTReaderInternals.h - AST Reader Internals ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides internal definitions used in the AST reader.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
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"
|
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"
|
2012-01-07 00:09:53 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2014-04-19 03:57:06 +08:00
|
|
|
#include "llvm/Support/OnDiskHashTable.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include <utility>
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class ASTReader;
|
|
|
|
class HeaderSearch;
|
|
|
|
struct HeaderFileInfo;
|
2013-03-07 02:12:47 +08:00
|
|
|
class FileEntry;
|
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 {
|
|
|
|
|
|
|
|
/// \brief Class that performs name lookup into a DeclContext stored
|
|
|
|
/// in an AST file.
|
|
|
|
class ASTDeclContextNameLookupTrait {
|
|
|
|
ASTReader &Reader;
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleFile &F;
|
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.
|
|
|
|
typedef llvm::SmallVector<DeclID, 4> data_type;
|
|
|
|
struct data_type_builder {
|
|
|
|
data_type &Data;
|
|
|
|
llvm::DenseSet<DeclID> Found;
|
|
|
|
|
|
|
|
data_type_builder(data_type &D) : Data(D) {}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
2014-04-19 04:27:24 +08:00
|
|
|
typedef unsigned hash_value_type;
|
|
|
|
typedef unsigned offset_type;
|
2015-09-02 04:35:42 +08:00
|
|
|
typedef ModuleFile *file_type;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
typedef DeclarationName external_key_type;
|
2015-08-27 07:55:49 +08:00
|
|
|
typedef DeclarationNameKey internal_key_type;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2012-04-16 10:51:46 +08:00
|
|
|
explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
|
2011-08-26 04:47:51 +08:00
|
|
|
: Reader(Reader), F(F) { }
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-01-24 02:53:14 +08:00
|
|
|
/// \brief Base class for the trait describing the on-disk hash table for the
|
|
|
|
/// 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
|
|
|
|
/// must provide the \c data_type typedef and the ReadData operation,
|
|
|
|
/// only.
|
|
|
|
class ASTIdentifierLookupTraitBase {
|
|
|
|
public:
|
|
|
|
typedef StringRef external_key_type;
|
|
|
|
typedef StringRef internal_key_type;
|
2014-04-19 04:27:24 +08:00
|
|
|
typedef unsigned hash_value_type;
|
|
|
|
typedef unsigned offset_type;
|
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);
|
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; }
|
|
|
|
|
|
|
|
// This hopefully will just get inlined and removed by the optimizer.
|
|
|
|
static const external_key_type&
|
|
|
|
GetExternalKey(const internal_key_type& x) { return x; }
|
|
|
|
|
|
|
|
static internal_key_type ReadKey(const unsigned char* d, unsigned n);
|
|
|
|
};
|
|
|
|
|
2011-08-26 04:47:51 +08:00
|
|
|
/// \brief 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;
|
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;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef IdentifierInfo * data_type;
|
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)
|
2011-08-26 04:47:51 +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);
|
2012-01-24 23:24:38 +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
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief The on-disk hash table used to contain information about
|
|
|
|
/// all of the identifiers in the program.
|
2014-04-19 03:57:06 +08:00
|
|
|
typedef llvm::OnDiskIterableChainedHashTable<ASTIdentifierLookupTrait>
|
2011-08-26 04:47:51 +08:00
|
|
|
ASTIdentifierLookupTable;
|
|
|
|
|
|
|
|
/// \brief Class that performs lookup for a selector's entries in the global
|
|
|
|
/// method pool stored in an AST file.
|
|
|
|
class ASTSelectorLookupTrait {
|
|
|
|
ASTReader &Reader;
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleFile &F;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
typedef Selector external_key_type;
|
|
|
|
typedef external_key_type internal_key_type;
|
2014-04-19 04:27:24 +08:00
|
|
|
typedef unsigned hash_value_type;
|
|
|
|
typedef unsigned offset_type;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
|
2011-08-26 04:47:51 +08:00
|
|
|
: Reader(Reader), F(F) { }
|
|
|
|
|
|
|
|
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(Selector Sel);
|
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; }
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
static std::pair<unsigned, unsigned>
|
|
|
|
ReadKeyDataLength(const unsigned char*& d);
|
|
|
|
|
|
|
|
internal_key_type ReadKey(const unsigned char* d, unsigned);
|
|
|
|
data_type ReadData(Selector, const unsigned char* d, unsigned DataLen);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief The on-disk hash table used for the global method pool.
|
2014-04-19 03:57:06 +08:00
|
|
|
typedef llvm::OnDiskChainedHashTable<ASTSelectorLookupTrait>
|
2011-08-26 04:47:51 +08:00
|
|
|
ASTSelectorLookupTable;
|
|
|
|
|
|
|
|
/// \brief Trait class used to search the on-disk hash table containing all of
|
|
|
|
/// the header search information.
|
|
|
|
///
|
|
|
|
/// The on-disk hash table contains a mapping from each header path to
|
|
|
|
/// 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:
|
2013-03-07 02:12:47 +08:00
|
|
|
typedef const FileEntry *external_key_type;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
typedef const internal_key_type &internal_key_ref;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
typedef HeaderFileInfo data_type;
|
2014-04-19 04:27:24 +08:00
|
|
|
typedef unsigned hash_value_type;
|
|
|
|
typedef unsigned offset_type;
|
2011-08-26 04:47:51 +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)
|
|
|
|
: Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { }
|
2011-08-26 04:47:51 +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);
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
static std::pair<unsigned, unsigned>
|
|
|
|
ReadKeyDataLength(const unsigned char*& d);
|
|
|
|
|
2013-03-07 02:12:47 +08:00
|
|
|
static internal_key_type ReadKey(const unsigned char *d, unsigned);
|
2011-08-26 04:47:51 +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
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief The on-disk hash table used for known header files.
|
2014-04-19 03:57:06 +08:00
|
|
|
typedef llvm::OnDiskChainedHashTable<HeaderFileInfoTrait>
|
2011-08-26 04:47:51 +08:00
|
|
|
HeaderFileInfoLookupTable;
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
} // end namespace clang::serialization::reader
|
|
|
|
} // end namespace clang::serialization
|
2011-08-26 04:47:51 +08:00
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|