Line data Source code
1 : #include "../../../inc/visitors/codeGeneration/codeGeneration.h"
2 :
3 : #include "../../../inc/parsingAnalysis/ast/tree.h"
4 : #include <cstddef>
5 : #include <memory>
6 : #include <variant>
7 :
8 : /**
9 :
10 : FillSemanticInfo ---> insertar delcaraciones en las tablas / insertar tipos /
11 : comprobar que las variables pertenecen al scope (llamadas a variables) /
12 : comrpobar llamadas a enum
13 :
14 : TypeAnalysis ---> comprobar en una llamada a funcion que esta existe debido a
15 : sobrecarga de funciones requiere que se trate en el typeAnalysis / igual con
16 : metodos / llamadas a atributos / variables auto
17 :
18 : */
19 :
20 : namespace nicole {
21 :
22 : std::expected<std::shared_ptr<llvm::Value>, Error>
23 0 : CodeGeneration::visit(const AST_STATEMENT *node) const noexcept {
24 0 : if (!node) {
25 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STATEMENT");
26 0 : }
27 0 : return node->expression()->accept(*this);
28 0 : }
29 :
30 : std::expected<std::shared_ptr<llvm::Value>, Error>
31 0 : CodeGeneration::visit(const AST_BODY *node) const noexcept {
32 0 : if (!node) {
33 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_BODY");
34 0 : }
35 0 : for (const auto &statement : node->body()) {
36 0 : const auto val{statement->accept(*this)};
37 0 : if (!val) {
38 0 : return createError(val.error());
39 0 : }
40 0 : }
41 0 : return {};
42 0 : }
43 :
44 : std::expected<std::shared_ptr<llvm::Value>, Error>
45 0 : CodeGeneration::visit(const Tree *tree) const noexcept {
46 0 : if (!tree) {
47 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid Tree");
48 0 : }
49 0 : return tree->root()->accept(*this);
50 0 : }
51 :
52 : } // namespace nicole
|