LCOV - code coverage report
Current view: top level - inc/parsingAnalysis - builder.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2025-04-18 15:53:49 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #ifndef BUILDER_H
       2              : #define BUILDER_H
       3              : 
       4              : #include "ast/assignments/ast_assignment.h"
       5              : 
       6              : #include "ast/conditionals/ast_condition.h"
       7              : #include "ast/conditionals/ast_default.h"
       8              : #include "ast/functions/ast_funcCall.h"
       9              : #include "ast/functions/ast_funcDecl.h"
      10              : #include "ast/functions/ast_return.h"
      11              : 
      12              : #include "ast/literals/ast_bool.h"
      13              : #include "ast/literals/ast_char.h"
      14              : #include "ast/literals/ast_double.h"
      15              : #include "ast/literals/ast_float.h"
      16              : #include "ast/literals/ast_int.h"
      17              : #include "ast/literals/ast_null.h"
      18              : #include "ast/literals/ast_string.h"
      19              : 
      20              : #include "ast/operators/ast_binary.h"
      21              : 
      22              : #include "ast/operators/ast_unary.h"
      23              : 
      24              : #include "ast/userTypes/ast_constructorCall.h"
      25              : #include "ast/userTypes/ast_constructorDecl.h"
      26              : #include "ast/userTypes/ast_destructorDecl.h"
      27              : #include "ast/userTypes/ast_methodDecl.h"
      28              : #include "ast/userTypes/ast_super.h"
      29              : #include "ast/userTypes/ast_this.h"
      30              : #include "ast/vector/ast_index.h"
      31              : #include "ast/vector/ast_vector.h"
      32              : 
      33              : #include "ast/enum/ast_enum.h"
      34              : #include "ast/enum/ast_enumAccess.h"
      35              : #include "ast/userTypes/ast_attrAccess.h"
      36              : #include "ast/userTypes/ast_methodCall.h"
      37              : #include "ast/userTypes/ast_struct.h"
      38              : 
      39              : #include "ast/utils/ast_import.h"
      40              : #include "ast/utils/ast_print.h"
      41              : 
      42              : #include "ast/statements/ast_body.h"
      43              : #include "ast/statements/ast_statement.h"
      44              : 
      45              : #include "ast/loops/ast_doWhile.h"
      46              : #include "ast/loops/ast_for.h"
      47              : #include "ast/loops/ast_pass.h"
      48              : #include "ast/loops/ast_stop.h"
      49              : #include "ast/loops/ast_while.h"
      50              : 
      51              : #include "ast/conditionals/ast_case.h"
      52              : #include "ast/conditionals/ast_if.h"
      53              : #include "ast/conditionals/ast_switch.h"
      54              : #include "ast/conditionals/ast_ternary.h"
      55              : 
      56              : #include "ast/variables/ast_autoDecl.h"
      57              : #include "ast/variables/ast_typedDecl.h"
      58              : #include "ast/variables/ast_varCall.h"
      59              : 
      60              : #include "ast/pointer/ast_delete.h"
      61              : #include "ast/pointer/ast_deref.h"
      62              : #include "ast/pointer/ast_new.h"
      63              : 
      64              : #include "ast/chained/ast_chained.h"
      65              : 
      66              : #include "ast/tree.h"
      67              : 
      68              : #include "../errors.h"
      69              : 
      70              : #include <cstddef>
      71              : #include <expected>
      72              : #include <memory>
      73              : 
      74              : namespace nicole {
      75              : 
      76              : class Builder final {
      77              : private:
      78          384 :   [[nodiscard]] static long long unsigned generateNextId() noexcept {
      79          384 :     static long long unsigned id{0};
      80          384 :     return ++id;
      81          384 :   }
      82              : 
      83              :   Builder() noexcept = delete;
      84              : 
      85              : public:
      86              :   // Literals
      87              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_BOOL>, Error>
      88              :   createBool(const SourceLocation &srcLoc, const bool value) noexcept;
      89              : 
      90              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_CHAR>, Error>
      91              :   createChar(const SourceLocation &srcLoc, const std::string &value) noexcept;
      92              : 
      93              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_DOUBLE>, Error>
      94              :   createDouble(const SourceLocation &srcLoc, const double value) noexcept;
      95              : 
      96              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_FLOAT>, Error>
      97              :   createFloat(const SourceLocation &srcLoc, const float value) noexcept;
      98              : 
      99              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_INT>, Error>
     100              :   createInt(const SourceLocation &srcLoc, const int value) noexcept;
     101              : 
     102              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_NULL>, Error>
     103              :   createNull(const SourceLocation &srcLoc) noexcept;
     104              : 
     105              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_STRING>, Error>
     106              :   createString(const SourceLocation &srcLoc, const std::string value) noexcept;
     107              : 
     108              :   // Vectors
     109              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_VECTOR>, Error>
     110              :   createVector(const SourceLocation &srcLoc,
     111              :                const std::vector<std::shared_ptr<AST>> values) noexcept;
     112              : 
     113              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_INDEX>, Error>
     114              :   createIndex(const SourceLocation &srcLoc,
     115              :               const std::shared_ptr<AST> value) noexcept;
     116              : 
     117              :   // Pointers
     118              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_DELETE>, Error>
     119              :   createDelete(const SourceLocation &srcLoc,
     120              :                const std::shared_ptr<AST> &value) noexcept;
     121              : 
     122              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_NEW>, Error>
     123              :   createNew(const SourceLocation &srcLoc,
     124              :             const std::shared_ptr<AST> &value) noexcept;
     125              : 
     126              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_DEREF>, Error>
     127              :   createDeref(const SourceLocation &srcLoc,
     128              :               const std::shared_ptr<AST> &value) noexcept;
     129              : 
     130              :   // Binary
     131              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_BINARY>, Error>
     132              :   createBinary(const SourceLocation &srcLoc, const Token &op,
     133              :                const std::shared_ptr<AST> &left,
     134              :                const std::shared_ptr<AST> &right) noexcept;
     135              : 
     136              :   // Unary
     137              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_UNARY>, Error>
     138              :   createUnary(const SourceLocation &srcLoc, const Token &op,
     139              :               const std::shared_ptr<AST> &value) noexcept;
     140              : 
     141              :   // Asignment
     142              : 
     143              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_ASSIGNMENT>, Error>
     144              :   createAssignment(const SourceLocation &srcLoc, const Token &op,
     145              :                    const std::shared_ptr<AST> &left,
     146              :                    const std::shared_ptr<AST> &value) noexcept;
     147              : 
     148              :   // Utils
     149              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_PRINT>, Error>
     150              :   createPrint(const SourceLocation &srcLoc,
     151              :               const std::vector<std::shared_ptr<AST>> &values) noexcept;
     152              : 
     153              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_IMPORT>, Error>
     154              :   createImport(const SourceLocation &srcLoc,
     155              :                const std::filesystem::path &path) noexcept;
     156              : 
     157              :   // Statements
     158              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_STATEMENT>, Error>
     159              :   createStatement(const SourceLocation &srcLoc,
     160              :                   const std::shared_ptr<AST> &expression) noexcept;
     161              : 
     162              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_BODY>, Error>
     163              :   createBody(const SourceLocation &srcLoc,
     164              :              const std::vector<std::shared_ptr<AST_STATEMENT>> &body) noexcept;
     165              : 
     166              :   // Loops
     167              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_WHILE>, Error>
     168              :   createWhile(const SourceLocation &srcLoc,
     169              :               const std::shared_ptr<AST_CONDITION> &condition,
     170              :               const std::shared_ptr<AST_BODY> &body) noexcept;
     171              : 
     172              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_FOR>, Error>
     173              :   createFor(const SourceLocation &srcLoc,
     174              :             const std::vector<std::shared_ptr<AST>> &init,
     175              :             const std::shared_ptr<AST_CONDITION> &condition,
     176              :             const std::vector<std::shared_ptr<AST>> &update,
     177              :             const std::shared_ptr<AST_BODY> &body) noexcept;
     178              : 
     179              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_DO_WHILE>, Error>
     180              :   createDoWhile(const SourceLocation &srcLoc,
     181              :                 const std::shared_ptr<AST_BODY> &body,
     182              :                 const std::shared_ptr<AST_CONDITION> &condition) noexcept;
     183              : 
     184              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_PASS>, Error>
     185              :   createPass(const SourceLocation &srcLoc,
     186              :              const std::shared_ptr<AST> &fatherLoop) noexcept;
     187              : 
     188              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_STOP>, Error>
     189              :   createStop(const SourceLocation &srcLoc,
     190              :              const std::shared_ptr<AST> &fatherLoop) noexcept;
     191              : 
     192              :   // Conditionals
     193              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_IF>, Error>
     194              :   createIf(const SourceLocation &srcLoc,
     195              :            const std::shared_ptr<AST_CONDITION> &condition,
     196              :            const std::shared_ptr<AST_BODY> &body,
     197              :            const std::vector<std::shared_ptr<AST_ELSE_IF>> &elseIf,
     198              :            const std::shared_ptr<AST_BODY> &elseBody) noexcept;
     199              : 
     200              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_ELSE_IF>, Error>
     201              :   createElseIf(const SourceLocation &srcLoc,
     202              :                const std::shared_ptr<AST_CONDITION> &condition,
     203              :                const std::shared_ptr<AST_BODY> &body) noexcept;
     204              : 
     205              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_SWITCH>, Error>
     206              :   createSwitch(const SourceLocation &srcLoc,
     207              :                const std::shared_ptr<AST_CONDITION> &condition,
     208              :                const std::vector<std::shared_ptr<AST_CASE>> &cases,
     209              :                const std::shared_ptr<AST_DEFAULT> &default_) noexcept;
     210              : 
     211              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_CASE>, Error>
     212              :   createCase(const SourceLocation &srcLoc, const std::shared_ptr<AST> &match,
     213              :              const std::shared_ptr<AST_BODY> &body) noexcept;
     214              : 
     215              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_DEFAULT>, Error>
     216              :   createDefault(const SourceLocation &srcLoc,
     217              :                 const std::shared_ptr<AST_BODY> &body) noexcept;
     218              : 
     219              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_TERNARY>, Error>
     220              :   createTernary(const SourceLocation &srcLoc,
     221              :                 const std::shared_ptr<AST_CONDITION> &condition,
     222              :                 const std::shared_ptr<AST> &first,
     223              :                 const std::shared_ptr<AST> &second) noexcept;
     224              : 
     225              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_CONDITION>, Error>
     226              :   createCondition(const SourceLocation &srcLoc,
     227              :                   const std::shared_ptr<AST> &expression) noexcept;
     228              : 
     229              :   // Functions
     230              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_FUNC_CALL>, Error>
     231              :   createFunCall(const SourceLocation &srcLoc, const std::string &id,
     232              :                 const std::vector<std::shared_ptr<Type>> &replaceOfGenerics,
     233              :                 const std::vector<std::shared_ptr<AST>> &parameters) noexcept;
     234              : 
     235              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_FUNC_DECL>, Error>
     236              :   createFuncDecl(const SourceLocation &srcLoc, const std::string &id,
     237              :                  const std::vector<GenericParameter> &generics,
     238              :                  const Parameters &params,
     239              :                  const std::shared_ptr<Type> &returnType,
     240              :                  const std::shared_ptr<AST_BODY> &body) noexcept;
     241              : 
     242              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_RETURN>, Error>
     243              :   createReturn(const SourceLocation &srcLoc,
     244              :                const std::shared_ptr<AST> &value) noexcept;
     245              : 
     246              :   // Enum
     247              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_ENUM>, Error>
     248              :   createEnum(const SourceLocation &srcLoc, const std::string &id,
     249              :              const std::vector<std::string> &enumIdentifiers) noexcept;
     250              : 
     251              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_ENUM_ACCESS>, Error>
     252              :   createEnumAccess(const SourceLocation &srcLoc, const std::string &id,
     253              :                    const std::string &identifiers) noexcept;
     254              : 
     255              :   // Usert types
     256              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_STRUCT>, Error>
     257              :   createStruct(const SourceLocation &srcLoc, const std::string &id,
     258              :                const std::vector<GenericParameter> &generics,
     259              :                const std::shared_ptr<Type> &fatherType,
     260              :                const Attributes &attributes,
     261              :                const std::vector<std::shared_ptr<AST_METHOD_DECL>> &methods,
     262              :                const std::shared_ptr<AST_CONSTRUCTOR_DECL> &constructor,
     263              :                const std::shared_ptr<AST_DESTRUCTOR_DECL> &destructor) noexcept;
     264              : 
     265              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_ATTR_ACCESS>, Error>
     266              :   createAttrAccess(const SourceLocation &srcLoc,
     267              :                    const std::string &id) noexcept;
     268              : 
     269              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_METHOD_CALL>, Error>
     270              :   createMethodCall(
     271              :       const SourceLocation &srcLoc, const std::string &id,
     272              :       const std::vector<std::shared_ptr<Type>> &replaceOfGenerics,
     273              :       const std::vector<std::shared_ptr<AST>> &parameters) noexcept;
     274              : 
     275              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_METHOD_DECL>, Error>
     276              :   createMethodDecl(const SourceLocation &srcLoc, const std::string &id,
     277              :                    const std::vector<GenericParameter> &generics,
     278              :                    const Parameters &params,
     279              : 
     280              :                    const std::shared_ptr<Type> &returnType,
     281              :                    const std::shared_ptr<AST_BODY> &body,
     282              :                    const bool isVirtual) noexcept;
     283              : 
     284              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_CONSTRUCTOR_DECL>,
     285              :                                      Error>
     286              :   createConstructorDecl(const SourceLocation &srcLoc, const std::string &id,
     287              :                         const std::vector<GenericParameter> &generics,
     288              :                         const Parameters &params,
     289              :                         const std::shared_ptr<AST_SUPER> &super,
     290              :                         const std::shared_ptr<Type> &returnType,
     291              :                         const std::shared_ptr<AST_BODY> &body) noexcept;
     292              : 
     293              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_DESTRUCTOR_DECL>,
     294              :                                      Error>
     295              :   createDestructorDecl(const SourceLocation &srcLoc, const std::string &id,
     296              :                        const std::shared_ptr<AST_BODY> &body) noexcept;
     297              : 
     298              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_SUPER>, Error>
     299              :   createSuper(const SourceLocation &srcLoc,
     300              :               const std::shared_ptr<Type> &fatherType,
     301              :               const std::vector<std::shared_ptr<Type>> &replacements,
     302              :               const std::vector<std::shared_ptr<AST>> &arguments) noexcept;
     303              : 
     304              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_THIS>, Error>
     305              :   createThis(const SourceLocation &srcLoc) noexcept;
     306              : 
     307              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_CONSTRUCTOR_CALL>,
     308              :                                      Error>
     309              :   createConstructorCall(
     310              :       const SourceLocation &srcLoc, const std::string &id,
     311              :       const std::vector<std::shared_ptr<Type>> &replaceOfGenerics,
     312              :       const std::vector<std::shared_ptr<AST>> &parameters) noexcept;
     313              : 
     314              :   // Variables
     315              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_AUTO_DECL>, Error>
     316              :   createAutoDecl(const SourceLocation &srcLoc, const std::string &id,
     317              :                  const std::shared_ptr<AST> &value,
     318              :                  const bool isConst) noexcept;
     319              : 
     320              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_VAR_TYPED_DECL>, Error>
     321              :   createVarTypedtDecl(const SourceLocation &srcLoc, const std::string &id,
     322              :                       const std::shared_ptr<Type> &type,
     323              :                       const std::shared_ptr<AST> &value) noexcept;
     324              : 
     325              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_VAR_CALL>, Error>
     326              :   createVarCall(const SourceLocation &srcLoc, const std::string &id) noexcept;
     327              : 
     328              :   // Chained expression
     329              :   [[nodiscard]] static std::expected<std::shared_ptr<AST_CHAINED>, Error>
     330              :   createChained(const SourceLocation &srcLoc, const std::shared_ptr<AST> &base,
     331              :                 const std::vector<std::shared_ptr<AST>> &operations) noexcept;
     332              : 
     333              :   // Tree
     334              :   [[nodiscard]] static std::expected<std::shared_ptr<Tree>, Error>
     335              :   createTree(const std::shared_ptr<AST_BODY> &statements) noexcept;
     336              : };
     337              : 
     338              : } // namespace nicole
     339              : 
     340              : #endif
        

Generated by: LCOV version 2.0-1