1 //===--- PTHManager.h - Manager object for PTH processing -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the PTHManager interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_PTHMANAGER_H
15 #define LLVM_CLANG_PTHMANAGER_H
17 #include "clang/Lex/PTHLexer.h"
18 #include "clang/Basic/LangOptions.h"
19 #include "clang/Basic/IdentifierTable.h"
20 #include "clang/Basic/Diagnostic.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/Support/Allocator.h"
33 class DiagnosticsEngine;
34 class FileSystemStatCache;
36 class PTHManager : public IdentifierInfoLookup {
37 friend class PTHLexer;
39 /// The memory mapped PTH file.
40 const llvm::MemoryBuffer* Buf;
42 /// Alloc - Allocator used for IdentifierInfo objects.
43 llvm::BumpPtrAllocator Alloc;
45 /// IdMap - A lazily generated cache mapping from persistent identifiers to
47 IdentifierInfo** PerIDCache;
49 /// FileLookup - Abstract data structure used for mapping between files
50 /// and token data in the PTH file.
53 /// IdDataTable - Array representing the mapping from persistent IDs to the
54 /// data offset within the PTH file containing the information to
55 /// reconsitute an IdentifierInfo.
56 const unsigned char* const IdDataTable;
58 /// SortedIdTable - Abstract data structure mapping from strings to
59 /// persistent IDs. This is used by get().
62 /// NumIds - The number of identifiers in the PTH file.
63 const unsigned NumIds;
65 /// PP - The Preprocessor object that will use this PTHManager to create
69 /// SpellingBase - The base offset within the PTH memory buffer that
70 /// contains the cached spellings for literals.
71 const unsigned char* const SpellingBase;
73 /// OriginalSourceFile - A null-terminated C-string that specifies the name
74 /// if the file (if any) that was to used to generate the PTH cache.
75 const char* OriginalSourceFile;
77 /// This constructor is intended to only be called by the static 'Create'
79 PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
80 const unsigned char* idDataTable, IdentifierInfo** perIDCache,
81 void* stringIdLookup, unsigned numIds,
82 const unsigned char* spellingBase, const char *originalSourceFile);
86 void operator=(const PTHManager&);
88 /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached
89 /// spelling for a token.
90 unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer);
92 /// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the
94 inline IdentifierInfo* GetIdentifierInfo(unsigned PersistentID) {
95 // Check if the IdentifierInfo has already been resolved.
96 if (IdentifierInfo* II = PerIDCache[PersistentID])
98 return LazilyCreateIdentifierInfo(PersistentID);
100 IdentifierInfo* LazilyCreateIdentifierInfo(unsigned PersistentID);
103 // The current PTH version.
104 enum { Version = 9 };
108 /// getOriginalSourceFile - Return the full path to the original header
109 /// file name that was used to generate the PTH cache.
110 const char* getOriginalSourceFile() const {
111 return OriginalSourceFile;
114 /// get - Return the identifier token info for the specified named identifier.
115 /// Unlike the version in IdentifierTable, this returns a pointer instead
116 /// of a reference. If the pointer is NULL then the IdentifierInfo cannot
118 IdentifierInfo *get(StringRef Name);
120 /// Create - This method creates PTHManager objects. The 'file' argument
121 /// is the name of the PTH file. This method returns NULL upon failure.
122 static PTHManager *Create(const std::string& file, DiagnosticsEngine &Diags);
124 void setPreprocessor(Preprocessor *pp) { PP = pp; }
126 /// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the
127 /// specified file. This method returns NULL if no cached tokens exist.
128 /// It is the responsibility of the caller to 'delete' the returned object.
129 PTHLexer *CreateLexer(FileID FID);
131 /// createStatCache - Returns a FileSystemStatCache object for use with
132 /// FileManager objects. These objects use the PTH data to speed up
133 /// calls to stat by memoizing their results from when the PTH file
135 FileSystemStatCache *createStatCache();
138 } // end namespace clang