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 {
23 namespace unit {
24 namespace detail {
25 
26 #include <spicy/autogen/__unit-item.h>
27 
29 inline Node to_node(Item i) { return Node(std::move(i)); }
30 
32 inline std::ostream& operator<<(std::ostream& out, Item d) { return out << to_node(std::move(d)); }
33 
34 } // namespace detail
35 
36 using Item = detail::Item;
37 using detail::to_node;
38 
39 namespace item {
41 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isUnitItem, T>::value>* = nullptr>
42 inline Node to_node(T t) {
43  return Node(Item(std::move(t)));
44 }
45 
46 } // namespace item
47 } // namespace unit
48 } // namespace type
49 } // namespace spicy
50 
51 namespace spicy::type::unit::detail {
52 inline bool operator==(const Item& x, const Item& y) {
53  if ( &x == &y )
54  return true;
55 
56  assert(x.isEqual(y) == y.isEqual(x)); // Expected to be symmetric.
57  return x.isEqual(y);
58 }
59 } // namespace spicy::type::unit::detail
60 
61 inline bool operator!=(const spicy::type::unit::Item& d1, const spicy::type::unit::Item& d2) { return ! (d1 == d2); }
62 
63 inline bool operator!=(const std::vector<spicy::type::unit::Item>& t1, const std::vector<spicy::type::unit::Item>& t2) {
64  return ! (t1 == t2);
65 }
Definition: unit-item.h:24
Definition: node.h:113
Definition: unit-item.h:19
Definition: node.h:22