7 #include <hilti/ast/declarations/local-variable.h> 8 #include <hilti/ast/expression.h> 9 #include <hilti/ast/statement.h> 10 #include <hilti/base/logger.h> 18 If(
const hilti::Declaration& init, std::optional<hilti::Expression> cond, Statement true_,
19 std::optional<Statement> false_,
Meta m =
Meta())
20 :
NodeBase(nodes(init, std::move(cond), std::move(true_), std::move(false_)), std::move(m)) {
22 logger().internalError(
"initialization for 'if' must be a local declaration");
25 If(hilti::Expression cond, Statement true_, std::optional<Statement> false_,
Meta m =
Meta())
26 :
NodeBase(nodes(
node::none, std::move(cond), std::move(true_), std::move(false_)), std::move(m)) {}
28 auto init()
const {
return childs()[0].tryReferenceAs<hilti::Declaration>(); }
29 auto condition()
const {
return childs()[1].tryReferenceAs<hilti::Expression>(); }
30 const auto& true_()
const {
return child<hilti::Statement>(2); }
31 auto false_()
const {
return childs()[3].tryReferenceAs<Statement>(); }
33 bool operator==(
const If& other)
const {
34 return init() == other.init() && condition() == other.condition() && true_() == other.true_() &&
35 false_() == other.false_();
45 auto isEqual(
const Statement& other)
const {
return node::isEqual(
this, other); }
57 static Statement
setInit(
const If& e,
const hilti::Declaration& d) {
58 auto x = Statement(e)._clone().as<
If>();
71 auto x = Statement(e)._clone().as<
If>();
Definition: local-variable.h:19
static Statement setCondition(const If &e, const hilti::Expression &c)
Definition: if.h:70
auto & childs() const
Definition: node.h:445
std::vector< T > childs(int begin, int end) const
Definition: node.h:373
auto properties() const
Definition: if.h:48
const Node none
Definition: node.cc:12
auto & _falseNode()
Definition: if.h:42
static Statement setInit(const If &e, const hilti::Declaration &d)
Definition: if.h:57
auto & _trueNode()
Definition: if.h:39
Definition: statement.h:14
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
auto isEqual(const Statement &other) const
Definition: if.h:45