Module.cpp 4.3 KB

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