Spicy
unit-hook.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 <spicy/ast/aliases.h>
8 #include <spicy/ast/types/unit-item.h>
9 #include <spicy/ast/types/unit.h>
10 
11 namespace spicy::type::unit::item {
12 
15 public:
16  UnitHook(ID id, Hook hook, Meta m = Meta()) : NodeBase(nodes(id, std::move(hook)), std::move(m)) {
17  childs()[1].as<Hook>().setID(id);
18  }
19 
20  const auto& id() const { return child<ID>(0); }
21  const auto& hook() const { return child<Hook>(1); }
22  const auto& location() const { return childs()[0].location(); }
23 
24  bool operator==(const UnitHook& other) const { return id() == other.id() && hook() == other.hook(); }
25 
26  // Unit field interface
27  const Type& itemType() const { return hook().function().type(); }
28  bool isResolved() const { return type::isResolved(itemType()); }
29  auto isEqual(const Item& other) const { return node::isEqual(this, other); }
30 
31  // Node interface.
32  auto properties() const { return node::Properties{}; }
33 };
34 
35 } // namespace spicy::type::unit::item
NodeBase(Meta meta)
Definition: node.h:365
Definition: hook.h:29
Definition: meta.h:18
Definition: type.h:159
Definition: unit-hook.h:14
Definition: unit-item.h:19
const auto & childs() const
Definition: node.h:470
Definition: location.h:93
Definition: hook.h:22
Definition: id.h:18
Definition: node.h:358