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 While(
const hilti::Declaration& init, std::optional<hilti::Expression> cond, Statement body,
19 std::optional<Statement> else_ = {},
Meta m =
Meta())
20 :
NodeBase(nodes(init, std::move(cond), std::move(body), std::move(else_)), std::move(m)) {
22 logger().internalError(
"initialization for 'while' must be a local declaration");
25 While(hilti::Expression cond, Statement body,
Meta m =
Meta())
28 While(hilti::Expression cond, Statement body, std::optional<Statement> else_,
Meta m =
Meta())
29 :
NodeBase(nodes(
node::none, std::move(cond), std::move(body), std::move(else_)), std::move(m)) {}
31 auto init()
const {
return childs()[0].tryReferenceAs<hilti::Declaration>(); }
32 auto condition()
const {
return childs()[1].tryReferenceAs<hilti::Expression>(); }
33 const auto& body()
const {
return child<hilti::Statement>(2); }
34 auto else_()
const {
return childs()[3].tryReferenceAs<Statement>(); }
36 bool operator==(
const While& other)
const {
37 return init() == other.init() && condition() == other.condition() && body() == other.body() &&
38 else_() == other.else_();
48 auto isEqual(
const Statement& other)
const {
return node::isEqual(
this, other); }
60 static Statement
setInit(
const While& e,
const hilti::Declaration& d) {
61 auto x = Statement(e)._clone().as<
While>();
74 auto x = Statement(e)._clone().as<
While>();
Definition: local-variable.h:19
auto & childs() const
Definition: node.h:445
std::vector< T > childs(int begin, int end) const
Definition: node.h:373
const Node none
Definition: node.cc:12
auto isEqual(const Statement &other) const
Definition: while.h:48
auto & _bodyNode()
Definition: while.h:42
Definition: statement.h:14
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
static Statement setCondition(const While &e, const hilti::Expression &c)
Definition: while.h:73
static Statement setInit(const While &e, const hilti::Declaration &d)
Definition: while.h:60
auto & _elseNode()
Definition: while.h:45
auto properties() const
Definition: while.h:51