blob: 16b95e2a68345bf002b7c86d79b554f8c1609afb [file] [log] [blame]
Douglas Gregor98339b92011-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"
15#include "llvm/Support/raw_ostream.h"
16#include "llvm/Support/MemoryBuffer.h"
17#include "ASTReaderInternals.h"
18
19using namespace clang;
20using namespace serialization;
21using namespace reader;
22
Douglas Gregor057df202012-01-18 20:56:22 +000023ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation)
24 : Kind(Kind), DirectlyImported(false), Generation(Generation), SizeInBits(0),
Douglas Gregor98339b92011-08-25 20:47:51 +000025 LocalNumSLocEntries(0), SLocEntryBaseID(0),
26 SLocEntryBaseOffset(0), SLocEntryOffsets(0),
27 SLocFileOffsets(0), LocalNumIdentifiers(0),
28 IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0),
29 IdentifierLookupTable(0), BasePreprocessedEntityID(0),
Argyrios Kyrtzidise24692b2011-09-15 18:02:56 +000030 PreprocessedEntityOffsets(0), NumPreprocessedEntities(0),
31 LocalNumHeaderFileInfos(0),
Douglas Gregor98339b92011-08-25 20:47:51 +000032 HeaderFileInfoTableData(0), HeaderFileInfoTable(0),
Benjamin Kramer4a082682011-12-27 11:15:04 +000033 HeaderFileFrameworkStrings(0), LocalNumSubmodules(0), BaseSubmoduleID(0),
Douglas Gregor98339b92011-08-25 20:47:51 +000034 LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0),
35 SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0),
36 DeclOffsets(0), BaseDeclID(0),
37 LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0),
Douglas Gregor2171bf12012-01-15 16:58:34 +000038 FileSortedDecls(0), RedeclarationsMap(0), LocalNumRedeclarationsInMap(0),
Douglas Gregorcff9f262012-01-27 01:47:08 +000039 ObjCCategoriesMap(0), LocalNumObjCCategoriesInMap(0),
Argyrios Kyrtzidise24692b2011-09-15 18:02:56 +000040 LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0)
Douglas Gregor98339b92011-08-25 20:47:51 +000041{}
42
Douglas Gregor1a4761e2011-11-30 23:21:26 +000043ModuleFile::~ModuleFile() {
Douglas Gregor98339b92011-08-25 20:47:51 +000044 for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
45 E = DeclContextInfos.end();
46 I != E; ++I) {
47 if (I->second.NameLookupTableData)
48 delete static_cast<ASTDeclContextNameLookupTable*>(
49 I->second.NameLookupTableData);
50 }
51
52 delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
53 delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
54 delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
55}
56
57template<typename Key, typename Offset, unsigned InitialCapacity>
58static void
59dumpLocalRemap(StringRef Name,
60 const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
61 if (Map.begin() == Map.end())
62 return;
63
64 typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType;
65 llvm::errs() << " " << Name << ":\n";
66 for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
67 I != IEnd; ++I) {
68 llvm::errs() << " " << I->first << " -> " << I->second << "\n";
69 }
70}
71
Douglas Gregor1a4761e2011-11-30 23:21:26 +000072void ModuleFile::dump() {
Douglas Gregor98339b92011-08-25 20:47:51 +000073 llvm::errs() << "\nModule: " << FileName << "\n";
74 if (!Imports.empty()) {
75 llvm::errs() << " Imports: ";
76 for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
77 if (I)
78 llvm::errs() << ", ";
79 llvm::errs() << Imports[I]->FileName;
80 }
81 llvm::errs() << "\n";
82 }
83
84 // Remapping tables.
85 llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
86 << '\n';
87 dumpLocalRemap("Source location offset local -> global map", SLocRemap);
88
89 llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
90 << " Number of identifiers: " << LocalNumIdentifiers << '\n';
91 dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
Douglas Gregor26ced122011-12-01 00:59:36 +000092
93 llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
94 << " Number of submodules: " << LocalNumSubmodules << '\n';
95 dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
96
Douglas Gregor98339b92011-08-25 20:47:51 +000097 llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
98 << " Number of selectors: " << LocalNumSelectors << '\n';
99 dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
100
101 llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
102 << '\n'
103 << " Number of preprocessed entities: "
Argyrios Kyrtzidise24692b2011-09-15 18:02:56 +0000104 << NumPreprocessedEntities << '\n';
Douglas Gregor98339b92011-08-25 20:47:51 +0000105 dumpLocalRemap("Preprocessed entity ID local -> global map",
106 PreprocessedEntityRemap);
107
Douglas Gregor98339b92011-08-25 20:47:51 +0000108 llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
109 << " Number of types: " << LocalNumTypes << '\n';
110 dumpLocalRemap("Type index local -> global map", TypeRemap);
111
112 llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
113 << " Number of decls: " << LocalNumDecls << '\n';
114 dumpLocalRemap("Decl ID local -> global map", DeclRemap);
115}