13 #include <hilti/ast/ctors/integer.h> 14 #include <hilti/ast/ctors/string.h> 15 #include <hilti/ast/expression.h> 16 #include <hilti/ast/expressions/ctor.h> 17 #include <hilti/ast/node.h> 18 #include <hilti/base/logger.h> 19 #include <hilti/base/result.h> 20 #include <hilti/base/util.h> 21 #include <hilti/compiler/coercion.h> 22 #include <hilti/global.h> 48 :
NodeBase({std::move(v)}, std::move(m)), _tag(std::move(tag)) {}
51 const auto&
tag()
const {
return _tag; }
78 if ( !
value().isA<Expression>() )
81 return {
value().as<Expression>()};
88 if (
auto e =
value().tryAs<expression::Ctor>() )
99 if (
auto e =
value().tryAs<expression::Ctor>() ) {
104 return static_cast<int64_t
>(s->value());
113 bool operator==(
const Attribute& other)
const {
114 if ( _tag != other._tag )
119 return y && *x == *y;
122 else if (
auto x = valueAsString() ) {
123 auto y = other.valueAsString();
124 return y && *x == *y;
127 else if (
auto x = valueAsInteger() ) {
128 auto y = other.valueAsInteger();
129 return y && *x == *y;
172 for (
const auto& a : attributes() )
173 if ( a.tag() ==
tag )
187 for (
const auto& a : attributes() )
188 if ( a.tag() ==
tag )
204 if ( ! type::isResolved(dst) )
207 for (
auto& n :
childs() ) {
209 if ( a.tag() !=
tag )
212 if (
auto e = a.valueAsExpression() ) {
213 auto ne = coerceExpression(*e, dst);
218 n =
Attribute(tag, std::move(*ne.nexpr));
234 bool has(std::string_view tag)
const {
return find(tag).has_value(); }
242 operator bool()
const {
return !
childs().empty(); }
280 std::string_view tag) {
282 return attrs->find(tag);
296 return attrs->findAll(tag);
309 std::string_view tag) {
311 return attrs->findAll(tag);
323 static bool has(
const std::optional<AttributeSet>& attrs, std::string_view tag) {
325 return attrs->has(tag);
335 inline Node to_node(std::optional<AttributeSet>&& i) {
return i ? to_node(*i) :
node::none; }
Attribute(std::string tag, Node v, Meta m=Meta())
Definition: attribute.h:47
bool hasValue() const
Definition: attribute.h:54
static hilti::node::Set< Attribute > findAll(const hilti::optional_ref< const AttributeSet > &attrs, std::string_view tag)
Definition: attribute.h:308
const Node none
Definition: node.cc:14
Definition: optional.h:79
static hilti::node::Set< Attribute > findAll(const std::optional< const AttributeSet > &attrs, std::string_view tag)
Definition: attribute.h:294
void addChild(Node n)
Definition: node.h:459
AttributeSet(std::vector< Attribute > a, Meta m=Meta())
Definition: attribute.h:153
const Node & value() const
Definition: attribute.h:61
static hilti::optional_ref< const Attribute > find(const hilti::optional_ref< const AttributeSet > &attrs, std::string_view tag)
Definition: attribute.h:279
Definition: attribute.h:145
Definition: optional-ref.h:22
auto findAll(std::string_view tag) const
Definition: attribute.h:184
Attribute(std::string tag, Meta m=Meta())
Definition: attribute.h:37
std::string fmt(const char *fmt, const Args &... args)
Definition: util.h:80
hilti::optional_ref< const Attribute > find(std::string_view tag) const
Definition: attribute.h:171
Definition: attribute.h:27
auto properties() const
Definition: attribute.h:111
const auto & tag() const
Definition: attribute.h:51
static bool has(const std::optional< AttributeSet > &attrs, std::string_view tag)
Definition: attribute.h:323
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
AttributeSet(Meta m=Meta())
Definition: attribute.h:160
Result< bool > coerceValueTo(const std::string &tag, const Type &dst)
Definition: attribute.h:203
auto properties() const
Definition: attribute.h:237
Result< std::reference_wrapper< const Expression > > valueAsExpression() const
Definition: attribute.h:74
static AttributeSet add(std::optional< AttributeSet > s, Attribute a)
Definition: attribute.h:263
const auto & childs() const
Definition: node.h:470
static AttributeSet add(AttributeSet s, Attribute a)
Definition: attribute.h:251
auto & meta() const
Definition: node.h:474
bool has(std::string_view tag) const
Definition: attribute.h:234
auto attributes() const
Definition: attribute.h:163