tcalc 0.2.0
 
Loading...
Searching...
No Matches
binaryop.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <utility>
15
16#include "tcalc/ast/node.hpp"
17#include "tcalc/common.hpp"
18
19namespace tcalc::ast {
20
25class BinaryOpNode : public Node
26{
27private:
28 NodePtr<> _left;
29 NodePtr<> _right;
30
31public:
38 : BinaryOpNode{ type, nullptr, nullptr }
39 {
40 }
41
50 : Node{ type }
51 , _left{ std::move(left) }
52 , _right{ std::move(right) }
53 {
54 }
55
56 ~BinaryOpNode() override = default;
57
63 [[nodiscard]] TCALC_INLINE auto& left() const noexcept { return _left; }
64
70 TCALC_INLINE auto& left() noexcept { return _left; }
71
77 TCALC_INLINE void left(NodePtr<> left) noexcept { _left = std::move(left); }
78
84 [[nodiscard]] TCALC_INLINE auto& right() const noexcept { return _right; }
85
91 TCALC_INLINE auto& right() noexcept { return _right; }
92
98 TCALC_INLINE void right(NodePtr<> right) noexcept
99 {
100 _right = std::move(right);
101 }
102};
103
104}
Binary operation base class.
Definition binaryop.hpp:26
TCALC_INLINE void right(NodePtr<> right) noexcept
Set the right subnode.
Definition binaryop.hpp:98
TCALC_INLINE void left(NodePtr<> left) noexcept
Set the left subnode.
Definition binaryop.hpp:77
BinaryOpNode(NodeType type)
Construct a new Binary Op Node object with no subnodes.
Definition binaryop.hpp:37
TCALC_INLINE auto & left() noexcept
Get the left subnode.
Definition binaryop.hpp:70
TCALC_INLINE auto & right() noexcept
Get the right subnode.
Definition binaryop.hpp:91
BinaryOpNode(NodeType type, NodePtr<> left, NodePtr<> right)
Construct a new Binary Op Node object with subnodes.
Definition binaryop.hpp:49
TCALC_INLINE auto & right() const noexcept
Get the right subnode.
Definition binaryop.hpp:84
TCALC_INLINE auto & left() const noexcept
Get the left subnode.
Definition binaryop.hpp:63
Base class for AST nodes.
Definition node.hpp:87
TCALC_INLINE auto type() const noexcept
Get the node type.
Definition node.hpp:109
tcalc common header.
Base class for AST nodes.
std::shared_ptr< NT > NodePtr
Shared pointer to a node.
Definition node.hpp:119
NodeType
AST node type.
Definition node.hpp:30