clang  3.7.0
Serialization/Module.h
Go to the documentation of this file.
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 
21 #include "llvm/ADT/SetVector.h"
22 #include "llvm/Bitcode/BitstreamReader.h"
23 #include "llvm/Support/Endian.h"
24 #include <memory>
25 #include <string>
26 
27 namespace llvm {
28 template <typename Info> class OnDiskChainedHashTable;
29 template <typename Info> class OnDiskIterableChainedHashTable;
30 }
31 
32 namespace clang {
33 
34 class FileEntry;
35 class DeclContext;
36 class Module;
37 
38 namespace serialization {
39 
40 namespace reader {
41  class ASTDeclContextNameLookupTrait;
42 }
43 
44 /// \brief Specifies the kind of module that has been loaded.
45 enum ModuleKind {
46  MK_ImplicitModule, ///< File is an implicitly-loaded module.
47  MK_ExplicitModule, ///< File is an explicitly-loaded module.
48  MK_PCH, ///< File is a PCH file treated as such.
49  MK_Preamble, ///< File is a PCH file treated as the preamble.
50  MK_MainFile ///< File is a PCH file treated as the actual main file.
51 };
52 
53 /// \brief Information about the contents of a DeclContext.
57 
59  *NameLookupTableData; // an ASTDeclContextNameLookupTable.
61  unsigned NumLexicalDecls;
62 };
63 
64 /// \brief The input file that has been loaded from this AST file, along with
65 /// bools indicating whether this was an overridden buffer or if it was
66 /// out-of-date or not-found.
67 class InputFile {
68  enum {
69  Overridden = 1,
70  OutOfDate = 2,
71  NotFound = 3
72  };
73  llvm::PointerIntPair<const FileEntry *, 2, unsigned> Val;
74 
75 public:
76  InputFile() {}
77  InputFile(const FileEntry *File,
78  bool isOverridden = false, bool isOutOfDate = false) {
79  assert(!(isOverridden && isOutOfDate) &&
80  "an overridden cannot be out-of-date");
81  unsigned intVal = 0;
82  if (isOverridden)
83  intVal = Overridden;
84  else if (isOutOfDate)
85  intVal = OutOfDate;
86  Val.setPointerAndInt(File, intVal);
87  }
88 
90  InputFile File;
91  File.Val.setInt(NotFound);
92  return File;
93  }
94 
95  const FileEntry *getFile() const { return Val.getPointer(); }
96  bool isOverridden() const { return Val.getInt() == Overridden; }
97  bool isOutOfDate() const { return Val.getInt() == OutOfDate; }
98  bool isNotFound() const { return Val.getInt() == NotFound; }
99 };
100 
101 typedef unsigned ASTFileSignature;
102 
103 /// \brief Information about a module that has been loaded by the ASTReader.
104 ///
105 /// Each instance of the Module class corresponds to a single AST file, which
106 /// may be a precompiled header, precompiled preamble, a module, or an AST file
107 /// of some sort loaded as the main file, all of which are specific formulations
108 /// of the general notion of a "module". A module may depend on any number of
109 /// other modules.
110 class ModuleFile {
111 public:
113  ~ModuleFile();
114 
115  // === General information ===
116 
117  /// \brief The index of this module in the list of modules.
118  unsigned Index;
119 
120  /// \brief The type of this module.
122 
123  /// \brief The file name of the module file.
124  std::string FileName;
125 
126  /// \brief The name of the module.
127  std::string ModuleName;
128 
129  /// \brief The base directory of the module.
130  std::string BaseDirectory;
131 
132  std::string getTimestampFilename() const {
133  return FileName + ".timestamp";
134  }
135 
136  /// \brief The original source file name that was used to build the
137  /// primary AST file, which may have been modified for
138  /// relocatable-pch support.
140 
141  /// \brief The actual original source file name that was used to
142  /// build this AST file.
144 
145  /// \brief The file ID for the original source file that was used to
146  /// build this AST file.
148 
149  /// \brief The directory that the PCH was originally created in. Used to
150  /// allow resolving headers even after headers+PCH was moved to a new path.
151  std::string OriginalDir;
152 
153  std::string ModuleMapPath;
154 
155  /// \brief Whether this precompiled header is a relocatable PCH file.
157 
158  /// \brief The file entry for the module file.
159  const FileEntry *File;
160 
161  /// \brief The signature of the module file, which may be used along with size
162  /// and modification time to identify this particular file.
164 
165  /// \brief Whether this module has been directly imported by the
166  /// user.
168 
169  /// \brief The generation of which this module file is a part.
170  unsigned Generation;
171 
172  /// \brief The memory buffer that stores the data associated with
173  /// this AST file.
174  std::unique_ptr<llvm::MemoryBuffer> Buffer;
175 
176  /// \brief The size of this file, in bits.
177  uint64_t SizeInBits;
178 
179  /// \brief The global bit offset (or base) of this module
180  uint64_t GlobalBitOffset;
181 
182  /// \brief The bitstream reader from which we'll read the AST file.
183  llvm::BitstreamReader StreamFile;
184 
185  /// \brief The main bitstream cursor for the main block.
186  llvm::BitstreamCursor Stream;
187 
188  /// \brief The source location where the module was explicitly or implicitly
189  /// imported in the local translation unit.
190  ///
191  /// If module A depends on and imports module B, both modules will have the
192  /// same DirectImportLoc, but different ImportLoc (B's ImportLoc will be a
193  /// source location inside module A).
194  ///
195  /// WARNING: This is largely useless. It doesn't tell you when a module was
196  /// made visible, just when the first submodule of that module was imported.
198 
199  /// \brief The source location where this module was first imported.
201 
202  /// \brief The first source location in this module.
204 
205  // === Input Files ===
206  /// \brief The cursor to the start of the input-files block.
207  llvm::BitstreamCursor InputFilesCursor;
208 
209  /// \brief Offsets for all of the input file entries in the AST file.
210  const llvm::support::unaligned_uint64_t *InputFileOffsets;
211 
212  /// \brief The input files that have been loaded from this AST file.
213  std::vector<InputFile> InputFilesLoaded;
214 
215  /// \brief If non-zero, specifies the time when we last validated input
216  /// files. Zero means we never validated them.
217  ///
218  /// The time is specified in seconds since the start of the Epoch.
220 
221  // === Source Locations ===
222 
223  /// \brief Cursor used to read source location entries.
224  llvm::BitstreamCursor SLocEntryCursor;
225 
226  /// \brief The number of source location entries in this AST file.
228 
229  /// \brief The base ID in the source manager's view of this module.
231 
232  /// \brief The base offset in the source manager's view of this module.
234 
235  /// \brief Offsets for all of the source location entries in the
236  /// AST file.
237  const uint32_t *SLocEntryOffsets;
238 
239  /// \brief SLocEntries that we're going to preload.
241 
242  /// \brief Remapping table for source locations in this module.
244 
245  // === Identifiers ===
246 
247  /// \brief The number of identifiers in this AST file.
249 
250  /// \brief Offsets into the identifier table data.
251  ///
252  /// This array is indexed by the identifier ID (-1), and provides
253  /// the offset into IdentifierTableData where the string data is
254  /// stored.
255  const uint32_t *IdentifierOffsets;
256 
257  /// \brief Base identifier ID for identifiers local to this module.
259 
260  /// \brief Remapping table for identifier IDs in this module.
262 
263  /// \brief Actual data for the on-disk hash table of identifiers.
264  ///
265  /// This pointer points into a memory buffer, where the on-disk hash
266  /// table for identifiers actually lives.
267  const char *IdentifierTableData;
268 
269  /// \brief A pointer to an on-disk hash table of opaque type
270  /// IdentifierHashTable.
272 
273  // === Macros ===
274 
275  /// \brief The cursor to the start of the preprocessor block, which stores
276  /// all of the macro definitions.
277  llvm::BitstreamCursor MacroCursor;
278 
279  /// \brief The number of macros in this AST file.
280  unsigned LocalNumMacros;
281 
282  /// \brief Offsets of macros in the preprocessor block.
283  ///
284  /// This array is indexed by the macro ID (-1), and provides
285  /// the offset into the preprocessor block where macro definitions are
286  /// stored.
287  const uint32_t *MacroOffsets;
288 
289  /// \brief Base macro ID for macros local to this module.
291 
292  /// \brief Remapping table for macro IDs in this module.
294 
295  /// \brief The offset of the start of the set of defined macros.
297 
298  // === Detailed PreprocessingRecord ===
299 
300  /// \brief The cursor to the start of the (optional) detailed preprocessing
301  /// record block.
302  llvm::BitstreamCursor PreprocessorDetailCursor;
303 
304  /// \brief The offset of the start of the preprocessor detail cursor.
306 
307  /// \brief Base preprocessed entity ID for preprocessed entities local to
308  /// this module.
310 
311  /// \brief Remapping table for preprocessed entity IDs in this module.
313 
316 
317  // === Header search information ===
318 
319  /// \brief The number of local HeaderFileInfo structures.
321 
322  /// \brief Actual data for the on-disk hash table of header file
323  /// information.
324  ///
325  /// This pointer points into a memory buffer, where the on-disk hash
326  /// table for header file information actually lives.
328 
329  /// \brief The on-disk hash table that contains information about each of
330  /// the header files.
332 
333  // === Submodule information ===
334  /// \brief The number of submodules in this module.
336 
337  /// \brief Base submodule ID for submodules local to this module.
339 
340  /// \brief Remapping table for submodule IDs in this module.
342 
343  // === Selectors ===
344 
345  /// \brief The number of selectors new to this file.
346  ///
347  /// This is the number of entries in SelectorOffsets.
349 
350  /// \brief Offsets into the selector lookup table's data array
351  /// where each selector resides.
352  const uint32_t *SelectorOffsets;
353 
354  /// \brief Base selector ID for selectors local to this module.
356 
357  /// \brief Remapping table for selector IDs in this module.
359 
360  /// \brief A pointer to the character data that comprises the selector table
361  ///
362  /// The SelectorOffsets table refers into this memory.
363  const unsigned char *SelectorLookupTableData;
364 
365  /// \brief A pointer to an on-disk hash table of opaque type
366  /// ASTSelectorLookupTable.
367  ///
368  /// This hash table provides the IDs of all selectors, and the associated
369  /// instance and factory methods.
371 
372  // === Declarations ===
373 
374  /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
375  /// has read all the abbreviations at the start of the block and is ready to
376  /// jump around with these in context.
377  llvm::BitstreamCursor DeclsCursor;
378 
379  /// \brief The number of declarations in this AST file.
380  unsigned LocalNumDecls;
381 
382  /// \brief Offset of each declaration within the bitstream, indexed
383  /// by the declaration ID (-1).
385 
386  /// \brief Base declaration ID for declarations local to this module.
388 
389  /// \brief Remapping table for declaration IDs in this module.
391 
392  /// \brief Mapping from the module files that this module file depends on
393  /// to the base declaration ID for that module as it is understood within this
394  /// module.
395  ///
396  /// This is effectively a reverse global-to-local mapping for declaration
397  /// IDs, so that we can interpret a true global ID (for this translation unit)
398  /// as a local ID (for this module file).
399  llvm::DenseMap<ModuleFile *, serialization::DeclID> GlobalToLocalDeclIDs;
400 
401  /// \brief The number of C++ base specifier sets in this AST file.
403 
404  /// \brief Offset of each C++ base specifier set within the bitstream,
405  /// indexed by the C++ base specifier set ID (-1).
406  const uint32_t *CXXBaseSpecifiersOffsets;
407 
408  /// \brief The number of C++ ctor initializer lists in this AST file.
410 
411  /// \brief Offset of each C++ ctor initializer list within the bitstream,
412  /// indexed by the C++ ctor initializer list ID minus 1.
413  const uint32_t *CXXCtorInitializersOffsets;
414 
415  typedef llvm::DenseMap<const DeclContext *, DeclContextInfo>
417 
418  /// \brief Information about the lexical and visible declarations
419  /// for each DeclContext.
421 
422  /// \brief Array of file-level DeclIDs sorted by file.
425 
426  /// \brief Array of redeclaration chain location information within this
427  /// module file, sorted by the first declaration ID.
429 
430  /// \brief The number of redeclaration info entries in RedeclarationsMap.
432 
433  /// \brief The redeclaration chains for declarations local to this
434  /// module file.
436 
437  /// \brief Array of category list location information within this
438  /// module file, sorted by the definition ID.
440 
441  /// \brief The number of redeclaration info entries in ObjCCategoriesMap.
443 
444  /// \brief The Objective-C category lists for categories known to this
445  /// module.
447 
448  // === Types ===
449 
450  /// \brief The number of types in this AST file.
451  unsigned LocalNumTypes;
452 
453  /// \brief Offset of each type within the bitstream, indexed by the
454  /// type ID, or the representation of a Type*.
455  const uint32_t *TypeOffsets;
456 
457  /// \brief Base type ID for types local to this module as represented in
458  /// the global type ID space.
460 
461  /// \brief Remapping table for type IDs in this module.
463 
464  // === Miscellaneous ===
465 
466  /// \brief Diagnostic IDs and their mappings that the user changed.
468 
469  /// \brief List of modules which depend on this module
470  llvm::SetVector<ModuleFile *> ImportedBy;
471 
472  /// \brief List of modules which this module depends on
473  llvm::SetVector<ModuleFile *> Imports;
474 
475  /// \brief Determine whether this module was directly imported at
476  /// any point during translation.
477  bool isDirectlyImported() const { return DirectlyImported; }
478 
479  /// \brief Dump debugging output for this module.
480  void dump();
481 };
482 
483 } // end namespace serialization
484 
485 } // end namespace clang
486 
487 #endif
bool isDirectlyImported() const
Determine whether this module was directly imported at any point during translation.
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:168
void * IdentifierLookupTable
A pointer to an on-disk hash table of opaque type IdentifierHashTable.
SourceLocation DirectImportLoc
The source location where the module was explicitly or implicitly imported in the local translation u...
const serialization::LocalRedeclarationsInfo * RedeclarationsMap
Array of redeclaration chain location information within this module file, sorted by the first declar...
unsigned Generation
The generation of which this module file is a part.
uint32_t IdentID
An ID number that refers to an identifier in an AST file.
Definition: ASTBitCodes.h:125
SmallVector< uint64_t, 4 > PreloadSLocEntries
SLocEntries that we're going to preload.
ModuleKind Kind
The type of this module.
std::string ModuleName
The name of the module.
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:62
unsigned Index
The index of this module in the list of modules.
unsigned LocalNumObjCCategoriesInMap
The number of redeclaration info entries in ObjCCategoriesMap.
uint64_t GlobalBitOffset
The global bit offset (or base) of this module.
ModuleFile(ModuleKind Kind, unsigned Generation)
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
ASTFileSignature Signature
The signature of the module file, which may be used along with size and modification time to identify...
llvm::OnDiskIterableChainedHashTable< reader::ASTDeclContextNameLookupTrait > * NameLookupTableData
InputFile(const FileEntry *File, bool isOverridden=false, bool isOutOfDate=false)
const uint32_t * SLocEntryOffsets
Offsets for all of the source location entries in the AST file.
bool RelocatablePCH
Whether this precompiled header is a relocatable PCH file.
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
int SLocEntryBaseID
The base ID in the source manager's view of this module.
ContinuousRangeMap< uint32_t, int, 2 > DeclRemap
Remapping table for declaration IDs in this module.
SourceLocation ImportLoc
The source location where this module was first imported.
std::string ActualOriginalSourceFileName
The actual original source file name that was used to build this AST file.
ContinuousRangeMap< uint32_t, int, 2 > PreprocessedEntityRemap
Remapping table for preprocessed entity IDs in this module.
std::string OriginalDir
The directory that the PCH was originally created in. Used to allow resolving headers even after head...
llvm::DenseMap< const DeclContext *, DeclContextInfo > DeclContextInfosMap
unsigned LocalNumHeaderFileInfos
The number of local HeaderFileInfo structures.
const PPEntityOffset * PreprocessedEntityOffsets
serialization::MacroID BaseMacroID
Base macro ID for macros local to this module.
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:162
unsigned LocalNumRedeclarationsInMap
The number of redeclaration info entries in RedeclarationsMap.
std::string OriginalSourceFileName
The original source file name that was used to build the primary AST file, which may have been modifi...
serialization::DeclID BaseDeclID
Base declaration ID for declarations local to this module.
SourceLocation FirstLoc
The first source location in this module.
ContinuousRangeMap< uint32_t, int, 2 > SLocRemap
Remapping table for source locations in this module.
uint64_t PreprocessorDetailStartOffset
The offset of the start of the preprocessor detail cursor.
std::pair< uint32_t, DeclID > KindDeclIDPair
a Decl::Kind/DeclID pair.
Definition: ASTBitCodes.h:65
llvm::BitstreamCursor Stream
The main bitstream cursor for the main block.
llvm::DenseMap< ModuleFile *, serialization::DeclID > GlobalToLocalDeclIDs
Mapping from the module files that this module file depends on to the base declaration ID for that mo...
ModuleKind
Specifies the kind of module that has been loaded.
unsigned LocalNumSLocEntries
The number of source location entries in this AST file.
const uint32_t * TypeOffsets
Offset of each type within the bitstream, indexed by the type ID, or the representation of a Type*...
unsigned LocalNumIdentifiers
The number of identifiers in this AST file.
unsigned LocalNumCXXBaseSpecifiers
The number of C++ base specifier sets in this AST file.
std::unique_ptr< llvm::MemoryBuffer > Buffer
The memory buffer that stores the data associated with this AST file.
ContinuousRangeMap< uint32_t, int, 2 > IdentifierRemap
Remapping table for identifier IDs in this module.
llvm::BitstreamCursor SLocEntryCursor
Cursor used to read source location entries.
llvm::BitstreamCursor InputFilesCursor
The cursor to the start of the input-files block.
unsigned LocalNumMacros
The number of macros in this AST file.
Information about a module that has been loaded by the ASTReader.
SmallVector< uint64_t, 1 > ObjCCategories
The Objective-C category lists for categories known to this module.
FileID OriginalSourceFileID
The file ID for the original source file that was used to build this AST file.
void dump()
Dump debugging output for this module.
std::string FileName
The file name of the module file.
unsigned SLocEntryBaseOffset
The base offset in the source manager's view of this module.
const unsigned char * SelectorLookupTableData
A pointer to the character data that comprises the selector table.
serialization::TypeID BaseTypeIndex
Base type ID for types local to this module as represented in the global type ID space.
ContinuousRangeMap< uint32_t, int, 2 > SelectorRemap
Remapping table for selector IDs in this module.
Kind
serialization::IdentID BaseIdentifierID
Base identifier ID for identifiers local to this module.
const uint32_t * CXXCtorInitializersOffsets
Offset of each C++ ctor initializer list within the bitstream, indexed by the C++ ctor initializer li...
File is a PCH file treated as the preamble.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
File is a PCH file treated as such.
ContinuousRangeMap< uint32_t, int, 2 > SubmoduleRemap
Remapping table for submodule IDs in this module.
llvm::BitstreamReader StreamFile
The bitstream reader from which we'll read the AST file.
File is an implicitly-loaded module.
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
uint64_t SizeInBits
The size of this file, in bits.
void * SelectorLookupTable
A pointer to an on-disk hash table of opaque type ASTSelectorLookupTable.
const uint32_t * IdentifierOffsets
Offsets into the identifier table data.
unsigned LocalNumDecls
The number of declarations in this AST file.
Information about the contents of a DeclContext.
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:1462
uint32_t MacroID
An ID number that refers to a macro in an AST file.
Definition: ASTBitCodes.h:131
llvm::SetVector< ModuleFile * > ImportedBy
List of modules which depend on this module.
const serialization::DeclID * FileSortedDecls
Array of file-level DeclIDs sorted by file.
std::vector< InputFile > InputFilesLoaded
The input files that have been loaded from this AST file.
unsigned LocalNumSubmodules
The number of submodules in this module.
const char * HeaderFileInfoTableData
Actual data for the on-disk hash table of header file information.
const llvm::support::unaligned_uint64_t * InputFileOffsets
Offsets for all of the input file entries in the AST file.
File is a PCH file treated as the actual main file.
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
uint64_t InputFilesValidationTimestamp
If non-zero, specifies the time when we last validated input files. Zero means we never validated the...
const uint32_t * MacroOffsets
Offsets of macros in the preprocessor block.
unsigned LocalNumSelectors
The number of selectors new to this file.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
DeclContextInfosMap DeclContextInfos
Information about the lexical and visible declarations for each DeclContext.
SmallVector< uint64_t, 1 > RedeclarationChains
The redeclaration chains for declarations local to this module file.
uint64_t MacroStartOffset
The offset of the start of the set of defined macros.
File is an explicitly-loaded module.
ContinuousRangeMap< uint32_t, int, 2 > MacroRemap
Remapping table for macro IDs in this module.
void * HeaderFileInfoTable
The on-disk hash table that contains information about each of the header files.
std::string BaseDirectory
The base directory of the module.
const uint32_t * CXXBaseSpecifiersOffsets
Offset of each C++ base specifier set within the bitstream, indexed by the C++ base specifier set ID ...
ContinuousRangeMap< uint32_t, int, 2 > TypeRemap
Remapping table for type IDs in this module.
serialization::PreprocessedEntityID BasePreprocessedEntityID
Base preprocessed entity ID for preprocessed entities local to this module.
uint32_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
Definition: ASTBitCodes.h:159
Defines the clang::SourceLocation class and associated facilities.
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
Definition: ASTBitCodes.h:144
SmallVector< uint64_t, 8 > PragmaDiagMappings
Diagnostic IDs and their mappings that the user changed.
const char * IdentifierTableData
Actual data for the on-disk hash table of identifiers.
const FileEntry * getFile() const
const DeclOffset * DeclOffsets
Offset of each declaration within the bitstream, indexed by the declaration ID (-1).
Describes the redeclarations of a declaration.
Definition: ASTBitCodes.h:1436
llvm::BitstreamCursor PreprocessorDetailCursor
The cursor to the start of the (optional) detailed preprocessing record block.
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:82
llvm::BitstreamCursor MacroCursor
The cursor to the start of the preprocessor block, which stores all of the macro definitions.
const uint32_t * SelectorOffsets
Offsets into the selector lookup table's data array where each selector resides.
unsigned LocalNumTypes
The number of types in this AST file.
bool DirectlyImported
Whether this module has been directly imported by the user.
const FileEntry * File
The file entry for the module file.
llvm::SetVector< ModuleFile * > Imports
List of modules which this module depends on.
Source range/offset of a preprocessed entity.
Definition: ASTBitCodes.h:183
const serialization::ObjCCategoriesInfo * ObjCCategoriesMap
Array of category list location information within this module file, sorted by the definition ID...
unsigned LocalNumCXXCtorInitializers
The number of C++ ctor initializer lists in this AST file.