@@ -46,7 +46,7 @@ std::string inline getKindName<swift::TypeRepr, swift::TypeReprKind>(swift::Type
46
46
47
47
} // namespace detail
48
48
49
- // The main reponsibilities of the SwiftDispatcher are as follows:
49
+ // The main responsibilities of the SwiftDispatcher are as follows:
50
50
// * redirect specific AST node emission to a corresponding visitor (statements, expressions, etc.)
51
51
// * storing TRAP labels for emitted AST nodes (in the TrapLabelStore) to avoid re-emission
52
52
// Since SwiftDispatcher sees all the AST nodes, it also attaches a location to every 'locatable'
@@ -72,19 +72,28 @@ class SwiftDispatcher {
72
72
}
73
73
74
74
private:
75
+ // types to be supported by assignNewLabel/fetchLabel need to be listed here
76
+ using Store = TrapLabelStore<swift::Decl,
77
+ swift::Stmt,
78
+ swift::Expr,
79
+ swift::Pattern,
80
+ swift::TypeRepr,
81
+ swift::TypeBase>;
82
+
75
83
// This method gives a TRAP label for already emitted AST node.
76
84
// If the AST node was not emitted yet, then the emission is dispatched to a corresponding
77
85
// visitor (see `visit(T *)` methods below).
78
86
template <typename E>
79
- TrapLabel<ToTag<E> > fetchLabel (E* e) {
87
+ TrapLabelOf<E > fetchLabel (E* e) {
80
88
// this is required so we avoid any recursive loop: a `fetchLabel` during the visit of `e` might
81
89
// end up calling `fetchLabel` on `e` itself, so we want the visit of `e` to call `fetchLabel`
82
- // only after having called `assignNewLabel` on `e`
83
- assert (!waitingForNewLabel && " fetchLabel called before assignNewLabel" );
90
+ // only after having called `assignNewLabel` on `e`.
91
+ assert (holds_alternative<std::monostate>(waitingForNewLabel) &&
92
+ " fetchLabel called before assignNewLabel" );
84
93
if (auto l = store.get (e)) {
85
94
return *l;
86
95
}
87
- waitingForNewLabel = getCanonicalPointer (e) ;
96
+ waitingForNewLabel = e ;
88
97
visit (e);
89
98
if (auto l = store.get (e)) {
90
99
if constexpr (!std::is_base_of_v<swift::TypeBase, E>) {
@@ -100,12 +109,12 @@ class SwiftDispatcher {
100
109
// it actually gets emitted to handle recursive cases such as recursive calls, or recursive type
101
110
// declarations
102
111
template <typename E>
103
- TrapLabel<ToTag<E> > assignNewLabel (E* e) {
104
- assert (waitingForNewLabel == getCanonicalPointer (e) && " assignNewLabel called on wrong entity" );
105
- auto label = getLabel<ToTag <E>>();
112
+ TrapLabelOf<E > assignNewLabel (E* e) {
113
+ assert (waitingForNewLabel == Store::Handle{e} && " assignNewLabel called on wrong entity" );
114
+ auto label = getLabel<TrapTagOf <E>>();
106
115
trap.assignStar (label);
107
116
store.insert (e, label);
108
- waitingForNewLabel = nullptr ;
117
+ waitingForNewLabel = std::monostate{} ;
109
118
return label;
110
119
}
111
120
@@ -167,8 +176,8 @@ class SwiftDispatcher {
167
176
const swift::SourceManager& sourceManager;
168
177
TrapArena& arena;
169
178
TrapOutput& trap;
170
- TrapLabelStore store;
171
- const void * waitingForNewLabel{nullptr };
179
+ Store store;
180
+ Store::Handle waitingForNewLabel{std::monostate{} };
172
181
};
173
182
174
183
} // namespace codeql
0 commit comments