@@ -57,9 +57,18 @@ class SwiftDispatcher {
5757 SwiftDispatcher (const swift::SourceManager& sourceManager, TrapArena& arena, TrapOutput& trap)
5858 : sourceManager{sourceManager}, arena{arena}, trap{trap} {}
5959
60- template <typename T>
61- void extract (T* entity) {
62- fetchLabel (entity);
60+ // This is a helper method to emit TRAP entries for AST nodes that we don't fully support yet.
61+ template <typename Parent, typename Child>
62+ void TBD (Child* entity, const std::string& suffix) {
63+ using namespace std ::string_literals;
64+ auto label = assignNewLabel (entity);
65+ auto kind = detail::getKindName<Parent>(static_cast <const Parent*>(entity)->getKind ());
66+ auto name = " TBD (" s + kind + suffix + " )" ;
67+ if constexpr (std::is_same_v<Parent, swift::TypeBase>) {
68+ trap.emit (UnknownTypesTrap{label, name});
69+ } else {
70+ trap.emit (UnknownAstNodesTrap{label, name});
71+ }
6372 }
6473
6574 private:
@@ -105,20 +114,6 @@ class SwiftDispatcher {
105114 return arena.allocateLabel <Tag>();
106115 }
107116
108- // This is a helper method to emit TRAP entries for AST nodes that we don't fully support yet.
109- template <typename Parent, typename Child>
110- void TBD (Child* entity, const std::string& suffix) {
111- using namespace std ::string_literals;
112- auto label = assignNewLabel (entity);
113- auto kind = detail::getKindName<Parent>(static_cast <const Parent*>(entity)->getKind ());
114- auto name = " TBD (" s + kind + suffix + " )" ;
115- if constexpr (std::is_same_v<Parent, swift::TypeBase>) {
116- trap.emit (UnknownTypesTrap{label, name});
117- } else {
118- trap.emit (UnknownAstNodesTrap{label, name});
119- }
120- }
121-
122117 template <typename Locatable>
123118 void attachLocation (Locatable locatable, TrapLabel<LocatableTag> locatableLabel) {
124119 attachLocation (&locatable, locatableLabel);
@@ -162,12 +157,12 @@ class SwiftDispatcher {
162157
163158 // TODO: The following methods are supposed to redirect TRAP emission to correpsonding visitors,
164159 // which are to be introduced in follow-up PRs
165- void visit (swift::Decl* decl) { TBD<swift::Decl>(decl, " Decl " ); }
166- void visit (swift::Stmt* stmt) { TBD<swift::Stmt>(stmt, " Stmt " ); }
167- void visit (swift::Expr* expr) { TBD<swift::Expr>(expr, " Expr " ); }
168- void visit (swift::Pattern* pattern) { TBD<swift::Pattern>(pattern, " Pattern " ); }
169- void visit (swift::TypeRepr* type) { TBD<swift::TypeRepr>(type, " TypeRepr " ); }
170- void visit (swift::TypeBase* type) { TBD<swift::TypeBase>(type, " Type " ); }
160+ virtual void visit (swift::Decl* decl) = 0;
161+ virtual void visit (swift::Stmt* stmt) = 0;
162+ virtual void visit (swift::Expr* expr) = 0;
163+ virtual void visit (swift::Pattern* pattern) = 0;
164+ virtual void visit (swift::TypeRepr* type) = 0;
165+ virtual void visit (swift::TypeBase* type) = 0;
171166
172167 const swift::SourceManager& sourceManager;
173168 TrapArena& arena;
0 commit comments