Fix foreach and pre/post increment in functions (#3613).

This commit is contained in:
Wilson Snyder
2022-10-18 20:04:09 -04:00
parent 2723223884
commit b930d0731a
5 changed files with 23 additions and 3 deletions
+7
View File
@@ -60,6 +60,7 @@ private:
};
// STATE
AstNodeFTask* m_ftaskp = nullptr; // Function or task we're inside
int m_modIncrementsNum = 0; // Var name counter
InsertMode m_insMode = IM_BEFORE; // How to insert
AstNode* m_insStmtp = nullptr; // Where to insert statement
@@ -94,6 +95,11 @@ private:
m_modIncrementsNum = 0;
iterateChildren(nodep);
}
void visit(AstNodeFTask* nodep) override {
VL_RESTORER(m_ftaskp);
m_ftaskp = nodep;
iterateChildren(nodep);
}
void visit(AstWhile* nodep) override {
// Special, as statements need to be put in different places
// Preconditions insert first just before themselves (the normal
@@ -241,6 +247,7 @@ private:
const string name = string("__Vincrement") + cvtToStr(++m_modIncrementsNum);
AstVar* const varp = new AstVar(fl, VVarType::BLOCKTEMP, name, VFlagChildDType(),
varrefp->varp()->subDTypep()->cloneTree(true));
if (m_ftaskp) varp->funcLocal(true);
// Declare the variable
insertBeforeStmt(nodep, varp);