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 children()[1].tryAs<Expression>(); }
26  auto attributes() const { return children()[2].tryAs<AttributeSet>(); }
27  bool inherited() 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  const Type& itemType() const { return type::void_; }
35  bool isResolved() const { return type::isResolved(itemType()); }
36  auto isEqual(const Item& other) const { return node::isEqual(this, other); }
37 
38  // Node interface.
39  auto properties() const { return node::Properties{{"inherited", _inherited}}; }
40 
41 private:
42  bool _inherited;
43 };
44 
45 } // namespace spicy::type::unit::item
NodeBase(Meta meta)
Definition: node.h:367
const auto & children() const
Definition: node.h:472
Definition: property.h:16
Definition: meta.h:19
Definition: attribute.h:174
Definition: type.h:160
Definition: unit-item.h:19
Definition: hook.h:22
Definition: id.h:18
Definition: node.h:360