HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_call_node.hpp
1// Copyright Take Vos 2020-2021.
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#include "../macros.hpp"
9
10hi_export_module(hikogui.formula.formula_call_node);
11
12namespace hi { inline namespace v1 {
13
16 formula_vector args;
17
18 formula_call_node(size_t line_nr, size_t column_nr, std::unique_ptr<formula_node> lhs, formula_node &rhs) :
19 formula_node(line_nr, column_nr), lhs(std::move(lhs))
20 {
21 auto &rhs_ = dynamic_cast<formula_arguments &>(rhs);
22 args = std::move(rhs_.args);
23 }
24
26 {
27 lhs->resolve_function_pointer(context);
28 for (auto &arg : args) {
29 arg->post_process(context);
30 }
31 }
32
34 {
35 hilet args_ = transform<datum::vector_type>(args, [&](hilet &x) {
36 return x->evaluate(context);
37 });
38
39 return lhs->call(context, args_);
40 }
41
43 {
45
46 try {
47 r.push_back(lhs->get_name());
48 } catch (parse_error const &e) {
49 throw parse_error(std::format("Function definition does not have a name, got {}\n{}", *lhs, e.what()));
50 }
51
52 for (hilet &arg : args) {
53 try {
54 r.push_back(arg->get_name());
55 } catch (parse_error const &e) {
56 throw parse_error(std::format("Definition of function {}() has a non-name argument {}\n{}", *lhs, *arg, e.what()));
57 }
58 }
59
60 return r;
61 }
62
63 std::string string() const noexcept override
64 {
65 auto s = std::format("({}(", *lhs);
66 int i = 0;
67 for (hilet &arg : args) {
68 if (i++ > 0) {
69 s += ',';
70 s += ' ';
71 }
72 s += to_string(*arg);
73 }
74 return s + "))";
75 }
76};
77
78}} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A dynamic data type.
Definition datum.hpp:212
A temporary node used during parsing.
Definition formula_arguments.hpp:16
Definition formula_call_node.hpp:14
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
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_call_node.hpp:33
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_call_node.hpp:25
Definition formula_evaluation_context.hpp:18
Definition formula_node.hpp:21
Definition formula_post_process_context.hpp:237
Exception thrown during parsing on an error.
Definition exception_intf.hpp:47
T move(T... args)
T push_back(T... args)
T what(T... args)