Line data Source code
1 : #include "../../../inc/visitors/fillSemanticInfo/fillSemanticInfo.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 : FillSemanticInfo::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 : pushScope();
21 0 : node->body()->setScope(currentScope_);
22 0 : const auto body{node->body()->accept(*this)};
23 0 : if (!body) {
24 0 : return createError(body.error());
25 0 : }
26 0 : popScope();
27 0 : return {};
28 0 : }
29 :
30 : std::expected<std::monostate, Error>
31 0 : FillSemanticInfo::visit(const AST_FOR *node) const noexcept {
32 0 : if (!node) {
33 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_FOR");
34 0 : }
35 0 : pushScope();
36 0 : node->body()->setScope(currentScope_);
37 0 : for (const auto &expr : node->init()) {
38 0 : const auto result{expr->accept(*this)};
39 0 : if (!result) {
40 0 : return createError(result.error());
41 0 : }
42 0 : }
43 0 : const auto condition{node->condition()->accept(*this)};
44 0 : if (!condition) {
45 0 : return createError(condition.error());
46 0 : }
47 0 : for (const auto &expr : node->update()) {
48 0 : const auto result{expr->accept(*this)};
49 0 : if (!result) {
50 0 : return createError(result.error());
51 0 : }
52 0 : }
53 0 : const auto body{node->body()->accept(*this)};
54 0 : if (!body) {
55 0 : return createError(body.error());
56 0 : }
57 0 : popScope();
58 0 : return {};
59 0 : }
60 :
61 : std::expected<std::monostate, Error>
62 0 : FillSemanticInfo::visit(const AST_DO_WHILE *node) const noexcept {
63 0 : if (!node) {
64 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DO_WHILE");
65 0 : }
66 0 : pushScope();
67 0 : node->body()->setScope(currentScope_);
68 0 : const auto body{node->body()->accept(*this)};
69 0 : if (!body) {
70 0 : return createError(body.error());
71 0 : }
72 0 : popScope();
73 0 : const auto condition{node->condition()->accept(*this)};
74 0 : if (!condition) {
75 0 : return createError(condition.error());
76 0 : }
77 0 : return {};
78 0 : }
79 :
80 : std::expected<std::monostate, Error>
81 0 : FillSemanticInfo::visit(const AST_PASS *node) const noexcept {
82 0 : if (!node) {
83 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_PASS");
84 0 : }
85 0 : return {};
86 0 : }
87 :
88 : std::expected<std::monostate, Error>
89 0 : FillSemanticInfo::visit(const AST_STOP *node) const noexcept {
90 0 : if (!node) {
91 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STOP");
92 0 : }
93 0 : return {};
94 0 : }
95 :
96 : }
|