10 #include <hilti/ast/declarations/local-variable.h> 11 #include <hilti/ast/expression.h> 12 #include <hilti/ast/expressions/id.h> 13 #include <hilti/ast/expressions/unresolved-operator.h> 14 #include <hilti/ast/statement.h> 22 using Default =
struct {};
36 Case(hilti::Expression expr, Statement body,
Meta m =
Meta())
37 :
NodeBase(nodes(std::move(body), std::move(expr)), std::move(m)), _end_exprs(2) {}
38 Case(std::vector<hilti::Expression> exprs, Statement body,
Meta m =
Meta())
39 :
NodeBase(nodes(std::move(body), std::move(exprs)), std::move(m)),
40 _end_exprs(static_cast<int>(
children().size())) {}
42 :
NodeBase(nodes(std::move(body)), std::move(m)), _end_exprs(1) {}
45 auto expressions()
const {
return children<hilti::Expression>(1, _end_exprs); }
46 auto preprocessedExpressions()
const {
return children<hilti::Expression>(_end_exprs, -1); }
47 const auto& body()
const {
return child<Statement>(0); }
49 bool isDefault()
const {
return expressions().empty(); }
57 bool operator==(
const Case& other)
const {
return expressions() == other.expressions() && body() == other.body(); }
62 void _preprocessExpressions(
const std::string&
id) {
64 children().reserve(static_cast<size_t>(_end_exprs) * 2);
66 for (
const auto& e : expressions() ) {
70 children().emplace_back(std::move(n));
77 inline Node to_node(
Case c) {
return Node(std::move(c)); }
84 Switch(hilti::Expression cond,
const std::vector<switch_::Case>& cases,
const Meta& m =
Meta())
88 :
NodeBase(nodes(cond, cases), std::move(m)) {
90 logger().internalError(
"initialization for 'switch' must be a local declaration");
95 auto cases()
const {
return children<switch_::Case>(1, -1); }
98 for (
const auto& c : children<switch_::Case>(1, -1) ) {
105 void preprocessCases() {
110 c->as<
switch_::Case>()._preprocessExpressions(condition().
id());
112 _preprocessed =
true;
115 bool operator==(
const Switch& other)
const {
116 return condition() == other.condition() && default_() == other.default_() && cases() == other.cases();
125 _preprocessed =
false;
129 auto isEqual(
const Statement& other)
const {
return node::isEqual(
this, other); }
135 bool _preprocessed =
false;
Definition: local-variable.h:18
auto isEqual(const Statement &other) const
Definition: switch.h:129
Definition: declaration.h:53
Definition: unresolved-operator.h:16
auto properties() const
Definition: switch.h:55
const auto & children() const
Definition: node.h:471
void addChild(Node n)
Definition: node.h:460
Definition: optional-ref.h:22
Definition: statement.h:14
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: node-ref.h:45
void _addCase(switch_::Case case_)
Definition: switch.h:123
auto & _bodyNode()
Definition: switch.h:52
auto & meta() const
Definition: node.h:475
auto properties() const
Definition: switch.h:132
auto & _lastCaseNode()
Definition: switch.h:120