Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.5 KiB

  1. //===-- llvm/ADT/GraphTraits.h - Graph traits template ----------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the little GraphTraits<X> template class that should be
  11. // specialized by classes that want to be iteratable by generic graph iterators.
  12. //
  13. // This file also defines the marker class Inverse that is used to iterate over
  14. // graphs in a graph defined, inverse ordering...
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_ADT_GRAPHTRAITS_H
  18. #define LLVM_ADT_GRAPHTRAITS_H
  19. namespace llvm {
  20. // GraphTraits - This class should be specialized by different graph types...
  21. // which is why the default version is empty.
  22. //
  23. template<class GraphType>
  24. struct GraphTraits {
  25. // Elements to provide:
  26. // typedef NodeType - Type of Node in the graph
  27. // typedef ChildIteratorType - Type used to iterate over children in graph
  28. // static NodeType *getEntryNode(const GraphType &)
  29. // Return the entry node of the graph
  30. // static ChildIteratorType child_begin(NodeType *)
  31. // static ChildIteratorType child_end (NodeType *)
  32. // Return iterators that point to the beginning and ending of the child
  33. // node list for the specified node.
  34. //
  35. // typedef ...iterator nodes_iterator;
  36. // static nodes_iterator nodes_begin(GraphType *G)
  37. // static nodes_iterator nodes_end (GraphType *G)
  38. // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
  39. // static unsigned size (GraphType *G)
  40. // Return total number of nodes in the graph
  41. //
  42. // If anyone tries to use this class without having an appropriate
  43. // specialization, make an error. If you get this error, it's because you
  44. // need to include the appropriate specialization of GraphTraits<> for your
  45. // graph, or you need to define it for a new graph type. Either that or
  46. // your argument to XXX_begin(...) is unknown or needs to have the proper .h
  47. // file #include'd.
  48. //
  49. typedef typename GraphType::UnknownGraphTypeError NodeType;
  50. };
  51. // Inverse - This class is used as a little marker class to tell the graph
  52. // iterator to iterate over the graph in a graph defined "Inverse" ordering.
  53. // Not all graphs define an inverse ordering, and if they do, it depends on
  54. // the graph exactly what that is. Here's an example of usage with the
  55. // df_iterator:
  56. //
  57. // idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
  58. // for (; I != E; ++I) { ... }
  59. //
  60. // Which is equivalent to:
  61. // df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
  62. // for (; I != E; ++I) { ... }
  63. //
  64. template <class GraphType>
  65. struct Inverse {
  66. const GraphType &Graph;
  67. inline Inverse(const GraphType &G) : Graph(G) {}
  68. };
  69. // Provide a partial specialization of GraphTraits so that the inverse of an
  70. // inverse falls back to the original graph.
  71. template<class T>
  72. struct GraphTraits<Inverse<Inverse<T> > > {
  73. typedef typename GraphTraits<T>::NodeType NodeType;
  74. typedef typename GraphTraits<T>::ChildIteratorType ChildIteratorType;
  75. static NodeType *getEntryNode(Inverse<Inverse<T> > *G) {
  76. return GraphTraits<T>::getEntryNode(G->Graph.Graph);
  77. }
  78. static ChildIteratorType child_begin(NodeType* N) {
  79. return GraphTraits<T>::child_begin(N);
  80. }
  81. static ChildIteratorType child_end(NodeType* N) {
  82. return GraphTraits<T>::child_end(N);
  83. }
  84. };
  85. } // End llvm namespace
  86. #endif