Internals: Refactor symIterate functions. No functional change intended

This commit is contained in:
Wilson Snyder 2024-11-30 22:55:16 -05:00
parent 2d71d66cf5
commit 7a04a5b9a8

View File

@ -2448,17 +2448,32 @@ class LinkDotResolveVisitor final : public VNVisitor {
// A class reference might be to a class that is later in Ast due to // A class reference might be to a class that is later in Ast due to
// e.g. parmaeterization or referring to a "class (type T) extends T" // e.g. parmaeterization or referring to a "class (type T) extends T"
// Resolve it so later Class:: references into its base classes work // Resolve it so later Class:: references into its base classes work
VL_RESTORER(m_ds); symIterateNull(nodep, m_statep->getNodeSym(nodep));
VSymEnt* const srcp = m_statep->getNodeSym(nodep);
m_ds.init(srcp);
iterate(nodep);
} }
void updateVarUse(AstVar* nodep) { void updateVarUse(AstVar* nodep) {
// Avoid dotted.PARAM false positive when in a parameter block // Avoid dotted.PARAM false positive when in a parameter block
// that is if ()'ed off by same dotted name as another block // that is if ()'ed off by same dotted name as another block
if (nodep && nodep->isParam()) nodep->usedParam(true); if (nodep && nodep->isParam()) nodep->usedParam(true);
} }
void symIterateChildren(AstNode* nodep, VSymEnt* symp) {
// Iterate children, changing to given context, with restore to old context
VL_RESTORER(m_ds);
VL_RESTORER(m_curSymp);
m_curSymp = symp;
m_ds.init(m_curSymp);
iterateChildren(nodep);
}
void symIterateNull(AstNode* nodep, VSymEnt* symp) {
// Iterate node, changing to given context, with restore to old context
VL_RESTORER(m_ds);
VL_RESTORER(m_curSymp);
m_curSymp = symp;
m_ds.init(m_curSymp);
iterateNull(nodep);
}
#define LINKDOT_VISIT_START() \ #define LINKDOT_VISIT_START() \
VL_RESTORER(m_indent); \ VL_RESTORER(m_indent); \
++m_indent; ++m_indent;
@ -2494,14 +2509,12 @@ class LinkDotResolveVisitor final : public VNVisitor {
void visit(AstScope* nodep) override { void visit(AstScope* nodep) override {
LINKDOT_VISIT_START(); LINKDOT_VISIT_START();
UINFO(8, indent() << "visit " << nodep << endl); UINFO(8, indent() << "visit " << nodep << endl);
checkNoDot(nodep);
VL_RESTORER(m_modSymp); VL_RESTORER(m_modSymp);
VL_RESTORER(m_curSymp); VL_RESTORER(m_curSymp);
{ m_ds.m_dotSymp = m_curSymp = m_modSymp = m_statep->getScopeSym(nodep);
checkNoDot(nodep); iterateChildren(nodep);
m_ds.m_dotSymp = m_curSymp = m_modSymp = m_statep->getScopeSym(nodep); m_ds.m_dotSymp = m_curSymp = m_modSymp = nullptr;
iterateChildren(nodep);
m_ds.m_dotSymp = m_curSymp = m_modSymp = nullptr;
}
} }
void visit(AstCellInline* nodep) override { void visit(AstCellInline* nodep) override {
LINKDOT_VISIT_START(); LINKDOT_VISIT_START();
@ -2670,6 +2683,8 @@ class LinkDotResolveVisitor final : public VNVisitor {
} else { } else {
if (m_statep->forPrimary() if (m_statep->forPrimary()
&& m_extendsParam.find(classp) != m_extendsParam.end()) { && m_extendsParam.find(classp) != m_extendsParam.end()) {
UINFO(9, indent() << "deferring until post-V3Param: " << nodep->lhsp()
<< endl);
m_ds.m_unresolvedClass = true; m_ds.m_unresolvedClass = true;
} else { } else {
const auto baseClassp = cextp->classp(); const auto baseClassp = cextp->classp();
@ -2696,6 +2711,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
} }
if (m_statep->forPrimary() && isParamedClassRef(nodep->lhsp())) { if (m_statep->forPrimary() && isParamedClassRef(nodep->lhsp())) {
// Dots of paramed classes will be linked after deparameterization // Dots of paramed classes will be linked after deparameterization
UINFO(9, indent() << "deferring until post-V3Param: " << nodep->lhsp() << endl);
m_ds.m_unresolvedClass = true; m_ds.m_unresolvedClass = true;
} }
if (m_ds.m_unresolvedCell if (m_ds.m_unresolvedCell
@ -3024,6 +3040,8 @@ class LinkDotResolveVisitor final : public VNVisitor {
refp->dotted(dotted.substr(0, pos)); refp->dotted(dotted.substr(0, pos));
newp = refp; newp = refp;
} else { } else {
UINFO(9, indent()
<< "deferring until post-V3Param: " << refp << endl);
newp = new AstUnlinkedRef{nodep->fileline(), refp, refp->name(), newp = new AstUnlinkedRef{nodep->fileline(), refp, refp->name(),
m_ds.m_unlinkedScopep->unlinkFrBack()}; m_ds.m_unlinkedScopep->unlinkFrBack()};
m_ds.m_unlinkedScopep = nullptr; m_ds.m_unlinkedScopep = nullptr;
@ -3475,9 +3493,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
if (m_ds.m_dotPos != DP_MEMBER || nodep->name() != "randomize") { if (m_ds.m_dotPos != DP_MEMBER || nodep->name() != "randomize") {
// Visit arguments at the beginning. // Visit arguments at the beginning.
// They may be visitted even if the current node can't be linked now. // They may be visitted even if the current node can't be linked now.
VL_RESTORER(m_ds); symIterateChildren(nodep, m_curSymp);
m_ds.init(m_curSymp);
iterateChildren(nodep);
} }
if (m_ds.m_super) { if (m_ds.m_super) {
@ -3732,16 +3748,10 @@ class LinkDotResolveVisitor final : public VNVisitor {
m_ds.m_unresolvedCell = true; m_ds.m_unresolvedCell = true;
// And pass up m_ds.m_dotText // And pass up m_ds.m_dotText
} }
// Pass dot state down to fromp() // Pass dot state down to only fromp()
iterateAndNextNull(nodep->fromp()); iterateAndNextNull(nodep->fromp());
{ symIterateNull(nodep->bitp(), m_curSymp);
VL_RESTORER(m_ds); symIterateNull(nodep->attrp(), m_curSymp);
{
m_ds.init(m_curSymp);
iterateAndNextNull(nodep->bitp());
iterateAndNextNull(nodep->attrp());
}
}
if (m_ds.m_unresolvedCell && (m_ds.m_dotPos == DP_SCOPE || m_ds.m_dotPos == DP_FIRST)) { if (m_ds.m_unresolvedCell && (m_ds.m_dotPos == DP_SCOPE || m_ds.m_dotPos == DP_FIRST)) {
AstNodeExpr* const exprp = nodep->bitp()->unlinkFrBack(); AstNodeExpr* const exprp = nodep->bitp()->unlinkFrBack();
AstCellArrayRef* const newp AstCellArrayRef* const newp
@ -3763,12 +3773,8 @@ class LinkDotResolveVisitor final : public VNVisitor {
return; return;
} }
iterateAndNextNull(nodep->fromp()); iterateAndNextNull(nodep->fromp());
VL_RESTORER(m_ds); symIterateNull(nodep->rhsp(), m_curSymp);
{ symIterateNull(nodep->thsp(), m_curSymp);
m_ds.init(m_curSymp);
iterateAndNextNull(nodep->rhsp());
iterateAndNextNull(nodep->thsp());
}
if (nodep->attrp()) { if (nodep->attrp()) {
AstNode* const attrp = nodep->attrp()->unlinkFrBack(); AstNode* const attrp = nodep->attrp()->unlinkFrBack();
@ -3792,15 +3798,15 @@ class LinkDotResolveVisitor final : public VNVisitor {
LINKDOT_VISIT_START(); LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl); UINFO(5, indent() << "visit " << nodep << endl);
checkNoDot(nodep); checkNoDot(nodep);
VL_RESTORER(m_curSymp);
{ {
VL_RESTORER(m_curSymp);
VL_RESTORER(m_ds);
if (nodep->name() != "") { if (nodep->name() != "") {
m_ds.m_dotSymp = m_curSymp = m_statep->getNodeSym(nodep); m_ds.m_dotSymp = m_curSymp = m_statep->getNodeSym(nodep);
UINFO(5, indent() << "cur=se" << cvtToHex(m_curSymp) << endl); UINFO(5, indent() << "cur=se" << cvtToHex(m_curSymp) << endl);
} }
iterateChildren(nodep); iterateChildren(nodep);
} }
m_ds.m_dotSymp = VL_RESTORER_PREV(m_curSymp);
UINFO(5, indent() << "cur=se" << cvtToHex(m_curSymp) << endl); UINFO(5, indent() << "cur=se" << cvtToHex(m_curSymp) << endl);
} }
void visit(AstNodeFTask* nodep) override { void visit(AstNodeFTask* nodep) override {
@ -3849,25 +3855,15 @@ class LinkDotResolveVisitor final : public VNVisitor {
LINKDOT_VISIT_START(); LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl); UINFO(5, indent() << "visit " << nodep << endl);
checkNoDot(nodep); checkNoDot(nodep);
VL_RESTORER(m_curSymp); symIterateChildren(nodep, m_statep->getNodeSym(nodep));
{
m_ds.m_dotSymp = m_curSymp = m_statep->getNodeSym(nodep);
iterateChildren(nodep);
}
m_ds.m_dotSymp = VL_RESTORER_PREV(m_curSymp);
} }
void visit(AstWith* nodep) override { void visit(AstWith* nodep) override {
LINKDOT_VISIT_START(); LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl); UINFO(5, indent() << "visit " << nodep << endl);
checkNoDot(nodep); checkNoDot(nodep);
VL_RESTORER(m_curSymp);
VL_RESTORER(m_inWith); VL_RESTORER(m_inWith);
{ m_inWith = true;
m_ds.m_dotSymp = m_curSymp = m_statep->getNodeSym(nodep); symIterateChildren(nodep, m_statep->getNodeSym(nodep));
m_inWith = true;
iterateChildren(nodep);
}
m_ds.m_dotSymp = VL_RESTORER_PREV(m_curSymp);
} }
void visit(AstLambdaArgRef* nodep) override { void visit(AstLambdaArgRef* nodep) override {
LINKDOT_VISIT_START(); LINKDOT_VISIT_START();