summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/method.cc
blob: 57269485f6424f1011ec2d6f7526ea7811627ba6 (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
/**
 ** \file type/method.cc
 ** \brief Implementation for type/method.hh.
 */

#include <iostream>

#include <type/method.hh>
#include <type/visitor.hh>

namespace type
{
  Method::Method(misc::symbol name,
                 const Class* owner,
                 const Record* formals,
                 const Type& result,
                 ast::MethodDec* def)
    : Function(formals, result)
    , name_(name)
    , owner_(owner)
    , def_(def)
  {}

  Method::Method(misc::symbol name,
                 const Record* formals,
                 const Type& result,
                 ast::MethodDec* def)
    : Function(formals, result)
    , name_(name)
    , owner_(nullptr)
    , def_(def)
  {}

  void Method::accept(ConstVisitor& v) const { v(*this); }

  void Method::accept(Visitor& v) { v(*this); }

  // FIXME DONE: Some code was deleted here.
  bool Method::compatible_with(const Type& other) const
  {
    const auto other_method = dynamic_cast<const Method*>(&other);

    return other_method != nullptr \
      && other_method->formals_get().compatible_with(other) \
      && other_method->result_get().compatible_with(other);
  }

} // namespace type