Lines Matching full:module
10 // module as it relates to headers.
19 #include "clang/Basic/Module.h"
46 /// A mechanism to observe the actions of the module map parser as it
47 /// reads module map files.
54 /// Called when a module map file has been read.
59 /// \param IsSystem Whether this is a module map from a system include path.
63 /// Called when a header is added during module map parsing.
68 /// Called when an umbrella header is added during module map parsing.
87 /// Language options used to parse the module map itself.
92 /// The module that the main source file is associated with (the module
94 Module *SourceModule = nullptr;
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;
101 llvm::StringMap<Module *> Modules;
103 /// Module loading cache that includes submodules, indexed by IdentifierInfo.
105 llvm::DenseMap<const IdentifierInfo *, Module *> CachedModuleLoads;
107 /// Shadow modules created while building this module map.
108 llvm::SmallVector<Module*, 2> ShadowModules;
113 /// In case a module has a export_as entry, it might have a pending link
114 /// name to be determined if that module is imported.
120 void resolveLinkAsDependencies(Module *Mod);
122 /// Make module to use export_as as the link dependency name if enough
124 void addLinkAsDependency(Module *Mod);
126 /// Flags describing the role of a module header.
128 /// This header is normally included in the module.
134 /// This header is part of the module (for layering purposes) but
138 /// This header is explicitly excluded from the module.
149 static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind);
152 static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role);
157 /// A header that is known to reside within a given module,
160 llvm::PointerIntPair<Module *, 3, ModuleHeaderRole> Storage;
164 KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) {}
173 /// Retrieve the module the header is stored in.
174 Module *getModule() const { return Storage.getPointer(); }
176 /// The role of this header within the module.
179 /// Whether this header is available in the module.
184 /// Whether this header is accessible from the specified module.
185 bool isAccessibleFrom(Module *M) const {
191 // associated module).
204 /// Mapping from each header to the module that owns the contents of
209 mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;
212 mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>
215 /// Mapping from directories with umbrella headers to the module
219 /// in the module map over to the module that includes them via its umbrella
221 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
230 llvm::DenseMap<Module *, unsigned> ModuleScopeIDs;
232 /// The set of attributes that can be attached to a module.
234 /// Whether this is a system module.
238 /// Whether this is an extern "C" module.
246 /// Whether files in this module can only include non-modular headers
265 /// If \c InferModules is non-zero, the module map file that allowed
280 /// A mapping from an inferred module to the module map that allowed the
282 llvm::DenseMap<const Module *, FileID> InferredModuleAllowedBy;
284 llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
286 /// Describes whether we haved parsed a particular file as a module
293 /// \param Mod The module in which we're resolving the export declaration.
302 Module::ExportDecl
303 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,
306 /// Resolve the given module id to an actual module.
308 /// \param Id The module-id to resolve.
310 /// \param Mod The module in which we're resolving the module-id.
313 /// module-ids.
315 /// \returns The resolved module, or null if the module-id could not be
317 Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const;
319 /// Add an unresolved header to a module.
321 /// \param Mod The module in which we're adding the unresolved header
326 void addUnresolvedHeader(Module *Mod,
327 Module::UnresolvedHeaderDirective Header,
332 /// \param M The module in which we're resolving the header directive.
335 /// module to the resolved header.
340 findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
345 /// \param M The module in which we're resolving the header directive.
349 void resolveHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
355 bool resolveAsBuiltinHeader(Module *M,
356 const Module::UnresolvedHeaderDirective &Header);
361 /// directory, this also loads all of the module maps to see if it will get
362 /// associated with a specific module (e.g. in /usr/include).
365 /// Searches for a module whose umbrella directory contains \p File.
375 /// umbrella directories and find or create a module for it.
385 Module *inferFrameworkModule(DirectoryEntryRef FrameworkDir, Attributes Attrs,
386 Module *Parent);
389 /// Construct a new module map.
391 /// \param SourceMgr The source manager used to find module files and headers.
404 /// Destroy the module map.
421 Module *Module) const;
423 /// Add a module map callback.
428 /// Retrieve the module that owns the given header file, if any. Note that
429 /// this does not implicitly load module maps, except for builtin headers,
436 /// its owning module. Otherwise, no KnownHeader will be returned if the
439 /// \returns The module KnownHeader, which provides the module that owns the
441 /// that no module owns this header file.
446 /// this does not implicitly load module maps, except for builtin headers,
451 /// the preferred module for the header.
454 /// Like \ref findAllModulesForHeader, but do not attempt to infer module
464 /// Resolve lazy header directives for the specified module. If File is
467 void resolveHeaderDirectives(Module *Mod,
470 /// Reports errors if a module must not include a specific file.
472 /// \param RequestingModule The module including a file.
484 void diagnoseHeaderInclusion(Module *RequestingModule,
489 /// Determine whether the given header is part of a module
494 /// of the specified module.
496 const Module *RequestingModule) const;
498 /// Retrieve a module with the given name.
500 /// \param Name The name of the module to look up.
502 /// \returns The named module, if known; otherwise, returns null.
503 Module *findModule(StringRef Name) const;
505 /// Retrieve a module with the given name using lexical name lookup,
508 /// \param Name The name of the module to look up.
510 /// \param Context The module context, from which we will perform lexical
513 /// \returns The named module, if known; otherwise, returns null.
514 Module *lookupModuleUnqualified(StringRef Name, Module *Context) const;
516 /// Retrieve a module with the given name within the given context,
519 /// \param Name The name of the module to look up.
521 /// \param Context The module for which we will look for a submodule. If
522 /// null, we will look for a top-level module.
525 Module *lookupModuleQualified(StringRef Name, Module *Context) const;
527 /// Find a new module or submodule, or create it if it does not already
530 /// \param Name The name of the module to find or create.
532 /// \param Parent The module that will act as the parent of this submodule,
533 /// or nullptr to indicate that this is a top-level module.
535 /// \param IsFramework Whether this is a framework module.
539 /// \returns The found or newly-created module, along with a boolean value
540 /// that will be true if the module is newly-created.
541 std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
545 /// Create a global module fragment for a C++ module unit.
547 /// We model the global module fragment as a submodule of the module
548 /// interface unit. Unfortunately, we can't create the module interface
549 /// unit's Module until later, because we don't know what it will be called
550 /// usually. See C++20 [module.unit]/7.2 for the case we could know its
552 Module *createGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
553 Module *Parent = nullptr);
554 Module *createImplicitGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
555 Module *Parent);
557 /// Create a global module fragment for a C++ module interface unit.
558 Module *createPrivateModuleFragmentForInterfaceUnit(Module *Parent,
561 /// Create a new C++ module with the specified kind, and reparent any pending
562 /// global module fragment(s) to it.
563 Module *createModuleUnitWithKind(SourceLocation Loc, StringRef Name,
564 Module::ModuleKind Kind);
566 /// Create a new module for a C++ module interface unit.
567 /// The module must not already exist, and will be configured for the current
570 /// Note that this also sets the current module to the newly-created module.
572 /// \returns The newly-created module.
573 Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name);
575 /// Create a new module for a C++ module implementation unit.
576 /// The interface module for this implementation (implicitly imported) must
579 /// \returns The newly-created module.
580 Module *createModuleForImplementationUnit(SourceLocation Loc, StringRef Name);
583 Module *createHeaderUnit(SourceLocation Loc, StringRef Name,
584 Module::Header H);
586 /// Infer the contents of a framework module map from the given
588 Module *inferFrameworkModule(DirectoryEntryRef FrameworkDir, bool IsSystem,
589 Module *Parent);
591 /// Create a new top-level module that is shadowed by
593 Module *createShadowedModule(StringRef Name, bool IsFramework,
594 Module *ShadowingModule);
596 /// Creates a new declaration scope for module names, allowing
599 /// \note Module names from earlier scopes will shadow names from the new
603 bool mayShadowNewModule(Module *ExistingModule) {
604 assert(!ExistingModule->Parent && "expected top-level module");
605 assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");
609 /// Check whether a framework module can be inferred in the given directory.
615 /// Retrieve the module map file containing the definition of the given
616 /// module.
618 /// \param Module The module whose module map file will be returned, if known.
620 /// \returns The FileID for the module map file containing the given module,
621 /// invalid if the module definition was inferred.
622 FileID getContainingModuleMapFileID(const Module *Module) const;
623 OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const;
625 /// Get the module map file that (along with the module name) uniquely
626 /// identifies this module.
628 /// The particular module that \c Name refers to may depend on how the module
630 /// this module map will be globally unique for top-level modules. In the case
631 /// of inferred modules, returns the module map that allowed the inference
632 /// (e.g. contained 'module *'). Otherwise, returns
634 FileID getModuleMapFileIDForUniquing(const Module *M) const;
635 OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const;
637 void setInferredModuleAllowedBy(Module *M, FileID ModMapFID);
639 /// Canonicalize \p Path in a manner suitable for a module map file. In
648 /// Get any module map files other than getModuleMapFileForUniquing(M)
649 /// that define submodules of a top-level module \p M. This is cheaper than
650 /// getting the module map file for each submodule individually, since the
652 AdditionalModMapsSet *getAdditionalModuleMapFiles(const Module *M) {
659 void addAdditionalModuleMapFile(const Module *M, FileEntryRef ModuleMap);
661 /// Resolve all of the unresolved exports in the given module.
663 /// \param Mod The module whose exports should be resolved.
669 bool resolveExports(Module *Mod, bool Complain);
671 /// Resolve all of the unresolved uses in the given module.
673 /// \param Mod The module whose uses should be resolved.
679 bool resolveUses(Module *Mod, bool Complain);
681 /// Resolve all of the unresolved conflicts in the given module.
683 /// \param Mod The module whose conflicts should be resolved.
689 bool resolveConflicts(Module *Mod, bool Complain);
691 /// Sets the umbrella header of the given module to the given header.
693 setUmbrellaHeaderAsWritten(Module *Mod, FileEntryRef UmbrellaHeader,
697 /// Sets the umbrella directory of the given module to the given directory.
698 void setUmbrellaDirAsWritten(Module *Mod, DirectoryEntryRef UmbrellaDir,
702 /// Adds this header to the given module.
703 /// \param Role The role of the header wrt the module.
704 void addHeader(Module *Mod, Module::Header Header,
707 /// Parse the given module map file, and record any modules we
712 /// \param IsSystem Whether this module map file is in a system header
713 /// directory, and therefore should be considered a system module.
715 /// \param HomeDir The directory in which relative paths within this module
721 /// output, the offset at which the module map terminated.
723 /// \param ExternModuleLoc The location of the "extern module" declaration
724 /// that caused us to load this module map file, if any.
732 /// Dump the contents of the module map, for debugging purposes.
735 using module_iterator = llvm::StringMap<Module *>::const_iterator;
743 /// Cache a module load. M might be nullptr.
744 void cacheModuleLoad(const IdentifierInfo &II, Module *M) {
748 /// Return a cached module load.
749 std::optional<Module *> getCachedModuleLoad(const IdentifierInfo &II) {