diff options
Diffstat (limited to 'tiger-compiler/src/ast/op-exp.hh')
| -rw-r--r-- | tiger-compiler/src/ast/op-exp.hh | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tiger-compiler/src/ast/op-exp.hh b/tiger-compiler/src/ast/op-exp.hh new file mode 100644 index 0000000..372650f --- /dev/null +++ b/tiger-compiler/src/ast/op-exp.hh @@ -0,0 +1,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> |
