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
9namespace hi::inline v1 {
10
13 formula_vector args;
14
16 formula_node(std::move(location)), lhs(std::move(lhs))
17 {
18 auto &rhs_ = dynamic_cast<formula_arguments &>(rhs);
19 args = std::move(rhs_.args);
20 }
21
23 {
24 lhs->resolve_function_pointer(context);
25 for (auto &arg : args) {
26 arg->post_process(context);
27 }
28 }
29
30 datum evaluate(formula_evaluation_context &context) const override
31 {
32 hilet args_ = transform<datum::vector_type>(args, [&](hilet &x) {
33 return x->evaluate(context);
34 });
35
36 return lhs->call(context, args_);
37 }
38
40 {
42
43 try {
44 r.push_back(lhs->get_name());
45 } catch (parse_error const &e) {
46 throw parse_error(std::format("Function definition does not have a name, got {}\n{}", *lhs, e.what()));
47 }
48
49 for (hilet &arg : args) {
50 try {
51 r.push_back(arg->get_name());
52 } catch (parse_error const &e) {
53 throw parse_error(std::format("Definition of function {}() has a non-name argument {}\n{}", *lhs, *arg, e.what()));
54 }
55 }
56
57 return r;
58 }
59
60 std::string string() const noexcept override
61 {
62 auto s = std::format("({}(", *lhs);
63 int i = 0;
64 for (hilet &arg : args) {
65 if (i++ > 0) {
66 s += ',';
67 s += ' ';
68 }
69 s += to_string(*arg);
70 }
71 return s + "))";
72 }
73};
74
75} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
A dynamic data type.
Definition datum.hpp:219
A temporary node used during parsing.
Definition formula_arguments.hpp:13
Definition formula_call_node.hpp:11
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_call_node.hpp:22
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_call_node.hpp:30
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:39
Definition formula_evaluation_context.hpp:15
Definition formula_node.hpp:28
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:18
T move(T... args)
T push_back(T... args)