ModuleMap.h revision 90db26000aefe9335370013eec64c85232d80227
1//===--- ModuleMap.h - Describe the layout of modules -----------*- 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 defines the ModuleMap interface, which describes the layout of a 11// module as it relates to headers. 12// 13//===----------------------------------------------------------------------===// 14 15 16#ifndef LLVM_CLANG_LEX_MODULEMAP_H 17#define LLVM_CLANG_LEX_MODULEMAP_H 18 19#include "clang/Basic/LangOptions.h" 20#include "clang/Basic/Module.h" 21#include "clang/Basic/SourceManager.h" 22#include "llvm/ADT/DenseMap.h" 23#include "llvm/ADT/IntrusiveRefCntPtr.h" 24#include "llvm/ADT/SmallVector.h" 25#include "llvm/ADT/StringRef.h" 26#include "llvm/ADT/StringMap.h" 27#include <string> 28 29namespace clang { 30 31class DirectoryEntry; 32class FileEntry; 33class FileManager; 34class DiagnosticConsumer; 35class DiagnosticsEngine; 36class ModuleMapParser; 37 38class ModuleMap { 39 SourceManager *SourceMgr; 40 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags; 41 LangOptions LangOpts; 42 43 /// \brief The top-level modules that are known. 44 llvm::StringMap<Module *> Modules; 45 46 /// \brief Mapping from each header to the module that owns the contents of the 47 /// that header. 48 llvm::DenseMap<const FileEntry *, Module *> Headers; 49 50 /// \brief Mapping from directories with umbrella headers to the module 51 /// that is generated from the umbrella header. 52 /// 53 /// This mapping is used to map headers that haven't explicitly been named 54 /// in the module map over to the module that includes them via its umbrella 55 /// header. 56 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs; 57 58 friend class ModuleMapParser; 59 60 /// \brief Resolve the given export declaration into an actual export 61 /// declaration. 62 /// 63 /// \param Mod The module in which we're resolving the export declaration. 64 /// 65 /// \param Unresolved The export declaration to resolve. 66 /// 67 /// \param Complain Whether this routine should complain about unresolvable 68 /// exports. 69 /// 70 /// \returns The resolved export declaration, which will have a NULL pointer 71 /// if the export could not be resolved. 72 Module::ExportDecl 73 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved, 74 bool Complain); 75 76public: 77 /// \brief Construct a new module map. 78 /// 79 /// \param FileMgr The file manager used to find module files and headers. 80 /// This file manager should be shared with the header-search mechanism, since 81 /// they will refer to the same headers. 82 /// 83 /// \param DC A diagnostic consumer that will be cloned for use in generating 84 /// diagnostics. 85 ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC); 86 87 /// \brief Destroy the module map. 88 /// 89 ~ModuleMap(); 90 91 /// \brief Retrieve the module that owns the given header file, if any. 92 /// 93 /// \param File The header file that is likely to be included. 94 /// 95 /// \returns The module that owns the given header file, or null to indicate 96 /// that no module owns this header file. 97 Module *findModuleForHeader(const FileEntry *File); 98 99 /// \brief Retrieve a module with the given name. 100 /// 101 /// \param The name of the module to look up. 102 /// 103 /// \returns The named module, if known; otherwise, returns null. 104 Module *findModule(StringRef Name); 105 106 /// \brief Retrieve a module with the given name using lexical name lookup, 107 /// starting at the given context. 108 /// 109 /// \param The name of the module to look up. 110 /// 111 /// \param Context The module context, from which we will perform lexical 112 /// name lookup. 113 /// 114 /// \returns The named module, if known; otherwise, returns null. 115 Module *lookupModuleUnqualified(StringRef Name, Module *Context); 116 117 /// \brief Retrieve a module with the given name within the given context, 118 /// using direct (qualified) name lookup. 119 /// 120 /// \param The name of the module to look up. 121 /// 122 /// \param Context The module for which we will look for a submodule. If 123 /// null, we will look for a top-level module. 124 /// 125 /// \returns The named submodule, if known; otherwose, returns null. 126 Module *lookupModuleQualified(StringRef Name, Module *Context); 127 128 /// \brief Find a new module or submodule, or create it if it does not already 129 /// exist. 130 /// 131 /// \param Name The name of the module to find or create. 132 /// 133 /// \param Parent The module that will act as the parent of this submodule, 134 /// or NULL to indicate that this is a top-level module. 135 /// 136 /// \param IsFramework Whether this is a framework module. 137 /// 138 /// \param IsExplicit Whether this is an explicit submodule. 139 /// 140 /// \returns The found or newly-created module, along with a boolean value 141 /// that will be true if the module is newly-created. 142 std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent, 143 bool IsFramework, 144 bool IsExplicit); 145 146 /// \brief Infer the contents of a framework module map from the given 147 /// framework directory. 148 Module *inferFrameworkModule(StringRef ModuleName, 149 const DirectoryEntry *FrameworkDir); 150 151 /// \brief Retrieve the module map file containing the definition of the given 152 /// module. 153 /// 154 /// \param Module The module whose module map file will be returned, if known. 155 /// 156 /// \returns The file entry for the module map file containing the given 157 /// module, or NULL if the module definition was inferred. 158 const FileEntry *getContainingModuleMapFile(Module *Module); 159 160 /// \brief Resolve all of the unresolved exports in the given module. 161 /// 162 /// \param Mod The module whose exports should be resolved. 163 /// 164 /// \param Complain Whether to emit diagnostics for failures. 165 /// 166 /// \returns true if any errors were encountered while resolving exports, 167 /// false otherwise. 168 bool resolveExports(Module *Mod, bool Complain); 169 170 /// \brief Parse the given module map file, and record any modules we 171 /// encounter. 172 /// 173 /// \param File The file to be parsed. 174 /// 175 /// \returns true if an error occurred, false otherwise. 176 bool parseModuleMapFile(const FileEntry *File); 177 178 /// \brief Dump the contents of the module map, for debugging purposes. 179 void dump(); 180}; 181 182} 183#endif 184