Internals: Add more const. No functional change intended.

This commit is contained in:
Wilson Snyder
2021-11-13 13:50:44 -05:00
parent 4cb5c1e1db
commit 37e3c6da70
85 changed files with 1172 additions and 1115 deletions
+16 -15
View File
@@ -66,7 +66,7 @@ protected:
class SubstVarEntry final {
// MEMBERS
AstVar* m_varp; // Variable this tracks
AstVar* const m_varp; // Variable this tracks
bool m_wordAssign = false; // True if any word assignments
bool m_wordUse = false; // True if any individual word usage
SubstVarWord m_whole; // Data for whole vector used at once
@@ -127,7 +127,7 @@ public:
// ACCESSORS
AstNode* substWhole(AstNode* errp) {
if (!m_varp->isWide() && !m_whole.m_complex && m_whole.m_assignp && !m_wordAssign) {
AstNodeAssign* assp = m_whole.m_assignp;
const AstNodeAssign* const assp = m_whole.m_assignp;
UASSERT_OBJ(assp, errp, "Reading whole that was never assigned");
return (assp->rhsp());
} else {
@@ -137,7 +137,7 @@ public:
// Return what to substitute given word number for
AstNode* substWord(AstNode* errp, int word) {
if (!m_whole.m_complex && !m_whole.m_assignp && !m_words[word].m_complex) {
AstNodeAssign* assp = getWordAssignp(word);
const AstNodeAssign* const assp = getWordAssignp(word);
UASSERT_OBJ(assp, errp, "Reading a word that was never assigned, or bad word #");
return (assp->rhsp());
} else {
@@ -189,7 +189,7 @@ private:
}
// VISITORS
virtual void visit(AstVarRef* nodep) override {
SubstVarEntry* entryp = findEntryp(nodep);
const SubstVarEntry* const entryp = findEntryp(nodep);
if (entryp) {
// Don't sweat it. We assign a new temp variable for every new assignment,
// so there's no way we'd ever replace a old value.
@@ -244,12 +244,13 @@ private:
// METHODS
SubstVarEntry* getEntryp(AstVarRef* nodep) {
if (!nodep->varp()->user1p()) {
SubstVarEntry* entryp = new SubstVarEntry(nodep->varp());
SubstVarEntry* const entryp = new SubstVarEntry(nodep->varp());
m_entryps.push_back(entryp);
nodep->varp()->user1p(entryp);
return entryp;
} else {
SubstVarEntry* entryp = reinterpret_cast<SubstVarEntry*>(nodep->varp()->user1p());
SubstVarEntry* const entryp
= reinterpret_cast<SubstVarEntry*>(nodep->varp()->user1p());
return entryp;
}
}
@@ -261,9 +262,9 @@ private:
m_assignStep++;
iterateAndNextNull(nodep->rhsp());
bool hit = false;
if (AstVarRef* varrefp = VN_CAST(nodep->lhsp(), VarRef)) {
if (AstVarRef* const varrefp = VN_CAST(nodep->lhsp(), VarRef)) {
if (isSubstVar(varrefp->varp())) {
SubstVarEntry* entryp = getEntryp(varrefp);
SubstVarEntry* const entryp = getEntryp(varrefp);
hit = true;
if (m_ops > SUBST_MAX_OPS_SUBST) {
UINFO(8, " ASSIGNtooDeep " << varrefp << endl);
@@ -274,10 +275,10 @@ private:
}
}
} else if (AstWordSel* wordp = VN_CAST(nodep->lhsp(), WordSel)) {
if (AstVarRef* varrefp = VN_CAST(wordp->lhsp(), VarRef)) {
if (AstVarRef* const varrefp = VN_CAST(wordp->lhsp(), VarRef)) {
if (VN_IS(wordp->rhsp(), Const) && isSubstVar(varrefp->varp())) {
const int word = VN_AS(wordp->rhsp(), Const)->toUInt();
SubstVarEntry* entryp = getEntryp(varrefp);
SubstVarEntry* const entryp = getEntryp(varrefp);
hit = true;
if (m_ops > SUBST_MAX_OPS_SUBST) {
UINFO(8, " ASSIGNtooDeep " << varrefp << endl);
@@ -304,15 +305,15 @@ private:
}
virtual void visit(AstWordSel* nodep) override {
iterate(nodep->rhsp());
AstVarRef* varrefp = VN_CAST(nodep->lhsp(), VarRef);
AstConst* constp = VN_CAST(nodep->rhsp(), Const);
AstVarRef* const varrefp = VN_CAST(nodep->lhsp(), VarRef);
const AstConst* const constp = VN_CAST(nodep->rhsp(), Const);
if (varrefp && isSubstVar(varrefp->varp()) && varrefp->access().isReadOnly() && constp) {
// Nicely formed lvalues handled in NodeAssign
// Other lvalues handled as unknown mess in AstVarRef
const int word = constp->toUInt();
UINFO(8, " USEword" << word << " " << varrefp << endl);
SubstVarEntry* entryp = getEntryp(varrefp);
if (AstNode* substp = entryp->substWord(nodep, word)) {
SubstVarEntry* const entryp = getEntryp(varrefp);
if (AstNode* const substp = entryp->substWord(nodep, word)) {
// Check that the RHS hasn't changed value since we recorded it.
SubstUseVisitor visitor{substp, entryp->getWordStep(word)};
if (visitor.ok()) {
@@ -335,7 +336,7 @@ private:
UINFO(9, " ASSIGNstep u2=" << nodep->varp()->user2() << " " << nodep << endl);
}
if (isSubstVar(nodep->varp())) {
SubstVarEntry* entryp = getEntryp(nodep);
SubstVarEntry* const entryp = getEntryp(nodep);
if (nodep->access().isWriteOrRW()) {
UINFO(8, " ASSIGNcpx " << nodep << endl);
entryp->assignComplex();