LCOV - code coverage report
Current view: top level - src/parsingAnalysis - builder.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 18.3 % 491 90
Test Date: 2025-04-18 15:53:49 Functions: 20.0 % 50 10

            Line data    Source code
       1              : #include "../../inc/parsingAnalysis/builder.h"
       2              : #include <memory>
       3              : 
       4              : namespace nicole {
       5              : 
       6              : std::expected<std::shared_ptr<AST_BOOL>, Error>
       7           38 : Builder::createBool(const SourceLocation &srcLoc, const bool value) noexcept {
       8           38 :   return std::make_shared<AST_BOOL>(generateNextId(), srcLoc, value);
       9           38 : }
      10              : 
      11              : std::expected<std::shared_ptr<AST_CHAR>, Error>
      12              : Builder::createChar(const SourceLocation &srcLoc,
      13            0 :                     const std::string &value) noexcept {
      14            0 :   const std::string strNoQuotes{value.substr(1, value.size() - 2)};
      15            0 :   char result;
      16            0 :   if (strNoQuotes.size() == 1) {
      17            0 :     result = strNoQuotes[0];
      18            0 :   }
      19              :   // Si hay un carácter de escape, comprobar cuál es
      20            0 :   if (strNoQuotes[0] == '\\' && strNoQuotes.size() == 2) {
      21            0 :     switch (strNoQuotes[1]) {
      22            0 :     case 'n':
      23            0 :       result = '\n';
      24            0 :     case 't':
      25            0 :       result = '\t';
      26            0 :     case '\\':
      27            0 :       result = '\\';
      28            0 :     case '\'':
      29            0 :       result = '\'';
      30            0 :     case '\"':
      31            0 :       result = '\"';
      32            0 :     default:
      33            0 :       result = strNoQuotes[1];
      34            0 :     }
      35            0 :   }
      36            0 :   return std::make_shared<AST_CHAR>(generateNextId(), srcLoc, result);
      37            0 : }
      38              : 
      39              : std::expected<std::shared_ptr<AST_DOUBLE>, Error>
      40              : Builder::createDouble(const SourceLocation &srcLoc,
      41            0 :                       const double value) noexcept {
      42            0 :   return std::make_shared<AST_DOUBLE>(generateNextId(), srcLoc, value);
      43            0 : }
      44              : 
      45              : std::expected<std::shared_ptr<AST_FLOAT>, Error>
      46            0 : Builder::createFloat(const SourceLocation &srcLoc, const float value) noexcept {
      47            0 :   return std::make_shared<AST_FLOAT>(generateNextId(), srcLoc, value);
      48            0 : }
      49              : 
      50              : std::expected<std::shared_ptr<AST_INT>, Error>
      51            3 : Builder::createInt(const SourceLocation &srcLoc, const int value) noexcept {
      52            3 :   return std::make_shared<AST_INT>(generateNextId(), srcLoc, value);
      53            3 : }
      54              : 
      55              : std::expected<std::shared_ptr<AST_NULL>, Error>
      56            0 : Builder::createNull(const SourceLocation &srcLoc) noexcept {
      57            0 :   return std::make_shared<AST_NULL>(generateNextId(), srcLoc);
      58            0 : }
      59              : 
      60              : std::expected<std::shared_ptr<AST_STRING>, Error>
      61              : Builder::createString(const SourceLocation &srcLoc,
      62            0 :                       const std::string value) noexcept {
      63            0 :   std::string result;
      64            0 :   if (value.size() < 2) {
      65            0 :     return createError(ERROR_TYPE::SINTAX, "ill formed string");
      66            0 :   }
      67            0 :   const std::string strNoQuotes = value.substr(1, value.size() - 2);
      68            0 :   for (size_t i = 0; i < strNoQuotes.length(); ++i) {
      69            0 :     if (strNoQuotes[i] == '\\' && i + 1 < strNoQuotes.length()) {
      70            0 :       switch (strNoQuotes[i + 1]) {
      71            0 :       case 'n':
      72            0 :         result.push_back('\n');
      73            0 :         break;
      74            0 :       case 't':
      75            0 :         result.push_back('\t');
      76            0 :         break;
      77            0 :       case '\\':
      78            0 :         result.push_back('\\');
      79            0 :         break;
      80            0 :       case '\"':
      81            0 :         result.push_back('\"');
      82            0 :         break;
      83            0 :       default:
      84            0 :         result.push_back(strNoQuotes[i + 1]);
      85            0 :         break;
      86            0 :       }
      87            0 :       i++; // Saltar el carácter escapado
      88            0 :     } else {
      89            0 :       result.push_back(strNoQuotes[i]);
      90            0 :     }
      91            0 :   }
      92            0 :   return std::make_shared<AST_STRING>(generateNextId(), srcLoc, result);
      93            0 : }
      94              : 
      95              : std::expected<std::shared_ptr<AST_VECTOR>, Error>
      96              : Builder::createVector(const SourceLocation &srcLoc,
      97            0 :                       const std::vector<std::shared_ptr<AST>> values) noexcept {
      98            0 :   const auto astVector{
      99            0 :       std::make_shared<AST_VECTOR>(generateNextId(), srcLoc, values)};
     100            0 :   const std::vector<std::shared_ptr<AST>> &expressions{astVector->values()};
     101            0 :   for (const auto &expression : expressions) {
     102            0 :     if (expression) {
     103            0 :       expression->setFather(astVector);
     104            0 :     }
     105            0 :   }
     106            0 :   return astVector;
     107            0 : }
     108              : 
     109              : std::expected<std::shared_ptr<AST_INDEX>, Error>
     110              : Builder::createIndex(const SourceLocation &srcLoc,
     111            0 :                      const std::shared_ptr<AST> value) noexcept {
     112            0 :   const auto astIndex{
     113            0 :       std::make_shared<AST_INDEX>(generateNextId(), srcLoc, value)};
     114            0 :   if (value) {
     115            0 :     value->setFather(astIndex);
     116            0 :   }
     117            0 :   return astIndex;
     118            0 : }
     119              : 
     120              : std::expected<std::shared_ptr<AST_DELETE>, Error>
     121              : Builder::createDelete(const SourceLocation &srcLoc,
     122            0 :                       const std::shared_ptr<AST> &value) noexcept {
     123            0 :   const auto astDelete{
     124            0 :       std::make_shared<AST_DELETE>(generateNextId(), srcLoc, value)};
     125            0 :   if (value) {
     126            0 :     value->setFather(astDelete);
     127            0 :   }
     128            0 :   return astDelete;
     129            0 : }
     130              : 
     131              : std::expected<std::shared_ptr<AST_NEW>, Error>
     132              : Builder::createNew(const SourceLocation &srcLoc,
     133            0 :                    const std::shared_ptr<AST> &value) noexcept {
     134            0 :   const auto astNew{std::make_shared<AST_NEW>(generateNextId(), srcLoc, value)};
     135            0 :   if (value) {
     136            0 :     value->setFather(astNew);
     137            0 :   }
     138            0 :   return astNew;
     139            0 : }
     140              : 
     141              : std::expected<std::shared_ptr<AST_DEREF>, Error>
     142              : Builder::createDeref(const SourceLocation &srcLoc,
     143            0 :                      const std::shared_ptr<AST> &value) noexcept {
     144            0 :   const auto astDeref{
     145            0 :       std::make_shared<AST_DEREF>(generateNextId(), srcLoc, value)};
     146            0 :   if (value) {
     147            0 :     value->setFather(astDeref);
     148            0 :   }
     149            0 :   return astDeref;
     150            0 : }
     151              : 
     152              : std::expected<std::shared_ptr<AST_BINARY>, Error>
     153              : Builder::createBinary(const SourceLocation &srcLoc, const Token &op,
     154              :                       const std::shared_ptr<AST> &left,
     155            0 :                       const std::shared_ptr<AST> &right) noexcept {
     156            0 :   const auto astBinary{
     157            0 :       std::make_shared<AST_BINARY>(generateNextId(), srcLoc, op, left, right)};
     158            0 :   if (left) {
     159            0 :     left->setFather(astBinary);
     160            0 :   }
     161            0 :   if (right) {
     162            0 :     right->setFather(astBinary);
     163            0 :   }
     164            0 :   return astBinary;
     165            0 : }
     166              : 
     167              : std::expected<std::shared_ptr<AST_UNARY>, Error>
     168              : Builder::createUnary(const SourceLocation &srcLoc, const Token &op,
     169            0 :                      const std::shared_ptr<AST> &value) noexcept {
     170            0 :   const auto astUnary{
     171            0 :       std::make_shared<AST_UNARY>(generateNextId(), srcLoc, op, value)};
     172            0 :   if (value) {
     173            0 :     value->setFather(astUnary);
     174            0 :   }
     175            0 :   return astUnary;
     176            0 : }
     177              : 
     178              : std::expected<std::shared_ptr<AST_ASSIGNMENT>, Error>
     179              : Builder::createAssignment(const SourceLocation &srcLoc, const Token &op,
     180              :                           const std::shared_ptr<AST> &left,
     181            0 :                           const std::shared_ptr<AST> &value) noexcept {
     182            0 :   const auto astSelfAssignment{std::make_shared<AST_ASSIGNMENT>(
     183            0 :       generateNextId(), srcLoc, op, left, value)};
     184            0 :   if (left) {
     185            0 :     left->setFather(astSelfAssignment);
     186            0 :   }
     187            0 :   if (value) {
     188            0 :     value->setFather(astSelfAssignment);
     189            0 :   }
     190            0 :   return astSelfAssignment;
     191            0 : }
     192              : 
     193              : std::expected<std::shared_ptr<AST_PRINT>, Error>
     194              : Builder::createPrint(const SourceLocation &srcLoc,
     195            0 :                      const std::vector<std::shared_ptr<AST>> &values) noexcept {
     196            0 :   const auto astPrint{
     197            0 :       std::make_shared<AST_PRINT>(generateNextId(), srcLoc, values)};
     198            0 :   const std::vector<std::shared_ptr<AST>> &values__{astPrint->values()};
     199            0 :   for (const auto &values_ : values__) {
     200            0 :     if (values_) {
     201            0 :       values_->setFather(astPrint);
     202            0 :     }
     203            0 :   }
     204            0 :   return astPrint;
     205            0 : }
     206              : 
     207              : std::expected<std::shared_ptr<AST_IMPORT>, Error>
     208              : Builder::createImport(const SourceLocation &srcLoc,
     209            0 :                       const std::filesystem::path &path) noexcept {
     210            0 :   const auto astImport{
     211            0 :       std::make_shared<AST_IMPORT>(generateNextId(), srcLoc, path)};
     212            0 :   return astImport;
     213            0 : }
     214              : 
     215              : std::expected<std::shared_ptr<AST_STATEMENT>, Error>
     216              : Builder::createStatement(const SourceLocation &srcLoc,
     217           15 :                          const std::shared_ptr<AST> &expression) noexcept {
     218           15 :   const auto astStatement{
     219           15 :       std::make_shared<AST_STATEMENT>(generateNextId(), srcLoc, expression)};
     220           15 :   if (expression) {
     221           15 :     expression->setFather(astStatement);
     222           15 :   }
     223           15 :   return astStatement;
     224           15 : }
     225              : 
     226              : std::expected<std::shared_ptr<AST_BODY>, Error> Builder::createBody(
     227              :     const SourceLocation &srcLoc,
     228           17 :     const std::vector<std::shared_ptr<AST_STATEMENT>> &body) noexcept {
     229           17 :   const auto astBody{
     230           17 :       std::make_shared<AST_BODY>(generateNextId(), srcLoc, body)};
     231           17 :   const std::vector<std::shared_ptr<AST_STATEMENT>> &statements{
     232           17 :       astBody->body()};
     233           17 :   for (const auto &statement : statements) {
     234           11 :     if (statement) {
     235           11 :       statement->setFather(astBody);
     236           11 :     }
     237           11 :   }
     238           17 :   return astBody;
     239           17 : }
     240              : 
     241              : std::expected<std::shared_ptr<AST_WHILE>, Error>
     242              : Builder::createWhile(const SourceLocation &srcLoc,
     243              :                      const std::shared_ptr<AST_CONDITION> &condition,
     244            2 :                      const std::shared_ptr<AST_BODY> &body) noexcept {
     245            2 :   const auto astWhile{
     246            2 :       std::make_shared<AST_WHILE>(generateNextId(), srcLoc, condition, body)};
     247            2 :   if (condition) {
     248            2 :     condition->setFather(astWhile);
     249            2 :   }
     250            2 :   if (body) {
     251            2 :     body->setFather(astWhile);
     252            2 :   }
     253            2 :   return astWhile;
     254            2 : }
     255              : 
     256              : std::expected<std::shared_ptr<AST_FOR>, Error>
     257              : Builder::createFor(const SourceLocation &srcLoc,
     258              :                    const std::vector<std::shared_ptr<AST>> &init,
     259              :                    const std::shared_ptr<AST_CONDITION> &condition,
     260              :                    const std::vector<std::shared_ptr<AST>> &update,
     261            2 :                    const std::shared_ptr<AST_BODY> &body) noexcept {
     262            2 :   const auto astFor{std::make_shared<AST_FOR>(generateNextId(), srcLoc, init,
     263            2 :                                               condition, update, body)};
     264            2 :   const std::vector<std::shared_ptr<AST>> &init__{astFor->init()};
     265            2 :   for (const auto &init_ : init__) {
     266            0 :     if (init_) {
     267            0 :       astFor->setFather(init_);
     268            0 :     }
     269            0 :   }
     270            2 :   if (condition) {
     271            2 :     condition->setFather(astFor);
     272            2 :   }
     273            2 :   const std::vector<std::shared_ptr<AST>> &update__{astFor->update()};
     274            2 :   for (const auto &update_ : update__) {
     275            0 :     if (update_) {
     276            0 :       astFor->setFather(update_);
     277            0 :     }
     278            0 :   }
     279            2 :   if (body) {
     280            2 :     body->setFather(astFor);
     281            2 :   }
     282            2 :   return astFor;
     283            2 : }
     284              : 
     285              : std::expected<std::shared_ptr<AST_DO_WHILE>, Error> Builder::createDoWhile(
     286              :     const SourceLocation &srcLoc, const std::shared_ptr<AST_BODY> &body,
     287            2 :     const std::shared_ptr<AST_CONDITION> &condition) noexcept {
     288            2 :   const auto astDoWhile{std::make_shared<AST_DO_WHILE>(generateNextId(), srcLoc,
     289            2 :                                                        body, condition)};
     290            2 :   if (condition) {
     291            2 :     condition->setFather(astDoWhile);
     292            2 :   }
     293            2 :   if (body) {
     294            2 :     body->setFather(astDoWhile);
     295            2 :   }
     296            2 :   return astDoWhile;
     297            2 : }
     298              : 
     299              : std::expected<std::shared_ptr<AST_PASS>, Error>
     300              : Builder::createPass(const SourceLocation &srcLoc,
     301            0 :                     const std::shared_ptr<AST> &fatherLoop) noexcept {
     302            0 :   const auto astPass{
     303            0 :       std::make_shared<AST_PASS>(generateNextId(), srcLoc, fatherLoop)};
     304            0 :   return astPass;
     305            0 : }
     306              : 
     307              : std::expected<std::shared_ptr<AST_STOP>, Error>
     308              : Builder::createStop(const SourceLocation &srcLoc,
     309            0 :                     const std::shared_ptr<AST> &fatherLoop) noexcept {
     310            0 :   const auto astStop{
     311            0 :       std::make_shared<AST_STOP>(generateNextId(), srcLoc, fatherLoop)};
     312            0 :   return astStop;
     313            0 : }
     314              : 
     315              : std::expected<std::shared_ptr<AST_IF>, Error>
     316              : Builder::createIf(const SourceLocation &srcLoc,
     317              :                   const std::shared_ptr<AST_CONDITION> &condition,
     318              :                   const std::shared_ptr<AST_BODY> &body,
     319              :                   const std::vector<std::shared_ptr<AST_ELSE_IF>> &elseIf,
     320            0 :                   const std::shared_ptr<AST_BODY> &elseBody) noexcept {
     321            0 :   const auto astIf{std::make_shared<AST_IF>(generateNextId(), srcLoc, condition,
     322            0 :                                             body, elseIf, elseBody)};
     323            0 :   if (condition) {
     324            0 :     condition->setFather(astIf);
     325            0 :   }
     326            0 :   if (body) {
     327            0 :     body->setFather(astIf);
     328            0 :   }
     329            0 :   const std::vector<std::shared_ptr<AST_ELSE_IF>> &elseIfs{astIf->elseIf()};
     330            0 :   for (const auto &elseIf_ : elseIfs) {
     331            0 :     if (elseIf_) {
     332            0 :       elseIf_->setFather(astIf);
     333            0 :     }
     334            0 :   }
     335            0 :   if (elseBody) {
     336            0 :     elseBody->setFather(astIf);
     337            0 :   }
     338            0 :   return astIf;
     339            0 : }
     340              : 
     341              : std::expected<std::shared_ptr<AST_ELSE_IF>, Error>
     342              : Builder::createElseIf(const SourceLocation &srcLoc,
     343              :                       const std::shared_ptr<AST_CONDITION> &condition,
     344            1 :                       const std::shared_ptr<AST_BODY> &body) noexcept {
     345            1 :   const auto astIf{
     346            1 :       std::make_shared<AST_ELSE_IF>(generateNextId(), srcLoc, condition, body)};
     347            1 :   if (condition) {
     348            1 :     condition->setFather(astIf);
     349            1 :   }
     350            1 :   if (body) {
     351            1 :     body->setFather(astIf);
     352            1 :   }
     353            1 :   return astIf;
     354            1 : }
     355              : 
     356              : std::expected<std::shared_ptr<AST_SWITCH>, Error>
     357              : Builder::createSwitch(const SourceLocation &srcLoc,
     358              :                       const std::shared_ptr<AST_CONDITION> &condition,
     359              :                       const std::vector<std::shared_ptr<AST_CASE>> &cases,
     360            0 :                       const std::shared_ptr<AST_DEFAULT> &default_) noexcept {
     361            0 :   const auto astSwitch{std::make_shared<AST_SWITCH>(
     362            0 :       generateNextId(), srcLoc, condition, cases, default_)};
     363            0 :   if (condition) {
     364            0 :     condition->setFather(astSwitch);
     365            0 :   }
     366            0 :   const std::vector<std::shared_ptr<AST_CASE>> &cases_{astSwitch->cases()};
     367            0 :   for (const auto &statement : cases_) {
     368            0 :     if (statement) {
     369            0 :       statement->setFather(astSwitch);
     370            0 :     }
     371            0 :   }
     372            0 :   if (default_) {
     373            0 :     default_->setFather(astSwitch);
     374            0 :   }
     375            0 :   return astSwitch;
     376            0 : }
     377              : 
     378              : std::expected<std::shared_ptr<AST_CASE>, Error>
     379              : Builder::createCase(const SourceLocation &srcLoc,
     380              :                     const std::shared_ptr<AST> &match,
     381            0 :                     const std::shared_ptr<AST_BODY> &body) noexcept {
     382            0 :   const auto astCase{
     383            0 :       std::make_shared<AST_CASE>(generateNextId(), srcLoc, match, body)};
     384            0 :   if (match) {
     385            0 :     match->setFather(astCase);
     386            0 :   }
     387            0 :   if (body) {
     388            0 :     body->setFather(astCase);
     389            0 :   }
     390            0 :   return astCase;
     391            0 : }
     392              : 
     393              : std::expected<std::shared_ptr<AST_DEFAULT>, Error>
     394              : Builder::createDefault(const SourceLocation &srcLoc,
     395            1 :                        const std::shared_ptr<AST_BODY> &body) noexcept {
     396            1 :   const auto astDefault{
     397            1 :       std::make_shared<AST_DEFAULT>(generateNextId(), srcLoc, body)};
     398            1 :   if (body) {
     399            1 :     body->setFather(astDefault);
     400            1 :   }
     401            1 :   return astDefault;
     402            1 : }
     403              : 
     404              : std::expected<std::shared_ptr<AST_TERNARY>, Error>
     405              : Builder::createTernary(const SourceLocation &srcLoc,
     406              :                        const std::shared_ptr<AST_CONDITION> &condition,
     407              :                        const std::shared_ptr<AST> &first,
     408            0 :                        const std::shared_ptr<AST> &second) noexcept {
     409            0 :   const auto astTernanry{std::make_shared<AST_TERNARY>(
     410            0 :       generateNextId(), srcLoc, condition, first, second)};
     411            0 :   if (condition) {
     412            0 :     condition->setFather(astTernanry);
     413            0 :   }
     414            0 :   if (first) {
     415            0 :     first->setFather(astTernanry);
     416            0 :   }
     417            0 :   if (second) {
     418            0 :     second->setFather(astTernanry);
     419            0 :   }
     420            0 :   return astTernanry;
     421            0 : }
     422              : 
     423              : std::expected<std::shared_ptr<AST_CONDITION>, Error>
     424              : Builder::createCondition(const SourceLocation &srcLoc,
     425           15 :                          const std::shared_ptr<AST> &expression) noexcept {
     426           15 :   const auto astCondition{
     427           15 :       std::make_shared<AST_CONDITION>(generateNextId(), srcLoc, expression)};
     428           15 :   if (expression) {
     429           15 :     expression->setFather(astCondition);
     430           15 :   }
     431           15 :   return astCondition;
     432           15 : }
     433              : 
     434              : std::expected<std::shared_ptr<AST_FUNC_CALL>, Error> Builder::createFunCall(
     435              :     const SourceLocation &srcLoc, const std::string &id,
     436              :     const std::vector<std::shared_ptr<Type>> &replaceOfGenerics,
     437            0 :     const std::vector<std::shared_ptr<AST>> &parameters) noexcept {
     438            0 :   const auto astFuncCall{std::make_shared<AST_FUNC_CALL>(
     439            0 :       generateNextId(), srcLoc, id, replaceOfGenerics, parameters)};
     440            0 :   const std::vector<std::shared_ptr<AST>> &parameters__{
     441            0 :       astFuncCall->parameters()};
     442            0 :   for (const auto &parameters_ : parameters__) {
     443            0 :     if (parameters_) {
     444            0 :       parameters_->setFather(astFuncCall);
     445            0 :     }
     446            0 :   }
     447            0 :   return astFuncCall;
     448            0 : }
     449              : 
     450              : std::expected<std::shared_ptr<AST_FUNC_DECL>, Error>
     451              : Builder::createFuncDecl(const SourceLocation &srcLoc, const std::string &id,
     452              :                         const std::vector<GenericParameter> &generics,
     453              :                         const Parameters &params,
     454              :                         const std::shared_ptr<Type> &returnType,
     455            0 :                         const std::shared_ptr<AST_BODY> &body) noexcept {
     456            0 :   const auto astFuncDecl{std::make_shared<AST_FUNC_DECL>(
     457            0 :       generateNextId(), srcLoc, id, generics, params, returnType, body)};
     458            0 :   if (body) {
     459            0 :     body->setFather(astFuncDecl);
     460            0 :   }
     461            0 :   return astFuncDecl;
     462            0 : }
     463              : 
     464              : std::expected<std::shared_ptr<AST_RETURN>, Error>
     465              : Builder::createReturn(const SourceLocation &srcLoc,
     466            0 :                       const std::shared_ptr<AST> &value) noexcept {
     467            0 :   const auto astReturn{
     468            0 :       std::make_shared<AST_RETURN>(generateNextId(), srcLoc, value)};
     469            0 :   if (value) {
     470            0 :     value->setFather(astReturn);
     471            0 :   }
     472            0 :   return astReturn;
     473            0 : }
     474              : 
     475              : std::expected<std::shared_ptr<AST_ENUM>, Error>
     476              : Builder::createEnum(const SourceLocation &srcLoc, const std::string &id,
     477            0 :                     const std::vector<std::string> &enumIdentifiers) noexcept {
     478            0 :   return std::make_shared<AST_ENUM>(generateNextId(), srcLoc, id,
     479            0 :                                     enumIdentifiers);
     480            0 : }
     481              : 
     482              : std::expected<std::shared_ptr<AST_ENUM_ACCESS>, Error>
     483              : Builder::createEnumAccess(const SourceLocation &srcLoc, const std::string &id,
     484            0 :                           const std::string &identifiers) noexcept {
     485            0 :   return std::make_shared<AST_ENUM_ACCESS>(generateNextId(), srcLoc, id,
     486            0 :                                            identifiers);
     487            0 : }
     488              : 
     489              : std::expected<std::shared_ptr<AST_STRUCT>, Error> Builder::createStruct(
     490              :     const SourceLocation &srcLoc, const std::string &id,
     491              :     const std::vector<GenericParameter> &generics,
     492              :     const std::shared_ptr<Type> &fatherType, const Attributes &attributes,
     493              :     const std::vector<std::shared_ptr<AST_METHOD_DECL>> &methods,
     494              :     const std::shared_ptr<AST_CONSTRUCTOR_DECL> &constructor,
     495            0 :     const std::shared_ptr<AST_DESTRUCTOR_DECL> &destructor) noexcept {
     496            0 :   const auto astStruct{std::make_shared<AST_STRUCT>(
     497            0 :       generateNextId(), srcLoc, id, generics, fatherType, attributes, methods,
     498            0 :       constructor, destructor)};
     499            0 :   const std::vector<std::shared_ptr<AST_METHOD_DECL>> &methods__{
     500            0 :       astStruct->methods()};
     501            0 :   for (const auto &methods_ : methods__) {
     502            0 :     if (methods_) {
     503            0 :       methods_->setFather(astStruct);
     504            0 :     }
     505            0 :   }
     506            0 :   if (constructor) {
     507            0 :     constructor->setFather(astStruct);
     508            0 :   }
     509            0 :   if (destructor) {
     510            0 :     destructor->setFather(astStruct);
     511            0 :   }
     512            0 :   return astStruct;
     513            0 : }
     514              : 
     515              : std::expected<std::shared_ptr<AST_ATTR_ACCESS>, Error>
     516              : Builder::createAttrAccess(const SourceLocation &srcLoc,
     517            0 :                           const std::string &id) noexcept {
     518            0 :   return std::make_shared<AST_ATTR_ACCESS>(generateNextId(), srcLoc, id);
     519            0 : }
     520              : 
     521              : std::expected<std::shared_ptr<AST_METHOD_CALL>, Error>
     522              : Builder::createMethodCall(
     523              :     const SourceLocation &srcLoc, const std::string &id,
     524              :     const std::vector<std::shared_ptr<Type>> &replaceOfGenerics,
     525            0 :     const std::vector<std::shared_ptr<AST>> &parameters) noexcept {
     526            0 :   const auto astMethodCall{std::make_shared<AST_METHOD_CALL>(
     527            0 :       generateNextId(), srcLoc, id, replaceOfGenerics, parameters)};
     528            0 :   const std::vector<std::shared_ptr<AST>> &parameters__{
     529            0 :       astMethodCall->parameters()};
     530            0 :   for (const auto &parameters_ : parameters__) {
     531            0 :     if (parameters_) {
     532            0 :       parameters_->setFather(astMethodCall);
     533            0 :     }
     534            0 :   }
     535            0 :   return astMethodCall;
     536            0 : }
     537              : 
     538              : std::expected<std::shared_ptr<AST_METHOD_DECL>, Error>
     539              : Builder::createMethodDecl(const SourceLocation &srcLoc, const std::string &id,
     540              :                           const std::vector<GenericParameter> &generics,
     541              :                           const Parameters &params,
     542              : 
     543              :                           const std::shared_ptr<Type> &returnType,
     544              :                           const std::shared_ptr<AST_BODY> &body,
     545            0 :                           const bool isVirtual) noexcept {
     546            0 :   const auto astMethodDecl{
     547            0 :       std::make_shared<AST_METHOD_DECL>(generateNextId(), srcLoc, id, generics,
     548            0 :                                         params, returnType, body, isVirtual)};
     549            0 :   if (body) {
     550            0 :     body->setFather(astMethodDecl);
     551            0 :   }
     552            0 :   return astMethodDecl;
     553            0 : }
     554              : 
     555              : std::expected<std::shared_ptr<AST_CONSTRUCTOR_CALL>, Error>
     556              : Builder::createConstructorCall(
     557              :     const SourceLocation &srcLoc, const std::string &id,
     558              :     const std::vector<std::shared_ptr<Type>> &replaceOfGenerics,
     559            0 :     const std::vector<std::shared_ptr<AST>> &parameters) noexcept {
     560            0 :   const auto astConstructorall{std::make_shared<AST_CONSTRUCTOR_CALL>(
     561            0 :       generateNextId(), srcLoc, id, replaceOfGenerics, parameters)};
     562            0 :   const std::vector<std::shared_ptr<AST>> &parameters__{
     563            0 :       astConstructorall->parameters()};
     564            0 :   for (const auto &parameters_ : parameters__) {
     565            0 :     if (parameters_) {
     566            0 :       parameters_->setFather(astConstructorall);
     567            0 :     }
     568            0 :   }
     569            0 :   return astConstructorall;
     570            0 : }
     571              : 
     572              : std::expected<std::shared_ptr<AST_CONSTRUCTOR_DECL>, Error>
     573              : Builder::createConstructorDecl(const SourceLocation &srcLoc,
     574              :                                const std::string &id,
     575              :                                const std::vector<GenericParameter> &generics,
     576              :                                const Parameters &params,
     577              :                                const std::shared_ptr<AST_SUPER> &super,
     578              :                                const std::shared_ptr<Type> &returnType,
     579            0 :                                const std::shared_ptr<AST_BODY> &body) noexcept {
     580            0 :   const auto astConstructor{std::make_shared<AST_CONSTRUCTOR_DECL>(
     581            0 :       generateNextId(), srcLoc, id, generics, params, super, returnType, body)};
     582            0 :   if (super) {
     583            0 :     super->setFather(astConstructor);
     584            0 :   }
     585            0 :   if (body) {
     586            0 :     body->setFather(astConstructor);
     587            0 :   }
     588            0 :   return astConstructor;
     589            0 : }
     590              : 
     591              : std::expected<std::shared_ptr<AST_SUPER>, Error> Builder::createSuper(
     592              :     const SourceLocation &srcLoc, const std::shared_ptr<Type> &fatherType,
     593              :     const std::vector<std::shared_ptr<Type>> &replacements,
     594            0 :     const std::vector<std::shared_ptr<AST>> &arguments) noexcept {
     595            0 :   const auto astSuper{std::make_shared<AST_SUPER>(
     596            0 :       generateNextId(), srcLoc, fatherType, replacements, arguments)};
     597            0 :   const std::vector<std::shared_ptr<AST>> &values__{astSuper->arguments()};
     598            0 :   for (const auto &values_ : values__) {
     599            0 :     if (values_) {
     600            0 :       values_->setFather(astSuper);
     601            0 :     }
     602            0 :   }
     603            0 :   return astSuper;
     604            0 : }
     605              : 
     606              : std::expected<std::shared_ptr<AST_DESTRUCTOR_DECL>, Error>
     607              : Builder::createDestructorDecl(const SourceLocation &srcLoc,
     608              :                               const std::string &id,
     609            0 :                               const std::shared_ptr<AST_BODY> &body) noexcept {
     610            0 :   const auto astConstructor{std::make_shared<AST_DESTRUCTOR_DECL>(
     611            0 :       generateNextId(), srcLoc, id, body)};
     612            0 :   if (body) {
     613            0 :     body->setFather(astConstructor);
     614            0 :   }
     615            0 :   return astConstructor;
     616            0 : }
     617              : 
     618              : std::expected<std::shared_ptr<AST_THIS>, Error>
     619            0 : Builder::createThis(const SourceLocation &srcLoc) noexcept {
     620            0 :   const auto astThis{std::make_shared<AST_THIS>(generateNextId(), srcLoc)};
     621            0 :   return astThis;
     622            0 : }
     623              : 
     624              : std::expected<std::shared_ptr<AST_AUTO_DECL>, Error>
     625              : Builder::createAutoDecl(const SourceLocation &srcLoc, const std::string &id,
     626              :                         const std::shared_ptr<AST> &value,
     627            0 :                         const bool isConst) noexcept {
     628            0 :   const auto astAutoDecl{std::make_shared<AST_AUTO_DECL>(
     629            0 :       generateNextId(), srcLoc, id, value, isConst)};
     630            0 :   if (value) {
     631            0 :     value->setFather(astAutoDecl);
     632            0 :   }
     633            0 :   return astAutoDecl;
     634            0 : }
     635              : 
     636              : std::expected<std::shared_ptr<AST_VAR_TYPED_DECL>, Error>
     637              : Builder::createVarTypedtDecl(const SourceLocation &srcLoc,
     638              :                              const std::string &id,
     639              :                              const std::shared_ptr<Type> &type,
     640            0 :                              const std::shared_ptr<AST> &value) noexcept {
     641            0 :   const auto astLetDecl{std::make_shared<AST_VAR_TYPED_DECL>(
     642            0 :       generateNextId(), srcLoc, id, type, value)};
     643            0 :   if (value) {
     644            0 :     value->setFather(astLetDecl);
     645            0 :   }
     646            0 :   return astLetDecl;
     647            0 : }
     648              : 
     649              : std::expected<std::shared_ptr<AST_VAR_CALL>, Error>
     650              : Builder::createVarCall(const SourceLocation &srcLoc,
     651            0 :                        const std::string &id) noexcept {
     652            0 :   return std::make_shared<AST_VAR_CALL>(generateNextId(), srcLoc, id);
     653            0 : }
     654              : 
     655              : std::expected<std::shared_ptr<AST_CHAINED>, Error> Builder::createChained(
     656              :     const SourceLocation &srcLoc, const std::shared_ptr<AST> &base,
     657            0 :     const std::vector<std::shared_ptr<AST>> &operations) noexcept {
     658            0 :   const auto astChained{std::make_shared<AST_CHAINED>(generateNextId(), srcLoc,
     659            0 :                                                       base, operations)};
     660            0 :   if (base) {
     661            0 :     base->setFather(astChained);
     662              : 
     663            0 :     const std::vector<std::shared_ptr<AST>> &operations__{
     664            0 :         astChained->operations()};
     665              : 
     666            0 :     if (operations__.size()) {
     667            0 :       operations__[0]->setFather(base);
     668              : 
     669            0 :       const std::size_t size{operations__.size()};
     670            0 :       if (size > 1) {
     671            0 :         for (std::size_t i{1}; i < size; ++i) {
     672            0 :           if (operations__[i] and operations__[i - 1]) {
     673            0 :             operations__[i]->setFather(operations__[i - 1]);
     674            0 :           }
     675            0 :         }
     676            0 :       }
     677            0 :     }
     678            0 :   }
     679            0 :   return astChained;
     680            0 : }
     681              : 
     682              : std::expected<std::shared_ptr<Tree>, Error>
     683            0 : Builder::createTree(const std::shared_ptr<AST_BODY> &statements) noexcept {
     684            0 :   return std::make_shared<Tree>(statements);
     685            0 : }
     686              : 
     687              : } // namespace nicole
        

Generated by: LCOV version 2.0-1