]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/include/clang/Lex/PTHManager.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / include / clang / Lex / PTHManager.h
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/Basic/Diagnostic.h"
18 #include "clang/Basic/IdentifierTable.h"
19 #include "clang/Basic/LangOptions.h"
20 #include "clang/Lex/PTHLexer.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/Support/Allocator.h"
23 #include <string>
24
25 namespace llvm {
26   class MemoryBuffer;
27 }
28
29 namespace clang {
30
31 class FileEntry;
32 class PTHLexer;
33 class DiagnosticsEngine;
34 class FileSystemStatCache;
35
36 class PTHManager : public IdentifierInfoLookup {
37   friend class PTHLexer;
38
39   /// The memory mapped PTH file.
40   const llvm::MemoryBuffer* Buf;
41
42   /// Alloc - Allocator used for IdentifierInfo objects.
43   llvm::BumpPtrAllocator Alloc;
44
45   /// IdMap - A lazily generated cache mapping from persistent identifiers to
46   ///  IdentifierInfo*.
47   IdentifierInfo** PerIDCache;
48
49   /// FileLookup - Abstract data structure used for mapping between files
50   ///  and token data in the PTH file.
51   void* FileLookup;
52
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;
57
58   /// SortedIdTable - Abstract data structure mapping from strings to
59   ///  persistent IDs.  This is used by get().
60   void* StringIdLookup;
61
62   /// NumIds - The number of identifiers in the PTH file.
63   const unsigned NumIds;
64
65   /// PP - The Preprocessor object that will use this PTHManager to create
66   ///  PTHLexer objects.
67   Preprocessor* PP;
68
69   /// SpellingBase - The base offset within the PTH memory buffer that
70   ///  contains the cached spellings for literals.
71   const unsigned char* const SpellingBase;
72
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;
76
77   /// This constructor is intended to only be called by the static 'Create'
78   /// method.
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);
83
84   PTHManager(const PTHManager &) LLVM_DELETED_FUNCTION;
85   void operator=(const PTHManager &) LLVM_DELETED_FUNCTION;
86
87   /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached
88   ///  spelling for a token.
89   unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer);
90
91   /// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the
92   ///  PTH file.
93   inline IdentifierInfo* GetIdentifierInfo(unsigned PersistentID) {
94     // Check if the IdentifierInfo has already been resolved.
95     if (IdentifierInfo* II = PerIDCache[PersistentID])
96       return II;
97     return LazilyCreateIdentifierInfo(PersistentID);
98   }
99   IdentifierInfo* LazilyCreateIdentifierInfo(unsigned PersistentID);
100
101 public:
102   // The current PTH version.
103   enum { Version = 10 };
104
105   ~PTHManager();
106
107   /// getOriginalSourceFile - Return the full path to the original header
108   ///  file name that was used to generate the PTH cache.
109   const char* getOriginalSourceFile() const {
110     return OriginalSourceFile;
111   }
112
113   /// get - Return the identifier token info for the specified named identifier.
114   ///  Unlike the version in IdentifierTable, this returns a pointer instead
115   ///  of a reference.  If the pointer is NULL then the IdentifierInfo cannot
116   ///  be found.
117   IdentifierInfo *get(StringRef Name);
118
119   /// Create - This method creates PTHManager objects.  The 'file' argument
120   ///  is the name of the PTH file.  This method returns NULL upon failure.
121   static PTHManager *Create(const std::string& file, DiagnosticsEngine &Diags);
122
123   void setPreprocessor(Preprocessor *pp) { PP = pp; }
124
125   /// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the
126   ///  specified file.  This method returns NULL if no cached tokens exist.
127   ///  It is the responsibility of the caller to 'delete' the returned object.
128   PTHLexer *CreateLexer(FileID FID);
129
130   /// createStatCache - Returns a FileSystemStatCache object for use with
131   ///  FileManager objects.  These objects use the PTH data to speed up
132   ///  calls to stat by memoizing their results from when the PTH file
133   ///  was generated.
134   FileSystemStatCache *createStatCache();
135 };
136
137 }  // end namespace clang
138
139 #endif