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;
97 llvm::SpecificBumpPtrAllocator<Module> ModulesAlloc;
99 /// Submodules of the current module that have not yet been attached to it.
100 /// (Relationship is set up if/when we create an enclosing module.)
101 llvm::SmallVector<Module *, 8> PendingSubmodules;
104 llvm::StringMap<Module *> Modules;
106 /// Module loading cache that includes submodules, indexed by IdentifierInfo.
108 llvm::DenseMap<const IdentifierInfo *, Module *> CachedModuleLoads;
110 /// Shadow modules created while building this module map.
111 llvm::SmallVector<Module*, 2> ShadowModules;
116 /// In case a module has a export_as entry, it might have a pending link
117 /// name to be determined if that module is imported.
123 void resolveLinkAsDependencies(Module *Mod);
125 /// Make module to use export_as as the link dependency name if enough
127 void addLinkAsDependency(Module *Mod);
129 /// Flags describing the role of a module header.
131 /// This header is normally included in the module.
137 /// This header is part of the module (for layering purposes) but
141 /// This header is explicitly excluded from the module.
152 static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind);
155 static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role);
160 /// A header that is known to reside within a given module,
163 llvm::PointerIntPair<Module *, 3, ModuleHeaderRole> Storage;
167 KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) {}
176 /// Retrieve the module the header is stored in.
177 Module *getModule() const { return Storage.getPointer(); }
179 /// The role of this header within the module.
182 /// Whether this header is available in the module.
187 /// Whether this header is accessible from the specified module.
188 bool isAccessibleFrom(Module *M) const {
194 // associated module).
207 /// Mapping from each header to the module that owns the contents of
212 mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;
215 mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>
218 /// Mapping from directories with umbrella headers to the module
222 /// in the module map over to the module that includes them via its umbrella
224 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
233 llvm::DenseMap<Module *, unsigned> ModuleScopeIDs;
235 /// The set of attributes that can be attached to a module.
237 /// Whether this is a system module.
241 /// Whether this is an extern "C" module.
249 /// Whether files in this module can only include non-modular headers
268 /// If \c InferModules is non-zero, the module map file that allowed
283 /// A mapping from an inferred module to the module map that allowed the
285 llvm::DenseMap<const Module *, FileID> InferredModuleAllowedBy;
287 llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
289 /// Describes whether we haved parsed a particular file as a module
296 /// \param Mod The module in which we're resolving the export declaration.
305 Module::ExportDecl
306 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,
309 /// Resolve the given module id to an actual module.
311 /// \param Id The module-id to resolve.
313 /// \param Mod The module in which we're resolving the module-id.
316 /// module-ids.
318 /// \returns The resolved module, or null if the module-id could not be
320 Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const;
322 /// Add an unresolved header to a module.
324 /// \param Mod The module in which we're adding the unresolved header
329 void addUnresolvedHeader(Module *Mod,
330 Module::UnresolvedHeaderDirective Header,
335 /// \param M The module in which we're resolving the header directive.
338 /// module to the resolved header.
343 findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
348 /// \param M The module in which we're resolving the header directive.
352 void resolveHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
358 bool resolveAsBuiltinHeader(Module *M,
359 const Module::UnresolvedHeaderDirective &Header);
364 /// directory, this also loads all of the module maps to see if it will get
365 /// associated with a specific module (e.g. in /usr/include).
368 /// Searches for a module whose umbrella directory contains \p File.
378 /// umbrella directories and find or create a module for it.
388 Module *inferFrameworkModule(DirectoryEntryRef FrameworkDir, Attributes Attrs,
389 Module *Parent);
392 /// Construct a new module map.
394 /// \param SourceMgr The source manager used to find module files and headers.
407 /// Destroy the module map.
424 Module *Module) const;
426 /// Add a module map callback.
431 /// Retrieve the module that owns the given header file, if any. Note that
432 /// this does not implicitly load module maps, except for builtin headers,
439 /// its owning module. Otherwise, no KnownHeader will be returned if the
442 /// \returns The module KnownHeader, which provides the module that owns the
444 /// that no module owns this header file.
449 /// this does not implicitly load module maps, except for builtin headers,
454 /// the preferred module for the header.
457 /// Like \ref findAllModulesForHeader, but do not attempt to infer module
467 /// Resolve lazy header directives for the specified module. If File is
470 void resolveHeaderDirectives(Module *Mod,
473 /// Reports errors if a module must not include a specific file.
475 /// \param RequestingModule The module including a file.
487 void diagnoseHeaderInclusion(Module *RequestingModule,
492 /// Determine whether the given header is part of a module
497 /// of the specified module.
499 const Module *RequestingModule) const;
501 /// Retrieve a module with the given name.
503 /// \param Name The name of the module to look up.
505 /// \returns The named module, if known; otherwise, returns null.
506 Module *findModule(StringRef Name) const;
508 Module *findOrInferSubmodule(Module *Parent, StringRef Name);
510 /// Retrieve a module with the given name using lexical name lookup,
513 /// \param Name The name of the module to look up.
515 /// \param Context The module context, from which we will perform lexical
518 /// \returns The named module, if known; otherwise, returns null.
519 Module *lookupModuleUnqualified(StringRef Name, Module *Context) const;
521 /// Retrieve a module with the given name within the given context,
524 /// \param Name The name of the module to look up.
526 /// \param Context The module for which we will look for a submodule. If
527 /// null, we will look for a top-level module.
530 Module *lookupModuleQualified(StringRef Name, Module *Context) const;
532 /// Find a new module or submodule, or create it if it does not already
535 /// \param Name The name of the module to find or create.
537 /// \param Parent The module that will act as the parent of this submodule,
538 /// or nullptr to indicate that this is a top-level module.
540 /// \param IsFramework Whether this is a framework module.
544 /// \returns The found or newly-created module, along with a boolean value
545 /// that will be true if the module is newly-created.
546 std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
550 /// whether the module was found or created.
551 Module *findOrCreateModuleFirst(StringRef Name, Module *Parent,
558 Module *createModule(StringRef Name, Module *Parent, bool IsFramework,
561 /// Create a global module fragment for a C++ module unit.
563 /// We model the global module fragment as a submodule of the module
564 /// interface unit. Unfortunately, we can't create the module interface
565 /// unit's Module until later, because we don't know what it will be called
566 /// usually. See C++20 [module.unit]/7.2 for the case we could know its
568 Module *createGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
569 Module *Parent = nullptr);
570 Module *createImplicitGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
571 Module *Parent);
573 /// Create a global module fragment for a C++ module interface unit.
574 Module *createPrivateModuleFragmentForInterfaceUnit(Module *Parent,
577 /// Create a new C++ module with the specified kind, and reparent any pending
578 /// global module fragment(s) to it.
579 Module *createModuleUnitWithKind(SourceLocation Loc, StringRef Name,
580 Module::ModuleKind Kind);
582 /// Create a new module for a C++ module interface unit.
583 /// The module must not already exist, and will be configured for the current
586 /// Note that this also sets the current module to the newly-created module.
588 /// \returns The newly-created module.
589 Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name);
591 /// Create a new module for a C++ module implementation unit.
592 /// The interface module for this implementation (implicitly imported) must
595 /// \returns The newly-created module.
596 Module *createModuleForImplementationUnit(SourceLocation Loc, StringRef Name);
599 Module *createHeaderUnit(SourceLocation Loc, StringRef Name,
600 Module::Header H);
602 /// Infer the contents of a framework module map from the given
604 Module *inferFrameworkModule(DirectoryEntryRef FrameworkDir, bool IsSystem,
605 Module *Parent);
607 /// Create a new top-level module that is shadowed by
609 Module *createShadowedModule(StringRef Name, bool IsFramework,
610 Module *ShadowingModule);
612 /// Creates a new declaration scope for module names, allowing
615 /// \note Module names from earlier scopes will shadow names from the new
619 bool mayShadowNewModule(Module *ExistingModule) {
620 assert(!ExistingModule->Parent && "expected top-level module");
621 assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");
625 /// Check whether a framework module can be inferred in the given directory.
631 /// Retrieve the module map file containing the definition of the given
632 /// module.
634 /// \param Module The module whose module map file will be returned, if known.
636 /// \returns The FileID for the module map file containing the given module,
637 /// invalid if the module definition was inferred.
638 FileID getContainingModuleMapFileID(const Module *Module) const;
639 OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const;
641 /// Get the module map file that (along with the module name) uniquely
642 /// identifies this module.
644 /// The particular module that \c Name refers to may depend on how the module
646 /// this module map will be globally unique for top-level modules. In the case
647 /// of inferred modules, returns the module map that allowed the inference
648 /// (e.g. contained 'module *'). Otherwise, returns
650 FileID getModuleMapFileIDForUniquing(const Module *M) const;
651 OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const;
653 void setInferredModuleAllowedBy(Module *M, FileID ModMapFID);
655 /// Canonicalize \p Path in a manner suitable for a module map file. In
664 /// Get any module map files other than getModuleMapFileForUniquing(M)
665 /// that define submodules of a top-level module \p M. This is cheaper than
666 /// getting the module map file for each submodule individually, since the
668 AdditionalModMapsSet *getAdditionalModuleMapFiles(const Module *M) {
675 void addAdditionalModuleMapFile(const Module *M, FileEntryRef ModuleMap);
677 /// Resolve all of the unresolved exports in the given module.
679 /// \param Mod The module whose exports should be resolved.
685 bool resolveExports(Module *Mod, bool Complain);
687 /// Resolve all of the unresolved uses in the given module.
689 /// \param Mod The module whose uses should be resolved.
695 bool resolveUses(Module *Mod, bool Complain);
697 /// Resolve all of the unresolved conflicts in the given module.
699 /// \param Mod The module whose conflicts should be resolved.
705 bool resolveConflicts(Module *Mod, bool Complain);
707 /// Sets the umbrella header of the given module to the given header.
709 setUmbrellaHeaderAsWritten(Module *Mod, FileEntryRef UmbrellaHeader,
713 /// Sets the umbrella directory of the given module to the given directory.
714 void setUmbrellaDirAsWritten(Module *Mod, DirectoryEntryRef UmbrellaDir,
718 /// Adds this header to the given module.
719 /// \param Role The role of the header wrt the module.
720 void addHeader(Module *Mod, Module::Header Header,
723 /// Parse the given module map file, and record any modules we
728 /// \param IsSystem Whether this module map file is in a system header
729 /// directory, and therefore should be considered a system module.
731 /// \param HomeDir The directory in which relative paths within this module
737 /// output, the offset at which the module map terminated.
739 /// \param ExternModuleLoc The location of the "extern module" declaration
740 /// that caused us to load this module map file, if any.
748 /// Dump the contents of the module map, for debugging purposes.
751 using module_iterator = llvm::StringMap<Module *>::const_iterator;
759 /// Cache a module load. M might be nullptr.
760 void cacheModuleLoad(const IdentifierInfo &II, Module *M) {
764 /// Return a cached module load.
765 std::optional<Module *> getCachedModuleLoad(const IdentifierInfo &II) {