forked from github/verilator
Internals: minor cleanup to V3Descope
This commit is contained in:
parent
9eafca5e28
commit
0a28fc8c63
@ -46,9 +46,9 @@ private:
|
|||||||
|
|
||||||
// STATE
|
// STATE
|
||||||
AstNodeModule* m_modp = nullptr; // Current module
|
AstNodeModule* m_modp = nullptr; // Current module
|
||||||
AstScope* m_scopep = nullptr; // Current scope
|
const AstScope* m_scopep = nullptr; // Current scope
|
||||||
bool m_modSingleton = false; // m_modp is only instanced once
|
const AstCFunc* m_funcp = nullptr; // Current function
|
||||||
bool m_allowThis = false; // Allow function non-static
|
bool m_modSingleton = false; // m_modp is only instantiated once
|
||||||
FuncMmap m_modFuncs; // Name of public functions added
|
FuncMmap m_modFuncs; // Name of public functions added
|
||||||
|
|
||||||
// METHODS
|
// METHODS
|
||||||
@ -74,12 +74,8 @@ private:
|
|||||||
string descopedSelfPointer(const AstScope* scopep) {
|
string descopedSelfPointer(const AstScope* scopep) {
|
||||||
UASSERT(scopep, "Var/Func not scoped");
|
UASSERT(scopep, "Var/Func not scoped");
|
||||||
|
|
||||||
// Whether to use relative references via 'this->'
|
// Static functions can't use relative references via 'this->'
|
||||||
bool relativeRefOk = true;
|
const bool relativeRefOk = !m_funcp->isStatic();
|
||||||
// Static functions can't use this
|
|
||||||
if (!m_allowThis) relativeRefOk = false;
|
|
||||||
// Class methods need relative
|
|
||||||
if (m_modp && VN_IS(m_modp, Class)) relativeRefOk = true;
|
|
||||||
|
|
||||||
UINFO(8, " Descope ref under " << m_scopep << endl);
|
UINFO(8, " Descope ref under " << m_scopep << endl);
|
||||||
UINFO(8, " ref to " << scopep << endl);
|
UINFO(8, " ref to " << scopep << endl);
|
||||||
@ -88,7 +84,7 @@ private:
|
|||||||
if (relativeRefOk && scopep == m_scopep) {
|
if (relativeRefOk && scopep == m_scopep) {
|
||||||
return "this";
|
return "this";
|
||||||
} else if (VN_IS(scopep->modp(), Class)) {
|
} else if (VN_IS(scopep->modp(), Class)) {
|
||||||
return "";
|
return "this";
|
||||||
} else if (!m_modSingleton && relativeRefOk && scopep->aboveScopep() == m_scopep
|
} else if (!m_modSingleton && relativeRefOk && scopep->aboveScopep() == m_scopep
|
||||||
&& VN_IS(scopep->modp(), Module)) {
|
&& VN_IS(scopep->modp(), Module)) {
|
||||||
// Reference to scope of instance directly under this module, can just "this->cell",
|
// Reference to scope of instance directly under this module, can just "this->cell",
|
||||||
@ -250,9 +246,12 @@ private:
|
|||||||
// nodep->funcp()->scopep(nullptr);
|
// nodep->funcp()->scopep(nullptr);
|
||||||
}
|
}
|
||||||
virtual void visit(AstCFunc* nodep) override {
|
virtual void visit(AstCFunc* nodep) override {
|
||||||
VL_RESTORER(m_allowThis);
|
VL_RESTORER(m_funcp);
|
||||||
if (!nodep->user1()) {
|
if (!nodep->user1()) {
|
||||||
m_allowThis = !nodep->isStatic();
|
// Static functions should have been moved under the corresponding AstClassPackage
|
||||||
|
UASSERT(!(nodep->isStatic() && VN_IS(m_modp, Class)),
|
||||||
|
"Static function under AstClass");
|
||||||
|
m_funcp = nodep;
|
||||||
iterateChildren(nodep);
|
iterateChildren(nodep);
|
||||||
nodep->user1(true);
|
nodep->user1(true);
|
||||||
// If it's under a scope, move it up to the top
|
// If it's under a scope, move it up to the top
|
||||||
|
Loading…
Reference in New Issue
Block a user