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 namespace serialization {
32 /// \brief Specifies the kind of module that has been loaded.
34 MK_Module, ///< File is a module proper.
35 MK_PCH, ///< File is a PCH file treated as such.
36 MK_Preamble, ///< File is a PCH file treated as the preamble.
37 MK_MainFile ///< File is a PCH file treated as the actual main file.
40 /// \brief Information about the contents of a DeclContext.
41 struct DeclContextInfo {
43 : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
45 void *NameLookupTableData; // an ASTDeclContextNameLookupTable.
46 const KindDeclIDPair *LexicalDecls;
47 unsigned NumLexicalDecls;
50 /// \brief Information about a module that has been loaded by the ASTReader.
52 /// Each instance of the Module class corresponds to a single AST file, which
53 /// may be a precompiled header, precompiled preamble, a module, or an AST file
54 /// of some sort loaded as the main file, all of which are specific formulations of
55 /// the general notion of a "module". A module may depend on any number of
59 Module(ModuleKind Kind);
62 // === General information ===
64 /// \brief The type of this module.
67 /// \brief The file name of the module file.
70 /// \brief Whether this module has been directly imported by the
72 bool DirectlyImported;
74 /// \brief The memory buffer that stores the data associated with
76 llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
78 /// \brief The size of this file, in bits.
81 /// \brief The global bit offset (or base) of this module
82 uint64_t GlobalBitOffset;
84 /// \brief The bitstream reader from which we'll read the AST file.
85 llvm::BitstreamReader StreamFile;
87 /// \brief The main bitstream cursor for the main block.
88 llvm::BitstreamCursor Stream;
90 /// \brief The source location where this module was first imported.
91 SourceLocation ImportLoc;
93 /// \brief The first source location in this module.
94 SourceLocation FirstLoc;
96 // === Source Locations ===
98 /// \brief Cursor used to read source location entries.
99 llvm::BitstreamCursor SLocEntryCursor;
101 /// \brief The number of source location entries in this AST file.
102 unsigned LocalNumSLocEntries;
104 /// \brief The base ID in the source manager's view of this module.
107 /// \brief The base offset in the source manager's view of this module.
108 unsigned SLocEntryBaseOffset;
110 /// \brief Offsets for all of the source location entries in the
112 const uint32_t *SLocEntryOffsets;
114 /// \brief SLocEntries that we're going to preload.
115 SmallVector<uint64_t, 4> PreloadSLocEntries;
117 /// \brief The number of source location file entries in this AST file.
118 unsigned LocalNumSLocFileEntries;
120 /// \brief Offsets for all of the source location file entries in the
122 const uint32_t *SLocFileOffsets;
124 /// \brief Remapping table for source locations in this module.
125 ContinuousRangeMap<uint32_t, int, 2> SLocRemap;
127 // === Identifiers ===
129 /// \brief The number of identifiers in this AST file.
130 unsigned LocalNumIdentifiers;
132 /// \brief Offsets into the identifier table data.
134 /// This array is indexed by the identifier ID (-1), and provides
135 /// the offset into IdentifierTableData where the string data is
137 const uint32_t *IdentifierOffsets;
139 /// \brief Base identifier ID for identifiers local to this module.
140 serialization::IdentID BaseIdentifierID;
142 /// \brief Remapping table for identifier IDs in this module.
143 ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap;
145 /// \brief Actual data for the on-disk hash table of identifiers.
147 /// This pointer points into a memory buffer, where the on-disk hash
148 /// table for identifiers actually lives.
149 const char *IdentifierTableData;
151 /// \brief A pointer to an on-disk hash table of opaque type
152 /// IdentifierHashTable.
153 void *IdentifierLookupTable;
157 /// \brief The cursor to the start of the preprocessor block, which stores
158 /// all of the macro definitions.
159 llvm::BitstreamCursor MacroCursor;
161 /// \brief The offset of the start of the set of defined macros.
162 uint64_t MacroStartOffset;
164 // === Detailed PreprocessingRecord ===
166 /// \brief The cursor to the start of the (optional) detailed preprocessing
168 llvm::BitstreamCursor PreprocessorDetailCursor;
170 /// \brief The offset of the start of the preprocessor detail cursor.
171 uint64_t PreprocessorDetailStartOffset;
173 /// \brief Base preprocessed entity ID for preprocessed entities local to
175 serialization::PreprocessedEntityID BasePreprocessedEntityID;
177 /// \brief Remapping table for preprocessed entity IDs in this module.
178 ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap;
180 const PPEntityOffset *PreprocessedEntityOffsets;
181 unsigned NumPreprocessedEntities;
183 // === Header search information ===
185 /// \brief The number of local HeaderFileInfo structures.
186 unsigned LocalNumHeaderFileInfos;
188 /// \brief Actual data for the on-disk hash table of header file
191 /// This pointer points into a memory buffer, where the on-disk hash
192 /// table for header file information actually lives.
193 const char *HeaderFileInfoTableData;
195 /// \brief The on-disk hash table that contains information about each of
196 /// the header files.
197 void *HeaderFileInfoTable;
199 /// \brief Actual data for the list of framework names used in the header
200 /// search information.
201 const char *HeaderFileFrameworkStrings;
205 /// \brief The number of selectors new to this file.
207 /// This is the number of entries in SelectorOffsets.
208 unsigned LocalNumSelectors;
210 /// \brief Offsets into the selector lookup table's data array
211 /// where each selector resides.
212 const uint32_t *SelectorOffsets;
214 /// \brief Base selector ID for selectors local to this module.
215 serialization::SelectorID BaseSelectorID;
217 /// \brief Remapping table for selector IDs in this module.
218 ContinuousRangeMap<uint32_t, int, 2> SelectorRemap;
220 /// \brief A pointer to the character data that comprises the selector table
222 /// The SelectorOffsets table refers into this memory.
223 const unsigned char *SelectorLookupTableData;
225 /// \brief A pointer to an on-disk hash table of opaque type
226 /// ASTSelectorLookupTable.
228 /// This hash table provides the IDs of all selectors, and the associated
229 /// instance and factory methods.
230 void *SelectorLookupTable;
232 // === Declarations ===
234 /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
235 /// has read all the abbreviations at the start of the block and is ready to
236 /// jump around with these in context.
237 llvm::BitstreamCursor DeclsCursor;
239 /// \brief The number of declarations in this AST file.
240 unsigned LocalNumDecls;
242 /// \brief Offset of each declaration within the bitstream, indexed
243 /// by the declaration ID (-1).
244 const uint32_t *DeclOffsets;
246 /// \brief Base declaration ID for declarations local to this module.
247 serialization::DeclID BaseDeclID;
249 /// \brief Remapping table for declaration IDs in this module.
250 ContinuousRangeMap<uint32_t, int, 2> DeclRemap;
252 /// \brief The number of C++ base specifier sets in this AST file.
253 unsigned LocalNumCXXBaseSpecifiers;
255 /// \brief Offset of each C++ base specifier set within the bitstream,
256 /// indexed by the C++ base specifier set ID (-1).
257 const uint32_t *CXXBaseSpecifiersOffsets;
259 typedef llvm::DenseMap<const DeclContext *, DeclContextInfo>
262 /// \brief Information about the lexical and visible declarations
263 /// for each DeclContext.
264 DeclContextInfosMap DeclContextInfos;
266 typedef llvm::DenseMap<serialization::GlobalDeclID,
267 std::pair<serialization::LocalDeclID, serialization::LocalDeclID> >
268 ChainedObjCCategoriesMap;
269 /// \brief ObjC categories that got chained to an interface from another
271 /// Key is the ID of the interface.
272 /// Value is a pair of linked category DeclIDs (head category, tail category).
273 ChainedObjCCategoriesMap ChainedObjCCategories;
277 /// \brief The number of types in this AST file.
278 unsigned LocalNumTypes;
280 /// \brief Offset of each type within the bitstream, indexed by the
281 /// type ID, or the representation of a Type*.
282 const uint32_t *TypeOffsets;
284 /// \brief Base type ID for types local to this module as represented in
285 /// the global type ID space.
286 serialization::TypeID BaseTypeIndex;
288 /// \brief Remapping table for type IDs in this module.
289 ContinuousRangeMap<uint32_t, int, 2> TypeRemap;
291 // === Miscellaneous ===
293 /// \brief Diagnostic IDs and their mappings that the user changed.
294 SmallVector<uint64_t, 8> PragmaDiagMappings;
296 /// \brief The AST stat cache installed for this file, if any.
298 /// The dynamic type of this stat cache is always ASTStatCache
301 /// \brief List of modules which depend on this module
302 llvm::SetVector<Module *> ImportedBy;
304 /// \brief List of modules which this module depends on
305 llvm::SetVector<Module *> Imports;
307 /// \brief Determine whether this module was directly imported at
308 /// any point during translation.
309 bool isDirectlyImported() const { return DirectlyImported; }
311 /// \brief Dump debugging output for this module.
315 } // end namespace serialization
317 } // end namespace clang