blob: ca0cb3c8ea1794c3e30029cd3b1ec1c144fa1464 [file] [log] [blame]
Douglas Gregord44252e2011-08-25 20:47:51 +00001//===--- 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//===----------------------------------------------------------------------===//
14#include "clang/Serialization/Module.h"
Douglas Gregord44252e2011-08-25 20:47:51 +000015#include "ASTReaderInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000016#include "llvm/Support/MemoryBuffer.h"
17#include "llvm/Support/raw_ostream.h"
Douglas Gregord44252e2011-08-25 20:47:51 +000018
19using namespace clang;
20using namespace serialization;
21using namespace reader;
22
Douglas Gregor4fc9f3e2012-01-18 20:56:22 +000023ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation)
Ben Langmuir487ea142014-10-23 18:05:36 +000024 : Kind(Kind), File(nullptr), Signature(0), DirectlyImported(false),
Argyrios Kyrtzidisaedf7142012-10-03 01:58:42 +000025 Generation(Generation), SizeInBits(0),
Douglas Gregord44252e2011-08-25 20:47:51 +000026 LocalNumSLocEntries(0), SLocEntryBaseID(0),
Craig Toppera13603a2014-05-22 05:54:18 +000027 SLocEntryBaseOffset(0), SLocEntryOffsets(nullptr),
Douglas Gregor72be3902012-10-19 00:38:02 +000028 LocalNumIdentifiers(0),
Craig Toppera13603a2014-05-22 05:54:18 +000029 IdentifierOffsets(nullptr), BaseIdentifierID(0),
30 IdentifierTableData(nullptr), IdentifierLookupTable(nullptr),
31 LocalNumMacros(0), MacroOffsets(nullptr),
Douglas Gregorcb28f9d2012-10-09 23:05:51 +000032 BasePreprocessedEntityID(0),
Craig Toppera13603a2014-05-22 05:54:18 +000033 PreprocessedEntityOffsets(nullptr), NumPreprocessedEntities(0),
Argyrios Kyrtzidis03c40c52011-09-15 18:02:56 +000034 LocalNumHeaderFileInfos(0),
Craig Toppera13603a2014-05-22 05:54:18 +000035 HeaderFileInfoTableData(nullptr), HeaderFileInfoTable(nullptr),
Argyrios Kyrtzidis61a38962013-03-06 18:12:44 +000036 LocalNumSubmodules(0), BaseSubmoduleID(0),
Craig Toppera13603a2014-05-22 05:54:18 +000037 LocalNumSelectors(0), SelectorOffsets(nullptr), BaseSelectorID(0),
38 SelectorLookupTableData(nullptr), SelectorLookupTable(nullptr),
39 LocalNumDecls(0), DeclOffsets(nullptr), BaseDeclID(0),
Craig Toppera13603a2014-05-22 05:54:18 +000040 FileSortedDecls(nullptr), NumFileSortedDecls(0),
Craig Toppera13603a2014-05-22 05:54:18 +000041 ObjCCategoriesMap(nullptr), LocalNumObjCCategoriesInMap(0),
42 LocalNumTypes(0), TypeOffsets(nullptr), BaseTypeIndex(0)
Douglas Gregord44252e2011-08-25 20:47:51 +000043{}
44
Douglas Gregorde3ef502011-11-30 23:21:26 +000045ModuleFile::~ModuleFile() {
Douglas Gregord44252e2011-08-25 20:47:51 +000046 delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
47 delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
48 delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
49}
50
51template<typename Key, typename Offset, unsigned InitialCapacity>
52static void
53dumpLocalRemap(StringRef Name,
54 const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
55 if (Map.begin() == Map.end())
56 return;
57
58 typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType;
59 llvm::errs() << " " << Name << ":\n";
60 for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
61 I != IEnd; ++I) {
62 llvm::errs() << " " << I->first << " -> " << I->second << "\n";
63 }
64}
65
Yaron Kerencdae9412016-01-29 19:38:18 +000066LLVM_DUMP_METHOD void ModuleFile::dump() {
Douglas Gregord44252e2011-08-25 20:47:51 +000067 llvm::errs() << "\nModule: " << FileName << "\n";
68 if (!Imports.empty()) {
69 llvm::errs() << " Imports: ";
70 for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
71 if (I)
72 llvm::errs() << ", ";
73 llvm::errs() << Imports[I]->FileName;
74 }
75 llvm::errs() << "\n";
76 }
77
78 // Remapping tables.
79 llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
80 << '\n';
81 dumpLocalRemap("Source location offset local -> global map", SLocRemap);
82
83 llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
84 << " Number of identifiers: " << LocalNumIdentifiers << '\n';
85 dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
Douglas Gregor253eefe2011-12-01 00:59:36 +000086
Douglas Gregorcb28f9d2012-10-09 23:05:51 +000087 llvm::errs() << " Base macro ID: " << BaseMacroID << '\n'
88 << " Number of macros: " << LocalNumMacros << '\n';
89 dumpLocalRemap("Macro ID local -> global map", MacroRemap);
90
Douglas Gregor253eefe2011-12-01 00:59:36 +000091 llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
92 << " Number of submodules: " << LocalNumSubmodules << '\n';
93 dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
94
Douglas Gregord44252e2011-08-25 20:47:51 +000095 llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
96 << " Number of selectors: " << LocalNumSelectors << '\n';
97 dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
98
99 llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
100 << '\n'
101 << " Number of preprocessed entities: "
Argyrios Kyrtzidis03c40c52011-09-15 18:02:56 +0000102 << NumPreprocessedEntities << '\n';
Douglas Gregord44252e2011-08-25 20:47:51 +0000103 dumpLocalRemap("Preprocessed entity ID local -> global map",
104 PreprocessedEntityRemap);
105
Douglas Gregord44252e2011-08-25 20:47:51 +0000106 llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
107 << " Number of types: " << LocalNumTypes << '\n';
108 dumpLocalRemap("Type index local -> global map", TypeRemap);
109
110 llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
111 << " Number of decls: " << LocalNumDecls << '\n';
112 dumpLocalRemap("Decl ID local -> global map", DeclRemap);
113}