[nest] Add 'AddNode' class (#701)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 18 Jul 2018 23:25:32 +0000 (08:25 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 18 Jul 2018 23:25:32 +0000 (08:25 +0900)
This commit adds 'AddNode' class under 'nest::expr' namespace, which
expressions the addition of two arithmetic values.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/nest/include/nest/Expr.h
contrib/nest/include/nest/expr/AddNode.h [new file with mode: 0644]
contrib/nest/include/nest/expr/Node.def
contrib/nest/src/expr/AddNode.test.cpp [new file with mode: 0644]

index aef73b3..9fc09cb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "nest/expr/VarNode.h"
 #include "nest/expr/DerefNode.h"
+#include "nest/expr/AddNode.h"
 
 #include <memory>
 
diff --git a/contrib/nest/include/nest/expr/AddNode.h b/contrib/nest/include/nest/expr/AddNode.h
new file mode 100644 (file)
index 0000000..b15d344
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef __NEST_EXPR_ADD_NODE_H__
+#define __NEST_EXPR_ADD_NODE_H__
+
+#include "nest/expr/Node.h"
+
+#include <memory>
+
+namespace nest
+{
+namespace expr
+{
+
+class AddNode final : public Node
+{
+public:
+  AddNode(const std::shared_ptr<expr::Node> &lhs, const std::shared_ptr<expr::Node> &rhs)
+      : _lhs{lhs}, _rhs{rhs}
+  {
+    // DO NOTHING
+  }
+
+public:
+  const AddNode *asAdd(void) const override { return this; }
+
+public:
+  const std::shared_ptr<expr::Node> &lhs(void) const { return _lhs; }
+  const std::shared_ptr<expr::Node> &rhs(void) const { return _rhs; }
+
+private:
+  std::shared_ptr<expr::Node> const _lhs;
+  std::shared_ptr<expr::Node> const _rhs;
+};
+
+} // namespace expr
+} // namespace nest
+
+#endif // __NEST_EXPR_ADD_NODE_H__
diff --git a/contrib/nest/src/expr/AddNode.test.cpp b/contrib/nest/src/expr/AddNode.test.cpp
new file mode 100644 (file)
index 0000000..0b2c778
--- /dev/null
@@ -0,0 +1,27 @@
+#include "nest/expr/AddNode.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+namespace
+{
+struct DummyNode final : public nest::expr::Node
+{
+};
+}
+
+TEST(ADD_NODE, cast)
+{
+  auto left = std::make_shared<DummyNode>();
+  auto right = std::make_shared<DummyNode>();
+
+  auto derived = std::make_shared<nest::expr::AddNode>(left, right);
+  std::shared_ptr<nest::expr::Node> base = derived;
+
+  ASSERT_NE(derived.get(), nullptr);
+  ASSERT_EQ(base->asAdd(), derived.get());
+
+  ASSERT_EQ(derived->lhs().get(), left.get());
+  ASSERT_EQ(derived->rhs().get(), right.get());
+}