Internals: Code movement, no functional change.

This commit is contained in:
Wilson Snyder 2020-11-28 22:01:11 -05:00
parent e09f039a36
commit aa360052a8
3 changed files with 10 additions and 7 deletions

View File

@ -1171,6 +1171,12 @@ void AstClass::repairCache() {
clearCache();
for (AstNode* itemp = membersp(); itemp; itemp = itemp->nextp()) { insertCache(itemp); }
}
bool AstClass::isClassExtendedFrom(const AstClass* refClassp, const AstClass* baseClassp) {
// TAIL RECURSIVE
if (!refClassp || !baseClassp) return false;
if (refClassp == baseClassp) return true;
return isClassExtendedFrom(refClassp->extendsp()->classp(), baseClassp);
}
void AstClass::dump(std::ostream& str) const {
this->AstNode::dump(str);
if (isExtended()) str << " [EXT]";

View File

@ -341,6 +341,9 @@ public:
void isExtended(bool flag) { m_extended = flag; }
bool isVirtual() const { return m_virtual; }
void isVirtual(bool flag) { m_virtual = flag; }
// Return true if this class is an extension of base class (SLOW)
// Accepts nullptrs
static bool isClassExtendedFrom(const AstClass* refClassp, const AstClass* baseClassp);
};
class AstClassExtends final : public AstNode {

View File

@ -133,7 +133,7 @@ private:
const char* how = nullptr;
if (local && defClassp && refClassp != defClassp) {
how = "'local'";
} else if (prot && defClassp && !classExtendedRecurse(refClassp, defClassp)) {
} else if (prot && defClassp && !AstClass::isClassExtendedFrom(refClassp, defClassp)) {
how = "'protected'";
}
if (how) {
@ -149,12 +149,6 @@ private:
}
}
}
static bool classExtendedRecurse(const AstClass* refClassp, const AstClass* defClassp) {
// Return true if refClassp is an extends class of defClassp
if (!refClassp || !defClassp) return false;
if (refClassp == defClassp) return true;
return classExtendedRecurse(refClassp->extendsp()->classp(), defClassp);
}
// VISITORS
virtual void visit(AstNodeModule* nodep) override {