summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/nil.hh
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/type/nil.hh')
-rw-r--r--tiger-compiler/src/type/nil.hh47
1 files changed, 47 insertions, 0 deletions
diff --git a/tiger-compiler/src/type/nil.hh b/tiger-compiler/src/type/nil.hh
new file mode 100644
index 0000000..4807ac0
--- /dev/null
+++ b/tiger-compiler/src/type/nil.hh
@@ -0,0 +1,47 @@
+/**
+ ** \file type/nil.hh
+ ** \brief The Nil type.
+ */
+#pragma once
+
+#include <type/fwd.hh>
+#include <type/type.hh>
+
+namespace type
+{
+ /*------.
+ | Nil. |
+ `------*/
+
+ class Record;
+
+ /// The builtin type of `nil'.
+ /// The Nil type is the type of a `nil` expression.
+ class Nil : public Type
+ {
+ public:
+ /// \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;
+ /** \} */
+
+ bool compatible_with(const Type& other) const override;
+
+ /// Get the associated record type.
+ const Type* record_type_get() const;
+
+ /// Set the record type used with the nil.
+ void record_type_set(const Type& type) const;
+
+ private:
+ /// The actual record_type that it represents.
+ /// Nil types are either compatible with `type::Record` or `type::Class`.
+ /// record_type represents the actual type that the `nil` was meant to be
+ /// used with.
+ mutable const Type* record_type_ = nullptr;
+ };
+
+} // namespace type