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