Fix foreach on associative arr with the same logic and update the tests (#5530)

This commit is contained in:
Yilou Wang
2024-10-10 12:50:43 -04:00
committed by GitHub
parent f3cc32554c
commit 3cced9baad
3 changed files with 64 additions and 13 deletions
+7 -3
View File
@@ -427,7 +427,8 @@ AstNode* V3Begin::convertToWhile(AstForeach* nodep) {
AstNode* bodyPointp = new AstBegin{nodep->fileline(), "[EditWrapper]", nullptr};
AstNode* newp = nullptr;
AstNode* lastp = nodep;
// subfromp used to traverse each dimension of multi-d queue/dyn-arr's
// subfromp used to traverse each dimension of multi-d variable-sized unpacked array (queue,
// dyn-arr and associative-arr)
AstNodeExpr* subfromp = fromp->cloneTreePure(false);
// Major dimension first
for (AstNode *argsp = loopsp->elementsp(), *next_argsp; argsp; argsp = next_argsp) {
@@ -477,13 +478,16 @@ AstNode* V3Begin::convertToWhile(AstForeach* nodep) {
first_varp->usedLoopIdx(true);
first_varp->lifetime(VLifetime::AUTOMATIC);
AstNodeExpr* const firstp
= new AstCMethodHard{fl, fromp->cloneTreePure(false), "first",
= new AstCMethodHard{fl, subfromp->cloneTreePure(false), "first",
new AstVarRef{fl, varp, VAccess::READWRITE}};
firstp->dtypeSetSigned32();
AstNodeExpr* const nextp
= new AstCMethodHard{fl, fromp->cloneTreePure(false), "next",
= new AstCMethodHard{fl, subfromp->cloneTreePure(false), "next",
new AstVarRef{fl, varp, VAccess::READWRITE}};
nextp->dtypeSetSigned32();
AstVarRef* varRefp = new AstVarRef{fl, varp, VAccess::READ};
subfromp = new AstCMethodHard{fl, subfromp, "at", varRefp};
subfromp->dtypep(fromDtp);
AstNode* const first_clearp
= new AstAssign{fl, new AstVarRef{fl, first_varp, VAccess::WRITE},
new AstConst{fl, AstConst::BitFalse{}}};