1193326Sed//===--- PTHManager.h - Manager object for PTH processing -------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the PTHManager interface. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_PTHMANAGER_H 15193326Sed#define LLVM_CLANG_PTHMANAGER_H 16193326Sed 17249423Sdim#include "clang/Basic/Diagnostic.h" 18249423Sdim#include "clang/Basic/IdentifierTable.h" 19249423Sdim#include "clang/Basic/LangOptions.h" 20193326Sed#include "clang/Lex/PTHLexer.h" 21193326Sed#include "llvm/ADT/DenseMap.h" 22193326Sed#include "llvm/Support/Allocator.h" 23193326Sed#include <string> 24193326Sed 25193326Sednamespace llvm { 26193326Sed class MemoryBuffer; 27193326Sed} 28193326Sed 29193326Sednamespace clang { 30193326Sed 31193326Sedclass FileEntry; 32193326Sedclass PTHLexer; 33226633Sdimclass DiagnosticsEngine; 34218893Sdimclass FileSystemStatCache; 35198092Srdivacky 36193326Sedclass PTHManager : public IdentifierInfoLookup { 37193326Sed friend class PTHLexer; 38198092Srdivacky 39193326Sed /// The memory mapped PTH file. 40193326Sed const llvm::MemoryBuffer* Buf; 41193326Sed 42193326Sed /// Alloc - Allocator used for IdentifierInfo objects. 43193326Sed llvm::BumpPtrAllocator Alloc; 44198092Srdivacky 45193326Sed /// IdMap - A lazily generated cache mapping from persistent identifiers to 46193326Sed /// IdentifierInfo*. 47193326Sed IdentifierInfo** PerIDCache; 48198092Srdivacky 49193326Sed /// FileLookup - Abstract data structure used for mapping between files 50193326Sed /// and token data in the PTH file. 51193326Sed void* FileLookup; 52198092Srdivacky 53193326Sed /// IdDataTable - Array representing the mapping from persistent IDs to the 54193326Sed /// data offset within the PTH file containing the information to 55193326Sed /// reconsitute an IdentifierInfo. 56193326Sed const unsigned char* const IdDataTable; 57198092Srdivacky 58193326Sed /// SortedIdTable - Abstract data structure mapping from strings to 59193326Sed /// persistent IDs. This is used by get(). 60193326Sed void* StringIdLookup; 61193326Sed 62193326Sed /// NumIds - The number of identifiers in the PTH file. 63193326Sed const unsigned NumIds; 64193326Sed 65193326Sed /// PP - The Preprocessor object that will use this PTHManager to create 66193326Sed /// PTHLexer objects. 67193326Sed Preprocessor* PP; 68198092Srdivacky 69198092Srdivacky /// SpellingBase - The base offset within the PTH memory buffer that 70193326Sed /// contains the cached spellings for literals. 71193326Sed const unsigned char* const SpellingBase; 72198092Srdivacky 73193326Sed /// OriginalSourceFile - A null-terminated C-string that specifies the name 74193326Sed /// if the file (if any) that was to used to generate the PTH cache. 75193326Sed const char* OriginalSourceFile; 76198092Srdivacky 77193326Sed /// This constructor is intended to only be called by the static 'Create' 78193326Sed /// method. 79193326Sed PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, 80193326Sed const unsigned char* idDataTable, IdentifierInfo** perIDCache, 81193326Sed void* stringIdLookup, unsigned numIds, 82193326Sed const unsigned char* spellingBase, const char *originalSourceFile); 83193326Sed 84243830Sdim PTHManager(const PTHManager &) LLVM_DELETED_FUNCTION; 85243830Sdim void operator=(const PTHManager &) LLVM_DELETED_FUNCTION; 86198092Srdivacky 87198092Srdivacky /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached 88193326Sed /// spelling for a token. 89193326Sed unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer); 90198092Srdivacky 91193326Sed /// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the 92193326Sed /// PTH file. 93193326Sed inline IdentifierInfo* GetIdentifierInfo(unsigned PersistentID) { 94193326Sed // Check if the IdentifierInfo has already been resolved. 95193326Sed if (IdentifierInfo* II = PerIDCache[PersistentID]) 96193326Sed return II; 97193326Sed return LazilyCreateIdentifierInfo(PersistentID); 98193326Sed } 99193326Sed IdentifierInfo* LazilyCreateIdentifierInfo(unsigned PersistentID); 100198092Srdivacky 101193326Sedpublic: 102193326Sed // The current PTH version. 103239462Sdim enum { Version = 10 }; 104193326Sed 105193326Sed ~PTHManager(); 106198092Srdivacky 107193326Sed /// getOriginalSourceFile - Return the full path to the original header 108193326Sed /// file name that was used to generate the PTH cache. 109193326Sed const char* getOriginalSourceFile() const { 110193326Sed return OriginalSourceFile; 111193326Sed } 112198092Srdivacky 113193326Sed /// get - Return the identifier token info for the specified named identifier. 114193326Sed /// Unlike the version in IdentifierTable, this returns a pointer instead 115193326Sed /// of a reference. If the pointer is NULL then the IdentifierInfo cannot 116193326Sed /// be found. 117226633Sdim IdentifierInfo *get(StringRef Name); 118198092Srdivacky 119193326Sed /// Create - This method creates PTHManager objects. The 'file' argument 120193326Sed /// is the name of the PTH file. This method returns NULL upon failure. 121226633Sdim static PTHManager *Create(const std::string& file, DiagnosticsEngine &Diags); 122193326Sed 123198092Srdivacky void setPreprocessor(Preprocessor *pp) { PP = pp; } 124198092Srdivacky 125193326Sed /// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the 126193326Sed /// specified file. This method returns NULL if no cached tokens exist. 127193326Sed /// It is the responsibility of the caller to 'delete' the returned object. 128198092Srdivacky PTHLexer *CreateLexer(FileID FID); 129198092Srdivacky 130218893Sdim /// createStatCache - Returns a FileSystemStatCache object for use with 131193326Sed /// FileManager objects. These objects use the PTH data to speed up 132193326Sed /// calls to stat by memoizing their results from when the PTH file 133193326Sed /// was generated. 134218893Sdim FileSystemStatCache *createStatCache(); 135193326Sed}; 136198092Srdivacky 137193326Sed} // end namespace clang 138193326Sed 139193326Sed#endif 140