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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34#ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H

35#define LLVM_CLANG_BASIC_SOURCEMANAGER_H

36

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

42#include "llvm/ADT/BitVector.h"

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

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

45#include "llvm/ADT/IntrusiveRefCntPtr.h"

46#include "llvm/ADT/PagedVector.h"

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

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

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

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

51#include "llvm/Support/Compiler.h"

52#include "llvm/Support/MemoryBuffer.h"

53#include

54#include

55#include

56#include

57#include

58#include

59#include

60#include

61

63

69

70

71

73

74

75

76

77

78

79

80

88

89

93

94

98

99

100

102public:

103 explicit operator bool() const { return Storage; }

105 assert(Storage);

106 return Storage[0];

107 }

109 assert(Storage);

111 }

113 const unsigned *end() const { return getLines().end(); }

115

117 llvm::BumpPtrAllocator &Alloc);

118

121 llvm::BumpPtrAllocator &Alloc);

122

123private:

124

125 unsigned *Storage = nullptr;

126};

127

128

129

130

132

133

134 mutable std::unique_ptrllvm::MemoryBuffer Buffer;

135

136public:

137

138

139

140

141

142

143

144

145

147

148

149

150

151

153

154

155

156

158

159

160

161

162

164

165

166

167

168

169

170 LLVM_PREFERRED_TYPE(bool)

172

173

174

175 LLVM_PREFERRED_TYPE(bool)

177

178

179

180

181 LLVM_PREFERRED_TYPE(bool)

183

184 LLVM_PREFERRED_TYPE(bool)

186

191

193

197

198

199

200

206

208 "Passed ContentCache object cannot own a buffer.");

209 }

210

212

213

214

215

216

217

218

219

220 std::optionalllvm::MemoryBufferRef

223

224

225

226

227

228

229

230 unsigned getSize() const;

231

232

233

234

235

237

238

239

241

242

244 if (Buffer)

245 return Buffer->getMemBufferRef();

246 return std::nullopt;

247 }

248

249

250

252 if (Buffer)

253 return Buffer->getBuffer();

254 return std::nullopt;

255 }

256

257

258 void setBuffer(std::unique_ptrllvm::MemoryBuffer B) {

260 Buffer = std::move(B);

261 }

262

263

264

265

267 assert(!Buffer && "Expected to be called right after construction");

268 if (B)

269 setBuffer(llvm::MemoryBuffer::getMemBuffer(*B));

270 }

271

272

273

274 static const char *getInvalidBOM(StringRef BufStr);

275};

276

277

278

279static_assert(alignof(ContentCache) >= 8,

280 "ContentCache must be 8-byte aligned.");

281

282

283

284

285

286

287

288

289

290

291

292

293

294

299

300

301

302

304

305

306

307

308

309 unsigned NumCreatedFIDs : 31;

310

311

312 LLVM_PREFERRED_TYPE(bool)

313 unsigned HasLineDirectives : 1;

314

315

316 llvm::PointerIntPair<const ContentCache *, 3, CharacteristicKind>

317 ContentAndKind;

318

319public:

320

324 X.IncludeLoc = IL;

325 X.NumCreatedFIDs = 0;

326 X.HasLineDirectives = false;

327 X.ContentAndKind.setPointer(&Con);

328 X.ContentAndKind.setInt(FileCharacter);

330 return X;

331 }

332

334 return IncludeLoc;

335 }

336

338 return *ContentAndKind.getPointer();

339 }

340

341

343 return ContentAndKind.getInt();

344 }

345

346

348

349

350

352

353

354

356};

357

358

359

360

362

363

364

366

367

368

369

370

371

372

374

375

376 bool ExpansionIsTokenRange;

377

378public:

382

384 return ExpansionLocStart;

385 }

386

389 : ExpansionLocEnd;

390 }

391

393

399

404

408

413

414

415

416

417

418

419

422 bool ExpansionIsTokenRange = true) {

424 X.SpellingLoc = SpellingLoc;

425 X.ExpansionLocStart = Start;

426 X.ExpansionLocEnd = End;

427 X.ExpansionIsTokenRange = ExpansionIsTokenRange;

428 return X;

429 }

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

457

458

459

460

461

462

466 return create(SpellingLoc, Start, End, false);

467 }

468};

469

470

471

472

473

474static_assert(sizeof(FileInfo) <= sizeof(ExpansionInfo),

475 "FileInfo must be no larger than ExpansionInfo.");

476

477

478

479

480

484 LLVM_PREFERRED_TYPE(bool)

486 union {

489 };

490

491public:

493

495

498

502

504 assert(isFile() && "Not a file SLocEntry!");

506 }

507

509 assert(isExpansion() && "Not a macro expansion SLocEntry!");

511 }

512

513

515 assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");

517 E.Offset = Offset;

518 return E;

519 }

520

522 assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");

524 E.Offset = Offset;

525 E.IsExpansion = false;

527 return E;

528 }

529

532 assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");

534 E.Offset = Offset;

535 E.IsExpansion = true;

537 return E;

538 }

539};

540

541}

542

543

545public:

547

548

549

550

551

552

554

555

556

557

558

560

561

562

563

565};

566

567

568

569

570

572

573

574

575 FileID LQueryFID, RQueryFID;

576

577

578

579

580 bool LChildBeforeRChild;

581

582

583

585

586

587

588

589

590

591 unsigned LCommonOffset, RCommonOffset;

592

593public:

596 assert(L != R);

597 }

598

599

600

601

602

604 return CommonFID.isValid();

605 }

606

607

608

610

611

612 if (LQueryFID != CommonFID) LOffset = LCommonOffset;

613 if (RQueryFID != CommonFID) ROffset = RCommonOffset;

614

615

616

617

618

619

620 if (LOffset == ROffset)

621 return LChildBeforeRChild;

622

623 return LOffset < ROffset;

624 }

625

626

627

629 assert(LHS != RHS);

630 if (LQueryFID != LHS || RQueryFID != RHS) {

631 LQueryFID = LHS;

632 RQueryFID = RHS;

633 CommonFID = FileID();

634 }

635 }

636

638 unsigned rCommonOffset, bool LParentBeforeRParent) {

639 CommonFID = commonFID;

640 LCommonOffset = lCommonOffset;

641 RCommonOffset = rCommonOffset;

642 LChildBeforeRChild = LParentBeforeRParent;

643 }

644};

645

646

647

648

650

651

652

653

654

655

656

657

658

659

660

661

662

664

666

668

669 mutable llvm::BumpPtrAllocator ContentCacheAlloc;

670

671

672

673

674

675

676

677 llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache*> FileInfos;

678

679

680

681 bool OverridenFilesKeepOriginalName = true;

682

683

684

685 bool UserFilesAreVolatile;

686

687

688

689

690 bool FilesAreTransient = false;

691

692 struct OverriddenFilesInfoTy {

693

694

695 llvm::DenseMap<const FileEntry *, FileEntryRef> OverriddenFiles;

696

697

698 llvm::DenseSet<const FileEntry *> OverriddenFilesWithBuffer;

699 };

700

701

702

703 std::unique_ptr OverriddenFilesInfo;

704

705 OverriddenFilesInfoTy &getOverriddenFilesInfo() {

706 if (!OverriddenFilesInfo)

707 OverriddenFilesInfo.reset(new OverriddenFilesInfoTy);

708 return *OverriddenFilesInfo;

709 }

710

711

712

713

714

715 std::vectorSrcMgr::ContentCache\* MemBufferInfos;

716

717

718

719

720

722

724

725

726

727

728

729 llvm::PagedVector<SrcMgr::SLocEntry, 32> LoadedSLocEntryTable;

730

731

732

733

735

736

737

738

740

741

742

743

744

746

747

748

751

752

753

754

755

756 llvm::BitVector SLocEntryLoaded;

757

758

759

760

761

762 llvm::BitVector SLocEntryOffsetLoaded;

763

764

766

767

768

769

770

771 mutable FileID LastFileIDLookup;

774

775

776

777

778 std::unique_ptr LineTable;

779

780

781

782 mutable FileID LastLineNoFileIDQuery;

784 mutable unsigned LastLineNoFilePos;

785 mutable unsigned LastLineNoResult;

786

787

789

790

791 FileID PreambleFileID;

792

793

794 mutable unsigned NumLinearScans = 0;

795 mutable unsigned NumBinaryProbes = 0;

796

797

798

799

800

801

802 mutable llvm::DenseMap<FileID, FileIDAndOffset> IncludedLocMap;

803

804

805 using IsBeforeInTUCacheKey = std::pair<FileID, FileID>;

806

807

808

809 using InBeforeInTUCache =

810 llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>;

811

812

813 mutable InBeforeInTUCache IBTUCache;

815

816

817

819

820

821 mutable std::unique_ptrllvm::MemoryBuffer FakeBufferForRecovery;

822

823 mutable std::unique_ptrSrcMgr::ContentCache FakeContentCacheForRecovery;

824

825 mutable std::unique_ptrSrcMgr::SLocEntry FakeSLocEntryForRecovery;

826

827

828

829 using MacroArgsMap = std::map<unsigned, SourceLocation>;

830

831 mutable llvm::DenseMap<FileID, std::unique_ptr>

832 MacroArgsCacheMap;

833

834

835

836

837

838

839

840

842

843public:

845 bool UserFilesAreVolatile = false);

849

851

852

853

855

857

859

860

861

862

864 OverridenFilesKeepOriginalName = value;

865 }

866

867

868

870

871

873 return StoredModuleBuildStack;

874 }

875

876

878 StoredModuleBuildStack.clear();

879 StoredModuleBuildStack.append(stack.begin(), stack.end());

880 }

881

882

884 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));

885 }

886

887

888

889

890

891

893

894

896 MainFileID = FID;

897 }

898

899

900

901

903

904

906 assert(PreambleFileID.isInvalid() && "PreambleFileID already set!");

908 }

909

910

912

913

914

915

916

917

918

921 int LoadedID = 0,

923

924

925

926

927

932

933

934

935

936

941

942

943

946

947

948

949

950

951

954 unsigned Length);

955

956

957

958

959

963 unsigned Length,

964 bool ExpansionIsTokenRange = true,

965 int LoadedID = 0,

967

968

969

973

974

975

976

977 std::optionalllvm::MemoryBufferRef

979

980

981

982

985 return *B;

986 return getFakeBufferForRecovery();

987 }

988

989

990

991

992

993

994

995

997 const llvm::MemoryBufferRef &Buffer) {

999 }

1000

1001

1002

1003

1004

1005

1006

1007

1009 std::unique_ptrllvm::MemoryBuffer Buffer);

1010

1011

1012

1013

1014

1015

1016

1018

1019

1021 if (OverriddenFilesInfo) {

1022 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))

1023 return true;

1024 if (OverriddenFilesInfo->OverriddenFiles.contains(File))

1025 return true;

1026 }

1027 return false;

1028 }

1029

1030

1031

1032

1033

1034

1036

1037

1039

1040

1041

1043 FilesAreTransient = Transient;

1044 }

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054 std::optionalllvm::MemoryBufferRef

1056 if (auto *Entry = getSLocEntryForFile(FID))

1057 return Entry->getFile().getContentCache().getBufferOrNone(

1059 return std::nullopt;

1060 }

1061

1062

1063

1064

1065

1066 llvm::MemoryBufferRef

1069 return *B;

1070 return getFakeBufferForRecovery();

1071 }

1072

1073

1076 return *FE;

1077 return nullptr;

1078 }

1079

1080

1082 if (auto *Entry = getSLocEntryForFile(FID))

1083 return Entry->getFile().getContentCache().OrigEntry;

1084 return std::nullopt;

1085 }

1086

1087

1088

1089

1090

1092

1093

1097 return *FE;

1098 return nullptr;

1099 }

1100

1101

1102

1103

1104

1105

1107

1108

1109

1110

1111

1113

1114

1115

1116

1117

1119

1120

1121

1123 if (auto *Entry = getSLocEntryForFile(FID))

1124 return Entry->getFile().NumCreatedFIDs;

1125 return 0;

1126 }

1127

1128

1129

1131 bool Force = false) {

1132 auto *Entry = getSLocEntryForFile(FID);

1133 if (!Entry)

1134 return;

1135 assert((Force || Entry->getFile().NumCreatedFIDs == 0) && "Already set!");

1136 Entry->getFile().NumCreatedFIDs = NumFIDs;

1137 }

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1150 return getFileID(SpellingLoc.getOffset());

1151 }

1152

1153

1155

1156

1157

1159 if (auto *Entry = getSLocEntryForFile(FID))

1160 return SourceLocation::getFileLoc(Entry->getOffset());

1162 }

1163

1164

1165

1167 if (auto *Entry = getSLocEntryForFile(FID))

1168 return SourceLocation::getFileLoc(Entry->getOffset() +

1171 }

1172

1173

1174

1176 if (auto *Entry = getSLocEntryForFile(FID))

1177 return Entry->getFile().getIncludeLoc();

1179 }

1180

1181

1182

1183

1184 std::pair<SourceLocation, StringRef>

1187

1188

1189

1190 if (FID.ID >= -1)

1192

1193 return ExternalSLocEntries->getModuleImportLoc(FID.ID);

1194 }

1195

1196

1197

1199

1200

1201 if (Loc.isFileID()) return Loc;

1202 return getExpansionLocSlowCase(Loc);

1203 }

1204

1205

1206

1207

1209 if (Loc.isFileID()) return Loc;

1210 return getFileLocSlowCase(Loc);

1211 }

1212

1213

1214

1215

1216

1218

1219

1220

1222

1223

1224

1231

1232

1233

1236 if (Expansion.getEnd() == Range.getEnd())

1238 return Expansion;

1239 }

1240

1241

1242

1243

1244

1245

1247

1248

1249 if (Loc.isFileID()) return Loc;

1250 return getSpellingLocSlowCase(Loc);

1251 }

1252

1253

1254

1255

1256

1257

1258

1260

1261

1263 auto *Entry = getSLocEntryOrNull(FID);

1264 if (!Entry)

1266

1268 return Entry->isFile() ? SourceLocation::getFileLoc(GlobalOffset)

1269 : SourceLocation::getMacroLoc(GlobalOffset);

1270 }

1271

1272

1273

1274

1275

1278 auto *Entry = getSLocEntryOrNull(FID);

1279 if (!Entry)

1280 return std::make_pair(FileID(), 0);

1281 return std::make_pair(FID, Loc.getOffset() - Entry->getOffset());

1282 }

1283

1284

1285

1286

1287

1291

1292

1293

1294

1295

1299

1300

1301

1303

1304

1305

1306

1307

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1323

1324

1325

1326

1327

1328

1330

1331

1332

1333

1334

1335

1338

1339

1340

1341

1342

1343

1344 bool

1347

1348

1349

1350

1351

1352

1353 bool

1356 assert(((Start.getOffset() < NextLocalOffset &&

1357 Start.getOffset()+Length <= NextLocalOffset) ||

1358 (Start.getOffset() >= CurrentLoadedOffset &&

1359 Start.getOffset()+Length < MaxLoadedOffset)) &&

1360 "Chunk is not valid SLoc address space");

1364 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {

1365 if (RelativeOffset)

1366 *RelativeOffset = LocOffs - BeginOffs;

1367 return true;

1368 }

1369

1370 return false;

1371 }

1372

1373

1374

1375

1376

1377

1381 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;

1382 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;

1383

1384 if (LHSLoaded == RHSLoaded) {

1385 if (RelativeOffset)

1386 *RelativeOffset = RHSOffs - LHSOffs;

1387 return true;

1388 }

1389

1390 return false;

1391 }

1392

1393

1394

1395

1396

1397

1398

1399

1400

1402 bool *Invalid = nullptr) const;

1403

1404

1405

1406

1407

1408

1409

1411 bool *Invalid = nullptr) const;

1414 bool *Invalid = nullptr) const {

1416 }

1418 bool *Invalid = nullptr) const {

1420 }

1422 bool *Invalid = nullptr) const;

1423

1424

1425

1426

1427

1428

1429

1433 bool *Invalid = nullptr) const {

1435 }

1437 bool *Invalid = nullptr) const {

1439 }

1441

1442

1443

1444

1445

1446

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1475 bool UseLineDirectives = true) const;

1476

1477

1478

1479

1480

1481

1482

1483

1485

1486

1487

1488

1489

1493

1494

1495

1496

1497

1501

1502

1506 return false;

1507 StringRef Filename(Presumed.getFilename());

1508 return Filename == "";

1509 }

1510

1511

1515 return false;

1516 StringRef Filename(Presumed.getFilename());

1517 return Filename == "";

1518 }

1519

1520

1524 return false;

1525 StringRef Filename(Presumed.getFilename());

1526 return Filename == "";

1527 }

1528

1529

1533 return false;

1534 StringRef Filename(Presumed.getFilename());

1535 return Filename == "" || Filename == "";

1536 }

1537

1538

1541 return false;

1543 }

1544

1545

1549

1550

1553 return false;

1554

1555

1556

1557

1559 do {

1563 }

1564

1566 }

1567

1568

1570

1571

1572

1573

1575 unsigned *RelativeOffset = nullptr) const {

1577 if (isOffsetInFileID(FID, Offs)) {

1578 if (RelativeOffset)

1580 return true;

1581 }

1582

1583 return false;

1584 }

1585

1586

1587

1588

1589

1590

1592

1593

1594

1595

1596

1598 bool IsFileEntry, bool IsFileExit,

1600

1601

1603

1604

1606

1607

1608

1609

1610

1611

1612

1614 return ContentCacheAlloc.getTotalMemory();

1615 }

1616

1624

1625

1626

1628

1629

1630

1632

1633

1634

1635

1636

1637

1638

1639

1640

1642 unsigned Line, unsigned Col) const;

1643

1644

1645

1646

1647

1652

1653

1654

1656 unsigned Line, unsigned Col) const;

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1668

1669

1670

1671

1673

1674

1675

1676

1677

1678

1679

1680

1681 std::pair<bool, bool>

1684

1685

1686

1687

1689

1690

1693

1694

1695

1699

1700

1701

1702

1703

1707 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;

1708 bool RHSLoaded = RHS >= CurrentLoadedOffset;

1709 if (LHSLoaded == RHSLoaded)

1710 return LHSOffset < RHS;

1711

1712 return LHSLoaded;

1713 }

1714

1715

1718 return Location == Start || Location == End ||

1721 }

1722

1723

1725 llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache *>::const_iterator;

1726

1730 return FileInfos.find_as(File) != FileInfos.end();

1731 }

1732

1733

1735

1736 void dump() const;

1737

1738

1740 std::optional MaxNotes = 32) const;

1741

1742

1744

1745

1749

1750

1752 assert(Index < LocalSLocEntryTable.size() && "Invalid index");

1753 return LocalSLocEntryTable[Index];

1754 }

1755

1756

1758

1759

1761 bool *Invalid = nullptr) const {

1764 }

1765

1766

1768 bool *Invalid = nullptr) {

1769 assert(Index < LoadedSLocEntryTable.size() && "Invalid index");

1770 if (SLocEntryLoaded[Index])

1771 return LoadedSLocEntryTable[Index];

1772 return loadSLocEntry(Index, Invalid);

1773 }

1774

1776 bool *Invalid = nullptr) const {

1778 }

1779

1781 if (FID.ID == 0 || FID.ID == -1) {

1783 return LocalSLocEntryTable[0];

1784 }

1785 return getSLocEntryByID(FID.ID, Invalid);

1786 }

1787

1789

1791 assert(LoadedSLocEntryTable.empty() &&

1792 "Invalidating existing loaded entries");

1793 ExternalSLocEntries = Source;

1794 }

1795

1796

1797

1798

1799

1800

1801

1802 std::pair<int, SourceLocation::UIntTy>

1805

1806

1808 return isLoadedOffset(Loc.getOffset());

1809 }

1810

1811

1813 return isLocalOffset(Loc.getOffset());

1814 }

1815

1816

1818 assert(FID.ID != -1 && "Using FileID sentinel value");

1819 return FID.ID < 0;

1820 }

1821

1822

1826

1827

1828

1830 if (!Loc.isMacroID()) return Loc;

1831

1832

1833

1834

1837

1838

1839

1841 }

1842

1843

1845

1846private:

1849

1850 llvm::MemoryBufferRef getFakeBufferForRecovery() const;

1852

1855

1857 return const_cast<SourceManager *>(this)->getSLocEntryOrNull(FID);

1858 }

1859

1864 }

1865

1866 const SrcMgr::SLocEntry *getSLocEntryForFile(FileID FID) const {

1867 return const_cast<SourceManager *>(this)->getSLocEntryForFile(FID);

1868 }

1869

1870 SrcMgr::SLocEntry *getSLocEntryForFile(FileID FID) {

1871 if (auto *Entry = getSLocEntryOrNull(FID))

1872 if (Entry->isFile())

1873 return Entry;

1874 return nullptr;

1875 }

1876

1877

1878

1879 const SrcMgr::SLocEntry &getSLocEntryByID(int ID,

1880 bool *Invalid = nullptr) const {

1882 }

1883

1884 SrcMgr::SLocEntry &getSLocEntryByID(int ID, bool *Invalid = nullptr) {

1885 assert(ID != -1 && "Using FileID sentinel value");

1886 if (ID < 0)

1887 return getLoadedSLocEntryByID(ID, Invalid);

1889 }

1890

1891 const SrcMgr::SLocEntry &

1892 getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) const {

1893 return const_cast<SourceManager *>(this)->getLoadedSLocEntryByID(ID,

1895 }

1896

1897 SrcMgr::SLocEntry &getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) {

1899 }

1900

1902

1903 if (SLocOffset >= LastLookupStartOffset && SLocOffset < LastLookupEndOffset)

1904 return LastFileIDLookup;

1905 return getFileIDSlow(SLocOffset);

1906 }

1907

1909 return SLocOffset < CurrentLoadedOffset;

1910 }

1911

1913 return SLocOffset >= CurrentLoadedOffset;

1914 }

1915

1916

1917

1918 SourceLocation

1919 createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion,

1920 unsigned Length, int LoadedID = 0,

1922

1923

1924

1925 inline bool isOffsetInFileID(FileID FID,

1927 const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);

1928

1929 if (SLocOffset < Entry.getOffset()) return false;

1930

1931

1932 if (FID.ID == -2)

1933 return true;

1934

1935

1936 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))

1937 return SLocOffset < NextLocalOffset;

1938

1939

1940

1941 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();

1942 }

1943

1944

1945

1946 FileID getPreviousFileID(FileID FID) const;

1947

1948

1949

1950 FileID getNextFileID(FileID FID) const;

1951

1952

1953

1954

1955

1956

1957 FileID createFileIDImpl(SrcMgr::ContentCache &File, StringRef Filename,

1958 SourceLocation IncludePos,

1961

1962 SrcMgr::ContentCache &getOrCreateContentCache(FileEntryRef SourceFile,

1963 bool isSystemFile = false);

1964

1965

1966 SrcMgr::ContentCache &

1967 createMemBufferContentCache(std::unique_ptrllvm::MemoryBuffer Buf);

1968

1972

1973 SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const;

1974 SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;

1975 SourceLocation getFileLocSlowCase(SourceLocation Loc) const;

1976

1977 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;

1978 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,

1979 FileID FID,

1980 SourceLocation SpellLoc,

1981 SourceLocation ExpansionLoc,

1982 unsigned ExpansionLength) const;

1983 void updateSlocUsageStats() const;

1984};

1985

1986

1987template

1989

1990

1991template<>

1994

1995public:

1997

1999 return SM.isBeforeInTranslationUnit(LHS, RHS);

2000 }

2001};

2002

2003

2004template<>

2007

2008public:

2010

2012 return SM.isBeforeInTranslationUnit(LHS.getBegin(), RHS.getBegin());

2013 }

2014};

2015

2016

2017

2019public:

2020

2021

2023

2025 assert(SourceMgr);

2026 return *SourceMgr;

2027 }

2028

2029private:

2030

2031

2032

2033 std::unique_ptr FileMgr;

2034 std::unique_ptr DiagOpts;

2035 std::unique_ptr Diagnostics;

2036 std::unique_ptr SourceMgr;

2037};

2038

2039}

2040

2041#endif

Defines the Diagnostic-related interfaces.

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

Defines the clang::FileManager interface and associated types.

static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)

Produce a diagnostic highlighting some portion of a literal.

Defines the clang::SourceLocation class and associated facilities.

Reads an AST files chain containing the contents of a translation unit.

Writes an AST file containing the contents of a translation unit.

bool operator()(SourceLocation LHS, SourceLocation RHS) const

Definition SourceManager.h:1998

BeforeThanCompare(SourceManager &SM)

Definition SourceManager.h:1996

BeforeThanCompare(SourceManager &SM)

Definition SourceManager.h:2009

bool operator()(SourceRange LHS, SourceRange RHS) const

Definition SourceManager.h:2011

Comparison function object.

Definition SourceManager.h:1988

Represents a character-granular source range.

bool isTokenRange() const

Return true if the end of this range specifies the start of the last token.

SourceLocation getEnd() const

SourceLocation getBegin() const

void setTokenRange(bool TR)

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

External source of source location entries.

Definition SourceManager.h:544

virtual int getSLocEntryID(SourceLocation::UIntTy SLocOffset)=0

Get the index ID for the loaded SourceLocation offset.

virtual std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID)=0

Retrieve the module import location and name for the given ID, if in fact it was loaded from a module...

virtual ~ExternalSLocEntrySource()

virtual bool ReadSLocEntry(int ID)=0

Read the source location entry with index ID, which will always be less than -1.

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

const FileEntry & getFileEntry() const

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.

A SourceLocation and its associated SourceManager.

Holds the cache used by isBeforeInTranslationUnit.

Definition SourceManager.h:571

void setCommonLoc(FileID commonFID, unsigned lCommonOffset, unsigned rCommonOffset, bool LParentBeforeRParent)

Definition SourceManager.h:637

bool getCachedResult(unsigned LOffset, unsigned ROffset) const

If the cache is valid, compute the result given the specified offsets in the LHS/RHS FileID's.

Definition SourceManager.h:609

void setQueryFIDs(FileID LHS, FileID RHS)

Set up a new query.

Definition SourceManager.h:628

InBeforeInTUCacheEntry(FileID L, FileID R)

Definition SourceManager.h:595

InBeforeInTUCacheEntry()=default

bool isCacheValid() const

Return true if the currently cached values match up with the specified LHS/RHS query.

Definition SourceManager.h:603

Used to hold and unique data used to represent #line information.

Represents an unpacked "presumed" location which can be presented to the user.

const char * getFilename() const

Return the presumed filename of this location.

bool isInvalid() const

Return true if this object is invalid or uninitialized.

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

SourceManagerForFile(StringRef FileName, StringRef Content)

Creates SourceManager and necessary dependencies (e.g.

SourceManager & get()

Definition SourceManager.h:2024

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

Definition SourceManager.h:663

std::optional< StringRef > getNonBuiltinFilenameForID(FileID FID) const

Returns the filename for the provided FileID, unless it's a built-in buffer that's not represented by...

FileIDAndOffset getDecomposedExpansionLoc(SourceLocation Loc) const

Decompose the specified location into a raw FileID + Offset pair.

Definition SourceManager.h:1288

bool isMacroBodyExpansion(SourceLocation Loc) const

Tests whether the given source location represents the expansion of a macro body.

friend class ASTWriter

Definition SourceManager.h:1848

FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const

Decompose the specified location into a raw FileID + Offset pair.

Definition SourceManager.h:1276

unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const

bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const

Determines the order of 2 source locations in the "source locationaddress space".

Definition SourceManager.h:1696

FileID getFileID(SourceLocation SpellingLoc) const

Return the FileID for a SourceLocation.

Definition SourceManager.h:1149

bool isAtEndOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroEnd=nullptr) const

Returns true if the given MacroID location points at the character end of the immediate macro expansi...

DiagnosticsEngine & getDiagnostics() const

Definition SourceManager.h:856

bool isInPredefinedFile(SourceLocation Loc) const

Returns whether Loc is located in a built-in or command line source.

Definition SourceManager.h:1530

SourceLocation::UIntTy getNextLocalOffset() const

Definition SourceManager.h:1788

bool isWrittenInBuiltinFile(SourceLocation Loc) const

Returns whether Loc is located in a file.

Definition SourceManager.h:1503

unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const

Return the column # for the specified file position.

void noteSLocAddressSpaceUsage(DiagnosticsEngine &Diag, std::optional< unsigned > MaxNotes=32) const

void setAllFilesAreTransient(bool Transient)

Specify that all files that are read during this compilation are transient.

Definition SourceManager.h:1042

unsigned getFileOffset(SourceLocation SpellingLoc) const

Returns the offset from the start of the file that the specified SourceLocation represents.

Definition SourceManager.h:1308

bool isLocalSourceLocation(SourceLocation Loc) const

Returns true if Loc did not come from a PCH/Module.

Definition SourceManager.h:1812

bool isInMainFile(SourceLocation Loc) const

Returns whether the PresumedLoc for a given SourceLocation is in the main file.

void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)

Add a line note to the line table for the FileID and offset specified by Loc.

SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, bool UserFilesAreVolatile=false)

SourceLocation createTokenSplitLoc(SourceLocation SpellingLoc, SourceLocation TokenStart, SourceLocation TokenEnd)

Return a new SourceLocation that encodes that the token starting at TokenStart ends prematurely at To...

PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const

Returns the "presumed" location of a SourceLocation specifies.

const FileEntry * getFileEntryForSLocEntry(const SrcMgr::SLocEntry &SLocEntry) const

Returns the FileEntry record for the provided SLocEntry.

Definition SourceManager.h:1095

bool isInTheSameTranslationUnitImpl(const FileIDAndOffset &LOffs, const FileIDAndOffset &ROffs) const

Determines whether the two decomposed source location is in the same TU.

unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const

Definition SourceManager.h:1436

bool isWrittenInCommandLineFile(SourceLocation Loc) const

Returns whether Loc is located in a file.

Definition SourceManager.h:1512

MemoryBufferSizes getMemoryBufferSizes() const

Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...

void setFileIsTransient(FileEntryRef SourceFile)

Specify that a file is transient.

unsigned getExpansionColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const

Definition SourceManager.h:1417

bool isFileOverridden(const FileEntry *File) const

Returns true if the file contents have been overridden.

Definition SourceManager.h:1020

OptionalFileEntryRef getFileEntryRefForID(FileID FID) const

Returns the FileEntryRef for the provided FileID.

Definition SourceManager.h:1081

CharSourceRange getExpansionRange(SourceRange Range) const

Given a SourceRange object, return the range of tokens or characters covered by the expansion in the ...

Definition SourceManager.h:1225

SourceLocation getFileLoc(SourceLocation Loc) const

Given Loc, if it is a macro location return the expansion location or the spelling location,...

Definition SourceManager.h:1208

bool isInSLocAddrSpace(SourceLocation Loc, SourceLocation Start, unsigned Length, SourceLocation::UIntTy *RelativeOffset=nullptr) const

Returns true if Loc is inside the [Start, +Length) chunk of the source location address space.

Definition SourceManager.h:1354

SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col) const

Get the source location in FID for the given line:col.

size_t getContentCacheSize() const

Return the total amount of physical memory allocated by the ContentCache allocator.

Definition SourceManager.h:1613

StringRef getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const

Return the filename or buffer identifier of the buffer the location is in.

SourceLocation getTopMacroCallerLoc(SourceLocation Loc) const

std::optional< StringRef > getBufferDataOrNone(FileID FID) const

Return a StringRef to the source buffer data for the specified FileID, returning std::nullopt if inva...

FileID translateFile(const FileEntry *SourceFile) const

Get the FileID for the given file.

CharSourceRange getExpansionRange(CharSourceRange Range) const

Given a CharSourceRange object, return the range of tokens or characters covered by the expansion in ...

Definition SourceManager.h:1234

void setModuleBuildStack(ModuleBuildStack stack)

Set the module build stack.

Definition SourceManager.h:877

StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const

Return a StringRef to the source buffer data for the specified FileID.

FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)

Create a new FileID that represents the specified file being #included from the specified IncludePosi...

void PrintStats() const

Print statistics to stderr.

friend class ASTReader

Definition SourceManager.h:1847

FileID getUniqueLoadedASTFileID(SourceLocation Loc) const

SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr)

Definition SourceManager.h:1780

bool isMainFile(const FileEntry &SourceFile)

Returns true when the given FileEntry corresponds to the main file.

size_t getDataStructureSizes() const

Return the amount of memory used for various side tables and data structures in the SourceManager.

bool isMacroArgExpansion(SourceLocation Loc, SourceLocation *StartLoc=nullptr) const

Tests whether the given source location represents a macro argument's expansion into the function-lik...

unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const

Definition SourceManager.h:1413

const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index) const

Get a local SLocEntry. This is exposed for indexing.

Definition SourceManager.h:1746

SourceLocation getComposedLoc(FileID FID, unsigned Offset) const

Form a SourceLocation from a FileID and Offset pair.

Definition SourceManager.h:1262

void setPreambleFileID(FileID Preamble)

Set the file ID for the precompiled preamble.

Definition SourceManager.h:905

OptionalFileEntryRef bypassFileContentsOverride(FileEntryRef File)

Bypass the overridden contents of a file.

bool userFilesAreVolatile() const

True if non-system source files should be treated as volatile (likely to change while trying to use t...

Definition SourceManager.h:869

const SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr) const

Get a loaded SLocEntry. This is exposed for indexing.

Definition SourceManager.h:1760

llvm::DenseMap< FileEntryRef, SrcMgr::ContentCache * >::const_iterator fileinfo_iterator

Definition SourceManager.h:1724

SourceLocation getSpellingLoc(SourceLocation Loc) const

Given a SourceLocation object, return the spelling location referenced by the ID.

Definition SourceManager.h:1246

FileManager & getFileManager() const

Definition SourceManager.h:858

void setOverridenFilesKeepOriginalName(bool value)

Set true if the SourceManager should report the original file name for contents of files that were ov...

Definition SourceManager.h:863

fileinfo_iterator fileinfo_end() const

Definition SourceManager.h:1728

FileID translateFile(FileEntryRef SourceFile) const

Definition SourceManager.h:1649

ModuleBuildStack getModuleBuildStack() const

Retrieve the module build stack.

Definition SourceManager.h:872

unsigned local_sloc_entry_size() const

Get the number of local SLocEntries we have.

Definition SourceManager.h:1743

std::optional< StringRef > getBufferDataIfLoaded(FileID FID) const

Return a StringRef to the source buffer data for the specified FileID, returning std::nullopt if it's...

SourceLocation getLocForEndOfFile(FileID FID) const

Return the source location corresponding to the last byte of the specified file.

Definition SourceManager.h:1166

FileIDAndOffset getDecomposedSpellingLoc(SourceLocation Loc) const

Decompose the specified location into a raw FileID + Offset pair.

Definition SourceManager.h:1296

FileID getMainFileID() const

Returns the FileID of the main source file.

Definition SourceManager.h:892

SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const

Gets the location of the immediate macro caller, one level up the stack toward the initial macro type...

Definition SourceManager.h:1829

const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const

Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.

std::pair< int, SourceLocation::UIntTy > AllocateLoadedSLocEntries(unsigned NumSLocEntries, SourceLocation::UIntTy TotalSize)

Allocate a number of loaded SLocEntries, which will be actually loaded on demand from the external so...

void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)

Push an entry to the module build stack.

Definition SourceManager.h:883

void overrideFileContents(FileEntryRef SourceFile, const llvm::MemoryBufferRef &Buffer)

Override the contents of the given source file by providing an already-allocated buffer.

Definition SourceManager.h:996

SourceLocation getIncludeLoc(FileID FID) const

Returns the include location if FID is a #include'd file otherwise it returns an invalid location.

Definition SourceManager.h:1175

llvm::MemoryBufferRef getBufferOrFake(FileID FID, SourceLocation Loc=SourceLocation()) const

Return the buffer for the specified FileID.

Definition SourceManager.h:1067

unsigned getFileIDSize(FileID FID) const

The size of the SLocEntry that FID represents.

bool isInSystemMacro(SourceLocation loc) const

Returns whether Loc is expanded from a macro in a system header.

Definition SourceManager.h:1551

void setMainFileID(FileID FID)

Set the file ID for the main source file.

Definition SourceManager.h:895

unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const

Given a SourceLocation, return the spelling line number for the position indicated.

CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const

Return the start/end of the expansion information for an expansion location.

bool hasLineTable() const

Determine if the source manager has a line table.

Definition SourceManager.h:1602

CharSourceRange getExpansionRange(SourceLocation Loc) const

Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...

bool isWrittenInScratchSpace(SourceLocation Loc) const

Returns whether Loc is located in a file.

Definition SourceManager.h:1521

bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const

Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (of...

Definition SourceManager.h:1574

void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)

Definition SourceManager.h:1790

unsigned getLineTableFilenameID(StringRef Str)

Return the uniqued ID for the specified filename.

void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs, bool Force=false)

Set the number of FileIDs (files and macros) that were created during preprocessing of FID,...

Definition SourceManager.h:1130

bool isLocalFileID(FileID FID) const

Returns true if FID did not come from a PCH/Module.

Definition SourceManager.h:1823

bool isInSystemHeader(SourceLocation Loc) const

Returns if a SourceLocation is in a system header.

Definition SourceManager.h:1539

FileID getPreambleFileID() const

Get the file ID for the precompiled preamble if there is one.

Definition SourceManager.h:911

SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index)

Get a local SLocEntry. This is exposed for indexing.

Definition SourceManager.h:1751

void initializeForReplay(const SourceManager &Old)

Initialize this source manager suitably to replay the compilation described by Old.

FileIDAndOffset getDecomposedIncludedLoc(FileID FID) const

Returns the "included/expanded in" decomposed location of the given FileID.

bool isLoadedSourceLocation(SourceLocation Loc) const

Returns true if Loc came from a PCH/Module.

Definition SourceManager.h:1807

unsigned loaded_sloc_entry_size() const

Get the number of loaded SLocEntries we have.

Definition SourceManager.h:1757

unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const

Definition SourceManager.h:1432

SourceManager & operator=(const SourceManager &)=delete

FileID getOrCreateFileID(FileEntryRef SourceFile, SrcMgr::CharacteristicKind FileCharacter)

Get the FileID for SourceFile if it exists.

bool hasFileInfo(const FileEntry *File) const

Definition SourceManager.h:1729

SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const

Get the source location for the given file:line:col triplet.

std::pair< SourceLocation, StringRef > getModuleImportLoc(SourceLocation Loc) const

Definition SourceManager.h:1185

bool isLoadedFileID(FileID FID) const

Returns true if FID came from a PCH/Module.

Definition SourceManager.h:1817

const FileEntry * getFileEntryForID(FileID FID) const

Returns the FileEntry record for the provided FileID.

Definition SourceManager.h:1074

bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, SourceLocation::IntTy *RelativeOffset) const

Return true if both LHS and RHS are in the local source location address space or the loaded one.

Definition SourceManager.h:1378

llvm::MemoryBufferRef getMemoryBufferForFileOrFake(FileEntryRef File)

Retrieve the memory buffer associated with the given file.

Definition SourceManager.h:983

SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr)

Get a loaded SLocEntry. This is exposed for indexing.

Definition SourceManager.h:1767

SourceLocation getLocForStartOfFile(FileID FID) const

Return the source location corresponding to the first byte of the specified file.

Definition SourceManager.h:1158

bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const

Returns true if the given MacroID location points at the beginning of the immediate macro expansion.

SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const

Return the file characteristic of the specified source location, indicating whether this is a normal ...

SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)

Creates an expansion SLocEntry for a macro use.

bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const

Returns true if the spelling locations for both SourceLocations are part of the same file buffer.

Definition SourceManager.h:1490

bool isInExternCSystemHeader(SourceLocation Loc) const

Returns if a SourceLocation is in an "extern C" system header.

Definition SourceManager.h:1546

unsigned getPresumedColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const

bool isWrittenInMainFile(SourceLocation Loc) const

Returns true if the spelling location for the given location is in the main file buffer.

Definition SourceManager.h:1498

std::pair< bool, bool > isInTheSameTranslationUnit(FileIDAndOffset &LOffs, FileIDAndOffset &ROffs) const

Determines whether the two decomposed source location is in the same translation unit.

bool isPointWithin(SourceLocation Location, SourceLocation Start, SourceLocation End) const

Return true if the Point is within Start and End.

Definition SourceManager.h:1716

SourceManager(const SourceManager &)=delete

StringRef getFilename(SourceLocation SpellingLoc) const

Return the filename of the file containing a SourceLocation.

SourceLocation getExpansionLoc(SourceLocation Loc) const

Given a SourceLocation object Loc, return the expansion location referenced by the ID.

Definition SourceManager.h:1198

SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const

If Loc points inside a function macro argument, the returned location will be the macro location in w...

bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const

Determines the order of 2 source locations in the translation unit.

unsigned getNumCreatedFIDsForFileID(FileID FID) const

Get the number of FileIDs (files and macros) that were created during preprocessing of FID,...

Definition SourceManager.h:1122

std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const

Return the buffer for the specified FileID.

Definition SourceManager.h:1055

fileinfo_iterator fileinfo_begin() const

Definition SourceManager.h:1727

bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation::UIntTy RHS) const

Determines the order of a source location and a source location offset in the "source location addres...

Definition SourceManager.h:1704

LineTableInfo & getLineTable()

Retrieve the stored line table.

SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const

Given a SourceLocation object, return the spelling location referenced by the ID.

std::optional< llvm::MemoryBufferRef > getMemoryBufferForFileOrNone(FileEntryRef File)

Retrieve the memory buffer associated with the given file.

const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const

Definition SourceManager.h:1775

SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)

Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.

A trivial tuple used to represent a source range.

SourceLocation getBegin() const

One instance of this struct is kept for every file loaded or used.

Definition SourceManager.h:131

void setBuffer(std::unique_ptr< llvm::MemoryBuffer > B)

Set the buffer.

Definition SourceManager.h:258

std::optional< StringRef > getBufferDataIfLoaded() const

Return a StringRef to the source buffer data, only if it has already been loaded.

Definition SourceManager.h:251

void setUnownedBuffer(std::optional< llvm::MemoryBufferRef > B)

Set the buffer to one that's not owned (or to nullptr).

Definition SourceManager.h:266

OptionalFileEntryRef ContentsEntry

References the file which the contents were actually loaded from.

Definition SourceManager.h:152

unsigned getSizeBytesMapped() const

Returns the number of bytes actually mapped for this ContentCache.

unsigned IsTransient

True if this file may be transient, that is, if it might not exist at some later point in time when t...

Definition SourceManager.h:182

StringRef Filename

The filename that is used to access OrigEntry.

Definition SourceManager.h:157

ContentCache(FileEntryRef Ent)

Definition SourceManager.h:192

ContentCache(FileEntryRef Ent, FileEntryRef contentEnt)

Definition SourceManager.h:194

unsigned IsBufferInvalid

Definition SourceManager.h:185

ContentCache()

Definition SourceManager.h:187

unsigned getSize() const

Returns the size of the content encapsulated by this ContentCache.

llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const

Returns the kind of memory used to back the memory buffer for this content cache.

unsigned IsFileVolatile

True if this content cache was initially created for a source file considered to be volatile (likely ...

Definition SourceManager.h:176

LineOffsetMapping SourceLineCache

A bump pointer allocated array of offsets for each source line.

Definition SourceManager.h:163

std::optional< llvm::MemoryBufferRef > getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, SourceLocation Loc=SourceLocation()) const

Returns the memory buffer for the associated content.

static const char * getInvalidBOM(StringRef BufStr)

std::optional< llvm::MemoryBufferRef > getBufferIfLoaded() const

Return the buffer, only if it has been loaded.

Definition SourceManager.h:243

unsigned BufferOverridden

Indicates whether the buffer itself was provided to override the actual file contents.

Definition SourceManager.h:171

ContentCache(const ContentCache &RHS)

The copy ctor does not allow copies where source object has either a non-NULL Buffer or SourceLineCac...

Definition SourceManager.h:201

ContentCache & operator=(const ContentCache &RHS)=delete

OptionalFileEntryRef OrigEntry

Reference to the file entry representing this ContentCache.

Definition SourceManager.h:146

Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...

Definition SourceManager.h:361

SourceLocation getExpansionLocStart() const

Definition SourceManager.h:383

static ExpansionInfo create(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End, bool ExpansionIsTokenRange=true)

Return a ExpansionInfo for an expansion.

Definition SourceManager.h:420

bool isMacroBodyExpansion() const

Definition SourceManager.h:405

bool isExpansionTokenRange() const

Definition SourceManager.h:392

bool isFunctionMacroExpansion() const

Definition SourceManager.h:409

SourceLocation getSpellingLoc() const

Definition SourceManager.h:379

CharSourceRange getExpansionLocRange() const

Definition SourceManager.h:394

bool isMacroArgExpansion() const

Definition SourceManager.h:400

static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc, SourceLocation ExpansionLoc)

Return a special ExpansionInfo for the expansion of a macro argument into a function-like macro's bod...

Definition SourceManager.h:450

static ExpansionInfo createForTokenSplit(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End)

Return a special ExpansionInfo representing a token that ends prematurely.

Definition SourceManager.h:463

SourceLocation getExpansionLocEnd() const

Definition SourceManager.h:387

Information about a FileID, basically just the logical file that it represents and include stack info...

Definition SourceManager.h:295

const ContentCache & getContentCache() const

Definition SourceManager.h:337

CharacteristicKind getFileCharacteristic() const

Return whether this is a system header or not.

Definition SourceManager.h:342

static FileInfo get(SourceLocation IL, ContentCache &Con, CharacteristicKind FileCharacter, StringRef Filename)

Return a FileInfo object.

Definition SourceManager.h:321

bool hasLineDirectives() const

Return true if this FileID has #line directives in it.

Definition SourceManager.h:347

void setHasLineDirectives()

Set the flag that indicates that this FileID has line table entries associated with it.

Definition SourceManager.h:351

SourceLocation getIncludeLoc() const

Definition SourceManager.h:333

StringRef getName() const

Returns the name of the file that was used when the file was loaded from the underlying file system.

Definition SourceManager.h:355

Mapping of line offsets into a source file.

Definition SourceManager.h:101

unsigned size() const

Definition SourceManager.h:104

const unsigned * begin() const

Definition SourceManager.h:112

LineOffsetMapping()=default

const unsigned * end() const

Definition SourceManager.h:113

const unsigned & operator[](int I) const

Definition SourceManager.h:114

static LineOffsetMapping get(llvm::MemoryBufferRef Buffer, llvm::BumpPtrAllocator &Alloc)

ArrayRef< unsigned > getLines() const

Definition SourceManager.h:108

This is a discriminated union of FileInfo and ExpansionInfo.

Definition SourceManager.h:481

FileInfo File

Definition SourceManager.h:487

SourceLocation::UIntTy getOffset() const

Definition SourceManager.h:494

bool isExpansion() const

Definition SourceManager.h:496

static SLocEntry getOffsetOnly(SourceLocation::UIntTy Offset)

Creates an incomplete SLocEntry that is only able to report its offset.

Definition SourceManager.h:514

SLocEntry()

Definition SourceManager.h:492

static SLocEntry get(SourceLocation::UIntTy Offset, const FileInfo &FI)

Definition SourceManager.h:521

FileInfo & getFile()

Definition SourceManager.h:503

bool isFile() const

Definition SourceManager.h:497

const FileInfo & getFile() const

Definition SourceManager.h:499

static SLocEntry get(SourceLocation::UIntTy Offset, const ExpansionInfo &Expansion)

Definition SourceManager.h:530

const ExpansionInfo & getExpansion() const

Definition SourceManager.h:508

ExpansionInfo Expansion

Definition SourceManager.h:488

Public enums and private classes that are part of the SourceManager implementation.

Definition SourceManager.h:72

CharacteristicKind

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

Definition SourceManager.h:81

@ C_System_ModuleMap

Definition SourceManager.h:86

@ C_User_ModuleMap

Definition SourceManager.h:85

@ C_ExternCSystem

Definition SourceManager.h:84

@ C_User

Definition SourceManager.h:82

@ C_System

Definition SourceManager.h:83

bool isSystem(CharacteristicKind CK)

Determine whether a file / directory characteristic is for system code.

Definition SourceManager.h:90

bool isModuleMap(CharacteristicKind CK)

Determine whether a file characteristic is for a module map.

Definition SourceManager.h:95

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

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

ArrayRef< std::pair< std::string, FullSourceLoc > > ModuleBuildStack

The stack used when building modules on demand, which is used to provide a link between the source ma...

Definition SourceManager.h:649

std::pair< FileID, unsigned > FileIDAndOffset

nullptr

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

const size_t mmap_bytes

Definition SourceManager.h:1619

const size_t malloc_bytes

Definition SourceManager.h:1618

MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)

Definition SourceManager.h:1621