Strengthen AstNode types to AstNodeExpr

Declare every AstNode children and variables as AstNodeExpr where we
statically know this is the appropriate sub-type.
This commit is contained in:
Geza Lore
2022-11-20 19:31:28 +00:00
parent 352d0b4582
commit 3abb65d732
52 changed files with 1742 additions and 1572 deletions
+6 -6
View File
@@ -119,7 +119,7 @@ public:
m_wordUse = true;
}
// ACCESSORS
AstNode* substWhole(AstNode* errp) {
AstNodeExpr* substWhole(AstNode* errp) {
if (!m_varp->isWide() && !m_whole.m_complex && m_whole.m_assignp && !m_wordAssign) {
const AstNodeAssign* const assp = m_whole.m_assignp;
UASSERT_OBJ(assp, errp, "Reading whole that was never assigned");
@@ -129,7 +129,7 @@ public:
}
}
// Return what to substitute given word number for
AstNode* substWord(AstNode* errp, int word) {
AstNodeExpr* substWord(AstNode* errp, int word) {
if (!m_whole.m_complex && !m_whole.m_assignp && !m_words[word].m_complex) {
const AstNodeAssign* const assp = getWordAssignp(word);
UASSERT_OBJ(assp, errp, "Reading a word that was never assigned, or bad word #");
@@ -287,9 +287,9 @@ private:
}
if (!hit) iterate(nodep->lhsp());
}
void replaceSubstEtc(AstNode* nodep, AstNode* substp) {
void replaceSubstEtc(AstNode* nodep, AstNodeExpr* substp) {
if (debug() > 5) nodep->dumpTree(cout, " substw_old: ");
AstNode* newp = substp->cloneTree(true);
AstNodeExpr* newp = substp->cloneTree(true);
if (!nodep->isQuad() && newp->isQuad()) {
newp = new AstCCast{newp->fileline(), newp, nodep};
}
@@ -308,7 +308,7 @@ private:
const int word = constp->toUInt();
UINFO(8, " USEword" << word << " " << varrefp << endl);
SubstVarEntry* const entryp = getEntryp(varrefp);
if (AstNode* const substp = entryp->substWord(nodep, word)) {
if (AstNodeExpr* const substp = entryp->substWord(nodep, word)) {
// Check that the RHS hasn't changed value since we recorded it.
const SubstUseVisitor visitor{substp, entryp->getWordStep(word)};
if (visitor.ok()) {
@@ -335,7 +335,7 @@ private:
if (nodep->access().isWriteOrRW()) {
UINFO(8, " ASSIGNcpx " << nodep << endl);
entryp->assignComplex();
} else if (AstNode* const substp = entryp->substWhole(nodep)) {
} else if (AstNodeExpr* const substp = entryp->substWhole(nodep)) {
// Check that the RHS hasn't changed value since we recorded it.
const SubstUseVisitor visitor{substp, entryp->getWholeStep()};
if (visitor.ok()) {