1 //===--- Module.h - Module description --------------------------*- 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 Module class, which describes a module that has
11 // been loaded from an AST file.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_SERIALIZATION_MODULE_H
16 #define LLVM_CLANG_SERIALIZATION_MODULE_H
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"
31 template<typename Info> class OnDiskChainedHashTable;
33 namespace serialization {
36 class ASTDeclContextNameLookupTrait;
39 /// \brief Specifies the kind of module that has been loaded.
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.
47 /// \brief Information about the contents of a DeclContext.
48 struct DeclContextInfo {
50 : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
52 OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait>
53 *NameLookupTableData; // an ASTDeclContextNameLookupTable.
54 const KindDeclIDPair *LexicalDecls;
55 unsigned NumLexicalDecls;
58 /// \brief Information about a module that has been loaded by the ASTReader.
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
67 ModuleFile(ModuleKind Kind, unsigned Generation);
70 // === General information ===
72 /// \brief The type of this module.
75 /// \brief The file name of the module file.
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;
83 /// \brief The actual original source file name that was used to
84 /// build this AST file.
85 std::string ActualOriginalSourceFileName;
87 /// \brief The file ID for the original source file that was used to
88 /// build this AST file.
89 FileID OriginalSourceFileID;
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;
95 /// \brief Whether this precompiled header is a relocatable PCH file.
98 /// \brief The file entry for the module file.
99 const FileEntry *File;
101 /// \brief Whether this module has been directly imported by the
103 bool DirectlyImported;
105 /// \brief The generation of which this module file is a part.
108 /// \brief The memory buffer that stores the data associated with
110 OwningPtr<llvm::MemoryBuffer> Buffer;
112 /// \brief The size of this file, in bits.
115 /// \brief The global bit offset (or base) of this module
116 uint64_t GlobalBitOffset;
118 /// \brief The bitstream reader from which we'll read the AST file.
119 llvm::BitstreamReader StreamFile;
121 /// \brief The main bitstream cursor for the main block.
122 llvm::BitstreamCursor Stream;
124 /// \brief The source location where this module was first imported.
125 /// FIXME: This is not properly initialized yet.
126 SourceLocation ImportLoc;
128 /// \brief The first source location in this module.
129 SourceLocation FirstLoc;
131 // === Input Files ===
132 /// \brief The cursor to the start of the input-files block.
133 llvm::BitstreamCursor InputFilesCursor;
135 /// \brief Offsets for all of the input file entries in the AST file.
136 const uint32_t *InputFileOffsets;
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> >
143 // === Source Locations ===
145 /// \brief Cursor used to read source location entries.
146 llvm::BitstreamCursor SLocEntryCursor;
148 /// \brief The number of source location entries in this AST file.
149 unsigned LocalNumSLocEntries;
151 /// \brief The base ID in the source manager's view of this module.
154 /// \brief The base offset in the source manager's view of this module.
155 unsigned SLocEntryBaseOffset;
157 /// \brief Offsets for all of the source location entries in the
159 const uint32_t *SLocEntryOffsets;
161 /// \brief SLocEntries that we're going to preload.
162 SmallVector<uint64_t, 4> PreloadSLocEntries;
164 /// \brief Remapping table for source locations in this module.
165 ContinuousRangeMap<uint32_t, int, 2> SLocRemap;
167 // === Identifiers ===
169 /// \brief The number of identifiers in this AST file.
170 unsigned LocalNumIdentifiers;
172 /// \brief Offsets into the identifier table data.
174 /// This array is indexed by the identifier ID (-1), and provides
175 /// the offset into IdentifierTableData where the string data is
177 const uint32_t *IdentifierOffsets;
179 /// \brief Base identifier ID for identifiers local to this module.
180 serialization::IdentID BaseIdentifierID;
182 /// \brief Remapping table for identifier IDs in this module.
183 ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap;
185 /// \brief Actual data for the on-disk hash table of identifiers.
187 /// This pointer points into a memory buffer, where the on-disk hash
188 /// table for identifiers actually lives.
189 const char *IdentifierTableData;
191 /// \brief A pointer to an on-disk hash table of opaque type
192 /// IdentifierHashTable.
193 void *IdentifierLookupTable;
197 /// \brief The cursor to the start of the preprocessor block, which stores
198 /// all of the macro definitions.
199 llvm::BitstreamCursor MacroCursor;
201 /// \brief The number of macros in this AST file.
202 unsigned LocalNumMacros;
204 /// \brief Offsets of macros in the preprocessor block.
206 /// This array is indexed by the macro ID (-1), and provides
207 /// the offset into the preprocessor block where macro definitions are
209 const uint32_t *MacroOffsets;
211 /// \brief Base macro ID for macros local to this module.
212 serialization::MacroID BaseMacroID;
214 /// \brief Remapping table for macro IDs in this module.
215 ContinuousRangeMap<uint32_t, int, 2> MacroRemap;
217 /// \brief The offset of the start of the set of defined macros.
218 uint64_t MacroStartOffset;
220 // === Detailed PreprocessingRecord ===
222 /// \brief The cursor to the start of the (optional) detailed preprocessing
224 llvm::BitstreamCursor PreprocessorDetailCursor;
226 /// \brief The offset of the start of the preprocessor detail cursor.
227 uint64_t PreprocessorDetailStartOffset;
229 /// \brief Base preprocessed entity ID for preprocessed entities local to
231 serialization::PreprocessedEntityID BasePreprocessedEntityID;
233 /// \brief Remapping table for preprocessed entity IDs in this module.
234 ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap;
236 const PPEntityOffset *PreprocessedEntityOffsets;
237 unsigned NumPreprocessedEntities;
239 // === Header search information ===
241 /// \brief The number of local HeaderFileInfo structures.
242 unsigned LocalNumHeaderFileInfos;
244 /// \brief Actual data for the on-disk hash table of header file
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;
251 /// \brief The on-disk hash table that contains information about each of
252 /// the header files.
253 void *HeaderFileInfoTable;
255 /// \brief Actual data for the list of framework names used in the header
256 /// search information.
257 const char *HeaderFileFrameworkStrings;
259 // === Submodule information ===
260 /// \brief The number of submodules in this module.
261 unsigned LocalNumSubmodules;
263 /// \brief Base submodule ID for submodules local to this module.
264 serialization::SubmoduleID BaseSubmoduleID;
266 /// \brief Remapping table for submodule IDs in this module.
267 ContinuousRangeMap<uint32_t, int, 2> SubmoduleRemap;
271 /// \brief The number of selectors new to this file.
273 /// This is the number of entries in SelectorOffsets.
274 unsigned LocalNumSelectors;
276 /// \brief Offsets into the selector lookup table's data array
277 /// where each selector resides.
278 const uint32_t *SelectorOffsets;
280 /// \brief Base selector ID for selectors local to this module.
281 serialization::SelectorID BaseSelectorID;
283 /// \brief Remapping table for selector IDs in this module.
284 ContinuousRangeMap<uint32_t, int, 2> SelectorRemap;
286 /// \brief A pointer to the character data that comprises the selector table
288 /// The SelectorOffsets table refers into this memory.
289 const unsigned char *SelectorLookupTableData;
291 /// \brief A pointer to an on-disk hash table of opaque type
292 /// ASTSelectorLookupTable.
294 /// This hash table provides the IDs of all selectors, and the associated
295 /// instance and factory methods.
296 void *SelectorLookupTable;
298 // === Declarations ===
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;
305 /// \brief The number of declarations in this AST file.
306 unsigned LocalNumDecls;
308 /// \brief Offset of each declaration within the bitstream, indexed
309 /// by the declaration ID (-1).
310 const DeclOffset *DeclOffsets;
312 /// \brief Base declaration ID for declarations local to this module.
313 serialization::DeclID BaseDeclID;
315 /// \brief Remapping table for declaration IDs in this module.
316 ContinuousRangeMap<uint32_t, int, 2> DeclRemap;
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
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;
327 /// \brief The number of C++ base specifier sets in this AST file.
328 unsigned LocalNumCXXBaseSpecifiers;
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;
334 typedef llvm::DenseMap<const DeclContext *, DeclContextInfo>
337 /// \brief Information about the lexical and visible declarations
338 /// for each DeclContext.
339 DeclContextInfosMap DeclContextInfos;
341 /// \brief Array of file-level DeclIDs sorted by file.
342 const serialization::DeclID *FileSortedDecls;
343 unsigned NumFileSortedDecls;
345 /// \brief Array of redeclaration chain location information within this
346 /// module file, sorted by the first declaration ID.
347 const serialization::LocalRedeclarationsInfo *RedeclarationsMap;
349 /// \brief The number of redeclaration info entries in RedeclarationsMap.
350 unsigned LocalNumRedeclarationsInMap;
352 /// \brief The redeclaration chains for declarations local to this
354 SmallVector<uint64_t, 1> RedeclarationChains;
356 /// \brief Array of category list location information within this
357 /// module file, sorted by the definition ID.
358 const serialization::ObjCCategoriesInfo *ObjCCategoriesMap;
360 /// \brief The number of redeclaration info entries in ObjCCategoriesMap.
361 unsigned LocalNumObjCCategoriesInMap;
363 /// \brief The Objective-C category lists for categories known to this
365 SmallVector<uint64_t, 1> ObjCCategories;
369 /// \brief The number of types in this AST file.
370 unsigned LocalNumTypes;
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;
376 /// \brief Base type ID for types local to this module as represented in
377 /// the global type ID space.
378 serialization::TypeID BaseTypeIndex;
380 /// \brief Remapping table for type IDs in this module.
381 ContinuousRangeMap<uint32_t, int, 2> TypeRemap;
383 // === Miscellaneous ===
385 /// \brief Diagnostic IDs and their mappings that the user changed.
386 SmallVector<uint64_t, 8> PragmaDiagMappings;
388 /// \brief List of modules which depend on this module
389 llvm::SetVector<ModuleFile *> ImportedBy;
391 /// \brief List of modules which this module depends on
392 llvm::SetVector<ModuleFile *> Imports;
394 /// \brief Determine whether this module was directly imported at
395 /// any point during translation.
396 bool isDirectlyImported() const { return DirectlyImported; }
398 /// \brief Dump debugging output for this module.
402 } // end namespace serialization
404 } // end namespace clang