summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/overload/binder.hh
blob: 607debb97e5348bd121236283cb752492cb27713 (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
/**
 ** \file overload/binder.hh
 ** \brief Declaration of overload::Binder.
 **/

#pragma once

#include <map>

#include <bind/binder.hh>
#include <overload/over-table.hh>

namespace overload
{
  /// Type of the dictionary of potential function bindings.
  using overfun_bindings_type = std::multimap<ast::CallExp*, ast::FunctionDec*>;

  /** \brief Computing bindings with support for overloaded functions.
   **
   ** This visitor inherits from Binder, but redefines methods
   ** dealing with function declarations and uses, to allow
   ** overloading.
   **
   ** As overloading requires some knowledge of the type of the
   ** arguments of a function, no real function binding is done here.
   ** We store all potential function declarations (``homonyms'') for
   ** each function call, and we'll let the overload::TypeChecker
   ** decide later.
   **
   ** Inheritance is declared virtual to enable diamond inheritance with
   ** the combine::Binder (src/combine/binder.hh), inheriting from
   ** overload::Binder and object::Binder, both inheriting from bind::Binder.
   **/
  class Binder : virtual public bind::Binder
  {
  public:
    /// Super class type.
    using super_type = bind::Binder;
    /// Import all the overloaded operator() methods.
    using super_type::operator();

    /* The visiting methods. */
    /// Visit a function call.
    void operator()(ast::CallExp& e) override;

    /// Check a function declaration header.
    void visit_dec_header(ast::FunctionDec& e);
    /// Visit a chunk of function declarations.
    void operator()(ast::FunctionChunk& e) override;

    /// Return the function bindings.
    overfun_bindings_type& overfun_bindings_get();

    // FIXME: Some code was deleted here (Overload scope handling).
    /** \} */

  private:
    using overtable_type = OverTable<ast::FunctionDec>;
    /// The environment of (overloaded) functions.
    overtable_type overfuns_;
    /// The potential function bindings.
    overfun_bindings_type overfun_bindings_;
  };

} // namespace overload