summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/callgraph/fundec-graph.hh
blob: 1addd0d102dd811b0669020f3325c25409b4737d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 ** \file callgraph/fundec-graph.hh
 ** \brief Declare and define fundec graph.
 */

#pragma once

#include <map>

#include <boost/graph/adjacency_list.hpp>

#include <ast/function-dec.hh>
#include <misc/graph.hh>

namespace callgraph
{
  /*--------------.
  | FundecGraph.  |
  `--------------*/

  class FundecGraph : public misc::directed_graph<ast::FunctionDec*>
  {
  public:
    /// Add a vertex to the graph, and attach a function definition to it.
    void fundec_add(ast::FunctionDec* f);
    /// Create an edge between two vertices, identified by the
    /// FunctionDec attached to each of them.
    void fundec_link(ast::FunctionDec* fu, ast::FunctionDec* fv);

    /// Retrieve the vertex handle corresponding to a FunctionDec.
    vertex_descriptor hfundec_get(ast::FunctionDec* f) const;

    // Search if FunctionDec 'searched' is 'start' or one of its parent.
    ast::FunctionDec* hfundec_deep_get(ast::FunctionDec* start,
                                       ast::FunctionDec* searched) const;

  protected:
    /// Print the label of vertex of a graph.
    std::ostream& vertex_print(vertex_descriptor v,
                               std::ostream& ostr) const override;

    using hfundecs_type = std::map<ast::FunctionDec*, vertex_descriptor>;

    hfundecs_type hfundecs;
  };

  using CallGraph = FundecGraph;
  using ParentGraph = FundecGraph;

  /*------------.
  | Iterators.  |
  `------------*/

  /// Iterator on the vertices of a FundecGraph.
  using fundecgraph_vertex_iter_type =
    boost::graph_traits<FundecGraph>::vertex_iterator;
  /// Iterator on the edges of a FundecGraph.
  using fundecgraph_edge_iter_type =
    boost::graph_traits<FundecGraph>::edge_iterator;
  /// Iterator on the neighborhood of a vertex of a FundecGraph.
  using fundecgraph_neighb_iter_type =
    boost::graph_traits<FundecGraph>::adjacency_iterator;

  /// \name Aliases.
  /// \{
  /// Iterator on the vertices of a CallGraph.
  using callgraph_vertex_iter_type = fundecgraph_vertex_iter_type;
  /// Iterator on the neighborhood of a vertex of a CallGraph.
  using callgraph_neighb_iter_type = fundecgraph_neighb_iter_type;
  /// Iterator on the neighborhood of a vertex of a ParentGraph.
  using parentgraph_neighb_iter_type = fundecgraph_neighb_iter_type;
  /// \}

} // namespace callgraph

#include <callgraph/fundec-graph.hxx>