HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_member_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_binary_operator_node.hpp"
8
9namespace tt {
10
13 formula_name_node* rhs_name;
14
17 {
18 rhs_name = dynamic_cast<formula_name_node*>(this->rhs.get());
19 if (rhs_name == nullptr) {
20 tt_error_info().set<"parse_location">(location);
21 throw parse_error("Expecting a name token on the right hand side of a member accessor. got {}.", rhs);
22 }
23 }
24
26 method = context.get_method(rhs_name->name);
27 if (!method) {
28 tt_error_info().set<"parse_location">(location);
29 throw parse_error("Could not find method .{}().", rhs_name->name);
30 }
31 }
32
33 datum evaluate(formula_evaluation_context& context) const override {
34 if (lhs->has_evaluate_xvalue()) {
35 ttlet &lhs_ = lhs->evaluate_xvalue(context);
36
37 if (!lhs_.contains(rhs_name->name)) {
38 tt_error_info().set<"parse_location">(location);
39 throw operation_error("Unknown attribute .{}", rhs_name->name);
40 }
41 try {
42 return lhs_[rhs_name->name];
43 } catch (...) {
44 error_info(true).set<"parse_location">(location);
45 throw;
46 }
47
48 } else {
49 ttlet lhs_ = lhs->evaluate(context);
50
51 if (!lhs_.contains(rhs_name->name)) {
52 tt_error_info().set<"parse_location">(location);
53 throw operation_error("Unknown attribute .{}", rhs_name->name);
54 }
55 try {
56 return lhs_[rhs_name->name];
57 } catch (...) {
58 error_info(true).set<"parse_location">(location);
59 throw;
60 }
61 }
62 }
63
65 auto &lhs_ = lhs->evaluate_lvalue(context);
66 try {
67 return lhs_[rhs_name->name];
68 } catch (...) {
69 error_info(true).set<"parse_location">(location);
70 throw;
71 }
72 }
73
74 datum call(formula_evaluation_context& context, datum::vector const &arguments) const override {
75 auto &lhs_ = lhs->evaluate_lvalue(context);
76 try {
77 return method(context, lhs_, arguments);
78 } catch (...) {
79 error_info(true).set<"parse_location">(location);
80 throw;
81 }
82 }
83
84 std::string string() const noexcept override {
85 return fmt::format("({} . {})", *lhs, *rhs);
86 }
87};
88
89}
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
Exception thrown during execution of a dynamic operation.
Definition exception.hpp:37
Definition formula_binary_operator_node.hpp:11
Definition formula_evaluation_context.hpp:16
Definition formula_member_node.hpp:11
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_member_node.hpp:25
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_member_node.hpp:64
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_member_node.hpp:33
datum call(formula_evaluation_context &context, datum::vector const &arguments) const override
Call a function with a datum::vector as arguments.
Definition formula_member_node.hpp:74
Definition formula_name_node.hpp:11
Definition formula_post_process_context.hpp:18
Definition parse_location.hpp:16
T get(T... args)
T move(T... args)