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