Spicy
unit-item.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 #include <vector>
7 
8 #include <hilti/ast/attribute.h>
9 #include <hilti/ast/expression.h>
10 #include <hilti/ast/id.h>
11 #include <hilti/ast/type.h>
12 
13 #include <spicy/ast/hook.h>
14 
15 namespace spicy {
16 
17 namespace trait {
19 class isUnitItem : public hilti::trait::isNode {};
20 } // namespace trait
21 
22 namespace type::unit {
23 namespace detail {
24 
25 #include <spicy/autogen/__unit-item.h>
26 
28 inline Node to_node(Item i) { return Node(std::move(i)); }
29 
31 inline std::ostream& operator<<(std::ostream& out, Item d) { return out << to_node(std::move(d)); }
32 
33 } // namespace detail
34 
35 using Item = detail::Item;
36 
37 namespace item {
39 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isUnitItem, T>::value>* = nullptr>
40 inline Node to_node(T t) {
41  return Node(Item(std::move(t)));
42 }
43 
44 } // namespace item
45 } // namespace type::unit
46 } // namespace spicy
47 
48 namespace spicy::type::unit::detail {
49 inline bool operator==(const Item& x, const Item& y) {
50  if ( &x == &y )
51  return true;
52 
53  assert(x.isEqual(y) == y.isEqual(x)); // Expected to be symmetric.
54  return x.isEqual(y);
55 }
56 } // namespace spicy::type::unit::detail
57 
58 inline bool operator!=(const spicy::type::unit::Item& d1, const spicy::type::unit::Item& d2) { return ! (d1 == d2); }
59 
60 inline bool operator!=(const std::vector<spicy::type::unit::Item>& t1, const std::vector<spicy::type::unit::Item>& t2) {
61  return ! (t1 == t2);
62 }
Definition: unit-item.h:23
Definition: node.h:112
Definition: unit-item.h:19
Definition: node.h:21