]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Serialization/Module.h
MFC r244628:
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / Serialization / Module.h
1 //===--- Module.h - Module description --------------------------*- 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 Module class, which describes a module that has
11 //  been loaded from an AST file.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_SERIALIZATION_MODULE_H
16 #define LLVM_CLANG_SERIALIZATION_MODULE_H
17
18 #include "clang/Serialization/ASTBitCodes.h"
19 #include "clang/Serialization/ContinuousRangeMap.h"
20 #include "clang/Basic/SourceLocation.h"
21 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/ADT/SetVector.h"
23 #include "llvm/Bitcode/BitstreamReader.h"
24 #include <string>
25
26 namespace clang {
27
28 class FileEntry;
29 class DeclContext;
30 class Module;
31 template<typename Info> class OnDiskChainedHashTable;
32
33 namespace serialization {
34
35 namespace reader {
36   class ASTDeclContextNameLookupTrait;
37 }
38
39 /// \brief Specifies the kind of module that has been loaded.
40 enum ModuleKind {
41   MK_Module,   ///< File is a module proper.
42   MK_PCH,      ///< File is a PCH file treated as such.
43   MK_Preamble, ///< File is a PCH file treated as the preamble.
44   MK_MainFile  ///< File is a PCH file treated as the actual main file.
45 };
46
47 /// \brief Information about the contents of a DeclContext.
48 struct DeclContextInfo {
49   DeclContextInfo()
50     : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
51
52   OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait>
53     *NameLookupTableData; // an ASTDeclContextNameLookupTable.
54   const KindDeclIDPair *LexicalDecls;
55   unsigned NumLexicalDecls;
56 };
57
58 /// \brief Information about a module that has been loaded by the ASTReader.
59 ///
60 /// Each instance of the Module class corresponds to a single AST file, which
61 /// may be a precompiled header, precompiled preamble, a module, or an AST file
62 /// of some sort loaded as the main file, all of which are specific formulations
63 /// of the general notion of a "module". A module may depend on any number of
64 /// other modules.
65 class ModuleFile {
66 public:
67   ModuleFile(ModuleKind Kind, unsigned Generation);
68   ~ModuleFile();
69
70   // === General information ===
71
72   /// \brief The type of this module.
73   ModuleKind Kind;
74
75   /// \brief The file name of the module file.
76   std::string FileName;
77
78   /// \brief The original source file name that was used to build the
79   /// primary AST file, which may have been modified for
80   /// relocatable-pch support.
81   std::string OriginalSourceFileName;
82
83   /// \brief The actual original source file name that was used to
84   /// build this AST file.
85   std::string ActualOriginalSourceFileName;
86
87   /// \brief The file ID for the original source file that was used to
88   /// build this AST file.
89   FileID OriginalSourceFileID;
90
91   /// \brief The directory that the PCH was originally created in. Used to
92   /// allow resolving headers even after headers+PCH was moved to a new path.
93   std::string OriginalDir;
94
95   /// \brief Whether this precompiled header is a relocatable PCH file.
96   bool RelocatablePCH;
97
98   /// \brief The file entry for the module file.
99   const FileEntry *File;
100
101   /// \brief Whether this module has been directly imported by the
102   /// user.
103   bool DirectlyImported;
104
105   /// \brief The generation of which this module file is a part.
106   unsigned Generation;
107   
108   /// \brief The memory buffer that stores the data associated with
109   /// this AST file.
110   OwningPtr<llvm::MemoryBuffer> Buffer;
111
112   /// \brief The size of this file, in bits.
113   uint64_t SizeInBits;
114
115   /// \brief The global bit offset (or base) of this module
116   uint64_t GlobalBitOffset;
117
118   /// \brief The bitstream reader from which we'll read the AST file.
119   llvm::BitstreamReader StreamFile;
120
121   /// \brief The main bitstream cursor for the main block.
122   llvm::BitstreamCursor Stream;
123
124   /// \brief The source location where this module was first imported.
125   /// FIXME: This is not properly initialized yet.
126   SourceLocation ImportLoc;
127
128   /// \brief The first source location in this module.
129   SourceLocation FirstLoc;
130
131   // === Input Files ===
132   /// \brief The cursor to the start of the input-files block.
133   llvm::BitstreamCursor InputFilesCursor;
134
135   /// \brief Offsets for all of the input file entries in the AST file.
136   const uint32_t *InputFileOffsets;
137
138   /// \brief The input files that have been loaded from this AST file, along
139   /// with a bool indicating whether this was an overridden buffer.
140   std::vector<llvm::PointerIntPair<const FileEntry *, 1, bool> > 
141     InputFilesLoaded;
142
143   // === Source Locations ===
144
145   /// \brief Cursor used to read source location entries.
146   llvm::BitstreamCursor SLocEntryCursor;
147
148   /// \brief The number of source location entries in this AST file.
149   unsigned LocalNumSLocEntries;
150
151   /// \brief The base ID in the source manager's view of this module.
152   int SLocEntryBaseID;
153
154   /// \brief The base offset in the source manager's view of this module.
155   unsigned SLocEntryBaseOffset;
156
157   /// \brief Offsets for all of the source location entries in the
158   /// AST file.
159   const uint32_t *SLocEntryOffsets;
160
161   /// \brief SLocEntries that we're going to preload.
162   SmallVector<uint64_t, 4> PreloadSLocEntries;
163
164   /// \brief Remapping table for source locations in this module.
165   ContinuousRangeMap<uint32_t, int, 2> SLocRemap;
166
167   // === Identifiers ===
168
169   /// \brief The number of identifiers in this AST file.
170   unsigned LocalNumIdentifiers;
171
172   /// \brief Offsets into the identifier table data.
173   ///
174   /// This array is indexed by the identifier ID (-1), and provides
175   /// the offset into IdentifierTableData where the string data is
176   /// stored.
177   const uint32_t *IdentifierOffsets;
178
179   /// \brief Base identifier ID for identifiers local to this module.
180   serialization::IdentID BaseIdentifierID;
181
182   /// \brief Remapping table for identifier IDs in this module.
183   ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap;
184
185   /// \brief Actual data for the on-disk hash table of identifiers.
186   ///
187   /// This pointer points into a memory buffer, where the on-disk hash
188   /// table for identifiers actually lives.
189   const char *IdentifierTableData;
190
191   /// \brief A pointer to an on-disk hash table of opaque type
192   /// IdentifierHashTable.
193   void *IdentifierLookupTable;
194
195   // === Macros ===
196
197   /// \brief The cursor to the start of the preprocessor block, which stores
198   /// all of the macro definitions.
199   llvm::BitstreamCursor MacroCursor;
200
201   /// \brief The number of macros in this AST file.
202   unsigned LocalNumMacros;
203
204   /// \brief Offsets of macros in the preprocessor block.
205   ///
206   /// This array is indexed by the macro ID (-1), and provides
207   /// the offset into the preprocessor block where macro definitions are
208   /// stored.
209   const uint32_t *MacroOffsets;
210
211   /// \brief Base macro ID for macros local to this module.
212   serialization::MacroID BaseMacroID;
213
214   /// \brief Remapping table for macro IDs in this module.
215   ContinuousRangeMap<uint32_t, int, 2> MacroRemap;
216
217   /// \brief The offset of the start of the set of defined macros.
218   uint64_t MacroStartOffset;
219
220   // === Detailed PreprocessingRecord ===
221
222   /// \brief The cursor to the start of the (optional) detailed preprocessing
223   /// record block.
224   llvm::BitstreamCursor PreprocessorDetailCursor;
225
226   /// \brief The offset of the start of the preprocessor detail cursor.
227   uint64_t PreprocessorDetailStartOffset;
228
229   /// \brief Base preprocessed entity ID for preprocessed entities local to
230   /// this module.
231   serialization::PreprocessedEntityID BasePreprocessedEntityID;
232
233   /// \brief Remapping table for preprocessed entity IDs in this module.
234   ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap;
235
236   const PPEntityOffset *PreprocessedEntityOffsets;
237   unsigned NumPreprocessedEntities;
238
239   // === Header search information ===
240
241   /// \brief The number of local HeaderFileInfo structures.
242   unsigned LocalNumHeaderFileInfos;
243
244   /// \brief Actual data for the on-disk hash table of header file
245   /// information.
246   ///
247   /// This pointer points into a memory buffer, where the on-disk hash
248   /// table for header file information actually lives.
249   const char *HeaderFileInfoTableData;
250
251   /// \brief The on-disk hash table that contains information about each of
252   /// the header files.
253   void *HeaderFileInfoTable;
254
255   /// \brief Actual data for the list of framework names used in the header
256   /// search information.
257   const char *HeaderFileFrameworkStrings;
258
259   // === Submodule information ===  
260   /// \brief The number of submodules in this module.
261   unsigned LocalNumSubmodules;
262   
263   /// \brief Base submodule ID for submodules local to this module.
264   serialization::SubmoduleID BaseSubmoduleID;
265   
266   /// \brief Remapping table for submodule IDs in this module.
267   ContinuousRangeMap<uint32_t, int, 2> SubmoduleRemap;
268   
269   // === Selectors ===
270
271   /// \brief The number of selectors new to this file.
272   ///
273   /// This is the number of entries in SelectorOffsets.
274   unsigned LocalNumSelectors;
275
276   /// \brief Offsets into the selector lookup table's data array
277   /// where each selector resides.
278   const uint32_t *SelectorOffsets;
279
280   /// \brief Base selector ID for selectors local to this module.
281   serialization::SelectorID BaseSelectorID;
282
283   /// \brief Remapping table for selector IDs in this module.
284   ContinuousRangeMap<uint32_t, int, 2> SelectorRemap;
285
286   /// \brief A pointer to the character data that comprises the selector table
287   ///
288   /// The SelectorOffsets table refers into this memory.
289   const unsigned char *SelectorLookupTableData;
290
291   /// \brief A pointer to an on-disk hash table of opaque type
292   /// ASTSelectorLookupTable.
293   ///
294   /// This hash table provides the IDs of all selectors, and the associated
295   /// instance and factory methods.
296   void *SelectorLookupTable;
297
298   // === Declarations ===
299
300   /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
301   /// has read all the abbreviations at the start of the block and is ready to
302   /// jump around with these in context.
303   llvm::BitstreamCursor DeclsCursor;
304
305   /// \brief The number of declarations in this AST file.
306   unsigned LocalNumDecls;
307
308   /// \brief Offset of each declaration within the bitstream, indexed
309   /// by the declaration ID (-1).
310   const DeclOffset *DeclOffsets;
311
312   /// \brief Base declaration ID for declarations local to this module.
313   serialization::DeclID BaseDeclID;
314
315   /// \brief Remapping table for declaration IDs in this module.
316   ContinuousRangeMap<uint32_t, int, 2> DeclRemap;
317
318   /// \brief Mapping from the module files that this module file depends on
319   /// to the base declaration ID for that module as it is understood within this
320   /// module.
321   ///
322   /// This is effectively a reverse global-to-local mapping for declaration
323   /// IDs, so that we can interpret a true global ID (for this translation unit)
324   /// as a local ID (for this module file).
325   llvm::DenseMap<ModuleFile *, serialization::DeclID> GlobalToLocalDeclIDs;
326
327   /// \brief The number of C++ base specifier sets in this AST file.
328   unsigned LocalNumCXXBaseSpecifiers;
329
330   /// \brief Offset of each C++ base specifier set within the bitstream,
331   /// indexed by the C++ base specifier set ID (-1).
332   const uint32_t *CXXBaseSpecifiersOffsets;
333
334   typedef llvm::DenseMap<const DeclContext *, DeclContextInfo>
335   DeclContextInfosMap;
336
337   /// \brief Information about the lexical and visible declarations
338   /// for each DeclContext.
339   DeclContextInfosMap DeclContextInfos;
340
341   /// \brief Array of file-level DeclIDs sorted by file.
342   const serialization::DeclID *FileSortedDecls;
343   unsigned NumFileSortedDecls;
344
345   /// \brief Array of redeclaration chain location information within this 
346   /// module file, sorted by the first declaration ID.
347   const serialization::LocalRedeclarationsInfo *RedeclarationsMap;
348
349   /// \brief The number of redeclaration info entries in RedeclarationsMap.
350   unsigned LocalNumRedeclarationsInMap;
351   
352   /// \brief The redeclaration chains for declarations local to this
353   /// module file.
354   SmallVector<uint64_t, 1> RedeclarationChains;
355   
356   /// \brief Array of category list location information within this 
357   /// module file, sorted by the definition ID.
358   const serialization::ObjCCategoriesInfo *ObjCCategoriesMap;
359   
360   /// \brief The number of redeclaration info entries in ObjCCategoriesMap.
361   unsigned LocalNumObjCCategoriesInMap;
362   
363   /// \brief The Objective-C category lists for categories known to this
364   /// module.
365   SmallVector<uint64_t, 1> ObjCCategories;
366
367   // === Types ===
368
369   /// \brief The number of types in this AST file.
370   unsigned LocalNumTypes;
371
372   /// \brief Offset of each type within the bitstream, indexed by the
373   /// type ID, or the representation of a Type*.
374   const uint32_t *TypeOffsets;
375
376   /// \brief Base type ID for types local to this module as represented in
377   /// the global type ID space.
378   serialization::TypeID BaseTypeIndex;
379
380   /// \brief Remapping table for type IDs in this module.
381   ContinuousRangeMap<uint32_t, int, 2> TypeRemap;
382
383   // === Miscellaneous ===
384
385   /// \brief Diagnostic IDs and their mappings that the user changed.
386   SmallVector<uint64_t, 8> PragmaDiagMappings;
387
388   /// \brief List of modules which depend on this module
389   llvm::SetVector<ModuleFile *> ImportedBy;
390
391   /// \brief List of modules which this module depends on
392   llvm::SetVector<ModuleFile *> Imports;
393
394   /// \brief Determine whether this module was directly imported at
395   /// any point during translation.
396   bool isDirectlyImported() const { return DirectlyImported; }
397
398   /// \brief Dump debugging output for this module.
399   void dump();
400 };
401
402 } // end namespace serialization
403
404 } // end namespace clang
405
406 #endif