summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/op-exp.hh
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/ast/op-exp.hh
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/ast/op-exp.hh')
-rw-r--r--tiger-compiler/src/ast/op-exp.hh80
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>