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

            Line data    Source code
       1              : #include "../../../inc/visitors/typeAnalysis/typeAnalysis.h"
       2              : #include "../../../inc/parsingAnalysis/ast/operators/ast_binary.h"
       3              : #include "../../../inc/parsingAnalysis/ast/operators/ast_unary.h"
       4              : #include <memory>
       5              : 
       6              : namespace nicole {
       7              : 
       8              : /*
       9              : - comrpueba que left no sea void ni NoPropagate, BreakType
      10              : - comrpueba que right no sea void ni NoPropagate, BreakType
      11              : - comrprueba que se puedan operar, caso speciales si un userType busca metodo
      12              : para sobrecarga de operador
      13              : */
      14              : std::expected<std::shared_ptr<Type>, Error>
      15            0 : TypeAnalysis::visit(const AST_BINARY *node) const noexcept {
      16            0 :   if (!node) {
      17            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_BINARY");
      18            0 :   }
      19            0 :   auto leftRes = node->left()->accept(*this);
      20            0 :   if (!leftRes)
      21            0 :     return createError(leftRes.error());
      22            0 :   auto leftType = leftRes.value();
      23              : 
      24            0 :   auto rightRes = node->right()->accept(*this);
      25            0 :   if (!rightRes)
      26            0 :     return createError(rightRes.error());
      27            0 :   auto rightType = rightRes.value();
      28              : 
      29            0 :   TokenType op =
      30            0 :       node->op().type(); // Assumes AST_BINARY::op() returns a TokenType
      31              : 
      32            0 :   auto resultExp = typeTable_->applyBinaryOperator(leftType, rightType, op);
      33            0 :   if (!resultExp)
      34            0 :     return createError(resultExp.error());
      35            0 :   node->setReturnedFromAnalysis(*resultExp);
      36            0 :   return resultExp.value();
      37            0 : }
      38              : 
      39              : /*
      40              : - comprueba que expression no es void ni NoPropagate, BreakType
      41              : - comrpueba que se puede operar, caso speciales si un userType busca metodo
      42              : para sobrecarga de operador y retorna el tipo
      43              :  */
      44              : std::expected<std::shared_ptr<Type>, Error>
      45            0 : TypeAnalysis::visit(const AST_UNARY *node) const noexcept {
      46            0 :   if (!node) {
      47            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_UNARY");
      48            0 :   }
      49              : 
      50            0 :   auto operandRes = node->value()->accept(*this);
      51            0 :   if (!operandRes)
      52            0 :     return createError(operandRes.error());
      53            0 :   auto operandType = operandRes.value();
      54            0 :   TokenType op =
      55            0 :       node->op().type(); // Se asume que node->op() retorna un TokenType
      56              : 
      57            0 :   auto resultTypeExp = typeTable_->applyUnaryOperator(operandType, op);
      58            0 :   if (!resultTypeExp)
      59            0 :     return createError(resultTypeExp.error());
      60            0 :   node->setReturnedFromAnalysis(*resultTypeExp);
      61            0 :   return resultTypeExp.value();
      62            0 : }
      63              : 
      64              : }
        

Generated by: LCOV version 2.0-1