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).
This commit is contained in:
parent
6c332a2f8e
commit
729bd268de
|
|
@ -1818,11 +1818,7 @@ void AstCFunc::dump(std::ostream& str) const {
|
||||||
this->AstNode::dump(str);
|
this->AstNode::dump(str);
|
||||||
if (slow()) str << " [SLOW]";
|
if (slow()) str << " [SLOW]";
|
||||||
if (pure()) str << " [PURE]";
|
if (pure()) str << " [PURE]";
|
||||||
if (isStatic().unknown()) {
|
if (isStatic()) str << " [STATIC]";
|
||||||
str << " [STATICU]";
|
|
||||||
} else if (isStatic().trueUnknown()) {
|
|
||||||
str << " [STATIC]";
|
|
||||||
}
|
|
||||||
if (dpiExportDispatcher()) str << " [DPIED]";
|
if (dpiExportDispatcher()) str << " [DPIED]";
|
||||||
if (dpiExportImpl()) str << " [DPIEI]";
|
if (dpiExportImpl()) str << " [DPIEI]";
|
||||||
if (dpiImportPrototype()) str << " [DPIIP]";
|
if (dpiImportPrototype()) str << " [DPIIP]";
|
||||||
|
|
|
||||||
|
|
@ -8734,7 +8734,7 @@ private:
|
||||||
string m_ctorInits; // Constructor sub-class inits
|
string m_ctorInits; // Constructor sub-class inits
|
||||||
string m_ifdef; // #ifdef symbol around this function
|
string m_ifdef; // #ifdef symbol around this function
|
||||||
VBoolOrUnknown m_isConst; // Function is declared const (*this not changed)
|
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_dontCombine : 1; // V3Combine shouldn't compare this func tree, it's special
|
||||||
bool m_declPrivate : 1; // Declare it private
|
bool m_declPrivate : 1; // Declare it private
|
||||||
bool m_formCallTree : 1; // Make a global function to call entire tree of functions
|
bool m_formCallTree : 1; // Make a global function to call entire tree of functions
|
||||||
|
|
@ -8758,10 +8758,10 @@ public:
|
||||||
: ASTGEN_SUPER_CFunc(fl) {
|
: ASTGEN_SUPER_CFunc(fl) {
|
||||||
m_funcType = AstCFuncType::FT_NORMAL;
|
m_funcType = AstCFuncType::FT_NORMAL;
|
||||||
m_isConst = VBoolOrUnknown::BU_UNKNOWN; // Unknown until analyzed
|
m_isConst = VBoolOrUnknown::BU_UNKNOWN; // Unknown until analyzed
|
||||||
m_isStatic = VBoolOrUnknown::BU_UNKNOWN; // Unknown until see where thisp needed
|
|
||||||
m_scopep = scopep;
|
m_scopep = scopep;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
m_rtnType = rtnType;
|
m_rtnType = rtnType;
|
||||||
|
m_isStatic = false;
|
||||||
m_dontCombine = false;
|
m_dontCombine = false;
|
||||||
m_declPrivate = false;
|
m_declPrivate = false;
|
||||||
m_formCallTree = false;
|
m_formCallTree = false;
|
||||||
|
|
@ -8801,9 +8801,8 @@ public:
|
||||||
VBoolOrUnknown isConst() const { return m_isConst; }
|
VBoolOrUnknown isConst() const { return m_isConst; }
|
||||||
void isConst(bool flag) { m_isConst.setTrueOrFalse(flag); }
|
void isConst(bool flag) { m_isConst.setTrueOrFalse(flag); }
|
||||||
void isConst(VBoolOrUnknown flag) { m_isConst = flag; }
|
void isConst(VBoolOrUnknown flag) { m_isConst = flag; }
|
||||||
VBoolOrUnknown isStatic() const { return m_isStatic; }
|
bool isStatic() const { return m_isStatic; }
|
||||||
void isStatic(bool flag) { m_isStatic.setTrueOrFalse(flag); }
|
void isStatic(bool flag) { m_isStatic = flag; }
|
||||||
void isStatic(VBoolOrUnknown flag) { m_isStatic = flag; }
|
|
||||||
void cname(const string& name) { m_cname = name; }
|
void cname(const string& name) { m_cname = name; }
|
||||||
string cname() const { return m_cname; }
|
string cname() const { return m_cname; }
|
||||||
AstScope* scopep() const { return m_scopep; }
|
AstScope* scopep() const { return m_scopep; }
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ private:
|
||||||
// (Here instead of new visitor after V3Descope just to avoid another visitor)
|
// (Here instead of new visitor after V3Descope just to avoid another visitor)
|
||||||
void needNonStaticFunc(AstNode* nodep) {
|
void needNonStaticFunc(AstNode* nodep) {
|
||||||
UASSERT_OBJ(m_cfuncp, nodep, "Non-static accessor not under a function");
|
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);
|
UINFO(5, "Mark non-public due to " << nodep << endl);
|
||||||
m_cfuncp->isStatic(false);
|
m_cfuncp->isStatic(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ private:
|
||||||
if (VN_IS(m_modp, Class)) {
|
if (VN_IS(m_modp, Class)) {
|
||||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||||
callp->argTypes("vlSymsp");
|
callp->argTypes("vlSymsp");
|
||||||
} else if (funcp->isStatic().falseUnknown()) {
|
} else if (!funcp->isStatic()) {
|
||||||
callp->selfPointer("this");
|
callp->selfPointer("this");
|
||||||
}
|
}
|
||||||
UINFO(6, " New " << callp << endl);
|
UINFO(6, " New " << callp << endl);
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ private:
|
||||||
AstScope* m_scopep = nullptr; // Current scope
|
AstScope* m_scopep = nullptr; // Current scope
|
||||||
bool m_modSingleton = false; // m_modp is only instanced once
|
bool m_modSingleton = false; // m_modp is only instanced once
|
||||||
bool m_allowThis = false; // Allow function non-static
|
bool m_allowThis = false; // Allow function non-static
|
||||||
bool m_needThis = false; // Make function non-static
|
|
||||||
FuncMmap m_modFuncs; // Name of public functions added
|
FuncMmap m_modFuncs; // Name of public functions added
|
||||||
|
|
||||||
// METHODS
|
// METHODS
|
||||||
|
|
@ -92,7 +91,6 @@ private:
|
||||||
UINFO(8, " aboveScope " << scopep->aboveScopep() << endl);
|
UINFO(8, " aboveScope " << scopep->aboveScopep() << endl);
|
||||||
|
|
||||||
if (relativeRefOk && scopep == m_scopep) {
|
if (relativeRefOk && scopep == m_scopep) {
|
||||||
m_needThis = true;
|
|
||||||
return "this";
|
return "this";
|
||||||
} else if (VN_IS(scopep->modp(), Class)) {
|
} else if (VN_IS(scopep->modp(), Class)) {
|
||||||
return "";
|
return "";
|
||||||
|
|
@ -105,7 +103,6 @@ private:
|
||||||
string name = scopep->name();
|
string name = scopep->name();
|
||||||
string::size_type pos;
|
string::size_type pos;
|
||||||
if ((pos = name.rfind('.')) != string::npos) name.erase(0, pos + 1);
|
if ((pos = name.rfind('.')) != string::npos) name.erase(0, pos + 1);
|
||||||
m_needThis = true;
|
|
||||||
return "this->" + name;
|
return "this->" + name;
|
||||||
} else {
|
} else {
|
||||||
// Reference to something elsewhere, or relative references are disabled. Use global
|
// Reference to something elsewhere, or relative references are disabled. Use global
|
||||||
|
|
@ -258,14 +255,11 @@ private:
|
||||||
// nodep->funcp()->scopep(nullptr);
|
// nodep->funcp()->scopep(nullptr);
|
||||||
}
|
}
|
||||||
virtual void visit(AstCFunc* nodep) override {
|
virtual void visit(AstCFunc* nodep) override {
|
||||||
VL_RESTORER(m_needThis);
|
|
||||||
VL_RESTORER(m_allowThis);
|
VL_RESTORER(m_allowThis);
|
||||||
if (!nodep->user1()) {
|
if (!nodep->user1()) {
|
||||||
m_needThis = false;
|
m_allowThis = !nodep->isStatic();
|
||||||
m_allowThis = nodep->isStatic().falseUnknown(); // Non-static or unknown if static
|
|
||||||
iterateChildren(nodep);
|
iterateChildren(nodep);
|
||||||
nodep->user1(true);
|
nodep->user1(true);
|
||||||
if (m_needThis) nodep->isStatic(false);
|
|
||||||
// If it's under a scope, move it up to the top
|
// If it's under a scope, move it up to the top
|
||||||
if (m_scopep) {
|
if (m_scopep) {
|
||||||
nodep->unlinkFrBack();
|
nodep->unlinkFrBack();
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ public:
|
||||||
}
|
}
|
||||||
void ccallIterateArgs(AstNodeCCall* nodep) {
|
void ccallIterateArgs(AstNodeCCall* nodep) {
|
||||||
bool comma = false;
|
bool comma = false;
|
||||||
if (nodep->funcp()->isLoose() && nodep->funcp()->isStatic().falseUnknown()) {
|
if (nodep->funcp()->isLoose() && !nodep->funcp()->isStatic()) {
|
||||||
UASSERT_OBJ(!nodep->selfPointer().empty(), nodep,
|
UASSERT_OBJ(!nodep->selfPointer().empty(), nodep,
|
||||||
"Call to loose method without self pointer");
|
"Call to loose method without self pointer");
|
||||||
puts(nodep->selfPointerProtect(m_useSelfForThis));
|
puts(nodep->selfPointerProtect(m_useSelfForThis));
|
||||||
|
|
@ -384,7 +384,7 @@ public:
|
||||||
} else if (funcp->dpiImportPrototype()) {
|
} else if (funcp->dpiImportPrototype()) {
|
||||||
// Calling DPI import
|
// Calling DPI import
|
||||||
puts(funcp->name());
|
puts(funcp->name());
|
||||||
} else if (funcp->isProperMethod() && funcp->isStatic().trueUnknown()) {
|
} 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);
|
AstNodeModule* modp = VN_CAST(funcp->user4p(), NodeModule);
|
||||||
puts(prefixNameProtect(modp) + "::");
|
puts(prefixNameProtect(modp) + "::");
|
||||||
|
|
@ -1588,7 +1588,7 @@ class EmitCImp final : EmitCStmts {
|
||||||
|
|
||||||
if (nodep->isLoose()) {
|
if (nodep->isLoose()) {
|
||||||
m_lazyDecls.declared(nodep); // Defined here, so no longer needs declaration
|
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;
|
m_useSelfForThis = true;
|
||||||
puts("if (false && vlSelf) {} // Prevent unused\n");
|
puts("if (false && vlSelf) {} // Prevent unused\n");
|
||||||
if (!VN_IS(m_modp, Class)) puts(symClassAssign());
|
if (!VN_IS(m_modp, Class)) puts(symClassAssign());
|
||||||
|
|
@ -3864,7 +3864,7 @@ class EmitCTrace final : EmitCStmts {
|
||||||
|
|
||||||
if (nodep->isLoose()) {
|
if (nodep->isLoose()) {
|
||||||
m_lazyDecls.declared(nodep); // Defined here, so no longer needs declaration
|
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");
|
puts("if (false && vlSelf) {} // Prevent unused\n");
|
||||||
m_useSelfForThis = true;
|
m_useSelfForThis = true;
|
||||||
puts(symClassAssign());
|
puts(symClassAssign());
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ public:
|
||||||
string cFuncArgs(const AstCFunc* nodep) {
|
string cFuncArgs(const AstCFunc* nodep) {
|
||||||
// Return argument list for given C function
|
// Return argument list for given C function
|
||||||
string args;
|
string args;
|
||||||
if (nodep->isLoose() && nodep->isStatic().falseUnknown()) {
|
if (nodep->isLoose() && !nodep->isStatic()) {
|
||||||
if (nodep->isConst().trueKnown()) args += "const ";
|
if (nodep->isConst().trueKnown()) args += "const ";
|
||||||
AstNodeModule* modp = VN_CAST(nodep->user4p(), NodeModule);
|
AstNodeModule* modp = VN_CAST(nodep->user4p(), NodeModule);
|
||||||
args += prefixNameProtect(modp);
|
args += prefixNameProtect(modp);
|
||||||
|
|
@ -148,7 +148,7 @@ public:
|
||||||
ensureNewLine();
|
ensureNewLine();
|
||||||
if (!funcp->ifdef().empty()) puts("#ifdef " + funcp->ifdef() + "\n");
|
if (!funcp->ifdef().empty()) puts("#ifdef " + funcp->ifdef() + "\n");
|
||||||
if (cLinkage) puts("extern \"C\" ");
|
if (cLinkage) puts("extern \"C\" ");
|
||||||
if (funcp->isStatic().trueUnknown() && funcp->isProperMethod()) puts("static ");
|
if (funcp->isStatic() && funcp->isProperMethod()) puts("static ");
|
||||||
if (funcp->isVirtual()) {
|
if (funcp->isVirtual()) {
|
||||||
UASSERT_OBJ(funcp->isProperMethod(), funcp, "Virtual function is not a proper method");
|
UASSERT_OBJ(funcp->isProperMethod(), funcp, "Virtual function is not a proper method");
|
||||||
puts("virtual ");
|
puts("virtual ");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue