astgen: generate type specific addNext, remove astNextNull

Generate type specific static overloads of Ast<Node>::addNext, which
return the correct sub-type of the 'this' they were invoked on.

Also remove AstNode::addNextNull, which is now only used in the parser,
implement in verilog.y directly as a template function.
This commit is contained in:
Geza Lore
2022-09-17 15:05:22 +01:00
parent 79be097e34
commit 7d88e63bab
14 changed files with 142 additions and 160 deletions
+7 -11
View File
@@ -177,21 +177,17 @@ private:
const int right = nodep->rangep()->rightConst();
const int increment = (left > right) ? -1 : 1;
int offset_from_init = 0;
AstNode* addp = nullptr;
AstEnumItem* addp = nullptr;
FileLine* const flp = nodep->fileline();
for (int i = left; i != (right + increment); i += increment, offset_from_init++) {
const string name = nodep->name() + cvtToStr(i);
AstNode* valuep = nullptr;
if (nodep->valuep()) {
valuep = new AstAdd(
nodep->fileline(), nodep->valuep()->cloneTree(true),
new AstConst(nodep->fileline(), AstConst::Unsized32(), offset_from_init));
}
AstNode* const newp = new AstEnumItem(nodep->fileline(), name, nullptr, valuep);
if (addp) {
addp = addp->addNextNull(newp);
} else {
addp = newp;
valuep
= new AstAdd(flp, nodep->valuep()->cloneTree(true),
new AstConst(flp, AstConst::Unsized32(), offset_from_init));
}
addp = AstNode::addNext(addp, new AstEnumItem{flp, name, nullptr, valuep});
}
nodep->replaceWith(addp);
VL_DO_DANGLING(nodep->deleteTree(), nodep);
@@ -372,7 +368,7 @@ private:
iterateChildren(nodep);
if (m_varp) {
nodep->unlinkFrBack();
m_varp->addNext(nodep);
AstNode::addNext<AstNode, AstNode>(m_varp, nodep);
// lvalue is true, because we know we have a verilator public_flat_rw
// but someday we may be more general
const bool lvalue = m_varp->isSigUserRWPublic();