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

            Line data    Source code
       1              : #ifndef TYPE_ANALYSIS_H
       2              : #define TYPE_ANALYSIS_H
       3              : 
       4              : #include "../../tables/functionTable/functionTable.h"
       5              : #include "../../tables/scope/scope.h"
       6              : #include "../../tables/typeTable/typeManager.h"
       7              : #include "../../tables/typeTable/typeTable.h"
       8              : #include "../visitor.h"
       9              : #include <memory>
      10              : #include <variant>
      11              : #include <vector>
      12              : 
      13              : namespace nicole {
      14              : 
      15              : class TypeAnalysis final : public Visitor<std::shared_ptr<Type>> {
      16              : private:
      17              :   mutable std::shared_ptr<FunctionTable> functionTable_;
      18              :   mutable std::shared_ptr<TypeTable> typeTable_;
      19              :   mutable std::shared_ptr<Type> currentType_{nullptr};
      20              :   mutable std::shared_ptr<Scope> currentScope_{nullptr};
      21              :   mutable std::vector<GenericParameter> currentGenericList_{};
      22              :   mutable std::vector<GenericParameter> currentStructGenericList_{};
      23              :   mutable std::shared_ptr<UserType> currentUserType_{nullptr};
      24              :   mutable std::shared_ptr<Type> switchTypeCondition_{nullptr};
      25              :   mutable bool analyzingInsideClass{false};
      26              :   mutable bool insideDeclWithGenerics{false};
      27              :   mutable bool firstBody{true};
      28              :   mutable bool foundReturn{false};
      29              : 
      30              :   [[nodiscard]] std::vector<GenericParameter>
      31              :   mergeGenericLists(const std::vector<GenericParameter> &list1,
      32              :                     const std::vector<GenericParameter> &list2) const noexcept;
      33              : 
      34              : public:
      35              :   TypeAnalysis(const std::shared_ptr<FunctionTable> &functionTable,
      36              :                std::shared_ptr<TypeTable> &typeTable) noexcept
      37            0 :       : functionTable_{functionTable}, typeTable_{typeTable} {}
      38              : 
      39              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      40              :   visit(const AST_BOOL *node) const noexcept override;
      41              : 
      42              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      43              :   visit(const AST_CHAR *node) const noexcept override;
      44              : 
      45              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      46              :   visit(const AST_DOUBLE *node) const noexcept override;
      47              : 
      48              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      49              :   visit(const AST_FLOAT *node) const noexcept override;
      50              : 
      51              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      52              :   visit(const AST_INT *node) const noexcept override;
      53              : 
      54              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      55              :   visit(const AST_NULL *node) const noexcept override;
      56              : 
      57              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      58              :   visit(const AST_STRING *node) const noexcept override;
      59              : 
      60              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      61              :   visit(const AST_VECTOR *node) const noexcept override;
      62              : 
      63              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      64              :   visit(const AST_INDEX *node) const noexcept override;
      65              : 
      66              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      67              :   visit(const AST_DELETE *node) const noexcept override;
      68              : 
      69              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      70              :   visit(const AST_NEW *node) const noexcept override;
      71              : 
      72              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      73              :   visit(const AST_DEREF *node) const noexcept override;
      74              : 
      75              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      76              :   visit(const AST_BINARY *node) const noexcept override;
      77              : 
      78              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      79              :   visit(const AST_UNARY *node) const noexcept override;
      80              : 
      81              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      82              :   visit(const AST_ASSIGNMENT *node) const noexcept override;
      83              : 
      84              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      85              :   visit(const AST_PRINT *node) const noexcept override;
      86              : 
      87              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      88              :   visit(const AST_IMPORT *node) const noexcept override;
      89              : 
      90              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      91              :   visit(const AST_STATEMENT *node) const noexcept override;
      92              : 
      93              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      94              :   visit(const AST_BODY *node) const noexcept override;
      95              : 
      96              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
      97              :   visit(const AST_WHILE *node) const noexcept override;
      98              : 
      99              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     100              :   visit(const AST_FOR *node) const noexcept override;
     101              : 
     102              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     103              :   visit(const AST_DO_WHILE *node) const noexcept override;
     104              : 
     105              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     106              :   visit(const AST_PASS *node) const noexcept override;
     107              : 
     108              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     109              :   visit(const AST_STOP *node) const noexcept override;
     110              : 
     111              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     112              :   visit(const AST_IF *node) const noexcept override;
     113              : 
     114              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     115              :   visit(const AST_ELSE_IF *node) const noexcept override;
     116              : 
     117              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     118              :   visit(const AST_SWITCH *node) const noexcept override;
     119              : 
     120              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     121              :   visit(const AST_CASE *node) const noexcept override;
     122              : 
     123              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     124              :   visit(const AST_DEFAULT *node) const noexcept override;
     125              : 
     126              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     127              :   visit(const AST_TERNARY *node) const noexcept override;
     128              : 
     129              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     130              :   visit(const AST_CONDITION *node) const noexcept override;
     131              : 
     132              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     133              :   visit(const AST_FUNC_CALL *node) const noexcept override;
     134              : 
     135              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     136              :   visit(const AST_FUNC_DECL *node) const noexcept override;
     137              : 
     138              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     139              :   visit(const AST_RETURN *node) const noexcept override;
     140              : 
     141              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     142              :   visit(const AST_ENUM *node) const noexcept override;
     143              : 
     144              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     145              :   visit(const AST_ENUM_ACCESS *node) const noexcept override;
     146              : 
     147              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     148              :   visit(const AST_STRUCT *node) const noexcept override;
     149              : 
     150              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     151              :   visit(const AST_ATTR_ACCESS *node) const noexcept override;
     152              : 
     153              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     154              :   visit(const AST_METHOD_CALL *node) const noexcept override;
     155              : 
     156              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     157              :   visit(const AST_METHOD_DECL *node) const noexcept override;
     158              : 
     159              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     160              :   visit(const AST_CONSTRUCTOR_DECL *node) const noexcept override;
     161              : 
     162              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     163              :   visit(const AST_SUPER *node) const noexcept override;
     164              : 
     165              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     166              :   visit(const AST_DESTRUCTOR_DECL *node) const noexcept override;
     167              : 
     168              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     169              :   visit(const AST_THIS *node) const noexcept override;
     170              : 
     171              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     172              :   visit(const AST_CONSTRUCTOR_CALL *node) const noexcept override;
     173              : 
     174              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     175              :   visit(const AST_AUTO_DECL *node) const noexcept override;
     176              : 
     177              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     178              :   visit(const AST_VAR_TYPED_DECL *node) const noexcept override;
     179              : 
     180              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     181              :   visit(const AST_VAR_CALL *node) const noexcept override;
     182              : 
     183              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     184              :   visit(const AST_CHAINED *node) const noexcept override;
     185              : 
     186              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     187              :   visit(const Tree *tree) const noexcept override;
     188              : 
     189              :   [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
     190            0 :   analyze(const Tree *tree) const noexcept {
     191            0 :     return visit(tree);
     192            0 :   }
     193              : };
     194              : 
     195              : } // namespace nicole
     196              : 
     197              : #endif
        

Generated by: LCOV version 2.0-1