clang: include/clang/ExtractAPI/API.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18#ifndef LLVM_CLANG_EXTRACTAPI_API_H

19#define LLVM_CLANG_EXTRACTAPI_API_H

20

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

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

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

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

30#include "llvm/TargetParser/Triple.h"

31#include

32#include

33#include

34#include

35#include <type_traits>

36

38namespace extractapi {

39

42

43 std::string Type;

44 std::string Name;

45 unsigned int Index;

46 unsigned int Depth;

47 bool IsParameterPack;

48

50 unsigned int Depth, bool IsParameterPack)

51 : Type(Type), Name(Name), Index(Index), Depth(Depth),

52 IsParameterPack(IsParameterPack) {}

53 };

54

55 struct TemplateConstraint {

56

57 std::string Type;

58 std::string Kind;

59 std::string LHS, RHS;

60 };

63

64public:

66

68 for (auto *const Parameter : *Decl->getTemplateParameters()) {

69 const auto *Param = dyn_cast(Parameter);

70 if (!Param)

71 continue;

72 std::string Type;

73 if (Param->hasTypeConstraint())

74 Type = Param->getTypeConstraint()->getNamedConcept()->getName().str();

75 else if (Param->wasDeclaredWithTypename())

76 Type = "typename";

77 else

78 Type = "class";

79

81 Param->getDepth(), Param->isParameterPack());

82 }

83 }

84

86 for (auto *const Parameter : *Decl->getTemplateParameters()) {

87 const auto *Param = dyn_cast(Parameter);

88 if (!Param)

89 continue;

90 std::string Type;

91 if (Param->hasTypeConstraint())

92 Type = Param->getTypeConstraint()->getNamedConcept()->getName().str();

93 else if (Param->wasDeclaredWithTypename())

94 Type = "typename";

95 else

96 Type = "class";

97

99 Param->getDepth(), Param->isParameterPack());

100 }

101 }

102

104 for (auto *const Parameter : *Decl->getTemplateParameters()) {

105 const auto *Param = dyn_cast(Parameter);

106 if (!Param)

107 continue;

108 std::string Type;

109 if (Param->hasTypeConstraint())

110 Type = Param->getTypeConstraint()->getNamedConcept()->getName().str();

111 else if (Param->wasDeclaredWithTypename())

112 Type = "typename";

113 else

114 Type = "class";

115

117 Param->getDepth(), Param->isParameterPack());

118 }

119 }

120

122 return Parameters;

123 }

124

126 return Constraints;

127 }

128

130 unsigned int Index, unsigned int Depth,

131 bool IsParameterPack) {

132 Parameters.emplace_back(Type, Name, Index, Depth, IsParameterPack);

133 }

134

135 bool empty() const { return Parameters.empty() && Constraints.empty(); }

136};

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151using DocComment = std::vectorRawComment::CommentLine;

152

154

155

156

160

161

163

164

166

171

172

173

174

176};

177

178class RecordContext;

179

180

181

182

183

184

186

189

190

191

232 };

233

236

238

242

243

245

246

248

249

250

251

252

253

254

256

257

259

261

263

264private:

267

268

269 mutable APIRecord *NextInContext = nullptr;

270

271public:

273

276

279

281

293

296

297

302};

303

304

305

307public:

310 }

314 }

315

317

319

320

321

323

325

327

329 private:

331

332 public:

338

342

343

346 Current = Current->getNextInContext();

347 return *this;

348 }

351 ++(*this);

352 return tmp;

353 }

354

356 return x.Current == y.Current;

357 }

359 return x.Current != y.Current;

360 }

361 };

362

363 using record_range = llvm::iterator_range<record_iterator>;

366 }

370

371private:

373 mutable APIRecord *First = nullptr;

374 mutable APIRecord *Last = nullptr;

375 bool IsWellFormed() const;

376

377protected:

380};

381

392

395 }

397};

398

399

402

413

425

428 }

430

431private:

432 virtual void anchor();

433};

434

437

451

454 }

457 }

458};

459

471

474 }

477 }

478};

479

480

491

502

505 }

510 }

511

512private:

513 virtual void anchor();

514};

515

518

530

533 }

536 }

537};

538

549

552 }

555 }

556};

557

561

573

576 }

579 }

580};

581

582

592

595 }

597

598private:

599 virtual void anchor();

600};

601

614

617 }

619 switch (K) {

621 LLVM_FALLTHROUGH;

623 LLVM_FALLTHROUGH;

625 LLVM_FALLTHROUGH;

627 LLVM_FALLTHROUGH;

629 LLVM_FALLTHROUGH;

631 LLVM_FALLTHROUGH;

633 return true;

634 default:

635 return false;

636 }

637 }

638

640

642};

643

644

655

658 }

659

661

662private:

663 virtual void anchor();

664};

665

666

677

680 }

683 }

684

686};

687

688

700

703 }

705 switch (K) {

707 LLVM_FALLTHROUGH;

709 LLVM_FALLTHROUGH;

711 LLVM_FALLTHROUGH;

713 LLVM_FALLTHROUGH;

715 LLVM_FALLTHROUGH;

717 return true;

718 default:

719 return false;

720 }

721 }

722

724

726};

727

736

739 }

741

742private:

743 virtual void anchor();

744};

745

755

758 }

760

761private:

762 virtual void anchor();

763};

764

773

776 }

778

779private:

780 virtual void anchor();

781};

782

792

795 }

797

798private:

799 virtual void anchor();

800};

801

812

823

826 }

829 }

830

831private:

832 virtual void anchor();

833};

834

837

848

851 }

853};

854

857

859

870

872};

873

888 }

890

891private:

892 virtual void anchor();

893};

894

909 }

911

912private:

913 virtual void anchor();

914};

915

930 }

932

933private:

934 virtual void anchor();

935};

936

949

952 }

954

955private:

956 virtual void anchor();

957};

958

961

974

977 }

979};

980

992

995 }

998 }

999};

1000

1001

1003

1008 };

1009

1014

1027

1030

1032};

1033

1045

1048 }

1050

1051private:

1052 virtual void anchor();

1053};

1054

1068

1071 }

1073

1074private:

1075 virtual void anchor();

1076};

1077

1078

1090

1093 }

1095

1096private:

1097 virtual void anchor();

1098};

1099

1100

1103

1105

1116

1118};

1119

1133 }

1135

1136private:

1137 virtual void anchor();

1138};

1139

1150

1153 }

1155

1156private:

1157 virtual void anchor();

1158};

1159

1170

1173 }

1175};

1176

1177

1178

1181

1183

1194

1196};

1197

1200

1210

1213 }

1218 }

1219

1220private:

1221 virtual void anchor();

1222};

1223

1226

1237

1240 }

1242};

1243

1253

1256 }

1259 }

1260};

1261

1274

1277 }

1280 }

1281};

1282

1285

1295

1298 }

1300};

1301

1302

1305

1317

1320 }

1322

1324

1327 return {};

1329 }

1330

1331private:

1332 virtual void anchor();

1333};

1334

1335

1338

1349

1352 }

1354

1355private:

1356 virtual void anchor();

1357};

1358

1359

1370

1373 }

1375

1376private:

1377 virtual void anchor();

1378};

1379

1380

1389

1392 }

1394

1395private:

1396 virtual void anchor();

1397};

1398

1399

1400

1401

1402

1403

1406

1416

1419 }

1421

1422private:

1423 virtual void anchor();

1424};

1425

1426

1428public:

1429

1431

1432

1434

1435

1436

1437

1439

1440

1441

1442

1443 StringRef copyString(StringRef String);

1444

1446 StringRef Source = "");

1447

1448

1449

1450

1451

1452 template <typename RecordTy, typename... CtorArgsContTy>

1453 typename std::enable_if_t<std::is_base_of_v<APIRecord, RecordTy>, RecordTy> *

1454 createRecord(StringRef USR, StringRef Name, CtorArgsContTy &&...CtorArgs);

1455

1457 return TopLevelRecords;

1458 }

1459

1461

1463

1467

1468

1473

1474private:

1475

1476 llvm::BumpPtrAllocator Allocator;

1477

1478 const llvm::Triple Target;

1480

1481 struct APIRecordDeleter {

1483 };

1484

1485

1486

1487

1488 using APIRecordStoredPtr = std::unique_ptr<APIRecord, APIRecordDeleter>;

1489 llvm::DenseMap<StringRef, APIRecordStoredPtr> USRBasedLookupTable;

1491

1492public:

1494};

1495

1496template <typename RecordTy, typename... CtorArgsContTy>

1497typename std::enable_if_t<std::is_base_of_v<APIRecord, RecordTy>, RecordTy> *

1499 CtorArgsContTy &&...CtorArgs) {

1500

1502 auto Result = USRBasedLookupTable.insert({USRString, nullptr});

1504

1505

1506 if (Result.second) {

1507 Record = new (Allocator) RecordTy(

1508 USRString, copyString(Name), std::forward(CtorArgs)...);

1509

1510 Result.first->second = APIRecordStoredPtr(Record);

1511

1512 if (auto *ParentContext =

1513 dyn_cast_if_present(Record->Parent.Record))

1514 ParentContext->addToRecordChain(Record);

1515 else

1516 TopLevelRecords.push_back(Record);

1517 } else {

1518 Record = dyn_cast(Result.first->second.get());

1519 }

1520

1522}

1523

1524

1525

1526template <typename FromTy,

1527 bool IsKnownSubType = std::is_base_of_v<RecordContext, FromTy>>

1529 static_assert(std::is_base_of_v<APIRecord, FromTy>,

1530 "Can only cast APIRecord and derived classes to RecordContext");

1531

1533

1536 }

1537};

1538

1539

1541 static_assert(std::is_base_of_v<APIRecord, FromTy>,

1542 "Can only cast APIRecord and derived classes to RecordContext");

1543 static bool isPossible(const FromTy *From) { return true; }

1546 }

1547};

1548

1549

1550

1551template <typename ToTy,

1552 bool IsKnownSubType = std::is_base_of_v<RecordContext, ToTy>>

1554 static_assert(

1555 std::is_base_of_v<APIRecord, ToTy>,

1556 "Can only class RecordContext to APIRecord and derived classes");

1557

1559 return ToTy::classofKind(Ctx->getKind());

1560 }

1561

1564 }

1565};

1566

1567

1569 static_assert(

1570 std::is_base_of_v<APIRecord, ToTy>,

1571 "Can only class RecordContext to APIRecord and derived classes");

1573 return ToTy::classof(Ctx->getKind());

1574 }

1576 return static_cast<ToTy *>(Ctx);

1577 }

1578};

1579

1580}

1581}

1582

1583

1584

1585namespace llvm {

1586

1587template

1591 ::clang::extractapi::RecordContext *, FromTy *,

1592 CastInfo<::clang::extractapi::RecordContext, FromTy *>> {

1594 return ::clang::extractapi::ToRecordContextCastInfoWrapper<

1595 FromTy>::isPossible(From);

1596 }

1597

1598 static inline ::clang::extractapi::RecordContext *doCast(FromTy *From) {

1599 return ::clang::extractapi::ToRecordContextCastInfoWrapper::doCast(

1600 From);

1601 }

1602};

1603

1604template

1607 ::clang::extractapi::RecordContext, const FromTy *,

1608 CastInfo<::clang::extractapi::RecordContext, FromTy *>> {};

1609

1610template

1614 ToTy *, ::clang::extractapi::RecordContext *,

1615 CastInfo<ToTy, ::clang::extractapi::RecordContext *>> {

1617 return ::clang::extractapi::FromRecordContextCastInfoWrapper<

1618 ToTy>::isPossible(Ctx);

1619 }

1620

1622 return ::clang::extractapi::FromRecordContextCastInfoWrapper::doCast(

1623 Ctx);

1624 }

1625};

1626

1627template

1630 ToTy, const ::clang::extractapi::RecordContext *,

1631 CastInfo<ToTy, ::clang::extractapi::RecordContext *>> {};

1632

1633}

1634

1635#endif

enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind

This file defines the Declaration Fragments related classes.

llvm::MachO::Target Target

llvm::MachO::Record Record

Defines the clang::SourceLocation class and associated facilities.

Decl - This represents one declaration (or definition), e.g.

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

The base class of all kinds of template declarations (e.g., class, function, etc.).

The base class of the type hierarchy.

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

Linkage

Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.

Language

The language for the input, used to select and validate the language standard and possible actions.

@ Parameter

The parameter type of a method or function.

@ Result

The result type of a method or function.

llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter

Stores a template parameter of any kind.

@ Other

Other implicit parameter.

Diagnostic wrappers for TextAPI types for error reporting.

Storage of availability attributes for a declaration.