Spicy
expression.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <list>
6 #include <utility>
7 
8 #include <hilti/ast/node.h>
9 #include <hilti/ast/type.h>
10 #include <hilti/base/type_erase.h>
11 
12 namespace hilti {
13 
14 namespace trait {
16 class isExpression : public isNode {};
17 } // namespace trait
18 
19 namespace expression {
20 namespace detail {
21 #include <hilti/autogen/__expression.h>
22 
24 inline Node to_node(Expression t) { return Node(std::move(t)); }
25 
27 inline std::ostream& operator<<(std::ostream& out, Expression e) { return out << to_node(std::move(e)); }
28 
29 inline bool operator==(const Expression& x, const Expression& y) {
30  if ( &x == &y )
31  return true;
32 
33  assert(x.isEqual(y) == y.isEqual(x)); // Expected to be symmetric.
34  return x.isEqual(y);
35 }
36 
37 inline bool operator!=(const Expression& e1, const Expression& e2) { return ! (e1 == e2); }
38 
39 } // namespace detail
40 
41 } // namespace expression
42 
43 using Expression = expression::detail::Expression;
44 using expression::detail::to_node;
45 
47 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isExpression, T>::value>* = nullptr>
48 inline Node to_node(T t) {
49  return Node(Expression(std::move(t)));
50 }
51 
52 } // namespace hilti
Definition: expression.h:16
Definition: node.h:97
Definition: node.h:19