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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
|
|
|
|
#define LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
|
|
|
|
|
|
|
|
#include "clang/AST/DeclarationName.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/OnDiskHashTable.h"
|
2013-01-24 02:53:14 +08:00
|
|
|
#include "clang/Serialization/ASTBitCodes.h"
|
2012-01-07 00:09:53 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2011-08-26 04:47:51 +08:00
|
|
|
#include <sys/stat.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:
|
|
|
|
/// \brief Pair of begin/end iterators for DeclIDs.
|
|
|
|
///
|
|
|
|
/// Note that these declaration IDs are local to the module that contains this
|
|
|
|
/// particular lookup t
|
2012-01-07 00:09:53 +08:00
|
|
|
typedef llvm::support::ulittle32_t LE32DeclID;
|
|
|
|
typedef std::pair<LE32DeclID *, LE32DeclID *> data_type;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
/// \brief Special internal key for declaration names.
|
|
|
|
/// The hash table creates keys for comparison; we do not create
|
|
|
|
/// a DeclarationName for the internal key to avoid deserializing types.
|
|
|
|
struct DeclNameKey {
|
|
|
|
DeclarationName::NameKind Kind;
|
|
|
|
uint64_t Data;
|
|
|
|
DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef DeclarationName external_key_type;
|
|
|
|
typedef DeclNameKey internal_key_type;
|
|
|
|
|
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) { }
|
|
|
|
|
|
|
|
static bool EqualKey(const internal_key_type& a,
|
|
|
|
const internal_key_type& b) {
|
|
|
|
return a.Kind == b.Kind && a.Data == b.Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ComputeHash(const DeclNameKey &Key) const;
|
|
|
|
internal_key_type GetInternalKey(const external_key_type& Name) const;
|
|
|
|
|
2012-04-16 10:51:46 +08:00
|
|
|
static std::pair<unsigned, unsigned>
|
2011-08-26 04:47:51 +08:00
|
|
|
ReadKeyDataLength(const unsigned char*& d);
|
|
|
|
|
|
|
|
internal_key_type ReadKey(const unsigned char* d, unsigned);
|
|
|
|
|
|
|
|
data_type ReadData(internal_key_type, const unsigned char* d,
|
|
|
|
unsigned DataLen);
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned ComputeHash(const internal_key_type& a);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
|
2011-08-26 04:47:51 +08:00
|
|
|
IdentifierInfo *II = 0)
|
|
|
|
: Reader(Reader), F(F), KnownII(II) { }
|
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
|
|
|
|
|
|
|
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.
|
|
|
|
typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait>
|
|
|
|
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;
|
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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned ComputeHash(Selector Sel);
|
|
|
|
|
|
|
|
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.
|
|
|
|
typedef OnDiskChainedHashTable<ASTSelectorLookupTrait>
|
|
|
|
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
|
|
|
|
/// controlling macro, etc.). Note that we actually hash based on the
|
|
|
|
/// filename, and support "deep" comparisons of file names based on current
|
|
|
|
/// 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;
|
|
|
|
const char *Filename;
|
|
|
|
};
|
|
|
|
typedef const internal_key_type &internal_key_ref;
|
2011-08-26 04:47:51 +08:00
|
|
|
|
|
|
|
typedef HeaderFileInfo data_type;
|
|
|
|
|
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
|
|
|
|
2013-03-07 02:12:47 +08:00
|
|
|
static unsigned ComputeHash(internal_key_ref ikey);
|
|
|
|
static internal_key_type GetInternalKey(const FileEntry *FE);
|
|
|
|
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.
|
|
|
|
typedef OnDiskChainedHashTable<HeaderFileInfoTrait>
|
|
|
|
HeaderFileInfoLookupTable;
|
|
|
|
|
|
|
|
} // end namespace clang::serialization::reader
|
|
|
|
} // end namespace clang::serialization
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|