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 {
13 namespace type {
14 
21 class OperandList : public TypeBase {
22 public:
23  OperandList(std::vector<operator_::Operand> operands) : _operands(std::move(operands)) {}
24 
25  const auto& operands() const { return _operands; }
26 
28  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
30  auto _isResolved(ResolvedState* rstate) const { return true; }
32  auto properties() const { return node::Properties{}; }
33 
34  bool operator==(const OperandList& other) const { return operands() == other.operands(); }
35 
36  template<typename Container>
37  static OperandList fromParameters(const Container& params) {
38  std::vector<operator_::Operand> ops;
39 
40  for ( const auto& p : params ) {
41  operator_::Operand op = {.id = p.id(),
42  .type = (p.isConstant() ? type::constant(p.type()) : p.type()),
43  .optional = p.default_().has_value(),
44  .default_ = p.default_()};
45 
46  ops.push_back(std::move(op));
47  }
48 
49  return type::OperandList(std::move(ops));
50  }
51 
52 private:
53  std::vector<operator_::Operand> _operands;
54 };
55 
56 } // namespace type
57 } // namespace hilti
Definition: operand-list.h:21
Definition: operator.h:194
auto _isResolved(ResolvedState *rstate) const
Definition: operand-list.h:30
Definition: type.h:159
std::optional< ID > id
Definition: operator.h:195
auto isEqual(const Type &other) const
Definition: operand-list.h:28
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: type.h:198
auto properties() const
Definition: operand-list.h:32