clang: include/clang/Basic/Module.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

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

31#include

32#include

33#include

34#include

35#include

36#include

37#include

38#include

39#include

40

41namespace llvm {

42

43class raw_ostream;

44

45}

46

48

49class FileManager;

50class LangOptions;

51class ModuleMap;

52class TargetInfo;

53

54

56

57

59 using BaseT = std::array<uint8_t, 20>;

60

61 static constexpr size_t size = std::tuple_size::value;

62

64

65 explicit operator bool() const { return *this != BaseT({{0}}); }

66

67

69 uint64_t Value = 0;

70 static_assert(sizeof(*this) >= sizeof(uint64_t), "No need to truncate.");

71 for (unsigned I = 0; I < sizeof(uint64_t); ++I)

72 Value |= static_cast<uint64_t>((*this)[I]) << (I * 8);

74 }

75

78 }

79

82 Sentinel.fill(0xFF);

83 return Sentinel;

84 }

85

88 Dummy.fill(0x00);

89 return Dummy;

90 }

91

92 template

95 "Wrong amount of bytes to create an ASTFileSignature");

96

98 std::copy(First, Last, Signature.begin());

99 return Signature;

100 }

101};

102

103

104

105

106

110};

111

112

113

114

116public:

117

119

120

122

123

124

125

127

128

130

131

133

134

136

137

139

140

142

143

145

146

147

149

150

152

153

154

155

157 };

158

159

161

162

163

165

166

167

168

170

171

172

174

175

176 std::variant<std::monostate, FileEntryRef, DirectoryEntryRef> Umbrella;

177

178

180

181

183

184

186

187

188

190

191

193

194

196 switch (Kind) {

202 return true;

203 default:

204 return false;

205 }

206 }

207

208

209

212 }

215 }

218 }

219

221

223

224private:

225

226 std::vector<Module *> SubModules;

227

228

229

230 mutable llvm::StringMap SubModuleIndex;

231

232

233

235

236

238

239

240 std::vectorstd::string TopHeaderNames;

241

242

243 mutable llvm::DenseSet<const Module*> VisibleModulesCache;

244

245

246 unsigned VisibilityID;

247

248public:

256

257

262 };

263

264private:

265 static const int NumHeaderKinds = HK_Excluded + 1;

266

267

268 unsigned HeaderKindBeginIndex[NumHeaderKinds + 1] = {};

270

271public:

274 assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");

275 auto BeginIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK];

276 auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];

277 return {BeginIt, EndIt};

278 }

280 assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");

281 auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];

282 HeadersStorage.insert(EndIt, std::move(H));

283 for (unsigned HKI = HK + 1; HKI != NumHeaderKinds + 1; ++HKI)

284 ++HeaderKindBeginIndex[HKI];

285 }

286

287

292 };

293

294

295

302 std::optional<off_t> Size;

304 };

305

306

307

309

310

311

313

317 };

318

319

320

321

322

324

325

327

328

329

330

331 LLVM_PREFERRED_TYPE(bool)

333

334

335 LLVM_PREFERRED_TYPE(bool)

337

338

339

340

341

342 LLVM_PREFERRED_TYPE(bool)

344

345

346 LLVM_PREFERRED_TYPE(bool)

348

349

350 LLVM_PREFERRED_TYPE(bool)

352

353

354 LLVM_PREFERRED_TYPE(bool)

356

357

358

359 LLVM_PREFERRED_TYPE(bool)

361

362

363

364

365 LLVM_PREFERRED_TYPE(bool)

367

368

369 LLVM_PREFERRED_TYPE(bool)

371

372

373

374

375

376 LLVM_PREFERRED_TYPE(bool)

378

379

380

381 LLVM_PREFERRED_TYPE(bool)

383

384

385

386 LLVM_PREFERRED_TYPE(bool)

388

389

390

391

392

393

394 LLVM_PREFERRED_TYPE(bool)

396

397

398

399 LLVM_PREFERRED_TYPE(bool)

401

402

403

404 LLVM_PREFERRED_TYPE(bool)

406

407

408

409 LLVM_PREFERRED_TYPE(bool)

411

412

413

415

417

420

421

423

424

426

427

428

430

431

432

434

435

436

437

438

439 using ExportDecl = llvm::PointerIntPair<Module *, 1, bool>;

440

441

443

444

445

447

449

450

452

453

454

455

457 };

458

459

461

462

464

465

467

468

469

471

472

473

478

479

480

481

482

484

485

487 };

488

489

490

492

493

494

496

497

498

500

501

503

505

506

508 };

509

510

511

513

514

516

518

519

521 };

522

523

525

526

529 unsigned VisibilityID);

530

532

533

535

536

537

538

539

540

541

542

543

544

545

546

547

548

551

552

554

555

556

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

578 Requirement &Req,

579 UnresolvedHeaderDirective &MissingHeader,

581

582

584

585

586

587

588

589

590

592

593

594

595

597 for (const Module *Mod = this; Mod; Mod = Mod->Parent)

598 if (Mod->IsFramework)

599 return true;

600

601 return false;

602 }

603

604

605

608 }

609

610

611

615 Parent->SubModules.push_back(this);

616 }

617

618

621 }

622

623

627 }

628

629

632 }

633

634

637 }

638

639

641

644 }

645

646

649 }

650

653 }

654

656

657

659

660

661

662

663

664

666 return "";

667

669 auto pos = Name.find(':');

670 return StringRef(Name.data(), pos);

671 }

672

675

677 }

678

679

680

681

682

683 std::string getFullModuleName(bool AllowStringLiterals = false) const;

684

685

686

687

688

690

691

692

694 return const_cast<Module *>(

696 }

697

698

699

701

702

705 }

706

707

710 }

711

712

716 }

717

718

720 if (const auto *Dir = std::get_if(&Umbrella))

723 return std::nullopt;

724 }

725

726

728 if (const auto *Hdr = std::get_if(&Umbrella))

730 *Hdr};

731 return std::nullopt;

732 }

733

734

735

736

738

739

741

742

744 TopHeaderNames.push_back(std::string(Filename));

745 }

746

747

749

750

751

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768 void addRequirement(StringRef Feature, bool RequiredState,

771

772

774

775

776

777

779

780

781

782

783

785

786

787

788

789

791

792

793

794

795

796

797

799 if (VisibleModulesCache.empty())

800 buildVisibleModulesCache();

801 return VisibleModulesCache.count(M);

802 }

803

805

808

809 llvm::iterator_range<submodule_iterator> submodules() {

810 return llvm::make_range(SubModules.begin(), SubModules.end());

811 }

812 llvm::iterator_range<submodule_const_iterator> submodules() const {

813 return llvm::make_range(SubModules.begin(), SubModules.end());

814 }

815

816

817

818

819

821

823 return "";

824 }

825

826

827 void print(raw_ostream &OS, unsigned Indent = 0, bool Dump = false) const;

828

829

830 void dump() const;

831

832private:

833 void buildVisibleModulesCache() const;

834};

835

836

838public:

841 : ImportLocs(std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {

842 O.ImportLocs.clear();

843 ++O.Generation;

844 }

845

846

847

849 ImportLocs = std::move(O.ImportLocs);

850 O.ImportLocs.clear();

851 ++O.Generation;

852 ++Generation;

853 return *this;

854 }

855

856

857

859

860

863 }

864

865

870 }

871

872

873

875

876

877

878

881 StringRef Message)>;

882

883

887 StringRef) {});

888private:

889

890

891 std::vector ImportLocs;

892

893

894 unsigned Generation = 0;

895};

896

897}

898

899#endif

Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.

Defines interfaces for clang::FileEntry and clang::FileEntryRef.

llvm::MachO::Target Target

Defines the clang::SourceLocation class and associated facilities.

A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...

A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...

Implements support for file system lookup, file system caching, and directory search management.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

Required to construct a Module.

Describes a module or submodule.

StringRef getTopLevelModuleName() const

Retrieve the name of the top-level module.

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.

unsigned IsExplicit

Whether this is an explicit submodule.

SmallVector< ExportDecl, 2 > Exports

The set of export declarations.

bool isForBuilding(const LangOptions &LangOpts) const

Determine whether this module can be built in this compilation.

std::variant< std::monostate, FileEntryRef, DirectoryEntryRef > Umbrella

The umbrella header or directory.

unsigned InferSubmodules

Whether we should infer submodules for this module based on the headers.

ArrayRef< Header > getAllHeaders() const

Module * findSubmodule(StringRef Name) const

Find the submodule with the given name.

bool directlyUses(const Module *Requested)

Determine whether this module has declared its intention to directly use another module.

bool isNamedModuleInterfaceHasInit() const

std::vector< std::string > ConfigMacros

The set of "configuration macros", which are macros that (intentionally) change how this module is bu...

SourceLocation InferredSubmoduleLoc

The location of the inferred submodule.

unsigned IsUnimportable

Whether this module has declared itself unimportable, either because it's missing a requirement from ...

bool isInterfaceOrPartition() const

NameVisibilityKind NameVisibility

The visibility of names within this particular module.

bool isModulePartitionImplementation() const

Is this a module partition implementation unit.

NameVisibilityKind

Describes the visibility of the various names within a particular module.

@ Hidden

All of the names in this module are hidden.

@ AllVisible

All of the names in this module are visible.

void print(raw_ostream &OS, unsigned Indent=0, bool Dump=false) const

Print the module map for this module to the given stream.

bool isNamedModuleUnit() const

Is this a C++20 named module unit.

SourceLocation DefinitionLoc

The location of the module definition.

SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders

Headers that are mentioned in the module map file but could not be found on the file system.

Module * Parent

The parent of this module.

void markUnavailable(bool Unimportable)

Mark this module and all of its submodules as unavailable.

SmallVector< UnresolvedHeaderDirective, 1 > UnresolvedHeaders

Headers that are mentioned in the module map file but that we have not yet attempted to resolve to a ...

ModuleKind Kind

The kind of this module.

bool isPrivateModule() const

void addTopHeaderFilename(StringRef Filename)

Add a top-level header filename associated with this module.

bool isUnimportable() const

Determine whether this module has been declared unimportable.

bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const

Whether the full name of this module is equal to joining nameParts with "."s.

Module * getPrivateModuleFragment() const

Get the Private Module Fragment (sub-module) for this module, it there is one.

void setASTFile(OptionalFileEntryRef File)

Set the serialized AST file for the top-level module of this module.

unsigned IsInferred

Whether this is an inferred submodule (module * { ... }).

llvm::SmallSetVector< Module *, 2 > Imports

The set of modules imported by this module, and on which this module depends.

bool isModuleVisible(const Module *M) const

Determine whether the specified module would be visible to a lookup at the end of this module.

unsigned IsSystem

Whether this is a "system" module (which assumes that all headers in it are system headers).

bool isModuleInterfaceUnit() const

static StringRef getModuleInputBufferName()

std::string Name

The name of this module.

Module * getGlobalModuleFragment() const

Get the Global Module Fragment (sub-module) for this module, it there is one.

bool isSubFramework() const

Determine whether this module is a subframework of another framework.

llvm::iterator_range< submodule_iterator > submodules()

unsigned IsExternC

Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...

bool isModuleMapModule() const

unsigned ModuleMapIsPrivate

Whether this module came from a "private" module map, found next to a regular (public) module map.

llvm::SmallVector< LinkLibrary, 2 > LinkLibraries

The set of libraries or frameworks to link against when an entity from this module is used.

SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports

The set of export declarations that have yet to be resolved.

void addHeader(HeaderKind HK, Header H)

void setParent(Module *M)

Set the parent of this module.

std::optional< Header > getUmbrellaHeaderAsWritten() const

Retrieve the umbrella header as written.

unsigned getVisibilityID() const

SmallVector< Requirement, 2 > Requirements

The set of language features required to use this module.

bool isHeaderLikeModule() const

Is this module have similar semantics as headers.

bool isModuleImplementation() const

Is this a module implementation.

llvm::SmallSetVector< const Module *, 2 > UndeclaredUses

When NoUndeclaredIncludes is true, the set of modules this module tried to import but didn't because ...

std::string UmbrellaRelativeToRootModuleDirectory

OptionalDirectoryEntryRef Directory

The build directory of this module.

std::vector< Module * >::iterator submodule_iterator

llvm::iterator_range< submodule_const_iterator > submodules() const

SmallVector< ModuleId, 2 > UnresolvedDirectUses

The set of use declarations that have yet to be resolved.

unsigned NamedModuleHasInit

Whether this C++20 named modules doesn't need an initializer.

unsigned NoUndeclaredIncludes

Whether files in this module can only include non-modular headers and headers from used modules.

StringRef getPrimaryModuleInterfaceName() const

Get the primary module interface name from a partition.

bool isModulePartition() const

Is this a module partition.

llvm::SmallSetVector< Module *, 2 > AffectingClangModules

The set of top-level modules that affected the compilation of this module, but were not imported.

SmallVector< Module *, 2 > DirectUses

The directly used modules.

unsigned ConfigMacrosExhaustive

Whether the set of configuration macros is exhaustive.

std::string PresumedModuleMapFile

The presumed file name for the module map defining this module.

std::string APINotesFile

For the debug info, the path to this module's .apinotes file, if any.

ASTFileSignature Signature

The module signature.

bool isExplicitGlobalModule() const

ArrayRef< Header > getHeaders(HeaderKind HK) const

bool isGlobalModule() const

Does this Module scope describe a fragment of the global module within some C++ module.

unsigned InferExportWildcard

Whether, when inferring submodules, the inferr submodules should export all modules they import (e....

bool isSubModule() const

Determine whether this module is a submodule.

void getExportedModules(SmallVectorImpl< Module * > &Exported) const

Appends this module's list of exported modules to Exported.

std::vector< UnresolvedConflict > UnresolvedConflicts

The list of conflicts for which the module-id has not yet been resolved.

unsigned IsFromModuleFile

Whether this module was loaded from a module file.

bool isSubModuleOf(const Module *Other) const

Check if this module is a (possibly transitive) submodule of Other.

bool isPartOfFramework() const

Determine whether this module is a part of a framework, either because it is a framework module or be...

ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)

The top-level headers associated with this module.

bool isAvailable() const

Determine whether this module is available for use within the current translation unit.

llvm::PointerIntPair< Module *, 1, bool > ExportDecl

Describes an exported module.

std::optional< DirectoryName > getUmbrellaDirAsWritten() const

Retrieve the umbrella directory as written.

unsigned HasIncompatibleModuleFile

Whether we tried and failed to load a module file for this module.

bool isImplicitGlobalModule() const

bool isHeaderUnit() const

Is this module a header unit.

@ ModuleImplementationUnit

This is a C++20 module implementation unit.

@ ModuleMapModule

This is a module that was defined by a module map and built out of header files.

@ ImplicitGlobalModuleFragment

This is an implicit fragment of the global module which contains only language linkage declarations (...

@ ModulePartitionInterface

This is a C++20 module partition interface.

@ ModuleInterfaceUnit

This is a C++20 module interface unit.

@ ModuleHeaderUnit

This is a C++20 header unit.

@ ModulePartitionImplementation

This is a C++20 module partition implementation.

@ PrivateModuleFragment

This is the private module fragment within some C++ module.

@ ExplicitGlobalModuleFragment

This is the explicit Global Module Fragment of a modular TU.

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.

unsigned IsFramework

Whether this is a framework module.

std::string ExportAsModule

The module through which entities defined in this module will eventually be exposed,...

std::string getFullModuleName(bool AllowStringLiterals=false) const

Retrieve the full name of this module, including the path from its top-level module.

bool isNamedModule() const

Does this Module is a named module of a standard named module?

std::string UmbrellaAsWritten

The name of the umbrella entry, as written in the module map.

void addTopHeader(FileEntryRef File)

Add a top-level header associated with this module.

std::vector< Module * >::const_iterator submodule_const_iterator

unsigned IsAvailable

Whether this module is available in the current translation unit.

unsigned InferExplicitSubmodules

Whether, when inferring submodules, the inferred submodules should be explicit.

Module * getTopLevelModule()

Retrieve the top-level module for this (sub)module, which may be this module.

OptionalFileEntryRef getASTFile() const

The serialized AST file for this module, if one was created.

OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const

Get the effective umbrella directory for this module: either the one explicitly written in the module...

bool UseExportAsModuleLinkName

Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...

std::vector< Conflict > Conflicts

The list of conflicts.

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

Exposes information about the current target.

A set of visible modules.

llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback

A callback to call when a module conflict is found.

VisibleModuleSet()=default

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.

SourceLocation getImportLoc(const Module *M) const

Get the location at which the import of a module was triggered.

bool isVisible(const Module *M) const

Determine whether a module is visible.

unsigned getGeneration() const

Get the current visibility generation.

VisibleModuleSet & operator=(VisibleModuleSet &&O)

Move from another visible modules set.

VisibleModuleSet(VisibleModuleSet &&O)

void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})

Make a specific module visible.

The JSON file list parser is used to communicate input to InstallAPI.

@ Other

Other implicit parameter.

Diagnostic wrappers for TextAPI types for error reporting.

The signature of a module, which is a hash of the AST content.

uint64_t truncatedValue() const

Returns the value truncated to the size of an uint64_t.

static constexpr size_t size

static ASTFileSignature create(std::array< uint8_t, 20 > Bytes)

ASTFileSignature(BaseT S={{0}})

static ASTFileSignature createDummy()

std::array< uint8_t, 20 > BaseT

static ASTFileSignature createDISentinel()

static ASTFileSignature create(InputIt First, InputIt Last)

A conflict between two modules.

Module * Other

The module that this module conflicts with.

std::string Message

The message provided to the user when there is a conflict.

Information about a directory name as found in the module map file.

std::string PathRelativeToRootModuleDirectory

std::string NameAsWritten

A library or framework to link against when an entity from this module is used.

bool IsFramework

Whether this is a framework rather than a library.

LinkLibrary(const std::string &Library, bool IsFramework)

std::string Library

The library to link against.

An unresolved conflict with another module.

std::string Message

The message provided to the user when there is a conflict.

ModuleId Id

The (unresolved) module id.

Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...

bool Wildcard

Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...

ModuleId Id

The name of the module.

SourceLocation ExportLoc

The location of the 'export' keyword in the module map file.