clang 19.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 TargetInfo;
52
53/// Describes the name of a module.
55
56/// The signature of a module, which is a hash of the AST content.
57struct ASTFileSignature : std::array<uint8_t, 20> {
58 using BaseT = std::array<uint8_t, 20>;
59
60 static constexpr size_t size = std::tuple_size<BaseT>::value;
61
62 ASTFileSignature(BaseT S = {{0}}) : BaseT(std::move(S)) {}
63
64 explicit operator bool() const { return *this != BaseT({{0}}); }
65
66 /// Returns the value truncated to the size of an uint64_t.
67 uint64_t truncatedValue() const {
68 uint64_t Value = 0;
69 static_assert(sizeof(*this) >= sizeof(uint64_t), "No need to truncate.");
70 for (unsigned I = 0; I < sizeof(uint64_t); ++I)
71 Value |= static_cast<uint64_t>((*this)[I]) << (I * 8);
72 return Value;
73 }
74
75 static ASTFileSignature create(std::array<uint8_t, 20> Bytes) {
76 return ASTFileSignature(std::move(Bytes));
77 }
78
80 ASTFileSignature Sentinel;
81 Sentinel.fill(0xFF);
82 return Sentinel;
83 }
84
86 ASTFileSignature Dummy;
87 Dummy.fill(0x00);
88 return Dummy;
89 }
90
91 template <typename InputIt>
92 static ASTFileSignature create(InputIt First, InputIt Last) {
93 assert(std::distance(First, Last) == size &&
94 "Wrong amount of bytes to create an ASTFileSignature");
95
96 ASTFileSignature Signature;
97 std::copy(First, Last, Signature.begin());
98 return Signature;
99 }
100};
101
102/// Describes a module or submodule.
103///
104/// Aligned to 8 bytes to allow for llvm::PointerIntPair<Module *, 3>.
105class alignas(8) Module {
106public:
107 /// The name of this module.
108 std::string Name;
109
110 /// The location of the module definition.
112
113 // FIXME: Consider if reducing the size of this enum (having Partition and
114 // Named modules only) then representing interface/implementation separately
115 // is more efficient.
117 /// This is a module that was defined by a module map and built out
118 /// of header files.
120
121 /// This is a C++20 header unit.
123
124 /// This is a C++20 module interface unit.
126
127 /// This is a C++20 module implementation unit.
129
130 /// This is a C++20 module partition interface.
132
133 /// This is a C++20 module partition implementation.
135
136 /// This is the explicit Global Module Fragment of a modular TU.
137 /// As per C++ [module.global.frag].
139
140 /// This is the private module fragment within some C++ module.
142
143 /// This is an implicit fragment of the global module which contains
144 /// only language linkage declarations (made in the purview of the
145 /// named module).
147 };
148
149 /// The kind of this module.
151
152 /// The parent of this module. This will be NULL for the top-level
153 /// module.
155
156 /// The build directory of this module. This is the directory in
157 /// which the module is notionally built, and relative to which its headers
158 /// are found.
160
161 /// The presumed file name for the module map defining this module.
162 /// Only non-empty when building from preprocessed source.
164
165 /// The umbrella header or directory.
166 std::variant<std::monostate, FileEntryRef, DirectoryEntryRef> Umbrella;
167
168 /// The module signature.
170
171 /// The name of the umbrella entry, as written in the module map.
172 std::string UmbrellaAsWritten;
173
174 // The path to the umbrella entry relative to the root module's \c Directory.
176
177 /// The module through which entities defined in this module will
178 /// eventually be exposed, for use in "private" modules.
179 std::string ExportAsModule;
180
181 /// For the debug info, the path to this module's .apinotes file, if any.
182 std::string APINotesFile;
183
184 /// Does this Module is a named module of a standard named module?
185 bool isNamedModule() const {
186 switch (Kind) {
192 return true;
193 default:
194 return false;
195 }
196 }
197
198 /// Does this Module scope describe a fragment of the global module within
199 /// some C++ module.
200 bool isGlobalModule() const {
202 }
205 }
208 }
209
210 bool isPrivateModule() const { return Kind == PrivateModuleFragment; }
211
212 bool isModuleMapModule() const { return Kind == ModuleMapModule; }
213
214private:
215 /// The submodules of this module, indexed by name.
216 std::vector<Module *> SubModules;
217
218 /// A mapping from the submodule name to the index into the
219 /// \c SubModules vector at which that submodule resides.
220 llvm::StringMap<unsigned> SubModuleIndex;
221
222 /// The AST file if this is a top-level module which has a
223 /// corresponding serialized AST file, or null otherwise.
224 OptionalFileEntryRef ASTFile;
225
226 /// The top-level headers associated with this module.
228
229 /// top-level header filenames that aren't resolved to FileEntries yet.
230 std::vector<std::string> TopHeaderNames;
231
232 /// Cache of modules visible to lookup in this module.
233 mutable llvm::DenseSet<const Module*> VisibleModulesCache;
234
235 /// The ID used when referencing this module within a VisibleModuleSet.
236 unsigned VisibilityID;
237
238public:
245 };
246 static const int NumHeaderKinds = HK_Excluded + 1;
247
248 /// Information about a header directive as found in the module map
249 /// file.
250 struct Header {
251 std::string NameAsWritten;
254 };
255
256 /// Information about a directory name as found in the module map
257 /// file.
259 std::string NameAsWritten;
262 };
263
264 /// The headers that are part of this module.
266
267 /// Stored information about a header directive that was found in the
268 /// module map file but has not been resolved to a file.
272 std::string FileName;
273 bool IsUmbrella = false;
274 bool HasBuiltinHeader = false;
275 std::optional<off_t> Size;
276 std::optional<time_t> ModTime;
277 };
278
279 /// Headers that are mentioned in the module map file but that we have not
280 /// yet attempted to resolve to a file on the file system.
282
283 /// Headers that are mentioned in the module map file but could not be
284 /// found on the file system.
286
287 struct Requirement {
288 std::string FeatureName;
290 };
291
292 /// The set of language features required to use this module.
293 ///
294 /// If any of these requirements are not available, the \c IsAvailable bit
295 /// will be false to indicate that this (sub)module is not available.
297
298 /// A module with the same name that shadows this module.
300
301 /// Whether this module has declared itself unimportable, either because
302 /// it's missing a requirement from \p Requirements or because it's been
303 /// shadowed by another module.
304 LLVM_PREFERRED_TYPE(bool)
306
307 /// Whether we tried and failed to load a module file for this module.
308 LLVM_PREFERRED_TYPE(bool)
310
311 /// Whether this module is available in the current translation unit.
312 ///
313 /// If the module is missing headers or does not meet all requirements then
314 /// this bit will be 0.
315 LLVM_PREFERRED_TYPE(bool)
316 unsigned IsAvailable : 1;
317
318 /// Whether this module was loaded from a module file.
319 LLVM_PREFERRED_TYPE(bool)
320 unsigned IsFromModuleFile : 1;
321
322 /// Whether this is a framework module.
323 LLVM_PREFERRED_TYPE(bool)
324 unsigned IsFramework : 1;
325
326 /// Whether this is an explicit submodule.
327 LLVM_PREFERRED_TYPE(bool)
328 unsigned IsExplicit : 1;
329
330 /// Whether this is a "system" module (which assumes that all
331 /// headers in it are system headers).
332 LLVM_PREFERRED_TYPE(bool)
333 unsigned IsSystem : 1;
334
335 /// Whether this is an 'extern "C"' module (which implicitly puts all
336 /// headers in it within an 'extern "C"' block, and allows the module to be
337 /// imported within such a block).
338 LLVM_PREFERRED_TYPE(bool)
339 unsigned IsExternC : 1;
340
341 /// Whether this is an inferred submodule (module * { ... }).
342 LLVM_PREFERRED_TYPE(bool)
343 unsigned IsInferred : 1;
344
345 /// Whether we should infer submodules for this module based on
346 /// the headers.
347 ///
348 /// Submodules can only be inferred for modules with an umbrella header.
349 LLVM_PREFERRED_TYPE(bool)
350 unsigned InferSubmodules : 1;
351
352 /// Whether, when inferring submodules, the inferred submodules
353 /// should be explicit.
354 LLVM_PREFERRED_TYPE(bool)
356
357 /// Whether, when inferring submodules, the inferr submodules should
358 /// export all modules they import (e.g., the equivalent of "export *").
359 LLVM_PREFERRED_TYPE(bool)
361
362 /// Whether the set of configuration macros is exhaustive.
363 ///
364 /// When the set of configuration macros is exhaustive, meaning
365 /// that no identifier not in this list should affect how the module is
366 /// built.
367 LLVM_PREFERRED_TYPE(bool)
369
370 /// Whether files in this module can only include non-modular headers
371 /// and headers from used modules.
372 LLVM_PREFERRED_TYPE(bool)
374
375 /// Whether this module came from a "private" module map, found next
376 /// to a regular (public) module map.
377 LLVM_PREFERRED_TYPE(bool)
378 unsigned ModuleMapIsPrivate : 1;
379
380 /// Whether this C++20 named modules doesn't need an initializer.
381 /// This is only meaningful for C++20 modules.
382 LLVM_PREFERRED_TYPE(bool)
383 unsigned NamedModuleHasInit : 1;
384
385 /// Describes the visibility of the various names within a
386 /// particular module.
388 /// All of the names in this module are hidden.
390 /// All of the names in this module are visible.
392 };
393
394 /// The visibility of names within this particular module.
396
397 /// The location of the inferred submodule.
399
400 /// The set of modules imported by this module, and on which this
401 /// module depends.
403
404 /// The set of top-level modules that affected the compilation of this module,
405 /// but were not imported.
407
408 /// Describes an exported module.
409 ///
410 /// The pointer is the module being re-exported, while the bit will be true
411 /// to indicate that this is a wildcard export.
412 using ExportDecl = llvm::PointerIntPair<Module *, 1, bool>;
413
414 /// The set of export declarations.
416
417 /// Describes an exported module that has not yet been resolved
418 /// (perhaps because the module it refers to has not yet been loaded).
420 /// The location of the 'export' keyword in the module map file.
422
423 /// The name of the module.
425
426 /// Whether this export declaration ends in a wildcard, indicating
427 /// that all of its submodules should be exported (rather than the named
428 /// module itself).
430 };
431
432 /// The set of export declarations that have yet to be resolved.
434
435 /// The directly used modules.
437
438 /// The set of use declarations that have yet to be resolved.
440
441 /// When \c NoUndeclaredIncludes is true, the set of modules this module tried
442 /// to import but didn't because they are not direct uses.
444
445 /// A library or framework to link against when an entity from this
446 /// module is used.
447 struct LinkLibrary {
448 LinkLibrary() = default;
449 LinkLibrary(const std::string &Library, bool IsFramework)
451
452 /// The library to link against.
453 ///
454 /// This will typically be a library or framework name, but can also
455 /// be an absolute path to the library or framework.
456 std::string Library;
457
458 /// Whether this is a framework rather than a library.
459 bool IsFramework = false;
460 };
461
462 /// The set of libraries or frameworks to link against when
463 /// an entity from this module is used.
465
466 /// Autolinking uses the framework name for linking purposes
467 /// when this is false and the export_as name otherwise.
469
470 /// The set of "configuration macros", which are macros that
471 /// (intentionally) change how this module is built.
472 std::vector<std::string> ConfigMacros;
473
474 /// An unresolved conflict with another module.
476 /// The (unresolved) module id.
478
479 /// The message provided to the user when there is a conflict.
480 std::string Message;
481 };
482
483 /// The list of conflicts for which the module-id has not yet been
484 /// resolved.
485 std::vector<UnresolvedConflict> UnresolvedConflicts;
486
487 /// A conflict between two modules.
488 struct Conflict {
489 /// The module that this module conflicts with.
491
492 /// The message provided to the user when there is a conflict.
493 std::string Message;
494 };
495
496 /// The list of conflicts.
497 std::vector<Conflict> Conflicts;
498
499 /// Construct a new module or submodule.
501 bool IsFramework, bool IsExplicit, unsigned VisibilityID);
502
503 ~Module();
504
505 /// Determine whether this module has been declared unimportable.
506 bool isUnimportable() const { return IsUnimportable; }
507
508 /// Determine whether this module has been declared unimportable.
509 ///
510 /// \param LangOpts The language options used for the current
511 /// translation unit.
512 ///
513 /// \param Target The target options used for the current translation unit.
514 ///
515 /// \param Req If this module is unimportable because of a missing
516 /// requirement, this parameter will be set to one of the requirements that
517 /// is not met for use of this module.
518 ///
519 /// \param ShadowingModule If this module is unimportable because it is
520 /// shadowed, this parameter will be set to the shadowing module.
521 bool isUnimportable(const LangOptions &LangOpts, const TargetInfo &Target,
522 Requirement &Req, Module *&ShadowingModule) const;
523
524 /// Determine whether this module can be built in this compilation.
525 bool isForBuilding(const LangOptions &LangOpts) const;
526
527 /// Determine whether this module is available for use within the
528 /// current translation unit.
529 bool isAvailable() const { return IsAvailable; }
530
531 /// Determine whether this module is available for use within the
532 /// current translation unit.
533 ///
534 /// \param LangOpts The language options used for the current
535 /// translation unit.
536 ///
537 /// \param Target The target options used for the current translation unit.
538 ///
539 /// \param Req If this module is unavailable because of a missing requirement,
540 /// this parameter will be set to one of the requirements that is not met for
541 /// use of this module.
542 ///
543 /// \param MissingHeader If this module is unavailable because of a missing
544 /// header, this parameter will be set to one of the missing headers.
545 ///
546 /// \param ShadowingModule If this module is unavailable because it is
547 /// shadowed, this parameter will be set to the shadowing module.
548 bool isAvailable(const LangOptions &LangOpts,
549 const TargetInfo &Target,
550 Requirement &Req,
551 UnresolvedHeaderDirective &MissingHeader,
552 Module *&ShadowingModule) const;
553
554 /// Determine whether this module is a submodule.
555 bool isSubModule() const { return Parent != nullptr; }
556
557 /// Check if this module is a (possibly transitive) submodule of \p Other.
558 ///
559 /// The 'A is a submodule of B' relation is a partial order based on the
560 /// the parent-child relationship between individual modules.
561 ///
562 /// Returns \c false if \p Other is \c nullptr.
563 bool isSubModuleOf(const Module *Other) const;
564
565 /// Determine whether this module is a part of a framework,
566 /// either because it is a framework module or because it is a submodule
567 /// of a framework module.
568 bool isPartOfFramework() const {
569 for (const Module *Mod = this; Mod; Mod = Mod->Parent)
570 if (Mod->IsFramework)
571 return true;
572
573 return false;
574 }
575
576 /// Determine whether this module is a subframework of another
577 /// framework.
578 bool isSubFramework() const {
580 }
581
582 /// Set the parent of this module. This should only be used if the parent
583 /// could not be set during module creation.
584 void setParent(Module *M) {
585 assert(!Parent);
586 Parent = M;
587 Parent->SubModuleIndex[Name] = Parent->SubModules.size();
588 Parent->SubModules.push_back(this);
589 }
590
591 /// Is this module have similar semantics as headers.
592 bool isHeaderLikeModule() const {
593 return isModuleMapModule() || isHeaderUnit();
594 }
595
596 /// Is this a module partition.
597 bool isModulePartition() const {
598 return Kind == ModulePartitionInterface ||
600 }
601
602 /// Is this a module partition implementation unit.
605 }
606
607 /// Is this a module implementation.
610 }
611
612 /// Is this module a header unit.
613 bool isHeaderUnit() const { return Kind == ModuleHeaderUnit; }
614 // Is this a C++20 module interface or a partition.
617 }
618
619 /// Is this a C++20 named module unit.
620 bool isNamedModuleUnit() const {
622 }
623
626 }
627
629
630 /// Get the primary module interface name from a partition.
632 // Technically, global module fragment belongs to global module. And global
633 // module has no name: [module.unit]p6:
634 // The global module has no name, no module interface unit, and is not
635 // introduced by any module-declaration.
636 //
637 // <global> is the default name showed in module map.
638 if (isGlobalModule())
639 return "<global>";
640
641 if (isModulePartition()) {
642 auto pos = Name.find(':');
643 return StringRef(Name.data(), pos);
644 }
645
646 if (isPrivateModule())
647 return getTopLevelModuleName();
648
649 return Name;
650 }
651
652 /// Retrieve the full name of this module, including the path from
653 /// its top-level module.
654 /// \param AllowStringLiterals If \c true, components that might not be
655 /// lexically valid as identifiers will be emitted as string literals.
656 std::string getFullModuleName(bool AllowStringLiterals = false) const;
657
658 /// Whether the full name of this module is equal to joining
659 /// \p nameParts with "."s.
660 ///
661 /// This is more efficient than getFullModuleName().
662 bool fullModuleNameIs(ArrayRef<StringRef> nameParts) const;
663
664 /// Retrieve the top-level module for this (sub)module, which may
665 /// be this module.
667 return const_cast<Module *>(
668 const_cast<const Module *>(this)->getTopLevelModule());
669 }
670
671 /// Retrieve the top-level module for this (sub)module, which may
672 /// be this module.
673 const Module *getTopLevelModule() const;
674
675 /// Retrieve the name of the top-level module.
676 StringRef getTopLevelModuleName() const {
677 return getTopLevelModule()->Name;
678 }
679
680 /// The serialized AST file for this module, if one was created.
682 return getTopLevelModule()->ASTFile;
683 }
684
685 /// Set the serialized AST file for the top-level module of this module.
687 assert((!getASTFile() || getASTFile() == File) && "file path changed");
688 getTopLevelModule()->ASTFile = File;
689 }
690
691 /// Retrieve the umbrella directory as written.
692 std::optional<DirectoryName> getUmbrellaDirAsWritten() const {
693 if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))
696 return std::nullopt;
697 }
698
699 /// Retrieve the umbrella header as written.
700 std::optional<Header> getUmbrellaHeaderAsWritten() const {
701 if (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella))
703 *Hdr};
704 return std::nullopt;
705 }
706
707 /// Get the effective umbrella directory for this module: either the one
708 /// explicitly written in the module map file, or the parent of the umbrella
709 /// header.
711
712 /// Add a top-level header associated with this module.
714
715 /// Add a top-level header filename associated with this module.
717 TopHeaderNames.push_back(std::string(Filename));
718 }
719
720 /// The top-level headers associated with this module.
722
723 /// Determine whether this module has declared its intention to
724 /// directly use another module.
725 bool directlyUses(const Module *Requested);
726
727 /// Add the given feature requirement to the list of features
728 /// required by this module.
729 ///
730 /// \param Feature The feature that is required by this module (and
731 /// its submodules).
732 ///
733 /// \param RequiredState The required state of this feature: \c true
734 /// if it must be present, \c false if it must be absent.
735 ///
736 /// \param LangOpts The set of language options that will be used to
737 /// evaluate the availability of this feature.
738 ///
739 /// \param Target The target options that will be used to evaluate the
740 /// availability of this feature.
741 void addRequirement(StringRef Feature, bool RequiredState,
742 const LangOptions &LangOpts,
743 const TargetInfo &Target);
744
745 /// Mark this module and all of its submodules as unavailable.
746 void markUnavailable(bool Unimportable);
747
748 /// Find the submodule with the given name.
749 ///
750 /// \returns The submodule if found, or NULL otherwise.
751 Module *findSubmodule(StringRef Name) const;
752 Module *findOrInferSubmodule(StringRef Name);
753
754 /// Get the Global Module Fragment (sub-module) for this module, it there is
755 /// one.
756 ///
757 /// \returns The GMF sub-module if found, or NULL otherwise.
759
760 /// Get the Private Module Fragment (sub-module) for this module, it there is
761 /// one.
762 ///
763 /// \returns The PMF sub-module if found, or NULL otherwise.
765
766 /// Determine whether the specified module would be visible to
767 /// a lookup at the end of this module.
768 ///
769 /// FIXME: This may return incorrect results for (submodules of) the
770 /// module currently being built, if it's queried before we see all
771 /// of its imports.
772 bool isModuleVisible(const Module *M) const {
773 if (VisibleModulesCache.empty())
774 buildVisibleModulesCache();
775 return VisibleModulesCache.count(M);
776 }
777
778 unsigned getVisibilityID() const { return VisibilityID; }
779
780 using submodule_iterator = std::vector<Module *>::iterator;
781 using submodule_const_iterator = std::vector<Module *>::const_iterator;
782
783 llvm::iterator_range<submodule_iterator> submodules() {
784 return llvm::make_range(SubModules.begin(), SubModules.end());
785 }
786 llvm::iterator_range<submodule_const_iterator> submodules() const {
787 return llvm::make_range(SubModules.begin(), SubModules.end());
788 }
789
790 /// Appends this module's list of exported modules to \p Exported.
791 ///
792 /// This provides a subset of immediately imported modules (the ones that are
793 /// directly exported), not the complete set of exported modules.
794 void getExportedModules(SmallVectorImpl<Module *> &Exported) const;
795
796 static StringRef getModuleInputBufferName() {
797 return "<module-includes>";
798 }
799
800 /// Print the module map for this module to the given stream.
801 void print(raw_ostream &OS, unsigned Indent = 0, bool Dump = false) const;
802
803 /// Dump the contents of this module to the given output stream.
804 void dump() const;
805
806private:
807 void buildVisibleModulesCache() const;
808};
809
810/// A set of visible modules.
812public:
813 VisibleModuleSet() = default;
815 : ImportLocs(std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
816 O.ImportLocs.clear();
817 ++O.Generation;
818 }
819
820 /// Move from another visible modules set. Guaranteed to leave the source
821 /// empty and bump the generation on both.
823 ImportLocs = std::move(O.ImportLocs);
824 O.ImportLocs.clear();
825 ++O.Generation;
826 ++Generation;
827 return *this;
828 }
829
830 /// Get the current visibility generation. Incremented each time the
831 /// set of visible modules changes in any way.
832 unsigned getGeneration() const { return Generation; }
833
834 /// Determine whether a module is visible.
835 bool isVisible(const Module *M) const {
836 return getImportLoc(M).isValid();
837 }
838
839 /// Get the location at which the import of a module was triggered.
841 return M->getVisibilityID() < ImportLocs.size()
842 ? ImportLocs[M->getVisibilityID()]
843 : SourceLocation();
844 }
845
846 /// A callback to call when a module is made visible (directly or
847 /// indirectly) by a call to \ref setVisible.
848 using VisibleCallback = llvm::function_ref<void(Module *M)>;
849
850 /// A callback to call when a module conflict is found. \p Path
851 /// consists of a sequence of modules from the conflicting module to the one
852 /// made visible, where each was exported by the next.
854 llvm::function_ref<void(ArrayRef<Module *> Path, Module *Conflict,
855 StringRef Message)>;
856
857 /// Make a specific module visible.
859 VisibleCallback Vis = [](Module *) {},
861 StringRef) {});
862private:
863 /// Import locations for each visible module. Indexed by the module's
864 /// VisibilityID.
865 std::vector<SourceLocation> ImportLocs;
866
867 /// Visibility generation, bumped every time the visibility state changes.
868 unsigned Generation = 0;
869};
870
871} // namespace clang
872
873#endif // LLVM_CLANG_BASIC_MODULE_H
Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
StringRef Filename
Definition: Format.cpp:2976
llvm::MachO::Target Target
Definition: MachO.h:51
SourceLocation Loc
Definition: SemaObjC.cpp:758
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...
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...
Definition: LangOptions.h:461
Describes a module or submodule.
Definition: Module.h:105
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Module.h:676
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:319
unsigned IsExplicit
Whether this is an explicit submodule.
Definition: Module.h:328
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition: Module.h:415
bool isForBuilding(const LangOptions &LangOpts) const
Determine whether this module can be built in this compilation.
Definition: Module.cpp:160
std::variant< std::monostate, FileEntryRef, DirectoryEntryRef > Umbrella
The umbrella header or directory.
Definition: Module.h:166
Module * findOrInferSubmodule(StringRef Name)
Definition: Module.cpp:365
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:350
Module * findSubmodule(StringRef Name) const
Find the submodule with the given name.
Definition: Module.cpp:357
static const int NumHeaderKinds
Definition: Module.h:246
bool directlyUses(const Module *Requested)
Determine whether this module has declared its intention to directly use another module.
Definition: Module.cpp:293
bool isNamedModuleInterfaceHasInit() const
Definition: Module.h:628
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:472
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
Definition: Module.h:398
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
Definition: Module.h:305
bool isInterfaceOrPartition() const
Definition: Module.h:615
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition: Module.h:395
bool isModulePartitionImplementation() const
Is this a module partition implementation unit.
Definition: Module.h:603
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Module.h:387
@ Hidden
All of the names in this module are hidden.
Definition: Module.h:389
@ AllVisible
All of the names in this module are visible.
Definition: Module.h:391
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:482
bool isNamedModuleUnit() const
Is this a C++20 named module unit.
Definition: Module.h:620
SourceLocation DefinitionLoc
The location of the module definition.
Definition: Module.h:111
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:285
Module * Parent
The parent of this module.
Definition: Module.h:154
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
Definition: Module.cpp:331
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:281
ModuleKind Kind
The kind of this module.
Definition: Module.h:150
bool isPrivateModule() const
Definition: Module.h:210
@ HK_PrivateTextual
Definition: Module.h:243
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Definition: Module.h:716
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition: Module.h:506
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
Definition: Module.cpp:260
Module * getPrivateModuleFragment() const
Get the Private Module Fragment (sub-module) for this module, it there is one.
Definition: Module.cpp:391
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:265
void setASTFile(OptionalFileEntryRef File)
Set the serialized AST file for the top-level module of this module.
Definition: Module.h:686
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition: Module.h:343
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:402
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:772
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition: Module.h:333
bool isModuleInterfaceUnit() const
Definition: Module.h:624
static StringRef getModuleInputBufferName()
Definition: Module.h:796
std::string Name
The name of this module.
Definition: Module.h:108
Module * getGlobalModuleFragment() const
Get the Global Module Fragment (sub-module) for this module, it there is one.
Definition: Module.cpp:380
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
Definition: Module.h:578
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:783
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition: Module.h:339
bool isModuleMapModule() const
Definition: Module.h:212
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
Definition: Module.h:378
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:464
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Module.h:433
void setParent(Module *M)
Set the parent of this module.
Definition: Module.h:584
std::optional< Header > getUmbrellaHeaderAsWritten() const
Retrieve the umbrella header as written.
Definition: Module.h:700
unsigned getVisibilityID() const
Definition: Module.h:778
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Module.h:296
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
Definition: Module.h:592
bool isModuleImplementation() const
Is this a module implementation.
Definition: Module.h:608
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:443
std::string UmbrellaRelativeToRootModuleDirectory
Definition: Module.h:175
OptionalDirectoryEntryRef Directory
The build directory of this module.
Definition: Module.h:159
std::vector< Module * >::iterator submodule_iterator
Definition: Module.h:780
llvm::iterator_range< submodule_const_iterator > submodules() const
Definition: Module.h:786
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition: Module.h:439
unsigned NamedModuleHasInit
Whether this C++20 named modules doesn't need an initializer.
Definition: Module.h:383
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition: Module.h:373
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
Definition: Module.h:631
bool isModulePartition() const
Is this a module partition.
Definition: Module.h:597
llvm::SmallSetVector< Module *, 2 > AffectingClangModules
The set of top-level modules that affected the compilation of this module, but were not imported.
Definition: Module.h:406
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition: Module.h:436
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:368
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
Definition: Module.h:163
std::string APINotesFile
For the debug info, the path to this module's .apinotes file, if any.
Definition: Module.h:182
ASTFileSignature Signature
The module signature.
Definition: Module.h:169
bool isExplicitGlobalModule() const
Definition: Module.h:203
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
Definition: Module.h:200
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition: Module.h:360
bool isSubModule() const
Determine whether this module is a submodule.
Definition: Module.h:555
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
Definition: Module.cpp:402
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Module.h:485
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition: Module.h:320
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
Definition: Module.cpp:198
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:568
ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition: Module.cpp:282
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition: Module.h:529
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:412
std::optional< DirectoryName > getUmbrellaDirAsWritten() const
Retrieve the umbrella directory as written.
Definition: Module.h:692
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
Definition: Module.h:309
bool isImplicitGlobalModule() const
Definition: Module.h:206
bool isHeaderUnit() const
Is this module a header unit.
Definition: Module.h:613
@ ModuleImplementationUnit
This is a C++20 module implementation unit.
Definition: Module.h:128
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
Definition: Module.h:119
@ ImplicitGlobalModuleFragment
This is an implicit fragment of the global module which contains only language linkage declarations (...
Definition: Module.h:146
@ ModulePartitionInterface
This is a C++20 module partition interface.
Definition: Module.h:131
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
Definition: Module.h:125
@ ModuleHeaderUnit
This is a C++20 header unit.
Definition: Module.h:122
@ ModulePartitionImplementation
This is a C++20 module partition implementation.
Definition: Module.h:134
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
Definition: Module.h:141
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
Definition: Module.h:138
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:299
unsigned IsFramework
Whether this is a framework module.
Definition: Module.h:324
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition: Module.h:179
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:244
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition: Module.h:185
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Definition: Module.h:172
void addTopHeader(FileEntryRef File)
Add a top-level header associated with this module.
Definition: Module.cpp:277
std::vector< Module * >::const_iterator submodule_const_iterator
Definition: Module.h:781
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition: Module.h:316
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:355
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:666
OptionalFileEntryRef getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Module.h:681
OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const
Get the effective umbrella directory for this module: either the one explicitly written in the module...
Definition: Module.cpp:269
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
Definition: Module.h:468
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:497
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:218
A set of visible modules.
Definition: Module.h:811
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:855
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:848
SourceLocation getImportLoc(const Module *M) const
Get the location at which the import of a module was triggered.
Definition: Module.h:840
bool isVisible(const Module *M) const
Determine whether a module is visible.
Definition: Module.h:835
unsigned getGeneration() const
Get the current visibility generation.
Definition: Module.h:832
VisibleModuleSet & operator=(VisibleModuleSet &&O)
Move from another visible modules set.
Definition: Module.h:822
VisibleModuleSet(VisibleModuleSet &&O)
Definition: Module.h:814
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
Definition: Module.cpp:681
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
#define bool
Definition: stdbool.h:24
The signature of a module, which is a hash of the AST content.
Definition: Module.h:57
uint64_t truncatedValue() const
Returns the value truncated to the size of an uint64_t.
Definition: Module.h:67
static constexpr size_t size
Definition: Module.h:60
static ASTFileSignature create(std::array< uint8_t, 20 > Bytes)
Definition: Module.h:75
ASTFileSignature(BaseT S={{0}})
Definition: Module.h:62
static ASTFileSignature createDummy()
Definition: Module.h:85
std::array< uint8_t, 20 > BaseT
Definition: Module.h:58
static ASTFileSignature createDISentinel()
Definition: Module.h:79
static ASTFileSignature create(InputIt First, InputIt Last)
Definition: Module.h:92
A conflict between two modules.
Definition: Module.h:488
Module * Other
The module that this module conflicts with.
Definition: Module.h:490
std::string Message
The message provided to the user when there is a conflict.
Definition: Module.h:493
Information about a directory name as found in the module map file.
Definition: Module.h:258
std::string PathRelativeToRootModuleDirectory
Definition: Module.h:260
DirectoryEntryRef Entry
Definition: Module.h:261
std::string NameAsWritten
Definition: Module.h:259
Information about a header directive as found in the module map file.
Definition: Module.h:250
std::string PathRelativeToRootModuleDirectory
Definition: Module.h:252
std::string NameAsWritten
Definition: Module.h:251
FileEntryRef Entry
Definition: Module.h:253
A library or framework to link against when an entity from this module is used.
Definition: Module.h:447
bool IsFramework
Whether this is a framework rather than a library.
Definition: Module.h:459
LinkLibrary(const std::string &Library, bool IsFramework)
Definition: Module.h:449
std::string Library
The library to link against.
Definition: Module.h:456
std::string FeatureName
Definition: Module.h:288
An unresolved conflict with another module.
Definition: Module.h:475
std::string Message
The message provided to the user when there is a conflict.
Definition: Module.h:480
ModuleId Id
The (unresolved) module id.
Definition: Module.h:477
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Definition: Module.h:419
bool Wildcard
Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...
Definition: Module.h:429
ModuleId Id
The name of the module.
Definition: Module.h:424
SourceLocation ExportLoc
The location of the 'export' keyword in the module map file.
Definition: Module.h:421
Stored information about a header directive that was found in the module map file but has not been re...
Definition: Module.h:269
std::optional< off_t > Size
Definition: Module.h:275
std::optional< time_t > ModTime
Definition: Module.h:276