9 #include <hilti/ast/declarations/local-variable.h> 10 #include <hilti/ast/expression.h> 11 #include <hilti/ast/expressions/id.h> 12 #include <hilti/ast/expressions/unresolved-operator.h> 13 #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)), _end_exprs(
childs().size()) {}
41 :
NodeBase(nodes(std::move(body)), std::move(m)), _end_exprs(1) {}
44 auto expressions()
const {
return childs<hilti::Expression>(1, _end_exprs); }
45 auto preprocessedExpressions()
const {
return childs<hilti::Expression>(_end_exprs, -1); }
46 const auto& body()
const {
return child<Statement>(0); }
48 bool isDefault()
const {
return expressions().empty(); }
56 bool operator==(
const Case& other)
const {
return expressions() == other.expressions() && body() == other.body(); }
61 void _preprocessExpressions(
const std::string&
id) {
63 childs().reserve(_end_exprs * 2);
65 for (
const auto& e : expressions() ) {
69 childs().emplace_back(std::move(n));
76 inline Node to_node(
Case c) {
return Node(std::move(c)); }
83 Switch(hilti::Expression cond,
const std::vector<switch_::Case>& cases,
Meta m =
Meta())
87 :
NodeBase(nodes(cond, cases), std::move(m)) {
89 logger().internalError(
"initialization for 'switch' must be a local declaration");
94 auto cases()
const {
return childs<switch_::Case>(1, -1); }
97 for (
const auto& c : childs<switch_::Case>(1, -1) ) {
104 void preprocessCases() {
108 for (
auto c =
childs().begin() + 1; c !=
childs().end(); c++ )
109 c->as<
switch_::Case>()._preprocessExpressions(condition().
id());
111 _preprocessed =
true;
114 bool operator==(
const Switch& other)
const {
115 return condition() == other.condition() && default_() == other.default_() && cases() == other.cases();
124 _preprocessed =
false;
128 auto isEqual(
const Statement& other)
const {
return node::isEqual(
this, other); }
134 bool _preprocessed =
false;
Definition: local-variable.h:19
auto isEqual(const Statement &other) const
Definition: switch.h:128
Definition: declaration.h:53
Definition: unresolved-operator.h:16
auto properties() const
Definition: switch.h:54
void addChild(Node n)
Definition: node.h:459
Definition: optional-ref.h:22
Definition: statement.h:14
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: node-ref.h:44
const auto & childs() const
Definition: node.h:470
void _addCase(switch_::Case case_)
Definition: switch.h:122
auto & _bodyNode()
Definition: switch.h:51
auto & meta() const
Definition: node.h:474
auto properties() const
Definition: switch.h:131
auto & _lastCaseNode()
Definition: switch.h:119