Internals: AstRefDType points to AstTypedef instead of sub-dtype, in prep for future commits.
This commit is contained in:
parent
613d76c578
commit
f7249ad23a
|
|
@ -1215,12 +1215,16 @@ void AstRange::dump(std::ostream& str) const {
|
||||||
}
|
}
|
||||||
void AstRefDType::dump(std::ostream& str) const {
|
void AstRefDType::dump(std::ostream& str) const {
|
||||||
this->AstNodeDType::dump(str);
|
this->AstNodeDType::dump(str);
|
||||||
if (defp()) {
|
if (typedefp() || subDTypep()) {
|
||||||
static bool s_recursing = false;
|
static bool s_recursing = false;
|
||||||
if (!s_recursing) { // Prevent infinite dump if circular typedefs
|
if (!s_recursing) { // Prevent infinite dump if circular typedefs
|
||||||
s_recursing = true;
|
s_recursing = true;
|
||||||
str << " -> ";
|
str << " -> ";
|
||||||
defp()->dump(str);
|
if (typedefp()) {
|
||||||
|
typedefp()->dump(str);
|
||||||
|
} else if (subDTypep()) {
|
||||||
|
subDTypep()->dump(str);
|
||||||
|
}
|
||||||
s_recursing = false;
|
s_recursing = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1094,25 +1094,24 @@ public:
|
||||||
|
|
||||||
class AstRefDType : public AstNodeDType {
|
class AstRefDType : public AstNodeDType {
|
||||||
private:
|
private:
|
||||||
|
// Pre-Width must reference the Typeref, not what it points to, as some child
|
||||||
|
// types like AstBracketArrayType will disappear and can't lose the handle
|
||||||
|
AstTypedef* m_typedefp; // referenced type
|
||||||
|
// Post-width typedefs are removed and point to type directly
|
||||||
AstNodeDType* m_refDTypep; // data type pointed to, BELOW the AstTypedef
|
AstNodeDType* m_refDTypep; // data type pointed to, BELOW the AstTypedef
|
||||||
string m_name; // Name of an AstTypedef
|
string m_name; // Name of an AstTypedef
|
||||||
AstNodeModule* m_packagep; // Package hierarchy
|
AstNodeModule* m_packagep; // Package hierarchy
|
||||||
public:
|
public:
|
||||||
AstRefDType(FileLine* fl, const string& name)
|
AstRefDType(FileLine* fl, const string& name)
|
||||||
: ASTGEN_SUPER(fl)
|
: ASTGEN_SUPER(fl)
|
||||||
|
, m_typedefp(NULL)
|
||||||
, m_refDTypep(NULL)
|
, m_refDTypep(NULL)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_packagep(NULL) {}
|
, m_packagep(NULL) {}
|
||||||
AstRefDType(FileLine* fl, AstNodeDType* defp)
|
|
||||||
: ASTGEN_SUPER(fl)
|
|
||||||
, m_refDTypep(defp)
|
|
||||||
, m_packagep(NULL) {
|
|
||||||
dtypeFrom(defp->dtypep());
|
|
||||||
widthFromSub(subDTypep());
|
|
||||||
}
|
|
||||||
class FlagTypeOfExpr {}; // type(expr) for parser only
|
class FlagTypeOfExpr {}; // type(expr) for parser only
|
||||||
AstRefDType(FileLine* fl, FlagTypeOfExpr, AstNode* typeofp)
|
AstRefDType(FileLine* fl, FlagTypeOfExpr, AstNode* typeofp)
|
||||||
: ASTGEN_SUPER(fl)
|
: ASTGEN_SUPER(fl)
|
||||||
|
, m_typedefp(NULL)
|
||||||
, m_refDTypep(NULL)
|
, m_refDTypep(NULL)
|
||||||
, m_packagep(NULL) {
|
, m_packagep(NULL) {
|
||||||
setOp2p(typeofp);
|
setOp2p(typeofp);
|
||||||
|
|
@ -1120,47 +1119,53 @@ public:
|
||||||
ASTNODE_NODE_FUNCS(RefDType)
|
ASTNODE_NODE_FUNCS(RefDType)
|
||||||
// METHODS
|
// METHODS
|
||||||
virtual const char* broken() const {
|
virtual const char* broken() const {
|
||||||
|
BROKEN_RTN(m_typedefp && !m_typedefp->brokeExists());
|
||||||
BROKEN_RTN(m_refDTypep && !m_refDTypep->brokeExists());
|
BROKEN_RTN(m_refDTypep && !m_refDTypep->brokeExists());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
virtual void cloneRelink() {
|
virtual void cloneRelink() {
|
||||||
|
if (m_typedefp && m_typedefp->clonep()) { m_typedefp = m_typedefp->clonep(); }
|
||||||
if (m_refDTypep && m_refDTypep->clonep()) { m_refDTypep = m_refDTypep->clonep(); }
|
if (m_refDTypep && m_refDTypep->clonep()) { m_refDTypep = m_refDTypep->clonep(); }
|
||||||
}
|
}
|
||||||
virtual bool same(const AstNode* samep) const {
|
virtual bool same(const AstNode* samep) const {
|
||||||
const AstRefDType* asamep = static_cast<const AstRefDType*>(samep);
|
const AstRefDType* asamep = static_cast<const AstRefDType*>(samep);
|
||||||
return (m_refDTypep == asamep->m_refDTypep && m_name == asamep->m_name
|
return (m_typedefp == asamep->m_typedefp && m_refDTypep == asamep->m_refDTypep
|
||||||
&& m_packagep == asamep->m_packagep);
|
&& m_name == asamep->m_name && m_packagep == asamep->m_packagep);
|
||||||
}
|
}
|
||||||
virtual bool similarDType(AstNodeDType* samep) const {
|
virtual bool similarDType(AstNodeDType* samep) const {
|
||||||
return skipRefp()->similarDType(samep->skipRefp());
|
return skipRefp()->similarDType(samep->skipRefp());
|
||||||
}
|
}
|
||||||
virtual V3Hash sameHash() const { return V3Hash(V3Hash(m_refDTypep), V3Hash(m_packagep)); }
|
virtual V3Hash sameHash() const { return V3Hash(V3Hash(m_typedefp), V3Hash(m_packagep)); }
|
||||||
virtual void dump(std::ostream& str = std::cout) const;
|
virtual void dump(std::ostream& str = std::cout) const;
|
||||||
virtual string name() const { return m_name; }
|
virtual string name() const { return m_name; }
|
||||||
virtual string prettyDTypeName() const {
|
virtual string prettyDTypeName() const {
|
||||||
return subDTypep() ? subDTypep()->name() : prettyName();
|
return subDTypep() ? subDTypep()->name() : prettyName();
|
||||||
}
|
}
|
||||||
virtual AstBasicDType* basicp() const { return subDTypep() ? subDTypep()->basicp() : NULL; }
|
virtual AstBasicDType* basicp() const { return subDTypep() ? subDTypep()->basicp() : NULL; }
|
||||||
|
AstNodeDType* subDTypep() const {
|
||||||
|
if (typedefp()) return typedefp()->subDTypep();
|
||||||
|
return refDTypep(); // Maybe NULL
|
||||||
|
}
|
||||||
virtual AstNodeDType* skipRefp() const {
|
virtual AstNodeDType* skipRefp() const {
|
||||||
// Skip past both the Ref and the Typedef
|
// Skip past both the Ref and the Typedef
|
||||||
if (defp()) {
|
if (subDTypep()) {
|
||||||
return defp()->skipRefp();
|
return subDTypep()->skipRefp();
|
||||||
} else {
|
} else {
|
||||||
v3fatalSrc("Typedef not linked");
|
v3fatalSrc("Typedef not linked");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual AstNodeDType* skipRefToConstp() const {
|
virtual AstNodeDType* skipRefToConstp() const {
|
||||||
if (defp()) {
|
if (subDTypep()) {
|
||||||
return defp()->skipRefToConstp();
|
return subDTypep()->skipRefToConstp();
|
||||||
} else {
|
} else {
|
||||||
v3fatalSrc("Typedef not linked");
|
v3fatalSrc("Typedef not linked");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual AstNodeDType* skipRefToEnump() const {
|
virtual AstNodeDType* skipRefToEnump() const {
|
||||||
if (defp()) {
|
if (subDTypep()) {
|
||||||
return defp()->skipRefToEnump();
|
return subDTypep()->skipRefToEnump();
|
||||||
} else {
|
} else {
|
||||||
v3fatalSrc("Typedef not linked");
|
v3fatalSrc("Typedef not linked");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1170,15 +1175,13 @@ public:
|
||||||
virtual int widthTotalBytes() const { return dtypeSkipRefp()->widthTotalBytes(); }
|
virtual int widthTotalBytes() const { return dtypeSkipRefp()->widthTotalBytes(); }
|
||||||
void name(const string& flag) { m_name = flag; }
|
void name(const string& flag) { m_name = flag; }
|
||||||
// op1 = Range of variable
|
// op1 = Range of variable
|
||||||
AstNodeDType* dtypeSkipRefp() const { return defp()->skipRefp(); }
|
AstNodeDType* dtypeSkipRefp() const { return subDTypep()->skipRefp(); }
|
||||||
AstNodeDType* defp() const {
|
AstTypedef* typedefp() const { return m_typedefp; }
|
||||||
return m_refDTypep;
|
void typedefp(AstTypedef* nodep) { m_typedefp = nodep; }
|
||||||
} // Code backward compatibility name for refDTypep
|
|
||||||
AstNodeDType* refDTypep() const { return m_refDTypep; }
|
AstNodeDType* refDTypep() const { return m_refDTypep; }
|
||||||
void refDTypep(AstNodeDType* nodep) { m_refDTypep = nodep; }
|
void refDTypep(AstNodeDType* nodep) { m_refDTypep = nodep; }
|
||||||
virtual AstNodeDType* virtRefDTypep() const { return refDTypep(); }
|
virtual AstNodeDType* virtRefDTypep() const { return refDTypep(); }
|
||||||
virtual void virtRefDTypep(AstNodeDType* nodep) { refDTypep(nodep); }
|
virtual void virtRefDTypep(AstNodeDType* nodep) { refDTypep(nodep); }
|
||||||
virtual AstNodeDType* subDTypep() const { return m_refDTypep; }
|
|
||||||
AstNodeModule* packagep() const { return m_packagep; }
|
AstNodeModule* packagep() const { return m_packagep; }
|
||||||
void packagep(AstNodeModule* nodep) { m_packagep = nodep; }
|
void packagep(AstNodeModule* nodep) { m_packagep = nodep; }
|
||||||
AstNode* typeofp() const { return op2p(); }
|
AstNode* typeofp() const { return op2p(); }
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,8 @@ private:
|
||||||
iterateChildren(nodep);
|
iterateChildren(nodep);
|
||||||
checkDType(nodep);
|
checkDType(nodep);
|
||||||
checkAll(nodep);
|
checkAll(nodep);
|
||||||
|
UASSERT_OBJ(!(m_elimCells && nodep->typedefp()), nodep,
|
||||||
|
"RefDType should point to data type before typedefs removed");
|
||||||
if (nodep->packagep()) {
|
if (nodep->packagep()) {
|
||||||
if (m_elimCells) {
|
if (m_elimCells) {
|
||||||
nodep->packagep(NULL);
|
nodep->packagep(NULL);
|
||||||
|
|
|
||||||
|
|
@ -2674,7 +2674,7 @@ private:
|
||||||
checkNoDot(nodep);
|
checkNoDot(nodep);
|
||||||
}
|
}
|
||||||
if (nodep->typeofp()) { // Really is a typeof not a reference
|
if (nodep->typeofp()) { // Really is a typeof not a reference
|
||||||
} else if (!nodep->defp()) {
|
} else if (!nodep->typedefp() && !nodep->subDTypep()) {
|
||||||
VSymEnt* foundp;
|
VSymEnt* foundp;
|
||||||
if (nodep->packagep()) {
|
if (nodep->packagep()) {
|
||||||
foundp = m_statep->getNodeSym(nodep->packagep())->findIdFlat(nodep->name());
|
foundp = m_statep->getNodeSym(nodep->packagep())->findIdFlat(nodep->name());
|
||||||
|
|
@ -2682,7 +2682,7 @@ private:
|
||||||
foundp = m_curSymp->findIdFallback(nodep->name());
|
foundp = m_curSymp->findIdFallback(nodep->name());
|
||||||
}
|
}
|
||||||
if (AstTypedef* defp = foundp ? VN_CAST(foundp->nodep(), Typedef) : NULL) {
|
if (AstTypedef* defp = foundp ? VN_CAST(foundp->nodep(), Typedef) : NULL) {
|
||||||
nodep->refDTypep(defp->subDTypep());
|
nodep->typedefp(defp);
|
||||||
nodep->packagep(foundp->packagep());
|
nodep->packagep(foundp->packagep());
|
||||||
} else if (AstParamTypeDType* defp
|
} else if (AstParamTypeDType* defp
|
||||||
= foundp ? VN_CAST(foundp->nodep(), ParamTypeDType) : NULL) {
|
= foundp ? VN_CAST(foundp->nodep(), ParamTypeDType) : NULL) {
|
||||||
|
|
|
||||||
|
|
@ -1437,18 +1437,21 @@ private:
|
||||||
// Type comes from expression's type
|
// Type comes from expression's type
|
||||||
userIterateAndNext(nodep->typeofp(), WidthVP(SELF, BOTH).p());
|
userIterateAndNext(nodep->typeofp(), WidthVP(SELF, BOTH).p());
|
||||||
AstNode* typeofp = nodep->typeofp();
|
AstNode* typeofp = nodep->typeofp();
|
||||||
|
nodep->typedefp(NULL);
|
||||||
nodep->refDTypep(typeofp->dtypep());
|
nodep->refDTypep(typeofp->dtypep());
|
||||||
VL_DO_DANGLING(typeofp->unlinkFrBack()->deleteTree(), typeofp);
|
VL_DO_DANGLING(typeofp->unlinkFrBack()->deleteTree(), typeofp);
|
||||||
// We had to use AstRefDType for this construct as pointers to this type
|
// We had to use AstRefDType for this construct as pointers to this type
|
||||||
// in type table are still correct (which they wouldn't be if we replaced the node)
|
// in type table are still correct (which they wouldn't be if we replaced the node)
|
||||||
}
|
}
|
||||||
userIterateChildren(nodep, NULL);
|
userIterateChildren(nodep, NULL);
|
||||||
if (nodep->subDTypep()) nodep->refDTypep(iterateEditDTypep(nodep, nodep->subDTypep()));
|
if (nodep->subDTypep()) {
|
||||||
|
nodep->refDTypep(iterateEditDTypep(nodep, nodep->subDTypep()));
|
||||||
|
nodep->typedefp(NULL); // Note until line above subDTypep() may have followed this
|
||||||
|
}
|
||||||
// Effectively nodep->dtypeFrom(nodep->dtypeSkipRefp());
|
// Effectively nodep->dtypeFrom(nodep->dtypeSkipRefp());
|
||||||
// But might be recursive, so instead manually recurse into the referenced type
|
// But might be recursive, so instead manually recurse into the referenced type
|
||||||
UASSERT_OBJ(nodep->defp(), nodep, "Unlinked");
|
UASSERT_OBJ(nodep->subDTypep(), nodep, "Unlinked");
|
||||||
nodep->dtypeFrom(nodep->defp());
|
nodep->dtypeFrom(nodep->subDTypep());
|
||||||
userIterate(nodep->defp(), NULL);
|
|
||||||
nodep->widthFromSub(nodep->subDTypep());
|
nodep->widthFromSub(nodep->subDTypep());
|
||||||
UINFO(4, "dtWidthed " << nodep << endl);
|
UINFO(4, "dtWidthed " << nodep << endl);
|
||||||
nodep->doingWidth(false);
|
nodep->doingWidth(false);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue