summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/method.hh
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/type/method.hh')
-rw-r--r--tiger-compiler/src/type/method.hh90
1 files changed, 90 insertions, 0 deletions
diff --git a/tiger-compiler/src/type/method.hh b/tiger-compiler/src/type/method.hh
new file mode 100644
index 0000000..f9c3d8c
--- /dev/null
+++ b/tiger-compiler/src/type/method.hh
@@ -0,0 +1,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>