Spicy
unresolved-operator.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/expression.h>
9 #include <hilti/ast/operator.h>
10 #include <hilti/ast/types/auto.h>
11 
12 namespace hilti {
13 namespace expression {
14 
17 public:
18  UnresolvedOperator(operator_::Kind op, std::vector<Expression> operands, Meta meta = Meta())
19  : NodeBase(nodes(type::auto_, std::move(operands)), std::move(meta)), _kind(op) {}
20 
21  UnresolvedOperator(operator_::Kind op, hilti::node::Range<Expression> operands, Meta meta = Meta())
22  : NodeBase(nodes(type::auto_, std::move(operands)), std::move(meta)), _kind(op) {}
23 
24  auto kind() const { return _kind; }
25 
26  bool areOperandsResolved() const {
27  for ( auto op : childs<Expression>(1, -1) ) {
28  if ( ! type::isResolved(op.type()) )
29  return false;
30  }
31 
32  return true;
33  }
34 
35  bool operator==(const UnresolvedOperator& other) const {
36  return kind() == other.kind() && operands() == other.operands();
37  }
38 
40  hilti::node::Range<Expression> operands() const { return childs<Expression>(1, -1); }
41 
42  // Dummy implementations as the node will be rejected in validation anyway.
43 
45  bool isLhs() const { return false; }
47  bool isTemporary() const { return false; }
49  const auto& type() const { return child<Type>(0); }
51  auto isConstant() const { return false; }
53  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
54 
56  auto properties() const { return node::Properties{{"kind", to_string(_kind)}}; }
57 
58 private:
59  operator_::Kind _kind;
60 };
61 
62 } // namespace expression
63 } // namespace hilti
Definition: node.h:39
auto isConstant() const
Definition: unresolved-operator.h:51
hilti::node::Range< Expression > operands() const
Definition: unresolved-operator.h:40
Definition: unresolved-operator.h:16
Definition: expression.h:17
Definition: meta.h:18
const auto & type() const
Definition: unresolved-operator.h:49
bool isTemporary() const
Definition: unresolved-operator.h:47
auto isEqual(const Expression &other) const
Definition: unresolved-operator.h:53
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
bool isLhs() const
Definition: unresolved-operator.h:45
auto properties() const
Definition: unresolved-operator.h:56
auto & meta() const
Definition: node.h:474
Definition: node.h:358