Spicy
property.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 
7 #include <hilti/ast/attribute.h>
8 
9 #include <spicy/ast/aliases.h>
10 #include <spicy/ast/types/unit-item.h>
11 #include <spicy/ast/types/unit.h>
12 
13 namespace spicy::type::unit::item {
14 
17 public:
18  Property(ID id, std::optional<AttributeSet> attrs = {}, bool inherited = false, Meta m = Meta())
19  : NodeBase(nodes(std::move(id), node::none, std::move(attrs)), std::move(m)), _inherited(inherited) {}
20 
21  Property(ID id, Expression expr, std::optional<AttributeSet> attrs = {}, bool inherited = false, Meta m = Meta())
22  : NodeBase(nodes(std::move(id), std::move(expr), std::move(attrs)), std::move(m)), _inherited(inherited) {}
23 
24  const auto& id() const { return child<ID>(0); }
25  auto expression() const { return childs()[1].tryReferenceAs<Expression>(); }
26  auto attributes() const { return childs()[2].tryReferenceAs<AttributeSet>(); }
27  bool interited() const { return _inherited; }
28 
29  bool operator==(const Property& other) const {
30  return id() == other.id() && expression() == other.expression() && attributes() == other.attributes();
31  }
32 
33  // Unit field interface
34  Type itemType() const { return type::Void(); }
35  auto isEqual(const Item& other) const { return node::isEqual(this, other); }
36 
37  // Node interface.
38  auto properties() const { return node::Properties{{"inherited", _inherited}}; }
39 
40 private:
41  bool _inherited;
42 };
43 
44 } // namespace spicy::type::unit::item
Definition: void.h:13
NodeBase(Meta meta)
Definition: node.h:325
auto & childs() const
Definition: node.h:445
Definition: property.h:16
Definition: meta.h:18
Definition: attribute.h:159
Definition: unit-item.h:19
Definition: unit-item.h:39
Definition: id.h:18
Definition: node.h:318