Internals: Remove m_classPrefix from AstNodeVarRef/AstNodeCCall

This is now redundant and can be reconstituted in V3EmitC without being
explicitly stored.
This commit is contained in:
Geza Lore 2021-06-19 15:50:29 +01:00
parent 2ee52222e2
commit fcb8bc22bd
5 changed files with 8 additions and 39 deletions

View File

@ -2285,7 +2285,6 @@ private:
AstNodeModule* m_classOrPackagep = nullptr; // Package hierarchy AstNodeModule* m_classOrPackagep = nullptr; // Package hierarchy
string m_name; // Name of variable string m_name; // Name of variable
string m_selfPointer; // Output code object pointer (e.g.: 'this') string m_selfPointer; // Output code object pointer (e.g.: 'this')
string m_classPrefix; // Output class prefix (i.e.: the part before ::)
protected: protected:
AstNodeVarRef(AstType t, FileLine* fl, const string& name, const VAccess& access) AstNodeVarRef(AstType t, FileLine* fl, const string& name, const VAccess& access)
@ -2320,9 +2319,6 @@ public:
string selfPointer() const { return m_selfPointer; } string selfPointer() const { return m_selfPointer; }
void selfPointer(const string& value) { m_selfPointer = value; } void selfPointer(const string& value) { m_selfPointer = value; }
string selfPointerProtect(bool useSelfForThis) const; string selfPointerProtect(bool useSelfForThis) const;
string classPrefix() const { return m_classPrefix; }
void classPrefix(const string& value) { m_classPrefix = value; }
string classPrefixProtect() const;
AstNodeModule* classOrPackagep() const { return m_classOrPackagep; } AstNodeModule* classOrPackagep() const { return m_classOrPackagep; }
void classOrPackagep(AstNodeModule* nodep) { m_classOrPackagep = nodep; } void classOrPackagep(AstNodeModule* nodep) { m_classOrPackagep = nodep; }
// Know no children, and hot function, so skip iterator for speed // Know no children, and hot function, so skip iterator for speed
@ -2626,7 +2622,6 @@ class AstNodeCCall VL_NOT_FINAL : public AstNodeStmt {
// Functions are not statements, while tasks are. AstNodeStmt needs isStatement() to deal. // Functions are not statements, while tasks are. AstNodeStmt needs isStatement() to deal.
AstCFunc* m_funcp; AstCFunc* m_funcp;
string m_selfPointer; // Output code object pointer (e.g.: 'this') string m_selfPointer; // Output code object pointer (e.g.: 'this')
string m_classPrefix; // Output class prefix (i.e.: the part before ::)
string m_argTypes; string m_argTypes;
protected: protected:
@ -2655,9 +2650,6 @@ public:
string selfPointer() const { return m_selfPointer; } string selfPointer() const { return m_selfPointer; }
void selfPointer(const string& value) { m_selfPointer = value; } void selfPointer(const string& value) { m_selfPointer = value; }
string selfPointerProtect(bool useSelfForThis) const; string selfPointerProtect(bool useSelfForThis) const;
string classPrefix() const { return m_classPrefix; }
void classPrefix(const string& value) { m_classPrefix = value; }
string classPrefixProtect() const;
void argTypes(const string& str) { m_argTypes = str; } void argTypes(const string& str) { m_argTypes = str; }
string argTypes() const { return m_argTypes; } string argTypes() const { return m_argTypes; }
// op1p reserved for AstCMethodCall // op1p reserved for AstCMethodCall

View File

@ -63,10 +63,6 @@ string AstNodeVarRef::selfPointerProtect(bool useSelfForThis) const {
return VIdProtect::protectWordsIf(sp, protect()); return VIdProtect::protectWordsIf(sp, protect());
} }
string AstNodeVarRef::classPrefixProtect() const {
return v3Global.opt.modPrefix() + "_" + VIdProtect::protectWordsIf(classPrefix(), protect());
}
void AstAddrOfCFunc::cloneRelink() { void AstAddrOfCFunc::cloneRelink() {
if (m_funcp && m_funcp->clonep()) m_funcp = m_funcp->clonep(); if (m_funcp && m_funcp->clonep()) m_funcp = m_funcp->clonep();
} }
@ -130,9 +126,6 @@ string AstNodeCCall::selfPointerProtect(bool useSelfForThis) const {
= useSelfForThis ? VString::replaceWord(selfPointer(), "this", "vlSelf") : selfPointer(); = useSelfForThis ? VString::replaceWord(selfPointer(), "this", "vlSelf") : selfPointer();
return VIdProtect::protectWordsIf(sp, protect()); return VIdProtect::protectWordsIf(sp, protect());
} }
string AstNodeCCall::classPrefixProtect() const {
return v3Global.opt.modPrefix() + "_" + VIdProtect::protectWordsIf(classPrefix(), protect());
}
void AstNodeCond::numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs, void AstNodeCond::numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs,
const V3Number& ths) { const V3Number& ths) {

View File

@ -73,7 +73,6 @@ public:
= oldp->argsp() ? oldp->argsp()->unlinkFrBackWithNext() : nullptr; = oldp->argsp() ? oldp->argsp()->unlinkFrBackWithNext() : nullptr;
AstCCall* const newp = new AstCCall(oldp->fileline(), newfuncp, argsp); AstCCall* const newp = new AstCCall(oldp->fileline(), newfuncp, argsp);
newp->selfPointer(oldp->selfPointer()); newp->selfPointer(oldp->selfPointer());
newp->classPrefix(oldp->classPrefix());
newp->argTypes(oldp->argTypes()); newp->argTypes(oldp->argTypes());
addCall(newp); // Fix the table, in case the newfuncp itself gets replaced addCall(newp); // Fix the table, in case the newfuncp itself gets replaced
oldp->replaceWith(newp); oldp->replaceWith(newp);

View File

@ -106,17 +106,6 @@ private:
} }
} }
// Construct the class prefix (as in, the part before the :: scope resolution operator) when
// referencing an object in 'scopep' from a CFunc in 'm_scopep'.
string descopedClassPrefix(const AstScope* scopep) {
UASSERT(scopep, "Var/Func not scoped");
if (VN_IS(scopep->modp(), Class) && scopep != m_scopep) {
return scopep->modp()->name();
} else {
return "";
}
}
void makePublicFuncWrappers() { void makePublicFuncWrappers() {
// We recorded all public functions in m_modFuncs. // We recorded all public functions in m_modFuncs.
// If for any given name only one function exists, we can use that function directly. // If for any given name only one function exists, we can use that function directly.
@ -229,10 +218,7 @@ private:
UASSERT_OBJ(m_scopep, nodep, "Node not under scope"); UASSERT_OBJ(m_scopep, nodep, "Node not under scope");
const AstVar* const varp = nodep->varScopep()->varp(); const AstVar* const varp = nodep->varScopep()->varp();
const AstScope* const scopep = nodep->varScopep()->scopep(); const AstScope* const scopep = nodep->varScopep()->scopep();
if (!varp->isFuncLocal()) { if (!varp->isFuncLocal()) { nodep->selfPointer(descopedSelfPointer(scopep)); }
nodep->selfPointer(descopedSelfPointer(scopep));
nodep->classPrefix(descopedClassPrefix(scopep));
}
nodep->varScopep(nullptr); nodep->varScopep(nullptr);
UINFO(9, " refout " << nodep << endl); UINFO(9, " refout " << nodep << endl);
} }
@ -243,7 +229,6 @@ private:
UASSERT_OBJ(m_scopep, nodep, "Node not under scope"); UASSERT_OBJ(m_scopep, nodep, "Node not under scope");
const AstScope* const scopep = nodep->funcp()->scopep(); const AstScope* const scopep = nodep->funcp()->scopep();
nodep->selfPointer(descopedSelfPointer(scopep)); nodep->selfPointer(descopedSelfPointer(scopep));
nodep->classPrefix(descopedClassPrefix(scopep));
// Can't do this, as we may have more calls later // Can't do this, as we may have more calls later
// nodep->funcp()->scopep(nullptr); // nodep->funcp()->scopep(nullptr);
} }

View File

@ -386,12 +386,11 @@ public:
puts(funcp->name()); puts(funcp->name());
} else if (funcp->isProperMethod() && funcp->isStatic()) { } else if (funcp->isProperMethod() && funcp->isStatic()) {
// Call static method via the containing class // Call static method via the containing class
AstNodeModule* modp = VN_CAST(funcp->user4p(), NodeModule); puts(prefixNameProtect(funcp->user4p()) + "::");
puts(prefixNameProtect(modp) + "::");
puts(funcp->nameProtect()); puts(funcp->nameProtect());
} else if (!nodep->classPrefix().empty()) { } else if (VN_IS(funcp->user4p(), Class) && funcp->user4p() != m_modp) {
// Prefix explicitly given // Calling superclass method
puts(nodep->classPrefixProtect() + "::"); puts(prefixNameProtect(funcp->user4p()) + "::");
puts(funcp->nameProtect()); puts(funcp->nameProtect());
} else if (funcp->isLoose()) { } else if (funcp->isLoose()) {
// Calling loose method // Calling loose method
@ -1133,8 +1132,9 @@ public:
} else if (varp->isStatic()) { } else if (varp->isStatic()) {
// Access static variable via the containing class // Access static variable via the containing class
puts(prefixNameProtect(varp->user4p()) + "::"); puts(prefixNameProtect(varp->user4p()) + "::");
} else if (!nodep->classPrefix().empty()) { } else if (VN_IS(varp->user4p(), Class) && varp->user4p() != m_modp) {
puts(nodep->classPrefixProtect() + "::"); // Superclass member reference
puts(prefixNameProtect(varp->user4p()) + "::");
} else if (!nodep->selfPointer().empty()) { } else if (!nodep->selfPointer().empty()) {
emitDereference(nodep->selfPointerProtect(m_useSelfForThis)); emitDereference(nodep->selfPointerProtect(m_useSelfForThis));
} }