clang API Documentation
00001 //===--- Module.cpp - Module description ------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the Module class, which describes a module that has 00011 // been loaded from an AST file. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 #include "clang/Serialization/Module.h" 00015 #include "ASTReaderInternals.h" 00016 #include "llvm/Support/MemoryBuffer.h" 00017 #include "llvm/Support/raw_ostream.h" 00018 00019 using namespace clang; 00020 using namespace serialization; 00021 using namespace reader; 00022 00023 ModuleFile::ModuleFile(ModuleKind Kind, unsigned Generation) 00024 : Kind(Kind), File(nullptr), Signature(0), DirectlyImported(false), 00025 Generation(Generation), SizeInBits(0), 00026 LocalNumSLocEntries(0), SLocEntryBaseID(0), 00027 SLocEntryBaseOffset(0), SLocEntryOffsets(nullptr), 00028 LocalNumIdentifiers(0), 00029 IdentifierOffsets(nullptr), BaseIdentifierID(0), 00030 IdentifierTableData(nullptr), IdentifierLookupTable(nullptr), 00031 LocalNumMacros(0), MacroOffsets(nullptr), 00032 BasePreprocessedEntityID(0), 00033 PreprocessedEntityOffsets(nullptr), NumPreprocessedEntities(0), 00034 LocalNumHeaderFileInfos(0), 00035 HeaderFileInfoTableData(nullptr), HeaderFileInfoTable(nullptr), 00036 LocalNumSubmodules(0), BaseSubmoduleID(0), 00037 LocalNumSelectors(0), SelectorOffsets(nullptr), BaseSelectorID(0), 00038 SelectorLookupTableData(nullptr), SelectorLookupTable(nullptr), 00039 LocalNumDecls(0), DeclOffsets(nullptr), BaseDeclID(0), 00040 LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(nullptr), 00041 FileSortedDecls(nullptr), NumFileSortedDecls(0), 00042 RedeclarationsMap(nullptr), LocalNumRedeclarationsInMap(0), 00043 ObjCCategoriesMap(nullptr), LocalNumObjCCategoriesInMap(0), 00044 LocalNumTypes(0), TypeOffsets(nullptr), BaseTypeIndex(0) 00045 {} 00046 00047 ModuleFile::~ModuleFile() { 00048 for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(), 00049 E = DeclContextInfos.end(); 00050 I != E; ++I) { 00051 if (I->second.NameLookupTableData) 00052 delete I->second.NameLookupTableData; 00053 } 00054 00055 delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); 00056 delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); 00057 delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); 00058 } 00059 00060 template<typename Key, typename Offset, unsigned InitialCapacity> 00061 static void 00062 dumpLocalRemap(StringRef Name, 00063 const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) { 00064 if (Map.begin() == Map.end()) 00065 return; 00066 00067 typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType; 00068 llvm::errs() << " " << Name << ":\n"; 00069 for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); 00070 I != IEnd; ++I) { 00071 llvm::errs() << " " << I->first << " -> " << I->second << "\n"; 00072 } 00073 } 00074 00075 void ModuleFile::dump() { 00076 llvm::errs() << "\nModule: " << FileName << "\n"; 00077 if (!Imports.empty()) { 00078 llvm::errs() << " Imports: "; 00079 for (unsigned I = 0, N = Imports.size(); I != N; ++I) { 00080 if (I) 00081 llvm::errs() << ", "; 00082 llvm::errs() << Imports[I]->FileName; 00083 } 00084 llvm::errs() << "\n"; 00085 } 00086 00087 // Remapping tables. 00088 llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset 00089 << '\n'; 00090 dumpLocalRemap("Source location offset local -> global map", SLocRemap); 00091 00092 llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n' 00093 << " Number of identifiers: " << LocalNumIdentifiers << '\n'; 00094 dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap); 00095 00096 llvm::errs() << " Base macro ID: " << BaseMacroID << '\n' 00097 << " Number of macros: " << LocalNumMacros << '\n'; 00098 dumpLocalRemap("Macro ID local -> global map", MacroRemap); 00099 00100 llvm::errs() << " Base submodule ID: " << BaseSubmoduleID << '\n' 00101 << " Number of submodules: " << LocalNumSubmodules << '\n'; 00102 dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap); 00103 00104 llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n' 00105 << " Number of selectors: " << LocalNumSelectors << '\n'; 00106 dumpLocalRemap("Selector ID local -> global map", SelectorRemap); 00107 00108 llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID 00109 << '\n' 00110 << " Number of preprocessed entities: " 00111 << NumPreprocessedEntities << '\n'; 00112 dumpLocalRemap("Preprocessed entity ID local -> global map", 00113 PreprocessedEntityRemap); 00114 00115 llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' 00116 << " Number of types: " << LocalNumTypes << '\n'; 00117 dumpLocalRemap("Type index local -> global map", TypeRemap); 00118 00119 llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' 00120 << " Number of decls: " << LocalNumDecls << '\n'; 00121 dumpLocalRemap("Decl ID local -> global map", DeclRemap); 00122 }