clang: include/clang/ASTMatchers/ASTMatchersMacros.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

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H

50#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H

51

53

54

55

56

57#define AST_MATCHER_FUNCTION(ReturnType, DefineMatcher) \

58 inline ReturnType DefineMatcher##_getInstance(); \

59 inline ReturnType DefineMatcher() { \

60 return ::clang::ast_matchers::internal::MemoizedMatcher< \

61 ReturnType, DefineMatcher##_getInstance>::getInstance(); \

62 } \

63 inline ReturnType DefineMatcher##_getInstance()

64

65

66

67

68

69

70

71

72

73

74

75

76#define AST_MATCHER_FUNCTION_P(ReturnType, DefineMatcher, ParamType, Param) \

77 AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, Param, \

78 0)

79#define AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, \

80 Param, OverloadId) \

81 inline ReturnType DefineMatcher(ParamType const &Param); \

82 typedef ReturnType (&DefineMatcher##_Type##OverloadId)(ParamType const &); \

83 inline ReturnType DefineMatcher(ParamType const &Param)

84

85

86

87

88

89

90

91

92

93

94

95

96#define AST_MATCHER(Type, DefineMatcher) \

97 namespace internal { \

98 class matcher_##DefineMatcher##Matcher \

99 : public ::clang::ast_matchers::internal::MatcherInterface { \

100 public: \

101 explicit matcher_##DefineMatcher##Matcher() = default; \

102 bool matches(const Type &Node, \

103 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

104 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

105 *Builder) const override; \

106 }; \

107 } \

108 inline ::clang::ast_matchers::internal::Matcher DefineMatcher() { \

109 return ::clang::ast_matchers::internal::makeMatcher( \

110 new internal::matcher_##DefineMatcher##Matcher()); \

111 } \

112 inline bool internal::matcher_##DefineMatcher##Matcher::matches( \

113 const Type &Node, \

114 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

115 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130#define AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) \

131 AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, 0)

132

133#define AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, \

134 OverloadId) \

135 namespace internal { \

136 class matcher_##DefineMatcher##OverloadId##Matcher \

137 : public ::clang::ast_matchers::internal::MatcherInterface { \

138 public: \

139 explicit matcher_##DefineMatcher##OverloadId##Matcher( \

140 ParamType const &A##Param) \

141 : Param(A##Param) {} \

142 bool matches(const Type &Node, \

143 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

144 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

145 *Builder) const override; \

146 \

147 private: \

148 ParamType Param; \

149 }; \

150 } \

151 inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \

152 ParamType const &Param) { \

153 return ::clang::ast_matchers::internal::makeMatcher( \

154 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param)); \

155 } \

156 typedef ::clang::ast_matchers::internal::Matcher ( \

157 &DefineMatcher##_Type##OverloadId)(ParamType const &Param); \

158 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \

159 const Type &Node, \

160 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

161 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177#define AST_MATCHER_P2(Type, DefineMatcher, ParamType1, Param1, ParamType2, \

178 Param2) \

179 AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, ParamType2, \

180 Param2, 0)

181

182#define AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, \

183 ParamType2, Param2, OverloadId) \

184 namespace internal { \

185 class matcher_##DefineMatcher##OverloadId##Matcher \

186 : public ::clang::ast_matchers::internal::MatcherInterface { \

187 public: \

188 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \

189 ParamType2 const &A##Param2) \

190 : Param1(A##Param1), Param2(A##Param2) {} \

191 bool matches(const Type &Node, \

192 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

193 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

194 *Builder) const override; \

195 \

196 private: \

197 ParamType1 Param1; \

198 ParamType2 Param2; \

199 }; \

200 } \

201 inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \

202 ParamType1 const &Param1, ParamType2 const &Param2) { \

203 return ::clang::ast_matchers::internal::makeMatcher( \

204 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1, \

205 Param2)); \

206 } \

207 typedef ::clang::ast_matchers::internal::Matcher ( \

208 &DefineMatcher##_Type##OverloadId)(ParamType1 const &Param1, \

209 ParamType2 const &Param2); \

210 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \

211 const Type &Node, \

212 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

213 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const

214

215

216

217

218

219

220

221

222

223#define AST_POLYMORPHIC_SUPPORTED_TYPES(...) \

224 void(::clang::ast_matchers::internal::TypeList<__VA_ARGS__>)

225

226

227

228

229

230

231

232#define AST_POLYMORPHIC_MATCHER(DefineMatcher, ReturnTypesF) \

233 namespace internal { \

234 template \

235 class matcher_##DefineMatcher##Matcher \

236 : public ::clang::ast_matchers::internal::MatcherInterface { \

237 public: \

238 bool matches(const NodeType &Node, \

239 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

240 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

241 *Builder) const override; \

242 }; \

243 } \

244 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \

245 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF> \

246 DefineMatcher() { \

247 return ::clang::ast_matchers::internal::PolymorphicMatcher< \

248 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF>(); \

249 } \

250 template \

251 bool internal::matcher_##DefineMatcher##Matcher::matches( \

252 const NodeType &Node, \

253 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

254 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const

255

256

257

258

259

260

261

262

263

264

265#define AST_POLYMORPHIC_MATCHER_P(DefineMatcher, ReturnTypesF, ParamType, \

266 Param) \

267 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType, \

268 Param, 0)

269

270#define AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, \

271 ParamType, Param, OverloadId) \

272 namespace internal { \

273 template <typename NodeType, typename ParamT> \

274 class matcher_##DefineMatcher##OverloadId##Matcher \

275 : public ::clang::ast_matchers::internal::MatcherInterface { \

276 public: \

277 explicit matcher_##DefineMatcher##OverloadId##Matcher( \

278 ParamType const &A##Param) \

279 : Param(A##Param) {} \

280 bool matches(const NodeType &Node, \

281 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

282 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

283 *Builder) const override; \

284 \

285 private: \

286 ParamType Param; \

287 }; \

288 } \

289 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \

290 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

291 ParamType> \

292 DefineMatcher(ParamType const &Param) { \

293 return ::clang::ast_matchers::internal::PolymorphicMatcher< \

294 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

295 ParamType>(Param); \

296 } \

297 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \

298 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

299 ParamType> (&DefineMatcher##_Type##OverloadId)(ParamType const &Param); \

300 template <typename NodeType, typename ParamT> \

301 bool internal:: \

302 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \

303 const NodeType &Node, \

304 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

305 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \

306 const

307

308

309

310

311

312

313

314

315

316#define AST_POLYMORPHIC_MATCHER_P2(DefineMatcher, ReturnTypesF, ParamType1, \

317 Param1, ParamType2, Param2) \

318 AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType1, \

319 Param1, ParamType2, Param2, 0)

320

321#define AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, \

322 ParamType1, Param1, ParamType2, \

323 Param2, OverloadId) \

324 namespace internal { \

325 template <typename NodeType, typename ParamT1, typename ParamT2> \

326 class matcher_##DefineMatcher##OverloadId##Matcher \

327 : public ::clang::ast_matchers::internal::MatcherInterface { \

328 public: \

329 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \

330 ParamType2 const &A##Param2) \

331 : Param1(A##Param1), Param2(A##Param2) {} \

332 bool matches(const NodeType &Node, \

333 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

334 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

335 *Builder) const override; \

336 \

337 private: \

338 ParamType1 Param1; \

339 ParamType2 Param2; \

340 }; \

341 } \

342 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \

343 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

344 ParamType1, ParamType2> \

345 DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) { \

346 return ::clang::ast_matchers::internal::PolymorphicMatcher< \

347 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

348 ParamType1, ParamType2>(Param1, Param2); \

349 } \

350 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \

351 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

352 ParamType1, ParamType2> (&DefineMatcher##_Type##OverloadId)( \

353 ParamType1 const &Param1, ParamType2 const &Param2); \

354 template <typename NodeType, typename ParamT1, typename ParamT2> \

355 bool internal::matcher_##DefineMatcher##OverloadId##Matcher< \

356 NodeType, ParamT1, ParamT2>:: \

357 matches(const NodeType &Node, \

358 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

359 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \

360 const

361

362

363

364

365#define AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \

366 ReturnTypesF) \

367 namespace internal { \

368 template struct TypeMatcher##MatcherName##Getter { \

369 static QualType (T::*value())() const { return &T::FunctionName; } \

370 }; \

371 } \

372 CLANG_ABI extern const ::clang::ast_matchers::internal:: \

373 TypeTraversePolymorphicMatcher< \

374 QualType, \

375 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \

376 ::clang::ast_matchers::internal::TypeTraverseMatcher, \

377 ReturnTypesF>::Func MatcherName

378

379#define AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \

380 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \

381 QualType, \

382 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \

383 ::clang::ast_matchers::internal::TypeTraverseMatcher, \

384 ReturnTypesF>::Func MatcherName

385

386

387

388

389

390

391

392

393#define AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \

394 namespace internal { \

395 template struct TypeMatcher##MatcherName##Getter { \

396 static QualType (T::*value())() const { return &T::FunctionName; } \

397 }; \

398 } \

399 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \

400 QualType, \

401 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \

402 ::clang::ast_matchers::internal::TypeTraverseMatcher, \

403 ReturnTypesF>::Func MatcherName

404

405#define AST_TYPELOC_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \

406 ReturnTypesF) \

407 namespace internal { \

408 template struct TypeLocMatcher##MatcherName##Getter { \

409 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \

410 }; \

411 } \

412 CLANG_ABI extern const ::clang::ast_matchers::internal:: \

413 TypeTraversePolymorphicMatcher< \

414 TypeLoc, \

415 ::clang::ast_matchers::internal:: \

416 TypeLocMatcher##MatcherName##Getter, \

417 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \

418 ReturnTypesF>::Func MatcherName##Loc; \

419 AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName##Type, ReturnTypesF)

420

421#define AST_TYPELOC_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \

422 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \

423 TypeLoc, \

424 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \

425 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \

426 ReturnTypesF>::Func MatcherName##Loc; \

427 AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF)

428

429

430

431#define AST_TYPELOC_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \

432 namespace internal { \

433 template struct TypeLocMatcher##MatcherName##Getter { \

434 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \

435 }; \

436 } \

437 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \

438 TypeLoc, \

439 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \

440 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \

441 ReturnTypesF>::Func MatcherName##Loc; \

442 AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName##Type, ReturnTypesF)

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457#define AST_MATCHER_REGEX(Type, DefineMatcher, Param) \

458 AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, 0)

459

460#define AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, OverloadId) \

461 namespace internal { \

462 class matcher_##DefineMatcher##OverloadId##Matcher \

463 : public ::clang::ast_matchers::internal::MatcherInterface { \

464 public: \

465 explicit matcher_##DefineMatcher##OverloadId##Matcher( \

466 std::shared_ptrllvm::Regex RE) \

467 : Param(std::move(RE)) {} \

468 bool matches(const Type &Node, \

469 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

470 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

471 *Builder) const override; \

472 \

473 private: \

474 std::shared_ptrllvm::Regex Param; \

475 }; \

476 } \

477 inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \

478 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \

479 return ::clang::ast_matchers::internal::makeMatcher( \

480 new internal::matcher_##DefineMatcher##OverloadId##Matcher( \

481 ::clang::ast_matchers::internal::createAndVerifyRegex( \

482 Param, RegexFlags, #DefineMatcher))); \

483 } \

484 inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \

485 llvm::StringRef Param) { \

486 return DefineMatcher(Param, llvm::Regex::NoFlags); \

487 } \

488 \

489 typedef ::clang::ast_matchers::internal::Matcher ( \

490 &DefineMatcher##_Type##OverloadId##Flags)(llvm::StringRef, \

491 llvm::Regex::RegexFlags); \

492 typedef ::clang::ast_matchers::internal::Matcher ( \

493 &DefineMatcher##_Type##OverloadId)(llvm::StringRef); \

494 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \

495 const Type &Node, \

496 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

497 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const

498

499

500

501

502

503

504

505

506

507#define AST_POLYMORPHIC_MATCHER_REGEX(DefineMatcher, ReturnTypesF, Param) \

508 AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, Param, 0)

509

510#define AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, \

511 Param, OverloadId) \

512 namespace internal { \

513 template <typename NodeType, typename ParamT> \

514 class matcher_##DefineMatcher##OverloadId##Matcher \

515 : public ::clang::ast_matchers::internal::MatcherInterface { \

516 public: \

517 explicit matcher_##DefineMatcher##OverloadId##Matcher( \

518 std::shared_ptrllvm::Regex RE) \

519 : Param(std::move(RE)) {} \

520 bool matches(const NodeType &Node, \

521 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

522 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \

523 *Builder) const override; \

524 \

525 private: \

526 std::shared_ptrllvm::Regex Param; \

527 }; \

528 } \

529 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \

530 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

531 std::shared_ptrllvm::Regex> \

532 DefineMatcher(llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \

533 return ::clang::ast_matchers::internal::PolymorphicMatcher< \

534 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

535 std::shared_ptrllvm::Regex>( \

536 ::clang::ast_matchers::internal::createAndVerifyRegex( \

537 Param, RegexFlags, #DefineMatcher)); \

538 } \

539 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \

540 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

541 std::shared_ptrllvm::Regex> \

542 DefineMatcher(llvm::StringRef Param) { \

543 return DefineMatcher(Param, llvm::Regex::NoFlags); \

544 } \

545 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \

546 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

547 std::shared_ptrllvm::Regex> ( \

548 &DefineMatcher##_Type##OverloadId##Flags)( \

549 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags); \

550 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \

551 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \

552 std::shared_ptrllvm::Regex> (&DefineMatcher##_Type##OverloadId)( \

553 llvm::StringRef Param); \

554 template <typename NodeType, typename ParamT> \

555 bool internal:: \

556 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \

557 const NodeType &Node, \

558 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \

559 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \

560 const

561

562#endif