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