Skip to content

Commit 1b75034

Browse files
committed
Swift: simplify CRTP monkey-patching
1 parent f857cd1 commit 1b75034

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

swift/extractor/visitors/PatternVisitor.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55

66
namespace codeql {
77

8+
namespace detail {
89
// swift code lacks default implementations of visitor for some entities. We can add those here
9-
// while we do not have yet all implemented. This is copy and pasted from the corresponding Expr
10+
// while we do not have yet all implemented. This is a simplified version of the corresponding Expr
1011
// code in swift/AST/ASTVisitor.h
11-
template <typename ImplClass, typename PatternRetTy = void, typename... Args>
12-
class PatchedPatternVisitor : public swift::PatternVisitor<ImplClass, PatternRetTy, Args...> {
12+
template <typename CrtpSubclass>
13+
class PatchedPatternVisitor : public swift::PatternVisitor<CrtpSubclass> {
1314
public:
14-
#define PATTERN(CLASS, PARENT) \
15-
PatternRetTy visit##CLASS##Pattern(swift::CLASS##Pattern* E, Args... AA) { \
16-
return static_cast<ImplClass*>(this)->visit##PARENT(E, ::std::forward<Args>(AA)...); \
15+
#define PATTERN(CLASS, PARENT) \
16+
void visit##CLASS##Pattern(swift::CLASS##Pattern* E) { \
17+
return static_cast<CrtpSubclass*>(this)->visit##PARENT(E); \
1718
}
1819
#include "swift/AST/PatternNodes.def"
1920
};
2021

21-
class PatternVisitor : public PatchedPatternVisitor<PatternVisitor> {
22+
} // namespace detail
23+
24+
class PatternVisitor : public detail::PatchedPatternVisitor<PatternVisitor> {
2225
public:
2326
// SwiftDispatcher should outlive the PatternVisitor
2427
PatternVisitor(SwiftDispatcher& dispatcher) : dispatcher(dispatcher) {}

swift/extractor/visitors/StmtVisitor.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55

66
namespace codeql {
77

8+
namespace detail {
89
// swift code lacks default implementations of visitor for some entities. We can add those here
9-
// while we do not have yet all implemented. This is copy and pasted from the corresponding Expr
10+
// while we do not have yet all implemented. This is a simplified version of the corresponding Expr
1011
// code in swift/AST/ASTVisitor.h
11-
template <typename ImplClass, typename StmtRetTy = void, typename... Args>
12-
class PatchedStmtVisitor : public swift::StmtVisitor<ImplClass, StmtRetTy, Args...> {
12+
template <typename CrtpSubclass>
13+
class PatchedStmtVisitor : public swift::StmtVisitor<CrtpSubclass> {
1314
public:
14-
#define ABSTRACT_STMT(CLASS, PARENT) \
15-
StmtRetTy visit##CLASS##Stmt(swift::CLASS##Stmt* E, Args... AA) { \
16-
return static_cast<ImplClass*>(this)->visit##PARENT(E, ::std::forward<Args>(AA)...); \
15+
#define ABSTRACT_STMT(CLASS, PARENT) \
16+
void visit##CLASS##Stmt(swift::CLASS##Stmt* E) { \
17+
return static_cast<CrtpSubclass*>(this)->visit##PARENT(E); \
1718
}
1819
#define STMT(CLASS, PARENT) ABSTRACT_STMT(CLASS, PARENT)
1920
#include "swift/AST/StmtNodes.def"
2021
};
2122

22-
class StmtVisitor : public PatchedStmtVisitor<StmtVisitor> {
23+
} // namespace detail
24+
25+
class StmtVisitor : public detail::PatchedStmtVisitor<StmtVisitor> {
2326
public:
2427
// SwiftDispatcher should outlive the StmtVisitor
2528
StmtVisitor(SwiftDispatcher& dispatcher) : dispatcher(dispatcher) {}

0 commit comments

Comments
 (0)