summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/cast-exp.hh
blob: a73e7bb3a216171e2b494fcf61eb60de06e3d6dc (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
/**
 ** \file ast/cast-exp.hh
 ** \brief Declaration of ast::CastExp.
 */

#pragma once

#include <ast/exp.hh>
#include <ast/ty.hh>

namespace ast
{
  /** \class ast::CastExp
   ** \brief Cast the type of an expression to a given type.
   **
   ** This node is only used in the bounds checking transformation
   ** (see desugar::bounds_checks_add).  You don't need to worry
   ** about it (nor about the `cast' keyword) if you don't implement
   ** this option.
   */

  class CastExp : public Exp
  {
  public:
    /** \name Ctor & dtor.
     ** \{ */
    /// Construct a CastExp node.
    CastExp(const Location& location, Exp* exp, Ty* ty);
    CastExp(const CastExp&) = delete;
    CastExp& operator=(const CastExp&) = delete;
    /// Destroy a CastExp node.
    ~CastExp() override;
    /** \} */

    /// \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 cast expression.
    const Exp& exp_get() const;
    /// Return the cast expression.
    Exp& exp_get();
    /// Return the target type.
    const Ty& ty_get() const;
    /// Return the target type.
    Ty& ty_get();
    /** \} */

  protected:
    /// The cast expression.
    Exp* exp_;
    /// The target type.
    Ty* ty_;
  };
} // namespace ast
#include <ast/cast-exp.hxx>