summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/op-exp.hh
blob: 372650f8b155be779c38fdc25237a84f94918adc (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
 ** \file ast/op-exp.hh
 ** \brief Declaration of ast::OpExp.
 */

#pragma once

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

namespace ast
{
  /// OpExp.
  class OpExp : public Exp
  {
  public:
    /// Operator qualifier.
    enum class Oper
    {
      // Arithmetics.
      /** \brief "+" */ add,
      /** \brief "-" */ sub,
      /** \brief "*" */ mul,
      /** \brief "/" */ div,

      // Comparison.
      /** \brief "=" */ eq,
      /** \brief "<>" */ ne,
      /** \brief "<" */ lt,
      /** \brief "<=" */ le,
      /** \brief ">" */ gt,
      /** \brief ">=" */ ge
    };

  public:
    /** \name Ctor & dtor.
     ** \{ */
    /// Construct an OpExp node.
    OpExp(const Location& location, Exp* left, OpExp::Oper oper, Exp* right);
    OpExp(const OpExp&) = delete;
    OpExp& operator=(const OpExp&) = delete;
    /// Destroy an OpExp node.
    ~OpExp() 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 left operand.
    const Exp& left_get() const;
    /// Return left operand.
    Exp& left_get();
    /// Return operator.
    OpExp::Oper oper_get() const;
    /// Return right operand.
    const Exp& right_get() const;
    /// Return right operand.
    Exp& right_get();
    /** \} */

  protected:
    /// Left operand.
    Exp* left_;
    /// Operator.
    OpExp::Oper oper_;
    /// Right operand.
    Exp* right_;
  };
} // namespace ast

// Return a representation of an operator.
std::string str(ast::OpExp::Oper oper);
#include <ast/op-exp.hxx>