HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_name_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
12 std::string name;
14
15 formula_name_node(parse_location location, std::string_view name) :
16 formula_node(std::move(location)), name(name) {}
17
19 function = context.get_function(name);
20 if (!function) {
21 tt_error_info().set<"parse_location">(location);
22 throw parse_error("Could not find function {}()", name);
23 }
24 }
25
26 datum evaluate(formula_evaluation_context& context) const override {
27 ttlet &const_context = context;
28
29 try {
30 return const_context.get(name);
31 } catch (...) {
32 error_info(true).set<"parse_location">(location);
33 throw;
34 }
35 }
36
38 try {
39 return context.get(name);
40 } catch (...) {
41 error_info(true).set<"parse_location">(location);
42 throw;
43 }
44 }
45
46 bool has_evaluate_xvalue() const override {
47 return true;
48 }
49
52 datum const &evaluate_xvalue(formula_evaluation_context const& context) const override {
53 try {
54 return context.get(name);
55 } catch (...) {
56 error_info(true).set<"parse_location">(location);
57 throw;
58 }
59 }
60
61 datum &assign(formula_evaluation_context& context, datum const &rhs) const override {
62 try {
63 return context.set(name, rhs);
64 } catch (...) {
65 error_info(true).set<"parse_location">(location);
66 throw;
67 }
68 }
69
70 datum call(formula_evaluation_context& context, datum::vector const &arguments) const override {
71 return function(context, arguments);
72 }
73
74 std::string get_name() const noexcept override {
75 return name;
76 }
77
78 std::string string() const noexcept override {
79 return name;
80 }
81};
82
83}
Error information passed alongside an error code or exception.
Definition error_info.hpp:81
error_info & set(Arg &&value) noexcept
Set an information for a given tag.
Definition error_info.hpp:144
Exception thrown during parsing on an error.
Definition exception.hpp:21
Definition formula_evaluation_context.hpp:16
Definition formula_name_node.hpp:11
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_name_node.hpp:18
datum const & evaluate_xvalue(formula_evaluation_context const &context) const override
Evaluate an existing xvalue.
Definition formula_name_node.hpp:52
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_name_node.hpp:26
datum & assign(formula_evaluation_context &context, datum const &rhs) const override
Assign to a non-existing or existing lvalue.
Definition formula_name_node.hpp:61
datum call(formula_evaluation_context &context, datum::vector const &arguments) const override
Call a function with a datum::vector as arguments.
Definition formula_name_node.hpp:70
std::string get_name() const noexcept override
Get the name of a formula_name_node.
Definition formula_name_node.hpp:74
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_name_node.hpp:37
Definition formula_node.hpp:20
Definition formula_post_process_context.hpp:18
Definition parse_location.hpp:16
T move(T... args)