HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_call_node.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "formula_node.hpp"
8
9namespace tt {
10
13 formula_vector args;
14
16 parse_location location,
19 ) :
20 formula_node(std::move(location)), lhs(std::move(lhs))
21 {
22 auto rhs_ = dynamic_cast<formula_arguments*>(rhs.get());
23 tt_assert(rhs_ != nullptr);
24 args = std::move(rhs_->args);
25 }
26
28 lhs->resolve_function_pointer(context);
29 for (auto &arg: args) {
30 arg->post_process(context);
31 }
32 }
33
34 datum evaluate(formula_evaluation_context& context) const override {
35 ttlet args_ = transform<datum::vector>(args, [&](ttlet& x) {
36 return x->evaluate(context);
37 });
38
39 return lhs->call(context, args_);
40 }
41
44
45 try {
46 r.push_back(lhs->get_name());
47 } catch (parse_error const &e) {
48 throw parse_error("Function definition does not have a name, got {}\n{}", lhs, e.what());
49 }
50
51 for (ttlet &arg: args) {
52 try {
53 r.push_back(arg->get_name());
54 } catch (parse_error const &e) {
55 throw parse_error("Definition of function {}() has a non-name argument {}\n{}", lhs, arg, e.what());
56 }
57 }
58
59 return r;
60 }
61
62 std::string string() const noexcept override {
63 auto s = fmt::format("({}(", *lhs);
64 int i = 0;
65 for (ttlet &arg: args) {
66 if (i++ > 0) {
67 s += ',';
68 s += ' ';
69 }
70 s += to_string(*arg);
71 }
72 return s + "))";
73 }
74};
75
76}
Exception thrown during parsing on an error.
Definition exception.hpp:26
A temporary node used during parsing.
Definition formula_arguments.hpp:13
Definition formula_call_node.hpp:11
std::vector< std::string > get_name_and_argument_names() const override
Get name and argument names from a function declaration.
Definition formula_call_node.hpp:42
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_call_node.hpp:27
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_call_node.hpp:34
Definition formula_evaluation_context.hpp:16
Definition formula_node.hpp:19
Definition formula_post_process_context.hpp:18
Definition parse_location.hpp:16
T get(T... args)
T move(T... args)
T push_back(T... args)
T what(T... args)