Add AstNode::foreach method for simple pre-order traversal (#3276)

This commit is contained in:
Geza Lore
2022-01-09 22:34:10 +00:00
committed by GitHub
parent 50094ca296
commit 64a6e1ac8b
15 changed files with 207 additions and 317 deletions
+4 -31
View File
@@ -243,36 +243,6 @@ public:
}
};
//######################################################################
// Using clonep(), find cell cross references.
// clone() must not be called inside this visitor
class InlineCollectVisitor final : public VNVisitor {
private:
// NODE STATE
// Output:
// AstCell::user4p() // AstCell* of the created clone
// METHODS
VL_DEBUG_FUNC; // Declare debug()
// VISITORS
virtual void visit(AstCell* nodep) override {
// clonep is nullptr when inlining the last instance, if so the use original node
nodep->user4p(nodep->clonep() ? nodep->clonep() : nodep);
}
//--------------------
virtual void visit(AstNodeStmt*) override {} // Accelerate
virtual void visit(AstNodeMath*) override {} // Accelerate
virtual void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
public:
// CONSTRUCTORS
explicit InlineCollectVisitor(AstNodeModule* nodep) { // passed OLD module, not new one
iterate(nodep);
}
};
//######################################################################
// After cell is cloned, relink the new module's contents
@@ -546,7 +516,10 @@ private:
newmodp = nodep->modp();
}
// Find cell cross-references
InlineCollectVisitor{nodep->modp()};
nodep->modp()->foreach<AstCell>([](AstCell* cellp) {
// clonep is nullptr when inlining the last instance, if so the use original node
cellp->user4p(cellp->clonep() ? cellp->clonep() : cellp);
});
// Create data for dotted variable resolution
AstCellInline* const inlinep
= new AstCellInline(nodep->fileline(), nodep->name(), nodep->modp()->origName(),