Line data Source code
1 : #include "../../../inc/visitors/monomorphize/monomorphize.h"
2 : #include "../../../inc/parsingAnalysis/ast/loops/ast_doWhile.h"
3 : #include "../../../inc/parsingAnalysis/ast/loops/ast_for.h"
4 : #include "../../../inc/parsingAnalysis/ast/loops/ast_pass.h"
5 : #include "../../../inc/parsingAnalysis/ast/loops/ast_stop.h"
6 : #include "../../../inc/parsingAnalysis/ast/loops/ast_while.h"
7 : #include <variant>
8 :
9 : namespace nicole {
10 :
11 : std::expected<std::monostate, Error>
12 0 : Monomorphize::visit(const AST_WHILE *node) const noexcept {
13 0 : if (!node) {
14 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_WHILE");
15 0 : }
16 0 : const auto condition{node->condition()->accept(*this)};
17 0 : if (!condition) {
18 0 : return createError(condition.error());
19 0 : }
20 0 : const auto result{node->body()->accept(*this)};
21 0 : if (!result) {
22 0 : return createError(result.error());
23 0 : }
24 0 : return {};
25 0 : }
26 :
27 : std::expected<std::monostate, Error>
28 0 : Monomorphize::visit(const AST_FOR *node) const noexcept {
29 0 : if (!node) {
30 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_FOR");
31 0 : }
32 0 : for (const auto &expr : node->init()) {
33 0 : const auto result{expr->accept(*this)};
34 0 : if (!result) {
35 0 : return createError(result.error());
36 0 : }
37 0 : }
38 0 : const auto condition{node->condition()->accept(*this)};
39 0 : if (!condition) {
40 0 : return createError(condition.error());
41 0 : }
42 0 : for (const auto &expr : node->update()) {
43 0 : const auto result{expr->accept(*this)};
44 0 : if (!result) {
45 0 : return createError(result.error());
46 0 : }
47 0 : }
48 0 : const auto result{node->body()->accept(*this)};
49 0 : if (!result) {
50 0 : return createError(result.error());
51 0 : }
52 0 : return {};
53 0 : }
54 :
55 : std::expected<std::monostate, Error>
56 0 : Monomorphize::visit(const AST_DO_WHILE *node) const noexcept {
57 0 : if (!node) {
58 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DO_WHILE");
59 0 : }
60 0 : const auto result{node->body()->accept(*this)};
61 0 : if (!result) {
62 0 : return createError(result.error());
63 0 : }
64 0 : const auto condition{node->condition()->accept(*this)};
65 0 : if (!condition) {
66 0 : return createError(condition.error());
67 0 : }
68 0 : return {};
69 0 : }
70 :
71 : std::expected<std::monostate, Error>
72 0 : Monomorphize::visit(const AST_PASS *node) const noexcept {
73 0 : if (!node) {
74 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_PASS");
75 0 : }
76 0 : return {};
77 0 : }
78 :
79 : std::expected<std::monostate, Error>
80 0 : Monomorphize::visit(const AST_STOP *node) const noexcept {
81 0 : if (!node) {
82 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STOP");
83 0 : }
84 0 : return {};
85 0 : }
86 :
87 : }
|