8 #include <hilti/ast/types/vector.h> 10 #include <spicy/ast/aliases.h> 11 #include <spicy/ast/engine.h> 12 #include <spicy/ast/types/unit-items/field.h> 13 #include <spicy/ast/types/unit.h> 22 Case(std::vector<Expression> exprs, std::vector<type::unit::Item> items,
Meta m =
Meta())
23 :
NodeBase(hilti::nodes(std::move(items), std::move(exprs)), std::move(m)) {}
35 auto expressions()
const {
return childsOfType<Expression>(); }
36 auto items()
const {
return childsOfType<type::unit::Item>(); }
37 auto itemRefs()
const {
return childRefsOfType<type::unit::Item>(); }
40 bool isDefault()
const {
return expressions().empty() && ! _look_ahead; }
47 for (
const auto& i : items() ) {
48 if ( ! i.isResolved() )
55 auto properties()
const {
return node::Properties{{
"default",
isDefault()}, {
"look-ahead",
isLookAhead()}}; }
57 bool operator==(
const Case& other)
const;
60 bool _look_ahead =
false;
63 inline Node to_node(
Case c) {
return Node(std::move(c)); }
70 Switch(std::optional<Expression> expr,
const std::vector<switch_::Case>& cases, Engine e,
71 std::optional<Expression> cond, std::vector<Hook> hooks, std::optional<AttributeSet> attributes,
73 : NodeBase(nodes(std::move(expr), std::move(cond), std::move(attributes), cases, std::move(hooks)),
77 Engine engine()
const {
return _engine; }
79 auto cases()
const {
return childsOfType<switch_::Case>(); }
80 auto condition()
const {
return childs()[1].tryAs<Expression>(); }
81 auto expression()
const {
return childs()[0].tryAs<Expression>(); }
82 auto hooks()
const {
return childsOfType<Hook>(); }
84 auto itemRefs()
const {
return childRefsOfType<type::unit::Item>(); }
87 bool hasNoFields()
const;
96 bool operator==(
const Switch& other)
const {
97 return expression() == other.expression() && engine() == other.engine() && condition() == other.condition() &&
98 cases() == other.cases() && hooks() == other.hooks();
102 const Type& itemType()
const {
return type::void_; }
105 for (
const auto& c : cases() ) {
106 if ( ! c.isResolved() )
113 auto isEqual(
const Item& other)
const {
return node::isEqual(
this, other); }
116 auto properties()
const {
return node::Properties{{
"engine", to_string(_engine)}}; }
NodeBase(Meta meta)
Definition: node.h:365
Case(std::vector< type::unit::Item > items, Meta m=Meta())
Definition: switch.h:26
Definition: optional.h:79
bool isResolved() const
Definition: switch.h:46
Definition: attribute.h:145
Definition: optional-ref.h:22
bool isDefault() const
Definition: switch.h:40
Case(type::unit::Item field, Meta m=Meta())
Definition: switch.h:30
bool isLookAhead() const
Definition: switch.h:43
Definition: unit-item.h:19
const auto & childs() const
Definition: node.h:470