Move matching check into AstBasicDType

This commit is contained in:
Todd Strader 2020-03-27 16:00:59 -04:00
parent 6dd4ff021f
commit d3ac16d6d9
2 changed files with 15 additions and 13 deletions

View File

@ -673,6 +673,16 @@ public:
virtual bool same(const AstNode* samep) const { // width/widthMin/numeric compared elsewhere
const AstBasicDType* sp = static_cast<const AstBasicDType*>(samep);
return m == sp->m; }
bool matching(const AstBasicDType* matchp) {
if (isSigned() == matchp->isSigned()
&& (same(matchp) ||
(isIntNumeric() && matchp->isIntNumeric()
&& isFourstate() == matchp->isFourstate()
&& nrange() == matchp->nrange()))) {
return true;
}
return false;
}
virtual bool similarDType(AstNodeDType* samep) const {
return type()==samep->type() && same(samep); }
virtual string name() const { return m.m_keyword.ascii(); }
@ -700,6 +710,7 @@ public:
bool isString() const { return keyword().isString(); }
bool isSloppy() const { return keyword().isSloppy(); }
bool isZeroInit() const { return keyword().isZeroInit(); }
bool isIntNumeric() const { return keyword().isIntNumeric(); }
bool isRanged() const { return rangep() || m.m_nrange.ranged(); }
const VNumRange& nrange() const { return m.m_nrange; } // Generally the msb/lsb/etc funcs should be used instead
int msb() const { return (rangep() ? rangep()->msbConst() : m.m_nrange.hi()); }

View File

@ -3592,19 +3592,10 @@ private:
if (refLhsp && refRhsp) {
AstNodeDType* typeLhsp = refLhsp->refDTypep();
AstNodeDType* typeRhsp = refRhsp->refDTypep();
if (AstBasicDType* basicLhsp = VN_CAST(typeLhsp, BasicDType)) {
AstBasicDType* basicRhsp = VN_CAST(typeRhsp, BasicDType);
// QUESTION -- AstBasicDType::same() doesn't check signedness . . . should it?
if (basicRhsp && basicLhsp->isSigned() == basicRhsp->isSigned()) {
AstBasicDTypeKwd kwdLhs = basicLhsp->keyword();
AstBasicDTypeKwd kwdRhs = basicRhsp->keyword();
if (basicLhsp->same(typeRhsp) ||
(kwdLhs.isIntNumeric() && kwdRhs.isIntNumeric()
&& kwdLhs.isFourstate() == kwdRhs.isFourstate()
&& basicLhsp->nrange() == basicRhsp->nrange())) {
equal = true;
}
}
AstBasicDType* basicLhsp = VN_CAST(typeLhsp, BasicDType);
AstBasicDType* basicRhsp = VN_CAST(typeRhsp, BasicDType);
if (basicLhsp && basicRhsp && basicLhsp->matching(basicRhsp)) {
equal = true;
} else if (refLhsp->dtypep() == refRhsp->dtypep()) {
equal = true;
}