Line data Source code
1 : #include "../../../inc/visitors/printTree/printTree.h"
2 : #include "../../../inc/parsingAnalysis/ast/pointer/ast_delete.h"
3 : #include "../../../inc/parsingAnalysis/ast/pointer/ast_deref.h"
4 : #include "../../../inc/parsingAnalysis/ast/pointer/ast_new.h"
5 : #include <ostream>
6 :
7 : namespace nicole {
8 :
9 : std::expected<std::string, Error>
10 0 : PrintTree::visit(const AST_DELETE *node) const noexcept {
11 0 : if (!node) {
12 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DELETE");
13 0 : }
14 0 : std::ostringstream result;
15 0 : result << indent_ << "delete:\n";
16 0 : increaseIndent();
17 0 : const auto val{node->value()->accept(*this)};
18 0 : if (!val) {
19 0 : return createError(val.error());
20 0 : }
21 0 : result << *val;
22 0 : decreaseIndent();
23 0 : return result.str();
24 0 : }
25 :
26 : std::expected<std::string, Error>
27 0 : PrintTree::visit(const AST_NEW *node) const noexcept {
28 0 : if (!node) {
29 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_NEW");
30 0 : }
31 0 : std::ostringstream result;
32 0 : result << indent_ << "new:\n";
33 0 : increaseIndent();
34 0 : const auto val{node->value()->accept(*this)};
35 0 : if (!val) {
36 0 : return createError(val.error());
37 0 : }
38 0 : result << *val;
39 0 : decreaseIndent();
40 0 : return result.str();
41 0 : }
42 :
43 : std::expected<std::string, Error>
44 0 : PrintTree::visit(const AST_DEREF *node) const noexcept {
45 0 : if (!node) {
46 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DEREF");
47 0 : }
48 0 : std::ostringstream result;
49 0 : result << indent_ << "deref:\n";
50 0 : increaseIndent();
51 0 : const auto val{node->value()->accept(*this)};
52 0 : if (!val) {
53 0 : return createError(val.error());
54 0 : }
55 0 : result << *val;
56 0 : decreaseIndent();
57 0 : return result.str();
58 0 : }
59 :
60 : }
|