diff --git a/src/V3Graph.cpp b/src/V3Graph.cpp index 208386338..eb66cd934 100644 --- a/src/V3Graph.cpp +++ b/src/V3Graph.cpp @@ -140,6 +140,14 @@ V3GraphEdge::V3GraphEdge(V3Graph* graphp, inPushBack(); } +V3GraphEdge* V3GraphEdge::relinkFromp(V3GraphVertex* newFromp) { + V3GraphEdge *oldNxt = outNextp(); + m_outs.unlink(m_fromp->m_outs, this); + m_fromp = newFromp; + outPushBack(); + return oldNxt; +} + void V3GraphEdge::unlinkDelete() { // Unlink from side m_outs.unlink(m_fromp->m_outs, this); diff --git a/src/V3Graph.h b/src/V3Graph.h index fd6e22a9b..b307c5c58 100644 --- a/src/V3Graph.h +++ b/src/V3Graph.h @@ -242,6 +242,7 @@ public: return top()->sortCmp(rhsp->top()); } void unlinkDelete(); + V3GraphEdge* relinkFromp(V3GraphVertex* newFromp); // ACCESSORS int weight() const { return m_weight; } void weight(int weight) { m_weight=weight; } diff --git a/src/V3Hashed.cpp b/src/V3Hashed.cpp index 1086f41fe..fe220023c 100644 --- a/src/V3Hashed.cpp +++ b/src/V3Hashed.cpp @@ -105,12 +105,16 @@ public: //###################################################################### // Hashed class functions -void V3Hashed::hashAndInsert(AstNode* nodep) { +V3Hashed::iterator V3Hashed::hashAndInsert(AstNode* nodep) { + hash(nodep); + return m_hashMmap.insert(make_pair(nodeHash(nodep), nodep)); +} + +void V3Hashed::hash(AstNode* nodep) { UINFO(8," hashI "<user4p()) { HashedVisitor visitor (nodep); } - m_hashMmap.insert(make_pair(nodeHash(nodep), nodep)); } bool V3Hashed::sameNodes(AstNode* node1p, AstNode* node2p) { @@ -189,3 +193,16 @@ V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) { return end(); } +V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp) { + UINFO(8," findD "<user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node"); + pair eqrange = mmap().equal_range(nodeHash(nodep)); + for (HashMmap::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) { + AstNode* node2p = eqit->second; + if (nodep != node2p && checkp->check(nodep,node2p) && sameNodes(nodep, node2p)) { + return eqit; + } + } + return end(); +} + diff --git a/src/V3Hashed.h b/src/V3Hashed.h index 68b2392bc..4c4038d1b 100644 --- a/src/V3Hashed.h +++ b/src/V3Hashed.h @@ -45,6 +45,11 @@ public: //============================================================================ +struct V3HashedUserCheck { + // Functor for V3Hashed::findDuplicate + virtual bool check(AstNode*,AstNode*) =0; +}; + class V3Hashed : public VHashedBase { // NODE STATE // AstNode::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal) @@ -70,10 +75,12 @@ public: // METHODS void clear() { m_hashMmap.clear(); AstNode::user4ClearTree(); } - void hashAndInsert(AstNode* nodep); // Hash the node, and insert into map + iterator hashAndInsert(AstNode* nodep); // Hash the node, and insert into map. Return iterator to inserted + void hash(AstNode* nodep); // Only hash the node bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical void erase(iterator it); // Remove node from structures iterator findDuplicate(AstNode* nodep); // Return duplicate in hash, if any + iterator findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp); // Extra user checks for sameness AstNode* iteratorNodep(iterator it) { return it->second; } void dumpFile(const string& filename, bool tree); void dumpFilePrefixed(const string& nameComment, bool tree=false);