tcalc 0.2.0
 
Loading...
Searching...
No Matches
control_flow.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 IfNode : public Node
26{
27private:
28 NodePtr<> _cond;
29 NodePtr<> _then;
30 NodePtr<> _else;
31
32public:
38 : IfNode{ nullptr, nullptr, nullptr }
39 {
40 }
41
50 : Node{ NodeType::IF }
51 , _cond{ std::move(cond) }
52 , _then{ std::move(then) }
53 , _else{ std::move(else_) }
54 {
55 }
56
57 ~IfNode() override = default;
58
64 [[nodiscard]] TCALC_INLINE auto& cond() const noexcept { return _cond; }
65
71 TCALC_INLINE auto& cond() noexcept { return _cond; }
72
78 TCALC_INLINE void cond(NodePtr<> cond) noexcept { _cond = std::move(cond); }
79
85 [[nodiscard]] TCALC_INLINE auto& then() const noexcept { return _then; }
86
92 TCALC_INLINE auto& then() noexcept { return _then; }
93
99 TCALC_INLINE void then(NodePtr<> then) noexcept { _then = std::move(then); }
100
106 [[nodiscard]] TCALC_INLINE auto& else_() const noexcept { return _else; }
107
113 TCALC_INLINE auto& else_() noexcept { return _else; }
114
120 TCALC_INLINE void else_(NodePtr<> else_) noexcept
121 {
122 _else = std::move(else_);
123 }
124};
125
126}
If node.
Definition control_flow.hpp:26
TCALC_INLINE auto & cond() const noexcept
Get the condition node.
Definition control_flow.hpp:64
TCALC_INLINE auto & then() const noexcept
Get the then node.
Definition control_flow.hpp:85
TCALC_INLINE void then(NodePtr<> then) noexcept
Set the then node.
Definition control_flow.hpp:99
TCALC_INLINE void cond(NodePtr<> cond) noexcept
Set the condition node.
Definition control_flow.hpp:78
TCALC_INLINE auto & cond() noexcept
Get the condition node.
Definition control_flow.hpp:71
TCALC_INLINE auto & then() noexcept
Get the then node.
Definition control_flow.hpp:92
TCALC_INLINE auto & else_() noexcept
Get the else node.
Definition control_flow.hpp:113
IfNode(NodePtr<> cond, NodePtr<> then, NodePtr<> else_)
Construct a new If Node object with nodes.
Definition control_flow.hpp:49
TCALC_INLINE auto & else_() const noexcept
Get the else node.
Definition control_flow.hpp:106
TCALC_INLINE void else_(NodePtr<> else_) noexcept
Set the else node.
Definition control_flow.hpp:120
IfNode()
Construct a new If Node object without nodes.
Definition control_flow.hpp:37
Base class for AST nodes.
Definition node.hpp:87
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