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