Line data Source code
1 : #include "../../../inc/visitors/validateTree/validateTree.h"
2 : #include "../../../inc/parsingAnalysis/ast/tree.h"
3 :
4 : namespace nicole {
5 :
6 : std::expected<bool, Error>
7 0 : ValidateTree::visit(const AST_STATEMENT *node) const noexcept {
8 0 : if (!node) {
9 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STATEMENT");
10 0 : }
11 0 : return node->expression()->accept(*this);
12 0 : }
13 :
14 : std::expected<bool, Error>
15 0 : ValidateTree::visit(const AST_BODY *node) const noexcept {
16 0 : if (!node) {
17 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_BODY");
18 0 : }
19 0 : for (const auto &statement : node->body()) {
20 0 : const auto val{statement->accept(*this)};
21 0 : if (!val) {
22 0 : return createError(val.error());
23 0 : }
24 0 : }
25 0 : return true;
26 0 : }
27 :
28 : std::expected<bool, Error>
29 0 : ValidateTree::visit(const Tree *tree) const noexcept {
30 0 : if (!tree) {
31 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid Tree");
32 0 : }
33 0 : return tree->root()->accept(*this);
34 0 : }
35 :
36 : } // namespace nicole
|