Spicy
operand-list.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/declarations/parameter.h>
9 #include <hilti/ast/operator.h>
10 #include <hilti/ast/type.h>
11 
12 namespace hilti::type {
13 
20 class OperandList : public TypeBase {
21 public:
22  OperandList(std::vector<operator_::Operand> operands) : _operands(std::move(operands)) {}
23 
24  const auto& operands() const { return _operands; }
25 
27  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
29  auto _isResolved(ResolvedState* rstate) const { return true; }
31  auto properties() const { return node::Properties{}; }
32 
33  bool operator==(const OperandList& other) const { return operands() == other.operands(); }
34 
35  template<typename Container>
36  static OperandList fromParameters(const Container& params) {
37  std::vector<operator_::Operand> ops;
38 
39  for ( const auto& p : params ) {
40  operator_::Operand op = {p.id(), (p.isConstant() ? type::constant(p.type()) : p.type()),
41  p.default_().has_value(), p.default_()};
42 
43  ops.push_back(std::move(op));
44  }
45 
46  return type::OperandList(std::move(ops));
47  }
48 
49 private:
50  std::vector<operator_::Operand> _operands;
51 };
52 
53 } // namespace hilti::type
Definition: operand-list.h:20
Definition: operator.h:191
auto _isResolved(ResolvedState *rstate) const
Definition: operand-list.h:29
Definition: type.h:158
std::optional< ID > id
Definition: operator.h:206
auto isEqual(const Type &other) const
Definition: operand-list.h:27
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: type.h:197
auto properties() const
Definition: operand-list.h:31
Definition: type.h:25