LCOV - code coverage report
Current view: top level - src/visitors/fillSemanticInfo - fillSemanticVarDecl.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 68 0
Test Date: 2025-04-18 15:53:49 Functions: 0.0 % 3 0

            Line data    Source code
       1              : #include "../../../inc/visitors/fillSemanticInfo/fillSemanticInfo.h"
       2              : #include "../../../inc/parsingAnalysis/ast/variables/ast_autoDecl.h"
       3              : #include "../../../inc/parsingAnalysis/ast/variables/ast_typedDecl.h"
       4              : #include "../../../inc/parsingAnalysis/ast/variables/ast_varCall.h"
       5              : #include <memory>
       6              : #include <variant>
       7              : 
       8              : namespace nicole {
       9              : 
      10              : std::expected<std::monostate, Error>
      11            0 : FillSemanticInfo::visit(const AST_AUTO_DECL *node) const noexcept {
      12            0 :   if (!node) {
      13            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_AUTO_DECL");
      14            0 :   }
      15              : 
      16            0 :   const auto value{node->value()->accept(*this)};
      17            0 :   if (!value) {
      18            0 :     return createError(value.error());
      19            0 :   }
      20              : 
      21            0 :   if (analyzingInsideClass and currentUserType_->hasAttribute(node->id())) {
      22            0 :     return createError(ERROR_TYPE::ATTR, " the variable " + node->id() +
      23            0 :                                              " is shadowing the atribute");
      24            0 :   }
      25              : 
      26            0 :   const auto insert{
      27            0 :       currentScope_->insert(Variable{node->id(), nullptr, nullptr})};
      28            0 :   if (!insert) {
      29            0 :     return createError(insert.error());
      30            0 :   }
      31              : 
      32            0 :   return {};
      33            0 : }
      34              : 
      35              : std::expected<std::monostate, Error>
      36            0 : FillSemanticInfo::visit(const AST_VAR_TYPED_DECL *node) const noexcept {
      37            0 :   if (!node) {
      38            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_VAR_TYPED_DECL");
      39            0 :   }
      40              : 
      41            0 :   const auto value{node->value()->accept(*this)};
      42            0 :   if (!value) {
      43            0 :     return createError(value.error());
      44            0 :   }
      45              : 
      46            0 :   if (analyzingInsideClass and currentUserType_->hasAttribute(node->id())) {
      47            0 :     return createError(ERROR_TYPE::ATTR, " the variable " + node->id() +
      48            0 :                                              " is shadowing the atribute");
      49            0 :   }
      50              : 
      51            0 :   auto varType{node->varType()};
      52            0 :   if (!typeTable_->isPossibleType(node->varType()) and
      53            0 :       !typeTable_->isGenericType(node->varType(), currentGenericList_)) {
      54            0 :     return createError(ERROR_TYPE::TYPE,
      55            0 :                        node->varType()->toString() +
      56            0 :                            " is not a posibble type or generic");
      57            0 :   }
      58              : 
      59            0 :   const auto checkIfMaskedEnum{typeTable_->isCompundEnumType(node->varType())};
      60            0 :   if (checkIfMaskedEnum) {
      61            0 :     varType = *checkIfMaskedEnum;
      62            0 :     node->setVarType(varType);
      63            0 :   }
      64              : 
      65            0 :   auto maybeGeneric = typeTable_->isCompundGenericType(varType, currentGenericList_);
      66            0 :   if (maybeGeneric.has_value()) {
      67            0 :     varType = *maybeGeneric;
      68            0 :     node->setVarType(varType);
      69            0 :   }
      70              : 
      71            0 :   const auto insert{
      72            0 :       currentScope_->insert(Variable{node->id(), varType, nullptr})};
      73            0 :   if (!insert) {
      74            0 :     return createError(insert.error());
      75            0 :   }
      76              : 
      77            0 :   return {};
      78            0 : }
      79              : 
      80              : std::expected<std::monostate, Error>
      81            0 : FillSemanticInfo::visit(const AST_VAR_CALL *node) const noexcept {
      82            0 :   if (!node) {
      83            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_VAR_CALL");
      84            0 :   }
      85            0 :   if (analyzingInsideClass and currentUserType_->hasAttribute(node->id())) {
      86            0 :     return {};
      87            0 :   }
      88            0 :   if (!currentScope_->has(node->id())) {
      89            0 :     return createError(ERROR_TYPE::VARIABLE,
      90            0 :                        "the variable " + node->id() + " does not exist");
      91            0 :   }
      92            0 :   return {};
      93            0 : }
      94              : 
      95              : }
        

Generated by: LCOV version 2.0-1