ASTReaderInternals.h [plain text]
#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
#define LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
#include "clang/AST/DeclarationName.h"
#include "clang/Basic/OnDiskHashTable.h"
#include "clang/Serialization/ASTBitCodes.h"
#include "llvm/Support/Endian.h"
#include <sys/stat.h>
#include <utility>
namespace clang {
class ASTReader;
class HeaderSearch;
struct HeaderFileInfo;
class FileEntry;
namespace serialization {
class ModuleFile;
namespace reader {
class ASTDeclContextNameLookupTrait {
ASTReader &Reader;
ModuleFile &F;
public:
typedef llvm::support::ulittle32_t LE32DeclID;
typedef std::pair<LE32DeclID *, LE32DeclID *> data_type;
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;
explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, ModuleFile &F)
: 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;
static std::pair<unsigned, unsigned>
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);
};
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);
static const internal_key_type&
GetInternalKey(const external_key_type& x) { return x; }
static const external_key_type&
GetExternalKey(const internal_key_type& x) { return x; }
static internal_key_type ReadKey(const unsigned char* d, unsigned n);
};
class ASTIdentifierLookupTrait : public ASTIdentifierLookupTraitBase {
ASTReader &Reader;
ModuleFile &F;
IdentifierInfo *KnownII;
public:
typedef IdentifierInfo * data_type;
ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
IdentifierInfo *II = 0)
: Reader(Reader), F(F), KnownII(II) { }
data_type ReadData(const internal_key_type& k,
const unsigned char* d,
unsigned DataLen);
ASTReader &getReader() const { return Reader; }
};
typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait>
ASTIdentifierLookupTable;
class ASTSelectorLookupTrait {
ASTReader &Reader;
ModuleFile &F;
public:
struct data_type {
SelectorID ID;
unsigned InstanceBits;
unsigned FactoryBits;
SmallVector<ObjCMethodDecl *, 2> Instance;
SmallVector<ObjCMethodDecl *, 2> Factory;
};
typedef Selector external_key_type;
typedef external_key_type internal_key_type;
ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F)
: 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&
GetInternalKey(const external_key_type& x) { return x; }
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);
};
typedef OnDiskChainedHashTable<ASTSelectorLookupTrait>
ASTSelectorLookupTable;
class HeaderFileInfoTrait {
ASTReader &Reader;
ModuleFile &M;
HeaderSearch *HS;
const char *FrameworkStrings;
public:
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;
typedef HeaderFileInfo data_type;
HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS,
const char *FrameworkStrings)
: Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { }
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);
static std::pair<unsigned, unsigned>
ReadKeyDataLength(const unsigned char*& d);
static internal_key_type ReadKey(const unsigned char *d, unsigned);
data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
};
typedef OnDiskChainedHashTable<HeaderFileInfoTrait>
HeaderFileInfoLookupTable;
} } }
#endif