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

            Line data    Source code
       1              : #include "../../../inc/visitors/validateTree/validateTree.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 "../../../inc/parsingAnalysis/checkPosition.h"
       6              : 
       7              : namespace nicole {
       8              : 
       9              : // statement / body / not null or for
      10              : std::expected<bool, Error>
      11            0 : ValidateTree::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            0 :   if (!(CheckPosition::itsBodyAncestorHasParent(node) or
      16            0 :         CheckPosition::isInsideForHeader(node))) {
      17            0 :     return createError(
      18            0 :         ERROR_TYPE::VALIDATE_TREE,
      19            0 :         "a auto declaration can only exist in a body or a for header init");
      20            0 :   }
      21            0 :   const auto result{node->value()->accept(*this)};
      22            0 :   if (!result) {
      23            0 :     return createError(result.error());
      24            0 :   }
      25            0 :   return true;
      26            0 : }
      27              : 
      28              : // statement / body / not null or for
      29              : std::expected<bool, Error>
      30            0 : ValidateTree::visit(const AST_VAR_TYPED_DECL *node) const noexcept {
      31            0 :   if (!node) {
      32            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_VAR_TYPED_DECL");
      33            0 :   }
      34            0 :   if (!(CheckPosition::itsBodyAncestorHasParent(node) or
      35            0 :         CheckPosition::isInsideForHeader(node))) {
      36            0 :     return createError(ERROR_TYPE::VALIDATE_TREE,
      37            0 :                        "a var typed declaration can only exist in a body or a "
      38            0 :                        "for header init");
      39            0 :   }
      40            0 :   const auto result{node->value()->accept(*this)};
      41            0 :   if (!result) {
      42            0 :     return createError(result.error());
      43            0 :   }
      44            0 :   return true;
      45            0 : }
      46              : 
      47              : // chained
      48              : std::expected<bool, Error>
      49            0 : ValidateTree::visit(const AST_VAR_CALL *node) const noexcept {
      50            0 :   if (!node) {
      51            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_VAR_CALL");
      52            0 :   }
      53            0 :   if (node->father() and node->father()->type() != AST_TYPE::CHAIN) {
      54            0 :     return createError(ERROR_TYPE::VALIDATE_TREE,
      55            0 :                        "invalid hierachy AST_VAR_CALL");
      56            0 :   }
      57            0 :   return true;
      58            0 : }
      59              : 
      60              : }
        

Generated by: LCOV version 2.0-1