summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/op-exp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/ast/op-exp.cc')
-rw-r--r--tiger-compiler/src/ast/op-exp.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/tiger-compiler/src/ast/op-exp.cc b/tiger-compiler/src/ast/op-exp.cc
new file mode 100644
index 0000000..6db4940
--- /dev/null
+++ b/tiger-compiler/src/ast/op-exp.cc
@@ -0,0 +1,42 @@
+/**
+ ** \file ast/op-exp.cc
+ ** \brief Implementation of ast::OpExp.
+ */
+
+#include <ast/op-exp.hh>
+#include <ast/visitor.hh>
+
+namespace ast
+{
+ OpExp::OpExp(const Location& location,
+ Exp* left,
+ OpExp::Oper oper,
+ Exp* right)
+ : Exp(location)
+ , left_(left)
+ , oper_(oper)
+ , right_(right)
+ {}
+
+ OpExp::~OpExp()
+ {
+ delete left_;
+ delete right_;
+ }
+
+ void OpExp::accept(ConstVisitor& v) const { v(*this); }
+
+ void OpExp::accept(Visitor& v) { v(*this); }
+} // namespace ast
+
+std::string str(ast::OpExp::Oper oper)
+{
+ static const std::unordered_map<ast::OpExp::Oper, std::string> op_str = {
+ {ast::OpExp::Oper::add, "+"}, {ast::OpExp::Oper::sub, "-"},
+ {ast::OpExp::Oper::mul, "*"}, {ast::OpExp::Oper::div, "/"},
+ {ast::OpExp::Oper::eq, "="}, {ast::OpExp::Oper::ne, "<>"},
+ {ast::OpExp::Oper::lt, "<"}, {ast::OpExp::Oper::le, "<="},
+ {ast::OpExp::Oper::gt, ">"}, {ast::OpExp::Oper::ge, ">="}};
+
+ return op_str.at(oper);
+}