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