LCOV - code coverage report
Current view: top level - src/visitors/validateTree - validateFunctions.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 47 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/functions/ast_funcCall.h"
       3              : #include "../../../inc/parsingAnalysis/ast/functions/ast_funcDecl.h"
       4              : #include "../../../inc/parsingAnalysis/ast/functions/ast_return.h"
       5              : #include "../../../inc/parsingAnalysis/checkPosition.h"
       6              : 
       7              : namespace nicole {
       8              : 
       9              : // chained
      10              : std::expected<bool, Error>
      11            0 : ValidateTree::visit(const AST_FUNC_CALL *node) const noexcept {
      12            0 :   if (!node) {
      13            0 :     return createError(ERROR_TYPE::NULL_NODE, "Invalid AST_FUNC_CALL");
      14            0 :   }
      15            0 :   if (node->father() and node->father()->type() != AST_TYPE::CHAIN) {
      16            0 :     return createError(ERROR_TYPE::VALIDATE_TREE,
      17            0 :                        "invalid hierachy AST_FUNC_CALL");
      18            0 :   }
      19            0 :   for (const auto &chain : node->parameters()) {
      20            0 :     const auto result{chain->accept(*this)};
      21            0 :     if (!result) {
      22            0 :       return createError(result.error());
      23            0 :     }
      24            0 :   }
      25            0 :   return true;
      26            0 : }
      27              : 
      28              : // statement / body / null or struct / class
      29              : std::expected<bool, Error>
      30            0 : ValidateTree::visit(const AST_FUNC_DECL *node) const noexcept {
      31            0 :   if (!node) {
      32            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_FUNC_DECL");
      33            0 :   }
      34            0 :   if (CheckPosition::itsBodyAncestorHasParent(node)) {
      35            0 :     return createError(ERROR_TYPE::VALIDATE_TREE,
      36            0 :                        "a funciton declaration cant appear inside a scope: " +
      37            0 :                            node->id());
      38            0 :   }
      39            0 :   const auto result{node->body()->accept(*this)};
      40            0 :   if (!result) {
      41            0 :     return createError(result.error());
      42            0 :   }
      43            0 :   return true;
      44            0 : }
      45              : 
      46              : // func decl
      47              : std::expected<bool, Error>
      48            0 : ValidateTree::visit(const AST_RETURN *node) const noexcept {
      49            0 :   if (!node) {
      50            0 :     return createError(ERROR_TYPE::NULL_NODE, "invalid AST_RETURN");
      51            0 :   }
      52            0 :   if (!CheckPosition::hasAnyAncestorOf(
      53            0 :           node, {AST_TYPE::FUNC_DECL, AST_TYPE::METHOD_DECL})) {
      54            0 :     return createError(ERROR_TYPE::VALIDATE_TREE,
      55            0 :                        "a return declaration must has a function "
      56            0 :                        "declaration in its hierarchy");
      57            0 :   }
      58            0 :   const auto result{node->expression()->accept(*this)};
      59            0 :   if (!result) {
      60            0 :     return createError(result.error());
      61            0 :   }
      62            0 :   return true;
      63            0 : }
      64              : 
      65              : }
        

Generated by: LCOV version 2.0-1