From fcb8bc22bdeeb0ba4a285cddeb16c61f4ce33339 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Sat, 19 Jun 2021 15:50:29 +0100 Subject: [PATCH] Internals: Remove m_classPrefix from AstNodeVarRef/AstNodeCCall This is now redundant and can be reconstituted in V3EmitC without being explicitly stored. --- src/V3Ast.h | 8 -------- src/V3AstNodes.cpp | 7 ------- src/V3Combine.cpp | 1 - src/V3Descope.cpp | 17 +---------------- src/V3EmitC.cpp | 14 +++++++------- 5 files changed, 8 insertions(+), 39 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index defd1d5a6..3c92a9a3a 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2285,7 +2285,6 @@ private: AstNodeModule* m_classOrPackagep = nullptr; // Package hierarchy string m_name; // Name of variable string m_selfPointer; // Output code object pointer (e.g.: 'this') - string m_classPrefix; // Output class prefix (i.e.: the part before ::) protected: AstNodeVarRef(AstType t, FileLine* fl, const string& name, const VAccess& access) @@ -2320,9 +2319,6 @@ public: string selfPointer() const { return m_selfPointer; } void selfPointer(const string& value) { m_selfPointer = value; } 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; } void classOrPackagep(AstNodeModule* nodep) { m_classOrPackagep = nodep; } // 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. AstCFunc* m_funcp; string m_selfPointer; // Output code object pointer (e.g.: 'this') - string m_classPrefix; // Output class prefix (i.e.: the part before ::) string m_argTypes; protected: @@ -2655,9 +2650,6 @@ public: string selfPointer() const { return m_selfPointer; } void selfPointer(const string& value) { m_selfPointer = value; } 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; } string argTypes() const { return m_argTypes; } // op1p reserved for AstCMethodCall diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index d631e4065..e933d6d92 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -63,10 +63,6 @@ string AstNodeVarRef::selfPointerProtect(bool useSelfForThis) const { return VIdProtect::protectWordsIf(sp, protect()); } -string AstNodeVarRef::classPrefixProtect() const { - return v3Global.opt.modPrefix() + "_" + VIdProtect::protectWordsIf(classPrefix(), protect()); -} - void AstAddrOfCFunc::cloneRelink() { 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(); 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, const V3Number& ths) { diff --git a/src/V3Combine.cpp b/src/V3Combine.cpp index ee1284598..b5cd7ff20 100644 --- a/src/V3Combine.cpp +++ b/src/V3Combine.cpp @@ -73,7 +73,6 @@ public: = oldp->argsp() ? oldp->argsp()->unlinkFrBackWithNext() : nullptr; AstCCall* const newp = new AstCCall(oldp->fileline(), newfuncp, argsp); newp->selfPointer(oldp->selfPointer()); - newp->classPrefix(oldp->classPrefix()); newp->argTypes(oldp->argTypes()); addCall(newp); // Fix the table, in case the newfuncp itself gets replaced oldp->replaceWith(newp); diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index 2428d61a4..a1f5453bd 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -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() { // We recorded all public functions in m_modFuncs. // 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"); const AstVar* const varp = nodep->varScopep()->varp(); const AstScope* const scopep = nodep->varScopep()->scopep(); - if (!varp->isFuncLocal()) { - nodep->selfPointer(descopedSelfPointer(scopep)); - nodep->classPrefix(descopedClassPrefix(scopep)); - } + if (!varp->isFuncLocal()) { nodep->selfPointer(descopedSelfPointer(scopep)); } nodep->varScopep(nullptr); UINFO(9, " refout " << nodep << endl); } @@ -243,7 +229,6 @@ private: UASSERT_OBJ(m_scopep, nodep, "Node not under scope"); const AstScope* const scopep = nodep->funcp()->scopep(); nodep->selfPointer(descopedSelfPointer(scopep)); - nodep->classPrefix(descopedClassPrefix(scopep)); // Can't do this, as we may have more calls later // nodep->funcp()->scopep(nullptr); } diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 9aa369517..dd48ecfe4 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -386,12 +386,11 @@ public: puts(funcp->name()); } else if (funcp->isProperMethod() && funcp->isStatic()) { // Call static method via the containing class - AstNodeModule* modp = VN_CAST(funcp->user4p(), NodeModule); - puts(prefixNameProtect(modp) + "::"); + puts(prefixNameProtect(funcp->user4p()) + "::"); puts(funcp->nameProtect()); - } else if (!nodep->classPrefix().empty()) { - // Prefix explicitly given - puts(nodep->classPrefixProtect() + "::"); + } else if (VN_IS(funcp->user4p(), Class) && funcp->user4p() != m_modp) { + // Calling superclass method + puts(prefixNameProtect(funcp->user4p()) + "::"); puts(funcp->nameProtect()); } else if (funcp->isLoose()) { // Calling loose method @@ -1133,8 +1132,9 @@ public: } else if (varp->isStatic()) { // Access static variable via the containing class puts(prefixNameProtect(varp->user4p()) + "::"); - } else if (!nodep->classPrefix().empty()) { - puts(nodep->classPrefixProtect() + "::"); + } else if (VN_IS(varp->user4p(), Class) && varp->user4p() != m_modp) { + // Superclass member reference + puts(prefixNameProtect(varp->user4p()) + "::"); } else if (!nodep->selfPointer().empty()) { emitDereference(nodep->selfPointerProtect(m_useSelfForThis)); }