From bd211c87aa2f5ae30c1c01dd31f582c46c79dfd9 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Tue, 2 Aug 2022 16:46:31 +0100 Subject: [PATCH] astgen: split 'visit' method declarations from definitions Add definitions to V3Ast.cpp, and use static_cast. This fixes a lot of clang-tidy noise. --- src/V3Ast.cpp | 5 +++++ src/V3Ast.h | 6 ++---- src/astgen | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 9a6e7fca8..de595be61 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -1293,3 +1293,8 @@ void VNDeleter::doDeletes() { for (AstNode* const nodep : m_deleteps) nodep->deleteTree(); m_deleteps.clear(); } + +//###################################################################### +// VNVisitor + +#include "V3Ast__gen_visitor_defns.h" // From ./astgen diff --git a/src/V3Ast.h b/src/V3Ast.h index e93dc4d86..45fe1fc98 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1297,10 +1297,8 @@ public: /// Return edited nodep; see comments in V3Ast.cpp AstNode* iterateSubtreeReturnEdits(AstNode* nodep); -#include "V3Ast__gen_visitor.h" // From ./astgen - // Things like: - // virtual void visit(AstBreak* nodep) { visit((AstNodeStmt*)(nodep)); } - // virtual void visit(AstNodeStmt* nodep) { visit((AstNode*)(nodep)); } + virtual void visit(AstNode* nodep) = 0; +#include "V3Ast__gen_visitor_decls.h" // From ./astgen }; //###################################################################### diff --git a/src/astgen b/src/astgen index b6071c06b..44529a0e4 100755 --- a/src/astgen +++ b/src/astgen @@ -507,15 +507,21 @@ def write_classes(filename): fh.write("\n") -def write_visitor(filename): +def write_visitor_decls(filename): with open_file(filename) as fh: for typen in sorted(Classes.keys()): - if typen == "Node": - fh.write(" virtual void visit(Ast" + typen + "*) = 0;\n") - else: + if typen != "Node": + fh.write("virtual void visit(Ast" + typen + "*);\n") + + +def write_visitor_defns(filename): + with open_file(filename) as fh: + for typen in sorted(Classes.keys()): + if typen != "Node": base = Classes[typen] - fh.write(" virtual void visit(Ast" + typen + - "* nodep) { visit((Ast" + base + "*)(nodep)); }\n") + fh.write("void VNVisitor::visit(Ast" + typen + + "* nodep) { visit(static_cast(nodep)); }\n") def write_impl(filename): @@ -692,7 +698,8 @@ for filename in source_files: if Args.classes: write_report("V3Ast__gen_report.txt") write_classes("V3Ast__gen_classes.h") - write_visitor("V3Ast__gen_visitor.h") + write_visitor_decls("V3Ast__gen_visitor_decls.h") + write_visitor_defns("V3Ast__gen_visitor_defns.h") write_impl("V3Ast__gen_impl.h") write_types("V3Ast__gen_types.h") write_yystype("V3Ast__gen_yystype.h")