Module.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. RedeclarationsMap(nullptr), LocalNumRedeclarationsInMap(0),
  42. ObjCCategoriesMap(nullptr), LocalNumObjCCategoriesInMap(0),
  43. LocalNumTypes(0), TypeOffsets(nullptr), BaseTypeIndex(0)
  44. {}
  45. ModuleFile::~ModuleFile() {
  46. for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
  47. E = DeclContextInfos.end();
  48. I != E; ++I) {
  49. if (I->second.NameLookupTableData)
  50. delete I->second.NameLookupTableData;
  51. }
  52. delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
  53. delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
  54. delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
  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. 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. void ModuleFile::dump() {
  70. llvm::errs() << "\nModule: " << FileName << "\n";
  71. if (!Imports.empty()) {
  72. llvm::errs() << " Imports: ";
  73. for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
  74. if (I)
  75. llvm::errs() << ", ";
  76. llvm::errs() << Imports[I]->FileName;
  77. }
  78. llvm::errs() << "\n";
  79. }
  80. // Remapping tables.
  81. llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
  82. << '\n';
  83. dumpLocalRemap("Source location offset local -> global map", SLocRemap);
  84. llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
  85. << " Number of identifiers: " << LocalNumIdentifiers << '\n';
  86. dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
  87. llvm::errs() << " Base macro ID: " << BaseMacroID << '\n'
  88. << " Number of macros: " << LocalNumMacros << '\n';
  89. dumpLocalRemap("Macro ID local -> global map", MacroRemap);
  90. llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
  91. << " Number of submodules: " << LocalNumSubmodules << '\n';
  92. dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
  93. llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
  94. << " Number of selectors: " << LocalNumSelectors << '\n';
  95. dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
  96. llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
  97. << '\n'
  98. << " Number of preprocessed entities: "
  99. << NumPreprocessedEntities << '\n';
  100. dumpLocalRemap("Preprocessed entity ID local -> global map",
  101. PreprocessedEntityRemap);
  102. llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
  103. << " Number of types: " << LocalNumTypes << '\n';
  104. dumpLocalRemap("Type index local -> global map", TypeRemap);
  105. llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
  106. << " Number of decls: " << LocalNumDecls << '\n';
  107. dumpLocalRemap("Decl ID local -> global map", DeclRemap);
  108. }