Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 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" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 15 | #include "ASTReaderInternals.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "llvm/Support/MemoryBuffer.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace clang; |
| 20 | using namespace serialization; |
| 21 | using namespace reader; |
| 22 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 23 | ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation) |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 24 | : Kind(Kind), File(0), DirectlyImported(false), |
| 25 | Generation(Generation), SizeInBits(0), |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 26 | LocalNumSLocEntries(0), SLocEntryBaseID(0), |
| 27 | SLocEntryBaseOffset(0), SLocEntryOffsets(0), |
Douglas Gregor | 745e6f1 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 28 | LocalNumIdentifiers(0), |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 29 | IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0), |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 30 | IdentifierLookupTable(0), |
| 31 | LocalNumMacros(0), MacroOffsets(0), |
| 32 | BasePreprocessedEntityID(0), |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 33 | PreprocessedEntityOffsets(0), NumPreprocessedEntities(0), |
| 34 | LocalNumHeaderFileInfos(0), |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 35 | HeaderFileInfoTableData(0), HeaderFileInfoTable(0), |
Benjamin Kramer | 4a08268 | 2011-12-27 11:15:04 +0000 | [diff] [blame] | 36 | HeaderFileFrameworkStrings(0), LocalNumSubmodules(0), BaseSubmoduleID(0), |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 37 | LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0), |
| 38 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
| 39 | DeclOffsets(0), BaseDeclID(0), |
| 40 | LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 41 | FileSortedDecls(0), NumFileSortedDecls(0), |
| 42 | RedeclarationsMap(0), LocalNumRedeclarationsInMap(0), |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 43 | ObjCCategoriesMap(0), LocalNumObjCCategoriesInMap(0), |
Argyrios Kyrtzidis | 4182ed6 | 2012-10-31 20:59:50 +0000 | [diff] [blame] | 44 | LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 45 | {} |
| 46 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 47 | ModuleFile::~ModuleFile() { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 48 | for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(), |
| 49 | E = DeclContextInfos.end(); |
| 50 | I != E; ++I) { |
| 51 | if (I->second.NameLookupTableData) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 52 | delete I->second.NameLookupTableData; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
| 56 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
| 57 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 58 | } |
| 59 | |
| 60 | template<typename Key, typename Offset, unsigned InitialCapacity> |
| 61 | static void |
| 62 | dumpLocalRemap(StringRef Name, |
| 63 | const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) { |
| 64 | if (Map.begin() == Map.end()) |
| 65 | return; |
| 66 | |
| 67 | typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType; |
| 68 | llvm::errs() << " " << Name << ":\n"; |
| 69 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 70 | I != IEnd; ++I) { |
| 71 | llvm::errs() << " " << I->first << " -> " << I->second << "\n"; |
| 72 | } |
| 73 | } |
| 74 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 75 | void ModuleFile::dump() { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 76 | llvm::errs() << "\nModule: " << FileName << "\n"; |
| 77 | if (!Imports.empty()) { |
| 78 | llvm::errs() << " Imports: "; |
| 79 | for (unsigned I = 0, N = Imports.size(); I != N; ++I) { |
| 80 | if (I) |
| 81 | llvm::errs() << ", "; |
| 82 | llvm::errs() << Imports[I]->FileName; |
| 83 | } |
| 84 | llvm::errs() << "\n"; |
| 85 | } |
| 86 | |
| 87 | // Remapping tables. |
| 88 | llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset |
| 89 | << '\n'; |
| 90 | dumpLocalRemap("Source location offset local -> global map", SLocRemap); |
| 91 | |
| 92 | llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n' |
| 93 | << " Number of identifiers: " << LocalNumIdentifiers << '\n'; |
| 94 | dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 95 | |
Douglas Gregor | a8235d6 | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 96 | llvm::errs() << " Base macro ID: " << BaseMacroID << '\n' |
| 97 | << " Number of macros: " << LocalNumMacros << '\n'; |
| 98 | dumpLocalRemap("Macro ID local -> global map", MacroRemap); |
| 99 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 100 | llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n' |
| 101 | << " Number of submodules: " << LocalNumSubmodules << '\n'; |
| 102 | dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap); |
| 103 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 104 | llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n' |
| 105 | << " Number of selectors: " << LocalNumSelectors << '\n'; |
| 106 | dumpLocalRemap("Selector ID local -> global map", SelectorRemap); |
| 107 | |
| 108 | llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID |
| 109 | << '\n' |
| 110 | << " Number of preprocessed entities: " |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 111 | << NumPreprocessedEntities << '\n'; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 112 | dumpLocalRemap("Preprocessed entity ID local -> global map", |
| 113 | PreprocessedEntityRemap); |
| 114 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 115 | llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' |
| 116 | << " Number of types: " << LocalNumTypes << '\n'; |
| 117 | dumpLocalRemap("Type index local -> global map", TypeRemap); |
| 118 | |
| 119 | llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' |
| 120 | << " Number of decls: " << LocalNumDecls << '\n'; |
| 121 | dumpLocalRemap("Decl ID local -> global map", DeclRemap); |
| 122 | } |