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

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_CLANG_LEX_HEADERSEARCH_H

14#define LLVM_CLANG_LEX_HEADERSEARCH_H

15

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

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

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

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

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

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

28#include "llvm/Support/Allocator.h"

29#include

30#include

31#include

32#include

33#include

34#include

35

36namespace llvm {

37

38class Triple;

39

40}

41

43

44class DiagnosticsEngine;

45class DirectoryEntry;

46class ExternalPreprocessorSource;

47class FileEntry;

48class FileManager;

50class HeaderSearchOptions;

51class IdentifierInfo;

52class LangOptions;

54class Preprocessor;

55class TargetInfo;

56

57

58

60

61

62

63 LLVM_PREFERRED_TYPE(bool)

65

66

67

68

69 LLVM_PREFERRED_TYPE(bool)

71

72

73 LLVM_PREFERRED_TYPE(bool)

75

76

77

78

79

80 LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)

82

83

84

85 LLVM_PREFERRED_TYPE(bool)

87

88

89

90

91 LLVM_PREFERRED_TYPE(bool)

93

94

95

96

97 LLVM_PREFERRED_TYPE(bool)

99

100

101

102

103 LLVM_PREFERRED_TYPE(bool)

105

106

107

108 LLVM_PREFERRED_TYPE(bool)

110

111

112 LLVM_PREFERRED_TYPE(bool)

114

115

116

117

118

119

120

121

122

124

130

131

132

135

136

137

138

139

141};

142

143static_assert(sizeof(HeaderFileInfo) <= 16);

144

145

146

148public:

150

151

152

153

154

155

157};

158

159

161

163

164

165

166

168};

169

170namespace detail {

171template <bool Const, typename T>

172using Qualified = std::conditional_t<Const, const T, T>;

173

174

175template

177 : llvm::iterator_facade_base<SearchDirIteratorImpl,

178 std::forward_iterator_tag,

179 Qualified<IsConst, DirectoryLookup>> {

180

181 template <typename Enable = std::enable_if<IsConst, bool>>

184

186

188

190 return HS == RHS.HS && Idx == RHS.Idx;

191 }

192

194 assert(*this && "Invalid iterator.");

195 ++Idx;

196 return *this;

197 }

198

200 assert(*this && "Invalid iterator.");

201 return HS->SearchDirs[Idx];

202 }

203

204

206

207

208 explicit operator bool() const { return HS != nullptr; }

209

210private:

211

213

214

215 size_t Idx;

216

217

219 : HS(&HS), Idx(Idx) {}

220

221

223

224

225 friend SearchDirIteratorImpl<!IsConst>;

226};

227}

228

231

234

235

236

239

242

243

244 std::shared_ptr HSOpts;

245

246

247 llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry;

248

251

252

253

254

255

256 std::vector SearchDirs;

257

258

259 std::vector SearchDirsUsage;

260 unsigned AngledDirIdx = 0;

261 unsigned SystemDirIdx = 0;

262

263

264

265

266 llvm::StringMap<unsigned, llvm::BumpPtrAllocator> SearchDirHeaderMapIndex;

267

268

269 unsigned FirstNonHeaderMapSearchDirIdx = 0;

270

271

272

273

274

275

276

277 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;

278

279

280 std::string ModuleHash;

281

282

283 std::string ModuleCachePath;

284

285

286

287 mutable std::vector FileInfo;

288

289

290 struct LookupFileCacheInfo {

291

292 const Module *RequestingModule = nullptr;

293

294

295

296

298

299

301

302

303

304 const char *MappedName = nullptr;

305

306

307 LookupFileCacheInfo() = default;

308

309 void reset(const Module *NewRequestingModule,

311 RequestingModule = NewRequestingModule;

312 StartIt = NewStartIt;

313 MappedName = nullptr;

314 }

315 };

316 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;

317

318

319

320 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;

321

322

323

324

325 using IncludeAliasMap =

326 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;

327 std::unique_ptr IncludeAliases;

328

329

330 std::vector<std::pair<FileEntryRef, std::unique_ptr>> HeaderMaps;

331

332

333 mutable ModuleMap ModMap;

334

335

336 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;

337

338

339

340 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;

341

342

343 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;

344

345

346

347 llvm::StringSetllvm::BumpPtrAllocator FrameworkNames;

348

349

350

351

352 ExternalPreprocessorSource *ExternalLookup = nullptr;

353

354

355 ExternalHeaderFileInfoSource *ExternalSource = nullptr;

356

357

358

359 void indexInitialHeaderMaps();

360

361public:

362 HeaderSearch(std::shared_ptr HSOpts,

363 SourceManager &SourceMgr, DiagnosticsEngine &Diags,

364 const LangOptions &LangOpts, const TargetInfo *Target);

367

368

369

371

373

375

376

377 void SetSearchPaths(std::vector dirs, unsigned angledDirIdx,

378 unsigned systemDirIdx,

379 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);

380

381

383

384

386 SearchDirs.push_back(dir);

387 SearchDirsUsage.push_back(false);

388 }

389

390

392 SystemHeaderPrefixes.assign(P.begin(), P.end());

393 }

394

395

397

398

399

400

401

403 if (!IncludeAliases)

404 IncludeAliases.reset(new IncludeAliasMap);

405 (*IncludeAliases)[Source] = std::string(Dest);

406 }

407

408

409

410

411

413 assert(IncludeAliases && "Trying to map headers when there's no map");

414

415

416 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);

417 if (Iter != IncludeAliases->end())

418 return Iter->second;

419 return {};

420 }

421

422

423 void setModuleHash(StringRef Hash) { ModuleHash = std::string(Hash); }

424

425

427 ModuleCachePath = std::string(CachePath);

428 }

429

430

432

433

435

436

438 DirectoryHasModuleMap[Dir] = true;

439 }

440

441

443 FileInfo.clear();

444 }

445

447 ExternalLookup = EPS;

448 }

449

451 return ExternalLookup;

452 }

453

454

457 }

458

459

460

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

501 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,

504 bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false,

505 bool BuildSystemModule = false, bool OpenFile = true,

506 bool CacheFailures = true);

507

508

509

510

511

512

513

518

519

520

522 return FrameworkMap[FWName];

523 }

524

525

526

527

528

529

530

531

532

534 bool isImport, bool ModulesEnabled, Module *M,

535 bool &IsFirstIncludeOfFile);

536

537

538

543 }

544

545

546

549 }

550

551

552

555 }

556

557

559 bool isCompilingModuleHeader);

560

561

562

563

564

568 }

569

570

571

572

573

574

576

577

581 }

582

583

584

585

587

588

589

590

591

592

594

595

596

598

599

601

602

603

604

605

606

607

608

610

611

612

613

614

615

616

617

618

619

620

622 bool FileMapOnly = false);

623

624

625

626

627

628

629

630

632

633

634

635

636

637

638

639

640

641

642

644 StringRef ModuleMapPath);

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

662 bool AllowSearch = true,

663 bool AllowExtraModuleMapSearch = false);

664

665

666

668 bool IsFramework);

669

670

671

672

673

674

675

676

677

678

679

680

682 bool IsSystem);

683

684

685

686

687

689 bool AllowTextual = false,

690 bool AllowExcluded = false) const;

691

692

693

694

697

698

699

702

703

704

705

706

707

708

709

710

711

712

713

714

715

717 unsigned *Offset = nullptr,

718 StringRef OriginalModuleMapFile = StringRef());

719

720

721

722

724

725

727

728private:

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

746 bool AllowExtraModuleMapSearch = false);

747

748

749

750

751

752

753

754

755

756

757

758

759

760 std::string getCachedModuleFileNameImpl(StringRef ModuleName,

761 StringRef ModuleMapPath,

762 StringRef CachePath);

763

764

765

766

767

768

769

770

771

772

773

774

776 bool IsSystem);

777

778

779

780 void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir);

781

782

783

784

785

787 Module *RequestingModule,

789 bool IsSystemHeaderDir);

790

791

792

793

794

795

796 bool findUsableModuleForFrameworkHeader(

799

800

801

805 Module *RequestingModule,

807 bool OpenFile = true, bool CacheFailures = true);

808

809

810

811 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,

814

815

816

817 void noteLookupUsage(unsigned HitIdx, SourceLocation IncludeLoc);

818

819public:

820

822

823

825

827

828

829

831

832

833

835

836

837

839

844 }

845

848 assert(n < SearchDirs.size());

849 return {*this, n};

850 }

854 }

855

857

860

862 return {*this, AngledDirIdx};

863 }

865

867 return {*this, SystemDirIdx};

868 }

870 return {*this, SearchDirs.size()};

871 }

872

873

875

876

878

879

880

881

882

883

885

886

887

888

889

890

891

892

893

894

896 llvm::StringRef MainFile,

897 bool *IsAngled = nullptr) const;

898

899

900

901

902

903

904

905

906

907

909 llvm::StringRef WorkingDir,

910 llvm::StringRef MainFile,

911 bool *IsAngled = nullptr) const;

912

914

916

917private:

918

919 enum LoadModuleMapResult {

920

921 LMM_AlreadyLoaded,

922

923

924 LMM_NewlyLoaded,

925

926

927 LMM_NoDirectory,

928

929

930

931 LMM_InvalidModuleMap

932 };

933

934 LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,

935 DirectoryEntryRef Dir,

936 FileID ID = FileID(),

937 unsigned *Offset = nullptr);

938

939

940

941

942

943

944

945

946

947

948 LoadModuleMapResult loadModuleMapFile(StringRef DirName, bool IsSystem,

949 bool IsFramework);

950

951

952

953

954

955

956

957

958

959 LoadModuleMapResult loadModuleMapFile(DirectoryEntryRef Dir, bool IsSystem,

960 bool IsFramework);

961};

962

963

965 const HeaderSearchOptions &HSOpts,

966 const LangOptions &Lang,

967 const llvm::Triple &triple);

968

969}

970

971#endif

llvm::MachO::Target Target

Defines the clang::SourceLocation class and associated facilities.

Defines the SourceManager interface.

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).

DirectoryLookup - This class represents one entry in the search list that specifies the search order ...

Abstract interface for external sources of preprocessor information.

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.

ModuleHeaderRole

Flags describing the role of a module header.

Describes a module or submodule.

Engages in a tight little dance with the lexer to efficiently preprocess tokens.

Encodes a location in the source.

Exposes information about the current target.

CharacteristicKind

Indicates whether a file or directory holds normal user code, system code, or system code which is im...

std::conditional_t< Const, const T, T > Qualified

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

void ApplyHeaderSearchOptions(HeaderSearch &HS, const HeaderSearchOptions &HSOpts, const LangOptions &Lang, const llvm::Triple &triple)

Apply the header search options to get given HeaderSearch object.

llvm::iterator_range< SearchDirIterator > SearchDirRange

@ Module

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

@ Other

Other implicit parameter.

llvm::iterator_range< ConstSearchDirIterator > ConstSearchDirRange

Diagnostic wrappers for TextAPI types for error reporting.

This structure is used to record entries in our framework cache.

bool IsUserSpecifiedSystemFramework

Whether this framework has been "user-specified" to be treated as if it were a system framework (even...

OptionalDirectoryEntryRef Directory

The directory entry which should be used for the cached framework.

Forward iterator over the search directories of HeaderSearch.

SearchDirIteratorImpl(std::nullptr_t)

Creates an invalid iterator.

Qualified< IsConst, DirectoryLookup > & operator*() const

bool operator==(const SearchDirIteratorImpl &RHS) const

SearchDirIteratorImpl(const SearchDirIteratorImpl< false > &Other)

Const -> non-const iterator conversion.

SearchDirIteratorImpl & operator++()

SearchDirIteratorImpl & operator=(const SearchDirIteratorImpl &)=default

SearchDirIteratorImpl(const SearchDirIteratorImpl &)=default