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