From 729bd268dec01bd8cad1db70b54147f3f28d6a0b Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Wed, 16 Jun 2021 13:52:37 +0100 Subject: [PATCH] Internals: make AstCFunc::m_isStatic a bool. All functions are now known to be static or not static when they are created, so turn the isStatic flag into a bool (from VBoolOrUnknown). --- src/V3AstNodes.cpp | 6 +----- src/V3AstNodes.h | 9 ++++----- src/V3Depth.cpp | 2 +- src/V3DepthBlock.cpp | 2 +- src/V3Descope.cpp | 8 +------- src/V3EmitC.cpp | 8 ++++---- src/V3EmitCBase.h | 4 ++-- 7 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 4b607309c..d631e4065 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -1818,11 +1818,7 @@ void AstCFunc::dump(std::ostream& str) const { this->AstNode::dump(str); if (slow()) str << " [SLOW]"; if (pure()) str << " [PURE]"; - if (isStatic().unknown()) { - str << " [STATICU]"; - } else if (isStatic().trueUnknown()) { - str << " [STATIC]"; - } + if (isStatic()) str << " [STATIC]"; if (dpiExportDispatcher()) str << " [DPIED]"; if (dpiExportImpl()) str << " [DPIEI]"; if (dpiImportPrototype()) str << " [DPIIP]"; diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 19dea6a9b..c2b82f85c 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -8734,7 +8734,7 @@ private: string m_ctorInits; // Constructor sub-class inits string m_ifdef; // #ifdef symbol around this function VBoolOrUnknown m_isConst; // Function is declared const (*this not changed) - VBoolOrUnknown m_isStatic; // Function is declared static (no this) + bool m_isStatic : 1; // Function is static (no need for a 'this' pointer) bool m_dontCombine : 1; // V3Combine shouldn't compare this func tree, it's special bool m_declPrivate : 1; // Declare it private bool m_formCallTree : 1; // Make a global function to call entire tree of functions @@ -8758,10 +8758,10 @@ public: : ASTGEN_SUPER_CFunc(fl) { m_funcType = AstCFuncType::FT_NORMAL; m_isConst = VBoolOrUnknown::BU_UNKNOWN; // Unknown until analyzed - m_isStatic = VBoolOrUnknown::BU_UNKNOWN; // Unknown until see where thisp needed m_scopep = scopep; m_name = name; m_rtnType = rtnType; + m_isStatic = false; m_dontCombine = false; m_declPrivate = false; m_formCallTree = false; @@ -8801,9 +8801,8 @@ public: VBoolOrUnknown isConst() const { return m_isConst; } void isConst(bool flag) { m_isConst.setTrueOrFalse(flag); } void isConst(VBoolOrUnknown flag) { m_isConst = flag; } - VBoolOrUnknown isStatic() const { return m_isStatic; } - void isStatic(bool flag) { m_isStatic.setTrueOrFalse(flag); } - void isStatic(VBoolOrUnknown flag) { m_isStatic = flag; } + bool isStatic() const { return m_isStatic; } + void isStatic(bool flag) { m_isStatic = flag; } void cname(const string& name) { m_cname = name; } string cname() const { return m_cname; } AstScope* scopep() const { return m_scopep; } diff --git a/src/V3Depth.cpp b/src/V3Depth.cpp index 5ff517a62..789cf8359 100644 --- a/src/V3Depth.cpp +++ b/src/V3Depth.cpp @@ -128,7 +128,7 @@ private: // (Here instead of new visitor after V3Descope just to avoid another visitor) void needNonStaticFunc(AstNode* nodep) { UASSERT_OBJ(m_cfuncp, nodep, "Non-static accessor not under a function"); - if (m_cfuncp->isStatic().trueUnknown()) { + if (m_cfuncp->isStatic()) { UINFO(5, "Mark non-public due to " << nodep << endl); m_cfuncp->isStatic(false); } diff --git a/src/V3DepthBlock.cpp b/src/V3DepthBlock.cpp index 5707fccd4..f94813a06 100644 --- a/src/V3DepthBlock.cpp +++ b/src/V3DepthBlock.cpp @@ -61,7 +61,7 @@ private: if (VN_IS(m_modp, Class)) { funcp->argTypes(EmitCBaseVisitor::symClassVar()); callp->argTypes("vlSymsp"); - } else if (funcp->isStatic().falseUnknown()) { + } else if (!funcp->isStatic()) { callp->selfPointer("this"); } UINFO(6, " New " << callp << endl); diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index 8d94ef243..44ba216d2 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -49,7 +49,6 @@ private: AstScope* m_scopep = nullptr; // Current scope bool m_modSingleton = false; // m_modp is only instanced once bool m_allowThis = false; // Allow function non-static - bool m_needThis = false; // Make function non-static FuncMmap m_modFuncs; // Name of public functions added // METHODS @@ -92,7 +91,6 @@ private: UINFO(8, " aboveScope " << scopep->aboveScopep() << endl); if (relativeRefOk && scopep == m_scopep) { - m_needThis = true; return "this"; } else if (VN_IS(scopep->modp(), Class)) { return ""; @@ -105,7 +103,6 @@ private: string name = scopep->name(); string::size_type pos; if ((pos = name.rfind('.')) != string::npos) name.erase(0, pos + 1); - m_needThis = true; return "this->" + name; } else { // Reference to something elsewhere, or relative references are disabled. Use global @@ -258,14 +255,11 @@ private: // nodep->funcp()->scopep(nullptr); } virtual void visit(AstCFunc* nodep) override { - VL_RESTORER(m_needThis); VL_RESTORER(m_allowThis); if (!nodep->user1()) { - m_needThis = false; - m_allowThis = nodep->isStatic().falseUnknown(); // Non-static or unknown if static + m_allowThis = !nodep->isStatic(); iterateChildren(nodep); nodep->user1(true); - if (m_needThis) nodep->isStatic(false); // If it's under a scope, move it up to the top if (m_scopep) { nodep->unlinkFrBack(); diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 671eecf5c..9aa369517 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -247,7 +247,7 @@ public: } void ccallIterateArgs(AstNodeCCall* nodep) { bool comma = false; - if (nodep->funcp()->isLoose() && nodep->funcp()->isStatic().falseUnknown()) { + if (nodep->funcp()->isLoose() && !nodep->funcp()->isStatic()) { UASSERT_OBJ(!nodep->selfPointer().empty(), nodep, "Call to loose method without self pointer"); puts(nodep->selfPointerProtect(m_useSelfForThis)); @@ -384,7 +384,7 @@ public: } else if (funcp->dpiImportPrototype()) { // Calling DPI import puts(funcp->name()); - } else if (funcp->isProperMethod() && funcp->isStatic().trueUnknown()) { + } else if (funcp->isProperMethod() && funcp->isStatic()) { // Call static method via the containing class AstNodeModule* modp = VN_CAST(funcp->user4p(), NodeModule); puts(prefixNameProtect(modp) + "::"); @@ -1588,7 +1588,7 @@ class EmitCImp final : EmitCStmts { if (nodep->isLoose()) { m_lazyDecls.declared(nodep); // Defined here, so no longer needs declaration - if (nodep->isStatic().falseUnknown()) { // Standard prologue + if (!nodep->isStatic()) { // Standard prologue m_useSelfForThis = true; puts("if (false && vlSelf) {} // Prevent unused\n"); if (!VN_IS(m_modp, Class)) puts(symClassAssign()); @@ -3864,7 +3864,7 @@ class EmitCTrace final : EmitCStmts { if (nodep->isLoose()) { m_lazyDecls.declared(nodep); // Defined here, so no longer needs declaration - if (nodep->isStatic().falseUnknown()) { // Standard prologue + if (!nodep->isStatic()) { // Standard prologue puts("if (false && vlSelf) {} // Prevent unused\n"); m_useSelfForThis = true; puts(symClassAssign()); diff --git a/src/V3EmitCBase.h b/src/V3EmitCBase.h index 005956543..e3d32d827 100644 --- a/src/V3EmitCBase.h +++ b/src/V3EmitCBase.h @@ -105,7 +105,7 @@ public: string cFuncArgs(const AstCFunc* nodep) { // Return argument list for given C function string args; - if (nodep->isLoose() && nodep->isStatic().falseUnknown()) { + if (nodep->isLoose() && !nodep->isStatic()) { if (nodep->isConst().trueKnown()) args += "const "; AstNodeModule* modp = VN_CAST(nodep->user4p(), NodeModule); args += prefixNameProtect(modp); @@ -148,7 +148,7 @@ public: ensureNewLine(); if (!funcp->ifdef().empty()) puts("#ifdef " + funcp->ifdef() + "\n"); if (cLinkage) puts("extern \"C\" "); - if (funcp->isStatic().trueUnknown() && funcp->isProperMethod()) puts("static "); + if (funcp->isStatic() && funcp->isProperMethod()) puts("static "); if (funcp->isVirtual()) { UASSERT_OBJ(funcp->isProperMethod(), funcp, "Virtual function is not a proper method"); puts("virtual ");