PTHManager.h revision 5f074266cc59563036c40516c814d63825723e20
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 "llvm/ADT/DenseMap.h" 20#include <string> 21 22namespace llvm { 23 class MemoryBuffer; 24} 25 26namespace clang { 27 28class FileEntry; 29class IdentifierInfo; 30class IdentifierTable; 31class PTHLexer; 32class PTHManager; 33 34class PTHSpellingSearch { 35 PTHManager& PTHMgr; 36 37 const char* TableBeg; 38 const char* TableEnd; 39 40 unsigned SpellingsLeft; 41 const char* LinearItr; 42 43public: 44 enum { SpellingEntrySize = 4*2 }; 45 46 unsigned getSpellingBinarySearch(unsigned fpos, const char *&Buffer); 47 unsigned getSpellingLinearSearch(unsigned fpos, const char *&Buffer); 48 49 PTHSpellingSearch(PTHManager& pm, unsigned numSpellings, const char* tableBeg) 50 : PTHMgr(pm), 51 TableBeg(tableBeg), 52 TableEnd(tableBeg + numSpellings*SpellingEntrySize), 53 SpellingsLeft(numSpellings), 54 LinearItr(tableBeg) {} 55}; 56 57class PTHManager { 58 friend class PTHLexer; 59 friend class PTHSpellingSearch; 60 61 /// The memory mapped PTH file. 62 const llvm::MemoryBuffer* Buf; 63 64 /// A map from FileIDs to SpellingSearch objects. 65 llvm::DenseMap<unsigned,PTHSpellingSearch*> SpellingMap; 66 67 /// IdMap - A lazily generated cache mapping from persistent identifiers to 68 /// IdentifierInfo*. 69 IdentifierInfo** PerIDCache; 70 71 /// FileLookup - Abstract data structure used for mapping between files 72 /// and token data in the PTH file. 73 void* FileLookup; 74 75 /// IdDataTable - Array representing the mapping from persistent IDs to the 76 /// data offset within the PTH file containing the information to 77 /// reconsitute an IdentifierInfo. 78 const char* IdDataTable; 79 80 /// ITable - The IdentifierTable used for the translation unit being lexed. 81 IdentifierTable& ITable; 82 83 /// PP - The Preprocessor object that will use this PTHManager to create 84 /// PTHLexer objects. 85 Preprocessor& PP; 86 87 /// This constructor is intended to only be called by the static 'Create' 88 /// method. 89 PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, 90 const char* idDataTable, IdentifierInfo** perIDCache, 91 Preprocessor& pp); 92 93 // Do not implement. 94 PTHManager(); 95 void operator=(const PTHManager&); 96 97 /// GetIdentifierInfo - Used by PTHManager to reconstruct IdentifierInfo 98 /// objects from the PTH file. 99 IdentifierInfo* GetIdentifierInfo(unsigned); 100 101 /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached 102 /// spelling for a token. 103 unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer); 104 105 unsigned getSpelling(unsigned FileID, unsigned fpos, const char *& Buffer); 106 107public: 108 109 ~PTHManager(); 110 111 /// Create - This method creates PTHManager objects. The 'file' argument 112 /// is the name of the PTH file. This method returns NULL upon failure. 113 static PTHManager* Create(const std::string& file, Preprocessor& 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(unsigned FileID, const FileEntry* FE); 119}; 120 121} // end namespace clang 122 123#endif 124