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