1 //===- ModuleFile.cpp - Module description --------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the ModuleFile class, which describes a module that
10 // has been loaded from an AST file.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Serialization/ModuleFile.h"
15 #include "ASTReaderInternals.h"
16 #include "clang/Serialization/ContinuousRangeMap.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/raw_ostream.h"
21 using namespace clang
;
22 using namespace serialization
;
23 using namespace reader
;
25 ModuleFile::~ModuleFile() {
26 delete static_cast<ASTIdentifierLookupTable
*>(IdentifierLookupTable
);
27 delete static_cast<HeaderFileInfoLookupTable
*>(HeaderFileInfoTable
);
28 delete static_cast<ASTSelectorLookupTable
*>(SelectorLookupTable
);
31 template<typename Key
, typename Offset
, unsigned InitialCapacity
>
33 dumpLocalRemap(StringRef Name
,
34 const ContinuousRangeMap
<Key
, Offset
, InitialCapacity
> &Map
) {
35 if (Map
.begin() == Map
.end())
38 using MapType
= ContinuousRangeMap
<Key
, Offset
, InitialCapacity
>;
40 llvm::errs() << " " << Name
<< ":\n";
41 for (typename
MapType::const_iterator I
= Map
.begin(), IEnd
= Map
.end();
43 llvm::errs() << " " << I
->first
<< " -> " << I
->second
<< "\n";
47 LLVM_DUMP_METHOD
void ModuleFile::dump() {
48 llvm::errs() << "\nModule: " << FileName
<< "\n";
49 if (!Imports
.empty()) {
50 llvm::errs() << " Imports: ";
51 for (unsigned I
= 0, N
= Imports
.size(); I
!= N
; ++I
) {
54 llvm::errs() << Imports
[I
]->FileName
;
60 llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
63 llvm::errs() << " Base identifier ID: " << BaseIdentifierID
<< '\n'
64 << " Number of identifiers: " << LocalNumIdentifiers
<< '\n';
66 llvm::errs() << " Base macro ID: " << BaseMacroID
<< '\n'
67 << " Number of macros: " << LocalNumMacros
<< '\n';
68 dumpLocalRemap("Macro ID local -> global map", MacroRemap
);
70 llvm::errs() << " Base submodule ID: " << BaseSubmoduleID
<< '\n'
71 << " Number of submodules: " << LocalNumSubmodules
<< '\n';
72 dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap
);
74 llvm::errs() << " Base selector ID: " << BaseSelectorID
<< '\n'
75 << " Number of selectors: " << LocalNumSelectors
<< '\n';
76 dumpLocalRemap("Selector ID local -> global map", SelectorRemap
);
78 llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
80 << " Number of preprocessed entities: "
81 << NumPreprocessedEntities
<< '\n';
82 dumpLocalRemap("Preprocessed entity ID local -> global map",
83 PreprocessedEntityRemap
);
85 llvm::errs() << " Base type index: " << BaseTypeIndex
<< '\n'
86 << " Number of types: " << LocalNumTypes
<< '\n';
88 llvm::errs() << " Base decl index: " << BaseDeclIndex
<< '\n'
89 << " Number of decls: " << LocalNumDecls
<< '\n';