Line data Source code
1 : #include "../../../inc/visitors/fillSemanticInfo/fillSemanticInfo.h"
2 : #include "../../../inc/parsingAnalysis/ast/enum/ast_enum.h"
3 : #include "../../../inc/parsingAnalysis/ast/enum/ast_enumAccess.h"
4 : #include <memory>
5 : #include <variant>
6 :
7 : namespace nicole {
8 :
9 : std::expected<std::monostate, Error>
10 0 : FillSemanticInfo::visit(const AST_ENUM *node) const noexcept {
11 0 : if (!node) {
12 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_ENUM");
13 0 : }
14 0 : const auto insert{typeTable_->insert(
15 0 : std::make_shared<EnumType>(node->id(), node->identifiers()))};
16 0 : if (!insert) {
17 0 : return createError(insert.error());
18 0 : }
19 0 : return {};
20 0 : }
21 :
22 : std::expected<std::monostate, Error>
23 0 : FillSemanticInfo::visit(const AST_ENUM_ACCESS *node) const noexcept {
24 0 : if (!node) {
25 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_ENUM_ACCESS");
26 0 : }
27 0 : const auto typeExists{typeTable_->getType(node->enumId())};
28 0 : if (!typeExists) {
29 0 : return createError(typeExists.error());
30 0 : }
31 0 : const auto enumType{std::dynamic_pointer_cast<EnumType>(*typeExists)};
32 0 : if (!enumType) {
33 0 : return createError(
34 0 : ERROR_TYPE::TYPE,
35 0 : "attempting to access a type as a enum but it isn't enum");
36 0 : }
37 0 : if (!enumType->hasIdentifier(node->identifier())) {
38 0 : return createError(ERROR_TYPE::TYPE, "the enum " + enumType->name() +
39 0 : " does not have the identifier " +
40 0 : node->identifier());
41 0 : }
42 0 : return {};
43 0 : }
44 :
45 : }
|