clang: include/clang/Lex/ModuleMap.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_LEX_MODULEMAP_H

15#define LLVM_CLANG_LEX_MODULEMAP_H

16

22#include "llvm/ADT/ArrayRef.h"

23#include "llvm/ADT/DenseMap.h"

24#include "llvm/ADT/DenseSet.h"

25#include "llvm/ADT/PointerIntPair.h"

26#include "llvm/ADT/SmallVector.h"

27#include "llvm/ADT/StringMap.h"

28#include "llvm/ADT/StringRef.h"

29#include "llvm/ADT/StringSet.h"

30#include "llvm/ADT/TinyPtrVector.h"

31#include "llvm/ADT/Twine.h"

32#include

33#include

34#include

35#include

36#include

37

39

46

47

48

50 virtual void anchor();

51

52public:

54

55

56

57

58

59

60

63

64

65

66

68

69

70

71

73};

74

81

83

84

85

87

88

89

90 Module *SourceModule = nullptr;

91

92

93 llvm::SpecificBumpPtrAllocator ModulesAlloc;

94

95

96

98

99

100 llvm::StringMap<Module *> Modules;

101

102

103

104 llvm::DenseMap<const IdentifierInfo *, Module *> CachedModuleLoads;

105

106

108

109

110 unsigned NumCreatedModules = 0;

111

112

113

114 llvm::StringMap<llvm::StringSet<>> PendingLinkAsModule;

115

116public:

117

118

120

121

122

124

125

127

129

130

132

133

134

136

137

139

140

141

142

143

144

145 };

146

147

149

150

152

153

155

156

157

159 llvm::PointerIntPair<Module *, 3, ModuleHeaderRole> Storage;

160

161 public:

164

166 return A.Storage == B.Storage;

167 }

169 return A.Storage != B.Storage;

170 }

171

172

174

175

177

178

182

183

188

189

190

191 explicit operator bool() const {

192 return Storage.getPointer() != nullptr;

193 }

194 };

195

197

198private:

200

201 using HeadersMap = llvm::DenseMap<FileEntryRef, SmallVector<KnownHeader, 1>>;

202

203

204

205 HeadersMap Headers;

206

207

208 mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;

209

210

211 mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>

212 LazyHeadersByModTime;

213

214

215

216

217

218

219

220 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;

221

222

223

224

225

226

227 unsigned CurrentModuleScopeID = 0;

228

229 llvm::DenseMap<Module *, unsigned> ModuleScopeIDs;

230

232

233

234 struct InferredDirectory {

235

236 LLVM_PREFERRED_TYPE(bool)

237 unsigned InferModules : 1;

238

239

240 Attributes Attrs;

241

242

243

245

246

247

249

250 InferredDirectory() : InferModules(false) {}

251 };

252

253

254

255 llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories;

256

257

258

259 llvm::DenseMap<const Module *, FileID> InferredModuleAllowedBy;

260

261 llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;

262

263

264

265 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMap;

266 llvm::DenseMap<const FileEntry *, const modulemap::ModuleMapFile *>

267 ParsedModuleMap;

268

269 std::vector<std::unique_ptrmodulemap::ModuleMapFile> ParsedModuleMaps;

270

271

272

273

274 llvm::StringMap<SmallVector<std::pair<const modulemap::ModuleMapFile *,

275 const modulemap::ModuleDecl *>,

276 1>>

277 ParsedModules;

278

279

280

281

282

283

284

285

286

287

288

289

290

292 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,

293 bool Complain) const;

294

295

296

297

298

299

300

301

302

303

304

305

306 Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const;

307

308

309

310

311

312

313

314

315 void addUnresolvedHeader(Module *Mod,

316 Module::UnresolvedHeaderDirective Header,

317 bool &NeedsFramework);

318

319

320

321

322

323

324

325

326

327

329 findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,

330 SmallVectorImpl &RelativePathName, bool &NeedsFramework);

331

332

333

334

335

336

337

338 void resolveHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,

339 bool &NeedsFramework);

340

341

342

343

344 bool resolveAsBuiltinHeader(Module *M,

345 const Module::UnresolvedHeaderDirective &Header);

346

347

348

349

350

351

352 HeadersMap::iterator findKnownHeader(FileEntryRef File);

353

354

355

356

357

358

359

360 KnownHeader findHeaderInUmbrellaDirs(

361 FileEntryRef File, SmallVectorImpl &IntermediateDirs);

362

363

364

365 KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File);

366

367

368

369 bool isHeaderInUmbrellaDirs(FileEntryRef File) {

371 return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));

372 }

373

374 Module *inferFrameworkModule(DirectoryEntryRef FrameworkDir, Attributes Attrs,

376

377public:

378

379

380

381

382

383

384

385

386

387

388

389 ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,

390 const LangOptions &LangOpts, const TargetInfo *Target,

391 HeaderSearch &HeaderInfo);

392

393

395

396

398

399

400

402

403

405

406

408

411

412

414 Callbacks.push_back(std::move(Callback));

415 }

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

432 bool AllowExcluded = false);

433

434

435

436

437

438

439

440

442

443

444

446

447

448

449

450

452

453

454

455

457 std::optional<const FileEntry *> File) const;

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

474 bool RequestingModuleIsModuleInterface,

477

478

479

481

482

483

485 const Module *RequestingModule) const;

486

487

488

489

490

491

493

495

497

498

499

500

501

502

503

504

505

506

508

509

510

511

512

513

514

515

516

517

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

535 bool IsFramework,

536 bool IsExplicit);

537

538

540 bool IsFramework, bool IsExplicit) {

541 return findOrCreateModule(Name, Parent, IsFramework, IsExplicit).first;

542 }

543

544

545

547 bool IsExplicit);

548

549

550

551

552

553

554

555

557 Module *Parent = nullptr);

560

561

564

565

566

569

570

571

572

573

574

575

576

578

579

580

581

582

583

585

586

589

590

591

594

595

596

598 Module *ShadowingModule);

599

600

601

602

603

604

606

608 assert(!ExistingModule->Parent && "expected top-level module");

609 assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");

610 return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID;

611 }

612

613

615 auto It = InferredDirectories.find(Dir);

616 return It != InferredDirectories.end() && It->getSecond().InferModules;

617 }

618

619

620

621

622

623

624

625

628

629

630

631

632

633

634

635

636

637

640

642

643

644

645

646

647

648

649

651

652

653

654

655

657 auto I = AdditionalModMaps.find(M);

658 if (I == AdditionalModMaps.end())

659 return nullptr;

660 return &I->second;

661 }

662

664

665

666

667

668

669

670

671

672

674

675

676

677

678

679

680

681

682

684

685

686

687

688

689

690

691

692

694

695

696 void

698 const Twine &NameAsWritten,

699 const Twine &PathRelativeToRootModuleDirectory);

700

701

703 const Twine &NameAsWritten,

704 const Twine &PathRelativeToRootModuleDirectory);

705

706

707

710

711

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736 bool

739 unsigned *Offset = nullptr,

741

742

744

746

749 llvm::iterator_range<module_iterator> modules() const {

751 }

752

753

755 CachedModuleLoads[&II] = M;

756 }

757

758

760 auto I = CachedModuleLoads.find(&II);

761 if (I == CachedModuleLoads.end())

762 return std::nullopt;

763 return I->second;

764 }

765};

766

767}

768

769#endif

std::shared_ptr< TokenRole > Role

A token can have a special role that can carry extra information about the token's formatting.

Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.

Defines the clang::LangOptions interface.

Defines the clang::Module class, which describes a module in the source code.

Defines the clang::SourceLocation class and associated facilities.

Concrete class used by the front-end to report problems and issues.

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

Cached information about one directory (either on disk or in the virtual file system).

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

Cached information about one file (either on disk or in the virtual file system).

An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...

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

One of these records is kept for each identifier that is lexed.

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

A mechanism to observe the actions of the module map loader as it reads module map files.

Definition ModuleMap.h:49

virtual void moduleMapFileRead(SourceLocation FileStart, FileEntryRef File, bool IsSystem)

Called when a module map file has been read.

Definition ModuleMap.h:61

virtual ~ModuleMapCallbacks()=default

virtual void moduleMapAddHeader(StringRef Filename)

Called when a header is added during module map parsing.

Definition ModuleMap.h:67

virtual void moduleMapAddUmbrellaHeader(FileEntryRef Header)

Called when an umbrella header is added during module map parsing.

Definition ModuleMap.h:72

Definition ModuleMap.h:75

Module * createShadowedModule(StringRef Name, bool IsFramework, Module *ShadowingModule)

Create a new top-level module that is shadowed by ShadowingModule.

bool resolveExports(Module *Mod, bool Complain)

Resolve all of the unresolved exports in the given module.

void addLinkAsDependency(Module *Mod)

Make module to use export_as as the link dependency name if enough information is available or add it...

friend class ModuleMapLoader

Definition ModuleMap.h:199

void dump()

Dump the contents of the module map, for debugging purposes.

std::pair< Module *, bool > findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)

Find a new module or submodule, or create it if it does not already exist.

llvm::StringMap< Module * >::const_iterator module_iterator

Definition ModuleMap.h:745

void setUmbrellaDirAsWritten(Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)

Sets the umbrella directory of the given module to the given directory.

void diagnoseHeaderInclusion(Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, FileEntryRef File)

Reports errors if a module must not include a specific file.

void addAdditionalModuleMapFile(const Module *M, FileEntryRef ModuleMap)

OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const

static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role)

Convert a header role to a kind.

Module * findModule(StringRef Name) const

Retrieve a module with the given name.

void finishModuleDeclarationScope()

Creates a new declaration scope for module names, allowing previously defined modules to shadow defin...

Definition ModuleMap.h:605

bool canInferFrameworkModule(const DirectoryEntry *Dir) const

Check whether a framework module can be inferred in the given directory.

Definition ModuleMap.h:614

bool mayShadowNewModule(Module *ExistingModule)

Definition ModuleMap.h:607

bool parseAndLoadModuleMapFile(FileEntryRef File, bool IsSystem, DirectoryEntryRef HomeDir, FileID ID=FileID(), unsigned *Offset=nullptr, SourceLocation ExternModuleLoc=SourceLocation())

Load the given module map file, and record any modules we encounter.

KnownHeader findModuleForHeader(FileEntryRef File, bool AllowTextual=false, bool AllowExcluded=false)

Retrieve the module that owns the given header file, if any.

Module * createHeaderUnit(SourceLocation Loc, StringRef Name, Module::Header H)

Create a C++20 header unit.

void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)

Add a module map callback.

Definition ModuleMap.h:413

void setBuiltinIncludeDir(DirectoryEntryRef Dir)

Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath....

Definition ModuleMap.h:401

static bool isModular(ModuleHeaderRole Role)

Check if the header with the given role is a modular one.

bool resolveConflicts(Module *Mod, bool Complain)

Resolve all of the unresolved conflicts in the given module.

bool isHeaderUnavailableInModule(FileEntryRef Header, const Module *RequestingModule) const

Determine whether the given header is unavailable as part of the specified module.

void resolveHeaderDirectives(const FileEntry *File) const

Resolve all lazy header directives for the specified file.

module_iterator module_begin() const

Definition ModuleMap.h:747

ArrayRef< KnownHeader > findResolvedModulesForHeader(FileEntryRef File) const

Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if w...

OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const

bool shouldImportRelativeToBuiltinIncludeDir(StringRef FileName, Module *Module) const

Module * createModuleForImplementationUnit(SourceLocation Loc, StringRef Name)

Create a new module for a C++ module implementation unit.

ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo)

Construct a new module map.

std::optional< Module * > getCachedModuleLoad(const IdentifierInfo &II)

Return a cached module load.

Definition ModuleMap.h:759

std::error_code canonicalizeModuleMapPath(SmallVectorImpl< char > &Path)

Canonicalize Path in a manner suitable for a module map file.

FileID getModuleMapFileIDForUniquing(const Module *M) const

Get the module map file that (along with the module name) uniquely identifies this module.

void setInferredModuleAllowedBy(Module *M, FileID ModMapFID)

void setUmbrellaHeaderAsWritten(Module *Mod, FileEntryRef UmbrellaHeader, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)

Sets the umbrella header of the given module to the given header.

llvm::DenseSet< FileEntryRef > AdditionalModMapsSet

Definition ModuleMap.h:196

Module * findOrCreateModuleFirst(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)

Call ModuleMap::findOrCreateModule and throw away the information whether the module was found or cre...

Definition ModuleMap.h:539

Module * lookupModuleUnqualified(StringRef Name, Module *Context) const

Retrieve a module with the given name using lexical name lookup, starting at the given context.

bool isBuiltinHeader(FileEntryRef File)

Is this a compiler builtin header?

Module * createModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)

Create new submodule, assuming it does not exist.

module_iterator module_end() const

Definition ModuleMap.h:748

AdditionalModMapsSet * getAdditionalModuleMapFiles(const Module *M)

Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-le...

Definition ModuleMap.h:656

bool isHeaderInUnavailableModule(FileEntryRef Header) const

Determine whether the given header is part of a module marked 'unavailable'.

FileID getContainingModuleMapFileID(const Module *Module) const

Retrieve the module map file containing the definition of the given module.

OptionalDirectoryEntryRef getBuiltinDir() const

Get the directory that contains Clang-supplied include files.

Definition ModuleMap.h:404

~ModuleMap()

Destroy the module map.

bool parseModuleMapFile(FileEntryRef File, bool IsSystem, DirectoryEntryRef Dir, FileID ID=FileID(), SourceLocation ExternModuleLoc=SourceLocation())

Parse a module map without creating clang::Module instances.

Module * createGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent=nullptr)

Create a global module fragment for a C++ module unit.

void setTarget(const TargetInfo &Target)

Set the target information.

Module * lookupModuleQualified(StringRef Name, Module *Context) const

Retrieve a module with the given name within the given context, using direct (qualified) name lookup.

void resolveLinkAsDependencies(Module *Mod)

Use PendingLinkAsModule information to mark top level link names that are going to be replaced by exp...

void cacheModuleLoad(const IdentifierInfo &II, Module *M)

Cache a module load. M might be nullptr.

Definition ModuleMap.h:754

ModuleHeaderRole

Flags describing the role of a module header.

Definition ModuleMap.h:126

@ PrivateHeader

This header is included but private.

Definition ModuleMap.h:131

@ ExcludedHeader

This header is explicitly excluded from the module.

Definition ModuleMap.h:138

@ NormalHeader

This header is normally included in the module.

Definition ModuleMap.h:128

@ TextualHeader

This header is part of the module (for layering purposes) but should be textually included.

Definition ModuleMap.h:135

Module * createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name)

Create a new module for a C++ module interface unit.

void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)

Adds this header to the given module.

Module * createPrivateModuleFragmentForInterfaceUnit(Module *Parent, SourceLocation Loc)

Create a global module fragment for a C++ module interface unit.

Module * findOrInferSubmodule(Module *Parent, StringRef Name)

ArrayRef< KnownHeader > findAllModulesForHeader(FileEntryRef File)

Retrieve all the modules that contain the given header file.

Module * createImplicitGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent)

Module * createModuleUnitWithKind(SourceLocation Loc, StringRef Name, Module::ModuleKind Kind)

Create a new C++ module with the specified kind, and reparent any pending global module fragment(s) t...

Module * findOrLoadModule(StringRef Name)

static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind)

Convert a header kind to a role. Requires Kind to not be HK_Excluded.

llvm::iterator_range< module_iterator > modules() const

Definition ModuleMap.h:749

bool resolveUses(Module *Mod, bool Complain)

Resolve all of the unresolved uses in the given module.

Describes a module or submodule.

Module * Parent

The parent of 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.

Module * getTopLevelModule()

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

Encodes a location in the source.

This class handles loading and caching of source files into memory.

Exposes information about the current target.

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

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId

Describes the name of a module.

nullptr

This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...

@ Module

Module linkage, which indicates that the entity can be referred to from other translation units withi...

CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef

The set of attributes that can be attached to a module.