1 //===--- ModuleMap.h - Describe the layout of modules -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ModuleMap interface, which describes the layout of a
11 // module as it relates to headers.
13 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_LEX_MODULEMAP_H
17 #define LLVM_CLANG_LEX_MODULEMAP_H
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"
34 class DiagnosticConsumer;
35 class DiagnosticsEngine;
36 class ModuleMapParser;
39 SourceManager *SourceMgr;
40 IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
41 const LangOptions &LangOpts;
42 const TargetInfo *Target;
44 /// \brief The directory used for Clang-supplied, builtin include headers,
45 /// such as "stdint.h".
46 const DirectoryEntry *BuiltinIncludeDir;
48 /// \brief Language options used to parse the module map itself.
50 /// These are always simple C language options.
51 LangOptions MMapLangOpts;
53 /// \brief The top-level modules that are known.
54 llvm::StringMap<Module *> Modules;
56 /// \brief Mapping from each header to the module that owns the contents of the
58 llvm::DenseMap<const FileEntry *, Module *> Headers;
60 /// \brief Mapping from directories with umbrella headers to the module
61 /// that is generated from the umbrella header.
63 /// This mapping is used to map headers that haven't explicitly been named
64 /// in the module map over to the module that includes them via its umbrella
66 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
68 friend class ModuleMapParser;
70 /// \brief Resolve the given export declaration into an actual export
73 /// \param Mod The module in which we're resolving the export declaration.
75 /// \param Unresolved The export declaration to resolve.
77 /// \param Complain Whether this routine should complain about unresolvable
80 /// \returns The resolved export declaration, which will have a NULL pointer
81 /// if the export could not be resolved.
83 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,
87 /// \brief Construct a new module map.
89 /// \param FileMgr The file manager used to find module files and headers.
90 /// This file manager should be shared with the header-search mechanism, since
91 /// they will refer to the same headers.
93 /// \param DC A diagnostic consumer that will be cloned for use in generating
96 /// \param LangOpts Language options for this translation unit.
98 /// \param Target The target for this translation unit.
99 ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC,
100 const LangOptions &LangOpts, const TargetInfo *Target);
102 /// \brief Destroy the module map.
106 /// \brief Set the target information.
107 void setTarget(const TargetInfo &Target);
109 /// \brief Set the directory that contains Clang-supplied include
110 /// files, such as our stdarg.h or tgmath.h.
111 void setBuiltinIncludeDir(const DirectoryEntry *Dir) {
112 BuiltinIncludeDir = Dir;
115 /// \brief Retrieve the module that owns the given header file, if any.
117 /// \param File The header file that is likely to be included.
119 /// \returns The module that owns the given header file, or null to indicate
120 /// that no module owns this header file.
121 Module *findModuleForHeader(const FileEntry *File);
123 /// \brief Determine whether the given header is part of a module
124 /// marked 'unavailable'.
125 bool isHeaderInUnavailableModule(const FileEntry *Header);
127 /// \brief Retrieve a module with the given name.
129 /// \param The name of the module to look up.
131 /// \returns The named module, if known; otherwise, returns null.
132 Module *findModule(StringRef Name);
134 /// \brief Retrieve a module with the given name using lexical name lookup,
135 /// starting at the given context.
137 /// \param The name of the module to look up.
139 /// \param Context The module context, from which we will perform lexical
142 /// \returns The named module, if known; otherwise, returns null.
143 Module *lookupModuleUnqualified(StringRef Name, Module *Context);
145 /// \brief Retrieve a module with the given name within the given context,
146 /// using direct (qualified) name lookup.
148 /// \param The name of the module to look up.
150 /// \param Context The module for which we will look for a submodule. If
151 /// null, we will look for a top-level module.
153 /// \returns The named submodule, if known; otherwose, returns null.
154 Module *lookupModuleQualified(StringRef Name, Module *Context);
156 /// \brief Find a new module or submodule, or create it if it does not already
159 /// \param Name The name of the module to find or create.
161 /// \param Parent The module that will act as the parent of this submodule,
162 /// or NULL to indicate that this is a top-level module.
164 /// \param IsFramework Whether this is a framework module.
166 /// \param IsExplicit Whether this is an explicit submodule.
168 /// \returns The found or newly-created module, along with a boolean value
169 /// that will be true if the module is newly-created.
170 std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
174 /// \brief Infer the contents of a framework module map from the given
175 /// framework directory.
176 Module *inferFrameworkModule(StringRef ModuleName,
177 const DirectoryEntry *FrameworkDir,
178 bool IsSystem, Module *Parent);
180 /// \brief Retrieve the module map file containing the definition of the given
183 /// \param Module The module whose module map file will be returned, if known.
185 /// \returns The file entry for the module map file containing the given
186 /// module, or NULL if the module definition was inferred.
187 const FileEntry *getContainingModuleMapFile(Module *Module);
189 /// \brief Resolve all of the unresolved exports in the given module.
191 /// \param Mod The module whose exports should be resolved.
193 /// \param Complain Whether to emit diagnostics for failures.
195 /// \returns true if any errors were encountered while resolving exports,
197 bool resolveExports(Module *Mod, bool Complain);
199 /// \brief Infers the (sub)module based on the given source location and
202 /// \param Loc The location within the source that we are querying, along
203 /// with its source manager.
205 /// \returns The module that owns this source location, or null if no
206 /// module owns this source location.
207 Module *inferModuleFromLocation(FullSourceLoc Loc);
209 /// \brief Sets the umbrella header of the given module to the given
211 void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader);
213 /// \brief Sets the umbrella directory of the given module to the given
215 void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir);
217 /// \brief Adds this header to the given module.
218 void addHeader(Module *Mod, const FileEntry *Header);
220 /// \brief Parse the given module map file, and record any modules we
223 /// \param File The file to be parsed.
225 /// \returns true if an error occurred, false otherwise.
226 bool parseModuleMapFile(const FileEntry *File);
228 /// \brief Dump the contents of the module map, for debugging purposes.
231 typedef llvm::StringMap<Module *>::const_iterator module_iterator;
232 module_iterator module_begin() const { return Modules.begin(); }
233 module_iterator module_end() const { return Modules.end(); }