Line data Source code
1 : #include "../../../inc/visitors/monomorphize/monomorphize.h"
2 : #include "../../../inc/parsingAnalysis/ast/conditionals/ast_case.h"
3 : #include "../../../inc/parsingAnalysis/ast/conditionals/ast_default.h"
4 : #include "../../../inc/parsingAnalysis/ast/conditionals/ast_elseIf.h"
5 : #include "../../../inc/parsingAnalysis/ast/conditionals/ast_if.h"
6 : #include "../../../inc/parsingAnalysis/ast/conditionals/ast_switch.h"
7 : #include "../../../inc/parsingAnalysis/ast/conditionals/ast_ternary.h"
8 : #include <variant>
9 :
10 : namespace nicole {
11 :
12 : std::expected<std::monostate, Error>
13 0 : Monomorphize::visit(const AST_IF *node) const noexcept {
14 0 : if (!node) {
15 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_IF");
16 0 : }
17 0 : const auto condition{node->condition()->accept(*this)};
18 0 : if (!condition) {
19 0 : return createError(condition.error());
20 0 : }
21 0 : const auto body{node->body()->accept(*this)};
22 0 : if (!body) {
23 0 : return createError(body.error());
24 0 : }
25 0 : for (const auto &elseif_ : node->elseIf()) {
26 0 : const auto result{elseif_->accept(*this)};
27 0 : if (!result) {
28 0 : return createError(result.error());
29 0 : }
30 0 : }
31 0 : if (node->elseBody()) {
32 0 : const auto elseBody{node->elseBody()->accept(*this)};
33 0 : if (!elseBody) {
34 0 : return createError(elseBody.error());
35 0 : }
36 0 : }
37 0 : return {};
38 0 : }
39 :
40 : std::expected<std::monostate, Error>
41 0 : Monomorphize::visit(const AST_ELSE_IF *node) const noexcept {
42 0 : if (!node) {
43 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_ELSE_IF");
44 0 : }
45 0 : const auto condition{node->condition()->accept(*this)};
46 0 : if (!condition) {
47 0 : return createError(condition.error());
48 0 : }
49 0 : const auto result{node->body()->accept(*this)};
50 0 : if (!result) {
51 0 : return createError(result.error());
52 0 : }
53 0 : return {};
54 0 : }
55 :
56 : std::expected<std::monostate, Error>
57 0 : Monomorphize::visit(const AST_SWITCH *node) const noexcept {
58 0 : if (!node) {
59 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_SWITCH");
60 0 : }
61 0 : const auto condition{node->condition()->accept(*this)};
62 0 : if (!condition) {
63 0 : return createError(condition.error());
64 0 : }
65 0 : for (const auto &case_ : node->cases()) {
66 0 : const auto result{case_->accept(*this)};
67 0 : if (!result) {
68 0 : return createError(result.error());
69 0 : }
70 0 : }
71 0 : if (node->defaultCase()) {
72 0 : const auto defaultCase{node->defaultCase()->accept(*this)};
73 0 : if (!defaultCase) {
74 0 : return createError(defaultCase.error());
75 0 : }
76 0 : }
77 0 : return {};
78 0 : }
79 :
80 : std::expected<std::monostate, Error>
81 0 : Monomorphize::visit(const AST_CASE *node) const noexcept {
82 0 : if (!node) {
83 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_CASE");
84 0 : }
85 0 : const auto match{node->match()->accept(*this)};
86 0 : if (!match) {
87 0 : return createError(match.error());
88 0 : }
89 0 : const auto result{node->body()->accept(*this)};
90 0 : if (!result) {
91 0 : return createError(result.error());
92 0 : }
93 0 : return {};
94 0 : }
95 :
96 : std::expected<std::monostate, Error>
97 0 : Monomorphize::visit(const AST_DEFAULT *node) const noexcept {
98 0 : if (!node) {
99 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DEFAULT");
100 0 : }
101 0 : const auto result{node->body()->accept(*this)};
102 0 : if (!result) {
103 0 : return createError(result.error());
104 0 : }
105 0 : return {};
106 0 : }
107 :
108 : std::expected<std::monostate, Error>
109 0 : Monomorphize::visit(const AST_TERNARY *node) const noexcept {
110 0 : if (!node) {
111 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_TERNARY");
112 0 : }
113 0 : const auto condition{node->condition()->accept(*this)};
114 0 : if (!condition) {
115 0 : return createError(condition.error());
116 0 : }
117 0 : const auto first{node->first()->accept(*this)};
118 0 : if (!first) {
119 0 : return createError(first.error());
120 0 : }
121 0 : const auto second{node->second()->accept(*this)};
122 0 : if (!second) {
123 0 : return createError(second.error());
124 0 : }
125 0 : return {};
126 0 : }
127 :
128 : std::expected<std::monostate, Error>
129 0 : Monomorphize::visit(const AST_CONDITION *node) const noexcept {
130 0 : if (!node) {
131 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_CONDITION");
132 0 : }
133 0 : return node->condition()->accept(*this);
134 0 : }
135 :
136 : }
|