Line data Source code
1 : #include "../../../inc/visitors/codeGeneration/codeGeneration.h"
2 : #include "../../../inc/parsingAnalysis/ast/operators/ast_binary.h"
3 : #include "../../../inc/parsingAnalysis/ast/operators/ast_unary.h"
4 : #include <cstddef>
5 : #include <memory>
6 : #include <variant>
7 :
8 : namespace nicole {
9 :
10 : std::expected<std::shared_ptr<llvm::Value>, Error>
11 0 : CodeGeneration::visit(const AST_BINARY *node) const noexcept {
12 0 : if (!node) {
13 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_BINARY");
14 0 : }
15 0 : const auto left{node->left()->accept(*this)};
16 0 : if (!left) {
17 0 : return createError(left.error());
18 0 : }
19 0 : const auto right{node->right()->accept(*this)};
20 0 : if (!right) {
21 0 : return createError(right.error());
22 0 : }
23 0 : return {};
24 0 : }
25 :
26 : std::expected<std::shared_ptr<llvm::Value>, Error>
27 0 : CodeGeneration::visit(const AST_UNARY *node) const noexcept {
28 0 : if (!node) {
29 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_UNARY");
30 0 : }
31 0 : const auto left{node->value()->accept(*this)};
32 0 : if (!left) {
33 0 : return createError(left.error());
34 0 : }
35 0 : return {};
36 0 : }
37 :
38 : }
|