summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/callgraph/call-graph-visitor.hh
blob: 97d79b4d660ba43b2548ef2c2cc783215690e4b7 (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
/**
 ** \file callgraph/call-graph-visitor.hh
 ** \brief Definition of callgraph::CallGraphVisitor.
 **/
#pragma once

#include <ast/default-visitor.hh>
#include <ast/non-assert-visitor.hh>
#include <ast/non-object-visitor.hh>
#include <callgraph/fundec-graph.hh>

namespace callgraph
{
  /// Computes the CallGraph.
  class CallGraphVisitor
    : protected ast::DefaultConstVisitor
    , protected ast::NonObjectConstVisitor
    , protected ast::NonAssertConstVisitor
  {
  public:
    using super_type = ast::DefaultConstVisitor;
    using super_type::operator();
    const CallGraph* create(const ast::Ast& tree);
    CallGraph* create(ast::Ast& tree);

  protected:
    void operator()(const ast::CallExp& e) override;
    void operator()(const ast::FunctionChunk& e) override;
    void operator()(const ast::FunctionDec& e) override;

  protected:
    /// Current function.
    ast::FunctionDec* caller = nullptr;
    /// Call graph.
    CallGraph* callgraph_ = nullptr;
  };

} // namespace callgraph