summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/method.hh
blob: f9c3d8c03ceb0998633fa01d65f1d4ff51d05595 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 ** \file type/method.hh
 ** \brief The class Method.
 */
#pragma once

#include <ast/method-dec.hh>
#include <type/function.hh>

namespace type
{
  // Forward declaration.
  class Class;

  /** \brief Method types.
   **
   ** Encapsulate the signature of a method, i.e. the type structures
   ** of both method's arguments and its result.  */
  class Method : public Function
  {
    /// A shortcut for the super type of this class.
    using super_type = Function;

  public:
    /** \brief Construct a FunEntry.
     **
     ** \param name     The method's identifier.
     ** \param owner    The type::Class owning this method.
     ** \param formals  The type structures of formal arguments.
     ** \param result   The type structure of what method returns.
     ** \param def      The method's definition site.  */
    Method(misc::symbol name,
           const Class* owner,
           const Record* formals,
           const Type& result,
           ast::MethodDec* def);

    /** \brief Construct a FunEntry.
    **
    ** \param name     The method's identifier.
    ** \param formals  The type structures of formal arguments.
    ** \param result   The type structure of what method returns.
    ** \param def      The method's definition site.  */
    Method(misc::symbol name,
           const Record* formals,
           const Type& result,
           ast::MethodDec* def);

    /// \name Visitors entry point.
    /** \{ */
    /// Accept a const visitor \a v.
    void accept(ConstVisitor& v) const override;
    /// Accept a non-const visitor \a v.
    void accept(Visitor& v) override;
    /** \} */

    /** \name Accessors.
     ** \{ */
    /// Return the method's name.
    misc::symbol name_get() const;
    /// Return the method's owner (enclosing class).
    const Class* owner_get() const;
    /// Return the method's type.
    const Type& type_get() const;
    /// Return the method's definiton site.
    const ast::MethodDec* def_get() const;
    /// Return the method's definiton site.
    ast::MethodDec* def_get();

    /// Set the method's name.
    void name_set(misc::symbol name);
    /// set the method's definiton site.
    void def_set(ast::MethodDec* def);
    /** \} */

    // FIXME DONE: Some code was deleted here (Special implementation of "compatible_with" for type::Method).
    bool compatible_with(const Type& other) const override;

  private:
    /// Method's identifier.
    misc::symbol name_;
    /// The Class where this Method is defined.
    const Class* owner_;
    /// Method's definition site.
    ast::MethodDec* def_;
  };

} // namespace type

#include <type/method.hxx>