1*4ba319b5SDimitry Andric //===- Module.cpp - Module description ------------------------------------===//
26122f3e6SDimitry Andric //
36122f3e6SDimitry Andric //                     The LLVM Compiler Infrastructure
46122f3e6SDimitry Andric //
56122f3e6SDimitry Andric // This file is distributed under the University of Illinois Open Source
66122f3e6SDimitry Andric // License. See LICENSE.TXT for details.
76122f3e6SDimitry Andric //
86122f3e6SDimitry Andric //===----------------------------------------------------------------------===//
96122f3e6SDimitry Andric //
106122f3e6SDimitry Andric //  This file implements the Module class, which describes a module that has
116122f3e6SDimitry Andric //  been loaded from an AST file.
126122f3e6SDimitry Andric //
136122f3e6SDimitry Andric //===----------------------------------------------------------------------===//
14*4ba319b5SDimitry Andric 
156122f3e6SDimitry Andric #include "clang/Serialization/Module.h"
166122f3e6SDimitry Andric #include "ASTReaderInternals.h"
17*4ba319b5SDimitry Andric #include "clang/Serialization/ContinuousRangeMap.h"
18*4ba319b5SDimitry Andric #include "llvm/ADT/StringRef.h"
19*4ba319b5SDimitry Andric #include "llvm/Support/Compiler.h"
20139f7f9bSDimitry Andric #include "llvm/Support/raw_ostream.h"
216122f3e6SDimitry Andric 
226122f3e6SDimitry Andric using namespace clang;
236122f3e6SDimitry Andric using namespace serialization;
246122f3e6SDimitry Andric using namespace reader;
256122f3e6SDimitry Andric 
~ModuleFile()26dff0c46cSDimitry Andric ModuleFile::~ModuleFile() {
276122f3e6SDimitry Andric   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
286122f3e6SDimitry Andric   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
296122f3e6SDimitry Andric   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
306122f3e6SDimitry Andric }
316122f3e6SDimitry Andric 
326122f3e6SDimitry Andric template<typename Key, typename Offset, unsigned InitialCapacity>
336122f3e6SDimitry Andric static void
dumpLocalRemap(StringRef Name,const ContinuousRangeMap<Key,Offset,InitialCapacity> & Map)346122f3e6SDimitry Andric dumpLocalRemap(StringRef Name,
356122f3e6SDimitry Andric                const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
366122f3e6SDimitry Andric   if (Map.begin() == Map.end())
376122f3e6SDimitry Andric     return;
386122f3e6SDimitry Andric 
39*4ba319b5SDimitry Andric   using MapType = ContinuousRangeMap<Key, Offset, InitialCapacity>;
40*4ba319b5SDimitry Andric 
416122f3e6SDimitry Andric   llvm::errs() << "  " << Name << ":\n";
426122f3e6SDimitry Andric   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
436122f3e6SDimitry Andric        I != IEnd; ++I) {
446122f3e6SDimitry Andric     llvm::errs() << "    " << I->first << " -> " << I->second << "\n";
456122f3e6SDimitry Andric   }
466122f3e6SDimitry Andric }
476122f3e6SDimitry Andric 
dump()48e7145dcbSDimitry Andric LLVM_DUMP_METHOD void ModuleFile::dump() {
496122f3e6SDimitry Andric   llvm::errs() << "\nModule: " << FileName << "\n";
506122f3e6SDimitry Andric   if (!Imports.empty()) {
516122f3e6SDimitry Andric     llvm::errs() << "  Imports: ";
526122f3e6SDimitry Andric     for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
536122f3e6SDimitry Andric       if (I)
546122f3e6SDimitry Andric         llvm::errs() << ", ";
556122f3e6SDimitry Andric       llvm::errs() << Imports[I]->FileName;
566122f3e6SDimitry Andric     }
576122f3e6SDimitry Andric     llvm::errs() << "\n";
586122f3e6SDimitry Andric   }
596122f3e6SDimitry Andric 
606122f3e6SDimitry Andric   // Remapping tables.
616122f3e6SDimitry Andric   llvm::errs() << "  Base source location offset: " << SLocEntryBaseOffset
626122f3e6SDimitry Andric                << '\n';
636122f3e6SDimitry Andric   dumpLocalRemap("Source location offset local -> global map", SLocRemap);
646122f3e6SDimitry Andric 
656122f3e6SDimitry Andric   llvm::errs() << "  Base identifier ID: " << BaseIdentifierID << '\n'
666122f3e6SDimitry Andric                << "  Number of identifiers: " << LocalNumIdentifiers << '\n';
676122f3e6SDimitry Andric   dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
686122f3e6SDimitry Andric 
693861d79fSDimitry Andric   llvm::errs() << "  Base macro ID: " << BaseMacroID << '\n'
703861d79fSDimitry Andric                << "  Number of macros: " << LocalNumMacros << '\n';
713861d79fSDimitry Andric   dumpLocalRemap("Macro ID local -> global map", MacroRemap);
723861d79fSDimitry Andric 
73dff0c46cSDimitry Andric   llvm::errs() << "  Base submodule ID: " << BaseSubmoduleID << '\n'
74dff0c46cSDimitry Andric                << "  Number of submodules: " << LocalNumSubmodules << '\n';
75dff0c46cSDimitry Andric   dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
76dff0c46cSDimitry Andric 
776122f3e6SDimitry Andric   llvm::errs() << "  Base selector ID: " << BaseSelectorID << '\n'
786122f3e6SDimitry Andric                << "  Number of selectors: " << LocalNumSelectors << '\n';
796122f3e6SDimitry Andric   dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
806122f3e6SDimitry Andric 
816122f3e6SDimitry Andric   llvm::errs() << "  Base preprocessed entity ID: " << BasePreprocessedEntityID
826122f3e6SDimitry Andric                << '\n'
836122f3e6SDimitry Andric                << "  Number of preprocessed entities: "
846122f3e6SDimitry Andric                << NumPreprocessedEntities << '\n';
856122f3e6SDimitry Andric   dumpLocalRemap("Preprocessed entity ID local -> global map",
866122f3e6SDimitry Andric                  PreprocessedEntityRemap);
876122f3e6SDimitry Andric 
886122f3e6SDimitry Andric   llvm::errs() << "  Base type index: " << BaseTypeIndex << '\n'
896122f3e6SDimitry Andric                << "  Number of types: " << LocalNumTypes << '\n';
906122f3e6SDimitry Andric   dumpLocalRemap("Type index local -> global map", TypeRemap);
916122f3e6SDimitry Andric 
926122f3e6SDimitry Andric   llvm::errs() << "  Base decl ID: " << BaseDeclID << '\n'
936122f3e6SDimitry Andric                << "  Number of decls: " << LocalNumDecls << '\n';
946122f3e6SDimitry Andric   dumpLocalRemap("Decl ID local -> global map", DeclRemap);
956122f3e6SDimitry Andric }
96