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#include "../macros.hpp"
9
10hi_export_module(hikogui.formula.formula_member_node);
11
12namespace hi { inline namespace v1 {
13
15 mutable formula_post_process_context::method_type method;
16 formula_name_node *rhs_name;
17
18 formula_member_node(size_t line_nr, size_t column_nr, std::unique_ptr<formula_node> lhs, std::unique_ptr<formula_node> rhs) :
19 formula_binary_operator_node(line_nr, column_nr, std::move(lhs), std::move(rhs))
20 {
21 rhs_name = dynamic_cast<formula_name_node *>(this->rhs.get());
22 if (rhs_name == nullptr) {
23 throw parse_error(std::format("{}:{}: Expecting a name token on the right hand side of a member accessor. got {}.", line_nr, column_nr, *rhs));
24 }
25 }
26
28 {
29 method = context.get_method(rhs_name->name);
30 if (!method) {
31 throw parse_error(std::format("{}:{}: Could not find method .{}().", line_nr, column_nr, rhs_name->name));
32 }
33 }
34
36 {
37 if (lhs->has_evaluate_xvalue()) {
38 hilet &lhs_ = lhs->evaluate_xvalue(context);
39
40 if (!lhs_.contains(rhs_name->name)) {
41 throw operation_error(std::format("{}:{}: Unknown attribute .{}", line_nr, column_nr, rhs_name->name));
42 }
43 try {
44 return lhs_[rhs_name->name];
45 } catch (std::exception const &e) {
46 throw operation_error(std::format("{}:{}: Can not evaluate member selection.\n{}", line_nr, column_nr, e.what()));
47 }
48
49 } else {
50 hilet lhs_ = lhs->evaluate(context);
51
52 if (!lhs_.contains(rhs_name->name)) {
53 throw operation_error(std::format("{}:{}: Unknown attribute .{}", line_nr, column_nr, rhs_name->name));
54 }
55 try {
56 return lhs_[rhs_name->name];
57 } catch (std::exception const &e) {
58 throw operation_error(std::format("{}:{}: Can not evaluate member selection.\n{}", line_nr, column_nr, e.what()));
59 }
60 }
61 }
62
64 {
65 auto &lhs_ = lhs->evaluate_lvalue(context);
66 try {
67 return lhs_[rhs_name->name];
68 } catch (std::exception const &e) {
69 throw operation_error(std::format("{}:{}: Can not evaluate member-selection.\n{}", line_nr, column_nr, e.what()));
70 }
71 }
72
74 {
75 auto &lhs_ = lhs->evaluate_lvalue(context);
76 try {
77 return method(context, lhs_, arguments);
78 } catch (std::exception const &e) {
79 throw operation_error(std::format("{}:{}: Can not evaluate call-of-method.\n{}", line_nr, column_nr, e.what()));
80 }
81 }
82
83 std::string string() const noexcept override
84 {
85 return std::format("({} . {})", *lhs, *rhs);
86 }
87};
88
89}} // 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
Definition formula_binary_operator_node.hpp:14
Definition formula_evaluation_context.hpp:18
Definition formula_member_node.hpp:14
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_member_node.hpp:35
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_member_node.hpp:27
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:73
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_member_node.hpp:63
Definition formula_name_node.hpp:14
Definition formula_post_process_context.hpp:237
Exception thrown during parsing on an error.
Definition exception_intf.hpp:47
Exception thrown during execution of a dynamic operation.
Definition exception_intf.hpp:160
T get(T... args)
T move(T... args)
T what(T... args)