HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_member_node.hpp
1// Copyright Take Vos 2020-2022.
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 hi::inline v1 {
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 throw parse_error(std::format("{}: Expecting a name token on the right hand side of a member accessor. got {}.", location, *rhs));
21 }
22 }
23
25 {
26 method = context.get_method(rhs_name->name);
27 if (!method) {
28 throw parse_error(std::format("{}: Could not find method .{}().", location, rhs_name->name));
29 }
30 }
31
32 datum evaluate(formula_evaluation_context &context) const override
33 {
34 if (lhs->has_evaluate_xvalue()) {
35 hilet &lhs_ = lhs->evaluate_xvalue(context);
36
37 if (!lhs_.contains(rhs_name->name)) {
38 throw operation_error(std::format("{}: Unknown attribute .{}", location, rhs_name->name));
39 }
40 try {
41 return lhs_[rhs_name->name];
42 } catch (std::exception const &e) {
43 throw operation_error(std::format("{}: Can not evaluate member selection.\n{}", location, e.what()));
44 }
45
46 } else {
47 hilet lhs_ = lhs->evaluate(context);
48
49 if (!lhs_.contains(rhs_name->name)) {
50 throw operation_error(std::format("{}: Unknown attribute .{}", location, rhs_name->name));
51 }
52 try {
53 return lhs_[rhs_name->name];
54 } catch (std::exception const &e) {
55 throw operation_error(std::format("{}: Can not evaluate member selection.\n{}", location, e.what()));
56 }
57 }
58 }
59
61 {
62 auto &lhs_ = lhs->evaluate_lvalue(context);
63 try {
64 return lhs_[rhs_name->name];
65 } catch (std::exception const &e) {
66 throw operation_error(std::format("{}: Can not evaluate member-selection.\n{}", location, e.what()));
67 }
68 }
69
70 datum call(formula_evaluation_context &context, datum::vector_type const &arguments) const override
71 {
72 auto &lhs_ = lhs->evaluate_lvalue(context);
73 try {
74 return method(context, lhs_, arguments);
75 } catch (std::exception const &e) {
76 throw operation_error(std::format("{}: Can not evaluate call-of-method.\n{}", location, e.what()));
77 }
78 }
79
80 std::string string() const noexcept override
81 {
82 return std::format("({} . {})", *lhs, *rhs);
83 }
84};
85
86} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
A dynamic data type.
Definition datum.hpp:225
Definition formula_binary_operator_node.hpp:11
Definition formula_evaluation_context.hpp:16
Definition formula_member_node.hpp:11
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_member_node.hpp:60
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_member_node.hpp:32
datum call(formula_evaluation_context &context, datum::vector_type const &arguments) const override
Call a function with a datum::vector as arguments.
Definition formula_member_node.hpp:70
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_member_node.hpp:24
Definition formula_name_node.hpp:11
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:18
T get(T... args)
T move(T... args)
T what(T... args)