blob: a5f709153c7e112e1aabd7fbbdc467777097286a [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)
Argyrios Kyrtzidisd64c26f2012-10-03 01:58:42 +000024 : Kind(Kind), File(0), DirectlyImported(false),
25 Generation(Generation), SizeInBits(0),
Douglas Gregor98339b92011-08-25 20:47:51 +000026 LocalNumSLocEntries(0), SLocEntryBaseID(0),
27 SLocEntryBaseOffset(0), SLocEntryOffsets(0),
28 SLocFileOffsets(0), LocalNumIdentifiers(0),
29 IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0),
30 IdentifierLookupTable(0), BasePreprocessedEntityID(0),
Argyrios Kyrtzidise24692b2011-09-15 18:02:56 +000031 PreprocessedEntityOffsets(0), NumPreprocessedEntities(0),
32 LocalNumHeaderFileInfos(0),
Douglas Gregor98339b92011-08-25 20:47:51 +000033 HeaderFileInfoTableData(0), HeaderFileInfoTable(0),
Benjamin Kramer4a082682011-12-27 11:15:04 +000034 HeaderFileFrameworkStrings(0), LocalNumSubmodules(0), BaseSubmoduleID(0),
Douglas Gregor98339b92011-08-25 20:47:51 +000035 LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0),
36 SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0),
37 DeclOffsets(0), BaseDeclID(0),
38 LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0),
Argyrios Kyrtzidis2093e0b2012-10-02 21:09:13 +000039 FileSortedDecls(0), NumFileSortedDecls(0),
40 RedeclarationsMap(0), LocalNumRedeclarationsInMap(0),
Douglas Gregorcff9f262012-01-27 01:47:08 +000041 ObjCCategoriesMap(0), LocalNumObjCCategoriesInMap(0),
Argyrios Kyrtzidise24692b2011-09-15 18:02:56 +000042 LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0)
Douglas Gregor98339b92011-08-25 20:47:51 +000043{}
44
Douglas Gregor1a4761e2011-11-30 23:21:26 +000045ModuleFile::~ModuleFile() {
Douglas Gregor98339b92011-08-25 20:47:51 +000046 for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
47 E = DeclContextInfos.end();
48 I != E; ++I) {
49 if (I->second.NameLookupTableData)
Benjamin Kramerb1758c62012-04-15 12:36:49 +000050 delete I->second.NameLookupTableData;
Douglas Gregor98339b92011-08-25 20:47:51 +000051 }
52
53 delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
54 delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
55 delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
56}
57
58template<typename Key, typename Offset, unsigned InitialCapacity>
59static void
60dumpLocalRemap(StringRef Name,
61 const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
62 if (Map.begin() == Map.end())
63 return;
64
65 typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType;
66 llvm::errs() << " " << Name << ":\n";
67 for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
68 I != IEnd; ++I) {
69 llvm::errs() << " " << I->first << " -> " << I->second << "\n";
70 }
71}
72
Douglas Gregor1a4761e2011-11-30 23:21:26 +000073void ModuleFile::dump() {
Douglas Gregor98339b92011-08-25 20:47:51 +000074 llvm::errs() << "\nModule: " << FileName << "\n";
75 if (!Imports.empty()) {
76 llvm::errs() << " Imports: ";
77 for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
78 if (I)
79 llvm::errs() << ", ";
80 llvm::errs() << Imports[I]->FileName;
81 }
82 llvm::errs() << "\n";
83 }
84
85 // Remapping tables.
86 llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
87 << '\n';
88 dumpLocalRemap("Source location offset local -> global map", SLocRemap);
89
90 llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
91 << " Number of identifiers: " << LocalNumIdentifiers << '\n';
92 dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
Douglas Gregor26ced122011-12-01 00:59:36 +000093
94 llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
95 << " Number of submodules: " << LocalNumSubmodules << '\n';
96 dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
97
Douglas Gregor98339b92011-08-25 20:47:51 +000098 llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
99 << " Number of selectors: " << LocalNumSelectors << '\n';
100 dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
101
102 llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
103 << '\n'
104 << " Number of preprocessed entities: "
Argyrios Kyrtzidise24692b2011-09-15 18:02:56 +0000105 << NumPreprocessedEntities << '\n';
Douglas Gregor98339b92011-08-25 20:47:51 +0000106 dumpLocalRemap("Preprocessed entity ID local -> global map",
107 PreprocessedEntityRemap);
108
Douglas Gregor98339b92011-08-25 20:47:51 +0000109 llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
110 << " Number of types: " << LocalNumTypes << '\n';
111 dumpLocalRemap("Type index local -> global map", TypeRemap);
112
113 llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
114 << " Number of decls: " << LocalNumDecls << '\n';
115 dumpLocalRemap("Decl ID local -> global map", DeclRemap);
116}