Line data Source code
1 : #include "../../../inc/visitors/typeAnalysis/typeAnalysis.h"
2 : #include "../../../inc/parsingAnalysis/ast/enum/ast_enum.h"
3 : #include "../../../inc/parsingAnalysis/ast/enum/ast_enumAccess.h"
4 : #include <memory>
5 :
6 : namespace nicole {
7 :
8 : /*
9 : - retorna NoPropagate
10 : */
11 : std::expected<std::shared_ptr<Type>, Error>
12 0 : TypeAnalysis::visit(const AST_ENUM *node) const noexcept {
13 0 : if (!node) {
14 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_ENUM");
15 0 : }
16 0 : const auto type{typeTable_->noPropagateType()};
17 0 : node->setReturnedFromAnalysis(type);
18 0 : return type;
19 0 : }
20 :
21 : /*
22 : - retorna int
23 : */
24 : std::expected<std::shared_ptr<Type>, Error>
25 0 : TypeAnalysis::visit(const AST_ENUM_ACCESS *node) const noexcept {
26 0 : if (!node) {
27 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_ENUM_ACCESS");
28 0 : }
29 0 : const auto type{typeTable_->getType(node->enumId())};
30 0 : if (!type) {
31 0 : return createError(ERROR_TYPE::TYPE, "enum does not exist");
32 0 : }
33 0 : node->setReturnedFromAnalysis(*type);
34 0 : return type;
35 0 : }
36 :
37 : }
|