clang API Documentation
00001 //===--- ModuleMap.h - Describe the layout of modules -----------*- 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 defines the ModuleMap interface, which describes the layout of a 00011 // module as it relates to headers. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 00016 #ifndef LLVM_CLANG_LEX_MODULEMAP_H 00017 #define LLVM_CLANG_LEX_MODULEMAP_H 00018 00019 #include "clang/Basic/LangOptions.h" 00020 #include "clang/Basic/Module.h" 00021 #include "clang/Basic/SourceManager.h" 00022 #include "llvm/ADT/DenseMap.h" 00023 #include "llvm/ADT/IntrusiveRefCntPtr.h" 00024 #include "llvm/ADT/SmallVector.h" 00025 #include "llvm/ADT/StringRef.h" 00026 #include "llvm/ADT/StringMap.h" 00027 #include <string> 00028 00029 namespace clang { 00030 00031 class DirectoryEntry; 00032 class FileEntry; 00033 class FileManager; 00034 class DiagnosticConsumer; 00035 class DiagnosticsEngine; 00036 class ModuleMapParser; 00037 00038 class ModuleMap { 00039 SourceManager *SourceMgr; 00040 IntrusiveRefCntPtr<DiagnosticsEngine> Diags; 00041 const LangOptions &LangOpts; 00042 const TargetInfo *Target; 00043 00044 /// \brief The directory used for Clang-supplied, builtin include headers, 00045 /// such as "stdint.h". 00046 const DirectoryEntry *BuiltinIncludeDir; 00047 00048 /// \brief Language options used to parse the module map itself. 00049 /// 00050 /// These are always simple C language options. 00051 LangOptions MMapLangOpts; 00052 00053 /// \brief The top-level modules that are known. 00054 llvm::StringMap<Module *> Modules; 00055 00056 /// \brief Mapping from each header to the module that owns the contents of the 00057 /// that header. 00058 llvm::DenseMap<const FileEntry *, Module *> Headers; 00059 00060 /// \brief Mapping from directories with umbrella headers to the module 00061 /// that is generated from the umbrella header. 00062 /// 00063 /// This mapping is used to map headers that haven't explicitly been named 00064 /// in the module map over to the module that includes them via its umbrella 00065 /// header. 00066 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs; 00067 00068 friend class ModuleMapParser; 00069 00070 /// \brief Resolve the given export declaration into an actual export 00071 /// declaration. 00072 /// 00073 /// \param Mod The module in which we're resolving the export declaration. 00074 /// 00075 /// \param Unresolved The export declaration to resolve. 00076 /// 00077 /// \param Complain Whether this routine should complain about unresolvable 00078 /// exports. 00079 /// 00080 /// \returns The resolved export declaration, which will have a NULL pointer 00081 /// if the export could not be resolved. 00082 Module::ExportDecl 00083 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved, 00084 bool Complain); 00085 00086 public: 00087 /// \brief Construct a new module map. 00088 /// 00089 /// \param FileMgr The file manager used to find module files and headers. 00090 /// This file manager should be shared with the header-search mechanism, since 00091 /// they will refer to the same headers. 00092 /// 00093 /// \param DC A diagnostic consumer that will be cloned for use in generating 00094 /// diagnostics. 00095 /// 00096 /// \param LangOpts Language options for this translation unit. 00097 /// 00098 /// \param Target The target for this translation unit. 00099 ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC, 00100 const LangOptions &LangOpts, const TargetInfo *Target); 00101 00102 /// \brief Destroy the module map. 00103 /// 00104 ~ModuleMap(); 00105 00106 /// \brief Set the target information. 00107 void setTarget(const TargetInfo &Target); 00108 00109 /// \brief Set the directory that contains Clang-supplied include 00110 /// files, such as our stdarg.h or tgmath.h. 00111 void setBuiltinIncludeDir(const DirectoryEntry *Dir) { 00112 BuiltinIncludeDir = Dir; 00113 } 00114 00115 /// \brief Retrieve the module that owns the given header file, if any. 00116 /// 00117 /// \param File The header file that is likely to be included. 00118 /// 00119 /// \returns The module that owns the given header file, or null to indicate 00120 /// that no module owns this header file. 00121 Module *findModuleForHeader(const FileEntry *File); 00122 00123 /// \brief Determine whether the given header is part of a module 00124 /// marked 'unavailable'. 00125 bool isHeaderInUnavailableModule(const FileEntry *Header); 00126 00127 /// \brief Retrieve a module with the given name. 00128 /// 00129 /// \param The name of the module to look up. 00130 /// 00131 /// \returns The named module, if known; otherwise, returns null. 00132 Module *findModule(StringRef Name); 00133 00134 /// \brief Retrieve a module with the given name using lexical name lookup, 00135 /// starting at the given context. 00136 /// 00137 /// \param The name of the module to look up. 00138 /// 00139 /// \param Context The module context, from which we will perform lexical 00140 /// name lookup. 00141 /// 00142 /// \returns The named module, if known; otherwise, returns null. 00143 Module *lookupModuleUnqualified(StringRef Name, Module *Context); 00144 00145 /// \brief Retrieve a module with the given name within the given context, 00146 /// using direct (qualified) name lookup. 00147 /// 00148 /// \param The name of the module to look up. 00149 /// 00150 /// \param Context The module for which we will look for a submodule. If 00151 /// null, we will look for a top-level module. 00152 /// 00153 /// \returns The named submodule, if known; otherwose, returns null. 00154 Module *lookupModuleQualified(StringRef Name, Module *Context); 00155 00156 /// \brief Find a new module or submodule, or create it if it does not already 00157 /// exist. 00158 /// 00159 /// \param Name The name of the module to find or create. 00160 /// 00161 /// \param Parent The module that will act as the parent of this submodule, 00162 /// or NULL to indicate that this is a top-level module. 00163 /// 00164 /// \param IsFramework Whether this is a framework module. 00165 /// 00166 /// \param IsExplicit Whether this is an explicit submodule. 00167 /// 00168 /// \returns The found or newly-created module, along with a boolean value 00169 /// that will be true if the module is newly-created. 00170 std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent, 00171 bool IsFramework, 00172 bool IsExplicit); 00173 00174 /// \brief Infer the contents of a framework module map from the given 00175 /// framework directory. 00176 Module *inferFrameworkModule(StringRef ModuleName, 00177 const DirectoryEntry *FrameworkDir, 00178 bool IsSystem, Module *Parent); 00179 00180 /// \brief Retrieve the module map file containing the definition of the given 00181 /// module. 00182 /// 00183 /// \param Module The module whose module map file will be returned, if known. 00184 /// 00185 /// \returns The file entry for the module map file containing the given 00186 /// module, or NULL if the module definition was inferred. 00187 const FileEntry *getContainingModuleMapFile(Module *Module); 00188 00189 /// \brief Resolve all of the unresolved exports in the given module. 00190 /// 00191 /// \param Mod The module whose exports should be resolved. 00192 /// 00193 /// \param Complain Whether to emit diagnostics for failures. 00194 /// 00195 /// \returns true if any errors were encountered while resolving exports, 00196 /// false otherwise. 00197 bool resolveExports(Module *Mod, bool Complain); 00198 00199 /// \brief Infers the (sub)module based on the given source location and 00200 /// source manager. 00201 /// 00202 /// \param Loc The location within the source that we are querying, along 00203 /// with its source manager. 00204 /// 00205 /// \returns The module that owns this source location, or null if no 00206 /// module owns this source location. 00207 Module *inferModuleFromLocation(FullSourceLoc Loc); 00208 00209 /// \brief Sets the umbrella header of the given module to the given 00210 /// header. 00211 void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader); 00212 00213 /// \brief Sets the umbrella directory of the given module to the given 00214 /// directory. 00215 void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir); 00216 00217 /// \brief Adds this header to the given module. 00218 void addHeader(Module *Mod, const FileEntry *Header); 00219 00220 /// \brief Parse the given module map file, and record any modules we 00221 /// encounter. 00222 /// 00223 /// \param File The file to be parsed. 00224 /// 00225 /// \returns true if an error occurred, false otherwise. 00226 bool parseModuleMapFile(const FileEntry *File); 00227 00228 /// \brief Dump the contents of the module map, for debugging purposes. 00229 void dump(); 00230 00231 typedef llvm::StringMap<Module *>::const_iterator module_iterator; 00232 module_iterator module_begin() const { return Modules.begin(); } 00233 module_iterator module_end() const { return Modules.end(); } 00234 }; 00235 00236 } 00237 #endif