Internals: Use pointer to const nodes in V3MemberMap (#4353)

This commit is contained in:
Krzysztof Boroński 2023-07-12 17:36:24 +02:00 committed by GitHub
parent 23fe5c1b93
commit 0774f825cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -35,12 +35,12 @@
class VMemberMap final {
// MEMBERS
using MemberMap = std::map<std::string, AstNode*>;
using NodeMap = std::map<AstNode*, MemberMap>;
using NodeMap = std::map<const AstNode*, MemberMap>;
NodeMap m_map; // Map of nodes being tracked
public:
void clear() { m_map.clear(); }
// Find 'name' under 'nodep', caching nodep's children if needed
AstNode* findMember(AstNode* nodep, const std::string& name) {
AstNode* findMember(const AstNode* nodep, const std::string& name) {
auto nit = m_map.find(nodep);
if (VL_UNLIKELY(nit == m_map.end())) {
scan(nodep);
@ -51,7 +51,7 @@ public:
return mit->second;
}
// Insert under the given parent node the child's name
void insert(AstNode* nodep, AstNode* childp) {
void insert(const AstNode* nodep, AstNode* childp) {
auto nit = m_map.find(nodep);
if (nit == m_map.end()) {
scan(nodep);
@ -61,10 +61,10 @@ public:
}
private:
void scan(AstNode* nodep) {
void scan(const AstNode* nodep) {
const auto nitPair = m_map.emplace(nodep, MemberMap{});
MemberMap& mmapr = nitPair.first->second;
if (AstClass* const anodep = VN_CAST(nodep, Class)) {
if (const AstClass* const anodep = VN_CAST(nodep, Class)) {
for (AstNode* itemp = anodep->membersp(); itemp; itemp = itemp->nextp()) {
if (const AstScope* const scopep = VN_CAST(itemp, Scope)) {
for (AstNode* blockp = scopep->blocksp(); blockp; blockp = blockp->nextp()) {
@ -74,7 +74,8 @@ private:
if (AstClass::isCacheableChild(itemp)) memberInsert(mmapr, itemp);
}
}
} else if (AstNodeUOrStructDType* const anodep = VN_CAST(nodep, NodeUOrStructDType)) {
} else if (const AstNodeUOrStructDType* const anodep
= VN_CAST(nodep, NodeUOrStructDType)) {
for (AstNode* itemp = anodep->membersp(); itemp; itemp = itemp->nextp()) {
memberInsert(mmapr, itemp);
}