Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 1 | //===-- Support/DotGraphTraits.h - Customize .dot output -------*- C++ -*--===// |
| 2 | // |
| 3 | // This file defines a template class that can be used to customize dot output |
| 4 | // graphs generated by the GraphWriter.h file. The default implementation of |
| 5 | // this file will produce a simple, but not very polished graph. By |
| 6 | // specializing this template, lots of customization opportunities are possible. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef SUPPORT_DOTGRAPHTRAITS_H |
| 11 | #define SUPPORT_DOTGRAPHTRAITS_H |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | /// DefaultDOTGraphTraits - This class provides the default implementations of |
| 16 | /// all of the DOTGraphTraits methods. If a specialization does not need to |
| 17 | /// override all methods here it should inherit so that it can get the default |
| 18 | /// implementations. |
| 19 | /// |
| 20 | struct DefaultDOTGraphTraits { |
| 21 | /// getGraphName - Return the label for the graph as a whole. Printed at the |
| 22 | /// top of the graph. |
| 23 | /// |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 24 | static std::string getGraphName(const void *Graph) { return ""; } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 25 | |
Chris Lattner | e981283 | 2002-10-10 22:29:10 +0000 | [diff] [blame] | 26 | /// getGraphProperties - Return any custom properties that should be included |
| 27 | /// in the top level graph structure for dot. By default, we resize the graph |
| 28 | /// to fit on a letter size page. |
| 29 | /// |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 30 | static std::string getGraphProperties(const void *Graph) { |
Chris Lattner | e981283 | 2002-10-10 22:29:10 +0000 | [diff] [blame] | 31 | return "\tsize=\"7.5,10\";\n"; // Size to fit on a page |
| 32 | } |
| 33 | |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 34 | /// getNodeLabel - Given a node and a pointer to the top level graph, return |
| 35 | /// the label to print in the node. |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 36 | static std::string getNodeLabel(const void *Node, const void *Graph) { |
| 37 | return ""; |
| 38 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 39 | |
| 40 | /// If you want to specify custom node attributes, this is the place to do so |
| 41 | /// |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 42 | static std::string getNodeAttributes(const void *Node) { return ""; } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 43 | |
| 44 | /// If you want to override the dot attributes printed for a particular edge, |
| 45 | /// override this method. |
| 46 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 47 | static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { |
| 48 | return ""; |
| 49 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 50 | |
| 51 | /// getEdgeSourceLabel - If you want to label the edge source itself, |
| 52 | /// implement this method. |
| 53 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 54 | static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) { |
| 55 | return ""; |
| 56 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 57 | |
| 58 | /// edgeTargetsEdgeSource - This method returns true if this outgoing edge |
| 59 | /// should actually target another edge source, not a node. If this method is |
| 60 | /// implemented, getEdgeTarget should be implemented. |
| 61 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 62 | static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) { |
| 63 | return false; |
| 64 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 65 | |
| 66 | /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is |
| 67 | /// called to determine which outgoing edge of Node is the target of this |
| 68 | /// edge. |
| 69 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 70 | static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) { |
| 71 | return I; |
| 72 | } |
Chris Lattner | 834a9d1 | 2002-10-16 01:44:59 +0000 | [diff] [blame] | 73 | |
| 74 | /// addCustomGraphFeatures - If a graph is made up of more than just |
| 75 | /// straight-forward nodes and edges, this is the place to put all of the |
| 76 | /// custom stuff neccesary. The GraphWriter object, instantiated with your |
| 77 | /// GraphType is passed in as an argument. You may call arbitrary methods on |
| 78 | /// it to add things to the output graph. |
| 79 | /// |
| 80 | template<typename GraphWriter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 81 | static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {} |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | |
| 85 | /// DOTGraphTraits - Template class that can be specialized to customize how |
| 86 | /// graphs are converted to 'dot' graphs. When specializing, you may inherit |
| 87 | /// from DefaultDOTGraphTraits if you don't need to override everything. |
| 88 | /// |
| 89 | template <typename Ty> |
| 90 | class DOTGraphTraits : public DefaultDOTGraphTraits {}; |
| 91 | |
| 92 | #endif |