Spicy
expression.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <algorithm>
6 #include <list>
7 #include <utility>
8 #include <vector>
9 
10 #include <hilti/ast/node.h>
11 #include <hilti/ast/type.h>
12 #include <hilti/base/type_erase.h>
13 
14 namespace hilti {
15 
16 namespace trait {
18 class isExpression : public isNode {};
19 } // namespace trait
20 
21 namespace expression {
22 namespace detail {
23 #include <hilti/autogen/__expression.h>
24 
26 inline Node to_node(Expression t) { return Node(std::move(t)); }
27 
29 inline std::ostream& operator<<(std::ostream& out, Expression e) { return out << to_node(std::move(e)); }
30 
31 inline bool operator==(const Expression& x, const Expression& y) {
32  if ( &x == &y )
33  return true;
34 
35  assert(x.isEqual(y) == y.isEqual(x)); // Expected to be symmetric.
36  return x.isEqual(y);
37 }
38 
39 inline bool operator!=(const Expression& e1, const Expression& e2) { return ! (e1 == e2); }
40 
41 } // namespace detail
42 
49 bool isResolved(const detail::Expression& e, type::ResolvedState* rstate = nullptr);
50 
57 inline bool isResolved(const std::vector<detail::Expression>& exprs, type::ResolvedState* rstate = nullptr) {
58  return std::all_of(exprs.begin(), exprs.end(), [&](const auto& e) { return isResolved(e, rstate); });
59 }
60 
67 inline bool isResolved(const hilti::node::Range<detail::Expression>& exprs, type::ResolvedState* rstate = nullptr) {
68  return std::all_of(exprs.begin(), exprs.end(), [&](const auto& e) { return isResolved(e, rstate); });
69 }
70 
77 inline bool isResolved(const hilti::node::Set<detail::Expression>& exprs, type::ResolvedState* rstate = nullptr) {
78  return std::all_of(exprs.begin(), exprs.end(),
79  [&](const auto& e) { return type::detail::isResolved(e.type(), rstate); });
80 }
81 
82 } // namespace expression
83 
84 using Expression = expression::detail::Expression;
85 using expression::detail::to_node; // NOLINT(misc-unused-using-decls)
86 
88 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isExpression, T>::value>* = nullptr>
89 inline Node to_node(T t) {
90  return Node(Expression(std::move(t)));
91 }
92 
93 } // namespace hilti
Definition: node.h:37
Definition: expression.h:18
Definition: node.h:40
Definition: node.h:111
Definition: node.h:21