clang 23.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 /// The module signature.
408
409 /// The name of the umbrella entry, as written in the module map.
410 std::string UmbrellaAsWritten;
411
412 // The path to the umbrella entry relative to the root module's \c Directory.
414
415 /// The module through which entities defined in this module will
416 /// eventually be exposed, for use in "private" modules.
417 std::string ExportAsModule;
418
419 /// For the debug info, the path to this module's .apinotes file, if any.
420 std::string APINotesFile;
421
422 /// Does this Module is a named module of a standard named module?
423 bool isNamedModule() const {
424 switch (Kind) {
430 return true;
431 default:
432 return false;
433 }
434 }
435
436 /// Does this Module scope describe a fragment of the global module within
437 /// some C++ module.
438 bool isGlobalModule() const {
440 }
443 }
446 }
447
448 bool isPrivateModule() const { return Kind == PrivateModuleFragment; }
449
450 bool isModuleMapModule() const { return Kind == ModuleMapModule; }
451
452private:
453 /// The submodules of this module, indexed by name.
454 std::vector<ModuleRef> SubModules;
455
456 /// A mapping from the submodule name to the index into the
457 /// \c SubModules vector at which that submodule resides.
458 llvm::StringMap<unsigned> SubModuleIndex;
459
460 /// The AST file name and key if this is a top-level module which has a
461 /// corresponding serialized AST file, or null otherwise.
462 std::optional<ModuleFileName> ASTFileName;
463 std::optional<ModuleFileKey> ASTFileKey;
464
465 /// The top-level headers associated with this module.
467
468 /// top-level header filenames that aren't resolved to FileEntries yet.
469 std::vector<std::string> TopHeaderNames;
470
471 /// Cache of modules visible to lookup in this module.
472 mutable llvm::DenseSet<const Module*> VisibleModulesCache;
473
474 /// The ID used when referencing this module within a VisibleModuleSet.
475 unsigned VisibilityID;
476
477public:
485 /// Information about a header directive as found in the module map
486 /// file.
492
493private:
494 static const int NumHeaderKinds = HK_Excluded + 1;
495 // The begin index for a HeaderKind also acts the end index of HeaderKind - 1.
496 // The extra element at the end acts as the end index of the last HeaderKind.
497 unsigned HeaderKindBeginIndex[NumHeaderKinds + 1] = {};
498 SmallVector<Header, 2> HeadersStorage;
499
500public:
501 ArrayRef<Header> getAllHeaders() const { return HeadersStorage; }
503 assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");
504 auto BeginIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK];
505 auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
506 return {BeginIt, EndIt};
507 }
509 assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");
510 auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
511 HeadersStorage.insert(EndIt, std::move(H));
512 for (unsigned HKI = HK + 1; HKI != NumHeaderKinds + 1; ++HKI)
513 ++HeaderKindBeginIndex[HKI];
514 }
515
516 /// Information about a directory name as found in the module map file.
522
523 /// Stored information about a header directive that was found in the
524 /// module map file but has not been resolved to a file.
528 std::string FileName;
529 bool IsUmbrella = false;
530 bool HasBuiltinHeader = false;
531 std::optional<off_t> Size;
532 std::optional<time_t> ModTime;
533 };
534
535 /// Headers that are mentioned in the module map file but that we have not
536 /// yet attempted to resolve to a file on the file system.
538
539 /// Headers that are mentioned in the module map file but could not be
540 /// found on the file system.
542
543 struct Requirement {
544 std::string FeatureName;
546 };
547
548 /// The set of language features required to use this module.
549 ///
550 /// If any of these requirements are not available, the \c IsAvailable bit
551 /// will be false to indicate that this (sub)module is not available.
553
554 /// A module with the same name that shadows this module.
556
557 /// Whether this module has declared itself unimportable, either because
558 /// it's missing a requirement from \p Requirements or because it's been
559 /// shadowed by another module.
560 LLVM_PREFERRED_TYPE(bool)
562
563 /// Whether we tried and failed to load a module file for this module.
564 LLVM_PREFERRED_TYPE(bool)
566
567 /// Whether this module is available in the current translation unit.
568 ///
569 /// If the module is missing headers or does not meet all requirements then
570 /// this bit will be 0.
571 LLVM_PREFERRED_TYPE(bool)
572 unsigned IsAvailable : 1;
573
574 /// Whether this module was loaded from a module file.
575 LLVM_PREFERRED_TYPE(bool)
576 unsigned IsFromModuleFile : 1;
577
578 /// Whether this is a framework module.
579 LLVM_PREFERRED_TYPE(bool)
580 unsigned IsFramework : 1;
581
582 /// Whether this is an explicit submodule.
583 LLVM_PREFERRED_TYPE(bool)
584 unsigned IsExplicit : 1;
585
586 /// Whether this is a "system" module (which assumes that all
587 /// headers in it are system headers).
588 LLVM_PREFERRED_TYPE(bool)
589 unsigned IsSystem : 1;
590
591 /// Whether this is an 'extern "C"' module (which implicitly puts all
592 /// headers in it within an 'extern "C"' block, and allows the module to be
593 /// imported within such a block).
594 LLVM_PREFERRED_TYPE(bool)
595 unsigned IsExternC : 1;
596
597 /// Whether this is an inferred submodule (module * { ... }).
598 LLVM_PREFERRED_TYPE(bool)
599 unsigned IsInferred : 1;
600
601 /// Whether we should infer submodules for this module based on
602 /// the headers.
603 ///
604 /// Submodules can only be inferred for modules with an umbrella header.
605 LLVM_PREFERRED_TYPE(bool)
606 unsigned InferSubmodules : 1;
607
608 /// Whether, when inferring submodules, the inferred submodules
609 /// should be explicit.
610 LLVM_PREFERRED_TYPE(bool)
612
613 /// Whether, when inferring submodules, the inferr submodules should
614 /// export all modules they import (e.g., the equivalent of "export *").
615 LLVM_PREFERRED_TYPE(bool)
617
618 /// Whether the set of configuration macros is exhaustive.
619 ///
620 /// When the set of configuration macros is exhaustive, meaning
621 /// that no identifier not in this list should affect how the module is
622 /// built.
623 LLVM_PREFERRED_TYPE(bool)
625
626 /// Whether files in this module can only include non-modular headers
627 /// and headers from used modules.
628 LLVM_PREFERRED_TYPE(bool)
630
631 /// Whether this module came from a "private" module map, found next
632 /// to a regular (public) module map.
633 LLVM_PREFERRED_TYPE(bool)
634 unsigned ModuleMapIsPrivate : 1;
635
636 /// Whether this C++20 named modules doesn't need an initializer.
637 /// This is only meaningful for C++20 modules.
638 LLVM_PREFERRED_TYPE(bool)
639 unsigned NamedModuleHasInit : 1;
640
641 /// Describes the visibility of the various names within a
642 /// particular module.
644 /// All of the names in this module are hidden.
646 /// All of the names in this module are visible.
648 };
649
650 /// The visibility of names within this particular module.
652
653 /// The location of the inferred submodule.
655
656 /// The set of modules imported by this module, and on which this
657 /// module depends.
659
660 /// The set of top-level modules that affected the compilation of this module,
661 /// but were not imported.
663
664 /// Describes an exported module.
665 ///
666 /// The pointer is the module being re-exported, while the bit will be true
667 /// to indicate that this is a wildcard export.
668 using ExportDecl = std::pair<ModuleRef, bool>;
669
670 /// The set of export declarations.
672
673 /// Describes an exported module that has not yet been resolved
674 /// (perhaps because the module it refers to has not yet been loaded).
676 /// The location of the 'export' keyword in the module map file.
678
679 /// The name of the module.
681
682 /// Whether this export declaration ends in a wildcard, indicating
683 /// that all of its submodules should be exported (rather than the named
684 /// module itself).
686 };
687
688 /// The set of export declarations that have yet to be resolved.
690
691 /// The directly used modules.
693
694 /// The set of use declarations that have yet to be resolved.
696
697 /// When \c NoUndeclaredIncludes is true, the set of modules this module tried
698 /// to import but didn't because they are not direct uses.
700
701 /// A library or framework to link against when an entity from this
702 /// module is used.
703 struct LinkLibrary {
704 LinkLibrary() = default;
705 LinkLibrary(const std::string &Library, bool IsFramework)
707
708 /// The library to link against.
709 ///
710 /// This will typically be a library or framework name, but can also
711 /// be an absolute path to the library or framework.
712 std::string Library;
713
714 /// Whether this is a framework rather than a library.
715 bool IsFramework = false;
716 };
717
718 /// The set of libraries or frameworks to link against when
719 /// an entity from this module is used.
721
722 /// Autolinking uses the framework name for linking purposes
723 /// when this is false and the export_as name otherwise.
725
726 /// The set of "configuration macros", which are macros that
727 /// (intentionally) change how this module is built.
728 std::vector<std::string> ConfigMacros;
729
730 /// An unresolved conflict with another module.
732 /// The (unresolved) module id.
734
735 /// The message provided to the user when there is a conflict.
736 std::string Message;
737 };
738
739 /// The list of conflicts for which the module-id has not yet been
740 /// resolved.
741 std::vector<UnresolvedConflict> UnresolvedConflicts;
742
743 /// A conflict between two modules.
744 struct Conflict {
745 /// The module that this module conflicts with.
747
748 /// The message provided to the user when there is a conflict.
749 std::string Message;
750 };
751
752 /// The list of conflicts.
753 std::vector<Conflict> Conflicts;
754
755 /// Construct a new module or submodule.
757 Module *Parent, bool IsFramework, bool IsExplicit,
758 unsigned VisibilityID);
759
761
762 /// Determine whether this module has been declared unimportable.
763 bool isUnimportable() const { return IsUnimportable; }
764
765 /// Determine whether this module has been declared unimportable.
766 ///
767 /// \param LangOpts The language options used for the current
768 /// translation unit.
769 ///
770 /// \param Target The target options used for the current translation unit.
771 ///
772 /// \param Req If this module is unimportable because of a missing
773 /// requirement, this parameter will be set to one of the requirements that
774 /// is not met for use of this module.
775 ///
776 /// \param ShadowingModule If this module is unimportable because it is
777 /// shadowed, this parameter will be set to the shadowing module.
778 bool isUnimportable(const LangOptions &LangOpts, const TargetInfo &Target,
779 Requirement &Req, Module *&ShadowingModule) const;
780
781 /// Determine whether this module can be built in this compilation.
782 bool isForBuilding(const LangOptions &LangOpts) const;
783
784 /// Determine whether this module is available for use within the
785 /// current translation unit.
786 bool isAvailable() const { return IsAvailable; }
787
788 /// Determine whether this module is available for use within the
789 /// current translation unit.
790 ///
791 /// \param LangOpts The language options used for the current
792 /// translation unit.
793 ///
794 /// \param Target The target options used for the current translation unit.
795 ///
796 /// \param Req If this module is unavailable because of a missing requirement,
797 /// this parameter will be set to one of the requirements that is not met for
798 /// use of this module.
799 ///
800 /// \param MissingHeader If this module is unavailable because of a missing
801 /// header, this parameter will be set to one of the missing headers.
802 ///
803 /// \param ShadowingModule If this module is unavailable because it is
804 /// shadowed, this parameter will be set to the shadowing module.
805 bool isAvailable(const LangOptions &LangOpts,
806 const TargetInfo &Target,
807 Requirement &Req,
808 UnresolvedHeaderDirective &MissingHeader,
809 Module *&ShadowingModule) const;
810
811 /// Determine whether this module is a submodule.
812 bool isSubModule() const { return Parent != nullptr; }
813
814 /// Check if this module is a (possibly transitive) submodule of \p Other.
815 ///
816 /// The 'A is a submodule of B' relation is a partial order based on the
817 /// the parent-child relationship between individual modules.
818 ///
819 /// Returns \c false if \p Other is \c nullptr.
820 bool isSubModuleOf(const Module *Other) const;
821
822 /// Determine whether this module is a part of a framework,
823 /// either because it is a framework module or because it is a submodule
824 /// of a framework module.
825 bool isPartOfFramework() const {
826 for (const Module *Mod = this; Mod; Mod = Mod->Parent)
827 if (Mod->IsFramework)
828 return true;
829
830 return false;
831 }
832
833 /// Determine whether this module is a subframework of another
834 /// framework.
835 bool isSubFramework() const {
836 return IsFramework && Parent && Parent->isPartOfFramework();
837 }
838
839 /// Set the parent of this module. This should only be used if the parent
840 /// could not be set during module creation.
841 void setParent(Module *M) {
842 assert(!Parent);
843 Parent = M;
844 Parent->SubModuleIndex[M->Name] = Parent->SubModules.size();
845 Parent->SubModules.push_back(this);
846 }
847
848 /// Add a child submodule.
849 void addSubmodule(StringRef Name, Module *Submodule) {
850 auto [It, New] = SubModuleIndex.insert({Name, SubModules.size()});
851 if (New)
852 SubModules.emplace_back();
853 SubModules[It->second].setExisting(Submodule);
854 }
855
856 /// Add the external part of a submodule ModuleRef.
858 uint64_t SubmoduleID) {
859 auto [It, New] = SubModuleIndex.insert({Name, SubModules.size()});
860 if (New)
861 SubModules.emplace_back();
862 SubModules[It->second].setExternal(ExternalSource, SubmoduleID);
863 }
864
865 /// Is this module have similar semantics as headers.
866 bool isHeaderLikeModule() const {
867 return isModuleMapModule() || isHeaderUnit();
868 }
869
870 /// Is this a module partition.
875
876 /// Is this a module partition implementation unit.
880
881 /// Is this a module implementation.
884 }
885
886 /// Is this module a header unit.
887 bool isHeaderUnit() const { return Kind == ModuleHeaderUnit; }
888 // Is this a C++20 module interface or a partition.
891 }
892
893 /// Is this a C++20 named module unit.
894 bool isNamedModuleUnit() const {
896 }
897
901
903
904 /// Get the primary module interface name from a partition.
906 // Technically, global module fragment belongs to global module. And global
907 // module has no name: [module.unit]p6:
908 // The global module has no name, no module interface unit, and is not
909 // introduced by any module-declaration.
910 //
911 // <global> is the default name showed in module map.
912 if (isGlobalModule())
913 return "<global>";
914
915 if (isModulePartition()) {
916 auto pos = Name.find(':');
917 return StringRef(Name.data(), pos);
918 }
919
920 if (isPrivateModule())
921 return getTopLevelModuleName();
922
923 return Name;
924 }
925
926 /// Retrieve the full name of this module, including the path from
927 /// its top-level module.
928 /// \param AllowStringLiterals If \c true, components that might not be
929 /// lexically valid as identifiers will be emitted as string literals.
930 std::string getFullModuleName(bool AllowStringLiterals = false) const;
931
932 /// Whether the full name of this module is equal to joining
933 /// \p nameParts with "."s.
934 ///
935 /// This is more efficient than getFullModuleName().
936 bool fullModuleNameIs(ArrayRef<StringRef> nameParts) const;
937
938 /// Retrieve the top-level module for this (sub)module, which may
939 /// be this module.
941 return const_cast<Module *>(
942 const_cast<const Module *>(this)->getTopLevelModule());
943 }
944
945 /// Retrieve the top-level module for this (sub)module, which may
946 /// be this module.
947 const Module *getTopLevelModule() const;
948
949 /// Retrieve the name of the top-level module.
950 StringRef getTopLevelModuleName() const {
951 return getTopLevelModule()->Name;
952 }
953
954 /// The serialized AST file name for this module, if one was created.
956 const Module *TopLevel = getTopLevelModule();
957 return TopLevel->ASTFileName ? &*TopLevel->ASTFileName : nullptr;
958 }
959
960 /// The serialized AST file key for this module, if one was created.
962 const Module *TopLevel = getTopLevelModule();
963 return TopLevel->ASTFileKey ? &*TopLevel->ASTFileKey : nullptr;
964 }
965
966 /// Set the serialized module file for the top-level module of this module.
968 assert(((!getASTFileName() && !getASTFileKey()) ||
969 *getASTFileKey() == NewKey) &&
970 "file path changed");
971 Module *TopLevel = getTopLevelModule();
972 TopLevel->ASTFileName = NewName;
973 TopLevel->ASTFileKey = NewKey;
974 }
975
976 /// Retrieve the umbrella directory as written.
977 std::optional<DirectoryName> getUmbrellaDirAsWritten() const {
978 if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))
981 return std::nullopt;
982 }
983
984 /// Retrieve the umbrella header as written.
985 std::optional<Header> getUmbrellaHeaderAsWritten() const {
986 if (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella))
988 *Hdr};
989 return std::nullopt;
990 }
991
992 /// Get the effective umbrella directory for this module: either the one
993 /// explicitly written in the module map file, or the parent of the umbrella
994 /// header.
996
997 /// Add a top-level header associated with this module.
999
1000 /// Add a top-level header filename associated with this module.
1001 void addTopHeaderFilename(StringRef Filename) {
1002 TopHeaderNames.push_back(std::string(Filename));
1003 }
1004
1005 /// The top-level headers associated with this module.
1007
1008 /// Determine whether this module has declared its intention to
1009 /// directly use another module.
1010 bool directlyUses(const Module *Requested);
1011
1012 /// Add the given feature requirement to the list of features
1013 /// required by this module.
1014 ///
1015 /// \param Feature The feature that is required by this module (and
1016 /// its submodules).
1017 ///
1018 /// \param RequiredState The required state of this feature: \c true
1019 /// if it must be present, \c false if it must be absent.
1020 ///
1021 /// \param LangOpts The set of language options that will be used to
1022 /// evaluate the availability of this feature.
1023 ///
1024 /// \param Target The target options that will be used to evaluate the
1025 /// availability of this feature.
1026 void addRequirement(StringRef Feature, bool RequiredState,
1027 const LangOptions &LangOpts,
1028 const TargetInfo &Target);
1029
1030 /// Mark this module and all of its submodules as unavailable.
1031 void markUnavailable(bool Unimportable);
1032
1033 /// Find the submodule with the given name.
1034 ///
1035 /// \returns The submodule if found, or NULL otherwise.
1036 ModuleRef findSubmodule(StringRef Name) const;
1037
1038 /// Get the Global Module Fragment (sub-module) for this module, it there is
1039 /// one.
1040 ///
1041 /// \returns The GMF sub-module if found, or NULL otherwise.
1043
1044 /// Get the Private Module Fragment (sub-module) for this module, it there is
1045 /// one.
1046 ///
1047 /// \returns The PMF sub-module if found, or NULL otherwise.
1049
1050 /// Determine whether the specified module would be visible to
1051 /// a lookup at the end of this module.
1052 ///
1053 /// FIXME: This may return incorrect results for (submodules of) the
1054 /// module currently being built, if it's queried before we see all
1055 /// of its imports.
1056 bool isModuleVisible(const Module *M) const {
1057 if (VisibleModulesCache.empty())
1058 buildVisibleModulesCache();
1059 return VisibleModulesCache.count(M);
1060 }
1061
1062 unsigned getVisibilityID() const { return VisibilityID; }
1063
1064 using submodule_iterator = std::vector<ModuleRef>::iterator;
1065 using submodule_const_iterator = std::vector<ModuleRef>::const_iterator;
1066
1067 llvm::iterator_range<submodule_iterator> submodules() {
1068 return llvm::make_range(SubModules.begin(), SubModules.end());
1069 }
1070 llvm::iterator_range<submodule_const_iterator> submodules() const {
1071 return llvm::make_range(SubModules.begin(), SubModules.end());
1072 }
1073
1074 /// Appends this module's list of exported modules to \p Exported.
1075 ///
1076 /// This provides a subset of immediately imported modules (the ones that are
1077 /// directly exported), not the complete set of exported modules.
1078 void getExportedModules(SmallVectorImpl<Module *> &Exported) const;
1079
1080 static StringRef getModuleInputBufferName() {
1081 return "<module-includes>";
1082 }
1083
1084 /// Print the module map for this module to the given stream.
1085 void print(raw_ostream &OS, unsigned Indent = 0, bool Dump = false) const;
1086
1087 /// Dump the contents of this module to the given output stream.
1088 void dump() const;
1089
1090private:
1091 void buildVisibleModulesCache() const;
1092};
1093
1094/// A set of visible modules.
1096public:
1097 VisibleModuleSet() = default;
1099 : ImportLocs(std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
1100 O.ImportLocs.clear();
1101 ++O.Generation;
1102 }
1103
1104 /// Move from another visible modules set. Guaranteed to leave the source
1105 /// empty and bump the generation on both.
1107 ImportLocs = std::move(O.ImportLocs);
1108 O.ImportLocs.clear();
1109 ++O.Generation;
1110 ++Generation;
1111 return *this;
1112 }
1113
1114 /// Get the current visibility generation. Incremented each time the
1115 /// set of visible modules changes in any way.
1116 unsigned getGeneration() const { return Generation; }
1117
1118 /// Determine whether a module is visible.
1119 bool isVisible(const Module *M) const {
1120 return getImportLoc(M).isValid();
1121 }
1122
1123 /// Get the location at which the import of a module was triggered.
1125 return M && M->getVisibilityID() < ImportLocs.size()
1126 ? ImportLocs[M->getVisibilityID()]
1127 : SourceLocation();
1128 }
1129
1130 /// A callback to call when a module is made visible (directly or
1131 /// indirectly) by a call to \ref setVisible.
1132 using VisibleCallback = llvm::function_ref<void(Module *M)>;
1133
1134 /// A callback to call when a module conflict is found. \p Path
1135 /// consists of a sequence of modules from the conflicting module to the one
1136 /// made visible, where each was exported by the next.
1138 llvm::function_ref<void(ArrayRef<Module *> Path, Module *Conflict,
1139 StringRef Message)>;
1140
1141 /// Make a specific module visible.
1142 void setVisible(
1143 Module *M, SourceLocation Loc, bool IncludeExports = true,
1144 VisibleCallback Vis = [](Module *) {},
1145 ConflictCallback Cb = [](ArrayRef<Module *>, Module *, StringRef) {});
1146
1147private:
1148 /// Import locations for each visible module. Indexed by the module's
1149 /// VisibilityID.
1150 std::vector<SourceLocation> ImportLocs;
1151
1152 /// Visibility generation, bumped every time the visibility state changes.
1153 unsigned Generation = 0;
1154};
1155
1156} // namespace clang
1157
1158template <> struct llvm::DenseMapInfo<clang::ModuleFileKey> {
1160 return DenseMapInfo<const void *>::getEmptyKey();
1161 }
1162
1164 return DenseMapInfo<const void *>::getTombstoneKey();
1165 }
1166
1167 static unsigned getHashValue(const clang::ModuleFileKey &Val) {
1168 return hash_combine(Val.Ptr, Val.ImplicitModulePathSuffix);
1169 }
1170
1171 static bool isEqual(const clang::ModuleFileKey &LHS,
1172 const clang::ModuleFileKey &RHS) {
1173 return LHS == RHS;
1174 }
1175};
1176
1177#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:54
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:950
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:313
unsigned IsExplicit
Whether this is an explicit submodule.
Definition Module.h:584
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition Module.h:671
bool isForBuilding(const LangOptions &LangOpts) const
Determine whether this module can be built in this compilation.
Definition Module.cpp:155
std::variant< std::monostate, FileEntryRef, DirectoryEntryRef > Umbrella
The umbrella header or directory.
Definition Module.h:401
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition Module.h:606
ArrayRef< Header > getAllHeaders() const
Definition Module.h:501
void addSubmodule(StringRef Name, ExternalSubmoduleSource *ExternalSource, uint64_t SubmoduleID)
Add the external part of a submodule ModuleRef.
Definition Module.h:857
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:287
bool isNamedModuleInterfaceHasInit() const
Definition Module.h:902
std::pair< ModuleRef, bool > ExportDecl
Describes an exported module.
Definition Module.h:668
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition Module.h:728
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
Definition Module.h:654
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
Definition Module.h:561
bool isInterfaceOrPartition() const
Definition Module.h:889
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition Module.h:651
bool isModulePartitionImplementation() const
Is this a module partition implementation unit.
Definition Module.h:877
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition Module.h:643
@ Hidden
All of the names in this module are hidden.
Definition Module.h:645
@ AllVisible
All of the names in this module are visible.
Definition Module.h:647
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:455
bool isNamedModuleUnit() const
Is this a C++20 named module unit.
Definition Module.h:894
const ModuleFileKey * getASTFileKey() const
The serialized AST file key for this module, if one was created.
Definition Module.h:961
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:541
Module(ModuleConstructorTag, StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
Definition Module.cpp:36
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:325
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:537
ModuleKind Kind
The kind of this module.
Definition Module.h:385
bool isPrivateModule() const
Definition Module.h:448
@ HK_PrivateTextual
Definition Module.h:482
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Definition Module.h:1001
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition Module.h:763
std::vector< ModuleRef >::const_iterator submodule_const_iterator
Definition Module.h:1065
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
Definition Module.cpp:254
Module * getPrivateModuleFragment() const
Get the Private Module Fragment (sub-module) for this module, it there is one.
Definition Module.cpp:368
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition Module.h:599
void setASTFileNameAndKey(ModuleFileName NewName, ModuleFileKey NewKey)
Set the serialized module file for the top-level module of this module.
Definition Module.h:967
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:1056
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition Module.h:589
bool isModuleInterfaceUnit() const
Definition Module.h:898
static StringRef getModuleInputBufferName()
Definition Module.h:1080
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:357
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
Definition Module.h:835
const ModuleFileName * getASTFileName() const
The serialized AST file name for this module, if one was created.
Definition Module.h:955
llvm::iterator_range< submodule_iterator > submodules()
Definition Module.h:1067
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition Module.h:595
bool isModuleMapModule() const
Definition Module.h:450
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
Definition Module.h:634
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:720
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition Module.h:689
void addHeader(HeaderKind HK, Header H)
Definition Module.h:508
void setParent(Module *M)
Set the parent of this module.
Definition Module.h:841
std::optional< Header > getUmbrellaHeaderAsWritten() const
Retrieve the umbrella header as written.
Definition Module.h:985
unsigned getVisibilityID() const
Definition Module.h:1062
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition Module.h:552
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
Definition Module.h:866
bool isModuleImplementation() const
Is this a module implementation.
Definition Module.h:882
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:699
std::string UmbrellaRelativeToRootModuleDirectory
Definition Module.h:413
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:662
llvm::iterator_range< submodule_const_iterator > submodules() const
Definition Module.h:1070
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition Module.h:695
unsigned NamedModuleHasInit
Whether this C++20 named modules doesn't need an initializer.
Definition Module.h:639
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition Module.h:629
ModuleRef findSubmodule(StringRef Name) const
Find the submodule with the given name.
Definition Module.cpp:350
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
Definition Module.h:905
bool isModulePartition() const
Is this a module partition.
Definition Module.h:871
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition Module.h:692
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition Module.h:624
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:420
ASTFileSignature Signature
The module signature.
Definition Module.h:407
bool isExplicitGlobalModule() const
Definition Module.h:441
ArrayRef< Header > getHeaders(HeaderKind HK) const
Definition Module.h:502
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
Definition Module.h:438
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition Module.h:616
bool isSubModule() const
Determine whether this module is a submodule.
Definition Module.h:812
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
Definition Module.cpp:379
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition Module.h:741
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition Module.h:576
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
Definition Module.cpp:193
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:825
ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition Module.cpp:276
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition Module.h:786
std::optional< DirectoryName > getUmbrellaDirAsWritten() const
Retrieve the umbrella directory as written.
Definition Module.h:977
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
Definition Module.h:565
bool isImplicitGlobalModule() const
Definition Module.h:444
bool isHeaderUnit() const
Is this module a header unit.
Definition Module.h:887
@ 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:555
unsigned IsFramework
Whether this is a framework module.
Definition Module.h:580
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition Module.h:417
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:239
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition Module.h:423
std::vector< ModuleRef >::iterator submodule_iterator
Definition Module.h:1064
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Definition Module.h:410
void addTopHeader(FileEntryRef File)
Add a top-level header associated with this module.
Definition Module.cpp:271
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition Module.h:572
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition Module.h:611
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition Module.h:940
void addSubmodule(StringRef Name, Module *Submodule)
Add a child submodule.
Definition Module.h:849
llvm::SmallVector< ModuleRef, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition Module.h:658
OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const
Get the effective umbrella directory for this module: either the one explicitly written in the module...
Definition Module.cpp:263
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
Definition Module.h:724
std::vector< Conflict > Conflicts
The list of conflicts.
Definition Module.h:753
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:227
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:654
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:1132
SourceLocation getImportLoc(const Module *M) const
Get the location at which the import of a module was triggered.
Definition Module.h:1124
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:1137
bool isVisible(const Module *M) const
Determine whether a module is visible.
Definition Module.h:1119
unsigned getGeneration() const
Get the current visibility generation.
Definition Module.h:1116
VisibleModuleSet & operator=(VisibleModuleSet &&O)
Move from another visible modules set.
Definition Module.h:1106
VisibleModuleSet(VisibleModuleSet &&O)
Definition Module.h:1098
The JSON file list parser is used to communicate input to InstallAPI.
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:1763
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:744
std::string Message
The message provided to the user when there is a conflict.
Definition Module.h:749
ModuleRef Other
The module that this module conflicts with.
Definition Module.h:746
Information about a directory name as found in the module map file.
Definition Module.h:517
std::string PathRelativeToRootModuleDirectory
Definition Module.h:519
DirectoryEntryRef Entry
Definition Module.h:520
Information about a header directive as found in the module map file.
Definition Module.h:487
std::string PathRelativeToRootModuleDirectory
Definition Module.h:489
std::string NameAsWritten
Definition Module.h:488
FileEntryRef Entry
Definition Module.h:490
bool IsFramework
Whether this is a framework rather than a library.
Definition Module.h:715
LinkLibrary(const std::string &Library, bool IsFramework)
Definition Module.h:705
std::string Library
The library to link against.
Definition Module.h:712
std::string FeatureName
Definition Module.h:544
An unresolved conflict with another module.
Definition Module.h:731
std::string Message
The message provided to the user when there is a conflict.
Definition Module.h:736
ModuleId Id
The (unresolved) module id.
Definition Module.h:733
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Definition Module.h:675
bool Wildcard
Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...
Definition Module.h:685
ModuleId Id
The name of the module.
Definition Module.h:680
SourceLocation ExportLoc
The location of the 'export' keyword in the module map file.
Definition Module.h:677
Stored information about a header directive that was found in the module map file but has not been re...
Definition Module.h:525
std::optional< time_t > ModTime
Definition Module.h:532
static clang::ModuleFileKey getEmptyKey()
Definition Module.h:1159
static bool isEqual(const clang::ModuleFileKey &LHS, const clang::ModuleFileKey &RHS)
Definition Module.h:1171
static unsigned getHashValue(const clang::ModuleFileKey &Val)
Definition Module.h:1167
static clang::ModuleFileKey getTombstoneKey()
Definition Module.h:1163