PTHManager.h revision a4b44dd9d30929a35c44d85102e5241ee847b2f2
1//===--- PTHManager.h - Manager object for PTH processing -------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the PTHManager interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_PTHMANAGER_H 15#define LLVM_CLANG_PTHMANAGER_H 16 17#include "clang/Lex/PTHLexer.h" 18#include "clang/Basic/LangOptions.h" 19#include "clang/Basic/IdentifierTable.h" 20#include "llvm/ADT/DenseMap.h" 21#include "llvm/Support/Allocator.h" 22#include <string> 23 24namespace llvm { 25 class MemoryBuffer; 26} 27 28namespace clang { 29 30class FileEntry; 31class PTHLexer; 32class Diagnostic; 33class StatSysCallCache; 34 35class PTHManager : public IdentifierInfoLookup { 36 friend class PTHLexer; 37 38 /// The memory mapped PTH file. 39 const llvm::MemoryBuffer* Buf; 40 41 /// Alloc - Allocator used for IdentifierInfo objects. 42 llvm::BumpPtrAllocator Alloc; 43 44 /// IdMap - A lazily generated cache mapping from persistent identifiers to 45 /// IdentifierInfo*. 46 IdentifierInfo** PerIDCache; 47 48 /// FileLookup - Abstract data structure used for mapping between files 49 /// and token data in the PTH file. 50 void* FileLookup; 51 52 /// IdDataTable - Array representing the mapping from persistent IDs to the 53 /// data offset within the PTH file containing the information to 54 /// reconsitute an IdentifierInfo. 55 const unsigned char* const IdDataTable; 56 57 /// SortedIdTable - Abstract data structure mapping from strings to 58 /// persistent IDs. This is used by get(). 59 void* StringIdLookup; 60 61 /// NumIds - The number of identifiers in the PTH file. 62 const unsigned NumIds; 63 64 /// PP - The Preprocessor object that will use this PTHManager to create 65 /// PTHLexer objects. 66 Preprocessor* PP; 67 68 /// SpellingBase - The base offset within the PTH memory buffer that 69 /// contains the cached spellings for literals. 70 const unsigned char* const SpellingBase; 71 72 /// This constructor is intended to only be called by the static 'Create' 73 /// method. 74 PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, 75 const unsigned char* idDataTable, IdentifierInfo** perIDCache, 76 void* stringIdLookup, unsigned numIds, 77 const unsigned char* spellingBase); 78 79 // Do not implement. 80 PTHManager(); 81 void operator=(const PTHManager&); 82 83 /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached 84 /// spelling for a token. 85 unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer); 86 87 /// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the 88 /// PTH file. 89 inline IdentifierInfo* GetIdentifierInfo(unsigned PersistentID) { 90 // Check if the IdentifierInfo has already been resolved. 91 if (IdentifierInfo* II = PerIDCache[PersistentID]) 92 return II; 93 return LazilyCreateIdentifierInfo(PersistentID); 94 } 95 IdentifierInfo* LazilyCreateIdentifierInfo(unsigned PersistentID); 96 97public: 98 // The current PTH version. 99 enum { Version = 8 }; 100 101 ~PTHManager(); 102 103 /// get - Return the identifier token info for the specified named identifier. 104 /// Unlike the version in IdentifierTable, this returns a pointer instead 105 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot 106 /// be found. 107 IdentifierInfo *get(const char *NameStart, const char *NameEnd); 108 109 /// Create - This method creates PTHManager objects. The 'file' argument 110 /// is the name of the PTH file. This method returns NULL upon failure. 111 static PTHManager *Create(const std::string& file, Diagnostic* Diags = 0); 112 113 void setPreprocessor(Preprocessor *pp) { PP = pp; } 114 115 /// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the 116 /// specified file. This method returns NULL if no cached tokens exist. 117 /// It is the responsibility of the caller to 'delete' the returned object. 118 PTHLexer *CreateLexer(FileID FID); 119 120 /// createStatCache - Returns a StatSysCallCache object for use with 121 /// FileManager objects. These objects use the PTH data to speed up 122 /// calls to stat by memoizing their results from when the PTH file 123 /// was generated. 124 StatSysCallCache *createStatCache(); 125}; 126 127} // end namespace clang 128 129#endif 130