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