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 Module::Module(ModuleKind Kind) 24 : Kind(Kind), DirectlyImported(false), 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), 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 LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0) 39 {} 40 41 Module::~Module() { 42 for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(), 43 E = DeclContextInfos.end(); 44 I != E; ++I) { 45 if (I->second.NameLookupTableData) 46 delete static_cast<ASTDeclContextNameLookupTable*>( 47 I->second.NameLookupTableData); 48 } 49 50 delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); 51 delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); 52 delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); 53 } 54 55 template<typename Key, typename Offset, unsigned InitialCapacity> 56 static void 57 dumpLocalRemap(StringRef Name, 58 const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) { 59 if (Map.begin() == Map.end()) 60 return; 61 62 typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType; 63 llvm::errs() << " " << Name << ":\n"; 64 for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 65 I != IEnd; ++I) { 66 llvm::errs() << " " << I->first << " -> " << I->second << "\n"; 67 } 68 } 69 70 void Module::dump() { 71 llvm::errs() << "\nModule: " << FileName << "\n"; 72 if (!Imports.empty()) { 73 llvm::errs() << " Imports: "; 74 for (unsigned I = 0, N = Imports.size(); I != N; ++I) { 75 if (I) 76 llvm::errs() << ", "; 77 llvm::errs() << Imports[I]->FileName; 78 } 79 llvm::errs() << "\n"; 80 } 81 82 // Remapping tables. 83 llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset 84 << '\n'; 85 dumpLocalRemap("Source location offset local -> global map", SLocRemap); 86 87 llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n' 88 << " Number of identifiers: " << LocalNumIdentifiers << '\n'; 89 dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap); 90 91 llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n' 92 << " Number of selectors: " << LocalNumSelectors << '\n'; 93 dumpLocalRemap("Selector ID local -> global map", SelectorRemap); 94 95 llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID 96 << '\n' 97 << " Number of preprocessed entities: " 98 << NumPreprocessedEntities << '\n'; 99 dumpLocalRemap("Preprocessed entity ID local -> global map", 100 PreprocessedEntityRemap); 101 102 llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' 103 << " Number of types: " << LocalNumTypes << '\n'; 104 dumpLocalRemap("Type index local -> global map", TypeRemap); 105 106 llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' 107 << " Number of decls: " << LocalNumDecls << '\n'; 108 dumpLocalRemap("Decl ID local -> global map", DeclRemap); 109 } 110