xref: /aosp_15_r20/external/clang/lib/Serialization/Module.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //===--- Module.cpp - Module description ------------------------*- C++ -*-===//
2*67e74705SXin Li //
3*67e74705SXin Li //                     The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li //
10*67e74705SXin Li //  This file implements the Module class, which describes a module that has
11*67e74705SXin Li //  been loaded from an AST file.
12*67e74705SXin Li //
13*67e74705SXin Li //===----------------------------------------------------------------------===//
14*67e74705SXin Li #include "clang/Serialization/Module.h"
15*67e74705SXin Li #include "ASTReaderInternals.h"
16*67e74705SXin Li #include "llvm/Support/MemoryBuffer.h"
17*67e74705SXin Li #include "llvm/Support/raw_ostream.h"
18*67e74705SXin Li 
19*67e74705SXin Li using namespace clang;
20*67e74705SXin Li using namespace serialization;
21*67e74705SXin Li using namespace reader;
22*67e74705SXin Li 
ModuleFile(ModuleKind Kind,unsigned Generation)23*67e74705SXin Li ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation)
24*67e74705SXin Li   : Kind(Kind), File(nullptr), Signature(0), DirectlyImported(false),
25*67e74705SXin Li     Generation(Generation), SizeInBits(0),
26*67e74705SXin Li     LocalNumSLocEntries(0), SLocEntryBaseID(0),
27*67e74705SXin Li     SLocEntryBaseOffset(0), SLocEntryOffsets(nullptr),
28*67e74705SXin Li     LocalNumIdentifiers(0),
29*67e74705SXin Li     IdentifierOffsets(nullptr), BaseIdentifierID(0),
30*67e74705SXin Li     IdentifierTableData(nullptr), IdentifierLookupTable(nullptr),
31*67e74705SXin Li     LocalNumMacros(0), MacroOffsets(nullptr),
32*67e74705SXin Li     BasePreprocessedEntityID(0),
33*67e74705SXin Li     PreprocessedEntityOffsets(nullptr), NumPreprocessedEntities(0),
34*67e74705SXin Li     LocalNumHeaderFileInfos(0),
35*67e74705SXin Li     HeaderFileInfoTableData(nullptr), HeaderFileInfoTable(nullptr),
36*67e74705SXin Li     LocalNumSubmodules(0), BaseSubmoduleID(0),
37*67e74705SXin Li     LocalNumSelectors(0), SelectorOffsets(nullptr), BaseSelectorID(0),
38*67e74705SXin Li     SelectorLookupTableData(nullptr), SelectorLookupTable(nullptr),
39*67e74705SXin Li     LocalNumDecls(0), DeclOffsets(nullptr), BaseDeclID(0),
40*67e74705SXin Li     FileSortedDecls(nullptr), NumFileSortedDecls(0),
41*67e74705SXin Li     ObjCCategoriesMap(nullptr), LocalNumObjCCategoriesInMap(0),
42*67e74705SXin Li     LocalNumTypes(0), TypeOffsets(nullptr), BaseTypeIndex(0)
43*67e74705SXin Li {}
44*67e74705SXin Li 
~ModuleFile()45*67e74705SXin Li ModuleFile::~ModuleFile() {
46*67e74705SXin Li   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
47*67e74705SXin Li   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
48*67e74705SXin Li   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
49*67e74705SXin Li }
50*67e74705SXin Li 
51*67e74705SXin Li template<typename Key, typename Offset, unsigned InitialCapacity>
52*67e74705SXin Li static void
dumpLocalRemap(StringRef Name,const ContinuousRangeMap<Key,Offset,InitialCapacity> & Map)53*67e74705SXin Li dumpLocalRemap(StringRef Name,
54*67e74705SXin Li                const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
55*67e74705SXin Li   if (Map.begin() == Map.end())
56*67e74705SXin Li     return;
57*67e74705SXin Li 
58*67e74705SXin Li   typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType;
59*67e74705SXin Li   llvm::errs() << "  " << Name << ":\n";
60*67e74705SXin Li   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
61*67e74705SXin Li        I != IEnd; ++I) {
62*67e74705SXin Li     llvm::errs() << "    " << I->first << " -> " << I->second << "\n";
63*67e74705SXin Li   }
64*67e74705SXin Li }
65*67e74705SXin Li 
dump()66*67e74705SXin Li LLVM_DUMP_METHOD void ModuleFile::dump() {
67*67e74705SXin Li   llvm::errs() << "\nModule: " << FileName << "\n";
68*67e74705SXin Li   if (!Imports.empty()) {
69*67e74705SXin Li     llvm::errs() << "  Imports: ";
70*67e74705SXin Li     for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
71*67e74705SXin Li       if (I)
72*67e74705SXin Li         llvm::errs() << ", ";
73*67e74705SXin Li       llvm::errs() << Imports[I]->FileName;
74*67e74705SXin Li     }
75*67e74705SXin Li     llvm::errs() << "\n";
76*67e74705SXin Li   }
77*67e74705SXin Li 
78*67e74705SXin Li   // Remapping tables.
79*67e74705SXin Li   llvm::errs() << "  Base source location offset: " << SLocEntryBaseOffset
80*67e74705SXin Li                << '\n';
81*67e74705SXin Li   dumpLocalRemap("Source location offset local -> global map", SLocRemap);
82*67e74705SXin Li 
83*67e74705SXin Li   llvm::errs() << "  Base identifier ID: " << BaseIdentifierID << '\n'
84*67e74705SXin Li                << "  Number of identifiers: " << LocalNumIdentifiers << '\n';
85*67e74705SXin Li   dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
86*67e74705SXin Li 
87*67e74705SXin Li   llvm::errs() << "  Base macro ID: " << BaseMacroID << '\n'
88*67e74705SXin Li                << "  Number of macros: " << LocalNumMacros << '\n';
89*67e74705SXin Li   dumpLocalRemap("Macro ID local -> global map", MacroRemap);
90*67e74705SXin Li 
91*67e74705SXin Li   llvm::errs() << "  Base submodule ID: " << BaseSubmoduleID << '\n'
92*67e74705SXin Li                << "  Number of submodules: " << LocalNumSubmodules << '\n';
93*67e74705SXin Li   dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
94*67e74705SXin Li 
95*67e74705SXin Li   llvm::errs() << "  Base selector ID: " << BaseSelectorID << '\n'
96*67e74705SXin Li                << "  Number of selectors: " << LocalNumSelectors << '\n';
97*67e74705SXin Li   dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
98*67e74705SXin Li 
99*67e74705SXin Li   llvm::errs() << "  Base preprocessed entity ID: " << BasePreprocessedEntityID
100*67e74705SXin Li                << '\n'
101*67e74705SXin Li                << "  Number of preprocessed entities: "
102*67e74705SXin Li                << NumPreprocessedEntities << '\n';
103*67e74705SXin Li   dumpLocalRemap("Preprocessed entity ID local -> global map",
104*67e74705SXin Li                  PreprocessedEntityRemap);
105*67e74705SXin Li 
106*67e74705SXin Li   llvm::errs() << "  Base type index: " << BaseTypeIndex << '\n'
107*67e74705SXin Li                << "  Number of types: " << LocalNumTypes << '\n';
108*67e74705SXin Li   dumpLocalRemap("Type index local -> global map", TypeRemap);
109*67e74705SXin Li 
110*67e74705SXin Li   llvm::errs() << "  Base decl ID: " << BaseDeclID << '\n'
111*67e74705SXin Li                << "  Number of decls: " << LocalNumDecls << '\n';
112*67e74705SXin Li   dumpLocalRemap("Decl ID local -> global map", DeclRemap);
113*67e74705SXin Li }
114