mirror of
https://github.com/verilator/verilator.git
synced 2025-04-16 01:26:54 +00:00
Internals: Generate ASTGEN_SUPER_* macros instead of expanding. (#2975)
astgen now generates ASTGEN_SUPER_* macros, instead of expanding the ASTGEN_SUPER itself. This means that V3AstNodes.h itself can be included in V3Ast.h, which helps IDEs (namely CLion) find definitions in V3AstNodes.h a lot better. Albeit this is a little bit more boilerplate, writing constructors of Ast nodes should be a lot rarer than trying to find their definitions, so hopefully this is an improvement overall. astgen will error if the developer calls the wrong superclass constructor.
This commit is contained in:
parent
63782556ae
commit
61c9866a1e
@ -2916,7 +2916,7 @@ public:
|
||||
|
||||
//######################################################################
|
||||
|
||||
#include "V3AstNodes__gen.h"
|
||||
#include "V3AstNodes.h"
|
||||
|
||||
//######################################################################
|
||||
// Inline AstNVisitor METHODS
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "V3String.h"
|
||||
#include "V3EmitCBase.h"
|
||||
|
||||
#include "V3AstNodes__gen_macros.h" // Generated by 'astgen'
|
||||
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
@ -214,7 +216,7 @@ AstNodeBiop* AstEqWild::newTyped(FileLine* fl, AstNode* lhsp, AstNode* rhsp) {
|
||||
}
|
||||
|
||||
AstExecGraph::AstExecGraph(FileLine* fileline)
|
||||
: AstNode{AstType::atExecGraph, fileline} {
|
||||
: ASTGEN_SUPER_ExecGraph(fileline) {
|
||||
m_depGraphp = new V3Graph;
|
||||
}
|
||||
AstExecGraph::~AstExecGraph() { VL_DO_DANGLING(delete m_depGraphp, m_depGraphp); }
|
||||
|
843
src/V3AstNodes.h
843
src/V3AstNodes.h
File diff suppressed because it is too large
Load Diff
27
src/astgen
27
src/astgen
@ -621,7 +621,7 @@ def write_types(filename):
|
||||
fh.write(" }\n")
|
||||
|
||||
|
||||
def write_header(filename):
|
||||
def write_macros(filename):
|
||||
with open_file(filename) as fh:
|
||||
typen = "None"
|
||||
base = "None"
|
||||
@ -629,10 +629,7 @@ def write_header(filename):
|
||||
in_filename = "V3AstNodes.h"
|
||||
ifile = Args.I + "/" + in_filename
|
||||
with open(ifile) as ifh:
|
||||
|
||||
fh.write("#line 1 \"../" + in_filename + "\"\n")
|
||||
|
||||
for line in ifh:
|
||||
for (lineno, line) in enumerate(ifh, 1):
|
||||
# Drop expanded macro definitions - but keep empty line so compiler
|
||||
# message locations are accurate
|
||||
line = re.sub(r'^\s*#(define|undef)\s+ASTGEN_.*$', '', line)
|
||||
@ -644,14 +641,18 @@ def write_header(filename):
|
||||
if match:
|
||||
typen = match.group(1)
|
||||
base = match.group(4)
|
||||
if not typen.startswith("Node"):
|
||||
macro = "#define ASTGEN_SUPER_{t}(...) {b}(AstType::at{t}, __VA_ARGS__)\n" \
|
||||
.format(b=base, t=typen)
|
||||
fh.write(macro)
|
||||
|
||||
# Substitute macros
|
||||
line = re.sub(r'\bASTGEN_SUPER\s*\(',
|
||||
base + "(AstType::at" + typen + ", ", line)
|
||||
|
||||
# Emit the line
|
||||
fh.write(line)
|
||||
|
||||
match = re.search(r"ASTGEN_SUPER_(\w+)", line)
|
||||
if match:
|
||||
if typen != match.group(1):
|
||||
print(("V3AstNodes.h:{l} ERROR: class Ast{t} calls wrong superclass " +
|
||||
"constructor macro (should call ASTGEN_SUPER_{t})")
|
||||
.format(l=lineno, t=typen))
|
||||
sys.exit(1)
|
||||
|
||||
######################################################################
|
||||
# main
|
||||
@ -708,7 +709,7 @@ if Args.classes:
|
||||
write_visitor("V3Ast__gen_visitor.h")
|
||||
write_impl("V3Ast__gen_impl.h")
|
||||
write_types("V3Ast__gen_types.h")
|
||||
write_header("V3AstNodes__gen.h")
|
||||
write_macros("V3AstNodes__gen_macros.h")
|
||||
|
||||
for cpt in Args.infiles:
|
||||
if not re.search(r'.cpp$', cpt):
|
||||
|
Loading…
Reference in New Issue
Block a user