Line data Source code
1 : #include "../../../inc/visitors/monomorphize/monomorphize.h"
2 : #include "../../../inc/parsingAnalysis/ast/userTypes/ast_attrAccess.h"
3 : #include "../../../inc/parsingAnalysis/ast/userTypes/ast_constructorCall.h"
4 : #include "../../../inc/parsingAnalysis/ast/userTypes/ast_methodCall.h"
5 : #include "../../../inc/parsingAnalysis/ast/userTypes/ast_struct.h"
6 : #include "../../../inc/parsingAnalysis/ast/userTypes/ast_this.h"
7 : #include <variant>
8 :
9 : namespace nicole {
10 :
11 : std::expected<std::monostate, Error>
12 0 : Monomorphize::visit(const AST_STRUCT *node) const noexcept {
13 0 : if (!node) {
14 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STRUCT");
15 0 : }
16 0 : const auto constructor{node->constructor()->accept(*this)};
17 0 : if (!constructor) {
18 0 : return createError(constructor.error());
19 0 : }
20 0 : const auto destructor{node->destructor()->accept(*this)};
21 0 : if (!destructor) {
22 0 : return createError(destructor.error());
23 0 : }
24 0 : for (const auto &chain : node->methods()) {
25 0 : const auto result{chain->accept(*this)};
26 0 : if (!result) {
27 0 : return createError(result.error());
28 0 : }
29 0 : }
30 0 : return {};
31 0 : }
32 :
33 : std::expected<std::monostate, Error>
34 0 : Monomorphize::visit(const AST_ATTR_ACCESS *node) const noexcept {
35 0 : if (!node) {
36 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_ATTR_ACCESS");
37 0 : }
38 0 : return {};
39 0 : }
40 :
41 : std::expected<std::monostate, Error>
42 0 : Monomorphize::visit(const AST_METHOD_CALL *node) const noexcept {
43 0 : if (!node) {
44 0 : return createError(ERROR_TYPE::NULL_NODE, "Invalid AST_METHOD_CALL");
45 0 : }
46 0 : for (const auto &chain : node->parameters()) {
47 0 : const auto result{chain->accept(*this)};
48 0 : if (!result) {
49 0 : return createError(result.error());
50 0 : }
51 0 : }
52 0 : return {};
53 0 : }
54 :
55 : std::expected<std::monostate, Error>
56 0 : Monomorphize::visit(const AST_METHOD_DECL *node) const noexcept {
57 0 : if (!node) {
58 0 : return createError(ERROR_TYPE::NULL_NODE, "Invalid AST_METHOD_DECL");
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 : return {};
65 0 : }
66 :
67 : std::expected<std::monostate, Error>
68 0 : Monomorphize::visit(const AST_CONSTRUCTOR_DECL *node) const noexcept {
69 0 : if (!node) {
70 0 : return createError(ERROR_TYPE::NULL_NODE, "Invalid AST_CONSTRUCTOR_DECL");
71 0 : }
72 0 : if (node->super()) {
73 0 : const auto result{node->super()->accept(*this)};
74 0 : if (!result) {
75 0 : return createError(result.error());
76 0 : }
77 0 : }
78 0 : const auto result{node->body()->accept(*this)};
79 0 : if (!result) {
80 0 : return createError(result.error());
81 0 : }
82 0 : return {};
83 0 : }
84 :
85 : std::expected<std::monostate, Error>
86 0 : Monomorphize::visit(const AST_SUPER *node) const noexcept {
87 0 : if (!node) {
88 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_SUPER");
89 0 : }
90 0 : for (const auto &chain : node->arguments()) {
91 0 : const auto result{chain->accept(*this)};
92 0 : if (!result) {
93 0 : return createError(result.error());
94 0 : }
95 0 : }
96 0 : return {};
97 0 : }
98 :
99 : std::expected<std::monostate, Error>
100 0 : Monomorphize::visit(const AST_DESTRUCTOR_DECL *node) const noexcept {
101 0 : if (!node) {
102 0 : return createError(ERROR_TYPE::NULL_NODE, "Invalid AST_DESTRUCTOR_DECL");
103 0 : }
104 0 : const auto result{node->body()->accept(*this)};
105 0 : if (!result) {
106 0 : return createError(result.error());
107 0 : }
108 0 : return {};
109 0 : }
110 :
111 : std::expected<std::monostate, Error>
112 0 : Monomorphize::visit(const AST_THIS *node) const noexcept {
113 0 : if (!node) {
114 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_THIS");
115 0 : }
116 0 : return {};
117 0 : }
118 :
119 : std::expected<std::monostate, Error>
120 0 : Monomorphize::visit(const AST_CONSTRUCTOR_CALL *node) const noexcept {
121 0 : if (!node) {
122 0 : return createError(ERROR_TYPE::NULL_NODE, "Invalid AST_CONSTRUCTOR_CALL");
123 0 : }
124 0 : for (const auto &chain : node->parameters()) {
125 0 : const auto result{chain->accept(*this)};
126 0 : if (!result) {
127 0 : return createError(result.error());
128 0 : }
129 0 : }
130 0 : return {};
131 0 : }
132 :
133 : }
|