summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/callgraph/fundec-graph.hxx
blob: d5d863e09eede34fcb35d5ed7ca2ca96f76c964b (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
/**
 ** \file callgraph/fundec-graph.hxx
 ** \brief Inline methods for callgraph/fundec-graph.hh.
 */

#pragma once

#include <callgraph/fundec-graph.hh>

namespace callgraph
{
  inline void FundecGraph::fundec_add(ast::FunctionDec* f)
  {
    hfundecs[f] = this->vertex_add(f);
  }

  inline void FundecGraph::fundec_link(ast::FunctionDec* fu,
                                       ast::FunctionDec* fv)
  {
    vertex_descriptor u = hfundecs[fu];
    vertex_descriptor v = hfundecs[fv];
    boost::add_edge(u, v, *this);
  }

  inline FundecGraph::vertex_descriptor
  FundecGraph::hfundec_get(ast::FunctionDec* f) const
  {
    hfundecs_type::const_iterator i = hfundecs.find(f);
    assertion(i != hfundecs.end());
    return i->second;
  }

  inline ast::FunctionDec*
  FundecGraph::hfundec_deep_get(ast::FunctionDec* start,
                                ast::FunctionDec* searched) const
  {
    if (start == searched)
      return searched;

    hfundecs_type::const_iterator i = hfundecs.find(start);
    parentgraph_neighb_iter_type parent =
      boost::adjacent_vertices(i->second, *this).first;

    if ((*this)[*parent] == start)
      return nullptr;

    return hfundec_deep_get((*this)[*parent], searched);
  }

  inline std::ostream& FundecGraph::vertex_print(vertex_descriptor v,
                                                 std::ostream& ostr) const
  {
    return ostr << (*this)[v]->name_get();
  }

} // namespace callgraph