clang 24.0.0git
Module.h
Go to the documentation of this file.
1//===- Module.h - Describe a module -----------------------------*- 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/// \file
10/// Defines the clang::Module class, which describes a module in the
11/// source code.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_MODULE_H
16#define LLVM_CLANG_BASIC_MODULE_H
17
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseSet.h"
23#include "llvm/ADT/PointerIntPair.h"
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/SetVector.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/ADT/StringMap.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/ADT/iterator_range.h"
30#include <array>
31#include <cassert>
32#include <cstdint>
33#include <ctime>
34#include <iterator>
35#include <optional>
36#include <string>
37#include <utility>
38#include <variant>
39#include <vector>
40
41namespace llvm {
42
43class raw_ostream;
44
45} // namespace llvm
46
47namespace clang {
48
49class FileManager;
50class LangOptions;
51class Module;
52class ModuleMap;
53class TargetInfo;
54
55/// Interface for on-demand deserialization of submodules stored in a PCM file.
57public:
58 virtual Module *getSubmodule(uint32_t GlobalID) = 0;
59 virtual ~ExternalSubmoduleSource() = default;
60};
61
62/// Describes the name of a module.
64
65/// Deduplication key for a loaded module file in \c ModuleManager.
66///
67/// For implicitly-built modules, this is a pointer representing the module
68/// cache directory and the module file name with the (optional) context hash.
69/// This enables using inode-based canonicalization of the user-provided module
70/// cache path without hitting issues on file systems that recycle inodes for
71/// recompiled module files.
72///
73/// For explicitly-built modules, this is \c FileEntry.
74/// This uses \c FileManager's inode-based canonicalization of the user-provided
75/// module file path. Because input explicitly-built modules do not change
76/// during the lifetime of the compiler, inode recycling is not of concern here.
77///
78/// For in-memory modules, this is the \c MemoryBuffer in InMemoryModuleCache.
80 /// The entity used for deduplication.
81 const void *Ptr;
82 /// The path relative to the module cache path for implicit module file, empty
83 /// for other kinds of module files.
84 std::string ImplicitModulePathSuffix;
85
86 friend llvm::DenseMapInfo<ModuleFileKey>;
87
88public:
89 ModuleFileKey(const void *ModuleFile) : Ptr(ModuleFile) {}
90
91 ModuleFileKey(const void *ModuleCacheDir, StringRef PathSuffix)
92 : Ptr(ModuleCacheDir), ImplicitModulePathSuffix(PathSuffix) {}
93
94 bool operator==(const ModuleFileKey &Other) const {
95 return Ptr == Other.Ptr &&
96 ImplicitModulePathSuffix == Other.ImplicitModulePathSuffix;
97 }
98
99 bool operator!=(const ModuleFileKey &Other) const {
100 return !operator==(Other);
101 }
102};
103
104/// Identifies a module file to be loaded.
105///
106/// For implicitly-built module files, the path is split into the module cache
107/// path and the module file name with the (optional) context hash. For all
108/// other types of module files, this is just the file system path.
110 enum Kind : unsigned {
111 InMemory = 0,
112 Explicit = 1,
113 ImplicitSuffixLength,
114 };
115
116 std::string Path;
117 /// The kind of the module file (\c Kind), or the length of the implicit
118 /// module file name suffix in \c Path (integer values 2+).
119 Kind KindOrSuffixLength;
120
121public:
122 /// Creates an empty module file name.
123 ModuleFileName() = default;
124
125 /// Creates a file name from the raw kind value.
126 static ModuleFileName makeFromRaw(StringRef Name, unsigned RawKind) {
128 File.Path = Name;
129 File.KindOrSuffixLength = static_cast<Kind>(RawKind);
130 return File;
131 }
132
133 /// Creates a file name for an in-memory module.
134 static ModuleFileName makeInMemory(StringRef Name) {
136 File.Path = Name;
137 File.KindOrSuffixLength = InMemory;
138 return File;
139 }
140
141 /// Creates a file name for an explicit module.
142 static ModuleFileName makeExplicit(std::string Name) {
144 File.Path = std::move(Name);
145 File.KindOrSuffixLength = Explicit;
146 return File;
147 }
148
149 /// Creates a file name for an explicit module.
150 static ModuleFileName makeExplicit(StringRef Name) {
151 return makeExplicit(Name.str());
152 }
153
154 /// Creates a file name for an implicit module.
155 static ModuleFileName makeImplicit(std::string Name, unsigned SuffixLength) {
156 assert(SuffixLength >= 2 && "Invalid suffix for implicit module file name");
157 assert(SuffixLength <= Name.size() &&
158 "Suffix for implicit module file name out-of-bounds");
160 File.Path = std::move(Name);
161 File.KindOrSuffixLength = static_cast<Kind>(SuffixLength);
162 return File;
163 }
164
165 /// Creates a file name for an implicit module.
166 static ModuleFileName makeImplicit(StringRef Name, unsigned SuffixLength) {
167 return makeImplicit(Name.str(), SuffixLength);
168 }
169
170 /// Returns the suffix length for an implicit module name, zero otherwise.
172 switch (KindOrSuffixLength) {
173 case InMemory:
174 case Explicit:
175 return 0;
176 default:
177 return KindOrSuffixLength;
178 }
179 }
180
181 /// Returns \c true iff this is an in-memory module file, \c false otherwise.
182 bool isInMemory() const { return KindOrSuffixLength == InMemory; }
183
184 /// Returns the raw value representing the kind of the module file.
185 unsigned getRawKind() const { return KindOrSuffixLength; }
186
187 /// Returns the plain module file name.
188 StringRef str() const { return Path; }
189
190 /// Converts to StringRef representing the plain module file name.
191 operator StringRef() const { return Path; }
192
193 /// Checks whether the module file name is empty.
194 bool empty() const { return Path.empty(); }
195};
196
197/// The signature of a module, which is a hash of the AST content.
198struct ASTFileSignature : std::array<uint8_t, 20> {
199 using BaseT = std::array<uint8_t, 20>;
200
201 static constexpr size_t size = std::tuple_size<BaseT>::value;
202
203 ASTFileSignature(BaseT S = {{0}}) : BaseT(std::move(S)) {}
204
205 explicit operator bool() const { return *this != BaseT({{0}}); }
206
207 // Support implicit cast to ArrayRef. Note that ASTFileSignature::size
208 // prevents implicit cast to ArrayRef because one of the implicit constructors
209 // of ArrayRef requires access to BaseT::size.
210 operator ArrayRef<uint8_t>() const { return ArrayRef<uint8_t>(data(), size); }
211
212 /// Returns the value truncated to the size of an uint64_t.
213 uint64_t truncatedValue() const {
214 uint64_t Value = 0;
215 static_assert(sizeof(*this) >= sizeof(uint64_t), "No need to truncate.");
216 for (unsigned I = 0; I < sizeof(uint64_t); ++I)
217 Value |= static_cast<uint64_t>((*this)[I]) << (I * 8);
218 return Value;
219 }
220
221 static ASTFileSignature create(std::array<uint8_t, 20> Bytes) {
222 return ASTFileSignature(std::move(Bytes));
223 }
224
226 ASTFileSignature Sentinel;
227 Sentinel.fill(0xFF);
228 return Sentinel;
229 }
230
232 ASTFileSignature Dummy;
233 Dummy.fill(0x00);
234 return Dummy;
235 }
236
237 template <typename InputIt>
238 static ASTFileSignature create(InputIt First, InputIt Last) {
239 assert(std::distance(First, Last) == size &&
240 "Wrong amount of bytes to create an ASTFileSignature");
241
242 ASTFileSignature Signature;
243 std::copy(First, Last, Signature.begin());
244 return Signature;
245 }
246};
247
248/// The set of attributes that can be attached to a module.
250 /// Whether this is a system module.
251 LLVM_PREFERRED_TYPE(bool)
253
254 /// Whether this is an extern "C" module.
255 LLVM_PREFERRED_TYPE(bool)
256 unsigned IsExternC : 1;
257
258 /// Whether this is an exhaustive set of configuration macros.
259 LLVM_PREFERRED_TYPE(bool)
260 unsigned IsExhaustive : 1;
261
262 /// Whether files in this module can only include non-modular headers
263 /// and headers from used modules.
264 LLVM_PREFERRED_TYPE(bool)
266
270};
271
272/// Reference to a module that consists of either an existing/materialized
273/// Module object, reference to a serialized submodule record, both, or
274/// neither (null).
276 /// The existing/materialized Module object.
277 mutable Module *Existing = nullptr;
278
279 /// The external submodule source (i.e. \c ASTReader), and a boolean
280 /// signifying whether it's already been used to deserialize \c SubmoduleID.
281 mutable llvm::PointerIntPair<ExternalSubmoduleSource *, 1, bool>
282 ExternalSource = {nullptr, false};
283
284 /// Identifier of the external submodule in \c ExternalSource.
285 mutable uint64_t SubmoduleID = 0;
286
287public:
288 /// Create an empty reference.
289 ModuleRef() = default;
290
291 /// Create reference to a materialized module.
292 ModuleRef(Module *M) : Existing(M) {}
293
294 /// Create reference to a serialized submodule record.
295 ModuleRef(ExternalSubmoduleSource *ExtSrc, uint64_t SubmoduleID)
296 : ExternalSource(ExtSrc, false), SubmoduleID(SubmoduleID) {}
297
298 /// Get the existing/materialized module, if there's any.
299 Module *getExisting() const { return Existing; }
300 /// Add the existing/materialized module.
301 void setExisting(Module *E) { Existing = E; }
302
303 /// Add the serialized submodule record reference.
304 void setExternal(ExternalSubmoduleSource *ExtSrc, uint64_t ID) {
305 ExternalSource = {ExtSrc, false};
306 SubmoduleID = ID;
307 }
308
309 /// Check whether this is a non-empty reference.
310 operator bool() const {
311 return Existing || (ExternalSource.getPointer() && SubmoduleID);
312 }
313
314 /// Get the existing/materialized module. Try materializing it on-demand from
315 /// the serialized submodule record if possible.
316 operator Module *() const {
317 if (!ExternalSource.getInt() && ExternalSource.getPointer() &&
318 SubmoduleID) {
319 Existing = ExternalSource.getPointer()->getSubmodule(SubmoduleID);
320 ExternalSource.setInt(true);
321 }
322 return Existing;
323 }
324
325 Module *operator->() const { return *this; }
326};
327
328/// Required to construct a Module.
329///
330/// This tag type is only constructible by ModuleMap, guaranteeing it ownership
331/// of all Module instances.
332class ModuleConstructorTag {
333 explicit ModuleConstructorTag() = default;
334 friend ModuleMap;
335};
336
337/// Describes a module or submodule.
338///
339/// Aligned to 8 bytes to allow for llvm::PointerIntPair<Module *, 3>.
340class alignas(8) Module {
341public:
342 /// The name of this module.
343 std::string Name;
344
345 /// The location of the module definition.
347
348 // FIXME: Consider if reducing the size of this enum (having Partition and
349 // Named modules only) then representing interface/implementation separately
350 // is more efficient.
352 /// This is a module that was defined by a module map and built out
353 /// of header files.
355
356 /// This is a C++20 header unit.
358
359 /// This is a C++20 module interface unit.
361
362 /// This is a C++20 module implementation unit.
364
365 /// This is a C++20 module partition interface.
367
368 /// This is a C++20 module partition implementation.
370
371 /// This is the explicit Global Module Fragment of a modular TU.
372 /// As per C++ [module.global.frag].
374
375 /// This is the private module fragment within some C++ module.
377
378 /// This is an implicit fragment of the global module which contains
379 /// only language linkage declarations (made in the purview of the
380 /// named module).
382 };
383
384 /// The kind of this module.
386
387 /// The parent of this module. This will be NULL for the top-level
388 /// module.
390
391 /// The build directory of this module. This is the directory in
392 /// which the module is notionally built, and relative to which its headers
393 /// are found.
395
396 /// The presumed file name for the module map defining this module.
397 /// Only non-empty when building from preprocessed source.
399
400 /// The umbrella header or directory.
401 std::variant<std::monostate, FileEntryRef, DirectoryEntryRef> Umbrella;
402
403 /// The location of the umbrella header or directory declaration.
405
406 /// Directories this module depends on the listing of.
407 std::vector<std::string> DirectoryDependencies;
408
409 /// The module signature.
411
412 /// The name of the umbrella entry, as written in the module map.
413 std::string UmbrellaAsWritten;
414
415 // The path to the umbrella entry relative to the root module's \c Directory.
417
418 /// The module through which entities defined in this module will
419 /// eventually be exposed, for use in "private" modules.
420 std::string ExportAsModule;
421
422 /// For the debug info, the path to this module's .apinotes file, if any.
423 std::string APINotesFile;
424
425 /// Does this Module is a named module of a standard named module?
426 bool isNamedModule() const {
427 switch (Kind) {
433 return true;
434 default:
435 return false;
436 }
437 }
438
439 /// Does this Module scope describe a fragment of the global module within
440 /// some C++ module.
441 bool isGlobalModule() const {
443 }
446 }
449 }
450
451 bool isPrivateModule() const { return Kind == PrivateModuleFragment; }
452
453 bool isModuleMapModule() const { return Kind == ModuleMapModule; }
454
455private:
456 /// The submodules of this module, indexed by name.
457 std::vector<ModuleRef> SubModules;
458
459 /// A mapping from the submodule name to the index into the
460 /// \c SubModules vector at which that submodule resides.
461 llvm::StringMap<unsigned> SubModuleIndex;
462
463 /// The AST file name and key if this is a top-level module which has a
464 /// corresponding serialized AST file, or null otherwise.
465 std::optional<ModuleFileName> ASTFileName;
466 std::optional<ModuleFileKey> ASTFileKey;
467
468 /// The top-level headers associated with this module.
470
471 /// top-level header filenames that aren't resolved to FileEntries yet.
472 std::vector<std::string> TopHeaderNames;
473
474 /// Cache of modules visible to lookup in this module.
475 mutable llvm::DenseSet<const Module*> VisibleModulesCache;
476
477 /// The ID used when referencing this module within a VisibleModuleSet.
478 unsigned VisibilityID;
479
480public:
488 /// Information about a header directive as found in the module map
489 /// file.
495
496private:
497 static const int NumHeaderKinds = HK_Excluded + 1;
498 // The begin index for a HeaderKind also acts the end index of HeaderKind - 1.
499 // The extra element at the end acts as the end index of the last HeaderKind.
500 unsigned HeaderKindBeginIndex[NumHeaderKinds + 1] = {};
501 SmallVector<Header, 2> HeadersStorage;
502
503public:
504 ArrayRef<Header> getAllHeaders() const { return HeadersStorage; }
506 assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");
507 auto BeginIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK];
508 auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
509 return {BeginIt, EndIt};
510 }
512 assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");
513 auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
514 HeadersStorage.insert(EndIt, std::move(H));
515 for (unsigned HKI = HK + 1; HKI != NumHeaderKinds + 1; ++HKI)
516 ++HeaderKindBeginIndex[HKI];
517 }
518
519 /// Information about a directory name as found in the module map file.
525
526 /// Stored information about a header directive that was found in the
527 /// module map file but has not been resolved to a file.
531 std::string FileName;
532 bool IsUmbrella = false;
533 bool HasBuiltinHeader = false;
534 std::optional<off_t> Size;
535 std::optional<time_t> ModTime;
536 };
537
538 /// Headers that are mentioned in the module map file but that we have not
539 /// yet attempted to resolve to a file on the file system.
541
542 /// Headers that are mentioned in the module map file but could not be
543 /// found on the file system.
545
546 struct Requirement {
547 std::string FeatureName;
549 };
550
551 /// The set of language features required to use this module.
552 ///
553 /// If any of these requirements are not available, the \c IsAvailable bit
554 /// will be false to indicate that this (sub)module is not available.
556
557 /// A module with the same name that shadows this module.
559
560 /// Whether this module has declared itself unimportable, either because
561 /// it's missing a requirement from \p Requirements or because it's been
562 /// shadowed by another module.
563 LLVM_PREFERRED_TYPE(bool)
565
566 /// Whether we tried and failed to load a module file for this module.
567 LLVM_PREFERRED_TYPE(bool)
569
570 /// Whether this module is available in the current translation unit.
571 ///
572 /// If the module is missing headers or does not meet all requirements then
573 /// this bit will be 0.
574 LLVM_PREFERRED_TYPE(bool)
575 unsigned IsAvailable : 1;
576
577 /// Whether this module was loaded from a module file.
578 LLVM_PREFERRED_TYPE(bool)
579 unsigned IsFromModuleFile : 1;
580
581 /// Whether this is a framework module.
582 LLVM_PREFERRED_TYPE(bool)
583 unsigned IsFramework : 1;
584
585 /// Whether this is an explicit submodule.
586 LLVM_PREFERRED_TYPE(bool)
587 unsigned IsExplicit : 1;
588
589 /// Whether this is a "system" module (which assumes that all
590 /// headers in it are system headers).
591 LLVM_PREFERRED_TYPE(bool)
592 unsigned IsSystem : 1;
593
594 /// Whether this is an 'extern "C"' module (which implicitly puts all
595 /// headers in it within an 'extern "C"' block, and allows the module to be
596 /// imported within such a block).
597 LLVM_PREFERRED_TYPE(bool)
598 unsigned IsExternC : 1;
599
600 /// Whether this is an inferred submodule (module * { ... }).
601 LLVM_PREFERRED_TYPE(bool)
602 unsigned IsInferred : 1;
603
604 /// Whether we should infer submodules for this module based on
605 /// the headers.
606 ///
607 /// Submodules can only be inferred for modules with an umbrella header.
608 LLVM_PREFERRED_TYPE(bool)
609 unsigned InferSubmodules : 1;
610
611 /// Whether, when inferring submodules, the inferred submodules
612 /// should be explicit.
613 LLVM_PREFERRED_TYPE(bool)
615
616 /// Whether, when inferring submodules, the inferr submodules should
617 /// export all modules they import (e.g., the equivalent of "export *").
618 LLVM_PREFERRED_TYPE(bool)
620
621 /// Whether the set of configuration macros is exhaustive.
622 ///
623 /// When the set of configuration macros is exhaustive, meaning
624 /// that no identifier not in this list should affect how the module is
625 /// built.
626 LLVM_PREFERRED_TYPE(bool)
628
629 /// Whether files in this module can only include non-modular headers
630 /// and headers from used modules.
631 LLVM_PREFERRED_TYPE(bool)
633
634 /// Whether this module came from a "private" module map, found next
635 /// to a regular (public) module map.
636 LLVM_PREFERRED_TYPE(bool)
637 unsigned ModuleMapIsPrivate : 1;
638
639 /// Whether this C++20 named modules doesn't need an initializer.
640 /// This is only meaningful for C++20 modules.
641 LLVM_PREFERRED_TYPE(bool)
642 unsigned NamedModuleHasInit : 1;
643
644 /// Describes the visibility of the various names within a
645 /// particular module.
647 /// All of the names in this module are hidden.
649 /// All of the names in this module are visible.
651 };
652
653 /// The visibility of names within this particular module.
655
656 /// The location of the inferred submodule.
658
659 /// The set of modules imported by this module, and on which this
660 /// module depends.
662
663 /// The set of top-level modules that affected the compilation of this module,
664 /// but were not imported.
666
667 /// Describes an exported module.
668 ///
669 /// The pointer is the module being re-exported, while the bit will be true
670 /// to indicate that this is a wildcard export.
671 using ExportDecl = std::pair<ModuleRef, bool>;
672
673 /// The set of export declarations.
675
676 /// Describes an exported module that has not yet been resolved
677 /// (perhaps because the module it refers to has not yet been loaded).
679 /// The location of the 'export' keyword in the module map file.
681
682 /// The name of the module.
684
685 /// Whether this export declaration ends in a wildcard, indicating
686 /// that all of its submodules should be exported (rather than the named
687 /// module itself).
689 };
690
691 /// The set of export declarations that have yet to be resolved.
693
694 /// The directly used modules.
696
697 /// The set of use declarations that have yet to be resolved.
699
700 /// When \c NoUndeclaredIncludes is true, the set of modules this module tried
701 /// to import but didn't because they are not direct uses.
703
704 /// A library or framework to link against when an entity from this
705 /// module is used.
706 struct LinkLibrary {
707 LinkLibrary() = default;
708 LinkLibrary(const std::string &Library, bool IsFramework)
710
711 /// The library to link against.
712 ///
713 /// This will typically be a library or framework name, but can also
714 /// be an absolute path to the library or framework.
715 std::string Library;
716
717 /// Whether this is a framework rather than a library.
718 bool IsFramework = false;
719 };
720
721 /// The set of libraries or frameworks to link against when
722 /// an entity from this module is used.
724
725 /// Autolinking uses the framework name for linking purposes
726 /// when this is false and the export_as name otherwise.
728
729 /// The set of "configuration macros", which are macros that
730 /// (intentionally) change how this module is built.
731 std::vector<std::string> ConfigMacros;
732
733 /// An unresolved conflict with another module.
735 /// The (unresolved) module id.
737
738 /// The message provided to the user when there is a conflict.
739 std::string Message;
740 };
741
742 /// The list of conflicts for which the module-id has not yet been
743 /// resolved.
744 std::vector<UnresolvedConflict> UnresolvedConflicts;
745
746 /// A conflict between two modules.
747 struct Conflict {
748 /// The module that this module conflicts with.
750
751 /// The message provided to the user when there is a conflict.
752 std::string Message;
753 };
754
755 /// The list of conflicts.
756 std::vector<Conflict> Conflicts;
757
758 /// Construct a new module or submodule.
760 Module *Parent, bool IsFramework, bool IsExplicit,
761 unsigned VisibilityID);
762
764
765 /// Determine whether this module has been declared unimportable.
766 bool isUnimportable() const { return IsUnimportable; }
767
768 /// Determine whether this module has been declared unimportable.
769 ///
770 /// \param LangOpts The language options used for the current
771 /// translation unit.
772 ///
773 /// \param Target The target options used for the current translation unit.
774 ///
775 /// \param Req If this module is unimportable because of a missing
776 /// requirement, this parameter will be set to one of the requirements that
777 /// is not met for use of this module.
778 ///
779 /// \param ShadowingModule If this module is unimportable because it is
780 /// shadowed, this parameter will be set to the shadowing module.
781 bool isUnimportable(const LangOptions &LangOpts, const TargetInfo &Target,
782 Requirement &Req, Module *&ShadowingModule) const;
783
784 /// Determine whether this module can be built in this compilation.
785 bool isForBuilding(const LangOptions &LangOpts) const;
786
787 /// Determine whether this module is available for use within the
788 /// current translation unit.
789 bool isAvailable() const { return IsAvailable; }
790
791 /// Determine whether this module is available for use within the
792 /// current translation unit.
793 ///
794 /// \param LangOpts The language options used for the current
795 /// translation unit.
796 ///
797 /// \param Target The target options used for the current translation unit.
798 ///
799 /// \param Req If this module is unavailable because of a missing requirement,
800 /// this parameter will be set to one of the requirements that is not met for
801 /// use of this module.
802 ///
803 /// \param MissingHeader If this module is unavailable because of a missing
804 /// header, this parameter will be set to one of the missing headers.
805 ///
806 /// \param ShadowingModule If this module is unavailable because it is
807 /// shadowed, this parameter will be set to the shadowing module.
808 bool isAvailable(const LangOptions &LangOpts,
809 const TargetInfo &Target,
810 Requirement &Req,
811 UnresolvedHeaderDirective &MissingHeader,
812 Module *&ShadowingModule) const;
813
814 /// Determine whether this module is a submodule.
815 bool isSubModule() const { return Parent != nullptr; }
816
817 /// Check if this module is a (possibly transitive) submodule of \p Other.
818 ///
819 /// The 'A is a submodule of B' relation is a partial order based on the
820 /// the parent-child relationship between individual modules.
821 ///
822 /// Returns \c false if \p Other is \c nullptr.
823 bool isSubModuleOf(const Module *Other) const;
824
825 /// Determine whether this module is a part of a framework,
826 /// either because it is a framework module or because it is a submodule
827 /// of a framework module.
828 bool isPartOfFramework() const {
829 for (const Module *Mod = this; Mod; Mod = Mod->Parent)
830 if (Mod->IsFramework)
831 return true;
832
833 return false;
834 }
835
836 /// Determine whether this module is a subframework of another
837 /// framework.
838 bool isSubFramework() const {
839 return IsFramework && Parent && Parent->isPartOfFramework();
840 }
841
842 /// Set the parent of this module. This should only be used if the parent
843 /// could not be set during module creation.
844 void setParent(Module *M) {
845 assert(!Parent);
846 Parent = M;
847 Parent->SubModuleIndex[M->Name] = Parent->SubModules.size();
848 Parent->SubModules.push_back(this);
849 }
850
851 /// Add a child submodule.
852 void addSubmodule(StringRef Name, Module *Submodule) {
853 auto [It, New] = SubModuleIndex.insert({Name, SubModules.size()});
854 if (New)
855 SubModules.emplace_back();
856 SubModules[It->second].setExisting(Submodule);
857 }
858
859 /// Add the external part of a submodule ModuleRef.
861 uint64_t SubmoduleID) {
862 auto [It, New] = SubModuleIndex.insert({Name, SubModules.size()});
863 if (New)
864 SubModules.emplace_back();
865 SubModules[It->second].setExternal(ExternalSource, SubmoduleID);
866 }
867
868 /// Is this module have similar semantics as headers.
869 bool isHeaderLikeModule() const {
870 return isModuleMapModule() || isHeaderUnit();
871 }
872
873 /// Is this a module partition.
878
879 /// Is this a module partition implementation unit.
883
884 /// Is this a module implementation.
887 }
888
889 /// Is this module a header unit.
890 bool isHeaderUnit() const { return Kind == ModuleHeaderUnit; }
891 // Is this a C++20 module interface or a partition.
894 }
895
896 /// Is this a C++20 named module unit.
897 bool isNamedModuleUnit() const {
899 }
900
904
906
907 /// Get the primary module interface name from a partition.
909 // Technically, global module fragment belongs to global module. And global
910 // module has no name: [module.unit]p6:
911 // The global module has no name, no module interface unit, and is not
912 // introduced by any module-declaration.
913 //
914 // <global> is the default name showed in module map.
915 if (isGlobalModule())
916 return "<global>";
917
918 if (isModulePartition()) {
919 auto pos = Name.find(':');
920 return StringRef(Name.data(), pos);
921 }
922
923 if (isPrivateModule())
924 return getTopLevelModuleName();
925
926 return Name;
927 }
928
929 /// Retrieve the full name of this module, including the path from
930 /// its top-level module.
931 /// \param AllowStringLiterals If \c true, components that might not be
932 /// lexically valid as identifiers will be emitted as string literals.
933 std::string getFullModuleName(bool AllowStringLiterals = false) const;
934
935 /// Whether the full name of this module is equal to joining
936 /// \p nameParts with "."s.
937 ///
938 /// This is more efficient than getFullModuleName().
939 bool fullModuleNameIs(ArrayRef<StringRef> nameParts) const;
940
941 /// Retrieve the top-level module for this (sub)module, which may
942 /// be this module.
944 return const_cast<Module *>(
945 const_cast<const Module *>(this)->getTopLevelModule());
946 }
947
948 /// Retrieve the top-level module for this (sub)module, which may
949 /// be this module.
950 const Module *getTopLevelModule() const;
951
952 /// Retrieve the name of the top-level module.
953 StringRef getTopLevelModuleName() const {
954 return getTopLevelModule()->Name;
955 }
956
957 /// The serialized AST file name for this module, if one was created.
959 const Module *TopLevel = getTopLevelModule();
960 return TopLevel->ASTFileName ? &*TopLevel->ASTFileName : nullptr;
961 }
962
963 /// The serialized AST file key for this module, if one was created.
965 const Module *TopLevel = getTopLevelModule();
966 return TopLevel->ASTFileKey ? &*TopLevel->ASTFileKey : nullptr;
967 }
968
969 /// Set the serialized module file for the top-level module of this module.
971 assert(((!getASTFileName() && !getASTFileKey()) ||
972 *getASTFileKey() == NewKey) &&
973 "file path changed");
974 Module *TopLevel = getTopLevelModule();
975 TopLevel->ASTFileName = NewName;
976 TopLevel->ASTFileKey = NewKey;
977 }
978
979 /// Retrieve the umbrella directory as written.
980 std::optional<DirectoryName> getUmbrellaDirAsWritten() const {
981 if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))
984 return std::nullopt;
985 }
986
987 /// Retrieve the umbrella header as written.
988 std::optional<Header> getUmbrellaHeaderAsWritten() const {
989 if (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella))
991 *Hdr};
992 return std::nullopt;
993 }
994
995 /// Get the effective umbrella directory for this module: either the one
996 /// explicitly written in the module map file, or the parent of the umbrella
997 /// header.
999
1000 /// Record that this module depends on the listing of \p Path, which must name
1001 /// a location in an underlying file system, not in a VFS overlay. Callers
1002 /// normally want \c ModuleMap::recordDirectoryDependencies.
1003 void addDirectoryDependency(StringRef Path);
1004
1008
1009 /// Add a top-level header associated with this module.
1011
1012 /// Add a top-level header filename associated with this module.
1013 void addTopHeaderFilename(StringRef Filename) {
1014 TopHeaderNames.push_back(std::string(Filename));
1015 }
1016
1017 /// The top-level headers associated with this module.
1019
1020 /// Determine whether this module has declared its intention to
1021 /// directly use another module.
1022 bool directlyUses(const Module *Requested);
1023
1024 /// Add the given feature requirement to the list of features
1025 /// required by this module.
1026 ///
1027 /// \param Feature The feature that is required by this module (and
1028 /// its submodules).
1029 ///
1030 /// \param RequiredState The required state of this feature: \c true
1031 /// if it must be present, \c false if it must be absent.
1032 ///
1033 /// \param LangOpts The set of language options that will be used to
1034 /// evaluate the availability of this feature.
1035 ///
1036 /// \param Target The target options that will be used to evaluate the
1037 /// availability of this feature.
1038 void addRequirement(StringRef Feature, bool RequiredState,
1039 const LangOptions &LangOpts,
1040 const TargetInfo &Target);
1041
1042 /// Mark this module and all of its submodules as unavailable.
1043 void markUnavailable(bool Unimportable);
1044
1045 /// Find the submodule with the given name.
1046 ///
1047 /// \returns The submodule if found, or NULL otherwise.
1048 ModuleRef findSubmodule(StringRef Name) const;
1049
1050 /// Get the Global Module Fragment (sub-module) for this module, it there is
1051 /// one.
1052 ///
1053 /// \returns The GMF sub-module if found, or NULL otherwise.
1055
1056 /// Get the Private Module Fragment (sub-module) for this module, it there is
1057 /// one.
1058 ///
1059 /// \returns The PMF sub-module if found, or NULL otherwise.
1061
1062 /// Determine whether the specified module would be visible to
1063 /// a lookup at the end of this module.
1064 ///
1065 /// FIXME: This may return incorrect results for (submodules of) the
1066 /// module currently being built, if it's queried before we see all
1067 /// of its imports.
1068 bool isModuleVisible(const Module *M) const {
1069 if (VisibleModulesCache.empty())
1070 buildVisibleModulesCache();
1071 return VisibleModulesCache.count(M);
1072 }
1073
1074 unsigned getVisibilityID() const { return VisibilityID; }
1075
1076 using submodule_iterator = std::vector<ModuleRef>::iterator;
1077 using submodule_const_iterator = std::vector<ModuleRef>::const_iterator;
1078
1079 llvm::iterator_range<submodule_iterator> submodules() {
1080 return llvm::make_range(SubModules.begin(), SubModules.end());
1081 }
1082 llvm::iterator_range<submodule_const_iterator> submodules() const {
1083 return llvm::make_range(SubModules.begin(), SubModules.end());
1084 }
1085
1086 /// Appends this module's list of exported modules to \p Exported.
1087 ///
1088 /// This provides a subset of immediately imported modules (the ones that are
1089 /// directly exported), not the complete set of exported modules.
1090 void getExportedModules(SmallVectorImpl<Module *> &Exported) const;
1091
1092 static StringRef getModuleInputBufferName() {
1093 return "<module-includes>";
1094 }
1095
1096 /// Print the module map for this module to the given stream.
1097 void print(raw_ostream &OS, unsigned Indent = 0, bool Dump = false) const;
1098
1099 /// Dump the contents of this module to the given output stream.
1100 void dump() const;
1101
1102private:
1103 void buildVisibleModulesCache() const;
1104};
1105
1106/// A set of visible modules.
1108public:
1109 VisibleModuleSet() = default;
1111 : ImportLocs(std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
1112 O.ImportLocs.clear();
1113 ++O.Generation;
1114 }
1115
1116 /// Move from another visible modules set. Guaranteed to leave the source
1117 /// empty and bump the generation on both.
1119 ImportLocs = std::move(O.ImportLocs);
1120 O.ImportLocs.clear();
1121 ++O.Generation;
1122 ++Generation;
1123 return *this;
1124 }
1125
1126 /// Get the current visibility generation. Incremented each time the
1127 /// set of visible modules changes in any way.
1128 unsigned getGeneration() const { return Generation; }
1129
1130 /// Determine whether a module is visible.
1131 bool isVisible(const Module *M) const {
1132 return getImportLoc(M).isValid();
1133 }
1134
1135 /// Get the location at which the import of a module was triggered.
1137 return M && M->getVisibilityID() < ImportLocs.size()
1138 ? ImportLocs[M->getVisibilityID()]
1139 : SourceLocation();
1140 }
1141
1142 /// A callback to call when a module is made visible (directly or
1143 /// indirectly) by a call to \ref setVisible.
1144 using VisibleCallback = llvm::function_ref<void(Module *M)>;
1145
1146 /// A callback to call when a module conflict is found. \p Path
1147 /// consists of a sequence of modules from the conflicting module to the one
1148 /// made visible, where each was exported by the next.
1150 llvm::function_ref<void(ArrayRef<Module *> Path, Module *Conflict,
1151 StringRef Message)>;
1152
1153 /// Make a specific module visible.
1154 void setVisible(
1155 Module *M, SourceLocation Loc, bool IncludeExports = true,
1156 VisibleCallback Vis = [](Module *) {},
1157 ConflictCallback Cb = [](ArrayRef<Module *>, Module *, StringRef) {});
1158
1159private:
1160 /// Import locations for each visible module. Indexed by the module's
1161 /// VisibilityID.
1162 std::vector<SourceLocation> ImportLocs;
1163
1164 /// Visibility generation, bumped every time the visibility state changes.
1165 unsigned Generation = 0;
1166};
1167
1168} // namespace clang
1169
1170template <> struct llvm::DenseMapInfo<clang::ModuleFileKey> {
1171 static unsigned getHashValue(const clang::ModuleFileKey &Val) {
1172 return hash_combine(Val.Ptr, Val.ImplicitModulePathSuffix);
1173 }
1174
1175 static bool isEqual(const clang::ModuleFileKey &LHS,
1176 const clang::ModuleFileKey &RHS) {
1177 return LHS == RHS;
1178 }
1179};
1180
1181#endif // LLVM_CLANG_BASIC_MODULE_H
Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Defines the clang::SourceLocation class and associated facilities.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Interface for on-demand deserialization of submodules stored in a PCM file.
Definition Module.h:56
virtual ~ExternalSubmoduleSource()=default
virtual Module * getSubmodule(uint32_t GlobalID)=0
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition FileEntry.h:57
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:57
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Required to construct a Module.
Definition Module.h:332
Deduplication key for a loaded module file in ModuleManager.
Definition Module.h:79
bool operator==(const ModuleFileKey &Other) const
Definition Module.h:94
ModuleFileKey(const void *ModuleFile)
Definition Module.h:89
bool operator!=(const ModuleFileKey &Other) const
Definition Module.h:99
ModuleFileKey(const void *ModuleCacheDir, StringRef PathSuffix)
Definition Module.h:91
Identifies a module file to be loaded.
Definition Module.h:109
static ModuleFileName makeExplicit(StringRef Name)
Creates a file name for an explicit module.
Definition Module.h:150
bool isInMemory() const
Returns true iff this is an in-memory module file, false otherwise.
Definition Module.h:182
unsigned getImplicitModuleSuffixLength() const
Returns the suffix length for an implicit module name, zero otherwise.
Definition Module.h:171
bool empty() const
Checks whether the module file name is empty.
Definition Module.h:194
unsigned getRawKind() const
Returns the raw value representing the kind of the module file.
Definition Module.h:185
static ModuleFileName makeImplicit(std::string Name, unsigned SuffixLength)
Creates a file name for an implicit module.
Definition Module.h:155
static ModuleFileName makeExplicit(std::string Name)
Creates a file name for an explicit module.
Definition Module.h:142
static ModuleFileName makeInMemory(StringRef Name)
Creates a file name for an in-memory module.
Definition Module.h:134
StringRef str() const
Returns the plain module file name.
Definition Module.h:188
static ModuleFileName makeFromRaw(StringRef Name, unsigned RawKind)
Creates a file name from the raw kind value.
Definition Module.h:126
ModuleFileName()=default
Creates an empty module file name.
static ModuleFileName makeImplicit(StringRef Name, unsigned SuffixLength)
Creates a file name for an implicit module.
Definition Module.h:166
Reference to a module that consists of either an existing/materialized Module object,...
Definition Module.h:275
void setExisting(Module *E)
Add the existing/materialized module.
Definition Module.h:301
ModuleRef()=default
Create an empty reference.
void setExternal(ExternalSubmoduleSource *ExtSrc, uint64_t ID)
Add the serialized submodule record reference.
Definition Module.h:304
ModuleRef(Module *M)
Create reference to a materialized module.
Definition Module.h:292
Module * getExisting() const
Get the existing/materialized module, if there's any.
Definition Module.h:299
ModuleRef(ExternalSubmoduleSource *ExtSrc, uint64_t SubmoduleID)
Create reference to a serialized submodule record.
Definition Module.h:295
Module * operator->() const
Definition Module.h:325
Describes a module or submodule.
Definition Module.h:340
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition Module.h:953
void addRequirement(StringRef Feature, bool RequiredState, const LangOptions &LangOpts, const TargetInfo &Target)
Add the given feature requirement to the list of features required by this module.
Definition Module.cpp:336
unsigned IsExplicit
Whether this is an explicit submodule.
Definition Module.h:587
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition Module.h:674
bool isForBuilding(const LangOptions &LangOpts) const
Determine whether this module can be built in this compilation.
Definition Module.cpp:157
std::variant< std::monostate, FileEntryRef, DirectoryEntryRef > Umbrella
The umbrella header or directory.
Definition Module.h:401
std::vector< std::string > DirectoryDependencies
Directories this module depends on the listing of.
Definition Module.h:407
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition Module.h:609
ArrayRef< Header > getAllHeaders() const
Definition Module.h:504
void addSubmodule(StringRef Name, ExternalSubmoduleSource *ExternalSource, uint64_t SubmoduleID)
Add the external part of a submodule ModuleRef.
Definition Module.h:860
SourceLocation UmbrellaDeclLoc
The location of the umbrella header or directory declaration.
Definition Module.h:404
bool directlyUses(const Module *Requested)
Determine whether this module has declared its intention to directly use another module.
Definition Module.cpp:310
bool isNamedModuleInterfaceHasInit() const
Definition Module.h:905
std::pair< ModuleRef, bool > ExportDecl
Describes an exported module.
Definition Module.h:671
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition Module.h:731
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
Definition Module.h:657
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
Definition Module.h:564
bool isInterfaceOrPartition() const
Definition Module.h:892
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition Module.h:654
bool isModulePartitionImplementation() const
Is this a module partition implementation unit.
Definition Module.h:880
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition Module.h:646
@ Hidden
All of the names in this module are hidden.
Definition Module.h:648
@ AllVisible
All of the names in this module are visible.
Definition Module.h:650
void print(raw_ostream &OS, unsigned Indent=0, bool Dump=false) const
Print the module map for this module to the given stream.
Definition Module.cpp:478
bool isNamedModuleUnit() const
Is this a C++20 named module unit.
Definition Module.h:897
const ModuleFileKey * getASTFileKey() const
The serialized AST file key for this module, if one was created.
Definition Module.h:964
SourceLocation DefinitionLoc
The location of the module definition.
Definition Module.h:346
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system.
Definition Module.h:544
Module(ModuleConstructorTag, StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
Definition Module.cpp:37
Module * Parent
The parent of this module.
Definition Module.h:389
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
Definition Module.cpp:348
SmallVector< UnresolvedHeaderDirective, 1 > UnresolvedHeaders
Headers that are mentioned in the module map file but that we have not yet attempted to resolve to a ...
Definition Module.h:540
ModuleKind Kind
The kind of this module.
Definition Module.h:385
bool isPrivateModule() const
Definition Module.h:451
@ HK_PrivateTextual
Definition Module.h:485
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Definition Module.h:1013
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition Module.h:766
std::vector< ModuleRef >::const_iterator submodule_const_iterator
Definition Module.h:1077
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
Definition Module.cpp:256
Module * getPrivateModuleFragment() const
Get the Private Module Fragment (sub-module) for this module, it there is one.
Definition Module.cpp:391
void addDirectoryDependency(StringRef Path)
Record that this module depends on the listing of Path, which must name a location in an underlying f...
Definition Module.cpp:280
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition Module.h:602
void setASTFileNameAndKey(ModuleFileName NewName, ModuleFileKey NewKey)
Set the serialized module file for the top-level module of this module.
Definition Module.h:970
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module.
Definition Module.h:1068
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition Module.h:592
bool isModuleInterfaceUnit() const
Definition Module.h:901
static StringRef getModuleInputBufferName()
Definition Module.h:1092
std::string Name
The name of this module.
Definition Module.h:343
Module * getGlobalModuleFragment() const
Get the Global Module Fragment (sub-module) for this module, it there is one.
Definition Module.cpp:380
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
Definition Module.h:838
const ModuleFileName * getASTFileName() const
The serialized AST file name for this module, if one was created.
Definition Module.h:958
llvm::iterator_range< submodule_iterator > submodules()
Definition Module.h:1079
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition Module.h:598
bool isModuleMapModule() const
Definition Module.h:453
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
Definition Module.h:637
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used.
Definition Module.h:723
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition Module.h:692
ArrayRef< std::string > getDirectoryDependencies() const
Definition Module.h:1005
void addHeader(HeaderKind HK, Header H)
Definition Module.h:511
void setParent(Module *M)
Set the parent of this module.
Definition Module.h:844
std::optional< Header > getUmbrellaHeaderAsWritten() const
Retrieve the umbrella header as written.
Definition Module.h:988
unsigned getVisibilityID() const
Definition Module.h:1074
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition Module.h:555
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
Definition Module.h:869
bool isModuleImplementation() const
Is this a module implementation.
Definition Module.h:885
llvm::SmallSetVector< const Module *, 2 > UndeclaredUses
When NoUndeclaredIncludes is true, the set of modules this module tried to import but didn't because ...
Definition Module.h:702
std::string UmbrellaRelativeToRootModuleDirectory
Definition Module.h:416
OptionalDirectoryEntryRef Directory
The build directory of this module.
Definition Module.h:394
llvm::SmallVector< ModuleRef, 2 > AffectingClangModules
The set of top-level modules that affected the compilation of this module, but were not imported.
Definition Module.h:665
llvm::iterator_range< submodule_const_iterator > submodules() const
Definition Module.h:1082
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition Module.h:698
unsigned NamedModuleHasInit
Whether this C++20 named modules doesn't need an initializer.
Definition Module.h:642
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition Module.h:632
ModuleRef findSubmodule(StringRef Name) const
Find the submodule with the given name.
Definition Module.cpp:373
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
Definition Module.h:908
bool isModulePartition() const
Is this a module partition.
Definition Module.h:874
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition Module.h:695
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition Module.h:627
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition Module.h:398
std::string APINotesFile
For the debug info, the path to this module's .apinotes file, if any.
Definition Module.h:423
ASTFileSignature Signature
The module signature.
Definition Module.h:410
bool isExplicitGlobalModule() const
Definition Module.h:444
ArrayRef< Header > getHeaders(HeaderKind HK) const
Definition Module.h:505
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
Definition Module.h:441
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition Module.h:619
bool isSubModule() const
Determine whether this module is a submodule.
Definition Module.h:815
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
Definition Module.cpp:402
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition Module.h:744
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition Module.h:579
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
Definition Module.cpp:195
bool isPartOfFramework() const
Determine whether this module is a part of a framework, either because it is a framework module or be...
Definition Module.h:828
ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition Module.cpp:299
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition Module.h:789
std::optional< DirectoryName > getUmbrellaDirAsWritten() const
Retrieve the umbrella directory as written.
Definition Module.h:980
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
Definition Module.h:568
bool isImplicitGlobalModule() const
Definition Module.h:447
bool isHeaderUnit() const
Is this module a header unit.
Definition Module.h:890
@ ModuleImplementationUnit
This is a C++20 module implementation unit.
Definition Module.h:363
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
Definition Module.h:354
@ ImplicitGlobalModuleFragment
This is an implicit fragment of the global module which contains only language linkage declarations (...
Definition Module.h:381
@ ModulePartitionInterface
This is a C++20 module partition interface.
Definition Module.h:366
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
Definition Module.h:360
@ ModuleHeaderUnit
This is a C++20 header unit.
Definition Module.h:357
@ ModulePartitionImplementation
This is a C++20 module partition implementation.
Definition Module.h:369
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
Definition Module.h:376
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
Definition Module.h:373
void dump() const
Dump the contents of this module to the given output stream.
Module * ShadowingModule
A module with the same name that shadows this module.
Definition Module.h:558
unsigned IsFramework
Whether this is a framework module.
Definition Module.h:583
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition Module.h:420
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition Module.cpp:241
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition Module.h:426
std::vector< ModuleRef >::iterator submodule_iterator
Definition Module.h:1076
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Definition Module.h:413
void addTopHeader(FileEntryRef File)
Add a top-level header associated with this module.
Definition Module.cpp:294
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition Module.h:575
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition Module.h:614
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition Module.h:943
void addSubmodule(StringRef Name, Module *Submodule)
Add a child submodule.
Definition Module.h:852
llvm::SmallVector< ModuleRef, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition Module.h:661
OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const
Get the effective umbrella directory for this module: either the one explicitly written in the module...
Definition Module.cpp:265
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
Definition Module.h:727
std::vector< Conflict > Conflicts
The list of conflicts.
Definition Module.h:756
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Exposes information about the current target.
Definition TargetInfo.h:228
void setVisible(Module *M, SourceLocation Loc, bool IncludeExports=true, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
Definition Module.cpp:677
llvm::function_ref< void(Module *M)> VisibleCallback
A callback to call when a module is made visible (directly or indirectly) by a call to setVisible.
Definition Module.h:1144
SourceLocation getImportLoc(const Module *M) const
Get the location at which the import of a module was triggered.
Definition Module.h:1136
llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback
A callback to call when a module conflict is found.
Definition Module.h:1149
bool isVisible(const Module *M) const
Determine whether a module is visible.
Definition Module.h:1131
unsigned getGeneration() const
Get the current visibility generation.
Definition Module.h:1128
VisibleModuleSet & operator=(VisibleModuleSet &&O)
Move from another visible modules set.
Definition Module.h:1118
VisibleModuleSet(VisibleModuleSet &&O)
Definition Module.h:1110
Top level wrappers for InstallAPI frontend operations.
SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId
Describes the name of a module.
Definition Module.h:63
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition JsonSupport.h:21
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef
@ Other
Other implicit parameter.
Definition Decl.h:1775
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
The signature of a module, which is a hash of the AST content.
Definition Module.h:198
uint64_t truncatedValue() const
Returns the value truncated to the size of an uint64_t.
Definition Module.h:213
static constexpr size_t size
Definition Module.h:201
static ASTFileSignature create(std::array< uint8_t, 20 > Bytes)
Definition Module.h:221
ASTFileSignature(BaseT S={{0}})
Definition Module.h:203
static ASTFileSignature createDummy()
Definition Module.h:231
std::array< uint8_t, 20 > BaseT
Definition Module.h:199
static ASTFileSignature createDISentinel()
Definition Module.h:225
static ASTFileSignature create(InputIt First, InputIt Last)
Definition Module.h:238
unsigned IsExternC
Whether this is an extern "C" module.
Definition Module.h:256
unsigned IsSystem
Whether this is a system module.
Definition Module.h:252
unsigned IsExhaustive
Whether this is an exhaustive set of configuration macros.
Definition Module.h:260
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition Module.h:265
A conflict between two modules.
Definition Module.h:747
std::string Message
The message provided to the user when there is a conflict.
Definition Module.h:752
ModuleRef Other
The module that this module conflicts with.
Definition Module.h:749
Information about a directory name as found in the module map file.
Definition Module.h:520
std::string PathRelativeToRootModuleDirectory
Definition Module.h:522
DirectoryEntryRef Entry
Definition Module.h:523
Information about a header directive as found in the module map file.
Definition Module.h:490
std::string PathRelativeToRootModuleDirectory
Definition Module.h:492
std::string NameAsWritten
Definition Module.h:491
FileEntryRef Entry
Definition Module.h:493
bool IsFramework
Whether this is a framework rather than a library.
Definition Module.h:718
LinkLibrary(const std::string &Library, bool IsFramework)
Definition Module.h:708
std::string Library
The library to link against.
Definition Module.h:715
std::string FeatureName
Definition Module.h:547
An unresolved conflict with another module.
Definition Module.h:734
std::string Message
The message provided to the user when there is a conflict.
Definition Module.h:739
ModuleId Id
The (unresolved) module id.
Definition Module.h:736
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Definition Module.h:678
bool Wildcard
Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...
Definition Module.h:688
ModuleId Id
The name of the module.
Definition Module.h:683
SourceLocation ExportLoc
The location of the 'export' keyword in the module map file.
Definition Module.h:680
Stored information about a header directive that was found in the module map file but has not been re...
Definition Module.h:528
std::optional< time_t > ModTime
Definition Module.h:535
static bool isEqual(const clang::ModuleFileKey &LHS, const clang::ModuleFileKey &RHS)
Definition Module.h:1175
static unsigned getHashValue(const clang::ModuleFileKey &Val)
Definition Module.h:1171