]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Serialization/Module.cpp
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / lib / Serialization / Module.cpp
1 //===- Module.cpp - Module description ------------------------------------===//
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
15 #include "clang/Serialization/Module.h"
16 #include "ASTReaderInternals.h"
17 #include "clang/Serialization/ContinuousRangeMap.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/raw_ostream.h"
21
22 using namespace clang;
23 using namespace serialization;
24 using namespace reader;
25
26 ModuleFile::~ModuleFile() {
27   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
28   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
29   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
30 }
31
32 template<typename Key, typename Offset, unsigned InitialCapacity>
33 static void 
34 dumpLocalRemap(StringRef Name,
35                const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
36   if (Map.begin() == Map.end())
37     return;
38   
39   using MapType = ContinuousRangeMap<Key, Offset, InitialCapacity>;
40
41   llvm::errs() << "  " << Name << ":\n";
42   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 
43        I != IEnd; ++I) {
44     llvm::errs() << "    " << I->first << " -> " << I->second << "\n";
45   }
46 }
47
48 LLVM_DUMP_METHOD void ModuleFile::dump() {
49   llvm::errs() << "\nModule: " << FileName << "\n";
50   if (!Imports.empty()) {
51     llvm::errs() << "  Imports: ";
52     for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
53       if (I)
54         llvm::errs() << ", ";
55       llvm::errs() << Imports[I]->FileName;
56     }
57     llvm::errs() << "\n";
58   }
59   
60   // Remapping tables.
61   llvm::errs() << "  Base source location offset: " << SLocEntryBaseOffset 
62                << '\n';
63   dumpLocalRemap("Source location offset local -> global map", SLocRemap);
64   
65   llvm::errs() << "  Base identifier ID: " << BaseIdentifierID << '\n'
66                << "  Number of identifiers: " << LocalNumIdentifiers << '\n';
67   dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
68
69   llvm::errs() << "  Base macro ID: " << BaseMacroID << '\n'
70                << "  Number of macros: " << LocalNumMacros << '\n';
71   dumpLocalRemap("Macro ID local -> global map", MacroRemap);
72
73   llvm::errs() << "  Base submodule ID: " << BaseSubmoduleID << '\n'
74                << "  Number of submodules: " << LocalNumSubmodules << '\n';
75   dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
76
77   llvm::errs() << "  Base selector ID: " << BaseSelectorID << '\n'
78                << "  Number of selectors: " << LocalNumSelectors << '\n';
79   dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
80   
81   llvm::errs() << "  Base preprocessed entity ID: " << BasePreprocessedEntityID
82                << '\n'  
83                << "  Number of preprocessed entities: " 
84                << NumPreprocessedEntities << '\n';
85   dumpLocalRemap("Preprocessed entity ID local -> global map", 
86                  PreprocessedEntityRemap);
87   
88   llvm::errs() << "  Base type index: " << BaseTypeIndex << '\n'
89                << "  Number of types: " << LocalNumTypes << '\n';
90   dumpLocalRemap("Type index local -> global map", TypeRemap);
91   
92   llvm::errs() << "  Base decl ID: " << BaseDeclID << '\n'
93                << "  Number of decls: " << LocalNumDecls << '\n';
94   dumpLocalRemap("Decl ID local -> global map", DeclRemap);
95 }