forked from github/verilator
Resolve RefDTypes safely
This commit is contained in:
parent
a105fdf731
commit
bfe2760098
14
src/V3Ast.h
14
src/V3Ast.h
@ -2094,7 +2094,15 @@ public:
|
||||
uint32_t arrayUnpackedElements(); // 1, or total multiplication of all dimensions
|
||||
static int uniqueNumInc() { return ++s_uniqueNum; }
|
||||
const char* charIQWN() const { return (isString() ? "N" : isWide() ? "W" : isQuad() ? "Q" : "I"); }
|
||||
virtual bool matching(const AstNodeDType* typep) const = 0;
|
||||
bool matching(const AstNodeDType* typep) const {
|
||||
if (VN_IS(typep, RefDType)) {
|
||||
// Follow RefDTypes
|
||||
return typep->match(this);
|
||||
} else {
|
||||
return match(typep);
|
||||
}
|
||||
}
|
||||
virtual bool match(const AstNodeDType* typep) const = 0;
|
||||
};
|
||||
|
||||
class AstNodeUOrStructDType : public AstNodeDType {
|
||||
@ -2149,7 +2157,7 @@ public:
|
||||
int lsb() const { return 0; }
|
||||
int msb() const { return dtypep()->width()-1; } // Packed classes look like arrays
|
||||
VNumRange declRange() const { return VNumRange(msb(), lsb(), false); }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return typep == this; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return typep == this; }
|
||||
};
|
||||
|
||||
class AstNodeArrayDType : public AstNodeDType {
|
||||
@ -2208,7 +2216,7 @@ public:
|
||||
int elementsConst() const;
|
||||
VNumRange declRange() const;
|
||||
virtual bool matchingArrayType(const AstNodeArrayDType* matchp) const = 0;
|
||||
virtual bool matching(const AstNodeDType* typep) const {
|
||||
virtual bool match(const AstNodeDType* typep) const {
|
||||
const AstNodeArrayDType* arrayp = VN_CAST_CONST(typep, NodeArrayDType);
|
||||
if (!arrayp) return typep->matching(this);
|
||||
return arrayp && matchingArrayType(arrayp) && declRange() == arrayp->declRange()
|
||||
|
@ -305,7 +305,7 @@ public:
|
||||
AstVarType varType() const { return m_varType; } // * = Type of variable
|
||||
bool isParam() const { return true; }
|
||||
bool isGParam() const { return (varType()==AstVarType::GPARAM); }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return childDTypep()->matching(typep); }
|
||||
virtual bool match(const AstNodeDType* typep) const { return childDTypep()->matching(typep); }
|
||||
};
|
||||
|
||||
class AstTypedef : public AstNode {
|
||||
@ -390,7 +390,7 @@ public:
|
||||
virtual int widthTotalBytes() const { return dtypep()->widthTotalBytes(); }
|
||||
virtual string name() const { return m_name; }
|
||||
void name(const string& flag) { m_name = flag; }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return typep == this; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return typep == this; }
|
||||
};
|
||||
|
||||
class AstAssocArrayDType : public AstNodeDType {
|
||||
@ -451,9 +451,8 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
|
||||
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
|
||||
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const {
|
||||
virtual bool match(const AstNodeDType* typep) const {
|
||||
const AstAssocArrayDType* arrayp = VN_CAST_CONST(typep, AssocArrayDType);
|
||||
if (!arrayp) return typep->matching(this);
|
||||
return arrayp && subDTypep()->matching(arrayp->subDTypep())
|
||||
&& keyDTypep()->matching(arrayp->keyDTypep());
|
||||
}
|
||||
@ -507,9 +506,8 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
|
||||
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
|
||||
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const {
|
||||
virtual bool match(const AstNodeDType* typep) const {
|
||||
const AstDynArrayDType* arrayp = VN_CAST_CONST(typep, DynArrayDType);
|
||||
if (!arrayp) return typep->matching(this);
|
||||
return arrayp && subDTypep()->matching(arrayp->subDTypep());
|
||||
}
|
||||
};
|
||||
@ -615,9 +613,8 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
|
||||
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
|
||||
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const {
|
||||
virtual bool match(const AstNodeDType* typep) const {
|
||||
const AstUnsizedArrayDType* arrayp = VN_CAST_CONST(typep, UnsizedArrayDType);
|
||||
if (!arrayp) return typep->matching(this);
|
||||
return arrayp && subDTypep()->matching(arrayp->subDTypep());
|
||||
}
|
||||
};
|
||||
@ -697,10 +694,9 @@ 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; }
|
||||
virtual bool matching(const AstNodeDType* typep) const {
|
||||
virtual bool match(const AstNodeDType* typep) const {
|
||||
const AstBasicDType* matchp = VN_CAST_CONST(typep, BasicDType);
|
||||
if (!matchp) return typep->matching(this);
|
||||
return isSigned() == matchp->isSigned()
|
||||
return matchp && isSigned() == matchp->isSigned()
|
||||
&& (same(matchp) ||
|
||||
(isIntNumeric() && matchp->isIntNumeric()
|
||||
&& isFourstate() == matchp->isFourstate()
|
||||
@ -793,7 +789,7 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return subDTypep()->skipRefToEnump(); }
|
||||
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
|
||||
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return subDTypep()->matching(typep); }
|
||||
virtual bool match(const AstNodeDType* typep) const { return subDTypep()->matching(typep); }
|
||||
};
|
||||
|
||||
class AstClassRefDType : public AstNodeDType {
|
||||
@ -833,7 +829,7 @@ public:
|
||||
void packagep(AstPackage* nodep) { m_packagep = nodep; }
|
||||
AstClass* classp() const { return m_classp; }
|
||||
void classp(AstClass* nodep) { m_classp = nodep; }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return typep == this; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return typep == this; }
|
||||
};
|
||||
|
||||
class AstIfaceRefDType : public AstNodeDType {
|
||||
@ -887,7 +883,7 @@ public:
|
||||
void modportp(AstModport* modportp) { m_modportp = modportp; }
|
||||
bool isModport() { return !m_modportName.empty(); }
|
||||
// Cannot take type() of interface
|
||||
virtual bool matching(const AstNodeDType* typep) const { return false; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return false; }
|
||||
};
|
||||
|
||||
class AstQueueDType : public AstNodeDType {
|
||||
@ -937,9 +933,8 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
|
||||
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
|
||||
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const {
|
||||
virtual bool match(const AstNodeDType* typep) const {
|
||||
const AstQueueDType* queuep = VN_CAST_CONST(typep, QueueDType);
|
||||
if (!queuep) return typep->matching(this);
|
||||
return queuep && subDTypep()->matching(typep);
|
||||
}
|
||||
};
|
||||
@ -1007,7 +1002,7 @@ public:
|
||||
AstPackage* packagep() const { return m_packagep; }
|
||||
void packagep(AstPackage* nodep) { m_packagep = nodep; }
|
||||
AstNode* typeofp() const { return op2p(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return refDTypep()->matching(typep); }
|
||||
virtual bool match(const AstNodeDType* typep) const { return refDTypep()->matching(typep); }
|
||||
};
|
||||
|
||||
class AstStructDType : public AstNodeUOrStructDType {
|
||||
@ -1085,7 +1080,7 @@ public:
|
||||
virtual string tag() const { return m_tag; }
|
||||
int lsb() const { return m_lsb; }
|
||||
void lsb(int lsb) { m_lsb = lsb; }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return subDTypep()->matching(typep); }
|
||||
virtual bool match(const AstNodeDType* typep) const { return subDTypep()->matching(typep); }
|
||||
};
|
||||
|
||||
class AstVoidDType : public AstNodeDType {
|
||||
@ -1108,7 +1103,7 @@ public:
|
||||
virtual int widthAlignBytes() const { return 1; }
|
||||
virtual int widthTotalBytes() const { return 1; }
|
||||
virtual V3Hash sameHash() const { return V3Hash(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return false; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return false; }
|
||||
};
|
||||
|
||||
class AstEnumItem : public AstNode {
|
||||
@ -1202,7 +1197,7 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
|
||||
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
|
||||
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return typep == this; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return typep == this; }
|
||||
};
|
||||
|
||||
class AstParseTypeDType : public AstNodeDType {
|
||||
@ -1222,7 +1217,7 @@ public:
|
||||
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
|
||||
virtual int widthAlignBytes() const { return 0; }
|
||||
virtual int widthTotalBytes() const { return 0; }
|
||||
virtual bool matching(const AstNodeDType* typep) const { return false; }
|
||||
virtual bool match(const AstNodeDType* typep) const { return false; }
|
||||
};
|
||||
|
||||
//######################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user