From de81593e987085f95ce823dd1a6db248156ae161 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 9 Jul 2018 19:15:46 -0400 Subject: [PATCH] Internals: Template GraphAlg to allow const. No functional change. --- src/V3GraphAlg.cpp | 12 ++++++------ src/V3GraphAlg.h | 18 ++++++++++-------- src/V3GraphDfa.cpp | 6 +++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/V3GraphAlg.cpp b/src/V3GraphAlg.cpp index ac9b41b27..da908ecb5 100644 --- a/src/V3GraphAlg.cpp +++ b/src/V3GraphAlg.cpp @@ -74,7 +74,7 @@ void V3Graph::deleteCutableOnlyEdges() { //###################################################################### // Algorithms - weakly connected components -class GraphRemoveRedundant : GraphAlg { +class GraphRemoveRedundant : GraphAlg<> { bool m_sumWeights; ///< Sum, rather then maximize weights private: void main() { @@ -138,7 +138,7 @@ void V3Graph::removeRedundantEdgesSum(V3EdgeFuncP edgeFuncp) { //###################################################################### // Algorithms - weakly connected components -class GraphAlgWeakly : GraphAlg { +class GraphAlgWeakly : GraphAlg<> { private: void main() { // Initialize state @@ -183,7 +183,7 @@ void V3Graph::weaklyConnected(V3EdgeFuncP edgeFuncp) { //###################################################################### // Algorithms - strongly connected components -class GraphAlgStrongly : GraphAlg { +class GraphAlgStrongly : GraphAlg<> { private: uint32_t m_currentDfs; // DFS count std::vector m_callTrace; // List of everything we hit processing so far @@ -269,7 +269,7 @@ void V3Graph::stronglyConnected(V3EdgeFuncP edgeFuncp) { //###################################################################### // Algorithms - ranking -class GraphAlgRank : GraphAlg { +class GraphAlgRank : GraphAlg<> { private: void main() { // Rank each vertex, ignoring cutable edges @@ -325,7 +325,7 @@ void V3Graph::rank(V3EdgeFuncP edgeFuncp) { //###################################################################### // Algorithms - ranking -class GraphAlgRLoops : GraphAlg { +class GraphAlgRLoops : GraphAlg<> { private: std::vector m_callTrace; // List of everything we hit processing so far bool m_done; // Exit algorithm @@ -381,7 +381,7 @@ void V3Graph::reportLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp) { //###################################################################### // Algorithms - subtrees -class GraphAlgSubtrees : GraphAlg { +class GraphAlgSubtrees : GraphAlg<> { private: V3Graph* m_loopGraphp; diff --git a/src/V3GraphAlg.h b/src/V3GraphAlg.h index d764ca9b5..63dc84516 100644 --- a/src/V3GraphAlg.h +++ b/src/V3GraphAlg.h @@ -30,17 +30,19 @@ // Algorithms - common class // For internal use, most graph algorithms use this as a base class +template // Or sometimes const V3Graph class GraphAlg { protected: - V3Graph* m_graphp; // Graph we're operating upon - V3EdgeFuncP m_edgeFuncp; // Function that says we follow this edge - - inline bool followEdge(V3GraphEdge* edgep) { - return (edgep->weight() && (m_edgeFuncp)(edgep)); - } - GraphAlg(V3Graph* graphp, V3EdgeFuncP edgeFuncp) - : m_graphp(graphp), m_edgeFuncp(edgeFuncp) {} + T* m_graphp; // Graph we're operating upon + V3EdgeFuncP m_edgeFuncp; // Function that says we follow this edge + // CONSTRUCTORS + GraphAlg(T* graphp, V3EdgeFuncP edgeFuncp) + : m_graphp(graphp), m_edgeFuncp(edgeFuncp) {} ~GraphAlg() {} + // METHODS + inline bool followEdge(V3GraphEdge* edgep) { + return (edgep->weight() && (m_edgeFuncp)(edgep)); + } }; //============================================================================ diff --git a/src/V3GraphDfa.cpp b/src/V3GraphDfa.cpp index f8fbd85cb..3914788b0 100644 --- a/src/V3GraphDfa.cpp +++ b/src/V3GraphDfa.cpp @@ -56,7 +56,7 @@ DfaVertex* DfaGraph::findStart() { // Algorithms - convert NFA to a DFA // Uses the Subset Construction Algorithm -class GraphNfaToDfa : GraphAlg { +class GraphNfaToDfa : GraphAlg<> { // We have two types of nodes in one graph, NFA and DFA nodes. // Edges from NFA to NFA come from the user, and indicate input or epsilon transitions // Edges from DFA to NFA indicate the NFA from which that DFA was formed. @@ -363,7 +363,7 @@ void DfaGraph::nfaToDfa() { // // Scan the DFA, cleaning up trailing states. -class DfaGraphReduce : GraphAlg { +class DfaGraphReduce : GraphAlg<> { private: // METHODS static int debug() { return 0; } @@ -505,7 +505,7 @@ void DfaGraph::dfaReduce() { // The user's old accept is now the new accept. This is imporant as // we want the virtual type of it to be intact. -class DfaGraphComplement : GraphAlg { +class DfaGraphComplement : GraphAlg<> { private: // MEMBERS DfaVertex* m_tempNewerReject;