summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/bind/renamer.hh
blob: f4a1e82cd6adf4af5dbc68cd6c2e73194c6c6b59 (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
/**
 ** \file bind/renamer.hh
 ** \brief Implementation of bind::Renamer.
 */

#pragma once

#include <map>
#include <ast/default-visitor.hh>
#include <ast/non-assert-visitor.hh>
#include <ast/non-object-visitor.hh>

namespace bind
{
  /// Perform identifier renaming within an AST (in place),
  /// without support for objects.
  class Renamer
    : public ast::DefaultVisitor
    , public ast::NonObjectVisitor
    , public ast::NonAssertVisitor
  {
  public:
    using super_type = ast::DefaultVisitor;

    // Import overloaded virtual functions.
    using super_type::operator();

    // FIXME DONE: Some code was deleted here.

    // Visit methods.
    /// \brief Process a declaration body or a usage site.
    ///
    /// \a def is the definition site of \e (must be equal to
    /// \a e if it is a Dec node).
    template <class E, class Def> void visit(E& e, const Def* def);

    /// \name Visiting definition sites.
    /// \{
    // FIXME DONE: Some code was deleted here.
    void operator()(ast::VarDec& e) override;
    void operator()(ast::TypeDec& e) override;
    void operator()(ast::FunctionDec& e) override;
    /// \}

    /// \name Visiting usage sites.
    /// \{
    // FIXME DONE: Some code was deleted here.
    void operator()(ast::SimpleVar& e) override;
    void operator()(ast::NameTy& e) override;
    void operator()(ast::CallExp& e) override;
    /// \}

  private:
    // FIXME DONE: Some code was deleted here.
    std::map<const ast::Dec*, misc::symbol> renames_;

    void new_name_(const ast::Dec*);
  };

} // namespace bind

#include <bind/renamer.hxx>