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