Fix function locals in display %p

This commit is contained in:
Wilson Snyder 2026-02-26 18:12:12 -05:00
parent 2efcfa567c
commit af65a85a1e
3 changed files with 25 additions and 6 deletions

View File

@ -107,7 +107,7 @@ static void makeToStringMiddle(AstClass* nodep) {
funcp->isConst(true);
funcp->isStatic(false);
funcp->protect(false);
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;"});
AstNodeStmt* stmtsp = nullptr;
std::string comma;
for (AstNode* itemp = nodep->membersp(); itemp; itemp = itemp->nextp()) {
if (const auto* const varp = VN_CAST(itemp, Var)) {
@ -122,7 +122,7 @@ static void makeToStringMiddle(AstClass* nodep) {
stmt += V3Common::makeToStringCall(itemp->dtypep(), itemp->nameProtect());
stmt += ";";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
stmtsp = AstNode::addNextNull(stmtsp, new AstCStmt{nodep->fileline(), stmt});
}
}
}
@ -133,11 +133,18 @@ static void makeToStringMiddle(AstClass* nodep) {
stmt += EmitCUtil::prefixNameProtect(nodep->extendsp()->dtypep());
stmt += "::to_string_middle();";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
stmtsp = AstNode::addNextNull(stmtsp, new AstCStmt{nodep->fileline(), stmt});
}
AstCExpr* const exprp = new AstCExpr{nodep->fileline(), "out"};
exprp->dtypeSetString();
AstNodeExpr* exprp;
if (stmtsp) {
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;"});
funcp->addStmtsp(stmtsp);
exprp = new AstCExpr{nodep->fileline(), "out"};
exprp->dtypeSetString();
} else { // Nothing to print, return ""
exprp = new AstConst{nodep->fileline(), AstConst::String{}, ""};
}
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
nodep->addStmtsp(funcp);

View File

@ -451,6 +451,7 @@ class TaskVisitor final : public VNVisitor {
= new AstVar{invarp->fileline(), VVarType::BLOCKTEMP, name, invarp};
newvarp->funcLocal(false);
newvarp->propagateAttrFrom(invarp);
newvarp->isInternal(true);
m_modp->addStmtsp(newvarp);
AstVarScope* const newvscp = new AstVarScope{newvarp->fileline(), m_scopep, newvarp};
m_scopep->addVarsp(newvscp);

View File

@ -18,6 +18,14 @@ endclass
class Base;
int m_in_base;
virtual function string fs(input string add = "default");
static string s_f = "foo";
fs = {s_f, add};
endfunction
virtual function string other(input string add = "default");
string other = "other";
other = {other, fs(add)};
endfunction
endclass
class ClsA extends Base;
@ -54,8 +62,11 @@ module t;
c.debug();
ca = new;
$display("'%p'", ca);
if (ca.fs("-s") !== "foo-s") $stop; // So not optimized away
if (ca.other("-o") !== "otherfoo-o") $stop; // So not optimized away
cb = new;
$display("'%p'", ca);
ca.m_b = cb;
$display("'%p'", ca);
cb.m_a = ca; // Circular