Line data Source code
1 : #include "../../../inc/parsingAnalysis/ast/literals/ast_bool.h"
2 : #include "../../../inc/parsingAnalysis/ast/literals/ast_char.h"
3 : #include "../../../inc/parsingAnalysis/ast/literals/ast_double.h"
4 : #include "../../../inc/parsingAnalysis/ast/literals/ast_float.h"
5 : #include "../../../inc/parsingAnalysis/ast/literals/ast_int.h"
6 : #include "../../../inc/parsingAnalysis/ast/literals/ast_null.h"
7 : #include "../../../inc/parsingAnalysis/ast/literals/ast_string.h"
8 : #include "../../../inc/visitors/typeAnalysis/typeAnalysis.h"
9 :
10 : namespace nicole {
11 :
12 : std::expected<std::shared_ptr<Type>, Error>
13 0 : TypeAnalysis::visit(const AST_BOOL *node) const noexcept {
14 0 : if (!node) {
15 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_BOOL");
16 0 : }
17 0 : const auto type{typeTable_->boolType()};
18 0 : node->setReturnedFromAnalysis(type);
19 0 : return type;
20 0 : }
21 :
22 : std::expected<std::shared_ptr<Type>, Error>
23 0 : TypeAnalysis::visit(const AST_CHAR *node) const noexcept {
24 0 : if (!node) {
25 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_CHAR");
26 0 : }
27 0 : const auto type{typeTable_->charType()};
28 0 : node->setReturnedFromAnalysis(type);
29 0 : return type;
30 0 : }
31 :
32 : std::expected<std::shared_ptr<Type>, Error>
33 0 : TypeAnalysis::visit(const AST_DOUBLE *node) const noexcept {
34 0 : if (!node) {
35 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DOUBLE");
36 0 : }
37 0 : const auto type{typeTable_->doubleType()};
38 0 : node->setReturnedFromAnalysis(type);
39 0 : return type;
40 0 : }
41 :
42 : std::expected<std::shared_ptr<Type>, Error>
43 0 : TypeAnalysis::visit(const AST_FLOAT *node) const noexcept {
44 0 : if (!node) {
45 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_FLOAT");
46 0 : }
47 0 : const auto type{typeTable_->floatType()};
48 0 : node->setReturnedFromAnalysis(type);
49 0 : return type;
50 0 : }
51 :
52 : std::expected<std::shared_ptr<Type>, Error>
53 0 : TypeAnalysis::visit(const AST_INT *node) const noexcept {
54 0 : if (!node) {
55 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_INT");
56 0 : }
57 0 : const auto type{typeTable_->intType()};
58 0 : node->setReturnedFromAnalysis(type);
59 0 : return type;
60 0 : }
61 :
62 : std::expected<std::shared_ptr<Type>, Error>
63 0 : TypeAnalysis::visit(const AST_NULL *node) const noexcept {
64 0 : if (!node) {
65 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_NULL");
66 0 : }
67 0 : const auto type{typeTable_->null()};
68 0 : node->setReturnedFromAnalysis(type);
69 0 : return type;
70 0 : }
71 :
72 : std::expected<std::shared_ptr<Type>, Error>
73 0 : TypeAnalysis::visit(const AST_STRING *node) const noexcept {
74 0 : if (!node) {
75 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STRING");
76 0 : }
77 0 : const auto type{typeTable_->strType()};
78 0 : node->setReturnedFromAnalysis(type);
79 0 : return type;
80 0 : }
81 :
82 : } // namespace nicole
|