9 #include <hilti/ast/declarations/expression.h> 10 #include <hilti/ast/expressions/keyword.h> 11 #include <hilti/ast/types/vector.h> 12 #include <hilti/base/uniquer.h> 13 #include <hilti/base/util.h> 15 #include <spicy/ast/aliases.h> 16 #include <spicy/ast/engine.h> 17 #include <spicy/ast/types/unit-item.h> 24 Field(
const std::optional<ID>&
id,
Type type, Engine e,
const std::vector<Expression>& args,
25 std::optional<Expression> repeat,
const std::vector<Expression>& sinks,
26 std::optional<AttributeSet> attrs = {}, std::optional<Expression> cond = {},
27 const std::vector<Hook>& hooks = {},
Meta m =
Meta())
28 :
NodeBase(nodes((
id ?
id : _uniquer.get(
"anon")), hilti::type::pruneWalk(std::move(type)), hilti::type::auto_,
29 hilti::node::none, hilti::type::auto_, node::none, std::move(repeat), std::move(attrs),
30 std::move(cond), args, sinks, hooks),
32 _is_forwarding(
false),
33 _is_transient(!
id.has_value()),
36 _args_end(_args_start + static_cast<int>(args.size())),
37 _sinks_start(_args_end),
38 _sinks_end(_sinks_start + static_cast<int>(sinks.size())),
39 _hooks_start(_sinks_end),
40 _hooks_end(_hooks_start + static_cast<int>(hooks.size())) {}
42 Field(
const std::optional<ID>&
id, Ctor ctor, Engine e,
const std::vector<Expression>& args,
43 std::optional<Expression> repeat,
const std::vector<Expression>& sinks,
44 std::optional<AttributeSet> attrs = {}, std::optional<Expression> cond = {},
45 const std::vector<Hook>& hooks = {},
Meta m =
Meta())
47 hilti::type::auto_, std::move(ctor), std::move(repeat), std::move(attrs), std::move(cond),
50 _is_forwarding(
false),
51 _is_transient(!
id.has_value()),
54 _args_end(_args_start + static_cast<int>(args.size())),
55 _sinks_start(_args_end),
56 _sinks_end(_sinks_start + static_cast<int>(sinks.size())),
57 _hooks_start(_sinks_end),
58 _hooks_end(_hooks_start + static_cast<int>(hooks.size())) {}
60 Field(
const std::optional<ID>&
id, Item item, Engine e,
const std::vector<Expression>& args,
61 std::optional<Expression> repeat,
const std::vector<Expression>& sinks,
62 std::optional<AttributeSet> attrs = {}, std::optional<Expression> cond = {},
63 const std::vector<Hook>& hooks = {},
const Meta& m =
Meta())
65 hilti::type::auto_, std::move(item), std::move(repeat), std::move(attrs), std::move(cond),
68 _is_forwarding(
false),
69 _is_transient(!
id.has_value()),
72 _args_end(_args_start + static_cast<int>(args.size())),
73 _sinks_start(_args_end),
74 _sinks_end(_sinks_start + static_cast<int>(sinks.size())),
75 _hooks_start(_sinks_end),
76 _hooks_end(_hooks_start + static_cast<int>(hooks.size())) {}
78 Field(
const std::optional<ID>&
id,
NodeRef type, Engine e,
const std::vector<Expression>& args,
79 std::optional<Expression> repeat,
const std::vector<Expression>& sinks,
80 std::optional<AttributeSet> attrs = {}, std::optional<Expression> cond = {},
81 const std::vector<Hook>& hooks = {},
const Meta& m =
Meta())
83 hilti::type::auto_, node::none, std::move(repeat), std::move(attrs), std::move(cond), args,
86 _type(std::move(type)),
87 _is_forwarding(
false),
88 _is_transient(!
id.has_value()),
91 _args_end(_args_start + static_cast<int>(args.size())),
92 _sinks_start(_args_end),
93 _sinks_end(_sinks_start + static_cast<int>(sinks.size())),
94 _hooks_start(_sinks_end),
95 _hooks_end(_hooks_start + static_cast<int>(hooks.size())) {
104 const auto& id()
const {
return children()[0].as<
ID>(); }
105 auto index()
const {
return _index; }
106 auto ctor()
const {
return children()[5].tryAs<Ctor>(); }
107 auto item()
const {
return children()[5].tryAs<Item>(); }
109 auto repeatCount()
const {
return children()[6].tryAs<Expression>(); }
111 auto condition()
const {
return children()[8].tryAs<Expression>(); }
112 auto arguments()
const {
return children<Expression>(_args_start, _args_end); }
113 auto sinks()
const {
return children<Expression>(_sinks_start, _sinks_end); }
114 auto hooks()
const {
return children<Hook>(_hooks_start, _hooks_end); }
115 Engine engine()
const {
return _engine; }
117 bool isContainer()
const {
return repeatCount().has_value(); }
118 bool isForwarding()
const {
return _is_forwarding; }
119 bool isTransient()
const {
return _is_transient; }
120 bool emitHook()
const {
return ! isTransient() || hooks().size(); }
122 const Type& originalType()
const {
126 if (
auto t =
children()[1].tryAs<Type>() )
129 if (
auto c = ctor() )
132 if (
auto i = item() )
133 return i->itemType();
135 hilti::util::cannot_be_reached();
142 const Type& ddType()
const {
143 if (
auto x =
children()[3].tryAs<hilti::declaration::Expression>() )
144 return x->expression().type();
146 return hilti::type::auto_;
150 if (
children()[3].isA<Declaration>() )
159 std::optional<std::pair<const Expression, std::optional<const Type>>> convertExpression()
const;
161 void setForwarding(
bool is_forwarding) { _is_forwarding = is_forwarding; }
163 void setIndex(uint64_t index) { _index = index; }
164 void setItemType(
Type t) {
children()[4] = hilti::type::pruneWalk(std::move(t)); }
165 void setParseType(
Type t) {
children()[2] = hilti::type::pruneWalk(std::move(t)); }
167 bool operator==(
const Field& other)
const {
168 return _engine == other._engine && id() == other.id() && originalType() == other.originalType() &&
169 itemType() == other.itemType() && parseType() == other.parseType() &&
170 attributes() == other.attributes() && arguments() == other.arguments() && sinks() == other.sinks() &&
171 condition() == other.condition() && hooks() == other.hooks();
174 Field& operator=(
const Field& other) =
default;
178 bool isResolved()
const {
return _type || item() || type::isResolved(itemType()); }
179 auto isEqual(
const Item& other)
const {
return node::isEqual(
this, other); }
182 auto properties()
const {
183 return node::Properties{{
"engine", to_string(_engine)},
184 {
"transient", _is_transient},
185 {
"forwarding", _is_forwarding}};
189 std::optional<NodeRef> _type;
190 std::optional<uint64_t> _index;
NodeBase(Meta meta)
Definition: node.h:366
const Node none
Definition: node.cc:14
const auto & children() const
Definition: node.h:471
static Declaration createDollarDollarDeclaration(Type t)
Definition: keyword.h:63
Definition: attribute.h:145
Definition: node-ref.h:45
Definition: unit-item.h:19