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