Module.cpp revision a8235d6c4093cd38dcf742909651f867de62e55b
198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor//===--- Module.cpp - Module description ------------------------*- C++ -*-===// 298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// 398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// The LLVM Compiler Infrastructure 498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// 598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// This file is distributed under the University of Illinois Open Source 698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// License. See LICENSE.TXT for details. 798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// 898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor//===----------------------------------------------------------------------===// 998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// 1098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// This file implements the Module class, which describes a module that has 1198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// been loaded from an AST file. 1298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor// 1398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor//===----------------------------------------------------------------------===// 1498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "clang/Serialization/Module.h" 1598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "llvm/Support/raw_ostream.h" 1698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "llvm/Support/MemoryBuffer.h" 1798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "ASTReaderInternals.h" 1898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 1998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregorusing namespace clang; 2098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregorusing namespace serialization; 2198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregorusing namespace reader; 2298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 23057df20b3107cef764052d271c89b8591b98b3ceDouglas GregorModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation) 24d64c26f6676eef69d1713f353ca8a3c2fe963f17Argyrios Kyrtzidis : Kind(Kind), File(0), DirectlyImported(false), 25d64c26f6676eef69d1713f353ca8a3c2fe963f17Argyrios Kyrtzidis Generation(Generation), SizeInBits(0), 2698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor LocalNumSLocEntries(0), SLocEntryBaseID(0), 2798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor SLocEntryBaseOffset(0), SLocEntryOffsets(0), 28a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor SLocFileOffsets(0), LocalNumIdentifiers(0), 2998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0), 30a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor IdentifierLookupTable(0), 31a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor LocalNumMacros(0), MacroOffsets(0), 32a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor BasePreprocessedEntityID(0), 33e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis PreprocessedEntityOffsets(0), NumPreprocessedEntities(0), 34e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis LocalNumHeaderFileInfos(0), 3598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor HeaderFileInfoTableData(0), HeaderFileInfoTable(0), 364a08268a6953b3ce77691d3a8a7589e7cdeea947Benjamin Kramer HeaderFileFrameworkStrings(0), LocalNumSubmodules(0), BaseSubmoduleID(0), 3798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0), 3898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), 3998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor DeclOffsets(0), BaseDeclID(0), 4098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), 412093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis FileSortedDecls(0), NumFileSortedDecls(0), 422093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis RedeclarationsMap(0), LocalNumRedeclarationsInMap(0), 43cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor ObjCCategoriesMap(0), LocalNumObjCCategoriesInMap(0), 44e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0) 4598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor{} 4698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas GregorModuleFile::~ModuleFile() { 4898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(), 4998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor E = DeclContextInfos.end(); 5098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor I != E; ++I) { 5198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor if (I->second.NameLookupTableData) 52b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer delete I->second.NameLookupTableData; 5398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor } 5498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 5598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); 5698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); 5798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); 5898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor} 5998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 6098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregortemplate<typename Key, typename Offset, unsigned InitialCapacity> 6198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregorstatic void 6298339b96a8089a6da715487e432c5abfca0ca0dfDouglas GregordumpLocalRemap(StringRef Name, 6398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) { 6498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor if (Map.begin() == Map.end()) 6598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor return; 6698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 6798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType; 6898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " " << Name << ":\n"; 6998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 7098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor I != IEnd; ++I) { 7198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " " << I->first << " -> " << I->second << "\n"; 7298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor } 7398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor} 7498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 751a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregorvoid ModuleFile::dump() { 7698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << "\nModule: " << FileName << "\n"; 7798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor if (!Imports.empty()) { 7898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Imports: "; 7998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor for (unsigned I = 0, N = Imports.size(); I != N; ++I) { 8098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor if (I) 8198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << ", "; 8298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << Imports[I]->FileName; 8398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor } 8498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << "\n"; 8598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor } 8698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 8798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor // Remapping tables. 8898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset 8998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << '\n'; 9098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor dumpLocalRemap("Source location offset local -> global map", SLocRemap); 9198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 9298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n' 9398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << " Number of identifiers: " << LocalNumIdentifiers << '\n'; 9498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap); 9526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor 96a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor llvm::errs() << " Base macro ID: " << BaseMacroID << '\n' 97a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor << " Number of macros: " << LocalNumMacros << '\n'; 98a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor dumpLocalRemap("Macro ID local -> global map", MacroRemap); 99a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 10026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n' 10126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor << " Number of submodules: " << LocalNumSubmodules << '\n'; 10226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap); 10326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor 10498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n' 10598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << " Number of selectors: " << LocalNumSelectors << '\n'; 10698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor dumpLocalRemap("Selector ID local -> global map", SelectorRemap); 10798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 10898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID 10998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << '\n' 11098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << " Number of preprocessed entities: " 111e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis << NumPreprocessedEntities << '\n'; 11298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor dumpLocalRemap("Preprocessed entity ID local -> global map", 11398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor PreprocessedEntityRemap); 11498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 11598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' 11698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << " Number of types: " << LocalNumTypes << '\n'; 11798339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor dumpLocalRemap("Type index local -> global map", TypeRemap); 11898339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor 11998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' 12098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor << " Number of decls: " << LocalNumDecls << '\n'; 12198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor dumpLocalRemap("Decl ID local -> global map", DeclRemap); 12298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor} 123