ModuleFile.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===- ModuleFile.cpp - Module description --------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the ModuleFile class, which describes a module that
  10. // has been loaded from an AST file.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Serialization/ModuleFile.h"
  14. #include "ASTReaderInternals.h"
  15. #include "clang/Serialization/ContinuousRangeMap.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/Support/Compiler.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. using namespace clang;
  20. using namespace serialization;
  21. using namespace reader;
  22. ModuleFile::~ModuleFile() {
  23. delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
  24. delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
  25. delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
  26. }
  27. template<typename Key, typename Offset, unsigned InitialCapacity>
  28. static void
  29. dumpLocalRemap(StringRef Name,
  30. const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
  31. if (Map.begin() == Map.end())
  32. return;
  33. using MapType = ContinuousRangeMap<Key, Offset, InitialCapacity>;
  34. llvm::errs() << " " << Name << ":\n";
  35. for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
  36. I != IEnd; ++I) {
  37. llvm::errs() << " " << I->first << " -> " << I->second << "\n";
  38. }
  39. }
  40. LLVM_DUMP_METHOD void ModuleFile::dump() {
  41. llvm::errs() << "\nModule: " << FileName << "\n";
  42. if (!Imports.empty()) {
  43. llvm::errs() << " Imports: ";
  44. for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
  45. if (I)
  46. llvm::errs() << ", ";
  47. llvm::errs() << Imports[I]->FileName;
  48. }
  49. llvm::errs() << "\n";
  50. }
  51. // Remapping tables.
  52. llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset
  53. << '\n';
  54. dumpLocalRemap("Source location offset local -> global map", SLocRemap);
  55. llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n'
  56. << " Number of identifiers: " << LocalNumIdentifiers << '\n';
  57. dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
  58. llvm::errs() << " Base macro ID: " << BaseMacroID << '\n'
  59. << " Number of macros: " << LocalNumMacros << '\n';
  60. dumpLocalRemap("Macro ID local -> global map", MacroRemap);
  61. llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n'
  62. << " Number of submodules: " << LocalNumSubmodules << '\n';
  63. dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
  64. llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n'
  65. << " Number of selectors: " << LocalNumSelectors << '\n';
  66. dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
  67. llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID
  68. << '\n'
  69. << " Number of preprocessed entities: "
  70. << NumPreprocessedEntities << '\n';
  71. dumpLocalRemap("Preprocessed entity ID local -> global map",
  72. PreprocessedEntityRemap);
  73. llvm::errs() << " Base type index: " << BaseTypeIndex << '\n'
  74. << " Number of types: " << LocalNumTypes << '\n';
  75. dumpLocalRemap("Type index local -> global map", TypeRemap);
  76. llvm::errs() << " Base decl ID: " << BaseDeclID << '\n'
  77. << " Number of decls: " << LocalNumDecls << '\n';
  78. dumpLocalRemap("Decl ID local -> global map", DeclRemap);
  79. }