Add parsing of solve-before inside foreach (#6934)

This commit is contained in:
Pawel Kojma
2026-01-20 07:14:11 -05:00
committed by GitHub
parent ea9752ab43
commit c4dcdeab9a
5 changed files with 86 additions and 6 deletions
+10 -6
View File
@@ -1309,8 +1309,9 @@ class ConstraintExprVisitor final : public VNVisitor {
// Convert to plain foreach
FileLine* const fl = nodep->fileline();
AstNode* const arrayp = nodep->arrayp()->unlinkFrBack();
if (m_wantSingle) {
if (!nodep->stmtsp()) {
nodep->unlinkFrBack();
} else if (m_wantSingle) {
AstNodeExpr* const itemp = editSingle(fl, nodep->stmtsp());
AstCStmt* const cstmtp = new AstCStmt{fl};
cstmtp->add("ret += \" \";\n");
@@ -1320,14 +1321,17 @@ class ConstraintExprVisitor final : public VNVisitor {
AstCExpr* const cexprp = new AstCExpr{fl};
cexprp->dtypeSetString();
cexprp->add("([&]{\nstd::string ret;\n");
cexprp->add(new AstBegin{fl, "", new AstForeach{fl, arrayp, cstmtp}, true});
cexprp->add(new AstBegin{
fl, "", new AstForeach{fl, nodep->arrayp()->unlinkFrBack(), cstmtp}, true});
cexprp->add("return ret.empty() ? \"#b1\" : \"(bvand\" + ret + \")\";\n})()");
nodep->replaceWith(new AstSFormatF{fl, "%@", false, cexprp});
} else {
iterateAndNextNull(nodep->stmtsp());
nodep->replaceWith(new AstBegin{
fl, "", new AstForeach{fl, arrayp, nodep->stmtsp()->unlinkFrBackWithNext()},
true});
nodep->replaceWith(
new AstBegin{fl, "",
new AstForeach{fl, nodep->arrayp()->unlinkFrBack(),
nodep->stmtsp()->unlinkFrBackWithNext()},
true});
}
VL_DO_DANGLING(nodep->deleteTree(), nodep);
}