clang  3.7.0
Serialization/Module.cpp
Go to the documentation of this file.
1 //===--- Module.cpp - 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 implements the Module class, which describes a module that has
11 // been loaded from an AST file.
12 //
13 //===----------------------------------------------------------------------===//
15 #include "ASTReaderInternals.h"
16 #include "llvm/Support/MemoryBuffer.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 using namespace clang;
20 using namespace serialization;
21 using namespace reader;
22 
23 ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation)
24  : Kind(Kind), File(nullptr), Signature(0), DirectlyImported(false),
25  Generation(Generation), SizeInBits(0),
26  LocalNumSLocEntries(0), SLocEntryBaseID(0),
27  SLocEntryBaseOffset(0), SLocEntryOffsets(nullptr),
28  LocalNumIdentifiers(0),
29  IdentifierOffsets(nullptr), BaseIdentifierID(0),
30  IdentifierTableData(nullptr), IdentifierLookupTable(nullptr),
31  LocalNumMacros(0), MacroOffsets(nullptr),
32  BasePreprocessedEntityID(0),
33  PreprocessedEntityOffsets(nullptr), NumPreprocessedEntities(0),
34  LocalNumHeaderFileInfos(0),
35  HeaderFileInfoTableData(nullptr), HeaderFileInfoTable(nullptr),
36  LocalNumSubmodules(0), BaseSubmoduleID(0),
37  LocalNumSelectors(0), SelectorOffsets(nullptr), BaseSelectorID(0),
38  SelectorLookupTableData(nullptr), SelectorLookupTable(nullptr),
39  LocalNumDecls(0), DeclOffsets(nullptr), BaseDeclID(0),
40  LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(nullptr),
41  LocalNumCXXCtorInitializers(0), CXXCtorInitializersOffsets(nullptr),
42  FileSortedDecls(nullptr), NumFileSortedDecls(0),
43  RedeclarationsMap(nullptr), LocalNumRedeclarationsInMap(0),
44  ObjCCategoriesMap(nullptr), LocalNumObjCCategoriesInMap(0),
45  LocalNumTypes(0), TypeOffsets(nullptr), BaseTypeIndex(0)
46 {}
47 
49  for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
50  E = DeclContextInfos.end();
51  I != E; ++I) {
52  if (I->second.NameLookupTableData)
53  delete I->second.NameLookupTableData;
54  }
55 
56  delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
57  delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
58  delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
59 }
60 
61 template<typename Key, typename Offset, unsigned InitialCapacity>
62 static void
63 dumpLocalRemap(StringRef Name,
65  if (Map.begin() == Map.end())
66  return;
67 
69  llvm::errs() << " " << Name << ":\n";
70  for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
71  I != IEnd; ++I) {
72  llvm::errs() << " " << I->first << " -> " << I->second << "\n";
73  }
74 }
75 
77  llvm::errs() << "\nModule: " << FileName << "\n";
78  if (!Imports.empty()) {
79  llvm::errs() << " Imports: ";
80  for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
81  if (I)
82  llvm::errs() << ", ";
83  llvm::errs() << Imports[I]->FileName;
84  }
85  llvm::errs() << "\n";
86  }
87 
88  // Remapping tables.
89  llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
90  << '\n';
91  dumpLocalRemap("Source location offset local -> global map", SLocRemap);
92 
93  llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
94  << " Number of identifiers: " << LocalNumIdentifiers << '\n';
95  dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
96 
97  llvm::errs() << " Base macro ID: " << BaseMacroID << '\n'
98  << " Number of macros: " << LocalNumMacros << '\n';
99  dumpLocalRemap("Macro ID local -> global map", MacroRemap);
100 
101  llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
102  << " Number of submodules: " << LocalNumSubmodules << '\n';
103  dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
104 
105  llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
106  << " Number of selectors: " << LocalNumSelectors << '\n';
107  dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
108 
109  llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
110  << '\n'
111  << " Number of preprocessed entities: "
112  << NumPreprocessedEntities << '\n';
113  dumpLocalRemap("Preprocessed entity ID local -> global map",
115 
116  llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
117  << " Number of types: " << LocalNumTypes << '\n';
118  dumpLocalRemap("Type index local -> global map", TypeRemap);
119 
120  llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
121  << " Number of decls: " << LocalNumDecls << '\n';
122  dumpLocalRemap("Decl ID local -> global map", DeclRemap);
123 }
void * IdentifierLookupTable
A pointer to an on-disk hash table of opaque type IdentifierHashTable.
ModuleFile(ModuleKind Kind, unsigned Generation)
serialization::SelectorID BaseSelectorID
Base selector ID for selectors local to this module.
serialization::SubmoduleID BaseSubmoduleID
Base submodule ID for submodules local to this module.
ContinuousRangeMap< uint32_t, int, 2 > DeclRemap
Remapping table for declaration IDs in this module.
ContinuousRangeMap< uint32_t, int, 2 > PreprocessedEntityRemap
Remapping table for preprocessed entity IDs in this module.
serialization::MacroID BaseMacroID
Base macro ID for macros local to this module.
serialization::DeclID BaseDeclID
Base declaration ID for declarations local to this module.
ModuleKind
Specifies the kind of module that has been loaded.
unsigned LocalNumIdentifiers
The number of identifiers in this AST file.
ContinuousRangeMap< uint32_t, int, 2 > IdentifierRemap
Remapping table for identifier IDs in this module.
unsigned LocalNumMacros
The number of macros in 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.
#define false
Definition: stdbool.h:33
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.
ContinuousRangeMap< uint32_t, int, 2 > SubmoduleRemap
Remapping table for submodule IDs in this module.
void * SelectorLookupTable
A pointer to an on-disk hash table of opaque type ASTSelectorLookupTable.
unsigned LocalNumDecls
The number of declarations in this AST file.
unsigned LocalNumSubmodules
The number of submodules in this module.
unsigned LocalNumSelectors
The number of selectors new to this file.
DeclContextInfosMap DeclContextInfos
Information about the lexical and visible declarations for each DeclContext.
static void dumpLocalRemap(StringRef Name, const ContinuousRangeMap< Key, Offset, InitialCapacity > &Map)
A map from continuous integer ranges to some value, with a very specialized interface.
ContinuousRangeMap< uint32_t, int, 2 > MacroRemap
Remapping table for macro IDs in this module.
unsigned Map[Count]
Definition: AddressSpaces.h:45
void * HeaderFileInfoTable
The on-disk hash table that contains information about each of the header files.
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.
unsigned LocalNumTypes
The number of types in this AST file.
llvm::SetVector< ModuleFile * > Imports
List of modules which this module depends on.