1 | //===- ModuleMap.h - Describe the layout of modules -------------*- C++ -*-===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file defines the ModuleMap interface, which describes the layout of a |
10 | // module as it relates to headers. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_LEX_MODULEMAP_H |
15 | #define LLVM_CLANG_LEX_MODULEMAP_H |
16 | |
17 | #include "clang/Basic/LangOptions.h" |
18 | #include "clang/Basic/Module.h" |
19 | #include "clang/Basic/SourceLocation.h" |
20 | #include "llvm/ADT/ArrayRef.h" |
21 | #include "llvm/ADT/DenseMap.h" |
22 | #include "llvm/ADT/PointerIntPair.h" |
23 | #include "llvm/ADT/StringSet.h" |
24 | #include "llvm/ADT/SmallPtrSet.h" |
25 | #include "llvm/ADT/SmallVector.h" |
26 | #include "llvm/ADT/StringMap.h" |
27 | #include "llvm/ADT/StringRef.h" |
28 | #include "llvm/ADT/TinyPtrVector.h" |
29 | #include "llvm/ADT/Twine.h" |
30 | #include <ctime> |
31 | #include <memory> |
32 | #include <string> |
33 | #include <utility> |
34 | |
35 | namespace clang { |
36 | |
37 | class DiagnosticsEngine; |
38 | class DirectoryEntry; |
39 | class FileEntry; |
40 | class FileManager; |
41 | class HeaderSearch; |
42 | class SourceManager; |
43 | |
44 | /// A mechanism to observe the actions of the module map parser as it |
45 | /// reads module map files. |
46 | class ModuleMapCallbacks { |
47 | virtual void anchor(); |
48 | |
49 | public: |
50 | virtual ~ModuleMapCallbacks() = default; |
51 | |
52 | /// Called when a module map file has been read. |
53 | /// |
54 | /// \param FileStart A SourceLocation referring to the start of the file's |
55 | /// contents. |
56 | /// \param File The file itself. |
57 | /// \param IsSystem Whether this is a module map from a system include path. |
58 | virtual void moduleMapFileRead(SourceLocation FileStart, |
59 | const FileEntry &File, bool IsSystem) {} |
60 | |
61 | /// Called when a header is added during module map parsing. |
62 | /// |
63 | /// \param Filename The header file itself. |
64 | virtual void moduleMapAddHeader(StringRef Filename) {} |
65 | |
66 | /// Called when an umbrella header is added during module map parsing. |
67 | /// |
68 | /// \param FileMgr FileManager instance |
69 | /// \param Header The umbrella header to collect. |
70 | virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr, |
71 | const FileEntry *Header) {} |
72 | }; |
73 | |
74 | class ModuleMap { |
75 | SourceManager &SourceMgr; |
76 | DiagnosticsEngine &Diags; |
77 | const LangOptions &LangOpts; |
78 | const TargetInfo *Target; |
79 | HeaderSearch &HeaderInfo; |
80 | |
81 | llvm::SmallVector<std::unique_ptr<ModuleMapCallbacks>, 1> Callbacks; |
82 | |
83 | /// The directory used for Clang-supplied, builtin include headers, |
84 | /// such as "stdint.h". |
85 | const DirectoryEntry *BuiltinIncludeDir = nullptr; |
86 | |
87 | /// Language options used to parse the module map itself. |
88 | /// |
89 | /// These are always simple C language options. |
90 | LangOptions MMapLangOpts; |
91 | |
92 | /// The module that the main source file is associated with (the module |
93 | /// named LangOpts::CurrentModule, if we've loaded it). |
94 | Module *SourceModule = nullptr; |
95 | |
96 | /// Submodules of the current module that have not yet been attached to it. |
97 | /// (Ownership is transferred if/when we create an enclosing module.) |
98 | llvm::SmallVector<std::unique_ptr<Module>, 8> PendingSubmodules; |
99 | |
100 | /// The top-level modules that are known. |
101 | llvm::StringMap<Module *> Modules; |
102 | |
103 | /// Shadow modules created while building this module map. |
104 | llvm::SmallVector<Module*, 2> ShadowModules; |
105 | |
106 | /// The number of modules we have created in total. |
107 | unsigned NumCreatedModules = 0; |
108 | |
109 | /// In case a module has a export_as entry, it might have a pending link |
110 | /// name to be determined if that module is imported. |
111 | llvm::StringMap<llvm::StringSet<>> PendingLinkAsModule; |
112 | |
113 | public: |
114 | /// Use PendingLinkAsModule information to mark top level link names that |
115 | /// are going to be replaced by export_as aliases. |
116 | void resolveLinkAsDependencies(Module *Mod); |
117 | |
118 | /// Make module to use export_as as the link dependency name if enough |
119 | /// information is available or add it to a pending list otherwise. |
120 | void addLinkAsDependency(Module *Mod); |
121 | |
122 | /// Flags describing the role of a module header. |
123 | enum ModuleHeaderRole { |
124 | /// This header is normally included in the module. |
125 | NormalHeader = 0x0, |
126 | |
127 | /// This header is included but private. |
128 | PrivateHeader = 0x1, |
129 | |
130 | /// This header is part of the module (for layering purposes) but |
131 | /// should be textually included. |
132 | TextualHeader = 0x2, |
133 | |
134 | // Caution: Adding an enumerator needs other changes. |
135 | // Adjust the number of bits for KnownHeader::Storage. |
136 | // Adjust the bitfield HeaderFileInfo::HeaderRole size. |
137 | // Adjust the HeaderFileInfoTrait::ReadData streaming. |
138 | // Adjust the HeaderFileInfoTrait::EmitData streaming. |
139 | // Adjust ModuleMap::addHeader. |
140 | }; |
141 | |
142 | /// Convert a header kind to a role. Requires Kind to not be HK_Excluded. |
143 | static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind); |
144 | |
145 | /// Convert a header role to a kind. |
146 | static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role); |
147 | |
148 | /// A header that is known to reside within a given module, |
149 | /// whether it was included or excluded. |
150 | class KnownHeader { |
151 | llvm::PointerIntPair<Module *, 2, ModuleHeaderRole> Storage; |
152 | |
153 | public: |
154 | KnownHeader() : Storage(nullptr, NormalHeader) {} |
155 | KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) {} |
156 | |
157 | friend bool operator==(const KnownHeader &A, const KnownHeader &B) { |
158 | return A.Storage == B.Storage; |
159 | } |
160 | friend bool operator!=(const KnownHeader &A, const KnownHeader &B) { |
161 | return A.Storage != B.Storage; |
162 | } |
163 | |
164 | /// Retrieve the module the header is stored in. |
165 | Module *getModule() const { return Storage.getPointer(); } |
166 | |
167 | /// The role of this header within the module. |
168 | ModuleHeaderRole getRole() const { return Storage.getInt(); } |
169 | |
170 | /// Whether this header is available in the module. |
171 | bool isAvailable() const { |
172 | return getModule()->isAvailable(); |
173 | } |
174 | |
175 | /// Whether this header is accessible from the specified module. |
176 | bool isAccessibleFrom(Module *M) const { |
177 | return !(getRole() & PrivateHeader) || |
178 | (M && M->getTopLevelModule() == getModule()->getTopLevelModule()); |
179 | } |
180 | |
181 | // Whether this known header is valid (i.e., it has an |
182 | // associated module). |
183 | explicit operator bool() const { |
184 | return Storage.getPointer() != nullptr; |
185 | } |
186 | }; |
187 | |
188 | using AdditionalModMapsSet = llvm::SmallPtrSet<const FileEntry *, 1>; |
189 | |
190 | private: |
191 | friend class ModuleMapParser; |
192 | |
193 | using HeadersMap = |
194 | llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1>>; |
195 | |
196 | /// Mapping from each header to the module that owns the contents of |
197 | /// that header. |
198 | HeadersMap Headers; |
199 | |
200 | /// Map from file sizes to modules with lazy header directives of that size. |
201 | mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize; |
202 | |
203 | /// Map from mtimes to modules with lazy header directives with those mtimes. |
204 | mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>> |
205 | LazyHeadersByModTime; |
206 | |
207 | /// Mapping from directories with umbrella headers to the module |
208 | /// that is generated from the umbrella header. |
209 | /// |
210 | /// This mapping is used to map headers that haven't explicitly been named |
211 | /// in the module map over to the module that includes them via its umbrella |
212 | /// header. |
213 | llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs; |
214 | |
215 | /// A generation counter that is used to test whether modules of the |
216 | /// same name may shadow or are illegal redefinitions. |
217 | /// |
218 | /// Modules from earlier scopes may shadow modules from later ones. |
219 | /// Modules from the same scope may not have the same name. |
220 | unsigned CurrentModuleScopeID = 0; |
221 | |
222 | llvm::DenseMap<Module *, unsigned> ModuleScopeIDs; |
223 | |
224 | /// The set of attributes that can be attached to a module. |
225 | struct Attributes { |
226 | /// Whether this is a system module. |
227 | unsigned IsSystem : 1; |
228 | |
229 | /// Whether this is an extern "C" module. |
230 | unsigned IsExternC : 1; |
231 | |
232 | /// Whether this is an exhaustive set of configuration macros. |
233 | unsigned IsExhaustive : 1; |
234 | |
235 | /// Whether files in this module can only include non-modular headers |
236 | /// and headers from used modules. |
237 | unsigned NoUndeclaredIncludes : 1; |
238 | |
239 | Attributes() |
240 | : IsSystem(false), IsExternC(false), IsExhaustive(false), |
241 | NoUndeclaredIncludes(false) {} |
242 | }; |
243 | |
244 | /// A directory for which framework modules can be inferred. |
245 | struct InferredDirectory { |
246 | /// Whether to infer modules from this directory. |
247 | unsigned InferModules : 1; |
248 | |
249 | /// The attributes to use for inferred modules. |
250 | Attributes Attrs; |
251 | |
252 | /// If \c InferModules is non-zero, the module map file that allowed |
253 | /// inferred modules. Otherwise, nullptr. |
254 | const FileEntry *ModuleMapFile; |
255 | |
256 | /// The names of modules that cannot be inferred within this |
257 | /// directory. |
258 | SmallVector<std::string, 2> ExcludedModules; |
259 | |
260 | InferredDirectory() : InferModules(false) {} |
261 | }; |
262 | |
263 | /// A mapping from directories to information about inferring |
264 | /// framework modules from within those directories. |
265 | llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories; |
266 | |
267 | /// A mapping from an inferred module to the module map that allowed the |
268 | /// inference. |
269 | llvm::DenseMap<const Module *, const FileEntry *> InferredModuleAllowedBy; |
270 | |
271 | llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps; |
272 | |
273 | /// Describes whether we haved parsed a particular file as a module |
274 | /// map. |
275 | llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap; |
276 | |
277 | /// Resolve the given export declaration into an actual export |
278 | /// declaration. |
279 | /// |
280 | /// \param Mod The module in which we're resolving the export declaration. |
281 | /// |
282 | /// \param Unresolved The export declaration to resolve. |
283 | /// |
284 | /// \param Complain Whether this routine should complain about unresolvable |
285 | /// exports. |
286 | /// |
287 | /// \returns The resolved export declaration, which will have a NULL pointer |
288 | /// if the export could not be resolved. |
289 | Module::ExportDecl |
290 | resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved, |
291 | bool Complain) const; |
292 | |
293 | /// Resolve the given module id to an actual module. |
294 | /// |
295 | /// \param Id The module-id to resolve. |
296 | /// |
297 | /// \param Mod The module in which we're resolving the module-id. |
298 | /// |
299 | /// \param Complain Whether this routine should complain about unresolvable |
300 | /// module-ids. |
301 | /// |
302 | /// \returns The resolved module, or null if the module-id could not be |
303 | /// resolved. |
304 | Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const; |
305 | |
306 | /// Add an unresolved header to a module. |
307 | /// |
308 | /// \param Mod The module in which we're adding the unresolved header |
309 | /// directive. |
310 | /// \param Header The unresolved header directive. |
311 | /// \param NeedsFramework If Mod is not a framework but a missing header would |
312 | /// be found in case Mod was, set it to true. False otherwise. |
313 | void addUnresolvedHeader(Module *Mod, |
314 | Module::UnresolvedHeaderDirective Header, |
315 | bool &NeedsFramework); |
316 | |
317 | /// Look up the given header directive to find an actual header file. |
318 | /// |
319 | /// \param M The module in which we're resolving the header directive. |
320 | /// \param Header The header directive to resolve. |
321 | /// \param RelativePathName Filled in with the relative path name from the |
322 | /// module to the resolved header. |
323 | /// \param NeedsFramework If M is not a framework but a missing header would |
324 | /// be found in case M was, set it to true. False otherwise. |
325 | /// \return The resolved file, if any. |
326 | const FileEntry *findHeader(Module *M, |
327 | const Module::UnresolvedHeaderDirective &Header, |
328 | SmallVectorImpl<char> &RelativePathName, |
329 | bool &NeedsFramework); |
330 | |
331 | /// Resolve the given header directive. |
332 | /// |
333 | /// \param M The module in which we're resolving the header directive. |
334 | /// \param Header The header directive to resolve. |
335 | /// \param NeedsFramework If M is not a framework but a missing header would |
336 | /// be found in case M was, set it to true. False otherwise. |
337 | void resolveHeader(Module *M, const Module::UnresolvedHeaderDirective &Header, |
338 | bool &NeedsFramework); |
339 | |
340 | /// Attempt to resolve the specified header directive as naming a builtin |
341 | /// header. |
342 | /// \return \c true if a corresponding builtin header was found. |
343 | bool resolveAsBuiltinHeader(Module *M, |
344 | const Module::UnresolvedHeaderDirective &Header); |
345 | |
346 | /// Looks up the modules that \p File corresponds to. |
347 | /// |
348 | /// If \p File represents a builtin header within Clang's builtin include |
349 | /// directory, this also loads all of the module maps to see if it will get |
350 | /// associated with a specific module (e.g. in /usr/include). |
351 | HeadersMap::iterator findKnownHeader(const FileEntry *File); |
352 | |
353 | /// Searches for a module whose umbrella directory contains \p File. |
354 | /// |
355 | /// \param File The header to search for. |
356 | /// |
357 | /// \param IntermediateDirs On success, contains the set of directories |
358 | /// searched before finding \p File. |
359 | KnownHeader findHeaderInUmbrellaDirs(const FileEntry *File, |
360 | SmallVectorImpl<const DirectoryEntry *> &IntermediateDirs); |
361 | |
362 | /// Given that \p File is not in the Headers map, look it up within |
363 | /// umbrella directories and find or create a module for it. |
364 | KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File); |
365 | |
366 | /// A convenience method to determine if \p File is (possibly nested) |
367 | /// in an umbrella directory. |
368 | bool isHeaderInUmbrellaDirs(const FileEntry *File) { |
369 | SmallVector<const DirectoryEntry *, 2> IntermediateDirs; |
370 | return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs)); |
371 | } |
372 | |
373 | Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir, |
374 | Attributes Attrs, Module *Parent); |
375 | |
376 | public: |
377 | /// Construct a new module map. |
378 | /// |
379 | /// \param SourceMgr The source manager used to find module files and headers. |
380 | /// This source manager should be shared with the header-search mechanism, |
381 | /// since they will refer to the same headers. |
382 | /// |
383 | /// \param Diags A diagnostic engine used for diagnostics. |
384 | /// |
385 | /// \param LangOpts Language options for this translation unit. |
386 | /// |
387 | /// \param Target The target for this translation unit. |
388 | ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, |
389 | const LangOptions &LangOpts, const TargetInfo *Target, |
390 | HeaderSearch &HeaderInfo); |
391 | |
392 | /// Destroy the module map. |
393 | ~ModuleMap(); |
394 | |
395 | /// Set the target information. |
396 | void setTarget(const TargetInfo &Target); |
397 | |
398 | /// Set the directory that contains Clang-supplied include |
399 | /// files, such as our stdarg.h or tgmath.h. |
400 | void setBuiltinIncludeDir(const DirectoryEntry *Dir) { |
401 | BuiltinIncludeDir = Dir; |
402 | } |
403 | |
404 | /// Get the directory that contains Clang-supplied include files. |
405 | const DirectoryEntry *getBuiltinDir() const { |
406 | return BuiltinIncludeDir; |
407 | } |
408 | |
409 | /// Is this a compiler builtin header? |
410 | static bool isBuiltinHeader(StringRef FileName); |
411 | |
412 | /// Add a module map callback. |
413 | void addModuleMapCallbacks(std::unique_ptr<ModuleMapCallbacks> Callback) { |
414 | Callbacks.push_back(std::move(Callback)); |
415 | } |
416 | |
417 | /// Retrieve the module that owns the given header file, if any. |
418 | /// |
419 | /// \param File The header file that is likely to be included. |
420 | /// |
421 | /// \param AllowTextual If \c true and \p File is a textual header, return |
422 | /// its owning module. Otherwise, no KnownHeader will be returned if the |
423 | /// file is only known as a textual header. |
424 | /// |
425 | /// \returns The module KnownHeader, which provides the module that owns the |
426 | /// given header file. The KnownHeader is default constructed to indicate |
427 | /// that no module owns this header file. |
428 | KnownHeader findModuleForHeader(const FileEntry *File, |
429 | bool AllowTextual = false); |
430 | |
431 | /// Retrieve all the modules that contain the given header file. This |
432 | /// may not include umbrella modules, nor information from external sources, |
433 | /// if they have not yet been inferred / loaded. |
434 | /// |
435 | /// Typically, \ref findModuleForHeader should be used instead, as it picks |
436 | /// the preferred module for the header. |
437 | ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File) const; |
438 | |
439 | /// Resolve all lazy header directives for the specified file. |
440 | /// |
441 | /// This ensures that the HeaderFileInfo on HeaderSearch is up to date. This |
442 | /// is effectively internal, but is exposed so HeaderSearch can call it. |
443 | void resolveHeaderDirectives(const FileEntry *File) const; |
444 | |
445 | /// Resolve all lazy header directives for the specified module. |
446 | void resolveHeaderDirectives(Module *Mod) const; |
447 | |
448 | /// Reports errors if a module must not include a specific file. |
449 | /// |
450 | /// \param RequestingModule The module including a file. |
451 | /// |
452 | /// \param RequestingModuleIsModuleInterface \c true if the inclusion is in |
453 | /// the interface of RequestingModule, \c false if it's in the |
454 | /// implementation of RequestingModule. Value is ignored and |
455 | /// meaningless if RequestingModule is nullptr. |
456 | /// |
457 | /// \param FilenameLoc The location of the inclusion's filename. |
458 | /// |
459 | /// \param Filename The included filename as written. |
460 | /// |
461 | /// \param File The included file. |
462 | void diagnoseHeaderInclusion(Module *RequestingModule, |
463 | bool RequestingModuleIsModuleInterface, |
464 | SourceLocation FilenameLoc, StringRef Filename, |
465 | const FileEntry *File); |
466 | |
467 | /// Determine whether the given header is part of a module |
468 | /// marked 'unavailable'. |
469 | bool isHeaderInUnavailableModule(const FileEntry *Header) const; |
470 | |
471 | /// Determine whether the given header is unavailable as part |
472 | /// of the specified module. |
473 | bool isHeaderUnavailableInModule(const FileEntry *Header, |
474 | const Module *RequestingModule) const; |
475 | |
476 | /// Retrieve a module with the given name. |
477 | /// |
478 | /// \param Name The name of the module to look up. |
479 | /// |
480 | /// \returns The named module, if known; otherwise, returns null. |
481 | Module *findModule(StringRef Name) const; |
482 | |
483 | /// Retrieve a module with the given name using lexical name lookup, |
484 | /// starting at the given context. |
485 | /// |
486 | /// \param Name The name of the module to look up. |
487 | /// |
488 | /// \param Context The module context, from which we will perform lexical |
489 | /// name lookup. |
490 | /// |
491 | /// \returns The named module, if known; otherwise, returns null. |
492 | Module *lookupModuleUnqualified(StringRef Name, Module *Context) const; |
493 | |
494 | /// Retrieve a module with the given name within the given context, |
495 | /// using direct (qualified) name lookup. |
496 | /// |
497 | /// \param Name The name of the module to look up. |
498 | /// |
499 | /// \param Context The module for which we will look for a submodule. If |
500 | /// null, we will look for a top-level module. |
501 | /// |
502 | /// \returns The named submodule, if known; otherwose, returns null. |
503 | Module *lookupModuleQualified(StringRef Name, Module *Context) const; |
504 | |
505 | /// Find a new module or submodule, or create it if it does not already |
506 | /// exist. |
507 | /// |
508 | /// \param Name The name of the module to find or create. |
509 | /// |
510 | /// \param Parent The module that will act as the parent of this submodule, |
511 | /// or nullptr to indicate that this is a top-level module. |
512 | /// |
513 | /// \param IsFramework Whether this is a framework module. |
514 | /// |
515 | /// \param IsExplicit Whether this is an explicit submodule. |
516 | /// |
517 | /// \returns The found or newly-created module, along with a boolean value |
518 | /// that will be true if the module is newly-created. |
519 | std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent, |
520 | bool IsFramework, |
521 | bool IsExplicit); |
522 | |
523 | /// Create a 'global module' for a C++ Modules TS module interface unit. |
524 | /// |
525 | /// We model the global module as a submodule of the module interface unit. |
526 | /// Unfortunately, we can't create the module interface unit's Module until |
527 | /// later, because we don't know what it will be called. |
528 | Module *createGlobalModuleForInterfaceUnit(SourceLocation Loc); |
529 | |
530 | /// Create a new module for a C++ Modules TS module interface unit. |
531 | /// The module must not already exist, and will be configured for the current |
532 | /// compilation. |
533 | /// |
534 | /// Note that this also sets the current module to the newly-created module. |
535 | /// |
536 | /// \returns The newly-created module. |
537 | Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name, |
538 | Module *GlobalModule); |
539 | |
540 | /// Create a header module from the specified list of headers. |
541 | Module *createHeaderModule(StringRef Name, ArrayRef<Module::Header> Headers); |
542 | |
543 | /// Infer the contents of a framework module map from the given |
544 | /// framework directory. |
545 | Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir, |
546 | bool IsSystem, Module *Parent); |
547 | |
548 | /// Create a new top-level module that is shadowed by |
549 | /// \p ShadowingModule. |
550 | Module *createShadowedModule(StringRef Name, bool IsFramework, |
551 | Module *ShadowingModule); |
552 | |
553 | /// Creates a new declaration scope for module names, allowing |
554 | /// previously defined modules to shadow definitions from the new scope. |
555 | /// |
556 | /// \note Module names from earlier scopes will shadow names from the new |
557 | /// scope, which is the opposite of how shadowing works for variables. |
558 | void finishModuleDeclarationScope() { CurrentModuleScopeID += 1; } |
559 | |
560 | bool mayShadowNewModule(Module *ExistingModule) { |
561 | (0) . __assert_fail ("!ExistingModule->Parent && \"expected top-level module\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/ModuleMap.h", 561, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!ExistingModule->Parent && "expected top-level module"); |
562 | (0) . __assert_fail ("ModuleScopeIDs.count(ExistingModule) && \"unknown module\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/ModuleMap.h", 562, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ModuleScopeIDs.count(ExistingModule) && "unknown module"); |
563 | return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID; |
564 | } |
565 | |
566 | /// Retrieve the module map file containing the definition of the given |
567 | /// module. |
568 | /// |
569 | /// \param Module The module whose module map file will be returned, if known. |
570 | /// |
571 | /// \returns The file entry for the module map file containing the given |
572 | /// module, or nullptr if the module definition was inferred. |
573 | const FileEntry *getContainingModuleMapFile(const Module *Module) const; |
574 | |
575 | /// Get the module map file that (along with the module name) uniquely |
576 | /// identifies this module. |
577 | /// |
578 | /// The particular module that \c Name refers to may depend on how the module |
579 | /// was found in header search. However, the combination of \c Name and |
580 | /// this module map will be globally unique for top-level modules. In the case |
581 | /// of inferred modules, returns the module map that allowed the inference |
582 | /// (e.g. contained 'module *'). Otherwise, returns |
583 | /// getContainingModuleMapFile(). |
584 | const FileEntry *getModuleMapFileForUniquing(const Module *M) const; |
585 | |
586 | void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap); |
587 | |
588 | /// Get any module map files other than getModuleMapFileForUniquing(M) |
589 | /// that define submodules of a top-level module \p M. This is cheaper than |
590 | /// getting the module map file for each submodule individually, since the |
591 | /// expected number of results is very small. |
592 | AdditionalModMapsSet *getAdditionalModuleMapFiles(const Module *M) { |
593 | auto I = AdditionalModMaps.find(M); |
594 | if (I == AdditionalModMaps.end()) |
595 | return nullptr; |
596 | return &I->second; |
597 | } |
598 | |
599 | void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap) { |
600 | AdditionalModMaps[M].insert(ModuleMap); |
601 | } |
602 | |
603 | /// Resolve all of the unresolved exports in the given module. |
604 | /// |
605 | /// \param Mod The module whose exports should be resolved. |
606 | /// |
607 | /// \param Complain Whether to emit diagnostics for failures. |
608 | /// |
609 | /// \returns true if any errors were encountered while resolving exports, |
610 | /// false otherwise. |
611 | bool resolveExports(Module *Mod, bool Complain); |
612 | |
613 | /// Resolve all of the unresolved uses in the given module. |
614 | /// |
615 | /// \param Mod The module whose uses should be resolved. |
616 | /// |
617 | /// \param Complain Whether to emit diagnostics for failures. |
618 | /// |
619 | /// \returns true if any errors were encountered while resolving uses, |
620 | /// false otherwise. |
621 | bool resolveUses(Module *Mod, bool Complain); |
622 | |
623 | /// Resolve all of the unresolved conflicts in the given module. |
624 | /// |
625 | /// \param Mod The module whose conflicts should be resolved. |
626 | /// |
627 | /// \param Complain Whether to emit diagnostics for failures. |
628 | /// |
629 | /// \returns true if any errors were encountered while resolving conflicts, |
630 | /// false otherwise. |
631 | bool resolveConflicts(Module *Mod, bool Complain); |
632 | |
633 | /// Sets the umbrella header of the given module to the given |
634 | /// header. |
635 | void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, |
636 | Twine NameAsWritten); |
637 | |
638 | /// Sets the umbrella directory of the given module to the given |
639 | /// directory. |
640 | void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, |
641 | Twine NameAsWritten); |
642 | |
643 | /// Adds this header to the given module. |
644 | /// \param Role The role of the header wrt the module. |
645 | void addHeader(Module *Mod, Module::Header Header, |
646 | ModuleHeaderRole Role, bool Imported = false); |
647 | |
648 | /// Marks this header as being excluded from the given module. |
649 | void excludeHeader(Module *Mod, Module::Header Header); |
650 | |
651 | /// Parse the given module map file, and record any modules we |
652 | /// encounter. |
653 | /// |
654 | /// \param File The file to be parsed. |
655 | /// |
656 | /// \param IsSystem Whether this module map file is in a system header |
657 | /// directory, and therefore should be considered a system module. |
658 | /// |
659 | /// \param HomeDir The directory in which relative paths within this module |
660 | /// map file will be resolved. |
661 | /// |
662 | /// \param ID The FileID of the file to process, if we've already entered it. |
663 | /// |
664 | /// \param Offset [inout] On input the offset at which to start parsing. On |
665 | /// output, the offset at which the module map terminated. |
666 | /// |
667 | /// \param ExternModuleLoc The location of the "extern module" declaration |
668 | /// that caused us to load this module map file, if any. |
669 | /// |
670 | /// \returns true if an error occurred, false otherwise. |
671 | bool parseModuleMapFile(const FileEntry *File, bool IsSystem, |
672 | const DirectoryEntry *HomeDir, |
673 | FileID ID = FileID(), unsigned *Offset = nullptr, |
674 | SourceLocation ExternModuleLoc = SourceLocation()); |
675 | |
676 | /// Dump the contents of the module map, for debugging purposes. |
677 | void dump(); |
678 | |
679 | using module_iterator = llvm::StringMap<Module *>::const_iterator; |
680 | |
681 | module_iterator module_begin() const { return Modules.begin(); } |
682 | module_iterator module_end() const { return Modules.end(); } |
683 | }; |
684 | |
685 | } // namespace clang |
686 | |
687 | #endif // LLVM_CLANG_LEX_MODULEMAP_H |
688 |