HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
skeleton_do_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 "skeleton_node.hpp"
8#include "../macros.hpp"
9
10namespace hi::inline v1 {
11
13 statement_vector children;
15 parse_location formula_location;
16
17 skeleton_do_node(parse_location location) noexcept : skeleton_node(std::move(location)) {}
18
19 bool found_while(parse_location _location, std::unique_ptr<formula_node> x) noexcept override
20 {
21 if (expression) {
22 return false;
23 } else {
24 expression = std::move(x);
25 formula_location = std::move(_location);
26 return true;
27 }
28 }
29
32 bool append(std::unique_ptr<skeleton_node> x) noexcept override
33 {
34 if (expression) {
35 return false;
36 } else {
37 append_child(children, std::move(x));
38 return true;
39 }
40 }
41
42 void post_process(formula_post_process_context &context) override
43 {
44 if (ssize(children) > 0) {
45 children.back()->left_align();
46 }
47
48 post_process_expression(context, *expression, location);
49
50 for (hilet &child : children) {
51 child->post_process(context);
52 }
53 }
54
55 datum evaluate(formula_evaluation_context &context) override
56 {
57 hilet output_size = context.output_size();
58
59 ssize_t loop_count = 0;
60 do {
61 context.loop_push(loop_count++);
62 auto tmp = evaluate_children(context, children);
63 context.loop_pop();
64
65 if (tmp.is_break()) {
66 break;
67 } else if (tmp.is_continue()) {
68 continue;
69 } else if (!tmp.is_undefined()) {
70 context.set_output_size(output_size);
71 return tmp;
72 }
73
74 } while (evaluate_formula_without_output(context, *expression, formula_location));
75 return {};
76 }
77
78 std::string string() const noexcept override
79 {
80 hi_assert(expression);
81 std::string s = "<do ";
82 s += join(transform<std::vector<std::string>>(children, [](auto &x) {
83 return to_string(*x);
84 }));
85 s += to_string(*expression);
86 s += ">";
87 return s;
88 }
89};
90
91} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition parse_location.hpp:18
Definition skeleton_do_node.hpp:12
bool append(std::unique_ptr< skeleton_node > x) noexcept override
Append a template-piece to the current template.
Definition skeleton_do_node.hpp:32
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_do_node.hpp:55
Definition skeleton_node.hpp:16
T move(T... args)