|
3 | 3 | #include <slang/ast/ASTVisitor.h> |
4 | 4 | #include <unordered_map> |
5 | 5 |
|
| 6 | +template <typename TNodeMapper> |
| 7 | +SetRemover makeSetRemover(std::shared_ptr<SyntaxTree> tree) { |
| 8 | + Compilation compilation; |
| 9 | + compilation.addSyntaxTree(tree); |
| 10 | + compilation.getAllDiagnostics(); |
| 11 | + TNodeMapper mapper; |
| 12 | + compilation.getRoot().visit(mapper); |
| 13 | + return SetRemover(std::move(mapper.removals)); |
| 14 | +} |
| 15 | + |
6 | 16 | class FunctionArgMapper final : public ASTVisitor<FunctionArgMapper, true, true, true> { |
7 | 17 | // Builds vector that maps the argument in definition to all calls |
8 | 18 | public: |
@@ -127,12 +137,7 @@ class FunctionArgMapper final : public ASTVisitor<FunctionArgMapper, true, true, |
127 | 137 | }; |
128 | 138 |
|
129 | 139 | SetRemover makeFunctionArgRemover(std::shared_ptr<SyntaxTree> tree) { |
130 | | - Compilation compilation; |
131 | | - compilation.addSyntaxTree(tree); |
132 | | - compilation.getAllDiagnostics(); |
133 | | - FunctionArgMapper mapper; |
134 | | - compilation.getRoot().visit(mapper); |
135 | | - return SetRemover(std::move(mapper.removals)); |
| 140 | + return makeSetRemover<FunctionArgMapper>(tree); |
136 | 141 | } |
137 | 142 |
|
138 | 143 | class PortMapper final : public ASTVisitor<PortMapper, true, true, true> { |
@@ -220,12 +225,7 @@ class PortMapper final : public ASTVisitor<PortMapper, true, true, true> { |
220 | 225 | }; |
221 | 226 |
|
222 | 227 | SetRemover makePortsRemover(std::shared_ptr<SyntaxTree> tree) { |
223 | | - Compilation compilation; |
224 | | - compilation.addSyntaxTree(tree); |
225 | | - compilation.getAllDiagnostics(); // kludge for launching full elaboration |
226 | | - PortMapper mapper; |
227 | | - compilation.getRoot().visit(mapper); |
228 | | - return SetRemover(std::move(mapper.removals)); |
| 228 | + return makeSetRemover<PortMapper>(tree); |
229 | 229 | } |
230 | 230 |
|
231 | 231 | class ExternMapper final : public ASTVisitor<ExternMapper, true, true, true> { |
@@ -262,12 +262,7 @@ class ExternMapper final : public ASTVisitor<ExternMapper, true, true, true> { |
262 | 262 | }; |
263 | 263 |
|
264 | 264 | SetRemover makeExternRemover(std::shared_ptr<SyntaxTree> tree) { |
265 | | - Compilation compilation; |
266 | | - compilation.addSyntaxTree(tree); |
267 | | - compilation.getAllDiagnostics(); // kludge for launching full elaboration |
268 | | - ExternMapper mapper; |
269 | | - compilation.getRoot().visit(mapper); |
270 | | - return SetRemover(std::move(mapper.removals)); |
| 265 | + return makeSetRemover<ExternMapper>(tree); |
271 | 266 | } |
272 | 267 |
|
273 | 268 | class StructFieldMapper final : public ASTVisitor<StructFieldMapper, true, true, true> { |
@@ -295,10 +290,5 @@ class StructFieldMapper final : public ASTVisitor<StructFieldMapper, true, true, |
295 | 290 | }; |
296 | 291 |
|
297 | 292 | SetRemover makeStructFieldRemover(std::shared_ptr<SyntaxTree> tree) { |
298 | | - Compilation compilation; |
299 | | - compilation.addSyntaxTree(tree); |
300 | | - compilation.getAllDiagnostics(); // kludge for launching full elaboration |
301 | | - StructFieldMapper mapper; |
302 | | - compilation.getRoot().visit(mapper); |
303 | | - return SetRemover(std::move(mapper.removals)); |
| 293 | + return makeSetRemover<StructFieldMapper>(tree); |
304 | 294 | } |
0 commit comments