summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/nil.hh
blob: 4807ac0d24231bb4274f27f60f4c85e2aadc310c (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
/**
 ** \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