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