Module.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. using namespace clang;
  19. using namespace serialization;
  20. using namespace reader;
  21. ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation)
  22. : Kind(Kind), File(nullptr), Signature(0), DirectlyImported(false),
  23. Generation(Generation), SizeInBits(0),
  24. LocalNumSLocEntries(0), SLocEntryBaseID(0),
  25. SLocEntryBaseOffset(0), SLocEntryOffsets(nullptr),
  26. LocalNumIdentifiers(0),
  27. IdentifierOffsets(nullptr), BaseIdentifierID(0),
  28. IdentifierTableData(nullptr), IdentifierLookupTable(nullptr),
  29. LocalNumMacros(0), MacroOffsets(nullptr),
  30. BasePreprocessedEntityID(0),
  31. PreprocessedEntityOffsets(nullptr), NumPreprocessedEntities(0),
  32. LocalNumHeaderFileInfos(0),
  33. HeaderFileInfoTableData(nullptr), HeaderFileInfoTable(nullptr),
  34. LocalNumSubmodules(0), BaseSubmoduleID(0),
  35. LocalNumSelectors(0), SelectorOffsets(nullptr), BaseSelectorID(0),
  36. SelectorLookupTableData(nullptr), SelectorLookupTable(nullptr),
  37. LocalNumDecls(0), DeclOffsets(nullptr), BaseDeclID(0),
  38. LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(nullptr),
  39. LocalNumCXXCtorInitializers(0), CXXCtorInitializersOffsets(nullptr),
  40. FileSortedDecls(nullptr), NumFileSortedDecls(0),
  41. ObjCCategoriesMap(nullptr), LocalNumObjCCategoriesInMap(0),
  42. LocalNumTypes(0), TypeOffsets(nullptr), BaseTypeIndex(0)
  43. {}
  44. ModuleFile::~ModuleFile() {
  45. for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
  46. E = DeclContextInfos.end();
  47. I != E; ++I) {
  48. if (I->second.NameLookupTableData)
  49. delete I->second.NameLookupTableData;
  50. }
  51. delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
  52. delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
  53. delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
  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. typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType;
  62. llvm::errs() << " " << Name << ":\n";
  63. for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
  64. I != IEnd; ++I) {
  65. llvm::errs() << " " << I->first << " -> " << I->second << "\n";
  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. // Remapping tables.
  80. llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
  81. << '\n';
  82. dumpLocalRemap("Source location offset local -> global map", SLocRemap);
  83. llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
  84. << " Number of identifiers: " << LocalNumIdentifiers << '\n';
  85. dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
  86. llvm::errs() << " Base macro ID: " << BaseMacroID << '\n'
  87. << " Number of macros: " << LocalNumMacros << '\n';
  88. dumpLocalRemap("Macro ID local -> global map", MacroRemap);
  89. llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
  90. << " Number of submodules: " << LocalNumSubmodules << '\n';
  91. dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
  92. llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
  93. << " Number of selectors: " << LocalNumSelectors << '\n';
  94. dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
  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. llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
  102. << " Number of types: " << LocalNumTypes << '\n';
  103. dumpLocalRemap("Type index local -> global map", TypeRemap);
  104. llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
  105. << " Number of decls: " << LocalNumDecls << '\n';
  106. dumpLocalRemap("Decl ID local -> global map", DeclRemap);
  107. }