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"
30 template<typename Info> class OnDiskChainedHashTable;
32 namespace serialization {
35 class ASTDeclContextNameLookupTrait;
38 /// \brief Specifies the kind of module that has been loaded.
40 MK_Module, ///< File is a module proper.
41 MK_PCH, ///< File is a PCH file treated as such.
42 MK_Preamble, ///< File is a PCH file treated as the preamble.
43 MK_MainFile ///< File is a PCH file treated as the actual main file.
46 /// \brief Information about the contents of a DeclContext.
47 struct DeclContextInfo {
49 : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
51 OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait>
52 *NameLookupTableData; // an ASTDeclContextNameLookupTable.
53 const KindDeclIDPair *LexicalDecls;
54 unsigned NumLexicalDecls;
57 /// \brief Information about a module that has been loaded by the ASTReader.
59 /// Each instance of the Module class corresponds to a single AST file, which
60 /// may be a precompiled header, precompiled preamble, a module, or an AST file
61 /// of some sort loaded as the main file, all of which are specific formulations
62 /// of the general notion of a "module". A module may depend on any number of
66 ModuleFile(ModuleKind Kind, unsigned Generation);
69 // === General information ===
71 /// \brief The type of this module.
74 /// \brief The file name of the module file.
77 /// \brief Whether this module has been directly imported by the
79 bool DirectlyImported;
81 /// \brief The generation of which this module file is a part.
84 /// \brief The memory buffer that stores the data associated with
86 OwningPtr<llvm::MemoryBuffer> Buffer;
88 /// \brief The size of this file, in bits.
91 /// \brief The global bit offset (or base) of this module
92 uint64_t GlobalBitOffset;
94 /// \brief The bitstream reader from which we'll read the AST file.
95 llvm::BitstreamReader StreamFile;
97 /// \brief The main bitstream cursor for the main block.
98 llvm::BitstreamCursor Stream;
100 /// \brief The source location where this module was first imported.
101 SourceLocation ImportLoc;
103 /// \brief The first source location in this module.
104 SourceLocation FirstLoc;
106 // === Source Locations ===
108 /// \brief Cursor used to read source location entries.
109 llvm::BitstreamCursor SLocEntryCursor;
111 /// \brief The number of source location entries in this AST file.
112 unsigned LocalNumSLocEntries;
114 /// \brief The base ID in the source manager's view of this module.
117 /// \brief The base offset in the source manager's view of this module.
118 unsigned SLocEntryBaseOffset;
120 /// \brief Offsets for all of the source location entries in the
122 const uint32_t *SLocEntryOffsets;
124 /// \brief SLocEntries that we're going to preload.
125 SmallVector<uint64_t, 4> PreloadSLocEntries;
127 /// \brief The number of source location file entries in this AST file.
128 unsigned LocalNumSLocFileEntries;
130 /// \brief Offsets for all of the source location file entries in the
132 const uint32_t *SLocFileOffsets;
134 /// \brief Remapping table for source locations in this module.
135 ContinuousRangeMap<uint32_t, int, 2> SLocRemap;
137 // === Identifiers ===
139 /// \brief The number of identifiers in this AST file.
140 unsigned LocalNumIdentifiers;
142 /// \brief Offsets into the identifier table data.
144 /// This array is indexed by the identifier ID (-1), and provides
145 /// the offset into IdentifierTableData where the string data is
147 const uint32_t *IdentifierOffsets;
149 /// \brief Base identifier ID for identifiers local to this module.
150 serialization::IdentID BaseIdentifierID;
152 /// \brief Remapping table for identifier IDs in this module.
153 ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap;
155 /// \brief Actual data for the on-disk hash table of identifiers.
157 /// This pointer points into a memory buffer, where the on-disk hash
158 /// table for identifiers actually lives.
159 const char *IdentifierTableData;
161 /// \brief A pointer to an on-disk hash table of opaque type
162 /// IdentifierHashTable.
163 void *IdentifierLookupTable;
167 /// \brief The cursor to the start of the preprocessor block, which stores
168 /// all of the macro definitions.
169 llvm::BitstreamCursor MacroCursor;
171 /// \brief The offset of the start of the set of defined macros.
172 uint64_t MacroStartOffset;
174 // === Detailed PreprocessingRecord ===
176 /// \brief The cursor to the start of the (optional) detailed preprocessing
178 llvm::BitstreamCursor PreprocessorDetailCursor;
180 /// \brief The offset of the start of the preprocessor detail cursor.
181 uint64_t PreprocessorDetailStartOffset;
183 /// \brief Base preprocessed entity ID for preprocessed entities local to
185 serialization::PreprocessedEntityID BasePreprocessedEntityID;
187 /// \brief Remapping table for preprocessed entity IDs in this module.
188 ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap;
190 const PPEntityOffset *PreprocessedEntityOffsets;
191 unsigned NumPreprocessedEntities;
193 // === Header search information ===
195 /// \brief The number of local HeaderFileInfo structures.
196 unsigned LocalNumHeaderFileInfos;
198 /// \brief Actual data for the on-disk hash table of header file
201 /// This pointer points into a memory buffer, where the on-disk hash
202 /// table for header file information actually lives.
203 const char *HeaderFileInfoTableData;
205 /// \brief The on-disk hash table that contains information about each of
206 /// the header files.
207 void *HeaderFileInfoTable;
209 /// \brief Actual data for the list of framework names used in the header
210 /// search information.
211 const char *HeaderFileFrameworkStrings;
213 // === Submodule information ===
214 /// \brief The number of submodules in this module.
215 unsigned LocalNumSubmodules;
217 /// \brief Base submodule ID for submodules local to this module.
218 serialization::SubmoduleID BaseSubmoduleID;
220 /// \brief Remapping table for submodule IDs in this module.
221 ContinuousRangeMap<uint32_t, int, 2> SubmoduleRemap;
225 /// \brief The number of selectors new to this file.
227 /// This is the number of entries in SelectorOffsets.
228 unsigned LocalNumSelectors;
230 /// \brief Offsets into the selector lookup table's data array
231 /// where each selector resides.
232 const uint32_t *SelectorOffsets;
234 /// \brief Base selector ID for selectors local to this module.
235 serialization::SelectorID BaseSelectorID;
237 /// \brief Remapping table for selector IDs in this module.
238 ContinuousRangeMap<uint32_t, int, 2> SelectorRemap;
240 /// \brief A pointer to the character data that comprises the selector table
242 /// The SelectorOffsets table refers into this memory.
243 const unsigned char *SelectorLookupTableData;
245 /// \brief A pointer to an on-disk hash table of opaque type
246 /// ASTSelectorLookupTable.
248 /// This hash table provides the IDs of all selectors, and the associated
249 /// instance and factory methods.
250 void *SelectorLookupTable;
252 // === Declarations ===
254 /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
255 /// has read all the abbreviations at the start of the block and is ready to
256 /// jump around with these in context.
257 llvm::BitstreamCursor DeclsCursor;
259 /// \brief The number of declarations in this AST file.
260 unsigned LocalNumDecls;
262 /// \brief Offset of each declaration within the bitstream, indexed
263 /// by the declaration ID (-1).
264 const DeclOffset *DeclOffsets;
266 /// \brief Base declaration ID for declarations local to this module.
267 serialization::DeclID BaseDeclID;
269 /// \brief Remapping table for declaration IDs in this module.
270 ContinuousRangeMap<uint32_t, int, 2> DeclRemap;
272 /// \brief Mapping from the module files that this module file depends on
273 /// to the base declaration ID for that module as it is understood within this
276 /// This is effectively a reverse global-to-local mapping for declaration
277 /// IDs, so that we can interpret a true global ID (for this translation unit)
278 /// as a local ID (for this module file).
279 llvm::DenseMap<ModuleFile *, serialization::DeclID> GlobalToLocalDeclIDs;
281 /// \brief The number of C++ base specifier sets in this AST file.
282 unsigned LocalNumCXXBaseSpecifiers;
284 /// \brief Offset of each C++ base specifier set within the bitstream,
285 /// indexed by the C++ base specifier set ID (-1).
286 const uint32_t *CXXBaseSpecifiersOffsets;
288 typedef llvm::DenseMap<const DeclContext *, DeclContextInfo>
291 /// \brief Information about the lexical and visible declarations
292 /// for each DeclContext.
293 DeclContextInfosMap DeclContextInfos;
295 /// \brief Array of file-level DeclIDs sorted by file.
296 const serialization::DeclID *FileSortedDecls;
298 /// \brief Array of redeclaration chain location information within this
299 /// module file, sorted by the first declaration ID.
300 const serialization::LocalRedeclarationsInfo *RedeclarationsMap;
302 /// \brief The number of redeclaration info entries in RedeclarationsMap.
303 unsigned LocalNumRedeclarationsInMap;
305 /// \brief The redeclaration chains for declarations local to this
307 SmallVector<uint64_t, 1> RedeclarationChains;
309 /// \brief Array of category list location information within this
310 /// module file, sorted by the definition ID.
311 const serialization::ObjCCategoriesInfo *ObjCCategoriesMap;
313 /// \brief The number of redeclaration info entries in ObjCCategoriesMap.
314 unsigned LocalNumObjCCategoriesInMap;
316 /// \brief The Objective-C category lists for categories known to this
318 SmallVector<uint64_t, 1> ObjCCategories;
322 /// \brief The number of types in this AST file.
323 unsigned LocalNumTypes;
325 /// \brief Offset of each type within the bitstream, indexed by the
326 /// type ID, or the representation of a Type*.
327 const uint32_t *TypeOffsets;
329 /// \brief Base type ID for types local to this module as represented in
330 /// the global type ID space.
331 serialization::TypeID BaseTypeIndex;
333 /// \brief Remapping table for type IDs in this module.
334 ContinuousRangeMap<uint32_t, int, 2> TypeRemap;
336 // === Miscellaneous ===
338 /// \brief Diagnostic IDs and their mappings that the user changed.
339 SmallVector<uint64_t, 8> PragmaDiagMappings;
341 /// \brief The AST stat cache installed for this file, if any.
343 /// The dynamic type of this stat cache is always ASTStatCache
346 /// \brief List of modules which depend on this module
347 llvm::SetVector<ModuleFile *> ImportedBy;
349 /// \brief List of modules which this module depends on
350 llvm::SetVector<ModuleFile *> Imports;
352 /// \brief Determine whether this module was directly imported at
353 /// any point during translation.
354 bool isDirectlyImported() const { return DirectlyImported; }
356 /// \brief Dump debugging output for this module.
360 } // end namespace serialization
362 } // end namespace clang