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/unknown.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(std::move(operands)), std::move(meta)), _kind(op) {}
20 
21  auto kind() const { return _kind; }
22 
24  const auto& operands() const {
25  if ( _cache.operands.empty() )
26  _cache.operands = childs<Expression>(0, -1);
27 
28  return _cache.operands;
29  }
30 
31  bool operator==(const UnresolvedOperator& other) const {
32  return kind() == other.kind() && operands() == other.operands();
33  }
34 
37  // Dummy implementations as the node will be rejected in validation anyway.
38  bool isLhs() const { return false; }
40  bool isTemporary() const { return false; }
42  auto type() const { return type::unknown; }
44  auto isConstant() const { return false; }
46  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
47 
49  auto properties() const { return node::Properties{{"kind", to_string(_kind)}}; }
50 
51  void clearCache() { _cache.operands.clear(); }
52 
53 private:
54  operator_::Kind _kind;
55 
56  mutable struct { std::vector<Expression> operands; } _cache;
57 };
58 
59 } // namespace expression
60 } // namespace hilti
auto isConstant() const
Definition: unresolved-operator.h:44
Definition: unresolved-operator.h:16
Definition: expression.h:16
Definition: meta.h:18
bool isTemporary() const
Definition: unresolved-operator.h:40
const auto & operands() const
Definition: unresolved-operator.h:24
auto isEqual(const Expression &other) const
Definition: unresolved-operator.h:46
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
bool isLhs() const
Definition: unresolved-operator.h:38
auto properties() const
Definition: unresolved-operator.h:49
auto type() const
Definition: unresolved-operator.h:42
auto & meta() const
Definition: node.h:449
Definition: node.h:318