summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/callgraph/parent-graph-visitor.cc
blob: f99121dd20d4ea23530255d97a1f2b20560b79ff (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
/**
 ** \file callgraph/parent-graph-visitor.cc
 ** \brief Implementation for callgraph::ParentGraphVisitor.
 **/

#include <ast/function-dec.hh>
#include <callgraph/parent-graph-visitor.hh>

namespace callgraph
{
  ParentGraph* ParentGraphVisitor::create(ast::Ast& tree)
  {
    // Create a new empty parentgraph
    parentgraph = new ParentGraph();

    // Launch visitor.
    tree.accept(*this);

    // Return created parentgraph.
    return parentgraph;
  }

  void ParentGraphVisitor::operator()(ast::FunctionChunk& e)
  {
    for (ast::FunctionDec* f : e)
      {
        parentgraph->fundec_add(f);
        parentgraph->fundec_link(f, parent);
      }
    super_type::operator()(e);
  }

  void ParentGraphVisitor::operator()(ast::FunctionDec& e)
  {
    // Current function becomes temporarily the parent function.
    ast::FunctionDec* tmp = parent;
    parent = &e;
    super_type::operator()(e);
    parent = tmp;
  }

} // namespace callgraph