Spicy
function.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include <hilti/ast/expressions/id.h>
10 #include <hilti/ast/operators/common.h>
11 #include <hilti/ast/types/bool.h>
12 #include <hilti/ast/types/string.h>
13 
14 namespace hilti::operator_ {
15 OPERATOR_DECLARE_ONLY(function, Call)
16 }
17 
19 
21 public:
22  using hilti::expression::ResolvedOperatorBase::ResolvedOperatorBase;
23 
25  Operator(const Scope::Referee& r, const type::Function& ftype) {
26  auto op0 = operator_::Operand{{}, type::Any()}; // IDs won't be resolved
27  auto op1 = operator_::Operand{{}, type::OperandList::fromParameters(ftype.parameters())};
28  _referee = r;
29  _operands = {op0, op1};
30  _result = ftype.result().type();
31  }
32 
33  static operator_::Kind kind() { return operator_::Kind::Call; }
34  const std::vector<operator_::Operand>& operands() const { return _operands; }
35  Type result(const hilti::node::Range<Expression>& /* ops */) const { return _result; }
36  bool isLhs() const { return false; }
37  auto priority() const { return hilti::operator_::Priority::Normal; }
38  void validate(const expression::ResolvedOperator& /* i */, operator_::position_t /* p */) const {}
39  std::string doc() const { return "<dynamic - no doc>"; }
40  std::string docNamespace() const { return "<dynamic - no ns>"; }
41 
42  Expression instantiate(const std::vector<Expression>& operands, const Meta& meta) const {
43  auto ops = std::vector<Expression>{expression::ResolvedID(ID(_referee.qualified), NodeRef(_referee.node),
44  _referee.node->meta()),
45  operands[1]};
46 
47  auto ro = expression::ResolvedOperator(Call(*this, ops, meta));
48  ro.setMeta(meta);
49  return std::move(ro);
50  }
51 
52  private:
53  Scope::Referee _referee;
54  std::vector<operator_::Operand> _operands;
55  Type _result;
56  };
57 };
58 
59 } // namespace hilti::operator_::function
Definition: function.h:71
Definition: function.h:20
Definition: operator.h:191
Definition: node.h:37
Definition: visitor-types.h:28
Definition: operator-registry.h:15
NodeRef node
Definition: scope.h:41
Definition: operator.h:35
Definition: function.h:18
Definition: meta.h:19
Definition: type.h:158
std::string qualified
Definition: scope.h:42
Definition: any.h:12
Definition: resolved-operator.h:37
Definition: scope.h:40
void setMeta(Meta m)
Definition: node.h:477
Definition: node-ref.h:45
auto & meta() const
Definition: node.h:475
Definition: id.h:18